@camstack/addon-admin-ui 1.2.477 → 1.2.479

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/assets/Addons-2bVk9gQP.js +5 -0
  2. package/dist/assets/{AdminSectionedPage-DtiHBXGC.js → AdminSectionedPage-5g5LDrXG.js} +1 -1
  3. package/dist/assets/{AiProfiles-7FToWDqj.js → AiProfiles-CjexfGhj.js} +1 -1
  4. package/dist/assets/{BrokerForm-D5-q8F_8.js → BrokerForm-Behibhry.js} +1 -1
  5. package/dist/assets/{Build-DwW5kYsa.js → Build-EtMIMKRO.js} +3 -3
  6. package/dist/assets/{Calendars-BhMRY6EV.js → Calendars-DH3P_u96.js} +1 -1
  7. package/dist/assets/{Cluster-z11q6anB.js → Cluster-CFnD0vXf.js} +1 -1
  8. package/dist/assets/{CompositionBlockEditor-CElNVsCR.js → CompositionBlockEditor-BsmLsHO7.js} +1 -1
  9. package/dist/assets/{CompositionEditorPage-NzgZB76B.js → CompositionEditorPage-DbFLOjT0.js} +1 -1
  10. package/dist/assets/{Data-D_U-HkwO.js → Data-DaycWn5V.js} +2 -2
  11. package/dist/assets/{DeviceDetail-D89wXQHP.js → DeviceDetail-DABbOvpp.js} +2 -2
  12. package/dist/assets/{DeviceDoActionFields-Bj4gX0r-.js → DeviceDoActionFields-DESERgis.js} +1 -1
  13. package/dist/assets/{Devices-BnhDZU3y.js → Devices-e9WRZF8o.js} +1 -1
  14. package/dist/assets/{HelperWizard-CrXHYd19.js → HelperWizard-B5Evcb8G.js} +1 -1
  15. package/dist/assets/{History-BsJBR2zt.js → History-CUBYC5vJ.js} +1 -1
  16. package/dist/assets/{Identity-B_6I_sCY.js → Identity-YiQC97gk.js} +1 -1
  17. package/dist/assets/IntegrationDetail-LZqy5tnJ.js +1 -0
  18. package/dist/assets/{IntegrationHub-CSaA690G.js → IntegrationHub-oKQf8Hqh.js} +1 -1
  19. package/dist/assets/Integrations-Bb8hbB7-.js +1 -0
  20. package/dist/assets/Integrations-CSF7awEo.js +1 -0
  21. package/dist/assets/{Library-3dGkOQB5.js → Library-CLum5n0h.js} +1 -1
  22. package/dist/assets/{Locations-Bh5GRDCv.js → Locations-CyGnajVJ.js} +1 -1
  23. package/dist/assets/{Logs-diqSxXEc.js → Logs-DTwpZ7zU.js} +1 -1
  24. package/dist/assets/{MyAccess-BqulMSGv.js → MyAccess--2ZT-HhR.js} +1 -1
  25. package/dist/assets/{Network-C8Gpb2Vn.js → Network-DAts0LIq.js} +1 -1
  26. package/dist/assets/{NodeAddonsSettingsPanel-Dq6sGWkR.js → NodeAddonsSettingsPanel-96SuINk0.js} +1 -1
  27. package/dist/assets/{Notifications-C5w5t75z.js → Notifications-BLt2f-nc.js} +1 -1
  28. package/dist/assets/{Pipeline-CjumfHMc.js → Pipeline-Bn9VYb0p.js} +1 -1
  29. package/dist/assets/{Recordings-DE76fgEt.js → Recordings-vrFJrZh0.js} +1 -1
  30. package/dist/assets/ScanNetworkModal-u-7qAdO5.js +1 -0
  31. package/dist/assets/{SessionsList-Ca-zN1Fi.js → SessionsList-DJR70bvB.js} +1 -1
  32. package/dist/assets/{Showroom-B9HZ38O5.js → Showroom-CK5L2uo3.js} +1 -1
  33. package/dist/assets/{System-CHEbMPI_.js → System-Bp5NGMuQ.js} +1 -1
  34. package/dist/assets/{Terminal-CWFZuQLg.js → Terminal-BnNXFsMP.js} +1 -1
  35. package/dist/assets/{assignment-candidates-BcnFMc1B.js → assignment-candidates-BMhC6h3l.js} +1 -1
  36. package/dist/assets/{board-model-gmvqxkjB.js → board-model--9Jw6SCm.js} +1 -1
  37. package/dist/assets/{device-integration-icon-0oWIIjcP.js → device-integration-icon-CdgkjIk4.js} +1 -1
  38. package/dist/assets/{format-CIO4xeN9.js → format-fYneBFV6.js} +1 -1
  39. package/dist/assets/i18n-D0o08mg-.js +1 -0
  40. package/dist/assets/{index-D4ZlWCxy.css → index-D4id__eL.css} +1 -1
  41. package/dist/assets/index-D_Tm4B7S.js +4 -0
  42. package/dist/assets/{linked-devices-model-BoOq02QT.js → linked-devices-model-DMEJU3bE.js} +1 -1
  43. package/dist/assets/{location-owned-usage-IF2k-L3A.js → location-owned-usage-BqMUhVoi.js} +1 -1
  44. package/dist/assets/{mf-entry-bootstrap-0-f45a46c2.js → mf-entry-bootstrap-0-e328376a.js} +1 -1
  45. package/dist/assets/{step-inspector-model-CyqFN-LU.js → step-inspector-model-G2bS8NkA.js} +1 -1
  46. package/dist/assets/{useNodeUrlSelection-DGV2ltbG.js → useNodeUrlSelection-XYqqUh3q.js} +1 -1
  47. package/dist/index.html +4 -4
  48. package/dist/server/addon.js +1 -1
  49. package/package.json +1 -1
  50. package/dist/assets/Addons-CbHidHOJ.js +0 -5
  51. package/dist/assets/IntegrationDetail-B9L7AfYy.js +0 -1
  52. package/dist/assets/Integrations-B-KtSB_m.js +0 -1
  53. package/dist/assets/Integrations-CMW4LOX-.js +0 -1
  54. package/dist/assets/ScanNetworkModal-DXzDOpxk.js +0 -1
  55. package/dist/assets/i18n-xhwARoF0.js +0 -1
  56. package/dist/assets/index-C3uCLHv0.js +0 -4
