@camstack/addon-admin-ui 1.2.49 → 1.2.51

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 (113) hide show
  1. package/dist/assets/AddLocationWizard-DNy5Mpkx.js +1 -0
  2. package/dist/assets/{AddonCollectionPage-CK4v9jSU.js → AddonCollectionPage-BJnHA6Yr.js} +1 -1
  3. package/dist/assets/{Addons-Dnx44V_o.js → Addons-Cx7V8zJb.js} +1 -1
  4. package/dist/assets/{AdminTabs-BjQnY4OV.js → AdminTabs-DDdG-sMf.js} +1 -1
  5. package/dist/assets/AiProfiles-Cp3cneae.js +1 -0
  6. package/dist/assets/{BrokerForm-CUTNnLfC.js → BrokerForm-K-dcLKZI.js} +1 -1
  7. package/dist/assets/Build-AVaTYSvX.js +32 -0
  8. package/dist/assets/{Capabilities-DmsUSTXd.js → Capabilities-C1fnI28W.js} +1 -1
  9. package/dist/assets/CapabilityBadges-Cr4n7U9J.js +1 -0
  10. package/dist/assets/Cluster-PVE8gXDb.js +1 -0
  11. package/dist/assets/Data-C49zrG4_.js +1 -0
  12. package/dist/assets/DetectionIntelligence-BJYtPF7e.js +1 -0
  13. package/dist/assets/{DeviceAggregateSection-D1VtHpJo.js → DeviceAggregateSection-DgOxdPpF.js} +1 -1
  14. package/dist/assets/DeviceDetail-DGf2HDVz.js +2 -0
  15. package/dist/assets/{Devices-rXat7KjL.js → Devices-BS4wjono.js} +1 -1
  16. package/dist/assets/{EmbedPlayerPage-DNvt-aaI.js → EmbedPlayerPage-D__4YSNi.js} +1 -1
  17. package/dist/assets/Events-DTfEa8Xp.js +1 -0
  18. package/dist/assets/{FormBuilder-D4TCK09f.js → FormBuilder-DLUFwW44.js} +1 -1
  19. package/dist/assets/{Identity-C7zrPYT4.js → Identity-9ZXwQ8Qj.js} +1 -1
  20. package/dist/assets/IntegrationDetail-wgWm0f_a.js +1 -0
  21. package/dist/assets/{Integrations-CWOM_mMA.js → Integrations-D1Nfik-a.js} +1 -1
  22. package/dist/assets/Integrations-SvM59zTM.js +1 -0
  23. package/dist/assets/{Logs-CNmLN2Va.js → Logs-Bs6Rv2Ue.js} +1 -1
  24. package/dist/assets/{MotionZonesSettings-Dok-N0KG.js → MotionZonesSettings-kfj2QnsS.js} +1 -1
  25. package/dist/assets/{MyAccess-DyujbjpW.js → MyAccess-hIeekqXv.js} +1 -1
  26. package/dist/assets/{Network-Ct57a8tW.js → Network-DOM164N5.js} +1 -1
  27. package/dist/assets/{NodeAddonsSettingsPanel-BVpPQh6Y.js → NodeAddonsSettingsPanel-612ENZmF.js} +1 -1
  28. package/dist/assets/{NodeInferenceDevices-DciF7oLw.js → NodeInferenceDevices-B5Bgeva1.js} +1 -1
  29. package/dist/assets/Notifications-wnbYqx8i.js +1 -0
  30. package/dist/assets/Pipeline-overMmnx.js +1 -0
  31. package/dist/assets/{Plates-DWVIZ4YS.js → Plates-DYkITuuM.js} +1 -1
  32. package/dist/assets/{PrivacyMaskSettings-CUaRx10f.js → PrivacyMaskSettings-IJQHYGp1.js} +1 -1
  33. package/dist/assets/{ProviderIcon-nTPdMviY.js → ProviderIcon-vnOQu4D_.js} +1 -1
  34. package/dist/assets/Recordings-DH6ez1Es.js +1 -0
  35. package/dist/assets/{ScanNetworkModal-DBfj4Bdm.js → ScanNetworkModal-CwMfO7lF.js} +1 -1
  36. package/dist/assets/{Settings-BxZlSYcW.js → Settings-DPImfbkR.js} +1 -1
  37. package/dist/assets/{Showroom-BwtVPGmm.js → Showroom-BeepOPUy.js} +1 -1
  38. package/dist/assets/{Terminal-D-FupEae.js → Terminal-B82c1yAn.js} +1 -1
  39. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DOJdLj_I.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-wu1e72UY.js} +1 -1
  40. package/dist/assets/{boxes-DvSDRyF7.js → boxes-B7U_g34P.js} +1 -1
  41. package/dist/assets/{build-cluster-graph-DyYa_05V.js → build-cluster-graph-xMKW01JX.js} +1 -1
  42. package/dist/assets/circle-check-big-DbbuCHA7.js +1 -0
  43. package/dist/assets/{circle-x-DtQPDgsE.js → circle-x-BJrsiGED.js} +1 -1
  44. package/dist/assets/clock-BzQeAJLI.js +1 -0
  45. package/dist/assets/{copy-BfSZhaqH.js → copy-CbIxHx6V.js} +1 -1
  46. package/dist/assets/{debounced-invalidate-6ffK2Oyp.js → debounced-invalidate-BWVZIfGh.js} +1 -1
  47. package/dist/assets/{dist-35X66BEr.js → dist-CK2-8PIG.js} +1 -1
  48. package/dist/assets/dist-V9rU1EMp.js +345 -0
  49. package/dist/assets/{download-BYiYWbFt.js → download-BuRZXNAu.js} +1 -1
  50. package/dist/assets/{face-bbox-CnPEtuY2.js → face-bbox-l0r3wxrB.js} +1 -1
  51. package/dist/assets/{hard-drive-DrH4p5NE.js → hard-drive-C0ZMQERE.js} +1 -1
  52. package/dist/assets/{hostInit-CyX7yag6.js → hostInit-CZjykJiy.js} +1 -1
  53. package/dist/assets/index-DSr9rXmX.js +4 -0
  54. package/dist/assets/index-DchMAgXl.css +2 -0
  55. package/dist/assets/{key-round-dZ1BFcdp.js → key-round-ByTafiD4.js} +1 -1
  56. package/dist/assets/{mf-entry-bootstrap-0-9f224a8e.js → mf-entry-bootstrap-0-7ce16675.js} +2 -2
  57. package/dist/assets/{pencil-Bz_ZrJOa.js → pencil-BxEumTq9.js} +1 -1
  58. package/dist/assets/play-pHCxem5A.js +1 -0
  59. package/dist/assets/{player-overlays-COkjFkib.js → player-overlays-DinWO-iY.js} +1 -1
  60. package/dist/assets/plus-BMSMXTLJ.js +1 -0
  61. package/dist/assets/power-9X4iJTM0.js +1 -0
  62. package/dist/assets/{radio-Db7gl-zS.js → radio-CxrlOtbH.js} +1 -1
  63. package/dist/assets/{refresh-cw-CGyy1yV7.js → refresh-cw-DB5OvXUG.js} +1 -1
  64. package/dist/assets/remoteEntry-DNPsGym2.js +1 -0
  65. package/dist/assets/rotate-ccw-DYs2JMeO.js +1 -0
  66. package/dist/assets/rotate-cw-WDm6QfVu.js +1 -0
  67. package/dist/assets/search-CHhIsfkX.js +1 -0
  68. package/dist/assets/{send-BRkSGin7.js → send-pgjPnGAN.js} +1 -1
  69. package/dist/assets/{server-BQv2rJCm.js → server-DsrrDrbP.js} +1 -1
  70. package/dist/assets/{square-check-big-Ga52OEfa.js → square-check-big-DUS4_d2a.js} +1 -1
  71. package/dist/assets/square-tm1n9gYQ.js +1 -0
  72. package/dist/assets/src-BEXY7p5t.js +345 -0
  73. package/dist/assets/src-DdYzDsDP.js +67 -0
  74. package/dist/assets/{undo-2-J1RIT6Px.js → undo-2-CaoR3oN8.js} +1 -1
  75. package/dist/assets/{upload-BvwaLd2o.js → upload-Daxobvp0.js} +1 -1
  76. package/dist/assets/{useEventInvalidation-BsKdSBfH.js → useEventInvalidation-BuGmF-ta.js} +1 -1
  77. package/dist/assets/video-B5xcnORf.js +1 -0
  78. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BJpuTutd.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-B-pSXqXs.js} +2 -2
  79. package/dist/assets/{wifi-DQcK0Biw.js → wifi-B7sFkP2k.js} +1 -1
  80. package/dist/assets/zap-khmquTMk.js +1 -0
  81. package/dist/index.html +6 -6
  82. package/dist/server/addon.js +519 -18
  83. package/package.json +1 -1
  84. package/dist/assets/AddLocationWizard-BJu3mtSw.js +0 -1
  85. package/dist/assets/AiProfiles-Tiz5n9gM.js +0 -1
  86. package/dist/assets/Build-BRIKYrPw.js +0 -32
  87. package/dist/assets/CapabilityBadges-Da9_ag1O.js +0 -1
  88. package/dist/assets/Cluster-BmsvZJvy.js +0 -1
  89. package/dist/assets/Data-H8wE3b6C.js +0 -1
  90. package/dist/assets/DetectionIntelligence-I9-ie1ja.js +0 -1
  91. package/dist/assets/DeviceDetail-DV8r8vC8.js +0 -2
  92. package/dist/assets/Events-FgGu0qQ0.js +0 -1
  93. package/dist/assets/IntegrationDetail-Blpd6T8m.js +0 -1
  94. package/dist/assets/Integrations-C21FuAge.js +0 -1
  95. package/dist/assets/Notifications-OJ3PnTPK.js +0 -1
  96. package/dist/assets/Pipeline-eSN-kICU.js +0 -1
  97. package/dist/assets/Recordings-BkZiVZTc.js +0 -1
  98. package/dist/assets/circle-check-big-FWiOlzic.js +0 -1
  99. package/dist/assets/clock-DHnCdO7L.js +0 -1
  100. package/dist/assets/dist-IhEsNjtp.js +0 -345
  101. package/dist/assets/index-BQrlv_je.js +0 -4
  102. package/dist/assets/index-DfbxOmzG.css +0 -2
  103. package/dist/assets/play-BlvH1l2D.js +0 -1
  104. package/dist/assets/plus-C5i2pOFJ.js +0 -1
  105. package/dist/assets/power-w9jdL6aH.js +0 -1
  106. package/dist/assets/remoteEntry-C6r9GH5z.js +0 -1
  107. package/dist/assets/rotate-ccw-DC6Yovo0.js +0 -1
  108. package/dist/assets/rotate-cw-DLAOZ01F.js +0 -1
  109. package/dist/assets/search-BFiLJvvR.js +0 -1
  110. package/dist/assets/square-DVLwx5hK.js +0 -1
  111. package/dist/assets/src-Di5BmOTg.js +0 -345
  112. package/dist/assets/src-bB3TQU8X.js +0 -67
  113. package/dist/assets/zap-B_NogjfF.js +0 -1
