@camstack/addon-admin-ui 1.2.446 → 1.2.447

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 (63) hide show
  1. package/dist/assets/{AddonAssetIcon-BtnvrLei.js → AddonAssetIcon-4Dl3K5Yu.js} +1 -1
  2. package/dist/assets/{Addons-DiN0Sq0P.js → Addons-D6G-9sO_.js} +1 -1
  3. package/dist/assets/{AdminPage-BgoL9iVo.js → AdminPage-CTKQzYSK.js} +1 -1
  4. package/dist/assets/{AdminSectionedPage-CoDZ6x7b.js → AdminSectionedPage-DB1wuvwM.js} +1 -1
  5. package/dist/assets/{AiProfiles-lNsea11k.js → AiProfiles-DGYy6F5H.js} +1 -1
  6. package/dist/assets/{BrokerForm-CswZ9Pol.js → BrokerForm-DgJKJJ9V.js} +1 -1
  7. package/dist/assets/{Build-DYD80n3d.js → Build-ChuBRxJe.js} +1 -1
  8. package/dist/assets/{Calendars-C4mjWRyG.js → Calendars-DTLTaLNh.js} +1 -1
  9. package/dist/assets/{Cluster-VodzpxZd.js → Cluster-CUFJA8Yh.js} +1 -1
  10. package/dist/assets/{ClusterStepModel-CAS-Vq8f.js → ClusterStepModel-G54nm4iG.js} +1 -1
  11. package/dist/assets/{CompositionEditor-jByeaDVd.js → CompositionEditor-ZIvK82Sw.js} +1 -1
  12. package/dist/assets/{CompositionEditorPage-B9gru9s4.js → CompositionEditorPage-DqCZgEdJ.js} +1 -1
  13. package/dist/assets/{Data-CJUHAXxy.js → Data-Dt-vrsjS.js} +1 -1
  14. package/dist/assets/{DeviceDetail-DJtah9RT.js → DeviceDetail-B-JixtlL.js} +1 -1
  15. package/dist/assets/{DeviceDoActionFields-Ba39XlhQ.js → DeviceDoActionFields-CU_AKA1W.js} +1 -1
  16. package/dist/assets/{Devices-D9_bQ-mC.js → Devices-CdmAtZP1.js} +1 -1
  17. package/dist/assets/{EmbedPlayerPage-GoJlsXiE.js → EmbedPlayerPage-OyxmU511.js} +1 -1
  18. package/dist/assets/{History-BZxSki6O.js → History-CYEo0VmZ.js} +1 -1
  19. package/dist/assets/{Identity-DMogY_EH.js → Identity-CFqxjMZh.js} +1 -1
  20. package/dist/assets/{IntegrationDetail-Diipw7Qj.js → IntegrationDetail-Cv36j4Pb.js} +1 -1
  21. package/dist/assets/{IntegrationHub-D9w-MPuX.js → IntegrationHub-Debcc46Y.js} +1 -1
  22. package/dist/assets/{Integrations-BYk2XLCB.js → Integrations-CTza89BR.js} +1 -1
  23. package/dist/assets/{Integrations-B3S-zuhI.js → Integrations-lU3DuymB.js} +1 -1
  24. package/dist/assets/{Library-3w1xKOPt.js → Library-D6P3tPHr.js} +1 -1
  25. package/dist/assets/{Locations-BmP4lTiU.js → Locations-C0hvZIQb.js} +1 -1
  26. package/dist/assets/{Logs-cGg5rkhk.js → Logs-CaO5TsuY.js} +1 -1
  27. package/dist/assets/{MyAccess-DQ_7mz2T.js → MyAccess-CaTk0IGs.js} +1 -1
  28. package/dist/assets/{Network-SboxgmTk.js → Network-BNthoi6m.js} +1 -1
  29. package/dist/assets/{NodeAddonsSettingsPanel-BAewekjl.js → NodeAddonsSettingsPanel-CpONFsu0.js} +1 -1
  30. package/dist/assets/{Notifications-DBcD1F0J.js → Notifications-WmYoCGsa.js} +1 -1
  31. package/dist/assets/{Recordings-ZawSBoKQ.js → Recordings-BBu3Qb1s.js} +1 -1
  32. package/dist/assets/{ScanNetworkModal-Q6h0tro3.js → ScanNetworkModal-B9n2JdTA.js} +1 -1
  33. package/dist/assets/{SessionsList-C0p8FnQi.js → SessionsList-D93VogSm.js} +1 -1
  34. package/dist/assets/{Showroom-GDC-4_10.js → Showroom-BaHMWO3G.js} +1 -1
  35. package/dist/assets/{System-BsfttXRK.js → System-D-2Ma-Kz.js} +1 -1
  36. package/dist/assets/{Terminal-ByO0PBzK.js → Terminal-TaTeiXX0.js} +1 -1
  37. package/dist/assets/{Viewer-Ba0H-L23.js → Viewer-DXjhAdbS.js} +1 -1
  38. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Cdb75XY5.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BYUIhxrf.js} +1 -1
  39. package/dist/assets/{addon-icons-context-BPV3OkkO.js → addon-icons-context-0MDrwtIo.js} +1 -1
  40. package/dist/assets/{authed-media-4VbI5rr4.js → authed-media-dGvmAGIm.js} +1 -1
  41. package/dist/assets/{device-integration-icon-Dadl9j0d.js → device-integration-icon-C_jsalSP.js} +1 -1
  42. package/dist/assets/device-picker-model-B0uThmDr.js +1 -0
  43. package/dist/assets/{hostInit-DcTpoL5R.js → hostInit-Cn05saXf.js} +1 -1
  44. package/dist/assets/{index-DmLUUGkL.js → index-2_qB4G1l.js} +3 -3
  45. package/dist/assets/{linked-devices-model-DjGQT8SB.js → linked-devices-model-Csh4WaVK.js} +1 -1
  46. package/dist/assets/{location-owned-usage-Bfhe0wto.js → location-owned-usage-Dqp8xgaw.js} +1 -1
  47. package/dist/assets/{mf-entry-bootstrap-0-45646240.js → mf-entry-bootstrap-0-1defdd87.js} +2 -2
  48. package/dist/assets/mount-B0uThmDr.js +1 -0
  49. package/dist/assets/{notification-schedule-field-DSAH7QIn.js → notification-schedule-field-CeZmOaz1.js} +1 -1
  50. package/dist/assets/remoteEntry-BiLc8a2-.js +1 -0
  51. package/dist/assets/{src-D9dVviCd.js → src-_mtQMfPm.js} +1 -1
  52. package/dist/assets/{use-scenes-feed-4m-FMCvL.js → use-scenes-feed-DsXuB27l.js} +1 -1
  53. package/dist/assets/{use-stationary-objects-Dxp_t9I6.js → use-stationary-objects-D_FqXLHG.js} +1 -1
  54. package/dist/assets/useEventInvalidation-B0uThmDr.js +1 -0
  55. package/dist/assets/{useNodeUrlSelection-D4c3I8B3.js → useNodeUrlSelection-DWli8jTd.js} +1 -1
  56. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CIloZSya.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CHMiEHNO.js} +2 -2
  57. package/dist/index.html +6 -6
  58. package/dist/server/addon.js +1 -1
  59. package/package.json +1 -1
  60. package/dist/assets/device-picker-model-Qf3yJdq3.js +0 -1
  61. package/dist/assets/mount-Qf3yJdq3.js +0 -1
  62. package/dist/assets/remoteEntry-DIFPrdpc.js +0 -1
  63. package/dist/assets/useEventInvalidation-Qf3yJdq3.js +0 -1
