@camstack/addon-admin-ui 1.2.29 → 1.2.31

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 (90) hide show
  1. package/dist/assets/{AddLocationWizard-f89-IkPt.js → AddLocationWizard-C8l2xgGA.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-Ch2XRf5H.js → AddonCollectionPage-C6c6iSQR.js} +1 -1
  3. package/dist/assets/{Addons-CdHie4yk.js → Addons-BltMkzm5.js} +1 -1
  4. package/dist/assets/{AdminTabs-CMrAY8Sg.js → AdminTabs-BlETE4he.js} +1 -1
  5. package/dist/assets/{AiProfiles-pTNZy3y1.js → AiProfiles-BcPA79i8.js} +1 -1
  6. package/dist/assets/{Automation-QfkBqrcI.js → Automation-C28vW-50.js} +1 -1
  7. package/dist/assets/{BrokerForm-BAZ82UHs.js → BrokerForm-DV5P6yLC.js} +1 -1
  8. package/dist/assets/{Capabilities-BU0m67L8.js → Capabilities-I7OecGck.js} +1 -1
  9. package/dist/assets/{CapabilityBadges-Bd-jxf5M.js → CapabilityBadges-CeffiM3_.js} +1 -1
  10. package/dist/assets/{Cluster-Kz7sxkEh.js → Cluster-CtsElqbm.js} +1 -1
  11. package/dist/assets/{ClusterRecordingTab-1Ep0a4vW.js → ClusterRecordingTab-Cu4e2Sa0.js} +1 -1
  12. package/dist/assets/{Dashboard-BkqNzZ9k.js → Dashboard-BV2-sKn8.js} +1 -1
  13. package/dist/assets/{Data-VrvWqvck.js → Data-D_in2E11.js} +1 -1
  14. package/dist/assets/{DetectionIntelligence-DhvaWm4u.js → DetectionIntelligence-DoDZdfkQ.js} +1 -1
  15. package/dist/assets/{DeviceAggregateSection-BjhiujPl.js → DeviceAggregateSection-BM70M394.js} +1 -1
  16. package/dist/assets/DeviceDetail-BkHiJUVr.js +2 -0
  17. package/dist/assets/{Devices-D8-uaQ9P.js → Devices-B3eRW0ZV.js} +1 -1
  18. package/dist/assets/{EmbedPlayerPage-VSLkL4EV.js → EmbedPlayerPage-BsSzvPTu.js} +1 -1
  19. package/dist/assets/{Events-C2Pic1x_.js → Events-CbDa9mNk.js} +1 -1
  20. package/dist/assets/{FormBuilder-4LCVdSVV.js → FormBuilder-CjOCkLVf.js} +1 -1
  21. package/dist/assets/{Identity-q7i7NqN9.js → Identity-BOJJJ9fs.js} +1 -1
  22. package/dist/assets/{IntegrationDetail-Dkxb4wOF.js → IntegrationDetail-AqDFph4_.js} +1 -1
  23. package/dist/assets/{Integrations-Bp74D4gz.js → Integrations-5slYYtBd.js} +1 -1
  24. package/dist/assets/{Integrations-Ds4j_JJ8.js → Integrations-UekIuTxN.js} +1 -1
  25. package/dist/assets/{Logs-fg8GZafU.js → Logs-CcRjhQ8q.js} +1 -1
  26. package/dist/assets/{MotionZonesSettings-DjXYc9mc.js → MotionZonesSettings-CeuQ-dQ4.js} +1 -1
  27. package/dist/assets/{MyAccess-COiq6WO3.js → MyAccess-C6ZM2f5P.js} +1 -1
  28. package/dist/assets/{Network-CiqowSs4.js → Network-D0CKemO3.js} +1 -1
  29. package/dist/assets/{NodeAddonsSettingsPanel-BGclM9Ra.js → NodeAddonsSettingsPanel-D2e6v5bt.js} +1 -1
  30. package/dist/assets/{NodeInferenceDevices-DrRLe_-U.js → NodeInferenceDevices-BCis98Y5.js} +1 -1
  31. package/dist/assets/Notifications-DITbe32-.js +1 -0
  32. package/dist/assets/{Pipeline-BJAW6qZG.js → Pipeline-BuUTm7JS.js} +1 -1
  33. package/dist/assets/{Plates-CvGuC_Lp.js → Plates-BJe-z0Ly.js} +1 -1
  34. package/dist/assets/{PrivacyMaskSettings-_kxexVKf.js → PrivacyMaskSettings-DL1wRk3D.js} +1 -1
  35. package/dist/assets/{ProviderIcon-wbxEq0bC.js → ProviderIcon-DTUqxb3A.js} +1 -1
  36. package/dist/assets/{Recordings-Nl54spnw.js → Recordings-DsFS0v_V.js} +1 -1
  37. package/dist/assets/{ScanNetworkModal-DeJtIRyh.js → ScanNetworkModal-Sh8DKc_Z.js} +1 -1
  38. package/dist/assets/{Settings-DeEQKEal.js → Settings-CX4Nf9gj.js} +1 -1
  39. package/dist/assets/{Showroom-CEeMdl7x.js → Showroom-BMroQnR-.js} +1 -1
  40. package/dist/assets/{Terminal-Bg-v89nq.js → Terminal-WVzNWGgt.js} +1 -1
  41. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CDUWxK0N.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-ueW3CNXD.js} +1 -1
  42. package/dist/assets/{build-cluster-graph-Cv0zvtyF.js → build-cluster-graph-BQfyn5-h.js} +1 -1
  43. package/dist/assets/circle-check-big-DeInsepB.js +1 -0
  44. package/dist/assets/clock-BW_cTo5d.js +1 -0
  45. package/dist/assets/{copy-CL5WAyDW.js → copy-CgqX6jAd.js} +1 -1
  46. package/dist/assets/{debounced-invalidate-DCC0mRXL.js → debounced-invalidate-Ckd5veqP.js} +1 -1
  47. package/dist/assets/{dist-AGMCUw5A.js → dist-CWZqSYg7.js} +1 -1
  48. package/dist/assets/dist-QF9uqGQD.js +7 -0
  49. package/dist/assets/{download-_vQgHc_K.js → download-p0j7iBId.js} +1 -1
  50. package/dist/assets/{face-bbox-BzRb0Cay.js → face-bbox-D1cykRSA.js} +1 -1
  51. package/dist/assets/{hostInit-BvGX5XHF.js → hostInit-Dt2ASvrJ.js} +1 -1
  52. package/dist/assets/{index-BeCIFexS.js → index-CCxo3WRY.js} +3 -3
  53. package/dist/assets/{key-round-BLz8Hopw.js → key-round-Cx7q2or5.js} +1 -1
  54. package/dist/assets/{mf-entry-bootstrap-0-6ae366a5.js → mf-entry-bootstrap-0-ba8db39e.js} +2 -2
  55. package/dist/assets/{pencil-omAkHegX.js → pencil-CSOkVyOg.js} +1 -1
  56. package/dist/assets/player-overlays-DMopxtfV.js +1 -0
  57. package/dist/assets/plus-65CWfpkk.js +1 -0
  58. package/dist/assets/{radio-DoX1V1g-.js → radio-sWK9osbk.js} +1 -1
  59. package/dist/assets/{refresh-cw-CE37ff37.js → refresh-cw-DvvUyPxz.js} +1 -1
  60. package/dist/assets/remoteEntry-BG0gquJL.js +1 -0
  61. package/dist/assets/{rotate-ccw-DkNejMx0.js → rotate-ccw-C9AgJ2n3.js} +1 -1
  62. package/dist/assets/rotate-cw-DzWdgqzc.js +1 -0
  63. package/dist/assets/search-C0NOsICx.js +1 -0
  64. package/dist/assets/{send-BOE-EMzz.js → send-DHGacLkf.js} +1 -1
  65. package/dist/assets/{server-Cmm-r2A6.js → server-BTkuOhTj.js} +1 -1
  66. package/dist/assets/square-5WfxRUZm.js +1 -0
  67. package/dist/assets/{square-check-big-BAgeP4VI.js → square-check-big-Bj-h9e8-.js} +1 -1
  68. package/dist/assets/src-Bbly4y8Q.js +7 -0
  69. package/dist/assets/src-DMF-vfTM.js +67 -0
  70. package/dist/assets/{upload-BgE7db3Z.js → upload-DpVq2e2i.js} +1 -1
  71. package/dist/assets/{useEventInvalidation-Cw6wrN4q.js → useEventInvalidation-d8_SLAo2.js} +1 -1
  72. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BlNrk-4E.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CxUAKqIn.js} +2 -2
  73. package/dist/assets/{wifi-DfeLPHsk.js → wifi-DTySHt8w.js} +1 -1
  74. package/dist/assets/{zap-Bp4zqxqw.js → zap-r1jKR3Im.js} +1 -1
  75. package/dist/index.html +5 -5
  76. package/dist/server/addon.js +12821 -12572
  77. package/package.json +1 -1
  78. package/dist/assets/DeviceDetail-CkQKBq03.js +0 -2
  79. package/dist/assets/Notifications-DQQm9HiJ.js +0 -1
  80. package/dist/assets/circle-check-big-CkPzYYPA.js +0 -1
  81. package/dist/assets/clock-J0G5s40X.js +0 -1
  82. package/dist/assets/dist-B3duXlmo.js +0 -7
  83. package/dist/assets/player-overlays-DHswkbsp.js +0 -1
  84. package/dist/assets/plus-BpyRM_02.js +0 -1
  85. package/dist/assets/remoteEntry-Czt3qcfu.js +0 -1
  86. package/dist/assets/rotate-cw-DjzrA-is.js +0 -1
  87. package/dist/assets/search-BfmAjYfy.js +0 -1
  88. package/dist/assets/square-CC6Ki3FL.js +0 -1
  89. package/dist/assets/src-BuqU1Y2C.js +0 -67
  90. package/dist/assets/src-d71rtvEQ.js +0 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/addon-admin-ui",