@@ -1,2 +1,2 @@
1
- import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,a as s,et as c,o as l,t as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Br as f,Cr as p,D as m,Di as h,En as g,G as _,Gn as v,It as y,J as b,Jn as x,Jr as S,K as C,Kn as w,Li as T,O as E,Ri as D,Si as O,St as k,T as A,V as j,W as ee,Xn as te,Xr as M,Z as ne,Zt as re,_t as N,bn as ie,dn as ae,dt as P,en as F,ht as oe,li as se,lr as I,or as L,ot as R,pi as z,pn as B,q as ce,r as le,sa as ue,t as de,ta as fe,tr as pe,vn as me,xn as V,yn as he,z as ge,zn as _e,zr as ve}from"./player-overlays-Dbv95cvz.js";import{Fi as ye,Fn as be,Gt as H,Ii as U,In as xe,Jt as Se,Kt as Ce,Li as W,Lr as we,Ni as Te,Nn as Ee,Pn as De,Wn as Oe,Wr as ke,Xt as G,Yt as Ae,ba as je,bi as Me,d as Ne,ga as Pe,pi as Fe,qt as Ie,ti as Le,ui as Re,ya as ze}from"./client-DvJxGh2F.js";import{t as Be}from"./archive-Brq5E-qM.js";import{i as Ve,n as He,r as Ue,t as We}from"./scan-eye-CWOvobjP.js";import{t as Ge}from"./bell-off-CDjOfT8K.js";import{t as Ke}from"./boxes-0ut2NdHU.js";import{n as qe}from"./video-D7jv0spx.js";import{t as Je}from"./circle-slash-CaxGVwz5.js";import{t as Ye}from"./layers-BnsQ5ORI.js";import{$a as Xe,$r as K,Al as Ze,Bn as Qe,Bt as $e,Cr as et,Da as tt,Dn as nt,Dr as q,Ea as rt,Fa as it,Fc as at,Fn as ot,Ft as st,Gn as ct,Gt as lt,Hn as ut,Ho as dt,Ht as ft,I as pt,Io as mt,It as ht,Ju as gt,Kc as _t,Kr as J,Kt as vt,La as yt,Lc as bt,Lt as xt,Ma as St,Mn as Ct,Nc as wt,Nn as Tt,No as Et,Nt as Dt,Oi as Ot,Pa as kt,Pc as At,Pn as jt,Qs as Mt,Qt as Nt,R as Pt,Ra as Ft,Ro as It,Sa as Lt,Sn as Rt,So as zt,Ta as Bt,Tc as Vt,Tt as Ht,Un as Ut,Ut as Wt,Vc as Gt,Vn as Kt,Wi as qt,Wn as Jt,Wr as Yt,X as Xt,Xn as Zt,Xt as Qt,Ya as $t,Yn as en,Yt as tn,Z as nn,Zt as rn,_r as an,a as on,al as sn,ao as cn,at as ln,bn as un,br as dn,c as fn,cc as pn,cd as mn,ci as hn,co as gn,dd as _n,do as vn,ed as yn,en as bn,et as xn,fo as Sn,fr as Cn,go as wn,gs as Tn,hl as En,hr as Dn,hs as On,i as kn,id as An,il as jn,io as Mn,it as Nn,jt as Pn,ko as Fn,kr as In,l as Ln,ld as Rn,lo as zn,md as Bn,mr as Vn,ms as Hn,nd as Un,ni as Wn,nl as Gn,nn as Kn,o as qn,oc as Jn,od as Yn,ol as Xn,ot as Zn,pd as Qn,po as $n,pr as er,qt as tr,r as nr,rd as rr,rl as ir,rt as ar,st as or,td as sr,ti as cr,tn as lr,tt as ur,un as dr,uo as fr,us as pr,vr as mr,wn as hr,wr as gr,wt as _r,xa as vr,xr as yr,xt as br,yo as xr,yr as Sr,za as Cr,zr as wr,zt as Tr}from"./src-DntJrWmU.js";import{t as Y}from"./i18n-xhwARoF0.js";import{t as X}from"./useTranslation-BJr-n0es.js";import"./mount-CUPf26ML.js";import{$n as Er,A as Dr,D as Or,E as kr,O as Ar,cr as jr,er as Mr,fr as Nr,ir as Pr,j as Fr,k as Ir,lr as Lr,mr as Rr,nr as zr,or as Z,p as Br,pr as Vr,rr as Hr,sr as Ur,tr as Wr,ur as Gr}from"./index-C3uCLHv0.js";import{A as Kr,B as qr,C as Jr,D as Yr,E as Xr,F as Zr,G as Qr,H as $r,I as ei,L as ti,M as ni,N as ri,O as ii,P as ai,S as oi,T as si,U as ci,V as li,W as ui,_ as di,a as fi,b as pi,c as mi,d as hi,f as gi,g as _i,h as vi,i as yi,j as bi,k as xi,l as Si,m as Ci,n as wi,o as Ti,p as Ei,r as Di,s as Oi,t as ki,u as Ai,v as ji,w as Mi,x as Ni,y as Pi,z as Fi}from"./HelperWizard-CrXHYd19.js";import{r as Ii,t as Li}from"./assignment-candidates-BcnFMc1B.js";import{_ as Ri,b as zi,i as Bi,m as Vi,o as Hi,t as Ui}from"./step-inspector-model-CyqFN-LU.js";import"./useEventInvalidation-CUPf26ML.js";import{t as Wi}from"./use-stationary-objects-DBEa50KS.js";import{n as Gi,t as Ki}from"./format-CIO4xeN9.js";import{a as qi,i as Ji,n as Yi,o as Xi,r as Zi,s as Qi,t as $i}from"./linked-devices-model-BoOq02QT.js";import{t as ea}from"./authed-media-CnaIhiH3.js";c();function ta(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 na(e){if(typeof e!=`object`||!e)return null;let t=e.switches;if(!Array.isArray(t))return null;let n=t.map(ta).filter(e=>e!==null);return n.length===0?null:n}var ra=[[/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 ia(e){for(let[t,n]of ra)if(t.test(e))return n;return`generic`}function aa(e){let t=e.filter(e=>e.on===!1).map(e=>e.id),n=e.filter(e=>e.on===null).map(e=>e.id),r=t=>t.map(t=>e.find(e=>e.id===t)?.label??t).join(`, `),i=[];return t.length>0&&i.push(Y.t(`helpers.cameraSwitchRows.off`,{list:r(t)})),n.length>0&&i.push(Y.t(`helpers.cameraSwitchRows.unknown`,{list:r(n)})),{offIds:t,unknownIds:n,summary:i.length===0?Y.t(`helpers.cameraSwitchRows.allOn`):i.join(` · `)}}var oa={stream:V,detection:We,privacy:ve,microphone:te,speaker:k,listening:He,archive:Be,recording:Ue,notifications:T,generic:F};function sa({deviceId:t}){let{t:n}=X(),a=l(),s=Number.isFinite(t),[c,u]=o(null),[d,f]=o(!1),p=bt({deviceId:t},{enabled:s});nr([`pipelineOrchestrator`,`getCameraSwitches`],[`capability.binding-changed`]);let m=na(p.data),h=Xn({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 _=aa(m),v=e=>c?.id===e.id?c.message:null;return e(Un,{open:d,onOpenChange:f,children:[e(An,{"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(F,{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(rr,{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(ca,{row:e,failure:v(e),onToggle:()=>g(e)})},e.id))})]})]})}function ca({row:t,failure:n,onToggle:r}){let{t:a}=X(),o=oa[ia(t.label)],s=t.on===null,c=t.on===!1,l=n===null?s?t.unavailableReason??`The source that owns this did not answer.`:t.costWhenOff:`Write failed: ${n}`,u=n===null?s?t.unavailableReason??`unknown`:null:`write failed`;return e(`button`,{type:`button`,role:`switch`,"aria-label":t.label,"aria-checked":t.on===!0,disabled:!t.available,onClick:r,title:l,className:`flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-[12px] text-foreground transition-colors hover:bg-surface-hover disabled:opacity-40 disabled:cursor-not-allowed`,children:[i(o,{className:`h-3.5 w-3.5 shrink-0 ${n===null?s?`text-foreground-subtle/50`:c?`text-warning`:`text-success`:`text-danger`}`}),e(`span`,{className:`flex-1 min-w-0 truncate`,children:[t.label,u!==null&&e(`span`,{className:`ml-1 text-[10px] text-foreground-subtle`,children:[`· `,u]})]}),i(`span`,{className:`shrink-0 rounded px-1 py-0.5 text-[9px] font-semibold uppercase tracking-wide ${s?`bg-surface-hover text-foreground-subtle/60`:c?`bg-warning/20 text-warning`:`bg-success/20 text-success`}`,children:s?`—`:a(c?`common.off`:`common.on`)})]})}function la({deviceId:t}){let n=ft(R().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(f,{className:`h-3.5 w-3.5`}),i(`span`,{className:`hidden sm:inline`,children:n.label})]})}function ua({parentDeviceId:t}){let{t:n}=X(),r=Nr(),a=R(),{data:o,isLoading:s,isError:c}=Pr(t),{data:l}=gn({deviceId:t},{enabled:Number.isFinite(t)});if(s)return i(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:i(`p`,{className:`text-[10px] text-foreground-subtle`,children:n(`common.loading`,{defaultValue:`Loading…`})})});if(c)return i(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:i(`p`,{className:`text-[10px] text-warning`,children:n(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let u=(o??[]).filter(e=>e.display?.hidden!==!0);if(u.length===0)return null;let d=xt(l?.stableId??``,u,l?.childLayout),f=d.ungrouped,p=e=>r(`/devices/${String(e)}`),m=l?.name??``,h=(e,t)=>i(st,{trpc:a.trpcClient,device:{...t,name:Wt(t,m)},variant:`minimal`,onNavigate:p},e),g=f.some(e=>!!e.role),_=f.some(e=>!e.role),v=g&&!_?n(`device.accessories`,{defaultValue:`Accessories`}):!g&&_?n(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):n(`device.children`,{defaultValue:`Children`}),y=f.length>0?e(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[i(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:v}),i(`div`,{className:`space-y-1`,children:f.map(e=>h(e.id,e))})]}):null,b=d.disabledSection===void 0?null:i(ht,{title:n(`device.disabledSection`,{defaultValue:`Disabled`}),count:d.disabledSection.children.length,defaultOpen:!1,children:i(`div`,{className:`opacity-60 space-y-1`,children:d.disabledSection.children.map(e=>h(e.id,e))})},d.disabledSection.title);if(d.sections.length===0)return b===null?y:e(`div`,{className:`space-y-2`,children:[y,b]});let x=_&&!g;return e(`div`,{className:`space-y-2`,children:[x?y:null,d.sections.map(e=>i(ht,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>h(e.id,e))},e.title)),x?null:y,b]})}function da({deviceId:e}){let t=R(),{data:n,isLoading:r}=Hr(e),{data:a,isLoading:o}=Pr(e),s=r||o,c=(a??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,features:e.features,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),l=typeof n?.linkDeviceId==`number`?n.linkDeviceId:null,u=typeof n?.primaryChildEntityId==`string`?n.primaryChildEntityId:null;return s?i(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):i(`div`,{className:`flex h-full w-full flex-col`,children:i(lt,{trpc:t.trpcClient,children:c,linkDeviceId:l,primaryChildEntityId:u})})}c();function fa({dev:t,busy:n,setBusy:r}){let{t:a}=X(),s=t?.motionTrigger,c=b(t?.state.motionTrigger),[l,u]=o(!1);if(!s)return null;let d=c?.enabled===!0,f=c!==void 0,p=async()=>{if(n||!f)return;let e=!d;r(!0),u(!0);try{await s.setMotionTrigger({enabled:e})}finally{r(!1),u(!1)}},m=l?d?`Disabling…`:`Enabling…`:f?d?`On motion: on`:`On motion: off`:`On motion: …`;return e(`button`,{type:`button`,onClick:()=>{p()},disabled:n||!f,title:f?d?a(`hero.motionTriggerToggle.disableTriggerOnMotion`,`Disable trigger on motion`):a(`hero.motionTriggerToggle.enableTriggerOnMotion`,`Enable trigger on motion`):a(`hero.motionTriggerToggle.awaitingState`,`Awaiting state…`),"aria-pressed":d,className:`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-[11px] font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${d?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground`}`,children:[i(fe,{className:`h-3 w-3`}),i(`span`,{children:m})]})}c();function Q({deviceId:t,deviceType:n,features:r}){let a=R(),s=tn(n)?.HeroCard??Qt,c=C(a.trpcClient,t),l=b(c?.state.deviceStatus),[u,d]=o(!1),f=l!==void 0&&l.online===!1,p=f?l.lastChangedAt:null;return e(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[f?i(`div`,{className:`flex justify-center`,children:i(tr,{lastChangedAt:p})}):null,i(s,{trpc:a.trpcClient,deviceId:t,features:r}),i(`div`,{className:`flex justify-center`,children:i(fa,{dev:c,busy:u,setBusy:d})})]})}function pa({deviceId:e,features:t}){return i(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:i(rn,{trpc:R().trpcClient,deviceId:e,features:t})})}function ma({deviceId:e,features:t}){return i(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:i(Qt,{trpc:R().trpcClient,deviceId:e,features:t})})}function ha(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}function ga(e){if(!e)return null;let t=ha(e.data);return t===null?e.eventType:Y.t(`helpers.eventEmitterFormat.buttonHeadline`,{channel:String(t),eventType:e.eventType})}var _a=1e3,va=60*_a,ya=60*va,ba=24*ya;function xa(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<_a?Y.t(`helpers.relativeTime.justNow`):n<va?Y.t(`helpers.relativeTime.secondsAgo`,{count:Math.floor(n/_a)}):n<ya?Y.t(`helpers.relativeTime.minutesAgo`,{count:Math.floor(n/va)}):n<ba?Y.t(`helpers.relativeTime.hoursAgo`,{count:Math.floor(n/ya)}):Y.t(`helpers.relativeTime.daysAgo`,{count:Math.floor(n/ba)})}c();var Sa=1500,Ca=15e3,wa=1e3;function Ta({deviceId:n}){let{t:r}=X(),s=C(R().trpcClient,n)?.state.eventEmitter,c=b(s);a(()=>{if(!s)return;s.refresh();let e=setInterval(()=>{s.refresh()},Ca);return()=>{clearInterval(e)}},[s]);let l=c?.lastEvent??null,u=l?.seq??null,d=t(null),[f,m]=o(!1);a(()=>{if(u===null)return;let e=d.current;if(d.current=u,e===null||e===u)return;m(!0);let t=setTimeout(()=>{m(!1)},Sa);return()=>{clearTimeout(t)}},[u]);let[h,g]=o(()=>Date.now());a(()=>{let e=setInterval(()=>{g(Date.now())},wa);return()=>{clearInterval(e)}},[]);let _=ga(l),y=c?.eventTypes??[],x=c?.eventCountSinceStart??0,S=c!==void 0,w=ha(l?.data);return e(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 p-4`,children:[i(`div`,{"data-testid":`event-emitter-indicator`,"data-flashing":String(f),className:`flex h-24 w-24 items-center justify-center rounded-full border-2 transition-all ${f?`border-primary bg-primary/20 text-primary shadow-lg shadow-primary/30 scale-105`:`border-border bg-surface text-foreground-subtle`}`,"aria-live":`polite`,title:_??r(`hero.eventEmitterHero.noPressRecorded`,`No press recorded`),children:i(f?v:p,{className:`h-10 w-10`})}),e(`div`,{className:`text-center`,children:[w!==null&&i(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-primary`,children:r(`hero.eventEmitterHero.button`,`Button {{value1}}`,{value1:String(w)})}),i(`div`,{"data-testid":`event-emitter-headline`,className:`text-sm font-semibold ${_?`text-foreground`:`text-foreground-subtle`}`,children:_??(S?r(`hero.eventEmitterHero.noPressRecorded`,`No press recorded`):r(`hero.eventEmitterHero.awaitingState`,`Awaiting state…`))}),i(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:l?xa(l.timestamp,h):r(`hero.eventEmitterHero.waitingForTheFirstEvent`,`Waiting for the first event`)})]}),y.length>0&&i(`div`,{className:`flex max-w-full flex-wrap justify-center gap-1`,children:y.map(e=>i(`span`,{"data-testid":`event-emitter-chip`,className:`rounded-full border px-2 py-0.5 text-[10px] font-medium ${e===l?.eventType?`border-primary bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle`}`,children:e},e))}),i(`div`,{className:`text-[10px] text-foreground-subtle`,children:r(`hero.eventEmitterHero.sinceStart`,{count:x})})]})}function Ea({deviceName:t,deviceType:n,provider:r,isOnline:a,features:o}){let{t:s}=X();return e(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-surface p-6 text-center`,children:[i(Ur,{type:r,size:`lg`}),e(`div`,{children:[i(`div`,{className:`text-sm font-semibold text-foreground`,children:t}),i(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:n})]}),e(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[i(Zn,{status:a?`online`:`offline`}),o.length>0&&i(jr,{capabilities:o})]}),i(`div`,{className:`text-[10px] text-foreground-subtle italic max-w-xs mt-1`,children:s(`hero.genericHero.noLiveViewForThis`,`No live view for this device type. Use the Config tab or the shortcut row to interact.`)})]})}c();function Da({deviceId:t}){let{t:r}=X(),a=l(),o=kt({deviceId:t},{refetchInterval:1e4,retry:!1}),s=it({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),a.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),c=n(()=>Oa(o.data??[]),[o.data]);return e(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[e(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[i(ka,{label:r(`hero.hubHero.discovered`,`Discovered`),value:c.total,icon:i(_e,{className:`h-3.5 w-3.5`})}),i(ka,{label:r(`hero.hubHero.adopted`,`Adopted`),value:c.adopted,accent:`success`}),i(ka,{label:r(`hero.hubHero.available`,`Available`),value:c.available,accent:c.available>0?`primary`:void 0}),e(`button`,{type:`button`,onClick:()=>{s.mutateAsync({deviceId:t}).catch(()=>{})},disabled:s.isPending,className:`inline-flex items-center justify-center gap-1.5 rounded-lg border border-border px-3 py-2 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 self-stretch shrink-0`,children:[s.isPending?i(L,{className:`h-3.5 w-3.5 animate-spin`}):i(ie,{className:`h-3.5 w-3.5`}),i(`span`,{className:`hidden sm:inline`,children:r(`hero.hubHero.discover`,`Discover`)})]})]}),e(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-foreground-subtle border-t border-border-subtle pt-2`,children:[i(Aa,{icon:i(oe,{className:`h-3 w-3 text-emerald-500`}),label:r(`hero.hubHero.online`,`{{online}} online`,{online:c.online})}),i(Aa,{icon:i(w,{className:`h-3 w-3 text-amber-500`}),label:r(`hero.hubHero.sleeping`,`{{sleeping}} sleeping`,{sleeping:c.sleeping})}),i(Aa,{icon:i(N,{className:`h-3 w-3 text-destructive`}),label:r(`hero.hubHero.offline`,`{{offline}} offline`,{offline:c.offline})}),c.unknown>0?i(Aa,{icon:i(se,{className:`h-3 w-3 text-foreground-subtle`}),label:r(`hero.hubHero.unknown`,`{{unknown}} unknown`,{unknown:c.unknown})}):null]})]})}function Oa(e){let t={total:e.length,adopted:0,available:0,online:0,sleeping:0,offline:0,unknown:0};for(let n of e)n.alreadyAdopted?t.adopted+=1:t.available+=1,t[n.status]+=1;return t}function ka({label:t,value:n,icon:r,accent:a}){return e(`div`,{className:`flex flex-1 basis-[140px] min-w-0 flex-col gap-1 rounded-lg border px-2 py-1.5 sm:px-3 sm:py-2 ${a===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:a===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[e(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[r,i(`span`,{className:`truncate`,children:t})]}),i(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:n})]})}function Aa({icon:t,label:n}){return e(`span`,{className:`inline-flex items-center gap-1`,children:[t,i(`span`,{children:n})]})}var ja={[W.Switch]:Q,[W.Siren]:Q,[W.Light]:Q,[W.Sensor]:Q,[W.Button]:Q,[W.Hub]:Da,[W.Cover]:pa,[W.Valve]:Q,[W.Humidifier]:Q,[W.WaterHeater]:Q,[W.Container]:da,[W.Lock]:Q,[W.Fan]:Q,[W.Thermostat]:Q,[W.Climate]:Q,[W.MediaPlayer]:Q,[W.Control]:Q,[W.AlarmPanel]:Q,[W.EventEmitter]:Ta,[W.Notifier]:ma,[W.Script]:Q,[W.Automation]:Q,[W.Presence]:Q,[W.Update]:Q,[W.Vacuum]:Q,[W.LawnMower]:Q,[W.Weather]:Q,[W.Image]:Q,[W.PetFeeder]:Q,[W.Dishwasher]:Q};function Ma(e){return ja[e]??Ea}function Na({deviceId:e}){let t=ce(R().trpcClient,e,e=>e.runningState);if(t===void 0||t.running!==!0&&t.running!==!1)return i(d,{});let n=t.running;return i(jt,{running:n,since:t?.since??null,phase:t?.phase??null,className:`px-3 pt-2 sm:px-4`})}function Pa(t){let n=Ma(t.deviceType);return e(d,{children:[i(Na,{deviceId:t.deviceId}),i(n,{...t})]})}function Fa({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(Cn,{widgetId:t.widgetId,deviceId:t.deviceId});return i(`div`,{children:t.deviceId===e?n:i(wr,{deviceId:t.deviceId,children:n})},t.widgetId)})})}function Ia(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 La(e){let t=Ia(e),n=new Set(t.map(e=>e.widgetId)),r=e.child===void 0?[]:Ia(e.child),i=[...t,...r.filter(e=>!n.has(e.widgetId))],a=new Set;return i.filter(e=>a.has(e.widgetId)?!1:(a.add(e.widgetId),!0)).sort((e,t)=>e.order-t.order)}function Ra(e){return qn(R().trpcClient,e)}c();function za(e){let[n,i]=o(`idle`),[s,c]=o(null),l=t(null),u=t(null),d=t(null),f=t(!0),p=On(),m=Hn(),h=Tn(),g=r(()=>{if(l.current){try{l.current.close()}catch{}l.current=null}if(u.current){for(let e of u.current.getTracks())try{e.stop()}catch{}u.current=null}d.current=null},[]),_=r(async()=>{if(n===`idle`)return;i(`stopping`);let t=d.current;if(t&&e!==null)try{await Promise.race([h.mutateAsync({deviceId:e,sessionId:t}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}g(),f.current&&(i(`idle`),c(null))},[n,e,h,g]),v=r(async()=>{if(e===null||n!==`idle`&&n!==`error`)return;c(null);let t=null,r=null,a=null;try{i(`requesting-mic`),t=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),u.current=t,i(`starting`);let n=await p.mutateAsync({deviceId:e});a=n.sessionId,d.current=a,i(`connecting`),r=new RTCPeerConnection,l.current=r,r.oniceconnectionstatechange=()=>{if(!f.current)return;let e=r.iceConnectionState;e===`connected`||e===`completed`?i(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&f.current&&(c(e===`failed`?`WebRTC connection failed`:null),_())};for(let e of t.getAudioTracks())r.addTrack(e,t);await r.setRemoteDescription({type:`offer`,sdp:n.sdpOffer});let o=await r.createAnswer();await r.setLocalDescription(o);let s=r.localDescription?.sdp??o.sdp??``;await m.mutateAsync({deviceId:e,sessionId:a,sdpAnswer:s})}catch(n){let o=n instanceof Error?n.message:String(n);if(console.warn(`[intercom] start failed`,n),r)try{r.close()}catch{}if(t)for(let e of t.getTracks())try{e.stop()}catch{}if(l.current=null,u.current=null,a!==null)try{await h.mutateAsync({deviceId:e,sessionId:a})}catch{}d.current=null,f.current&&(c(o),i(`error`))}},[e,n,p,m,h,_]);return a(()=>(f.current=!0,()=>{f.current=!1;let t=d.current;if(t!==null&&e!==null&&h.mutate({deviceId:e,sessionId:t}),l.current){try{l.current.close()}catch{}l.current=null}if(u.current){for(let e of u.current.getTracks())try{e.stop()}catch{}u.current=null}d.current=null}),[e]),{state:n,error:s,start:v,stop:_,isTalking:n===`talking`}}c();var Ba=0;function $(){return++Ba}function Va(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function Ha(e){return[``,`Commands`,` help Show this help`,` examples Show usage examples for the current scope`,` context Show every available variable + full API surface`,` clear Clear terminal (also Ctrl+L)`,``,`Shortcuts`,` Enter Execute expression`,` Arrow Up/Down Navigate command history`,` Ctrl+L Clear terminal`,``,`Try: ${{system:` sm.summary() // fleet overview`,device:` device.state.battery.value?.sleeping // sync read`,provider:` devices.map(d => d.name)`,addon:` manifest.version`}[e.type]}`,``,`Top-level objects: sm (SystemMirror), DeviceType, Math, JSON, Date, …`]}function Ua(e){switch(e.type){case`device`:return[``,`── State (sync, zero round-trip) ─────────────────────────`,` device.state.battery.value`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,``,`── Actions (async, through wrapper chain) ────────────────`,` await device.snapshot.getSnapshot({})`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.switch.setState({ on: true })`,``,`── Wait for condition ───────────────────────────────────`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`── Subscribe to changes ─────────────────────────────────`,` const off = device.state.battery.subscribe(s => console.log(s))`,``,`── Quick info ───────────────────────────────────────────`,` info.name device name`,` info.addonId owning addon`,` sm.dump(deviceId) full debug dump`];case`system`:return[``,`── Lookups ──────────────────────────────────────────────`,` sm.getDeviceById(8)`,` sm.getDeviceByName('Sala da pranzo')`,` sm.getDevicesByAddon('reolink')`,` sm.getDevicesByType(DeviceType.Camera)`,``,`── Filters (typed query) ────────────────────────────────`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] })`,` sm.query({ name: /^Cam-/ })`,``,`── Cross-device ─────────────────────────────────────────`,` sm.whereState('battery', s => s.percentage < 20).length`,` sm.mapState('battery', s => s.percentage)`,` sm.countByCap('snapshot')`,``,`── Batch action ─────────────────────────────────────────`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,``,`── Listen ───────────────────────────────────────────────`,` sm.listenCap('motion', (id, s) => console.log(id, s))`,` sm.onDeviceAdded((id, info) => console.log('+', info.name))`,``,`── Diagnostics ──────────────────────────────────────────`,` sm.summary()`,` sm.dump(8)`];case`provider`:return[``,` devices.map(d => d.name)`,` await getIntegration()`,` sm.getDevicesByAddon('<this-addon-id>').length`];case`addon`:return[``,` manifest.name`,` manifest.version`,` declaration`]}}function Wa(e){let t=[``,`Scope: ${e.type}`,``];switch(e.type){case`system`:return[...t,`Primary API — sm (SystemMirror):`,` sm.getDeviceById(id) DeviceProxy | null (sync)`,` sm.getDeviceByName(name) DeviceProxy | null`,` sm.getDeviceByStableId(sid) DeviceProxy | null`,` sm.getAllDevices() readonly DeviceProxy[]`,` sm.getDeviceInfo(id) DeviceInfo | null`,` sm.summary() fleet stats`,``,`Filters — sm.query({...}):`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] }) // ALL caps required`,` sm.query({ anyCap: ['ptz', 'motion'] }) // ANY cap`,` sm.query({ name: { contains: 'sala' } }) // case-insensitive`,` sm.query({ name: /^Cam-\\d+$/ })`,` sm.query({ type: DeviceType.Camera })`,` sm.query({ parentDeviceId: 8 }) // accessories of cam 8`,` sm.query({ where: (info, dev) => dev.state.battery.value?.sleeping })`,``,`State queries:`,` sm.whereState('battery', s => s.percentage < 20)`,` sm.mapState('battery', s => s.percentage)`,` sm.findState('motion', s => s.detected)`,` sm.countByCap('snapshot')`,``,`Listeners (return unsubscribe fn):`,` sm.listen((id, cap, slice) => …) // every state change`,` sm.listenCap('motion', (id, slice) => …)`,` sm.listenDevice(8, (id, cap, slice) => …)`,` sm.onDeviceAdded((id, info) => …)`,` sm.onDeviceRemoved((id, info) => …)`,``,`Wait primitives:`,` await sm.waitForState(8, 'battery', s => !s.sleeping, 30_000)`,` await sm.waitForDevice(99, 30_000)`,``,`Batch:`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,` await sm.forEachCap('reboot', d => d.reboot.reboot({}))`,``,`Diagnostics:`,` sm.dump(8) debug dump (one device)`,` sm.dump() full fleet dump`,` sm.summary() breakdown by cap/addon/type`,``,`Legacy: deviceRegistry, addonRegistry, eventBus, devices(), addons()`];case`device`:return[...t,`Pre-bound variables:`,` device DeviceProxy for this device (sync state + async methods)`,` deviceId number`,` info DeviceInfo metadata (name, addonId, type, online, …)`,` sm SystemMirror (full cluster view)`,` rawDevice legacy IDevice instance (escape hatch)`,``,`Reactive state (sync, zero round-trip):`,` device.state.battery.value BatteryStatus | undefined`,` device.state.battery.value?.sleeping`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,` device.state.switch.value?.on`,` device.state.brightness.value?.percentage`,` device.state.doorbell.value?.lastPressedAt`,``,`Cap actions (async, through wrapper chain):`,` await device.snapshot.getSnapshot({})`,` await device.snapshot.getSnapshot({ streamId: 'high' })`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.ptz.goToPreset({ presetId: 'home' })`,` await device.switch.setState({ on: true })`,` await device.brightness.setBrightness({ percentage: 60 })`,` await device.reboot.reboot({})`,``,`Subscribe to slice changes:`,` const off = device.state.battery.subscribe(s => console.log(s))`,` // off() to unsubscribe`,``,`Wait for a state condition:`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`Diagnostics:`,` info.name device name`,` info.addonId which addon owns it`,` info.online transport health`,` sm.dump(deviceId) full debug dump (binding + state + info)`];case`provider`:return[...t,`Pre-bound variables:`,` devices Devices belonging to this provider (raw IDevice[])`,` getIntegration() Integration metadata`,``,`For typed device access use the SystemMirror:`,` await getSystemMirror()`,` sm.getDevicesByAddon('this-addon-id')`];case`addon`:return[...t,`Pre-bound variables:`,` manifest { name, version, ... }`,` declaration addon declaration`,` source addon source location`,``,`Examples:`,` manifest.name`,` manifest.version`]}}function Ga({scope:n,greeting:s,className:c}){let{t:l}=X(),d=R(),[f,p]=o(()=>{let e=[];return s&&e.push({id:$(),kind:`info`,text:s}),e.push({id:$(),kind:`info`,text:`scope: ${Va(n)} — type help or context for available commands`}),e}),[m,h]=o(``),[g,_]=o([]),[v,y]=o(-1),b=t(null),x=t(null);a(()=>{let e=x.current;e&&(e.scrollTop=e.scrollHeight)},[f]);let S=r(()=>{b.current?.focus()},[]),C=u({mutationFn:e=>d.trpcClient.repl.execute.mutate({code:e,scope:n}),onSuccess:e=>{let t=e??{},n=typeof t.output==`string`?t.output:e==null?`undefined`:typeof e==`string`?e:JSON.stringify(e,null,2),r=t.type===`error`;p(e=>[...e,{id:$(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);p(e=>[...e,{id:$(),kind:`error`,text:t}])}});function w(e){let t=e.trim();if(t){if(t===`clear`){p([{id:$(),kind:`info`,text:`scope: ${Va(n)}`}]),h(``);return}if(t===`help`){p(e=>[...e,{id:$(),kind:`input`,text:`> ${t}`},...Ha(n).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}if(t===`context`){p(e=>[...e,{id:$(),kind:`input`,text:`> ${t}`},...Wa(n).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}if(t===`examples`){p(e=>[...e,{id:$(),kind:`input`,text:`> ${t}`},...Ua(n).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}_(e=>[...e,t]),y(-1),p(e=>[...e,{id:$(),kind:`input`,text:`> ${t}`}]),h(``),C.mutate(t)}}function T(e){if(e.key===`Enter`){e.preventDefault(),w(m);return}if(e.key===`ArrowUp`){if(e.preventDefault(),g.length===0)return;let t=v===-1?g.length-1:Math.max(0,v-1);y(t),h(g[t]??``);return}if(e.key===`ArrowDown`){if(e.preventDefault(),v===-1)return;let t=v+1;t>=g.length?(y(-1),h(``)):(y(t),h(g[t]??``));return}e.ctrlKey&&e.key===`l`&&(e.preventDefault(),p([{id:$(),kind:`info`,text:`scope: ${Va(n)}`}]))}let E={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return e(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${c??``}`,onClick:S,children:[e(`div`,{ref:x,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[f.map(e=>i(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${E[e.kind]}`,children:e.text},e.id)),C.isPending&&i(`span`,{className:`text-zinc-500 animate-pulse`,children:l(`shared.replTerminal.thinking`,`…thinking`)})]}),e(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[i(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:l(`shared.replTerminal.text`,`>`)}),i(`input`,{ref:b,value:m,onChange:e=>h(e.target.value),onKeyDown:T,disabled:C.isPending,placeholder:`device.state.battery.value`,autoFocus:!0,className:`flex-1 bg-transparent text-zinc-100 placeholder:text-zinc-600 focus:outline-none caret-emerald-400 disabled:opacity-50`,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`})]})]})}function Ka(e,t){return e===null?null:{playbackUrl:e.url,...e.format===void 0?{}:{playbackFormat:e.format},playbackAuthToken:t,...e.label===void 0?{}:{playbackLabel:e.label}}}c();function qa({deviceId:e,intercomAvailable:t=!1}){let r=R(),a=typeof window<`u`?ne():``,o=Number.isFinite(e),s=Ra(o?e:null),c=Wi(o?[e]:[]),l=n(()=>{if(!o)return;let e=[];for(let t of c.rows){let n=on(t);n!==null&&e.push(n)}return e},[o,c.rows]),{streams:u,pipelineMetrics:f,createSession:p,sendAnswer:m,handleOffer:h,getIceServers:g,addIceCandidate:v,getIceCandidates:y,closeSession:b,getSessionState:x,applyDownlinkProbe:S}=un(r.trpcClient,o?e:null),C=_(o?e:null,{width:Qa}),w=za(o&&t?e:null),T=w.state===`requesting-mic`||w.state===`starting`||w.state===`connecting`||w.state===`stopping`,E=w.isTalking||T,D=()=>{w.state===`idle`||w.state===`error`?w.start():w.state!==`stopping`&&w.stop()},O=le(),k=gr(),A=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,j=Ka(k.request,A),ee=O.length>0?i(d,{children:O.map(e=>i(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return i(Xt,{serverUrl:a,createSession:p,sendAnswer:m,handleOffer:h,getIceServers:g,addIceCandidate:v,getIceCandidates:y,closeSession:b,getSessionState:x,applyDownlinkProbe:S,...j===null?{}:{...j,onExitPlayback:()=>k.clear()},streams:u,pipelineMetrics:f,phase:s.phase,detections:s,...l===void 0?{}:{stationaryObjects:l},defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:C.src,...C.src?{posterUrl:C.src}:{},snapshotLoading:C.loading,onRefreshSnapshot:C.refresh,intercomAvailable:t,intercomShown:E,onIntercomToggle:D,extraOverlay:ee,chromeless:!0,className:`h-full`})}function Ja({deviceId:e,containerDeviceId:t}){let{t:n}=X();return Number.isFinite(e)?i(`div`,{className:`flex flex-col h-full`,children:i(Kn,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):i(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:n(`device.panelContent.notLoaded`,{id:e})})}function Ya({deviceId:e}){let{t}=X();if(!Number.isFinite(e))return i(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:t(`device.panelContent.notLoaded`,{id:e})});let n=[`CamStack REPL — device #${e}`,``,` device.state.battery.value sync state read`,` await device.snapshot.getSnapshot({}) cap action`,``,` type 'examples' for more, 'context' for the full API`].join(`
2
- `);return i(Ga,{scope:{type:`device`,deviceId:e},greeting:n,className:`h-full border-0 rounded-none`})}function Xa({deviceId:e}){let{t}=X();return Number.isFinite(e)?i(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:i(lr,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):i(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:t(`device.panelContent.notLoaded`,{id:e})})}function Za({deviceId:e}){let{t}=X();return Number.isFinite(e)?i(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:i(bn,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):i(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:t(`device.panelContent.notLoaded`,{id:e})})}var Qa=960;function $a({initialName:e,label:t=`Name`,layout:n=`inline`,bound:r}){return i(Z,{label:t,layout:n,value:i(`input`,{type:`text`,value:r.value,"aria-label":t,placeholder:e,onChange:e=>r.onChange(e.target.value),className:`flex-1 min-w-0 w-full px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`})})}c();function eo({label:t=`Location`,layout:r=`inline`,bound:a}){let{t:o}=X(),{data:s}=wn(),c=s??[],l=a.value.trim().toLowerCase(),u=n(()=>l.length===0?[]:c.filter(e=>e.toLowerCase()!==l&&e.toLowerCase().includes(l)),[c,l]);return i(Z,{label:t,layout:r,value:e(`div`,{className:`relative`,children:[i(`input`,{type:`text`,value:a.value,"aria-label":t,onChange:e=>a.onChange(e.target.value),placeholder:o(`shared.locationRow.roomAreaOrLeaveEmpty`,`Room / area (or leave empty to clear)`),className:`flex-1 min-w-0 w-full px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),u.length>0&&i(`div`,{className:`absolute z-10 left-0 right-0 mt-0.5 max-h-40 overflow-y-auto rounded-md border border-border bg-surface shadow-md`,children:u.map(t=>e(`button`,{type:`button`,onClick:()=>a.onChange(t),className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[i(pe,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),i(`span`,{className:`truncate`,children:t})]},t))})]})})}var to=`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`,no=0,ro=10;function io(e){if(e.trim()===``)return``;let t=Number.parseInt(e,10);return Number.isFinite(t)?String(t<no?no:t>ro?ro:t):``}function ao({value:e,onChange:t,disabled:n=!1,placeholder:r,className:a,id:o,"aria-label":s}){return i(`input`,{type:`number`,min:no,max:ro,step:1,id:o,className:a??to,"aria-label":s,placeholder:r,value:e,onChange:e=>{t(io(e.target.value))},disabled:n})}function oo({deviceName:t,value:n,inheritedIcon:r,inheritedLabel:a,disabled:o,onChange:s}){let{t:c}=X(),l={trigger:c(`deviceDisplay.pickIcon`,{name:t}),panel:c(`deviceDisplay.iconFor`,{name:t}),searchPlaceholder:c(`deviceDisplay.iconSearchPlaceholder`),clear:a,noMatches:c(`deviceDisplay.iconNoMatches`)};return e(`div`,{className:`flex items-center gap-2`,children:[i(sr,{value:n===``?null:n,onPick:e=>s(e??``),categoryLabel:e=>c(`deviceDisplay.iconCategory.${e}`,{defaultValue:ke(e)}),fallbackGlyph:r,labels:l,disabled:o}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:n===``?a:n})]})}var so=`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 co(e){if(e.trim()===``)return;let t=Number.parseInt(e,10);return Number.isFinite(t)?t:void 0}function lo({device:t,role:n,display:r,onChange:a}){let o=ue();Rn();let{t:s}=X(),c=l(),u=n===null?void 0:Nt[n],f=u?.kind===`numeric`,p=n!==null||t.parentDeviceId!==null&&t.parentDeviceId!==void 0,m=t.sourceInfo?.quantity,h=u?.kind===`numeric`?u.quantity??(m!==void 0&&m!==`device`?m:void 0):void 0,g=h===void 0?void 0:Pe(h),_=g===void 0?void 0:Oe(g),{data:v}=fr({},{staleTime:6e4,enabled:n!==null}),y=mt({onSuccess:()=>{c.invalidateQueries({queryKey:[[`deviceManager`]]})}}),b=()=>{if(n===null)return;let e=co(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:mn(x),C=n===null?Qn(t.type,o):_n(n,o),w={icon:S??C.icon,label:S===void 0?C.label:String(x)},T=n===null&&t.type===W.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?``:_n(n,o).label;return e(`div`,{className:`mt-3 divide-y divide-border border-t border-border`,children:[i(Z,{label:s(`deviceDisplay.icon`),value:i(oo,{deviceName:t.name,value:r.icon,inheritedIcon:w.icon,inheritedLabel:T,disabled:!1,onChange:e=>a({icon:e})})}),p&&i(Z,{label:s(`deviceDisplay.label`),value:i(`input`,{type:`text`,className:so,"aria-label":s(`deviceDisplay.label`),placeholder:n===null?t.name:E,value:r.label,onChange:e=>a({label:e.target.value})})}),f&&e(d,{children:[i(Z,{label:s(`deviceDisplay.unit`),value:i(pt,{dimension:_,value:r.unit,onChange:e=>a({unit:e}),disabled:!1,"aria-label":s(`deviceDisplay.unit`),inheritLabel:s(`deviceDisplay.unitSource`,{unit:g===void 0?``:` (${g})`}),emptyReason:s(`deviceDisplay.unitSource`,{unit:``})})}),i(Z,{label:s(`deviceDisplay.precision`),value:i(ao,{"aria-label":s(`deviceDisplay.precision`),placeholder:s(`deviceDisplay.precisionInherit`),value:r.precision,onChange:e=>a({precision:e}),disabled:!1})})]}),n!==null&&i(`div`,{className:`px-3 sm:px-4 py-2`,children:i(J,{type:`button`,variant:`outline`,size:`sm`,onClick:b,disabled:y.isPending,title:s(`deviceDisplay.setRoleDefaultTitle`,{role:E}),children:s(`deviceDisplay.setRoleDefault`,{role:E})})})]})}function uo(e){return typeof e.linkDeviceId==`number`}var fo=new Set(Object.values(U));function po(e){return fo.has(e)}var mo={[W.Switch]:[U.Siren,U.Floodlight,U.Spotlight,U.PirSensor,U.Chime,U.Autotrack,U.Nightvision,U.PrivacyMask,U.BinaryHelper],[W.Light]:[U.Floodlight,U.Spotlight,U.Nightvision],[W.Siren]:[U.Siren],[W.Button]:[U.Doorbell],[W.Sensor]:[U.MotionSensor,U.ContactSensor,U.LeakSensor,U.SmokeSensor,U.COSensor,U.GasSensor,U.TamperSensor,U.VibrationSensor,U.ConnectivitySensor,U.SoundSensor,U.BinarySensor,U.TemperatureSensor,U.HumiditySensor,U.AmbientLightSensor,U.PressureSensor,U.WindSensor,U.RainSensor,U.UvSensor,U.SolarRadiationSensor,U.SoilMoistureSensor,U.PowerSensor,U.EnergySensor,U.VoltageSensor,U.CurrentSensor,U.AirQualitySensor,U.BatterySensor,U.NumericSensor,U.EnumSensor,U.DateTimeSensor,U.GenericSensor],[W.Control]:[U.NumericControl,U.SelectControl,U.TextControl,U.DateTimeControl],[W.Notifier]:[U.MobilePushNotifier,U.MessagingNotifier,U.EmailNotifier,U.GenericNotifier]};function ho(e){for(let t of Object.values(W))if(t===e)return!0;return!1}function go(e){return ho(e)?mo[e]??[]:[]}function _o(e,t){let n=go(t);return e==null||e===``||n.includes(e)?n:[...n,e]}function vo({device:t}){let{t:n}=X(),r=ue(),a=Wr(),o=a?.identity??null,s=o?.name??t.name,c=o?.location??t.location??``,l=o?.role??t.role??null,u=o?.display.hidden??t.display?.hidden===!0,d=a!==null&&o!==null;return e(`section`,{"aria-label":n(`customize.identity.title`),className:`${E} ${m}`,children:[e(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[d?i($a,{deviceId:t.id,initialName:s,label:n(`customize.identity.name`),layout:`stacked`,bound:{value:s,onChange:a.setIdentityName}}):i(Z,{label:n(`customize.identity.name`),layout:`stacked`,value:s}),d?i(eo,{deviceId:t.id,initialLocation:c,label:n(`customize.identity.room`),layout:`stacked`,bound:{value:c,onChange:a.setIdentityLocation}}):i(Z,{label:n(`customize.identity.room`),layout:`stacked`,value:c===``?n(`common.unset`):c}),i(Z,{label:n(`customize.identity.type`),layout:`stacked`,value:t.type}),i(Z,{label:n(`customize.identity.hidden`),layout:`stacked`,value:i(ct,{"aria-label":n(`deviceDisplay.hideFromLists`),checked:u,disabled:!d,onChange:e=>a?.setIdentityDisplay({hidden:e.target.checked})})}),i(Z,{label:n(`customize.identity.role`),layout:`stacked`,value:uo(t)||!d?i(`span`,{children:yo(l,n(`customize.identity.noRole`),r)}):i(gt,{"aria-label":n(`customize.identity.role`),value:l??``,options:[{value:``,label:n(`customize.identity.noRole`)},..._o(l,t.type).map(e=>({value:e,label:yo(e,n(`customize.identity.noRole`),r)}))],onChange:e=>a.setIdentityRole(e.target.value===``?null:e.target.value)})})]}),o!==null&&a!==null&&i(lo,{device:t,role:l,display:o.display,onChange:a.setIdentityDisplay})]})}function yo(e,t,n){return e==null||e===``?t:po(e)?_n(e,n).label:e}function bo(e){let t=De({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 xo(e){let t=be({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 So(e,t){return{deviceId:e,config:t.config}}function Co(e,t){return{deviceId:e,patch:{motionCooldownMs:t}}}async function wo(e,t,n,r){await n(So(e,t)),await r(Co(e,t.timeoutMs))}c();function To(t){let{t:n}=X(),r=t.mode===`change`?n(`customize.scalar.changeTitle`,{title:t.title}):n(`customize.scalar.addTitle`,{title:t.title});return i(er,{open:t.open,onOpenChange:e=>!e&&t.onClose(),children:e(Dn,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":r,children:[i(mr,{children:i(Sr,{children:r})}),t.open?i(Eo,{...t}):null]})})}function Eo(t){let{t:r}=X(),a=Sn({projection:`slim`}),s=ii(n(()=>a.status===`success`?ni(a.data):[],[a.status,a.data]),t.sources[0]),[c,l]=o(()=>Do(t.sources)),[u,f]=o(null),[p,m]=o(!1);!p&&s!==null&&(f(s),m(!0));let[h,g]=o(t.edge),[_,v]=o(t.debounceMs/1e3),y=Oo(c),b=y.length===0?null:bo({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=dt({deviceId:c[0]?.deviceId??0}),C=Ao(S.status===`success`?S.data:void 0,x),w=Ae(Ie,C,Math.round(_*1e3));return e(d,{children:[e(Vn,{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(Yr,{kind:`event`,shape:`pulse`,enabled:t.open,hostId:t.host.id,devicePickerTestId:`event-pulse-picker`,destination:{cap:t.cap,targetId:t.targetId,title:t.title},device:u,picked:c,onDeviceChange:f,onPickedChange:l,edges:t.edges,edge:h,onEdgeChange:g,debounceSec:_,onDebounceSecChange:v,sourceModes:[],timeoutSec:0,onTimeoutSecChange:()=>void 0,cooldownSec:null,onCooldownSecChange:()=>void 0}),C.kind===`level`?i(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:r(ko(C,w.lastPressedAt))}):null]}),e(an,{className:`flex flex-wrap gap-2`,children:[i(J,{variant:`ghost`,onClick:t.onClose,children:r(`customize.scalar.cancel`)}),i(J,{"data-testid":`event-save`,disabled:!t.canSave||b===null,onClick:()=>{b!==null&&t.onSave(b)},children:r(`customize.scalar.save`)})]})]})}function Do(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 Oo(e){return e.map(e=>({addonId:e.addonId,stableId:e.stableId,cap:e.cap,fieldPath:e.fieldPath,changedAtField:e.changedAtField??Te[e.cap]??`lastChangedAt`}))}function ko(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 Ao(e,t){if(e===void 0||t===null)return{kind:`unread`};let n=e[t.cap],r=n===void 0?void 0:bi(n,t.fieldPath),i=Te[t.cap]??t.changedAtField,a=n===void 0?void 0:bi(n,i);return typeof r==`boolean`?{kind:`level`,active:r,changedAt:typeof a==`number`&&Number.isFinite(a)?a:null}:{kind:`unread`}}function jo(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=Mo(t,n);return r===null?{kind:`unknown`,seconds:null}:{kind:`active`,seconds:r}}function Mo(e,t){if(e==null||!Number.isFinite(e)||e<Ki)return null;let n=Math.floor((t-e)/1e3);return n<0?0:n}function No(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>=Ki?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();function Po({device:t,handle:n,availability:r,cap:a,title:s,view:c}){let{t:l,i18n:u}=X(),f=ri(),[p,m]=o(!1),[h,g]=o(null),_=li(n.state),v=ai(_,a),y=Io(n,v),b=y.kind===`known`&&y.value!==null?Ee({feature:y.value,device:n.target,cap:a,targetId:c.id,timestampPath:c.timestampPath,counterPath:c.counterPath}):null,x=b!==null,S=ci(x),C=b?.draft.sources[0]??null,w=C===null||S.kind!==`known`?null:S.value.find(e=>Me({addonId:e.addonId,stableId:e.stableId})===Me(C))??null,T=Lo(x,S.kind,w!==null),E=H({cap:a,targetId:c.id,device:n.target,timestampPath:c.timestampPath,counterPath:c.counterPath,apply:c.apply,stored:y,sourcePresence:T,sourceUnknownReason:S.kind===`unknown`?S.reason:null}),O=n.state.kind===`none`||n.state.kind===`present`;if(r.kind===`absent`||!c.deviceTypes.includes(t.type))return null;let k=async e=>{let t=await n.save(e);g(t.kind===`refused`?t.reason:null)},A=Ro(b),j=b?.draft.edges?.[0],ee=j!==void 0&&c.edges.includes(j)?j:c.defaultEdge,te=C===null?``:qr(C.cap,C.fieldPath,u.language),M=y.kind===`known`&&y.value===null,ne=!x&&y.kind===`known`&&y.value!==null;return e(d,{children:[i(Qr,{id:a,icon:D,title:s,testId:`event-card-${a}`,actions:e(d,{children:[v!==null&&e(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground`,children:[i(ct,{"aria-label":l(`customize.doorbell.active`),checked:v.enabled!==!1,disabled:!O||n.saving,onChange:e=>{k(ei(_,n.target,{...v,enabled:e.target.checked}))}}),l(`customize.doorbell.active`)]}),i(K,{children:l(Mi(E.text,E.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`&&!O?i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:l(`customize.event.checking`)}):r.kind===`unknown`?i(q,{title:l(`customize.scalar.unreadable`),message:r.reason}):e(d,{children:[x&&C!==null&&i(`p`,{className:`text-xs text-foreground`,children:l(`customize.scalar.override`,{name:w===null?C.stableId:xi(w.name,w.id,S.kind===`known`?S.value.map(e=>({id:e.id,name:e.name,parentDeviceId:e.parentDeviceId??null})):[]),field:te})}),x&&i(Fo,{deviceId:t.id,cap:a,timestampPath:c.timestampPath,counterPath:c.counterPath,startedAt:n.state.kind===`present`?n.state.view.block.createdAt:null}),ne&&v!==null&&e(`p`,{className:`text-xs text-foreground flex flex-wrap items-center gap-1`,children:[l(`customize.doorbell.otherFormula`),i(pi,{handle:n,cap:a,fieldPath:c.counterPath})]}),M&&i(`p`,{className:`text-xs text-foreground-subtle`,children:l(`customize.scalar.noOverride`)}),h!==null&&i(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:h}),e(`div`,{className:`flex flex-wrap gap-2`,children:[x&&i(J,{variant:`outline`,size:`sm`,disabled:n.saving,onClick:()=>m(!0),children:l(`customize.scalar.change`)}),x&&i(J,{variant:`ghost`,size:`sm`,disabled:n.saving,onClick:()=>{if(_===null)return;let e=ti(_,a);f(l(`customize.doorbell.removeWhat`,{name:w?.name??t.name}),e===null).then(t=>{t&&k(e)})},children:l(`customize.scalar.remove`)}),M&&i(J,{variant:`outline`,size:`sm`,"data-testid":`event-add-${a}`,disabled:n.saving,onClick:()=>m(!0),children:l(`customize.scalar.add`)})]})]})})}),i(To,{open:p,mode:x?`change`:`add`,title:s,cap:a,targetId:c.id,host:t,target:n.target,enabled:v?.enabled!==!1,debounceMs:b?.draft.debounceMs??c.debounceMs,edges:c.edges,edge:ee,sources:A,canSave:O&&!n.saving,onClose:()=>m(!1),onSave:e=>{m(!1),k(ei(_,n.target,e))}})]})}function Fo({deviceId:t,cap:n,timestampPath:r,counterPath:a,startedAt:o}){let{t:s}=X(),c=Kr({deviceId:t,cap:n,path:r}),l=Kr({deviceId:t,cap:n,path:a}),u=No(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?``:Gi(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:Gi(u.lastPressedAt)}),u.pressCount===null?``:` · ${s(`customize.event.doorbellCount`,{count:u.pressCount})}`]})}function Io(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 Lo(e,t,n){return e?t===`pending`?`pending`:t===`unknown`?`unknown`:n?`present`:`absent`:`present`}function Ro(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 zo(t){let{t:n}=X(),r=t.mode===`change`?n(`customize.scalar.changeTitle`,{title:t.title}):n(`customize.scalar.addTitle`,{title:t.title});return i(er,{open:t.open,onOpenChange:e=>!e&&t.onClose(),children:e(Dn,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":r,children:[i(mr,{children:i(Sr,{children:r})}),t.open?i(Bo,{...t}):null]})})}function Bo(t){let{t:r}=X(),a=Sn({projection:`slim`}),s=ii(n(()=>a.status===`success`?ni(a.data):[],[a.status,a.data]),t.sources[0]),[c,l]=o(()=>Vo(t.sources)),[u,f]=o(null),[p,m]=o(!1);!p&&s!==null&&(f(s),m(!0));let[h,g]=o(t.timeoutMs/1e3),[_,v]=o((t.cooldownMs??0)/1e3),y=Ho(c),b=xo({cap:t.cap,targetId:t.targetId,device:t.target,timeoutMs:Math.round(h*1e3),cooldownMs:t.cooldownMs===null?void 0:Math.round(_*1e3),sources:y}),x=c[0];return e(d,{children:[e(Vn,{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(Yr,{kind:`event`,shape:`span`,enabled:t.open,hostId:t.host.id,devicePickerTestId:`event-span-picker`,destination:{cap:t.cap,targetId:t.targetId,title:t.title},device:u,picked:c,onDeviceChange:f,onPickedChange:e=>l(e.filter(e=>!(e.addonId===t.host.addonId&&e.stableId===t.host.stableId))),edges:[],edge:`rising`,onEdgeChange:()=>void 0,debounceSec:0,onDebounceSecChange:()=>void 0,sourceModes:t.sourceModes,timeoutSec:h,onTimeoutSecChange:g,cooldownSec:t.cooldownMs===null?null:_,onCooldownSecChange:v}),x!==void 0&&i(Uo,{deviceId:x.deviceId,cap:x.cap,fieldPath:x.fieldPath,timeoutMs:Math.round(h*1e3)})]}),e(an,{className:`flex flex-wrap gap-2`,children:[i(J,{variant:`ghost`,onClick:t.onClose,children:r(`customize.scalar.cancel`)}),i(J,{"data-testid":`event-save`,disabled:!t.canSave||b===null,onClick:()=>{b!==null&&t.onSave(b)},children:r(`customize.scalar.save`)})]})]})}function Vo(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 Ho(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 Uo({deviceId:e,cap:t,fieldPath:n,timeoutMs:r}){let{t:a}=X(),o=Kr({deviceId:e,cap:t,path:n}),s=o.kind===`value`&&typeof o.value==`boolean`?{kind:`level`,active:o.value,changedAt:null}:{kind:`unread`},c=G(Se,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(Wo(s,c.open))})}function Wo(e,t){return e.kind===`unread`?`customize.event.previewWaiting`:t?`customize.event.previewMotionOn`:e.active?`customize.event.previewSensorOn`:`customize.event.previewMotionOff`}c();function Go({device:n,availability:r,cap:a,title:s,view:c,sensors:l}){let{t:u}=X(),f=ir(),p=Vt(),m=hn({addonId:`pipeline-orchestrator`,deviceId:n.id,nodeId:`hub`}),[h,g]=o(!1),[_,v]=o(null),y=t(!1),[b,x]=o(!1),S=qo(l),C=ci(!0),w=Ce(c.id,S),T=Zo(Ri(m.data).motionCooldownMs,c.timeoutMs);if(r.kind===`absent`||!c.deviceTypes.includes(n.type))return null;let E=b||f.isPending||p.isPending,D=w.writable&&!E&&r.kind===`present`,O=async e=>{if(!w.writable||y.current){v(u(`customize.saveInFlight`));return}y.current=!0,x(!0);try{await wo(n.id,e,async e=>{await f.mutateAsync({deviceId:e.deviceId,config:e.config===null?null:{sensors:e.config.sensors.map(e=>({addonId:e.addonId,stableId:e.stableId,mode:e.mode}))}})},async e=>{let t={motionCooldownMs:e.patch.motionCooldownMs};await p.mutateAsync({deviceId:e.deviceId,patch:t})}),v(null),await l.refetch()===`failed`&&v(u(`customize.motion.refetchFailed`))}catch(e){v(e instanceof Error?e.message:String(e))}finally{y.current=!1,x(!1)}},k=w.rows.map(e=>({addonId:e.addonId,stableId:e.stableId,cap:`binary`,fieldPath:`on`,mode:e.mode,label:e.name}));return e(d,{children:[i(Qr,{id:a,icon:fe,title:s,testId:`event-card-${a}`,actions:i(K,{children:u(Mi(w.text,w.status.state))}),children:i(`div`,{className:`flex flex-col gap-2 px-3 py-2 sm:px-4`,children:r.kind===`pending`||S.kind===`pending`?i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:u(`customize.motion.reading`)}):r.kind===`unknown`||S.kind===`unknown`?i(Jo,{reason:Xo(S)||(r.kind===`unknown`?r.reason:``)}):e(d,{children:[i(Ko,{deviceId:n.id}),w.rows.length===0?i(`p`,{className:`text-xs text-foreground-subtle`,children:u(`customize.scalar.noOverride`)}):i(`ul`,{className:`flex flex-col gap-1`,children:w.rows.map(t=>e(`li`,{className:`text-xs text-foreground`,children:[Yo(t,C),t.reason===null?``:` — ${u(`customize.motion.state.${t.state}`)}`]},t.key))}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:u(`customize.event.timeoutSeconds`,{seconds:T/1e3})}),_!==null&&i(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:_}),i(`div`,{className:`flex flex-wrap gap-2`,children:i(J,{variant:`outline`,size:`sm`,"data-testid":`event-add-${a}`,disabled:!D,onClick:()=>g(!0),children:w.rows.length===0?u(`customize.scalar.add`):u(`customize.scalar.change`)})})]})})}),i(zo,{open:h,mode:w.rows.length===0?`add`:`change`,title:s,cap:a,targetId:c.id,host:n,target:{addonId:n.addonId,stableId:n.stableId},timeoutMs:T,cooldownMs:c.cooldownMs,sourceModes:c.sourceModes,sources:k,canSave:D,onClose:()=>g(!1),onSave:e=>{g(!1),O(e)}})]})}function Ko({deviceId:e}){let{t}=X(),n=Kr({deviceId:e,cap:`motion`,path:`detected`}),r=Kr({deviceId:e,cap:`motion`,path:`lastDetectedAt`}),a=jo(n.kind===`pending`?`pending`:n.kind!==`value`||typeof n.value!=`boolean`?`unknown`:n.value,r.kind===`value`&&typeof r.value==`number`?r.value:null,Date.now());return i(`p`,{role:`status`,className:`text-xs text-foreground`,children:t(a.kind===`active`?`customize.event.motionNow.active`:`customize.event.motionNow.${a.kind}`,a.seconds===null?void 0:{seconds:a.seconds})})}function qo(e){return e.presence===`pending`?{kind:`pending`}:e.status===null?{kind:`unknown`,reason:e.failureReason}:{kind:`known`,value:e.status}}function Jo({reason:e}){let{t}=X(),n=e.trim();return n.length===0?i(q,{message:t(`customize.motion.unreadableBare`)}):i(q,{title:t(`customize.motion.unreadable`,{reason:n}),message:n})}function Yo(e,t){if(t.kind!==`known`)return e.name;let n=t.value.find(t=>t.addonId===e.addonId&&t.stableId===e.stableId);return xi(e.name,n?.id??null,t.value.map(e=>({id:e.id,name:e.name,parentDeviceId:e.parentDeviceId??null})))}function Xo(e){return e.kind===`unknown`?e.reason??``:e.kind===`known`&&e.value.state===`unreadable`?e.value.reason:``}function Zo(e,t){return e!==null&&Number.isFinite(e)?e:t}var Qo=xe;function $o(e,t){let n=Qo[e];return n===void 0?null:n.targets.find(e=>e.id===t)??null}function es({device:e,handle:t,facts:n,sensors:r}){let{t:a}=X();return i(d,{children:si().map(o=>{let s=o.pulse??o.span;if(s===null||!s.deviceTypes.includes(e.type))return null;let c=$o(o.cap,s.id);if(c===null)return null;let l=a(o.pulse===null?`customize.motion.title`:`customize.doorbell.title`),u=Ni(Jr(o.cap,c),n);return o.pulse===null?o.span===null?null:i(Go,{device:e,availability:u,cap:o.cap,title:l,view:o.span,sensors:r},o.cap):i(Po,{device:e,handle:t,availability:u,cap:o.cap,title:l,view:o.pulse},o.cap)})})}function ts({id:t,icon:n,title:r,headerControl:a,addLabel:o,onAdd:s,addDisabled:c=!1,notices:l,suggestion:u,children:f}){let{t:p}=X(),m=s!==void 0&&o!==void 0;return e(Qr,{id:t,icon:n,title:r,actions:e(d,{children:[a,m&&!c&&u!==void 0&&u.count>0&&e(J,{variant:`ghost`,size:`sm`,onClick:u.onOpen,children:[i(re,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),p(`customize.suggest.hint`,{count:u.count,location:u.location})]}),m&&i(J,{variant:`outline`,size:`sm`,disabled:c,onClick:s,children:o})]}),children:[l!==void 0&&i(`div`,{className:`flex flex-col gap-1 px-3 pt-2 empty:hidden sm:px-4`,children:l}),i(`ul`,{className:`flex flex-col divide-y divide-border`,children:f})]})}function ns(e,t){if(e.kind!==`known`||typeof t!=`string`||t.length===0)return null;let n=Wn(e.value,t),r=new Map(e.value.map(e=>[e.id,e])),i=new Map;for(let e of n){let t=r.get(e)?.parentDeviceId,n=t==null?void 0:r.get(t);n!==void 0&&n.type===`container`&&i.set(e,n.name)}return{location:t,ids:n,containers:i}}function rs(e,t,n){return cr(e,t?.ids??new Set,n)}function is(e,t){return e?.containers.get(t)??null}function as(e,t,n){return e.kind===`known`?rs(e.value,t,n).suggested.length:0}function os(e,t){let n=[t,e.detail].filter(e=>e!==null&&e!==``);return n.length===0?null:n.join(` · `)}function ss({location:t,devices:n,action:r,onPick:a,onPickAll:o}){let{t:s}=X();if(n.length===0)return null;let c=s(`customize.suggest.heading`,{location:t});return e(`section`,{"aria-label":c,className:`flex flex-col gap-1`,children:[e(`div`,{className:`flex min-h-7 items-center gap-2`,children:[i(`h3`,{className:`${j} min-w-0 flex-1`,children:c}),o!==void 0&&n.length>1&&i(J,{variant:`ghost`,size:`sm`,onClick:o,children:s(`customize.suggest.addAll`,{count:n.length})})]}),i(`ul`,{className:`flex flex-col divide-y divide-border rounded-md border border-border`,children:n.map(t=>{let n=os(t,t.container===null||t.name.includes(t.container)?null:s(`customize.suggest.in`,{container:t.container}));return e(`li`,{className:`${A} flex items-center gap-3`,children:[e(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`text-xs text-foreground break-words`,children:t.name}),n!==null&&i(`div`,{className:`text-[11px] text-foreground-subtle break-words`,children:n})]}),i(J,{variant:`outline`,size:`sm`,"aria-label":s(r===`add`?`customize.suggest.addNamed`:`customize.suggest.useNamed`,{name:t.name}),onClick:()=>a(t.id),children:s(r===`add`?`customize.suggest.add`:`customize.suggest.use`)})]},t.id)})})]})}c();function cs(e){return e.kind===`pending`?`pending`:e.kind===`unknown`?`failed`:`answered`}function ls(e){return e.map(e=>({id:e.deviceId,name:e.name,...e.meta===null?{}:{type:e.meta},...e.detail===null?{}:{location:e.detail.includes(` · `)?e.detail.split(` · `).at(-1)??null:e.detail},...e.detail===null?{}:{detail:e.detail}}))}function us({open:t,title:r,selection:s,candidates:c,filters:l,room:u=null,confirmLabel:d,onConfirm:f,onClose:p}){let{t:m}=X(),[h,g]=o(null),[_,v]=o([]),y=l?.find(e=>e.id===h)??l?.[0]??null,b=c.kind===`known`?c.value:[],x=c.kind===`known`?Ii(c.value,``,y):[],S=rs(b,u,e=>e.deviceId).suggested,C=rs(x,u,e=>e.deviceId).others,w=n(()=>ls(C),[C]),T=cs(c),E=b.filter(e=>_.includes(e.deviceId));a(()=>{t||(v([]),g(null))},[t]);let D=()=>{v([]),g(null),p()},O=e=>{e.length!==0&&(f(e),v([]),g(null))},k=()=>O(E);return i(er,{open:t,onOpenChange:e=>e?void 0:D(),children:e(Dn,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":r,children:[i(mr,{children:i(Sr,{children:r})}),e(Vn,{className:`flex flex-col gap-2 p-2 sm:p-4`,children:[l!==void 0&&l.length>0&&i(`div`,{className:`flex flex-wrap gap-1`,role:`tablist`,"aria-label":m(`customize.assign.filtersLabel`),children:l.map(e=>i(`button`,{type:`button`,role:`tab`,"aria-selected":(y?.id??null)===e.id,className:`inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${(y?.id??null)===e.id?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:bg-surface-hover`}`,onClick:()=>g(e.id),children:m(e.labelKey)},e.id))}),u!==null&&i(ss,{location:u.location,devices:S.map(e=>({id:e.deviceId,name:e.name,container:is(u,e.deviceId),detail:e.detail})),action:`add`,onPick:e=>O(S.filter(t=>t.deviceId===e)),...s===`multi`?{onPickAll:()=>O(S)}:{}}),c.kind===`unknown`?i(`p`,{role:`alert`,className:`text-xs text-warning`,children:m(`customize.assign.unknown`,{reason:c.reason})}):w.length===0&&S.length>0?null:i(Pt,{devices:w,listState:T,value:_,onChange:e=>v(s===`single`?e.length>0?[e[e.length-1]]:[]:e),noun:`device`,emptyLabel:m(`customize.assign.none`),showAll:!0,testId:`customize-device-picker`})]}),e(an,{children:[i(J,{variant:`ghost`,onClick:D,children:m(`customize.picker.cancel`)}),i(J,{disabled:E.length===0,onClick:k,children:d(E.length)})]})]})})}c();function ds(e,t){let r=typeof e==`string`&&e.length>0,i=ci(t&&r);return n(()=>t?ns(i,e):null,[t,i,e])}c();function fs(e){return e==null?null:e.message}function ps({device:t}){let n=ue(),{t:r}=X(),a=l(),s=ri(),c=we.includes(t.type),[u,f]=o(!1),[p,m]=o(!1),[h,g]=o(null),_=Ft({deviceId:t.id},{enabled:c}),v=Zi({status:_.status,data:_.data,error:fs(_.error)===null?null:{message:fs(_.error)??``}}),y=v.kind===`present`?v.slot.slotRef:``,b=v.kind===`present`?[...Yi(v.slot,v.value).map(e=>e.deviceId),...Ji(v.slot,v.value)]:[],x=Cr(),S=ci(c&&v.kind===`present`&&(u||b.length>0)),C=ds(t.location,c&&v.kind===`present`),w=yt({deviceId:t.id,slotRef:y},{enabled:(u||C!==null)&&v.kind===`present`});if(!c||v.kind===`absent`)return null;if(v.kind!==`present`)return i(ts,{id:`linked`,icon:I,title:r(`customize.linked.title`),notices:v.kind===`pending`?i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`customize.assign.checking`)}):i(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:r(`customize.assign.unknown`,{reason:v.reason})}),children:null});let T=v.value,E=new Map(S.kind===`known`?S.value.map(e=>[e.id,e]):[]),D=T.trackedDeviceIds!==void 0,O=(e,t)=>{let n=E.get(e.deviceId);return{...e,name:e.name??n?.name??null,type:n?.type??null,detail:n===void 0?null:Li(n.integration,n.location),orphan:t}},k=[...Yi(v.slot,T).map(e=>O(e,!1)),...Ji(v.slot,T).map(e=>O({deviceId:e,name:null,health:`ok`,implied:!1,tracked:!0},!0))],A=new Set(b),j=S.kind===`unknown`?S:w.status===`error`?{kind:`unknown`,reason:fs(w.error)??r(`helpers.customize.requestFailed`)}:S.kind===`pending`||w.status===`pending`||w.data===void 0?{kind:`pending`}:{kind:`known`,value:$i(w.data.candidates,E,A)},ee=async e=>{if(p){g(r(`customize.saveInFlight`));return}m(!0),g(null);try{await x.mutateAsync({deviceId:t.id,slotRef:v.slot.slotRef,value:e}),await _.refetch(),await a.invalidateQueries({queryKey:[[`deviceManager`]]})}catch(e){g(e instanceof Error?e.message:String(e))}finally{m(!1)}},te=async e=>{await s(r(`customize.linked.removeWhat`,{name:e.name??`#${e.deviceId}`}),!1)&&await ee(Qi(T,e.deviceId))},M=[{key:`device`,header:r(`customize.linked.device`),cell:t=>e(`div`,{className:`flex flex-col min-w-0`,children:[i(`span`,{className:`truncate text-xs text-foreground`,children:t.name??`#${t.deviceId}`}),t.detail!==null&&i(`span`,{className:`truncate text-[11px] text-foreground-subtle`,children:t.detail}),t.orphan&&i(`span`,{className:`text-[11px] text-foreground-subtle`,children:r(`customize.linked.notLinked`)}),t.health!==`ok`&&i(`span`,{role:`alert`,className:`text-[11px] text-warning`,children:r(`customize.linked.health.${t.health}`)})]})},{key:`type`,header:r(`customize.linked.type`),headerClassName:`hidden sm:table-cell`,cellClassName:`hidden sm:table-cell text-xs text-foreground-subtle`,cell:e=>e.type===null?`—`:Qn(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(Jt,{checked:e.tracked,disabled:p,"aria-label":r(`customize.linked.trackFor`,{name:e.name??e.deviceId}),onCheckedChange:t=>void ee(Xi(T,e.deviceId,t))})}]:[],{key:`remove`,header:``,cellClassName:`text-right w-10`,cell:e=>e.implied||e.orphan?null:i(yn,{icon:P,variant:`ghost`,size:`sm`,"aria-label":r(`customize.assign.removeNamed`,{name:e.name??e.deviceId}),disabled:p,onClick:t=>{t.stopPropagation(),te(e)}})}];return e(d,{children:[i(ts,{id:`linked`,icon:I,title:r(`customize.linked.title`),addLabel:r(`customize.linked.add`),onAdd:p?void 0:()=>f(!0),...C===null?{}:{suggestion:{count:as(j,C,e=>e.deviceId),location:C.location,onOpen:()=>f(!0)}},notices:e(d,{children:[S.kind===`unknown`&&i(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:r(`customize.assign.devicesUnreadable`,{reason:S.reason})}),h!==null&&i(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:h})]}),children:e(`li`,{className:`list-none px-3 py-2 sm:px-4`,children:[k.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`customize.assign.none`)}):i(Pn,{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:Qn(e.type,n).label,columns:M,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(us,{open:u,title:r(`customize.linked.pickTitle`),selection:`multi`,candidates:j,room:C,confirmLabel:e=>r(`customize.assign.addCount`,{count:e}),onConfirm:e=>{f(!1),ee(qi(T,e.map(e=>e.deviceId)))},onClose:()=>f(!1)})]})}c();function ms(e){return e instanceof Error?e.message:String(e)}function hs(e){let n=rt({addonId:e.addonId,stableId:e.stableId}),r=vr(),i=St(),a=Lt(),s=$r({status:n.status,data:n.data,error:n.error===null||n.error===void 0?null:{message:n.error.message}}),{t:c}=X(),l=t(!1),[u,d]=o(!1),f=async e=>{let t=Zr(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:ms(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 gs=`pipeline-orchestrator`;function _s(e){return e.data===void 0?e.status===`pending`?`pending`:e.status===`error`?`unknown`:`pending`:e.data.cameraSensors===void 0?`absent`:`present`}function vs(e,t){return e===`absent`?`absent`:_s(t)}async function ys(e){try{return(await e()).isError?`failed`:`answered`}catch{return`failed`}}function bs(e,t){let n=In(gs),r=at({deviceId:e},{enabled:t&&n!==`absent`}),i=()=>ys(r.refetch),a=r.data===void 0&&r.status===`error`?r.error?.message??null:null;return t?{presence:vs(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 xs(e,t){let n=tt({deviceType:e.type}),r=cn({deviceId:e.id}),i=vn({deviceId:e.id}),a=ui(n,e=>new Set(e.caps.map(e=>e.cap))),o=ui(r,e=>oi(e.entries)),s=ui(i,e=>e);return{deviceType:e.type,composable:a,nativeCaps:o,wireable:s,composed:new Set((t?.features??[]).map(e=>e.cap))}}function Ss(e,t,n){let r=t.kind===`known`&&t.value.has(`consumables`),i=Kr(r?{deviceId:e,cap:di,path:ji}:null);return Pi(t,n,r?i:null)}c();function Cs({device:t}){let{t:r}=X(),a=t.stableId.startsWith(`composed-`)?t.stableId.slice(Fe.length):null,o=Bt({blockId:a??``},{enabled:a!==null}),s=St(),c=Et(),l=Fn(),u=n(()=>{let e=new Set;for(let{cap:t}of Ci())e.add(t);for(let{cap:t}of _i())e.add(t);for(let{cap:t}of si())e.add(t);return e},[]);if(a===null)return i(`p`,{className:`text-xs text-foreground-subtle`,children:r(`customize.composed.missingBlock`)});if(o.status===`pending`)return i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`customize.loadingDevice`)});if(o.status===`error`)return i(q,{title:r(`customize.composed.loadFailed`),message:o.error.message,onRetry:()=>void o.refetch()});if(o.data.state===`not-loaded`)return i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`customize.status.notLoaded`,{reason:o.data.reason})});let d=o.data.view;if(d===null)return i(`p`,{className:`text-xs text-foreground-subtle`,children:r(`customize.composed.notFound`)});let f=Le(d.block);if(f===null)return i(`p`,{className:`text-xs text-foreground-subtle`,children:r(`compositionEditor.notComposition`)});if(Ti(f)){let n=Di(f.helper,t.name,t.location??``);return n===null?i(`p`,{role:`alert`,children:r(`helper.unreadable`)}):e(`div`,{className:`flex flex-col gap-3`,children:[i(vo,{device:t}),i(ki,{initial:n,start:`parameters`,saving:s.isPending,onSave:e=>gi(e,async(n,r)=>{await s.mutateAsync({blockId:d.block.id,expectedUpdatedAt:d.block.updatedAt,block:{composition:n,...r===``?{}:{name:r}}}),r!==``&&r!==t.name&&await c.mutateAsync({deviceId:t.id,name:r}),e.room.trim()!==``&&e.room.trim()!==(t.location??``)&&await l.mutateAsync({deviceId:t.id,location:e.room.trim()}),await o.refetch()})})]})}let p={target:{addonId:t.addonId,stableId:t.stableId},state:{kind:`present`,view:d,composition:f},saving:s.isPending,save:async e=>{if(e===null)return{kind:`refused`,reason:r(`customize.composed.noDelete`)};try{return await s.mutateAsync({blockId:d.block.id,expectedUpdatedAt:d.block.updatedAt,block:{composition:e}}),await o.refetch(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:e instanceof Error?e.message:String(e)}}}};return e(`div`,{className:`flex flex-col gap-3`,children:[i(vo,{device:t}),Fi(f)===`incomplete`&&i(K,{variant:`warning`,children:r(`customize.blockStatus.incomplete`)}),i(Xr,{device:t,handle:p,skipCaps:u})]})}c();function ws({deviceId:e}){let{t}=X(),n=gn({deviceId:e}),r=n.data;if(r==null)return n.status===`error`?i(q,{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(Cs,{device:r}):i(Ts,{device:r,target:{addonId:r.addonId,stableId:r.stableId}});return i(Mr,{deviceId:r.id,seed:{name:r.name,location:r.location??``,role:r.role??null,display:r.display},children:a})}function Ts({device:t,target:r}){let a=hs(r),o=In(`composer`),{t:s}=X(),c=bs(t.id,t.type===W.Camera),l=xs(t,li(a.state)),u=Ss(t.id,l.nativeCaps,l.wireable),d={deviceType:t.type,composable:l.composable,nativeCaps:l.nativeCaps,cameraSensors:c.presence},f=n(()=>{let e=new Set;for(let{cap:t}of Ci())e.add(t);for(let{cap:t}of _i())e.add(t);for(let{cap:t}of si())e.add(t);return e},[]);return e(`div`,{className:`flex flex-col gap-3`,children:[i(vo,{device:t}),o===`absent`&&i(`p`,{role:`alert`,className:`text-xs text-warning`,children:s(`customize.composerAbsent`)}),a.state.kind!==`none`&&i(Es,{state:a.state}),i(es,{device:t,handle:a,facts:d,sensors:c}),i(Ei,{device:t,handle:a,facts:d}),i(vi,{device:t,handle:a,facts:d,defaults:u}),i(Xr,{device:t,handle:a,skipCaps:f}),i(ps,{device:t})]})}function Es({state:t}){let{t:n}=X();switch(t.kind){case`pending`:return i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:n(`customize.status.pending`)});case`unknown`:return i(q,{title:n(`customize.status.unknownTitle`),message:t.reason});case`not-loaded`:return i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:n(`customize.status.notLoaded`,{reason:t.reason})});case`none`:return null;case`present`:{let r=t.view.block;return e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(K,{variant:r.status===`running`?`success`:r.status===`failed`?`danger`:`warning`,children:n(`customize.blockStatus.${r.status}`)}),!r.enabled&&i(K,{variant:`default`,children:n(`customize.status.off`)}),r.lastError!==void 0&&i(`span`,{className:`text-[11px] text-foreground-muted break-words`,children:r.lastError}),t.view.state.kind===`unreachable`&&i(`span`,{className:`text-[11px] text-warning`,children:n(`customize.status.composerUnreachable`,{reason:t.view.state.error})})]})}}}var Ds=`overview`;function Os(e,t){return e.some(e=>e.id===t)?t:Ds}function ks({deviceId:t}){let{t:n}=X(),r=l(),a=Number.isFinite(t),{data:o}=gn({deviceId:t},{enabled:a}),s=typeof o?.type==`string`?o.type:`camera`;nr([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:c,isLoading:u,isError:d,error:f}=cn({deviceId:t},{enabled:a}),{data:p}=$n({deviceType:s},{enabled:!!s}),m=It({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(Ke,{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(As,{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(js,{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(Ms,{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(Lr,{i18nKey:`device.bindingsTab.boundSummary`,count:_.length,values:{bound:v},components:{b:i(`span`,{className:`font-medium text-foreground`}),em:i(`em`,{})}})}),i(hr,{columns:y,rows:_,rowKey:e=>e.capName,minWidthPx:720})]})}function As({kind:t}){let{t:n}=X();return t===`native`?e(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-success/30 text-success bg-success/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[i(ae,{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(Ye,{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(I,{className:`h-3 w-3`}),n(`device.bindingsTab.linked`)]}):e(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border text-foreground-subtle/70 px-1.5 py-0.5 text-[10px] font-medium`,children:[i(x,{className:`h-3 w-3`}),n(`common.unbound`)]})}function js({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 Ms({wrappers:t,activeWrapperId:n,disabled:r,onPick:a}){let{t:o}=X();return t.length===0?i(`span`,{className:`text-[10px] opacity-40`,children:o(`device.bindingsTab.noneAvailable`,`none available`)}):i(`div`,{className:`flex flex-wrap gap-1`,children:t.map(t=>{let s=t===n;return e(`button`,{disabled:r,onClick:()=>a(t),title:s?o(`device.bindingsTab.clickToDeactivateRevertTo`,`Click to deactivate (revert to native)`):o(`device.bindingsTab.activateWrapper`,`Activate wrapper {{wrapperId}}`,{wrapperId:t}),className:`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 font-mono text-[10px] transition-colors disabled:opacity-50 ${s?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[i(s?O:he,{className:`h-3 w-3`}),t]},t)})})}function Ns({deviceId:t,activeSubTab:n,onSubTabChange:r,deviceType:a,isAdmin:o}){return e(`div`,{className:`flex flex-col gap-3`,children:[Ar(a,o)&&i(yr,{deviceId:t,readOnly:!0}),i(kr,{deviceId:t,activeSubTab:n,onSubTabChange:r})]})}c();var Ps=[[`pipelineOrchestrator`,`getCameraDetectionSource`]];function Fs(e){let t=l(),n=wt({deviceId:e},{refetchOnMount:`always`}),i=Gn(),[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:Ps})}catch(e){u(e instanceof Error?e.message:`Could not change the root detector`),await t.invalidateQueries({queryKey:Ps})}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 Is=`object-detection`;function Ls(e){return[e.addonId,...e.children.flatMap(Ls)]}function Rs(e,t){if(e===`pipeline`)return new Set;let n=zs(t,Is);return n===void 0?new Set:new Set(e===`onboard`?[n.addonId]:Ls(n))}function zs(e,t){for(let n of e){if(n.addonId===t)return n;let e=zs(n.children,t);if(e!==void 0)return e}}function Bs(e,t){return e===`onboard`?Y.t(`helpers.detectionSourceModel.badgeCameraAi`):t===`object-detection`?Y.t(`helpers.detectionSourceModel.badgeNoRoot`):Y.t(`helpers.detectionSourceModel.badgeIdle`)}function Vs(e){switch(e){case`pipeline`:return Y.t(`helpers.detectionSourceModel.explainPipeline`);case`onboard`:return Y.t(`helpers.detectionSourceModel.explainOnboard`);case`none`:return Y.t(`helpers.detectionSourceModel.explainNone`)}}function Hs(e){switch(e){case`boxed`:return``;case`while-streaming`:return Y.t(`helpers.detectionSourceModel.geometryWhileStreaming`);case`flag-only`:return Y.t(`helpers.detectionSourceModel.geometryFlagOnly`);case`unknown`:return Y.t(`helpers.detectionSourceModel.geometryUnknown`)}}function Us(e,t){return e===`onboard`?Y.t(`helpers.detectionSourceModel.noticeOnboard`):t===`object-detection`?Y.t(`helpers.detectionSourceModel.noticeNoRoot`):Y.t(`helpers.detectionSourceModel.noticeIdle`)}var Ws=[`pl-2`,`pl-6`,`pl-10`,`pl-14`],Gs={detector:`success`,cropper:`info`,classifier:`primary`,refiner:`warning`,"audio-classifier":`neutral`};function Ks(e){return Ws[Math.min(e,Ws.length-1)]??`pl-2`}function qs(e){return e.zoneDriven?{kind:`zone-driven`}:{kind:`gate`,effectiveOn:e.ownOn,defaultOn:e.defaultOn,explicit:e.choice!==`auto`}}function Js(e,t,n){return e.kind===`parent`?n:Bs(e.source,t)}function Ys({inputs:t,outputs:n}){return t.length===0&&n.length===0?null:e(`span`,{className:`inline-flex flex-wrap items-center gap-1`,children:[t.map(e=>i(K,{size:`sm`,variant:`info`,children:e},`in-${e}`)),t.length>0&&n.length>0&&i(`span`,{className:`text-[10px] text-foreground-subtle`,"aria-hidden":!0,children:`→`}),n.map(e=>i(K,{size:`sm`,variant:`success`,children:e},`out-${e}`))]})}function Xs({rows:t,label:n,selectedId:r,busy:a,onOpen:o,onSet:s}){let{t:c}=X(),l=e=>{switch(e){case`detector`:return c(`device.cameraStepInspector.kindDetector`,`detector`);case`cropper`:return c(`device.cameraStepInspector.kindCropper`,`cropper`);case`classifier`:return c(`device.cameraStepInspector.kindClassifier`,`classifier`);case`refiner`:return c(`device.cameraStepInspector.kindRefiner`,`refiner`);case`audio-classifier`:return c(`device.cameraStepInspector.kindAudio`,`audio`)}},u=c(`device.cameraStepInspector.offBecauseParent`,`Off because its parent is off`);return i(`ul`,{"aria-label":n,className:`divide-y divide-border rounded-md border border-border`,children:t.map(t=>{let n=t.stepId===r,c=t.blocked===null?null:Js(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 ${Ks(t.depth)} ${n?`bg-primary/10`:t.runs?``:`bg-muted/40`}`,children:[e(`button`,{type:`button`,"aria-expanded":n,onClick:()=>o(t.stepId),className:`flex min-w-0 flex-1 flex-wrap items-center gap-x-2 gap-y-1 text-left`,children:[i(`span`,{className:`text-sm font-medium ${t.runs?`text-foreground`:`text-foreground-muted`}`,children:t.name}),i(K,{size:`sm`,variant:Gs[t.kind],children:l(t.kind)}),i(Ys,{inputs:t.inputs,outputs:t.outputs}),c!==null&&i(`span`,{className:`text-[11px] text-warning`,children:c})]}),i(ln,{gate:qs(t),busy:a,onSet:e=>s(t.stepId,e)})]},t.stepId)})})}function Zs(e,t){let n=e?.[t];return n===void 0?`auto`:n?`on`:`off`}function Qs(e,t){return e===`auto`?t:e===`on`}function $s(e,t,n){return e!==`onboard`&&e!==`none`||!n.has(t)?null:{kind:`source`,source:e}}function ec(e,t,n,r,i){let a=e.zoneDrivenIds??new Set;return t.flatMap(t=>{let o=a.has(t.addonId),s=Zs(e.toggles,t.addonId),c=e.defaults[t.addonId]??!0,l=o||Qs(s,c),u=r===null?$s(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,...ec(e,t.children,n+1,f,i)]})}function tc(e){let t=e.source===null?new Set:Rs(e.source,e.tree);return ec(e,e.tree,0,null,t)}function nc({source:t,geometry:n,saving:r,error:a,onPick:o}){let{t:s}=X(),c=n===`flag-only`,l=Hs(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:j,children:s(`device.detectionSourceControl.rootDetector`,`Root detector`)}),i(Nn,{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:ge,children:[Vs(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 rc=new Set([`package-detection`]),ic=`/system/pipeline?view=nodes`;function ac(e){return Object.fromEntries(e.slots.flatMap(e=>e.addons.map(e=>[e.id,e.enabledByDefault??!0])))}function oc({deviceId:a}){let{t:c}=X(),u=Yt(),d=Yn(),f=l(),p=R().trpcClient,m=t(null),h=t(null),g=At({deviceId:a},{refetchOnMount:`always`}),_=_t(void 0,{refetchOnMount:`always`});nr([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let{nodes:v}=Bn(),y=n(()=>{let e=new Set((_.data??[]).map(e=>e.nodeId));return v.filter(t=>t.isOnline&&e.has(t.id)).map(e=>({id:e.id,name:e.name}))},[_.data,v]),b=y.map(e=>e.id).join(`,`),x=s({enabled:y.length>0,queryKey:[[`pipelineExecutor`,`getSchema`],`camera-step-schemas`,b],queryFn:async()=>{let e={};for(let t of y)try{e[t.id]=await p.pipelineExecutor.getSchema.query({nodeId:t.id})}catch{}return e}}),S=r(()=>{f.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]})},[f]),C=sn({onSuccess:S}),w=jn(),[T,E]=o(null),[D,O]=o(!1),[k,A]=o(null),j=Fs(a),ee=x.data??{},te=g.data??null,M=y.map(e=>ee[e.id]).find(e=>e!==void 0)??null,ne=n(()=>M?nn(M):[],[M]),re=n(()=>M===null?[]:tc({tree:ne,toggles:te?.stepToggles,defaults:ac(M),source:j.source,zoneDrivenIds:rc}),[ne,M,te?.stepToggles,j.source]),{selection:N,open:ie,close:ae}=Vi(n(()=>re.map(e=>e.stepId),[re]),[]),F=y[0]?.id,oe=r(async e=>{if(T!==null){if(!await u({title:c(`stepInspector.stepMatrixFrame.discardUnsavedChanges`,`Discard unsaved changes?`),message:c(`stepInspector.stepMatrixFrame.thisStepHasChangesThat`,`This step has changes that are not saved yet.`),confirmLabel:c(`stepInspector.stepMatrixFrame.discard`,`Discard`),variant:`danger`}))return;E(null)}e()},[u,T,c]),se=e=>{e!==N.stepId&&oe(()=>ie({stepId:e}))},I=()=>{oe(()=>ae())};if(_.isLoading||y.length>0&&x.isLoading)return i(`div`,{className:`animate-pulse p-4 text-xs text-foreground-subtle`,children:c(`device.cameraStepInspector.loadingPipeline`,`Loading pipeline…`)});if(y.length===0)return i(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:c(`device.cameraStepInspector.noPipelineNodeIsOnline`,`No pipeline node is online.`)});if(M===null)return i(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:c(`device.cameraStepInspector.catalogUnavailable`,`Catalog unavailable.`)});let L=e=>_.data?.find(e=>e.nodeId===F)?.settings.stepSettings?.[e]??{},z=re.find(e=>e.stepId===N.stepId)??null,B=z===null?null:Bi(M,z.stepId),ce=d?i(ur,{onClick:I}):i(yn,{icon:P,variant:`ghost`,size:`sm`,"aria-label":c(`common.close`,`Close`),onClick:I});return e(`div`,{ref:m,className:`space-y-2`,children:[j.view?.onboard.available===!0&&j.source!==null&&i(nc,{source:j.source,geometry:j.view.onboard.geometry,saving:j.saving,error:j.error,onPick:e=>void j.pick(e)}),i(`p`,{className:ge,children:i(Lr,{i18nKey:`device.cameraStepInspector.modelsChosenByAccelerators`,components:{nodes:i(Gr,{to:ic,className:`font-medium text-primary hover:underline`})}})}),N.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:N.staleStepId})}),i(Xs,{rows:re,label:c(`device.cameraStepInspector.detectionStepsOfThisCamera`,`Detection steps of this camera`),selectedId:N.stepId,busy:C.isPending,onOpen:se,onSet:(e,t)=>C.mutate({deviceId:a,addonId:e,enabled:t})}),i(ar,{open:z!==null&&B!==null,anchor:m,onClose:I,label:c(`stepInspector.stepMatrixFrame.stepSettings`,`Step settings`),children:z!==null&&B!==null&&i(sc,{addon:B,nodeBag:L(z.stepId),storedCamera:te?.stepSettings?.[z.stepId],draft:T?.stepId===z.stepId?T:null,saving:D,status:k,notice:z.blocked?.kind===`source`?Us(z.blocked.source,z.stepId):null,closeButton:ce,onEscape:I,headingRef:e=>{h.current=e},onDraft:e=>{A(null),E({stepId:z.stepId,camera:e})},onDiscard:()=>E(null),onSave:async e=>{O(!0);try{await w.mutateAsync({deviceId:a,addonId:z.stepId,settings:Object.keys(e).length>0?{...e}:null}),E(null),A({kind:`saved`})}catch(e){A({kind:`error`,error:e instanceof Error?e.message:c(`device.cameraStepInspector.saveFailed`)})}finally{O(!1),S()}}})})]})}function sc({addon:t,nodeBag:n,storedCamera:r,draft:a,saving:o,status:s,notice:c,closeButton:l,onEscape:u,headingRef:d,onDraft:f,onDiscard:p,onSave:m}){let{t:h}=X(),g=en(t),_=Ui(g),v=Hi(g),y=a?.camera??r,b=a!==null&&!Ne(a.camera,r??{});return i(xn,{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:ge,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(cc,{addon:t,fields:_,nodeBag:n,cameraBag:y,onChange:f}):i(`p`,{className:ge,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 cc({addon:e,fields:t,nodeBag:n,cameraBag:r,onChange:a}){let{t:o}=X();return i(Zt,{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 lc(e,t,n){return{id:e,get label(){return Y.t(t)},icon:n}}var uc=[lc(`object-detection`,`helpers.detectionSettingsGroups.objectDetection`,`scan-search`),lc(`tracking`,`helpers.detectionSettingsGroups.tracking`,`route`),lc(`motion`,`helpers.detectionSettingsGroups.motion`,`activity`),lc(`stationary`,`helpers.detectionSettingsGroups.stationary`,`square-parking`),lc(`zones`,`helpers.detectionSettingsGroups.zones`,`shapes`),lc(`audio`,`helpers.detectionSettingsGroups.audio`,`volume-2`),lc(`cluster`,`helpers.detectionSettingsGroups.cluster`,`server`)],dc={"pipeline-object-detection":`object-detection`,"detection-sensitivity":`object-detection`,"onboard-object-detection":`object-detection`,tracking:`tracking`,"tracking-core":`tracking`,"motion-tuning":`motion`,"stationary-objects":`stationary`,occupancy:`stationary`,zones:`zones`,"pipeline-audio":`audio`,"cluster-assignment":`cluster`,"orchestrator-live":`cluster`};function fc(e){return dc[e]??`object-detection`}c();var pc=`steps`,mc=`settings`,hc=new Set([pc,mc]);function gc(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}function _c({deviceId:t,activeSubTab:n,onSubTabChange:a}){let{t:o}=X();return e(Qe,{value:n&&hc.has(n)?n:pc,onValueChange:r(e=>{a?.(e)},[a]),className:`flex flex-col`,children:[e(ut,{className:`flex-shrink-0`,children:[i(Ut,{value:pc,children:o(`device.detectionPipelineTab.steps`,`Steps`)}),i(Ut,{value:mc,children:o(`device.detectionPipelineTab.settings`,`Settings`)})]}),i(Kt,{value:pc,children:i(oc,{deviceId:t})}),i(Kt,{value:mc,children:i(kr,{deviceId:t,sectionFilter:gc,subTabGrouping:{groupOf:e=>fc(e.id),tabs:uc}})})]})}var vc=`Notifications`,yc={i18nKey:`device.deviceNotificationMute.cameraCostWhenOff`,text:`This camera never notifies — no rule, no target, no alarm. Existing events, tracks and recordings are unaffected.`},bc={i18nKey:`device.deviceNotificationMute.deviceCostWhenOff`,text:`This device never notifies — no rule, no target, no alarm.`};function xc(e){let{mutedDeviceIds:t,deviceId:n}=e,r=t===null?null:!t.includes(n),i=e.pendingOn??null;return{label:vc,on:r===null?null:i??r,available:r!==null,costWhenOff:e.isCamera?yc:bc}}function Sc(e,t){return!e.available||e.on===null?null:{deviceId:t,muted:e.on}}c();function Cc(e){if(typeof e!=`object`||!e)return null;let t={...e}.mutedDeviceIds;return Array.isArray(t)?t.filter(e=>typeof e==`number`):null}function wc({deviceId:t,isCamera:n}){let{t:a}=X(),s=l(),c=Number.isFinite(t),[u,d]=o(null),[f,p]=o(null),m=xc({mutedDeviceIds:Cc(Jn({},{enabled:c}).data),deviceId:t,isCamera:n,pendingOn:f}),h=a(m.costWhenOff.i18nKey,m.costWhenOff.text),g=pn({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=Sc(m,t);e!==null&&(p(!e.muted),g.mutate(e))},[t,g,m]),v=m.on===null,y=m.on===!1,b=y?Ge:D;return e(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[e(`div`,{className:`border-b border-border px-4 py-2 flex items-center justify-between gap-2`,children:[i(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:a(`device.deviceNotificationMute.notifications`,`Notifications`)}),y&&i(`span`,{className:`rounded bg-warning/20 px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wide text-warning`,children:a(`common.muted`)})]}),e(`div`,{className:`px-4 py-3 flex items-start gap-3`,children:[e(`button`,{type:`button`,role:`switch`,"aria-label":m.label,"aria-checked":m.on===!0,disabled:!m.available||g.isPending,onClick:_,title:v?a(`device.deviceNotificationMute.notificationMuteStateUnknownThe`,`Notification mute — state unknown; the notification centre did not answer.`):y?a(`device.deviceNotificationMute.muted`,`Muted. {{costWhenOff}}`,{costWhenOff:h}):a(`device.deviceNotificationMute.notifyingMutingIt`,`Notifying. Muting it: {{costWhenOff}}`,{costWhenOff:h}),className:`inline-flex items-center gap-1.5 rounded-lg border px-2 py-1.5 text-[11px] font-medium transition-colors disabled:cursor-not-allowed ${u===null?v?`border-dashed border-border text-foreground-subtle/50`:y?`border-warning/40 text-warning hover:bg-warning/10`:`border-success/30 text-success hover:bg-success/10`:`border-danger/50 text-danger bg-danger/5`}`,children:[i(b,{className:`h-3.5 w-3.5`}),i(`span`,{children:v?a(`device.deviceNotificationMute.unknown`,`Unknown`):y?a(`device.deviceNotificationMute.muted2`,`Muted`):a(`device.deviceNotificationMute.notifying`,`Notifying`)})]}),i(`p`,{className:`flex-1 text-[11px] leading-relaxed text-foreground-subtle`,children:u===null?v?a(`device.deviceNotificationMute.theNotificationCentreDidNot`,`The notification centre did not answer, so this device’s mute state is unknown.`):h:a(`device.deviceNotificationMute.writeFailed`,`Write failed: {{failure}}`,{failure:u})})]})]})}c();function Tc({template:t,members:n,fleet:a,fleetKind:s,snapshot:c,nameOf:l}){let{t:u}=X(),[f,p]=o(()=>new Map),m=r((e,t)=>{p(n=>{if(jc(n.get(e),t))return n;let r=new Map(n);return r.set(e,t),r})},[]);if(t.family!==`actuator`)return null;let h=wi(c),g=t.id===`light`?Ai(n.map(e=>f.get(Ac(e))??{kind:`pending`})):null;return e(d,{children:[t.id===`light`&&n.map(e=>i(Oc,{member:e,row:kc(a,e),fleetKind:s,onRead:m},Ac(e))),g!==null&&i(Ec,{view:g}),e(`div`,{"data-testid":`helper-commands`,children:[i(`h3`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:u(`helper.commandTitle`)}),h.kind===`pending`&&i(`p`,{role:`status`,className:`mt-1 text-xs text-foreground-subtle`,children:u(`helper.reportingPending`)}),h.kind===`unavailable`&&i(q,{title:u(`helper.outputUnavailable`),message:h.message}),h.kind===`none`&&i(`p`,{className:`mt-1 text-xs text-foreground-muted`,children:u(`helper.commandNone`)}),h.kind===`rows`&&i(Dc,{view:h,nameOf:l})]})]})}function Ec({view:t}){let{t:n}=X();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`&&t.caps.length<=1&&i(`p`,{className:`mt-1 text-xs text-foreground-muted`,children:n(`helper.sharedNone`)}),t.kind===`ready`&&t.caps.length>1&&e(`ul`,{className:`mt-1 flex flex-col gap-0.5 text-xs text-foreground`,children:[t.caps.filter(e=>e!==`switch`).map(e=>i(`li`,{children:n(`helper.cap.${e}`)},e)),t.modes.map(e=>i(`li`,{children:n(`helper.mode.${e}`)},e))]})]})}function Dc({view:t,nameOf:n}){let{t:r}=X();return i(`ul`,{className:`mt-1 flex flex-col gap-0.5 text-xs text-foreground`,"data-testid":`helper-command-rows`,children:t.rows.map(t=>e(`li`,{children:[n(t.deviceId),` — `,r(`helper.cap.${t.cap}`),` —`,` `,t.ok?r(`helper.commandOk`):r(`helper.commandFailed`),t.error===null?``:` — ${t.error}`]},`${t.deviceId}:${t.cap}:${t.at}`))})}function Oc({member:e,row:t,fleetKind:n,onRead:r}){let i=Ac(e),o=cn({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 kc(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 Ac(e){return`${e.source.addonId}/${e.source.stableId}`}function jc(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`)}c();function Mc({deviceId:t,stableId:n}){let{t:a}=X(),s=n.startsWith(`composed-`)?n.slice(Fe.length):null,c=Bt({blockId:s??``},{enabled:s!==null}),l=dt({deviceId:t},{enabled:s!==null}),u=Sn({projection:`slim`},{enabled:s!==null}),[d,f]=o(()=>new Map),p=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(q,{title:a(`helper.outputUnavailable`),message:c.error.message});if(c.data.state!==`loaded`||c.data.view===null)return null;let h=Le(c.data.view.block);if(h===null||!Ti(h))return null;let g=Re(h.helper.templateId);if(g===null)return null;let _=Fc(l.status,l.data,l.error?.message),v=Si(_,g),y=fi(_),b=u.status===`success`?u.data.map(Ic):[],x=Lc(u.status),S=mi(h.helper.members.map(e=>d.get(Pc(e))??{name:e.source.stableId,presence:`unknown`})),C=v.kind===`number`?v.unit===void 0?String(v.value):`${v.value} ${v.unit}`:v.kind===`boolean`?v.value?a(`helper.on`):a(`helper.off`):v.kind===`empty`?a(`helper.noReading`):null;return i(Rt,{headingId:`helper-group-status`,title:a(`helper.statusTitle`),icon:Ke,testId:`helper-group-status`,children:e(`div`,{className:`${m} flex flex-col gap-3`,children:[h.helper.members.map(e=>i(Nc,{member:e,row:b.find(t=>t.addonId===e.source.addonId&&t.stableId===e.source.stableId)??null,fleetKind:x,onLive:p},Pc(e))),v.kind===`pending`&&i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:a(`helper.outputPending`)}),v.kind===`unavailable`&&i(q,{title:a(`helper.outputUnavailable`),message:v.message}),C!==null&&i(or,{value:C,label:a(`helper.template.${g.id}`)}),y.kind===`pending`&&i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:a(`helper.reportingPending`)}),y.kind===`unavailable`&&i(q,{title:a(`helper.outputUnavailable`),message:y.message}),y.kind===`absent`&&i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:a(`helper.reportingAbsent`)}),y.kind===`ready`&&i(`p`,{className:`text-sm text-foreground`,"data-testid":`helper-reporting`,children:a(`helper.reporting`,{included:y.included,total:y.total})}),y.kind===`ready`&&y.excluded>0&&e(`div`,{children:[i(`h3`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:a(`helper.excluded`)}),S.kind===`pending`?i(`p`,{role:`status`,className:`mt-1 text-xs text-foreground-subtle`,children:a(`helper.excludedPending`)}):S.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:S.names.map(e=>i(`li`,{children:e},e))})]}),i(Tc,{template:g,members:h.helper.members,fleet:b.map(e=>({id:e.id,name:e.name,addonId:e.addonId,stableId:e.stableId,features:e.features})),fleetKind:x,snapshot:_,nameOf:e=>b.find(t=>t.id===e)?.name??String(e)})]})})}function Nc({member:e,row:t,fleetKind:n,onLive:r}){let i=t?.online===!0,o=dt({deviceId:t?.id??0},{enabled:n===`answered`&&t!==null&&i}),s=yi(o.status,o.status===`success`?hi(o.data):void 0,e.cap,e.fieldPath),c=Oi({fleet:n,deviceOnline:n===`answered`?t===null?null:t.online:!0,field:s}),l=t?.name??e.source.stableId,u=Pc(e);return a(()=>{r(u,{name:l,presence:c})},[u,l,r,c]),null}function Pc(e){return`${e.source.addonId}/${e.source.stableId}/${e.cap}.${e.fieldPath}`}function Fc(e,t,n){return e===`pending`?{kind:`pending`}:e===`error`?{kind:`error`,message:n??``}:{kind:`answered`,caps:hi(t)}}function Ic(e){return{id:e.id,name:e.name,online:e.online,addonId:e.addonId,stableId:e.stableId,features:e.features??[]}}function Lc(e){return e===`pending`?`pending`:e===`error`?`error`:`answered`}function Rc(e,t){return{switchId:e,label:ze[e].label,detail:t===void 0||t.length===0?null:t}}function zc(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 Bc(e){let t=zc(e),n=new Set(e.sourceStillLive),r=e.sourceStillLive.map(e=>Rc(e,t.get(e)?.detail)),i=[...t.values()].filter(e=>e.outcome===`not-offered`&&!n.has(e.switchId)).map(e=>Rc(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 Vc(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 Hc({deviceId:t,deviceName:r}){let{t:a}=X(),s=Yt(),[c,l]=o(null),u=Sn({isCamera:!0,projection:`slim`}),d=xr(),f=u.data!==void 0,p=n(()=>u.data===void 0?[]:Vc(u.data,t),[u.data,t]),m=p.find(e=>e.id===c)??null,h=d.data===void 0?null:Bc(d.data),g=d.error===null?null:d.error.message,_=async()=>{m===null||m.id===t||await s({title:a(`deviceMigrate.confirmTitle`,`Replace “{{source}}” with “{{target}}”?`,{source:r,target:m.name}),message:a(`deviceMigrate.confirmMessage`,`“{{target}}” takes over number {{sourceId}}. That number is what every recording, event, rule, zone and home-automation export of “{{source}}” is filed under, so all of it follows the number to the new hardware and keeps working. “{{source}}” is switched off and handed number {{targetId}} in exchange. This swaps two device identities and cannot be undone from here.`,{source:r,target:m.name,sourceId:t,targetId:m.id}),confirmLabel:a(`deviceMigrate.confirmAction`,`Migrate`),variant:`danger`})&&d.mutate({sourceId:t,targetId:m.id})};return e(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[e(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[e(`div`,{className:`min-w-0`,children:[i(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:a(`deviceMigrate.title`,`Migrate to…`)}),i(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:a(`deviceMigrate.subtitle`,`Replace this camera with other hardware you have already adopted. The new camera inherits number {{deviceId}}, so recordings, rules and integrations follow it.`,{deviceId:t})})]}),e(`div`,{className:`flex shrink-0 items-center gap-2`,children:[e(`select`,{"aria-label":a(`deviceMigrate.pickerLabel`,`Replacement camera`),className:`rounded-md border border-border bg-background px-2 py-1.5 text-xs text-foreground disabled:opacity-50`,disabled:!f||p.length===0||d.isPending,value:c===null?``:String(c),onChange:e=>{let t=e.target.value;l(t===``?null:Number(t))},children:[i(`option`,{value:``,children:f?a(`deviceMigrate.pickerPlaceholder`,`Select a camera…`):a(`deviceMigrate.pickerPending`,`Reading the fleet…`)}),p.map(t=>e(`option`,{value:String(t.id),children:[t.name,` (#`,t.id,`)`]},t.id))]}),e(`button`,{type:`button`,disabled:m===null||d.isPending,onClick:()=>{_()},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[i(Ve,{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(Uc,{report:h})]})}function Uc({report:t}){let{t:n}=X(),r=t.verdict===`quiet`;return e(`div`,{className:`mt-3 space-y-2 border-t border-border pt-3`,children:[i(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`deviceMigrate.swapped`,`The replacement now answers on number {{inheritedId}}; the old camera was handed number {{retiredId}}.`,{inheritedId:t.inheritedId,retiredId:t.retiredId})}),r?e(`div`,{className:`flex items-start gap-2 rounded-md border border-success/30 bg-success/5 px-3 py-2`,children:[i(z,{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(V,{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(Je,{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 Wc({deviceId:t}){let{t:n}=X(),[r,a]=o(null),s=$t({onSuccess:e=>{a(e.changed?`Re-aligned with source — ${e.rebuiltChildren} child${e.rebuiltChildren===1?``:`ren`} rebuilt.`:`Already up to date.`)},onError:e=>a(`Re-sync failed: ${e.message}`)});return e(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[e(`div`,{className:`flex items-center justify-between gap-3`,children:[e(`div`,{children:[i(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:n(`device.resyncButton.reSync`,`Re-sync`)}),i(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:n(`device.resyncButton.reAlignThisDeviceS`,`Re-align this device's type, role, capabilities and units with its source.`)})]}),e(`button`,{type:`button`,disabled:s.isPending,onClick:()=>{a(null),s.mutate({camDeviceId:t})},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[i(ie,{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 Gc(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function Kc({device:t}){let{t:n}=X(),r=Nr(),a=typeof t.id==`number`?t.id:null,o=String(t.type??``),s=o===W.Camera,c=o===W.Hub,l=t.features??[],u=l.includes(ye.Resyncable),{data:d}=Mt({deviceId:a??0},{enabled:a!==null&&s,refetchInterval:5e3}),f=d?.streams??{},p=Object.entries(f),m=l.includes(ye.DoorbellButton),h=kn(m?{deviceId:a??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`&&a!==null&&typeof t.stableId==`string`&&i(Mc,{deviceId:a,stableId:t.stableId}),c&&a!==null&&i(Ht,{deviceId:a,onOpenChild:e=>r(`/devices/${e}`)}),u&&a!==null&&i(Wc,{deviceId:a}),s&&a!==null&&i(Hc,{deviceId:a,deviceName:String(t.name??``)}),a!==null&&i(wc,{deviceId:a,isCamera:s}),s&&a!==null&&i(Cn,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:a}),m&&i(_r,{history:h.history,latestIsFresh:g}),s&&a!==null&&i(Cn,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:a}),s&&p.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:p.map(([t,r])=>e(`div`,{className:`px-4 py-2.5`,children:[e(`div`,{className:`flex items-center gap-2 mb-2`,children:[i(oe,{className:`h-3 w-3 text-foreground-subtle`}),i(`span`,{className:`text-[11px] font-medium text-foreground`,children:t})]}),e(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[i(qc,{label:n(`device.overviewTab.nominal`,`Nominal`),value:Gc(r.nominalBitrateKbps??0)}),i(qc,{label:n(`device.overviewTab.observed`,`Observed`),value:Gc(r.observedBitrateKbps??0)}),i(qc,{label:n(`device.overviewTab.peak`,`Peak`),value:Gc(r.peakBitrateKbps??0)}),i(qc,{label:n(`device.overviewTab.packetLoss`,`Packet Loss`),value:`${(r.packetLossPercent??0).toFixed(2)}%`,warning:(r.packetLossPercent??0)>1})]})]},t))})]}),i(zr,{})]})}function qc({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 Jc=`history`,Yc=[{id:`overview`,labelKey:`helpers.structuralTabs.overview`,cameraOnly:!1,adminOnly:!1},{id:`config`,labelKey:`helpers.structuralTabs.config`,cameraOnly:!1,adminOnly:!1},{id:Br,labelKey:`helpers.structuralTabs.customize`,cameraOnly:!1,adminOnly:!0},{id:Jc,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}],Xc=new Set([W.Hub,W.Container]);function Zc(e,t){let n=e===W.Camera,r=e===void 0||!Xc.has(e);return Yc.filter(e=>(n||!e.cameraOnly)&&(t||!e.adminOnly)&&(r||e.id!==`history`)).map(({id:e,labelKey:t})=>({id:e,label:Y.t(t)}))}function Qc({provider:e,integrationId:t,name:n}){let r=Nr(),a=t===null?`/integrations`:`/integrations/${t}`,o=n===null?`Open integrations`:`Open integration ${n}`;return i(`button`,{type:`button`,onClick:()=>r(a),className:`shrink-0 rounded-md transition-opacity hover:opacity-80 focus:outline-none focus-visible:ring-1 focus-visible:ring-primary/50`,title:o,"aria-label":o,children:i(Ur,{type:e,size:`lg`})})}c();var $c=[{id:`logs`,icon:B,labelKey:`common.logs`},{id:`repl`,icon:qe,labelKey:`deviceDetail.repl`},{id:`events`,icon:T,labelKey:`common.events`},{id:`state`,icon:S,labelKey:`common.state`}];function el(){let{t:a}=X(),s=ue(),c=Vr(),u=Number(c.deviceId),f=Number.isFinite(u),p=Nr(),m=l(),_=Yt(),v=R(),{user:b}=Er(),x=b?.isAdmin===!0,[S,C]=Rr(),w=S.get(`tab`)??`overview`,T=S.get(`sub`),[E,D]=o(`logs`),O=`device-detail.left-col-width-px`,[k,A]=o(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(O),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),j=t(k);j.current=k;function te(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??k??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{A(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=j.current;if(e!==null)try{window.localStorage.setItem(O,String(Math.round(e)))}catch{}document.body.style.userSelect=``,document.body.style.cursor=``};document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,document.addEventListener(`mousemove`,i),document.addEventListener(`mouseup`,a)}let{data:M,isLoading:ne,isError:re}=gn({deviceId:u},{enabled:f,refetchInterval:5e3,retry:1}),{data:N}=zn({deviceId:u},{enabled:f}),ae=n(()=>{let e=N?.settings?.sections??[],t=N?.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(Fr)&&r.add(Ir),[...r].map(e=>e===`export`?{id:e,label:Dr,isAddonContrib:!0}:{id:e,label:je[e]?.label??e,isAddonContrib:!0})},[N]),P=M,F=String(P?.name??c.deviceId??`Device`),oe=P?.online===!0,se=oe?`online`:`offline`,I=String(P?.addonId??`rtsp`),L=P?.features??[],z=P?.type,B=z===W.Camera,{data:le}=Pr(f?u:0),fe=z===W.Container,pe=n(()=>(le??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[le]),V=n(()=>fe?vt(pe,typeof P?.linkDeviceId==`number`?P.linkDeviceId:null,typeof P?.primaryChildEntityId==`string`?P.primaryChildEntityId:null)?.id??null:null,[fe,pe,P?.linkDeviceId,P?.primaryChildEntityId]),{data:he}=zn({deviceId:V??0},{enabled:V!==null}),ge=n(()=>{if(V===null)return[];let e=he?.settings?.sections??[],t=he?.live?.sections??[],n=new Set;for(let r of[...e,...t])r.location===`top-tab`&&r.tab&&n.add(r.tab);return[...n].map(e=>({id:e,label:je[e]?.label??e,isAddonContrib:!0,childDeviceId:V}))},[V,he]),_e=n(()=>La({sections:[...N?.settings?.sections??[],...N?.live?.sections??[]],deviceId:u,...V===null?{}:{child:{sections:[...he?.settings?.sections??[],...he?.live?.sections??[]],deviceId:V}}}),[N,he,u,V]),ve=typeof P?.parentDeviceId==`number`?P.parentDeviceId:null,{data:be}=gn({deviceId:ve??0},{enabled:ve!==null}),H=Yn(),U=P?.disabled!==!0,xe=n(()=>{let e=N?.settings?.sections??[],t=N?.live?.sections??[];return Or([...e,...t],z,x,N!==void 0)},[N,z,x]),Se=n(()=>{let e=new Set,t=[];for(let n of[...Zc(z,x),...ae,...ge])n.id===`config`&&!xe||e.has(n.id)||(e.add(n.id),t.push(n));return t},[z,x,ae,ge,xe]),Ce=n(()=>Os(Se,w),[Se,w]),we=r(e=>{C(t=>{let n=new URLSearchParams(t);e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`);for(let e of zi)n.delete(e);return n},{replace:!0})},[C]),Te=r(e=>{C(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[C]),Ee=(le??[]).length>0,De=n(()=>$c.filter(({featureGate:e})=>!e||L.includes(e)),[L]),{data:Oe}=pr(void 0),ke=n(()=>P?Dt(P,Oe):null,[P,Oe]),G=ke?.kind===`resolved`?ke.integration:null,Ae=G===null?ke?.kind===`unknown`?a(`deviceDetail.loadingIntegration`):ke?.kind===`orphan`?a(`deviceDetail.missingIntegration`):a(`deviceDetail.noIntegration`):G.name,Me=G!==null&&G.addonId===I?G.name:I,Ne=zt({onSuccess:()=>{m.invalidateQueries({queryKey:[[`deviceManager`]]}),p(G?.id?`/integrations/${G.id}`:`/integrations`)}}),Pe=Mn({onSuccess:()=>{m.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=Xe({onSuccess:()=>{m.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ie=Ze(),Le=Ot({onSuccess:()=>{m.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Re=L.includes(ye.Rebootable),ze=L.includes(ye.BatteryOperated),Be=$e(v.trpcClient,ze&&f?u:null),Ve=Tr(v.trpcClient,f?u:null),He=ce(v.trpcClient,f?u:null,e=>e.runningState),Ue=He===void 0||He.running===null?null:He.running,We=Qn(z??`unknown`,s).icon,[Ge,Ke]=o(!1),qe=async()=>{if(!Ge){Ke(!0);try{let e=F.replace(/[^a-zA-Z0-9_.-]+/g,`_`),t=new Date().toISOString().replace(/[:.]/g,`-`);await ea(`${ee}/${String(u)}.jpg?force=1`,`${e}-${t}.jpg`)}finally{Ke(!1)}}},Je=Pe.isPending||Fe.isPending,{data:Ye}=Gt({deviceId:u},{enabled:f&&B,refetchInterval:1e4}),K=Ye?.agentNodeId??null,Qe=typeof K==`string`&&K.length>0&&!K.startsWith(`addon:`)?K:void 0,{data:tt}=En({deviceId:u,...Qe?{nodeId:Qe}:{}},{enabled:f&&B,refetchInterval:3e3,retry:!1}),{data:q}=qt({deviceId:u},{enabled:f&&B,refetchInterval:3e3,retry:!1}),rt=q?.level?.dbfs??null;function it(){if(!f)return null;switch(Ce){case`overview`:return i(Kc,{device:P??{}});case`config`:return i(Ns,{deviceId:u,activeSubTab:T,onSubTabChange:Te,deviceType:z,isAdmin:x});case`detection-pipeline`:return i(_c,{deviceId:u,activeSubTab:T,onSubTabChange:Te});case`bindings`:return i(ks,{deviceId:u});case Jc:return i(Ln,{deviceId:u,onNavigate:e=>p(e)});case Br:return i(ws,{deviceId:u});default:{let e=Ce,t=ae.some(t=>t.id===e),n=ge.find(t=>t.id===e);if(!t&&n===void 0)return null;let r=n?.childDeviceId??u;if(e===`export`)return i(kr,{deviceId:u,sectionFilter:Fr,activeSubTab:T,onSubTabChange:Te});let a=i(kr,{deviceId:r,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:T,onSubTabChange:Te});return n!==void 0&&r!==u?i(wr,{deviceId:r,children:a}):a}}}return f?ne?e(`div`,{className:`flex flex-col h-full`,children:[e(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[i(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),i(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),i(`div`,{className:`flex-1 p-6`,children:i(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):re||!M?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(Lr,{i18nKey:`deviceDetail.noDeviceWithId`,values:{id:u},components:{code:i(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`})}})}),i(`button`,{onClick:()=>p(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:a(`deviceDetail.backToIntegrations`,`Back to Integrations`)})]}):e(`div`,{className:`absolute inset-0 flex flex-col overflow-clip`,children:[e(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[i(`div`,{className:`mb-2`,children:i(nt,{items:[{label:a(`deviceDetail.integrations`,`Integrations`),onClick:()=>p(`/integrations`)},G===null?{label:Ae}:{label:Ae,onClick:()=>p(`/integrations/${G.id}`)},{label:F}]})}),e(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[G!==null&&i(Qc,{provider:G.addonId,integrationId:G.id,name:G.name}),i(Tt,{running:Ue,children:i(We,{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:F}),i(Zn,{status:se}),ze&&i(ot,{status:Be,variant:`full`}),i(Ct,{status:Ve})]}),ve!==null&&be&&e(`button`,{type:`button`,onClick:()=>p(`/devices/${ve}`),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:be.name}),children:[i(`span`,{children:`↑`}),i(`span`,{className:`truncate`,children:String(be.name??`Device #${ve}`)})]}),i(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:L.length>0&&i(jr,{capabilities:L})})]}),tt&&i(`div`,{className:`hidden lg:flex`,children:i(tl,{metrics:tt,dbfs:rt})}),e(`div`,{className:`flex items-center gap-1 shrink-0`,children:[e(`button`,{onClick:async()=>{U?await _({title:a(`deviceDetail.disable`,`Disable "{{name}}"?`,{name:F}),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`})&&Fe.mutate({deviceId:u}):Pe.mutate({deviceId:u})},disabled:Je,title:U?a(`deviceDetail.disableDevice`,`Disable device`):a(`deviceDetail.enableDevice`,`Enable device`),className:`inline-flex items-center gap-1.5 rounded-lg px-2 sm:px-2.5 py-1.5 text-[11px] font-medium border transition-colors disabled:opacity-50 ${U?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[i(g,{className:`h-3.5 w-3.5`}),i(`span`,{className:`hidden sm:inline`,children:Je?a(`deviceDetail.updating`,`Updating…`):U?a(`deviceDetail.enabled`,`Enabled`):a(`deviceDetail.disabled`,`Disabled`)})]}),i(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),B&&e(d,{children:[i(sa,{deviceId:u}),i(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`})]}),i(la,{deviceId:u}),i(br,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:a(`deviceDetail.takeSnapshot`,`Take snapshot`),description:a(`deviceDetail.fetchAFreshFrameAnd`,`Fetch a fresh frame and download it.`),icon:h,disabled:Ge,onClick:()=>{qe()}},{id:`reboot`,label:a(`deviceDetail.rebootDevice`,`Reboot device`),description:a(`deviceDetail.cameraGoesOfflineFor30`,`Camera goes offline for ~30 seconds.`),icon:me,hidden:!Re,disabled:Ie.isPending,danger:!0,onClick:async()=>{await _({title:a(`deviceDetail.reboot`,`Reboot "{{name}}"?`,{name:F}),message:a(`deviceDetail.theCameraWillGoOffline`,`The camera will go offline for around 30 seconds while the firmware reboots.`),confirmLabel:a(`deviceDetail.reboot2`,`Reboot`),variant:`danger`})&&Ie.mutate({deviceId:u})}},{id:`restart-addon`,label:a(`deviceDetail.restartAddon`,`Restart addon`),description:a(`deviceDetail.bouncesEveryDeviceServedBy`,`Bounces every device served by {{servingAddonLabel}}.`,{servingAddonLabel:Me}),icon:ie,disabled:Le.isPending,danger:!0,onClick:async()=>{await _({title:a(`deviceDetail.restart`,`Restart "{{servingAddonLabel}}"?`,{servingAddonLabel:Me}),message:a(`deviceDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device served by it (not just "{{name}}"). Streams will reconnect automatically.`,{name:F}),confirmLabel:a(`deviceDetail.restart2`,`Restart`),variant:`danger`})&&Le.mutate({addonId:I})}},{id:`delete`,label:a(`deviceDetail.deleteDevice`,`Delete device`),description:a(`deviceDetail.removeTheDeviceAndAll`,`Remove the device and all its settings.`),icon:y,separatorBefore:!0,disabled:Ne.isPending,danger:!0,onClick:async()=>{await _({title:a(`deviceDetail.delete`,`Delete "{{name}}"?`,{name:F}),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`})&&Ne.mutate({deviceId:u})}}]})]})]})]}),i(wr,{deviceId:u,device:P??void 0,children:i(et,{children:i(dn,{children:i(de,{children:i(fn,{children:e(`main`,{className:H?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[e(`div`,{className:H?`flex flex-col bg-surface`:`${k===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-y-auto`,style:!H&&k!==null?{width:`${String(k)}px`}:void 0,children:[i(`div`,{className:B?`flex-shrink-0 border-b border-border-subtle bg-black`:H?`flex-shrink-0 border-b border-border-subtle bg-surface`:`shrink-0 border-b border-border-subtle bg-surface`,children:B?i(qa,{deviceId:u,intercomAvailable:L.includes(ye.TwoWayAudio)}):e(`div`,{children:[i(Pa,{deviceId:u,deviceName:F,deviceType:z??`unknown`,provider:I,isOnline:oe,features:L}),i(Fa,{deviceId:u,widgets:_e})]})}),B&&_e.length>0&&i(`div`,{className:`flex-shrink-0 border-b border-border-subtle bg-surface pt-3 sm:pt-4`,children:i(Fa,{deviceId:u,widgets:_e})}),e(`div`,{className:H?`flex flex-col border-b border-border`:`flex-1 min-h-64 flex flex-col overflow-hidden`,children:[i(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:i(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:De.map(({id:t,labelKey:n,icon:r})=>{let o=E===t;return e(`button`,{onClick:()=>D(t),title:a(n),className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${o?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[i(r,{className:`h-3 w-3`}),a(n)]},t)})})}),e(`div`,{className:H?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[E===`logs`&&i(Ja,{deviceId:u,containerDeviceId:z===`container`?u:void 0}),E===`repl`&&i(Ya,{deviceId:u}),E===`events`&&i(Xa,{deviceId:u}),E===`state`&&i(Za,{deviceId:u})]})]})]}),!H&&i(`div`,{role:`separator`,"aria-orientation":`vertical`,title:a(`deviceDetail.dragToResize`,`Drag to resize`),onMouseDown:te,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:i(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),e(`div`,{className:H?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[i(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:i(`div`,{className:`flex flex-nowrap overflow-x-auto md:flex-wrap md:overflow-x-visible items-center gap-0`,children:Se.map(t=>{let n=Ce===t.id;return e(`button`,{onClick:()=>we(t.id),className:`relative flex-shrink-0 px-3 py-2 text-xs font-medium transition-colors ${n?`text-primary`:`text-foreground-subtle hover:text-foreground`}`,children:[t.label,n&&i(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},t.id)})})}),e(`div`,{className:H?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[Ce===`overview`&&Ee&&i(ua,{parentDeviceId:u}),it()]})]})]})})})})})})]}):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(Lr,{i18nKey:`deviceDetail.invalidSegment`,values:{segment:c.deviceId},components:{code:i(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`})}})}),i(`button`,{onClick:()=>p(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:a(`deviceDetail.backToIntegrations`,`Back to Integrations`)})]})}function tl({metrics:t,dbfs:n}){let r=ue(),{t:a}=X(),o=dr(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(fe,{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(M,{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{el as DeviceDetailPage};
1
+ import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,a as s,et as c,o as l,t as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Br as f,Cr as p,D as m,Di as h,En as g,G as _,Gn as v,It as y,J as b,Jn as x,Jr as S,K as C,Kn as w,Li as T,O as E,Ri as D,Si as O,St as k,T as A,V as j,W as ee,Xn as te,Xr as M,Z as ne,Zt as re,_t as N,bn as ie,dn as ae,dt as P,en as F,ht as oe,li as se,lr as I,or as L,ot as R,pi as z,pn as B,q as ce,r as le,sa as ue,t as de,ta as fe,tr as pe,vn as me,xn as V,yn as he,z as ge,zn as _e,zr as ve}from"./player-overlays-Dbv95cvz.js";import{Fi as ye,Fn as be,Gt as H,Ii as U,In as xe,Jt as Se,Kt as Ce,Li as W,Lr as we,Ni as Te,Nn as Ee,Pn as De,Wn as Oe,Wr as ke,Xt as G,Yt as Ae,ba as je,bi as Me,d as Ne,ga as Pe,pi as Fe,qt as Ie,ti as Le,ui as Re,ya as ze}from"./client-DvJxGh2F.js";import{t as Be}from"./archive-Brq5E-qM.js";import{i as Ve,n as He,r as Ue,t as We}from"./scan-eye-CWOvobjP.js";import{t as Ge}from"./bell-off-CDjOfT8K.js";import{t as Ke}from"./boxes-0ut2NdHU.js";import{n as qe}from"./video-D7jv0spx.js";import{t as Je}from"./circle-slash-CaxGVwz5.js";import{t as Ye}from"./layers-BnsQ5ORI.js";import{$a as Xe,$r as K,Al as Ze,Bn as Qe,Bt as $e,Cr as et,Da as tt,Dn as nt,Dr as q,Ea as rt,Fa as it,Fc as at,Fn as ot,Ft as st,Gn as ct,Gt as lt,Hn as ut,Ho as dt,Ht as ft,I as pt,Io as mt,It as ht,Ju as gt,Kc as _t,Kr as J,Kt as vt,La as yt,Lc as bt,Lt as xt,Ma as St,Mn as Ct,Nc as wt,Nn as Tt,No as Et,Nt as Dt,Oi as Ot,Pa as kt,Pc as At,Pn as jt,Qs as Mt,Qt as Nt,R as Pt,Ra as Ft,Ro as It,Sa as Lt,Sn as Rt,So as zt,Ta as Bt,Tc as Vt,Tt as Ht,Un as Ut,Ut as Wt,Vc as Gt,Vn as Kt,Wi as qt,Wn as Jt,Wr as Yt,X as Xt,Xn as Zt,Xt as Qt,Ya as $t,Yn as en,Yt as tn,Z as nn,Zt as rn,_r as an,a as on,al as sn,ao as cn,at as ln,bn as un,br as dn,c as fn,cc as pn,cd as mn,ci as hn,co as gn,dd as _n,do as vn,ed as yn,en as bn,et as xn,fo as Sn,fr as Cn,go as wn,gs as Tn,hl as En,hr as Dn,hs as On,i as kn,id as An,il as jn,io as Mn,it as Nn,jt as Pn,ko as Fn,kr as In,l as Ln,ld as Rn,lo as zn,md as Bn,mr as Vn,ms as Hn,nd as Un,ni as Wn,nl as Gn,nn as Kn,o as qn,oc as Jn,od as Yn,ol as Xn,ot as Zn,pd as Qn,po as $n,pr as er,qt as tr,r as nr,rd as rr,rl as ir,rt as ar,st as or,td as sr,ti as cr,tn as lr,tt as ur,un as dr,uo as fr,us as pr,vr as mr,wn as hr,wr as gr,wt as _r,xa as vr,xr as yr,xt as br,yo as xr,yr as Sr,za as Cr,zr as wr,zt as Tr}from"./src-DntJrWmU.js";import{t as Y}from"./i18n-D0o08mg-.js";import{t as X}from"./useTranslation-BJr-n0es.js";import"./mount-CUPf26ML.js";import{$n as Er,A as Dr,D as Or,E as kr,O as Ar,cr as jr,er as Mr,hr as Nr,ir as Pr,j as Fr,k as Ir,lr as Lr,mr as Rr,nr as zr,or as Z,p as Br,pr as Vr,rr as Hr,sr as Ur,tr as Wr,ur as Gr}from"./index-D_Tm4B7S.js";import{A as Kr,B as qr,C as Jr,D as Yr,E as Xr,F as Zr,G as Qr,H as $r,I as ei,L as ti,M as ni,N as ri,O as ii,P as ai,S as oi,T as si,U as ci,V as li,W as ui,_ as di,a as fi,b as pi,c as mi,d as hi,f as gi,g as _i,h as vi,i as yi,j as bi,k as xi,l as Si,m as Ci,n as wi,o as Ti,p as Ei,r as Di,s as Oi,t as ki,u as Ai,v as ji,w as Mi,x as Ni,y as Pi,z as Fi}from"./HelperWizard-B5Evcb8G.js";import{r as Ii,t as Li}from"./assignment-candidates-BMhC6h3l.js";import{_ as Ri,b as zi,i as Bi,m as Vi,o as Hi,t as Ui}from"./step-inspector-model-G2bS8NkA.js";import"./useEventInvalidation-CUPf26ML.js";import{t as Wi}from"./use-stationary-objects-DBEa50KS.js";import{n as Gi,t as Ki}from"./format-fYneBFV6.js";import{a as qi,i as Ji,n as Yi,o as Xi,r as Zi,s as Qi,t as $i}from"./linked-devices-model-DMEJU3bE.js";import{t as ea}from"./authed-media-CnaIhiH3.js";c();function ta(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 na(e){if(typeof e!=`object`||!e)return null;let t=e.switches;if(!Array.isArray(t))return null;let n=t.map(ta).filter(e=>e!==null);return n.length===0?null:n}var ra=[[/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 ia(e){for(let[t,n]of ra)if(t.test(e))return n;return`generic`}function aa(e){let t=e.filter(e=>e.on===!1).map(e=>e.id),n=e.filter(e=>e.on===null).map(e=>e.id),r=t=>t.map(t=>e.find(e=>e.id===t)?.label??t).join(`, `),i=[];return t.length>0&&i.push(Y.t(`helpers.cameraSwitchRows.off`,{list:r(t)})),n.length>0&&i.push(Y.t(`helpers.cameraSwitchRows.unknown`,{list:r(n)})),{offIds:t,unknownIds:n,summary:i.length===0?Y.t(`helpers.cameraSwitchRows.allOn`):i.join(` · `)}}var oa={stream:V,detection:We,privacy:ve,microphone:te,speaker:k,listening:He,archive:Be,recording:Ue,notifications:T,generic:F};function sa({deviceId:t}){let{t:n}=X(),a=l(),s=Number.isFinite(t),[c,u]=o(null),[d,f]=o(!1),p=bt({deviceId:t},{enabled:s});nr([`pipelineOrchestrator`,`getCameraSwitches`],[`capability.binding-changed`]);let m=na(p.data),h=Xn({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 _=aa(m),v=e=>c?.id===e.id?c.message:null;return e(Un,{open:d,onOpenChange:f,children:[e(An,{"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(F,{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(rr,{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(ca,{row:e,failure:v(e),onToggle:()=>g(e)})},e.id))})]})]})}function ca({row:t,failure:n,onToggle:r}){let{t:a}=X(),o=oa[ia(t.label)],s=t.on===null,c=t.on===!1,l=n===null?s?t.unavailableReason??`The source that owns this did not answer.`:t.costWhenOff:`Write failed: ${n}`,u=n===null?s?t.unavailableReason??`unknown`:null:`write failed`;return e(`button`,{type:`button`,role:`switch`,"aria-label":t.label,"aria-checked":t.on===!0,disabled:!t.available,onClick:r,title:l,className:`flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-[12px] text-foreground transition-colors hover:bg-surface-hover disabled:opacity-40 disabled:cursor-not-allowed`,children:[i(o,{className:`h-3.5 w-3.5 shrink-0 ${n===null?s?`text-foreground-subtle/50`:c?`text-warning`:`text-success`:`text-danger`}`}),e(`span`,{className:`flex-1 min-w-0 truncate`,children:[t.label,u!==null&&e(`span`,{className:`ml-1 text-[10px] text-foreground-subtle`,children:[`· `,u]})]}),i(`span`,{className:`shrink-0 rounded px-1 py-0.5 text-[9px] font-semibold uppercase tracking-wide ${s?`bg-surface-hover text-foreground-subtle/60`:c?`bg-warning/20 text-warning`:`bg-success/20 text-success`}`,children:s?`—`:a(c?`common.off`:`common.on`)})]})}function la({deviceId:t}){let n=ft(R().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(f,{className:`h-3.5 w-3.5`}),i(`span`,{className:`hidden sm:inline`,children:n.label})]})}function ua({parentDeviceId:t}){let{t:n}=X(),r=Vr(),a=R(),{data:o,isLoading:s,isError:c}=Pr(t),{data:l}=gn({deviceId:t},{enabled:Number.isFinite(t)});if(s)return i(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:i(`p`,{className:`text-[10px] text-foreground-subtle`,children:n(`common.loading`,{defaultValue:`Loading…`})})});if(c)return i(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:i(`p`,{className:`text-[10px] text-warning`,children:n(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let u=(o??[]).filter(e=>e.display?.hidden!==!0);if(u.length===0)return null;let d=xt(l?.stableId??``,u,l?.childLayout),f=d.ungrouped,p=e=>r(`/devices/${String(e)}`),m=l?.name??``,h=(e,t)=>i(st,{trpc:a.trpcClient,device:{...t,name:Wt(t,m)},variant:`minimal`,onNavigate:p},e),g=f.some(e=>!!e.role),_=f.some(e=>!e.role),v=g&&!_?n(`device.accessories`,{defaultValue:`Accessories`}):!g&&_?n(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):n(`device.children`,{defaultValue:`Children`}),y=f.length>0?e(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[i(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:v}),i(`div`,{className:`space-y-1`,children:f.map(e=>h(e.id,e))})]}):null,b=d.disabledSection===void 0?null:i(ht,{title:n(`device.disabledSection`,{defaultValue:`Disabled`}),count:d.disabledSection.children.length,defaultOpen:!1,children:i(`div`,{className:`opacity-60 space-y-1`,children:d.disabledSection.children.map(e=>h(e.id,e))})},d.disabledSection.title);if(d.sections.length===0)return b===null?y:e(`div`,{className:`space-y-2`,children:[y,b]});let x=_&&!g;return e(`div`,{className:`space-y-2`,children:[x?y:null,d.sections.map(e=>i(ht,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>h(e.id,e))},e.title)),x?null:y,b]})}function da({deviceId:e}){let t=R(),{data:n,isLoading:r}=Hr(e),{data:a,isLoading:o}=Pr(e),s=r||o,c=(a??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,features:e.features,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),l=typeof n?.linkDeviceId==`number`?n.linkDeviceId:null,u=typeof n?.primaryChildEntityId==`string`?n.primaryChildEntityId:null;return s?i(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):i(`div`,{className:`flex h-full w-full flex-col`,children:i(lt,{trpc:t.trpcClient,children:c,linkDeviceId:l,primaryChildEntityId:u})})}c();function fa({dev:t,busy:n,setBusy:r}){let{t:a}=X(),s=t?.motionTrigger,c=b(t?.state.motionTrigger),[l,u]=o(!1);if(!s)return null;let d=c?.enabled===!0,f=c!==void 0,p=async()=>{if(n||!f)return;let e=!d;r(!0),u(!0);try{await s.setMotionTrigger({enabled:e})}finally{r(!1),u(!1)}},m=l?d?`Disabling…`:`Enabling…`:f?d?`On motion: on`:`On motion: off`:`On motion: …`;return e(`button`,{type:`button`,onClick:()=>{p()},disabled:n||!f,title:f?d?a(`hero.motionTriggerToggle.disableTriggerOnMotion`,`Disable trigger on motion`):a(`hero.motionTriggerToggle.enableTriggerOnMotion`,`Enable trigger on motion`):a(`hero.motionTriggerToggle.awaitingState`,`Awaiting state…`),"aria-pressed":d,className:`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-[11px] font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${d?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground`}`,children:[i(fe,{className:`h-3 w-3`}),i(`span`,{children:m})]})}c();function Q({deviceId:t,deviceType:n,features:r}){let a=R(),s=tn(n)?.HeroCard??Qt,c=C(a.trpcClient,t),l=b(c?.state.deviceStatus),[u,d]=o(!1),f=l!==void 0&&l.online===!1,p=f?l.lastChangedAt:null;return e(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[f?i(`div`,{className:`flex justify-center`,children:i(tr,{lastChangedAt:p})}):null,i(s,{trpc:a.trpcClient,deviceId:t,features:r}),i(`div`,{className:`flex justify-center`,children:i(fa,{dev:c,busy:u,setBusy:d})})]})}function pa({deviceId:e,features:t}){return i(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:i(rn,{trpc:R().trpcClient,deviceId:e,features:t})})}function ma({deviceId:e,features:t}){return i(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:i(Qt,{trpc:R().trpcClient,deviceId:e,features:t})})}function ha(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}function ga(e){if(!e)return null;let t=ha(e.data);return t===null?e.eventType:Y.t(`helpers.eventEmitterFormat.buttonHeadline`,{channel:String(t),eventType:e.eventType})}var _a=1e3,va=60*_a,ya=60*va,ba=24*ya;function xa(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<_a?Y.t(`helpers.relativeTime.justNow`):n<va?Y.t(`helpers.relativeTime.secondsAgo`,{count:Math.floor(n/_a)}):n<ya?Y.t(`helpers.relativeTime.minutesAgo`,{count:Math.floor(n/va)}):n<ba?Y.t(`helpers.relativeTime.hoursAgo`,{count:Math.floor(n/ya)}):Y.t(`helpers.relativeTime.daysAgo`,{count:Math.floor(n/ba)})}c();var Sa=1500,Ca=15e3,wa=1e3;function Ta({deviceId:n}){let{t:r}=X(),s=C(R().trpcClient,n)?.state.eventEmitter,c=b(s);a(()=>{if(!s)return;s.refresh();let e=setInterval(()=>{s.refresh()},Ca);return()=>{clearInterval(e)}},[s]);let l=c?.lastEvent??null,u=l?.seq??null,d=t(null),[f,m]=o(!1);a(()=>{if(u===null)return;let e=d.current;if(d.current=u,e===null||e===u)return;m(!0);let t=setTimeout(()=>{m(!1)},Sa);return()=>{clearTimeout(t)}},[u]);let[h,g]=o(()=>Date.now());a(()=>{let e=setInterval(()=>{g(Date.now())},wa);return()=>{clearInterval(e)}},[]);let _=ga(l),y=c?.eventTypes??[],x=c?.eventCountSinceStart??0,S=c!==void 0,w=ha(l?.data);return e(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 p-4`,children:[i(`div`,{"data-testid":`event-emitter-indicator`,"data-flashing":String(f),className:`flex h-24 w-24 items-center justify-center rounded-full border-2 transition-all ${f?`border-primary bg-primary/20 text-primary shadow-lg shadow-primary/30 scale-105`:`border-border bg-surface text-foreground-subtle`}`,"aria-live":`polite`,title:_??r(`hero.eventEmitterHero.noPressRecorded`,`No press recorded`),children:i(f?v:p,{className:`h-10 w-10`})}),e(`div`,{className:`text-center`,children:[w!==null&&i(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-primary`,children:r(`hero.eventEmitterHero.button`,`Button {{value1}}`,{value1:String(w)})}),i(`div`,{"data-testid":`event-emitter-headline`,className:`text-sm font-semibold ${_?`text-foreground`:`text-foreground-subtle`}`,children:_??(S?r(`hero.eventEmitterHero.noPressRecorded`,`No press recorded`):r(`hero.eventEmitterHero.awaitingState`,`Awaiting state…`))}),i(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:l?xa(l.timestamp,h):r(`hero.eventEmitterHero.waitingForTheFirstEvent`,`Waiting for the first event`)})]}),y.length>0&&i(`div`,{className:`flex max-w-full flex-wrap justify-center gap-1`,children:y.map(e=>i(`span`,{"data-testid":`event-emitter-chip`,className:`rounded-full border px-2 py-0.5 text-[10px] font-medium ${e===l?.eventType?`border-primary bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle`}`,children:e},e))}),i(`div`,{className:`text-[10px] text-foreground-subtle`,children:r(`hero.eventEmitterHero.sinceStart`,{count:x})})]})}function Ea({deviceName:t,deviceType:n,provider:r,isOnline:a,features:o}){let{t:s}=X();return e(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-surface p-6 text-center`,children:[i(Ur,{type:r,size:`lg`}),e(`div`,{children:[i(`div`,{className:`text-sm font-semibold text-foreground`,children:t}),i(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:n})]}),e(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[i(Zn,{status:a?`online`:`offline`}),o.length>0&&i(jr,{capabilities:o})]}),i(`div`,{className:`text-[10px] text-foreground-subtle italic max-w-xs mt-1`,children:s(`hero.genericHero.noLiveViewForThis`,`No live view for this device type. Use the Config tab or the shortcut row to interact.`)})]})}c();function Da({deviceId:t}){let{t:r}=X(),a=l(),o=kt({deviceId:t},{refetchInterval:1e4,retry:!1}),s=it({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),a.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),c=n(()=>Oa(o.data??[]),[o.data]);return e(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[e(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[i(ka,{label:r(`hero.hubHero.discovered`,`Discovered`),value:c.total,icon:i(_e,{className:`h-3.5 w-3.5`})}),i(ka,{label:r(`hero.hubHero.adopted`,`Adopted`),value:c.adopted,accent:`success`}),i(ka,{label:r(`hero.hubHero.available`,`Available`),value:c.available,accent:c.available>0?`primary`:void 0}),e(`button`,{type:`button`,onClick:()=>{s.mutateAsync({deviceId:t}).catch(()=>{})},disabled:s.isPending,className:`inline-flex items-center justify-center gap-1.5 rounded-lg border border-border px-3 py-2 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 self-stretch shrink-0`,children:[s.isPending?i(L,{className:`h-3.5 w-3.5 animate-spin`}):i(ie,{className:`h-3.5 w-3.5`}),i(`span`,{className:`hidden sm:inline`,children:r(`hero.hubHero.discover`,`Discover`)})]})]}),e(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-foreground-subtle border-t border-border-subtle pt-2`,children:[i(Aa,{icon:i(oe,{className:`h-3 w-3 text-emerald-500`}),label:r(`hero.hubHero.online`,`{{online}} online`,{online:c.online})}),i(Aa,{icon:i(w,{className:`h-3 w-3 text-amber-500`}),label:r(`hero.hubHero.sleeping`,`{{sleeping}} sleeping`,{sleeping:c.sleeping})}),i(Aa,{icon:i(N,{className:`h-3 w-3 text-destructive`}),label:r(`hero.hubHero.offline`,`{{offline}} offline`,{offline:c.offline})}),c.unknown>0?i(Aa,{icon:i(se,{className:`h-3 w-3 text-foreground-subtle`}),label:r(`hero.hubHero.unknown`,`{{unknown}} unknown`,{unknown:c.unknown})}):null]})]})}function Oa(e){let t={total:e.length,adopted:0,available:0,online:0,sleeping:0,offline:0,unknown:0};for(let n of e)n.alreadyAdopted?t.adopted+=1:t.available+=1,t[n.status]+=1;return t}function ka({label:t,value:n,icon:r,accent:a}){return e(`div`,{className:`flex flex-1 basis-[140px] min-w-0 flex-col gap-1 rounded-lg border px-2 py-1.5 sm:px-3 sm:py-2 ${a===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:a===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[e(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[r,i(`span`,{className:`truncate`,children:t})]}),i(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:n})]})}function Aa({icon:t,label:n}){return e(`span`,{className:`inline-flex items-center gap-1`,children:[t,i(`span`,{children:n})]})}var ja={[W.Switch]:Q,[W.Siren]:Q,[W.Light]:Q,[W.Sensor]:Q,[W.Button]:Q,[W.Hub]:Da,[W.Cover]:pa,[W.Valve]:Q,[W.Humidifier]:Q,[W.WaterHeater]:Q,[W.Container]:da,[W.Lock]:Q,[W.Fan]:Q,[W.Thermostat]:Q,[W.Climate]:Q,[W.MediaPlayer]:Q,[W.Control]:Q,[W.AlarmPanel]:Q,[W.EventEmitter]:Ta,[W.Notifier]:ma,[W.Script]:Q,[W.Automation]:Q,[W.Presence]:Q,[W.Update]:Q,[W.Vacuum]:Q,[W.LawnMower]:Q,[W.Weather]:Q,[W.Image]:Q,[W.PetFeeder]:Q,[W.Dishwasher]:Q};function Ma(e){return ja[e]??Ea}function Na({deviceId:e}){let t=ce(R().trpcClient,e,e=>e.runningState);if(t===void 0||t.running!==!0&&t.running!==!1)return i(d,{});let n=t.running;return i(jt,{running:n,since:t?.since??null,phase:t?.phase??null,className:`px-3 pt-2 sm:px-4`})}function Pa(t){let n=Ma(t.deviceType);return e(d,{children:[i(Na,{deviceId:t.deviceId}),i(n,{...t})]})}function Fa({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(Cn,{widgetId:t.widgetId,deviceId:t.deviceId});return i(`div`,{children:t.deviceId===e?n:i(wr,{deviceId:t.deviceId,children:n})},t.widgetId)})})}function Ia(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 La(e){let t=Ia(e),n=new Set(t.map(e=>e.widgetId)),r=e.child===void 0?[]:Ia(e.child),i=[...t,...r.filter(e=>!n.has(e.widgetId))],a=new Set;return i.filter(e=>a.has(e.widgetId)?!1:(a.add(e.widgetId),!0)).sort((e,t)=>e.order-t.order)}function Ra(e){return qn(R().trpcClient,e)}c();function za(e){let[n,i]=o(`idle`),[s,c]=o(null),l=t(null),u=t(null),d=t(null),f=t(!0),p=On(),m=Hn(),h=Tn(),g=r(()=>{if(l.current){try{l.current.close()}catch{}l.current=null}if(u.current){for(let e of u.current.getTracks())try{e.stop()}catch{}u.current=null}d.current=null},[]),_=r(async()=>{if(n===`idle`)return;i(`stopping`);let t=d.current;if(t&&e!==null)try{await Promise.race([h.mutateAsync({deviceId:e,sessionId:t}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}g(),f.current&&(i(`idle`),c(null))},[n,e,h,g]),v=r(async()=>{if(e===null||n!==`idle`&&n!==`error`)return;c(null);let t=null,r=null,a=null;try{i(`requesting-mic`),t=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),u.current=t,i(`starting`);let n=await p.mutateAsync({deviceId:e});a=n.sessionId,d.current=a,i(`connecting`),r=new RTCPeerConnection,l.current=r,r.oniceconnectionstatechange=()=>{if(!f.current)return;let e=r.iceConnectionState;e===`connected`||e===`completed`?i(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&f.current&&(c(e===`failed`?`WebRTC connection failed`:null),_())};for(let e of t.getAudioTracks())r.addTrack(e,t);await r.setRemoteDescription({type:`offer`,sdp:n.sdpOffer});let o=await r.createAnswer();await r.setLocalDescription(o);let s=r.localDescription?.sdp??o.sdp??``;await m.mutateAsync({deviceId:e,sessionId:a,sdpAnswer:s})}catch(n){let o=n instanceof Error?n.message:String(n);if(console.warn(`[intercom] start failed`,n),r)try{r.close()}catch{}if(t)for(let e of t.getTracks())try{e.stop()}catch{}if(l.current=null,u.current=null,a!==null)try{await h.mutateAsync({deviceId:e,sessionId:a})}catch{}d.current=null,f.current&&(c(o),i(`error`))}},[e,n,p,m,h,_]);return a(()=>(f.current=!0,()=>{f.current=!1;let t=d.current;if(t!==null&&e!==null&&h.mutate({deviceId:e,sessionId:t}),l.current){try{l.current.close()}catch{}l.current=null}if(u.current){for(let e of u.current.getTracks())try{e.stop()}catch{}u.current=null}d.current=null}),[e]),{state:n,error:s,start:v,stop:_,isTalking:n===`talking`}}c();var Ba=0;function $(){return++Ba}function Va(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function Ha(e){return[``,`Commands`,` help Show this help`,` examples Show usage examples for the current scope`,` context Show every available variable + full API surface`,` clear Clear terminal (also Ctrl+L)`,``,`Shortcuts`,` Enter Execute expression`,` Arrow Up/Down Navigate command history`,` Ctrl+L Clear terminal`,``,`Try: ${{system:` sm.summary() // fleet overview`,device:` device.state.battery.value?.sleeping // sync read`,provider:` devices.map(d => d.name)`,addon:` manifest.version`}[e.type]}`,``,`Top-level objects: sm (SystemMirror), DeviceType, Math, JSON, Date, …`]}function Ua(e){switch(e.type){case`device`:return[``,`── State (sync, zero round-trip) ─────────────────────────`,` device.state.battery.value`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,``,`── Actions (async, through wrapper chain) ────────────────`,` await device.snapshot.getSnapshot({})`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.switch.setState({ on: true })`,``,`── Wait for condition ───────────────────────────────────`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`── Subscribe to changes ─────────────────────────────────`,` const off = device.state.battery.subscribe(s => console.log(s))`,``,`── Quick info ───────────────────────────────────────────`,` info.name device name`,` info.addonId owning addon`,` sm.dump(deviceId) full debug dump`];case`system`:return[``,`── Lookups ──────────────────────────────────────────────`,` sm.getDeviceById(8)`,` sm.getDeviceByName('Sala da pranzo')`,` sm.getDevicesByAddon('reolink')`,` sm.getDevicesByType(DeviceType.Camera)`,``,`── Filters (typed query) ────────────────────────────────`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] })`,` sm.query({ name: /^Cam-/ })`,``,`── Cross-device ─────────────────────────────────────────`,` sm.whereState('battery', s => s.percentage < 20).length`,` sm.mapState('battery', s => s.percentage)`,` sm.countByCap('snapshot')`,``,`── Batch action ─────────────────────────────────────────`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,``,`── Listen ───────────────────────────────────────────────`,` sm.listenCap('motion', (id, s) => console.log(id, s))`,` sm.onDeviceAdded((id, info) => console.log('+', info.name))`,``,`── Diagnostics ──────────────────────────────────────────`,` sm.summary()`,` sm.dump(8)`];case`provider`:return[``,` devices.map(d => d.name)`,` await getIntegration()`,` sm.getDevicesByAddon('<this-addon-id>').length`];case`addon`:return[``,` manifest.name`,` manifest.version`,` declaration`]}}function Wa(e){let t=[``,`Scope: ${e.type}`,``];switch(e.type){case`system`:return[...t,`Primary API — sm (SystemMirror):`,` sm.getDeviceById(id) DeviceProxy | null (sync)`,` sm.getDeviceByName(name) DeviceProxy | null`,` sm.getDeviceByStableId(sid) DeviceProxy | null`,` sm.getAllDevices() readonly DeviceProxy[]`,` sm.getDeviceInfo(id) DeviceInfo | null`,` sm.summary() fleet stats`,``,`Filters — sm.query({...}):`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] }) // ALL caps required`,` sm.query({ anyCap: ['ptz', 'motion'] }) // ANY cap`,` sm.query({ name: { contains: 'sala' } }) // case-insensitive`,` sm.query({ name: /^Cam-\\d+$/ })`,` sm.query({ type: DeviceType.Camera })`,` sm.query({ parentDeviceId: 8 }) // accessories of cam 8`,` sm.query({ where: (info, dev) => dev.state.battery.value?.sleeping })`,``,`State queries:`,` sm.whereState('battery', s => s.percentage < 20)`,` sm.mapState('battery', s => s.percentage)`,` sm.findState('motion', s => s.detected)`,` sm.countByCap('snapshot')`,``,`Listeners (return unsubscribe fn):`,` sm.listen((id, cap, slice) => …) // every state change`,` sm.listenCap('motion', (id, slice) => …)`,` sm.listenDevice(8, (id, cap, slice) => …)`,` sm.onDeviceAdded((id, info) => …)`,` sm.onDeviceRemoved((id, info) => …)`,``,`Wait primitives:`,` await sm.waitForState(8, 'battery', s => !s.sleeping, 30_000)`,` await sm.waitForDevice(99, 30_000)`,``,`Batch:`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,` await sm.forEachCap('reboot', d => d.reboot.reboot({}))`,``,`Diagnostics:`,` sm.dump(8) debug dump (one device)`,` sm.dump() full fleet dump`,` sm.summary() breakdown by cap/addon/type`,``,`Legacy: deviceRegistry, addonRegistry, eventBus, devices(), addons()`];case`device`:return[...t,`Pre-bound variables:`,` device DeviceProxy for this device (sync state + async methods)`,` deviceId number`,` info DeviceInfo metadata (name, addonId, type, online, …)`,` sm SystemMirror (full cluster view)`,` rawDevice legacy IDevice instance (escape hatch)`,``,`Reactive state (sync, zero round-trip):`,` device.state.battery.value BatteryStatus | undefined`,` device.state.battery.value?.sleeping`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,` device.state.switch.value?.on`,` device.state.brightness.value?.percentage`,` device.state.doorbell.value?.lastPressedAt`,``,`Cap actions (async, through wrapper chain):`,` await device.snapshot.getSnapshot({})`,` await device.snapshot.getSnapshot({ streamId: 'high' })`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.ptz.goToPreset({ presetId: 'home' })`,` await device.switch.setState({ on: true })`,` await device.brightness.setBrightness({ percentage: 60 })`,` await device.reboot.reboot({})`,``,`Subscribe to slice changes:`,` const off = device.state.battery.subscribe(s => console.log(s))`,` // off() to unsubscribe`,``,`Wait for a state condition:`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`Diagnostics:`,` info.name device name`,` info.addonId which addon owns it`,` info.online transport health`,` sm.dump(deviceId) full debug dump (binding + state + info)`];case`provider`:return[...t,`Pre-bound variables:`,` devices Devices belonging to this provider (raw IDevice[])`,` getIntegration() Integration metadata`,``,`For typed device access use the SystemMirror:`,` await getSystemMirror()`,` sm.getDevicesByAddon('this-addon-id')`];case`addon`:return[...t,`Pre-bound variables:`,` manifest { name, version, ... }`,` declaration addon declaration`,` source addon source location`,``,`Examples:`,` manifest.name`,` manifest.version`]}}function Ga({scope:n,greeting:s,className:c}){let{t:l}=X(),d=R(),[f,p]=o(()=>{let e=[];return s&&e.push({id:$(),kind:`info`,text:s}),e.push({id:$(),kind:`info`,text:`scope: ${Va(n)} — type help or context for available commands`}),e}),[m,h]=o(``),[g,_]=o([]),[v,y]=o(-1),b=t(null),x=t(null);a(()=>{let e=x.current;e&&(e.scrollTop=e.scrollHeight)},[f]);let S=r(()=>{b.current?.focus()},[]),C=u({mutationFn:e=>d.trpcClient.repl.execute.mutate({code:e,scope:n}),onSuccess:e=>{let t=e??{},n=typeof t.output==`string`?t.output:e==null?`undefined`:typeof e==`string`?e:JSON.stringify(e,null,2),r=t.type===`error`;p(e=>[...e,{id:$(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);p(e=>[...e,{id:$(),kind:`error`,text:t}])}});function w(e){let t=e.trim();if(t){if(t===`clear`){p([{id:$(),kind:`info`,text:`scope: ${Va(n)}`}]),h(``);return}if(t===`help`){p(e=>[...e,{id:$(),kind:`input`,text:`> ${t}`},...Ha(n).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}if(t===`context`){p(e=>[...e,{id:$(),kind:`input`,text:`> ${t}`},...Wa(n).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}if(t===`examples`){p(e=>[...e,{id:$(),kind:`input`,text:`> ${t}`},...Ua(n).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}_(e=>[...e,t]),y(-1),p(e=>[...e,{id:$(),kind:`input`,text:`> ${t}`}]),h(``),C.mutate(t)}}function T(e){if(e.key===`Enter`){e.preventDefault(),w(m);return}if(e.key===`ArrowUp`){if(e.preventDefault(),g.length===0)return;let t=v===-1?g.length-1:Math.max(0,v-1);y(t),h(g[t]??``);return}if(e.key===`ArrowDown`){if(e.preventDefault(),v===-1)return;let t=v+1;t>=g.length?(y(-1),h(``)):(y(t),h(g[t]??``));return}e.ctrlKey&&e.key===`l`&&(e.preventDefault(),p([{id:$(),kind:`info`,text:`scope: ${Va(n)}`}]))}let E={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return e(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${c??``}`,onClick:S,children:[e(`div`,{ref:x,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[f.map(e=>i(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${E[e.kind]}`,children:e.text},e.id)),C.isPending&&i(`span`,{className:`text-zinc-500 animate-pulse`,children:l(`shared.replTerminal.thinking`,`…thinking`)})]}),e(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[i(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:l(`shared.replTerminal.text`,`>`)}),i(`input`,{ref:b,value:m,onChange:e=>h(e.target.value),onKeyDown:T,disabled:C.isPending,placeholder:`device.state.battery.value`,autoFocus:!0,className:`flex-1 bg-transparent text-zinc-100 placeholder:text-zinc-600 focus:outline-none caret-emerald-400 disabled:opacity-50`,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`})]})]})}function Ka(e,t){return e===null?null:{playbackUrl:e.url,...e.format===void 0?{}:{playbackFormat:e.format},playbackAuthToken:t,...e.label===void 0?{}:{playbackLabel:e.label}}}c();function qa({deviceId:e,intercomAvailable:t=!1}){let r=R(),a=typeof window<`u`?ne():``,o=Number.isFinite(e),s=Ra(o?e:null),c=Wi(o?[e]:[]),l=n(()=>{if(!o)return;let e=[];for(let t of c.rows){let n=on(t);n!==null&&e.push(n)}return e},[o,c.rows]),{streams:u,pipelineMetrics:f,createSession:p,sendAnswer:m,handleOffer:h,getIceServers:g,addIceCandidate:v,getIceCandidates:y,closeSession:b,getSessionState:x,applyDownlinkProbe:S}=un(r.trpcClient,o?e:null),C=_(o?e:null,{width:Qa}),w=za(o&&t?e:null),T=w.state===`requesting-mic`||w.state===`starting`||w.state===`connecting`||w.state===`stopping`,E=w.isTalking||T,D=()=>{w.state===`idle`||w.state===`error`?w.start():w.state!==`stopping`&&w.stop()},O=le(),k=gr(),A=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,j=Ka(k.request,A),ee=O.length>0?i(d,{children:O.map(e=>i(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return i(Xt,{serverUrl:a,createSession:p,sendAnswer:m,handleOffer:h,getIceServers:g,addIceCandidate:v,getIceCandidates:y,closeSession:b,getSessionState:x,applyDownlinkProbe:S,...j===null?{}:{...j,onExitPlayback:()=>k.clear()},streams:u,pipelineMetrics:f,phase:s.phase,detections:s,...l===void 0?{}:{stationaryObjects:l},defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:C.src,...C.src?{posterUrl:C.src}:{},snapshotLoading:C.loading,onRefreshSnapshot:C.refresh,intercomAvailable:t,intercomShown:E,onIntercomToggle:D,extraOverlay:ee,chromeless:!0,className:`h-full`})}function Ja({deviceId:e,containerDeviceId:t}){let{t:n}=X();return Number.isFinite(e)?i(`div`,{className:`flex flex-col h-full`,children:i(Kn,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):i(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:n(`device.panelContent.notLoaded`,{id:e})})}function Ya({deviceId:e}){let{t}=X();if(!Number.isFinite(e))return i(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:t(`device.panelContent.notLoaded`,{id:e})});let n=[`CamStack REPL — device #${e}`,``,` device.state.battery.value sync state read`,` await device.snapshot.getSnapshot({}) cap action`,``,` type 'examples' for more, 'context' for the full API`].join(`
2
+ `);return i(Ga,{scope:{type:`device`,deviceId:e},greeting:n,className:`h-full border-0 rounded-none`})}function Xa({deviceId:e}){let{t}=X();return Number.isFinite(e)?i(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:i(lr,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):i(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:t(`device.panelContent.notLoaded`,{id:e})})}function Za({deviceId:e}){let{t}=X();return Number.isFinite(e)?i(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:i(bn,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):i(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:t(`device.panelContent.notLoaded`,{id:e})})}var Qa=960;function $a({initialName:e,label:t=`Name`,layout:n=`inline`,bound:r}){return i(Z,{label:t,layout:n,value:i(`input`,{type:`text`,value:r.value,"aria-label":t,placeholder:e,onChange:e=>r.onChange(e.target.value),className:`flex-1 min-w-0 w-full px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`})})}c();function eo({label:t=`Location`,layout:r=`inline`,bound:a}){let{t:o}=X(),{data:s}=wn(),c=s??[],l=a.value.trim().toLowerCase(),u=n(()=>l.length===0?[]:c.filter(e=>e.toLowerCase()!==l&&e.toLowerCase().includes(l)),[c,l]);return i(Z,{label:t,layout:r,value:e(`div`,{className:`relative`,children:[i(`input`,{type:`text`,value:a.value,"aria-label":t,onChange:e=>a.onChange(e.target.value),placeholder:o(`shared.locationRow.roomAreaOrLeaveEmpty`,`Room / area (or leave empty to clear)`),className:`flex-1 min-w-0 w-full px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),u.length>0&&i(`div`,{className:`absolute z-10 left-0 right-0 mt-0.5 max-h-40 overflow-y-auto rounded-md border border-border bg-surface shadow-md`,children:u.map(t=>e(`button`,{type:`button`,onClick:()=>a.onChange(t),className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[i(pe,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),i(`span`,{className:`truncate`,children:t})]},t))})]})})}var to=`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`,no=0,ro=10;function io(e){if(e.trim()===``)return``;let t=Number.parseInt(e,10);return Number.isFinite(t)?String(t<no?no:t>ro?ro:t):``}function ao({value:e,onChange:t,disabled:n=!1,placeholder:r,className:a,id:o,"aria-label":s}){return i(`input`,{type:`number`,min:no,max:ro,step:1,id:o,className:a??to,"aria-label":s,placeholder:r,value:e,onChange:e=>{t(io(e.target.value))},disabled:n})}function oo({deviceName:t,value:n,inheritedIcon:r,inheritedLabel:a,disabled:o,onChange:s}){let{t:c}=X(),l={trigger:c(`deviceDisplay.pickIcon`,{name:t}),panel:c(`deviceDisplay.iconFor`,{name:t}),searchPlaceholder:c(`deviceDisplay.iconSearchPlaceholder`),clear:a,noMatches:c(`deviceDisplay.iconNoMatches`)};return e(`div`,{className:`flex items-center gap-2`,children:[i(sr,{value:n===``?null:n,onPick:e=>s(e??``),categoryLabel:e=>c(`deviceDisplay.iconCategory.${e}`,{defaultValue:ke(e)}),fallbackGlyph:r,labels:l,disabled:o}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:n===``?a:n})]})}var so=`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 co(e){if(e.trim()===``)return;let t=Number.parseInt(e,10);return Number.isFinite(t)?t:void 0}function lo({device:t,role:n,display:r,onChange:a}){let o=ue();Rn();let{t:s}=X(),c=l(),u=n===null?void 0:Nt[n],f=u?.kind===`numeric`,p=n!==null||t.parentDeviceId!==null&&t.parentDeviceId!==void 0,m=t.sourceInfo?.quantity,h=u?.kind===`numeric`?u.quantity??(m!==void 0&&m!==`device`?m:void 0):void 0,g=h===void 0?void 0:Pe(h),_=g===void 0?void 0:Oe(g),{data:v}=fr({},{staleTime:6e4,enabled:n!==null}),y=mt({onSuccess:()=>{c.invalidateQueries({queryKey:[[`deviceManager`]]})}}),b=()=>{if(n===null)return;let e=co(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:mn(x),C=n===null?Qn(t.type,o):_n(n,o),w={icon:S??C.icon,label:S===void 0?C.label:String(x)},T=n===null&&t.type===W.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?``:_n(n,o).label;return e(`div`,{className:`mt-3 divide-y divide-border border-t border-border`,children:[i(Z,{label:s(`deviceDisplay.icon`),value:i(oo,{deviceName:t.name,value:r.icon,inheritedIcon:w.icon,inheritedLabel:T,disabled:!1,onChange:e=>a({icon:e})})}),p&&i(Z,{label:s(`deviceDisplay.label`),value:i(`input`,{type:`text`,className:so,"aria-label":s(`deviceDisplay.label`),placeholder:n===null?t.name:E,value:r.label,onChange:e=>a({label:e.target.value})})}),f&&e(d,{children:[i(Z,{label:s(`deviceDisplay.unit`),value:i(pt,{dimension:_,value:r.unit,onChange:e=>a({unit:e}),disabled:!1,"aria-label":s(`deviceDisplay.unit`),inheritLabel:s(`deviceDisplay.unitSource`,{unit:g===void 0?``:` (${g})`}),emptyReason:s(`deviceDisplay.unitSource`,{unit:``})})}),i(Z,{label:s(`deviceDisplay.precision`),value:i(ao,{"aria-label":s(`deviceDisplay.precision`),placeholder:s(`deviceDisplay.precisionInherit`),value:r.precision,onChange:e=>a({precision:e}),disabled:!1})})]}),n!==null&&i(`div`,{className:`px-3 sm:px-4 py-2`,children:i(J,{type:`button`,variant:`outline`,size:`sm`,onClick:b,disabled:y.isPending,title:s(`deviceDisplay.setRoleDefaultTitle`,{role:E}),children:s(`deviceDisplay.setRoleDefault`,{role:E})})})]})}function uo(e){return typeof e.linkDeviceId==`number`}var fo=new Set(Object.values(U));function po(e){return fo.has(e)}var mo={[W.Switch]:[U.Siren,U.Floodlight,U.Spotlight,U.PirSensor,U.Chime,U.Autotrack,U.Nightvision,U.PrivacyMask,U.BinaryHelper],[W.Light]:[U.Floodlight,U.Spotlight,U.Nightvision],[W.Siren]:[U.Siren],[W.Button]:[U.Doorbell],[W.Sensor]:[U.MotionSensor,U.ContactSensor,U.LeakSensor,U.SmokeSensor,U.COSensor,U.GasSensor,U.TamperSensor,U.VibrationSensor,U.ConnectivitySensor,U.SoundSensor,U.BinarySensor,U.TemperatureSensor,U.HumiditySensor,U.AmbientLightSensor,U.PressureSensor,U.WindSensor,U.RainSensor,U.UvSensor,U.SolarRadiationSensor,U.SoilMoistureSensor,U.PowerSensor,U.EnergySensor,U.VoltageSensor,U.CurrentSensor,U.AirQualitySensor,U.BatterySensor,U.NumericSensor,U.EnumSensor,U.DateTimeSensor,U.GenericSensor],[W.Control]:[U.NumericControl,U.SelectControl,U.TextControl,U.DateTimeControl],[W.Notifier]:[U.MobilePushNotifier,U.MessagingNotifier,U.EmailNotifier,U.GenericNotifier]};function ho(e){for(let t of Object.values(W))if(t===e)return!0;return!1}function go(e){return ho(e)?mo[e]??[]:[]}function _o(e,t){let n=go(t);return e==null||e===``||n.includes(e)?n:[...n,e]}function vo({device:t}){let{t:n}=X(),r=ue(),a=Wr(),o=a?.identity??null,s=o?.name??t.name,c=o?.location??t.location??``,l=o?.role??t.role??null,u=o?.display.hidden??t.display?.hidden===!0,d=a!==null&&o!==null;return e(`section`,{"aria-label":n(`customize.identity.title`),className:`${E} ${m}`,children:[e(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[d?i($a,{deviceId:t.id,initialName:s,label:n(`customize.identity.name`),layout:`stacked`,bound:{value:s,onChange:a.setIdentityName}}):i(Z,{label:n(`customize.identity.name`),layout:`stacked`,value:s}),d?i(eo,{deviceId:t.id,initialLocation:c,label:n(`customize.identity.room`),layout:`stacked`,bound:{value:c,onChange:a.setIdentityLocation}}):i(Z,{label:n(`customize.identity.room`),layout:`stacked`,value:c===``?n(`common.unset`):c}),i(Z,{label:n(`customize.identity.type`),layout:`stacked`,value:t.type}),i(Z,{label:n(`customize.identity.hidden`),layout:`stacked`,value:i(ct,{"aria-label":n(`deviceDisplay.hideFromLists`),checked:u,disabled:!d,onChange:e=>a?.setIdentityDisplay({hidden:e.target.checked})})}),i(Z,{label:n(`customize.identity.role`),layout:`stacked`,value:uo(t)||!d?i(`span`,{children:yo(l,n(`customize.identity.noRole`),r)}):i(gt,{"aria-label":n(`customize.identity.role`),value:l??``,options:[{value:``,label:n(`customize.identity.noRole`)},..._o(l,t.type).map(e=>({value:e,label:yo(e,n(`customize.identity.noRole`),r)}))],onChange:e=>a.setIdentityRole(e.target.value===``?null:e.target.value)})})]}),o!==null&&a!==null&&i(lo,{device:t,role:l,display:o.display,onChange:a.setIdentityDisplay})]})}function yo(e,t,n){return e==null||e===``?t:po(e)?_n(e,n).label:e}function bo(e){let t=De({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 xo(e){let t=be({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 So(e,t){return{deviceId:e,config:t.config}}function Co(e,t){return{deviceId:e,patch:{motionCooldownMs:t}}}async function wo(e,t,n,r){await n(So(e,t)),await r(Co(e,t.timeoutMs))}c();function To(t){let{t:n}=X(),r=t.mode===`change`?n(`customize.scalar.changeTitle`,{title:t.title}):n(`customize.scalar.addTitle`,{title:t.title});return i(er,{open:t.open,onOpenChange:e=>!e&&t.onClose(),children:e(Dn,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":r,children:[i(mr,{children:i(Sr,{children:r})}),t.open?i(Eo,{...t}):null]})})}function Eo(t){let{t:r}=X(),a=Sn({projection:`slim`}),s=ii(n(()=>a.status===`success`?ni(a.data):[],[a.status,a.data]),t.sources[0]),[c,l]=o(()=>Do(t.sources)),[u,f]=o(null),[p,m]=o(!1);!p&&s!==null&&(f(s),m(!0));let[h,g]=o(t.edge),[_,v]=o(t.debounceMs/1e3),y=Oo(c),b=y.length===0?null:bo({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=dt({deviceId:c[0]?.deviceId??0}),C=Ao(S.status===`success`?S.data:void 0,x),w=Ae(Ie,C,Math.round(_*1e3));return e(d,{children:[e(Vn,{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(Yr,{kind:`event`,shape:`pulse`,enabled:t.open,hostId:t.host.id,devicePickerTestId:`event-pulse-picker`,destination:{cap:t.cap,targetId:t.targetId,title:t.title},device:u,picked:c,onDeviceChange:f,onPickedChange:l,edges:t.edges,edge:h,onEdgeChange:g,debounceSec:_,onDebounceSecChange:v,sourceModes:[],timeoutSec:0,onTimeoutSecChange:()=>void 0,cooldownSec:null,onCooldownSecChange:()=>void 0}),C.kind===`level`?i(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:r(ko(C,w.lastPressedAt))}):null]}),e(an,{className:`flex flex-wrap gap-2`,children:[i(J,{variant:`ghost`,onClick:t.onClose,children:r(`customize.scalar.cancel`)}),i(J,{"data-testid":`event-save`,disabled:!t.canSave||b===null,onClick:()=>{b!==null&&t.onSave(b)},children:r(`customize.scalar.save`)})]})]})}function Do(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 Oo(e){return e.map(e=>({addonId:e.addonId,stableId:e.stableId,cap:e.cap,fieldPath:e.fieldPath,changedAtField:e.changedAtField??Te[e.cap]??`lastChangedAt`}))}function ko(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 Ao(e,t){if(e===void 0||t===null)return{kind:`unread`};let n=e[t.cap],r=n===void 0?void 0:bi(n,t.fieldPath),i=Te[t.cap]??t.changedAtField,a=n===void 0?void 0:bi(n,i);return typeof r==`boolean`?{kind:`level`,active:r,changedAt:typeof a==`number`&&Number.isFinite(a)?a:null}:{kind:`unread`}}function jo(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=Mo(t,n);return r===null?{kind:`unknown`,seconds:null}:{kind:`active`,seconds:r}}function Mo(e,t){if(e==null||!Number.isFinite(e)||e<Ki)return null;let n=Math.floor((t-e)/1e3);return n<0?0:n}function No(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>=Ki?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();function Po({device:t,handle:n,availability:r,cap:a,title:s,view:c}){let{t:l,i18n:u}=X(),f=ri(),[p,m]=o(!1),[h,g]=o(null),_=li(n.state),v=ai(_,a),y=Io(n,v),b=y.kind===`known`&&y.value!==null?Ee({feature:y.value,device:n.target,cap:a,targetId:c.id,timestampPath:c.timestampPath,counterPath:c.counterPath}):null,x=b!==null,S=ci(x),C=b?.draft.sources[0]??null,w=C===null||S.kind!==`known`?null:S.value.find(e=>Me({addonId:e.addonId,stableId:e.stableId})===Me(C))??null,T=Lo(x,S.kind,w!==null),E=H({cap:a,targetId:c.id,device:n.target,timestampPath:c.timestampPath,counterPath:c.counterPath,apply:c.apply,stored:y,sourcePresence:T,sourceUnknownReason:S.kind===`unknown`?S.reason:null}),O=n.state.kind===`none`||n.state.kind===`present`;if(r.kind===`absent`||!c.deviceTypes.includes(t.type))return null;let k=async e=>{let t=await n.save(e);g(t.kind===`refused`?t.reason:null)},A=Ro(b),j=b?.draft.edges?.[0],ee=j!==void 0&&c.edges.includes(j)?j:c.defaultEdge,te=C===null?``:qr(C.cap,C.fieldPath,u.language),M=y.kind===`known`&&y.value===null,ne=!x&&y.kind===`known`&&y.value!==null;return e(d,{children:[i(Qr,{id:a,icon:D,title:s,testId:`event-card-${a}`,actions:e(d,{children:[v!==null&&e(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground`,children:[i(ct,{"aria-label":l(`customize.doorbell.active`),checked:v.enabled!==!1,disabled:!O||n.saving,onChange:e=>{k(ei(_,n.target,{...v,enabled:e.target.checked}))}}),l(`customize.doorbell.active`)]}),i(K,{children:l(Mi(E.text,E.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`&&!O?i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:l(`customize.event.checking`)}):r.kind===`unknown`?i(q,{title:l(`customize.scalar.unreadable`),message:r.reason}):e(d,{children:[x&&C!==null&&i(`p`,{className:`text-xs text-foreground`,children:l(`customize.scalar.override`,{name:w===null?C.stableId:xi(w.name,w.id,S.kind===`known`?S.value.map(e=>({id:e.id,name:e.name,parentDeviceId:e.parentDeviceId??null})):[]),field:te})}),x&&i(Fo,{deviceId:t.id,cap:a,timestampPath:c.timestampPath,counterPath:c.counterPath,startedAt:n.state.kind===`present`?n.state.view.block.createdAt:null}),ne&&v!==null&&e(`p`,{className:`text-xs text-foreground flex flex-wrap items-center gap-1`,children:[l(`customize.doorbell.otherFormula`),i(pi,{handle:n,cap:a,fieldPath:c.counterPath})]}),M&&i(`p`,{className:`text-xs text-foreground-subtle`,children:l(`customize.scalar.noOverride`)}),h!==null&&i(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:h}),e(`div`,{className:`flex flex-wrap gap-2`,children:[x&&i(J,{variant:`outline`,size:`sm`,disabled:n.saving,onClick:()=>m(!0),children:l(`customize.scalar.change`)}),x&&i(J,{variant:`ghost`,size:`sm`,disabled:n.saving,onClick:()=>{if(_===null)return;let e=ti(_,a);f(l(`customize.doorbell.removeWhat`,{name:w?.name??t.name}),e===null).then(t=>{t&&k(e)})},children:l(`customize.scalar.remove`)}),M&&i(J,{variant:`outline`,size:`sm`,"data-testid":`event-add-${a}`,disabled:n.saving,onClick:()=>m(!0),children:l(`customize.scalar.add`)})]})]})})}),i(To,{open:p,mode:x?`change`:`add`,title:s,cap:a,targetId:c.id,host:t,target:n.target,enabled:v?.enabled!==!1,debounceMs:b?.draft.debounceMs??c.debounceMs,edges:c.edges,edge:ee,sources:A,canSave:O&&!n.saving,onClose:()=>m(!1),onSave:e=>{m(!1),k(ei(_,n.target,e))}})]})}function Fo({deviceId:t,cap:n,timestampPath:r,counterPath:a,startedAt:o}){let{t:s}=X(),c=Kr({deviceId:t,cap:n,path:r}),l=Kr({deviceId:t,cap:n,path:a}),u=No(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?``:Gi(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:Gi(u.lastPressedAt)}),u.pressCount===null?``:` · ${s(`customize.event.doorbellCount`,{count:u.pressCount})}`]})}function Io(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 Lo(e,t,n){return e?t===`pending`?`pending`:t===`unknown`?`unknown`:n?`present`:`absent`:`present`}function Ro(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 zo(t){let{t:n}=X(),r=t.mode===`change`?n(`customize.scalar.changeTitle`,{title:t.title}):n(`customize.scalar.addTitle`,{title:t.title});return i(er,{open:t.open,onOpenChange:e=>!e&&t.onClose(),children:e(Dn,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":r,children:[i(mr,{children:i(Sr,{children:r})}),t.open?i(Bo,{...t}):null]})})}function Bo(t){let{t:r}=X(),a=Sn({projection:`slim`}),s=ii(n(()=>a.status===`success`?ni(a.data):[],[a.status,a.data]),t.sources[0]),[c,l]=o(()=>Vo(t.sources)),[u,f]=o(null),[p,m]=o(!1);!p&&s!==null&&(f(s),m(!0));let[h,g]=o(t.timeoutMs/1e3),[_,v]=o((t.cooldownMs??0)/1e3),y=Ho(c),b=xo({cap:t.cap,targetId:t.targetId,device:t.target,timeoutMs:Math.round(h*1e3),cooldownMs:t.cooldownMs===null?void 0:Math.round(_*1e3),sources:y}),x=c[0];return e(d,{children:[e(Vn,{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(Yr,{kind:`event`,shape:`span`,enabled:t.open,hostId:t.host.id,devicePickerTestId:`event-span-picker`,destination:{cap:t.cap,targetId:t.targetId,title:t.title},device:u,picked:c,onDeviceChange:f,onPickedChange:e=>l(e.filter(e=>!(e.addonId===t.host.addonId&&e.stableId===t.host.stableId))),edges:[],edge:`rising`,onEdgeChange:()=>void 0,debounceSec:0,onDebounceSecChange:()=>void 0,sourceModes:t.sourceModes,timeoutSec:h,onTimeoutSecChange:g,cooldownSec:t.cooldownMs===null?null:_,onCooldownSecChange:v}),x!==void 0&&i(Uo,{deviceId:x.deviceId,cap:x.cap,fieldPath:x.fieldPath,timeoutMs:Math.round(h*1e3)})]}),e(an,{className:`flex flex-wrap gap-2`,children:[i(J,{variant:`ghost`,onClick:t.onClose,children:r(`customize.scalar.cancel`)}),i(J,{"data-testid":`event-save`,disabled:!t.canSave||b===null,onClick:()=>{b!==null&&t.onSave(b)},children:r(`customize.scalar.save`)})]})]})}function Vo(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 Ho(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 Uo({deviceId:e,cap:t,fieldPath:n,timeoutMs:r}){let{t:a}=X(),o=Kr({deviceId:e,cap:t,path:n}),s=o.kind===`value`&&typeof o.value==`boolean`?{kind:`level`,active:o.value,changedAt:null}:{kind:`unread`},c=G(Se,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(Wo(s,c.open))})}function Wo(e,t){return e.kind===`unread`?`customize.event.previewWaiting`:t?`customize.event.previewMotionOn`:e.active?`customize.event.previewSensorOn`:`customize.event.previewMotionOff`}c();function Go({device:n,availability:r,cap:a,title:s,view:c,sensors:l}){let{t:u}=X(),f=ir(),p=Vt(),m=hn({addonId:`pipeline-orchestrator`,deviceId:n.id,nodeId:`hub`}),[h,g]=o(!1),[_,v]=o(null),y=t(!1),[b,x]=o(!1),S=qo(l),C=ci(!0),w=Ce(c.id,S),T=Zo(Ri(m.data).motionCooldownMs,c.timeoutMs);if(r.kind===`absent`||!c.deviceTypes.includes(n.type))return null;let E=b||f.isPending||p.isPending,D=w.writable&&!E&&r.kind===`present`,O=async e=>{if(!w.writable||y.current){v(u(`customize.saveInFlight`));return}y.current=!0,x(!0);try{await wo(n.id,e,async e=>{await f.mutateAsync({deviceId:e.deviceId,config:e.config===null?null:{sensors:e.config.sensors.map(e=>({addonId:e.addonId,stableId:e.stableId,mode:e.mode}))}})},async e=>{let t={motionCooldownMs:e.patch.motionCooldownMs};await p.mutateAsync({deviceId:e.deviceId,patch:t})}),v(null),await l.refetch()===`failed`&&v(u(`customize.motion.refetchFailed`))}catch(e){v(e instanceof Error?e.message:String(e))}finally{y.current=!1,x(!1)}},k=w.rows.map(e=>({addonId:e.addonId,stableId:e.stableId,cap:`binary`,fieldPath:`on`,mode:e.mode,label:e.name}));return e(d,{children:[i(Qr,{id:a,icon:fe,title:s,testId:`event-card-${a}`,actions:i(K,{children:u(Mi(w.text,w.status.state))}),children:i(`div`,{className:`flex flex-col gap-2 px-3 py-2 sm:px-4`,children:r.kind===`pending`||S.kind===`pending`?i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:u(`customize.motion.reading`)}):r.kind===`unknown`||S.kind===`unknown`?i(Jo,{reason:Xo(S)||(r.kind===`unknown`?r.reason:``)}):e(d,{children:[i(Ko,{deviceId:n.id}),w.rows.length===0?i(`p`,{className:`text-xs text-foreground-subtle`,children:u(`customize.scalar.noOverride`)}):i(`ul`,{className:`flex flex-col gap-1`,children:w.rows.map(t=>e(`li`,{className:`text-xs text-foreground`,children:[Yo(t,C),t.reason===null?``:` — ${u(`customize.motion.state.${t.state}`)}`]},t.key))}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:u(`customize.event.timeoutSeconds`,{seconds:T/1e3})}),_!==null&&i(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:_}),i(`div`,{className:`flex flex-wrap gap-2`,children:i(J,{variant:`outline`,size:`sm`,"data-testid":`event-add-${a}`,disabled:!D,onClick:()=>g(!0),children:w.rows.length===0?u(`customize.scalar.add`):u(`customize.scalar.change`)})})]})})}),i(zo,{open:h,mode:w.rows.length===0?`add`:`change`,title:s,cap:a,targetId:c.id,host:n,target:{addonId:n.addonId,stableId:n.stableId},timeoutMs:T,cooldownMs:c.cooldownMs,sourceModes:c.sourceModes,sources:k,canSave:D,onClose:()=>g(!1),onSave:e=>{g(!1),O(e)}})]})}function Ko({deviceId:e}){let{t}=X(),n=Kr({deviceId:e,cap:`motion`,path:`detected`}),r=Kr({deviceId:e,cap:`motion`,path:`lastDetectedAt`}),a=jo(n.kind===`pending`?`pending`:n.kind!==`value`||typeof n.value!=`boolean`?`unknown`:n.value,r.kind===`value`&&typeof r.value==`number`?r.value:null,Date.now());return i(`p`,{role:`status`,className:`text-xs text-foreground`,children:t(a.kind===`active`?`customize.event.motionNow.active`:`customize.event.motionNow.${a.kind}`,a.seconds===null?void 0:{seconds:a.seconds})})}function qo(e){return e.presence===`pending`?{kind:`pending`}:e.status===null?{kind:`unknown`,reason:e.failureReason}:{kind:`known`,value:e.status}}function Jo({reason:e}){let{t}=X(),n=e.trim();return n.length===0?i(q,{message:t(`customize.motion.unreadableBare`)}):i(q,{title:t(`customize.motion.unreadable`,{reason:n}),message:n})}function Yo(e,t){if(t.kind!==`known`)return e.name;let n=t.value.find(t=>t.addonId===e.addonId&&t.stableId===e.stableId);return xi(e.name,n?.id??null,t.value.map(e=>({id:e.id,name:e.name,parentDeviceId:e.parentDeviceId??null})))}function Xo(e){return e.kind===`unknown`?e.reason??``:e.kind===`known`&&e.value.state===`unreadable`?e.value.reason:``}function Zo(e,t){return e!==null&&Number.isFinite(e)?e:t}var Qo=xe;function $o(e,t){let n=Qo[e];return n===void 0?null:n.targets.find(e=>e.id===t)??null}function es({device:e,handle:t,facts:n,sensors:r}){let{t:a}=X();return i(d,{children:si().map(o=>{let s=o.pulse??o.span;if(s===null||!s.deviceTypes.includes(e.type))return null;let c=$o(o.cap,s.id);if(c===null)return null;let l=a(o.pulse===null?`customize.motion.title`:`customize.doorbell.title`),u=Ni(Jr(o.cap,c),n);return o.pulse===null?o.span===null?null:i(Go,{device:e,availability:u,cap:o.cap,title:l,view:o.span,sensors:r},o.cap):i(Po,{device:e,handle:t,availability:u,cap:o.cap,title:l,view:o.pulse},o.cap)})})}function ts({id:t,icon:n,title:r,headerControl:a,addLabel:o,onAdd:s,addDisabled:c=!1,notices:l,suggestion:u,children:f}){let{t:p}=X(),m=s!==void 0&&o!==void 0;return e(Qr,{id:t,icon:n,title:r,actions:e(d,{children:[a,m&&!c&&u!==void 0&&u.count>0&&e(J,{variant:`ghost`,size:`sm`,onClick:u.onOpen,children:[i(re,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),p(`customize.suggest.hint`,{count:u.count,location:u.location})]}),m&&i(J,{variant:`outline`,size:`sm`,disabled:c,onClick:s,children:o})]}),children:[l!==void 0&&i(`div`,{className:`flex flex-col gap-1 px-3 pt-2 empty:hidden sm:px-4`,children:l}),i(`ul`,{className:`flex flex-col divide-y divide-border`,children:f})]})}function ns(e,t){if(e.kind!==`known`||typeof t!=`string`||t.length===0)return null;let n=Wn(e.value,t),r=new Map(e.value.map(e=>[e.id,e])),i=new Map;for(let e of n){let t=r.get(e)?.parentDeviceId,n=t==null?void 0:r.get(t);n!==void 0&&n.type===`container`&&i.set(e,n.name)}return{location:t,ids:n,containers:i}}function rs(e,t,n){return cr(e,t?.ids??new Set,n)}function is(e,t){return e?.containers.get(t)??null}function as(e,t,n){return e.kind===`known`?rs(e.value,t,n).suggested.length:0}function os(e,t){let n=[t,e.detail].filter(e=>e!==null&&e!==``);return n.length===0?null:n.join(` · `)}function ss({location:t,devices:n,action:r,onPick:a,onPickAll:o}){let{t:s}=X();if(n.length===0)return null;let c=s(`customize.suggest.heading`,{location:t});return e(`section`,{"aria-label":c,className:`flex flex-col gap-1`,children:[e(`div`,{className:`flex min-h-7 items-center gap-2`,children:[i(`h3`,{className:`${j} min-w-0 flex-1`,children:c}),o!==void 0&&n.length>1&&i(J,{variant:`ghost`,size:`sm`,onClick:o,children:s(`customize.suggest.addAll`,{count:n.length})})]}),i(`ul`,{className:`flex flex-col divide-y divide-border rounded-md border border-border`,children:n.map(t=>{let n=os(t,t.container===null||t.name.includes(t.container)?null:s(`customize.suggest.in`,{container:t.container}));return e(`li`,{className:`${A} flex items-center gap-3`,children:[e(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`text-xs text-foreground break-words`,children:t.name}),n!==null&&i(`div`,{className:`text-[11px] text-foreground-subtle break-words`,children:n})]}),i(J,{variant:`outline`,size:`sm`,"aria-label":s(r===`add`?`customize.suggest.addNamed`:`customize.suggest.useNamed`,{name:t.name}),onClick:()=>a(t.id),children:s(r===`add`?`customize.suggest.add`:`customize.suggest.use`)})]},t.id)})})]})}c();function cs(e){return e.kind===`pending`?`pending`:e.kind===`unknown`?`failed`:`answered`}function ls(e){return e.map(e=>({id:e.deviceId,name:e.name,...e.meta===null?{}:{type:e.meta},...e.detail===null?{}:{location:e.detail.includes(` · `)?e.detail.split(` · `).at(-1)??null:e.detail},...e.detail===null?{}:{detail:e.detail}}))}function us({open:t,title:r,selection:s,candidates:c,filters:l,room:u=null,confirmLabel:d,onConfirm:f,onClose:p}){let{t:m}=X(),[h,g]=o(null),[_,v]=o([]),y=l?.find(e=>e.id===h)??l?.[0]??null,b=c.kind===`known`?c.value:[],x=c.kind===`known`?Ii(c.value,``,y):[],S=rs(b,u,e=>e.deviceId).suggested,C=rs(x,u,e=>e.deviceId).others,w=n(()=>ls(C),[C]),T=cs(c),E=b.filter(e=>_.includes(e.deviceId));a(()=>{t||(v([]),g(null))},[t]);let D=()=>{v([]),g(null),p()},O=e=>{e.length!==0&&(f(e),v([]),g(null))},k=()=>O(E);return i(er,{open:t,onOpenChange:e=>e?void 0:D(),children:e(Dn,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":r,children:[i(mr,{children:i(Sr,{children:r})}),e(Vn,{className:`flex flex-col gap-2 p-2 sm:p-4`,children:[l!==void 0&&l.length>0&&i(`div`,{className:`flex flex-wrap gap-1`,role:`tablist`,"aria-label":m(`customize.assign.filtersLabel`),children:l.map(e=>i(`button`,{type:`button`,role:`tab`,"aria-selected":(y?.id??null)===e.id,className:`inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${(y?.id??null)===e.id?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:bg-surface-hover`}`,onClick:()=>g(e.id),children:m(e.labelKey)},e.id))}),u!==null&&i(ss,{location:u.location,devices:S.map(e=>({id:e.deviceId,name:e.name,container:is(u,e.deviceId),detail:e.detail})),action:`add`,onPick:e=>O(S.filter(t=>t.deviceId===e)),...s===`multi`?{onPickAll:()=>O(S)}:{}}),c.kind===`unknown`?i(`p`,{role:`alert`,className:`text-xs text-warning`,children:m(`customize.assign.unknown`,{reason:c.reason})}):w.length===0&&S.length>0?null:i(Pt,{devices:w,listState:T,value:_,onChange:e=>v(s===`single`?e.length>0?[e[e.length-1]]:[]:e),noun:`device`,emptyLabel:m(`customize.assign.none`),showAll:!0,testId:`customize-device-picker`})]}),e(an,{children:[i(J,{variant:`ghost`,onClick:D,children:m(`customize.picker.cancel`)}),i(J,{disabled:E.length===0,onClick:k,children:d(E.length)})]})]})})}c();function ds(e,t){let r=typeof e==`string`&&e.length>0,i=ci(t&&r);return n(()=>t?ns(i,e):null,[t,i,e])}c();function fs(e){return e==null?null:e.message}function ps({device:t}){let n=ue(),{t:r}=X(),a=l(),s=ri(),c=we.includes(t.type),[u,f]=o(!1),[p,m]=o(!1),[h,g]=o(null),_=Ft({deviceId:t.id},{enabled:c}),v=Zi({status:_.status,data:_.data,error:fs(_.error)===null?null:{message:fs(_.error)??``}}),y=v.kind===`present`?v.slot.slotRef:``,b=v.kind===`present`?[...Yi(v.slot,v.value).map(e=>e.deviceId),...Ji(v.slot,v.value)]:[],x=Cr(),S=ci(c&&v.kind===`present`&&(u||b.length>0)),C=ds(t.location,c&&v.kind===`present`),w=yt({deviceId:t.id,slotRef:y},{enabled:(u||C!==null)&&v.kind===`present`});if(!c||v.kind===`absent`)return null;if(v.kind!==`present`)return i(ts,{id:`linked`,icon:I,title:r(`customize.linked.title`),notices:v.kind===`pending`?i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`customize.assign.checking`)}):i(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:r(`customize.assign.unknown`,{reason:v.reason})}),children:null});let T=v.value,E=new Map(S.kind===`known`?S.value.map(e=>[e.id,e]):[]),D=T.trackedDeviceIds!==void 0,O=(e,t)=>{let n=E.get(e.deviceId);return{...e,name:e.name??n?.name??null,type:n?.type??null,detail:n===void 0?null:Li(n.integration,n.location),orphan:t}},k=[...Yi(v.slot,T).map(e=>O(e,!1)),...Ji(v.slot,T).map(e=>O({deviceId:e,name:null,health:`ok`,implied:!1,tracked:!0},!0))],A=new Set(b),j=S.kind===`unknown`?S:w.status===`error`?{kind:`unknown`,reason:fs(w.error)??r(`helpers.customize.requestFailed`)}:S.kind===`pending`||w.status===`pending`||w.data===void 0?{kind:`pending`}:{kind:`known`,value:$i(w.data.candidates,E,A)},ee=async e=>{if(p){g(r(`customize.saveInFlight`));return}m(!0),g(null);try{await x.mutateAsync({deviceId:t.id,slotRef:v.slot.slotRef,value:e}),await _.refetch(),await a.invalidateQueries({queryKey:[[`deviceManager`]]})}catch(e){g(e instanceof Error?e.message:String(e))}finally{m(!1)}},te=async e=>{await s(r(`customize.linked.removeWhat`,{name:e.name??`#${e.deviceId}`}),!1)&&await ee(Qi(T,e.deviceId))},M=[{key:`device`,header:r(`customize.linked.device`),cell:t=>e(`div`,{className:`flex flex-col min-w-0`,children:[i(`span`,{className:`truncate text-xs text-foreground`,children:t.name??`#${t.deviceId}`}),t.detail!==null&&i(`span`,{className:`truncate text-[11px] text-foreground-subtle`,children:t.detail}),t.orphan&&i(`span`,{className:`text-[11px] text-foreground-subtle`,children:r(`customize.linked.notLinked`)}),t.health!==`ok`&&i(`span`,{role:`alert`,className:`text-[11px] text-warning`,children:r(`customize.linked.health.${t.health}`)})]})},{key:`type`,header:r(`customize.linked.type`),headerClassName:`hidden sm:table-cell`,cellClassName:`hidden sm:table-cell text-xs text-foreground-subtle`,cell:e=>e.type===null?`—`:Qn(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(Jt,{checked:e.tracked,disabled:p,"aria-label":r(`customize.linked.trackFor`,{name:e.name??e.deviceId}),onCheckedChange:t=>void ee(Xi(T,e.deviceId,t))})}]:[],{key:`remove`,header:``,cellClassName:`text-right w-10`,cell:e=>e.implied||e.orphan?null:i(yn,{icon:P,variant:`ghost`,size:`sm`,"aria-label":r(`customize.assign.removeNamed`,{name:e.name??e.deviceId}),disabled:p,onClick:t=>{t.stopPropagation(),te(e)}})}];return e(d,{children:[i(ts,{id:`linked`,icon:I,title:r(`customize.linked.title`),addLabel:r(`customize.linked.add`),onAdd:p?void 0:()=>f(!0),...C===null?{}:{suggestion:{count:as(j,C,e=>e.deviceId),location:C.location,onOpen:()=>f(!0)}},notices:e(d,{children:[S.kind===`unknown`&&i(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:r(`customize.assign.devicesUnreadable`,{reason:S.reason})}),h!==null&&i(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:h})]}),children:e(`li`,{className:`list-none px-3 py-2 sm:px-4`,children:[k.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`customize.assign.none`)}):i(Pn,{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:Qn(e.type,n).label,columns:M,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(us,{open:u,title:r(`customize.linked.pickTitle`),selection:`multi`,candidates:j,room:C,confirmLabel:e=>r(`customize.assign.addCount`,{count:e}),onConfirm:e=>{f(!1),ee(qi(T,e.map(e=>e.deviceId)))},onClose:()=>f(!1)})]})}c();function ms(e){return e instanceof Error?e.message:String(e)}function hs(e){let n=rt({addonId:e.addonId,stableId:e.stableId}),r=vr(),i=St(),a=Lt(),s=$r({status:n.status,data:n.data,error:n.error===null||n.error===void 0?null:{message:n.error.message}}),{t:c}=X(),l=t(!1),[u,d]=o(!1),f=async e=>{let t=Zr(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:ms(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 gs=`pipeline-orchestrator`;function _s(e){return e.data===void 0?e.status===`pending`?`pending`:e.status===`error`?`unknown`:`pending`:e.data.cameraSensors===void 0?`absent`:`present`}function vs(e,t){return e===`absent`?`absent`:_s(t)}async function ys(e){try{return(await e()).isError?`failed`:`answered`}catch{return`failed`}}function bs(e,t){let n=In(gs),r=at({deviceId:e},{enabled:t&&n!==`absent`}),i=()=>ys(r.refetch),a=r.data===void 0&&r.status===`error`?r.error?.message??null:null;return t?{presence:vs(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 xs(e,t){let n=tt({deviceType:e.type}),r=cn({deviceId:e.id}),i=vn({deviceId:e.id}),a=ui(n,e=>new Set(e.caps.map(e=>e.cap))),o=ui(r,e=>oi(e.entries)),s=ui(i,e=>e);return{deviceType:e.type,composable:a,nativeCaps:o,wireable:s,composed:new Set((t?.features??[]).map(e=>e.cap))}}function Ss(e,t,n){let r=t.kind===`known`&&t.value.has(`consumables`),i=Kr(r?{deviceId:e,cap:di,path:ji}:null);return Pi(t,n,r?i:null)}c();function Cs({device:t}){let{t:r}=X(),a=t.stableId.startsWith(`composed-`)?t.stableId.slice(Fe.length):null,o=Bt({blockId:a??``},{enabled:a!==null}),s=St(),c=Et(),l=Fn(),u=n(()=>{let e=new Set;for(let{cap:t}of Ci())e.add(t);for(let{cap:t}of _i())e.add(t);for(let{cap:t}of si())e.add(t);return e},[]);if(a===null)return i(`p`,{className:`text-xs text-foreground-subtle`,children:r(`customize.composed.missingBlock`)});if(o.status===`pending`)return i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`customize.loadingDevice`)});if(o.status===`error`)return i(q,{title:r(`customize.composed.loadFailed`),message:o.error.message,onRetry:()=>void o.refetch()});if(o.data.state===`not-loaded`)return i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`customize.status.notLoaded`,{reason:o.data.reason})});let d=o.data.view;if(d===null)return i(`p`,{className:`text-xs text-foreground-subtle`,children:r(`customize.composed.notFound`)});let f=Le(d.block);if(f===null)return i(`p`,{className:`text-xs text-foreground-subtle`,children:r(`compositionEditor.notComposition`)});if(Ti(f)){let n=Di(f.helper,t.name,t.location??``);return n===null?i(`p`,{role:`alert`,children:r(`helper.unreadable`)}):e(`div`,{className:`flex flex-col gap-3`,children:[i(vo,{device:t}),i(ki,{initial:n,start:`parameters`,saving:s.isPending,onSave:e=>gi(e,async(n,r)=>{await s.mutateAsync({blockId:d.block.id,expectedUpdatedAt:d.block.updatedAt,block:{composition:n,...r===``?{}:{name:r}}}),r!==``&&r!==t.name&&await c.mutateAsync({deviceId:t.id,name:r}),e.room.trim()!==``&&e.room.trim()!==(t.location??``)&&await l.mutateAsync({deviceId:t.id,location:e.room.trim()}),await o.refetch()})})]})}let p={target:{addonId:t.addonId,stableId:t.stableId},state:{kind:`present`,view:d,composition:f},saving:s.isPending,save:async e=>{if(e===null)return{kind:`refused`,reason:r(`customize.composed.noDelete`)};try{return await s.mutateAsync({blockId:d.block.id,expectedUpdatedAt:d.block.updatedAt,block:{composition:e}}),await o.refetch(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:e instanceof Error?e.message:String(e)}}}};return e(`div`,{className:`flex flex-col gap-3`,children:[i(vo,{device:t}),Fi(f)===`incomplete`&&i(K,{variant:`warning`,children:r(`customize.blockStatus.incomplete`)}),i(Xr,{device:t,handle:p,skipCaps:u})]})}c();function ws({deviceId:e}){let{t}=X(),n=gn({deviceId:e}),r=n.data;if(r==null)return n.status===`error`?i(q,{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(Cs,{device:r}):i(Ts,{device:r,target:{addonId:r.addonId,stableId:r.stableId}});return i(Mr,{deviceId:r.id,seed:{name:r.name,location:r.location??``,role:r.role??null,display:r.display},children:a})}function Ts({device:t,target:r}){let a=hs(r),o=In(`composer`),{t:s}=X(),c=bs(t.id,t.type===W.Camera),l=xs(t,li(a.state)),u=Ss(t.id,l.nativeCaps,l.wireable),d={deviceType:t.type,composable:l.composable,nativeCaps:l.nativeCaps,cameraSensors:c.presence},f=n(()=>{let e=new Set;for(let{cap:t}of Ci())e.add(t);for(let{cap:t}of _i())e.add(t);for(let{cap:t}of si())e.add(t);return e},[]);return e(`div`,{className:`flex flex-col gap-3`,children:[i(vo,{device:t}),o===`absent`&&i(`p`,{role:`alert`,className:`text-xs text-warning`,children:s(`customize.composerAbsent`)}),a.state.kind!==`none`&&i(Es,{state:a.state}),i(es,{device:t,handle:a,facts:d,sensors:c}),i(Ei,{device:t,handle:a,facts:d}),i(vi,{device:t,handle:a,facts:d,defaults:u}),i(Xr,{device:t,handle:a,skipCaps:f}),i(ps,{device:t})]})}function Es({state:t}){let{t:n}=X();switch(t.kind){case`pending`:return i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:n(`customize.status.pending`)});case`unknown`:return i(q,{title:n(`customize.status.unknownTitle`),message:t.reason});case`not-loaded`:return i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:n(`customize.status.notLoaded`,{reason:t.reason})});case`none`:return null;case`present`:{let r=t.view.block;return e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(K,{variant:r.status===`running`?`success`:r.status===`failed`?`danger`:`warning`,children:n(`customize.blockStatus.${r.status}`)}),!r.enabled&&i(K,{variant:`default`,children:n(`customize.status.off`)}),r.lastError!==void 0&&i(`span`,{className:`text-[11px] text-foreground-muted break-words`,children:r.lastError}),t.view.state.kind===`unreachable`&&i(`span`,{className:`text-[11px] text-warning`,children:n(`customize.status.composerUnreachable`,{reason:t.view.state.error})})]})}}}var Ds=`overview`;function Os(e,t){return e.some(e=>e.id===t)?t:Ds}function ks({deviceId:t}){let{t:n}=X(),r=l(),a=Number.isFinite(t),{data:o}=gn({deviceId:t},{enabled:a}),s=typeof o?.type==`string`?o.type:`camera`;nr([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:c,isLoading:u,isError:d,error:f}=cn({deviceId:t},{enabled:a}),{data:p}=$n({deviceType:s},{enabled:!!s}),m=It({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(Ke,{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(As,{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(js,{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(Ms,{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(Lr,{i18nKey:`device.bindingsTab.boundSummary`,count:_.length,values:{bound:v},components:{b:i(`span`,{className:`font-medium text-foreground`}),em:i(`em`,{})}})}),i(hr,{columns:y,rows:_,rowKey:e=>e.capName,minWidthPx:720})]})}function As({kind:t}){let{t:n}=X();return t===`native`?e(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-success/30 text-success bg-success/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[i(ae,{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(Ye,{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(I,{className:`h-3 w-3`}),n(`device.bindingsTab.linked`)]}):e(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border text-foreground-subtle/70 px-1.5 py-0.5 text-[10px] font-medium`,children:[i(x,{className:`h-3 w-3`}),n(`common.unbound`)]})}function js({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 Ms({wrappers:t,activeWrapperId:n,disabled:r,onPick:a}){let{t:o}=X();return t.length===0?i(`span`,{className:`text-[10px] opacity-40`,children:o(`device.bindingsTab.noneAvailable`,`none available`)}):i(`div`,{className:`flex flex-wrap gap-1`,children:t.map(t=>{let s=t===n;return e(`button`,{disabled:r,onClick:()=>a(t),title:s?o(`device.bindingsTab.clickToDeactivateRevertTo`,`Click to deactivate (revert to native)`):o(`device.bindingsTab.activateWrapper`,`Activate wrapper {{wrapperId}}`,{wrapperId:t}),className:`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 font-mono text-[10px] transition-colors disabled:opacity-50 ${s?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[i(s?O:he,{className:`h-3 w-3`}),t]},t)})})}function Ns({deviceId:t,activeSubTab:n,onSubTabChange:r,deviceType:a,isAdmin:o}){return e(`div`,{className:`flex flex-col gap-3`,children:[Ar(a,o)&&i(yr,{deviceId:t,readOnly:!0}),i(kr,{deviceId:t,activeSubTab:n,onSubTabChange:r})]})}c();var Ps=[[`pipelineOrchestrator`,`getCameraDetectionSource`]];function Fs(e){let t=l(),n=wt({deviceId:e},{refetchOnMount:`always`}),i=Gn(),[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:Ps})}catch(e){u(e instanceof Error?e.message:`Could not change the root detector`),await t.invalidateQueries({queryKey:Ps})}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 Is=`object-detection`;function Ls(e){return[e.addonId,...e.children.flatMap(Ls)]}function Rs(e,t){if(e===`pipeline`)return new Set;let n=zs(t,Is);return n===void 0?new Set:new Set(e===`onboard`?[n.addonId]:Ls(n))}function zs(e,t){for(let n of e){if(n.addonId===t)return n;let e=zs(n.children,t);if(e!==void 0)return e}}function Bs(e,t){return e===`onboard`?Y.t(`helpers.detectionSourceModel.badgeCameraAi`):t===`object-detection`?Y.t(`helpers.detectionSourceModel.badgeNoRoot`):Y.t(`helpers.detectionSourceModel.badgeIdle`)}function Vs(e){switch(e){case`pipeline`:return Y.t(`helpers.detectionSourceModel.explainPipeline`);case`onboard`:return Y.t(`helpers.detectionSourceModel.explainOnboard`);case`none`:return Y.t(`helpers.detectionSourceModel.explainNone`)}}function Hs(e){switch(e){case`boxed`:return``;case`while-streaming`:return Y.t(`helpers.detectionSourceModel.geometryWhileStreaming`);case`flag-only`:return Y.t(`helpers.detectionSourceModel.geometryFlagOnly`);case`unknown`:return Y.t(`helpers.detectionSourceModel.geometryUnknown`)}}function Us(e,t){return e===`onboard`?Y.t(`helpers.detectionSourceModel.noticeOnboard`):t===`object-detection`?Y.t(`helpers.detectionSourceModel.noticeNoRoot`):Y.t(`helpers.detectionSourceModel.noticeIdle`)}var Ws=[`pl-2`,`pl-6`,`pl-10`,`pl-14`],Gs={detector:`success`,cropper:`info`,classifier:`primary`,refiner:`warning`,"audio-classifier":`neutral`};function Ks(e){return Ws[Math.min(e,Ws.length-1)]??`pl-2`}function qs(e){return e.zoneDriven?{kind:`zone-driven`}:{kind:`gate`,effectiveOn:e.ownOn,defaultOn:e.defaultOn,explicit:e.choice!==`auto`}}function Js(e,t,n){return e.kind===`parent`?n:Bs(e.source,t)}function Ys({inputs:t,outputs:n}){return t.length===0&&n.length===0?null:e(`span`,{className:`inline-flex flex-wrap items-center gap-1`,children:[t.map(e=>i(K,{size:`sm`,variant:`info`,children:e},`in-${e}`)),t.length>0&&n.length>0&&i(`span`,{className:`text-[10px] text-foreground-subtle`,"aria-hidden":!0,children:`→`}),n.map(e=>i(K,{size:`sm`,variant:`success`,children:e},`out-${e}`))]})}function Xs({rows:t,label:n,selectedId:r,busy:a,onOpen:o,onSet:s}){let{t:c}=X(),l=e=>{switch(e){case`detector`:return c(`device.cameraStepInspector.kindDetector`,`detector`);case`cropper`:return c(`device.cameraStepInspector.kindCropper`,`cropper`);case`classifier`:return c(`device.cameraStepInspector.kindClassifier`,`classifier`);case`refiner`:return c(`device.cameraStepInspector.kindRefiner`,`refiner`);case`audio-classifier`:return c(`device.cameraStepInspector.kindAudio`,`audio`)}},u=c(`device.cameraStepInspector.offBecauseParent`,`Off because its parent is off`);return i(`ul`,{"aria-label":n,className:`divide-y divide-border rounded-md border border-border`,children:t.map(t=>{let n=t.stepId===r,c=t.blocked===null?null:Js(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 ${Ks(t.depth)} ${n?`bg-primary/10`:t.runs?``:`bg-muted/40`}`,children:[e(`button`,{type:`button`,"aria-expanded":n,onClick:()=>o(t.stepId),className:`flex min-w-0 flex-1 flex-wrap items-center gap-x-2 gap-y-1 text-left`,children:[i(`span`,{className:`text-sm font-medium ${t.runs?`text-foreground`:`text-foreground-muted`}`,children:t.name}),i(K,{size:`sm`,variant:Gs[t.kind],children:l(t.kind)}),i(Ys,{inputs:t.inputs,outputs:t.outputs}),c!==null&&i(`span`,{className:`text-[11px] text-warning`,children:c})]}),i(ln,{gate:qs(t),busy:a,onSet:e=>s(t.stepId,e)})]},t.stepId)})})}function Zs(e,t){let n=e?.[t];return n===void 0?`auto`:n?`on`:`off`}function Qs(e,t){return e===`auto`?t:e===`on`}function $s(e,t,n){return e!==`onboard`&&e!==`none`||!n.has(t)?null:{kind:`source`,source:e}}function ec(e,t,n,r,i){let a=e.zoneDrivenIds??new Set;return t.flatMap(t=>{let o=a.has(t.addonId),s=Zs(e.toggles,t.addonId),c=e.defaults[t.addonId]??!0,l=o||Qs(s,c),u=r===null?$s(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,...ec(e,t.children,n+1,f,i)]})}function tc(e){let t=e.source===null?new Set:Rs(e.source,e.tree);return ec(e,e.tree,0,null,t)}function nc({source:t,geometry:n,saving:r,error:a,onPick:o}){let{t:s}=X(),c=n===`flag-only`,l=Hs(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:j,children:s(`device.detectionSourceControl.rootDetector`,`Root detector`)}),i(Nn,{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:ge,children:[Vs(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 rc=new Set([`package-detection`]),ic=`/system/pipeline?view=nodes`;function ac(e){return Object.fromEntries(e.slots.flatMap(e=>e.addons.map(e=>[e.id,e.enabledByDefault??!0])))}function oc({deviceId:a}){let{t:c}=X(),u=Yt(),d=Yn(),f=l(),p=R().trpcClient,m=t(null),h=t(null),g=At({deviceId:a},{refetchOnMount:`always`}),_=_t(void 0,{refetchOnMount:`always`});nr([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let{nodes:v}=Bn(),y=n(()=>{let e=new Set((_.data??[]).map(e=>e.nodeId));return v.filter(t=>t.isOnline&&e.has(t.id)).map(e=>({id:e.id,name:e.name}))},[_.data,v]),b=y.map(e=>e.id).join(`,`),x=s({enabled:y.length>0,queryKey:[[`pipelineExecutor`,`getSchema`],`camera-step-schemas`,b],queryFn:async()=>{let e={};for(let t of y)try{e[t.id]=await p.pipelineExecutor.getSchema.query({nodeId:t.id})}catch{}return e}}),S=r(()=>{f.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]})},[f]),C=sn({onSuccess:S}),w=jn(),[T,E]=o(null),[D,O]=o(!1),[k,A]=o(null),j=Fs(a),ee=x.data??{},te=g.data??null,M=y.map(e=>ee[e.id]).find(e=>e!==void 0)??null,ne=n(()=>M?nn(M):[],[M]),re=n(()=>M===null?[]:tc({tree:ne,toggles:te?.stepToggles,defaults:ac(M),source:j.source,zoneDrivenIds:rc}),[ne,M,te?.stepToggles,j.source]),{selection:N,open:ie,close:ae}=Vi(n(()=>re.map(e=>e.stepId),[re]),[]),F=y[0]?.id,oe=r(async e=>{if(T!==null){if(!await u({title:c(`stepInspector.stepMatrixFrame.discardUnsavedChanges`,`Discard unsaved changes?`),message:c(`stepInspector.stepMatrixFrame.thisStepHasChangesThat`,`This step has changes that are not saved yet.`),confirmLabel:c(`stepInspector.stepMatrixFrame.discard`,`Discard`),variant:`danger`}))return;E(null)}e()},[u,T,c]),se=e=>{e!==N.stepId&&oe(()=>ie({stepId:e}))},I=()=>{oe(()=>ae())};if(_.isLoading||y.length>0&&x.isLoading)return i(`div`,{className:`animate-pulse p-4 text-xs text-foreground-subtle`,children:c(`device.cameraStepInspector.loadingPipeline`,`Loading pipeline…`)});if(y.length===0)return i(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:c(`device.cameraStepInspector.noPipelineNodeIsOnline`,`No pipeline node is online.`)});if(M===null)return i(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:c(`device.cameraStepInspector.catalogUnavailable`,`Catalog unavailable.`)});let L=e=>_.data?.find(e=>e.nodeId===F)?.settings.stepSettings?.[e]??{},z=re.find(e=>e.stepId===N.stepId)??null,B=z===null?null:Bi(M,z.stepId),ce=d?i(ur,{onClick:I}):i(yn,{icon:P,variant:`ghost`,size:`sm`,"aria-label":c(`common.close`,`Close`),onClick:I});return e(`div`,{ref:m,className:`space-y-2`,children:[j.view?.onboard.available===!0&&j.source!==null&&i(nc,{source:j.source,geometry:j.view.onboard.geometry,saving:j.saving,error:j.error,onPick:e=>void j.pick(e)}),i(`p`,{className:ge,children:i(Lr,{i18nKey:`device.cameraStepInspector.modelsChosenByAccelerators`,components:{nodes:i(Gr,{to:ic,className:`font-medium text-primary hover:underline`})}})}),N.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:N.staleStepId})}),i(Xs,{rows:re,label:c(`device.cameraStepInspector.detectionStepsOfThisCamera`,`Detection steps of this camera`),selectedId:N.stepId,busy:C.isPending,onOpen:se,onSet:(e,t)=>C.mutate({deviceId:a,addonId:e,enabled:t})}),i(ar,{open:z!==null&&B!==null,anchor:m,onClose:I,label:c(`stepInspector.stepMatrixFrame.stepSettings`,`Step settings`),children:z!==null&&B!==null&&i(sc,{addon:B,nodeBag:L(z.stepId),storedCamera:te?.stepSettings?.[z.stepId],draft:T?.stepId===z.stepId?T:null,saving:D,status:k,notice:z.blocked?.kind===`source`?Us(z.blocked.source,z.stepId):null,closeButton:ce,onEscape:I,headingRef:e=>{h.current=e},onDraft:e=>{A(null),E({stepId:z.stepId,camera:e})},onDiscard:()=>E(null),onSave:async e=>{O(!0);try{await w.mutateAsync({deviceId:a,addonId:z.stepId,settings:Object.keys(e).length>0?{...e}:null}),E(null),A({kind:`saved`})}catch(e){A({kind:`error`,error:e instanceof Error?e.message:c(`device.cameraStepInspector.saveFailed`)})}finally{O(!1),S()}}})})]})}function sc({addon:t,nodeBag:n,storedCamera:r,draft:a,saving:o,status:s,notice:c,closeButton:l,onEscape:u,headingRef:d,onDraft:f,onDiscard:p,onSave:m}){let{t:h}=X(),g=en(t),_=Ui(g),v=Hi(g),y=a?.camera??r,b=a!==null&&!Ne(a.camera,r??{});return i(xn,{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:ge,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(cc,{addon:t,fields:_,nodeBag:n,cameraBag:y,onChange:f}):i(`p`,{className:ge,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 cc({addon:e,fields:t,nodeBag:n,cameraBag:r,onChange:a}){let{t:o}=X();return i(Zt,{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 lc(e,t,n){return{id:e,get label(){return Y.t(t)},icon:n}}var uc=[lc(`object-detection`,`helpers.detectionSettingsGroups.objectDetection`,`scan-search`),lc(`tracking`,`helpers.detectionSettingsGroups.tracking`,`route`),lc(`motion`,`helpers.detectionSettingsGroups.motion`,`activity`),lc(`stationary`,`helpers.detectionSettingsGroups.stationary`,`square-parking`),lc(`zones`,`helpers.detectionSettingsGroups.zones`,`shapes`),lc(`audio`,`helpers.detectionSettingsGroups.audio`,`volume-2`),lc(`cluster`,`helpers.detectionSettingsGroups.cluster`,`server`)],dc={"pipeline-object-detection":`object-detection`,"detection-sensitivity":`object-detection`,"onboard-object-detection":`object-detection`,tracking:`tracking`,"tracking-core":`tracking`,"motion-tuning":`motion`,"stationary-objects":`stationary`,occupancy:`stationary`,zones:`zones`,"pipeline-audio":`audio`,"cluster-assignment":`cluster`,"orchestrator-live":`cluster`};function fc(e){return dc[e]??`object-detection`}c();var pc=`steps`,mc=`settings`,hc=new Set([pc,mc]);function gc(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}function _c({deviceId:t,activeSubTab:n,onSubTabChange:a}){let{t:o}=X();return e(Qe,{value:n&&hc.has(n)?n:pc,onValueChange:r(e=>{a?.(e)},[a]),className:`flex flex-col`,children:[e(ut,{className:`flex-shrink-0`,children:[i(Ut,{value:pc,children:o(`device.detectionPipelineTab.steps`,`Steps`)}),i(Ut,{value:mc,children:o(`device.detectionPipelineTab.settings`,`Settings`)})]}),i(Kt,{value:pc,children:i(oc,{deviceId:t})}),i(Kt,{value:mc,children:i(kr,{deviceId:t,sectionFilter:gc,subTabGrouping:{groupOf:e=>fc(e.id),tabs:uc}})})]})}var vc=`Notifications`,yc={i18nKey:`device.deviceNotificationMute.cameraCostWhenOff`,text:`This camera never notifies — no rule, no target, no alarm. Existing events, tracks and recordings are unaffected.`},bc={i18nKey:`device.deviceNotificationMute.deviceCostWhenOff`,text:`This device never notifies — no rule, no target, no alarm.`};function xc(e){let{mutedDeviceIds:t,deviceId:n}=e,r=t===null?null:!t.includes(n),i=e.pendingOn??null;return{label:vc,on:r===null?null:i??r,available:r!==null,costWhenOff:e.isCamera?yc:bc}}function Sc(e,t){return!e.available||e.on===null?null:{deviceId:t,muted:e.on}}c();function Cc(e){if(typeof e!=`object`||!e)return null;let t={...e}.mutedDeviceIds;return Array.isArray(t)?t.filter(e=>typeof e==`number`):null}function wc({deviceId:t,isCamera:n}){let{t:a}=X(),s=l(),c=Number.isFinite(t),[u,d]=o(null),[f,p]=o(null),m=xc({mutedDeviceIds:Cc(Jn({},{enabled:c}).data),deviceId:t,isCamera:n,pendingOn:f}),h=a(m.costWhenOff.i18nKey,m.costWhenOff.text),g=pn({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=Sc(m,t);e!==null&&(p(!e.muted),g.mutate(e))},[t,g,m]),v=m.on===null,y=m.on===!1,b=y?Ge:D;return e(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[e(`div`,{className:`border-b border-border px-4 py-2 flex items-center justify-between gap-2`,children:[i(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:a(`device.deviceNotificationMute.notifications`,`Notifications`)}),y&&i(`span`,{className:`rounded bg-warning/20 px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wide text-warning`,children:a(`common.muted`)})]}),e(`div`,{className:`px-4 py-3 flex items-start gap-3`,children:[e(`button`,{type:`button`,role:`switch`,"aria-label":m.label,"aria-checked":m.on===!0,disabled:!m.available||g.isPending,onClick:_,title:v?a(`device.deviceNotificationMute.notificationMuteStateUnknownThe`,`Notification mute — state unknown; the notification centre did not answer.`):y?a(`device.deviceNotificationMute.muted`,`Muted. {{costWhenOff}}`,{costWhenOff:h}):a(`device.deviceNotificationMute.notifyingMutingIt`,`Notifying. Muting it: {{costWhenOff}}`,{costWhenOff:h}),className:`inline-flex items-center gap-1.5 rounded-lg border px-2 py-1.5 text-[11px] font-medium transition-colors disabled:cursor-not-allowed ${u===null?v?`border-dashed border-border text-foreground-subtle/50`:y?`border-warning/40 text-warning hover:bg-warning/10`:`border-success/30 text-success hover:bg-success/10`:`border-danger/50 text-danger bg-danger/5`}`,children:[i(b,{className:`h-3.5 w-3.5`}),i(`span`,{children:v?a(`device.deviceNotificationMute.unknown`,`Unknown`):y?a(`device.deviceNotificationMute.muted2`,`Muted`):a(`device.deviceNotificationMute.notifying`,`Notifying`)})]}),i(`p`,{className:`flex-1 text-[11px] leading-relaxed text-foreground-subtle`,children:u===null?v?a(`device.deviceNotificationMute.theNotificationCentreDidNot`,`The notification centre did not answer, so this device’s mute state is unknown.`):h:a(`device.deviceNotificationMute.writeFailed`,`Write failed: {{failure}}`,{failure:u})})]})]})}c();function Tc({template:t,members:n,fleet:a,fleetKind:s,snapshot:c,nameOf:l}){let{t:u}=X(),[f,p]=o(()=>new Map),m=r((e,t)=>{p(n=>{if(jc(n.get(e),t))return n;let r=new Map(n);return r.set(e,t),r})},[]);if(t.family!==`actuator`)return null;let h=wi(c),g=t.id===`light`?Ai(n.map(e=>f.get(Ac(e))??{kind:`pending`})):null;return e(d,{children:[t.id===`light`&&n.map(e=>i(Oc,{member:e,row:kc(a,e),fleetKind:s,onRead:m},Ac(e))),g!==null&&i(Ec,{view:g}),e(`div`,{"data-testid":`helper-commands`,children:[i(`h3`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:u(`helper.commandTitle`)}),h.kind===`pending`&&i(`p`,{role:`status`,className:`mt-1 text-xs text-foreground-subtle`,children:u(`helper.reportingPending`)}),h.kind===`unavailable`&&i(q,{title:u(`helper.outputUnavailable`),message:h.message}),h.kind===`none`&&i(`p`,{className:`mt-1 text-xs text-foreground-muted`,children:u(`helper.commandNone`)}),h.kind===`rows`&&i(Dc,{view:h,nameOf:l})]})]})}function Ec({view:t}){let{t:n}=X();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`&&t.caps.length<=1&&i(`p`,{className:`mt-1 text-xs text-foreground-muted`,children:n(`helper.sharedNone`)}),t.kind===`ready`&&t.caps.length>1&&e(`ul`,{className:`mt-1 flex flex-col gap-0.5 text-xs text-foreground`,children:[t.caps.filter(e=>e!==`switch`).map(e=>i(`li`,{children:n(`helper.cap.${e}`)},e)),t.modes.map(e=>i(`li`,{children:n(`helper.mode.${e}`)},e))]})]})}function Dc({view:t,nameOf:n}){let{t:r}=X();return i(`ul`,{className:`mt-1 flex flex-col gap-0.5 text-xs text-foreground`,"data-testid":`helper-command-rows`,children:t.rows.map(t=>e(`li`,{children:[n(t.deviceId),` — `,r(`helper.cap.${t.cap}`),` —`,` `,t.ok?r(`helper.commandOk`):r(`helper.commandFailed`),t.error===null?``:` — ${t.error}`]},`${t.deviceId}:${t.cap}:${t.at}`))})}function Oc({member:e,row:t,fleetKind:n,onRead:r}){let i=Ac(e),o=cn({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 kc(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 Ac(e){return`${e.source.addonId}/${e.source.stableId}`}function jc(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`)}c();function Mc({deviceId:t,stableId:n}){let{t:a}=X(),s=n.startsWith(`composed-`)?n.slice(Fe.length):null,c=Bt({blockId:s??``},{enabled:s!==null}),l=dt({deviceId:t},{enabled:s!==null}),u=Sn({projection:`slim`},{enabled:s!==null}),[d,f]=o(()=>new Map),p=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(q,{title:a(`helper.outputUnavailable`),message:c.error.message});if(c.data.state!==`loaded`||c.data.view===null)return null;let h=Le(c.data.view.block);if(h===null||!Ti(h))return null;let g=Re(h.helper.templateId);if(g===null)return null;let _=Fc(l.status,l.data,l.error?.message),v=Si(_,g),y=fi(_),b=u.status===`success`?u.data.map(Ic):[],x=Lc(u.status),S=mi(h.helper.members.map(e=>d.get(Pc(e))??{name:e.source.stableId,presence:`unknown`})),C=v.kind===`number`?v.unit===void 0?String(v.value):`${v.value} ${v.unit}`:v.kind===`boolean`?v.value?a(`helper.on`):a(`helper.off`):v.kind===`empty`?a(`helper.noReading`):null;return i(Rt,{headingId:`helper-group-status`,title:a(`helper.statusTitle`),icon:Ke,testId:`helper-group-status`,children:e(`div`,{className:`${m} flex flex-col gap-3`,children:[h.helper.members.map(e=>i(Nc,{member:e,row:b.find(t=>t.addonId===e.source.addonId&&t.stableId===e.source.stableId)??null,fleetKind:x,onLive:p},Pc(e))),v.kind===`pending`&&i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:a(`helper.outputPending`)}),v.kind===`unavailable`&&i(q,{title:a(`helper.outputUnavailable`),message:v.message}),C!==null&&i(or,{value:C,label:a(`helper.template.${g.id}`)}),y.kind===`pending`&&i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:a(`helper.reportingPending`)}),y.kind===`unavailable`&&i(q,{title:a(`helper.outputUnavailable`),message:y.message}),y.kind===`absent`&&i(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:a(`helper.reportingAbsent`)}),y.kind===`ready`&&i(`p`,{className:`text-sm text-foreground`,"data-testid":`helper-reporting`,children:a(`helper.reporting`,{included:y.included,total:y.total})}),y.kind===`ready`&&y.excluded>0&&e(`div`,{children:[i(`h3`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:a(`helper.excluded`)}),S.kind===`pending`?i(`p`,{role:`status`,className:`mt-1 text-xs text-foreground-subtle`,children:a(`helper.excludedPending`)}):S.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:S.names.map(e=>i(`li`,{children:e},e))})]}),i(Tc,{template:g,members:h.helper.members,fleet:b.map(e=>({id:e.id,name:e.name,addonId:e.addonId,stableId:e.stableId,features:e.features})),fleetKind:x,snapshot:_,nameOf:e=>b.find(t=>t.id===e)?.name??String(e)})]})})}function Nc({member:e,row:t,fleetKind:n,onLive:r}){let i=t?.online===!0,o=dt({deviceId:t?.id??0},{enabled:n===`answered`&&t!==null&&i}),s=yi(o.status,o.status===`success`?hi(o.data):void 0,e.cap,e.fieldPath),c=Oi({fleet:n,deviceOnline:n===`answered`?t===null?null:t.online:!0,field:s}),l=t?.name??e.source.stableId,u=Pc(e);return a(()=>{r(u,{name:l,presence:c})},[u,l,r,c]),null}function Pc(e){return`${e.source.addonId}/${e.source.stableId}/${e.cap}.${e.fieldPath}`}function Fc(e,t,n){return e===`pending`?{kind:`pending`}:e===`error`?{kind:`error`,message:n??``}:{kind:`answered`,caps:hi(t)}}function Ic(e){return{id:e.id,name:e.name,online:e.online,addonId:e.addonId,stableId:e.stableId,features:e.features??[]}}function Lc(e){return e===`pending`?`pending`:e===`error`?`error`:`answered`}function Rc(e,t){return{switchId:e,label:ze[e].label,detail:t===void 0||t.length===0?null:t}}function zc(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 Bc(e){let t=zc(e),n=new Set(e.sourceStillLive),r=e.sourceStillLive.map(e=>Rc(e,t.get(e)?.detail)),i=[...t.values()].filter(e=>e.outcome===`not-offered`&&!n.has(e.switchId)).map(e=>Rc(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 Vc(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 Hc({deviceId:t,deviceName:r}){let{t:a}=X(),s=Yt(),[c,l]=o(null),u=Sn({isCamera:!0,projection:`slim`}),d=xr(),f=u.data!==void 0,p=n(()=>u.data===void 0?[]:Vc(u.data,t),[u.data,t]),m=p.find(e=>e.id===c)??null,h=d.data===void 0?null:Bc(d.data),g=d.error===null?null:d.error.message,_=async()=>{m===null||m.id===t||await s({title:a(`deviceMigrate.confirmTitle`,`Replace “{{source}}” with “{{target}}”?`,{source:r,target:m.name}),message:a(`deviceMigrate.confirmMessage`,`“{{target}}” takes over number {{sourceId}}. That number is what every recording, event, rule, zone and home-automation export of “{{source}}” is filed under, so all of it follows the number to the new hardware and keeps working. “{{source}}” is switched off and handed number {{targetId}} in exchange. This swaps two device identities and cannot be undone from here.`,{source:r,target:m.name,sourceId:t,targetId:m.id}),confirmLabel:a(`deviceMigrate.confirmAction`,`Migrate`),variant:`danger`})&&d.mutate({sourceId:t,targetId:m.id})};return e(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[e(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[e(`div`,{className:`min-w-0`,children:[i(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:a(`deviceMigrate.title`,`Migrate to…`)}),i(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:a(`deviceMigrate.subtitle`,`Replace this camera with other hardware you have already adopted. The new camera inherits number {{deviceId}}, so recordings, rules and integrations follow it.`,{deviceId:t})})]}),e(`div`,{className:`flex shrink-0 items-center gap-2`,children:[e(`select`,{"aria-label":a(`deviceMigrate.pickerLabel`,`Replacement camera`),className:`rounded-md border border-border bg-background px-2 py-1.5 text-xs text-foreground disabled:opacity-50`,disabled:!f||p.length===0||d.isPending,value:c===null?``:String(c),onChange:e=>{let t=e.target.value;l(t===``?null:Number(t))},children:[i(`option`,{value:``,children:f?a(`deviceMigrate.pickerPlaceholder`,`Select a camera…`):a(`deviceMigrate.pickerPending`,`Reading the fleet…`)}),p.map(t=>e(`option`,{value:String(t.id),children:[t.name,` (#`,t.id,`)`]},t.id))]}),e(`button`,{type:`button`,disabled:m===null||d.isPending,onClick:()=>{_()},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[i(Ve,{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(Uc,{report:h})]})}function Uc({report:t}){let{t:n}=X(),r=t.verdict===`quiet`;return e(`div`,{className:`mt-3 space-y-2 border-t border-border pt-3`,children:[i(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`deviceMigrate.swapped`,`The replacement now answers on number {{inheritedId}}; the old camera was handed number {{retiredId}}.`,{inheritedId:t.inheritedId,retiredId:t.retiredId})}),r?e(`div`,{className:`flex items-start gap-2 rounded-md border border-success/30 bg-success/5 px-3 py-2`,children:[i(z,{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(V,{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(Je,{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 Wc({deviceId:t}){let{t:n}=X(),[r,a]=o(null),s=$t({onSuccess:e=>{a(e.changed?`Re-aligned with source — ${e.rebuiltChildren} child${e.rebuiltChildren===1?``:`ren`} rebuilt.`:`Already up to date.`)},onError:e=>a(`Re-sync failed: ${e.message}`)});return e(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[e(`div`,{className:`flex items-center justify-between gap-3`,children:[e(`div`,{children:[i(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:n(`device.resyncButton.reSync`,`Re-sync`)}),i(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:n(`device.resyncButton.reAlignThisDeviceS`,`Re-align this device's type, role, capabilities and units with its source.`)})]}),e(`button`,{type:`button`,disabled:s.isPending,onClick:()=>{a(null),s.mutate({camDeviceId:t})},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[i(ie,{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 Gc(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function Kc({device:t}){let{t:n}=X(),r=Vr(),a=typeof t.id==`number`?t.id:null,o=String(t.type??``),s=o===W.Camera,c=o===W.Hub,l=t.features??[],u=l.includes(ye.Resyncable),{data:d}=Mt({deviceId:a??0},{enabled:a!==null&&s,refetchInterval:5e3}),f=d?.streams??{},p=Object.entries(f),m=l.includes(ye.DoorbellButton),h=kn(m?{deviceId:a??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`&&a!==null&&typeof t.stableId==`string`&&i(Mc,{deviceId:a,stableId:t.stableId}),c&&a!==null&&i(Ht,{deviceId:a,onOpenChild:e=>r(`/devices/${e}`)}),u&&a!==null&&i(Wc,{deviceId:a}),s&&a!==null&&i(Hc,{deviceId:a,deviceName:String(t.name??``)}),a!==null&&i(wc,{deviceId:a,isCamera:s}),s&&a!==null&&i(Cn,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:a}),m&&i(_r,{history:h.history,latestIsFresh:g}),s&&a!==null&&i(Cn,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:a}),s&&p.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:p.map(([t,r])=>e(`div`,{className:`px-4 py-2.5`,children:[e(`div`,{className:`flex items-center gap-2 mb-2`,children:[i(oe,{className:`h-3 w-3 text-foreground-subtle`}),i(`span`,{className:`text-[11px] font-medium text-foreground`,children:t})]}),e(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[i(qc,{label:n(`device.overviewTab.nominal`,`Nominal`),value:Gc(r.nominalBitrateKbps??0)}),i(qc,{label:n(`device.overviewTab.observed`,`Observed`),value:Gc(r.observedBitrateKbps??0)}),i(qc,{label:n(`device.overviewTab.peak`,`Peak`),value:Gc(r.peakBitrateKbps??0)}),i(qc,{label:n(`device.overviewTab.packetLoss`,`Packet Loss`),value:`${(r.packetLossPercent??0).toFixed(2)}%`,warning:(r.packetLossPercent??0)>1})]})]},t))})]}),i(zr,{})]})}function qc({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 Jc=`history`,Yc=[{id:`overview`,labelKey:`helpers.structuralTabs.overview`,cameraOnly:!1,adminOnly:!1},{id:`config`,labelKey:`helpers.structuralTabs.config`,cameraOnly:!1,adminOnly:!1},{id:Br,labelKey:`helpers.structuralTabs.customize`,cameraOnly:!1,adminOnly:!0},{id:Jc,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}],Xc=new Set([W.Hub,W.Container]);function Zc(e,t){let n=e===W.Camera,r=e===void 0||!Xc.has(e);return Yc.filter(e=>(n||!e.cameraOnly)&&(t||!e.adminOnly)&&(r||e.id!==`history`)).map(({id:e,labelKey:t})=>({id:e,label:Y.t(t)}))}function Qc({provider:e,integrationId:t,name:n}){let r=Vr(),a=t===null?`/integrations`:`/integrations/${t}`,o=n===null?`Open integrations`:`Open integration ${n}`;return i(`button`,{type:`button`,onClick:()=>r(a),className:`shrink-0 rounded-md transition-opacity hover:opacity-80 focus:outline-none focus-visible:ring-1 focus-visible:ring-primary/50`,title:o,"aria-label":o,children:i(Ur,{type:e,size:`lg`})})}c();var $c=[{id:`logs`,icon:B,labelKey:`common.logs`},{id:`repl`,icon:qe,labelKey:`deviceDetail.repl`},{id:`events`,icon:T,labelKey:`common.events`},{id:`state`,icon:S,labelKey:`common.state`}];function el(){let{t:a}=X(),s=ue(),c=Rr(),u=Number(c.deviceId),f=Number.isFinite(u),p=Vr(),m=l(),_=Yt(),v=R(),{user:b}=Er(),x=b?.isAdmin===!0,[S,C]=Nr(),w=S.get(`tab`)??`overview`,T=S.get(`sub`),[E,D]=o(`logs`),O=`device-detail.left-col-width-px`,[k,A]=o(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(O),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),j=t(k);j.current=k;function te(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??k??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{A(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=j.current;if(e!==null)try{window.localStorage.setItem(O,String(Math.round(e)))}catch{}document.body.style.userSelect=``,document.body.style.cursor=``};document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,document.addEventListener(`mousemove`,i),document.addEventListener(`mouseup`,a)}let{data:M,isLoading:ne,isError:re}=gn({deviceId:u},{enabled:f,refetchInterval:5e3,retry:1}),{data:N}=zn({deviceId:u},{enabled:f}),ae=n(()=>{let e=N?.settings?.sections??[],t=N?.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(Fr)&&r.add(Ir),[...r].map(e=>e===`export`?{id:e,label:Dr,isAddonContrib:!0}:{id:e,label:je[e]?.label??e,isAddonContrib:!0})},[N]),P=M,F=String(P?.name??c.deviceId??`Device`),oe=P?.online===!0,se=oe?`online`:`offline`,I=String(P?.addonId??`rtsp`),L=P?.features??[],z=P?.type,B=z===W.Camera,{data:le}=Pr(f?u:0),fe=z===W.Container,pe=n(()=>(le??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[le]),V=n(()=>fe?vt(pe,typeof P?.linkDeviceId==`number`?P.linkDeviceId:null,typeof P?.primaryChildEntityId==`string`?P.primaryChildEntityId:null)?.id??null:null,[fe,pe,P?.linkDeviceId,P?.primaryChildEntityId]),{data:he}=zn({deviceId:V??0},{enabled:V!==null}),ge=n(()=>{if(V===null)return[];let e=he?.settings?.sections??[],t=he?.live?.sections??[],n=new Set;for(let r of[...e,...t])r.location===`top-tab`&&r.tab&&n.add(r.tab);return[...n].map(e=>({id:e,label:je[e]?.label??e,isAddonContrib:!0,childDeviceId:V}))},[V,he]),_e=n(()=>La({sections:[...N?.settings?.sections??[],...N?.live?.sections??[]],deviceId:u,...V===null?{}:{child:{sections:[...he?.settings?.sections??[],...he?.live?.sections??[]],deviceId:V}}}),[N,he,u,V]),ve=typeof P?.parentDeviceId==`number`?P.parentDeviceId:null,{data:be}=gn({deviceId:ve??0},{enabled:ve!==null}),H=Yn(),U=P?.disabled!==!0,xe=n(()=>{let e=N?.settings?.sections??[],t=N?.live?.sections??[];return Or([...e,...t],z,x,N!==void 0)},[N,z,x]),Se=n(()=>{let e=new Set,t=[];for(let n of[...Zc(z,x),...ae,...ge])n.id===`config`&&!xe||e.has(n.id)||(e.add(n.id),t.push(n));return t},[z,x,ae,ge,xe]),Ce=n(()=>Os(Se,w),[Se,w]),we=r(e=>{C(t=>{let n=new URLSearchParams(t);e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`);for(let e of zi)n.delete(e);return n},{replace:!0})},[C]),Te=r(e=>{C(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[C]),Ee=(le??[]).length>0,De=n(()=>$c.filter(({featureGate:e})=>!e||L.includes(e)),[L]),{data:Oe}=pr(void 0),ke=n(()=>P?Dt(P,Oe):null,[P,Oe]),G=ke?.kind===`resolved`?ke.integration:null,Ae=G===null?ke?.kind===`unknown`?a(`deviceDetail.loadingIntegration`):ke?.kind===`orphan`?a(`deviceDetail.missingIntegration`):a(`deviceDetail.noIntegration`):G.name,Me=G!==null&&G.addonId===I?G.name:I,Ne=zt({onSuccess:()=>{m.invalidateQueries({queryKey:[[`deviceManager`]]}),p(G?.id?`/integrations/${G.id}`:`/integrations`)}}),Pe=Mn({onSuccess:()=>{m.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=Xe({onSuccess:()=>{m.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ie=Ze(),Le=Ot({onSuccess:()=>{m.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Re=L.includes(ye.Rebootable),ze=L.includes(ye.BatteryOperated),Be=$e(v.trpcClient,ze&&f?u:null),Ve=Tr(v.trpcClient,f?u:null),He=ce(v.trpcClient,f?u:null,e=>e.runningState),Ue=He===void 0||He.running===null?null:He.running,We=Qn(z??`unknown`,s).icon,[Ge,Ke]=o(!1),qe=async()=>{if(!Ge){Ke(!0);try{let e=F.replace(/[^a-zA-Z0-9_.-]+/g,`_`),t=new Date().toISOString().replace(/[:.]/g,`-`);await ea(`${ee}/${String(u)}.jpg?force=1`,`${e}-${t}.jpg`)}finally{Ke(!1)}}},Je=Pe.isPending||Fe.isPending,{data:Ye}=Gt({deviceId:u},{enabled:f&&B,refetchInterval:1e4}),K=Ye?.agentNodeId??null,Qe=typeof K==`string`&&K.length>0&&!K.startsWith(`addon:`)?K:void 0,{data:tt}=En({deviceId:u,...Qe?{nodeId:Qe}:{}},{enabled:f&&B,refetchInterval:3e3,retry:!1}),{data:q}=qt({deviceId:u},{enabled:f&&B,refetchInterval:3e3,retry:!1}),rt=q?.level?.dbfs??null;function it(){if(!f)return null;switch(Ce){case`overview`:return i(Kc,{device:P??{}});case`config`:return i(Ns,{deviceId:u,activeSubTab:T,onSubTabChange:Te,deviceType:z,isAdmin:x});case`detection-pipeline`:return i(_c,{deviceId:u,activeSubTab:T,onSubTabChange:Te});case`bindings`:return i(ks,{deviceId:u});case Jc:return i(Ln,{deviceId:u,onNavigate:e=>p(e)});case Br:return i(ws,{deviceId:u});default:{let e=Ce,t=ae.some(t=>t.id===e),n=ge.find(t=>t.id===e);if(!t&&n===void 0)return null;let r=n?.childDeviceId??u;if(e===`export`)return i(kr,{deviceId:u,sectionFilter:Fr,activeSubTab:T,onSubTabChange:Te});let a=i(kr,{deviceId:r,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:T,onSubTabChange:Te});return n!==void 0&&r!==u?i(wr,{deviceId:r,children:a}):a}}}return f?ne?e(`div`,{className:`flex flex-col h-full`,children:[e(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[i(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),i(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),i(`div`,{className:`flex-1 p-6`,children:i(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):re||!M?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(Lr,{i18nKey:`deviceDetail.noDeviceWithId`,values:{id:u},components:{code:i(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`})}})}),i(`button`,{onClick:()=>p(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:a(`deviceDetail.backToIntegrations`,`Back to Integrations`)})]}):e(`div`,{className:`absolute inset-0 flex flex-col overflow-clip`,children:[e(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[i(`div`,{className:`mb-2`,children:i(nt,{items:[{label:a(`deviceDetail.integrations`,`Integrations`),onClick:()=>p(`/integrations`)},G===null?{label:Ae}:{label:Ae,onClick:()=>p(`/integrations/${G.id}`)},{label:F}]})}),e(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[G!==null&&i(Qc,{provider:G.addonId,integrationId:G.id,name:G.name}),i(Tt,{running:Ue,children:i(We,{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:F}),i(Zn,{status:se}),ze&&i(ot,{status:Be,variant:`full`}),i(Ct,{status:Ve})]}),ve!==null&&be&&e(`button`,{type:`button`,onClick:()=>p(`/devices/${ve}`),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:be.name}),children:[i(`span`,{children:`↑`}),i(`span`,{className:`truncate`,children:String(be.name??`Device #${ve}`)})]}),i(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:L.length>0&&i(jr,{capabilities:L})})]}),tt&&i(`div`,{className:`hidden lg:flex`,children:i(tl,{metrics:tt,dbfs:rt})}),e(`div`,{className:`flex items-center gap-1 shrink-0`,children:[e(`button`,{onClick:async()=>{U?await _({title:a(`deviceDetail.disable`,`Disable "{{name}}"?`,{name:F}),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`})&&Fe.mutate({deviceId:u}):Pe.mutate({deviceId:u})},disabled:Je,title:U?a(`deviceDetail.disableDevice`,`Disable device`):a(`deviceDetail.enableDevice`,`Enable device`),className:`inline-flex items-center gap-1.5 rounded-lg px-2 sm:px-2.5 py-1.5 text-[11px] font-medium border transition-colors disabled:opacity-50 ${U?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[i(g,{className:`h-3.5 w-3.5`}),i(`span`,{className:`hidden sm:inline`,children:Je?a(`deviceDetail.updating`,`Updating…`):U?a(`deviceDetail.enabled`,`Enabled`):a(`deviceDetail.disabled`,`Disabled`)})]}),i(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),B&&e(d,{children:[i(sa,{deviceId:u}),i(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`})]}),i(la,{deviceId:u}),i(br,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:a(`deviceDetail.takeSnapshot`,`Take snapshot`),description:a(`deviceDetail.fetchAFreshFrameAnd`,`Fetch a fresh frame and download it.`),icon:h,disabled:Ge,onClick:()=>{qe()}},{id:`reboot`,label:a(`deviceDetail.rebootDevice`,`Reboot device`),description:a(`deviceDetail.cameraGoesOfflineFor30`,`Camera goes offline for ~30 seconds.`),icon:me,hidden:!Re,disabled:Ie.isPending,danger:!0,onClick:async()=>{await _({title:a(`deviceDetail.reboot`,`Reboot "{{name}}"?`,{name:F}),message:a(`deviceDetail.theCameraWillGoOffline`,`The camera will go offline for around 30 seconds while the firmware reboots.`),confirmLabel:a(`deviceDetail.reboot2`,`Reboot`),variant:`danger`})&&Ie.mutate({deviceId:u})}},{id:`restart-addon`,label:a(`deviceDetail.restartAddon`,`Restart addon`),description:a(`deviceDetail.bouncesEveryDeviceServedBy`,`Bounces every device served by {{servingAddonLabel}}.`,{servingAddonLabel:Me}),icon:ie,disabled:Le.isPending,danger:!0,onClick:async()=>{await _({title:a(`deviceDetail.restart`,`Restart "{{servingAddonLabel}}"?`,{servingAddonLabel:Me}),message:a(`deviceDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device served by it (not just "{{name}}"). Streams will reconnect automatically.`,{name:F}),confirmLabel:a(`deviceDetail.restart2`,`Restart`),variant:`danger`})&&Le.mutate({addonId:I})}},{id:`delete`,label:a(`deviceDetail.deleteDevice`,`Delete device`),description:a(`deviceDetail.removeTheDeviceAndAll`,`Remove the device and all its settings.`),icon:y,separatorBefore:!0,disabled:Ne.isPending,danger:!0,onClick:async()=>{await _({title:a(`deviceDetail.delete`,`Delete "{{name}}"?`,{name:F}),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`})&&Ne.mutate({deviceId:u})}}]})]})]})]}),i(wr,{deviceId:u,device:P??void 0,children:i(et,{children:i(dn,{children:i(de,{children:i(fn,{children:e(`main`,{className:H?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[e(`div`,{className:H?`flex flex-col bg-surface`:`${k===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-y-auto`,style:!H&&k!==null?{width:`${String(k)}px`}:void 0,children:[i(`div`,{className:B?`flex-shrink-0 border-b border-border-subtle bg-black`:H?`flex-shrink-0 border-b border-border-subtle bg-surface`:`shrink-0 border-b border-border-subtle bg-surface`,children:B?i(qa,{deviceId:u,intercomAvailable:L.includes(ye.TwoWayAudio)}):e(`div`,{children:[i(Pa,{deviceId:u,deviceName:F,deviceType:z??`unknown`,provider:I,isOnline:oe,features:L}),i(Fa,{deviceId:u,widgets:_e})]})}),B&&_e.length>0&&i(`div`,{className:`flex-shrink-0 border-b border-border-subtle bg-surface pt-3 sm:pt-4`,children:i(Fa,{deviceId:u,widgets:_e})}),e(`div`,{className:H?`flex flex-col border-b border-border`:`flex-1 min-h-64 flex flex-col overflow-hidden`,children:[i(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:i(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:De.map(({id:t,labelKey:n,icon:r})=>{let o=E===t;return e(`button`,{onClick:()=>D(t),title:a(n),className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${o?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[i(r,{className:`h-3 w-3`}),a(n)]},t)})})}),e(`div`,{className:H?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[E===`logs`&&i(Ja,{deviceId:u,containerDeviceId:z===`container`?u:void 0}),E===`repl`&&i(Ya,{deviceId:u}),E===`events`&&i(Xa,{deviceId:u}),E===`state`&&i(Za,{deviceId:u})]})]})]}),!H&&i(`div`,{role:`separator`,"aria-orientation":`vertical`,title:a(`deviceDetail.dragToResize`,`Drag to resize`),onMouseDown:te,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:i(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),e(`div`,{className:H?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[i(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:i(`div`,{className:`flex flex-nowrap overflow-x-auto md:flex-wrap md:overflow-x-visible items-center gap-0`,children:Se.map(t=>{let n=Ce===t.id;return e(`button`,{onClick:()=>we(t.id),className:`relative flex-shrink-0 px-3 py-2 text-xs font-medium transition-colors ${n?`text-primary`:`text-foreground-subtle hover:text-foreground`}`,children:[t.label,n&&i(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},t.id)})})}),e(`div`,{className:H?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[Ce===`overview`&&Ee&&i(ua,{parentDeviceId:u}),it()]})]})]})})})})})})]}):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(Lr,{i18nKey:`deviceDetail.invalidSegment`,values:{segment:c.deviceId},components:{code:i(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`})}})}),i(`button`,{onClick:()=>p(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:a(`deviceDetail.backToIntegrations`,`Back to Integrations`)})]})}function tl({metrics:t,dbfs:n}){let r=ue(),{t:a}=X(),o=dr(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(fe,{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(M,{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{el as DeviceDetailPage};