@camstack/addon-admin-ui 1.1.27 → 1.1.28

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 (84) hide show
  1. package/dist/assets/{AddLocationWizard-CINm21H1.js → AddLocationWizard-BqqTpair.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-BkUO0Tru.js → AddonCollectionPage-CHJrQbxS.js} +1 -1
  3. package/dist/assets/Addons-PDcFB41o.js +1 -0
  4. package/dist/assets/{AdminTabs-mgvEpBDZ.js → AdminTabs-Dcn_NnRS.js} +1 -1
  5. package/dist/assets/{BrokerForm-1o4dgBsn.js → BrokerForm-DhpuU5tk.js} +1 -1
  6. package/dist/assets/{Capabilities-Hll85kIK.js → Capabilities-DNFfJgC4.js} +1 -1
  7. package/dist/assets/{CapabilityBadges-D7EsQrNT.js → CapabilityBadges-BPp4spWK.js} +1 -1
  8. package/dist/assets/Cluster-BaaYsixN.js +1 -0
  9. package/dist/assets/{Dashboard-CJnGC7ye.js → Dashboard-CM2iQw9a.js} +1 -1
  10. package/dist/assets/{Data-CcoeTmaj.js → Data-Cm_DTQc3.js} +1 -1
  11. package/dist/assets/{DetectionIntelligence-DV0-5hhZ.js → DetectionIntelligence-BUvN-5c-.js} +1 -1
  12. package/dist/assets/DeviceDetail-PPL3d07c.js +2 -0
  13. package/dist/assets/{Devices-BetTA0QM.js → Devices-BFQvObda.js} +1 -1
  14. package/dist/assets/{EmbedPlayerPage-DC8HQG9A.js → EmbedPlayerPage-D7ziDRCE.js} +1 -1
  15. package/dist/assets/{FormBuilder-CL6dlXwQ.js → FormBuilder-BtCunYUK.js} +1 -1
  16. package/dist/assets/Identity-DShDOLzy.js +1 -0
  17. package/dist/assets/IntegrationDetail-Dn2Q55u8.js +1 -0
  18. package/dist/assets/{Integrations-B9NKf_18.js → Integrations-DLAx15Dx.js} +1 -1
  19. package/dist/assets/{Integrations-m0TAjBFs.js → Integrations-DMQWpYfB.js} +1 -1
  20. package/dist/assets/{Logs-NBZRysED.js → Logs-BZ22Tof8.js} +1 -1
  21. package/dist/assets/{MotionZonesSettings-XX_gd-OU.js → MotionZonesSettings-Cb04qdzk.js} +1 -1
  22. package/dist/assets/{MyAccess-MnFNVCPV.js → MyAccess-BSGRdNLj.js} +1 -1
  23. package/dist/assets/Network-p8KkZ0a2.js +1 -0
  24. package/dist/assets/{NodeAddonsSettingsPanel-5OLeCWWK.js → NodeAddonsSettingsPanel-u4V1iTbJ.js} +1 -1
  25. package/dist/assets/{NotificationTargets-DcnKusHA.js → NotificationTargets-CCNlJEh8.js} +1 -1
  26. package/dist/assets/Pipeline-BlhdDHB0.js +1 -0
  27. package/dist/assets/{PrivacyMaskSettings-BdV7p1W_.js → PrivacyMaskSettings-uImjMvtB.js} +1 -1
  28. package/dist/assets/{ProviderIcon-AXlCHsTd.js → ProviderIcon-X1LLmqTA.js} +1 -1
  29. package/dist/assets/{ScanNetworkModal-tDFKEL2L.js → ScanNetworkModal-DNl-uXYZ.js} +1 -1
  30. package/dist/assets/{SchemaTabBar-Lx0lVN3x.js → SchemaTabBar-DhsmEGyn.js} +1 -1
  31. package/dist/assets/{Settings-Cq9lEA2q.js → Settings-CkWgIblv.js} +1 -1
  32. package/dist/assets/{Showroom-Bgf-mV2W.js → Showroom-BjxzO7Xe.js} +1 -1
  33. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CUYaV0wb.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BW32eA4e.js} +1 -1
  34. package/dist/assets/build-cluster-graph-BBzichfL.js +7 -0
  35. package/dist/assets/circle-check-big-Blvkp2hJ.js +1 -0
  36. package/dist/assets/{copy-BwY737s-.js → copy-BzVBaBlO.js} +1 -1
  37. package/dist/assets/{dist-7sVMyhkP.js → dist-B6nrtI9D.js} +1 -1
  38. package/dist/assets/{dist-Bp7iSHw-.js → dist-ipJu8FwS.js} +1 -1
  39. package/dist/assets/{download-CDTSR7Xa.js → download-Bg3fxTwd.js} +1 -1
  40. package/dist/assets/{hostInit-C_DOKr_T.js → hostInit-AVzON_Ql.js} +1 -1
  41. package/dist/assets/index-7ucUNPxm.css +2 -0
  42. package/dist/assets/index-cObQUDCu.js +4 -0
  43. package/dist/assets/{key-round-CRs7h4JP.js → key-round-BeNuMjW0.js} +1 -1
  44. package/dist/assets/{mf-entry-bootstrap-0-f15090ce.js → mf-entry-bootstrap-0-75a8d503.js} +2 -2
  45. package/dist/assets/{pencil-DR7yGacK.js → pencil-BxhnkUV_.js} +1 -1
  46. package/dist/assets/{player-overlays-CqpHdvYF.js → player-overlays-Bhh-T-qH.js} +1 -1
  47. package/dist/assets/plus-BR0mGk3r.js +1 -0
  48. package/dist/assets/{radio-Bzq_SNgq.js → radio-CP28eXrH.js} +1 -1
  49. package/dist/assets/{refresh-cw-DH7JcsAT.js → refresh-cw-hKUYl1HT.js} +1 -1
  50. package/dist/assets/remoteEntry-CaZXIGdX.js +1 -0
  51. package/dist/assets/{rotate-ccw-C9Gcb3tJ.js → rotate-ccw-B1y8E4DF.js} +1 -1
  52. package/dist/assets/rotate-cw-ChSqQNtp.js +1 -0
  53. package/dist/assets/search-qPHxMz5I.js +1 -0
  54. package/dist/assets/{server-Crr45iTm.js → server-BD-hEzuI.js} +1 -1
  55. package/dist/assets/{sparkles-C5A0sFZJ.js → sparkles-C8w2oZIa.js} +1 -1
  56. package/dist/assets/square-D5fMq7WQ.js +1 -0
  57. package/dist/assets/{square-check-big-B8Q-LJXA.js → square-check-big-BquN3GaR.js} +1 -1
  58. package/dist/assets/{src-9Nw_7MUt.js → src-BvxPxXyx.js} +6 -6
  59. package/dist/assets/{src-DYcadIAu.js → src-Ce30zKhx.js} +1 -1
  60. package/dist/assets/{upload-BWN1zN1a.js → upload-ChX0t6dA.js} +1 -1
  61. package/dist/assets/{useDevice-LyxwBrYX.js → useDevice-BRRdLKBn.js} +1 -1
  62. package/dist/assets/{useEventInvalidation-CoNLHhyv.js → useEventInvalidation-OVOcl54D.js} +1 -1
  63. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BMXZuPDZ.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BKo-bthY.js} +2 -2
  64. package/dist/assets/{wifi-G6nDQGOi.js → wifi-Cl7ptz-k.js} +1 -1
  65. package/dist/assets/{zap-JlTWX6I9.js → zap-Bis62gF5.js} +1 -1
  66. package/dist/index.html +6 -6
  67. package/dist/server/addon.js +1 -1
  68. package/package.json +1 -1
  69. package/dist/assets/Addons-6GwyCrFZ.js +0 -1
  70. package/dist/assets/Cluster-J7bWxCyF.js +0 -1
  71. package/dist/assets/DeviceDetail-Cg4_si18.js +0 -2
  72. package/dist/assets/Identity-Cnr-q0hs.js +0 -1
  73. package/dist/assets/IntegrationDetail-CyVsgPEp.js +0 -1
  74. package/dist/assets/Network-BnuGSw90.js +0 -1
  75. package/dist/assets/Pipeline-Dl9S29Wb.js +0 -1
  76. package/dist/assets/circle-check-big-6ez5bWMa.js +0 -1
  77. package/dist/assets/index-Da6GKRLl.js +0 -4
  78. package/dist/assets/index-DgnLfnMW.css +0 -2
  79. package/dist/assets/plus-CekuJPnw.js +0 -1
  80. package/dist/assets/remoteEntry-DCvysifo.js +0 -1
  81. package/dist/assets/rotate-cw-CTrqUHcp.js +0 -1
  82. package/dist/assets/search-B5TMrljD.js +0 -1
  83. package/dist/assets/square-jObXvdFU.js +0 -1
  84. package/dist/assets/use-persisted-flow-layout-DuQZXkHq.js +0 -7
