@camstack/addon-admin-ui 1.2.81 → 1.2.83

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 (111) hide show
  1. package/dist/assets/{AddLocationWizard-WDALxpq-.js → AddLocationWizard-De7ns5QL.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-D86qUT-8.js → AddonCollectionPage-DXsxDYkh.js} +1 -1
  3. package/dist/assets/{Addons-C7jR5jKB.js → Addons-iB8Jj8Wa.js} +1 -1
  4. package/dist/assets/{AdminTabs-D6yDsobg.js → AdminTabs-Ea5QF5Xy.js} +1 -1
  5. package/dist/assets/AiProfiles-Cf11u16h.js +3 -0
  6. package/dist/assets/{BrokerForm-DnKqFWQy.js → BrokerForm-B-sL3dqC.js} +1 -1
  7. package/dist/assets/{Build-Ipz6h2Qx.js → Build-_kPogt2B.js} +5 -5
  8. package/dist/assets/{Capabilities-wOV3gO99.js → Capabilities-D-_vyuUw.js} +1 -1
  9. package/dist/assets/{CapabilityBadges-CByvC3eB.js → CapabilityBadges-DVcflr6z.js} +1 -1
  10. package/dist/assets/{Cluster-DDXbnzQA.js → Cluster-CP-cfGdm.js} +1 -1
  11. package/dist/assets/{Data-Btzeyfj7.js → Data-D3-pzcKz.js} +1 -1
  12. package/dist/assets/{DetectionIntelligence-Dt4la9Ns.js → DetectionIntelligence-B914KqGk.js} +1 -1
  13. package/dist/assets/{DeviceAggregateSection-iY2G54zN.js → DeviceAggregateSection-CZPFsC_N.js} +1 -1
  14. package/dist/assets/DeviceDetail-Cz70xnHl.js +2 -0
  15. package/dist/assets/Devices-CQEzT4CH.js +1 -0
  16. package/dist/assets/EmbedPlayerPage-BQ1dgL2t.js +1 -0
  17. package/dist/assets/Events-B9-2qvUg.js +1 -0
  18. package/dist/assets/{FormBuilder-B-sNHhCg.js → FormBuilder-ERsdhqXU.js} +1 -1
  19. package/dist/assets/Identity-BNMnBiNq.js +1 -0
  20. package/dist/assets/IntegrationDetail-CY-7m0wv.js +1 -0
  21. package/dist/assets/Integrations-Bs6_6m2A.js +1 -0
  22. package/dist/assets/Integrations-CbfIXyMv.js +1 -0
  23. package/dist/assets/{Logs-Rdo_SjmO.js → Logs-CJEauzfn.js} +1 -1
  24. package/dist/assets/{MotionZonesSettings-Bhfztqso.js → MotionZonesSettings-CrtWFnAG.js} +1 -1
  25. package/dist/assets/{MyAccess-Cuk_gmTY.js → MyAccess-MG2HC7n3.js} +1 -1
  26. package/dist/assets/Network-DaZHubTl.js +1 -0
  27. package/dist/assets/{NodeAddonsSettingsPanel-mIPiVij_.js → NodeAddonsSettingsPanel-Cm3hCWxL.js} +1 -1
  28. package/dist/assets/{NodeInferenceDevices-9bqVJEiE.js → NodeInferenceDevices-2-PPLG4L.js} +1 -1
  29. package/dist/assets/Notifications-DMPhSkZ8.js +1 -0
  30. package/dist/assets/Pipeline-D4RLE8zf.js +1 -0
  31. package/dist/assets/{Plates-DyGd_pUG.js → Plates-CdlwAHjB.js} +1 -1
  32. package/dist/assets/{PrivacyMaskSettings-CTbYEYkc.js → PrivacyMaskSettings-1sJg0nCf.js} +1 -1
  33. package/dist/assets/{ProviderIcon-D8aWAoj0.js → ProviderIcon-CIB9wAOh.js} +1 -1
  34. package/dist/assets/Recordings-D4KRWthc.js +1 -0
  35. package/dist/assets/{ScanNetworkModal-C8Bakspm.js → ScanNetworkModal-QJjU9tvg.js} +1 -1
  36. package/dist/assets/{SceneMonitorEditor-Cx7eASci.js → SceneMonitorEditor-B_qhxMl3.js} +1 -1
  37. package/dist/assets/{Scenes-DnqImYTT.js → Scenes-S26M2qHR.js} +1 -1
  38. package/dist/assets/{Settings-COAxk1-6.js → Settings-BgvNkBP1.js} +1 -1
  39. package/dist/assets/{Showroom-DmEvzSMg.js → Showroom-GHOpXZqD.js} +1 -1
  40. package/dist/assets/{Terminal-DasTfEQo.js → Terminal-B0ibWMEy.js} +2 -2
  41. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-tsLPdvDU.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BxzyL6ky.js} +1 -1
  42. package/dist/assets/{bell-ring-B6JDETmm.js → bell-ring-C1CDDXf4.js} +1 -1
  43. package/dist/assets/{boxes-DVDxegRH.js → boxes-D1jLdgix.js} +1 -1
  44. package/dist/assets/{build-cluster-graph-B8Cdzik4.js → build-cluster-graph-C4jX8n1A.js} +2 -2
  45. package/dist/assets/circle-check-big-Be_uVG-B.js +1 -0
  46. package/dist/assets/{circle-x-a0OLhq9b.js → circle-x-CJJu15h-.js} +1 -1
  47. package/dist/assets/clock-9WRXwSMf.js +1 -0
  48. package/dist/assets/{copy-EKhXmX92.js → copy-CCWWm0Zr.js} +1 -1
  49. package/dist/assets/{debounced-invalidate-BQ8ML6Ah.js → debounced-invalidate-Bo_vaBxo.js} +1 -1
  50. package/dist/assets/{dist-Df5TpDx0.js → dist-B7jD-S4H.js} +1 -1
  51. package/dist/assets/{download-BChaquac.js → download-BkhXjXOx.js} +1 -1
  52. package/dist/assets/{face-bbox-DKVz3zEq.js → face-bbox-BOyxoUe0.js} +1 -1
  53. package/dist/assets/{hard-drive-Dg_uzT-t.js → hard-drive-fVjmkYpz.js} +1 -1
  54. package/dist/assets/{hostInit-CbA0YcFo.js → hostInit-CFYQGKqd.js} +1 -1
  55. package/dist/assets/index-DM4pp8Vx.js +4 -0
  56. package/dist/assets/{key-round-DpXzoCIV.js → key-round-BWUCyF0a.js} +1 -1
  57. package/dist/assets/{mf-entry-bootstrap-0-631dbdb7.js → mf-entry-bootstrap-0-8a7c339b.js} +2 -2
  58. package/dist/assets/{pencil-dvZNet31.js → pencil-BOy-rDbD.js} +1 -1
  59. package/dist/assets/play-tYEpmInf.js +1 -0
  60. package/dist/assets/{player-overlays-DXNKqmwI.js → player-overlays-UTlrOH4s.js} +1 -1
  61. package/dist/assets/plus-uTnAmy5n.js +1 -0
  62. package/dist/assets/power-DLJJxxZ5.js +1 -0
  63. package/dist/assets/{radio-CUBDyXa0.js → radio-DKuDbOsT.js} +1 -1
  64. package/dist/assets/{refresh-cw-CikJV4hg.js → refresh-cw-BRs_7wGu.js} +1 -1
  65. package/dist/assets/remoteEntry-B-TTgn5K.js +1 -0
  66. package/dist/assets/rotate-ccw-CZY9UuXq.js +1 -0
  67. package/dist/assets/rotate-cw-rDbUnEsj.js +1 -0
  68. package/dist/assets/search-BGsNM6IN.js +1 -0
  69. package/dist/assets/{send-jra0X2FY.js → send-DSafmQi_.js} +1 -1
  70. package/dist/assets/{server-CLphEdE1.js → server-wq15CL48.js} +1 -1
  71. package/dist/assets/square-BFMdi_Qm.js +1 -0
  72. package/dist/assets/{square-check-big-B4oQsHOX.js → square-check-big-DO81u3O2.js} +1 -1
  73. package/dist/assets/{src-DAigq6PX.js → src-C9CFJqET.js} +2 -2
  74. package/dist/assets/{src-C0QlPpXb.js → src-DVZrqMsD.js} +14 -14
  75. package/dist/assets/{star-Ch9uuiCl.js → star-Docf4EYZ.js} +1 -1
  76. package/dist/assets/{undo-2-DLrLmKUr.js → undo-2-LIqqVOPk.js} +1 -1
  77. package/dist/assets/{upload-DVgOLthM.js → upload-D4XiPM-V.js} +1 -1
  78. package/dist/assets/{use-scenes-feed-DdlE4MDL.js → use-scenes-feed-BdUI8ZzS.js} +1 -1
  79. package/dist/assets/useEventInvalidation-DLMOtAJP.js +1 -0
  80. package/dist/assets/{video-DuMIkvBP.js → video-DdJ2lmUL.js} +1 -1
  81. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DdAFU5xY.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-cD-zqb5y.js} +2 -2
  82. package/dist/assets/{wifi-DNsDHc6u.js → wifi-Dx0-akbW.js} +1 -1
  83. package/dist/assets/{zap-RHfxlZhI.js → zap-BLI50LGc.js} +1 -1
  84. package/dist/index.html +5 -5
  85. package/dist/server/addon.js +1 -1
  86. package/package.json +1 -1
  87. package/dist/assets/AiProfiles-DECvat8h.js +0 -3
  88. package/dist/assets/DeviceDetail-CVuY2t9Q.js +0 -2
  89. package/dist/assets/Devices-DornCZOc.js +0 -1
  90. package/dist/assets/EmbedPlayerPage-DLdvRzTy.js +0 -1
  91. package/dist/assets/Events-CEUNSnDV.js +0 -1
  92. package/dist/assets/Identity-CLAq5pc-.js +0 -1
  93. package/dist/assets/IntegrationDetail-7LmaONwQ.js +0 -1
  94. package/dist/assets/Integrations-CDPziDzI.js +0 -1
  95. package/dist/assets/Integrations-o_BOKz_C.js +0 -1
  96. package/dist/assets/Network-BAt6cJW9.js +0 -1
  97. package/dist/assets/Notifications-CwcH2yYC.js +0 -1
  98. package/dist/assets/Pipeline-C3oEXt8M.js +0 -1
  99. package/dist/assets/Recordings-CcL3TTxW.js +0 -1
  100. package/dist/assets/circle-check-big-BZnwR-f7.js +0 -1
  101. package/dist/assets/clock-fhk_ag9V.js +0 -1
  102. package/dist/assets/index-DhYfPTfU.js +0 -4
  103. package/dist/assets/play-D6bynunz.js +0 -1
  104. package/dist/assets/plus-CDo9Tbkz.js +0 -1
  105. package/dist/assets/power-BF-VFkkW.js +0 -1
  106. package/dist/assets/remoteEntry-DbX8dE3W.js +0 -1
  107. package/dist/assets/rotate-ccw-P5OXZofT.js +0 -1
  108. package/dist/assets/rotate-cw-DDRA2uuI.js +0 -1
  109. package/dist/assets/search-DhirDmpC.js +0 -1
  110. package/dist/assets/square-UC6vONGu.js +0 -1
  111. package/dist/assets/useEventInvalidation-DqKGeTpc.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-DXNKqmwI.js";import{$a as y,$t as b,A as x,Ao as S,Ar as C,B as w,Br as T,Bt as E,Ca as D,Ci as O,D as k,Eo as ee,F as A,Fr as te,G as j,Gn as ne,Gr as re,H as ie,Hi as M,Ht as ae,Jr as N,K as P,Kr as oe,L as F,La as I,Lr as L,Ma as R,N as z,O as B,Pa as se,Pr as V,Qa as ce,Qi as H,Qt as le,R as U,Si as ue,Sr as de,Tr as fe,U as W,Ur as pe,Va as me,Vt as G,W as K,Xr as he,Y as ge,Yi as _e,Yr as ve,Yt as ye,Zi as be,_t as xe,a as q,ao as Se,b as Ce,bo as we,c as Te,cn as Ee,dt as De,en as Oe,et as ke,ft as Ae,g as je,gi as Me,ht as Ne,i as Pe,j as Fe,jr as J,k as Ie,kn as Le,l as Re,lt as ze,mr as Be,mt as Ve,o as He,on as Ue,ot as We,pr as Ge,pt as Ke,q as qe,qr as Je,r as Ye,s as Xe,sn as Ze,st as Qe,tt as $e,u as et,un as tt,ut as nt,wi as rt,x as it,y as at,z as ot,zr as st,zt as ct}from"./src-C0QlPpXb.js";import{$ as lt,Ct as ut,St as dt,a as ft,i as pt,tt as Y,xt as mt}from"./src-DAigq6PX.js";import{t as ht}from"./CapabilityBadges-CByvC3eB.js";import{n as gt,t as _t}from"./bell-ring-B6JDETmm.js";import{t as vt}from"./boxes-DVDxegRH.js";import{t as yt}from"./ProviderIcon-D8aWAoj0.js";import{a as bt,c as xt,l as St,n as Ct,o as wt}from"./NodeInferenceDevices-9bqVJEiE.js";import{n as Tt}from"./FormBuilder-B-sNHhCg.js";import{t as Et}from"./pencil-dvZNet31.js";import{t as Dt}from"./power-BF-VFkkW.js";import{t as Ot}from"./refresh-cw-CikJV4hg.js";import{t as kt}from"./rotate-ccw-P5OXZofT.js";import{t as At}from"./rotate-cw-DDRA2uuI.js";import{t as jt}from"./server-CLphEdE1.js";import{t as Mt}from"./wifi-DNsDHc6u.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,a as Ht,b as Ut,c as Wt,d as Gt,g as Kt,i as qt,m as Jt,s as Yt,t as Xt,y as Zt,z as Qt}from"./index-DhYfPTfU.js";import{t as $t}from"./useEventInvalidation-DqKGeTpc.js";import{t as en}from"./StatusBadge-CeptlsPG.js";import{i as tn,n as nn,r as rn,t as an}from"./DeviceAggregateSection-iY2G54zN.js";var on=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`}]]),sn=X(`disc`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}]]),cn=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`}]]),ln=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`}]]),un=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`}]]),dn=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`}]]),fn=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 pn=[{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:mt}],mn=`Recording`,hn=`Nothing new is written to disk — live still works, existing footage is kept.`;function gn(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 _n(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 vn(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 yn(e){let t=pn.map(t=>gn(t,e)),n={id:`recording`,label:mn,costWhenOff:hn,on:e.recordingEnabled,available:e.recordingEnabled!==null,capName:null,wrapperAddonId:null};return[...t,n]}var bn={"object-detection":Kt,"audio-analysis":cn,recording:sn};function xn(e){if(typeof e!=`object`||!e)return!1;let t={...e};return typeof t.enabled==`boolean`&&Array.isArray(t.bands)}function Sn(e){if(typeof e!=`object`||!e)return!1;let t={...e};return typeof t.deviceId==`number`&&Array.isArray(t.entries)}function Cn(e){return Sn(e)?e.entries:null}function wn(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 Tn({deviceId:t}){let n=s(),i=Number.isFinite(t),[a,o]=c(null),[l,d]=c(!1),f=J({deviceId:t},{enabled:i}),p=st({deviceType:Y.Camera},{enabled:i}),m=ee({deviceId:t},{enabled:i,retry:!1});$t([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let h=[[`deviceManager`,`getBindings`],{input:{deviceId:t}}],g=[[`recording`,`getDeviceConfig`],{input:{deviceId:t}}],_=m.data,v=xn(_)?_:null,y=yn({bindings:Cn(f.data),bindable:wn(p.data),recordingEnabled:v===null?null:v.enabled}),b=he({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=S({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`]]})}}),C=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);Sn(o)&&n.setQueryData(h,_n(o,i,a,r)),b.mutate({deviceId:t,capName:i,wrapperAddonId:a,active:r})},[h,t,n,v,g,x,b]),w=vn(y,xe()),T=e=>a?.id===e.id?a.message:null;return w.layout===`menu`?r(Ke,{open:l,onOpenChange:d,children:[r(Ne,{"aria-label":`Camera functions`,title:w.summary,className:`inline-flex items-center gap-1 rounded-lg border px-2 py-1.5 text-[11px] font-medium transition-colors ${a===null?w.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(Gt,{className:`h-3.5 w-3.5`}),w.offIds.length>0&&r(`span`,{className:`rounded bg-warning/20 px-1 text-[9px] font-semibold uppercase tracking-wide`,children:[w.offIds.length,` off`]})]}),r(Ve,{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(En,{state:e,failure:T(e),onToggle:()=>C(e)})},e.id))})]})]}):u(`div`,{className:`flex items-center gap-1`,children:y.map(e=>u(Dn,{state:e,failure:T(e),onToggle:()=>C(e)},e.id))})}function En({state:e,failure:t,onToggle:n}){let i=bn[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 Dn({state:e,failure:t,onToggle:n}){let i=bn[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 On({parentDeviceId:e}){let{t}=Xt(),n=Ft(),i=m(),{data:a,isLoading:o,isError:s}=wt(e),{data:c}=V({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=Ie(c?.stableId??``,l,c?.childLayout),f=d.ungrouped,p=e=>n(`/devices/${String(e)}`),h=c?.name??``,g=(e,t)=>u(k,{trpc:i.trpcClient,device:{...t,name:Fe(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,x=d.disabledSection===void 0?null:u(B,{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?x===null?b:r(`div`,{className:`space-y-2`,children:[b,x]}):r(`div`,{className:`space-y-2`,children:[d.sections.map(e=>u(B,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>g(e.id,e))},e.title)),b,x]})}function kn({deviceId:e}){let t=m(),{data:n,isLoading:r}=bt(e),{data:i,isLoading:a}=wt(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(U,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}n();function An({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=ie(t)?.HeroCard??W,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(w,{lastChangedAt:g})}):null,u(a,{trpc:i.trpcClient,deviceId:e,features:n}),u(`div`,{className:`flex justify-center`,children:u(An,{dev:o,busy:l,setBusy:d})})]})}function jn({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(K,{trpc:m().trpcClient,deviceId:e,features:t})})}function Mn({deviceId:e,features:t}){return u(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:u(W,{trpc:m().trpcClient,deviceId:e,features:t})})}function Nn(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}function Pn(e){if(!e)return null;let t=Nn(e.data);return t===null?e.eventType:`Button ${String(t)} · ${e.eventType}`}var Fn=1e3,In=60*Fn,Ln=60*In,Rn=24*Ln;function zn(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<Fn?`just now`:n<In?`${String(Math.floor(n/Fn))}s ago`:n<Ln?`${String(Math.floor(n/In))}m ago`:n<Rn?`${String(Math.floor(n/Ln))}h ago`:`${String(Math.floor(n/Rn))}d ago`}n();var Bn=1500,Vn=15e3,Hn=1e3;function Un({deviceId:e}){let n=p(m().trpcClient,e)?.state.eventEmitter,i=f(n);d(()=>{if(!n)return;n.refresh();let e=setInterval(()=>{n.refresh()},Vn);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)},Bn);return()=>{clearTimeout(t)}},[o]);let[g,_]=c(()=>Date.now());d(()=>{let e=setInterval(()=>{_(Date.now())},Hn);return()=>{clearInterval(e)}},[]);let v=Pn(a),y=i?.eventTypes??[],b=i?.eventCountSinceStart??0,x=i!==void 0,S=Nn(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?dn:ln,{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?zn(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 Wn({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(en,{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 Gn({deviceId:e}){let t=s(),n=Ge({deviceId:e},{refetchInterval:1e4,retry:!1}),a=Be({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),o=i(()=>Kn(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(qn,{label:`Discovered`,value:o.total,icon:u(Zt,{className:`h-3.5 w-3.5`})}),u(qn,{label:`Adopted`,value:o.adopted,accent:`success`}),u(qn,{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(Jn,{icon:u(Mt,{className:`h-3 w-3 text-emerald-500`}),label:`${o.online} online`}),u(Jn,{icon:u(Ut,{className:`h-3 w-3 text-amber-500`}),label:`${o.sleeping} sleeping`}),u(Jn,{icon:u(Ht,{className:`h-3 w-3 text-destructive`}),label:`${o.offline} offline`}),o.unknown>0?u(Jn,{icon:u(on,{className:`h-3 w-3 text-foreground-subtle`}),label:`${o.unknown} unknown`}):null]})]})}function Kn(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 qn({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 Jn({icon:e,label:t}){return r(`span`,{className:`inline-flex items-center gap-1`,children:[e,u(`span`,{children:t})]})}var Yn={[Y.Switch]:Z,[Y.Siren]:Z,[Y.Light]:Z,[Y.Sensor]:Z,[Y.Button]:Z,[Y.Hub]:Gn,[Y.Cover]:jn,[Y.Valve]:Z,[Y.Humidifier]:Z,[Y.WaterHeater]:Z,[Y.Container]:kn,[Y.Lock]:Z,[Y.Fan]:Z,[Y.Thermostat]:Z,[Y.Climate]:Z,[Y.MediaPlayer]:Z,[Y.Control]:Z,[Y.AlarmPanel]:Z,[Y.EventEmitter]:Un,[Y.Notifier]:Mn,[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 Xn(e){return Yn[e]??Wn}function Zn(e){return u(Xn(e.deviceType),{...e})}function Qn(e){return He(m().trpcClient,e)}n();function $n(n){let[r,i]=c(`idle`),[a,o]=c(null),s=t(null),l=t(null),u=t(null),f=t(!0),p=O(),m=ue(),h=rt(),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 er=0;function Q(){return++er}function tr(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function nr(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 rr(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 ir(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 ar({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: ${tr(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: ${tr(n)}`}]),h(``);return}if(t===`help`){f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`},...nr(n).map(e=>({id:Q(),kind:`info`,text:e}))]),h(``);return}if(t===`context`){f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`},...ir(n).map(e=>({id:Q(),kind:`info`,text:e}))]),h(``);return}if(t===`examples`){f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`},...rr(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: ${tr(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 or({deviceId:e,intercomAvailable:t=!1}){let n=m(),r=typeof window<`u`?window.location.origin:``,i=Number.isFinite(e),a=Qn(i?e:null),{streams:s,pipelineMetrics:c,createSession:l,sendAnswer:d,handleOffer:f,getIceServers:p,addIceCandidate:_,getIceCandidates:v,closeSession:y,getSessionState:b}=q(n.trpcClient,i?e:null),x=h(i?e:null,{width:dr}),S=$n(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=Oe(),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(Te,{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 sr({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full`,children:u(ge,{...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 cr({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(ar,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function lr({deviceId:e}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:u(qe,{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 ur({deviceId:e}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:u(P,{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 dr=960;function fr({deviceId:e}){let t=s(),n=Number.isFinite(e),{data:i}=V({deviceId:e},{enabled:n}),a=typeof i?.type==`string`?i.type:`camera`;$t([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:o,isLoading:c,isError:l,error:d}=J({deviceId:e},{enabled:n}),{data:f}=st({deviceType:a},{enabled:!!a}),p=he({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($e,{columns:[{key:`capability`,header:`Capability`,render:e=>u(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>u(pr,{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(mr,{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(hr,{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 pr({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(St,{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(un,{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(xt,{className:`h-3 w-3`}),`unbound`]})}function mr({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 hr({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 gr({deviceId:e,activeSubTab:t,onSubTabChange:n}){return u(`div`,{className:`flex flex-col gap-3`,children:u(an,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}n();var _r=new Set([`package-detection`]);function vr(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 yr(e){return e?e.modelId!==void 0||e.settings!==void 0:!1}function br({deviceId:e,refreshToken:t}){let n=s(),l=m().trpcClient,[d,f]=c(null),[p,h]=c(null),[g,_]=c(null),v=R({deviceId:e},{refetchOnMount:`always`}),b=se({deviceId:e},{refetchOnMount:`always`}),x=me(void 0,{refetchOnMount:`always`});$t([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let S=_e(void 0,{refetchOnMount:`always`}),C=i(()=>{let e=new Set;for(let t of S.data??[])t.isOnline&&e.add(t.id);return e},[S.data]),w=i(()=>(x.data??[]).filter(e=>C.has(e.nodeId)).map(e=>e.nodeId),[x.data,C]),T=w[0]??``,O=D({nodeId:T},{enabled:T!==``,refetchOnMount:`always`}),k=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}}),ee=()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]})},A=ce({onSuccess:ee}),te=y({onSuccess:ee}),j=i(()=>O.data?Re(O.data):[],[O.data]),ne=i(()=>{let e=x.data??[],t=C.size===0?[]:e.filter(e=>C.has(e.nodeId)),n=[];for(let e of t){let t=(k.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:Ct(r).label});else n.push({agentNodeId:e.nodeId,engineLabel:t[0]?.format??`(engine unknown)`})}return n},[x.data,k.data,C]),re=(e,t)=>k.data?.[e]?.find(e=>e.key===t)??null,ie=e=>{if(e.deviceKey!==void 0)return e.deviceKey;let t=k.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},M=(e,t,n)=>b.data?.[e]?.[t]?.[n]??null,N=e=>{if(_r.has(e))return{kind:`zone-driven`};let t=vr(O.data??null,e)?.enabledByDefault??!0,n=v.data?.stepToggles?.[e];return{kind:`gate`,effectiveOn:n??t,defaultOn:t,explicit:n!==void 0}},P=(e,t)=>{let n=vr(O.data??null,e);if(n)return E(n,t)},oe=(e,t)=>{let n=N(e),r=n.kind===`gate`?n.effectiveOn:!1,i=vr(O.data??null,e),a=ie(t),o=a===null?null:re(t.agentNodeId,a);if(!ae(i?.models??[],o?.format))return r?{kind:`skip`}:{kind:`na`};let s=a===null?null:M(t.agentNodeId,a,e),c=o?.steps?.[e];return{kind:`enabled`,modelId:(i?G({catalog:i,device:o,override:s?.modelId,base:c?.modelId}):void 0)??`Auto`,overridden:yr(s)}},F=d&&O.data?vr(O.data,d.addonId):null,I=d?re(d.agentNodeId,d.deviceKey):null,L=I?.format??`coreml`,z=d?yr(M(d.agentNodeId,d.deviceKey,d.addonId)):!1,B=d?P(d.addonId,I):void 0,V=i(()=>{if(!d||!I)return null;let e=I.steps?.[d.addonId];return{enabled:!0,...e?.modelId===void 0?{}:{modelId:e.modelId},settings:e?.settings??{}}},[d,I]),H=()=>{f(null),h(null)},le=(e,t)=>{let n=ie(t);n!==null&&(f({addonId:e,agentNodeId:t.agentNodeId,deviceKey:n}),h(M(t.agentNodeId,n,e)))},U=(t,n)=>{te.mutate({deviceId:e,addonId:t,enabled:n})},ue=()=>{d&&A.mutate({deviceId:e,agentNodeId:d.agentNodeId,deviceKey:d.deviceKey,addonId:d.addonId,patch:p},{onSuccess:H})},de=()=>{d&&A.mutate({deviceId:e,agentNodeId:d.agentNodeId,deviceKey:d.deviceKey,addonId:d.addonId,patch:null},{onSuccess:H})};if(x.isLoading||T!==``&&O.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(!O.data)return u(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let fe=d!==null&&F!==null&&I!==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:fe?`md:pr-[360px]`:``,children:j.length>0?u(it,{tree:j,agents:ne,gateFor:N,getCellState:oe,onCellClick:le,selectedCell:d,onSetGate:U,gateBusy:te.isPending,fallbackNodeId:g,onFallbackNodeChange:_}):u(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),u(et,{open:fe,onClose:H,title:F?.name??``,subtitle:d&&I?`${d.agentNodeId} · ${Ct(I).label} · ${I.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:!z||A.isPending,onClick:de,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:H,children:`Cancel`}),u(`button`,{type:`button`,disabled:!d||!V||A.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:ue,children:A.isPending?`Saving…`:`Save`})]}),children:F&&d&&V?u(ct,{mode:`device`,addon:F,agentDefault:V,agentNodeId:d.agentNodeId,currentPatch:p,engineFormat:L,effectiveModelId:B,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 xr=[{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`}],Sr={"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 Cr(e){return Sr[e]??`object-detection`}n();var wr=`steps`,Tr=`settings`,Er=new Set([wr,Tr]);function Dr(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}function Or({deviceId:t,activeSubTab:n,onSubTabChange:i}){return r(ze,{value:n&&Er.has(n)?n:wr,onValueChange:e(e=>{i?.(e)},[i]),className:`flex flex-col`,children:[r(De,{className:`flex-shrink-0`,children:[u(Ae,{value:wr,children:`Steps`}),u(Ae,{value:Tr,children:`Settings`})]}),u(nt,{value:wr,children:u(br,{deviceId:t,refreshToken:0})}),u(nt,{value:Tr,children:u(an,{deviceId:t,sectionFilter:Dr,subTabGrouping:{groupOf:e=>Cr(e.id),tabs:xr}})})]})}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 kr({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=Je({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 Ar({deviceId:e,initialLocation:n}){let a=s(),[o,l]=c(!1),[f,p]=c(n??``),[m,h]=c(!1),g=t(null),{data:_}=T(void 0,{enabled:o}),v=_??[];d(()=>{o||p(n??``)},[n,o]),d(()=>{o&&g.current?.focus()},[o]);let y=oe({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 jr({deviceId:e}){let t=s(),{data:n}=bt(e),{data:i}=wt(e),[a,l]=c(null),d=N({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(F,{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 Mr=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function Nr(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function Pr(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function Fr(){let e=Ze(),t=Ee(),{data:n}=V({deviceId:e??0},{enabled:e!==null}),{data:i}=J({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(Ir,{active:o===`identity`,onClick:()=>s(`identity`),label:`Identity`}),u(Ir,{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(kr,{deviceId:e,initialName:d}),u(Ar,{deviceId:e,initialLocation:v}),u(jr,{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(Lr,{metadata:y})]})}function Ir({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 Lr({metadata:e}){let t=Mr.filter(t=>t in e),n=Object.keys(e).filter(e=>!Mr.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:Nr(t),value:u(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:Pr(e[t])})},t))})]})}var Rr=`Notifications`,zr=`This camera never notifies — no rule, no target, no alarm. Existing events, tracks and recordings are unaffected.`;function Br(e){let{mutedDeviceIds:t,deviceId:n}=e,r=t===null?null:!t.includes(n),i=e.pendingOn??null;return{label:Rr,on:r===null?null:i??r,available:r!==null,costWhenOff:zr}}function Vr(e,t){return!e.available||e.on===null?null:{deviceId:t,muted:e.on}}n();function Hr(e){if(typeof e!=`object`||!e)return null;let t={...e}.mutedDeviceIds;return Array.isArray(t)?t.filter(e=>typeof e==`number`):null}function Ur({deviceId:t}){let n=s(),i=Number.isFinite(t),[a,o]=c(null),[l,d]=c(null),f=Br({mutedDeviceIds:Hr(be({},{enabled:i}).data),deviceId:t,pendingOn:l}),p=H({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=Vr(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 Wr({deviceId:e}){let[t,n]=c(null),i=de({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 Gr={icon:``,label:``,unit:``,precision:``,hidden:!1};function Kr(e){return{icon:e?.icon??``,label:e?.label??``,unit:e?.unit??``,precision:e?.precision===void 0?``:String(e.precision),hidden:e?.hidden===!0}}function qr(e){if(typeof e!=`object`||!e)return;let t=e.unit;return typeof t==`string`?t:void 0}function Jr(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 Yr({deviceId:e}){let t=m(),n=s(),{data:a}=V({deviceId:e},{enabled:e>0}),o=typeof a?.role==`string`?a.role:null,l=o===null?void 0:j[o],d=l?.kind===`numeric`,f=Ye(t.trpcClient,e,o??``),p=l?.kind===`numeric`?l.canonicalUnit:void 0,h=qr(f)??p,g=h===void 0?void 0:pt(h),_=i(()=>g===void 0?[]:ft(g),[g]),[v,y]=c(null),b=v??Kr(a?.display),x=re({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),{data:S}=L({},{staleTime:6e4}),C=ve({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}});if(a===void 0||o===null)return null;let w=e=>{y({...b,...e})},T=()=>{x.mutate({deviceId:e,display:Jr(b)})},E=()=>{y(Gr),x.mutate({deviceId:e,display:null})},D=()=>{let e={...b.icon===``?{}:{icon:b.icon},...b.unit===``?{}:{unit:b.unit},...b.precision.trim()!==``&&Number.isFinite(Number.parseInt(b.precision,10))?{precision:Number.parseInt(b.precision,10)}:{}},t={...S?.defaults,[o]:e};C.mutate({defaults:t})},O=A(o).label,k=Object.keys(z);return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,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:`Display`})}),r(`div`,{className:`p-4 space-y-3`,children:[r(`label`,{className:`block`,children:[u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Icon`}),r(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,value:b.icon,onChange:e=>w({icon:e.target.value}),children:[r(`option`,{value:``,children:[`Default (`,O,`)`]}),k.map(e=>u(`option`,{value:e,children:e},e))]})]}),r(`label`,{className:`block`,children:[u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Label`}),u(`input`,{type:`text`,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,placeholder:O,value:b.label,onChange:e=>w({label:e.target.value})})]}),d&&r(`div`,{className:`grid grid-cols-2 gap-3`,children:[r(`label`,{className:`block`,children:[u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Unit`}),r(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,value:b.unit,onChange:e=>w({unit:e.target.value}),disabled:_.length===0,children:[r(`option`,{value:``,children:[`Source`,h?` (${h})`:``]}),_.map(e=>u(`option`,{value:e,children:e},e))]})]}),r(`label`,{className:`block`,children:[u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Precision`}),u(`input`,{type:`number`,min:0,max:10,step:1,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,placeholder:`inherit`,value:b.precision,onChange:e=>w({precision:e.target.value})})]})]}),r(`label`,{className:`flex items-center gap-2`,children:[u(`input`,{type:`checkbox`,checked:b.hidden,onChange:e=>w({hidden:e.target.checked})}),u(`span`,{className:`text-sm text-foreground`,children:`Hide from device lists`})]}),r(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[u(`button`,{type:`button`,className:`rounded bg-primary px-3 py-1 text-sm font-medium text-primary-foreground disabled:opacity-50`,onClick:T,disabled:x.isPending,children:`Save`}),u(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:E,disabled:x.isPending,children:`Reset`}),r(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:D,disabled:C.isPending,title:`Apply this unit / precision / icon as the default for every ${O} sensor`,children:[`Set as default for all `,O,` sensors`]})]})]})]})}function Xr(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function Zr({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(lt.Resyncable),{data:d}=M({deviceId:n??0},{enabled:n!==null&&a,refetchInterval:5e3}),f=d?.streams??{},p=Object.entries(f),m=c.includes(lt.DoorbellButton),h=Pe(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(Ce,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),l&&n!==null&&u(Wr,{deviceId:n}),n!==null&&u(Ur,{deviceId:n}),a&&n!==null&&u(ye,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),m&&u(at,{history:h.history,latestIsFresh:g}),a&&n!==null&&u(ye,{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(Qr,{label:`Nominal`,value:Xr(t.nominalBitrateKbps??0)}),u(Qr,{label:`Observed`,value:Xr(t.observedBitrateKbps??0)}),u(Qr,{label:`Peak`,value:Xr(t.peakBitrateKbps??0)}),u(Qr,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),u(Fr,{}),s&&n!==null&&u(Yr,{deviceId:n})]})}function Qr({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 $r=[{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 ei(e){let t=e===Y.Camera;return $r.filter(e=>t||!e.cameraOnly).map(({id:e,label:t})=>({id:e,label:t}))}var ti=[{id:`logs`,icon:Jt,label:`Logs`},{id:`repl`,icon:Wt,label:`REPL`},{id:`events`,icon:Rt,label:`Events`},{id:`state`,icon:It,label:`State`}];function ni(){let n=Vt(),a=Number(n.deviceId),l=Number.isFinite(a),d=Ft(),f=s(),h=tt(),g=m(),[v,y]=Bt(),S=v.get(`tab`)??`overview`,w=v.get(`sub`),[T,E]=c(`logs`),D=`device-detail.left-col-width-px`,[O,k]=c(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(D),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),ee=t(O);ee.current=O;function A(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??O??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{k(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=ee.current;if(e!==null)try{window.localStorage.setItem(D,String(Math.round(e)))}catch{}document.body.style.userSelect=``,document.body.style.cursor=``};document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,document.addEventListener(`mousemove`,i),document.addEventListener(`mouseup`,a)}let{data:j,isLoading:re,isError:ie}=V({deviceId:a},{enabled:l,refetchInterval:5e3,retry:1}),{data:M}=te({deviceId:a},{enabled:l}),ae=i(()=>{let e=M?.settings?.sections??[],t=M?.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(tn)&&r.add(nn),[...r].map(e=>e===`export`?{id:e,label:rn,isAddonContrib:!0}:{id:e,label:ut[e]?.label??e,isAddonContrib:!0})},[M]),N=j,P=String(N?.name??n.deviceId??`Device`),oe=N?.online===!0,F=oe?`online`:`offline`,L=String(N?.addonId??`rtsp`),R=N?.features??[],z=N?.type,B=z===Y.Camera,{data:se}=wt(l?a:0),ce=z===Y.Container,H=i(()=>(se??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[se]),U=i(()=>ce?ot(H,typeof N?.linkDeviceId==`number`?N.linkDeviceId:null,typeof N?.primaryChildEntityId==`string`?N.primaryChildEntityId:null)?.id??null:null,[ce,H,N?.linkDeviceId,N?.primaryChildEntityId]),{data:ue}=te({deviceId:U??0},{enabled:U!==null}),de=i(()=>{if(U===null)return[];let e=ue?.settings?.sections??[],t=ue?.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:ut[e]?.label??e,isAddonContrib:!0,childDeviceId:U}))},[U,ue]),W=typeof N?.parentDeviceId==`number`?N.parentDeviceId:null,{data:me}=V({deviceId:W??0},{enabled:W!==null}),G=xe(),K=N?.disabled!==!0,he=i(()=>{let e=new Set,t=[];for(let n of[...ei(z),...ae,...de])e.has(n.id)||(e.add(n.id),t.push(n));return t},[z,ae,de]),ge=i(()=>he.some(e=>e.id===S)?S:`overview`,[he,S]),_e=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]),ve=e(e=>{y(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[y]),ye=(se??[]).length>0,be=i(()=>ti.filter(({featureGate:e})=>!e||R.includes(e)),[R]),{data:q}=Me({addonId:L},{enabled:!!L&&L!==`rtsp`}),Ce=pe({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]}),d(q?.id?`/integrations/${q.id}`:`/integrations`)}}),Te=C({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ee=fe({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),De=we(),Oe=Le({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ke=R.includes(lt.Rebootable),Ae=R.includes(lt.BatteryOperated),Ne=x(g.trpcClient,Ae&&l?a:null),[Pe,Fe]=c(!1),J=p(g.trpcClient,l?a:null),Ie=async()=>{if(!(Pe||!J)){Fe(!0);try{await J.snapshot?.invalidateCache({});let e=await J.snapshot?.getSnapshot({});if(!e)return;let t=`data:${e.contentType};base64,${e.base64}`,n=e.contentType.includes(`png`)?`png`:`jpg`,r=P.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{Fe(!1)}}},Re=Te.isPending||Ee.isPending,{data:ze}=I({deviceId:a},{enabled:l,refetchInterval:1e4}),Be=ze?.agentNodeId??null,Ve=typeof Be==`string`&&Be.length>0&&!Be.startsWith(`addon:`)?Be:void 0,{data:He}=Se({deviceId:a,...Ve?{nodeId:Ve}:{}},{enabled:l,refetchInterval:3e3,retry:!1}),{data:Ge}=ne({deviceId:a},{enabled:l,refetchInterval:3e3,retry:!1}),Ke=Ge?.level?.dbfs??null;function qe(){if(!l)return null;switch(ge){case`overview`:return u(Zr,{device:N??{}});case`config`:return u(gr,{deviceId:a,activeSubTab:w,onSubTabChange:ve});case`detection-pipeline`:return u(Or,{deviceId:a,activeSubTab:w,onSubTabChange:ve});case`bindings`:return u(fr,{deviceId:a});default:{let e=ge,t=ae.some(t=>t.id===e),n=de.find(t=>t.id===e);if(!t&&n===void 0)return null;let r=n?.childDeviceId??a;if(e===`export`)return u(an,{deviceId:a,sectionFilter:tn,activeSubTab:w,onSubTabChange:ve});let i=u(an,{deviceId:r,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:w,onSubTabChange:ve});return n!==void 0&&r!==a?u(Ue,{deviceId:r,children:i}):i}}}return l?re?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`})})]}):ie||!j?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(We,{items:[{label:`Integrations`,onClick:()=>d(`/integrations`)},{label:q?.name??L,onClick:()=>q?.id&&d(`/integrations/${q.id}`)},{label:P}]})}),r(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[u(yt,{type:L,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:P}),u(en,{status:F}),Ae&&u(Qe,{status:Ne,variant:`full`})]}),W!==null&&me&&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 ${me.name}`,children:[u(`span`,{children:`↑`}),u(`span`,{className:`truncate`,children:String(me.name??`Device #${W}`)})]}),u(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:R.length>0&&u(ht,{capabilities:R})})]}),He&&u(`div`,{className:`hidden lg:flex`,children:u(ri,{metrics:He,dbfs:Ke})}),r(`div`,{className:`flex items-center gap-1 shrink-0`,children:[r(`button`,{onClick:async()=>{K?await h({title:`Disable "${P}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&Ee.mutate({deviceId:a}):Te.mutate({deviceId:a})},disabled:Re,title:K?`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 ${K?`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:Re?`Updating…`:K?`Enabled`:`Disabled`})]}),u(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),B&&r(o,{children:[u(Tn,{deviceId:a}),u(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`})]}),u(je,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:zt,disabled:Pe,onClick:()=>{Ie()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:At,hidden:!ke,disabled:De.isPending,danger:!0,onClick:async()=>{await h({title:`Reboot "${P}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&De.mutate({deviceId:a})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${q?.name??L}.`,icon:Ot,disabled:Oe.isPending,danger:!0,onClick:async()=>{await h({title:`Restart "${q?.name??L}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${P}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&Oe.mutate({addonId:L})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:Yt,separatorBefore:!0,disabled:Ce.isPending,danger:!0,onClick:async()=>{await h({title:`Delete "${P}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&Ce.mutate({deviceId:a})}}]})]})]})]}),u(Ue,{deviceId:a,device:N??void 0,children:u(b,{children:u(le,{children:u(_,{children:u(Xe,{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`:`${O===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!G&&O!==null?{width:`${String(O)}px`}:void 0,children:[u(`div`,{className:B?`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:B?u(or,{deviceId:a,intercomAvailable:R.includes(lt.TwoWayAudio)}):u(Zn,{deviceId:a,deviceName:P,deviceType:z??`unknown`,provider:L,isOnline:oe,features:R})}),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:()=>E(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${T===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:[T===`logs`&&u(sr,{deviceId:a,containerDeviceId:z===`container`?a:void 0}),T===`repl`&&u(cr,{deviceId:a}),T===`events`&&u(lr,{deviceId:a}),T===`state`&&u(ur,{deviceId:a})]})]})]}),!G&&u(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:A,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:he.map(e=>{let t=ge===e.id;return r(`button`,{onClick:()=>_e(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:[ge===`overview`&&ye&&u(On,{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 ri({metrics:e,dbfs:t}){let n=ke(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(fn,{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{ni as DeviceDetailPage};
@@ -1 +0,0 @@
1
- import{I as e,Q as t,S as n,W as r,o as i,x as a}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as o}from"./player-overlays-DXNKqmwI.js";import{Ar as s,Rr as c,T as l,Tr as u,Ur as d,vi as f}from"./src-C0QlPpXb.js";import{t as p}from"./ProviderIcon-D8aWAoj0.js";import{J as m,V as h,o as g,t as _}from"./index-DhYfPTfU.js";import{t as v}from"./AdminPage-CCD07UMs.js";import{t as y}from"./useEventInvalidation-DqKGeTpc.js";t();var b=32;function x(e,t){if(t===null)return{activeDevices:e,orphanDevices:[]};let n=e=>typeof e.addonId==`string`&&e.addonId.length>0&&!t.has(e.addonId),r=new Set;for(let t of e)n(t)&&r.add(t.id);let i=new Map;for(let t of e)i.set(t.id,t);let a=(e,t=0)=>{if(t>b)return!1;if(r.has(e.id))return!0;if(e.parentDeviceId==null)return!1;let n=i.get(e.parentDeviceId);return n?a(n,t+1):!1},o=[],s=[];for(let t of e)a(t)?s.push(t):o.push(t);return{activeDevices:o,orphanDevices:s}}function S(){let{t}=_(),b=m(),S=o(),C=i();y([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]),y([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`]);let{data:w}=c({}),{data:T}=f(void 0),E=d({onSuccess:()=>{C.invalidateQueries({queryKey:[[`deviceManager`]]})}}),D=u({onSuccess:()=>{C.invalidateQueries({queryKey:[[`deviceManager`]]})}}),O=s({onSuccess:()=>{C.invalidateQueries({queryKey:[[`deviceManager`]]})}}),k=r(()=>w??[],[w]),{activeDevices:A,orphanDevices:j}=r(()=>x(k,T===void 0?null:new Set(T.map(e=>e.addonId))),[k,T]),M=r(()=>{let e=new Map;for(let t of k)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[k]),N=e(e=>M.get(e)??null,[M]),P=r(()=>(T??[]).map(e=>({id:e.addonId,name:e.name??e.addonId,icon:a(p,{type:e.addonId,size:`sm`})})),[T]),F=e(e=>a(p,{type:e,size:`sm`}),[]),I=e(e=>b(`/devices/${String(e)}`),[b]);return n(v,{icon:h,title:t(`nav.devices`,`Devices`),children:[a(l,{context:`devices`,devices:A,trpc:S.trpcClient,filters:{addons:P},resolveIntegrationIcon:F,resolveParent:N,onNavigate:I,batchActions:{remove:E.mutate,disable:D.mutate,enable:O.mutate}}),j.length>0&&n(`div`,{className:`mt-6 space-y-2`,children:[n(`div`,{className:`flex items-baseline gap-2`,children:[a(g,{className:`h-3.5 w-3.5 text-warning shrink-0`}),a(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Orphan devices`}),n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[j.length,` device`,j.length===1?``:`s`,` pointing at integrations no longer registered`]})]}),n(`div`,{className:`rounded-lg border border-warning/30 bg-warning/5 p-2`,children:[a(`p`,{className:`text-[11px] text-foreground-subtle px-2 pb-2`,children:"These devices reference an addonId that has no matching integration. Delete them, or re-install the missing integration to bring them back online. The provider scope (`addonId`) shown beside each row is what's failing to resolve."}),a(l,{context:`devices`,devices:j,trpc:S.trpcClient,filters:{addons:P},urlScope:`nested`,lsKey:`devices:orphan`,resolveIntegrationIcon:F,resolveParent:N,onNavigate:I})]})]})]})}export{S as DevicesPage};
@@ -1 +0,0 @@
1
- import{Q as e,S as t,W as n,d as r,q as i,u 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{Y as c}from"./player-overlays-DXNKqmwI.js";import{$ as l,As as u,a as d,at as f}from"./src-C0QlPpXb.js";import{vt as p}from"./src-DAigq6PX.js";import{D as m,E as h,N as g,j as _,v,w as y}from"./__vite-browser-external-B6qJ4svC.js";e();var b=g([m({kind:y(`adaptive`)}),m({kind:y(`profile`),profile:p})]),x=m({serverUrl:_().min(1),token:_().min(1),deviceId:h().int().nonnegative(),target:b,muted:v()});function S(e,t){let n=t===void 0?{type:`state`,state:e}:{type:`state`,state:e,message:t};window.ReactNativeWebView?.postMessage(JSON.stringify(n))}function C(e){switch(e){case`playing`:return`playing`;case`error`:return`error`;case`connecting`:case`disconnected`:case`idle`:return`connecting`}}function w(e){return e.kind===`adaptive`?{kind:`adaptive`}:{kind:`profile`,profile:e.profile}}function T(e){return e.kind===`adaptive`?`embed:adaptive`:`embed:profile:${e.profile}`}function E(){let e=window.__CAMSTACK_EMBED__;if(e==null)return{ok:!1,error:`window.__CAMSTACK_EMBED__ is not set`};let t=x.safeParse(e);return t.success?{ok:!0,config:t.data}:{ok:!1,error:t.error.issues.map(e=>`${e.path.join(`.`)||`(root)`}: ${e.message}`).join(`; `)}}function D({message:e}){return s(()=>{S(`error`,e)},[e]),t(`div`,{style:{position:`fixed`,inset:0,display:`flex`,alignItems:`center`,justifyContent:`center`,background:`#000`,color:`#f87171`,fontFamily:`system-ui, sans-serif`,fontSize:13,padding:16,textAlign:`center`},children:[`Embed config error: `,e]})}function O({system:e,deviceId:t,initialTarget:r,initialMuted:a}){let[c,l]=i(r),[u,p]=i(a),{handleOffer:m,getIceServers:h,addIceCandidate:g,getIceCandidates:_,closeSession:v,getSessionState:y}=d(e.trpcClient,t),x=n(()=>w(c),[c]),E=n(()=>(e,t)=>m(x,e,t),[m,x]),D=n(()=>(e,t,n)=>m(n,t,e),[m]);s(()=>(window.__camstackEmbed={setMuted:e=>p(e),setTarget:e=>{let t=b.safeParse(e);t.success&&l(t.data)}},()=>{window.__camstackEmbed&&delete window.__camstackEmbed}),[]);let O=T(c);return o(`div`,{style:{position:`fixed`,inset:0,width:`100vw`,height:`100vh`,background:`#000`},children:o(f,{serverUrl:e.serverUrl,streamKey:O,autoPlay:!0,muted:u,showControls:!1,className:`w-full h-full`,handleOffer:E,reoffer:D,getSessionState:y,getIceServers:h,addIceCandidate:g,getIceCandidates:_,closeSession:v,onStateChange:e=>S(C(e)),onError:e=>S(`error`,e)},O)})}function k(){let e=n(()=>E(),[]),t=n(()=>e.ok?{system:l({serverUrl:e.config.serverUrl,token:e.config.token}),queryClient:new r({defaultOptions:{queries:{retry:!1,refetchOnWindowFocus:!1}}})}:null,[e]);return s(()=>{if(t)return()=>{t.system.close()}},[t]),e.ok?t?o(c,{system:t.system,children:o(a,{client:t.queryClient,children:o(u.Provider,{client:t.system.trpcClient,queryClient:t.queryClient,children:o(O,{system:t.system,deviceId:e.config.deviceId,initialTarget:e.config.target,initialMuted:e.config.muted})})})}):o(D,{message:`Failed to initialise the embed player`}):o(D,{message:e.error})}export{k as EmbedPlayerPage};
@@ -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-DXNKqmwI.js";import{$i as m,Dt as h,Ft as g,It as _,Lt as v,M as y,Pt as b,Rr as x,Rt as S,Tn as C,Ts as w,Tt as T,Xt as E,_ as D,_a as O,aa as k,ca as A,da as j,fa as M,ga as N,ha as P,ks as F,na as I,oa as L,pa as ee,ra as R,sa as z,ta as B,ua as te,v as V,va as ne,ya as H,zi as U}from"./src-C0QlPpXb.js";import{K as W,Tt as re,tt as G}from"./src-DAigq6PX.js";import{t as ie}from"./clock-fhk_ag9V.js";import{t as ae}from"./copy-EKhXmX92.js";import{t as oe}from"./download-BChaquac.js";import{a as se,c as K,d as ce,f as le,i as ue,m as de,n as fe,o as pe,p as me,r as he,s as ge,t as _e}from"./debounced-invalidate-BQ8ML6Ah.js";import{t as ve}from"./refresh-cw-CikJV4hg.js";import{t as ye}from"./search-DhirDmpC.js";import{t as be}from"./square-check-big-B4oQsHOX.js";import{t as xe}from"./square-UC6vONGu.js";import{t as Se}from"./star-Ch9uuiCl.js";import{t as Ce}from"./undo-2-DLrLmKUr.js";import{C as q,G as we,I as Te,K as J,O as Ee,P as De,R as Oe,i as ke,l as Ae,s as je,t as Me,z as Ne}from"./index-DhYfPTfU.js";import{t as Pe}from"./AdminPage-CCD07UMs.js";import{i as Fe,n as Ie,t as Le}from"./authed-media-BPd_L9jr.js";import{t as Re}from"./AdminTabs-D6yDsobg.js";var ze=J(`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`}]]),Be=J(`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`}]]),Ve=J(`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`}]]),He=J(`circle`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),Ue=J(`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`}]]),We=J(`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`}]]),Ge=J(`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`}]]),Ke=J(`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();var qe=`pipeline-analytics`,Je=`debug.listTracks`,Ye=`debug.analyze`,Xe=`/addon/pipeline-analytics/debug-export`;function Ze(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Qe(e,t){let n=e[t];return typeof n==`string`?n:null}function Y(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function $e(e,t){let n=e[t];return typeof n==`boolean`?n:null}function et(e){return e===`error`||e===`warn`||e===`info`}function tt(e){if(!Ze(e))return null;let t=Qe(e,`code`),n=Qe(e,`detail`),r=e.severity;return t===null||n===null||!et(r)?null:{code:t,severity:r,detail:n}}function nt(e){if(!Ze(e))return null;let t=Qe(e,`trackId`),n=Y(e,`deviceId`),r=Qe(e,`className`),i=Y(e,`firstSeen`),a=Y(e,`lastSeen`),o=Y(e,`durationMs`),s=$e(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=Qe(e,`label`);return{trackId:t,deviceId:n,className:r,...c===null?{}:{label:c},firstSeen:i,lastSeen:a,durationMs:o,active:s}}function rt(e){let t=nt(e);if(t===null||!Ze(e))return null;let n=Y(e,`mediaCount`),r=Y(e,`eventCount`),i=Y(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=tt(e);t!==null&&c.push(t)}return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c}}function it(e){if(!Ze(e))return null;let t=$e(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=nt(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function at(e){if(!Ze(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=rt(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var ot={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`};function st(e){return ot[e]??e}var ct={error:0,warn:1,info:2};function lt(e){return e.toSorted((e,t)=>ct[e.severity]-ct[t.severity]||e.code.localeCompare(t.code))}function ut(e){return e.length===0?Xe:`${Xe}?deviceIds=${e.join(`,`)}`}function dt(e){if(e<1e4)return`${(e/1e3).toFixed(1)}s`;let t=Math.round(e/1e3);if(t<60)return`${String(t)}s`;let n=Math.floor(t/60);return`${String(n)}m ${String(t%60).padStart(2,`0`)}s`}var ft=`all`,pt=`The server answered in a shape this build does not understand.`,mt={error:`danger`,warn:`warning`,info:`info`};function ht({findings:e}){return e.length===0?d(v,{variant:`success`,children:`no anomaly found`}):d(`div`,{className:`flex flex-wrap gap-1`,children:lt(e).map(e=>d(v,{variant:mt[e.severity],title:e.detail,children:st(e.code)},e.code))})}function gt({track:e,report:t,cameraName:n,analyzing:i}){return r(`div`,{className:`flex flex-col gap-1.5 border-b border-border px-3 py-2.5 last:border-b-0`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[d(`span`,{className:`font-medium text-foreground`,children:n}),d(`span`,{className:`text-foreground-subtle`,children:e.label??e.className}),r(`span`,{className:`text-foreground-subtle`,children:[new Date(e.lastSeen).toLocaleString(),` · `,dt(e.durationMs)]}),e.active&&d(v,{variant:`default`,children:`still open`}),t!==void 0&&r(`span`,{className:`text-foreground-subtle`,children:[String(t.mediaCount),` media · `,String(t.eventCount),` events ·`,` `,String(t.positionCount),` positions`]})]}),d(`div`,{className:`flex items-center gap-2`,children:t===void 0?d(`span`,{className:`text-xs text-foreground-subtle`,children:i?`analysing…`:`not analysed`}):d(ht,{findings:t.findings})}),d(`code`,{className:`text-[10px] text-foreground-subtle`,children:e.trackId})]})}function _t(){let e=p(),[t,n]=u(ft),[i,s]=u(!1),[c,l]=u(null),f=x({}),m=a(()=>[{value:ft,label:`All cameras`},...(f.data??[]).map(e=>({value:String(e.id),label:e.name}))],[f.data]),h=a(()=>{let e=new Map;for(let t of f.data??[])e.set(t.id,t.name);return e},[f.data]),g=a(()=>t===ft?[]:[Number.parseInt(t,10)],[t]),v=o({queryKey:[`events-debug`,`list`,g],queryFn:async()=>it(await e.trpcClient.addons.custom.mutate({addonId:qe,action:Je,input:g.length===0?{}:{deviceIds:g}}))}),y=a(()=>(v.data?.tracks??[]).map(e=>e.trackId),[v.data]),C=o({queryKey:[`events-debug`,`analyze`,y],enabled:y.length>0,queryFn:async()=>at(await e.trpcClient.addons.custom.mutate({addonId:qe,action:Ye,input:{trackIds:y}}))}),w=a(()=>{let e=new Map;for(let t of C.data?.reports??[])e.set(t.trackId,t);return e},[C.data]),T=()=>{v.refetch(),C.refetch()},D=async()=>{s(!0),l(null);try{await Ie(ut(g),`camstack-debug.zip`)}catch(e){l(e instanceof Error?e.message:`Export failed.`)}finally{s(!1)}},O=v.data?.tracks??[],k=v.data===null||C.data===null;return d(Pe,{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(b,{value:t,options:m,onChange:e=>n(e.target.value)})}),r(S,{variant:`secondary`,onClick:T,disabled:v.isFetching,children:[v.isFetching?d(q,{className:`h-3.5 w-3.5 animate-spin`}):d(ve,{className:`h-3.5 w-3.5`}),`Refresh`]}),r(S,{onClick:()=>void D(),disabled:i||O.length===0,children:[i?d(q,{className:`h-3.5 w-3.5 animate-spin`}):d(oe,{className:`h-3.5 w-3.5`}),`Export all (`,String(O.length),`)`]})]}),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.`]}),v.isError&&d(E,{message:`Could not load the marked tracks.`}),k&&!v.isError&&d(E,{message:pt}),c!==null&&d(E,{message:c}),v.data?.truncated===!0&&d(E,{message:`A camera filled the per-camera cap — some marked tracks are not listed. Un-mark a few, or filter to one camera.`}),(C.data?.vanished.length??0)>0&&r(`p`,{className:`text-xs text-foreground-subtle`,children:[String(C.data?.vanished.length),` marked track(s) were evicted between the list and the analysis.`]}),d(_,{children:v.isLoading?d(`div`,{className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`Loading…`}):O.length===0?r(`div`,{className:`flex flex-col items-center gap-2 px-3 py-8 text-center`,children:[d(Be,{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.`})]}):O.map(e=>d(gt,{track:e,report:w.get(e.trackId),cameraName:h.get(e.deviceId)??`Camera ${String(e.deviceId)}`,analyzing:C.isFetching},e.trackId))})]})})}function vt(e){return e.subLabel??e.label}var yt=720*60*60*1e3;function bt(e){let t=[];for(let n of e)t.push(...n);return t}function xt(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function St(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 Ct(e,t){return`${String(e)}:${t}`}function wt(e,t){let n=new Map,r=new Set;for(let i of e){let e=Ct(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-yt,until:e.toMs??t}}var Et=typeof B==`function`,Dt=`Track deletion arrives with the next server update`;function Ot(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var kt=Et?B:Ot,At=200,jt=3e4;function Mt(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:jt,refetchInterval:jt,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEvents.query({deviceId:n,since:e.since,until:e.until,limit:At,...e.minImportance===void 0?{}:{minImportance:e.minImportance},...e.classFilter===void 0?{}:{classFilter:e.classFilter}})).map(e=>({...e,deviceId:n}))}))});return{rows:xt(bt(n.map(e=>e.data??[])),`importance`),isLoading:n.some(e=>e.isLoading)}}n();var Nt=[`events-feed`],Pt=2e3;function Ft(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:Nt})},[]),p=t(void 0);p.current||=_e({delayMs:Pt,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 F(re.PipelineAnalyticsDetectionEvent,()=>{p.current?.trigger()}),F(re.PipelineAnalyticsTrackEnded,()=>{p.current?.trigger()}),{pending:s,refreshNow:m}}n();function It({groups:e,selected:t,onChange:n,loading:i=!1}){let{t:o}=Me(),[s,c]=u(!1),[l,f]=u(``),[p,m]=u(new Set),h=l.trim().toLowerCase(),g=e=>h.length===0||D(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(Ke,{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(ye,{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=V(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:D(e.macro,o)})]})]}),i&&e.subs.map(e=>{let n=V(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:D(e,o)})]},e.kind)})]},e.macro.kind)})]})]})}function Lt(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 Rt(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var zt=new Set([`detection`,`package`]);function Bt(e,t){return[...Lt(e,t).values()].filter(e=>e.parentKind===null&&zt.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function Vt(e,t){let n=Lt(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,Rt(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();var Ht=1400,Ut=`Admin-gated URL — opens only inside an authenticated session`;function Wt({label:t,value:n,title:i}){let[a,o]=u(!1);return f(()=>{if(!a)return;let e=setTimeout(()=>o(!1),Ht);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?Ne:ae,{className:`h-2.5 w-2.5 shrink-0`}),d(`span`,{className:`truncate`,children:a?`Copied`:t})]})}function Gt({localUrl:e,publicUrl:t}){return r(`div`,{className:`flex flex-wrap gap-1`,children:[d(Wt,{label:`Local`,value:e,title:`Copy LAN URL — ${Ut}`}),t&&d(Wt,{label:`Public`,value:t,title:`Copy public URL — ${Ut}`})]})}var Kt={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 qt(e){return e in Kt}function Jt(e){return qt(e)?Kt[e]:e}function Yt(e,t){return`${e}${Le}/${encodeURIComponent(t)}`}n();var Xt=3e4;function Zt(t){let[n,r]=u(null),i=e(e=>{r(t=>t??e)},[]);return f(()=>{t||r(null)},[t]),{publicOrigin:n,probes:t?d(Qt,{onOrigin:i}):null}}function Qt({onOrigin:e}){let{data:t}=C({capName:`network-access`});return d(s,{children:(t??[]).map(t=>d($t,{addonId:t.addonId,onOrigin:e},t.addonId))})}function $t({addonId:e,onOrigin:t}){let{data:n}=U({addonId:e},{refetchInterval:Xt,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 en=typeof H==`function`,tn=`Track flags arrive with the next server update`;function nn(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var rn=en?H:nn;function an(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 on({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 sn({deviceId:e,trackId:t,markForTrain:n,debug:i,favourited:a,onChange:o}){let s=rn(),[c,l]=u(null),f=c?.markForTrain??n===!0,p=c?.debug??i===!0,m=c?.favourited??a===!0,h=!en||s.isPending,g=en?void 0:tn,_=n=>{h||(async()=>{try{let r=an(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(on,{label:`Mark for training`,hint:`Keeps this track and its media past retention`,checked:f,disabled:h,...g===void 0?{}:{title:g},icon:d(We,{className:`h-4 w-4`}),onToggle:()=>_({markForTrain:!f})}),d(on,{label:`Debug`,hint:`Flag this track for diagnostic attention`,checked:p,disabled:h,...g===void 0?{}:{title:g},icon:d(Be,{className:`h-4 w-4`}),onToggle:()=>_({debug:!p})}),d(on,{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 X=100,cn=120,ln={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Z=e=>e<0?0:e>1?1:e,Q=e=>Math.round(e*100)/100;function un(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 dn(e,t,n){if(e.length===0||t===null)return ln;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return ln;let a=un(e,n?.maxPoints??cn).map(e=>({x:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X)})),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:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X),mediaKey:e.mediaKey})),u=null,d=-1;for(let t of e){let e=Z(t.bbox.w/r)*Z(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:Q(Z(u.bbox.x/r)*X),y:Q(Z(u.bbox.y/i)*X),w:Q(Z(u.bbox.w/r)*X),h:Q(Z(u.bbox.h/i)*X)}:null}}n();var fn=15e3,pn=window.location.origin,mn=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),hn=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]);function gn(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 _n({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 $({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 vn({row:t,cameraName:n,deleteAvailable:i,onClose:o,onDeleted:c,onFlagsChanged:l}){let m=p(),g=kt(),_=t!==null,v=t?.deviceId??0,y=t?.trackId??``,b=t?.bestEventId??``,x=t?.timestamp??0,C=t?.windowMs??0,{data:E}=L({deviceId:v,trackId:y},{enabled:_}),{data:D}=z({trackId:y,deviceId:v},{enabled:_}),{data:O}=R({eventId:b,deviceId:v},{enabled:_&&b!==``}),{data:k}=w({deviceId:v,since:x-fn,until:x+C+fn},{enabled:_}),[A,j]=u(null),[M,N]=u(!1),{publicOrigin:P,probes:F}=Zt(_);f(()=>{j(null)},[v,y]);let I=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]),ee=Fe(I?`${Le}/${encodeURIComponent(I.key)}`:void 0),B=a(()=>{let e=new Set,t=[];for(let n of[...O??[],...D??[]])!n.base64||e.has(n.key)||(e.add(n.key),t.push(n));return t},[O,D]),te=a(()=>B.find(e=>mn.has(e.kind))??null,[B]),V=gn(te?`data:image/jpeg;base64,${te.base64}`:null),ne=a(()=>dn(E?.positions??[],V,{snapshots:(E?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaKey:e.mediaKey}))}),[E?.positions,E?.snapshots,V]),H=e(e=>{let t=B.find(t=>t.key===e);t&&j(t)},[B]);if(t===null)return null;let U=A?`data:image/jpeg;base64,${A.base64}`:ee.src,W=A?.kind??I?.kind,re=W!==void 0&&hn.has(W)&&V!==null&&(E?.positions.length??0)>=2,G=k&&k.length>0?k[0]:null,ie=()=>{G&&(N(!0),(async()=>{try{let e=await m.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:G.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{window.alert(`Could not resolve clip playback. Check the server logs.`)}finally{N(!1)}})())},ae=()=>{!i||g.isPending||window.confirm(`Delete this track and all its media? This cannot be undone.`)&&(async()=>{try{await g.mutateAsync({deviceId:t.deviceId,trackIds:[t.trackId]}),c()}catch{window.alert(`Failed to delete this track. Check the server logs.`)}})()},oe=Math.round(t.importance*100),se=E?.importanceReason?`${String(oe)}% · ${E.importanceReason}`:`${String(oe)}%`,K=E?.zonesVisited&&E.zonesVisited.length>0?E.zonesVisited.join(`, `):`—`,le=E?.audioLabels&&E.audioLabels.length>0?E.audioLabels.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `):`—`,ue=E?E.totalDistance.toFixed(2):`—`,pe=me(E?E.firstSeen:x),he=E?me(E.lastSeen):`—`;return d(T,{open:!0,onOpenChange:e=>!e&&o(),children:r(h,{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,vt(t)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,vt(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(ke,{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(fe,{src:U,alt:`Key frame from ${n}`,fit:`natural`,className:`w-full`,overlay:re?d(_n,{overlay:ne,onPickSnapshot:H}):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:ee.failed?r(s,{children:[d(de,{className:`h-8 w-8 opacity-60`}),d(`span`,{className:`text-[11px]`,children:`Key-frame media unavailable`})]}):d(q,{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=`data:image/jpeg;base64,${e.base64}`,n=Jt(e.kind),i=Yt(pn,e.key),a=P?Yt(P,e.key):null;return r(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[d(`button`,{type:`button`,onClick:()=>j(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${n} · ${me(e.timestamp)}`,children:d(`img`,{src:t,alt:n,className:`h-full w-full object-cover`})}),r(`figcaption`,{className:`min-w-0 px-0.5`,children:[d(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:n,children:n}),d(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:me(e.timestamp),children:ce(e.timestamp)})]}),d(Gt,{localUrl:i,publicUrl:a})]},e.key)})}),F,G&&r(S,{variant:`secondary`,onClick:ie,disabled:M,children:[M?d(q,{className:`h-3.5 w-3.5 animate-spin`}):d(Ee,{className:`h-3.5 w-3.5`}),` `,`View clip`]}),d(sn,{deviceId:t.deviceId,trackId:t.trackId,...(E?.markForTrain??t.markForTrain)===void 0?{}:{markForTrain:E?.markForTrain??t.markForTrain},...(E?.debug??t.debug)===void 0?{}:{debug:E?.debug??t.debug},...(E?.favourited??t.favourited)===void 0?{}:{favourited:E?.favourited??t.favourited},onChange:l}),r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[d($,{label:`Camera`,value:n}),d($,{label:`Class`,value:t.className}),d($,{label:`Label`,value:t.label??`—`}),d($,{label:`Sub-label`,value:t.subLabel??`—`}),d($,{label:`Importance`,value:se}),d($,{label:`Zones visited`,value:K}),d($,{label:`Audio heard`,value:le}),d($,{label:`Total distance`,value:ue}),d($,{label:`First seen`,value:pe}),d($,{label:`Last seen`,value:he}),d($,{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:Dt,children:r(S,{variant:`secondary`,onClick:ae,disabled:!i||g.isPending,children:[g.isPending?d(q,{className:`h-3.5 w-3.5 animate-spin`}):d(je,{className:`h-3.5 w-3.5`}),` `,`Delete track`]})})})]})})}function yn(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 bn({row:e,cameraName:t,nowMs:n,onOpenDetail:i,selected:a=!1,onToggleSelect:o,score:s}){let c=Fe(e.bestEventId?`${Le}/${e.bestEventId}`:void 0),l=Math.round(e.importance*100),u=s===void 0?void 0:Math.round(s*100),f=yn(e.windowMs),p=()=>i(e);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:[c.src?d(`img`,{src:c.src,alt:`Event from ${t}`,onClick:p,className:`h-full w-full cursor-zoom-in object-cover`}):d(`button`,{type:`button`,onClick:p,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-surface-hover text-foreground-subtle`,title:c.failed?`Key-event media unavailable`:`No key-event media`,children:d(de,{className:`h-6 w-6 opacity-60`})}),o&&d(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(Ct(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`})}),u!==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(u),`%`]}),l>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(l)}),(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(We,{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(Be,{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:p,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,vt(e)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,vt(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:le(e.timestamp,n)}),f&&d(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:f})]})]})]})}n();function xn(){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 Sn=[`events-feed`],Cn=60,wn=[{value:`importance`,label:`Importance`,icon:ze},{value:`time`,label:`Recent`,icon:ie}];function Tn(){let e=l(),[t,n]=u(ge),[i,o]=u(new Set),[c,p]=u(new Set),[m,h]=u(0),[g,_]=u(`time`),[v,y]=u(new Set),[b,C]=u(null),[w,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},w),[t.fromMs,t.toMs,w]),O=xn(),{pending:k,refreshNow:j}=Ft({paused:b!==null||v.size>0||O.scrolledPast}),{data:M}=x({}),N=a(()=>(M??[]).filter(e=>e.type===G.Camera),[M]),P=a(()=>N.map(e=>e.id),[N]),{data:F,isLoading:I}=A({deviceIds:P},{enabled:P.length>0,staleTime:5*6e4}),L=a(()=>Vt(F??[],i),[F,i]),ee=kt(),R=ee.isPending,{rows:z,isLoading:B}=Mt({deviceIds:P,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 N??[])e.set(t.id,t.name);return e},[N]),V=e=>te.get(e)??`Camera #${String(e)}`,ne=a(()=>K(z).map(e=>({id:e,name:V(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[z,te]),H=a(()=>xt(St(z,{cameras:i,classes:c,minImportance:m}),g),[z,i,c,m,g]),U=pe(H,Cn,a(()=>JSON.stringify([[...i].sort((e,t)=>e-t),[...c].sort(),m,g,E,D]),[i,c,m,g,E,D])),W=()=>{e.invalidateQueries({queryKey:Sn})},re=()=>y(new Set);function ie(e){y(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function ae(){if(v.size===0||!Et)return;let e=wt(z,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=>{W();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(Ct(o,e));else t.push(o)}),y(e=>{let t=new Set(e);for(let e of r)t.delete(e);return t}),t.length>0){let e=t.map(e=>V(e)).join(`, `);window.alert(`Failed to delete tracks on: ${e}. They remain selected — retry, or check the server logs.`)}})}let oe=H.length!==z.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d(he,{onChange:n}),d(ue,{cameras:ne,selected:i,onChange:o}),d(It,{groups:L,selected:c,onChange:p,loading:I}),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:wn.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)})}),!B&&d(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:oe?`${String(H.length)} of ${String(z.length)} events`:`${String(H.length)} event${H.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:Et?void 0:`Track deletion arrives with the next server update`,children:r(S,{variant:`secondary`,onClick:ae,disabled:!Et||R,children:[R?d(q,{className:`h-3.5 w-3.5 animate-spin`}):d(je,{className:`h-3.5 w-3.5`}),` `,`Delete`]})}),d(S,{variant:`ghost`,onClick:re,disabled:R,children:d(ke,{className:`h-3.5 w-3.5`})})]})]}),B&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[d(q,{className:`h-4 w-4 animate-spin`}),` Loading events…`]}),!B&&H.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:j,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`})}),!B&&H.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:U.pageItems.map(e=>d(bn,{row:e,cameraName:V(e.deviceId),nowMs:w,selected:v.has(Ct(e.deviceId,e.trackId)),onToggleSelect:ie,onOpenDetail:C},Ct(e.deviceId,e.trackId)))}),d(se,{currentPage:U.page,totalItems:U.totalItems,pageSize:U.pageSize,onPageChange:U.setPage,itemNoun:`events`})]}),b&&d(vn,{row:b,cameraName:V(b.deviceId),deleteAvailable:Et,onClose:()=>C(null),onDeleted:()=>{W(),C(null)},onFlagsChanged:e=>{C(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug,favourited:e.favourited}:t)}})]})}n();var En=50,Dn=350,On=[{value:.2,label:`Loose`},{value:.25,label:`Balanced`},{value:.3,label:`Strict`}];function kn(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 An({onActiveChange:e}){let[t,n]=u(``),[i,o]=u(.2),[s,c]=u(null),[l,p]=u(null),[m,h]=u(null),g=y(t,Dn).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:S}=x({}),C=a(()=>(S??[]).filter(e=>e.type===G.Camera),[S]),w=a(()=>{let e=new Map;for(let t of S??[])e.set(t.id,t.name);return e},[S]),T=e=>w.get(e)??`Camera #${String(e)}`,E=a(()=>C.map(e=>e.id),[C]),{data:k}=A({deviceIds:E},{enabled:E.length>0,staleTime:5*6e4}),j=a(()=>Bt(k??[],new Set(l===null?[]:[l])),[k,l]);f(()=>{s!==null&&(j.some(e=>e.kind===s)||c(null))},[j,s]);let{data:M,isFetching:N,isError:P,error:F}=O({text:g,minScore:i,limit:En,classFilter:s??void 0,deviceId:l??void 0},{enabled:_}),I=a(()=>[...M??[]].sort((e,t)=>t.score-e.score).map(e=>({...kn(e),score:e.score})),[M]);function L(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(ye,{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(ke,{className:`h-3.5 w-3.5`})})]}),N&&_&&d(q,{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:j.map(e=>d(`button`,{type:`button`,onClick:()=>L(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:D(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`}),C.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:On.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))})]}),_&&!N&&!P&&r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[I.length,` match`,I.length===1?``:`es`]})]})]}),_&&r(`div`,{className:`space-y-3`,children:[P&&r(`p`,{className:`py-4 text-xs text-danger`,children:[`Search failed: `,F instanceof Error?F.message:`unknown error`,`. Check that the CLIP embedding step is enabled.`]}),!P&&N&&I.length===0&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[d(q,{className:`h-4 w-4 animate-spin`}),` Searching…`]}),!P&&!N&&I.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.`]}),!P&&I.length>0&&d(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:I.map(e=>d(bn,{row:e,cameraName:T(e.deviceId),nowMs:v,score:e.score,onOpenDetail:h},e.id))})]}),m&&d(vn,{row:m,cameraName:T(m.deviceId),deleteAvailable:Et,onClose:()=>h(null),onDeleted:()=>h(null)})]})}var jn=15e3;function Mn(e){let t=p(),n=c({queries:e.map(e=>({queryKey:[`stationary-objects`,e],staleTime:jn,refetchInterval:jn,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 Nn(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 Pn({row:e,cameraName:t,nowMs:n}){let i=e.keyFrameMediaKey?.startsWith(`track:`)?e.keyFrameMediaKey.split(`:`)[1]:e.keyFrameMediaKey,a=Fe(i?`${Le}/${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(Ge,{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 `,Nn(n,e.becameStationaryAt)]})]})]})}function Fn(){let[e,t]=u(!1),n=Date.now(),{data:i}=x({}),o=a(()=>(i??[]).filter(e=>e.type===G.Camera),[i]),s=a(()=>o.map(e=>e.id),[o]),c=a(()=>{let e=new Map;for(let t of o)e.set(t.id,t.name);return e},[o]),{rows:l}=Mn(s);return l.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(Ge,{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:l.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:l.map(e=>d(Pn,{row:e,cameraName:c.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:n},e.id))})]})}n();function In(){let[e,t]=u(!1);return d(Pe,{children:r(`section`,{className:`space-y-3`,children:[d(An,{onActiveChange:t}),!e&&d(Fn,{}),!e&&d(Tn,{})]})})}var Ln=[`person`,`vehicle`,`animal`,`package`,`face`,`plate`],Rn=new Set(Ln);function zn(e){let t=e?.trim().toLowerCase();return t===void 0||t===``?null:Rn.has(t)?`"${t}" is a macro class, not a label — person / postman / Marco are three different tiers`:null}function Bn({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=zn(e.label),l=zn(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(b,{className:`w-28`,value:e.macroClass,options:Ln.map(e=>({value:e,label:e})),onChange:e=>{let t=Ln.find(t=>t===e.target.value);t!==void 0&&i(o,{macroClass:t})}}),d(b,{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(v,{variant:`info`,children:[e.assistModelId??`assist`,e.assistScore===void 0?``:` ${e.assistScore.toFixed(2)}`]}),d(S,{variant:`ghost`,size:`sm`,"aria-label":`Delete this subject`,onClick:()=>{a(o)},children:d(je,{className:`h-3 w-3`})})]}),r(`div`,{className:`flex items-center gap-2`,children:[d(g,{className:`flex-1`,placeholder:`label (postman, van, cat…)`,value:e.label??``,onChange:e=>{i(o,{label:e.target.value})}}),d(g,{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 Vn(e){return e.every(e=>zn(e.label)===null&&zn(e.subLabel)===null&&Rn.has(e.macroClass))}function Hn(e){return e<0?0:e>1?1:e}function Un(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 Wn(e,t,n){return{x:Hn((e-n.left)/n.width),y:Hn((t-n.top)/n.height)}}function Gn(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 Kn(e){return e.w>=.01&&e.h>=.01}function qn(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 Jn(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 Yn({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=Un(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 Wn(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:Gn(t,t)}))},onPointerMove:e=>{if(g===null)return;let t=y(e);t!==null&&_({start:g.start,current:Gn(g.start,t)})},onPointerUp:()=>{if(g===null)return;let e=g.current;_(null),Kn(e)?f(e):l(Jn(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=qn(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:qn(g.current,v)})]})}function Xn(e){return e>=1e6?`${(e/1e6).toFixed(1)} MB`:`${Math.round(e/1e3)} KB`}function Zn({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(Ne,{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,` · `,Xn(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(je,{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(S,{variant:`secondary`,size:`sm`,disabled:a||t!==void 0,onClick:()=>{o(e.mediaKey)},children:[a?d(q,{className:`h-3 w-3 animate-spin`}):d(t===void 0?Ue:de,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:e.kind}),d(`span`,{className:`ml-1 text-foreground-subtle`,children:Xn(e.sizeBytes)})]}),t!==void 0&&d(v,{variant:`danger`,className:`ml-1`,children:t})]},e.mediaKey)})})]})]})}function Qn(e){return e.frameCount===0?`untouched`:e.annotationCount===0?`started`:`ready`}var $n={untouched:{icon:He,label:`to do`,variant:`default`},started:{icon:Ve,label:`frames only`,variant:`info`},ready:{icon:De,label:`annotated`,variant:`success`}};function er(e){return new Date(e).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function tr({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(q,{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=$n[Qn(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(v,{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)}`,` ·`,` `,er(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 nr=`person`;function rr(){let[t,n]=u(null),[i,o]=u(null),[c,l]=u([]),[p,h]=u(-1),[g,_]=u(new Map),[y,b]=u(null),C=x({projection:`slim`,isCamera:!0}),w=a(()=>{let e=new Map;for(let t of C.data??[])e.set(t.id,t.name);return e},[C.data]),T=M({}),E=j({trackId:t?.trackId??``},{enabled:t!==null}),D=te({trackId:t?.trackId??``},{enabled:t!==null}),O=k({frameId:i??``},{enabled:i!==null}),A=ne(),F=I(),L=ee(),R=N(),z=m(),B=P();f(()=>{if(i===null){l([]);return}l((D.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,D.data]),f(()=>{let e=E.data?.copies??[];i===null&&e.length>0&&o(e[0].frameId)},[E.data,i]);let V=e(e=>{n(e),o(null),l([]),_(new Map),b(null)},[]),H=e(async e=>{if(t===null)return;let n=await A.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);_(e)}n.copied.length>0&&o(n.copied[0].frameId),await E.refetch(),await T.refetch()},[t,A,g,E,T]),U=e(async e=>{t!==null&&(await F.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:e}),i===e&&o(null),await E.refetch(),await D.refetch(),await T.refetch())},[t,F,i,E,D,T]),W=e(async e=>{if(t===null||i===null)return;b(null);let n=await L.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:i,subject:e===`package`?{kind:`package`}:{kind:`objects`,modelId:`yolo26n`,minScore:.3}});if(n.kind===`refused`){b(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}}))]),b(`${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,L]),re=e(e=>{l(t=>[...t,{bbox:e,macroClass:nr,kind:`subject`,source:`operator`}]),h(c.length)},[c.length]),G=e((e,t)=>{l(n=>n.map((n,r)=>r===e?{...n,...t}:n))},[]),ie=e(e=>{l(t=>t.filter((t,n)=>n!==e)),h(-1)},[]),ae=e(async()=>{t===null||i===null||(await R.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 D.refetch(),await T.refetch(),b(`Annotations saved.`))},[t,i,c,R,D,T]),oe=e(async()=>{if(t===null)return;let e=await z.mutateAsync({deviceId:t.deviceId,trackId:t.trackId});b(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 T.refetch(),e.changed&&n(null)},[t,z,T]),se=e(async()=>{if(t===null)return;let e=await B.mutateAsync({deviceId:t.deviceId,trackId:t.trackId});b(e.changed?`Track returned to staging. Its copies and annotations were left alone.`:`Refused: ${e.reason??`unknown`}`),await T.refetch()},[t,B,T]),K=O.data,ce=Vn(c)&&i!==null;return r(Pe,{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(S,{variant:`secondary`,size:`sm`,onClick:()=>void se(),children:[d(Ce,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:`Back to staging`})]}),r(S,{size:`sm`,onClick:()=>void oe(),children:[d(We,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:`Complete track`})]})]}),children:[y!==null&&d(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-xs text-foreground`,children:y}),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(v,{children:T.data?.length??0})]}),d(tr,{tracks:T.data??[],isLoading:T.isLoading,selectedTrackId:t?.trackId??null,deviceNames:w,onSelect:V})]}),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(Zn,{candidates:E.data?.candidates??[],copies:E.data?.copies??[],activeFrameId:i,refusals:g,isSelecting:A.isPending,onSelectCandidate:e=>void H(e),onOpenCopy:o,onRemoveCopy:e=>void U(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:K===void 0?r(`div`,{className:`flex items-center gap-2 p-6 text-xs text-foreground-subtle`,children:[d(q,{className:`h-3.5 w-3.5 animate-spin`}),`Loading the frame…`]}):d(Yn,{imageSrc:`data:image/jpeg;base64,${K.base64}`,imageWidth:K.width,imageHeight:K.height,boxes:c,selectedIndex:p,onSelect:h,onDraw:re})}),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(S,{variant:`secondary`,size:`sm`,disabled:L.isPending,onClick:()=>void W(`objects`),children:[d(Ae,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:`Propose`})]}),r(S,{variant:`secondary`,size:`sm`,disabled:L.isPending,onClick:()=>void W(`package`),children:[d(Ae,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:`Packages`})]})]}),d(`div`,{className:`flex-1 overflow-y-auto`,children:d(Bn,{annotations:c,selectedIndex:p,onSelect:h,onChange:G,onDelete:ie})}),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(S,{size:`sm`,disabled:!ce||R.isPending,onClick:()=>void ae(),children:`Save frame`})]})]})]})]})})]})]})}function ir(){return d(`div`,{className:`flex flex-col p-4`,children:d(Re,{tabs:[{id:`feed`,label:`Feed`,icon:we,content:d(In,{})},{id:`retrain`,label:`Retrain`,icon:We,content:d(rr,{})},{id:`debug`,label:`Debug`,icon:Be,content:d(_t,{})}]})})}export{ir as EventsPage};
@@ -1 +0,0 @@
1
- import{Q as e,S as t,W as n,a as r,b as i,o as a,q as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as c}from"./player-overlays-DXNKqmwI.js";import{C as l,Cs as u,Rr as d,Rt as f,S as p,Ss as m,Tn as h,_s as g,bs as _,d as v,ds as y,f as b,fs as x,gs as S,hs as C,ms as w,ps as T,tt as ee,un as E,us as D,vs as te,wn as O,ws as ne,xs as k,ys as re}from"./src-C0QlPpXb.js";import{c as A,d as j,l as M,u as N}from"./src-DAigq6PX.js";import{t as P}from"./circle-check-big-BZnwR-f7.js";import{t as F}from"./copy-EKhXmX92.js";import{t as ie}from"./key-round-DpXzoCIV.js";import{t as ae}from"./pencil-dvZNet31.js";import{t as oe}from"./plus-CDo9Tbkz.js";import{C as I,E as L,I as se,K as R,R as ce,f as z,i as B,k as le,r as V,s as H,u as U,w as ue,z as de}from"./index-DhYfPTfU.js";import{t as W}from"./AdminPage-CCD07UMs.js";import{t as fe}from"./AdminTabs-D6yDsobg.js";import{t as pe}from"./AddonCollectionPage-D86qUT-8.js";import{t as me}from"./addon-display-names-DvSEQty-.js";var he=R(`book-open`,[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z`,key:`ruj8y`}]]),ge=R(`key-square`,[[`path`,{d:`M12.4 2.7a2.5 2.5 0 0 1 3.4 0l5.5 5.5a2.5 2.5 0 0 1 0 3.4l-3.7 3.7a2.5 2.5 0 0 1-3.4 0L8.7 9.8a2.5 2.5 0 0 1 0-3.4z`,key:`165ttr`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`m9.4 10.6-6.814 6.814A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814`,key:`1ubxi2`}]]),_e=R(`key`,[[`path`,{d:`m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4`,key:`g0fldk`}],[`path`,{d:`m21 2-9.6 9.6`,key:`1j0ho8`}],[`circle`,{cx:`7.5`,cy:`15.5`,r:`5.5`,key:`yqb3hr`}]]),ve=R(`link`,[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]),ye=R(`shield-alert`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M12 16h.01`,key:`1drbdi`}]]),be=R(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]);e();function xe({userId:e,username:n,onClose:r}){let o=a(),c=E(),l=w({userId:e}),u=l.data,d=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),p=T({onSuccess:()=>{d(),r()}}),m=l.isLoading?`loading`:u?.enabled?`enrolled`:`not_enrolled`;return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4`,children:t(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden`,children:[t(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-border`,children:[t(`div`,{className:`flex items-center gap-2`,children:[s(U,{className:`h-4 w-4 text-primary`}),t(`div`,{children:[s(`div`,{className:`text-sm font-medium text-foreground`,children:`Two-factor authentication`}),t(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,s(`span`,{className:`font-mono`,children:n})]})]})]}),s(`button`,{onClick:r,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:s(B,{className:`h-4 w-4`})})]}),t(`div`,{className:`p-4 space-y-4`,children:[m===`loading`&&t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(I,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),m===`not_enrolled`&&t(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[s(ue,{className:`h-4 w-4 mt-0.5 shrink-0`}),t(`div`,{children:[s(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),s(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),m===`enrolled`&&u&&t(i,{children:[t(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[s(P,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),t(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[s(`div`,{className:`font-medium`,children:`2FA is active`}),t(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,u.confirmedAt?new Date(u.confirmedAt).toLocaleString():`—`]})]})]}),s(`div`,{className:`text-[11px] text-foreground-subtle`,children:`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`}),t(`div`,{className:`flex justify-end gap-2`,children:[s(f,{onClick:r,variant:`secondary`,children:`Close`}),t(`button`,{onClick:async()=>{await c({title:`Remove 2FA`,message:`Remove two-factor authentication for "${n}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,confirmLabel:`Remove`,variant:`danger`})&&p.mutate({userId:e})},disabled:p.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[p.isPending?s(I,{className:`h-3 w-3 animate-spin`}):s(B,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function G({icon:e,label:n,count:r,all:i,total:a}){return t(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[s(e,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(`span`,{className:`min-w-0 flex-1 text-foreground-subtle`,children:n}),s(`span`,{className:r===0?`text-foreground-subtle`:`font-medium text-foreground`,children:r===0?`none`:i?`all ${a}`:`${r} of ${a}`})]})}function Se({scopes:e,isAdmin:n,invalidReason:a}){let o=c(),l=r({queryKey:[`auth`,`previewScope`,e,n],enabled:a===null,queryFn:()=>o.trpcClient.auth.previewScope.query({scopes:[...e],isAdmin:n})}),{data:u}=d({}),f=u?.length??0;if(a!==null)return s(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:t(`p`,{className:`flex items-center gap-1.5 text-[11px] text-warning`,children:[s(ye,{className:`h-3 w-3 shrink-0`}),a]})});if(l.isLoading)return t(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface p-3 text-[11px] text-foreground-subtle`,children:[s(I,{className:`h-3 w-3 animate-spin`}),`Resolving…`]});if(l.isError||!l.data)return s(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:s(`p`,{className:`text-[11px] text-danger`,children:`Could not resolve this grant set. Saving is still allowed — the server enforces the same rules either way.`})});let p=l.data;return s(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-3`,children:p.isAdmin?t(`p`,{className:`text-[11px] text-foreground`,children:[s(`span`,{className:`font-medium`,children:`Administrator`}),` — unrestricted. Grants are ignored for an admin.`]}):t(i,{children:[s(G,{icon:le,label:`Devices they can see`,count:p.device.view.deviceCount,all:p.device.view.all,total:f}),s(G,{icon:ae,label:`Devices they can operate`,count:p.device.create.deviceCount,all:p.device.create.all,total:f}),s(G,{icon:H,label:`Devices they can delete`,count:p.device.delete.deviceCount,all:p.device.delete.all,total:f}),t(`div`,{className:`border-t border-border pt-2 text-[10px] text-foreground-subtle`,children:[`System access: `,p.system.length===0?`none`:p.system.join(`, `),p.capabilities.length>0&&t(i,{children:[` · Extra capabilities: `,p.capabilities.map(e=>e.name).join(`, `)]}),p.addons.length>0&&t(i,{children:[` · Addons: `,p.addons.map(e=>e.name).join(`, `)]})]}),p.device.view.deviceCount===0&&s(`p`,{className:`text-[10px] text-warning`,children:`This user will not be able to see any device.`})]})})}function Ce(e){let t=N(e);return t===null?{mode:e.length===0?`role`:`advanced`,roleId:null,selector:{kind:`all`},includeLinked:!0,advancedScopes:e}:{mode:`role`,roleId:t.roleId,selector:t.selector,includeLinked:t.includeLinked,advancedScopes:e}}function we(e){return e.mode===`advanced`?e.advancedScopes:e.roleId===null?[]:M({roleId:e.roleId,selector:e.selector,includeLinked:e.includeLinked})}function Te({user:e,onClose:r,onSubmit:a,submitting:c,callerScopes:l}){let u=n(()=>Ce(e.scopes??[]),[e.scopes]),[d,f]=o(u),[m,h]=o(u.mode===`advanced`),g=n(()=>we(d),[d]),_=!e.isAdmin&&d.mode===`role`&&d.roleId===null,y=n(()=>e.isAdmin?null:d.mode===`role`&&d.roleId===null?`Pick what this user can do to see the result.`:b(g),[e.isAdmin,d.mode,d.roleId,g]),x=e=>f({...d,...e});return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4 pt-[calc(1rem+env(safe-area-inset-top))] pb-[calc(1rem+env(safe-area-inset-bottom))]`,children:t(`div`,{className:`flex max-h-full w-full max-w-2xl flex-col rounded-lg border border-border bg-surface shadow-xl`,children:[t(`div`,{className:`flex shrink-0 items-start justify-between border-b border-border px-4 py-3`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`text-sm font-semibold text-foreground`,children:[`Access — `,e.username]}),s(`div`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?`This user is an administrator — they can do everything, and the settings below are ignored.`:`Choose what they can do, then which devices it applies to.`})]}),s(`button`,{onClick:r,className:`shrink-0 text-foreground-subtle hover:text-foreground`,title:`Close`,children:s(B,{className:`h-4 w-4`})})]}),t(`div`,{className:`min-h-0 flex-1 space-y-4 overflow-y-auto px-4 py-4`,children:[_&&t(`div`,{className:`flex items-start gap-2 rounded-lg border border-warning/40 bg-warning/10 p-3`,children:[s(ye,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`}),t(`p`,{className:`text-[11px] text-foreground`,children:[s(`span`,{className:`font-medium`,children:`No access.`}),` `,t(`span`,{className:`text-foreground-subtle`,children:[e.username,` cannot see or do anything yet. Configure it below.`]})]})]}),t(`section`,{className:`space-y-2`,children:[s(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`1 · What can they do`}),s(`div`,{className:`space-y-1.5`,children:A.map(e=>{let n=d.mode===`role`&&d.roleId===e.id;return t(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-lg border p-2.5 transition-colors ${n?`border-primary bg-primary/5`:`border-border hover:bg-foreground-subtle/5`}`,children:[s(`input`,{type:`radio`,name:`access-role`,checked:n,onChange:()=>x({mode:`role`,roleId:e.id}),className:`mt-0.5 border-border focus:ring-primary`}),t(`span`,{className:`min-w-0`,children:[s(`span`,{className:`block text-[12px] font-medium text-foreground`,children:e.label}),s(`span`,{className:`mt-0.5 block text-[10px] text-foreground-subtle`,children:e.description})]})]},e.id)})}),t(`button`,{type:`button`,onClick:()=>{if(!m){f({...d,mode:`advanced`,advancedScopes:g}),h(!0);return}h(!1),f(Ce(d.advancedScopes))},className:`inline-flex items-center gap-1 rounded px-1.5 py-1 text-[10px] text-foreground-subtle transition-colors hover:bg-foreground-subtle/10 hover:text-foreground`,children:[s(m?ce:se,{className:`h-3 w-3`}),`Advanced — edit raw grants`]}),m&&t(`div`,{className:`rounded-lg border border-border p-2`,children:[s(`p`,{className:`mb-2 text-[10px] text-foreground-subtle`,children:`One row per grant. Anything expressible here overrides the three roles above; close this section to go back to them.`}),s(v,{value:d.advancedScopes,onChange:e=>x({mode:`advanced`,advancedScopes:e}),clampToParent:l,emptyHint:t(i,{children:[`No grants.`,` `,s(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until one is added.`]})})]})]}),d.mode===`role`&&t(`section`,{className:`space-y-2`,children:[s(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`2 · On which devices`}),s(p,{value:d.selector,onChange:e=>x({selector:e}),includeLinked:d.includeLinked,onIncludeLinkedChange:e=>x({includeLinked:e}),clampToDeviceIds:null})]}),t(`section`,{className:`space-y-2`,children:[s(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:d.mode===`role`?`3 · Result`:`2 · Result`}),s(Se,{scopes:g,isAdmin:e.isAdmin,invalidReason:y})]})]}),t(`div`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3`,children:[s(`button`,{onClick:r,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground`,children:`Cancel`}),s(`button`,{onClick:()=>a([...g]),disabled:c||y!==null,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:c?s(I,{className:`h-3 w-3 animate-spin`}):`Save access`})]})]})})}e();function Ee(){let e=a(),{user:n}=V(),[r,i]=o(!1),[c,l]=o(``),[d,f]=o(``),[p,m]=o(!1),[h,g]=o(null),{data:_,isLoading:v,isError:b}=te(),S=E(),C=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),w=y({onSuccess:()=>{C(),i(!1),l(``),f(``),m(!1),g(null)},onError:e=>{g(e instanceof Error?e.message:`Failed to create user`)}}),T=x({onSuccess:C}),D=ne({onSuccess:C}),O=re({onSuccess:C}),k=u({onSuccess:()=>{C(),j(null)}}),[A,j]=o(null),[M,N]=o(null),P=_??[];async function F(e){await S({title:`Delete user`,message:`Permanently delete user "${e.username}"? This cannot be undone — any active sessions will be revoked on next request.`,confirmLabel:`Delete`,variant:`danger`})&&T.mutate({id:e.id})}async function ie(e){let t=window.prompt(`New password for "${e.username}":`);if(t){if(t.length<8){window.alert(`Password must be at least 8 characters.`);return}await S({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&O.mutate({id:e.id,newPassword:t})}}function ae(e,t){t!==e.isAdmin&&D.mutate({id:e.id,isAdmin:t})}function L(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}return t(W,{children:[s(`div`,{className:`flex items-center justify-end`,children:t(`button`,{onClick:()=>i(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm hover:bg-primary/90`,children:[s(oe,{className:`h-3.5 w-3.5`}),`Create User`]})}),r&&t(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[t(`div`,{className:`flex items-center justify-between`,children:[s(`span`,{className:`text-xs font-medium text-foreground`,children:`New User`}),s(`button`,{onClick:()=>i(!1),className:`text-foreground-subtle hover:text-foreground`,children:s(B,{className:`h-4 w-4`})})]}),t(`div`,{className:`grid grid-cols-3 gap-3`,children:[t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),s(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`john`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Password`}),s(`input`,{type:`password`,value:d,onChange:e=>f(e.target.value),placeholder:`••••••••`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),t(`label`,{className:`flex items-center gap-2 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:p,onChange:e=>m(e.target.checked),className:`rounded border-border focus:ring-primary`}),s(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),h&&s(`p`,{className:`text-[10px] text-danger`,children:h}),t(`div`,{className:`flex justify-end gap-2`,children:[s(`button`,{onClick:()=>i(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),s(`button`,{onClick:()=>w.mutate({username:c,password:d,isAdmin:p}),disabled:w.isPending||!c||!d,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:w.isPending?`Creating...`:`Create`})]})]}),v&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),b&&s(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!v&&!b&&P.length===0&&s(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>T.isPending&&T.variables?.id===e.id||D.isPending&&D.variables?.id===e.id||O.isPending&&O.variables?.id===e.id;return s(ee,{columns:[{key:`username`,header:`Username`,render:e=>e.username},{key:`isAdmin`,header:`Admin`,render:n=>t(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:n.isAdmin,onChange:e=>ae(n,e.target.checked),disabled:e(n),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),s(`span`,{className:n.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:n.isAdmin?`Admin`:`Regular`})]})},{key:`scopes`,header:`Access`,render:e=>e.isAdmin?s(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:`everything (admin)`}):t(`button`,{onClick:()=>j(e),className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] hover:bg-foreground-subtle/10`,title:`Configure access`,children:[s(z,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(De,{scopes:e.scopes??[]})]})},{key:`createdAt`,header:`Created`,render:e=>s(`span`,{className:`text-foreground-subtle`,children:L(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:r=>{let i=e(r);return t(`div`,{className:`flex items-center justify-end gap-1`,children:[r.id!==n?.id&&r.totpEnabled&&t(`button`,{onClick:()=>N(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Remove two-factor authentication`,children:[s(U,{className:`h-3 w-3`}),`Remove 2FA`]}),t(`button`,{onClick:()=>ie(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Reset password`,children:[s(_e,{className:`h-3 w-3`}),`Reset password`]}),t(`button`,{onClick:()=>F(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete user`,children:[i?s(I,{className:`h-3 w-3 animate-spin`}):s(H,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:P,rowKey:e=>e.id,minWidthPx:560})})(),M&&s(xe,{userId:M.id,username:M.username,onClose:()=>N(null)}),A&&s(Oe,{user:A,onClose:()=>j(null),onSubmit:e=>k.mutate({userId:A.id,scopes:e}),submitting:k.isPending})]})}function De({scopes:e}){if(e.length===0)return s(`span`,{className:`font-medium text-warning`,children:`No access`});let n=N(e);return n===null?t(`span`,{className:`text-foreground-subtle`,children:[`Custom · `,e.length,` grant`,e.length===1?``:`s`]}):t(`span`,{className:`text-foreground-subtle`,children:[s(`span`,{className:`font-medium text-foreground`,children:j(n.roleId).label}),` ·`,` `,l(n.selector)]})}function Oe(e){let{user:t}=V(),n=t?.isAdmin===!0;return s(Te,{...e,callerScopes:n?null:t?.scopes??[]})}e();var ke=`bg-primary/10 text-primary`,Ae=`bg-foreground-subtle/10 text-foreground-subtle`;function K(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function je(e){return e?e===`*`?`*`:e.join(`, `):``}function Me(){let e=a(),r=E(),{data:i,isLoading:c}=C(),{data:l}=te(),u=n(()=>i??[],[i]),d=n(()=>l??[],[l]),f=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),p=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[h,g]=o(!1),[v,y]=o(null),b=_({onSuccess:f}),x=D({onSuccess:({token:e,record:t})=>{p(),g(!1),y({token:e,label:t.name})}}),S=m({onSuccess:p}),w=async(e,t)=>{await r({title:`Revoke "${t}"?`,message:`Any client using this token will lose access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&b.mutate({id:e})},T=async(e,t)=>{await r({title:`Revoke "${t}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&S.mutate({id:e})};return t(W,{children:[t(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[s(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Issue scoped tokens to grant a user a narrow surface — a specific addon, integration, or capability. Every token MUST be scoped: revoking it has predictable blast radius.`}),t(`button`,{onClick:()=>g(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,disabled:d.length===0,title:d.length===0?`Create a user first`:`Issue a scoped token`,children:[s(z,{className:`h-3.5 w-3.5`}),`New token`]})]}),t(q,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[d.length===0&&s(Pe,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),d.map(e=>s(Ie,{userId:e.id,username:e.username,onRevoke:(e,t)=>{T(e,t)},revokePending:S.isPending,revokeId:S.variables?.id},e.id))]}),u.length>0&&s(q,{title:`Legacy API keys`,subtitle:`${u.length} pre-existing — revoke only`,children:s(Fe,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:u.map(e=>{let n=!!e.isAdmin,r=b.isPending&&b.variables?.id===e.id;return t(`tr`,{className:`hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.label}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:s(`span`,{className:`inline-block rounded px-2 py-0.5 text-[10px] uppercase tracking-wide ${n?ke:Ae}`,children:n?`admin`:`regular`})}),t(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border text-foreground-subtle`,children:je(e.allowedProviders)||`all`}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:K(e.createdAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:K(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:t(`button`,{onClick:()=>{w(e.id,e.label)},disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[r?s(I,{className:`h-3 w-3 animate-spin`}):s(H,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),c&&s(Ne,{}),h&&s(Le,{users:d.map(e=>({id:e.id,username:e.username})),onClose:()=>g(!1),onSubmit:e=>x.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:x.isPending}),v&&s(Re,{token:v.token,label:v.label,onClose:()=>y(null)})]})}function q({title:e,subtitle:n,children:r}){return t(`div`,{className:`space-y-2`,children:[t(`div`,{className:`flex items-baseline justify-between`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),n&&s(`span`,{className:`text-[10px] text-foreground-subtle`,children:n})]}),r]})}function Ne(){return s(`div`,{className:`space-y-2`,children:[1,2].map(e=>s(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function Pe({text:e}){return s(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function Fe({headers:e,rows:n}){return s(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full text-xs min-w-[640px]`,children:[s(`thead`,{children:s(`tr`,{children:e.map((t,n)=>s(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),s(`tbody`,{children:n})]})})}function Ie({userId:e,username:n,onRevoke:r,revokePending:i,revokeId:a}){let{data:o,isLoading:c}=g({userId:e}),u=o??[];return c||u.length===0?null:t(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[11px] font-medium text-foreground`,children:n}),s(Fe,{headers:[`Name`,`Prefix`,`Scopes`,`Expires`,`Last used`,`Created`,``],rows:u.map(e=>{let n=i&&a===e.id;return t(`tr`,{className:`hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.name}),t(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:s(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,n)=>t(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:[e.type,`:`,e.type===`device`?`[${l(e.selector)}]`:e.target]},n))})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:K(e.expiresAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:K(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:K(e.createdAt)}),s(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:t(`button`,{onClick:()=>r(e.id,e.name),disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[n?s(I,{className:`h-3 w-3 animate-spin`}):s(H,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function Le({users:e,onClose:n,onSubmit:r,submitting:i}){let{user:a}=V(),c=a?.isAdmin===!0?null:a?.scopes??[],[l,u]=o(e[0]?.id??``),[d,f]=o(``),[p,m]=o([{type:`capability`,target:``,access:[`view`,`create`]}]),[h,g]=o(``),_=b(p),y=l!==``&&d.trim().length>0&&p.length>0&&_===null&&!i;return t(ze,{title:`Create scoped token`,onClose:n,children:[t(`div`,{className:`space-y-3`,children:[s(Y,{label:`On behalf of user`,children:s(`select`,{value:l,onChange:e=>u(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>s(`option`,{value:e.id,children:e.username},e.id))})}),s(Y,{label:`Name`,children:s(`input`,{value:d,onChange:e=>f(e.target.value),placeholder:`cloudflare-tunnel-route`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})}),t(Y,{label:`Scopes`,hint:`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`,children:[s(v,{value:p,onChange:m,clampToParent:c}),_&&s(`p`,{className:`mt-1 text-[10px] text-danger`,children:_})]}),s(Y,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:s(`input`,{type:`number`,min:1,value:h,onChange:e=>g(e.target.value),placeholder:`30`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})})]}),t(J,{children:[s(`button`,{onClick:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),t(`button`,{onClick:()=>{let e=parseInt(h,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;r({userId:l,name:d.trim(),scopes:p,expiresAt:t})},disabled:!y,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[i?s(I,{className:`h-3.5 w-3.5 animate-spin`}):s(z,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function Re({token:e,label:n,onClose:r}){let[i,a]=o(!1),c=async()=>{try{await navigator.clipboard.writeText(e),a(!0)}catch{}};return t(ze,{title:`Token: ${n}`,onClose:r,children:[t(`div`,{className:`space-y-3`,children:[s(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:`Copy this token now. Once you close this dialog the secret cannot be displayed again.`}),s(`div`,{className:`rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all`,children:e})]}),t(J,{children:[t(`button`,{onClick:()=>{c()},className:`inline-flex items-center gap-1.5 rounded bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[i?s(de,{className:`h-3.5 w-3.5 text-primary`}):s(F,{className:`h-3.5 w-3.5`}),i?`Copied`:`Copy`]}),s(`button`,{onClick:r,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Done`})]})]})}function ze({title:e,onClose:n,children:r}){return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:t(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[t(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),s(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:s(B,{className:`h-4 w-4`})})]}),s(`div`,{className:`p-4`,children:r})]})})}function J({children:e}){return s(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:e})}function Y({label:e,hint:n,children:r}){return t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:e}),r,n&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:n})]})}e();function X(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function Be(e){if(e.type===`category`){let t=e.target??``;return t===`device`?`all devices`:`all ${t}`}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function Ve(){return s(`div`,{className:`space-y-2`,children:[1,2].map(e=>s(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function He({text:e}){return s(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function Ue({headers:e,rows:n}){return s(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full text-xs min-w-[640px]`,children:[s(`thead`,{children:s(`tr`,{children:e.map((t,n)=>s(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),s(`tbody`,{children:n})]})})}function We(){let e=a(),r=E(),{data:i,isLoading:o}=S(),c=n(()=>i??[],[i]),l=k({onSuccess:()=>e.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),u=async(e,t)=>{await r({title:`Revoke "${t}" session?`,message:`This integration will lose access immediately on its next API call. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&l.mutate({id:e})};return t(W,{icon:ve,title:`Linked Sessions`,subtitle:`External integrations (Alexa, …) linked to this hub via OAuth. Revoke a session to immediately invalidate that integration's access.`,children:[o&&s(Ve,{}),!o&&c.length===0&&s(He,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!o&&c.length>0&&s(Ue,{headers:[`Integration`,`User`,`Scopes`,`Created`,`Last used`,`Status`,``],rows:c.map(e=>{let n=e.revokedAt!==null,r=(l.isPending?l.variables?.id:void 0)===e.id;return t(`tr`,{className:`hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.integrationId}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:e.username}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:s(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>s(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:Be(e)},t))})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 border-b border-border`,children:n?t(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-2 py-0.5 text-[10px] text-foreground-subtle`,children:[`Revoked `,X(e.revokedAt)]}):s(`span`,{className:`inline-block rounded bg-emerald-500/15 px-2 py-0.5 text-[10px] text-emerald-700 dark:text-emerald-300`,children:`Active`})}),s(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:!n&&t(`button`,{onClick:()=>{u(e.id,e.integrationId)},disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[r?s(I,{className:`h-3 w-3 animate-spin`}):s(H,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}e();var Z=3e4,Q=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],$={title:`Authentication providers`,subtitle:`Every registered authentication surface in one list: login providers (local password, OIDC, SAML, magic-link) and second-factor providers (passkeys / WebAuthn — configure the relying-party RP ID + origin inline; users enroll from My access → Passkeys). Multiple providers run in parallel — enable/disable each independently. Disabling one only removes that method; local password login is unaffected.`,emptyTitle:`No authentication providers registered`,emptyDescription:`Local auth should always be available — if this list is empty the local-auth builtin failed to register. Check the Addons page for load errors.`,installLabel:`Add provider`};function Ge(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:ge,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA is self-enrolled: each user enables it from their own profile page (My access → Two-factor authentication).`,`API keys + scoped tokens are managed from the API Keys page.`],setupSteps:[`Add users from Users → New user (or seed via CAMSTACK_ADMIN_USER / CAMSTACK_ADMIN_PASS).`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:L,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`First-time sign-ins are auto-provisioned with the configured Default Role.`],setupSteps:[`Register a web app at your IdP and copy the client_id + client_secret.`,"Set the redirect URI to `https://<this-hub>/addon/<addon-id>/callback`.",`Paste issuer + credentials in the Settings panel below — saves on every change.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:L,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:U,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)||e.startsWith(`auth-magic-link`)?{headline:`TOTP / magic-link — second factor or passwordless sign-in.`,icon:U,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:z,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Ke(){let e=h({capName:Q[0].capName},{refetchInterval:Z}),t=h({capName:Q[1].capName},{refetchInterval:Z}),r=O(void 0,{refetchInterval:Z}),i=n(()=>me(r.data??[]),[r.data]),a=n(()=>{let n=[],r=[e.data??[],t.data??[]];for(let[e,t]of Q.entries())for(let a of r[e]??[])n.push({addonId:a.addonId,displayName:i.get(a.addonId)??a.addonId,isActive:a.isActive,capName:t.capName,stageBadge:t.stageBadge});return n},[e.data,t.data,i]);return s(pe,{title:$.title,subtitle:$.subtitle,pageIcon:z,itemIcon:z,capability:Q[0].capName,installButtonLabel:$.installLabel,items:a,isLoading:e.isLoading||t.isLoading,emptyTitle:$.emptyTitle,emptyDescription:$.emptyDescription,renderStatusBadges:e=>e.stageBadge===null?null:s(`span`,{className:`inline-flex items-center rounded-full border border-primary/30 bg-primary/10 px-2 py-0.5 text-[10px] font-medium text-primary`,children:e.stageBadge}),renderExpandedPanel:e=>s(qe,{addonId:e.addonId})})}function qe({addonId:e}){let n=Ge(e),r=n.icon;return t(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[t(`div`,{className:`flex items-start gap-2.5`,children:[s(r,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),s(`div`,{className:`text-xs text-foreground font-medium`,children:n.headline})]}),s(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:n.bullets.map((e,t)=>s(`li`,{children:e},t))}),n.setupSteps&&n.setupSteps.length>0&&t(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[t(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[s(he,{className:`h-3 w-3`}),`Setup steps`]}),s(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:n.setupSteps.map((e,t)=>s(`li`,{children:e},t))})]}),e===`local-auth`&&t(`div`,{className:`rounded-md border border-blue-500/30 bg-blue-500/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[s(ue,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),t(`span`,{children:[`TOTP / 2FA is self-service: each user enrols from their own profile page —`,` `,s(`a`,{href:`/system/my-access`,className:`underline text-primary`,children:`My access`}),` `,`→ “Two-factor authentication” → Enable 2FA. Admins can only remove a user’s active enrollment (lost device) from the`,` `,s(`a`,{href:`/system/users`,className:`underline text-primary`,children:`Users`}),` `,`page via Actions → “Remove 2FA”.`]})]})]})}function Je(){return s(`div`,{className:`flex flex-col p-4`,children:s(fe,{tabs:[{id:`users`,label:`Users`,icon:be,content:s(Ee,{})},{id:`api-keys`,label:`Tokens`,icon:ie,content:s(Me,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:ve,content:s(We,{})},{id:`authentication`,label:`Authentication`,icon:z,content:s(Ke,{})}]})})}export{Je as IdentityPage};
@@ -1 +0,0 @@
1
- import{I as e,K as t,Q as n,S as r,W as i,b as a,o,q as s,x as c,z as l}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 u}from"./player-overlays-DXNKqmwI.js";import{Ar as d,Cr as f,E as p,Gt as m,I as h,Mt as g,Nr as _,P as v,Rr as y,T as b,Tr as x,Ur as S,Vr as C,Y as w,Zr as T,_i as E,_r as D,br as O,hi as ee,kn as k,kr as A,mi as j,mn as M,ot as N,pi as te,rt as ne,vr as re,wr as ie,xi as P,xr as F,yi as I,yr as L}from"./src-C0QlPpXb.js";import{tt as R}from"./src-DAigq6PX.js";import{t as z}from"./ProviderIcon-D8aWAoj0.js";import{t as ae}from"./circle-x-a0OLhq9b.js";import{t as B}from"./FormBuilder-B-sNHhCg.js";import{t as V}from"./plus-CDo9Tbkz.js";import{i as oe,n as H,r as U,t as se}from"./ScanNetworkModal-C8Bakspm.js";import{t as ce}from"./refresh-cw-CikJV4hg.js";import{t as W}from"./rotate-cw-DDRA2uuI.js";import{t as le}from"./wifi-DNsDHc6u.js";import{A as ue,C as G,I as K,J as de,K as q,P as fe,R as pe,W as me,X as he,Y as ge,i as _e,k as ve,m as ye,o as J,p as be,s as xe,t as Y,z as Se}from"./index-DhYfPTfU.js";var Ce=q(`search-x`,[[`path`,{d:`m13.5 8.5-5 5`,key:`1cs55j`}],[`path`,{d:`m8.5 8.5 5 5`,key:`a8mexj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]);n();function we(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...we(n.fields));return t}function Te(t,n,r){let[a,o]=s(`idle`),[c,l]=s({}),u=i(()=>{let e=[];for(let n of t.sections)e.push(...we(n.fields));return e},[t]),d=u.length>0&&r!==void 0,f=e(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:a,hasProbeFields:d,probeResults:c,handleTestAll:e(async()=>{if(!r)return;let e=u.filter(e=>{let t=n[e];return t!=null&&String(t).trim()!==``});if(e.length===0)return;o(`testing`);let t={};for(let n of e)t[n]={status:`probing`};l(t);let i=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await r(e,n[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),a={};for(let e of i)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;a[t]={status:n.status===`ok`?`ok`:`error`,result:n}}l(a),o(`idle`)},[r,u,n]),clearProbeResult:f}}n();function X(e){let t=[];for(let n of e)`required`in n&&n.required===!0&&`key`in n&&n.key&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...X(n.fields));return t}function Z(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Q(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Q(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function Ee(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function De({open:t,integrationId:n,addonId:a,onClose:u}){let{t:d}=Y(),f=o(),[p,m]=s({}),[h,g]=s(!1),[v,y]=s(null),[b,x]=s(Ee),S=C({addonId:a},{enabled:t}),E=S.data?.deviceType??null,D=_({addonId:a,type:E??R.Camera},{enabled:t&&S.isSuccess&&E!==null}),O=D.data??null;l(()=>{t&&(m(O?Q(O.sections.flatMap(e=>e.fields)):{}),x(Ee()),g(!1),y(null))},[t,n,O]);let ee=i(()=>({...p,_probeRequestId:b}),[p,b]),k=ie({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),A=T(),j=e(async(e,t)=>{g(!0);let n=await A.mutateAsync({addonId:a,type:E??R.Camera,key:e,value:t,formValues:ee});return n.status===`ok`&&n.suggestedValues&&m(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Z(e[i])&&!Z(a)&&(r[i]=a,t=!0);return t?r:e}),n},[A,a,ee,E]),{testAllStatus:M,hasProbeFields:N,probeResults:te,handleTestAll:ne,clearProbeResult:re}=Te(O??{sections:[]},p,j);async function P(e){y(null);try{await k.mutateAsync({addonId:a,type:E??R.Camera,config:p,integrationId:n}),e?m(O?Q(O.sections.flatMap(e=>e.fields)):{}):u()}catch(e){y(e instanceof Error?e.message:String(e))}}if(!t)return null;let F=X((O?.sections??[]).flatMap(e=>e.fields)).filter(e=>Z(p[e])),I=F.length===0,L=S.isLoading||E!==null&&D.isLoading,z=S.isError||S.isSuccess&&E===null||D.isError||D.isSuccess&&O===null;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:u}),r(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[calc(90dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl`,children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:d(`integrations.addDevice`)}),c(`button`,{onClick:u,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:c(_e,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:L?c(`div`,{className:`flex items-center justify-center py-8`,children:c(G,{className:`h-5 w-5 animate-spin text-primary`})}):z?r(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[c(J,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`space-y-1`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,c(`span`,{className:`font-mono`,children:a}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):c(B,{schema:O,values:p,onChange:m,onTestField:j,probeResults:te,onClearProbe:re})}),!z&&!L&&r(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[r(`button`,{type:`button`,onClick:()=>g(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[r(`span`,{className:`flex items-center gap-2`,children:[c(ye,{className:`h-3.5 w-3.5`}),`Test logs`,c(`span`,{className:`font-mono text-[9px] opacity-60`,children:b.slice(0,14)})]}),c(pe,{className:`h-3.5 w-3.5 transition-transform ${h?`rotate-180`:``}`})]}),h&&c(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:c(w,{addonId:a,requestId:b,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!z&&!L&&(v||F.length>0)&&c(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[c(J,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:v||`Required: ${F.join(`, `)}`})]})}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:u,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:d(`integrations.cancel`)}),!z&&N&&r(`button`,{type:`button`,onClick:ne,disabled:M===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[M===`testing`?c(G,{className:`h-3.5 w-3.5 animate-spin`}):c(le,{className:`h-3.5 w-3.5`}),`Test All`]})]}),r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:()=>P(!0),disabled:z||!I||k.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:d(`integrations.saveAndNew`)}),c(`button`,{onClick:()=>P(!1),disabled:z||!I||k.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:k.isPending?d(`integrations.saving`):d(`integrations.save`)})]})]})]})]})}var Oe=1500;function ke({addonId:e,integrationId:t,jobId:n,onFinished:i}){let{t:a}=Y(),o=D(),s=(O({addonId:e,integrationId:t},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?Oe:!1}).data??[]).find(e=>e.jobId===n);if(!s)return null;let l=s.state===`running`,u=s.processed,d=s.total>0?Math.round(u/s.total*100):0;!l&&s.finishedAt!==null&&i();let f=[`${u}/${s.total} ${a(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];s.adopted>0&&f.push(`${s.adopted} ${a(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),s.alreadyAdopted>0&&f.push(`${s.alreadyAdopted} ${a(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),s.failed>0&&f.push(`${s.failed} ${a(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let p=f.join(` · `);return r(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[r(`div`,{className:`flex items-center gap-2`,children:[l?c(G,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):s.failed>0?c(J,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):s.state===`cancelled`?c(ae,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):c(fe,{className:`h-3.5 w-3.5 text-primary shrink-0`}),c(`p`,{className:`text-[11px] text-foreground`,children:p}),l&&c(`button`,{onClick:()=>o.mutate({jobId:n}),className:`ml-auto rounded-lg border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:a(`integrations.adoptJobCancel`,{defaultValue:`Stop`})})]}),c(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:c(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${d}%`},role:`progressbar`,"aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100})}),s.results.filter(e=>e.outcome===`failed`).slice(0,5).map(e=>r(`p`,{className:`text-[11px] text-destructive`,children:[e.childNativeId,`: `,e.error]},e.childNativeId))]})}function Ae(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}n();var $=`devices`,je={id:$,label:`Devices`,isDefault:!0},Me=2e4,Ne=100;function Pe({addonId:n,integrationId:i,onClose:a}){let{t:o}=Y(),[u,d]=s(new Set),[p,m]=s(new Set),[g,_]=s(new Map),[y,x]=s(null),{data:S}=ee(),C=(S??[]).find(e=>e.addonId===n)?.supportsLocationImport??!1,[w,T]=s(!0),E=re({addonId:n,integrationId:i}).data?.filters,D=E&&E.length>0?E:[je],[O,k]=s(D.find(e=>e.isDefault)?.id??(D.some(e=>e.id===$)?$:D[0].id)),A=O!==$,j=F(),M=L({addonId:n,integrationId:i,page:1,pageSize:Me,filter:O}),N=M.refetch,te=j.mutate,ne=e(()=>{te({addonId:n,integrationId:i},{onSettled:()=>{N()}})},[te,n,i,N]),ie=t(null);l(()=>{let e=`${n}::${i}`;ie.current===e||M.isLoading||(ie.current=e,(M.data?.candidates.length??0)===0&&ne())},[n,i,M.isLoading,M.data,ne]);let P=j.isPending,I=j.isError?j.error instanceof Error?j.error.message:String(j.error):null,R=typeof j.data?.lastError==`string`&&j.data.lastError.length>0?j.data.lastError:null,z=M.data?.candidates??[],ae=M.isError?M.error instanceof Error?M.error.message:String(M.error):null,B=f(),[V,oe]=s(null),H=e(e=>{e.alreadyAdopted||d(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),U=e(e=>{m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),se=e((e,t)=>{_(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),ce=e(e=>{let t={};for(let n of e){let e=g.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[g]),le=e(async()=>{x(null);let e=[...u];if(e.length!==0)try{let t=ce(e),{jobId:r}=await B.mutateAsync({addonId:n,integrationId:i,filter:O,childNativeIds:e,...t?{perCandidate:t}:{},...C?{importLocations:w}:{}});oe(r),d(new Set),_(new Map)}catch(e){x(e instanceof Error?e.message:String(e))}},[u,ce,B,n,i,O,C,w]),ue=t(null),K=e(()=>{V===null||ue.current===V||(ue.current=V,N())},[V,N]),de=e(e=>{k(e),d(new Set),m(new Set),_(new Map),x(null)},[]),q=u.size;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:a}),r(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] rounded-xl border border-border bg-background shadow-2xl`,children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[r(`div`,{className:`min-w-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:o(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),c(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:o(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),r(`div`,{className:`flex items-center gap-3 shrink-0`,children:[C&&r(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[c(`input`,{type:`checkbox`,checked:w,onChange:e=>T(e.target.checked),className:`accent-primary`}),o(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),c(`button`,{onClick:a,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:c(_e,{className:`h-4 w-4`})})]})]}),r(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(I??ae??R)&&z.length===0&&c(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[c(J,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`min-w-0`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:o(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),c(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:I??ae??R})]})]})}),D.length>1&&c(Fe,{filters:D,activeFilter:O,onSelect:de}),c(`div`,{className:`flex-1 min-h-0`,children:c(b,{mode:`generic`,items:z,pageSize:Ne,getKey:e=>e.childNativeId,getSearchText:Ae,getFilterType:e=>e.type,filterOptions:v(),filterLabel:o(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:M.isLoading||P&&z.length===0,searchPlaceholder:o(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(I??ae??R)&&z.length===0?``:o(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:r(`button`,{type:`button`,onClick:ne,disabled:P,title:o(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[c(W,{className:`h-3.5 w-3.5 ${P?`animate-spin`:``}`}),o(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:o(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>c(Ie,{candidate:e,expandable:!A,expanded:p.has(e.childNativeId),onToggleExpand:()=>U(e.childNativeId),adoptedLabel:o(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:o(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=h(e.type),n=t.icon;return r(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[c(n,{className:`h-3.5 w-3.5 shrink-0`}),t.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>c(`div`,{className:`flex items-center justify-end`,children:c(`button`,{onClick:()=>H(e),disabled:e.alreadyAdopted,"aria-label":u.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${u.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:u.has(e.childNativeId)&&c(Se,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!A&&p.has(e.childNativeId),renderExpanded:A?void 0:e=>c(Le,{candidate:e,hiddenChildIds:g.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>se(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:u.has(e.childNativeId)?`bg-primary/5`:``})})]}),y&&c(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[c(J,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:y})]})}),V!==null&&c(ke,{addonId:n,integrationId:i,jobId:V,onFinished:K}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[c(`div`,{}),r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:a,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:o(`integrations.cancel`,{defaultValue:`Cancel`})}),r(`button`,{onClick:le,disabled:q===0||B.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,children:[B.isPending&&c(G,{className:`h-3.5 w-3.5 animate-spin`}),o(`integrations.addSelected`,{defaultValue:`Add selected`}),q>0?` (${q})`:``]})]})]})]})]})}function Fe({filters:e,activeFilter:t,onSelect:n}){return c(`div`,{role:`tablist`,"aria-label":`Discovery granularity`,className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return c(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function Ie({candidate:e,expandable:t,expanded:n,onToggleExpand:i,adoptedLabel:a}){let o=(e.children??[]).length;return r(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&o>0?r(`button`,{type:`button`,onClick:i,"aria-label":n?`Collapse`:`Expand`,"aria-expanded":n,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[c(n?pe:K,{className:`h-3.5 w-3.5`}),o]}):c(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),c(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&c(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:a})]})}function Le({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let i=e.children??[];return i.length===0?null:c(`div`,{className:`space-y-1 py-1`,children:i.map(e=>{let i=t.has(e.childNativeId),a=e.capabilities??[];return r(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${i?`opacity-50`:``}`,children:[c(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),a.length>0&&c(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:a.join(`, `)}),c(`button`,{onClick:()=>n(e.childNativeId),"aria-label":i?`Show child`:`Hide child`,title:i?`Show after adopt`:`Hide after adopt`,className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:c(i?ue:ve,{className:`h-3 w-3`})})]},e.childNativeId)})})}n();function Re(e){let t=[];for(let n of e){if(n.type===`group`){t.push(...Re(n.fields));continue}`key`in n&&typeof n.key==`string`&&t.push(n.key)}return t}function ze(e,t){if(!e)return{};let n=new Set(e.sections.flatMap(e=>Re(e.fields))),r={};for(let e of n)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}function Be(e){return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{if(`value`in e){let{value:t,...n}=e;return n}return e})}))}}function Ve({integrationId:e,addonId:t,name:n,kind:a,mode:s,brokerKind:l,canTest:u=!1,trpc:d,onClose:f}){let{t:p}=Y(),h=o(),{data:g,isLoading:_}=E({id:e},{enabled:s===`account`||s===`broker`}),v=i(()=>{let e=g?.brokerId;return typeof e==`string`?e:null},[g]),{data:y,isLoading:b}=M({addonId:t,nodeId:`hub`},{enabled:s===`account`}),x=i(()=>y?Be(y):null,[y]),S=I(),C=t=>{S.mutate({id:e,settings:t},{onSuccess:()=>{h.invalidateQueries(),f()}})};return c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onClick:f,children:r(`div`,{className:`max-h-[85vh] w-full max-w-lg overflow-y-auto rounded-xl border border-border bg-surface p-5 shadow-xl`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`mb-3 flex items-center justify-between`,children:[r(`h2`,{className:`text-sm font-semibold text-foreground`,children:[p(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]}),c(`button`,{onClick:f,className:`rounded-md p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":p(`common.close`,{defaultValue:`Close`}),children:c(_e,{className:`h-4 w-4`})})]}),s===`broker`?l?r(`div`,{className:`space-y-3`,children:[c(`p`,{className:`text-[11px] text-foreground-subtle`,children:p(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),v&&r(`p`,{className:`text-[11px] text-foreground`,children:[p(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,c(`span`,{className:`font-mono text-foreground-subtle`,children:v})]}),S.isPending?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(G,{className:`h-3 w-3 animate-spin`}),p(`integrations.saving`,{defaultValue:`Saving…`})]}):c(U,{kind:l,onResolved:e=>{C({brokerId:e})},onBack:f}),S.isError&&c(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):c(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):s===`account`?_||b?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(G,{className:`h-3 w-3 animate-spin`}),p(`integrations.loading`,{defaultValue:`Loading…`})]}):c(H,{addonId:t,configSchema:x,canTest:u,initialName:n,initialConfig:ze(x,g??{}),submitLabel:p(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e})=>C(e),onBack:f}):c(m,{trpc:d,addonId:t,nodeId:`hub`,title:n})]})})}n();function He(){let{t}=Y(),{integrationId:n}=ge(),f=o(),m=de(),[h,_]=he(),v=u(),[C,T]=s(!1),[E,D]=s(!1),[O,re]=s(!1),[ie,F]=s(!1),[I,L]=s(!1),{data:R,isLoading:ae}=j({id:n??``},{enabled:!!n}),{data:B}=M({addonId:R?.addonId??``,nodeId:`hub`},{enabled:!!R?.addonId}),{data:H,isSuccess:U}=ee(),W=i(()=>{let e=R?.addonId;return!e||!U?null:(H??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[H,R?.addonId,U]),{data:le}=A({}),ue=i(()=>(le?.providers??[]).some(e=>e.addonId===R?.addonId),[le,R?.addonId]),K=W!==null,q=R?.info?.fixed===!0,fe=K?W===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),pe=i(()=>{let e=R?.addonId;return!e||!U?null:(H??[]).find(t=>t.addonId===e)?.brokerKind??null},[H,R?.addonId,U]),ve=i(()=>{let e=R?.addonId;return!e||!U?!1:(H??[]).find(t=>t.addonId===e)?.canTest===!0},[H,R?.addonId,U]),Se=i(()=>{let e=R?.addonId;return!e||!U?null:(H??[]).find(t=>t.addonId===e)?.mode??null},[H,R?.addonId,U]);l(()=>{h.get(`add`)===`1`&&K&&(T(!0),_(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[h,K,_]);let we=B!=null&&Array.isArray(B.sections)&&B.sections.some(e=>e.fields.length>0),{data:Te}=y({},{refetchInterval:5e3}),X=[[`integrations`,`get`],{input:{id:n??``},type:`query`}],Z=P({onMutate:async e=>{await f.cancelQueries({queryKey:X});let t=f.getQueryData(X);return t!=null&&f.setQueryData(X,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&f.setQueryData(X,r.previous)},onSettled:()=>{f.invalidateQueries({queryKey:[[`integrations`]]}),f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=te({onSuccess:()=>{f.invalidateQueries({queryKey:[[`integrations`]]}),f.invalidateQueries({queryKey:[[`deviceManager`]]}),F(!1),m(`/integrations`)}}),Ee=k({onSuccess:()=>{f.invalidateQueries({queryKey:[[`integrations`]]}),f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Oe=S({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ke=x({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ae=d({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),$=i(()=>Te??[],[Te]),je=i(()=>{let e=new Map;for(let t of $)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[$]),Me=e(e=>je.get(e)??null,[je]),Ne=e(e=>c(z,{type:e,size:`sm`}),[]),Fe=e(e=>m(`/devices/${String(e)}`),[m]),Ie=i(()=>{let e=R?.addonId;return e?$.filter(t=>t.addonId===e):[]},[$,R?.addonId]),Le=i(()=>p(Ie).length,[Ie]);return ae?r(`div`,{className:`p-4`,children:[c(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),c(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):R?r(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[c(N,{items:[{label:`Integrations`,onClick:()=>m(`/integrations`)},{label:R.name}]}),r(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[r(`div`,{className:`flex items-center gap-3 min-w-0`,children:[c(`img`,{src:`/api/addon-assets/${R.addonId}/assets/icon.svg`,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:e=>{e.target.style.display=`none`}}),r(`div`,{className:`min-w-0`,children:[c(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:R.name}),r(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[R.addonId,` · `,Le,` `,t(`integrations.devices`)]})]})]}),r(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[ue&&r(`button`,{onClick:()=>D(!0),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 network for devices (incl. a different subnet)`,children:[c(oe,{className:`h-3.5 w-3.5`}),`Scan network`]}),!q&&r(`button`,{onClick:()=>T(!0),disabled:!K,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 disabled:opacity-50 disabled:cursor-not-allowed`,title:fe,children:[c(V,{className:`h-3.5 w-3.5`}),fe]}),r(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Z.isPending?`opacity-60`:``} ${R.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[c(g,{checked:R.enabled,onCheckedChange:e=>Z.mutate({id:n,enabled:e}),disabled:Z.isPending,"aria-label":R.enabled?`Disable integration`:`Enable integration`}),c(`span`,{className:`text-[11px] font-medium ${R.enabled?`text-success`:`text-foreground-subtle`}`,children:R.enabled?`Enabled`:`Disabled`}),Z.isPending&&c(G,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Se!==`standalone`&&(we||W===`device-adoption`)&&r(`button`,{onClick:()=>re(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[c(be,{className:`h-3 w-3`}),t(`integrations.config`)]}),r(`button`,{onClick:()=>L(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:t(`integrations.logs`,{defaultValue:`View logs`}),children:[c(ye,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),c(ne,{label:`Restart`,icon:ce,title:`Restart "${R.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Le} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Ee.isPending,action:()=>Ee.mutateAsync({addonId:R.addonId})}),!q&&r(`button`,{onClick:()=>F(!0),className:`flex items-center gap-1.5 rounded-lg border border-danger bg-danger/10 px-3 py-1.5 text-[11px] font-medium text-danger hover:bg-danger hover:text-background transition-colors`,title:t(`integrations.delete`,{defaultValue:`Delete integration`}),children:[c(xe,{className:`h-3 w-3`}),t(`integrations.delete`,{defaultValue:`Delete`})]})]})]}),c(b,{context:`integration-detail`,devices:$,trpc:v.trpcClient,defaultView:`cards`,forceAddon:R.addonId,urlScope:`root`,lsKey:`integration-detail:${R.addonId}`,resolveIntegrationIcon:Ne,resolveParent:Me,onNavigate:Fe,batchActions:{remove:Oe.mutate,disable:ke.mutate,enable:Ae.mutate},...q?{}:{onDeleteDevice:e=>Oe.mutate({deviceId:e.id})}}),C&&n&&W===`device-adoption`&&c(Pe,{addonId:R.addonId,integrationId:n,onClose:()=>T(!1)}),C&&n&&W===`device-provider`&&c(De,{open:C,integrationId:n,addonId:R.addonId,onClose:()=>T(!1)}),E&&R&&c(se,{open:E,scope:{addonId:R.addonId,label:R.name},onClose:()=>D(!1)}),O&&n&&W!==null&&Se!==null&&c(Ve,{integrationId:n,addonId:R.addonId,name:R.name,kind:W,mode:Se,brokerKind:pe,canTest:ve,trpc:v.trpcClient,onClose:()=>re(!1)}),I&&c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>L(!1),children:r(`div`,{className:`flex flex-col rounded-xl border border-border bg-surface shadow-xl w-full max-w-5xl h-[80vh]`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5`,children:[r(`div`,{className:`flex items-center gap-2 min-w-0`,children:[c(ye,{className:`h-4 w-4 text-primary shrink-0`}),c(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:R.name}),r(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[R.addonId,n?` · ${n}`:``]})]}),c(`button`,{onClick:()=>L(!1),className:`flex h-7 w-7 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close logs`,children:c(_e,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:c(w,{addonId:R.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})}),ie&&c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:()=>!Q.isPending&&F(!1),children:r(`div`,{className:`rounded-xl border border-border bg-background p-5 shadow-2xl w-96 space-y-3`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`flex items-start gap-3`,children:[c(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg bg-danger/10 shrink-0`,children:c(J,{className:`h-4 w-4 text-danger`})}),r(`div`,{className:`min-w-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.deleteTitle`,{defaultValue:`Delete integration?`})}),c(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:t(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:R.name,count:Le})})]})]}),Q.error&&c(`div`,{className:`rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:Q.error instanceof Error?Q.error.message:String(Q.error)}),r(`div`,{className:`flex items-center justify-end gap-2 pt-1`,children:[c(`button`,{onClick:()=>F(!1),disabled:Q.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:t(`integrations.cancel`,{defaultValue:`Cancel`})}),c(`button`,{onClick:()=>Q.mutate({id:n}),disabled:Q.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-danger px-3 py-1.5 text-[11px] font-medium text-background hover:bg-danger/90 transition-colors disabled:opacity-60 disabled:cursor-not-allowed`,children:Q.isPending?r(a,{children:[c(G,{className:`h-3 w-3 animate-spin`}),t(`integrations.deleting`,{defaultValue:`Deleting…`})]}):r(a,{children:[c(xe,{className:`h-3 w-3`}),t(`integrations.confirmDelete`,{defaultValue:`Delete integration`})]})})]})]})})]}):r(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[c(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:c(Ce,{className:`h-6 w-6 text-foreground-subtle`})}),r(`div`,{className:`space-y-1 max-w-sm`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),c(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:n??``})})]}),r(`button`,{onClick:()=>m(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[c(me,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}export{He as IntegrationDetailPage};