@camstack/addon-admin-ui 1.1.61 → 1.1.63

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 (94) hide show
  1. package/dist/assets/{AddLocationWizard-bhaoQHmi.js → AddLocationWizard-VuBsssbs.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-CDqyaaBM.js → AddonCollectionPage-rY0iw4Lx.js} +1 -1
  3. package/dist/assets/Addons-waDrxMrF.js +1 -0
  4. package/dist/assets/{AdminTabs-DuXQHrHl.js → AdminTabs-DdlxkzYF.js} +1 -1
  5. package/dist/assets/{AiProfiles-D5XjlwmU.js → AiProfiles-CXfreEns.js} +1 -1
  6. package/dist/assets/{BrokerForm-Baz2aj-M.js → BrokerForm-Bi1zDzJU.js} +1 -1
  7. package/dist/assets/{Capabilities-DvWcCLd-.js → Capabilities-CBqnCVAQ.js} +1 -1
  8. package/dist/assets/{CapabilityBadges-Bi6Tc2CY.js → CapabilityBadges-bb3Kp76B.js} +1 -1
  9. package/dist/assets/{Cluster-DcCFkNFk.js → Cluster-CkmNDo_z.js} +1 -1
  10. package/dist/assets/{ClusterRecordingTab-B7HSeqkq.js → ClusterRecordingTab-qj7qdRav.js} +1 -1
  11. package/dist/assets/{Dashboard-hskGR5xq.js → Dashboard-0L-WtwHw.js} +1 -1
  12. package/dist/assets/{Data-Dis-z_X0.js → Data-B-KdcyYb.js} +1 -1
  13. package/dist/assets/{DetectionIntelligence-CA3LMzt1.js → DetectionIntelligence-DH2CerYz.js} +1 -1
  14. package/dist/assets/DeviceDetail-C0xHmlNy.js +2 -0
  15. package/dist/assets/{Devices-DNxov4qw.js → Devices-BqWTi9bF.js} +1 -1
  16. package/dist/assets/{EmbedPlayerPage-hw9jA2hT.js → EmbedPlayerPage-BmllV_ir.js} +1 -1
  17. package/dist/assets/{Events-BaEa4hl0.js → Events-Cg33ehHw.js} +1 -1
  18. package/dist/assets/{FormBuilder-pVzTAhbz.js → FormBuilder-DDOu77Pz.js} +1 -1
  19. package/dist/assets/Identity-DokGTNX5.js +1 -0
  20. package/dist/assets/{IntegrationDetail-DgaohpFt.js → IntegrationDetail-HKDhoWtW.js} +1 -1
  21. package/dist/assets/{Integrations-ddV6H8iR.js → Integrations-as3Ez0fd.js} +1 -1
  22. package/dist/assets/{Integrations-CLAnn2sl.js → Integrations-qqFL0Gs0.js} +1 -1
  23. package/dist/assets/{Logs-C-l_222o.js → Logs-C0i-qXwM.js} +1 -1
  24. package/dist/assets/{MotionZonesSettings-QJdI6XiU.js → MotionZonesSettings-rxIHdY6l.js} +1 -1
  25. package/dist/assets/{MyAccess-C-2QbLht.js → MyAccess-52fP18AF.js} +1 -1
  26. package/dist/assets/Network-s1InxtpH.js +1 -0
  27. package/dist/assets/NodeAddonsSettingsPanel-PSaY411C.js +1 -0
  28. package/dist/assets/NodeInferenceDevices-CoLAPH96.js +1 -0
  29. package/dist/assets/{NotificationTargets-CuVPNUqr.js → NotificationTargets-BYTjEwxL.js} +1 -1
  30. package/dist/assets/Pipeline-D3jI3Huf.js +1 -0
  31. package/dist/assets/{Plates-DdLC_wRY.js → Plates-BwI8RHl9.js} +1 -1
  32. package/dist/assets/{PrivacyMaskSettings-Bo-FkVZR.js → PrivacyMaskSettings-DDk6LoXQ.js} +1 -1
  33. package/dist/assets/{ProviderIcon-CnbzzcMq.js → ProviderIcon-CWyyzoZB.js} +1 -1
  34. package/dist/assets/{Recordings-D4cmFzZr.js → Recordings-D5IKi_ba.js} +1 -1
  35. package/dist/assets/{ScanNetworkModal-C6i9aK6q.js → ScanNetworkModal-B2bUhuZ1.js} +1 -1
  36. package/dist/assets/{Settings-phbzuilC.js → Settings-DKkqVGNC.js} +1 -1
  37. package/dist/assets/{Showroom-DmDq_i4m.js → Showroom-ablwi-TX.js} +1 -1
  38. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DHhQMm3y.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CCcHjOIo.js} +1 -1
  39. package/dist/assets/{build-cluster-graph-CZpvG2DP.js → build-cluster-graph-C1vd_7m_.js} +1 -1
  40. package/dist/assets/circle-check-big-GmO5fdEl.js +1 -0
  41. package/dist/assets/clock-OUNfpFX_.js +1 -0
  42. package/dist/assets/{copy-DF0dst5T.js → copy-St-1O01R.js} +1 -1
  43. package/dist/assets/{debounced-invalidate-D_V-nbWY.js → debounced-invalidate-DlIKzA73.js} +1 -1
  44. package/dist/assets/{dist-Bhw1R8vS.js → dist-CYW0dAGQ.js} +1 -1
  45. package/dist/assets/dist-D7nNU2QV.js +7 -0
  46. package/dist/assets/{download-CHtMXSyD.js → download-CJ-1cdDh.js} +1 -1
  47. package/dist/assets/{face-bbox-DgibKOZL.js → face-bbox-CTcnAI8I.js} +1 -1
  48. package/dist/assets/{hostInit-tj-M5EQ9.js → hostInit-D4IGCyt3.js} +1 -1
  49. package/dist/assets/index-BKBKdGDb.css +2 -0
  50. package/dist/assets/index-Cjto-EXm.js +4 -0
  51. package/dist/assets/{key-round-e-ZWFR-B.js → key-round-LcTErOxf.js} +1 -1
  52. package/dist/assets/{mf-entry-bootstrap-0-eabd788d.js → mf-entry-bootstrap-0-c57c6485.js} +2 -2
  53. package/dist/assets/{pencil-B3cC4tAQ.js → pencil-BkXeyiDf.js} +1 -1
  54. package/dist/assets/{player-overlays-QWBHo29P.js → player-overlays-BfnV1C0Q.js} +1 -1
  55. package/dist/assets/plus-DXXZ8pd7.js +1 -0
  56. package/dist/assets/{radio-DJUawWOR.js → radio-CGyv3voN.js} +1 -1
  57. package/dist/assets/{refresh-cw-CPElSd1E.js → refresh-cw-DC4KMLsa.js} +1 -1
  58. package/dist/assets/remoteEntry-CXtVdVO7.js +1 -0
  59. package/dist/assets/{rotate-ccw-Dp3LyyNb.js → rotate-ccw-DlNmHkpr.js} +1 -1
  60. package/dist/assets/rotate-cw-d8IjPUYX.js +1 -0
  61. package/dist/assets/search-DkClo4ZA.js +1 -0
  62. package/dist/assets/{send-BHy3n_wg.js → send-CeJ2J9V3.js} +1 -1
  63. package/dist/assets/{server-jWz5lmi4.js → server-CArIZ-KL.js} +1 -1
  64. package/dist/assets/square-BFjZ9GUs.js +1 -0
  65. package/dist/assets/{square-check-big-XDhdJZmb.js → square-check-big--y441eG8.js} +1 -1
  66. package/dist/assets/src-CCZM6rtM.js +7 -0
  67. package/dist/assets/src-CfZUxvPx.js +67 -0
  68. package/dist/assets/{upload-D3TVf2zJ.js → upload-D6H_84gF.js} +1 -1
  69. package/dist/assets/{useEventInvalidation-CguqAy76.js → useEventInvalidation-DxjiYIcd.js} +1 -1
  70. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BU8EM8C6.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-zgU2Aw4J.js} +2 -2
  71. package/dist/assets/{wifi-CjcdCR8p.js → wifi-B0toFYT9.js} +1 -1
  72. package/dist/assets/{zap-WvYWjJ23.js → zap-d6IKZFEN.js} +1 -1
  73. package/dist/index.html +6 -6
  74. package/dist/server/addon.js +128 -33
  75. package/package.json +1 -1
  76. package/dist/assets/Addons-D1gjFdsg.js +0 -1
  77. package/dist/assets/DeviceDetail-Ck8YpUxr.js +0 -2
  78. package/dist/assets/Identity-bmeRqIbV.js +0 -1
  79. package/dist/assets/Network-_lS0ynPr.js +0 -1
  80. package/dist/assets/NodeAddonsSettingsPanel-BYlipjiY.js +0 -1
  81. package/dist/assets/Pipeline-C4AUuZCt.js +0 -1
  82. package/dist/assets/circle-check-big-CPxj2KQE.js +0 -1
  83. package/dist/assets/clock-2ZdTSOML.js +0 -1
  84. package/dist/assets/dist-CGJaNSH2.js +0 -7
  85. package/dist/assets/index-BOnUkW6K.js +0 -4
  86. package/dist/assets/index-Cmef4Jek.css +0 -2
  87. package/dist/assets/plus-DaxL0ZPp.js +0 -1
  88. package/dist/assets/remoteEntry-BZgTphE5.js +0 -1
  89. package/dist/assets/rotate-cw-Bq5FdMBy.js +0 -1
  90. package/dist/assets/search-sOe8umG9.js +0 -1
  91. package/dist/assets/square-Df6rn0vR.js +0 -1
  92. package/dist/assets/src-Ck8eP0y_.js +0 -7
  93. package/dist/assets/src-DP-u1HtQ.js +0 -67
  94. package/dist/assets/useDevice-DqpXrha7.js +0 -1