@@ -1,2 +1,2 @@
1
- import{$ as e,B as t,G as n,J as r,L as i,S as a,a as o,b as s,o as c,q 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-CEHpkaJP.js";import{Br as f,Ci as p,Cr as m,D as h,En as g,G as _,Gn as v,Hi as y,It as b,J as x,Jn as S,K as C,Kn as w,O as T,Oi as E,Ri as D,Rn as O,St as k,T as A,V as j,Vr as M,W as ee,Xn as N,Yr as P,Z as F,Zr as te,Zt as I,_t as L,bn as R,ca as ne,cr as z,dn as re,dt as B,en as V,ht as ie,lr as ae,m as oe,mi as se,na as H,or as ce,ot as U,pn as le,r as ue,t as de,ui as fe,vn as pe,xn as W,yn as me,z as he,zi as ge,zn as _e}from"./player-overlays-DyNPyo_W.js";import{Bn as ve,Dr as ye,Fr as G,Gr as be,In as xe,Jr as Se,Kr as Ce,Mr as K,Pr as we,Ti as Te,Tr as Ee,Vn as De,Xr as q,Yr as J,_ as Oe,_n as ke,an as Ae,cn as je,d as Me,gr as Ne,h as Pe,hn as Fe,ln as Ie,m as Le,mn as Re,on as ze,p as Be,rr as Ve,sn as He,v as Ue,wi as We,x as Ge,xr as Ke,zn as qe}from"./client-CRCWO8cg.js";import{t as Je}from"./archive-C3J7kPmp.js";import{i as Ye,n as Xe,r as Ze,t as Qe}from"./scan-eye-DSsbXKWH.js";import{t as $e}from"./bell-off-Df5MKmnk.js";import{t as et}from"./boxes-B4UVG1kT.js";import{n as tt}from"./video-BtFmM3eg.js";import{t as nt}from"./circle-slash-BTU53Q69.js";import{t as rt}from"./layers-CBNWlTsd.js";import{$ as it,$n as at,Ac as ot,An as st,Bu as ct,Cu as lt,Dn as ut,Ds as dt,Dt as ft,Er as pt,F as mt,Fn as ht,Fs as gt,Ft as _t,Fu as vt,G as yt,Ga as bt,Go as xt,Gt as St,Ha as Ct,Hc as wt,Hn as Tt,Ht as Et,Hu as Dt,In as Ot,Ir as kt,It as At,J as jt,Ju as Mt,K as Nt,Ka as Pt,Kt as Ft,La as It,Ln as Lt,Lr as Rt,Ls as zt,Ma as Bt,Mc as Vt,Mn as Ht,Mt as Ut,Mu as Wt,N as Gt,Nc as Kt,Nt as qt,Nu as Jt,Oa as Yt,On as Xt,Ou as Zt,Pc as Qt,Pn as $t,Pr as en,Qn as tn,Ra as nn,Rn as rn,Rt as an,Tn as on,Uo as sn,Ut as cn,Uu as ln,Va as un,Vt as dn,Wa as fn,Wo as pn,Wr as mn,Xt as hn,Y as gn,Yt as _n,Za as vn,Zn as yn,Zt as bn,a as xn,ac as Sn,an as Cn,ar as wn,ba as Tn,bt as En,c as Dn,ci as On,cr as kn,eo as An,er as jn,et as Mn,fa as Nn,fn as Pn,fr as Fn,ga as In,gn as Ln,go as Rn,gr as zn,gt as Bn,ha as Vn,hr as Y,i as Hn,ir as Un,jc as Wn,jn as Gn,jt as Kn,ju as qn,kc as Jn,kn as Yn,kt as Xn,ku as Zn,l as Qn,lc as $n,lr as er,mc as tr,mn as nr,na as rr,nr as ir,nt as ar,o as or,oa as sr,oc as cr,oo as lr,or as ur,po as dr,qt as fr,r as pr,rl as mr,rr as hr,s as gr,sa as _r,sc as vr,ta as yr,tt as br,uc as xr,va as Sr,wi as Cr,wn as wr,xr as Tr,ya as Er,yc as Dr,yn as Or,yo as kr,yt as Ar,zo as jr,zt as Mr}from"./src-D9dVviCd.js";import{t as X}from"./i18n-DzruZdmx.js";import{t as Z}from"./useTranslation-D3Is_4B6.js";import"./mount-Qf3yJdq3.js";import{A as Nr,F as Pr,H as Fr,I as Ir,J as Lr,K as Rr,M as zr,N as Br,P as Vr,Q as Hr,U as Ur,V as Wr,W as Gr,X as Kr,Y as qr,Z as Jr,et as Yr,g as Xr,h as Zr,j as Qr,nt as $r,p as ei,q as ti,tt as ni}from"./index-DmLUUGkL.js";import{C as ri,D as ii,E as ai,S as oi,_ as si,a as ci,b as li,c as ui,d as di,f as fi,g as pi,h as mi,i as hi,l as gi,m as _i,n as vi,o as yi,p as bi,r as xi,s as Si,t as Ci,u as wi,v as Ti,x as Ei,y as Di}from"./CompositionEditor-jByeaDVd.js";import{_ as Oi,a as ki,c as Ai,d as ji,f as Mi,g as Ni,h as Pi,i as Fi,l as Ii,m as Li,n as Ri,o as zi,p as Bi,s as Vi,t as Hi,u as Ui,v as Wi,y as Gi}from"./ClusterStepModel-CAS-Vq8f.js";import"./useEventInvalidation-Qf3yJdq3.js";import{t as Ki}from"./use-stationary-objects-Dxp_t9I6.js";import{a as qi,c as Ji,d as Yi,f as Xi,i as Zi,l as Qi,n as $i,o as ea,p as ta,r as na,s as ra,t as ia,u as aa}from"./linked-devices-model-DjGQT8SB.js";import{t as oa}from"./authed-media-4VbI5rr4.js";e();function sa(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 ca(e){if(typeof e!=`object`||!e)return null;let t=e.switches;if(!Array.isArray(t))return null;let n=t.map(sa).filter(e=>e!==null);return n.length===0?null:n}var la=[[/privacy|mask/i,`privacy`],[/microphone|mic\b/i,`microphone`],[/speaker|broker audio|stream audio/i,`speaker`],[/audio/i,`listening`],[/object|detect/i,`detection`],[/event/i,`archive`],[/record/i,`recording`],[/notif/i,`notifications`],[/stream|broker/i,`stream`]];function ua(e){for(let[t,n]of la)if(t.test(e))return n;return`generic`}function da(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(X.t(`helpers.cameraSwitchRows.off`,{list:r(t)})),n.length>0&&i.push(X.t(`helpers.cameraSwitchRows.unknown`,{list:r(n)})),{offIds:t,unknownIds:n,summary:i.length===0?X.t(`helpers.cameraSwitchRows.allOn`):i.join(` · `)}}var fa={stream:W,detection:Qe,privacy:f,microphone:N,speaker:k,listening:Xe,archive:Je,recording:Ze,notifications:D,generic:V};function pa({deviceId:e}){let{t}=Z(),n=c(),o=Number.isFinite(e),[s,l]=r(null),[u,f]=r(!1),p=xr({deviceId:e},{enabled:o});pr([`pipelineOrchestrator`,`getCameraSwitches`],[`capability.binding-changed`]);let m=ca(p.data),h=Qt({onError:(t,r)=>{console.error(`[CameraFunctionSwitches] switch write failed — reverting`,{tags:{deviceId:e},meta:{switchId:r.switchId,error:t instanceof Error?t.message:String(t)}}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSwitches`]]}),l({id:r.switchId,message:t instanceof Error?t.message:String(t)})},onSuccess:()=>{l(null),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]}),n.invalidateQueries({queryKey:[[`deviceManager`]]}),n.invalidateQueries({queryKey:[[`recording`]]})}}),g=i(t=>{!t.available||t.on===null||h.mutate({deviceId:e,switchId:t.id,enabled:!t.on})},[e,h]);if(m===null)return null;let _=da(m),v=e=>s?.id===e.id?s.message:null;return a(qn,{open:u,onOpenChange:f,children:[a(Jt,{"aria-label":t(`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 ${s===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:[d(V,{className:`h-3.5 w-3.5`}),d(`span`,{className:`hidden lg:inline`,children:t(`device.cameraFunctionSwitches.functions`,`Functions`)}),_.offIds.length>0&&d(`span`,{className:`rounded bg-warning/20 px-1 text-[9px] font-semibold uppercase tracking-wide`,children:t(`device.cameraFunctionSwitches.offCount`,{count:_.offIds.length})})]}),a(Wt,{align:`end`,className:`min-w-[240px] max-h-[60vh] overflow-y-auto p-1`,children:[d(`div`,{className:`px-2 py-1 text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t(`device.cameraFunctionSwitches.cameraFunctions`,`Camera functions`)}),d(`ul`,{className:`space-y-0.5`,children:m.map(e=>d(`li`,{children:d(ma,{row:e,failure:v(e),onToggle:()=>g(e)})},e.id))})]})]})}function ma({row:e,failure:t,onToggle:n}){let{t:r}=Z(),i=fa[ua(e.label)],o=e.on===null,s=e.on===!1,c=t===null?o?e.unavailableReason??`The source that owns this did not answer.`:e.costWhenOff:`Write failed: ${t}`,l=t===null?o?e.unavailableReason??`unknown`:null:`write failed`;return a(`button`,{type:`button`,role:`switch`,"aria-label":e.label,"aria-checked":e.on===!0,disabled:!e.available,onClick:n,title:c,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:[d(i,{className:`h-3.5 w-3.5 shrink-0 ${t===null?o?`text-foreground-subtle/50`:s?`text-warning`:`text-success`:`text-danger`}`}),a(`span`,{className:`flex-1 min-w-0 truncate`,children:[e.label,l!==null&&a(`span`,{className:`ml-1 text-[10px] text-foreground-subtle`,children:[`· `,l]})]}),d(`span`,{className:`shrink-0 rounded px-1 py-0.5 text-[9px] font-semibold uppercase tracking-wide ${o?`bg-surface-hover text-foreground-subtle/60`:s?`bg-warning/20 text-warning`:`bg-success/20 text-success`}`,children:o?`—`:r(s?`common.off`:`common.on`)})]})}function ha({deviceId:e}){let t=an(U().trpcClient,e);return t===null?null:a(`a`,{href:t.url,target:`_blank`,rel:`noopener noreferrer`,title:`${t.label} — ${t.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:[d(M,{className:`h-3.5 w-3.5`}),d(`span`,{className:`hidden sm:inline`,children:t.label})]})}function ga({parentDeviceId:e}){let{t}=Z(),n=Yr(),r=U(),{data:i,isLoading:o,isError:s}=Gr(e),{data:c}=un({deviceId:e},{enabled:Number.isFinite(e)});if(o)return d(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:d(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(s)return d(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:d(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let l=(i??[]).filter(e=>e.display?.hidden!==!0);if(l.length===0)return null;let u=qt(c?.stableId??``,l,c?.childLayout),f=u.ungrouped,p=e=>n(`/devices/${String(e)}`),m=c?.name??``,h=(e,t)=>d(Kn,{trpc:r.trpcClient,device:{...t,name:Mr(t,m)},variant:`minimal`,onNavigate:p},e),g=f.some(e=>!!e.role),_=f.some(e=>!e.role),v=g&&!_?t(`device.accessories`,{defaultValue:`Accessories`}):!g&&_?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),y=f.length>0?a(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[d(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:v}),d(`div`,{className:`space-y-1`,children:f.map(e=>h(e.id,e))})]}):null,b=u.disabledSection===void 0?null:d(Ut,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:u.disabledSection.children.length,defaultOpen:!1,children:d(`div`,{className:`opacity-60 space-y-1`,children:u.disabledSection.children.map(e=>h(e.id,e))})},u.disabledSection.title);if(u.sections.length===0)return b===null?y:a(`div`,{className:`space-y-2`,children:[y,b]});let x=_&&!g;return a(`div`,{className:`space-y-2`,children:[x?y:null,u.sections.map(e=>d(Ut,{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 _a({deviceId:e}){let t=U(),{data:n,isLoading:r}=Ur(e),{data:i,isLoading:a}=Gr(e),o=r||a,s=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,features:e.features,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),c=typeof n?.linkDeviceId==`number`?n.linkDeviceId:null,l=typeof n?.primaryChildEntityId==`string`?n.primaryChildEntityId:null;return o?d(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):d(`div`,{className:`flex h-full w-full flex-col`,children:d(dn,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}e();function va({dev:e,busy:t,setBusy:n}){let{t:i}=Z(),o=e?.motionTrigger,s=x(e?.state.motionTrigger),[c,l]=r(!1);if(!o)return null;let u=s?.enabled===!0,f=s!==void 0,p=async()=>{if(t||!f)return;let e=!u;n(!0),l(!0);try{await o.setMotionTrigger({enabled:e})}finally{n(!1),l(!1)}},m=c?u?`Disabling…`:`Enabling…`:f?u?`On motion: on`:`On motion: off`:`On motion: …`;return a(`button`,{type:`button`,onClick:()=>{p()},disabled:t||!f,title:f?u?i(`hero.motionTriggerToggle.disableTriggerOnMotion`,`Disable trigger on motion`):i(`hero.motionTriggerToggle.enableTriggerOnMotion`,`Enable trigger on motion`):i(`hero.motionTriggerToggle.awaitingState`,`Awaiting state…`),"aria-pressed":u,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 ${u?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground`}`,children:[d(H,{className:`h-3 w-3`}),d(`span`,{children:m})]})}e();function Q({deviceId:e,deviceType:t,features:n}){let i=U(),o=St(t)?.HeroCard??Ft,s=C(i.trpcClient,e),c=x(s?.state.deviceStatus),[l,u]=r(!1),f=c!==void 0&&c.online===!1,p=f?c.lastChangedAt:null;return a(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[f?d(`div`,{className:`flex justify-center`,children:d(cn,{lastChangedAt:p})}):null,d(o,{trpc:i.trpcClient,deviceId:e,features:n}),d(`div`,{className:`flex justify-center`,children:d(va,{dev:s,busy:l,setBusy:u})})]})}function ya({deviceId:e,features:t}){return d(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:d(fr,{trpc:U().trpcClient,deviceId:e,features:t})})}function ba({deviceId:e,features:t}){return d(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:d(Ft,{trpc:U().trpcClient,deviceId:e,features:t})})}function xa(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}function Sa(e){if(!e)return null;let t=xa(e.data);return t===null?e.eventType:X.t(`helpers.eventEmitterFormat.buttonHeadline`,{channel:String(t),eventType:e.eventType})}var Ca=1e3,wa=60*Ca,Ta=60*wa,Ea=24*Ta;function Da(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<Ca?X.t(`helpers.relativeTime.justNow`):n<wa?X.t(`helpers.relativeTime.secondsAgo`,{count:Math.floor(n/Ca)}):n<Ta?X.t(`helpers.relativeTime.minutesAgo`,{count:Math.floor(n/wa)}):n<Ea?X.t(`helpers.relativeTime.hoursAgo`,{count:Math.floor(n/Ta)}):X.t(`helpers.relativeTime.daysAgo`,{count:Math.floor(n/Ea)})}e();var Oa=1500,ka=15e3,Aa=1e3;function ja({deviceId:e}){let{t:n}=Z(),i=C(U().trpcClient,e)?.state.eventEmitter,o=x(i);t(()=>{if(!i)return;i.refresh();let e=setInterval(()=>{i.refresh()},ka);return()=>{clearInterval(e)}},[i]);let s=o?.lastEvent??null,c=s?.seq??null,u=l(null),[f,p]=r(!1);t(()=>{if(c===null)return;let e=u.current;if(u.current=c,e===null||e===c)return;p(!0);let t=setTimeout(()=>{p(!1)},Oa);return()=>{clearTimeout(t)}},[c]);let[h,g]=r(()=>Date.now());t(()=>{let e=setInterval(()=>{g(Date.now())},Aa);return()=>{clearInterval(e)}},[]);let _=Sa(s),y=o?.eventTypes??[],b=o?.eventCountSinceStart??0,S=o!==void 0,w=xa(s?.data);return a(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 p-4`,children:[d(`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:_??n(`hero.eventEmitterHero.noPressRecorded`,`No press recorded`),children:d(f?v:m,{className:`h-10 w-10`})}),a(`div`,{className:`text-center`,children:[w!==null&&d(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-primary`,children:n(`hero.eventEmitterHero.button`,`Button {{value1}}`,{value1:String(w)})}),d(`div`,{"data-testid":`event-emitter-headline`,className:`text-sm font-semibold ${_?`text-foreground`:`text-foreground-subtle`}`,children:_??(S?n(`hero.eventEmitterHero.noPressRecorded`,`No press recorded`):n(`hero.eventEmitterHero.awaitingState`,`Awaiting state…`))}),d(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:s?Da(s.timestamp,h):n(`hero.eventEmitterHero.waitingForTheFirstEvent`,`Waiting for the first event`)})]}),y.length>0&&d(`div`,{className:`flex max-w-full flex-wrap justify-center gap-1`,children:y.map(e=>d(`span`,{"data-testid":`event-emitter-chip`,className:`rounded-full border px-2 py-0.5 text-[10px] font-medium ${e===s?.eventType?`border-primary bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle`}`,children:e},e))}),d(`div`,{className:`text-[10px] text-foreground-subtle`,children:n(`hero.eventEmitterHero.sinceStart`,{count:b})})]})}function Ma({deviceName:e,deviceType:t,provider:n,isOnline:r,features:i}){let{t:o}=Z();return a(`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:[d(qr,{type:n,size:`lg`}),a(`div`,{children:[d(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),d(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),a(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[d(ar,{status:r?`online`:`offline`}),i.length>0&&d(Kr,{capabilities:i})]}),d(`div`,{className:`text-[10px] text-foreground-subtle italic max-w-xs mt-1`,children:o(`hero.genericHero.noLiveViewForThis`,`No live view for this device type. Use the Config tab or the shortcut row to interact.`)})]})}e();function Na({deviceId:e}){let{t}=Z(),r=c(),i=Vn({deviceId:e},{refetchInterval:1e4,retry:!1}),o=In({onSuccess:()=>{r.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),r.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),s=n(()=>Pa(i.data??[]),[i.data]);return a(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[a(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[d(Fa,{label:t(`hero.hubHero.discovered`,`Discovered`),value:s.total,icon:d(_e,{className:`h-3.5 w-3.5`})}),d(Fa,{label:t(`hero.hubHero.adopted`,`Adopted`),value:s.adopted,accent:`success`}),d(Fa,{label:t(`hero.hubHero.available`,`Available`),value:s.available,accent:s.available>0?`primary`:void 0}),a(`button`,{type:`button`,onClick:()=>{o.mutateAsync({deviceId:e}).catch(()=>{})},disabled:o.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:[o.isPending?d(ce,{className:`h-3.5 w-3.5 animate-spin`}):d(R,{className:`h-3.5 w-3.5`}),d(`span`,{className:`hidden sm:inline`,children:t(`hero.hubHero.discover`,`Discover`)})]})]}),a(`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:[d(Ia,{icon:d(ie,{className:`h-3 w-3 text-emerald-500`}),label:t(`hero.hubHero.online`,`{{online}} online`,{online:s.online})}),d(Ia,{icon:d(w,{className:`h-3 w-3 text-amber-500`}),label:t(`hero.hubHero.sleeping`,`{{sleeping}} sleeping`,{sleeping:s.sleeping})}),d(Ia,{icon:d(L,{className:`h-3 w-3 text-destructive`}),label:t(`hero.hubHero.offline`,`{{offline}} offline`,{offline:s.offline})}),s.unknown>0?d(Ia,{icon:d(fe,{className:`h-3 w-3 text-foreground-subtle`}),label:t(`hero.hubHero.unknown`,`{{unknown}} unknown`,{unknown:s.unknown})}):null]})]})}function Pa(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 Fa({label:e,value:t,icon:n,accent:r}){return a(`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 ${r===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:r===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[a(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,d(`span`,{className:`truncate`,children:e})]}),d(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function Ia({icon:e,label:t}){return a(`span`,{className:`inline-flex items-center gap-1`,children:[e,d(`span`,{children:t})]})}var La={[q.Switch]:Q,[q.Siren]:Q,[q.Light]:Q,[q.Sensor]:Q,[q.Button]:Q,[q.Hub]:Na,[q.Cover]:ya,[q.Valve]:Q,[q.Humidifier]:Q,[q.WaterHeater]:Q,[q.Container]:_a,[q.Lock]:Q,[q.Fan]:Q,[q.Thermostat]:Q,[q.Climate]:Q,[q.MediaPlayer]:Q,[q.Control]:Q,[q.AlarmPanel]:Q,[q.EventEmitter]:ja,[q.Notifier]:ba,[q.Script]:Q,[q.Automation]:Q,[q.Presence]:Q,[q.Update]:Q,[q.Vacuum]:Q,[q.LawnMower]:Q,[q.Weather]:Q,[q.Image]:Q,[q.PetFeeder]:Q,[q.Dishwasher]:Q};function Ra(e){return La[e]??Ma}function za(e){return d(Ra(e.deviceType),{...e})}function Ba(e){return or(U().trpcClient,e)}e();function Va(e){let[n,a]=r(`idle`),[o,s]=r(null),c=l(null),u=l(null),d=l(null),f=l(!0),p=pn(),m=sn(),h=xt(),g=i(()=>{if(c.current){try{c.current.close()}catch{}c.current=null}if(u.current){for(let e of u.current.getTracks())try{e.stop()}catch{}u.current=null}d.current=null},[]),_=i(async()=>{if(n===`idle`)return;a(`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&&(a(`idle`),s(null))},[n,e,h,g]),v=i(async()=>{if(e===null||n!==`idle`&&n!==`error`)return;s(null);let t=null,r=null,i=null;try{a(`requesting-mic`),t=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),u.current=t,a(`starting`);let n=await p.mutateAsync({deviceId:e});i=n.sessionId,d.current=i,a(`connecting`),r=new RTCPeerConnection,c.current=r,r.oniceconnectionstatechange=()=>{if(!f.current)return;let e=r.iceConnectionState;e===`connected`||e===`completed`?a(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&f.current&&(s(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 l=r.localDescription?.sdp??o.sdp??``;await m.mutateAsync({deviceId:e,sessionId:i,sdpAnswer:l})}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(c.current=null,u.current=null,i!==null)try{await h.mutateAsync({deviceId:e,sessionId:i})}catch{}d.current=null,f.current&&(s(o),a(`error`))}},[e,n,p,m,h,_]);return t(()=>(f.current=!0,()=>{f.current=!1;let t=d.current;if(t!==null&&e!==null&&h.mutate({deviceId:e,sessionId:t}),c.current){try{c.current.close()}catch{}c.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:o,start:v,stop:_,isTalking:n===`talking`}}e();var Ha=0;function $(){return++Ha}function Ua(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function Wa(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 Ga(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 Ka(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 qa({scope:e,greeting:n,className:o}){let{t:s}=Z(),c=U(),[f,p]=r(()=>{let t=[];return n&&t.push({id:$(),kind:`info`,text:n}),t.push({id:$(),kind:`info`,text:`scope: ${Ua(e)} — type help or context for available commands`}),t}),[m,h]=r(``),[g,_]=r([]),[v,y]=r(-1),b=l(null),x=l(null);t(()=>{let e=x.current;e&&(e.scrollTop=e.scrollHeight)},[f]);let S=i(()=>{b.current?.focus()},[]),C=u({mutationFn:t=>c.trpcClient.repl.execute.mutate({code:t,scope:e}),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(t){let n=t.trim();if(n){if(n===`clear`){p([{id:$(),kind:`info`,text:`scope: ${Ua(e)}`}]),h(``);return}if(n===`help`){p(t=>[...t,{id:$(),kind:`input`,text:`> ${n}`},...Wa(e).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}if(n===`context`){p(t=>[...t,{id:$(),kind:`input`,text:`> ${n}`},...Ka(e).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}if(n===`examples`){p(t=>[...t,{id:$(),kind:`input`,text:`> ${n}`},...Ga(e).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}_(e=>[...e,n]),y(-1),p(e=>[...e,{id:$(),kind:`input`,text:`> ${n}`}]),h(``),C.mutate(n)}}function T(t){if(t.key===`Enter`){t.preventDefault(),w(m);return}if(t.key===`ArrowUp`){if(t.preventDefault(),g.length===0)return;let e=v===-1?g.length-1:Math.max(0,v-1);y(e),h(g[e]??``);return}if(t.key===`ArrowDown`){if(t.preventDefault(),v===-1)return;let e=v+1;e>=g.length?(y(-1),h(``)):(y(e),h(g[e]??``));return}t.ctrlKey&&t.key===`l`&&(t.preventDefault(),p([{id:$(),kind:`info`,text:`scope: ${Ua(e)}`}]))}let E={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return a(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${o??``}`,onClick:S,children:[a(`div`,{ref:x,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[f.map(e=>d(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${E[e.kind]}`,children:e.text},e.id)),C.isPending&&d(`span`,{className:`text-zinc-500 animate-pulse`,children:s(`shared.replTerminal.thinking`,`…thinking`)})]}),a(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[d(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:s(`shared.replTerminal.text`,`>`)}),d(`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 Ja(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}}}e();function Ya({deviceId:e,intercomAvailable:t=!1}){let r=U(),i=typeof window<`u`?F():``,a=Number.isFinite(e),o=Ba(a?e:null),c=Ki(a?[e]:[]),l=n(()=>{if(!a)return;let e=[];for(let t of c.rows){let n=xn(t);n!==null&&e.push(n)}return e},[a,c.rows]),{streams:u,pipelineMetrics:f,createSession:p,sendAnswer:m,handleOffer:h,getIceServers:g,addIceCandidate:v,getIceCandidates:y,closeSession:b,getSessionState:x,applyDownlinkProbe:S}=Pn(r.trpcClient,a?e:null),C=_(a?e:null,{width:eo}),w=Va(a&&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=ue(),k=er(),A=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,j=Ja(k.request,A),M=O.length>0?d(s,{children:O.map(e=>d(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return d(yt,{serverUrl:i,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:o.phase,detections:o,...l===void 0?{}:{stationaryObjects:l},defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:C.src,...C.src?{posterUrl:C.src}:{},snapshotLoading:C.loading,onRefreshSnapshot:C.refresh,intercomAvailable:t,intercomShown:E,onIntercomToggle:D,extraOverlay:M,chromeless:!0,className:`h-full`})}function Xa({deviceId:e,containerDeviceId:t}){let{t:n}=Z();return Number.isFinite(e)?d(`div`,{className:`flex flex-col h-full`,children:d(bn,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):d(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:n(`device.panelContent.notLoaded`,{id:e})})}function Za({deviceId:e}){let{t}=Z();if(!Number.isFinite(e))return d(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:t(`device.panelContent.notLoaded`,{id:e})});let n=[`CamStack REPL — device #${e}`,``,` device.state.battery.value sync state read`,` await device.snapshot.getSnapshot({}) cap action`,``,` type 'examples' for more, 'context' for the full API`].join(`
1
+ import{$ as e,B as t,G as n,J as r,L as i,S as a,a as o,b as s,o as c,q 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-CEHpkaJP.js";import{Br as f,Ci as p,Cr as m,D as h,En as g,G as _,Gn as v,Hi as y,It as b,J as x,Jn as S,K as C,Kn as w,O as T,Oi as E,Ri as D,Rn as O,St as k,T as A,V as j,Vr as M,W as ee,Xn as N,Yr as P,Z as F,Zr as te,Zt as I,_t as L,bn as R,ca as ne,cr as z,dn as re,dt as B,en as V,ht as ie,lr as ae,m as oe,mi as se,na as H,or as ce,ot as U,pn as le,r as ue,t as de,ui as fe,vn as pe,xn as W,yn as me,z as he,zi as ge,zn as _e}from"./player-overlays-DyNPyo_W.js";import{Bn as ve,Dr as ye,Fr as G,Gr as be,In as xe,Jr as Se,Kr as Ce,Mr as K,Pr as we,Ti as Te,Tr as Ee,Vn as De,Xr as q,Yr as J,_ as Oe,_n as ke,an as Ae,cn as je,d as Me,gr as Ne,h as Pe,hn as Fe,ln as Ie,m as Le,mn as Re,on as ze,p as Be,rr as Ve,sn as He,v as Ue,wi as We,x as Ge,xr as Ke,zn as qe}from"./client-CRCWO8cg.js";import{t as Je}from"./archive-C3J7kPmp.js";import{i as Ye,n as Xe,r as Ze,t as Qe}from"./scan-eye-DSsbXKWH.js";import{t as $e}from"./bell-off-Df5MKmnk.js";import{t as et}from"./boxes-B4UVG1kT.js";import{n as tt}from"./video-BtFmM3eg.js";import{t as nt}from"./circle-slash-BTU53Q69.js";import{t as rt}from"./layers-CBNWlTsd.js";import{$ as it,$n as at,Ac as ot,An as st,Bu as ct,Cu as lt,Dn as ut,Ds as dt,Dt as ft,Er as pt,F as mt,Fn as ht,Fs as gt,Ft as _t,Fu as vt,G as yt,Ga as bt,Go as xt,Gt as St,Ha as Ct,Hc as wt,Hn as Tt,Ht as Et,Hu as Dt,In as Ot,Ir as kt,It as At,J as jt,Ju as Mt,K as Nt,Ka as Pt,Kt as Ft,La as It,Ln as Lt,Lr as Rt,Ls as zt,Ma as Bt,Mc as Vt,Mn as Ht,Mt as Ut,Mu as Wt,N as Gt,Nc as Kt,Nt as qt,Nu as Jt,Oa as Yt,On as Xt,Ou as Zt,Pc as Qt,Pn as $t,Pr as en,Qn as tn,Ra as nn,Rn as rn,Rt as an,Tn as on,Uo as sn,Ut as cn,Uu as ln,Va as un,Vt as dn,Wa as fn,Wo as pn,Wr as mn,Xt as hn,Y as gn,Yt as _n,Za as vn,Zn as yn,Zt as bn,a as xn,ac as Sn,an as Cn,ar as wn,ba as Tn,bt as En,c as Dn,ci as On,cr as kn,eo as An,er as jn,et as Mn,fa as Nn,fn as Pn,fr as Fn,ga as In,gn as Ln,go as Rn,gr as zn,gt as Bn,ha as Vn,hr as Y,i as Hn,ir as Un,jc as Wn,jn as Gn,jt as Kn,ju as qn,kc as Jn,kn as Yn,kt as Xn,ku as Zn,l as Qn,lc as $n,lr as er,mc as tr,mn as nr,na as rr,nr as ir,nt as ar,o as or,oa as sr,oc as cr,oo as lr,or as ur,po as dr,qt as fr,r as pr,rl as mr,rr as hr,s as gr,sa as _r,sc as vr,ta as yr,tt as br,uc as xr,va as Sr,wi as Cr,wn as wr,xr as Tr,ya as Er,yc as Dr,yn as Or,yo as kr,yt as Ar,zo as jr,zt as Mr}from"./src-_mtQMfPm.js";import{t as X}from"./i18n-DzruZdmx.js";import{t as Z}from"./useTranslation-D3Is_4B6.js";import"./mount-B0uThmDr.js";import{A as Nr,F as Pr,H as Fr,I as Ir,J as Lr,K as Rr,M as zr,N as Br,P as Vr,Q as Hr,U as Ur,V as Wr,W as Gr,X as Kr,Y as qr,Z as Jr,et as Yr,g as Xr,h as Zr,j as Qr,nt as $r,p as ei,q as ti,tt as ni}from"./index-2_qB4G1l.js";import{C as ri,D as ii,E as ai,S as oi,_ as si,a as ci,b as li,c as ui,d as di,f as fi,g as pi,h as mi,i as hi,l as gi,m as _i,n as vi,o as yi,p as bi,r as xi,s as Si,t as Ci,u as wi,v as Ti,x as Ei,y as Di}from"./CompositionEditor-ZIvK82Sw.js";import{_ as Oi,a as ki,c as Ai,d as ji,f as Mi,g as Ni,h as Pi,i as Fi,l as Ii,m as Li,n as Ri,o as zi,p as Bi,s as Vi,t as Hi,u as Ui,v as Wi,y as Gi}from"./ClusterStepModel-G54nm4iG.js";import"./useEventInvalidation-B0uThmDr.js";import{t as Ki}from"./use-stationary-objects-D_FqXLHG.js";import{a as qi,c as Ji,d as Yi,f as Xi,i as Zi,l as Qi,n as $i,o as ea,p as ta,r as na,s as ra,t as ia,u as aa}from"./linked-devices-model-Csh4WaVK.js";import{t as oa}from"./authed-media-dGvmAGIm.js";e();function sa(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 ca(e){if(typeof e!=`object`||!e)return null;let t=e.switches;if(!Array.isArray(t))return null;let n=t.map(sa).filter(e=>e!==null);return n.length===0?null:n}var la=[[/privacy|mask/i,`privacy`],[/microphone|mic\b/i,`microphone`],[/speaker|broker audio|stream audio/i,`speaker`],[/audio/i,`listening`],[/object|detect/i,`detection`],[/event/i,`archive`],[/record/i,`recording`],[/notif/i,`notifications`],[/stream|broker/i,`stream`]];function ua(e){for(let[t,n]of la)if(t.test(e))return n;return`generic`}function da(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(X.t(`helpers.cameraSwitchRows.off`,{list:r(t)})),n.length>0&&i.push(X.t(`helpers.cameraSwitchRows.unknown`,{list:r(n)})),{offIds:t,unknownIds:n,summary:i.length===0?X.t(`helpers.cameraSwitchRows.allOn`):i.join(` · `)}}var fa={stream:W,detection:Qe,privacy:f,microphone:N,speaker:k,listening:Xe,archive:Je,recording:Ze,notifications:D,generic:V};function pa({deviceId:e}){let{t}=Z(),n=c(),o=Number.isFinite(e),[s,l]=r(null),[u,f]=r(!1),p=xr({deviceId:e},{enabled:o});pr([`pipelineOrchestrator`,`getCameraSwitches`],[`capability.binding-changed`]);let m=ca(p.data),h=Qt({onError:(t,r)=>{console.error(`[CameraFunctionSwitches] switch write failed — reverting`,{tags:{deviceId:e},meta:{switchId:r.switchId,error:t instanceof Error?t.message:String(t)}}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSwitches`]]}),l({id:r.switchId,message:t instanceof Error?t.message:String(t)})},onSuccess:()=>{l(null),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]}),n.invalidateQueries({queryKey:[[`deviceManager`]]}),n.invalidateQueries({queryKey:[[`recording`]]})}}),g=i(t=>{!t.available||t.on===null||h.mutate({deviceId:e,switchId:t.id,enabled:!t.on})},[e,h]);if(m===null)return null;let _=da(m),v=e=>s?.id===e.id?s.message:null;return a(qn,{open:u,onOpenChange:f,children:[a(Jt,{"aria-label":t(`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 ${s===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:[d(V,{className:`h-3.5 w-3.5`}),d(`span`,{className:`hidden lg:inline`,children:t(`device.cameraFunctionSwitches.functions`,`Functions`)}),_.offIds.length>0&&d(`span`,{className:`rounded bg-warning/20 px-1 text-[9px] font-semibold uppercase tracking-wide`,children:t(`device.cameraFunctionSwitches.offCount`,{count:_.offIds.length})})]}),a(Wt,{align:`end`,className:`min-w-[240px] max-h-[60vh] overflow-y-auto p-1`,children:[d(`div`,{className:`px-2 py-1 text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t(`device.cameraFunctionSwitches.cameraFunctions`,`Camera functions`)}),d(`ul`,{className:`space-y-0.5`,children:m.map(e=>d(`li`,{children:d(ma,{row:e,failure:v(e),onToggle:()=>g(e)})},e.id))})]})]})}function ma({row:e,failure:t,onToggle:n}){let{t:r}=Z(),i=fa[ua(e.label)],o=e.on===null,s=e.on===!1,c=t===null?o?e.unavailableReason??`The source that owns this did not answer.`:e.costWhenOff:`Write failed: ${t}`,l=t===null?o?e.unavailableReason??`unknown`:null:`write failed`;return a(`button`,{type:`button`,role:`switch`,"aria-label":e.label,"aria-checked":e.on===!0,disabled:!e.available,onClick:n,title:c,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:[d(i,{className:`h-3.5 w-3.5 shrink-0 ${t===null?o?`text-foreground-subtle/50`:s?`text-warning`:`text-success`:`text-danger`}`}),a(`span`,{className:`flex-1 min-w-0 truncate`,children:[e.label,l!==null&&a(`span`,{className:`ml-1 text-[10px] text-foreground-subtle`,children:[`· `,l]})]}),d(`span`,{className:`shrink-0 rounded px-1 py-0.5 text-[9px] font-semibold uppercase tracking-wide ${o?`bg-surface-hover text-foreground-subtle/60`:s?`bg-warning/20 text-warning`:`bg-success/20 text-success`}`,children:o?`—`:r(s?`common.off`:`common.on`)})]})}function ha({deviceId:e}){let t=an(U().trpcClient,e);return t===null?null:a(`a`,{href:t.url,target:`_blank`,rel:`noopener noreferrer`,title:`${t.label} — ${t.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:[d(M,{className:`h-3.5 w-3.5`}),d(`span`,{className:`hidden sm:inline`,children:t.label})]})}function ga({parentDeviceId:e}){let{t}=Z(),n=Yr(),r=U(),{data:i,isLoading:o,isError:s}=Gr(e),{data:c}=un({deviceId:e},{enabled:Number.isFinite(e)});if(o)return d(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:d(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(s)return d(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:d(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let l=(i??[]).filter(e=>e.display?.hidden!==!0);if(l.length===0)return null;let u=qt(c?.stableId??``,l,c?.childLayout),f=u.ungrouped,p=e=>n(`/devices/${String(e)}`),m=c?.name??``,h=(e,t)=>d(Kn,{trpc:r.trpcClient,device:{...t,name:Mr(t,m)},variant:`minimal`,onNavigate:p},e),g=f.some(e=>!!e.role),_=f.some(e=>!e.role),v=g&&!_?t(`device.accessories`,{defaultValue:`Accessories`}):!g&&_?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),y=f.length>0?a(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[d(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:v}),d(`div`,{className:`space-y-1`,children:f.map(e=>h(e.id,e))})]}):null,b=u.disabledSection===void 0?null:d(Ut,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:u.disabledSection.children.length,defaultOpen:!1,children:d(`div`,{className:`opacity-60 space-y-1`,children:u.disabledSection.children.map(e=>h(e.id,e))})},u.disabledSection.title);if(u.sections.length===0)return b===null?y:a(`div`,{className:`space-y-2`,children:[y,b]});let x=_&&!g;return a(`div`,{className:`space-y-2`,children:[x?y:null,u.sections.map(e=>d(Ut,{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 _a({deviceId:e}){let t=U(),{data:n,isLoading:r}=Ur(e),{data:i,isLoading:a}=Gr(e),o=r||a,s=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,features:e.features,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),c=typeof n?.linkDeviceId==`number`?n.linkDeviceId:null,l=typeof n?.primaryChildEntityId==`string`?n.primaryChildEntityId:null;return o?d(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):d(`div`,{className:`flex h-full w-full flex-col`,children:d(dn,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}e();function va({dev:e,busy:t,setBusy:n}){let{t:i}=Z(),o=e?.motionTrigger,s=x(e?.state.motionTrigger),[c,l]=r(!1);if(!o)return null;let u=s?.enabled===!0,f=s!==void 0,p=async()=>{if(t||!f)return;let e=!u;n(!0),l(!0);try{await o.setMotionTrigger({enabled:e})}finally{n(!1),l(!1)}},m=c?u?`Disabling…`:`Enabling…`:f?u?`On motion: on`:`On motion: off`:`On motion: …`;return a(`button`,{type:`button`,onClick:()=>{p()},disabled:t||!f,title:f?u?i(`hero.motionTriggerToggle.disableTriggerOnMotion`,`Disable trigger on motion`):i(`hero.motionTriggerToggle.enableTriggerOnMotion`,`Enable trigger on motion`):i(`hero.motionTriggerToggle.awaitingState`,`Awaiting state…`),"aria-pressed":u,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 ${u?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground`}`,children:[d(H,{className:`h-3 w-3`}),d(`span`,{children:m})]})}e();function Q({deviceId:e,deviceType:t,features:n}){let i=U(),o=St(t)?.HeroCard??Ft,s=C(i.trpcClient,e),c=x(s?.state.deviceStatus),[l,u]=r(!1),f=c!==void 0&&c.online===!1,p=f?c.lastChangedAt:null;return a(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[f?d(`div`,{className:`flex justify-center`,children:d(cn,{lastChangedAt:p})}):null,d(o,{trpc:i.trpcClient,deviceId:e,features:n}),d(`div`,{className:`flex justify-center`,children:d(va,{dev:s,busy:l,setBusy:u})})]})}function ya({deviceId:e,features:t}){return d(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:d(fr,{trpc:U().trpcClient,deviceId:e,features:t})})}function ba({deviceId:e,features:t}){return d(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:d(Ft,{trpc:U().trpcClient,deviceId:e,features:t})})}function xa(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}function Sa(e){if(!e)return null;let t=xa(e.data);return t===null?e.eventType:X.t(`helpers.eventEmitterFormat.buttonHeadline`,{channel:String(t),eventType:e.eventType})}var Ca=1e3,wa=60*Ca,Ta=60*wa,Ea=24*Ta;function Da(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<Ca?X.t(`helpers.relativeTime.justNow`):n<wa?X.t(`helpers.relativeTime.secondsAgo`,{count:Math.floor(n/Ca)}):n<Ta?X.t(`helpers.relativeTime.minutesAgo`,{count:Math.floor(n/wa)}):n<Ea?X.t(`helpers.relativeTime.hoursAgo`,{count:Math.floor(n/Ta)}):X.t(`helpers.relativeTime.daysAgo`,{count:Math.floor(n/Ea)})}e();var Oa=1500,ka=15e3,Aa=1e3;function ja({deviceId:e}){let{t:n}=Z(),i=C(U().trpcClient,e)?.state.eventEmitter,o=x(i);t(()=>{if(!i)return;i.refresh();let e=setInterval(()=>{i.refresh()},ka);return()=>{clearInterval(e)}},[i]);let s=o?.lastEvent??null,c=s?.seq??null,u=l(null),[f,p]=r(!1);t(()=>{if(c===null)return;let e=u.current;if(u.current=c,e===null||e===c)return;p(!0);let t=setTimeout(()=>{p(!1)},Oa);return()=>{clearTimeout(t)}},[c]);let[h,g]=r(()=>Date.now());t(()=>{let e=setInterval(()=>{g(Date.now())},Aa);return()=>{clearInterval(e)}},[]);let _=Sa(s),y=o?.eventTypes??[],b=o?.eventCountSinceStart??0,S=o!==void 0,w=xa(s?.data);return a(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 p-4`,children:[d(`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:_??n(`hero.eventEmitterHero.noPressRecorded`,`No press recorded`),children:d(f?v:m,{className:`h-10 w-10`})}),a(`div`,{className:`text-center`,children:[w!==null&&d(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-primary`,children:n(`hero.eventEmitterHero.button`,`Button {{value1}}`,{value1:String(w)})}),d(`div`,{"data-testid":`event-emitter-headline`,className:`text-sm font-semibold ${_?`text-foreground`:`text-foreground-subtle`}`,children:_??(S?n(`hero.eventEmitterHero.noPressRecorded`,`No press recorded`):n(`hero.eventEmitterHero.awaitingState`,`Awaiting state…`))}),d(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:s?Da(s.timestamp,h):n(`hero.eventEmitterHero.waitingForTheFirstEvent`,`Waiting for the first event`)})]}),y.length>0&&d(`div`,{className:`flex max-w-full flex-wrap justify-center gap-1`,children:y.map(e=>d(`span`,{"data-testid":`event-emitter-chip`,className:`rounded-full border px-2 py-0.5 text-[10px] font-medium ${e===s?.eventType?`border-primary bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle`}`,children:e},e))}),d(`div`,{className:`text-[10px] text-foreground-subtle`,children:n(`hero.eventEmitterHero.sinceStart`,{count:b})})]})}function Ma({deviceName:e,deviceType:t,provider:n,isOnline:r,features:i}){let{t:o}=Z();return a(`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:[d(qr,{type:n,size:`lg`}),a(`div`,{children:[d(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),d(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),a(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[d(ar,{status:r?`online`:`offline`}),i.length>0&&d(Kr,{capabilities:i})]}),d(`div`,{className:`text-[10px] text-foreground-subtle italic max-w-xs mt-1`,children:o(`hero.genericHero.noLiveViewForThis`,`No live view for this device type. Use the Config tab or the shortcut row to interact.`)})]})}e();function Na({deviceId:e}){let{t}=Z(),r=c(),i=Vn({deviceId:e},{refetchInterval:1e4,retry:!1}),o=In({onSuccess:()=>{r.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),r.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),s=n(()=>Pa(i.data??[]),[i.data]);return a(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[a(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[d(Fa,{label:t(`hero.hubHero.discovered`,`Discovered`),value:s.total,icon:d(_e,{className:`h-3.5 w-3.5`})}),d(Fa,{label:t(`hero.hubHero.adopted`,`Adopted`),value:s.adopted,accent:`success`}),d(Fa,{label:t(`hero.hubHero.available`,`Available`),value:s.available,accent:s.available>0?`primary`:void 0}),a(`button`,{type:`button`,onClick:()=>{o.mutateAsync({deviceId:e}).catch(()=>{})},disabled:o.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:[o.isPending?d(ce,{className:`h-3.5 w-3.5 animate-spin`}):d(R,{className:`h-3.5 w-3.5`}),d(`span`,{className:`hidden sm:inline`,children:t(`hero.hubHero.discover`,`Discover`)})]})]}),a(`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:[d(Ia,{icon:d(ie,{className:`h-3 w-3 text-emerald-500`}),label:t(`hero.hubHero.online`,`{{online}} online`,{online:s.online})}),d(Ia,{icon:d(w,{className:`h-3 w-3 text-amber-500`}),label:t(`hero.hubHero.sleeping`,`{{sleeping}} sleeping`,{sleeping:s.sleeping})}),d(Ia,{icon:d(L,{className:`h-3 w-3 text-destructive`}),label:t(`hero.hubHero.offline`,`{{offline}} offline`,{offline:s.offline})}),s.unknown>0?d(Ia,{icon:d(fe,{className:`h-3 w-3 text-foreground-subtle`}),label:t(`hero.hubHero.unknown`,`{{unknown}} unknown`,{unknown:s.unknown})}):null]})]})}function Pa(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 Fa({label:e,value:t,icon:n,accent:r}){return a(`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 ${r===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:r===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[a(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,d(`span`,{className:`truncate`,children:e})]}),d(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function Ia({icon:e,label:t}){return a(`span`,{className:`inline-flex items-center gap-1`,children:[e,d(`span`,{children:t})]})}var La={[q.Switch]:Q,[q.Siren]:Q,[q.Light]:Q,[q.Sensor]:Q,[q.Button]:Q,[q.Hub]:Na,[q.Cover]:ya,[q.Valve]:Q,[q.Humidifier]:Q,[q.WaterHeater]:Q,[q.Container]:_a,[q.Lock]:Q,[q.Fan]:Q,[q.Thermostat]:Q,[q.Climate]:Q,[q.MediaPlayer]:Q,[q.Control]:Q,[q.AlarmPanel]:Q,[q.EventEmitter]:ja,[q.Notifier]:ba,[q.Script]:Q,[q.Automation]:Q,[q.Presence]:Q,[q.Update]:Q,[q.Vacuum]:Q,[q.LawnMower]:Q,[q.Weather]:Q,[q.Image]:Q,[q.PetFeeder]:Q,[q.Dishwasher]:Q};function Ra(e){return La[e]??Ma}function za(e){return d(Ra(e.deviceType),{...e})}function Ba(e){return or(U().trpcClient,e)}e();function Va(e){let[n,a]=r(`idle`),[o,s]=r(null),c=l(null),u=l(null),d=l(null),f=l(!0),p=pn(),m=sn(),h=xt(),g=i(()=>{if(c.current){try{c.current.close()}catch{}c.current=null}if(u.current){for(let e of u.current.getTracks())try{e.stop()}catch{}u.current=null}d.current=null},[]),_=i(async()=>{if(n===`idle`)return;a(`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&&(a(`idle`),s(null))},[n,e,h,g]),v=i(async()=>{if(e===null||n!==`idle`&&n!==`error`)return;s(null);let t=null,r=null,i=null;try{a(`requesting-mic`),t=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),u.current=t,a(`starting`);let n=await p.mutateAsync({deviceId:e});i=n.sessionId,d.current=i,a(`connecting`),r=new RTCPeerConnection,c.current=r,r.oniceconnectionstatechange=()=>{if(!f.current)return;let e=r.iceConnectionState;e===`connected`||e===`completed`?a(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&f.current&&(s(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 l=r.localDescription?.sdp??o.sdp??``;await m.mutateAsync({deviceId:e,sessionId:i,sdpAnswer:l})}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(c.current=null,u.current=null,i!==null)try{await h.mutateAsync({deviceId:e,sessionId:i})}catch{}d.current=null,f.current&&(s(o),a(`error`))}},[e,n,p,m,h,_]);return t(()=>(f.current=!0,()=>{f.current=!1;let t=d.current;if(t!==null&&e!==null&&h.mutate({deviceId:e,sessionId:t}),c.current){try{c.current.close()}catch{}c.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:o,start:v,stop:_,isTalking:n===`talking`}}e();var Ha=0;function $(){return++Ha}function Ua(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function Wa(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 Ga(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 Ka(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 qa({scope:e,greeting:n,className:o}){let{t:s}=Z(),c=U(),[f,p]=r(()=>{let t=[];return n&&t.push({id:$(),kind:`info`,text:n}),t.push({id:$(),kind:`info`,text:`scope: ${Ua(e)} — type help or context for available commands`}),t}),[m,h]=r(``),[g,_]=r([]),[v,y]=r(-1),b=l(null),x=l(null);t(()=>{let e=x.current;e&&(e.scrollTop=e.scrollHeight)},[f]);let S=i(()=>{b.current?.focus()},[]),C=u({mutationFn:t=>c.trpcClient.repl.execute.mutate({code:t,scope:e}),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(t){let n=t.trim();if(n){if(n===`clear`){p([{id:$(),kind:`info`,text:`scope: ${Ua(e)}`}]),h(``);return}if(n===`help`){p(t=>[...t,{id:$(),kind:`input`,text:`> ${n}`},...Wa(e).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}if(n===`context`){p(t=>[...t,{id:$(),kind:`input`,text:`> ${n}`},...Ka(e).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}if(n===`examples`){p(t=>[...t,{id:$(),kind:`input`,text:`> ${n}`},...Ga(e).map(e=>({id:$(),kind:`info`,text:e}))]),h(``);return}_(e=>[...e,n]),y(-1),p(e=>[...e,{id:$(),kind:`input`,text:`> ${n}`}]),h(``),C.mutate(n)}}function T(t){if(t.key===`Enter`){t.preventDefault(),w(m);return}if(t.key===`ArrowUp`){if(t.preventDefault(),g.length===0)return;let e=v===-1?g.length-1:Math.max(0,v-1);y(e),h(g[e]??``);return}if(t.key===`ArrowDown`){if(t.preventDefault(),v===-1)return;let e=v+1;e>=g.length?(y(-1),h(``)):(y(e),h(g[e]??``));return}t.ctrlKey&&t.key===`l`&&(t.preventDefault(),p([{id:$(),kind:`info`,text:`scope: ${Ua(e)}`}]))}let E={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return a(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${o??``}`,onClick:S,children:[a(`div`,{ref:x,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[f.map(e=>d(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${E[e.kind]}`,children:e.text},e.id)),C.isPending&&d(`span`,{className:`text-zinc-500 animate-pulse`,children:s(`shared.replTerminal.thinking`,`…thinking`)})]}),a(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[d(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:s(`shared.replTerminal.text`,`>`)}),d(`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 Ja(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}}}e();function Ya({deviceId:e,intercomAvailable:t=!1}){let r=U(),i=typeof window<`u`?F():``,a=Number.isFinite(e),o=Ba(a?e:null),c=Ki(a?[e]:[]),l=n(()=>{if(!a)return;let e=[];for(let t of c.rows){let n=xn(t);n!==null&&e.push(n)}return e},[a,c.rows]),{streams:u,pipelineMetrics:f,createSession:p,sendAnswer:m,handleOffer:h,getIceServers:g,addIceCandidate:v,getIceCandidates:y,closeSession:b,getSessionState:x,applyDownlinkProbe:S}=Pn(r.trpcClient,a?e:null),C=_(a?e:null,{width:eo}),w=Va(a&&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=ue(),k=er(),A=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,j=Ja(k.request,A),M=O.length>0?d(s,{children:O.map(e=>d(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return d(yt,{serverUrl:i,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:o.phase,detections:o,...l===void 0?{}:{stationaryObjects:l},defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:C.src,...C.src?{posterUrl:C.src}:{},snapshotLoading:C.loading,onRefreshSnapshot:C.refresh,intercomAvailable:t,intercomShown:E,onIntercomToggle:D,extraOverlay:M,chromeless:!0,className:`h-full`})}function Xa({deviceId:e,containerDeviceId:t}){let{t:n}=Z();return Number.isFinite(e)?d(`div`,{className:`flex flex-col h-full`,children:d(bn,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):d(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:n(`device.panelContent.notLoaded`,{id:e})})}function Za({deviceId:e}){let{t}=Z();if(!Number.isFinite(e))return d(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:t(`device.panelContent.notLoaded`,{id:e})});let n=[`CamStack REPL — device #${e}`,``,` device.state.battery.value sync state read`,` await device.snapshot.getSnapshot({}) cap action`,``,` type 'examples' for more, 'context' for the full API`].join(`
2
2
  `);return d(qa,{scope:{type:`device`,deviceId:e},greeting:n,className:`h-full border-0 rounded-none`})}function Qa({deviceId:e}){let{t}=Z();return Number.isFinite(e)?d(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:d(hn,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):d(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:t(`device.panelContent.notLoaded`,{id:e})})}function $a({deviceId:e}){let{t}=Z();return Number.isFinite(e)?d(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:d(_n,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):d(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:t(`device.panelContent.notLoaded`,{id:e})})}var eo=960;function to(e){return new Set(e.filter(e=>{let t=e.nativeAddonId?.trim()??``;return t!==``&&t!==`composer`}).map(e=>e.capName))}function no(e){return e.kind===`known`?null:e}function ro(e,t){return e.composable.kind===`known`?e.composable.value.has(t)?{kind:`present`,mode:`add`}:{kind:`absent`}:e.composable}function io(e){if(e.deviceType!==q.Camera)return{kind:`absent`};switch(e.cameraSensors){case`pending`:return{kind:`pending`};case`unknown`:return{kind:`unknown`,reason:X.t(`helpers.assignmentAvailability.sensorsUnchecked`)};case`absent`:return{kind:`absent`};case`present`:return{kind:`present`,mode:`add`}}}function ao(e,t){if(e===`motion`)return io(t);let n=no(t.nativeCaps);if(n!==null)return n;let r=t.nativeCaps.kind===`known`?t.nativeCaps.value:new Set;switch(e){case`doorbell`:return r.has(`doorbell`)?{kind:`absent`}:ro(t,`doorbell`);case`battery`:return r.has(`battery`)?{kind:`present`,mode:`replace`}:ro(t,`battery`);case`consumables`:return r.has(`consumables`)?{kind:`absent`}:ro(t,`consumables`)}}function oo({onAdvanced:e}){let{t}=Z();return e===void 0?null:d(`button`,{type:`button`,className:`rounded text-left text-[11px] text-primary hover:underline focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary`,onClick:e,children:t(`customize.advancedLink`)})}function so(e){if(e.status===`pending`)return{kind:`pending`};if(e.status===`error`)return{kind:`unknown`,reason:e.error?.message??X.t(`helpers.customize.requestFailed`)};let t=e.data;if(t===void 0)return{kind:`pending`};if(t.state===`not-loaded`)return{kind:`not-loaded`,reason:t.reason};if(t.view===null)return{kind:`none`};let n=Ke(t.view.block);return n===null?{kind:`unknown`,reason:X.t(`helpers.customizationRead.notAComposition`,{id:t.view.block.id})}:{kind:`present`,view:t.view,composition:n}}function co(e){return e.kind===`present`?e.composition:null}function lo(e,t){let{hidden:n,...r}=e??{},i=t?{...r,hidden:!0}:r;return Object.keys(i).length===0?null:i}function uo(e){return typeof e.linkDeviceId==`number`}var fo=new Set(Object.values(J));function po(e){return fo.has(e)}var mo={[q.Switch]:[J.Siren,J.Floodlight,J.Spotlight,J.PirSensor,J.Chime,J.Autotrack,J.Nightvision,J.PrivacyMask,J.BinaryHelper],[q.Light]:[J.Floodlight,J.Spotlight,J.Nightvision],[q.Siren]:[J.Siren],[q.Button]:[J.Doorbell],[q.Sensor]:[J.MotionSensor,J.ContactSensor,J.LeakSensor,J.SmokeSensor,J.COSensor,J.GasSensor,J.TamperSensor,J.VibrationSensor,J.ConnectivitySensor,J.SoundSensor,J.BinarySensor,J.TemperatureSensor,J.HumiditySensor,J.AmbientLightSensor,J.PressureSensor,J.WindSensor,J.RainSensor,J.UvSensor,J.SolarRadiationSensor,J.SoilMoistureSensor,J.PowerSensor,J.EnergySensor,J.VoltageSensor,J.CurrentSensor,J.AirQualitySensor,J.BatterySensor,J.NumericSensor,J.EnumSensor,J.DateTimeSensor,J.GenericSensor],[q.Control]:[J.NumericControl,J.SelectControl,J.TextControl,J.DateTimeControl],[q.Notifier]:[J.MobilePushNotifier,J.MessagingNotifier,J.EmailNotifier,J.GenericNotifier]};function ho(e){for(let t of Object.values(q))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]}e();function vo({device:e}){let{t}=Z(),n=ne(),i=c(),[o,s]=r(null),l=()=>s(null),u={onSuccess:()=>{l(),i.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>s(e.message)},f=dr(),p=lr(),m=e.display?.hidden===!0;return a(`section`,{"aria-label":t(`customize.identity.title`),className:`${T} ${h}`,children:[a(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[d(ti,{deviceId:e.id,initialName:e.name,label:t(`customize.identity.name`),layout:`stacked`,onError:s,onSaved:l,onCancel:l}),d(Rr,{deviceId:e.id,initialLocation:e.location,label:t(`customize.identity.room`),layout:`stacked`,onError:s,onSaved:l,onCancel:l}),d(Lr,{label:t(`customize.identity.hidden`),layout:`stacked`,value:d(Ht,{"aria-label":t(`deviceDisplay.hideFromLists`),checked:m,disabled:p.isPending,onChange:t=>p.mutate({deviceId:e.id,display:lo(e.display,t.target.checked)},u)})}),d(Lr,{label:t(`customize.identity.role`),layout:`stacked`,value:uo(e)?d(`span`,{children:yo(e.role,t(`customize.identity.noRole`),n)}):d(lt,{"aria-label":t(`customize.identity.role`),value:e.role??``,disabled:f.isPending,options:[{value:``,label:t(`customize.identity.noRole`)},..._o(e.role,e.type).map(e=>({value:e,label:yo(e,t(`customize.identity.noRole`),n)}))],onChange:t=>f.mutate({deviceId:e.id,role:t.target.value===``?null:t.target.value},u)})})]}),o!==null&&d(`p`,{role:`alert`,className:`mt-2 text-xs text-danger break-words`,children:o})]})}function yo(e,t,n){return e==null||e===``?t:po(e)?ct(e,n).label:e}e();function bo(e){return e===`pending`?`pending`:e===`error`?`failed`:`answered`}function xo({excludeDeviceIds:e,onSelect:t}){let{t:r}=Z(),i=bt({projection:`slim`}),a=i.status===`success`?i.data:null,o=n(()=>{if(a===null)return[];let t=new Set(e);return ui(a).filter(e=>!t.has(e.id))},[a,e]),s=n(()=>new Map(o.map(e=>[e.id,e])),[o]),c=n(()=>o.map(e=>({id:e.id,name:e.name,type:e.type,...e.location===null?{}:{location:e.location}})),[o]);if(i.status===`error`)return d(Fn,{title:r(`customize.picker.devicesFailed`),message:i.error?.message??``});let l=e=>{let n=s.get(e);n!==void 0&&t(n)};return d(mt,{devices:c,listState:bo(i.status),value:[],onChange:e=>{let t=e.at(-1);t!==void 0&&l(t)},noun:`device`,emptyLabel:r(`customize.assign.none`),showAll:!0,testId:`customize-field-device-picker`})}function So({open:e,title:t,targetKind:n,excludeDeviceIds:i,confirmLabel:o,extra:c,extraComplete:l=!0,onConfirm:u,onClose:f}){let{t:p}=Z(),[m,h]=r(null),[g,_]=r(null),v=()=>{h(null),_(null),f()};return d(tn,{open:e,onOpenChange:e=>e?void 0:v(),children:a(jn,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":t,children:[d(hr,{children:d(Un,{children:t})}),d(at,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:e&&a(s,{children:[a(`section`,{"aria-label":p(`customize.assign.stepDevice`),className:`flex flex-col gap-1`,children:[d(`h3`,{className:`text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:p(`customize.assign.stepDevice`)}),m===null?d(xo,{excludeDeviceIds:i,onSelect:h}):a(`p`,{className:`flex items-center gap-2 text-xs text-foreground`,children:[m.name,d(Y,{variant:`ghost`,size:`sm`,onClick:()=>{h(null),_(null)},children:p(`customize.assign.change`)})]})]}),m!==null&&a(`section`,{"aria-label":p(`customize.assign.stepField`),className:`flex flex-col gap-1`,children:[d(`h3`,{className:`text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:p(`customize.assign.stepField`)}),d(ci,{device:m,targetKind:n,selected:g===null?null:{cap:g.cap,path:g.path},onPick:_,onBack:()=>{h(null),_(null)}})]}),m!==null&&c!==void 0&&a(`section`,{"aria-label":p(`customize.assign.stepDetails`),className:`flex flex-col gap-1`,children:[d(`h3`,{className:`text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:p(`customize.assign.stepDetails`)}),c]})]})}),a(ir,{children:[d(Y,{variant:`ghost`,onClick:v,children:p(`customize.assign.cancel`)}),d(Y,{disabled:g===null||!l,onClick:()=>{g!==null&&(u(g),h(null),_(null))},children:o})]})]})})}function Co(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function wo(e,t){let n=Si(e,t);return n===void 0?{kind:`absent`}:{kind:`value`,value:n}}function To(e,t,n){return Co(t)?wo(t,n):e.status===`error`?{kind:`unknown`,reason:e.error?.message??X.t(`helpers.liveValue.unreadable`)}:e.status===`pending`||e.data===void 0?{kind:`pending`}:e.data===null?{kind:`absent`}:wo(e.data,n)}function Eo(e,t,n){let r=e?`active`:`muted`;return t.cap===`contact`&&t.path===`entryOpen`?{text:e?n.open:n.closed,tone:r}:Ce[t.cap]===t.path?{text:e?n.active:n.inactive,tone:r}:{text:String(e),tone:`normal`}}function Do(e,t,n){switch(e.kind){case`pending`:return{text:`…`,tone:`muted`};case`unknown`:return{text:`?`,title:e.reason,tone:`warning`};case`absent`:return{text:`—`,tone:`muted`};case`value`:{let r=e.value;return r===null?{text:`—`,tone:`muted`}:typeof r==`boolean`?Eo(r,t,n):typeof r==`number`?{text:t.path===`percentage`?`${Math.round(r)} %`:String(r),tone:`normal`}:typeof r==`string`?{text:r,tone:`normal`}:{text:JSON.stringify(r),tone:`normal`}}}}var Oo=0;function ko(e){let t=U(),n=kr({deviceId:e?.deviceId??Oo,capName:e?.cap??``},{enabled:e!==null}),r=gr(t.trpcClient,e?.deviceId??null,e?.cap??``);return e===null?{kind:`absent`}:To({status:n.status,data:n.data,error:n.error===null||n.error===void 0?null:{message:n.error.message}},r,e.path)}var Ao={muted:`text-foreground-subtle`,active:`text-success`,normal:`text-foreground`,warning:`text-warning`};function jo({target:e}){let{t}=Z(),n=ko(e);return e===null?null:d(Mo,{display:Do(n,e,{active:t(`customize.assign.value.active`),inactive:t(`customize.assign.value.inactive`),open:t(`customize.assign.value.open`),closed:t(`customize.assign.value.closed`)})})}function Mo({display:e}){return d(`span`,{className:`text-xs ${Ao[e.tone]}`,title:e.title,children:e.text})}function No({name:e,detail:t,meta:n,value:r,shown:i,problem:o,onRemove:s,removeLabel:c,busy:l=!1}){return a(`li`,{className:`${A} grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 gap-y-1 sm:grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,1fr)_1.75rem]`,children:[a(`div`,{className:`min-w-0`,children:[d(`div`,{className:`text-xs text-foreground break-words`,children:e}),t!==null&&d(`div`,{className:`text-[11px] text-foreground-subtle break-words`,children:t}),o!==void 0&&d(`div`,{role:`alert`,className:`text-[11px] text-warning break-words`,children:o})]}),d(`div`,{className:`row-start-2 col-start-1 text-[11px] text-foreground-subtle empty:hidden sm:row-start-auto sm:col-start-auto sm:empty:block`,children:n}),d(`div`,{className:`row-start-3 col-start-1 empty:hidden sm:row-start-auto sm:col-start-auto sm:empty:block`,children:i===void 0?d(jo,{target:r}):i!==null&&d(Mo,{display:i})}),d(`div`,{className:`row-start-1 col-start-2 flex justify-end sm:row-start-auto sm:col-start-auto`,children:s!==void 0&&d(Zn,{icon:B,variant:`ghost`,size:`sm`,"aria-label":c,disabled:l,onClick:s})})]})}function Po({id:e,...t}){return d(nr,{headingId:`customize-${e}`,...t})}function Fo({id:e,icon:t,title:n,headerControl:r,addLabel:i,onAdd:o,addDisabled:c=!1,notices:l,suggestion:u,children:f}){let{t:p}=Z(),m=o!==void 0&&i!==void 0;return a(Po,{id:e,icon:t,title:n,actions:a(s,{children:[r,m&&!c&&u!==void 0&&u.count>0&&a(Y,{variant:`ghost`,size:`sm`,onClick:u.onOpen,children:[d(I,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),p(`customize.suggest.hint`,{count:u.count,location:u.location})]}),m&&d(Y,{variant:`outline`,size:`sm`,disabled:c,onClick:o,children:i})]}),children:[l!==void 0&&d(`div`,{className:`flex flex-col gap-1 px-3 pt-2 empty:hidden sm:px-4`,children:l}),d(`ul`,{className:`flex flex-col divide-y divide-border`,children:f})]})}function Io({availability:e}){let{t}=Z();return e.kind===`pending`?d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.assign.checking`)}):e.kind===`unknown`?d(`p`,{role:`alert`,className:`text-xs text-warning`,children:t(`customize.assign.unknown`,{reason:e.reason})}):null}function Lo(e,t){if(e.status===`error`)return{kind:`unknown`,reason:e.error?.message??X.t(`helpers.customize.requestFailed`)};let n=e.data;return e.status===`pending`||n===void 0?{kind:`pending`}:{kind:`known`,value:t(n)}}function Ro(e,t){let n=Mt.useQueries(n=>e.map(e=>n.deviceManager.listDeviceIdsByCaps({capNames:[e]},{enabled:t})));return aa(e.map((e,t)=>{let r=n[t];return{cap:e,query:r===void 0?{status:`pending`}:{status:r.status,data:r.data,error:r.error===null?null:{message:r.error.message}}}}))}e();function zo(e,t){let n=Xn(e,t);return n.kind===`resolved`?n.integration.name:null}function Bo(e){let t=bt({projection:`slim`},{enabled:e}),{data:r}=jr(void 0,{enabled:e}),i=t.error===null||t.error===void 0?null:t.error.message;return n(()=>Lo({status:t.status,data:t.data,error:i===null?null:{message:i}},e=>e.map(e=>({id:e.id,name:e.name,addonId:e.addonId,stableId:e.stableId,type:e.type,location:e.location,isCamera:e.isCamera,integration:zo(e,r),parentDeviceId:e.parentDeviceId,primaryChildEntityId:e.primaryChildEntityId??null,role:e.role??null}))),[t.status,t.data,i,r])}function Vo(e){let t=Bo(e.enabled),n=Ro(be,e.enabled);return t.kind===`unknown`?t:n.kind===`unknown`?n:t.kind===`pending`||n.kind===`pending`?{kind:`pending`}:{kind:`known`,value:ta({devices:t.value,capIndex:n.value,hostId:e.hostId,excludeCameras:e.excludeCameras,assigned:e.assigned,preferredCap:e.preferredCap})}}function Ho(){let{t:e}=Z(),t=pt();return(n,r)=>t({title:e(`customize.assign.removeConfirm.title`),message:r?`${e(`customize.assign.removeConfirm.message`,{what:n})} ${e(`customize.assign.removeConfirm.last`)}`:e(`customize.assign.removeConfirm.message`,{what:n}),confirmLabel:e(`customize.assign.removeConfirm.confirm`),variant:`danger`})}e();function Uo(e){return e===null?null:mi(e,`replace`)?`replace`:mi(e,`add`)?`add`:null}function Wo({device:e,handle:t,availability:n,onAdvanced:i}){let{t:o}=Z(),c=Ho(),[l,u]=r(!1),[f,p]=r(null),m=co(t.state),h=Di(m,`battery`),g=Uo(h),_=g===null?null:si(h?.fields.percentage),v=Bo(_!==null);if(n.kind===`absent`)return null;let b=n.kind===`present`?n.mode:null,x=t.state.kind===`none`||t.state.kind===`present`,S=_===null||v.kind!==`known`?null:v.value.find(e=>G({addonId:e.addonId,stableId:e.stableId})===G(_.source))??null,C=_===null?``:S?.name??G(_.source),w=async e=>{let n=await t.save(e);p(n.kind===`refused`?n.reason:null)},T=async()=>{if(m===null)return;let e=ri(m,`battery`);await c(o(`customize.battery.removeWhat`,{name:C}),e===null)&&await w(e)},E=b!==null&&x&&h===null&&!t.saving;return a(s,{children:[a(Fo,{id:`battery`,icon:y,title:o(`customize.battery.title`),addLabel:o(b===`replace`?`customize.battery.replace`:`customize.battery.add`),onAdd:E?()=>u(!0):void 0,notices:a(s,{children:[d(Io,{availability:n}),_!==null&&v.kind===`unknown`&&d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:o(`customize.assign.devicesUnreadable`,{reason:v.reason})}),f!==null&&d(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:f})]}),children:[b===`replace`&&x&&d(No,{name:o(`customize.battery.native`),detail:null,meta:o(h===null?`customize.assign.native`:`customize.battery.nativeReplaced`),value:h===null?{deviceId:e.id,cap:`battery`,path:`percentage`}:null,removeLabel:``}),h===null&&b===`add`&&x&&d(`li`,{className:`px-3 sm:px-4 py-1.5 sm:py-2 text-[11px] text-foreground-subtle`,children:o(`customize.assign.none`)}),_!==null&&d(No,{name:C,detail:`${_.cap}.${_.fieldPath}`,meta:o(g===`replace`?`customize.assign.replaces`:`customize.assign.adds`),value:S===null?null:{deviceId:S.id,cap:_.cap,path:_.fieldPath},problem:S===null&&v.kind===`known`?o(`customize.assign.missingKept`):void 0,onRemove:x?()=>void T():void 0,removeLabel:o(`customize.assign.removeNamed`,{name:C}),busy:t.saving}),h!==null&&_===null&&d(No,{name:o(`customize.battery.otherFormula`),detail:null,meta:d(oo,{onAdvanced:i}),value:{deviceId:e.id,cap:`battery`,path:`percentage`},removeLabel:``})]}),d(So,{open:l,title:o(b===`replace`?`customize.battery.replace`:`customize.battery.add`),targetKind:`number`,excludeDeviceIds:[e.id],confirmLabel:o(`customize.assign.add`),onConfirm:e=>{u(!1);let n=b===null?null:wi({percentage:{source:e.ref,cap:e.cap,fieldPath:e.path,kind:e.kind},mode:b});n===null?p(o(`customize.assign.pickUnusable`)):w(oi(m,t.target,n))},onClose:()=>u(!1)})]})}e();function Go(e,t){let n=e.source;if(n===null||t.kind!==`known`)return null;let r=G(n.source);return t.value.find(e=>G({addonId:e.addonId,stableId:e.stableId})===r)??null}function Ko(e){let t=typeof e==`number`?e:typeof e==`string`?Number(e):NaN;return Number.isFinite(t)?t:null}function qo({device:e,handle:t,availability:n,onAdvanced:i}){let{t:o}=Z(),c=Ho(),[l,u]=r(!1),[f,p]=r(``),[m,h]=r(`percent`),[g,_]=r(null),v=co(t.state),y=Di(v,`consumables`),b=fi(y),x=Bo(b.some(e=>e.source!==null));if(n.kind===`absent`)return null;let S=t.state.kind===`none`||t.state.kind===`present`,C=n.kind===`present`&&S&&!t.saving,w=pi(f),T=b.find(e=>e.key===w)??null,E=T!==null,D=f.trim()!==``&&w===``,k=async e=>{let n=await t.save(e);_(n.kind===`refused`?n.reason:null)},A=()=>{u(!1),p(``),h(`percent`)},j=async e=>{if(y===null||v===null)return;let n=Ti(y,e.key),r=n===null?ri(v,`consumables`):oi(v,t.target,n);await c(o(`customize.consumables.removeWhat`,{name:e.label}),r===null)&&await k(r)},M=a(`div`,{className:`flex flex-wrap items-end gap-2`,children:[a(`label`,{className:`flex w-full flex-col gap-1 text-[11px] text-foreground-subtle sm:w-56`,children:[o(`customize.consumables.name`),d(Zt,{"aria-label":o(`customize.consumables.name`),value:f,onChange:e=>p(e.target.value)})]}),a(`label`,{className:`flex w-full flex-col gap-1 text-[11px] text-foreground-subtle sm:w-40`,children:[o(`customize.consumables.unit`),d(lt,{"aria-label":o(`customize.consumables.unit`),value:m,options:gi.map(e=>({value:e,label:o(`customize.consumables.units.${e}`)})),onChange:e=>{let t=gi.find(t=>t===e.target.value);t!==void 0&&h(t)}})]}),E&&d(`p`,{role:`alert`,className:`basis-full text-xs text-warning`,children:o(`customize.consumables.takenBy`,{name:T.label})}),D&&d(`p`,{role:`alert`,className:`basis-full text-xs text-warning`,children:o(`customize.consumables.keyless`)})]});return a(s,{children:[a(Fo,{id:`consumables`,icon:O,title:o(`customize.consumables.title`),addLabel:o(`customize.consumables.add`),onAdd:C?()=>u(!0):void 0,notices:a(s,{children:[d(Io,{availability:n}),x.kind===`unknown`&&b.some(e=>e.source!==null)&&d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:o(`customize.assign.devicesUnreadable`,{reason:x.reason})}),g!==null&&d(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:g})]}),children:[b.map(e=>{let n=e.source;if(e.unit===null||n===null)return d(No,{name:e.label,detail:o(`customize.consumables.otherFormula`),meta:d(oo,{onAdvanced:i}),value:null,removeLabel:``},e.key);let r=Go(e,x),a=r?.name??G(n.source);return d(No,{name:e.label,detail:`${o(`customize.consumables.units.${e.unit}`)} · ${a}`,meta:`${n.cap}.${n.fieldPath}`,value:r===null?null:{deviceId:r.id,cap:n.cap,path:n.fieldPath},problem:r===null&&x.kind===`known`?o(`customize.assign.missingKept`):void 0,onRemove:S?()=>void j(e):void 0,removeLabel:o(`customize.assign.removeNamed`,{name:e.label}),busy:t.saving},e.key)}),b.length===0&&n.kind===`present`&&S&&d(`li`,{className:`px-3 sm:px-4 py-1.5 sm:py-2 text-[11px] text-foreground-subtle`,children:o(`customize.assign.none`)})]}),d(So,{open:l,title:o(`customize.consumables.pickTitle`),targetKind:`number`,excludeDeviceIds:[e.id],confirmLabel:o(`customize.assign.add`),extra:M,extraComplete:w!==``&&!E,onConfirm:e=>{let n=Ko(e.value);if(n!==null&&(n<0||m===`percent`&&n>100)){A(),_(o(`customize.consumables.outOfRange`,{value:n}));return}let r=di(y,{key:w,label:f,remaining:{source:e.ref,cap:e.cap,fieldPath:e.path,kind:e.kind},unit:m});A(),r===null?_(o(`customize.assign.pickUnusable`)):k(oi(v,t.target,r))},onClose:A})]})}function Jo(e,t){if(e.kind!==`known`||typeof t!=`string`||t.length===0)return null;let n=Rt(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 Yo(e,t,n){return kt(e,t?.ids??new Set,n)}function Xo(e,t){return e?.containers.get(t)??null}function Zo(e,t,n){return e.kind===`known`?Yo(e.value,t,n).suggested.length:0}function Qo(e,t){let n=[t,e.detail].filter(e=>e!==null&&e!==``);return n.length===0?null:n.join(` · `)}function $o({location:e,devices:t,action:n,onPick:r,onPickAll:i}){let{t:o}=Z();if(t.length===0)return null;let s=o(`customize.suggest.heading`,{location:e});return a(`section`,{"aria-label":s,className:`flex flex-col gap-1`,children:[a(`div`,{className:`flex min-h-7 items-center gap-2`,children:[d(`h3`,{className:`${j} min-w-0 flex-1`,children:s}),i!==void 0&&t.length>1&&d(Y,{variant:`ghost`,size:`sm`,onClick:i,children:o(`customize.suggest.addAll`,{count:t.length})})]}),d(`ul`,{className:`flex flex-col divide-y divide-border rounded-md border border-border`,children:t.map(e=>{let t=Qo(e,e.container===null||e.name.includes(e.container)?null:o(`customize.suggest.in`,{container:e.container}));return a(`li`,{className:`${A} flex items-center gap-3`,children:[a(`div`,{className:`min-w-0 flex-1`,children:[d(`div`,{className:`text-xs text-foreground break-words`,children:e.name}),t!==null&&d(`div`,{className:`text-[11px] text-foreground-subtle break-words`,children:t})]}),d(Y,{variant:`outline`,size:`sm`,"aria-label":o(n===`add`?`customize.suggest.addNamed`:`customize.suggest.useNamed`,{name:e.name}),onClick:()=>r(e.id),children:o(n===`add`?`customize.suggest.add`:`customize.suggest.use`)})]},e.id)})})]})}e();function es(e){return e.kind===`pending`?`pending`:e.kind===`unknown`?`failed`:`answered`}function ts(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 ns({open:e,title:i,selection:o,candidates:s,filters:c,room:l=null,confirmLabel:u,onConfirm:f,onClose:p}){let{t:m}=Z(),[h,g]=r(null),[_,v]=r([]),y=c?.find(e=>e.id===h)??c?.[0]??null,b=s.kind===`known`?s.value:[],x=s.kind===`known`?Yi(s.value,``,y):[],S=Yo(b,l,e=>e.deviceId).suggested,C=Yo(x,l,e=>e.deviceId).others,w=n(()=>ts(C),[C]),T=es(s),E=b.filter(e=>_.includes(e.deviceId));t(()=>{e||(v([]),g(null))},[e]);let D=()=>{v([]),g(null),p()},O=e=>{e.length!==0&&(f(e),v([]),g(null))},k=()=>O(E);return d(tn,{open:e,onOpenChange:e=>e?void 0:D(),children:a(jn,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":i,children:[d(hr,{children:d(Un,{children:i})}),a(at,{className:`flex flex-col gap-2 p-2 sm:p-4`,children:[c!==void 0&&c.length>0&&d(`div`,{className:`flex flex-wrap gap-1`,role:`tablist`,"aria-label":m(`customize.assign.filtersLabel`),children:c.map(e=>d(`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))}),l!==null&&d($o,{location:l.location,devices:S.map(e=>({id:e.deviceId,name:e.name,container:Xo(l,e.deviceId),detail:e.detail})),action:`add`,onPick:e=>O(S.filter(t=>t.deviceId===e)),...o===`multi`?{onPickAll:()=>O(S)}:{}}),s.kind===`unknown`?d(`p`,{role:`alert`,className:`text-xs text-warning`,children:m(`customize.assign.unknown`,{reason:s.reason})}):w.length===0&&S.length>0?null:d(mt,{devices:w,listState:T,value:_,onChange:e=>v(o===`single`?e.length>0?[e[e.length-1]]:[]:e),noun:`device`,emptyLabel:m(`customize.assign.none`),showAll:!0,testId:`customize-device-picker`})]}),a(ir,{children:[d(Y,{variant:`ghost`,onClick:D,children:m(`customize.picker.cancel`)}),d(Y,{disabled:E.length===0,onClick:k,children:u(E.length)})]})]})})}function rs(e){if(e===null)return[];let t=_i(e);return bi(e).map(e=>{let n=G(e);return{key:n,ref:e,caps:t.filter(e=>G(e.source)===n).map(e=>e.cap)}})}function is(e,t){let n=_i(e);if(n.length===0)return!1;let{enabled:r,...i}=e,{enabled:a,...o}=je({camera:t,sources:n,enabled:!0});return Ei(i,o)}function as(e){return e?.enabled!==!1}function os(e,t,n){let r=[...e===null?[]:_i(e),...n.flatMap(e=>Ie(e.ref,e.caps))];return r.length===0?null:je({camera:t,sources:r,enabled:as(e)})}function ss(e,t,n){let r=_i(e).filter(e=>G(e.source)!==n);return r.length===0?null:je({camera:t,sources:r,enabled:as(e)})}function cs(e,t){return{...e,enabled:t}}e();function ls({device:e,handle:t,availability:n,onAdvanced:i}){let{t:o}=Z(),c=Ho(),[l,u]=r(!1),[f,p]=r(null),m=co(t.state),h=Di(m,`doorbell`),g=h===null||is(h,t.target),_=g?rs(h):[],v=Bo(_.length>0),y=Vo({hostId:e.id,excludeCameras:!1,assigned:new Set(_.map(e=>e.key)),preferredCap:null,enabled:l});if(n.kind===`absent`)return null;let b=t.state.kind===`none`||t.state.kind===`present`,x=b&&!t.saving,S=n.kind===`present`&&x&&g,C=async e=>{let n=e===null?m===null?null:ri(m,`doorbell`):oi(m,t.target,e),r=await t.save(n);p(r.kind===`refused`?r.reason:null)},w=async(e,n)=>{if(h===null||m===null)return;let r=ss(h,t.target,e.key),i=r===null&&ri(m,`doorbell`)===null;await c(o(`customize.doorbell.removeWhat`,{name:n}),i)&&await C(r)},T=e=>v.kind===`known`?v.value.find(t=>G({addonId:t.addonId,stableId:t.stableId})===e.key)??null:null;return a(s,{children:[a(Fo,{id:`doorbell`,icon:ge,title:o(`customize.doorbell.title`),headerControl:h===null?void 0:a(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground`,children:[d(Ht,{"aria-label":o(`customize.doorbell.active`),checked:h.enabled!==!1,disabled:!x,onChange:e=>void C(cs(h,e.target.checked))}),o(`customize.doorbell.active`)]}),addLabel:o(`customize.doorbell.add`),onAdd:S?()=>u(!0):void 0,notices:a(s,{children:[d(Io,{availability:n}),v.kind===`unknown`&&d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:o(`customize.assign.devicesUnreadable`,{reason:v.reason})}),f!==null&&d(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:f})]}),children:[_.map(e=>{let n=T(e),r=n?.name??e.key,i=Xi(e.caps,null),a=i===null?void 0:Ce[i];return d(No,{name:r,detail:n===null?null:Qi(n.integration,n.location),meta:e.caps.join(`, `),value:n!==null&&i!==null&&a!==void 0?{deviceId:n.id,cap:i,path:a}:null,problem:n===null&&v.kind===`known`?o(`customize.assign.missingKept`):void 0,onRemove:b?()=>void w(e,r):void 0,removeLabel:o(`customize.assign.removeNamed`,{name:r}),busy:t.saving},e.key)}),!g&&d(No,{name:o(`customize.doorbell.otherFormula`),detail:null,meta:d(oo,{onAdvanced:i}),value:null,removeLabel:``}),h===null&&n.kind===`present`&&b&&d(`li`,{className:`px-3 sm:px-4 py-1.5 sm:py-2 text-[11px] text-foreground-subtle`,children:o(`customize.assign.none`)})]}),d(ns,{open:l,title:o(`customize.doorbell.pickTitle`),selection:`multi`,candidates:y,confirmLabel:e=>o(`customize.assign.addCount`,{count:e}),onConfirm:e=>{u(!1),C(os(h,t.target,e.map(e=>({ref:e.ref,caps:e.caps}))))},onClose:()=>u(!1)})]})}e();function us(e,t){let r=typeof e==`string`&&e.length>0,i=Bo(t&&r);return n(()=>t?Jo(i,e):null,[t,i,e])}e();function ds(e){return e==null?null:e.message}function fs({device:e}){let t=ne(),{t:n}=Z(),i=c(),o=Ho(),l=Ve.includes(e.type),[u,f]=r(!1),[p,m]=r(!1),[h,g]=r(null),_=Er({deviceId:e.id},{enabled:l}),v=na({status:_.status,data:_.data,error:ds(_.error)===null?null:{message:ds(_.error)??``}}),y=v.kind===`present`?v.slot.slotRef:``,b=v.kind===`present`?[...$i(v.slot,v.value).map(e=>e.deviceId),...Zi(v.slot,v.value)]:[],x=Tn(),S=Bo(l&&v.kind===`present`&&(u||b.length>0)),C=us(e.location,l&&v.kind===`present`),w=Sr({deviceId:e.id,slotRef:y},{enabled:(u||C!==null)&&v.kind===`present`});if(!l||v.kind===`absent`)return null;if(v.kind!==`present`)return d(Fo,{id:`linked`,icon:ae,title:n(`customize.linked.title`),notices:v.kind===`pending`?d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:n(`customize.assign.checking`)}):d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:n(`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:Qi(n.integration,n.location),orphan:t}},k=[...$i(v.slot,T).map(e=>O(e,!1)),...Zi(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:ds(w.error)??n(`helpers.customize.requestFailed`)}:S.kind===`pending`||w.status===`pending`||w.data===void 0?{kind:`pending`}:{kind:`known`,value:ia(w.data.candidates,E,A)},M=async t=>{if(p){g(n(`customize.saveInFlight`));return}m(!0),g(null);try{await x.mutateAsync({deviceId:e.id,slotRef:v.slot.slotRef,value:t}),await _.refetch(),await i.invalidateQueries({queryKey:[[`deviceManager`]]})}catch(e){g(e instanceof Error?e.message:String(e))}finally{m(!1)}},ee=async e=>{await o(n(`customize.linked.removeWhat`,{name:e.name??`#${e.deviceId}`}),!1)&&await M(ra(T,e.deviceId))},N=[{key:`device`,header:n(`customize.linked.device`),cell:e=>a(`div`,{className:`flex flex-col min-w-0`,children:[d(`span`,{className:`truncate text-xs text-foreground`,children:e.name??`#${e.deviceId}`}),e.detail!==null&&d(`span`,{className:`truncate text-[11px] text-foreground-subtle`,children:e.detail}),e.orphan&&d(`span`,{className:`text-[11px] text-foreground-subtle`,children:n(`customize.linked.notLinked`)}),e.health!==`ok`&&d(`span`,{role:`alert`,className:`text-[11px] text-warning`,children:n(`customize.linked.health.${e.health}`)})]})},{key:`type`,header:n(`customize.linked.type`),headerClassName:`hidden sm:table-cell`,cellClassName:`hidden sm:table-cell text-xs text-foreground-subtle`,cell:e=>e.type===null?`—`:Dt(e.type,t).label},{key:`controls`,header:n(`customize.linked.controls`),headerClassName:`hidden md:table-cell`,cellClassName:`hidden md:table-cell text-xs text-foreground-subtle`,cell:e=>e.orphan?`—`:n(`customize.linked.yes`)},...D?[{key:`tracked`,header:n(`customize.linked.tracked`),cellClassName:`text-right`,headerClassName:`text-right`,cell:e=>d(Gn,{checked:e.tracked,disabled:p,"aria-label":n(`customize.linked.trackFor`,{name:e.name??e.deviceId}),onCheckedChange:t=>void M(ea(T,e.deviceId,t))})}]:[],{key:`remove`,header:``,cellClassName:`text-right w-10`,cell:e=>e.implied||e.orphan?null:d(Zn,{icon:B,variant:`ghost`,size:`sm`,"aria-label":n(`customize.assign.removeNamed`,{name:e.name??e.deviceId}),disabled:p,onClick:t=>{t.stopPropagation(),ee(e)}})}];return a(s,{children:[d(Fo,{id:`linked`,icon:ae,title:n(`customize.linked.title`),addLabel:n(`customize.linked.add`),onAdd:p?void 0:()=>f(!0),...C===null?{}:{suggestion:{count:Zo(j,C,e=>e.deviceId),location:C.location,onOpen:()=>f(!0)}},notices:a(s,{children:[S.kind===`unknown`&&d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:n(`customize.assign.devicesUnreadable`,{reason:S.reason})}),h!==null&&d(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:h})]}),children:a(`li`,{className:`list-none px-3 py-2 sm:px-4`,children:[k.length===0?d(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`customize.assign.none`)}):d(ft,{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:Dt(e.type,t).label,columns:N,searchPlaceholder:n(`customize.assign.search`),emptyLabel:n(`customize.assign.none`)}),k.some(e=>!e.orphan)&&d(`p`,{className:`mt-2 text-[10px] text-foreground-subtle`,children:n(`customize.linked.controlsAlways`)}),D&&d(`p`,{className:`mt-0.5 text-[10px] text-foreground-subtle`,children:n(`customize.linked.trackedHint`)})]})}),d(ns,{open:u,title:n(`customize.linked.pickTitle`),selection:`multi`,candidates:j,room:C,confirmLabel:e=>n(`customize.assign.addCount`,{count:e}),onConfirm:e=>{f(!1),M(qi(T,e.map(e=>e.deviceId)))},onClose:()=>f(!1)})]})}function ps(e){return e===null||e.state===`unreadable`?null:e.state===`configured`?e.sensors:[]}function ms(e){return{addonId:e.addonId,stableId:e.stableId,mode:e.mode}}function hs(e){return e.length===0?null:{sensors:[...e]}}function gs(e,t){let n=new Set(e.map(De));return hs([...e.map(ms),...t.filter(e=>!n.has(De(e))).map(e=>({...e,mode:ve}))])}function _s(e,t,n){return hs(e.map(e=>De(e)===t?{...ms(e),mode:n}:ms(e)))}function vs(e,t){return hs(e.filter(e=>De(e)!==t).map(ms))}function ys(e){return e?.state===`configured`&&e.cameraMotion!==void 0}function bs(e){return e===null||e.state===`unreadable`?null:e.state===`configured`?e.cameraMotion??`always`:`always`}function xs(e){return e===null||e.state===`unreadable`?!1:e.state===`not-configured`||ys(e)}function Ss(e){return e?.state===`configured`&&(e.notForwarded!==void 0||e.notEnforced!==void 0)}function Cs(e,t,n){if(e!==`present`||t===null||n)return{kind:`none`};let r=t.cameraLevel;return r===void 0?{kind:`unknown`}:{kind:`level`,detected:r.detected,atMs:r.atMs}}e();var ws=5e3;function Ts(e){return e.state===`missing`||e.state===`unreadable`?e.stableId:e.name}function Es({device:e,availability:n,sensors:i}){let{t:o}=Z(),c=Ho(),u=ot(),[f,p]=r(!1),[m,h]=r(null),g=l(!1),[_,v]=r(!1),[y,b]=r(!1),x=i.status,S=l(i.refetch);S.current=i.refetch,t(()=>{let e=setInterval(()=>{g.current||S.current()},ws);return()=>clearInterval(e)},[]);let C=ps(x);t(()=>{x!==null&&b(!1)},[x]);let w=i.presence===`present`&&xs(x)&&!y?C:null,T=Bo(C!==null&&C.length>0),E=Vo({hostId:e.id,excludeCameras:!0,assigned:new Set((C??[]).map(De)),preferredCap:`motion`,enabled:f});if(n.kind===`absent`)return null;let D=ys(x),O=Ss(x)?`passes`:bs(x),k=Cs(i.presence,x,y),A=k.kind===`none`?null:k.kind===`unknown`?{text:`?`,tone:`warning`,title:o(`customize.motion.cameraLevelUnknown`)}:{text:o(k.detected?`customize.assign.value.active`:`customize.assign.value.inactive`),tone:k.detected?`active`:`muted`,title:o(`customize.motion.cameraLevelOwn`,{at:new Date(k.atMs).toLocaleTimeString()})},j=_||u.isPending,M=async t=>{if(g.current){h(o(`customize.saveInFlight`));return}g.current=!0,v(!0);try{await u.mutateAsync({deviceId:e.id,config:t}),h(null),await i.refetch()===`failed`&&b(!0)}catch(e){h(e instanceof Error?e.message:String(e))}finally{g.current=!1,v(!1)}},ee=async e=>{w!==null&&await c(o(`customize.motion.removeWhat`,{name:Ts(e)}),!1)&&await M(vs(w,De(e)))},N=e=>{if(T.kind!==`known`||!(`deviceId`in e))return null;let t=T.value.find(t=>t.id===e.deviceId);return t===void 0?null:Qi(t.integration,t.location)};return a(s,{children:[a(Fo,{id:`motion`,icon:H,title:o(`customize.motion.title`),addLabel:o(`customize.motion.add`),onAdd:w!==null&&n.kind===`present`?()=>p(!0):void 0,addDisabled:j,notices:a(s,{children:[d(Io,{availability:n}),i.presence===`pending`&&n.kind!==`pending`&&d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:o(`customize.motion.reading`)}),x?.state===`unreadable`&&d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:o(`customize.motion.unreadable`,{reason:x.reason})}),x?.state===`configured`&&!xs(x)&&d(`p`,{role:`alert`,className:`text-xs text-warning`,children:o(`customize.motion.olderOrchestrator`)}),y&&d(`p`,{role:`alert`,className:`text-xs text-warning`,children:o(`customize.motion.refetchFailed`)}),x?.state===`configured`&&x.notForwarded!==void 0&&d(`p`,{role:`alert`,className:`text-xs text-warning`,children:o(`customize.motion.notForwarded.${x.notForwarded}`)}),x?.state===`configured`&&x.notEnforced!==void 0&&d(`p`,{role:`alert`,className:`text-xs text-warning`,children:o(`customize.motion.notEnforced`)}),T.kind===`unknown`&&d(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:o(`customize.assign.devicesUnreadable`,{reason:T.reason})}),m!==null&&d(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:m})]}),children:[d(No,{name:o(`customize.motion.camera`),detail:null,meta:O===null?o(`customize.assign.native`):`${o(`customize.motion.cameraState.${O}`)} · ${o(`customize.assign.native`)}`,value:null,shown:A,removeLabel:``}),(C??[]).map(e=>{let t=De(e),n=Ts(e),r=e.state===`ready`?Xi(e.caps,`motion`):null,i=r===null?void 0:Ce[r];return d(No,{name:n,detail:N(e),meta:D&&w!==null?d(lt,{"aria-label":o(`customize.motion.modeFor`,{name:n}),value:e.mode,disabled:j,options:qe.options.map(e=>({value:e,label:o(`customize.motion.mode.${e}`)})),onChange:e=>{let n=qe.safeParse(e.target.value);n.success&&w!==null&&M(_s(w,t,n.data))}}):o(`customize.motion.mode.${e.mode}`),value:r!==null&&i!==void 0&&`deviceId`in e?{deviceId:e.deviceId,cap:r,path:i}:null,problem:e.state===`ready`?void 0:e.reason===e.state?o(`customize.motion.state.${e.state}`):`${o(`customize.motion.state.${e.state}`)}: ${e.reason}`,onRemove:w===null?void 0:()=>void ee(e),removeLabel:o(`customize.assign.removeNamed`,{name:n}),busy:j},t)})]}),d(ns,{open:f,title:o(`customize.motion.pickTitle`),selection:`multi`,candidates:E,filters:Ji,confirmLabel:e=>o(`customize.assign.addCount`,{count:e}),onConfirm:e=>{if(p(!1),w===null)return;let t=gs(w,e.map(e=>e.ref));if(t!==null&&t.sensors.length>8){h(o(`customize.motion.tooMany`,{max:8}));return}M(t)},onClose:()=>p(!1)})]})}var Ds={"numeric-sensor":{fieldPath:`value`,unitField:`unit`},"temperature-sensor":{fieldPath:`celsius`,unitField:`unit`},"humidity-sensor":{fieldPath:`percent`,unitField:`unit`},"pressure-sensor":{fieldPath:`hpa`,unitField:`unit`},"ambient-light-sensor":{fieldPath:`lux`,unitField:`unit`}},Os=new Set([q.Camera]);function ks(e){return e.unitField===null?[e.fieldPath]:[e.fieldPath,e.unitField]}function As(e,t){if(Os.has(e))return{kind:`absent`};let n=null;for(let[e,r]of Object.entries(Ds))if(t.has(e)){n={cap:e,fieldPath:r.fieldPath,unitField:r.unitField};break}let r=null;for(let e of Ae)if(t.has(e)){let t=Ce[e];if(t!==void 0){r={cap:e,fieldPath:t};break}}return n===null&&r===null?{kind:`absent`}:{kind:`present`,convert:n,invert:r}}function js(e){return Fe(e.from,e.to)?ze(e):null}function Ms(e){return He(e)}var Ns=/^convert\(v,\s*"[^"]*",\s*"[^"]*"\)$/;function Ps(e){return e!==void 0&&Ns.test(e.expr)}function Fs(e){return e===void 0||e.expr===`!v`||Ns.test(e.expr)?!1:e.bindings.v!==void 0}function Is(e){let t=e.expr.trim();if(t===``)return{kind:`refused`,reason:X.t(`helpers.numericTransforms.emptyExpression`)};let n={kind:`expression`,expr:t,bindings:{v:{kind:`from`,source:e.self,cap:e.cap,fieldPath:e.fieldPath}}},r=Re({source:n,now:Date.now(),read:()=>({state:`fresh`,value:e.probe})});return r.state===`unavailable`?{kind:`refused`,reason:r.reason}:{kind:`ok`,feature:{kind:`fields`,cap:e.cap,fields:{[e.fieldPath]:n}}}}function Ls(e,t,n){if(e===null)return null;let r=Di(e,n.cap);if(r===null)return e;let i=new Set(ks(n)),a=Object.fromEntries(Object.entries(r.fields).filter(([e])=>!i.has(e)));return Object.keys(a).length===0?ri(e,n.cap):oi(e,t,{kind:`fields`,cap:n.cap,...r.enabled===void 0?{}:{enabled:r.enabled},fields:a,...r.items===void 0?{}:{items:r.items}})}e();function Rs(e){if(typeof e!=`object`||!e)return;let t=Reflect.get(e,`unit`);return typeof t==`string`?t:void 0}function zs(e,t){if(typeof e!=`object`||!e)return;let n=Reflect.get(e,t);return typeof n==`number`&&Number.isFinite(n)?n:void 0}function Bs(e,t){let n=Di(e,t.cap);if(n===null)return;let r=n.fields[t.fieldPath];return r!==void 0&&r.kind===`expression`?r:void 0}function Vs(e,t){let n=Bs(e,t);return n===void 0||!Ps(n)?null:/^convert\(v,\s*"[^"]*",\s*"([^"]*)"\)$/.exec(n.expr)?.[1]??null}function Hs(e,t){let n=Bs(e,t);return n===void 0||!Fs(n)?null:n.expr}function Us(e,t,n){let r=Di(e,t);if(r===null)return!1;let i=r.fields[n];return i!==void 0&&i.kind===`expression`&&i.expr===`!v`}function Ws(e){return typeof e==`number`||typeof e==`boolean`||typeof e==`string`?String(e):e===null?`null`:JSON.stringify(e)}function Gs({device:e,target:t,handle:n,facts:i}){let{t:o}=Z(),s=U(),[c,l]=r(null),[u,f]=r(``),[p,m]=r(null),g=i.nativeCaps.kind===`known`?i.nativeCaps.value:null,_=g===null?null:As(e.type,g),v=_?.kind===`present`?_.convert?.cap??``:``,y=gr(s.trpcClient,e.id,v);if(i.nativeCaps.kind===`pending`)return d(`section`,{className:`${T} ${h}`,children:d(Io,{availability:{kind:`pending`}})});if(i.nativeCaps.kind===`unknown`)return d(`section`,{className:`${T} ${h}`,children:d(Io,{availability:{kind:`unknown`,reason:i.nativeCaps.reason}})});if(_===null||_.kind===`absent`)return null;let b=co(n.state),x=_.convert,S=_.invert,C=x===null?void 0:Rs(y),w=C===void 0?void 0:Ne(C)??C,E=w===void 0?void 0:ke(w),D=x===null?null:Vs(b,x),O=x===null?null:Hs(b,x),k=p??O??``,A=S===null?!1:Us(b,S.cap,S.fieldPath),j=n.state.kind===`none`||n.state.kind===`present`,M=x===null?0:zs(y,x.fieldPath)??0,ee=x!==null&&k.trim()!==``?{kind:`expression`,expr:k.trim(),bindings:{v:{kind:`from`,source:t,cap:x.cap,fieldPath:x.fieldPath}}}:null,N=ee===null||x===null?null:vi(ee,new Map([[we(t,x.cap),y===void 0?{kind:`pending`}:{kind:`value`,slice:y}]]),Date.now()),P=async e=>{let t=await n.save(e);l(t.kind===`refused`?t.reason:null)},F=async()=>{if(x===null||w===void 0||u===``)return;let e=js({self:t,cap:x.cap,fieldPath:x.fieldPath,from:w,to:u,unitField:x.unitField});if(e===null){l(o(`customize.numericTransforms.convertRefused`));return}m(null),await P(oi(b,t,e))},te=async()=>{x!==null&&(await P(Ls(b,t,x)),f(``))},I=async()=>{if(x===null)return;let e=Is({self:t,cap:x.cap,fieldPath:x.fieldPath,expr:k,probe:M});if(e.kind===`refused`){l(e.reason);return}f(``),await P(oi(b,t,e.feature))},L=async()=>{x!==null&&(await P(Ls(b,t,x)),m(``))},R=async()=>{if(S===null)return;let e=Ms({self:t,cap:S.cap});if(e===null){l(o(`customize.numericTransforms.invertRefused`));return}await P(oi(b,t,e))},ne=async()=>{S===null||b===null||await P(ri(b,S.cap))};return d(Po,{id:`numeric-transforms`,icon:Ye,title:o(`customize.numericTransforms.title`),testId:`numeric-transforms-card`,children:a(`div`,{className:`${h} flex flex-col gap-3`,children:[d(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`customize.numericTransforms.blurb`)}),c!==null&&d(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:c}),x!==null&&a(`div`,{className:`flex flex-col gap-2`,"data-testid":`numeric-convert`,children:[d(`label`,{className:`text-[11px] font-medium text-foreground`,children:o(`customize.numericTransforms.publishUnit`)}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:w===void 0?o(`customize.numericTransforms.fromUnknown`):o(`customize.numericTransforms.fromUnit`,{unit:w})}),d(`div`,{className:`w-full sm:max-w-xs`,children:d(Gt,{dimension:E,value:u===``?D??``:u,onChange:e=>{f(e),e!==``&&m(``)},disabled:!j||n.saving||w===void 0,"aria-label":o(`customize.numericTransforms.toUnit`),inheritLabel:o(`customize.numericTransforms.pickUnit`),emptyReason:o(`customize.numericTransforms.fromUnknown`)})}),a(`div`,{className:`flex flex-wrap gap-2`,children:[d(Y,{size:`sm`,disabled:!j||n.saving||w===void 0||u===``||u===w,onClick:()=>void F(),children:o(`customize.numericTransforms.applyConvert`)}),D!==null&&d(Y,{size:`sm`,variant:`outline`,disabled:!j||n.saving,onClick:()=>void te(),children:o(`customize.numericTransforms.clearConvert`)})]})]}),x!==null&&a(`div`,{className:`flex flex-col gap-2`,"data-testid":`numeric-script`,children:[d(xi,{label:o(`customize.numericTransforms.script`),value:k,bindings:[`v`],onChange:e=>{m(e),e.trim()!==``&&f(``)}}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`customize.numericTransforms.scriptBlurb`)}),N!==null&&d(`p`,{role:`status`,className:`text-[11px] font-mono text-foreground`,"data-testid":`numeric-script-preview`,children:N.kind===`value`?o(`customize.numericTransforms.preview`,{source:Ws(M),result:Ws(N.value)}):N.kind===`waiting`?o(`customize.numericTransforms.previewWaiting`):N.kind===`unavailable`?o(`customize.numericTransforms.previewError`,{reason:N.reason}):o(`customize.numericTransforms.previewRuntimeOnly`)}),a(`div`,{className:`flex flex-wrap gap-2`,children:[d(Y,{size:`sm`,disabled:!j||n.saving||k.trim()===``,onClick:()=>void I(),children:o(`customize.numericTransforms.applyScript`)}),O!==null&&d(Y,{size:`sm`,variant:`outline`,disabled:!j||n.saving,onClick:()=>void L(),children:o(`customize.numericTransforms.clearScript`)})]})]}),S!==null&&a(`div`,{className:`flex flex-col gap-2`,"data-testid":`numeric-invert`,children:[d(`label`,{className:`text-[11px] font-medium text-foreground`,children:o(`customize.numericTransforms.invert`)}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`customize.numericTransforms.invertBlurb`)}),d(`div`,{className:`flex flex-wrap gap-2`,children:A?d(Y,{size:`sm`,variant:`outline`,disabled:!j||n.saving,onClick:()=>void ne(),children:o(`customize.numericTransforms.clearInvert`)}):d(Y,{size:`sm`,disabled:!j||n.saving,onClick:()=>void R(),children:o(`customize.numericTransforms.applyInvert`)})})]})]})})}e();function Ks(e){return e instanceof Error?e.message:String(e)}function qs(e){let t=sr({addonId:e.addonId,stableId:e.stableId}),n=yr(),i=Nn(),a=rr(),o=so({status:t.status,data:t.data,error:t.error===null||t.error===void 0?null:{message:t.error.message}}),{t:s}=Z(),c=l(!1),[u,d]=r(!1),f=async e=>{let r=li(o,e);try{switch(r.kind){case`refused`:return{kind:`refused`,reason:r.reason};case`noop`:return{kind:`saved`};case`create`:await n.mutateAsync({block:r.input});break;case`update`:await i.mutateAsync({blockId:r.blockId,expectedUpdatedAt:r.expectedUpdatedAt,block:{composition:r.composition}});break;case`delete`:await a.mutateAsync({blockId:r.blockId});break}return await t.refetch(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:Ks(e)}}};return{target:e,state:o,saving:u||n.isPending||i.isPending||a.isPending,save:async e=>{if(c.current)return{kind:`refused`,reason:s(`customize.saveInFlight`)};c.current=!0,d(!0);try{return await f(e)}finally{c.current=!1,d(!1)}}}}var Js=`pipeline-orchestrator`;function Ys(e){return e.status===`pending`?`pending`:e.status===`error`?`unknown`:e.data===void 0?`pending`:e.data.cameraSensors===void 0?`absent`:`present`}function Xs(e,t){return e===`absent`?`absent`:Ys(t)}async function Zs(e){try{return(await e()).isError?`failed`:`answered`}catch{return`failed`}}function Qs(e,t){let n=zn(Js),r=vr({deviceId:e},{enabled:t&&n!==`absent`}),i=()=>Zs(r.refetch);return t?{presence:Xs(n,{status:r.status,data:r.data}),status:r.data?.cameraSensors??null,refetch:i}:{presence:`absent`,status:null,refetch:i}}function $s(e,t){let n=_r({deviceType:e.type}),r=nn({deviceId:e.id}),i=fn({deviceId:e.id}),a=Lo(n,e=>new Set(e.caps.map(e=>e.cap))),o=Lo(r,e=>to(e.entries)),s=Lo(i,e=>e);return{deviceType:e.type,composable:a,nativeCaps:o,wireable:s,composed:new Set((t?.features??[]).map(e=>e.cap))}}function ec(){return{kind:`unknown`,reason:X.t(`helpers.fieldsTableRows.noValue`)}}function tc(e,t){let n=G(e);return t.get(n)??n}function nc(e,t,n){let r=n.nativeCaps.has(e.cap)?`replaced`:`added`,i=t.filter(t=>t.cap===e.cap&&t.origin===`composed`);if(e.cap===`doorbell`){let t=bi(e).map(e=>tc(e,n.sourceNames)).join(` + `),a=i.find(e=>e.field===`lastPressedAt`);return[{key:`doorbell`,label:X.t(`helpers.whatChangesRows.doorbell`),origin:{kind:r,from:t},value:a?.value??ec()}]}return e.cap===`consumables`?fi(e).map(e=>{let t=t=>K(ye,e.key,t),a=i.find(e=>e.field===t(`level`)||e.field===t(`remaining.value`)),o=e.source===null?``:tc(e.source.source,n.sourceNames);return{key:`consumables.${e.key}`,label:X.t(`helpers.whatChangesRows.consumable`,{name:e.label}),origin:{kind:r,from:o},value:a?.value??ec()}}):i.map(e=>({key:e.key,label:`${e.cap}.${e.field}`,origin:{kind:r,from:e.from},value:e.value}))}function rc(e){let t=hi({composition:e.composition,nativeCaps:e.nativeCaps,state:e.state,nativeFields:new Map,snapshot:null,sourceNames:e.sourceNames});return e.composition.features.flatMap(n=>n.kind===`fields`?nc(n,t,e):[])}function ic(e,t){if(e?.state!==`configured`||e.sensors.length===0)return null;let n=e.cameraMotion===`never`?[]:[t.camera],r=e.sensors.map(e=>t.sensor(e.state===`missing`||e.state===`unreadable`?e.stableId:e.name,e.mode));return[...n,...r].join(` + `)}var ac=`${A} grid grid-cols-1 gap-x-3 gap-y-0.5 items-baseline sm:grid-cols-[minmax(0,1fr)_minmax(0,2fr)_minmax(0,1.5fr)]`,oc=`font-mono text-[11px] text-foreground break-words`,sc=`text-[11px] text-foreground-subtle break-words`,cc=`text-[11px] break-words sm:text-right`;function lc({device:e,composition:t,state:n,nativeCaps:r,cameraSensors:i}){let{t:o}=Z(),s=t!==null&&n!==null,c=Bo(s),l=new Map(c.kind===`known`?c.value.map(e=>[G({addonId:e.addonId,stableId:e.stableId}),e.name]):[]),u=s&&r.kind===`known`?rc({composition:t,nativeCaps:r.value,state:n,sourceNames:l}):[],f=s&&r.kind===`known`&&u.length===0&&t.features.length>0,p=ic(i,{camera:o(`customize.changes.motion.camera`),sensor:(e,t)=>o(`customize.changes.motion.${t}`,{name:e})}),m=s&&r.kind!==`known`;return u.length===0&&p===null&&!m&&!f?null:a(Po,{id:`changes`,icon:z,title:o(`customize.changes.title`),children:[m&&d(`p`,{role:r.kind===`unknown`?`alert`:`status`,className:`px-3 sm:px-4 py-1.5 sm:py-2 text-[11px] text-foreground-subtle`,children:r.kind===`unknown`?o(`customize.changes.unknown`,{reason:r.reason}):o(`customize.changes.reading`)}),f&&d(`p`,{className:`px-3 sm:px-4 py-1.5 sm:py-2 text-[11px] text-foreground-subtle`,children:o(`customize.changes.noRows`)}),a(`ul`,{className:`divide-y divide-border`,children:[u.map(e=>a(`li`,{className:ac,children:[d(`span`,{className:oc,children:e.label}),d(`span`,{className:sc,children:c.kind===`known`?o(`customize.changes.origin.${e.origin.kind}`,{from:e.origin.from}):o(`customize.changes.originUnread.${c.kind}`,{kind:o(`customize.changes.kind.${e.origin.kind}`),reason:c.kind===`unknown`?c.reason:``})}),d(`span`,{className:cc,children:d(uc,{value:e.value})})]},e.key)),p!==null&&a(`li`,{className:ac,children:[d(`span`,{className:oc,children:o(`common.motionWord`)}),d(`span`,{className:sc,children:p}),d(`span`,{className:cc,children:d(jo,{target:{deviceId:e.id,cap:`motion`,path:`detected`}})})]})]})]})}function uc({value:e}){let{t}=Z();switch(e.kind){case`value`:return a(`span`,{children:[yi(e.value,!0),e.staleReason!==null&&a(`span`,{className:`text-warning`,children:[` `,`·`,` `,t(`customize.changes.value.stale`,{reason:e.staleReason})]})]});case`unavailable`:return d(`span`,{className:`text-warning`,children:t(`customize.changes.value.unavailable`,{reason:e.reason})});case`unknown`:return d(`span`,{className:`text-foreground-subtle`,children:t(`customize.changes.value.unknown`,{reason:e.reason})});case`off`:return d(`span`,{className:`text-foreground-subtle`,children:t(`customize.status.off`)})}}e();function dc({deviceId:e,activeSubTab:t,onSubTabChange:n}){let{t:r}=Z(),i=un({deviceId:e}),a=i.data;return a==null?i.status===`error`?d(Fn,{title:r(`customize.deviceUnreadable`),message:i.error?.message??``,onRetry:()=>void i.refetch()}):a===null?d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`customize.noSuchDevice`,{deviceId:e})}):d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`customize.loadingDevice`)}):a.addonId===`composer`?d(fc,{device:a}):d(pc,{device:a,target:{addonId:a.addonId,stableId:a.stableId},activeSubTab:t,onSubTabChange:n})}function fc({device:e}){let{t}=Z(),n=e.stableId.startsWith(`composed-`)?e.stableId.slice(Ee.length):null;return a(`section`,{className:`${T} ${h} flex flex-col gap-2`,children:[d(`p`,{className:`text-xs text-foreground`,children:t(`customize.composed.body`)}),n!==null&&d(Hr,{className:`text-[11px] text-primary hover:underline`,to:Xr(n),children:t(`customize.composed.edit`)})]})}function pc({device:e,target:t,activeSubTab:n,onSubTabChange:r}){let i=qs(t),o=zn(`composer`),{t:s}=Z(),c=Qs(e.id,e.type===q.Camera),l=$s(e,co(i.state)),u={deviceType:e.type,composable:l.composable,nativeCaps:l.nativeCaps,cameraSensors:c.presence},f=()=>r(ei),p=i.state.kind===`none`||i.state.kind===`present`;return n===`advanced`?a(`div`,{className:`flex flex-col gap-3`,children:[d(hc,{state:i.state}),p&&d(mc,{device:e,target:t,handle:i,facts:l,onDone:()=>r(`main`)})]}):a(`div`,{className:`flex flex-col gap-3`,children:[d(vo,{device:e}),o===`absent`&&d(`p`,{role:`alert`,className:`text-xs text-warning`,children:s(`customize.composerAbsent`)}),i.state.kind!==`none`&&d(hc,{state:i.state}),d(ls,{device:e,handle:i,availability:ao(`doorbell`,u),onAdvanced:f}),d(Es,{device:e,handle:i,availability:ao(`motion`,u),sensors:c}),d(Wo,{device:e,handle:i,availability:ao(`battery`,u),onAdvanced:f}),d(qo,{device:e,handle:i,availability:ao(`consumables`,u),onAdvanced:f}),d(Gs,{device:e,target:t,handle:i,facts:l}),d(fs,{device:e}),d(lc,{device:e,composition:co(i.state),state:i.state.kind===`present`?i.state.view.state:null,nativeCaps:l.nativeCaps,cameraSensors:c.status}),a(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[p?d(oo,{onAdvanced:f}):d(`span`,{}),d(gc,{handle:i})]})]})}function mc({device:e,target:t,handle:n,facts:r,onDone:i}){let a=n.state.kind===`present`?n.state:null;return d(Ci,{initial:a===null?ii(t):ai(a.composition,``),blockId:a===null?null:a.view.block.id,deviceType:e.type,targetName:e.name,nativeCaps:r.nativeCaps,targetFields:r.wireable,onCancel:i,save:async e=>{let t=await n.save(e);return t.kind===`saved`&&i(),t}})}function hc({state:e}){let{t}=Z();switch(e.kind){case`pending`:return d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.status.pending`)});case`unknown`:return d(Fn,{title:t(`customize.status.unknownTitle`),message:e.reason});case`not-loaded`:return d(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.status.notLoaded`,{reason:e.reason})});case`none`:return null;case`present`:{let n=e.view.block;return a(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(en,{variant:n.status===`running`?`success`:n.status===`failed`?`danger`:`warning`,children:t(`customize.blockStatus.${n.status}`)}),!n.enabled&&d(en,{variant:`default`,children:t(`customize.status.off`)}),n.lastError!==void 0&&d(`span`,{className:`text-[11px] text-foreground-muted break-words`,children:n.lastError}),e.view.state.kind===`unreachable`&&d(`span`,{className:`text-[11px] text-warning`,children:t(`customize.status.composerUnreachable`,{reason:e.view.state.error})})]})}}}function gc({handle:e}){let{t}=Z(),n=pt(),[i,o]=r(null);if(e.state.kind!==`present`)return null;let s=async()=>{if(!await n({title:t(`customize.remove.title`),message:t(`customize.remove.message`),confirmLabel:t(`customize.remove.confirm`),variant:`danger`}))return;let r=await e.save(null);o(r.kind===`refused`?r.reason:null)};return a(`div`,{className:`flex flex-col items-start gap-1`,children:[d(Y,{variant:`danger`,size:`sm`,disabled:e.saving,onClick:()=>void s(),children:t(`customize.remove.button`)}),i!==null&&d(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:i})]})}var _c=`overview`;function vc(e,t){return e.some(e=>e.id===t)?t:_c}function yc({deviceId:e}){let{t}=Z(),n=c(),r=Number.isFinite(e),{data:i}=un({deviceId:e},{enabled:r}),o=typeof i?.type==`string`?i.type:`camera`;pr([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:s,isLoading:l,isError:u,error:f}=nn({deviceId:e},{enabled:r}),{data:p}=Pt({deviceType:o},{enabled:!!o}),m=Rn({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(l)return d(`div`,{className:`p-4`,children:d(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(u)return a(`div`,{className:`p-4 text-xs text-red-400`,children:[t(`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 s?.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 a(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[d(et,{className:`h-8 w-8 opacity-40`}),d(`p`,{className:`text-xs`,children:t(`device.bindingsTab.noCapabilityProvidersApplicableTo`,`No capability providers applicable to this device yet.`)}),d(`p`,{className:`text-[10px] opacity-60`,children:t(`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:t(`device.bindingsTab.capability`,`Capability`),render:e=>d(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:t(`device.bindingsTab.kind`,`Kind`),render:e=>d(bc,{kind:e.kind})},{key:`provider`,header:t(`device.bindingsTab.activeProvider`,`Active Provider`),render:e=>d(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||d(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:t(`device.bindingsTab.node`,`Node`),render:e=>e.providerNodeId?d(xc,{nodeId:e.providerNodeId}):d(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:t(`device.bindingsTab.kindNative`,`Native`),render:e=>d(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||d(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:t(`device.bindingsTab.wrapper`,`Wrapper`),render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return d(Sc,{wrappers:t.wrappers,activeWrapperId:n,disabled:m.isPending,onPick:r=>{let i=n===r;m.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}];return a(`div`,{className:`flex flex-col gap-3 p-1`,children:[d(`div`,{className:`text-[11px] text-foreground-subtle`,children:d(Jr,{i18nKey:`device.bindingsTab.boundSummary`,count:_.length,values:{bound:v},components:{b:d(`span`,{className:`font-medium text-foreground`}),em:d(`em`,{})}})}),d(Ln,{columns:y,rows:_,rowKey:e=>e.capName,minWidthPx:720})]})}function bc({kind:e}){let{t}=Z();return e===`native`?a(`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:[d(re,{className:`h-3 w-3`}),t(`device.bindingsTab.kindNative`)]}):e===`wrapped`?a(`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:[d(rt,{className:`h-3 w-3`}),t(`device.bindingsTab.wrapped`)]}):e===`linked`?a(`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:[d(ae,{className:`h-3 w-3`}),t(`device.bindingsTab.linked`)]}):a(`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:[d(S,{className:`h-3 w-3`}),t(`common.unbound`)]})}function xc({nodeId:e}){return d(`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 Sc({wrappers:e,activeWrapperId:t,disabled:n,onPick:r}){let{t:i}=Z();return e.length===0?d(`span`,{className:`text-[10px] opacity-40`,children:i(`device.bindingsTab.noneAvailable`,`none available`)}):d(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let o=e===t;return a(`button`,{disabled:n,onClick:()=>r(e),title:o?i(`device.bindingsTab.clickToDeactivateRevertTo`,`Click to deactivate (revert to native)`):i(`device.bindingsTab.activateWrapper`,`Activate wrapper {{wrapperId}}`,{wrapperId:e}),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 ${o?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[d(o?p:me,{className:`h-3 w-3`}),e]},e)})})}function Cc({deviceId:e,activeSubTab:t,onSubTabChange:n,deviceType:r,isAdmin:i}){return a(`div`,{className:`flex flex-col gap-3`,children:[Br(r,i)&&d(ur,{deviceId:e,readOnly:!0}),d(Qr,{deviceId:e,activeSubTab:t,onSubTabChange:n})]})}e();var wc=[[`pipelineOrchestrator`,`getCameraDetectionSource`]];function Tc(e){let t=c(),n=Sn({deviceId:e},{refetchOnMount:`always`}),a=Jn(),[o,s]=r(null),[l,u]=r(null),d=i(async n=>{u(null),s(n);try{await a.mutateAsync({deviceId:e,source:n}),await t.invalidateQueries({queryKey:wc})}catch(e){u(e instanceof Error?e.message:`Could not change the root detector`),await t.invalidateQueries({queryKey:wc})}finally{s(null)}},[e,a,t]),f=n.data??null;return{view:f,isLoading:n.isLoading,source:o??f?.source??null,saving:o!==null,error:l,pick:d}}var Ec=`object-detection`;function Dc(e){return[e.addonId,...e.children.flatMap(Dc)]}function Oc(e,t){if(e===`pipeline`)return new Set;let n=kc(t,Ec);return n===void 0?new Set:new Set(e===`onboard`?[n.addonId]:Dc(n))}function kc(e,t){for(let n of e){if(n.addonId===t)return n;let e=kc(n.children,t);if(e!==void 0)return e}}function Ac(e,t){return e===`onboard`?X.t(`helpers.detectionSourceModel.badgeCameraAi`):t===`object-detection`?X.t(`helpers.detectionSourceModel.badgeNoRoot`):X.t(`helpers.detectionSourceModel.badgeIdle`)}function jc(e){switch(e){case`pipeline`:return X.t(`helpers.detectionSourceModel.explainPipeline`);case`onboard`:return X.t(`helpers.detectionSourceModel.explainOnboard`);case`none`:return X.t(`helpers.detectionSourceModel.explainNone`)}}function Mc(e){switch(e){case`boxed`:return``;case`while-streaming`:return X.t(`helpers.detectionSourceModel.geometryWhileStreaming`);case`flag-only`:return X.t(`helpers.detectionSourceModel.geometryFlagOnly`);case`unknown`:return X.t(`helpers.detectionSourceModel.geometryUnknown`)}}function Nc(e,t){return e===`onboard`?X.t(`helpers.detectionSourceModel.noticeOnboard`):t===`object-detection`?X.t(`helpers.detectionSourceModel.noticeNoRoot`):X.t(`helpers.detectionSourceModel.noticeIdle`)}function Pc({source:e,geometry:t,saving:n,error:r,onPick:i}){let{t:o}=Z(),s=t===`flag-only`,c=Mc(t);return a(`section`,{"aria-label":o(`device.detectionSourceControl.rootDetector`,`Root detector`),"aria-busy":n,className:`space-y-1.5 rounded-md border border-border bg-surface px-3 py-2`,children:[a(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1.5`,children:[d(`h3`,{className:j,children:o(`device.detectionSourceControl.rootDetector`,`Root detector`)}),d(it,{label:o(`device.detectionSourceControl.rootDetector`,`Root detector`),value:e,onChange:t=>{!n&&t!==e&&i(t)},options:[{value:`pipeline`,label:o(`device.detectionSourceControl.thisNode`,`This node`)},{value:`onboard`,label:o(`device.detectionSourceControl.cameraOnboardAi`,`Camera onboard AI`),disabled:s&&e!==`onboard`,reason:c},{value:`none`,label:o(`device.detectionSourceControl.none`,`None`)}]}),n&&d(`span`,{className:`text-[10px] text-foreground-subtle`,children:o(`device.detectionSourceControl.saving`,`Saving…`)})]}),a(`p`,{className:he,children:[jc(e),` `,o(`device.detectionSourceControl.oneRoot`)]}),c!==``&&d(`p`,{className:`text-[10px] text-foreground-subtle`,children:c}),r!==null&&d(`p`,{role:`alert`,className:`text-[11px] text-danger`,children:r})]})}e();var Fc=new Set([`package-detection`]);function Ic(e){return e?.settings!==void 0&&Object.keys(e.settings).length>0?`accelerator`:`camera`}function Lc(e){return e===`camera`?X.t(`device.cameraStepInspector.modelSource.camera`):e===`node`?X.t(`device.cameraStepInspector.modelSource.node`):X.t(`device.cameraStepInspector.modelSource.default`)}function Rc(e){let{stored:t,draft:n,below:r,boundKeys:i}=e,a=n?.modelId===void 0?t?.modelId:n.modelId??void 0,o=Me(n?.settings??t?.settings,r,i),s={...a===void 0?{}:{modelId:a},...o===void 0?{}:{settings:o}};return Object.keys(s).length>0?s:null}function zc(e,t){return(e?.modelId??null)===(t?.modelId??null)&&Pe(e?.settings??{},t?.settings??{})}function Bc({deviceId:e}){let{t}=Z(),i=c(),l=U().trpcClient,u=cr({deviceId:e},{refetchOnMount:`always`}),f=$n({deviceId:e},{refetchOnMount:`always`}),p=Dr(void 0,{refetchOnMount:`always`}),m=xe(mn({addonId:`pipeline-orchestrator`}).data??null);pr([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let{nodes:h}=ln(),g=n(()=>{let e=new Set((p.data??[]).map(e=>e.nodeId));return h.filter(t=>t.isOnline&&e.has(t.id)).map(e=>({id:e.id,name:e.name}))},[p.data,h]),_=g.map(e=>e.id).join(`,`),v=o({enabled:g.length>0,queryKey:[[`pipelineExecutor`,`getSchema`],`camera-step-schemas`,_],queryFn:async()=>{let e={};for(let t of g)try{e[t.id]=await l.pipelineExecutor.getSchema.query({nodeId:t.id})}catch{}return e}}),y=o({enabled:g.length>0,queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`],`camera-step`,_],queryFn:async()=>{let e={};for(let t of g)try{e[t.id]=(await l.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:t.id})).devices}catch{e[t.id]=[]}return e}}),b=()=>{i.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),i.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]})},x=Kt({onSuccess:b}),S=Wn(),C=Vt(),[w,T]=r(null),[E,D]=r(null),[O,k]=r(null),[A,M]=r(!1),[ee,N]=r(null),P=v.data??{},F=y.data??{},te=f.data??{},I=u.data??null,L=g.map(e=>P[e.id]).find(e=>e!==void 0)??null,R=n(()=>L?Nt(L):[],[L]),ne=n(()=>Ii(R),[R]),z=Tc(e),re=n(()=>z.source===null?new Set:Oc(z.source,R),[z.source,R]),[B,V]=r(!1),ie=n(()=>zi(g,F,B),[g,F,B]),ae=n(()=>zi(g,F,!0),[g,F]),oe=n(()=>zi(g,F).length,[g,F]),se=(e,t)=>Ai(P[e.nodeId],t),H=(e,t)=>te[e.nodeId]?.[e.deviceKey]?.[t],ce=(e,t)=>Wi(F[e.nodeId]??[],e.deviceKey,t)??{},le=e=>{if(Fc.has(e))return{kind:`zone-driven`};let t=Ai(L,e)?.enabledByDefault??!0,n=I?.stepToggles?.[e];return{kind:`gate`,effectiveOn:n??t,defaultOn:t,explicit:n!==void 0}},ue=(e,t,n)=>{let r=n?.stepId===t?n:null;return{node:ce(e,t),camera:r?.camera??I?.stepSettings?.[t],accelerator:r?.perAccelerator[e.id]?.settings??H(e,t)?.settings}},de=(e,t,n)=>{let r=n?.stepId===t?n.perAccelerator[e.id]?.modelId:void 0;return r===void 0?H(e,t)?.modelId:r??void 0},fe=(e,t)=>{if(re.has(e))return{kind:`disabled`};let n=se(t,e),r=le(e),i=Ri(e),a=ji(P[t.nodeId],t,H(t,`object-detection`)?.modelId),o=ue(t,e,null),s=Le(o.node,o.camera,o.accelerator);return Vi({addon:n,acc:t,gatedOn:r.kind===`gate`?r.effectiveOn:!0,model:n?Li(n,t,{nodePin:t.device.steps?.[e]?.modelId,cameraPin:H(t,e)?.modelId}):{modelId:void 0,source:`default`},...Pi(e,s,a)&&a?{rootName:a.name}:{},...i?{clusterModelId:m[e]??i.defaultModelId}:{}})},pe=ne.map(({node:e})=>({addonId:e.addonId,name:e.addonName,fieldLabels:Bi(Ai(L,e.addonId))}));return p.isLoading||g.length>0&&(v.isLoading||y.isLoading)?d(`div`,{className:`animate-pulse p-4 text-xs text-foreground-subtle`,children:t(`device.cameraStepInspector.loadingPipeline`,`Loading pipeline…`)}):g.length===0?d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:t(`device.cameraStepInspector.noPipelineNodeIsOnline`,`No pipeline node is online.`)}):L===null?d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:t(`device.cameraStepInspector.catalogUnavailable`,`Catalog unavailable.`)}):a(`div`,{className:`space-y-2`,children:[z.view?.onboard.available===!0&&z.source!==null&&d(Pc,{source:z.source,geometry:z.view.onboard.geometry,saving:z.saving,error:z.error,onPick:e=>void z.pick(e)}),d(ki,{tree:R,searchRows:pe,accelerators:ie,cellState:fe,stepBadge:e=>re.has(e)&&z.source!==null?d(en,{variant:`warning`,title:Nc(z.source,e),children:Ac(z.source,e)}):d(Mn,{gate:le(e)}),disabledCount:Ui(Object.fromEntries(g.map(e=>[e.id,F[e.id]??[]]))),showDisabled:B,onShowDisabledChange:V,dirty:w!==null,onDiscard:()=>T(null),summary:d(`span`,{className:he,children:t(`device.cameraStepInspector.balancedAcross`,{count:oe})}),label:t(`device.cameraStepInspector.detectionStepsOfThisCamera`,`Detection steps of this camera`),renderDetail:({stepId:n,accelerator:r,matchedField:i,closeButton:o,onEscape:c,headingRef:l})=>{let u=r??ie[0],f=u?se(u,n)??Ai(L,n):null;if(f===null||u===void 0)return d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:t(`device.cameraStepInspector.noStepSelected`,`No step selected.`)});let p=w?.stepId===n?w:null,m=Ot(f),h=Ge(m),g=ue(u,n,p),_=Le(g.node,g.camera,g.accelerator),v=ji(P[u.nodeId],u,H(u,`object-detection`)?.modelId),y=Li(f,u,{nodePin:u.device.steps?.[n]?.modelId,cameraPin:de(u,n,p)}).modelId,F=Le(g.node,g.camera),te=Be(g.accelerator,F,h),R=Ri(n),ne=le(n),B=m.find(e=>`label`in e&&e.label===i)?.key??null,V=r===null?null:`${n}|${r.id}`,oe=r===null?`camera`:E?.key===V?E.scope:Ic(H(r,n)),U=e=>{N(null),T(t=>e(t?.stepId===n?t:{stepId:n,perAccelerator:{}}))},fe=(e,t)=>U(n=>({...n,perAccelerator:{...n.perAccelerator,[e.id]:{...n.perAccelerator[e.id],...t}}})),pe=e=>U(t=>{let r=g.accelerator??{},i=Oe(t.camera??I?.stepSettings?.[n],e,r,h),a={...t.perAccelerator};for(let r of ae){let i=t.perAccelerator[r.id]?.settings??H(r,n)?.settings;i!==void 0&&(a[r.id]={...a[r.id],settings:Ue(i,e,h)})}return{...t,camera:i,perAccelerator:a}}),W=async()=>{if(p!==null){M(!0);try{let t=I?.stepSettings?.[n];p.camera!==void 0&&!Pe(p.camera,t??{})&&await C.mutateAsync({deviceId:e,addonId:n,settings:Object.keys(p.camera).length>0?{...p.camera}:null});let r=p.camera??t;for(let t of ae){let i=p.perAccelerator[t.id];if(i===void 0)continue;let a=H(t,n),o=Rc({stored:a,draft:i,below:Le(ce(t,n),r),boundKeys:h});zc(o,a)||await S.mutateAsync({deviceId:e,agentNodeId:t.nodeId,deviceKey:t.deviceKey,addonId:n,patch:o})}T(null),N({kind:`saved`})}catch(e){N({kind:`error`,error:e instanceof Error?e.message:t(`device.cameraStepInspector.saveFailed`)})}finally{M(!1),b()}}},me=p===null?0:+(p.camera!==void 0&&!Pe(p.camera,I?.stepSettings?.[n]??{}))+Object.values(p.perAccelerator).length,ge=e=>{let r=se(e,n)??f,i=de(e,n,p),a=e.device.steps?.[n]?.modelId,o=Li(r,e,{nodePin:a,cameraPin:i}),c=ue(e,n,p),l=ji(P[e.nodeId],e,H(e,`object-detection`)?.modelId),u=Pi(n,Le(c.node,c.camera,c.accelerator),l),m=Mi(r,e)?u&&l?d($t,{rootModel:l,stepModelId:o.modelId}):void 0:d(s,{children:t(`device.cameraStepInspector.noBuild`,{format:e.device.format})});return{label:e.label,format:e.device.format,modelId:o.modelId,source:o.source,sourceLabel:Lc(o.source),models:Tt(r.models??[],e.device.format),defaultModelId:r.defaultModelIdByFormat?.[e.device.format]??r.defaultModelId,expanded:O===e.id,onToggle:()=>k(t=>t===e.id?null:e.id),onChangeModel:t=>fe(e,{modelId:t}),...i===void 0?{}:{onReset:()=>fe(e,{modelId:null}),resetLabel:a===void 0?`Reset to hardware default`:`Reset to node pin`},...m===void 0?{}:{note:m},changed:p?.perAccelerator[e.id]?.modelId!==void 0}},_e=R===null&&m.length>0?r===null?d(`p`,{className:he,children:t(`device.cameraStepInspector.appliesToAllAcceleratorsOf`,`Applies to: all accelerators of this camera.`)}):a(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`span`,{className:`text-[11px] font-medium text-foreground`,children:t(`device.cameraStepInspector.appliesTo`,`Applies to`)}),d(it,{label:t(`device.cameraStepInspector.settingsApplyTo`,`Settings apply to`),options:[{value:`accelerator`,label:t(`device.cameraStepInspector.thisAccelerator`,`This accelerator`)},{value:`camera`,label:t(`device.cameraStepInspector.allAcceleratorsOfThisCamera`,`All accelerators of this camera`)}],value:oe,onChange:e=>V!==null&&D({key:V,scope:e})})]}):void 0;return d(gn,{ref:l,title:r===null?t(`device.cameraStepInspector.thisCamera`,`{{name}} · this camera`,{name:f.name}):`${f.name} · ${r.label}`,subtitle:r===null?t(`device.cameraStepInspector.everyAcceleratorThisCameraRuns`,`{{slot}} · every accelerator this camera runs on`,{slot:f.slot}):`${f.slot} · ${r.device.format}`,leading:o,onEscape:c,headerActions:d(br,{gate:ne,busy:x.isPending,onSet:t=>x.mutate({deviceId:e,addonId:n,enabled:t})}),saveBar:{dirtyCount:me,saving:A,status:ee?.kind??null,...ee?.error===void 0?{}:{error:ee.error},onSave:()=>void W(),onDiscard:()=>T(null),..._e===void 0?{}:{scope:_e}},children:a(`div`,{className:`space-y-3`,children:[re.has(n)&&z.source!==null&&d(`p`,{role:`note`,className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-1.5 text-[11px] text-warning`,children:Nc(z.source,n)}),a(`section`,{className:`space-y-2`,"aria-label":t(`device.cameraStepInspector.model`,`Model`),children:[d(`h3`,{className:j,children:t(`device.cameraStepInspector.model`,`Model`)}),R===null?r===null?d(Ni,{rows:ie.map(e=>{let t=Li(se(e,n)??f,e,{nodePin:e.device.steps?.[n]?.modelId,cameraPin:de(e,n,p)});return{id:e.id,label:e.label,modelId:t.modelId,sourceLabel:Lc(t.source)}})}):d(jt,{...ge(r)},r.id):d(Hi,{step:R,engineFormat:u.device.format,runnableModelIds:Tt(f.models??[],u.device.format).map(e=>e.id)})]}),R===null&&(m.length>0||v!==void 0)&&d(`section`,{"aria-label":t(`device.cameraStepInspector.settings`,`Settings`),className:`border-t border-border/60 pt-2`,children:d(Vc,{addon:f,fields:m,layers:g,scope:oe,viewed:r,modelId:ht(f,y,_,v),root:v,pinned:r===null?[]:te,highlightKey:B,onChangeCamera:e=>U(t=>({...t,camera:e})),onChangeAccelerator:e=>fe(u,{settings:e}),onApplyToAll:pe,onFollowNode:()=>fe(u,{settings:te.reduce((e,t)=>Ue(e,t,h),{...g.accelerator})})})}),d(Oi,{addonId:n,highlightLabel:i})]})})}})]})}function Vc({addon:e,fields:t,layers:n,scope:r,viewed:i,modelId:a,root:o,pinned:s,highlightKey:c,onChangeCamera:l,onChangeAccelerator:u,onApplyToAll:f,onFollowNode:p}){let{t:m}=Z();Fi(c===null?null:rn(c));let h=i!==null&&n.accelerator!==void 0;return d(Lt,{addon:e,fields:t,layers:{node:n.node,...n.camera===void 0?{}:{camera:n.camera},...h?{accelerator:n.accelerator}:{}},target:r,labels:{...i===null?{}:{accelerator:`This accelerator`},camera:`All accelerators`,node:`Node`},modelId:a,...o===void 0?{}:{rootModel:o},pinnedKeys:s,highlightKey:c,onChangeLayer:r===`camera`?l:u,...s.length>0?{headerActions:d(`button`,{type:`button`,className:oe,onClick:p,children:m(`device.cameraStepInspector.followNode`,{count:s.length})})}:{},fieldActions:(e,t)=>i!==null&&t===`accelerator`?d(`button`,{type:`button`,className:oe,onClick:()=>f(e),children:m(`device.cameraStepInspector.applyToAllAccelerators`,`Apply to all accelerators`)}):null})}function Hc(e,t,n){return{id:e,get label(){return X.t(t)},icon:n}}var Uc=[Hc(`object-detection`,`helpers.detectionSettingsGroups.objectDetection`,`scan-search`),Hc(`tracking`,`helpers.detectionSettingsGroups.tracking`,`route`),Hc(`motion`,`helpers.detectionSettingsGroups.motion`,`activity`),Hc(`stationary`,`helpers.detectionSettingsGroups.stationary`,`square-parking`),Hc(`zones`,`helpers.detectionSettingsGroups.zones`,`shapes`),Hc(`audio`,`helpers.detectionSettingsGroups.audio`,`volume-2`),Hc(`cluster`,`helpers.detectionSettingsGroups.cluster`,`server`)],Wc={"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 Gc(e){return Wc[e]??`object-detection`}e();var Kc=`steps`,qc=`settings`,Jc=new Set([Kc,qc]);function Yc(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}function Xc({deviceId:e,activeSubTab:t,onSubTabChange:n}){let{t:r}=Z();return a(ut,{value:t&&Jc.has(t)?t:Kc,onValueChange:i(e=>{n?.(e)},[n]),className:`flex flex-col`,children:[a(Yn,{className:`flex-shrink-0`,children:[d(st,{value:Kc,children:r(`device.detectionPipelineTab.steps`,`Steps`)}),d(st,{value:qc,children:r(`device.detectionPipelineTab.settings`,`Settings`)})]}),d(Xt,{value:Kc,children:d(Bc,{deviceId:e})}),d(Xt,{value:qc,children:d(Qr,{deviceId:e,sectionFilter:Yc,subTabGrouping:{groupOf:e=>Gc(e.id),tabs:Uc}})})]})}var Zc=`Notifications`,Qc=`This camera never notifies — no rule, no target, no alarm. Existing events, tracks and recordings are unaffected.`;function $c(e){let{mutedDeviceIds:t,deviceId:n}=e,r=t===null?null:!t.includes(n),i=e.pendingOn??null;return{label:Zc,on:r===null?null:i??r,available:r!==null,costWhenOff:Qc}}function el(e,t){return!e.available||e.on===null?null:{deviceId:t,muted:e.on}}e();function tl(e){if(typeof e!=`object`||!e)return null;let t={...e}.mutedDeviceIds;return Array.isArray(t)?t.filter(e=>typeof e==`number`):null}function nl({deviceId:e}){let{t}=Z(),n=c(),o=Number.isFinite(e),[s,l]=r(null),[u,f]=r(null),p=$c({mutedDeviceIds:tl(gt({},{enabled:o}).data),deviceId:e,pendingOn:u}),m=zt({onError:t=>{console.error(`[DeviceNotificationMute] mute write failed — reverting`,{tags:{deviceId:e},meta:{error:t instanceof Error?t.message:String(t)}}),f(null),l(t instanceof Error?t.message:String(t)),n.invalidateQueries({queryKey:[[`notificationRules`,`listDeviceMutes`]]})},onSuccess:()=>{l(null),f(null),n.invalidateQueries({queryKey:[[`notificationRules`]]})}}),h=i(()=>{let t=el(p,e);t!==null&&(f(!t.muted),m.mutate(t))},[e,m,p]),g=p.on===null,_=p.on===!1,v=_?$e:ge;return a(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[a(`div`,{className:`border-b border-border px-4 py-2 flex items-center justify-between gap-2`,children:[d(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:t(`device.deviceNotificationMute.notifications`,`Notifications`)}),_&&d(`span`,{className:`rounded bg-warning/20 px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wide text-warning`,children:t(`common.muted`)})]}),a(`div`,{className:`px-4 py-3 flex items-start gap-3`,children:[a(`button`,{type:`button`,role:`switch`,"aria-label":p.label,"aria-checked":p.on===!0,disabled:!p.available||m.isPending,onClick:h,title:g?t(`device.deviceNotificationMute.notificationMuteStateUnknownThe`,`Notification mute — state unknown; the notification centre did not answer.`):_?t(`device.deviceNotificationMute.muted`,`Muted. {{costWhenOff}}`,{costWhenOff:p.costWhenOff}):t(`device.deviceNotificationMute.notifyingMutingIt`,`Notifying. Muting it: {{costWhenOff}}`,{costWhenOff:p.costWhenOff}),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 ${s===null?g?`border-dashed border-border text-foreground-subtle/50`:_?`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:[d(v,{className:`h-3.5 w-3.5`}),d(`span`,{children:g?t(`device.deviceNotificationMute.unknown`,`Unknown`):_?t(`device.deviceNotificationMute.muted2`,`Muted`):t(`device.deviceNotificationMute.notifying`,`Notifying`)})]}),d(`p`,{className:`flex-1 text-[11px] leading-relaxed text-foreground-subtle`,children:s===null?g?t(`device.deviceNotificationMute.theNotificationCentreDidNot`,`The notification centre did not answer, so this device’s mute state is unknown.`):p.costWhenOff:t(`device.deviceNotificationMute.writeFailed`,`Write failed: {{failure}}`,{failure:s})})]})]})}function rl(e,t){return{switchId:e,label:We[e].label,detail:t===void 0||t.length===0?null:t}}function il(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 al(e){let t=il(e),n=new Set(e.sourceStillLive),r=e.sourceStillLive.map(e=>rl(e,t.get(e)?.detail)),i=[...t.values()].filter(e=>e.outcome===`not-offered`&&!n.has(e.switchId)).map(e=>rl(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}}e();function ol(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 sl({deviceId:e,deviceName:t}){let{t:i}=Z(),o=pt(),[s,c]=r(null),l=bt({isCamera:!0,projection:`slim`}),u=vn(),f=l.data!==void 0,p=n(()=>l.data===void 0?[]:ol(l.data,e),[l.data,e]),m=p.find(e=>e.id===s)??null,h=u.data===void 0?null:al(u.data),g=u.error===null?null:u.error.message,_=async()=>{m===null||m.id===e||await o({title:i(`deviceMigrate.confirmTitle`,`Replace “{{source}}” with “{{target}}”?`,{source:t,target:m.name}),message:i(`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:t,target:m.name,sourceId:e,targetId:m.id}),confirmLabel:i(`deviceMigrate.confirmAction`,`Migrate`),variant:`danger`})&&u.mutate({sourceId:e,targetId:m.id})};return a(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[a(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[a(`div`,{className:`min-w-0`,children:[d(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:i(`deviceMigrate.title`,`Migrate to…`)}),d(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:i(`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:e})})]}),a(`div`,{className:`flex shrink-0 items-center gap-2`,children:[a(`select`,{"aria-label":i(`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||u.isPending,value:s===null?``:String(s),onChange:e=>{let t=e.target.value;c(t===``?null:Number(t))},children:[d(`option`,{value:``,children:f?i(`deviceMigrate.pickerPlaceholder`,`Select a camera…`):i(`deviceMigrate.pickerPending`,`Reading the fleet…`)}),p.map(e=>a(`option`,{value:String(e.id),children:[e.name,` (#`,e.id,`)`]},e.id))]}),a(`button`,{type:`button`,disabled:m===null||u.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:[d(Ye,{className:`h-3 w-3`}),u.isPending?i(`deviceMigrate.running`,`Migrating…`):i(`deviceMigrate.action`,`Migrate`)]})]})]}),f&&p.length===0&&d(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:i(`deviceMigrate.noTargets`,`No other camera is adopted, so there is nothing to migrate to.`)}),g!==null&&d(`p`,{className:`mt-2 text-[11px] text-danger`,children:i(`deviceMigrate.failed`,`Migration failed: {{error}}`,{error:g})}),h!==null&&d(cl,{report:h})]})}function cl({report:e}){let{t}=Z(),n=e.verdict===`quiet`;return a(`div`,{className:`mt-3 space-y-2 border-t border-border pt-3`,children:[d(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`deviceMigrate.swapped`,`The replacement now answers on number {{inheritedId}}; the old camera was handed number {{retiredId}}.`,{inheritedId:e.inheritedId,retiredId:e.retiredId})}),n?a(`div`,{className:`flex items-start gap-2 rounded-md border border-success/30 bg-success/5 px-3 py-2`,children:[d(se,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-success`}),d(`p`,{className:`text-[11px] leading-relaxed text-foreground`,children:t(`deviceMigrate.quiet`,`Every function on the replaced camera was switched off — the old hardware is quiet.`)})]}):a(`div`,{className:`rounded-md border border-warning/40 bg-warning/5 px-3 py-2`,children:[a(`div`,{className:`flex items-start gap-2`,children:[d(W,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`}),d(`p`,{className:`text-[11px] leading-relaxed text-foreground`,children:t(`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.`)})]}),d(`ul`,{className:`mt-2 space-y-1 pl-5`,children:e.stillLive.map(e=>a(`li`,{className:`text-[11px] text-foreground`,children:[d(`span`,{className:`font-medium`,children:e.label}),e.detail!==null&&a(`span`,{className:`text-foreground-subtle`,children:[` — `,e.detail]})]},e.switchId))})]}),e.neverOffered.length>0&&a(`div`,{className:`rounded-md border border-border px-3 py-2`,children:[a(`div`,{className:`flex items-start gap-2`,children:[d(nt,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),d(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`deviceMigrate.neverOffered`,`The replaced camera never offered these, so there was nothing to switch off. They are not running.`)})]}),d(`ul`,{className:`mt-2 space-y-1 pl-5`,children:e.neverOffered.map(e=>d(`li`,{className:`text-[11px] text-foreground-subtle`,children:e.label},e.switchId))})]})]})}e();function ll({deviceId:e}){let{t}=Z(),[n,i]=r(null),o=Yt({onSuccess:e=>{i(e.changed?`Re-aligned with source — ${e.rebuiltChildren} child${e.rebuiltChildren===1?``:`ren`} rebuilt.`:`Already up to date.`)},onError:e=>i(`Re-sync failed: ${e.message}`)});return a(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[a(`div`,{className:`flex items-center justify-between gap-3`,children:[a(`div`,{children:[d(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:t(`device.resyncButton.reSync`,`Re-sync`)}),d(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:t(`device.resyncButton.reAlignThisDeviceS`,`Re-align this device's type, role, capabilities and units with its source.`)})]}),a(`button`,{type:`button`,disabled:o.isPending,onClick:()=>{i(null),o.mutate({camDeviceId:e})},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:[d(R,{className:`h-3 w-3 ${o.isPending?`animate-spin`:``}`}),o.isPending?t(`device.resyncButton.reSyncing`,`Re-syncing…`):t(`device.resyncButton.reSync`,`Re-sync`)]})]}),n!==null&&d(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:n})]})}function ul(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function dl({device:e}){let{t}=Z(),n=Yr(),r=typeof e.id==`number`?e.id:null,i=String(e.type??``),o=i===q.Camera,s=i===q.Hub,c=e.features??[],l=c.includes(Se.Resyncable),{data:u}=dt({deviceId:r??0},{enabled:r!==null&&o,refetchInterval:5e3}),f=u?.streams??{},p=Object.entries(f),m=c.includes(Se.DoorbellButton),h=Hn(m?{deviceId:r??void 0,historyLimit:10}:void 0),g=h.latest?Date.now()-h.latest.timestamp<3e4:!1;return a(`div`,{className:`space-y-5`,children:[s&&r!==null&&d(En,{deviceId:r,onOpenChild:e=>n(`/devices/${e}`)}),l&&r!==null&&d(ll,{deviceId:r}),o&&r!==null&&d(sl,{deviceId:r,deviceName:String(e.name??``)}),r!==null&&d(nl,{deviceId:r}),o&&r!==null&&d(yn,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:r}),m&&d(Ar,{history:h.history,latestIsFresh:g}),o&&r!==null&&d(yn,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:r}),o&&p.length>0&&a(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[d(`div`,{className:`border-b border-border px-4 py-2`,children:d(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:t(`device.overviewTab.streamNetwork`,`Stream Network`)})}),d(`div`,{className:`divide-y divide-border`,children:p.map(([e,n])=>a(`div`,{className:`px-4 py-2.5`,children:[a(`div`,{className:`flex items-center gap-2 mb-2`,children:[d(ie,{className:`h-3 w-3 text-foreground-subtle`}),d(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),a(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[d(fl,{label:t(`device.overviewTab.nominal`,`Nominal`),value:ul(n.nominalBitrateKbps??0)}),d(fl,{label:t(`device.overviewTab.observed`,`Observed`),value:ul(n.observedBitrateKbps??0)}),d(fl,{label:t(`device.overviewTab.peak`,`Peak`),value:ul(n.peakBitrateKbps??0)}),d(fl,{label:t(`device.overviewTab.packetLoss`,`Packet Loss`),value:`${(n.packetLossPercent??0).toFixed(2)}%`,warning:(n.packetLossPercent??0)>1})]})]},e))})]}),d(Fr,{}),r!==null&&d(Nr,{deviceId:r})]})}function fl({label:e,value:t,warning:n}){return a(`div`,{children:[d(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),d(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}var pl=`history`,ml=[{id:`overview`,labelKey:`helpers.structuralTabs.overview`,cameraOnly:!1,adminOnly:!1},{id:`config`,labelKey:`helpers.structuralTabs.config`,cameraOnly:!1,adminOnly:!1},{id:Zr,labelKey:`helpers.structuralTabs.customize`,cameraOnly:!1,adminOnly:!0},{id:pl,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}],hl=new Set([q.Hub,q.Container]);function gl(e,t){let n=e===q.Camera,r=e===void 0||!hl.has(e);return ml.filter(e=>(n||!e.cameraOnly)&&(t||!e.adminOnly)&&(r||e.id!==`history`)).map(({id:e,labelKey:t})=>({id:e,label:X.t(t)}))}function _l({provider:e,integrationId:t,name:n}){let r=Yr(),i=t===null?`/integrations`:`/integrations/${t}`,a=n===null?`Open integrations`:`Open integration ${n}`;return d(`button`,{type:`button`,onClick:()=>r(i),className:`shrink-0 rounded-md transition-opacity hover:opacity-80 focus:outline-none focus-visible:ring-1 focus-visible:ring-primary/50`,title:a,"aria-label":a,children:d(qr,{type:e,size:`lg`})})}e();var vl=[{id:`logs`,icon:le,labelKey:`common.logs`},{id:`repl`,icon:tt,labelKey:`deviceDetail.repl`},{id:`events`,icon:D,labelKey:`common.events`},{id:`state`,icon:P,labelKey:`common.state`}];function yl(){let{t:e}=Z(),t=ni(),o=Number(t.deviceId),u=Number.isFinite(o),f=Yr(),p=c(),m=pt(),h=U(),{user:_}=Wr(),v=_?.isAdmin===!0,[y,x]=$r(),S=y.get(`tab`)??`overview`,C=y.get(`sub`),[w,T]=r(`logs`),D=`device-detail.left-col-width-px`,[O,k]=r(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(D),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),A=l(O);A.current=O;function j(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??O??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{k(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=A.current;if(e!==null)try{window.localStorage.setItem(D,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:N,isError:P}=un({deviceId:o},{enabled:u,refetchInterval:5e3,retry:1}),{data:F}=Ct({deviceId:o},{enabled:u}),te=n(()=>{let e=F?.settings?.sections??[],t=F?.live?.sections??[],n=[...e,...t],r=new Set;for(let e of n)e.location===`top-tab`&&e.tab&&r.add(e.tab===`zones`?`detection-pipeline`:e.tab);return n.some(Ir)&&r.add(Vr),[...r].map(e=>e===`export`?{id:e,label:Pr,isAddonContrib:!0}:{id:e,label:Te[e]?.label??e,isAddonContrib:!0})},[F]),I=M,L=String(I?.name??t.deviceId??`Device`),ne=I?.online===!0,z=ne?`online`:`offline`,re=String(I?.addonId??`rtsp`),B=I?.features??[],V=I?.type,ie=V===q.Camera,{data:ae}=Gr(u?o:0),oe=V===q.Container,se=n(()=>(ae??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[ae]),H=n(()=>oe?Et(se,typeof I?.linkDeviceId==`number`?I.linkDeviceId:null,typeof I?.primaryChildEntityId==`string`?I.primaryChildEntityId:null)?.id??null:null,[oe,se,I?.linkDeviceId,I?.primaryChildEntityId]),{data:ce}=Ct({deviceId:H??0},{enabled:H!==null}),le=n(()=>{if(H===null)return[];let e=ce?.settings?.sections??[],t=ce?.live?.sections??[],n=new Set;for(let r of[...e,...t])r.location===`top-tab`&&r.tab&&n.add(r.tab);return[...n].map(e=>({id:e,label:Te[e]?.label??e,isAddonContrib:!0,childDeviceId:H}))},[H,ce]),ue=typeof I?.parentDeviceId==`number`?I.parentDeviceId:null,{data:fe}=un({deviceId:ue??0},{enabled:ue!==null}),W=vt(),me=I?.disabled!==!0,he=n(()=>{let e=F?.settings?.sections??[],t=F?.live?.sections??[];return zr([...e,...t],V,v,F!==void 0)},[F,V,v]),ge=n(()=>{let e=new Set,t=[];for(let n of[...gl(V,v),...te,...le])n.id===`config`&&!he||e.has(n.id)||(e.add(n.id),t.push(n));return t},[V,v,te,le,he]),_e=n(()=>vc(ge,S),[ge,S]),ve=i(e=>{x(t=>{let n=new URLSearchParams(t);e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`);for(let e of Gi)n.delete(e);return n},{replace:!0})},[x]),ye=i(e=>{x(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[x]),G=(ae??[]).length>0,be=n(()=>vl.filter(({featureGate:e})=>!e||B.includes(e)),[B]),{data:xe}=jr(void 0),Ce=n(()=>I?Xn(I,xe):null,[I,xe]),K=Ce?.kind===`resolved`?Ce.integration:null,we=K===null?Ce?.kind===`unknown`?e(`deviceDetail.loadingIntegration`):Ce?.kind===`orphan`?e(`deviceDetail.missingIntegration`):e(`deviceDetail.noIntegration`):K.name,Ee=K!==null&&K.addonId===re?K.name:re,De=An({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]}),f(K?.id?`/integrations/${K.id}`:`/integrations`)}}),J=It({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Oe=Bt({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ke=mr(),Ae=On({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),je=B.includes(Se.Rebootable),Me=B.includes(Se.BatteryOperated),Ne=At(h.trpcClient,Me&&u?o:null),Pe=_t(h.trpcClient,u?o:null),[Fe,Ie]=r(!1),Le=async()=>{if(!Fe){Ie(!0);try{let e=L.replace(/[^a-zA-Z0-9_.-]+/g,`_`),t=new Date().toISOString().replace(/[:.]/g,`-`);await oa(`${ee}/${String(o)}.jpg?force=1`,`${e}-${t}.jpg`)}finally{Ie(!1)}}},Re=J.isPending||Oe.isPending,{data:ze}=tr({deviceId:o},{enabled:u&&ie,refetchInterval:1e4}),Be=ze?.agentNodeId??null,Ve=typeof Be==`string`&&Be.length>0&&!Be.startsWith(`addon:`)?Be:void 0,{data:He}=wt({deviceId:o,...Ve?{nodeId:Ve}:{}},{enabled:u&&ie,refetchInterval:3e3,retry:!1}),{data:Ue}=Cr({deviceId:o},{enabled:u&&ie,refetchInterval:3e3,retry:!1}),We=Ue?.level?.dbfs??null;function Ge(){if(!u)return null;switch(_e){case`overview`:return d(dl,{device:I??{}});case`config`:return d(Cc,{deviceId:o,activeSubTab:C,onSubTabChange:ye,deviceType:V,isAdmin:v});case`detection-pipeline`:return d(Xc,{deviceId:o,activeSubTab:C,onSubTabChange:ye});case`bindings`:return d(yc,{deviceId:o});case pl:return d(Qn,{deviceId:o,onNavigate:e=>f(e)});case Zr:return d(dc,{deviceId:o,activeSubTab:C,onSubTabChange:ye});default:{let e=_e,t=te.some(t=>t.id===e),n=le.find(t=>t.id===e);if(!t&&n===void 0)return null;let r=n?.childDeviceId??o;if(e===`export`)return d(Qr,{deviceId:o,sectionFilter:Ir,activeSubTab:C,onSubTabChange:ye});let i=d(Qr,{deviceId:r,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:C,onSubTabChange:ye});return n!==void 0&&r!==o?d(Tr,{deviceId:r,children:i}):i}}}return u?N?a(`div`,{className:`flex flex-col h-full`,children:[a(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[d(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),d(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),d(`div`,{className:`flex-1 p-6`,children:d(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):P||!M?a(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[d(`p`,{className:`text-lg font-semibold text-foreground`,children:e(`deviceDetail.deviceNotFound`,`Device not found`)}),d(`p`,{className:`text-xs`,children:d(Jr,{i18nKey:`deviceDetail.noDeviceWithId`,values:{id:o},components:{code:d(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`})}})}),d(`button`,{onClick:()=>f(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:e(`deviceDetail.backToIntegrations`,`Back to Integrations`)})]}):a(`div`,{className:`absolute inset-0 flex flex-col overflow-clip`,children:[a(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[d(`div`,{className:`mb-2`,children:d(Or,{items:[{label:e(`deviceDetail.integrations`,`Integrations`),onClick:()=>f(`/integrations`)},K===null?{label:we}:{label:we,onClick:()=>f(`/integrations/${K.id}`)},{label:L}]})}),a(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[K!==null&&d(_l,{provider:K.addonId,integrationId:K.id,name:K.name}),a(`div`,{className:`min-w-0 flex-1`,children:[a(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[d(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:L}),d(ar,{status:z}),Me&&d(on,{status:Ne,variant:`full`}),d(wr,{status:Pe})]}),ue!==null&&fe&&a(`button`,{type:`button`,onClick:()=>f(`/devices/${ue}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:e(`deviceDetail.openParentDevice`,`Open parent device {{name}}`,{name:fe.name}),children:[d(`span`,{children:`↑`}),d(`span`,{className:`truncate`,children:String(fe.name??`Device #${ue}`)})]}),d(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:B.length>0&&d(Kr,{capabilities:B})})]}),He&&d(`div`,{className:`hidden lg:flex`,children:d(bl,{metrics:He,dbfs:We})}),a(`div`,{className:`flex items-center gap-1 shrink-0`,children:[a(`button`,{onClick:async()=>{me?await m({title:e(`deviceDetail.disable`,`Disable "{{name}}"?`,{name:L}),message:e(`deviceDetail.theDeviceWillStopProcessing`,`The device will stop processing streams and events. You can re-enable it later.`),confirmLabel:e(`common.disable`,`Disable`),variant:`danger`})&&Oe.mutate({deviceId:o}):J.mutate({deviceId:o})},disabled:Re,title:me?e(`deviceDetail.disableDevice`,`Disable device`):e(`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 ${me?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[d(g,{className:`h-3.5 w-3.5`}),d(`span`,{className:`hidden sm:inline`,children:Re?e(`deviceDetail.updating`,`Updating…`):me?e(`deviceDetail.enabled`,`Enabled`):e(`deviceDetail.disabled`,`Disabled`)})]}),d(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),ie&&a(s,{children:[d(pa,{deviceId:o}),d(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`})]}),d(ha,{deviceId:o}),d(Bn,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:e(`deviceDetail.takeSnapshot`,`Take snapshot`),description:e(`deviceDetail.fetchAFreshFrameAnd`,`Fetch a fresh frame and download it.`),icon:E,disabled:Fe,onClick:()=>{Le()}},{id:`reboot`,label:e(`deviceDetail.rebootDevice`,`Reboot device`),description:e(`deviceDetail.cameraGoesOfflineFor30`,`Camera goes offline for ~30 seconds.`),icon:pe,hidden:!je,disabled:ke.isPending,danger:!0,onClick:async()=>{await m({title:e(`deviceDetail.reboot`,`Reboot "{{name}}"?`,{name:L}),message:e(`deviceDetail.theCameraWillGoOffline`,`The camera will go offline for around 30 seconds while the firmware reboots.`),confirmLabel:e(`deviceDetail.reboot2`,`Reboot`),variant:`danger`})&&ke.mutate({deviceId:o})}},{id:`restart-addon`,label:e(`deviceDetail.restartAddon`,`Restart addon`),description:e(`deviceDetail.bouncesEveryDeviceServedBy`,`Bounces every device served by {{servingAddonLabel}}.`,{servingAddonLabel:Ee}),icon:R,disabled:Ae.isPending,danger:!0,onClick:async()=>{await m({title:e(`deviceDetail.restart`,`Restart "{{servingAddonLabel}}"?`,{servingAddonLabel:Ee}),message:e(`deviceDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device served by it (not just "{{name}}"). Streams will reconnect automatically.`,{name:L}),confirmLabel:e(`deviceDetail.restart2`,`Restart`),variant:`danger`})&&Ae.mutate({addonId:re})}},{id:`delete`,label:e(`deviceDetail.deleteDevice`,`Delete device`),description:e(`deviceDetail.removeTheDeviceAndAll`,`Remove the device and all its settings.`),icon:b,separatorBefore:!0,disabled:De.isPending,danger:!0,onClick:async()=>{await m({title:e(`deviceDetail.delete`,`Delete "{{name}}"?`,{name:L}),message:e(`deviceDetail.thisWillRemoveTheDevice`,`This will remove the device and all its settings. This action cannot be undone.`),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&De.mutate({deviceId:o})}}]})]})]})]}),d(Tr,{deviceId:o,device:I??void 0,children:d(kn,{children:d(wn,{children:d(de,{children:d(Dn,{children:a(`main`,{className:W?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[a(`div`,{className:W?`flex flex-col bg-surface`:`${O===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!W&&O!==null?{width:`${String(O)}px`}:void 0,children:[d(`div`,{className:ie?`flex-shrink-0 border-b border-border-subtle bg-black`:W?`flex-shrink-0 border-b border-border-subtle bg-surface`:`max-h-[55%] shrink-0 overflow-y-auto border-b border-border-subtle bg-surface`,children:ie?d(Ya,{deviceId:o,intercomAvailable:B.includes(Se.TwoWayAudio)}):d(za,{deviceId:o,deviceName:L,deviceType:V??`unknown`,provider:re,isOnline:ne,features:B})}),a(`div`,{className:W?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[d(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:d(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:be.map(({id:t,labelKey:n,icon:r})=>{let i=w===t;return a(`button`,{onClick:()=>T(t),title:e(n),className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${i?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[d(r,{className:`h-3 w-3`}),e(n)]},t)})})}),a(`div`,{className:W?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[w===`logs`&&d(Xa,{deviceId:o,containerDeviceId:V===`container`?o:void 0}),w===`repl`&&d(Za,{deviceId:o}),w===`events`&&d(Qa,{deviceId:o}),w===`state`&&d($a,{deviceId:o})]})]})]}),!W&&d(`div`,{role:`separator`,"aria-orientation":`vertical`,title:e(`deviceDetail.dragToResize`,`Drag to resize`),onMouseDown:j,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:d(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),a(`div`,{className:W?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[d(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:d(`div`,{className:`flex flex-nowrap overflow-x-auto md:flex-wrap md:overflow-x-visible items-center gap-0`,children:ge.map(e=>{let t=_e===e.id;return a(`button`,{onClick:()=>ve(e.id),className:`relative flex-shrink-0 px-3 py-2 text-xs font-medium transition-colors ${t?`text-primary`:`text-foreground-subtle hover:text-foreground`}`,children:[e.label,t&&d(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),a(`div`,{className:W?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[_e===`overview`&&G&&d(ga,{parentDeviceId:o}),Ge()]})]})]})})})})})})]}):a(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[d(`p`,{className:`text-lg font-semibold text-foreground`,children:e(`deviceDetail.invalidDeviceId`,`Invalid device id`)}),d(`p`,{className:`text-xs`,children:d(Jr,{i18nKey:`deviceDetail.invalidSegment`,values:{segment:t.deviceId},components:{code:d(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`})}})}),d(`button`,{onClick:()=>f(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:e(`deviceDetail.backToIntegrations`,`Back to Integrations`)})]})}function bl({metrics:e,dbfs:t}){let n=ne(),{t:r}=Z(),i=Cn(e.phase??`idle`,n);return a(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[a(`div`,{className:`flex items-center gap-1.5`,children:[d(`span`,{className:`h-1.5 w-1.5 rounded-full ${i.dotClass}`}),d(`span`,{className:`text-[10px] font-medium ${i.textColor}`,children:i.label})]}),d(`div`,{className:`h-3 w-px bg-border`}),a(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[d(H,{className:`h-3 w-3`}),d(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),d(`span`,{children:r(`common.fpsWord`)})]}),a(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[d(te,{className:`h-3 w-3`}),d(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),d(`span`,{children:`ms`})]}),a(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:r(`deviceDetail.currentAudioLevelDbfs`,`Current audio level (dBFS)`),children:[d(k,{className:`h-3 w-3`}),d(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),d(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&a(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{yl as DeviceDetailPage};
@@ -1 +1 @@
1
- import{$ as e,G as t,S as n,a as r,x as i}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{ot as a}from"./player-overlays-DyNPyo_W.js";import{Gt as o,Jt as s,Kt as c,Wt as l,Xt as u,Yt as d,Zt as f,qt as p}from"./client-CRCWO8cg.js";import{F as m}from"./src-D9dVviCd.js";import{t as h}from"./i18n-DzruZdmx.js";import{t as g}from"./useTranslation-D3Is_4B6.js";import"./notification-schedule-field-DSAH7QIn.js";e();var _=6e4;function v(e){let t=a();return r({queryKey:[`device-do-action`,`bound-caps`,e],enabled:e>0,staleTime:_,queryFn:async()=>{let n=await t.trpcClient.deviceManager.getBindings.query({deviceId:e});return[...new Set(n.entries.map(e=>e.capName))].sort((e,t)=>e.localeCompare(t))}})}function y(e){let t=a(),n=[...new Set(e.filter(e=>e>0))].sort((e,t)=>e-t);return r({queryKey:[`device-do-action`,`bound-caps-batch`,n],enabled:n.length>0,staleTime:_,queryFn:async()=>{let e=await t.trpcClient.deviceManager.getBindingsBatch.query({deviceIds:n}),r=new Map;for(let t of e)r.set(t.deviceId,[...new Set(t.entries.map(e=>e.capName))].sort((e,t)=>e.localeCompare(t)));return r}})}var b=`mt-1 w-full rounded border border-border bg-background px-2 py-1 text-xs`,x=`block text-[11px] font-medium text-foreground`,S=`deviceId`;function C(e,t){return t.length===0?0:t.length===1?t[0]:t.find(t=>!e.includes(t))??t[t.length-1]}function w(e,t,n){if(t.length===0)return[];if(t.length===1)return t;let r=t.find(t=>!e.includes(t));if(r===void 0)return t;let i=n(r);if(i===void 0)return[r];let a=e[0]??t.find(e=>e!==r);if(a===void 0)return[r];let o=n(a);return o===void 0||!f(o,i)?[r]:t.filter(e=>{let t=n(e);return t!==void 0&&f(o,t)})}function T(e){return e.length===0?0:e.length===1?e[0]:[...e]}function E(e){return typeof e==`number`?e>0?[e]:[]:Array.isArray(e)?e.filter(e=>e>0):[]}function D(e,t){return{deviceId:e,cap:t.cap,method:t.method,...t.args===void 0?{}:{args:{...t.args}}}}function O(e,t){return h.t(`deviceDoAction.customLabel`,{name:`${e}.${t}`})}function k({value:e,onChange:r,devices:a,listState:h,fleet:_,allowTriggerDevice:k=!1,allowMultiSameFamily:A=!1,testId:j=`device-do-action`}){let{t:M}=g(),N=typeof e.deviceId!=`number`&&!Array.isArray(e.deviceId),P=E(e.deviceId),F=t(()=>a.filter(e=>d(String(e.type??``))),[a]),I=t(()=>{let e=new Map;for(let t of F)t.type!==void 0&&t.type!==null&&e.set(t.id,String(t.type));return e},[F]),L=t(()=>{if(!A||P.length===0)return F;let e=I.get(P[0]);return e===void 0?F:F.filter(t=>{if(P.includes(t.id))return!0;let n=t.type!==void 0&&t.type!==null?String(t.type):void 0;return n!==void 0&&f(e,n)})},[A,P,F,I]),R=v(!A&&P.length===1?P[0]:0),z=y(A?P:[]),B=t(()=>N?p():P.length===0?[]:A?z.isLoading&&z.data===void 0?[]:c(P.map(e=>({boundCaps:z.data?.get(e),deviceType:I.get(e)}))):R.data===void 0&&R.isLoading?[]:o({boundCaps:R.data,deviceType:I.get(P[0])}),[N,P,A,z.data,z.isLoading,R.data,R.isLoading,I]),V=s(e.cap,e.method,e.args),H=u(e.cap,e.method,e.args),U=e.cap!==``&&e.method!==``&&H===null&&(N||P.length>0),W=A?z.isLoading:R.isLoading,G=A?z.isError:R.isError,K=t=>{if(t.startsWith(`custom:`))return;let n=l.find(e=>e.id===t);n!==void 0&&r(D(N?e.deviceId:P.length>0?T(P):F[0]?.id??0,n))};return n(`div`,{className:`flex min-w-0 flex-1 flex-col gap-2`,"data-testid":j,children:[k&&n(`div`,{className:`w-full max-w-xs`,children:[i(`label`,{className:x,children:M(`deviceDoAction.deviceDoActionFields.target`,`Target`)}),n(`select`,{className:b,"data-testid":`${j}-target`,value:N?`trigger`:`device`,onChange:e=>{if(e.target.value===`trigger`){r({deviceId:{$var:S},cap:``,method:``});return}r({deviceId:F[0]?.id??0,cap:``,method:``})},children:[i(`option`,{value:`device`,children:M(`deviceDoAction.deviceDoActionFields.specificDevice`,`Specific device`)}),i(`option`,{value:`trigger`,children:M(`deviceDoAction.deviceDoActionFields.theDeviceThatTriggeredThis`,`The device that triggered this run`)})]})]}),!N&&n(`div`,{"data-testid":`${j}-device`,children:[i(`label`,{className:x,children:M(`deviceDoAction.deviceLabel`,{count:A?2:1})}),i(m,{devices:L,listState:h,..._===void 0?{}:{fleet:_},value:[...P],onChange:e=>{r({deviceId:T(A?w(P,e,e=>I.get(e)):(()=>{let t=C(P,e);return t>0?[t]:[]})()),cap:``,method:``})},emptyLabel:A?`No devices selected`:`No device selected`,noun:`device`,testId:`${j}-device-picker`}),A&&P.length>1&&i(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:M(`deviceDoAction.deviceDoActionFields.sameFamilyOnlyTheAction`,`Same family only — the action runs on each selected device.`)})]}),n(`div`,{className:`w-full max-w-sm`,children:[i(`label`,{className:x,children:M(`deviceDoAction.deviceDoActionFields.action`,`Action`)}),n(`select`,{className:b,"data-testid":`${j}-action`,value:V===`custom:${e.cap}.${e.method}`?V:H?.id??``,disabled:!N&&(P.length===0||W),onChange:e=>K(e.target.value),children:[i(`option`,{value:``,children:!N&&P.length===0?M(`deviceDoAction.deviceDoActionFields.pickADeviceFirst`,`Pick a device first`):W?M(`deviceDoAction.deviceDoActionFields.loadingActions`,`Loading actions…`):B.length===0?M(`deviceDoAction.deviceDoActionFields.noActionsForThisDevice`,`No actions for this device`):M(`deviceDoAction.deviceDoActionFields.selectAnAction`,`Select an action…`)}),U&&i(`option`,{value:V,children:O(e.cap,e.method)}),B.map(e=>i(`option`,{value:e.id,children:e.label},e.id))]}),G&&i(`p`,{className:`mt-1 text-[11px] text-warning`,children:M(`deviceDoAction.deviceDoActionFields.couldNotReadThisDevice`,`Could not read this device’s capabilities.`)})]}),H?.openArgs!==void 0&&H.openArgs.length>0&&i(`div`,{className:`flex flex-col gap-2`,children:H.openArgs.map(t=>{let a=e.args?.[t.key],o=typeof a==`string`||typeof a==`number`?String(a):``;return n(`div`,{className:`w-full max-w-sm`,children:[i(`label`,{className:x,htmlFor:`${j}-${t.key}`,children:t.label}),i(`input`,{id:`${j}-${t.key}`,className:b,"data-testid":`${j}-${t.key}`,type:t.kind===`number`?`number`:`text`,value:o,onChange:n=>{let i=n.target.value,a=e.args===void 0?{}:{...e.args};if(i===``)delete a[t.key];else if(t.kind===`number`){let e=Number(i);Number.isNaN(e)?delete a[t.key]:a[t.key]=e}else a[t.key]=i;r(Object.keys(a).length>0?{...e,args:a}:{deviceId:e.deviceId,cap:e.cap,method:e.method})}})]},t.key)})})]})}export{k as t};
1
+ import{$ as e,G as t,S as n,a as r,x as i}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{ot as a}from"./player-overlays-DyNPyo_W.js";import{Gt as o,Jt as s,Kt as c,Wt as l,Xt as u,Yt as d,Zt as f,qt as p}from"./client-CRCWO8cg.js";import{F as m}from"./src-_mtQMfPm.js";import{t as h}from"./i18n-DzruZdmx.js";import{t as g}from"./useTranslation-D3Is_4B6.js";import"./notification-schedule-field-CeZmOaz1.js";e();var _=6e4;function v(e){let t=a();return r({queryKey:[`device-do-action`,`bound-caps`,e],enabled:e>0,staleTime:_,queryFn:async()=>{let n=await t.trpcClient.deviceManager.getBindings.query({deviceId:e});return[...new Set(n.entries.map(e=>e.capName))].sort((e,t)=>e.localeCompare(t))}})}function y(e){let t=a(),n=[...new Set(e.filter(e=>e>0))].sort((e,t)=>e-t);return r({queryKey:[`device-do-action`,`bound-caps-batch`,n],enabled:n.length>0,staleTime:_,queryFn:async()=>{let e=await t.trpcClient.deviceManager.getBindingsBatch.query({deviceIds:n}),r=new Map;for(let t of e)r.set(t.deviceId,[...new Set(t.entries.map(e=>e.capName))].sort((e,t)=>e.localeCompare(t)));return r}})}var b=`mt-1 w-full rounded border border-border bg-background px-2 py-1 text-xs`,x=`block text-[11px] font-medium text-foreground`,S=`deviceId`;function C(e,t){return t.length===0?0:t.length===1?t[0]:t.find(t=>!e.includes(t))??t[t.length-1]}function w(e,t,n){if(t.length===0)return[];if(t.length===1)return t;let r=t.find(t=>!e.includes(t));if(r===void 0)return t;let i=n(r);if(i===void 0)return[r];let a=e[0]??t.find(e=>e!==r);if(a===void 0)return[r];let o=n(a);return o===void 0||!f(o,i)?[r]:t.filter(e=>{let t=n(e);return t!==void 0&&f(o,t)})}function T(e){return e.length===0?0:e.length===1?e[0]:[...e]}function E(e){return typeof e==`number`?e>0?[e]:[]:Array.isArray(e)?e.filter(e=>e>0):[]}function D(e,t){return{deviceId:e,cap:t.cap,method:t.method,...t.args===void 0?{}:{args:{...t.args}}}}function O(e,t){return h.t(`deviceDoAction.customLabel`,{name:`${e}.${t}`})}function k({value:e,onChange:r,devices:a,listState:h,fleet:_,allowTriggerDevice:k=!1,allowMultiSameFamily:A=!1,testId:j=`device-do-action`}){let{t:M}=g(),N=typeof e.deviceId!=`number`&&!Array.isArray(e.deviceId),P=E(e.deviceId),F=t(()=>a.filter(e=>d(String(e.type??``))),[a]),I=t(()=>{let e=new Map;for(let t of F)t.type!==void 0&&t.type!==null&&e.set(t.id,String(t.type));return e},[F]),L=t(()=>{if(!A||P.length===0)return F;let e=I.get(P[0]);return e===void 0?F:F.filter(t=>{if(P.includes(t.id))return!0;let n=t.type!==void 0&&t.type!==null?String(t.type):void 0;return n!==void 0&&f(e,n)})},[A,P,F,I]),R=v(!A&&P.length===1?P[0]:0),z=y(A?P:[]),B=t(()=>N?p():P.length===0?[]:A?z.isLoading&&z.data===void 0?[]:c(P.map(e=>({boundCaps:z.data?.get(e),deviceType:I.get(e)}))):R.data===void 0&&R.isLoading?[]:o({boundCaps:R.data,deviceType:I.get(P[0])}),[N,P,A,z.data,z.isLoading,R.data,R.isLoading,I]),V=s(e.cap,e.method,e.args),H=u(e.cap,e.method,e.args),U=e.cap!==``&&e.method!==``&&H===null&&(N||P.length>0),W=A?z.isLoading:R.isLoading,G=A?z.isError:R.isError,K=t=>{if(t.startsWith(`custom:`))return;let n=l.find(e=>e.id===t);n!==void 0&&r(D(N?e.deviceId:P.length>0?T(P):F[0]?.id??0,n))};return n(`div`,{className:`flex min-w-0 flex-1 flex-col gap-2`,"data-testid":j,children:[k&&n(`div`,{className:`w-full max-w-xs`,children:[i(`label`,{className:x,children:M(`deviceDoAction.deviceDoActionFields.target`,`Target`)}),n(`select`,{className:b,"data-testid":`${j}-target`,value:N?`trigger`:`device`,onChange:e=>{if(e.target.value===`trigger`){r({deviceId:{$var:S},cap:``,method:``});return}r({deviceId:F[0]?.id??0,cap:``,method:``})},children:[i(`option`,{value:`device`,children:M(`deviceDoAction.deviceDoActionFields.specificDevice`,`Specific device`)}),i(`option`,{value:`trigger`,children:M(`deviceDoAction.deviceDoActionFields.theDeviceThatTriggeredThis`,`The device that triggered this run`)})]})]}),!N&&n(`div`,{"data-testid":`${j}-device`,children:[i(`label`,{className:x,children:M(`deviceDoAction.deviceLabel`,{count:A?2:1})}),i(m,{devices:L,listState:h,..._===void 0?{}:{fleet:_},value:[...P],onChange:e=>{r({deviceId:T(A?w(P,e,e=>I.get(e)):(()=>{let t=C(P,e);return t>0?[t]:[]})()),cap:``,method:``})},emptyLabel:A?`No devices selected`:`No device selected`,noun:`device`,testId:`${j}-device-picker`}),A&&P.length>1&&i(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:M(`deviceDoAction.deviceDoActionFields.sameFamilyOnlyTheAction`,`Same family only — the action runs on each selected device.`)})]}),n(`div`,{className:`w-full max-w-sm`,children:[i(`label`,{className:x,children:M(`deviceDoAction.deviceDoActionFields.action`,`Action`)}),n(`select`,{className:b,"data-testid":`${j}-action`,value:V===`custom:${e.cap}.${e.method}`?V:H?.id??``,disabled:!N&&(P.length===0||W),onChange:e=>K(e.target.value),children:[i(`option`,{value:``,children:!N&&P.length===0?M(`deviceDoAction.deviceDoActionFields.pickADeviceFirst`,`Pick a device first`):W?M(`deviceDoAction.deviceDoActionFields.loadingActions`,`Loading actions…`):B.length===0?M(`deviceDoAction.deviceDoActionFields.noActionsForThisDevice`,`No actions for this device`):M(`deviceDoAction.deviceDoActionFields.selectAnAction`,`Select an action…`)}),U&&i(`option`,{value:V,children:O(e.cap,e.method)}),B.map(e=>i(`option`,{value:e.id,children:e.label},e.id))]}),G&&i(`p`,{className:`mt-1 text-[11px] text-warning`,children:M(`deviceDoAction.deviceDoActionFields.couldNotReadThisDevice`,`Could not read this device’s capabilities.`)})]}),H?.openArgs!==void 0&&H.openArgs.length>0&&i(`div`,{className:`flex flex-col gap-2`,children:H.openArgs.map(t=>{let a=e.args?.[t.key],o=typeof a==`string`||typeof a==`number`?String(a):``;return n(`div`,{className:`w-full max-w-sm`,children:[i(`label`,{className:x,htmlFor:`${j}-${t.key}`,children:t.label}),i(`input`,{id:`${j}-${t.key}`,className:b,"data-testid":`${j}-${t.key}`,type:t.kind===`number`?`number`:`text`,value:o,onChange:n=>{let i=n.target.value,a=e.args===void 0?{}:{...e.args};if(i===``)delete a[t.key];else if(t.kind===`number`){let e=Number(i);Number.isNaN(e)?delete a[t.key]:a[t.key]=e}else a[t.key]=i;r(Object.keys(a).length>0?{...e,args:a}:{deviceId:e.deviceId,cap:e.cap,method:e.method})}})]},t.key)})})]})}export{k as t};
@@ -1 +1 @@
1
- import{$ as e,G as t,L as n,S as r,o as i,x as a}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Nt as o,Oi as s,ot as c}from"./player-overlays-DyNPyo_W.js";import{Dt as l,Ga as u,La as d,Ma as f,Ot as p,eo as m,r as h,zo as g}from"./src-D9dVviCd.js";import{t as _}from"./useTranslation-D3Is_4B6.js";import{Y as v,et as y}from"./index-DmLUUGkL.js";import{t as b}from"./AdminPage-BgoL9iVo.js";import"./useEventInvalidation-Qf3yJdq3.js";import{t as x}from"./device-integration-icon-Dadl9j0d.js";e();var S=32;function C(e,t){let n=e=>t(e).kind===`orphan`,r=new Set;for(let t of e)n(t)&&r.add(t.id);let i=new Map;for(let t of e)i.set(t.id,t);let a=(e,t=0)=>{if(t>S)return!1;if(r.has(e.id))return!0;if(e.parentDeviceId==null)return!1;let n=i.get(e.parentDeviceId);return n?a(n,t+1):!1},o=[],s=[];for(let t of e)a(t)?s.push(t):o.push(t);return{activeDevices:o,orphanDevices:s}}function w(){let{t:e}=_(),S=y(),w=c(),T=i();h([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]),h([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`]);let{data:E}=u({projection:`slim`}),{data:D}=g(void 0),O=m({onSuccess:()=>{T.invalidateQueries({queryKey:[[`deviceManager`]]})}}),k=f({onSuccess:()=>{T.invalidateQueries({queryKey:[[`deviceManager`]]})}}),A=d({onSuccess:()=>{T.invalidateQueries({queryKey:[[`deviceManager`]]})}}),j=t(()=>E??[],[E]),M=t(()=>p(D),[D]),{activeDevices:N,orphanDevices:P}=t(()=>C(j,M),[j,M]),F=t(()=>{let e=new Map;for(let t of j)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[j]),I=n(e=>F.get(e)??null,[F]),L=t(()=>(D??[]).map(e=>({id:e.id,name:e.name??e.addonId,icon:a(v,{type:e.addonId,size:`sm`})})),[D]),R=n(e=>S(`/devices/${String(e)}`),[S]);return r(b,{icon:s,title:e(`nav.devices`,`Devices`),children:[a(l,{context:`devices`,devices:N,trpc:w.trpcClient,filters:{integrations:L},integrationOf:M,resolveIntegrationIcon:x,resolveParent:I,onNavigate:R,batchActions:{remove:O.mutate,disable:k.mutate,enable:A.mutate}}),P.length>0&&r(`div`,{className:`mt-6 space-y-2`,children:[r(`div`,{className:`flex items-baseline gap-2`,children:[a(o,{className:`h-3.5 w-3.5 text-warning shrink-0`}),a(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`devices.orphanDevices`,`Orphan devices`)}),a(`span`,{className:`text-[10px] text-foreground-subtle`,children:e(`common.deviceOrphans`,{count:P.length})})]}),r(`div`,{className:`rounded-lg border border-warning/30 bg-warning/5 p-2`,children:[a(`p`,{className:`text-[11px] text-foreground-subtle px-2 pb-2`,children:e(`devices.theseDevicesReferenceAnIntegration`,"These devices reference an integration that is no longer registered (their `integrationId`, or — for older devices without one — their `addonId`). Delete them, or re-install the missing integration to bring them back online. The provider badge beside each row is the addon that serves it.")}),a(l,{context:`devices`,devices:P,trpc:w.trpcClient,integrationOf:M,urlScope:`nested`,lsKey:`devices:orphan`,resolveIntegrationIcon:x,resolveParent:I,onNavigate:R})]})]})]})}export{w as DevicesPage};
1
+ import{$ as e,G as t,L as n,S as r,o as i,x as a}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Nt as o,Oi as s,ot as c}from"./player-overlays-DyNPyo_W.js";import{Dt as l,Ga as u,La as d,Ma as f,Ot as p,eo as m,r as h,zo as g}from"./src-_mtQMfPm.js";import{t as _}from"./useTranslation-D3Is_4B6.js";import{Y as v,et as y}from"./index-2_qB4G1l.js";import{t as b}from"./AdminPage-CTKQzYSK.js";import"./useEventInvalidation-B0uThmDr.js";import{t as x}from"./device-integration-icon-C_jsalSP.js";e();var S=32;function C(e,t){let n=e=>t(e).kind===`orphan`,r=new Set;for(let t of e)n(t)&&r.add(t.id);let i=new Map;for(let t of e)i.set(t.id,t);let a=(e,t=0)=>{if(t>S)return!1;if(r.has(e.id))return!0;if(e.parentDeviceId==null)return!1;let n=i.get(e.parentDeviceId);return n?a(n,t+1):!1},o=[],s=[];for(let t of e)a(t)?s.push(t):o.push(t);return{activeDevices:o,orphanDevices:s}}function w(){let{t:e}=_(),S=y(),w=c(),T=i();h([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]),h([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`]);let{data:E}=u({projection:`slim`}),{data:D}=g(void 0),O=m({onSuccess:()=>{T.invalidateQueries({queryKey:[[`deviceManager`]]})}}),k=f({onSuccess:()=>{T.invalidateQueries({queryKey:[[`deviceManager`]]})}}),A=d({onSuccess:()=>{T.invalidateQueries({queryKey:[[`deviceManager`]]})}}),j=t(()=>E??[],[E]),M=t(()=>p(D),[D]),{activeDevices:N,orphanDevices:P}=t(()=>C(j,M),[j,M]),F=t(()=>{let e=new Map;for(let t of j)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[j]),I=n(e=>F.get(e)??null,[F]),L=t(()=>(D??[]).map(e=>({id:e.id,name:e.name??e.addonId,icon:a(v,{type:e.addonId,size:`sm`})})),[D]),R=n(e=>S(`/devices/${String(e)}`),[S]);return r(b,{icon:s,title:e(`nav.devices`,`Devices`),children:[a(l,{context:`devices`,devices:N,trpc:w.trpcClient,filters:{integrations:L},integrationOf:M,resolveIntegrationIcon:x,resolveParent:I,onNavigate:R,batchActions:{remove:O.mutate,disable:k.mutate,enable:A.mutate}}),P.length>0&&r(`div`,{className:`mt-6 space-y-2`,children:[r(`div`,{className:`flex items-baseline gap-2`,children:[a(o,{className:`h-3.5 w-3.5 text-warning shrink-0`}),a(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`devices.orphanDevices`,`Orphan devices`)}),a(`span`,{className:`text-[10px] text-foreground-subtle`,children:e(`common.deviceOrphans`,{count:P.length})})]}),r(`div`,{className:`rounded-lg border border-warning/30 bg-warning/5 p-2`,children:[a(`p`,{className:`text-[11px] text-foreground-subtle px-2 pb-2`,children:e(`devices.theseDevicesReferenceAnIntegration`,"These devices reference an integration that is no longer registered (their `integrationId`, or — for older devices without one — their `addonId`). Delete them, or re-install the missing integration to bring them back online. The provider badge beside each row is the addon that serves it.")}),a(l,{context:`devices`,devices:P,trpc:w.trpcClient,integrationOf:M,urlScope:`nested`,lsKey:`devices:orphan`,resolveIntegrationIcon:x,resolveParent:I,onNavigate:R})]})]})]})}export{w as DevicesPage};
@@ -1 +1 @@
1
- import{$ as e,B as t,G as n,J as r,S as i,d as a,u as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{it as c}from"./player-overlays-DyNPyo_W.js";import{xi as l}from"./client-CRCWO8cg.js";import{D as u,M as d,O as f,P as p,T as m,y as h}from"./__vite-browser-external-BlMfPwfH.js";import{$t as g,Ju as _,fn as v,rn as y,vn as b}from"./src-D9dVviCd.js";import{t as x}from"./useTranslation-D3Is_4B6.js";e();var S=p([f({kind:m(`adaptive`)}),f({kind:m(`profile`),profile:l})]),C=f({serverUrl:d().min(1),token:d().min(1),deviceId:u().int().nonnegative(),target:S,muted:h()});function w(e,t){let n=t===void 0?{type:`state`,state:e}:{type:`state`,state:e,message:t};window.ReactNativeWebView?.postMessage(JSON.stringify(n))}function T(e){switch(e){case`playing`:return`playing`;case`error`:return`error`;case`connecting`:case`disconnected`:case`idle`:return`connecting`}}function E(e){return e.kind===`adaptive`?{kind:`adaptive`}:{kind:`profile`,profile:e.profile}}function D(e){return e.kind===`adaptive`?`embed:adaptive`:`embed:profile:${e.profile}`}function O(){let e=window.__CAMSTACK_EMBED__;if(e==null)return{ok:!1,error:`window.__CAMSTACK_EMBED__ is not set`};let t=C.safeParse(e);return t.success?{ok:!0,config:t.data}:{ok:!1,error:t.error.issues.map(e=>`${e.path.join(`.`)||`(root)`}: ${e.message}`).join(`; `)}}function k({message:e}){let{t:n}=x();return t(()=>{w(`error`,e)},[e]),i(`div`,{style:{position:`fixed`,inset:0,display:`flex`,alignItems:`center`,justifyContent:`center`,background:`#000`,color:`#f87171`,fontFamily:`system-ui, sans-serif`,fontSize:13,padding:16,textAlign:`center`},children:[n(`embedPlayerPage.embedConfigError`,`Embed config error:`),` `,e]})}function A({system:e,deviceId:i,initialTarget:a,initialMuted:o}){let[c,l]=r(a),[u,d]=r(o),{handleOffer:f,getIceServers:p,addIceCandidate:m,getIceCandidates:h,closeSession:g,getSessionState:_,getSessionDebug:y,applyDownlinkProbe:x}=v(e.trpcClient,i),C=n(()=>E(c),[c]),O=n(()=>(e,t)=>f(C,e,t),[f,C]),k=n(()=>(e,t,n)=>f(n,t,e),[f]);t(()=>(window.__camstackEmbed={setMuted:e=>d(e),setTarget:e=>{let t=S.safeParse(e);t.success&&l(t.data)}},()=>{window.__camstackEmbed&&delete window.__camstackEmbed}),[]);let A=D(c);return s(`div`,{style:{position:`fixed`,inset:0,width:`100vw`,height:`100vh`,background:`#000`},children:s(b,{serverUrl:e.serverUrl,streamKey:A,autoPlay:!0,muted:u,showControls:!1,className:`w-full h-full`,getSessionDebug:y,applyDownlinkProbe:x,handleOffer:O,reoffer:k,getSessionState:_,getIceServers:p,addIceCandidate:m,getIceCandidates:h,closeSession:g,onStateChange:e=>w(T(e)),onError:e=>w(`error`,e)},A)})}function j(){let{t:e}=x(),r=n(()=>O(),[]),i=n(()=>{if(!r.ok)return null;let e=y({serverUrl:r.config.serverUrl,token:r.config.token}),t=new a({defaultOptions:{queries:{retry:!1,refetchOnWindowFocus:!1}}});return g(t),{system:e,queryClient:t}},[r]);return t(()=>{if(i)return()=>{i.system.close()}},[i]),r.ok?i?s(c,{system:i.system,children:s(o,{client:i.queryClient,children:s(_.Provider,{client:i.system.trpcClient,queryClient:i.queryClient,children:s(A,{system:i.system,deviceId:r.config.deviceId,initialTarget:r.config.target,initialMuted:r.config.muted})})})}):s(k,{message:e(`embedPlayerPage.failedToInitialiseTheEmbed`,`Failed to initialise the embed player`)}):s(k,{message:r.error})}export{j as EmbedPlayerPage};
1
+ import{$ as e,B as t,G as n,J as r,S as i,d as a,u as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{it as c}from"./player-overlays-DyNPyo_W.js";import{xi as l}from"./client-CRCWO8cg.js";import{D as u,M as d,O as f,P as p,T as m,y as h}from"./__vite-browser-external-BlMfPwfH.js";import{$t as g,Ju as _,fn as v,rn as y,vn as b}from"./src-_mtQMfPm.js";import{t as x}from"./useTranslation-D3Is_4B6.js";e();var S=p([f({kind:m(`adaptive`)}),f({kind:m(`profile`),profile:l})]),C=f({serverUrl:d().min(1),token:d().min(1),deviceId:u().int().nonnegative(),target:S,muted:h()});function w(e,t){let n=t===void 0?{type:`state`,state:e}:{type:`state`,state:e,message:t};window.ReactNativeWebView?.postMessage(JSON.stringify(n))}function T(e){switch(e){case`playing`:return`playing`;case`error`:return`error`;case`connecting`:case`disconnected`:case`idle`:return`connecting`}}function E(e){return e.kind===`adaptive`?{kind:`adaptive`}:{kind:`profile`,profile:e.profile}}function D(e){return e.kind===`adaptive`?`embed:adaptive`:`embed:profile:${e.profile}`}function O(){let e=window.__CAMSTACK_EMBED__;if(e==null)return{ok:!1,error:`window.__CAMSTACK_EMBED__ is not set`};let t=C.safeParse(e);return t.success?{ok:!0,config:t.data}:{ok:!1,error:t.error.issues.map(e=>`${e.path.join(`.`)||`(root)`}: ${e.message}`).join(`; `)}}function k({message:e}){let{t:n}=x();return t(()=>{w(`error`,e)},[e]),i(`div`,{style:{position:`fixed`,inset:0,display:`flex`,alignItems:`center`,justifyContent:`center`,background:`#000`,color:`#f87171`,fontFamily:`system-ui, sans-serif`,fontSize:13,padding:16,textAlign:`center`},children:[n(`embedPlayerPage.embedConfigError`,`Embed config error:`),` `,e]})}function A({system:e,deviceId:i,initialTarget:a,initialMuted:o}){let[c,l]=r(a),[u,d]=r(o),{handleOffer:f,getIceServers:p,addIceCandidate:m,getIceCandidates:h,closeSession:g,getSessionState:_,getSessionDebug:y,applyDownlinkProbe:x}=v(e.trpcClient,i),C=n(()=>E(c),[c]),O=n(()=>(e,t)=>f(C,e,t),[f,C]),k=n(()=>(e,t,n)=>f(n,t,e),[f]);t(()=>(window.__camstackEmbed={setMuted:e=>d(e),setTarget:e=>{let t=S.safeParse(e);t.success&&l(t.data)}},()=>{window.__camstackEmbed&&delete window.__camstackEmbed}),[]);let A=D(c);return s(`div`,{style:{position:`fixed`,inset:0,width:`100vw`,height:`100vh`,background:`#000`},children:s(b,{serverUrl:e.serverUrl,streamKey:A,autoPlay:!0,muted:u,showControls:!1,className:`w-full h-full`,getSessionDebug:y,applyDownlinkProbe:x,handleOffer:O,reoffer:k,getSessionState:_,getIceServers:p,addIceCandidate:m,getIceCandidates:h,closeSession:g,onStateChange:e=>w(T(e)),onError:e=>w(`error`,e)},A)})}function j(){let{t:e}=x(),r=n(()=>O(),[]),i=n(()=>{if(!r.ok)return null;let e=y({serverUrl:r.config.serverUrl,token:r.config.token}),t=new a({defaultOptions:{queries:{retry:!1,refetchOnWindowFocus:!1}}});return g(t),{system:e,queryClient:t}},[r]);return t(()=>{if(i)return()=>{i.system.close()}},[i]),r.ok?i?s(c,{system:i.system,children:s(o,{client:i.queryClient,children:s(_.Provider,{client:i.system.trpcClient,queryClient:i.queryClient,children:s(A,{system:i.system,deviceId:r.config.deviceId,initialTarget:r.config.target,initialMuted:r.config.muted})})})}):s(k,{message:e(`embedPlayerPage.failedToInitialiseTheEmbed`,`Failed to initialise the embed player`)}):s(k,{message:r.error})}export{j as EmbedPlayerPage};
@@ -1 +1 @@
1
- import{$ as e,G as t,S as n,i as r,x as i}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{ca as a,dt as o,hn as s,ot as c,wi as l,yr as u}from"./player-overlays-DyNPyo_W.js";import{An as d,Xr as f}from"./client-CRCWO8cg.js";import{A as p,D as m,Dr as h,E as g,Er as _,Ga as v,M as y,O as b,S as x,T as S,Uu as C,_ as ee,_n as w,b as T,bl as E,d as te,f as D,fr as O,g as k,gn as A,gr as ne,hr as j,j as M,k as N,m as re,mn as P,mr as F,on as I,p as L,pr as R,sn as z,u as B,ur as V,v as H,w as ie,x as ae,y as U}from"./src-D9dVviCd.js";import{t as W}from"./useTranslation-D3Is_4B6.js";import{nt as G}from"./index-DmLUUGkL.js";import{t as K}from"./AdminPage-BgoL9iVo.js";e();function q(e,t){return e.scope===``?e.displayName:`${e.displayName} · ${t?.(e)??e.scope}`}function oe(e,t,n){let r=[];for(let{device:t,series:i}of e)for(let e of i){let i={subject:{kind:`device`,deviceId:t.id},key:e.key,scope:e.scope};r.push({id:U(i),ref:i,info:e,subjectName:t.name,location:t.location??``,nodeId:``,metric:q(e,n)})}for(let{node:e,series:i}of t)for(let t of i){let i={subject:{kind:`node`,nodeId:e.id},key:t.key,scope:t.scope};r.push({id:U(i),ref:i,info:t,subjectName:e.name,location:``,nodeId:e.id,metric:q(t,n)})}return r}function se(e){return[e.subjectName,e.location,e.metric,e.info.key,e.info.unit??``,e.nodeId].join(` `)}var ce=[`energy`,`temperatures`,`nodes`,`storage`],le=new Set([`cap:temperature-sensor.celsius`,`cap:climate-control.currentTemp`]),J=[`addon:metrics-native/node-cpu-percent`,`addon:metrics-native/node-memory-percent`],ue=`addon:storage-orchestrator/location-used-percent`;function de(e,t){let n=(e,n)=>{let r=t.filter(e);return H((n?[...r].sort(n):r).map(e=>e.ref))};switch(e){case`energy`:return n(e=>e.ref.subject.kind===`device`&&e.info.key===`derived:energy.kwh`);case`temperatures`:return n(e=>e.ref.subject.kind===`device`&&le.has(e.info.key)&&e.info.scope===``,(e,t)=>e.location.localeCompare(t.location)||e.subjectName.localeCompare(t.subjectName));case`nodes`:return n(e=>e.ref.subject.kind===`node`&&J.includes(e.info.key)&&e.info.scope===``,(e,t)=>J.indexOf(e.info.key)-J.indexOf(t.info.key)||e.subjectName.localeCompare(t.subjectName));case`storage`:return n(e=>e.ref.subject.kind===`node`&&e.info.key===ue)}}function fe(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[],i=[],a=[],o=[];for(let t of H(e)){let e=n.get(U(t));if(e===void 0){o.push(t);continue}e.info.key===`derived:energy.kwh`?a.push(e):e.info.kind===`boolean`||e.info.kind===`enum`?i.push(e):r.push(e)}return{lines:r,states:i,energy:a,missing:o}}function Y(e){return e.subject.kind===`device`?{deviceId:e.subject.deviceId,key:e.key,scope:e.scope}:{forNodeId:e.subject.nodeId,key:e.key,scope:e.scope}}var X=`history-page`;function Z(e){return`${e.subjectName} · ${e.metric}`}function pe({part:e,window:r}){let{t:o}=W(),s=a(),c=t(()=>[...e.lines,...e.states,...e.energy],[e]),u=L(t(()=>c.map(e=>Y(e.ref)),[c]),r,!1),d=e=>u.status===`ok`?u.data.current.get(D(Y(e.ref))):void 0,f=e=>{let t=d(e);return t?.ok?t.result:void 0};if(c.length===0)return i(R,{icon:l,title:o(`history.page.emptyTitle`,`Pick series to compare`),description:o(`history.page.emptyHint`,`Choose up to 24 series on the left, or start from a panel above.`)});if(u.status===`error`)return i(O,{title:o(`history.page.readFailed`,`History could not be read`),message:u.error});let p=u.status===`pending`,m=c.map(e=>({c:e,e:d(e)})).filter(e=>e.e?.ok===!1),h=e.lines.map((e,t)=>{let n=f(e),i=S(e.info,n,r.from);return{id:e.id,label:Z(e),unit:e.info.unit,colorIndex:t,points:i.points,gapMs:i.gapMs,interpolation:i.held&&n?.resolution===`raw`?`step`:`linear`}}),_=e.states.map((e,t)=>{let n=g(e.info,f(e),r.from,r.to),i=x(e.info.key,s);return{id:e.id,label:Z(e),kind:e.info.kind===`boolean`?`boolean`:`enum`,colorIndex:e.info.kind===`boolean`?t:0,states:n.states,segments:n.segments,totals:n.totals,stateLabel:e.info.kind===`boolean`?e=>e===`true`?i.on:i.off:void 0}}),v=e.energy.map(e=>({c:e,...ie(f(e))})),b=v[0]?.bucketMs??36e5,C=[...new Set(v.flatMap(e=>e.buckets.map(e=>e.t)))].sort((e,t)=>e-t).map(e=>({t:e,values:v.map(t=>t.buckets.find(t=>t.t===e)?.values[0]??null)}));return n(`div`,{className:`space-y-5 min-w-0`,children:[m.length>0&&i(O,{title:o(`history.page.someFailed`,`Some series could not be read`),message:m.map(e=>`${Z(e.c)}: ${e.e.error}`).join(` · `)}),h.length>0&&i(y,{title:o(`history.page.lines`,`Measurements`),series:h,range:r,height:260,syncKey:X,pending:p}),v.length>0&&i(V,{title:o(`history.page.energy`,`Energy`),layers:v.map((e,t)=>({id:e.c.id,label:e.c.subjectName,colorIndex:t})),buckets:C,bucketMs:b,range:r,unit:`kWh`,showTotal:!0,height:160,syncKey:X,pending:p}),_.length>0&&i(M,{title:_.length===1?_[0]?.label??``:o(`history.page.states`,`States`),rows:_,range:r,syncKey:X,pending:p})]})}e();var Q=`device`,me=`node`;function he({catalog:e,selected:r,onChange:a,loading:o}){let{t:s}=W(),c=I(e,{searchText:e=>[se(e)],facetGroups:[{id:`subject`,value:e=>e.ref.subject.kind===`device`?Q:me},{id:`room`,value:e=>e.location},{id:`unit`,value:e=>e.info.unit??``}]}),l=t(()=>[{key:`metric`,header:s(`history.picker.series`,`Series`),render:e=>n(`div`,{className:`min-w-0`,children:[i(`div`,{className:`truncate text-foreground`,children:e.metric}),i(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.location===``?e.subjectName:`${e.subjectName} · ${e.location}`})]}),sortValue:e=>`${e.subjectName} ${e.metric}`},{key:`unit`,header:s(`history.picker.unit`,`Unit`),render:e=>i(`span`,{className:`text-foreground-muted`,children:e.info.unit??`—`}),sortValue:e=>e.info.unit??``}],[s]),u=r.size>=24;return n(`div`,{className:`space-y-2 min-w-0`,children:[i(z,{state:c.state,facets:[],groups:[{...c.groups.find(e=>e.id===`subject`)??{id:`subject`,facets:[],selected:[]},label:s(`history.picker.subject`,`Source`),facetLabel:e=>e===Q?s(`history.picker.devices`,`Devices`):s(`history.picker.nodes`,`Nodes`)},{...c.groups.find(e=>e.id===`room`)??{id:`room`,facets:[],selected:[]},label:s(`history.picker.room`,`Room`),facetLabel:e=>e===``?s(`history.picker.noRoom`,`No room`):e},{...c.groups.find(e=>e.id===`unit`)??{id:`unit`,facets:[],selected:[]},label:s(`history.picker.metricType`,`Unit`),facetLabel:e=>e===``?s(`history.picker.noUnit`,`States & counts`):e}],labels:{searchPlaceholder:s(`history.picker.search`,`Search device, room, metric or node…`),searchLabel:s(`history.picker.searchLabel`,`Search series`),facetsLabel:s(`history.picker.facets`,`Filters`),clearLabel:s(`history.picker.clear`,`Clear`)},onSearch:c.setSearch,onToggleFacet:c.toggleFacet,onToggleGroupFacet:c.toggleGroupFacet,onClear:c.clear}),i(`p`,{className:`text-[10px] text-foreground-subtle`,"aria-live":`polite`,children:s(`history.picker.count`,`{{count}} of {{max}} selected`,{count:r.size,max:24})}),i(A,{columns:l,rows:c.rows,rowKey:e=>e.id,maxBodyHeight:w,pageSize:50,defaultSort:{columnKey:`metric`,dir:`asc`},emptyMessage:o?s(`history.picker.loading`,`Reading the series of every device…`):c.active?s(`history.picker.emptyFiltered`,`No series match these filters.`):s(`history.picker.empty`,`Nothing is recorded yet.`),selection:{selected:r,onChange:e=>{let t=[...e].filter(e=>r.has(e)),n=[...e].filter(e=>!r.has(e));a(new Set([...t,...n].slice(0,24)))},isSelectable:e=>r.has(e.id)||!u,rowLabel:e=>`${e.subjectName} · ${e.metric}`,pageLabel:s(`history.picker.selectPage`,`Select every series on this page`)}})]})}e();var ge=new Set([f.Hub,f.Container]),$=5*6e4;function _e(){let{t:e}=W(),r=ne(`device-history`),[a,c]=G(),d=t(()=>H(a.getAll(`s`).flatMap(e=>{let t=k(e);return t===null?[]:[t]})),[a]),f=a.get(`window`),g=N(f)?f:`7d`,v=m(a.get(`range`)),y=(e,t,n)=>{let r=new URLSearchParams;for(let t of H(e))r.append(`s`,ee(t));t!==`7d`&&r.set(`window`,t);let i=n===void 0?a.get(`range`):n;t===`custom`&&i&&r.set(`range`,i),c(r,{replace:!0})},x=ve(r===`present`),S=p(g,Date.now(),v),C=p(g,te(Date.now(),S.to-S.from),v),w=t(()=>fe(d,x.candidates),[d,x.candidates]),E=t(()=>new Set(d.map(U)),[d]),D=B(),A=h(),M=_(),I=async()=>{let t=await A({title:e(`history.page.saveTitle`,`Save as panel`),label:e(`history.page.saveName`,`Panel name`),confirmLabel:e(`history.page.save`,`Save`)});t===null||t.trim()===``||await D.update(e=>T(e,{id:`panel-${Date.now().toString(36)}`,name:t.trim().slice(0,80),window:g,selection:[...d]}))},L=async(t,n)=>{await M({title:e(`history.page.deleteTitle`,`Delete panel`),message:e(`history.page.deleteMessage`,`The panel "{{name}}" is removed from your account.`,{name:n}),confirmLabel:e(`history.page.delete`,`Delete`),variant:`danger`})&&await D.update(e=>ae(e,t))},z=t=>t===`energy`?e(`history.panels.energy`,`Total energy`):t===`temperatures`?e(`history.panels.temperatures`,`Temperatures by room`):t===`nodes`?e(`history.panels.nodes`,`Cluster nodes`):e(`history.panels.storage`,`Storage locations`);return i(K,{icon:l,title:e(`history.page.title`,`History`),subtitle:e(`history.page.subtitle`,`What devices, nodes and storage recorded over time, side by side.`),actions:r===`present`?n(j,{size:`sm`,variant:`outline`,onClick:()=>void I(),disabled:d.length===0||!D.writable,children:[i(s,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),e(`history.page.saveTitle`,`Save as panel`)]}):void 0,children:r===`pending`?i(F,{className:`h-64 w-full`}):r===`unknown`?i(O,{title:e(`history.page.presenceUnknownTitle`,`Could not reach the hub`),message:e(`history.page.presenceUnknown`,`The hub did not say whether device history is installed. Try again in a moment.`)}):r===`absent`?i(R,{icon:u,title:e(`history.page.absentTitle`,`Device history is not running on this hub`),description:e(`history.page.absent`,`Nothing is recorded until the device-history system addon is enabled.`)}):n(`div`,{className:`space-y-3 sm:space-y-4`,children:[n(`div`,{className:`flex flex-wrap items-center gap-2`,role:`group`,"aria-label":e(`history.page.panels`,`Panels`),children:[ce.map(e=>i(j,{size:`sm`,variant:`outline`,disabled:x.status!==`ok`,onClick:()=>y(de(e,x.candidates),g),children:z(e)},e)),D.value.panels.map(t=>n(`span`,{className:`inline-flex items-center`,children:[i(j,{size:`sm`,variant:`secondary`,onClick:()=>y(t.selection,t.window,null),children:t.name}),i(j,{size:`sm`,variant:`ghost`,"aria-label":e(`history.page.deleteNamed`,`Delete panel {{name}}`,{name:t.name}),onClick:()=>void L(t.id,t.name),disabled:!D.writable,children:i(o,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})]},t.id))]}),n(`div`,{className:`grid grid-cols-1 gap-3 sm:gap-4 xl:grid-cols-5`,children:[i(`div`,{className:`min-w-0 xl:col-span-2`,children:i(P,{headingId:`history-picker`,title:e(`history.picker.title`,`Series`),children:i(`div`,{className:`p-2 sm:p-3`,children:x.status===`error`?i(O,{message:x.error}):i(he,{catalog:x.candidates,loading:x.status===`pending`,selected:E,onChange:e=>{let t=d.filter(t=>e.has(U(t))),n=x.candidates.filter(t=>e.has(t.id)&&!E.has(t.id)).map(e=>e.ref);y([...t,...n],g)}})})})}),i(`div`,{className:`min-w-0 xl:col-span-3`,children:i(P,{headingId:`history-overlay`,title:e(`history.page.overlay`,`Overlay`),actions:d.length>0?i(j,{size:`sm`,variant:`ghost`,onClick:()=>y([],g),children:e(`history.page.clear`,`Clear`)}):void 0,children:n(`div`,{className:`p-2 sm:p-3 space-y-3 min-w-0`,children:[i(re,{value:g,onChange:e=>y(d,e),custom:v,onCustomChange:e=>y(d,`custom`,b(e))}),x.status===`pending`&&d.length>0?i(F,{className:`h-64 w-full`}):i(pe,{part:w,window:C}),w.missing.length>0&&x.status===`ok`&&i(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`history.page.missing`,{count:w.missing.length,defaultValue_one:`{{count}} selected series is no longer recorded.`,defaultValue_other:`{{count}} selected series are no longer recorded.`})})]})})})]})]})})}function ve(e){let{t:n}=W(),i=n(`history.picker.wholeFrame`,`Whole frame`),a=c().trpcClient,o=v({projection:`slim`},{enabled:e,staleTime:$}),{nodes:s}=C(),l=t(()=>(o.data??[]).filter(e=>!ge.has(String(e.type))),[o.data]),u=r({queries:l.map(t=>({queryKey:[`device-history`,`listSeries`,t.id],queryFn:()=>a.deviceHistory.listSeries.query({deviceId:t.id}),enabled:e,staleTime:$}))}),f=r({queries:s.map(t=>({queryKey:[`device-history`,`listNodeSeries`,t.id],queryFn:()=>a.deviceHistory.listNodeSeries.query({forNodeId:t.id}),enabled:e,staleTime:$}))}),p=E({},{enabled:e,staleTime:$}),m=t(()=>new Map((p?.data??[]).map(e=>[e.id,e.displayName])),[p?.data]),h=u.map(e=>e.data),g=f.map(e=>e.data),_=t(()=>oe(l.flatMap((e,t)=>{let n=h[t];return n===void 0?[]:[{device:{id:e.id,name:e.name,location:e.location??null},series:n}]}),s.flatMap((e,t)=>{let n=g[t];return n===void 0?[]:[{node:{id:e.id,name:e.name},series:n}]}),e=>{if(e.key!==`addon:pipeline-analytics/occupancy`)return m.get(e.scope)??e.scope;let{zoneId:t,className:n}=d(e.scope),r=t===``?i:t;return n===void 0?r:`${r} · ${n}`}),[l,s,m,[...u,...f].map(e=>e.dataUpdatedAt).join(`,`),i]);return o.status===`error`?{status:`error`,error:o.error.message,candidates:[]}:{status:o.status===`pending`||u.some(e=>e.isPending)||f.some(e=>e.isPending)?`pending`:`ok`,error:``,candidates:_}}export{_e as HistoryPage};
1
+ import{$ as e,G as t,S as n,i as r,x as i}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{ca as a,dt as o,hn as s,ot as c,wi as l,yr as u}from"./player-overlays-DyNPyo_W.js";import{An as d,Xr as f}from"./client-CRCWO8cg.js";import{A as p,D as m,Dr as h,E as g,Er as _,Ga as v,M as y,O as b,S as x,T as S,Uu as C,_ as ee,_n as w,b as T,bl as E,d as te,f as D,fr as O,g as k,gn as A,gr as ne,hr as j,j as M,k as N,m as re,mn as P,mr as F,on as I,p as L,pr as R,sn as z,u as B,ur as V,v as H,w as ie,x as ae,y as U}from"./src-_mtQMfPm.js";import{t as W}from"./useTranslation-D3Is_4B6.js";import{nt as G}from"./index-2_qB4G1l.js";import{t as K}from"./AdminPage-CTKQzYSK.js";e();function q(e,t){return e.scope===``?e.displayName:`${e.displayName} · ${t?.(e)??e.scope}`}function oe(e,t,n){let r=[];for(let{device:t,series:i}of e)for(let e of i){let i={subject:{kind:`device`,deviceId:t.id},key:e.key,scope:e.scope};r.push({id:U(i),ref:i,info:e,subjectName:t.name,location:t.location??``,nodeId:``,metric:q(e,n)})}for(let{node:e,series:i}of t)for(let t of i){let i={subject:{kind:`node`,nodeId:e.id},key:t.key,scope:t.scope};r.push({id:U(i),ref:i,info:t,subjectName:e.name,location:``,nodeId:e.id,metric:q(t,n)})}return r}function se(e){return[e.subjectName,e.location,e.metric,e.info.key,e.info.unit??``,e.nodeId].join(` `)}var ce=[`energy`,`temperatures`,`nodes`,`storage`],le=new Set([`cap:temperature-sensor.celsius`,`cap:climate-control.currentTemp`]),J=[`addon:metrics-native/node-cpu-percent`,`addon:metrics-native/node-memory-percent`],ue=`addon:storage-orchestrator/location-used-percent`;function de(e,t){let n=(e,n)=>{let r=t.filter(e);return H((n?[...r].sort(n):r).map(e=>e.ref))};switch(e){case`energy`:return n(e=>e.ref.subject.kind===`device`&&e.info.key===`derived:energy.kwh`);case`temperatures`:return n(e=>e.ref.subject.kind===`device`&&le.has(e.info.key)&&e.info.scope===``,(e,t)=>e.location.localeCompare(t.location)||e.subjectName.localeCompare(t.subjectName));case`nodes`:return n(e=>e.ref.subject.kind===`node`&&J.includes(e.info.key)&&e.info.scope===``,(e,t)=>J.indexOf(e.info.key)-J.indexOf(t.info.key)||e.subjectName.localeCompare(t.subjectName));case`storage`:return n(e=>e.ref.subject.kind===`node`&&e.info.key===ue)}}function fe(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[],i=[],a=[],o=[];for(let t of H(e)){let e=n.get(U(t));if(e===void 0){o.push(t);continue}e.info.key===`derived:energy.kwh`?a.push(e):e.info.kind===`boolean`||e.info.kind===`enum`?i.push(e):r.push(e)}return{lines:r,states:i,energy:a,missing:o}}function Y(e){return e.subject.kind===`device`?{deviceId:e.subject.deviceId,key:e.key,scope:e.scope}:{forNodeId:e.subject.nodeId,key:e.key,scope:e.scope}}var X=`history-page`;function Z(e){return`${e.subjectName} · ${e.metric}`}function pe({part:e,window:r}){let{t:o}=W(),s=a(),c=t(()=>[...e.lines,...e.states,...e.energy],[e]),u=L(t(()=>c.map(e=>Y(e.ref)),[c]),r,!1),d=e=>u.status===`ok`?u.data.current.get(D(Y(e.ref))):void 0,f=e=>{let t=d(e);return t?.ok?t.result:void 0};if(c.length===0)return i(R,{icon:l,title:o(`history.page.emptyTitle`,`Pick series to compare`),description:o(`history.page.emptyHint`,`Choose up to 24 series on the left, or start from a panel above.`)});if(u.status===`error`)return i(O,{title:o(`history.page.readFailed`,`History could not be read`),message:u.error});let p=u.status===`pending`,m=c.map(e=>({c:e,e:d(e)})).filter(e=>e.e?.ok===!1),h=e.lines.map((e,t)=>{let n=f(e),i=S(e.info,n,r.from);return{id:e.id,label:Z(e),unit:e.info.unit,colorIndex:t,points:i.points,gapMs:i.gapMs,interpolation:i.held&&n?.resolution===`raw`?`step`:`linear`}}),_=e.states.map((e,t)=>{let n=g(e.info,f(e),r.from,r.to),i=x(e.info.key,s);return{id:e.id,label:Z(e),kind:e.info.kind===`boolean`?`boolean`:`enum`,colorIndex:e.info.kind===`boolean`?t:0,states:n.states,segments:n.segments,totals:n.totals,stateLabel:e.info.kind===`boolean`?e=>e===`true`?i.on:i.off:void 0}}),v=e.energy.map(e=>({c:e,...ie(f(e))})),b=v[0]?.bucketMs??36e5,C=[...new Set(v.flatMap(e=>e.buckets.map(e=>e.t)))].sort((e,t)=>e-t).map(e=>({t:e,values:v.map(t=>t.buckets.find(t=>t.t===e)?.values[0]??null)}));return n(`div`,{className:`space-y-5 min-w-0`,children:[m.length>0&&i(O,{title:o(`history.page.someFailed`,`Some series could not be read`),message:m.map(e=>`${Z(e.c)}: ${e.e.error}`).join(` · `)}),h.length>0&&i(y,{title:o(`history.page.lines`,`Measurements`),series:h,range:r,height:260,syncKey:X,pending:p}),v.length>0&&i(V,{title:o(`history.page.energy`,`Energy`),layers:v.map((e,t)=>({id:e.c.id,label:e.c.subjectName,colorIndex:t})),buckets:C,bucketMs:b,range:r,unit:`kWh`,showTotal:!0,height:160,syncKey:X,pending:p}),_.length>0&&i(M,{title:_.length===1?_[0]?.label??``:o(`history.page.states`,`States`),rows:_,range:r,syncKey:X,pending:p})]})}e();var Q=`device`,me=`node`;function he({catalog:e,selected:r,onChange:a,loading:o}){let{t:s}=W(),c=I(e,{searchText:e=>[se(e)],facetGroups:[{id:`subject`,value:e=>e.ref.subject.kind===`device`?Q:me},{id:`room`,value:e=>e.location},{id:`unit`,value:e=>e.info.unit??``}]}),l=t(()=>[{key:`metric`,header:s(`history.picker.series`,`Series`),render:e=>n(`div`,{className:`min-w-0`,children:[i(`div`,{className:`truncate text-foreground`,children:e.metric}),i(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.location===``?e.subjectName:`${e.subjectName} · ${e.location}`})]}),sortValue:e=>`${e.subjectName} ${e.metric}`},{key:`unit`,header:s(`history.picker.unit`,`Unit`),render:e=>i(`span`,{className:`text-foreground-muted`,children:e.info.unit??`—`}),sortValue:e=>e.info.unit??``}],[s]),u=r.size>=24;return n(`div`,{className:`space-y-2 min-w-0`,children:[i(z,{state:c.state,facets:[],groups:[{...c.groups.find(e=>e.id===`subject`)??{id:`subject`,facets:[],selected:[]},label:s(`history.picker.subject`,`Source`),facetLabel:e=>e===Q?s(`history.picker.devices`,`Devices`):s(`history.picker.nodes`,`Nodes`)},{...c.groups.find(e=>e.id===`room`)??{id:`room`,facets:[],selected:[]},label:s(`history.picker.room`,`Room`),facetLabel:e=>e===``?s(`history.picker.noRoom`,`No room`):e},{...c.groups.find(e=>e.id===`unit`)??{id:`unit`,facets:[],selected:[]},label:s(`history.picker.metricType`,`Unit`),facetLabel:e=>e===``?s(`history.picker.noUnit`,`States & counts`):e}],labels:{searchPlaceholder:s(`history.picker.search`,`Search device, room, metric or node…`),searchLabel:s(`history.picker.searchLabel`,`Search series`),facetsLabel:s(`history.picker.facets`,`Filters`),clearLabel:s(`history.picker.clear`,`Clear`)},onSearch:c.setSearch,onToggleFacet:c.toggleFacet,onToggleGroupFacet:c.toggleGroupFacet,onClear:c.clear}),i(`p`,{className:`text-[10px] text-foreground-subtle`,"aria-live":`polite`,children:s(`history.picker.count`,`{{count}} of {{max}} selected`,{count:r.size,max:24})}),i(A,{columns:l,rows:c.rows,rowKey:e=>e.id,maxBodyHeight:w,pageSize:50,defaultSort:{columnKey:`metric`,dir:`asc`},emptyMessage:o?s(`history.picker.loading`,`Reading the series of every device…`):c.active?s(`history.picker.emptyFiltered`,`No series match these filters.`):s(`history.picker.empty`,`Nothing is recorded yet.`),selection:{selected:r,onChange:e=>{let t=[...e].filter(e=>r.has(e)),n=[...e].filter(e=>!r.has(e));a(new Set([...t,...n].slice(0,24)))},isSelectable:e=>r.has(e.id)||!u,rowLabel:e=>`${e.subjectName} · ${e.metric}`,pageLabel:s(`history.picker.selectPage`,`Select every series on this page`)}})]})}e();var ge=new Set([f.Hub,f.Container]),$=5*6e4;function _e(){let{t:e}=W(),r=ne(`device-history`),[a,c]=G(),d=t(()=>H(a.getAll(`s`).flatMap(e=>{let t=k(e);return t===null?[]:[t]})),[a]),f=a.get(`window`),g=N(f)?f:`7d`,v=m(a.get(`range`)),y=(e,t,n)=>{let r=new URLSearchParams;for(let t of H(e))r.append(`s`,ee(t));t!==`7d`&&r.set(`window`,t);let i=n===void 0?a.get(`range`):n;t===`custom`&&i&&r.set(`range`,i),c(r,{replace:!0})},x=ve(r===`present`),S=p(g,Date.now(),v),C=p(g,te(Date.now(),S.to-S.from),v),w=t(()=>fe(d,x.candidates),[d,x.candidates]),E=t(()=>new Set(d.map(U)),[d]),D=B(),A=h(),M=_(),I=async()=>{let t=await A({title:e(`history.page.saveTitle`,`Save as panel`),label:e(`history.page.saveName`,`Panel name`),confirmLabel:e(`history.page.save`,`Save`)});t===null||t.trim()===``||await D.update(e=>T(e,{id:`panel-${Date.now().toString(36)}`,name:t.trim().slice(0,80),window:g,selection:[...d]}))},L=async(t,n)=>{await M({title:e(`history.page.deleteTitle`,`Delete panel`),message:e(`history.page.deleteMessage`,`The panel "{{name}}" is removed from your account.`,{name:n}),confirmLabel:e(`history.page.delete`,`Delete`),variant:`danger`})&&await D.update(e=>ae(e,t))},z=t=>t===`energy`?e(`history.panels.energy`,`Total energy`):t===`temperatures`?e(`history.panels.temperatures`,`Temperatures by room`):t===`nodes`?e(`history.panels.nodes`,`Cluster nodes`):e(`history.panels.storage`,`Storage locations`);return i(K,{icon:l,title:e(`history.page.title`,`History`),subtitle:e(`history.page.subtitle`,`What devices, nodes and storage recorded over time, side by side.`),actions:r===`present`?n(j,{size:`sm`,variant:`outline`,onClick:()=>void I(),disabled:d.length===0||!D.writable,children:[i(s,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),e(`history.page.saveTitle`,`Save as panel`)]}):void 0,children:r===`pending`?i(F,{className:`h-64 w-full`}):r===`unknown`?i(O,{title:e(`history.page.presenceUnknownTitle`,`Could not reach the hub`),message:e(`history.page.presenceUnknown`,`The hub did not say whether device history is installed. Try again in a moment.`)}):r===`absent`?i(R,{icon:u,title:e(`history.page.absentTitle`,`Device history is not running on this hub`),description:e(`history.page.absent`,`Nothing is recorded until the device-history system addon is enabled.`)}):n(`div`,{className:`space-y-3 sm:space-y-4`,children:[n(`div`,{className:`flex flex-wrap items-center gap-2`,role:`group`,"aria-label":e(`history.page.panels`,`Panels`),children:[ce.map(e=>i(j,{size:`sm`,variant:`outline`,disabled:x.status!==`ok`,onClick:()=>y(de(e,x.candidates),g),children:z(e)},e)),D.value.panels.map(t=>n(`span`,{className:`inline-flex items-center`,children:[i(j,{size:`sm`,variant:`secondary`,onClick:()=>y(t.selection,t.window,null),children:t.name}),i(j,{size:`sm`,variant:`ghost`,"aria-label":e(`history.page.deleteNamed`,`Delete panel {{name}}`,{name:t.name}),onClick:()=>void L(t.id,t.name),disabled:!D.writable,children:i(o,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})]},t.id))]}),n(`div`,{className:`grid grid-cols-1 gap-3 sm:gap-4 xl:grid-cols-5`,children:[i(`div`,{className:`min-w-0 xl:col-span-2`,children:i(P,{headingId:`history-picker`,title:e(`history.picker.title`,`Series`),children:i(`div`,{className:`p-2 sm:p-3`,children:x.status===`error`?i(O,{message:x.error}):i(he,{catalog:x.candidates,loading:x.status===`pending`,selected:E,onChange:e=>{let t=d.filter(t=>e.has(U(t))),n=x.candidates.filter(t=>e.has(t.id)&&!E.has(t.id)).map(e=>e.ref);y([...t,...n],g)}})})})}),i(`div`,{className:`min-w-0 xl:col-span-3`,children:i(P,{headingId:`history-overlay`,title:e(`history.page.overlay`,`Overlay`),actions:d.length>0?i(j,{size:`sm`,variant:`ghost`,onClick:()=>y([],g),children:e(`history.page.clear`,`Clear`)}):void 0,children:n(`div`,{className:`p-2 sm:p-3 space-y-3 min-w-0`,children:[i(re,{value:g,onChange:e=>y(d,e),custom:v,onCustomChange:e=>y(d,`custom`,b(e))}),x.status===`pending`&&d.length>0?i(F,{className:`h-64 w-full`}):i(pe,{part:w,window:C}),w.missing.length>0&&x.status===`ok`&&i(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`history.page.missing`,{count:w.missing.length,defaultValue_one:`{{count}} selected series is no longer recorded.`,defaultValue_other:`{{count}} selected series are no longer recorded.`})})]})})})]})]})})}function ve(e){let{t:n}=W(),i=n(`history.picker.wholeFrame`,`Whole frame`),a=c().trpcClient,o=v({projection:`slim`},{enabled:e,staleTime:$}),{nodes:s}=C(),l=t(()=>(o.data??[]).filter(e=>!ge.has(String(e.type))),[o.data]),u=r({queries:l.map(t=>({queryKey:[`device-history`,`listSeries`,t.id],queryFn:()=>a.deviceHistory.listSeries.query({deviceId:t.id}),enabled:e,staleTime:$}))}),f=r({queries:s.map(t=>({queryKey:[`device-history`,`listNodeSeries`,t.id],queryFn:()=>a.deviceHistory.listNodeSeries.query({forNodeId:t.id}),enabled:e,staleTime:$}))}),p=E({},{enabled:e,staleTime:$}),m=t(()=>new Map((p?.data??[]).map(e=>[e.id,e.displayName])),[p?.data]),h=u.map(e=>e.data),g=f.map(e=>e.data),_=t(()=>oe(l.flatMap((e,t)=>{let n=h[t];return n===void 0?[]:[{device:{id:e.id,name:e.name,location:e.location??null},series:n}]}),s.flatMap((e,t)=>{let n=g[t];return n===void 0?[]:[{node:{id:e.id,name:e.name},series:n}]}),e=>{if(e.key!==`addon:pipeline-analytics/occupancy`)return m.get(e.scope)??e.scope;let{zoneId:t,className:n}=d(e.scope),r=t===``?i:t;return n===void 0?r:`${r} · ${n}`}),[l,s,m,[...u,...f].map(e=>e.dataUpdatedAt).join(`,`),i]);return o.status===`error`?{status:`error`,error:o.error.message,candidates:[]}:{status:o.status===`pending`||u.some(e=>e.isPending)||f.some(e=>e.isPending)?`pending`:`ok`,error:``,candidates:_}}export{_e as HistoryPage};