@camstack/addon-admin-ui 1.2.330 → 1.2.331

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 (88) hide show
  1. package/dist/assets/{AddonCollectionPage-BGvPXFd4.js → AddonCollectionPage-DpIQBL-z.js} +1 -1
  2. package/dist/assets/{Addons-BE5HX8Kh.js → Addons-DV6azXtV.js} +1 -1
  3. package/dist/assets/{AdminTabs-BFluDHSH.js → AdminTabs-CIqJ81O1.js} +1 -1
  4. package/dist/assets/{AiProfiles-BtP_LFHX.js → AiProfiles-DeT1Enb2.js} +1 -1
  5. package/dist/assets/{BrokerForm-f8H7gEpR.js → BrokerForm-Dys69RO8.js} +1 -1
  6. package/dist/assets/{Build-dd9955Wj.js → Build-ByaMsUZu.js} +1 -1
  7. package/dist/assets/{Calendars-C927RnBR.js → Calendars-aLTbzETg.js} +1 -1
  8. package/dist/assets/{Capabilities-BtJb_WbI.js → Capabilities-vKNWJXIH.js} +1 -1
  9. package/dist/assets/{Cluster-B4GCwbTO.js → Cluster-CM_TU9eP.js} +1 -1
  10. package/dist/assets/{CompositionEditor-BmBT-tSk.js → CompositionEditor-DjaR5c8a.js} +1 -1
  11. package/dist/assets/{CompositionEditorPage-BWjd2jy7.js → CompositionEditorPage-DUNmLk9Z.js} +1 -1
  12. package/dist/assets/{Data-B3iSwwht.js → Data-Co1Ru5wl.js} +1 -1
  13. package/dist/assets/{DetectionIntelligence-qyghT3Ii.js → DetectionIntelligence-wOP9P-Rx.js} +1 -1
  14. package/dist/assets/DeviceDetail-Cp6xqV94.js +2 -0
  15. package/dist/assets/{DeviceDoActionFields-B19O_9BT.js → DeviceDoActionFields-B-UaI7n-.js} +1 -1
  16. package/dist/assets/{Devices-BBtYW5yf.js → Devices-CKSZmwEn.js} +1 -1
  17. package/dist/assets/{EmbedPlayerPage-ec76Ypbl.js → EmbedPlayerPage-DLsOxS55.js} +1 -1
  18. package/dist/assets/{Events-BzcQa4ah.js → Events-Dyc68nae.js} +1 -1
  19. package/dist/assets/{Identity-CVrfKg6B.js → Identity-D9V5bdov.js} +1 -1
  20. package/dist/assets/{IntegrationDetail-CqtmCE70.js → IntegrationDetail-dT9dySHX.js} +1 -1
  21. package/dist/assets/{Integrations-CtB9iyXd.js → Integrations-DRcMDP4-.js} +1 -1
  22. package/dist/assets/{Integrations-C_YdoSjA.js → Integrations-DVuPFBKi.js} +1 -1
  23. package/dist/assets/{Locations-CBtkkmU4.js → Locations-bMH9yI6x.js} +1 -1
  24. package/dist/assets/{Logs-McOzfwf5.js → Logs-DAXcD2Ag.js} +1 -1
  25. package/dist/assets/{MotionZonesSettings-C_FvegYU.js → MotionZonesSettings-CiD4d9Ko.js} +1 -1
  26. package/dist/assets/{MyAccess-CsJBJSi-.js → MyAccess-Od0asOaP.js} +1 -1
  27. package/dist/assets/{Network-ZXyeOelt.js → Network-BZoW2JSJ.js} +1 -1
  28. package/dist/assets/{NodeAddonsSettingsPanel-C56sPvtL.js → NodeAddonsSettingsPanel-DuTlgAWG.js} +1 -1
  29. package/dist/assets/{NodeInferenceDevices-Bqo-7570.js → NodeInferenceDevices-DG7m5Y7w.js} +1 -1
  30. package/dist/assets/{Notifications-YukSowyX.js → Notifications-DDG3Z8FY.js} +1 -1
  31. package/dist/assets/Pipeline-DMtisKG3.js +1 -0
  32. package/dist/assets/{Plates-DmFSQNFe.js → Plates-DKbIAPin.js} +1 -1
  33. package/dist/assets/{PrivacyMaskSettings-DYJX-Ljr.js → PrivacyMaskSettings-CEoJQQNL.js} +1 -1
  34. package/dist/assets/{Recordings-PkJ0G8NB.js → Recordings-B5326osa.js} +1 -1
  35. package/dist/assets/{ScanNetworkModal-DKwhvvYq.js → ScanNetworkModal-JEhQBxc0.js} +1 -1
  36. package/dist/assets/{SceneMonitorEditor-B4-zs3WA.js → SceneMonitorEditor-C7nLYtWS.js} +1 -1
  37. package/dist/assets/{Scenes-BJHNURPw.js → Scenes-BpPVAE-1.js} +1 -1
  38. package/dist/assets/{Settings-DahXgC20.js → Settings-CfK7VUrn.js} +1 -1
  39. package/dist/assets/{Showroom-DHNwi9pE.js → Showroom-Ci8uBRT6.js} +1 -1
  40. package/dist/assets/{StorageLocationsPanel-Bu7c32vF.js → StorageLocationsPanel-CZTMZPVY.js} +1 -1
  41. package/dist/assets/{Terminal-AF4QYRZZ.js → Terminal-BPhklMPi.js} +1 -1
  42. package/dist/assets/{Viewer-C1-4AVSD.js → Viewer-DKC1UyF1.js} +1 -1
  43. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DXbI3DPG.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-xWBvqyND.js} +1 -1
  44. package/dist/assets/{archive-gWBFIT2D.js → archive-Cudlo5P7.js} +1 -1
  45. package/dist/assets/{authed-media-CkAe7M1O.js → authed-media-Bf77DHiU.js} +1 -1
  46. package/dist/assets/{boxes-BMaw7T0C.js → boxes-DIXdAt9T.js} +1 -1
  47. package/dist/assets/circle-slash-dArMQdeW.js +1 -0
  48. package/dist/assets/{debounced-invalidate-C04KV_wn.js → debounced-invalidate-CHSCMizx.js} +1 -1
  49. package/dist/assets/{device-integration-icon-C4GjLB9n.js → device-integration-icon-D0JHl1uT.js} +1 -1
  50. package/dist/assets/device-picker-model-C3GxEmbZ.js +1 -0
  51. package/dist/assets/{dist-DK0k4z5N.js → dist-C99tjf3g.js} +1 -1
  52. package/dist/assets/dist-CUXVcnid.js +357 -0
  53. package/dist/assets/{face-bbox-Dg6C7OMO.js → face-bbox-B9Tyg9NW.js} +1 -1
  54. package/dist/assets/{hard-drive-download-Cpu8d8G_.js → hard-drive-download-Dc_abYTk.js} +1 -1
  55. package/dist/assets/{hostInit-D-LMJAGD.js → hostInit-D6ltpv22.js} +1 -1
  56. package/dist/assets/{index-CfVrkT4q.js → index-wFUqYEfd.js} +3 -3
  57. package/dist/assets/{layers-ByvtFPPP.js → layers-BKQnUkD2.js} +1 -1
  58. package/dist/assets/{location-owned-usage-1THZb4ah.js → location-owned-usage-BWn9-eob.js} +1 -1
  59. package/dist/assets/{mf-entry-bootstrap-0-7d1d99d4.js → mf-entry-bootstrap-0-4930a9c7.js} +2 -2
  60. package/dist/assets/mount-C3GxEmbZ.js +1 -0
  61. package/dist/assets/{notification-schedule-field-D6mKEw0W.js → notification-schedule-field-BzLlAfqp.js} +1 -1
  62. package/dist/assets/{player-overlays-CEHVDSJu.js → player-overlays-BHG5CSFQ.js} +1 -1
  63. package/dist/assets/remoteEntry-DRuu7Vh_.js +1 -0
  64. package/dist/assets/{send-DagoqhTj.js → send-BDpImfaU.js} +1 -1
  65. package/dist/assets/{settings-2-b3j8Pwfi.js → settings-2-CR-WDPMe.js} +1 -1
  66. package/dist/assets/{square-check-big-CN0Jzq_i.js → square-check-big-CsHHs7_N.js} +1 -1
  67. package/dist/assets/src-BpnJ-sMW.js +357 -0
  68. package/dist/assets/src-De0k1ip_.js +67 -0
  69. package/dist/assets/{use-scenes-feed-Dptn_Cyw.js → use-scenes-feed-Bo_WZsYm.js} +1 -1
  70. package/dist/assets/{use-stationary-objects-CxxpG4_u.js → use-stationary-objects-Da0t43FO.js} +1 -1
  71. package/dist/assets/useEventInvalidation-C3GxEmbZ.js +1 -0
  72. package/dist/assets/{useNodeUrlSelection-DUkN1GGf.js → useNodeUrlSelection-CBUJxmpe.js} +1 -1
  73. package/dist/assets/user-round-B_-xKzQ7.js +1 -0
  74. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CnR6eZYL.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-Cz-1ztlx.js} +2 -2
  75. package/dist/index.html +7 -7
  76. package/dist/server/addon.js +70 -47
  77. package/package.json +1 -1
  78. package/dist/assets/DeviceDetail-BZ7nk5VG.js +0 -2
  79. package/dist/assets/Pipeline-DLRmcN_Q.js +0 -1
  80. package/dist/assets/circle-slash-exzl9yW0.js +0 -1
  81. package/dist/assets/device-picker-model-Ds54E7eB.js +0 -1
  82. package/dist/assets/dist-2wXmuZBO.js +0 -357
  83. package/dist/assets/mount-Ds54E7eB.js +0 -1
  84. package/dist/assets/remoteEntry-xb8EJH2S.js +0 -1
  85. package/dist/assets/src-CQ9R75CO.js +0 -67
  86. package/dist/assets/src-DDxhrhKR.js +0 -357
  87. package/dist/assets/useEventInvalidation-Ds54E7eB.js +0 -1
  88. package/dist/assets/user-round-CkMm4TOh.js +0 -1