@@ -1 +0,0 @@
1
- import{Ar as e,Cr as t,Fr as n,Ia as r,Ir as i,Mr as a,Nr as o,Pr as s,Xi as c,_a as l,g as u,ga as d,h as f,ha as p,hi as m,jr as h,m as g,ni as _,ra as v,ta as y,va as b,wr as x}from"./src-9Nw_7MUt.js";import{I as S,K as C,Q as w,S as T,W as E,o as D,q as O,x as k,z as A}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as j}from"./player-overlays-CqpHdvYF.js";import{t as M}from"./pencil-DR7yGacK.js";import{t as N}from"./radio-Bzq_SNgq.js";import{t as P}from"./refresh-cw-DH7JcsAT.js";import{t as F}from"./rotate-cw-CTrqUHcp.js";import{t as ee}from"./server-Crr45iTm.js";import{t as I}from"./upload-BWN1zN1a.js";import{F as L,L as te,M as R,P as z,V as B,i as V,k as ne,o as re,p as H,s as U,x as W}from"./index-Da6GKRLl.js";import{a as G,i as K,n as q,o as J,r as Y,s as X,t as ie}from"./use-persisted-flow-layout-DuQZXkHq.js";import{t as Z}from"./format-size-CO9d3C3-.js";import{t as ae}from"./NodeAddonsSettingsPanel-5OLeCWWK.js";var oe=B(`git-fork`,[[`circle`,{cx:`12`,cy:`18`,r:`3`,key:`1mpf1b`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`path`,{d:`M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9`,key:`1uq4wg`}],[`path`,{d:`M12 12v3`,key:`158kv8`}]]),se=B(`memory-stick`,[[`path`,{d:`M6 19v-3`,key:`1nvgqn`}],[`path`,{d:`M10 19v-3`,key:`iu8nkm`}],[`path`,{d:`M14 19v-3`,key:`kcehxu`}],[`path`,{d:`M18 19v-3`,key:`1vh91z`}],[`path`,{d:`M8 11V9`,key:`63erz4`}],[`path`,{d:`M16 11V9`,key:`fru6f3`}],[`path`,{d:`M12 11V9`,key:`ha00sb`}],[`path`,{d:`M2 15h20`,key:`16ne18`}],[`path`,{d:`M2 7a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v1.1a2 2 0 0 0 0 3.837V17a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-5.1a2 2 0 0 0 0-3.837Z`,key:`lhddv3`}]]),Q=B(`skull`,[[`path`,{d:`m12.5 17-.5-1-.5 1h1z`,key:`3me087`}],[`path`,{d:`M15 22a1 1 0 0 0 1-1v-1a2 2 0 0 0 1.56-3.25 8 8 0 1 0-11.12 0A2 2 0 0 0 8 20v1a1 1 0 0 0 1 1z`,key:`1o5pge`}],[`circle`,{cx:`15`,cy:`12`,r:`1`,key:`1tmaij`}],[`circle`,{cx:`9`,cy:`12`,r:`1`,key:`1vctgf`}]]),ce=B(`table-2`,[[`path`,{d:`M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18`,key:`gugj83`}]]);w();function le(e){let t=new FormData;return t.append(`file`,e.file,e.file.name),t.append(`nodeId`,e.nodeId),e.addonId&&t.append(`addonId`,e.addonId),new Promise((n,r)=>{let i=new XMLHttpRequest;i.open(`POST`,`/api/addons/upload`),e.token&&i.setRequestHeader(`Authorization`,`Bearer ${e.token}`),i.upload.addEventListener(`progress`,t=>{t.lengthComputable&&e.onProgress(Math.round(t.loaded/t.total*100))}),i.addEventListener(`load`,()=>{let e;try{e=JSON.parse(i.responseText)}catch{r(Error(`HTTP ${i.status}`));return}i.status>=200&&i.status<300?n(e):r(Error(e.error??`HTTP ${i.status}`))}),i.addEventListener(`error`,()=>r(Error(`Network error during upload`))),i.addEventListener(`abort`,()=>r(Error(`Upload aborted`))),i.send(t)})}function ue({nodeId:t,addons:n,isHub:r}){let o=D(),s=c(),[l,u]=O(null),[d,f]=O(null),[p,m]=O(!1),[h,g]=O(null),[_,v]=O(0),y=C(null),b=a(),x=i(),S=e({nodeId:t}),w=S.data??[],E=new Map(n.map(e=>[e.id,e.capabilities])),A=w.length>0?w.map(e=>({id:e.id,status:e.status,capabilities:E.get(e.id)??[],version:e.version,packageName:e.packageName})):n.map(e=>({id:e.id,status:e.status,capabilities:e.capabilities,version:void 0,packageName:void 0})),j=()=>{o.invalidateQueries({queryKey:[[`nodes`,`topology`]]}),S.refetch()},M=async e=>{u(e);try{await b.mutateAsync({nodeId:t,addonId:e}),j()}catch(e){console.error(`Failed to restart addon:`,e)}finally{u(null)}},N=async e=>{if(await s({title:`Uninstall addon`,message:`Remove "${e}" from ${t}? The addon directory will be deleted on disk.`,confirmLabel:`Uninstall`,variant:`danger`})){f(e);try{await x.mutateAsync({nodeId:t,addonId:e}),j()}catch(e){console.error(`Failed to uninstall addon:`,e)}finally{f(null)}}},P=T(`div`,{className:`flex items-center gap-2 mb-2`,children:[k(`input`,{ref:y,type:`file`,accept:`.tgz,.tar.gz`,className:`hidden`,onChange:async e=>{let n=e.target.files?.[0];if(n){e.target.value=``,g(null),m(!0),v(0);try{await le({file:n,nodeId:t,token:localStorage.getItem(`camstack_admin_token`),onProgress:v}),j()}catch(e){g(e instanceof Error?e.message:String(e))}finally{m(!1),v(0)}}}}),T(`button`,{onClick:()=>y.current?.click(),disabled:p,className:`inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[p?k(W,{className:`h-3 w-3 animate-spin`}):k(I,{className:`h-3 w-3`}),p?`Uploading… ${_}%`:`Upload addon (.tgz)`]}),p&&k(`div`,{className:`flex-1 h-1 rounded-full bg-muted overflow-hidden max-w-[140px]`,children:k(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${_}%`}})}),h&&k(`span`,{className:`text-[10px] text-destructive`,children:h})]});return A.length===0?T(`div`,{children:[P,k(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:S.isLoading?`Loading addons…`:`No addons on this node`})]}):T(`div`,{children:[P,T(`table`,{className:`w-full text-xs`,children:[k(`thead`,{children:T(`tr`,{className:`text-muted-foreground text-left`,children:[k(`th`,{className:`py-2 font-medium`,children:`Addon`}),k(`th`,{className:`py-2 font-medium`,children:`Version`}),k(`th`,{className:`py-2 font-medium`,children:`Capabilities`}),k(`th`,{className:`py-2 font-medium`,children:`Status`}),k(`th`,{className:`py-2 font-medium w-16`})]})}),k(`tbody`,{children:A.map(e=>T(`tr`,{className:`border-t border-border/50`,children:[T(`td`,{className:`py-2 font-medium`,children:[k(`div`,{children:e.id}),e.packageName&&k(`div`,{className:`text-[9px] text-muted-foreground`,children:e.packageName})]}),k(`td`,{className:`py-2 text-muted-foreground`,children:e.version??`—`}),k(`td`,{className:`py-2`,children:k(`div`,{className:`flex flex-wrap gap-1`,children:e.capabilities.length>0?e.capabilities.map(e=>k(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400`,children:e},e)):k(`span`,{className:`text-muted-foreground`,children:`—`})})}),k(`td`,{className:`py-2`,children:k(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e.status===`running`?`bg-success/10 text-success`:e.status===`error`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e.status})}),k(`td`,{className:`py-2`,children:T(`div`,{className:`flex items-center gap-1 justify-end`,children:[k(`button`,{onClick:()=>M(e.id),disabled:l===e.id||d===e.id,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.id}`,children:k(F,{className:`h-3 w-3 ${l===e.id?`animate-spin`:``}`})}),k(`button`,{onClick:()=>N(e.id),disabled:l===e.id||d===e.id,className:`p-1 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50`,title:`Uninstall ${e.id}`,children:d===e.id?k(W,{className:`h-3 w-3 animate-spin`}):k(U,{className:`h-3 w-3`})})]})})]},e.id))})]})]})}w();function de(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60);return n<24?`${n}h ${t%60}m`:`${Math.floor(n/24)}d ${n%24}h`}function fe({state:e}){return k(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e===`running`?`bg-success/10 text-success`:e===`crashed`||e===`failed`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e})}var pe=[`trace`,`debug`,`info`,`warn`,`error`];function me({proc:e,nodeId:t,defaultExpanded:n,activePanel:r,onTogglePanel:i}){let c=e.services??[],f=c.length===1,[m,h]=O(f||n),[_,v]=O(null),[y,x]=O(`info`),S=e.name.includes(`(core)`),C=a(),w=o(),E=s(),D=async e=>{v(e);try{await C.mutateAsync({nodeId:t,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{v(null)}},A=async()=>{v(e.name);try{await w.mutateAsync({nodeId:t,processName:e.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{v(null)}},j=async n=>{let r=`${t}/${e.name}`;try{await E.mutateAsync({nodeId:r,level:n}),x(n)}catch(e){console.error(`Failed to set log level:`,e)}};return T(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[T(`div`,{role:f?void 0:`button`,tabIndex:f?void 0:0,onClick:f?void 0:()=>h(!m),onKeyDown:f?void 0:e=>{(e.key===`Enter`||e.key===` `)&&h(!m)},className:`flex items-center gap-2 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${f?``:`hover:bg-muted/40 cursor-pointer`}`,children:[f?k(`span`,{className:`h-3 w-3 shrink-0`}):k(m?z:R,{className:`h-3 w-3 text-muted-foreground shrink-0`}),S?k(ee,{className:`h-3.5 w-3.5 text-primary shrink-0`}):k(te,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),k(`span`,{className:`text-xs font-semibold flex-1`,children:e.name}),T(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[`PID `,e.pid]}),k(fe,{state:e.state}),T(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[e.cpuPercent,`% CPU`]}),k(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:Z(e.memoryRss)}),k(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:de(e.uptimeSeconds)}),!S&&T(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[T(p,{children:[k(b,{className:`text-[9px] px-1.5 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors font-mono`,title:`Set log level`,children:y}),k(d,{align:`end`,className:`min-w-[70px] py-0.5`,children:pe.map(e=>k(l,{onClick:()=>j(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===y?`text-primary font-semibold`:``}`,children:e},e))})]}),k(`button`,{onClick:A,disabled:_===e.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart process`,children:k(F,{className:`h-3 w-3 ${_===e.name?`animate-spin`:``}`})})]})]}),m&&c.length>0&&k(`div`,{className:`divide-y divide-border/30`,children:c.map(e=>T(`div`,{children:[T(`div`,{className:`flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors`,children:[k(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`running`?`bg-success`:`bg-muted-foreground/30`}`}),k(`span`,{className:`text-xs font-medium flex-1 min-w-0 truncate`,children:e.addonId}),e.capabilities.length>0&&T(`div`,{className:`flex gap-1 flex-shrink-0`,children:[e.capabilities.slice(0,3).map(e=>k(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400 truncate max-w-[80px]`,children:e},e)),e.capabilities.length>3&&T(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,e.capabilities.length-3]})]}),T(`div`,{className:`flex items-center gap-1 shrink-0`,children:[k(`button`,{onClick:()=>i(e.addonId,`logs`),className:`p-0.5 rounded transition-colors ${r?.addonId===e.addonId&&r.type===`logs`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show logs for ${e.addonId}`,children:k(H,{className:`h-3 w-3`})}),k(`button`,{onClick:()=>i(e.addonId,`events`),className:`p-0.5 rounded transition-colors ${r?.addonId===e.addonId&&r.type===`events`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show events for ${e.addonId}`,children:k(N,{className:`h-3 w-3`})}),k(`button`,{onClick:()=>D(e.addonId),disabled:_===e.addonId,className:`p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.addonId}`,children:k(F,{className:`h-3 w-3 ${_===e.addonId?`animate-spin`:``}`})})]})]}),r?.addonId===e.addonId&&r.type===`logs`&&k(`div`,{className:`border-t border-border/40 bg-muted/5`,children:k(u,{addonId:e.addonId,agentId:t,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>i(e.addonId,`logs`)})}),r?.addonId===e.addonId&&r.type===`events`&&k(`div`,{className:`border-t border-border/40 bg-muted/5`,children:k(g,{addonId:e.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>i(e.addonId,`events`)})})]},e.addonId))}),m&&c.length===0&&k(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:`No services`})]})}function he({nodeId:e,processes:t}){let[n,r]=O(null),i=(e,t)=>{r(n=>n?.addonId===e&&n.type===t?null:{addonId:e,type:t})};return t.length===0?k(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No processes on this node`}):k(`div`,{className:`space-y-2 py-1`,children:t.map((t,r)=>k(me,{proc:t,nodeId:e,defaultExpanded:r===0,activePanel:n,onTogglePanel:i},t.name))})}w();function ge(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m ${e%60}s`:e<86400?`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`:`${Math.floor(e/86400)}d ${Math.floor(e%86400/3600)}h`}function _e(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function ve({nodeId:e}){let n=D(),r=c(),[i,a]=O(`all`),o=y(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:s}=x({nodeId:e}),l=o?.processes??s,u=E(()=>l?[...l]:[],[l]),d=E(()=>i===`ghost`?u.filter(e=>e.classification===`ghost`):u,[u,i]),f=E(()=>{let e=u.filter(e=>e.classification===`ghost`),t=new Map;for(let n of e)t.has(n.ppid)||t.set(n.ppid,[]),t.get(n.ppid).push(n);return[...t.entries()].filter(([,e])=>e.length>1).map(([e,t])=>({ppid:e,children:t})).toSorted((e,t)=>t.children.length-e.children.length)},[u]),p=t({onSettled:()=>{n.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]})}}),m=E(()=>{let e=new Map;for(let t of u)e.set(t.pid,t.classification);return e},[u]),h=async(t,n)=>{if(t.classification===`root`||t.classification===`system`)return;let i=t.classification===`ghost`?`ghost`:t.addonId??`process`,a=n?`SIGKILL`:`SIGTERM`;await r({title:`Send ${a}?`,message:`Target pid ${t.pid} (${i}) on node ${e}.`,confirmLabel:`Send ${a}`,variant:`danger`})&&p.mutate({nodeId:e,pid:t.pid,force:n})},g=async(t,n)=>{try{await p.mutateAsync({nodeId:e,pid:t,force:n})}catch{}},_=async t=>{let i=m.get(t.ppid);if(i===`root`||i===`system`){await r({title:`Cannot kill protected ancestor`,message:i===`root`?`pid ${t.ppid} is the current node supervisor. Restart the node via the cluster page instead.`:`pid ${t.ppid} is a system ancestor (concurrently / vite / npm wrapper). Killing it would tear down the dev tree.`,confirmLabel:`OK`,cancelLabel:`Close`,variant:`warning`});return}await r({title:`Kill ghost parent + ${t.children.length} child(ren)?`,message:`SIGKILL parent pid ${t.ppid} and SIGTERM ${t.children.length} ghost child(ren) on node ${e}.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all([g(t.ppid,!0),...t.children.map(e=>g(e.pid,!1))]),n.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},v=async()=>{let t=u.filter(e=>e.classification===`ghost`);t.length!==0&&await r({title:`Kill all ${t.length} ghost process(es)?`,message:`SIGKILL ${t.length} ghost process(es) on node ${e}. This is irreversible.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all(t.map(e=>g(e.pid,!0))),n.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},b=u.filter(e=>e.classification===`ghost`).length,S=u.filter(e=>e.classification===`managed`).length,C=u.filter(e=>e.classification===`root`).length,w=u.filter(e=>e.classification===`system`).length;return T(`div`,{className:`space-y-4`,children:[T(`div`,{className:`flex items-start justify-between gap-4`,children:[T(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`ps`," scan + kernel `$process.list` cross-reference. Ghosts = camstack-shaped commands with no managed binding (usually orphaned to ppid=1). Refreshes every 10s."]}),T(`button`,{type:`button`,onClick:()=>n.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}),className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[k(P,{className:`h-3 w-3`}),` Refresh`]})]}),T(`div`,{className:`grid grid-cols-4 gap-3`,children:[T(`div`,{className:`rounded-lg border border-border p-3`,children:[k(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Root`}),k(`div`,{className:`text-xl font-semibold text-foreground`,children:C})]}),T(`div`,{className:`rounded-lg border border-border p-3`,children:[k(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Managed`}),k(`div`,{className:`text-xl font-semibold text-foreground`,children:S})]}),T(`div`,{className:`rounded-lg border border-border p-3`,children:[k(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`System`}),k(`div`,{className:`text-xl font-semibold text-foreground`,children:w})]}),T(`div`,{className:`rounded-lg border p-3 ${b>0?`border-destructive/40 bg-destructive/5`:`border-border`}`,children:[T(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle flex items-center gap-1`,children:[b>0&&k(Q,{className:`h-3 w-3 text-destructive`}),` Ghosts`]}),k(`div`,{className:`text-xl font-semibold ${b>0?`text-destructive`:`text-foreground`}`,children:b})]})]}),f.length>0&&T(`div`,{className:`rounded-lg border border-amber-500/40 bg-amber-500/5 p-3`,children:[T(`div`,{className:`flex items-center gap-1 text-[11px] font-semibold text-amber-400 mb-2`,children:[k(re,{className:`h-3 w-3`}),` Recurring ghost parents (`,f.length,`)`]}),k(`div`,{className:`space-y-1.5`,children:f.map(e=>T(`div`,{className:`text-[11px] text-foreground flex items-center justify-between gap-2`,children:[T(`div`,{className:`flex items-center gap-2`,children:[T(`span`,{className:`font-mono text-foreground-subtle`,children:[`ppid `,e.ppid]}),T(`span`,{children:[`→ `,e.children.length,` ghost(s)`]})]}),T(`button`,{type:`button`,disabled:p.isPending,onClick:()=>{_(e)},className:`inline-flex items-center gap-1 rounded border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 text-[10px] text-amber-400 hover:bg-amber-500/20 disabled:opacity-30`,children:[k(Q,{className:`h-3 w-3`}),` Kill parent + `,e.children.length]})]},e.ppid))})]}),T(`div`,{className:`flex items-center justify-between gap-2 text-[11px]`,children:[T(`div`,{className:`flex items-center gap-2`,children:[k(`span`,{className:`text-foreground-subtle`,children:`Filter:`}),T(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${i===`all`?`bg-primary text-primary-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>a(`all`),children:[`All (`,u.length,`)`]}),T(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${i===`ghost`?`bg-destructive text-destructive-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>a(`ghost`),children:[`Ghost only (`,b,`)`]})]}),b>0&&T(`button`,{type:`button`,disabled:p.isPending,onClick:()=>{v()},className:`inline-flex items-center gap-1 rounded border border-destructive/40 bg-destructive/10 px-2 py-1 text-[11px] font-medium text-destructive hover:bg-destructive/20 disabled:opacity-30`,children:[k(Q,{className:`h-3 w-3`}),` Kill all `,b,` ghost(s)`]})]}),k(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:T(`table`,{className:`w-full text-xs`,children:[k(`thead`,{className:`bg-surface`,children:T(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[k(`th`,{className:`text-left px-3 py-2`,children:`Class`}),k(`th`,{className:`text-right px-3 py-2`,children:`PID`}),k(`th`,{className:`text-right px-3 py-2`,children:`PPID`}),k(`th`,{className:`text-left px-3 py-2`,children:`Addon`}),k(`th`,{className:`text-left px-3 py-2`,children:`Command`}),k(`th`,{className:`text-right px-3 py-2`,children:`CPU%`}),k(`th`,{className:`text-right px-3 py-2`,children:`RSS`}),k(`th`,{className:`text-right px-3 py-2`,children:`Uptime`}),k(`th`,{className:`w-44`})]})}),T(`tbody`,{children:[d.length===0&&k(`tr`,{children:k(`td`,{colSpan:9,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:i===`ghost`?`No ghost processes detected.`:`Scanning…`})}),d.map(e=>T(`tr`,{className:`border-t border-border ${e.classification===`ghost`?`bg-destructive/5`:``}`,children:[k(`td`,{className:`px-3 py-2`,children:k(`span`,{className:`inline-block rounded-full px-1.5 py-0.5 text-[10px] font-medium ${e.classification===`ghost`?`bg-destructive/20 text-destructive`:e.classification===`root`?`bg-sky-500/20 text-sky-400`:e.classification===`system`?`bg-foreground-subtle/20 text-foreground-subtle`:`bg-success/20 text-success`}`,children:e.classification})}),k(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.pid}),T(`td`,{className:`px-3 py-2 text-right font-mono text-foreground-subtle`,children:[e.ppid,e.orphaned?` ⚠`:``]}),k(`td`,{className:`px-3 py-2 text-foreground-subtle text-[11px]`,children:e.addonId??`—`}),k(`td`,{className:`px-3 py-2 font-mono text-[10px] text-foreground-subtle break-all`,children:_e(e.command)}),k(`td`,{className:`px-3 py-2 text-right text-foreground`,children:e.cpuPercent.toFixed(1)}),k(`td`,{className:`px-3 py-2 text-right text-foreground`,children:Z(e.memoryRssBytes)}),k(`td`,{className:`px-3 py-2 text-right text-foreground-subtle`,children:ge(e.uptimeSec)}),k(`td`,{className:`px-3 py-2 text-right`,children:T(`div`,{className:`inline-flex gap-1`,children:[T(`button`,{type:`button`,disabled:p.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{h(e,!1)},title:`SIGTERM`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-border text-[10px] text-foreground hover:bg-surface-hover disabled:opacity-30`,children:[k(U,{className:`h-3 w-3`}),` Term`]}),T(`button`,{type:`button`,disabled:p.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{h(e,!0)},title:`SIGKILL`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-destructive/30 text-[10px] text-destructive hover:bg-destructive/10 disabled:opacity-30`,children:[k(Q,{className:`h-3 w-3`}),` Kill`]})]})})]},e.pid))]})]})}),p.isError&&T(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,p.error instanceof Error?p.error.message:`unknown`]})]})}function ye({nodeId:e,addonIds:t}){return t.length===0?k(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No addons on this node`}):k(`div`,{className:`w-full py-2`,children:k(ae,{nodeId:e,addonIds:t,level:`global`})})}w();function be({nodeId:e,addons:t}){let n=D(),{data:r,isLoading:i}=_({nodeId:e}),a=E(()=>{let e=new Map;for(let n of t)for(let t of n.capabilities){let r=e.get(t)??[];r.push(n.id),e.set(t,r)}return[...e.entries()].toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({capName:e,providers:t}))},[t]),o=m({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCapabilityBindings`]]})}});return a.length===0?k(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No capabilities on this node`}):T(`table`,{className:`w-full text-xs`,children:[k(`thead`,{children:T(`tr`,{className:`text-muted-foreground text-left`,children:[k(`th`,{className:`py-2 font-medium w-1/2`,children:`Capability`}),k(`th`,{className:`py-2 font-medium`,children:`Bound provider`})]})}),k(`tbody`,{children:a.map(({capName:t,providers:n})=>{let a=r?.[t]??n[0]??``,s=n.length===1;return T(`tr`,{className:`border-t border-border/50`,children:[k(`td`,{className:`py-2 font-medium`,children:t}),k(`td`,{className:`py-2`,children:k(`select`,{value:a,onChange:n=>o.mutate({nodeId:e,capName:t,addonId:n.target.value}),disabled:s||o.isPending||i,className:`w-full rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-60`,title:s?`Only one provider installed — choice becomes available once a second addon registers this capability`:void 0,children:n.map(e=>k(`option`,{value:e,children:e},e))})})]},t)})})]})}w();function xe(e){if(e==null)return`—`;let t=Math.floor(e/1e3),n=Math.floor(t/86400),r=Math.floor(t%86400/3600),i=Math.floor(t%3600/60);return n>0?`${n}d ${r}h ${i}m`:r>0?`${r}h ${i}m`:`${i}m`}function Se(e){let[t,n]=O(!1),[r,i]=O(e.name),a=D(),o=h({onSuccess:()=>{a.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}}),s=(e.localIps??[]).filter(e=>!e.includes(`:`)),c=(e.localIps??[]).filter(e=>e.includes(`:`)),l=async()=>{if(!r.trim()||r===e.name){n(!1);return}try{await o.mutateAsync({nodeId:e.nodeId,name:r.trim()}),n(!1)}catch(e){console.error(`Rename failed:`,e)}},u=[[`Node ID`,k(`span`,{className:`font-mono text-xs`,children:e.nodeId})],[`Display Name`,t?T(`div`,{className:`flex items-center gap-1.5`,children:[k(`input`,{type:`text`,className:`flex-1 px-2 py-0.5 text-xs border border-border rounded bg-background focus:outline-none focus:ring-1 focus:ring-primary`,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&l(),e.key===`Escape`&&n(!1)},disabled:o.isPending,autoFocus:!0}),k(`button`,{onClick:()=>void l(),disabled:o.isPending,className:`p-0.5 text-success hover:bg-success/10 rounded`,title:`Save`,children:k(L,{className:`h-3.5 w-3.5`})}),k(`button`,{onClick:()=>n(!1),className:`p-0.5 text-muted-foreground hover:bg-muted rounded`,title:`Cancel`,children:k(V,{className:`h-3.5 w-3.5`})})]}):T(`div`,{className:`flex items-center gap-1.5`,children:[k(`span`,{className:`text-xs`,children:e.name}),!e.isHub&&k(`button`,{onClick:()=>{i(e.name),n(!0)},className:`p-0.5 text-muted-foreground hover:text-primary rounded`,title:`Rename`,children:k(M,{className:`h-3 w-3`})})]})],[`Hostname`,k(`span`,{className:`text-xs`,children:e.hostname})],[`Role`,e.isHub?k(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary font-medium`,children:`Hub`}):k(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium`,children:`Agent`})],[`Platform`,T(`span`,{className:`text-xs`,children:[e.platform,` / `,e.arch]})],[`CPU`,T(`span`,{className:`text-xs`,children:[e.cpuModel??`—`,` (`,e.cpuCores,` cores)`]})],[`Memory`,k(`span`,{className:`text-xs`,children:e.memoryMB>0?`${(e.memoryMB/1024).toFixed(1)} GB`:`—`})],[`Uptime`,k(`span`,{className:`text-xs`,children:xe(e.uptime)})],[`Engines`,e.engines.length>0?k(`div`,{className:`flex flex-wrap gap-1`,children:e.engines.map(e=>k(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e))}):k(`span`,{className:`text-xs text-muted-foreground`,children:`—`})]];return s.length>0&&u.push([`IPv4`,k(`div`,{className:`flex flex-wrap gap-1.5`,children:s.map((e,t)=>k(`span`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted`,children:e},`${e}-${t}`))})]),c.length>0&&u.push([`IPv6`,k(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map((e,t)=>k(`span`,{className:`font-mono text-[10px] px-1.5 py-0.5 rounded bg-muted truncate max-w-[280px]`,title:e,children:e},`${e}-${t}`))})]),k(`div`,{className:`py-2`,children:k(`table`,{className:`w-full text-sm`,children:k(`tbody`,{children:u.map(([e,t],n)=>T(`tr`,{className:n%2==0?`bg-muted/20`:``,children:[k(`td`,{className:`py-1.5 px-2 text-xs font-medium text-muted-foreground w-28 align-top whitespace-nowrap`,children:e}),k(`td`,{className:`py-1.5 px-2`,children:t})]},e))})})})}w();function Ce({node:e}){let t=j(),[n,r]=O(`info`),[i,a]=O(!1),o=e.processes??[],s=e.addons.map(e=>e.id),c=async()=>{if(!i){a(!0);try{await Promise.allSettled([t.trpcClient.pipelineOrchestrator.removeAgentSettings.mutate({agentNodeId:e.id}),t.trpcClient.clusterNodes.forgetNode.mutate({nodeId:e.id})])}finally{a(!1)}}};return e.isOnline?T(`div`,{className:`border border-border rounded-xl overflow-hidden`,children:[T(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30 border-b border-border`,children:[k(`div`,{className:`w-2.5 h-2.5 rounded-full bg-success`}),k(`span`,{className:`text-sm font-semibold`,children:e.name}),T(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>k(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),T(`div`,{className:`ml-auto flex gap-3 text-xs text-muted-foreground`,children:[T(`span`,{className:`flex items-center gap-1`,children:[k(ne,{className:`h-3 w-3`}),` `,e.cpuPercent,`%`]}),T(`span`,{className:`flex items-center gap-1`,children:[k(se,{className:`h-3 w-3`}),` `,e.memoryPercent,`%`]})]})]}),k(`div`,{className:`flex border-b border-border px-4`,children:[`info`,`addons`,`forks`,`processes`,`settings`,`capabilities`].map(t=>k(`button`,{onClick:()=>r(t),className:`px-3 py-2 text-xs font-medium border-b-2 transition-colors ${n===t?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:t===`info`?`Info`:t===`addons`?`Addons (${e.addons.length})`:t===`forks`?`Forks (${o.length})`:t===`processes`?`Processes`:t===`settings`?`Settings`:`Capabilities`},t))}),T(`div`,{className:`px-4 py-2`,children:[n===`info`&&k(Se,{nodeId:e.id,name:e.name,hostname:e.hostname,platform:e.platform,arch:e.arch,cpuModel:e.cpuModel,cpuCores:e.cpuCores,memoryMB:e.memoryMB,engines:e.engines,isHub:e.isHub,uptime:e.uptime,localIps:e.localIps}),n===`addons`&&k(ue,{nodeId:e.id,addons:e.addons,isHub:e.isHub}),n===`forks`&&k(he,{nodeId:e.id,processes:o}),n===`processes`&&k(ve,{nodeId:e.id}),n===`settings`&&k(ye,{nodeId:e.id,addonIds:s}),n===`capabilities`&&k(be,{nodeId:e.id,addons:e.addons})]})]}):T(`div`,{className:`border border-border rounded-xl overflow-hidden opacity-60`,children:[T(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30`,children:[k(`div`,{className:`w-2.5 h-2.5 rounded-full bg-destructive`}),k(`span`,{className:`text-sm font-semibold`,children:e.name}),T(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>k(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),k(`span`,{className:`ml-auto text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`})]}),T(`div`,{className:`flex items-center justify-between gap-3 px-4 py-3`,children:[T(`span`,{className:`text-xs text-muted-foreground`,children:[e.lastSeen?`Last seen ${new Date(e.lastSeen).toLocaleString()} — `:``,e.addons.length,` addon`,e.addons.length===1?``:`s`,` assigned; will resume when node reconnects`]}),T(`button`,{type:`button`,onClick:()=>void c(),disabled:i,title:`Forget this node — removes its saved history and pipeline assignments`,className:`flex items-center gap-1 text-xs px-2 py-1 rounded-md border border-border text-muted-foreground hover:text-destructive hover:border-destructive/50 disabled:opacity-50 transition-colors`,children:[k(U,{className:`h-3 w-3`}),i?`Forgetting…`:`Forget node`]})]})]})}w();function we({nodes:e,focusNodeId:t,focusNonce:n}){let r=[...e].toSorted((e,t)=>e.isHub?-1:t.isHub?1:e.isOnline&&!t.isOnline?-1:!e.isOnline&&t.isOnline?1:e.name.localeCompare(t.name)),i=C(null);return A(()=>{if(!t)return;let e=i.current?.querySelector(`#node-card-${CSS.escape(t)}`);e&&e.scrollIntoView({behavior:`smooth`,block:`start`})},[t,n]),k(`div`,{ref:i,className:`flex flex-col gap-4`,children:r.map(e=>k(`div`,{id:`node-card-${e.id}`,children:k(Ce,{node:e})},e.id))})}w();function Te(e){return e===`running`||e===`online`?`bg-success`:e===`crashed`||e===`failed`?`bg-destructive`:`bg-muted-foreground`}function Ee({runner:e,nodeId:t,expanded:n,pid:r,onToggleCaps:i}){let[o,s]=O(!1),c=a();function l(){c.mutateAsync({nodeId:t,addonId:e.addonId})}function u(){s(e=>!e)}return T(`div`,{className:`border border-border rounded-md px-2 py-1.5 text-xs space-y-1`,children:[T(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[k(`span`,{className:`shrink-0 h-1.5 w-1.5 rounded-full ${Te(e.state)}`,"aria-label":`status: ${e.state}`}),k(`span`,{className:`font-medium truncate flex-1 min-w-0`,children:e.name}),T(`span`,{className:`shrink-0 text-muted-foreground`,children:[e.cpu.toFixed(1),`%`]}),k(`span`,{className:`shrink-0 text-muted-foreground`,children:Z(e.mem)}),T(`button`,{type:`button`,"aria-label":`caps: ${e.caps.length}`,onClick:()=>i(r),className:`shrink-0 inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full bg-muted text-muted-foreground hover:bg-muted/80`,children:[k(n?z:R,{className:`h-2.5 w-2.5`,"aria-hidden":!0}),T(`span`,{children:[`caps: `,e.caps.length]})]}),k(`button`,{type:`button`,"aria-label":`Restart addon`,onClick:l,className:`shrink-0 p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-muted`,children:k(F,{className:`h-3 w-3`})}),k(`button`,{type:`button`,"aria-label":`Logs`,onClick:u,className:`shrink-0 p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-muted`,children:k(H,{className:`h-3 w-3`})})]}),n&&e.caps.length>0&&k(`ul`,{className:`pl-3 space-y-0.5`,children:e.caps.map(e=>T(`li`,{className:`text-muted-foreground`,children:[k(`span`,{className:`text-foreground`,children:e.name}),` · `,k(`span`,{children:e.addonId})]},`${e.name}\0${e.addonId}`))}),o&&k(f,{addonId:e.addonId,agentId:t,showScope:!0,onClose:()=>s(!1)})]})}w();function De(e){return e?`bg-success`:`bg-muted-foreground`}function $({data:e}){let[t,n]=O(new Set),i=S(e=>{n(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]);A(()=>{e.expandAllNonce!==0&&(e.expandAllValue?n(new Set(e.runners.map(e=>e.pid))):n(new Set))},[e.expandAllNonce,e.expandAllValue,e.runners]);let a=!e.isOnline,o=a?r(X(e.lastSeen)):null,s=o===null?`offline`:`offline · ${o}`;return T(`div`,{className:`border border-border rounded-xl bg-background shadow-md min-w-[280px] max-w-[360px] flex flex-col${a?` opacity-50`:``}`,children:[k(K,{type:`target`,position:J.Left}),k(K,{type:`source`,position:J.Right}),T(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-border`,children:[k(`span`,{className:`text-[10px] font-semibold px-1.5 py-0.5 rounded bg-muted text-muted-foreground shrink-0`,children:e.isHub?`HUB`:`AGENT`}),k(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${De(e.isOnline)}`,"aria-label":e.isOnline?`online`:`offline`}),a&&k(`span`,{className:`text-[10px] font-semibold px-1.5 py-0.5 rounded bg-destructive/10 text-destructive shrink-0`,title:o===null?`offline`:`last seen ${o}`,children:s}),k(`span`,{className:`font-semibold text-sm truncate flex-1 min-w-0`,children:e.identity.name}),k(`span`,{className:`text-xs text-muted-foreground shrink-0`,children:e.identity.ip}),T(`span`,{className:`text-xs text-muted-foreground shrink-0`,children:[e.identity.cpu,`%`]}),T(`span`,{className:`text-xs text-muted-foreground shrink-0`,children:[e.identity.mem,`%`]}),k(`button`,{type:`button`,"aria-label":`Open node detail`,onClick:()=>e.onOpenNodeDetail(e.nodeId),className:`shrink-0 text-xs text-muted-foreground hover:text-foreground underline-offset-2 hover:underline ml-1`,children:`↗`})]}),T(`div`,{className:`flex flex-col gap-1 p-2 max-h-96 overflow-auto`,children:[e.runners.map(n=>k(Ee,{runner:n,nodeId:e.nodeId,expanded:t.has(n.pid),onToggleCaps:i,pid:n.pid},n.pid)),e.runners.length===0&&k(`span`,{className:`text-xs text-muted-foreground px-1`,children:`No processes`})]})]})}w();var Oe={nodeBox:$},ke=`camstack-cluster-graph-layout`;function Ae(e,t){let n=new Map,r=0,i=0;for(let a=0;a<e.length;a++){let o=e[a];o!==void 0&&(t[a]?(n.set(o,{x:0,y:i*340}),i++):(n.set(o,{x:480,y:r*340}),r++))}return n}function je(e,t){if(e===``)return!0;let n=e.toLowerCase();return t.identity.name.toLowerCase().includes(n)?!0:t.runners.some(e=>e.name.toLowerCase().includes(n)||e.addonId.toLowerCase().includes(n)||e.caps.some(e=>e.name.toLowerCase().includes(n)||e.addonId.toLowerCase().includes(n)))}function Me({graph:e,onOpenNodeDetail:t}){let[n,r]=O(``),[i,a]=O(!1),[o,s]=O(0),c=S(()=>{a(!0),s(e=>e+1)},[]),l=S(()=>{a(!1),s(e=>e+1)},[]),u=S(e=>{t?.(e)},[t]),d=E(()=>Ae(e.nodes.map(e=>e.nodeId),e.nodes.map(e=>e.isHub)),[e.nodes]),{nodes:f,onNodesChange:p,resetLayout:m}=ie(ke,E(()=>e.nodes.map(e=>{let t=d.get(e.nodeId)??{x:0,y:0},r={...e,onOpenNodeDetail:u,expandAllValue:i,expandAllNonce:o},a=n!==``&&!je(n,r);return{id:e.nodeId,type:`nodeBox`,position:t,data:r,hidden:a}}),[e.nodes,d,u,n,i,o])),h=E(()=>e.edges.map(e=>({id:e.id,source:e.source,target:e.target,label:`moleculer`,style:e.online?{}:{strokeDasharray:`5,5`,opacity:.4},animated:!1})),[e.edges]);return T(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[T(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[k(`input`,{type:`search`,placeholder:`Filter by node / runner / cap…`,value:n,onChange:e=>r(e.target.value),className:`flex-1 text-xs border border-border rounded px-2 py-1 bg-background focus:outline-none focus:ring-1 focus:ring-ring`}),k(`button`,{type:`button`,onClick:c,className:`text-xs px-2 py-1 rounded border border-border hover:bg-muted`,children:`Expand all`}),k(`button`,{type:`button`,onClick:l,className:`text-xs px-2 py-1 rounded border border-border hover:bg-muted`,children:`Collapse all`}),k(`button`,{type:`button`,onClick:m,className:`text-xs px-2 py-1 rounded border border-border hover:bg-muted`,title:`Restore the automatic layout, discarding dragged positions`,children:`Reset layout`})]}),k(`div`,{className:`flex-1 min-h-0 border-t border-border overflow-hidden`,children:T(G,{nodes:f,edges:h,onNodesChange:p,nodesDraggable:!0,nodeTypes:Oe,fitView:!0,proOptions:{hideAttribution:!0},children:[k(q,{gap:20,size:1}),k(Y,{showInteractive:!1})]})})]})}function Ne(e){if(e===void 0||e.length===0)return[];let t=new Set,n=[];for(let r of e)for(let e of r.capabilities){let i=`${e}\0${r.addonId}`;t.has(i)||(t.add(i),n.push({name:e,addonId:r.addonId}))}return n.toSorted((e,t)=>e.name.localeCompare(t.name))}function Pe(e){let t=e.services;return{pid:e.pid,name:e.name,addonId:t?.[0]?.addonId??``,cpu:e.cpuPercent,mem:e.memoryRss,state:e.state,caps:Ne(t)}}function Fe(e){return{nodeId:e.id,isHub:e.isHub,isOnline:e.isOnline,lastSeen:e.lastSeen,identity:{name:e.name,ip:e.localIps?.[0]??``,cpu:e.cpuPercent,mem:e.memoryPercent,platform:e.platform,arch:e.arch},runners:e.processes.map(Pe)}}function Ie(e){let t=e.toSorted((e,t)=>{let n=+!!e.isHub;return+!!t.isHub-n}).map(Fe),n=t.find(e=>e.isHub);return n===void 0?{nodes:t,edges:[]}:{nodes:t,edges:t.filter(e=>!e.isHub).map(e=>({id:`hub:${n.nodeId}->${e.nodeId}`,source:n.nodeId,target:e.nodeId,online:e.isOnline&&n.isOnline}))}}w();function Le(e){let[t,n]=O(()=>typeof window<`u`?window.matchMedia(e).matches:!1);return A(()=>{let t=window.matchMedia(e),r=e=>n(e.matches);return t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t}function Re(){let{data:e,isLoading:t}=n(void 0,{staleTime:1/0}),[r,i]=O(null);return v(`cluster.topology-snapshot`,e=>{let t=e.data?.nodes;Array.isArray(t)&&i(t)}),{nodes:E(()=>r??e??[],[r,e]),isLoading:t&&!r}}function ze(){let[e,t]=O(`table`),[n,r]=O(void 0),[i,a]=O(0),o=Le(`(max-width: 767px)`),s=o&&e===`graph`?`table`:e,{nodes:c,isLoading:l}=Re(),u=E(()=>Ie(c),[c]),d=c.filter(e=>e.isOnline).length,f=c.filter(e=>!e.isOnline).length,p=S(e=>{t(`table`),r(e),a(e=>e+1)},[]),m=(n,r,i)=>T(`button`,{onClick:()=>t(n),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${e===n?`bg-primary text-primary-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[k(i,{className:`h-3.5 w-3.5`}),r]});return T(`div`,{className:`flex flex-col h-full gap-4 p-4`,children:[T(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[T(`div`,{className:`flex items-center gap-2`,children:[d>0&&T(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-success/10 text-success`,children:[d,` online`]}),f>0&&T(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:[f,` offline`]})]}),T(`div`,{className:`flex gap-0.5 p-1 rounded-lg bg-muted`,children:[m(`table`,`Table`,ce),!o&&m(`graph`,`Graph`,oe)]})]}),l?k(`div`,{className:`flex items-center justify-center flex-1 text-muted-foreground`,children:`Loading cluster topology...`}):s===`graph`?k(Me,{graph:u,onOpenNodeDetail:p}):k(`div`,{className:`flex-1 overflow-auto`,children:k(we,{nodes:c,focusNodeId:n,focusNonce:i})})]})}export{ze as ClusterPage};
@@ -1,2 +0,0 @@
1
- import{$r as e,B as t,Bn as n,Br as r,Cn as i,D as a,Dn as o,E as s,En as c,Fa as l,Fn as u,G as d,In as f,It as p,J as m,Ji as h,K as g,Ln as _,M as v,Mn as y,N as b,Nn as x,O as S,Oi as C,On as w,Or as T,Pa as E,Pn as D,Q as O,R as k,Rn as A,Si as ee,Sn as j,T as te,Tn as ne,U as re,Vn as M,W as N,X as P,Xi as ie,Y as ae,Yr as oe,a as se,bi as ce,bt as le,ca as ue,da as de,dn as F,dr as fe,et as pe,f as me,fr as he,g as ge,i as I,ii as _e,in as ve,ir as ye,j as L,jn as be,ki as xe,l as Se,m as Ce,ma as we,n as Te,nt as Ee,o as De,oa as Oe,oi as ke,p as Ae,pi as je,pn as Me,q as R,qi as Ne,r as Pe,rn as Fe,sa as Ie,tt as Le,u as Re,ua as ze,ur as Be,vn as Ve,wn as He,y as Ue,yn as We,z as Ge,zn as Ke}from"./src-9Nw_7MUt.js";import{I as z,K as B,Q as V,S as H,W as U,b as W,o as G,q as K,t as qe,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 Je,D as Ye,E as Xe,I as Ze,N as Qe,O as $e,S as et,T as tt,b as nt,g as rt,k as it,w as Y,y as at}from"./src-DYcadIAu.js";import{c as ot,k as st,p as X,r as ct,t as lt,u as ut}from"./player-overlays-CqpHdvYF.js";import{t as dt}from"./CapabilityBadges-D7EsQrNT.js";import{n as ft,t as pt}from"./rotate-ccw-C9Gcb3tJ.js";import{t as mt}from"./ProviderIcon-AXlCHsTd.js";import{t as ht}from"./pencil-DR7yGacK.js";import{t as gt}from"./plus-CekuJPnw.js";import{t as _t}from"./refresh-cw-DH7JcsAT.js";import{t as vt}from"./rotate-cw-CTrqUHcp.js";import{t as yt}from"./server-Crr45iTm.js";import{t as bt}from"./wifi-G6nDQGOi.js";import{B as xt,F as St,G as Ct,I as wt,O as Tt,R as Et,U as Dt,V as Ot,W as kt,_ as At,a as jt,c as Mt,i as Nt,k as Pt,p as Ft,r as It,s as Lt,t as Rt,v as zt,x as Bt}from"./index-Da6GKRLl.js";import{n as Vt,t as Ht}from"./useDevice-LyxwBrYX.js";import{t as Ut}from"./StatusBadge-Dcr2bw58.js";import{t as Wt}from"./useEventInvalidation-CoNLHhyv.js";import{n as Gt,r as Kt,t as qt}from"./SchemaTabBar-Lx0lVN3x.js";import{t as Jt}from"./FormBuilder-CL6dlXwQ.js";var Yt=Ot(`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`}]]),Xt=Ot(`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`}]]),Zt=Ot(`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`}]]),Qt=Ot(`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`}]]),$t=Ot(`map-pin`,[[`path`,{d:`M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0`,key:`1r0f0z`}],[`circle`,{cx:`12`,cy:`10`,r:`3`,key:`ilqhr7`}]]),en=Ot(`minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),tn=Ot(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),nn=Ot(`volume-2`,[[`path`,{d:`M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z`,key:`uqj9uw`}],[`path`,{d:`M16 9a5 5 0 0 1 0 6`,key:`1q6k2b`}],[`path`,{d:`M19.364 18.364a9 9 0 0 0 0-12.728`,key:`ijwkga`}]]);V();function rn({parentDeviceId:e}){let{t}=Rt(),n=Dt(),r=X(),{data:i,isLoading:a,isError:o}=Vt(e),{data:s}=j({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=d(s?.stableId??``,c,s?.childLayout),u=l.ungrouped,f=e=>n(`/devices/${String(e)}`),p=s?.name??``,m=(e,t)=>q(re,{trpc:r.trpcClient,device:{...t,name:ae(t,p)},variant:`minimal`,onNavigate:f},e),h=u.some(e=>!!e.role),g=u.some(e=>!e.role),_=h&&!g?t(`device.accessories`,{defaultValue:`Accessories`}):!h&&g?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),v=u.length>0?H(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[q(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:_}),q(`div`,{className:`space-y-1`,children:u.map(e=>m(e.id,e))})]}):null,y=l.disabledSection===void 0?null:q(N,{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?y===null?v:H(`div`,{className:`space-y-2`,children:[v,y]}):H(`div`,{className:`space-y-2`,children:[l.sections.map(e=>q(N,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>m(e.id,e))},e.title)),v,y]})}function an({deviceName:e,deviceType:t,provider:n,isOnline:r,features:i}){return H(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-surface p-6 text-center`,children:[q(mt,{type:n,size:`lg`}),H(`div`,{children:[q(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),q(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),H(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[q(Ut,{status:r?`online`:`offline`}),i.length>0&&q(dt,{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 on({deviceId:e}){let t=G(),n=Fe({deviceId:e},{refetchInterval:1e4,retry:!1}),r=ve({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),i=U(()=>sn(n.data??[]),[n.data]);return H(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[H(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[q(cn,{label:`Discovered`,value:i.total,icon:q(At,{className:`h-3.5 w-3.5`})}),q(cn,{label:`Adopted`,value:i.adopted,accent:`success`}),q(cn,{label:`Available`,value:i.available,accent:i.available>0?`primary`:void 0}),H(`button`,{type:`button`,onClick:()=>{r.mutateAsync({deviceId:e}).catch(()=>{})},disabled:r.isPending,className:`inline-flex items-center justify-center gap-1.5 rounded-lg border border-border px-3 py-2 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 self-stretch shrink-0`,children:[r.isPending?q(Bt,{className:`h-3.5 w-3.5 animate-spin`}):q(_t,{className:`h-3.5 w-3.5`}),q(`span`,{className:`hidden sm:inline`,children:`Discover`})]})]}),H(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-foreground-subtle border-t border-border-subtle pt-2`,children:[q(ln,{icon:q(bt,{className:`h-3 w-3 text-emerald-500`}),label:`${i.online} online`}),q(ln,{icon:q(zt,{className:`h-3 w-3 text-amber-500`}),label:`${i.sleeping} sleeping`}),q(ln,{icon:q(jt,{className:`h-3 w-3 text-destructive`}),label:`${i.offline} offline`}),i.unknown>0?q(ln,{icon:q(Yt,{className:`h-3 w-3 text-foreground-subtle`}),label:`${i.unknown} unknown`}):null]})]})}function sn(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 cn({label:e,value:t,icon:n,accent:r}){return H(`div`,{className:`flex flex-1 basis-[140px] min-w-0 flex-col gap-1 rounded-lg border px-2 py-1.5 sm:px-3 sm:py-2 ${r===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:r===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[H(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,q(`span`,{className:`truncate`,children:e})]}),q(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function ln({icon:e,label:t}){return H(`span`,{className:`inline-flex items-center gap-1`,children:[e,q(`span`,{children:t})]})}function un({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(h,{trpc:X().trpcClient,deviceId:e,features:t})})}function dn({deviceId:e,features:t}){return q(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:q(Ne,{trpc:X().trpcClient,deviceId:e,features:t})})}function Z({deviceId:e,deviceType:n,features:r}){let i=X(),a=Le(n)?.HeroCard??Ne,o=ut(ot(i.trpcClient,e)?.state.deviceStatus),s=o!==void 0&&o.online===!1,c=s?o.lastChangedAt:null;return H(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[s?q(`div`,{className:`flex justify-center`,children:q(t,{lastChangedAt:c})}):null,q(a,{trpc:i.trpcClient,deviceId:e,features:r})]})}function fn({deviceId:e}){let t=X(),{data:n,isLoading:r}=Ht(e),{data:i,isLoading:a}=Vt(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(Ge,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}var pn={[Y.Switch]:Z,[Y.Siren]:Z,[Y.Light]:Z,[Y.Sensor]:Z,[Y.Button]:Z,[Y.Hub]:on,[Y.Cover]:un,[Y.Valve]:Z,[Y.Humidifier]:Z,[Y.WaterHeater]:Z,[Y.Container]:fn,[Y.Lock]:Z,[Y.Fan]:Z,[Y.Thermostat]:Z,[Y.Climate]:Z,[Y.MediaPlayer]:Z,[Y.Control]:Z,[Y.AlarmPanel]:dn,[Y.EventEmitter]:dn,[Y.Notifier]:dn,[Y.Script]:dn,[Y.Automation]:dn,[Y.Presence]:Z,[Y.Update]:Z,[Y.Vacuum]:Z,[Y.LawnMower]:Z,[Y.Weather]:Z,[Y.Image]:Z,[Y.PetFeeder]:Z};function mn(e){return q(pn[e.deviceType]??an,{...e})}function hn(e){return se(X().trpcClient,e)}V();function gn(e){let[t,n]=K(`idle`),[r,i]=K(null),a=B(null),o=B(null),s=B(null),c=B(!0),l=fe(),u=Be(),d=he(),f=z(()=>{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=z(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=z(async()=>{if(e===null||t!==`idle`&&t!==`error`)return;i(null);let r=null,f=null,m=null;try{n(`requesting-mic`),r=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),o.current=r,n(`starting`);let t=await l.mutateAsync({deviceId:e});m=t.sessionId,s.current=m,n(`connecting`),f=new RTCPeerConnection,a.current=f,f.oniceconnectionstatechange=()=>{if(!c.current)return;let e=f.iceConnectionState;e===`connected`||e===`completed`?n(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&c.current&&(i(e===`failed`?`WebRTC connection failed`:null),p())};for(let e of r.getAudioTracks())f.addTrack(e,r);await f.setRemoteDescription({type:`offer`,sdp:t.sdpOffer});let d=await f.createAnswer();await f.setLocalDescription(d);let h=f.localDescription?.sdp??d.sdp??``;await u.mutateAsync({deviceId:e,sessionId:m,sdpAnswer:h})}catch(t){let l=t instanceof Error?t.message:String(t);if(console.warn(`[intercom] start failed`,t),f)try{f.close()}catch{}if(r)for(let e of r.getTracks())try{e.stop()}catch{}if(a.current=null,o.current=null,m!==null)try{await d.mutateAsync({deviceId:e,sessionId:m})}catch{}s.current=null,c.current&&(i(l),n(`error`))}},[e,t,l,u,d,p]);return J(()=>(c.current=!0,()=>{c.current=!1;let t=s.current;if(t!==null&&e!==null&&d.mutate({deviceId:e,sessionId:t}),a.current){try{a.current.close()}catch{}a.current=null}if(o.current){for(let e of o.current.getTracks())try{e.stop()}catch{}o.current=null}s.current=null}),[e]),{state:t,error:r,start:m,stop:p,isTalking:t===`talking`}}V();var _n=0;function Q(){return++_n}function vn(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function yn(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 bn(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 xn(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 Sn({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: ${vn(e)} — type help or context for available commands`}),n}),[o,s]=K(``),[c,l]=K([]),[u,d]=K(-1),f=B(null),p=B(null);J(()=>{let e=p.current;e&&(e.scrollTop=e.scrollHeight)},[i]);let m=z(()=>{f.current?.focus()},[]),h=qe({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: ${vn(e)}`}]),s(``);return}if(n===`help`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...yn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`context`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...xn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`examples`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...bn(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: ${vn(e)}`}]))}let v={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return H(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${n??``}`,onClick:m,children:[H(`div`,{ref:p,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[i.map(e=>q(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${v[e.kind]}`,children:e.text},e.id)),h.isPending&&q(`span`,{className:`text-zinc-500 animate-pulse`,children:`…thinking`})]}),H(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[q(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),q(`input`,{ref:f,value:o,onChange:e=>s(e.target.value),onKeyDown:_,disabled:h.isPending,placeholder:`device.state.battery.value`,autoFocus:!0,className:`flex-1 bg-transparent text-zinc-100 placeholder:text-zinc-600 focus:outline-none caret-emerald-400 disabled:opacity-50`,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`})]})]})}function Cn({deviceId:e,intercomAvailable:t=!1}){let n=X(),r=typeof window<`u`?window.location.origin:``,i=Number.isFinite(e),a=hn(i?e:null),{streams:o,pipelineMetrics:s,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h}=I(n.trpcClient,i?e:null),g=R(n.trpcClient,i?e:null),_=gn(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=ct(),C=S(),w=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,T=x.length>0?q(W,{children:x.map(e=>q(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return q(Ue,{serverUrl:r,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h,...C.request?{playbackUrl:C.request.url,playbackAuthToken:w,...C.request.label?{playbackLabel:C.request.label}:{},onExitPlayback:()=>C.clear()}:{},streams:o,pipelineMetrics:s,phase:a.phase,detections:a,defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:g.src,...g.src?{posterUrl:g.src}:{},snapshotLoading:g.loading,onRefreshSnapshot:g.refresh,intercomAvailable:t,intercomShown:y,onIntercomToggle:b,extraOverlay:T,chromeless:!0,className:`h-full`})}function wn({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full`,children:q(ge,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function Tn({deviceId:e}){if(!Number.isFinite(e))return H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]});let t=[`CamStack REPL — device #${e}`,``,` device.state.battery.value sync state read`,` await device.snapshot.getSnapshot({}) cap action`,``,` type 'examples' for more, 'context' for the full API`].join(`
2
- `);return q(Sn,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function En({deviceId:e}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:q(Ce,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function Dn({deviceId:e}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:q(me,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function On({deviceId:e}){let t=G(),n=Number.isFinite(e),{data:r}=j({deviceId:e},{enabled:n}),i=typeof r?.type==`string`?r.type:`camera`;Wt([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:a,isLoading:s,isError:c,error:l}=We({deviceId:e},{enabled:n}),{data:u}=o({deviceType:i},{enabled:!!i}),d=Ke({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 H(`div`,{className:`p-4 text-xs text-red-400`,children:[`Failed to load bindings: `,l instanceof Error?l.message:String(l)]});let f=new Map,p={};for(let e of u??[])p[e.capName]=e.wrappers;for(let e of a?.entries??[])f.set(e.capName,{...e,wrappers:p[e.capName]??[]});for(let e of u??[])f.has(e.capName)||f.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let m=[...f.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(m.length===0)return H(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[q(ft,{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 h=m.filter(e=>e.kind!==`unbound`).length;return H(`div`,{className:`flex flex-col gap-3 p-1`,children:[H(`div`,{className:`text-[11px] text-foreground-subtle`,children:[q(`span`,{className:`font-medium text-foreground`,children:h}),` of `,m.length,` capabilit`,m.length===1?`y`:`ies`,` bound — rows marked `,q(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),q(ze,{columns:[{key:`capability`,header:`Capability`,render:e=>q(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>q(kn,{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(An,{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(jn,{wrappers:t.wrappers,activeWrapperId:n,disabled:d.isPending,onPick:r=>{let i=n===r;d.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}],rows:m,rowKey:e=>e.capName,minWidthPx:720})]})}function kn({kind:e}){return e===`native`?H(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-success/30 text-success bg-success/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[q(yt,{className:`h-3 w-3`}),`native`]}):e===`wrapped`?H(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-primary/30 text-primary bg-primary/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[q(Xt,{className:`h-3 w-3`}),`wrapped`]}):e===`linked`?H(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-warning/30 text-warning bg-warning/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[q(Qt,{className:`h-3 w-3`}),`linked`]}):H(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border text-foreground-subtle/70 px-1.5 py-0.5 text-[10px] font-medium`,children:[q(en,{className:`h-3 w-3`}),`unbound`]})}function An({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 jn({wrappers:e,activeWrapperId:t,disabled:n,onPick:r}){return e.length===0?q(`span`,{className:`text-[10px] opacity-40`,children:`none available`}):q(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let i=e===t;return H(`button`,{disabled:n,onClick:()=>r(e),title:i?`Click to deactivate (revert to native)`:`Activate wrapper ${e}`,className:`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 font-mono text-[10px] transition-colors disabled:opacity-50 ${i?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[q(i?St:pt,{className:`h-3 w-3`}),e]},e)})})}V();function Mn({schema:e,values:t,pendingKeys:n,onChange:r,onAction:i,onSave:a,onDiscard:o,disabled:s,activeSubTab:c,onSubTabChange:l,flattenTabs:u=!1}){let d=e.tabs??[],f=U(()=>{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]),p=new Set(d.map(e=>e.id)),m=[...d,...[...f.keys()].filter(e=>!p.has(e)).map(e=>({id:e,label:e,icon:`wrench`,order:100}))],h=m[0]?.id??`general`,[g,_]=K(h),v=l!==void 0,y=new Set(m.map(e=>e.id)),b=v?c&&y.has(c)?c:h:y.has(g)?g:h,x=e=>{v?l(e):_(e)},S=f.get(b)??[],C={sections:S.length<=1?S.length===1?[{...S[0],title:``}]:S:S.every(e=>!e.title)?[{...S[0],title:``,fields:S.flatMap(e=>e.fields)}]:S},w=q(Gt,{pendingCount:n.length,onSave:()=>a(n),onDiscard:()=>o(n),saving:s});if(u||m.length<=1)return H(`div`,{className:`flex flex-col gap-3`,children:[q(Jt,{schema:e,values:t,onChange:r,onAction:i,disabled:s}),w]});let T=new Map,E=new Map;for(let[e,t]of f){T.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&&E.set(e,a)}return H(`div`,{className:`flex flex-col gap-3`,children:[q(qt,{tabs:m.map(e=>({id:e.id,label:e.label})),activeId:b,onChange:x,countByTab:T,pendingByTab:E}),q(Jt,{schema:C,values:t,onChange:r,onAction:i,disabled:s}),w]})}var Nn=`device-export`,Pn=`export`,Fn=`Export`;function In(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(In):e.type===`sub-tabs`?e.tabs.some(e=>e.fields.some(In)):e.writerCapName===Nn}function Ln(e){return e.fields.some(In)}V();function Rn(e,t){return t&&t===`admin`?e:!0}function zn(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?Ln(e)&&Ln(t)?e.id.localeCompare(t.id):(e.order??0)-(t.order??0):n.localeCompare(r)})};return e.tabs?{...t,tabs:e.tabs}:t}function Bn(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 Vn(e){return e.key}function Hn(e){if(!Bn(e))return e.value}function Un(e){return Bn(e)?null:e}function Wn(e,t){for(let n of e)if(t(n),n.type===`group`)Wn(n.fields,t);else if(n.type===`sub-tabs`)for(let e of n.tabs)Wn(e.fields,t)}function Gn(e){if(!e)return{};let t={};for(let n of e.sections)Wn(n.fields,e=>{let n=Vn(e);n!==null&&(t[n]=Hn(e))});return t}function Kn(e,t){if(!e)return null;let n=null;for(let r of e.sections)if(Wn(r.fields,e=>{if(n!==null||Vn(e)!==t)return;let r=Un(e);r&&r.writerCapName&&r.writerAddonId&&(n={capName:r.writerCapName,addonId:r.writerAddonId})}),n!==null)break;return n}function qn(e){return{...e,fields:e.fields.map(Jn)}}function Jn(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`object-array`?e:{...e,readonlyField:!0}}function Yn(e,t){return e&&{...e,sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{let n=Un(e);return n?Rn(t,n.minRole)?e:Jn(e):e})}))}}function Xn({deviceId:e,sectionFilter:t,activeSubTab:r,onSubTabChange:a,flattenSubTabs:o}){let s=G(),{user:c}=It(),l=c?.isAdmin===!0,u=B(!1),{data:d,isLoading:f}=i({deviceId:e},{refetchInterval:()=>u.current?!1:2500,enabled:Number.isFinite(e)}),{data:p}=j({deviceId:e},{enabled:Number.isFinite(e)}),m=d?.settings??null,h=d?.live??null,g=U(()=>{if(!m&&!h)return null;let e=m?.sections??[],n=(h?.sections??[]).map(qn),r=[...e,...n],i=t?r.filter(t):r.filter(e=>e.location!==`top-tab`&&!Ln(e));if(i.length===0)return null;let a=new Set;for(let e of i)a.add(e.tab??`general`);let o=[...m?.tabs??[],...(h?.tabs??[]).filter(e=>!(m?.tabs??[]).some(t=>t.id===e.id))].filter(e=>a.has(e.id));return o.length>0?{tabs:o,sections:i}:{sections:i}},[m,h,t]),_=U(()=>zn(g),[g]),v=U(()=>Yn(_,l),[_,l]),b=U(()=>Gn(v),[v]),x=xe(),S=C(),w=n(),T=y(),E=M({onSuccess:()=>{s.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),D={isPending:E.isPending,mutate:t=>{E.mutate({deviceId:e,changes:[...t]})}},O=Kt({schema:v,serverValues:b,onImmediateSave:z(e=>{let t=Object.entries(e).map(([e,t])=>{let n=Kn(v,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&D.mutate(t)},[v,D]),onDeferredSave:z(e=>{let t=Object.entries(e).map(([e,t])=>{let n=Kn(v,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&D.mutate(t)},[v,D])}),{values:k,pendingKeys:A,handleChange:ee,handleSave:te,handleDiscard:ne}=O;if(u.current=O.editingPaused,f)return H(`div`,{className:`flex items-center justify-center py-12 text-foreground-subtle`,children:[q(Bt,{className:`h-4 w-4 animate-spin mr-2`}),q(`span`,{className:`text-xs`,children:`Loading device aggregate…`})]});if(!v||v.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 re(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=Qe(e,r);await x.mutateAsync({brokerId:i}),s.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]});return}if(t===`test-probe`){if(!p)return{status:`error`,error:`Device metadata not loaded yet`};try{return await w.mutateAsync({addonId:p.addonId,type:p.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=Qe(e,t),i=await S.mutateAsync({brokerId:r});return s.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),i}if(t===`device-custom-action`){let t=await T.mutateAsync({deviceId:e,action:n,input:r});return s.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),t}throw Error(`[device-aggregate] unknown action "${t}"`)}return q(Mn,{schema:v,values:k,pendingKeys:A,onChange:ee,onAction:re,onSave:te,onDiscard:ne,disabled:D.isPending,activeSubTab:r,onSubTabChange:a,flattenTabs:o})}function Zn({deviceId:e,activeSubTab:t,onSubTabChange:n}){return q(`div`,{className:`flex flex-col gap-3`,children:q(Xn,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}V();function Qn(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 $n(e,t,n){let r=e?.stepOverridesByAgent?.[t]?.[n];if(r)return r.enabled===!1?`off`:(r.enabled,`on`);let i=e?.stepToggles?.[n];return i===!1?`off`:i===!0?`on`:`inherit`}function er({agents:e,currentAgent:t,onPick:n}){let[r,i]=K(!1);return H(`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:()=>i(e=>!e),children:`Mirror from ▾`}),r&&q(`div`,{className:`absolute top-full left-0 mt-1 min-w-[140px] bg-surface border border-border rounded shadow-lg z-10`,children:e.filter(e=>e!==t).map(e=>q(`button`,{type:`button`,className:`w-full text-left px-3 py-1.5 text-xs hover:bg-muted`,onClick:()=>{i(!1),n(e)},children:e},e))})]})}function tr({deviceId:t,refreshToken:n}){let i=G(),[a,o]=K(null),[s,c]=K(null),[u,d]=K(null),[f,p]=K(null),m=e({deviceId:t}),h=ke(),g=_e({deviceId:t}),_=oe(),v=U(()=>g.data?.agentNodeId||_.data?.find(e=>e.online)?.nodeId||`hub`,[g.data?.agentNodeId,_.data]),y=s??v,b=r({nodeId:y??``},{enabled:!!y}),x=je({onSuccess:()=>{i.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),d(null)}}),S=U(()=>b.data?ue(b.data):[],[b.data]),C=U(()=>{let e=m.data??null,t={};for(let n of h.data??[])for(let r of Object.keys(n.settings.addonDefaults)){let i=t[r]??[];i.push({agentNodeId:n.nodeId,state:$n(e,n.nodeId,r)}),t[r]=i}return t},[m.data,h.data]),w=a?Qn(b.data??null,a):null,T=y?h.data?.find(e=>e.nodeId===y)??null:null,E=a&&T?T.settings.addonDefaults[a]??null:null,D=a&&y?m.data?.stepOverridesByAgent?.[y]?.[a]??null:null,O=b.data?.selectedEngine.format??`coreml`,k=e=>{c(e),d(null),p(null)};return h.isLoading||b.isLoading?q(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`}):b.data?q(`div`,{className:`@container h-full`,style:{containerType:`inline-size`},children:H(`div`,{className:`flex flex-col @[720px]:flex-row h-full`,children:[q(`aside`,{className:`w-full @[720px]:w-[300px] @[720px]:flex-shrink-0 border-b @[720px]:border-b-0 @[720px]:border-r border-border overflow-y-auto max-h-[40vh] @[720px]:max-h-none`,children:q(Ie,{tree:S,selectedAddonId:a,onSelect:e=>{o(e),d(null),p(null)},agentDots:C})}),q(`section`,{className:`flex-1 min-w-0 p-4 overflow-y-auto`,children:!a||!w?q(`div`,{className:`text-sm text-foreground-subtle`,children:`Select a step on the left to configure it for this camera.`}):H(`div`,{className:`space-y-4`,children:[H(`div`,{children:[q(`div`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle`,children:`Selected step`}),q(`div`,{className:`text-base font-semibold`,children:w.name})]}),H(`div`,{className:`flex items-end gap-3 flex-wrap`,children:[H(`div`,{children:[q(`div`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle mb-1`,children:`Agent`}),q(`div`,{className:`flex rounded border border-border overflow-hidden`,children:(h.data??[]).map(e=>q(`button`,{type:`button`,onClick:()=>k(e.nodeId),className:`px-3 py-1 text-xs ${y===e.nodeId?`bg-primary text-primary-foreground`:`bg-surface hover:bg-muted`}`,children:e.nodeId},e.nodeId))})]}),q(er,{agents:(h.data??[]).map(e=>e.nodeId),currentAgent:y,onPick:e=>{if(!y||!a||!b.data||!h.data)return;let t=h.data.find(t=>t.nodeId===e),n=h.data.find(e=>e.nodeId===y);if(!t||!n)return;let[r]=l({source:{nodeId:t.nodeId,engine:{format:O},defaults:t.settings.addonDefaults},target:{nodeId:n.nodeId,engine:{format:O},defaults:n.settings.addonDefaults},catalog:b.data,addonIds:[a]});if(!r){p(`no mirror result`);return}if(r.outcome===`skip`){p(`skipped: ${r.reason??`no candidate`}`);return}d(r.patch),p(`${r.outcome} from ${e}`)}}),f&&q(`div`,{className:`text-[10px] text-foreground-subtle`,children:f})]}),E&&q(Oe,{mode:`device`,addon:w,agentDefault:E,agentNodeId:y??``,currentPatch:u??D,engineFormat:O,onChangePatch:d}),H(`div`,{className:`flex items-center justify-between gap-2 pt-4 border-t border-border`,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:!D||x.isPending,onClick:()=>{!y||!a||x.mutate({deviceId:t,agentNodeId:y,addonId:a,patch:null})},children:`Clear override`}),H(`div`,{className:`flex items-center gap-2`,children:[q(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:()=>d(null),children:`Reset draft`}),q(`button`,{type:`button`,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,disabled:!y||!a||x.isPending,onClick:()=>{!y||!a||x.mutate({deviceId:t,agentNodeId:y,addonId:a,patch:u})},children:x.isPending?`Saving…`:`Save`})]})]})]})})]})}):q(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`})}function $({label:e,value:t}){return H(`div`,{className:`${st} flex items-start gap-2 sm:gap-3`,children:[q(`span`,{className:`w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle`,children:e}),q(`div`,{className:`flex-1 min-w-0 text-[11px] text-foreground`,children:t})]})}V();function nr({deviceId:e,initialName:t}){let n=G(),[r,i]=K(!1),[a,o]=K(t),[s,c]=K(!1),l=B(null);J(()=>{r||o(t)},[t,r]),J(()=>{r&&l.current?.focus()},[r]);let u=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)}},p=()=>{o(t),i(!1)};return r?q($,{label:`Name`,value:H(`div`,{className:`flex items-center gap-1`,children:[q(`input`,{ref:l,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?d():e.key===`Escape`&&p()},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(St,{className:`h-3 w-3`})}),q(`button`,{type:`button`,onClick:p,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:q(Nt,{className:`h-3 w-3`})})]})}):q($,{label:`Name`,value:H(`div`,{className:`flex items-center gap-2 group`,children:[q(`span`,{className:`truncate`,children:t}),q(`button`,{type:`button`,onClick:()=>i(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit name`,children:q(ht,{className:`h-3.5 w-3.5`})})]})})}V();function rr({deviceId:e,initialLocation:t}){let n=G(),[r,i]=K(!1),[a,o]=K(t??``),[s,c]=K(!1),l=B(null),{data:d}=w(void 0,{enabled:r}),f=d??[];J(()=>{r||o(t??``)},[t,r]),J(()=>{r&&l.current?.focus()},[r]);let p=u({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]})}}),m=U(()=>{let e=a.trim().toLowerCase();return e.length===0?f:f.filter(t=>t.toLowerCase()!==e&&t.toLowerCase().includes(e))},[f,a]),h=a.trim().length>0&&!f.some(e=>e.toLowerCase()===a.trim().toLowerCase()),g=async n=>{let r=(n??a).trim(),o=r.length===0?null:r;if(o===(t??null)){i(!1);return}c(!0);try{await p.mutateAsync({deviceId:e,location:o}),i(!1)}catch{}finally{c(!1)}},_=()=>{o(t??``),i(!1)};return r?q($,{label:`Location`,value:H(`div`,{className:`relative`,children:[H(`div`,{className:`flex items-center gap-1`,children:[q(`input`,{ref:l,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?g():e.key===`Escape`&&_()},disabled:s,placeholder:`Room / area (or leave empty to clear)`,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),q(`button`,{type:`button`,onClick:()=>void g(),disabled:s,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:q(St,{className:`h-3 w-3`})}),q(`button`,{type:`button`,onClick:_,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:q(Nt,{className:`h-3 w-3`})})]}),(m.length>0||h)&&H(`div`,{className:`absolute z-10 left-0 right-0 mt-0.5 max-h-40 overflow-y-auto rounded-md border border-border bg-surface shadow-md`,children:[m.map(e=>H(`button`,{type:`button`,onClick:()=>{o(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($t,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),q(`span`,{className:`truncate`,children:e})]},e)),h&&H(`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`}),H(`span`,{className:`font-medium truncate`,children:[`"`,a.trim(),`"`]})]})]})]})}):q($,{label:`Location`,value:H(`div`,{className:`flex items-center gap-2 group`,children:[t?q(`span`,{className:`truncate`,children:t}):q(`span`,{className:`italic text-foreground-subtle`,children:`unset`}),q(`button`,{type:`button`,onClick:()=>i(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit location`,children:q(ht,{className:`h-3.5 w-3.5`})})]})})}V();function ir({deviceId:e}){let t=G(),{data:n}=Ht(e),{data:r}=Vt(e),[i,a]=K(null),o=_({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=pe(s,typeof n.linkDeviceId==`number`?n.linkDeviceId:null,typeof n.primaryChildEntityId==`string`?n.primaryChildEntityId:null);return H(W,{children:[q($,{label:`Primary child`,value:q(k,{childrenList:s,selectedId:c===null?s[0].id:c.id,onSetPrimary:t=>o.mutate({deviceId:e,primaryChildEntityId:t}),disabled:o.isPending})}),i!==null&&q(`p`,{role:`alert`,className:`px-3 sm:px-4 py-1.5 text-[11px] text-danger`,children:i})]})}V();var ar=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function or(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function sr(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function cr(){let e=v(),t=b(),{data:n}=j({deviceId:e??0},{enabled:e!==null}),{data:r}=We({deviceId:e??0},{enabled:e!==null}),i=n??t??null,[a,o]=K(`identity`);if(e===null||!i)return null;let s=String(i.stableId??``),c=String(i.name??``),l=String(i.type??``),u=String(i.addonId??``),d=i.features??[],f=new Set([`device-status`,`feature-probe`,`device-ops`]),p=(r?.entries??[]).filter(e=>e.kind===`native`&&!f.has(e.capName)).map(e=>e.capName),m=d.length>0?d:p,h=i.location??null,g=i.metadata??null,_=g!==null&&Object.keys(g).length>0;return H(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[H(`div`,{className:`border-b border-border px-3 sm:px-4 py-2 flex items-center justify-between gap-3`,children:[q(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Device Info`}),_&&H(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[q(lr,{active:a===`identity`,onClick:()=>o(`identity`),label:`Identity`}),q(lr,{active:a===`hardware`,onClick:()=>o(`hardware`),label:`Hardware`})]})]}),(!_||a===`identity`)&&H(`div`,{className:`divide-y divide-border`,children:[q($,{label:`ID`,value:H(`span`,{className:`font-mono text-[11px] text-foreground`,children:[`#${e}`,H(`span`,{className:`ml-1.5 text-foreground-subtle`,children:[`(`,s,`)`]})]})}),q(nr,{deviceId:e,initialName:c}),q(rr,{deviceId:e,initialLocation:h}),q(ir,{deviceId:e}),q($,{label:`Type`,value:l}),q($,{label:`Provider`,value:q(mt,{type:u,size:`sm`,showLabel:!0})}),q($,{label:`Capabilities`,value:m.length>0?q(dt,{capabilities:m,showLabels:!0}):q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),_&&a===`hardware`&&q(ur,{metadata:g})]})}function lr({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 ur({metadata:e}){let t=ar.filter(t=>t in e),n=Object.keys(e).filter(e=>!ar.includes(e)).toSorted(),r=[...t,...n];return H(`div`,{children:[q(`div`,{className:`px-3 sm:px-4 py-1.5 text-[10px] text-foreground-subtle border-b border-border bg-surface-subtle/40`,children:`Auto-populated by the driver on every connect. Read-only.`}),q(`div`,{className:`divide-y divide-border`,children:r.map(t=>q($,{label:or(t),value:q(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:sr(e[t])})},t))})]})}V();function dr({deviceId:e}){let[t,n]=K(null),r=F({onSuccess:e=>{n(e.changed?`Re-aligned with source — ${e.rebuiltChildren} child${e.rebuiltChildren===1?``:`ren`} rebuilt.`:`Already up to date.`)},onError:e=>n(`Re-sync failed: ${e.message}`)});return H(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[H(`div`,{className:`flex items-center justify-between gap-3`,children:[H(`div`,{children:[q(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:`Re-sync`}),q(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:`Re-align this device's type, role, capabilities and units with its source.`})]}),H(`button`,{type:`button`,disabled:r.isPending,onClick:()=>{n(null),r.mutate({camDeviceId:e})},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[q(_t,{className:`h-3 w-3 ${r.isPending?`animate-spin`:``}`}),r.isPending?`Re-syncing…`:`Re-sync`]})]}),t!==null&&q(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:t})]})}V();var fr={icon:``,label:``,unit:``,precision:``,hidden:!1};function pr(e){return{icon:e?.icon??``,label:e?.label??``,unit:e?.unit??``,precision:e?.precision===void 0?``:String(e.precision),hidden:e?.hidden===!0}}function mr(e){if(typeof e!=`object`||!e)return;let t=e.unit;return typeof t==`string`?t:void 0}function hr(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 gr({deviceId:e}){let t=X(),n=G(),{data:r}=j({deviceId:e},{enabled:e>0}),i=typeof r?.role==`string`?r.role:null,a=i===null?void 0:Ee[i],o=a?.kind===`numeric`,s=Te(t.trpcClient,e,i??``),c=a?.kind===`numeric`?a.canonicalUnit:void 0,l=mr(s)??c,u=l===void 0?void 0:at(l),d=U(()=>u===void 0?[]:nt(u),[u]),[f,p]=K(null),m=f??pr(r?.display),h=D({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),{data:g}=He({},{staleTime:6e4}),_=A({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}});if(r===void 0||i===null)return null;let v=e=>{p({...m,...e})},y=()=>{h.mutate({deviceId:e,display:hr(m)})},b=()=>{p(fr),h.mutate({deviceId:e,display:null})},x=()=>{let e={...m.icon===``?{}:{icon:m.icon},...m.unit===``?{}:{unit:m.unit},...m.precision.trim()!==``&&Number.isFinite(Number.parseInt(m.precision,10))?{precision:Number.parseInt(m.precision,10)}:{}},t={...g?.defaults??{},[i]:e};_.mutate({defaults:t})},S=O(i).label,C=Object.keys(P);return H(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[q(`div`,{className:`border-b border-border px-4 py-2`,children:q(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Display`})}),H(`div`,{className:`p-4 space-y-3`,children:[H(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Icon`}),H(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,value:m.icon,onChange:e=>v({icon:e.target.value}),children:[H(`option`,{value:``,children:[`Default (`,S,`)`]}),C.map(e=>q(`option`,{value:e,children:e},e))]})]}),H(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Label`}),q(`input`,{type:`text`,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,placeholder:S,value:m.label,onChange:e=>v({label:e.target.value})})]}),o&&H(`div`,{className:`grid grid-cols-2 gap-3`,children:[H(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Unit`}),H(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,value:m.unit,onChange:e=>v({unit:e.target.value}),disabled:d.length===0,children:[H(`option`,{value:``,children:[`Source`,l?` (${l})`:``]}),d.map(e=>q(`option`,{value:e,children:e},e))]})]}),H(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Precision`}),q(`input`,{type:`number`,min:0,max:10,step:1,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,placeholder:`inherit`,value:m.precision,onChange:e=>v({precision:e.target.value})})]})]}),H(`label`,{className:`flex items-center gap-2`,children:[q(`input`,{type:`checkbox`,checked:m.hidden,onChange:e=>v({hidden:e.target.checked})}),q(`span`,{className:`text-sm text-foreground`,children:`Hide from device lists`})]}),H(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[q(`button`,{type:`button`,className:`rounded bg-primary px-3 py-1 text-sm font-medium text-primary-foreground disabled:opacity-50`,onClick:y,disabled:h.isPending,children:`Save`}),q(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:b,disabled:h.isPending,children:`Reset`}),H(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:x,disabled:_.isPending,title:`Apply this unit / precision / icon as the default for every ${S} sensor`,children:[`Set as default for all `,S,` sensors`]})]})]})]})}function _r(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function vr({device:e}){let t=Dt(),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(et.Resyncable),{data:l}=T({deviceId:n??0},{enabled:n!==null&&i,refetchInterval:5e3}),u=l?.streams??{},d=Object.entries(u),f=s.includes(et.DoorbellButton),p=Pe(f?{deviceId:n??void 0,historyLimit:10}:void 0),m=p.latest?Date.now()-p.latest.timestamp<3e4:!1;return H(`div`,{className:`space-y-5`,children:[a&&n!==null&&q(Ae,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),c&&n!==null&&q(dr,{deviceId:n}),i&&n!==null&&q(te,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),f&&q(Re,{history:p.history,latestIsFresh:m}),i&&n!==null&&q(te,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),i&&d.length>0&&H(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[q(`div`,{className:`border-b border-border px-4 py-2`,children:q(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Stream Network`})}),q(`div`,{className:`divide-y divide-border`,children:d.map(([e,t])=>H(`div`,{className:`px-4 py-2.5`,children:[H(`div`,{className:`flex items-center gap-2 mb-2`,children:[q(bt,{className:`h-3 w-3 text-foreground-subtle`}),q(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),H(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[q(yr,{label:`Nominal`,value:_r(t.nominalBitrateKbps??0)}),q(yr,{label:`Observed`,value:_r(t.observedBitrateKbps??0)}),q(yr,{label:`Peak`,value:_r(t.peakBitrateKbps??0)}),q(yr,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),q(cr,{}),o&&n!==null&&q(gr,{deviceId:n})]})}function yr({label:e,value:t,warning:n}){return H(`div`,{children:[q(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),q(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}V();function br(e,t){if(t===`number`){let t=Number(e);return Number.isNaN(t)?e:t}return t===`boolean`?e===`true`:e}function xr(e,t){let n={};for(let r of e)r.key!==``&&r.value!==``&&(n[r.key]=br(r.value,t));return n}function Sr(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 Cr(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 wr(e){return e==null?`identity`:e.kind}function Tr({value:e,onChange:t,sourceField:n,targetKind:r}){let[i,a]=K(()=>wr(e)),[o,s]=K(()=>Sr(e,n)),[c,l]=K(()=>e?.kind===`enum-map`&&e.fallback!=null?String(e.fallback):``),[u,d]=K(()=>Cr(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=xr(o,r),n=c===``?void 0:br(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(Sr(void 0,n)),e===`linear`&&d(Cr(void 0))},p=(e,t,n)=>{s(r=>r.map((r,i)=>i===e?{...r,[t]:n}:r))},m=()=>s(e=>[...e,{key:``,value:``}]),h=e=>s(t=>t.filter((t,n)=>n!==e));return H(`div`,{className:`flex flex-col gap-3`,children:[H(`div`,{children:[q(`p`,{className:`text-[11px] font-medium text-foreground-subtle mb-1.5`,children:`Transform`}),q(`div`,{className:`flex items-center gap-4`,children:[`identity`,`enum-map`,`linear`].map(e=>H(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[q(`input`,{type:`radio`,name:`transform-kind`,value:e,checked:i===e,onChange:()=>f(e),className:`accent-primary`}),e===`identity`?`None`:e]},e))})]}),i===`enum-map`&&H(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[q(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Key → Value mapping`}),o.map((e,t)=>H(`div`,{className:`flex items-center gap-1.5`,children:[q(`input`,{"aria-label":`enum key ${t}`,type:`text`,value:e.key,readOnly:n?.kind===`enum`,onChange:e=>p(t,`key`,e.target.value),placeholder:`source value`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs font-mono text-foreground focus:border-primary outline-none read-only:opacity-70`}),q(`span`,{className:`text-foreground-subtle/50 text-xs`,children:`→`}),r===`boolean`?H(`select`,{"aria-label":`enum value ${t}`,value:e.value,onChange:e=>p(t,`value`,e.target.value),className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`,children:[q(`option`,{value:``,children:`—`}),q(`option`,{value:`true`,children:`true`}),q(`option`,{value:`false`,children:`false`})]}):q(`input`,{"aria-label":`enum value ${t}`,type:r===`number`?`number`:`text`,value:e.value,onChange:e=>p(t,`value`,e.target.value),placeholder:`target value`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs font-mono text-foreground focus:border-primary outline-none`}),n?.kind!==`enum`&&q(`button`,{type:`button`,onClick:()=>h(t),className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] border border-border/80 text-foreground-subtle hover:text-danger hover:border-danger/50 transition-colors`,children:`✕`})]},t)),n?.kind!==`enum`&&q(`button`,{type:`button`,onClick:m,className:`self-start text-[10px] text-primary/70 hover:text-primary transition-colors`,children:`+ Add row`}),H(`div`,{className:`flex items-center gap-2 pt-1 border-t border-border/50`,children:[q(`label`,{className:`text-[10px] text-foreground-subtle/70 whitespace-nowrap`,children:`Fallback:`}),q(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`(leave empty for none)`,className:`flex-1 rounded border border-border bg-background px-2 py-0.5 text-xs font-mono text-foreground focus:border-primary outline-none`})]})]}),i===`linear`&&H(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[q(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Linear: value × scale + offset`}),H(`div`,{className:`grid grid-cols-2 gap-2`,children:[H(`label`,{className:`flex flex-col gap-0.5`,children:[q(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Scale`}),q(`input`,{type:`number`,value:u.scale,onChange:e=>d(t=>({...t,scale:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),H(`label`,{className:`flex flex-col gap-0.5`,children:[q(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Offset`}),q(`input`,{type:`number`,value:u.offset,onChange:e=>d(t=>({...t,offset:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]})]}),H(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[q(`input`,{type:`checkbox`,checked:u.useClamp,onChange:e=>d(t=>({...t,useClamp:e.target.checked})),className:`accent-primary`}),q(`span`,{className:`text-foreground-subtle`,children:`Clamp output`})]}),u.useClamp&&H(`div`,{className:`grid grid-cols-2 gap-2`,children:[H(`label`,{className:`flex flex-col gap-0.5`,children:[q(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Min`}),q(`input`,{type:`number`,value:u.clampMin,onChange:e=>d(t=>({...t,clampMin:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),H(`label`,{className:`flex flex-col gap-0.5`,children:[q(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Max`}),q(`input`,{type:`number`,value:u.clampMax,onChange:e=>d(t=>({...t,clampMax:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]})]})]})]})}var Er=`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 Dr({mode:e,idPrefix:t,labelPrefix:n,pickerDevices:r,value:i,onChange:a,search:o,onSearchChange:s}){let{data:c}=ne({deviceId:i.sourceId??0},{enabled:i.sourceId!=null}),l=c?.caps??[],u=l.find(e=>e.cap===i.cap)?.fields??[],d=e=>{a(e,(l.find(t=>t.cap===e.cap)?.fields??[]).find(t=>t.path===e.fieldPath))},f=e=>{d({sourceId:e===``?null:Number(e),cap:``,fieldPath:``})},p=e=>{d({sourceId:i.sourceId,cap:e,fieldPath:``})},m=e=>{d({sourceId:i.sourceId,cap:i.cap,fieldPath:e})};return H(W,{children:[e===`global`&&s&&H(`div`,{children:[q(`label`,{htmlFor:`${t}-search`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Search devices`}),q(`input`,{id:`${t}-search`,type:`text`,value:o??``,placeholder:`Filter by name, stable id or #id`,onChange:e=>s(e.target.value),className:Er})]}),H(`div`,{children:[H(`label`,{htmlFor:`${t}-device`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:[n,` device`]}),H(`select`,{id:`${t}-device`,value:i.sourceId??``,onChange:e=>f(e.target.value),className:Er,children:[q(`option`,{value:``,children:`— select a device —`}),r.map(e=>H(`option`,{value:e.id,children:[e.name??e.stableId,` (#`,e.id,`)`]},e.id))]})]}),H(`div`,{children:[H(`label`,{htmlFor:`${t}-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:[n,` cap`]}),H(`select`,{id:`${t}-cap`,value:i.cap,disabled:i.sourceId==null,onChange:e=>p(e.target.value),className:Er,children:[q(`option`,{value:``,children:`— select a cap —`}),l.map(e=>q(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),H(`div`,{children:[H(`label`,{htmlFor:`${t}-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:[n,` field`]}),H(`select`,{id:`${t}-field`,value:i.fieldPath,disabled:i.cap===``,onChange:e=>m(e.target.value),className:Er,children:[q(`option`,{value:``,children:`— select a field —`}),u.map(e=>H(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]})}function Or(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 Ar(e){return e===null?``:String(e)}V();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`,Mr=`min, max, abs, round, floor, ceil, sqrt, pow, clamp, avg, sum, coalesce, age, convert`,Nr=0;function Pr(){return Nr+=1,`b${Nr}`}function Fr(e){return{key:Pr(),name:e,mode:`sibling`,sourceId:null,cap:``,fieldPath:``,search:``,literalType:`number`,literalText:``,sampleText:``}}function Ir(e,t,n){if(e===null)return[Fr(`a`)];let r=[];for(let[i,a]of Object.entries(e.bindings)){if(a.kind===`literal`){r.push({...Fr(i),mode:`literal`,literalType:kr(a.value),literalText:Ar(a.value)});continue}if(a.kind===`global`){r.push({...Fr(i),mode:`global`,sourceId:t.find(e=>e.stableId===a.sourceStableId)?.id??null,cap:a.cap,fieldPath:a.fieldPath});continue}r.push({...Fr(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:[Fr(`a`)]}function Lr(e,t,n){if(e.mode===`literal`){let t=Or(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 Rr(e){if(e.mode===`literal`)return Or(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 zr({devices:e,siblings:t,targetDeviceId:n,containerStableId:r,initial:i,onChange:a}){let[o,s]=K(i?.expr??``),[c,l]=K(()=>Ir(i,e,r)),u=U(()=>{let t={},n=c.length>0,i=new Set;for(let a of c){let o=a.name.trim();if(o===``||i.has(o)){n=!1;continue}i.add(o);let s=Lr(a,e,r);if(s===null){n=!1;continue}t[o]=s}return{source:{kind:`expression`,expr:o,bindings:t},complete:n}},[c,o,e,r]),d=U(()=>Xe({expr:u.source.expr,bindings:u.source.bindings}),[u.source]),f=U(()=>{if(o.trim()===``)return null;let e=Ye(o);return e.ok?null:e.error},[o]),p=U(()=>{if(u.source.expr.trim()===``)return null;let e={};for(let t of c){let n=t.name.trim();n!==``&&(e[n]=Rr(t))}return tt(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`:it.test(t)?Je.has(t)?`reserved`:$e.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,Fr(Br(e))])},v=e=>{l(t=>t.length<=1?t:t.filter(t=>t.key!==e))};return H(`div`,{className:`flex flex-col gap-3`,children:[H(`div`,{className:`flex flex-col gap-2`,children:[q(`span`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Bindings`}),c.map((r,i)=>q(Vr,{row:r,ordinal:i+1,devices:e,siblings:t,targetDeviceId:n,nameError:h(r),onPatch:e=>g(r.key,e),onRemove:()=>v(r.key),canRemove:c.length>1},r.key)),q(`button`,{type:`button`,onClick:_,disabled:c.length>=32,className:`self-start px-2 py-1 rounded-md text-[11px] font-medium border border-border text-foreground-subtle hover:bg-surface-hover disabled:opacity-50`,children:`+ Add binding`})]}),H(`div`,{children:[q(`label`,{htmlFor:`link-expr-input`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Expression`}),q(`textarea`,{id:`link-expr-input`,value:o,rows:2,spellCheck:!1,placeholder:`e.g. clamp(avg(a, b) + 5, 0, 100)`,onChange:e=>s(e.target.value),className:`${jr} font-mono resize-y`}),H(`p`,{className:`mt-1 text-[10px] text-foreground-subtle/60`,children:[`Functions: `,Mr]}),f&&q(`p`,{className:`mt-1 text-[10px] text-danger`,children:f}),f===null&&d&&q(`p`,{className:`mt-1 text-[10px] text-danger`,children:d})]}),H(`div`,{className:`rounded-md border border-border bg-surface/50 px-2 py-1.5`,children:[q(`span`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle/60`,children:`Preview`}),` `,p===null?q(`span`,{className:`text-[11px] text-foreground-subtle/60`,children:`enter an expression`}):p.ok?q(`span`,{className:`font-mono text-[11px] text-foreground`,children:JSON.stringify(p.value)}):q(`span`,{className:`font-mono text-[11px] text-danger`,children:p.error})]})]})}function Br(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 Vr({row:e,ordinal:t,devices:n,siblings:r,targetDeviceId:i,nameError:a,onPatch:o,onRemove:s,canRemove:c}){let l=e.search.trim().toLowerCase(),u=n.filter(e=>e.id===i?!1:l===``?!0:e.name.toLowerCase().includes(l)||e.stableId.toLowerCase().includes(l)||String(e.id).includes(l)),d=e.mode===`global`?u:r;return H(`div`,{className:`flex flex-col gap-2 rounded-md border border-border/60 p-2`,children:[H(`div`,{className:`flex items-center gap-2`,children:[q(`input`,{type:`text`,"aria-label":`binding ${t} name`,value:e.name,placeholder:`name`,onChange:e=>o({name:e.target.value}),className:`${jr} max-w-[8rem] font-mono`}),H(`select`,{"aria-label":`binding ${t} mode`,value:e.mode,onChange:e=>{let t=e.target.value;(t===`sibling`||t===`global`||t===`literal`)&&o({mode:t,sourceId:null,cap:``,fieldPath:``,search:``})},className:`${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&&H(`span`,{className:`text-[10px] text-danger`,children:[`name: `,a]}),e.mode===`literal`?H(`div`,{className:`flex items-center gap-2`,children:[H(`select`,{"aria-label":`binding ${t} literal type`,value:e.literalType,onChange:e=>{let t=e.target.value;(t===`string`||t===`number`||t===`boolean`||t===`null`)&&o({literalType:t,literalText:t===`boolean`?`true`:``})},className:`${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})]}):H(W,{children:[q(Dr,{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]`})]})]})}V();function Hr(e,t,n){return(n===void 0?[e,t]:[e,n,t]).map(e=>e.replace(/[^a-z0-9]/gi,`-`)).join(`-`)}function Ur(e,t,n){let r=`${t}-${e}`;return n.find(e=>e.stableId===r)?.id??null}function Wr(e,t){return t.find(t=>t.stableId===e)?.id??null}function Gr(e){return e==null?`sibling`:e.source.kind===`literal`?`literal`:e.source.kind===`global`?`global`:e.source.kind===`expression`?`expression`:`sibling`}function Kr(e){return e==null||e.source.kind!==`literal`?`string`:kr(e.source.value)}function qr(e){return e==null||e.source.kind!==`literal`?``:Ar(e.source.value)}function Jr({deviceId:e,parentDeviceId:t,deviceStableId:n,initial:r,onSave:i,onCancel:a}){let{data:o}=c({}),s=o??[],l=t==null?n:s.find(e=>e.id===t)?.stableId??n,u=s.filter(n=>n.parentDeviceId===t&&n.id!==e),{data:d}=ne({deviceId:e,includeSynthesizable:!0}),f=d?.caps??[],p=r!=null&&(r.source.kind===void 0||r.source.kind===`field`)?r.source:null,m=r!=null&&r.source.kind===`global`?r.source:null,h=r!=null&&r.source.kind===`expression`?r.source:null,g=p==null?m==null?null:Wr(m.sourceStableId,s):Ur(p.sourceKey,l,s),[_,v]=K(Gr(r)),[y,b]=K(r?.target.cap??``),[x,S]=K(r?.target.fieldPath??``),[C,w]=K(r?.target.itemKey??``),[T,E]=K(g),[D,O]=K((p??m)?.cap??``),[k,A]=K((p??m)?.fieldPath??``),[ee,j]=K(void 0),[te,re]=K(``),[M,N]=K(Kr(r)),[P,ie]=K(qr(r)),[ae,oe]=K(h),[se,ce]=K(r?.transform);J(()=>{if((p??m)==null||T!==null||s.length===0)return;let e=p==null?m==null?null:Wr(m.sourceStableId,s):Ur(p.sourceKey,l,s);e!==null&&E(e)},[p,m,T,s,l]);let le=f.find(e=>e.cap===y)?.fields??[],ue=le.find(e=>e.path===x),de=ue?.item===!0,F=te.trim().toLowerCase(),fe=s.filter(t=>t.id===e?!1:F===``?!0:t.name.toLowerCase().includes(F)||t.stableId.toLowerCase().includes(F)||String(t.id).includes(F)),pe=_===`global`?fe:u,me=e=>{b(e),S(``),w(``)},he=e=>{e!==`sibling`&&e!==`global`&&e!==`literal`&&e!==`expression`||(v(e),E(null),O(``),A(``),j(void 0),re(``))},ge=Or(M,P),I=_===`literal`?ge!==null:_===`expression`?ae!==null:T!=null&&D!==``&&k!==``,_e=y!==``&&x!==``&&(!de||C.trim()!==``)&&I,ve=()=>{if(_===`literal`)return ge===null?null:{kind:`literal`,value:ge.value};if(_===`expression`)return ae;let e=s.find(e=>e.id===T);if(!e||D===``||k===``)return null;if(_===`global`)return{kind:`global`,sourceStableId:e.stableId,cap:D,fieldPath:k};let t=`${l}-`;return{sourceKey:e.stableId.startsWith(t)?e.stableId.slice(t.length):``,cap:D,fieldPath:k}},ye=()=>{if(!_e)return;let e=ve();if(e===null)return;let t=de?C.trim():void 0;i({id:r?.id??Hr(y,x,t),source:e,target:{cap:y,fieldPath:x,...t===void 0?{}:{itemKey:t}},...se==null?{}:{transform:se}})},L=`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none disabled:opacity-50`;return H(`div`,{className:`flex flex-col gap-4 p-3`,children:[H(`fieldset`,{className:`flex flex-col gap-3`,children:[q(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Target (this device)`}),H(`div`,{children:[q(`label`,{htmlFor:`link-target-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target cap`}),H(`select`,{id:`link-target-cap`,value:y,onChange:e=>me(e.target.value),className:L,children:[q(`option`,{value:``,children:`— select a cap —`}),f.map(e=>q(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),H(`div`,{children:[q(`label`,{htmlFor:`link-target-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target field`}),H(`select`,{id:`link-target-field`,value:x,disabled:y===``,onChange:e=>S(e.target.value),className:L,children:[q(`option`,{value:``,children:`— select a field —`}),le.map(e=>q(`option`,{value:e.path,children:e.item===!0?`${e.path} (per item, ${e.kind})`:`${e.path} (${e.kind})`},e.path))]})]}),de&&H(`div`,{children:[q(`label`,{htmlFor:`link-target-item-key`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Item key`}),q(`input`,{id:`link-target-item-key`,type:`text`,value:C,placeholder:`e.g. main-brush`,onChange:e=>w(e.target.value),className:L}),q(`p`,{className:`mt-1 text-[10px] text-foreground-subtle/60`,children:`Links sharing the same item key build one item (e.g. one consumable).`})]})]}),H(`fieldset`,{className:`flex flex-col gap-3`,children:[q(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Source`}),H(`div`,{children:[q(`label`,{htmlFor:`link-source-mode`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source mode`}),H(`select`,{id:`link-source-mode`,value:_,onChange:e=>he(e.target.value),className:L,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`&&H(W,{children:[H(`div`,{children:[q(`label`,{htmlFor:`link-literal-type`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Literal type`}),H(`select`,{id:`link-literal-type`,value:M,onChange:e=>{let t=e.target.value;(t===`string`||t===`number`||t===`boolean`||t===`null`)&&(N(t),t===`boolean`&&ie(`true`),t===`null`&&ie(``))},className:L,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`})]})]}),M!==`null`&&(M===`boolean`?H(`div`,{children:[q(`label`,{htmlFor:`link-literal-value`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Literal value`}),H(`select`,{id:`link-literal-value`,value:P,onChange:e=>ie(e.target.value),className:L,children:[q(`option`,{value:`true`,children:`true`}),q(`option`,{value:`false`,children:`false`})]})]}):H(`div`,{children:[q(`label`,{htmlFor:`link-literal-value`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Literal value`}),q(`input`,{id:`link-literal-value`,type:`text`,value:P,placeholder:M===`number`?`e.g. 42`:`e.g. main-brush`,onChange:e=>ie(e.target.value),className:L})]}))]}),_===`expression`&&q(zr,{devices:s,siblings:u,targetDeviceId:e,containerStableId:l,initial:h,onChange:oe}),(_===`sibling`||_===`global`)&&q(Dr,{mode:_,idPrefix:`link-source`,labelPrefix:`Source`,pickerDevices:pe,value:{sourceId:T,cap:D,fieldPath:k},onChange:(e,t)=>{E(e.sourceId),O(e.cap),A(e.fieldPath),j(t)},search:te,onSearchChange:re})]}),q(Tr,{value:se,onChange:ce,sourceField:_===`literal`||_===`expression`?void 0:ee,targetKind:ue?.kind}),H(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-border`,children:[q(`button`,{type:`button`,onClick:a,className:`px-3 py-1.5 rounded-md text-xs font-medium border border-border text-foreground-subtle hover:bg-surface-hover hover:text-foreground transition-colors`,children:`Cancel`}),q(`button`,{type:`button`,disabled:!_e,onClick:ye,className:`px-3 py-1.5 rounded-md text-xs font-medium bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:`Save`})]})]})}V();function Yr({deviceId:e}){let t=X(),n=G(),r=Number.isFinite(e),{data:i,isLoading:a}=j({deviceId:e},{enabled:r,refetchInterval:1e4}),{data:o}=ne({deviceId:e,includeSynthesizable:!0},{enabled:r}),s=new Map;for(let e of o?.caps??[])e.itemArray&&s.set(e.cap,e.itemArray);let c=x({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),l=i?.deviceLinks??[],u=typeof i?.parentDeviceId==`number`?i.parentDeviceId:null,d=typeof i?.stableId==`string`?i.stableId:``,[f,p]=K(null),m=t=>{c.mutate({deviceId:e,deviceLinks:l.filter(e=>e.id!==t)})};return a?q(`div`,{className:`p-4`,children:q(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})}):f===null?H(`div`,{className:`flex flex-col gap-3 p-1`,children:[H(`div`,{className:`flex items-center justify-between`,children:[q(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Wiring`}),H(`button`,{type:`button`,onClick:()=>p(`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(gt,{className:`h-3 w-3`}),`Add link`]})]}),l.length===0?H(`div`,{className:`flex flex-col items-center justify-center gap-2 py-8 text-foreground-subtle`,children:[q(Zt,{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:l.map(n=>q(Zr,{deviceId:e,link:n,itemArray:s.get(n.target.cap),trpcClient:t.trpcClient,onDelete:()=>m(n.id),onEdit:()=>p(n),isPending:c.isPending},n.id))})]}):H(`div`,{className:`flex flex-col gap-3 p-1`,children:[q(`div`,{className:`flex items-center justify-between`,children:q(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:f===`new`?`Add link`:`Edit link`})}),q(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:q(Jr,{deviceId:e,parentDeviceId:u,deviceStableId:d,initial:f===`new`?null:f,onSave:t=>{let n=l.some(e=>e.id===t.id)?l.map(e=>e.id===t.id?t:e):[...l,t];c.mutate({deviceId:e,deviceLinks:n}),p(null)},onCancel:()=>{p(null)}})})]})}function Xr(e,t,n,r){let i=rt(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:rt(a,r)}function Zr({deviceId:e,link:t,itemArray:n,trpcClient:r,onDelete:i,onEdit:a,isPending:o}){let s=Te(r,e,t.target.cap),c=t.target.itemKey,l=s===void 0?void 0:c!==void 0&&n!==void 0?Xr(s,n,c,t.target.fieldPath):c===void 0?rt(s,t.target.fieldPath):void 0,u=l==null?`—`:String(l);return H(`div`,{className:`flex items-center gap-3 px-3 py-2.5 bg-surface hover:bg-surface-hover transition-colors`,children:[q(Qt,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle/40`}),H(`div`,{className:`min-w-0 flex-1 flex flex-col gap-0.5`,children:[H(`div`,{className:`flex items-baseline gap-1 flex-wrap`,children:[q(`span`,{className:`font-mono text-[11px] font-medium text-foreground`,children:t.target.cap}),q(`span`,{className:`text-[10px] text-foreground-subtle/60`,children:`.`}),q(`span`,{className:`font-mono text-[11px] text-foreground-subtle`,children:t.target.fieldPath}),c!==void 0&&q(`span`,{className:`rounded bg-surface-hover px-1 py-px font-mono text-[9px] text-foreground-subtle`,title:`Item key — links sharing it build one array item`,children:c})]}),H(`div`,{className:`flex items-baseline gap-1 flex-wrap text-[10px] text-foreground-subtle/70`,children:[q(`span`,{children:`←`}),t.source.kind===`literal`?H(`span`,{className:`font-mono`,children:[`literal: `,String(t.source.value)]}):t.source.kind===`expression`?H(W,{children:[H(`span`,{className:`font-mono`,title:t.source.expr,children:[`ƒ`,` `,t.source.expr.length>40?`${t.source.expr.slice(0,40)}…`:t.source.expr]}),H(`span`,{className:`rounded bg-surface-hover px-1 py-px font-mono text-[9px] text-foreground-subtle`,title:`Number of source bindings`,children:[Object.keys(t.source.bindings).length,` bindings`]})]}):H(W,{children:[q(`span`,{className:`font-mono`,children:t.source.kind===`global`?t.source.sourceStableId:t.source.sourceKey}),q(`span`,{className:`opacity-60`,children:`/`}),q(`span`,{className:`font-mono`,children:t.source.cap}),q(`span`,{className:`opacity-60`,children:`.`}),q(`span`,{className:`font-mono`,children:t.source.fieldPath})]})]})]}),t.transform&&q(Qr,{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 Qr({kind:e}){return q(`span`,{className:`inline-flex items-center rounded-md border border-primary/20 bg-primary/5 px-1.5 py-0.5 font-mono text-[10px] text-primary/80 shrink-0`,children:e})}V();var $r=[{id:`overview`,label:`Overview`,cameraOnly:!1},{id:`config`,label:`Config`,cameraOnly:!1},{id:`pipeline`,label:`Pipeline steps`,cameraOnly:!0},{id:`bindings`,label:`Bindings`,cameraOnly:!0},{id:`wiring`,label:`Wiring`,cameraOnly:!1}];function ei(e){let t=e===Y.Camera;return $r.filter(e=>t||!e.cameraOnly).map(({id:e,label:t})=>({id:e,label:t}))}var ti=[{id:`logs`,icon:Ft,label:`Logs`},{id:`repl`,icon:Mt,label:`REPL`},{id:`events`,icon:Et,label:`Events`},{id:`state`,icon:Tt,label:`State`}];function ni(){let e=kt(),t=Number(e.deviceId),n=Number.isFinite(t),r=Dt(),o=G(),c=ie(),l=X(),[u,d]=Ct(),f=u.get(`tab`)??`overview`,h=u.get(`sub`),[_,v]=K(`logs`),y=`device-detail.left-col-width-px`,[b,x]=K(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(y),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),S=B(b);S.current=b;function C(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??b??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{x(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=S.current;if(e!==null)try{window.localStorage.setItem(y,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:w,isLoading:T,isError:E}=j({deviceId:t},{enabled:n,refetchInterval:5e3,retry:1}),{data:D}=i({deviceId:t},{enabled:n}),O=U(()=>{let e=D?.settings?.sections??[],t=D?.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(Ln)&&r.add(Pn),[...r].map(e=>e===`export`?{id:e,label:Fn,isAddonContrib:!0}:{id:e,label:Ze[e]?.label??e,isAddonContrib:!0})},[D]),k=w,A=String(k?.name??e.deviceId??`Device`),te=k?.online===!0,re=te?`online`:`offline`,M=String(k?.addonId??`rtsp`),N=k?.features??[],P=k?.type,ae=P===Y.Camera,{data:oe}=Vt(n?t:0),se=P===Y.Container,ue=U(()=>(oe??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[oe]),F=U(()=>se?pe(ue,typeof k?.linkDeviceId==`number`?k.linkDeviceId:null,typeof k?.primaryChildEntityId==`string`?k.primaryChildEntityId:null)?.id??null:null,[se,ue,k?.linkDeviceId,k?.primaryChildEntityId]),{data:fe}=i({deviceId:F??0},{enabled:F!==null}),me=U(()=>{if(F===null)return[];let e=fe?.settings?.sections??[],t=fe?.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:Ze[e]?.label??e,isAddonContrib:!0,childDeviceId:F}))},[F,fe]),he=typeof k?.parentDeviceId==`number`?k.parentDeviceId:null,{data:ge}=j({deviceId:he??0},{enabled:he!==null}),I=we(),ve=k?.disabled!==!0,{data:xe}=ne({deviceId:t},{enabled:n}),Ce=(xe?.caps.length??0)>0,Te=U(()=>{let e=new Set,t=[];for(let n of[...ei(P),...O,...me])e.has(n.id)||(e.add(n.id),!(n.id===`wiring`&&!Ce)&&t.push(n));return t},[P,O,me,Ce]),Ee=U(()=>Te.some(e=>e.id===f)?f:`overview`,[Te,f]),Oe=z(e=>{d(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[d]),ke=z(e=>{d(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[d]),Ae=(oe??[]).length>0,je=U(()=>ti.filter(({featureGate:e})=>!e||N.includes(e)),[N]),{data:R}=ye({addonId:M},{enabled:!!M&&M!==`rtsp`}),Ne=be({onSuccess:()=>{o.invalidateQueries({queryKey:[[`deviceManager`]]}),r(R?.id?`/integrations/${R.id}`:`/integrations`)}}),Pe=Ve({onSuccess:()=>{o.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=Me({onSuccess:()=>{o.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ie=ee(),Le=le({onSuccess:()=>{o.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Re=N.includes(et.Rebootable),ze=N.includes(et.BatteryOperated),Be=m(l.trpcClient,ze&&n?t:null),[He,Ue]=K(!1),We=ot(l.trpcClient,n?t:null),Ge=async()=>{if(!(He||!We)){Ue(!0);try{await We.snapshot?.invalidateCache({});let e=await We.snapshot?.getSnapshot({});if(!e)return;let t=`data:${e.contentType};base64,${e.base64}`,n=e.contentType.includes(`png`)?`png`:`jpg`,r=A.replace(/[^a-zA-Z0-9_.-]+/g,`_`),i=new Date().toISOString().replace(/[:.]/g,`-`),a=document.createElement(`a`);a.href=t,a.download=`${r}-${i}.${n}`,document.body.appendChild(a),a.click(),document.body.removeChild(a)}finally{Ue(!1)}}},Ke=Pe.isPending||Fe.isPending,{data:V}=_e({deviceId:t},{enabled:n,refetchInterval:1e4}),W=V?.agentNodeId??null,qe=typeof W==`string`&&W.length>0&&!W.startsWith(`addon:`)?W:void 0,{data:J}=ce({deviceId:t,...qe?{nodeId:qe}:{}},{enabled:n,refetchInterval:3e3,retry:!1}),{data:Je}=p({deviceId:t},{enabled:n,refetchInterval:3e3,retry:!1}),Ye=Je?.level?.dbfs??null;function Xe(){if(!n)return null;switch(Ee){case`overview`:return q(vr,{device:k??{}});case`config`:return q(Zn,{deviceId:t,activeSubTab:h,onSubTabChange:ke});case`pipeline`:return q(tr,{deviceId:t,refreshToken:0});case`bindings`:return q(On,{deviceId:t});case`wiring`:return q(Yr,{deviceId:t});default:{let e=Ee,n=O.some(t=>t.id===e),r=me.find(t=>t.id===e);if(!n&&r===void 0)return null;let i=r?.childDeviceId??t;if(e===`export`)return q(Xn,{deviceId:t,sectionFilter:Ln,activeSubTab:h,onSubTabChange:ke});let a=q(Xn,{deviceId:i,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:h,onSubTabChange:ke});return r!==void 0&&i!==t?q(L,{deviceId:i,children:a}):a}}}return n?T?H(`div`,{className:`flex flex-col h-full`,children:[H(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[q(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),q(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),q(`div`,{className:`flex-1 p-6`,children:q(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):E||!w?H(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[q(`p`,{className:`text-lg font-semibold text-foreground`,children:`Device not found`}),H(`p`,{className:`text-xs`,children:[`No device with ID`,` `,H(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,t]})]}),q(`button`,{onClick:()=>r(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]}):H(`div`,{className:`absolute inset-0 flex flex-col overflow-hidden`,children:[H(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[q(`div`,{className:`mb-2`,children:q(de,{items:[{label:`Integrations`,onClick:()=>r(`/integrations`)},{label:R?.name??M,onClick:()=>R?.id&&r(`/integrations/${R.id}`)},{label:A}]})}),H(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[q(mt,{type:M,size:`lg`}),H(`div`,{className:`min-w-0 flex-1`,children:[H(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[q(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:A}),q(Ut,{status:re}),ze&&q(g,{status:Be,variant:`full`})]}),he!==null&&ge&&H(`button`,{type:`button`,onClick:()=>r(`/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:N.length>0&&q(dt,{capabilities:N})})]}),J&&q(`div`,{className:`hidden lg:flex`,children:q(ri,{metrics:J,dbfs:Ye})}),H(`div`,{className:`flex items-center gap-1 shrink-0`,children:[H(`button`,{onClick:async()=>{ve?await c({title:`Disable "${A}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&Fe.mutate({deviceId:t}):Pe.mutate({deviceId:t})},disabled:Ke,title:ve?`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 ${ve?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[q(tn,{className:`h-3.5 w-3.5`}),q(`span`,{className:`hidden sm:inline`,children:Ke?`Updating…`:ve?`Enabled`:`Disabled`})]}),q(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),q(Se,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:wt,disabled:He,onClick:()=>{Ge()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:vt,hidden:!Re,disabled:Ie.isPending,danger:!0,onClick:async()=>{await c({title:`Reboot "${A}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&Ie.mutate({deviceId:t})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${R?.name??M}.`,icon:_t,disabled:Le.isPending,danger:!0,onClick:async()=>{await c({title:`Restart "${R?.name??M}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${A}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&Le.mutate({addonId:M})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:Lt,separatorBefore:!0,disabled:Ne.isPending,danger:!0,onClick:async()=>{await c({title:`Delete "${A}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&Ne.mutate({deviceId:t})}}]})]})]})]}),q(L,{deviceId:t,device:k??void 0,children:q(a,{children:q(s,{children:q(lt,{children:q(De,{children:H(`main`,{className:I?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[H(`div`,{className:I?`flex flex-col bg-surface`:`${b===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!I&&b!==null?{width:`${String(b)}px`}:void 0,children:[q(`div`,{className:ae?`flex-shrink-0 border-b border-border-subtle bg-black`:I?`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:ae?q(Cn,{deviceId:t,intercomAvailable:N.includes(et.TwoWayAudio)}):q(mn,{deviceId:t,deviceName:A,deviceType:P??`unknown`,provider:M,isOnline:te,features:N})}),H(`div`,{className:I?`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:je.map(({id:e,label:t,icon:n})=>H(`button`,{onClick:()=>v(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${_===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[q(n,{className:`h-3 w-3`}),t]},e))})}),H(`div`,{className:I?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[_===`logs`&&q(wn,{deviceId:t,containerDeviceId:P===`container`?t:void 0}),_===`repl`&&q(Tn,{deviceId:t}),_===`events`&&q(En,{deviceId:t}),_===`state`&&q(Dn,{deviceId:t})]})]})]}),!I&&q(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:C,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:q(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),H(`div`,{className:I?`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-wrap items-center gap-0`,children:Te.map(e=>{let t=Ee===e.id;return H(`button`,{onClick:()=>Oe(e.id),className:`relative flex-shrink-0 px-3 py-2 text-xs font-medium transition-colors ${t?`text-primary`:`text-foreground-subtle hover:text-foreground`}`,children:[e.label,t&&q(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),H(`div`,{className:I?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[Ee===`overview`&&Ae&&q(rn,{parentDeviceId:t}),Xe()]})]})]})})})})})})]}):H(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[q(`p`,{className:`text-lg font-semibold text-foreground`,children:`Invalid device id`}),H(`p`,{className:`text-xs`,children:[`The URL segment`,` `,q(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:e.deviceId}),` `,`is not a number.`]}),q(`button`,{onClick:()=>r(`/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 ri({metrics:e,dbfs:t}){let n=E(e.phase??`idle`);return H(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[H(`div`,{className:`flex items-center gap-1.5`,children:[q(`span`,{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),q(`span`,{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),q(`div`,{className:`h-3 w-px bg-border`}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[q(xt,{className:`h-3 w-3`}),q(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),q(`span`,{children:`fps`})]}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[q(Pt,{className:`h-3 w-3`}),q(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),q(`span`,{children:`ms`})]}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:`Current audio level (dBFS)`,children:[q(nn,{className:`h-3 w-3`}),q(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),q(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&H(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{ni as DeviceDetailPage};
@@ -1 +0,0 @@
1
- import{Bi as e,Fi as t,Gi as n,Hi as r,Ii as i,Ki as a,Li as o,Mi as s,Ni as c,Pi as l,Ri as u,Ui as d,Vi as f,Wi as p,Xi as m,c as h,ht as g,ka as _,mt as v,s as y,ua as b,zi as x}from"./src-9Nw_7MUt.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-6ez5bWMa.js";import{t as A}from"./copy-BwY737s-.js";import{t as j}from"./key-round-CRs7h4JP.js";import{t as M}from"./AddonCollectionPage-BkUO0Tru.js";import{t as ee}from"./plus-CekuJPnw.js";import{C as N,F as P,V as F,d as I,i as L,l as R,r as z,s as B,w as V,x as H}from"./index-Da6GKRLl.js";import{t as U}from"./AdminPage-BwmGKnRf.js";import{t as W}from"./AdminTabs-mgvEpBDZ.js";var G=F(`book-open`,[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z`,key:`ruj8y`}]]),K=F(`key-square`,[[`path`,{d:`M12.4 2.7a2.5 2.5 0 0 1 3.4 0l5.5 5.5a2.5 2.5 0 0 1 0 3.4l-3.7 3.7a2.5 2.5 0 0 1-3.4 0L8.7 9.8a2.5 2.5 0 0 1 0-3.4z`,key:`165ttr`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`m9.4 10.6-6.814 6.814A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814`,key:`1ubxi2`}]]),te=F(`key`,[[`path`,{d:`m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4`,key:`g0fldk`}],[`path`,{d:`m21 2-9.6 9.6`,key:`1j0ho8`}],[`circle`,{cx:`7.5`,cy:`15.5`,r:`5.5`,key:`yqb3hr`}]]),q=F(`link`,[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]),ne=F(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]);S();function re({userId:e,username:n,onClose:r}){let a=E(),o=m(),s=i({userId:e}),c=s.data,l=()=>a.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),u=t({onSuccess:()=>{l(),r()}}),d=s.isLoading?`loading`:c?.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(R,{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:n})]})]})]}),O(`button`,{onClick:r,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:O(L,{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(H,{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(N,{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`&&c&&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`,` `,c.confirmedAt?new Date(c.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(_,{onClick:r,variant:`secondary`,children:`Close`}),C(`button`,{onClick:async()=>{await o({title:`Remove 2FA`,message:`Remove two-factor authentication for "${n}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,confirmLabel:`Remove`,variant:`danger`})&&u.mutate({userId:e})},disabled:u.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:[u.isPending?O(H,{className:`h-3 w-3 animate-spin`}):O(L,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function J(){let t=E(),{user:r}=z(),[i,o]=D(!1),[s,u]=D(``),[d,p]=D(``),[h,g]=D(!1),[_,v]=D(null),{data:y,isLoading:x,isError:S}=e(),w=m(),T=()=>t.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),k=c({onSuccess:()=>{T(),o(!1),u(``),p(``),g(!1),v(null)},onError:e=>{v(e instanceof Error?e.message:`Failed to create user`)}}),A=l({onSuccess:T}),j=a({onSuccess:T}),M=f({onSuccess:T}),N=n({onSuccess:()=>{T(),F(null)}}),[P,F]=D(null),[V,W]=D(null),G=y??[];async function K(e){await w({title:`Delete user`,message:`Permanently delete user "${e.username}"? This cannot be undone — any active sessions will be revoked on next request.`,confirmLabel:`Delete`,variant:`danger`})&&A.mutate({id:e.id})}async function q(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 ne(e,t){t!==e.isAdmin&&j.mutate({id:e.id,isAdmin:t})}function J(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:()=>o(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm hover:bg-primary/90`,children:[O(ee,{className:`h-3.5 w-3.5`}),`Create User`]})}),i&&C(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[C(`div`,{className:`flex items-center justify-between`,children:[O(`span`,{className:`text-xs font-medium text-foreground`,children:`New User`}),O(`button`,{onClick:()=>o(!1),className:`text-foreground-subtle hover:text-foreground`,children:O(L,{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:s,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=>p(e.target.value),placeholder:`••••••••`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),C(`label`,{className:`flex items-center gap-2 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground cursor-pointer`,children:[O(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked),className:`rounded border-border focus:ring-primary`}),O(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),_&&O(`p`,{className:`text-[10px] text-danger`,children:_}),C(`div`,{className:`flex justify-end gap-2`,children:[O(`button`,{onClick:()=>o(!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:s,password:d,isAdmin:h}),disabled:k.isPending||!s||!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(b,{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=>ne(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:()=>F(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(I,{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:J(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:t=>{let n=e(t);return C(`div`,{className:`flex items-center justify-end gap-1`,children:[t.id!==r?.id&&t.totpEnabled&&C(`button`,{onClick:()=>W(t),disabled:n,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(R,{className:`h-3 w-3`}),`Remove 2FA`]}),C(`button`,{onClick:()=>q(t),disabled:n,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(te,{className:`h-3 w-3`}),`Reset password`]}),C(`button`,{onClick:()=>K(t),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:`Delete user`,children:[n?O(H,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:G,rowKey:e=>e.id,minWidthPx:560})})(),V&&O(re,{userId:V.id,username:V.username,onClose:()=>W(null)}),P&&O(ie,{user:P,onClose:()=>F(null),onSubmit:e=>N.mutate({userId:P.id,scopes:e}),submitting:N.isPending})]})}function ie(e){let{user:t}=z(),n=t?.isAdmin===!0;return O(ae,{...e,callerScopes:n?null:t?.scopes??[]})}function ae({user:e,onClose:t,onSubmit:n,submitting:r,callerScopes:i}){let[a,o]=D(w(()=>(e.scopes??[]).map(e=>({...e,access:[...e.access]})),[e.scopes])),s=h(a);return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4`,children:C(`div`,{className:`w-full max-w-2xl rounded-lg border border-border bg-surface shadow-xl`,children:[C(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-3`,children:[C(`div`,{children:[C(`div`,{className:`text-sm font-semibold text-foreground`,children:[`Edit scopes — `,e.username]}),O(`div`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?`Admin users bypass the scope check; this list is ignored.`:`Pick which capabilities this user can call, and which access flavours within each.`})]}),O(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:O(L,{className:`h-4 w-4`})})]}),C(`div`,{className:`px-4 py-4`,children:[O(y,{value:a,onChange:o,clampToParent:i,emptyHint:C(T,{children:[`No scopes granted.`,` `,O(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until a scope is added.`]})}),s&&O(`p`,{className:`mt-2 text-[10px] text-danger`,children:s})]}),C(`div`,{className:`flex items-center justify-end gap-2 border-t border-border px-4 py-3`,children:[O(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),O(`button`,{onClick:()=>n(a),disabled:r||s!==null,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:r?O(H,{className:`h-3 w-3 animate-spin`}):`Save scopes`})]})]})})}S();var oe=`bg-primary/10 text-primary`,se=`bg-foreground-subtle/10 text-foreground-subtle`;function Y(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function ce(e){return e?e===`*`?`*`:e.join(`, `):``}function le(){let t=E(),n=m(),{data:i,isLoading:a}=o(),{data:c}=e(),l=w(()=>i??[],[i]),u=w(()=>c??[],[c]),d=()=>t.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),f=()=>t.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[h,g]=D(!1),[_,v]=D(null),y=r({onSuccess:d}),b=s({onSuccess:({token:e,record:t})=>{f(),g(!1),v({token:e,label:t.name})}}),x=p({onSuccess:f}),S=async(e,t)=>{await n({title:`Revoke "${t}"?`,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,t)=>{await n({title:`Revoke "${t}"?`,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:()=>g(!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:u.length===0,title:u.length===0?`Create a user first`:`Issue a scoped token`,children:[O(I,{className:`h-3.5 w-3.5`}),`New token`]})]}),C(X,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[u.length===0&&O(de,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),u.map(e=>O(fe,{userId:e.id,username:e.username,onRevoke:(e,t)=>{T(e,t)},revokePending:x.isPending,revokeId:x.variables?.id},e.id))]}),l.length>0&&O(X,{title:`Legacy API keys`,subtitle:`${l.length} pre-existing — revoke only`,children:O(Z,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:l.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?oe:se}`,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:ce(e.allowedProviders)||`all`}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:Y(e.createdAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:Y(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(H,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),a&&O(ue,{}),h&&O(pe,{users:u.map(e=>({id:e.id,username:e.username})),onClose:()=>g(!1),onSubmit:e=>b.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:b.isPending}),_&&O(me,{token:_.token,label:_.label,onClose:()=>v(null)})]})}function X({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 ue(){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 de({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 Z({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 fe({userId:e,username:t,onRevoke:n,revokePending:r,revokeId:i}){let{data:a,isLoading:o}=x({userId:e}),s=a??[];return o||s.length===0?null:C(`div`,{className:`space-y-1.5`,children:[O(`div`,{className:`text-[11px] font-medium text-foreground`,children:t}),O(Z,{headers:[`Name`,`Prefix`,`Scopes`,`Expires`,`Last used`,`Created`,``],rows:s.map(e=>{let t=r&&i===e.id;return C(`tr`,{className:`hover:bg-primary/5`,children:[O(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.name}),C(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:O(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>C(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:[e.type,`:`,e.type===`device`?`[${e.targets.join(`,`)}]`:e.target]},t))})}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:Y(e.expiresAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:Y(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:Y(e.createdAt)}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:C(`button`,{onClick:()=>n(e.id,e.name),disabled:t,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[t?O(H,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function pe({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`]}]),[f,p]=D(``),m=h(u),g=o!==``&&c.trim().length>0&&u.length>0&&m===null&&!r;return C(he,{title:`Create scoped token`,onClose:t,children:[C(`div`,{className:`space-y-3`,children:[O(Q,{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(Q,{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(Q,{label:`Scopes`,hint:`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`,children:[O(y,{value:u,onChange:d,clampToParent:a}),m&&O(`p`,{className:`mt-1 text-[10px] text-danger`,children:m})]}),O(Q,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:O(`input`,{type:`number`,min:1,value:f,onChange:e=>p(e.target.value),placeholder:`30`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})})]}),C(ge,{children:[O(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),C(`button`,{onClick:()=>{let e=parseInt(f,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;n({userId:o,name:c.trim(),scopes:u,expiresAt:t})},disabled:!g,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[r?O(H,{className:`h-3.5 w-3.5 animate-spin`}):O(I,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function me({token:e,label:t,onClose:n}){let[r,i]=D(!1),a=async()=>{try{await navigator.clipboard.writeText(e),i(!0)}catch{}};return C(he,{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(ge,{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(P,{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 he({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(L,{className:`h-4 w-4`})})]}),O(`div`,{className:`p-4`,children:n})]})})}function ge({children:e}){return O(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:e})}function Q({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 $(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function _e(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 ve(){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 ye({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 be({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 xe(){let e=E(),t=m(),{data:n,isLoading:r}=u(),i=w(()=>n??[],[n]),a=d({onSuccess:()=>e.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),o=async(e,n)=>{await t({title:`Revoke "${n}" session?`,message:`This integration will lose access immediately on its next API call. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&a.mutate({id:e})};return C(U,{icon:q,title:`Linked Sessions`,subtitle:`External integrations (Alexa, …) linked to this hub via OAuth. Revoke a session to immediately invalidate that integration's access.`,children:[r&&O(ve,{}),!r&&i.length===0&&O(ye,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!r&&i.length>0&&O(be,{headers:[`Integration`,`User`,`Scopes`,`Created`,`Last used`,`Status`,``],rows:i.map(e=>{let t=e.revokedAt!==null,n=(a.isPending?a.variables?.id:void 0)===e.id;return C(`tr`,{className:`hover:bg-primary/5`,children:[O(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.integrationId}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:e.username}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:O(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>O(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:_e(e)},t))})}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:$(e.createdAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:$(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 `,$(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:()=>{o(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(H,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}S();var Se=3e4;function Ce(e){let t=new Map;for(let n of e){let e=n?.manifest;e?.id&&t.set(e.id,e.packageDisplayName??e.name??e.id)}return t}function we(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 can be enrolled per-user from the Users page (added in v0.4).`,`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:V,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:V,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:R,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:R,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:I,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Te(){let e=g({capName:`auth-provider`},{refetchInterval:Se}),t=v(void 0,{refetchInterval:Se}),n=w(()=>Ce(t.data??[]),[t.data]);return O(M,{title:`Authentication`,subtitle:`Identity providers exposed to the admin UI. Multiple providers can run in parallel — operators pick which to enable. Disabling a provider only removes that external login method; local password login is unaffected. Each provider’s settings + live logs are inline below.`,pageIcon:I,itemIcon:I,capability:`auth-provider`,installButtonLabel:`Add provider`,items:w(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,n]),isLoading:e.isLoading,emptyTitle:`No 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.`,renderExpandedPanel:e=>O(Ee,{addonId:e.addonId})})}function Ee({addonId:e}){let t=we(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(G,{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(N,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),C(`span`,{children:[`TOTP / 2FA settings are exposed per-user from the`,` `,O(`a`,{href:`/system/users`,className:`underline text-primary`,children:`Users`}),` `,`page (added in v0.4). Enable for each user via the Actions column → “Enable TOTP”.`]})]})]})}function De(){return O(`div`,{className:`flex flex-col p-4`,children:O(W,{tabs:[{id:`users`,label:`Users`,icon:ne,content:O(J,{})},{id:`api-keys`,label:`Tokens`,icon:j,content:O(le,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:q,content:O(xe,{})},{id:`authentication`,label:`Authentication`,icon:I,content:O(Te,{})}]})})}export{De as IdentityPage};
@@ -1 +0,0 @@
1
- import{$ as e,Bn as t,En as n,H as r,Ta as i,V as a,Z as o,_n as s,ar as c,bt as l,cn as u,d,da as f,fn as p,g as ee,it as m,jn as te,kn as h,ln as g,lr as _,nr as v,pn as y,rr as b,sn as x,sr as S,tr as C,un as w,vn as ne,x as T,xn as E}from"./src-9Nw_7MUt.js";import{I as D,K as re,Q as O,S as k,W as A,b as j,o as M,q as N,x as P,z as ie}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 F}from"./src-DYcadIAu.js";import{p as I}from"./player-overlays-CqpHdvYF.js";import{t as L}from"./ProviderIcon-AXlCHsTd.js";import{t as R}from"./plus-CekuJPnw.js";import{n as z,r as B,t as ae}from"./ScanNetworkModal-tDFKEL2L.js";import{t as oe}from"./refresh-cw-DH7JcsAT.js";import{t as V}from"./rotate-cw-CTrqUHcp.js";import{t as se}from"./wifi-G6nDQGOi.js";import{E as H,F as U,G as ce,M as W,P as G,T as le,U as ue,V as de,W as fe,f as pe,i as me,o as K,p as he,s as ge,t as _e,x as q,z as ve}from"./index-Da6GKRLl.js";import{t as J}from"./FormBuilder-CL6dlXwQ.js";var ye=de(`search-x`,[[`path`,{d:`m13.5 8.5-5 5`,key:`1cs55j`}],[`path`,{d:`m8.5 8.5 5 5`,key:`a8mexj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]);O();function be(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...be(n.fields));return t}function xe(e,t,n){let[r,i]=N(`idle`),[a,o]=N({}),s=A(()=>{let t=[];for(let n of e.sections)t.push(...be(n.fields));return t},[e]),c=s.length>0&&n!==void 0,l=D(e=>{o(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:r,hasProbeFields:c,probeResults:a,handleTestAll:D(async()=>{if(!n)return;let e=s.filter(e=>{let n=t[e];return n!=null&&String(n).trim()!==``});if(e.length===0)return;i(`testing`);let r={};for(let t of e)r[t]={status:`probing`};o(r);let a=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await n(e,t[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),c={};for(let e of a)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;c[t]={status:n.status===`ok`?`ok`:`error`,result:n}}o(c),i(`idle`)},[n,s,t]),clearProbeResult:l}}O();function Se(e){let t=[];for(let n of e)`required`in n&&n.required===!0&&`key`in n&&n.key&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Se(n.fields));return t}function Ce(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Y(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Y(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function X(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function we({open:e,integrationId:n,addonId:r,onClose:i}){let{t:a}=_e(),o=M(),[s,c]=N({}),[l,u]=N(!1),[d,f]=N(null),[m,te]=N(X),g=h({addonId:r},{enabled:e}),_=g.data?.deviceType??null,v=E({addonId:r,type:_??F.Camera},{enabled:e&&g.isSuccess&&_!==null}),y=v.data??null;ie(()=>{e&&(c(y?Y(y.sections.flatMap(e=>e.fields)):{}),te(X()),u(!1),f(null))},[e,n,y]);let b=A(()=>({...s,_probeRequestId:m}),[s,m]),x=p({onSuccess:()=>{o.invalidateQueries({queryKey:[[`deviceManager`]]})}}),S=t(),C=D(async(e,t)=>{u(!0);let n=await S.mutateAsync({addonId:r,type:_??F.Camera,key:e,value:t,formValues:b});return n.status===`ok`&&n.suggestedValues&&c(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Ce(e[i])&&!Ce(a)&&(r[i]=a,t=!0);return t?r:e}),n},[S,r,b,_]),{testAllStatus:w,hasProbeFields:ne,probeResults:T,handleTestAll:re,clearProbeResult:O}=xe(y??{sections:[]},s,C);async function j(e){f(null);try{await x.mutateAsync({addonId:r,type:_??F.Camera,config:s,integrationId:n}),e?c(y?Y(y.sections.flatMap(e=>e.fields)):{}):i()}catch(e){f(e instanceof Error?e.message:String(e))}}if(!e)return null;let I=Se((y?.sections??[]).flatMap(e=>e.fields)).filter(e=>Ce(s[e])),L=I.length===0,R=g.isLoading||_!==null&&v.isLoading,z=g.isError||g.isSuccess&&_===null||v.isError||v.isSuccess&&y===null;return k(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[P(`div`,{className:`absolute inset-0 bg-black/60`,onClick:i}),k(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[90vh] rounded-xl border border-border bg-background shadow-2xl`,children:[k(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[P(`h2`,{className:`text-sm font-semibold text-foreground`,children:a(`integrations.addDevice`)}),P(`button`,{onClick:i,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:P(me,{className:`h-4 w-4`})})]}),P(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:R?P(`div`,{className:`flex items-center justify-center py-8`,children:P(q,{className:`h-5 w-5 animate-spin text-primary`})}):z?k(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[P(K,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),k(`div`,{className:`space-y-1`,children:[P(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),k(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,P(`span`,{className:`font-mono`,children:r}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):P(J,{schema:y,values:s,onChange:c,onTestField:C,probeResults:T,onClearProbe:O})}),!z&&!R&&k(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[k(`button`,{type:`button`,onClick:()=>u(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[k(`span`,{className:`flex items-center gap-2`,children:[P(he,{className:`h-3.5 w-3.5`}),`Test logs`,P(`span`,{className:`font-mono text-[9px] opacity-60`,children:m.slice(0,14)})]}),P(G,{className:`h-3.5 w-3.5 transition-transform ${l?`rotate-180`:``}`})]}),l&&P(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:P(ee,{addonId:r,requestId:m,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!z&&!R&&(d||I.length>0)&&P(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:k(`div`,{className:`flex items-start gap-2`,children:[P(K,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),P(`p`,{className:`text-[11px] text-destructive`,children:d||`Required: ${I.join(`, `)}`})]})}),k(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[k(`div`,{className:`flex items-center gap-2`,children:[P(`button`,{onClick:i,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:a(`integrations.cancel`)}),!z&&ne&&k(`button`,{type:`button`,onClick:re,disabled:w===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[w===`testing`?P(q,{className:`h-3.5 w-3.5 animate-spin`}):P(se,{className:`h-3.5 w-3.5`}),`Test All`]})]}),k(`div`,{className:`flex items-center gap-2`,children:[P(`button`,{onClick:()=>j(!0),disabled:z||!L||x.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:a(`integrations.saveAndNew`)}),P(`button`,{onClick:()=>j(!1),disabled:z||!L||x.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:x.isPending?a(`integrations.saving`):a(`integrations.save`)})]})]})]})]})}function Z(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}O();var Q=`devices`,Te={id:Q,label:`Devices`,isDefault:!0},Ee=2e4,De=100;function Oe({addonId:t,integrationId:n,onClose:r}){let{t:i}=_e(),[s,c]=N(new Set),[l,d]=N(new Set),[f,p]=N(new Map),[ee,m]=N(null),{data:te}=b(),h=(te??[]).find(e=>e.addonId===t)?.supportsLocationImport??!1,[_,v]=N(!0),y=u({addonId:t,integrationId:n}).data?.filters,S=y&&y.length>0?y:[Te],[C,ne]=N(S.find(e=>e.isDefault)?.id??(S.some(e=>e.id===Q)?Q:S[0].id)),T=C!==Q,E=w(),O=g({addonId:t,integrationId:n,page:1,pageSize:Ee,filter:C}),A=O.refetch,j=E.mutate,M=D(()=>{j({addonId:t,integrationId:n},{onSettled:()=>{A()}})},[j,t,n,A]),F=re(null);ie(()=>{let e=`${t}::${n}`;F.current===e||O.isLoading||(F.current=e,(O.data?.candidates.length??0)===0&&M())},[t,n,O.isLoading,O.data,M]);let I=E.isPending,L=E.isError?E.error instanceof Error?E.error.message:String(E.error):null,R=O.data?.candidates??[],z=O.isError?O.error instanceof Error?O.error.message:String(O.error):null,B=x(),ae=D(e=>{e.alreadyAdopted||c(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),oe=D(e=>{d(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),se=D((e,t)=>{p(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),H=D(e=>{let t={};for(let n of e){let e=f.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[f]),ce=D(async()=>{m(null);let e=[...s];if(e.length!==0)try{let i=H(e);await B.mutateAsync({addonId:t,integrationId:n,filter:C,childNativeIds:e,...i?{perCandidate:i}:{},...h?{importLocations:_}:{}}),c(new Set),p(new Map),await A(),r()}catch(e){m(e instanceof Error?e.message:String(e))}},[s,H,B,t,n,C,A,h,_]),W=D(e=>{ne(e),c(new Set),d(new Set),p(new Map),m(null)},[]),G=s.size;return k(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[P(`div`,{className:`absolute inset-0 bg-black/60`,onClick:r}),k(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] rounded-xl border border-border bg-background shadow-2xl`,children:[k(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[k(`div`,{className:`min-w-0`,children:[P(`h2`,{className:`text-sm font-semibold text-foreground`,children:i(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),P(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:i(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),k(`div`,{className:`flex items-center gap-3 shrink-0`,children:[h&&k(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[P(`input`,{type:`checkbox`,checked:_,onChange:e=>v(e.target.checked),className:`accent-primary`}),i(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),P(`button`,{onClick:r,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:P(me,{className:`h-4 w-4`})})]})]}),k(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(L??z)&&R.length===0&&P(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:k(`div`,{className:`flex items-start gap-2`,children:[P(K,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),k(`div`,{className:`min-w-0`,children:[P(`p`,{className:`text-xs font-medium text-destructive`,children:i(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),P(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:L??z})]})]})}),S.length>1&&P(ke,{filters:S,activeFilter:C,onSelect:W}),P(`div`,{className:`flex-1 min-h-0`,children:P(a,{mode:`generic`,items:R,pageSize:De,getKey:e=>e.childNativeId,getSearchText:Z,getFilterType:e=>e.type,filterOptions:o(),filterLabel:i(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:O.isLoading||I&&R.length===0,searchPlaceholder:i(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(L??z)&&R.length===0?``:i(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:k(`button`,{type:`button`,onClick:M,disabled:I,title:i(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[P(V,{className:`h-3.5 w-3.5 ${I?`animate-spin`:``}`}),i(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:i(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>P($,{candidate:e,expandable:!T,expanded:l.has(e.childNativeId),onToggleExpand:()=>oe(e.childNativeId),adoptedLabel:i(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:i(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:t=>{let n=e(t.type),r=n.icon;return k(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[P(r,{className:`h-3.5 w-3.5 shrink-0`}),n.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>P(`div`,{className:`flex items-center justify-end`,children:P(`button`,{onClick:()=>ae(e),disabled:e.alreadyAdopted,"aria-label":s.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${s.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:s.has(e.childNativeId)&&P(U,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!T&&l.has(e.childNativeId),renderExpanded:T?void 0:e=>P(Ae,{candidate:e,hiddenChildIds:f.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>se(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:s.has(e.childNativeId)?`bg-primary/5`:``})})]}),ee&&P(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:k(`div`,{className:`flex items-start gap-2`,children:[P(K,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),P(`p`,{className:`text-[11px] text-destructive`,children:ee})]})}),k(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[P(`div`,{}),k(`div`,{className:`flex items-center gap-2`,children:[P(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.cancel`,{defaultValue:`Cancel`})}),k(`button`,{onClick:ce,disabled:G===0||B.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,children:[B.isPending&&P(q,{className:`h-3.5 w-3.5 animate-spin`}),i(`integrations.addSelected`,{defaultValue:`Add selected`}),G>0?` (${G})`:``]})]})]})]})]})}function ke({filters:e,activeFilter:t,onSelect:n}){return P(`div`,{role:`tablist`,"aria-label":`Discovery granularity`,className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return P(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function $({candidate:e,expandable:t,expanded:n,onToggleExpand:r,adoptedLabel:i}){let a=(e.children??[]).length;return k(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&a>0?k(`button`,{type:`button`,onClick:r,"aria-label":n?`Collapse`:`Expand`,"aria-expanded":n,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[P(n?G:W,{className:`h-3.5 w-3.5`}),a]}):P(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),P(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&P(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:i})]})}function Ae({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let r=e.children??[];return r.length===0?null:P(`div`,{className:`space-y-1 py-1`,children:r.map(e=>{let r=t.has(e.childNativeId),i=e.capabilities??[];return k(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${r?`opacity-50`:``}`,children:[P(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),i.length>0&&P(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:i.join(`, `)}),P(`button`,{onClick:()=>n(e.childNativeId),"aria-label":r?`Show child`:`Hide child`,title:r?`Show after adopt`:`Hide after adopt`,className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:P(r?H:le,{className:`h-3 w-3`})})]},e.childNativeId)})})}O();function je({integrationId:e,addonId:t,name:n,kind:r,brokerKind:i,trpc:a,onClose:o}){let{t:s}=_e(),l=M(),u=r===`device-adoption`,{data:d}=c({id:e},{enabled:u}),f=A(()=>{let e=d?.brokerId;return typeof e==`string`?e:null},[d]),p=S();return P(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onClick:o,children:k(`div`,{className:`max-h-[85vh] w-full max-w-md overflow-y-auto rounded-xl border border-border bg-surface p-5 shadow-xl`,onClick:e=>e.stopPropagation(),children:[k(`div`,{className:`mb-3 flex items-center justify-between`,children:[k(`h2`,{className:`text-sm font-semibold text-foreground`,children:[s(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]}),P(`button`,{onClick:o,className:`rounded-md p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":s(`common.close`,{defaultValue:`Close`}),children:P(me,{className:`h-4 w-4`})})]}),u?i?k(`div`,{className:`space-y-3`,children:[P(`p`,{className:`text-[11px] text-foreground-subtle`,children:s(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),f&&k(`p`,{className:`text-[11px] text-foreground`,children:[s(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,P(`span`,{className:`font-mono text-foreground-subtle`,children:f})]}),p.isPending?k(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[P(q,{className:`h-3 w-3 animate-spin`}),s(`integrations.saving`,{defaultValue:`Saving…`})]}):P(z,{kind:i,onResolved:t=>{p.mutate({id:e,settings:{brokerId:t}},{onSuccess:()=>{l.invalidateQueries(),o()}})},onBack:o}),p.isError&&P(`p`,{className:`text-[11px] text-danger`,children:s(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):P(`p`,{className:`text-[11px] text-danger`,children:s(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):P(T,{trpc:a,addonId:t,nodeId:`hub`,title:n})]})})}O();function Me(){let{t:e}=_e(),{integrationId:t}=fe(),o=M(),c=ue(),[u,p]=ce(),h=I(),[g,x]=N(!1),[S,w]=N(!1),[T,E]=N(!1),[re,O]=N(!1),[F,z]=N(!1),{data:V,isLoading:se}=v({id:t??``},{enabled:!!t}),{data:H}=m({addonId:V?.addonId??``,nodeId:`hub`},{enabled:!!V?.addonId}),{data:U,isSuccess:W}=b(),G=A(()=>{let e=V?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[U,V?.addonId,W]),{data:le}=s({}),de=A(()=>(le?.providers??[]).some(e=>e.addonId===V?.addonId),[le,V?.addonId]),J=G!==null,be=J?G===`device-adoption`?e(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):e(`integrations.addDevice`):e(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),xe=A(()=>{let e=V?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.brokerKind??null},[U,V?.addonId,W]),Se=A(()=>{let e=V?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.mode??null},[U,V?.addonId,W]);ie(()=>{u.get(`add`)===`1`&&J&&(x(!0),p(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[u,J,p]);let Ce=H!=null&&Array.isArray(H.sections)&&H.sections.some(e=>e.fields.length>0),{data:Y}=n({},{refetchInterval:5e3}),X=[[`integrations`,`get`],{input:{id:t??``},type:`query`}],Z=_({onMutate:async e=>{await o.cancelQueries({queryKey:X});let t=o.getQueryData(X);return t!=null&&o.setQueryData(X,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&o.setQueryData(X,r.previous)},onSettled:()=>{o.invalidateQueries({queryKey:[[`integrations`]]}),o.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=C({onSuccess:()=>{o.invalidateQueries({queryKey:[[`integrations`]]}),o.invalidateQueries({queryKey:[[`deviceManager`]]}),O(!1),c(`/integrations`)}}),Te=l({onSuccess:()=>{o.invalidateQueries({queryKey:[[`integrations`]]}),o.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ee=te({onSuccess:()=>{o.invalidateQueries({queryKey:[[`deviceManager`]]})}}),De=y({onSuccess:()=>{o.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ke=ne({onSuccess:()=>{o.invalidateQueries({queryKey:[[`deviceManager`]]})}}),$=A(()=>Y??[],[Y]),Ae=A(()=>{let e=new Map;for(let t of $)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[$]),Me=D(e=>Ae.get(e)??null,[Ae]),Ne=D(e=>P(L,{type:e,size:`sm`}),[]),Pe=D(e=>c(`/devices/${String(e)}`),[c]),Fe=A(()=>{let e=V?.addonId;return e?$.filter(t=>t.addonId===e):[]},[$,V?.addonId]),Ie=A(()=>r(Fe).length,[Fe]);return se?k(`div`,{className:`p-4`,children:[P(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),P(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):V?k(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[P(f,{items:[{label:`Integrations`,onClick:()=>c(`/integrations`)},{label:V.name}]}),k(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[k(`div`,{className:`flex items-center gap-3 min-w-0`,children:[P(`img`,{src:`/api/addon-assets/${V.addonId}/assets/icon.svg`,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:e=>{e.target.style.display=`none`}}),k(`div`,{className:`min-w-0`,children:[P(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:V.name}),k(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[V.addonId,` · `,Ie,` `,e(`integrations.devices`)]})]})]}),k(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[de&&k(`button`,{onClick:()=>w(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the network for devices (incl. a different subnet)`,children:[P(B,{className:`h-3.5 w-3.5`}),`Scan network`]}),k(`button`,{onClick:()=>x(!0),disabled:!J,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:be,children:[P(R,{className:`h-3.5 w-3.5`}),be]}),k(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Z.isPending?`opacity-60`:``} ${V.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:e(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[P(i,{checked:V.enabled,onCheckedChange:e=>Z.mutate({id:t,enabled:e}),disabled:Z.isPending,"aria-label":V.enabled?`Disable integration`:`Enable integration`}),P(`span`,{className:`text-[11px] font-medium ${V.enabled?`text-success`:`text-foreground-subtle`}`,children:V.enabled?`Enabled`:`Disabled`}),Z.isPending&&P(q,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Se!==`standalone`&&(Ce||G===`device-adoption`)&&k(`button`,{onClick:()=>E(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[P(pe,{className:`h-3 w-3`}),e(`integrations.config`)]}),k(`button`,{onClick:()=>z(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:e(`integrations.logs`,{defaultValue:`View logs`}),children:[P(he,{className:`h-3 w-3`}),e(`integrations.logs`,{defaultValue:`Logs`})]}),P(d,{label:`Restart`,icon:oe,title:`Restart "${V.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Ie} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Te.isPending,action:()=>Te.mutateAsync({addonId:V.addonId})}),k(`button`,{onClick:()=>O(!0),className:`flex items-center gap-1.5 rounded-lg border border-danger bg-danger/10 px-3 py-1.5 text-[11px] font-medium text-danger hover:bg-danger hover:text-background transition-colors`,title:e(`integrations.delete`,{defaultValue:`Delete integration`}),children:[P(ge,{className:`h-3 w-3`}),e(`integrations.delete`,{defaultValue:`Delete`})]})]})]}),P(a,{context:`integration-detail`,devices:$,trpc:h.trpcClient,defaultView:`cards`,forceAddon:V.addonId,urlScope:`root`,lsKey:`integration-detail:${V.addonId}`,resolveIntegrationIcon:Ne,resolveParent:Me,onNavigate:Pe,batchActions:{remove:Ee.mutate,disable:De.mutate,enable:ke.mutate},onDeleteDevice:e=>Ee.mutate({deviceId:e.id})}),g&&t&&G===`device-adoption`&&P(Oe,{addonId:V.addonId,integrationId:t,onClose:()=>x(!1)}),g&&t&&G===`device-provider`&&P(we,{open:g,integrationId:t,addonId:V.addonId,onClose:()=>x(!1)}),S&&V&&P(ae,{open:S,scope:{addonId:V.addonId,label:V.name},onClose:()=>w(!1)}),T&&t&&G!==null&&P(je,{integrationId:t,addonId:V.addonId,name:V.name,kind:G,brokerKind:xe,trpc:h.trpcClient,onClose:()=>E(!1)}),F&&P(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>z(!1),children:k(`div`,{className:`flex flex-col rounded-xl border border-border bg-surface shadow-xl w-full max-w-5xl h-[80vh]`,onClick:e=>e.stopPropagation(),children:[k(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5`,children:[k(`div`,{className:`flex items-center gap-2 min-w-0`,children:[P(he,{className:`h-4 w-4 text-primary shrink-0`}),P(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:V.name}),k(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[V.addonId,t?` · ${t}`:``]})]}),P(`button`,{onClick:()=>z(!1),className:`flex h-7 w-7 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close logs`,children:P(me,{className:`h-4 w-4`})})]}),P(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:P(ee,{addonId:V.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})}),re&&P(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:()=>!Q.isPending&&O(!1),children:k(`div`,{className:`rounded-xl border border-border bg-background p-5 shadow-2xl w-96 space-y-3`,onClick:e=>e.stopPropagation(),children:[k(`div`,{className:`flex items-start gap-3`,children:[P(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg bg-danger/10 shrink-0`,children:P(K,{className:`h-4 w-4 text-danger`})}),k(`div`,{className:`min-w-0`,children:[P(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`integrations.deleteTitle`,{defaultValue:`Delete integration?`})}),P(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:e(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:V.name,count:Ie})})]})]}),Q.error&&P(`div`,{className:`rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:Q.error instanceof Error?Q.error.message:String(Q.error)}),k(`div`,{className:`flex items-center justify-end gap-2 pt-1`,children:[P(`button`,{onClick:()=>O(!1),disabled:Q.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:e(`integrations.cancel`,{defaultValue:`Cancel`})}),P(`button`,{onClick:()=>Q.mutate({id:t}),disabled:Q.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-danger px-3 py-1.5 text-[11px] font-medium text-background hover:bg-danger/90 transition-colors disabled:opacity-60 disabled:cursor-not-allowed`,children:Q.isPending?k(j,{children:[P(q,{className:`h-3 w-3 animate-spin`}),e(`integrations.deleting`,{defaultValue:`Deleting…`})]}):k(j,{children:[P(ge,{className:`h-3 w-3`}),e(`integrations.confirmDelete`,{defaultValue:`Delete integration`})]})})]})]})})]}):k(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[P(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:P(ye,{className:`h-6 w-6 text-foreground-subtle`})}),k(`div`,{className:`space-y-1 max-w-sm`,children:[P(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),P(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:t??``})})]}),k(`button`,{onClick:()=>c(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[P(ve,{className:`h-3 w-3`}),e(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}export{Me as IntegrationDetailPage};
@@ -1 +0,0 @@
1
- import{Da as e,Dr as t,Er as n,Oa as r,Sr as i,Tr as a,Zi as o,_r as s,br as c,gr as l,hr as u,ht as d,ji as f,ka as p,mr as m,mt as h,pr as g,ua as _,vr as v,xr as y,yr as b}from"./src-9Nw_7MUt.js";import{I as x,Q as S,S as C,W as w,b as T,o as E,q as D,x as O,z as ee}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 k,s as A}from"./src-DYcadIAu.js";import{p as j}from"./player-overlays-CqpHdvYF.js";import{n as M,t as te}from"./rotate-ccw-C9Gcb3tJ.js";import{t as N}from"./copy-BwY737s-.js";import{n as ne,t as P}from"./AddonCollectionPage-BkUO0Tru.js";import{t as re}from"./refresh-cw-DH7JcsAT.js";import{t as F}from"./server-Crr45iTm.js";import{t as ie}from"./sparkles-C5A0sFZJ.js";import{t as ae}from"./square-jObXvdFU.js";import{t as oe}from"./wifi-G6nDQGOi.js";import{D as I,F as se,V as L,_ as R,b as ce,i as le,o as z,w as B,x as V,y as ue}from"./index-Da6GKRLl.js";import{t as H}from"./AdminPage-BwmGKnRf.js";import{t as U}from"./AdminTabs-mgvEpBDZ.js";var de=L(`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`}]]),fe=L(`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=L(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]);S();var G=5e3,pe={connected:!1,endpoint:null};function me(e){let t=new Map;for(let n of e){let e=n?.manifest;e?.id&&t.set(e.id,e.packageDisplayName??e.name??e.id)}return t}function he(){let e=E(),r=d({capName:`network-access`},{refetchInterval:G}),i=h(void 0,{refetchInterval:G}),a=w(()=>me(i.data??[]),[i.data]),o=w(()=>(r.data??[]).map(e=>({addonId:e.addonId,displayName:a.get(e.addonId)??e.addonId,isActive:e.isActive})),[r.data,a]),[s,c]=D(null),[l,u]=D({}),f=(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=n({onSuccess:f,onError:p}),g=t({onSuccess:f,onError:p});return O(P,{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:B,itemIcon:B,capability:`network-access`,installButtonLabel:`Add tunnel`,items:o,isLoading:r.isLoading,emptyTitle:`No remote-access providers installed`,emptyDescription:`Install a tunnel addon (e.g. @camstack/addon-cloudflare) to expose this hub publicly.`,renderStatusBadges:e=>O(ge,{addonId:e.addonId}),itemError:e=>l[e.addonId]??null,renderPrimaryAction:e=>O(_e,{addonId:e.addonId,busyId:s,onStart:e=>{c(e),m.mutate({addonId:e})},onStop:e=>{c(e),g.mutate({addonId:e})}})})}function K(e){let{data:t}=a({addonId:e},{refetchInterval:G,retry:!1}),n=t?A.safeParse(t):null;return n?.success?n.data:pe}function ge({addonId:e}){let t=K(e);return C(T,{children:[O(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.connected?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.connected?`Connected`:`Disconnected`}),t.endpoint&&C(`a`,{href:t.endpoint.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-[10px] text-emerald-700 dark:text-emerald-300 hover:underline flex items-center gap-1`,children:[O(I,{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?C(p,{size:`sm`,variant:`secondary`,disabled:a,onClick:()=>r(e),children:[a?O(V,{className:`h-3 w-3 animate-spin`}):O(ae,{className:`h-3 w-3`}),`Stop`]}):C(p,{size:`sm`,variant:`primary`,disabled:a,onClick:()=>n(e),children:[a?O(V,{className:`h-3 w-3 animate-spin`}):O(ne,{className:`h-3 w-3`}),`Start`]})}S();var q=3e4;function ve(e){let t=new Map;for(let n of e){let e=n?.manifest;e?.id&&t.set(e.id,e.packageDisplayName??e.name??e.id)}return t}function ye(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function be(){let t=d({capName:`turn-provider`},{refetchInterval:q}),n=h(void 0,{refetchInterval:q}),r=f(),i=r.data??[],a=w(()=>ve(n.data??[]),[n.data]);return O(P,{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:R,itemIcon:R,capability:`turn-provider`,installButtonLabel:`Add provider`,items:w(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:a.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,a]),isLoading:t.isLoading,emptyTitle:`No TURN providers installed`,emptyDescription:`Install a TURN addon (e.g. @camstack/addon-cloudflare) to enable WebRTC behind restrictive NATs.`,renderExpandedPanel:e=>O(xe,{addonId:e.addonId,enabled:e.isActive}),trailing:C(e,{children:[C(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[C(`div`,{children:[O(`div`,{className:`text-sm font-semibold`,children:`Combined ICE server list`}),O(`div`,{className:`text-xs text-foreground-subtle`,children:`What the WebRTC layer fetches per-session.`})]}),O(p,{size:`sm`,variant:`secondary`,onClick:()=>r.refetch(),disabled:r.isFetching,children:`Refresh`})]}),O(`div`,{className:`p-4`,children:i.length===0?O(`div`,{className:`text-xs text-foreground-subtle`,children:`No servers from enabled providers.`}):O(`div`,{className:`flex flex-col gap-3`,children:i.map((e,t)=>{let n=Array.isArray(e.urls)?e.urls:[e.urls];return C(`div`,{className:`rounded border border-border bg-surface`,children:[(e.username||e.credential)&&C(`div`,{className:`px-3 py-1.5 border-b border-border text-[10px] font-mono text-foreground-subtle flex items-center gap-3`,children:[e.username&&C(`span`,{children:[O(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,O(`span`,{className:`text-foreground`,children:e.username})]}),e.credential&&C(`span`,{children:[O(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,O(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),O(`ul`,{className:`divide-y divide-border`,children:n.map(e=>O(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},t)})})})]})})}function xe({addonId:e,enabled:t}){let n=f({addonId:e},{enabled:t,retry:!1}),r=w(()=>ye(n.data??[]),[n.data]);return!t||r.length===0?null:C(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[C(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Discovered ICE servers (`,r.length,`)`]}),O(`div`,{className:`flex flex-wrap gap-1`,children:r.map(e=>O(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground`,children:e},e))})]})}S();var Se={lan:R,wifi:oe,docker:M,vpn:ce,loopback:F,other:F},Ce={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},we=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function Te(e){let{interfaces:t,disabled:n,hideLoopback:r,ipv4Only:i,emptyMessage:a}=e,o=w(()=>t.filter(e=>!(r&&e.kind===`loopback`||i&&e.family!==`IPv4`)),[t,r,i]),s=w(()=>{let e=new Map;for(let t of o){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return we.filter(t=>e.has(t)).map(t=>({kind:t,items:e.get(t)}))},[o]),c=t=>e.mode===`single`?e.value===t:e.value.includes(t),l=t=>{if(n||t.kind===`loopback`)return;if(e.mode===`single`){e.onChange(e.value===t.address?null:t.address);return}let r=new Set(e.value);r.has(t.address)?r.delete(t.address):r.add(t.address),e.onChange([...r])};return o.length===0?O(`div`,{className:`text-xs text-foreground-subtle italic`,children:a??`No addresses available.`}):O(`div`,{className:`flex flex-col gap-3`,children:s.map(({kind:t,items:r})=>C(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[C(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[O(Se[t]??F,{className:`h-3.5 w-3.5 text-foreground-subtle`}),O(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:Ce[t]??t}),C(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,r.length]})]}),O(`ul`,{className:`divide-y divide-border`,children:r.map(t=>{let r=c(t.address),i=t.kind===`loopback`,a=!t.plausible&&!i;return C(`li`,{className:`flex items-center gap-3 px-3 py-2 ${i?`opacity-60 cursor-not-allowed`:n?`opacity-60`:a?`cursor-pointer hover:bg-surface-hover/30 bg-amber-500/[0.04]`:`cursor-pointer hover:bg-surface-hover/30`}`,onClick:()=>l(t),children:[O(`span`,{className:`flex items-center justify-center h-4 w-4 rounded ${e.mode===`single`?`rounded-full`:`rounded`} border ${r?`border-primary bg-primary text-primary-foreground`:`border-border bg-surface`}`,children:r&&O(se,{className:`h-3 w-3`})}),C(`div`,{className:`flex-1 min-w-0 ${a?`text-foreground-subtle`:``}`,children:[C(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[O(`span`,{className:`font-mono text-xs font-semibold ${a?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),O(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-mono`,children:t.family}),t.preferred&&O(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:`Auto-preferred`}),i&&O(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:`Always included`}),a&&C(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:t.plausibleReason||void 0,children:[O(z,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]}),C(`div`,{className:`text-xs text-foreground-subtle mt-0.5 font-mono break-all`,children:[t.address,t.cidr&&t.cidr!==t.address?` (${t.cidr})`:``]})]})]},`${t.name}-${t.family}-${t.address}`)})})]},t))})}S();var J={"lan-ipv4":`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,"lan-ipv6":`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`,loopback:`bg-foreground-subtle/15 text-foreground-subtle`};function Ee(){let t=E(),n=j(),r=u(void 0,{refetchInterval:3e4}),i=g(void 0),a=s({onSuccess:()=>{t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),o=l({onSuccess:e=>{h(e.addresses),t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),c=w(()=>r.data?.interfaces??[],[r.data]),d=m({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,h]=D([]),[_,v]=D(!1);ee(()=>{!_&&i.data&&(h(i.data.addresses),v(!0))},[i.data,_]);let y=i.data?.addresses??[],b=w(()=>{if(f.length!==y.length)return!0;let e=[...f].toSorted(),t=[...y].toSorted();return e.some((e,n)=>e!==t[n])},[f,y]),x=()=>{a.mutate({addresses:[...f]})},S=()=>{h(y)},T=()=>{h([])},k=()=>{r.refetch(),d.refetch(),i.refetch()},A=async()=>{try{let e=await n.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info(`[network-addresses] race result`,e)}catch(e){console.warn(`[network-addresses] race failed`,e)}},M=d.data?.endpoints??[];return C(H,{children:[C(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[O(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Pick the local addresses SDK clients should race for the fastest path to this hub. Empty selection (auto) lets every non-loopback / non-link-local interface participate.`}),C(`div`,{className:`flex items-center gap-2 shrink-0`,children:[C(p,{size:`sm`,variant:`secondary`,onClick:k,disabled:r.isLoading,children:[O(re,{className:`h-3 w-3 ${r.isLoading?`animate-spin`:``}`}),`Refresh`]}),O(p,{size:`sm`,variant:`secondary`,onClick:A,children:`Probe race`})]})]}),C(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[C(e,{children:[C(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[C(`div`,{children:[O(`div`,{className:`text-sm font-semibold`,children:`Allowed addresses`}),O(`div`,{className:`text-xs text-foreground-subtle`,children:f.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${f.length} pinned`})]}),C(`div`,{className:`flex items-center gap-1`,children:[C(p,{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:[O(ie,{className:`h-3 w-3`}),o.isPending?`Detecting…`:`Best match`]}),C(p,{size:`sm`,variant:`secondary`,onClick:T,disabled:f.length===0||a.isPending,children:[O(te,{className:`h-3 w-3`}),`Clear`]}),b&&O(p,{size:`sm`,variant:`secondary`,onClick:S,disabled:a.isPending,children:`Discard`}),C(p,{size:`sm`,variant:`primary`,onClick:x,disabled:!b||a.isPending,children:[O(fe,{className:`h-3 w-3`}),a.isPending?`Saving…`:`Save`]})]})]}),O(`div`,{className:`p-4`,children:O(Te,{mode:`multiple`,interfaces:c,value:f,onChange:h,disabled:a.isPending,emptyMessage:r.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),C(e,{children:[C(`div`,{className:`px-4 py-3 border-b border-border`,children:[O(`div`,{className:`text-sm font-semibold`,children:`Connection endpoints — priority order`}),O(`div`,{className:`text-xs text-foreground-subtle`,children:`Live preview of the ranked candidate list the SDK would race against. Updates with each Save.`})]}),O(`div`,{className:`p-4`,children:M.length===0?O(`div`,{className:`text-xs text-foreground-subtle italic`,children:d.isLoading?`Loading…`:`No endpoints available.`}):O(`ul`,{className:`space-y-1 text-xs`,children:M.map(e=>C(`li`,{className:`flex items-center gap-2 flex-wrap ${e.plausible?``:`opacity-80`}`,children:[O(`span`,{className:`font-mono text-[10px] w-10 text-foreground-subtle`,children:String(e.priority).padStart(4,`0`)}),O(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${J[e.kind]??J.loopback}`,children:e.kind}),e.interfaceKind!==`lan`&&e.interfaceKind!==`public`&&O(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-medium uppercase`,children:e.interfaceKind}),!e.plausible&&e.interfaceKind!==`loopback`&&C(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:e.plausibleReason||void 0,children:[O(z,{className:`h-2.5 w-2.5`}),`Unlikely usable`]}),O(`span`,{className:`font-mono break-all ${e.plausible?`text-foreground`:`text-foreground-subtle`}`,children:e.baseUrl}),C(`span`,{className:`text-foreground-subtle`,children:[`— `,e.label]})]},`${e.priority}-${e.baseUrl}`))})})]})]})]})}S();var De={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,Oe=3e4,ke={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function Ae(e){let t=new Map;for(let n of e){let e=n?.manifest;e?.id&&t.set(e.id,e.packageDisplayName??e.name??e.id)}return t}function je(){let e=d({capName:`mesh-network`},{refetchInterval:Y}),t=h(void 0,{refetchInterval:Y}),n=w(()=>Ae(t.data??[]),[t.data]);return O(P,{title:`Mesh Networks`,subtitle:`Private VPN meshes that connect CamStack to your other devices (Tailscale, Headscale, …). Each provider can also expose this hub publicly via its ingress (Tailscale Funnel).`,pageIcon:M,itemIcon:R,capability:`mesh-network`,installButtonLabel:`Add mesh`,items:w(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,n]),isLoading:e.isLoading,emptyTitle:`No mesh-network providers installed`,emptyDescription:`Install a mesh addon (e.g. @camstack/addon-tailscale) to join this hub into a private VPN mesh.`,renderStatusBadges:e=>O(Me,{addonId:e.addonId}),renderPrimaryAction:e=>O(Z,{addonId:e.addonId}),renderExpandedPanel:e=>O(Ne,{addonId:e.addonId})})}function X(e){let{data:t,isLoading:n}=v({addonId:e},{refetchInterval:Y,retry:!1}),r=t?k.safeParse(t):null;return{status:r?.success?r.data:ke,isLoading:n}}function Me({addonId:e}){let{status:t}=X(e);return C(T,{children:[O(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.joined?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.joined?`Joined`:`Not joined`}),t.joined&&C(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:[t.peerCount,` peer`,t.peerCount===1?``:`s`]})]})}function Z({addonId:e}){let t=E(),[n,r]=D(!1),[a,o]=D(null),s=j(),{status:c}=X(e),l=x(()=>{t.invalidateQueries({queryKey:[[`meshNetwork`]]})},[t]),u=i(),d=b({onSuccess:l}),f=y({onSuccess:l}),m=x(async()=>{r(!0);let t={cancelled:!1};o(t);try{let n=await u.mutateAsync({addonId:e});if(t.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!t.cancelled&&(await Re(2e3),!t.cancelled);){let t=await s.trpcClient.meshNetwork.getStatus.query({addonId:e}).catch(()=>null),n=t?k.safeParse(t):null;if(n?.success&&n.data.joined){l();break}if(Date.now()-r>6e5)break}}finally{r(!1),o(null)}},[e,l,u,s]),h=x(()=>{a&&(a.cancelled=!0),r(!1),o(null)},[a]);return O(T,{children:c.joined?C(T,{children:[C(p,{size:`sm`,variant:`secondary`,disabled:d.isPending,onClick:()=>d.mutate({addonId:e}),children:[d.isPending?O(V,{className:`h-3 w-3 animate-spin`}):O(ue,{className:`h-3 w-3`}),`Disconnect`]}),C(p,{size:`sm`,variant:`ghost`,disabled:f.isPending,onClick:()=>f.mutate({addonId:e}),children:[f.isPending?O(V,{className:`h-3 w-3 animate-spin`}):O(W,{className:`h-3 w-3`}),`Log out`]})]}):n?C(p,{size:`sm`,variant:`ghost`,onClick:h,children:[O(le,{className:`h-3 w-3 mr-1`}),` Cancel`]}):C(T,{children:[C(p,{size:`sm`,variant:`primary`,onClick:()=>void m(),children:[O(de,{className:`h-3 w-3`}),`Connect`]}),C(p,{size:`sm`,variant:`ghost`,disabled:f.isPending,onClick:()=>f.mutate({addonId:e}),children:[f.isPending?O(V,{className:`h-3 w-3 animate-spin`}):O(W,{className:`h-3 w-3`}),`Log out`]})]})})}function Ne({addonId:e}){let{status:t}=X(e),n=c({addonId:e},{refetchInterval:Oe,retry:!1});return C(`div`,{className:`rounded-lg border border-border bg-surface`,children:[C(`div`,{className:`p-4 space-y-4`,children:[t.error&&O(o,{message:t.error}),O(Pe,{status:t}),t.endpoints.length>0&&C(`div`,{className:`space-y-1.5`,children:[O(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Endpoints`}),t.endpoints.map(e=>C(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[C(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${De[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?O(B,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),C(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-emerald-700 dark:text-emerald-300 hover:underline break-all flex items-center gap-1`,children:[O(I,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),O(`div`,{className:`border-t border-border`,children:O(Ie,{peers:n.data?.peers??[],loading:n.isLoading})})]})}function Pe({status:e}){return O(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-1.5`,children:[{label:`Tenant`,value:e.tenantName||`—`},{label:`User`,value:e.userLogin??`—`},{label:`Control plane`,value:e.controlPlaneUrl||`—`},{label:`Mesh IP`,value:e.meshIp||`—`,mono:!0},{label:`MagicDNS`,value:e.magicDnsHostname||`—`,mono:!0},{label:`DNS suffix`,value:e.magicDnsSuffix||`—`,mono:!0},{label:`Peers`,value:String(e.peerCount)},{label:`Key expiry`,value:e.keyExpiry?Fe(e.keyExpiry):`—`}].map(e=>C(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[O(`span`,{className:`text-foreground-subtle shrink-0`,children:e.label}),O(`span`,{className:`text-foreground truncate ${e.mono?`font-mono`:``}`,children:e.value})]},e.label))})}function Fe(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 Ie({peers:e,loading:t}){let n=w(()=>e.map(e=>({...e,_id:e.id})),[e]),i=x(e=>{e&&navigator.clipboard?.writeText(e)},[]),a=w(()=>[{key:`hostname`,header:`Hostname`,render:e=>C(`div`,{className:`flex flex-col`,children:[C(`div`,{className:`flex items-center gap-1.5`,children:[O(`span`,{className:`font-medium text-foreground`,children:e.hostname||`(unknown)`}),e.isSelf&&O(r,{variant:`info`,children:`self`}),e.exitNodeOption&&O(r,{variant:`warning`,children:`exit-node`})]}),e.userLogin&&O(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.userLogin})]})},{key:`magicDns`,header:`MagicDNS`,render:e=>e.magicDns?C(`div`,{className:`flex items-center gap-1`,children:[O(`span`,{className:`font-mono text-xs truncate`,children:e.magicDns}),O(`button`,{onClick:()=>i(e.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy MagicDNS`,children:O(N,{className:`h-3 w-3 text-foreground-subtle`})})]}):O(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:e=>{let t=e.addresses[0]??``;return t?C(`div`,{className:`flex items-center gap-1`,children:[O(`span`,{className:`font-mono text-xs`,children:t}),O(`button`,{onClick:()=>i(t),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy IP`,children:O(N,{className:`h-3 w-3 text-foreground-subtle`})})]}):O(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:`Connection`,render:e=>C(`div`,{className:`flex items-center gap-1.5`,children:[O(r,{variant:Le(e.connection),children:e.connection}),e.relay&&O(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.relay})]})},{key:`routes`,header:`Routes`,render:e=>e.advertisedRoutes.length>0?O(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):O(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:`TX / RX`,render:e=>C(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,Q(e.txBytes),` · ↓ `,Q(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>O(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?$(e.lastSeenMs):`—`})}],[i]);return t&&e.length===0?C(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[O(V,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):e.length===0?O(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No peers visible — your tailnet may be empty or the host is not joined.`}):O(`div`,{className:`p-4`,children:O(_,{columns:a,rows:n,rowKey:e=>e._id,minWidthPx:820})})}function Le(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 Re(e){return new Promise(t=>setTimeout(t,e))}function ze(){return O(`div`,{className:`flex flex-col p-4`,children:O(U,{tabs:[{id:`addresses`,label:`Network Addresses`,icon:F,content:O(Ee,{})},{id:`remote-access`,label:`Remote Access`,icon:B,content:O(he,{})},{id:`mesh`,label:`Mesh Networks`,icon:M,content:O(je,{})},{id:`turn`,label:`TURN Servers`,icon:R,content:O(be,{})}]})})}export{ze as NetworkPage};