@@ -1 +0,0 @@
1
- import{$o as e,Fo as t,Io as n,Jo as r,Lo as i,Po as a,Qn as o,Qo as s,S as c,Xo as l,Zo as u,aa as d,as as f,is as p,jo as m,ns as h,qo as g,rs as _,ts as v,vo as y}from"./src-bB3TQU8X.js";import{Q as b,S as x,W as S,a as C,b as w,i as T,o as E,q as D,t as O,x as k,z as A}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{C as j,F as ee,b as te,c as M,o as N,s as P,w as ne}from"./src-Di5BmOTg.js";import{p as F}from"./player-overlays-COkjFkib.js";import{t as I}from"./circle-check-big-FWiOlzic.js";import{t as re}from"./copy-BfSZhaqH.js";import{t as ie}from"./pencil-Bz_ZrJOa.js";import{t as L}from"./plus-C5i2pOFJ.js";import{t as ae}from"./refresh-cw-CGyy1yV7.js";import{t as oe}from"./search-BFiLJvvR.js";import{t as se}from"./send-BRkSGin7.js";import{J as R,N as ce,S as z,V as le,W as ue,f as de,i as fe,o as pe,s as B}from"./index-BQrlv_je.js";import{t as V}from"./AdminPage-Dq33XE9j.js";import{t as me}from"./AdminTabs-BjQnY4OV.js";var he=ue(`bell-off`,[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M17 17H4a1 1 0 0 1-.74-1.673C4.59 13.956 6 12.499 6 8a6 6 0 0 1 .258-1.742`,key:`178tsu`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M8.668 3.01A6 6 0 0 1 18 8c0 2.687.77 4.653 1.707 6.05`,key:`1hqiys`}]]),ge=ue(`bell-ring`,[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M22 8c0-2.3-.8-4.3-2-6`,key:`5bb3ad`}],[`path`,{d:`M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326`,key:`11g9vi`}],[`path`,{d:`M4 2C2.8 3.7 2 5.7 2 8`,key:`tap9e0`}]]),_e=ue(`flask-conical`,[[`path`,{d:`M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2`,key:`18mbvz`}],[`path`,{d:`M6.453 15h11.094`,key:`3shlmq`}],[`path`,{d:`M8.5 2h7`,key:`csnxdl`}]]),ve=ue(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]);b();var H=e=>typeof e==`string`&&e.length>0;function ye(e){return{levels:e.levels,formats:e.format,bodyMaxLen:e.bodyMaxLen,attachmentSlots:e.attachments.mediaTypes,attachmentMode:e.attachments.mode,attachmentMax:e.attachments.max,attachmentMaxBytes:e.attachments.maxBytes,maxActions:e.actions,showActions:e.actions>0,showClickUrl:e.clickUrl,showSound:e.sound,showTtl:e.ttl,showTag:!0}}function be(e,t){return e.format.includes(t)?t:e.format[0]??`text`}function xe(e,t){let n=[];for(let r of e.attachments.mediaTypes){if(n.length>=e.attachments.max)break;let i=t[r];H(i)&&n.push({mediaType:r,url:i})}return n}function Se(e,t){if(e.actions<=0)return[];let n=[];for(let r of t){if(n.length>=e.actions)break;let t=H(r.label),i=H(r.url);!t&&!i||n.push({id:`test-${n.length+1}`,label:t?r.label:`Action ${n.length+1}`,...i?{url:r.url}:{}})}return n}function Ce(e,t){let n=e.levels.some(e=>e.id===t.level)?t.level:void 0,r=xe(e,t.attachmentUrls),i=Se(e,t.actions),a=e.ttl&&H(t.ttl)?Number(t.ttl):void 0;return{body:t.body,format:be(e,t.format),priority:we(t.priority),...H(t.title)?{title:t.title}:{},...n?{level:n}:{},...r.length>0?{attachments:r}:{},...i.length>0?{actions:i}:{},...e.clickUrl&&H(t.clickUrl)?{clickUrl:t.clickUrl}:{},...e.sound&&H(t.sound)?{sound:t.sound}:{},...a!==void 0&&Number.isFinite(a)?{ttl:a}:{},...H(t.tag)?{tag:t.tag}:{}}}function we(e){return Number.isFinite(e)?Math.min(5,Math.max(1,Math.round(e))):3}function Te(e){return e.levels.find(e=>e.flags?.critical===!0)||e.levels.filter(e=>typeof e.ordinal==`number`).sort((e,t)=>t.ordinal-e.ordinal)[0]}function Ee(e){return{level:``,priority:3,format:e.format[0]??`text`,title:``,body:``,attachmentUrls:{},actions:[],clickUrl:``,sound:``,ttl:``,tag:``}}var De={image:`/addon/notifiers/samples/image`,video:`/addon/notifiers/samples/video`,gif:`/addon/notifiers/samples/gif`,audio:`/addon/notifiers/samples/audio`,icon:`/addon/notifiers/samples/icon`};function Oe(e,t){return e.attachments.max>0&&e.attachments.mediaTypes.includes(t)}function ke(e){let t=[`text`];for(let n of[`image`,`gif`,`video`,`audio`])Oe(e,n)&&t.push(n);return e.actions>0&&t.push(`actions`),e.levels.length>0&&t.push(`critical`),t.push(`overflow`),t}function Ae(e,t,n){let r=Ee(e);return Oe(e,t)?{...r,body:n,attachmentUrls:{[t]:De[t]}}:{...r,body:n}}function je(e,t){let n=Ee(e);switch(t){case`text`:return{...n,title:`CamStack`,body:`Test notification — text only.`};case`image`:return Ae(e,`image`,`Test notification with an image.`);case`gif`:return Ae(e,`gif`,`Test notification with an animation.`);case`video`:return Ae(e,`video`,`Test notification with a video.`);case`audio`:return Ae(e,`audio`,`Test notification with audio.`);case`actions`:{let t=Array.from({length:e.actions},(e,t)=>({label:`Action ${t+1}`,url:`/`}));return{...n,title:`CamStack`,body:`Test notification with action buttons.`,actions:t,...e.clickUrl?{clickUrl:`/`}:{}}}case`critical`:{let t=Te(e);return{...n,title:`CamStack`,body:`Critical test notification.`,priority:5,level:t?.id??``}}case`overflow`:return{...n,body:`X`.repeat(e.bodyMaxLen+50)}}}var Me={text:`Text only`,image:`With image`,gif:`With GIF`,video:`With video`,audio:`With audio`,actions:`With buttons`,critical:`Critical`,overflow:`Overflow (advanced)`},U=`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none`,W=`block text-[11px] font-medium text-foreground mb-1`;function Ne({target:e,kind:t,open:n,onClose:i}){let a=F(),o=S(()=>ye(t.caps),[t.caps]),c=S(()=>ke(t.caps),[t.caps]),[d,m]=D(()=>Ee(t.caps)),[h,_]=D(null),v=S(()=>Ce(t.caps,d),[t.caps,d]),y=d.body.length,b=y>o.bodyMaxLen,C=e=>m(t=>({...t,...e})),w=O({mutationFn:()=>a.trpcClient.notificationOutput.testTarget.mutate({addonId:e.addonId,targetId:e.id,sample:Ce(t.caps,d)}),onMutate:()=>_(null),onSuccess:e=>_(e),onError:e=>_({success:!1,error:e instanceof Error?e.message:`Test failed`})}),T=e=>{m(je(t.caps,e)),_(null)},E=(e,t,n)=>{let r=d.actions.length>0?[...d.actions]:[];for(;r.length<=e;)r.push({label:``,url:``});r[e]={...r[e],[t]:n},C({actions:r})};return k(g,{open:n,onOpenChange:e=>!e&&i(),children:x(r,{width:`lg`,className:`!max-w-2xl`,children:[k(u,{children:x(s,{children:[`Test "`,e.name,`" (`,t.label,`)`]})}),x(`div`,{className:`space-y-4 max-h-[60vh] overflow-y-auto pr-1`,children:[k(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map(e=>k(f,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>T(e),children:Me[e]},e))}),x(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[o.levels.length>0&&x(`div`,{children:[k(`label`,{className:W,children:`Level`}),x(`select`,{className:U,value:d.level,onChange:e=>C({level:e.target.value}),children:[k(`option`,{value:``,children:`— derive from priority —`}),o.levels.map(e=>x(`option`,{value:e.id,children:[e.label,e.ordinal===null?` (qualitative)`:` (p${e.ordinal})`]},e.id))]}),(()=>{let e=o.levels.find(e=>e.id===d.level);return e?x(`div`,{className:`mt-1 space-y-1`,children:[e.description&&k(`p`,{className:`text-[10px] text-foreground-subtle`,children:e.description}),x(`div`,{className:`flex flex-wrap gap-1`,children:[e.flags?.critical&&k(p,{variant:`danger`,"data-testid":`flag-critical`,children:`critical`}),e.flags?.silent&&k(p,{variant:`info`,children:`silent`}),e.flags?.noPush&&k(p,{variant:`warning`,children:`no-push`})]}),e.requires&&e.requires.length>0&&x(`p`,{className:`text-[10px] text-warning`,children:[`Requires target config: `,e.requires.join(`, `)]})]}):null})()]}),x(`div`,{children:[x(`label`,{className:W,children:[`Priority (ordinal): `,d.priority]}),k(`input`,{type:`range`,min:1,max:5,step:1,value:d.priority,onChange:e=>C({priority:Number(e.target.value)}),className:`w-full accent-primary`,"aria-label":`priority`})]})]}),o.formats.length>0&&x(`div`,{children:[k(`label`,{className:W,children:`Format`}),k(`div`,{className:`flex flex-wrap gap-2`,children:o.formats.map(e=>x(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground cursor-pointer`,children:[k(`input`,{type:`radio`,name:`format`,className:`accent-primary`,checked:d.format===e,onChange:()=>C({format:e})}),e]},e))})]}),x(`div`,{children:[k(`label`,{className:W,children:`Title`}),k(`input`,{className:U,value:d.title,onChange:e=>C({title:e.target.value})})]}),x(`div`,{children:[x(`label`,{className:W,children:[`Body`,` `,x(`span`,{className:b?`text-danger`:`text-foreground-subtle`,children:[`(`,y,`/`,o.bodyMaxLen,b?` — overflow`:``,`)`]})]}),k(`textarea`,{className:`${U} min-h-[80px] resize-y`,value:d.body,onChange:e=>C({body:e.target.value})})]}),o.attachmentSlots.length>0&&x(`div`,{children:[x(`label`,{className:W,children:[`Attachments`,` `,x(`span`,{className:`text-foreground-subtle`,children:[`(mode: `,o.attachmentMode,`, max `,o.attachmentMax,o.attachmentMaxBytes?`, ≤${Math.round(o.attachmentMaxBytes/1024/1024)}MB`:``,`)`]})]}),k(`div`,{className:`space-y-1.5`,children:o.attachmentSlots.map(e=>x(`div`,{className:`flex items-center gap-2`,children:[k(`span`,{className:`text-[10px] w-12 shrink-0 text-foreground-subtle`,children:e}),k(`input`,{className:U,placeholder:`${e} URL`,value:d.attachmentUrls[e]??``,onChange:t=>C({attachmentUrls:{...d.attachmentUrls,[e]:t.target.value}})})]},e))})]}),o.showActions&&x(`div`,{children:[x(`label`,{className:W,children:[`Actions (up to `,o.maxActions,`)`]}),k(`div`,{className:`space-y-1.5`,children:Array.from({length:Math.min(o.maxActions,3)},(e,t)=>x(`div`,{className:`flex items-center gap-2`,children:[k(`input`,{className:U,placeholder:`label`,value:d.actions[t]?.label??``,onChange:e=>E(t,`label`,e.target.value)}),k(`input`,{className:U,placeholder:`url`,value:d.actions[t]?.url??``,onChange:e=>E(t,`url`,e.target.value)})]},t))})]}),x(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[o.showClickUrl&&x(`div`,{children:[k(`label`,{className:W,children:`Click URL`}),k(`input`,{className:U,value:d.clickUrl,onChange:e=>C({clickUrl:e.target.value})})]}),o.showSound&&x(`div`,{children:[k(`label`,{className:W,children:`Sound`}),k(`input`,{className:U,value:d.sound,onChange:e=>C({sound:e.target.value})})]}),o.showTtl&&x(`div`,{children:[k(`label`,{className:W,children:`TTL (seconds)`}),k(`input`,{className:U,type:`number`,value:d.ttl,onChange:e=>C({ttl:e.target.value})})]}),o.showTag&&x(`div`,{children:[k(`label`,{className:W,children:`Tag`}),k(`input`,{className:U,value:d.tag,onChange:e=>C({tag:e.target.value})})]})]}),h&&k(Pe,{result:h}),x(`details`,{className:`text-[10px]`,children:[k(`summary`,{className:`cursor-pointer text-foreground-subtle`,children:`Payload preview`}),k(`pre`,{className:`mt-1 overflow-x-auto rounded bg-surface p-2 text-foreground-subtle`,children:JSON.stringify(v,null,2)})]})]}),x(l,{children:[k(f,{variant:`secondary`,size:`sm`,type:`button`,onClick:i,children:`Close`}),x(f,{size:`sm`,type:`button`,disabled:w.isPending||d.body.length===0,onClick:()=>w.mutate(),children:[w.isPending?k(z,{className:`h-3.5 w-3.5 animate-spin`}):k(se,{className:`h-3.5 w-3.5`}),`Send test`]})]})]})})}function Pe({result:e}){let t=e.renderedAs;return x(`div`,{className:`rounded-md border px-3 py-2 text-xs ${e.success?`border-success/40 bg-success/10`:`border-danger/40 bg-danger/10`}`,"data-testid":`test-result`,children:[x(`div`,{className:`flex items-center gap-2 font-medium`,children:[e.success?k(I,{className:`h-3.5 w-3.5 text-success`}):k(ce,{className:`h-3.5 w-3.5 text-danger`}),k(`span`,{children:e.success?`Delivered`:`Failed`})]}),e.error&&k(`p`,{className:`mt-1 text-danger`,children:e.error}),t&&x(`dl`,{className:`mt-2 grid grid-cols-2 gap-x-3 gap-y-0.5 text-[11px] text-foreground-subtle`,children:[k(`dt`,{children:`Resolved level`}),k(`dd`,{className:`text-foreground`,children:t.level}),k(`dt`,{children:`Format sent`}),k(`dd`,{className:`text-foreground`,children:t.format}),k(`dt`,{children:`Attachments sent`}),k(`dd`,{className:`text-foreground`,children:t.attachmentsSent}),k(`dt`,{children:`Actions sent`}),k(`dd`,{className:`text-foreground`,children:t.actionsSent}),k(`dt`,{children:`Truncated`}),k(`dd`,{className:`text-foreground`,children:t.truncated?`yes`:`no`}),k(`dt`,{children:`Dropped`}),k(`dd`,{className:`text-foreground`,children:t.dropped.length>0?t.dropped.join(`, `):`—`})]})]})}function Fe(e){let t=[],n=new Map;for(let r of e){let e=n.get(r.addonId);e?e.push(r):(n.set(r.addonId,[r]),t.push(r.addonId))}return t.map(e=>({addonId:e,kinds:n.get(e)??[]}))}function Ie(e){let t=[],n=e=>{for(let r of e){if(r.type===`password`){t.push(r.key);continue}if(r.type===`group`){n(r.fields);continue}if(r.type===`sub-tabs`)for(let e of r.tabs)n(e.fields)}};for(let t of e.sections)n(t.fields);return t}function Le(e,t,n){let r=new Set(n),i={};for(let[n,a]of Object.entries(e)){if(!r.has(n)){i[n]=a;continue}a==null||a===``||a!==t[n]&&(i[n]=a)}return i}function Re(e,t){let n=new Set(t),r={};for(let[t,i]of Object.entries(e))r[t]=n.has(t)?``:i;return r}b();var ze=[`notificationOutput`,`listTargets`],Be=[`notificationOutput`,`listTargetKinds`],Ve=[`userManagement`,`listUsers`],He=`ownerUserId`;function Ue(e){let t=e.config[He];return typeof t==`string`&&t.length>0?t:null}function We(t){return[{key:`name`,header:`Target`,render:e=>{let n=t.kindByKey.get(e.kind);return x(`span`,{className:`flex items-center gap-2`,children:[k(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface text-xs`,title:n?.label??e.kind,children:k(Ge,{kind:n,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:``})}),k(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),!e.enabled&&k(p,{variant:`warning`,children:`disabled`})]})}},{key:`kind`,header:`Kind`,nowrap:!0,render:e=>k(`span`,{className:`text-[11px] text-foreground-subtle`,children:t.kindByKey.get(e.kind)?.label??e.kind})},{key:`owner`,header:`Owner`,nowrap:!0,render:e=>{let n=Ue(e);return n===null?k(p,{variant:`default`,children:`system`}):k(`span`,{className:`text-[11px] text-foreground`,children:t.userNameById.get(n)??n})}},{key:`enabled`,header:`On`,align:`center`,nowrap:!0,render:n=>k(e,{checked:n.enabled,onCheckedChange:e=>t.onToggle(n,e),"aria-label":`toggle ${n.name}`})},{key:`actions`,header:``,align:`right`,nowrap:!0,render:e=>{let n=t.kindByKey.get(e.kind);return x(`span`,{className:`flex items-center justify-end gap-1`,children:[k(f,{size:`sm`,variant:`ghost`,type:`button`,disabled:!n,onClick:()=>t.onTest(e),title:`Test`,children:k(se,{className:`h-3.5 w-3.5`})}),k(f,{size:`sm`,variant:`ghost`,type:`button`,disabled:!n,onClick:()=>n&&t.onEdit(e,n),title:`Edit`,children:k(ie,{className:`h-3.5 w-3.5`})}),k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>t.onDelete(e),title:`Delete`,children:k(B,{className:`h-3.5 w-3.5 text-danger`})})]})}}]}function Ge({kind:e,imgClassName:t,fallbackClassName:n}){return e?.iconUrl?k(`img`,{src:e.iconUrl,alt:e.label,className:t,loading:`lazy`,draggable:!1}):k(`span`,{className:n,children:e?.icon??`🔔`})}function Ke(){let e=F(),[t,n]=D({mode:`closed`}),[r,i]=D(null),a=C({queryKey:ze,queryFn:()=>e.trpcClient.notificationOutput.listTargets.query({})}),o=C({queryKey:Be,queryFn:async()=>(await e.trpcClient.notificationOutput.listTargetKinds.query({})).map(e=>{let t=e.iconUrl;return{...e,configSchema:e.configSchema,iconUrl:t}})}),s=S(()=>o.data??[],[o.data]),c=S(()=>{let e=new Map;for(let t of s)e.set(t.kind,t);return e},[s]),l=C({queryKey:Ve,queryFn:()=>e.trpcClient.userManagement.listUsers.query()}),u=S(()=>{let e=new Map;for(let t of l.data??[])e.set(t.id,t.username);return e},[l.data]),d=O({mutationFn:t=>e.trpcClient.notificationOutput.setTargetEnabled.mutate({addonId:t.target.addonId,targetId:t.target.id,enabled:t.enabled}),onSuccess:()=>void a.refetch()}),p=O({mutationFn:t=>e.trpcClient.notificationOutput.deleteTarget.mutate({addonId:t.addonId,targetId:t.id}),onSuccess:()=>void a.refetch()}),h=r?c.get(r.kind):void 0;return x(V,{icon:le,title:`Notification Targets`,subtitle:`Deliver notifications to ntfy, Pushover, Telegram, Home Assistant and more. Each target's kind declares its capabilities; the test panel shows exactly what a message degrades to.`,actions:x(f,{size:`sm`,type:`button`,onClick:()=>n({mode:`pick-kind`}),children:[k(L,{className:`h-3.5 w-3.5`}),`Add target`]}),children:[a.isLoading&&k(`div`,{className:`flex items-center justify-center py-16`,children:k(z,{className:`h-6 w-6 animate-spin text-primary`})}),a.isError&&!a.isLoading&&k(y,{title:`Failed to load targets`,message:a.error instanceof Error?a.error.message:`Unknown error`,onRetry:()=>void a.refetch()}),!a.isLoading&&!a.isError&&(a.data??[]).length===0&&k(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No notification targets yet. Click "Add target" to configure one.`}),(a.data??[]).length>0&&k(_,{children:k(m,{columns:We({kindByKey:c,userNameById:u,onToggle:(e,t)=>d.mutate({target:e,enabled:t}),onTest:i,onEdit:(e,t)=>n({mode:`form`,kind:t,target:e}),onDelete:e=>p.mutate(e)}),rows:a.data??[],rowKey:e=>e.id,minWidthPx:720,bordered:!1})}),t.mode===`pick-kind`&&k(qe,{kinds:s,onCancel:()=>n({mode:`closed`}),onPick:e=>n({mode:`form`,kind:e,target:null})}),t.mode===`form`&&k(Je,{kind:t.kind,target:t.target,users:l.data??[],onCancel:()=>n({mode:`closed`}),onSaved:()=>{n({mode:`closed`}),a.refetch()}}),r&&h&&k(Ne,{target:r,kind:h,open:!0,onClose:()=>i(null)})]})}function qe({kinds:e,onPick:t,onCancel:n}){let r=S(()=>Fe(e),[e]);return x(_,{className:`p-4 space-y-4`,children:[x(`div`,{className:`flex items-center justify-between`,children:[k(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Choose a notification kind`}),k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:n,children:`Cancel`})]}),r.length===0&&k(`p`,{className:`text-xs text-foreground-subtle`,children:`No notification providers are installed. Install the notifiers addon (or connect Home Assistant) to add targets.`}),r.map(e=>x(`div`,{children:[k(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1.5`,children:e.addonId}),k(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-2`,children:e.kinds.map(n=>x(`button`,{type:`button`,onClick:()=>t(n),className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-xs hover:border-primary/50 hover:bg-surface-hover transition-colors`,children:[k(Ge,{kind:n,imgClassName:`h-7 w-7 object-contain`,fallbackClassName:`text-lg leading-7`}),k(`span`,{className:`font-medium text-foreground`,children:n.label}),n.supportsDiscovery&&k(p,{variant:`info`,style:`outline`,children:`discover`})]},`${e.addonId}:${n.kind}`))})]},e.addonId))]})}function Je({kind:e,target:t,users:n,onSaved:r,onCancel:i}){let a=F(),o=S(()=>Ie(e.configSchema),[e.configSchema]),s=S(()=>t?.config??{},[t]),[l,u]=D(t?.name??e.label),[d,p]=D(()=>t?Re(t.config,o):{}),[m,h]=D(null),[g,y]=D(null),[b,C]=D(t?Ue(t)??``:``),w=O({mutationFn:()=>a.trpcClient.notificationOutput.discoverTargets.query({addonId:e.addonId,kind:e.kind,config:d}),onSuccess:e=>h(e),onError:e=>y(e instanceof Error?e.message:`Discovery failed`)}),T=O({mutationFn:()=>{let{[He]:n,...r}=Le(d,s,o),i=b===``?r:{...r,[He]:b},c={id:t?.id??`${e.kind}-${Date.now()}`,name:l,kind:e.kind,addonId:e.addonId,enabled:t?.enabled??!0,config:i};return a.trpcClient.notificationOutput.upsertTarget.mutate({addonId:e.addonId,target:c})},onSuccess:r,onError:e=>y(e instanceof Error?e.message:`Save failed`)}),E=e=>{u(e.suggestedName),p(t=>({...t,...e.config})),h(null)};return x(_,{className:`p-4 space-y-4`,children:[x(`div`,{className:`flex items-center justify-between`,children:[x(`h3`,{className:`text-sm font-semibold text-foreground flex items-center gap-2`,children:[k(Ge,{kind:e,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:`text-lg`}),t?`Edit ${t.name}`:`Add ${e.label} target`]}),k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:i,children:`Cancel`})]}),g&&k(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:g}),x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Name`}),k(`input`,{className:`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none`,value:l,onChange:e=>u(e.target.value)})]}),x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Owner`}),k(v,{value:b,options:[{value:``,label:`System (shared, admin-managed)`},...n.map(e=>({value:e.id,label:e.username}))],onChange:e=>C(e.target.value)}),k(`p`,{className:`mt-0.5 text-[10px] text-foreground-subtle`,children:`A user-owned target belongs to that user: it shows in their viewer and their own rules may deliver to it. System targets stay admin-managed.`})]}),e.supportsDiscovery&&x(`div`,{className:`space-y-2`,children:[x(f,{size:`sm`,variant:`outline`,type:`button`,disabled:w.isPending,onClick:()=>{y(null),w.mutate()},children:[w.isPending?k(z,{className:`h-3.5 w-3.5 animate-spin`}):k(oe,{className:`h-3.5 w-3.5`}),`Discover`]}),m&&m.length===0&&k(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No candidates discovered.`}),m&&m.length>0&&k(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:m.map((e,t)=>x(`button`,{type:`button`,onClick:()=>E(e),className:`flex w-full items-center justify-between px-3 py-1.5 text-xs hover:bg-surface-hover`,children:[k(`span`,{className:`text-foreground`,children:e.suggestedName}),k(`span`,{className:`text-[10px] text-primary`,children:`use`})]},`${e.suggestedName}-${t}`))})]}),o.length>0&&t&&k(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Secret fields are hidden. Leave them blank to keep the stored value; type a new value to replace it.`}),k(c,{schema:e.configSchema,values:d,onChange:p}),x(`div`,{className:`flex justify-end gap-2`,children:[k(f,{variant:`secondary`,size:`sm`,type:`button`,onClick:i,children:`Cancel`}),x(f,{size:`sm`,type:`button`,disabled:T.isPending||l.trim().length===0,onClick:()=>{y(null),T.mutate()},children:[T.isPending&&k(z,{className:`h-3.5 w-3.5 animate-spin`}),t?`Save changes`:`Create target`]})]})]})}var Ye=[{value:`acknowledge`,label:`Acknowledge`},{value:`dismiss`,label:`Dismiss`},{value:`silence`,label:`Silence`},{value:`view`,label:`View`},{value:`play`,label:`Play`},{value:`open`,label:`Open`},{value:`close`,label:`Close`},{value:`unlock`,label:`Unlock`},{value:`lock`,label:`Lock`},{value:`disarm`,label:`Disarm`},{value:`arm`,label:`Arm`},{value:`light`,label:`Light`},{value:`alert`,label:`Alert`}],Xe={sequences:[],buttons:[]};function Ze(e){return e===void 0?Xe:{sequences:[...e.onTrigger??[]],buttons:[...e.buttons??[]]}}function Qe(e){let t=e.sequences.filter(e=>e.name.trim()!==``),n=e.buttons.filter(e=>e.id.trim()!==``&&e.label.trim()!==``);if(!(t.length===0&&n.length===0))return{...t.length>0?{onTrigger:t}:{},...n.length>0?{buttons:n}:{}}}function $e(e){let t=[],n=new Set;for(let r of e.sequences){let e=r.name.trim();e!==``&&(n.has(e)&&t.push({kind:`duplicate-sequence`,message:`Two sequences are called "${e}". The name is how a button points at one, and how its throttle is keyed.`}),n.add(e),r.actions.length===0&&t.push({kind:`empty-sequence`,message:`"${e}" has no steps, so it would do nothing.`}))}let r=new Set;for(let i of e.buttons){let e=i.id.trim();e!==``&&(r.has(e)&&t.push({kind:`duplicate-button`,message:`Two buttons share the id "${e}". The id is what the audit line names when one is tapped.`}),r.add(e),n.has(i.sequence.trim())||t.push({kind:`unknown-sequence`,message:`"${i.label||e}" points at the sequence "${i.sequence}", which this rule does not have. It would never appear on a notification.`}))}return t}function et(e){return{name:`sequence ${String(e+1)}`,enabled:!1,actions:[]}}function tt(e,t){return{id:`action-${String(e+1)}`,label:`Action`,sequence:t}}function nt(){return{kind:`wait`,seconds:5}}var G=`mt-1 w-full rounded border border-border bg-background px-2 py-1 text-xs`,K=`block text-[11px] font-medium text-foreground`;function rt({value:e,onChange:t,devices:n}){let r=$e(e),i=(n,r)=>t({...e,sequences:e.sequences.map((e,t)=>t===n?r:e)}),a=(n,r)=>t({...e,buttons:e.buttons.map((e,t)=>t===n?r:e)});return x(`div`,{className:`space-y-4`,children:[r.length>0&&k(`div`,{className:`space-y-1 rounded-md border border-warning/40 bg-warning/10 px-3 py-2 text-[11px] text-warning`,children:r.map(e=>k(`p`,{children:e.message},e.message))}),x(`section`,{className:`space-y-2`,children:[x(`div`,{className:`flex items-center justify-between`,children:[x(`div`,{children:[k(`h4`,{className:`text-xs font-semibold text-foreground`,children:`What this rule does`}),k(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Runs when the rule matches. A sequence stops at the first failed step, and its own delay limits how often it may physically run — separate from the notification cooldown.`})]}),x(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>t({...e,sequences:[...e.sequences,et(e.sequences.length)]}),children:[k(L,{className:`h-3.5 w-3.5`}),` Sequence`]})]}),e.sequences.length===0?k(`p`,{className:`rounded border border-border px-3 py-2 text-[11px] text-foreground-subtle`,children:`This rule actuates nothing — it only notifies.`}):e.sequences.map((r,a)=>k(it,{sequence:r,devices:n,onChange:e=>i(a,e),onRemove:()=>t({...e,sequences:e.sequences.filter((e,t)=>t!==a)})},`seq-${String(a)}`))]}),x(`section`,{className:`space-y-2`,children:[x(`div`,{className:`flex items-center justify-between`,children:[x(`div`,{children:[k(`h4`,{className:`text-xs font-semibold text-foreground`,children:`Buttons on the notification`}),k(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Each button runs one of the sequences above when tapped.`})]}),x(f,{size:`sm`,variant:`ghost`,type:`button`,disabled:e.sequences.length===0,onClick:()=>t({...e,buttons:[...e.buttons,tt(e.buttons.length,e.sequences[0]?.name??``)]}),children:[k(L,{className:`h-3.5 w-3.5`}),` Button`]})]}),e.buttons.length>0&&x(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/40 bg-warning/10 px-3 py-2 text-[11px] text-warning`,children:[k(pe,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),x(`span`,{children:[`A button's link travels inside the notification — through ntfy, a push relay, anyone it is forwarded to. The link is the only authority: it does not check who taps it. Anyone holding the notification can run the button `,k(`strong`,{children:`once`}),`, within 15 minutes. Do not add one for something you would not want a forwarded screenshot to do.`]})]}),e.sequences.length===0?k(`p`,{className:`rounded border border-border px-3 py-2 text-[11px] text-foreground-subtle`,children:`Add a sequence first — a button runs one, it does not define its own steps.`}):e.buttons.length===0?k(`p`,{className:`rounded border border-border px-3 py-2 text-[11px] text-foreground-subtle`,children:`No buttons. The notification arrives with nothing to tap.`}):e.buttons.map((n,r)=>k(st,{button:n,sequenceNames:e.sequences.map(e=>e.name),onChange:e=>a(r,e),onRemove:()=>t({...e,buttons:e.buttons.filter((e,t)=>t!==r)})},`btn-${String(r)}`))]})]})}function it({sequence:t,devices:n,onChange:r,onRemove:i}){let a=(e,n)=>r({...t,actions:t.actions.map((t,r)=>r===e?n:t)});return x(`div`,{className:`space-y-2 rounded-md border border-border p-3`,children:[x(`div`,{className:`flex flex-wrap items-end gap-2`,children:[x(`div`,{className:`min-w-0 flex-1`,children:[k(`label`,{className:K,children:`Name`}),k(h,{className:`mt-1`,value:t.name,onChange:e=>r({...t,name:e.target.value})})]}),x(`div`,{className:`w-28`,children:[k(`label`,{className:K,children:`Min delay (s)`}),k(`input`,{type:`number`,min:0,className:G,value:t.minDelaySec??``,onChange:e=>{let n=e.target.value,i={...t};n===``?delete i.minDelaySec:i.minDelaySec=Number(n),r(i)}})]}),x(`div`,{className:`flex items-center gap-2 pb-1`,children:[k(e,{checked:t.enabled,onCheckedChange:e=>r({...t,enabled:e})}),k(`span`,{className:`text-[11px] text-foreground-subtle`,children:t.enabled?`Runs on match`:`Only when a button is tapped`})]}),k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:i,title:`Remove`,children:k(B,{className:`h-3.5 w-3.5`})})]}),x(`div`,{className:`space-y-2 border-l-2 border-border-subtle pl-3`,children:[t.actions.map((e,i)=>k(at,{step:e,devices:n,onChange:e=>a(i,e),onRemove:()=>r({...t,actions:t.actions.filter((e,t)=>t!==i)})},`step-${String(i)}`)),x(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>r({...t,actions:[...t.actions,nt()]}),children:[k(L,{className:`h-3.5 w-3.5`}),` Step`]})]})]})}function at({step:e,devices:t,onChange:n,onRemove:r}){return x(`div`,{className:`flex flex-wrap items-end gap-2`,children:[x(`div`,{className:`w-24`,children:[k(`label`,{className:K,children:`Step`}),x(`select`,{className:G,value:e.kind,onChange:e=>n(e.target.value===`wait`?{kind:`wait`,seconds:5}:{kind:`cap`,deviceId:t[0]?.id??0,cap:``,method:``}),children:[k(`option`,{value:`cap`,children:`Do`}),k(`option`,{value:`wait`,children:`Wait`})]})]}),e.kind===`wait`?x(`div`,{className:`w-28`,children:[k(`label`,{className:K,children:`Seconds`}),k(`input`,{type:`number`,min:0,max:300,className:G,value:e.seconds,onChange:e=>n({kind:`wait`,seconds:Number(e.target.value)})})]}):k(ot,{step:e,devices:t,onChange:n}),k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:r,title:`Remove step`,children:k(B,{className:`h-3.5 w-3.5`})})]})}function ot({step:e,devices:t,onChange:n}){let r=F(),i=C({queryKey:[`deviceManager`,`getBindings`,e.deviceId],enabled:e.deviceId>0,staleTime:6e4,queryFn:async()=>{let t=await r.trpcClient.deviceManager.getBindings.query({deviceId:e.deviceId});return[...new Set(t.entries.map(e=>e.capName))].sort((e,t)=>e.localeCompare(t))}}).data??[];return x(w,{children:[x(`div`,{className:`min-w-[9rem] flex-1`,children:[k(`label`,{className:K,children:`Device`}),x(`select`,{className:G,value:String(e.deviceId),onChange:t=>n({...e,deviceId:Number(t.target.value),cap:``}),children:[k(`option`,{value:`0`,children:`Select…`}),t.map(e=>k(`option`,{value:String(e.id),children:e.name},e.id))]})]}),x(`div`,{className:`min-w-[8rem] flex-1`,children:[k(`label`,{className:K,children:`Capability`}),x(`select`,{className:G,value:e.cap,disabled:i.length===0,onChange:t=>n({...e,cap:t.target.value,method:``}),children:[k(`option`,{value:``,children:i.length===0?`No devices bound`:`Select…`}),i.map(e=>k(`option`,{value:e,children:e},e))]})]}),x(`div`,{className:`min-w-[7rem] flex-1`,children:[k(`label`,{className:K,children:`Method`}),k(h,{className:`mt-1`,value:e.method,placeholder:`arm`,onChange:t=>n({...e,method:t.target.value})})]}),x(`div`,{className:`min-w-[8rem] flex-1`,children:[k(`label`,{className:K,children:`Arguments (JSON)`}),k(h,{className:`mt-1`,value:e.args===void 0?``:JSON.stringify(e.args),placeholder:`{"mode":"away"}`,onChange:t=>{let r=t.target.value.trim();if(r===``){let t={...e};delete t.args,n(t);return}try{let t=JSON.parse(r);typeof t==`object`&&t&&!Array.isArray(t)&&n({...e,args:t})}catch{}}})]})]})}function st({button:t,sequenceNames:n,onChange:r,onRemove:i}){return x(`div`,{className:`flex flex-wrap items-end gap-2 rounded-md border border-border p-3`,children:[x(`div`,{className:`min-w-[7rem] flex-1`,children:[k(`label`,{className:K,children:`Label`}),k(h,{className:`mt-1`,value:t.label,onChange:e=>r({...t,label:e.target.value})})]}),x(`div`,{className:`min-w-[8rem] flex-1`,children:[k(`label`,{className:K,children:`Runs`}),x(`select`,{className:G,value:t.sequence,onChange:e=>r({...t,sequence:e.target.value}),children:[!n.includes(t.sequence)&&x(`option`,{value:t.sequence,children:[t.sequence,` (missing)`]}),n.map(e=>k(`option`,{value:e,children:e},e))]})]}),x(`div`,{className:`w-32`,children:[k(`label`,{className:K,children:`Icon`}),x(`select`,{className:G,value:t.icon??``,onChange:e=>{let n={...t};if(e.target.value===``)delete n.icon;else{let t=Ye.find(t=>t.value===e.target.value);t!==void 0&&(n.icon=t.value)}r(n)},children:[k(`option`,{value:``,children:`None`}),Ye.map(e=>k(`option`,{value:e.value,children:e.label},e.value))]})]}),x(`div`,{className:`flex items-center gap-2 pb-1`,children:[k(e,{checked:t.destructive===!0,onCheckedChange:e=>{let n={...t};e?n.destructive=!0:delete n.destructive,r(n)}}),k(p,{variant:t.destructive===!0?`danger`:`default`,children:`Destructive style`})]}),k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:i,title:`Remove`,children:k(B,{className:`h-3.5 w-3.5`})})]})}var ct={search:``,types:[],selectedOnly:!1};function lt(e){let t=new Map;for(let n of e)t.set(n.type,(t.get(n.type)??0)+1);return[...t.entries()].map(([e,t])=>({type:e,count:t})).sort((e,t)=>t.count-e.count||e.type.localeCompare(t.type))}function ut(e,t,n){let r=new Set(n),i=t.search.trim().toLowerCase(),a=new Set(t.types);return e.filter(e=>r.has(e.id)?!0:!(t.selectedOnly||a.size>0&&!a.has(e.type)||i!==``&&!e.name.toLowerCase().includes(i)))}function dt(e){let t=new Map,n=[];for(let r of e){if(r.location===null||r.location===``){n.push(r);continue}let e=t.get(r.location)??[];e.push(r),t.set(r.location,e)}let r=[...t.entries()].sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({location:e,devices:[...t].sort((e,t)=>e.name.localeCompare(t.name))}));return n.length>0&&r.push({location:null,devices:[...n].sort((e,t)=>e.name.localeCompare(t.name))}),r}function ft(e,t){let n=new Set(t);for(let t of e)n.add(t.id);return[...n]}function pt(e,t){let n=new Set(e.map(e=>e.id));return t.filter(e=>!n.has(e))}function mt(e,t){return e.length===0?`Every device (${String(t)}) — no restriction`:`${String(e.length)} of ${String(t)} selected`}b();function ht({devices:e,value:t,onChange:n,loading:r=!1}){let[i,a]=D(ct),o=S(()=>lt(e),[e]),s=S(()=>ut(e,i,t),[e,i,t]),c=S(()=>dt(s),[s]),l=e=>a(t=>({...t,types:t.types.includes(e)?t.types.filter(t=>t!==e):[...t.types,e]})),u=e=>n(t.includes(e)?t.filter(t=>t!==e):[...t,e]);return r?k(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Loading devices…`}):x(`div`,{className:`space-y-3`,children:[x(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[k(`p`,{className:`text-[11px] text-foreground-subtle`,children:mt(t,e.length)}),x(`div`,{className:`flex items-center gap-1`,children:[k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>n(ft(s,t)),children:`Select shown`}),k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>n(pt(s,t)),children:`Clear shown`})]})]}),x(`div`,{className:`flex flex-wrap items-center gap-2`,children:[k(h,{className:`min-w-[10rem] flex-1`,value:i.search,placeholder:`Search by name…`,leftSlot:k(oe,{className:`h-3.5 w-3.5 text-foreground-subtle`}),onChange:e=>a(t=>({...t,search:e.target.value}))}),x(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[k(`input`,{type:`checkbox`,checked:i.selectedOnly,onChange:e=>a(t=>({...t,selectedOnly:e.target.checked}))}),`Selected only`]})]}),k(`div`,{className:`flex flex-wrap gap-1`,children:o.map(e=>x(`button`,{type:`button`,onClick:()=>l(e.type),className:i.types.includes(e.type)?`rounded-full border border-primary bg-primary/10 px-2 py-0.5 text-[10px] text-foreground`:`rounded-full border border-border px-2 py-0.5 text-[10px] text-foreground-muted hover:bg-surface-hover`,children:[e.type,` `,k(`span`,{className:`text-foreground-subtle`,children:e.count})]},e.type))}),s.length===0?k(`p`,{className:`rounded border border-border px-3 py-2 text-[11px] text-foreground-subtle`,children:`No device matches this filter.`}):k(`div`,{className:`max-h-72 space-y-2 overflow-y-auto`,children:c.map(e=>x(`div`,{children:[k(`p`,{className:`px-1 pb-1 text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e.location??`No location`}),k(`div`,{className:`divide-y divide-border rounded-md border border-border`,children:e.devices.map(e=>x(`label`,{className:`flex cursor-pointer items-center gap-2.5 px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover`,children:[k(`input`,{type:`checkbox`,checked:t.includes(e.id),onChange:()=>u(e.id),className:`accent-primary`}),k(`span`,{className:`flex-1 truncate`,children:e.name}),k(p,{variant:`default`,children:e.type})]},e.id))})]},e.location??`__unplaced`))})]})}function q(e){return t=>Object.prototype.hasOwnProperty.call(e,t)}var gt=q({devices:!0}),_t=q({classes:!0,classesExclude:!0,labelEquals:!0,identities:!0,identitiesExclude:!0,eventTypeTokens:!0,sensorKinds:!0}),vt=q({zonesExclude:!0}),yt=q({minConfidence:!0,minImportance:!0,minLabelConfidence:!0}),bt=q({minDwellSeconds:!0}),xt=q({source:!0}),St=q({crossing:!0}),Ct=q({packagePhase:!0}),wt=q({zones:!0}),Tt=q({plates:!0}),Et=q({occupancy:!0}),Dt=q({systemEvent:!0}),Ot=q({deviceState:!0});function kt(e,t){let n=e[t];return Array.isArray(n)?n:[]}function At(e,t){let n=e[t];return typeof n==`number`?n:void 0}var jt=[{id:`system`,label:`System events`},{id:`scope`,label:`Scope`},{id:`class`,label:`Classes`},{id:`zones`,label:`Zones`},{id:`quality`,label:`Quality`},{id:`label`,label:`Identity & plates`},{id:`device`,label:`Device event`},{id:`package`,label:`Package`},{id:`occupancy`,label:`Occupancy`},{id:`schedule`,label:`Schedule`}];function Mt(e){let t=e.replace(/[-_]/g,` `);return t.charAt(0).toUpperCase()+t.slice(1)}function Nt(e,t){let n=e.filter(t),r=new Set(jt.map(e=>e.id)),i=[];for(let e of jt){let t=n.filter(t=>t.group===e.id);t.length>0&&i.push({id:e.id,label:e.label,descriptors:t})}let a=[];for(let e of n)r.has(e.group)||a.includes(e.group)||a.push(e.group);for(let e of a)i.push({id:e,label:Mt(e),descriptors:n.filter(t=>t.group===e)});return i}b();function Pt(e,t){let n=F().trpcClient,r=T({queries:e.map(e=>({queryKey:[[`nc-pickers`,`zones`],{deviceId:e}],staleTime:3e4,queryFn:async()=>({deviceId:e,zones:(await n.zones.listZones.query({deviceId:e})).map(e=>({id:e.id,name:e.name}))})}))});return S(()=>{let e=[],n=new Set;for(let i of r){if(!i.data)continue;let r=t.find(e=>e.id===i.data.deviceId)?.name;for(let t of i.data.zones)n.has(t.id)||(n.add(t.id),e.push({value:t.id,label:t.name,...r===void 0?{}:{hint:r}}))}return{options:e,loading:r.some(e=>e.isLoading)}},[r,t])}function Ft(e){let t=F().trpcClient,n=T({queries:e.map(e=>({queryKey:[[`nc-pickers`,`event-kinds`],{deviceId:e}],staleTime:6e4,queryFn:async()=>(await t.pipelineAnalytics.listEventKinds.query({deviceId:e})).map(e=>({kind:e.kind,label:e.label}))}))});return S(()=>{let e=new Map;for(let t of n)for(let n of t.data??[])e.has(n.kind)||e.set(n.kind,n.label);let t=[...e.entries()].map(([e,t])=>({value:e,label:t}));return t.sort((e,t)=>e.label.localeCompare(t.label)),{options:t,loading:n.some(e=>e.isLoading)}},[n])}function It(){let e=o();return S(()=>({options:(e.data??[]).map(e=>({value:e.name,label:e.name})),loading:e.isLoading}),[e.data,e.isLoading])}function Lt(){let e=d({limit:200});return S(()=>{let t=new Set;for(let n of e.data??[])n.text.trim().length>0&&t.add(n.text);return[...t].sort()},[e.data])}function J({options:e,value:t,onChange:n,loading:r,emptyHint:i,placeholder:a,noFreeText:o=!1}){let[s,c]=D(``),l=S(()=>new Set(e.map(e=>e.value)),[e]),u=S(()=>new Set(t),[t]),d=t.filter(e=>!l.has(e)),f=e=>{n(u.has(e)?t.filter(t=>t!==e):[...t,e])},p=()=>{let e=s.trim();e.length===0||t.includes(e)||(n([...t,e]),c(``))};return x(`div`,{className:`mt-1 space-y-1.5`,children:[d.length>0&&k(`div`,{className:`flex flex-wrap gap-1`,children:d.map(e=>x(`button`,{type:`button`,onClick:()=>n(t.filter(t=>t!==e)),className:`inline-flex items-center gap-1 rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground hover:bg-surface-hover`,title:`Custom value — click to remove`,children:[e,` ×`]},e))}),e.length>0?k(`div`,{className:`max-h-40 overflow-y-auto rounded-md border border-border divide-y divide-border`,children:e.map(e=>x(`label`,{className:`flex items-center gap-2.5 px-3 py-1.5 text-xs text-foreground cursor-pointer hover:bg-surface-hover`,children:[k(`input`,{type:`checkbox`,checked:u.has(e.value),onChange:()=>f(e.value),className:`accent-primary`}),k(`span`,{className:`flex-1 truncate`,children:e.label}),e.hint!==void 0&&k(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.hint})]},e.value))}):k(`p`,{className:`text-[10px] text-foreground-subtle`,children:r===!0?`Loading…`:i}),!o&&k(`input`,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),p())},placeholder:a,className:`w-full rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground placeholder:text-foreground-subtle`})]})}var Rt=[{value:`immediate`,label:`Immediate`,hint:`Fires on the first matching detection of a track (lowest latency).`},{value:`track-end`,label:`Track end`,hint:`Evaluates the finalised track record when it closes.`},{value:`device-event`,label:`Device event`,hint:`Doorbell press / sensor state change on a linked device.`},{value:`package-event`,label:`Package event`,hint:`A parcel delivery or pick-up.`},{value:`system-event`,label:`System event`,hint:`The installation itself: a camera or stream going offline, a node leaving the cluster, an addon or server update becoming available.`}];function zt(e){return Rt.find(t=>t.value===e)?.label??e}function Bt(e){return Rt.find(t=>t.value===e)?.value}function Vt(e){return Rt.some(t=>t.value===e)}function Y(e){return e===`system-event`}var Ht=[{key:`all`,label:`All rules`,blurb:`Every notification rule, whatever its trigger. Each rule picks a trigger, matches conditions and fans out to one or more delivery targets.`},{key:`detection`,label:`Detections & devices`,blurb:`Rules driven by what the cameras and sensors SEE — detections, tracks, doorbell presses and package events.`},{key:`system`,label:`System events`,blurb:`Rules about the installation itself: a camera or stream dropping, a node leaving the cluster, an addon or server update becoming available. These carry no image and are not tied to a detection.`}];function Ut(e){return Ht.find(t=>t.key===e)?.key}function Wt(e,t){return t===`all`?!0:t===`system`?Y(e):!Y(e)}function Gt(e){return e===`system`?`system-event`:`immediate`}var Kt=[{value:0,label:`No cooldown`},{value:30,label:`30 seconds`},{value:60,label:`1 minute`},{value:300,label:`5 minutes`},{value:600,label:`10 minutes`},{value:1800,label:`30 minutes`},{value:3600,label:`1 hour`}];function qt(e){let t=Kt.find(t=>t.value===e);return t?t.label:e%3600==0?`${e/3600} hours`:e%60==0?`${e/60} minutes`:`${e} seconds`}function Jt(e){return Kt.some(t=>t.value===e)?Kt:[...Kt,{value:e,label:qt(e)}].toSorted((e,t)=>e.value-t.value)}function Yt(e){if(e.trim().length===0)return;let t=Number(e);return Number.isFinite(t)&&t>=0?t:void 0}var Xt=[{value:`best`,label:`Best available image`,description:`The best subject crop available when the notification is sent.`},{value:`best-matching`,label:`Best matching image`,description:`The image that explains why the rule fired — the face crop for an identity rule, the plate crop for a plate rule; falls back to the best image otherwise.`},{value:`keyFrame`,label:`Key frame`,description:`The clean full scene frame with no subject box.`},{value:`none`,label:`No attachment`,description:`Send the notification with no image.`}];function Zt(e){return Xt.find(t=>t.value===e)?.value}var Qt=[{value:``,label:`Automatic`},{value:`cropped`,label:`Cropped on the subject`},{value:`full`,label:`Full frame`},{value:`boxed`,label:`Full frame with boxes`}];function $t(e){let t=Qt.find(t=>t.value===e)?.value;return t===``?void 0:t}var en=[{value:``,label:`Lowest available`},{value:`low`,label:`Low`},{value:`mid`,label:`Medium`},{value:`high`,label:`High`}];function tn(e){let t=en.find(t=>t.value===e)?.value;return t===``?void 0:t}var nn=[{value:`any`,label:`Any source`},{value:`pipeline`,label:`Pipeline`},{value:`onboard`,label:`Onboard (camera)`},{value:`sensor`,label:`Sensor`}],rn=[{value:`delivered`,label:`Delivered`},{value:`picked-up`,label:`Picked up`},{value:`both`,label:`Both`}],an=[{value:``,label:`Not set — entering`,hint:`Entries, and every detection that is not a crossing at all. Exits are excluded. This is what a rule without a crossing condition already does, and choosing it writes nothing to the rule.`},{value:`enter`,label:`Entered a zone`,hint:`The same matches as "not set", stated explicitly: entries and non-crossing detections pass, exits do not.`},{value:`exit`,label:`Left a zone`,hint:`ONLY an exit crossing. A detection that is not a crossing fails, so this rule cannot fire on ordinary movement — pair it with the zones the subject must have left.`},{value:`any`,label:`Entered or left`,hint:`No direction filter: entries, exits and non-crossing detections alike. This is the only choice that adds exits to what the rule already matched.`}];function on(e){let t=an.find(t=>t.value===e)?.value;return t===``||t===void 0?void 0:t}var sn=[{value:`any`,label:`Any of`},{value:`all`,label:`All of`}],cn=[{value:1,label:`1 — Min`},{value:2,label:`2 — Low`},{value:3,label:`3 — Default`},{value:4,label:`4 — High`},{value:5,label:`5 — Max`}];function ln(e=`immediate`){return{name:``,enabled:!0,delivery:e,targetIds:[],targetUsers:[],targetParams:{},priority:3,mediaAttach:`best`,mediaZoneCrop:!1,mediaFrame:void 0,mediaGif:!1,mediaClip:!1,mediaProfile:void 0,mediaClipSpeed:void 0,templateTitle:``,templateBody:``,conditions:{},schedule:void 0,snoozeAllowGlobal:!1,actions:Xe,deviceIds:[],cooldownSec:60}}function un(e){let t={};for(let n of e.targets)n.params&&Object.keys(n.params).length>0&&(t[n.targetId]=n.params);return{name:e.name,enabled:e.enabled,delivery:e.delivery,targetIds:e.targets.map(e=>e.targetId),targetUsers:e.targetUsers??[],targetParams:t,priority:e.priority,mediaAttach:e.media.attach,mediaZoneCrop:e.media.zoneCrop===!0,mediaFrame:e.media.frame,mediaGif:e.media.gif===!0,mediaClip:e.media.clip===!0,mediaProfile:e.media.profile,mediaClipSpeed:e.media.clipSpeed,templateTitle:e.template?.title??``,templateBody:e.template?.body??``,conditions:e.conditions,schedule:e.schedule,snoozeAllowGlobal:e.snoozeAllowGlobal===!0,actions:Ze(e.actions),deviceIds:e.conditions.devices??[],cooldownSec:e.throttle.cooldownSec}}function dn(e){return Vt(e.delivery)&&(!Y(e.delivery)||fn(e)>0)&&e.name.trim().length>0&&(e.targetIds.length>0||e.targetUsers.length>0)&&$e(e.actions).length===0}function fn(e){return e.conditions.systemEvent?.kinds.length??0}function pn(e,t){return e.appliesTo.includes(t)}var mn={source:`any`};function hn(e,t){if(t==null)return!0;if(Array.isArray(t))return t.length===0;if(typeof t==`string`)return t.length===0||mn[e]===t;if(typeof t==`number`)return!Number.isFinite(t);if(typeof t==`object`){if(`ids`in t){let e=t.ids;return!Array.isArray(e)||e.length===0}if(`values`in t){let e=t.values;return!Array.isArray(e)||e.length===0}return!1}return!1}function gn(e,t,n){let r=n.length===0?null:new Set(n.filter(e=>e.id!==`schedule`&&pn(e,t)).map(e=>e.id)),i={};for(let[t,n]of Object.entries(e))r!==null&&!r.has(t)||hn(t,n)||(i[t]=n);return i}function _n(e){return e!==void 0&&e.windows.length>0}function vn(e,t,n=[]){let r=e.templateTitle.trim(),i=e.templateBody.trim(),a=r.length>0||i.length>0?{...r.length>0?{title:r}:{},...i.length>0?{body:i}:{}}:void 0,o=Qe(e.actions),s=(n.length===0||n.some(t=>t.id===`schedule`&&pn(t,e.delivery)))&&_n(e.schedule)?e.schedule:void 0,c=n.length===0?!0:n.some(t=>t.id===`devices`&&pn(t,e.delivery));return{name:e.name.trim(),enabled:e.enabled,delivery:e.delivery,conditions:{...gn(e.conditions,e.delivery,n),...c&&e.deviceIds.length>0?{devices:[...e.deviceIds]}:{}},...s?{schedule:s}:{},targets:e.targetIds.map(t=>{let n=e.targetParams[t];return n&&Object.keys(n).length>0?{targetId:t,params:n}:{targetId:t}}),...e.targetUsers.length>0?{targetUsers:[...e.targetUsers]}:{},media:Y(e.delivery)?{attach:`none`}:{attach:e.mediaAttach,...e.mediaZoneCrop?{zoneCrop:!0}:{},...e.mediaFrame===void 0?{}:{frame:e.mediaFrame},...e.mediaGif?{gif:!0}:{},...e.mediaClip?{clip:!0}:{},...e.mediaProfile===void 0?{}:{profile:e.mediaProfile},...e.mediaClipSpeed===void 0?{}:{clipSpeed:e.mediaClipSpeed}},throttle:{cooldownSec:e.cooldownSec,scope:t?.throttle.scope??`rule-device`},priority:e.priority,...a?{template:a}:{},...e.snoozeAllowGlobal?{snoozeAllowGlobal:!0}:{},...o===void 0?{}:{actions:o}}}function yn(e,t){return e.options&&e.options.length>0?e.options:t}var bn=[{value:``,label:`Default (2×)`},{value:`1`,label:`1× — real time`},{value:`2`,label:`2×`},{value:`3`,label:`3×`},{value:`4`,label:`4×`},{value:`6`,label:`6×`},{value:`8`,label:`8×`}];function xn(e){if(e===``)return;let t=Number(e);return Number.isFinite(t)&&t>=1&&t<=8?t:void 0}var Sn=[{key:`rule`,label:`Rule`,fields:[`name`,`enabled`,`delivery`,`targetIds`,`targetUsers`,`targetParams`]},{key:`devices`,label:`Devices`,fields:[`deviceIds`]},{key:`conditions`,label:`Conditions`,fields:[`conditions`,`schedule`]},{key:`notification`,label:`Notification`,fields:[`priority`,`mediaAttach`,`mediaFrame`,`mediaZoneCrop`,`mediaGif`,`mediaClip`,`mediaProfile`,`mediaClipSpeed`,`templateTitle`,`templateBody`]},{key:`actions`,label:`Actions`,fields:[`actions`]},{key:`advanced`,label:`Advanced`,fields:[`snoozeAllowGlobal`,`cooldownSec`]}];function Cn(e){return Y(e)?Sn.filter(e=>e.key!==`devices`).map(e=>e.key===`conditions`?{...e,label:`Events`}:e):Sn}var wn=`rule`;function Tn(e){return Sn.find(t=>t.key===e)?.key}b();var X=`block text-[11px] font-medium text-foreground`,Z=`text-[10px] text-foreground-subtle mt-0.5`;function En({cameras:e,value:t,onChange:n}){if(e.length===0)return k(`p`,{className:Z,children:`No cameras available — the rule applies to all devices.`});let r=e=>n(t.includes(e)?t.filter(t=>t!==e):[...t,e]);return k(`div`,{className:`mt-1 max-h-40 overflow-y-auto rounded-md border border-border divide-y divide-border`,children:e.map(e=>x(`label`,{className:`flex items-center gap-2.5 px-3 py-1.5 text-xs text-foreground cursor-pointer hover:bg-surface-hover`,children:[k(`input`,{type:`checkbox`,checked:t.includes(e.id),onChange:()=>r(e.id),className:`accent-primary`}),k(`span`,{className:`flex-1 truncate`,children:e.name})]},e.id))})}function Dn({value:e,placeholder:t,onChange:n}){let[r,i]=D(``),a=()=>{let t=r.trim();if(t.length===0||e.includes(t)){i(``);return}n([...e,t]),i(``)},o=t=>n(e.filter(e=>e!==t));return x(`div`,{className:`mt-1 space-y-1.5`,children:[e.length>0&&k(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>x(`span`,{className:`inline-flex items-center gap-1 rounded bg-surface-hover px-1.5 py-0.5 text-[11px] text-foreground`,children:[e,k(`button`,{type:`button`,onClick:()=>o(e),"aria-label":`remove ${e}`,className:`text-foreground-subtle hover:text-danger`,children:k(fe,{className:`h-3 w-3`})})]},e))}),k(h,{value:r,placeholder:t,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),a())},onBlur:a})]})}function On({picker:e,value:t,onChange:n}){let r=S(()=>P(e),[e]),i=S(()=>new Set(t),[t]),a=t.filter(e=>!r.has(e)),o=e=>{n(i.has(e)?t.filter(t=>t!==e):[...t,e])};return x(`div`,{className:`space-y-2`,children:[a.length>0&&k(`div`,{className:`flex flex-wrap gap-1`,children:a.map(e=>x(`button`,{type:`button`,onClick:()=>n(t.filter(t=>t!==e)),className:`inline-flex items-center gap-1 rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground hover:bg-surface-hover`,title:`Custom value — click to remove`,children:[e,` ×`]},e))}),e.groups.map(e=>x(`div`,{children:[k(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-muted mb-1`,children:e.fallbackLabel}),k(`div`,{className:`flex flex-wrap gap-1`,children:e.options.map(e=>{let t=i.has(e.value);return k(`button`,{type:`button`,"aria-pressed":t,onClick:()=>o(e.value),className:t?`rounded border border-primary bg-primary/15 px-1.5 py-0.5 text-[10px] text-foreground`:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground hover:bg-surface-hover`,children:e.label},e.value)})})]},e.key))]})}function Q({value:e,min:t,max:n,step:r,onChange:i}){return x(`div`,{className:`mt-1 flex items-center gap-2`,children:[k(h,{type:`number`,value:e??``,min:t,max:n,step:r,className:`max-w-[8rem]`,onChange:e=>{let t=e.target.value;if(t===``){i(void 0);return}let n=Number(t);i(Number.isFinite(n)?n:void 0)}}),e!==void 0&&n!==void 0&&k(`input`,{type:`range`,min:t,max:n,step:r,value:e,onChange:e=>i(Number(e.target.value)),className:`flex-1 accent-primary`,"aria-label":`value`})]})}function kn({value:e,onChange:t,options:n}){let r=e??``,i=n&&n.length>0?n:an,a=i.find(e=>e.value===r);return x(`div`,{className:`mt-1 space-y-1`,children:[k(v,{value:r,options:i.map(e=>({value:e.value,label:e.label})),onChange:e=>t(on(e.target.value))}),a!==void 0&&k(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:a.hint})]})}function An({deviceIds:e,cameras:t,value:n,onChange:r}){let i=n?.ids??[],a=n?.match??`any`,o=e=>r(e.length>0?{ids:e,match:a}:void 0),s=e=>r(i.length>0?{ids:i,match:e}:void 0);return x(`div`,{className:`mt-1 space-y-1.5`,children:[k(`div`,{className:`max-w-[10rem]`,children:k(v,{value:a,options:sn.map(e=>({value:e.value,label:e.label})),onChange:e=>s(e.target.value===`all`?`all`:`any`)})}),k(jn,{deviceIds:e,cameras:t,value:i,onChange:o})]})}function jn({deviceIds:e,cameras:t,value:n,onChange:r}){let{options:i,loading:a}=Pt(e,t);return k(J,{options:i,value:n,onChange:r,loading:a,noFreeText:!0,emptyHint:e.length===0?`Select cameras first — a rule can only use zones those cameras actually have.`:`The selected cameras have no zones. Draw one in the camera’s zone editor first.`,placeholder:``})}function Mn({value:e,onChange:t}){let{options:n,loading:r}=It();return k(J,{options:n,value:e,onChange:t,loading:r,emptyHint:`No identities in the face gallery yet — type a name.`,placeholder:`Identity name…`})}function Nn({deviceIds:e,value:t,onChange:n}){let{options:r,loading:i}=Ft(e);return k(J,{options:r,value:t,onChange:n,loading:i,emptyHint:e.length===0?`Select cameras above to pick their event kinds — or type a token.`:`No event kinds reported for the selected cameras — type a token.`,placeholder:`Event token…`})}var Pn=[{value:`became-occupied`,label:`Became occupied`},{value:`became-free`,label:`Became free`},{value:`>=`,label:`Count ≥`},{value:`<=`,label:`Count ≤`}],Fn={op:`became-occupied`,count:1,sustainSeconds:15};function In({deviceIds:e,cameras:t,classOptions:n,value:r,onChange:i}){let{options:a,loading:o}=Pt(e,t),s=r??Fn,c=e=>i({...s,...e}),l=s.op===`became-occupied`||s.op===`became-free`;return x(`div`,{className:`mt-1 space-y-1.5`,children:[x(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[k(`div`,{className:`min-w-[10rem]`,children:k(v,{value:s.zoneId??``,options:[{value:``,label:o?`Loading zones…`:`— whole frame —`},...a.map(e=>({value:e.value,label:e.label}))],onChange:e=>c({zoneId:e.target.value===``?void 0:e.target.value})})}),k(`div`,{className:`min-w-[9rem]`,children:k(v,{value:s.className??``,options:[{value:``,label:`— any class —`},...n.map(e=>({value:e.value,label:e.label}))],onChange:e=>c({className:e.target.value===``?void 0:e.target.value})})}),k(`div`,{className:`min-w-[9rem]`,children:k(v,{value:s.op,options:Pn.map(e=>({value:e.value,label:e.label})),onChange:e=>{let t=Pn.find(t=>t.value===e.target.value);t&&c({op:t.value})}})})]}),x(`div`,{className:`flex flex-wrap items-center gap-3 text-xs text-foreground-subtle`,children:[x(`label`,{className:`flex items-center gap-1`,children:[l?`Threshold`:`Count`,k(h,{type:`number`,min:0,className:`w-16`,value:String(s.count),onChange:e=>c({count:Math.max(0,Number(e.target.value)||0)})})]}),x(`label`,{className:`flex items-center gap-1`,children:[`Hold for`,k(h,{type:`number`,min:0,max:3600,className:`w-16`,value:String(s.sustainSeconds),onChange:e=>c({sustainSeconds:Math.min(3600,Math.max(0,Number(e.target.value)||0))})}),`s`]}),r===void 0?null:k(`button`,{type:`button`,onClick:()=>i(void 0),className:`underline hover:text-foreground`,children:`Clear`})]}),k(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Counts confirmed tracked objects from zone analytics. The change must hold for the sustain window before it fires; with no snapshot for the camera or zone the rule never fires.`})]})}function Ln({value:e,onChange:t}){let n=e?.values??[],r=e?.maxDistance??1,i=e=>t(e.length>0?{values:e,maxDistance:r}:void 0),a=e=>t(n.length>0?{values:n,maxDistance:e}:void 0),o=Lt().filter(e=>!n.includes(e));return x(`div`,{className:`mt-1 space-y-1.5`,children:[k(Dn,{value:n,placeholder:`Plate text…`,onChange:i}),o.length>0&&x(`div`,{className:`flex flex-wrap items-center gap-1`,children:[k(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Seen:`}),o.slice(0,12).map(e=>k(`button`,{type:`button`,onClick:()=>i([...n,e]),className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:e},e))]}),x(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Max distance`,k(h,{type:`number`,min:0,max:3,step:1,value:r,className:`max-w-[5rem]`,onChange:e=>{let t=Number(e.target.value);a(Number.isFinite(t)?Math.max(0,Math.min(3,t)):1)}})]})]})}function Rn({gateable:e,value:t,onChange:n}){let r=e.find(e=>e.id===t?.deviceId),i=new Set(t?.states??[]),a=e=>{let t=Number(e);if(!Number.isFinite(t)||t===0)return n(void 0);n({deviceId:t,states:[]})},o=e=>{if(t===void 0)return;let r=new Set(i);r.has(e)?r.delete(e):r.add(e),n(r.size===0?void 0:{deviceId:t.deviceId,states:[...r]})};return x(`div`,{className:`mt-1 space-y-2`,children:[k(v,{value:t===void 0?``:String(t.deviceId),options:[{value:``,label:`— no device gate —`},...e.map(e=>({value:String(e.id),label:e.name}))],onChange:e=>a(e.target.value)}),r!==void 0&&k(`div`,{className:`flex flex-wrap gap-1.5`,children:r.states.map(e=>k(`button`,{type:`button`,onClick:()=>o(e),className:i.has(e)?`rounded-md border border-primary bg-primary/10 px-2 py-0.5 text-[11px] text-primary`:`rounded-md border border-border px-2 py-0.5 text-[11px] text-foreground-subtle`,children:e},e))}),r!==void 0&&r.states.length===0&&k(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:`This device reports no state the gate can read, so it cannot arm a rule.`}),t!==void 0&&k(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:`The rule is silent while the device is in any other state — including when its state cannot be read at all.`})]})}var zn=[{value:1,label:`Mon`},{value:2,label:`Tue`},{value:3,label:`Wed`},{value:4,label:`Thu`},{value:5,label:`Fri`},{value:6,label:`Sat`},{value:0,label:`Sun`}];function Bn(e){let t=Math.floor(e/60),n=e%60;return`${String(t).padStart(2,`0`)}:${String(n).padStart(2,`0`)}`}function Vn(e){let[t,n]=e.split(`:`),r=Number(t)*60+Number(n);return Number.isFinite(r)?Math.max(0,Math.min(1439,r)):0}function Hn(){return{days:[1,2,3,4,5],startMinute:540,endMinute:1080}}function Un({value:e,onChange:t}){let n=e?.windows??[],r=e?.invert??!1,i=(n,r)=>{if(n.length===0){t(void 0);return}t({windows:n,...r?{invert:!0}:{},...e?.timezone?{timezone:e.timezone}:{}})},a=()=>i([...n,Hn()],r),o=e=>i(n.filter((t,n)=>n!==e),r),s=(e,t)=>i(n.map((n,r)=>r===e?t:n),r);return x(`div`,{className:`mt-1 space-y-2`,children:[n.length===0?k(`p`,{className:Z,children:`Always active — add a window to restrict when the rule fires.`}):n.map((e,t)=>k(Wn,{window:e,onChange:e=>s(t,e),onRemove:()=>o(t)},t)),x(`div`,{className:`flex items-center gap-3`,children:[x(`button`,{type:`button`,onClick:a,className:`flex items-center gap-1 rounded-md bg-surface-hover px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground`,children:[k(L,{className:`h-3 w-3`}),` Add window`]}),n.length>0&&x(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[k(`input`,{type:`checkbox`,checked:r,onChange:e=>i([...n],e.target.checked),className:`accent-primary`}),`Active outside the windows`]})]})]})}function Wn({window:e,onChange:t,onRemove:n}){let r=n=>{let r=e.days.includes(n)?e.days.filter(e=>e!==n):[...e.days,n];r.length!==0&&t({...e,days:r})};return x(`div`,{className:`space-y-1.5 rounded-md border border-border p-2`,children:[x(`div`,{className:`flex items-center gap-2 text-xs`,children:[k(`input`,{type:`time`,value:Bn(e.startMinute),onChange:n=>t({...e,startMinute:Vn(n.target.value)}),className:`rounded-md border border-border bg-background px-1 py-0.5`}),k(`span`,{className:`text-foreground-subtle`,children:`→`}),k(`input`,{type:`time`,value:Bn(e.endMinute),onChange:n=>t({...e,endMinute:Vn(n.target.value)}),className:`rounded-md border border-border bg-background px-1 py-0.5`}),k(`span`,{className:`flex-1`}),k(`button`,{type:`button`,onClick:n,"aria-label":`Remove window`,className:`text-foreground-subtle hover:text-danger`,children:k(B,{className:`h-3.5 w-3.5`})})]}),k(`div`,{className:`flex flex-wrap gap-1`,children:zn.map(t=>k(`button`,{type:`button`,onClick:()=>r(t.value),className:`rounded px-1.5 py-0.5 text-[10px] ${e.days.includes(t.value)?`bg-primary text-primary-foreground`:`bg-surface-hover text-foreground-subtle`}`,children:t.label},t.value))})]})}var Gn=[{id:`liveness`,label:`Cameras & streams`,hint:`A camera the hub can no longer reach, or a stream that stopped or came back.`,kinds:[{value:`camera-offline`,label:`Camera offline`},{value:`camera-online`,label:`Camera online`},{value:`stream-offline`,label:`Stream offline`},{value:`stream-online`,label:`Stream online`}]},{id:`nodes`,label:`Nodes`,hint:`An agent or worker node joining or leaving the cluster.`,kinds:[{value:`node-offline`,label:`Node offline`},{value:`node-online`,label:`Node online`}]},{id:`updates`,label:`Updates`,hint:`A newer version of an addon or of the server itself is available.`,kinds:[{value:`addon-update-available`,label:`Addon update available`},{value:`server-update-available`,label:`Server update available`}]}],Kn=Gn.flatMap(e=>e.kinds);function qn(e){return Kn.find(t=>t.value===e)?.label??e}function Jn(e){return{devices:e.some(e=>e.startsWith(`camera-`)||e.startsWith(`stream-`)),nodes:e.some(e=>e.startsWith(`node-`)||e===`addon-update-available`),packages:e.some(e=>e.endsWith(`update-available`))}}function Yn(e,t){let n=e?.kinds??[],r=n.includes(t)?n.filter(e=>e!==t):Kn.filter(e=>e.value===t||n.includes(e.value)).map(e=>e.value);if(r.length!==0)return Qn(e,r)}function Xn(e,t){let n=e?.kinds??[];if(n.length===0)return;let r=Zn(t,`deviceIds`,e?.deviceIds),i=Zn(t,`nodeIds`,e?.nodeIds),a=Zn(t,`packageNames`,e?.packageNames);return{kinds:[...n],...r===void 0?{}:{deviceIds:[...r]},...i===void 0?{}:{nodeIds:[...i]},...a===void 0?{}:{packageNames:[...a]}}}function Zn(e,t,n){let r=Object.prototype.hasOwnProperty.call(e,t)?e[t]:n;return r!==void 0&&r.length===0?void 0:r}function Qn(e,t){let n=Jn(t),r=n.devices?e?.deviceIds:void 0,i=n.nodes?e?.nodeIds:void 0,a=n.packages?e?.packageNames:void 0;return{kinds:[...t],...r&&r.length>0?{deviceIds:[...r]}:{},...i&&i.length>0?{nodeIds:[...i]}:{},...a&&a.length>0?{packageNames:[...a]}:{}}}function $n(e,t=2){if(e===void 0||e.length===0)return`No event selected`;let n=e.slice(0,t).map(qn).join(`, `),r=e.length-Math.min(t,e.length);return r>0?`${n} +${r}`:n}function er(e){if(e===void 0)return`—`;let t=[],n=e.deviceIds?.length??0,r=e.nodeIds?.length??0,i=e.packageNames?.length??0;return n>0&&t.push(`${n} camera${n===1?``:`s`}`),r>0&&t.push(`${r} node${r===1?``:`s`}`),i>0&&t.push(`${i} package${i===1?``:`s`}`),t.length===0?`Everything`:t.join(` · `)}j.options,b();var tr=[`nc-pickers`,`nodes`],nr=[`nc-pickers`,`addon-packages`];function rr(){let e=F().trpcClient,t=C({queryKey:tr,staleTime:6e4,queryFn:async()=>(await e.nodes.topology.query()).map(e=>({value:e.id,label:e.name.length>0?e.name:e.id,hint:e.isOnline?e.id:`${e.id} · offline`}))});return{options:t.data??[],loading:t.isLoading}}function ir(){let e=F().trpcClient,t=C({queryKey:nr,staleTime:6e4,queryFn:async()=>(await e.addons.listPackages.query()).map(e=>({value:e.name,label:e.name,hint:e.version})).toSorted((e,t)=>e.label.localeCompare(t.label))});return{options:t.data??[],loading:t.isLoading}}function ar({value:e,cameras:t,onChange:n}){let r=S(()=>e?.kinds??[],[e]),i=Jn(r),a=rr(),o=ir();return x(`div`,{className:`mt-1 space-y-3`,"data-testid":`system-event-field`,children:[Gn.map(t=>x(`div`,{children:[k(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:t.label}),k(`div`,{className:`mt-1 flex flex-wrap gap-1.5`,children:t.kinds.map(t=>{let i=r.includes(t.value);return k(`button`,{type:`button`,role:`checkbox`,"aria-checked":i,"aria-label":t.label,onClick:()=>n(Yn(e,t.value)),className:i?`rounded-md border border-primary bg-primary/10 px-2 py-1 text-[11px] text-primary`:`rounded-md border border-border px-2 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:t.label},t.value)})}),k(`p`,{className:Z,children:t.hint})]},t.id)),r.length===0&&k(`p`,{className:`rounded-md border border-warning/40 bg-warning/10 px-2.5 py-1.5 text-[11px] text-warning`,children:`Pick at least one event — a system rule with no event selected is never evaluated, and the hub refuses to save it.`}),i.devices&&x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground`,children:`Only these cameras (optional)`}),k(En,{cameras:t,value:e?.deviceIds??[],onChange:t=>n(Xn(e,{deviceIds:t}))}),k(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:`Leave everything unchecked to watch every camera.`})]}),i.nodes&&x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground`,children:`Only these nodes (optional)`}),k(J,{options:a.options,value:e?.nodeIds??[],onChange:t=>n(Xn(e,{nodeIds:t})),loading:a.loading,emptyHint:`No nodes reported — the rule watches every node.`,placeholder:`Node id…`}),k(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:`Leave everything unchecked to watch every node.`})]}),i.packages&&x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground`,children:`Only these packages (optional)`}),k(J,{options:o.options,value:e?.packageNames??[],onChange:t=>n(Xn(e,{packageNames:t})),loading:o.loading,emptyHint:`No installed packages listed — the rule watches every package.`,placeholder:`Package name…`}),k(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:`Leave everything unchecked to be told about every addon and server update.`})]})]})}b();function or({catalog:e,taxonomy:t,delivery:n,conditions:r,schedule:i,cameras:a,gateable:o,onConditionsChange:s,onScheduleChange:c}){let l=(e,t)=>{let n={...r};t===void 0?delete n[e]:n[e]=t,s(n)},u=S(()=>Nt(e,e=>e.id!==`devices`&&cr(e,n)),[e,n]),d=S(()=>Nt(e,e=>e.id!==`devices`&&!cr(e,n)),[e,n]),[f,m]=D(()=>{if(lr(r,i))return!0;try{return localStorage.getItem(sr)===`1`}catch{return!1}}),h=()=>{let e=!f;m(e);try{localStorage.setItem(sr,e?`1`:`0`)}catch{}},g=e=>e.map(e=>x(`div`,{className:`space-y-2.5`,children:[k(`div`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:e.label}),e.descriptors.map(e=>{let s=pn(e,n);return x(`div`,{className:s?``:`opacity-50`,"data-testid":`condition-${e.id}`,children:[x(`div`,{className:`flex items-center justify-between gap-2`,children:[k(`label`,{className:X,children:e.label}),!s&&x(p,{variant:`default`,children:[`not for `,e.appliesTo.join(` / `)]})]}),s?k(ur,{descriptor:e,taxonomy:t,conditions:r,schedule:i,cameras:a,gateable:o,onFieldChange:l,onScheduleChange:c}):k(`p`,{className:Z,children:`Not evaluated for the selected trigger — switch the trigger to use it.`}),s&&e.description&&k(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:e.description})]},e.id)})]},e.id));return x(`div`,{className:`space-y-4`,children:[g(u),d.length>0&&k(`button`,{type:`button`,onClick:h,"data-testid":`nc-advanced-toggle`,className:`w-full rounded-md border border-border px-3 py-1.5 text-left text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:f?`▾ Hide advanced configurations`:`▸ Show more configurations`}),f&&g(d)]})}var sr=`camstack.nc.showAdvanced`;function cr(e,t){return t===`system-event`?e.id===`systemEvent`:N(e.id)}function lr(e,t){for(let[t,n]of Object.entries(e))if(!N(t)&&t!==`systemEvent`&&n!==void 0&&!(Array.isArray(n)&&n.length===0))return!0;return t!==void 0&&t.windows.length>0}function ur({descriptor:e,taxonomy:t,conditions:n,schedule:r,cameras:i,gateable:a,onFieldChange:o,onScheduleChange:s}){switch(e.valueType){case`deviceIdList`:{if(!gt(e.id))break;let t=e.id;return k(En,{cameras:i,value:n[t]??[],onChange:e=>o(t,e.length>0?e:void 0)})}case`stringList`:{if(!_t(e.id))break;let r=e.id,i=e=>o(r,e.length>0?e:void 0);if(r===`identities`||r===`identitiesExclude`)return k(Mn,{value:kt(n,r),onChange:i});if(r===`eventTypeTokens`)return k(Nn,{deviceIds:n.devices??[],value:kt(n,r),onChange:i});let a=M(r,t);return a===null?k(Dn,{value:kt(n,r),placeholder:`Add value…`,onChange:i}):k(On,{picker:a,value:kt(n,r),onChange:i})}case`zoneIdList`:{if(!vt(e.id))break;let t=e.id;return k(jn,{deviceIds:n.devices??[],cameras:i,value:kt(n,t),onChange:e=>o(t,e.length>0?e:void 0)})}case`number01`:{if(!yt(e.id))break;let t=e.id;return k(Q,{value:At(n,t),min:0,max:1,step:.05,onChange:e=>o(t,e)})}case`number`:{if(!bt(e.id))break;let t=e.id;return k(Q,{value:At(n,t),min:0,step:1,onChange:e=>o(t,e)})}case`sourceSelect`:{if(!xt(e.id))break;let t=e.id;return k(v,{value:n[t]??`any`,options:yn(e,nn).map(e=>({value:e.value,label:e.label})),onChange:e=>o(t,pr(e.target.value))})}case`systemEvent`:{if(!Dt(e.id))break;let t=e.id;return k(ar,{value:n[t],cameras:i,onChange:e=>o(t,e)})}case`deviceState`:if(!Ot(e.id))break;return k(Rn,{gateable:a,value:n.deviceState,onChange:e=>o(`deviceState`,e)});case`crossingSelect`:{if(!St(e.id))break;let t=e.id;return k(kn,{value:n[t],onChange:e=>o(t,e),...e.options?{options:e.options}:{}})}case`packagePhase`:{if(!Ct(e.id))break;let t=e.id;return k(v,{value:n[t]??``,options:[{value:``,label:`— any phase —`},...yn(e,rn).map(e=>({value:e.value,label:e.label}))],onChange:e=>o(t,mr(e.target.value))})}case`zoneSelection`:{if(!wt(e.id))break;let t=e.id;return k(An,{deviceIds:n.devices??[],cameras:i,value:n[t],onChange:e=>o(t,e)})}case`plateMatcher`:{if(!Tt(e.id))break;let t=e.id;return k(Ln,{value:n[t],onChange:e=>o(t,e)})}case`occupancy`:{if(!Et(e.id))break;let r=e.id;return k(In,{deviceIds:n.devices??[],cameras:i,classOptions:dr(t),value:n[r],onChange:e=>o(r,e)})}case`schedule`:return k(Un,{value:r,onChange:s});default:break}return k(fr,{descriptor:e,conditions:n})}function dr(e){let t=M(`classes`,e);return t===null?[]:t.groups.flatMap(e=>e.options)}function fr({descriptor:e,conditions:t}){let n=Object.entries(t).find(([t])=>t===e.id);return x(`p`,{className:Z,children:[n!==void 0&&n[1]!==void 0?`Authored elsewhere and preserved — this admin editor cannot change it yet.`:`Not editable here yet — this condition has no admin editor.`,` `,x(`span`,{className:`text-foreground-muted`,children:[`(`,e.valueType,`)`]})]})}function pr(e){if(e===`pipeline`||e===`onboard`||e===`sensor`||e===`any`)return e}function mr(e){return rn.find(t=>t.value===e)?.value}b();var hr=[`notificationRules`,`listSnoozes`],gr=3e4;function _r(e,t){return Math.max(0,Math.ceil((e.expiresAt-t)/6e4))}function vr(e){if(e===0)return`ending`;if(e<60)return`${e}m left`;let t=Math.floor(e/60),n=e%60;return n===0?`${t}h left`:`${t}h ${n}m left`}function yr({rules:e}){let t=F(),n=E(),r=C({queryKey:hr,refetchInterval:gr,queryFn:async()=>(await t.trpcClient.notificationRules.listSnoozes.query({})).snoozes}),i=O({mutationFn:e=>t.trpcClient.notificationRules.cancelSnooze.mutate({snoozeId:e}),onSuccess:()=>n.invalidateQueries({queryKey:hr})}),a=S(()=>{let t=new Map;for(let n of e)t.set(n.id,n.name);return t},[e]),o=Date.now(),s=(r.data??[]).filter(e=>o>=e.startedAt&&o<e.expiresAt);return s.length===0?null:x(_,{className:`p-4`,children:[x(`div`,{className:`flex items-center gap-2 mb-3`,children:[k(he,{className:`h-4 w-4 text-foreground-subtle`}),k(`h3`,{className:`text-sm font-medium text-foreground`,children:`Silenced right now`})]}),k(`div`,{className:`space-y-2`,children:s.map(e=>x(`div`,{className:`flex items-center justify-between gap-3 rounded-md border border-border px-3 py-2`,children:[x(`div`,{className:`min-w-0`,children:[x(`div`,{className:`flex items-center gap-2`,children:[k(`span`,{className:`text-xs text-foreground truncate`,children:e.scope===`all`?`Everything`:e.scope===`device`?`Camera ${e.deviceId??`?`}`:a.get(e.ruleId??``)??`A rule`}),e.global&&k(p,{variant:`warning`,className:`text-[10px]`,children:`everyone`}),!e.summary&&k(p,{variant:`default`,className:`text-[10px]`,children:`no summary`})]}),x(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`set by `,e.userId,` · `,vr(_r(e,o))]})]}),k(f,{size:`sm`,variant:`outline`,disabled:i.isPending,onClick:()=>i.mutate(e.id),children:`End now`})]},e.id))})]})}b();var br=[`notificationRules`,`listRules`],xr=[`notificationOutput`,`listTargets`,`forRules`],Sr=[`notificationRules`,`getConditionCatalog`],Cr=[`deviceManager`,`listAll`,`forRules`],wr=[`deviceManager`,`listAll`,`forRuleActions`],Tr=[`deviceManager`,`gateableDevices`],Er=ne.options;function Dr({onSimulateRule:e}={}){let t=F(),[r,o]=D({mode:`closed`}),[s,c]=D(null),[l,u]=D(`all`),d=C({queryKey:br,queryFn:async()=>(await t.trpcClient.notificationRules.listRules.query({})).rules}),p=C({queryKey:xr,queryFn:()=>t.trpcClient.notificationOutput.listTargets.query({})}),h=C({queryKey:Sr,queryFn:()=>t.trpcClient.notificationRules.getConditionCatalog.query({})}),g=C({queryKey:Tr,queryFn:async()=>{let e=await t.trpcClient.deviceManager.listAll.query({}),n=[];for(let r of e){let e=te(await t.trpcClient.deviceManager.loadRuntimeState.query({deviceId:r.id}),Er);e.length>0&&n.push({id:r.id,name:r.name,states:e})}return n},staleTime:6e4}),v=C({queryKey:wr,queryFn:async()=>(await t.trpcClient.deviceManager.listAll.query({projection:`slim`})).map(e=>({id:e.id,name:e.name,type:String(e.type),location:e.location??null})).sort((e,t)=>e.name.localeCompare(t.name)),staleTime:6e4}),b=C({queryKey:Cr,queryFn:async()=>(await t.trpcClient.deviceManager.listAll.query({})).filter(e=>e.type===ee.Camera).map(e=>({id:e.id,name:e.name}))}),w=S(()=>{let e=new Map;for(let t of p.data??[])e.set(t.id,t.name);return e},[p.data]),T=O({mutationFn:e=>t.trpcClient.notificationRules.setRuleEnabled.mutate(e),onSuccess:()=>void d.refetch()}),E=O({mutationFn:e=>t.trpcClient.notificationRules.deleteRule.mutate({ruleId:e}),onSuccess:()=>{c(null),d.refetch()}}),A=d.data??[],j=S(()=>A.filter(e=>Wt(e.delivery,l)),[A,l]),M=S(()=>{let e=new Map;for(let t of Ht)e.set(t.key,A.filter(e=>Wt(e.delivery,t.key)).length);return e},[A]),N=Ht.find(e=>e.key===l)??Ht[0],P=l===`system`;return x(V,{icon:ge,title:`Notification Rules`,subtitle:N.blurb,actions:x(f,{size:`sm`,type:`button`,onClick:()=>o({mode:`form`,rule:null,delivery:Gt(l)}),children:[k(L,{className:`h-3.5 w-3.5`}),P?`New system rule`:`New rule`]}),children:[k(a,{value:l,onValueChange:e=>u(Ut(e)??l),children:k(n,{className:`mb-3`,children:Ht.map(e=>x(i,{value:e.key,children:[e.label,k(`span`,{className:`ml-1.5 text-[10px] text-foreground-subtle`,children:M.get(e.key)??0})]},e.key))})}),k(yr,{rules:A}),d.isLoading&&k(`div`,{className:`flex items-center justify-center py-16`,children:k(z,{className:`h-6 w-6 animate-spin text-primary`})}),d.isError&&!d.isLoading&&k(y,{title:`Failed to load rules`,message:d.error instanceof Error?d.error.message:`Unknown error`,onRetry:()=>void d.refetch()}),!d.isLoading&&!d.isError&&j.length===0&&k(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:P?`No system-event rules yet. Click "New system rule" to be told when a camera drops, a node leaves or an update lands.`:`No ${l===`all`?`notification`:`detection`} rules yet. Click "New rule" to author one.`}),j.length>0&&k(_,{children:k(m,{columns:P?kr({targetNameById:w,confirmDeleteId:s,deletePending:E.isPending,onToggle:(e,t)=>T.mutate({ruleId:e.id,enabled:t}),onEdit:e=>o({mode:`form`,rule:e}),onDuplicate:e=>o({mode:`form`,rule:{...e,id:``,name:`${e.name} (copy)`}}),onAskDelete:c,onConfirmDelete:e=>E.mutate(e.id)}):Or({targetNameById:w,confirmDeleteId:s,deletePending:E.isPending,onToggle:(e,t)=>T.mutate({ruleId:e.id,enabled:t}),onEdit:e=>o({mode:`form`,rule:e}),onDuplicate:e=>o({mode:`form`,rule:{...e,id:``,name:`${e.name} (copy)`}}),onAskDelete:c,onConfirmDelete:e=>E.mutate(e.id),...e?{onTest:e}:{}}),rows:j,rowKey:e=>e.id,minWidthPx:760,bordered:!1})}),r.mode===`form`&&k(Ar,{rule:r.rule,...r.delivery?{newRuleDelivery:r.delivery}:{},targets:p.data??[],actuatable:v.data??[],catalog:h.data?.catalog??[],taxonomy:h.data?.taxonomy,cameras:b.data??[],gateable:g.data??[],onCancel:()=>o({mode:`closed`}),onSaved:()=>{o({mode:`closed`}),d.refetch()}})]})}function Or(t){return[{key:`name`,header:`Rule`,render:e=>x(`span`,{className:`flex items-center gap-2`,children:[k(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),!e.enabled&&k(p,{variant:`warning`,children:`disabled`})]})},{key:`trigger`,header:`Trigger`,nowrap:!0,render:e=>x(`span`,{className:`flex items-center gap-1.5`,children:[k(`span`,{className:`text-[11px] text-foreground-subtle`,children:zt(e.delivery)}),!Vt(e.delivery)&&k(p,{variant:`warning`,children:`read-only`})]})},{key:`targets`,header:`Targets`,render:e=>{let n=e.targets[0],r=n?t.targetNameById.get(n.targetId)??n.targetId:null;return k(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.targets.length===1&&r?r:`${e.targets.length} target${e.targets.length===1?``:`s`}`})}},{key:`priority`,header:`Priority`,align:`center`,nowrap:!0,render:e=>k(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.priority})},{key:`enabled`,header:`On`,align:`center`,nowrap:!0,render:n=>k(e,{checked:n.enabled,onCheckedChange:e=>t.onToggle(n,e),"aria-label":`toggle ${n.name}`})},{key:`actions`,header:``,align:`right`,nowrap:!0,render:e=>x(`span`,{className:`flex items-center justify-end gap-1`,children:[t.onTest&&k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>t.onTest?.(e),title:`Test — simulate an event this rule should match`,"aria-label":`test ${e.name}`,children:k(_e,{className:`h-3.5 w-3.5`})}),k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>t.onEdit(e),title:`Edit`,children:k(ie,{className:`h-3.5 w-3.5`})}),k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>t.onDuplicate(e),title:`Duplicate`,children:k(re,{className:`h-3.5 w-3.5`})}),t.confirmDeleteId===e.id?x(w,{children:[x(f,{size:`sm`,variant:`danger`,type:`button`,disabled:t.deletePending,onClick:()=>t.onConfirmDelete(e),children:[t.deletePending&&k(z,{className:`h-3.5 w-3.5 animate-spin`}),`Confirm`]}),k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>t.onAskDelete(null),children:`Cancel`})]}):k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>t.onAskDelete(e.id),title:`Delete`,children:k(B,{className:`h-3.5 w-3.5 text-danger`})})]})}]}function kr(e){let t=Or(e),n=e=>t.filter(t=>t.key===e);return[...n(`name`),{key:`events`,header:`Events`,render:e=>k(`span`,{className:`text-[11px] text-foreground-subtle`,children:$n(e.conditions.systemEvent?.kinds)})},{key:`scope`,header:`Scope`,nowrap:!0,render:e=>k(`span`,{className:`text-[11px] text-foreground-subtle`,children:er(e.conditions.systemEvent)})},{key:`targets`,header:`Targets`,render:t=>{let n=t.targets[0],r=n?e.targetNameById.get(n.targetId)??n.targetId:null;return k(`span`,{className:`text-[11px] text-foreground-subtle`,children:t.targets.length===1&&r?r:`${t.targets.length} target${t.targets.length===1?``:`s`}`})}},{key:`cooldown`,header:`Cooldown`,nowrap:!0,render:e=>k(`span`,{className:`text-[11px] text-foreground-subtle`,children:qt(e.throttle.cooldownSec)})},...n(`enabled`),...n(`actions`)]}function Ar({rule:o,newRuleDelivery:s,targets:c,catalog:l,taxonomy:u,cameras:d,gateable:m,actuatable:_,onSaved:y,onCancel:b}){let S=F(),w=o!=null&&o.id.length>0,[T,E]=D(()=>o?un(o):ln(s)),[A,j]=D(null),[ee,te]=D(null),[M,N]=D(wn),P=e=>E(t=>({...t,...e})),ne=w&&o?{throttle:o.throttle}:void 0,I=O({mutationFn:async()=>{let e=vn(T,ne,l);w&&o?await S.trpcClient.notificationRules.updateRule.mutate({ruleId:o.id,patch:e}):await S.trpcClient.notificationRules.createRule.mutate({rule:e})},onSuccess:y,onError:e=>j(e instanceof Error?e.message:`Save failed`)}),re=O({mutationFn:async()=>{let e=vn(T,ne,l);return(await S.trpcClient.notificationRules.testRule.mutate({rule:e,lookbackMinutes:60})).results},onMutate:()=>te(null),onSuccess:e=>te(e),onError:e=>j(e instanceof Error?e.message:`Test failed`)}),ie=T.targetIds.map(e=>c.find(t=>t.id===e)?.name??e),L=e=>P({targetIds:T.targetIds.includes(e)?T.targetIds.filter(t=>t!==e):[...T.targetIds,e]}),ae=C({queryKey:[`userManagement`,`listUsers`],queryFn:()=>S.trpcClient.userManagement.listUsers.query()}).data,oe=e=>P({targetUsers:T.targetUsers.includes(e)?T.targetUsers.filter(t=>t!==e):[...T.targetUsers,e]}),se=Rt.find(e=>e.value===T.delivery)?.hint,R=Y(T.delivery),ce=Cn(T.delivery),le=ce.some(e=>e.key===M)?M:wn;return Vt(T.delivery)?k(g,{open:!0,onOpenChange:e=>!e&&b(),children:x(r,{width:`lg`,placement:`sheet-on-mobile`,children:[x(`div`,{className:`flex items-center justify-between mb-3`,children:[x(`h3`,{className:`text-sm font-semibold text-foreground flex items-center gap-2`,children:[k(ge,{className:`h-4 w-4 text-foreground-subtle`}),w?`Edit ${o?.name}`:`New notification rule`]}),k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:b,children:`Cancel`})]}),A&&k(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger mb-3`,children:A}),x(a,{value:le,onValueChange:e=>N(Tn(e)??M),children:[k(n,{className:`mb-3`,children:ce.map(e=>k(i,{value:e.key,children:e.label},e.key))}),x(t,{value:`rule`,className:`space-y-4`,children:[x(`div`,{className:`flex items-end gap-3`,children:[x(`div`,{className:`min-w-0 flex-1`,children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Name`}),k(h,{value:T.name,onChange:e=>P({name:e.target.value}),placeholder:`e.g. Front door package`})]}),x(`label`,{className:`flex items-center gap-2 pb-1.5 text-[11px] font-medium text-foreground`,children:[k(e,{checked:T.enabled,onCheckedChange:e=>P({enabled:e}),"aria-label":`enabled`}),`Enabled`]})]}),x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Trigger`}),k(v,{value:T.delivery,onChange:e=>{let t=Bt(e.target.value);t&&P({delivery:t})},options:Rt.map(e=>({value:e.value,label:e.label}))}),se&&k(`p`,{className:`text-[10px] text-foreground-subtle mt-1`,children:se})]}),x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Delivery targets`}),c.length===0?k(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No delivery targets configured. Add one under the Targets tab first.`}):k(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:c.map(e=>x(`label`,{className:`flex items-center gap-2.5 px-3 py-1.5 text-xs text-foreground cursor-pointer hover:bg-surface-hover`,children:[k(`input`,{type:`checkbox`,checked:T.targetIds.includes(e.id),onChange:()=>L(e.id),className:`accent-primary`}),k(`span`,{className:`flex-1 truncate`,children:e.name}),!e.enabled&&k(p,{variant:`warning`,children:`disabled`})]},e.id))})]}),x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Notify users`}),(ae??[]).length===0?k(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No users to notify.`}):k(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:(ae??[]).map(e=>x(`label`,{className:`flex items-center gap-2.5 px-3 py-1.5 text-xs text-foreground cursor-pointer hover:bg-surface-hover`,children:[k(`input`,{type:`checkbox`,checked:T.targetUsers.includes(e.id),onChange:()=>oe(e.id),className:`accent-primary`}),k(`span`,{className:`flex-1 truncate`,children:e.username}),e.isAdmin&&k(p,{variant:`info`,children:`admin`})]},e.id))}),k(`p`,{className:`text-[10px] text-foreground-subtle mt-1`,children:`Delivers to the targets each user owns, only for cameras that user can access.`})]})]}),k(t,{value:`devices`,className:`space-y-4`,children:k(ht,{devices:_,value:T.deviceIds,onChange:e=>P({deviceIds:e}),loading:_.length===0})}),k(t,{value:`actions`,className:`space-y-4`,children:k(rt,{value:T.actions,onChange:e=>P({actions:e}),devices:_})}),x(t,{value:`advanced`,className:`space-y-4`,children:[x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Cooldown`}),k(v,{value:String(T.cooldownSec),onChange:e=>{let t=Yt(e.target.value);t!==void 0&&P({cooldownSec:t})},options:Jt(T.cooldownSec).map(e=>({value:String(e.value),label:e.label}))}),k(`p`,{className:`text-[10px] text-foreground-subtle mt-1`,children:R?`A camera that flaps, or a node that reconnects every minute, would otherwise send one notification per flap. The cooldown is the shortest gap between two deliveries of this rule.`:`The shortest gap between two deliveries of this rule. Counted per device unless the rule was configured otherwise.`})]}),x(`div`,{children:[x(`label`,{className:`flex items-center gap-2 text-[11px] font-medium text-foreground`,children:[k(e,{checked:T.snoozeAllowGlobal,onCheckedChange:e=>P({snoozeAllowGlobal:e}),"aria-label":`allow global snooze`}),`Anyone may snooze this rule for everyone`]}),k(`p`,{className:`text-[10px] text-foreground-subtle mt-1`,children:`A snooze is personal by default — it silences only the person who set it. Turn this on for a rule where silencing the whole household is legitimate (the gardener is here all afternoon). Admins can always do it.`})]})]}),x(t,{value:`notification`,className:`space-y-4`,children:[x(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Priority`}),k(v,{value:String(T.priority),onChange:e=>P({priority:Number(e.target.value)}),options:cn.map(e=>({value:String(e.value),label:e.label}))})]}),R&&k(`div`,{className:`rounded-md border border-border px-3 py-2 text-[11px] text-foreground-subtle`,children:`A system event carries no image: there is no camera frame behind "a node went offline". This rule sends text only.`}),!R&&x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Media attachment`}),k(v,{value:T.mediaAttach,onChange:e=>{let t=Zt(e.target.value);t&&P({mediaAttach:t})},options:Xt.map(e=>({value:e.value,label:e.label}))}),k(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:Xt.find(e=>e.value===T.mediaAttach)?.description}),x(`div`,{className:`mt-2 space-y-1`,children:[x(`label`,{className:`flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[k(`input`,{type:`checkbox`,checked:T.mediaZoneCrop,onChange:e=>P({mediaZoneCrop:e.target.checked}),className:`accent-primary`}),`Crop the image to the rule's zone`]}),x(`label`,{className:`flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[k(`input`,{type:`checkbox`,checked:T.mediaGif,onChange:e=>P({mediaGif:e.target.checked}),className:`accent-primary`}),`Attach a GIF around the event`]}),x(`label`,{className:`flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[k(`input`,{type:`checkbox`,checked:T.mediaClip,onChange:e=>P({mediaClip:e.target.checked}),className:`accent-primary`}),`Attach an MP4 clip around the event`]})]}),(T.mediaGif||T.mediaClip)&&x(`div`,{className:`mt-2`,children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Video quality`}),k(v,{value:T.mediaProfile??``,onChange:e=>P({mediaProfile:tn(e.target.value)}),options:en.map(e=>({value:e.value,label:e.label}))}),k(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:`A notification is watched on a phone — the cheapest stream is normally the right one, and the high profile only costs CPU to render.`}),k(`label`,{className:`mt-2 block text-[11px] font-medium text-foreground mb-1`,children:`Playback speed`}),k(v,{value:T.mediaClipSpeed===void 0?``:String(T.mediaClipSpeed),onChange:e=>P({mediaClipSpeed:xn(e.target.value)}),options:bn.map(e=>({value:e.value,label:e.label}))}),k(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:`A notification clip is glanced at, not watched: at 2× the recipient sees the whole passage in half the time and the file is half the size. Real time is there when the detail matters more than the glance.`})]})]}),!R&&x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Image frame`}),k(v,{value:T.mediaFrame??``,onChange:e=>P({mediaFrame:$t(e.target.value)}),options:Qt.map(e=>({value:e.value,label:e.label}))}),k(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:`What the attached still shows. "Automatic" leaves it to the attachment mode above.`})]})]}),x(`div`,{className:`space-y-2`,children:[x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Notification title`}),k(h,{value:T.templateTitle,onChange:e=>P({templateTitle:e.target.value}),placeholder:`{{camera}} — {{class}}`})]}),x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Notification body`}),k(`textarea`,{value:T.templateBody,onChange:e=>P({templateBody:e.target.value}),rows:2,placeholder:`{{label}} seen in {{zone}} at {{time}}`,className:`w-full rounded-md border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),x(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Leave blank to use the backend default text. Supported variables include`,` `,k(`code`,{children:`{{camera}}`}),`, `,k(`code`,{children:`{{class}}`}),`, `,k(`code`,{children:`{{label}}`}),`,`,` `,k(`code`,{children:`{{zone}}`}),`, `,k(`code`,{children:`{{confidence}}`}),`,`,` `,k(`code`,{children:`{{time}}`}),`.`]})]})]}),x(t,{value:`conditions`,className:`space-y-4`,children:[x(`div`,{className:`rounded-md border border-border px-3 py-3`,children:[k(`div`,{className:`mb-2 text-[11px] font-semibold text-foreground`,children:R?`Which system events`:`Conditions`}),R&&k(`p`,{className:`mb-2 text-[10px] text-foreground-subtle`,children:`Pick the events this rule reacts to, then narrow them if you want. Nothing else on a system rule is a condition — there is no detection behind it.`}),l.length===0?k(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Condition catalog unavailable — this rule matches on its trigger and targets alone.`}):k(or,{catalog:l,taxonomy:u,delivery:T.delivery,conditions:T.conditions,schedule:T.schedule,cameras:d,gateable:m,onConditionsChange:e=>P({conditions:e}),onScheduleChange:e=>P({schedule:e})})]}),!R&&x(`div`,{className:`rounded-md border border-border px-3 py-3`,children:[x(`div`,{className:`flex items-center justify-between gap-2`,children:[k(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`Test rule`}),x(f,{size:`sm`,variant:`outline`,type:`button`,disabled:re.isPending||!dn(T),onClick:()=>{j(null),re.mutate()},children:[re.isPending?k(z,{className:`h-3.5 w-3.5 animate-spin`}):k(_e,{className:`h-3.5 w-3.5`}),`Dry-run (last 60 min)`]})]}),k(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:`Evaluate the CURRENT (unsaved) rule against recently persisted records — no notification is sent.`}),ee!==null&&k(Mr,{delivery:T.delivery,results:ee,targetNames:ie})]})]})]}),x(`div`,{className:`flex justify-end gap-2 mt-4`,children:[k(f,{variant:`secondary`,size:`sm`,type:`button`,onClick:b,children:`Cancel`}),x(f,{size:`sm`,type:`button`,disabled:I.isPending||!dn(T),onClick:()=>{j(null),I.mutate()},children:[I.isPending&&k(z,{className:`h-3.5 w-3.5 animate-spin`}),w?`Save changes`:`Create rule`]})]})]})}):k(jr,{rule:o,onCancel:b})}function jr({rule:e,onCancel:t}){let n=Object.keys(e?.conditions??{});return k(g,{open:!0,onOpenChange:e=>!e&&t(),children:x(r,{width:`lg`,placement:`sheet-on-mobile`,children:[x(`div`,{className:`flex items-center justify-between mb-3`,children:[x(`h3`,{className:`text-sm font-semibold text-foreground flex items-center gap-2`,children:[k(ge,{className:`h-4 w-4 text-foreground-subtle`}),e?.name??`Rule`]}),k(p,{variant:`warning`,children:`read-only`})]}),x(`div`,{className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-2 text-xs text-warning`,"data-testid":`unsupported-trigger-notice`,children:[`This rule uses the trigger `,k(`code`,{children:e?.delivery}),`, which this version of the admin UI cannot author. It is shown exactly as stored and nothing here can change it — editing it with an editor that does not know the trigger would rewrite it. Update the server bundle, or edit this rule from the viewer app.`]}),x(`dl`,{className:`mt-3 space-y-1.5 text-[11px]`,children:[x(`div`,{className:`flex gap-2`,children:[k(`dt`,{className:`w-24 shrink-0 text-foreground-subtle`,children:`Trigger`}),k(`dd`,{className:`text-foreground`,children:e?.delivery})]}),x(`div`,{className:`flex gap-2`,children:[k(`dt`,{className:`w-24 shrink-0 text-foreground-subtle`,children:`Enabled`}),k(`dd`,{className:`text-foreground`,children:e?.enabled?`yes`:`no`})]}),x(`div`,{className:`flex gap-2`,children:[k(`dt`,{className:`w-24 shrink-0 text-foreground-subtle`,children:`Targets`}),k(`dd`,{className:`text-foreground`,children:e?.targets.length??0})]}),x(`div`,{className:`flex gap-2`,children:[k(`dt`,{className:`w-24 shrink-0 text-foreground-subtle`,children:`Conditions`}),k(`dd`,{className:`text-foreground`,children:n.length>0?n.join(`, `):`none`})]})]}),k(`div`,{className:`flex justify-end gap-2 mt-4`,children:k(f,{variant:`secondary`,size:`sm`,type:`button`,onClick:t,children:`Close`})})]})})}function Mr({delivery:e,results:t,targetNames:n}){if(e===`device-event`)return k(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:`Device-event rules cannot be dry-run: the sensor-event store has no cross-device scan surface, so a test returns no candidate records. The rule still fires live on a matching doorbell press / sensor change.`});if(t.length===0)return k(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:`No records in the last 60 minutes matched — nothing to evaluate.`});let r=t.filter(e=>e.wouldFire).length;return x(`div`,{className:`mt-2 space-y-1.5`,children:[x(`div`,{className:`text-[11px] text-foreground-subtle`,children:[r,` of `,t.length,` evaluated record`,t.length===1?``:`s`,` would fire.`]}),k(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:t.slice(0,50).map(e=>x(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5 text-[11px]`,children:[e.wouldFire?k(I,{className:`h-3.5 w-3.5 shrink-0 text-success`}):k(ce,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),k(`span`,{className:`w-32 shrink-0 text-foreground-subtle`,children:new Date(e.timestamp).toLocaleString()}),x(`span`,{className:`w-14 shrink-0 text-foreground-subtle`,children:[`#`,e.deviceId]}),k(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:e.label??e.className??`object`}),e.wouldFire?x(`span`,{className:`shrink-0 truncate text-success`,children:[`→ `,n.join(`, `)||`targets`]}):e.failedCondition&&x(`span`,{className:`shrink-0 text-foreground-subtle`,children:[`failed: `,e.failedCondition]})]},e.recordId))})]})}b();var Nr=[{value:1,label:`Last hour`},{value:24,label:`Last 24 hours`},{value:168,label:`Last 7 days`},{value:0,label:`All time`}],Pr=[{value:``,label:`Any status`},{value:`pending`,label:`Pending`},{value:`sent`,label:`Sent`},{value:`dead`,label:`Dead`}],Fr=[50,100,250,500];function Ir(){return{ruleId:``,deviceId:``,status:``,windowHours:24,limit:100}}function Lr(e){return e===`pending`||e===`sent`||e===`dead`?e:void 0}function Rr(e){switch(e){case`pending`:return`info`;case`sent`:return`success`;case`dead`:return`danger`}}function zr(){let e=F(),[t,n]=D(Ir),r=e=>n(t=>({...t,...e})),i=C({queryKey:[`notificationRules`,`listRules`,`forHistory`],queryFn:async()=>(await e.trpcClient.notificationRules.listRules.query({})).rules}),a=C({queryKey:[`deviceManager`,`listAll`,`forHistory`],queryFn:async()=>(await e.trpcClient.deviceManager.listAll.query({})).filter(e=>e.type===ee.Camera).map(e=>({id:e.id,name:e.name}))}),o=Date.now(),s=C({queryKey:[`notificationRules`,`getHistory`,t],retry:!1,queryFn:async()=>{let n=t.windowHours>0?o-t.windowHours*36e5:void 0;return(await e.trpcClient.notificationRules.getHistory.query({filter:{limit:t.limit,...t.ruleId?{ruleId:t.ruleId}:{},...t.deviceId?{deviceId:Number(t.deviceId)}:{},...Lr(t.status)?{status:Lr(t.status)}:{},...n===void 0?{}:{since:n}}})).entries}}),c=S(()=>{let e=new Map;for(let t of a.data??[])e.set(t.id,t.name);return e},[a.data]),l=e=>c.get(e)??`Camera #${String(e)}`,u=s.data??[],d=s.isError;return x(V,{icon:ve,title:`Delivery history`,subtitle:`A searchable log of every notification the rules delivered (or failed to deliver).`,children:[x(`div`,{className:`mb-4 grid grid-cols-2 gap-2 sm:grid-cols-5`,children:[x(`div`,{children:[k(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Rule`}),k(v,{value:t.ruleId,onChange:e=>r({ruleId:e.target.value}),options:[{value:``,label:`All rules`},...(i.data??[]).map(e=>({value:e.id,label:e.name}))]})]}),x(`div`,{children:[k(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Camera`}),k(v,{value:t.deviceId,onChange:e=>r({deviceId:e.target.value}),options:[{value:``,label:`All cameras`},...(a.data??[]).map(e=>({value:String(e.id),label:e.name}))]})]}),x(`div`,{children:[k(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Status`}),k(v,{value:t.status,onChange:e=>r({status:e.target.value}),options:Pr.map(e=>({value:e.value,label:e.label}))})]}),x(`div`,{children:[k(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Window`}),k(v,{value:String(t.windowHours),onChange:e=>r({windowHours:Number(e.target.value)}),options:Nr.map(e=>({value:String(e.value),label:e.label}))})]}),x(`div`,{children:[k(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Limit`}),k(v,{value:String(t.limit),onChange:e=>r({limit:Number(e.target.value)}),options:Fr.map(e=>({value:String(e),label:String(e)}))})]})]}),s.isLoading&&k(`div`,{className:`flex items-center justify-center py-16`,children:k(z,{className:`h-6 w-6 animate-spin text-primary`})}),d&&!s.isLoading&&k(_,{children:x(`div`,{className:`flex flex-col items-center gap-2 px-4 py-14 text-center`,children:[k(ve,{className:`h-6 w-6 text-foreground-subtle`}),k(`div`,{className:`text-sm font-medium text-foreground`,children:`Delivery history requires a server update`}),k(`p`,{className:`max-w-md text-xs text-foreground-subtle`,children:`The history query is not available on this hub yet. It becomes queryable after the next server update ships the notification-center history endpoint. Rules still deliver and record their outcome in the meantime.`}),x(`button`,{type:`button`,onClick:()=>void s.refetch(),className:`mt-1 inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:[k(ae,{className:`h-3 w-3`}),` Retry`]})]})}),!d&&!s.isLoading&&u.length===0&&k(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:`No deliveries match these filters.`}),!d&&u.length>0&&k(_,{children:k(m,{columns:Br(l),rows:u,rowKey:e=>e.id,minWidthPx:720,bordered:!1})})]})}function Br(e){return[{key:`when`,header:`When`,nowrap:!0,render:e=>k(`span`,{className:`text-[11px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})},{key:`rule`,header:`Rule`,render:e=>k(`span`,{className:`text-xs font-medium text-foreground`,children:e.ruleName})},{key:`camera`,header:`Camera`,nowrap:!0,render:t=>k(`span`,{className:`text-[11px] text-foreground-subtle`,children:e(t.deviceId)})},{key:`subject`,header:`Subject`,render:e=>x(`span`,{className:`text-[11px] text-foreground-subtle`,children:[e.subject.label??e.subject.className,e.subject.confidence===void 0?``:` · ${Math.round(e.subject.confidence*100)}%`]})},{key:`status`,header:`Status`,nowrap:!0,render:e=>x(`span`,{className:`flex items-center gap-1.5`,children:[k(p,{variant:Rr(e.status),children:e.status}),e.attempts>1?x(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`×`,e.attempts]}):null]})},{key:`error`,header:`Detail`,render:e=>e.error?k(`span`,{className:`text-[11px] text-danger`,children:e.error}):k(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`})}]}var Vr={home:`Home`,away:`Away`,night:`Night`,vacation:`Vacation`,custom_bypass:`Custom`};function Hr(e){return Vr[e]??e}function Ur(e,t){if(e<=0)return t;if(e<60)return`${e} s`;let n=Math.floor(e/60),r=e%60;return r===0?`${n} min`:`${n} min ${r} s`}function Wr(e,t){return e.ruleCount===0?`Arms nothing — no enabled rule is gated on this mode.`:e.allDevices?`Every device — ${Kr(e.ruleCount,`rule`)} with no device scope.`:e.deviceIds.length===0?`${Kr(e.ruleCount,`rule`)}, no device restriction.`:e.deviceIds.map(e=>t.get(e)??`Device ${e}`).join(`, `)}function Gr(e){return e.ruleCount===0}function Kr(e,t){return e===1?`1 ${t}`:`${e} ${t}s`}function qr(e,t){let n=e.trim();if(n===``)return null;let r=Number(n);return!Number.isFinite(r)||!Number.isInteger(r)||r<0||r>t?null:r}b();var Jr=[`notificationRules`,`getAlarmConfig`],Yr=[`notificationOutput`,`listTargets`],Xr=[`deviceManager`,`listAll`,`alarm-coverage`],Zr=600,Qr=3600;function $r({label:e,hint:t,value:n,max:r,zeroMeans:i,disabled:a,onCommit:o}){let[s,c]=D(null);return x(`div`,{className:`flex flex-col gap-1`,children:[k(`label`,{className:`text-sm font-medium`,children:e}),x(`div`,{className:`flex items-center gap-2`,children:[k(h,{type:`number`,min:0,max:r,value:s??String(n),disabled:a,onChange:e=>c(e.target.value),onBlur:()=>{let e=s===null?null:qr(s,r);c(null),e!==null&&e!==n&&o(e)},className:`w-28`,"data-testid":`alarm-delay-${e.toLowerCase().replace(/\s+/g,`-`)}`}),k(`span`,{className:`text-sm text-foreground-subtle`,children:Ur(n,i)})]}),k(`p`,{className:`text-xs text-foreground-subtle`,children:t})]})}function ei(){let t=F(),n=E(),r=C({queryKey:Jr,queryFn:async()=>t.trpcClient.notificationRules.getAlarmConfig.query({})}),i=C({queryKey:Yr,queryFn:async()=>(await t.trpcClient.notificationOutput.listTargets.query({})).map(e=>({id:e.id,name:e.name,enabled:e.enabled}))}),a=C({queryKey:Xr,queryFn:async()=>(await t.trpcClient.deviceManager.listAll.query({projection:`slim`})).map(e=>({id:e.id,name:e.name}))}),o=O({mutationFn:e=>t.trpcClient.notificationRules.setAlarmConfig.mutate({patch:e}),onSuccess:()=>n.invalidateQueries({queryKey:Jr})}),s=S(()=>{let e=new Map;for(let t of a.data??[])e.set(t.id,t.name);return e},[a.data]);if(r.isLoading)return k(V,{icon:de,title:`Alarm`,subtitle:`Panel delays and mode coverage.`,children:k(z,{className:`h-5 w-5 animate-spin`})});let c=r.data;if(c===void 0||r.isError)return k(V,{icon:de,title:`Alarm`,subtitle:`Panel delays and mode coverage.`,children:k(y,{title:`Alarm settings are not available`,message:`This hub has not been updated to serve the alarm configuration yet.`})});if(c.deviceId===null)return k(V,{icon:de,title:`Alarm`,subtitle:`Panel delays and mode coverage.`,children:k(_,{className:`p-4`,children:k(`p`,{className:`text-sm text-foreground-subtle`,children:`This installation has no alarm panel. The panel is created by the Notification Center on the hub — if this is the hub, its creation failed and the server log says why.`})})});let l=c.settings,u=o.isPending,d=i.data??[],f=l.announceTargets,m=e=>{o.mutate(e)},h=e=>{m({announceTargets:f.includes(e)?f.filter(t=>t!==e):[...f,e]})};return k(V,{icon:de,title:`Alarm`,subtitle:`Panel delays, and what each mode actually arms.`,children:x(`div`,{className:`flex flex-col gap-4`,children:[o.isError?k(y,{title:`Could not save`,message:String(o.error)}):null,x(_,{className:`p-4`,children:[k(`h3`,{className:`text-sm font-semibold mb-3`,children:`Delays`}),x(`div`,{className:`grid gap-4 sm:grid-cols-3`,children:[k($r,{label:`Exit delay`,hint:`Time between arming and the mode taking effect — long enough to leave.`,value:l.exitDelaySec,max:Zr,zeroMeans:`arms immediately`,disabled:u,onCommit:e=>m({exitDelaySec:e})}),k($r,{label:`Entry delay`,hint:`Time between a trigger and the alarm firing — long enough to reach the keypad.`,value:l.entryDelaySec,max:Zr,zeroMeans:`fires immediately`,disabled:u,onCommit:e=>m({entryDelaySec:e})}),k($r,{label:`Triggered for`,hint:`How long the alarm stays triggered before re-arming itself.`,value:l.triggeredDurationSec,max:Qr,zeroMeans:`until disarmed`,disabled:u,onCommit:e=>m({triggeredDurationSec:e})})]})]}),x(_,{className:`p-4`,children:[x(`div`,{className:`flex items-start justify-between gap-4`,children:[x(`div`,{children:[k(`h3`,{className:`text-sm font-semibold`,children:`Announce when a mode is armed`}),k(`p`,{className:`text-xs text-foreground-subtle mt-1`,children:`Sends one notification listing the devices that mode arms — the list below, as it stands at that moment.`})]}),k(e,{checked:l.announceArm,disabled:u,onCheckedChange:e=>m({announceArm:e}),"data-testid":`alarm-announce-toggle`})]}),l.announceArm?x(`div`,{className:`mt-3 flex flex-col gap-2`,children:[d.length===0?k(`p`,{className:`text-xs text-foreground-subtle`,children:`No notification targets are configured — nothing can be sent.`}):d.map(e=>x(`label`,{className:`flex items-center gap-2 text-sm`,children:[k(`input`,{type:`checkbox`,checked:f.includes(e.id),disabled:u,onChange:()=>h(e.id),"data-testid":`alarm-target-${e.id}`}),k(`span`,{children:e.name}),e.enabled?null:k(p,{variant:`warning`,children:`disabled`})]},e.id)),f.length===0?k(`p`,{className:`text-xs text-warning`,children:`No target selected — the announcement will not be sent.`}):null]}):null]}),x(_,{className:`p-4`,children:[k(`h3`,{className:`text-sm font-semibold mb-1`,children:`What each mode arms`}),k(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Derived from the enabled rules gated on this panel. Nothing here is stored — change a rule and this changes with it.`}),k(`div`,{className:`flex flex-col gap-2`,"data-testid":`alarm-coverage`,children:c.coverage.map(e=>x(`div`,{className:`flex items-start gap-3 rounded border border-border p-2`,"data-mode":e.mode,"data-empty":Gr(e)?`true`:`false`,children:[k(`div`,{className:`w-20 shrink-0 text-sm font-medium`,children:Hr(e.mode)}),k(`div`,{className:`flex-1 text-sm text-foreground-subtle`,children:Wr(e,s)}),Gr(e)?k(pe,{className:`h-4 w-4 shrink-0 text-warning`}):null]},e.mode))})]})]})})}var ti=[{value:`object-event`,label:`Object detection`,hint:`A detection on a live track — what an "Immediate" rule sees.`},{value:`track-end`,label:`Track end`,hint:`A finalised track: importance, dwell and label confidence exist only here.`},{value:`device-event`,label:`Device event`,hint:`A doorbell press or a linked sensor changing state.`},{value:`package-event`,label:`Package event`,hint:`A parcel delivered or picked up.`},{value:`audio-event`,label:`Audio event`,hint:`A classified audio episode. Rides the Immediate delivery, gated by the audio classes.`},{value:`occupancy-event`,label:`Occupancy edge`,hint:`A zone count crossing its threshold. Rides the Device-event delivery.`}];function ni(e){return ti.find(t=>t.value===e)?.value}function ri(e){return e===`object-event`||e===`audio-event`?`immediate`:e===`occupancy-event`?`device-event`:e}function ii(e){return``}var ai={x:.25,y:.25,w:.5,h:.5},oi={zoneId:``,zoneName:``,className:``,count:1,previousCount:0,occupied:!0,threshold:1};function si(){return{trigger:`object-event`,deviceId:null,sourceDeviceId:null,classNames:[],label:``,confidence:void 0,labelConfidence:void 0,importance:void 0,dwellSeconds:void 0,zones:[],crossingEnabled:!1,crossingZoneId:``,crossingDirection:`enter`,sensorKind:``,eventType:``,packagePhase:``,source:``,bboxEnabled:!1,bbox:ai,occupancy:oi,timestampLocal:``,onlyRuleId:``,bypassCooldown:!1,bypassMute:!1,runActions:!1,still:`live`}}function ci(e){return e.deviceId!==null}function li(e){if(e.trim().length===0)return;let t=Number(e);return Number.isFinite(t)?t:void 0}function ui(e){if(e.trim().length===0)return;let t=Date.parse(e);return Number.isFinite(t)?t:void 0}function di(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}T${n(t.getHours())}:${n(t.getMinutes())}`}function fi(e){if(e.deviceId===null)return null;let t=e.trigger,n=ui(e.timestampLocal),r=e.label.trim(),i=e.sensorKind.trim(),a=e.eventType.trim(),o=e.onlyRuleId.trim(),s=t===`device-event`,c=t===`occupancy-event`;return{trigger:t,deviceId:e.deviceId,...s&&e.sourceDeviceId!==null&&e.sourceDeviceId!==e.deviceId?{sourceDeviceId:e.sourceDeviceId}:{},classNames:[...e.classNames],...r.length>0?{label:r}:{},...e.confidence===void 0?{}:{confidence:e.confidence},...e.labelConfidence===void 0?{}:{labelConfidence:e.labelConfidence},...e.importance===void 0?{}:{importance:e.importance},...e.dwellSeconds===void 0?{}:{dwellSeconds:e.dwellSeconds},zones:[...e.zones],...t===`object-event`&&e.crossingEnabled?{crossing:{zoneId:e.crossingZoneId,direction:e.crossingDirection}}:{},...s&&i.length>0?{sensorKind:i}:{},...s&&a.length>0?{eventType:a}:{},...t===`package-event`&&e.packagePhase!==``?{packagePhase:e.packagePhase}:{},...e.source===``?{}:{source:e.source},...e.bboxEnabled?{bbox:{...e.bbox}}:{},...c?{occupancy:pi(e.occupancy)}:{},...n===void 0?{}:{timestamp:n},...o.length>0?{onlyRuleId:o}:{},bypassCooldown:e.bypassCooldown,bypassMute:e.bypassMute,runActions:e.runActions,still:e.still}}function pi(e){let t=e.zoneId.trim(),n=e.zoneName.trim(),r=e.className.trim();return{...t.length>0?{zoneId:t}:{},...n.length>0?{zoneName:n}:{},...r.length>0?{className:r}:{},count:Math.max(0,Math.round(e.count)),previousCount:Math.max(0,Math.round(e.previousCount)),occupied:e.occupied,threshold:Math.max(1,Math.round(e.threshold))}}function mi(e){return Math.min(1,Math.round((e+.05)*100)/100)}function hi(e){if(e.delivery===`immediate`){let t=e.conditions.classes??[];return t.length>0&&t.every(e=>e.startsWith(`audio-`))?`audio-event`:`object-event`}return e.delivery===`device-event`?e.conditions.occupancy===void 0?`device-event`:`occupancy-event`:e.delivery===`track-end`?`track-end`:`package-event`}function gi(e){let t=si(),n=e.conditions,r=hi(e),i=n.zones?.ids??[],a=n.identities?.[0]??n.labelEquals?.[0]??n.plates?.values?.[0],o=n.crossing===`exit`?`exit`:n.crossing===void 0?void 0:`enter`,s=r===`package-event`?n.packagePhase===`picked-up`?`picked-up`:`delivered`:``;return{...t,trigger:r,deviceId:n.devices?.[0]??null,classNames:[...n.classes??[]],...a===void 0?{}:{label:a},...n.minConfidence===void 0?{}:{confidence:mi(n.minConfidence)},...n.minLabelConfidence===void 0?{}:{labelConfidence:mi(n.minLabelConfidence)},...n.minImportance===void 0?{}:{importance:mi(n.minImportance)},...n.minDwellSeconds===void 0?{}:{dwellSeconds:Math.round(n.minDwellSeconds)+1},zones:[...i],...r===`object-event`&&o!==void 0?{crossingEnabled:!0,crossingZoneId:i[0]??``,crossingDirection:o}:{},...n.sensorKinds?.[0]===void 0?{}:{sensorKind:n.sensorKinds[0]},...n.eventTypeTokens?.[0]===void 0?{}:{eventType:n.eventTypeTokens[0]},packagePhase:s,source:n.source!==void 0&&n.source!==`any`?n.source:ii(r),...n.customZones!==void 0&&n.customZones.length>0?{bboxEnabled:!0}:{},...n.occupancy===void 0?{}:{occupancy:_i(n.occupancy)},onlyRuleId:e.id}}function _i(e){let t=Math.max(1,Math.round(e.count)),n={zoneId:e.zoneId??``,zoneName:``,className:e.className??``,threshold:t};if(e.op===`became-free`)return{...n,count:0,previousCount:t,occupied:!1};if(e.op===`<=`){let t=Math.max(0,Math.round(e.count));return{...n,count:t,previousCount:t+1,occupied:t>0}}return{...n,count:t,previousCount:Math.max(0,t-1),occupied:!0}}function vi(e){let t=[];return e.conditions.deviceState!==void 0&&t.push({conditionId:`deviceState`,note:`This rule is gated on device #${e.conditions.deviceState.deviceId} being in a given state. The gate reads the REAL device — put it in that state first, or the simulation fails closed exactly as production would.`}),e.conditions.customZones!==void 0&&e.conditions.customZones.length>0&&t.push({conditionId:`customZones`,note:`This rule matches viewer-drawn polygons against the subject bbox. The bbox below is enabled but centred — move it over the polygon, or the condition fails.`}),t}function yi(e){return{form:gi(e),caveats:vi(e),ruleName:e.name}}var bi=null;function xi(e){bi=e}function Si(){return bi}function Ci(){bi=null}var wi=[`n/a`,`clear`,`suppressed`,`bypassed`],Ti=[`live`,`none`,`unavailable`,`unattachable`];function Ei(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function $(e,t){let n=e[t];return typeof n==`string`?n:void 0}function Di(e,t){let n=e[t];return Array.isArray(n)?n.filter(e=>typeof e==`string`):[]}function Oi(e){if(!Ei(e))return null;let t=$(e,`ruleId`),n=$(e,`ruleName`),r=$(e,`cooldown`),i=wi.find(e=>e===r);if(t===void 0||n===void 0||i===void 0||typeof e.matched!=`boolean`)return null;let a=$(e,`failedCondition`),o=Array.isArray(e.matchedOn)?Di(e,`matchedOn`):void 0;return{ruleId:t,ruleName:n,matched:e.matched,...a===void 0?{}:{failedCondition:a},...o===void 0?{}:{matchedOn:o},cooldown:i,enqueued:typeof e.enqueued==`number`?e.enqueued:0,targetIds:Di(e,`targetIds`)}}function ki(e){if(!Ei(e))return null;let t=$(e,`recordId`),n=$(e,`delivery`),r=$(e,`still`),i=Ti.find(e=>e===r);if(t===void 0||n===void 0||i===void 0||e.origin!==`synthetic`)return null;let a=Array.isArray(e.outcomes)?e.outcomes:[],o=[];for(let e of a){let t=Oi(e);t!==null&&o.push(t)}let s=$(e,`droppedBy`);return{recordId:t,origin:`synthetic`,delivery:n,candidates:typeof e.candidates==`number`?e.candidates:0,outcomes:o,still:i,notes:Di(e,`notes`),...s===void 0?{}:{droppedBy:s}}}function Ai(e){if(e.droppedBy!==void 0)return`Dropped before evaluation (${e.droppedBy}) — no rule was consulted.`;if(e.candidates===0)return`No enabled rule declares the "${e.delivery}" delivery, so nothing was evaluated.`;let t=e.outcomes.filter(e=>e.matched).length,n=e.outcomes.reduce((e,t)=>e+t.enqueued,0);return t===0?`${e.candidates} candidate rule${e.candidates===1?``:`s`} evaluated, none matched.`:`${t} of ${e.candidates} candidate rule${e.candidates===1?``:`s`} matched — ${n} notification${n===1?``:`s`} enqueued.`}var ji=new Set([`sensor`,`control`,`custom`]);function Mi({form:e,cameras:t,taxonomy:n,kinds:r,kindsLoading:i,onPatch:a}){let o=e.deviceId===null?[]:[e.deviceId],s=M(`classes`,n);if(e.trigger===`device-event`)return x(`div`,{className:`space-y-3 rounded-md border border-border px-3 py-2`,children:[k(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`What happened`}),k(Ni,{form:e,kinds:r,loading:i,onPatch:a})]});if(e.trigger===`audio-event`){let n=r.filter(e=>e.category===`audio`&&e.level===`sub`).map(e=>({value:e.kind,label:e.label}));return x(`div`,{className:`space-y-3 rounded-md border border-border px-3 py-2`,children:[k(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`What happened`}),x(`div`,{children:[k(`label`,{className:X,children:`Audio classes`}),k(J,{options:n,value:e.classNames,onChange:e=>a({classNames:e}),loading:i,emptyHint:e.deviceId===null?`Pick a camera first — the audio vocabulary is per camera.`:`This camera advertises no audio kinds. The audio classifier is probably off for it.`,placeholder:`Audio class id…`})]}),x(`div`,{children:[k(`label`,{className:X,children:`Zones`}),k(jn,{deviceIds:o,cameras:t,value:e.zones,onChange:e=>a({zones:e})})]})]})}return e.trigger===`occupancy-event`?x(`div`,{className:`space-y-3 rounded-md border border-border px-3 py-2`,children:[k(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`What happened`}),k(Pi,{form:e,cameras:t,taxonomy:n,onPatch:a})]}):x(`div`,{className:`space-y-3 rounded-md border border-border px-3 py-2`,children:[k(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`What happened`}),x(`div`,{children:[k(`label`,{className:X,children:`Detected classes`}),s===null?k(Dn,{value:e.classNames,placeholder:`Class id (person, car…)`,onChange:e=>a({classNames:e})}):k(On,{picker:s,value:e.classNames,onChange:e=>a({classNames:e})})]}),x(`div`,{children:[k(`label`,{className:X,children:`Zones the subject is in`}),k(jn,{deviceIds:o,cameras:t,value:e.zones,onChange:e=>a({zones:e})})]}),e.trigger===`package-event`&&x(`div`,{className:`max-w-[14rem]`,children:[k(`label`,{className:`block text-[11px] font-medium text-foreground`,children:`Package phase`}),k(v,{value:e.packagePhase,options:[{value:``,label:`— none —`},{value:`delivered`,label:`Delivered`},{value:`picked-up`,label:`Picked up`}],onChange:e=>a({packagePhase:e.target.value===`delivered`?`delivered`:e.target.value===`picked-up`?`picked-up`:``})})]})]})}function Ni({form:e,kinds:t,loading:n,onPatch:r}){let i=t.filter(e=>ji.has(e.category)),a=i.find(t=>t.kind===e.sensorKind);return x(w,{children:[x(`div`,{children:[k(`label`,{className:X,children:`Event kind`}),k(v,{value:e.sensorKind,options:[{value:``,label:n?`Loading kinds…`:`— pick a kind —`},...i.map(e=>({value:e.kind,label:`${e.label} (${e.category})`}))],onChange:e=>{let t=i.find(t=>t.kind===e.target.value);r({sensorKind:t?.kind??``,sourceDeviceId:t?.source.deviceId??null})}}),!n&&i.length===0&&k(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:e.deviceId===null?`Pick a camera first — sensor and control kinds come from the devices linked to it.`:`This camera has no linked sensor or control device, so it can produce no device event. Link one on the camera page first.`})]}),x(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[x(`div`,{children:[k(`label`,{className:X,children:`Source device`}),k(h,{type:`number`,value:e.sourceDeviceId===null?``:String(e.sourceDeviceId),placeholder:`the camera itself`,onChange:e=>r({sourceDeviceId:li(e.target.value)??null})}),k(`p`,{className:Z,children:a===void 0?`The linked device whose state changed. Filled in for you when you pick a kind.`:`Filled in from "${a.label}" — contributed by device #${a.source.deviceId} via the ${a.source.capName} capability.`})]}),x(`div`,{children:[k(`label`,{className:X,children:`Event type token`}),k(h,{value:e.eventType,placeholder:`press, press_long…`,onChange:e=>r({eventType:e.target.value})}),k(`p`,{className:Z,children:`Only event-emitter sources carry one. A passive sensor emits none, and a rule gating on a token would fail closed for it.`})]})]})]})}function Pi({form:t,cameras:n,taxonomy:r,onPatch:i}){let a=t.deviceId===null?[]:[t.deviceId],o=M(`classes`,r),s=o===null?[]:o.groups.flatMap(e=>e.options),c=t.occupancy,l=e=>i({occupancy:{...c,...e}});return x(w,{children:[x(`div`,{children:[k(`label`,{className:X,children:`Zone`}),k(jn,{deviceIds:a,cameras:n,value:c.zoneId===``?[]:[c.zoneId],onChange:e=>l({zoneId:e[e.length-1]??``})}),k(`p`,{className:Z,children:`Leave empty for the whole frame.`})]}),x(`div`,{className:`max-w-[14rem]`,children:[k(`label`,{className:X,children:`Class`}),k(v,{value:c.className,options:[{value:``,label:`— any class —`},...s.map(e=>({value:e.value,label:e.label}))],onChange:e=>l({className:e.target.value})})]}),x(`div`,{className:`flex flex-wrap items-end gap-3`,children:[x(`label`,{className:`text-[11px] text-foreground-subtle`,children:[`Count now`,k(h,{type:`number`,min:0,className:`w-20`,value:String(c.count),onChange:e=>l({count:li(e.target.value)??0})})]}),x(`label`,{className:`text-[11px] text-foreground-subtle`,children:[`Count before`,k(h,{type:`number`,min:0,className:`w-20`,value:String(c.previousCount),onChange:e=>l({previousCount:li(e.target.value)??0})})]}),x(`label`,{className:`text-[11px] text-foreground-subtle`,children:[`Threshold`,k(h,{type:`number`,min:1,className:`w-20`,value:String(c.threshold),onChange:e=>l({threshold:li(e.target.value)??1})})]}),x(`label`,{className:`flex items-center gap-2 pb-1 text-[11px] text-foreground`,children:[k(e,{checked:c.occupied,onCheckedChange:e=>l({occupied:e}),"aria-label":`occupied`}),`Occupied`]})]})]})}function Fi({form:t,cameras:n,onPatch:r}){let i=t.deviceId===null?[]:[t.deviceId];return x(`details`,{className:`rounded-md border border-border px-3 py-2`,children:[k(`summary`,{className:`cursor-pointer text-[11px] font-semibold text-foreground`,children:`Advanced`}),x(`div`,{className:`mt-2 space-y-3`,children:[t.trigger===`object-event`&&x(`div`,{children:[x(`label`,{className:`flex items-center gap-2 text-[11px] font-medium text-foreground`,children:[k(e,{checked:t.crossingEnabled,onCheckedChange:e=>r({crossingEnabled:e}),"aria-label":`zone crossing`}),`This event is a confirmed zone crossing`]}),t.crossingEnabled&&x(`div`,{className:`mt-1 space-y-1.5`,children:[k(`div`,{className:`max-w-[12rem]`,children:k(v,{value:t.crossingDirection,options:[{value:`enter`,label:`Entered the zone`},{value:`exit`,label:`Left the zone`}],onChange:e=>r({crossingDirection:e.target.value===`exit`?`exit`:`enter`})})}),k(jn,{deviceIds:i,cameras:n,value:t.crossingZoneId===``?[]:[t.crossingZoneId],onChange:e=>r({crossingZoneId:e[e.length-1]??``})})]})]}),x(`div`,{children:[x(`label`,{className:`flex items-center gap-2 text-[11px] font-medium text-foreground`,children:[k(e,{checked:t.bboxEnabled,onCheckedChange:e=>r({bboxEnabled:e}),"aria-label":`bounding box`}),`Carry a bounding box`]}),k(`p`,{className:Z,children:"Normalized 0–1, top-left origin. Feeds the `customZones` condition and decides how the still is cropped or boxed."}),t.bboxEnabled&&k(`div`,{className:`mt-1 flex flex-wrap gap-2`,children:[`x`,`y`,`w`,`h`].map(e=>x(`label`,{className:`text-[11px] text-foreground-subtle`,children:[e,k(h,{type:`number`,min:0,max:1,step:.05,className:`w-20`,value:String(t.bbox[e]),onChange:n=>r({bbox:{...t.bbox,[e]:li(n.target.value)??0}})})]},e))})]}),x(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[x(`div`,{children:[k(`label`,{className:X,children:`Happened at`}),x(`div`,{className:`flex items-center gap-2`,children:[k(h,{type:`datetime-local`,value:t.timestampLocal,onChange:e=>r({timestampLocal:e.target.value})}),t.timestampLocal===``?k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>r({timestampLocal:di(Date.now())}),children:`Set`}):k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>r({timestampLocal:``}),children:`Now`})]}),k(`p`,{className:Z,children:`Empty = now. Set it to a time inside (or outside) a rule's schedule window to test the schedule without waiting for the hour.`})]}),x(`div`,{children:[k(`label`,{className:X,children:`Detection source`}),k(v,{value:t.source,options:[{value:``,label:`— unset (reads as pipeline) —`},{value:`pipeline`,label:`Pipeline`},{value:`onboard`,label:`Onboard (camera)`},{value:`sensor`,label:`Sensor`},{value:`audio`,label:`Audio`}],onChange:e=>{let t=e.target.value;r({source:t===`pipeline`||t===`onboard`||t===`sensor`||t===`audio`?t:``})}})]})]})]})]})}function Ii({checked:t,label:n,hint:r,danger:i=!1,onChange:a}){return x(`div`,{children:[x(`label`,{className:`flex items-center gap-2 text-[11px] font-medium text-foreground`,children:[k(e,{checked:t,onCheckedChange:a,"aria-label":n}),n,i&&k(p,{variant:`danger`,children:`actuates devices`})]}),k(`p`,{className:Z,children:r})]})}b();var Li={live:`A live snapshot of the camera was taken and attached.`,none:`No still was requested.`,unavailable:`A still was requested but the camera could not produce one.`,unattachable:`This trigger cannot carry a still at all — an audio or occupancy notification freezes no media owner, so it ships text-only in production too. This is not a limit of the test.`},Ri={"n/a":`The rule did not match, so no cooldown was consulted.`,clear:`No cooldown was in effect — the rule was free to fire.`,suppressed:`A cooldown from an earlier fire silenced this one. Re-run with "Ignore cooldown".`,bypassed:`A cooldown was in effect and was deliberately ignored for this run.`};function zi({result:e,targetName:t}){return x(`div`,{className:`space-y-3 rounded-md border border-border px-3 py-3`,children:[k(`p`,{className:`text-xs font-medium text-foreground`,children:Ai(e)}),x(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px] text-foreground-subtle`,children:[k(Bi,{recordId:e.recordId}),x(`span`,{children:[`delivery `,k(`span`,{className:`text-foreground`,children:e.delivery})]}),x(`span`,{children:[`candidates `,k(`span`,{className:`text-foreground`,children:e.candidates})]}),x(`span`,{title:Li[e.still],children:[`still `,k(`span`,{className:`text-foreground`,children:e.still})]}),e.droppedBy!==void 0&&x(p,{variant:`warning`,children:[`dropped: `,e.droppedBy]})]}),e.notes.length>0&&k(`ul`,{className:`space-y-1 rounded-md border border-border bg-surface px-2.5 py-2`,children:e.notes.map(e=>k(`li`,{className:`text-[11px] leading-snug text-foreground-subtle`,children:e},e))}),e.outcomes.length===0?x(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`No rule was evaluated. Either no enabled rule declares the`,` `,k(`span`,{className:`text-foreground`,children:e.delivery}),` delivery, or the ones that do were filtered out before evaluation — the notes above say which.`]}):k(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:e.outcomes.map(e=>k(Vi,{outcome:e,targetName:t},e.ruleId))})]})}function Bi({recordId:e}){let[t,n]=D(!1);return x(`span`,{className:`inline-flex items-center gap-1 rounded border border-border px-1.5 py-0.5`,children:[k(`code`,{className:`text-[10px] text-foreground`,children:e}),k(f,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>{let t=navigator.clipboard;t!==void 0&&t.writeText(e).then(()=>{n(!0),setTimeout(()=>n(!1),1500)},()=>n(!1))},title:`Copy record id`,children:k(re,{className:`h-3 w-3`})}),t&&k(`span`,{className:`text-[10px] text-success`,children:`copied`})]})}function Vi({outcome:e,targetName:t}){return x(`li`,{className:`space-y-1 px-2.5 py-2`,children:[x(`div`,{className:`flex items-center gap-2`,children:[e.matched?k(I,{className:`h-3.5 w-3.5 shrink-0 text-success`}):k(ce,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),k(`span`,{className:`min-w-0 flex-1 truncate text-xs text-foreground`,children:e.ruleName}),x(`span`,{className:`shrink-0 text-[10px] text-foreground-subtle`,title:Ri[e.cooldown],children:[`cooldown: `,e.cooldown]})]}),!e.matched&&k(`p`,{className:`pl-5 text-[11px] text-foreground-subtle`,children:e.failedCondition===void 0?`Did not match. The engine reported no failing condition id.`:x(w,{children:[`Did not match — first failing condition`,` `,k(`code`,{className:`text-foreground`,children:e.failedCondition}),`.`]})}),e.matched&&x(`p`,{className:`pl-5 text-[11px] text-foreground-subtle`,children:[e.enqueued,` outbox row`,e.enqueued===1?``:`s`,` enqueued`,e.targetIds.length>0?` → ${e.targetIds.map(t).join(`, `)}`:` — no target resolved, so nothing will be delivered`,`.`]}),e.matchedOn!==void 0&&e.matchedOn.length>0&&x(`p`,{className:`pl-5 text-[10px] text-foreground-muted`,children:[`matched on: `,e.matchedOn.join(`, `)]})]})}b();var Hi=`pipeline-analytics`,Ui=`nc.injectTestEvent`;function Wi(){let e=F(),[t,n]=D(()=>Si()?.form??si()),[r]=D(()=>Si()?.caveats??[]),[i]=D(()=>Si()?.ruleName??null);A(()=>Ci(),[]);let[a,o]=D(null),[s,c]=D(!1),[l,u]=D(null),d=e=>n(t=>({...t,...e})),p=C({queryKey:Cr,queryFn:async()=>(await e.trpcClient.deviceManager.listAll.query({})).filter(e=>e.type===ee.Camera).map(e=>({id:e.id,name:e.name}))}),m=C({queryKey:Sr,queryFn:()=>e.trpcClient.notificationRules.getConditionCatalog.query({})}),g=C({queryKey:br,queryFn:async()=>(await e.trpcClient.notificationRules.listRules.query({})).rules}),b=C({queryKey:xr,queryFn:()=>e.trpcClient.notificationOutput.listTargets.query({})}),w=t.deviceId,T=C({queryKey:[[`pipelineAnalytics`,`listEventKindsBatch`],{deviceId:w}],enabled:w!==null,staleTime:6e4,queryFn:async()=>w===null?[]:(await e.trpcClient.pipelineAnalytics.listEventKindsBatch.query({deviceIds:[w]})).flatMap(e=>[...e.kinds])}),E=p.data??[],j=m.data?.taxonomy,te=T.data??[],M=S(()=>{let e=new Map;for(let t of b.data??[])e.set(t.id,t.name);return e},[b.data]),N=O({mutationFn:async()=>{let n=fi(t);if(n===null)throw Error(`Pick a camera first.`);return e.trpcClient.addons.custom.mutate({addonId:Hi,action:Ui,input:n})},onMutate:()=>{o(null),c(!1),u(null)},onSuccess:e=>{let t=ki(e);o(t),c(t===null)},onError:e=>u(e instanceof Error?e.message:`The simulation failed.`)}),P=ri(t.trigger),ne=g.data?.find(e=>e.id===t.onlyRuleId);return x(V,{icon:_e,title:`Simulate an event`,subtitle:`Inject a synthetic detection, doorbell press or occupancy edge and see exactly which rules match it, which condition each one fails on, and what would be delivered. Nothing is persisted — no track, no event row, no media.`,children:[p.isError&&k(y,{title:`Failed to load cameras`,message:p.error instanceof Error?p.error.message:`Unknown error`,onRetry:()=>void p.refetch()}),i!==null&&x(`div`,{className:`rounded-md border border-primary/40 bg-primary/5 px-3 py-2 text-[11px] text-foreground`,children:[`Seeded from the rule `,k(`span`,{className:`font-medium`,children:i}),`. Only that rule will be evaluated — clear "Evaluate only one rule" below to run the whole rule set.`]}),r.length>0&&k(`div`,{className:`space-y-1 rounded-md border border-warning/40 bg-warning/5 px-3 py-2`,children:r.map(e=>x(`p`,{className:`flex gap-1.5 text-[11px] text-foreground`,children:[k(pe,{className:`mt-0.5 h-3 w-3 shrink-0 text-warning`}),k(`span`,{children:e.note})]},e.conditionId))}),x(_,{className:`space-y-4`,children:[x(`div`,{children:[k(`label`,{className:X,children:`Camera`}),k(v,{"data-testid":`simulate-camera`,value:t.deviceId===null?``:String(t.deviceId),options:[{value:``,label:E.length===0?`Loading cameras…`:`— pick a camera —`},...E.map(e=>({value:String(e.id),label:e.name}))],onChange:e=>{d({deviceId:li(e.target.value)??null,zones:[],crossingZoneId:``,sensorKind:``,sourceDeviceId:null,occupancy:{...t.occupancy,zoneId:``}})}}),k(`p`,{className:Z,children:`The camera the event is attributed to — what a notification shows.`})]}),x(`div`,{children:[k(`label`,{className:X,children:`Trigger`}),k(v,{"data-testid":`simulate-trigger`,value:t.trigger,options:ti.map(e=>({value:e.value,label:e.label})),onChange:e=>{let n=ni(e.target.value);if(!n)return;let r=ii(t.trigger);d({trigger:n,source:t.source===``||t.source===r?ii(n):t.source})}}),x(`p`,{className:Z,children:[ti.find(e=>e.value===t.trigger)?.hint,` Only rules whose trigger is `,k(`span`,{className:`text-foreground`,children:P}),` are candidates.`]})]}),k(Mi,{form:t,cameras:E,taxonomy:j,kinds:te,kindsLoading:T.isLoading,onPatch:d}),x(`details`,{className:`rounded-md border border-border px-3 py-2`,open:!0,children:[k(`summary`,{className:`cursor-pointer text-[11px] font-semibold text-foreground`,children:`Quality`}),x(`div`,{className:`mt-2 space-y-3`,children:[k(`p`,{className:Z,children:`Every field here can be left EMPTY, and empty is a real state: a rule with a minimum confidence FAILS on a subject that carries none. Leave one blank to reproduce exactly that.`}),x(`div`,{children:[k(`label`,{className:X,children:`Label (identity name / plate / subclass)`}),k(h,{value:t.label,placeholder:`e.g. Marco, AB123CD`,onChange:e=>d({label:e.target.value})})]}),x(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[x(`div`,{children:[k(`label`,{className:X,children:`Detection confidence`}),k(Q,{value:t.confidence,min:0,max:1,step:.05,onChange:e=>d({confidence:e})})]}),x(`div`,{children:[k(`label`,{className:X,children:`Label-match confidence`}),k(Q,{value:t.labelConfidence,min:0,max:1,step:.05,onChange:e=>d({labelConfidence:e})})]}),x(`div`,{children:[k(`label`,{className:X,children:`Importance`}),k(Q,{value:t.importance,min:0,max:1,step:.05,onChange:e=>d({importance:e})})]}),x(`div`,{children:[k(`label`,{className:X,children:`Dwell (seconds)`}),k(Q,{value:t.dwellSeconds,min:0,step:1,onChange:e=>d({dwellSeconds:e})})]})]})]})]}),k(Fi,{form:t,cameras:E,onPatch:d}),x(`div`,{className:`space-y-2 rounded-md border border-border px-3 py-2`,children:[k(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`How to run it`}),k(Ii,{checked:t.bypassCooldown,label:`Ignore the cooldown`,hint:`A rule that already fired recently is normally silenced. Turn this on to fire anyway; leave it off to SEE the suppression.`,onChange:e=>d({bypassCooldown:e})}),k(Ii,{checked:t.bypassMute,label:`Ignore mutes and snoozes`,hint:`A muted camera or a snoozed rule drops the event before any rule is consulted.`,onChange:e=>d({bypassMute:e})}),k(Ii,{checked:t.runActions,danger:!0,label:`Run the rule's actions — this actuates real devices`,hint:`A matched rule's onTrigger sequences run for real: locks unlock, lights switch, sirens sound. Off unless you mean it.`,onChange:e=>d({runActions:e})}),x(`div`,{className:`max-w-[14rem]`,children:[k(`label`,{className:X,children:`Still image`}),k(v,{value:t.still,options:[{value:`live`,label:`Live snapshot of the camera`},{value:`none`,label:`No image`}],onChange:e=>d({still:e.target.value===`none`?`none`:`live`})})]}),x(`div`,{children:[k(`label`,{className:X,children:`Evaluate only one rule`}),k(v,{value:t.onlyRuleId,options:[{value:``,label:`— every enabled rule —`},...(g.data??[]).map(e=>({value:e.id,label:e.name}))],onChange:e=>d({onlyRuleId:e.target.value})}),t.onlyRuleId.length>0&&ne===void 0&&x(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:[`Rule `,k(`code`,{children:t.onlyRuleId}),` is not in the current list — it may have been deleted. The run will find no candidate.`]})]})]}),l!==null&&k(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:l}),x(`div`,{className:`flex items-center justify-between gap-2`,children:[k(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Nothing is persisted: no track, no event row, no stored media. Delivery is real.`}),x(f,{size:`sm`,type:`button`,disabled:N.isPending||!ci(t),onClick:()=>N.mutate(),children:[N.isPending?k(z,{className:`h-3.5 w-3.5 animate-spin`}):k(_e,{className:`h-3.5 w-3.5`}),`Inject event`]})]})]}),s&&k(`div`,{className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-2 text-[11px] text-foreground`,children:`The hub answered, but this build could not read the answer. That is what a hub older than the simulator looks like — update the server, then re-run.`}),a!==null&&k(zi,{result:a,targetName:e=>M.get(e)??e})]})}var Gi=`simulate`;function Ki(){let[e,t]=R();return k(`div`,{className:`flex flex-col p-4`,children:k(me,{tabs:[{id:`targets`,label:`Targets`,icon:le,content:k(Ke,{})},{id:`rules`,label:`Rules`,icon:ge,content:k(Dr,{onSimulateRule:n=>{xi(yi(n));let r=new URLSearchParams(e);r.set(`tab`,Gi),t(r,{replace:!0})}})},{id:Gi,label:`Simulate`,icon:_e,content:k(Wi,{})},{id:`history`,label:`History`,icon:ve,content:k(zr,{})},{id:`alarm`,label:`Alarm`,icon:de,content:k(ei,{})}]})})}export{Ki as NotificationsPage,Ki as default};
@@ -1 +0,0 @@
1
- import{Ao as e,Bi as t,Ci as n,Co as r,Do as i,Eo as a,Fi as o,Ii as s,Ji as c,Li as l,Mi as u,Ni as d,Pi as f,Qi as p,Ri as m,Si as h,So as g,T as _,Ti as v,Ur as y,Vi as b,Xi as x,Yi as S,_ as C,_i as w,_o as T,bi as E,ct as D,ds as O,dt as k,fi as A,fs as ee,g as j,gi as M,hi as te,hs as ne,is as N,ji as P,ki as re,ko as ie,lt as ae,mi as oe,ms as se,pi as ce,ps as le,qi as ue,us as de,vi as fe,wo as F,xi as pe,xo as me,yi as he,zi as ge}from"./src-bB3TQU8X.js";import{I as _e,K as ve,Q as I,S as L,T as ye,W as R,b as z,o as B,q as V,x as H,z as U}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{$ as be,V as xe,et as Se}from"./src-Di5BmOTg.js";import{c as Ce,i as we,l as Te,n as W,r as Ee,s as De,t as Oe}from"./NodeInferenceDevices-DciF7oLw.js";import{t as ke}from"./download-BYiYWbFt.js";import{t as Ae}from"./hard-drive-DrH4p5NE.js";import{n as je,r as Me,t as Ne}from"./zap-B_NogjfF.js";import{t as Pe}from"./pencil-Bz_ZrJOa.js";import{t as Fe}from"./plus-C5i2pOFJ.js";import{t as Ie}from"./radio-Db7gl-zS.js";import{t as Le}from"./refresh-cw-CGyy1yV7.js";import{t as Re}from"./search-BFiLJvvR.js";import{t as ze}from"./server-BQv2rJCm.js";import{t as Be}from"./square-check-big-Ga52OEfa.js";import{t as Ve}from"./square-DVLwx5hK.js";import{E as He,I as Ue,J as We,L as Ge,M as Ke,N as qe,P as Je,S as G,T as Ye,W as Xe,i as Ze,j as K,o as Qe,s as $e}from"./index-BQrlv_je.js";import{t as et}from"./AdminPage-Dq33XE9j.js";import{t as tt}from"./useEventInvalidation-BsKdSBfH.js";import{r as nt,t as rt}from"./build-cluster-graph-DyYa_05V.js";import{n as it}from"./format-size-CO9d3C3-.js";import{t as at}from"./NodeAddonsSettingsPanel-BVpPQh6Y.js";var ot=Xe(`ellipsis-vertical`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]]),st=Xe(`flame`,[[`path`,{d:`M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 0 0 2.5 2.5z`,key:`96xj49`}]]),ct=Xe(`pin`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]);I();function lt(e){return e}function ut(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function dt(e,t){return typeof e==`boolean`?e:lt(t)}function ft(e,t){return{pipeline:dt(ut(e,`detect`),t),audio:dt(ut(e,`audio`),t),ingest:dt(ut(e,`ingest`),t)}}function pt(e,t,n){let r=e?.find(e=>e.nodeId===t);return ft(r?.settings,n)}function mt({selectedNodeId:e,onSelect:t,refreshToken:n}){let{data:r}=y(void 0),{data:i}=P(void 0),{data:a}=d(void 0),o=new Map;for(let e of i??[])o.set(e.agentNodeId,(o.get(e.agentNodeId)??0)+1);let s=r??[],c=s.filter(e=>e.isOnline).length,l=s.filter(e=>!e.isOnline).length;return L(`div`,{className:`flex flex-col h-full`,children:[L(`button`,{type:`button`,onClick:()=>t(Cr),className:`flex items-center gap-3 px-4 py-3 border-b border-border text-left transition-colors ${e===`__cluster__`?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[H(Ye,{className:`h-4 w-4 flex-shrink-0`}),L(`div`,{className:`min-w-0 flex-1`,children:[H(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),H(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Balancer + failover + assignments`})]})]}),H(`div`,{className:`flex-1 overflow-y-auto`,children:s.map(n=>{let r=e===n.id,i=o.get(n.id)??0,s=n.isHub?ze:K,c=pt(a,n.id,n.isHub),l=n.isOnline?null:ne(nt(n.lastSeen));return L(`button`,{type:`button`,onClick:()=>t(n.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${r?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}${n.isOnline?``:` opacity-60`}`,children:[H(s,{className:`h-4 w-4 flex-shrink-0`}),L(`div`,{className:`min-w-0 flex-1`,children:[L(`div`,{className:`flex items-center gap-2`,children:[H(`span`,{className:`text-xs font-semibold truncate`,children:n.name}),n.isHub&&H(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!n.isOnline&&H(`span`,{className:`h-1.5 w-1.5 rounded-full bg-destructive flex-shrink-0`}),n.isOnline&&H(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),L(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[L(`span`,{children:[n.cpuCores,` cores`]}),H(`span`,{children:`•`}),L(`span`,{children:[Math.round(n.memoryMB/1024),` GB`]}),i>0&&L(z,{children:[H(`span`,{children:`•`}),L(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[H(je,{className:`h-2.5 w-2.5`}),i]})]}),!n.isOnline&&L(z,{children:[H(`span`,{children:`•`}),L(`span`,{className:`text-destructive`,children:[`offline`,l===null?``:` · ${l}`]})]})]}),L(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[H(N,{variant:c.pipeline?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:c.pipeline?`Pipeline: enabled`:`Pipeline: not enabled (agent capability)`,children:`Pipe`}),H(N,{variant:c.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:c.audio?`Audio: enabled`:`Audio: not enabled (agent capability)`,children:`Aud`})]})]})]},n.id)})}),L(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[L(`span`,{children:[c,` online`]}),l>0&&L(`span`,{className:`text-destructive`,children:[l,` offline`]})]})]})}function ht({nodeId:e,refreshToken:t}){let{data:n}=y(void 0),r=n?.find(t=>t.id===e),i=g(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return r?L(`div`,{className:`px-6 py-4 border-b border-border`,children:[L(`div`,{className:`flex items-center gap-2 mb-1`,children:[H(`h2`,{className:`text-base font-semibold text-foreground`,children:r.name}),r.isOnline?H(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):H(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`}),r.isHub&&H(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),L(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[H(`span`,{children:r.cpuModel??`CPU`}),H(`span`,{children:`•`}),L(`span`,{children:[r.cpuCores,` cores`]}),H(`span`,{children:`•`}),L(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),i&&L(z,{children:[H(`span`,{children:`•`}),L(`span`,{children:[i.attachedCameras,` cameras (`,i.activeCameras,` active)`]}),H(`span`,{children:`•`}),L(`span`,{children:[i.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),H(`span`,{children:`•`}),L(`span`,{children:[`queue `,i.queueDepthTotal]}),i.hardware.hasGpu&&L(z,{children:[H(`span`,{children:`•`}),H(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):H(`div`,{className:`px-6 py-4 border-b border-border`,children:L(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}function gt({refreshToken:e,nodeId:t}){let[r,i]=V(new Map),{nodes:a}=me();F(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t?.deviceId==`number`&&i(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})});let{data:o}=n(void 0),s=R(()=>{let e=new Map;for(let t of o??[])e.set(t.nodeId,t.deviceCount);return e},[o]),c=R(()=>{let e=new Map,t=Date.now()-3e4;for(let n of r.values()){if(n.timestamp<t)continue;let r=n.nodeId??`hub`,i=e.get(r)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};i.attachedCameras++,n.metrics.phase===`active`&&i.activeCameras++,i.totalFps+=n.metrics.actualFps,i.totalInferenceWeighted+=n.metrics.avgInferenceTimeMs,i.queueDepth+=n.metrics.queueDepth,e.set(r,i)}return e},[r]),l=R(()=>{let e=new Map;for(let t of a)e.set(t.id,t.shortName);return e},[a]),u=R(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of c.values())e+=a.attachedCameras,t+=a.activeCameras,n+=a.totalFps,r+=a.totalInferenceWeighted,i+=a.queueDepth;let o=e>0?r/e:0;return{totalAgents:a.length,onlineAgents:a.filter(e=>e.isOnline).length,attachedCameras:e,activeCameras:t,avgInferenceTimeMs:o,queueDepth:i,totalFps:n}},[c,a]);if(t){let e=c.get(t);return L(`div`,{className:`@container/liveload`,children:[H(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),L(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[H(q,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),H(q,{label:`Active / Attached`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),H(q,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),H(q,{label:`Queue`,value:e?String(e.queueDepth):`—`}),H(q,{label:`Audio`,value:String(s.get(t)??`—`)})]})]})}let d=[...c.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return L(`div`,{className:`@container/liveload`,children:[H(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),L(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[H(q,{label:`Total agents`,value:`${u.onlineAgents}/${u.totalAgents}`}),H(q,{label:`Active / Attached`,value:`${u.activeCameras}/${u.attachedCameras}`}),H(q,{label:`Total FPS`,value:u.totalFps.toFixed(1)}),H(q,{label:`Avg inference ms`,value:u.avgInferenceTimeMs.toFixed(0)}),H(q,{label:`Queue depth`,value:String(u.queueDepth)})]}),H(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:L(`table`,{className:`w-full text-xs min-w-[480px]`,children:[H(`thead`,{className:`bg-surface`,children:L(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[H(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),H(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),H(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),H(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),H(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),H(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),L(`tbody`,{children:[d.map(([e,t])=>L(`tr`,{className:`border-t border-border`,children:[H(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:l.get(e)??e}),H(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),H(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),H(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),H(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),H(`td`,{className:`px-3 py-2 text-right text-foreground`,children:s.get(e)??`—`})]},e)),d.length===0&&H(`tr`,{children:H(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function q({label:e,value:t}){return L(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[H(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),H(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}I();var _t={active:!1,pinned:!1,nodeId:null,reason:``},vt=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`],yt={pipeline:K,decoder:He,audio:Me},bt={pipeline:`Pipeline`,decoder:`Decoder`,audio:`Audio`};function xt({mode:e,nodeId:t,compact:n=!1}){if(e===`agent`&&!t)throw Error(`CameraAssignmentsTable: nodeId is required when mode === "agent"`);let r=B(),[i,a]=V(null),[o,s]=V(null),[l,u]=V(new Map);tt([`pipelineOrchestrator`,`getPipelineAssignments`],vt),tt([`pipelineOrchestrator`,`getAudioAssignments`],vt),tt([`pipelineOrchestrator`,`getCameraStatuses`],vt);let{data:d}=P(void 0),{data:f}=h(void 0),{data:p}=v({},{enabled:e===`agent`}),{nodes:m}=me(),{data:g}=De();F(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t.deviceId==`number`&&u(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})}),U(()=>{if(l.size===0)return;let e=setInterval(()=>{u(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[l.size]);let y=R(()=>{let e=new Map;for(let t of g??[])e.set(t.id,t.name);return e},[g]),b=R(()=>{if(e===`agent`){let e=[];for(let n of p??[]){let r=n.assignment,i=(e,n,r)=>({active:e!==null&&e===t,pinned:n,nodeId:e,reason:r??``}),a=i(r.detectionNodeId,r.pinned.detection,r.reasons.detection),o=i(r.decoderNodeId,r.pinned.decoder,r.reasons.decoder),s=i(r.audioNodeId,r.pinned.audio,r.reasons.audio);!a.active&&!o.active&&!s.active||e.push({deviceId:n.deviceId,deviceName:y.get(n.deviceId)??`Device ${n.deviceId}`,pipeline:a,decoder:o,audio:s})}return e.sort((e,t)=>e.deviceId-t.deviceId),e}let n=new Map,r=e=>{let t=n.get(e);if(t)return t;let r={deviceId:e,deviceName:y.get(e)??`Device ${e}`,pipeline:_t,decoder:_t,audio:_t};return n.set(e,r),r};for(let i of d??[]){let a=r(i.deviceId);n.set(i.deviceId,{...a,pipeline:{active:!0,pinned:i.pinned,nodeId:i.agentNodeId,reason:i.reason??``},decoder:{active:e===`cluster`?!0:i.agentNodeId===t,pinned:!1,nodeId:i.agentNodeId,reason:`co-located`}})}for(let e of f??[]){let t=r(e.deviceId);n.set(e.deviceId,{...t,audio:{active:!0,pinned:e.pinned,nodeId:e.nodeId,reason:`capacity`}})}let i=[...n.values()];return i.sort((e,t)=>e.deviceId-t.deviceId),i},[d,f,p,y,e,t]),x=R(()=>(m??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[m]),C=()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},w=E({onSuccess:C}),T=S({onSuccess:C}),D=he({onSuccess:C}),O=c({onSuccess:C}),k=(e,t,n)=>{t===`pipeline`?w.mutate({deviceId:e,agentNodeId:n}):D.mutate({deviceId:e,nodeId:n}),a(null)},A=(e,t)=>{t===`pipeline`?T.mutate({deviceId:e}):O.mutate({deviceId:e}),a(null)};return H(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:L(`table`,{className:`w-full text-xs min-w-[760px] table-fixed`,children:[H(`thead`,{className:`bg-surface`,children:L(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[!n&&H(`th`,{className:`w-10`}),H(`th`,{className:`min-w-[200px] text-left px-3 py-2 align-middle`,children:`Camera`}),e===`cluster`?L(z,{children:[H(`th`,{className:`w-[168px] text-left px-3 py-2 align-middle`,children:`Auto | Pin`}),H(`th`,{className:`w-[188px] text-left px-3 py-2 align-middle`,children:`Resolved placement`})]}):L(z,{children:[H(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Pipeline`}),H(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Decoder`}),H(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Audio`})]}),H(`th`,{className:`w-[132px] text-left px-3 py-2 align-middle`,children:`Status`})]})}),L(`tbody`,{children:[b.map(t=>{let r=l.get(t.deviceId),c=o===t.deviceId;return L(ye.Fragment,{children:[L(`tr`,{className:`border-t border-border align-middle relative`,children:[!n&&H(`td`,{className:`px-2 py-2 align-middle`,children:H(`button`,{type:`button`,onClick:()=>s(c?null:t.deviceId),className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":c?`Collapse broker details`:`Expand broker details`,children:H(c?Ue:Je,{className:`h-3.5 w-3.5`})})}),L(`td`,{className:`px-3 py-2 align-middle min-w-0`,children:[H(`div`,{className:`text-foreground font-medium leading-tight line-clamp-2 break-words`,title:t.deviceName,children:t.deviceName}),L(`div`,{className:`text-[10px] text-foreground-subtle leading-tight`,children:[`#`,t.deviceId]})]}),e===`cluster`?L(z,{children:[H(`td`,{className:`px-3 py-2 align-middle`,children:H(Ct,{state:t.pipeline,onlineNodes:x,pending:w.isPending||T.isPending,onChange:e=>{e===`auto`?A(t.deviceId,`pipeline`):k(t.deviceId,`pipeline`,e)}})}),H(`td`,{className:`px-3 py-2 align-middle`,children:H(wt,{state:t.pipeline,deviceId:t.deviceId})})]}):L(z,{children:[H(Et,{role:`pipeline`,state:t.pipeline,mode:e,deviceId:t.deviceId,onlineNodes:x,isMenuOpen:i?.deviceId===t.deviceId&&i.role===`pipeline`,onToggleMenu:()=>a(i?.deviceId===t.deviceId&&i.role===`pipeline`?null:{deviceId:t.deviceId,role:`pipeline`}),onCloseMenu:()=>a(null),onMove:e=>k(t.deviceId,`pipeline`,e),onUnpin:()=>A(t.deviceId,`pipeline`)}),H(Et,{role:`decoder`,state:t.decoder,mode:e,deviceId:t.deviceId,onlineNodes:x,readOnly:!0,isMenuOpen:!1,onToggleMenu:()=>void 0,onCloseMenu:()=>void 0,onMove:()=>void 0,onUnpin:()=>void 0}),H(Et,{role:`audio`,state:t.audio,mode:e,deviceId:t.deviceId,onlineNodes:x,isMenuOpen:i?.deviceId===t.deviceId&&i.role===`audio`,onToggleMenu:()=>a(i?.deviceId===t.deviceId&&i.role===`audio`?null:{deviceId:t.deviceId,role:`audio`}),onCloseMenu:()=>a(null),onMove:e=>k(t.deviceId,`audio`,e),onUnpin:()=>A(t.deviceId,`audio`)})]}),H(`td`,{className:`px-3 py-2 align-middle`,children:H(At,{snap:r})})]}),c&&!n&&L(`tr`,{className:`bg-surface/50`,children:[H(`td`,{}),L(`td`,{colSpan:e===`cluster`?4:5,className:`px-3 py-2 space-y-3`,children:[t.pipeline.nodeId&&H(St,{deviceId:t.deviceId,nodeId:t.pipeline.nodeId}),H(_,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:t.deviceId,instanceId:`pipeline-row/${t.deviceId}`,config:{variant:`compact`,title:`Stream brokers & clients`}})]})]})]},t.deviceId)}),b.length===0&&H(`tr`,{children:H(`td`,{colSpan:n?e===`cluster`?4:5:e===`cluster`?5:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:e===`agent`?`No cameras assigned to this node`:`No cameras currently assigned`})})]})]})})}function St({deviceId:e,nodeId:t}){let n=B(),{data:r}=re({nodeId:t}),{data:i}=u({deviceId:e}),a=ue({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}}),o=r?.devices??[],s=i?.deviceKey??`auto`,c=s!==`auto`&&!o.some(e=>e.key===s);return L(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[H(`span`,{className:`shrink-0 font-medium text-foreground`,children:`Inference device`}),L(`select`,{value:s,disabled:a.isPending,"aria-label":`Inference device pin`,onChange:t=>a.mutate({deviceId:e,deviceKey:t.target.value}),className:`rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[H(`option`,{value:`auto`,children:`Auto (balanced)`}),c&&L(`option`,{value:s,children:[`Pin → `,s,` (not on this node)`]}),o.map(e=>L(`option`,{value:e.key,children:[`Pin → `,e.key,e.available?``:` (unavailable)`]},e.key))]}),a.isPending&&H(`span`,{className:`text-[10px] opacity-70`,children:`saving…`})]})}function Ct({state:e,onlineNodes:t,pending:n,onChange:r}){let i=e.pinned&&e.nodeId?e.nodeId:`auto`,a=[...new Set([...e.nodeId?[e.nodeId]:[],...t.map(e=>e.id)])];return L(`select`,{value:i,disabled:n,"aria-label":`Pipeline placement pin`,onChange:e=>r(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[H(`option`,{value:`auto`,children:`Auto`}),a.map(e=>L(`option`,{value:e,children:[`Pin → `,t.find(t=>t.id===e)?.name??e]},e))]})}function wt({state:e,deviceId:t}){if(!e.active||!e.nodeId)return H(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`});let n=e.pinned?`pinned · manual`:`auto · ${e.reason||`capacity`}`;return L(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[H(`span`,{className:`font-mono text-[11px] text-foreground truncate`,title:e.nodeId,children:e.nodeId}),H(`span`,{className:`truncate ${e.pinned?`text-amber-400 text-[10px]`:`text-foreground-subtle text-[10px]`}`,title:n,children:n}),H(Tt,{deviceId:t,nodeId:e.nodeId})]})}function Tt({deviceId:e,nodeId:t}){let n=B(),{data:r}=u({deviceId:e},{refetchOnMount:`always`}),{data:i}=re({nodeId:t},{refetchOnMount:`always`}),a=ue({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});if(r===void 0||i===void 0)return H(`span`,{className:`mt-0.5 text-[10px] text-foreground-subtle italic`,children:`device: …`});let o=i.devices??[],s=o.filter(e=>e.enabled),c=r.deviceKey??`auto`,l=c!==`auto`&&!s.some(e=>e.key===c),d=o.find(e=>e.key===c);return L(`select`,{value:c,disabled:a.isPending,"aria-label":`Inference device pin`,onChange:t=>a.mutate({deviceId:e,deviceKey:t.target.value}),className:`mt-0.5 w-full min-w-0 rounded border border-border bg-background px-1 py-0.5 text-[10px] text-foreground disabled:opacity-50`,children:[H(`option`,{value:`auto`,children:`Auto (balanced)`}),l&&L(`option`,{value:c,children:[d?`${W(d).label} (${c})`:c,` (not enabled)`]}),s.map(e=>L(`option`,{value:e.key,children:[W(e).label,` · `,e.format]},e.key))]})}function Et({role:e,state:t,mode:n,onlineNodes:r,readOnly:i=!1,isMenuOpen:a,onToggleMenu:o,onCloseMenu:s,onMove:c,onUnpin:l}){let u=yt[e],d=r.filter(e=>e.id!==(t.nodeId??``)),f=!i&&(t.active||n===`cluster`)&&(d.length>0||t.pinned);return L(`td`,{className:`px-3 py-2 align-middle relative min-w-0`,children:[L(`div`,{className:`flex items-center gap-2 min-w-0`,children:[H(n===`agent`?Dt:Ot,{state:t,Icon:u}),H(`div`,{className:`ml-auto shrink-0`,children:f&&H(`button`,{type:`button`,onClick:o,className:`p-1 rounded hover:bg-surface-hover`,"aria-label":`${bt[e]} actions`,children:H(ot,{className:`h-3 w-3 text-foreground-subtle`})})})]}),a&&f&&H(jt,{title:bt[e],targets:d,pinned:t.pinned,onMove:c,onUnpin:l,onClose:s})]})}function Dt({state:e,Icon:t}){return L(`div`,{className:`flex items-center gap-1.5`,children:[H(e.active?Be:Ve,{className:`h-3.5 w-3.5 ${e.active?`text-success`:`text-foreground-subtle/50`}`}),H(t,{className:`h-3 w-3 ${e.active?`text-foreground-subtle`:`text-foreground-subtle/40`}`}),e.pinned&&H(ct,{className:`h-2.5 w-2.5 text-amber-400`})]})}function Ot({state:e,Icon:t}){return!e.active||!e.nodeId?L(`div`,{className:`flex items-center gap-1.5 text-foreground-subtle/60`,children:[H(t,{className:`h-3 w-3`}),H(`span`,{className:`text-[10px] italic`,children:`—`})]}):L(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[H(t,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),L(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[H(`span`,{className:`font-mono text-[11px] text-foreground truncate`,children:e.nodeId}),H(`span`,{className:`flex items-center gap-1 text-[10px]`,children:e.pinned?L(`span`,{className:`inline-flex items-center gap-0.5 text-amber-400`,children:[H(ct,{className:`h-2.5 w-2.5`}),` manual`]}):L(`span`,{className:`text-foreground-subtle truncate`,children:[`auto · `,e.reason||`capacity`]})})]})]})}var kt=`min-h-[3.25rem]`;function At({snap:e}){if(!e)return H(`div`,{className:`flex items-center ${kt}`,children:H(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`})});let{phase:t,actualFps:n,avgInferenceTimeMs:r,queueDepth:i,configuredFps:a,droppedFrames:o}=e.metrics,s=de(t);return L(`div`,{className:`flex flex-col justify-center gap-0.5 font-mono text-[10px] tabular-nums leading-tight min-w-0 ${kt}`,children:[L(`span`,{className:`inline-flex items-center gap-1 min-w-0 ${s.textColor}`,children:[H(C,{phase:t,className:`h-2.5 w-2.5 shrink-0`}),H(`span`,{className:`font-semibold uppercase tracking-wider truncate`,children:s.label})]}),L(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[H(`span`,{className:`text-foreground`,children:n.toFixed(1)}),L(`span`,{children:[`/`,a.toFixed(0),` fps`]})]}),L(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[H(`span`,{className:`text-foreground`,children:r.toFixed(0)}),H(`span`,{children:` ms`}),i>0&&L(`span`,{className:`text-warning ml-1`,children:[`q`,i]})]}),L(`span`,{className:`whitespace-nowrap truncate ${o>0?`text-warning`:`text-foreground-subtle`}`,children:[`drops `,H(`span`,{className:`text-foreground`,children:o})]})]})}function jt({title:e,targets:t,pinned:n,onMove:r,onUnpin:i,onClose:a}){let o=ve(null);return U(()=>{let e=e=>{o.current?.contains(e.target)||a()};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[a]),L(`div`,{ref:o,className:`absolute right-2 top-full mt-1 w-48 rounded-lg border border-border bg-surface shadow-lg z-20 text-left`,children:[H(`div`,{className:`px-3 py-1 text-[9px] uppercase tracking-wider text-foreground-subtle border-b border-border`,children:e}),t.length>0&&H(`div`,{className:`py-1`,children:t.map(e=>L(`button`,{type:`button`,onClick:()=>r(e.id),className:`block w-full text-left px-3 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[`Move to `,e.name]},e.id))}),n&&L(`button`,{type:`button`,onClick:i,className:`block w-full text-left px-3 py-1.5 text-[11px] text-destructive hover:bg-destructive/10 border-t border-border`,children:[`Unpin `,e.toLowerCase()]}),t.length===0&&!n&&H(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle italic`,children:`Already auto · no other nodes online`})]})}function Mt({nodeId:e,refreshToken:t}){return L(`div`,{className:`space-y-6`,children:[H(gt,{refreshToken:t,nodeId:e}),L(`div`,{children:[H(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Cameras on this node`}),L(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Checkboxes mark the roles currently running on `,e,`. Use the kebab to move a role to another node or unpin it; live KPIs come from the runner snapshot stream.`]})]}),H(xt,{mode:`agent`,nodeId:e,compact:!0})]})}I();function Nt(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function Pt({nodeId:e,refreshToken:t}){let n=B(),i=w({onSettled:()=>{n.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:a}=fe({nodeId:e}),o=g(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??a??null,s=o===null;tt([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:c}=p({nodeId:e}),{values:l}=r(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),u=R(()=>l.filter(e=>e.metrics.phase===`active`).length,[l]),d=t=>{let n=c??[];n.length>0&&!window.confirm(`${n.length} camera(s) are dispatching through this engine. Killing it forces a respawn on the next frame. Continue?`)||i.mutate({nodeId:e,engine:t,force:n.length>0})};return L(`div`,{className:`space-y-6`,children:[L(`div`,{children:[H(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),L(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(o??[]).length,` engine(s) resident in RAM. `,(c??[]).length,` `,`camera(s) attached, `,u,` actively dispatching frames. Refreshes every 5s.`]})]}),H(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:L(`table`,{className:`w-full text-xs min-w-[640px]`,children:[H(`thead`,{className:`bg-surface`,children:L(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[H(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),H(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),H(`th`,{className:`text-left px-3 py-2`,children:`Models`}),H(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),H(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),H(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),H(`th`,{className:`w-20`})]})}),L(`tbody`,{children:[s&&H(`tr`,{children:H(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!s&&(o??[]).map(e=>{let t=e.kind===`warm-override`,n=e.kind===`device-pool`;return L(`tr`,{className:`border-t border-border ${t?`bg-amber-500/5`:n?`bg-primary/[0.05]`:``}`,children:[H(`td`,{className:`px-3 py-2`,children:L(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-medium ${t?`bg-amber-500/15 text-amber-400`:n?`bg-primary/15 text-primary`:`bg-success/15 text-success`}`,children:[H(t?st:n?Te:K,{className:`h-3 w-3`}),t?`warm`:n?`pool`:`runtime`]})}),H(`td`,{className:`px-3 py-2`,children:L(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[H(Ne,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),H(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?H(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):H(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>H(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),H(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),H(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?H(`span`,{className:`text-foreground-subtle`,children:Nt(e.idleMs,e.idleTtlMs)}):H(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),H(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t?`—`:(c??[]).length}),H(`td`,{className:`px-3 py-2 text-right`,children:n?H(`span`,{className:`text-[11px] text-foreground-subtle`,children:`auto`}):L(`button`,{type:`button`,disabled:i.isPending,onClick:()=>d(e.engine),className:`inline-flex items-center gap-1 px-2 py-1 rounded border border-destructive/30 text-destructive text-[11px] hover:bg-destructive/10 disabled:opacity-50`,children:[H($e,{className:`h-3 w-3`}),`Kill`]})})]},e.engineKey)}),!s&&(o??[]).length===0&&H(`tr`,{children:H(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No engines resident — the factory spins up on the first pipeline run.`})})]})]})}),L(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[H(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,H(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`,` `,H(`strong`,{className:`text-foreground`,children:`pool`}),`: a per-device balanced inference pool (one per enabled accelerator, running concurrently); reaper-managed on its own idle TTL.`]}),i.isError&&L(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,i.error instanceof Error?i.error.message:`unknown`]})]})}I();var Ft=new Set(xe);function It(e){return Ft.has(e)}function Lt(e,t,n){return`${e}/${t}/${n}`}function Rt(e){return{coreml:`CoreML`,openvino:`OpenVINO`,onnx:`ONNX`}[e.format]??e.format.toUpperCase()}function zt(e){return{coreml:`Apple Neural Engine / GPU — .mlpackage`,openvino:`Intel CPU / GPU / NPU — .xml`,onnx:`CPU, CUDA, Node.js — .onnx`}[e.format]??`.${e.format}`}function J(e){return e.format}function Bt(e,t){let n=0,r=0,i=0;for(let a of e)for(let e of a.addons)for(let a of e.models){let e=a.formats[t];e&&(n++,e.downloaded&&(r++,i+=e.sizeMB))}return{total:n,downloaded:r,downloadedSizeMB:i}}function Vt({addonId:e,model:t,format:n,isActive:r,progress:i,errorMsg:a,onDownload:o,onDelete:s}){let c=t.formats[n];return c?L(`div`,{className:`flex items-center gap-3 px-4 py-3 border-b border-border/50 last:border-b-0 hover:bg-surface-hover/30 transition-colors`,children:[H(`div`,{className:`h-2 w-2 rounded-full shrink-0 ${c.downloaded?`bg-success`:`bg-foreground-subtle/30`}`}),L(`div`,{className:`flex-1 min-w-0`,children:[L(`div`,{className:`flex items-center gap-2`,children:[H(`span`,{className:`text-sm font-medium text-foreground`,children:t.name}),L(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`(`,t.id,`)`]})]}),i&&i.progress>=0&&i.progress<100&&L(`div`,{className:`mt-1.5 flex items-center gap-2 max-w-xs`,children:[H(`div`,{className:`flex-1 h-1 bg-surface-hover rounded-full overflow-hidden`,children:H(`div`,{className:`bg-primary h-full rounded-full transition-all duration-300`,style:{width:`${i.progress}%`}})}),L(`span`,{className:`text-[9px] text-primary font-mono tabular-nums shrink-0`,children:[Math.round(i.progress),`%`]})]})]}),H(`span`,{className:`text-xs text-foreground-subtle tabular-nums shrink-0`,children:it(c.sizeMB)}),a&&L(`span`,{className:`flex items-center gap-1 text-[10px] text-danger max-w-[160px] truncate shrink-0`,title:a,children:[H(qe,{className:`h-3 w-3 shrink-0`}),a]}),c.downloaded?L(`button`,{onClick:s,disabled:r,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md border border-danger/30 text-danger hover:bg-danger/10 disabled:opacity-50 transition-colors shrink-0`,children:[r?H(G,{className:`h-3 w-3 animate-spin`}):H($e,{className:`h-3 w-3`}),r?`Deleting...`:`Delete`]}):L(`button`,{onClick:o,disabled:r,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors shrink-0`,children:[r?H(G,{className:`h-3 w-3 animate-spin`}):H(ke,{className:`h-3 w-3`}),r?`Downloading...`:`Download`]})]}):null}function Ht({engines:e,activeEngine:t,viewEngine:n,onSelect:r}){let[i,a]=V(!1);return L(`div`,{className:`relative`,children:[L(`button`,{type:`button`,onClick:()=>a(!i),className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-4 py-2.5 w-full text-left hover:bg-surface-hover transition-colors`,children:[H(K,{className:`h-4 w-4 text-primary shrink-0`}),L(`div`,{className:`flex-1 min-w-0`,children:[L(`div`,{className:`flex items-center gap-2`,children:[H(`span`,{className:`text-sm font-medium text-foreground`,children:Rt(n)}),J(n)===J(t)&&H(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),H(`div`,{className:`text-[10px] text-foreground-subtle`,children:zt(n)})]}),H(Ue,{className:`h-4 w-4 text-foreground-subtle transition-transform ${i?`rotate-180`:``}`})]}),i&&H(`div`,{className:`absolute top-full left-0 right-0 mt-1 rounded-lg border border-border bg-surface shadow-lg z-50 overflow-hidden`,children:e.map(e=>{let i=J(e)===J(n),o=J(e)===J(t);return L(`button`,{type:`button`,onClick:()=>{r(e),a(!1)},className:`flex items-center gap-3 px-4 py-2.5 w-full text-left transition-colors ${i?`bg-primary/5`:`hover:bg-surface-hover`}`,children:[H(K,{className:`h-4 w-4 shrink-0 ${i?`text-primary`:`text-foreground-subtle`}`}),L(`div`,{className:`flex-1`,children:[L(`div`,{className:`flex items-center gap-2`,children:[H(`span`,{className:`text-sm font-medium ${i?`text-primary`:`text-foreground`}`,children:Rt(e)}),o&&H(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),H(`div`,{className:`text-[10px] text-foreground-subtle`,children:zt(e)})]}),i&&H(Ke,{className:`h-4 w-4 text-primary shrink-0`})]},J(e))})})]})}function Ut({embedded:e=!1,nodeId:t}={}){let n=B(),r=t??`hub`,[i,a]=V(null),[o,s]=V(new Set),[c,l]=V(new Map),[u,d]=V(new Map),[f,p]=V(``),{data:m=[]}=oe({nodeId:r}),h=m.filter((e,t,n)=>n.findIndex(t=>t.format===e.format)===t),{data:g}=M({nodeId:r}),_=g,{data:v,isLoading:y}=te({nodeId:r}),b=ce(),x=A();F(`model.download.progress`,e=>{let t=e.data,r=typeof t.modelId==`string`?t.modelId:void 0,i=typeof t.progress==`number`?t.progress:void 0,a=typeof t.totalMB==`number`?t.totalMB:0;r===void 0||i===void 0||(l(e=>{let t=new Map(e);return i===100||i===-1?t.delete(r):t.set(r,{modelId:r,progress:i,totalMB:a}),t}),i===100&&n.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]}))});let S=_??{runtime:`node`,backend:`cpu`,format:`onnx`},C=h.find(e=>e.format===i)??S,w=C.format,T=e=>e.formats[w]?.downloaded===!0,E=v?.slots??[],D=E.map(e=>({...e,addons:e.addons.map(e=>({...e,models:se(e.models,w)})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0),O=Bt(D,w),k=_e(async(e,t,i)=>{if(!It(i))return;let a=Lt(e,t,i);s(e=>new Set([...e,a])),d(e=>{let t=new Map(e);return t.delete(a),t});try{await b.mutateAsync({addonId:e,modelId:t,format:i,nodeId:r}),n.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){d(t=>new Map([...t,[a,e instanceof Error?e.message:`Download failed`]]))}finally{s(e=>{let t=new Set(e);return t.delete(a),t})}},[b,n,r]),ee=_e(async(e,t,i)=>{if(!It(i))return;let a=Lt(e,t,i);s(e=>new Set([...e,a])),d(e=>{let t=new Map(e);return t.delete(a),t});try{await x.mutateAsync({addonId:e,modelId:t,format:i,nodeId:r}),n.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){d(t=>new Map([...t,[a,e instanceof Error?e.message:`Delete failed`]]))}finally{s(e=>{let t=new Set(e);return t.delete(a),t})}},[x,n,r]),j=_e(e=>{a(e.format)},[]),ne=f.trim()?D.map(e=>({...e,addons:e.addons.map(e=>({...e,models:e.models.filter(t=>t.name.toLowerCase().includes(f.toLowerCase())||t.id.toLowerCase().includes(f.toLowerCase())||e.name.toLowerCase().includes(f.toLowerCase()))})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0):D,N=L(z,{children:[y&&H(`div`,{className:`flex items-center justify-center py-16`,children:H(G,{className:`h-5 w-5 animate-spin text-foreground-subtle`})}),!y&&E.length===0&&L(`div`,{className:`flex flex-col items-center justify-center py-16 text-foreground-subtle`,children:[H(Ae,{className:`h-8 w-8 mb-3 opacity-30`}),H(`span`,{className:`text-sm`,children:`No pipeline steps available`}),H(`span`,{className:`text-xs mt-1`,children:`Configure the detection pipeline to see available models.`})]}),!y&&E.length>0&&L(z,{children:[H(Ht,{engines:h,activeEngine:S,viewEngine:C,onSelect:j}),L(`div`,{className:`flex items-center gap-4 text-xs text-foreground-subtle`,children:[L(`span`,{children:[H(`span`,{className:`font-semibold text-foreground tabular-nums`,children:O.total}),H(`span`,{className:`ml-1`,children:`compatible models`})]}),H(`span`,{className:`text-border`,children:`|`}),L(`span`,{children:[H(`span`,{className:`font-semibold text-success tabular-nums`,children:O.downloaded}),H(`span`,{className:`ml-1`,children:`downloaded`})]}),H(`span`,{className:`text-border`,children:`|`}),L(`span`,{className:`tabular-nums`,children:[it(O.downloadedSizeMB),H(`span`,{className:`ml-1`,children:`on disk`})]})]}),O.total>5&&L(`div`,{className:`relative`,children:[H(Re,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),H(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:`Search models...`,className:`w-full pl-9 pr-3 py-2 text-sm rounded-lg border border-border bg-surface text-foreground placeholder:text-foreground-subtle/50 focus:outline-none focus:ring-1 focus:ring-primary`})]}),ne.map(e=>{let t=e.addons.reduce((e,t)=>e+t.models.length,0),n=e.addons.reduce((e,t)=>e+se(t.models,w).filter(T).length,0);return L(`div`,{children:[L(`div`,{className:`flex items-center gap-2 mb-2`,children:[H(`h2`,{className:`text-sm font-semibold text-foreground`,children:e.label}),H(`div`,{className:`flex-1 h-px bg-border`}),L(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[n,`/`,t]})]}),H(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:e.addons.map(e=>e.models.map(t=>{let n=Lt(e.id,t.id,w);return H(Vt,{addonId:e.id,model:t,format:w,isActive:o.has(n),progress:c.get(t.id),errorMsg:u.get(n),onDownload:()=>k(e.id,t.id,w),onDelete:()=>ee(e.id,t.id,w)},`${e.id}/${t.id}`)}))})]},e.id)}),ne.length===0&&H(`div`,{className:`text-center py-8 text-sm text-foreground-subtle`,children:f.trim()?L(z,{children:[`No models matching “`,f,`”`]}):L(z,{children:[`No models available for `,Rt(C),` format`]})})]})]});return e?H(`div`,{className:`space-y-4`,children:N}):H(et,{children:N})}function Wt({nodeId:e,refreshToken:t}){return H(Ut,{embedded:!0,nodeId:e})}var Gt=`pipeline-runner`,Kt=200;function qt({nodeId:e}){return L(`div`,{className:`flex flex-col gap-3`,children:[L(`div`,{children:[H(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Runner logs`}),L(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`pipeline-runner activity on `,e,` — camera attach/detach, engine phases and pipeline errors. Streaming live; the device chip on a line tells which camera it refers to.`]})]}),H(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:H(j,{agentId:e,addonId:Gt,limit:Kt,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}I(),I();function Jt({nodeId:e,title:t}){let{data:n}=De(),{data:r}=P(void 0),i=R(()=>{let e=new Map;for(let t of n??[])e.set(t.id,t.name);return e},[n]),a=R(()=>{if(!e)return null;let t=new Set;for(let n of r??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,r]),[o,s]=V(new Map);F(`pipeline.camera-metrics-snapshot`,t=>{let n=t.data;typeof n.deviceId==`number`&&(e&&n.nodeId!==e||s(e=>{let t=new Map(e);return t.set(n.deviceId,n),t}))}),U(()=>{if(o.size===0)return;let e=setInterval(()=>{s(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[o.size]);let c=R(()=>{let e=[];for(let t of o.values())a&&!a.has(t.deviceId)||e.push(t);return e.sort((e,t)=>e.deviceId-t.deviceId),e},[o,a]);return c.length===0?L(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-[11px] text-foreground-subtle italic`,children:[t??`Cameras`,`: no live snapshots yet`]}):L(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[L(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[H(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),H(`span`,{className:`text-[10px] text-foreground-subtle`,children:c.length})]}),H(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map(e=>{let t=i.get(e.deviceId)??`#${e.deviceId}`,n=de(e.metrics.phase);return L(`div`,{title:`${t} · ${n.label} · ${e.metrics.actualFps.toFixed(1)} fps · ${e.metrics.avgInferenceTimeMs.toFixed(0)}ms infer · q=${e.metrics.queueDepth}`,className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] ${n.badgeClass}`,children:[H(C,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),H(`span`,{className:`font-medium text-foreground/90 max-w-[220px] truncate`,children:t}),H(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),H(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}I();function Yt(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 Xt(e){if(!e)return null;let t=e.modelId!==void 0&&e.modelId!==``?e.modelId:void 0,n=e.settings&&Object.keys(e.settings).length>0?e.settings:void 0;return t===void 0&&n===void 0?null:{...t===void 0?{}:{modelId:t},...n===void 0?{}:{settings:n}}}function Zt({nodeId:n,refreshToken:r}){let o=B(),[s,c]=V(null),[l,u]=V(null),[d,f]=V(``),[p,m]=V(null),h=re({nodeId:n},{refetchOnMount:`always`}),g=te({nodeId:n},{refetchOnMount:`always`}),_=h.data?.devices??[],v=t({onSuccess:()=>{o.invalidateQueries({queryKey:[`pipelineOrchestrator`,`getNodeInferenceDevices`]})}}),y=R(()=>g.data?ie(g.data):[],[g.data]),b=R(()=>_.map(e=>({agentNodeId:n,engineLabel:e.format,deviceKey:e.key,deviceLabel:W(e).label})),[_,n]),x=e=>_.find(t=>t.key===e)??null,S=R(()=>_.filter(e=>e.enabled),[_]),C=S.length>=2,w=(e,t)=>le(Yt(g.data??null,e)?.models??[],t?.format),T=e=>{let t=x(e);return t?W(t).label:e},E=(e,t)=>S.filter(n=>n.key!==t&&w(e,n)).toSorted((e,t)=>e.key<t.key?-1:+(e.key>t.key))[0]??null,D=e=>{let t=Yt(g.data??null,e)?.enabledByDefault??!0;return{kind:`gate`,effectiveOn:t,defaultOn:t,explicit:!1}},k=(e,t)=>{let n=Yt(g.data??null,e);if(n)return O(n,t)},A=(e,t)=>{let n=D(e),r=n.kind===`gate`?n.effectiveOn:!1,i=Yt(g.data??null,e),a=t.deviceKey===void 0?null:x(t.deviceKey),o=le(i?.models??[],a?.format),s=a?.steps?.[e];if(!o){if(!r)return{kind:`na`};let n=s?.jumpDeviceKey,i=n!==void 0&&S.some(e=>e.key===n)?n:t.deviceKey===void 0?void 0:E(e,t.deviceKey)?.key;return i===void 0?{kind:`skip`}:{kind:`skip`,jumpTo:T(i)}}return{kind:`enabled`,modelId:(i?ee({catalog:i,device:a,base:s?.modelId}):void 0)??`Auto`,...s?.jumpDeviceKey!==void 0&&S.some(e=>e.key===s.jumpDeviceKey)?{jumpTo:T(s.jumpDeviceKey)}:{}}},j=s&&g.data?Yt(g.data,s.addonId):null,M=s?x(s.deviceKey):null,ne=M?.format??`coreml`,N=s?k(s.addonId,M):void 0,P=()=>{c(null),u(null),f(``)},ae=(e,t)=>{if(t.deviceKey===void 0)return;let n=x(t.deviceKey)?.steps?.[e];c({addonId:e,deviceKey:t.deviceKey}),u({enabled:!0,...n?.modelId===void 0?{}:{modelId:n.modelId},settings:n?.settings??{}}),f(n?.jumpDeviceKey??``)},oe=()=>{if(!s)return;let e=Xt(l),t=d!==``&&d!==s.deviceKey?d:void 0,r=e||t!==void 0?{...e,...t===void 0?{}:{jumpDeviceKey:t}}:null,i=_.map(e=>{let t={...e.steps};return e.key===s.deviceKey&&(r?t[s.addonId]=r:delete t[s.addonId]),{key:e.key,enabled:e.key===s.deviceKey?!0:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:t}});v.mutate({agentNodeId:n,inferenceDevices:we(i)},{onSuccess:P})};if(h.isLoading||g.isLoading)return H(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(_.length===0)return H(`div`,{className:`rounded-md border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No inference devices reported by this node's platform probe.`});if(!g.data)return H(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let se=s!==null&&j!==null&&M!==null;return L(`div`,{className:`relative h-full w-full space-y-3`,children:[L(`div`,{className:`rounded-md border border-border bg-muted/20 px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[`Each column is one of this node's inference accelerators. A cell shows the`,` `,H(`span`,{className:`font-medium text-foreground`,children:`base model`}),` every camera landing on that accelerator runs; click to change it. Whether a camera runs a step is set per-camera on that camera's Detection pipeline tab — there is no gate here.`]}),H(`div`,{className:se?`md:pr-[360px]`:``,children:y.length>0?H(a,{tree:y,agents:b,gateFor:D,getCellState:A,onCellClick:ae,selectedCell:s?{addonId:s.addonId,agentNodeId:n,deviceKey:s.deviceKey}:null,onSetGate:()=>{},fallbackNodeId:p,onFallbackNodeChange:m,hideGate:!0}):H(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),H(e,{open:se,onClose:P,title:j?.name??``,subtitle:s&&M?`${n} · ${W(M).label} · ${M.format}`:``,footer:L(z,{children:[H(`div`,{className:`flex-1`}),H(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:P,children:`Cancel`}),H(`button`,{type:`button`,disabled:!s||!l||v.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:oe,children:v.isPending?`Saving…`:`Save`})]}),children:j&&s&&l?L(`div`,{className:`space-y-3`,children:[C&&L(`div`,{className:`rounded-md border border-border bg-muted/10 px-3 py-2 space-y-1`,children:[H(`label`,{className:`block text-[11px] font-medium text-foreground`,children:`Run on`}),L(`select`,{className:`w-full rounded border border-border bg-surface px-2 py-1 text-xs`,value:d,onChange:e=>f(e.target.value),children:[H(`option`,{value:``,children:`Auto (this device, or auto-jump if unsupported)`}),S.filter(e=>e.key!==s.deviceKey).map(e=>L(`option`,{value:e.key,children:[W(e).label,` · `,e.format]},e.key))]}),H(`p`,{className:`text-[10px] leading-snug text-foreground-subtle`,children:`Route this step (and its child steps) to another accelerator on this node.`})]}),H(i,{mode:`agent`,addon:j,agentDefault:l,agentNodeId:n,engineFormat:ne,effectiveModelId:N,onChangeAgentConfig:u})]}):H(`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.`})})]})}I();var Qt=[`pipeline-orchestrator`],$t=[`decoder`],en=!1;function tn({nodeId:e,refreshToken:t}){let n=T(),[r,i]=V(null),[a,o]=V(null),c=(y(void 0).data??[]).find(t=>t.id===e),l=c?.name??e,u=c?.isOnline??!1,d=s({onSuccess:e=>{o(e.effectiveModelId===null?`Reset done — model config cleared (node offline: effective model resolves on reconnect)`:`Reset done — effective detection model: ${e.effectiveModelId} (Auto)`)}}),f=async()=>{await n({title:`Reset ${l} to hardware-aware defaults?`,message:`This clears every per-device model default on this node (back to the format default) and every per-camera step override scoped to it. Existing per-camera customisations on this node are lost.`,confirmLabel:`Reset`,variant:`danger`})&&(o(null),d.mutate({agentNodeId:e}))};return L(`div`,{className:`relative h-full w-full space-y-3`,children:[L(`div`,{className:`flex items-center justify-end gap-2 text-xs`,children:[a&&H(`span`,{className:`text-emerald-400`,children:a}),d.isError&&H(`span`,{className:`text-red-400`,children:d.error instanceof Error?d.error.message:`Reset failed`}),H(`button`,{type:`button`,onClick:()=>{f()},disabled:d.isPending,className:`rounded border border-amber-500/40 bg-surface px-2 py-0.5 text-amber-300 hover:bg-surface-hover disabled:opacity-50`,title:`Clear this node's per-device model defaults + per-camera overrides scoped to this node`,children:d.isPending?`Resetting…`:`Reset to default`})]}),H(Jt,{nodeId:e}),H(at,{nodeId:e,addonIds:Qt,level:`global`,sectionIds:$t}),en,en,L(`div`,{children:[H(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices — default model per accelerator`}),H(Oe,{nodeId:e,nodeName:l,isOnline:u})]}),L(`div`,{children:[H(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection steps — model per accelerator`}),H(Zt,{nodeId:e,refreshToken:t})]})]})}var nn=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],rn=`decoder-nodeav`;function an({nodeId:e,refreshToken:t}){let{data:n}=y(void 0),r=n?.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.id??rn,i=[...nn,r];return L(`div`,{className:`flex flex-col h-full`,children:[H(ht,{nodeId:e,refreshToken:t}),H(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-6`,children:H(at,{nodeId:e,addonIds:i,level:`global`,extraTabs:[{id:`assignments`,label:`Assignments`,order:-10,content:H(Mt,{nodeId:e,refreshToken:t})},{id:`tree`,label:`Pipeline`,order:39,content:H(tn,{nodeId:e,refreshToken:t})},{id:`engines`,label:`Warm instances`,order:180,content:H(Pt,{nodeId:e,refreshToken:t})},{id:`models`,label:`Models`,order:200,content:H(Wt,{nodeId:e,refreshToken:t})},{id:`logs`,label:`Logs`,order:300,content:H(qt,{nodeId:e})}]})})]})}function on(){return L(`div`,{className:`space-y-6`,children:[H(Jt,{title:`Cluster cameras`}),L(`div`,{className:`min-w-0`,children:[H(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Placement matrix`}),H(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Pipeline · audio assignments per camera (decode always runs co-located with the pipeline). Use the Auto | Pin control to pin a camera to a node, the inference-device select to pin it to an accelerator, or the kebab to move a role; expand the chevron for the per-camera broker drill-down. Cluster load, inference-device weights, and Rebalance live on the Balancer tab.`})]}),H(xt,{mode:`cluster`})]})}var sn=`pipeline-orchestrator`,cn=`recorder`,ln=`recordingNodeId`,un=[`ingestNode`,`recordingNode`,`audioNode`,`motionNode`],dn=[{key:`detect`,label:`Detect`,hint:`Runs the detection pipeline (decode + inference) for assigned cameras`}];function fn(e,t){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t)return e.value}function pn(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function mn(e,t,n){let r=fn(e,t);return typeof r==`string`&&r.length>0?r:n}function hn(e,t,n){let r=fn(e,t);return typeof r==`number`&&Number.isFinite(r)?r:n}function gn(e,t){let n=pn(e,t);return typeof n==`number`&&Number.isFinite(n)?n:null}function _n(e,t){let n=pn(e,t);return typeof n==`string`&&n.length>0?n:null}function vn(e){return e===`ingestNode`?`Ingest`:e===`recordingNode`?`Recording`:e===`audioNode`?`Audio`:`Motion Node`}function yn(e){return e===`ingestNode`?`Node that terminates default camera ingest`:e===`recordingNode`?`Node that owns the recorder (recording-node)`:e===`audioNode`?`Node that runs singleton audio work`:`Runs software (analyzer) motion-watch. Onboard cameras are unaffected.`}function bn(e,t){switch(t){case`detect`:return e.pipeline}}function xn(e){return e instanceof Error?e.message:`Failed to save`}function Sn(e){e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAgentSettings`]]}),e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}function Cn({capability:e,label:t,hint:n,nodeId:r,active:i,pending:a,layout:o,onToggle:s}){let c=i?`border-success/30 bg-success/15 text-success hover:bg-success/25`:`border-border bg-surface-hover text-foreground-subtle hover:bg-surface hover:text-foreground`,l=o===`card`?`w-full justify-center px-3 py-2 text-xs`:`px-2.5 py-1 text-[11px]`,u=i?Ge:Ce;return L(`button`,{type:`button`,role:`switch`,"aria-checked":i,"aria-label":`${t} capability for ${r}`,title:`${t} — ${n}`,disabled:a,onClick:()=>s(e,!i),className:`inline-flex items-center gap-1.5 rounded-full border font-medium transition-colors disabled:opacity-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 ${c} ${l}`,children:[H(u,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":`true`}),H(`span`,{children:t})]})}function wn({node:e,emphasis:t=!1}){let n=e.isHub?ze:K;return L(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[H(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),H(n,{className:`h-4 w-4 shrink-0 text-foreground-subtle`,"aria-hidden":`true`}),L(`div`,{className:`min-w-0`,children:[L(`div`,{className:`flex items-center gap-1.5 ${t?`text-sm`:`text-xs`} font-semibold text-foreground`,children:[H(`span`,{className:`truncate`,children:e.name}),e.isHub&&H(N,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`hub`}),!e.isOnline&&H(N,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`offline`})]}),H(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:e.id})]})]})}I();function Tn({nodeId:e,value:t,detectedHosts:n,status:r,errorMessage:i,onCommit:a}){let[o,s]=V(t??``);U(()=>{s(t??``)},[t]);let c=n[0],l=c===void 0?`auto-detect`:`auto: ${c}`,u=r===`pending`,d=o.trim(),f=d!==(t??``),p=f&&!u,m=()=>{p&&a(e,d.length>0?d:null)};return L(`div`,{className:`flex items-center gap-1.5`,children:[H(`input`,{"aria-label":`Reachable host for ${e}`,type:`text`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:l,value:o,disabled:u,onChange:e=>s(e.target.value),onBlur:m,onKeyDown:e=>{e.key===`Enter`&&m(),e.key===`Escape`&&s(t??``)},className:`w-40 rounded-md border border-border bg-background px-2.5 py-1.5 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none disabled:opacity-50`}),L(`button`,{type:`button`,onClick:m,disabled:!p,"aria-label":`Save reachable host for ${e}`,title:`Save reachable host`,className:`inline-flex shrink-0 items-center gap-1 rounded-md px-2 py-1.5 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-40 disabled:cursor-not-allowed`,children:[u?H(G,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):H(Ge,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),!f&&!u&&r===`success`&&H(Ge,{className:`h-3.5 w-3.5 shrink-0 text-emerald-400`,"aria-label":`Saved`,role:`img`}),r===`error`&&H(`span`,{title:i??`Failed to save reachable host`,children:H(qe,{className:`h-3.5 w-3.5 shrink-0 text-red-400`,"aria-label":i??`Failed to save reachable host`,role:`img`})})]})}function En({label:e,children:t}){return L(`div`,{className:`flex items-center justify-between gap-3`,children:[H(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-foreground-subtle`,children:e}),t]})}function Dn({node:e,actions:t}){return L(`div`,{className:`rounded-xl border border-border bg-background p-4 space-y-4 ${e.isOnline?``:`opacity-60`}`,children:[H(wn,{node:e,emphasis:!0}),H(`div`,{className:`grid grid-cols-2 gap-2`,children:dn.map(n=>H(Cn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:bn(e.effective,n.key),pending:t.capabilityPending,layout:`card`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)},n.key))}),H(`div`,{className:`space-y-3 border-t border-border pt-3`,children:H(En,{label:`Reachable host`,children:H(Tn,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})})})]})}function On(){return L(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[10px] text-foreground-subtle`,children:[L(`span`,{className:`inline-flex items-center gap-1.5`,children:[H(`span`,{className:`h-2.5 w-2.5 rounded-full border border-success/30 bg-success/15`}),`Active capability`]}),L(`span`,{className:`inline-flex items-center gap-1.5`,children:[H(`span`,{className:`h-2.5 w-2.5 rounded-full border border-border bg-surface-hover`}),`Idle`]}),L(`span`,{className:`inline-flex items-center gap-1.5`,children:[H(`span`,{className:`h-2 w-2 rounded-full bg-success`}),`Node online`]}),L(`span`,{className:`inline-flex items-center gap-1.5`,children:[H(`span`,{className:`h-2 w-2 rounded-full bg-danger`}),`Node offline`]})]})}function kn({nodes:e,actions:t}){return H(`div`,{className:`overflow-x-auto rounded-lg border border-border`,children:L(`table`,{className:`w-full min-w-[720px] border-collapse text-sm`,children:[H(`thead`,{children:L(`tr`,{className:`border-b border-border bg-background text-[10px] uppercase tracking-wider text-foreground-subtle`,children:[H(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Node`}),dn.map(e=>H(`th`,{className:`px-3 py-3 text-center font-semibold`,children:e.label},e.key)),H(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Reachable host`})]})}),H(`tbody`,{children:e.map(e=>L(`tr`,{className:`border-b border-border last:border-b-0 transition-colors hover:bg-surface-hover/40 ${e.isOnline?``:`opacity-60`}`,children:[H(`td`,{className:`px-4 py-3 align-middle`,children:H(wn,{node:e})}),dn.map(n=>H(`td`,{className:`px-3 py-3 text-center align-middle`,children:H(Cn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:bn(e.effective,n.key),pending:t.capabilityPending,layout:`cell`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)})},n.key)),H(`td`,{className:`px-4 py-3 align-middle`,children:H(Tn,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})})]},e.id))})]})})}function An({role:e,value:t,options:n,pending:r,onChange:i}){return L(`label`,{className:`flex flex-col gap-1.5 rounded-lg border border-border bg-background p-3`,children:[H(`span`,{className:`text-xs font-semibold text-foreground`,children:vn(e)}),H(`select`,{value:t,disabled:r,onChange:t=>i(e,t.target.value),className:`rounded-md border border-border bg-surface px-2.5 py-1.5 text-sm text-foreground focus:border-primary focus:outline-none disabled:opacity-50`,children:n.map(e=>H(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),H(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:yn(e)})]})}function jn({roleValues:e,options:t,pending:n,lowFpsEnabled:r,fpsMinThreshold:i,onRoleChange:a,onLowFpsToggle:o}){return L(`div`,{className:`grid gap-3 @lg/clustertab:grid-cols-2 @3xl/clustertab:grid-cols-4`,children:[un.map(r=>H(An,{role:r,value:e[r],options:t,pending:n,onChange:a},r)),L(`label`,{className:`flex items-start gap-2.5 rounded-lg border border-border bg-background p-3 text-sm text-foreground`,children:[H(`input`,{type:`checkbox`,checked:r,disabled:n,onChange:e=>o(e.target.checked),className:`mt-0.5 h-4 w-4 shrink-0 accent-primary`}),L(`span`,{className:`flex flex-col gap-0.5`,children:[H(`span`,{className:`text-xs font-semibold`,children:`Low-fps relocate/shed`}),L(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:[`fpsMinThreshold `,r?`${i} fps`:`disabled`]})]})]})]})}I();function Mn(){let e=B(),{nodes:t}=me(),n=d(void 0),r=ae({addonId:sn}),i=ae({addonId:cn}),a=()=>Sn(e),o=m({onSuccess:a}),s=ge(),c=b({onSuccess:a}),l=k({onSuccess:a}),[u,f]=V(!1),p=R(()=>{let e=new Map;for(let t of n.data??[])e.set(t.nodeId,t.settings);return e},[n.data]),h=R(()=>t.map(e=>{let t=p.get(e.id),n=ft(t,e.isHub),r=gn(t,`detectWeight`);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n,weight:r??1,maxCameras:gn(t,`maxCameras`),reachableHost:_n(t,`reachableHost`),detectedHosts:e.localIps}}),[t,p]),g=h.filter(e=>e.effective.pipeline),_={ingestNode:mn(r.data,`ingestNode`,`hub`),recordingNode:mn(i.data,ln,`hub`),audioNode:mn(r.data,`audioNode`,`hub`),motionNode:mn(r.data,`motionNode`,`hub`)},v=R(()=>{let e=t.filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,...un.map(e=>_[e]),...e])].filter(e=>e.length>0)},[t,_]),y=hn(r.data,`fpsMinThreshold`,0),x=y>0,S=n.isLoading||r.isLoading||i.isLoading,C=(e,t,n)=>{o.mutate({agentNodeId:e,[t]:n})},w=(e,t)=>{if(e===`recordingNode`){l.mutate({addonId:cn,patch:{[ln]:t}});return}l.mutate({addonId:sn,patch:{[e]:t}})},T=e=>{l.mutate({addonId:sn,patch:{fpsMinThreshold:e?Math.max(1,y):0}})},E=e=>c.variables?.agentNodeId===e?c.isPending?`pending`:c.isError?`error`:c.isSuccess?`success`:`idle`:`idle`,D=e=>E(e)===`error`?xn(c.error):null,O=async e=>{f(!0);try{for(let t of e)await s.mutateAsync({agentNodeId:t.nodeId,detectWeight:t.weight})}finally{f(!1),a()}},A={capabilityPending:o.isPending,onToggleCapability:C,onCommitReachableHost:(e,t)=>c.mutate({agentNodeId:e,reachableHost:t}),reachableHostStatus:E,reachableHostErrorMessage:D};return L(`section`,{className:`rounded-xl border border-border bg-surface p-5 @3xl/clustertab:p-6 space-y-6`,children:[L(`header`,{className:`flex items-start justify-between gap-4`,children:[L(`div`,{className:`space-y-1`,children:[H(`h3`,{className:`text-base font-semibold text-foreground`,children:`Pipeline placement`}),H(`p`,{className:`max-w-prose text-xs leading-relaxed text-foreground-subtle`,children:`Toggle which node runs each pipeline capability, distribute detection weight across detect-capable nodes, and choose the singleton cluster roles.`})]}),S&&H(G,{className:`h-5 w-5 shrink-0 animate-spin text-foreground-subtle`,"aria-label":`Loading`})]}),L(`div`,{className:`space-y-3`,children:[H(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Singleton cluster roles`}),H(jn,{roleValues:_,options:v,pending:l.isPending,lowFpsEnabled:x,fpsMinThreshold:y,onRoleChange:w,onLowFpsToggle:T})]}),L(`div`,{className:`space-y-3`,children:[L(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[H(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Per-node capabilities`}),H(On,{})]}),h.length===0?H(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No cluster nodes reporting yet.`}):L(z,{children:[H(`div`,{className:`grid gap-4 @xl/clustertab:grid-cols-2 @3xl/clustertab:hidden`,children:h.map(e=>H(Dn,{node:e,actions:A},e.id))}),H(`div`,{className:`hidden @3xl/clustertab:block`,children:H(kn,{nodes:h,actions:A})})]})]}),L(`div`,{className:`space-y-3`,children:[H(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection weight`}),H(Ee,{nodes:g,pending:u,onCommitWeights:e=>void O(e)})]}),L(`div`,{className:`space-y-3`,children:[H(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices`}),g.length===0?H(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No detect-capable nodes — enable detection on a node above to configure its accelerators.`}):H(`div`,{className:`space-y-2`,children:g.map(e=>H(Oe,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline},e.id))})]})]})}I();var Nn=!1;function Pn({refreshToken:e}){let t=B(),{data:n}=y(void 0);R(()=>rt(n??[]),[n]);let r=o({onSuccess:()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})}});return L(`div`,{className:`space-y-6`,children:[H(gt,{refreshToken:e}),H(Mn,{}),Nn,L(`div`,{className:`flex flex-col gap-3 @md/clustertab:flex-row @md/clustertab:items-center @md/clustertab:justify-between`,children:[L(`div`,{className:`min-w-0`,children:[H(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Rebalance`}),H(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Recompute the optimal node for every assigned camera from current load + hardware affinity, and migrate the ones no longer on their best node. Pinned cameras never move.`})]}),L(`button`,{type:`button`,onClick:()=>r.mutate(void 0),disabled:r.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-white hover:bg-primary/90 disabled:opacity-50 shrink-0 self-start @md/clustertab:self-auto whitespace-nowrap`,children:[H(Ne,{className:`h-3.5 w-3.5`}),r.isPending?`Rebalancing…`:`Rebalance pipelines`]})]})]})}var Fn=[`pipeline-orchestrator`];function In({refreshToken:e}){return H(`div`,{className:`space-y-4 max-w-3xl`,children:H(at,{nodeId:`hub`,addonIds:Fn,level:`global`,title:`Cluster settings`,description:`Cluster-wide orchestration knobs: enabled nodes, load balancer thresholds, and failover policy. Per-camera pipelines live in Device Overrides; live cluster load is on the Assignments tab.`})})}I();function Ln({refreshToken:e}){let t=B(),{data:n,isLoading:r}=f(),[i,a]=V(null),[o,s]=V(``),[c,l]=V(``),u=()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listTemplates`]]})},d=x({onSuccess:()=>{a(null),u()}}),p=pe({onSuccess:u}),m=e=>{a(e.id),s(e.name),l(e.description??``)},h=()=>{a(null),s(``),l(``)},g=()=>{if(!i)return;let e=c.trim();d.mutate({id:i,name:o.trim()||`Untitled`,...e?{description:e}:{}})};if(r)return H(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading templates…`});let _=[...n??[]].toSorted((e,t)=>e.name.localeCompare(t.name));return H(`div`,{className:`space-y-6 max-w-4xl`,children:L(`section`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[L(`div`,{className:`border-b border-border px-4 py-3 flex items-center justify-between`,children:[L(`div`,{children:[H(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Templates`}),H(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:`Curated pipeline presets operators can apply to any camera. Apply-time is a copy — future edits to a template don't retroactively change cameras that were seeded from it. Save a template from the device Pipeline tab.`})]}),L(`div`,{className:`text-[11px] text-foreground-subtle`,children:[_.length,` template`,_.length===1?``:`s`]})]}),_.length===0?L(`div`,{className:`px-4 py-8 text-xs text-foreground-subtle flex flex-col items-center gap-2`,children:[H(Fe,{className:`h-6 w-6 opacity-40`}),H(`div`,{children:`No templates yet. Create one from a device Pipeline tab ("Save as template").`})]}):H(`ul`,{className:`divide-y divide-border`,children:_.map(e=>{let t=i===e.id;return H(`li`,{className:`px-4 py-3 text-xs`,children:L(`div`,{className:`flex items-start gap-3`,children:[H(`div`,{className:`flex-1 min-w-0`,children:t?L(`div`,{className:`space-y-2`,children:[H(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-xs text-foreground focus:outline-none focus:border-primary`,value:o,onChange:e=>s(e.target.value),placeholder:`Template name`,autoFocus:!0}),H(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-[11px] text-foreground focus:outline-none focus:border-primary`,value:c,onChange:e=>l(e.target.value),placeholder:`Description (optional)`})]}):L(z,{children:[H(`div`,{className:`font-medium text-foreground`,children:e.name}),e.description&&H(`div`,{className:`text-foreground-subtle mt-0.5`,children:e.description}),L(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:[e.config.steps.length,` step(s)`,e.config.audio?.enabled?` · audio`:``,L(`span`,{className:`ml-2`,children:[`updated `,new Date(e.updatedAt).toLocaleString()]})]})]})}),H(`div`,{className:`flex items-center gap-1 shrink-0`,children:t?L(z,{children:[L(`button`,{type:`button`,onClick:g,disabled:d.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-50`,children:[H(Ge,{className:`h-3 w-3`}),`Save`]}),L(`button`,{type:`button`,onClick:h,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover`,children:[H(Ze,{className:`h-3 w-3`}),`Cancel`]})]}):L(z,{children:[H(`button`,{type:`button`,onClick:()=>m(e),title:`Rename`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,children:H(Pe,{className:`h-3 w-3`})}),H(`button`,{type:`button`,onClick:()=>{confirm(`Delete template "${e.name}"?`)&&p.mutate({id:e.id})},disabled:p.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-red-400 hover:bg-surface-hover disabled:opacity-50`,children:H($e,{className:`h-3 w-3`})})]})})]})},e.id)})})]})})}var Rn=`pipeline-orchestrator`,zn=200;function Bn(){return L(`div`,{className:`flex flex-col gap-3`,children:[L(`div`,{children:[H(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Orchestrator logs`}),H(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Dispatch decisions, balancer moves and failover events from the pipeline orchestrator. Streaming live; the device chip on a line tells which camera it refers to.`})]}),H(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:H(j,{addonId:Rn,limit:zn,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}I();var Vn=[{id:`assignments`,label:`Assignments`},{id:`balancer`,label:`Balancer`},{id:`settings`,label:`Settings`},{id:`templates`,label:`Templates`},{id:`logs`,label:`Logs`}];function Hn({refreshToken:e}){let[t,n]=V(`assignments`);return L(`div`,{className:`flex flex-col h-full`,children:[L(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[H(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),H(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Per-camera assignments, the load balancer (live load + inference-device weights), cluster-wide settings, and the pipeline template library.`})]}),H(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:Vn.map(e=>H(`button`,{type:`button`,onClick:()=>n(e.id),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${t===e.id?`border-primary text-primary`:`border-transparent text-foreground-subtle hover:text-foreground`}`,children:e.label},e.id))}),L(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[t===`assignments`&&H(on,{}),t===`balancer`&&H(Pn,{refreshToken:e}),t===`settings`&&H(In,{refreshToken:e}),t===`templates`&&H(Ln,{refreshToken:e}),t===`logs`&&H(Bn,{})]})]})}var Un=`armed:`;function Wn(e){return e.assignment.reasons.detection?.startsWith(Un)===!0}function Gn(e){let{assignment:t,detection:n}=e;return n!==null&&n.provisioning.state===`failed`||t.detectionNodeId===null&&n===null&&!Wn(e)?`error`:n!==null&&n.phase===`active`?`healthy`:`idle`}function Kn(e){let t=[],n=[],{assignment:r,detection:i,decoder:a,broker:o}=e;i!==null&&i.provisioning.state===`failed`&&t.push({code:`provisioning-failed`,severity:`error`,message:i.provisioning.error!==void 0&&i.provisioning.error.length>0?`Engine provisioning failed: ${i.provisioning.error}`:`Engine provisioning failed on the detection node`}),i!==null&&i.phase===`active`&&i.actualFps===0&&t.push({code:`detection-black-hole`,severity:`error`,message:`Detection phase is ACTIVE but 0 fps are being processed — frames are not reaching the detector (cross-node black-hole signature)`}),i!==null&&i.phase===`active`&&a!==null&&a.shm.framesWritten===0&&t.push({code:`decoder-black-hole`,severity:`error`,message:`Decoder on ${a.nodeId} has written 0 frames to the shared-memory plane while detection is active — the decode path is stalled`}),r.detectionNodeId===null&&i===null&&!Wn(e)&&n.push({code:`unassigned`,severity:`warning`,message:`Not placed on any detection node — no pipeline is running for this camera`});let s=e.degraded??[];if(s.length>0){let e=[...new Set(s.map(e=>e.stage))].join(`, `);n.push({code:`status-unreadable`,severity:`warning`,message:`Could not read ${e} for this camera — those blocks are unknown, not empty (a switch read that failed does NOT mean nothing is switched off)`})}for(let e of o?.profiles??[])e.status===`streaming`&&e.inFps===0&&n.push({code:`broker-stalled`,severity:`warning`,message:`Broker profile "${e.profile}" reports streaming but 0 in-fps — the source pull may be stalled`});return[...t,...n]}function qn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Y(e){return typeof e==`string`&&e.length>0?e:null}function Jn(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function Yn(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function Xn(e,t){return e==null?!1:JSON.stringify(e)!==JSON.stringify(t??null)}var Zn={detectionMode:null,detectionStreamProfile:null,detectionFps:null,motionSources:[],motionFps:null,motionCooldownMs:null,motionStreamProfile:null,audioMode:null,pipelineNodeId:null,decoderNodeId:null,audioNodeId:null,overriddenKeys:new Set};function Qn(e){if(!qn(e)||!Array.isArray(e.sections))return Zn;let t=be(e),n=e=>{let n=t.get(e);if(n!==void 0)return n.value??n.default},r=new Set;for(let[e,n]of t)Xn(n.value,n.default)&&r.add(e);return{detectionMode:Y(n(`detectionMode`)),detectionStreamProfile:Y(n(`detectionStreamProfile`)),detectionFps:Jn(n(`detectionFps`)),motionSources:Yn(n(`motionSources`)),motionFps:Jn(n(`motionFps`)),motionCooldownMs:Jn(n(`motionCooldownMs`)),motionStreamProfile:Y(n(`motionStreamProfile`)),audioMode:Y(n(`audioMode`)),pipelineNodeId:Y(n(`pipelineNodeId`)),decoderNodeId:Y(n(`decoderNodeId`)),audioNodeId:Y(n(`audioNodeId`)),overriddenKeys:r}}function $n(e,t=0){let n=[];for(let r of e)n.push({addonId:r.addonId,modelId:r.modelId??null,enabled:r.enabled,depth:t}),r.children!==void 0&&r.children.length>0&&n.push(...$n(r.children,t+1));return n}function X({title:e,children:t}){return L(`div`,{className:`bg-background px-3.5 py-3 min-w-0`,children:[H(`div`,{className:`text-[9px] font-semibold uppercase tracking-[0.14em] text-foreground-subtle mb-2`,children:e}),H(`div`,{className:`flex flex-col gap-1 min-w-0`,children:t})]})}function Z({label:e,children:t,overridden:n=!1}){return L(`div`,{className:`flex items-baseline gap-2 text-[11px] leading-snug min-w-0`,children:[H(`span`,{className:`text-foreground-subtle shrink-0 w-24 truncate`,title:e,children:e}),H(`span`,{className:`font-mono tabular-nums text-foreground min-w-0 truncate flex-1`,children:t}),n&&H(er,{})]})}function er(){return H(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0 self-center`,title:`Device-level override active`,"aria-label":`Device-level override active`,role:`img`})}var tr={neutral:`border-border text-foreground-muted`,success:`border-success/40 text-success`,warning:`border-warning/40 text-warning`,danger:`border-danger/40 text-danger`,info:`border-info/40 text-info`};function Q({tone:e=`neutral`,children:t,title:n}){return H(`span`,{title:n,className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-medium leading-tight whitespace-nowrap ${tr[e]}`,children:t})}function $({children:e}){return H(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function nr({icon:e,label:t,nodeId:n,pinned:r,reason:i,overridden:a}){return L(`div`,{className:`flex items-center gap-2 text-[11px] leading-snug min-w-0`,children:[H(e,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),H(`span`,{className:`text-foreground-subtle w-[4.5rem] shrink-0`,children:t}),n===null?H(`span`,{className:`text-foreground-subtle italic`,children:`unassigned`}):L(z,{children:[H(`span`,{className:`font-mono text-foreground truncate`,title:n,children:n}),r?L(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] text-warning shrink-0`,title:`Manually pinned`,children:[H(ct,{className:`h-2.5 w-2.5`}),` manual`]}):L(`span`,{className:`text-[10px] text-foreground-subtle shrink-0 truncate`,children:[`auto · `,i!==void 0&&i.length>0?i:`capacity`]}),a&&H(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0`,title:`Persisted settings pin for this role`})]})]})}function rr({assignment:e,settings:t,onlineNodes:n,pinPending:r,onDetectionPinChange:i}){let a=e.pinned.detection&&e.detectionNodeId!==null?e.detectionNodeId:`auto`,o=[...new Set([...e.detectionNodeId===null?[]:[e.detectionNodeId],...n.map(e=>e.id)])];return L(X,{title:`Where it runs`,children:[H(nr,{icon:K,label:`Detection`,nodeId:e.detectionNodeId,pinned:e.pinned.detection,reason:e.reasons.detection,overridden:t.overriddenKeys.has(`pipelineNodeId`)}),H(nr,{icon:He,label:`Decoder`,nodeId:e.decoderNodeId,pinned:e.pinned.decoder,reason:e.reasons.decoder,overridden:t.overriddenKeys.has(`decoderNodeId`)}),H(nr,{icon:Me,label:`Audio`,nodeId:e.audioNodeId,pinned:e.pinned.audio,reason:e.reasons.audio,overridden:t.overriddenKeys.has(`audioNodeId`)}),H(nr,{icon:Ie,label:`Source`,nodeId:e.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),H(`div`,{className:`mt-1.5`,children:L(`select`,{value:a,disabled:r,"aria-label":`Detection placement pin`,onChange:e=>i(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-[11px] text-foreground disabled:opacity-50`,children:[H(`option`,{value:`auto`,children:`Auto (load balanced)`}),o.map(e=>L(`option`,{value:e,children:[`Pin detection → `,n.find(t=>t.id===e)?.name??e]},e))]})})]})}function ir(e){return`${e.width}×${e.height} ${e.codec} @${e.fps}fps`}function ar(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function or(e){return e===null?`default`:e===0?`native (no throttle)`:`${e} fps`}function sr({streams:e,brokerProfiles:t,settings:n,motionEnabled:r,motionFpsLive:i}){let a=ar(t,n.detectionStreamProfile),o=ar(t,n.motionStreamProfile),s=n.motionSources.includes(`analyzer`);return L(X,{title:`Streams & motion`,children:[L(Z,{label:`Detect stream`,overridden:n.overriddenKeys.has(`detectionStreamProfile`),children:[n.detectionStreamProfile??`—`,a!==void 0&&` · ${a.width}×${a.height} ${a.codec}`]}),H(Z,{label:`Detect FPS`,overridden:n.overriddenKeys.has(`detectionFps`),children:or(n.detectionFps)}),L(Z,{label:`Motion src`,overridden:n.overriddenKeys.has(`motionSources`),children:[n.motionSources.length>0?n.motionSources.join(` + `):`none`,r===!1&&` · inactive`]}),s&&L(z,{children:[L(Z,{label:`Motion stream`,overridden:n.overriddenKeys.has(`motionStreamProfile`),children:[n.motionStreamProfile??`—`,o!==void 0&&` · ${o.width}×${o.height} ${o.codec}`]}),L(Z,{label:`Motion FPS`,overridden:n.overriddenKeys.has(`motionFps`),children:[or(n.motionFps),i!==null&&` · live ${i.toFixed(1)}`]})]}),H(Z,{label:`Cooldown`,overridden:n.overriddenKeys.has(`motionCooldownMs`),children:n.motionCooldownMs===null?`default`:`${n.motionCooldownMs/1e3}s`}),H(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:e.length===0?H($,{children:`No streams registered`}):e.map(e=>L(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,title:e.camStreamId,children:[H(`span`,{className:`text-foreground-muted`,children:e.kind}),` `,ir(e)]},e.camStreamId))})]})}function cr({steps:e,audioModelId:t,audioEnabled:n,audioMode:r}){return L(X,{title:`Pipeline steps`,children:[e===void 0?H($,{children:`Resolving…`}):e.length===0?H($,{children:`No steps configured`}):H(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>H(Q,{tone:e.enabled&&e.depth===0?`info`:`neutral`,title:e.modelId??e.addonId,children:L(`span`,{className:e.enabled?``:`line-through opacity-60`,children:[e.depth>0&&H(`span`,{className:`opacity-50`,children:`↳ `}),e.addonId,e.modelId!==null&&L(`span`,{className:`font-mono opacity-75`,children:[` · `,e.modelId]})]})},`${e.addonId}-${t}`))}),H(`div`,{className:`mt-1`,children:L(Z,{label:`Audio class.`,children:[r??`—`,n!==null&&(n?` · running`:` · off`),t!==null&&` · ${t}`]})})]})}var lr={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function ur({detection:e,live:t,detectionMode:n,modeOverridden:r}){if(e===null)return L(X,{title:`Detection runtime`,children:[H(Z,{label:`Mode`,overridden:r,children:n??`—`}),H($,{children:`Detection stage inactive or unreachable`})]});let i=t?.phase??e.phase,a=t?.actualFps??e.actualFps,o=t?.configuredFps??e.configuredFps,s=t?.avgInferenceTimeMs??e.avgInferenceMs,c=t?.queueDepth??e.queueDepth,l=de(i),u=i===`active`&&a===0;return L(X,{title:`Detection runtime`,children:[L(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:[L(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-semibold uppercase tracking-wider ${l.badgeClass}`,children:[H(C,{phase:i,className:`h-2.5 w-2.5`}),l.label]}),t!==void 0&&H(`span`,{className:`text-[9px] text-foreground-subtle uppercase tracking-wider`,children:`live`})]}),H(Z,{label:`Mode`,overridden:r,children:n??`—`}),L(Z,{label:`FPS`,children:[H(`span`,{className:u?`text-danger font-semibold`:``,children:a.toFixed(1)}),L(`span`,{className:`text-foreground-subtle`,children:[` / `,o.toFixed(0),` configured`]})]}),L(Z,{label:`Inference`,children:[s.toFixed(0),` ms`,c>0&&L(`span`,{className:`text-warning`,children:[` · queue `,c]}),t!==void 0&&t.droppedFrames>0&&L(`span`,{className:`text-warning`,children:[` · drops `,t.droppedFrames]})]}),L(Z,{label:`Engine`,children:[e.engine.backend,` · `,e.engine.device]}),L(Z,{label:`Provisioning`,children:[H(Q,{tone:lr[e.provisioning.state]??`neutral`,children:e.provisioning.state}),e.provisioning.error!==void 0&&L(`span`,{className:`text-danger text-[10px]`,children:[` `,e.provisioning.error]})]})]})}function dr({broker:e}){return e===null?H(X,{title:`Stream broker`,children:H($,{children:`Broker stage inactive or unreachable`})}):L(X,{title:`Stream broker`,children:[e.profiles.length===0?H($,{children:`No broker profiles`}):H(`div`,{className:`flex flex-col gap-1`,children:e.profiles.map(e=>{let t=e.status===`streaming`,n=t&&e.inFps===0;return L(`div`,{className:`flex items-center gap-2 text-[11px] font-mono tabular-nums min-w-0`,children:[H(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full shrink-0 ${n?`bg-danger`:t?`bg-success animate-pulse`:`bg-border`}`,title:e.status}),H(`span`,{className:`text-foreground w-10 shrink-0 truncate`,title:e.profile,children:e.profile}),L(`span`,{className:`text-foreground-subtle truncate`,children:[e.width,`×`,e.height,` `,e.codec]}),L(`span`,{className:`ml-auto shrink-0 ${n?`text-danger`:`text-foreground`}`,children:[e.inFps.toFixed(0),`→`,e.outFps.toFixed(0),`fps`]}),L(`span`,{className:`text-foreground-subtle shrink-0`,title:`Subscribers`,children:[`×`,e.subscribers]})]},e.profile)})}),L(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[L(Q,{tone:e.webrtcSessions>0?`info`:`neutral`,children:[`WebRTC `,e.webrtcSessions]}),L(Q,{tone:e.rtspRestream?`success`:`neutral`,children:[`restream `,e.rtspRestream?`on`:`off`]})]})]})}function fr({decoder:e,detectionActive:t}){if(e===null)return H(X,{title:`Decoder`,children:H($,{children:`Decoder stage inactive or unreachable`})});let n=t&&e.shm.framesWritten===0;return L(X,{title:`Decoder`,children:[H(Z,{label:`Node`,children:e.nodeId}),H(Z,{label:`Sessions`,children:e.sessionCount}),L(Z,{label:`SHM frames`,children:[H(`span`,{className:n?`text-danger font-semibold`:``,children:e.shm.framesWritten}),H(`span`,{className:`text-foreground-subtle`,children:` written`})]}),L(Z,{label:`SHM reads`,children:[e.shm.getFrameHits,` hits`,e.shm.getFrameMisses>0&&L(`span`,{className:`text-warning`,children:[` · `,e.shm.getFrameMisses,` misses`]})]}),L(Z,{label:`SHM budget`,children:[e.shm.budgetMb,` MB`]}),e.formats.length>0&&H(Z,{label:`Formats`,children:e.formats.join(`, `)})]})}I();var pr=`pipeline-orchestrator`,mr={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},hr={healthy:`Healthy`,idle:`Idle`,error:`Error`};function gr({problems:e}){return H(`div`,{role:`alert`,className:`flex flex-col border-b border-border`,children:e.map(e=>L(`div`,{className:`flex items-start gap-2 px-4 py-1.5 text-[11px] font-medium ${e.severity===`error`?`bg-danger/10 text-danger`:`bg-warning/10 text-warning`}`,children:[H(Qe,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),H(`span`,{className:`min-w-0`,children:e.message})]},e.code))})}function _r({deviceId:e,name:t,online:n,status:r,live:i,onlineNodes:a}){let o=B(),{data:s}=D({addonId:pr,deviceId:e,nodeId:`hub`},{staleTime:3e4}),{data:c}=l({deviceId:e},{staleTime:3e4}),u=R(()=>Qn(s),[s]),d=R(()=>c===void 0?void 0:$n(c.steps),[c]),f=R(()=>r===void 0?[]:Kn(r),[r]),p=()=>{o.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),o.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},m=E({onSuccess:p}),h=S({onSuccess:p}),g=t=>{t===`auto`?h.mutate({deviceId:e}):m.mutate({deviceId:e,agentNodeId:t})},_=r===void 0?`idle`:Gn(r),v=f.some(e=>e.severity===`error`),y=f.length>0,b=v?`border-danger/50`:y?`border-warning/40`:`border-border`;return L(`article`,{"aria-label":`${t} pipeline status`,className:`rounded-lg border ${b} bg-background overflow-hidden`,children:[L(`header`,{className:`flex items-center gap-2.5 px-4 py-2.5 border-b border-border bg-surface/50 min-w-0`,children:[H(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${v?`bg-danger`:mr[_]}`,title:v?`Error`:hr[_],"aria-label":v?`Error`:hr[_],role:`img`}),H(`h3`,{className:`text-[13px] font-semibold text-foreground truncate`,title:t,children:t}),L(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`#`,e]}),!n&&H(Q,{tone:`danger`,children:`offline`}),L(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[u.detectionMode!==null&&H(Q,{tone:u.detectionMode===`disabled`?`warning`:u.detectionMode===`always-on`?`info`:`neutral`,title:`Object detection mode`,children:u.detectionMode===`disabled`?`detection off`:u.detectionMode}),r?.recording!=null&&(r.recording.active?L(Q,{tone:`danger`,title:`Recording (${r.recording.mode})`,children:[H(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-danger animate-pulse`}),`REC`]}):r.recording.mode!==`off`&&L(Q,{tone:`neutral`,title:`Recording mode`,children:[`rec `,r.recording.mode]}))]})]}),f.length>0&&H(gr,{problems:f}),r===void 0?H(`div`,{className:`px-4 py-5 text-[11px] text-foreground-subtle italic`,children:`No pipeline status yet — the orchestrator has not composed a snapshot for this camera.`}):L(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-px bg-border`,children:[H(rr,{assignment:r.assignment,settings:u,onlineNodes:a,pinPending:m.isPending||h.isPending,onDetectionPinChange:g}),H(ur,{detection:r.detection,live:i,detectionMode:u.detectionMode,modeOverridden:u.overriddenKeys.has(`detectionMode`)}),H(cr,{steps:d,audioModelId:c?.audio?.modelId??null,audioEnabled:r.audio?.enabled??c?.audio?.enabled??null,audioMode:u.audioMode}),H(sr,{streams:r.source.streams,brokerProfiles:r.broker?.profiles,settings:u,motionEnabled:r.motion?.enabled??null,motionFpsLive:r.motion?.fps??null}),H(dr,{broker:r.broker}),H(fr,{decoder:r.decoder,detectionActive:r.detection?.phase===`active`})]})]})}I();var vr=5e3,yr=1e4,br=5e3;function xr(e){let t=B(),{data:n,isLoading:r}=De(),{data:i,isLoading:a}=v({},{refetchInterval:vr}),{nodes:o}=me();U(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[s,c]=V(new Map);F(Se.PipelineCameraMetricsSnapshot,e=>{let t=e.data;typeof t.deviceId==`number`&&c(e=>{let n=new Map(e);return n.set(t.deviceId,{phase:t.metrics.phase,configuredFps:t.metrics.configuredFps,actualFps:t.metrics.actualFps,queueDepth:t.metrics.queueDepth,avgInferenceTimeMs:t.metrics.avgInferenceTimeMs,droppedFrames:t.metrics.droppedFrames,timestamp:t.timestamp}),n})}),U(()=>{if(s.size===0)return;let e=setInterval(()=>{c(e=>{let t=Date.now()-yr,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},br);return()=>clearInterval(e)},[s.size]);let l=R(()=>{let e=new Map;for(let t of i??[])e.set(t.deviceId,t);return e},[i]);return{rows:R(()=>(n??[]).filter(e=>e.isCamera).map(e=>({deviceId:e.id,name:e.name,online:e.online,status:l.get(e.id)})).sort((e,t)=>e.name.localeCompare(t.name)),[n,l]),liveMetrics:s,onlineNodes:R(()=>(o??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[o]),isLoading:r||a}}I();function Sr({refreshToken:e}){let{rows:t,liveMetrics:n,onlineNodes:r,isLoading:i}=xr(e),a=R(()=>[...t.map(e=>{let t=e.status===void 0?[]:Kn(e.status);return{row:e,errorCount:t.filter(e=>e.severity===`error`).length,warningCount:t.filter(e=>e.severity===`warning`).length}})].sort((e,t)=>e.errorCount===t.errorCount?e.warningCount===t.warningCount?0:t.warningCount-e.warningCount:t.errorCount-e.errorCount),[t]),o=R(()=>{let e=0,t=0;for(let r of a)(r.errorCount>0||r.warningCount>0)&&(t+=1),(n.get(r.row.deviceId)?.phase??r.row.status?.detection?.phase)===`active`&&(e+=1);return{total:a.length,active:e,issues:t}},[a,n]);return i&&t.length===0?H(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Loading camera pipelines…`}):t.length===0?H(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`No cameras found`}):H(`div`,{className:`h-full overflow-y-auto`,children:L(`div`,{className:`max-w-6xl mx-auto flex flex-col gap-3 px-4 py-4`,children:[L(`div`,{className:`flex items-center gap-4 text-[11px] text-foreground-subtle px-1`,children:[L(`span`,{children:[H(`span`,{className:`font-semibold text-foreground`,children:o.total}),` cameras`]}),L(`span`,{children:[H(`span`,{className:`font-semibold text-success`,children:o.active}),` actively inferring`]}),L(`span`,{children:[H(`span`,{className:`font-semibold ${o.issues>0?`text-danger`:`text-foreground`}`,children:o.issues}),` `,`with issues`]}),H(`span`,{className:`ml-auto hidden sm:inline text-[10px]`,children:`polled every 5 s · detection metrics live at 1 Hz`})]}),a.map(({row:e})=>H(_r,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:n.get(e.deviceId),onlineNodes:r},e.deviceId))]})})}I();var Cr=`__cluster__`;function wr(e){return e===`cameras`?`cameras`:`nodes`}function Tr(){let[e,t]=We(),n=wr(e.get(`view`)),r=e.get(`node`)??`__cluster__`,[i,a]=V(0),[o,s]=V(!1);return U(()=>{n===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:Cr},{replace:!0})},[n,e,t]),L(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[L(`div`,{className:`flex items-center justify-between gap-4 px-4 py-3 border-b border-border shrink-0`,children:[L(`div`,{className:`flex items-center gap-1 rounded-lg border border-border p-0.5 bg-surface`,children:[H(`button`,{type:`button`,onClick:()=>{t({view:`nodes`,node:r},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,n===`nodes`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Nodes`}),H(`button`,{type:`button`,onClick:()=>{t({view:`cameras`},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,n===`cameras`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Cameras`})]}),L(`button`,{type:`button`,onClick:()=>a(e=>e+1),title:`Refresh`,className:`inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[H(Le,{className:`h-3.5 w-3.5`}),`Refresh`]})]}),n===`nodes`&&L(`button`,{type:`button`,onClick:()=>s(e=>!e),"aria-expanded":o,className:`md:hidden flex items-center justify-between gap-2 px-4 py-2 border-b border-border shrink-0 text-[11px] font-medium text-foreground-subtle hover:text-foreground transition-colors`,children:[L(`span`,{children:[o?`Hide`:`Show`,` node list`]}),H(Ue,{className:[`h-4 w-4 transition-transform`,o?`rotate-180`:``].join(` `)})]}),H(`div`,{className:`flex-1 flex flex-col md:flex-row overflow-hidden min-h-0`,children:n===`nodes`?L(z,{children:[H(`aside`,{className:[o?`block`:`hidden`,`md:block w-full md:w-72 shrink-0 border-b md:border-b-0 md:border-r border-border`,`max-h-[60vh] md:max-h-none overflow-y-auto`].join(` `),children:H(mt,{selectedNodeId:r,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),s(!1)},refreshToken:i})}),H(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:r===`__cluster__`?H(Hn,{refreshToken:i}):H(an,{nodeId:r,refreshToken:i})})]}):H(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:H(Sr,{refreshToken:i})})})]})}export{Tr as PipelinePage};