@@ -1,2 +0,0 @@
1
- import{I as e,K as t,Q as n,S as r,W as i,a,b as o,o as s,q as c,t as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{G as f,U as p,W as m,X as h,_t as g,at as _,lt as v,mt as y,q as b,r as x,st as S,t as C,ut as w,vt as T}from"./player-overlays-CEHVDSJu.js";import{$t as E,A as D,As as O,At as k,Bt as A,C as j,Cn as M,Co as N,Cu as P,Dd as F,Du as ee,El as te,Ft as I,G as ne,Ga as L,Gi as R,Hd as z,Hi as re,Hn as ie,Ht as ae,Hu as B,It as V,J as oe,Jt as H,Ki as se,Kt as ce,Li as le,Ls as ue,Lt as de,M as fe,Mi as pe,Mt as me,N as he,Nu as ge,Od as _e,Os as ve,P as ye,Pn as be,Pt as U,Pu as W,Qs as xe,Qt as Se,Ri as Ce,Rt as we,S as Te,Sl as Ee,Su as De,Tl as Oe,To as ke,Tu as Ae,U as G,Ua as je,V as Me,Vi as Ne,W as Pe,Wa as Fe,Wi as Ie,X as Le,Xl as Re,Xt as ze,Z as Be,Zi as Ve,Zt as He,Zu as Ue,_i as We,_u as Ge,a as Ke,an as qe,as as Je,at as Ye,au as Xe,b as Ze,bi as Qe,bl as $e,bn as et,c as tt,ci as nt,cs as rt,dd as it,dt as at,ea as ot,et as st,f as ct,fs as lt,fu as ut,ga as dt,gi as ft,gn as pt,gs as mt,hl as ht,hn as gt,ho as _t,ht as vt,i as yt,id as bt,in as xt,jd as St,js as Ct,jt as wt,kd as Tt,ki as Et,kl as Dt,kn as Ot,kr as kt,ks as At,l as jt,ls as Mt,lt as Nt,md as Pt,mn as Ft,mt as It,mu as Lt,ni as Rt,nn as zt,nt as Bt,o as Vt,oa as Ht,os as Ut,ot as Wt,pa as Gt,pi as Kt,pr as qt,pt as Jt,pu as Yt,q as Xt,qt as Zt,r as Qt,rd as $t,ri as en,rn as tn,s as nn,si as rn,st as an,su as on,u as sn,ut as cn,vn as ln,w as un,wn as dn,wt as fn,wu as pn,x as mn,xi as hn,xt as gn,ya as _n,yd as vn,yi as yn,yn as bn,z as xn,za as Sn,zt as Cn}from"./src-CQ9R75CO.js";import{t as wn}from"./archive-gWBFIT2D.js";import{t as Tn}from"./boxes-BMaw7T0C.js";import{t as En}from"./circle-slash-exzl9yW0.js";import{n as Dn}from"./NodeInferenceDevices-Bqo-7570.js";import{t as On}from"./layers-ByvtFPPP.js";import{Bt as kn,Fr as An,Hn as jn,Ht as Mn,In as Nn,Jt as Pn,On as Fn,Pr as In,Qn as K,Rn as Ln,Ut as Rn,Vt as zn,Wn as Bn,Yn as Vn,Yt as Hn,Zn as Un,Zt as Wn,_n as Gn,dr as Kn,fr as qn,gn as Jn,nr as q,rr as J,tr as Yn,vn as Xn,zt as Zn}from"./src-DDxhrhKR.js";import{t as Y}from"./useTranslation-Bc5yH9V9.js";import"./mount-Ds54E7eB.js";import{A as Qn,C as $n,D as er,F as tr,I as nr,M as rr,N as ir,O as ar,P as or,R as sr,S as cr,T as lr,d as ur,f as dr,g as fr,h as pr,i as mr,j as hr,k as gr,m as _r,n as vr,o as yr,p as br,u as xr,w as Sr}from"./index-CfVrkT4q.js";import{C as Cr,D as wr,E as Tr,S as X,_ as Er,a as Dr,b as Or,c as kr,d as Ar,f as jr,g as Mr,h as Nr,i as Pr,l as Fr,m as Ir,n as Lr,o as Rr,p as zr,r as Br,s as Vr,t as Hr,u as Ur,v as Wr,x as Gr,y as Kr}from"./CompositionEditor-BmBT-tSk.js";import{t as qr}from"./authed-media-CkAe7M1O.js";import"./useEventInvalidation-Ds54E7eB.js";import{t as Jr}from"./StatusBadge-CeptlsPG.js";import{t as Yr}from"./use-stationary-objects-CxxpG4_u.js";import"./device-picker-model-Ds54E7eB.js";var Xr=T(`arrow-left-right`,[[`path`,{d:`M8 3 4 7l4 4`,key:`9rb6wj`}],[`path`,{d:`M4 7h16`,key:`6tx8e3`}],[`path`,{d:`m16 21 4-4-4-4`,key:`siv7j2`}],[`path`,{d:`M20 17H4`,key:`h6l3hr`}]]),Zr=T(`disc`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}]]),Qr=T(`ear`,[[`path`,{d:`M6 8.5a6.5 6.5 0 1 1 13 0c0 6-6 6-6 10a3.5 3.5 0 1 1-7 0`,key:`1dfaln`}],[`path`,{d:`M15 8.5a2.5 2.5 0 0 0-5 0v1a2 2 0 1 1 0 4`,key:`1qnva7`}]]);n();function $r(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 ei(e){if(typeof e!=`object`||!e)return null;let t=e.switches;if(!Array.isArray(t))return null;let n=t.map($r).filter(e=>e!==null);return n.length===0?null:n}var ti=[[/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 ni(e){for(let[t,n]of ti)if(t.test(e))return n;return`generic`}function ri(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(`Off: ${r(t)}`),n.length>0&&i.push(`Unknown: ${r(n)}`),{offIds:t,unknownIds:n,summary:i.length===0?`All camera functions on`:i.join(` · `)}}var ii={stream:Lt,detection:sr,privacy:y,microphone:w,speaker:Dt,listening:Qr,archive:wn,recording:Zr,notifications:F,generic:Re};function ai({deviceId:t}){let n=s(),i=Number.isFinite(t),[a,o]=c(null),[l,d]=c(!1),f=Mt({deviceId:t},{enabled:i});Qt([`pipelineOrchestrator`,`getCameraSwitches`],[`capability.binding-changed`]);let p=ei(f.data),m=Ct({onError:(e,r)=>{console.error(`[CameraFunctionSwitches] switch write failed — reverting`,{tags:{deviceId:t},meta:{switchId:r.switchId,error:e instanceof Error?e.message:String(e)}}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSwitches`]]}),o({id:r.switchId,message:e instanceof Error?e.message:String(e)})},onSuccess:()=>{o(null),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]}),n.invalidateQueries({queryKey:[[`deviceManager`]]}),n.invalidateQueries({queryKey:[[`recording`]]})}}),h=e(e=>{!e.available||e.on===null||m.mutate({deviceId:t,switchId:e.id,enabled:!e.on})},[t,m]);if(p===null)return null;let g=ri(p),_=e=>a?.id===e.id?a.message:null;return r(we,{open:l,onOpenChange:d,children:[r(A,{"aria-label":`Camera functions`,title:g.summary,className:`inline-flex items-center gap-1 rounded-lg border px-2 py-1.5 text-[11px] font-medium transition-colors ${a===null?g.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:[u(Re,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden lg:inline`,children:`Functions`}),g.offIds.length>0&&r(`span`,{className:`rounded bg-warning/20 px-1 text-[9px] font-semibold uppercase tracking-wide`,children:[g.offIds.length,` off`]})]}),r(Cn,{className:`left-auto right-0 mt-1 min-w-[240px] max-h-[60vh] overflow-y-auto p-1`,children:[u(`div`,{className:`px-2 py-1 text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Camera functions`}),u(`ul`,{className:`space-y-0.5`,children:p.map(e=>u(`li`,{children:u(oi,{row:e,failure:_(e),onToggle:()=>h(e)})},e.id))})]})]})}function oi({row:e,failure:t,onToggle:n}){let i=ii[ni(e.label)],a=e.on===null,o=e.on===!1,s=t===null?a?e.unavailableReason??`The source that owns this did not answer.`:e.costWhenOff:`Write failed: ${t}`,c=t===null?a?e.unavailableReason??`unknown`:null:`write failed`;return r(`button`,{type:`button`,role:`switch`,"aria-label":e.label,"aria-checked":e.on===!0,disabled:!e.available,onClick:n,title:s,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:[u(i,{className:`h-3.5 w-3.5 shrink-0 ${t===null?a?`text-foreground-subtle/50`:o?`text-warning`:`text-success`:`text-danger`}`}),r(`span`,{className:`flex-1 min-w-0 truncate`,children:[e.label,c!==null&&r(`span`,{className:`ml-1 text-[10px] text-foreground-subtle`,children:[`· `,c]})]}),u(`span`,{className:`shrink-0 rounded px-1 py-0.5 text-[9px] font-semibold uppercase tracking-wide ${a?`bg-surface-hover text-foreground-subtle/60`:o?`bg-warning/20 text-warning`:`bg-success/20 text-success`}`,children:a?`—`:o?`off`:`on`})]})}function si({deviceId:e}){let t=Le(_().trpcClient,e);return t===null?null:r(`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:[u(Ue,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden sm:inline`,children:t.label})]})}function ci({parentDeviceId:e}){let{t}=Y(),n=ir(),i=_(),{data:a,isLoading:o,isError:s}=lr(e),{data:c}=Ne({deviceId:e},{enabled:Number.isFinite(e)});if(o)return u(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:u(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(s)return u(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:u(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let l=(a??[]).filter(e=>e.display?.hidden!==!0);if(l.length===0)return null;let d=ne(c?.stableId??``,l,c?.childLayout),f=d.ungrouped,p=e=>n(`/devices/${String(e)}`),m=c?.name??``,h=(e,t)=>u(G,{trpc:i.trpcClient,device:{...t,name:Be(t,m)},variant:`minimal`,onNavigate:p},e),g=f.some(e=>!!e.role),v=f.some(e=>!e.role),y=g&&!v?t(`device.accessories`,{defaultValue:`Accessories`}):!g&&v?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),b=f.length>0?r(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[u(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:y}),u(`div`,{className:`space-y-1`,children:f.map(e=>h(e.id,e))})]}):null,x=d.disabledSection===void 0?null:u(Pe,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:d.disabledSection.children.length,defaultOpen:!1,children:u(`div`,{className:`opacity-60 space-y-1`,children:d.disabledSection.children.map(e=>h(e.id,e))})},d.disabledSection.title);if(d.sections.length===0)return x===null?b:r(`div`,{className:`space-y-2`,children:[b,x]});let S=v&&!g;return r(`div`,{className:`space-y-2`,children:[S?b:null,d.sections.map(e=>u(Pe,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>h(e.id,e))},e.title)),S?null:b,x]})}function li({deviceId:e}){let t=_(),{data:n,isLoading:r}=Sr(e),{data:i,isLoading:a}=lr(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?u(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):u(`div`,{className:`flex h-full w-full flex-col`,children:u(Ye,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}n();function ui({dev:e,busy:t,setBusy:n}){let i=e?.motionTrigger,a=b(e?.state.motionTrigger),[o,s]=c(!1);if(!i)return null;let l=a?.enabled===!0,d=a!==void 0,f=async()=>{if(t||!d)return;let e=!l;n(!0),s(!0);try{await i.setMotionTrigger({enabled:e})}finally{n(!1),s(!1)}};return r(`button`,{type:`button`,onClick:()=>{f()},disabled:t||!d,title:d?l?`Disable trigger on motion`:`Enable trigger on motion`:`Awaiting state…`,"aria-pressed":l,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 ${l?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground`}`,children:[u(z,{className:`h-3 w-3`}),u(`span`,{children:o?l?`Disabling…`:`Enabling…`:d?l?`On motion: on`:`On motion: off`:`On motion: …`})]})}n();function Z({deviceId:e,deviceType:t,features:n}){let i=_(),a=Nt(t)?.HeroCard??cn,o=f(i.trpcClient,e),s=b(o?.state.deviceStatus),[l,d]=c(!1),p=s!==void 0&&s.online===!1,m=p?s.lastChangedAt:null;return r(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[p?u(`div`,{className:`flex justify-center`,children:u(an,{lastChangedAt:m})}):null,u(a,{trpc:i.trpcClient,deviceId:e,features:n}),u(`div`,{className:`flex justify-center`,children:u(ui,{dev:o,busy:l,setBusy:d})})]})}function di({deviceId:e,features:t}){return u(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:u(at,{trpc:_().trpcClient,deviceId:e,features:t})})}function fi({deviceId:e,features:t}){return u(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:u(cn,{trpc:_().trpcClient,deviceId:e,features:t})})}function pi(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}function mi(e){if(!e)return null;let t=pi(e.data);return t===null?e.eventType:`Button ${String(t)} · ${e.eventType}`}var hi=1e3,gi=60*hi,_i=60*gi,vi=24*_i;function yi(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<hi?`just now`:n<gi?`${String(Math.floor(n/hi))}s ago`:n<_i?`${String(Math.floor(n/gi))}m ago`:n<vi?`${String(Math.floor(n/_i))}h ago`:`${String(Math.floor(n/vi))}d ago`}n();var bi=1500,xi=15e3,Si=1e3;function Ci({deviceId:e}){let n=f(_().trpcClient,e)?.state.eventEmitter,i=b(n);d(()=>{if(!n)return;n.refresh();let e=setInterval(()=>{n.refresh()},xi);return()=>{clearInterval(e)}},[n]);let a=i?.lastEvent??null,o=a?.seq??null,s=t(null),[l,p]=c(!1);d(()=>{if(o===null)return;let e=s.current;if(s.current=o,e===null||e===o)return;p(!0);let t=setTimeout(()=>{p(!1)},bi);return()=>{clearTimeout(t)}},[o]);let[m,h]=c(()=>Date.now());d(()=>{let e=setInterval(()=>{h(Date.now())},Si);return()=>{clearInterval(e)}},[]);let g=mi(a),v=i?.eventTypes??[],y=i?.eventCountSinceStart??0,x=i!==void 0,S=pi(a?.data);return r(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 p-4`,children:[u(`div`,{"data-testid":`event-emitter-indicator`,"data-flashing":String(l),className:`flex h-24 w-24 items-center justify-center rounded-full border-2 transition-all ${l?`border-primary bg-primary/20 text-primary shadow-lg shadow-primary/30 scale-105`:`border-border bg-surface text-foreground-subtle`}`,"aria-live":`polite`,title:g??`No press recorded`,children:u(l?pn:B,{className:`h-10 w-10`})}),r(`div`,{className:`text-center`,children:[S!==null&&u(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-primary`,children:`Button ${String(S)}`}),u(`div`,{"data-testid":`event-emitter-headline`,className:`text-sm font-semibold ${g?`text-foreground`:`text-foreground-subtle`}`,children:g??(x?`No press recorded`:`Awaiting state…`)}),u(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:a?yi(a.timestamp,m):`Waiting for the first event`})]}),v.length>0&&u(`div`,{className:`flex max-w-full flex-wrap justify-center gap-1`,children:v.map(e=>u(`span`,{"data-testid":`event-emitter-chip`,className:`rounded-full border px-2 py-0.5 text-[10px] font-medium ${e===a?.eventType?`border-primary bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle`}`,children:e},e))}),u(`div`,{className:`text-[10px] text-foreground-subtle`,children:`${String(y)} ${y===1?`event`:`events`} since start`})]})}function wi({deviceName:e,deviceType:t,provider:n,isOnline:i,features:a}){return r(`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:[u(Qn,{type:n,size:`lg`}),r(`div`,{children:[u(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),u(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),r(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[u(Jr,{status:i?`online`:`offline`}),a.length>0&&u(hr,{capabilities:a})]}),u(`div`,{className:`text-[10px] text-foreground-subtle italic max-w-xs mt-1`,children:`No live view for this device type. Use the Config tab or the shortcut row to interact.`})]})}n();function Ti({deviceId:e}){let t=s(),n=ft({deviceId:e},{refetchInterval:1e4,retry:!1}),a=We({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),o=i(()=>Ei(n.data??[]),[n.data]);return r(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[r(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[u(Di,{label:`Discovered`,value:o.total,icon:u(P,{className:`h-3.5 w-3.5`})}),u(Di,{label:`Adopted`,value:o.adopted,accent:`success`}),u(Di,{label:`Available`,value:o.available,accent:o.available>0?`primary`:void 0}),r(`button`,{type:`button`,onClick:()=>{a.mutateAsync({deviceId:e}).catch(()=>{})},disabled:a.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:[a.isPending?u(ge,{className:`h-3.5 w-3.5 animate-spin`}):u(Yt,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden sm:inline`,children:`Discover`})]})]}),r(`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:[u(Oi,{icon:u(Oe,{className:`h-3 w-3 text-emerald-500`}),label:`${o.online} online`}),u(Oi,{icon:u(Ae,{className:`h-3 w-3 text-amber-500`}),label:`${o.sleeping} sleeping`}),u(Oi,{icon:u(te,{className:`h-3 w-3 text-destructive`}),label:`${o.offline} offline`}),o.unknown>0?u(Oi,{icon:u(it,{className:`h-3 w-3 text-foreground-subtle`}),label:`${o.unknown} unknown`}):null]})]})}function Ei(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 Di({label:e,value:t,icon:n,accent:i}){return r(`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 ${i===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:i===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[r(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,u(`span`,{className:`truncate`,children:e})]}),u(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function Oi({icon:e,label:t}){return r(`span`,{className:`inline-flex items-center gap-1`,children:[e,u(`span`,{children:t})]})}var ki={[J.Switch]:Z,[J.Siren]:Z,[J.Light]:Z,[J.Sensor]:Z,[J.Button]:Z,[J.Hub]:Ti,[J.Cover]:di,[J.Valve]:Z,[J.Humidifier]:Z,[J.WaterHeater]:Z,[J.Container]:li,[J.Lock]:Z,[J.Fan]:Z,[J.Thermostat]:Z,[J.Climate]:Z,[J.MediaPlayer]:Z,[J.Control]:Z,[J.AlarmPanel]:Z,[J.EventEmitter]:Ci,[J.Notifier]:fi,[J.Script]:Z,[J.Automation]:Z,[J.Presence]:Z,[J.Update]:Z,[J.Vacuum]:Z,[J.LawnMower]:Z,[J.Weather]:Z,[J.Image]:Z,[J.PetFeeder]:Z};function Ai(e){return ki[e]??wi}function ji(e){return u(Ai(e.deviceType),{...e})}function Mi(e){return nn(_().trpcClient,e)}n();function Ni(n){let[r,i]=c(`idle`),[a,o]=c(null),s=t(null),l=t(null),u=t(null),f=t(!0),p=Fe(),m=je(),h=L(),g=e(()=>{if(s.current){try{s.current.close()}catch{}s.current=null}if(l.current){for(let e of l.current.getTracks())try{e.stop()}catch{}l.current=null}u.current=null},[]),_=e(async()=>{if(r===`idle`)return;i(`stopping`);let e=u.current;if(e&&n!==null)try{await Promise.race([h.mutateAsync({deviceId:n,sessionId:e}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}g(),f.current&&(i(`idle`),o(null))},[r,n,h,g]),v=e(async()=>{if(n===null||r!==`idle`&&r!==`error`)return;o(null);let e=null,t=null,a=null;try{i(`requesting-mic`),e=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),l.current=e,i(`starting`);let r=await p.mutateAsync({deviceId:n});a=r.sessionId,u.current=a,i(`connecting`),t=new RTCPeerConnection,s.current=t,t.oniceconnectionstatechange=()=>{if(!f.current)return;let e=t.iceConnectionState;e===`connected`||e===`completed`?i(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&f.current&&(o(e===`failed`?`WebRTC connection failed`:null),_())};for(let n of e.getAudioTracks())t.addTrack(n,e);await t.setRemoteDescription({type:`offer`,sdp:r.sdpOffer});let c=await t.createAnswer();await t.setLocalDescription(c);let d=t.localDescription?.sdp??c.sdp??``;await m.mutateAsync({deviceId:n,sessionId:a,sdpAnswer:d})}catch(r){let c=r instanceof Error?r.message:String(r);if(console.warn(`[intercom] start failed`,r),t)try{t.close()}catch{}if(e)for(let t of e.getTracks())try{t.stop()}catch{}if(s.current=null,l.current=null,a!==null)try{await h.mutateAsync({deviceId:n,sessionId:a})}catch{}u.current=null,f.current&&(o(c),i(`error`))}},[n,r,p,m,h,_]);return d(()=>(f.current=!0,()=>{f.current=!1;let e=u.current;if(e!==null&&n!==null&&h.mutate({deviceId:n,sessionId:e}),s.current){try{s.current.close()}catch{}s.current=null}if(l.current){for(let e of l.current.getTracks())try{e.stop()}catch{}l.current=null}u.current=null}),[n]),{state:r,error:a,start:v,stop:_,isTalking:r===`talking`}}n();var Pi=0;function Q(){return++Pi}function Fi(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function Ii(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 Li(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 Ri(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 zi({scope:n,greeting:i,className:a}){let o=_(),[s,f]=c(()=>{let e=[];return i&&e.push({id:Q(),kind:`info`,text:i}),e.push({id:Q(),kind:`info`,text:`scope: ${Fi(n)} — type help or context for available commands`}),e}),[p,m]=c(``),[h,g]=c([]),[v,y]=c(-1),b=t(null),x=t(null);d(()=>{let e=x.current;e&&(e.scrollTop=e.scrollHeight)},[s]);let S=e(()=>{b.current?.focus()},[]),C=l({mutationFn:e=>o.trpcClient.repl.execute.mutate({code:e,scope:n}),onSuccess:e=>{let t=e??{},n=typeof t.output==`string`?t.output:e==null?`undefined`:typeof e==`string`?e:JSON.stringify(e,null,2),r=t.type===`error`;f(e=>[...e,{id:Q(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);f(e=>[...e,{id:Q(),kind:`error`,text:t}])}});function w(e){let t=e.trim();if(t){if(t===`clear`){f([{id:Q(),kind:`info`,text:`scope: ${Fi(n)}`}]),m(``);return}if(t===`help`){f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`},...Ii(n).map(e=>({id:Q(),kind:`info`,text:e}))]),m(``);return}if(t===`context`){f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`},...Ri(n).map(e=>({id:Q(),kind:`info`,text:e}))]),m(``);return}if(t===`examples`){f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`},...Li(n).map(e=>({id:Q(),kind:`info`,text:e}))]),m(``);return}g(e=>[...e,t]),y(-1),f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`}]),m(``),C.mutate(t)}}function T(e){if(e.key===`Enter`){e.preventDefault(),w(p);return}if(e.key===`ArrowUp`){if(e.preventDefault(),h.length===0)return;let t=v===-1?h.length-1:Math.max(0,v-1);y(t),m(h[t]??``);return}if(e.key===`ArrowDown`){if(e.preventDefault(),v===-1)return;let t=v+1;t>=h.length?(y(-1),m(``)):(y(t),m(h[t]??``));return}e.ctrlKey&&e.key===`l`&&(e.preventDefault(),f([{id:Q(),kind:`info`,text:`scope: ${Fi(n)}`}]))}let E={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return r(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${a??``}`,onClick:S,children:[r(`div`,{ref:x,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[s.map(e=>u(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${E[e.kind]}`,children:e.text},e.id)),C.isPending&&u(`span`,{className:`text-zinc-500 animate-pulse`,children:`…thinking`})]}),r(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[u(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),u(`input`,{ref:b,value:p,onChange:e=>m(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 Bi(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}}}n();function Vi({deviceId:e,intercomAvailable:t=!1}){let n=_(),r=typeof window<`u`?h():``,a=Number.isFinite(e),s=Mi(a?e:null),c=Yr(a?[e]:[]),l=i(()=>{if(!a)return;let e=[];for(let t of c.rows){let n=Vt(t);n!==null&&e.push(n)}return e},[a,c.rows]),{streams:d,pipelineMetrics:f,createSession:p,sendAnswer:g,handleOffer:v,getIceServers:y,addIceCandidate:b,getIceCandidates:S,closeSession:C,getSessionState:w}=Ke(n.trpcClient,a?e:null),T=m(a?e:null,{width:Ki}),E=Ni(a&&t?e:null),D=E.state===`requesting-mic`||E.state===`starting`||E.state===`connecting`||E.state===`stopping`,O=E.isTalking||D,k=()=>{E.state===`idle`||E.state===`error`?E.start():E.state!==`stopping`&&E.stop()},A=x(),j=bn(),M=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,N=Bi(j.request,M),P=A.length>0?u(o,{children:A.map(e=>u(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return u(Te,{serverUrl:r,createSession:p,sendAnswer:g,handleOffer:v,getIceServers:y,addIceCandidate:b,getIceCandidates:S,closeSession:C,getSessionState:w,...N===null?{}:{...N,onExitPlayback:()=>j.clear()},streams:d,pipelineMetrics:f,phase:s.phase,detections:s,...l===void 0?{}:{stationaryObjects:l},defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:T.src,...T.src?{posterUrl:T.src}:{},snapshotLoading:T.loading,onRefreshSnapshot:T.refresh,intercomAvailable:t,intercomShown:O,onIntercomToggle:k,extraOverlay:P,chromeless:!0,className:`h-full`})}function Hi({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full`,children:u(vt,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function Ui({deviceId:e}){if(!Number.isFinite(e))return r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]});let t=[`CamStack REPL — device #${e}`,``,` device.state.battery.value sync state read`,` await device.snapshot.getSnapshot({}) cap action`,``,` type 'examples' for more, 'context' for the full API`].join(`
2
- `);return u(zi,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function Wi({deviceId:e}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:u(It,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function Gi({deviceId:e}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:u(Jt,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}var Ki=960;function qi(e){return new Set(e.filter(e=>{let t=e.nativeAddonId?.trim()??``;return t!==``&&t!==`composer`}).map(e=>e.capName))}function Ji(e){return e.kind===`known`?null:e}function Yi(e,t){return e.composable.kind===`known`?e.composable.value.has(t)?{kind:`present`,mode:`add`}:{kind:`absent`}:e.composable}function Xi(e){if(e.deviceType!==J.Camera)return{kind:`absent`};switch(e.cameraSensors){case`pending`:return{kind:`pending`};case`unknown`:return{kind:`unknown`,reason:`camera sensors could not be checked`};case`absent`:return{kind:`absent`};case`present`:return{kind:`present`,mode:`add`}}}function Zi(e,t){if(e===`motion`)return Xi(t);let n=Ji(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`}:Yi(t,`doorbell`);case`battery`:return r.has(`battery`)?{kind:`present`,mode:`replace`}:Yi(t,`battery`);case`consumables`:return r.has(`consumables`)?{kind:`absent`}:Yi(t,`consumables`)}}function Qi(e){if(e.status===`pending`)return{kind:`pending`};if(e.status===`error`)return{kind:`unknown`,reason:e.error?.message??`the request failed`};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=Ln(t.view.block);return n===null?{kind:`unknown`,reason:`block ${t.view.block.id} is not a composition`}:{kind:`present`,view:t.view,composition:n}}function $i(e){return e.kind===`present`?e.composition:null}function ea(e,t){let{hidden:n,...r}=e??{},i=t?{...r,hidden:!0}:r;return Object.keys(i).length===0?null:i}function ta(e){return typeof e.linkDeviceId==`number`}var na=new Set(Object.values(q));function ra(e){return na.has(e)}var ia={[J.Switch]:[q.Siren,q.Floodlight,q.Spotlight,q.PirSensor,q.Chime,q.Autotrack,q.Nightvision,q.PrivacyMask,q.BinaryHelper],[J.Light]:[q.Floodlight,q.Spotlight,q.Nightvision],[J.Siren]:[q.Siren],[J.Button]:[q.Doorbell],[J.Sensor]:[q.MotionSensor,q.ContactSensor,q.LeakSensor,q.SmokeSensor,q.COSensor,q.GasSensor,q.TamperSensor,q.VibrationSensor,q.ConnectivitySensor,q.SoundSensor,q.BinarySensor,q.TemperatureSensor,q.HumiditySensor,q.AmbientLightSensor,q.PressureSensor,q.WindSensor,q.RainSensor,q.UvSensor,q.SolarRadiationSensor,q.SoilMoistureSensor,q.PowerSensor,q.EnergySensor,q.VoltageSensor,q.CurrentSensor,q.AirQualitySensor,q.BatterySensor,q.NumericSensor,q.EnumSensor,q.DateTimeSensor,q.GenericSensor],[J.Control]:[q.NumericControl,q.SelectControl,q.TextControl,q.DateTimeControl],[J.Notifier]:[q.MobilePushNotifier,q.MessagingNotifier,q.EmailNotifier,q.GenericNotifier]};function aa(e){for(let t of Object.values(J))if(t===e)return!0;return!1}function oa(e){return aa(e)?ia[e]??[]:[]}function sa(e,t){let n=oa(t);return e==null||e===``||n.includes(e)?n:[...n,e]}n();var ca=`w-full min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`;function la({device:e}){let{t}=Y(),n=s(),[i,a]=c(null),o=()=>a(null),l={onSuccess:()=>{o(),n.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>a(e.message)},d=Gt(),f=Ht(),p=e.display?.hidden===!0;return r(`section`,{"aria-label":t(`customize.identity.title`),className:`rounded-lg border border-border bg-surface p-2 sm:p-4`,children:[r(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[u(ar,{deviceId:e.id,initialName:e.name,label:t(`customize.identity.name`),layout:`stacked`,onError:a,onSaved:o,onCancel:o}),u(er,{deviceId:e.id,initialLocation:e.location,label:t(`customize.identity.room`),layout:`stacked`,onError:a,onSaved:o,onCancel:o}),u(gr,{label:t(`customize.identity.hidden`),layout:`stacked`,value:u(`input`,{type:`checkbox`,"aria-label":t(`deviceDisplay.hideFromLists`),checked:p,disabled:f.isPending,onChange:t=>f.mutate({deviceId:e.id,display:ea(e.display,t.target.checked)},l)})}),u(gr,{label:t(`customize.identity.role`),layout:`stacked`,value:ta(e)?u(`span`,{children:ua(e.role,t(`customize.identity.noRole`))}):r(`select`,{"aria-label":t(`customize.identity.role`),className:ca,value:e.role??``,disabled:d.isPending,onChange:t=>d.mutate({deviceId:e.id,role:t.target.value===``?null:t.target.value},l),children:[u(`option`,{value:``,children:t(`customize.identity.noRole`)}),sa(e.role,e.type).map(e=>u(`option`,{value:e,children:ua(e,t(`customize.identity.noRole`))},e))]})})]}),i!==null&&u(`p`,{role:`alert`,className:`mt-2 text-xs text-danger break-words`,children:i})]})}function ua(e,t){return e==null||e===``?t:ra(e)?st(e).label:e}function da({onAdvanced:e}){let{t}=Y();return e===void 0?null:u(`button`,{type:`button`,className:`min-h-11 text-left text-primary underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`,onClick:e,children:t(`customize.advancedLink`)})}n();function fa(e){return e===`pending`?`pending`:e===`error`?`failed`:`answered`}function pa({excludeDeviceIds:e,onSelect:t}){let{t:n}=Y(),r=R({projection:`slim`}),a=r.status===`success`?r.data:null,o=i(()=>{if(a===null)return[];let t=new Set(e);return kr(a).filter(e=>!t.has(e.id))},[a,e]),s=i(()=>new Map(o.map(e=>[e.id,e])),[o]),c=i(()=>o.map(e=>({id:e.id,name:e.name,type:e.type,...e.location===null?{}:{location:e.location}})),[o]);return r.status===`error`?u(et,{title:n(`customize.picker.devicesFailed`),message:r.error?.message??``}):u(ct,{devices:c,listState:fa(r.status),value:[],onChange:e=>{let n=e.at(-1);if(n===void 0)return;let r=s.get(n);r!==void 0&&t(r)},noun:`device`,emptyLabel:n(`customize.assign.none`),showAll:!0,testId:`customize-field-device-picker`})}function ma({open:e,title:t,targetKind:n,excludeDeviceIds:i,confirmLabel:a,extra:s,extraComplete:l=!0,onConfirm:d,onClose:f}){let{t:p}=Y(),[m,h]=c(null),[g,_]=c(null),v=()=>{h(null),_(null),f()};return u(ce,{open:e,onOpenChange:e=>e?void 0:v(),children:r(H,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":t,children:[u(He,{children:u(Se,{children:t})}),u(Zt,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:e&&r(o,{children:[r(`section`,{"aria-label":p(`customize.assign.stepDevice`),className:`flex flex-col gap-1`,children:[u(`h3`,{className:`text-xs font-semibold`,children:p(`customize.assign.stepDevice`)}),m===null?u(pa,{excludeDeviceIds:i,onSelect:h}):r(`p`,{className:`flex items-center gap-2 text-sm`,children:[m.name,u(M,{variant:`ghost`,size:`sm`,onClick:()=>{h(null),_(null)},children:p(`customize.assign.change`)})]})]}),m!==null&&r(`section`,{"aria-label":p(`customize.assign.stepField`),className:`flex flex-col gap-1`,children:[u(`h3`,{className:`text-xs font-semibold`,children:p(`customize.assign.stepField`)}),u(Dr,{device:m,targetKind:n,selected:g===null?null:{cap:g.cap,path:g.path},onPick:_,onBack:()=>{h(null),_(null)}})]}),m!==null&&s!==void 0&&r(`section`,{"aria-label":p(`customize.assign.stepDetails`),className:`flex flex-col gap-1`,children:[u(`h3`,{className:`text-xs font-semibold`,children:p(`customize.assign.stepDetails`)}),s]})]})}),r(ze,{children:[u(M,{variant:`ghost`,onClick:v,children:p(`customize.assign.cancel`)}),u(M,{disabled:g===null||!l,onClick:()=>{g!==null&&(d(g),h(null),_(null))},children:a})]})]})})}function ha(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ga(e,t){let n=Vr(e,t);return n===void 0?{kind:`absent`}:{kind:`value`,value:n}}function _a(e,t,n){return ha(t)?ga(t,n):e.status===`error`?{kind:`unknown`,reason:e.error?.message??`the value could not be read`}:e.status===`pending`||e.data===void 0?{kind:`pending`}:e.data===null?{kind:`absent`}:ga(e.data,n)}function va(e,t,n){let r=e?`active`:`muted`;return t.cap===`contact`&&t.path===`entryOpen`?{text:e?n.open:n.closed,tone:r}:qn[t.cap]===t.path?{text:e?n.active:n.inactive,tone:r}:{text:String(e),tone:`normal`}}function ya(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`?va(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 ba=0;function xa(e){let t=_(),n=_n({deviceId:e?.deviceId??ba,capName:e?.cap??``},{enabled:e!==null}),r=tt(t.trpcClient,e?.deviceId??null,e?.cap??``);return e===null?{kind:`absent`}:_a({status:n.status,data:n.data,error:n.error===null||n.error===void 0?null:{message:n.error.message}},r,e.path)}var Sa={muted:`text-foreground-subtle`,active:`text-success`,normal:`text-foreground`,warning:`text-warning`};function Ca({target:e}){let{t}=Y(),n=xa(e);return e===null?null:u(wa,{display:ya(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 wa({display:e}){return u(`span`,{className:`text-xs ${Sa[e.tone]}`,title:e.title,children:e.text})}function $({name:e,detail:t,meta:n,value:i,shown:a,problem:o,onRemove:s,removeLabel:c,busy:l=!1}){return r(`li`,{className:`grid grid-cols-[minmax(0,1fr)_44px] gap-x-3 gap-y-1 items-center px-2 py-2 sm:px-4 sm:grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,1fr)_44px]`,children:[r(`div`,{className:`min-w-0`,children:[u(`div`,{className:`text-sm break-words`,children:e}),t!==null&&u(`div`,{className:`text-xs text-foreground-subtle break-words`,children:t}),o!==void 0&&u(`div`,{role:`alert`,className:`text-xs text-warning break-words`,children:o})]}),u(`div`,{className:`row-start-2 col-start-1 text-xs text-foreground-subtle empty:hidden sm:row-start-auto sm:col-start-auto sm:empty:block`,children:n}),u(`div`,{className:`row-start-3 col-start-1 empty:hidden sm:row-start-auto sm:col-start-auto sm:empty:block`,children:a===void 0?u(Ca,{target:i}):a!==null&&u(wa,{display:a})}),u(`div`,{className:`row-start-1 col-start-2 sm:row-start-auto sm:col-start-auto`,children:s!==void 0&&u(`button`,{type:`button`,"aria-label":c,disabled:l,className:`h-11 w-11 flex items-center justify-center rounded text-foreground-subtle hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:opacity-50 disabled:cursor-not-allowed`,onClick:s,children:u(Ee,{className:`h-4 w-4`})})})]})}function Ta({id:e,icon:t,title:n,headerControl:i,addLabel:a,onAdd:o,addDisabled:s=!1,notices:c,children:l}){return r(`section`,{"aria-labelledby":`customize-${e}`,className:`rounded-lg border border-border bg-surface`,children:[r(`header`,{className:`flex flex-wrap items-center gap-2 border-b border-border px-2 py-2 sm:px-4`,children:[t,u(`h2`,{id:`customize-${e}`,className:`flex-1 text-sm font-semibold`,children:n}),i,o!==void 0&&a!==void 0&&u(M,{variant:`outline`,size:`sm`,disabled:s,onClick:o,children:a})]}),c!==void 0&&u(`div`,{className:`flex flex-col gap-1 px-2 pt-2 empty:hidden sm:px-4`,children:c}),u(`ul`,{className:`flex flex-col divide-y divide-border`,children:l})]})}function Ea({availability:e}){let{t}=Y();return e.kind===`pending`?u(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.assign.checking`)}):e.kind===`unknown`?u(`p`,{role:`alert`,className:`text-xs text-warning`,children:t(`customize.assign.unknown`,{reason:e.reason})}):null}function Da(e,t){if(e.status===`error`)return{kind:`unknown`,reason:e.error?.message??`the request failed`};let n=e.data;return e.status===`pending`||n===void 0?{kind:`pending`}:{kind:`known`,value:t(n)}}var Oa=[{id:`motion`,labelKey:`customize.assign.filters.motion`,caps:[`motion`]},{id:`contact`,labelKey:`customize.assign.filters.contact`,caps:[`contact`]},{id:`all`,labelKey:`customize.assign.filters.all`,caps:Kn}];function ka(e,t){return t!==null&&e.includes(t)?t:Kn.find(t=>e.includes(t))??null}function Aa(e,t){let n=[e,t].filter(e=>e!==null&&e!==``);return n.length===0?null:n.join(` · `)}function ja(e,t){if(e.id===t.hostId||e.type===J.Container||t.excludeCameras&&e.isCamera)return!1;let n=K({addonId:e.addonId,stableId:e.stableId});return!t.assigned.has(n)}function Ma(e){return e.devices.flatMap(t=>{if(!ja(t,e))return[];let n=e.capIndex.get(t.id)??[],r=ka(n,e.preferredCap);if(r===null)return[];let i=qn[r];return[{deviceId:t.id,ref:{addonId:t.addonId,stableId:t.stableId},name:t.name,detail:Aa(t.integration,t.location),meta:r,caps:n,value:i===void 0?null:{deviceId:t.id,cap:r,path:i}}]}).toSorted((e,t)=>e.name.localeCompare(t.name))}function Na(e,t,n){let r=Ze(t);return e.filter(e=>{if(n!==null&&!e.caps.some(e=>n.caps.includes(e)))return!1;if(r.length===0)return!0;let t=mn({id:e.deviceId,name:e.name,...e.detail===null?{}:{detail:e.detail},...e.meta===null?{}:{type:e.meta}});return r.every(e=>t.includes(e))})}function Pa(e){let t=e.find(e=>e.query.status===`error`);if(t!==void 0)return{kind:`unknown`,reason:t.query.error?.message??`the request failed`};if(e.some(e=>e.query.status!==`success`||e.query.data===void 0))return{kind:`pending`};let n=new Map;for(let t of e)for(let e of t.query.data??[])n.set(e,[...n.get(e)??[],t.cap]);return{kind:`known`,value:n}}function Fa(e,t){let n=$e.useQueries(n=>e.map(e=>n.deviceManager.listDeviceIdsByCaps({capNames:[e]},{enabled:t})));return Pa(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}}}}))}n();function Ia(e,t){let n=Me(e,t);return n.kind===`resolved`?n.integration.name:null}function La(e){let t=R({projection:`slim`},{enabled:e}),{data:n}=Sn(void 0,{enabled:e}),r=t.error===null||t.error===void 0?null:t.error.message;return i(()=>Da({status:t.status,data:t.data,error:r===null?null:{message:r}},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:Ia(e,n)}))),[t.status,t.data,r,n])}function Ra(e){let t=La(e.enabled),n=Fa(Kn,e.enabled);return t.kind===`unknown`?t:n.kind===`unknown`?n:t.kind===`pending`||n.kind===`pending`?{kind:`pending`}:{kind:`known`,value:Ma({devices:t.value,capIndex:n.value,hostId:e.hostId,excludeCameras:e.excludeCameras,assigned:e.assigned,preferredCap:e.preferredCap})}}function za(){let{t:e}=Y(),t=be();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`})}n();function Ba(e){return e===null?null:Nr(e,`replace`)?`replace`:Nr(e,`add`)?`add`:null}function Va({device:e,handle:t,availability:n,onAdvanced:i}){let{t:a}=Y(),s=za(),[l,d]=c(!1),[f,p]=c(null),m=$i(t.state),h=Kr(m,`battery`),g=Ba(h),_=g===null?null:Er(h?.fields.percentage),v=La(_!==null);if(n.kind===`absent`)return null;let y=n.kind===`present`?n.mode:null,b=t.state.kind===`none`||t.state.kind===`present`,x=_===null||v.kind!==`known`?null:v.value.find(e=>K({addonId:e.addonId,stableId:e.stableId})===K(_.source))??null,S=_===null?``:x?.name??K(_.source),C=async e=>{let n=await t.save(e);p(n.kind===`refused`?n.reason:null)},w=async()=>{if(m===null)return;let e=Cr(m,`battery`);await s(a(`customize.battery.removeWhat`,{name:S}),e===null)&&await C(e)},T=y!==null&&b&&h===null&&!t.saving;return r(o,{children:[r(Ta,{id:`battery`,icon:u(St,{className:`h-4 w-4 text-foreground-subtle`}),title:a(`customize.battery.title`),addLabel:a(y===`replace`?`customize.battery.replace`:`customize.battery.add`),onAdd:T?()=>d(!0):void 0,notices:r(o,{children:[u(Ea,{availability:n}),_!==null&&v.kind===`unknown`&&u(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:a(`customize.assign.devicesUnreadable`,{reason:v.reason})}),f!==null&&u(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:f})]}),children:[y===`replace`&&b&&u($,{name:a(`customize.battery.native`),detail:null,meta:a(h===null?`customize.assign.native`:`customize.battery.nativeReplaced`),value:h===null?{deviceId:e.id,cap:`battery`,path:`percentage`}:null,removeLabel:``}),h===null&&y===`add`&&b&&u(`li`,{className:`px-2 py-2 text-xs text-foreground-subtle sm:px-4`,children:a(`customize.assign.none`)}),_!==null&&u($,{name:S,detail:`${_.cap}.${_.fieldPath}`,meta:a(g===`replace`?`customize.assign.replaces`:`customize.assign.adds`),value:x===null?null:{deviceId:x.id,cap:_.cap,path:_.fieldPath},problem:x===null&&v.kind===`known`?a(`customize.assign.missingKept`):void 0,onRemove:b?()=>void w():void 0,removeLabel:a(`customize.assign.removeNamed`,{name:S}),busy:t.saving}),h!==null&&_===null&&u($,{name:a(`customize.battery.otherFormula`),detail:null,meta:u(da,{onAdvanced:i}),value:{deviceId:e.id,cap:`battery`,path:`percentage`},removeLabel:``})]}),u(ma,{open:l,title:a(y===`replace`?`customize.battery.replace`:`customize.battery.add`),targetKind:`number`,excludeDeviceIds:[e.id],confirmLabel:a(`customize.assign.add`),onConfirm:e=>{d(!1);let n=y===null?null:Ur({percentage:{source:e.ref,cap:e.cap,fieldPath:e.path,kind:e.kind},mode:y});n===null?p(a(`customize.assign.pickUnusable`)):C(X(m,t.target,n))},onClose:()=>d(!1)})]})}n();function Ha(e,t){let n=e.source;if(n===null||t.kind!==`known`)return null;let r=K(n.source);return t.value.find(e=>K({addonId:e.addonId,stableId:e.stableId})===r)??null}function Ua(e){let t=typeof e==`number`?e:typeof e==`string`?Number(e):NaN;return Number.isFinite(t)?t:null}function Wa({device:e,handle:t,availability:n,onAdvanced:i}){let{t:a}=Y(),s=za(),[l,d]=c(!1),[f,p]=c(``),[m,h]=c(`percent`),[g,_]=c(null),v=$i(t.state),y=Kr(v,`consumables`),b=jr(y),x=La(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=Mr(f),T=b.find(e=>e.key===w)??null,E=T!==null,D=f.trim()!==``&&w===``,O=async e=>{let n=await t.save(e);_(n.kind===`refused`?n.reason:null)},k=()=>{d(!1),p(``),h(`percent`)},A=async e=>{if(y===null||v===null)return;let n=Wr(y,e.key),r=n===null?Cr(v,`consumables`):X(v,t.target,n);await s(a(`customize.consumables.removeWhat`,{name:e.label}),r===null)&&await O(r)},j=r(`div`,{className:`flex flex-wrap items-end gap-2`,children:[r(`label`,{className:`flex w-full flex-col gap-1 text-xs sm:w-56`,children:[a(`customize.consumables.name`),u(`input`,{"aria-label":a(`customize.consumables.name`),className:`px-2 py-1 text-sm bg-background border border-border rounded`,value:f,onChange:e=>p(e.target.value)})]}),r(`label`,{className:`flex flex-col gap-1 text-xs`,children:[a(`customize.consumables.unit`),u(`select`,{"aria-label":a(`customize.consumables.unit`),className:`px-2 py-1 text-sm bg-background border border-border rounded`,value:m,onChange:e=>{let t=Fr.find(t=>t===e.target.value);t!==void 0&&h(t)},children:Fr.map(e=>u(`option`,{value:e,children:a(`customize.consumables.units.${e}`)},e))})]}),E&&u(`p`,{role:`alert`,className:`basis-full text-xs text-warning`,children:a(`customize.consumables.takenBy`,{name:T.label})}),D&&u(`p`,{role:`alert`,className:`basis-full text-xs text-warning`,children:a(`customize.consumables.keyless`)})]});return r(o,{children:[r(Ta,{id:`consumables`,icon:u(De,{className:`h-4 w-4 text-foreground-subtle`}),title:a(`customize.consumables.title`),addLabel:a(`customize.consumables.add`),onAdd:C?()=>d(!0):void 0,notices:r(o,{children:[u(Ea,{availability:n}),x.kind===`unknown`&&b.some(e=>e.source!==null)&&u(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:a(`customize.assign.devicesUnreadable`,{reason:x.reason})}),g!==null&&u(`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 u($,{name:e.label,detail:a(`customize.consumables.otherFormula`),meta:u(da,{onAdvanced:i}),value:null,removeLabel:``},e.key);let r=Ha(e,x),o=r?.name??K(n.source);return u($,{name:e.label,detail:`${a(`customize.consumables.units.${e.unit}`)} · ${o}`,meta:`${n.cap}.${n.fieldPath}`,value:r===null?null:{deviceId:r.id,cap:n.cap,path:n.fieldPath},problem:r===null&&x.kind===`known`?a(`customize.assign.missingKept`):void 0,onRemove:S?()=>void A(e):void 0,removeLabel:a(`customize.assign.removeNamed`,{name:e.label}),busy:t.saving},e.key)}),b.length===0&&n.kind===`present`&&S&&u(`li`,{className:`px-2 py-2 text-xs text-foreground-subtle sm:px-4`,children:a(`customize.assign.none`)})]}),u(ma,{open:l,title:a(`customize.consumables.pickTitle`),targetKind:`number`,excludeDeviceIds:[e.id],confirmLabel:a(`customize.assign.add`),extra:j,extraComplete:w!==``&&!E,onConfirm:e=>{let n=Ua(e.value);if(n!==null&&(n<0||m===`percent`&&n>100)){k(),_(a(`customize.consumables.outOfRange`,{value:n}));return}let r=Ar(y,{key:w,label:f,remaining:{source:e.ref,cap:e.cap,fieldPath:e.path,kind:e.kind},unit:m});k(),r===null?_(a(`customize.assign.pickUnusable`)):O(X(v,t.target,r))},onClose:k})]})}n();function Ga(e){return e.kind===`pending`?`pending`:e.kind===`unknown`?`failed`:`answered`}function Ka(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 qa({open:e,title:t,selection:n,candidates:a,filters:o,confirmLabel:s,onConfirm:l,onClose:f}){let{t:p}=Y(),[m,h]=c(null),[g,_]=c([]),v=o?.find(e=>e.id===m)??o?.[0]??null,y=a.kind===`known`?a.value:[],b=a.kind===`known`?Na(a.value,``,v):[],x=i(()=>Ka(b),[b]),S=Ga(a),C=y.filter(e=>g.includes(e.deviceId));d(()=>{e||(_([]),h(null))},[e]);let w=()=>{_([]),h(null),f()};return u(ce,{open:e,onOpenChange:e=>e?void 0:w(),children:r(H,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":t,children:[u(He,{children:u(Se,{children:t})}),r(Zt,{className:`flex flex-col gap-2 p-2 sm:p-4`,children:[o!==void 0&&o.length>0&&u(`div`,{className:`flex flex-wrap gap-1`,role:`tablist`,"aria-label":p(`customize.assign.filtersLabel`),children:o.map(e=>u(`button`,{type:`button`,role:`tab`,"aria-selected":(v?.id??null)===e.id,className:`rounded-md border px-2 py-1 text-xs ${(v?.id??null)===e.id?`border-foreground bg-surface-hover`:`border-border text-foreground-subtle`}`,onClick:()=>h(e.id),children:p(e.labelKey)},e.id))}),a.kind===`unknown`?u(`p`,{role:`alert`,className:`text-xs text-warning`,children:p(`customize.assign.unknown`,{reason:a.reason})}):u(ct,{devices:x,listState:S,value:g,onChange:e=>_(n===`single`?e.length>0?[e[e.length-1]]:[]:e),noun:`device`,emptyLabel:p(`customize.assign.none`),showAll:!0,testId:`customize-device-picker`})]}),r(ze,{children:[u(M,{variant:`ghost`,onClick:w,children:p(`customize.picker.cancel`)}),u(M,{disabled:C.length===0,onClick:()=>{C.length!==0&&(l(C),_([]),h(null))},children:s(C.length)})]})]})})}function Ja(e){if(e===null)return[];let t=Ir(e);return zr(e).map(e=>{let n=K(e);return{key:n,ref:e,caps:t.filter(e=>K(e.source)===n).map(e=>e.cap)}})}function Ya(e,t){let n=Ir(e);if(n.length===0)return!1;let{enabled:r,...i}=e,{enabled:a,...o}=Mn({camera:t,sources:n,enabled:!0});return Gr(i,o)}function Xa(e){return e?.enabled!==!1}function Za(e,t,n){let r=[...e===null?[]:Ir(e),...n.flatMap(e=>Rn(e.ref,e.caps))];return r.length===0?null:Mn({camera:t,sources:r,enabled:Xa(e)})}function Qa(e,t,n){let r=Ir(e).filter(e=>K(e.source)!==n);return r.length===0?null:Mn({camera:t,sources:r,enabled:Xa(e)})}function $a(e,t){return{...e,enabled:t}}n();function eo({device:e,handle:t,availability:n,onAdvanced:i}){let{t:a}=Y(),s=za(),[l,d]=c(!1),[f,p]=c(null),m=$i(t.state),h=Kr(m,`doorbell`),g=h===null||Ya(h,t.target),_=g?Ja(h):[],v=La(_.length>0),y=Ra({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:Cr(m,`doorbell`):X(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=Qa(h,t.target,e.key),i=r===null&&Cr(m,`doorbell`)===null;await s(a(`customize.doorbell.removeWhat`,{name:n}),i)&&await C(r)},T=e=>v.kind===`known`?v.value.find(t=>K({addonId:t.addonId,stableId:t.stableId})===e.key)??null:null;return r(o,{children:[r(Ta,{id:`doorbell`,icon:u(_e,{className:`h-4 w-4 text-foreground-subtle`}),title:a(`customize.doorbell.title`),headerControl:h===null?void 0:r(`label`,{className:`flex min-h-11 items-center gap-1 text-xs`,children:[u(`input`,{type:`checkbox`,"aria-label":a(`customize.doorbell.active`),checked:h.enabled!==!1,disabled:!x,onChange:e=>void C($a(h,e.target.checked))}),a(`customize.doorbell.active`)]}),addLabel:a(`customize.doorbell.add`),onAdd:S?()=>d(!0):void 0,notices:r(o,{children:[u(Ea,{availability:n}),v.kind===`unknown`&&u(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:a(`customize.assign.devicesUnreadable`,{reason:v.reason})}),f!==null&&u(`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=ka(e.caps,null),o=i===null?void 0:qn[i];return u($,{name:r,detail:n===null?null:Aa(n.integration,n.location),meta:e.caps.join(`, `),value:n!==null&&i!==null&&o!==void 0?{deviceId:n.id,cap:i,path:o}:null,problem:n===null&&v.kind===`known`?a(`customize.assign.missingKept`):void 0,onRemove:b?()=>void w(e,r):void 0,removeLabel:a(`customize.assign.removeNamed`,{name:r}),busy:t.saving},e.key)}),!g&&u($,{name:a(`customize.doorbell.otherFormula`),detail:null,meta:u(da,{onAdvanced:i}),value:null,removeLabel:``}),h===null&&n.kind===`present`&&b&&u(`li`,{className:`px-2 py-2 text-xs text-foreground-subtle sm:px-4`,children:a(`customize.assign.none`)})]}),u(qa,{open:l,title:a(`customize.doorbell.pickTitle`),selection:`multi`,candidates:y,confirmLabel:e=>a(`customize.assign.addCount`,{count:e}),onConfirm:e=>{d(!1),C(Za(h,t.target,e.map(e=>({ref:e.ref,caps:e.caps}))))},onClose:()=>d(!1)})]})}function to(e){return e.slot===`linked-devices`}function no(e){if(e.status===`error`)return{kind:`unknown`,reason:e.error?.message??`the request failed`};if(e.status===`pending`||e.data===void 0)return{kind:`pending`};for(let t of e.data)if(t.state===`ok`&&t.slot===`linked-devices`&&to(t.value))return{kind:`present`,slot:t,value:t.value};let t=e.data.find(e=>e.state===`unreachable`);return t!==void 0&&t.state===`unreachable`?{kind:`unknown`,reason:t.reason}:{kind:`absent`}}function ro(e,t){let n=t.trackedDeviceIds??[],r=e=>t=>({deviceId:t.deviceId,name:t.name,health:t.health,implied:e,tracked:n.includes(t.deviceId)});return[...e.sources.map(r(!1)),...(e.impliedSources??[]).map(r(!0))]}function io(e,t){let n=new Set([...e.sources,...e.impliedSources??[]].map(e=>e.deviceId));return(t.trackedDeviceIds??[]).filter(e=>!n.has(e))}function ao(e,t){return{...e,deviceIds:[...e.deviceIds,...t.filter(t=>!e.deviceIds.includes(t))]}}function oo(e,t){return{...e,deviceIds:e.deviceIds.filter(e=>e!==t),...e.trackedDeviceIds===void 0?{}:{trackedDeviceIds:e.trackedDeviceIds.filter(e=>e!==t)}}}function so(e,t,n){let r=e.trackedDeviceIds??[],i=n?[...r.filter(e=>e!==t),t]:r.filter(e=>e!==t);return{...e,trackedDeviceIds:i}}function co(e,t,n){return e.flatMap(e=>{let r=t.get(e.deviceId);return n.has(e.deviceId)||r===void 0?[]:[{deviceId:e.deviceId,ref:{addonId:r.addonId,stableId:r.stableId},name:e.parentName===null?e.name:`${e.parentName} · ${e.name}`,detail:Aa(r.integration,e.location),meta:e.type,caps:[],value:null}]})}n();function lo(e){return e==null?null:e.message}function uo({device:e}){let{t}=Y(),n=s(),i=za(),a=Fn.includes(e.type),[l,d]=c(!1),[f,p]=c(!1),[m,h]=c(null),g=Qe({deviceId:e.id},{enabled:a}),_=no({status:g.status,data:g.data,error:lo(g.error)===null?null:{message:lo(g.error)??``}}),v=_.kind===`present`?_.slot.slotRef:``,y=_.kind===`present`?[...ro(_.slot,_.value).map(e=>e.deviceId),...io(_.slot,_.value)]:[],b=hn(),x=La(a&&_.kind===`present`&&(l||y.length>0)),S=yn({deviceId:e.id,slotRef:v},{enabled:l&&_.kind===`present`});if(!a||_.kind===`absent`)return null;if(_.kind!==`present`)return u(Ta,{id:`linked`,icon:u(W,{className:`h-4 w-4 text-foreground-subtle`}),title:t(`customize.linked.title`),notices:_.kind===`pending`?u(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.assign.checking`)}):u(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:t(`customize.assign.unknown`,{reason:_.reason})}),children:null});let C=_.value,w=new Map(x.kind===`known`?x.value.map(e=>[e.id,e]):[]),T=C.trackedDeviceIds!==void 0,D=(e,t)=>{let n=w.get(e.deviceId);return{...e,name:e.name??n?.name??null,type:n?.type??null,detail:n===void 0?null:Aa(n.integration,n.location),orphan:t}},O=[...ro(_.slot,C).map(e=>D(e,!1)),...io(_.slot,C).map(e=>D({deviceId:e,name:null,health:`ok`,implied:!1,tracked:!0},!0))],k=new Set(y),A=x.kind===`unknown`?x:S.status===`error`?{kind:`unknown`,reason:lo(S.error)??`the request failed`}:x.kind===`pending`||S.status===`pending`||S.data===void 0?{kind:`pending`}:{kind:`known`,value:co(S.data.candidates,w,k)},j=async r=>{if(f){h(t(`customize.saveInFlight`));return}p(!0),h(null);try{await b.mutateAsync({deviceId:e.id,slotRef:_.slot.slotRef,value:r}),await g.refetch(),await n.invalidateQueries({queryKey:[[`deviceManager`]]})}catch(e){h(e instanceof Error?e.message:String(e))}finally{p(!1)}},M=async e=>{await i(t(`customize.linked.removeWhat`,{name:e.name??`#${e.deviceId}`}),!1)&&await j(oo(C,e.deviceId))},N=[{key:`device`,header:t(`customize.linked.device`),cell:e=>r(`div`,{className:`flex flex-col min-w-0`,children:[u(`span`,{className:`truncate text-sm`,children:e.name??`#${e.deviceId}`}),e.detail!==null&&u(`span`,{className:`truncate text-xs text-foreground-subtle`,children:e.detail}),e.orphan&&u(`span`,{className:`text-xs text-foreground-subtle`,children:t(`customize.linked.notLinked`)}),e.health!==`ok`&&u(`span`,{role:`alert`,className:`text-xs text-warning`,children:t(`customize.linked.health.${e.health}`)})]})},{key:`type`,header:t(`customize.linked.type`),headerClassName:`hidden sm:table-cell`,cellClassName:`hidden sm:table-cell text-xs text-foreground-subtle`,cell:e=>e.type===null?`—`:Bt(e.type).label},{key:`controls`,header:t(`customize.linked.controls`),headerClassName:`hidden md:table-cell`,cellClassName:`hidden md:table-cell text-xs text-foreground-subtle`,cell:e=>e.orphan?`—`:t(`customize.linked.yes`)},...T?[{key:`tracked`,header:t(`customize.linked.tracked`),cellClassName:`text-right`,headerClassName:`text-right`,cell:e=>u(E,{checked:e.tracked,disabled:f,"aria-label":t(`customize.linked.trackFor`,{name:e.name??e.deviceId}),onCheckedChange:t=>void j(so(C,e.deviceId,t))})}]:[],{key:`remove`,header:``,cellClassName:`text-right w-12`,cell:e=>e.implied||e.orphan?null:u(`button`,{type:`button`,"aria-label":t(`customize.assign.removeNamed`,{name:e.name??e.deviceId}),className:`h-11 w-11 inline-flex items-center justify-center text-foreground-subtle hover:text-foreground disabled:opacity-50`,disabled:f,onClick:t=>{t.stopPropagation(),M(e)},children:u(Ee,{className:`h-4 w-4`})})}];return r(o,{children:[u(Ta,{id:`linked`,icon:u(W,{className:`h-4 w-4 text-foreground-subtle`}),title:t(`customize.linked.title`),addLabel:t(`customize.linked.add`),onAdd:f?void 0:()=>d(!0),notices:r(o,{children:[x.kind===`unknown`&&u(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:t(`customize.assign.devicesUnreadable`,{reason:x.reason})}),m!==null&&u(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:m})]}),children:r(`li`,{className:`list-none px-2 sm:px-4`,children:[O.length===0?u(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:t(`customize.assign.none`)}):u(xn,{mode:`generic`,items:O,getKey:e=>String(e.deviceId),getSearchText:e=>[e.name??``,e.detail??``,e.type??``,String(e.deviceId)].join(` `),getFilterType:e=>e.type===null?null:Bt(e.type).label,columns:N,searchPlaceholder:t(`customize.assign.search`),emptyLabel:t(`customize.assign.none`)}),O.some(e=>!e.orphan)&&u(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:t(`customize.linked.controlsAlways`)}),T&&u(`p`,{className:`pb-2 text-xs text-foreground-subtle`,children:t(`customize.linked.trackedHint`)})]})}),u(qa,{open:l,title:t(`customize.linked.pickTitle`),selection:`multi`,candidates:A,confirmLabel:e=>t(`customize.assign.addCount`,{count:e}),onConfirm:e=>{d(!1),j(ao(C,e.map(e=>e.deviceId)))},onClose:()=>d(!1)})]})}function fo(e){return e===null||e.state===`unreadable`?null:e.state===`configured`?e.sensors:[]}function po(e){return{addonId:e.addonId,stableId:e.stableId,mode:e.mode}}function mo(e){return e.length===0?null:{sensors:[...e]}}function ho(e,t){let n=new Set(e.map(Xn));return mo([...e.map(po),...t.filter(e=>!n.has(Xn(e))).map(e=>({...e,mode:Gn}))])}function go(e,t,n){return mo(e.map(e=>Xn(e)===t?{...po(e),mode:n}:po(e)))}function _o(e,t){return mo(e.filter(e=>Xn(e)!==t).map(po))}function vo(e){return e?.state===`configured`&&e.cameraMotion!==void 0}function yo(e){return e===null||e.state===`unreadable`?null:e.state===`configured`?e.cameraMotion??`always`:`always`}function bo(e){return e===null||e.state===`unreadable`?!1:e.state===`not-configured`||vo(e)}function xo(e){return e?.state===`configured`&&(e.notForwarded!==void 0||e.notEnforced!==void 0)}function So(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}}n();var Co=5e3;function wo(e){return e.state===`missing`||e.state===`unreadable`?e.stableId:e.name}function To({device:e,availability:n,sensors:i}){let{t:a}=Y(),s=za(),l=ve(),[f,p]=c(!1),[m,h]=c(null),g=t(!1),[_,v]=c(!1),[y,b]=c(!1),x=i.status,S=t(i.refetch);S.current=i.refetch,d(()=>{let e=setInterval(()=>{g.current||S.current()},Co);return()=>clearInterval(e)},[]);let C=fo(x);d(()=>{x!==null&&b(!1)},[x]);let w=i.presence===`present`&&bo(x)&&!y?C:null,T=La(C!==null&&C.length>0),E=Ra({hostId:e.id,excludeCameras:!0,assigned:new Set((C??[]).map(Xn)),preferredCap:`motion`,enabled:f});if(n.kind===`absent`)return null;let D=vo(x),O=xo(x)?`passes`:yo(x),k=So(i.presence,x,y),A=k.kind===`none`?null:k.kind===`unknown`?{text:`?`,tone:`warning`,title:a(`customize.motion.cameraLevelUnknown`)}:{text:a(k.detected?`customize.assign.value.active`:`customize.assign.value.inactive`),tone:k.detected?`active`:`muted`,title:a(`customize.motion.cameraLevelOwn`,{at:new Date(k.atMs).toLocaleTimeString()})},j=_||l.isPending,M=async t=>{if(g.current){h(a(`customize.saveInFlight`));return}g.current=!0,v(!0);try{await l.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)}},N=async e=>{w!==null&&await s(a(`customize.motion.removeWhat`,{name:wo(e)}),!1)&&await M(_o(w,Xn(e)))},P=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:Aa(t.integration,t.location)};return r(o,{children:[r(Ta,{id:`motion`,icon:u(z,{className:`h-4 w-4 text-foreground-subtle`}),title:a(`customize.motion.title`),addLabel:a(`customize.motion.add`),onAdd:w!==null&&n.kind===`present`?()=>p(!0):void 0,addDisabled:j,notices:r(o,{children:[u(Ea,{availability:n}),i.presence===`pending`&&n.kind!==`pending`&&u(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:a(`customize.motion.reading`)}),x?.state===`unreadable`&&u(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:a(`customize.motion.unreadable`,{reason:x.reason})}),x?.state===`configured`&&!bo(x)&&u(`p`,{role:`alert`,className:`text-xs text-warning`,children:a(`customize.motion.olderOrchestrator`)}),y&&u(`p`,{role:`alert`,className:`text-xs text-warning`,children:a(`customize.motion.refetchFailed`)}),x?.state===`configured`&&x.notForwarded!==void 0&&u(`p`,{role:`alert`,className:`text-xs text-warning`,children:a(`customize.motion.notForwarded.${x.notForwarded}`)}),x?.state===`configured`&&x.notEnforced!==void 0&&u(`p`,{role:`alert`,className:`text-xs text-warning`,children:a(`customize.motion.notEnforced`)}),T.kind===`unknown`&&u(`p`,{role:`alert`,className:`text-xs text-warning break-words`,children:a(`customize.assign.devicesUnreadable`,{reason:T.reason})}),m!==null&&u(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:m})]}),children:[u($,{name:a(`customize.motion.camera`),detail:null,meta:O===null?a(`customize.assign.native`):`${a(`customize.motion.cameraState.${O}`)} · ${a(`customize.assign.native`)}`,value:null,shown:A,removeLabel:``}),(C??[]).map(e=>{let t=Xn(e),n=wo(e),r=e.state===`ready`?ka(e.caps,`motion`):null,i=r===null?void 0:qn[r];return u($,{name:n,detail:P(e),meta:D&&w!==null?u(`select`,{"aria-label":a(`customize.motion.modeFor`,{name:n}),className:`h-11 rounded border border-border bg-surface px-1 text-xs`,value:e.mode,disabled:j,onChange:e=>{let n=Jn.safeParse(e.target.value);n.success&&w!==null&&M(go(w,t,n.data))},children:Jn.options.map(e=>u(`option`,{value:e,children:a(`customize.motion.mode.${e}`)},e))}):a(`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?a(`customize.motion.state.${e.state}`):`${a(`customize.motion.state.${e.state}`)}: ${e.reason}`,onRemove:w===null?void 0:()=>void N(e),removeLabel:a(`customize.assign.removeNamed`,{name:n}),busy:j},t)})]}),u(qa,{open:f,title:a(`customize.motion.pickTitle`),selection:`multi`,candidates:E,filters:Oa,confirmLabel:e=>a(`customize.assign.addCount`,{count:e}),onConfirm:e=>{if(p(!1),w===null)return;let t=ho(w,e.map(e=>e.ref));if(t!==null&&t.sensors.length>8){h(a(`customize.motion.tooMany`,{max:8}));return}M(t)},onClose:()=>p(!1)})]})}var Eo={"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`}},Do=new Set([J.Camera]);function Oo(e){return e.unitField===null?[e.fieldPath]:[e.fieldPath,e.unitField]}function ko(e,t){if(Do.has(e))return{kind:`absent`};let n=null;for(let[e,r]of Object.entries(Eo))if(t.has(e)){n={cap:e,fieldPath:r.fieldPath,unitField:r.unitField};break}let r=null;for(let e of Zn)if(t.has(e)){let t=qn[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 Ao(e){return Hn(e.from,e.to)?kn(e):null}function jo(e){return zn(e)}var Mo=/^convert\(v,\s*"[^"]*",\s*"[^"]*"\)$/;function No(e){return e!==void 0&&Mo.test(e.expr)}function Po(e){return e===void 0||e.expr===`!v`||Mo.test(e.expr)?!1:e.bindings.v!==void 0}function Fo(e){let t=e.expr.trim();if(t===``)return{kind:`refused`,reason:`expression is empty`};let n={kind:`expression`,expr:t,bindings:{v:{kind:`from`,source:e.self,cap:e.cap,fieldPath:e.fieldPath}}},r=Pn({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 Io(e,t,n){if(e===null)return null;let r=Kr(e,n.cap);if(r===null)return e;let i=new Set(Oo(n)),a=Object.fromEntries(Object.entries(r.fields).filter(([e])=>!i.has(e)));return Object.keys(a).length===0?Cr(e,n.cap):X(e,t,{kind:`fields`,cap:n.cap,...r.enabled===void 0?{}:{enabled:r.enabled},fields:a,...r.items===void 0?{}:{items:r.items}})}n();function Lo(e){if(typeof e!=`object`||!e)return;let t=Reflect.get(e,`unit`);return typeof t==`string`?t:void 0}function Ro(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 zo(e,t){let n=Kr(e,t.cap);if(n===null)return;let r=n.fields[t.fieldPath];return r!==void 0&&r.kind===`expression`?r:void 0}function Bo(e,t){let n=zo(e,t);return n===void 0||!No(n)?null:/^convert\(v,\s*"[^"]*",\s*"([^"]*)"\)$/.exec(n.expr)?.[1]??null}function Vo(e,t){let n=zo(e,t);return n===void 0||!Po(n)?null:n.expr}function Ho(e,t,n){let r=Kr(e,t);if(r===null)return!1;let i=r.fields[n];return i!==void 0&&i.kind===`expression`&&i.expr===`!v`}function Uo(e){return typeof e==`number`||typeof e==`boolean`||typeof e==`string`?String(e):e===null?`null`:JSON.stringify(e)}function Wo({device:e,target:t,handle:n,facts:i}){let{t:a}=Y(),o=_(),[s,l]=c(null),[d,f]=c(``),[p,m]=c(null),h=i.nativeCaps.kind===`known`?i.nativeCaps.value:null,g=h===null?null:ko(e.type,h),v=g?.kind===`present`?g.convert?.cap??``:``,y=tt(o.trpcClient,e.id,v);if(i.nativeCaps.kind===`pending`)return u(`section`,{className:`rounded-lg border border-border bg-surface p-3`,children:u(Ea,{availability:{kind:`pending`}})});if(i.nativeCaps.kind===`unknown`)return u(`section`,{className:`rounded-lg border border-border bg-surface p-3`,children:u(Ea,{availability:{kind:`unknown`,reason:i.nativeCaps.reason}})});if(g===null||g.kind===`absent`)return null;let b=$i(n.state),x=g.convert,S=g.invert,C=x===null?void 0:Lo(y),w=C===void 0?void 0:Nn(C)??C,T=w===void 0?void 0:Wn(w),E=x===null?null:Bo(b,x),D=x===null?null:Vo(b,x),O=p??D??``,k=S===null?!1:Ho(b,S.cap,S.fieldPath),A=n.state.kind===`none`||n.state.kind===`present`,j=x===null?0:Ro(y,x.fieldPath)??0,N=x!==null&&O.trim()!==``?{kind:`expression`,expr:O.trim(),bindings:{v:{kind:`from`,source:t,cap:x.cap,fieldPath:x.fieldPath}}}:null,P=N===null||x===null?null:Lr(N,new Map([[Un(t,x.cap),y===void 0?{kind:`pending`}:{kind:`value`,slice:y}]]),Date.now()),F=async e=>{let t=await n.save(e);l(t.kind===`refused`?t.reason:null)},ee=async()=>{if(x===null||w===void 0||d===``)return;let e=Ao({self:t,cap:x.cap,fieldPath:x.fieldPath,from:w,to:d,unitField:x.unitField});if(e===null){l(a(`customize.numericTransforms.convertRefused`));return}m(null),await F(X(b,t,e))},te=async()=>{x!==null&&(await F(Io(b,t,x)),f(``))},I=async()=>{if(x===null)return;let e=Fo({self:t,cap:x.cap,fieldPath:x.fieldPath,expr:O,probe:j});if(e.kind===`refused`){l(e.reason);return}f(``),await F(X(b,t,e.feature))},ne=async()=>{x!==null&&(await F(Io(b,t,x)),m(``))},L=async()=>{if(S===null)return;let e=jo({self:t,cap:S.cap});if(e===null){l(a(`customize.numericTransforms.invertRefused`));return}await F(X(b,t,e))},R=async()=>{S===null||b===null||await F(Cr(b,S.cap))};return r(`section`,{"aria-labelledby":`customize-numeric-transforms`,className:`rounded-lg border border-border bg-surface`,"data-testid":`numeric-transforms-card`,children:[r(`header`,{className:`flex flex-wrap items-center gap-2 border-b border-border px-2 py-2 sm:px-4`,children:[u(Xr,{className:`h-4 w-4 text-foreground-subtle`,"aria-hidden":!0}),u(`h2`,{id:`customize-numeric-transforms`,className:`flex-1 text-sm font-semibold`,children:a(`customize.numericTransforms.title`)})]}),r(`div`,{className:`flex flex-col gap-3 px-2 py-3 sm:px-4`,children:[u(`p`,{className:`text-xs text-foreground-subtle`,children:a(`customize.numericTransforms.blurb`)}),s!==null&&u(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:s}),x!==null&&r(`div`,{className:`flex flex-col gap-2`,"data-testid":`numeric-convert`,children:[u(`label`,{className:`text-[11px] font-medium text-foreground`,children:a(`customize.numericTransforms.publishUnit`)}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:w===void 0?a(`customize.numericTransforms.fromUnknown`):a(`customize.numericTransforms.fromUnit`,{unit:w})}),u(sn,{dimension:T,value:d===``?E??``:d,onChange:e=>{f(e),e!==``&&m(``)},disabled:!A||n.saving||w===void 0,"aria-label":a(`customize.numericTransforms.toUnit`),inheritLabel:a(`customize.numericTransforms.pickUnit`),emptyReason:a(`customize.numericTransforms.fromUnknown`)}),r(`div`,{className:`flex flex-wrap gap-2`,children:[u(M,{size:`sm`,disabled:!A||n.saving||w===void 0||d===``||d===w,onClick:()=>void ee(),children:a(`customize.numericTransforms.applyConvert`)}),E!==null&&u(M,{size:`sm`,variant:`outline`,disabled:!A||n.saving,onClick:()=>void te(),children:a(`customize.numericTransforms.clearConvert`)})]})]}),x!==null&&r(`div`,{className:`flex flex-col gap-2`,"data-testid":`numeric-script`,children:[u(Br,{label:a(`customize.numericTransforms.script`),value:O,bindings:[`v`],onChange:e=>{m(e),e.trim()!==``&&f(``)}}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`customize.numericTransforms.scriptBlurb`)}),P!==null&&u(`p`,{role:`status`,className:`text-[11px] font-mono text-foreground`,"data-testid":`numeric-script-preview`,children:P.kind===`value`?a(`customize.numericTransforms.preview`,{source:Uo(j),result:Uo(P.value)}):P.kind===`waiting`?a(`customize.numericTransforms.previewWaiting`):P.kind===`unavailable`?a(`customize.numericTransforms.previewError`,{reason:P.reason}):a(`customize.numericTransforms.previewRuntimeOnly`)}),r(`div`,{className:`flex flex-wrap gap-2`,children:[u(M,{size:`sm`,disabled:!A||n.saving||O.trim()===``,onClick:()=>void I(),children:a(`customize.numericTransforms.applyScript`)}),D!==null&&u(M,{size:`sm`,variant:`outline`,disabled:!A||n.saving,onClick:()=>void ne(),children:a(`customize.numericTransforms.clearScript`)})]})]}),S!==null&&r(`div`,{className:`flex flex-col gap-2`,"data-testid":`numeric-invert`,children:[u(`label`,{className:`text-[11px] font-medium text-foreground`,children:a(`customize.numericTransforms.invert`)}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`customize.numericTransforms.invertBlurb`)}),u(`div`,{className:`flex flex-wrap gap-2`,children:k?u(M,{size:`sm`,variant:`outline`,disabled:!A||n.saving,onClick:()=>void R(),children:a(`customize.numericTransforms.clearInvert`)}):u(M,{size:`sm`,disabled:!A||n.saving,onClick:()=>void L(),children:a(`customize.numericTransforms.applyInvert`)})})]})]})]})}n();function Go(e){return e instanceof Error?e.message:String(e)}function Ko(e){let n=rn({addonId:e.addonId,stableId:e.stableId}),r=Rt(),i=Kt(),a=en(),o=Qi({status:n.status,data:n.data,error:n.error===null||n.error===void 0?null:{message:n.error.message}}),{t:s}=Y(),l=t(!1),[u,d]=c(!1),f=async e=>{let t=Or(o,e);try{switch(t.kind){case`refused`:return{kind:`refused`,reason:t.reason};case`noop`:return{kind:`saved`};case`create`:await r.mutateAsync({block:t.input});break;case`update`:await i.mutateAsync({blockId:t.blockId,expectedUpdatedAt:t.expectedUpdatedAt,block:{composition:t.composition}});break;case`delete`:await a.mutateAsync({blockId:t.blockId});break}return await n.refetch(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:Go(e)}}};return{target:e,state:o,saving:u||r.isPending||i.isPending||a.isPending,save:async e=>{if(l.current)return{kind:`refused`,reason:s(`customize.saveInFlight`)};l.current=!0,d(!0);try{return await f(e)}finally{l.current=!1,d(!1)}}}}var qo=`pipeline-orchestrator`;function Jo(e){return e.status===`pending`?`pending`:e.status===`error`?`unknown`:e.data===void 0?`pending`:e.data.cameraSensors===void 0?`absent`:`present`}function Yo(e,t){return e===`absent`?`absent`:Jo(t)}async function Xo(e){try{return(await e()).isError?`failed`:`answered`}catch{return`failed`}}function Zo(e,t){let n=dn(qo),r=Ut({deviceId:e},{enabled:t&&n!==`absent`}),i=()=>Xo(r.refetch);return t?{presence:Yo(n,{status:r.status,data:r.data}),status:r.data?.cameraSensors??null,refetch:i}:{presence:`absent`,status:null,refetch:i}}function Qo(e,t){let n=nt({deviceType:e.type}),r=Ce({deviceId:e.id}),i=Ie({deviceId:e.id}),a=Da(n,e=>new Set(e.caps.map(e=>e.cap))),o=Da(r,e=>qi(e.entries)),s=Da(i,e=>e);return{deviceType:e.type,composable:a,nativeCaps:o,wireable:s,composed:new Set((t?.features??[]).map(e=>e.cap))}}var $o={kind:`unknown`,reason:`the composer reports no value for this field`};function es(e,t){let n=K(e);return t.get(n)??n}function ts(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=zr(e).map(e=>es(e,n.sourceNames)).join(` + `),a=i.find(e=>e.field===`lastPressedAt`);return[{key:`doorbell`,label:`doorbell`,origin:{kind:r,from:t},value:a?.value??$o}]}return e.cap===`consumables`?jr(e).map(e=>{let t=t=>Vn(Bn,e.key,t),a=i.find(e=>e.field===t(`level`)||e.field===t(`remaining.value`)),o=e.source===null?``:es(e.source.source,n.sourceNames);return{key:`consumables.${e.key}`,label:`consumables · ${e.label}`,origin:{kind:r,from:o},value:a?.value??$o}}):i.map(e=>({key:e.key,label:`${e.cap}.${e.field}`,origin:{kind:r,from:e.from},value:e.value}))}function ns(e){let t=Pr({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`?ts(n,t,e):[])}function rs(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 is=`grid grid-cols-[minmax(0,1fr)_auto] gap-x-3 gap-y-1 items-baseline px-2 py-2 sm:px-4 sm:grid-cols-[minmax(0,1fr)_minmax(0,2fr)_auto]`;function as({device:e,composition:t,state:n,nativeCaps:i,cameraSensors:a}){let{t:o}=Y(),s=t!==null&&n!==null,c=La(s),l=new Map(c.kind===`known`?c.value.map(e=>[K({addonId:e.addonId,stableId:e.stableId}),e.name]):[]),d=s&&i.kind===`known`?ns({composition:t,nativeCaps:i.value,state:n,sourceNames:l}):[],f=s&&i.kind===`known`&&d.length===0&&t.features.length>0,p=rs(a,{camera:o(`customize.changes.motion.camera`),sensor:(e,t)=>o(`customize.changes.motion.${t}`,{name:e})}),m=s&&i.kind!==`known`;return d.length===0&&p===null&&!m&&!f?null:r(`section`,{"aria-labelledby":`customize-changes`,className:`rounded-lg border border-border bg-surface`,children:[u(`h2`,{id:`customize-changes`,className:`px-3 py-2 text-[11px] font-semibold uppercase tracking-wider border-b border-border`,children:o(`customize.changes.title`)}),m&&u(`p`,{role:i.kind===`unknown`?`alert`:`status`,className:`px-2 py-2 text-xs text-foreground-subtle sm:px-4`,children:i.kind===`unknown`?o(`customize.changes.unknown`,{reason:i.reason}):o(`customize.changes.reading`)}),f&&u(`p`,{className:`px-2 py-2 text-xs text-foreground-subtle sm:px-4`,children:o(`customize.changes.noRows`)}),r(`ul`,{className:`divide-y divide-border`,children:[d.map(e=>r(`li`,{className:is,children:[u(`span`,{className:`font-mono text-xs break-words`,children:e.label}),u(`span`,{className:`col-span-2 row-start-2 text-xs text-foreground-subtle break-words sm:col-span-1 sm:row-start-auto`,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:``})}),u(`span`,{className:`row-start-1 col-start-2 text-xs sm:row-start-auto sm:col-start-auto`,children:u(os,{value:e.value})})]},e.key)),p!==null&&r(`li`,{className:is,children:[u(`span`,{className:`font-mono text-xs`,children:`motion`}),u(`span`,{className:`col-span-2 row-start-2 text-xs text-foreground-subtle break-words sm:col-span-1 sm:row-start-auto`,children:p}),u(`span`,{className:`row-start-1 col-start-2 sm:row-start-auto sm:col-start-auto`,children:u(Ca,{target:{deviceId:e.id,cap:`motion`,path:`detected`}})})]})]})]})}function os({value:e}){let{t}=Y();switch(e.kind){case`value`:return r(`span`,{children:[Rr(e.value,!0),e.staleReason!==null&&r(`span`,{className:`text-warning`,children:[` `,`· `,t(`customize.changes.value.stale`,{reason:e.staleReason})]})]});case`unavailable`:return u(`span`,{className:`text-warning`,children:t(`customize.changes.value.unavailable`,{reason:e.reason})});case`unknown`:return u(`span`,{className:`text-foreground-subtle`,children:t(`customize.changes.value.unknown`,{reason:e.reason})});case`off`:return u(`span`,{className:`text-foreground-subtle`,children:t(`customize.status.off`)})}}n();function ss({deviceId:e,activeSubTab:t,onSubTabChange:n}){let{t:r}=Y(),i=Ne({deviceId:e}),a=i.data;return a==null?i.status===`error`?u(et,{title:r(`customize.deviceUnreadable`),message:i.error?.message??``,onRetry:()=>void i.refetch()}):a===null?u(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`customize.noSuchDevice`,{deviceId:e})}):u(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:r(`customize.loadingDevice`)}):a.addonId===`composer`?u(cs,{device:a}):u(ls,{device:a,target:{addonId:a.addonId,stableId:a.stableId},activeSubTab:t,onSubTabChange:n})}function cs({device:e}){let{t}=Y(),n=e.stableId.startsWith(`composed-`)?e.stableId.slice(jn.length):null;return r(`section`,{className:`rounded-lg border border-border bg-surface p-4 flex flex-col gap-2`,children:[u(`p`,{className:`text-sm text-foreground`,children:t(`customize.composed.body`)}),n!==null&&u(rr,{className:`text-sm text-primary`,to:yr(n),children:t(`customize.composed.edit`)})]})}function ls({device:e,target:t,activeSubTab:n,onSubTabChange:i}){let a=Ko(t),o=dn(`composer`),{t:s}=Y(),c=Zo(e.id,e.type===J.Camera),l=Qo(e,$i(a.state)),d={deviceType:e.type,composable:l.composable,nativeCaps:l.nativeCaps,cameraSensors:c.presence},f=()=>i(vr),p=a.state.kind===`none`||a.state.kind===`present`;return n===`advanced`?r(`div`,{className:`flex flex-col gap-4`,children:[u(ds,{state:a.state}),p&&u(us,{device:e,target:t,handle:a,facts:l,onDone:()=>i(`main`)})]}):r(`div`,{className:`flex flex-col gap-4`,children:[u(la,{device:e}),o===`absent`&&u(`p`,{role:`alert`,className:`text-xs text-warning`,children:s(`customize.composerAbsent`)}),a.state.kind!==`none`&&u(ds,{state:a.state}),u(eo,{device:e,handle:a,availability:Zi(`doorbell`,d),onAdvanced:f}),u(To,{device:e,handle:a,availability:Zi(`motion`,d),sensors:c}),u(Va,{device:e,handle:a,availability:Zi(`battery`,d),onAdvanced:f}),u(Wa,{device:e,handle:a,availability:Zi(`consumables`,d),onAdvanced:f}),u(Wo,{device:e,target:t,handle:a,facts:l}),u(uo,{device:e}),u(as,{device:e,composition:$i(a.state),state:a.state.kind===`present`?a.state.view.state:null,nativeCaps:l.nativeCaps,cameraSensors:c.status}),r(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[p?u(M,{variant:`ghost`,className:`text-primary underline`,onClick:f,children:s(`customize.advancedLink`)}):u(`span`,{}),u(fs,{handle:a})]})]})}function us({device:e,target:t,handle:n,facts:r,onDone:i}){let a=n.state.kind===`present`?n.state:null;return u(Hr,{initial:a===null?wr(t):Tr(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 ds({state:e}){let{t}=Y();switch(e.kind){case`pending`:return u(`p`,{role:`status`,className:`text-xs text-foreground-subtle`,children:t(`customize.status.pending`)});case`unknown`:return u(et,{title:t(`customize.status.unknownTitle`),message:e.reason});case`not-loaded`:return u(`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 r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[u(ie,{variant:n.status===`running`?`success`:n.status===`failed`?`danger`:`warning`,children:t(`customize.blockStatus.${n.status}`)}),!n.enabled&&u(ie,{variant:`default`,children:t(`customize.status.off`)}),n.lastError!==void 0&&u(`span`,{className:`text-[11px] text-foreground-muted break-words`,children:n.lastError}),e.view.state.kind===`unreachable`&&u(`span`,{className:`text-[11px] text-warning`,children:t(`customize.status.composerUnreachable`,{reason:e.view.state.error})})]})}}}function fs({handle:e}){let{t}=Y(),n=be(),[i,a]=c(null);if(e.state.kind!==`present`)return null;let o=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);a(r.kind===`refused`?r.reason:null)};return r(`div`,{className:`flex flex-col items-start gap-1`,children:[u(M,{variant:`danger`,disabled:e.saving,onClick:()=>void o(),children:t(`customize.remove.button`)}),i!==null&&u(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:i})]})}var ps=`overview`;function ms(e,t){return e.some(e=>e.id===t)?t:ps}function hs({deviceId:e}){let t=s(),n=Number.isFinite(e),{data:i}=Ne({deviceId:e},{enabled:n}),a=typeof i?.type==`string`?i.type:`camera`;Qt([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:o,isLoading:c,isError:l,error:d}=Ce({deviceId:e},{enabled:n}),{data:f}=se({deviceType:a},{enabled:!!a}),p=dt({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(c)return u(`div`,{className:`p-4`,children:u(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(l)return r(`div`,{className:`p-4 text-xs text-red-400`,children:[`Failed to load bindings: `,d instanceof Error?d.message:String(d)]});let m=new Map,h={};for(let e of f??[])h[e.capName]=e.wrappers;for(let e of o?.entries??[])m.set(e.capName,{...e,wrappers:h[e.capName]??[]});for(let e of f??[])m.has(e.capName)||m.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let g=[...m.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(g.length===0)return r(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[u(Tn,{className:`h-8 w-8 opacity-40`}),u(`p`,{className:`text-xs`,children:`No capability providers applicable to this device yet.`}),u(`p`,{className:`text-[10px] opacity-60`,children:`Native providers show up here as soon as the owning addon registers them.`})]});let _=g.filter(e=>e.kind!==`unbound`).length;return r(`div`,{className:`flex flex-col gap-3 p-1`,children:[r(`div`,{className:`text-[11px] text-foreground-subtle`,children:[u(`span`,{className:`font-medium text-foreground`,children:_}),` of `,g.length,` capabilit`,g.length===1?`y`:`ies`,` bound — rows marked `,u(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),u(fn,{columns:[{key:`capability`,header:`Capability`,render:e=>u(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>u(gs,{kind:e.kind})},{key:`provider`,header:`Active Provider`,render:e=>u(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||u(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:`Node`,render:e=>e.providerNodeId?u(_s,{nodeId:e.providerNodeId}):u(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:`Native`,render:e=>u(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||u(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:`Wrapper`,render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return u(vs,{wrappers:t.wrappers,activeWrapperId:n,disabled:p.isPending,onPick:r=>{let i=n===r;p.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}],rows:g,rowKey:e=>e.capName,minWidthPx:720})]})}function gs({kind:e}){return e===`native`?r(`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:[u(Xe,{className:`h-3 w-3`}),`native`]}):e===`wrapped`?r(`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:[u(On,{className:`h-3 w-3`}),`wrapped`]}):e===`linked`?r(`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:[u(W,{className:`h-3 w-3`}),`linked`]}):r(`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:[u(ee,{className:`h-3 w-3`}),`unbound`]})}function _s({nodeId:e}){return u(`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 vs({wrappers:e,activeWrapperId:t,disabled:n,onPick:i}){return e.length===0?u(`span`,{className:`text-[10px] opacity-40`,children:`none available`}):u(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let a=e===t;return r(`button`,{disabled:n,onClick:()=>i(e),title:a?`Click to deactivate (revert to native)`:`Activate wrapper ${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 ${a?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[u(a?vn:v,{className:`h-3 w-3`}),e]},e)})})}function ys({deviceId:e,activeSubTab:t,onSubTabChange:n,deviceType:i,isAdmin:a}){return r(`div`,{className:`flex flex-col gap-3`,children:[br(i,a)&&u(pt,{deviceId:e,readOnly:!0}),u(ur,{deviceId:e,activeSubTab:t,onSubTabChange:n})]})}n();var bs=new Set([`package-detection`]);function xs(e,t){if(!e)return null;for(let n of e.slots)for(let e of n.addons)if(e.id===t)return e;return null}function Ss(e){return e?e.modelId!==void 0||e.settings!==void 0:!1}function Cs({deviceId:e,refreshToken:t}){let n=s(),l=_().trpcClient,[d,f]=c(null),[p,m]=c(null),[h,g]=c(null),v=Je({deviceId:e},{refetchOnMount:`always`}),y=rt({deviceId:e},{refetchOnMount:`always`}),b=mt(void 0,{refetchOnMount:`always`});Qt([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let{nodes:x}=ht(),S=i(()=>{let e=new Set;for(let t of x)t.isOnline&&e.add(t.id);return e},[x]),C=i(()=>(b.data??[]).filter(e=>S.has(e.nodeId)).map(e=>e.nodeId),[b.data,S]),w=a({enabled:C.length>0,queryKey:[[`pipelineExecutor`,`getSchema`],`device-step-schemas`,C.join(`,`),t],queryFn:async()=>{let e={};for(let t of C)try{e[t]=await l.pipelineExecutor.getSchema.query({nodeId:t})}catch{}return e}}),T=e=>w.data?.[e]??null,E=i(()=>{let e=C[0];if(e!==void 0){let t=w.data?.[e];if(t)return t}return Object.values(w.data??{})[0]??null},[C,w.data]),D=a({enabled:C.length>0,queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`],`device-step`,C.join(`,`),t],queryFn:async()=>{let e={};for(let t of C)try{e[t]=(await l.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:t})).devices}catch{e[t]=[]}return e}}),k=()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]})},A=At({onSuccess:k}),M=O({onSuccess:k}),N=i(()=>E?j(E):[],[E]),P=i(()=>{let e=b.data??[],t=S.size===0?[]:e.filter(e=>S.has(e.nodeId)),n=[];for(let e of t){let t=(D.data?.[e.nodeId]??[]).filter(e=>e.enabled&&e.available);if(t.length>=2)for(let r of t)n.push({agentNodeId:e.nodeId,engineLabel:r.format,deviceKey:r.key,deviceLabel:Dn(r).label});else n.push({agentNodeId:e.nodeId,engineLabel:t[0]?.format??`(engine unknown)`})}return n},[b.data,D.data,S]),F=(e,t)=>D.data?.[e]?.find(e=>e.key===t)??null,ee=e=>{if(e.deviceKey!==void 0)return e.deviceKey;let t=D.data?.[e.agentNodeId]??[],n=t.filter(e=>e.enabled&&e.available);return n.length>=1?n[0].key:t.find(e=>e.available)?.key??t[0]?.key??null},te=(e,t,n)=>y.data?.[e]?.[t]?.[n]??null,I=e=>{if(bs.has(e))return{kind:`zone-driven`};let t=xs(E,e)?.enabledByDefault??!0,n=v.data?.stepToggles?.[e];return{kind:`gate`,effectiveOn:n??t,defaultOn:t,explicit:n!==void 0}},ne=(e,t,n)=>{let r=xs(T(n),e);if(r)return tn(r,t)},L=(e,t)=>{let n=I(e),r=n.kind===`gate`?n.effectiveOn:!1,i=xs(T(t.agentNodeId),e),a=ee(t),o=a===null?null:F(t.agentNodeId,a);if(!qe(i?.models??[],o?.format))return r?{kind:`skip`}:{kind:`na`};let s=a===null?null:te(t.agentNodeId,a,e),c=o?.steps?.[e];return{kind:`enabled`,modelId:(i?xt({catalog:i,device:o,override:s?.modelId,base:c?.modelId}):void 0)??`Auto`,overridden:Ss(s)}},R=d===null?null:xs(T(d.agentNodeId),d.addonId),z=d?F(d.agentNodeId,d.deviceKey):null,re=z?.format??`coreml`,ie=d?Ss(te(d.agentNodeId,d.deviceKey,d.addonId)):!1,ae=d?ne(d.addonId,z,d.agentNodeId):void 0,B=i(()=>{if(!d||!z)return null;let e=z.steps?.[d.addonId];return{enabled:!0,...e?.modelId===void 0?{}:{modelId:e.modelId},settings:e?.settings??{}}},[d,z]),V=()=>{f(null),m(null)},oe=(e,t)=>{let n=ee(t);n!==null&&(f({addonId:e,agentNodeId:t.agentNodeId,deviceKey:n}),m(te(t.agentNodeId,n,e)))},H=(t,n)=>{M.mutate({deviceId:e,addonId:t,enabled:n})},se=()=>{d&&A.mutate({deviceId:e,agentNodeId:d.agentNodeId,deviceKey:d.deviceKey,addonId:d.addonId,patch:p},{onSuccess:V})},ce=()=>{d&&A.mutate({deviceId:e,agentNodeId:d.agentNodeId,deviceKey:d.deviceKey,addonId:d.addonId,patch:null},{onSuccess:V})};if(b.isLoading||C.length>0&&w.isLoading)return u(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(P.length===0)return u(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`No online agents.`});if(!E)return u(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let le=d!==null&&R!==null&&z!==null;return r(`div`,{className:`relative h-full w-full space-y-3`,children:[r(`div`,{className:`rounded-md border border-border bg-muted/20 px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[u(`span`,{className:`font-medium text-foreground`,children:`Gate`}),` (col 1) decides whether this camera runs a step — independent of nodes. Each`,` `,u(`span`,{className:`font-medium text-foreground`,children:`node column`}),` shows the model that node runs; click a cell to pin a per-camera model override for that accelerator. A gated-on step with no model on a device shows a clickable `,u(`span`,{className:`text-amber-500`,children:`⚠ skip`}),` `,`and won't run there.`]}),r(`div`,{className:`rounded-md border border-sky-500/25 bg-sky-500/[0.06] px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[u(`span`,{className:`font-medium text-sky-400`,children:`Placement is dynamic.`}),` When a node has multiple inference accelerators, each session is balanced across them per-session at dispatch time — these device columns show each accelerator's effective model (override ?? device default), not a fixed assignment.`]}),u(`div`,{className:le?`md:pr-[360px]`:``,children:N.length>0?u(ye,{tree:N,agents:P,gateFor:I,getCellState:L,onCellClick:oe,selectedCell:d,onSetGate:H,gateBusy:M.isPending,fallbackNodeId:h,onFallbackNodeChange:g}):u(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),u(un,{open:le,onClose:V,title:R?.name??``,subtitle:d&&z?`${d.agentNodeId} · ${Dn(z).label} · ${z.format}`:``,footer:r(o,{children:[u(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted text-foreground-subtle disabled:opacity-50`,disabled:!ie||A.isPending,onClick:ce,children:`Clear override`}),u(`div`,{className:`flex-1`}),u(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:V,children:`Cancel`}),u(`button`,{type:`button`,disabled:!d||!B||A.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:se,children:A.isPending?`Saving…`:`Save`})]}),children:R&&d&&B?u(zt,{mode:`device`,addon:R,agentDefault:B,agentNodeId:d.agentNodeId,currentPatch:p,engineFormat:re,effectiveModelId:ae,onChangePatch:m}):u(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-300`,children:`This accelerator is no longer reported by the node, so there is nothing to provision here.`})})]})}var ws=[{id:`object-detection`,label:`Object detection`,icon:`scan-search`},{id:`tracking`,label:`Tracking`,icon:`route`},{id:`motion`,label:`Motion`,icon:`activity`},{id:`stationary`,label:`Stationary`,icon:`square-parking`},{id:`zones`,label:`Zones`,icon:`shapes`},{id:`audio`,label:`Audio`,icon:`volume-2`},{id:`cluster`,label:`Cluster`,icon:`server`}],Ts={"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 Es(e){return Ts[e]??`object-detection`}n();var Ds=`steps`,Os=`settings`,ks=new Set([Ds,Os]);function As(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}function js({deviceId:t,activeSubTab:n,onSubTabChange:i}){return r(U,{value:n&&ks.has(n)?n:Ds,onValueChange:e(e=>{i?.(e)},[i]),className:`flex flex-col`,children:[r(V,{className:`flex-shrink-0`,children:[u(de,{value:Ds,children:`Steps`}),u(de,{value:Os,children:`Settings`})]}),u(I,{value:Ds,children:u(Cs,{deviceId:t,refreshToken:0})}),u(I,{value:Os,children:u(ur,{deviceId:t,sectionFilter:As,subTabGrouping:{groupOf:e=>Es(e.id),tabs:ws}})})]})}var Ms=`Notifications`,Ns=`This camera never notifies — no rule, no target, no alarm. Existing events, tracks and recordings are unaffected.`;function Ps(e){let{mutedDeviceIds:t,deviceId:n}=e,r=t===null?null:!t.includes(n),i=e.pendingOn??null;return{label:Ms,on:r===null?null:i??r,available:r!==null,costWhenOff:Ns}}function Fs(e,t){return!e.available||e.on===null?null:{deviceId:t,muted:e.on}}n();function Is(e){if(typeof e!=`object`||!e)return null;let t={...e}.mutedDeviceIds;return Array.isArray(t)?t.filter(e=>typeof e==`number`):null}function Ls({deviceId:t}){let n=s(),i=Number.isFinite(t),[a,o]=c(null),[l,d]=c(null),f=Ps({mutedDeviceIds:Is(N({},{enabled:i}).data),deviceId:t,pendingOn:l}),p=ke({onError:e=>{console.error(`[DeviceNotificationMute] mute write failed — reverting`,{tags:{deviceId:t},meta:{error:e instanceof Error?e.message:String(e)}}),d(null),o(e instanceof Error?e.message:String(e)),n.invalidateQueries({queryKey:[[`notificationRules`,`listDeviceMutes`]]})},onSuccess:()=>{o(null),d(null),n.invalidateQueries({queryKey:[[`notificationRules`]]})}}),m=e(()=>{let e=Fs(f,t);e!==null&&(d(!e.muted),p.mutate(e))},[t,p,f]),h=f.on===null,g=f.on===!1,_=g?Tt:_e;return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`border-b border-border px-4 py-2 flex items-center justify-between gap-2`,children:[u(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Notifications`}),g&&u(`span`,{className:`rounded bg-warning/20 px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wide text-warning`,children:`muted`})]}),r(`div`,{className:`px-4 py-3 flex items-start gap-3`,children:[r(`button`,{type:`button`,role:`switch`,"aria-label":f.label,"aria-checked":f.on===!0,disabled:!f.available||p.isPending,onClick:m,title:h?`Notification mute — state unknown; the notification centre did not answer.`:g?`Muted. ${f.costWhenOff}`:`Notifying. Muting it: ${f.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 ${a===null?h?`border-dashed border-border text-foreground-subtle/50`:g?`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:[u(_,{className:`h-3.5 w-3.5`}),u(`span`,{children:h?`Unknown`:g?`Muted`:`Notifying`})]}),u(`p`,{className:`flex-1 text-[11px] leading-relaxed text-foreground-subtle`,children:a===null?h?`The notification centre did not answer, so this device’s mute state is unknown.`:f.costWhenOff:`Write failed: ${a}`})]})]})}function Rs(e,t){return{switchId:e,label:In[e].label,detail:t===void 0||t.length===0?null:t}}function zs(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 Bs(e){let t=zs(e),n=new Set(e.sourceStillLive),r=e.sourceStillLive.map(e=>Rs(e,t.get(e)?.detail)),i=[...t.values()].filter(e=>e.outcome===`not-offered`&&!n.has(e.switchId)).map(e=>Rs(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}}n();function Vs(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 Hs({deviceId:e,deviceName:t}){let{t:n}=Y(),a=be(),[o,s]=c(null),l=R({isCamera:!0,projection:`slim`}),d=Ve(),f=l.data!==void 0,p=i(()=>l.data===void 0?[]:Vs(l.data,e),[l.data,e]),m=p.find(e=>e.id===o)??null,h=d.data===void 0?null:Bs(d.data),g=d.error===null?null:d.error.message,_=async()=>{m===null||m.id===e||await a({title:n(`deviceMigrate.confirmTitle`,`Replace “{{source}}” with “{{target}}”?`,{source:t,target:m.name}),message:n(`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:n(`deviceMigrate.confirmAction`,`Migrate`),variant:`danger`})&&d.mutate({sourceId:e,targetId:m.id})};return r(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[r(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[r(`div`,{className:`min-w-0`,children:[u(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:n(`deviceMigrate.title`,`Migrate to…`)}),u(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:n(`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})})]}),r(`div`,{className:`flex shrink-0 items-center gap-2`,children:[r(`select`,{"aria-label":n(`deviceMigrate.pickerLabel`,`Replacement camera`),className:`rounded-md border border-border bg-background px-2 py-1.5 text-xs text-foreground disabled:opacity-50`,disabled:!f||p.length===0||d.isPending,value:o===null?``:String(o),onChange:e=>{let t=e.target.value;s(t===``?null:Number(t))},children:[u(`option`,{value:``,children:f?n(`deviceMigrate.pickerPlaceholder`,`Select a camera…`):n(`deviceMigrate.pickerPending`,`Reading the fleet…`)}),p.map(e=>r(`option`,{value:String(e.id),children:[e.name,` (#`,e.id,`)`]},e.id))]}),r(`button`,{type:`button`,disabled:m===null||d.isPending,onClick:()=>{_()},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[u(Xr,{className:`h-3 w-3`}),d.isPending?n(`deviceMigrate.running`,`Migrating…`):n(`deviceMigrate.action`,`Migrate`)]})]})]}),f&&p.length===0&&u(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:n(`deviceMigrate.noTargets`,`No other camera is adopted, so there is nothing to migrate to.`)}),g!==null&&u(`p`,{className:`mt-2 text-[11px] text-danger`,children:n(`deviceMigrate.failed`,`Migration failed: {{error}}`,{error:g})}),h!==null&&u(Us,{report:h})]})}function Us({report:e}){let{t}=Y(),n=e.verdict===`quiet`;return r(`div`,{className:`mt-3 space-y-2 border-t border-border pt-3`,children:[u(`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?r(`div`,{className:`flex items-start gap-2 rounded-md border border-success/30 bg-success/5 px-3 py-2`,children:[u(Pt,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-success`}),u(`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.`)})]}):r(`div`,{className:`rounded-md border border-warning/40 bg-warning/5 px-3 py-2`,children:[r(`div`,{className:`flex items-start gap-2`,children:[u(Lt,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`}),u(`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.`)})]}),u(`ul`,{className:`mt-2 space-y-1 pl-5`,children:e.stillLive.map(e=>r(`li`,{className:`text-[11px] text-foreground`,children:[u(`span`,{className:`font-medium`,children:e.label}),e.detail!==null&&r(`span`,{className:`text-foreground-subtle`,children:[` — `,e.detail]})]},e.switchId))})]}),e.neverOffered.length>0&&r(`div`,{className:`rounded-md border border-border px-3 py-2`,children:[r(`div`,{className:`flex items-start gap-2`,children:[u(En,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),u(`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.`)})]}),u(`ul`,{className:`mt-2 space-y-1 pl-5`,children:e.neverOffered.map(e=>u(`li`,{className:`text-[11px] text-foreground-subtle`,children:e.label},e.switchId))})]})]})}n();function Ws({deviceId:e}){let[t,n]=c(null),i=Et({onSuccess:e=>{n(e.changed?`Re-aligned with source — ${e.rebuiltChildren} child${e.rebuiltChildren===1?``:`ren`} rebuilt.`:`Already up to date.`)},onError:e=>n(`Re-sync failed: ${e.message}`)});return r(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[r(`div`,{className:`flex items-center justify-between gap-3`,children:[r(`div`,{children:[u(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:`Re-sync`}),u(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:`Re-align this device's type, role, capabilities and units with its source.`})]}),r(`button`,{type:`button`,disabled:i.isPending,onClick:()=>{n(null),i.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:[u(Yt,{className:`h-3 w-3 ${i.isPending?`animate-spin`:``}`}),i.isPending?`Re-syncing…`:`Re-sync`]})]}),t!==null&&u(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:t})]})}function Gs(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function Ks({device:e}){let t=ir(),n=typeof e.id==`number`?e.id:null,i=String(e.type??``),a=i===J.Camera,o=i===J.Hub,s=e.features??[],c=s.includes(Yn.Resyncable),{data:l}=_t({deviceId:n??0},{enabled:n!==null&&a,refetchInterval:5e3}),d=l?.streams??{},f=Object.entries(d),p=s.includes(Yn.DoorbellButton),m=yt(p?{deviceId:n??void 0,historyLimit:10}:void 0),h=m.latest?Date.now()-m.latest.timestamp<3e4:!1;return r(`div`,{className:`space-y-5`,children:[o&&n!==null&&u(he,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),c&&n!==null&&u(Ws,{deviceId:n}),a&&n!==null&&u(Hs,{deviceId:n,deviceName:String(e.name??``)}),n!==null&&u(Ls,{deviceId:n}),a&&n!==null&&u(Ft,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),p&&u(fe,{history:m.history,latestIsFresh:h}),a&&n!==null&&u(Ft,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),a&&f.length>0&&r(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[u(`div`,{className:`border-b border-border px-4 py-2`,children:u(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Stream Network`})}),u(`div`,{className:`divide-y divide-border`,children:f.map(([e,t])=>r(`div`,{className:`px-4 py-2.5`,children:[r(`div`,{className:`flex items-center gap-2 mb-2`,children:[u(Oe,{className:`h-3 w-3 text-foreground-subtle`}),u(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),r(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[u(qs,{label:`Nominal`,value:Gs(t.nominalBitrateKbps??0)}),u(qs,{label:`Observed`,value:Gs(t.observedBitrateKbps??0)}),u(qs,{label:`Peak`,value:Gs(t.peakBitrateKbps??0)}),u(qs,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),u($n,{}),n!==null&&u(xr,{deviceId:n})]})}function qs({label:e,value:t,warning:n}){return r(`div`,{children:[u(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),u(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}var Js=[{id:`overview`,label:`Overview`,cameraOnly:!1,adminOnly:!1},{id:`config`,label:`Config`,cameraOnly:!1,adminOnly:!1},{id:mr,label:`Customize`,cameraOnly:!1,adminOnly:!0},{id:`detection-pipeline`,label:`Detection pipeline`,cameraOnly:!0,adminOnly:!1},{id:`bindings`,label:`Bindings`,cameraOnly:!0,adminOnly:!1}];function Ys(e,t){let n=e===J.Camera;return Js.filter(e=>(n||!e.cameraOnly)&&(t||!e.adminOnly)).map(({id:e,label:t})=>({id:e,label:t}))}function Xs({provider:e,integrationId:t,name:n}){let r=ir(),i=t===null?`/integrations`:`/integrations/${t}`,a=n===null?`Open integrations`:`Open integration ${n}`;return u(`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:u(Qn,{type:e,size:`lg`})})}n();var Zs=[{id:`logs`,icon:on,label:`Logs`},{id:`repl`,icon:nr,label:`REPL`},{id:`events`,icon:F,label:`Events`},{id:`state`,icon:$t,label:`State`}];function Qs(){let n=or(),a=Number(n.deviceId),l=Number.isFinite(a),d=ir(),f=s(),m=be(),h=_(),{user:v}=cr(),y=v?.isAdmin===!0,[b,x]=tr(),w=b.get(`tab`)??`overview`,T=b.get(`sub`),[E,O]=c(`logs`),A=`device-detail.left-col-width-px`,[j,M]=c(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(A),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),N=t(j);N.current=j;function P(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??j??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{M(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=N.current;if(e!==null)try{window.localStorage.setItem(A,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:F,isLoading:ee,isError:te}=Ne({deviceId:a},{enabled:l,refetchInterval:5e3,retry:1}),{data:I}=re({deviceId:a},{enabled:l}),ne=i(()=>{let e=I?.settings?.sections??[],t=I?.live?.sections??[],n=[...e,...t],r=new Set;for(let e of n)e.location===`top-tab`&&e.tab&&r.add(e.tab===`zones`?`detection-pipeline`:e.tab);return n.some(fr)&&r.add(_r),[...r].map(e=>e===`export`?{id:e,label:pr,isAddonContrib:!0}:{id:e,label:An[e]?.label??e,isAddonContrib:!0})},[I]),L=F,R=String(L?.name??n.deviceId??`Device`),z=L?.online===!0,ie=z?`online`:`offline`,B=String(L?.addonId??`rtsp`),V=L?.features??[],H=L?.type,se=H===J.Camera,{data:ce}=lr(l?a:0),de=H===J.Container,fe=i(()=>(ce??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[ce]),he=i(()=>de?Wt(fe,typeof L?.linkDeviceId==`number`?L.linkDeviceId:null,typeof L?.primaryChildEntityId==`string`?L.primaryChildEntityId:null)?.id??null:null,[de,fe,L?.linkDeviceId,L?.primaryChildEntityId]),{data:ge}=re({deviceId:he??0},{enabled:he!==null}),_e=i(()=>{if(he===null)return[];let e=ge?.settings?.sections??[],t=ge?.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:An[e]?.label??e,isAddonContrib:!0,childDeviceId:he}))},[he,ge]),ve=typeof L?.parentDeviceId==`number`?L.parentDeviceId:null,{data:ye}=Ne({deviceId:ve??0},{enabled:ve!==null}),U=ae(),W=L?.disabled!==!0,Se=i(()=>{let e=I?.settings?.sections??[],t=I?.live?.sections??[];return dr([...e,...t],H,y,I!==void 0)},[I,H,y]),Ce=i(()=>{let e=new Set,t=[];for(let n of[...Ys(H,y),...ne,..._e])n.id===`config`&&!Se||e.has(n.id)||(e.add(n.id),t.push(n));return t},[H,y,ne,_e,Se]),we=i(()=>ms(Ce,w),[Ce,w]),Te=e(e=>{x(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[x]),Ee=e(e=>{x(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[x]),De=(ce??[]).length>0,Oe=i(()=>Zs.filter(({featureGate:e})=>!e||V.includes(e)),[V]),{data:ke}=Sn(void 0),Ae=i(()=>L?Me(L,ke):null,[L,ke]),G=Ae?.kind===`resolved`?Ae.integration:null,je=G===null?Ae?.kind===`unknown`?`Loading integration…`:Ae?.kind===`orphan`?`Missing integration`:`No integration`:G.name,Pe=G!==null&&G.addonId===B?G.name:B,Fe=ot({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]}),d(G?.id?`/integrations/${G.id}`:`/integrations`)}}),Ie=le({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Le=pe({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Re=xe(),ze=qt({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Be=V.includes(Yn.Rebootable),Ve=V.includes(Yn.BatteryOperated),He=oe(h.trpcClient,Ve&&l?a:null),Ue=Xt(h.trpcClient,l?a:null),[We,Ke]=c(!1),qe=async()=>{if(!We){Ke(!0);try{let e=R.replace(/[^a-zA-Z0-9_.-]+/g,`_`),t=new Date().toISOString().replace(/[:.]/g,`-`);await qr(`${p}/${String(a)}.jpg?force=1`,`${e}-${t}.jpg`)}finally{Ke(!1)}}},Je=Ie.isPending||Le.isPending,{data:Ye}=lt({deviceId:a},{enabled:l,refetchInterval:1e4}),Xe=Ye?.agentNodeId??null,Ze=typeof Xe==`string`&&Xe.length>0&&!Xe.startsWith(`addon:`)?Xe:void 0,{data:Qe}=ue({deviceId:a,...Ze?{nodeId:Ze}:{}},{enabled:l,refetchInterval:3e3,retry:!1}),{data:$e}=kt({deviceId:a},{enabled:l,refetchInterval:3e3,retry:!1}),et=$e?.level?.dbfs??null;function tt(){if(!l)return null;switch(we){case`overview`:return u(Ks,{device:L??{}});case`config`:return u(ys,{deviceId:a,activeSubTab:T,onSubTabChange:Ee,deviceType:H,isAdmin:y});case`detection-pipeline`:return u(js,{deviceId:a,activeSubTab:T,onSubTabChange:Ee});case`bindings`:return u(hs,{deviceId:a});case mr:return u(ss,{deviceId:a,activeSubTab:T,onSubTabChange:Ee});default:{let e=we,t=ne.some(t=>t.id===e),n=_e.find(t=>t.id===e);if(!t&&n===void 0)return null;let r=n?.childDeviceId??a;if(e===`export`)return u(ur,{deviceId:a,sectionFilter:fr,activeSubTab:T,onSubTabChange:Ee});let i=u(ur,{deviceId:r,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:T,onSubTabChange:Ee});return n!==void 0&&r!==a?u(Ot,{deviceId:r,children:i}):i}}}return l?ee?r(`div`,{className:`flex flex-col h-full`,children:[r(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[u(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),u(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),u(`div`,{className:`flex-1 p-6`,children:u(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):te||!F?r(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[u(`p`,{className:`text-lg font-semibold text-foreground`,children:`Device not found`}),r(`p`,{className:`text-xs`,children:[`No device with ID`,` `,r(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,a]})]}),u(`button`,{onClick:()=>d(`/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:`Back to Integrations`})]}):r(`div`,{className:`absolute inset-0 flex flex-col overflow-clip`,children:[r(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[u(`div`,{className:`mb-2`,children:u(k,{items:[{label:`Integrations`,onClick:()=>d(`/integrations`)},G===null?{label:je}:{label:je,onClick:()=>d(`/integrations/${G.id}`)},{label:R}]})}),r(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[G!==null&&u(Xs,{provider:G.addonId,integrationId:G.id,name:G.name}),r(`div`,{className:`min-w-0 flex-1`,children:[r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:R}),u(Jr,{status:ie}),Ve&&u(me,{status:He,variant:`full`}),u(wt,{status:Ue})]}),ve!==null&&ye&&r(`button`,{type:`button`,onClick:()=>d(`/devices/${ve}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${ye.name}`,children:[u(`span`,{children:`↑`}),u(`span`,{className:`truncate`,children:String(ye.name??`Device #${ve}`)})]}),u(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:V.length>0&&u(hr,{capabilities:V})})]}),Qe&&u(`div`,{className:`hidden lg:flex`,children:u($s,{metrics:Qe,dbfs:et})}),r(`div`,{className:`flex items-center gap-1 shrink-0`,children:[r(`button`,{onClick:async()=>{W?await m({title:`Disable "${R}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&Le.mutate({deviceId:a}):Ie.mutate({deviceId:a})},disabled:Je,title:W?`Disable device`:`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 ${W?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[u(Ge,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden sm:inline`,children:Je?`Updating…`:W?`Enabled`:`Disabled`})]}),u(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),se&&r(o,{children:[u(ai,{deviceId:a}),u(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`})]}),u(si,{deviceId:a}),u(D,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:g,disabled:We,onClick:()=>{qe()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:ut,hidden:!Be,disabled:Re.isPending,danger:!0,onClick:async()=>{await m({title:`Reboot "${R}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&Re.mutate({deviceId:a})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${Pe}.`,icon:Yt,disabled:ze.isPending,danger:!0,onClick:async()=>{await m({title:`Restart "${Pe}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${R}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&ze.mutate({addonId:B})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:S,separatorBefore:!0,disabled:Fe.isPending,danger:!0,onClick:async()=>{await m({title:`Delete "${R}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&Fe.mutate({deviceId:a})}}]})]})]})]}),u(Ot,{deviceId:a,device:L??void 0,children:u(ln,{children:u(gt,{children:u(C,{children:u(jt,{children:r(`main`,{className:U?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[r(`div`,{className:U?`flex flex-col bg-surface`:`${j===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!U&&j!==null?{width:`${String(j)}px`}:void 0,children:[u(`div`,{className:se?`flex-shrink-0 border-b border-border-subtle bg-black`:U?`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:se?u(Vi,{deviceId:a,intercomAvailable:V.includes(Yn.TwoWayAudio)}):u(ji,{deviceId:a,deviceName:R,deviceType:H??`unknown`,provider:B,isOnline:z,features:V})}),r(`div`,{className:U?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[u(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:u(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:Oe.map(({id:e,label:t,icon:n})=>r(`button`,{onClick:()=>O(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${E===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[u(n,{className:`h-3 w-3`}),t]},e))})}),r(`div`,{className:U?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[E===`logs`&&u(Hi,{deviceId:a,containerDeviceId:H===`container`?a:void 0}),E===`repl`&&u(Ui,{deviceId:a}),E===`events`&&u(Wi,{deviceId:a}),E===`state`&&u(Gi,{deviceId:a})]})]})]}),!U&&u(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:P,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:u(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),r(`div`,{className:U?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[u(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:u(`div`,{className:`flex flex-nowrap overflow-x-auto md:flex-wrap md:overflow-x-visible items-center gap-0`,children:Ce.map(e=>{let t=we===e.id;return r(`button`,{onClick:()=>Te(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&&u(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),r(`div`,{className:U?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[we===`overview`&&De&&u(ci,{parentDeviceId:a}),tt()]})]})]})})})})})})]}):r(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[u(`p`,{className:`text-lg font-semibold text-foreground`,children:`Invalid device id`}),r(`p`,{className:`text-xs`,children:[`The URL segment`,` `,u(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:n.deviceId}),` `,`is not a number.`]}),u(`button`,{onClick:()=>d(`/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:`Back to Integrations`})]})}function $s({metrics:e,dbfs:t}){let n=gn(e.phase??`idle`);return r(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[r(`div`,{className:`flex items-center gap-1.5`,children:[u(`span`,{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),u(`span`,{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),u(`div`,{className:`h-3 w-px bg-border`}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[u(z,{className:`h-3 w-3`}),u(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),u(`span`,{children:`fps`})]}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[u(bt,{className:`h-3 w-3`}),u(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),u(`span`,{children:`ms`})]}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:`Current audio level (dBFS)`,children:[u(Dt,{className:`h-3 w-3`}),u(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),u(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&r(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{Qs as DeviceDetailPage};
@@ -1 +0,0 @@
1
- import{K as e,Q as t,S as n,T as r,W as i,b as a,i as o,o as s,p as c,q as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as f,ct as p,gt as m,ht as h,st as g,ut as _,vt as v}from"./player-overlays-CEHVDSJu.js";import{$n as y,$o as b,Al as x,C as S,Cs as C,Du as w,El as T,Es as E,Fs as D,Hn as O,Is as k,Ll as A,Ns as j,Nu as M,O as N,P as ee,Pn as P,Ps as F,Qo as I,Qu as te,Rs as L,Sl as ne,Ss as re,Ts as ie,Wu as ae,Xn as R,Xo as oe,Yn as se,Zo as ce,_l as le,_s as ue,an as de,au as fe,bl as pe,bs as me,ct as he,ds as ge,es as _e,gd as ve,gl as ye,gs as be,hl as z,ht as xe,id as B,in as Se,is as Ce,mn as we,ms as Te,mu as Ee,nn as De,ns as Oe,on as ke,ps as Ae,pu as je,qu as Me,r as V,rn as Ne,rs as Pe,ss as Fe,ts as Ie,vl as Le,vs as Re,w as ze,ws as Be,xl as Ve,xs as He,xt as Ue,xu as We,yd as H,yl as Ge,yu as Ke}from"./src-CQ9R75CO.js";import{a as qe,i as Je,n as U,o as Ye,r as Xe,t as Ze}from"./NodeInferenceDevices-Bqo-7570.js";import{t as Qe}from"./layers-ByvtFPPP.js";import{t as $e}from"./square-check-big-CN0Jzq_i.js";import{n as et}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DX7sYWrs.js";import{Ir as tt,Lr as nt,dn as rt,fn as it,hn as at,mn as ot,un as st}from"./src-DDxhrhKR.js";import{B as ct,E as lt,F as ut}from"./index-CfVrkT4q.js";import"./useEventInvalidation-Ds54E7eB.js";import{t as dt}from"./NodeAddonsSettingsPanel-C56sPvtL.js";import{t as ft}from"./StorageLocationsPanel-Bu7c32vF.js";var pt=v(`pin`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]);t();function mt(e){if(e==null)return null;if(typeof e==`number`)return e>0?e:null;let t=Date.parse(e);return Number.isNaN(t)?null:t}function ht(e){return e}function gt(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function _t(e,t){return typeof e==`boolean`?e:ht(t)}function vt(e,t){return{pipeline:_t(gt(e,`detect`),t),audio:_t(gt(e,`audio`),t),ingest:_t(gt(e,`ingest`),t)}}function yt(e,t,n){let r=e?.find(e=>e.nodeId===t);return vt(r?.settings,n)}function bt({selectedNodeId:e,onSelect:t,refreshToken:r}){let{nodes:i}=ye(),{data:o}=Ae(void 0),{data:s}=be(void 0),c=new Map;for(let e of o??[])c.set(e.agentNodeId,(c.get(e.agentNodeId)??0)+1);let l=i??[],d=l.filter(e=>e.isOnline).length,f=l.filter(e=>!e.isOnline).length;return n(`div`,{className:`flex flex-col h-full`,children:[n(`button`,{type:`button`,onClick:()=>t(Qr),className:`flex items-center gap-3 px-4 py-3 border-b border-border text-left transition-colors ${e===`__cluster__`?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[u(ct,{className:`h-4 w-4 flex-shrink-0`}),n(`div`,{className:`min-w-0 flex-1`,children:[u(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),u(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Balancer + failover + assignments`})]})]}),u(`div`,{className:`flex-1 overflow-y-auto`,children:l.map(r=>{let i=e===r.id,o=c.get(r.id)??0,l=r.isHub?fe:B,d=yt(s,r.id,r.isHub),f=r.isOnline?null:he(mt(r.lastSeen));return n(`button`,{type:`button`,onClick:()=>t(r.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${i?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}${r.isOnline?``:` opacity-60`}`,children:[u(l,{className:`h-4 w-4 flex-shrink-0`}),n(`div`,{className:`min-w-0 flex-1`,children:[n(`div`,{className:`flex items-center gap-2`,children:[u(`span`,{className:`text-xs font-semibold truncate`,children:r.name}),r.isHub&&u(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!r.isOnline&&u(`span`,{className:`h-1.5 w-1.5 rounded-full bg-destructive flex-shrink-0`}),r.isOnline&&u(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),n(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[n(`span`,{children:[r.cpuCores,` cores`]}),u(`span`,{children:`•`}),n(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),o>0&&n(a,{children:[u(`span`,{children:`•`}),n(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[u(x,{className:`h-2.5 w-2.5`}),o]})]}),!r.isOnline&&n(a,{children:[u(`span`,{children:`•`}),n(`span`,{className:`text-destructive`,children:[`offline`,f===null?``:` · ${f}`]})]})]}),n(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[u(O,{variant:d.pipeline?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:d.pipeline?`Pipeline: enabled`:`Pipeline: not enabled (agent capability)`,children:`Pipe`}),u(O,{variant:d.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:d.audio?`Audio: enabled`:`Audio: not enabled (agent capability)`,children:`Aud`})]})]})]},r.id)})}),n(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[n(`span`,{children:[d,` online`]}),f>0&&n(`span`,{className:`text-destructive`,children:[f,` offline`]})]})]})}function xt({nodeId:e,refreshToken:t}){let{nodes:r}=ye(),i=r?.find(t=>t.id===e),o=le(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return i?n(`div`,{className:`px-6 py-4 border-b border-border`,children:[n(`div`,{className:`flex items-center gap-2 mb-1`,children:[u(`h2`,{className:`text-base font-semibold text-foreground`,children:i.name}),i.isOnline?u(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):u(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`}),i.isHub&&u(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),n(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[u(`span`,{children:i.cpuModel??`CPU`}),u(`span`,{children:`•`}),n(`span`,{children:[i.cpuCores,` cores`]}),u(`span`,{children:`•`}),n(`span`,{children:[Math.round(i.memoryMB/1024),` GB`]}),o&&n(a,{children:[u(`span`,{children:`•`}),n(`span`,{children:[o.attachedCameras,` cameras (`,o.activeCameras,` active)`]}),u(`span`,{children:`•`}),n(`span`,{children:[o.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),u(`span`,{children:`•`}),n(`span`,{children:[`queue `,o.queueDepthTotal]}),o.hardware.hasGpu&&n(a,{children:[u(`span`,{children:`•`}),u(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):u(`div`,{className:`px-6 py-4 border-b border-border`,children:n(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}var St=[`assignments`,`tree`,`engines`,`logs`];function Ct({refreshToken:e,nodeId:t}){let[r,a]=l(new Map),{nodes:o}=z();Ge(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t?.deviceId==`number`&&a(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})});let{data:s}=Ce(void 0),c=i(()=>{let e=new Map;for(let t of s??[])e.set(t.nodeId,t.deviceCount);return e},[s]),d=i(()=>{let e=new Map,t=Date.now()-3e4;for(let n of r.values()){if(n.timestamp<t)continue;let r=n.nodeId??`hub`,i=e.get(r)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};i.attachedCameras++,n.metrics.phase===`active`&&i.activeCameras++,i.totalFps+=n.metrics.actualFps,i.totalInferenceWeighted+=n.metrics.avgInferenceTimeMs,i.queueDepth+=n.metrics.queueDepth,e.set(r,i)}return e},[r]),f=i(()=>{let e=new Map;for(let t of o)e.set(t.id,t.shortName);return e},[o]),p=i(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of d.values())e+=a.attachedCameras,t+=a.activeCameras,n+=a.totalFps,r+=a.totalInferenceWeighted,i+=a.queueDepth;let a=e>0?r/e:0;return{totalAgents:o.length,onlineAgents:o.filter(e=>e.isOnline).length,attachedCameras:e,activeCameras:t,avgInferenceTimeMs:a,queueDepth:i,totalFps:n}},[d,o]);if(t){let e=d.get(t);return n(`div`,{className:`@container/liveload`,children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),n(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[u(W,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),u(W,{label:`Active / Attached`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),u(W,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),u(W,{label:`Queue`,value:e?String(e.queueDepth):`—`}),u(W,{label:`Audio`,value:String(c.get(t)??`—`)})]})]})}let m=[...d.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return n(`div`,{className:`@container/liveload`,children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),n(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[u(W,{label:`Total agents`,value:`${p.onlineAgents}/${p.totalAgents}`}),u(W,{label:`Active / Attached`,value:`${p.activeCameras}/${p.attachedCameras}`}),u(W,{label:`Total FPS`,value:p.totalFps.toFixed(1)}),u(W,{label:`Avg inference ms`,value:p.avgInferenceTimeMs.toFixed(0)}),u(W,{label:`Queue depth`,value:String(p.queueDepth)})]}),u(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[480px]`,children:[u(`thead`,{className:`bg-surface`,children:n(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[u(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),u(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),u(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),u(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),u(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),u(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),n(`tbody`,{children:[m.map(([e,t])=>n(`tr`,{className:`border-t border-border`,children:[u(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:f.get(e)??e}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:c.get(e)??`—`})]},e)),m.length===0&&u(`tr`,{children:u(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function W({label:e,value:t}){return n(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[u(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),u(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}t();var wt={active:!1,pinned:!1,nodeId:null,reason:``},Tt=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`],Et=3e5,Dt={pipeline:B,decoder:Me,audio:_},Ot={pipeline:`Pipeline`,decoder:`Decoder`,audio:`Audio`};function kt({mode:e,nodeId:t,compact:o=!1}){if(e===`agent`&&!t)throw Error(`CameraAssignmentsTable: nodeId is required when mode === "agent"`);let c=s(),[f,p]=l(null),[g,_]=l(null),[v,y]=l(new Map);V([`pipelineOrchestrator`,`getPipelineAssignments`],Tt),V([`pipelineOrchestrator`,`getAudioAssignments`],Tt),V([`pipelineOrchestrator`,`getCameraStatuses`],Tt);let{data:x}=Ae(void 0),{data:S}=Pe(void 0),{data:C}=Fe({},{enabled:e===`agent`}),{nodes:w}=z(),{data:T}=lt();Ge(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t.deviceId==`number`&&y(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})}),d(()=>{if(v.size===0)return;let e=setInterval(()=>{y(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[v.size]);let E=i(()=>{let e=new Map;for(let t of T??[])e.set(t.id,t.name);return e},[T]),O=i(()=>{if(e===`agent`){let e=[];for(let n of C??[]){let r=n.assignment,i=(e,n,r)=>({active:e!==null&&e===t,pinned:n,nodeId:e,reason:r??``}),a=i(r.detectionNodeId,r.pinned.detection,r.reasons.detection),o=i(r.decoderNodeId,r.pinned.decoder,r.reasons.decoder),s=i(r.audioNodeId,r.pinned.audio,r.reasons.audio);!a.active&&!o.active&&!s.active||e.push({deviceId:n.deviceId,deviceName:E.get(n.deviceId)??`Device ${n.deviceId}`,pipeline:a,decoder:o,audio:s})}return e.sort((e,t)=>e.deviceId-t.deviceId),e}let n=new Map,r=e=>{let t=n.get(e);if(t)return t;let r={deviceId:e,deviceName:E.get(e)??`Device ${e}`,pipeline:wt,decoder:wt,audio:wt};return n.set(e,r),r};for(let i of x??[]){let a=r(i.deviceId);n.set(i.deviceId,{...a,pipeline:{active:!0,pinned:i.pinned,nodeId:i.agentNodeId,reason:i.reason??``},decoder:{active:e===`cluster`?!0:i.agentNodeId===t,pinned:!1,nodeId:i.agentNodeId,reason:`co-located`}})}for(let e of S??[]){let t=r(e.deviceId);n.set(e.deviceId,{...t,audio:{active:!0,pinned:e.pinned,nodeId:e.nodeId,reason:`capacity`}})}let i=[...n.values()];return i.sort((e,t)=>e.deviceId-t.deviceId),i},[x,S,C,E,e,t]),k=i(()=>(w??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[w]),A=()=>{c.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),c.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]}),c.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},j=_e({onSuccess:A}),M=D({onSuccess:A}),N=b({onSuccess:A}),ee=F({onSuccess:A}),P=(e,t,n)=>{t===`pipeline`?j.mutate({deviceId:e,agentNodeId:n}):N.mutate({deviceId:e,nodeId:n}),p(null)},I=(e,t)=>{t===`pipeline`?M.mutate({deviceId:e}):ee.mutate({deviceId:e}),p(null)};return u(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[760px] table-fixed`,children:[u(`thead`,{className:`bg-surface`,children:n(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[!o&&u(`th`,{className:`w-10`}),u(`th`,{className:`min-w-[200px] text-left px-3 py-2 align-middle`,children:`Camera`}),e===`cluster`?n(a,{children:[u(`th`,{className:`w-[168px] text-left px-3 py-2 align-middle`,children:`Auto | Pin`}),u(`th`,{className:`w-[188px] text-left px-3 py-2 align-middle`,children:`Resolved placement`})]}):n(a,{children:[u(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Pipeline`}),u(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Decoder`}),u(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Audio`})]}),u(`th`,{className:`w-[132px] text-left px-3 py-2 align-middle`,children:`Status`})]})}),n(`tbody`,{children:[O.map(t=>{let i=v.get(t.deviceId),s=g===t.deviceId;return n(r.Fragment,{children:[n(`tr`,{className:`border-t border-border align-middle relative`,children:[!o&&u(`td`,{className:`px-2 py-2 align-middle`,children:u(`button`,{type:`button`,onClick:()=>_(s?null:t.deviceId),className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":s?`Collapse broker details`:`Expand broker details`,children:u(s?m:h,{className:`h-3.5 w-3.5`})})}),n(`td`,{className:`px-3 py-2 align-middle min-w-0`,children:[u(`div`,{className:`text-foreground font-medium leading-tight line-clamp-2 break-words`,title:t.deviceName,children:t.deviceName}),n(`div`,{className:`text-[10px] text-foreground-subtle leading-tight`,children:[`#`,t.deviceId]})]}),e===`cluster`?n(a,{children:[u(`td`,{className:`px-3 py-2 align-middle`,children:u(jt,{state:t.pipeline,onlineNodes:k,pending:j.isPending||M.isPending,onChange:e=>{e===`auto`?I(t.deviceId,`pipeline`):P(t.deviceId,`pipeline`,e)}})}),u(`td`,{className:`px-3 py-2 align-middle`,children:u(Nt,{state:t.pipeline,deviceId:t.deviceId})})]}):n(a,{children:[u(Ft,{role:`pipeline`,state:t.pipeline,mode:e,deviceId:t.deviceId,onlineNodes:k,isMenuOpen:f?.deviceId===t.deviceId&&f.role===`pipeline`,onToggleMenu:()=>p(f?.deviceId===t.deviceId&&f.role===`pipeline`?null:{deviceId:t.deviceId,role:`pipeline`}),onCloseMenu:()=>p(null),onMove:e=>P(t.deviceId,`pipeline`,e),onUnpin:()=>I(t.deviceId,`pipeline`)}),u(Ft,{role:`decoder`,state:t.decoder,mode:e,deviceId:t.deviceId,onlineNodes:k,readOnly:!0,isMenuOpen:!1,onToggleMenu:()=>void 0,onCloseMenu:()=>void 0,onMove:()=>void 0,onUnpin:()=>void 0}),u(Ft,{role:`audio`,state:t.audio,mode:e,deviceId:t.deviceId,onlineNodes:k,isMenuOpen:f?.deviceId===t.deviceId&&f.role===`audio`,onToggleMenu:()=>p(f?.deviceId===t.deviceId&&f.role===`audio`?null:{deviceId:t.deviceId,role:`audio`}),onCloseMenu:()=>p(null),onMove:e=>P(t.deviceId,`audio`,e),onUnpin:()=>I(t.deviceId,`audio`)})]}),u(`td`,{className:`px-3 py-2 align-middle`,children:u(zt,{snap:i})})]}),s&&!o&&n(`tr`,{className:`bg-surface/50`,children:[u(`td`,{}),n(`td`,{colSpan:e===`cluster`?4:5,className:`px-3 py-2 space-y-3`,children:[t.pipeline.nodeId&&u(At,{deviceId:t.deviceId,nodeId:t.pipeline.nodeId}),u(we,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:t.deviceId,instanceId:`pipeline-row/${t.deviceId}`,config:{variant:`compact`,title:`Stream brokers & clients`}})]})]})]},t.deviceId)}),O.length===0&&u(`tr`,{children:u(`td`,{colSpan:o?e===`cluster`?4:5:e===`cluster`?5:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:e===`agent`?`No cameras assigned to this node`:`No cameras currently assigned`})})]})]})})}function At({deviceId:e,nodeId:t}){let r=s(),{data:i}=ge({nodeId:t}),{data:a}=Te({deviceId:e}),o=j({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}}),c=i?.devices??[],l=a?.deviceKey??`auto`,d=l!==`auto`&&!c.some(e=>e.key===l);return n(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[u(`span`,{className:`shrink-0 font-medium text-foreground`,children:`Inference device`}),n(`select`,{value:l,disabled:o.isPending,"aria-label":`Inference device pin`,onChange:t=>o.mutate({deviceId:e,deviceKey:t.target.value}),className:`rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[u(`option`,{value:`auto`,children:`Auto (balanced)`}),d&&n(`option`,{value:l,children:[`Pin → `,l,` (not on this node)`]}),c.map(e=>n(`option`,{value:e.key,children:[`Pin → `,e.key,e.available?``:` (unavailable)`]},e.key))]}),o.isPending&&u(`span`,{className:`text-[10px] opacity-70`,children:`saving…`})]})}function jt({state:e,onlineNodes:t,pending:r,onChange:i}){let a=e.pinned&&e.nodeId?e.nodeId:`auto`,o=[...new Set([...e.nodeId?[e.nodeId]:[],...t.map(e=>e.id)])];return n(`select`,{value:a,disabled:r,"aria-label":`Pipeline placement pin`,onChange:e=>i(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[u(`option`,{value:`auto`,children:`Auto`}),o.map(e=>n(`option`,{value:e,children:[`Pin → `,t.find(t=>t.id===e)?.name??e]},e))]})}function Mt(t){let n=e(null);return t.nodeId!==null&&(n.current=t),n.current}function Nt({state:e,deviceId:t}){let r=Mt(e),i=e.active&&e.nodeId!==null;if(r===null||r.nodeId===null)return u(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`— · no session yet`});let a=r.pinned?`pinned · manual`:`auto · ${r.reason||`capacity`}`;return n(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[u(`span`,{className:`font-mono text-[11px] truncate ${i?`text-foreground`:`text-foreground-subtle`}`,title:r.pinned?r.nodeId:`${r.nodeId} — an unpinned camera is re-elected per on-motion session, so this can change between sessions`,children:r.nodeId}),u(`span`,{className:`truncate ${r.pinned?`text-amber-400 text-[10px]`:`text-foreground-subtle text-[10px]`}`,title:a,children:a}),u(`span`,{className:`truncate text-[10px] ${i?`text-emerald-400`:`text-foreground-subtle/70`}`,children:i?`● running here`:`○ idle · last session here`}),u(Pt,{deviceId:t,nodeId:r.nodeId})]})}function Pt({deviceId:e,nodeId:t}){let r=s(),{data:i}=Te({deviceId:e},{refetchOnMount:`always`}),{data:a}=ge({nodeId:t},{staleTime:Et}),o=j({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});if(i===void 0||a===void 0)return u(`span`,{className:`mt-0.5 text-[10px] text-foreground-subtle italic`,children:`device: …`});let c=a.devices??[],l=c.filter(e=>e.enabled),d=i.deviceKey??`auto`,f=d!==`auto`&&!l.some(e=>e.key===d),p=c.find(e=>e.key===d);return n(`select`,{value:d,disabled:o.isPending,"aria-label":`Inference device pin`,onChange:t=>o.mutate({deviceId:e,deviceKey:t.target.value}),className:`mt-0.5 w-full min-w-0 rounded border border-border bg-background px-1 py-0.5 text-[10px] text-foreground disabled:opacity-50`,children:[u(`option`,{value:`auto`,children:`Auto (balanced)`}),f&&n(`option`,{value:d,children:[p?`${U(p).label} (${d})`:d,` (not enabled)`]}),l.map(e=>n(`option`,{value:e.key,children:[U(e).label,` · `,e.format]},e.key))]})}function Ft({role:e,state:t,mode:r,onlineNodes:i,readOnly:a=!1,isMenuOpen:o,onToggleMenu:s,onCloseMenu:c,onMove:l,onUnpin:d}){let f=Dt[e],p=i.filter(e=>e.id!==(t.nodeId??``)),m=!a&&(t.active||r===`cluster`)&&(p.length>0||t.pinned);return n(`td`,{className:`px-3 py-2 align-middle relative min-w-0`,children:[n(`div`,{className:`flex items-center gap-2 min-w-0`,children:[u(r===`agent`?It:Lt,{state:t,Icon:f}),u(`div`,{className:`ml-auto shrink-0`,children:m&&u(`button`,{type:`button`,onClick:s,className:`p-1 rounded hover:bg-surface-hover`,"aria-label":`${Ot[e]} actions`,children:u(te,{className:`h-3 w-3 text-foreground-subtle`})})})]}),o&&m&&u(Bt,{title:Ot[e],targets:p,pinned:t.pinned,onMove:l,onUnpin:d,onClose:c})]})}function It({state:e,Icon:t}){return n(`div`,{className:`flex items-center gap-1.5`,children:[u(e.active?$e:p,{className:`h-3.5 w-3.5 ${e.active?`text-success`:`text-foreground-subtle/50`}`}),u(t,{className:`h-3 w-3 ${e.active?`text-foreground-subtle`:`text-foreground-subtle/40`}`}),e.pinned&&u(pt,{className:`h-2.5 w-2.5 text-amber-400`})]})}function Lt({state:e,Icon:t}){return!e.active||!e.nodeId?n(`div`,{className:`flex items-center gap-1.5 text-foreground-subtle/60`,children:[u(t,{className:`h-3 w-3`}),u(`span`,{className:`text-[10px] italic`,children:`—`})]}):n(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[u(t,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),n(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[u(`span`,{className:`font-mono text-[11px] text-foreground truncate`,children:e.nodeId}),u(`span`,{className:`flex items-center gap-1 text-[10px]`,children:e.pinned?n(`span`,{className:`inline-flex items-center gap-0.5 text-amber-400`,children:[u(pt,{className:`h-2.5 w-2.5`}),` manual`]}):n(`span`,{className:`text-foreground-subtle truncate`,children:[`auto · `,e.reason||`capacity`]})})]})]})}var Rt=`min-h-[3.25rem]`;function zt({snap:e}){if(!e)return u(`div`,{className:`flex items-center ${Rt}`,children:u(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`})});let{phase:t,actualFps:r,avgInferenceTimeMs:i,queueDepth:a,configuredFps:o,droppedFrames:s}=e.metrics,c=Ue(t);return n(`div`,{className:`flex flex-col justify-center gap-0.5 font-mono text-[10px] tabular-nums leading-tight min-w-0 ${Rt}`,children:[n(`span`,{className:`inline-flex items-center gap-1 min-w-0 ${c.textColor}`,children:[u(N,{phase:t,className:`h-2.5 w-2.5 shrink-0`}),u(`span`,{className:`font-semibold uppercase tracking-wider truncate`,children:c.label})]}),n(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[u(`span`,{className:`text-foreground`,children:r.toFixed(1)}),n(`span`,{children:[`/`,o.toFixed(0),` fps`]})]}),n(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[u(`span`,{className:`text-foreground`,children:i.toFixed(0)}),u(`span`,{children:` ms`}),a>0&&n(`span`,{className:`text-warning ml-1`,children:[`q`,a]})]}),n(`span`,{className:`whitespace-nowrap truncate ${s>0?`text-warning`:`text-foreground-subtle`}`,children:[`drops `,u(`span`,{className:`text-foreground`,children:s})]})]})}function Bt({title:t,targets:r,pinned:i,onMove:a,onUnpin:o,onClose:s}){let c=e(null);return d(()=>{let e=e=>{c.current?.contains(e.target)||s()};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[s]),n(`div`,{ref:c,className:`absolute right-2 top-full mt-1 w-48 rounded-lg border border-border bg-surface shadow-lg z-20 text-left`,children:[u(`div`,{className:`px-3 py-1 text-[9px] uppercase tracking-wider text-foreground-subtle border-b border-border`,children:t}),r.length>0&&u(`div`,{className:`py-1`,children:r.map(e=>n(`button`,{type:`button`,onClick:()=>a(e.id),className:`block w-full text-left px-3 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[`Move to `,e.name]},e.id))}),i&&n(`button`,{type:`button`,onClick:o,className:`block w-full text-left px-3 py-1.5 text-[11px] text-destructive hover:bg-destructive/10 border-t border-border`,children:[`Unpin `,t.toLowerCase()]}),r.length===0&&!i&&u(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle italic`,children:`Already auto · no other nodes online`})]})}function Vt({nodeId:e,refreshToken:t}){return n(`div`,{className:`space-y-6`,children:[u(Ct,{refreshToken:t,nodeId:e}),n(`div`,{children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Cameras on this node`}),n(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Checkboxes mark the roles currently running on `,e,`. Use the kebab to move a role to another node or unpin it; live KPIs come from the runner snapshot stream.`]})]}),u(kt,{mode:`agent`,nodeId:e,compact:!0})]})}t();function Ht(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function Ut({nodeId:e,refreshToken:t}){let r=s(),a=P(),o=ce({onSettled:()=>{r.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:c}=I({nodeId:e}),l=le(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??c??null,d=l===null;V([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:f}=L({nodeId:e}),{values:p}=Le(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),m=i(()=>p.filter(e=>e.metrics.phase===`active`).length,[p]),h=t=>{let n=f??[];if(n.length===0){o.mutate({nodeId:e,engine:t,force:!1});return}(async()=>{await a({title:`Kill engine`,message:`${String(n.length)} camera(s) are dispatching through this engine. Killing it drops their in-flight work and forces a respawn on the next frame.`,confirmLabel:`Kill engine`,variant:`danger`})&&o.mutate({nodeId:e,engine:t,force:!0})})()};return n(`div`,{className:`space-y-6`,children:[n(`div`,{children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),n(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(l??[]).length,` engine(s) resident in RAM. `,(f??[]).length,` `,`camera(s) attached, `,m,` actively dispatching frames. Refreshes every 5s.`]})]}),u(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[640px]`,children:[u(`thead`,{className:`bg-surface`,children:n(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[u(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),u(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),u(`th`,{className:`text-left px-3 py-2`,children:`Models`}),u(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),u(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),u(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),u(`th`,{className:`w-20`})]})}),n(`tbody`,{children:[d&&u(`tr`,{children:u(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!d&&(l??[]).map(e=>{let t=e.kind===`device-pool`;return n(`tr`,{className:`border-t border-border ${t?`bg-primary/[0.05]`:``}`,children:[u(`td`,{className:`px-3 py-2`,children:n(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-medium ${t?`bg-primary/15 text-primary`:`bg-success/15 text-success`}`,children:[u(t?Qe:B,{className:`h-3 w-3`}),t?`pool`:`runtime`]})}),u(`td`,{className:`px-3 py-2`,children:n(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[u(Ve,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),u(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?u(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):u(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>u(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),u(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),u(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?u(`span`,{className:`text-foreground-subtle`,children:Ht(e.idleMs,e.idleTtlMs)}):u(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:(f??[]).length}),u(`td`,{className:`px-3 py-2 text-right`,children:t?u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`auto`}):n(`button`,{type:`button`,disabled:o.isPending,onClick:()=>h(e.engine),className:`inline-flex items-center gap-1 px-2 py-1 rounded border border-destructive/30 text-destructive text-[11px] hover:bg-destructive/10 disabled:opacity-50`,children:[u(g,{className:`h-3 w-3`}),`Kill`]})})]},e.engineKey)}),!d&&(l??[]).length===0&&u(`tr`,{children:u(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No engines resident — the factory spins up on the first pipeline run.`})})]})]})}),n(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[u(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,u(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`,` `,u(`strong`,{className:`text-foreground`,children:`pool`}),`: a per-device balanced inference pool (one per enabled accelerator, running concurrently); reaper-managed on its own idle TTL.`]}),o.isError&&n(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,o.error instanceof Error?o.error.message:`unknown`]})]})}var Wt=`pipeline-runner`,Gt=200;function Kt({nodeId:e}){return n(`div`,{className:`flex flex-col gap-3`,children:[n(`div`,{children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Runner logs`}),n(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`pipeline-runner activity on `,e,` — camera attach/detach, engine phases and pipeline errors. Streaming live; the device chip on a line tells which camera it refers to.`]})]}),u(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:u(xe,{agentId:e,addonId:Wt,limit:Gt,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}t(),t();function qt({nodeId:e,title:t}){let{data:r}=lt(),{data:a}=Ae(void 0),o=i(()=>{let e=new Map;for(let t of r??[])e.set(t.id,t.name);return e},[r]),s=i(()=>{if(!e)return null;let t=new Set;for(let n of a??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,a]),[c,f]=l(new Map);Ge(`pipeline.camera-metrics-snapshot`,t=>{let n=t.data;typeof n.deviceId==`number`&&(e&&n.nodeId!==e||f(e=>{let t=new Map(e);return t.set(n.deviceId,n),t}))}),d(()=>{if(c.size===0)return;let e=setInterval(()=>{f(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[c.size]);let p=i(()=>{let e=[];for(let t of c.values())s&&!s.has(t.deviceId)||e.push(t);return e.sort((e,t)=>e.deviceId-t.deviceId),e},[c,s]);return p.length===0?n(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-[11px] text-foreground-subtle italic`,children:[t??`Cameras`,`: no live snapshots yet`]}):n(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[n(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[u(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),u(`span`,{className:`text-[10px] text-foreground-subtle`,children:p.length})]}),u(`div`,{className:`flex flex-wrap gap-1.5`,children:p.map(e=>{let t=o.get(e.deviceId)??`#${e.deviceId}`,r=Ue(e.metrics.phase);return n(`div`,{title:`${t} · ${r.label} · ${e.metrics.actualFps.toFixed(1)} fps · ${e.metrics.avgInferenceTimeMs.toFixed(0)}ms infer · q=${e.metrics.queueDepth}`,className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] ${r.badgeClass}`,children:[u(N,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),u(`span`,{className:`font-medium text-foreground/90 max-w-[220px] truncate`,children:t}),u(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),u(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}var Jt=`pipeline-orchestrator`;function Yt(e){return rt.find(t=>t.stepId===e)??null}function Xt({title:e}){return u(`span`,{title:e??`One value for the whole cluster — this step writes into a shared vector index, where two encoders make similarity scores meaningless.`,className:`ml-1 rounded border border-primary/40 bg-primary/10 px-1 py-px text-[9px] font-medium uppercase tracking-wide text-primary`,children:`cluster-wide`})}function Zt({step:e,engineFormat:t,runnableModelIds:r}){let i=s(),{data:a,isLoading:o}=R({addonId:Jt}),c=y({onSuccess:()=>{i.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),l=ot(a??null)[e.stepId]??e.defaultModelId,d=r.length>0&&!r.includes(l);return n(`div`,{className:`space-y-3`,children:[n(`div`,{className:`rounded-md border border-primary/30 bg-primary/5 px-3 py-2`,children:[n(`div`,{className:`flex items-center text-[11px] font-medium text-foreground`,children:[e.label,u(Xt,{})]}),n(`p`,{className:`mt-1 text-[10px] leading-snug text-foreground-subtle`,children:[`Applies to every node. Changing it does not corrupt `,e.indexName,` — every vector carries the model that produced it and only matches its own — but it STRANDS it: the existing vectors stay readable and match nothing until a re-embed pass has run.`]})]}),o?u(M,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):u(`select`,{className:`w-full rounded border border-border bg-surface px-2 py-1 text-xs`,value:l,disabled:c.isPending,onChange:t=>{t.target.value!==l&&c.mutate({addonId:Jt,patch:{[it(e.stepId)]:t.target.value}})},children:e.options.map(t=>n(`option`,{value:t.id,children:[t.label,t.id===e.defaultModelId?` (default)`:``]},t.id))}),d&&n(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[10px] leading-snug text-amber-300`,children:[`This node's engine (`,t,`) ships no build of `,u(`b`,{children:l}),`. It will REFUSE this step rather than run a different encoder — a substitute would put a second feature space into `,e.indexName,`. Either pick a model with a `,t,` build, or accept that this node contributes nothing to that index.`]}),u(`p`,{className:`text-[10px] leading-snug text-foreground-subtle`,children:`Stored once, in Pipeline → Cluster → Settings → Enrichment models. This editor writes that same row — there is no per-node copy of this value. Step knobs for this encoder (minimum face size, …) live on that same settings page.`})]})}t();function G(e,t){if(!e)return null;for(let n of e.slots)for(let e of n.addons)if(e.id===t)return e;return null}function Qt(e){if(!e)return null;let t=e.modelId!==void 0&&e.modelId!==``?e.modelId:void 0,n=e.settings&&Object.keys(e.settings).length>0?e.settings:void 0;return t===void 0&&n===void 0?null:{...t===void 0?{}:{modelId:t},...n===void 0?{}:{settings:n}}}function $t({nodeId:e,refreshToken:t}){let r=s(),[o,c]=l(null),[d,f]=l(null),[p,m]=l(``),[h,g]=l(null),_=ge({nodeId:e},{refetchOnMount:`always`}),v=oe({nodeId:e},{refetchOnMount:`always`}),y=ot(R({addonId:`pipeline-orchestrator`}).data??null),b=_.data?.devices??[],x=ie({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),C=i(()=>v.data?S(v.data):[],[v.data]),w=i(()=>b.map(t=>({agentNodeId:e,engineLabel:t.format,deviceKey:t.key,deviceLabel:U(t).label})),[b,e]),T=e=>b.find(t=>t.key===e)??null,E=i(()=>b.filter(e=>e.enabled),[b]),D=E.length>=2,O=(e,t)=>de(G(v.data??null,e)?.models??[],t?.format),k=e=>{let t=T(e);return t?U(t).label:e},A=(e,t)=>E.filter(n=>n.key!==t&&O(e,n)).toSorted((e,t)=>e.key<t.key?-1:+(e.key>t.key))[0]??null,j=e=>{let t=G(v.data??null,e)?.enabledByDefault??!0;return{kind:`gate`,effectiveOn:t,defaultOn:t,explicit:!1}},M=(e,t)=>{let n=G(v.data??null,e);if(n)return Ne(n,t)},N=(e,t)=>{let n=j(e),r=n.kind===`gate`?n.effectiveOn:!1,i=G(v.data??null,e),a=t.deviceKey===void 0?null:T(t.deviceKey),o=de(i?.models??[],a?.format),s=a?.steps?.[e];if(!o){if(!r)return{kind:`na`};let n=s?.jumpDeviceKey,i=n!==void 0&&E.some(e=>e.key===n)?n:t.deviceKey===void 0?void 0:A(e,t.deviceKey)?.key;return i===void 0?{kind:`skip`}:{kind:`skip`,jumpTo:k(i)}}let c=Yt(e);return c?{kind:`enabled`,modelId:y[e]??c.defaultModelId,clusterWide:!0}:{kind:`enabled`,modelId:(i?Se({catalog:i,device:a,base:s?.modelId}):void 0)??`Auto`,...s?.jumpDeviceKey!==void 0&&E.some(e=>e.key===s.jumpDeviceKey)?{jumpTo:k(s.jumpDeviceKey)}:{}}},P=o&&v.data?G(v.data,o.addonId):null,F=o?T(o.deviceKey):null,I=F?.format??`coreml`,te=o?M(o.addonId,F):void 0,L=()=>{c(null),f(null),m(``)},ne=(e,t)=>{if(t.deviceKey===void 0)return;let n=T(t.deviceKey)?.steps?.[e];c({addonId:e,deviceKey:t.deviceKey});let r=n?.settings??qe(b.map(e=>({key:e.key,enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}})),t.deviceKey,e)??{};f({enabled:!0,...n?.modelId===void 0?{}:{modelId:n.modelId},settings:r}),m(n?.jumpDeviceKey??``)},re=()=>{if(!o)return;let t=Qt(d),n=p!==``&&p!==o.deviceKey?p:void 0,r=t||n!==void 0?{...t,...n===void 0?{}:{jumpDeviceKey:n}}:null,i=b.map(e=>{let t={...e.steps};return e.key===o.deviceKey&&(r?t[o.addonId]=r:delete t[o.addonId]),{key:e.key,enabled:e.key===o.deviceKey?!0:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:t}}),a=r?.settings!==void 0&&Object.keys(r.settings).length>0?Ye(i,o.deviceKey,o.addonId):i;x.mutate({agentNodeId:e,inferenceDevices:Je(a)},{onSuccess:L})};if(_.isLoading||v.isLoading)return u(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(b.length===0)return u(`div`,{className:`rounded-md border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No inference devices reported by this node's platform probe.`});if(!v.data)return u(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let ae=o!==null&&P!==null&&F!==null;return n(`div`,{className:`relative h-full w-full space-y-3`,children:[n(`div`,{className:`rounded-md border border-border bg-muted/20 px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[`Each column is one of this node's inference accelerators. A cell shows the`,` `,u(`span`,{className:`font-medium text-foreground`,children:`base model`}),` every camera landing on that accelerator runs; click to change it. Whether a camera runs a step is set per-camera on that camera's Detection pipeline tab — there is no gate here.`]}),u(`div`,{className:ae?`md:pr-[360px]`:``,children:C.length>0?u(ee,{tree:C,agents:w,gateFor:j,getCellState:N,onCellClick:ne,selectedCell:o?{addonId:o.addonId,agentNodeId:e,deviceKey:o.deviceKey}:null,onSetGate:()=>{},fallbackNodeId:h,onFallbackNodeChange:g,hideGate:!0}):u(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),u(ze,{open:ae,onClose:L,title:P?.name??``,subtitle:o&&F?`${e} · ${U(F).label} · ${F.format}`:``,footer:n(a,{children:[u(`div`,{className:`flex-1`}),u(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:L,children:`Cancel`}),u(`button`,{type:`button`,disabled:!o||!d||x.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:re,children:x.isPending?`Saving…`:`Save`})]}),children:P&&o&&Yt(o.addonId)?u(Zt,{step:Yt(o.addonId),engineFormat:I,runnableModelIds:ke(P.models??[],I).map(e=>e.id)}):P&&o&&d?n(`div`,{className:`space-y-3`,children:[D&&n(`div`,{className:`rounded-md border border-border bg-muted/10 px-3 py-2 space-y-1`,children:[u(`label`,{className:`block text-[11px] font-medium text-foreground`,children:`Run on`}),n(`select`,{className:`w-full rounded border border-border bg-surface px-2 py-1 text-xs`,value:p,onChange:e=>m(e.target.value),children:[u(`option`,{value:``,children:`Auto (this device, or auto-jump if unsupported)`}),E.filter(e=>e.key!==o.deviceKey).map(e=>n(`option`,{value:e.key,children:[U(e).label,` · `,e.format]},e.key))]}),u(`p`,{className:`text-[10px] leading-snug text-foreground-subtle`,children:`Route this step (and its child steps) to another accelerator on this node.`})]}),u(De,{mode:`agent`,addon:P,agentDefault:d,agentNodeId:e,engineFormat:I,effectiveModelId:te,onChangeAgentConfig:f})]}):u(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-300`,children:`This accelerator is no longer reported by the node, so there is nothing to provision here.`})})]})}t();var en=!1;function tn({nodeId:e,refreshToken:t}){let r=P(),[i,a]=l(null),[o,s]=l(null),{nodes:c}=z(),d=c.find(t=>t.id===e),f=d?.name??e,p=d?.isOnline??!1,m=me({onSuccess:e=>{s(e.effectiveModelId===null?`Reset done — model config cleared (node offline: effective model resolves on reconnect)`:`Reset done — effective detection model: ${e.effectiveModelId} (Auto)`)}}),h=async()=>{await r({title:`Reset ${f} to hardware-aware defaults?`,message:`This clears every per-device model default on this node (back to the format default) and every per-camera step override scoped to it. Existing per-camera customisations on this node are lost.`,confirmLabel:`Reset`,variant:`danger`})&&(s(null),m.mutate({agentNodeId:e}))};return n(`div`,{className:`relative h-full w-full space-y-3`,children:[n(`div`,{className:`flex items-center justify-end gap-2 text-xs`,children:[o&&u(`span`,{className:`text-emerald-400`,children:o}),m.isError&&u(`span`,{className:`text-red-400`,children:m.error instanceof Error?m.error.message:`Reset failed`}),u(`button`,{type:`button`,onClick:()=>{h()},disabled:m.isPending,className:`rounded border border-amber-500/40 bg-surface px-2 py-0.5 text-amber-300 hover:bg-surface-hover disabled:opacity-50`,title:`Clear this node's per-device model defaults + per-camera overrides scoped to this node`,children:m.isPending?`Resetting…`:`Reset to default`})]}),u(qt,{nodeId:e}),en,en,n(`div`,{children:[u(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices — default model per accelerator`}),u(Ze,{nodeId:e,nodeName:f,isOnline:p})]}),n(`div`,{children:[u(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection steps — model per accelerator`}),u($t,{nodeId:e,refreshToken:t})]})]})}var nn=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],rn=`decoder-nodeav`;function an({nodeId:e,refreshToken:t}){let{nodes:r}=z(),i=r.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.addonId??rn,a=[...nn,i],o={assignments:{id:`assignments`,label:`Assignments`,order:-10,content:u(Vt,{nodeId:e,refreshToken:t})},tree:{id:`tree`,label:`Pipeline`,order:39,content:u(tn,{nodeId:e,refreshToken:t})},engines:{id:`engines`,label:`Warm instances`,order:180,content:u(Ut,{nodeId:e,refreshToken:t})},logs:{id:`logs`,label:`Logs`,order:300,content:u(Kt,{nodeId:e})}},s=St.map(e=>o[e]);return n(`div`,{className:`flex flex-col h-full`,children:[u(xt,{nodeId:e,refreshToken:t}),u(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-6`,children:u(dt,{nodeId:e,addonIds:a,level:`global`,extraTabs:s})})]})}function on(e){let t=e.backend.toLowerCase(),n=e.device.toLowerCase();return e.key===`cpu`||n===`cpu`?`CPU`:t===`openvino`&&n===`npu`?`Intel NPU`:t===`openvino`&&(n===`gpu`||n===`igpu`)?`Intel iGPU`:t===`edgetpu`?`Coral Edge TPU`:t===`coreml`?`Apple ANE`:`${e.backend} ${e.device}`.trim()}var sn={disabled:`switched off — not a dispatch target`,unavailable:`the node probe does not see it (unplugged or still provisioning)`,"cannot-host-camera-root":`its engine format has no object-detection root model`,"accelerator-preferred":`CPU fallback — it never competes while an accelerator is serving`};function cn(e,t){return t<=0?0:Math.round(e/t*1e3)/10}function ln(e,t){let n=e.filter(e=>e.exclusion===null).reduce((e,t)=>e+(t.weight>0?t.weight:1),0);return e.map(e=>{let r=t.get(e.key),i=r?.sessions??0,a=e.weight>0?e.weight:1;return{key:e.key,label:on(e),format:e.format,sessions:i,queueDepth:r?.queueDepth??0,weight:a,weightSharePct:e.exclusion===null?cn(a,n):null,maxSessions:e.maxSessions,atCap:e.maxSessions!==null&&i>=e.maxSessions,available:e.available,enabled:e.enabled,exclusion:e.exclusion}}).toSorted((e,t)=>e.exclusion===null==(t.exclusion===null)?e.key.localeCompare(t.key):e.exclusion===null?-1:1)}function un(e){let t=new Map(e.loads.map(e=>[e.nodeId,e])),n=e.nodes.filter(e=>e.isOnline&&e.detectEnabled).reduce((e,t)=>e+(t.weight>0?t.weight:1),0),r=e.loads.reduce((e,t)=>e+t.load.attachedCameras,0);return e.nodes.map(i=>{let a=t.get(i.id),o=ln(e.devicesByNode[i.id]??[],new Map((a?.load.devices??[]).map(e=>[e.deviceKey,{sessions:e.attachedCameras,queueDepth:e.queueDepthTotal}]))),s=i.isOnline&&i.detectEnabled,c=i.weight>0?i.weight:1,l=a?.load.attachedCameras??null;return{nodeId:i.id,name:i.name,isOnline:i.isOnline,detectEnabled:i.detectEnabled,reported:a!==void 0,attachedCameras:l,activeCameras:a?.load.activeCameras??null,maxCameras:i.maxCameras,capacityPct:l!==null&&i.maxCameras!==null&&i.maxCameras>0?cn(l,i.maxCameras):null,queueDepthTotal:a?.load.queueDepthTotal??null,avgInferenceTimeMs:a?.load.avgInferenceTimeMs??null,score:a?.score??null,weight:c,weightSharePct:s?cn(c,n):null,cameraSharePct:l===null?null:cn(l,r),decodeHwaccel:a?.decodeHwaccel??null,devices:o,eligibleDeviceCount:o.filter(e=>e.exclusion===null).length}})}var dn=`pipeline-orchestrator`,fn=`recorder`,pn=`recordingNodeId`,mn=`pipeline-analytics`,hn=`postProcessingNodeId`,gn=[`ingestNode`,`recordingNode`,`audioNode`,`motionNode`,`postProcessingNode`],_n=[{key:`detect`,label:`Detect`,hint:`Runs the detection pipeline (decode + inference) for assigned cameras`}];function vn(e,t){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t)return e.value}function yn(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function K(e,t,n){let r=vn(e,t);return typeof r==`string`&&r.length>0?r:n}function bn(e,t,n){let r=vn(e,t);return typeof r==`number`&&Number.isFinite(r)?r:n}function q(e,t){let n=yn(e,t);return typeof n==`number`&&Number.isFinite(n)?n:null}function xn(e,t){let n=yn(e,t);return typeof n==`string`&&n.length>0?n:null}function Sn(e){return e===`ingestNode`?`Ingest`:e===`recordingNode`?`Recording`:e===`audioNode`?`Audio`:e===`postProcessingNode`?`Post-processing`:`Motion Node`}function Cn(e){return e===`ingestNode`?`Node that terminates default camera ingest`:e===`recordingNode`?`Node that owns the recorder (recording-node)`:e===`audioNode`?`Node that runs singleton audio work`:e===`postProcessingNode`?`Runs detection post-processing (events, media, audio & motion)`:`Runs software (analyzer) motion-watch. Onboard cameras are unaffected.`}function wn(e,t){switch(t){case`detect`:return e.pipeline}}function Tn(e){return e instanceof Error?e.message:`Failed to save`}function En(e){e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAgentSettings`]]}),e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}t();var Dn=2e4,On=3e5;function kn(){let{nodes:e}=z(),t=f().trpcClient,r=Oe(void 0,{placeholderData:c,staleTime:Dn,refetchInterval:Dn,refetchOnWindowFocus:!0}),a=be(void 0,{staleTime:On}),s=i(()=>e.map(e=>e.id),[e]),l=o({queries:s.map(e=>({queryKey:et(pe.pipelineOrchestrator.getNodeInferenceDevices,{nodeId:e},`query`),queryFn:()=>t.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:e}),staleTime:On,refetchOnWindowFocus:!1,placeholderData:c}))}),d=i(()=>{let e={};return s.forEach((t,n)=>{let r=l[n]?.data;r&&(e[t]=r.devices)}),e},[s,l.map(e=>e.dataUpdatedAt).join(`|`)]),p=i(()=>{let e=new Map;for(let t of a.data??[])e.set(t.nodeId,t.settings);return e},[a.data]),m=i(()=>e.map(e=>{let t=p.get(e.id);return{id:e.id,name:e.name,isOnline:e.isOnline,detectEnabled:vt(t,e.isHub).pipeline,weight:q(t,`detectWeight`)??1,maxCameras:q(t,`maxCameras`)}}),[e,p]),h=r.data??[],g=i(()=>un({nodes:m,loads:h,devicesByNode:d}),[m,h,d]),_=g.reduce((e,t)=>e+(t.attachedCameras??0),0),v=g.reduce((e,t)=>e+(t.activeCameras??0),0),y=r.dataUpdatedAt>0?Date.now()-r.dataUpdatedAt:null;return n(`section`,{className:`rounded-md border border-border bg-surface px-3 py-2.5`,children:[n(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1 mb-2`,children:[u(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Node load`}),n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[v,` running · `,_,` attached across `,g.length,` `,g.length===1?`node`:`nodes`]}),u(`span`,{className:`ml-auto text-[10px] text-foreground-subtle/70 tabular-nums`,children:r.data===void 0?`reading…`:`reading ${y===null?`—`:`${Math.round(y/1e3)}s`} old · every ${Dn/1e3}s`})]}),g.length===0?u(`p`,{className:`text-[11px] italic text-foreground-subtle`,children:`No cluster nodes reported yet.`}):u(`div`,{className:`grid gap-2 @2xl/clustertab:grid-cols-2 @5xl/clustertab:grid-cols-3`,children:g.map(e=>u(An,{row:e},e.nodeId))})]})}function An({row:e}){let t=e.attachedCameras===null?`—`:`${e.activeCameras??0} / ${e.attachedCameras}${e.maxCameras===null?``:` of ${e.maxCameras}`}`;return n(`div`,{className:`rounded-lg border border-border bg-surface/60 p-2.5 min-w-0`,children:[n(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[u(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${e.isOnline?`bg-emerald-400`:`bg-foreground-subtle/40`}`}),u(`span`,{className:`truncate text-xs font-medium text-foreground`,title:e.nodeId,children:e.name}),!e.detectEnabled&&u(`span`,{className:`shrink-0 rounded bg-surface-hover px-1 text-[9px] uppercase tracking-wide text-foreground-subtle`,children:`no detect`}),!e.reported&&e.isOnline&&n(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-amber-400`,title:`Online, but it did not answer the last load read — its numbers below are unknown, not zero.`,children:[u(A,{className:`h-2.5 w-2.5`}),` no reading`]}),!e.isOnline&&n(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-foreground-subtle`,children:[u(T,{className:`h-2.5 w-2.5`}),` offline`]})]}),n(`dl`,{className:`mt-1.5 grid grid-cols-2 gap-x-2 gap-y-0.5 text-[10px]`,children:[u(J,{label:`Running / attached`,value:t,title:`Sessions in inference now / cameras attached to this runner (the balancer's committed load) / operator cap.`}),u(J,{label:`Target share`,value:e.weightSharePct===null?`out of play`:`${e.weightSharePct}%`,title:`detectWeight normalised over the nodes the balancer actually ranks (online AND detect-enabled).`}),u(J,{label:`Actual share`,value:e.cameraSharePct===null?`—`:`${e.cameraSharePct}%`,title:`Share of the cluster's attached cameras this node carries right now.`}),u(J,{label:`Score · queue`,value:e.score===null?`—`:`${e.score} · ${e.queueDepthTotal??0}`,title:`The capacity score balance() minimises (attached + queue depth), and the raw queue depth.`}),e.capacityPct!==null&&u(J,{label:`Cap fill`,value:`${e.capacityPct}%`,title:`attached / maxCameras.`}),e.avgInferenceTimeMs!==null&&u(J,{label:`Avg infer`,value:`${Math.round(e.avgInferenceTimeMs)} ms`,title:`Mean inference time across this node's attached cameras.`}),e.decodeHwaccel!==null&&u(J,{label:`Decode`,value:e.decodeHwaccel,title:`This node's probed decode hwaccel.`})]}),u(jn,{row:e})]})}function jn({row:e}){return e.devices.length===0?u(`p`,{className:`mt-2 text-[10px] italic text-foreground-subtle`,children:`Accelerators not read yet.`}):n(`div`,{className:`mt-2 border-t border-border pt-1.5`,children:[n(`div`,{className:`flex items-center gap-1 text-[9px] uppercase tracking-wider text-foreground-subtle`,children:[u(ae,{className:`h-2.5 w-2.5`}),`Accelerators`,e.eligibleDeviceCount===0&&u(`span`,{className:`ml-1 normal-case tracking-normal text-amber-400`,title:`No device is a camera-root candidate on this node — sessions run on the runner's default (CPU) pool.`,children:`none in play · runner default pool`})]}),u(`ul`,{className:`mt-1 space-y-0.5`,children:e.devices.map(e=>u(Mn,{device:e},e.key))})]})}function Mn({device:e}){let t=e.exclusion;return n(`li`,{className:`flex items-baseline gap-1.5 text-[10px] min-w-0`,children:[u(B,{className:`h-2.5 w-2.5 shrink-0 ${t===null?`text-foreground-subtle`:`text-foreground-subtle/50`}`}),u(`span`,{className:`shrink-0 font-medium ${t===null?`text-foreground`:`text-foreground-subtle`}`,title:`${e.key} · ${e.format}`,children:e.label}),t===null?n(a,{children:[n(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,children:[e.weightSharePct,`% share`]}),n(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,children:[`· `,e.sessions,` session`,e.sessions===1?``:`s`,e.maxSessions===null?``:`/${e.maxSessions}`]}),e.queueDepth>0&&n(`span`,{className:`shrink-0 tabular-nums text-amber-400`,children:[`· q`,e.queueDepth]}),e.atCap&&u(`span`,{className:`shrink-0 text-amber-400`,title:`At its maxSessions cap — the balancer skips it until a session ends.`,children:`· at cap`})]}):n(`span`,{className:`truncate text-foreground-subtle/80`,title:sn[t],children:[`excluded — `,sn[t]]})]})}function J({label:e,value:t,title:r}){return n(`div`,{className:`min-w-0`,title:r,children:[u(`dt`,{className:`text-[9px] uppercase tracking-wide text-foreground-subtle`,children:e}),u(`dd`,{className:`truncate font-medium tabular-nums text-foreground`,children:t})]})}function Nn(){return n(`div`,{className:`space-y-6`,children:[u(qt,{title:`Cluster cameras`}),u(kn,{}),n(`div`,{className:`min-w-0`,children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Placement matrix`}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Pipeline · audio assignments per camera (decode always runs co-located with the pipeline). Use the Auto | Pin control to pin a camera to a node, the inference-device select to pin it to an accelerator, or the kebab to move a role; expand the chevron for the per-camera broker drill-down. Cluster load, inference-device weights, and Rebalance live on the Balancer tab.`})]}),u(kt,{mode:`cluster`})]})}function Pn({capability:e,label:t,hint:r,nodeId:i,active:a,pending:o,layout:s,onToggle:c}){let l=a?`border-success/30 bg-success/15 text-success hover:bg-success/25`:`border-border bg-surface-hover text-foreground-subtle hover:bg-surface hover:text-foreground`,d=s===`card`?`w-full justify-center px-3 py-2 text-xs`:`px-2.5 py-1 text-[11px]`,f=a?H:w;return n(`button`,{type:`button`,role:`switch`,"aria-checked":a,"aria-label":`${t} capability for ${i}`,title:`${t} — ${r}`,disabled:o,onClick:()=>c(e,!a),className:`inline-flex items-center gap-1.5 rounded-full border font-medium transition-colors disabled:opacity-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 ${l} ${d}`,children:[u(f,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":`true`}),u(`span`,{children:t})]})}function Fn({node:e,emphasis:t=!1}){let r=e.isHub?fe:B;return n(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[u(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),u(r,{className:`h-4 w-4 shrink-0 text-foreground-subtle`,"aria-hidden":`true`}),n(`div`,{className:`min-w-0`,children:[n(`div`,{className:`flex items-center gap-1.5 ${t?`text-sm`:`text-xs`} font-semibold text-foreground`,children:[u(`span`,{className:`truncate`,children:e.name}),e.isHub&&u(O,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`hub`}),!e.isOnline&&u(O,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`offline`})]}),u(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:e.id})]})]})}t();function In({nodeId:e,value:t,detectedHosts:r,status:i,errorMessage:a,onCommit:o}){let[s,c]=l(t??``);d(()=>{c(t??``)},[t]);let f=r[0],p=f===void 0?`auto-detect`:`auto: ${f}`,m=i===`pending`,h=s.trim(),g=h!==(t??``),_=g&&!m,v=()=>{_&&o(e,h.length>0?h:null)};return n(`div`,{className:`flex items-center gap-1.5`,children:[u(`input`,{"aria-label":`Reachable host for ${e}`,type:`text`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:p,value:s,disabled:m,onChange:e=>c(e.target.value),onBlur:v,onKeyDown:e=>{e.key===`Enter`&&v(),e.key===`Escape`&&c(t??``)},className:`w-40 rounded-md border border-border bg-background px-2.5 py-1.5 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none disabled:opacity-50`}),n(`button`,{type:`button`,onClick:v,disabled:!_,"aria-label":`Save reachable host for ${e}`,title:`Save reachable host`,className:`inline-flex shrink-0 items-center gap-1 rounded-md px-2 py-1.5 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-40 disabled:cursor-not-allowed`,children:[m?u(M,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):u(H,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),!g&&!m&&i===`success`&&u(H,{className:`h-3.5 w-3.5 shrink-0 text-emerald-400`,"aria-label":`Saved`,role:`img`}),i===`error`&&u(`span`,{title:a??`Failed to save reachable host`,children:u(ve,{className:`h-3.5 w-3.5 shrink-0 text-red-400`,"aria-label":a??`Failed to save reachable host`,role:`img`})})]})}t();var Ln=1024,Rn=65536;function zn(e,t,n){let r=e.trim();if(r.length===0)return{value:null,error:null};let i=Number(r);return Number.isInteger(i)?i<t?{value:null,error:`at least ${t}`}:i>n?{value:null,error:`at most ${n}`}:{value:i,error:null}:{value:null,error:`whole number`}}function Bn({nodeId:e,decodeBudgetMb:t,maxLiveDecodeWorkers:r,status:i,errorMessage:a,onCommit:o}){let[s,c]=l(t===null?``:String(t)),[f,p]=l(r===null?``:String(r));d(()=>{c(t===null?``:String(t))},[t]),d(()=>{p(r===null?``:String(r))},[r]);let m=zn(s,Ln,Rn),h=zn(f,1,32),g=i===`pending`,_=m.value!==t||h.value!==r,v=m.error!==null||h.error!==null,y=_&&!v&&!g,b=()=>{y&&o(e,{decodeBudgetMb:m.value,maxLiveDecodeWorkers:h.value})},x=`w-24 rounded-md border border-border bg-background px-2.5 py-1.5 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none disabled:opacity-50`;return n(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[u(`input`,{"aria-label":`Decode budget MB for ${e}`,type:`number`,inputMode:`numeric`,min:Ln,max:Rn,placeholder:`auto`,value:s,disabled:g,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b()},className:x}),u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`MB`}),u(`input`,{"aria-label":`Max decode workers for ${e}`,type:`number`,inputMode:`numeric`,min:1,max:32,placeholder:`auto`,value:f,disabled:g,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b()},className:x}),u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`workers`}),n(`button`,{type:`button`,onClick:b,disabled:!y,"aria-label":`Save decode limits for ${e}`,title:`Save decode limits`,className:`inline-flex shrink-0 items-center gap-1 rounded-md px-2 py-1.5 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-40 disabled:cursor-not-allowed`,children:[g?u(M,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):u(H,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),m.error===null?null:n(`span`,{className:`text-[11px] text-red-400`,children:[`budget: `,m.error]}),h.error===null?null:n(`span`,{className:`text-[11px] text-red-400`,children:[`workers: `,h.error]}),!_&&!g&&i===`success`&&u(H,{className:`h-3.5 w-3.5 shrink-0 text-emerald-400`,"aria-label":`Saved`,role:`img`}),i===`error`&&u(`span`,{title:a??`Failed to save decode limits`,children:u(ve,{className:`h-3.5 w-3.5 shrink-0 text-red-400`,"aria-label":`Save failed`,role:`img`})})]})}function Vn({label:e,children:t}){return n(`div`,{className:`flex items-center justify-between gap-3`,children:[u(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-foreground-subtle`,children:e}),t]})}function Hn({node:e,actions:t}){return n(`div`,{className:`rounded-xl border border-border bg-background p-4 space-y-4 ${e.isOnline?``:`opacity-60`}`,children:[u(Fn,{node:e,emphasis:!0}),u(`div`,{className:`grid grid-cols-2 gap-2`,children:_n.map(n=>u(Pn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:wn(e.effective,n.key),pending:t.capabilityPending,layout:`card`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)},n.key))}),n(`div`,{className:`space-y-3 border-t border-border pt-3`,children:[u(Vn,{label:`Reachable host`,children:u(In,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})}),u(Vn,{label:`Decode limits`,children:u(Bn,{nodeId:e.id,decodeBudgetMb:e.decodeBudgetMb,maxLiveDecodeWorkers:e.maxLiveDecodeWorkers,status:t.decodeLimitsStatus(e.id),errorMessage:t.decodeLimitsErrorMessage(e.id),onCommit:t.onCommitDecodeLimits})})]})]})}function Un(){return n(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[10px] text-foreground-subtle`,children:[n(`span`,{className:`inline-flex items-center gap-1.5`,children:[u(`span`,{className:`h-2.5 w-2.5 rounded-full border border-success/30 bg-success/15`}),`Active capability`]}),n(`span`,{className:`inline-flex items-center gap-1.5`,children:[u(`span`,{className:`h-2.5 w-2.5 rounded-full border border-border bg-surface-hover`}),`Idle`]}),n(`span`,{className:`inline-flex items-center gap-1.5`,children:[u(`span`,{className:`h-2 w-2 rounded-full bg-success`}),`Node online`]}),n(`span`,{className:`inline-flex items-center gap-1.5`,children:[u(`span`,{className:`h-2 w-2 rounded-full bg-danger`}),`Node offline`]})]})}function Wn({nodes:e,actions:t}){return u(`div`,{className:`overflow-x-auto rounded-lg border border-border`,children:n(`table`,{className:`w-full min-w-[720px] border-collapse text-sm`,children:[u(`thead`,{children:n(`tr`,{className:`border-b border-border bg-background text-[10px] uppercase tracking-wider text-foreground-subtle`,children:[u(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Node`}),_n.map(e=>u(`th`,{className:`px-3 py-3 text-center font-semibold`,children:e.label},e.key)),u(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Reachable host`}),u(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Decode limits`})]})}),u(`tbody`,{children:e.map(e=>n(`tr`,{className:`border-b border-border last:border-b-0 transition-colors hover:bg-surface-hover/40 ${e.isOnline?``:`opacity-60`}`,children:[u(`td`,{className:`px-4 py-3 align-middle`,children:u(Fn,{node:e})}),_n.map(n=>u(`td`,{className:`px-3 py-3 text-center align-middle`,children:u(Pn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:wn(e.effective,n.key),pending:t.capabilityPending,layout:`cell`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)})},n.key)),u(`td`,{className:`px-4 py-3 align-middle`,children:u(In,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})}),u(`td`,{className:`px-4 py-3 align-middle`,children:u(Bn,{nodeId:e.id,decodeBudgetMb:e.decodeBudgetMb,maxLiveDecodeWorkers:e.maxLiveDecodeWorkers,status:t.decodeLimitsStatus(e.id),errorMessage:t.decodeLimitsErrorMessage(e.id),onCommit:t.onCommitDecodeLimits})})]},e.id))})]})})}function Gn({role:e,value:t,options:r,pending:i,onChange:a}){return n(`label`,{className:`flex flex-col gap-1.5 rounded-lg border border-border bg-background p-3`,children:[u(`span`,{className:`text-xs font-semibold text-foreground`,children:Sn(e)}),u(`select`,{value:t,disabled:i,onChange:t=>a(e,t.target.value),className:`rounded-md border border-border bg-surface px-2.5 py-1.5 text-sm text-foreground focus:border-primary focus:outline-none disabled:opacity-50`,children:r.map(e=>u(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),u(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:Cn(e)})]})}function Kn({roleValues:e,options:t,pending:r,lowFpsEnabled:i,fpsMinThreshold:a,onRoleChange:o,onLowFpsToggle:s}){return n(`div`,{className:`grid gap-3 @lg/clustertab:grid-cols-2 @3xl/clustertab:grid-cols-3`,children:[gn.map(n=>u(Gn,{role:n,value:e[n],options:t,pending:r,onChange:o},n)),n(`label`,{className:`flex items-start gap-2.5 rounded-lg border border-border bg-background p-3 text-sm text-foreground`,children:[u(`input`,{type:`checkbox`,checked:i,disabled:r,onChange:e=>s(e.target.checked),className:`mt-0.5 h-4 w-4 shrink-0 accent-primary`}),n(`span`,{className:`flex flex-col gap-0.5`,children:[u(`span`,{className:`text-xs font-semibold`,children:`Low-fps relocate/shed`}),n(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:[`fpsMinThreshold `,i?`${a} fps`:`disabled`]})]})]})]})}t();function qn(){let e=s(),{nodes:t}=z(),r=be(void 0),o=R({addonId:dn}),c=R({addonId:fn}),d=R({addonId:mn}),f=()=>En(e),p=re({onSuccess:f}),m=Be(),h=E({onSuccess:f}),g=C({onSuccess:f}),_=y({onSuccess:f}),[v,b]=l(!1),x=i(()=>{let e=new Map;for(let t of r.data??[])e.set(t.nodeId,t.settings);return e},[r.data]),S=i(()=>t.map(e=>{let t=x.get(e.id),n=vt(t,e.isHub),r=q(t,`detectWeight`);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n,weight:r??1,maxCameras:q(t,`maxCameras`),reachableHost:xn(t,`reachableHost`),detectedHosts:e.localIps,decodeBudgetMb:q(t,`decodeBudgetMb`),maxLiveDecodeWorkers:q(t,`maxLiveDecodeWorkers`)}}),[t,x]),w=S.filter(e=>e.effective.pipeline),T={ingestNode:K(o.data,`ingestNode`,`hub`),recordingNode:K(c.data,pn,`hub`),audioNode:K(o.data,`audioNode`,`hub`),motionNode:K(o.data,`motionNode`,`hub`),postProcessingNode:K(d.data,hn,`hub`)},D=i(()=>{let e=t.filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,...gn.map(e=>T[e]),...e])].filter(e=>e.length>0)},[t,T]),O=bn(o.data,`fpsMinThreshold`,0),k=O>0,A=r.isLoading||o.isLoading||c.isLoading||d.isLoading,j=(e,t,n)=>{p.mutate({agentNodeId:e,[t]:n})},N=(e,t)=>{if(e===`recordingNode`){_.mutate({addonId:fn,patch:{[pn]:t}});return}if(e===`postProcessingNode`){_.mutate({addonId:mn,patch:{[hn]:t}});return}_.mutate({addonId:dn,patch:{[e]:t}})},ee=e=>{_.mutate({addonId:dn,patch:{fpsMinThreshold:e?Math.max(1,O):0}})},P=e=>h.variables?.agentNodeId===e?h.isPending?`pending`:h.isError?`error`:h.isSuccess?`success`:`idle`:`idle`,F=e=>P(e)===`error`?Tn(h.error):null,I=e=>g.variables?.agentNodeId===e?g.isPending?`pending`:g.isError?`error`:g.isSuccess?`success`:`idle`:`idle`,te=e=>I(e)===`error`?Tn(g.error):null,L=async e=>{b(!0);try{for(let t of e)await m.mutateAsync({agentNodeId:t.nodeId,detectWeight:t.weight})}finally{b(!1),f()}},ne={capabilityPending:p.isPending,onToggleCapability:j,onCommitReachableHost:(e,t)=>h.mutate({agentNodeId:e,reachableHost:t}),reachableHostStatus:P,reachableHostErrorMessage:F,onCommitDecodeLimits:(e,t)=>g.mutate({agentNodeId:e,...t}),decodeLimitsStatus:I,decodeLimitsErrorMessage:te};return n(`section`,{className:`rounded-xl border border-border bg-surface p-5 @3xl/clustertab:p-6 space-y-6`,children:[n(`header`,{className:`flex items-start justify-between gap-4`,children:[n(`div`,{className:`space-y-1`,children:[u(`h3`,{className:`text-base font-semibold text-foreground`,children:`Pipeline placement`}),u(`p`,{className:`max-w-prose text-xs leading-relaxed text-foreground-subtle`,children:`Toggle which node runs each pipeline capability, distribute detection weight across detect-capable nodes, and choose the singleton cluster roles.`})]}),A&&u(M,{className:`h-5 w-5 shrink-0 animate-spin text-foreground-subtle`,"aria-label":`Loading`})]}),n(`div`,{className:`space-y-3`,children:[u(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Singleton cluster roles`}),u(Kn,{roleValues:T,options:D,pending:_.isPending,lowFpsEnabled:k,fpsMinThreshold:O,onRoleChange:N,onLowFpsToggle:ee})]}),n(`div`,{className:`space-y-3`,children:[u(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Events folder`}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Where event crops / full frames are stored. A single folder — no collection / equal-splitting.`}),u(ft,{types:[`eventMedia`]})]}),n(`div`,{className:`space-y-3`,children:[n(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[u(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Per-node capabilities`}),u(Un,{})]}),S.length===0?u(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No cluster nodes reporting yet.`}):n(a,{children:[u(`div`,{className:`grid gap-4 @xl/clustertab:grid-cols-2 @3xl/clustertab:hidden`,children:S.map(e=>u(Hn,{node:e,actions:ne},e.id))}),u(`div`,{className:`hidden @3xl/clustertab:block`,children:u(Wn,{nodes:S,actions:ne})})]})]}),n(`div`,{className:`space-y-3`,children:[u(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection weight`}),u(Xe,{nodes:w,pending:v,onCommitWeights:e=>void L(e)})]}),n(`div`,{className:`space-y-3`,children:[u(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices`}),w.length===0?u(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No detect-capable nodes — enable detection on a node above to configure its accelerators.`}):u(`div`,{className:`space-y-2`,children:w.map(e=>u(Ze,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline},e.id))})]})]})}t(),t(),t(),t();function Jn(e){if(e===void 0||e.length===0)return[];let t=new Set,n=[];for(let r of e)for(let e of r.capabilities){let i=`${e}\0${r.addonId}`;t.has(i)||(t.add(i),n.push({name:e,addonId:r.addonId}))}return n.toSorted((e,t)=>e.name.localeCompare(t.name))}function Yn(e){let t=e.services;return{pid:e.pid,name:e.name,addonId:t?.[0]?.addonId??``,cpu:e.cpuPercent,mem:e.memoryRss,state:e.state,caps:Jn(t)}}function Xn(e){return{nodeId:e.id,isHub:e.isHub,isOnline:e.isOnline,lastSeen:e.lastSeen,identity:{name:e.name,ip:e.localIps?.[0]??``,cpu:e.cpuPercent,mem:e.memoryPercent,platform:e.platform,arch:e.arch},runners:e.processes.map(Yn)}}function Zn(e){let t=e.toSorted((e,t)=>{let n=+!!e.isHub;return+!!t.isHub-n}).map(Xn),n=t.find(e=>e.isHub);return n===void 0?{nodes:t,edges:[]}:{nodes:t,edges:t.filter(e=>!e.isHub).map(e=>({id:`hub:${n.nodeId}->${e.nodeId}`,source:n.nodeId,target:e.nodeId,online:e.isOnline&&n.isOnline}))}}t();var Qn=!1;function $n({refreshToken:e}){let t=s(),{nodes:r}=ye();i(()=>Zn(r??[]),[r]);let a=Re({onSuccess:()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})}});return n(`div`,{className:`space-y-6`,children:[u(Ct,{refreshToken:e}),u(qn,{}),Qn,n(`div`,{className:`flex flex-col gap-3 @md/clustertab:flex-row @md/clustertab:items-center @md/clustertab:justify-between`,children:[n(`div`,{className:`min-w-0`,children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Rebalance`}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Recompute the optimal node for every assigned camera from current load + hardware affinity, and migrate the ones no longer on their best node. Pinned cameras never move.`})]}),n(`button`,{type:`button`,onClick:()=>a.mutate(void 0),disabled:a.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-white hover:bg-primary/90 disabled:opacity-50 shrink-0 self-start @md/clustertab:self-auto whitespace-nowrap`,children:[u(Ve,{className:`h-3.5 w-3.5`}),a.isPending?`Rebalancing…`:`Rebalance pipelines`]})]})]})}var er=[`pipeline-orchestrator`],tr=`pipeline-analytics`,nr=`face-gallery`;function rr({refreshToken:e}){return n(`div`,{className:`space-y-4 max-w-3xl`,children:[u(dt,{nodeId:`hub`,addonIds:er,level:`global`,omitSectionIds:[`cluster`],title:`Cluster settings`,description:`Cluster-wide orchestration knobs: load balancer, failover, enrichment models, and the admission settings those models share. Ingest / Audio / Motion / Recording / Post-processing node pickers live on the Balancer tab. Per-camera pipelines live in Device Overrides.`}),u(dt,{nodeId:`hub`,addonIds:[tr],level:`global`,capability:nr,title:`Face recognition`,description:`Match threshold, ambiguity margin, and auto-assign floors. Same settings as System → Settings → pipeline-analytics — this page asks the face-gallery cap, it does not store a second copy.`})]})}t();function ir({refreshToken:e}){let t=s(),r=P(),{data:i,isLoading:o}=ue(),[c,d]=l(null),[f,p]=l(``),[m,h]=l(``),_=()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listTemplates`]]})},v=k({onSuccess:()=>{d(null),_()}}),y=Ie({onSuccess:_}),b=e=>{d(e.id),p(e.name),h(e.description??``)},x=()=>{d(null),p(``),h(``)},S=()=>{if(!c)return;let e=m.trim();v.mutate({id:c,name:f.trim()||`Untitled`,...e?{description:e}:{}})};if(o)return u(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading templates…`});let C=[...i??[]].toSorted((e,t)=>e.name.localeCompare(t.name));return u(`div`,{className:`space-y-6 max-w-4xl`,children:n(`section`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[n(`div`,{className:`border-b border-border px-4 py-3 flex items-center justify-between`,children:[n(`div`,{children:[u(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Templates`}),u(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:`Curated pipeline presets operators can apply to any camera. Apply-time is a copy — future edits to a template don't retroactively change cameras that were seeded from it. Save a template from the device Pipeline tab.`})]}),n(`div`,{className:`text-[11px] text-foreground-subtle`,children:[C.length,` template`,C.length===1?``:`s`]})]}),C.length===0?n(`div`,{className:`px-4 py-8 text-xs text-foreground-subtle flex flex-col items-center gap-2`,children:[u(Ke,{className:`h-6 w-6 opacity-40`}),u(`div`,{children:`No templates yet. Create one from a device Pipeline tab ("Save as template").`})]}):u(`ul`,{className:`divide-y divide-border`,children:C.map(e=>{let t=c===e.id;return u(`li`,{className:`px-4 py-3 text-xs`,children:n(`div`,{className:`flex items-start gap-3`,children:[u(`div`,{className:`flex-1 min-w-0`,children:t?n(`div`,{className:`space-y-2`,children:[u(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-xs text-foreground focus:outline-none focus:border-primary`,value:f,onChange:e=>p(e.target.value),placeholder:`Template name`,autoFocus:!0}),u(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-[11px] text-foreground focus:outline-none focus:border-primary`,value:m,onChange:e=>h(e.target.value),placeholder:`Description (optional)`})]}):n(a,{children:[u(`div`,{className:`font-medium text-foreground`,children:e.name}),e.description&&u(`div`,{className:`text-foreground-subtle mt-0.5`,children:e.description}),n(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:[e.config.steps.length,` step(s)`,e.config.audio?.enabled?` · audio`:``,n(`span`,{className:`ml-2`,children:[`updated `,new Date(e.updatedAt).toLocaleString()]})]})]})}),u(`div`,{className:`flex items-center gap-1 shrink-0`,children:t?n(a,{children:[n(`button`,{type:`button`,onClick:S,disabled:v.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-50`,children:[u(H,{className:`h-3 w-3`}),`Save`]}),n(`button`,{type:`button`,onClick:x,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover`,children:[u(ne,{className:`h-3 w-3`}),`Cancel`]})]}):n(a,{children:[u(`button`,{type:`button`,onClick:()=>b(e),title:`Rename`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,children:u(We,{className:`h-3 w-3`})}),u(`button`,{type:`button`,onClick:()=>{(async()=>{await r({title:`Delete template`,message:`Delete the cluster pipeline template "${e.name}"? Cameras already using it keep their current pipeline.`,confirmLabel:`Delete`,variant:`danger`})&&y.mutate({id:e.id})})()},disabled:y.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-red-400 hover:bg-surface-hover disabled:opacity-50`,children:u(g,{className:`h-3 w-3`})})]})})]})},e.id)})})]})})}var ar=`pipeline-orchestrator`,or=200;function sr(){return n(`div`,{className:`flex flex-col gap-3`,children:[n(`div`,{children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Orchestrator logs`}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Dispatch decisions, balancer moves and failover events from the pipeline orchestrator. Streaming live; the device chip on a line tells which camera it refers to.`})]}),u(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:u(xe,{addonId:ar,limit:or,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}t();var cr=[{id:`assignments`,label:`Assignments`},{id:`balancer`,label:`Balancer`},{id:`settings`,label:`Settings`},{id:`templates`,label:`Templates`},{id:`logs`,label:`Logs`}];function lr({refreshToken:e}){let[t,r]=l(`assignments`);return n(`div`,{className:`flex flex-col h-full`,children:[n(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[u(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),u(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Per-camera assignments, the load balancer (live load + inference-device weights), cluster-wide settings, and the pipeline template library.`})]}),u(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:cr.map(e=>u(`button`,{type:`button`,onClick:()=>r(e.id),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${t===e.id?`border-primary text-primary`:`border-transparent text-foreground-subtle hover:text-foreground`}`,children:e.label},e.id))}),n(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[t===`assignments`&&u(Nn,{}),t===`balancer`&&u($n,{refreshToken:e}),t===`settings`&&u(rr,{refreshToken:e}),t===`templates`&&u(ir,{refreshToken:e}),t===`logs`&&u(sr,{})]})]})}var ur=`armed:`;function dr(e){return e.assignment.reasons.detection?.startsWith(ur)===!0}function fr(e){let{assignment:t,detection:n}=e;return n!==null&&n.provisioning.state===`failed`||t.detectionNodeId===null&&n===null&&!dr(e)?`error`:n!==null&&n.phase===`active`?`healthy`:`idle`}function pr(e){let t=[],n=[],{assignment:r,detection:i,decoder:a,broker:o}=e;i!==null&&i.provisioning.state===`failed`&&t.push({code:`provisioning-failed`,severity:`error`,message:i.provisioning.error!==void 0&&i.provisioning.error.length>0?`Engine provisioning failed: ${i.provisioning.error}`:`Engine provisioning failed on the detection node`}),i!==null&&i.phase===`active`&&i.actualFps===0&&t.push({code:`detection-black-hole`,severity:`error`,message:`Detection phase is ACTIVE but 0 fps are being processed — frames are not reaching the detector (cross-node black-hole signature)`}),i!==null&&i.phase===`active`&&a!==null&&a.shm.framesWritten===0&&t.push({code:`decoder-black-hole`,severity:`error`,message:`Decoder on ${a.nodeId} has written 0 frames to the shared-memory plane while detection is active — the decode path is stalled`}),r.detectionNodeId===null&&i===null&&!dr(e)&&n.push({code:`unassigned`,severity:`warning`,message:`Not placed on any detection node — no pipeline is running for this camera`});let s=e.degraded??[];if(s.length>0){let e=[...new Set(s.map(e=>e.stage))].join(`, `);n.push({code:`status-unreadable`,severity:`warning`,message:`Could not read ${e} for this camera — those blocks are unknown, not empty (a switch read that failed does NOT mean nothing is switched off)`})}n.push(...gr(e.cameraSensors));for(let e of o?.profiles??[])e.status===`streaming`&&e.inFps===0&&n.push({code:`broker-stalled`,severity:`warning`,message:`Broker profile "${e.profile}" reports streaming but 0 in-fps — the source pull may be stalled`});return[...t,...n]}function mr(e){return e.state===`unreadable`&&at.state===`unreadable`&&e.reason===at.reason}function hr(e){switch(e.state){case`ready`:return null;case`missing`:return{code:`camera-sensor-missing`,severity:`warning`,message:`Camera sensor ${e.addonId}/${e.stableId} is missing`};case`offline`:return{code:`camera-sensor-offline`,severity:`warning`,message:`Camera sensor ${e.name} (#${e.deviceId}) is ${e.reason}`};case`unsupported`:return{code:`camera-sensor-unsupported`,severity:`warning`,message:`Camera sensor ${e.name} (#${e.deviceId}) cannot drive motion: ${e.reason}`};case`unreadable`:return{code:`camera-sensor-unreadable`,severity:`warning`,message:`Camera sensor ${e.addonId}/${e.stableId} is unreadable: ${e.reason}`}}}function gr(e){if(e===void 0||e.state===`not-configured`)return[];if(e.state===`unreadable`)return mr(e)?[]:[{code:`camera-sensors-unreadable`,severity:`warning`,message:`Camera sensors unreadable: ${e.reason}`}];let t=e.sensors.flatMap(e=>{let t=hr(e);return t===null?[]:[t]}),n=e.notForwarded===void 0?t:[_r(e.notForwarded),...t];return e.notEnforced===void 0?n:[{code:`camera-sensors-not-enforced`,severity:`warning`,message:`Confirm / Replace cannot suppress this camera's own motion until its provider is updated`},...n]}function _r(e){return{code:`camera-sensors-not-forwarded`,severity:`warning`,message:e===`onboard-not-listed`?`Camera sensors are attached but never fire: add "Camera sensors" (onboard) to this camera's motion sources`:`Camera sensors are attached but never fire: this camera has no active detection`}}function vr(e){return e===void 0?`status unavailable from this node`:e.state===`not-configured`?`none attached`:e.state===`unreadable`?`unknown — ${e.reason}`:e.sensors.map(br).join(`, `)}function yr(e){return e.mode===`in-addition`?``:` · ${e.mode}`}function br(e){return`${xr(e)}${yr(e)}`}function xr(e){switch(e.state){case`ready`:return`${e.name} (#${e.deviceId})`;case`offline`:return`${e.name} (#${e.deviceId}) — ${e.reason}`;case`unsupported`:return`${e.name} (#${e.deviceId}) — unsupported`;case`missing`:case`unreadable`:return`${e.addonId}/${e.stableId} — ${e.state}`}}function Sr(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Y(e){return typeof e==`string`&&e.length>0?e:null}function Cr(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function wr(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function Tr(e,t){return e==null?!1:JSON.stringify(e)!==JSON.stringify(t??null)}var Er={detectionMode:null,detectionStreamProfile:null,detectionFps:null,motionSources:[],motionFps:null,motionCooldownMs:null,motionStreamProfile:null,audioMode:null,pipelineNodeId:null,decoderNodeId:null,audioNodeId:null,overriddenKeys:new Set};function Dr(e){if(!Sr(e)||!Array.isArray(e.sections))return Er;let t=tt(e),n=e=>{let n=t.get(e);if(n!==void 0)return n.value??n.default},r=new Set;for(let[e,n]of t)Tr(n.value,n.default)&&r.add(e);return{detectionMode:Y(n(`detectionMode`)),detectionStreamProfile:Y(n(`detectionStreamProfile`)),detectionFps:Cr(n(`detectionFps`)),motionSources:wr(n(`motionSources`)),motionFps:Cr(n(`motionFps`)),motionCooldownMs:Cr(n(`motionCooldownMs`)),motionStreamProfile:Y(n(`motionStreamProfile`)),audioMode:Y(n(`audioMode`)),pipelineNodeId:Y(n(`pipelineNodeId`)),decoderNodeId:Y(n(`decoderNodeId`)),audioNodeId:Y(n(`audioNodeId`)),overriddenKeys:r}}function Or(e,t=0){let n=[];for(let r of e)n.push({addonId:r.addonId,modelId:r.modelId??null,enabled:r.enabled,depth:t}),r.children!==void 0&&r.children.length>0&&n.push(...Or(r.children,t+1));return n}function X({title:e,children:t}){return n(`div`,{className:`bg-background px-3.5 py-3 min-w-0`,children:[u(`div`,{className:`text-[9px] font-semibold uppercase tracking-[0.14em] text-foreground-subtle mb-2`,children:e}),u(`div`,{className:`flex flex-col gap-1 min-w-0`,children:t})]})}function Z({label:e,children:t,overridden:r=!1}){return n(`div`,{className:`flex items-baseline gap-2 text-[11px] leading-snug min-w-0`,children:[u(`span`,{className:`text-foreground-subtle shrink-0 w-24 truncate`,title:e,children:e}),u(`span`,{className:`font-mono tabular-nums text-foreground min-w-0 truncate flex-1`,children:t}),r&&u(kr,{})]})}function kr(){return u(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0 self-center`,title:`Device-level override active`,"aria-label":`Device-level override active`,role:`img`})}var Ar={neutral:`border-border text-foreground-muted`,success:`border-success/40 text-success`,warning:`border-warning/40 text-warning`,danger:`border-danger/40 text-danger`,info:`border-info/40 text-info`};function Q({tone:e=`neutral`,children:t,title:n}){return u(`span`,{title:n,className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-medium leading-tight whitespace-nowrap ${Ar[e]}`,children:t})}function $({children:e}){return u(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function jr({icon:e,label:t,nodeId:r,pinned:i,reason:o,overridden:s}){return n(`div`,{className:`flex items-center gap-2 text-[11px] leading-snug min-w-0`,children:[u(e,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),u(`span`,{className:`text-foreground-subtle w-[4.5rem] shrink-0`,children:t}),r===null?u(`span`,{className:`text-foreground-subtle italic`,children:`unassigned`}):n(a,{children:[u(`span`,{className:`font-mono text-foreground truncate`,title:r,children:r}),i?n(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] text-warning shrink-0`,title:`Manually pinned`,children:[u(pt,{className:`h-2.5 w-2.5`}),` manual`]}):n(`span`,{className:`text-[10px] text-foreground-subtle shrink-0 truncate`,children:[`auto · `,o!==void 0&&o.length>0?o:`capacity`]}),s&&u(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0`,title:`Persisted settings pin for this role`})]})]})}function Mr({assignment:e,settings:t,onlineNodes:r,pinPending:i,onDetectionPinChange:a}){let o=e.pinned.detection&&e.detectionNodeId!==null?e.detectionNodeId:`auto`,s=[...new Set([...e.detectionNodeId===null?[]:[e.detectionNodeId],...r.map(e=>e.id)])];return n(X,{title:`Where it runs`,children:[u(jr,{icon:B,label:`Detection`,nodeId:e.detectionNodeId,pinned:e.pinned.detection,reason:e.reasons.detection,overridden:t.overriddenKeys.has(`pipelineNodeId`)}),u(jr,{icon:Me,label:`Decoder`,nodeId:e.decoderNodeId,pinned:e.pinned.decoder,reason:e.reasons.decoder,overridden:t.overriddenKeys.has(`decoderNodeId`)}),u(jr,{icon:_,label:`Audio`,nodeId:e.audioNodeId,pinned:e.pinned.audio,reason:e.reasons.audio,overridden:t.overriddenKeys.has(`audioNodeId`)}),u(jr,{icon:Ee,label:`Source`,nodeId:e.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),u(`div`,{className:`mt-1.5`,children:n(`select`,{value:o,disabled:i,"aria-label":`Detection placement pin`,onChange:e=>a(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-[11px] text-foreground disabled:opacity-50`,children:[u(`option`,{value:`auto`,children:`Auto (load balanced)`}),s.map(e=>n(`option`,{value:e,children:[`Pin detection → `,r.find(t=>t.id===e)?.name??e]},e))]})})]})}function Nr(e){return`${e.width}×${e.height} ${e.codec} @${e.fps}fps`}function Pr(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function Fr(e){return e===null?`default`:e===0?`native (no throttle)`:`${e} fps`}function Ir({streams:e,brokerProfiles:t,settings:r,motionEnabled:i,motionFpsLive:o,cameraSensors:s}){let c=Pr(t,r.detectionStreamProfile),l=Pr(t,r.motionStreamProfile),d=r.motionSources.includes(`analyzer`);return n(X,{title:`Streams & motion`,children:[n(Z,{label:`Detect stream`,overridden:r.overriddenKeys.has(`detectionStreamProfile`),children:[r.detectionStreamProfile??`—`,c!==void 0&&` · ${c.width}×${c.height} ${c.codec}`]}),u(Z,{label:`Detect FPS`,overridden:r.overriddenKeys.has(`detectionFps`),children:Fr(r.detectionFps)}),n(Z,{label:`Motion src`,overridden:r.overriddenKeys.has(`motionSources`),children:[r.motionSources.length>0?r.motionSources.map(st).join(` + `):`none`,i===!1&&` · inactive`]}),u(Z,{label:`Camera sensors`,children:vr(s)}),d&&n(a,{children:[n(Z,{label:`Motion stream`,overridden:r.overriddenKeys.has(`motionStreamProfile`),children:[r.motionStreamProfile??`—`,l!==void 0&&` · ${l.width}×${l.height} ${l.codec}`]}),n(Z,{label:`Motion FPS`,overridden:r.overriddenKeys.has(`motionFps`),children:[Fr(r.motionFps),o!==null&&` · live ${o.toFixed(1)}`]})]}),u(Z,{label:`Cooldown`,overridden:r.overriddenKeys.has(`motionCooldownMs`),children:r.motionCooldownMs===null?`default`:`${r.motionCooldownMs/1e3}s`}),u(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:e.length===0?u($,{children:`No streams registered`}):e.map(e=>n(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,title:e.camStreamId,children:[u(`span`,{className:`text-foreground-muted`,children:e.kind}),` `,Nr(e)]},e.camStreamId))})]})}function Lr({steps:e,audioModelId:t,audioEnabled:r,audioMode:i}){return n(X,{title:`Pipeline steps`,children:[e===void 0?u($,{children:`Resolving…`}):e.length===0?u($,{children:`No steps configured`}):u(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>u(Q,{tone:e.enabled&&e.depth===0?`info`:`neutral`,title:e.modelId??e.addonId,children:n(`span`,{className:e.enabled?``:`line-through opacity-60`,children:[e.depth>0&&u(`span`,{className:`opacity-50`,children:`↳ `}),e.addonId,e.modelId!==null&&n(`span`,{className:`font-mono opacity-75`,children:[` · `,e.modelId]})]})},`${e.addonId}-${t}`))}),u(`div`,{className:`mt-1`,children:n(Z,{label:`Audio class.`,children:[i??`—`,r!==null&&(r?` · running`:` · off`),t!==null&&` · ${t}`]})})]})}var Rr={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function zr({detection:e,live:t,detectionMode:r,modeOverridden:i}){if(e===null)return n(X,{title:`Detection runtime`,children:[u(Z,{label:`Mode`,overridden:i,children:r??`—`}),u($,{children:`Detection stage inactive or unreachable`})]});let a=t?.phase??e.phase,o=t?.actualFps??e.actualFps,s=t?.configuredFps??e.configuredFps,c=t?.avgInferenceTimeMs??e.avgInferenceMs,l=t?.queueDepth??e.queueDepth,d=Ue(a),f=a===`active`&&o===0;return n(X,{title:`Detection runtime`,children:[n(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:[n(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-semibold uppercase tracking-wider ${d.badgeClass}`,children:[u(N,{phase:a,className:`h-2.5 w-2.5`}),d.label]}),t!==void 0&&u(`span`,{className:`text-[9px] text-foreground-subtle uppercase tracking-wider`,children:`live`})]}),u(Z,{label:`Mode`,overridden:i,children:r??`—`}),n(Z,{label:`FPS`,children:[u(`span`,{className:f?`text-danger font-semibold`:``,children:o.toFixed(1)}),n(`span`,{className:`text-foreground-subtle`,children:[` / `,s.toFixed(0),` configured`]})]}),n(Z,{label:`Inference`,children:[c.toFixed(0),` ms`,l>0&&n(`span`,{className:`text-warning`,children:[` · queue `,l]}),t!==void 0&&t.droppedFrames>0&&n(`span`,{className:`text-warning`,children:[` · drops `,t.droppedFrames]})]}),n(Z,{label:`Engine`,children:[e.engine.backend,` · `,e.engine.device]}),n(Z,{label:`Provisioning`,children:[u(Q,{tone:Rr[e.provisioning.state]??`neutral`,children:e.provisioning.state}),e.provisioning.error!==void 0&&n(`span`,{className:`text-danger text-[10px]`,children:[` `,e.provisioning.error]})]})]})}function Br({broker:e}){return e===null?u(X,{title:`Stream broker`,children:u($,{children:`Broker stage inactive or unreachable`})}):n(X,{title:`Stream broker`,children:[e.profiles.length===0?u($,{children:`No broker profiles`}):u(`div`,{className:`flex flex-col gap-1`,children:e.profiles.map(e=>{let t=e.status===`streaming`,r=t&&e.inFps===0;return n(`div`,{className:`flex items-center gap-2 text-[11px] font-mono tabular-nums min-w-0`,children:[u(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full shrink-0 ${r?`bg-danger`:t?`bg-success animate-pulse`:`bg-border`}`,title:e.status}),u(`span`,{className:`text-foreground w-10 shrink-0 truncate`,title:e.profile,children:e.profile}),n(`span`,{className:`text-foreground-subtle truncate`,children:[e.width,`×`,e.height,` `,e.codec]}),n(`span`,{className:`ml-auto shrink-0 ${r?`text-danger`:`text-foreground`}`,children:[e.inFps.toFixed(0),`→`,e.outFps.toFixed(0),`fps`]}),n(`span`,{className:`text-foreground-subtle shrink-0`,title:`Subscribers`,children:[`×`,e.subscribers]})]},e.profile)})}),n(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[n(Q,{tone:e.webrtcSessions>0?`info`:`neutral`,children:[`WebRTC `,e.webrtcSessions]}),n(Q,{tone:e.rtspRestream?`success`:`neutral`,children:[`restream `,e.rtspRestream?`on`:`off`]})]})]})}function Vr({decoder:e,detectionActive:t}){if(e===null)return u(X,{title:`Decoder`,children:u($,{children:`Decoder stage inactive or unreachable`})});let r=t&&e.shm.framesWritten===0;return n(X,{title:`Decoder`,children:[u(Z,{label:`Node`,children:e.nodeId}),u(Z,{label:`Sessions`,children:e.sessionCount}),n(Z,{label:`SHM frames`,children:[u(`span`,{className:r?`text-danger font-semibold`:``,children:e.shm.framesWritten}),u(`span`,{className:`text-foreground-subtle`,children:` written`})]}),n(Z,{label:`SHM reads`,children:[e.shm.getFrameHits,` hits`,e.shm.getFrameMisses>0&&n(`span`,{className:`text-warning`,children:[` · `,e.shm.getFrameMisses,` misses`]})]}),n(Z,{label:`SHM budget`,children:[e.shm.budgetMb,` MB`]}),e.formats.length>0&&u(Z,{label:`Formats`,children:e.formats.join(`, `)})]})}t();var Hr=`pipeline-orchestrator`,Ur={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},Wr={healthy:`Healthy`,idle:`Idle`,error:`Error`};function Gr({problems:e}){return u(`div`,{role:`alert`,className:`flex flex-col border-b border-border`,children:e.map(e=>n(`div`,{className:`flex items-start gap-2 px-4 py-1.5 text-[11px] font-medium ${e.severity===`error`?`bg-danger/10 text-danger`:`bg-warning/10 text-warning`}`,children:[u(A,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),u(`span`,{className:`min-w-0`,children:e.message})]},e.code))})}function Kr({deviceId:e,name:t,online:r,status:a,live:o,onlineNodes:c}){let l=s(),{data:d}=se({addonId:Hr,deviceId:e,nodeId:`hub`},{staleTime:3e4}),{data:f}=He({deviceId:e},{staleTime:3e4}),p=i(()=>Dr(d),[d]),m=i(()=>f===void 0?void 0:Or(f.steps),[f]),h=i(()=>a===void 0?[]:pr(a),[a]),g=()=>{l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},_=_e({onSuccess:g}),v=D({onSuccess:g}),y=t=>{t===`auto`?v.mutate({deviceId:e}):_.mutate({deviceId:e,agentNodeId:t})},b=a===void 0?`idle`:fr(a),x=h.some(e=>e.severity===`error`),S=h.length>0,C=x?`border-danger/50`:S?`border-warning/40`:`border-border`;return n(`article`,{"aria-label":`${t} pipeline status`,className:`rounded-lg border ${C} bg-background overflow-hidden`,children:[n(`header`,{className:`flex items-center gap-2.5 px-4 py-2.5 border-b border-border bg-surface/50 min-w-0`,children:[u(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${x?`bg-danger`:Ur[b]}`,title:x?`Error`:Wr[b],"aria-label":x?`Error`:Wr[b],role:`img`}),u(`h3`,{className:`text-[13px] font-semibold text-foreground truncate`,title:t,children:t}),n(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`#`,e]}),!r&&u(Q,{tone:`danger`,children:`offline`}),n(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[p.detectionMode!==null&&u(Q,{tone:p.detectionMode===`disabled`?`warning`:p.detectionMode===`always-on`?`info`:`neutral`,title:`Object detection mode`,children:p.detectionMode===`disabled`?`detection off`:p.detectionMode}),a?.recording!=null&&(a.recording.active?n(Q,{tone:`danger`,title:`Recording (${a.recording.mode})`,children:[u(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-danger animate-pulse`}),`REC`]}):a.recording.mode!==`off`&&n(Q,{tone:`neutral`,title:`Recording mode`,children:[`rec `,a.recording.mode]}))]})]}),h.length>0&&u(Gr,{problems:h}),a===void 0?u(`div`,{className:`px-4 py-5 text-[11px] text-foreground-subtle italic`,children:`No pipeline status yet — the orchestrator has not composed a snapshot for this camera.`}):n(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-px bg-border`,children:[u(Mr,{assignment:a.assignment,settings:p,onlineNodes:c,pinPending:_.isPending||v.isPending,onDetectionPinChange:y}),u(zr,{detection:a.detection,live:o,detectionMode:p.detectionMode,modeOverridden:p.overriddenKeys.has(`detectionMode`)}),u(Lr,{steps:m,audioModelId:f?.audio?.modelId??null,audioEnabled:a.audio?.enabled??f?.audio?.enabled??null,audioMode:p.audioMode}),u(Ir,{streams:a.source.streams,brokerProfiles:a.broker?.profiles,settings:p,motionEnabled:a.motion?.enabled??null,motionFpsLive:a.motion?.fps??null,cameraSensors:a.cameraSensors}),u(Br,{broker:a.broker}),u(Vr,{decoder:a.decoder,detectionActive:a.detection?.phase===`active`})]})]})}t();var qr=5e3,Jr=1e4,Yr=5e3;function Xr(e){let t=s(),{data:n,isLoading:r}=lt(),{data:a,isLoading:o}=Fe({},{refetchInterval:qr}),{nodes:c}=z();d(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[u,f]=l(new Map);Ge(nt.PipelineCameraMetricsSnapshot,e=>{let t=e.data;typeof t.deviceId==`number`&&f(e=>{let n=new Map(e);return n.set(t.deviceId,{phase:t.metrics.phase,configuredFps:t.metrics.configuredFps,actualFps:t.metrics.actualFps,queueDepth:t.metrics.queueDepth,avgInferenceTimeMs:t.metrics.avgInferenceTimeMs,droppedFrames:t.metrics.droppedFrames,timestamp:t.timestamp}),n})}),d(()=>{if(u.size===0)return;let e=setInterval(()=>{f(e=>{let t=Date.now()-Jr,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},Yr);return()=>clearInterval(e)},[u.size]);let p=i(()=>{let e=new Map;for(let t of a??[])e.set(t.deviceId,t);return e},[a]);return{rows:i(()=>(n??[]).filter(e=>e.isCamera).map(e=>({deviceId:e.id,name:e.name,online:e.online,status:p.get(e.id)})).sort((e,t)=>e.name.localeCompare(t.name)),[n,p]),liveMetrics:u,onlineNodes:i(()=>(c??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[c]),isLoading:r||o}}t();function Zr({refreshToken:e}){let{rows:t,liveMetrics:r,onlineNodes:a,isLoading:o}=Xr(e),s=i(()=>[...t.map(e=>{let t=e.status===void 0?[]:pr(e.status);return{row:e,errorCount:t.filter(e=>e.severity===`error`).length,warningCount:t.filter(e=>e.severity===`warning`).length}})].sort((e,t)=>e.errorCount===t.errorCount?e.warningCount===t.warningCount?0:t.warningCount-e.warningCount:t.errorCount-e.errorCount),[t]),c=i(()=>{let e=0,t=0;for(let n of s)(n.errorCount>0||n.warningCount>0)&&(t+=1),(r.get(n.row.deviceId)?.phase??n.row.status?.detection?.phase)===`active`&&(e+=1);return{total:s.length,active:e,issues:t}},[s,r]);return o&&t.length===0?u(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Loading camera pipelines…`}):t.length===0?u(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`No cameras found`}):u(`div`,{className:`h-full overflow-y-auto`,children:n(`div`,{className:`max-w-6xl mx-auto flex flex-col gap-3 px-4 py-4`,children:[n(`div`,{className:`flex items-center gap-4 text-[11px] text-foreground-subtle px-1`,children:[n(`span`,{children:[u(`span`,{className:`font-semibold text-foreground`,children:c.total}),` cameras`]}),n(`span`,{children:[u(`span`,{className:`font-semibold text-success`,children:c.active}),` actively inferring`]}),n(`span`,{children:[u(`span`,{className:`font-semibold ${c.issues>0?`text-danger`:`text-foreground`}`,children:c.issues}),` `,`with issues`]}),u(`span`,{className:`ml-auto hidden sm:inline text-[10px]`,children:`polled every 5 s · detection metrics live at 1 Hz`})]}),s.map(({row:e})=>u(Kr,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:r.get(e.deviceId),onlineNodes:a},e.deviceId))]})})}t();var Qr=`__cluster__`;function $r(e){return e===`cameras`?`cameras`:`nodes`}function ei(){let[e,t]=ut(),r=$r(e.get(`view`)),i=e.get(`node`)??`__cluster__`,[o,s]=l(0),[c,f]=l(!1);return d(()=>{r===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:Qr},{replace:!0})},[r,e,t]),n(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[n(`div`,{className:`flex items-center justify-between gap-4 px-4 py-3 border-b border-border shrink-0`,children:[n(`div`,{className:`flex items-center gap-1 rounded-lg border border-border p-0.5 bg-surface`,children:[u(`button`,{type:`button`,onClick:()=>{t({view:`nodes`,node:i},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,r===`nodes`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Nodes`}),u(`button`,{type:`button`,onClick:()=>{t({view:`cameras`},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,r===`cameras`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Cameras`})]}),u(`div`,{className:`flex items-center gap-2`,children:n(`button`,{type:`button`,onClick:()=>s(e=>e+1),title:`Refresh`,className:`inline-flex items-center gap-1.5 rounded-lg 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:[u(je,{className:`h-3.5 w-3.5`}),`Refresh`]})})]}),r===`nodes`&&n(`button`,{type:`button`,onClick:()=>f(e=>!e),"aria-expanded":c,className:`md:hidden flex items-center justify-between gap-2 px-4 py-2 border-b border-border shrink-0 text-[11px] font-medium text-foreground-subtle hover:text-foreground transition-colors`,children:[n(`span`,{children:[c?`Hide`:`Show`,` node list`]}),u(m,{className:[`h-4 w-4 transition-transform`,c?`rotate-180`:``].join(` `)})]}),u(`div`,{className:`flex-1 flex flex-col md:flex-row overflow-hidden min-h-0`,children:r===`nodes`?n(a,{children:[u(`aside`,{className:[c?`block`:`hidden`,`md:block w-full md:w-72 shrink-0 border-b md:border-b-0 md:border-r border-border`,`max-h-[60vh] md:max-h-none overflow-y-auto`].join(` `),children:u(bt,{selectedNodeId:i,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),f(!1)},refreshToken:o})}),u(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:i===`__cluster__`?u(lr,{refreshToken:o}):u(an,{nodeId:i,refreshToken:o})})]}):u(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:u(Zr,{refreshToken:o})})})]})}export{ei as PipelinePage};
@@ -1 +0,0 @@
1
- import{vt as e}from"./player-overlays-CEHVDSJu.js";var t=e(`circle-slash`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`9`,x2:`15`,y1:`15`,y2:`9`,key:`1dfufj`}]]);export{t};
@@ -1 +0,0 @@
1
- import"./src-CQ9R75CO.js";