@camstack/addon-admin-ui 1.2.36 → 1.2.37

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 (114) hide show
  1. package/dist/assets/{AddLocationWizard-D3WNwwzO.js → AddLocationWizard-ruAb2ySj.js} +1 -1
  2. package/dist/assets/AddonCollectionPage-y9PlVqw3.js +1 -0
  3. package/dist/assets/Addons-cAsBu2OQ.js +1 -0
  4. package/dist/assets/{AdminTabs-EuBAqr82.js → AdminTabs-BVHcviOJ.js} +1 -1
  5. package/dist/assets/{AiProfiles-YpD0cNHK.js → AiProfiles-B6EskvNu.js} +1 -1
  6. package/dist/assets/{BrokerForm-lcZzCH84.js → BrokerForm-DIw2g_KM.js} +1 -1
  7. package/dist/assets/Build-sVmfeGFf.js +29 -0
  8. package/dist/assets/Capabilities-CTlKJVid.js +1 -0
  9. package/dist/assets/{CapabilityBadges-DDCH_NHd.js → CapabilityBadges-B_ZC7k04.js} +1 -1
  10. package/dist/assets/Cluster-DkXZdWpm.js +1 -0
  11. package/dist/assets/{ClusterRecordingTab-uoQhw_ij.js → ClusterRecordingTab-U0cdF9UF.js} +1 -1
  12. package/dist/assets/{Dashboard-BM-5S-Cj.js → Dashboard-BCNcg--7.js} +1 -1
  13. package/dist/assets/Data-ZtVnR1Fe.js +1 -0
  14. package/dist/assets/DetectionIntelligence-BlZl9E8S.js +1 -0
  15. package/dist/assets/{DeviceAggregateSection-Cfju7u5B.js → DeviceAggregateSection-UxtJHE5B.js} +1 -1
  16. package/dist/assets/DeviceDetail-BbYvgUSY.js +2 -0
  17. package/dist/assets/{Devices-dbkRu6sh.js → Devices-DzLVWcFg.js} +1 -1
  18. package/dist/assets/{EmbedPlayerPage-CCTm073s.js → EmbedPlayerPage-C5yT7D0W.js} +1 -1
  19. package/dist/assets/Events-BGJ5su4V.js +1 -0
  20. package/dist/assets/FormBuilder-C0N6NRfe.js +1 -0
  21. package/dist/assets/{Identity-EphebNT0.js → Identity-FI4f8ox5.js} +1 -1
  22. package/dist/assets/IntegrationDetail-DxAOxN6t.js +1 -0
  23. package/dist/assets/Integrations-D5S4Yf1A.js +1 -0
  24. package/dist/assets/{Integrations-B3fddOYM.js → Integrations-w3RuUxDV.js} +1 -1
  25. package/dist/assets/{Logs-xK4--bh0.js → Logs-BfDIf7QZ.js} +1 -1
  26. package/dist/assets/{MotionZonesSettings-C0sxf_os.js → MotionZonesSettings-CHyWV5lm.js} +1 -1
  27. package/dist/assets/{MyAccess-D043-D3_.js → MyAccess-76Y7QhMu.js} +1 -1
  28. package/dist/assets/Network-BAUdETHi.js +1 -0
  29. package/dist/assets/{NodeAddonsSettingsPanel-CV-reVXD.js → NodeAddonsSettingsPanel-CeWEr-Zg.js} +1 -1
  30. package/dist/assets/NodeInferenceDevices-CUinkSSN.js +1 -0
  31. package/dist/assets/{Notifications-DZMSKwIB.js → Notifications-CK3PuxFQ.js} +1 -1
  32. package/dist/assets/Pipeline-CTSS1aGu.js +1 -0
  33. package/dist/assets/Plates-Cns09Gg2.js +1 -0
  34. package/dist/assets/{PrivacyMaskSettings-Cj47lnFx.js → PrivacyMaskSettings-C4ycA7Un.js} +1 -1
  35. package/dist/assets/{ProviderIcon-DFIIdGww.js → ProviderIcon-DyK-gNEs.js} +1 -1
  36. package/dist/assets/Recordings-UAlZznSu.js +1 -0
  37. package/dist/assets/{ScanNetworkModal-DEK5U2cd.js → ScanNetworkModal-h3WtjMhA.js} +1 -1
  38. package/dist/assets/{Settings-Casus0ex.js → Settings-oupU5GDf.js} +1 -1
  39. package/dist/assets/{Showroom-f88Jp6ju.js → Showroom-HqqCUr23.js} +1 -1
  40. package/dist/assets/{Terminal-M_8UHE7n.js → Terminal-7B0qx8ho.js} +2 -2
  41. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-AQtYY37w.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BnceOEA8.js} +1 -1
  42. package/dist/assets/authed-media-B8T1dsFh.js +1 -0
  43. package/dist/assets/{rotate-ccw-DGfCNuX0.js → boxes-BS6UzXs9.js} +1 -1
  44. package/dist/assets/{build-cluster-graph-CAb1HaUw.js → build-cluster-graph-CO-MCBmD.js} +2 -2
  45. package/dist/assets/circle-check-big-DKZCFZff.js +1 -0
  46. package/dist/assets/clock-DqPUDB1Y.js +1 -0
  47. package/dist/assets/{copy-BtwlORlH.js → copy-bKWchDUS.js} +1 -1
  48. package/dist/assets/debounced-invalidate-CoCA-chF.js +1 -0
  49. package/dist/assets/dist-B66gZe27.js +7 -0
  50. package/dist/assets/{dist-B_UrLLw9.js → dist-CXHmz2j1.js} +1 -1
  51. package/dist/assets/{download-T_lOWVlB.js → download-C3-lXLSJ.js} +1 -1
  52. package/dist/assets/{face-bbox-f3p_Yctl.js → face-bbox-Cb2eJK0t.js} +1 -1
  53. package/dist/assets/{hostInit-tEAagC07.js → hostInit-DtkE57IB.js} +1 -1
  54. package/dist/assets/index-Bke_0boK.js +4 -0
  55. package/dist/assets/index-mdJi1UIz.css +2 -0
  56. package/dist/assets/{key-round-DDU-8is6.js → key-round-CSNhr2jN.js} +1 -1
  57. package/dist/assets/{mf-entry-bootstrap-0-482a4da7.js → mf-entry-bootstrap-0-e0821d3f.js} +2 -2
  58. package/dist/assets/{pencil-DXM3cvvP.js → pencil-Dbscj0iB.js} +1 -1
  59. package/dist/assets/{player-overlays-Ba-DoE5F.js → player-overlays-CCOENCr_.js} +1 -1
  60. package/dist/assets/plus-kjGKne3v.js +1 -0
  61. package/dist/assets/{radio-DGfartpy.js → radio-BCrXf-T5.js} +1 -1
  62. package/dist/assets/{refresh-cw-NwlTy6_-.js → refresh-cw-B50UNH29.js} +1 -1
  63. package/dist/assets/remoteEntry-DSjWOwlm.js +1 -0
  64. package/dist/assets/rotate-ccw-CnFi79eH.js +1 -0
  65. package/dist/assets/rotate-cw-BMi2-EKp.js +1 -0
  66. package/dist/assets/search-Cqbwip0Z.js +1 -0
  67. package/dist/assets/{send-zoWD-FsL.js → send-vIA2Sg01.js} +1 -1
  68. package/dist/assets/{server-Bv5NUu2G.js → server-CVgGKwKo.js} +1 -1
  69. package/dist/assets/square-NIJNDIvZ.js +1 -0
  70. package/dist/assets/{square-check-big-C_0qc0Ud.js → square-check-big-DTiBKI6p.js} +1 -1
  71. package/dist/assets/src-C3IwZqep.js +7 -0
  72. package/dist/assets/src-DiF3p-RR.js +67 -0
  73. package/dist/assets/{undo-2-B5eeo7kt.js → undo-2-buMXiXDJ.js} +1 -1
  74. package/dist/assets/{upload-B2QyA3Ml.js → upload-YICZuTHD.js} +1 -1
  75. package/dist/assets/{useEventInvalidation-CQp2HDcf.js → useEventInvalidation-CGT7WKQk.js} +1 -1
  76. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BmbjlXvs.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CbdC118i.js} +2 -2
  77. package/dist/assets/{wifi-DiUaWSk8.js → wifi-B6uMvniy.js} +1 -1
  78. package/dist/assets/{zap-y-GpHg-7.js → zap-O3h5iXhW.js} +1 -1
  79. package/dist/index.html +6 -6
  80. package/dist/server/addon.js +1040 -1065
  81. package/package.json +1 -1
  82. package/dist/assets/AddonCollectionPage-D6-DslHs.js +0 -1
  83. package/dist/assets/Addons-xiv8mENL.js +0 -1
  84. package/dist/assets/Automation-Bnvadu_q.js +0 -29
  85. package/dist/assets/Capabilities-BO4EdQiS.js +0 -1
  86. package/dist/assets/Cluster-HqhJz5p-.js +0 -1
  87. package/dist/assets/Data-DBvjn1Ul.js +0 -1
  88. package/dist/assets/DetectionIntelligence-pRUA7cQB.js +0 -1
  89. package/dist/assets/DeviceDetail-DUZkWQjP.js +0 -2
  90. package/dist/assets/Events-D9bI1DWk.js +0 -1
  91. package/dist/assets/FormBuilder-pSCqn9Pp.js +0 -1
  92. package/dist/assets/IntegrationDetail-vt_WT2kb.js +0 -1
  93. package/dist/assets/Integrations-D2z39cEx.js +0 -1
  94. package/dist/assets/Network-DQkG5Rat.js +0 -1
  95. package/dist/assets/NodeInferenceDevices-tLptbnD4.js +0 -1
  96. package/dist/assets/Pipeline-f6X5D5vg.js +0 -1
  97. package/dist/assets/Plates-Dct--YKd.js +0 -1
  98. package/dist/assets/Recordings-Sn1cAwz6.js +0 -1
  99. package/dist/assets/Retrain-cSIFr_tD.js +0 -1
  100. package/dist/assets/authed-media-XfBD4Ma-.js +0 -1
  101. package/dist/assets/circle-check-big-DG4qagl7.js +0 -1
  102. package/dist/assets/clock-XeL04zsb.js +0 -1
  103. package/dist/assets/debounced-invalidate-D3Cu80c9.js +0 -1
  104. package/dist/assets/dist-rfpANeiT.js +0 -7
  105. package/dist/assets/image-off-CxrOL9bA.js +0 -1
  106. package/dist/assets/index-BJkpCYtR.css +0 -2
  107. package/dist/assets/index-CY7HK9zV.js +0 -4
  108. package/dist/assets/plus-DrqAQeFJ.js +0 -1
  109. package/dist/assets/remoteEntry-BzAN7Tig.js +0 -1
  110. package/dist/assets/rotate-cw-W4djelbj.js +0 -1
  111. package/dist/assets/search-DOYQxoHy.js +0 -1
  112. package/dist/assets/square-CBtc15_U.js +0 -1
  113. package/dist/assets/src-CPanq9UB.js +0 -67
  114. package/dist/assets/src-EmgPMReM.js +0 -7
