@camstack/addon-admin-ui 1.2.30 → 1.2.32

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 (103) hide show
  1. package/dist/assets/{AddLocationWizard-BMJasR9E.js → AddLocationWizard-Bqn51iVc.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-B7h-KuUE.js → AddonCollectionPage-D9EE6p80.js} +1 -1
  3. package/dist/assets/Addons-Bp55KXZR.js +1 -0
  4. package/dist/assets/{AdminTabs-DJVKnkBk.js → AdminTabs-DB9TozBh.js} +1 -1
  5. package/dist/assets/AiProfiles-C4ji0awJ.js +1 -0
  6. package/dist/assets/{Automation-eNJjEWy4.js → Automation-BmDGNoTh.js} +2 -2
  7. package/dist/assets/{BrokerForm-t_GUOg2J.js → BrokerForm-CtjETVv8.js} +1 -1
  8. package/dist/assets/{Capabilities-Dt_r6gDs.js → Capabilities-BlEUfcGN.js} +1 -1
  9. package/dist/assets/{CapabilityBadges-UGpydWTL.js → CapabilityBadges-CTZ7zqWM.js} +1 -1
  10. package/dist/assets/{Cluster-D7uZJzB2.js → Cluster-CkGq5KVh.js} +1 -1
  11. package/dist/assets/{ClusterRecordingTab-DNIc_5e9.js → ClusterRecordingTab-nszIK7qG.js} +1 -1
  12. package/dist/assets/{Dashboard-CgcdFk1_.js → Dashboard-CO5PTZ9n.js} +1 -1
  13. package/dist/assets/{Data-DHXxwE1N.js → Data-CYwE4-K2.js} +1 -1
  14. package/dist/assets/DetectionIntelligence-MaxZ_sn8.js +1 -0
  15. package/dist/assets/{DeviceAggregateSection-DfzIZHua.js → DeviceAggregateSection-C6sscd95.js} +1 -1
  16. package/dist/assets/DeviceDetail-KHB2dWaR.js +2 -0
  17. package/dist/assets/{Devices-C_ATmfMN.js → Devices-xlmwhKxI.js} +1 -1
  18. package/dist/assets/EmbedPlayerPage-CLGFNg5C.js +1 -0
  19. package/dist/assets/Events-EfdVWQGS.js +1 -0
  20. package/dist/assets/{FormBuilder-DDh3o7-1.js → FormBuilder-ZuE9B0w9.js} +1 -1
  21. package/dist/assets/Identity-CKR7bmrK.js +1 -0
  22. package/dist/assets/{IntegrationDetail-CSxqQW_Z.js → IntegrationDetail-DUkC3dFN.js} +1 -1
  23. package/dist/assets/{Integrations-Bf3m3Eof.js → Integrations-BuhF2y9p.js} +1 -1
  24. package/dist/assets/{Integrations-1N5QbLzg.js → Integrations-t8-3dqN4.js} +1 -1
  25. package/dist/assets/{Logs-rC4Ya2q2.js → Logs-D1sMKNHu.js} +1 -1
  26. package/dist/assets/{MotionZonesSettings-kuDgPoqn.js → MotionZonesSettings-JUP-5dky.js} +1 -1
  27. package/dist/assets/{MyAccess-BBGGcTwo.js → MyAccess-BSkJTbz8.js} +1 -1
  28. package/dist/assets/{Network-Cy-A5pNz.js → Network-CXKyrgFS.js} +1 -1
  29. package/dist/assets/{NodeAddonsSettingsPanel-rKp5y5HT.js → NodeAddonsSettingsPanel-1C9rZfoa.js} +1 -1
  30. package/dist/assets/{NodeInferenceDevices-jYmHLpBX.js → NodeInferenceDevices-D1yIrxri.js} +1 -1
  31. package/dist/assets/Notifications-gurR5fDh.js +1 -0
  32. package/dist/assets/Pipeline-DTKomVZV.js +1 -0
  33. package/dist/assets/{Plates-fOePmMM0.js → Plates-CQ4aoncO.js} +1 -1
  34. package/dist/assets/{PrivacyMaskSettings-BHD7h8OK.js → PrivacyMaskSettings-CfvJZ3tP.js} +1 -1
  35. package/dist/assets/{ProviderIcon-naWrpMmN.js → ProviderIcon-ClXY1rL4.js} +1 -1
  36. package/dist/assets/{Recordings-u2MKr-kb.js → Recordings-DglOV8NW.js} +1 -1
  37. package/dist/assets/{ScanNetworkModal-NI996FTx.js → ScanNetworkModal-DmZyDQIW.js} +1 -1
  38. package/dist/assets/{Settings-Qw24YqpK.js → Settings-BVw2pnr7.js} +1 -1
  39. package/dist/assets/{Showroom-BhMUr9Ql.js → Showroom-9BtpR6nD.js} +1 -1
  40. package/dist/assets/{Terminal-DFixQFFc.js → Terminal-C-v8B3we.js} +2 -2
  41. package/dist/assets/__vite-browser-external-DQHwpgVa.js +64 -0
  42. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-dNSjrRfm.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BtA4eogJ.js} +1 -1
  43. package/dist/assets/{build-cluster-graph-C6MLwK2s.js → build-cluster-graph-6UMcPt27.js} +2 -2
  44. package/dist/assets/circle-check-big-5J4vhHcH.js +1 -0
  45. package/dist/assets/clock-D19QkJv2.js +1 -0
  46. package/dist/assets/{copy-BncZJlXn.js → copy-BObtPXKC.js} +1 -1
  47. package/dist/assets/{debounced-invalidate-CFQ1nQUs.js → debounced-invalidate-Sygznr_T.js} +1 -1
  48. package/dist/assets/dist-Bso6V1TI.js +7 -0
  49. package/dist/assets/{dist-CYA-j6zS.js → dist-W1UImz79.js} +1 -1
  50. package/dist/assets/{download-C-SIOwsB.js → download-DsIysR_y.js} +1 -1
  51. package/dist/assets/{face-bbox-05d9xU_s.js → face-bbox-DjqvdhYZ.js} +1 -1
  52. package/dist/assets/{hostInit-B7f1m2Ck.js → hostInit-BUHMjqwF.js} +1 -1
  53. package/dist/assets/index-BH_HqZVJ.css +2 -0
  54. package/dist/assets/index-BqCgqp9V.js +4 -0
  55. package/dist/assets/{key-round-BW7VSrNd.js → key-round-DF1dcL0w.js} +1 -1
  56. package/dist/assets/{mf-entry-bootstrap-0-2b4b5d1e.js → mf-entry-bootstrap-0-62a13374.js} +2 -2
  57. package/dist/assets/{pencil-ChPuHfCU.js → pencil-CQwfEybQ.js} +1 -1
  58. package/dist/assets/player-overlays-CJ2EDXmI.js +1 -0
  59. package/dist/assets/plus-BIR1e9Y7.js +1 -0
  60. package/dist/assets/{radio-BCYd2EQY.js → radio-C754NrLM.js} +1 -1
  61. package/dist/assets/{refresh-cw-_uUkpw3C.js → refresh-cw-DAm7QoFj.js} +1 -1
  62. package/dist/assets/remoteEntry-EVtyXnE6.js +1 -0
  63. package/dist/assets/{rotate-ccw-Dn6h4TrJ.js → rotate-ccw-ildFCltM.js} +1 -1
  64. package/dist/assets/rotate-cw-DyrhB96Y.js +1 -0
  65. package/dist/assets/search-BFU3RCdH.js +1 -0
  66. package/dist/assets/{send-BHfeKQ26.js → send-BMpnpOJi.js} +1 -1
  67. package/dist/assets/{server-CxbU82tS.js → server-2ReeYjUz.js} +1 -1
  68. package/dist/assets/square-CjeJk_qb.js +1 -0
  69. package/dist/assets/{square-check-big-DgNfiXED.js → square-check-big-DUv4JqM3.js} +1 -1
  70. package/dist/assets/src-DCsdXZpS.js +67 -0
  71. package/dist/assets/src-YgttllUb.js +7 -0
  72. package/dist/assets/{upload-vT0_VhDG.js → upload-Dvv16Zg3.js} +1 -1
  73. package/dist/assets/{useEventInvalidation-Djmiw-m0.js → useEventInvalidation-BI2Lc7mp.js} +1 -1
  74. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-C5QKBykg.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-D3wOFHTg.js} +2 -2
  75. package/dist/assets/{wifi-B43Oo_Wu.js → wifi-cBAahSiZ.js} +1 -1
  76. package/dist/assets/{zap-v3R56D2n.js → zap-C86yuB6j.js} +1 -1
  77. package/dist/index.html +7 -7
  78. package/dist/server/addon.js +13329 -12537
  79. package/package.json +1 -1
  80. package/dist/assets/Addons-Bc6CMJXc.js +0 -1
  81. package/dist/assets/AiProfiles-o7lEemqD.js +0 -1
  82. package/dist/assets/DetectionIntelligence-BHSjagTY.js +0 -1
  83. package/dist/assets/DeviceDetail-DR2LOSDx.js +0 -2
  84. package/dist/assets/EmbedPlayerPage-LYTZoHZq.js +0 -1
  85. package/dist/assets/Events-C_AGDN7L.js +0 -1
  86. package/dist/assets/Identity-DOM4zFzC.js +0 -1
  87. package/dist/assets/Notifications-CfsEELe0.js +0 -1
  88. package/dist/assets/Pipeline-BpIXVT-q.js +0 -1
  89. package/dist/assets/__vite-browser-external-NEUUz2mh.js +0 -1
  90. package/dist/assets/circle-check-big-JjHQOVDC.js +0 -1
  91. package/dist/assets/clock-CqpeT16c.js +0 -1
  92. package/dist/assets/compat-CbwIzIXq.js +0 -64
  93. package/dist/assets/dist-VqcUWZOQ.js +0 -7
  94. package/dist/assets/index-B4yaKbnm.js +0 -4
  95. package/dist/assets/index-BHm1FmD-.css +0 -2
  96. package/dist/assets/player-overlays-DuTcd1oY.js +0 -1
  97. package/dist/assets/plus-Dw5CKvNT.js +0 -1
  98. package/dist/assets/remoteEntry-BTik834j.js +0 -1
  99. package/dist/assets/rotate-cw-JDQGHlMh.js +0 -1
  100. package/dist/assets/search-dbMboEvL.js +0 -1
  101. package/dist/assets/square-BxOJgJFR.js +0 -1
  102. package/dist/assets/src-CUZFIAzy.js +0 -7
  103. package/dist/assets/src-CkX4IOdq.js +0 -67