@@ -1,2 +0,0 @@
1
- import{$ as e,$a as t,An as n,Bn as r,Bt as i,Cn as a,D as o,Di as s,Dn as c,E as l,En as u,F as d,Fa as f,Gn as p,H as m,Hn as h,In as g,J as _,Ja as v,Ji as y,Ka as b,Kn as x,Ln as S,Ma as C,Mn as w,N as T,Na as E,Ni as D,Nn as ee,O,Oi as te,P as ne,Pr as re,Q as k,Rn as A,Sn as j,T as M,To as N,Tt as P,U as ie,Un as ae,Vn as F,Vr as I,W as L,Wa as oe,Wn as se,X as R,Xa as ce,Y as le,Ya as ue,Z as de,Za as fe,_i as pe,_n as me,_r as he,a as ge,at as z,cn as B,eo as _e,et as ve,f as ye,fa as be,fi as xe,g as Se,gr as Ce,hi as we,hn as Te,i as Ee,io as De,jn as Oe,kn as ke,l as Ae,m as je,n as Me,no as Ne,o as Pe,ot as Fe,p as Ie,pa as Le,r as Re,rt as ze,sn as Be,st as Ve,ti as He,to as Ue,tt as We,u as Ge,ur as Ke,vr as qe,wo as Je,y as Ye,zn as Xe}from"./src-DP-u1HtQ.js";import{I as Ze,K as V,Q as H,S as U,W,a as Qe,b as $e,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,E as Y,M as rt,O as it,S as at,V as ot,W as st,j as ct,k as lt,v as ut,w as dt,x as ft}from"./src-Ck8eP0y_.js";import{c as pt,k as mt,p as X,r as ht,t as gt,u as _t}from"./player-overlays-QWBHo29P.js";import{t as vt}from"./CapabilityBadges-Bi6Tc2CY.js";import{n as yt,t as bt}from"./rotate-ccw-Dp3LyyNb.js";import{t as xt}from"./ProviderIcon-CnbzzcMq.js";import{n as St,t as Ct}from"./FormBuilder-pVzTAhbz.js";import{i as wt,n as Tt,t as Et}from"./useDevice-DqpXrha7.js";import{t as Dt}from"./pencil-B3cC4tAQ.js";import{t as Ot}from"./plus-DaxL0ZPp.js";import{t as kt}from"./refresh-cw-CPElSd1E.js";import{t as At}from"./rotate-cw-Bq5FdMBy.js";import{t as jt}from"./server-jWz5lmi4.js";import{t as Mt}from"./wifi-CjcdCR8p.js";import{A as Nt,J as Pt,K as Ft,L as It,S as Lt,U as Rt,V as zt,W as Bt,a as Vt,c as Ht,i as Ut,j as Wt,m as Gt,q as Kt,r as qt,s as Jt,t as Yt,v as Xt,y as Zt,z as Qt}from"./index-BOnUkW6K.js";import{t as $t}from"./StatusBadge-Dcr2bw58.js";import{t as en}from"./useEventInvalidation-CguqAy76.js";import{n as tn,r as nn,t as rn}from"./SchemaTabBar-DhsmEGyn.js";var an=Bt(`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`}]]),on=Bt(`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`}]]),sn=Bt(`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=Bt(`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=Bt(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),un=Bt(`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`}]]);H();function dn({parentDeviceId:e}){let{t}=Yt(),n=Ft(),r=X(),{data:i,isLoading:a,isError:o}=Tt(e),{data:s}=u({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 c=(i??[]).filter(e=>e.display?.hidden!==!0);if(c.length===0)return null;let l=R(s?.stableId??``,c,s?.childLayout),d=l.ungrouped,f=e=>n(`/devices/${String(e)}`),p=s?.name??``,m=(e,t)=>q(_,{trpc:r.trpcClient,device:{...t,name:ve(t,p)},variant:`minimal`,onNavigate:f},e),h=d.some(e=>!!e.role),g=d.some(e=>!e.role),v=h&&!g?t(`device.accessories`,{defaultValue:`Accessories`}):!h&&g?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),y=d.length>0?U(`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=l.disabledSection===void 0?null:q(le,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:l.disabledSection.children.length,defaultOpen:!1,children:q(`div`,{className:`opacity-60 space-y-1`,children:l.disabledSection.children.map(e=>m(e.id,e))})},l.disabledSection.title);return l.sections.length===0?b===null?y:U(`div`,{className:`space-y-2`,children:[y,b]}):U(`div`,{className:`space-y-2`,children:[l.sections.map(e=>q(le,{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 U(`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(xt,{type:n,size:`lg`}),U(`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})]}),U(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[q($t,{status:r?`online`:`offline`}),i.length>0&&q(vt,{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=Be({deviceId:e},{refetchInterval:1e4,retry:!1}),r=B({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),i=W(()=>mn(n.data??[]),[n.data]);return U(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[U(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[q(hn,{label:`Discovered`,value:i.total,icon:q(Xt,{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}),U(`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(Lt,{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`})]})]}),U(`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(Zt,{className:`h-3 w-3 text-amber-500`}),label:`${i.sleeping} sleeping`}),q(gn,{icon:q(Vt,{className:`h-3 w-3 text-destructive`}),label:`${i.offline} offline`}),i.unknown>0?q(gn,{icon:q(an,{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 U(`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:[U(`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 U(`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(E,{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(C,{trpc:X().trpcClient,deviceId:e,features:t})})}H();function yn({dev:e,busy:t,setBusy:n}){let r=e?.motionTrigger,i=_t(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 U(`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(Rt,{className:`h-3 w-3`}),q(`span`,{children:a?s?`Disabling…`:`Enabling…`:c?s?`On motion: on`:`On motion: off`:`On motion: …`})]})}H();function Z({deviceId:e,deviceType:t,features:n}){let r=X(),i=Fe(t)?.HeroCard??C,a=pt(r.trpcClient,e),o=_t(a?.state.deviceStatus),[s,c]=K(!1),l=o!==void 0&&o.online===!1,u=l?o.lastChangedAt:null;return U(`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(L,{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}=Et(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(ie,{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]:vn,[Y.EventEmitter]:vn,[Y.Notifier]:vn,[Y.Script]:vn,[Y.Automation]:vn,[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 q(xn[e.deviceType]??fn,{...e})}function Cn(e){return ge(X().trpcClient,e)}H();function wn(e){let[t,n]=K(`idle`),[r,i]=K(null),a=V(null),o=V(null),s=V(null),c=V(!0),l=he(),u=Ce(),d=qe(),f=Ze(()=>{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=Ze(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=Ze(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`}}H();var Tn=0;function Q(){return++Tn}function En(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function Dn(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 On(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 kn(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 An({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: ${En(e)} — type help or context for available commands`}),n}),[o,s]=K(``),[c,l]=K([]),[u,d]=K(-1),f=V(null),p=V(null);J(()=>{let e=p.current;e&&(e.scrollTop=e.scrollHeight)},[i]);let m=Ze(()=>{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: ${En(e)}`}]),s(``);return}if(n===`help`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...Dn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`context`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...kn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`examples`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...On(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: ${En(e)}`}]))}let v={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return U(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${n??``}`,onClick:m,children:[U(`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`})]}),U(`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 jn({deviceId:e,intercomAvailable:t=!1}){let n=X(),r=typeof window<`u`?window.location.origin:``,i=Number.isFinite(e),a=Cn(i?e:null),{streams:o,pipelineMetrics:s,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h}=Ee(n.trpcClient,i?e:null),g=k(n.trpcClient,i?e:null),_=wn(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=ht(),S=O(),C=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,w=x.length>0?q($e,{children:x.map(e=>q(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return q(Ye,{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:w,chromeless:!0,className:`h-full`})}function Mn({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full`,children:q(Se,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):U(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function Nn({deviceId:e}){if(!Number.isFinite(e))return U(`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(An,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function Pn({deviceId:e}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:q(je,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):U(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function Fn({deviceId:e}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:q(ye,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):U(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function In({deviceId:e}){let t=G(),n=Number.isFinite(e),{data:r}=u({deviceId:e},{enabled:n}),i=typeof r?.type==`string`?r.type:`camera`;en([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:o,isLoading:s,isError:c,error:l}=a({deviceId:e},{enabled:n}),{data:d}=w({deviceType:i},{enabled:!!i}),f=se({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(s)return q(`div`,{className:`p-4`,children:q(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(c)return U(`div`,{className:`p-4 text-xs text-red-400`,children:[`Failed to load bindings: `,l instanceof Error?l.message:String(l)]});let p=new Map,m={};for(let e of d??[])m[e.capName]=e.wrappers;for(let e of o?.entries??[])p.set(e.capName,{...e,wrappers:m[e.capName]??[]});for(let e of d??[])p.has(e.capName)||p.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let h=[...p.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(h.length===0)return U(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[q(yt,{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 U(`div`,{className:`flex flex-col gap-3 p-1`,children:[U(`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(ce,{columns:[{key:`capability`,header:`Capability`,render:e=>q(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>q(Ln,{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(Rn,{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(zn,{wrappers:t.wrappers,activeWrapperId:n,disabled:f.isPending,onPick:r=>{let i=n===r;f.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}],rows:h,rowKey:e=>e.capName,minWidthPx:720})]})}function Ln({kind:e}){return e===`native`?U(`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`?U(`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(on,{className:`h-3 w-3`}),`wrapped`]}):e===`linked`?U(`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`]}):U(`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(wt,{className:`h-3 w-3`}),`unbound`]})}function Rn({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 zn({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 U(`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?It:bt,{className:`h-3 w-3`}),e]},e)})})}H();function Bn({schema:e,values:t,pendingKeys:n,onChange:r,onAction:i,onSave:a,onDiscard:o,disabled:s,activeSubTab:c,onSubTabChange:l,flattenTabs:u=!1,deviceId:d}){let f=e.tabs??[],p=W(()=>{let t=new Map;for(let n of e.sections){let e=n.tab??`general`,r=t.get(e)??[];r.push(n),t.set(e,r)}return t},[e.sections]),m=new Set(f.map(e=>e.id)),h=[...f,...[...p.keys()].filter(e=>!m.has(e)).map(e=>({id:e,label:e,icon:`wrench`,order:100}))],g=h[0]?.id??`general`,[_,v]=K(g),y=l!==void 0,b=new Set(h.map(e=>e.id)),x=y?c&&b.has(c)?c:g:b.has(_)?_:g,S=e=>{y?l(e):v(e)},C=p.get(x)??[],w={sections:C.length<=1?C.length===1?[{...C[0],title:``}]:C:C.every(e=>!e.title)?[{...C[0],title:``,fields:C.flatMap(e=>e.fields)}]:C},T=q(tn,{pendingCount:n.length,onSave:()=>a(n),onDiscard:()=>o(n),saving:s});if(u||h.length<=1)return U(`div`,{className:`flex flex-col gap-3`,children:[q(Ct,{schema:e,values:t,onChange:r,onAction:i,disabled:s,deviceId:d}),T]});let E=new Map,D=new Map;for(let[e,t]of p){E.set(e,t.length);let r=new Set,i=e=>{for(let t of e)if(`key`in t&&typeof t.key==`string`&&r.add(t.key),t.type===`group`)i(t.fields);else if(t.type===`sub-tabs`)for(let e of t.tabs)i(e.fields)};for(let e of t)i(e.fields);let a=n.filter(e=>r.has(e)).length;a>0&&D.set(e,a)}return U(`div`,{className:`flex flex-col gap-3`,children:[q(rn,{tabs:h.map(e=>({id:e.id,label:e.label})),activeId:x,onChange:S,countByTab:E,pendingByTab:D}),q(Ct,{schema:w,values:t,onChange:r,onAction:i,disabled:s,deviceId:d}),T]})}var Vn=`device-export`,Hn=`export`,Un=`Export`;function Wn(e){return e.type===`separator`||e.type===`info`||e.type===`object-array`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`?!1:e.type===`group`?e.fields.some(Wn):e.type===`sub-tabs`?e.tabs.some(e=>e.fields.some(Wn)):e.writerCapName===Vn}function Gn(e){return e.fields.some(Wn)}H();function Kn(e,t){return t&&t===`admin`?e:!0}function qn(e){if(!e)return null;let t={sections:[...e.sections].toSorted((e,t)=>{let n=e.tab??`general`,r=t.tab??`general`;return n===r?Gn(e)&&Gn(t)?e.id.localeCompare(t.id):(e.order??0)-(t.order??0):n.localeCompare(r)})};return e.tabs?{...t,tabs:e.tabs}:t}function Jn(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`}function Yn(e){return e.key}function Xn(e){if(!Jn(e))return e.value}function Zn(e){return Jn(e)?null:e}function Qn(e,t){for(let n of e)if(t(n),n.type===`group`)Qn(n.fields,t);else if(n.type===`sub-tabs`)for(let e of n.tabs)Qn(e.fields,t)}function $n(e){if(!e)return{};let t={};for(let n of e.sections)Qn(n.fields,e=>{let n=Yn(e);n!==null&&(t[n]=Xn(e))});return t}function er(e,t){if(!e)return null;let n=null;for(let r of e.sections)if(Qn(r.fields,e=>{if(n!==null||Yn(e)!==t)return;let r=Zn(e);r&&r.writerCapName&&r.writerAddonId&&(n={capName:r.writerCapName,addonId:r.writerAddonId})}),n!==null)break;return n}function tr(e){return{...e,fields:e.fields.map(nr)}}function nr(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`object-array`?e:{...e,readonlyField:!0}}function rr(e,t){return e&&{...e,sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{let n=Zn(e);return n?Kn(t,n.minRole)?e:nr(e):e})}))}}function ir({deviceId:e,sectionFilter:t,activeSubTab:n,onSubTabChange:r,flattenSubTabs:i,subTabGrouping:a}){let o=G(),{user:s}=qt(),l=s?.isAdmin===!0,d=V(!1),{data:f,isLoading:m}=c({deviceId:e},{refetchInterval:()=>d.current?!1:2500,enabled:Number.isFinite(e)}),{data:h}=u({deviceId:e},{enabled:Number.isFinite(e)}),g=f?.settings??null,_=f?.live??null,v=W(()=>{if(!g&&!_)return null;let e=g?.sections??[],n=(_?.sections??[]).map(tr),r=[...e,...n],i=t?r.filter(t):r.filter(e=>e.location!==`top-tab`&&!Gn(e));if(i.length===0)return null;if(a){let e=i.map(e=>({...e,tab:a.groupOf(e)})),t=new Set(e.map(e=>e.tab)),n=a.tabs.filter(e=>t.has(e.id));return n.length>0?{tabs:n,sections:e}:{sections:e}}let o=new Set;for(let e of i)o.add(e.tab??`general`);let s=[...g?.tabs??[],...(_?.tabs??[]).filter(e=>!(g?.tabs??[]).some(t=>t.id===e.id))].filter(e=>o.has(e.id));return s.length>0?{tabs:s,sections:i}:{sections:i}},[g,_,t,a]),y=W(()=>qn(v),[v]),b=W(()=>rr(y,l),[y,l]),C=W(()=>$n(b),[b]),w=Le(),T=be(),E=p(),D=S(),ee=x({onSuccess:()=>{o.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),O={isPending:ee.isPending,mutate:t=>{ee.mutate({deviceId:e,changes:[...t]})}},te=nn({schema:b,serverValues:C,onImmediateSave:Ze(e=>{let t=Object.entries(e).map(([e,t])=>{let n=er(b,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&O.mutate(t)},[b,O]),onDeferredSave:Ze(e=>{let t=Object.entries(e).map(([e,t])=>{let n=er(b,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&O.mutate(t)},[b,O])}),{values:ne,pendingKeys:re,handleChange:k,handleSave:A,handleDiscard:j}=te;if(d.current=te.editingPaused,m)return U(`div`,{className:`flex items-center justify-center py-12 text-foreground-subtle`,children:[q(Lt,{className:`h-4 w-4 animate-spin mr-2`}),q(`span`,{className:`text-xs`,children:`Loading device aggregate…`})]});if(!b||b.sections.length===0)return q(`div`,{className:`text-xs text-foreground-subtle italic py-4 text-center`,children:`No aggregate contributions for this device.`});async function M(t,n,r){if(t===`regenerate-rtsp-token`){let t=[`rtspUrl:`,`regenerateToken:`].find(e=>n.startsWith(e));if(!t)throw Error(`regenerate-rtsp-token: unrecognised key "${n}" (expected "rtspUrl:<streamId>" or "regenerateToken:<streamId>")`);let r=n.slice(t.length);if(!r)throw Error(`regenerate-rtsp-token: key "${n}" has no streamId after prefix`);let i=ot(e,r);await w.mutateAsync({brokerId:i}),o.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]});return}if(t===`test-probe`){if(!h)return{status:`error`,error:`Device metadata not loaded yet`};try{return await E.mutateAsync({addonId:h.addonId,type:h.type,key:n,value:r})}catch(e){return{status:`error`,error:e instanceof Error?e.message:String(e)}}}if(t===`refresh-probe`){if(!n.startsWith(`probedInfo:`))throw Error(`refresh-probe: unrecognised key "${n}" (expected "probedInfo:<streamId>")`);let t=n.slice(11);if(!t)throw Error(`refresh-probe: key "${n}" has no streamId after prefix`);let r=ot(e,t),i=await T.mutateAsync({brokerId:r});return o.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),i}if(t===`device-custom-action`){let t=await D.mutateAsync({deviceId:e,action:n,input:r});return o.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),t}throw Error(`[device-aggregate] unknown action "${t}"`)}return q(Bn,{schema:b,values:ne,pendingKeys:re,onChange:k,onAction:M,onSave:A,onDiscard:j,disabled:O.isPending,activeSubTab:n,onSubTabChange:r,flattenTabs:i,deviceId:e})}function ar({deviceId:e,activeSubTab:t,onSubTabChange:n}){return q(`div`,{className:`flex flex-col gap-3`,children:q(ir,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}H();var or=new Set([`package-detection`]);function sr(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 cr(e){return e?e.enabled!==void 0||e.modelId!==void 0||e.settings!==void 0:!1}function lr({agents:e,currentAgent:t,onPick:n,hint:r}){let[i,a]=K(!1),o=e.filter(e=>e!==t);return o.length===0?null:U(`div`,{className:`relative`,children:[q(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:()=>a(e=>!e),children:`Mirror from ▾`}),r&&q(`div`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:r}),i&&q(`div`,{className:`absolute top-full left-0 mt-1 min-w-[140px] bg-surface border border-border rounded shadow-lg z-10`,children:o.map(e=>q(`button`,{type:`button`,className:`w-full text-left px-3 py-1.5 text-xs hover:bg-muted`,onClick:()=>{a(!1),n(e)},children:e},e))})]})}function ur({deviceId:e,refreshToken:t}){let n=G(),r=X().trpcClient,[i,a]=K(null),[o,c]=K(null),[l,u]=K(null),[d,f]=K(null),p=xe({deviceId:e},{refetchOnMount:`always`}),m=pe(void 0,{refetchOnMount:`always`});en([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let h=I(void 0,{refetchOnMount:`always`}),g=W(()=>{let e=new Set;for(let t of h.data??[])t.isOnline&&e.add(t.id);return e},[h.data]),_=W(()=>(m.data??[]).filter(e=>g.has(e.nodeId)).map(e=>e.nodeId),[m.data,g]),y=_[0]??``,x=He({nodeId:y},{enabled:y!==``,refetchOnMount:`always`}),S=Qe({enabled:_.length>0,queryKey:[[`pipelineExecutor`,`getSchema`],`device-step-formats`,_.join(`,`),t],queryFn:async()=>{let e={};for(let t of _)try{e[t]=(await r.pipelineExecutor.getSchema.query({nodeId:t})).selectedEngine.format}catch{e[t]=`coreml`}return e}}),C=()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]})},w=s({onSuccess:C}),T=te({onSuccess:C}),E=W(()=>x.data?v(x.data):[],[x.data]),D=W(()=>{let e=m.data??[];return(g.size===0?[]:e.filter(e=>g.has(e.nodeId))).map(e=>({agentNodeId:e.nodeId,engineLabel:S.data?.[e.nodeId]??`(engine unknown)`}))},[m.data,S.data,g]),ee=(e,t)=>(m.data?.find(t=>t.nodeId===e))?.settings.addonDefaults[t]??null,O=(e,t,n)=>e?.stepOverridesByAgent?.[t]?.[n]??null,ne=e=>{if(or.has(e))return{kind:`zone-driven`};let t=sr(x.data??null,e)?.enabledByDefault??!0,n=p.data?.stepToggles?.[e];return{kind:`gate`,effectiveOn:n??t,defaultOn:t,explicit:n!==void 0}},re=(e,t)=>{let n=ne(e),r=n.kind===`gate`?n.effectiveOn:!1,i=S.data?.[t];if(!(sr(x.data??null,e)?.models.some(e=>i!==void 0&&!!e.formats[i])??!1))return r?{kind:`skip`}:{kind:`na`};let a=ee(t,e);if(!a)return{kind:`na`};let o=O(p.data??null,t,e);return{kind:`enabled`,modelId:o?.modelId??a.modelId??`Auto`,overridden:cr(o)}},k=i&&x.data?sr(x.data,i.addonId):null,A=i?ee(i.agentNodeId,i.addonId):null,j=i?S.data?.[i.agentNodeId]??`coreml`:`coreml`,M=i?cr(O(p.data??null,i.agentNodeId,i.addonId)):!1,P=()=>{a(null),c(null),u(null)},ie=(e,t)=>{a({addonId:e,agentNodeId:t}),c(O(p.data??null,t,e)),u(null)},ae=(t,n)=>{T.mutate({deviceId:e,addonId:t,enabled:n})},F=e=>{if(!i||!x.data||!m.data)return;let t=m.data.find(t=>t.nodeId===e),n=m.data.find(e=>e.nodeId===i.agentNodeId);if(!t||!n)return;let[r]=N({source:{nodeId:t.nodeId,engine:{format:j},defaults:t.settings.addonDefaults},target:{nodeId:n.nodeId,engine:{format:j},defaults:n.settings.addonDefaults},catalog:x.data,addonIds:[i.addonId]});if(!r){u(`no mirror result`);return}if(r.outcome===`skip`){u(`skipped: ${r.reason??`no candidate`}`);return}c(r.patch),u(`${r.outcome} from ${e}`)},L=()=>{i&&w.mutate({deviceId:e,agentNodeId:i.agentNodeId,addonId:i.addonId,patch:o},{onSuccess:P})},se=()=>{i&&w.mutate({deviceId:e,agentNodeId:i.agentNodeId,addonId:i.addonId,patch:null},{onSuccess:P})};if(m.isLoading||y!==``&&x.isLoading)return q(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(D.length===0)return q(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`No online agents.`});if(!x.data)return q(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let R=i!==null&&k!==null,ce=(m.data??[]).map(e=>e.nodeId);return U(`div`,{className:`relative h-full w-full space-y-3`,children:[U(`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 pick its model. A gated-on step with no model on a node shows a clickable `,q(`span`,{className:`text-amber-500`,children:`⚠ skip`}),` and won't run there.`]}),q(`div`,{className:R?`md:pr-[360px]`:``,children:E.length>0?q(oe,{tree:E,agents:D,gateFor:ne,getCellState:re,onCellClick:ie,selectedCell:i,onSetGate:ae,gateBusy:T.isPending,fallbackNodeId:d,onFallbackNodeChange:f}):q(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),q(ue,{open:R,onClose:P,title:k?.name??``,subtitle:i?`${i.agentNodeId} · ${j}`:``,footer:U($e,{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:!M||w.isPending,onClick:se,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:P,children:`Cancel`}),q(`button`,{type:`button`,disabled:!i||!A||w.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:L,children:w.isPending?`Saving…`:`Save`})]}),children:k&&i&&A?U(`div`,{className:`space-y-4`,children:[q(lr,{agents:ce,currentAgent:i.agentNodeId,onPick:F,hint:l}),q(b,{mode:`device`,addon:k,agentDefault:A,agentNodeId:i.agentNodeId,currentPatch:o,engineFormat:j,onChangePatch:c})]}):U(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-300`,children:[`This node has no compatible model for `,k?.name??`this step`,` on its current engine format, so there is nothing to provision here. Pick a node that supports the step, or install a compatible model on this node.`]})})]})}var dr=[{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`}],fr={"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 pr(e){return fr[e]??`object-detection`}H();var mr=`steps`,hr=`settings`,gr=new Set([mr,hr]);function _r(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}function vr({deviceId:e,activeSubTab:n,onSubTabChange:r}){return U(t,{value:n&&gr.has(n)?n:mr,onValueChange:Ze(e=>{r?.(e)},[r]),className:`flex flex-col`,children:[U(Ue,{className:`flex-shrink-0`,children:[q(Ne,{value:mr,children:`Steps`}),q(Ne,{value:hr,children:`Settings`})]}),q(_e,{value:mr,children:q(ur,{deviceId:e,refreshToken:0})}),q(_e,{value:hr,children:q(ir,{deviceId:e,sectionFilter:_r,subTabGrouping:{groupOf:e=>pr(e.id),tabs:dr}})})]})}function $({label:e,value:t}){return U(`div`,{className:`${mt} 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})]})}H();function yr({deviceId:e,initialName:t}){let n=G(),[r,i]=K(!1),[a,o]=K(t),[s,c]=K(!1),l=V(null);J(()=>{r||o(t)},[t,r]),J(()=>{r&&l.current?.focus()},[r]);let u=F({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:U(`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(It,{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(Ut,{className:`h-3 w-3`})})]})}):q($,{label:`Name`,value:U(`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`})})]})})}H();function br({deviceId:e,initialLocation:t}){let n=G(),[i,a]=K(!1),[o,s]=K(t??``),[c,l]=K(!1),u=V(null),{data:d}=ee(void 0,{enabled:i}),f=d??[];J(()=>{i||s(t??``)},[t,i]),J(()=>{i&&u.current?.focus()},[i]);let p=r({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]})}}),m=W(()=>{let e=o.trim().toLowerCase();return e.length===0?f:f.filter(t=>t.toLowerCase()!==e&&t.toLowerCase().includes(e))},[f,o]),h=o.trim().length>0&&!f.some(e=>e.toLowerCase()===o.trim().toLowerCase()),g=async n=>{let r=(n??o).trim(),i=r.length===0?null:r;if(i===(t??null)){a(!1);return}l(!0);try{await p.mutateAsync({deviceId:e,location:i}),a(!1)}catch{}finally{l(!1)}},_=()=>{s(t??``),a(!1)};return i?q($,{label:`Location`,value:U(`div`,{className:`relative`,children:[U(`div`,{className:`flex items-center gap-1`,children:[q(`input`,{ref:u,type:`text`,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`?g():e.key===`Escape`&&_()},disabled:c,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 g(),disabled:c,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:q(It,{className:`h-3 w-3`})}),q(`button`,{type:`button`,onClick:_,disabled:c,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:q(Ut,{className:`h-3 w-3`})})]}),(m.length>0||h)&&U(`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:[m.map(e=>U(`button`,{type:`button`,onClick:()=>{s(e),g(e)},className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[q(St,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),q(`span`,{className:`truncate`,children:e})]},e)),h&&U(`button`,{type:`button`,onClick:()=>void g(),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`}),U(`span`,{className:`font-medium truncate`,children:[`"`,o.trim(),`"`]})]})]})]})}):q($,{label:`Location`,value:U(`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:()=>a(!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`})})]})})}H();function xr({deviceId:e}){let t=G(),{data:n}=Et(e),{data:r}=Tt(e),[i,a]=K(null),o=h({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=z(s,typeof n.linkDeviceId==`number`?n.linkDeviceId:null,typeof n.primaryChildEntityId==`string`?n.primaryChildEntityId:null);return U($e,{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})]})}H();var Sr=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function Cr(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function wr(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function Tr(){let e=ne(),t=d(),{data:n}=u({deviceId:e??0},{enabled:e!==null}),{data:r}=a({deviceId:e??0},{enabled:e!==null}),i=n??t??null,[o,s]=K(`identity`);if(e===null||!i)return null;let c=String(i.stableId??``),l=String(i.name??``),f=String(i.type??``),p=String(i.addonId??``),m=i.features??[],h=new Set([`device-status`,`feature-probe`,`device-ops`]),g=(r?.entries??[]).filter(e=>e.kind===`native`&&!h.has(e.capName)).map(e=>e.capName),_=m.length>0?m:g,v=i.location??null,y=i.metadata??null,b=y!==null&&Object.keys(y).length>0;return U(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[U(`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`}),b&&U(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[q(Er,{active:o===`identity`,onClick:()=>s(`identity`),label:`Identity`}),q(Er,{active:o===`hardware`,onClick:()=>s(`hardware`),label:`Hardware`})]})]}),(!b||o===`identity`)&&U(`div`,{className:`divide-y divide-border`,children:[q($,{label:`ID`,value:U(`span`,{className:`font-mono text-[11px] text-foreground`,children:[`#${e}`,U(`span`,{className:`ml-1.5 text-foreground-subtle`,children:[`(`,c,`)`]})]})}),q(yr,{deviceId:e,initialName:l}),q(br,{deviceId:e,initialLocation:v}),q(xr,{deviceId:e}),q($,{label:`Type`,value:f}),q($,{label:`Provider`,value:q(xt,{type:p,size:`sm`,showLabel:!0})}),q($,{label:`Capabilities`,value:_.length>0?q(vt,{capabilities:_,showLabels:!0}):q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),b&&o===`hardware`&&q(Dr,{metadata:y})]})}function Er({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=Sr.filter(t=>t in e),n=Object.keys(e).filter(e=>!Sr.includes(e)).toSorted(),r=[...t,...n];return U(`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:Cr(t),value:q(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:wr(e[t])})},t))})]})}H();function Or({deviceId:e}){let[t,n]=K(null),r=Te({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 U(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[U(`div`,{className:`flex items-center justify-between gap-3`,children:[U(`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.`})]}),U(`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})]})}H();var kr={icon:``,label:``,unit:``,precision:``,hidden:!1};function Ar(e){return{icon:e?.icon??``,label:e?.label??``,unit:e?.unit??``,precision:e?.precision===void 0?``:String(e.precision),hidden:e?.hidden===!0}}function jr(e){if(typeof e!=`object`||!e)return;let t=e.unit;return typeof t==`string`?t:void 0}function Mr(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 Nr({deviceId:e}){let t=X(),n=G(),{data:r}=u({deviceId:e},{enabled:e>0}),i=typeof r?.role==`string`?r.role:null,a=i===null?void 0:Ve[i],o=a?.kind===`numeric`,s=Me(t.trpcClient,e,i??``),c=a?.kind===`numeric`?a.canonicalUnit:void 0,l=jr(s)??c,d=l===void 0?void 0:ft(l),f=W(()=>d===void 0?[]:at(d),[d]),[p,m]=K(null),h=p??Ar(r?.display),g=Xe({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),{data:_}=ke({},{staleTime:6e4}),v=ae({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}});if(r===void 0||i===null)return null;let y=e=>{m({...h,...e})},b=()=>{g.mutate({deviceId:e,display:Mr(h)})},x=()=>{m(kr),g.mutate({deviceId:e,display:null})},S=()=>{let e={...h.icon===``?{}:{icon:h.icon},...h.unit===``?{}:{unit:h.unit},...h.precision.trim()!==``&&Number.isFinite(Number.parseInt(h.precision,10))?{precision:Number.parseInt(h.precision,10)}:{}},t={..._?.defaults??{},[i]:e};v.mutate({defaults:t})},C=ze(i).label,w=Object.keys(We);return U(`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`})}),U(`div`,{className:`p-4 space-y-3`,children:[U(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Icon`}),U(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,value:h.icon,onChange:e=>y({icon:e.target.value}),children:[U(`option`,{value:``,children:[`Default (`,C,`)`]}),w.map(e=>q(`option`,{value:e,children:e},e))]})]}),U(`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:C,value:h.label,onChange:e=>y({label:e.target.value})})]}),o&&U(`div`,{className:`grid grid-cols-2 gap-3`,children:[U(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Unit`}),U(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,value:h.unit,onChange:e=>y({unit:e.target.value}),disabled:f.length===0,children:[U(`option`,{value:``,children:[`Source`,l?` (${l})`:``]}),f.map(e=>q(`option`,{value:e,children:e},e))]})]}),U(`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:h.precision,onChange:e=>y({precision:e.target.value})})]})]}),U(`label`,{className:`flex items-center gap-2`,children:[q(`input`,{type:`checkbox`,checked:h.hidden,onChange:e=>y({hidden:e.target.checked})}),q(`span`,{className:`text-sm text-foreground`,children:`Hide from device lists`})]}),U(`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:b,disabled:g.isPending,children:`Save`}),q(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:x,disabled:g.isPending,children:`Reset`}),U(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:S,disabled:v.isPending,title:`Apply this unit / precision / icon as the default for every ${C} sensor`,children:[`Set as default for all `,C,` sensors`]})]})]})]})}function Pr(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function Fr({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(dt.Resyncable),{data:l}=re({deviceId:n??0},{enabled:n!==null&&i,refetchInterval:5e3}),u=l?.streams??{},d=Object.entries(u),f=s.includes(dt.DoorbellButton),p=Re(f?{deviceId:n??void 0,historyLimit:10}:void 0),m=p.latest?Date.now()-p.latest.timestamp<3e4:!1;return U(`div`,{className:`space-y-5`,children:[a&&n!==null&&q(Ie,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),c&&n!==null&&q(Or,{deviceId:n}),i&&n!==null&&q(M,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),f&&q(Ge,{history:p.history,latestIsFresh:m}),i&&n!==null&&q(M,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),i&&d.length>0&&U(`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])=>U(`div`,{className:`px-4 py-2.5`,children:[U(`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})]}),U(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[q(Ir,{label:`Nominal`,value:Pr(t.nominalBitrateKbps??0)}),q(Ir,{label:`Observed`,value:Pr(t.observedBitrateKbps??0)}),q(Ir,{label:`Peak`,value:Pr(t.peakBitrateKbps??0)}),q(Ir,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),q(Tr,{}),o&&n!==null&&q(Nr,{deviceId:n})]})}function Ir({label:e,value:t,warning:n}){return U(`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})]})}H();function Lr(e,t){if(t===`number`){let t=Number(e);return Number.isNaN(t)?e:t}return t===`boolean`?e===`true`:e}function Rr(e,t){let n={};for(let r of e)r.key!==``&&r.value!==``&&(n[r.key]=Lr(r.value,t));return n}function zr(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 Br(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 Vr(e){return e==null?`identity`:e.kind}function Hr({value:e,onChange:t,sourceField:n,targetKind:r}){let[i,a]=K(()=>Vr(e)),[o,s]=K(()=>zr(e,n)),[c,l]=K(()=>e?.kind===`enum-map`&&e.fallback!=null?String(e.fallback):``),[u,d]=K(()=>Br(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=Rr(o,r),n=c===``?void 0:Lr(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(zr(void 0,n)),e===`linear`&&d(Br(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 U(`div`,{className:`flex flex-col gap-3`,children:[U(`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=>U(`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`&&U(`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)=>U(`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`?U(`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`}),U(`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`&&U(`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`}),U(`div`,{className:`grid grid-cols-2 gap-2`,children:[U(`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`})]}),U(`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`})]})]}),U(`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&&U(`div`,{className:`grid grid-cols-2 gap-2`,children:[U(`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`})]}),U(`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 Ur=`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 Wr({mode:e,idPrefix:t,labelPrefix:r,pickerDevices:i,value:a,onChange:o,search:s,onSearchChange:c}){let{data:l}=n({deviceId:a.sourceId??0},{enabled:a.sourceId!=null}),u=l?.caps??[],d=u.find(e=>e.cap===a.cap)?.fields??[],f=e=>{o(e,(u.find(t=>t.cap===e.cap)?.fields??[]).find(t=>t.path===e.fieldPath))},p=e=>{f({sourceId:e===``?null:Number(e),cap:``,fieldPath:``})},m=e=>{f({sourceId:a.sourceId,cap:e,fieldPath:``})},h=e=>{f({sourceId:a.sourceId,cap:a.cap,fieldPath:e})};return U($e,{children:[e===`global`&&c&&U(`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:s??``,placeholder:`Filter by name, stable id or #id`,onChange:e=>c(e.target.value),className:Ur})]}),U(`div`,{children:[U(`label`,{htmlFor:`${t}-device`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:[r,` device`]}),U(`select`,{id:`${t}-device`,value:a.sourceId??``,onChange:e=>p(e.target.value),className:Ur,children:[q(`option`,{value:``,children:`— select a device —`}),i.map(e=>U(`option`,{value:e.id,children:[e.name??e.stableId,` (#`,e.id,`)`]},e.id))]})]}),U(`div`,{children:[U(`label`,{htmlFor:`${t}-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:[r,` cap`]}),U(`select`,{id:`${t}-cap`,value:a.cap,disabled:a.sourceId==null,onChange:e=>m(e.target.value),className:Ur,children:[q(`option`,{value:``,children:`— select a cap —`}),u.map(e=>q(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),U(`div`,{children:[U(`label`,{htmlFor:`${t}-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:[r,` field`]}),U(`select`,{id:`${t}-field`,value:a.fieldPath,disabled:a.cap===``,onChange:e=>h(e.target.value),className:Ur,children:[q(`option`,{value:``,children:`— select a field —`}),d.map(e=>U(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]})}function Gr(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 Kr(e){return e===null?`null`:typeof e==`number`?`number`:typeof e==`boolean`?`boolean`:`string`}function qr(e){return e===null?``:String(e)}H();var Jr=`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`,Yr=`min, max, abs, round, floor, ceil, sqrt, pow, clamp, avg, sum, coalesce, age, convert`,Xr=0;function Zr(){return Xr+=1,`b${Xr}`}function Qr(e){return{key:Zr(),name:e,mode:`sibling`,sourceId:null,cap:``,fieldPath:``,search:``,literalType:`number`,literalText:``,sampleText:``}}function $r(e,t,n){if(e===null)return[Qr(`a`)];let r=[];for(let[i,a]of Object.entries(e.bindings)){if(a.kind===`literal`){r.push({...Qr(i),mode:`literal`,literalType:Kr(a.value),literalText:qr(a.value)});continue}if(a.kind===`global`){r.push({...Qr(i),mode:`global`,sourceId:t.find(e=>e.stableId===a.sourceStableId)?.id??null,cap:a.cap,fieldPath:a.fieldPath});continue}r.push({...Qr(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:[Qr(`a`)]}function ei(e,t,n){if(e.mode===`literal`){let t=Gr(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 ti(e){if(e.mode===`literal`)return Gr(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 ni({devices:e,siblings:t,targetDeviceId:n,containerStableId:r,initial:i,onChange:a}){let[o,s]=K(i?.expr??``),[c,l]=K(()=>$r(i,e,r)),u=W(()=>{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=ei(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=W(()=>it({expr:u.source.expr,bindings:u.source.bindings}),[u.source]),f=W(()=>{if(o.trim()===``)return null;let e=lt(o);return e.ok?null:e.error},[o]),p=W(()=>{if(u.source.expr.trim()===``)return null;let e={};for(let t of c){let n=t.name.trim();n!==``&&(e[n]=ti(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`:ct.test(t)?rt.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,Qr(ri(e))])},v=e=>{l(t=>t.length<=1?t:t.filter(t=>t.key!==e))};return U(`div`,{className:`flex flex-col gap-3`,children:[U(`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(ii,{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`})]}),U(`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:`${Jr} font-mono resize-y`}),U(`p`,{className:`mt-1 text-[10px] text-foreground-subtle/60`,children:[`Functions: `,Yr]}),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})]}),U(`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 ri(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 ii({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 U(`div`,{className:`flex flex-col gap-2 rounded-md border border-border/60 p-2`,children:[U(`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:`${Jr} max-w-[8rem] font-mono`}),U(`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:`${Jr} 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&&U(`span`,{className:`text-[10px] text-danger`,children:[`name: `,a]}),e.mode===`literal`?U(`div`,{className:`flex items-center gap-2`,children:[U(`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:`${Jr} 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:Jr})]}):U($e,{children:[q(Wr,{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:`${Jr} text-[10px]`})]})]})}H();function ai(e,t,n){return(n===void 0?[e,t]:[e,n,t]).map(e=>e.replace(/[^a-z0-9]/gi,`-`)).join(`-`)}function oi(e,t,n){let r=`${t}-${e}`;return n.find(e=>e.stableId===r)?.id??null}function si(e,t){return t.find(t=>t.stableId===e)?.id??null}function ci(e){return e==null?`sibling`:e.source.kind===`literal`?`literal`:e.source.kind===`global`?`global`:e.source.kind===`expression`?`expression`:`sibling`}function li(e){return e==null||e.source.kind!==`literal`?`string`:Kr(e.source.value)}function ui(e){return e==null||e.source.kind!==`literal`?``:qr(e.source.value)}function di({deviceId:e,parentDeviceId:t,deviceStableId:r,initial:i,onSave:a,onCancel:o}){let{data:s}=Oe({}),c=s??[],l=t==null?r:c.find(e=>e.id===t)?.stableId??r,u=c.filter(n=>n.parentDeviceId===t&&n.id!==e),{data:d}=n({deviceId:e,includeSynthesizable:!0}),f=d?.caps??[],p=i!=null&&(i.source.kind===void 0||i.source.kind===`field`)?i.source:null,m=i!=null&&i.source.kind===`global`?i.source:null,h=i!=null&&i.source.kind===`expression`?i.source:null,g=p==null?m==null?null:si(m.sourceStableId,c):oi(p.sourceKey,l,c),[_,v]=K(ci(i)),[y,b]=K(i?.target.cap??``),[x,S]=K(i?.target.fieldPath??``),[C,w]=K(i?.target.itemKey??``),[T,E]=K(g),[D,ee]=K((p??m)?.cap??``),[O,te]=K((p??m)?.fieldPath??``),[ne,re]=K(void 0),[k,A]=K(``),[j,M]=K(li(i)),[N,P]=K(ui(i)),[ie,ae]=K(h),[F,I]=K(i?.transform);J(()=>{if((p??m)==null||T!==null||c.length===0)return;let e=p==null?m==null?null:si(m.sourceStableId,c):oi(p.sourceKey,l,c);e!==null&&E(e)},[p,m,T,c,l]);let L=f.find(e=>e.cap===y)?.fields??[],oe=L.find(e=>e.path===x),se=oe?.item===!0,R=k.trim().toLowerCase(),ce=c.filter(t=>t.id===e?!1:R===``?!0:t.name.toLowerCase().includes(R)||t.stableId.toLowerCase().includes(R)||String(t.id).includes(R)),le=_===`global`?ce:u,ue=e=>{b(e),S(``),w(``)},de=e=>{e!==`sibling`&&e!==`global`&&e!==`literal`&&e!==`expression`||(v(e),E(null),ee(``),te(``),re(void 0),A(``))},fe=Gr(j,N),pe=_===`literal`?fe!==null:_===`expression`?ie!==null:T!=null&&D!==``&&O!==``,me=y!==``&&x!==``&&(!se||C.trim()!==``)&&pe,he=()=>{if(_===`literal`)return fe===null?null:{kind:`literal`,value:fe.value};if(_===`expression`)return ie;let e=c.find(e=>e.id===T);if(!e||D===``||O===``)return null;if(_===`global`)return{kind:`global`,sourceStableId:e.stableId,cap:D,fieldPath:O};let t=`${l}-`;return{sourceKey:e.stableId.startsWith(t)?e.stableId.slice(t.length):``,cap:D,fieldPath:O}},ge=()=>{if(!me)return;let e=he();if(e===null)return;let t=se?C.trim():void 0;a({id:i?.id??ai(y,x,t),source:e,target:{cap:y,fieldPath:x,...t===void 0?{}:{itemKey:t}},...F==null?{}:{transform:F}})},z=`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none disabled:opacity-50`;return U(`div`,{className:`flex flex-col gap-4 p-3`,children:[U(`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)`}),U(`div`,{children:[q(`label`,{htmlFor:`link-target-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target cap`}),U(`select`,{id:`link-target-cap`,value:y,onChange:e=>ue(e.target.value),className:z,children:[q(`option`,{value:``,children:`— select a cap —`}),f.map(e=>q(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),U(`div`,{children:[q(`label`,{htmlFor:`link-target-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target field`}),U(`select`,{id:`link-target-field`,value:x,disabled:y===``,onChange:e=>S(e.target.value),className:z,children:[q(`option`,{value:``,children:`— select a field —`}),L.map(e=>q(`option`,{value:e.path,children:e.item===!0?`${e.path} (per item, ${e.kind})`:`${e.path} (${e.kind})`},e.path))]})]}),se&&U(`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:z}),q(`p`,{className:`mt-1 text-[10px] text-foreground-subtle/60`,children:`Links sharing the same item key build one item (e.g. one consumable).`})]})]}),U(`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`}),U(`div`,{children:[q(`label`,{htmlFor:`link-source-mode`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source mode`}),U(`select`,{id:`link-source-mode`,value:_,onChange:e=>de(e.target.value),className:z,children:[q(`option`,{value:`sibling`,children:`Sibling device (same container)`}),q(`option`,{value:`global`,children:`Any device`}),q(`option`,{value:`literal`,children:`Literal constant`}),q(`option`,{value:`expression`,children:`Expression (computed)`})]})]}),_===`literal`&&U($e,{children:[U(`div`,{children:[q(`label`,{htmlFor:`link-literal-type`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Literal type`}),U(`select`,{id:`link-literal-type`,value:j,onChange:e=>{let t=e.target.value;(t===`string`||t===`number`||t===`boolean`||t===`null`)&&(M(t),t===`boolean`&&P(`true`),t===`null`&&P(``))},className:z,children:[q(`option`,{value:`string`,children:`string`}),q(`option`,{value:`number`,children:`number`}),q(`option`,{value:`boolean`,children:`boolean`}),q(`option`,{value:`null`,children:`null`})]})]}),j!==`null`&&(j===`boolean`?U(`div`,{children:[q(`label`,{htmlFor:`link-literal-value`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Literal value`}),U(`select`,{id:`link-literal-value`,value:N,onChange:e=>P(e.target.value),className:z,children:[q(`option`,{value:`true`,children:`true`}),q(`option`,{value:`false`,children:`false`})]})]}):U(`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:N,placeholder:j===`number`?`e.g. 42`:`e.g. main-brush`,onChange:e=>P(e.target.value),className:z})]}))]}),_===`expression`&&q(ni,{devices:c,siblings:u,targetDeviceId:e,containerStableId:l,initial:h,onChange:ae}),(_===`sibling`||_===`global`)&&q(Wr,{mode:_,idPrefix:`link-source`,labelPrefix:`Source`,pickerDevices:le,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(Hr,{value:F,onChange:I,sourceField:_===`literal`||_===`expression`?void 0:ne,targetKind:oe?.kind}),U(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-border`,children:[q(`button`,{type:`button`,onClick:o,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:!me,onClick:ge,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`})]})]})}H();function fi({deviceId:e}){let t=X(),r=G(),i=Number.isFinite(e),{data:a,isLoading:o}=u({deviceId:e},{enabled:i,refetchInterval:1e4}),{data:s}=n({deviceId:e,includeSynthesizable:!0},{enabled:i}),c=new Map;for(let e of s?.caps??[])e.itemArray&&c.set(e.cap,e.itemArray);let l=A({onSuccess:()=>{r.invalidateQueries({queryKey:[[`deviceManager`]]})}}),d=a?.deviceLinks??[],f=typeof a?.parentDeviceId==`number`?a.parentDeviceId:null,p=typeof a?.stableId==`string`?a.stableId:``,[m,h]=K(null),g=t=>{l.mutate({deviceId:e,deviceLinks:d.filter(e=>e.id!==t)})};return o?q(`div`,{className:`p-4`,children:q(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})}):m===null?U(`div`,{className:`flex flex-col gap-3 p-1`,children:[U(`div`,{className:`flex items-center justify-between`,children:[q(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Wiring`}),U(`button`,{type:`button`,onClick:()=>h(`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`]})]}),d.length===0?U(`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:d.map(n=>q(mi,{deviceId:e,link:n,itemArray:c.get(n.target.cap),trpcClient:t.trpcClient,onDelete:()=>g(n.id),onEdit:()=>h(n),isPending:l.isPending},n.id))})]}):U(`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:m===`new`?`Add link`:`Edit link`})}),q(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:q(di,{deviceId:e,parentDeviceId:f,deviceStableId:p,initial:m===`new`?null:m,onSave:t=>{let n=d.some(e=>e.id===t.id)?d.map(e=>e.id===t.id?t:e):[...d,t];l.mutate({deviceId:e,deviceLinks:n}),h(null)},onCancel:()=>{h(null)}})})]})}function pi(e,t,n,r){let i=ut(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:ut(a,r)}function mi({deviceId:e,link:t,itemArray:n,trpcClient:r,onDelete:i,onEdit:a,isPending:o}){let s=Me(r,e,t.target.cap),c=t.target.itemKey,l=s===void 0?void 0:c!==void 0&&n!==void 0?pi(s,n,c,t.target.fieldPath):c===void 0?ut(s,t.target.fieldPath):void 0,u=l==null?`—`:String(l);return U(`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`}),U(`div`,{className:`min-w-0 flex-1 flex flex-col gap-0.5`,children:[U(`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})]}),U(`div`,{className:`flex items-baseline gap-1 flex-wrap text-[10px] text-foreground-subtle/70`,children:[q(`span`,{children:`←`}),t.source.kind===`literal`?U(`span`,{className:`font-mono`,children:[`literal: `,String(t.source.value)]}):t.source.kind===`expression`?U($e,{children:[U(`span`,{className:`font-mono`,title:t.source.expr,children:[`ƒ`,` `,t.source.expr.length>40?`${t.source.expr.slice(0,40)}…`:t.source.expr]}),U(`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`]})]}):U($e,{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(hi,{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 hi({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})}H();var gi=[{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 _i(e){let t=e===Y.Camera;return gi.filter(e=>t||!e.cameraOnly).map(({id:e,label:t})=>({id:e,label:t}))}var vi=[{id:`logs`,icon:Gt,label:`Logs`},{id:`repl`,icon:Ht,label:`REPL`},{id:`events`,icon:zt,label:`Events`},{id:`state`,icon:Nt,label:`State`}];function yi(){let t=Kt(),r=Number(t.deviceId),a=Number.isFinite(r),s=Ft(),d=G(),p=f(),m=X(),[h,_]=Pt(),v=h.get(`tab`)??`overview`,b=h.get(`sub`),[x,S]=K(`logs`),C=`device-detail.left-col-width-px`,[w,E]=K(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(C),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),ee=V(w);ee.current=w;function O(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??w??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{E(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=ee.current;if(e!==null)try{window.localStorage.setItem(C,String(Math.round(e)))}catch{}document.body.style.userSelect=``,document.body.style.cursor=``};document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,document.addEventListener(`mousemove`,i),document.addEventListener(`mouseup`,a)}let{data:te,isLoading:ne,isError:re}=u({deviceId:r},{enabled:a,refetchInterval:5e3,retry:1}),{data:k}=c({deviceId:r},{enabled:a}),A=W(()=>{let e=k?.settings?.sections??[],t=k?.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(Gn)&&r.add(Hn),[...r].map(e=>e===`export`?{id:e,label:Un,isAddonContrib:!0}:{id:e,label:st[e]?.label??e,isAddonContrib:!0})},[k]),M=te,N=String(M?.name??t.deviceId??`Device`),ie=M?.online===!0,ae=ie?`online`:`offline`,F=String(M?.addonId??`rtsp`),I=M?.features??[],L=M?.type,oe=L===Y.Camera,{data:se}=Tt(a?r:0),R=L===Y.Container,ce=W(()=>(se??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[se]),le=W(()=>R?z(ce,typeof M?.linkDeviceId==`number`?M.linkDeviceId:null,typeof M?.primaryChildEntityId==`string`?M.primaryChildEntityId:null)?.id??null:null,[R,ce,M?.linkDeviceId,M?.primaryChildEntityId]),{data:ue}=c({deviceId:le??0},{enabled:le!==null}),pe=W(()=>{if(le===null)return[];let e=ue?.settings?.sections??[],t=ue?.live?.sections??[],n=new Set;for(let r of[...e,...t])r.location===`top-tab`&&r.tab&&n.add(r.tab);return[...n].map(e=>({id:e,label:st[e]?.label??e,isAddonContrib:!0,childDeviceId:le}))},[le,ue]),he=typeof M?.parentDeviceId==`number`?M.parentDeviceId:null,{data:ge}=u({deviceId:he??0},{enabled:he!==null}),B=De(),_e=M?.disabled!==!0,{data:ve}=n({deviceId:r},{enabled:a}),ye=(ve?.caps.length??0)>0,be=W(()=>{let e=new Set,t=[];for(let n of[..._i(L),...A,...pe])e.has(n.id)||(e.add(n.id),!(n.id===`wiring`&&!ye)&&t.push(n));return t},[L,A,pe,ye]),xe=W(()=>be.some(e=>e.id===v)?v:`overview`,[be,v]),Se=Ze(e=>{_(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[_]),Ce=Ze(e=>{_(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[_]),Te=(se??[]).length>0,Ee=W(()=>vi.filter(({featureGate:e})=>!e||I.includes(e)),[I]),{data:Oe}=Ke({addonId:F},{enabled:!!F&&F!==`rtsp`}),ke=g({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]}),s(Oe?.id?`/integrations/${Oe.id}`:`/integrations`)}}),je=j({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Me=me({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ne=y(),Fe=P({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ie=I.includes(dt.Rebootable),Le=I.includes(dt.BatteryOperated),Re=e(m.trpcClient,Le&&a?r:null),[ze,Be]=K(!1),Ve=pt(m.trpcClient,a?r:null),He=async()=>{if(!(ze||!Ve)){Be(!0);try{await Ve.snapshot?.invalidateCache({});let e=await Ve.snapshot?.getSnapshot({});if(!e)return;let t=`data:${e.contentType};base64,${e.base64}`,n=e.contentType.includes(`png`)?`png`:`jpg`,r=N.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{Be(!1)}}},Ue=je.isPending||Me.isPending,{data:We}=we({deviceId:r},{enabled:a,refetchInterval:1e4}),Ge=We?.agentNodeId??null,qe=typeof Ge==`string`&&Ge.length>0&&!Ge.startsWith(`addon:`)?Ge:void 0,{data:Je}=D({deviceId:r,...qe?{nodeId:qe}:{}},{enabled:a,refetchInterval:3e3,retry:!1}),{data:Ye}=i({deviceId:r},{enabled:a,refetchInterval:3e3,retry:!1}),Xe=Ye?.level?.dbfs??null;function H(){if(!a)return null;switch(xe){case`overview`:return q(Fr,{device:M??{}});case`config`:return q(ar,{deviceId:r,activeSubTab:b,onSubTabChange:Ce});case`detection-pipeline`:return q(vr,{deviceId:r,activeSubTab:b,onSubTabChange:Ce});case`bindings`:return q(In,{deviceId:r});case`wiring`:return q(fi,{deviceId:r});default:{let e=xe,t=A.some(t=>t.id===e),n=pe.find(t=>t.id===e);if(!t&&n===void 0)return null;let i=n?.childDeviceId??r;if(e===`export`)return q(ir,{deviceId:r,sectionFilter:Gn,activeSubTab:b,onSubTabChange:Ce});let a=q(ir,{deviceId:i,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:b,onSubTabChange:Ce});return n!==void 0&&i!==r?q(T,{deviceId:i,children:a}):a}}}return a?ne?U(`div`,{className:`flex flex-col h-full`,children:[U(`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`})})]}):re||!te?U(`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`}),U(`p`,{className:`text-xs`,children:[`No device with ID`,` `,U(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,r]})]}),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`})]}):U(`div`,{className:`absolute inset-0 flex flex-col overflow-hidden`,children:[U(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[q(`div`,{className:`mb-2`,children:q(fe,{items:[{label:`Integrations`,onClick:()=>s(`/integrations`)},{label:Oe?.name??F,onClick:()=>Oe?.id&&s(`/integrations/${Oe.id}`)},{label:N}]})}),U(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[q(xt,{type:F,size:`lg`}),U(`div`,{className:`min-w-0 flex-1`,children:[U(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[q(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:N}),q($t,{status:ae}),Le&&q(de,{status:Re,variant:`full`})]}),he!==null&&ge&&U(`button`,{type:`button`,onClick:()=>s(`/devices/${he}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${ge.name}`,children:[q(`span`,{children:`↑`}),q(`span`,{className:`truncate`,children:String(ge.name??`Device #${he}`)})]}),q(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:I.length>0&&q(vt,{capabilities:I})})]}),Je&&q(`div`,{className:`hidden lg:flex`,children:q(bi,{metrics:Je,dbfs:Xe})}),U(`div`,{className:`flex items-center gap-1 shrink-0`,children:[U(`button`,{onClick:async()=>{_e?await p({title:`Disable "${N}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&Me.mutate({deviceId:r}):je.mutate({deviceId:r})},disabled:Ue,title:_e?`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 ${_e?`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:Ue?`Updating…`:_e?`Enabled`:`Disabled`})]}),q(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),q(Ae,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:Qt,disabled:ze,onClick:()=>{He()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:At,hidden:!Ie,disabled:Ne.isPending,danger:!0,onClick:async()=>{await p({title:`Reboot "${N}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&Ne.mutate({deviceId:r})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${Oe?.name??F}.`,icon:kt,disabled:Fe.isPending,danger:!0,onClick:async()=>{await p({title:`Restart "${Oe?.name??F}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${N}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&Fe.mutate({addonId:F})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:Jt,separatorBefore:!0,disabled:ke.isPending,danger:!0,onClick:async()=>{await p({title:`Delete "${N}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&ke.mutate({deviceId:r})}}]})]})]})]}),q(T,{deviceId:r,device:M??void 0,children:q(o,{children:q(l,{children:q(gt,{children:q(Pe,{children:U(`main`,{className:B?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[U(`div`,{className:B?`flex flex-col bg-surface`:`${w===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!B&&w!==null?{width:`${String(w)}px`}:void 0,children:[q(`div`,{className:oe?`flex-shrink-0 border-b border-border-subtle bg-black`:B?`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:oe?q(jn,{deviceId:r,intercomAvailable:I.includes(dt.TwoWayAudio)}):q(Sn,{deviceId:r,deviceName:N,deviceType:L??`unknown`,provider:F,isOnline:ie,features:I})}),U(`div`,{className:B?`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:Ee.map(({id:e,label:t,icon:n})=>U(`button`,{onClick:()=>S(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${x===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))})}),U(`div`,{className:B?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[x===`logs`&&q(Mn,{deviceId:r,containerDeviceId:L===`container`?r:void 0}),x===`repl`&&q(Nn,{deviceId:r}),x===`events`&&q(Pn,{deviceId:r}),x===`state`&&q(Fn,{deviceId:r})]})]})]}),!B&&q(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:O,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`})}),U(`div`,{className:B?`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:be.map(e=>{let t=xe===e.id;return U(`button`,{onClick:()=>Se(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)})})}),U(`div`,{className:B?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[xe===`overview`&&Te&&q(dn,{parentDeviceId:r}),H()]})]})]})})})})})})]}):U(`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`}),U(`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 bi({metrics:e,dbfs:t}){let n=Je(e.phase??`idle`);return U(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[U(`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`}),U(`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.actualFps??0).toFixed(1)}),q(`span`,{children:`fps`})]}),U(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[q(Wt,{className:`h-3 w-3`}),q(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),q(`span`,{children:`ms`})]}),U(`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&&U(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{yi as DeviceDetailPage};
@@ -1 +0,0 @@
1
- import{Aa as e,Ca as t,Da as n,Ea as r,Fa as i,Oa as a,Sa as o,Ta as s,Xa as c,_a as l,ba as u,bt as d,c as f,ga as p,ka as m,s as h,va as g,wa as _,xa as v,xt as y,ya as b,yo as x}from"./src-DP-u1HtQ.js";import{Q as S,S as C,W as w,b as T,o as E,q as D,x as O}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as k}from"./circle-check-big-CPxj2KQE.js";import{t as A}from"./copy-DF0dst5T.js";import{t as j}from"./key-round-e-ZWFR-B.js";import{t as M}from"./AddonCollectionPage-CDqyaaBM.js";import{t as ee}from"./plus-DaxL0ZPp.js";import{L as N,S as P,T as F,W as I,f as L,i as R,r as z,s as B,u as V,w as H}from"./index-BOnUkW6K.js";import{t as U}from"./AdminPage-BwmGKnRf.js";import{t as W}from"./AdminTabs-DuXQHrHl.js";import{t as G}from"./addon-display-names-DvSEQty-.js";var te=I(`book-open`,[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z`,key:`ruj8y`}]]),K=I(`key-square`,[[`path`,{d:`M12.4 2.7a2.5 2.5 0 0 1 3.4 0l5.5 5.5a2.5 2.5 0 0 1 0 3.4l-3.7 3.7a2.5 2.5 0 0 1-3.4 0L8.7 9.8a2.5 2.5 0 0 1 0-3.4z`,key:`165ttr`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`m9.4 10.6-6.814 6.814A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814`,key:`1ubxi2`}]]),ne=I(`key`,[[`path`,{d:`m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4`,key:`g0fldk`}],[`path`,{d:`m21 2-9.6 9.6`,key:`1j0ho8`}],[`circle`,{cx:`7.5`,cy:`15.5`,r:`5.5`,key:`yqb3hr`}]]),q=I(`link`,[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]),re=I(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]);S();function ie({userId:e,username:t,onClose:n}){let r=E(),a=i(),o=u({userId:e}),s=o.data,c=()=>r.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),l=b({onSuccess:()=>{c(),n()}}),d=o.isLoading?`loading`:s?.enabled?`enrolled`:`not_enrolled`;return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4`,children:C(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden`,children:[C(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-border`,children:[C(`div`,{className:`flex items-center gap-2`,children:[O(V,{className:`h-4 w-4 text-primary`}),C(`div`,{children:[O(`div`,{className:`text-sm font-medium text-foreground`,children:`Two-factor authentication`}),C(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,O(`span`,{className:`font-mono`,children:t})]})]})]}),O(`button`,{onClick:n,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:O(R,{className:`h-4 w-4`})})]}),C(`div`,{className:`p-4 space-y-4`,children:[d===`loading`&&C(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[O(P,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),d===`not_enrolled`&&C(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[O(H,{className:`h-4 w-4 mt-0.5 shrink-0`}),C(`div`,{children:[O(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),O(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),d===`enrolled`&&s&&C(T,{children:[C(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[O(k,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),C(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[O(`div`,{className:`font-medium`,children:`2FA is active`}),C(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,s.confirmedAt?new Date(s.confirmedAt).toLocaleString():`—`]})]})]}),O(`div`,{className:`text-[11px] text-foreground-subtle`,children:`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`}),C(`div`,{className:`flex justify-end gap-2`,children:[O(x,{onClick:n,variant:`secondary`,children:`Close`}),C(`button`,{onClick:async()=>{await a({title:`Remove 2FA`,message:`Remove two-factor authentication for "${t}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,confirmLabel:`Remove`,variant:`danger`})&&l.mutate({userId:e})},disabled:l.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[l.isPending?O(P,{className:`h-3 w-3 animate-spin`}):O(R,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function ae(){let t=E(),{user:n}=z(),[r,a]=D(!1),[o,u]=D(``),[d,f]=D(``),[p,h]=D(!1),[v,y]=D(null),{data:b,isLoading:x,isError:S}=_(),w=i(),T=()=>t.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),k=l({onSuccess:()=>{T(),a(!1),u(``),f(``),h(!1),y(null)},onError:e=>{y(e instanceof Error?e.message:`Failed to create user`)}}),A=g({onSuccess:T}),j=e({onSuccess:T}),M=s({onSuccess:T}),N=m({onSuccess:()=>{T(),I(null)}}),[F,I]=D(null),[H,W]=D(null),G=b??[];async function te(e){await w({title:`Delete user`,message:`Permanently delete user "${e.username}"? This cannot be undone — any active sessions will be revoked on next request.`,confirmLabel:`Delete`,variant:`danger`})&&A.mutate({id:e.id})}async function K(e){let t=window.prompt(`New password for "${e.username}":`);if(t){if(t.length<8){window.alert(`Password must be at least 8 characters.`);return}await w({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&M.mutate({id:e.id,newPassword:t})}}function q(e,t){t!==e.isAdmin&&j.mutate({id:e.id,isAdmin:t})}function re(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}return C(U,{children:[O(`div`,{className:`flex items-center justify-end`,children:C(`button`,{onClick:()=>a(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm hover:bg-primary/90`,children:[O(ee,{className:`h-3.5 w-3.5`}),`Create User`]})}),r&&C(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[C(`div`,{className:`flex items-center justify-between`,children:[O(`span`,{className:`text-xs font-medium text-foreground`,children:`New User`}),O(`button`,{onClick:()=>a(!1),className:`text-foreground-subtle hover:text-foreground`,children:O(R,{className:`h-4 w-4`})})]}),C(`div`,{className:`grid grid-cols-3 gap-3`,children:[C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),O(`input`,{type:`text`,value:o,onChange:e=>u(e.target.value),placeholder:`john`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Password`}),O(`input`,{type:`password`,value:d,onChange:e=>f(e.target.value),placeholder:`••••••••`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),C(`label`,{className:`flex items-center gap-2 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground cursor-pointer`,children:[O(`input`,{type:`checkbox`,checked:p,onChange:e=>h(e.target.checked),className:`rounded border-border focus:ring-primary`}),O(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),v&&O(`p`,{className:`text-[10px] text-danger`,children:v}),C(`div`,{className:`flex justify-end gap-2`,children:[O(`button`,{onClick:()=>a(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),O(`button`,{onClick:()=>k.mutate({username:o,password:d,isAdmin:p}),disabled:k.isPending||!o||!d,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:k.isPending?`Creating...`:`Create`})]})]}),x&&O(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),S&&O(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!x&&!S&&G.length===0&&O(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>A.isPending&&A.variables?.id===e.id||j.isPending&&j.variables?.id===e.id||M.isPending&&M.variables?.id===e.id;return O(c,{columns:[{key:`username`,header:`Username`,render:e=>e.username},{key:`isAdmin`,header:`Admin`,render:t=>C(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[O(`input`,{type:`checkbox`,checked:t.isAdmin,onChange:e=>q(t,e.target.checked),disabled:e(t),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),O(`span`,{className:t.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:t.isAdmin?`Admin`:`Regular`})]})},{key:`scopes`,header:`Scopes`,render:e=>{if(e.isAdmin)return O(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`unscoped`});let t=e.scopes??[];return C(`button`,{onClick:()=>I(e),className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground`,title:`Edit scope grants`,children:[O(L,{className:`h-3 w-3`}),t.length===0?`no access`:`${t.length} grant${t.length===1?``:`s`}`]})}},{key:`createdAt`,header:`Created`,render:e=>O(`span`,{className:`text-foreground-subtle`,children:re(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:t=>{let r=e(t);return C(`div`,{className:`flex items-center justify-end gap-1`,children:[t.id!==n?.id&&t.totpEnabled&&C(`button`,{onClick:()=>W(t),disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Remove two-factor authentication`,children:[O(V,{className:`h-3 w-3`}),`Remove 2FA`]}),C(`button`,{onClick:()=>K(t),disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Reset password`,children:[O(ne,{className:`h-3 w-3`}),`Reset password`]}),C(`button`,{onClick:()=>te(t),disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete user`,children:[r?O(P,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:G,rowKey:e=>e.id,minWidthPx:560})})(),H&&O(ie,{userId:H.id,username:H.username,onClose:()=>W(null)}),F&&O(oe,{user:F,onClose:()=>I(null),onSubmit:e=>N.mutate({userId:F.id,scopes:e}),submitting:N.isPending})]})}function oe(e){let{user:t}=z(),n=t?.isAdmin===!0;return O(se,{...e,callerScopes:n?null:t?.scopes??[]})}function se({user:e,onClose:t,onSubmit:n,submitting:r,callerScopes:i}){let[a,o]=D(w(()=>(e.scopes??[]).map(e=>({...e,access:[...e.access]})),[e.scopes])),s=f(a);return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4`,children:C(`div`,{className:`w-full max-w-2xl rounded-lg border border-border bg-surface shadow-xl`,children:[C(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-3`,children:[C(`div`,{children:[C(`div`,{className:`text-sm font-semibold text-foreground`,children:[`Edit scopes — `,e.username]}),O(`div`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?`Admin users bypass the scope check; this list is ignored.`:`Pick which capabilities this user can call, and which access flavours within each.`})]}),O(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:O(R,{className:`h-4 w-4`})})]}),C(`div`,{className:`px-4 py-4`,children:[O(h,{value:a,onChange:o,clampToParent:i,emptyHint:C(T,{children:[`No scopes granted.`,` `,O(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until a scope is added.`]})}),s&&O(`p`,{className:`mt-2 text-[10px] text-danger`,children:s})]}),C(`div`,{className:`flex items-center justify-end gap-2 border-t border-border px-4 py-3`,children:[O(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),O(`button`,{onClick:()=>n(a),disabled:r||s!==null,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:r?O(P,{className:`h-3 w-3 animate-spin`}):`Save scopes`})]})]})})}S();var ce=`bg-primary/10 text-primary`,le=`bg-foreground-subtle/10 text-foreground-subtle`;function J(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function ue(e){return e?e===`*`?`*`:e.join(`, `):``}function de(){let e=E(),t=i(),{data:n,isLoading:o}=v(),{data:s}=_(),c=w(()=>n??[],[n]),l=w(()=>s??[],[s]),u=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),d=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[f,m]=D(!1),[h,g]=D(null),y=r({onSuccess:u}),b=p({onSuccess:({token:e,record:t})=>{d(),m(!1),g({token:e,label:t.name})}}),x=a({onSuccess:d}),S=async(e,n)=>{await t({title:`Revoke "${n}"?`,message:`Any client using this token will lose access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&y.mutate({id:e})},T=async(e,n)=>{await t({title:`Revoke "${n}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&x.mutate({id:e})};return C(U,{children:[C(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[O(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Issue scoped tokens to grant a user a narrow surface — a specific addon, integration, or capability. Every token MUST be scoped: revoking it has predictable blast radius.`}),C(`button`,{onClick:()=>m(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,disabled:l.length===0,title:l.length===0?`Create a user first`:`Issue a scoped token`,children:[O(L,{className:`h-3.5 w-3.5`}),`New token`]})]}),C(fe,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[l.length===0&&O(me,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),l.map(e=>O(ge,{userId:e.id,username:e.username,onRevoke:(e,t)=>{T(e,t)},revokePending:x.isPending,revokeId:x.variables?.id},e.id))]}),c.length>0&&O(fe,{title:`Legacy API keys`,subtitle:`${c.length} pre-existing — revoke only`,children:O(he,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:c.map(e=>{let t=!!e.isAdmin,n=y.isPending&&y.variables?.id===e.id;return C(`tr`,{className:`hover:bg-primary/5`,children:[O(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.label}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:O(`span`,{className:`inline-block rounded px-2 py-0.5 text-[10px] uppercase tracking-wide ${t?ce:le}`,children:t?`admin`:`regular`})}),C(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border text-foreground-subtle`,children:ue(e.allowedProviders)||`all`}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.createdAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:C(`button`,{onClick:()=>{S(e.id,e.label)},disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[n?O(P,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),o&&O(pe,{}),f&&O(_e,{users:l.map(e=>({id:e.id,username:e.username})),onClose:()=>m(!1),onSubmit:e=>b.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:b.isPending}),h&&O(ve,{token:h.token,label:h.label,onClose:()=>g(null)})]})}function fe({title:e,subtitle:t,children:n}){return C(`div`,{className:`space-y-2`,children:[C(`div`,{className:`flex items-baseline justify-between`,children:[O(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),t&&O(`span`,{className:`text-[10px] text-foreground-subtle`,children:t})]}),n]})}function pe(){return O(`div`,{className:`space-y-2`,children:[1,2].map(e=>O(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function me({text:e}){return O(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function he({headers:e,rows:t}){return O(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:C(`table`,{className:`w-full text-xs min-w-[640px]`,children:[O(`thead`,{children:O(`tr`,{children:e.map((t,n)=>O(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),O(`tbody`,{children:t})]})})}function ge({userId:e,username:n,onRevoke:r,revokePending:i,revokeId:a}){let{data:o,isLoading:s}=t({userId:e}),c=o??[];return s||c.length===0?null:C(`div`,{className:`space-y-1.5`,children:[O(`div`,{className:`text-[11px] font-medium text-foreground`,children:n}),O(he,{headers:[`Name`,`Prefix`,`Scopes`,`Expires`,`Last used`,`Created`,``],rows:c.map(e=>{let t=i&&a===e.id;return C(`tr`,{className:`hover:bg-primary/5`,children:[O(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.name}),C(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:O(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>C(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:[e.type,`:`,e.type===`device`?`[${e.targets.join(`,`)}]`:e.target]},t))})}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.expiresAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.createdAt)}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:C(`button`,{onClick:()=>r(e.id,e.name),disabled:t,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[t?O(P,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function _e({users:e,onClose:t,onSubmit:n,submitting:r}){let{user:i}=z(),a=i?.isAdmin===!0?null:i?.scopes??[],[o,s]=D(e[0]?.id??``),[c,l]=D(``),[u,d]=D([{type:`capability`,target:``,access:[`view`,`create`]}]),[p,m]=D(``),g=f(u),_=o!==``&&c.trim().length>0&&u.length>0&&g===null&&!r;return C(ye,{title:`Create scoped token`,onClose:t,children:[C(`div`,{className:`space-y-3`,children:[O(Y,{label:`On behalf of user`,children:O(`select`,{value:o,onChange:e=>s(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>O(`option`,{value:e.id,children:e.username},e.id))})}),O(Y,{label:`Name`,children:O(`input`,{value:c,onChange:e=>l(e.target.value),placeholder:`cloudflare-tunnel-route`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})}),C(Y,{label:`Scopes`,hint:`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`,children:[O(h,{value:u,onChange:d,clampToParent:a}),g&&O(`p`,{className:`mt-1 text-[10px] text-danger`,children:g})]}),O(Y,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:O(`input`,{type:`number`,min:1,value:p,onChange:e=>m(e.target.value),placeholder:`30`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})})]}),C(be,{children:[O(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),C(`button`,{onClick:()=>{let e=parseInt(p,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;n({userId:o,name:c.trim(),scopes:u,expiresAt:t})},disabled:!_,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[r?O(P,{className:`h-3.5 w-3.5 animate-spin`}):O(L,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function ve({token:e,label:t,onClose:n}){let[r,i]=D(!1),a=async()=>{try{await navigator.clipboard.writeText(e),i(!0)}catch{}};return C(ye,{title:`Token: ${t}`,onClose:n,children:[C(`div`,{className:`space-y-3`,children:[O(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:`Copy this token now. Once you close this dialog the secret cannot be displayed again.`}),O(`div`,{className:`rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all`,children:e})]}),C(be,{children:[C(`button`,{onClick:()=>{a()},className:`inline-flex items-center gap-1.5 rounded bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[r?O(N,{className:`h-3.5 w-3.5 text-primary`}):O(A,{className:`h-3.5 w-3.5`}),r?`Copied`:`Copy`]}),O(`button`,{onClick:n,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Done`})]})]})}function ye({title:e,onClose:t,children:n}){return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:C(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[C(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[O(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),O(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:O(R,{className:`h-4 w-4`})})]}),O(`div`,{className:`p-4`,children:n})]})})}function be({children:e}){return O(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:e})}function Y({label:e,hint:t,children:n}){return C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:e}),n,t&&O(`p`,{className:`text-[10px] text-foreground-subtle`,children:t})]})}S();function X(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function xe(e){if(e.type===`category`){let t=e.target??``;return t===`device`?`all devices`:`all ${t}`}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function Se(){return O(`div`,{className:`space-y-2`,children:[1,2].map(e=>O(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function Ce({text:e}){return O(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function we({headers:e,rows:t}){return O(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:C(`table`,{className:`w-full text-xs min-w-[640px]`,children:[O(`thead`,{children:O(`tr`,{children:e.map((t,n)=>O(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),O(`tbody`,{children:t})]})})}function Te(){let e=E(),t=i(),{data:r,isLoading:a}=o(),s=w(()=>r??[],[r]),c=n({onSuccess:()=>e.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),l=async(e,n)=>{await t({title:`Revoke "${n}" session?`,message:`This integration will lose access immediately on its next API call. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&c.mutate({id:e})};return C(U,{icon:q,title:`Linked Sessions`,subtitle:`External integrations (Alexa, …) linked to this hub via OAuth. Revoke a session to immediately invalidate that integration's access.`,children:[a&&O(Se,{}),!a&&s.length===0&&O(Ce,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!a&&s.length>0&&O(we,{headers:[`Integration`,`User`,`Scopes`,`Created`,`Last used`,`Status`,``],rows:s.map(e=>{let t=e.revokedAt!==null,n=(c.isPending?c.variables?.id:void 0)===e.id;return C(`tr`,{className:`hover:bg-primary/5`,children:[O(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.integrationId}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:e.username}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:O(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>O(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:xe(e)},t))})}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 border-b border-border`,children:t?C(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-2 py-0.5 text-[10px] text-foreground-subtle`,children:[`Revoked `,X(e.revokedAt)]}):O(`span`,{className:`inline-block rounded bg-emerald-500/15 px-2 py-0.5 text-[10px] text-emerald-700 dark:text-emerald-300`,children:`Active`})}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:!t&&C(`button`,{onClick:()=>{l(e.id,e.integrationId)},disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[n?O(P,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}S();var Z=3e4,Q=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],$={title:`Authentication providers`,subtitle:`Every registered authentication surface in one list: login providers (local password, OIDC, SAML, magic-link) and second-factor providers (passkeys / WebAuthn — configure the relying-party RP ID + origin inline; users enroll from My access → Passkeys). Multiple providers run in parallel — enable/disable each independently. Disabling one only removes that method; local password login is unaffected.`,emptyTitle:`No authentication providers registered`,emptyDescription:`Local auth should always be available — if this list is empty the local-auth builtin failed to register. Check the Addons page for load errors.`,installLabel:`Add provider`};function Ee(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:K,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA is self-enrolled: each user enables it from their own profile page (My access → Two-factor authentication).`,`API keys + scoped tokens are managed from the API Keys page.`],setupSteps:[`Add users from Users → New user (or seed via CAMSTACK_ADMIN_USER / CAMSTACK_ADMIN_PASS).`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:F,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`First-time sign-ins are auto-provisioned with the configured Default Role.`],setupSteps:[`Register a web app at your IdP and copy the client_id + client_secret.`,"Set the redirect URI to `https://<this-hub>/addon/<addon-id>/callback`.",`Paste issuer + credentials in the Settings panel below — saves on every change.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:F,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:V,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)||e.startsWith(`auth-magic-link`)?{headline:`TOTP / magic-link — second factor or passwordless sign-in.`,icon:V,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:L,bullets:[`Generic authentication provider. No additional hints registered.`]}}function De(){let e=y({capName:Q[0].capName},{refetchInterval:Z}),t=y({capName:Q[1].capName},{refetchInterval:Z}),n=d(void 0,{refetchInterval:Z}),r=w(()=>G(n.data??[]),[n.data]),i=w(()=>{let n=[],i=[e.data??[],t.data??[]];for(let[e,t]of Q.entries())for(let a of i[e]??[])n.push({addonId:a.addonId,displayName:r.get(a.addonId)??a.addonId,isActive:a.isActive,capName:t.capName,stageBadge:t.stageBadge});return n},[e.data,t.data,r]);return O(M,{title:$.title,subtitle:$.subtitle,pageIcon:L,itemIcon:L,capability:Q[0].capName,installButtonLabel:$.installLabel,items:i,isLoading:e.isLoading||t.isLoading,emptyTitle:$.emptyTitle,emptyDescription:$.emptyDescription,renderStatusBadges:e=>e.stageBadge===null?null:O(`span`,{className:`inline-flex items-center rounded-full border border-primary/30 bg-primary/10 px-2 py-0.5 text-[10px] font-medium text-primary`,children:e.stageBadge}),renderExpandedPanel:e=>O(Oe,{addonId:e.addonId})})}function Oe({addonId:e}){let t=Ee(e),n=t.icon;return C(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[C(`div`,{className:`flex items-start gap-2.5`,children:[O(n,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),O(`div`,{className:`text-xs text-foreground font-medium`,children:t.headline})]}),O(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:t.bullets.map((e,t)=>O(`li`,{children:e},t))}),t.setupSteps&&t.setupSteps.length>0&&C(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[C(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[O(te,{className:`h-3 w-3`}),`Setup steps`]}),O(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:t.setupSteps.map((e,t)=>O(`li`,{children:e},t))})]}),e===`local-auth`&&C(`div`,{className:`rounded-md border border-blue-500/30 bg-blue-500/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[O(H,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),C(`span`,{children:[`TOTP / 2FA is self-service: each user enrols from their own profile page —`,` `,O(`a`,{href:`/system/my-access`,className:`underline text-primary`,children:`My access`}),` `,`→ “Two-factor authentication” → Enable 2FA. Admins can only remove a user’s active enrollment (lost device) from the`,` `,O(`a`,{href:`/system/users`,className:`underline text-primary`,children:`Users`}),` `,`page via Actions → “Remove 2FA”.`]})]})]})}function ke(){return O(`div`,{className:`flex flex-col p-4`,children:O(W,{tabs:[{id:`users`,label:`Users`,icon:re,content:O(ae,{})},{id:`api-keys`,label:`Tokens`,icon:j,content:O(de,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:q,content:O(Te,{})},{id:`authentication`,label:`Authentication`,icon:L,content:O(De,{})}]})})}export{ke as IdentityPage};
@@ -1 +0,0 @@
1
- import{Cr as e,Dr as t,Er as n,Ia as r,Mr as i,Nr as a,Or as o,Sr as s,Tr as c,Xa as l,_o as u,br as d,bt as f,ha as p,jr as m,vo as h,wr as g,xr as ee,xt as _,yo as v,yr as te}from"./src-DP-u1HtQ.js";import{I as y,Q as b,S as x,W as S,b as C,o as w,q as T,x as E,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{o as D,s as O}from"./src-Ck8eP0y_.js";import{p as k}from"./player-overlays-QWBHo29P.js";import{n as A,t as re}from"./rotate-ccw-Dp3LyyNb.js";import{t as j}from"./copy-DF0dst5T.js";import{n as ie,t as M}from"./AddonCollectionPage-CDqyaaBM.js";import{t as ae}from"./refresh-cw-CPElSd1E.js";import{t as N}from"./server-jWz5lmi4.js";import{t as oe}from"./square-Df6rn0vR.js";import{t as se}from"./wifi-CjcdCR8p.js";import{L as ce,S as P,T as F,W as I,b as le,i as ue,k as L,l as de,o as R,v as z,x as B}from"./index-BOnUkW6K.js";import{t as V}from"./AdminPage-BwmGKnRf.js";import{t as H}from"./AdminTabs-DuXQHrHl.js";import{t as U}from"./addon-display-names-DvSEQty-.js";var fe=I(`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`}]]),pe=I(`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=I(`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`}]]);b();var G=5e3,me={connected:!1,endpoint:null};function he(){let e=w(),t=_({capName:`network-access`},{refetchInterval:G}),n=f(void 0,{refetchInterval:G}),r=S(()=>U(n.data??[]),[n.data]),o=S(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:r.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,r]),[s,c]=T(null),[l,u]=T({}),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})},p=(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}))},m=i({onSuccess:d,onError:p}),h=a({onSuccess:d,onError:p});return E(M,{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:F,itemIcon:F,capability:`network-access`,installButtonLabel:`Add tunnel`,items:o,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=>E(ge,{addonId:e.addonId}),itemError:e=>l[e.addonId]??null,renderPrimaryAction:e=>E(_e,{addonId:e.addonId,busyId:s,onStart:e=>{c(e),m.mutate({addonId:e})},onStop:e=>{c(e),h.mutate({addonId:e})}})})}function K(e){let{data:t}=m({addonId:e},{refetchInterval:G,retry:!1}),n=t?O.safeParse(t):null;return n?.success?n.data:me}function ge({addonId:e}){let t=K(e);return x(C,{children:[E(`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&&x(`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:[E(L,{className:`h-3 w-3`}),t.endpoint.url]})]})}function _e({addonId:e,busyId:t,onStart:n,onStop:r}){let i=K(e),a=t===e;return i.connected?x(v,{size:`sm`,variant:`secondary`,disabled:a,onClick:()=>r(e),children:[a?E(P,{className:`h-3 w-3 animate-spin`}):E(oe,{className:`h-3 w-3`}),`Stop`]}):x(v,{size:`sm`,variant:`primary`,disabled:a,onClick:()=>n(e),children:[a?E(P,{className:`h-3 w-3 animate-spin`}):E(ie,{className:`h-3 w-3`}),`Start`]})}b();var q=3e4;function ve(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function ye(){let e=_({capName:`turn-provider`},{refetchInterval:q}),t=f(void 0,{refetchInterval:q}),n=p(),r=n.data??[],i=S(()=>U(t.data??[]),[t.data]);return E(M,{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:z,itemIcon:z,capability:`turn-provider`,installButtonLabel:`Add provider`,items:S(()=>(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=>E(be,{addonId:e.addonId,enabled:e.isActive}),trailing:x(u,{children:[x(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[x(`div`,{children:[E(`div`,{className:`text-sm font-semibold`,children:`Combined ICE server list`}),E(`div`,{className:`text-xs text-foreground-subtle`,children:`What the WebRTC layer fetches per-session.`})]}),E(v,{size:`sm`,variant:`secondary`,onClick:()=>n.refetch(),disabled:n.isFetching,children:`Refresh`})]}),E(`div`,{className:`p-4`,children:r.length===0?E(`div`,{className:`text-xs text-foreground-subtle`,children:`No servers from enabled providers.`}):E(`div`,{className:`flex flex-col gap-3`,children:r.map((e,t)=>{let n=Array.isArray(e.urls)?e.urls:[e.urls];return x(`div`,{className:`rounded border border-border bg-surface`,children:[(e.username||e.credential)&&x(`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&&x(`span`,{children:[E(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,E(`span`,{className:`text-foreground`,children:e.username})]}),e.credential&&x(`span`,{children:[E(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,E(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),E(`ul`,{className:`divide-y divide-border`,children:n.map(e=>E(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},t)})})})]})})}function be({addonId:e,enabled:t}){let n=p({addonId:e},{enabled:t,retry:!1}),r=S(()=>ve(n.data??[]),[n.data]);return!t||r.length===0?null:x(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[x(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Discovered ICE servers (`,r.length,`)`]}),E(`div`,{className:`flex flex-wrap gap-1`,children:r.map(e=>E(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground`,children:e},e))})]})}b();var xe={lan:z,wifi:se,docker:A,vpn:B,loopback:N,other:N},Se={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},Ce=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function we(e){let{interfaces:t,disabled:n,hideLoopback:r,ipv4Only:i,emptyMessage:a}=e,o=S(()=>t.filter(e=>!(r&&e.kind===`loopback`||i&&e.family!==`IPv4`)),[t,r,i]),s=S(()=>{let e=new Map;for(let t of o){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return Ce.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?E(`div`,{className:`text-xs text-foreground-subtle italic`,children:a??`No addresses available.`}):E(`div`,{className:`flex flex-col gap-3`,children:s.map(({kind:t,items:r})=>x(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[x(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[E(xe[t]??N,{className:`h-3.5 w-3.5 text-foreground-subtle`}),E(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:Se[t]??t}),x(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,r.length]})]}),E(`ul`,{className:`divide-y divide-border`,children:r.map(t=>{let r=c(t.address),i=t.kind===`loopback`,a=!t.plausible&&!i;return x(`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:[E(`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&&E(ce,{className:`h-3 w-3`})}),x(`div`,{className:`flex-1 min-w-0 ${a?`text-foreground-subtle`:``}`,children:[x(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[E(`span`,{className:`font-mono text-xs font-semibold ${a?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),E(`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&&E(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:`Auto-preferred`}),i&&E(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:`Always included`}),a&&x(`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:[E(R,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]}),x(`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))})}b();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 Te(){let t=w(),n=k(),r=ee(void 0,{refetchInterval:3e4}),i=te(void 0),a=e({onSuccess:()=>{t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),o=s({onSuccess:e=>{p(e.addresses),t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),c=S(()=>r.data?.interfaces??[],[r.data]),l=d({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}),[f,p]=T([]),[m,h]=T(!1);ne(()=>{!m&&i.data&&(p(i.data.addresses),h(!0))},[i.data,m]);let g=i.data?.addresses??[],_=S(()=>{if(f.length!==g.length)return!0;let e=[...f].toSorted(),t=[...g].toSorted();return e.some((e,n)=>e!==t[n])},[f,g]),y=()=>{a.mutate({addresses:[...f]})},b=()=>{p(g)},C=()=>{p([])},D=()=>{r.refetch(),l.refetch(),i.refetch()},O=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)}},A=l.data?.endpoints??[];return x(V,{children:[x(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[E(`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.`}),x(`div`,{className:`flex items-center gap-2 shrink-0`,children:[x(v,{size:`sm`,variant:`secondary`,onClick:D,disabled:r.isLoading,children:[E(ae,{className:`h-3 w-3 ${r.isLoading?`animate-spin`:``}`}),`Refresh`]}),E(v,{size:`sm`,variant:`secondary`,onClick:O,children:`Probe race`})]})]}),x(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[x(u,{children:[x(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[x(`div`,{children:[E(`div`,{className:`text-sm font-semibold`,children:`Allowed addresses`}),E(`div`,{className:`text-xs text-foreground-subtle`,children:f.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${f.length} pinned`})]}),x(`div`,{className:`flex items-center gap-1`,children:[x(v,{size:`sm`,variant:`secondary`,onClick:()=>o.mutate(void 0),disabled:o.isPending||a.isPending,title:`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`,children:[E(de,{className:`h-3 w-3`}),o.isPending?`Detecting…`:`Best match`]}),x(v,{size:`sm`,variant:`secondary`,onClick:C,disabled:f.length===0||a.isPending,children:[E(re,{className:`h-3 w-3`}),`Clear`]}),_&&E(v,{size:`sm`,variant:`secondary`,onClick:b,disabled:a.isPending,children:`Discard`}),x(v,{size:`sm`,variant:`primary`,onClick:y,disabled:!_||a.isPending,children:[E(pe,{className:`h-3 w-3`}),a.isPending?`Saving…`:`Save`]})]})]}),E(`div`,{className:`p-4`,children:E(we,{mode:`multiple`,interfaces:c,value:f,onChange:p,disabled:a.isPending,emptyMessage:r.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),x(u,{children:[x(`div`,{className:`px-4 py-3 border-b border-border`,children:[E(`div`,{className:`text-sm font-semibold`,children:`Connection endpoints — priority order`}),E(`div`,{className:`text-xs text-foreground-subtle`,children:`Live preview of the ranked candidate list the SDK would race against. Updates with each Save.`})]}),E(`div`,{className:`p-4`,children:A.length===0?E(`div`,{className:`text-xs text-foreground-subtle italic`,children:l.isLoading?`Loading…`:`No endpoints available.`}):E(`ul`,{className:`space-y-1 text-xs`,children:A.map(e=>x(`li`,{className:`flex items-center gap-2 flex-wrap ${e.plausible?``:`opacity-80`}`,children:[E(`span`,{className:`font-mono text-[10px] w-10 text-foreground-subtle`,children:String(e.priority).padStart(4,`0`)}),E(`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`&&E(`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`&&x(`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:[E(R,{className:`h-2.5 w-2.5`}),`Unlikely usable`]}),E(`span`,{className:`font-mono break-all ${e.plausible?`text-foreground`:`text-foreground-subtle`}`,children:e.baseUrl}),x(`span`,{className:`text-foreground-subtle`,children:[`— `,e.label]})]},`${e.priority}-${e.baseUrl}`))})})]})]})]})}b();var Ee={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,De=3e4,Oe={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function ke(){let e=_({capName:`mesh-network`},{refetchInterval:Y}),t=f(void 0,{refetchInterval:Y}),n=S(()=>U(t.data??[]),[t.data]);return E(M,{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:A,itemIcon:z,capability:`mesh-network`,installButtonLabel:`Add mesh`,items:S(()=>(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=>E(Ae,{addonId:e.addonId}),renderPrimaryAction:e=>E(Z,{addonId:e.addonId}),renderExpandedPanel:e=>E(je,{addonId:e.addonId})})}function X(e){let{data:t,isLoading:n}=g({addonId:e},{refetchInterval:Y,retry:!1}),r=t?D.safeParse(t):null;return{status:r?.success?r.data:Oe,isLoading:n}}function Ae({addonId:e}){let{status:t}=X(e);return x(C,{children:[E(`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&&x(`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 Z({addonId:e}){let n=w(),[r,i]=T(!1),[a,s]=T(null),l=k(),{status:u}=X(e),d=y(()=>{n.invalidateQueries({queryKey:[[`meshNetwork`]]})},[n]),f=o(),p=c({onSuccess:d}),m=t({onSuccess:d}),h=y(async()=>{i(!0);let t={cancelled:!1};s(t);try{let n=await f.mutateAsync({addonId:e});if(t.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!t.cancelled&&(await Ie(2e3),!t.cancelled);){let t=await l.trpcClient.meshNetwork.getStatus.query({addonId:e}).catch(()=>null),n=t?D.safeParse(t):null;if(n?.success&&n.data.joined){d();break}if(Date.now()-r>6e5)break}}finally{i(!1),s(null)}},[e,d,f,l]),g=y(()=>{a&&(a.cancelled=!0),i(!1),s(null)},[a]);return E(C,{children:u.joined?x(C,{children:[x(v,{size:`sm`,variant:`secondary`,disabled:p.isPending,onClick:()=>p.mutate({addonId:e}),children:[p.isPending?E(P,{className:`h-3 w-3 animate-spin`}):E(le,{className:`h-3 w-3`}),`Disconnect`]}),x(v,{size:`sm`,variant:`ghost`,disabled:m.isPending,onClick:()=>m.mutate({addonId:e}),children:[m.isPending?E(P,{className:`h-3 w-3 animate-spin`}):E(W,{className:`h-3 w-3`}),`Log out`]})]}):r?x(v,{size:`sm`,variant:`ghost`,onClick:g,children:[E(ue,{className:`h-3 w-3 mr-1`}),` Cancel`]}):x(C,{children:[x(v,{size:`sm`,variant:`primary`,onClick:()=>void h(),children:[E(fe,{className:`h-3 w-3`}),`Connect`]}),x(v,{size:`sm`,variant:`ghost`,disabled:m.isPending,onClick:()=>m.mutate({addonId:e}),children:[m.isPending?E(P,{className:`h-3 w-3 animate-spin`}):E(W,{className:`h-3 w-3`}),`Log out`]})]})})}function je({addonId:e}){let{status:t}=X(e),i=n({addonId:e},{refetchInterval:De,retry:!1});return x(`div`,{className:`rounded-lg border border-border bg-surface`,children:[x(`div`,{className:`p-4 space-y-4`,children:[t.error&&E(r,{message:t.error}),E(Me,{status:t}),t.endpoints.length>0&&x(`div`,{className:`space-y-1.5`,children:[E(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Endpoints`}),t.endpoints.map(e=>x(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[x(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${Ee[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?E(F,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),x(`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:[E(L,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),E(`div`,{className:`border-t border-border`,children:E(Pe,{peers:i.data?.peers??[],loading:i.isLoading})})]})}function Me({status:e}){return E(`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?Ne(e.keyExpiry):`—`}].map(e=>x(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[E(`span`,{className:`text-foreground-subtle shrink-0`,children:e.label}),E(`span`,{className:`text-foreground truncate ${e.mono?`font-mono`:``}`,children:e.value})]},e.label))})}function Ne(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 Pe({peers:e,loading:t}){let n=S(()=>e.map(e=>({...e,_id:e.id})),[e]),r=y(e=>{e&&navigator.clipboard?.writeText(e)},[]),i=S(()=>[{key:`hostname`,header:`Hostname`,render:e=>x(`div`,{className:`flex flex-col`,children:[x(`div`,{className:`flex items-center gap-1.5`,children:[E(`span`,{className:`font-medium text-foreground`,children:e.hostname||`(unknown)`}),e.isSelf&&E(h,{variant:`info`,children:`self`}),e.exitNodeOption&&E(h,{variant:`warning`,children:`exit-node`})]}),e.userLogin&&E(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.userLogin})]})},{key:`magicDns`,header:`MagicDNS`,render:e=>e.magicDns?x(`div`,{className:`flex items-center gap-1`,children:[E(`span`,{className:`font-mono text-xs truncate`,children:e.magicDns}),E(`button`,{onClick:()=>r(e.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy MagicDNS`,children:E(j,{className:`h-3 w-3 text-foreground-subtle`})})]}):E(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:e=>{let t=e.addresses[0]??``;return t?x(`div`,{className:`flex items-center gap-1`,children:[E(`span`,{className:`font-mono text-xs`,children:t}),E(`button`,{onClick:()=>r(t),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy IP`,children:E(j,{className:`h-3 w-3 text-foreground-subtle`})})]}):E(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:`Connection`,render:e=>x(`div`,{className:`flex items-center gap-1.5`,children:[E(h,{variant:Fe(e.connection),children:e.connection}),e.relay&&E(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.relay})]})},{key:`routes`,header:`Routes`,render:e=>e.advertisedRoutes.length>0?E(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):E(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:`TX / RX`,render:e=>x(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,Q(e.txBytes),` · ↓ `,Q(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>E(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?$(e.lastSeenMs):`—`})}],[r]);return t&&e.length===0?x(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[E(P,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):e.length===0?E(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No peers visible — your tailnet may be empty or the host is not joined.`}):E(`div`,{className:`p-4`,children:E(l,{columns:i,rows:n,rowKey:e=>e._id,minWidthPx:820})})}function Fe(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 Ie(e){return new Promise(t=>setTimeout(t,e))}function Le(){return E(`div`,{className:`flex flex-col p-4`,children:E(H,{tabs:[{id:`addresses`,label:`Network Addresses`,icon:N,content:E(Te,{})},{id:`remote-access`,label:`Remote Access`,icon:F,content:E(he,{})},{id:`mesh`,label:`Mesh Networks`,icon:A,content:E(ke,{})},{id:`turn`,label:`TURN Servers`,icon:z,content:E(ye,{})}]})})}export{Le as NetworkPage};
@@ -1 +0,0 @@
1
- import{ai as e,bt as t,dt as n,ft as r,on as i,zt as a}from"./src-DP-u1HtQ.js";import{H as o,I as s,K as c,Q as l,S as u,W as d,i as f,k as p,o as m,p as h,q as g,t as _,x as v,z as y}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{W as b}from"./src-Ck8eP0y_.js";import{p as ee}from"./player-overlays-QWBHo29P.js";import{t as x}from"./FormBuilder-pVzTAhbz.js";import{n as te,r as S,t as ne}from"./SchemaTabBar-DhsmEGyn.js";l();var C=p(function({addonId:e,schema:t,serverValues:n,onImmediateSave:r,onStateChange:i,onAction:a,disabled:l},u){let f=S({schema:t,serverValues:n,onImmediateSave:s(t=>r(e,t),[e,r]),onDeferredSave:s(()=>{},[])});o(u,()=>({flush:()=>{let e={};for(let t of f.pendingKeys)e[t]=f.values[t];return f.handleDiscard(f.pendingKeys),e},discard:()=>f.resetAll()}),[f]);let p=f.pendingKeys,m=p.join(`|`),h=d(()=>p.map(e=>`${e}=${JSON.stringify(f.values[e])}`).join(`,`),[p,f.values]),g=c(i);y(()=>{g.current=i},[i]),y(()=>{let t={};for(let e of p)t[e]=f.values[e];g.current({addonId:e,pendingKeys:p,pendingValues:t})},[e,m,h]);let _=d(()=>{if(a)return(t,n,r)=>a(e,t,n,r)},[e,a]);return v(x,{schema:t,values:f.values,onChange:f.handleChange,disabled:l,onAction:_})});l();function w(e,t){if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`){let n=e.fields.map(e=>w(e,t));return{...e,fields:n}}let n=e;t[e.key]=n.value;let{value:r,...i}=n;return i}function T(e,t){return{...e,fields:e.fields.map(e=>w(e,t))}}function re(e){let t={};return{schema:{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>T(e,t))},values:t}}function E({nodeId:o,addonIds:l,level:p,deviceId:y,capability:x,sectionIds:S,sectionTab:C,extraTabs:w,title:T,description:E}){let D=m(),O=ee().trpcClient,k=r(),A=n(),j=e(),M=i(),N=a(),P=!!(w&&w.length>0),[F,ae]=g(null);if(p===`device`&&!y)throw Error(`NodeAddonsSettingsPanel: deviceId is required when level === "device"`);let I=o??`hub`,L=f({queries:l.map(e=>({queryKey:[[`addonSettings`,p===`global`?`getGlobalSettings`:`getDeviceSettings`],{addonId:e,nodeId:I,deviceId:y??null,cap:x??null}],queryFn:async()=>p===`global`?{addonId:e,result:await O.addonSettings.getGlobalSettings.query({addonId:e,nodeId:I,...x?{cap:x}:{}})}:{addonId:e,result:await O.addonSettings.getDeviceSettings.query({addonId:e,deviceId:y,nodeId:I})},placeholderData:h}))}),R=L.some(e=>e.isLoading),z=L.map(e=>{if(!e.data)return`-`;if(e.data.result===null)return`${e.data.addonId}:n`;let t=[];for(let n of e.data.result.sections){t.push(`s:${n.id}:${n.tab??`general`}`);for(let e of n.fields){if(!(`key`in e))continue;let n=`options`in e&&Array.isArray(e.options)?e.options.map(e=>e.value).join(`,`):``,r=e.value,i=r===void 0?``:typeof r==`string`?r:JSON.stringify(r);t.push(`f:${e.key}:${n}:${i}`)}}return`${e.data.addonId}:${t.join(`|`)}`}).join(`||`),B=d(()=>{let e=new Set;for(let t of L){let n=t.data?.result?.sections;if(n)for(let t of n)e.add(t.tab??`general`)}return[...e]},[z+`::`+L.map(e=>(e.data?.result?.sections??[]).map(e=>e.tab??`general`).join(`,`)).join(`::`)]),V=d(()=>new Map((w??[]).map(e=>[e.id,e])),[w]),H=d(()=>{if(!P)return[];let e=[...new Set([...B,...(w??[]).map(e=>e.id)])],t=e=>{let t=V.get(e);if(t?.order!==void 0)return t.order;let n=b[e];return n?n.order:50};return e.toSorted((e,n)=>{let r=t(e),i=t(n);return r===i?e.localeCompare(n):r-i})},[P,B,w,V]),oe=d(()=>{let e=new Map;for(let t of B){let n=b[t];e.set(t,n?.label??t.charAt(0).toUpperCase()+t.slice(1))}for(let t of w??[])e.set(t.id,t.label);return e},[B,w]),U=P?F&&H.includes(F)?F:H[0]??null:null,W=U!==null&&V.has(U),G=P?U&&!W?U:void 0:C,{data:K}=t(void 0),se=d(()=>{let e=new Map;for(let t of K??[]){let n=t.manifest?.id;if(!n)continue;let r=t.manifest?.name??t.manifest?.packageDisplayName??n;e.set(n,r)}return e},[K]),q=c(new Map),J=d(()=>{let e=S?new Set(S):null,t=[];for(let n of L){if(!n.data)continue;let r=n.data.result??q.current.get(n.data.addonId)??null;if(n.data.result!==null&&q.current.set(n.data.addonId,n.data.result),r===null)continue;let{schema:i,values:a}=re(r),o=i.sections.filter(t=>e?e.has(t.id):!0);if(o.length===0)continue;let s={...r,sections:r.sections.filter(t=>e?e.has(t.id):!0)},c={...i,sections:o};t.push({addonId:n.data.addonId,schemaWithValues:s,schema:c,serverValues:a})}return t},[z,S]),[Y,ce]=g(new Map),le=s(e=>{ce(t=>{let n=new Map(t);return n.set(e.addonId,e),n})},[]),X=c(new Map),ue=s(e=>t=>{t?X.current.set(e,t):X.current.delete(e)},[]),Z=s(async(e,t)=>{p===`global`?await k.mutateAsync({addonId:e,nodeId:I,patch:t}):await A.mutateAsync({addonId:e,deviceId:y,nodeId:I,patch:t}),D.invalidateQueries({queryKey:[[`addonSettings`]]})},[k,A,I,p,y,D]),de=s(async(e,t,n,r)=>{let i=I;try{switch(t){case`reprobe-engine`:await j.mutateAsync({nodeId:i}),D.invalidateQueries({queryKey:[[`addonSettings`]]});return;case`reprobe-hwaccel`:await M.mutateAsync({nodeId:i}),D.invalidateQueries({queryKey:[[`addonSettings`]]});return;case`reprobe-audio-engine`:await N.mutateAsync({nodeId:i}),D.invalidateQueries({queryKey:[[`addonSettings`]]});return;default:{let n=await O.addons.custom.mutate({addonId:e,action:t,input:r});return D.invalidateQueries({queryKey:[[`addonSettings`]]}),n}}}catch(n){throw console.error(`[NodeAddonsSettingsPanel] action failed`,{addonId:e,action:t,err:n}),n}},[j,M,N,I,D,O]),fe=s((e,t)=>{Z(e,t)},[Z]),Q=_({mutationFn:async()=>{let e=[];for(let t of J){let n=Y.get(t.addonId);!n||n.pendingKeys.length===0||e.push({addonId:t.addonId,patch:n.pendingValues})}return e.length===0?{saved:[]}:{saved:await Promise.all(e.map(async({addonId:e,patch:t})=>(p===`global`?await k.mutateAsync({addonId:e,nodeId:I,patch:t}):await A.mutateAsync({addonId:e,deviceId:y,nodeId:I,patch:t}),e)))}},onSuccess:({saved:e})=>{for(let t of e)X.current.get(t)?.discard();D.invalidateQueries({queryKey:[[`addonSettings`]]})}}),pe=s(()=>{for(let e of X.current.values())e.discard()},[]),me=d(()=>{let e=0;for(let t of J){let n=Y.get(t.addonId);n&&(e+=n.pendingKeys.length)}return e},[J,Y]),he=d(()=>{let e=new Map;for(let t of J){let n=Y.get(t.addonId);if(!n||n.pendingKeys.length===0)continue;let r=new Set(n.pendingKeys);for(let n of t.schema.sections){let t=n.tab??`general`;for(let i of n.fields)`key`in i&&r.has(i.key)&&e.set(t,(e.get(t)??0)+1)}}return e},[J,Y]);if(R)return v(`div`,{className:`h-24 rounded-lg border border-border bg-surface animate-pulse`});let $=U&&W?V.get(U):void 0;if(!P&&J.length===0)return u(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:[`No addons in `,l.length>0?`[${l.join(`, `)}]`:`the current selection`,` `,`expose `,p,`-level settings on this node.`]});let ge=Q.isPending;return u(`div`,{className:`space-y-4`,children:[(T||E)&&u(`div`,{className:`border-b border-border pb-2`,children:[T&&v(`h2`,{className:`text-sm font-semibold text-foreground`,children:T}),E&&v(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:E})]}),P&&v(ne,{tabs:H.map(e=>({id:e,label:oe.get(e)??e})),activeId:U,onChange:ae,pendingByTab:he}),Q.isError&&u(`div`,{className:`rounded-md border border-red-500/40 bg-red-500/10 px-3 py-2 text-[11px] text-red-400`,children:[`Save failed: `,String(Q.error?.message??Q.error)]}),$?$.content:(()=>{let e=G?J.reduce((e,t)=>e+t.schemaWithValues.sections.filter(e=>(e.tab??`general`)===G).length,0):0,t=G!==null&&e<=1,n=J.map(e=>({...e,renderedWithValues:{...e.schemaWithValues,sections:e.schemaWithValues.sections.filter(e=>G?(e.tab??`general`)===G:!0).map(e=>t?{...e,title:``,description:void 0}:e)}})).filter(e=>e.renderedWithValues.sections.length>0).toSorted((e,t)=>{let n=e=>{let t=1/0;for(let n of e)typeof n.order==`number`&&n.order<t&&(t=n.order);return t},r=n(e.renderedWithValues.sections),i=n(t.renderedWithValues.sections);return r===i?0:r-i});return n.length===0?v(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:`Nothing to configure here for this node.`}):v(ie,{entries:n,paneStates:Y,displayNames:se,disabled:ge,setPaneRef:ue,onPaneStateChange:le,onImmediateSave:fe,onAction:de,inline:P||!!C})})(),!R&&v(te,{pendingCount:me,onSave:()=>Q.mutate(),onDiscard:pe,saving:ge})]})}function ie({entries:e,paneStates:t,displayNames:n,disabled:r,setPaneRef:i,onPaneStateChange:a,onImmediateSave:o,onAction:s,inline:c}){let l=d(()=>[...e].toSorted((e,t)=>{if(e.addonId===`system-config`)return-1;if(t.addonId===`system-config`)return 1;let r=n.get(e.addonId)??e.addonId,i=n.get(t.addonId)??t.addonId;return r.localeCompare(i)}),[e,n]),[f,p]=g(l[0]?.addonId??``);y(()=>{l.length!==0&&(l.find(e=>e.addonId===f)||p(l[0].addonId))},[l,f]);let m=l.find(e=>e.addonId===f)??l[0];if(!m)return null;let h=d(()=>s?(e,t,n,r)=>s(e,t,n,r):void 0,[s]),_=e=>v(C,{ref:i(e.addonId),addonId:e.addonId,schema:e.renderedWithValues,serverValues:e.serverValues,onImmediateSave:o,onStateChange:a,onAction:h,disabled:r},e.addonId);return l.length===1||c?v(`div`,{className:`flex flex-col gap-4`,children:l.map(_)}):u(`div`,{className:`flex flex-col gap-3`,children:[v(`div`,{className:`flex flex-wrap items-center gap-1 border-b border-border shrink-0`,children:l.map(e=>{let r=n.get(e.addonId)??e.addonId,i=e.addonId===m.addonId,a=(t.get(e.addonId)?.pendingKeys.length??0)>0;return u(`button`,{type:`button`,onClick:()=>p(e.addonId),className:`relative px-3 py-1.5 text-xs font-medium rounded-t-md transition-colors -mb-px border-b-2 whitespace-nowrap ${i?`text-primary border-primary bg-primary/5`:`text-foreground-subtle border-transparent hover:text-foreground hover:bg-surface-hover`}`,children:[r,a&&v(`span`,{className:`ml-1.5 inline-flex h-1.5 w-1.5 rounded-full bg-amber-400`})]},e.addonId)})}),v(`div`,{className:`space-y-2`,children:l.map(e=>v(`div`,{style:e.addonId===m.addonId?void 0:{display:`none`},children:_(e)},e.addonId))})]})}export{E as t};