@camstack/addon-admin-ui 1.2.118 → 1.2.119

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 (107) hide show
  1. package/dist/assets/{AddLocationWizard-Bf2d5QJC.js → AddLocationWizard-BcscyeiT.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-BKFXFcwj.js → AddonCollectionPage-B03rWwOK.js} +1 -1
  3. package/dist/assets/{Addons-BE4c7Eft.js → Addons-BDWcu7bj.js} +1 -1
  4. package/dist/assets/{AdminTabs-CW5SZp7Y.js → AdminTabs-BhVFfu-V.js} +1 -1
  5. package/dist/assets/{AiProfiles-DtrI9DHP.js → AiProfiles-CmIRcCjv.js} +1 -1
  6. package/dist/assets/{BrokerForm-BGjBv1to.js → BrokerForm-CGbxdxp0.js} +1 -1
  7. package/dist/assets/{Build-mA9Ywcki.js → Build-Bneqa83Z.js} +1 -1
  8. package/dist/assets/{Capabilities-DVGShQpV.js → Capabilities-Bd7XskC7.js} +1 -1
  9. package/dist/assets/{CapabilityBadges-B_jIPQNS.js → CapabilityBadges-KMhMCn1k.js} +1 -1
  10. package/dist/assets/{Cluster-CZGyMZZq.js → Cluster-CS-NJ6OS.js} +1 -1
  11. package/dist/assets/{Data-DuyRytLu.js → Data-Dr3p27zg.js} +1 -1
  12. package/dist/assets/{DetectionIntelligence-tpYFIJC0.js → DetectionIntelligence-BziKZgjR.js} +1 -1
  13. package/dist/assets/{DeviceAggregateSection-BhDnF-0R.js → DeviceAggregateSection-CheBdbsr.js} +1 -1
  14. package/dist/assets/DeviceDetail-Br1qPJ6r.js +2 -0
  15. package/dist/assets/{Devices-19N1vFVC.js → Devices-BV1t7-g5.js} +1 -1
  16. package/dist/assets/{EmbedPlayerPage-uNDQHMOY.js → EmbedPlayerPage-n4oktMWk.js} +1 -1
  17. package/dist/assets/Events-CkGijCDG.js +1 -0
  18. package/dist/assets/{FormBuilder-Bw_BfLct.js → FormBuilder-D7eVmgZJ.js} +1 -1
  19. package/dist/assets/{Identity-ChUC1Yzb.js → Identity-Cb2GAD5w.js} +1 -1
  20. package/dist/assets/{IntegrationDetail-uhUiJaKD.js → IntegrationDetail-B4uov2Kt.js} +1 -1
  21. package/dist/assets/{Integrations-CDpK4Iya.js → Integrations-SNPkOFhA.js} +1 -1
  22. package/dist/assets/Integrations-_7bjpG_5.js +1 -0
  23. package/dist/assets/{Logs-QkSAbBaP.js → Logs-pNO26-_g.js} +1 -1
  24. package/dist/assets/{MotionZonesSettings-DEJj0tIr.js → MotionZonesSettings-DikN9JEQ.js} +1 -1
  25. package/dist/assets/{MyAccess-Dq5B9DXE.js → MyAccess-BnULhZgR.js} +1 -1
  26. package/dist/assets/{Network-CdFVF0Bh.js → Network-Bv3jrJ1-.js} +1 -1
  27. package/dist/assets/{NodeAddonsSettingsPanel-BpV4vZ3y.js → NodeAddonsSettingsPanel-DvTRBvQl.js} +1 -1
  28. package/dist/assets/{NodeInferenceDevices-fUGmh21X.js → NodeInferenceDevices-BaRmgURr.js} +1 -1
  29. package/dist/assets/{Notifications-BXPxGe8Q.js → Notifications-DXzfB7Iv.js} +1 -1
  30. package/dist/assets/{Pipeline-Dul0Xxvp.js → Pipeline-DCSX_1o6.js} +1 -1
  31. package/dist/assets/Plates-BEU4sAqP.js +1 -0
  32. package/dist/assets/PrivacyMaskSettings-CZLQzQgv.js +1 -0
  33. package/dist/assets/{ProviderIcon-BXczeeUa.js → ProviderIcon-aFjOxP4_.js} +1 -1
  34. package/dist/assets/{Recordings-BqpIOzrs.js → Recordings-b6zC1cWE.js} +1 -1
  35. package/dist/assets/{ScanNetworkModal-D3jJwqnQ.js → ScanNetworkModal-DFZ9sM0F.js} +1 -1
  36. package/dist/assets/SceneMonitorEditor-BN655weg.js +1 -0
  37. package/dist/assets/{Scenes-DC0f71cu.js → Scenes-C0y2uk0j.js} +1 -1
  38. package/dist/assets/{Settings-BpKwlBs0.js → Settings-DpIKYRlm.js} +1 -1
  39. package/dist/assets/{Showroom-DqOzeQMg.js → Showroom-CWbwspFj.js} +1 -1
  40. package/dist/assets/{Terminal-BDB9l80Z.js → Terminal-ykBOga6k.js} +1 -1
  41. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-B3MkFUBK.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BYhH6kE0.js} +1 -1
  42. package/dist/assets/{bell-ring-DXlqoV-n.js → bell-ring-CXoCKJnn.js} +1 -1
  43. package/dist/assets/{boxes-D5TGZrSv.js → boxes-Bw4b1Wc1.js} +1 -1
  44. package/dist/assets/circle-check-big-D_Kt6W2W.js +1 -0
  45. package/dist/assets/{circle-x-zj-Y8V0g.js → circle-x-DDabN2KD.js} +1 -1
  46. package/dist/assets/clock-BeIF3nWG.js +1 -0
  47. package/dist/assets/{copy-DVYoqFlk.js → copy-C-EqjmDP.js} +1 -1
  48. package/dist/assets/{debounced-invalidate-DKj6sAUn.js → debounced-invalidate-Bfd2Qzzn.js} +1 -1
  49. package/dist/assets/dist-D-Tiwsk7.js +349 -0
  50. package/dist/assets/{dist-D_qQ3ZLb.js → dist-D_lTK4xz.js} +1 -1
  51. package/dist/assets/{download-BifPfhIt.js → download-Cuj1maBm.js} +1 -1
  52. package/dist/assets/{face-bbox-DaCckiPf.js → face-bbox-y-km4dI8.js} +1 -1
  53. package/dist/assets/{hostInit-C203P4lS.js → hostInit-Cym8Rr5d.js} +1 -1
  54. package/dist/assets/index-BTGQKEEA.js +4 -0
  55. package/dist/assets/{key-round-9MDNzuSJ.js → key-round-DvhPSBSH.js} +1 -1
  56. package/dist/assets/{layers-ZG2sPM2X.js → layers-B7No2bw_.js} +1 -1
  57. package/dist/assets/{mf-entry-bootstrap-0-81aebfb2.js → mf-entry-bootstrap-0-ae9b3119.js} +2 -2
  58. package/dist/assets/{pencil-CZejwlRX.js → pencil-BJxboIbx.js} +1 -1
  59. package/dist/assets/play-CeohfaKf.js +1 -0
  60. package/dist/assets/player-overlays-RwoCa548.js +1 -0
  61. package/dist/assets/plus-Brv4i72u.js +1 -0
  62. package/dist/assets/power-DmJawhTF.js +1 -0
  63. package/dist/assets/{radio-DNUWRE34.js → radio-klp_ubdd.js} +1 -1
  64. package/dist/assets/{refresh-cw-DTXYyRHZ.js → refresh-cw-OR1QZ198.js} +1 -1
  65. package/dist/assets/remoteEntry-CRo49mol.js +1 -0
  66. package/dist/assets/rotate-ccw-Dzp5z5a_.js +1 -0
  67. package/dist/assets/rotate-cw-6dMVo8-E.js +1 -0
  68. package/dist/assets/{send-B7H6pAaP.js → send-vc4Psyt4.js} +1 -1
  69. package/dist/assets/{server-BxzOan8u.js → server-BXgYajYr.js} +1 -1
  70. package/dist/assets/{shield-CEP1YgoU.js → shield-Y4WSkvsK.js} +1 -1
  71. package/dist/assets/square-Dd2LMGtj.js +1 -0
  72. package/dist/assets/{square-check-big-Cx7mXraC.js → square-check-big-hQzwD37R.js} +1 -1
  73. package/dist/assets/src-CDVm70oc.js +67 -0
  74. package/dist/assets/src-ijaeX4aR.js +349 -0
  75. package/dist/assets/{star-Bf7LBoXR.js → star-BM5cPk35.js} +1 -1
  76. package/dist/assets/{undo-2-Cx6lwzFn.js → undo-2-C4NHExfy.js} +1 -1
  77. package/dist/assets/{use-scenes-feed-C2I8IX9W.js → use-scenes-feed-BsYnn_Rq.js} +1 -1
  78. package/dist/assets/useEventInvalidation-D4KUD_Rr.js +1 -0
  79. package/dist/assets/{useNodeUrlSelection-ClAXDXQJ.js → useNodeUrlSelection-DbuPo174.js} +1 -1
  80. package/dist/assets/{video-Bdo0_RSo.js → video-DIbJOXgM.js} +1 -1
  81. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CA7Bimee.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DbvhoXKV.js} +2 -2
  82. package/dist/assets/{wifi-sJIjMU2Y.js → wifi-CMg5tM5x.js} +1 -1
  83. package/dist/assets/{zap-CRMTcuGs.js → zap-Dnw48_IY.js} +1 -1
  84. package/dist/index.html +5 -5
  85. package/dist/server/addon.js +260 -175
  86. package/package.json +1 -1
  87. package/dist/assets/DeviceDetail-B_T4KUCH.js +0 -2
  88. package/dist/assets/Events-CeYY81EE.js +0 -1
  89. package/dist/assets/Integrations-DasmVT6a.js +0 -1
  90. package/dist/assets/Plates-vm8v4CX0.js +0 -1
  91. package/dist/assets/PrivacyMaskSettings-Dyh3C1Gc.js +0 -1
  92. package/dist/assets/SceneMonitorEditor-CMdf9veT.js +0 -1
  93. package/dist/assets/circle-check-big-THS7TOUg.js +0 -1
  94. package/dist/assets/clock-sO6o_mjY.js +0 -1
  95. package/dist/assets/dist-NbQ5dxwG.js +0 -349
  96. package/dist/assets/index-lupFu8MS.js +0 -4
  97. package/dist/assets/play-Dj5XCwJ4.js +0 -1
  98. package/dist/assets/player-overlays-9UuGjKRi.js +0 -1
  99. package/dist/assets/plus-DyGAblLU.js +0 -1
  100. package/dist/assets/power-DoFXllOi.js +0 -1
  101. package/dist/assets/remoteEntry-Bds4bwsC.js +0 -1
  102. package/dist/assets/rotate-ccw-Dp-SmUgt.js +0 -1
  103. package/dist/assets/rotate-cw-CHNi--Cf.js +0 -1
  104. package/dist/assets/square-De580U5i.js +0 -1
  105. package/dist/assets/src-DbUPImmO.js +0 -349
  106. package/dist/assets/src-eNwyjio2.js +0 -67
  107. package/dist/assets/useEventInvalidation-C3I3KCPD.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{K as f,W as p,Z as m,o as h,r as g,t as _,v}from"./player-overlays-9UuGjKRi.js";import{$r as y,$t as b,A as x,B as S,Bt as C,D as w,Di as T,E,Ei as D,Er as O,Fo as k,Fr as A,G as ee,H as te,Ha as ne,Ht as re,J as j,K as M,Ka as N,L as P,La as ie,M as F,Nn as ae,O as I,Oi as L,P as R,Pr as oe,Qi as se,Qr as ce,Qt as le,R as z,Rr as B,To as ue,U as V,Ur as H,Vr as U,Vt as W,W as de,Wr as G,Xr as fe,Yn as pe,Yr as me,Yt as K,Zr as he,_ as ge,_r as _e,_t as ve,a as ye,aa as be,b as q,bi as xe,c as Se,cn as Ce,d as we,dt as Te,ei as Ee,en as De,et as Oe,ft as ke,ht as Ae,i as je,ia as Me,io as Ne,jo as Pe,k as Fe,kr as Ie,l as Le,lt as Re,mt as ze,o as Be,oa as Ve,on as He,ot as Ue,pt as We,q as Ge,qr as Ke,r as qe,ro as Je,s as Ye,sn as Xe,st as Ze,tt as Qe,u as $e,un as et,uo as tt,ut as nt,v as rt,vr as it,y as at,z as ot,za as st,zr as ct,zt as lt}from"./src-eNwyjio2.js";import{Lt as ut,Rt as dt,a as ft,ft as J,i as pt,mt as Y,zt as mt}from"./src-DbUPImmO.js";import{t as ht}from"./CapabilityBadges-B_jIPQNS.js";import{n as gt,t as _t}from"./bell-ring-DXlqoV-n.js";import{t as vt}from"./boxes-D5TGZrSv.js";import{t as yt}from"./ProviderIcon-BXczeeUa.js";import{c as bt,n as xt,s as St,u as Ct}from"./NodeInferenceDevices-fUGmh21X.js";import{t as wt}from"./layers-ZG2sPM2X.js";import{n as Tt}from"./FormBuilder-Bw_BfLct.js";import{t as Et}from"./pencil-CZejwlRX.js";import{t as Dt}from"./power-DoFXllOi.js";import{t as Ot}from"./refresh-cw-DTXYyRHZ.js";import{t as kt}from"./rotate-ccw-Dp-SmUgt.js";import{t as At}from"./rotate-cw-CHNi--Cf.js";import{t as jt}from"./server-BxzOan8u.js";import{t as Mt}from"./wifi-sJIjMU2Y.js";import{C as Nt,G as Pt,J as Ft,K as X,M as It,N as Lt,U as Rt,V as zt,X as Bt,Y as Vt,b as Ht,g as Ut,i as Wt,m as Gt,o as Kt,r as qt,s as Jt,t as Yt,u as Xt,y as Zt,z as Qt}from"./index-lupFu8MS.js";import"./useEventInvalidation-C3I3KCPD.js";import{t as $t}from"./StatusBadge-CeptlsPG.js";import{i as en,n as tn,r as nn,t as rn}from"./DeviceAggregateSection-BhDnF-0R.js";var an=X(`circle-help`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),on=X(`disc`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}]]),sn=X(`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`}]]),cn=X(`hand`,[[`path`,{d:`M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2`,key:`1fvzgz`}],[`path`,{d:`M14 10V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2`,key:`1kc0my`}],[`path`,{d:`M10 10.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8`,key:`10h0bg`}],[`path`,{d:`M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15`,key:`1s1gnw`}]]),ln=X(`link-2`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`,key:`8i5ue5`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`,key:`1b9ql8`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`,key:`1jonct`}]]),un=X(`mouse-pointer-click`,[[`path`,{d:`M14 4.1 12 6`,key:`ita8i4`}],[`path`,{d:`m5.1 8-2.9-.8`,key:`1go3kf`}],[`path`,{d:`m6 12-1.9 2`,key:`mnht97`}],[`path`,{d:`M7.2 2.2 8 5.1`,key:`1cfko1`}],[`path`,{d:`M9.037 9.69a.498.498 0 0 1 .653-.653l11 4.5a.5.5 0 0 1-.074.949l-4.349 1.041a1 1 0 0 0-.74.739l-1.04 4.35a.5.5 0 0 1-.95.074z`,key:`s0h3yz`}]]),dn=X(`volume-2`,[[`path`,{d:`M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z`,key:`uqj9uw`}],[`path`,{d:`M16 9a5 5 0 0 1 0 6`,key:`1q6k2b`}],[`path`,{d:`M19.364 18.364a9 9 0 0 0 0-12.728`,key:`ijwkga`}]]);n();var fn=[{id:`object-detection`,label:`Object detection`,costWhenOff:`No detections, tracks or detection-driven notifications for this camera.`,capName:dt},{id:`audio-analysis`,label:`Audio analysis`,costWhenOff:`No audio events (glass, alarm, speech) and no audio-driven notifications.`,capName:ut}],pn=`Recording`,mn=`Nothing new is written to disk — live still works, existing footage is kept.`;function hn(e,t){let{bindings:n,bindable:r}=t,i=n===null?void 0:n.find(t=>t.capName===e.capName&&t.kind===`wrapped`),a=r?.find(t=>t.capName===e.capName)?.wrappers[0],o=i!==void 0&&i.providerAddonId!==``?i.providerAddonId:a??null,s=n===null?null:i!==void 0;return{id:e.id,label:e.label,costWhenOff:e.costWhenOff,on:s,available:s!==null&&o!==null,capName:e.capName,wrapperAddonId:o}}function gn(e,t,n,r){let i=e.entries.filter(e=>e.capName!==t);return r?{...e,entries:[...i,{capName:t,kind:`wrapped`,providerAddonId:n}]}:{...e,entries:i}}function _n(e,t){let n=e.filter(e=>e.on===!1).map(e=>e.id),r=e.filter(e=>e.on===null).map(e=>e.id),i=t=>t.map(t=>e.find(e=>e.id===t)?.label??t).join(`, `),a=[];return n.length>0&&a.push(`Off: ${i(n)}`),r.length>0&&a.push(`Unknown: ${i(r)}`),{layout:t?`menu`:`inline`,offIds:n,unknownIds:r,summary:a.length===0?`All camera functions on`:a.join(` · `)}}function vn(e){let t=fn.map(t=>hn(t,e)),n={id:`recording`,label:pn,costWhenOff:mn,on:e.recordingEnabled,available:e.recordingEnabled!==null,capName:null,wrapperAddonId:null};return[...t,n]}var yn={"object-detection":Ut,"audio-analysis":sn,recording:on};function bn(e){if(typeof e!=`object`||!e)return!1;let t={...e};return typeof t.enabled==`boolean`&&Array.isArray(t.bands)}function xn(e){if(typeof e!=`object`||!e)return!1;let t={...e};return typeof t.deviceId==`number`&&Array.isArray(t.entries)}function Sn(e){return xn(e)?e.entries:null}function Cn(e){if(!Array.isArray(e))return null;let t=[];for(let n of e){if(typeof n!=`object`||!n)continue;let e={...n},r=e.capName,i=e.wrappers;typeof r!=`string`||!Array.isArray(i)||t.push({capName:r,wrappers:i.filter(e=>typeof e==`string`)})}return t}function wn({deviceId:t}){let n=s(),i=Number.isFinite(t),[a,o]=c(null),[l,d]=c(!1),f=A({deviceId:t},{enabled:i}),p=H({deviceType:Y.Camera},{enabled:i}),m=Pe({deviceId:t},{enabled:i,retry:!1});je([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let h=[[`deviceManager`,`getBindings`],{input:{deviceId:t}}],g=[[`recording`,`getDeviceConfig`],{input:{deviceId:t}}],_=m.data,v=bn(_)?_:null,y=vn({bindings:Sn(f.data),bindable:Cn(p.data),recordingEnabled:v===null?null:v.enabled}),b=Ee({onError:(e,r)=>{let i=r.capName===y[1]?.capName?`audio-analysis`:`object-detection`;console.error(`[CameraFunctionSwitches] wrapper write failed — reverting`,{tags:{deviceId:t},meta:{capName:r.capName,error:e instanceof Error?e.message:String(e)}}),n.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]}),o({id:i,message:e instanceof Error?e.message:String(e)})},onSuccess:()=>{o(null),n.invalidateQueries({queryKey:[[`deviceManager`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]})}}),x=k({onError:e=>{console.error(`[CameraFunctionSwitches] recording write failed — reverting`,{tags:{deviceId:t},meta:{error:e instanceof Error?e.message:String(e)}}),n.invalidateQueries({queryKey:[[`recording`,`getDeviceConfig`]]}),o({id:`recording`,message:e instanceof Error?e.message:String(e)})},onSuccess:()=>{o(null),n.invalidateQueries({queryKey:[[`recording`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]})}}),S=e(e=>{if(!e.available||e.on===null)return;let r=!e.on;if(e.id===`recording`){if(v===null)return;n.setQueryData(g,{...v,enabled:r}),x.mutate({deviceId:t,config:{...v,enabled:r}});return}let{capName:i,wrapperAddonId:a}=e;if(i===null||a===null)return;let o=n.getQueryData(h);xn(o)&&n.setQueryData(h,gn(o,i,a,r)),b.mutate({deviceId:t,capName:i,wrapperAddonId:a,active:r})},[h,t,n,v,g,x,b]),C=_n(y,ve()),w=e=>a?.id===e.id?a.message:null;return C.layout===`menu`?r(We,{open:l,onOpenChange:d,children:[r(Ae,{"aria-label":`Camera functions`,title:C.summary,className:`inline-flex items-center gap-1 rounded-lg border px-2 py-1.5 text-[11px] font-medium transition-colors ${a===null?C.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(Xt,{className:`h-3.5 w-3.5`}),C.offIds.length>0&&r(`span`,{className:`rounded bg-warning/20 px-1 text-[9px] font-semibold uppercase tracking-wide`,children:[C.offIds.length,` off`]})]}),r(ze,{className:`left-auto right-0 mt-1 min-w-[240px] 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:y.map(e=>u(`li`,{children:u(Tn,{state:e,failure:w(e),onToggle:()=>S(e)})},e.id))})]})]}):u(`div`,{className:`flex items-center gap-1`,children:y.map(e=>u(En,{state:e,failure:w(e),onToggle:()=>S(e)},e.id))})}function Tn({state:e,failure:t,onToggle:n}){let i=yn[e.id],a=e.on===null,o=e.on===!1;return r(`button`,{type:`button`,role:`switch`,"aria-label":e.label,"aria-checked":e.on===!0,disabled:!e.available,onClick:n,title:a?`${e.label} — state unknown; the source that owns it did not answer.`:t===null?e.costWhenOff:`Last write failed: ${t}`,className:`flex w-full items-start gap-2 rounded-md px-2 py-1.5 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 mt-0.5 ${t===null?a?`text-foreground-subtle/50`:o?`text-warning`:`text-success`:`text-danger`}`}),r(`span`,{className:`flex-1 min-w-0`,children:[u(`span`,{className:`block leading-tight`,children:e.label}),u(`span`,{className:`block mt-0.5 text-[10px] text-foreground-subtle leading-tight`,children:t===null?a?`Unknown`:e.costWhenOff:`Write failed: ${t}`})]}),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 En({state:e,failure:t,onToggle:n}){let i=yn[e.id],a=e.on===null,o=e.on===!1,s=a?`${e.label} — state unknown; the source that owns it did not answer.`:o?`${e.label} is OFF. ${e.costWhenOff}`:`${e.label} is on. Turning it off: ${e.costWhenOff}`;return r(`button`,{type:`button`,role:`switch`,"aria-label":e.label,"aria-checked":e.on===!0,disabled:!e.available,onClick:n,title:t===null?s:`${s} — last write failed: ${t}`,className:`inline-flex items-center gap-1 rounded-lg border px-1.5 sm:px-2 py-1.5 text-[11px] font-medium transition-colors disabled:cursor-not-allowed ${t===null?a?`border-dashed border-border text-foreground-subtle/50`:o?`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(i,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden lg:inline`,children:e.label}),o&&u(`span`,{className:`rounded bg-warning/20 px-1 text-[9px] font-semibold uppercase tracking-wide`,children:`off`})]})}function Dn({parentDeviceId:e}){let{t}=Yt(),n=Ft(),i=m(),{data:a,isLoading:o,isError:s}=bt(e),{data:c}=B({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=I(c?.stableId??``,l,c?.childLayout),f=d.ungrouped,p=e=>n(`/devices/${String(e)}`),h=c?.name??``,g=(e,t)=>u(E,{trpc:i.trpcClient,device:{...t,name:x(t,h)},variant:`minimal`,onNavigate:p},e),_=f.some(e=>!!e.role),v=f.some(e=>!e.role),y=_&&!v?t(`device.accessories`,{defaultValue:`Accessories`}):!_&&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=>g(e.id,e))})]}):null,S=d.disabledSection===void 0?null:u(w,{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=>g(e.id,e))})},d.disabledSection.title);return d.sections.length===0?S===null?b:r(`div`,{className:`space-y-2`,children:[b,S]}):r(`div`,{className:`space-y-2`,children:[d.sections.map(e=>u(w,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>g(e.id,e))},e.title)),b,S]})}function On({deviceId:e}){let t=m(),{data:n,isLoading:r}=St(e),{data:i,isLoading:a}=bt(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(z,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}n();function kn({dev:e,busy:t,setBusy:n}){let i=e?.motionTrigger,a=f(e?.state.motionTrigger),[o,s]=c(!1);if(!i)return null;let l=a?.enabled===!0,d=a!==void 0,p=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:()=>{p()},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(Pt,{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=m(),a=te(t)?.HeroCard??V,o=p(i.trpcClient,e),s=f(o?.state.deviceStatus),[l,d]=c(!1),h=s!==void 0&&s.online===!1,g=h?s.lastChangedAt:null;return r(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[h?u(`div`,{className:`flex justify-center`,children:u(S,{lastChangedAt:g})}):null,u(a,{trpc:i.trpcClient,deviceId:e,features:n}),u(`div`,{className:`flex justify-center`,children:u(kn,{dev:o,busy:l,setBusy:d})})]})}function An({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(de,{trpc:m().trpcClient,deviceId:e,features:t})})}function jn({deviceId:e,features:t}){return u(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:u(V,{trpc:m().trpcClient,deviceId:e,features:t})})}function Mn(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}function Nn(e){if(!e)return null;let t=Mn(e.data);return t===null?e.eventType:`Button ${String(t)} · ${e.eventType}`}var Pn=1e3,Fn=60*Pn,In=60*Fn,Ln=24*In;function Rn(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<Pn?`just now`:n<Fn?`${String(Math.floor(n/Pn))}s ago`:n<In?`${String(Math.floor(n/Fn))}m ago`:n<Ln?`${String(Math.floor(n/In))}h ago`:`${String(Math.floor(n/Ln))}d ago`}n();var zn=1500,Bn=15e3,Vn=1e3;function Hn({deviceId:e}){let n=p(m().trpcClient,e)?.state.eventEmitter,i=f(n);d(()=>{if(!n)return;n.refresh();let e=setInterval(()=>{n.refresh()},Bn);return()=>{clearInterval(e)}},[n]);let a=i?.lastEvent??null,o=a?.seq??null,s=t(null),[l,h]=c(!1);d(()=>{if(o===null)return;let e=s.current;if(s.current=o,e===null||e===o)return;h(!0);let t=setTimeout(()=>{h(!1)},zn);return()=>{clearTimeout(t)}},[o]);let[g,_]=c(()=>Date.now());d(()=>{let e=setInterval(()=>{_(Date.now())},Vn);return()=>{clearInterval(e)}},[]);let v=Nn(a),y=i?.eventTypes??[],b=i?.eventCountSinceStart??0,x=i!==void 0,S=Mn(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:v??`No press recorded`,children:u(l?un:cn,{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 ${v?`text-foreground`:`text-foreground-subtle`}`,children:v??(x?`No press recorded`:`Awaiting state…`)}),u(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:a?Rn(a.timestamp,g):`Waiting for the first event`})]}),y.length>0&&u(`div`,{className:`flex max-w-full flex-wrap justify-center gap-1`,children:y.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(b)} ${b===1?`event`:`events`} since start`})]})}function Un({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(yt,{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($t,{status:i?`online`:`offline`}),a.length>0&&u(ht,{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 Wn({deviceId:e}){let t=s(),n=_e({deviceId:e},{refetchInterval:1e4,retry:!1}),a=it({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),o=i(()=>Gn(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(Kn,{label:`Discovered`,value:o.total,icon:u(Zt,{className:`h-3.5 w-3.5`})}),u(Kn,{label:`Adopted`,value:o.adopted,accent:`success`}),u(Kn,{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(Nt,{className:`h-3.5 w-3.5 animate-spin`}):u(Ot,{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(qn,{icon:u(Mt,{className:`h-3 w-3 text-emerald-500`}),label:`${o.online} online`}),u(qn,{icon:u(Ht,{className:`h-3 w-3 text-amber-500`}),label:`${o.sleeping} sleeping`}),u(qn,{icon:u(Wt,{className:`h-3 w-3 text-destructive`}),label:`${o.offline} offline`}),o.unknown>0?u(qn,{icon:u(an,{className:`h-3 w-3 text-foreground-subtle`}),label:`${o.unknown} unknown`}):null]})]})}function Gn(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 Kn({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 qn({icon:e,label:t}){return r(`span`,{className:`inline-flex items-center gap-1`,children:[e,u(`span`,{children:t})]})}var Jn={[Y.Switch]:Z,[Y.Siren]:Z,[Y.Light]:Z,[Y.Sensor]:Z,[Y.Button]:Z,[Y.Hub]:Wn,[Y.Cover]:An,[Y.Valve]:Z,[Y.Humidifier]:Z,[Y.WaterHeater]:Z,[Y.Container]:On,[Y.Lock]:Z,[Y.Fan]:Z,[Y.Thermostat]:Z,[Y.Climate]:Z,[Y.MediaPlayer]:Z,[Y.Control]:Z,[Y.AlarmPanel]:Z,[Y.EventEmitter]:Hn,[Y.Notifier]:jn,[Y.Script]:Z,[Y.Automation]:Z,[Y.Presence]:Z,[Y.Update]:Z,[Y.Vacuum]:Z,[Y.LawnMower]:Z,[Y.Weather]:Z,[Y.Image]:Z,[Y.PetFeeder]:Z};function Yn(e){return Jn[e]??Un}function Xn(e){return u(Yn(e.deviceType),{...e})}function Zn(e){return Ye(m().trpcClient,e)}n();function Qn(n){let[r,i]=c(`idle`),[a,o]=c(null),s=t(null),l=t(null),u=t(null),f=t(!0),p=T(),m=D(),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 $n=0;function Q(){return++$n}function er(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function tr(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 nr(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 rr(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 ir({scope:n,greeting:i,className:a}){let o=m(),[s,f]=c(()=>{let e=[];return i&&e.push({id:Q(),kind:`info`,text:i}),e.push({id:Q(),kind:`info`,text:`scope: ${er(n)} — type help or context for available commands`}),e}),[p,h]=c(``),[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: ${er(n)}`}]),h(``);return}if(t===`help`){f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`},...tr(n).map(e=>({id:Q(),kind:`info`,text:e}))]),h(``);return}if(t===`context`){f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`},...rr(n).map(e=>({id:Q(),kind:`info`,text:e}))]),h(``);return}if(t===`examples`){f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`},...nr(n).map(e=>({id:Q(),kind:`info`,text:e}))]),h(``);return}_(e=>[...e,t]),y(-1),f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`}]),h(``),C.mutate(t)}}function T(e){if(e.key===`Enter`){e.preventDefault(),w(p);return}if(e.key===`ArrowUp`){if(e.preventDefault(),g.length===0)return;let t=v===-1?g.length-1:Math.max(0,v-1);y(t),h(g[t]??``);return}if(e.key===`ArrowDown`){if(e.preventDefault(),v===-1)return;let t=v+1;t>=g.length?(y(-1),h(``)):(y(t),h(g[t]??``));return}e.ctrlKey&&e.key===`l`&&(e.preventDefault(),f([{id:Q(),kind:`info`,text:`scope: ${er(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=>h(e.target.value),onKeyDown:T,disabled:C.isPending,placeholder:`device.state.battery.value`,autoFocus:!0,className:`flex-1 bg-transparent text-zinc-100 placeholder:text-zinc-600 focus:outline-none caret-emerald-400 disabled:opacity-50`,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`})]})]})}function ar({deviceId:e,intercomAvailable:t=!1}){let n=m(),r=typeof window<`u`?window.location.origin:``,i=Number.isFinite(e),a=Zn(i?e:null),{streams:s,pipelineMetrics:c,createSession:l,sendAnswer:d,handleOffer:f,getIceServers:p,addIceCandidate:_,getIceCandidates:v,closeSession:y,getSessionState:b}=Be(n.trpcClient,i?e:null),x=h(i?e:null,{width:ur}),S=Qn(i&&t?e:null),C=S.state===`requesting-mic`||S.state===`starting`||S.state===`connecting`||S.state===`stopping`,w=S.isTalking||C,T=()=>{S.state===`idle`||S.state===`error`?S.start():S.state!==`stopping`&&S.stop()},E=g(),D=De(),O=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,k=E.length>0?u(o,{children:E.map(e=>u(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return u(Le,{serverUrl:r,createSession:l,sendAnswer:d,handleOffer:f,getIceServers:p,addIceCandidate:_,getIceCandidates:v,closeSession:y,getSessionState:b,...D.request?{playbackUrl:D.request.url,playbackAuthToken:O,...D.request.label?{playbackLabel:D.request.label}:{},onExitPlayback:()=>D.clear()}:{},streams:s,pipelineMetrics:c,phase:a.phase,detections:a,defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:x.src,...x.src?{posterUrl:x.src}:{},snapshotLoading:x.loading,onRefreshSnapshot:x.refresh,intercomAvailable:t,intercomShown:w,onIntercomToggle:T,extraOverlay:k,chromeless:!0,className:`h-full`})}function or({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full`,children:u(j,{...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 sr({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(ir,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function cr({deviceId:e}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:u(Ge,{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 lr({deviceId:e}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:u(M,{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 ur=960;function dr({deviceId:e}){let t=s(),n=Number.isFinite(e),{data:i}=B({deviceId:e},{enabled:n}),a=typeof i?.type==`string`?i.type:`camera`;je([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:o,isLoading:c,isError:l,error:d}=A({deviceId:e},{enabled:n}),{data:f}=H({deviceType:a},{enabled:!!a}),p=Ee({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(vt,{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(Qe,{columns:[{key:`capability`,header:`Capability`,render:e=>u(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>u(fr,{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(pr,{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(mr,{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 fr({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(jt,{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(wt,{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(ln,{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(Ct,{className:`h-3 w-3`}),`unbound`]})}function pr({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 mr({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?Qt:kt,{className:`h-3 w-3`}),e]},e)})})}function hr({deviceId:e,activeSubTab:t,onSubTabChange:n}){return u(`div`,{className:`flex flex-col gap-3`,children:u(rn,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}n();var gr=new Set([`package-detection`]);function _r(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 vr(e){return e?e.modelId!==void 0||e.settings!==void 0:!1}function yr({deviceId:e,refreshToken:t}){let n=s(),l=m().trpcClient,[d,f]=c(null),[p,h]=c(null),[g,_]=c(null),v=ie({deviceId:e},{refetchOnMount:`always`}),y=st({deviceId:e},{refetchOnMount:`always`}),b=N(void 0,{refetchOnMount:`always`});je([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let x=Me(void 0,{refetchOnMount:`always`}),S=i(()=>{let e=new Set;for(let t of x.data??[])t.isOnline&&e.add(t.id);return e},[x.data]),w=i(()=>(b.data??[]).filter(e=>S.has(e.nodeId)).map(e=>e.nodeId),[b.data,S]),T=a({enabled:w.length>0,queryKey:[[`pipelineExecutor`,`getSchema`],`device-step-schemas`,w.join(`,`),t],queryFn:async()=>{let e={};for(let t of w)try{e[t]=await l.pipelineExecutor.getSchema.query({nodeId:t})}catch{}return e}}),E=e=>T.data?.[e]??null,D=i(()=>{let e=w[0];if(e!==void 0){let t=T.data?.[e];if(t)return t}return Object.values(T.data??{})[0]??null},[w,T.data]),O=a({enabled:w.length>0,queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`],`device-step`,w.join(`,`),t],queryFn:async()=>{let e={};for(let t of w)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=Je({onSuccess:k}),ee=Ne({onSuccess:k}),te=i(()=>D?$e(D):[],[D]),ne=i(()=>{let e=b.data??[],t=S.size===0?[]:e.filter(e=>S.has(e.nodeId)),n=[];for(let e of t){let t=(O.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:xt(r).label});else n.push({agentNodeId:e.nodeId,engineLabel:t[0]?.format??`(engine unknown)`})}return n},[b.data,O.data,S]),j=(e,t)=>O.data?.[e]?.find(e=>e.key===t)??null,M=e=>{if(e.deviceKey!==void 0)return e.deviceKey;let t=O.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},P=(e,t,n)=>y.data?.[e]?.[t]?.[n]??null,F=e=>{if(gr.has(e))return{kind:`zone-driven`};let t=_r(D,e)?.enabledByDefault??!0,n=v.data?.stepToggles?.[e];return{kind:`gate`,effectiveOn:n??t,defaultOn:t,explicit:n!==void 0}},ae=(e,t,n)=>{let r=_r(E(n),e);if(r)return C(r,t)},I=(e,t)=>{let n=F(e),r=n.kind===`gate`?n.effectiveOn:!1,i=_r(E(t.agentNodeId),e),a=M(t),o=a===null?null:j(t.agentNodeId,a);if(!re(i?.models??[],o?.format))return r?{kind:`skip`}:{kind:`na`};let s=a===null?null:P(t.agentNodeId,a,e),c=o?.steps?.[e];return{kind:`enabled`,modelId:(i?W({catalog:i,device:o,override:s?.modelId,base:c?.modelId}):void 0)??`Auto`,overridden:vr(s)}},L=d===null?null:_r(E(d.agentNodeId),d.addonId),R=d?j(d.agentNodeId,d.deviceKey):null,oe=R?.format??`coreml`,se=d?vr(P(d.agentNodeId,d.deviceKey,d.addonId)):!1,ce=d?ae(d.addonId,R,d.agentNodeId):void 0,le=i(()=>{if(!d||!R)return null;let e=R.steps?.[d.addonId];return{enabled:!0,...e?.modelId===void 0?{}:{modelId:e.modelId},settings:e?.settings??{}}},[d,R]),z=()=>{f(null),h(null)},B=(e,t)=>{let n=M(t);n!==null&&(f({addonId:e,agentNodeId:t.agentNodeId,deviceKey:n}),h(P(t.agentNodeId,n,e)))},ue=(t,n)=>{ee.mutate({deviceId:e,addonId:t,enabled:n})},V=()=>{d&&A.mutate({deviceId:e,agentNodeId:d.agentNodeId,deviceKey:d.deviceKey,addonId:d.addonId,patch:p},{onSuccess:z})},H=()=>{d&&A.mutate({deviceId:e,agentNodeId:d.agentNodeId,deviceKey:d.deviceKey,addonId:d.addonId,patch:null},{onSuccess:z})};if(b.isLoading||w.length>0&&T.isLoading)return u(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(ne.length===0)return u(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`No online agents.`});if(!D)return u(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let U=d!==null&&L!==null&&R!==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:U?`md:pr-[360px]`:``,children:te.length>0?u(q,{tree:te,agents:ne,gateFor:F,getCellState:I,onCellClick:B,selectedCell:d,onSetGate:ue,gateBusy:ee.isPending,fallbackNodeId:g,onFallbackNodeChange:_}):u(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),u(we,{open:U,onClose:z,title:L?.name??``,subtitle:d&&R?`${d.agentNodeId} · ${xt(R).label} · ${R.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:!se||A.isPending,onClick:H,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:z,children:`Cancel`}),u(`button`,{type:`button`,disabled:!d||!le||A.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:V,children:A.isPending?`Saving…`:`Save`})]}),children:L&&d&&le?u(lt,{mode:`device`,addon:L,agentDefault:le,agentNodeId:d.agentNodeId,currentPatch:p,engineFormat:oe,effectiveModelId:ce,onChangePatch:h}):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 br=[{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`}],xr={"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 Sr(e){return xr[e]??`object-detection`}n();var Cr=`steps`,wr=`settings`,Tr=new Set([Cr,wr]);function Er(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}function Dr({deviceId:t,activeSubTab:n,onSubTabChange:i}){return r(Re,{value:n&&Tr.has(n)?n:Cr,onValueChange:e(e=>{i?.(e)},[i]),className:`flex flex-col`,children:[r(Te,{className:`flex-shrink-0`,children:[u(ke,{value:Cr,children:`Steps`}),u(ke,{value:wr,children:`Settings`})]}),u(nt,{value:Cr,children:u(yr,{deviceId:t,refreshToken:0})}),u(nt,{value:wr,children:u(rn,{deviceId:t,sectionFilter:Er,subTabGrouping:{groupOf:e=>Sr(e.id),tabs:br}})})]})}var Or=`overview`;function kr(e,t){return e.some(e=>e.id===t)?t:Or}function $({label:e,value:t}){return r(`div`,{className:`${v} flex items-start gap-2 sm:gap-3`,children:[u(`span`,{className:`w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle`,children:e}),u(`div`,{className:`flex-1 min-w-0 text-[11px] text-foreground`,children:t})]})}n();function Ar({deviceId:e,initialName:n}){let i=s(),[a,o]=c(!1),[l,f]=c(n),[p,m]=c(!1),h=t(null);d(()=>{a||f(n)},[n,a]),d(()=>{a&&h.current?.focus()},[a]);let g=he({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),i.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),_=async()=>{let t=l.trim();if(t.length===0||t===n){o(!1),f(n);return}m(!0);try{await g.mutateAsync({deviceId:e,name:t}),o(!1)}catch{}finally{m(!1)}},v=()=>{f(n),o(!1)};return a?u($,{label:`Name`,value:r(`div`,{className:`flex items-center gap-1`,children:[u(`input`,{ref:h,type:`text`,value:l,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`?_():e.key===`Escape`&&v()},disabled:p,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),u(`button`,{type:`button`,onClick:()=>void _(),disabled:p,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:u(Qt,{className:`h-3 w-3`})}),u(`button`,{type:`button`,onClick:v,disabled:p,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:u(qt,{className:`h-3 w-3`})})]})}):u($,{label:`Name`,value:r(`div`,{className:`flex items-center gap-2 group`,children:[u(`span`,{className:`truncate`,children:n}),u(`button`,{type:`button`,onClick:()=>o(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit name`,children:u(Et,{className:`h-3.5 w-3.5`})})]})})}n();function jr({deviceId:e,initialLocation:n}){let a=s(),[o,l]=c(!1),[f,p]=c(n??``),[m,h]=c(!1),g=t(null),{data:_}=G(void 0,{enabled:o}),v=_??[];d(()=>{o||p(n??``)},[n,o]),d(()=>{o&&g.current?.focus()},[o]);let y=fe({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]})}}),b=i(()=>{let e=f.trim().toLowerCase();return e.length===0?v:v.filter(t=>t.toLowerCase()!==e&&t.toLowerCase().includes(e))},[v,f]),x=f.trim().length>0&&!v.some(e=>e.toLowerCase()===f.trim().toLowerCase()),S=async t=>{let r=(t??f).trim(),i=r.length===0?null:r;if(i===(n??null)){l(!1);return}h(!0);try{await y.mutateAsync({deviceId:e,location:i}),l(!1)}catch{}finally{h(!1)}},C=()=>{p(n??``),l(!1)};return o?u($,{label:`Location`,value:r(`div`,{className:`relative`,children:[r(`div`,{className:`flex items-center gap-1`,children:[u(`input`,{ref:g,type:`text`,value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`?S():e.key===`Escape`&&C()},disabled:m,placeholder:`Room / area (or leave empty to clear)`,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),u(`button`,{type:`button`,onClick:()=>void S(),disabled:m,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:u(Qt,{className:`h-3 w-3`})}),u(`button`,{type:`button`,onClick:C,disabled:m,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:u(qt,{className:`h-3 w-3`})})]}),(b.length>0||x)&&r(`div`,{className:`absolute z-10 left-0 right-0 mt-0.5 max-h-40 overflow-y-auto rounded-md border border-border bg-surface shadow-md`,children:[b.map(e=>r(`button`,{type:`button`,onClick:()=>{p(e),S(e)},className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[u(Tt,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),u(`span`,{className:`truncate`,children:e})]},e)),x&&r(`button`,{type:`button`,onClick:()=>void S(),className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover border-t border-border`,children:[u(`span`,{className:`text-foreground-subtle`,children:`Create`}),r(`span`,{className:`font-medium truncate`,children:[`"`,f.trim(),`"`]})]})]})]})}):u($,{label:`Location`,value:r(`div`,{className:`flex items-center gap-2 group`,children:[n?u(`span`,{className:`truncate`,children:n}):u(`span`,{className:`italic text-foreground-subtle`,children:`unset`}),u(`button`,{type:`button`,onClick:()=>l(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit location`,children:u(Et,{className:`h-3.5 w-3.5`})})]})})}n();function Mr({deviceId:e}){let t=s(),{data:n}=St(e),{data:i}=bt(e),[a,l]=c(null),d=ce({onSuccess:()=>{l(null),t.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>{l(`Could not change primary child: ${e.message}`)}});if(n==null||String(n.type??``)!==Y.Container)return null;let f=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}}));if(f.length<=1)return null;let p=ot(f,typeof n.linkDeviceId==`number`?n.linkDeviceId:null,typeof n.primaryChildEntityId==`string`?n.primaryChildEntityId:null);return r(o,{children:[u($,{label:`Primary child`,value:u(P,{childrenList:f,selectedId:p===null?f[0].id:p.id,onSetPrimary:t=>d.mutate({deviceId:e,primaryChildEntityId:t}),disabled:d.isPending})}),a!==null&&u(`p`,{role:`alert`,className:`px-3 sm:px-4 py-1.5 text-[11px] text-danger`,children:a})]})}n();var Nr=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function Pr(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function Fr(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function Ir(){let e=Xe(),t=Ce(),{data:n}=B({deviceId:e??0},{enabled:e!==null}),{data:i}=A({deviceId:e??0},{enabled:e!==null}),a=n??t??null,[o,s]=c(`identity`);if(e===null||!a)return null;let l=String(a.stableId??``),d=String(a.name??``),f=String(a.type??``),p=String(a.addonId??``),m=a.features??[],h=new Set([`device-status`,`feature-probe`,`device-ops`]),g=(i?.entries??[]).filter(e=>e.kind===`native`&&!h.has(e.capName)).map(e=>e.capName),_=m.length>0?m:g,v=a.location??null,y=a.metadata??null,b=y!==null&&Object.keys(y).length>0;return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`border-b border-border px-3 sm:px-4 py-2 flex items-center justify-between gap-3`,children:[u(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Device Info`}),b&&r(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[u(Lr,{active:o===`identity`,onClick:()=>s(`identity`),label:`Identity`}),u(Lr,{active:o===`hardware`,onClick:()=>s(`hardware`),label:`Hardware`})]})]}),(!b||o===`identity`)&&r(`div`,{className:`divide-y divide-border`,children:[u($,{label:`ID`,value:r(`span`,{className:`font-mono text-[11px] text-foreground`,children:[`#${e}`,r(`span`,{className:`ml-1.5 text-foreground-subtle`,children:[`(`,l,`)`]})]})}),u(Ar,{deviceId:e,initialName:d}),u(jr,{deviceId:e,initialLocation:v}),u(Mr,{deviceId:e}),u($,{label:`Type`,value:f}),u($,{label:`Provider`,value:u(yt,{type:p,size:`sm`,showLabel:!0})}),u($,{label:`Capabilities`,value:_.length>0?u(ht,{capabilities:_,showLabels:!0}):u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),b&&o===`hardware`&&u(Rr,{metadata:y})]})}function Lr({active:e,onClick:t,label:n}){return u(`button`,{type:`button`,onClick:t,className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${e?`bg-surface text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`}`,children:n})}function Rr({metadata:e}){let t=Nr.filter(t=>t in e),n=Object.keys(e).filter(e=>!Nr.includes(e)).toSorted(),i=[...t,...n];return r(`div`,{children:[u(`div`,{className:`px-3 sm:px-4 py-1.5 text-[10px] text-foreground-subtle border-b border-border bg-surface-subtle/40`,children:`Auto-populated by the driver on every connect. Read-only.`}),u(`div`,{className:`divide-y divide-border`,children:i.map(t=>u($,{label:Pr(t),value:u(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:Fr(e[t])})},t))})]})}var zr=`Notifications`,Br=`This camera never notifies — no rule, no target, no alarm. Existing events, tracks and recordings are unaffected.`;function Vr(e){let{mutedDeviceIds:t,deviceId:n}=e,r=t===null?null:!t.includes(n),i=e.pendingOn??null;return{label:zr,on:r===null?null:i??r,available:r!==null,costWhenOff:Br}}function Hr(e,t){return!e.available||e.on===null?null:{deviceId:t,muted:e.on}}n();function Ur(e){if(typeof e!=`object`||!e)return null;let t={...e}.mutedDeviceIds;return Array.isArray(t)?t.filter(e=>typeof e==`number`):null}function Wr({deviceId:t}){let n=s(),i=Number.isFinite(t),[a,o]=c(null),[l,d]=c(null),f=Vr({mutedDeviceIds:Ur(be({},{enabled:i}).data),deviceId:t,pendingOn:l}),p=Ve({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=Hr(f,t);e!==null&&(d(!e.muted),p.mutate(e))},[t,p,f]),h=f.on===null,g=f.on===!1,_=g?gt:_t;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}`})]})]})}n();function Gr({deviceId:e}){let[t,n]=c(null),i=O({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(Ot,{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})]})}n();var Kr=`w-full min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary disabled:opacity-50`,qr={icon:``,label:``,unit:``,precision:``,hidden:!1};function Jr(e){return{icon:e?.icon??``,label:e?.label??``,unit:e?.unit??``,precision:e?.precision===void 0?``:String(e.precision),hidden:e?.hidden===!0}}function Yr(e){if(typeof e!=`object`||!e)return;let t=e.unit;return typeof t==`string`?t:void 0}function Xr(e){let t=e.precision.trim()===``?void 0:Number.parseInt(e.precision,10),n={...e.icon===``?{}:{icon:e.icon},...e.label.trim()===``?{}:{label:e.label.trim()},...e.unit===``?{}:{unit:e.unit},...t!==void 0&&Number.isFinite(t)?{precision:t}:{},...e.hidden?{hidden:!0}:{}};return Object.keys(n).length===0?null:n}function Zr({deviceId:e}){let t=m(),n=s(),{data:a}=B({deviceId:e},{enabled:e>0}),l=typeof a?.role==`string`?a.role:null,d=l===null?void 0:ee[l],f=d?.kind===`numeric`,p=qe(t.trpcClient,e,l??``),h=d?.kind===`numeric`?d.canonicalUnit:void 0,g=Yr(p)??h,_=g===void 0?void 0:pt(g),v=i(()=>_===void 0?[]:ft(_),[_]),[b,x]=c(null),S=b??Jr(a?.display),C=me({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),{data:w}=U({},{staleTime:6e4}),T=y({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}});if(a===void 0||l===null)return null;let E=e=>{x({...S,...e})},D=()=>{C.mutate({deviceId:e,display:Xr(S)})},O=()=>{x(qr),C.mutate({deviceId:e,display:null})},k=()=>{let e={...S.icon===``?{}:{icon:S.icon},...S.unit===``?{}:{unit:S.unit},...S.precision.trim()!==``&&Number.isFinite(Number.parseInt(S.precision,10))?{precision:Number.parseInt(S.precision,10)}:{}},t={...w?.defaults,[l]:e};T.mutate({defaults:t})},A=R(l).label,te=Object.keys(F);return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[u(`div`,{className:`border-b border-border px-3 sm:px-4 py-2`,children:u(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Display`})}),r(`div`,{className:`divide-y divide-border`,children:[u($,{label:`Icon`,value:r(`select`,{className:Kr,value:S.icon,onChange:e=>E({icon:e.target.value}),children:[r(`option`,{value:``,children:[`Default (`,A,`)`]}),te.map(e=>u(`option`,{value:e,children:e},e))]})}),u($,{label:`Label`,value:u(`input`,{type:`text`,className:Kr,placeholder:A,value:S.label,onChange:e=>E({label:e.target.value})})}),f&&r(o,{children:[u($,{label:`Unit`,value:r(`select`,{className:Kr,value:S.unit,onChange:e=>E({unit:e.target.value}),disabled:v.length===0,children:[r(`option`,{value:``,children:[`Source`,g?` (${g})`:``]}),v.map(e=>u(`option`,{value:e,children:e},e))]})}),u($,{label:`Precision`,value:u(`input`,{type:`number`,min:0,max:10,step:1,className:Kr,placeholder:`inherit`,value:S.precision,onChange:e=>E({precision:e.target.value})})})]}),u($,{label:`Hidden`,value:r(`label`,{className:`flex items-center gap-2`,children:[u(`input`,{type:`checkbox`,checked:S.hidden,onChange:e=>E({hidden:e.target.checked})}),u(`span`,{className:`text-[11px] text-foreground`,children:`Hide from device lists`})]})})]}),r(`div`,{className:`border-t border-border px-3 sm:px-4 py-2 flex flex-wrap items-center gap-2`,children:[u(`button`,{type:`button`,className:`rounded bg-primary px-3 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-50`,onClick:D,disabled:C.isPending,children:`Save`}),u(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-[11px] text-foreground-subtle`,onClick:O,disabled:C.isPending,children:`Reset`}),r(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-[11px] text-foreground-subtle`,onClick:k,disabled:T.isPending,title:`Apply this unit / precision / icon as the default for every ${A} sensor`,children:[`Set as default for all `,A,` sensors`]})]})]})}function Qr(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function $r({device:e}){let t=Ft(),n=typeof e.id==`number`?e.id:null,i=String(e.type??``),a=i===Y.Camera,o=i===Y.Hub,s=typeof e.role==`string`&&e.role.length>0,c=e.features??[],l=c.includes(J.Resyncable),{data:d}=se({deviceId:n??0},{enabled:n!==null&&a,refetchInterval:5e3}),f=d?.streams??{},p=Object.entries(f),m=c.includes(J.DoorbellButton),h=ye(m?{deviceId:n??void 0,historyLimit:10}:void 0),g=h.latest?Date.now()-h.latest.timestamp<3e4:!1;return r(`div`,{className:`space-y-5`,children:[o&&n!==null&&u(at,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),l&&n!==null&&u(Gr,{deviceId:n}),n!==null&&u(Wr,{deviceId:n}),a&&n!==null&&u(K,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),m&&u(rt,{history:h.history,latestIsFresh:g}),a&&n!==null&&u(K,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),a&&p.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:p.map(([e,t])=>r(`div`,{className:`px-4 py-2.5`,children:[r(`div`,{className:`flex items-center gap-2 mb-2`,children:[u(Mt,{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(ei,{label:`Nominal`,value:Qr(t.nominalBitrateKbps??0)}),u(ei,{label:`Observed`,value:Qr(t.observedBitrateKbps??0)}),u(ei,{label:`Peak`,value:Qr(t.peakBitrateKbps??0)}),u(ei,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),u(Ir,{}),s&&n!==null&&u(Zr,{deviceId:n})]})}function ei({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})]})}n();var ti=[{id:`overview`,label:`Overview`,cameraOnly:!1},{id:`config`,label:`Config`,cameraOnly:!1},{id:`detection-pipeline`,label:`Detection pipeline`,cameraOnly:!0},{id:`bindings`,label:`Bindings`,cameraOnly:!0}];function ni(e){let t=e===Y.Camera;return ti.filter(e=>t||!e.cameraOnly).map(({id:e,label:t})=>({id:e,label:t}))}var ri=[{id:`logs`,icon:Gt,label:`Logs`},{id:`repl`,icon:Jt,label:`REPL`},{id:`events`,icon:Rt,label:`Events`},{id:`state`,icon:It,label:`State`}];function ii(){let n=Vt(),a=Number(n.deviceId),l=Number.isFinite(a),d=Ft(),f=s(),h=et(),g=m(),[v,y]=Bt(),x=v.get(`tab`)??`overview`,S=v.get(`sub`),[C,w]=c(`logs`),T=`device-detail.left-col-width-px`,[E,D]=c(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(T),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),O=t(E);O.current=E;function k(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??E??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{D(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=O.current;if(e!==null)try{window.localStorage.setItem(T,String(Math.round(e)))}catch{}document.body.style.userSelect=``,document.body.style.cursor=``};document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,document.addEventListener(`mousemove`,i),document.addEventListener(`mouseup`,a)}let{data:A,isLoading:ee,isError:te}=B({deviceId:a},{enabled:l,refetchInterval:5e3,retry:1}),{data:re}=ct({deviceId:a},{enabled:l}),j=i(()=>{let e=re?.settings?.sections??[],t=re?.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(en)&&r.add(tn),[...r].map(e=>e===`export`?{id:e,label:nn,isAddonContrib:!0}:{id:e,label:mt[e]?.label??e,isAddonContrib:!0})},[re]),M=A,N=String(M?.name??n.deviceId??`Device`),P=M?.online===!0,ie=P?`online`:`offline`,F=String(M?.addonId??`rtsp`),I=M?.features??[],L=M?.type,R=L===Y.Camera,{data:se}=bt(l?a:0),ce=L===Y.Container,z=i(()=>(se??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[se]),V=i(()=>ce?ot(z,typeof M?.linkDeviceId==`number`?M.linkDeviceId:null,typeof M?.primaryChildEntityId==`string`?M.primaryChildEntityId:null)?.id??null:null,[ce,z,M?.linkDeviceId,M?.primaryChildEntityId]),{data:H}=ct({deviceId:V??0},{enabled:V!==null}),U=i(()=>{if(V===null)return[];let e=H?.settings?.sections??[],t=H?.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:mt[e]?.label??e,isAddonContrib:!0,childDeviceId:V}))},[V,H]),W=typeof M?.parentDeviceId==`number`?M.parentDeviceId:null,{data:de}=B({deviceId:W??0},{enabled:W!==null}),G=ve(),fe=M?.disabled!==!0,me=i(()=>{let e=new Set,t=[];for(let n of[...ni(L),...j,...U])e.has(n.id)||(e.add(n.id),t.push(n));return t},[L,j,U]),K=i(()=>kr(me,x),[me,x]),he=e(e=>{y(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[y]),_e=e(e=>{y(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[y]),ye=(se??[]).length>0,be=i(()=>ri.filter(({featureGate:e})=>!e||I.includes(e)),[I]),{data:q}=xe({addonId:F},{enabled:!!F&&F!==`rtsp`}),Ce=Ke({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]}),d(q?.id?`/integrations/${q.id}`:`/integrations`)}}),we=oe({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Te=Ie({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ee=ue(),De=ae({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Oe=I.includes(J.Rebootable),ke=I.includes(J.BatteryOperated),Ae=Fe(g.trpcClient,ke&&l?a:null),[je,Me]=c(!1),Ne=p(g.trpcClient,l?a:null),Pe=async()=>{if(!(je||!Ne)){Me(!0);try{await Ne.snapshot?.invalidateCache({});let e=await Ne.snapshot?.getSnapshot({});if(!e)return;let t=`data:${e.contentType};base64,${e.base64}`,n=e.contentType.includes(`png`)?`png`:`jpg`,r=N.replace(/[^a-zA-Z0-9_.-]+/g,`_`),i=new Date().toISOString().replace(/[:.]/g,`-`),a=document.createElement(`a`);a.href=t,a.download=`${r}-${i}.${n}`,document.body.appendChild(a),a.click(),document.body.removeChild(a)}finally{Me(!1)}}},Le=we.isPending||Te.isPending,{data:Re}=ne({deviceId:a},{enabled:l,refetchInterval:1e4}),ze=Re?.agentNodeId??null,Be=typeof ze==`string`&&ze.length>0&&!ze.startsWith(`addon:`)?ze:void 0,{data:Ve}=tt({deviceId:a,...Be?{nodeId:Be}:{}},{enabled:l,refetchInterval:3e3,retry:!1}),{data:We}=pe({deviceId:a},{enabled:l,refetchInterval:3e3,retry:!1}),Ge=We?.level?.dbfs??null;function qe(){if(!l)return null;switch(K){case`overview`:return u($r,{device:M??{}});case`config`:return u(hr,{deviceId:a,activeSubTab:S,onSubTabChange:_e});case`detection-pipeline`:return u(Dr,{deviceId:a,activeSubTab:S,onSubTabChange:_e});case`bindings`:return u(dr,{deviceId:a});default:{let e=K,t=j.some(t=>t.id===e),n=U.find(t=>t.id===e);if(!t&&n===void 0)return null;let r=n?.childDeviceId??a;if(e===`export`)return u(rn,{deviceId:a,sectionFilter:en,activeSubTab:S,onSubTabChange:_e});let i=u(rn,{deviceId:r,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:S,onSubTabChange:_e});return n!==void 0&&r!==a?u(He,{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||!A?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-hidden`,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(Ue,{items:[{label:`Integrations`,onClick:()=>d(`/integrations`)},{label:q?.name??F,onClick:()=>q?.id&&d(`/integrations/${q.id}`)},{label:N}]})}),r(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[u(yt,{type:F,size:`lg`}),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:N}),u($t,{status:ie}),ke&&u(Ze,{status:Ae,variant:`full`})]}),W!==null&&de&&r(`button`,{type:`button`,onClick:()=>d(`/devices/${W}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${de.name}`,children:[u(`span`,{children:`↑`}),u(`span`,{className:`truncate`,children:String(de.name??`Device #${W}`)})]}),u(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:I.length>0&&u(ht,{capabilities:I})})]}),Ve&&u(`div`,{className:`hidden lg:flex`,children:u(ai,{metrics:Ve,dbfs:Ge})}),r(`div`,{className:`flex items-center gap-1 shrink-0`,children:[r(`button`,{onClick:async()=>{fe?await h({title:`Disable "${N}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&Te.mutate({deviceId:a}):we.mutate({deviceId:a})},disabled:Le,title:fe?`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 ${fe?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[u(Dt,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden sm:inline`,children:Le?`Updating…`:fe?`Enabled`:`Disabled`})]}),u(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),R&&r(o,{children:[u(wn,{deviceId:a}),u(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`})]}),u(ge,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:zt,disabled:je,onClick:()=>{Pe()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:At,hidden:!Oe,disabled:Ee.isPending,danger:!0,onClick:async()=>{await h({title:`Reboot "${N}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&Ee.mutate({deviceId:a})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${q?.name??F}.`,icon:Ot,disabled:De.isPending,danger:!0,onClick:async()=>{await h({title:`Restart "${q?.name??F}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${N}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&De.mutate({addonId:F})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:Kt,separatorBefore:!0,disabled:Ce.isPending,danger:!0,onClick:async()=>{await h({title:`Delete "${N}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&Ce.mutate({deviceId:a})}}]})]})]})]}),u(He,{deviceId:a,device:M??void 0,children:u(b,{children:u(le,{children:u(_,{children:u(Se,{children:r(`main`,{className:G?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[r(`div`,{className:G?`flex flex-col bg-surface`:`${E===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!G&&E!==null?{width:`${String(E)}px`}:void 0,children:[u(`div`,{className:R?`flex-shrink-0 border-b border-border-subtle bg-black`:G?`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:R?u(ar,{deviceId:a,intercomAvailable:I.includes(J.TwoWayAudio)}):u(Xn,{deviceId:a,deviceName:N,deviceType:L??`unknown`,provider:F,isOnline:P,features:I})}),r(`div`,{className:G?`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:be.map(({id:e,label:t,icon:n})=>r(`button`,{onClick:()=>w(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${C===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:G?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[C===`logs`&&u(or,{deviceId:a,containerDeviceId:L===`container`?a:void 0}),C===`repl`&&u(sr,{deviceId:a}),C===`events`&&u(cr,{deviceId:a}),C===`state`&&u(lr,{deviceId:a})]})]})]}),!G&&u(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:k,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:u(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),r(`div`,{className:G?`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:me.map(e=>{let t=K===e.id;return r(`button`,{onClick:()=>he(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:G?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[K===`overview`&&ye&&u(Dn,{parentDeviceId:a}),qe()]})]})]})})})})})})]}):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 ai({metrics:e,dbfs:t}){let n=Oe(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(Pt,{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(Lt,{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(dn,{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{ii as DeviceDetailPage};
@@ -1 +0,0 @@
1
- import{I as e,K as t,Q as n,S as r,U as i,W as a,a as o,b as s,i as c,o as l,q as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as p}from"./player-overlays-9UuGjKRi.js";import{Ca as m,Da as h,Dt as g,Ea as _,Ft as v,Hr as y,It as b,Ls as x,Lt as S,Pt as C,Rt as w,Ta as T,Tt as E,Vs as D,Xt as O,Yi as k,_a as A,ba as j,da as M,fn as N,ha as P,j as F,kn as I,la as ee,ma as L,pa as R,pn as z,sa as te,ua as B,va as ne,wa as V,xa as H,ya as re}from"./src-eNwyjio2.js";import{Vt as U,at as W}from"./src-DbUPImmO.js";import{t as ie}from"./clock-sO6o_mjY.js";import{t as ae}from"./copy-DVYoqFlk.js";import{t as oe}from"./download-BifPfhIt.js";import{a as se,c as ce,d as le,f as ue,i as de,m as fe,n as pe,o as me,p as he,r as ge,s as _e,t as ve}from"./debounced-invalidate-DKj6sAUn.js";import{t as ye}from"./refresh-cw-DTXYyRHZ.js";import{t as be}from"./square-check-big-Cx7mXraC.js";import{t as xe}from"./square-De580U5i.js";import{t as Se}from"./star-Bf7LBoXR.js";import{t as Ce}from"./undo-2-Cx6lwzFn.js";import{C as G,G as we,I as Te,K,O as Ee,P as De,R as Oe,c as ke,o as Ae,p as je,r as Me,t as Ne,z as Pe}from"./index-lupFu8MS.js";import{t as Fe}from"./AdminPage-CCD07UMs.js";import{i as Ie,n as Le,t as Re}from"./authed-media-BPd_L9jr.js";import{t as ze}from"./AdminTabs-CW5SZp7Y.js";var Be=K(`arrow-down-wide-narrow`,[[`path`,{d:`m3 16 4 4 4-4`,key:`1co6wj`}],[`path`,{d:`M7 20V4`,key:`1yoxec`}],[`path`,{d:`M11 4h10`,key:`1w87gc`}],[`path`,{d:`M11 8h7`,key:`djye34`}],[`path`,{d:`M11 12h4`,key:`q8tih4`}]]),Ve=K(`bug`,[[`path`,{d:`m8 2 1.88 1.88`,key:`fmnt4t`}],[`path`,{d:`M14.12 3.88 16 2`,key:`qol33r`}],[`path`,{d:`M9 7.13v-1a3.003 3.003 0 1 1 6 0v1`,key:`d7y7pr`}],[`path`,{d:`M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6`,key:`xs1cw7`}],[`path`,{d:`M12 20v-9`,key:`1qisl0`}],[`path`,{d:`M6.53 9C4.6 8.8 3 7.1 3 5`,key:`32zzws`}],[`path`,{d:`M6 13H2`,key:`82j7cp`}],[`path`,{d:`M3 21c0-2.1 1.7-3.9 3.8-4`,key:`4p0ekp`}],[`path`,{d:`M20.97 5c0 2.1-1.6 3.8-3.5 4`,key:`18gb23`}],[`path`,{d:`M22 13h-4`,key:`1jl80f`}],[`path`,{d:`M17.2 17c2.1.1 3.8 1.9 3.8 4`,key:`k3fwyw`}]]),He=K(`circle-dashed`,[[`path`,{d:`M10.1 2.182a10 10 0 0 1 3.8 0`,key:`5ilxe3`}],[`path`,{d:`M13.9 21.818a10 10 0 0 1-3.8 0`,key:`11zvb9`}],[`path`,{d:`M17.609 3.721a10 10 0 0 1 2.69 2.7`,key:`1iw5b2`}],[`path`,{d:`M2.182 13.9a10 10 0 0 1 0-3.8`,key:`c0bmvh`}],[`path`,{d:`M20.279 17.609a10 10 0 0 1-2.7 2.69`,key:`1ruxm7`}],[`path`,{d:`M21.818 10.1a10 10 0 0 1 0 3.8`,key:`qkgqxc`}],[`path`,{d:`M3.721 6.391a10 10 0 0 1 2.7-2.69`,key:`1mcia2`}],[`path`,{d:`M6.391 20.279a10 10 0 0 1-2.69-2.7`,key:`1fvljs`}]]),Ue=K(`circle`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),We=K(`copy-plus`,[[`line`,{x1:`15`,x2:`15`,y1:`12`,y2:`18`,key:`1p7wdc`}],[`line`,{x1:`12`,x2:`18`,y1:`15`,y2:`15`,key:`1nscbv`}],[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]),Ge=K(`graduation-cap`,[[`path`,{d:`M21.42 10.922a1 1 0 0 0-.019-1.838L12.83 5.18a2 2 0 0 0-1.66 0L2.6 9.08a1 1 0 0 0 0 1.832l8.57 3.908a2 2 0 0 0 1.66 0z`,key:`j76jl0`}],[`path`,{d:`M22 10v6`,key:`1lu8f3`}],[`path`,{d:`M6 12.5V16a6 3 0 0 0 12 0v-3.5`,key:`1r8lef`}]]),Ke=K(`square-parking`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 17V7h4a3 3 0 0 1 0 6H9`,key:`1dfk2c`}]]),qe=K(`tag`,[[`path`,{d:`M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z`,key:`vktsd0`}],[`circle`,{cx:`7.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`kqv944`}]]);n();function Je(e){return e.subLabel??e.label}var Ye=720*60*60*1e3;function Xe(e){let t=[];for(let n of e)t.push(...n);return t}function Ze(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function Qe(e,t){return e.filter(e=>!(e.importance<t.minImportance||t.cameras.size>0&&!t.cameras.has(e.deviceId)||t.classes.size>0&&!t.classes.has(e.className)))}function $e(e,t){return`${String(e)}:${t}`}function et(e,t){let n=new Map,r=new Set;for(let i of e){let e=$e(i.deviceId,i.trackId);if(!t.has(e)||r.has(e))continue;r.add(e);let a=n.get(i.deviceId);a?a.push(i.trackId):n.set(i.deviceId,[i.trackId])}return n}function tt(e,t){return{since:e.fromMs??t-Ye,until:e.toMs??t}}var nt=[`native`,`raster`,`standin`];function rt(e){return nt.some(t=>t===e)}var it={standin:{label:`stand-in`,title:`Stand-in: this tile is a face or plate detail crop copied in because no frame of the subject was captured. It is not a best shot.`,tone:`warning`},raster:{label:`low-res`,title:`Raster crop: a sub-native cut of the subject, not a native capture. Honest, but lower resolution than a best shot.`,tone:`info`}};function at(e){return e===`standin`?it.standin:e===`raster`?it.raster:null}var ot={"no-key-frame":`No key frame existed at close, so no native tile could be cut.`,"no-best-seen-bbox":`No subject box was ever recorded, so there was nothing to cut around.`,"derive-returned-null":`The close-time crop was attempted and produced nothing.`,"derive-threw":`The close-time crop failed with an error.`,"derive-not-wired":`No close-time crop was wired on this node.`,"no-media-store":`The node was shutting down mid-close.`,"no-thumbnail":`The track closed with no tile of any kind.`,"standin-tile":`The track closed with a detail crop standing in for the subject.`,"raster-tile":`The track closed with a sub-native raster crop of the subject.`,"native-tile":`The track closed with a native tile.`};function st(e){if(e===void 0)return null;let t=e.trim();if(t.length===0)return null;let n=t.split(/\s+/),r=n[0]??t,i=[];for(let e of n.slice(1)){let t=e.indexOf(`=`);t===-1?i.push({key:e,value:null}):i.push({key:e.slice(0,t),value:e.slice(t+1)})}return{sentence:ot[r]??r,detail:i,raw:t}}function ct(e){if(e===void 0||!Number.isFinite(e)||e<=0)return``;let t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return`${String(n)}m ${String(r).padStart(2,`0`)}s`}function lt({row:e,cameraName:t,nowMs:n,onOpenDetail:i,selected:a=!1,onToggleSelect:o,score:s,provenance:c,footer:l}){let u=Ie(e.bestEventId?`${Re}/${e.bestEventId}`:void 0),f=Math.round(e.importance*100),p=s===void 0?void 0:Math.round(s*100),m=ct(e.windowMs),h=()=>i(e),g=at(c);return r(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${a?`border-primary ring-1 ring-primary`:`border-border`}`,children:[r(`div`,{className:`aspect-video relative overflow-hidden bg-surface-hover`,children:[u.src?d(`img`,{src:u.src,alt:`Event from ${t}`,onClick:h,className:`h-full w-full cursor-zoom-in object-cover`}):d(`button`,{type:`button`,onClick:h,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-surface-hover text-foreground-subtle`,title:u.failed?`Key-event media unavailable`:`No key-event media`,children:d(fe,{className:`h-6 w-6 opacity-60`})}),o&&d(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o($e(e.deviceId,e.trackId))},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":a?`Deselect`:`Select`,children:a?d(be,{className:`h-4 w-4 text-primary`}):d(xe,{className:`h-4 w-4`})}),p!==void 0&&r(`span`,{className:`absolute left-1 top-1 z-10 rounded bg-primary/85 px-1.5 py-0.5 text-[10px] font-semibold text-white tabular-nums`,title:`CLIP semantic-match score`,children:[String(p),`%`]}),f>0&&d(`span`,{className:`absolute right-1 top-1 z-10 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-semibold text-white`,children:String(f)}),g!==null&&d(`span`,{className:`absolute bottom-1 right-1 z-10 rounded px-1.5 py-0.5 text-[10px] font-semibold text-white ${g.tone===`warning`?`bg-warning/90`:`bg-black/70`}`,title:g.title,children:g.label}),(e.markForTrain===!0||e.debug===!0||e.favourited===!0)&&r(`span`,{className:`absolute bottom-1 left-1 z-10 flex gap-1`,children:[e.markForTrain===!0&&d(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:`Marked for training`,"aria-label":`Marked for training`,children:d(Ge,{className:`h-3 w-3`})}),e.debug===!0&&d(`span`,{className:`rounded bg-black/70 p-0.5 text-white`,title:`Flagged for debug`,"aria-label":`Flagged for debug`,children:d(Ve,{className:`h-3 w-3`})}),e.favourited===!0&&d(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:`Favourited`,"aria-label":`Favourited`,children:d(Se,{className:`h-3 w-3`})})]})]}),r(`button`,{type:`button`,onClick:h,className:`min-w-0 px-2 py-1.5 text-left space-y-0.5`,children:[r(`p`,{className:`text-[11px] font-medium text-foreground truncate`,title:e.className,children:[e.className,Je(e)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,Je(e)]}):null]}),d(`p`,{className:`text-[10px] text-foreground-subtle truncate`,title:t,children:t}),r(`div`,{className:`flex items-center justify-between gap-2`,children:[d(`span`,{className:`text-[10px] text-foreground-subtle truncate`,children:ue(e.timestamp,n)}),m&&d(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:m})]})]}),l!==void 0&&d(`div`,{className:`px-2 pb-1.5`,children:l})]})}var ut=1400,dt=`Admin-gated URL — opens only inside an authenticated session`;function ft({label:t,value:n,title:i}){let[a,o]=u(!1);return f(()=>{if(!a)return;let e=setTimeout(()=>o(!1),ut);return()=>clearTimeout(e)},[a]),r(`button`,{type:`button`,onClick:e(()=>{(async()=>{try{await navigator.clipboard.writeText(n),o(!0)}catch{window.prompt(`Copy the media URL:`,n)}})()},[n]),title:i,"aria-label":`Copy ${t} URL`,className:`flex min-w-0 items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${a?`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:`border-border text-foreground-subtle hover:border-primary hover:text-foreground`}`,children:[d(a?Pe:ae,{className:`h-2.5 w-2.5 shrink-0`}),d(`span`,{className:`truncate`,children:a?`Copied`:t})]})}function pt({localUrl:e,publicUrl:t}){return r(`div`,{className:`flex flex-wrap gap-1`,children:[d(ft,{label:`Local`,value:e,title:`Copy LAN URL — ${dt}`}),t&&d(ft,{label:`Public`,value:t,title:`Copy public URL — ${dt}`})]})}var mt={firstFrame:`First frame (track start)`,lastFrame:`Last frame (track end)`,thumbnail:`Best detection`,thumbnailSmall:`Best detection (480)`,snapshot:`Snapshot`,keyFrame:`Key frame (native-res)`,keyFrameSmall:`Key frame (960)`,crop:`Object crop`,fullFrame:`Full frame`,fullFrameBoxed:`Full frame (boxed)`,faceCrop:`Face crop`,plateCrop:`Plate crop`};function ht(e){return e in mt}function gt(e){return ht(e)?mt[e]:e}function _t(e,t){return`${e}${Re}/${encodeURIComponent(t)}`}n();var vt=3e4;function yt(t){let[n,r]=u(null),i=e(e=>{r(t=>t??e)},[]);return f(()=>{t||r(null)},[t]),{publicOrigin:n,probes:t?d(bt,{onOrigin:i}):null}}function bt({onOrigin:e}){let{data:t}=I({capName:`network-access`});return d(s,{children:(t??[]).map(t=>d(xt,{addonId:t.addonId,onOrigin:e},t.addonId))})}function xt({addonId:e,onOrigin:t}){let{data:n}=k({addonId:e},{refetchInterval:vt,retry:!1});return f(()=>{let e=n?W.safeParse(n):null,r=e?.success?e.data.endpoint?.url:void 0;if(r)try{t(new URL(r).origin)}catch{}},[n,t]),null}var q=typeof h==`function`,St=`Track flags arrive with the next server update`;function Ct(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var wt=q?h:Ct;function Tt(e){if(typeof e!=`object`||!e||!(`trackId`in e)||!(`markForTrain`in e)||!(`debug`in e)||!(`favourited`in e))return null;let{trackId:t,markForTrain:n,debug:r,favourited:i}=e;return typeof t!=`string`||typeof n!=`boolean`||typeof r!=`boolean`||typeof i!=`boolean`?null:{trackId:t,markForTrain:n,debug:r,favourited:i}}n();function Et({label:e,hint:t,checked:n,disabled:i,title:a,icon:o,onToggle:s}){return r(`button`,{type:`button`,role:`switch`,"aria-checked":n,"aria-label":e,disabled:i,title:a,onClick:s,className:`flex w-full items-center gap-2 rounded-md border px-2 py-1.5 text-left transition-colors disabled:opacity-50 ${n?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[d(`span`,{className:n?`text-primary`:`text-foreground-subtle`,children:o}),r(`span`,{className:`min-w-0 flex-1`,children:[d(`span`,{className:`block text-[11px] font-medium text-foreground`,children:e}),d(`span`,{className:`block text-[10px] text-foreground-subtle`,children:t})]}),d(`span`,{"aria-hidden":`true`,className:`h-4 w-7 shrink-0 rounded-full p-0.5 transition-colors ${n?`bg-primary`:`bg-border`}`,children:d(`span`,{className:`block h-3 w-3 rounded-full bg-white transition-transform ${n?`translate-x-3`:``}`})})]})}function Dt({deviceId:e,trackId:t,markForTrain:n,debug:i,favourited:a,onChange:o}){let s=wt(),[c,l]=u(null),f=c?.markForTrain??n===!0,p=c?.debug??i===!0,m=c?.favourited??a===!0,h=!q||s.isPending,g=q?void 0:St,_=n=>{h||(async()=>{try{let r=Tt(await s.mutateAsync({deviceId:e,trackId:t,flags:n}));if(!r)return;l(r),o?.(r)}catch(e){let t=e instanceof Error?e.message:``;window.alert(t===``?`Could not update this track. Check the server logs.`:`Could not update this track — ${t}`)}})()};return r(`div`,{className:`grid gap-1.5 sm:grid-cols-2`,children:[d(Et,{label:`Mark for training`,hint:`Keeps this track and its media past retention`,checked:f,disabled:h,...g===void 0?{}:{title:g},icon:d(Ge,{className:`h-4 w-4`}),onToggle:()=>_({markForTrain:!f})}),d(Et,{label:`Debug`,hint:`Flag this track for diagnostic attention`,checked:p,disabled:h,...g===void 0?{}:{title:g},icon:d(Ve,{className:`h-4 w-4`}),onToggle:()=>_({debug:!p})}),d(Et,{label:`Favourited`,hint:`Keeps this track and its media past retention`,checked:m,disabled:h,...g===void 0?{}:{title:g},icon:d(Se,{className:`h-4 w-4`}),onToggle:()=>_({favourited:!m})})]})}var J=100,Ot=120,kt={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Y=e=>e<0?0:e>1?1:e,X=e=>Math.round(e*100)/100;function At(e,t){if(e.length<=t)return[...e];let n=(e.length-1)/(t-1),r=[];for(let i=0;i<t;i++)r.push(e[Math.round(i*n)]);return r[r.length-1]=e[e.length-1],r}function jt(e,t,n){if(e.length===0||t===null)return kt;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return kt;let a=At(e,n?.maxPoints??Ot).map(e=>({x:X(Y(e.x/r)*J),y:X(Y(e.y/i)*J)})),o=a[0]??null,s=a[a.length-1]??null,c=a.length>=2?a.map(e=>`${e.x},${e.y}`).join(` `):``,l=(n?.snapshots??[]).map(e=>({x:X(Y(e.x/r)*J),y:X(Y(e.y/i)*J),mediaKey:e.mediaKey})),u=null,d=-1;for(let t of e){let e=Y(t.bbox.w/r)*Y(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:X(Y(u.bbox.x/r)*J),y:X(Y(u.bbox.y/i)*J),w:X(Y(u.bbox.w/r)*J),h:X(Y(u.bbox.h/i)*J)}:null}}var Mt=typeof ee==`function`,Nt=`Track deletion arrives with the next server update`;function Pt(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var Ft=Mt?ee:Pt;n();var It=15e3;function Lt(e){return`${Re}/${encodeURIComponent(e)}`}var Rt=window.location.origin;function zt({mediaKey:e,label:t}){let{src:n,failed:r}=Ie(Lt(e));return n===null?d(`div`,{className:`flex h-full w-full items-center justify-center bg-surface-hover`,children:r?d(fe,{className:`h-4 w-4 text-foreground-subtle opacity-60`}):d(G,{className:`h-4 w-4 animate-spin text-foreground-subtle opacity-70`})}):d(`img`,{src:n,alt:t,className:`h-full w-full object-cover`})}var Bt=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),Vt=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]);function Ht(e){let[t,n]=u(null);return f(()=>{if(n(null),!e)return;let t=!1,r=new Image;return r.onload=()=>{t||n({width:r.naturalWidth,height:r.naturalHeight})},r.src=e,()=>{t=!0,r.onload=null}},[e]),t}function Ut({overlay:e,onPickSnapshot:t}){return!e.polyline&&!e.peakBox&&e.snapshots.length===0?null:r(`svg`,{viewBox:`0 0 100 100`,preserveAspectRatio:`none`,className:`pointer-events-none absolute inset-0 h-full w-full`,children:[e.peakBox&&d(`rect`,{x:e.peakBox.x,y:e.peakBox.y,width:e.peakBox.w,height:e.peakBox.h,fill:`none`,stroke:`#f59e0b`,strokeWidth:2,vectorEffect:`non-scaling-stroke`,rx:1}),e.polyline&&d(`polyline`,{points:e.polyline,fill:`none`,stroke:`#38bdf8`,strokeWidth:2,strokeLinejoin:`round`,strokeLinecap:`round`,strokeOpacity:.85,vectorEffect:`non-scaling-stroke`}),e.points.map((e,t)=>d(`circle`,{cx:e.x,cy:e.y,r:1,fill:`#38bdf8`,fillOpacity:.6,vectorEffect:`non-scaling-stroke`},`${String(e.x)}-${String(e.y)}-${String(t)}`)),e.snapshots.map((e,n)=>d(`circle`,{cx:e.x,cy:e.y,r:1.9,fill:`#0ea5e9`,fillOpacity:.95,stroke:`#082f49`,strokeWidth:.7,vectorEffect:`non-scaling-stroke`,className:t?`pointer-events-auto cursor-pointer`:void 0,onClick:t?n=>{n.stopPropagation(),t(e.mediaKey)}:void 0,children:d(`title`,{children:`Snapshot checkpoint — click to view this frame`})},`snap-${e.mediaKey}-${String(n)}`)),e.start&&d(`circle`,{cx:e.start.x,cy:e.start.y,r:2.4,fill:`#22c55e`,stroke:`#052e16`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`}),e.end&&d(`circle`,{cx:e.end.x,cy:e.end.y,r:2.4,fill:`#ef4444`,stroke:`#450a0a`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`})]})}function Z({label:e,value:t,mono:n}){return r(`div`,{className:`flex items-baseline justify-between gap-3 border-b border-border/60 py-1.5 last:border-0`,children:[d(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),d(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono text-[11px]`:``}`,title:t,children:t})]})}function Wt({row:t,cameraName:n,deleteAvailable:i,onClose:o,onDeleted:c,onFlagsChanged:l}){let m=p(),h=Ft(),_=t!==null,v=t?.deviceId??0,y=t?.trackId??``,b=t?.bestEventId??``,S=t?.timestamp??0,C=t?.windowMs??0,{data:T}=L({deviceId:v,trackId:y},{enabled:_}),{data:D}=j({trackId:y,deviceId:v},{enabled:_}),{data:O}=M({eventId:b,deviceId:v},{enabled:_&&b!==``}),{data:k}=x({deviceId:v,since:S-It,until:S+C+It},{enabled:_}),[A,N]=u(null),[P,F]=u(!1),{publicOrigin:I,probes:ee}=yt(_);f(()=>{N(null)},[v,y]);let R=a(()=>{let e=D??[],t=O??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[D,O]),z=A??R,te=Ie(z?Lt(z.key):void 0),B=a(()=>{let e=new Set,t=[];for(let n of[...O??[],...D??[]])n.key===``||e.has(n.key)||(e.add(n.key),t.push(n));return t},[O,D]),ne=a(()=>B.find(e=>Bt.has(e.kind))??null,[B]),V=Ht(Ie(ne?Lt(ne.key):void 0).src),H=a(()=>jt(T?.positions??[],V,{snapshots:(T?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaKey:e.mediaKey}))}),[T?.positions,T?.snapshots,V]),re=e(e=>{let t=B.find(t=>t.key===e);t&&N(t)},[B]);if(t===null)return null;let U=te.src,W=z?.kind,ie=W!==void 0&&Vt.has(W)&&V!==null&&(T?.positions.length??0)>=2,ae=k&&k.length>0?k[0]:null,oe=()=>{ae&&(F(!0),(async()=>{try{let e=await m.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:ae.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{window.alert(`Could not resolve clip playback. Check the server logs.`)}finally{F(!1)}})())},se=()=>{!i||h.isPending||window.confirm(`Delete this track and all its media? This cannot be undone.`)&&(async()=>{try{await h.mutateAsync({deviceId:t.deviceId,trackIds:[t.trackId]}),c()}catch{window.alert(`Failed to delete this track. Check the server logs.`)}})()},ce=Math.round(t.importance*100),ue=T?.importanceReason?`${String(ce)}% · ${T.importanceReason}`:`${String(ce)}%`,de=T?.zonesVisited&&T.zonesVisited.length>0?T.zonesVisited.join(`, `):`—`,me=T?.audioLabels&&T.audioLabels.length>0?T.audioLabels.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `):`—`,ge=T?T.totalDistance.toFixed(2):`—`,_e=st(T?.previewMissReason),ve=he(T?T.firstSeen:S),ye=T?he(T.lastSeen):`—`;return d(E,{open:!0,onOpenChange:e=>!e&&o(),children:r(g,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Event detail`,className:`flex h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:h-auto md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[r(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[r(`div`,{className:`min-w-0`,children:[r(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:[t.className,Je(t)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,Je(t)]}):null]}),d(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:n})]}),d(`button`,{type:`button`,onClick:o,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:d(Me,{className:`h-4 w-4`})})]}),r(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[U?d(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:d(pe,{src:U,alt:`Key frame from ${n}`,fit:`natural`,className:`w-full`,overlay:ie?d(Ut,{overlay:H,onPickSnapshot:re}):void 0})}):d(`div`,{className:`flex aspect-video w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-surface-hover text-foreground-subtle`,children:te.failed?r(s,{children:[d(fe,{className:`h-8 w-8 opacity-60`}),d(`span`,{className:`text-[11px]`,children:`Key-frame media unavailable`})]}):d(G,{className:`h-6 w-6 animate-spin opacity-70`})}),B.length>0&&d(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:B.map(e=>{let t=gt(e.kind),n=_t(Rt,e.key),i=I?_t(I,e.key):null;return r(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[d(`button`,{type:`button`,onClick:()=>N(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${t} · ${he(e.timestamp)}`,children:d(zt,{mediaKey:e.key,label:t})}),r(`figcaption`,{className:`min-w-0 px-0.5`,children:[d(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:t,children:t}),d(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:he(e.timestamp),children:le(e.timestamp)})]}),d(pt,{localUrl:n,publicUrl:i})]},e.key)})}),ee,ae&&r(w,{variant:`secondary`,onClick:oe,disabled:P,children:[P?d(G,{className:`h-3.5 w-3.5 animate-spin`}):d(Ee,{className:`h-3.5 w-3.5`}),` `,`View clip`]}),d(Dt,{deviceId:t.deviceId,trackId:t.trackId,...(T?.markForTrain??t.markForTrain)===void 0?{}:{markForTrain:T?.markForTrain??t.markForTrain},...(T?.debug??t.debug)===void 0?{}:{debug:T?.debug??t.debug},...(T?.favourited??t.favourited)===void 0?{}:{favourited:T?.favourited??t.favourited},onChange:l}),_e!==null&&r(`div`,{className:`rounded-lg border border-warning/40 bg-warning/8 px-3 py-2`,children:[d(`p`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Best shot`}),d(`p`,{className:`mt-0.5 text-xs text-foreground`,children:_e.sentence}),d(`code`,{className:`mt-1 block break-all font-mono text-[10px] text-foreground-subtle`,children:_e.raw})]}),r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[d(Z,{label:`Camera`,value:n}),d(Z,{label:`Class`,value:t.className}),d(Z,{label:`Label`,value:t.label??`—`}),d(Z,{label:`Sub-label`,value:t.subLabel??`—`}),d(Z,{label:`Importance`,value:ue}),d(Z,{label:`Zones visited`,value:de}),d(Z,{label:`Audio heard`,value:me}),d(Z,{label:`Total distance`,value:ge}),d(Z,{label:`First seen`,value:ve}),d(Z,{label:`Last seen`,value:ye}),d(Z,{label:`Track`,value:t.trackId,mono:!0})]})]}),d(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:d(`span`,{title:i?void 0:Nt,children:r(w,{variant:`secondary`,onClick:se,disabled:!i||h.isPending,children:[h.isPending?d(G,{className:`h-3.5 w-3.5 animate-spin`}):d(Ae,{className:`h-3.5 w-3.5`}),` `,`Delete track`]})})})]})})}var Gt=`pipeline-analytics`,Kt=`debug.listTracks`,qt=`debug.analyze`,Jt=`/addon/pipeline-analytics/debug-export`;function Yt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Q(e,t){let n=e[t];return typeof n==`string`?n:null}function $(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Xt(e,t){let n=e[t];return typeof n==`boolean`?n:null}function Zt(e){return e===`error`||e===`warn`||e===`info`}function Qt(e){if(!Yt(e))return null;let t=Q(e,`code`),n=Q(e,`detail`),r=e.severity;return t===null||n===null||!Zt(r)?null:{code:t,severity:r,detail:n}}function $t(e){if(!Yt(e))return null;let t=Q(e,`trackId`),n=$(e,`deviceId`),r=Q(e,`className`),i=$(e,`firstSeen`),a=$(e,`lastSeen`),o=$(e,`durationMs`),s=Xt(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=Q(e,`label`),l=Q(e,`subLabel`),u=Q(e,`previewMissReason`),d=Xt(e,`markForTrain`),f=Xt(e,`favourited`);return{trackId:t,deviceId:n,className:r,...c===null?{}:{label:c},...l===null?{}:{subLabel:l},firstSeen:i,lastSeen:a,durationMs:o,active:s,timestamp:i,windowMs:o,importance:$(e,`importance`)??0,bestEventId:Q(e,`bestEventId`)??``,...d===null?{}:{markForTrain:d},...f===null?{}:{favourited:f},debug:!0,...u===null||u.length===0?{}:{previewMissReason:u}}}function en(e){let t=$t(e);if(t===null||!Yt(e))return null;let n=$(e,`mediaCount`),r=$(e,`eventCount`),i=$(e,`positionCount`);if(n===null||r===null||i===null)return null;let a=e.mediaKinds,o=e.findings;if(!Array.isArray(a)||!Array.isArray(o))return null;let s=a.filter(e=>typeof e==`string`),c=[];for(let e of o){let t=Qt(e);t!==null&&c.push(t)}let l=e.thumbnailProvenance;return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c,...rt(l)?{thumbnailProvenance:l}:{}}}function tn(e){if(!Yt(e))return null;let t=Xt(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=$t(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function nn(e){if(!Yt(e))return null;let t=e.reports,n=e.vanished;if(!Array.isArray(t)||!Array.isArray(n))return null;let r=[];for(let e of t){let t=en(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var rn={MEDIA_EVICTED_OR_NEVER:`no media`,MISSING_KEYFRAME:`no keyframe`,MISSING_FIRSTFRAME:`no first frame`,MISSING_LASTFRAME:`no last frame`,MISSING_THUMBNAIL:`no thumbnail`,MISSING_BEST_CROP:`no crop`,SHORT_TRACK:`very short`,ZERO_EVENTS:`no events`,ZERO_POSITIONS:`no trajectory`,NO_PERIODIC_SNAPSHOTS:`no snapshots`,LASTFRAME_STALE:`stale last frame`,MEDIA_STOPPED_EARLY:`media stopped early`,NO_BEST_EVENT:`no best event`,LOW_BEST_SCORE:`low score`,BEST_SHOT_STANDIN:`stand-in best shot`,BEST_SHOT_RASTER:`low-res best shot`};function an(e){return rn[e]??e}var on={error:0,warn:1,info:2};function sn(e){return e.toSorted((e,t)=>on[e.severity]-on[t.severity]||e.code.localeCompare(t.code))}function cn(e){return e.length===0?Jt:`${Jt}?deviceIds=${e.join(`,`)}`}function ln(e,t){return`${String(e)}:${t}`}function un(e,t){let n=[],r=new Set;for(let i of e){let e=ln(i.deviceId,i.trackId);!t.has(e)||r.has(e)||(r.add(e),n.push({deviceId:i.deviceId,trackId:i.trackId}))}return n}n();var dn=`all`,fn=`The server answered in a shape this build does not understand.`,pn={error:`danger`,warn:`warning`,info:`info`};function mn({findings:e}){return e.length===0?d(S,{variant:`success`,children:`no anomaly found`}):d(`div`,{className:`flex flex-wrap gap-1`,children:sn(e).map(e=>d(S,{variant:pn[e.severity],title:e.detail,children:an(e.code)},e.code))})}function hn({track:e,report:t,analyzing:n}){let i=st(t?.previewMissReason??e.previewMissReason);return r(`div`,{className:`space-y-1 border-t border-border pt-1.5`,children:[t===void 0?d(`span`,{className:`text-[10px] text-foreground-subtle`,children:n?`analysing…`:`not analysed`}):r(s,{children:[d(mn,{findings:t.findings}),r(`p`,{className:`text-[10px] text-foreground-subtle`,title:t.mediaKinds.length>0?t.mediaKinds.join(`, `):`no media of any kind`,children:[String(t.mediaCount),` media · `,String(t.eventCount),` events ·`,` `,String(t.positionCount),` positions`]})]}),i!==null&&d(`p`,{className:`text-[10px] text-foreground-subtle`,title:i.raw,children:i.sentence})]})}function gn(){let e=p(),[t,n]=u(dn),[i,s]=u(!1),[c,l]=u(null),[f,m]=u(new Set),[h,g]=u(null),[_,v]=u(null),[x,S]=u(null),[T,E]=u([]),D=wt(),k=y({isCamera:!0,projection:`slim`}),A=a(()=>[{value:dn,label:`All cameras`},...(k.data??[]).map(e=>({value:String(e.id),label:e.name}))],[k.data]),j=a(()=>{let e=new Map;for(let t of k.data??[])e.set(t.id,t.name);return e},[k.data]),M=e=>j.get(e)??`Camera ${String(e)}`,N=a(()=>t===dn?[]:[Number.parseInt(t,10)],[t]),P=o({queryKey:[`events-debug`,`list`,N],queryFn:async()=>tn(await e.trpcClient.addons.custom.mutate({addonId:Gt,action:Kt,input:N.length===0?{}:{deviceIds:N}}))}),F=a(()=>(P.data?.tracks??[]).map(e=>e.trackId),[P.data]),I=o({queryKey:[`events-debug`,`analyze`,F],enabled:F.length>0,queryFn:async()=>nn(await e.trpcClient.addons.custom.mutate({addonId:Gt,action:qt,input:{trackIds:F}}))}),ee=a(()=>{let e=new Map;for(let t of I.data?.reports??[])e.set(t.trackId,t);return e},[I.data]),L=P.data?.tracks??[],R=P.data===null||I.data===null,z=()=>{P.refetch(),I.refetch()},te=e=>{m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},B=()=>{m(new Set(L.map(e=>ln(e.deviceId,e.trackId))))},ne=()=>m(new Set),V=async(e,t)=>{let n=e===`analyzed`?{debug:!1}:{favourited:!0},r=0,i=[];for(let e of t)try{await D.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,flags:n}),r+=1}catch{i.push(e.trackId)}return{applied:r,refused:i}},H=e=>{if(!q||_!==null)return;let t=un(L,f);t.length!==0&&(v(e),S(null),(async()=>{let n=await V(e,t);v(null);let r=new Set(n.refused);m(new Set(t.filter(e=>r.has(e.trackId)).map(e=>ln(e.deviceId,e.trackId)))),e===`analyzed`&&E(t.filter(e=>!r.has(e.trackId))),n.refused.length>0&&S(`${String(n.refused.length)} of ${String(t.length)} were refused by the server and are still selected. Check the hub log.`),P.refetch()})())},re=()=>{let e=T;e.length===0||_!==null||(v(`analyzed`),S(null),(async()=>{for(let t of e)try{await D.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,flags:{debug:!0}})}catch{S(`Some tracks could not be re-marked. Refresh and try again.`)}v(null),E([]),P.refetch()})())},U=async()=>{s(!0),l(null);try{await Le(cn(N),`camstack-debug.zip`)}catch(e){l(e instanceof Error?e.message:`Export failed.`)}finally{s(!1)}},W=_!==null;return d(Fe,{children:r(`section`,{className:`space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`div`,{className:`w-44`,children:d(C,{value:t,options:A,onChange:e=>n(e.target.value)})}),r(w,{variant:`secondary`,onClick:z,disabled:P.isFetching,children:[P.isFetching?d(G,{className:`h-3.5 w-3.5 animate-spin`}):d(ye,{className:`h-3.5 w-3.5`}),`Refresh`]}),r(w,{onClick:()=>void U(),disabled:i||L.length===0,children:[i?d(G,{className:`h-3.5 w-3.5 animate-spin`}):d(oe,{className:`h-3.5 w-3.5`}),`Export all (`,String(L.length),`)`]}),L.length>0&&f.size<L.length&&d(w,{variant:`ghost`,onClick:B,children:`Select all`})]}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`A `,d(`code`,{children:`debug`}),` mark does not pin retention — this lists the marked tracks that still exist. A track whose media was evicted shows as missing media. Use `,d(`strong`,{children:`Keep`}),` `,`to hold a selection against pruning while you investigate, and `,d(`strong`,{children:`Analyzed`}),` `,`to un-mark the ones you are finished with.`]}),P.isError&&d(O,{message:`Could not load the marked tracks.`}),R&&!P.isError&&d(O,{message:fn}),c!==null&&d(O,{message:c}),x!==null&&d(O,{message:x}),P.data?.truncated===!0&&d(O,{message:`A camera filled the per-camera cap — some marked tracks are not listed. Un-mark a few, or filter to one camera.`}),(I.data?.vanished.length??0)>0&&r(`p`,{className:`text-xs text-foreground-subtle`,children:[String(I.data?.vanished.length),` marked track(s) were evicted between the list and the analysis.`]}),f.size>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[r(`span`,{className:`text-xs font-medium text-foreground`,children:[String(f.size),` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[d(`span`,{title:q?void 0:`Track flags arrive with the next server update`,children:r(w,{variant:`secondary`,onClick:()=>H(`keep`),disabled:!q||W,children:[_===`keep`?d(G,{className:`h-3.5 w-3.5 animate-spin`}):d(Se,{className:`h-3.5 w-3.5`}),` `,`Keep`]})}),d(`span`,{title:q?void 0:`Track flags arrive with the next server update`,children:r(w,{onClick:()=>H(`analyzed`),disabled:!q||W,children:[_===`analyzed`?d(G,{className:`h-3.5 w-3.5 animate-spin`}):d(Pe,{className:`h-3.5 w-3.5`}),` `,`Analyzed`]})}),d(w,{variant:`ghost`,onClick:ne,disabled:W,children:d(Me,{className:`h-3.5 w-3.5`})})]})]}),T.length>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-border bg-surface px-3 py-2`,children:[r(`span`,{className:`text-xs text-foreground`,children:[String(T.length),` track(s) marked analyzed and removed from this list.`]}),r(w,{variant:`ghost`,onClick:re,disabled:W,children:[d(Ce,{className:`h-3.5 w-3.5`}),` Undo`]}),d(w,{variant:`ghost`,onClick:()=>E([]),disabled:W,children:d(Me,{className:`h-3.5 w-3.5`})})]}),P.isLoading?d(b,{children:d(`div`,{className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`Loading…`})}):L.length===0?d(b,{children:r(`div`,{className:`flex flex-col items-center gap-2 px-3 py-8 text-center`,children:[d(Ve,{className:`h-5 w-5 text-foreground-subtle`}),d(`p`,{className:`text-xs text-foreground-subtle`,children:`No track is marked for debug. Mark one from a track's actions to see it here.`})]})}):d(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:L.map(e=>{let t=ee.get(e.trackId);return d(lt,{row:e,cameraName:M(e.deviceId),nowMs:e.lastSeen,selected:f.has(ln(e.deviceId,e.trackId)),onToggleSelect:te,onOpenDetail:g,...t?.thumbnailProvenance===void 0?{}:{provenance:t.thumbnailProvenance},footer:d(hn,{track:e,report:t,analyzing:I.isFetching})},ln(e.deviceId,e.trackId))})}),h&&d(Wt,{row:h,cameraName:M(h.deviceId),deleteAvailable:Mt,onClose:()=>g(null),onDeleted:()=>{g(null),P.refetch()},onFlagsChanged:e=>{e.debug||(g(null),P.refetch())}})]})})}var _n=200,vn=3e4;function yn(e){let t=p(),n=c({queries:e.deviceIds.map(n=>({queryKey:[`events-feed`,n,e.since,e.until,e.minImportance??null,e.classFilter??null],staleTime:vn,refetchInterval:vn,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEvents.query({deviceId:n,since:e.since,until:e.until,limit:_n,...e.minImportance===void 0?{}:{minImportance:e.minImportance},...e.classFilter===void 0?{}:{classFilter:e.classFilter}})).map(e=>({...e,deviceId:n}))}))});return{rows:Ze(Xe(n.map(e=>e.data??[])),`importance`),isLoading:n.some(e=>e.isLoading)}}n();var bn=[`events-feed`],xn=2e3;function Sn(n){let r=l(),i=n?.paused===!0,a=t(r);a.current=r;let o=t(i);o.current=i;let[s,c]=u(!1),d=e(()=>{a.current.invalidateQueries({queryKey:bn})},[]),p=t(void 0);p.current||=ve({delayMs:xn,invalidate:()=>{o.current?c(!0):d()}}),f(()=>()=>p.current?.cancel(),[]),f(()=>{i||!s||(c(!1),d())},[i,s,d]);let m=e(()=>{c(!1),d()},[d]);return D(U.PipelineAnalyticsDetectionEvent,()=>{p.current?.trigger()}),D(U.PipelineAnalyticsTrackEnded,()=>{p.current?.trigger()}),{pending:s,refreshNow:m}}n();function Cn({groups:e,selected:t,onChange:n,loading:i=!1}){let{t:o}=Ne(),[s,c]=u(!1),[l,f]=u(``),[p,m]=u(new Set),h=l.trim().toLowerCase(),g=e=>h.length===0||N(e,o).toLowerCase().includes(h),_=a(()=>e.map(e=>({macro:e.macro,subs:e.subs.filter(t=>g(t)||g(e.macro))})).filter(e=>g(e.macro)||e.subs.length>0),[e,h]),v=e=>m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),y=e=>{let r=new Set(t),i=t.has(e.macro.kind)&&e.subs.every(e=>t.has(e.kind)),a=[e.macro.kind,...e.subs.map(e=>e.kind)];if(i)for(let e of a)r.delete(e);else for(let e of a)r.add(e);n(r)},b=e=>{let r=new Set(t);r.has(e)?r.delete(e):r.add(e),n(r)},x=()=>n(new Set),S=t.size;return r(`div`,{className:`relative`,children:[r(`button`,{type:`button`,onClick:()=>c(e=>!e),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${S>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[d(qe,{className:`h-3.5 w-3.5`}),S>0?`Kinds (${String(S)})`:`Kinds`,d(Oe,{className:`h-3 w-3`})]}),s&&r(`div`,{className:`absolute z-20 mt-1 max-h-80 w-64 overflow-auto rounded-md border border-border bg-surface p-2 shadow-lg`,children:[r(`div`,{className:`mb-2 flex items-center gap-1 rounded border border-border px-1.5`,children:[d(je,{className:`h-3.5 w-3.5 text-foreground-subtle`}),d(`input`,{type:`text`,value:l,onChange:e=>f(e.target.value),placeholder:`Search kinds…`,className:`w-full bg-transparent py-1 text-xs outline-none`}),S>0&&d(`button`,{type:`button`,onClick:x,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),_.length===0&&d(`div`,{className:`px-1 py-2 text-[11px] text-foreground-subtle`,children:i?`Loading kinds…`:h.length>0?`No kind matches that search.`:`These cameras advertise no event kinds.`}),_.map(e=>{let n=z(e.macro.iconId),i=p.has(e.macro.kind)||h.length>0,a=t.has(e.macro.kind);return r(`div`,{className:`mb-0.5`,children:[r(`div`,{className:`flex items-center gap-1`,children:[e.subs.length>0?d(`button`,{type:`button`,onClick:()=>v(e.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Expand`,children:d(i?Oe:Te,{className:`h-3 w-3`})}):d(`span`,{className:`w-3`}),r(`label`,{className:`flex flex-1 cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[d(`input`,{type:`checkbox`,checked:a,onChange:()=>y(e),className:`accent-primary`}),d(n,{className:`h-3.5 w-3.5`,style:{color:e.macro.color}}),d(`span`,{className:`font-medium`,children:N(e.macro,o)})]})]}),i&&e.subs.map(e=>{let n=z(e.iconId);return r(`label`,{className:`ml-5 flex cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[d(`input`,{type:`checkbox`,checked:t.has(e.kind),onChange:()=>b(e.kind),className:`accent-primary`}),d(n,{className:`h-3.5 w-3.5`,style:{color:e.color}}),d(`span`,{children:N(e,o)})]},e.kind)})]},e.macro.kind)})]})]})}function wn(e,t){let n=new Map;for(let r of e)if(!(t.size>0&&!t.has(r.deviceId)))for(let e of r.kinds)n.has(e.kind)||n.set(e.kind,e);return n}function Tn(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var En=new Set([`detection`,`package`]);function Dn(e,t){return[...wn(e,t).values()].filter(e=>e.parentKind===null&&En.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function On(e,t){let n=wn(e,t),r=new Map,i=new Map;for(let e of n.values()){if(e.parentKind===null){i.set(e.kind,e);continue}let t=r.get(e.parentKind);t===void 0?r.set(e.parentKind,[e]):t.push(e)}for(let[e,t]of r){if(i.has(e))continue;let n=t[0];n!==void 0&&i.set(e,Tn(e,n))}return[...i.values()].map(e=>({macro:e,subs:[...r.get(e.kind)??[]].sort((e,t)=>e.label.localeCompare(t.label))})).sort((e,t)=>e.macro.label.localeCompare(t.macro.label))}n();function kn(){let[n,r]=u(!1),i=t(null),[a,o]=u(0),s=e(e=>{i.current!==e&&(i.current=e,o(e=>e+1))},[]);return f(()=>{let e=i.current;if(!e||typeof IntersectionObserver>`u`){r(!1);return}let t=new IntersectionObserver(e=>{let t=e[e.length-1];t&&r(!t.isIntersecting)},{rootMargin:`64px 0px 0px 0px`,threshold:0});return t.observe(e),()=>t.disconnect()},[a]),{ref:s,scrolledPast:n}}n();var An=[`events-feed`],jn=60,Mn=[{value:`importance`,label:`Importance`,icon:Be},{value:`time`,label:`Recent`,icon:ie}];function Nn(){let e=l(),[t,n]=u(_e),[i,o]=u(new Set),[c,p]=u(new Set),[m,h]=u(0),[g,_]=u(`time`),[v,b]=u(new Set),[x,S]=u(null),[C,T]=u(()=>Date.now());f(()=>{let e=setInterval(()=>T(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:E,until:D}=a(()=>tt({fromMs:t.fromMs,toMs:t.toMs},C),[t.fromMs,t.toMs,C]),O=kn(),{pending:k,refreshNow:A}=Sn({paused:x!==null||v.size>0||O.scrolledPast}),{data:j=[]}=y({isCamera:!0,projection:`slim`}),M=a(()=>j.map(e=>e.id),[j]),{data:N,isLoading:F}=P({deviceIds:M},{enabled:M.length>0,staleTime:5*6e4}),I=a(()=>On(N??[],i),[N,i]),ee=Ft(),L=ee.isPending,{rows:R,isLoading:z}=yn({deviceIds:M,since:E,until:D,minImportance:m>0?m:void 0,classFilter:c.size===1?[...c][0]:void 0}),te=a(()=>{let e=new Map;for(let t of j??[])e.set(t.id,t.name);return e},[j]),B=e=>te.get(e)??`Camera #${String(e)}`,ne=a(()=>ce(R).map(e=>({id:e,name:B(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[R,te]),V=a(()=>Ze(Qe(R,{cameras:i,classes:c,minImportance:m}),g),[R,i,c,m,g]),H=me(V,jn,a(()=>JSON.stringify([[...i].sort((e,t)=>e-t),[...c].sort(),m,g,E,D]),[i,c,m,g,E,D])),re=()=>{e.invalidateQueries({queryKey:An})},U=()=>b(new Set);function W(e){b(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function ie(){if(v.size===0||!Mt)return;let e=et(R,v),t=[...e.values()].reduce((e,t)=>e+t.length,0);if(t===0||!window.confirm(`Delete ${String(t)} track${t===1?``:`s`} and all their media? This cannot be undone.`))return;let n=[...e];Promise.allSettled(n.map(([e,t])=>ee.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{re();let t=[],r=new Set;if(e.forEach((e,i)=>{let a=n[i];if(!a)return;let[o,s]=a;if(e.status===`fulfilled`)for(let e of s)r.add($e(o,e));else t.push(o)}),b(e=>{let t=new Set(e);for(let e of r)t.delete(e);return t}),t.length>0){let e=t.map(e=>B(e)).join(`, `);window.alert(`Failed to delete tracks on: ${e}. They remain selected — retry, or check the server logs.`)}})}let ae=V.length!==R.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d(ge,{onChange:n}),d(de,{cameras:ne,selected:i,onChange:o}),d(Cn,{groups:I,selected:c,onChange:p,loading:F}),r(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[d(`span`,{children:`Min score`}),d(`input`,{type:`range`,min:0,max:1,step:.05,value:m,onChange:e=>h(Number(e.target.value)),className:`h-1 w-24 cursor-pointer accent-primary`,"aria-label":`Minimum importance`}),d(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(m*100)})]}),d(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Mn.map(e=>{let t=e.icon;return r(`button`,{type:`button`,onClick:()=>_(e.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${g===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[d(t,{className:`h-3.5 w-3.5`}),` `,e.label]},e.value)})}),!z&&d(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:ae?`${String(V.length)} of ${String(R.length)} events`:`${String(V.length)} event${V.length===1?``:`s`}`})]}),v.size>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[r(`span`,{className:`text-xs font-medium text-foreground`,children:[v.size,` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[d(`span`,{title:Mt?void 0:`Track deletion arrives with the next server update`,children:r(w,{variant:`secondary`,onClick:ie,disabled:!Mt||L,children:[L?d(G,{className:`h-3.5 w-3.5 animate-spin`}):d(Ae,{className:`h-3.5 w-3.5`}),` `,`Delete`]})}),d(w,{variant:`ghost`,onClick:U,disabled:L,children:d(Me,{className:`h-3.5 w-3.5`})})]})]}),z&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[d(G,{className:`h-4 w-4 animate-spin`}),` Loading events…`]}),!z&&V.length===0&&d(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No key events in this window.`}),k&&d(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:d(`button`,{type:`button`,onClick:A,className:`rounded-full border border-primary/40 bg-surface px-3 py-1 text-[11px] font-medium text-primary shadow-sm hover:bg-primary/10`,children:`New events — refresh`})}),!z&&V.length>0&&r(s,{children:[d(`div`,{ref:O.ref,"aria-hidden":!0,className:`h-0`}),d(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:H.pageItems.map(e=>d(lt,{row:e,cameraName:B(e.deviceId),nowMs:C,selected:v.has($e(e.deviceId,e.trackId)),onToggleSelect:W,onOpenDetail:S},$e(e.deviceId,e.trackId)))}),d(se,{currentPage:H.page,totalItems:H.totalItems,pageSize:H.pageSize,onPageChange:H.setPage,itemNoun:`events`})]}),x&&d(Wt,{row:x,cameraName:B(x.deviceId),deleteAvailable:Mt,onClose:()=>S(null),onDeleted:()=>{re(),S(null)},onFlagsChanged:e=>{S(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug,favourited:e.favourited}:t)}})]})}n();var Pn=50,Fn=350,In=[{value:.2,label:`Loose`},{value:.25,label:`Balanced`},{value:.3,label:`Strict`}];function Ln(e){return{id:e.id,trackId:e.trackId??e.id,deviceId:e.deviceId,timestamp:e.timestamp,className:e.className,label:e.label,subLabel:e.subLabel,importance:e.importance??0,bestEventId:e.mediaKey??e.trackId??e.id,windowMs:void 0}}function Rn({onActiveChange:e}){let[t,n]=u(``),[i,o]=u(.2),[s,c]=u(null),[l,p]=u(null),[m,h]=u(null),g=F(t,Fn).trim(),_=g.length>0;f(()=>{e(_)},[_,e]);let[v,b]=u(()=>Date.now());f(()=>{let e=setInterval(()=>b(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:x=[]}=y({isCamera:!0,projection:`slim`}),S=a(()=>{let e=new Map;for(let t of x)e.set(t.id,t.name);return e},[x]),C=e=>S.get(e)??`Camera #${String(e)}`,w=a(()=>x.map(e=>e.id),[x]),{data:E}=P({deviceIds:w},{enabled:w.length>0,staleTime:5*6e4}),D=a(()=>Dn(E??[],new Set(l===null?[]:[l])),[E,l]);f(()=>{s!==null&&(D.some(e=>e.kind===s)||c(null))},[D,s]);let{data:O,isFetching:k,isError:A,error:j}=T({text:g,minScore:i,limit:Pn,classFilter:s??void 0,deviceId:l??void 0},{enabled:_}),M=a(()=>[...O??[]].sort((e,t)=>t.score-e.score).map(e=>({...Ln(e),score:e.score})),[O]);function I(e){c(t=>t===e?null:e)}return r(`div`,{className:`space-y-3`,children:[r(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(`div`,{className:`relative min-w-[16rem] flex-1`,children:[d(je,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),d(`input`,{type:`text`,value:t,onChange:e=>n(e.target.value),placeholder:`Semantic search — describe what you're looking for…`,className:`h-9 w-full rounded-md border border-border bg-background pl-8 pr-8 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary`,"aria-label":`Semantic event search`}),t&&d(`button`,{type:`button`,onClick:()=>n(``),className:`absolute right-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Clear search`,children:d(Me,{className:`h-3.5 w-3.5`})})]}),k&&_&&d(G,{className:`h-4 w-4 shrink-0 animate-spin text-foreground-subtle`})]}),r(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[d(`div`,{className:`flex items-center gap-1`,children:D.map(e=>d(`button`,{type:`button`,onClick:()=>I(e.kind),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${s===e.kind?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:N(e)},e.kind))}),r(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[d(`span`,{children:`Camera`}),r(`select`,{value:l===null?``:String(l),onChange:e=>p(e.target.value===``?null:Number(e.target.value)),className:`h-7 rounded-md border border-border bg-background px-1.5 text-xs text-foreground focus:border-primary focus:outline-none`,"aria-label":`Filter by camera`,children:[d(`option`,{value:``,children:`All`}),x.map(e=>d(`option`,{value:String(e.id),children:e.name},e.id))]})]}),r(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[d(`span`,{children:`Match`}),d(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:In.map(e=>d(`button`,{type:`button`,onClick:()=>o(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${i===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:`Minimum CLIP score ${e.value.toFixed(2)}`,children:e.label},e.value))})]}),_&&!k&&!A&&r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[M.length,` match`,M.length===1?``:`es`]})]})]}),_&&r(`div`,{className:`space-y-3`,children:[A&&r(`p`,{className:`py-4 text-xs text-danger`,children:[`Search failed: `,j instanceof Error?j.message:`unknown error`,`. Check that the CLIP embedding step is enabled.`]}),!A&&k&&M.length===0&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[d(G,{className:`h-4 w-4 animate-spin`}),` Searching…`]}),!A&&!k&&M.length===0&&r(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:[`No semantic matches for “`,g,`”. Try a looser match threshold or a different phrasing.`]}),!A&&M.length>0&&d(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:M.map(e=>d(lt,{row:e,cameraName:C(e.deviceId),nowMs:v,score:e.score,onOpenDetail:h},e.id))})]}),m&&d(Wt,{row:m,cameraName:C(m.deviceId),deleteAvailable:Mt,onClose:()=>h(null),onDeleted:()=>h(null)})]})}var zn=15e3;function Bn(e){let t=p(),n=c({queries:e.map(e=>({queryKey:[`stationary-objects`,e],staleTime:zn,refetchInterval:zn,queryFn:async()=>((await t.trpcClient.zoneAnalytics.getCurrentSnapshot.query({deviceId:e}))?.stationaryObjects??[]).map(t=>({...t,deviceId:e}))}))});return{rows:n.flatMap(e=>e.data??[]).toSorted((e,t)=>t.becameStationaryAt-e.becameStationaryAt),isLoading:n.some(e=>e.isLoading)}}n();function Vn(e,t){let n=Math.max(0,Math.round((e-t)/6e4));if(n<1)return`just now`;if(n<60)return`${String(n)}m`;let r=Math.floor(n/60);return`${String(r)}h ${String(n%60)}m`}function Hn({row:e,cameraName:t,nowMs:n}){let i=e.keyFrameMediaKey?.startsWith(`track:`)?e.keyFrameMediaKey.split(`:`)[1]:e.keyFrameMediaKey,a=Ie(i?`${Re}/${i}`:void 0);return r(`div`,{className:`flex flex-col overflow-hidden rounded-md border border-border bg-surface`,children:[r(`div`,{className:`relative aspect-video overflow-hidden bg-surface-hover`,children:[a.src?d(`img`,{src:a.src,alt:`Parked ${e.className} on ${t}`,className:`h-full w-full object-cover`}):d(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:d(Ke,{className:`h-6 w-6`})}),d(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-medium capitalize text-white`,children:e.label??e.className})]}),r(`div`,{className:`flex flex-col gap-0.5 p-1.5`,children:[d(`span`,{className:`truncate text-[11px] text-foreground`,children:t}),r(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`parked `,Vn(n,e.becameStationaryAt)]})]})]})}function Un(){let[e,t]=u(!1),n=Date.now(),{data:i=[]}=y({isCamera:!0,projection:`slim`}),o=a(()=>i.map(e=>e.id),[i]),s=a(()=>{let e=new Map;for(let t of i)e.set(t.id,t.name);return e},[i]),{rows:c}=Bn(o);return c.length===0?null:r(`div`,{className:`rounded-md border border-border bg-surface/40`,children:[r(`button`,{type:`button`,onClick:()=>t(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,children:[d(e?Oe:Te,{className:`h-4 w-4 text-foreground-subtle`}),d(Ke,{className:`h-4 w-4 text-foreground-subtle`}),d(`span`,{className:`text-sm font-semibold text-foreground`,children:`Stationary`}),d(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:c.length}),d(`span`,{className:`ml-2 text-[11px] text-foreground-subtle`,children:`Parked objects — kept out of the event feed`})]}),e&&d(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:c.map(e=>d(Hn,{row:e,cameraName:s.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:n},e.id))})]})}n();function Wn(){let[e,t]=u(!1);return d(Fe,{children:r(`section`,{className:`space-y-3`,children:[d(Rn,{onActiveChange:t}),!e&&d(Un,{}),!e&&d(Nn,{})]})})}var Gn=[`person`,`vehicle`,`animal`,`package`,`face`,`plate`],Kn=new Set(Gn);function qn(e){let t=e?.trim().toLowerCase();return t===void 0||t===``?null:Kn.has(t)?`"${t}" is a macro class, not a label — person / postman / Marco are three different tiers`:null}function Jn({annotations:e,selectedIndex:t,onSelect:n,onChange:i,onDelete:a}){return e.length===0?r(`p`,{className:`text-[11px] text-foreground-subtle p-3`,children:[`No subject on this frame yet. Drag on the image to draw one, or ask the pipeline for a proposal. Annotate `,d(`strong`,{children:`every`}),` subject — a frame with one box and three unlabelled people teaches the model that two thirds of the people in it are background.`]}):d(`ul`,{className:`divide-y divide-border`,children:e.map((e,o)=>{let s=o===t,c=qn(e.label),l=qn(e.subLabel);return r(`li`,{className:`p-2.5 space-y-1.5 ${s?`bg-surface-hover`:``}`,onFocus:()=>{n(o)},children:[r(`div`,{className:`flex items-center gap-2`,children:[d(C,{className:`w-28`,value:e.macroClass,options:Gn.map(e=>({value:e,label:e})),onChange:e=>{let t=Gn.find(t=>t===e.target.value);t!==void 0&&i(o,{macroClass:t})}}),d(C,{className:`w-32`,value:e.kind,options:[{value:`subject`,label:`subject`},{value:`model_error`,label:`model error`}],onChange:e=>{i(o,{kind:e.target.value===`model_error`?`model_error`:`subject`})}}),e.source===`assist`&&r(S,{variant:`info`,children:[e.assistModelId??`assist`,e.assistScore===void 0?``:` ${e.assistScore.toFixed(2)}`]}),d(w,{variant:`ghost`,size:`sm`,"aria-label":`Delete this subject`,onClick:()=>{a(o)},children:d(Ae,{className:`h-3 w-3`})})]}),r(`div`,{className:`flex items-center gap-2`,children:[d(v,{className:`flex-1`,placeholder:`label (postman, van, cat…)`,value:e.label??``,onChange:e=>{i(o,{label:e.target.value})}}),d(v,{className:`flex-1`,placeholder:`sub-label (a name, a plate…)`,value:e.subLabel??``,onChange:e=>{i(o,{subLabel:e.target.value})}})]}),c!==null&&d(`p`,{className:`text-[11px] text-danger`,children:c}),l!==null&&d(`p`,{className:`text-[11px] text-danger`,children:l})]},`${String(o)}-${String(e.bbox.x)}`)})})}function Yn(e){return e.every(e=>qn(e.label)===null&&qn(e.subLabel)===null&&Kn.has(e.macroClass))}function Xn(e){return e<0?0:e>1?1:e}function Zn(e,t,n,r){if(!(e>0)||!(t>0)||!(n>0)||!(r>0))return null;let i=Math.min(e/n,t/r),a=n*i,o=r*i;return{left:(e-a)/2,top:(t-o)/2,width:a,height:o}}function Qn(e,t,n){return{x:Xn((e-n.left)/n.width),y:Xn((t-n.top)/n.height)}}function $n(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),w:Math.abs(t.x-e.x),h:Math.abs(t.y-e.y)}}function er(e){return e.w>=.01&&e.h>=.01}function tr(e,t){return{left:t.left+e.x*t.width,top:t.top+e.y*t.height,width:e.w*t.width,height:e.h*t.height}}function nr(e,t){let n=-1,r=1/0;return e.forEach((e,i)=>{if(!(t.x>=e.x&&t.x<=e.x+e.w&&t.y>=e.y&&t.y<=e.y+e.h))return;let a=e.w*e.h;a<r&&(n=i,r=a)}),n}n();function rr({imageSrc:n,imageWidth:a,imageHeight:o,boxes:s,selectedIndex:c,onSelect:l,onDraw:f}){let p=t(null),[m,h]=u({w:0,h:0}),[g,_]=u(null);i(()=>{let e=p.current;if(e===null)return;let t=new ResizeObserver(()=>{h({w:e.clientWidth,h:e.clientHeight})});return t.observe(e),h({w:e.clientWidth,h:e.clientHeight}),()=>{t.disconnect()}},[]);let v=Zn(m.w,m.h,a,o),y=e(e=>{let t=p.current;if(t===null||v===null)return null;let n=t.getBoundingClientRect();return Qn(e.clientX-n.left,e.clientY-n.top,v)},[v]);return r(`div`,{ref:p,className:`relative w-full h-full min-h-[280px] bg-surface-sunken select-none touch-none`,onPointerDown:e=>{let t=y(e);t!==null&&(e.currentTarget.setPointerCapture(e.pointerId),_({start:t,current:$n(t,t)}))},onPointerMove:e=>{if(g===null)return;let t=y(e);t!==null&&_({start:g.start,current:$n(g.start,t)})},onPointerUp:()=>{if(g===null)return;let e=g.current;_(null),er(e)?f(e):l(nr(s.map(e=>e.bbox),g.start))},children:[d(`img`,{src:n,alt:`Frame being annotated`,className:`absolute inset-0 w-full h-full object-contain pointer-events-none`}),v!==null&&s.map((e,t)=>{let n=tr(e.bbox,v),i=e.kind===`model_error`,a=t===c,o=i?`#ef4444`:a?`#22c55e`:`#3b82f6`;return d(`div`,{className:`absolute pointer-events-none`,style:{left:n.left,top:n.top,width:n.width,height:n.height,border:`${a?`2px`:`1px`} ${i?`dashed`:`solid`} ${o}`,opacity:e.source===`assist`&&!a?.65:1},children:r(`span`,{className:`absolute -top-4 left-0 text-[10px] px-1 rounded`,style:{background:o,color:`#08121f`},children:[e.label??e.macroClass,i?` ✕`:``]})},`${String(t)}-${String(e.bbox.x)}-${String(e.bbox.y)}`)}),g!==null&&v!==null&&d(`div`,{className:`absolute border border-dashed border-primary pointer-events-none`,style:tr(g.current,v)})]})}function ir(e){return e>=1e6?`${(e/1e6).toFixed(1)} MB`:`${Math.round(e/1e3)} KB`}function ar({candidates:e,copies:t,activeFrameId:n,refusals:i,isSelecting:a,onSelectCandidate:o,onOpenCopy:s,onRemoveCopy:c}){let l=new Set(t.map(e=>e.sourceMediaKey)),u=e.filter(e=>!l.has(e.mediaKey));return r(`div`,{className:`space-y-3`,children:[r(`section`,{children:[r(`h3`,{className:`text-xs font-semibold text-foreground mb-1.5`,children:[`In the dataset (`,t.length,`)`]}),t.length===0?d(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No frame copied yet. Selecting a frame copies it into retrain storage immediately — the dataset stops depending on the track's own media from that moment.`}):d(`ul`,{className:`flex flex-wrap gap-2`,children:t.map(e=>d(`li`,{children:r(`div`,{className:`rounded-md border px-2 py-1.5 text-[11px] ${e.frameId===n?`border-primary bg-surface-hover`:`border-border`}`,children:[r(`button`,{type:`button`,className:`flex items-center gap-1.5 text-left`,onClick:()=>{s(e.frameId)},children:[d(Pe,{className:`h-3 w-3 text-success`}),d(`span`,{className:`font-medium text-foreground`,children:e.sourceKind}),r(`span`,{className:`text-foreground-subtle`,children:[e.width,`×`,e.height,` · `,ir(e.sizeBytes)]})]}),r(`button`,{type:`button`,"aria-label":`Remove this frame from the dataset`,className:`mt-1 flex items-center gap-1 text-foreground-muted hover:text-danger`,onClick:()=>{c(e.frameId)},children:[d(Ae,{className:`h-3 w-3`}),`remove`]})]})},e.frameId))})]}),r(`section`,{children:[r(`h3`,{className:`text-xs font-semibold text-foreground mb-1.5`,children:[`Available frames (`,u.length,`)`]}),u.length===0?d(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.length===0?`This track has no whole, unannotated frame left — its media aged out before it was marked. Anything already copied above is still usable.`:`Every available frame is already in the dataset.`}):d(`ul`,{className:`flex flex-wrap gap-2`,children:u.map(e=>{let t=i.get(e.mediaKey);return r(`li`,{children:[r(w,{variant:`secondary`,size:`sm`,disabled:a||t!==void 0,onClick:()=>{o(e.mediaKey)},children:[a?d(G,{className:`h-3 w-3 animate-spin`}):d(t===void 0?We:fe,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:e.kind}),d(`span`,{className:`ml-1 text-foreground-subtle`,children:ir(e.sizeBytes)})]}),t!==void 0&&d(S,{variant:`danger`,className:`ml-1`,children:t})]},e.mediaKey)})})]})]})}function or(e){return e.frameCount===0?`untouched`:e.annotationCount===0?`started`:`ready`}var sr={untouched:{icon:Ue,label:`to do`,variant:`default`},started:{icon:He,label:`frames only`,variant:`info`},ready:{icon:De,label:`annotated`,variant:`success`}};function cr(e){return new Date(e).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function lr({tracks:e,isLoading:t,selectedTrackId:n,deviceNames:i,onSelect:a}){return t?r(`div`,{className:`flex items-center gap-2 p-4 text-xs text-foreground-subtle`,children:[d(G,{className:`h-3.5 w-3.5 animate-spin`}),`Loading staging tracks…`]}):e.length===0?d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`Nothing in staging. Mark a track for training from the viewer or the Events grid and it appears here.`}):d(`ul`,{className:`divide-y divide-border`,children:e.map(e=>{let t=sr[or(e)],o=t.icon;return d(`li`,{children:r(`button`,{type:`button`,onClick:()=>{a(e)},className:`w-full text-left px-3 py-2 flex items-start gap-2 hover:bg-surface-hover ${e.trackId===n?`bg-surface-hover`:``}`,children:[d(o,{className:`h-3.5 w-3.5 mt-0.5 shrink-0 text-foreground-subtle`}),r(`span`,{className:`min-w-0 flex-1`,children:[r(`span`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs font-medium text-foreground truncate`,children:e.label??e.className}),d(S,{variant:t.variant,children:t.label})]}),r(`span`,{className:`block text-[11px] text-foreground-subtle truncate`,children:[i.get(e.deviceId)??`Camera ${String(e.deviceId)}`,` ·`,` `,cr(e.lastSeen)]}),r(`span`,{className:`block text-[11px] text-foreground-muted`,children:[e.frameCount,` frame`,e.frameCount===1?``:`s`,` ·`,` `,e.annotationCount,` subject`,e.annotationCount===1?``:`s`]})]})]})},e.trackId)})})}n();var ur=`person`;function dr(){let[t,n]=u(null),[i,o]=u(null),[c,l]=u([]),[p,h]=u(-1),[g,v]=u(new Map),[b,x]=u(null),C=y({projection:`slim`,isCamera:!0}),T=a(()=>{let e=new Map;for(let t of C.data??[])e.set(t.id,t.name);return e},[C.data]),E=re({}),D=ne({trackId:t?.trackId??``},{enabled:t!==null}),O=A({trackId:t?.trackId??``},{enabled:t!==null}),k=R({frameId:i??``},{enabled:i!==null}),j=_(),M=B(),N=H(),P=V(),F=te(),I=m();f(()=>{if(i===null){l([]);return}l((O.data??[]).filter(e=>e.mediaKey===i).map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},...e.subLabel===void 0?{}:{subLabel:e.subLabel},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))),h(-1)},[i,O.data]),f(()=>{let e=D.data?.copies??[];i===null&&e.length>0&&o(e[0].frameId)},[D.data,i]);let ee=e(e=>{n(e),o(null),l([]),v(new Map),x(null)},[]),L=e(async e=>{if(t===null)return;let n=await j.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,mediaKeys:[e]});if(n.refused.length>0){let e=new Map(g);for(let t of n.refused)e.set(t.sourceMediaKey,t.reason);v(e)}n.copied.length>0&&o(n.copied[0].frameId),await D.refetch(),await E.refetch()},[t,j,g,D,E]),z=e(async e=>{t!==null&&(await M.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:e}),i===e&&o(null),await D.refetch(),await O.refetch(),await E.refetch())},[t,M,i,D,O,E]),U=e(async e=>{if(t===null||i===null)return;x(null);let n=await N.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:i,subject:e===`package`?{kind:`package`}:{kind:`objects`,modelId:`yolo26n`,minScore:.3}});if(n.kind===`refused`){x(n.reason===`no-zone`?`A package proposal runs on the zone crop only — this camera has no zone, and running the detector on the whole frame at 0.35 proposes furniture.`:`The pipeline refused: ${n.reason}${n.detail===void 0?``:` — ${n.detail}`}`);return}l(e=>[...e,...n.proposals.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))]),x(`${n.proposals.length} proposal${n.proposals.length===1?``:`s`} from ${n.modelId}`+(n.belowThreshold>0?` — ${n.belowThreshold} more were below ${n.minScore.toFixed(2)}`:``))},[t,i,N]),W=e(e=>{l(t=>[...t,{bbox:e,macroClass:ur,kind:`subject`,source:`operator`}]),h(c.length)},[c.length]),ie=e((e,t)=>{l(n=>n.map((n,r)=>r===e?{...n,...t}:n))},[]),ae=e(e=>{l(t=>t.filter((t,n)=>n!==e)),h(-1)},[]),oe=e(async()=>{t===null||i===null||(await P.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:i,annotations:c.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label!==void 0&&e.label!==``?{label:e.label}:{},...e.subLabel!==void 0&&e.subLabel!==``?{subLabel:e.subLabel}:{},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))}),await O.refetch(),await E.refetch(),x(`Annotations saved.`))},[t,i,c,P,O,E]),se=e(async()=>{if(t===null)return;let e=await F.mutateAsync({deviceId:t.deviceId,trackId:t.trackId});x(e.changed?`Track completed — it is now trained, and its own media is evictable again.`:e.reason===`no-frames-copied`?`Refused: no frame was ever copied into the dataset. Completing would let retention delete material nothing was extracted from.`:`Refused: ${e.reason??`unknown`}`),await E.refetch(),e.changed&&n(null)},[t,F,E]),ce=e(async()=>{if(t===null)return;let e=await I.mutateAsync({deviceId:t.deviceId,trackId:t.trackId});x(e.changed?`Track returned to staging. Its copies and annotations were left alone.`:`Refused: ${e.reason??`unknown`}`),await E.refetch()},[t,I,E]),le=k.data,ue=Yn(c)&&i!==null;return r(Fe,{subtitle:`Turn the tracks you marked for training into an annotated dataset. Selecting a frame copies it — the dataset never depends on media that can be swept.`,actions:t===null?null:r(`div`,{className:`flex items-center gap-2`,children:[r(w,{variant:`secondary`,size:`sm`,onClick:()=>void ce(),children:[d(Ce,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:`Back to staging`})]}),r(w,{size:`sm`,onClick:()=>void se(),children:[d(Ge,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:`Complete track`})]})]}),children:[b!==null&&d(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-xs text-foreground`,children:b}),r(`div`,{className:`grid grid-cols-1 lg:grid-cols-[minmax(0,260px)_minmax(0,1fr)] gap-4`,children:[r(`aside`,{className:`rounded-md border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-3 py-2 border-b border-border flex items-center justify-between`,children:[d(`h2`,{className:`text-xs font-semibold text-foreground`,children:`Staging`}),d(S,{children:E.data?.length??0})]}),d(lr,{tracks:E.data??[],isLoading:E.isLoading,selectedTrackId:t?.trackId??null,deviceNames:T,onSelect:ee})]}),d(`section`,{className:`space-y-3 min-w-0`,children:t===null?d(`p`,{className:`text-xs text-foreground-subtle`,children:`Pick a track from the staging list to start annotating it.`}):r(s,{children:[d(`div`,{className:`rounded-md border border-border bg-surface p-3`,children:d(ar,{candidates:D.data?.candidates??[],copies:D.data?.copies??[],activeFrameId:i,refusals:g,isSelecting:j.isPending,onSelectCandidate:e=>void L(e),onOpenCopy:o,onRemoveCopy:e=>void z(e)})}),i!==null&&r(`div`,{className:`grid grid-cols-1 xl:grid-cols-[minmax(0,1fr)_minmax(0,380px)] gap-3`,children:[d(`div`,{className:`rounded-md border border-border overflow-hidden`,children:le===void 0?r(`div`,{className:`flex items-center gap-2 p-6 text-xs text-foreground-subtle`,children:[d(G,{className:`h-3.5 w-3.5 animate-spin`}),`Loading the frame…`]}):d(rr,{imageSrc:`data:image/jpeg;base64,${le.base64}`,imageWidth:le.width,imageHeight:le.height,boxes:c,selectedIndex:p,onSelect:h,onDraw:W})}),r(`div`,{className:`rounded-md border border-border bg-surface flex flex-col min-h-0`,children:[r(`div`,{className:`px-3 py-2 border-b border-border flex items-center gap-2`,children:[d(`h2`,{className:`text-xs font-semibold text-foreground flex-1`,children:`Subjects`}),r(w,{variant:`secondary`,size:`sm`,disabled:N.isPending,onClick:()=>void U(`objects`),children:[d(ke,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:`Propose`})]}),r(w,{variant:`secondary`,size:`sm`,disabled:N.isPending,onClick:()=>void U(`package`),children:[d(ke,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:`Packages`})]})]}),d(`div`,{className:`flex-1 overflow-y-auto`,children:d(Jn,{annotations:c,selectedIndex:p,onSelect:h,onChange:ie,onDelete:ae})}),r(`div`,{className:`px-3 py-2 border-t border-border flex items-center justify-between`,children:[r(`span`,{className:`text-[11px] text-foreground-subtle`,children:[c.filter(e=>e.kind===`model_error`).length,` marked as model errors`]}),d(w,{size:`sm`,disabled:!ue||P.isPending,onClick:()=>void oe(),children:`Save frame`})]})]})]})]})})]})]})}function fr(){return d(`div`,{className:`flex flex-col p-4`,children:d(ze,{tabs:[{id:`feed`,label:`Feed`,icon:we,content:d(Wn,{})},{id:`retrain`,label:`Retrain`,icon:Ge,content:d(dr,{})},{id:`debug`,label:`Debug`,icon:Ve,content:d(gn,{})}]})})}export{fr as EventsPage};
@@ -1 +0,0 @@
1
- import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as l}from"./player-overlays-9UuGjKRi.js";import{Hr as u,Si as d,T as f,_n as ee,br as p,gi as m,i as h,jr as g,tn as _,w as v,yi as y}from"./src-eNwyjio2.js";import{t as b}from"./ProviderIcon-BXczeeUa.js";import{t as x}from"./plus-DyGAblLU.js";import{i as S,n as te,r as C,t as w}from"./ScanNetworkModal-D3jJwqnQ.js";import{t as ne}from"./refresh-cw-DTXYyRHZ.js";import{C as re,I as T,J as E,R as D,V as O,X as k,f as A,r as j,t as M,v as N,z as ie}from"./index-lupFu8MS.js";import{t as ae}from"./AdminPage-CCD07UMs.js";import"./useEventInvalidation-C3I3KCPD.js";import{t as P}from"./StatusBadge-CeptlsPG.js";import{t as F}from"./useBodyScrollLock-BDocajQE.js";t();function I(e,t){let[n,r]=o(!1);return c(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}t();function L({providerId:e,onImport:t,onSkip:r}){let{t:i}=M(),[a,l]=o(new Set),u=g(),d=u.data,f=u.isPending||!u.data&&!u.isError;c(()=>{e&&(u.isPending||u.data||u.mutate({addonId:e}))},[e,u]);function ee(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(f)return n(`div`,{className:`flex flex-col items-center py-12`,children:[s(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),s(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:i(`integrations.searchingDevices`)})]});let p=d??[];return n(`div`,{className:`space-y-4`,children:[s(`p`,{className:`text-xs text-foreground-subtle`,children:p.length>0?i(`integrations.foundDevices`,{count:p.length}):i(`integrations.noDevicesFound`)}),p.length>0&&s(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:p.map(e=>{let t=e.stableId,r=e.suggestedName??t,i=a.has(t);return n(`button`,{onClick:()=>ee(t),className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${i?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[s(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${i?`border-primary bg-primary`:`border-border`}`,children:i&&s(ie,{className:`h-3 w-3 text-primary-foreground`})}),s(O,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),s(`span`,{className:`text-xs font-medium text-foreground truncate`,children:r})]},t)})}),n(`div`,{className:`flex items-center justify-between pt-2`,children:[s(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.skip`)}),p.length>0&&n(`button`,{onClick:()=>t(Array.from(a)),disabled:a.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[i(`integrations.importSelected`),` (`,a.size,`)`]})]})]})}function R({onSelect:e,onClose:t,pendingAddonId:r=null}){let{t:i}=M(),a=E(),{data:o,isLoading:c}=y();if(c)return s(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-14 rounded-lg bg-surface animate-pulse`},e))});let l=r!==null;return n(`div`,{className:`space-y-2`,children:[(o??[]).map(o=>{let c=o.instanceMode===`unique`&&o.existingInstances.length>0,u=r===o.addonId,d=l;return n(`button`,{disabled:d,onClick:()=>{if(!d)if(c){let e=o.existingInstances[0].id;t(),a(`/integrations/${e}`)}else e(o.addonId,o.instanceMode,o.discoveryMode,o.name,o.kind,o.brokerKind,o.mode,o.canTest)},className:`flex w-full items-center gap-3 rounded-lg border border-border bg-surface p-3 text-left hover:border-foreground-subtle/30 transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[o.iconUrl?s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`img`,{src:o.iconUrl,alt:``,className:`h-5 w-5`})}):s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`span`,{className:`text-sm`,style:{color:o.color},children:`◉`})}),n(`div`,{className:`flex-1 min-w-0`,children:[s(`p`,{className:`text-xs font-semibold text-foreground`,children:o.name}),o.description&&s(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 truncate`,children:o.description})]}),u?s(re,{className:`h-4 w-4 animate-spin text-primary flex-shrink-0`}):c?n(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[s(A,{className:`h-3 w-3`}),i(`integrations.manage`)]}):s(T,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},o.addonId)}),(o??[]).length===0&&s(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:i(`integrations.noProviders`)})]})}t();function oe(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}var z=2e4;function se({open:e,onClose:t}){let{t:l}=M(),u=E(),d=a(),[f,h]=o(`picker`),[_,v]=o(null),[y,b]=o(null),[x,S]=o(`manual`),[w,ne]=o(null),[T,D]=o(``),[O,k]=o(null),[A,N]=o(null),[ie,ae]=o(!1),{data:P}=ee({addonId:_??``,nodeId:`hub`},{enabled:_!=null}),se=r(()=>P?oe(P):null,[P]),B=m({onSuccess:()=>d.invalidateQueries({queryKey:[[`integrations`]]})}),V=g(),ce=V.data;c(()=>{f!==`discovery`||!y||!_||V.isPending||V.data||V.mutate({addonId:_})},[f,y,_,V]);let H=p({onSuccess:()=>d.invalidateQueries({queryKey:[[`deviceManager`]]})});function U(e,t,n,r,i,a,o,s){if(!B.isPending){if(v(e),ae(s),S(n),D(r),N(null),o===`broker`){if(!a){N(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}ne(a),h(`broker`);return}if(o===`account`){h(`config`);return}W(e,r)}}async function W(e,n){try{let r=await B.mutateAsync({addonId:e,name:n,settings:{}});t(),J(),u(`/integrations/${r.id}?add=1`)}catch{}}async function G(e){if(_)try{let t=await B.mutateAsync({addonId:_,name:e.name,settings:e.config});b(t.id),x===`auto`||x===`both`?h(`discovery`):q(t.id)}catch{}}async function K(e){if(_)try{let t=await B.mutateAsync({addonId:_,name:T,settings:{brokerId:e}});k(t.id),b(t.id),q(t.id)}catch{}}async function le(e){if(_){for(let t of e){let e=ce?.find(e=>e.stableId===t);e&&await H.mutateAsync({addonId:_,candidate:e,...O===null?{}:{integrationId:O}})}q()}}function q(e){let n=e??y??_;t(),J(),n&&u(`/integrations/${n}`)}function J(){h(`picker`),v(null),b(null),S(`manual`),ne(null),D(``),k(null),N(null),ae(!1)}function Y(){t(),J()}F(e);let X=B.isPending,Z=I(X,z);if(!e)return null;let Q={picker:l(`integrations.newIntegration`),config:l(`integrations.configureIntegration`),discovery:l(`integrations.importDevices`),broker:l(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},ue=X?_:null,$=B.error,de=X&&!Z;return n(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:de?void 0:Y}),n(`div`,{className:`relative z-10 w-full max-w-lg max-h-[calc(85dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[n(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:Q[f]}),s(`button`,{onClick:Y,disabled:de,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:s(j,{className:`h-4 w-4`})})]}),n(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[$&&!X&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:$ instanceof Error?$.message:String($)}),f===`picker`&&n(i,{children:[A&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:A}),s(R,{onSelect:U,onClose:Y,pendingAddonId:ue})]}),f===`config`&&_&&s(te,{addonId:_,configSchema:se??null,canTest:ie,onSave:G,onBack:()=>h(`picker`)}),f===`broker`&&w&&s(C,{kind:w,onResolved:e=>{K(e)},onBack:()=>h(`picker`)}),f===`discovery`&&y&&s(L,{providerId:y,onImport:le,onSkip:q})]}),X&&n(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm px-6 text-center`,children:[s(re,{className:`h-6 w-6 animate-spin text-primary`}),s(`p`,{className:`text-xs font-medium text-foreground`,children:l(`integrations.creating`,{defaultValue:`Creating integration…`})}),!Z&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:l(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),Z&&n(i,{children:[s(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:l(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),s(`button`,{onClick:Y,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:l(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})]})}function B({integration:e,expanded:t,onToggleExpand:r}){return n(`div`,{className:`flex items-center gap-2.5`,children:[s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e.addonId)},"aria-label":t?`Collapse`:`Expand`,"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:s(t?D:T,{className:`h-3.5 w-3.5`})}),s(b,{type:e.addonId,size:`sm`}),n(`div`,{className:`flex min-w-0 flex-col`,children:[s(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),s(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function V(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>s(B,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:`Devices`,headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>`${e.deviceCount} device${e.deviceCount===1?``:`s`}`},{key:`status`,header:`Status`,headerClassName:`w-[15%]`,cell:e=>s(P,{status:e.status})}]}t();function ce(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var H=`expand`;function U(){let{t}=M(),a=E(),c=l(),[ee]=k(),[p,m]=o(!1),g=e(()=>m(!0),[]),y=e(()=>m(!1),[]),[te,C]=o(!1),re=e(()=>C(!0),[]),T=e(()=>C(!1),[]);h([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),h([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:D,isLoading:O,refetch:A}=d(void 0),{data:j,isLoading:ie,refetch:P}=u({projection:`slim`}),F=r(()=>j??[],[j]),I=r(()=>D??[],[D]),L=r(()=>{let e=new Map;for(let t of F)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[F]),R=r(()=>{let e=new Map;for(let t of f(F)){let n=t.addonId??``;n&&e.set(n,(e.get(n)??0)+1)}return e},[F]),oe=r(()=>I.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:ce(e),deviceCount:R.get(e.addonId)??0})),[I,R]),z=ee.get(H),B=e(e=>{let t=new URLSearchParams(window.location.search);t.get(H)===e?t.delete(H):t.set(H,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),U=e(e=>a(`/integrations/${e.id}`),[a]),W=e(e=>L.get(e)??null,[L]),G=e(e=>s(b,{type:e,size:`sm`}),[]),K=e(e=>a(`/devices/${String(e)}`),[a]),le=e(e=>s(v,{context:`integration-detail`,devices:F,trpc:c.trpcClient,forceAddon:e.addonId,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:G,resolveParent:W,onNavigate:K}),[F,c.trpcClient,G,W,K]),q=e(e=>z===e.addonId,[z]),J=r(()=>V({isExpanded:q,onToggleExpand:B}),[q,B]),Y=e(e=>`${e.name} ${e.addonId}`,[]),X=e(e=>e.addonId,[]),Z=e(()=>{A(),P()},[A,P]),Q=O||ie,ue=I.length>0;return n(ae,{icon:N,title:t(`nav.integrations`,`Integrations`),actions:n(i,{children:[s(`button`,{onClick:Z,disabled:Q,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:`Refresh`,children:s(ne,{className:_(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),n(`button`,{onClick:re,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the local network for devices`,children:[s(S,{className:`h-3.5 w-3.5`}),`Scan network`]}),n(`button`,{onClick:g,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[s(x,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[Q&&s(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!ue&&n(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[s(`p`,{className:`text-sm`,children:`No integrations configured.`}),s(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!Q&&ue&&s(v,{mode:`generic`,items:oe,getKey:X,getSearchText:Y,columns:J,onRowClick:U,isExpanded:q,renderExpanded:le,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),s(se,{open:p,onClose:y}),s(w,{open:te,onClose:T})]})}export{U as IntegrationsPage};
@@ -1 +0,0 @@
1
- import{K as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}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 l,Co as u,Dt as d,Ft as f,Hr as p,Lt as m,Ot as h,Rt as g,So as _,Tt as v,Vs as y,_o as b,bo as x,fo as S,go as C,ho as w,jt as T,kt as E,mo as D,po as O,vo as k,wo as A,xo as j,yo as M}from"./src-eNwyjio2.js";import{Vt as N}from"./src-DbUPImmO.js";import{a as P,i as F,n as I,o as L,r as R,t as ee}from"./face-bbox-DaCckiPf.js";import{a as te,c as ne,f as z,i as re,l as ie,m as B,n as V,o as H,p as U,r as ae,s as oe,t as W,u as se}from"./debounced-invalidate-DKj6sAUn.js";import{t as G}from"./pencil-CZejwlRX.js";import{t as ce}from"./plus-DyGAblLU.js";import{t as K}from"./square-check-big-Cx7mXraC.js";import{t as q}from"./square-De580U5i.js";import{B as J,C as Y,I as le,K as ue,R as de,o as X,r as Z,z as fe}from"./index-lupFu8MS.js";import{t as pe}from"./AdminPage-CCD07UMs.js";import{r as me,t as he}from"./authed-media-BPd_L9jr.js";var ge=ue(`badge-check`,[[`path`,{d:`M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z`,key:`3c2336`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]);t();var Q=[[`plateGallery`]];function _e({vehicleId:e}){let t=a(),{data:r,isLoading:i}=M({vehicleId:e}),o=j();function c(n){o.mutate({vehicleId:e,sampleId:n.id},{onSettled:()=>{t.invalidateQueries({queryKey:Q})}})}return i?n(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[s(Y,{className:`h-3.5 w-3.5 animate-spin`}),`Loading plates…`]}):!r||r.length===0?s(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No plates yet.`}):s(`div`,{className:`mt-2 grid grid-cols-3 gap-2 sm:grid-cols-4 md:grid-cols-6`,children:r.map(e=>n(`div`,{className:`group relative overflow-hidden rounded-md border border-border bg-surface`,children:[n(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[e.base64?s(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:e.text,className:`h-full w-full object-cover`}):s(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:s(J,{className:`h-6 w-6`})}),s(`button`,{type:`button`,onClick:()=>c(e),disabled:o.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":`Remove plate sample`,children:s(Z,{className:`h-4 w-4 text-white`})})]}),s(`p`,{className:`truncate px-1.5 py-1 text-center font-mono text-[11px] font-semibold tracking-wide text-foreground`,title:e.text,children:e.text})]},e.id))})}function ve({vehicle:e,expanded:t,onToggle:r}){let c=a(),[u,p]=o(``),[y,b]=o(!1),[x,S]=o(!1),w=_(),D=C();function O(){p(e.name),b(!0)}function k(){b(!1),p(``)}function A(){let t=u.trim();if(!t||t===e.name){k();return}w.mutate({id:e.id,name:t},{onSettled:()=>{c.invalidateQueries({queryKey:Q}),k()}})}function j(){D.mutate({id:e.id},{onSettled:()=>{c.invalidateQueries({queryKey:Q}),S(!1)}})}return n(`div`,{className:`rounded-md border border-border bg-surface`,children:[n(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[s(`div`,{className:`h-8 w-12 shrink-0 overflow-hidden rounded border border-border bg-surface-hover`,children:s(I,{mediaKey:e.coverMediaKey,base64:e.coverBase64,alt:e.name,className:`h-full w-full object-cover`,placeholder:s(`div`,{className:`flex h-full w-full items-center justify-center`,children:s(J,{className:`h-4 w-4 text-foreground-subtle`})})})}),s(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:y?n(i,{children:[s(f,{value:u,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&A(),e.key===`Escape`&&k()},className:`h-6 text-xs`,autoFocus:!0}),s(`button`,{type:`button`,onClick:A,disabled:w.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:s(fe,{className:`h-3.5 w-3.5`})}),s(`button`,{type:`button`,onClick:k,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:s(Z,{className:`h-3.5 w-3.5`})})]}):s(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),s(m,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!y&&n(`div`,{className:`flex items-center gap-1`,children:[s(`button`,{type:`button`,onClick:O,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:s(G,{className:`h-3.5 w-3.5`})}),s(`button`,{type:`button`,onClick:()=>S(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:s(X,{className:`h-3.5 w-3.5`})})]}),s(`button`,{type:`button`,onClick:r,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":t?`Collapse`:`Expand`,children:s(t?de:le,{className:`h-3.5 w-3.5`})})]}),t&&s(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:s(_e,{vehicleId:e.id})}),s(v,{open:x,onOpenChange:e=>!e&&S(!1),children:n(d,{children:[n(l,{children:[s(T,{children:`Delete vehicle`}),n(h,{children:[`Delete `,s(`strong`,{children:e.name}),` and all its plate samples? This cannot be undone.`]})]}),n(E,{children:[s(g,{variant:`secondary`,onClick:()=>S(!1),children:`Cancel`}),n(g,{variant:`danger`,onClick:j,disabled:D.isPending,children:[D.isPending?s(Y,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function ye(){let e=a(),[t,r]=o(``),i=D();function c(){let n=t.trim();n&&i.mutate({name:n},{onSettled:()=>{e.invalidateQueries({queryKey:Q}),r(``)}})}return n(`div`,{className:`flex items-center gap-2 pt-2`,children:[s(f,{placeholder:`New vehicle name…`,value:t,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`&&c()},className:`h-7 text-xs flex-1`}),n(g,{variant:`primary`,size:`sm`,onClick:c,disabled:i.isPending||!t.trim(),children:[i.isPending?s(Y,{className:`h-3.5 w-3.5 animate-spin`}):s(ce,{className:`h-3.5 w-3.5`}),`Add`]})]})}function be(){let{data:e,isLoading:t}=x(),[r,i]=o(null);function a(e){i(t=>t===e?null:e)}return t?n(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[s(Y,{className:`h-4 w-4 animate-spin`}),`Loading vehicles…`]}):n(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&s(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No vehicles enrolled yet. Add one below.`}),e?.map(e=>s(ve,{vehicle:e,expanded:r===e.id,onToggle:()=>a(e.id)},e.id)),s(ye,{})]})}function xe(e){return e==null?null:e.cropUrl!==void 0&&e.cropUrl.length>0?e.cropUrl:e.base64!==void 0&&e.base64.length>0?`data:image/jpeg;base64,${e.base64}`:null}t();var Se=[[`plateGallery`]];function Ce({plateIds:e,vehicles:t,onDone:r}){let i=a(),c=S(),u=D(),[p,m]=o(``),[_,y]=o(!1),[b,x]=o(null),C=e!==null&&e.length>0,w=e?.length??0;function O(){y(!1),m(``),x(null)}function k(){O(),r()}function A(t){!e||e.length===0||c.mutate({plateIds:[...e],vehicleId:t},{onSettled:()=>{i.invalidateQueries({queryKey:Se}),k()}})}function j(){!e||!p.trim()||u.mutate({name:p.trim()},{onSuccess:e=>{e?.id&&A(e.id)},onError:()=>{i.invalidateQueries({queryKey:Se}),k()}})}let M=c.isPending||u.isPending;return s(v,{open:C,onOpenChange:e=>!e&&k(),children:n(d,{children:[n(l,{children:[s(T,{children:w>1?`Assign ${String(w)} plates to vehicle`:`Assign plate to vehicle`}),s(h,{children:`Select an existing vehicle or create a new one.`})]}),s(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:t.map(e=>n(`button`,{type:`button`,onClick:()=>x(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${b===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[s(`span`,{className:`font-medium`,children:e.name}),n(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` plates`]})]},e.id))}),_?s(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:s(f,{placeholder:`New vehicle name…`,value:p,onChange:e=>m(e.target.value),onKeyDown:e=>{e.key===`Enter`&&j()},autoFocus:!0,className:`flex-1`})}):s(`button`,{type:`button`,onClick:()=>{x(null),y(!0)},className:`mt-2 w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle hover:border-primary hover:text-primary transition-colors`,children:`+ New vehicle…`}),n(E,{children:[s(g,{variant:`secondary`,onClick:k,disabled:M,children:`Cancel`}),_?n(g,{variant:`primary`,onClick:j,disabled:M||!p.trim(),children:[M&&s(Y,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):n(g,{variant:`primary`,onClick:()=>b&&A(b),disabled:M||!b,children:[M&&s(Y,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,w>1?` ${String(w)}`:``]})]})]})})}t();var we=[[`plateGallery`]];function Te(e){let[t,n]=o(null),[r,i]=o(null),[a,s]=o(!1);return c(()=>{if(n(null),i(null),s(!1),!e)return;let t=!1,r=null;return(async()=>{try{let i=await me(`${he}/${encodeURIComponent(e)}`);if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||s(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),c(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>s(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function Ee(e){let t=e.filter(e=>e.base64.length>0);return t.length===0?null:t.find(e=>/crop|plate/i.test(e.kind))??t[0]}function $({label:e,value:t,mono:r}){return n(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[s(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),s(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${r?`font-mono`:``}`,title:t,children:t})]})}function De({box:e}){return s(`div`,{className:`pointer-events-none absolute rounded-[3px] border-2 border-primary shadow-[0_0_0_9999px_rgba(0,0,0,0.28)]`,style:{left:`${String(e.x*100)}%`,top:`${String(e.y*100)}%`,width:`${String(e.width*100)}%`,height:`${String(e.height*100)}%`},children:s(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:`Plate`})})}function Oe({plate:e,cameraName:t,onClose:i,onAssign:l,onUnassign:u,onDelete:p,actionsPending:m}){let h=a(),{data:_,isFetching:y}=b({plateId:e?.plateId??``},{enabled:e!==null}),x=O(),[S,C]=o(`frame`),[w,T]=o(!1),[E,D]=o(``),{frameSrc:k,naturalWidth:A,naturalHeight:j,failed:M}=Te(e?.keyFrameMediaKey);c(()=>{T(!1),D(``),C(`frame`)},[e?.plateId]);let N=r(()=>{let t=Ee(_??[]);return t?`data:image/jpeg;base64,${t.base64}`:xe(e)},[_,e]),I=r(()=>!e?.plateBbox||A===null||j===null?null:ee(e.plateBbox,A,j),[e?.plateBbox,A,j]);if(e===null)return null;let te=typeof e.keyFrameMediaKey==`string`&&e.keyFrameMediaKey.length>0&&!M,ne=te&&S===`frame`,z=e.assigned?e.vehicleName??`Assigned`:e.recognizedVehicleId?`${e.vehicleName??`Recognized`} (suggested)`:`Unassigned`,re=`${String(Math.round(e.score*100))}%${e.corrected?` · corrected`:``}`;function ie(){e&&(D(e.text),T(!0))}function H(){if(!e)return;let t=E.trim().toUpperCase();if(!t||t===e.text){T(!1);return}x.mutate({plateId:e.plateId,text:t},{onSettled:()=>{h.invalidateQueries({queryKey:we}),T(!1)}})}return s(v,{open:!0,onOpenChange:e=>!e&&i(),children:n(d,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Plate detail`,className:`flex h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:h-auto md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[n(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[n(`div`,{className:`min-w-0`,children:[s(`div`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:e.text||`Plate detail`}),s(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]}),s(`button`,{type:`button`,onClick:i,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:s(Z,{className:`h-4 w-4`})})]}),n(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[te&&n(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[n(`button`,{type:`button`,onClick:()=>C(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${S===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[s(P,{className:`h-3.5 w-3.5`}),` Full frame`]}),n(`button`,{type:`button`,onClick:()=>C(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${S===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[s(L,{className:`h-3.5 w-3.5`}),` Crop`]})]}),ne&&k?s(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:s(V,{src:k,alt:`Full frame with detected plate`,fit:`natural`,className:`w-full`,overlay:I?s(De,{box:I}):void 0})}):N?n(`div`,{className:`relative aspect-[2/1] w-full overflow-hidden rounded-lg border border-border bg-background`,children:[s(V,{src:N,alt:`Detected plate`,className:`h-full w-full`}),y&&s(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:s(Y,{className:`h-3.5 w-3.5 animate-spin`})})]}):n(`div`,{className:`flex aspect-[2/1] w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[s(B,{className:`h-8 w-8 text-warning/70`}),s(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:`No image`}),s(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:`The crop media for this plate could not be resolved. Safe to delete.`})]}),s(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-2`,children:n(`div`,{className:`flex items-center justify-between gap-3`,children:[s(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:`Plate text`}),w?n(`div`,{className:`flex min-w-0 flex-1 items-center justify-end gap-1.5`,children:[s(f,{value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`&&H(),e.key===`Escape`&&T(!1)},className:`h-7 max-w-[10rem] text-right font-mono text-xs uppercase`,autoFocus:!0}),s(`button`,{type:`button`,onClick:H,disabled:x.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Save corrected text`,children:x.isPending?s(Y,{className:`h-3.5 w-3.5 animate-spin`}):s(fe,{className:`h-3.5 w-3.5`})}),s(`button`,{type:`button`,onClick:()=>T(!1),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel`,children:s(Z,{className:`h-3.5 w-3.5`})})]}):n(`button`,{type:`button`,onClick:ie,className:`group flex min-w-0 items-center gap-1.5`,title:`Correct the OCR reading`,children:[s(`span`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:e.text||`—`}),s(G,{className:`h-3 w-3 shrink-0 text-foreground-subtle group-hover:text-foreground`})]})]})}),n(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[s($,{label:`Camera`,value:t}),s($,{label:`Captured`,value:U(e.timestamp)}),s($,{label:`Confidence`,value:re}),s($,{label:`Vehicle`,value:z}),s($,{label:`Track`,value:e.trackId,mono:!0})]})]}),n(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[e.assigned?n(g,{variant:`secondary`,onClick:()=>u(e.plateId),disabled:m,children:[s(R,{className:`h-3.5 w-3.5`}),` Detach`]}):n(g,{variant:`primary`,onClick:()=>l(e.plateId),disabled:m,children:[s(F,{className:`h-3.5 w-3.5`}),` Assign`]}),n(g,{variant:`secondary`,onClick:()=>p(e.plateId),disabled:m,children:[s(X,{className:`h-3.5 w-3.5`}),` Delete`]})]})]})})}t();var ke=[[`plateGallery`]],Ae=500,je=120;function Me({plate:e,cameraName:t,nowMs:r,selected:i,onToggleSelect:o,onAssign:c,onOpenDetail:l}){let d=a(),f=u(),p=w(),m=()=>{d.invalidateQueries({queryKey:ke})},h=()=>l(e.plateId),g=xe(e);return n(`div`,{className:`relative flex flex-col overflow-hidden rounded-md border bg-surface ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[n(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[g===null?n(`button`,{type:`button`,onClick:h,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:`No crop image — the plate's crop media is missing. Safe to delete.`,children:[s(B,{className:`h-7 w-7 text-warning/70`}),s(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}):s(`img`,{src:g,alt:`Plate ${e.text} from ${t}`,onClick:h,className:`h-full w-full cursor-zoom-in object-cover`}),s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(e.plateId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?`Deselect`:`Select`,children:i?s(K,{className:`h-4 w-4 text-primary`}):s(q,{className:`h-4 w-4`})}),e.corrected&&n(`span`,{className:`absolute right-0 top-0 z-10 flex items-center gap-0.5 rounded-bl-md bg-primary/80 px-1 py-0.5 text-[8px] font-semibold uppercase tracking-wide text-white`,title:`Manually corrected`,children:[s(ge,{className:`h-3 w-3`}),` Fixed`]})]}),n(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[s(`p`,{className:`truncate font-mono text-xs font-bold tracking-wide text-foreground`,title:e.text,children:e.text||`—`}),s(`p`,{className:`truncate text-[10px] text-foreground-subtle`,title:t,children:t}),s(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:z(e.timestamp,r)}),e.vehicleName&&s(`p`,{className:`truncate text-[10px] font-medium text-primary`,title:e.vehicleName,children:e.vehicleName})]}),n(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[e.assigned?s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),f.mutate({plateId:e.plateId},{onSettled:m})},disabled:f.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":`Detach plate`,title:`Detach`,children:f.isPending?s(Y,{className:`h-4 w-4 animate-spin`}):s(R,{className:`h-4 w-4`})}):s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),c(e.plateId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":`Assign plate to vehicle`,title:`Assign to vehicle`,children:s(F,{className:`h-4 w-4`})}),s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),p.mutate({plateId:e.plateId},{onSettled:m})},disabled:p.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":`Delete plate`,title:`Delete plate`,children:p.isPending?s(Y,{className:`h-4 w-4 animate-spin`}):s(X,{className:`h-4 w-4`})})]})]})}var Ne=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Assigned`,value:`assigned`}];function Pe(e,t){return t===`unassigned`?e.filter(e=>!e.assigned):t===`assigned`?e.filter(e=>e.assigned):e}function Fe(){let e=a(),[t,c]=o(`all`),[l,d]=o(oe),[f,m]=o(new Set),[h,_]=o(new Set),[v,y]=o(null),[b,S]=o(null),{data:C,isLoading:T}=k({limit:Ae,includeCrops:!1},{refetchInterval:3e4}),{data:E=[]}=x(),{data:D}=p({isCamera:!0,projection:`slim`}),O=u(),j=A(),M=w(),N=Date.now(),P=C??[],I=r(()=>{let e=new Map;for(let t of D??[])e.set(t.id,t.name);return e},[D]),L=e=>I.get(e)??`Camera #${String(e)}`,ee=r(()=>ne(P).map(e=>({id:e,name:L(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[P,I]),z=r(()=>ie(se(Pe(P,t),l),f),[P,t,l,f]),B=H(z,je,r(()=>JSON.stringify([t,l.fromMs,l.toMs,[...f].sort((e,t)=>e-t)]),[t,l.fromMs,l.toMs,f])),V=r(()=>new Map(P.map(e=>[e.plateId,e])),[P]),U=b===null?null:V.get(b)??null,W=()=>{e.invalidateQueries({queryKey:ke})},G=()=>_(new Set);function ce(e){_(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}let K=[...h],q=j.isPending||M.isPending,J=O.isPending||M.isPending;function le(){K.length!==0&&j.mutate({plateIds:K},{onSettled:()=>{W(),G()}})}function ue(){K.length!==0&&Promise.allSettled(K.map(e=>M.mutateAsync({plateId:e}))).then(()=>{W(),G()})}function de(e){S(null),y([e])}function fe(e){O.mutate({plateId:e},{onSettled:W}),S(null)}function pe(e){M.mutate({plateId:e},{onSettled:W}),S(null)}let me=z.length!==P.length;return n(`div`,{className:`relative space-y-3`,children:[n(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[s(`div`,{className:`flex items-center gap-1`,children:Ne.map(e=>s(`button`,{type:`button`,onClick:()=>c(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${t===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.label},e.value))}),s(ae,{onChange:d}),s(re,{cameras:ee,selected:f,onChange:m}),!T&&s(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:me?`${String(z.length)} of ${String(P.length)} plates`:`${String(z.length)} plate${z.length===1?``:`s`}`})]}),h.size>0&&n(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[n(`span`,{className:`text-xs font-medium text-foreground`,children:[h.size,` selected`]}),n(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[n(g,{variant:`primary`,onClick:()=>y(K),disabled:q,children:[s(F,{className:`h-3.5 w-3.5`}),` Assign`]}),n(g,{variant:`secondary`,onClick:le,disabled:q,children:[j.isPending?s(Y,{className:`h-3.5 w-3.5 animate-spin`}):s(R,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),n(g,{variant:`secondary`,onClick:ue,disabled:q,children:[s(X,{className:`h-3.5 w-3.5`}),` Delete`]}),s(g,{variant:`ghost`,onClick:G,disabled:q,children:s(Z,{className:`h-3.5 w-3.5`})})]})]}),T&&n(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[s(Y,{className:`h-4 w-4 animate-spin`}),` Loading plates…`]}),!T&&z.length===0&&s(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:P.length>0?`No plates match the current filters.`:`No plates recognized yet.`}),!T&&z.length>0&&n(i,{children:[s(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2`,children:B.pageItems.map(e=>s(Me,{plate:e,cameraName:L(e.deviceId),nowMs:N,selected:h.has(e.plateId),onToggleSelect:ce,onAssign:e=>y([e]),onOpenDetail:S},e.plateId))}),s(te,{currentPage:B.page,totalItems:B.totalItems,pageSize:B.pageSize,onPageChange:B.setPage,itemNoun:`plates`})]}),s(Oe,{plate:U,cameraName:U?L(U.deviceId):``,onClose:()=>S(null),onAssign:de,onUnassign:fe,onDelete:pe,actionsPending:J}),s(Ce,{plateIds:v,vehicles:E,onDone:()=>{y(null),G()}})]})}t();var Ie=[[`plateGallery`]],Le=2e3;function Re(){let t=a(),n=e(t);n.current=t;let r=e(void 0);r.current||=W({delayMs:Le,invalidate:()=>{n.current.invalidateQueries({queryKey:Ie})}}),c(()=>()=>r.current?.cancel(),[]),y(N.PipelineAnalyticsPlateGalleryChanged,()=>{r.current?.trigger()})}function ze(){return Re(),s(pe,{icon:J,title:`Plates`,subtitle:`Manage enrolled vehicles and assign recognized license plates to them.`,children:n(`section`,{className:`space-y-3`,children:[n(`div`,{children:[s(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Vehicles`}),s(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Enrolled vehicle identities used for plate recognition. Expand a row to view or remove plate samples.`}),s(be,{})]}),n(`div`,{className:`pt-4 border-t border-border`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent recognized plates`}),s(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`License plates read by the detection pipeline. Assign them to a vehicle, correct the OCR text, or delete.`}),s(Fe,{})]})]})})}export{ze as PlatesPage};
@@ -1 +0,0 @@
1
- import{I as e,K as t,Q as n,S as r,W as i,b as ee,q as a,x as o,z as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{$ as te,J as ne,U as re,W as c,Z as ie,ct as l,et as ae,it as oe,j as u,n as se,nt as d}from"./player-overlays-9UuGjKRi.js";import{MaskShapeCanvas as f}from"./MaskShapeCanvas-Dcpby34M.js";var p=l(`hexagon`,[[`path`,{d:`M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z`,key:`yt0hxn`}]]),ce=l(`mic-off`,[[`path`,{d:`M12 19v3`,key:`npa21l`}],[`path`,{d:`M15 9.34V5a3 3 0 0 0-5.68-1.33`,key:`1gzdoj`}],[`path`,{d:`M16.95 16.95A7 7 0 0 1 5 12v-2`,key:`cqa7eg`}],[`path`,{d:`M18.89 13.23A7 7 0 0 0 19 12v-2`,key:`16hl24`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v3a3 3 0 0 0 5.12 2.12`,key:`r2i35w`}]]);n();var m=`Microphone`,h=`The camera encodes no audio at all — live view, recordings, exports and the audio analyzer are all silent.`;function le(e){let t=e.supportsAudioMute===!0,n=t?e.audioEnabled:null,r=e.pendingOn??null;return{label:m,supported:t,on:n===null?null:r??n,available:t&&n!==null,costWhenOff:h}}function ue(e){return!e.available||e.on===null?null:{enabled:!e.on}}var de=120,fe=`privacy-mask`,g=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,_=`rounded-md border border-primary/50 bg-primary/15 px-2.5 py-1 text-[11px] font-medium text-primary hover:bg-primary/25 disabled:opacity-40 transition-colors`;function v(e){return e.kind===`rect`||e.kind===`polygon`?e:null}function pe(e){let t=new Set(e.map(e=>e.id)),n=0;for(;t.has(n);)n+=1;return n}function y(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(JSON.stringify(e[n])!==JSON.stringify(t[n]))return!1;return!0}function b({deviceId:n}){let l=c(ie().trpcClient,n),[m,h]=a(null),[b,x]=a(!1),[S,C]=a(null),[w,T]=a(null),[E,D]=a(!1),[O,k]=a(!1),[A,j]=a(null),[M,N]=a(null),[me,P]=a(null),[F,I]=a(null),[L,R]=a(null),z=t(!1);s(()=>{if(!l)return;let e=!1;return z.current=!1,h(null),x(!1),C(null),T(null),k(!1),j(null),N(null),P(null),I(null),R(null),(async()=>{try{let t=await l.privacyMask?.getOptions({});if(e)return;if(!t)throw Error(`device proxy not ready`);if(h(t),z.current)return;let n=await l.privacyMask?.getStatus({});if(e)return;if(!n)throw Error(`device proxy not ready`);z.current=!0;let r={enabled:n.enabled,regions:n.regions};T(r),C(r),P(n.audioEnabled)}catch(t){if(e)return;re(t)?x(!0):console.error(`Privacy Mask load failed`,t)}})(),()=>{e=!0}},[l]);let B=i(()=>S!==null&&w!==null&&(S.enabled!==w.enabled||!y(S.regions,w.regions)),[S,w]),V=S?S.regions.length:0,H=m?m.maxRegions:0,U=t(0);s(()=>{U.current=H},[H]);let W=H>0&&V>=H,he=e(()=>{C(e=>e&&{...e,enabled:!e.enabled})},[]),G=e(e=>{j(typeof e==`number`?e:null)},[]),K=i(()=>S?S.regions.map(e=>({id:e.id,shape:e.shape,enabled:e.enabled,label:`Zone ${String(e.id)}`})):[],[S]),q=e((e,t)=>{let n=v(t);n&&C(t=>t&&{...t,regions:t.regions.map(t=>t.id===e?{...t,shape:n}:t)})},[]),J=e(e=>{let t=v(e);t&&(N(null),C(e=>{if(!e)return e;let n=U.current;if(n>0&&e.regions.length>=n)return e;let r=pe(e.regions),i={id:r,enabled:!0,shape:t};return j(r),{...e,regions:[...e.regions,i]}}))},[]),Y=e(e=>{k(!0),j(null),N(e)},[]),ge=e(e=>{k(!0),N(null),j(e)},[]),_e=e(e=>{j(t=>t===e?null:t),C(t=>t&&{...t,regions:t.regions.filter(t=>t.id!==e)})},[]),ve=e(()=>{N(null),j(null),w&&C({enabled:w.enabled,regions:w.regions})},[w]),ye=e(async()=>{if(!(!l||!S)){D(!0);try{await l.privacyMask?.setMask({patch:{enabled:S.enabled,regions:[...S.regions]}});let e=await l.privacyMask?.getStatus({});if(e){let t={enabled:e.enabled,regions:e.regions};T(t),C(t)}}catch(e){console.error(`Privacy Mask save failed`,e)}finally{D(!1)}}},[l,S]),X=le({supportsAudioMute:m===null?null:m.supportsAudioMute,audioEnabled:me,pendingOn:F}),Z=e(async()=>{let e=ue(X);if(!(!l||e===null)){I(e.enabled),R(null);try{await l.privacyMask?.setAudioEnabled(e);let t=await l.privacyMask?.getStatus({});t&&P(t.audioEnabled)}catch(e){console.error(`Privacy microphone write failed — reverting`,e),R(e instanceof Error?e.message:String(e))}finally{I(null)}}},[l,X]),be=e(()=>{k(e=>(e&&(N(null),j(null)),!e))},[]),Q=m?.supportedShapes??[];se(i(()=>O&&!b&&m&&S?{id:fe,order:de,node:o(f,{transparent:!0,items:K,supportedShapes:Q,polygonVertices:m.polygonVertices,selectedId:A,onSelect:G,onShapeChange:q,onDrawComplete:J,drawingKind:M})}:null,[O,b,m,S,K,Q,A,G,q,J,M]));let xe=m?.supportedShapes.includes(`rect`)??!1,Se=m?.supportedShapes.includes(`polygon`)??!1,$=m!==null&&(m.maxRegions<=0||m.supportedShapes.length===0);return l?o(ne,{title:`Privacy Mask`,icon:o(oe,{className:`h-3.5 w-3.5 text-foreground-subtle`}),children:r(`div`,{className:`flex flex-col gap-3`,children:[b||$?o(`p`,{className:`${u} leading-relaxed`,children:`This camera doesn't support an on-board privacy mask.`}):!b&&!$&&m!==null&&S!==null?r(ee,{children:[r(`p`,{className:`${u} leading-relaxed`,children:[`Toggle `,o(`strong`,{className:`text-foreground`,children:`Edit mask`}),` to draw blanked-out zones on the live frame, then `,o(`strong`,{className:`text-foreground`,children:`Save`}),` to push them to the camera. Drag a rectangle to move, its corner to resize; drag polygon vertices, click an edge midpoint to add one, or right-click a vertex to remove it.`]}),r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[o(`button`,{type:`button`,onClick:be,disabled:E,"aria-pressed":O,className:O?_:g,children:O?`Done editing`:`Edit mask`}),o(`button`,{type:`button`,onClick:he,disabled:E,"aria-pressed":S.enabled,className:S.enabled?_:g,children:S.enabled?`Mask on`:`Mask off`}),xe&&o(`button`,{type:`button`,onClick:()=>Y(`rect`),disabled:E||W,"aria-pressed":M===`rect`,className:M===`rect`?_:g,title:W?`Maximum zones reached`:`Add a rectangle zone`,children:`+ Rect`}),Se&&o(`button`,{type:`button`,onClick:()=>Y(`polygon`),disabled:E||W,"aria-pressed":M===`polygon`,className:M===`polygon`?_:g,title:W?`Maximum zones reached`:`Add a polygon zone`,children:`+ Polygon`}),r(`span`,{className:`${u} ml-1 tabular-nums`,children:[V,` / `,H,` zones`]}),o(`span`,{className:`flex-1`}),o(`button`,{type:`button`,onClick:ve,disabled:E||!B,className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,children:`Revert`}),o(`button`,{type:`button`,onClick:()=>void ye(),disabled:E||!B,className:_,children:E?`Saving…`:`Save`})]}),V>0?o(`div`,{className:`flex flex-col gap-1`,children:S.regions.map(e=>{let t=A===e.id,n=e.shape.kind===`polygon`?p:ae;return r(`div`,{className:`flex items-center gap-2 rounded-md border px-2 py-1 transition-colors ${t?`border-primary/50 bg-primary/10`:`border-border bg-surface`}`,children:[r(`button`,{type:`button`,onClick:()=>ge(e.id),disabled:E,className:`flex flex-1 items-center gap-2 text-left text-[11px] font-medium text-foreground-subtle hover:text-foreground disabled:opacity-40 transition-colors`,children:[o(n,{className:`h-3.5 w-3.5 shrink-0`}),r(`span`,{children:[`Zone `,e.id]}),o(`span`,{className:`text-foreground-faint capitalize`,children:e.shape.kind})]}),o(`button`,{type:`button`,onClick:()=>_e(e.id),disabled:E,"aria-label":`Delete zone ${String(e.id)}`,title:`Delete zone`,className:`inline-flex h-6 w-6 items-center justify-center rounded border border-border bg-surface text-foreground-subtle hover:border-red-400/40 hover:bg-red-500/10 hover:text-red-400 disabled:opacity-40 transition-colors`,children:o(te,{className:`h-3.5 w-3.5`})})]},e.id)})}):null]}):o(`p`,{className:`${u} leading-relaxed`,children:`Loading the camera's privacy mask…`}),X.supported&&r(`div`,{className:`flex items-start gap-3 rounded-md border border-border bg-surface px-2 py-2`,children:[o(`button`,{type:`button`,role:`switch`,"aria-label":X.label,"aria-checked":X.on===!0,disabled:!X.available||F!==null,onClick:()=>void Z(),title:X.on===null?`Microphone — state unknown; the camera did not answer.`:X.on?`The camera is capturing sound. Turning it off: ${X.costWhenOff}`:`The camera is silent. ${X.costWhenOff}`,className:X.on===!1||X.on===null?g:_,children:r(`span`,{className:`inline-flex items-center gap-1.5`,children:[X.on===!1?o(ce,{className:`h-3.5 w-3.5`}):o(d,{className:`h-3.5 w-3.5`}),X.on===null?`Microphone unknown`:X.on?`Microphone on`:`Microphone off`]})}),o(`p`,{className:`text-[10px] text-foreground-subtle flex-1 leading-relaxed`,children:L===null?X.on===null?`The camera did not report its microphone, so this state is unknown.`:X.costWhenOff:`Write failed: ${L}`})]})]})}):null}export{b as PrivacyMaskSettings};
@@ -1 +0,0 @@
1
- import{I as e,K as t,Q as n,S as r,W as i,b as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{$ as l,B as u,H as d,I as f,K as p,L as m,R as h,U as g,V as _,W as v,Z as y,ct as b,j as x,o as S,rt as C,st as w,tt as ee}from"./player-overlays-9UuGjKRi.js";import{MaskShapeCanvas as te}from"./MaskShapeCanvas-Dcpby34M.js";var ne=b(`settings-2`,[[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`path`,{d:`M19 7h-9`,key:`6i9tg`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]);n();var T=`/addon/pipeline-analytics/event-media`;function E(e){let t=new Map;for(let n of e.states)n.references.forEach((e,r)=>{let i=t.get(e.condition)??[];i.push({stateId:n.id,index:r,reference:e}),t.set(e.condition,i)});return[...t.entries()].map(([e,t])=>({condition:e,tiles:[...t].sort((e,t)=>t.reference.capturedAt-e.reference.capturedAt)})).sort((e,t)=>e.condition.localeCompare(t.condition))}function D(e){return e.states.reduce((e,t)=>e+t.references.length,0)}var O=`rounded border border-danger/50 bg-danger/10 px-1 py-0.5 text-[10px] font-medium text-danger hover:bg-danger/20 disabled:opacity-40 transition-colors`;function k({monitor:e,disabled:t,onDelete:n}){let i=E(e),a=D(e),[c,u]=o(null);return i.length===0?s(`p`,{className:`${x} leading-relaxed`,children:`No photographs captured yet. Press “Capture daylight” to take the one this scene will judge everything against.`}):s(`div`,{className:`flex flex-col gap-2`,children:i.map(e=>r(`div`,{className:`flex flex-col gap-1`,children:[r(`p`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:[d(e.condition),` · `,e.tiles.length]}),s(`ul`,{className:`flex flex-wrap gap-1.5`,children:e.tiles.map(i=>{let o=`${i.stateId}:${String(i.index)}`,f=a===1,p=c===o;return r(`li`,{className:`flex w-24 flex-col gap-1 rounded-md border border-border p-1`,children:[s(A,{reference:i.reference}),s(`span`,{className:`${x} tabular-nums`,children:j(i.reference.capturedAt)}),r(`button`,{type:`button`,className:O,disabled:t,"aria-label":`Delete the ${d(e.condition).toLowerCase()} photograph from ${j(i.reference.capturedAt)}`,onClick:()=>{if(f&&!p){u(o);return}u(null),n({stateId:i.stateId,index:i.index})},children:[s(l,{className:`mr-1 inline h-3 w-3`}),p?`Confirm`:`Delete`]}),p&&s(`p`,{className:`text-[10px] leading-snug text-warning`,children:`This is the only photograph this scene has. Delete it and the scene no longer knows what normal looks like — it stops judging until you capture again.`})]},o)})})]},e.condition))})}function A({reference:e}){let[t,n]=o(!1),i=e.thumbnailMediaId;return i===void 0||t?r(`div`,{className:`flex h-16 w-full flex-col items-center justify-center gap-0.5 rounded bg-surface text-foreground-subtle`,title:`The picture for this reference is no longer stored. The reference itself is intact and still being scored against.`,children:[s(C,{className:`h-4 w-4`}),s(`span`,{className:`text-[9px]`,children:`no picture`})]}):s(`img`,{src:`${T}/${encodeURIComponent(i)}`,alt:``,loading:`lazy`,className:`h-16 w-full rounded object-cover`,onError:()=>n(!0)})}function j(e){let t=new Date(e);return`${t.toLocaleDateString()} ${t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}`}n();var M=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground focus:border-primary focus:outline-none disabled:opacity-50`,N=`text-[10px] font-medium text-foreground-subtle`,P=`flex flex-col gap-2 rounded-md border border-border bg-surface/40 p-2`,F=`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle`,I=5,L=3600,R={periodic:`Only on the clock. Predictable, and it notices a change even on a camera nothing ever moves in front of.`,"on-motion":`Only after the camera has been still again for the quiet window below. Cheapest, but a change nobody walks past is never seen.`,both:`Both — the clock is the safety net that lets the motion path miss. This is the right answer for almost every scene.`},z={skip:`Sit that light out. No verdict, no alarm, no flag touched — it picks itself back up when a light it knows returns. This is why the night capture is optional.`,"judge-anyway":`Compare against the references you do have. Only correct when the two lights genuinely look alike (a floodlit driveway, an indoor lamp) — against a real infrared frame it will report a change that did not happen.`};function B(e){return{label:e.label,checkIntervalSec:e.checkIntervalSec??60,threshold:e.check.mode===`similarity`?e.check.threshold:.8,hysteresisCount:e.check.hysteresisCount,quietSeconds:e.quietSeconds,minObservationSpacingSec:e.minObservationSpacingSec,confirmPrompt:e.confirm?.prompt??``}}function V({monitor:e,disabled:t,onPatch:n}){let[i,l]=o(()=>B(e)),[u,d]=o(!1);c(()=>{u||l(B(e))},[e,u]);let f=e=>{d(!1),n(e)},p=t=>e.check.mode===`similarity`?{mode:`similarity`,threshold:t.threshold??e.check.threshold,hysteresisCount:t.hysteresisCount??e.check.hysteresisCount}:{...e.check,hysteresisCount:t.hysteresisCount??e.check.hysteresisCount},m=e.confirm?.enabled===!0,h=e.check.mode===`similarity`?e.check.threshold:null;return r(`div`,{className:`flex flex-col gap-2`,children:[r(`div`,{className:P,children:[s(`p`,{className:F,children:`What it watches`}),r(`label`,{className:`flex flex-col gap-1`,children:[s(`span`,{className:N,children:`Name`}),s(`input`,{type:`text`,value:i.label,disabled:t,className:M,onFocus:()=>d(!0),onChange:e=>l(t=>({...t,label:e.target.value})),onBlur:()=>{let t=i.label.trim();t.length>0&&t!==e.label?f({label:t}):d(!1)}})]}),r(`label`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`checkbox`,checked:e.enabled,disabled:t,onChange:e=>f({enabled:e.target.checked})}),s(`span`,{className:N,children:`Watching`})]}),s(`p`,{className:x,children:`Turned off, the scene keeps its region, its references and its flag — it simply stops checking. Nothing is lost by pausing one for a while.`}),r(`label`,{className:`flex flex-col gap-1`,children:[s(`span`,{className:N,children:`When to look`}),r(`select`,{value:e.triggerMode,disabled:t,className:M,onChange:e=>{let t=e.target.value;(t===`periodic`||t===`on-motion`||t===`both`)&&f({triggerMode:t})},children:[s(`option`,{value:`both`,children:`On the clock and after motion settles`}),s(`option`,{value:`periodic`,children:`On the clock only`}),s(`option`,{value:`on-motion`,children:`After motion settles only`})]})]}),s(`p`,{className:x,children:R[e.triggerMode]}),r(`label`,{className:`flex flex-col gap-1`,children:[s(`span`,{className:N,children:`Check every (seconds)`}),s(`input`,{type:`number`,min:I,max:L,value:i.checkIntervalSec,disabled:t,className:M,onFocus:()=>d(!0),onChange:e=>l(t=>({...t,checkIntervalSec:Number(e.target.value)||0})),onBlur:()=>{let t=H(i.checkIntervalSec,I,L);t===e.checkIntervalSec?d(!1):f({checkIntervalSec:t})}})]}),s(`p`,{className:x,children:`60 s suits “is the bin still out”. Every check costs one photograph and one encode, so going below about 30 s buys latency you almost never need and multiplies the cost by the number of scenes you own.`})]}),r(`div`,{className:P,children:[s(`p`,{className:F,children:`How sure it has to be`}),e.check.mode===`similarity`&&r(a,{children:[r(`label`,{className:`flex flex-col gap-1`,children:[r(`span`,{className:N,children:[`Match threshold — `,s(`span`,{className:`tabular-nums`,children:i.threshold.toFixed(2)})]}),s(`input`,{type:`range`,min:.3,max:.99,step:.01,value:i.threshold,disabled:t,onFocus:()=>d(!0),onChange:e=>l(t=>({...t,threshold:Number(e.target.value)})),onMouseUp:()=>{i.threshold===h?d(!1):f({check:p({threshold:i.threshold})})},onBlur:()=>{i.threshold===h?d(!1):f({check:p({threshold:i.threshold})})}})]}),s(`p`,{className:`text-[10px] text-foreground-subtle`,children:`How closely the region still has to resemble the photograph to count as unchanged. Higher means fussier: at 0.95 a passing cloud can read as a change; at 0.60 the bin can be taken and the scene will shrug. 0.80 is a sensible start — if it cries wolf, lower it; if it misses the thing you care about, raise it.`})]}),r(`label`,{className:`flex flex-col gap-1`,children:[s(`span`,{className:N,children:`Agreeing checks before it changes its mind`}),s(`input`,{type:`number`,min:1,max:10,value:i.hysteresisCount,disabled:t,className:M,onFocus:()=>d(!0),onChange:e=>l(t=>({...t,hysteresisCount:Number(e.target.value)||1})),onBlur:()=>{let t=H(i.hysteresisCount,1,10);t===e.check.hysteresisCount?d(!1):f({check:p({hysteresisCount:t})})}})]}),s(`p`,{className:x,children:`One bad photograph must never be able to flip a scene. 3 agreeing checks at 60 s is about four minutes of latency and is what makes the answer trustworthy — leaving a state costs exactly the same as entering one.`}),r(`label`,{className:`flex flex-col gap-1`,children:[s(`span`,{className:N,children:`Quiet for (seconds) before a check counts`}),s(`input`,{type:`number`,min:0,max:3600,value:i.quietSeconds,disabled:t,className:M,onFocus:()=>d(!0),onChange:e=>l(t=>({...t,quietSeconds:Number(e.target.value)||0})),onBlur:()=>{let t=H(i.quietSeconds,0,3600);t===e.quietSeconds?d(!1):f({quietSeconds:t})}})]}),s(`p`,{className:x,children:`A check taken while something is moving is a photograph of the van parked in front of the bin, so it is discarded rather than merely delayed. 0 disables the gate.`}),r(`label`,{className:`flex flex-col gap-1`,children:[s(`span`,{className:N,children:`Minimum gap between counted checks (seconds)`}),s(`input`,{type:`number`,min:0,max:3600,value:i.minObservationSpacingSec,disabled:t,className:M,onFocus:()=>d(!0),onChange:e=>l(t=>({...t,minObservationSpacingSec:Number(e.target.value)||0})),onBlur:()=>{let t=H(i.minObservationSpacingSec,0,3600);t===e.minObservationSpacingSec?d(!1):f({minObservationSpacingSec:t})}})]}),s(`p`,{className:x,children:`Spreads the agreeing checks over real time instead of letting three adjacent polls inside one long occlusion be mistaken for three independent opinions.`})]}),r(`div`,{className:P,children:[s(`p`,{className:F,children:`Lighting`}),r(`label`,{className:`flex flex-col gap-1`,children:[s(`span`,{className:N,children:`When a light has no reference of its own`}),r(`select`,{value:e.onUncoveredCondition,disabled:t,className:M,onChange:e=>{let t=e.target.value;(t===`skip`||t===`judge-anyway`)&&f({onUncoveredCondition:t})},children:[s(`option`,{value:`skip`,children:`Skip the check (recommended)`}),s(`option`,{value:`judge-anyway`,children:`Judge against the other light anyway`})]})]}),s(`p`,{className:x,children:z[e.onUncoveredCondition]})]}),r(`div`,{className:P,children:[s(`p`,{className:F,children:`What you get told`}),r(`label`,{className:`flex flex-col gap-1`,children:[s(`span`,{className:N,children:`Notifications follow`}),r(`select`,{value:e.emit,disabled:t,className:M,onChange:e=>{let t=e.target.value;(t===`latched`||t===`live`)&&f({emit:t})},children:[s(`option`,{value:`latched`,children:`The flag — told once, still visible at breakfast`}),s(`option`,{value:`live`,children:`The live state — follows the region as it changes`})]})]}),s(`p`,{className:x,children:`“Is the bin gone” is a flag: you want to be told once and still see it later. “Is the gate open” is a live state.`}),r(`label`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`checkbox`,checked:e.autoRestore,disabled:t,onChange:e=>f({autoRestore:e.target.checked})}),s(`span`,{className:N,children:`Clear the flag by itself when things look normal again`})]}),s(`p`,{className:x,children:`Off by default, so an alarm never silently clears itself. The “back to normal” moment is recorded either way, so an automation can still react to it.`})]}),r(`div`,{className:P,children:[s(`p`,{className:F,children:`AI double-check`}),r(`label`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`checkbox`,checked:m,disabled:t||i.confirmPrompt.trim().length===0,onChange:e=>f(e.target.checked?{confirm:{...U(i.confirmPrompt.trim()),enabled:!0}}:{confirm:null})}),s(`span`,{className:N,children:`Ask a vision model before changing the answer`})]}),r(`label`,{className:`flex flex-col gap-1`,children:[s(`span`,{className:N,children:`The question to ask`}),s(`input`,{type:`text`,value:i.confirmPrompt,placeholder:`e.g. Is the wheelie bin still there?`,disabled:t,className:M,onFocus:()=>d(!0),onChange:e=>l(t=>({...t,confirmPrompt:e.target.value})),onBlur:()=>{let t=i.confirmPrompt.trim();t.length>0&&t!==e.confirm?.prompt?f({confirm:{...U(t),enabled:m}}):d(!1)}})]}),r(`p`,{className:x,children:[`The model is asked `,s(`strong`,{children:`only`}),` when the region has already changed enough to flip the answer — roughly twice a week for a bin, not once a minute. It reasons about the object rather than the pixels, so rain, shadows and a repositioned bin stop counting as the thing being taken. If it cannot be reached, the change is held rather than announced.`]})]})]})}function H(e,t,n){return Math.min(n,Math.max(t,e))}function U(e){return{enabled:!1,prompt:e,timeoutMs:8e3,maxImagePx:448,onTimeout:`hold`}}n();var W=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,G=`rounded-md border border-primary/50 bg-primary/15 px-2.5 py-1 text-[11px] font-medium text-primary hover:bg-primary/25 disabled:opacity-40 transition-colors`,K=`rounded-md border border-danger/50 bg-danger/10 px-2 py-1 text-[11px] font-medium text-danger hover:bg-danger/20 disabled:opacity-40 transition-colors`,q={alarm:`border-danger/50 bg-danger/15 text-danger`,ok:`border-success/50 bg-success/15 text-success`,unknown:`border-border bg-surface text-foreground-subtle`},re=.8,ie=3;function J({deviceId:n}){let b=v(y().trpcClient,n),C=p(b?.state.sceneMonitor),T=S(n,{width:640}),[E,D]=o(null),[O,A]=o(!1),[j,M]=o(null),[N,P]=o(null),[F,I]=o(null),[L,R]=o(null),[z,B]=o(!1),[H,U]=o(null),[J,Y]=o(``),X=t(!0);c(()=>(X.current=!0,()=>{X.current=!1}),[]);let Z=e(async()=>{if(b)try{let e=await b.sceneMonitor?.listScenes({});if(!X.current)return;e&&D(e)}catch(e){if(!X.current)return;g(e)?A(!0):P(e instanceof Error?e.message:String(e))}},[b]);c(()=>{D(null),A(!1),P(null),Z()},[Z]);let Q=C?.monitors??E?.monitors??[],ae=Date.now(),$=e(async(e,t)=>{M(e),P(null);try{await t(),await Z()}catch(e){X.current&&P(e instanceof Error?e.message:String(e))}finally{X.current&&M(null)}},[Z]),oe=i(()=>{let e=Q.map(e=>({id:e.id,shape:e.roi,label:e.label,enabled:e.enabled}));return H===null?e:[...e,{id:`__draft__`,shape:H,label:`New scene`}]},[Q,H]),se=e((e,t)=>{if(t.kind===`rect`){if(e===`__draft__`){U(t);return}$(`roi-${String(e)}`,async()=>b?.sceneMonitor?.updateScene({monitorId:String(e),patch:{roi:t}}))}},[b,$]),ce=e(e=>{e.kind===`rect`&&U(e)},[]),le=e(async()=>{H===null||J.trim().length===0||(await $(`create`,async()=>{await b?.sceneMonitor?.createScene({label:J.trim(),roi:H,check:{mode:`similarity`,threshold:re,hysteresisCount:ie}})}),U(null),Y(``),B(!1))},[b,H,J,$]);return b?s(`div`,{className:`flex flex-col gap-3`,children:O?s(`p`,{className:`${x} leading-relaxed`,children:`Scene monitoring is not available for this camera.`}):r(a,{children:[s(`p`,{className:`${x} leading-relaxed`,children:`A scene watches one region of this camera and tells you when it stops looking like the picture you captured. Draw a box around the thing you care about — a wheelie bin, a gate, a parking space — then capture what “normal” looks like. Daylight is enough to start: the night reference is optional, and without it the scene simply sits the infrared hours out instead of reporting a problem.`}),s(`div`,{className:`relative overflow-hidden rounded-md border border-border`,children:s(te,{items:oe,supportedShapes:[`rect`],selectedId:F??(H===null?null:`__draft__`),onSelect:e=>I(e===null?null:String(e)),onShapeChange:se,onDrawComplete:ce,drawingKind:z&&H===null?`rect`:null,backdrop:T.src===null?null:s(`img`,{src:T.src,alt:``,className:`h-full w-full object-contain`,draggable:!1})})}),r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[s(`button`,{type:`button`,className:z?G:W,"aria-pressed":z,onClick:()=>{B(e=>!e),U(null)},disabled:j!==null,children:z?`Cancel`:`+ New scene`}),s(`button`,{type:`button`,className:W,onClick:T.refresh,disabled:j!==null,children:`Refresh frame`})]}),z&&r(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-2`,children:[s(`p`,{className:`text-[10px] text-foreground-subtle`,children:H===null?`Click on the frame to drop a box, then drag its corner to fit it around the thing you want watched.`:`Name it, then create. You capture what “normal” looks like next.`}),H!==null&&u(H)&&s(`p`,{className:`text-[11px] leading-relaxed text-warning`,children:`That box covers most of the frame. A scene that big is dominated by the weather, the sky and passing cars — it will quietly stop noticing the thing you actually care about. Draw it tighter.`}),r(`div`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`text`,value:J,onChange:e=>Y(e.target.value),placeholder:`e.g. Immondizia prelevata`,className:`flex-1 rounded-md border border-border bg-surface px-2 py-1 text-[12px] text-foreground`}),s(`button`,{type:`button`,className:G,onClick:()=>void le(),disabled:H===null||J.trim().length===0||j!==null,children:`Create`})]})]}),N!==null&&s(`p`,{className:`text-[11px] leading-relaxed text-danger`,children:N}),Q.length===0?s(`p`,{className:`${x} leading-relaxed`,children:`No scenes on this camera yet.`}):s(`ul`,{className:`flex flex-col gap-2`,children:Q.map(e=>{let t=m(e);return r(`li`,{className:`flex flex-col gap-1.5 rounded-md border p-2 ${F===e.id?`border-primary/50`:`border-border`}`,children:[r(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{type:`button`,className:`flex-1 text-left text-[12px] font-medium text-foreground`,onClick:()=>I(e.id),children:e.label}),s(`span`,{className:`rounded border px-1.5 py-0.5 text-[10px] font-medium ${q[t.tone]}`,children:t.text})]}),s(`p`,{className:`${x} leading-relaxed`,children:_(e,ae)}),s(`p`,{className:`${x} tabular-nums`,children:h(e)}),s(k,{monitor:e,disabled:j!==null,onDelete:({stateId:t,index:n})=>void $(`refdel-${e.id}-${t}-${String(n)}`,async()=>b.sceneMonitor?.deleteReference({monitorId:e.id,stateId:t,index:n}))}),r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[f.map(t=>{let n=t===`ir`;return r(`button`,{type:`button`,className:W,disabled:j!==null,title:n?`Optional. Without a night reference the checks in infrared are simply skipped — the scene keeps working in daylight and nothing is reported as broken.`:`Take a fresh photo now and store it as the ${d(t).toLowerCase()} reference`,onClick:()=>void $(`cap-${e.id}-${t}`,async()=>b.sceneMonitor?.captureReference({monitorId:e.id,condition:t})),children:[s(w,{className:`mr-1 inline h-3 w-3`}),`Capture `,d(t).toLowerCase(),n&&s(`span`,{className:`ml-1 text-foreground-subtle/70`,children:`(optional)`})]},t)}),r(`button`,{type:`button`,className:G,disabled:j!==null||e.states.length===0,title:`Clear the flag and re-photograph what normal looks like right now`,onClick:()=>void $(`reset-${e.id}`,async()=>b.sceneMonitor?.resetScene({monitorId:e.id})),children:[s(ee,{className:`mr-1 inline h-3 w-3`}),`Reset`]}),s(`button`,{type:`button`,className:W,disabled:j!==null,onClick:()=>void $(`check-${e.id}`,async()=>b.sceneMonitor?.recheckNow({monitorId:e.id})),children:`Check now`}),r(`button`,{type:`button`,className:L===e.id?G:W,"aria-pressed":L===e.id,"aria-label":`Settings for ${e.label}`,disabled:j!==null,onClick:()=>R(t=>t===e.id?null:e.id),children:[s(ne,{className:`mr-1 inline h-3 w-3`}),`Settings`]}),s(`button`,{type:`button`,className:K,disabled:j!==null,onClick:()=>void $(`del-${e.id}`,async()=>b.sceneMonitor?.deleteScene({monitorId:e.id})),children:s(l,{className:`h-3 w-3`})})]}),L===e.id&&s(V,{monitor:e,disabled:j!==null,onPatch:t=>void $(`tune-${e.id}`,async()=>b.sceneMonitor?.updateScene({monitorId:e.id,patch:t}))})]},e.id)})})]})}):null}export{J as SceneMonitorEditor};
@@ -1 +0,0 @@
1
- import{K as e}from"./index-lupFu8MS.js";var t=e(`circle-check-big`,[[`path`,{d:`M21.801 10A10 10 0 1 1 17 3.335`,key:`yps3ct`}],[`path`,{d:`m9 11 3 3L22 4`,key:`1pflzl`}]]);export{t};
@@ -1 +0,0 @@
1
- import{K as e}from"./index-lupFu8MS.js";var t=e(`clock`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`polyline`,{points:`12 6 12 12 16 14`,key:`68esgv`}]]);export{t};