@@ -1 +0,0 @@
1
- import{Aa as e,Ao as t,Ba as n,Da as r,Ea as i,Fa as a,Ga as o,Ia as s,La as c,Ma as l,Na as u,Oa as d,Pa as f,Ra as p,bt as m,c as h,ja as g,ka as _,oo as v,s as y,xt as b,za as x}from"./src-CkX4IOdq.js";import{Q as S,S as C,W as w,b as T,o as E,q as D,x as O}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as k}from"./circle-check-big-JjHQOVDC.js";import{t as A}from"./copy-BncZJlXn.js";import{t as j}from"./key-round-BW7VSrNd.js";import{t as M}from"./AddonCollectionPage-B7h-KuUE.js";import{t as ee}from"./plus-Dw5CKvNT.js";import{C as N,E as P,G as F,R as I,T as L,c as R,d as z,i as B,p as V,r as H}from"./index-B4yaKbnm.js";import{t as U}from"./AdminPage-Dq33XE9j.js";import{t as W}from"./AdminTabs-DJVKnkBk.js";import{t as G}from"./addon-display-names-DvSEQty-.js";var K=F(`book-open`,[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z`,key:`ruj8y`}]]),te=F(`key-square`,[[`path`,{d:`M12.4 2.7a2.5 2.5 0 0 1 3.4 0l5.5 5.5a2.5 2.5 0 0 1 0 3.4l-3.7 3.7a2.5 2.5 0 0 1-3.4 0L8.7 9.8a2.5 2.5 0 0 1 0-3.4z`,key:`165ttr`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`m9.4 10.6-6.814 6.814A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814`,key:`1ubxi2`}]]),ne=F(`key`,[[`path`,{d:`m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4`,key:`g0fldk`}],[`path`,{d:`m21 2-9.6 9.6`,key:`1j0ho8`}],[`circle`,{cx:`7.5`,cy:`15.5`,r:`5.5`,key:`yqb3hr`}]]),q=F(`link`,[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]),re=F(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]);S();function ie({userId:n,username:r,onClose:i}){let a=E(),s=o(),c=e({userId:n}),l=c.data,u=()=>a.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),d=_({onSuccess:()=>{u(),i()}}),f=c.isLoading?`loading`:l?.enabled?`enrolled`:`not_enrolled`;return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4`,children:C(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden`,children:[C(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-border`,children:[C(`div`,{className:`flex items-center gap-2`,children:[O(z,{className:`h-4 w-4 text-primary`}),C(`div`,{children:[O(`div`,{className:`text-sm font-medium text-foreground`,children:`Two-factor authentication`}),C(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,O(`span`,{className:`font-mono`,children:r})]})]})]}),O(`button`,{onClick:i,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:O(B,{className:`h-4 w-4`})})]}),C(`div`,{className:`p-4 space-y-4`,children:[f===`loading`&&C(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[O(N,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),f===`not_enrolled`&&C(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[O(L,{className:`h-4 w-4 mt-0.5 shrink-0`}),C(`div`,{children:[O(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),O(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),f===`enrolled`&&l&&C(T,{children:[C(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[O(k,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),C(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[O(`div`,{className:`font-medium`,children:`2FA is active`}),C(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,l.confirmedAt?new Date(l.confirmedAt).toLocaleString():`—`]})]})]}),O(`div`,{className:`text-[11px] text-foreground-subtle`,children:`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`}),C(`div`,{className:`flex justify-end gap-2`,children:[O(t,{onClick:i,variant:`secondary`,children:`Close`}),C(`button`,{onClick:async()=>{await s({title:`Remove 2FA`,message:`Remove two-factor authentication for "${r}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,confirmLabel:`Remove`,variant:`danger`})&&d.mutate({userId:n})},disabled:d.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[d.isPending?O(N,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function ae(){let e=E(),{user:t}=H(),[i,s]=D(!1),[c,l]=D(``),[u,p]=D(``),[m,h]=D(!1),[g,_]=D(null),{data:y,isLoading:b,isError:S}=f(),w=o(),T=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),k=r({onSuccess:()=>{T(),s(!1),l(``),p(``),h(!1),_(null)},onError:e=>{_(e instanceof Error?e.message:`Failed to create user`)}}),A=d({onSuccess:T}),j=n({onSuccess:T}),M=a({onSuccess:T}),P=x({onSuccess:()=>{T(),I(null)}}),[F,I]=D(null),[L,W]=D(null),G=y??[];async function K(e){await w({title:`Delete user`,message:`Permanently delete user "${e.username}"? This cannot be undone — any active sessions will be revoked on next request.`,confirmLabel:`Delete`,variant:`danger`})&&A.mutate({id:e.id})}async function te(e){let t=window.prompt(`New password for "${e.username}":`);if(t){if(t.length<8){window.alert(`Password must be at least 8 characters.`);return}await w({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&M.mutate({id:e.id,newPassword:t})}}function q(e,t){t!==e.isAdmin&&j.mutate({id:e.id,isAdmin:t})}function re(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}return C(U,{children:[O(`div`,{className:`flex items-center justify-end`,children:C(`button`,{onClick:()=>s(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm hover:bg-primary/90`,children:[O(ee,{className:`h-3.5 w-3.5`}),`Create User`]})}),i&&C(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[C(`div`,{className:`flex items-center justify-between`,children:[O(`span`,{className:`text-xs font-medium text-foreground`,children:`New User`}),O(`button`,{onClick:()=>s(!1),className:`text-foreground-subtle hover:text-foreground`,children:O(B,{className:`h-4 w-4`})})]}),C(`div`,{className:`grid grid-cols-3 gap-3`,children:[C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),O(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`john`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Password`}),O(`input`,{type:`password`,value:u,onChange:e=>p(e.target.value),placeholder:`••••••••`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),C(`label`,{className:`flex items-center gap-2 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground cursor-pointer`,children:[O(`input`,{type:`checkbox`,checked:m,onChange:e=>h(e.target.checked),className:`rounded border-border focus:ring-primary`}),O(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),g&&O(`p`,{className:`text-[10px] text-danger`,children:g}),C(`div`,{className:`flex justify-end gap-2`,children:[O(`button`,{onClick:()=>s(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),O(`button`,{onClick:()=>k.mutate({username:c,password:u,isAdmin:m}),disabled:k.isPending||!c||!u,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:k.isPending?`Creating...`:`Create`})]})]}),b&&O(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),S&&O(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!b&&!S&&G.length===0&&O(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>A.isPending&&A.variables?.id===e.id||j.isPending&&j.variables?.id===e.id||M.isPending&&M.variables?.id===e.id;return O(v,{columns:[{key:`username`,header:`Username`,render:e=>e.username},{key:`isAdmin`,header:`Admin`,render:t=>C(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[O(`input`,{type:`checkbox`,checked:t.isAdmin,onChange:e=>q(t,e.target.checked),disabled:e(t),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),O(`span`,{className:t.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:t.isAdmin?`Admin`:`Regular`})]})},{key:`scopes`,header:`Scopes`,render:e=>{if(e.isAdmin)return O(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`unscoped`});let t=e.scopes??[];return C(`button`,{onClick:()=>I(e),className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground`,title:`Edit scope grants`,children:[O(V,{className:`h-3 w-3`}),t.length===0?`no access`:`${t.length} grant${t.length===1?``:`s`}`]})}},{key:`createdAt`,header:`Created`,render:e=>O(`span`,{className:`text-foreground-subtle`,children:re(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:n=>{let r=e(n);return C(`div`,{className:`flex items-center justify-end gap-1`,children:[n.id!==t?.id&&n.totpEnabled&&C(`button`,{onClick:()=>W(n),disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Remove two-factor authentication`,children:[O(z,{className:`h-3 w-3`}),`Remove 2FA`]}),C(`button`,{onClick:()=>te(n),disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Reset password`,children:[O(ne,{className:`h-3 w-3`}),`Reset password`]}),C(`button`,{onClick:()=>K(n),disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete user`,children:[r?O(N,{className:`h-3 w-3 animate-spin`}):O(R,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:G,rowKey:e=>e.id,minWidthPx:560})})(),L&&O(ie,{userId:L.id,username:L.username,onClose:()=>W(null)}),F&&O(oe,{user:F,onClose:()=>I(null),onSubmit:e=>P.mutate({userId:F.id,scopes:e}),submitting:P.isPending})]})}function oe(e){let{user:t}=H(),n=t?.isAdmin===!0;return O(se,{...e,callerScopes:n?null:t?.scopes??[]})}function se({user:e,onClose:t,onSubmit:n,submitting:r,callerScopes:i}){let[a,o]=D(w(()=>(e.scopes??[]).map(e=>({...e,access:[...e.access]})),[e.scopes])),s=h(a);return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4`,children:C(`div`,{className:`w-full max-w-2xl rounded-lg border border-border bg-surface shadow-xl`,children:[C(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-3`,children:[C(`div`,{children:[C(`div`,{className:`text-sm font-semibold text-foreground`,children:[`Edit scopes — `,e.username]}),O(`div`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?`Admin users bypass the scope check; this list is ignored.`:`Pick which capabilities this user can call, and which access flavours within each.`})]}),O(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:O(B,{className:`h-4 w-4`})})]}),C(`div`,{className:`px-4 py-4`,children:[O(y,{value:a,onChange:o,clampToParent:i,emptyHint:C(T,{children:[`No scopes granted.`,` `,O(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until a scope is added.`]})}),s&&O(`p`,{className:`mt-2 text-[10px] text-danger`,children:s})]}),C(`div`,{className:`flex items-center justify-end gap-2 border-t border-border px-4 py-3`,children:[O(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),O(`button`,{onClick:()=>n(a),disabled:r||s!==null,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:r?O(N,{className:`h-3 w-3 animate-spin`}):`Save scopes`})]})]})})}S();var ce=`bg-primary/10 text-primary`,le=`bg-foreground-subtle/10 text-foreground-subtle`;function J(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function ue(e){return e?e===`*`?`*`:e.join(`, `):``}function de(){let e=E(),t=o(),{data:n,isLoading:r}=g(),{data:a}=f(),c=w(()=>n??[],[n]),l=w(()=>a??[],[a]),u=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),d=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[m,h]=D(!1),[_,v]=D(null),y=s({onSuccess:u}),b=i({onSuccess:({token:e,record:t})=>{d(),h(!1),v({token:e,label:t.name})}}),x=p({onSuccess:d}),S=async(e,n)=>{await t({title:`Revoke "${n}"?`,message:`Any client using this token will lose access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&y.mutate({id:e})},T=async(e,n)=>{await t({title:`Revoke "${n}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&x.mutate({id:e})};return C(U,{children:[C(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[O(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Issue scoped tokens to grant a user a narrow surface — a specific addon, integration, or capability. Every token MUST be scoped: revoking it has predictable blast radius.`}),C(`button`,{onClick:()=>h(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,disabled:l.length===0,title:l.length===0?`Create a user first`:`Issue a scoped token`,children:[O(V,{className:`h-3.5 w-3.5`}),`New token`]})]}),C(fe,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[l.length===0&&O(me,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),l.map(e=>O(ge,{userId:e.id,username:e.username,onRevoke:(e,t)=>{T(e,t)},revokePending:x.isPending,revokeId:x.variables?.id},e.id))]}),c.length>0&&O(fe,{title:`Legacy API keys`,subtitle:`${c.length} pre-existing — revoke only`,children:O(he,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:c.map(e=>{let t=!!e.isAdmin,n=y.isPending&&y.variables?.id===e.id;return C(`tr`,{className:`hover:bg-primary/5`,children:[O(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.label}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:O(`span`,{className:`inline-block rounded px-2 py-0.5 text-[10px] uppercase tracking-wide ${t?ce:le}`,children:t?`admin`:`regular`})}),C(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border text-foreground-subtle`,children:ue(e.allowedProviders)||`all`}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.createdAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:C(`button`,{onClick:()=>{S(e.id,e.label)},disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[n?O(N,{className:`h-3 w-3 animate-spin`}):O(R,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),r&&O(pe,{}),m&&O(_e,{users:l.map(e=>({id:e.id,username:e.username})),onClose:()=>h(!1),onSubmit:e=>b.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:b.isPending}),_&&O(ve,{token:_.token,label:_.label,onClose:()=>v(null)})]})}function fe({title:e,subtitle:t,children:n}){return C(`div`,{className:`space-y-2`,children:[C(`div`,{className:`flex items-baseline justify-between`,children:[O(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),t&&O(`span`,{className:`text-[10px] text-foreground-subtle`,children:t})]}),n]})}function pe(){return O(`div`,{className:`space-y-2`,children:[1,2].map(e=>O(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function me({text:e}){return O(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function he({headers:e,rows:t}){return O(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:C(`table`,{className:`w-full text-xs min-w-[640px]`,children:[O(`thead`,{children:O(`tr`,{children:e.map((t,n)=>O(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),O(`tbody`,{children:t})]})})}function ge({userId:e,username:t,onRevoke:n,revokePending:r,revokeId:i}){let{data:a,isLoading:o}=u({userId:e}),s=a??[];return o||s.length===0?null:C(`div`,{className:`space-y-1.5`,children:[O(`div`,{className:`text-[11px] font-medium text-foreground`,children:t}),O(he,{headers:[`Name`,`Prefix`,`Scopes`,`Expires`,`Last used`,`Created`,``],rows:s.map(e=>{let t=r&&i===e.id;return C(`tr`,{className:`hover:bg-primary/5`,children:[O(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.name}),C(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:O(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>C(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:[e.type,`:`,e.type===`device`?`[${e.targets.join(`,`)}]`:e.target]},t))})}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.expiresAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.createdAt)}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:C(`button`,{onClick:()=>n(e.id,e.name),disabled:t,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[t?O(N,{className:`h-3 w-3 animate-spin`}):O(R,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function _e({users:e,onClose:t,onSubmit:n,submitting:r}){let{user:i}=H(),a=i?.isAdmin===!0?null:i?.scopes??[],[o,s]=D(e[0]?.id??``),[c,l]=D(``),[u,d]=D([{type:`capability`,target:``,access:[`view`,`create`]}]),[f,p]=D(``),m=h(u),g=o!==``&&c.trim().length>0&&u.length>0&&m===null&&!r;return C(ye,{title:`Create scoped token`,onClose:t,children:[C(`div`,{className:`space-y-3`,children:[O(Y,{label:`On behalf of user`,children:O(`select`,{value:o,onChange:e=>s(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>O(`option`,{value:e.id,children:e.username},e.id))})}),O(Y,{label:`Name`,children:O(`input`,{value:c,onChange:e=>l(e.target.value),placeholder:`cloudflare-tunnel-route`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})}),C(Y,{label:`Scopes`,hint:`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`,children:[O(y,{value:u,onChange:d,clampToParent:a}),m&&O(`p`,{className:`mt-1 text-[10px] text-danger`,children:m})]}),O(Y,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:O(`input`,{type:`number`,min:1,value:f,onChange:e=>p(e.target.value),placeholder:`30`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})})]}),C(be,{children:[O(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),C(`button`,{onClick:()=>{let e=parseInt(f,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;n({userId:o,name:c.trim(),scopes:u,expiresAt:t})},disabled:!g,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[r?O(N,{className:`h-3.5 w-3.5 animate-spin`}):O(V,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function ve({token:e,label:t,onClose:n}){let[r,i]=D(!1),a=async()=>{try{await navigator.clipboard.writeText(e),i(!0)}catch{}};return C(ye,{title:`Token: ${t}`,onClose:n,children:[C(`div`,{className:`space-y-3`,children:[O(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:`Copy this token now. Once you close this dialog the secret cannot be displayed again.`}),O(`div`,{className:`rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all`,children:e})]}),C(be,{children:[C(`button`,{onClick:()=>{a()},className:`inline-flex items-center gap-1.5 rounded bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[r?O(I,{className:`h-3.5 w-3.5 text-primary`}):O(A,{className:`h-3.5 w-3.5`}),r?`Copied`:`Copy`]}),O(`button`,{onClick:n,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Done`})]})]})}function ye({title:e,onClose:t,children:n}){return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:C(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[C(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[O(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),O(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:O(B,{className:`h-4 w-4`})})]}),O(`div`,{className:`p-4`,children:n})]})})}function be({children:e}){return O(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:e})}function Y({label:e,hint:t,children:n}){return C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:e}),n,t&&O(`p`,{className:`text-[10px] text-foreground-subtle`,children:t})]})}S();function X(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function xe(e){if(e.type===`category`){let t=e.target??``;return t===`device`?`all devices`:`all ${t}`}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function Se(){return O(`div`,{className:`space-y-2`,children:[1,2].map(e=>O(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function Ce({text:e}){return O(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function we({headers:e,rows:t}){return O(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:C(`table`,{className:`w-full text-xs min-w-[640px]`,children:[O(`thead`,{children:O(`tr`,{children:e.map((t,n)=>O(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),O(`tbody`,{children:t})]})})}function Te(){let e=E(),t=o(),{data:n,isLoading:r}=l(),i=w(()=>n??[],[n]),a=c({onSuccess:()=>e.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),s=async(e,n)=>{await t({title:`Revoke "${n}" session?`,message:`This integration will lose access immediately on its next API call. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&a.mutate({id:e})};return C(U,{icon:q,title:`Linked Sessions`,subtitle:`External integrations (Alexa, …) linked to this hub via OAuth. Revoke a session to immediately invalidate that integration's access.`,children:[r&&O(Se,{}),!r&&i.length===0&&O(Ce,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!r&&i.length>0&&O(we,{headers:[`Integration`,`User`,`Scopes`,`Created`,`Last used`,`Status`,``],rows:i.map(e=>{let t=e.revokedAt!==null,n=(a.isPending?a.variables?.id:void 0)===e.id;return C(`tr`,{className:`hover:bg-primary/5`,children:[O(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.integrationId}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:e.username}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:O(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>O(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:xe(e)},t))})}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 border-b border-border`,children:t?C(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-2 py-0.5 text-[10px] text-foreground-subtle`,children:[`Revoked `,X(e.revokedAt)]}):O(`span`,{className:`inline-block rounded bg-emerald-500/15 px-2 py-0.5 text-[10px] text-emerald-700 dark:text-emerald-300`,children:`Active`})}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:!t&&C(`button`,{onClick:()=>{s(e.id,e.integrationId)},disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[n?O(N,{className:`h-3 w-3 animate-spin`}):O(R,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}S();var Z=3e4,Q=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],$={title:`Authentication providers`,subtitle:`Every registered authentication surface in one list: login providers (local password, OIDC, SAML, magic-link) and second-factor providers (passkeys / WebAuthn — configure the relying-party RP ID + origin inline; users enroll from My access → Passkeys). Multiple providers run in parallel — enable/disable each independently. Disabling one only removes that method; local password login is unaffected.`,emptyTitle:`No authentication providers registered`,emptyDescription:`Local auth should always be available — if this list is empty the local-auth builtin failed to register. Check the Addons page for load errors.`,installLabel:`Add provider`};function Ee(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:te,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA is self-enrolled: each user enables it from their own profile page (My access → Two-factor authentication).`,`API keys + scoped tokens are managed from the API Keys page.`],setupSteps:[`Add users from Users → New user (or seed via CAMSTACK_ADMIN_USER / CAMSTACK_ADMIN_PASS).`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:P,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`First-time sign-ins are auto-provisioned with the configured Default Role.`],setupSteps:[`Register a web app at your IdP and copy the client_id + client_secret.`,"Set the redirect URI to `https://<this-hub>/addon/<addon-id>/callback`.",`Paste issuer + credentials in the Settings panel below — saves on every change.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:P,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:z,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)||e.startsWith(`auth-magic-link`)?{headline:`TOTP / magic-link — second factor or passwordless sign-in.`,icon:z,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:V,bullets:[`Generic authentication provider. No additional hints registered.`]}}function De(){let e=b({capName:Q[0].capName},{refetchInterval:Z}),t=b({capName:Q[1].capName},{refetchInterval:Z}),n=m(void 0,{refetchInterval:Z}),r=w(()=>G(n.data??[]),[n.data]),i=w(()=>{let n=[],i=[e.data??[],t.data??[]];for(let[e,t]of Q.entries())for(let a of i[e]??[])n.push({addonId:a.addonId,displayName:r.get(a.addonId)??a.addonId,isActive:a.isActive,capName:t.capName,stageBadge:t.stageBadge});return n},[e.data,t.data,r]);return O(M,{title:$.title,subtitle:$.subtitle,pageIcon:V,itemIcon:V,capability:Q[0].capName,installButtonLabel:$.installLabel,items:i,isLoading:e.isLoading||t.isLoading,emptyTitle:$.emptyTitle,emptyDescription:$.emptyDescription,renderStatusBadges:e=>e.stageBadge===null?null:O(`span`,{className:`inline-flex items-center rounded-full border border-primary/30 bg-primary/10 px-2 py-0.5 text-[10px] font-medium text-primary`,children:e.stageBadge}),renderExpandedPanel:e=>O(Oe,{addonId:e.addonId})})}function Oe({addonId:e}){let t=Ee(e),n=t.icon;return C(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[C(`div`,{className:`flex items-start gap-2.5`,children:[O(n,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),O(`div`,{className:`text-xs text-foreground font-medium`,children:t.headline})]}),O(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:t.bullets.map((e,t)=>O(`li`,{children:e},t))}),t.setupSteps&&t.setupSteps.length>0&&C(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[C(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[O(K,{className:`h-3 w-3`}),`Setup steps`]}),O(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:t.setupSteps.map((e,t)=>O(`li`,{children:e},t))})]}),e===`local-auth`&&C(`div`,{className:`rounded-md border border-blue-500/30 bg-blue-500/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[O(L,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),C(`span`,{children:[`TOTP / 2FA is self-service: each user enrols from their own profile page —`,` `,O(`a`,{href:`/system/my-access`,className:`underline text-primary`,children:`My access`}),` `,`→ “Two-factor authentication” → Enable 2FA. Admins can only remove a user’s active enrollment (lost device) from the`,` `,O(`a`,{href:`/system/users`,className:`underline text-primary`,children:`Users`}),` `,`page via Actions → “Remove 2FA”.`]})]})]})}function ke(){return O(`div`,{className:`flex flex-col p-4`,children:O(W,{tabs:[{id:`users`,label:`Users`,icon:re,content:O(ae,{})},{id:`api-keys`,label:`Tokens`,icon:j,content:O(de,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:q,content:O(Te,{})},{id:`authentication`,label:`Authentication`,icon:V,content:O(De,{})}]})})}export{ke as IdentityPage};
@@ -1 +0,0 @@
1
- import{$n as e,Ao as t,Co as n,Do as r,Eo as i,Ka as a,Ki as o,Oo as s,S as c,So as l,To as u,bo as d,do as f,fo as p,ko as m,lo as h,oo as g,uo as _,wo as v,yo as y}from"./src-CkX4IOdq.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}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{A,D as j,E as ee,L as te,T as M,w as N}from"./src-CUZFIAzy.js";import{p as P}from"./player-overlays-DuTcd1oY.js";import{t as F}from"./circle-check-big-JjHQOVDC.js";import{t as I}from"./copy-BncZJlXn.js";import{t as L}from"./pencil-ChPuHfCU.js";import{t as R}from"./plus-Dw5CKvNT.js";import{t as ne}from"./refresh-cw-_uUkpw3C.js";import{t as z}from"./search-dbMboEvL.js";import{t as re}from"./send-BHfeKQ26.js";import{C as B,G as V,H as ie,P as ae,c as H,i as oe,p as U,s as se}from"./index-B4yaKbnm.js";import{t as W}from"./AdminPage-Dq33XE9j.js";import{t as ce}from"./AdminTabs-DJVKnkBk.js";var le=V(`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`}]]),ue=V(`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`}]]),de=V(`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`}]]),fe=V(`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 G=e=>typeof e==`string`&&e.length>0;function pe(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 me(e,t){return e.format.includes(t)?t:e.format[0]??`text`}function he(e,t){let n=[];for(let r of e.attachments.mediaTypes){if(n.length>=e.attachments.max)break;let i=t[r];G(i)&&n.push({mediaType:r,url:i})}return n}function ge(e,t){if(e.actions<=0)return[];let n=[];for(let r of t){if(n.length>=e.actions)break;let t=G(r.label),i=G(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 _e(e,t){let n=e.levels.some(e=>e.id===t.level)?t.level:void 0,r=he(e,t.attachmentUrls),i=ge(e,t.actions),a=e.ttl&&G(t.ttl)?Number(t.ttl):void 0;return{body:t.body,format:me(e,t.format),priority:ve(t.priority),...G(t.title)?{title:t.title}:{},...n?{level:n}:{},...r.length>0?{attachments:r}:{},...i.length>0?{actions:i}:{},...e.clickUrl&&G(t.clickUrl)?{clickUrl:t.clickUrl}:{},...e.sound&&G(t.sound)?{sound:t.sound}:{},...a!==void 0&&Number.isFinite(a)?{ttl:a}:{},...G(t.tag)?{tag:t.tag}:{}}}function ve(e){return Number.isFinite(e)?Math.min(5,Math.max(1,Math.round(e))):3}function ye(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 be(e){return{level:``,priority:3,format:e.format[0]??`text`,title:``,body:``,attachmentUrls:{},actions:[],clickUrl:``,sound:``,ttl:``,tag:``}}var xe={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 Se(e,t){return e.attachments.max>0&&e.attachments.mediaTypes.includes(t)}function Ce(e){let t=[`text`];for(let n of[`image`,`gif`,`video`,`audio`])Se(e,n)&&t.push(n);return e.actions>0&&t.push(`actions`),e.levels.length>0&&t.push(`critical`),t.push(`overflow`),t}function K(e,t,n){let r=be(e);return Se(e,t)?{...r,body:n,attachmentUrls:{[t]:xe[t]}}:{...r,body:n}}function we(e,t){let n=be(e);switch(t){case`text`:return{...n,title:`CamStack`,body:`Test notification — text only.`};case`image`:return K(e,`image`,`Test notification with an image.`);case`gif`:return K(e,`gif`,`Test notification with an animation.`);case`video`:return K(e,`video`,`Test notification with a video.`);case`audio`:return K(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=ye(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 Te={text:`Text only`,image:`With image`,gif:`With GIF`,video:`With video`,audio:`With audio`,actions:`With buttons`,critical:`Critical`,overflow:`Overflow (advanced)`},q=`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`,J=`block text-[11px] font-medium text-foreground mb-1`;function Ee({target:e,kind:r,open:i,onClose:a}){let o=P(),s=S(()=>pe(r.caps),[r.caps]),c=S(()=>Ce(r.caps),[r.caps]),[u,f]=D(()=>be(r.caps)),[p,h]=D(null),g=S(()=>_e(r.caps,u),[r.caps,u]),_=u.body.length,b=_>s.bodyMaxLen,C=e=>f(t=>({...t,...e})),w=O({mutationFn:()=>o.trpcClient.notificationOutput.testTarget.mutate({addonId:e.addonId,targetId:e.id,sample:_e(r.caps,u)}),onMutate:()=>h(null),onSuccess:e=>h(e),onError:e=>h({success:!1,error:e instanceof Error?e.message:`Test failed`})}),T=e=>{f(we(r.caps,e)),h(null)},E=(e,t,n)=>{let r=u.actions.length>0?[...u.actions]:[];for(;r.length<=e;)r.push({label:``,url:``});r[e]={...r[e],[t]:n},C({actions:r})};return k(y,{open:i,onOpenChange:e=>!e&&a(),children:x(d,{width:`lg`,className:`!max-w-2xl`,children:[k(n,{children:x(v,{children:[`Test "`,e.name,`" (`,r.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(t,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>T(e),children:Te[e]},e))}),x(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[s.levels.length>0&&x(`div`,{children:[k(`label`,{className:J,children:`Level`}),x(`select`,{className:q,value:u.level,onChange:e=>C({level:e.target.value}),children:[k(`option`,{value:``,children:`— derive from priority —`}),s.levels.map(e=>x(`option`,{value:e.id,children:[e.label,e.ordinal===null?` (qualitative)`:` (p${e.ordinal})`]},e.id))]}),(()=>{let e=s.levels.find(e=>e.id===u.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(m,{variant:`danger`,"data-testid":`flag-critical`,children:`critical`}),e.flags?.silent&&k(m,{variant:`info`,children:`silent`}),e.flags?.noPush&&k(m,{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:J,children:[`Priority (ordinal): `,u.priority]}),k(`input`,{type:`range`,min:1,max:5,step:1,value:u.priority,onChange:e=>C({priority:Number(e.target.value)}),className:`w-full accent-primary`,"aria-label":`priority`})]})]}),s.formats.length>0&&x(`div`,{children:[k(`label`,{className:J,children:`Format`}),k(`div`,{className:`flex flex-wrap gap-2`,children:s.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:u.format===e,onChange:()=>C({format:e})}),e]},e))})]}),x(`div`,{children:[k(`label`,{className:J,children:`Title`}),k(`input`,{className:q,value:u.title,onChange:e=>C({title:e.target.value})})]}),x(`div`,{children:[x(`label`,{className:J,children:[`Body`,` `,x(`span`,{className:b?`text-danger`:`text-foreground-subtle`,children:[`(`,_,`/`,s.bodyMaxLen,b?` — overflow`:``,`)`]})]}),k(`textarea`,{className:`${q} min-h-[80px] resize-y`,value:u.body,onChange:e=>C({body:e.target.value})})]}),s.attachmentSlots.length>0&&x(`div`,{children:[x(`label`,{className:J,children:[`Attachments`,` `,x(`span`,{className:`text-foreground-subtle`,children:[`(mode: `,s.attachmentMode,`, max `,s.attachmentMax,s.attachmentMaxBytes?`, ≤${Math.round(s.attachmentMaxBytes/1024/1024)}MB`:``,`)`]})]}),k(`div`,{className:`space-y-1.5`,children:s.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:q,placeholder:`${e} URL`,value:u.attachmentUrls[e]??``,onChange:t=>C({attachmentUrls:{...u.attachmentUrls,[e]:t.target.value}})})]},e))})]}),s.showActions&&x(`div`,{children:[x(`label`,{className:J,children:[`Actions (up to `,s.maxActions,`)`]}),k(`div`,{className:`space-y-1.5`,children:Array.from({length:Math.min(s.maxActions,3)},(e,t)=>x(`div`,{className:`flex items-center gap-2`,children:[k(`input`,{className:q,placeholder:`label`,value:u.actions[t]?.label??``,onChange:e=>E(t,`label`,e.target.value)}),k(`input`,{className:q,placeholder:`url`,value:u.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:[s.showClickUrl&&x(`div`,{children:[k(`label`,{className:J,children:`Click URL`}),k(`input`,{className:q,value:u.clickUrl,onChange:e=>C({clickUrl:e.target.value})})]}),s.showSound&&x(`div`,{children:[k(`label`,{className:J,children:`Sound`}),k(`input`,{className:q,value:u.sound,onChange:e=>C({sound:e.target.value})})]}),s.showTtl&&x(`div`,{children:[k(`label`,{className:J,children:`TTL (seconds)`}),k(`input`,{className:q,type:`number`,value:u.ttl,onChange:e=>C({ttl:e.target.value})})]}),s.showTag&&x(`div`,{children:[k(`label`,{className:J,children:`Tag`}),k(`input`,{className:q,value:u.tag,onChange:e=>C({tag:e.target.value})})]})]}),p&&k(De,{result:p}),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(g,null,2)})]})]}),x(l,{children:[k(t,{variant:`secondary`,size:`sm`,type:`button`,onClick:a,children:`Close`}),x(t,{size:`sm`,type:`button`,disabled:w.isPending||u.body.length===0,onClick:()=>w.mutate(),children:[w.isPending?k(B,{className:`h-3.5 w-3.5 animate-spin`}):k(re,{className:`h-3.5 w-3.5`}),`Send test`]})]})]})})}function De({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(F,{className:`h-3.5 w-3.5 text-success`}):k(ae,{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 Oe(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 ke(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 Ae(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 je(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 Me=[`notificationOutput`,`listTargets`],Ne=[`notificationOutput`,`listTargetKinds`],Pe=[`userManagement`,`listUsers`],Fe=`ownerUserId`;function Ie(e){let t=e.config[Fe];return typeof t==`string`&&t.length>0?t:null}function Le(e){return[{key:`name`,header:`Target`,render:t=>{let n=e.kindByKey.get(t.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??t.kind,children:k(Re,{kind:n,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:``})}),k(`span`,{className:`truncate text-sm font-medium text-foreground`,children:t.name}),!t.enabled&&k(m,{variant:`warning`,children:`disabled`})]})}},{key:`kind`,header:`Kind`,nowrap:!0,render:t=>k(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.kindByKey.get(t.kind)?.label??t.kind})},{key:`owner`,header:`Owner`,nowrap:!0,render:t=>{let n=Ie(t);return n===null?k(m,{variant:`default`,children:`system`}):k(`span`,{className:`text-[11px] text-foreground`,children:e.userNameById.get(n)??n})}},{key:`enabled`,header:`On`,align:`center`,nowrap:!0,render:t=>k(u,{checked:t.enabled,onCheckedChange:n=>e.onToggle(t,n),"aria-label":`toggle ${t.name}`})},{key:`actions`,header:``,align:`right`,nowrap:!0,render:n=>{let r=e.kindByKey.get(n.kind);return x(`span`,{className:`flex items-center justify-end gap-1`,children:[k(t,{size:`sm`,variant:`ghost`,type:`button`,disabled:!r,onClick:()=>e.onTest(n),title:`Test`,children:k(re,{className:`h-3.5 w-3.5`})}),k(t,{size:`sm`,variant:`ghost`,type:`button`,disabled:!r,onClick:()=>r&&e.onEdit(n,r),title:`Edit`,children:k(L,{className:`h-3.5 w-3.5`})}),k(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onDelete(n),title:`Delete`,children:k(H,{className:`h-3.5 w-3.5 text-danger`})})]})}}]}function Re({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 ze(){let e=P(),[n,r]=D({mode:`closed`}),[i,o]=D(null),c=C({queryKey:Me,queryFn:()=>e.trpcClient.notificationOutput.listTargets.query({})}),l=C({queryKey:Ne,queryFn:async()=>(await e.trpcClient.notificationOutput.listTargetKinds.query({})).map(e=>{let t=e.iconUrl;return{...e,configSchema:e.configSchema,iconUrl:t}})}),u=S(()=>l.data??[],[l.data]),d=S(()=>{let e=new Map;for(let t of u)e.set(t.kind,t);return e},[u]),f=C({queryKey:Pe,queryFn:()=>e.trpcClient.userManagement.listUsers.query()}),p=S(()=>{let e=new Map;for(let t of f.data??[])e.set(t.id,t.username);return e},[f.data]),m=O({mutationFn:t=>e.trpcClient.notificationOutput.setTargetEnabled.mutate({addonId:t.target.addonId,targetId:t.target.id,enabled:t.enabled}),onSuccess:()=>void c.refetch()}),h=O({mutationFn:t=>e.trpcClient.notificationOutput.deleteTarget.mutate({addonId:t.addonId,targetId:t.id}),onSuccess:()=>void c.refetch()}),_=i?d.get(i.kind):void 0;return x(W,{icon:ie,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(t,{size:`sm`,type:`button`,onClick:()=>r({mode:`pick-kind`}),children:[k(R,{className:`h-3.5 w-3.5`}),`Add target`]}),children:[c.isLoading&&k(`div`,{className:`flex items-center justify-center py-16`,children:k(B,{className:`h-6 w-6 animate-spin text-primary`})}),c.isError&&!c.isLoading&&k(a,{title:`Failed to load targets`,message:c.error instanceof Error?c.error.message:`Unknown error`,onRetry:()=>void c.refetch()}),!c.isLoading&&!c.isError&&(c.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.`}),(c.data??[]).length>0&&k(s,{children:k(g,{columns:Le({kindByKey:d,userNameById:p,onToggle:(e,t)=>m.mutate({target:e,enabled:t}),onTest:o,onEdit:(e,t)=>r({mode:`form`,kind:t,target:e}),onDelete:e=>h.mutate(e)}),rows:c.data??[],rowKey:e=>e.id,minWidthPx:720,bordered:!1})}),n.mode===`pick-kind`&&k(Be,{kinds:u,onCancel:()=>r({mode:`closed`}),onPick:e=>r({mode:`form`,kind:e,target:null})}),n.mode===`form`&&k(Ve,{kind:n.kind,target:n.target,users:f.data??[],onCancel:()=>r({mode:`closed`}),onSaved:()=>{r({mode:`closed`}),c.refetch()}}),i&&_&&k(Ee,{target:i,kind:_,open:!0,onClose:()=>o(null)})]})}function Be({kinds:e,onPick:n,onCancel:r}){let i=S(()=>Oe(e),[e]);return x(s,{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(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:r,children:`Cancel`})]}),i.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.`}),i.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(t=>x(`button`,{type:`button`,onClick:()=>n(t),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(Re,{kind:t,imgClassName:`h-7 w-7 object-contain`,fallbackClassName:`text-lg leading-7`}),k(`span`,{className:`font-medium text-foreground`,children:t.label}),t.supportsDiscovery&&k(m,{variant:`info`,style:`outline`,children:`discover`})]},`${e.addonId}:${t.kind}`))})]},e.addonId))]})}function Ve({kind:e,target:n,users:r,onSaved:a,onCancel:o}){let l=P(),u=S(()=>ke(e.configSchema),[e.configSchema]),d=S(()=>n?.config??{},[n]),[f,p]=D(n?.name??e.label),[m,h]=D(()=>n?je(n.config,u):{}),[g,_]=D(null),[v,y]=D(null),[b,C]=D(n?Ie(n)??``:``),w=O({mutationFn:()=>l.trpcClient.notificationOutput.discoverTargets.query({addonId:e.addonId,kind:e.kind,config:m}),onSuccess:e=>_(e),onError:e=>y(e instanceof Error?e.message:`Discovery failed`)}),T=O({mutationFn:()=>{let{[Fe]:t,...r}=Ae(m,d,u),i=b===``?r:{...r,[Fe]:b},a={id:n?.id??`${e.kind}-${Date.now()}`,name:f,kind:e.kind,addonId:e.addonId,enabled:n?.enabled??!0,config:i};return l.trpcClient.notificationOutput.upsertTarget.mutate({addonId:e.addonId,target:a})},onSuccess:a,onError:e=>y(e instanceof Error?e.message:`Save failed`)}),E=e=>{p(e.suggestedName),h(t=>({...t,...e.config})),_(null)};return x(s,{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(Re,{kind:e,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:`text-lg`}),n?`Edit ${n.name}`:`Add ${e.label} target`]}),k(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:o,children:`Cancel`})]}),v&&k(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:v}),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:f,onChange:e=>p(e.target.value)})]}),x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Owner`}),k(i,{value:b,options:[{value:``,label:`System (shared, admin-managed)`},...r.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(t,{size:`sm`,variant:`outline`,type:`button`,disabled:w.isPending,onClick:()=>{y(null),w.mutate()},children:[w.isPending?k(B,{className:`h-3.5 w-3.5 animate-spin`}):k(z,{className:`h-3.5 w-3.5`}),`Discover`]}),g&&g.length===0&&k(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No candidates discovered.`}),g&&g.length>0&&k(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:g.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}`))})]}),u.length>0&&n&&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:m,onChange:h}),x(`div`,{className:`flex justify-end gap-2`,children:[k(t,{variant:`secondary`,size:`sm`,type:`button`,onClick:o,children:`Cancel`}),x(t,{size:`sm`,type:`button`,disabled:T.isPending||f.trim().length===0,onClick:()=>{y(null),T.mutate()},children:[T.isPending&&k(B,{className:`h-3.5 w-3.5 animate-spin`}),n?`Save changes`:`Create target`]})]})]})}var He=[{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`}],Ue={sequences:[],buttons:[]};function We(e){return e===void 0?Ue:{sequences:[...e.onTrigger??[]],buttons:[...e.buttons??[]]}}function Ge(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 Ke(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 qe(e){return{name:`sequence ${String(e+1)}`,enabled:!1,actions:[]}}function Je(e,t){return{id:`action-${String(e+1)}`,label:`Action`,sequence:t}}function Ye(){return{kind:`wait`,seconds:5}}var Y=`mt-1 w-full rounded border border-border bg-background px-2 py-1 text-xs`,X=`block text-[11px] font-medium text-foreground`;function Xe({value:e,onChange:n,devices:r}){let i=Ke(e),a=(t,r)=>n({...e,sequences:e.sequences.map((e,n)=>n===t?r:e)}),o=(t,r)=>n({...e,buttons:e.buttons.map((e,n)=>n===t?r:e)});return x(`div`,{className:`space-y-4`,children:[i.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:i.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(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>n({...e,sequences:[...e.sequences,qe(e.sequences.length)]}),children:[k(R,{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((t,i)=>k(Ze,{sequence:t,devices:r,onChange:e=>a(i,e),onRemove:()=>n({...e,sequences:e.sequences.filter((e,t)=>t!==i)})},`seq-${String(i)}`))]}),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(t,{size:`sm`,variant:`ghost`,type:`button`,disabled:e.sequences.length===0,onClick:()=>n({...e,buttons:[...e.buttons,Je(e.buttons.length,e.sequences[0]?.name??``)]}),children:[k(R,{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(se,{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((t,r)=>k(et,{button:t,sequenceNames:e.sequences.map(e=>e.name),onChange:e=>o(r,e),onRemove:()=>n({...e,buttons:e.buttons.filter((e,t)=>t!==r)})},`btn-${String(r)}`))]})]})}function Ze({sequence:e,devices:n,onChange:i,onRemove:a}){let o=(t,n)=>i({...e,actions:e.actions.map((e,r)=>r===t?n:e)});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:X,children:`Name`}),k(r,{className:`mt-1`,value:e.name,onChange:t=>i({...e,name:t.target.value})})]}),x(`div`,{className:`w-28`,children:[k(`label`,{className:X,children:`Min delay (s)`}),k(`input`,{type:`number`,min:0,className:Y,value:e.minDelaySec??``,onChange:t=>{let n=t.target.value,r={...e};n===``?delete r.minDelaySec:r.minDelaySec=Number(n),i(r)}})]}),x(`div`,{className:`flex items-center gap-2 pb-1`,children:[k(u,{checked:e.enabled,onCheckedChange:t=>i({...e,enabled:t})}),k(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.enabled?`Runs on match`:`Only when a button is tapped`})]}),k(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:a,title:`Remove`,children:k(H,{className:`h-3.5 w-3.5`})})]}),x(`div`,{className:`space-y-2 border-l-2 border-border-subtle pl-3`,children:[e.actions.map((t,r)=>k(Qe,{step:t,devices:n,onChange:e=>o(r,e),onRemove:()=>i({...e,actions:e.actions.filter((e,t)=>t!==r)})},`step-${String(r)}`)),x(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>i({...e,actions:[...e.actions,Ye()]}),children:[k(R,{className:`h-3.5 w-3.5`}),` Step`]})]})]})}function Qe({step:e,devices:n,onChange:r,onRemove:i}){return x(`div`,{className:`flex flex-wrap items-end gap-2`,children:[x(`div`,{className:`w-24`,children:[k(`label`,{className:X,children:`Step`}),x(`select`,{className:Y,value:e.kind,onChange:e=>r(e.target.value===`wait`?{kind:`wait`,seconds:5}:{kind:`cap`,deviceId:n[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:X,children:`Seconds`}),k(`input`,{type:`number`,min:0,max:300,className:Y,value:e.seconds,onChange:e=>r({kind:`wait`,seconds:Number(e.target.value)})})]}):k($e,{step:e,devices:n,onChange:r}),k(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:i,title:`Remove step`,children:k(H,{className:`h-3.5 w-3.5`})})]})}function $e({step:e,devices:t,onChange:n}){let i=P(),a=C({queryKey:[`deviceManager`,`getBindings`,e.deviceId],enabled:e.deviceId>0,staleTime:6e4,queryFn:async()=>{let t=await i.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:X,children:`Device`}),x(`select`,{className:Y,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:X,children:`Capability`}),x(`select`,{className:Y,value:e.cap,disabled:a.length===0,onChange:t=>n({...e,cap:t.target.value,method:``}),children:[k(`option`,{value:``,children:a.length===0?`No devices bound`:`Select…`}),a.map(e=>k(`option`,{value:e,children:e},e))]})]}),x(`div`,{className:`min-w-[7rem] flex-1`,children:[k(`label`,{className:X,children:`Method`}),k(r,{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:X,children:`Arguments (JSON)`}),k(r,{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 et({button:e,sequenceNames:n,onChange:i,onRemove:a}){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:X,children:`Label`}),k(r,{className:`mt-1`,value:e.label,onChange:t=>i({...e,label:t.target.value})})]}),x(`div`,{className:`min-w-[8rem] flex-1`,children:[k(`label`,{className:X,children:`Runs`}),x(`select`,{className:Y,value:e.sequence,onChange:t=>i({...e,sequence:t.target.value}),children:[!n.includes(e.sequence)&&x(`option`,{value:e.sequence,children:[e.sequence,` (missing)`]}),n.map(e=>k(`option`,{value:e,children:e},e))]})]}),x(`div`,{className:`w-32`,children:[k(`label`,{className:X,children:`Icon`}),x(`select`,{className:Y,value:e.icon??``,onChange:t=>{let n={...e};if(t.target.value===``)delete n.icon;else{let e=He.find(e=>e.value===t.target.value);e!==void 0&&(n.icon=e.value)}i(n)},children:[k(`option`,{value:``,children:`None`}),He.map(e=>k(`option`,{value:e.value,children:e.label},e.value))]})]}),x(`div`,{className:`flex items-center gap-2 pb-1`,children:[k(u,{checked:e.destructive===!0,onCheckedChange:t=>{let n={...e};t?n.destructive=!0:delete n.destructive,i(n)}}),k(m,{variant:e.destructive===!0?`danger`:`default`,children:`Destructive style`})]}),k(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:a,title:`Remove`,children:k(H,{className:`h-3.5 w-3.5`})})]})}var tt={search:``,types:[],selectedOnly:!1};function nt(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 rt(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 it(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 at(e,t){let n=new Set(t);for(let t of e)n.add(t.id);return[...n]}function ot(e,t){let n=new Set(e.map(e=>e.id));return t.filter(e=>!n.has(e))}function st(e,t){return e.length===0?`Every device (${String(t)}) — no restriction`:`${String(e.length)} of ${String(t)} selected`}b();function ct({devices:e,value:n,onChange:i,loading:a=!1}){let[o,s]=D(tt),c=S(()=>nt(e),[e]),l=S(()=>rt(e,o,n),[e,o,n]),u=S(()=>it(l),[l]),d=e=>s(t=>({...t,types:t.types.includes(e)?t.types.filter(t=>t!==e):[...t.types,e]})),f=e=>i(n.includes(e)?n.filter(t=>t!==e):[...n,e]);return a?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:st(n,e.length)}),x(`div`,{className:`flex items-center gap-1`,children:[k(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>i(at(l,n)),children:`Select shown`}),k(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>i(ot(l,n)),children:`Clear shown`})]})]}),x(`div`,{className:`flex flex-wrap items-center gap-2`,children:[k(r,{className:`min-w-[10rem] flex-1`,value:o.search,placeholder:`Search by name…`,leftSlot:k(z,{className:`h-3.5 w-3.5 text-foreground-subtle`}),onChange:e=>s(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:o.selectedOnly,onChange:e=>s(t=>({...t,selectedOnly:e.target.checked}))}),`Selected only`]})]}),k(`div`,{className:`flex flex-wrap gap-1`,children:c.map(e=>x(`button`,{type:`button`,onClick:()=>d(e.type),className:o.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))}),l.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:u.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:n.includes(e.id),onChange:()=>f(e.id),className:`accent-primary`}),k(`span`,{className:`flex-1 truncate`,children:e.name}),k(m,{variant:`default`,children:e.type})]},e.id))})]},e.location??`__unplaced`))})]})}function Z(e){return t=>Object.prototype.hasOwnProperty.call(e,t)}var lt=Z({devices:!0}),ut=Z({classes:!0,classesExclude:!0,labelEquals:!0,identities:!0,identitiesExclude:!0,eventTypeTokens:!0,sensorKinds:!0}),dt=Z({zonesExclude:!0}),ft=Z({minConfidence:!0,minImportance:!0,minLabelConfidence:!0}),pt=Z({minDwellSeconds:!0}),mt=Z({source:!0}),ht=Z({crossing:!0}),gt=Z({packagePhase:!0}),_t=Z({zones:!0}),vt=Z({plates:!0}),yt=Z({occupancy:!0}),bt=Z({deviceState:!0});function Q(e,t){let n=e[t];return Array.isArray(n)?n:[]}function xt(e,t){let n=e[t];return typeof n==`number`?n:void 0}var St=[{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 Ct(e){let t=e.replace(/[-_]/g,` `);return t.charAt(0).toUpperCase()+t.slice(1)}function wt(e,t){let n=e.filter(t),r=new Set(St.map(e=>e.id)),i=[];for(let e of St){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:Ct(e),descriptors:n.filter(t=>t.group===e)});return i}b();function Tt(e,t){let n=P().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 Et(e){let t=P().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 Dt(){let t=e();return S(()=>({options:(t.data??[]).map(e=>({value:e.name,label:e.name})),loading:t.isLoading}),[t.data,t.isLoading])}function Ot(){let e=o({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 kt({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 $=[{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.`}];function At(e){return $.find(t=>t.value===e)?.label??e}function jt(e){return $.find(t=>t.value===e)?.value}var Mt=[{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 Nt(e){return Mt.find(t=>t.value===e)?.value}var Pt=[{value:``,label:`Automatic`},{value:`cropped`,label:`Cropped on the subject`},{value:`full`,label:`Full frame`},{value:`boxed`,label:`Full frame with boxes`}];function Ft(e){let t=Pt.find(t=>t.value===e)?.value;return t===``?void 0:t}var It=[{value:``,label:`Lowest available`},{value:`low`,label:`Low`},{value:`mid`,label:`Medium`},{value:`high`,label:`High`}];function Lt(e){let t=It.find(t=>t.value===e)?.value;return t===``?void 0:t}var Rt=[{value:`any`,label:`Any source`},{value:`pipeline`,label:`Pipeline`},{value:`onboard`,label:`Onboard (camera)`},{value:`sensor`,label:`Sensor`}],zt=[{value:`delivered`,label:`Delivered`},{value:`picked-up`,label:`Picked up`},{value:`both`,label:`Both`}],Bt=[{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 Vt(e){let t=Bt.find(t=>t.value===e)?.value;return t===``||t===void 0?void 0:t}var Ht=[{value:`any`,label:`Any of`},{value:`all`,label:`All of`}],Ut=[{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 Wt(){return{name:``,enabled:!0,delivery:`immediate`,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:Ue,deviceIds:[]}}function Gt(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:We(e.actions),deviceIds:e.conditions.devices??[]}}function Kt(e){return e.name.trim().length>0&&(e.targetIds.length>0||e.targetUsers.length>0)&&Ke(e.actions).length===0}function qt(e,t){return e.appliesTo.includes(t)}var Jt={source:`any`};function Yt(e,t){if(t==null)return!0;if(Array.isArray(t))return t.length===0;if(typeof t==`string`)return t.length===0||Jt[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 Xt(e,t,n){let r=n.length===0?null:new Set(n.filter(e=>e.id!==`schedule`&&qt(e,t)).map(e=>e.id)),i={};for(let[t,n]of Object.entries(e))r!==null&&!r.has(t)||Yt(t,n)||(i[t]=n);return i}function Zt(e){return e!==void 0&&e.windows.length>0}function Qt(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=Ge(e.actions),s=(n.length===0||n.some(t=>t.id===`schedule`&&qt(t,e.delivery)))&&Zt(e.schedule)?e.schedule:void 0;return{name:e.name.trim(),enabled:e.enabled,delivery:e.delivery,conditions:{...Xt(e.conditions,e.delivery,n),...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:{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:t?.throttle??{cooldownSec:60,scope:`rule-device`},priority:e.priority,...a?{template:a}:{},...e.snoozeAllowGlobal?{snoozeAllowGlobal:!0}:{},...o===void 0?{}:{actions:o}}}function $t(e,t){return e.options&&e.options.length>0?e.options:t}var en=[{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 tn(e){if(e===``)return;let t=Number(e);return Number.isFinite(t)&&t>=1&&t<=8?t:void 0}var nn=[{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`]}],rn=`rule`;function an(e){return nn.find(t=>t.key===e)?.key}b();var on=`block text-[11px] font-medium text-foreground`,sn=`text-[10px] text-foreground-subtle mt-0.5`;function cn({cameras:e,value:t,onChange:n}){if(e.length===0)return k(`p`,{className:sn,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 ln({value:e,placeholder:t,onChange:n}){let[i,a]=D(``),o=()=>{let t=i.trim();if(t.length===0||e.includes(t)){a(``);return}n([...e,t]),a(``)},s=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:()=>s(e),"aria-label":`remove ${e}`,className:`text-foreground-subtle hover:text-danger`,children:k(oe,{className:`h-3 w-3`})})]},e))}),k(r,{value:i,placeholder:t,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),o())},onBlur:o})]})}function un({picker:e,value:t,onChange:n}){let r=S(()=>ee(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 dn({value:e,min:t,max:n,step:i,onChange:a}){return x(`div`,{className:`mt-1 flex items-center gap-2`,children:[k(r,{type:`number`,value:e??``,min:t,max:n,step:i,className:`max-w-[8rem]`,onChange:e=>{let t=e.target.value;if(t===``){a(void 0);return}let n=Number(t);a(Number.isFinite(n)?n:void 0)}}),e!==void 0&&n!==void 0&&k(`input`,{type:`range`,min:t,max:n,step:i,value:e,onChange:e=>a(Number(e.target.value)),className:`flex-1 accent-primary`,"aria-label":`value`})]})}function fn({value:e,onChange:t,options:n}){let r=e??``,a=n&&n.length>0?n:Bt,o=a.find(e=>e.value===r);return x(`div`,{className:`mt-1 space-y-1`,children:[k(i,{value:r,options:a.map(e=>({value:e.value,label:e.label})),onChange:e=>t(Vt(e.target.value))}),o!==void 0&&k(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:o.hint})]})}function pn({deviceIds:e,cameras:t,value:n,onChange:r}){let a=n?.ids??[],o=n?.match??`any`,s=e=>r(e.length>0?{ids:e,match:o}:void 0),c=e=>r(a.length>0?{ids:a,match:e}:void 0);return x(`div`,{className:`mt-1 space-y-1.5`,children:[k(`div`,{className:`max-w-[10rem]`,children:k(i,{value:o,options:Ht.map(e=>({value:e.value,label:e.label})),onChange:e=>c(e.target.value===`all`?`all`:`any`)})}),k(mn,{deviceIds:e,cameras:t,value:a,onChange:s})]})}function mn({deviceIds:e,cameras:t,value:n,onChange:r}){let{options:i,loading:a}=Tt(e,t);return k(kt,{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 hn({value:e,onChange:t}){let{options:n,loading:r}=Dt();return k(kt,{options:n,value:e,onChange:t,loading:r,emptyHint:`No identities in the face gallery yet — type a name.`,placeholder:`Identity name…`})}function gn({deviceIds:e,value:t,onChange:n}){let{options:r,loading:i}=Et(e);return k(kt,{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 _n=[{value:`became-occupied`,label:`Became occupied`},{value:`became-free`,label:`Became free`},{value:`>=`,label:`Count ≥`},{value:`<=`,label:`Count ≤`}],vn={op:`became-occupied`,count:1,sustainSeconds:15};function yn({deviceIds:e,cameras:t,classOptions:n,value:a,onChange:o}){let{options:s,loading:c}=Tt(e,t),l=a??vn,u=e=>o({...l,...e}),d=l.op===`became-occupied`||l.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(i,{value:l.zoneId??``,options:[{value:``,label:c?`Loading zones…`:`— whole frame —`},...s.map(e=>({value:e.value,label:e.label}))],onChange:e=>u({zoneId:e.target.value===``?void 0:e.target.value})})}),k(`div`,{className:`min-w-[9rem]`,children:k(i,{value:l.className??``,options:[{value:``,label:`— any class —`},...n.map(e=>({value:e.value,label:e.label}))],onChange:e=>u({className:e.target.value===``?void 0:e.target.value})})}),k(`div`,{className:`min-w-[9rem]`,children:k(i,{value:l.op,options:_n.map(e=>({value:e.value,label:e.label})),onChange:e=>{let t=_n.find(t=>t.value===e.target.value);t&&u({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:[d?`Threshold`:`Count`,k(r,{type:`number`,min:0,className:`w-16`,value:String(l.count),onChange:e=>u({count:Math.max(0,Number(e.target.value)||0)})})]}),x(`label`,{className:`flex items-center gap-1`,children:[`Hold for`,k(r,{type:`number`,min:0,max:3600,className:`w-16`,value:String(l.sustainSeconds),onChange:e=>u({sustainSeconds:Math.min(3600,Math.max(0,Number(e.target.value)||0))})}),`s`]}),a===void 0?null:k(`button`,{type:`button`,onClick:()=>o(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 bn({value:e,onChange:t}){let n=e?.values??[],i=e?.maxDistance??1,a=e=>t(e.length>0?{values:e,maxDistance:i}:void 0),o=e=>t(n.length>0?{values:n,maxDistance:e}:void 0),s=Ot().filter(e=>!n.includes(e));return x(`div`,{className:`mt-1 space-y-1.5`,children:[k(ln,{value:n,placeholder:`Plate text…`,onChange:a}),s.length>0&&x(`div`,{className:`flex flex-wrap items-center gap-1`,children:[k(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Seen:`}),s.slice(0,12).map(e=>k(`button`,{type:`button`,onClick:()=>a([...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(r,{type:`number`,min:0,max:3,step:1,value:i,className:`max-w-[5rem]`,onChange:e=>{let t=Number(e.target.value);o(Number.isFinite(t)?Math.max(0,Math.min(3,t)):1)}})]})]})}function xn({gateable:e,value:t,onChange:n}){let r=e.find(e=>e.id===t?.deviceId),a=new Set(t?.states??[]),o=e=>{let t=Number(e);if(!Number.isFinite(t)||t===0)return n(void 0);n({deviceId:t,states:[]})},s=e=>{if(t===void 0)return;let r=new Set(a);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(i,{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=>o(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:()=>s(e),className:a.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 Sn=[{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 Cn(e){let t=Math.floor(e/60),n=e%60;return`${String(t).padStart(2,`0`)}:${String(n).padStart(2,`0`)}`}function wn(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 Tn(){return{days:[1,2,3,4,5],startMinute:540,endMinute:1080}}function En({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,Tn()],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:sn,children:`Always active — add a window to restrict when the rule fires.`}):n.map((e,t)=>k(Dn,{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(R,{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 Dn({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:Cn(e.startMinute),onChange:n=>t({...e,startMinute:wn(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:Cn(e.endMinute),onChange:n=>t({...e,endMinute:wn(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(H,{className:`h-3.5 w-3.5`})})]}),k(`div`,{className:`flex flex-wrap gap-1`,children:Sn.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))})]})}b();function On({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(()=>wt(e,e=>e.id!==`devices`&&M(e.id)),[e]),d=S(()=>wt(e,e=>e.id!==`devices`&&!M(e.id)),[e]),[f,p]=D(()=>{if(An(r,i))return!0;try{return localStorage.getItem(kn)===`1`}catch{return!1}}),h=()=>{let e=!f;p(e);try{localStorage.setItem(kn,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=qt(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:on,children:e.label}),!s&&x(m,{variant:`default`,children:[`not for `,e.appliesTo.join(` / `)]})]}),s?k(jn,{descriptor:e,taxonomy:t,conditions:r,schedule:i,cameras:a,gateable:o,onFieldChange:l,onScheduleChange:c}):k(`p`,{className:sn,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 kn=`camstack.nc.showAdvanced`;function An(e,t){for(let[t,n]of Object.entries(e))if(!M(t)&&n!==void 0&&!(Array.isArray(n)&&n.length===0))return!0;return t!==void 0&&t.windows.length>0}function jn({descriptor:e,taxonomy:t,conditions:n,schedule:r,cameras:a,gateable:o,onFieldChange:s,onScheduleChange:c}){switch(e.valueType){case`deviceIdList`:{if(!lt(e.id))break;let t=e.id;return k(cn,{cameras:a,value:n[t]??[],onChange:e=>s(t,e.length>0?e:void 0)})}case`stringList`:{if(!ut(e.id))break;let r=e.id,i=e=>s(r,e.length>0?e:void 0);if(r===`identities`||r===`identitiesExclude`)return k(hn,{value:Q(n,r),onChange:i});if(r===`eventTypeTokens`)return k(gn,{deviceIds:n.devices??[],value:Q(n,r),onChange:i});let a=j(r,t);return a===null?k(ln,{value:Q(n,r),placeholder:`Add value…`,onChange:i}):k(un,{picker:a,value:Q(n,r),onChange:i})}case`zoneIdList`:{if(!dt(e.id))break;let t=e.id;return k(mn,{deviceIds:n.devices??[],cameras:a,value:Q(n,t),onChange:e=>s(t,e.length>0?e:void 0)})}case`number01`:{if(!ft(e.id))break;let t=e.id;return k(dn,{value:xt(n,t),min:0,max:1,step:.05,onChange:e=>s(t,e)})}case`number`:{if(!pt(e.id))break;let t=e.id;return k(dn,{value:xt(n,t),min:0,step:1,onChange:e=>s(t,e)})}case`sourceSelect`:{if(!mt(e.id))break;let t=e.id;return k(i,{value:n[t]??`any`,options:$t(e,Rt).map(e=>({value:e.value,label:e.label})),onChange:e=>s(t,Pn(e.target.value))})}case`deviceState`:if(!bt(e.id))break;return k(xn,{gateable:o,value:n.deviceState,onChange:e=>s(`deviceState`,e)});case`crossingSelect`:{if(!ht(e.id))break;let t=e.id;return k(fn,{value:n[t],onChange:e=>s(t,e),...e.options?{options:e.options}:{}})}case`packagePhase`:{if(!gt(e.id))break;let t=e.id;return k(i,{value:n[t]??``,options:[{value:``,label:`— any phase —`},...$t(e,zt).map(e=>({value:e.value,label:e.label}))],onChange:e=>s(t,Fn(e.target.value))})}case`zoneSelection`:{if(!_t(e.id))break;let t=e.id;return k(pn,{deviceIds:n.devices??[],cameras:a,value:n[t],onChange:e=>s(t,e)})}case`plateMatcher`:{if(!vt(e.id))break;let t=e.id;return k(bn,{value:n[t],onChange:e=>s(t,e)})}case`occupancy`:{if(!yt(e.id))break;let r=e.id;return k(yn,{deviceIds:n.devices??[],cameras:a,classOptions:Mn(t),value:n[r],onChange:e=>s(r,e)})}case`schedule`:return k(En,{value:r,onChange:c});default:break}return k(Nn,{descriptor:e,conditions:n})}function Mn(e){let t=j(`classes`,e);return t===null?[]:t.groups.flatMap(e=>e.options)}function Nn({descriptor:e,conditions:t}){let n=Object.entries(t).find(([t])=>t===e.id);return x(`p`,{className:sn,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 Pn(e){if(e===`pipeline`||e===`onboard`||e===`sensor`||e===`any`)return e}function Fn(e){return zt.find(t=>t.value===e)?.value}b();var In=[`notificationRules`,`listSnoozes`],Ln=3e4;function Rn(e,t){return Math.max(0,Math.ceil((e.expiresAt-t)/6e4))}function zn(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 Bn({rules:e}){let n=P(),r=E(),i=C({queryKey:In,refetchInterval:Ln,queryFn:async()=>(await n.trpcClient.notificationRules.listSnoozes.query({})).snoozes}),a=O({mutationFn:e=>n.trpcClient.notificationRules.cancelSnooze.mutate({snoozeId:e}),onSuccess:()=>r.invalidateQueries({queryKey:In})}),o=S(()=>{let t=new Map;for(let n of e)t.set(n.id,n.name);return t},[e]),c=Date.now(),l=(i.data??[]).filter(e=>c>=e.startedAt&&c<e.expiresAt);return l.length===0?null:x(s,{className:`p-4`,children:[x(`div`,{className:`flex items-center gap-2 mb-3`,children:[k(le,{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:l.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??`?`}`:o.get(e.ruleId??``)??`A rule`}),e.global&&k(m,{variant:`warning`,className:`text-[10px]`,children:`everyone`}),!e.summary&&k(m,{variant:`default`,className:`text-[10px]`,children:`no summary`})]}),x(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`set by `,e.userId,` · `,zn(Rn(e,c))]})]}),k(t,{size:`sm`,variant:`outline`,disabled:a.isPending,onClick:()=>a.mutate(e.id),children:`End now`})]},e.id))})]})}b();var Vn=[`notificationRules`,`listRules`],Hn=[`notificationOutput`,`listTargets`,`forRules`],Un=[`notificationRules`,`getConditionCatalog`],Wn=[`deviceManager`,`listAll`,`forRules`],Gn=[`deviceManager`,`listAll`,`forRuleActions`],Kn=[`deviceManager`,`gateableDevices`],qn=N.options;function Jn(){let e=P(),[n,r]=D({mode:`closed`}),[i,o]=D(null),c=C({queryKey:Vn,queryFn:async()=>(await e.trpcClient.notificationRules.listRules.query({})).rules}),l=C({queryKey:Hn,queryFn:()=>e.trpcClient.notificationOutput.listTargets.query({})}),u=C({queryKey:Un,queryFn:()=>e.trpcClient.notificationRules.getConditionCatalog.query({})}),d=C({queryKey:Kn,queryFn:async()=>{let t=await e.trpcClient.deviceManager.listAll.query({}),n=[];for(let r of t){let t=te(await e.trpcClient.deviceManager.loadRuntimeState.query({deviceId:r.id}),qn);t.length>0&&n.push({id:r.id,name:r.name,states:t})}return n},staleTime:6e4}),f=C({queryKey:Gn,queryFn:async()=>(await e.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}),p=C({queryKey:Wn,queryFn:async()=>(await e.trpcClient.deviceManager.listAll.query({})).filter(e=>e.type===A.Camera).map(e=>({id:e.id,name:e.name}))}),m=S(()=>{let e=new Map;for(let t of l.data??[])e.set(t.id,t.name);return e},[l.data]),h=O({mutationFn:t=>e.trpcClient.notificationRules.setRuleEnabled.mutate(t),onSuccess:()=>void c.refetch()}),_=O({mutationFn:t=>e.trpcClient.notificationRules.deleteRule.mutate({ruleId:t}),onSuccess:()=>{o(null),c.refetch()}}),v=c.data??[];return x(W,{icon:ue,title:`Notification Rules`,subtitle:`Author rules that turn detections, doorbell presses and package events into notifications. Each rule picks a trigger, matches conditions and fans out to one or more delivery targets.`,actions:x(t,{size:`sm`,type:`button`,onClick:()=>r({mode:`form`,rule:null}),children:[k(R,{className:`h-3.5 w-3.5`}),`New rule`]}),children:[k(Bn,{rules:v}),c.isLoading&&k(`div`,{className:`flex items-center justify-center py-16`,children:k(B,{className:`h-6 w-6 animate-spin text-primary`})}),c.isError&&!c.isLoading&&k(a,{title:`Failed to load rules`,message:c.error instanceof Error?c.error.message:`Unknown error`,onRetry:()=>void c.refetch()}),!c.isLoading&&!c.isError&&v.length===0&&k(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No notification rules yet. Click "New rule" to author one.`}),v.length>0&&k(s,{children:k(g,{columns:Yn({targetNameById:m,confirmDeleteId:i,deletePending:_.isPending,onToggle:(e,t)=>h.mutate({ruleId:e.id,enabled:t}),onEdit:e=>r({mode:`form`,rule:e}),onDuplicate:e=>r({mode:`form`,rule:{...e,id:``,name:`${e.name} (copy)`}}),onAskDelete:o,onConfirmDelete:e=>_.mutate(e.id)}),rows:v,rowKey:e=>e.id,minWidthPx:760,bordered:!1})}),n.mode===`form`&&k(Xn,{rule:n.rule,targets:l.data??[],actuatable:f.data??[],catalog:u.data?.catalog??[],taxonomy:u.data?.taxonomy,cameras:p.data??[],gateable:d.data??[],onCancel:()=>r({mode:`closed`}),onSaved:()=>{r({mode:`closed`}),c.refetch()}})]})}function Yn(e){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(m,{variant:`warning`,children:`disabled`})]})},{key:`trigger`,header:`Trigger`,nowrap:!0,render:e=>k(`span`,{className:`text-[11px] text-foreground-subtle`,children:At(e.delivery)})},{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:`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:t=>k(u,{checked:t.enabled,onCheckedChange:n=>e.onToggle(t,n),"aria-label":`toggle ${t.name}`})},{key:`actions`,header:``,align:`right`,nowrap:!0,render:n=>x(`span`,{className:`flex items-center justify-end gap-1`,children:[k(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onEdit(n),title:`Edit`,children:k(L,{className:`h-3.5 w-3.5`})}),k(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onDuplicate(n),title:`Duplicate`,children:k(I,{className:`h-3.5 w-3.5`})}),e.confirmDeleteId===n.id?x(w,{children:[x(t,{size:`sm`,variant:`danger`,type:`button`,disabled:e.deletePending,onClick:()=>e.onConfirmDelete(n),children:[e.deletePending&&k(B,{className:`h-3.5 w-3.5 animate-spin`}),`Confirm`]}),k(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onAskDelete(null),children:`Cancel`})]}):k(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onAskDelete(n.id),title:`Delete`,children:k(H,{className:`h-3.5 w-3.5 text-danger`})})]})}]}function Xn({rule:e,targets:n,catalog:a,taxonomy:o,cameras:s,gateable:c,actuatable:l,onSaved:g,onCancel:v}){let b=P(),S=e!=null&&e.id.length>0,[w,T]=D(()=>e?Gt(e):Wt()),[E,A]=D(null),[j,ee]=D(null),[te,M]=D(rn),N=e=>T(t=>({...t,...e})),F=S&&e?{throttle:e.throttle}:void 0,I=O({mutationFn:async()=>{let t=Qt(w,F,a);S&&e?await b.trpcClient.notificationRules.updateRule.mutate({ruleId:e.id,patch:t}):await b.trpcClient.notificationRules.createRule.mutate({rule:t})},onSuccess:g,onError:e=>A(e instanceof Error?e.message:`Save failed`)}),L=O({mutationFn:async()=>{let e=Qt(w,F,a);return(await b.trpcClient.notificationRules.testRule.mutate({rule:e,lookbackMinutes:60})).results},onMutate:()=>ee(null),onSuccess:e=>ee(e),onError:e=>A(e instanceof Error?e.message:`Test failed`)}),R=w.targetIds.map(e=>n.find(t=>t.id===e)?.name??e),ne=e=>N({targetIds:w.targetIds.includes(e)?w.targetIds.filter(t=>t!==e):[...w.targetIds,e]}),z=C({queryKey:[`userManagement`,`listUsers`],queryFn:()=>b.trpcClient.userManagement.listUsers.query()}).data,re=e=>N({targetUsers:w.targetUsers.includes(e)?w.targetUsers.filter(t=>t!==e):[...w.targetUsers,e]}),V=$.find(e=>e.value===w.delivery)?.hint;return k(y,{open:!0,onOpenChange:e=>!e&&v(),children:x(d,{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(ue,{className:`h-4 w-4 text-foreground-subtle`}),S?`Edit ${e?.name}`:`New notification rule`]}),k(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:v,children:`Cancel`})]}),E&&k(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger mb-3`,children:E}),x(h,{value:te,onValueChange:e=>M(an(e)??te),children:[k(f,{className:`mb-3`,children:nn.map(e=>k(p,{value:e.key,children:e.label},e.key))}),x(_,{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(r,{value:w.name,onChange:e=>N({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(u,{checked:w.enabled,onCheckedChange:e=>N({enabled:e}),"aria-label":`enabled`}),`Enabled`]})]}),x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Trigger`}),k(i,{value:w.delivery,onChange:e=>{let t=jt(e.target.value);t&&N({delivery:t})},options:$.map(e=>({value:e.value,label:e.label}))}),V&&k(`p`,{className:`text-[10px] text-foreground-subtle mt-1`,children:V})]}),x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Delivery targets`}),n.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:n.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:w.targetIds.includes(e.id),onChange:()=>ne(e.id),className:`accent-primary`}),k(`span`,{className:`flex-1 truncate`,children:e.name}),!e.enabled&&k(m,{variant:`warning`,children:`disabled`})]},e.id))})]}),x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Notify users`}),(z??[]).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:(z??[]).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:w.targetUsers.includes(e.id),onChange:()=>re(e.id),className:`accent-primary`}),k(`span`,{className:`flex-1 truncate`,children:e.username}),e.isAdmin&&k(m,{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(_,{value:`devices`,className:`space-y-4`,children:k(ct,{devices:l,value:w.deviceIds,onChange:e=>N({deviceIds:e}),loading:l.length===0})}),k(_,{value:`actions`,className:`space-y-4`,children:k(Xe,{value:w.actions,onChange:e=>N({actions:e}),devices:l})}),k(_,{value:`advanced`,className:`space-y-4`,children:x(`div`,{children:[x(`label`,{className:`flex items-center gap-2 text-[11px] font-medium text-foreground`,children:[k(u,{checked:w.snoozeAllowGlobal,onCheckedChange:e=>N({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(_,{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(i,{value:String(w.priority),onChange:e=>N({priority:Number(e.target.value)}),options:Ut.map(e=>({value:String(e.value),label:e.label}))})]}),x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Media attachment`}),k(i,{value:w.mediaAttach,onChange:e=>{let t=Nt(e.target.value);t&&N({mediaAttach:t})},options:Mt.map(e=>({value:e.value,label:e.label}))}),k(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:Mt.find(e=>e.value===w.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:w.mediaZoneCrop,onChange:e=>N({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:w.mediaGif,onChange:e=>N({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:w.mediaClip,onChange:e=>N({mediaClip:e.target.checked}),className:`accent-primary`}),`Attach an MP4 clip around the event`]})]}),(w.mediaGif||w.mediaClip)&&x(`div`,{className:`mt-2`,children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Video quality`}),k(i,{value:w.mediaProfile??``,onChange:e=>N({mediaProfile:Lt(e.target.value)}),options:It.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(i,{value:w.mediaClipSpeed===void 0?``:String(w.mediaClipSpeed),onChange:e=>N({mediaClipSpeed: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 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.`})]})]}),x(`div`,{children:[k(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Image frame`}),k(i,{value:w.mediaFrame??``,onChange:e=>N({mediaFrame:Ft(e.target.value)}),options:Pt.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(r,{value:w.templateTitle,onChange:e=>N({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:w.templateBody,onChange:e=>N({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(_,{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:`Conditions`}),a.length===0?k(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Condition catalog unavailable — this rule matches on its trigger and targets alone.`}):k(On,{catalog:a,taxonomy:o,delivery:w.delivery,conditions:w.conditions,schedule:w.schedule,cameras:s,gateable:c,onConditionsChange:e=>N({conditions:e}),onScheduleChange:e=>N({schedule:e})})]}),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(t,{size:`sm`,variant:`outline`,type:`button`,disabled:L.isPending||!Kt(w),onClick:()=>{A(null),L.mutate()},children:[L.isPending?k(B,{className:`h-3.5 w-3.5 animate-spin`}):k(de,{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.`}),j!==null&&k(Zn,{delivery:w.delivery,results:j,targetNames:R})]})]})]}),x(`div`,{className:`flex justify-end gap-2 mt-4`,children:[k(t,{variant:`secondary`,size:`sm`,type:`button`,onClick:v,children:`Cancel`}),x(t,{size:`sm`,type:`button`,disabled:I.isPending||!Kt(w),onClick:()=>{A(null),I.mutate()},children:[I.isPending&&k(B,{className:`h-3.5 w-3.5 animate-spin`}),S?`Save changes`:`Create rule`]})]})]})})}function Zn({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(F,{className:`h-3.5 w-3.5 shrink-0 text-success`}):k(ae,{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 Qn=[{value:1,label:`Last hour`},{value:24,label:`Last 24 hours`},{value:168,label:`Last 7 days`},{value:0,label:`All time`}],$n=[{value:``,label:`Any status`},{value:`pending`,label:`Pending`},{value:`sent`,label:`Sent`},{value:`dead`,label:`Dead`}],er=[50,100,250,500];function tr(){return{ruleId:``,deviceId:``,status:``,windowHours:24,limit:100}}function nr(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 ir(){let e=P(),[t,n]=D(tr),r=e=>n(t=>({...t,...e})),a=C({queryKey:[`notificationRules`,`listRules`,`forHistory`],queryFn:async()=>(await e.trpcClient.notificationRules.listRules.query({})).rules}),o=C({queryKey:[`deviceManager`,`listAll`,`forHistory`],queryFn:async()=>(await e.trpcClient.deviceManager.listAll.query({})).filter(e=>e.type===A.Camera).map(e=>({id:e.id,name:e.name}))}),c=Date.now(),l=C({queryKey:[`notificationRules`,`getHistory`,t],retry:!1,queryFn:async()=>{let n=t.windowHours>0?c-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)}:{},...nr(t.status)?{status:nr(t.status)}:{},...n===void 0?{}:{since:n}}})).entries}}),u=S(()=>{let e=new Map;for(let t of o.data??[])e.set(t.id,t.name);return e},[o.data]),d=e=>u.get(e)??`Camera #${String(e)}`,f=l.data??[],p=l.isError;return x(W,{icon:fe,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(i,{value:t.ruleId,onChange:e=>r({ruleId:e.target.value}),options:[{value:``,label:`All rules`},...(a.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(i,{value:t.deviceId,onChange:e=>r({deviceId:e.target.value}),options:[{value:``,label:`All cameras`},...(o.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(i,{value:t.status,onChange:e=>r({status:e.target.value}),options:$n.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(i,{value:String(t.windowHours),onChange:e=>r({windowHours:Number(e.target.value)}),options:Qn.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(i,{value:String(t.limit),onChange:e=>r({limit:Number(e.target.value)}),options:er.map(e=>({value:String(e),label:String(e)}))})]})]}),l.isLoading&&k(`div`,{className:`flex items-center justify-center py-16`,children:k(B,{className:`h-6 w-6 animate-spin text-primary`})}),p&&!l.isLoading&&k(s,{children:x(`div`,{className:`flex flex-col items-center gap-2 px-4 py-14 text-center`,children:[k(fe,{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 l.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(ne,{className:`h-3 w-3`}),` Retry`]})]})}),!p&&!l.isLoading&&f.length===0&&k(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:`No deliveries match these filters.`}),!p&&f.length>0&&k(s,{children:k(g,{columns:ar(d),rows:f,rowKey:e=>e.id,minWidthPx:720,bordered:!1})})]})}function ar(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(m,{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 or={home:`Home`,away:`Away`,night:`Night`,vacation:`Vacation`,custom_bypass:`Custom`};function sr(e){return or[e]??e}function cr(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 lr(e,t){return e.ruleCount===0?`Arms nothing — no enabled rule is gated on this mode.`:e.allDevices?`Every device — ${dr(e.ruleCount,`rule`)} with no device scope.`:e.deviceIds.length===0?`${dr(e.ruleCount,`rule`)}, no device restriction.`:e.deviceIds.map(e=>t.get(e)??`Device ${e}`).join(`, `)}function ur(e){return e.ruleCount===0}function dr(e,t){return e===1?`1 ${t}`:`${e} ${t}s`}function fr(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 pr=[`notificationRules`,`getAlarmConfig`],mr=[`notificationOutput`,`listTargets`],hr=[`deviceManager`,`listAll`,`alarm-coverage`],gr=600,_r=3600;function vr({label:e,hint:t,value:n,max:i,zeroMeans:a,disabled:o,onCommit:s}){let[c,l]=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(r,{type:`number`,min:0,max:i,value:c??String(n),disabled:o,onChange:e=>l(e.target.value),onBlur:()=>{let e=c===null?null:fr(c,i);l(null),e!==null&&e!==n&&s(e)},className:`w-28`,"data-testid":`alarm-delay-${e.toLowerCase().replace(/\s+/g,`-`)}`}),k(`span`,{className:`text-sm text-foreground-subtle`,children:cr(n,a)})]}),k(`p`,{className:`text-xs text-foreground-subtle`,children:t})]})}function yr(){let e=P(),t=E(),n=C({queryKey:pr,queryFn:async()=>e.trpcClient.notificationRules.getAlarmConfig.query({})}),r=C({queryKey:mr,queryFn:async()=>(await e.trpcClient.notificationOutput.listTargets.query({})).map(e=>({id:e.id,name:e.name,enabled:e.enabled}))}),i=C({queryKey:hr,queryFn:async()=>(await e.trpcClient.deviceManager.listAll.query({projection:`slim`})).map(e=>({id:e.id,name:e.name}))}),o=O({mutationFn:t=>e.trpcClient.notificationRules.setAlarmConfig.mutate({patch:t}),onSuccess:()=>t.invalidateQueries({queryKey:pr})}),c=S(()=>{let e=new Map;for(let t of i.data??[])e.set(t.id,t.name);return e},[i.data]);if(n.isLoading)return k(W,{icon:U,title:`Alarm`,subtitle:`Panel delays and mode coverage.`,children:k(B,{className:`h-5 w-5 animate-spin`})});let l=n.data;if(l===void 0||n.isError)return k(W,{icon:U,title:`Alarm`,subtitle:`Panel delays and mode coverage.`,children:k(a,{title:`Alarm settings are not available`,message:`This hub has not been updated to serve the alarm configuration yet.`})});if(l.deviceId===null)return k(W,{icon:U,title:`Alarm`,subtitle:`Panel delays and mode coverage.`,children:k(s,{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 d=l.settings,f=o.isPending,p=r.data??[],h=d.announceTargets,g=e=>{o.mutate(e)},_=e=>{g({announceTargets:h.includes(e)?h.filter(t=>t!==e):[...h,e]})};return k(W,{icon:U,title:`Alarm`,subtitle:`Panel delays, and what each mode actually arms.`,children:x(`div`,{className:`flex flex-col gap-4`,children:[o.isError?k(a,{title:`Could not save`,message:String(o.error)}):null,x(s,{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(vr,{label:`Exit delay`,hint:`Time between arming and the mode taking effect — long enough to leave.`,value:d.exitDelaySec,max:gr,zeroMeans:`arms immediately`,disabled:f,onCommit:e=>g({exitDelaySec:e})}),k(vr,{label:`Entry delay`,hint:`Time between a trigger and the alarm firing — long enough to reach the keypad.`,value:d.entryDelaySec,max:gr,zeroMeans:`fires immediately`,disabled:f,onCommit:e=>g({entryDelaySec:e})}),k(vr,{label:`Triggered for`,hint:`How long the alarm stays triggered before re-arming itself.`,value:d.triggeredDurationSec,max:_r,zeroMeans:`until disarmed`,disabled:f,onCommit:e=>g({triggeredDurationSec:e})})]})]}),x(s,{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(u,{checked:d.announceArm,disabled:f,onCheckedChange:e=>g({announceArm:e}),"data-testid":`alarm-announce-toggle`})]}),d.announceArm?x(`div`,{className:`mt-3 flex flex-col gap-2`,children:[p.length===0?k(`p`,{className:`text-xs text-foreground-subtle`,children:`No notification targets are configured — nothing can be sent.`}):p.map(e=>x(`label`,{className:`flex items-center gap-2 text-sm`,children:[k(`input`,{type:`checkbox`,checked:h.includes(e.id),disabled:f,onChange:()=>_(e.id),"data-testid":`alarm-target-${e.id}`}),k(`span`,{children:e.name}),e.enabled?null:k(m,{variant:`warning`,children:`disabled`})]},e.id)),h.length===0?k(`p`,{className:`text-xs text-warning`,children:`No target selected — the announcement will not be sent.`}):null]}):null]}),x(s,{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:l.coverage.map(e=>x(`div`,{className:`flex items-start gap-3 rounded border border-border p-2`,"data-mode":e.mode,"data-empty":ur(e)?`true`:`false`,children:[k(`div`,{className:`w-20 shrink-0 text-sm font-medium`,children:sr(e.mode)}),k(`div`,{className:`flex-1 text-sm text-foreground-subtle`,children:lr(e,c)}),ur(e)?k(se,{className:`h-4 w-4 shrink-0 text-warning`}):null]},e.mode))})]})]})})}function br(){return k(`div`,{className:`flex flex-col p-4`,children:k(ce,{tabs:[{id:`targets`,label:`Targets`,icon:ie,content:k(ze,{})},{id:`rules`,label:`Rules`,icon:ue,content:k(Jn,{})},{id:`history`,label:`History`,icon:fe,content:k(ir,{})},{id:`alarm`,label:`Alarm`,icon:U,content:k(yr,{})}]})})}export{br as NotificationsPage,br as default};
@@ -1 +0,0 @@
1
- import{Ci as e,Di as t,Ei as n,Fi as r,Fo as i,Ga as a,Ii as o,Io as s,Li as c,Oi as l,Pi as u,Qa as d,Si as f,T as p,Ti as m,Wr as h,Xa as g,Ya as _,Za as v,_ as y,_i as b,ai as x,ao as S,bi as C,ci as w,di as T,eo as E,fi as D,ft as O,g as k,ii as A,io as ee,ki as j,ko as M,li as N,lt as te,mi as P,ni as ne,no as re,oi as ie,ri as ae,si as oe,ti as se,to as ce,ui as le,ut as ue,wi as de,xi as fe,yi as pe,zi as me}from"./src-CkX4IOdq.js";import{I as he,K as ge,Q as F,S as I,T as _e,W as L,b as R,o as z,q as B,x as V,z as H}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{J as ve,Q as ye,q as be}from"./src-CUZFIAzy.js";import{i as xe}from"./AddLocationWizard-BMJasR9E.js";import{c as Se,i as Ce,l as we,n as U,r as Te,s as Ee,t as De}from"./NodeInferenceDevices-jYmHLpBX.js";import{t as Oe}from"./download-C-SIOwsB.js";import{n as ke,r as Ae,t as je}from"./zap-v3R56D2n.js";import{t as Me}from"./pencil-ChPuHfCU.js";import{t as Ne}from"./plus-Dw5CKvNT.js";import{t as Pe}from"./radio-BCYd2EQY.js";import{t as Fe}from"./refresh-cw-_uUkpw3C.js";import{t as Ie}from"./search-dbMboEvL.js";import{t as Le}from"./server-CxbU82tS.js";import{t as Re}from"./square-check-big-DgNfiXED.js";import{t as ze}from"./square-BxOJgJFR.js";import{C as W,D as Be,E as Ve,F as He,G as Ue,L as We,M as G,N as Ge,P as Ke,R as qe,Y as Je,c as Ye,i as Xe,s as Ze}from"./index-B4yaKbnm.js";import{t as Qe}from"./AdminPage-Dq33XE9j.js";import{t as $e}from"./useEventInvalidation-Djmiw-m0.js";import{r as et,t as tt}from"./build-cluster-graph-C6MLwK2s.js";import{n as nt}from"./format-size-CO9d3C3-.js";import{t as rt}from"./NodeAddonsSettingsPanel-rKp5y5HT.js";import{n as it,t as at}from"./ClusterRecordingTab-DNIc_5e9.js";var ot=Ue(`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=Ue(`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=Ue(`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`}]]);F();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}=h(void 0),{data:i}=pe(void 0),{data:a}=fe(void 0),o=new Map;for(let e of i??[])o.set(e.agentNodeId,(o.get(e.agentNodeId)??0)+1);let c=r??[],l=c.filter(e=>e.isOnline).length,u=c.filter(e=>!e.isOnline).length;return I(`div`,{className:`flex flex-col h-full`,children:[I(`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:[V(Ve,{className:`h-4 w-4 flex-shrink-0`}),I(`div`,{className:`min-w-0 flex-1`,children:[V(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),V(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Balancer + failover + assignments`})]})]}),V(`div`,{className:`flex-1 overflow-y-auto`,children:c.map(n=>{let r=e===n.id,i=o.get(n.id)??0,c=n.isHub?Le:G,l=pt(a,n.id,n.isHub),u=n.isOnline?null:s(et(n.lastSeen));return I(`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:[V(c,{className:`h-4 w-4 flex-shrink-0`}),I(`div`,{className:`min-w-0 flex-1`,children:[I(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`text-xs font-semibold truncate`,children:n.name}),n.isHub&&V(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!n.isOnline&&V(`span`,{className:`h-1.5 w-1.5 rounded-full bg-destructive flex-shrink-0`}),n.isOnline&&V(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),I(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[I(`span`,{children:[n.cpuCores,` cores`]}),V(`span`,{children:`•`}),I(`span`,{children:[Math.round(n.memoryMB/1024),` GB`]}),i>0&&I(R,{children:[V(`span`,{children:`•`}),I(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[V(ke,{className:`h-2.5 w-2.5`}),i]})]}),!n.isOnline&&I(R,{children:[V(`span`,{children:`•`}),I(`span`,{className:`text-destructive`,children:[`offline`,u===null?``:` · ${u}`]})]})]}),I(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[V(M,{variant:l.pipeline?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:l.pipeline?`Pipeline: enabled`:`Pipeline: not enabled (agent capability)`,children:`Pipe`}),V(M,{variant:l.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:l.audio?`Audio: enabled`:`Audio: not enabled (agent capability)`,children:`Aud`})]})]})]},n.id)})}),I(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[I(`span`,{children:[l,` online`]}),u>0&&I(`span`,{className:`text-destructive`,children:[u,` offline`]})]})]})}function ht({nodeId:e,refreshToken:t}){let{data:n}=h(void 0),r=n?.find(t=>t.id===e),i=g(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return r?I(`div`,{className:`px-6 py-4 border-b border-border`,children:[I(`div`,{className:`flex items-center gap-2 mb-1`,children:[V(`h2`,{className:`text-base font-semibold text-foreground`,children:r.name}),r.isOnline?V(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):V(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`}),r.isHub&&V(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),I(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[V(`span`,{children:r.cpuModel??`CPU`}),V(`span`,{children:`•`}),I(`span`,{children:[r.cpuCores,` cores`]}),V(`span`,{children:`•`}),I(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),i&&I(R,{children:[V(`span`,{children:`•`}),I(`span`,{children:[i.attachedCameras,` cameras (`,i.activeCameras,` active)`]}),V(`span`,{children:`•`}),I(`span`,{children:[i.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),V(`span`,{children:`•`}),I(`span`,{children:[`queue `,i.queueDepthTotal]}),i.hardware.hasGpu&&I(R,{children:[V(`span`,{children:`•`}),V(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):V(`div`,{className:`px-6 py-4 border-b border-border`,children:I(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}function gt({refreshToken:e,nodeId:t}){let[n,r]=B(new Map),{nodes:i}=_();d(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t?.deviceId==`number`&&r(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})});let{data:a}=D(void 0),o=L(()=>{let e=new Map;for(let t of a??[])e.set(t.nodeId,t.deviceCount);return e},[a]),s=L(()=>{let e=new Map,t=Date.now()-3e4;for(let r of n.values()){if(r.timestamp<t)continue;let n=r.nodeId??`hub`,i=e.get(n)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};i.attachedCameras++,r.metrics.phase===`active`&&i.activeCameras++,i.totalFps+=r.metrics.actualFps,i.totalInferenceWeighted+=r.metrics.avgInferenceTimeMs,i.queueDepth+=r.metrics.queueDepth,e.set(n,i)}return e},[n]),c=L(()=>{let e=new Map;for(let t of i)e.set(t.id,t.shortName);return e},[i]),l=L(()=>{let e=0,t=0,n=0,r=0,a=0;for(let i of s.values())e+=i.attachedCameras,t+=i.activeCameras,n+=i.totalFps,r+=i.totalInferenceWeighted,a+=i.queueDepth;let o=e>0?r/e:0;return{totalAgents:i.length,onlineAgents:i.filter(e=>e.isOnline).length,attachedCameras:e,activeCameras:t,avgInferenceTimeMs:o,queueDepth:a,totalFps:n}},[s,i]);if(t){let e=s.get(t);return I(`div`,{className:`@container/liveload`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),I(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[V(K,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),V(K,{label:`Active / Attached`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),V(K,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),V(K,{label:`Queue`,value:e?String(e.queueDepth):`—`}),V(K,{label:`Audio`,value:String(o.get(t)??`—`)})]})]})}let u=[...s.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return I(`div`,{className:`@container/liveload`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),I(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[V(K,{label:`Total agents`,value:`${l.onlineAgents}/${l.totalAgents}`}),V(K,{label:`Active / Attached`,value:`${l.activeCameras}/${l.attachedCameras}`}),V(K,{label:`Total FPS`,value:l.totalFps.toFixed(1)}),V(K,{label:`Avg inference ms`,value:l.avgInferenceTimeMs.toFixed(0)}),V(K,{label:`Queue depth`,value:String(l.queueDepth)})]}),V(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:I(`table`,{className:`w-full text-xs min-w-[480px]`,children:[V(`thead`,{className:`bg-surface`,children:I(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[V(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),V(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),V(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),V(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),V(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),V(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),I(`tbody`,{children:[u.map(([e,t])=>I(`tr`,{className:`border-t border-border`,children:[V(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:c.get(e)??e}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:o.get(e)??`—`})]},e)),u.length===0&&V(`tr`,{children:V(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function K({label:e,value:t}){return I(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[V(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),V(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}F();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:G,decoder:Be,audio:Ae},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 i=z(),[a,s]=B(null),[c,l]=B(null),[u,f]=B(new Map);$e([`pipelineOrchestrator`,`getPipelineAssignments`],vt),$e([`pipelineOrchestrator`,`getAudioAssignments`],vt),$e([`pipelineOrchestrator`,`getCameraStatuses`],vt);let{data:m}=pe(void 0),{data:h}=T(void 0),{data:g}=P({},{enabled:e===`agent`}),{nodes:v}=_(),{data:y}=Ee();d(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t.deviceId==`number`&&f(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})}),H(()=>{if(u.size===0)return;let e=setInterval(()=>{f(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[u.size]);let b=L(()=>{let e=new Map;for(let t of y??[])e.set(t.id,t.name);return e},[y]),x=L(()=>{if(e===`agent`){let e=[];for(let n of g??[]){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:b.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:b.get(e)??`Device ${e}`,pipeline:_t,decoder:_t,audio:_t};return n.set(e,r),r};for(let i of m??[]){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 h??[]){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},[m,h,g,b,e,t]),S=L(()=>(v??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[v]),C=()=>{i.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),i.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]}),i.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},E=N({onSuccess:C}),D=o({onSuccess:C}),O=w({onSuccess:C}),k=r({onSuccess:C}),A=(e,t,n)=>{t===`pipeline`?E.mutate({deviceId:e,agentNodeId:n}):O.mutate({deviceId:e,nodeId:n}),s(null)},ee=(e,t)=>{t===`pipeline`?D.mutate({deviceId:e}):k.mutate({deviceId:e}),s(null)};return V(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:I(`table`,{className:`w-full text-xs min-w-[760px] table-fixed`,children:[V(`thead`,{className:`bg-surface`,children:I(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[!n&&V(`th`,{className:`w-10`}),V(`th`,{className:`min-w-[200px] text-left px-3 py-2 align-middle`,children:`Camera`}),e===`cluster`?I(R,{children:[V(`th`,{className:`w-[168px] text-left px-3 py-2 align-middle`,children:`Auto | Pin`}),V(`th`,{className:`w-[188px] text-left px-3 py-2 align-middle`,children:`Resolved placement`})]}):I(R,{children:[V(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Pipeline`}),V(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Decoder`}),V(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Audio`})]}),V(`th`,{className:`w-[132px] text-left px-3 py-2 align-middle`,children:`Status`})]})}),I(`tbody`,{children:[x.map(t=>{let r=u.get(t.deviceId),i=c===t.deviceId;return I(_e.Fragment,{children:[I(`tr`,{className:`border-t border-border align-middle relative`,children:[!n&&V(`td`,{className:`px-2 py-2 align-middle`,children:V(`button`,{type:`button`,onClick:()=>l(i?null:t.deviceId),className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":i?`Collapse broker details`:`Expand broker details`,children:V(i?We:He,{className:`h-3.5 w-3.5`})})}),I(`td`,{className:`px-3 py-2 align-middle min-w-0`,children:[V(`div`,{className:`text-foreground font-medium leading-tight line-clamp-2 break-words`,title:t.deviceName,children:t.deviceName}),I(`div`,{className:`text-[10px] text-foreground-subtle leading-tight`,children:[`#`,t.deviceId]})]}),e===`cluster`?I(R,{children:[V(`td`,{className:`px-3 py-2 align-middle`,children:V(Ct,{state:t.pipeline,onlineNodes:S,pending:E.isPending||D.isPending,onChange:e=>{e===`auto`?ee(t.deviceId,`pipeline`):A(t.deviceId,`pipeline`,e)}})}),V(`td`,{className:`px-3 py-2 align-middle`,children:V(wt,{state:t.pipeline,deviceId:t.deviceId})})]}):I(R,{children:[V(Et,{role:`pipeline`,state:t.pipeline,mode:e,deviceId:t.deviceId,onlineNodes:S,isMenuOpen:a?.deviceId===t.deviceId&&a.role===`pipeline`,onToggleMenu:()=>s(a?.deviceId===t.deviceId&&a.role===`pipeline`?null:{deviceId:t.deviceId,role:`pipeline`}),onCloseMenu:()=>s(null),onMove:e=>A(t.deviceId,`pipeline`,e),onUnpin:()=>ee(t.deviceId,`pipeline`)}),V(Et,{role:`decoder`,state:t.decoder,mode:e,deviceId:t.deviceId,onlineNodes:S,readOnly:!0,isMenuOpen:!1,onToggleMenu:()=>void 0,onCloseMenu:()=>void 0,onMove:()=>void 0,onUnpin:()=>void 0}),V(Et,{role:`audio`,state:t.audio,mode:e,deviceId:t.deviceId,onlineNodes:S,isMenuOpen:a?.deviceId===t.deviceId&&a.role===`audio`,onToggleMenu:()=>s(a?.deviceId===t.deviceId&&a.role===`audio`?null:{deviceId:t.deviceId,role:`audio`}),onCloseMenu:()=>s(null),onMove:e=>A(t.deviceId,`audio`,e),onUnpin:()=>ee(t.deviceId,`audio`)})]}),V(`td`,{className:`px-3 py-2 align-middle`,children:V(At,{snap:r})})]}),i&&!n&&I(`tr`,{className:`bg-surface/50`,children:[V(`td`,{}),I(`td`,{colSpan:e===`cluster`?4:5,className:`px-3 py-2 space-y-3`,children:[t.pipeline.nodeId&&V(St,{deviceId:t.deviceId,nodeId:t.pipeline.nodeId}),V(p,{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)}),x.length===0&&V(`tr`,{children:V(`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=z(),{data:r}=b({nodeId:t}),{data:i}=C({deviceId:e}),a=u({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}}),o=r?.devices??[],s=i?.deviceKey??`auto`,c=s!==`auto`&&!o.some(e=>e.key===s);return I(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[V(`span`,{className:`shrink-0 font-medium text-foreground`,children:`Inference device`}),I(`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:[V(`option`,{value:`auto`,children:`Auto (balanced)`}),c&&I(`option`,{value:s,children:[`Pin → `,s,` (not on this node)`]}),o.map(e=>I(`option`,{value:e.key,children:[`Pin → `,e.key,e.available?``:` (unavailable)`]},e.key))]}),a.isPending&&V(`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 I(`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:[V(`option`,{value:`auto`,children:`Auto`}),a.map(e=>I(`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 V(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`});let n=e.pinned?`pinned · manual`:`auto · ${e.reason||`capacity`}`;return I(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[V(`span`,{className:`font-mono text-[11px] text-foreground truncate`,title:e.nodeId,children:e.nodeId}),V(`span`,{className:`truncate ${e.pinned?`text-amber-400 text-[10px]`:`text-foreground-subtle text-[10px]`}`,title:n,children:n}),V(Tt,{deviceId:t,nodeId:e.nodeId})]})}function Tt({deviceId:e,nodeId:t}){let n=z(),{data:r}=C({deviceId:e},{refetchOnMount:`always`}),{data:i}=b({nodeId:t},{refetchOnMount:`always`}),a=u({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});if(r===void 0||i===void 0)return V(`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 I(`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:[V(`option`,{value:`auto`,children:`Auto (balanced)`}),l&&I(`option`,{value:c,children:[d?`${U(d).label} (${c})`:c,` (not enabled)`]}),s.map(e=>I(`option`,{value:e.key,children:[U(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 I(`td`,{className:`px-3 py-2 align-middle relative min-w-0`,children:[I(`div`,{className:`flex items-center gap-2 min-w-0`,children:[V(n===`agent`?Dt:Ot,{state:t,Icon:u}),V(`div`,{className:`ml-auto shrink-0`,children:f&&V(`button`,{type:`button`,onClick:o,className:`p-1 rounded hover:bg-surface-hover`,"aria-label":`${bt[e]} actions`,children:V(ot,{className:`h-3 w-3 text-foreground-subtle`})})})]}),a&&f&&V(jt,{title:bt[e],targets:d,pinned:t.pinned,onMove:c,onUnpin:l,onClose:s})]})}function Dt({state:e,Icon:t}){return I(`div`,{className:`flex items-center gap-1.5`,children:[V(e.active?Re:ze,{className:`h-3.5 w-3.5 ${e.active?`text-success`:`text-foreground-subtle/50`}`}),V(t,{className:`h-3 w-3 ${e.active?`text-foreground-subtle`:`text-foreground-subtle/40`}`}),e.pinned&&V(ct,{className:`h-2.5 w-2.5 text-amber-400`})]})}function Ot({state:e,Icon:t}){return!e.active||!e.nodeId?I(`div`,{className:`flex items-center gap-1.5 text-foreground-subtle/60`,children:[V(t,{className:`h-3 w-3`}),V(`span`,{className:`text-[10px] italic`,children:`—`})]}):I(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[V(t,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),I(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[V(`span`,{className:`font-mono text-[11px] text-foreground truncate`,children:e.nodeId}),V(`span`,{className:`flex items-center gap-1 text-[10px]`,children:e.pinned?I(`span`,{className:`inline-flex items-center gap-0.5 text-amber-400`,children:[V(ct,{className:`h-2.5 w-2.5`}),` manual`]}):I(`span`,{className:`text-foreground-subtle truncate`,children:[`auto · `,e.reason||`capacity`]})})]})]})}var kt=`min-h-[3.25rem]`;function At({snap:e}){if(!e)return V(`div`,{className:`flex items-center ${kt}`,children:V(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`})});let{phase:t,actualFps:n,avgInferenceTimeMs:r,queueDepth:a,configuredFps:o,droppedFrames:s}=e.metrics,c=i(t);return I(`div`,{className:`flex flex-col justify-center gap-0.5 font-mono text-[10px] tabular-nums leading-tight min-w-0 ${kt}`,children:[I(`span`,{className:`inline-flex items-center gap-1 min-w-0 ${c.textColor}`,children:[V(y,{phase:t,className:`h-2.5 w-2.5 shrink-0`}),V(`span`,{className:`font-semibold uppercase tracking-wider truncate`,children:c.label})]}),I(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[V(`span`,{className:`text-foreground`,children:n.toFixed(1)}),I(`span`,{children:[`/`,o.toFixed(0),` fps`]})]}),I(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[V(`span`,{className:`text-foreground`,children:r.toFixed(0)}),V(`span`,{children:` ms`}),a>0&&I(`span`,{className:`text-warning ml-1`,children:[`q`,a]})]}),I(`span`,{className:`whitespace-nowrap truncate ${s>0?`text-warning`:`text-foreground-subtle`}`,children:[`drops `,V(`span`,{className:`text-foreground`,children:s})]})]})}function jt({title:e,targets:t,pinned:n,onMove:r,onUnpin:i,onClose:a}){let o=ge(null);return H(()=>{let e=e=>{o.current?.contains(e.target)||a()};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[a]),I(`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:[V(`div`,{className:`px-3 py-1 text-[9px] uppercase tracking-wider text-foreground-subtle border-b border-border`,children:e}),t.length>0&&V(`div`,{className:`py-1`,children:t.map(e=>I(`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&&I(`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&&V(`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 I(`div`,{className:`space-y-6`,children:[V(gt,{refreshToken:t,nodeId:e}),I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Cameras on this node`}),I(`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.`]})]}),V(xt,{mode:`agent`,nodeId:e,compact:!0})]})}F();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=z(),r=ie({onSettled:()=>{n.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:i}=oe({nodeId:e}),a=g(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??i??null,o=a===null;$e([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:s}=me({nodeId:e}),{values:c}=v(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),l=L(()=>c.filter(e=>e.metrics.phase===`active`).length,[c]),u=t=>{let n=s??[];n.length>0&&!window.confirm(`${n.length} camera(s) are dispatching through this engine. Killing it forces a respawn on the next frame. Continue?`)||r.mutate({nodeId:e,engine:t,force:n.length>0})};return I(`div`,{className:`space-y-6`,children:[I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),I(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(a??[]).length,` engine(s) resident in RAM. `,(s??[]).length,` `,`camera(s) attached, `,l,` actively dispatching frames. Refreshes every 5s.`]})]}),V(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:I(`table`,{className:`w-full text-xs min-w-[640px]`,children:[V(`thead`,{className:`bg-surface`,children:I(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[V(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),V(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),V(`th`,{className:`text-left px-3 py-2`,children:`Models`}),V(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),V(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),V(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),V(`th`,{className:`w-20`})]})}),I(`tbody`,{children:[o&&V(`tr`,{children:V(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!o&&(a??[]).map(e=>{let t=e.kind===`warm-override`,n=e.kind===`device-pool`;return I(`tr`,{className:`border-t border-border ${t?`bg-amber-500/5`:n?`bg-primary/[0.05]`:``}`,children:[V(`td`,{className:`px-3 py-2`,children:I(`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:[V(t?st:n?we:G,{className:`h-3 w-3`}),t?`warm`:n?`pool`:`runtime`]})}),V(`td`,{className:`px-3 py-2`,children:I(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[V(je,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),V(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?V(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):V(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>V(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),V(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),V(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?V(`span`,{className:`text-foreground-subtle`,children:Nt(e.idleMs,e.idleTtlMs)}):V(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t?`—`:(s??[]).length}),V(`td`,{className:`px-3 py-2 text-right`,children:n?V(`span`,{className:`text-[11px] text-foreground-subtle`,children:`auto`}):I(`button`,{type:`button`,disabled:r.isPending,onClick:()=>u(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:[V(Ye,{className:`h-3 w-3`}),`Kill`]})})]},e.engineKey)}),!o&&(a??[]).length===0&&V(`tr`,{children:V(`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.`})})]})]})}),I(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[V(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,V(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`,` `,V(`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.`]}),r.isError&&I(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,r.error instanceof Error?r.error.message:`unknown`]})]})}F();var Ft=new Set(ye);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 q(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?I(`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:[V(`div`,{className:`h-2 w-2 rounded-full shrink-0 ${c.downloaded?`bg-success`:`bg-foreground-subtle/30`}`}),I(`div`,{className:`flex-1 min-w-0`,children:[I(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`text-sm font-medium text-foreground`,children:t.name}),I(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`(`,t.id,`)`]})]}),i&&i.progress>=0&&i.progress<100&&I(`div`,{className:`mt-1.5 flex items-center gap-2 max-w-xs`,children:[V(`div`,{className:`flex-1 h-1 bg-surface-hover rounded-full overflow-hidden`,children:V(`div`,{className:`bg-primary h-full rounded-full transition-all duration-300`,style:{width:`${i.progress}%`}})}),I(`span`,{className:`text-[9px] text-primary font-mono tabular-nums shrink-0`,children:[Math.round(i.progress),`%`]})]})]}),V(`span`,{className:`text-xs text-foreground-subtle tabular-nums shrink-0`,children:nt(c.sizeMB)}),a&&I(`span`,{className:`flex items-center gap-1 text-[10px] text-danger max-w-[160px] truncate shrink-0`,title:a,children:[V(Ke,{className:`h-3 w-3 shrink-0`}),a]}),c.downloaded?I(`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?V(W,{className:`h-3 w-3 animate-spin`}):V(Ye,{className:`h-3 w-3`}),r?`Deleting...`:`Delete`]}):I(`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?V(W,{className:`h-3 w-3 animate-spin`}):V(Oe,{className:`h-3 w-3`}),r?`Downloading...`:`Download`]})]}):null}function Ht({engines:e,activeEngine:t,viewEngine:n,onSelect:r}){let[i,a]=B(!1);return I(`div`,{className:`relative`,children:[I(`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:[V(G,{className:`h-4 w-4 text-primary shrink-0`}),I(`div`,{className:`flex-1 min-w-0`,children:[I(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`text-sm font-medium text-foreground`,children:Rt(n)}),q(n)===q(t)&&V(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),V(`div`,{className:`text-[10px] text-foreground-subtle`,children:zt(n)})]}),V(We,{className:`h-4 w-4 text-foreground-subtle transition-transform ${i?`rotate-180`:``}`})]}),i&&V(`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=q(e)===q(n),o=q(e)===q(t);return I(`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:[V(G,{className:`h-4 w-4 shrink-0 ${i?`text-primary`:`text-foreground-subtle`}`}),I(`div`,{className:`flex-1`,children:[I(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`text-sm font-medium ${i?`text-primary`:`text-foreground`}`,children:Rt(e)}),o&&V(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),V(`div`,{className:`text-[10px] text-foreground-subtle`,children:zt(e)})]}),i&&V(Ge,{className:`h-4 w-4 text-primary shrink-0`})]},q(e))})})]})}function Ut({embedded:e=!1,nodeId:t}={}){let n=z(),r=t??`hub`,[i,a]=B(null),[o,s]=B(new Set),[c,l]=B(new Map),[u,f]=B(new Map),[p,m]=B(``),{data:h=[]}=ae({nodeId:r}),g=h.filter((e,t,n)=>n.findIndex(t=>t.format===e.format)===t),{data:_}=x({nodeId:r}),v=_,{data:y,isLoading:b}=A({nodeId:r}),S=ne(),C=se();d(`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 w=v??{runtime:`node`,backend:`cpu`,format:`onnx`},T=g.find(e=>e.format===i)??w,E=T.format,D=y?.slots??[],O=D.map(e=>({...e,addons:e.addons.map(e=>({...e,models:e.models.filter(e=>e.formats[E]!==void 0)})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0),k=Bt(O,E),ee=he(async(e,t,i)=>{if(!It(i))return;let a=Lt(e,t,i);s(e=>new Set([...e,a])),f(e=>{let t=new Map(e);return t.delete(a),t});try{await S.mutateAsync({addonId:e,modelId:t,format:i,nodeId:r}),n.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){f(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})}},[S,n,r]),j=he(async(e,t,i)=>{if(!It(i))return;let a=Lt(e,t,i);s(e=>new Set([...e,a])),f(e=>{let t=new Map(e);return t.delete(a),t});try{await C.mutateAsync({addonId:e,modelId:t,format:i,nodeId:r}),n.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){f(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})}},[C,n,r]),M=he(e=>{a(e.format)},[]),N=p.trim()?O.map(e=>({...e,addons:e.addons.map(e=>({...e,models:e.models.filter(t=>t.name.toLowerCase().includes(p.toLowerCase())||t.id.toLowerCase().includes(p.toLowerCase())||e.name.toLowerCase().includes(p.toLowerCase()))})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0):O,te=I(R,{children:[b&&V(`div`,{className:`flex items-center justify-center py-16`,children:V(W,{className:`h-5 w-5 animate-spin text-foreground-subtle`})}),!b&&D.length===0&&I(`div`,{className:`flex flex-col items-center justify-center py-16 text-foreground-subtle`,children:[V(xe,{className:`h-8 w-8 mb-3 opacity-30`}),V(`span`,{className:`text-sm`,children:`No pipeline steps available`}),V(`span`,{className:`text-xs mt-1`,children:`Configure the detection pipeline to see available models.`})]}),!b&&D.length>0&&I(R,{children:[V(Ht,{engines:g,activeEngine:w,viewEngine:T,onSelect:M}),I(`div`,{className:`flex items-center gap-4 text-xs text-foreground-subtle`,children:[I(`span`,{children:[V(`span`,{className:`font-semibold text-foreground tabular-nums`,children:k.total}),V(`span`,{className:`ml-1`,children:`compatible models`})]}),V(`span`,{className:`text-border`,children:`|`}),I(`span`,{children:[V(`span`,{className:`font-semibold text-success tabular-nums`,children:k.downloaded}),V(`span`,{className:`ml-1`,children:`downloaded`})]}),V(`span`,{className:`text-border`,children:`|`}),I(`span`,{className:`tabular-nums`,children:[nt(k.downloadedSizeMB),V(`span`,{className:`ml-1`,children:`on disk`})]})]}),k.total>5&&I(`div`,{className:`relative`,children:[V(Ie,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),V(`input`,{type:`text`,value:p,onChange:e=>m(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`})]}),N.map(e=>{let t=e.addons.reduce((e,t)=>e+t.models.length,0),n=e.addons.reduce((e,t)=>e+t.models.filter(e=>e.formats[E]?.downloaded).length,0);return I(`div`,{children:[I(`div`,{className:`flex items-center gap-2 mb-2`,children:[V(`h2`,{className:`text-sm font-semibold text-foreground`,children:e.label}),V(`div`,{className:`flex-1 h-px bg-border`}),I(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[n,`/`,t]})]}),V(`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,E);return V(Vt,{addonId:e.id,model:t,format:E,isActive:o.has(n),progress:c.get(t.id),errorMsg:u.get(n),onDownload:()=>ee(e.id,t.id,E),onDelete:()=>j(e.id,t.id,E)},`${e.id}/${t.id}`)}))})]},e.id)}),N.length===0&&V(`div`,{className:`text-center py-8 text-sm text-foreground-subtle`,children:p.trim()?I(R,{children:[`No models matching “`,p,`”`]}):I(R,{children:[`No models available for `,Rt(T),` format`]})})]})]});return e?V(`div`,{className:`space-y-4`,children:te}):V(Qe,{children:te})}function Wt({nodeId:e,refreshToken:t}){return V(Ut,{embedded:!0,nodeId:e})}var Gt=`pipeline-runner`,Kt=200;function qt({nodeId:e}){return I(`div`,{className:`flex flex-col gap-3`,children:[I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Runner logs`}),I(`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.`]})]}),V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:V(k,{agentId:e,addonId:Gt,limit:Kt,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}F(),F();function Jt({nodeId:e,title:t}){let{data:n}=Ee(),{data:r}=pe(void 0),a=L(()=>{let e=new Map;for(let t of n??[])e.set(t.id,t.name);return e},[n]),o=L(()=>{if(!e)return null;let t=new Set;for(let n of r??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,r]),[s,c]=B(new Map);d(`pipeline.camera-metrics-snapshot`,t=>{let n=t.data;typeof n.deviceId==`number`&&(e&&n.nodeId!==e||c(e=>{let t=new Map(e);return t.set(n.deviceId,n),t}))}),H(()=>{if(s.size===0)return;let e=setInterval(()=>{c(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)},[s.size]);let l=L(()=>{let e=[];for(let t of s.values())o&&!o.has(t.deviceId)||e.push(t);return e.sort((e,t)=>e.deviceId-t.deviceId),e},[s,o]);return l.length===0?I(`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`]}):I(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[I(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[V(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),V(`span`,{className:`text-[10px] text-foreground-subtle`,children:l.length})]}),V(`div`,{className:`flex flex-wrap gap-1.5`,children:l.map(e=>{let t=a.get(e.deviceId)??`#${e.deviceId}`,n=i(e.metrics.phase);return I(`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:[V(y,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),V(`span`,{className:`font-medium text-foreground/90 max-w-[220px] truncate`,children:t}),V(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),V(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}F();function J(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 Yt(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 Xt({nodeId:e,refreshToken:t}){let n=z(),[r,i]=B(null),[a,o]=B(null),[s,c]=B(``),[u,d]=B(null),f=b({nodeId:e},{refetchOnMount:`always`}),p=A({nodeId:e},{refetchOnMount:`always`}),m=f.data?.devices??[],h=l({onSuccess:()=>{n.invalidateQueries({queryKey:[`pipelineOrchestrator`,`getNodeInferenceDevices`]})}}),g=L(()=>p.data?ee(p.data):[],[p.data]),_=L(()=>m.map(t=>({agentNodeId:e,engineLabel:t.format,deviceKey:t.key,deviceLabel:U(t).label})),[m,e]),v=e=>m.find(t=>t.key===e)??null,y=L(()=>m.filter(e=>e.enabled),[m]),x=y.length>=2,C=(e,t)=>{let n=J(p.data??null,e),r=t?.format;return n?.models.some(e=>r!==void 0&&!!e.formats[r])??!1},w=e=>{let t=v(e);return t?U(t).label:e},T=(e,t)=>y.filter(n=>n.key!==t&&C(e,n)).toSorted((e,t)=>e.key<t.key?-1:+(e.key>t.key))[0]??null,D=e=>{let t=J(p.data??null,e)?.enabledByDefault??!0;return{kind:`gate`,effectiveOn:t,defaultOn:t,explicit:!1}},O=(e,t)=>{let n=J(p.data??null,e),r=t?.format;if(!(!n||r===void 0))return(n.slot===`detector`?t?.defaultModelId:void 0)??E(n,r)},k=(e,t)=>{let n=D(e),r=n.kind===`gate`?n.effectiveOn:!1,i=J(p.data??null,e),a=t.deviceKey===void 0?null:v(t.deviceKey),o=a?.format,s=i?.models.some(e=>o!==void 0&&!!e.formats[o])??!1,c=a?.steps?.[e];if(!s){if(!r)return{kind:`na`};let n=c?.jumpDeviceKey,i=n!==void 0&&y.some(e=>e.key===n)?n:t.deviceKey===void 0?void 0:T(e,t.deviceKey)?.key;return i===void 0?{kind:`skip`}:{kind:`skip`,jumpTo:w(i)}}return{kind:`enabled`,modelId:c?.modelId??O(e,a)??`Auto`,...c?.jumpDeviceKey!==void 0&&y.some(e=>e.key===c.jumpDeviceKey)?{jumpTo:w(c.jumpDeviceKey)}:{}}},j=r&&p.data?J(p.data,r.addonId):null,M=r?v(r.deviceKey):null,N=M?.format??`coreml`,te=r?O(r.addonId,M):void 0,P=()=>{i(null),o(null),c(``)},ne=(e,t)=>{if(t.deviceKey===void 0)return;let n=v(t.deviceKey)?.steps?.[e];i({addonId:e,deviceKey:t.deviceKey}),o({enabled:!0,...n?.modelId===void 0?{}:{modelId:n.modelId},settings:n?.settings??{}}),c(n?.jumpDeviceKey??``)},ie=()=>{if(!r)return;let t=Yt(a),n=s!==``&&s!==r.deviceKey?s:void 0,i=t||n!==void 0?{...t,...n===void 0?{}:{jumpDeviceKey:n}}:null,o=m.map(e=>{let t={...e.steps};return e.key===r.deviceKey&&(i?t[r.addonId]=i:delete t[r.addonId]),{key:e.key,enabled:e.key===r.deviceKey?!0:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:t}});h.mutate({agentNodeId:e,inferenceDevices:Ce(o)},{onSuccess:P})};if(f.isLoading||p.isLoading)return V(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(m.length===0)return V(`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(!p.data)return V(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let ae=r!==null&&j!==null&&M!==null;return I(`div`,{className:`relative h-full w-full space-y-3`,children:[I(`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`,` `,V(`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.`]}),V(`div`,{className:ae?`md:pr-[360px]`:``,children:g.length>0?V(ce,{tree:g,agents:_,gateFor:D,getCellState:k,onCellClick:ne,selectedCell:r?{addonId:r.addonId,agentNodeId:e,deviceKey:r.deviceKey}:null,onSetGate:()=>{},fallbackNodeId:u,onFallbackNodeChange:d,hideGate:!0}):V(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),V(S,{open:ae,onClose:P,title:j?.name??``,subtitle:r&&M?`${e} · ${U(M).label} · ${M.format}`:``,footer:I(R,{children:[V(`div`,{className:`flex-1`}),V(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:P,children:`Cancel`}),V(`button`,{type:`button`,disabled:!r||!a||h.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:ie,children:h.isPending?`Saving…`:`Save`})]}),children:j&&r&&a?I(`div`,{className:`space-y-3`,children:[x&&I(`div`,{className:`rounded-md border border-border bg-muted/10 px-3 py-2 space-y-1`,children:[V(`label`,{className:`block text-[11px] font-medium text-foreground`,children:`Run on`}),I(`select`,{className:`w-full rounded border border-border bg-surface px-2 py-1 text-xs`,value:s,onChange:e=>c(e.target.value),children:[V(`option`,{value:``,children:`Auto (this device, or auto-jump if unsupported)`}),y.filter(e=>e.key!==r.deviceKey).map(e=>I(`option`,{value:e.key,children:[U(e).label,` · `,e.format]},e.key))]}),V(`p`,{className:`text-[10px] leading-snug text-foreground-subtle`,children:`Route this step (and its child steps) to another accelerator on this node.`})]}),V(re,{mode:`agent`,addon:j,agentDefault:a,agentNodeId:e,engineFormat:N,effectiveModelId:te,onChangeAgentConfig:o})]}):V(`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.`})})]})}F();var Zt=[`pipeline-orchestrator`],Qt=[`decoder`],$t=!1;function en({nodeId:e,refreshToken:t}){let n=a(),[r,i]=B(null),[o,s]=B(null),c=(h(void 0).data??[]).find(t=>t.id===e),l=c?.name??e,u=c?.isOnline??!1,d=de({onSuccess:e=>{s(e.effectiveModelId===null?`Reset done — model config cleared (node offline: effective model resolves on reconnect)`:`Reset done — effective detection model: ${e.effectiveModelId} (Auto)`)}}),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`})&&(s(null),d.mutate({agentNodeId:e}))};return I(`div`,{className:`relative h-full w-full space-y-3`,children:[I(`div`,{className:`flex items-center justify-end gap-2 text-xs`,children:[o&&V(`span`,{className:`text-emerald-400`,children:o}),d.isError&&V(`span`,{className:`text-red-400`,children:d.error instanceof Error?d.error.message:`Reset failed`}),V(`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`})]}),V(Jt,{nodeId:e}),V(rt,{nodeId:e,addonIds:Zt,level:`global`,sectionIds:Qt}),$t,$t,I(`div`,{children:[V(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices — default model per accelerator`}),V(De,{nodeId:e,nodeName:l,isOnline:u})]}),I(`div`,{children:[V(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection steps — model per accelerator`}),V(Xt,{nodeId:e,refreshToken:t})]})]})}var tn=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],nn=`decoder-nodeav`;function rn({nodeId:e,refreshToken:t}){let{data:n}=h(void 0),r=n?.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.id??nn,i=[...tn,r];return I(`div`,{className:`flex flex-col h-full`,children:[V(ht,{nodeId:e,refreshToken:t}),V(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-6`,children:V(rt,{nodeId:e,addonIds:i,level:`global`,extraTabs:[{id:`assignments`,label:`Assignments`,order:-10,content:V(Mt,{nodeId:e,refreshToken:t})},{id:`tree`,label:`Pipeline`,order:39,content:V(en,{nodeId:e,refreshToken:t})},{id:`engines`,label:`Warm instances`,order:180,content:V(Pt,{nodeId:e,refreshToken:t})},{id:`models`,label:`Models`,order:200,content:V(Wt,{nodeId:e,refreshToken:t})},{id:`logs`,label:`Logs`,order:300,content:V(qt,{nodeId:e})}]})})]})}function an(){return I(`div`,{className:`space-y-6`,children:[V(Jt,{title:`Cluster cameras`}),I(`div`,{className:`min-w-0`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Placement matrix`}),V(`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.`})]}),V(xt,{mode:`cluster`})]})}var on=`pipeline-orchestrator`,sn=`recorder`,cn=`recordingNodeId`,ln=[`ingestNode`,`recordingNode`,`audioNode`,`motionNode`],un=[{key:`detect`,label:`Detect`,hint:`Runs the detection pipeline (decode + inference) for assigned cameras`}];function dn(e,t){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t)return e.value}function fn(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function pn(e,t,n){let r=dn(e,t);return typeof r==`string`&&r.length>0?r:n}function mn(e,t,n){let r=dn(e,t);return typeof r==`number`&&Number.isFinite(r)?r:n}function hn(e,t){let n=fn(e,t);return typeof n==`number`&&Number.isFinite(n)?n:null}function gn(e,t){let n=fn(e,t);return typeof n==`string`&&n.length>0?n:null}function _n(e){return e===`ingestNode`?`Ingest`:e===`recordingNode`?`Recording`:e===`audioNode`?`Audio`:`Motion Node`}function vn(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 yn(e,t){switch(t){case`detect`:return e.pipeline}}function bn(e){return e instanceof Error?e.message:`Failed to save`}function xn(e){e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAgentSettings`]]}),e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}function Sn({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?qe:Se;return I(`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:[V(u,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":`true`}),V(`span`,{children:t})]})}function Cn({node:e,emphasis:t=!1}){let n=e.isHub?Le:G;return I(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[V(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),V(n,{className:`h-4 w-4 shrink-0 text-foreground-subtle`,"aria-hidden":`true`}),I(`div`,{className:`min-w-0`,children:[I(`div`,{className:`flex items-center gap-1.5 ${t?`text-sm`:`text-xs`} font-semibold text-foreground`,children:[V(`span`,{className:`truncate`,children:e.name}),e.isHub&&V(M,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`hub`}),!e.isOnline&&V(M,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`offline`})]}),V(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:e.id})]})]})}F();function wn({nodeId:e,value:t,detectedHosts:n,status:r,errorMessage:i,onCommit:a}){let[o,s]=B(t??``);H(()=>{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 I(`div`,{className:`flex items-center gap-1.5`,children:[V(`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`}),I(`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?V(W,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):V(qe,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),!f&&!u&&r===`success`&&V(qe,{className:`h-3.5 w-3.5 shrink-0 text-emerald-400`,"aria-label":`Saved`,role:`img`}),r===`error`&&V(`span`,{title:i??`Failed to save reachable host`,children:V(Ke,{className:`h-3.5 w-3.5 shrink-0 text-red-400`,"aria-label":i??`Failed to save reachable host`,role:`img`})})]})}function Tn({label:e,children:t}){return I(`div`,{className:`flex items-center justify-between gap-3`,children:[V(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-foreground-subtle`,children:e}),t]})}function En({node:e,actions:t}){return I(`div`,{className:`rounded-xl border border-border bg-background p-4 space-y-4 ${e.isOnline?``:`opacity-60`}`,children:[V(Cn,{node:e,emphasis:!0}),V(`div`,{className:`grid grid-cols-2 gap-2`,children:un.map(n=>V(Sn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:yn(e.effective,n.key),pending:t.capabilityPending,layout:`card`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)},n.key))}),V(`div`,{className:`space-y-3 border-t border-border pt-3`,children:V(Tn,{label:`Reachable host`,children:V(wn,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})})})]})}function Dn(){return I(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[10px] text-foreground-subtle`,children:[I(`span`,{className:`inline-flex items-center gap-1.5`,children:[V(`span`,{className:`h-2.5 w-2.5 rounded-full border border-success/30 bg-success/15`}),`Active capability`]}),I(`span`,{className:`inline-flex items-center gap-1.5`,children:[V(`span`,{className:`h-2.5 w-2.5 rounded-full border border-border bg-surface-hover`}),`Idle`]}),I(`span`,{className:`inline-flex items-center gap-1.5`,children:[V(`span`,{className:`h-2 w-2 rounded-full bg-success`}),`Node online`]}),I(`span`,{className:`inline-flex items-center gap-1.5`,children:[V(`span`,{className:`h-2 w-2 rounded-full bg-danger`}),`Node offline`]})]})}function On({nodes:e,actions:t}){return V(`div`,{className:`overflow-x-auto rounded-lg border border-border`,children:I(`table`,{className:`w-full min-w-[720px] border-collapse text-sm`,children:[V(`thead`,{children:I(`tr`,{className:`border-b border-border bg-background text-[10px] uppercase tracking-wider text-foreground-subtle`,children:[V(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Node`}),un.map(e=>V(`th`,{className:`px-3 py-3 text-center font-semibold`,children:e.label},e.key)),V(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Reachable host`})]})}),V(`tbody`,{children:e.map(e=>I(`tr`,{className:`border-b border-border last:border-b-0 transition-colors hover:bg-surface-hover/40 ${e.isOnline?``:`opacity-60`}`,children:[V(`td`,{className:`px-4 py-3 align-middle`,children:V(Cn,{node:e})}),un.map(n=>V(`td`,{className:`px-3 py-3 text-center align-middle`,children:V(Sn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:yn(e.effective,n.key),pending:t.capabilityPending,layout:`cell`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)})},n.key)),V(`td`,{className:`px-4 py-3 align-middle`,children:V(wn,{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 kn({role:e,value:t,options:n,pending:r,onChange:i}){return I(`label`,{className:`flex flex-col gap-1.5 rounded-lg border border-border bg-background p-3`,children:[V(`span`,{className:`text-xs font-semibold text-foreground`,children:_n(e)}),V(`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=>V(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),V(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:vn(e)})]})}function An({roleValues:e,options:t,pending:n,lowFpsEnabled:r,fpsMinThreshold:i,onRoleChange:a,onLowFpsToggle:o}){return I(`div`,{className:`grid gap-3 @lg/clustertab:grid-cols-2 @3xl/clustertab:grid-cols-4`,children:[ln.map(r=>V(kn,{role:r,value:e[r],options:t,pending:n,onChange:a},r)),I(`label`,{className:`flex items-start gap-2.5 rounded-lg border border-border bg-background p-3 text-sm text-foreground`,children:[V(`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`}),I(`span`,{className:`flex flex-col gap-0.5`,children:[V(`span`,{className:`text-xs font-semibold`,children:`Low-fps relocate/shed`}),I(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:[`fpsMinThreshold `,r?`${i} fps`:`disabled`]})]})]})]})}F();function jn(){let e=z(),{nodes:r}=_(),i=fe(void 0),a=ue({addonId:on}),o=ue({addonId:sn}),s=()=>xn(e),c=n({onSuccess:s}),l=t(),u=j({onSuccess:s}),d=O({onSuccess:s}),[f,p]=B(!1),m=L(()=>{let e=new Map;for(let t of i.data??[])e.set(t.nodeId,t.settings);return e},[i.data]),h=L(()=>r.map(e=>{let t=m.get(e.id),n=ft(t,e.isHub),r=hn(t,`detectWeight`);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n,weight:r??1,maxCameras:hn(t,`maxCameras`),reachableHost:gn(t,`reachableHost`),detectedHosts:e.localIps}}),[r,m]),g=h.filter(e=>e.effective.pipeline),v={ingestNode:pn(a.data,`ingestNode`,`hub`),recordingNode:pn(o.data,cn,`hub`),audioNode:pn(a.data,`audioNode`,`hub`),motionNode:pn(a.data,`motionNode`,`hub`)},y=L(()=>{let e=r.filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,...ln.map(e=>v[e]),...e])].filter(e=>e.length>0)},[r,v]),b=mn(a.data,`fpsMinThreshold`,0),x=b>0,S=i.isLoading||a.isLoading||o.isLoading,C=(e,t,n)=>{c.mutate({agentNodeId:e,[t]:n})},w=(e,t)=>{if(e===`recordingNode`){d.mutate({addonId:sn,patch:{[cn]:t}});return}d.mutate({addonId:on,patch:{[e]:t}})},T=e=>{d.mutate({addonId:on,patch:{fpsMinThreshold:e?Math.max(1,b):0}})},E=e=>u.variables?.agentNodeId===e?u.isPending?`pending`:u.isError?`error`:u.isSuccess?`success`:`idle`:`idle`,D=e=>E(e)===`error`?bn(u.error):null,k=async e=>{p(!0);try{for(let t of e)await l.mutateAsync({agentNodeId:t.nodeId,detectWeight:t.weight})}finally{p(!1),s()}},A={capabilityPending:c.isPending,onToggleCapability:C,onCommitReachableHost:(e,t)=>u.mutate({agentNodeId:e,reachableHost:t}),reachableHostStatus:E,reachableHostErrorMessage:D};return I(`section`,{className:`rounded-xl border border-border bg-surface p-5 @3xl/clustertab:p-6 space-y-6`,children:[I(`header`,{className:`flex items-start justify-between gap-4`,children:[I(`div`,{className:`space-y-1`,children:[V(`h3`,{className:`text-base font-semibold text-foreground`,children:`Pipeline placement`}),V(`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&&V(W,{className:`h-5 w-5 shrink-0 animate-spin text-foreground-subtle`,"aria-label":`Loading`})]}),I(`div`,{className:`space-y-3`,children:[V(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Singleton cluster roles`}),V(An,{roleValues:v,options:y,pending:d.isPending,lowFpsEnabled:x,fpsMinThreshold:b,onRoleChange:w,onLowFpsToggle:T})]}),I(`div`,{className:`space-y-3`,children:[I(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[V(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Per-node capabilities`}),V(Dn,{})]}),h.length===0?V(`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.`}):I(R,{children:[V(`div`,{className:`grid gap-4 @xl/clustertab:grid-cols-2 @3xl/clustertab:hidden`,children:h.map(e=>V(En,{node:e,actions:A},e.id))}),V(`div`,{className:`hidden @3xl/clustertab:block`,children:V(On,{nodes:h,actions:A})})]})]}),I(`div`,{className:`space-y-3`,children:[V(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection weight`}),V(Te,{nodes:g,pending:f,onCommitWeights:e=>void k(e)})]}),I(`div`,{className:`space-y-3`,children:[V(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices`}),g.length===0?V(`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.`}):V(`div`,{className:`space-y-2`,children:g.map(e=>V(De,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline},e.id))})]})]})}F();var Mn=!1;function Nn({refreshToken:t}){let n=z(),{data:r}=h(void 0);L(()=>tt(r??[]),[r]);let i=e({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})}});return I(`div`,{className:`space-y-6`,children:[V(gt,{refreshToken:t}),V(jn,{}),Mn,I(`div`,{className:`flex flex-col gap-3 @md/clustertab:flex-row @md/clustertab:items-center @md/clustertab:justify-between`,children:[I(`div`,{className:`min-w-0`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Rebalance`}),V(`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.`})]}),I(`button`,{type:`button`,onClick:()=>i.mutate(void 0),disabled:i.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:[V(je,{className:`h-3.5 w-3.5`}),i.isPending?`Rebalancing…`:`Rebalance pipelines`]})]})]})}var Pn=[`pipeline-orchestrator`];function Fn({refreshToken:e}){return V(`div`,{className:`space-y-4 max-w-3xl`,children:V(rt,{nodeId:`hub`,addonIds:Pn,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.`})})}F();function In({refreshToken:e}){let t=z(),{data:n,isLoading:r}=f(),[i,a]=B(null),[o,s]=B(``),[l,u]=B(``),d=()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listTemplates`]]})},p=c({onSuccess:()=>{a(null),d()}}),m=le({onSuccess:d}),h=e=>{a(e.id),s(e.name),u(e.description??``)},g=()=>{a(null),s(``),u(``)},_=()=>{if(!i)return;let e=l.trim();p.mutate({id:i,name:o.trim()||`Untitled`,...e?{description:e}:{}})};if(r)return V(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading templates…`});let v=[...n??[]].toSorted((e,t)=>e.name.localeCompare(t.name));return V(`div`,{className:`space-y-6 max-w-4xl`,children:I(`section`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[I(`div`,{className:`border-b border-border px-4 py-3 flex items-center justify-between`,children:[I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Templates`}),V(`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.`})]}),I(`div`,{className:`text-[11px] text-foreground-subtle`,children:[v.length,` template`,v.length===1?``:`s`]})]}),v.length===0?I(`div`,{className:`px-4 py-8 text-xs text-foreground-subtle flex flex-col items-center gap-2`,children:[V(Ne,{className:`h-6 w-6 opacity-40`}),V(`div`,{children:`No templates yet. Create one from a device Pipeline tab ("Save as template").`})]}):V(`ul`,{className:`divide-y divide-border`,children:v.map(e=>{let t=i===e.id;return V(`li`,{className:`px-4 py-3 text-xs`,children:I(`div`,{className:`flex items-start gap-3`,children:[V(`div`,{className:`flex-1 min-w-0`,children:t?I(`div`,{className:`space-y-2`,children:[V(`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}),V(`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:l,onChange:e=>u(e.target.value),placeholder:`Description (optional)`})]}):I(R,{children:[V(`div`,{className:`font-medium text-foreground`,children:e.name}),e.description&&V(`div`,{className:`text-foreground-subtle mt-0.5`,children:e.description}),I(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:[e.config.steps.length,` step(s)`,e.config.audio?.enabled?` · audio`:``,I(`span`,{className:`ml-2`,children:[`updated `,new Date(e.updatedAt).toLocaleString()]})]})]})}),V(`div`,{className:`flex items-center gap-1 shrink-0`,children:t?I(R,{children:[I(`button`,{type:`button`,onClick:_,disabled:p.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:[V(qe,{className:`h-3 w-3`}),`Save`]}),I(`button`,{type:`button`,onClick:g,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover`,children:[V(Xe,{className:`h-3 w-3`}),`Cancel`]})]}):I(R,{children:[V(`button`,{type:`button`,onClick:()=>h(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:V(Me,{className:`h-3 w-3`})}),V(`button`,{type:`button`,onClick:()=>{confirm(`Delete template "${e.name}"?`)&&m.mutate({id:e.id})},disabled:m.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:V(Ye,{className:`h-3 w-3`})})]})})]})},e.id)})})]})})}F();var Ln=`pipeline-analytics`;function Rn(e){for(let t of e?.sections??[])for(let e of t.fields??[])if(e.key===`postProcessingNodeId`&&typeof e.value==`string`)return e.value;return`hub`}function zn(){let e=z(),{data:t}=h(void 0),{data:n,isLoading:r}=ue({addonId:Ln}),i=Rn(n),a=O({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),o=L(()=>{let e=(t??[]).filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,i,...e])].filter(Boolean)},[t,i]);return I(`div`,{className:`flex flex-col gap-6`,children:[I(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Post-processing node`}),V(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that runs detection post-processing (events, media, audio & motion). Every other node stays inert — no multi-node balancing. Takes effect on addon restart.`}),I(`div`,{className:`mt-3 flex items-center gap-2`,children:[r?V(W,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):V(`select`,{value:i,onChange:e=>{e.target.value!==i&&a.mutate({addonId:Ln,patch:{postProcessingNodeId:e.target.value}})},disabled:a.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:o.map(e=>V(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),a.isPending&&V(W,{className:`h-4 w-4 animate-spin text-primary`})]})]}),I(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[V(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Events folder`}),V(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where event crops / full frames are stored. A single folder — no collection / equal-splitting.`}),V(it,{types:[`eventMedia`]})]})]})}var Bn=`pipeline-orchestrator`,Vn=200;function Hn(){return I(`div`,{className:`flex flex-col gap-3`,children:[I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Orchestrator logs`}),V(`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.`})]}),V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:V(k,{addonId:Bn,limit:Vn,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}F();var Un=[{id:`assignments`,label:`Assignments`},{id:`balancer`,label:`Balancer`},{id:`events`,label:`Events`},{id:`recording`,label:`Recording`},{id:`settings`,label:`Settings`},{id:`templates`,label:`Templates`},{id:`logs`,label:`Logs`}];function Wn({refreshToken:e}){let[t,n]=B(`assignments`);return I(`div`,{className:`flex flex-col h-full`,children:[I(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[V(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),V(`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.`})]}),V(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:Un.map(e=>V(`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))}),I(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[t===`assignments`&&V(an,{}),t===`balancer`&&V(Nn,{refreshToken:e}),t===`events`&&V(zn,{}),t===`recording`&&V(at,{}),t===`settings`&&V(Fn,{refreshToken:e}),t===`templates`&&V(In,{refreshToken:e}),t===`logs`&&V(Hn,{})]})]})}function Gn(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&&n.push({code:`unassigned`,severity:`warning`,message:`Not placed on any detection node — no pipeline is running for this camera`});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 Kn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Y(e){return typeof e==`string`&&e.length>0?e:null}function qn(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function Jn(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function Yn(e,t){return e==null?!1:JSON.stringify(e)!==JSON.stringify(t??null)}var Xn={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 Zn(e){if(!Kn(e)||!Array.isArray(e.sections))return Xn;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)Yn(n.value,n.default)&&r.add(e);return{detectionMode:Y(n(`detectionMode`)),detectionStreamProfile:Y(n(`detectionStreamProfile`)),detectionFps:qn(n(`detectionFps`)),motionSources:Jn(n(`motionSources`)),motionFps:qn(n(`motionFps`)),motionCooldownMs:qn(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 Qn(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(...Qn(r.children,t+1));return n}function $n(e){let{assignment:t,detection:n}=e;return n!==null&&n.provisioning.state===`failed`||t.detectionNodeId===null&&n===null?`error`:n!==null&&n.phase===`active`?`healthy`:`idle`}function X({title:e,children:t}){return I(`div`,{className:`bg-background px-3.5 py-3 min-w-0`,children:[V(`div`,{className:`text-[9px] font-semibold uppercase tracking-[0.14em] text-foreground-subtle mb-2`,children:e}),V(`div`,{className:`flex flex-col gap-1 min-w-0`,children:t})]})}function Z({label:e,children:t,overridden:n=!1}){return I(`div`,{className:`flex items-baseline gap-2 text-[11px] leading-snug min-w-0`,children:[V(`span`,{className:`text-foreground-subtle shrink-0 w-24 truncate`,title:e,children:e}),V(`span`,{className:`font-mono tabular-nums text-foreground min-w-0 truncate flex-1`,children:t}),n&&V(er,{})]})}function er(){return V(`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 V(`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 V(`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 I(`div`,{className:`flex items-center gap-2 text-[11px] leading-snug min-w-0`,children:[V(e,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),V(`span`,{className:`text-foreground-subtle w-[4.5rem] shrink-0`,children:t}),n===null?V(`span`,{className:`text-foreground-subtle italic`,children:`unassigned`}):I(R,{children:[V(`span`,{className:`font-mono text-foreground truncate`,title:n,children:n}),r?I(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] text-warning shrink-0`,title:`Manually pinned`,children:[V(ct,{className:`h-2.5 w-2.5`}),` manual`]}):I(`span`,{className:`text-[10px] text-foreground-subtle shrink-0 truncate`,children:[`auto · `,i!==void 0&&i.length>0?i:`capacity`]}),a&&V(`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 I(X,{title:`Where it runs`,children:[V(nr,{icon:G,label:`Detection`,nodeId:e.detectionNodeId,pinned:e.pinned.detection,reason:e.reasons.detection,overridden:t.overriddenKeys.has(`pipelineNodeId`)}),V(nr,{icon:Be,label:`Decoder`,nodeId:e.decoderNodeId,pinned:e.pinned.decoder,reason:e.reasons.decoder,overridden:t.overriddenKeys.has(`decoderNodeId`)}),V(nr,{icon:Ae,label:`Audio`,nodeId:e.audioNodeId,pinned:e.pinned.audio,reason:e.reasons.audio,overridden:t.overriddenKeys.has(`audioNodeId`)}),V(nr,{icon:Pe,label:`Source`,nodeId:e.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),V(`div`,{className:`mt-1.5`,children:I(`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:[V(`option`,{value:`auto`,children:`Auto (load balanced)`}),o.map(e=>I(`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 I(X,{title:`Streams & motion`,children:[I(Z,{label:`Detect stream`,overridden:n.overriddenKeys.has(`detectionStreamProfile`),children:[n.detectionStreamProfile??`—`,a!==void 0&&` · ${a.width}×${a.height} ${a.codec}`]}),V(Z,{label:`Detect FPS`,overridden:n.overriddenKeys.has(`detectionFps`),children:or(n.detectionFps)}),I(Z,{label:`Motion src`,overridden:n.overriddenKeys.has(`motionSources`),children:[n.motionSources.length>0?n.motionSources.join(` + `):`none`,r===!1&&` · inactive`]}),s&&I(R,{children:[I(Z,{label:`Motion stream`,overridden:n.overriddenKeys.has(`motionStreamProfile`),children:[n.motionStreamProfile??`—`,o!==void 0&&` · ${o.width}×${o.height} ${o.codec}`]}),I(Z,{label:`Motion FPS`,overridden:n.overriddenKeys.has(`motionFps`),children:[or(n.motionFps),i!==null&&` · live ${i.toFixed(1)}`]})]}),V(Z,{label:`Cooldown`,overridden:n.overriddenKeys.has(`motionCooldownMs`),children:n.motionCooldownMs===null?`default`:`${n.motionCooldownMs/1e3}s`}),V(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:e.length===0?V($,{children:`No streams registered`}):e.map(e=>I(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,title:e.camStreamId,children:[V(`span`,{className:`text-foreground-muted`,children:e.kind}),` `,ir(e)]},e.camStreamId))})]})}function cr({steps:e,audioModelId:t,audioEnabled:n,audioMode:r}){return I(X,{title:`Pipeline steps`,children:[e===void 0?V($,{children:`Resolving…`}):e.length===0?V($,{children:`No steps configured`}):V(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>V(Q,{tone:e.enabled&&e.depth===0?`info`:`neutral`,title:e.modelId??e.addonId,children:I(`span`,{className:e.enabled?``:`line-through opacity-60`,children:[e.depth>0&&V(`span`,{className:`opacity-50`,children:`↳ `}),e.addonId,e.modelId!==null&&I(`span`,{className:`font-mono opacity-75`,children:[` · `,e.modelId]})]})},`${e.addonId}-${t}`))}),V(`div`,{className:`mt-1`,children:I(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 I(X,{title:`Detection runtime`,children:[V(Z,{label:`Mode`,overridden:r,children:n??`—`}),V($,{children:`Detection stage inactive or unreachable`})]});let a=t?.phase??e.phase,o=t?.actualFps??e.actualFps,s=t?.configuredFps??e.configuredFps,c=t?.avgInferenceTimeMs??e.avgInferenceMs,l=t?.queueDepth??e.queueDepth,u=i(a),d=a===`active`&&o===0;return I(X,{title:`Detection runtime`,children:[I(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:[I(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-semibold uppercase tracking-wider ${u.badgeClass}`,children:[V(y,{phase:a,className:`h-2.5 w-2.5`}),u.label]}),t!==void 0&&V(`span`,{className:`text-[9px] text-foreground-subtle uppercase tracking-wider`,children:`live`})]}),V(Z,{label:`Mode`,overridden:r,children:n??`—`}),I(Z,{label:`FPS`,children:[V(`span`,{className:d?`text-danger font-semibold`:``,children:o.toFixed(1)}),I(`span`,{className:`text-foreground-subtle`,children:[` / `,s.toFixed(0),` configured`]})]}),I(Z,{label:`Inference`,children:[c.toFixed(0),` ms`,l>0&&I(`span`,{className:`text-warning`,children:[` · queue `,l]}),t!==void 0&&t.droppedFrames>0&&I(`span`,{className:`text-warning`,children:[` · drops `,t.droppedFrames]})]}),I(Z,{label:`Engine`,children:[e.engine.backend,` · `,e.engine.device]}),I(Z,{label:`Provisioning`,children:[V(Q,{tone:lr[e.provisioning.state]??`neutral`,children:e.provisioning.state}),e.provisioning.error!==void 0&&I(`span`,{className:`text-danger text-[10px]`,children:[` `,e.provisioning.error]})]})]})}function dr({broker:e}){return e===null?V(X,{title:`Stream broker`,children:V($,{children:`Broker stage inactive or unreachable`})}):I(X,{title:`Stream broker`,children:[e.profiles.length===0?V($,{children:`No broker profiles`}):V(`div`,{className:`flex flex-col gap-1`,children:e.profiles.map(e=>{let t=e.status===`streaming`,n=t&&e.inFps===0;return I(`div`,{className:`flex items-center gap-2 text-[11px] font-mono tabular-nums min-w-0`,children:[V(`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}),V(`span`,{className:`text-foreground w-10 shrink-0 truncate`,title:e.profile,children:e.profile}),I(`span`,{className:`text-foreground-subtle truncate`,children:[e.width,`×`,e.height,` `,e.codec]}),I(`span`,{className:`ml-auto shrink-0 ${n?`text-danger`:`text-foreground`}`,children:[e.inFps.toFixed(0),`→`,e.outFps.toFixed(0),`fps`]}),I(`span`,{className:`text-foreground-subtle shrink-0`,title:`Subscribers`,children:[`×`,e.subscribers]})]},e.profile)})}),I(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[I(Q,{tone:e.webrtcSessions>0?`info`:`neutral`,children:[`WebRTC `,e.webrtcSessions]}),I(Q,{tone:e.rtspRestream?`success`:`neutral`,children:[`restream `,e.rtspRestream?`on`:`off`]})]})]})}function fr({decoder:e,detectionActive:t}){if(e===null)return V(X,{title:`Decoder`,children:V($,{children:`Decoder stage inactive or unreachable`})});let n=t&&e.shm.framesWritten===0;return I(X,{title:`Decoder`,children:[V(Z,{label:`Node`,children:e.nodeId}),V(Z,{label:`Sessions`,children:e.sessionCount}),I(Z,{label:`SHM frames`,children:[V(`span`,{className:n?`text-danger font-semibold`:``,children:e.shm.framesWritten}),V(`span`,{className:`text-foreground-subtle`,children:` written`})]}),I(Z,{label:`SHM reads`,children:[e.shm.getFrameHits,` hits`,e.shm.getFrameMisses>0&&I(`span`,{className:`text-warning`,children:[` · `,e.shm.getFrameMisses,` misses`]})]}),I(Z,{label:`SHM budget`,children:[e.shm.budgetMb,` MB`]}),e.formats.length>0&&V(Z,{label:`Formats`,children:e.formats.join(`, `)})]})}F();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 V(`div`,{role:`alert`,className:`flex flex-col border-b border-border`,children:e.map(e=>I(`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:[V(Ze,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),V(`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 s=z(),{data:c}=te({addonId:pr,deviceId:e,nodeId:`hub`},{staleTime:3e4}),{data:l}=m({deviceId:e},{staleTime:3e4}),u=L(()=>Zn(c),[c]),d=L(()=>l===void 0?void 0:Qn(l.steps),[l]),f=L(()=>r===void 0?[]:Gn(r),[r]),p=()=>{s.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),s.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},h=N({onSuccess:p}),g=o({onSuccess:p}),_=t=>{t===`auto`?g.mutate({deviceId:e}):h.mutate({deviceId:e,agentNodeId:t})},v=r===void 0?`idle`:$n(r),y=f.some(e=>e.severity===`error`),b=f.length>0,x=y?`border-danger/50`:b?`border-warning/40`:`border-border`;return I(`article`,{"aria-label":`${t} pipeline status`,className:`rounded-lg border ${x} bg-background overflow-hidden`,children:[I(`header`,{className:`flex items-center gap-2.5 px-4 py-2.5 border-b border-border bg-surface/50 min-w-0`,children:[V(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${y?`bg-danger`:mr[v]}`,title:y?`Error`:hr[v],"aria-label":y?`Error`:hr[v],role:`img`}),V(`h3`,{className:`text-[13px] font-semibold text-foreground truncate`,title:t,children:t}),I(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`#`,e]}),!n&&V(Q,{tone:`danger`,children:`offline`}),I(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[u.detectionMode!==null&&V(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?I(Q,{tone:`danger`,title:`Recording (${r.recording.mode})`,children:[V(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-danger animate-pulse`}),`REC`]}):r.recording.mode!==`off`&&I(Q,{tone:`neutral`,title:`Recording mode`,children:[`rec `,r.recording.mode]}))]})]}),f.length>0&&V(gr,{problems:f}),r===void 0?V(`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.`}):I(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-px bg-border`,children:[V(rr,{assignment:r.assignment,settings:u,onlineNodes:a,pinPending:h.isPending||g.isPending,onDetectionPinChange:_}),V(ur,{detection:r.detection,live:i,detectionMode:u.detectionMode,modeOverridden:u.overriddenKeys.has(`detectionMode`)}),V(cr,{steps:d,audioModelId:l?.audio?.modelId??null,audioEnabled:r.audio?.enabled??l?.audio?.enabled??null,audioMode:u.audioMode}),V(sr,{streams:r.source.streams,brokerProfiles:r.broker?.profiles,settings:u,motionEnabled:r.motion?.enabled??null,motionFpsLive:r.motion?.fps??null}),V(dr,{broker:r.broker}),V(fr,{decoder:r.decoder,detectionActive:r.detection?.phase===`active`})]})]})}F();var vr=5e3,yr=1e4,br=5e3;function xr(e){let t=z(),{data:n,isLoading:r}=Ee(),{data:i,isLoading:a}=P({},{refetchInterval:vr}),{nodes:o}=_();H(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[s,c]=B(new Map);d(ve.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})}),H(()=>{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=L(()=>{let e=new Map;for(let t of i??[])e.set(t.deviceId,t);return e},[i]);return{rows:L(()=>(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:L(()=>(o??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[o]),isLoading:r||a}}F();function Sr({refreshToken:e}){let{rows:t,liveMetrics:n,onlineNodes:r,isLoading:i}=xr(e),a=L(()=>[...t.map(e=>{let t=e.status===void 0?[]:Gn(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=L(()=>{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?V(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Loading camera pipelines…`}):t.length===0?V(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`No cameras found`}):V(`div`,{className:`h-full overflow-y-auto`,children:I(`div`,{className:`max-w-6xl mx-auto flex flex-col gap-3 px-4 py-4`,children:[I(`div`,{className:`flex items-center gap-4 text-[11px] text-foreground-subtle px-1`,children:[I(`span`,{children:[V(`span`,{className:`font-semibold text-foreground`,children:o.total}),` cameras`]}),I(`span`,{children:[V(`span`,{className:`font-semibold text-success`,children:o.active}),` actively inferring`]}),I(`span`,{children:[V(`span`,{className:`font-semibold ${o.issues>0?`text-danger`:`text-foreground`}`,children:o.issues}),` `,`with issues`]}),V(`span`,{className:`ml-auto hidden sm:inline text-[10px]`,children:`polled every 5 s · detection metrics live at 1 Hz`})]}),a.map(({row:e})=>V(_r,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:n.get(e.deviceId),onlineNodes:r},e.deviceId))]})})}F();var Cr=`__cluster__`;function wr(e){return e===`cameras`?`cameras`:`nodes`}function Tr(){let[e,t]=Je(),n=wr(e.get(`view`)),r=e.get(`node`)??`__cluster__`,[i,a]=B(0),[o,s]=B(!1);return H(()=>{n===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:Cr},{replace:!0})},[n,e,t]),I(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[I(`div`,{className:`flex items-center justify-between gap-4 px-4 py-3 border-b border-border shrink-0`,children:[I(`div`,{className:`flex items-center gap-1 rounded-lg border border-border p-0.5 bg-surface`,children:[V(`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`}),V(`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`})]}),I(`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:[V(Fe,{className:`h-3.5 w-3.5`}),`Refresh`]})]}),n===`nodes`&&I(`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:[I(`span`,{children:[o?`Hide`:`Show`,` node list`]}),V(We,{className:[`h-4 w-4 transition-transform`,o?`rotate-180`:``].join(` `)})]}),V(`div`,{className:`flex-1 flex flex-col md:flex-row overflow-hidden min-h-0`,children:n===`nodes`?I(R,{children:[V(`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:V(mt,{selectedNodeId:r,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),s(!1)},refreshToken:i})}),V(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:r===`__cluster__`?V(Wn,{refreshToken:i}):V(rn,{nodeId:r,refreshToken:i})})]}):V(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:V(Sr,{refreshToken:i})})})]})}export{Tr as PipelinePage};
@@ -1 +0,0 @@
1
- import{t as e}from"./rolldown-runtime-Cyuzqnbw.js";var t=e(((e,t)=>{t.exports={}}));export default t();
@@ -1 +0,0 @@
1
- import{G as e}from"./index-B4yaKbnm.js";var t=e(`circle-check-big`,[[`path`,{d:`M21.801 10A10 10 0 1 1 17 3.335`,key:`yps3ct`}],[`path`,{d:`m9 11 3 3L22 4`,key:`1pflzl`}]]);export{t};
@@ -1 +0,0 @@
1
- import{G as e}from"./index-B4yaKbnm.js";var t=e(`clock`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`polyline`,{points:`12 6 12 12 16 14`,key:`68esgv`}]]);export{t};