3
- "version": "1.2.29",
3
+ "version": "1.2.31",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Admin UI — Vite frontend build and server-side addon",
@@ -1,2 +0,0 @@
1
- import{$ as e,$i as t,An as n,Bn as r,Bt as i,Cn as a,D as o,Dn as s,E as c,F as l,Fo as u,Ga as d,Gn as f,H as p,Ha as m,Hn as h,J as g,Ln as _,Lr as v,Mi as y,Mn as b,N as x,Nn as S,O as C,On as ee,P as w,Pn as te,Q as T,Ri as ne,T as E,Tt as re,U as ie,Ua as D,Un as ae,Vn as oe,W as O,Wn as k,Wr as A,X as j,Y as se,Z as ce,_r as M,a as N,ao as P,at as le,cn as ue,do as F,dr as de,eo as fe,et as pe,f as me,fo as I,g as he,gn as L,hi as ge,i as R,ii as z,io as _e,ji as ve,jn as ye,l as be,ln as xe,lo as Se,m as Ce,mo as we,n as Te,no as Ee,o as De,oo as Oe,ot as ke,p as Ae,pi as je,r as Me,rt as Ne,so as Pe,st as Fe,to as Ie,tt as Le,u as Re,uo as ze,vi as Be,vn as Ve,vr as He,wn as Ue,xi as We,y as Ge,yr as Ke,zn as qe}from"./src-BuqU1Y2C.js";import{I as Je,K as B,Q as V,S as H,W as U,a as Ye,b as W,o as G,q as K,t as Xe,x as q,z as J}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{A as Y,F as Ze,I as Qe,K as $e,M as et,N as tt,O as nt,P as rt,S as it,j as at,v as ot,x as st}from"./src-d71rtvEQ.js";import{c as ct,k as lt,p as X,r as ut,t as dt,u as ft}from"./player-overlays-DHswkbsp.js";import{t as pt}from"./CapabilityBadges-Bd-jxf5M.js";import{n as mt,t as ht}from"./rotate-ccw-DkNejMx0.js";import{t as gt}from"./ProviderIcon-wbxEq0bC.js";import{a as _t,c as vt,l as yt,n as bt,o as xt}from"./NodeInferenceDevices-DrRLe_-U.js";import{n as St}from"./FormBuilder-4LCVdSVV.js";import{t as Ct}from"./pencil-omAkHegX.js";import{t as wt}from"./plus-BpyRM_02.js";import{t as Tt}from"./refresh-cw-CE37ff37.js";import{t as Et}from"./rotate-cw-DjzrA-is.js";import{t as Dt}from"./server-Cmm-r2A6.js";import{t as Ot}from"./wifi-DfeLPHsk.js";import{B as kt,C as At,G as jt,H as Mt,J as Nt,M as Pt,R as Ft,W as It,Y as Lt,b as Rt,c as zt,h as Bt,i as Vt,j as Ht,l as Ut,o as Wt,q as Gt,t as Kt,y as qt}from"./index-BeCIFexS.js";import{t as Jt}from"./StatusBadge-Dcr2bw58.js";import{t as Yt}from"./useEventInvalidation-Cw6wrN4q.js";import{i as Xt,n as Zt,r as Qt,t as $t}from"./DeviceAggregateSection-BjhiujPl.js";var en=jt(`circle-help`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),tn=jt(`link-2-off`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7`,key:`10o201`}],[`path`,{d:`M15 7h2a5 5 0 0 1 4 8`,key:`1d3206`}],[`line`,{x1:`8`,x2:`12`,y1:`12`,y2:`12`,key:`rvw6j4`}],[`line`,{x1:`2`,x2:`22`,y1:`2`,y2:`22`,key:`a6p6uj`}]]),nn=jt(`link-2`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`,key:`8i5ue5`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`,key:`1b9ql8`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`,key:`1jonct`}]]),rn=jt(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),an=jt(`volume-2`,[[`path`,{d:`M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z`,key:`uqj9uw`}],[`path`,{d:`M16 9a5 5 0 0 1 0 6`,key:`1q6k2b`}],[`path`,{d:`M19.364 18.364a9 9 0 0 0 0-12.728`,key:`ijwkga`}]]);V();function on({parentDeviceId:e}){let{t}=Kt(),n=Gt(),r=X(),{data:i,isLoading:a,isError:o}=xt(e),{data:c}=s({deviceId:e},{enabled:Number.isFinite(e)});if(a)return q(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:q(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(o)return q(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:q(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let l=(i??[]).filter(e=>e.display?.hidden!==!0);if(l.length===0)return null;let u=j(c?.stableId??``,l,c?.childLayout),d=u.ungrouped,f=e=>n(`/devices/${String(e)}`),p=c?.name??``,m=(e,t)=>q(g,{trpc:r.trpcClient,device:{...t,name:pe(t,p)},variant:`minimal`,onNavigate:f},e),h=d.some(e=>!!e.role),_=d.some(e=>!e.role),v=h&&!_?t(`device.accessories`,{defaultValue:`Accessories`}):!h&&_?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),y=d.length>0?H(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[q(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:v}),q(`div`,{className:`space-y-1`,children:d.map(e=>m(e.id,e))})]}):null,b=u.disabledSection===void 0?null:q(se,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:u.disabledSection.children.length,defaultOpen:!1,children:q(`div`,{className:`opacity-60 space-y-1`,children:u.disabledSection.children.map(e=>m(e.id,e))})},u.disabledSection.title);return u.sections.length===0?b===null?y:H(`div`,{className:`space-y-2`,children:[y,b]}):H(`div`,{className:`space-y-2`,children:[u.sections.map(e=>q(se,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>m(e.id,e))},e.title)),y,b]})}function sn({deviceName:e,deviceType:t,provider:n,isOnline:r,features:i}){return H(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-surface p-6 text-center`,children:[q(gt,{type:n,size:`lg`}),H(`div`,{children:[q(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),q(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),H(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[q(Jt,{status:r?`online`:`offline`}),i.length>0&&q(pt,{capabilities:i})]}),q(`div`,{className:`text-[10px] text-foreground-subtle italic max-w-xs mt-1`,children:`No live view for this device type. Use the Config tab or the shortcut row to interact.`})]})}function cn({deviceId:e}){let t=G(),n=ue({deviceId:e},{refetchInterval:1e4,retry:!1}),r=xe({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),i=U(()=>ln(n.data??[]),[n.data]);return H(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[H(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[q(un,{label:`Discovered`,value:i.total,icon:q(qt,{className:`h-3.5 w-3.5`})}),q(un,{label:`Adopted`,value:i.adopted,accent:`success`}),q(un,{label:`Available`,value:i.available,accent:i.available>0?`primary`:void 0}),H(`button`,{type:`button`,onClick:()=>{r.mutateAsync({deviceId:e}).catch(()=>{})},disabled:r.isPending,className:`inline-flex items-center justify-center gap-1.5 rounded-lg border border-border px-3 py-2 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 self-stretch shrink-0`,children:[r.isPending?q(At,{className:`h-3.5 w-3.5 animate-spin`}):q(Tt,{className:`h-3.5 w-3.5`}),q(`span`,{className:`hidden sm:inline`,children:`Discover`})]})]}),H(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-foreground-subtle border-t border-border-subtle pt-2`,children:[q(dn,{icon:q(Ot,{className:`h-3 w-3 text-emerald-500`}),label:`${i.online} online`}),q(dn,{icon:q(Rt,{className:`h-3 w-3 text-amber-500`}),label:`${i.sleeping} sleeping`}),q(dn,{icon:q(Wt,{className:`h-3 w-3 text-destructive`}),label:`${i.offline} offline`}),i.unknown>0?q(dn,{icon:q(en,{className:`h-3 w-3 text-foreground-subtle`}),label:`${i.unknown} unknown`}):null]})]})}function ln(e){let t={total:e.length,adopted:0,available:0,online:0,sleeping:0,offline:0,unknown:0};for(let n of e)n.alreadyAdopted?t.adopted+=1:t.available+=1,t[n.status]+=1;return t}function un({label:e,value:t,icon:n,accent:r}){return H(`div`,{className:`flex flex-1 basis-[140px] min-w-0 flex-col gap-1 rounded-lg border px-2 py-1.5 sm:px-3 sm:py-2 ${r===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:r===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[H(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,q(`span`,{className:`truncate`,children:e})]}),q(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function dn({icon:e,label:t}){return H(`span`,{className:`inline-flex items-center gap-1`,children:[e,q(`span`,{children:t})]})}function fn({deviceId:e,features:t}){return q(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:q(D,{trpc:X().trpcClient,deviceId:e,features:t})})}function pn({deviceId:e,features:t}){return q(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:q(m,{trpc:X().trpcClient,deviceId:e,features:t})})}V();function mn({dev:e,busy:t,setBusy:n}){let r=e?.motionTrigger,i=ft(e?.state.motionTrigger),[a,o]=K(!1);if(!r)return null;let s=i?.enabled===!0,c=i!==void 0,l=async()=>{if(t||!c)return;let e=!s;n(!0),o(!0);try{await r.setMotionTrigger({enabled:e})}finally{n(!1),o(!1)}};return H(`button`,{type:`button`,onClick:()=>{l()},disabled:t||!c,title:c?s?`Disable trigger on motion`:`Enable trigger on motion`:`Awaiting state…`,"aria-pressed":s,className:`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-[11px] font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${s?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground`}`,children:[q(It,{className:`h-3 w-3`}),q(`span`,{children:a?s?`Disabling…`:`Enabling…`:c?s?`On motion: on`:`On motion: off`:`On motion: …`})]})}V();function Z({deviceId:e,deviceType:t,features:n}){let r=X(),i=ke(t)?.HeroCard??m,a=ct(r.trpcClient,e),o=ft(a?.state.deviceStatus),[s,c]=K(!1),l=o!==void 0&&o.online===!1,u=l?o.lastChangedAt:null;return H(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[l?q(`div`,{className:`flex justify-center`,children:q(O,{lastChangedAt:u})}):null,q(i,{trpc:r.trpcClient,deviceId:e,features:n}),q(`div`,{className:`flex justify-center`,children:q(mn,{dev:a,busy:s,setBusy:c})})]})}function hn({deviceId:e}){let t=X(),{data:n,isLoading:r}=_t(e),{data:i,isLoading:a}=xt(e),o=r||a,s=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,features:e.features,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),c=typeof n?.linkDeviceId==`number`?n.linkDeviceId:null,l=typeof n?.primaryChildEntityId==`string`?n.primaryChildEntityId:null;return o?q(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):q(`div`,{className:`flex h-full w-full flex-col`,children:q(ie,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}var gn={[Y.Switch]:Z,[Y.Siren]:Z,[Y.Light]:Z,[Y.Sensor]:Z,[Y.Button]:Z,[Y.Hub]:cn,[Y.Cover]:fn,[Y.Valve]:Z,[Y.Humidifier]:Z,[Y.WaterHeater]:Z,[Y.Container]:hn,[Y.Lock]:Z,[Y.Fan]:Z,[Y.Thermostat]:Z,[Y.Climate]:Z,[Y.MediaPlayer]:Z,[Y.Control]:Z,[Y.AlarmPanel]:pn,[Y.EventEmitter]:pn,[Y.Notifier]:pn,[Y.Script]:pn,[Y.Automation]:pn,[Y.Presence]:Z,[Y.Update]:Z,[Y.Vacuum]:Z,[Y.LawnMower]:Z,[Y.Weather]:Z,[Y.Image]:Z,[Y.PetFeeder]:Z};function _n(e){return q(gn[e.deviceType]??sn,{...e})}function vn(e){return N(X().trpcClient,e)}V();function yn(e){let[t,n]=K(`idle`),[r,i]=K(null),a=B(null),o=B(null),s=B(null),c=B(!0),l=He(),u=M(),d=Ke(),f=Je(()=>{if(a.current){try{a.current.close()}catch{}a.current=null}if(o.current){for(let e of o.current.getTracks())try{e.stop()}catch{}o.current=null}s.current=null},[]),p=Je(async()=>{if(t===`idle`)return;n(`stopping`);let r=s.current;if(r&&e!==null)try{await Promise.race([d.mutateAsync({deviceId:e,sessionId:r}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}f(),c.current&&(n(`idle`),i(null))},[t,e,d,f]),m=Je(async()=>{if(e===null||t!==`idle`&&t!==`error`)return;i(null);let r=null,f=null,m=null;try{n(`requesting-mic`),r=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),o.current=r,n(`starting`);let t=await l.mutateAsync({deviceId:e});m=t.sessionId,s.current=m,n(`connecting`),f=new RTCPeerConnection,a.current=f,f.oniceconnectionstatechange=()=>{if(!c.current)return;let e=f.iceConnectionState;e===`connected`||e===`completed`?n(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&c.current&&(i(e===`failed`?`WebRTC connection failed`:null),p())};for(let e of r.getAudioTracks())f.addTrack(e,r);await f.setRemoteDescription({type:`offer`,sdp:t.sdpOffer});let d=await f.createAnswer();await f.setLocalDescription(d);let h=f.localDescription?.sdp??d.sdp??``;await u.mutateAsync({deviceId:e,sessionId:m,sdpAnswer:h})}catch(t){let l=t instanceof Error?t.message:String(t);if(console.warn(`[intercom] start failed`,t),f)try{f.close()}catch{}if(r)for(let e of r.getTracks())try{e.stop()}catch{}if(a.current=null,o.current=null,m!==null)try{await d.mutateAsync({deviceId:e,sessionId:m})}catch{}s.current=null,c.current&&(i(l),n(`error`))}},[e,t,l,u,d,p]);return J(()=>(c.current=!0,()=>{c.current=!1;let t=s.current;if(t!==null&&e!==null&&d.mutate({deviceId:e,sessionId:t}),a.current){try{a.current.close()}catch{}a.current=null}if(o.current){for(let e of o.current.getTracks())try{e.stop()}catch{}o.current=null}s.current=null}),[e]),{state:t,error:r,start:m,stop:p,isTalking:t===`talking`}}V();var bn=0;function Q(){return++bn}function xn(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function Sn(e){return[``,`Commands`,` help Show this help`,` examples Show usage examples for the current scope`,` context Show every available variable + full API surface`,` clear Clear terminal (also Ctrl+L)`,``,`Shortcuts`,` Enter Execute expression`,` Arrow Up/Down Navigate command history`,` Ctrl+L Clear terminal`,``,`Try: ${{system:` sm.summary() // fleet overview`,device:` device.state.battery.value?.sleeping // sync read`,provider:` devices.map(d => d.name)`,addon:` manifest.version`}[e.type]}`,``,`Top-level objects: sm (SystemMirror), DeviceType, Math, JSON, Date, …`]}function Cn(e){switch(e.type){case`device`:return[``,`── State (sync, zero round-trip) ─────────────────────────`,` device.state.battery.value`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,``,`── Actions (async, through wrapper chain) ────────────────`,` await device.snapshot.getSnapshot({})`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.switch.setState({ on: true })`,``,`── Wait for condition ───────────────────────────────────`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`── Subscribe to changes ─────────────────────────────────`,` const off = device.state.battery.subscribe(s => console.log(s))`,``,`── Quick info ───────────────────────────────────────────`,` info.name device name`,` info.addonId owning addon`,` sm.dump(deviceId) full debug dump`];case`system`:return[``,`── Lookups ──────────────────────────────────────────────`,` sm.getDeviceById(8)`,` sm.getDeviceByName('Sala da pranzo')`,` sm.getDevicesByAddon('reolink')`,` sm.getDevicesByType(DeviceType.Camera)`,``,`── Filters (typed query) ────────────────────────────────`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] })`,` sm.query({ name: /^Cam-/ })`,``,`── Cross-device ─────────────────────────────────────────`,` sm.whereState('battery', s => s.percentage < 20).length`,` sm.mapState('battery', s => s.percentage)`,` sm.countByCap('snapshot')`,``,`── Batch action ─────────────────────────────────────────`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,``,`── Listen ───────────────────────────────────────────────`,` sm.listenCap('motion', (id, s) => console.log(id, s))`,` sm.onDeviceAdded((id, info) => console.log('+', info.name))`,``,`── Diagnostics ──────────────────────────────────────────`,` sm.summary()`,` sm.dump(8)`];case`provider`:return[``,` devices.map(d => d.name)`,` await getIntegration()`,` sm.getDevicesByAddon('<this-addon-id>').length`];case`addon`:return[``,` manifest.name`,` manifest.version`,` declaration`]}}function wn(e){let t=[``,`Scope: ${e.type}`,``];switch(e.type){case`system`:return[...t,`Primary API — sm (SystemMirror):`,` sm.getDeviceById(id) DeviceProxy | null (sync)`,` sm.getDeviceByName(name) DeviceProxy | null`,` sm.getDeviceByStableId(sid) DeviceProxy | null`,` sm.getAllDevices() readonly DeviceProxy[]`,` sm.getDeviceInfo(id) DeviceInfo | null`,` sm.summary() fleet stats`,``,`Filters — sm.query({...}):`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] }) // ALL caps required`,` sm.query({ anyCap: ['ptz', 'motion'] }) // ANY cap`,` sm.query({ name: { contains: 'sala' } }) // case-insensitive`,` sm.query({ name: /^Cam-\\d+$/ })`,` sm.query({ type: DeviceType.Camera })`,` sm.query({ parentDeviceId: 8 }) // accessories of cam 8`,` sm.query({ where: (info, dev) => dev.state.battery.value?.sleeping })`,``,`State queries:`,` sm.whereState('battery', s => s.percentage < 20)`,` sm.mapState('battery', s => s.percentage)`,` sm.findState('motion', s => s.detected)`,` sm.countByCap('snapshot')`,``,`Listeners (return unsubscribe fn):`,` sm.listen((id, cap, slice) => …) // every state change`,` sm.listenCap('motion', (id, slice) => …)`,` sm.listenDevice(8, (id, cap, slice) => …)`,` sm.onDeviceAdded((id, info) => …)`,` sm.onDeviceRemoved((id, info) => …)`,``,`Wait primitives:`,` await sm.waitForState(8, 'battery', s => !s.sleeping, 30_000)`,` await sm.waitForDevice(99, 30_000)`,``,`Batch:`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,` await sm.forEachCap('reboot', d => d.reboot.reboot({}))`,``,`Diagnostics:`,` sm.dump(8) debug dump (one device)`,` sm.dump() full fleet dump`,` sm.summary() breakdown by cap/addon/type`,``,`Legacy: deviceRegistry, addonRegistry, eventBus, devices(), addons()`];case`device`:return[...t,`Pre-bound variables:`,` device DeviceProxy for this device (sync state + async methods)`,` deviceId number`,` info DeviceInfo metadata (name, addonId, type, online, …)`,` sm SystemMirror (full cluster view)`,` rawDevice legacy IDevice instance (escape hatch)`,``,`Reactive state (sync, zero round-trip):`,` device.state.battery.value BatteryStatus | undefined`,` device.state.battery.value?.sleeping`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,` device.state.switch.value?.on`,` device.state.brightness.value?.percentage`,` device.state.doorbell.value?.lastPressedAt`,``,`Cap actions (async, through wrapper chain):`,` await device.snapshot.getSnapshot({})`,` await device.snapshot.getSnapshot({ streamId: 'high' })`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.ptz.goToPreset({ presetId: 'home' })`,` await device.switch.setState({ on: true })`,` await device.brightness.setBrightness({ percentage: 60 })`,` await device.reboot.reboot({})`,``,`Subscribe to slice changes:`,` const off = device.state.battery.subscribe(s => console.log(s))`,` // off() to unsubscribe`,``,`Wait for a state condition:`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`Diagnostics:`,` info.name device name`,` info.addonId which addon owns it`,` info.online transport health`,` sm.dump(deviceId) full debug dump (binding + state + info)`];case`provider`:return[...t,`Pre-bound variables:`,` devices Devices belonging to this provider (raw IDevice[])`,` getIntegration() Integration metadata`,``,`For typed device access use the SystemMirror:`,` await getSystemMirror()`,` sm.getDevicesByAddon('this-addon-id')`];case`addon`:return[...t,`Pre-bound variables:`,` manifest { name, version, ... }`,` declaration addon declaration`,` source addon source location`,``,`Examples:`,` manifest.name`,` manifest.version`]}}function Tn({scope:e,greeting:t,className:n}){let r=X(),[i,a]=K(()=>{let n=[];return t&&n.push({id:Q(),kind:`info`,text:t}),n.push({id:Q(),kind:`info`,text:`scope: ${xn(e)} — type help or context for available commands`}),n}),[o,s]=K(``),[c,l]=K([]),[u,d]=K(-1),f=B(null),p=B(null);J(()=>{let e=p.current;e&&(e.scrollTop=e.scrollHeight)},[i]);let m=Je(()=>{f.current?.focus()},[]),h=Xe({mutationFn:t=>r.trpcClient.repl.execute.mutate({code:t,scope:e}),onSuccess:e=>{let t=e??{},n=typeof t.output==`string`?t.output:e==null?`undefined`:typeof e==`string`?e:JSON.stringify(e,null,2),r=t.type===`error`;a(e=>[...e,{id:Q(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);a(e=>[...e,{id:Q(),kind:`error`,text:t}])}});function g(t){let n=t.trim();if(n){if(n===`clear`){a([{id:Q(),kind:`info`,text:`scope: ${xn(e)}`}]),s(``);return}if(n===`help`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...Sn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`context`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...wn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`examples`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...Cn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}l(e=>[...e,n]),d(-1),a(e=>[...e,{id:Q(),kind:`input`,text:`> ${n}`}]),s(``),h.mutate(n)}}function _(t){if(t.key===`Enter`){t.preventDefault(),g(o);return}if(t.key===`ArrowUp`){if(t.preventDefault(),c.length===0)return;let e=u===-1?c.length-1:Math.max(0,u-1);d(e),s(c[e]??``);return}if(t.key===`ArrowDown`){if(t.preventDefault(),u===-1)return;let e=u+1;e>=c.length?(d(-1),s(``)):(d(e),s(c[e]??``));return}t.ctrlKey&&t.key===`l`&&(t.preventDefault(),a([{id:Q(),kind:`info`,text:`scope: ${xn(e)}`}]))}let v={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return H(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${n??``}`,onClick:m,children:[H(`div`,{ref:p,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[i.map(e=>q(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${v[e.kind]}`,children:e.text},e.id)),h.isPending&&q(`span`,{className:`text-zinc-500 animate-pulse`,children:`…thinking`})]}),H(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[q(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),q(`input`,{ref:f,value:o,onChange:e=>s(e.target.value),onKeyDown:_,disabled:h.isPending,placeholder:`device.state.battery.value`,autoFocus:!0,className:`flex-1 bg-transparent text-zinc-100 placeholder:text-zinc-600 focus:outline-none caret-emerald-400 disabled:opacity-50`,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`})]})]})}function En({deviceId:e,intercomAvailable:t=!1}){let n=X(),r=typeof window<`u`?window.location.origin:``,i=Number.isFinite(e),a=vn(i?e:null),{streams:o,pipelineMetrics:s,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h}=R(n.trpcClient,i?e:null),g=T(n.trpcClient,i?e:null),_=yn(i&&t?e:null),v=_.state===`requesting-mic`||_.state===`starting`||_.state===`connecting`||_.state===`stopping`,y=_.isTalking||v,b=()=>{_.state===`idle`||_.state===`error`?_.start():_.state!==`stopping`&&_.stop()},x=ut(),S=C(),ee=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,w=x.length>0?q(W,{children:x.map(e=>q(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return q(Ge,{serverUrl:r,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h,...S.request?{playbackUrl:S.request.url,playbackAuthToken:ee,...S.request.label?{playbackLabel:S.request.label}:{},onExitPlayback:()=>S.clear()}:{},streams:o,pipelineMetrics:s,phase:a.phase,detections:a,defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:g.src,...g.src?{posterUrl:g.src}:{},snapshotLoading:g.loading,onRefreshSnapshot:g.refresh,intercomAvailable:t,intercomShown:y,onIntercomToggle:b,extraOverlay:w,chromeless:!0,className:`h-full`})}function Dn({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full`,children:q(he,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function On({deviceId:e}){if(!Number.isFinite(e))return H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]});let t=[`CamStack REPL — device #${e}`,``,` device.state.battery.value sync state read`,` await device.snapshot.getSnapshot({}) cap action`,``,` type 'examples' for more, 'context' for the full API`].join(`
2
- `);return q(Tn,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function kn({deviceId:e}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:q(Ce,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function An({deviceId:e}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:q(me,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function jn({deviceId:e}){let t=G(),n=Number.isFinite(e),{data:r}=s({deviceId:e},{enabled:n}),i=typeof r?.type==`string`?r.type:`camera`;Yt([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:a,isLoading:o,isError:c,error:l}=Ue({deviceId:e},{enabled:n}),{data:u}=S({deviceType:i},{enabled:!!i}),d=f({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(o)return q(`div`,{className:`p-4`,children:q(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(c)return H(`div`,{className:`p-4 text-xs text-red-400`,children:[`Failed to load bindings: `,l instanceof Error?l.message:String(l)]});let p=new Map,m={};for(let e of u??[])m[e.capName]=e.wrappers;for(let e of a?.entries??[])p.set(e.capName,{...e,wrappers:m[e.capName]??[]});for(let e of u??[])p.has(e.capName)||p.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let h=[...p.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(h.length===0)return H(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[q(mt,{className:`h-8 w-8 opacity-40`}),q(`p`,{className:`text-xs`,children:`No capability providers applicable to this device yet.`}),q(`p`,{className:`text-[10px] opacity-60`,children:`Native providers show up here as soon as the owning addon registers them.`})]});let g=h.filter(e=>e.kind!==`unbound`).length;return H(`div`,{className:`flex flex-col gap-3 p-1`,children:[H(`div`,{className:`text-[11px] text-foreground-subtle`,children:[q(`span`,{className:`font-medium text-foreground`,children:g}),` of `,h.length,` capabilit`,h.length===1?`y`:`ies`,` bound — rows marked `,q(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),q(Oe,{columns:[{key:`capability`,header:`Capability`,render:e=>q(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>q(Mn,{kind:e.kind})},{key:`provider`,header:`Active Provider`,render:e=>q(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||q(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:`Node`,render:e=>e.providerNodeId?q(Nn,{nodeId:e.providerNodeId}):q(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:`Native`,render:e=>q(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||q(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:`Wrapper`,render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return q(Pn,{wrappers:t.wrappers,activeWrapperId:n,disabled:d.isPending,onPick:r=>{let i=n===r;d.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}],rows:h,rowKey:e=>e.capName,minWidthPx:720})]})}function Mn({kind:e}){return e===`native`?H(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-success/30 text-success bg-success/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[q(Dt,{className:`h-3 w-3`}),`native`]}):e===`wrapped`?H(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-primary/30 text-primary bg-primary/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[q(yt,{className:`h-3 w-3`}),`wrapped`]}):e===`linked`?H(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-warning/30 text-warning bg-warning/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[q(nn,{className:`h-3 w-3`}),`linked`]}):H(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border text-foreground-subtle/70 px-1.5 py-0.5 text-[10px] font-medium`,children:[q(vt,{className:`h-3 w-3`}),`unbound`]})}function Nn({nodeId:e}){return q(`span`,{className:`inline-flex items-center rounded-md border border-border px-1.5 py-0.5 font-mono text-[10px] ${e===`hub`?`text-foreground-subtle`:`text-foreground`}`,children:e})}function Pn({wrappers:e,activeWrapperId:t,disabled:n,onPick:r}){return e.length===0?q(`span`,{className:`text-[10px] opacity-40`,children:`none available`}):q(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let i=e===t;return H(`button`,{disabled:n,onClick:()=>r(e),title:i?`Click to deactivate (revert to native)`:`Activate wrapper ${e}`,className:`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 font-mono text-[10px] transition-colors disabled:opacity-50 ${i?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[q(i?Ft:ht,{className:`h-3 w-3`}),e]},e)})})}function Fn({deviceId:e,activeSubTab:t,onSubTabChange:n}){return q(`div`,{className:`flex flex-col gap-3`,children:q($t,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}V();var In=new Set([`package-detection`]);function Ln(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 Rn(e){return e?e.modelId!==void 0||e.settings!==void 0:!1}function zn({deviceId:e,refreshToken:t}){let n=G(),r=X().trpcClient,[i,a]=K(null),[o,s]=K(null),[c,l]=K(null),u=je({deviceId:e},{refetchOnMount:`always`}),d=ge({deviceId:e},{refetchOnMount:`always`}),f=We(void 0,{refetchOnMount:`always`});Yt([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let p=A(void 0,{refetchOnMount:`always`}),m=U(()=>{let e=new Set;for(let t of p.data??[])t.isOnline&&e.add(t.id);return e},[p.data]),h=U(()=>(f.data??[]).filter(e=>m.has(e.nodeId)).map(e=>e.nodeId),[f.data,m]),g=h[0]??``,_=z({nodeId:g},{enabled:g!==``,refetchOnMount:`always`}),v=Ye({enabled:h.length>0,queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`],`device-step`,h.join(`,`),t],queryFn:async()=>{let e={};for(let t of h)try{e[t]=(await r.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:t})).devices}catch{e[t]=[]}return e}}),b=()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]})},x=ve({onSuccess:b}),S=y({onSuccess:b}),C=U(()=>_.data?_e(_.data):[],[_.data]),ee=U(()=>{let e=f.data??[],t=m.size===0?[]:e.filter(e=>m.has(e.nodeId)),n=[];for(let e of t){let t=(v.data?.[e.nodeId]??[]).filter(e=>e.enabled&&e.available);if(t.length>=2)for(let r of t)n.push({agentNodeId:e.nodeId,engineLabel:r.format,deviceKey:r.key,deviceLabel:bt(r).label});else n.push({agentNodeId:e.nodeId,engineLabel:t[0]?.format??`(engine unknown)`})}return n},[f.data,v.data,m]),w=(e,t)=>v.data?.[e]?.find(e=>e.key===t)??null,te=e=>{if(e.deviceKey!==void 0)return e.deviceKey;let t=v.data?.[e.agentNodeId]??[],n=t.filter(e=>e.enabled&&e.available);return n.length>=1?n[0].key:t.find(e=>e.available)?.key??t[0]?.key??null},T=(e,t,n)=>d.data?.[e]?.[t]?.[n]??null,ne=e=>{if(In.has(e))return{kind:`zone-driven`};let t=Ln(_.data??null,e)?.enabledByDefault??!0,n=u.data?.stepToggles?.[e];return{kind:`gate`,effectiveOn:n??t,defaultOn:t,explicit:n!==void 0}},E=(e,t)=>{let n=Ln(_.data??null,e),r=t?.format;if(!(!n||r===void 0))return(n.slot===`detector`?t?.defaultModelId:void 0)??fe(n,r)},re=(e,t)=>{let n=ne(e),r=n.kind===`gate`?n.effectiveOn:!1,i=Ln(_.data??null,e),a=te(t),o=a===null?null:w(t.agentNodeId,a),s=o?.format;if(!(i?.models.some(e=>s!==void 0&&!!e.formats[s])??!1))return r?{kind:`skip`}:{kind:`na`};let c=a===null?null:T(t.agentNodeId,a,e),l=o?.steps?.[e];return{kind:`enabled`,modelId:c?.modelId??l?.modelId??E(e,o)??`Auto`,overridden:Rn(c)}},ie=i&&_.data?Ln(_.data,i.addonId):null,D=i?w(i.agentNodeId,i.deviceKey):null,ae=D?.format??`coreml`,oe=i?Rn(T(i.agentNodeId,i.deviceKey,i.addonId)):!1,O=i?E(i.addonId,D):void 0,k=U(()=>{if(!i||!D)return null;let e=D.steps?.[i.addonId];return{enabled:!0,...e?.modelId===void 0?{}:{modelId:e.modelId},settings:e?.settings??{}}},[i,D]),j=()=>{a(null),s(null)},se=(e,t)=>{let n=te(t);n!==null&&(a({addonId:e,agentNodeId:t.agentNodeId,deviceKey:n}),s(T(t.agentNodeId,n,e)))},ce=(t,n)=>{S.mutate({deviceId:e,addonId:t,enabled:n})},M=()=>{i&&x.mutate({deviceId:e,agentNodeId:i.agentNodeId,deviceKey:i.deviceKey,addonId:i.addonId,patch:o},{onSuccess:j})},N=()=>{i&&x.mutate({deviceId:e,agentNodeId:i.agentNodeId,deviceKey:i.deviceKey,addonId:i.addonId,patch:null},{onSuccess:j})};if(f.isLoading||g!==``&&_.isLoading)return q(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(ee.length===0)return q(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`No online agents.`});if(!_.data)return q(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let le=i!==null&&ie!==null&&D!==null;return H(`div`,{className:`relative h-full w-full space-y-3`,children:[H(`div`,{className:`rounded-md border border-border bg-muted/20 px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[q(`span`,{className:`font-medium text-foreground`,children:`Gate`}),` (col 1) decides whether this camera runs a step — independent of nodes. Each`,` `,q(`span`,{className:`font-medium text-foreground`,children:`node column`}),` shows the model that node runs; click a cell to pin a per-camera model override for that accelerator. A gated-on step with no model on a device shows a clickable `,q(`span`,{className:`text-amber-500`,children:`⚠ skip`}),` `,`and won't run there.`]}),H(`div`,{className:`rounded-md border border-sky-500/25 bg-sky-500/[0.06] px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[q(`span`,{className:`font-medium text-sky-400`,children:`Placement is dynamic.`}),` When a node has multiple inference accelerators, each session is balanced across them per-session at dispatch time — these device columns show each accelerator's effective model (override ?? device default), not a fixed assignment.`]}),q(`div`,{className:le?`md:pr-[360px]`:``,children:C.length>0?q(Ie,{tree:C,agents:ee,gateFor:ne,getCellState:re,onCellClick:se,selectedCell:i,onSetGate:ce,gateBusy:S.isPending,fallbackNodeId:c,onFallbackNodeChange:l}):q(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),q(P,{open:le,onClose:j,title:ie?.name??``,subtitle:i&&D?`${i.agentNodeId} · ${bt(D).label} · ${D.format}`:``,footer:H(W,{children:[q(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted text-foreground-subtle disabled:opacity-50`,disabled:!oe||x.isPending,onClick:N,children:`Clear override`}),q(`div`,{className:`flex-1`}),q(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:j,children:`Cancel`}),q(`button`,{type:`button`,disabled:!i||!k||x.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:M,children:x.isPending?`Saving…`:`Save`})]}),children:ie&&i&&k?q(Ee,{mode:`device`,addon:ie,agentDefault:k,agentNodeId:i.agentNodeId,currentPatch:o,engineFormat:ae,effectiveModelId:O,onChangePatch:s}):q(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-300`,children:`This accelerator is no longer reported by the node, so there is nothing to provision here.`})})]})}var Bn=[{id:`object-detection`,label:`Object detection`,icon:`scan-search`},{id:`tracking`,label:`Tracking`,icon:`route`},{id:`motion`,label:`Motion`,icon:`activity`},{id:`stationary`,label:`Stationary`,icon:`square-parking`},{id:`zones`,label:`Zones`,icon:`shapes`},{id:`audio`,label:`Audio`,icon:`volume-2`},{id:`cluster`,label:`Cluster`,icon:`server`}],Vn={"pipeline-object-detection":`object-detection`,"detection-sensitivity":`object-detection`,"onboard-object-detection":`object-detection`,tracking:`tracking`,"tracking-core":`tracking`,"motion-tuning":`motion`,"stationary-objects":`stationary`,occupancy:`stationary`,zones:`zones`,"pipeline-audio":`audio`,"cluster-assignment":`cluster`,"orchestrator-live":`cluster`};function Hn(e){return Vn[e]??`object-detection`}V();var Un=`steps`,Wn=`settings`,Gn=new Set([Un,Wn]);function Kn(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}function qn({deviceId:e,activeSubTab:t,onSubTabChange:n}){return H(Se,{value:t&&Gn.has(t)?t:Un,onValueChange:Je(e=>{n?.(e)},[n]),className:`flex flex-col`,children:[H(F,{className:`flex-shrink-0`,children:[q(I,{value:Un,children:`Steps`}),q(I,{value:Wn,children:`Settings`})]}),q(ze,{value:Un,children:q(zn,{deviceId:e,refreshToken:0})}),q(ze,{value:Wn,children:q($t,{deviceId:e,sectionFilter:Kn,subTabGrouping:{groupOf:e=>Hn(e.id),tabs:Bn}})})]})}function $({label:e,value:t}){return H(`div`,{className:`${lt} flex items-start gap-2 sm:gap-3`,children:[q(`span`,{className:`w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle`,children:e}),q(`div`,{className:`flex-1 min-w-0 text-[11px] text-foreground`,children:t})]})}V();function Jn({deviceId:e,initialName:t}){let n=G(),[r,i]=K(!1),[a,o]=K(t),[s,c]=K(!1),l=B(null);J(()=>{r||o(t)},[t,r]),J(()=>{r&&l.current?.focus()},[r]);let u=h({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),d=async()=>{let n=a.trim();if(n.length===0||n===t){i(!1),o(t);return}c(!0);try{await u.mutateAsync({deviceId:e,name:n}),i(!1)}catch{}finally{c(!1)}},f=()=>{o(t),i(!1)};return r?q($,{label:`Name`,value:H(`div`,{className:`flex items-center gap-1`,children:[q(`input`,{ref:l,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?d():e.key===`Escape`&&f()},disabled:s,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),q(`button`,{type:`button`,onClick:()=>void d(),disabled:s,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:q(Ft,{className:`h-3 w-3`})}),q(`button`,{type:`button`,onClick:f,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:q(Vt,{className:`h-3 w-3`})})]})}):q($,{label:`Name`,value:H(`div`,{className:`flex items-center gap-2 group`,children:[q(`span`,{className:`truncate`,children:t}),q(`button`,{type:`button`,onClick:()=>i(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit name`,children:q(Ct,{className:`h-3.5 w-3.5`})})]})})}V();function Yn({deviceId:e,initialLocation:t}){let n=G(),[r,i]=K(!1),[a,o]=K(t??``),[s,c]=K(!1),l=B(null),{data:u}=te(void 0,{enabled:r}),d=u??[];J(()=>{r||o(t??``)},[t,r]),J(()=>{r&&l.current?.focus()},[r]);let f=oe({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]})}}),p=U(()=>{let e=a.trim().toLowerCase();return e.length===0?d:d.filter(t=>t.toLowerCase()!==e&&t.toLowerCase().includes(e))},[d,a]),m=a.trim().length>0&&!d.some(e=>e.toLowerCase()===a.trim().toLowerCase()),h=async n=>{let r=(n??a).trim(),o=r.length===0?null:r;if(o===(t??null)){i(!1);return}c(!0);try{await f.mutateAsync({deviceId:e,location:o}),i(!1)}catch{}finally{c(!1)}},g=()=>{o(t??``),i(!1)};return r?q($,{label:`Location`,value:H(`div`,{className:`relative`,children:[H(`div`,{className:`flex items-center gap-1`,children:[q(`input`,{ref:l,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?h():e.key===`Escape`&&g()},disabled:s,placeholder:`Room / area (or leave empty to clear)`,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),q(`button`,{type:`button`,onClick:()=>void h(),disabled:s,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:q(Ft,{className:`h-3 w-3`})}),q(`button`,{type:`button`,onClick:g,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:q(Vt,{className:`h-3 w-3`})})]}),(p.length>0||m)&&H(`div`,{className:`absolute z-10 left-0 right-0 mt-0.5 max-h-40 overflow-y-auto rounded-md border border-border bg-surface shadow-md`,children:[p.map(e=>H(`button`,{type:`button`,onClick:()=>{o(e),h(e)},className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[q(St,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),q(`span`,{className:`truncate`,children:e})]},e)),m&&H(`button`,{type:`button`,onClick:()=>void h(),className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover border-t border-border`,children:[q(`span`,{className:`text-foreground-subtle`,children:`Create`}),H(`span`,{className:`font-medium truncate`,children:[`"`,a.trim(),`"`]})]})]})]})}):q($,{label:`Location`,value:H(`div`,{className:`flex items-center gap-2 group`,children:[t?q(`span`,{className:`truncate`,children:t}):q(`span`,{className:`italic text-foreground-subtle`,children:`unset`}),q(`button`,{type:`button`,onClick:()=>i(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit location`,children:q(Ct,{className:`h-3.5 w-3.5`})})]})})}V();function Xn({deviceId:e}){let t=G(),{data:n}=_t(e),{data:r}=xt(e),[i,a]=K(null),o=ae({onSuccess:()=>{a(null),t.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>{a(`Could not change primary child: ${e.message}`)}});if(n==null||String(n.type??``)!==Y.Container)return null;let s=(r??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}}));if(s.length<=1)return null;let c=le(s,typeof n.linkDeviceId==`number`?n.linkDeviceId:null,typeof n.primaryChildEntityId==`string`?n.primaryChildEntityId:null);return H(W,{children:[q($,{label:`Primary child`,value:q(p,{childrenList:s,selectedId:c===null?s[0].id:c.id,onSetPrimary:t=>o.mutate({deviceId:e,primaryChildEntityId:t}),disabled:o.isPending})}),i!==null&&q(`p`,{role:`alert`,className:`px-3 sm:px-4 py-1.5 text-[11px] text-danger`,children:i})]})}V();var Zn=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function Qn(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function $n(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function er(){let e=w(),t=l(),{data:n}=s({deviceId:e??0},{enabled:e!==null}),{data:r}=Ue({deviceId:e??0},{enabled:e!==null}),i=n??t??null,[a,o]=K(`identity`);if(e===null||!i)return null;let c=String(i.stableId??``),u=String(i.name??``),d=String(i.type??``),f=String(i.addonId??``),p=i.features??[],m=new Set([`device-status`,`feature-probe`,`device-ops`]),h=(r?.entries??[]).filter(e=>e.kind===`native`&&!m.has(e.capName)).map(e=>e.capName),g=p.length>0?p:h,_=i.location??null,v=i.metadata??null,y=v!==null&&Object.keys(v).length>0;return H(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[H(`div`,{className:`border-b border-border px-3 sm:px-4 py-2 flex items-center justify-between gap-3`,children:[q(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Device Info`}),y&&H(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[q(tr,{active:a===`identity`,onClick:()=>o(`identity`),label:`Identity`}),q(tr,{active:a===`hardware`,onClick:()=>o(`hardware`),label:`Hardware`})]})]}),(!y||a===`identity`)&&H(`div`,{className:`divide-y divide-border`,children:[q($,{label:`ID`,value:H(`span`,{className:`font-mono text-[11px] text-foreground`,children:[`#${e}`,H(`span`,{className:`ml-1.5 text-foreground-subtle`,children:[`(`,c,`)`]})]})}),q(Jn,{deviceId:e,initialName:u}),q(Yn,{deviceId:e,initialLocation:_}),q(Xn,{deviceId:e}),q($,{label:`Type`,value:d}),q($,{label:`Provider`,value:q(gt,{type:f,size:`sm`,showLabel:!0})}),q($,{label:`Capabilities`,value:g.length>0?q(pt,{capabilities:g,showLabels:!0}):q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),y&&a===`hardware`&&q(nr,{metadata:v})]})}function tr({active:e,onClick:t,label:n}){return q(`button`,{type:`button`,onClick:t,className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${e?`bg-surface text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`}`,children:n})}function nr({metadata:e}){let t=Zn.filter(t=>t in e),n=Object.keys(e).filter(e=>!Zn.includes(e)).toSorted(),r=[...t,...n];return H(`div`,{children:[q(`div`,{className:`px-3 sm:px-4 py-1.5 text-[10px] text-foreground-subtle border-b border-border bg-surface-subtle/40`,children:`Auto-populated by the driver on every connect. Read-only.`}),q(`div`,{className:`divide-y divide-border`,children:r.map(t=>q($,{label:Qn(t),value:q(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:$n(e[t])})},t))})]})}V();function rr({deviceId:e}){let[t,n]=K(null),r=L({onSuccess:e=>{n(e.changed?`Re-aligned with source — ${e.rebuiltChildren} child${e.rebuiltChildren===1?``:`ren`} rebuilt.`:`Already up to date.`)},onError:e=>n(`Re-sync failed: ${e.message}`)});return H(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[H(`div`,{className:`flex items-center justify-between gap-3`,children:[H(`div`,{children:[q(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:`Re-sync`}),q(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:`Re-align this device's type, role, capabilities and units with its source.`})]}),H(`button`,{type:`button`,disabled:r.isPending,onClick:()=>{n(null),r.mutate({camDeviceId:e})},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[q(Tt,{className:`h-3 w-3 ${r.isPending?`animate-spin`:``}`}),r.isPending?`Re-syncing…`:`Re-sync`]})]}),t!==null&&q(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:t})]})}V();var ir={icon:``,label:``,unit:``,precision:``,hidden:!1};function ar(e){return{icon:e?.icon??``,label:e?.label??``,unit:e?.unit??``,precision:e?.precision===void 0?``:String(e.precision),hidden:e?.hidden===!0}}function or(e){if(typeof e!=`object`||!e)return;let t=e.unit;return typeof t==`string`?t:void 0}function sr(e){let t=e.precision.trim()===``?void 0:Number.parseInt(e.precision,10),n={...e.icon===``?{}:{icon:e.icon},...e.label.trim()===``?{}:{label:e.label.trim()},...e.unit===``?{}:{unit:e.unit},...t!==void 0&&Number.isFinite(t)?{precision:t}:{},...e.hidden?{hidden:!0}:{}};return Object.keys(n).length===0?null:n}function cr({deviceId:e}){let t=X(),i=G(),{data:a}=s({deviceId:e},{enabled:e>0}),o=typeof a?.role==`string`?a.role:null,c=o===null?void 0:Fe[o],l=c?.kind===`numeric`,u=Te(t.trpcClient,e,o??``),d=c?.kind===`numeric`?c.canonicalUnit:void 0,f=or(u)??d,p=f===void 0?void 0:st(f),m=U(()=>p===void 0?[]:it(p),[p]),[h,g]=K(null),_=h??ar(a?.display),v=r({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),{data:y}=n({},{staleTime:6e4}),b=k({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}});if(a===void 0||o===null)return null;let x=e=>{g({..._,...e})},S=()=>{v.mutate({deviceId:e,display:sr(_)})},C=()=>{g(ir),v.mutate({deviceId:e,display:null})},ee=()=>{let e={..._.icon===``?{}:{icon:_.icon},..._.unit===``?{}:{unit:_.unit},..._.precision.trim()!==``&&Number.isFinite(Number.parseInt(_.precision,10))?{precision:Number.parseInt(_.precision,10)}:{}},t={...y?.defaults??{},[o]:e};b.mutate({defaults:t})},w=Ne(o).label,te=Object.keys(Le);return H(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[q(`div`,{className:`border-b border-border px-4 py-2`,children:q(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Display`})}),H(`div`,{className:`p-4 space-y-3`,children:[H(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Icon`}),H(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,value:_.icon,onChange:e=>x({icon:e.target.value}),children:[H(`option`,{value:``,children:[`Default (`,w,`)`]}),te.map(e=>q(`option`,{value:e,children:e},e))]})]}),H(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Label`}),q(`input`,{type:`text`,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,placeholder:w,value:_.label,onChange:e=>x({label:e.target.value})})]}),l&&H(`div`,{className:`grid grid-cols-2 gap-3`,children:[H(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Unit`}),H(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,value:_.unit,onChange:e=>x({unit:e.target.value}),disabled:m.length===0,children:[H(`option`,{value:``,children:[`Source`,f?` (${f})`:``]}),m.map(e=>q(`option`,{value:e,children:e},e))]})]}),H(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Precision`}),q(`input`,{type:`number`,min:0,max:10,step:1,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,placeholder:`inherit`,value:_.precision,onChange:e=>x({precision:e.target.value})})]})]}),H(`label`,{className:`flex items-center gap-2`,children:[q(`input`,{type:`checkbox`,checked:_.hidden,onChange:e=>x({hidden:e.target.checked})}),q(`span`,{className:`text-sm text-foreground`,children:`Hide from device lists`})]}),H(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[q(`button`,{type:`button`,className:`rounded bg-primary px-3 py-1 text-sm font-medium text-primary-foreground disabled:opacity-50`,onClick:S,disabled:v.isPending,children:`Save`}),q(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:C,disabled:v.isPending,children:`Reset`}),H(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:ee,disabled:b.isPending,title:`Apply this unit / precision / icon as the default for every ${w} sensor`,children:[`Set as default for all `,w,` sensors`]})]})]})]})}function lr(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function ur({device:e}){let t=Gt(),n=typeof e.id==`number`?e.id:null,r=String(e.type??``),i=r===Y.Camera,a=r===Y.Hub,o=typeof e.role==`string`&&e.role.length>0,s=e.features??[],c=s.includes(nt.Resyncable),{data:l}=v({deviceId:n??0},{enabled:n!==null&&i,refetchInterval:5e3}),u=l?.streams??{},d=Object.entries(u),f=s.includes(nt.DoorbellButton),p=Me(f?{deviceId:n??void 0,historyLimit:10}:void 0),m=p.latest?Date.now()-p.latest.timestamp<3e4:!1;return H(`div`,{className:`space-y-5`,children:[a&&n!==null&&q(Ae,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),c&&n!==null&&q(rr,{deviceId:n}),i&&n!==null&&q(E,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),f&&q(Re,{history:p.history,latestIsFresh:m}),i&&n!==null&&q(E,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),i&&d.length>0&&H(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[q(`div`,{className:`border-b border-border px-4 py-2`,children:q(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Stream Network`})}),q(`div`,{className:`divide-y divide-border`,children:d.map(([e,t])=>H(`div`,{className:`px-4 py-2.5`,children:[H(`div`,{className:`flex items-center gap-2 mb-2`,children:[q(Ot,{className:`h-3 w-3 text-foreground-subtle`}),q(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),H(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[q(dr,{label:`Nominal`,value:lr(t.nominalBitrateKbps??0)}),q(dr,{label:`Observed`,value:lr(t.observedBitrateKbps??0)}),q(dr,{label:`Peak`,value:lr(t.peakBitrateKbps??0)}),q(dr,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),q(er,{}),o&&n!==null&&q(cr,{deviceId:n})]})}function dr({label:e,value:t,warning:n}){return H(`div`,{children:[q(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),q(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}V();function fr(e,t){if(t===`number`){let t=Number(e);return Number.isNaN(t)?e:t}return t===`boolean`?e===`true`:e}function pr(e,t){let n={};for(let r of e)r.key!==``&&r.value!==``&&(n[r.key]=fr(r.value,t));return n}function mr(e,t){return e?.kind===`enum-map`?Object.entries(e.mapping).map(([e,t])=>({key:e,value:String(t)})):t?.kind===`enum`&&t.enumValues?t.enumValues.map(e=>({key:e,value:``})):[{key:``,value:``}]}function hr(e){return e?.kind===`linear`?{scale:String(e.scale),offset:String(e.offset),clampMin:e.clamp?String(e.clamp[0]):``,clampMax:e.clamp?String(e.clamp[1]):``,useClamp:e.clamp!=null}:{scale:`1`,offset:`0`,clampMin:``,clampMax:``,useClamp:!1}}function gr(e){return e==null?`identity`:e.kind}function _r({value:e,onChange:t,sourceField:n,targetKind:r}){let[i,a]=K(()=>gr(e)),[o,s]=K(()=>mr(e,n)),[c,l]=K(()=>e?.kind===`enum-map`&&e.fallback!=null?String(e.fallback):``),[u,d]=K(()=>hr(e));J(()=>{if(i===`enum-map`&&n?.kind===`enum`&&n.enumValues){let e=n.enumValues;s(t=>e.map(e=>({key:e,value:t.find(t=>t.key===e)?.value??``})))}},[n,i]),J(()=>{if(i===`identity`){t(void 0);return}if(i===`enum-map`){let e=pr(o,r),n=c===``?void 0:fr(c,r);t({kind:`enum-map`,mapping:e,...n===void 0?{}:{fallback:n}});return}if(i===`linear`){let e=Number(u.scale),n=Number(u.offset);if(Number.isNaN(e)||Number.isNaN(n))return;let r=Number(u.clampMin),i=Number(u.clampMax),a=u.useClamp&&!Number.isNaN(r)&&!Number.isNaN(i)?[r,i]:void 0;t({kind:`linear`,scale:e,offset:n,...a?{clamp:a}:{}})}},[i,o,c,u,r,t]);let f=e=>{a(e),e===`enum-map`&&s(mr(void 0,n)),e===`linear`&&d(hr(void 0))},p=(e,t,n)=>{s(r=>r.map((r,i)=>i===e?{...r,[t]:n}:r))},m=()=>s(e=>[...e,{key:``,value:``}]),h=e=>s(t=>t.filter((t,n)=>n!==e));return H(`div`,{className:`flex flex-col gap-3`,children:[H(`div`,{children:[q(`p`,{className:`text-[11px] font-medium text-foreground-subtle mb-1.5`,children:`Transform`}),q(`div`,{className:`flex items-center gap-4`,children:[`identity`,`enum-map`,`linear`].map(e=>H(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[q(`input`,{type:`radio`,name:`transform-kind`,value:e,checked:i===e,onChange:()=>f(e),className:`accent-primary`}),e===`identity`?`None`:e]},e))})]}),i===`enum-map`&&H(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[q(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Key → Value mapping`}),o.map((e,t)=>H(`div`,{className:`flex items-center gap-1.5`,children:[q(`input`,{"aria-label":`enum key ${t}`,type:`text`,value:e.key,readOnly:n?.kind===`enum`,onChange:e=>p(t,`key`,e.target.value),placeholder:`source value`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs font-mono text-foreground focus:border-primary outline-none read-only:opacity-70`}),q(`span`,{className:`text-foreground-subtle/50 text-xs`,children:`→`}),r===`boolean`?H(`select`,{"aria-label":`enum value ${t}`,value:e.value,onChange:e=>p(t,`value`,e.target.value),className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`,children:[q(`option`,{value:``,children:`—`}),q(`option`,{value:`true`,children:`true`}),q(`option`,{value:`false`,children:`false`})]}):q(`input`,{"aria-label":`enum value ${t}`,type:r===`number`?`number`:`text`,value:e.value,onChange:e=>p(t,`value`,e.target.value),placeholder:`target value`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs font-mono text-foreground focus:border-primary outline-none`}),n?.kind!==`enum`&&q(`button`,{type:`button`,onClick:()=>h(t),className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] border border-border/80 text-foreground-subtle hover:text-danger hover:border-danger/50 transition-colors`,children:`✕`})]},t)),n?.kind!==`enum`&&q(`button`,{type:`button`,onClick:m,className:`self-start text-[10px] text-primary/70 hover:text-primary transition-colors`,children:`+ Add row`}),H(`div`,{className:`flex items-center gap-2 pt-1 border-t border-border/50`,children:[q(`label`,{className:`text-[10px] text-foreground-subtle/70 whitespace-nowrap`,children:`Fallback:`}),q(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`(leave empty for none)`,className:`flex-1 rounded border border-border bg-background px-2 py-0.5 text-xs font-mono text-foreground focus:border-primary outline-none`})]})]}),i===`linear`&&H(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[q(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Linear: value × scale + offset`}),H(`div`,{className:`grid grid-cols-2 gap-2`,children:[H(`label`,{className:`flex flex-col gap-0.5`,children:[q(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Scale`}),q(`input`,{type:`number`,value:u.scale,onChange:e=>d(t=>({...t,scale:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),H(`label`,{className:`flex flex-col gap-0.5`,children:[q(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Offset`}),q(`input`,{type:`number`,value:u.offset,onChange:e=>d(t=>({...t,offset:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]})]}),H(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[q(`input`,{type:`checkbox`,checked:u.useClamp,onChange:e=>d(t=>({...t,useClamp:e.target.checked})),className:`accent-primary`}),q(`span`,{className:`text-foreground-subtle`,children:`Clamp output`})]}),u.useClamp&&H(`div`,{className:`grid grid-cols-2 gap-2`,children:[H(`label`,{className:`flex flex-col gap-0.5`,children:[q(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Min`}),q(`input`,{type:`number`,value:u.clampMin,onChange:e=>d(t=>({...t,clampMin:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),H(`label`,{className:`flex flex-col gap-0.5`,children:[q(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Max`}),q(`input`,{type:`number`,value:u.clampMax,onChange:e=>d(t=>({...t,clampMax:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]})]})]})]})}var vr=`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none disabled:opacity-50`;function yr({mode:e,idPrefix:t,labelPrefix:n,pickerDevices:r,value:i,onChange:a,search:o,onSearchChange:s}){let{data:c}=ye({deviceId:i.sourceId??0},{enabled:i.sourceId!=null}),l=c?.caps??[],u=l.find(e=>e.cap===i.cap)?.fields??[],d=e=>{a(e,(l.find(t=>t.cap===e.cap)?.fields??[]).find(t=>t.path===e.fieldPath))},f=e=>{d({sourceId:e===``?null:Number(e),cap:``,fieldPath:``})},p=e=>{d({sourceId:i.sourceId,cap:e,fieldPath:``})},m=e=>{d({sourceId:i.sourceId,cap:i.cap,fieldPath:e})};return H(W,{children:[e===`global`&&s&&H(`div`,{children:[q(`label`,{htmlFor:`${t}-search`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Search devices`}),q(`input`,{id:`${t}-search`,type:`text`,value:o??``,placeholder:`Filter by name, stable id or #id`,onChange:e=>s(e.target.value),className:vr})]}),H(`div`,{children:[H(`label`,{htmlFor:`${t}-device`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:[n,` device`]}),H(`select`,{id:`${t}-device`,value:i.sourceId??``,onChange:e=>f(e.target.value),className:vr,children:[q(`option`,{value:``,children:`— select a device —`}),r.map(e=>H(`option`,{value:e.id,children:[e.name??e.stableId,` (#`,e.id,`)`]},e.id))]})]}),H(`div`,{children:[H(`label`,{htmlFor:`${t}-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:[n,` cap`]}),H(`select`,{id:`${t}-cap`,value:i.cap,disabled:i.sourceId==null,onChange:e=>p(e.target.value),className:vr,children:[q(`option`,{value:``,children:`— select a cap —`}),l.map(e=>q(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),H(`div`,{children:[H(`label`,{htmlFor:`${t}-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:[n,` field`]}),H(`select`,{id:`${t}-field`,value:i.fieldPath,disabled:i.cap===``,onChange:e=>m(e.target.value),className:vr,children:[q(`option`,{value:``,children:`— select a field —`}),u.map(e=>H(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]})}function br(e,t){switch(e){case`null`:return{value:null};case`string`:return t===``?null:{value:t};case`number`:{if(t.trim()===``)return null;let e=Number(t);return Number.isFinite(e)?{value:e}:null}case`boolean`:return t===`true`?{value:!0}:t===`false`?{value:!1}:null}}function xr(e){return e===null?`null`:typeof e==`number`?`number`:typeof e==`boolean`?`boolean`:`string`}function Sr(e){return e===null?``:String(e)}V();var Cr=`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none disabled:opacity-50`,wr=`min, max, abs, round, floor, ceil, sqrt, pow, clamp, avg, sum, coalesce, age, convert`,Tr=0;function Er(){return Tr+=1,`b${Tr}`}function Dr(e){return{key:Er(),name:e,mode:`sibling`,sourceId:null,cap:``,fieldPath:``,search:``,literalType:`number`,literalText:``,sampleText:``}}function Or(e,t,n){if(e===null)return[Dr(`a`)];let r=[];for(let[i,a]of Object.entries(e.bindings)){if(a.kind===`literal`){r.push({...Dr(i),mode:`literal`,literalType:xr(a.value),literalText:Sr(a.value)});continue}if(a.kind===`global`){r.push({...Dr(i),mode:`global`,sourceId:t.find(e=>e.stableId===a.sourceStableId)?.id??null,cap:a.cap,fieldPath:a.fieldPath});continue}r.push({...Dr(i),mode:`sibling`,sourceId:t.find(e=>e.stableId===`${n}-${a.sourceKey}`)?.id??null,cap:a.cap,fieldPath:a.fieldPath})}return r.length>0?r:[Dr(`a`)]}function kr(e,t,n){if(e.mode===`literal`){let t=br(e.literalType,e.literalText);return t===null?null:{kind:`literal`,value:t.value}}let r=t.find(t=>t.id===e.sourceId);if(!r||e.cap===``||e.fieldPath===``)return null;if(e.mode===`global`)return{kind:`global`,sourceStableId:r.stableId,cap:e.cap,fieldPath:e.fieldPath};let i=`${n}-`,a=r.stableId.startsWith(i)?r.stableId.slice(i.length):``;return a===``?null:{kind:`field`,sourceKey:a,cap:e.cap,fieldPath:e.fieldPath}}function Ar(e){if(e.mode===`literal`)return br(e.literalType,e.literalText)?.value??null;let t=e.sampleText.trim();if(t===``)return null;let n=Number(t);return Number.isFinite(n)?n:e.sampleText}function jr({devices:e,siblings:t,targetDeviceId:n,containerStableId:r,initial:i,onChange:a}){let[o,s]=K(i?.expr??``),[c,l]=K(()=>Or(i,e,r)),u=U(()=>{let t={},n=c.length>0,i=new Set;for(let a of c){let o=a.name.trim();if(o===``||i.has(o)){n=!1;continue}i.add(o);let s=kr(a,e,r);if(s===null){n=!1;continue}t[o]=s}return{source:{kind:`expression`,expr:o,bindings:t},complete:n}},[c,o,e,r]),d=U(()=>et({expr:u.source.expr,bindings:u.source.bindings}),[u.source]),f=U(()=>{if(o.trim()===``)return null;let e=tt(o);return e.ok?null:e.error},[o]),p=U(()=>{if(u.source.expr.trim()===``)return null;let e={};for(let t of c){let n=t.name.trim();n!==``&&(e[n]=Ar(t))}return at(u.source.expr,e,Date.now())},[u.source.expr,c]),m=u.complete&&d===null&&o.trim()!==``;J(()=>{a(m?u.source:null)},[m?JSON.stringify(u.source):`null`]);let h=e=>{let t=e.name.trim();return t===``?`required`:Ze.test(t)?Qe.has(t)?`reserved`:rt.has(t)?`shadows builtin`:c.filter(e=>e.name.trim()===t).length>1?`duplicate`:null:`invalid name`},g=(e,t)=>{l(n=>n.map(n=>n.key===e?{...n,...t}:n))},_=()=>{c.length>=32||l(e=>[...e,Dr(Mr(e))])},v=e=>{l(t=>t.length<=1?t:t.filter(t=>t.key!==e))};return H(`div`,{className:`flex flex-col gap-3`,children:[H(`div`,{className:`flex flex-col gap-2`,children:[q(`span`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Bindings`}),c.map((r,i)=>q(Nr,{row:r,ordinal:i+1,devices:e,siblings:t,targetDeviceId:n,nameError:h(r),onPatch:e=>g(r.key,e),onRemove:()=>v(r.key),canRemove:c.length>1},r.key)),q(`button`,{type:`button`,onClick:_,disabled:c.length>=32,className:`self-start px-2 py-1 rounded-md text-[11px] font-medium border border-border text-foreground-subtle hover:bg-surface-hover disabled:opacity-50`,children:`+ Add binding`})]}),H(`div`,{children:[q(`label`,{htmlFor:`link-expr-input`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Expression`}),q(`textarea`,{id:`link-expr-input`,value:o,rows:2,spellCheck:!1,placeholder:`e.g. clamp(avg(a, b) + 5, 0, 100)`,onChange:e=>s(e.target.value),className:`${Cr} font-mono resize-y`}),H(`p`,{className:`mt-1 text-[10px] text-foreground-subtle/60`,children:[`Functions: `,wr]}),f&&q(`p`,{className:`mt-1 text-[10px] text-danger`,children:f}),f===null&&d&&q(`p`,{className:`mt-1 text-[10px] text-danger`,children:d})]}),H(`div`,{className:`rounded-md border border-border bg-surface/50 px-2 py-1.5`,children:[q(`span`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle/60`,children:`Preview`}),` `,p===null?q(`span`,{className:`text-[11px] text-foreground-subtle/60`,children:`enter an expression`}):p.ok?q(`span`,{className:`font-mono text-[11px] text-foreground`,children:JSON.stringify(p.value)}):q(`span`,{className:`font-mono text-[11px] text-danger`,children:p.error})]})]})}function Mr(e){let t=new Set(e.map(e=>e.name.trim()));for(let e=0;e<26;e++){let n=String.fromCharCode(97+e);if(!t.has(n))return n}return`b${e.length+1}`}function Nr({row:e,ordinal:t,devices:n,siblings:r,targetDeviceId:i,nameError:a,onPatch:o,onRemove:s,canRemove:c}){let l=e.search.trim().toLowerCase(),u=n.filter(e=>e.id===i?!1:l===``?!0:e.name.toLowerCase().includes(l)||e.stableId.toLowerCase().includes(l)||String(e.id).includes(l)),d=e.mode===`global`?u:r;return H(`div`,{className:`flex flex-col gap-2 rounded-md border border-border/60 p-2`,children:[H(`div`,{className:`flex items-center gap-2`,children:[q(`input`,{type:`text`,"aria-label":`binding ${t} name`,value:e.name,placeholder:`name`,onChange:e=>o({name:e.target.value}),className:`${Cr} max-w-[8rem] font-mono`}),H(`select`,{"aria-label":`binding ${t} mode`,value:e.mode,onChange:e=>{let t=e.target.value;(t===`sibling`||t===`global`||t===`literal`)&&o({mode:t,sourceId:null,cap:``,fieldPath:``,search:``})},className:`${Cr} max-w-[9rem]`,children:[q(`option`,{value:`sibling`,children:`Sibling`}),q(`option`,{value:`global`,children:`Any device`}),q(`option`,{value:`literal`,children:`Literal`})]}),c&&q(`button`,{type:`button`,"aria-label":`remove binding ${t}`,onClick:s,className:`px-2 py-1 rounded-md text-[11px] text-danger hover:bg-surface-hover`,children:`✕`})]}),a&&H(`span`,{className:`text-[10px] text-danger`,children:[`name: `,a]}),e.mode===`literal`?H(`div`,{className:`flex items-center gap-2`,children:[H(`select`,{"aria-label":`binding ${t} literal type`,value:e.literalType,onChange:e=>{let t=e.target.value;(t===`string`||t===`number`||t===`boolean`||t===`null`)&&o({literalType:t,literalText:t===`boolean`?`true`:``})},className:`${Cr} max-w-[7rem]`,children:[q(`option`,{value:`string`,children:`string`}),q(`option`,{value:`number`,children:`number`}),q(`option`,{value:`boolean`,children:`boolean`}),q(`option`,{value:`null`,children:`null`})]}),e.literalType!==`null`&&q(`input`,{type:`text`,"aria-label":`binding ${t} literal value`,value:e.literalText,placeholder:e.literalType===`number`?`e.g. 42`:`value`,onChange:e=>o({literalText:e.target.value}),className:Cr})]}):H(W,{children:[q(yr,{mode:e.mode,idPrefix:`binding-${t}`,labelPrefix:`Binding`,pickerDevices:d,value:{sourceId:e.sourceId,cap:e.cap,fieldPath:e.fieldPath},onChange:e=>o({sourceId:e.sourceId,cap:e.cap,fieldPath:e.fieldPath}),search:e.search,onSearchChange:e=>o({search:e})}),q(`input`,{type:`text`,"aria-label":`binding ${t} sample`,value:e.sampleText,placeholder:`sample value (preview only)`,onChange:e=>o({sampleText:e.target.value}),className:`${Cr} text-[10px]`})]})]})}V();function Pr(e,t,n){return(n===void 0?[e,t]:[e,n,t]).map(e=>e.replace(/[^a-z0-9]/gi,`-`)).join(`-`)}function Fr(e,t,n){let r=`${t}-${e}`;return n.find(e=>e.stableId===r)?.id??null}function Ir(e,t){return t.find(t=>t.stableId===e)?.id??null}function Lr(e){return e==null?`sibling`:e.source.kind===`literal`?`literal`:e.source.kind===`global`?`global`:e.source.kind===`expression`?`expression`:`sibling`}function Rr(e){return e==null||e.source.kind!==`literal`?`string`:xr(e.source.value)}function zr(e){return e==null||e.source.kind!==`literal`?``:Sr(e.source.value)}function Br({deviceId:e,parentDeviceId:t,deviceStableId:n,initial:r,onSave:i,onCancel:a}){let{data:o}=b({}),s=o??[],c=t==null?n:s.find(e=>e.id===t)?.stableId??n,l=s.filter(n=>n.parentDeviceId===t&&n.id!==e),{data:u}=ye({deviceId:e,includeSynthesizable:!0}),d=u?.caps??[],f=r!=null&&(r.source.kind===void 0||r.source.kind===`field`)?r.source:null,p=r!=null&&r.source.kind===`global`?r.source:null,m=r!=null&&r.source.kind===`expression`?r.source:null,h=f==null?p==null?null:Ir(p.sourceStableId,s):Fr(f.sourceKey,c,s),[g,_]=K(Lr(r)),[v,y]=K(r?.target.cap??``),[x,S]=K(r?.target.fieldPath??``),[C,ee]=K(r?.target.itemKey??``),[w,te]=K(h),[T,ne]=K((f??p)?.cap??``),[E,re]=K((f??p)?.fieldPath??``),[ie,D]=K(void 0),[ae,oe]=K(``),[O,k]=K(Rr(r)),[A,j]=K(zr(r)),[se,ce]=K(m),[M,N]=K(r?.transform);J(()=>{if((f??p)==null||w!==null||s.length===0)return;let e=f==null?p==null?null:Ir(p.sourceStableId,s):Fr(f.sourceKey,c,s);e!==null&&te(e)},[f,p,w,s,c]);let P=d.find(e=>e.cap===v)?.fields??[],le=P.find(e=>e.path===x),ue=le?.item===!0,F=ae.trim().toLowerCase(),de=s.filter(t=>t.id===e?!1:F===``?!0:t.name.toLowerCase().includes(F)||t.stableId.toLowerCase().includes(F)||String(t.id).includes(F)),fe=g===`global`?de:l,pe=e=>{y(e),S(``),ee(``)},me=e=>{e!==`sibling`&&e!==`global`&&e!==`literal`&&e!==`expression`||(_(e),te(null),ne(``),re(``),D(void 0),oe(``))},I=br(O,A),he=g===`literal`?I!==null:g===`expression`?se!==null:w!=null&&T!==``&&E!==``,L=v!==``&&x!==``&&(!ue||C.trim()!==``)&&he,ge=()=>{if(g===`literal`)return I===null?null:{kind:`literal`,value:I.value};if(g===`expression`)return se;let e=s.find(e=>e.id===w);if(!e||T===``||E===``)return null;if(g===`global`)return{kind:`global`,sourceStableId:e.stableId,cap:T,fieldPath:E};let t=`${c}-`;return{sourceKey:e.stableId.startsWith(t)?e.stableId.slice(t.length):``,cap:T,fieldPath:E}},R=()=>{if(!L)return;let e=ge();if(e===null)return;let t=ue?C.trim():void 0;i({id:r?.id??Pr(v,x,t),source:e,target:{cap:v,fieldPath:x,...t===void 0?{}:{itemKey:t}},...M==null?{}:{transform:M}})},z=`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none disabled:opacity-50`;return H(`div`,{className:`flex flex-col gap-4 p-3`,children:[H(`fieldset`,{className:`flex flex-col gap-3`,children:[q(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Target (this device)`}),H(`div`,{children:[q(`label`,{htmlFor:`link-target-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target cap`}),H(`select`,{id:`link-target-cap`,value:v,onChange:e=>pe(e.target.value),className:z,children:[q(`option`,{value:``,children:`— select a cap —`}),d.map(e=>q(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),H(`div`,{children:[q(`label`,{htmlFor:`link-target-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target field`}),H(`select`,{id:`link-target-field`,value:x,disabled:v===``,onChange:e=>S(e.target.value),className:z,children:[q(`option`,{value:``,children:`— select a field —`}),P.map(e=>q(`option`,{value:e.path,children:e.item===!0?`${e.path} (per item, ${e.kind})`:`${e.path} (${e.kind})`},e.path))]})]}),ue&&H(`div`,{children:[q(`label`,{htmlFor:`link-target-item-key`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Item key`}),q(`input`,{id:`link-target-item-key`,type:`text`,value:C,placeholder:`e.g. main-brush`,onChange:e=>ee(e.target.value),className:z}),q(`p`,{className:`mt-1 text-[10px] text-foreground-subtle/60`,children:`Links sharing the same item key build one item (e.g. one consumable).`})]})]}),H(`fieldset`,{className:`flex flex-col gap-3`,children:[q(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Source`}),H(`div`,{children:[q(`label`,{htmlFor:`link-source-mode`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source mode`}),H(`select`,{id:`link-source-mode`,value:g,onChange:e=>me(e.target.value),className:z,children:[q(`option`,{value:`sibling`,children:`Sibling device (same container)`}),q(`option`,{value:`global`,children:`Any device`}),q(`option`,{value:`literal`,children:`Literal constant`}),q(`option`,{value:`expression`,children:`Expression (computed)`})]})]}),g===`literal`&&H(W,{children:[H(`div`,{children:[q(`label`,{htmlFor:`link-literal-type`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Literal type`}),H(`select`,{id:`link-literal-type`,value:O,onChange:e=>{let t=e.target.value;(t===`string`||t===`number`||t===`boolean`||t===`null`)&&(k(t),t===`boolean`&&j(`true`),t===`null`&&j(``))},className:z,children:[q(`option`,{value:`string`,children:`string`}),q(`option`,{value:`number`,children:`number`}),q(`option`,{value:`boolean`,children:`boolean`}),q(`option`,{value:`null`,children:`null`})]})]}),O!==`null`&&(O===`boolean`?H(`div`,{children:[q(`label`,{htmlFor:`link-literal-value`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Literal value`}),H(`select`,{id:`link-literal-value`,value:A,onChange:e=>j(e.target.value),className:z,children:[q(`option`,{value:`true`,children:`true`}),q(`option`,{value:`false`,children:`false`})]})]}):H(`div`,{children:[q(`label`,{htmlFor:`link-literal-value`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Literal value`}),q(`input`,{id:`link-literal-value`,type:`text`,value:A,placeholder:O===`number`?`e.g. 42`:`e.g. main-brush`,onChange:e=>j(e.target.value),className:z})]}))]}),g===`expression`&&q(jr,{devices:s,siblings:l,targetDeviceId:e,containerStableId:c,initial:m,onChange:ce}),(g===`sibling`||g===`global`)&&q(yr,{mode:g,idPrefix:`link-source`,labelPrefix:`Source`,pickerDevices:fe,value:{sourceId:w,cap:T,fieldPath:E},onChange:(e,t)=>{te(e.sourceId),ne(e.cap),re(e.fieldPath),D(t)},search:ae,onSearchChange:oe})]}),q(_r,{value:M,onChange:N,sourceField:g===`literal`||g===`expression`?void 0:ie,targetKind:le?.kind}),H(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-border`,children:[q(`button`,{type:`button`,onClick:a,className:`px-3 py-1.5 rounded-md text-xs font-medium border border-border text-foreground-subtle hover:bg-surface-hover hover:text-foreground transition-colors`,children:`Cancel`}),q(`button`,{type:`button`,disabled:!L,onClick:R,className:`px-3 py-1.5 rounded-md text-xs font-medium bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:`Save`})]})]})}V();function Vr({deviceId:e}){let t=X(),n=G(),r=Number.isFinite(e),{data:i,isLoading:a}=s({deviceId:e},{enabled:r,refetchInterval:1e4}),{data:o}=ye({deviceId:e,includeSynthesizable:!0},{enabled:r}),c=new Map;for(let e of o?.caps??[])e.itemArray&&c.set(e.cap,e.itemArray);let l=qe({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),u=i?.deviceLinks??[],d=typeof i?.parentDeviceId==`number`?i.parentDeviceId:null,f=typeof i?.stableId==`string`?i.stableId:``,[p,m]=K(null),h=t=>{l.mutate({deviceId:e,deviceLinks:u.filter(e=>e.id!==t)})};return a?q(`div`,{className:`p-4`,children:q(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})}):p===null?H(`div`,{className:`flex flex-col gap-3 p-1`,children:[H(`div`,{className:`flex items-center justify-between`,children:[q(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Wiring`}),H(`button`,{type:`button`,onClick:()=>m(`new`),title:`Add a cross-device link`,className:`inline-flex items-center gap-1 rounded-md border border-border px-2 py-1 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[q(wt,{className:`h-3 w-3`}),`Add link`]})]}),u.length===0?H(`div`,{className:`flex flex-col items-center justify-center gap-2 py-8 text-foreground-subtle`,children:[q(tn,{className:`h-8 w-8 opacity-30`}),q(`p`,{className:`text-xs`,children:`No links yet.`}),q(`p`,{className:`text-[10px] opacity-60`,children:`Cross-device field wirings will appear here once authored.`})]}):q(`div`,{className:`flex flex-col divide-y divide-border rounded-lg border border-border overflow-hidden`,children:u.map(n=>q(Ur,{deviceId:e,link:n,itemArray:c.get(n.target.cap),trpcClient:t.trpcClient,onDelete:()=>h(n.id),onEdit:()=>m(n),isPending:l.isPending},n.id))})]}):H(`div`,{className:`flex flex-col gap-3 p-1`,children:[q(`div`,{className:`flex items-center justify-between`,children:q(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:p===`new`?`Add link`:`Edit link`})}),q(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:q(Br,{deviceId:e,parentDeviceId:d,deviceStableId:f,initial:p===`new`?null:p,onSave:t=>{let n=u.some(e=>e.id===t.id)?u.map(e=>e.id===t.id?t:e):[...u,t];l.mutate({deviceId:e,deviceLinks:n}),m(null)},onCancel:()=>{m(null)}})})]})}function Hr(e,t,n,r){let i=ot(e,t.path);if(!Array.isArray(i))return;let a=i.find(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Reflect.get(e,t.keyField)===n);return a===void 0?void 0:ot(a,r)}function Ur({deviceId:e,link:t,itemArray:n,trpcClient:r,onDelete:i,onEdit:a,isPending:o}){let s=Te(r,e,t.target.cap),c=t.target.itemKey,l=s===void 0?void 0:c!==void 0&&n!==void 0?Hr(s,n,c,t.target.fieldPath):c===void 0?ot(s,t.target.fieldPath):void 0,u=l==null?`—`:String(l);return H(`div`,{className:`flex items-center gap-3 px-3 py-2.5 bg-surface hover:bg-surface-hover transition-colors`,children:[q(nn,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle/40`}),H(`div`,{className:`min-w-0 flex-1 flex flex-col gap-0.5`,children:[H(`div`,{className:`flex items-baseline gap-1 flex-wrap`,children:[q(`span`,{className:`font-mono text-[11px] font-medium text-foreground`,children:t.target.cap}),q(`span`,{className:`text-[10px] text-foreground-subtle/60`,children:`.`}),q(`span`,{className:`font-mono text-[11px] text-foreground-subtle`,children:t.target.fieldPath}),c!==void 0&&q(`span`,{className:`rounded bg-surface-hover px-1 py-px font-mono text-[9px] text-foreground-subtle`,title:`Item key — links sharing it build one array item`,children:c})]}),H(`div`,{className:`flex items-baseline gap-1 flex-wrap text-[10px] text-foreground-subtle/70`,children:[q(`span`,{children:`←`}),t.source.kind===`literal`?H(`span`,{className:`font-mono`,children:[`literal: `,String(t.source.value)]}):t.source.kind===`expression`?H(W,{children:[H(`span`,{className:`font-mono`,title:t.source.expr,children:[`ƒ`,` `,t.source.expr.length>40?`${t.source.expr.slice(0,40)}…`:t.source.expr]}),H(`span`,{className:`rounded bg-surface-hover px-1 py-px font-mono text-[9px] text-foreground-subtle`,title:`Number of source bindings`,children:[Object.keys(t.source.bindings).length,` bindings`]})]}):H(W,{children:[q(`span`,{className:`font-mono`,children:t.source.kind===`global`?t.source.sourceStableId:t.source.sourceKey}),q(`span`,{className:`opacity-60`,children:`/`}),q(`span`,{className:`font-mono`,children:t.source.cap}),q(`span`,{className:`opacity-60`,children:`.`}),q(`span`,{className:`font-mono`,children:t.source.fieldPath})]})]})]}),t.transform&&q(Wr,{kind:t.transform.kind}),q(`span`,{className:`font-mono text-[11px] tabular-nums min-w-[2.5rem] text-right text-foreground-subtle`,title:`Live resolved value (from this device's runtime-state slice)`,children:u}),q(`button`,{type:`button`,"aria-label":`Edit link`,title:`Edit this link`,disabled:o,onClick:a,className:`shrink-0 inline-flex items-center gap-1 rounded-md border border-border/80 px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:`Edit`}),q(`button`,{type:`button`,"aria-label":`Delete link`,title:`Remove this link`,disabled:o,onClick:i,className:`shrink-0 inline-flex items-center gap-1 rounded-md border border-border/80 px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-danger hover:border-danger/50 hover:bg-danger/5 transition-colors disabled:opacity-50`,children:`Delete`})]})}function Wr({kind:e}){return q(`span`,{className:`inline-flex items-center rounded-md border border-primary/20 bg-primary/5 px-1.5 py-0.5 font-mono text-[10px] text-primary/80 shrink-0`,children:e})}V();var Gr=[{id:`overview`,label:`Overview`,cameraOnly:!1},{id:`config`,label:`Config`,cameraOnly:!1},{id:`detection-pipeline`,label:`Detection pipeline`,cameraOnly:!0},{id:`bindings`,label:`Bindings`,cameraOnly:!0},{id:`wiring`,label:`Wiring`,cameraOnly:!1}];function Kr(e){let t=e===Y.Camera;return Gr.filter(e=>t||!e.cameraOnly).map(({id:e,label:t})=>({id:e,label:t}))}var qr=[{id:`logs`,icon:Bt,label:`Logs`},{id:`repl`,icon:Ut,label:`REPL`},{id:`events`,icon:Mt,label:`Events`},{id:`state`,icon:Ht,label:`State`}];function Jr(){let n=Nt(),r=Number(n.deviceId),l=Number.isFinite(r),u=Gt(),f=G(),p=d(),m=X(),[h,g]=Lt(),v=h.get(`tab`)??`overview`,y=h.get(`sub`),[b,S]=K(`logs`),C=`device-detail.left-col-width-px`,[w,te]=K(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(C),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),T=B(w);T.current=w;function E(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??w??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{te(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=T.current;if(e!==null)try{window.localStorage.setItem(C,String(Math.round(e)))}catch{}document.body.style.userSelect=``,document.body.style.cursor=``};document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,document.addEventListener(`mousemove`,i),document.addEventListener(`mouseup`,a)}let{data:ie,isLoading:D,isError:ae}=s({deviceId:r},{enabled:l,refetchInterval:5e3,retry:1}),{data:oe}=ee({deviceId:r},{enabled:l}),O=U(()=>{let e=oe?.settings?.sections??[],t=oe?.live?.sections??[],n=[...e,...t],r=new Set;for(let e of n)e.location===`top-tab`&&e.tab&&r.add(e.tab===`zones`?`detection-pipeline`:e.tab);return n.some(Xt)&&r.add(Zt),[...r].map(e=>e===`export`?{id:e,label:Qt,isAddonContrib:!0}:{id:e,label:$e[e]?.label??e,isAddonContrib:!0})},[oe]),k=ie,A=String(k?.name??n.deviceId??`Device`),j=k?.online===!0,se=j?`online`:`offline`,M=String(k?.addonId??`rtsp`),N=k?.features??[],P=k?.type,ue=P===Y.Camera,{data:F}=xt(l?r:0),fe=P===Y.Container,pe=U(()=>(F??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[F]),me=U(()=>fe?le(pe,typeof k?.linkDeviceId==`number`?k.linkDeviceId:null,typeof k?.primaryChildEntityId==`string`?k.primaryChildEntityId:null)?.id??null:null,[fe,pe,k?.linkDeviceId,k?.primaryChildEntityId]),{data:I}=ee({deviceId:me??0},{enabled:me!==null}),he=U(()=>{if(me===null)return[];let e=I?.settings?.sections??[],t=I?.live?.sections??[],n=new Set;for(let r of[...e,...t])r.location===`top-tab`&&r.tab&&n.add(r.tab);return[...n].map(e=>({id:e,label:$e[e]?.label??e,isAddonContrib:!0,childDeviceId:me}))},[me,I]),L=typeof k?.parentDeviceId==`number`?k.parentDeviceId:null,{data:ge}=s({deviceId:L??0},{enabled:L!==null}),R=we(),z=k?.disabled!==!0,{data:_e}=ye({deviceId:r},{enabled:l}),ve=(_e?.caps.length??0)>0,xe=U(()=>{let e=new Set,t=[];for(let n of[...Kr(P),...O,...he])e.has(n.id)||(e.add(n.id),!(n.id===`wiring`&&!ve)&&t.push(n));return t},[P,O,he,ve]),Se=U(()=>xe.some(e=>e.id===v)?v:`overview`,[xe,v]),Ce=Je(e=>{g(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[g]),Te=Je(e=>{g(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[g]),Ee=(F??[]).length>0,Oe=U(()=>qr.filter(({featureGate:e})=>!e||N.includes(e)),[N]),{data:ke}=de({addonId:M},{enabled:!!M&&M!==`rtsp`}),Ae=_({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]}),u(ke?.id?`/integrations/${ke.id}`:`/integrations`)}}),je=a({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Me=Ve({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ne=t(),Fe=re({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ie=N.includes(nt.Rebootable),Le=N.includes(nt.BatteryOperated),Re=e(m.trpcClient,Le&&l?r:null),[ze,He]=K(!1),Ue=ct(m.trpcClient,l?r:null),We=async()=>{if(!(ze||!Ue)){He(!0);try{await Ue.snapshot?.invalidateCache({});let e=await Ue.snapshot?.getSnapshot({});if(!e)return;let t=`data:${e.contentType};base64,${e.base64}`,n=e.contentType.includes(`png`)?`png`:`jpg`,r=A.replace(/[^a-zA-Z0-9_.-]+/g,`_`),i=new Date().toISOString().replace(/[:.]/g,`-`),a=document.createElement(`a`);a.href=t,a.download=`${r}-${i}.${n}`,document.body.appendChild(a),a.click(),document.body.removeChild(a)}finally{He(!1)}}},Ge=je.isPending||Me.isPending,{data:Ke}=Be({deviceId:r},{enabled:l,refetchInterval:1e4}),qe=Ke?.agentNodeId??null,V=typeof qe==`string`&&qe.length>0&&!qe.startsWith(`addon:`)?qe:void 0,{data:Ye}=ne({deviceId:r,...V?{nodeId:V}:{}},{enabled:l,refetchInterval:3e3,retry:!1}),{data:W}=i({deviceId:r},{enabled:l,refetchInterval:3e3,retry:!1}),Xe=W?.level?.dbfs??null;function J(){if(!l)return null;switch(Se){case`overview`:return q(ur,{device:k??{}});case`config`:return q(Fn,{deviceId:r,activeSubTab:y,onSubTabChange:Te});case`detection-pipeline`:return q(qn,{deviceId:r,activeSubTab:y,onSubTabChange:Te});case`bindings`:return q(jn,{deviceId:r});case`wiring`:return q(Vr,{deviceId:r});default:{let e=Se,t=O.some(t=>t.id===e),n=he.find(t=>t.id===e);if(!t&&n===void 0)return null;let i=n?.childDeviceId??r;if(e===`export`)return q($t,{deviceId:r,sectionFilter:Xt,activeSubTab:y,onSubTabChange:Te});let a=q($t,{deviceId:i,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:y,onSubTabChange:Te});return n!==void 0&&i!==r?q(x,{deviceId:i,children:a}):a}}}return l?D?H(`div`,{className:`flex flex-col h-full`,children:[H(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[q(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),q(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),q(`div`,{className:`flex-1 p-6`,children:q(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):ae||!ie?H(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[q(`p`,{className:`text-lg font-semibold text-foreground`,children:`Device not found`}),H(`p`,{className:`text-xs`,children:[`No device with ID`,` `,H(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,r]})]}),q(`button`,{onClick:()=>u(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]}):H(`div`,{className:`absolute inset-0 flex flex-col overflow-hidden`,children:[H(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[q(`div`,{className:`mb-2`,children:q(Pe,{items:[{label:`Integrations`,onClick:()=>u(`/integrations`)},{label:ke?.name??M,onClick:()=>ke?.id&&u(`/integrations/${ke.id}`)},{label:A}]})}),H(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[q(gt,{type:M,size:`lg`}),H(`div`,{className:`min-w-0 flex-1`,children:[H(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[q(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:A}),q(Jt,{status:se}),Le&&q(ce,{status:Re,variant:`full`})]}),L!==null&&ge&&H(`button`,{type:`button`,onClick:()=>u(`/devices/${L}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${ge.name}`,children:[q(`span`,{children:`↑`}),q(`span`,{className:`truncate`,children:String(ge.name??`Device #${L}`)})]}),q(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:N.length>0&&q(pt,{capabilities:N})})]}),Ye&&q(`div`,{className:`hidden lg:flex`,children:q(Yr,{metrics:Ye,dbfs:Xe})}),H(`div`,{className:`flex items-center gap-1 shrink-0`,children:[H(`button`,{onClick:async()=>{z?await p({title:`Disable "${A}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&Me.mutate({deviceId:r}):je.mutate({deviceId:r})},disabled:Ge,title:z?`Disable device`:`Enable device`,className:`inline-flex items-center gap-1.5 rounded-lg px-2 sm:px-2.5 py-1.5 text-[11px] font-medium border transition-colors disabled:opacity-50 ${z?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[q(rn,{className:`h-3.5 w-3.5`}),q(`span`,{className:`hidden sm:inline`,children:Ge?`Updating…`:z?`Enabled`:`Disabled`})]}),q(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),q(be,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:kt,disabled:ze,onClick:()=>{We()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:Et,hidden:!Ie,disabled:Ne.isPending,danger:!0,onClick:async()=>{await p({title:`Reboot "${A}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&Ne.mutate({deviceId:r})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${ke?.name??M}.`,icon:Tt,disabled:Fe.isPending,danger:!0,onClick:async()=>{await p({title:`Restart "${ke?.name??M}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${A}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&Fe.mutate({addonId:M})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:zt,separatorBefore:!0,disabled:Ae.isPending,danger:!0,onClick:async()=>{await p({title:`Delete "${A}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&Ae.mutate({deviceId:r})}}]})]})]})]}),q(x,{deviceId:r,device:k??void 0,children:q(o,{children:q(c,{children:q(dt,{children:q(De,{children:H(`main`,{className:R?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[H(`div`,{className:R?`flex flex-col bg-surface`:`${w===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!R&&w!==null?{width:`${String(w)}px`}:void 0,children:[q(`div`,{className:ue?`flex-shrink-0 border-b border-border-subtle bg-black`:R?`flex-shrink-0 border-b border-border-subtle bg-surface`:`max-h-[55%] shrink-0 overflow-y-auto border-b border-border-subtle bg-surface`,children:ue?q(En,{deviceId:r,intercomAvailable:N.includes(nt.TwoWayAudio)}):q(_n,{deviceId:r,deviceName:A,deviceType:P??`unknown`,provider:M,isOnline:j,features:N})}),H(`div`,{className:R?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[q(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:q(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:Oe.map(({id:e,label:t,icon:n})=>H(`button`,{onClick:()=>S(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${b===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[q(n,{className:`h-3 w-3`}),t]},e))})}),H(`div`,{className:R?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[b===`logs`&&q(Dn,{deviceId:r,containerDeviceId:P===`container`?r:void 0}),b===`repl`&&q(On,{deviceId:r}),b===`events`&&q(kn,{deviceId:r}),b===`state`&&q(An,{deviceId:r})]})]})]}),!R&&q(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:E,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:q(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),H(`div`,{className:R?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[q(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:q(`div`,{className:`flex flex-nowrap overflow-x-auto md:flex-wrap md:overflow-x-visible items-center gap-0`,children:xe.map(e=>{let t=Se===e.id;return H(`button`,{onClick:()=>Ce(e.id),className:`relative flex-shrink-0 px-3 py-2 text-xs font-medium transition-colors ${t?`text-primary`:`text-foreground-subtle hover:text-foreground`}`,children:[e.label,t&&q(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),H(`div`,{className:R?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[Se===`overview`&&Ee&&q(on,{parentDeviceId:r}),J()]})]})]})})})})})})]}):H(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[q(`p`,{className:`text-lg font-semibold text-foreground`,children:`Invalid device id`}),H(`p`,{className:`text-xs`,children:[`The URL segment`,` `,q(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:n.deviceId}),` `,`is not a number.`]}),q(`button`,{onClick:()=>u(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]})}function Yr({metrics:e,dbfs:t}){let n=u(e.phase??`idle`);return H(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[H(`div`,{className:`flex items-center gap-1.5`,children:[q(`span`,{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),q(`span`,{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),q(`div`,{className:`h-3 w-px bg-border`}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[q(It,{className:`h-3 w-3`}),q(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),q(`span`,{children:`fps`})]}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[q(Pt,{className:`h-3 w-3`}),q(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),q(`span`,{children:`ms`})]}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:`Current audio level (dBFS)`,children:[q(an,{className:`h-3 w-3`}),q(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),q(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&H(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{Jr as DeviceDetailPage};
@@ -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-BuqU1Y2C.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-d71rtvEQ.js";import{p as P}from"./player-overlays-DHswkbsp.js";import{t as F}from"./circle-check-big-CkPzYYPA.js";import{t as I}from"./copy-CL5WAyDW.js";import{t as L}from"./pencil-omAkHegX.js";import{t as R}from"./plus-BpyRM_02.js";import{t as ne}from"./refresh-cw-CE37ff37.js";import{t as re}from"./search-BfmAjYfy.js";import{t as z}from"./send-BOE-EMzz.js";import{C as B,G as V,H as ie,P as ae,c as H,i as oe,s as se}from"./index-BeCIFexS.js";import{t as U}from"./AdminPage-Dq33XE9j.js";import{t as ce}from"./AdminTabs-CMrAY8Sg.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 W=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];W(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=W(r.label),i=W(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&&W(t.ttl)?Number(t.ttl):void 0;return{body:t.body,format:me(e,t.format),priority:ve(t.priority),...W(t.title)?{title:t.title}:{},...n?{level:n}:{},...r.length>0?{attachments:r}:{},...i.length>0?{actions:i}:{},...e.clickUrl&&W(t.clickUrl)?{clickUrl:t.clickUrl}:{},...e.sound&&W(t.sound)?{sound:t.sound}:{},...a!==void 0&&Number.isFinite(a)?{ttl:a}:{},...W(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 G(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 G(e,`image`,`Test notification with an image.`);case`gif`:return G(e,`gif`,`Test notification with an animation.`);case`video`:return G(e,`video`,`Test notification with a video.`);case`audio`:return G(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)`},K=`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`,q=`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:q,children:`Level`}),x(`select`,{className:K,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:q,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:q,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:q,children:`Title`}),k(`input`,{className:K,value:u.title,onChange:e=>C({title:e.target.value})})]}),x(`div`,{children:[x(`label`,{className:q,children:[`Body`,` `,x(`span`,{className:b?`text-danger`:`text-foreground-subtle`,children:[`(`,_,`/`,s.bodyMaxLen,b?` — overflow`:``,`)`]})]}),k(`textarea`,{className:`${K} 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:q,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:K,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:q,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:K,placeholder:`label`,value:u.actions[t]?.label??``,onChange:e=>E(t,`label`,e.target.value)}),k(`input`,{className:K,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:q,children:`Click URL`}),k(`input`,{className:K,value:u.clickUrl,onChange:e=>C({clickUrl:e.target.value})})]}),s.showSound&&x(`div`,{children:[k(`label`,{className:q,children:`Sound`}),k(`input`,{className:K,value:u.sound,onChange:e=>C({sound:e.target.value})})]}),s.showTtl&&x(`div`,{children:[k(`label`,{className:q,children:`TTL (seconds)`}),k(`input`,{className:K,type:`number`,value:u.ttl,onChange:e=>C({ttl:e.target.value})})]}),s.showTag&&x(`div`,{children:[k(`label`,{className:q,children:`Tag`}),k(`input`,{className:K,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(z,{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(z,{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(U,{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(re,{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 J=`mt-1 w-full rounded border border-border bg-background px-2 py-1 text-xs`,Y=`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:Y,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:Y,children:`Min delay (s)`}),k(`input`,{type:`number`,min:0,className:J,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:Y,children:`Step`}),x(`select`,{className:J,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:Y,children:`Seconds`}),k(`input`,{type:`number`,min:0,max:300,className:J,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:Y,children:`Device`}),x(`select`,{className:J,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:Y,children:`Capability`}),x(`select`,{className:J,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:Y,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:Y,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:Y,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:Y,children:`Runs`}),x(`select`,{className:J,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:Y,children:`Icon`}),x(`select`,{className:J,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`})})]})}function X(e){return t=>Object.prototype.hasOwnProperty.call(e,t)}var tt=X({devices:!0}),nt=X({classes:!0,classesExclude:!0,labelEquals:!0,identities:!0,identitiesExclude:!0,eventTypeTokens:!0,sensorKinds:!0}),rt=X({zonesExclude:!0}),it=X({minConfidence:!0,minImportance:!0,minLabelConfidence:!0}),at=X({minDwellSeconds:!0}),ot=X({source:!0}),st=X({crossing:!0}),ct=X({packagePhase:!0}),lt=X({zones:!0}),ut=X({plates:!0}),dt=X({occupancy:!0}),ft=X({deviceState:!0});function Z(e,t){let n=e[t];return Array.isArray(n)?n:[]}function pt(e,t){let n=e[t];return typeof n==`number`?n:void 0}var mt=[{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 ht(e){let t=e.replace(/[-_]/g,` `);return t.charAt(0).toUpperCase()+t.slice(1)}function gt(e,t){let n=e.filter(t),r=new Set(mt.map(e=>e.id)),i=[];for(let e of mt){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:ht(e),descriptors:n.filter(t=>t.group===e)});return i}b();function _t(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 vt(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 yt(){let t=e();return S(()=>({options:(t.data??[]).map(e=>({value:e.name,label:e.name})),loading:t.isLoading}),[t.data,t.isLoading])}function bt(){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 xt({options:e,value:t,onChange:n,loading:r,emptyHint:i,placeholder:a}){let[o,s]=D(``),c=S(()=>new Set(e.map(e=>e.value)),[e]),l=S(()=>new Set(t),[t]),u=t.filter(e=>!c.has(e)),d=e=>{n(l.has(e)?t.filter(t=>t!==e):[...t,e])},f=()=>{let e=o.trim();e.length===0||t.includes(e)||(n([...t,e]),s(``))};return x(`div`,{className:`mt-1 space-y-1.5`,children:[u.length>0&&k(`div`,{className:`flex flex-wrap gap-1`,children:u.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:l.has(e.value),onChange:()=>d(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}),k(`input`,{value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),f())},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 Q=[{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 St(e){return Q.find(t=>t.value===e)?.label??e}function Ct(e){return Q.find(t=>t.value===e)?.value}var wt=[{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 Tt(e){return wt.find(t=>t.value===e)?.value}var Et=[{value:``,label:`Automatic`},{value:`cropped`,label:`Cropped on the subject`},{value:`full`,label:`Full frame`},{value:`boxed`,label:`Full frame with boxes`}];function Dt(e){let t=Et.find(t=>t.value===e)?.value;return t===``?void 0:t}var Ot=[{value:``,label:`Lowest available`},{value:`low`,label:`Low`},{value:`mid`,label:`Medium`},{value:`high`,label:`High`}];function kt(e){let t=Ot.find(t=>t.value===e)?.value;return t===``?void 0:t}var At=[{value:`any`,label:`Any source`},{value:`pipeline`,label:`Pipeline`},{value:`onboard`,label:`Onboard (camera)`},{value:`sensor`,label:`Sensor`}],jt=[{value:`delivered`,label:`Delivered`},{value:`picked-up`,label:`Picked up`},{value:`both`,label:`Both`}],Mt=[{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 Nt(e){let t=Mt.find(t=>t.value===e)?.value;return t===``||t===void 0?void 0:t}var Pt=[{value:`any`,label:`Any of`},{value:`all`,label:`All of`}],Ft=[{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 It(){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}}function Lt(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)}}function Rt(e){return e.name.trim().length>0&&(e.targetIds.length>0||e.targetUsers.length>0)&&Ke(e.actions).length===0}function zt(e,t){return e.appliesTo.includes(t)}var Bt={source:`any`};function Vt(e,t){if(t==null)return!0;if(Array.isArray(t))return t.length===0;if(typeof t==`string`)return t.length===0||Bt[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 Ht(e,t,n){let r=n.length===0?null:new Set(n.filter(e=>e.id!==`schedule`&&zt(e,t)).map(e=>e.id)),i={};for(let[t,n]of Object.entries(e))r!==null&&!r.has(t)||Vt(t,n)||(i[t]=n);return i}function Ut(e){return e!==void 0&&e.windows.length>0}function Wt(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`&&zt(t,e.delivery)))&&Ut(e.schedule)?e.schedule:void 0;return{name:e.name.trim(),enabled:e.enabled,delivery:e.delivery,conditions:Ht(e.conditions,e.delivery,n),...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 Gt(e,t){return e.options&&e.options.length>0?e.options:t}var Kt=[{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 qt(e){if(e===``)return;let t=Number(e);return Number.isFinite(t)&&t>=1&&t<=8?t:void 0}var Jt=[{key:`rule`,label:`Rule`,fields:[`name`,`enabled`,`delivery`,`targetIds`,`targetUsers`,`targetParams`]},{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`]}],Yt=`rule`;function Xt(e){return Jt.find(t=>t.key===e)?.key}b();var Zt=`block text-[11px] font-medium text-foreground`,$=`text-[10px] text-foreground-subtle mt-0.5`;function Qt({cameras:e,value:t,onChange:n}){if(e.length===0)return k(`p`,{className:$,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 $t({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 en({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 tn({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 nn({value:e,onChange:t,options:n}){let r=e??``,a=n&&n.length>0?n:Mt,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(Nt(e.target.value))}),o!==void 0&&k(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:o.hint})]})}function rn({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:Pt.map(e=>({value:e.value,label:e.label})),onChange:e=>c(e.target.value===`all`?`all`:`any`)})}),k(an,{deviceIds:e,cameras:t,value:a,onChange:s})]})}function an({deviceIds:e,cameras:t,value:n,onChange:r}){let{options:i,loading:a}=_t(e,t);return k(xt,{options:i,value:n,onChange:r,loading:a,emptyHint:e.length===0?`Select cameras above to pick their zones by name — or type a zone id.`:`The selected cameras have no zones — type a zone id if you know one.`,placeholder:`Zone id…`})}function on({value:e,onChange:t}){let{options:n,loading:r}=yt();return k(xt,{options:n,value:e,onChange:t,loading:r,emptyHint:`No identities in the face gallery yet — type a name.`,placeholder:`Identity name…`})}function sn({deviceIds:e,value:t,onChange:n}){let{options:r,loading:i}=vt(e);return k(xt,{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 cn=[{value:`became-occupied`,label:`Became occupied`},{value:`became-free`,label:`Became free`},{value:`>=`,label:`Count ≥`},{value:`<=`,label:`Count ≤`}],ln={op:`became-occupied`,count:1,sustainSeconds:15};function un({deviceIds:e,cameras:t,classOptions:n,value:a,onChange:o}){let{options:s,loading:c}=_t(e,t),l=a??ln,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:cn.map(e=>({value:e.value,label:e.label})),onChange:e=>{let t=cn.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 dn({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=bt().filter(e=>!n.includes(e));return x(`div`,{className:`mt-1 space-y-1.5`,children:[k($t,{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 fn({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 pn=[{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 mn(e){let t=Math.floor(e/60),n=e%60;return`${String(t).padStart(2,`0`)}:${String(n).padStart(2,`0`)}`}function hn(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 gn(){return{days:[1,2,3,4,5],startMinute:540,endMinute:1080}}function _n({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,gn()],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:$,children:`Always active — add a window to restrict when the rule fires.`}):n.map((e,t)=>k(vn,{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 vn({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:mn(e.startMinute),onChange:n=>t({...e,startMinute:hn(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:mn(e.endMinute),onChange:n=>t({...e,endMinute:hn(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:pn.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 yn({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(()=>gt(e,e=>M(e.id)),[e]),d=S(()=>gt(e,e=>!M(e.id)),[e]),[f,p]=D(()=>{if(xn(r,i))return!0;try{return localStorage.getItem(bn)===`1`}catch{return!1}}),h=()=>{let e=!f;p(e);try{localStorage.setItem(bn,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=zt(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:Zt,children:e.label}),!s&&x(m,{variant:`default`,children:[`not for `,e.appliesTo.join(` / `)]})]}),s?k(Sn,{descriptor:e,taxonomy:t,conditions:r,schedule:i,cameras:a,gateable:o,onFieldChange:l,onScheduleChange:c}):k(`p`,{className:$,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 bn=`camstack.nc.showAdvanced`;function xn(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 Sn({descriptor:e,taxonomy:t,conditions:n,schedule:r,cameras:a,gateable:o,onFieldChange:s,onScheduleChange:c}){switch(e.valueType){case`deviceIdList`:{if(!tt(e.id))break;let t=e.id;return k(Qt,{cameras:a,value:n[t]??[],onChange:e=>s(t,e.length>0?e:void 0)})}case`stringList`:{if(!nt(e.id))break;let r=e.id,i=e=>s(r,e.length>0?e:void 0);if(r===`identities`||r===`identitiesExclude`)return k(on,{value:Z(n,r),onChange:i});if(r===`eventTypeTokens`)return k(sn,{deviceIds:n.devices??[],value:Z(n,r),onChange:i});let a=j(r,t);return a===null?k($t,{value:Z(n,r),placeholder:`Add value…`,onChange:i}):k(en,{picker:a,value:Z(n,r),onChange:i})}case`zoneIdList`:{if(!rt(e.id))break;let t=e.id;return k(an,{deviceIds:n.devices??[],cameras:a,value:Z(n,t),onChange:e=>s(t,e.length>0?e:void 0)})}case`number01`:{if(!it(e.id))break;let t=e.id;return k(tn,{value:pt(n,t),min:0,max:1,step:.05,onChange:e=>s(t,e)})}case`number`:{if(!at(e.id))break;let t=e.id;return k(tn,{value:pt(n,t),min:0,step:1,onChange:e=>s(t,e)})}case`sourceSelect`:{if(!ot(e.id))break;let t=e.id;return k(i,{value:n[t]??`any`,options:Gt(e,At).map(e=>({value:e.value,label:e.label})),onChange:e=>s(t,Tn(e.target.value))})}case`deviceState`:if(!ft(e.id))break;return k(fn,{gateable:o,value:n.deviceState,onChange:e=>s(`deviceState`,e)});case`crossingSelect`:{if(!st(e.id))break;let t=e.id;return k(nn,{value:n[t],onChange:e=>s(t,e),...e.options?{options:e.options}:{}})}case`packagePhase`:{if(!ct(e.id))break;let t=e.id;return k(i,{value:n[t]??``,options:[{value:``,label:`— any phase —`},...Gt(e,jt).map(e=>({value:e.value,label:e.label}))],onChange:e=>s(t,En(e.target.value))})}case`zoneSelection`:{if(!lt(e.id))break;let t=e.id;return k(rn,{deviceIds:n.devices??[],cameras:a,value:n[t],onChange:e=>s(t,e)})}case`plateMatcher`:{if(!ut(e.id))break;let t=e.id;return k(dn,{value:n[t],onChange:e=>s(t,e)})}case`occupancy`:{if(!dt(e.id))break;let r=e.id;return k(un,{deviceIds:n.devices??[],cameras:a,classOptions:Cn(t),value:n[r],onChange:e=>s(r,e)})}case`schedule`:return k(_n,{value:r,onChange:c});default:break}return k(wn,{descriptor:e,conditions:n})}function Cn(e){let t=j(`classes`,e);return t===null?[]:t.groups.flatMap(e=>e.options)}function wn({descriptor:e,conditions:t}){let n=Object.entries(t).find(([t])=>t===e.id);return x(`p`,{className:$,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 Tn(e){if(e===`pipeline`||e===`onboard`||e===`sensor`||e===`any`)return e}function En(e){return jt.find(t=>t.value===e)?.value}b();var Dn=[`notificationRules`,`listSnoozes`],On=3e4;function kn(e,t){return Math.max(0,Math.ceil((e.expiresAt-t)/6e4))}function An(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 jn({rules:e}){let n=P(),r=E(),i=C({queryKey:Dn,refetchInterval:On,queryFn:async()=>(await n.trpcClient.notificationRules.listSnoozes.query({})).snoozes}),a=O({mutationFn:e=>n.trpcClient.notificationRules.cancelSnooze.mutate({snoozeId:e}),onSuccess:()=>r.invalidateQueries({queryKey:Dn})}),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,` · `,An(kn(e,c))]})]}),k(t,{size:`sm`,variant:`outline`,disabled:a.isPending,onClick:()=>a.mutate(e.id),children:`End now`})]},e.id))})]})}b();var Mn=[`notificationRules`,`listRules`],Nn=[`notificationOutput`,`listTargets`,`forRules`],Pn=[`notificationRules`,`getConditionCatalog`],Fn=[`deviceManager`,`listAll`,`forRules`],In=[`deviceManager`,`listAll`,`forRuleActions`],Ln=[`deviceManager`,`gateableDevices`],Rn=N.options;function zn(){let e=P(),[n,r]=D({mode:`closed`}),[i,o]=D(null),c=C({queryKey:Mn,queryFn:async()=>(await e.trpcClient.notificationRules.listRules.query({})).rules}),l=C({queryKey:Nn,queryFn:()=>e.trpcClient.notificationOutput.listTargets.query({})}),u=C({queryKey:Pn,queryFn:()=>e.trpcClient.notificationRules.getConditionCatalog.query({})}),d=C({queryKey:Ln,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}),Rn);t.length>0&&n.push({id:r.id,name:r.name,states:t})}return n},staleTime:6e4}),f=C({queryKey:In,queryFn:async()=>(await e.trpcClient.deviceManager.listAll.query({})).map(e=>({id:e.id,name:e.name})).sort((e,t)=>e.name.localeCompare(t.name)),staleTime:6e4}),p=C({queryKey:Fn,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(U,{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(jn,{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:Bn({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(Vn,{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 Bn(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:St(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 Vn({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?Lt(e):It()),[E,A]=D(null),[j,ee]=D(null),[te,M]=D(Yt),N=e=>T(t=>({...t,...e})),F=S&&e?{throttle:e.throttle}:void 0,I=O({mutationFn:async()=>{let t=Wt(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=Wt(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]}),re=C({queryKey:[`userManagement`,`listUsers`],queryFn:()=>b.trpcClient.userManagement.listUsers.query()}).data,z=e=>N({targetUsers:w.targetUsers.includes(e)?w.targetUsers.filter(t=>t!==e):[...w.targetUsers,e]}),V=Q.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(Xt(e)??te),children:[k(f,{className:`mb-3`,children:Jt.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=Ct(e.target.value);t&&N({delivery:t})},options:Q.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`}),(re??[]).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:(re??[]).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:()=>z(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:`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:Ft.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=Tt(e.target.value);t&&N({mediaAttach:t})},options:wt.map(e=>({value:e.value,label:e.label}))}),k(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:wt.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:kt(e.target.value)}),options:Ot.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:qt(e.target.value)}),options:Kt.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:Dt(e.target.value)}),options:Et.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(yn,{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||!Rt(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(Hn,{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||!Rt(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 Hn({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 Un=[{value:1,label:`Last hour`},{value:24,label:`Last 24 hours`},{value:168,label:`Last 7 days`},{value:0,label:`All time`}],Wn=[{value:``,label:`Any status`},{value:`pending`,label:`Pending`},{value:`sent`,label:`Sent`},{value:`dead`,label:`Dead`}],Gn=[50,100,250,500];function Kn(){return{ruleId:``,deviceId:``,status:``,windowHours:24,limit:100}}function qn(e){return e===`pending`||e===`sent`||e===`dead`?e:void 0}function Jn(e){switch(e){case`pending`:return`info`;case`sent`:return`success`;case`dead`:return`danger`}}function Yn(){let e=P(),[t,n]=D(Kn),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)}:{},...qn(t.status)?{status:qn(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(U,{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:Wn.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:Un.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:Gn.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:Xn(d),rows:f,rowKey:e=>e.id,minWidthPx:720,bordered:!1})})]})}function Xn(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:Jn(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:`—`})}]}function Zn(){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(zn,{})},{id:`history`,label:`History`,icon:fe,content:k(Yn,{})}]})})}export{Zn as NotificationsPage,Zn as default};
@@ -1 +0,0 @@
1
- import{G as e}from"./index-BeCIFexS.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-BeCIFexS.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};