@@ -1,2 +0,0 @@
1
- import{$ as e,An as t,Bn as n,Bt as r,Cn as i,Co as a,D as o,Di as s,Dn as c,Do as l,E as u,F as d,Gi as f,Gn as p,H as m,Hn as h,J as g,Jo as _,Ki as v,Ln as y,Lr as b,Mn as x,N as S,Nn as C,O as w,Oi as T,On as E,P as D,Pi as ee,Pn as O,Q as te,Qi as ne,So as re,T as k,Ti as A,To as j,Tt as ie,U as ae,Un as oe,Vn as M,W as N,Wi as P,Wn as se,Wr as ce,X as le,Xo as ue,Y as F,Yo as de,Z as fe,Zo as pe,_o as me,_r as I,a as L,ao as he,at as ge,bo as _e,cn as R,dr as ve,et as ye,f as be,g as xe,gi as Se,gn as Ce,ho as we,i as Te,ji as Ee,jn as De,l as Oe,ln as ke,m as z,mo as Ae,n as je,no as Me,o as Ne,ot as Pe,p as Fe,pa as Ie,r as Le,ro as Re,rt as ze,st as Be,tt as Ve,u as He,vn as Ue,vo as We,vr as Ge,wn as Ke,wo as qe,y as Je,yo as Ye,yr as Xe,zn as Ze}from"./src-CPanq9UB.js";import{I as Qe,K as B,Q as V,S as H,W as U,a as $e,b as W,o as G,q as K,t as et,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 tt,D as nt,L as rt,M as it,O as at,X as ot,a as st,h as ct,i as lt,j as ut,k as dt,z as Y}from"./src-EmgPMReM.js";import{c as ft,k as pt,p as X,r as mt,t as ht,u as gt}from"./player-overlays-Ba-DoE5F.js";import{t as _t}from"./CapabilityBadges-DDCH_NHd.js";import{n as vt,t as yt}from"./rotate-ccw-DGfCNuX0.js";import{t as bt}from"./ProviderIcon-DFIIdGww.js";import{a as xt,c as St,l as Ct,n as wt,o as Tt}from"./NodeInferenceDevices-tLptbnD4.js";import{n as Et}from"./FormBuilder-pSCqn9Pp.js";import{t as Dt}from"./pencil-DXM3cvvP.js";import{t as Ot}from"./plus-DrqAQeFJ.js";import{t as kt}from"./refresh-cw-NwlTy6_-.js";import{t as At}from"./rotate-cw-W4djelbj.js";import{t as jt}from"./server-Bv5NUu2G.js";import{t as Mt}from"./wifi-DiUaWSk8.js";import{C as Nt,G as Pt,J as Ft,K as It,M as Lt,N as Rt,U as zt,V as Bt,X as Vt,Y as Ht,b as Ut,c as Wt,h as Gt,i as Kt,l as qt,o as Jt,s as Yt,t as Xt,y as Zt,z as Qt}from"./index-CY7HK9zV.js";import{t as $t}from"./StatusBadge-Dcr2bw58.js";import{t as en}from"./useEventInvalidation-CQp2HDcf.js";import{i as tn,n as nn,r as rn,t as an}from"./DeviceAggregateSection-Cfju7u5B.js";var on=It(`circle-help`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),sn=It(`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`}]]),cn=It(`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`}]]),ln=It(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),un=It(`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 dn({parentDeviceId:e}){let{t}=Xt(),n=Ft(),r=X(),{data:i,isLoading:a,isError:o}=Tt(e),{data:s}=c({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=le(s?.stableId??``,l,s?.childLayout),d=u.ungrouped,f=e=>n(`/devices/${String(e)}`),p=s?.name??``,m=(e,t)=>q(g,{trpc:r.trpcClient,device:{...t,name:ye(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(F,{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(F,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>m(e.id,e))},e.title)),y,b]})}function fn({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(bt,{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($t,{status:r?`online`:`offline`}),i.length>0&&q(_t,{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 pn({deviceId:e}){let t=G(),n=R({deviceId:e},{refetchInterval:1e4,retry:!1}),r=ke({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),i=U(()=>mn(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(hn,{label:`Discovered`,value:i.total,icon:q(Zt,{className:`h-3.5 w-3.5`})}),q(hn,{label:`Adopted`,value:i.adopted,accent:`success`}),q(hn,{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(Nt,{className:`h-3.5 w-3.5 animate-spin`}):q(kt,{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(gn,{icon:q(Mt,{className:`h-3 w-3 text-emerald-500`}),label:`${i.online} online`}),q(gn,{icon:q(Ut,{className:`h-3 w-3 text-amber-500`}),label:`${i.sleeping} sleeping`}),q(gn,{icon:q(Jt,{className:`h-3 w-3 text-destructive`}),label:`${i.offline} offline`}),i.unknown>0?q(gn,{icon:q(on,{className:`h-3 w-3 text-foreground-subtle`}),label:`${i.unknown} unknown`}):null]})]})}function mn(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 hn({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 gn({icon:e,label:t}){return H(`span`,{className:`inline-flex items-center gap-1`,children:[e,q(`span`,{children:t})]})}function _n({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(Re,{trpc:X().trpcClient,deviceId:e,features:t})})}function vn({deviceId:e,features:t}){return q(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:q(Me,{trpc:X().trpcClient,deviceId:e,features:t})})}V();function yn({dev:e,busy:t,setBusy:n}){let r=e?.motionTrigger,i=gt(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(Pt,{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=Pe(t)?.HeroCard??Me,a=ft(r.trpcClient,e),o=gt(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(N,{lastChangedAt:u})}):null,q(i,{trpc:r.trpcClient,deviceId:e,features:n}),q(`div`,{className:`flex justify-center`,children:q(yn,{dev:a,busy:s,setBusy:c})})]})}function bn({deviceId:e}){let t=X(),{data:n,isLoading:r}=xt(e),{data:i,isLoading:a}=Tt(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(ae,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}var xn={[Y.Switch]:Z,[Y.Siren]:Z,[Y.Light]:Z,[Y.Sensor]:Z,[Y.Button]:Z,[Y.Hub]:pn,[Y.Cover]:_n,[Y.Valve]:Z,[Y.Humidifier]:Z,[Y.WaterHeater]:Z,[Y.Container]:bn,[Y.Lock]:Z,[Y.Fan]:Z,[Y.Thermostat]:Z,[Y.Climate]:Z,[Y.MediaPlayer]:Z,[Y.Control]:Z,[Y.AlarmPanel]:Z,[Y.EventEmitter]:vn,[Y.Notifier]:vn,[Y.Script]:Z,[Y.Automation]:Z,[Y.Presence]:Z,[Y.Update]:Z,[Y.Vacuum]:Z,[Y.LawnMower]:Z,[Y.Weather]:Z,[Y.Image]:Z,[Y.PetFeeder]:Z};function Sn(e){return xn[e]??fn}function Cn(e){return q(Sn(e.deviceType),{...e})}function wn(e){return L(X().trpcClient,e)}V();function Tn(e){let[t,n]=K(`idle`),[r,i]=K(null),a=B(null),o=B(null),s=B(null),c=B(!0),l=Ge(),u=I(),d=Xe(),f=Qe(()=>{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=Qe(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=Qe(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 En=0;function Q(){return++En}function Dn(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function On(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 kn(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 An(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 jn({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: ${Dn(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=Qe(()=>{f.current?.focus()},[]),h=et({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: ${Dn(e)}`}]),s(``);return}if(n===`help`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...On(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`context`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...An(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`examples`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...kn(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: ${Dn(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 Mn({deviceId:e,intercomAvailable:t=!1}){let n=X(),r=typeof window<`u`?window.location.origin:``,i=Number.isFinite(e),a=wn(i?e:null),{streams:o,pipelineMetrics:s,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h}=Te(n.trpcClient,i?e:null),g=te(n.trpcClient,i?e:null),_=Tn(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=mt(),S=w(),C=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,T=x.length>0?q(W,{children:x.map(e=>q(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return q(Je,{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:C,...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:T,chromeless:!0,className:`h-full`})}function Nn({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full`,children:q(xe,{...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 Pn({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(jn,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function Fn({deviceId:e}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:q(z,{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 In({deviceId:e}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:q(be,{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.`]})}var Ln={"no-provider":`Not available — nothing in this installation provides it.`,"source-unreachable":`Unknown — the service that owns this did not answer.`,"not-configured":`Nothing set up yet — configure it first (Image → Privacy Mask).`};function Rn({deviceId:e}){let t=G(),{data:n,isLoading:r,error:i}=T({deviceId:e},{enabled:Number.isFinite(e)});en([`pipelineOrchestrator`,`getCameraSwitches`],[`capability.binding-changed`]);let a=[[`pipelineOrchestrator`,`getCameraSwitches`],{input:{deviceId:e}}],o=v({onMutate:async e=>{await t.cancelQueries({queryKey:a});let n=t.getQueryData(a);return n!==void 0&&t.setQueryData(a,{...n,switches:n.switches.map(t=>t.id===e.switchId&&t.available?{...t,enabled:e.enabled}:t)}),{previous:n}},onError:(e,n,r)=>{r?.previous!==void 0&&t.setQueryData(a,r.previous)},onSuccess:e=>{t.setQueryData(a,e),t.invalidateQueries({queryKey:[[`deviceManager`]]}),t.invalidateQueries({queryKey:[[`recording`]]})}});return r?H(`div`,{className:`flex items-center gap-2 text-xs text-muted`,children:[q(Nt,{className:`h-3 w-3 animate-spin`}),` Loading camera functions…`]}):i||!n?H(`div`,{className:`flex items-start gap-2 rounded-lg border border-border p-3 text-xs text-muted`,children:[q(Yt,{className:`mt-0.5 h-3 w-3 shrink-0`}),q(`span`,{children:`Camera functions could not be read. Nothing has changed — the switches are not shown rather than shown with a guessed state.`})]}):q(`div`,{className:`flex flex-col gap-2`,children:n.switches.map(t=>q(zn,{row:t,busy:o.isPending&&o.variables?.switchId===t.id,onToggle:n=>o.mutate({deviceId:e,switchId:t.id,enabled:n})},t.id))})}function zn({row:e,busy:t,onToggle:n}){let r=e.available&&!e.enabled;return H(`div`,{className:`rounded-lg border p-3 ${r?`border-warning/50 bg-warning/5`:`border-border`}`,children:[H(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[H(`div`,{className:`flex items-center gap-2`,children:[q(`span`,{className:`text-sm font-medium`,children:e.label}),r?q(`span`,{className:`rounded bg-warning/20 px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-warning`,children:`Off`}):null]}),e.available?q(`button`,{type:`button`,disabled:t,onClick:()=>n(!e.enabled),className:`shrink-0 rounded border border-border px-2 py-1 text-xs disabled:opacity-50`,children:e.enabled?`Turn off`:`Turn on`}):q(`span`,{className:`shrink-0 text-[11px] text-muted`,children:e.unavailableReason?Ln[e.unavailableReason]:`Not available.`})]}),q(`p`,{className:`mt-1.5 text-xs leading-snug text-muted`,children:e.costWhenOff})]})}function Bn({deviceId:e}){let t=G(),n=Number.isFinite(e),{data:r}=c({deviceId:e},{enabled:n}),i=typeof r?.type==`string`?r.type:`camera`;en([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:a,isLoading:o,isError:s,error:l}=Ke({deviceId:e},{enabled:n}),{data:u}=C({deviceType:i},{enabled:!!i}),d=p({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(s)return H(`div`,{className:`p-4 text-xs text-red-400`,children:[`Failed to load bindings: `,l instanceof Error?l.message:String(l)]});let f=new Map,m={};for(let e of u??[])m[e.capName]=e.wrappers;for(let e of a?.entries??[])f.set(e.capName,{...e,wrappers:m[e.capName]??[]});for(let e of u??[])f.has(e.capName)||f.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let h=[...f.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(vt,{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:[i===`camera`?H(`section`,{className:`flex flex-col gap-2`,children:[q(`h3`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Camera functions`}),q(Rn,{deviceId:e})]}):null,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(Ye,{columns:[{key:`capability`,header:`Capability`,render:e=>q(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>q(Vn,{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(Hn,{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(Un,{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 Vn({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(jt,{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(Ct,{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(cn,{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(St,{className:`h-3 w-3`}),`unbound`]})}function Hn({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 Un({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?Qt:yt,{className:`h-3 w-3`}),e]},e)})})}function Wn({deviceId:e,activeSubTab:t,onSubTabChange:n}){return q(`div`,{className:`flex flex-col gap-3`,children:q(an,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}V();var Gn=new Set([`package-detection`]);function Kn(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 qn(e){return e?e.modelId!==void 0||e.settings!==void 0:!1}function Jn({deviceId:e,refreshToken:t}){let n=G(),r=X().trpcClient,[i,a]=K(null),[o,c]=K(null),[l,u]=K(null),d=A({deviceId:e},{refetchOnMount:`always`}),p=s({deviceId:e},{refetchOnMount:`always`}),m=ee(void 0,{refetchOnMount:`always`});en([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let h=ce(void 0,{refetchOnMount:`always`}),g=U(()=>{let e=new Set;for(let t of h.data??[])t.isOnline&&e.add(t.id);return e},[h.data]),_=U(()=>(m.data??[]).filter(e=>g.has(e.nodeId)).map(e=>e.nodeId),[m.data,g]),v=_[0]??``,y=Se({nodeId:v},{enabled:v!==``,refetchOnMount:`always`}),b=$e({enabled:_.length>0,queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`],`device-step`,_.join(`,`),t],queryFn:async()=>{let e={};for(let t of _)try{e[t]=(await r.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:t})).devices}catch{e[t]=[]}return e}}),x=()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]})},S=P({onSuccess:x}),C=f({onSuccess:x}),w=U(()=>y.data?me(y.data):[],[y.data]),T=U(()=>{let e=m.data??[],t=g.size===0?[]:e.filter(e=>g.has(e.nodeId)),n=[];for(let e of t){let t=(b.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:wt(r).label});else n.push({agentNodeId:e.nodeId,engineLabel:t[0]?.format??`(engine unknown)`})}return n},[m.data,b.data,g]),E=(e,t)=>b.data?.[e]?.find(e=>e.key===t)??null,D=e=>{if(e.deviceKey!==void 0)return e.deviceKey;let t=b.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},O=(e,t,n)=>p.data?.[e]?.[t]?.[n]??null,te=e=>{if(Gn.has(e))return{kind:`zone-driven`};let t=Kn(y.data??null,e)?.enabledByDefault??!0,n=d.data?.stepToggles?.[e];return{kind:`gate`,effectiveOn:n??t,defaultOn:t,explicit:n!==void 0}},ne=(e,t)=>{let n=Kn(y.data??null,e);if(n)return de(n,t)},re=(e,t)=>{let n=te(e),r=n.kind===`gate`?n.effectiveOn:!1,i=Kn(y.data??null,e),a=D(t),o=a===null?null:E(t.agentNodeId,a);if(!pe(i?.models??[],o?.format))return r?{kind:`skip`}:{kind:`na`};let s=a===null?null:O(t.agentNodeId,a,e),c=o?.steps?.[e];return{kind:`enabled`,modelId:(i?ue({catalog:i,device:o,override:s?.modelId,base:c?.modelId}):void 0)??`Auto`,overridden:qn(s)}},k=i&&y.data?Kn(y.data,i.addonId):null,j=i?E(i.agentNodeId,i.deviceKey):null,ie=j?.format??`coreml`,ae=i?qn(O(i.agentNodeId,i.deviceKey,i.addonId)):!1,oe=i?ne(i.addonId,j):void 0,M=U(()=>{if(!i||!j)return null;let e=j.steps?.[i.addonId];return{enabled:!0,...e?.modelId===void 0?{}:{modelId:e.modelId},settings:e?.settings??{}}},[i,j]),N=()=>{a(null),c(null)},se=(e,t)=>{let n=D(t);n!==null&&(a({addonId:e,agentNodeId:t.agentNodeId,deviceKey:n}),c(O(t.agentNodeId,n,e)))},le=(t,n)=>{C.mutate({deviceId:e,addonId:t,enabled:n})},F=()=>{i&&S.mutate({deviceId:e,agentNodeId:i.agentNodeId,deviceKey:i.deviceKey,addonId:i.addonId,patch:o},{onSuccess:N})},fe=()=>{i&&S.mutate({deviceId:e,agentNodeId:i.agentNodeId,deviceKey:i.deviceKey,addonId:i.addonId,patch:null},{onSuccess:N})};if(m.isLoading||v!==``&&y.isLoading)return q(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(T.length===0)return q(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`No online agents.`});if(!y.data)return q(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let I=i!==null&&k!==null&&j!==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:I?`md:pr-[360px]`:``,children:w.length>0?q(Ae,{tree:w,agents:T,gateFor:te,getCellState:re,onCellClick:se,selectedCell:i,onSetGate:le,gateBusy:C.isPending,fallbackNodeId:l,onFallbackNodeChange:u}):q(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),q(We,{open:I,onClose:N,title:k?.name??``,subtitle:i&&j?`${i.agentNodeId} · ${wt(j).label} · ${j.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:!ae||S.isPending,onClick:fe,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:N,children:`Cancel`}),q(`button`,{type:`button`,disabled:!i||!M||S.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:F,children:S.isPending?`Saving…`:`Save`})]}),children:k&&i&&M?q(we,{mode:`device`,addon:k,agentDefault:M,agentNodeId:i.agentNodeId,currentPatch:o,engineFormat:ie,effectiveModelId:oe,onChangePatch:c}):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 Yn=[{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`}],Xn={"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 Zn(e){return Xn[e]??`object-detection`}V();var Qn=`steps`,$n=`settings`,er=new Set([Qn,$n]);function tr(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}function nr({deviceId:e,activeSubTab:t,onSubTabChange:n}){return H(re,{value:t&&er.has(t)?t:Qn,onValueChange:Qe(e=>{n?.(e)},[n]),className:`flex flex-col`,children:[H(qe,{className:`flex-shrink-0`,children:[q(j,{value:Qn,children:`Steps`}),q(j,{value:$n,children:`Settings`})]}),q(a,{value:Qn,children:q(Jn,{deviceId:e,refreshToken:0})}),q(a,{value:$n,children:q(an,{deviceId:e,sectionFilter:tr,subTabGrouping:{groupOf:e=>Zn(e.id),tabs:Yn}})})]})}function $({label:e,value:t}){return H(`div`,{className:`${pt} 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 rr({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(Qt,{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(Kt,{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(Dt,{className:`h-3.5 w-3.5`})})]})})}V();function ir({deviceId:e,initialLocation:t}){let n=G(),[r,i]=K(!1),[a,o]=K(t??``),[s,c]=K(!1),l=B(null),{data:u}=O(void 0,{enabled:r}),d=u??[];J(()=>{r||o(t??``)},[t,r]),J(()=>{r&&l.current?.focus()},[r]);let f=M({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(Qt,{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(Kt,{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(Et,{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(Dt,{className:`h-3.5 w-3.5`})})]})})}V();function ar({deviceId:e}){let t=G(),{data:n}=xt(e),{data:r}=Tt(e),[i,a]=K(null),o=oe({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=ge(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(m,{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 or=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function sr(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function cr(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function lr(){let e=D(),t=d(),{data:n}=c({deviceId:e??0},{enabled:e!==null}),{data:r}=Ke({deviceId:e??0},{enabled:e!==null}),i=n??t??null,[a,o]=K(`identity`);if(e===null||!i)return null;let s=String(i.stableId??``),l=String(i.name??``),u=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(ur,{active:a===`identity`,onClick:()=>o(`identity`),label:`Identity`}),q(ur,{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:[`(`,s,`)`]})]})}),q(rr,{deviceId:e,initialName:l}),q(ir,{deviceId:e,initialLocation:_}),q(ar,{deviceId:e}),q($,{label:`Type`,value:u}),q($,{label:`Provider`,value:q(bt,{type:f,size:`sm`,showLabel:!0})}),q($,{label:`Capabilities`,value:g.length>0?q(_t,{capabilities:g,showLabels:!0}):q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),y&&a===`hardware`&&q(dr,{metadata:v})]})}function ur({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 dr({metadata:e}){let t=or.filter(t=>t in e),n=Object.keys(e).filter(e=>!or.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:sr(t),value:q(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:cr(e[t])})},t))})]})}V();function fr({deviceId:e}){let[t,n]=K(null),r=Ce({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(kt,{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 pr={icon:``,label:``,unit:``,precision:``,hidden:!1};function mr(e){return{icon:e?.icon??``,label:e?.label??``,unit:e?.unit??``,precision:e?.precision===void 0?``:String(e.precision),hidden:e?.hidden===!0}}function hr(e){if(typeof e!=`object`||!e)return;let t=e.unit;return typeof t==`string`?t:void 0}function gr(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 _r({deviceId:e}){let r=X(),i=G(),{data:a}=c({deviceId:e},{enabled:e>0}),o=typeof a?.role==`string`?a.role:null,s=o===null?void 0:Be[o],l=s?.kind===`numeric`,u=je(r.trpcClient,e,o??``),d=s?.kind===`numeric`?s.canonicalUnit:void 0,f=hr(u)??d,p=f===void 0?void 0:lt(f),m=U(()=>p===void 0?[]:st(p),[p]),[h,g]=K(null),_=h??mr(a?.display),v=n({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),{data:y}=t({},{staleTime:6e4}),b=se({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}});if(a===void 0||o===null)return null;let x=e=>{g({..._,...e})},S=()=>{v.mutate({deviceId:e,display:gr(_)})},C=()=>{g(pr),v.mutate({deviceId:e,display:null})},w=()=>{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})},T=ze(o).label,E=Object.keys(Ve);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 (`,T,`)`]}),E.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:T,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:w,disabled:b.isPending,title:`Apply this unit / precision / icon as the default for every ${T} sensor`,children:[`Set as default for all `,T,` sensors`]})]})]})]})}function vr(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function yr({device:e}){let t=Ft(),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(rt.Resyncable),{data:l}=b({deviceId:n??0},{enabled:n!==null&&i,refetchInterval:5e3}),u=l?.streams??{},d=Object.entries(u),f=s.includes(rt.DoorbellButton),p=Le(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(Fe,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),c&&n!==null&&q(fr,{deviceId:n}),i&&n!==null&&q(k,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),f&&q(He,{history:p.history,latestIsFresh:m}),i&&n!==null&&q(k,{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(Mt,{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(br,{label:`Nominal`,value:vr(t.nominalBitrateKbps??0)}),q(br,{label:`Observed`,value:vr(t.observedBitrateKbps??0)}),q(br,{label:`Peak`,value:vr(t.peakBitrateKbps??0)}),q(br,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),q(lr,{}),o&&n!==null&&q(_r,{deviceId:n})]})}function br({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 xr(e,t){if(t===`number`){let t=Number(e);return Number.isNaN(t)?e:t}return t===`boolean`?e===`true`:e}function Sr(e,t){let n={};for(let r of e)r.key!==``&&r.value!==``&&(n[r.key]=xr(r.value,t));return n}function Cr(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 wr(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 Tr(e){return e==null?`identity`:e.kind}function Er({value:e,onChange:t,sourceField:n,targetKind:r}){let[i,a]=K(()=>Tr(e)),[o,s]=K(()=>Cr(e,n)),[c,l]=K(()=>e?.kind===`enum-map`&&e.fallback!=null?String(e.fallback):``),[u,d]=K(()=>wr(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=Sr(o,r),n=c===``?void 0:xr(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(Cr(void 0,n)),e===`linear`&&d(wr(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 Dr=`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 Or({mode:e,idPrefix:t,labelPrefix:n,pickerDevices:r,value:i,onChange:a,search:o,onSearchChange:s}){let{data:c}=De({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:Dr})]}),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:Dr,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:Dr,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:Dr,children:[q(`option`,{value:``,children:`— select a field —`}),u.map(e=>H(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]})}function kr(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 Ar(e){return e===null?`null`:typeof e==`number`?`number`:typeof e==`boolean`?`boolean`:`string`}function jr(e){return e===null?``:String(e)}V();var Mr=`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`,Nr=`min, max, abs, round, floor, ceil, sqrt, pow, clamp, avg, sum, coalesce, age, convert`,Pr=0;function Fr(){return Pr+=1,`b${Pr}`}function Ir(e){return{key:Fr(),name:e,mode:`sibling`,sourceId:null,cap:``,fieldPath:``,search:``,literalType:`number`,literalText:``,sampleText:``}}function Lr(e,t,n){if(e===null)return[Ir(`a`)];let r=[];for(let[i,a]of Object.entries(e.bindings)){if(a.kind===`literal`){r.push({...Ir(i),mode:`literal`,literalType:Ar(a.value),literalText:jr(a.value)});continue}if(a.kind===`global`){r.push({...Ir(i),mode:`global`,sourceId:t.find(e=>e.stableId===a.sourceStableId)?.id??null,cap:a.cap,fieldPath:a.fieldPath});continue}r.push({...Ir(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:[Ir(`a`)]}function Rr(e,t,n){if(e.mode===`literal`){let t=kr(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 zr(e){if(e.mode===`literal`)return kr(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 Br({devices:e,siblings:t,targetDeviceId:n,containerStableId:r,initial:i,onChange:a}){let[o,s]=K(i?.expr??``),[c,l]=K(()=>Lr(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=Rr(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(()=>at({expr:u.source.expr,bindings:u.source.bindings}),[u.source]),f=U(()=>{if(o.trim()===``)return null;let e=dt(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]=zr(t))}return nt(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`:ut.test(t)?it.has(t)?`reserved`:tt.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,Ir(Vr(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(Hr,{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:`${Mr} font-mono resize-y`}),H(`p`,{className:`mt-1 text-[10px] text-foreground-subtle/60`,children:[`Functions: `,Nr]}),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 Vr(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 Hr({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:`${Mr} 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:`${Mr} 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:`${Mr} 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:Mr})]}):H(W,{children:[q(Or,{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:`${Mr} text-[10px]`})]})]})}V();function Ur(e,t,n){return(n===void 0?[e,t]:[e,n,t]).map(e=>e.replace(/[^a-z0-9]/gi,`-`)).join(`-`)}function Wr(e,t,n){let r=`${t}-${e}`;return n.find(e=>e.stableId===r)?.id??null}function Gr(e,t){return t.find(t=>t.stableId===e)?.id??null}function Kr(e){return e==null?`sibling`:e.source.kind===`literal`?`literal`:e.source.kind===`global`?`global`:e.source.kind===`expression`?`expression`:`sibling`}function qr(e){return e==null||e.source.kind!==`literal`?`string`:Ar(e.source.value)}function Jr(e){return e==null||e.source.kind!==`literal`?``:jr(e.source.value)}function Yr({deviceId:e,parentDeviceId:t,deviceStableId:n,initial:r,onSave:i,onCancel:a}){let{data:o}=x({}),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}=De({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:Gr(p.sourceStableId,s):Wr(f.sourceKey,c,s),[g,_]=K(Kr(r)),[v,y]=K(r?.target.cap??``),[b,S]=K(r?.target.fieldPath??``),[C,w]=K(r?.target.itemKey??``),[T,E]=K(h),[D,ee]=K((f??p)?.cap??``),[O,te]=K((f??p)?.fieldPath??``),[ne,re]=K(void 0),[k,A]=K(``),[j,ie]=K(qr(r)),[ae,oe]=K(Jr(r)),[M,N]=K(m),[P,se]=K(r?.transform);J(()=>{if((f??p)==null||T!==null||s.length===0)return;let e=f==null?p==null?null:Gr(p.sourceStableId,s):Wr(f.sourceKey,c,s);e!==null&&E(e)},[f,p,T,s,c]);let ce=d.find(e=>e.cap===v)?.fields??[],le=ce.find(e=>e.path===b),ue=le?.item===!0,F=k.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(``),w(``)},me=e=>{e!==`sibling`&&e!==`global`&&e!==`literal`&&e!==`expression`||(_(e),E(null),ee(``),te(``),re(void 0),A(``))},I=kr(j,ae),L=g===`literal`?I!==null:g===`expression`?M!==null:T!=null&&D!==``&&O!==``,he=v!==``&&b!==``&&(!ue||C.trim()!==``)&&L,ge=()=>{if(g===`literal`)return I===null?null:{kind:`literal`,value:I.value};if(g===`expression`)return M;let e=s.find(e=>e.id===T);if(!e||D===``||O===``)return null;if(g===`global`)return{kind:`global`,sourceStableId:e.stableId,cap:D,fieldPath:O};let t=`${c}-`;return{sourceKey:e.stableId.startsWith(t)?e.stableId.slice(t.length):``,cap:D,fieldPath:O}},_e=()=>{if(!he)return;let e=ge();if(e===null)return;let t=ue?C.trim():void 0;i({id:r?.id??Ur(v,b,t),source:e,target:{cap:v,fieldPath:b,...t===void 0?{}:{itemKey:t}},...P==null?{}:{transform:P}})},R=`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:R,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:b,disabled:v===``,onChange:e=>S(e.target.value),className:R,children:[q(`option`,{value:``,children:`— select a field —`}),ce.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=>w(e.target.value),className:R}),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:R,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:j,onChange:e=>{let t=e.target.value;(t===`string`||t===`number`||t===`boolean`||t===`null`)&&(ie(t),t===`boolean`&&oe(`true`),t===`null`&&oe(``))},className:R,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`})]})]}),j!==`null`&&(j===`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:ae,onChange:e=>oe(e.target.value),className:R,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:ae,placeholder:j===`number`?`e.g. 42`:`e.g. main-brush`,onChange:e=>oe(e.target.value),className:R})]}))]}),g===`expression`&&q(Br,{devices:s,siblings:l,targetDeviceId:e,containerStableId:c,initial:m,onChange:N}),(g===`sibling`||g===`global`)&&q(Or,{mode:g,idPrefix:`link-source`,labelPrefix:`Source`,pickerDevices:fe,value:{sourceId:T,cap:D,fieldPath:O},onChange:(e,t)=>{E(e.sourceId),ee(e.cap),te(e.fieldPath),re(t)},search:k,onSearchChange:A})]}),q(Er,{value:P,onChange:se,sourceField:g===`literal`||g===`expression`?void 0:ne,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:!he,onClick:_e,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 Xr({deviceId:e}){let t=X(),n=G(),r=Number.isFinite(e),{data:i,isLoading:a}=c({deviceId:e},{enabled:r,refetchInterval:1e4}),{data:o}=De({deviceId:e,includeSynthesizable:!0},{enabled:r}),s=new Map;for(let e of o?.caps??[])e.itemArray&&s.set(e.cap,e.itemArray);let l=Ze({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(Ot,{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(sn,{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(Qr,{deviceId:e,link:n,itemArray:s.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(Yr,{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 Zr(e,t,n,r){let i=ct(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:ct(a,r)}function Qr({deviceId:e,link:t,itemArray:n,trpcClient:r,onDelete:i,onEdit:a,isPending:o}){let s=je(r,e,t.target.cap),c=t.target.itemKey,l=s===void 0?void 0:c!==void 0&&n!==void 0?Zr(s,n,c,t.target.fieldPath):c===void 0?ct(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(cn,{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($r,{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 $r({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 ei=[{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 ti(e){let t=e===Y.Camera;return ei.filter(e=>t||!e.cameraOnly).map(({id:e,label:t})=>({id:e,label:t}))}var ni=[{id:`logs`,icon:Gt,label:`Logs`},{id:`repl`,icon:qt,label:`REPL`},{id:`events`,icon:zt,label:`Events`},{id:`state`,icon:Lt,label:`State`}];function ri(){let t=Ht(),n=Number(t.deviceId),a=Number.isFinite(n),s=Ft(),d=G(),f=he(),p=X(),[m,h]=Vt(),g=m.get(`tab`)??`overview`,_=m.get(`sub`),[v,b]=K(`logs`),x=`device-detail.left-col-width-px`,[C,w]=K(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(x),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),T=B(C);T.current=C;function D(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??C??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{w(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(x,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:ee,isLoading:O,isError:te}=c({deviceId:n},{enabled:a,refetchInterval:5e3,retry:1}),{data:re}=E({deviceId:n},{enabled:a}),k=U(()=>{let e=re?.settings?.sections??[],t=re?.live?.sections??[],n=[...e,...t],r=new Set;for(let e of n)e.location===`top-tab`&&e.tab&&r.add(e.tab===`zones`?`detection-pipeline`:e.tab);return n.some(tn)&&r.add(nn),[...r].map(e=>e===`export`?{id:e,label:rn,isAddonContrib:!0}:{id:e,label:ot[e]?.label??e,isAddonContrib:!0})},[re]),A=ee,j=String(A?.name??t.deviceId??`Device`),ae=A?.online===!0,oe=ae?`online`:`offline`,M=String(A?.addonId??`rtsp`),N=A?.features??[],P=A?.type,se=P===Y.Camera,{data:ce}=Tt(a?n:0),le=P===Y.Container,ue=U(()=>(ce??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[ce]),F=U(()=>le?ge(ue,typeof A?.linkDeviceId==`number`?A.linkDeviceId:null,typeof A?.primaryChildEntityId==`string`?A.primaryChildEntityId:null)?.id??null:null,[le,ue,A?.linkDeviceId,A?.primaryChildEntityId]),{data:de}=E({deviceId:F??0},{enabled:F!==null}),pe=U(()=>{if(F===null)return[];let e=de?.settings?.sections??[],t=de?.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:ot[e]?.label??e,isAddonContrib:!0,childDeviceId:F}))},[F,de]),me=typeof A?.parentDeviceId==`number`?A.parentDeviceId:null,{data:I}=c({deviceId:me??0},{enabled:me!==null}),L=l(),R=A?.disabled!==!0,{data:ye}=De({deviceId:n},{enabled:a}),be=(ye?.caps.length??0)>0,xe=U(()=>{let e=new Set,t=[];for(let n of[...ti(P),...k,...pe])e.has(n.id)||(e.add(n.id),!(n.id===`wiring`&&!be)&&t.push(n));return t},[P,k,pe,be]),Se=U(()=>xe.some(e=>e.id===g)?g:`overview`,[xe,g]),Ce=Qe(e=>{h(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[h]),we=Qe(e=>{h(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[h]),Te=(ce??[]).length>0,ke=U(()=>ni.filter(({featureGate:e})=>!e||N.includes(e)),[N]),{data:z}=ve({addonId:M},{enabled:!!M&&M!==`rtsp`}),Ae=y({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]}),s(z?.id?`/integrations/${z.id}`:`/integrations`)}}),je=i({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Me=Ue({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Pe=Ie(),Fe=ie({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Le=N.includes(rt.Rebootable),Re=N.includes(rt.BatteryOperated),ze=e(p.trpcClient,Re&&a?n:null),[Be,Ve]=K(!1),He=ft(p.trpcClient,a?n:null),We=async()=>{if(!(Be||!He)){Ve(!0);try{await He.snapshot?.invalidateCache({});let e=await He.snapshot?.getSnapshot({});if(!e)return;let t=`data:${e.contentType};base64,${e.base64}`,n=e.contentType.includes(`png`)?`png`:`jpg`,r=j.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{Ve(!1)}}},Ge=je.isPending||Me.isPending,{data:Ke}=Ee({deviceId:n},{enabled:a,refetchInterval:1e4}),qe=Ke?.agentNodeId??null,Je=typeof qe==`string`&&qe.length>0&&!qe.startsWith(`addon:`)?qe:void 0,{data:Ye}=ne({deviceId:n,...Je?{nodeId:Je}:{}},{enabled:a,refetchInterval:3e3,retry:!1}),{data:Xe}=r({deviceId:n},{enabled:a,refetchInterval:3e3,retry:!1}),Ze=Xe?.level?.dbfs??null;function V(){if(!a)return null;switch(Se){case`overview`:return q(yr,{device:A??{}});case`config`:return q(Wn,{deviceId:n,activeSubTab:_,onSubTabChange:we});case`detection-pipeline`:return q(nr,{deviceId:n,activeSubTab:_,onSubTabChange:we});case`bindings`:return q(Bn,{deviceId:n});case`wiring`:return q(Xr,{deviceId:n});default:{let e=Se,t=k.some(t=>t.id===e),r=pe.find(t=>t.id===e);if(!t&&r===void 0)return null;let i=r?.childDeviceId??n;if(e===`export`)return q(an,{deviceId:n,sectionFilter:tn,activeSubTab:_,onSubTabChange:we});let a=q(an,{deviceId:i,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:_,onSubTabChange:we});return r!==void 0&&i!==n?q(S,{deviceId:i,children:a}):a}}}return a?O?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`})})]}):te||!ee?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:[`#`,n]})]}),q(`button`,{onClick:()=>s(`/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(_e,{items:[{label:`Integrations`,onClick:()=>s(`/integrations`)},{label:z?.name??M,onClick:()=>z?.id&&s(`/integrations/${z.id}`)},{label:j}]})}),H(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[q(bt,{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:j}),q($t,{status:oe}),Re&&q(fe,{status:ze,variant:`full`})]}),me!==null&&I&&H(`button`,{type:`button`,onClick:()=>s(`/devices/${me}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${I.name}`,children:[q(`span`,{children:`↑`}),q(`span`,{className:`truncate`,children:String(I.name??`Device #${me}`)})]}),q(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:N.length>0&&q(_t,{capabilities:N})})]}),Ye&&q(`div`,{className:`hidden lg:flex`,children:q(ii,{metrics:Ye,dbfs:Ze})}),H(`div`,{className:`flex items-center gap-1 shrink-0`,children:[H(`button`,{onClick:async()=>{R?await f({title:`Disable "${j}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&Me.mutate({deviceId:n}):je.mutate({deviceId:n})},disabled:Ge,title:R?`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 ${R?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[q(ln,{className:`h-3.5 w-3.5`}),q(`span`,{className:`hidden sm:inline`,children:Ge?`Updating…`:R?`Enabled`:`Disabled`})]}),q(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),q(Oe,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:Bt,disabled:Be,onClick:()=>{We()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:At,hidden:!Le,disabled:Pe.isPending,danger:!0,onClick:async()=>{await f({title:`Reboot "${j}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&Pe.mutate({deviceId:n})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${z?.name??M}.`,icon:kt,disabled:Fe.isPending,danger:!0,onClick:async()=>{await f({title:`Restart "${z?.name??M}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${j}"). 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:Wt,separatorBefore:!0,disabled:Ae.isPending,danger:!0,onClick:async()=>{await f({title:`Delete "${j}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&Ae.mutate({deviceId:n})}}]})]})]})]}),q(S,{deviceId:n,device:A??void 0,children:q(o,{children:q(u,{children:q(ht,{children:q(Ne,{children:H(`main`,{className:L?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[H(`div`,{className:L?`flex flex-col bg-surface`:`${C===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!L&&C!==null?{width:`${String(C)}px`}:void 0,children:[q(`div`,{className:se?`flex-shrink-0 border-b border-border-subtle bg-black`:L?`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:se?q(Mn,{deviceId:n,intercomAvailable:N.includes(rt.TwoWayAudio)}):q(Cn,{deviceId:n,deviceName:j,deviceType:P??`unknown`,provider:M,isOnline:ae,features:N})}),H(`div`,{className:L?`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:ke.map(({id:e,label:t,icon:n})=>H(`button`,{onClick:()=>b(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${v===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:L?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[v===`logs`&&q(Nn,{deviceId:n,containerDeviceId:P===`container`?n:void 0}),v===`repl`&&q(Pn,{deviceId:n}),v===`events`&&q(Fn,{deviceId:n}),v===`state`&&q(In,{deviceId:n})]})]})]}),!L&&q(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:D,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:L?`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:L?`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`&&Te&&q(dn,{parentDeviceId:n}),V()]})]})]})})})})})})]}):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:t.deviceId}),` `,`is not a number.`]}),q(`button`,{onClick:()=>s(`/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 ii({metrics:e,dbfs:t}){let n=_(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(Pt,{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(Rt,{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(un,{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{ri as DeviceDetailPage};
@@ -1 +0,0 @@
1
- import{$r as e,B as t,Jr as n,Mn as r,Mo as i,No as a,Pr as o,Uo as s,Xr as c,ei as l,fi as u,fo as d,q as f,ti as p,to as m,ui as h,xt as g,z as _}from"./src-CPanq9UB.js";import{I as v,K as y,Q as b,S as x,W as S,b as C,i as w,o as T,q as E,x as D,z as O}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{E as k,Q as A,z as j}from"./src-EmgPMReM.js";import{p as M}from"./player-overlays-Ba-DoE5F.js";import{t as N}from"./clock-XeL04zsb.js";import{t as P}from"./copy-BtwlORlH.js";import{t as F}from"./image-off-CxrOL9bA.js";import{t as I}from"./search-DOYQxoHy.js";import{t as L}from"./square-check-big-C_0qc0Ud.js";import{t as R}from"./square-CBtc15_U.js";import{C as z,E as B,G as V,I as H,K as U,O as ee,R as W,c as te,i as ne,t as G,z as K}from"./index-CY7HK9zV.js";import{t as q}from"./AdminPage-Dq33XE9j.js";import{a as re,c as ie,d as ae,f as oe,i as se,n as ce,o as le,p as J,r as ue,s as de,t as fe}from"./debounced-invalidate-D3Cu80c9.js";import{r as pe,t as me}from"./authed-media-XfBD4Ma-.js";var he=U(`arrow-down-wide-narrow`,[[`path`,{d:`m3 16 4 4 4-4`,key:`1co6wj`}],[`path`,{d:`M7 20V4`,key:`1yoxec`}],[`path`,{d:`M11 4h10`,key:`1w87gc`}],[`path`,{d:`M11 8h7`,key:`djye34`}],[`path`,{d:`M11 12h4`,key:`q8tih4`}]]),ge=U(`bug`,[[`path`,{d:`m8 2 1.88 1.88`,key:`fmnt4t`}],[`path`,{d:`M14.12 3.88 16 2`,key:`qol33r`}],[`path`,{d:`M9 7.13v-1a3.003 3.003 0 1 1 6 0v1`,key:`d7y7pr`}],[`path`,{d:`M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6`,key:`xs1cw7`}],[`path`,{d:`M12 20v-9`,key:`1qisl0`}],[`path`,{d:`M6.53 9C4.6 8.8 3 7.1 3 5`,key:`32zzws`}],[`path`,{d:`M6 13H2`,key:`82j7cp`}],[`path`,{d:`M3 21c0-2.1 1.7-3.9 3.8-4`,key:`4p0ekp`}],[`path`,{d:`M20.97 5c0 2.1-1.6 3.8-3.5 4`,key:`18gb23`}],[`path`,{d:`M22 13h-4`,key:`1jl80f`}],[`path`,{d:`M17.2 17c2.1.1 3.8 1.9 3.8 4`,key:`k3fwyw`}]]),_e=U(`square-parking`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 17V7h4a3 3 0 0 1 0 6H9`,key:`1dfk2c`}]]),ve=U(`tag`,[[`path`,{d:`M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z`,key:`vktsd0`}],[`circle`,{cx:`7.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`kqv944`}]]);b();function ye(e){return e.subLabel??e.label}var be=720*60*60*1e3;function xe(e){let t=[];for(let n of e)t.push(...n);return t}function Se(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function Ce(e,t){return e.filter(e=>!(e.importance<t.minImportance||t.cameras.size>0&&!t.cameras.has(e.deviceId)||t.classes.size>0&&!t.classes.has(e.className)))}function we(e,t){return`${String(e)}:${t}`}function Te(e,t){let n=new Map,r=new Set;for(let i of e){let e=we(i.deviceId,i.trackId);if(!t.has(e)||r.has(e))continue;r.add(e);let a=n.get(i.deviceId);a?a.push(i.trackId):n.set(i.deviceId,[i.trackId])}return n}function Ee(e,t){return{since:e.fromMs??t-be,until:e.toMs??t}}var Y=typeof n==`function`,De=`Track deletion arrives with the next server update`;function Oe(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var ke=Y?n:Oe,Ae=200,je=3e4;function Me(e){let t=M(),n=w({queries:e.deviceIds.map(n=>({queryKey:[`events-feed`,n,e.since,e.until,e.minImportance??null,e.classFilter??null],staleTime:je,refetchInterval:je,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEvents.query({deviceId:n,since:e.since,until:e.until,limit:Ae,...e.minImportance===void 0?{}:{minImportance:e.minImportance},...e.classFilter===void 0?{}:{classFilter:e.classFilter}})).map(e=>({...e,deviceId:n}))}))});return{rows:Se(xe(n.map(e=>e.data??[])),`importance`),isLoading:n.some(e=>e.isLoading)}}var Ne=[`events-feed`],Pe=2e3;function Fe(e){let t=T(),n=e?.paused===!0,r=y(t);r.current=t;let i=y(n);i.current=n;let[a,o]=E(!1),s=v(()=>{r.current.invalidateQueries({queryKey:Ne})},[]),c=y(void 0);c.current||=fe({delayMs:Pe,invalidate:()=>{i.current?o(!0):s()}}),O(()=>()=>c.current?.cancel(),[]),O(()=>{n||!a||(o(!1),s())},[n,a,s]);let l=v(()=>{o(!1),s()},[s]);return d(A.PipelineAnalyticsDetectionEvent,()=>{c.current?.trigger()}),d(A.PipelineAnalyticsTrackEnded,()=>{c.current?.trigger()}),{pending:a,refreshNow:l}}b();function Ie({groups:e,selected:n,onChange:r,loading:i=!1}){let{t:a}=G(),[o,s]=E(!1),[c,l]=E(``),[u,d]=E(new Set),f=c.trim().toLowerCase(),p=e=>f.length===0||_(e,a).toLowerCase().includes(f),m=S(()=>e.map(e=>({macro:e.macro,subs:e.subs.filter(t=>p(t)||p(e.macro))})).filter(e=>p(e.macro)||e.subs.length>0),[e,f]),h=e=>d(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),g=e=>{let t=new Set(n),i=n.has(e.macro.kind)&&e.subs.every(e=>n.has(e.kind)),a=[e.macro.kind,...e.subs.map(e=>e.kind)];if(i)for(let e of a)t.delete(e);else for(let e of a)t.add(e);r(t)},v=e=>{let t=new Set(n);t.has(e)?t.delete(e):t.add(e),r(t)},y=()=>r(new Set),b=n.size;return x(`div`,{className:`relative`,children:[x(`button`,{type:`button`,onClick:()=>s(e=>!e),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${b>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[D(ve,{className:`h-3.5 w-3.5`}),b>0?`Kinds (${String(b)})`:`Kinds`,D(W,{className:`h-3 w-3`})]}),o&&x(`div`,{className:`absolute z-20 mt-1 max-h-80 w-64 overflow-auto rounded-md border border-border bg-surface p-2 shadow-lg`,children:[x(`div`,{className:`mb-2 flex items-center gap-1 rounded border border-border px-1.5`,children:[D(I,{className:`h-3.5 w-3.5 text-foreground-subtle`}),D(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`Search kinds…`,className:`w-full bg-transparent py-1 text-xs outline-none`}),b>0&&D(`button`,{type:`button`,onClick:y,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),m.length===0&&D(`div`,{className:`px-1 py-2 text-[11px] text-foreground-subtle`,children:i?`Loading kinds…`:f.length>0?`No kind matches that search.`:`These cameras advertise no event kinds.`}),m.map(e=>{let r=t(e.macro.iconId),i=u.has(e.macro.kind)||f.length>0,o=n.has(e.macro.kind);return x(`div`,{className:`mb-0.5`,children:[x(`div`,{className:`flex items-center gap-1`,children:[e.subs.length>0?D(`button`,{type:`button`,onClick:()=>h(e.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Expand`,children:D(i?W:H,{className:`h-3 w-3`})}):D(`span`,{className:`w-3`}),x(`label`,{className:`flex flex-1 cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[D(`input`,{type:`checkbox`,checked:o,onChange:()=>g(e),className:`accent-primary`}),D(r,{className:`h-3.5 w-3.5`,style:{color:e.macro.color}}),D(`span`,{className:`font-medium`,children:_(e.macro,a)})]})]}),i&&e.subs.map(e=>{let r=t(e.iconId);return x(`label`,{className:`ml-5 flex cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[D(`input`,{type:`checkbox`,checked:n.has(e.kind),onChange:()=>v(e.kind),className:`accent-primary`}),D(r,{className:`h-3.5 w-3.5`,style:{color:e.color}}),D(`span`,{children:_(e,a)})]},e.kind)})]},e.macro.kind)})]})]})}function Le(e,t){let n=new Map;for(let r of e)if(!(t.size>0&&!t.has(r.deviceId)))for(let e of r.kinds)n.has(e.kind)||n.set(e.kind,e);return n}function Re(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var ze=new Set([`detection`,`package`]);function Be(e,t){return[...Le(e,t).values()].filter(e=>e.parentKind===null&&ze.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function Ve(e,t){let n=Le(e,t),r=new Map,i=new Map;for(let e of n.values()){if(e.parentKind===null){i.set(e.kind,e);continue}let t=r.get(e.parentKind);t===void 0?r.set(e.parentKind,[e]):t.push(e)}for(let[e,t]of r){if(i.has(e))continue;let n=t[0];n!==void 0&&i.set(e,Re(e,n))}return[...i.values()].map(e=>({macro:e,subs:[...r.get(e.kind)??[]].sort((e,t)=>e.label.localeCompare(t.label))})).sort((e,t)=>e.macro.label.localeCompare(t.macro.label))}b();var He=1400,Ue=`Admin-gated URL — opens only inside an authenticated session`;function We({label:e,value:t,title:n}){let[r,i]=E(!1);return O(()=>{if(!r)return;let e=setTimeout(()=>i(!1),He);return()=>clearTimeout(e)},[r]),x(`button`,{type:`button`,onClick:v(()=>{(async()=>{try{await navigator.clipboard.writeText(t),i(!0)}catch{window.prompt(`Copy the media URL:`,t)}})()},[t]),title:n,"aria-label":`Copy ${e} URL`,className:`flex min-w-0 items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${r?`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:`border-border text-foreground-subtle hover:border-primary hover:text-foreground`}`,children:[D(r?K:P,{className:`h-2.5 w-2.5 shrink-0`}),D(`span`,{className:`truncate`,children:r?`Copied`:e})]})}function Ge({localUrl:e,publicUrl:t}){return x(`div`,{className:`flex flex-wrap gap-1`,children:[D(We,{label:`Local`,value:e,title:`Copy LAN URL — ${Ue}`}),t&&D(We,{label:`Public`,value:t,title:`Copy public URL — ${Ue}`})]})}var Ke={firstFrame:`First frame (track start)`,lastFrame:`Last frame (track end)`,thumbnail:`Best detection`,thumbnailSmall:`Best detection (480)`,snapshot:`Snapshot`,keyFrame:`Key frame (native-res)`,keyFrameSmall:`Key frame (960)`,crop:`Object crop`,fullFrame:`Full frame`,fullFrameBoxed:`Full frame (boxed)`,faceCrop:`Face crop`,plateCrop:`Plate crop`};function qe(e){return e in Ke}function Je(e){return qe(e)?Ke[e]:e}function Ye(e,t){return`${e}${me}/${encodeURIComponent(t)}`}b();var Xe=3e4;function Ze(e){let[t,n]=E(null),r=v(e=>{n(t=>t??e)},[]);return O(()=>{e||n(null)},[e]),{publicOrigin:t,probes:e?D(Qe,{onOrigin:r}):null}}function Qe({onOrigin:e}){let{data:t}=g({capName:`network-access`});return D(C,{children:(t??[]).map(t=>D($e,{addonId:t.addonId,onOrigin:e},t.addonId))})}function $e({addonId:e,onOrigin:t}){let{data:n}=o({addonId:e},{refetchInterval:Xe,retry:!1});return O(()=>{let e=n?k.safeParse(n):null,r=e?.success?e.data.endpoint?.url:void 0;if(r)try{t(new URL(r).origin)}catch{}},[n,t]),null}var et=typeof u==`function`,tt=`Track flags arrive with the next server update`;function nt(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var rt=et?u:nt;function it(e){if(typeof e!=`object`||!e||!(`trackId`in e)||!(`markForTrain`in e)||!(`debug`in e))return null;let{trackId:t,markForTrain:n,debug:r}=e;return typeof t!=`string`||typeof n!=`boolean`||typeof r!=`boolean`?null:{trackId:t,markForTrain:n,debug:r}}b();function at({label:e,hint:t,checked:n,disabled:r,title:i,icon:a,onToggle:o}){return x(`button`,{type:`button`,role:`switch`,"aria-checked":n,"aria-label":e,disabled:r,title:i,onClick:o,className:`flex w-full items-center gap-2 rounded-md border px-2 py-1.5 text-left transition-colors disabled:opacity-50 ${n?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[D(`span`,{className:n?`text-primary`:`text-foreground-subtle`,children:a}),x(`span`,{className:`min-w-0 flex-1`,children:[D(`span`,{className:`block text-[11px] font-medium text-foreground`,children:e}),D(`span`,{className:`block text-[10px] text-foreground-subtle`,children:t})]}),D(`span`,{"aria-hidden":`true`,className:`h-4 w-7 shrink-0 rounded-full p-0.5 transition-colors ${n?`bg-primary`:`bg-border`}`,children:D(`span`,{className:`block h-3 w-3 rounded-full bg-white transition-transform ${n?`translate-x-3`:``}`})})]})}function ot({deviceId:e,trackId:t,markForTrain:n,debug:r,onChange:i}){let a=rt(),[o,s]=E(null),c=o?.markForTrain??n===!0,l=o?.debug??r===!0,u=!et||a.isPending,d=et?void 0:tt,f=n=>{u||(async()=>{try{let r=it(await a.mutateAsync({deviceId:e,trackId:t,flags:n}));if(!r)return;s(r),i?.(r)}catch(e){let t=e instanceof Error?e.message:``;window.alert(t===``?`Could not update this track. Check the server logs.`:`Could not update this track — ${t}`)}})()};return x(`div`,{className:`grid gap-1.5 sm:grid-cols-2`,children:[D(at,{label:`Mark for training`,hint:`Keeps this track and its media past retention`,checked:c,disabled:u,...d===void 0?{}:{title:d},icon:D(B,{className:`h-4 w-4`}),onToggle:()=>f({markForTrain:!c})}),D(at,{label:`Debug`,hint:`Flag this track for diagnostic attention`,checked:l,disabled:u,...d===void 0?{}:{title:d},icon:D(ge,{className:`h-4 w-4`}),onToggle:()=>f({debug:!l})})]})}var X=100,st=120,ct={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Z=e=>e<0?0:e>1?1:e,Q=e=>Math.round(e*100)/100;function lt(e,t){if(e.length<=t)return[...e];let n=(e.length-1)/(t-1),r=[];for(let i=0;i<t;i++)r.push(e[Math.round(i*n)]);return r[r.length-1]=e[e.length-1],r}function ut(e,t,n){if(e.length===0||t===null)return ct;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return ct;let a=lt(e,n?.maxPoints??st).map(e=>({x:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X)})),o=a[0]??null,s=a[a.length-1]??null,c=a.length>=2?a.map(e=>`${e.x},${e.y}`).join(` `):``,l=(n?.snapshots??[]).map(e=>({x:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X),mediaKey:e.mediaKey})),u=null,d=-1;for(let t of e){let e=Z(t.bbox.w/r)*Z(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:Q(Z(u.bbox.x/r)*X),y:Q(Z(u.bbox.y/i)*X),w:Q(Z(u.bbox.w/r)*X),h:Q(Z(u.bbox.h/i)*X)}:null}}b();var dt=15e3,ft=window.location.origin,pt=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),mt=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]);function ht(e){let[t,n]=E(null);return O(()=>{if(n(null),!e)return;let t=!1,r=new Image;return r.onload=()=>{t||n({width:r.naturalWidth,height:r.naturalHeight})},r.src=e,()=>{t=!0,r.onload=null}},[e]),t}function gt({overlay:e,onPickSnapshot:t}){return!e.polyline&&!e.peakBox&&e.snapshots.length===0?null:x(`svg`,{viewBox:`0 0 100 100`,preserveAspectRatio:`none`,className:`pointer-events-none absolute inset-0 h-full w-full`,children:[e.peakBox&&D(`rect`,{x:e.peakBox.x,y:e.peakBox.y,width:e.peakBox.w,height:e.peakBox.h,fill:`none`,stroke:`#f59e0b`,strokeWidth:2,vectorEffect:`non-scaling-stroke`,rx:1}),e.polyline&&D(`polyline`,{points:e.polyline,fill:`none`,stroke:`#38bdf8`,strokeWidth:2,strokeLinejoin:`round`,strokeLinecap:`round`,strokeOpacity:.85,vectorEffect:`non-scaling-stroke`}),e.points.map((e,t)=>D(`circle`,{cx:e.x,cy:e.y,r:1,fill:`#38bdf8`,fillOpacity:.6,vectorEffect:`non-scaling-stroke`},`${String(e.x)}-${String(e.y)}-${String(t)}`)),e.snapshots.map((e,n)=>D(`circle`,{cx:e.x,cy:e.y,r:1.9,fill:`#0ea5e9`,fillOpacity:.95,stroke:`#082f49`,strokeWidth:.7,vectorEffect:`non-scaling-stroke`,className:t?`pointer-events-auto cursor-pointer`:void 0,onClick:t?n=>{n.stopPropagation(),t(e.mediaKey)}:void 0,children:D(`title`,{children:`Snapshot checkpoint — click to view this frame`})},`snap-${e.mediaKey}-${String(n)}`)),e.start&&D(`circle`,{cx:e.start.x,cy:e.start.y,r:2.4,fill:`#22c55e`,stroke:`#052e16`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`}),e.end&&D(`circle`,{cx:e.end.x,cy:e.end.y,r:2.4,fill:`#ef4444`,stroke:`#450a0a`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`})]})}function $({label:e,value:t,mono:n}){return x(`div`,{className:`flex items-baseline justify-between gap-3 border-b border-border/60 py-1.5 last:border-0`,children:[D(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),D(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono text-[11px]`:``}`,title:t,children:t})]})}function _t({row:t,cameraName:n,deleteAvailable:r,onClose:o,onDeleted:u,onFlagsChanged:d}){let f=M(),p=ke(),h=t!==null,g=t?.deviceId??0,_=t?.trackId??``,y=t?.bestEventId??``,b=t?.timestamp??0,w=t?.windowMs??0,{data:T}=e({deviceId:g,trackId:_},{enabled:h}),{data:k}=l({trackId:_},{enabled:h}),{data:A}=c({eventId:y},{enabled:h&&y!==``}),{data:j}=m({deviceId:g,since:b-dt,until:b+w+dt},{enabled:h}),[N,P]=E(null),[I,L]=E(!1),{publicOrigin:R,probes:B}=Ze(h);O(()=>{P(null)},[g,_]);let V=S(()=>{let e=k??[],t=A??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[k,A]),H=pe(V?`${me}/${encodeURIComponent(V.key)}`:void 0),U=S(()=>{let e=new Set,t=[];for(let n of[...A??[],...k??[]])!n.base64||e.has(n.key)||(e.add(n.key),t.push(n));return t},[A,k]),W=S(()=>U.find(e=>pt.has(e.kind))??null,[U]),G=ht(W?`data:image/jpeg;base64,${W.base64}`:null),K=S(()=>ut(T?.positions??[],G,{snapshots:(T?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaKey:e.mediaKey}))}),[T?.positions,T?.snapshots,G]),q=v(e=>{let t=U.find(t=>t.key===e);t&&P(t)},[U]);if(t===null)return null;let re=N?`data:image/jpeg;base64,${N.base64}`:H.src,ie=N?.kind??V?.kind,oe=ie!==void 0&&mt.has(ie)&&G!==null&&(T?.positions.length??0)>=2,ce=j&&j.length>0?j[0]:null,le=()=>{ce&&(L(!0),(async()=>{try{let e=await f.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:ce.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{window.alert(`Could not resolve clip playback. Check the server logs.`)}finally{L(!1)}})())},ue=()=>{!r||p.isPending||window.confirm(`Delete this track and all its media? This cannot be undone.`)&&(async()=>{try{await p.mutateAsync({deviceId:t.deviceId,trackIds:[t.trackId]}),u()}catch{window.alert(`Failed to delete this track. Check the server logs.`)}})()},de=Math.round(t.importance*100),fe=T?.importanceReason?`${String(de)}% · ${T.importanceReason}`:`${String(de)}%`,he=T?.zonesVisited&&T.zonesVisited.length>0?T.zonesVisited.join(`, `):`—`,ge=T?.audioLabels&&T.audioLabels.length>0?T.audioLabels.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `):`—`,_e=T?T.totalDistance.toFixed(2):`—`,ve=J(T?T.firstSeen:b),be=T?J(T.lastSeen):`—`;return D(i,{open:!0,onOpenChange:e=>!e&&o(),children:x(a,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Event detail`,className:`flex h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:h-auto md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[x(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[x(`div`,{className:`min-w-0`,children:[x(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:[t.className,ye(t)?x(`span`,{className:`text-foreground-subtle`,children:[` · `,ye(t)]}):null]}),D(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:n})]}),D(`button`,{type:`button`,onClick:o,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:D(ne,{className:`h-4 w-4`})})]}),x(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[re?D(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:D(se,{src:re,alt:`Key frame from ${n}`,fit:`natural`,className:`w-full`,overlay:oe?D(gt,{overlay:K,onPickSnapshot:q}):void 0})}):D(`div`,{className:`flex aspect-video w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-surface-hover text-foreground-subtle`,children:H.failed?x(C,{children:[D(F,{className:`h-8 w-8 opacity-60`}),D(`span`,{className:`text-[11px]`,children:`Key-frame media unavailable`})]}):D(z,{className:`h-6 w-6 animate-spin opacity-70`})}),U.length>0&&D(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:U.map(e=>{let t=`data:image/jpeg;base64,${e.base64}`,n=Je(e.kind),r=Ye(ft,e.key),i=R?Ye(R,e.key):null;return x(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[D(`button`,{type:`button`,onClick:()=>P(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${n} · ${J(e.timestamp)}`,children:D(`img`,{src:t,alt:n,className:`h-full w-full object-cover`})}),x(`figcaption`,{className:`min-w-0 px-0.5`,children:[D(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:n,children:n}),D(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:J(e.timestamp),children:ae(e.timestamp)})]}),D(Ge,{localUrl:r,publicUrl:i})]},e.key)})}),B,ce&&x(s,{variant:`secondary`,onClick:le,disabled:I,children:[I?D(z,{className:`h-3.5 w-3.5 animate-spin`}):D(ee,{className:`h-3.5 w-3.5`}),` `,`View clip`]}),D(ot,{deviceId:t.deviceId,trackId:t.trackId,...(T?.markForTrain??t.markForTrain)===void 0?{}:{markForTrain:T?.markForTrain??t.markForTrain},...(T?.debug??t.debug)===void 0?{}:{debug:T?.debug??t.debug},onChange:d}),x(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[D($,{label:`Camera`,value:n}),D($,{label:`Class`,value:t.className}),D($,{label:`Label`,value:t.label??`—`}),D($,{label:`Sub-label`,value:t.subLabel??`—`}),D($,{label:`Importance`,value:fe}),D($,{label:`Zones visited`,value:he}),D($,{label:`Audio heard`,value:ge}),D($,{label:`Total distance`,value:_e}),D($,{label:`First seen`,value:ve}),D($,{label:`Last seen`,value:be}),D($,{label:`Track`,value:t.trackId,mono:!0})]})]}),D(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:D(`span`,{title:r?void 0:De,children:x(s,{variant:`secondary`,onClick:ue,disabled:!r||p.isPending,children:[p.isPending?D(z,{className:`h-3.5 w-3.5 animate-spin`}):D(te,{className:`h-3.5 w-3.5`}),` `,`Delete track`]})})})]})})}function vt(e){if(e===void 0||!Number.isFinite(e)||e<=0)return``;let t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return`${String(n)}m ${String(r).padStart(2,`0`)}s`}function yt({row:e,cameraName:t,nowMs:n,onOpenDetail:r,selected:i=!1,onToggleSelect:a,score:o}){let s=pe(e.bestEventId?`${me}/${e.bestEventId}`:void 0),c=Math.round(e.importance*100),l=o===void 0?void 0:Math.round(o*100),u=vt(e.windowMs),d=()=>r(e);return x(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[x(`div`,{className:`aspect-video relative overflow-hidden bg-surface-hover`,children:[s.src?D(`img`,{src:s.src,alt:`Event from ${t}`,onClick:d,className:`h-full w-full cursor-zoom-in object-cover`}):D(`button`,{type:`button`,onClick:d,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-surface-hover text-foreground-subtle`,title:s.failed?`Key-event media unavailable`:`No key-event media`,children:D(F,{className:`h-6 w-6 opacity-60`})}),a&&D(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),a(we(e.deviceId,e.trackId))},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?`Deselect`:`Select`,children:i?D(L,{className:`h-4 w-4 text-primary`}):D(R,{className:`h-4 w-4`})}),l!==void 0&&x(`span`,{className:`absolute left-1 top-1 z-10 rounded bg-primary/85 px-1.5 py-0.5 text-[10px] font-semibold text-white tabular-nums`,title:`CLIP semantic-match score`,children:[String(l),`%`]}),c>0&&D(`span`,{className:`absolute right-1 top-1 z-10 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-semibold text-white`,children:String(c)}),(e.markForTrain===!0||e.debug===!0)&&x(`span`,{className:`absolute bottom-1 left-1 z-10 flex gap-1`,children:[e.markForTrain===!0&&D(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:`Marked for training`,"aria-label":`Marked for training`,children:D(B,{className:`h-3 w-3`})}),e.debug===!0&&D(`span`,{className:`rounded bg-black/70 p-0.5 text-white`,title:`Flagged for debug`,"aria-label":`Flagged for debug`,children:D(ge,{className:`h-3 w-3`})})]})]}),x(`button`,{type:`button`,onClick:d,className:`min-w-0 px-2 py-1.5 text-left space-y-0.5`,children:[x(`p`,{className:`text-[11px] font-medium text-foreground truncate`,title:e.className,children:[e.className,ye(e)?x(`span`,{className:`text-foreground-subtle`,children:[` · `,ye(e)]}):null]}),D(`p`,{className:`text-[10px] text-foreground-subtle truncate`,title:t,children:t}),x(`div`,{className:`flex items-center justify-between gap-2`,children:[D(`span`,{className:`text-[10px] text-foreground-subtle truncate`,children:oe(e.timestamp,n)}),u&&D(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:u})]})]})]})}b();function bt(){let[e,t]=E(!1),n=y(null),[r,i]=E(0),a=v(e=>{n.current!==e&&(n.current=e,i(e=>e+1))},[]);return O(()=>{let e=n.current;if(!e||typeof IntersectionObserver>`u`){t(!1);return}let r=new IntersectionObserver(e=>{let n=e[e.length-1];n&&t(!n.isIntersecting)},{rootMargin:`64px 0px 0px 0px`,threshold:0});return r.observe(e),()=>r.disconnect()},[r]),{ref:a,scrolledPast:e}}b();var xt=[`events-feed`],St=60,Ct=[{value:`importance`,label:`Importance`,icon:he},{value:`time`,label:`Recent`,icon:N}];function wt(){let e=T(),[t,n]=E(de),[i,a]=E(new Set),[o,c]=E(new Set),[l,u]=E(0),[d,f]=E(`time`),[m,h]=E(new Set),[g,_]=E(null),[v,y]=E(()=>Date.now());O(()=>{let e=setInterval(()=>y(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:b,until:w}=S(()=>Ee({fromMs:t.fromMs,toMs:t.toMs},v),[t.fromMs,t.toMs,v]),k=bt(),{pending:A,refreshNow:M}=Fe({paused:g!==null||m.size>0||k.scrolledPast}),{data:N}=r({}),P=S(()=>(N??[]).filter(e=>e.type===j.Camera),[N]),F=S(()=>P.map(e=>e.id),[P]),{data:I,isLoading:L}=p({deviceIds:F},{enabled:F.length>0,staleTime:5*6e4}),R=S(()=>Ve(I??[],i),[I,i]),B=ke(),V=B.isPending,{rows:H,isLoading:U}=Me({deviceIds:F,since:b,until:w,minImportance:l>0?l:void 0,classFilter:o.size===1?[...o][0]:void 0}),ee=S(()=>{let e=new Map;for(let t of P??[])e.set(t.id,t.name);return e},[P]),W=e=>ee.get(e)??`Camera #${String(e)}`,G=S(()=>ie(H).map(e=>({id:e,name:W(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[H,ee]),K=S(()=>Se(Ce(H,{cameras:i,classes:o,minImportance:l}),d),[H,i,o,l,d]),q=ce(K,St,S(()=>JSON.stringify([[...i].sort((e,t)=>e-t),[...o].sort(),l,d,b,w]),[i,o,l,d,b,w])),ae=()=>{e.invalidateQueries({queryKey:xt})},oe=()=>h(new Set);function se(e){h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function J(){if(m.size===0||!Y)return;let e=Te(H,m),t=[...e.values()].reduce((e,t)=>e+t.length,0);if(t===0||!window.confirm(`Delete ${String(t)} track${t===1?``:`s`} and all their media? This cannot be undone.`))return;let n=[...e];Promise.allSettled(n.map(([e,t])=>B.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{ae();let t=[],r=new Set;if(e.forEach((e,i)=>{let a=n[i];if(!a)return;let[o,s]=a;if(e.status===`fulfilled`)for(let e of s)r.add(we(o,e));else t.push(o)}),h(e=>{let t=new Set(e);for(let e of r)t.delete(e);return t}),t.length>0){let e=t.map(e=>W(e)).join(`, `);window.alert(`Failed to delete tracks on: ${e}. They remain selected — retry, or check the server logs.`)}})}let fe=K.length!==H.length;return x(`div`,{className:`relative space-y-3`,children:[x(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[D(re,{onChange:n}),D(le,{cameras:G,selected:i,onChange:a}),D(Ie,{groups:R,selected:o,onChange:c,loading:L}),x(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[D(`span`,{children:`Min score`}),D(`input`,{type:`range`,min:0,max:1,step:.05,value:l,onChange:e=>u(Number(e.target.value)),className:`h-1 w-24 cursor-pointer accent-primary`,"aria-label":`Minimum importance`}),D(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(l*100)})]}),D(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Ct.map(e=>{let t=e.icon;return x(`button`,{type:`button`,onClick:()=>f(e.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${d===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[D(t,{className:`h-3.5 w-3.5`}),` `,e.label]},e.value)})}),!U&&D(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:fe?`${String(K.length)} of ${String(H.length)} events`:`${String(K.length)} event${K.length===1?``:`s`}`})]}),m.size>0&&x(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[x(`span`,{className:`text-xs font-medium text-foreground`,children:[m.size,` selected`]}),x(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[D(`span`,{title:Y?void 0:`Track deletion arrives with the next server update`,children:x(s,{variant:`secondary`,onClick:J,disabled:!Y||V,children:[V?D(z,{className:`h-3.5 w-3.5 animate-spin`}):D(te,{className:`h-3.5 w-3.5`}),` `,`Delete`]})}),D(s,{variant:`ghost`,onClick:oe,disabled:V,children:D(ne,{className:`h-3.5 w-3.5`})})]})]}),U&&x(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[D(z,{className:`h-4 w-4 animate-spin`}),` Loading events…`]}),!U&&K.length===0&&D(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No key events in this window.`}),A&&D(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:D(`button`,{type:`button`,onClick:M,className:`rounded-full border border-primary/40 bg-surface px-3 py-1 text-[11px] font-medium text-primary shadow-sm hover:bg-primary/10`,children:`New events — refresh`})}),!U&&K.length>0&&x(C,{children:[D(`div`,{ref:k.ref,"aria-hidden":!0,className:`h-0`}),D(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:q.pageItems.map(e=>D(yt,{row:e,cameraName:W(e.deviceId),nowMs:v,selected:m.has(we(e.deviceId,e.trackId)),onToggleSelect:se,onOpenDetail:_},we(e.deviceId,e.trackId)))}),D(ue,{currentPage:q.page,totalItems:q.totalItems,pageSize:q.pageSize,onPageChange:q.setPage,itemNoun:`events`})]}),g&&D(_t,{row:g,cameraName:W(g.deviceId),deleteAvailable:Y,onClose:()=>_(null),onDeleted:()=>{ae(),_(null)},onFlagsChanged:e=>{_(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug}:t)}})]})}b();var Tt=50,Et=350,Dt=[{value:.2,label:`Loose`},{value:.25,label:`Balanced`},{value:.3,label:`Strict`}];function Ot(e){return{id:e.id,trackId:e.trackId??e.id,deviceId:e.deviceId,timestamp:e.timestamp,className:e.className,label:e.label,subLabel:e.subLabel,importance:e.importance??0,bestEventId:e.mediaKey??e.trackId??e.id,windowMs:void 0}}function kt({onActiveChange:e}){let[t,n]=E(``),[i,a]=E(.2),[o,s]=E(null),[c,l]=E(null),[u,d]=E(null),m=f(t,Et).trim(),g=m.length>0;O(()=>{e(g)},[g,e]);let[v,y]=E(()=>Date.now());O(()=>{let e=setInterval(()=>y(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:b}=r({}),C=S(()=>(b??[]).filter(e=>e.type===j.Camera),[b]),w=S(()=>{let e=new Map;for(let t of b??[])e.set(t.id,t.name);return e},[b]),T=e=>w.get(e)??`Camera #${String(e)}`,k=S(()=>C.map(e=>e.id),[C]),{data:A}=p({deviceIds:k},{enabled:k.length>0,staleTime:5*6e4}),M=S(()=>Be(A??[],new Set(c===null?[]:[c])),[A,c]);O(()=>{o!==null&&(M.some(e=>e.kind===o)||s(null))},[M,o]);let{data:N,isFetching:P,isError:F,error:L}=h({text:m,minScore:i,limit:Tt,classFilter:o??void 0,deviceId:c??void 0},{enabled:g}),R=S(()=>[...N??[]].sort((e,t)=>t.score-e.score).map(e=>({...Ot(e),score:e.score})),[N]);function B(e){s(t=>t===e?null:e)}return x(`div`,{className:`space-y-3`,children:[x(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-3`,children:[x(`div`,{className:`flex flex-wrap items-center gap-2`,children:[x(`div`,{className:`relative min-w-[16rem] flex-1`,children:[D(I,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),D(`input`,{type:`text`,value:t,onChange:e=>n(e.target.value),placeholder:`Semantic search — describe what you're looking for…`,className:`h-9 w-full rounded-md border border-border bg-background pl-8 pr-8 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary`,"aria-label":`Semantic event search`}),t&&D(`button`,{type:`button`,onClick:()=>n(``),className:`absolute right-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Clear search`,children:D(ne,{className:`h-3.5 w-3.5`})})]}),P&&g&&D(z,{className:`h-4 w-4 shrink-0 animate-spin text-foreground-subtle`})]}),x(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[D(`div`,{className:`flex items-center gap-1`,children:M.map(e=>D(`button`,{type:`button`,onClick:()=>B(e.kind),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${o===e.kind?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:_(e)},e.kind))}),x(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[D(`span`,{children:`Camera`}),x(`select`,{value:c===null?``:String(c),onChange:e=>l(e.target.value===``?null:Number(e.target.value)),className:`h-7 rounded-md border border-border bg-background px-1.5 text-xs text-foreground focus:border-primary focus:outline-none`,"aria-label":`Filter by camera`,children:[D(`option`,{value:``,children:`All`}),C.map(e=>D(`option`,{value:String(e.id),children:e.name},e.id))]})]}),x(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[D(`span`,{children:`Match`}),D(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Dt.map(e=>D(`button`,{type:`button`,onClick:()=>a(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${i===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:`Minimum CLIP score ${e.value.toFixed(2)}`,children:e.label},e.value))})]}),g&&!P&&!F&&x(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[R.length,` match`,R.length===1?``:`es`]})]})]}),g&&x(`div`,{className:`space-y-3`,children:[F&&x(`p`,{className:`py-4 text-xs text-danger`,children:[`Search failed: `,L instanceof Error?L.message:`unknown error`,`. Check that the CLIP embedding step is enabled.`]}),!F&&P&&R.length===0&&x(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[D(z,{className:`h-4 w-4 animate-spin`}),` Searching…`]}),!F&&!P&&R.length===0&&x(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:[`No semantic matches for “`,m,`”. Try a looser match threshold or a different phrasing.`]}),!F&&R.length>0&&D(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:R.map(e=>D(yt,{row:e,cameraName:T(e.deviceId),nowMs:v,score:e.score,onOpenDetail:d},e.id))})]}),u&&D(_t,{row:u,cameraName:T(u.deviceId),deleteAvailable:Y,onClose:()=>d(null),onDeleted:()=>d(null)})]})}var At=15e3;function jt(e){let t=M(),n=w({queries:e.map(e=>({queryKey:[`stationary-objects`,e],staleTime:At,refetchInterval:At,queryFn:async()=>((await t.trpcClient.zoneAnalytics.getCurrentSnapshot.query({deviceId:e}))?.stationaryObjects??[]).map(t=>({...t,deviceId:e}))}))});return{rows:n.flatMap(e=>e.data??[]).toSorted((e,t)=>t.becameStationaryAt-e.becameStationaryAt),isLoading:n.some(e=>e.isLoading)}}b();function Mt(e,t){let n=Math.max(0,Math.round((e-t)/6e4));if(n<1)return`just now`;if(n<60)return`${String(n)}m`;let r=Math.floor(n/60);return`${String(r)}h ${String(n%60)}m`}function Nt({row:e,cameraName:t,nowMs:n}){let r=e.keyFrameMediaKey?.startsWith(`track:`)?e.keyFrameMediaKey.split(`:`)[1]:e.keyFrameMediaKey,i=pe(r?`${me}/${r}`:void 0);return x(`div`,{className:`flex flex-col overflow-hidden rounded-md border border-border bg-surface`,children:[x(`div`,{className:`relative aspect-video overflow-hidden bg-surface-hover`,children:[i.src?D(`img`,{src:i.src,alt:`Parked ${e.className} on ${t}`,className:`h-full w-full object-cover`}):D(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:D(_e,{className:`h-6 w-6`})}),D(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-medium capitalize text-white`,children:e.label??e.className})]}),x(`div`,{className:`flex flex-col gap-0.5 p-1.5`,children:[D(`span`,{className:`truncate text-[11px] text-foreground`,children:t}),x(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`parked `,Mt(n,e.becameStationaryAt)]})]})]})}function Pt(){let[e,t]=E(!1),n=Date.now(),{data:i}=r({}),a=S(()=>(i??[]).filter(e=>e.type===j.Camera),[i]),o=S(()=>a.map(e=>e.id),[a]),s=S(()=>{let e=new Map;for(let t of a)e.set(t.id,t.name);return e},[a]),{rows:c}=jt(o);return c.length===0?null:x(`div`,{className:`rounded-md border border-border bg-surface/40`,children:[x(`button`,{type:`button`,onClick:()=>t(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,children:[D(e?W:H,{className:`h-4 w-4 text-foreground-subtle`}),D(_e,{className:`h-4 w-4 text-foreground-subtle`}),D(`span`,{className:`text-sm font-semibold text-foreground`,children:`Stationary`}),D(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:c.length}),D(`span`,{className:`ml-2 text-[11px] text-foreground-subtle`,children:`Parked objects — kept out of the event feed`})]}),e&&D(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:c.map(e=>D(Nt,{row:e,cameraName:s.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:n},e.id))})]})}b();function Ft(){let[e,t]=E(!1);return D(q,{icon:V,title:`Events`,subtitle:`Every captured key event across all cameras — trajectory, media, and clips.`,children:x(`section`,{className:`space-y-3`,children:[D(kt,{onActiveChange:t}),!e&&D(Pt,{}),!e&&D(wt,{})]})})}export{Ft as EventsPage};
@@ -1 +0,0 @@
1
- import{C as e,kn as t,w as n}from"./src-CPanq9UB.js";import{K as r,Q as i,S as a,W as o,b as s,q as c,x as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as u}from"./refresh-cw-NwlTy6_-.js";import{t as d}from"./search-DOYQxoHy.js";import{C as f,K as p,R as m,i as h,z as g}from"./index-CY7HK9zV.js";var _=p(`map-pin`,[[`path`,{d:`M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0`,key:`1r0f0z`}],[`circle`,{cx:`12`,cy:`10`,r:`3`,key:`ilqhr7`}]]);function v(e){return[e.value,e.label,e.description].filter(e=>typeof e==`string`&&e.length>0).join(` `).toLowerCase()}function y(e,t){let n=t.trim().toLowerCase().split(/\s+/).filter(Boolean);return n.length===0?e:e.filter(e=>{let t=v(e);return n.every(e=>t.includes(e))})}function b(e,t){let n=new Map(e.map(e=>[e.value,e])),r=new Set(t);return{selectedOptions:t.map(e=>n.get(e)??{value:e,label:e}),unselected:e.filter(e=>!r.has(e.value))}}function x(e){return e>=8}i();var S=`flex items-center gap-1.5 rounded-md border border-border bg-background px-2 py-1.5 focus-within:border-primary focus-within:ring-1 focus-within:ring-primary/30`,C=`block text-[11px] font-medium text-foreground mb-1 break-words`,w=`text-[10px] text-foreground-subtle mt-0.5 break-words`;function T({field:e,value:t,onChange:n,disabled:i,translationFn:s}){let u=Array.isArray(t)?t:[],f=i===!0||e.disabled===!0,p=e.maxItems!==void 0&&u.length>=e.maxItems,[_,v]=c(``),[x,T]=c(!1),[E,D]=c(0),O=r(null),k=r(null),{selectedOptions:A}=o(()=>b(e.options,u),[e.options,u]),j=o(()=>y(e.options,_),[e.options,_]),N=t=>{if(!f)if(u.includes(t))n(u.filter(e=>e!==t));else{if(e.maxItems!==void 0&&u.length>=e.maxItems)return;n([...u,t])}},P=e=>{if(e.key===`ArrowDown`)e.preventDefault(),T(!0),D(e=>j.length===0?0:(e+1)%j.length);else if(e.key===`ArrowUp`)e.preventDefault(),T(!0),D(e=>j.length===0?0:(e-1+j.length)%j.length);else if(e.key===`Enter`){e.preventDefault();let t=j[E];t&&N(t.value)}else e.key===`Escape`?T(!1):e.key===`Backspace`&&_===``&&u.length>0&&n(u.slice(0,-1))},F=M(e.label,s),I=M(e.description,s);return a(`div`,{className:`min-w-0`,children:[F!==void 0&&F!==``&&l(`label`,{className:C,children:F}),A.length>0&&l(`div`,{className:`flex flex-wrap gap-1 mb-1.5`,children:A.map(e=>a(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-primary/10 px-1.5 py-0.5 text-[11px] text-primary max-w-full`,children:[l(`span`,{className:`truncate`,children:e.label}),!f&&l(`button`,{type:`button`,className:`shrink-0 hover:text-danger`,"aria-label":`Remove ${e.label}`,onClick:()=>N(e.value),children:l(h,{className:`h-2.5 w-2.5`})})]},e.value))}),a(`div`,{className:S+(f?` opacity-50`:``),children:[l(d,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),l(`input`,{ref:O,type:`text`,role:`combobox`,"aria-expanded":x,"aria-controls":`msel-${e.key}`,className:`min-w-0 flex-1 bg-transparent text-xs text-foreground outline-none placeholder:text-foreground-disabled`,value:_,placeholder:p?`Max ${e.maxItems} selected`:e.placeholder??`Search to add…`,disabled:f,onChange:e=>{v(e.target.value),T(!0),D(0)},onFocus:()=>T(!0),onBlur:()=>{k.current=setTimeout(()=>T(!1),120)},onKeyDown:P}),l(m,{className:`h-3.5 w-3.5 shrink-0 cursor-pointer text-foreground-subtle`,onMouseDown:e=>{e.preventDefault(),k.current&&clearTimeout(k.current),T(e=>!e),O.current?.focus()}})]}),x&&!f&&l(`div`,{id:`msel-${e.key}`,role:`listbox`,className:`mt-1 max-h-56 overflow-y-auto rounded-md border border-border bg-surface shadow-lg`,onMouseDown:e=>{e.preventDefault()},children:j.length===0?a(`div`,{className:`px-2.5 py-2 text-[11px] text-foreground-subtle italic`,children:[`No matches for “`,_,`”`]}):j.map((e,t)=>{let n=u.includes(e.value),r=!n&&p;return a(`button`,{type:`button`,role:`option`,"aria-selected":n,disabled:r,className:[`flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-xs transition-colors`,t===E?`bg-primary/10`:`hover:bg-surface-hover`,r?`opacity-40 cursor-not-allowed`:`cursor-pointer`].join(` `),onMouseEnter:()=>D(t),onClick:()=>N(e.value),children:[l(`span`,{className:[`flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded border`,n?`border-primary bg-primary text-white`:`border-border`].join(` `),children:n&&l(g,{className:`h-2.5 w-2.5`})}),l(`span`,{className:`truncate text-foreground`,children:e.label})]},e.value)})}),I&&l(`p`,{className:w,children:I})]})}function E({deviceId:e,mode:n}){let{data:r,isLoading:i,isFetching:o,isError:s,refetch:c}=t({deviceId:e},{enabled:Number.isFinite(e)}),d=r?.devices??[];return a(`div`,{className:`mt-3 rounded-md border border-border bg-background p-2.5`,children:[a(`div`,{className:`flex items-center justify-between mb-1.5`,children:[a(`span`,{className:`text-[11px] font-medium text-foreground`,children:[`Resolved links`,l(`span`,{className:`ml-1.5 text-[10px] font-normal text-foreground-subtle`,children:(r?.mode??n)===`auto`?`children + same location`:`children + manual list`})]}),a(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:bg-surface-hover disabled:opacity-50`,disabled:o,onClick:()=>void c(),title:`Re-run the resolver`,children:[l(u,{className:`h-3 w-3 ${o?`animate-spin`:``}`}),`Refresh`]})]}),i?a(`div`,{className:`flex items-center gap-1.5 py-1 text-[11px] text-foreground-subtle`,children:[l(f,{className:`h-3 w-3 animate-spin`}),`Resolving…`]}):s?l(`p`,{className:`py-1 text-[11px] text-danger`,children:`Failed to resolve linked devices.`}):d.length===0?l(`p`,{className:`py-1 text-[11px] text-foreground-subtle italic`,children:`No linked devices resolved.`}):l(`div`,{className:`flex flex-wrap gap-1`,children:d.map(e=>a(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border bg-surface px-1.5 py-0.5 text-[11px] text-foreground max-w-full`,title:e.location??void 0,children:[l(`span`,{className:`truncate`,children:e.name}),e.location!==null&&e.location.length>0&&a(`span`,{className:`inline-flex items-center gap-0.5 shrink-0 text-[10px] text-foreground-subtle`,children:[l(_,{className:`h-2.5 w-2.5`}),e.location]})]},e.deviceId))})]})}i();var D=`_linkedDevicesMode`,O=`_linkedDeviceIds`;function k(e){return e.type===`multiselect`}function A({field:t,values:r,onChange:i,disabled:a,translationFn:o,onTestField:s,externalProbe:c,allFields:u,onAction:d}){return k(t)&&x(t.options.length)?n(t,r,u)?l(T,{field:t,value:r[t.key],onChange:e=>i(t.key,e),disabled:a,translationFn:o}):null:l(e,{field:t,values:r,onChange:i,disabled:a,translationFn:o,onTestField:s,externalProbe:c,allFields:u,onAction:d})}function j(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function M(e,t){if(e!==void 0)return t&&j(e)?t(e):e}function N({section:t,values:r,onChange:i,disabled:o,translationFn:u,onTestField:d,probeResults:f,onAction:p,deviceId:m}){let[h,g]=c(t.defaultCollapsed??!1),_=t.style===`accordion`;if(t.fields.reduce((e,i)=>e+ +!!n(i,r,t.fields),0)===0)return null;let v=t.fields.some(e=>`key`in e&&e.key===D),y=r[D]===`manual`?`manual`:`auto`,b=v&&y!==`manual`?t.fields.filter(e=>!(`key`in e&&e.key===O)):t.fields,x=v?1:t.columns??2,S=x===1?`grid-cols-1`:x===3?`grid-cols-1 @[480px]:grid-cols-2 @[880px]:grid-cols-3`:x===4?`grid-cols-1 @[480px]:grid-cols-2 @[1140px]:grid-cols-4`:`grid-cols-1 @[480px]:grid-cols-2`,C=t.fields.length===1&&t.fields[0]?.type===`widget`?t.fields[0]:void 0;return a(`div`,{className:`@container rounded-lg border border-border bg-surface p-3`,style:{containerType:`inline-size`},children:[!(C!==void 0||!t.title&&!t.description)&&a(`div`,{className:[`flex items-center justify-between mb-2`,_?`cursor-pointer`:``].join(` `),onClick:_?()=>g(e=>!e):void 0,children:[a(`div`,{children:[t.title&&l(`h3`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider`,children:M(t.title,u)}),t.description&&l(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:M(t.description,u)})]}),_&&l(`span`,{className:`text-foreground-subtle text-xs ml-2`,children:h?`▸`:`▾`})]}),!h&&(C===void 0?a(s,{children:[l(`div`,{className:`grid ${S} gap-x-3 gap-y-2.5`,children:b.map(e=>l(A,{field:e,values:r,onChange:i,disabled:o,translationFn:u,onTestField:d,externalProbe:f?.[e.key],allFields:t.fields,onAction:p},e.key))}),v&&m!==void 0&&l(E,{deviceId:m,mode:y})]}):l(e,{field:C,values:r,onChange:i,disabled:o,translationFn:u,onTestField:d,externalProbe:f?.[C.key],allFields:t.fields,onAction:p},C.key))]})}function P({schema:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,probeResults:o,onClearProbe:s,onAction:c,deviceId:u}){let d=(e,r)=>{n({...t,[e]:r}),s?.(e)};return l(`div`,{className:`space-y-4`,children:e.sections.map((e,n)=>l(N,{section:e,values:t,onChange:d,disabled:r,translationFn:i,onTestField:a,probeResults:o,onAction:c,deviceId:u},`${e.id}-${n}`))})}export{_ as n,P as t};
@@ -1 +0,0 @@
1
- import{Cn as e,En as t,Fn as n,G as r,K as i,Kn as a,Ln as o,Mn as s,Ro as c,Sn as l,Tt as u,_n as d,bo as f,cr as p,d as m,fn as h,fr as g,g as ee,gr as _,hn as v,it as y,lr as b,mn as x,mr as S,nt as C,pn as te,ur as ne,ut as re,vn as w,x as T}from"./src-CPanq9UB.js";import{I as E,K as ie,Q as D,S as O,W as k,b as A,o as j,q as M,x as N,z as ae}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{z as P}from"./src-EmgPMReM.js";import{p as F}from"./player-overlays-Ba-DoE5F.js";import{t as I}from"./ProviderIcon-DFIIdGww.js";import{t as L}from"./FormBuilder-pSCqn9Pp.js";import{t as R}from"./plus-DrqAQeFJ.js";import{n as z,r as oe,t as se}from"./ScanNetworkModal-DEK5U2cd.js";import{t as ce}from"./refresh-cw-NwlTy6_-.js";import{t as le}from"./rotate-cw-W4djelbj.js";import{t as B}from"./wifi-DiUaWSk8.js";import{A as V,C as H,I as U,J as W,K as G,R as ue,W as de,X as fe,Y as pe,c as me,h as he,i as K,k as ge,m as _e,s as q,t as ve,z as J}from"./index-CY7HK9zV.js";var ye=G(`search-x`,[[`path`,{d:`m13.5 8.5-5 5`,key:`1cs55j`}],[`path`,{d:`m8.5 8.5 5 5`,key:`a8mexj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]);D();function Y(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Y(n.fields));return t}function be(e,t,n){let[r,i]=M(`idle`),[a,o]=M({}),s=k(()=>{let t=[];for(let n of e.sections)t.push(...Y(n.fields));return t},[e]),c=s.length>0&&n!==void 0,l=E(e=>{o(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:r,hasProbeFields:c,probeResults:a,handleTestAll:E(async()=>{if(!n)return;let e=s.filter(e=>{let n=t[e];return n!=null&&String(n).trim()!==``});if(e.length===0)return;i(`testing`);let r={};for(let t of e)r[t]={status:`probing`};o(r);let a=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await n(e,t[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),c={};for(let e of a)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;c[t]={status:n.status===`ok`?`ok`:`error`,result:n}}o(c),i(`idle`)},[n,s,t]),clearProbeResult:l}}D();function xe(e){let t=[];for(let n of e)`required`in n&&n.required===!0&&`key`in n&&n.key&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...xe(n.fields));return t}function Se(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Ce(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Ce(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function we(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function Te({open:e,integrationId:r,addonId:i,onClose:o}){let{t:s}=ve(),c=j(),[l,u]=M({}),[f,p]=M(!1),[m,h]=M(null),[g,_]=M(we),v=n({addonId:i},{enabled:e}),y=v.data?.deviceType??null,b=t({addonId:i,type:y??P.Camera},{enabled:e&&v.isSuccess&&y!==null}),x=b.data??null;ae(()=>{e&&(u(x?Ce(x.sections.flatMap(e=>e.fields)):{}),_(we()),p(!1),h(null))},[e,r,x]);let S=k(()=>({...l,_probeRequestId:g}),[l,g]),C=d({onSuccess:()=>{c.invalidateQueries({queryKey:[[`deviceManager`]]})}}),te=a(),ne=E(async(e,t)=>{p(!0);let n=await te.mutateAsync({addonId:i,type:y??P.Camera,key:e,value:t,formValues:S});return n.status===`ok`&&n.suggestedValues&&u(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Se(e[i])&&!Se(a)&&(r[i]=a,t=!0);return t?r:e}),n},[te,i,S,y]),{testAllStatus:re,hasProbeFields:w,probeResults:T,handleTestAll:ie,clearProbeResult:D}=be(x??{sections:[]},l,ne);async function A(e){h(null);try{await C.mutateAsync({addonId:i,type:y??P.Camera,config:l,integrationId:r}),e?u(x?Ce(x.sections.flatMap(e=>e.fields)):{}):o()}catch(e){h(e instanceof Error?e.message:String(e))}}if(!e)return null;let F=xe((x?.sections??[]).flatMap(e=>e.fields)).filter(e=>Se(l[e])),I=F.length===0,R=v.isLoading||y!==null&&b.isLoading,z=v.isError||v.isSuccess&&y===null||b.isError||b.isSuccess&&x===null;return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[N(`div`,{className:`absolute inset-0 bg-black/60`,onClick:o}),O(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[calc(90dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl`,children:[O(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[N(`h2`,{className:`text-sm font-semibold text-foreground`,children:s(`integrations.addDevice`)}),N(`button`,{onClick:o,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:N(K,{className:`h-4 w-4`})})]}),N(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:R?N(`div`,{className:`flex items-center justify-center py-8`,children:N(H,{className:`h-5 w-5 animate-spin text-primary`})}):z?O(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[N(q,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),O(`div`,{className:`space-y-1`,children:[N(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),O(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,N(`span`,{className:`font-mono`,children:i}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):N(L,{schema:x,values:l,onChange:u,onTestField:ne,probeResults:T,onClearProbe:D})}),!z&&!R&&O(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[O(`button`,{type:`button`,onClick:()=>p(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[O(`span`,{className:`flex items-center gap-2`,children:[N(he,{className:`h-3.5 w-3.5`}),`Test logs`,N(`span`,{className:`font-mono text-[9px] opacity-60`,children:g.slice(0,14)})]}),N(ue,{className:`h-3.5 w-3.5 transition-transform ${f?`rotate-180`:``}`})]}),f&&N(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:N(ee,{addonId:i,requestId:g,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!z&&!R&&(m||F.length>0)&&N(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:O(`div`,{className:`flex items-start gap-2`,children:[N(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),N(`p`,{className:`text-[11px] text-destructive`,children:m||`Required: ${F.join(`, `)}`})]})}),O(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[O(`div`,{className:`flex items-center gap-2`,children:[N(`button`,{onClick:o,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:s(`integrations.cancel`)}),!z&&w&&O(`button`,{type:`button`,onClick:ie,disabled:re===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[re===`testing`?N(H,{className:`h-3.5 w-3.5 animate-spin`}):N(B,{className:`h-3.5 w-3.5`}),`Test All`]})]}),O(`div`,{className:`flex items-center gap-2`,children:[N(`button`,{onClick:()=>A(!0),disabled:z||!I||C.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:s(`integrations.saveAndNew`)}),N(`button`,{onClick:()=>A(!1),disabled:z||!I||C.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:C.isPending?s(`integrations.saving`):s(`integrations.save`)})]})]})]})]})}function X(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}D();var Z=`devices`,Q={id:Z,label:`Devices`,isDefault:!0},Ee=2e4,De=100;function Oe({addonId:e,integrationId:t,onClose:n}){let{t:i}=ve(),[a,o]=M(new Set),[s,c]=M(new Set),[l,u]=M(new Map),[d,f]=M(null),{data:p}=ne(),m=(p??[]).find(t=>t.addonId===e)?.supportsLocationImport??!1,[g,ee]=M(!0),_=te({addonId:e,integrationId:t}).data?.filters,b=_&&_.length>0?_:[Q],[S,re]=M(b.find(e=>e.isDefault)?.id??(b.some(e=>e.id===Z)?Z:b[0].id)),w=S!==Z,T=v(),D=x({addonId:e,integrationId:t,page:1,pageSize:Ee,filter:S}),k=D.refetch,A=T.mutate,j=E(()=>{A({addonId:e,integrationId:t},{onSettled:()=>{k()}})},[A,e,t,k]),P=ie(null);ae(()=>{let n=`${e}::${t}`;P.current===n||D.isLoading||(P.current=n,(D.data?.candidates.length??0)===0&&j())},[e,t,D.isLoading,D.data,j]);let F=T.isPending,I=T.isError?T.error instanceof Error?T.error.message:String(T.error):null,L=D.data?.candidates??[],R=D.isError?D.error instanceof Error?D.error.message:String(D.error):null,z=h(),oe=E(e=>{e.alreadyAdopted||o(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),se=E(e=>{c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),ce=E((e,t)=>{u(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),B=E(e=>{let t={};for(let n of e){let e=l.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[l]),V=E(async()=>{f(null);let r=[...a];if(r.length!==0)try{let i=B(r);await z.mutateAsync({addonId:e,integrationId:t,filter:S,childNativeIds:r,...i?{perCandidate:i}:{},...m?{importLocations:g}:{}}),o(new Set),u(new Map),await k(),n()}catch(e){f(e instanceof Error?e.message:String(e))}},[a,B,z,e,t,S,k,m,g]),U=E(e=>{re(e),o(new Set),c(new Set),u(new Map),f(null)},[]),W=a.size;return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[N(`div`,{className:`absolute inset-0 bg-black/60`,onClick:n}),O(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] rounded-xl border border-border bg-background shadow-2xl`,children:[O(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[O(`div`,{className:`min-w-0`,children:[N(`h2`,{className:`text-sm font-semibold text-foreground`,children:i(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),N(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:i(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),O(`div`,{className:`flex items-center gap-3 shrink-0`,children:[m&&O(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[N(`input`,{type:`checkbox`,checked:g,onChange:e=>ee(e.target.checked),className:`accent-primary`}),i(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),N(`button`,{onClick:n,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:N(K,{className:`h-4 w-4`})})]})]}),O(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(I??R)&&L.length===0&&N(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:O(`div`,{className:`flex items-start gap-2`,children:[N(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),O(`div`,{className:`min-w-0`,children:[N(`p`,{className:`text-xs font-medium text-destructive`,children:i(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),N(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:I??R})]})]})}),b.length>1&&N(ke,{filters:b,activeFilter:S,onSelect:U}),N(`div`,{className:`flex-1 min-h-0`,children:N(r,{mode:`generic`,items:L,pageSize:De,getKey:e=>e.childNativeId,getSearchText:X,getFilterType:e=>e.type,filterOptions:C(),filterLabel:i(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:D.isLoading||F&&L.length===0,searchPlaceholder:i(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(I??R)&&L.length===0?``:i(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:O(`button`,{type:`button`,onClick:j,disabled:F,title:i(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[N(le,{className:`h-3.5 w-3.5 ${F?`animate-spin`:``}`}),i(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:i(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>N(Ae,{candidate:e,expandable:!w,expanded:s.has(e.childNativeId),onToggleExpand:()=>se(e.childNativeId),adoptedLabel:i(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:i(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=y(e.type),n=t.icon;return O(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[N(n,{className:`h-3.5 w-3.5 shrink-0`}),t.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>N(`div`,{className:`flex items-center justify-end`,children:N(`button`,{onClick:()=>oe(e),disabled:e.alreadyAdopted,"aria-label":a.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${a.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:a.has(e.childNativeId)&&N(J,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!w&&s.has(e.childNativeId),renderExpanded:w?void 0:e=>N($,{candidate:e,hiddenChildIds:l.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>ce(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:a.has(e.childNativeId)?`bg-primary/5`:``})})]}),d&&N(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:O(`div`,{className:`flex items-start gap-2`,children:[N(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),N(`p`,{className:`text-[11px] text-destructive`,children:d})]})}),O(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[N(`div`,{}),O(`div`,{className:`flex items-center gap-2`,children:[N(`button`,{onClick:n,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.cancel`,{defaultValue:`Cancel`})}),O(`button`,{onClick:V,disabled:W===0||z.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,children:[z.isPending&&N(H,{className:`h-3.5 w-3.5 animate-spin`}),i(`integrations.addSelected`,{defaultValue:`Add selected`}),W>0?` (${W})`:``]})]})]})]})]})}function ke({filters:e,activeFilter:t,onSelect:n}){return N(`div`,{role:`tablist`,"aria-label":`Discovery granularity`,className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return N(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function Ae({candidate:e,expandable:t,expanded:n,onToggleExpand:r,adoptedLabel:i}){let a=(e.children??[]).length;return O(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&a>0?O(`button`,{type:`button`,onClick:r,"aria-label":n?`Collapse`:`Expand`,"aria-expanded":n,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[N(n?ue:U,{className:`h-3.5 w-3.5`}),a]}):N(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),N(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&N(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:i})]})}function $({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let r=e.children??[];return r.length===0?null:N(`div`,{className:`space-y-1 py-1`,children:r.map(e=>{let r=t.has(e.childNativeId),i=e.capabilities??[];return O(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${r?`opacity-50`:``}`,children:[N(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),i.length>0&&N(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:i.join(`, `)}),N(`button`,{onClick:()=>n(e.childNativeId),"aria-label":r?`Show child`:`Hide child`,title:r?`Show after adopt`:`Hide after adopt`,className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:N(r?V:ge,{className:`h-3 w-3`})})]},e.childNativeId)})})}D();function je({integrationId:e,addonId:t,name:n,kind:r,brokerKind:i,trpc:a,onClose:o}){let{t:s}=ve(),c=j(),l=r===`device-adoption`,{data:u}=g({id:e},{enabled:l}),d=k(()=>{let e=u?.brokerId;return typeof e==`string`?e:null},[u]),f=S();return N(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onClick:o,children:O(`div`,{className:`max-h-[85vh] w-full max-w-md overflow-y-auto rounded-xl border border-border bg-surface p-5 shadow-xl`,onClick:e=>e.stopPropagation(),children:[O(`div`,{className:`mb-3 flex items-center justify-between`,children:[O(`h2`,{className:`text-sm font-semibold text-foreground`,children:[s(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]}),N(`button`,{onClick:o,className:`rounded-md p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":s(`common.close`,{defaultValue:`Close`}),children:N(K,{className:`h-4 w-4`})})]}),l?i?O(`div`,{className:`space-y-3`,children:[N(`p`,{className:`text-[11px] text-foreground-subtle`,children:s(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),d&&O(`p`,{className:`text-[11px] text-foreground`,children:[s(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,N(`span`,{className:`font-mono text-foreground-subtle`,children:d})]}),f.isPending?O(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[N(H,{className:`h-3 w-3 animate-spin`}),s(`integrations.saving`,{defaultValue:`Saving…`})]}):N(z,{kind:i,onResolved:t=>{f.mutate({id:e,settings:{brokerId:t}},{onSuccess:()=>{c.invalidateQueries(),o()}})},onBack:o}),f.isError&&N(`p`,{className:`text-[11px] text-danger`,children:s(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):N(`p`,{className:`text-[11px] text-danger`,children:s(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):N(T,{trpc:a,addonId:t,nodeId:`hub`,title:n})]})})}D();function Me(){let{t}=ve(),{integrationId:n}=pe(),a=j(),d=W(),[h,g]=fe(),v=F(),[y,x]=M(!1),[S,C]=M(!1),[te,T]=M(!1),[ie,D]=M(!1),[P,L]=M(!1),{data:z,isLoading:le}=b({id:n??``},{enabled:!!n}),{data:B}=re({addonId:z?.addonId??``,nodeId:`hub`},{enabled:!!z?.addonId}),{data:V,isSuccess:U}=ne(),G=k(()=>{let e=z?.addonId;return!e||!U?null:(V??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[V,z?.addonId,U]),{data:ue}=l({}),ge=k(()=>(ue?.providers??[]).some(e=>e.addonId===z?.addonId),[ue,z?.addonId]),J=G!==null,Y=z?.info?.fixed===!0,be=J?G===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),xe=k(()=>{let e=z?.addonId;return!e||!U?null:(V??[]).find(t=>t.addonId===e)?.brokerKind??null},[V,z?.addonId,U]),Se=k(()=>{let e=z?.addonId;return!e||!U?null:(V??[]).find(t=>t.addonId===e)?.mode??null},[V,z?.addonId,U]);ae(()=>{h.get(`add`)===`1`&&J&&(x(!0),g(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[h,J,g]);let Ce=B!=null&&Array.isArray(B.sections)&&B.sections.some(e=>e.fields.length>0),{data:we}=s({},{refetchInterval:5e3}),X=[[`integrations`,`get`],{input:{id:n??``},type:`query`}],Z=_({onMutate:async e=>{await a.cancelQueries({queryKey:X});let t=a.getQueryData(X);return t!=null&&a.setQueryData(X,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&a.setQueryData(X,r.previous)},onSettled:()=>{a.invalidateQueries({queryKey:[[`integrations`]]}),a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=p({onSuccess:()=>{a.invalidateQueries({queryKey:[[`integrations`]]}),a.invalidateQueries({queryKey:[[`deviceManager`]]}),D(!1),d(`/integrations`)}}),Ee=u({onSuccess:()=>{a.invalidateQueries({queryKey:[[`integrations`]]}),a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),De=o({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ke=w({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ae=e({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),$=k(()=>we??[],[we]),Me=k(()=>{let e=new Map;for(let t of $)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[$]),Ne=E(e=>Me.get(e)??null,[Me]),Pe=E(e=>N(I,{type:e,size:`sm`}),[]),Fe=E(e=>d(`/devices/${String(e)}`),[d]),Ie=k(()=>{let e=z?.addonId;return e?$.filter(t=>t.addonId===e):[]},[$,z?.addonId]),Le=k(()=>i(Ie).length,[Ie]);return le?O(`div`,{className:`p-4`,children:[N(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),N(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):z?O(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[N(f,{items:[{label:`Integrations`,onClick:()=>d(`/integrations`)},{label:z.name}]}),O(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[O(`div`,{className:`flex items-center gap-3 min-w-0`,children:[N(`img`,{src:`/api/addon-assets/${z.addonId}/assets/icon.svg`,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:e=>{e.target.style.display=`none`}}),O(`div`,{className:`min-w-0`,children:[N(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:z.name}),O(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[z.addonId,` · `,Le,` `,t(`integrations.devices`)]})]})]}),O(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[ge&&O(`button`,{onClick:()=>C(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the network for devices (incl. a different subnet)`,children:[N(oe,{className:`h-3.5 w-3.5`}),`Scan network`]}),!Y&&O(`button`,{onClick:()=>x(!0),disabled:!J,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:be,children:[N(R,{className:`h-3.5 w-3.5`}),be]}),O(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Z.isPending?`opacity-60`:``} ${z.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[N(c,{checked:z.enabled,onCheckedChange:e=>Z.mutate({id:n,enabled:e}),disabled:Z.isPending,"aria-label":z.enabled?`Disable integration`:`Enable integration`}),N(`span`,{className:`text-[11px] font-medium ${z.enabled?`text-success`:`text-foreground-subtle`}`,children:z.enabled?`Enabled`:`Disabled`}),Z.isPending&&N(H,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Se!==`standalone`&&(Ce||G===`device-adoption`)&&O(`button`,{onClick:()=>T(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[N(_e,{className:`h-3 w-3`}),t(`integrations.config`)]}),O(`button`,{onClick:()=>L(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:t(`integrations.logs`,{defaultValue:`View logs`}),children:[N(he,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),N(m,{label:`Restart`,icon:ce,title:`Restart "${z.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Le} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Ee.isPending,action:()=>Ee.mutateAsync({addonId:z.addonId})}),!Y&&O(`button`,{onClick:()=>D(!0),className:`flex items-center gap-1.5 rounded-lg border border-danger bg-danger/10 px-3 py-1.5 text-[11px] font-medium text-danger hover:bg-danger hover:text-background transition-colors`,title:t(`integrations.delete`,{defaultValue:`Delete integration`}),children:[N(me,{className:`h-3 w-3`}),t(`integrations.delete`,{defaultValue:`Delete`})]})]})]}),N(r,{context:`integration-detail`,devices:$,trpc:v.trpcClient,defaultView:`cards`,forceAddon:z.addonId,urlScope:`root`,lsKey:`integration-detail:${z.addonId}`,resolveIntegrationIcon:Pe,resolveParent:Ne,onNavigate:Fe,batchActions:{remove:De.mutate,disable:ke.mutate,enable:Ae.mutate},...Y?{}:{onDeleteDevice:e=>De.mutate({deviceId:e.id})}}),y&&n&&G===`device-adoption`&&N(Oe,{addonId:z.addonId,integrationId:n,onClose:()=>x(!1)}),y&&n&&G===`device-provider`&&N(Te,{open:y,integrationId:n,addonId:z.addonId,onClose:()=>x(!1)}),S&&z&&N(se,{open:S,scope:{addonId:z.addonId,label:z.name},onClose:()=>C(!1)}),te&&n&&G!==null&&N(je,{integrationId:n,addonId:z.addonId,name:z.name,kind:G,brokerKind:xe,trpc:v.trpcClient,onClose:()=>T(!1)}),P&&N(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>L(!1),children:O(`div`,{className:`flex flex-col rounded-xl border border-border bg-surface shadow-xl w-full max-w-5xl h-[80vh]`,onClick:e=>e.stopPropagation(),children:[O(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5`,children:[O(`div`,{className:`flex items-center gap-2 min-w-0`,children:[N(he,{className:`h-4 w-4 text-primary shrink-0`}),N(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:z.name}),O(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[z.addonId,n?` · ${n}`:``]})]}),N(`button`,{onClick:()=>L(!1),className:`flex h-7 w-7 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close logs`,children:N(K,{className:`h-4 w-4`})})]}),N(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:N(ee,{addonId:z.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})}),ie&&N(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:()=>!Q.isPending&&D(!1),children:O(`div`,{className:`rounded-xl border border-border bg-background p-5 shadow-2xl w-96 space-y-3`,onClick:e=>e.stopPropagation(),children:[O(`div`,{className:`flex items-start gap-3`,children:[N(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg bg-danger/10 shrink-0`,children:N(q,{className:`h-4 w-4 text-danger`})}),O(`div`,{className:`min-w-0`,children:[N(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.deleteTitle`,{defaultValue:`Delete integration?`})}),N(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:t(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:z.name,count:Le})})]})]}),Q.error&&N(`div`,{className:`rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:Q.error instanceof Error?Q.error.message:String(Q.error)}),O(`div`,{className:`flex items-center justify-end gap-2 pt-1`,children:[N(`button`,{onClick:()=>D(!1),disabled:Q.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:t(`integrations.cancel`,{defaultValue:`Cancel`})}),N(`button`,{onClick:()=>Q.mutate({id:n}),disabled:Q.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-danger px-3 py-1.5 text-[11px] font-medium text-background hover:bg-danger/90 transition-colors disabled:opacity-60 disabled:cursor-not-allowed`,children:Q.isPending?O(A,{children:[N(H,{className:`h-3 w-3 animate-spin`}),t(`integrations.deleting`,{defaultValue:`Deleting…`})]}):O(A,{children:[N(me,{className:`h-3 w-3`}),t(`integrations.confirmDelete`,{defaultValue:`Delete integration`})]})})]})]})})]}):O(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[N(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:N(ye,{className:`h-6 w-6 text-foreground-subtle`})}),O(`div`,{className:`space-y-1 max-w-sm`,children:[N(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),N(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:n??``})})]}),O(`button`,{onClick:()=>d(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[N(de,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}export{Me as IntegrationDetailPage};
@@ -1 +0,0 @@
1
- import{G as e,K as t,Mn as n,bn as r,dn as i,es as a,hr as o,pr as s,sr as c,ur as l,ut as u}from"./src-CPanq9UB.js";import{I as d,Q as f,S as p,W as m,b as h,o as ee,q as g,x as _,z as v}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as y}from"./player-overlays-Ba-DoE5F.js";import{t as b}from"./ProviderIcon-DFIIdGww.js";import{t as x}from"./FormBuilder-pSCqn9Pp.js";import{t as S}from"./plus-DrqAQeFJ.js";import{n as te,r as C,t as w}from"./ScanNetworkModal-DEK5U2cd.js";import{t as ne}from"./refresh-cw-NwlTy6_-.js";import{C as T,I as E,J as D,R as O,V as k,X as A,i as j,m as M,t as N,v as P,z as F}from"./index-CY7HK9zV.js";import{t as I}from"./AdminPage-Dq33XE9j.js";import{t as L}from"./StatusBadge-Dcr2bw58.js";import{t as R}from"./useEventInvalidation-CQp2HDcf.js";import{t as z}from"./useBodyScrollLock-B_rtaBV1.js";f();function B(e,t){let[n,r]=g(!1);return v(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}function V({onSelect:e,onClose:t,pendingAddonId:n=null}){let{t:r}=N(),i=D(),{data:a,isLoading:o}=l();if(o)return _(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>_(`div`,{className:`h-14 rounded-lg bg-surface animate-pulse`},e))});let s=n!==null;return p(`div`,{className:`space-y-2`,children:[(a??[]).map(a=>{let o=a.instanceMode===`unique`&&a.existingInstances.length>0,c=n===a.addonId,l=s;return p(`button`,{disabled:l,onClick:()=>{if(!l)if(o){let e=a.existingInstances[0].id;t(),i(`/integrations/${e}`)}else e(a.addonId,a.instanceMode,a.discoveryMode,a.name,a.kind,a.brokerKind,a.mode)},className:`flex w-full items-center gap-3 rounded-lg border border-border bg-surface p-3 text-left hover:border-foreground-subtle/30 transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[a.iconUrl?_(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${a.color}15`},children:_(`img`,{src:a.iconUrl,alt:``,className:`h-5 w-5`})}):_(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${a.color}15`},children:_(`span`,{className:`text-sm`,style:{color:a.color},children:`◉`})}),p(`div`,{className:`flex-1 min-w-0`,children:[_(`p`,{className:`text-xs font-semibold text-foreground`,children:a.name}),a.description&&_(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 truncate`,children:a.description})]}),c?_(T,{className:`h-4 w-4 animate-spin text-primary flex-shrink-0`}):o?p(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[_(M,{className:`h-3 w-3`}),r(`integrations.manage`)]}):_(E,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},a.addonId)}),(a??[]).length===0&&_(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:r(`integrations.noProviders`)})]})}f();function re({addonId:e,configSchema:t,onSave:n,onBack:r}){let{t:i}=N(),[a,s]=g(``),[c,l]=g({}),[u,d]=g(null),f=o({onSuccess:e=>d(e),onError:e=>d({success:!1,error:String(e)})});return p(`div`,{className:`space-y-4`,children:[p(`div`,{children:[_(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:i(`integrations.integrationName`)}),_(`input`,{type:`text`,value:a,onChange:e=>s(e.target.value),placeholder:i(`integrations.integrationNamePlaceholder`),className:`w-full rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:border-primary/50`})]}),t&&_(x,{schema:t,values:c,onChange:l}),u&&_(`div`,{className:`rounded-lg border px-3 py-2 text-xs ${u.success?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:u.success?i(`integrations.connectionSuccess`):`${i(`integrations.errorPrefix`)} ${u.error}`}),p(`div`,{className:`flex items-center justify-between pt-2`,children:[_(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.back`)}),p(`div`,{className:`flex items-center gap-2`,children:[_(`button`,{onClick:()=>f.mutate({addonId:e,settings:c}),disabled:f.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:f.isPending?i(`integrations.testing`):i(`integrations.testConnection`)}),_(`button`,{onClick:()=>n({name:a,config:c}),disabled:!a.trim(),className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:i(`integrations.forward`)})]})]})]})}f();function H({providerId:e,onImport:t,onSkip:n}){let{t:i}=N(),[a,o]=g(new Set),s=r(),c=s.data,l=s.isPending||!s.data&&!s.isError;v(()=>{e&&(s.isPending||s.data||s.mutate({addonId:e}))},[e,s]);function u(e){o(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(l)return p(`div`,{className:`flex flex-col items-center py-12`,children:[_(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),_(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:i(`integrations.searchingDevices`)})]});let d=c??[];return p(`div`,{className:`space-y-4`,children:[_(`p`,{className:`text-xs text-foreground-subtle`,children:d.length>0?i(`integrations.foundDevices`,{count:d.length}):i(`integrations.noDevicesFound`)}),d.length>0&&_(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:d.map(e=>{let t=e.stableId,n=e.suggestedName??t,r=a.has(t);return p(`button`,{onClick:()=>u(t),className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${r?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[_(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${r?`border-primary bg-primary`:`border-border`}`,children:r&&_(F,{className:`h-3 w-3 text-primary-foreground`})}),_(k,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),_(`span`,{className:`text-xs font-medium text-foreground truncate`,children:n})]},t)})}),p(`div`,{className:`flex items-center justify-between pt-2`,children:[_(`button`,{onClick:n,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.skip`)}),d.length>0&&p(`button`,{onClick:()=>t(Array.from(a)),disabled:a.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[i(`integrations.importSelected`),` (`,a.size,`)`]})]})]})}f();function U(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}var ie=2e4;function ae({open:e,onClose:t}){let{t:n}=N(),a=D(),o=ee(),[s,l]=g(`picker`),[d,f]=g(null),[y,b]=g(null),[x,S]=g(`manual`),[C,w]=g(null),[ne,E]=g(``),[O,k]=g(null),[A,M]=g(null),{data:P}=u({addonId:d??``,nodeId:`hub`},{enabled:d!=null}),F=m(()=>P?U(P):null,[P]),I=c({onSuccess:()=>o.invalidateQueries({queryKey:[[`integrations`]]})}),L=r(),R=L.data;v(()=>{s!==`discovery`||!y||!d||L.isPending||L.data||L.mutate({addonId:d})},[s,y,d,L]);let ae=i({onSuccess:()=>o.invalidateQueries({queryKey:[[`deviceManager`]]})});function W(e,t,n,r,i,a,o){if(!I.isPending){if(f(e),S(n),E(r),M(null),o===`broker`){if(!a){M(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}w(a),l(`broker`);return}if(o===`account`){l(`config`);return}oe(e,r)}}async function oe(e,n){try{let r=await I.mutateAsync({addonId:e,name:n,settings:{}});t(),J(),a(`/integrations/${r.id}?add=1`)}catch{}}async function se(e){if(d)try{let t=await I.mutateAsync({addonId:d,name:e.name,settings:e.config});b(t.id),x===`auto`||x===`both`?l(`discovery`):q(t.id)}catch{}}async function G(e){if(d)try{let t=await I.mutateAsync({addonId:d,name:ne,settings:{brokerId:e}});k(t.id),b(t.id),q(t.id)}catch{}}async function K(e){if(d){for(let t of e){let e=R?.find(e=>e.stableId===t);e&&await ae.mutateAsync({addonId:d,candidate:e,...O===null?{}:{integrationId:O}})}q()}}function q(e){let n=e??y??d;t(),J(),n&&a(`/integrations/${n}`)}function J(){l(`picker`),f(null),b(null),S(`manual`),w(null),E(``),k(null),M(null)}function Y(){t(),J()}z(e);let X=I.isPending,Z=B(X,ie);if(!e)return null;let ce={picker:n(`integrations.newIntegration`),config:n(`integrations.configureIntegration`),discovery:n(`integrations.importDevices`),broker:n(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},le=X?d:null,Q=I.error,$=X&&!Z;return p(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[_(`div`,{className:`absolute inset-0 bg-black/60`,onClick:$?void 0:Y}),p(`div`,{className:`relative z-10 w-full max-w-lg max-h-[calc(85dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[p(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[_(`h2`,{className:`text-sm font-semibold text-foreground`,children:ce[s]}),_(`button`,{onClick:Y,disabled:$,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:_(j,{className:`h-4 w-4`})})]}),p(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[Q&&!X&&_(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:Q instanceof Error?Q.message:String(Q)}),s===`picker`&&p(h,{children:[A&&_(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:A}),_(V,{onSelect:W,onClose:Y,pendingAddonId:le})]}),s===`config`&&d&&_(re,{addonId:d,configSchema:F??null,onSave:se,onBack:()=>l(`picker`)}),s===`broker`&&C&&_(te,{kind:C,onResolved:e=>{G(e)},onBack:()=>l(`picker`)}),s===`discovery`&&y&&_(H,{providerId:y,onImport:K,onSkip:q})]}),X&&p(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm px-6 text-center`,children:[_(T,{className:`h-6 w-6 animate-spin text-primary`}),_(`p`,{className:`text-xs font-medium text-foreground`,children:n(`integrations.creating`,{defaultValue:`Creating integration…`})}),!Z&&_(`p`,{className:`text-[10px] text-foreground-subtle`,children:n(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),Z&&p(h,{children:[_(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:n(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),_(`button`,{onClick:Y,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:n(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})]})}function W({integration:e,expanded:t,onToggleExpand:n}){return p(`div`,{className:`flex items-center gap-2.5`,children:[_(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),n(e.addonId)},"aria-label":t?`Collapse`:`Expand`,"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:_(t?O:E,{className:`h-3.5 w-3.5`})}),_(b,{type:e.addonId,size:`sm`}),p(`div`,{className:`flex min-w-0 flex-col`,children:[_(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),_(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function oe(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>_(W,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:`Devices`,headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>`${e.deviceCount} device${e.deviceCount===1?``:`s`}`},{key:`status`,header:`Status`,headerClassName:`w-[15%]`,cell:e=>_(L,{status:e.status})}]}f();function se(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var G=`expand`;function K(){let{t:r}=N(),i=D(),o=y(),[c]=A(),[l,u]=g(!1),f=d(()=>u(!0),[]),ee=d(()=>u(!1),[]),[v,x]=g(!1),te=d(()=>x(!0),[]),T=d(()=>x(!1),[]);R([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),R([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:E,isLoading:O,refetch:k}=s(void 0),{data:j,isLoading:M,refetch:F}=n({}),L=m(()=>j??[],[j]),z=m(()=>E??[],[E]),B=m(()=>{let e=new Map;for(let t of L)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[L]),V=m(()=>{let e=new Map;for(let n of t(L)){let t=n.addonId??``;t&&e.set(t,(e.get(t)??0)+1)}return e},[L]),re=m(()=>z.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:se(e),deviceCount:V.get(e.addonId)??0})),[z,V]),H=c.get(G),U=d(e=>{let t=new URLSearchParams(window.location.search);t.get(G)===e?t.delete(G):t.set(G,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),ie=d(e=>i(`/integrations/${e.id}`),[i]),W=d(e=>B.get(e)??null,[B]),K=d(e=>_(b,{type:e,size:`sm`}),[]),q=d(e=>i(`/devices/${String(e)}`),[i]),J=d(t=>_(e,{context:`integration-detail`,devices:L,trpc:o.trpcClient,forceAddon:t.addonId,urlScope:`nested`,lsKey:`integrations:nested:${t.addonId}`,resolveIntegrationIcon:K,resolveParent:W,onNavigate:q}),[L,o.trpcClient,K,W,q]),Y=d(e=>H===e.addonId,[H]),X=m(()=>oe({isExpanded:Y,onToggleExpand:U}),[Y,U]),Z=d(e=>`${e.name} ${e.addonId}`,[]),ce=d(e=>e.addonId,[]),le=d(()=>{k(),F()},[k,F]),Q=O||M,$=z.length>0;return p(I,{icon:P,title:r(`nav.integrations`,`Integrations`),actions:p(h,{children:[_(`button`,{onClick:le,disabled:Q,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:`Refresh`,children:_(ne,{className:a(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),p(`button`,{onClick:te,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the local network for devices`,children:[_(C,{className:`h-3.5 w-3.5`}),`Scan network`]}),p(`button`,{onClick:f,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[_(S,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[Q&&_(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>_(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!$&&p(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[_(`p`,{className:`text-sm`,children:`No integrations configured.`}),_(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!Q&&$&&_(e,{mode:`generic`,items:re,getKey:ce,getSearchText:Z,columns:X,onRowClick:ie,isExpanded:Y,renderExpanded:J,searchPlaceholder:r(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:r(`integrations.empty`,{defaultValue:`No integrations found.`})}),_(ae,{open:l,onClose:ee}),_(w,{open:v,onClose:T})]})}export{K as IntegrationsPage};
@@ -1 +0,0 @@
1
- import{Ar as e,Cr as t,Dr as n,Er as r,Fr as i,Ho as a,Ir as o,Or as s,Pr as c,Sr as l,Tr as u,Uo as d,Vo as f,br as p,bt as m,jr as h,kr as g,oo as _,wr as ee,xr as te,xt as v,yo as y,za as b}from"./src-CPanq9UB.js";import{I as x,Q as S,S as C,W as w,b as T,o as E,q as D,x as O,z as ne}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{E as k,S as A}from"./src-EmgPMReM.js";import{p as j}from"./player-overlays-Ba-DoE5F.js";import{n as M,t as re}from"./rotate-ccw-DGfCNuX0.js";import{t as N}from"./copy-BtwlORlH.js";import{n as P,t as F}from"./AddonCollectionPage-D6-DslHs.js";import{t as ie}from"./refresh-cw-NwlTy6_-.js";import{t as I}from"./server-Bv5NUu2G.js";import{t as ae}from"./square-CBtc15_U.js";import{t as oe}from"./wifi-DiUaWSk8.js";import{C as L,D as R,K as z,S as se,U as ce,i as le,j as B,s as V,u as ue,x as de,y as H,z as fe}from"./index-CY7HK9zV.js";import{t as pe}from"./AdminPage-Dq33XE9j.js";import{t as me}from"./AdminTabs-EuBAqr82.js";import{t as U}from"./addon-display-names-DvSEQty-.js";var he=z(`log-in`,[[`path`,{d:`m10 17 5-5-5-5`,key:`1bsop3`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`,key:`u53s6r`}]]),ge=z(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]),W=z(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]);S();var G=5e3,_e={connected:!1,endpoint:null};function ve(){let e=E(),t=v({capName:`network-access`},{refetchInterval:G}),n=m(void 0,{refetchInterval:G}),r=w(()=>U(n.data??[]),[n.data]),a=w(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:r.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,r]),[s,c]=D(null),[l,u]=D({}),d=(t,n)=>{let r=n?.addonId;e.invalidateQueries({queryKey:[[`networkAccess`,`getStatus`],{input:{addonId:r},type:`query`}]}),c(null),u(e=>{if(r===void 0||!(r in e))return e;let t={...e};return delete t[r],t})},f=(e,t)=>{c(null);let n=t?.addonId;if(n===void 0)return;let r=e instanceof Error?e.message:String(e);u(e=>({...e,[n]:r}))},p=i({onSuccess:d,onError:f}),h=o({onSuccess:d,onError:f});return O(F,{title:`Remote Access`,subtitle:`Public-facing tunnels that expose this hub to the internet (Cloudflare Tunnel, ngrok, …). Settings, Logs and Events are docked under every provider.`,pageIcon:R,itemIcon:R,capability:`network-access`,installButtonLabel:`Add tunnel`,items:a,isLoading:t.isLoading,emptyTitle:`No remote-access providers installed`,emptyDescription:`Install a tunnel addon (e.g. @camstack/addon-cloudflare) to expose this hub publicly.`,renderStatusBadges:e=>O(ye,{addonId:e.addonId}),itemError:e=>l[e.addonId]??null,renderPrimaryAction:e=>O(be,{addonId:e.addonId,busyId:s,onStart:e=>{c(e),p.mutate({addonId:e})},onStop:e=>{c(e),h.mutate({addonId:e})}})})}function K(e){let{data:t}=c({addonId:e},{refetchInterval:G,retry:!1}),n=t?k.safeParse(t):null;return n?.success?n.data:_e}function ye({addonId:e}){let t=K(e);return C(T,{children:[O(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.connected?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.connected?`Connected`:`Disconnected`}),t.endpoint&&C(`a`,{href:t.endpoint.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-[10px] text-emerald-700 dark:text-emerald-300 hover:underline flex items-center gap-1`,children:[O(B,{className:`h-3 w-3`}),t.endpoint.url]})]})}function be({addonId:e,busyId:t,onStart:n,onStop:r}){let i=K(e),a=t===e;return i.connected?C(d,{size:`sm`,variant:`secondary`,disabled:a,onClick:()=>r(e),children:[a?O(L,{className:`h-3 w-3 animate-spin`}):O(ae,{className:`h-3 w-3`}),`Stop`]}):C(d,{size:`sm`,variant:`primary`,disabled:a,onClick:()=>n(e),children:[a?O(L,{className:`h-3 w-3 animate-spin`}):O(P,{className:`h-3 w-3`}),`Start`]})}S();var q=3e4;function xe(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function Se(){let e=v({capName:`turn-provider`},{refetchInterval:q}),t=m(void 0,{refetchInterval:q}),n=b(),r=n.data??[],i=w(()=>U(t.data??[]),[t.data]);return O(F,{title:`TURN Servers`,subtitle:`ICE servers used for WebRTC NAT traversal. Multiple providers can coexist — the WebRTC layer concatenates servers from all enabled providers per session.`,pageIcon:H,itemIcon:H,capability:`turn-provider`,installButtonLabel:`Add provider`,items:w(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:i.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,i]),isLoading:e.isLoading,emptyTitle:`No TURN providers installed`,emptyDescription:`Install a TURN addon (e.g. @camstack/addon-cloudflare) to enable WebRTC behind restrictive NATs.`,renderExpandedPanel:e=>O(Ce,{addonId:e.addonId,enabled:e.isActive}),trailing:C(f,{children:[C(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[C(`div`,{children:[O(`div`,{className:`text-sm font-semibold`,children:`Combined ICE server list`}),O(`div`,{className:`text-xs text-foreground-subtle`,children:`What the WebRTC layer fetches per-session.`})]}),O(d,{size:`sm`,variant:`secondary`,onClick:()=>n.refetch(),disabled:n.isFetching,children:`Refresh`})]}),O(`div`,{className:`p-4`,children:r.length===0?O(`div`,{className:`text-xs text-foreground-subtle`,children:`No servers from enabled providers.`}):O(`div`,{className:`flex flex-col gap-3`,children:r.map((e,t)=>{let n=Array.isArray(e.urls)?e.urls:[e.urls];return C(`div`,{className:`rounded border border-border bg-surface`,children:[(e.username||e.credential)&&C(`div`,{className:`px-3 py-1.5 border-b border-border text-[10px] font-mono text-foreground-subtle flex items-center gap-3`,children:[e.username&&C(`span`,{children:[O(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,O(`span`,{className:`text-foreground`,children:e.username})]}),e.credential&&C(`span`,{children:[O(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,O(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),O(`ul`,{className:`divide-y divide-border`,children:n.map(e=>O(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},t)})})})]})})}function Ce({addonId:e,enabled:t}){let n=b({addonId:e},{enabled:t,retry:!1}),r=w(()=>xe(n.data??[]),[n.data]);return!t||r.length===0?null:C(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[C(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Discovered ICE servers (`,r.length,`)`]}),O(`div`,{className:`flex flex-wrap gap-1`,children:r.map(e=>O(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground`,children:e},e))})]})}S();var we={lan:H,wifi:oe,docker:M,vpn:se,loopback:I,other:I},Te={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},Ee=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function De(e){let{interfaces:t,disabled:n,hideLoopback:r,ipv4Only:i,emptyMessage:a}=e,o=w(()=>t.filter(e=>!(r&&e.kind===`loopback`||i&&e.family!==`IPv4`)),[t,r,i]),s=w(()=>{let e=new Map;for(let t of o){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return Ee.filter(t=>e.has(t)).map(t=>({kind:t,items:e.get(t)}))},[o]),c=t=>e.mode===`single`?e.value===t:e.value.includes(t),l=t=>{if(n||t.kind===`loopback`)return;if(e.mode===`single`){e.onChange(e.value===t.address?null:t.address);return}let r=new Set(e.value);r.has(t.address)?r.delete(t.address):r.add(t.address),e.onChange([...r])};return o.length===0?O(`div`,{className:`text-xs text-foreground-subtle italic`,children:a??`No addresses available.`}):O(`div`,{className:`flex flex-col gap-3`,children:s.map(({kind:t,items:r})=>C(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[C(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[O(we[t]??I,{className:`h-3.5 w-3.5 text-foreground-subtle`}),O(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:Te[t]??t}),C(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,r.length]})]}),O(`ul`,{className:`divide-y divide-border`,children:r.map(t=>{let r=c(t.address),i=t.kind===`loopback`,a=!t.plausible&&!i;return C(`li`,{className:`flex items-center gap-3 px-3 py-2 ${i?`opacity-60 cursor-not-allowed`:n?`opacity-60`:a?`cursor-pointer hover:bg-surface-hover/30 bg-amber-500/[0.04]`:`cursor-pointer hover:bg-surface-hover/30`}`,onClick:()=>l(t),children:[O(`span`,{className:`flex items-center justify-center h-4 w-4 rounded ${e.mode===`single`?`rounded-full`:`rounded`} border ${r?`border-primary bg-primary text-primary-foreground`:`border-border bg-surface`}`,children:r&&O(fe,{className:`h-3 w-3`})}),C(`div`,{className:`flex-1 min-w-0 ${a?`text-foreground-subtle`:``}`,children:[C(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[O(`span`,{className:`font-mono text-xs font-semibold ${a?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),O(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-mono`,children:t.family}),t.preferred&&O(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:`Auto-preferred`}),i&&O(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:`Always included`}),a&&C(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:t.plausibleReason||void 0,children:[O(V,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]}),C(`div`,{className:`text-xs text-foreground-subtle mt-0.5 font-mono break-all`,children:[t.address,t.cidr&&t.cidr!==t.address?` (${t.cidr})`:``]})]})]},`${t.name}-${t.family}-${t.address}`)})})]},t))})}S();var J={"lan-ipv4":`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,"lan-ipv6":`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`,loopback:`bg-foreground-subtle/15 text-foreground-subtle`};function Oe(){let e=E(),n=j(),i=t(void 0,{refetchInterval:3e4}),a=p(void 0),o=u({onSuccess:()=>{e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),s=ee({onSuccess:t=>{g(t.addresses),e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),c=w(()=>i.data?.interfaces??[],[i.data]),m=te({port:typeof window<`u`?Number(window.location.port)||(window.location.protocol===`https:`?443:80):4e3,scheme:typeof window<`u`&&window.location.protocol===`https:`?`https`:`http`},{refetchInterval:3e4}),[h,g]=D([]),[_,v]=D(!1);ne(()=>{!_&&a.data&&(g(a.data.addresses),v(!0))},[a.data,_]);let y=a.data?.addresses??[],b=w(()=>{if(h.length!==y.length)return!0;let e=[...h].toSorted(),t=[...y].toSorted();return e.some((e,n)=>e!==t[n])},[h,y]),x=()=>{o.mutate({addresses:[...h]})},S=()=>{g(y)},T=()=>{g([])},k=()=>{i.refetch(),m.refetch(),a.refetch()},A=async()=>{try{let e=await n.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info(`[network-addresses] race result`,e)}catch(e){console.warn(`[network-addresses] race failed`,e)}},M=l(),N=r({onSuccess:()=>void M.refetch()}),P=m.data?.endpoints??[],F=M.data?.baseUrl??null,I=M.data?.resolved??null;return C(pe,{children:[C(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[O(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Pick the local addresses SDK clients should race for the fastest path to this hub. Empty selection (auto) lets every non-loopback / non-link-local interface participate.`}),C(`div`,{className:`flex items-center gap-2 shrink-0`,children:[C(d,{size:`sm`,variant:`secondary`,onClick:k,disabled:i.isLoading,children:[O(ie,{className:`h-3 w-3 ${i.isLoading?`animate-spin`:``}`}),`Refresh`]}),O(d,{size:`sm`,variant:`secondary`,onClick:A,children:`Probe race`})]})]}),C(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[C(f,{children:[C(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[C(`div`,{children:[O(`div`,{className:`text-sm font-semibold`,children:`Allowed addresses`}),O(`div`,{className:`text-xs text-foreground-subtle`,children:h.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${h.length} pinned`})]}),C(`div`,{className:`flex items-center gap-1`,children:[C(d,{size:`sm`,variant:`secondary`,onClick:()=>s.mutate(void 0),disabled:s.isPending||o.isPending,title:`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`,children:[O(ue,{className:`h-3 w-3`}),s.isPending?`Detecting…`:`Best match`]}),C(d,{size:`sm`,variant:`secondary`,onClick:T,disabled:h.length===0||o.isPending,children:[O(re,{className:`h-3 w-3`}),`Clear`]}),b&&O(d,{size:`sm`,variant:`secondary`,onClick:S,disabled:o.isPending,children:`Discard`}),C(d,{size:`sm`,variant:`primary`,onClick:x,disabled:!b||o.isPending,children:[O(ge,{className:`h-3 w-3`}),o.isPending?`Saving…`:`Save`]})]})]}),O(`div`,{className:`p-4`,children:O(De,{mode:`multiple`,interfaces:c,value:h,onChange:g,disabled:o.isPending,emptyMessage:i.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),C(f,{children:[C(`div`,{className:`px-4 py-3 border-b border-border`,children:[O(`div`,{className:`text-sm font-semibold`,children:`Connection endpoints — priority order`}),O(`div`,{className:`text-xs text-foreground-subtle`,children:`Live preview of the ranked candidate list the SDK would race against. Updates with each Save.`}),C(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-2 text-xs`,children:[O(`span`,{className:`text-foreground-subtle`,children:`Notification links use:`}),O(`span`,{className:`font-mono text-foreground`,children:F??`${I??`nothing reachable`} (auto)`}),F!==null&&O(`button`,{type:`button`,disabled:N.isPending,onClick:()=>N.mutate({baseUrl:null}),className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:`reset to auto`})]}),F===null&&I===null&&O(`p`,{className:`mt-1 text-[11px] text-amber-600 dark:text-amber-400`,children:`No public address is reachable, so notification media ships as bytes only — a backend that can only take links (WhatsApp, gotify) receives none.`})]}),O(`div`,{className:`p-4`,children:P.length===0?O(`div`,{className:`text-xs text-foreground-subtle italic`,children:m.isLoading?`Loading…`:`No endpoints available.`}):O(`ul`,{className:`space-y-1 text-xs`,children:P.map(e=>C(`li`,{className:`flex items-center gap-2 flex-wrap ${e.plausible?``:`opacity-80`}`,children:[O(`span`,{className:`font-mono text-[10px] w-10 text-foreground-subtle`,children:String(e.priority).padStart(4,`0`)}),O(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${J[e.kind]??J.loopback}`,children:e.kind}),e.interfaceKind!==`lan`&&e.interfaceKind!==`public`&&O(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-medium uppercase`,children:e.interfaceKind}),!e.plausible&&e.interfaceKind!==`loopback`&&C(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:e.plausibleReason||void 0,children:[O(V,{className:`h-2.5 w-2.5`}),`Unlikely usable`]}),O(`span`,{className:`font-mono break-all ${e.plausible?`text-foreground`:`text-foreground-subtle`}`,children:e.baseUrl}),C(`span`,{className:`text-foreground-subtle`,children:[`— `,e.label]}),e.kind===`loopback`?null:F===e.baseUrl?C(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-primary/15 px-2 py-0.5 text-[10px] font-medium text-primary`,children:[O(ce,{className:`h-2.5 w-2.5`}),` notifications`]}):O(`button`,{type:`button`,disabled:N.isPending,onClick:()=>N.mutate({baseUrl:e.baseUrl}),className:`rounded-full border border-border px-2 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:`use for notifications`})]},`${e.priority}-${e.baseUrl}`))})})]})]})]})}S();var ke={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},Y=5e3,Ae=3e4,je={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function Me(){let e=v({capName:`mesh-network`},{refetchInterval:Y}),t=m(void 0,{refetchInterval:Y}),n=w(()=>U(t.data??[]),[t.data]);return O(F,{title:`Mesh Networks`,subtitle:`Private VPN meshes that connect CamStack to your other devices (Tailscale, Headscale, …). Each provider can also expose this hub publicly via its ingress (Tailscale Funnel).`,pageIcon:M,itemIcon:H,capability:`mesh-network`,installButtonLabel:`Add mesh`,items:w(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,n]),isLoading:e.isLoading,emptyTitle:`No mesh-network providers installed`,emptyDescription:`Install a mesh addon (e.g. @camstack/addon-tailscale) to join this hub into a private VPN mesh.`,renderStatusBadges:e=>O(Ne,{addonId:e.addonId}),renderPrimaryAction:e=>O(Pe,{addonId:e.addonId}),renderExpandedPanel:e=>O(Z,{addonId:e.addonId})})}function X(e){let{data:t,isLoading:r}=n({addonId:e},{refetchInterval:Y,retry:!1}),i=t?A.safeParse(t):null;return{status:i?.success?i.data:je,isLoading:r}}function Ne({addonId:e}){let{status:t}=X(e);return C(T,{children:[O(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.joined?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.joined?`Joined`:`Not joined`}),t.joined&&C(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:[t.peerCount,` peer`,t.peerCount===1?``:`s`]})]})}function Pe({addonId:t}){let n=E(),[r,i]=D(!1),[a,o]=D(null),c=j(),{status:l}=X(t),u=x(()=>{n.invalidateQueries({queryKey:[[`meshNetwork`]]})},[n]),f=h(),p=s({onSuccess:u}),m=e({onSuccess:u}),g=x(async()=>{i(!0);let e={cancelled:!1};o(e);try{let n=await f.mutateAsync({addonId:t});if(e.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!e.cancelled&&(await ze(2e3),!e.cancelled);){let e=await c.trpcClient.meshNetwork.getStatus.query({addonId:t}).catch(()=>null),n=e?A.safeParse(e):null;if(n?.success&&n.data.joined){u();break}if(Date.now()-r>6e5)break}}finally{i(!1),o(null)}},[t,u,f,c]),_=x(()=>{a&&(a.cancelled=!0),i(!1),o(null)},[a]);return O(T,{children:l.joined?C(T,{children:[C(d,{size:`sm`,variant:`secondary`,disabled:p.isPending,onClick:()=>p.mutate({addonId:t}),children:[p.isPending?O(L,{className:`h-3 w-3 animate-spin`}):O(de,{className:`h-3 w-3`}),`Disconnect`]}),C(d,{size:`sm`,variant:`ghost`,disabled:m.isPending,onClick:()=>m.mutate({addonId:t}),children:[m.isPending?O(L,{className:`h-3 w-3 animate-spin`}):O(W,{className:`h-3 w-3`}),`Log out`]})]}):r?C(d,{size:`sm`,variant:`ghost`,onClick:_,children:[O(le,{className:`h-3 w-3 mr-1`}),` Cancel`]}):C(T,{children:[C(d,{size:`sm`,variant:`primary`,onClick:()=>void g(),children:[O(he,{className:`h-3 w-3`}),`Connect`]}),C(d,{size:`sm`,variant:`ghost`,disabled:m.isPending,onClick:()=>m.mutate({addonId:t}),children:[m.isPending?O(L,{className:`h-3 w-3 animate-spin`}):O(W,{className:`h-3 w-3`}),`Log out`]})]})})}function Z({addonId:e}){let{status:t}=X(e),n=g({addonId:e},{refetchInterval:Ae,retry:!1});return C(`div`,{className:`rounded-lg border border-border bg-surface`,children:[C(`div`,{className:`p-4 space-y-4`,children:[t.error&&O(_,{message:t.error}),O(Fe,{status:t}),t.endpoints.length>0&&C(`div`,{className:`space-y-1.5`,children:[O(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Endpoints`}),t.endpoints.map(e=>C(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[C(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${ke[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?O(R,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),C(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-emerald-700 dark:text-emerald-300 hover:underline break-all flex items-center gap-1`,children:[O(B,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),O(`div`,{className:`border-t border-border`,children:O(Le,{peers:n.data?.peers??[],loading:n.isLoading})})]})}function Fe({status:e}){return O(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-1.5`,children:[{label:`Tenant`,value:e.tenantName||`—`},{label:`User`,value:e.userLogin??`—`},{label:`Control plane`,value:e.controlPlaneUrl||`—`},{label:`Mesh IP`,value:e.meshIp||`—`,mono:!0},{label:`MagicDNS`,value:e.magicDnsHostname||`—`,mono:!0},{label:`DNS suffix`,value:e.magicDnsSuffix||`—`,mono:!0},{label:`Peers`,value:String(e.peerCount)},{label:`Key expiry`,value:e.keyExpiry?Ie(e.keyExpiry):`—`}].map(e=>C(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[O(`span`,{className:`text-foreground-subtle shrink-0`,children:e.label}),O(`span`,{className:`text-foreground truncate ${e.mono?`font-mono`:``}`,children:e.value})]},e.label))})}function Ie(e){let t=e-Date.now();if(t<0)return`Expired ${$(e)}`;let n=Math.floor(t/864e5);if(n>60)return new Date(e).toLocaleDateString();if(n>1)return`in ${n} days`;let r=Math.floor(t/36e5);return r>1?`in ${r}h`:`in ${Math.max(1,Math.floor(t/6e4))} min`}function Le({peers:e,loading:t}){let n=w(()=>e.map(e=>({...e,_id:e.id})),[e]),r=x(e=>{e&&navigator.clipboard?.writeText(e)},[]),i=w(()=>[{key:`hostname`,header:`Hostname`,render:e=>C(`div`,{className:`flex flex-col`,children:[C(`div`,{className:`flex items-center gap-1.5`,children:[O(`span`,{className:`font-medium text-foreground`,children:e.hostname||`(unknown)`}),e.isSelf&&O(a,{variant:`info`,children:`self`}),e.exitNodeOption&&O(a,{variant:`warning`,children:`exit-node`})]}),e.userLogin&&O(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.userLogin})]})},{key:`magicDns`,header:`MagicDNS`,render:e=>e.magicDns?C(`div`,{className:`flex items-center gap-1`,children:[O(`span`,{className:`font-mono text-xs truncate`,children:e.magicDns}),O(`button`,{onClick:()=>r(e.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy MagicDNS`,children:O(N,{className:`h-3 w-3 text-foreground-subtle`})})]}):O(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:e=>{let t=e.addresses[0]??``;return t?C(`div`,{className:`flex items-center gap-1`,children:[O(`span`,{className:`font-mono text-xs`,children:t}),O(`button`,{onClick:()=>r(t),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy IP`,children:O(N,{className:`h-3 w-3 text-foreground-subtle`})})]}):O(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:`Connection`,render:e=>C(`div`,{className:`flex items-center gap-1.5`,children:[O(a,{variant:Re(e.connection),children:e.connection}),e.relay&&O(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.relay})]})},{key:`routes`,header:`Routes`,render:e=>e.advertisedRoutes.length>0?O(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):O(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:`TX / RX`,render:e=>C(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,Q(e.txBytes),` · ↓ `,Q(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>O(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?$(e.lastSeenMs):`—`})}],[r]);return t&&e.length===0?C(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[O(L,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):e.length===0?O(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No peers visible — your tailnet may be empty or the host is not joined.`}):O(`div`,{className:`p-4`,children:O(y,{columns:i,rows:n,rowKey:e=>e._id,minWidthPx:820})})}function Re(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function Q(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)}MB`:`${(e/1024/1024/1024).toFixed(2)}GB`}function $(e){let t=Date.now()-e;return t<6e4?`just now`:t<36e5?`${Math.round(t/6e4)}m ago`:t<864e5?`${Math.round(t/36e5)}h ago`:`${Math.round(t/864e5)}d ago`}function ze(e){return new Promise(t=>setTimeout(t,e))}function Be(){return O(`div`,{className:`flex flex-col p-4`,children:O(me,{tabs:[{id:`addresses`,label:`Network Addresses`,icon:I,content:O(Oe,{})},{id:`remote-access`,label:`Remote Access`,icon:R,content:O(ve,{})},{id:`mesh`,label:`Mesh Networks`,icon:M,content:O(Me,{})},{id:`turn`,label:`TURN Servers`,icon:H,content:O(Se,{})}]})})}export{Be as NetworkPage};
@@ -1 +0,0 @@
1
- import{Ai as e,Dn as t,Ho as n,Mn as r,Ro as i,Tn as a,Vi as o}from"./src-CPanq9UB.js";import{K as s,Q as c,S as l,W as u,b as d,o as f,q as p,x as m,z as h}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as g}from"./zap-y-GpHg-7.js";import{I as _,K as v,N as y,S as b,o as x}from"./index-CY7HK9zV.js";var S=v(`circuit-board`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M11 9h4a2 2 0 0 0 2-2V3`,key:`1ve2rv`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`M7 21v-4a2 2 0 0 1 2-2h4`,key:`1fwkro`}],[`circle`,{cx:`15`,cy:`15`,r:`2`,key:`3i40o0`}]]),C=v(`layers`,[[`path`,{d:`M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z`,key:`zw3jo`}],[`path`,{d:`M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12`,key:`1wduqc`}],[`path`,{d:`M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17`,key:`kqbvx6`}]]),w=v(`lock-open`,[[`rect`,{width:`18`,height:`11`,x:`3`,y:`11`,rx:`2`,ry:`2`,key:`1w4ew1`}],[`path`,{d:`M7 11V7a5 5 0 0 1 9.9-1`,key:`1mm8w8`}]]),T=v(`minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),E=v(`scale`,[[`path`,{d:`m16 16 3-8 3 8c-.87.65-1.92 1-3 1s-2.13-.35-3-1Z`,key:`7g6ntu`}],[`path`,{d:`m2 16 3-8 3 8c-.87.65-1.92 1-3 1s-2.13-.35-3-1Z`,key:`ijws7r`}],[`path`,{d:`M7 21h10`,key:`1b0cd5`}],[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`M3 7h2c2 0 5-1 7-2 2 1 5 2 7 2h2`,key:`3gwbw2`}]]),D=v(`usb`,[[`circle`,{cx:`10`,cy:`7`,r:`1`,key:`dypaad`}],[`circle`,{cx:`4`,cy:`20`,r:`1`,key:`22iqad`}],[`path`,{d:`M4.7 19.3 19 5`,key:`1enqfc`}],[`path`,{d:`m21 3-3 1 2 2Z`,key:`d3ov82`}],[`path`,{d:`M9.26 7.68 5 12l2 5`,key:`1esawj`}],[`path`,{d:`m10 14 5 2 3.5-3.5`,key:`v8oal5`}],[`path`,{d:`m18 12 1-1 1 1-1 1Z`,key:`1bh22v`}]]);c();function O(e){return r({addonId:e})}function k(e){return t({deviceId:e},{enabled:Number.isFinite(e)})}var A=3e4,j=2e3;function M(e){let t=s(0);return t.current===0&&(t.current=Date.now()),a({parentDeviceId:e},{enabled:Number.isFinite(e),staleTime:0,refetchOnMount:`always`,refetchInterval:e=>{let n=e.state.data;return n&&n.length>0||Date.now()-t.current>=A?!1:j}})}function N(e){let t={};for(let n of e){let e=Object.keys(n.steps).length>0;t[n.key]={enabled:n.enabled,weight:Math.max(1,n.weight),...n.maxSessions!==null&&n.maxSessions>0?{maxSessions:n.maxSessions}:{},...e?{steps:n.steps}:{}}}return t}c();function P(e,t,n){return Math.min(Math.max(e,t),n)}function F(e){let t=e.reduce((e,t)=>e+Math.max(t.weight,0),0);if(t<=0){let t=e.length>0?100/e.length:0;return Object.fromEntries(e.map(e=>[e.id,t]))}return Object.fromEntries(e.map(e=>[e.id,Math.max(e.weight,0)/t*100]))}function I(e,t,n,r,i){let a=i.filter(e=>e!==t&&r.has(e)).reduce((t,n)=>t+Math.max(e[n]??0,0),0),o=Math.max(0,100-a),s=i.filter(e=>e!==t&&!r.has(e)),c=s.length===0?o:P(n,0,o),l={...e,[t]:c};if(s.length>0){let e=Math.max(0,o-c)/s.length;for(let t of s)l[t]=e}return l}function L(e,t,n){let r={},i=0,a=[];for(let o of t){let t=Math.max(e[o]??0,0);if(n.has(o)){let e=Math.round(t);r[o]=e,i+=e}else{let e=Math.floor(t);r[o]=e,a.push({id:o,floor:e,frac:t-e})}}let o=Math.max(0,100-i)-a.reduce((e,t)=>e+t.floor,0),s=[...a].sort((e,t)=>t.frac-e.frac);for(let e=0;o>0&&s.length>0;e+=1)r[s[e%s.length].id]+=1,--o;let c=[...a].sort((e,t)=>e.frac-t.frac);for(let e=0;o<0&&c.length>0;e+=1){let t=c[e%c.length].id;r[t]>0&&(--r[t],o+=1)}return r}function R({nodes:e,pending:t,onCommitWeights:n,weightLabel:r=`Detection weight`,emptyHint:i,footnote:a}){let[o,s]=p(()=>F(e)),[c,u]=p(new Set);h(()=>{s(F(e)),u(t=>new Set([...t].filter(t=>e.some(e=>e.id===t))))},[e.map(e=>`${e.id}:${e.weight}`).join(`|`)]);let f=e.map(e=>e.id),g=e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},_=(e,t)=>{s(n=>I(n,e,t,c,f))},v=()=>{let t=L(o,f,c),r=e.filter(e=>(t[e.id]??0)!==e.weight).map(e=>e.id);if(r.length===0)return;let i=new Set([...r,...c]);n(e.filter(e=>i.has(e.id)).map(e=>({nodeId:e.id,weight:t[e.id]??0})))};if(e.length===0)return m(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:i??`No detect-enabled nodes. Enable “Detect” on a node above to distribute detection weight.`});let y=e.length===1;return l(`div`,{className:`space-y-3`,children:[e.map(e=>{let n=o[e.id]??0,i=c.has(e.id);return l(`div`,{className:`flex items-center gap-3`,children:[m(`span`,{className:`w-28 shrink-0 truncate text-xs font-medium text-foreground`,title:e.name,children:e.name}),m(`input`,{"aria-label":`${r} for ${e.name}`,type:`range`,min:0,max:100,step:1,value:Math.round(n),disabled:t||i||y,onChange:t=>_(e.id,Number(t.target.value)),onPointerUp:()=>v(),onKeyUp:()=>v(),className:`h-1.5 flex-1 cursor-pointer accent-primary disabled:cursor-not-allowed disabled:opacity-50`}),l(`span`,{className:`w-10 shrink-0 text-right font-mono text-xs tabular-nums text-foreground`,children:[Math.round(n),`%`]}),m(`button`,{type:`button`,onClick:()=>g(e.id),disabled:t||y,"aria-pressed":i,title:i?`Unlock — allow rebalancing`:`Lock this share when others change`,className:`shrink-0 rounded p-1 hover:bg-surface-hover disabled:opacity-40 ${i?`text-amber-400`:`text-foreground-subtle`}`,children:m(i?b:w,{className:`h-3.5 w-3.5`})})]},e.id)}),m(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:a??m(d,{children:`Dragging one slider splits the rest equally across the unlocked nodes; lock a node to pin its share — locked nodes never move and the total always stays at 100%, so a drag is bounded by the room the unlocked nodes leave. Detection only distributes across nodes that can source a camera’s frames.`})})]})}c();function z(e){let t=e.backend.toLowerCase(),n=e.device.toLowerCase();return e.key===`cpu`||n===`cpu`?{label:`CPU`,Icon:y,hue:`slate`}:t===`openvino`&&n===`npu`?{label:`Intel NPU (AI Boost)`,Icon:g,hue:`sky`}:t===`openvino`&&(n===`gpu`||n===`igpu`)?{label:`Intel iGPU`,Icon:S,hue:`violet`}:t===`edgetpu`?{label:`Coral Edge TPU`,Icon:D,hue:`emerald`}:{label:`${e.backend} ${e.device}`.replace(/\b\w/g,e=>e.toUpperCase()).trim(),Icon:y,hue:`slate`}}var B={sky:`bg-sky-500/12 text-sky-400 ring-sky-500/25`,violet:`bg-violet-500/12 text-violet-400 ring-violet-500/25`,emerald:`bg-emerald-500/12 text-emerald-400 ring-emerald-500/25`,slate:`bg-surface-hover text-foreground-subtle ring-border`};function V({nodeId:t,nodeName:r,isOnline:a}){let s=f(),{data:c,isLoading:g}=e({nodeId:t},{refetchInterval:15e3}),v=o({onSettled:()=>{s.invalidateQueries({queryKey:[`pipelineOrchestrator`,`getNodeInferenceDevices`]})}}),y=c?.devices??[],b=c?.reachable??a,[S,w]=p({});h(()=>{w(Object.fromEntries(y.map(e=>[e.key,{enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}])))},[y.map(e=>`${e.key}:${e.enabled}:${e.weight}:${e.maxSessions}:${JSON.stringify(e.steps??{})}`).join(`|`)]);let T=u(()=>y.filter(e=>S[e.key]?.enabled??e.enabled).length,[y,S]),[D,O]=p(null),k=D??T>0,A=e=>{let n=y.map(t=>{let n=e[t.key]??j(t);return{key:t.key,enabled:n.enabled,weight:n.weight,maxSessions:n.maxSessions,steps:n.steps}});v.mutate({agentNodeId:t,inferenceDevices:N(n)})},j=e=>({enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}),M=e=>{if(!e.available)return;let t=S[e.key]??j(e),n={...S,[e.key]:{...t,enabled:!t.enabled}};w(n),A(n)},P=(e,t)=>{let n=S[e.key]??j(e),r={...S,[e.key]:{...n,maxSessions:t}};w(r),A(r)},F=u(()=>y.filter(e=>(S[e.key]?.enabled??e.enabled)&&e.available),[y,S]),I=u(()=>F.map(e=>({id:e.key,name:z(e).label,weight:S[e.key]?.weight??e.weight})),[F,S]);return l(`div`,{className:`rounded-lg border border-border bg-surface/60`,children:[l(`button`,{type:`button`,onClick:()=>O(!k),className:`flex w-full items-center gap-2.5 px-3.5 py-2.5 text-left`,"aria-expanded":k,children:[m(_,{className:`h-4 w-4 shrink-0 text-foreground-subtle transition-transform ${k?`rotate-90`:``}`}),m(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:r}),m(`span`,{className:`ml-auto flex items-center gap-2 text-[11px]`,children:b?T>=2?l(`span`,{className:`inline-flex items-center gap-1 text-emerald-400`,children:[m(C,{className:`h-3.5 w-3.5`}),T,` accelerators`]}):T===1?m(`span`,{className:`text-foreground-subtle`,children:`single default`}):m(`span`,{className:`text-foreground-subtle/70`,children:`auto default`}):l(`span`,{className:`inline-flex items-center gap-1 text-foreground-subtle`,children:[m(x,{className:`h-3.5 w-3.5`}),` unreachable`]})})]}),k&&l(`div`,{className:`space-y-3 border-t border-border px-3.5 py-3`,children:[b?g&&y.length===0?m(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`Probing accelerators…`}):y.length===0?m(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No inference devices reported by this node's platform probe.`}):m(`ul`,{className:`space-y-2`,children:y.map(e=>{let t=z(e),r=S[e.key]??j(e),a=r.enabled&&e.available;return l(`li`,{className:`flex items-center gap-3 rounded-lg border px-3 py-2.5 transition-colors ${e.available?a?`border-primary/40 bg-primary/[0.04] ring-1 ring-inset ring-primary/20`:`border-border bg-surface`:`border-border/60 bg-background opacity-55`}`,children:[m(`span`,{className:`grid h-9 w-9 shrink-0 place-items-center rounded-md ring-1 ring-inset ${B[t.hue]}`,children:m(t.Icon,{className:`h-4.5 w-4.5`})}),l(`div`,{className:`min-w-0 flex-1`,children:[l(`div`,{className:`flex items-center gap-2`,children:[m(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t.label}),m(n,{variant:`default`,style:`outline`,className:`font-mono text-[9px]`,children:e.format}),!e.available&&m(n,{variant:`warning`,className:`text-[9px]`,children:`unavailable`})]}),l(`div`,{className:`mt-0.5 flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[m(`span`,{className:`font-mono`,children:e.key}),!a&&l(d,{children:[m(`span`,{"aria-hidden":!0,children:`·`}),l(`span`,{children:[`default model`,` `,m(`span`,{className:`font-mono text-foreground/80`,children:e.defaultModelId})]})]})]})]}),a&&l(`label`,{className:`flex shrink-0 items-center gap-1 text-[10px] text-foreground-subtle`,children:[m(`span`,{className:`hidden @sm/clustertab:inline`,children:`cap`}),m(`input`,{type:`number`,min:1,placeholder:`∞`,value:r.maxSessions??``,onChange:t=>{let n=t.target.value.trim(),r=n===``?null:Number.parseInt(n,10);P(e,r!=null&&r>0?r:null)},disabled:v.isPending,"aria-label":`Max concurrent sessions for ${t.label}`,className:`w-14 rounded border border-border bg-background px-1.5 py-1 text-right font-mono text-[11px] text-foreground focus:border-primary focus:outline-none`})]}),m(i,{checked:a,onCheckedChange:()=>M(e),disabled:!e.available||v.isPending,"aria-label":`Enable ${t.label}`,className:e.available?``:`cursor-not-allowed opacity-50`})]},e.key)})}):m(H,{}),b&&F.length>=2&&l(`div`,{className:`space-y-3 rounded-lg border border-border bg-background/60 p-3.5`,children:[l(`h4`,{className:`flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:[m(E,{className:`h-3.5 w-3.5`}),`Balancer weight`]}),m(R,{nodes:I,pending:v.isPending,onCommitWeights:e=>{let t={...S};for(let n of e){let e=t[n.nodeId];e&&(t[n.nodeId]={...e,weight:n.weight})}w(t),A(t)},weightLabel:`Balancer weight`,footnote:m(d,{children:`Drag to shift the share of detection sessions each accelerator handles; lock one to pin its share while the others rebalance. Shares always sum to 100%.`})})]}),v.isError&&l(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px] text-danger`,children:[`Failed to save inference devices:`,` `,v.error instanceof Error?v.error.message:`unknown error`]})]})]})}function H(){return l(`div`,{className:`flex flex-col items-center gap-2 rounded-lg border border-dashed border-border bg-background px-4 py-8 text-center`,children:[m(x,{className:`h-6 w-6 text-foreground-subtle/60`}),m(`p`,{className:`text-xs font-medium text-foreground`,children:`Node unreachable`}),m(`p`,{className:`max-w-sm text-[11px] text-foreground-subtle`,children:`The platform probe couldn't be reached, so its live accelerator set is unavailable. Settings resume once the node reconnects.`})]})}export{k as a,T as c,N as i,C as l,z as n,M as o,R as r,O as s,V as t};