@camstack/addon-admin-ui 1.2.109 → 1.2.111

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 (101) hide show
  1. package/dist/assets/{AddLocationWizard-DVt0za_9.js → AddLocationWizard-CEgiBGeK.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-DWplp-oK.js → AddonCollectionPage-DH55gIbE.js} +1 -1
  3. package/dist/assets/{Addons-BjpIgFkC.js → Addons-CGooWY5T.js} +1 -1
  4. package/dist/assets/{AdminTabs-4zkj5XSp.js → AdminTabs-CR-73Caj.js} +1 -1
  5. package/dist/assets/{AiProfiles-DRWH68EU.js → AiProfiles-9KKYGhmH.js} +1 -1
  6. package/dist/assets/{BrokerForm-CXoJXoeC.js → BrokerForm-5ka8xuo5.js} +1 -1
  7. package/dist/assets/{Build-CHfx39iZ.js → Build-NmOv_ttA.js} +1 -1
  8. package/dist/assets/{Capabilities-Ydyl3Dhc.js → Capabilities-D8IlmLou.js} +1 -1
  9. package/dist/assets/{CapabilityBadges-DbqvYCTx.js → CapabilityBadges-CXpMHOmO.js} +1 -1
  10. package/dist/assets/Cluster-DbR9yx2R.js +11 -0
  11. package/dist/assets/{Data-Ccb_lYs2.js → Data-Do5W9Wl2.js} +1 -1
  12. package/dist/assets/{DetectionIntelligence-BFe74hPm.js → DetectionIntelligence-03FqDXd8.js} +1 -1
  13. package/dist/assets/{DeviceAggregateSection-wxIEfTgN.js → DeviceAggregateSection-DijwEDkL.js} +1 -1
  14. package/dist/assets/{DeviceDetail-BTODFjmg.js → DeviceDetail-B9IIayJd.js} +1 -1
  15. package/dist/assets/{Devices-lE6CGmWT.js → Devices-CLzII3FS.js} +1 -1
  16. package/dist/assets/{EmbedPlayerPage-EL2eM8Az.js → EmbedPlayerPage-5qdw9AQ5.js} +1 -1
  17. package/dist/assets/Events-zRoA9Jz6.js +1 -0
  18. package/dist/assets/{FormBuilder-D_bhTf6T.js → FormBuilder-DobHTqPD.js} +1 -1
  19. package/dist/assets/{Identity-DtJZgHbi.js → Identity-BxhLyy_z.js} +1 -1
  20. package/dist/assets/{IntegrationDetail-CSW-g7yU.js → IntegrationDetail-C-Il9aYL.js} +1 -1
  21. package/dist/assets/{Integrations-Q9TuMm7_.js → Integrations-C6zctJcf.js} +1 -1
  22. package/dist/assets/{Integrations-RtsvRfEc.js → Integrations-CSyV2oCS.js} +1 -1
  23. package/dist/assets/{Logs-Chliu8ip.js → Logs-k2AatW44.js} +1 -1
  24. package/dist/assets/{MotionZonesSettings-BTYV12ib.js → MotionZonesSettings-DztkSAzw.js} +1 -1
  25. package/dist/assets/{MyAccess-CVMv1P7j.js → MyAccess-Df7ce85Y.js} +1 -1
  26. package/dist/assets/{Network-Cxza5Erf.js → Network-NH7cqo5t.js} +1 -1
  27. package/dist/assets/{NodeAddonsSettingsPanel-Ct93rhsv.js → NodeAddonsSettingsPanel-CZgCHLIC.js} +1 -1
  28. package/dist/assets/{NodeInferenceDevices-Cb41ITAx.js → NodeInferenceDevices-rr-TGfyF.js} +1 -1
  29. package/dist/assets/{Notifications-DH-3KUGO.js → Notifications-D1EmPjgE.js} +1 -1
  30. package/dist/assets/{Pipeline-Bnh4BvJw.js → Pipeline-DrJnzJ9t.js} +1 -1
  31. package/dist/assets/{Plates-DTgO0CTY.js → Plates-6NNWxuhT.js} +1 -1
  32. package/dist/assets/{PrivacyMaskSettings-Bt-onl_p.js → PrivacyMaskSettings-BhcRGnjg.js} +1 -1
  33. package/dist/assets/{ProviderIcon-CQ3zBUuC.js → ProviderIcon-CvKyMo33.js} +1 -1
  34. package/dist/assets/{Recordings-NknJVWbz.js → Recordings-BWG4GaMv.js} +1 -1
  35. package/dist/assets/{ScanNetworkModal-usrCXDoI.js → ScanNetworkModal-lm518Ul1.js} +1 -1
  36. package/dist/assets/{SceneMonitorEditor-CFPhO9Na.js → SceneMonitorEditor-CC_SRLkY.js} +1 -1
  37. package/dist/assets/{Scenes-Di30HB2t.js → Scenes-BK317X1w.js} +1 -1
  38. package/dist/assets/{Settings-DpnrxEdU.js → Settings-DgNT8lpk.js} +1 -1
  39. package/dist/assets/{Showroom-BMTp7fak.js → Showroom-CFtZjm_S.js} +1 -1
  40. package/dist/assets/{Terminal-CabXjLgJ.js → Terminal-N1q4JLrF.js} +1 -1
  41. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Bd5YVyDX.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-MSGGSFff.js} +1 -1
  42. package/dist/assets/{bell-ring-BYggvQca.js → bell-ring-Dc40Lz_m.js} +1 -1
  43. package/dist/assets/{boxes-DM1XrDXa.js → boxes-D_EBN2IO.js} +1 -1
  44. package/dist/assets/circle-check-big-BLcbyBkC.js +1 -0
  45. package/dist/assets/{circle-x-CjftHCtn.js → circle-x-9TEaOYMh.js} +1 -1
  46. package/dist/assets/clock-CmWJJCCR.js +1 -0
  47. package/dist/assets/{copy-cBOxpZ8P.js → copy-2sJiEWo5.js} +1 -1
  48. package/dist/assets/{debounced-invalidate-PFEkzyMG.js → debounced-invalidate-BPm0xQjE.js} +1 -1
  49. package/dist/assets/{dist-DWjN4AwJ.js → dist-B2d_n790.js} +1 -1
  50. package/dist/assets/dist-CwHxBEa6.js +349 -0
  51. package/dist/assets/{download-CirENnbh.js → download-Bi9sN8UV.js} +1 -1
  52. package/dist/assets/{face-bbox-BhSYe0P0.js → face-bbox-BiVLa1QE.js} +1 -1
  53. package/dist/assets/{hostInit-oIU7Vu_q.js → hostInit-BXhxZCos.js} +1 -1
  54. package/dist/assets/{index-JUF-VzOE.js → index-BWNViBw0.js} +3 -3
  55. package/dist/assets/{index-2B_jjVhf.css → index-CChcWx2e.css} +1 -1
  56. package/dist/assets/{key-round-CNjQoJAO.js → key-round-Cwk2sFDK.js} +1 -1
  57. package/dist/assets/{layers-BbTQR4Ts.js → layers-Bkhxc8O8.js} +1 -1
  58. package/dist/assets/{mf-entry-bootstrap-0-737047d0.js → mf-entry-bootstrap-0-767fb92e.js} +2 -2
  59. package/dist/assets/{pencil-Bz16G0wg.js → pencil-BF1cI2bF.js} +1 -1
  60. package/dist/assets/play-DrhkSF52.js +1 -0
  61. package/dist/assets/{player-overlays-C82v-qwN.js → player-overlays-BrCS3AFF.js} +1 -1
  62. package/dist/assets/plus-BNmythl0.js +1 -0
  63. package/dist/assets/power-bOdAXjkP.js +1 -0
  64. package/dist/assets/{radio-BpkPlUcc.js → radio-BWOwFRH2.js} +1 -1
  65. package/dist/assets/{refresh-cw-MvTOb710.js → refresh-cw-D7w1H6wV.js} +1 -1
  66. package/dist/assets/remoteEntry-y4f0U6fp.js +1 -0
  67. package/dist/assets/rotate-ccw-BSwQUT3g.js +1 -0
  68. package/dist/assets/rotate-cw-C-Y0NZbw.js +1 -0
  69. package/dist/assets/{send-Bghf7VTV.js → send-MJzFX77B.js} +1 -1
  70. package/dist/assets/{server-HN9uDXhM.js → server-DhlXaMrU.js} +1 -1
  71. package/dist/assets/{shield-CZo8EJtJ.js → shield-CAl6DSIT.js} +1 -1
  72. package/dist/assets/square-DmrJdKXC.js +1 -0
  73. package/dist/assets/{square-check-big-NfXNSjaq.js → square-check-big-Bh9qEI5Y.js} +1 -1
  74. package/dist/assets/src-CTpgEWRF.js +67 -0
  75. package/dist/assets/src-Db_n2ue2.js +349 -0
  76. package/dist/assets/{star-CrQ3fiXC.js → star-BLl-AYwU.js} +1 -1
  77. package/dist/assets/{undo-2-C9d7b8fp.js → undo-2-DY_9xHcZ.js} +1 -1
  78. package/dist/assets/{use-scenes-feed-IFMeXKP_.js → use-scenes-feed-DuRQEHSx.js} +1 -1
  79. package/dist/assets/useEventInvalidation-DI7nUUUv.js +1 -0
  80. package/dist/assets/{video-_g8ORnym.js → video-B4mg6mWU.js} +1 -1
  81. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CM3XhGTs.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-vbnrVEeZ.js} +2 -2
  82. package/dist/assets/{wifi-DgVkB_aX.js → wifi-ywTK10OM.js} +1 -1
  83. package/dist/assets/{zap-CNS3qfgy.js → zap-BCx1At6u.js} +1 -1
  84. package/dist/index.html +6 -6
  85. package/dist/server/addon.js +143 -2
  86. package/package.json +1 -1
  87. package/dist/assets/Cluster-DTFlM0ry.js +0 -11
  88. package/dist/assets/Events-B2Hn4orj.js +0 -1
  89. package/dist/assets/circle-check-big-BxRTF9W-.js +0 -1
  90. package/dist/assets/clock-Dz_n89dK.js +0 -1
  91. package/dist/assets/dist-B4f7WmLM.js +0 -349
  92. package/dist/assets/play-Dvnd56Mu.js +0 -1
  93. package/dist/assets/plus-Df153AO8.js +0 -1
  94. package/dist/assets/power-TvWQYQph.js +0 -1
  95. package/dist/assets/remoteEntry-CTd6ZDuI.js +0 -1
  96. package/dist/assets/rotate-ccw-C8RUMp4_.js +0 -1
  97. package/dist/assets/rotate-cw-D_fIdRma.js +0 -1
  98. package/dist/assets/square-CWz1Ojab.js +0 -1
  99. package/dist/assets/src-BZXGF7UJ.js +0 -67
  100. package/dist/assets/src-BeRVcbbC.js +0 -349
  101. package/dist/assets/useEventInvalidation-BYeF1CRq.js +0 -1
@@ -1 +1 @@
1
- import{Q as e,S as t,W as n,b as r,o as i,q as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as s}from"./player-overlays-C82v-qwN.js";import{C as c,On as l,dr as u,fr as d,lr as f,mr as p,or as m,pr as h,sr as g,un as _,ur as v,yr as y}from"./src-BZXGF7UJ.js";import{H as b,dt as x,st as S}from"./src-BeRVcbbC.js";import{t as C}from"./pencil-Bz16G0wg.js";import{t as w}from"./plus-Df153AO8.js";import{t as T}from"./radio-BpkPlUcc.js";import{t as E}from"./wifi-DgVkB_aX.js";import{C as D,J as O,K as k,o as ee,r as A,v as j}from"./index-JUF-VzOE.js";import{t as M}from"./AdminPage-CCD07UMs.js";import{t as N}from"./AdminTabs-4zkj5XSp.js";import{t as P}from"./BrokerForm-CXoJXoeC.js";import{t as F}from"./useBodyScrollLock-BDocajQE.js";import{t as I}from"./AddonCollectionPage-DWplp-oK.js";var L=k(`mail`,[[`path`,{d:`m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7`,key:`132q7q`}],[`rect`,{x:`2`,y:`4`,width:`20`,height:`16`,rx:`2`,key:`izxlao`}]]),R=k(`share-2`,[[`circle`,{cx:`18`,cy:`5`,r:`3`,key:`gq8acd`}],[`circle`,{cx:`6`,cy:`12`,r:`3`,key:`w7nqdw`}],[`circle`,{cx:`18`,cy:`19`,r:`3`,key:`1xt0gg`}],[`line`,{x1:`8.59`,x2:`15.42`,y1:`13.51`,y2:`17.49`,key:`47mynk`}],[`line`,{x1:`15.41`,x2:`8.59`,y1:`6.51`,y2:`10.49`,key:`1n3mei`}]]);e();var z={"home-assistant":`Home Assistant`,mqtt:`MQTT`};function B(e){return z[e]??e}function V(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var H={connected:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,connecting:`bg-amber-500/15 text-amber-700 dark:text-amber-300`,disconnected:`bg-foreground-subtle/15 text-foreground-subtle`,"auth-failed":`bg-danger/15 text-danger`,unreachable:`bg-danger/15 text-danger`,error:`bg-danger/15 text-danger`};function U({status:e}){return o(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${H[e]}`,children:e})}function W(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function G({title:e,subtitle:n,onClose:r,children:i}){return F(),o(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,children:t(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[t(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[t(`div`,{className:`space-y-0.5`,children:[o(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),n&&o(`p`,{className:`text-xs text-foreground-subtle`,children:n})]}),o(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,children:o(A,{className:`h-4 w-4`})})]}),o(`div`,{className:`p-4 max-h-[70vh] overflow-y-auto overscroll-contain`,children:i})]})})}function K({kinds:e,onClose:n,onDone:s}){let c=i(),l=e=>`${e.addonId??``}::${e.kind}`,[u,d]=a(e[0]?l(e[0]):``),[f,p]=a(``),[h,g]=a(!1),[_,v]=a(``),y=e.find(e=>l(e)===u)??e[0],b=y?.kind??``,x=y?.addonId,S=m({onSuccess:()=>{c.invalidateQueries({queryKey:[[`broker`,`list`]]}),s()}}),C=e=>{if(!b||f.trim().length===0)return;let t=h?_.trim():``;h&&t===``||S.mutate({kind:b,name:f.trim(),settings:e,...t===``?{}:{id:t},...x===void 0?{}:{addonId:x}})};return o(G,{title:`Add broker`,subtitle:`Register a message broker for exporters and automations.`,onClose:S.isPending?()=>{}:n,children:t(`div`,{className:`space-y-3`,children:[t(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Kind`}),o(`select`,{value:u,onChange:e=>d(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>o(`option`,{value:l(e),children:e.label},l(e)))})]}),t(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Name`}),o(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:`My Home Assistant`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),t(`div`,{className:`space-y-1 rounded border border-border px-3 py-2`,children:[t(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground`,children:[o(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked)}),`Restore a broker that was removed, under its original id`]}),h&&t(r,{children:[o(`input`,{type:`text`,value:_,onChange:e=>v(e.target.value),placeholder:`ha_004`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Devices remember the broker id they were discovered under, so restoring the original id reconnects them instead of needing re-discovery. An id that is still in use is refused.`})]})]}),S.isError&&o(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:S.error instanceof Error?S.error.message:String(S.error)}),b&&o(P,{kind:b,...x===void 0?{}:{addonId:x},onSubmit:C,onCancel:n,submitLabel:S.isPending?`Adding…`:`Add broker`,disabled:S.isPending}),f.trim().length===0&&o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter a name before saving.`}),h&&_.trim().length===0&&o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter the original id, or clear the checkbox to create a new broker.`})]})})}function q({broker:e,onClose:r,onDone:a}){let s=i(),c=g({id:e.id,addonId:e.addonId}),l=h({onSuccess:()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]}),s.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:e.id,addonId:e.addonId}}]}),a()}}),u=n(()=>{let e=c.data;return e&&typeof e==`object`?{...e}:{}},[c.data]);return o(G,{title:`Edit ${e.name}`,subtitle:`${B(e.kind)} · ${e.id}`,onClose:l.isPending?()=>{}:r,children:c.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[o(D,{className:`h-3.5 w-3.5 animate-spin`}),` Loading settings…`]}):c.isError?t(`div`,{className:`space-y-3`,children:[t(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[`Failed to load settings:`,` `,c.error instanceof Error?c.error.message:`Unknown error`]}),o(`div`,{className:`flex justify-end`,children:o(`button`,{type:`button`,onClick:r,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Close`})})]}):t(`div`,{className:`space-y-3`,children:[l.isError&&o(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:l.error instanceof Error?l.error.message:String(l.error)}),o(P,{kind:e.kind,addonId:e.addonId,initialValues:u,onSubmit:t=>{l.mutate({id:e.id,settings:t,addonId:e.addonId})},onCancel:r,submitLabel:l.isPending?`Saving…`:`Save`,disabled:l.isPending})]})})}function J({broker:e,onEdit:n}){let r=i(),s=_(),[c,l]=a(null),u=p({onSuccess:e=>l(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>l({ok:!1,error:e instanceof Error?e.message:String(e)})}),f=d({onSuccess:()=>{r.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),m=async()=>{await s({title:`Delete broker`,message:`Delete broker "${e.name}"? Integrations that depend on it will stop working.`,confirmLabel:`Delete`,variant:`danger`})&&f.mutate({id:e.id,addonId:e.addonId})};return t(`tr`,{className:`border-b border-border last:border-0`,children:[o(`td`,{className:`px-3 py-2 text-xs text-foreground font-medium`,children:e.name}),o(`td`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:B(e.kind)}),t(`td`,{className:`px-3 py-2`,children:[o(U,{status:e.status}),c&&o(`span`,{className:`ml-2 text-[10px] ${c.ok?`text-success`:`text-danger`}`,children:c.ok?`OK`:c.error??`failed`})]}),o(`td`,{className:`px-3 py-2`,children:t(`div`,{className:`flex items-center justify-end gap-1.5`,children:[t(`button`,{type:`button`,onClick:()=>u.mutate({id:e.id,addonId:e.addonId}),disabled:u.isPending,title:`Test connection`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10 disabled:opacity-50`,children:[u.isPending?o(D,{className:`h-3 w-3 animate-spin`}):o(E,{className:`h-3 w-3`}),`Test`]}),t(`button`,{type:`button`,onClick:()=>n(e),title:`Edit`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10`,children:[o(C,{className:`h-3 w-3`}),` Edit`]}),t(`button`,{type:`button`,onClick:()=>{m()},disabled:f.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded border border-danger/40 px-2 py-1 text-[11px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[f.isPending?o(D,{className:`h-3 w-3 animate-spin`}):o(ee,{className:`h-3 w-3`}),`Delete`]})]})})]})}function Y(){let e=v({}),r=u(),i=n(()=>W(e.data),[e.data]),[s,c]=a(!1),[l,d]=a(null),f=n(()=>{let e=new Map;for(let t of V(r.data))for(let n of t.kinds)e.set(`${t.addonId}::${n.kind}`,{addonId:t.addonId,kind:n.kind,label:n.label});for(let t of i)[...e.values()].some(e=>e.kind===t.kind)||e.set(`::${t.kind}`,{kind:t.kind,label:B(t.kind)});return[...e.values()]},[i,r.data]);return t(`div`,{className:`space-y-3`,children:[o(`div`,{className:`flex items-center justify-end`,children:t(`button`,{type:`button`,onClick:()=>c(!0),disabled:f.length===0,title:f.length===0?`No broker providers available`:void 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:cursor-not-allowed`,children:[o(w,{className:`h-3.5 w-3.5`}),` Add broker`]})}),o(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full min-w-[36rem] border-collapse`,children:[o(`thead`,{children:t(`tr`,{className:`border-b border-border bg-background/50`,children:[o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Name`}),o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Kind`}),o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Status`}),o(`th`,{className:`px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Actions`})]})}),t(`tbody`,{children:[e.isLoading&&o(`tr`,{children:t(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[o(D,{className:`inline h-4 w-4 animate-spin`}),` Loading brokers…`]})}),e.isError&&o(`tr`,{children:t(`td`,{colSpan:4,className:`px-3 py-4 text-center text-xs text-danger`,children:[`Failed to load brokers:`,` `,e.error instanceof Error?e.error.message:`Unknown error`]})}),!e.isLoading&&!e.isError&&i.length===0&&o(`tr`,{children:o(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`No brokers registered yet. Add one to publish device events for downstream automations.`})}),i.map(e=>o(J,{broker:e,onEdit:d},e.id))]})]})}),s&&o(K,{kinds:f,onClose:()=>c(!1),onDone:()=>c(!1)}),l&&o(q,{broker:l,onClose:()=>d(null),onDone:()=>d(null)})]})}var X=[{kind:`device-export`,tabId:`device-export`,title:`Device export`,subtitle:`Outbound exporters that publish CamStack devices to other ecosystems (HomeAssistant, HomeKit, Alexa, …).`,icon:R,emptyTitle:`No device-export providers installed`,emptyDescription:`Install an export addon (e.g. @camstack/addon-export-ha-mqtt) to surface your CamStack devices in HomeAssistant, HomeKit, …`,addLabel:`Add export`},{kind:`email`,tabId:`email`,title:`Email providers`,subtitle:`Outbound email relays used for magic-link login, notifications, and alerts (SMTP today, future SendGrid, …).`,icon:L,emptyTitle:`No email providers installed`,emptyDescription:`Install an email-provider addon (e.g. @camstack/addon-smtp) so the hub can deliver magic-link logins and notifications.`,addLabel:`Add email provider`},{kind:`broker`,tabId:`broker`,title:`Brokers`,subtitle:`Message brokers consumed by exporters and downstream automations (MQTT today, future Kafka, …).`,icon:T,emptyTitle:`No brokers installed`,emptyDescription:`Install a broker addon (e.g. @camstack/addon-mqtt-broker) to publish device events for downstream automations.`,addLabel:`Add broker`}];function Z(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e.name;if(typeof t==`string`)return t}return null}function Q(e){let t=e,n=t?.manifest;if(!n?.id)return null;let r=[];for(let e of n.capabilities??[]){let t=Z(e);t!==null&&r.push(t)}let i=n.packageDisplayName??n.name??n.id,a=t?.process?.state??null;return{addonId:n.id,displayName:i,isActive:a===`running`,packageName:n.packageName??`@camstack/addon-${n.id}`,capNames:r,processState:a}}function te(e,t){let n=new Set(t);return e.filter(e=>e.capNames.some(e=>n.has(e)))}function ne(e){for(let[t,n]of Object.entries(b))if(n===e)return t;return null}function re(e){return e===`running`?{label:`Running`,className:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`}:e===`crashed`||e===`failed`?{label:e===`failed`?`Failed`:`Crashed`,className:`bg-danger/15 text-danger`}:e===`stopped`||e===`disabled`?{label:`Stopped`,className:`bg-foreground-subtle/15 text-foreground-subtle`}:{label:e??`Unknown`,className:`bg-foreground-subtle/15 text-foreground-subtle`}}function $({label:e,className:t}){return o(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t}`,children:e})}function ie({addonId:e}){let{data:t,isLoading:n}=f({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=x.safeParse(t);if(!r.success)return null;let i=r.data;return o($,{label:`${i.brokerCount} broker${i.brokerCount===1?``:`s`}${i.connectedCount>0?` • ${i.connectedCount} connected`:``}`,className:`bg-primary/10 text-primary`})}function ae({addonId:e}){let{data:t,isLoading:n}=y({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=S.safeParse(t);if(!r.success)return null;let i=r.data,a=i.linkState===`linked`?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:i.linkState===`error`?`bg-danger/15 text-danger`:`bg-foreground-subtle/15 text-foreground-subtle`;return o($,{label:`${i.linkState} • ${i.exposedDeviceCount} exposed`,className:a})}function oe({kind:e,addonId:t}){return e===`broker`?o(ie,{addonId:t}):e===`device-export`?o(ae,{addonId:t}):null}function se({descriptor:e,rows:n,isLoading:i}){let a=ne(e.kind),l=e.kind===`device-export`,u=s(),d=O();return o(I,{title:e.title,subtitle:e.subtitle,pageIcon:e.icon,itemIcon:e.icon,capability:a??e.kind,installButtonLabel:e.addLabel,items:n,isLoading:i,emptyTitle:e.emptyTitle,emptyDescription:e.emptyDescription,renderStatusBadges:n=>{let i=re(n.processState);return t(r,{children:[o($,{label:i.label,className:i.className}),o(oe,{kind:e.kind,addonId:n.addonId})]})},renderExpandedPanel:l?e=>o(c,{addonId:e.addonId,trpc:u.trpcClient,onOpenDevice:e=>d(`/devices/${e}`)}):void 0,showChrome:!0})}function ce(){let e=l(void 0,{refetchInterval:1e4}),t=(e.data??[]).map(Q).filter(e=>e!==null);return o(M,{icon:j,title:`External systems`,subtitle:`External systems this hub talks to — device exporters, email relays, and message brokers. Settings, Logs and Events are docked under every provider.`,children:o(N,{tabs:X.map(n=>{let r=Object.entries(b).filter(([,e])=>e===n.kind).map(([e])=>e),i=n.kind===`broker`?o(Y,{}):o(se,{descriptor:n,rows:te(t,r),isLoading:e.isLoading});return{id:n.tabId,label:n.title,icon:n.icon,content:i}})})})}export{ce as IntegrationsPage};
1
+ import{Q as e,S as t,W as n,b as r,o as i,q as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as s}from"./player-overlays-BrCS3AFF.js";import{C as c,On as l,dr as u,fr as d,lr as f,mr as p,or as m,pr as h,sr as g,un as _,ur as v,yr as y}from"./src-CTpgEWRF.js";import{H as b,dt as x,st as S}from"./src-Db_n2ue2.js";import{t as C}from"./pencil-BF1cI2bF.js";import{t as w}from"./plus-BNmythl0.js";import{t as T}from"./radio-BWOwFRH2.js";import{t as E}from"./wifi-ywTK10OM.js";import{C as D,J as O,K as k,o as ee,r as A,v as j}from"./index-BWNViBw0.js";import{t as M}from"./AdminPage-CCD07UMs.js";import{t as N}from"./AdminTabs-CR-73Caj.js";import{t as P}from"./BrokerForm-5ka8xuo5.js";import{t as F}from"./useBodyScrollLock-BDocajQE.js";import{t as I}from"./AddonCollectionPage-DH55gIbE.js";var L=k(`mail`,[[`path`,{d:`m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7`,key:`132q7q`}],[`rect`,{x:`2`,y:`4`,width:`20`,height:`16`,rx:`2`,key:`izxlao`}]]),R=k(`share-2`,[[`circle`,{cx:`18`,cy:`5`,r:`3`,key:`gq8acd`}],[`circle`,{cx:`6`,cy:`12`,r:`3`,key:`w7nqdw`}],[`circle`,{cx:`18`,cy:`19`,r:`3`,key:`1xt0gg`}],[`line`,{x1:`8.59`,x2:`15.42`,y1:`13.51`,y2:`17.49`,key:`47mynk`}],[`line`,{x1:`15.41`,x2:`8.59`,y1:`6.51`,y2:`10.49`,key:`1n3mei`}]]);e();var z={"home-assistant":`Home Assistant`,mqtt:`MQTT`};function B(e){return z[e]??e}function V(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var H={connected:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,connecting:`bg-amber-500/15 text-amber-700 dark:text-amber-300`,disconnected:`bg-foreground-subtle/15 text-foreground-subtle`,"auth-failed":`bg-danger/15 text-danger`,unreachable:`bg-danger/15 text-danger`,error:`bg-danger/15 text-danger`};function U({status:e}){return o(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${H[e]}`,children:e})}function W(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function G({title:e,subtitle:n,onClose:r,children:i}){return F(),o(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,children:t(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[t(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[t(`div`,{className:`space-y-0.5`,children:[o(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),n&&o(`p`,{className:`text-xs text-foreground-subtle`,children:n})]}),o(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,children:o(A,{className:`h-4 w-4`})})]}),o(`div`,{className:`p-4 max-h-[70vh] overflow-y-auto overscroll-contain`,children:i})]})})}function K({kinds:e,onClose:n,onDone:s}){let c=i(),l=e=>`${e.addonId??``}::${e.kind}`,[u,d]=a(e[0]?l(e[0]):``),[f,p]=a(``),[h,g]=a(!1),[_,v]=a(``),y=e.find(e=>l(e)===u)??e[0],b=y?.kind??``,x=y?.addonId,S=m({onSuccess:()=>{c.invalidateQueries({queryKey:[[`broker`,`list`]]}),s()}}),C=e=>{if(!b||f.trim().length===0)return;let t=h?_.trim():``;h&&t===``||S.mutate({kind:b,name:f.trim(),settings:e,...t===``?{}:{id:t},...x===void 0?{}:{addonId:x}})};return o(G,{title:`Add broker`,subtitle:`Register a message broker for exporters and automations.`,onClose:S.isPending?()=>{}:n,children:t(`div`,{className:`space-y-3`,children:[t(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Kind`}),o(`select`,{value:u,onChange:e=>d(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>o(`option`,{value:l(e),children:e.label},l(e)))})]}),t(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Name`}),o(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:`My Home Assistant`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),t(`div`,{className:`space-y-1 rounded border border-border px-3 py-2`,children:[t(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground`,children:[o(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked)}),`Restore a broker that was removed, under its original id`]}),h&&t(r,{children:[o(`input`,{type:`text`,value:_,onChange:e=>v(e.target.value),placeholder:`ha_004`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Devices remember the broker id they were discovered under, so restoring the original id reconnects them instead of needing re-discovery. An id that is still in use is refused.`})]})]}),S.isError&&o(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:S.error instanceof Error?S.error.message:String(S.error)}),b&&o(P,{kind:b,...x===void 0?{}:{addonId:x},onSubmit:C,onCancel:n,submitLabel:S.isPending?`Adding…`:`Add broker`,disabled:S.isPending}),f.trim().length===0&&o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter a name before saving.`}),h&&_.trim().length===0&&o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter the original id, or clear the checkbox to create a new broker.`})]})})}function q({broker:e,onClose:r,onDone:a}){let s=i(),c=g({id:e.id,addonId:e.addonId}),l=h({onSuccess:()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]}),s.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:e.id,addonId:e.addonId}}]}),a()}}),u=n(()=>{let e=c.data;return e&&typeof e==`object`?{...e}:{}},[c.data]);return o(G,{title:`Edit ${e.name}`,subtitle:`${B(e.kind)} · ${e.id}`,onClose:l.isPending?()=>{}:r,children:c.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[o(D,{className:`h-3.5 w-3.5 animate-spin`}),` Loading settings…`]}):c.isError?t(`div`,{className:`space-y-3`,children:[t(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[`Failed to load settings:`,` `,c.error instanceof Error?c.error.message:`Unknown error`]}),o(`div`,{className:`flex justify-end`,children:o(`button`,{type:`button`,onClick:r,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Close`})})]}):t(`div`,{className:`space-y-3`,children:[l.isError&&o(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:l.error instanceof Error?l.error.message:String(l.error)}),o(P,{kind:e.kind,addonId:e.addonId,initialValues:u,onSubmit:t=>{l.mutate({id:e.id,settings:t,addonId:e.addonId})},onCancel:r,submitLabel:l.isPending?`Saving…`:`Save`,disabled:l.isPending})]})})}function J({broker:e,onEdit:n}){let r=i(),s=_(),[c,l]=a(null),u=p({onSuccess:e=>l(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>l({ok:!1,error:e instanceof Error?e.message:String(e)})}),f=d({onSuccess:()=>{r.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),m=async()=>{await s({title:`Delete broker`,message:`Delete broker "${e.name}"? Integrations that depend on it will stop working.`,confirmLabel:`Delete`,variant:`danger`})&&f.mutate({id:e.id,addonId:e.addonId})};return t(`tr`,{className:`border-b border-border last:border-0`,children:[o(`td`,{className:`px-3 py-2 text-xs text-foreground font-medium`,children:e.name}),o(`td`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:B(e.kind)}),t(`td`,{className:`px-3 py-2`,children:[o(U,{status:e.status}),c&&o(`span`,{className:`ml-2 text-[10px] ${c.ok?`text-success`:`text-danger`}`,children:c.ok?`OK`:c.error??`failed`})]}),o(`td`,{className:`px-3 py-2`,children:t(`div`,{className:`flex items-center justify-end gap-1.5`,children:[t(`button`,{type:`button`,onClick:()=>u.mutate({id:e.id,addonId:e.addonId}),disabled:u.isPending,title:`Test connection`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10 disabled:opacity-50`,children:[u.isPending?o(D,{className:`h-3 w-3 animate-spin`}):o(E,{className:`h-3 w-3`}),`Test`]}),t(`button`,{type:`button`,onClick:()=>n(e),title:`Edit`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10`,children:[o(C,{className:`h-3 w-3`}),` Edit`]}),t(`button`,{type:`button`,onClick:()=>{m()},disabled:f.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded border border-danger/40 px-2 py-1 text-[11px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[f.isPending?o(D,{className:`h-3 w-3 animate-spin`}):o(ee,{className:`h-3 w-3`}),`Delete`]})]})})]})}function Y(){let e=v({}),r=u(),i=n(()=>W(e.data),[e.data]),[s,c]=a(!1),[l,d]=a(null),f=n(()=>{let e=new Map;for(let t of V(r.data))for(let n of t.kinds)e.set(`${t.addonId}::${n.kind}`,{addonId:t.addonId,kind:n.kind,label:n.label});for(let t of i)[...e.values()].some(e=>e.kind===t.kind)||e.set(`::${t.kind}`,{kind:t.kind,label:B(t.kind)});return[...e.values()]},[i,r.data]);return t(`div`,{className:`space-y-3`,children:[o(`div`,{className:`flex items-center justify-end`,children:t(`button`,{type:`button`,onClick:()=>c(!0),disabled:f.length===0,title:f.length===0?`No broker providers available`:void 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:cursor-not-allowed`,children:[o(w,{className:`h-3.5 w-3.5`}),` Add broker`]})}),o(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full min-w-[36rem] border-collapse`,children:[o(`thead`,{children:t(`tr`,{className:`border-b border-border bg-background/50`,children:[o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Name`}),o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Kind`}),o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Status`}),o(`th`,{className:`px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Actions`})]})}),t(`tbody`,{children:[e.isLoading&&o(`tr`,{children:t(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[o(D,{className:`inline h-4 w-4 animate-spin`}),` Loading brokers…`]})}),e.isError&&o(`tr`,{children:t(`td`,{colSpan:4,className:`px-3 py-4 text-center text-xs text-danger`,children:[`Failed to load brokers:`,` `,e.error instanceof Error?e.error.message:`Unknown error`]})}),!e.isLoading&&!e.isError&&i.length===0&&o(`tr`,{children:o(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`No brokers registered yet. Add one to publish device events for downstream automations.`})}),i.map(e=>o(J,{broker:e,onEdit:d},e.id))]})]})}),s&&o(K,{kinds:f,onClose:()=>c(!1),onDone:()=>c(!1)}),l&&o(q,{broker:l,onClose:()=>d(null),onDone:()=>d(null)})]})}var X=[{kind:`device-export`,tabId:`device-export`,title:`Device export`,subtitle:`Outbound exporters that publish CamStack devices to other ecosystems (HomeAssistant, HomeKit, Alexa, …).`,icon:R,emptyTitle:`No device-export providers installed`,emptyDescription:`Install an export addon (e.g. @camstack/addon-export-ha-mqtt) to surface your CamStack devices in HomeAssistant, HomeKit, …`,addLabel:`Add export`},{kind:`email`,tabId:`email`,title:`Email providers`,subtitle:`Outbound email relays used for magic-link login, notifications, and alerts (SMTP today, future SendGrid, …).`,icon:L,emptyTitle:`No email providers installed`,emptyDescription:`Install an email-provider addon (e.g. @camstack/addon-smtp) so the hub can deliver magic-link logins and notifications.`,addLabel:`Add email provider`},{kind:`broker`,tabId:`broker`,title:`Brokers`,subtitle:`Message brokers consumed by exporters and downstream automations (MQTT today, future Kafka, …).`,icon:T,emptyTitle:`No brokers installed`,emptyDescription:`Install a broker addon (e.g. @camstack/addon-mqtt-broker) to publish device events for downstream automations.`,addLabel:`Add broker`}];function Z(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e.name;if(typeof t==`string`)return t}return null}function Q(e){let t=e,n=t?.manifest;if(!n?.id)return null;let r=[];for(let e of n.capabilities??[]){let t=Z(e);t!==null&&r.push(t)}let i=n.packageDisplayName??n.name??n.id,a=t?.process?.state??null;return{addonId:n.id,displayName:i,isActive:a===`running`,packageName:n.packageName??`@camstack/addon-${n.id}`,capNames:r,processState:a}}function te(e,t){let n=new Set(t);return e.filter(e=>e.capNames.some(e=>n.has(e)))}function ne(e){for(let[t,n]of Object.entries(b))if(n===e)return t;return null}function re(e){return e===`running`?{label:`Running`,className:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`}:e===`crashed`||e===`failed`?{label:e===`failed`?`Failed`:`Crashed`,className:`bg-danger/15 text-danger`}:e===`stopped`||e===`disabled`?{label:`Stopped`,className:`bg-foreground-subtle/15 text-foreground-subtle`}:{label:e??`Unknown`,className:`bg-foreground-subtle/15 text-foreground-subtle`}}function $({label:e,className:t}){return o(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t}`,children:e})}function ie({addonId:e}){let{data:t,isLoading:n}=f({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=x.safeParse(t);if(!r.success)return null;let i=r.data;return o($,{label:`${i.brokerCount} broker${i.brokerCount===1?``:`s`}${i.connectedCount>0?` • ${i.connectedCount} connected`:``}`,className:`bg-primary/10 text-primary`})}function ae({addonId:e}){let{data:t,isLoading:n}=y({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=S.safeParse(t);if(!r.success)return null;let i=r.data,a=i.linkState===`linked`?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:i.linkState===`error`?`bg-danger/15 text-danger`:`bg-foreground-subtle/15 text-foreground-subtle`;return o($,{label:`${i.linkState} • ${i.exposedDeviceCount} exposed`,className:a})}function oe({kind:e,addonId:t}){return e===`broker`?o(ie,{addonId:t}):e===`device-export`?o(ae,{addonId:t}):null}function se({descriptor:e,rows:n,isLoading:i}){let a=ne(e.kind),l=e.kind===`device-export`,u=s(),d=O();return o(I,{title:e.title,subtitle:e.subtitle,pageIcon:e.icon,itemIcon:e.icon,capability:a??e.kind,installButtonLabel:e.addLabel,items:n,isLoading:i,emptyTitle:e.emptyTitle,emptyDescription:e.emptyDescription,renderStatusBadges:n=>{let i=re(n.processState);return t(r,{children:[o($,{label:i.label,className:i.className}),o(oe,{kind:e.kind,addonId:n.addonId})]})},renderExpandedPanel:l?e=>o(c,{addonId:e.addonId,trpc:u.trpcClient,onOpenDevice:e=>d(`/devices/${e}`)}):void 0,showChrome:!0})}function ce(){let e=l(void 0,{refetchInterval:1e4}),t=(e.data??[]).map(Q).filter(e=>e!==null);return o(M,{icon:j,title:`External systems`,subtitle:`External systems this hub talks to — device exporters, email relays, and message brokers. Settings, Logs and Events are docked under every provider.`,children:o(N,{tabs:X.map(n=>{let r=Object.entries(b).filter(([,e])=>e===n.kind).map(([e])=>e),i=n.kind===`broker`?o(Y,{}):o(se,{descriptor:n,rows:te(t,r),isLoading:e.isLoading});return{id:n.tabId,label:n.title,icon:n.icon,content:i}})})})}export{ce as IntegrationsPage};
@@ -1 +1 @@
1
- import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as l}from"./player-overlays-C82v-qwN.js";import{Hr as u,Si as d,T as f,_n as ee,br as p,gi as m,i as h,jr as g,tn as _,w as v,yi as y}from"./src-BZXGF7UJ.js";import{t as b}from"./ProviderIcon-CQ3zBUuC.js";import{t as x}from"./plus-Df153AO8.js";import{i as S,n as te,r as C,t as w}from"./ScanNetworkModal-usrCXDoI.js";import{t as ne}from"./refresh-cw-MvTOb710.js";import{C as re,I as T,J as E,R as D,V as O,X as k,f as A,r as j,t as M,v as N,z as ie}from"./index-JUF-VzOE.js";import{t as ae}from"./AdminPage-CCD07UMs.js";import"./useEventInvalidation-BYeF1CRq.js";import{t as P}from"./StatusBadge-CeptlsPG.js";import{t as F}from"./useBodyScrollLock-BDocajQE.js";t();function I(e,t){let[n,r]=o(!1);return c(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}t();function L({providerId:e,onImport:t,onSkip:r}){let{t:i}=M(),[a,l]=o(new Set),u=g(),d=u.data,f=u.isPending||!u.data&&!u.isError;c(()=>{e&&(u.isPending||u.data||u.mutate({addonId:e}))},[e,u]);function ee(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(f)return n(`div`,{className:`flex flex-col items-center py-12`,children:[s(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),s(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:i(`integrations.searchingDevices`)})]});let p=d??[];return n(`div`,{className:`space-y-4`,children:[s(`p`,{className:`text-xs text-foreground-subtle`,children:p.length>0?i(`integrations.foundDevices`,{count:p.length}):i(`integrations.noDevicesFound`)}),p.length>0&&s(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:p.map(e=>{let t=e.stableId,r=e.suggestedName??t,i=a.has(t);return n(`button`,{onClick:()=>ee(t),className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${i?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[s(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${i?`border-primary bg-primary`:`border-border`}`,children:i&&s(ie,{className:`h-3 w-3 text-primary-foreground`})}),s(O,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),s(`span`,{className:`text-xs font-medium text-foreground truncate`,children:r})]},t)})}),n(`div`,{className:`flex items-center justify-between pt-2`,children:[s(`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.skip`)}),p.length>0&&n(`button`,{onClick:()=>t(Array.from(a)),disabled:a.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[i(`integrations.importSelected`),` (`,a.size,`)`]})]})]})}function R({onSelect:e,onClose:t,pendingAddonId:r=null}){let{t:i}=M(),a=E(),{data:o,isLoading:c}=y();if(c)return s(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-14 rounded-lg bg-surface animate-pulse`},e))});let l=r!==null;return n(`div`,{className:`space-y-2`,children:[(o??[]).map(o=>{let c=o.instanceMode===`unique`&&o.existingInstances.length>0,u=r===o.addonId,d=l;return n(`button`,{disabled:d,onClick:()=>{if(!d)if(c){let e=o.existingInstances[0].id;t(),a(`/integrations/${e}`)}else e(o.addonId,o.instanceMode,o.discoveryMode,o.name,o.kind,o.brokerKind,o.mode,o.canTest)},className:`flex w-full items-center gap-3 rounded-lg border border-border bg-surface p-3 text-left hover:border-foreground-subtle/30 transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[o.iconUrl?s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`img`,{src:o.iconUrl,alt:``,className:`h-5 w-5`})}):s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`span`,{className:`text-sm`,style:{color:o.color},children:`◉`})}),n(`div`,{className:`flex-1 min-w-0`,children:[s(`p`,{className:`text-xs font-semibold text-foreground`,children:o.name}),o.description&&s(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 truncate`,children:o.description})]}),u?s(re,{className:`h-4 w-4 animate-spin text-primary flex-shrink-0`}):c?n(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[s(A,{className:`h-3 w-3`}),i(`integrations.manage`)]}):s(T,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},o.addonId)}),(o??[]).length===0&&s(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:i(`integrations.noProviders`)})]})}t();function oe(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}var z=2e4;function se({open:e,onClose:t}){let{t:l}=M(),u=E(),d=a(),[f,h]=o(`picker`),[_,v]=o(null),[y,b]=o(null),[x,S]=o(`manual`),[w,ne]=o(null),[T,D]=o(``),[O,k]=o(null),[A,N]=o(null),[ie,ae]=o(!1),{data:P}=ee({addonId:_??``,nodeId:`hub`},{enabled:_!=null}),se=r(()=>P?oe(P):null,[P]),B=m({onSuccess:()=>d.invalidateQueries({queryKey:[[`integrations`]]})}),V=g(),ce=V.data;c(()=>{f!==`discovery`||!y||!_||V.isPending||V.data||V.mutate({addonId:_})},[f,y,_,V]);let H=p({onSuccess:()=>d.invalidateQueries({queryKey:[[`deviceManager`]]})});function U(e,t,n,r,i,a,o,s){if(!B.isPending){if(v(e),ae(s),S(n),D(r),N(null),o===`broker`){if(!a){N(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}ne(a),h(`broker`);return}if(o===`account`){h(`config`);return}W(e,r)}}async function W(e,n){try{let r=await B.mutateAsync({addonId:e,name:n,settings:{}});t(),J(),u(`/integrations/${r.id}?add=1`)}catch{}}async function G(e){if(_)try{let t=await B.mutateAsync({addonId:_,name:e.name,settings:e.config});b(t.id),x===`auto`||x===`both`?h(`discovery`):q(t.id)}catch{}}async function K(e){if(_)try{let t=await B.mutateAsync({addonId:_,name:T,settings:{brokerId:e}});k(t.id),b(t.id),q(t.id)}catch{}}async function le(e){if(_){for(let t of e){let e=ce?.find(e=>e.stableId===t);e&&await H.mutateAsync({addonId:_,candidate:e,...O===null?{}:{integrationId:O}})}q()}}function q(e){let n=e??y??_;t(),J(),n&&u(`/integrations/${n}`)}function J(){h(`picker`),v(null),b(null),S(`manual`),ne(null),D(``),k(null),N(null),ae(!1)}function Y(){t(),J()}F(e);let X=B.isPending,Z=I(X,z);if(!e)return null;let Q={picker:l(`integrations.newIntegration`),config:l(`integrations.configureIntegration`),discovery:l(`integrations.importDevices`),broker:l(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},ue=X?_:null,$=B.error,de=X&&!Z;return n(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:de?void 0:Y}),n(`div`,{className:`relative z-10 w-full max-w-lg max-h-[calc(85dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[n(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:Q[f]}),s(`button`,{onClick:Y,disabled:de,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:s(j,{className:`h-4 w-4`})})]}),n(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[$&&!X&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:$ instanceof Error?$.message:String($)}),f===`picker`&&n(i,{children:[A&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:A}),s(R,{onSelect:U,onClose:Y,pendingAddonId:ue})]}),f===`config`&&_&&s(te,{addonId:_,configSchema:se??null,canTest:ie,onSave:G,onBack:()=>h(`picker`)}),f===`broker`&&w&&s(C,{kind:w,onResolved:e=>{K(e)},onBack:()=>h(`picker`)}),f===`discovery`&&y&&s(L,{providerId:y,onImport:le,onSkip:q})]}),X&&n(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm px-6 text-center`,children:[s(re,{className:`h-6 w-6 animate-spin text-primary`}),s(`p`,{className:`text-xs font-medium text-foreground`,children:l(`integrations.creating`,{defaultValue:`Creating integration…`})}),!Z&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:l(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),Z&&n(i,{children:[s(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:l(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),s(`button`,{onClick:Y,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:l(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})]})}function B({integration:e,expanded:t,onToggleExpand:r}){return n(`div`,{className:`flex items-center gap-2.5`,children:[s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e.addonId)},"aria-label":t?`Collapse`:`Expand`,"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:s(t?D:T,{className:`h-3.5 w-3.5`})}),s(b,{type:e.addonId,size:`sm`}),n(`div`,{className:`flex min-w-0 flex-col`,children:[s(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),s(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function V(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>s(B,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:`Devices`,headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>`${e.deviceCount} device${e.deviceCount===1?``:`s`}`},{key:`status`,header:`Status`,headerClassName:`w-[15%]`,cell:e=>s(P,{status:e.status})}]}t();function ce(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var H=`expand`;function U(){let{t}=M(),a=E(),c=l(),[ee]=k(),[p,m]=o(!1),g=e(()=>m(!0),[]),y=e(()=>m(!1),[]),[te,C]=o(!1),re=e(()=>C(!0),[]),T=e(()=>C(!1),[]);h([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),h([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:D,isLoading:O,refetch:A}=d(void 0),{data:j,isLoading:ie,refetch:P}=u({projection:`slim`}),F=r(()=>j??[],[j]),I=r(()=>D??[],[D]),L=r(()=>{let e=new Map;for(let t of F)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[F]),R=r(()=>{let e=new Map;for(let t of f(F)){let n=t.addonId??``;n&&e.set(n,(e.get(n)??0)+1)}return e},[F]),oe=r(()=>I.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:ce(e),deviceCount:R.get(e.addonId)??0})),[I,R]),z=ee.get(H),B=e(e=>{let t=new URLSearchParams(window.location.search);t.get(H)===e?t.delete(H):t.set(H,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),U=e(e=>a(`/integrations/${e.id}`),[a]),W=e(e=>L.get(e)??null,[L]),G=e(e=>s(b,{type:e,size:`sm`}),[]),K=e(e=>a(`/devices/${String(e)}`),[a]),le=e(e=>s(v,{context:`integration-detail`,devices:F,trpc:c.trpcClient,forceAddon:e.addonId,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:G,resolveParent:W,onNavigate:K}),[F,c.trpcClient,G,W,K]),q=e(e=>z===e.addonId,[z]),J=r(()=>V({isExpanded:q,onToggleExpand:B}),[q,B]),Y=e(e=>`${e.name} ${e.addonId}`,[]),X=e(e=>e.addonId,[]),Z=e(()=>{A(),P()},[A,P]),Q=O||ie,ue=I.length>0;return n(ae,{icon:N,title:t(`nav.integrations`,`Integrations`),actions:n(i,{children:[s(`button`,{onClick:Z,disabled:Q,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:`Refresh`,children:s(ne,{className:_(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),n(`button`,{onClick:re,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the local network for devices`,children:[s(S,{className:`h-3.5 w-3.5`}),`Scan network`]}),n(`button`,{onClick:g,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[s(x,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[Q&&s(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!ue&&n(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[s(`p`,{className:`text-sm`,children:`No integrations configured.`}),s(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!Q&&ue&&s(v,{mode:`generic`,items:oe,getKey:X,getSearchText:Y,columns:J,onRowClick:U,isExpanded:q,renderExpanded:le,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),s(se,{open:p,onClose:y}),s(w,{open:te,onClose:T})]})}export{U as IntegrationsPage};
1
+ import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as l}from"./player-overlays-BrCS3AFF.js";import{Hr as u,Si as d,T as f,_n as ee,br as p,gi as m,i as h,jr as g,tn as _,w as v,yi as y}from"./src-CTpgEWRF.js";import{t as b}from"./ProviderIcon-CvKyMo33.js";import{t as x}from"./plus-BNmythl0.js";import{i as S,n as te,r as C,t as w}from"./ScanNetworkModal-lm518Ul1.js";import{t as ne}from"./refresh-cw-D7w1H6wV.js";import{C as re,I as T,J as E,R as D,V as O,X as k,f as A,r as j,t as M,v as N,z as ie}from"./index-BWNViBw0.js";import{t as ae}from"./AdminPage-CCD07UMs.js";import"./useEventInvalidation-DI7nUUUv.js";import{t as P}from"./StatusBadge-CeptlsPG.js";import{t as F}from"./useBodyScrollLock-BDocajQE.js";t();function I(e,t){let[n,r]=o(!1);return c(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}t();function L({providerId:e,onImport:t,onSkip:r}){let{t:i}=M(),[a,l]=o(new Set),u=g(),d=u.data,f=u.isPending||!u.data&&!u.isError;c(()=>{e&&(u.isPending||u.data||u.mutate({addonId:e}))},[e,u]);function ee(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(f)return n(`div`,{className:`flex flex-col items-center py-12`,children:[s(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),s(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:i(`integrations.searchingDevices`)})]});let p=d??[];return n(`div`,{className:`space-y-4`,children:[s(`p`,{className:`text-xs text-foreground-subtle`,children:p.length>0?i(`integrations.foundDevices`,{count:p.length}):i(`integrations.noDevicesFound`)}),p.length>0&&s(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:p.map(e=>{let t=e.stableId,r=e.suggestedName??t,i=a.has(t);return n(`button`,{onClick:()=>ee(t),className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${i?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[s(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${i?`border-primary bg-primary`:`border-border`}`,children:i&&s(ie,{className:`h-3 w-3 text-primary-foreground`})}),s(O,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),s(`span`,{className:`text-xs font-medium text-foreground truncate`,children:r})]},t)})}),n(`div`,{className:`flex items-center justify-between pt-2`,children:[s(`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.skip`)}),p.length>0&&n(`button`,{onClick:()=>t(Array.from(a)),disabled:a.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[i(`integrations.importSelected`),` (`,a.size,`)`]})]})]})}function R({onSelect:e,onClose:t,pendingAddonId:r=null}){let{t:i}=M(),a=E(),{data:o,isLoading:c}=y();if(c)return s(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-14 rounded-lg bg-surface animate-pulse`},e))});let l=r!==null;return n(`div`,{className:`space-y-2`,children:[(o??[]).map(o=>{let c=o.instanceMode===`unique`&&o.existingInstances.length>0,u=r===o.addonId,d=l;return n(`button`,{disabled:d,onClick:()=>{if(!d)if(c){let e=o.existingInstances[0].id;t(),a(`/integrations/${e}`)}else e(o.addonId,o.instanceMode,o.discoveryMode,o.name,o.kind,o.brokerKind,o.mode,o.canTest)},className:`flex w-full items-center gap-3 rounded-lg border border-border bg-surface p-3 text-left hover:border-foreground-subtle/30 transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[o.iconUrl?s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`img`,{src:o.iconUrl,alt:``,className:`h-5 w-5`})}):s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`span`,{className:`text-sm`,style:{color:o.color},children:`◉`})}),n(`div`,{className:`flex-1 min-w-0`,children:[s(`p`,{className:`text-xs font-semibold text-foreground`,children:o.name}),o.description&&s(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 truncate`,children:o.description})]}),u?s(re,{className:`h-4 w-4 animate-spin text-primary flex-shrink-0`}):c?n(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[s(A,{className:`h-3 w-3`}),i(`integrations.manage`)]}):s(T,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},o.addonId)}),(o??[]).length===0&&s(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:i(`integrations.noProviders`)})]})}t();function oe(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}var z=2e4;function se({open:e,onClose:t}){let{t:l}=M(),u=E(),d=a(),[f,h]=o(`picker`),[_,v]=o(null),[y,b]=o(null),[x,S]=o(`manual`),[w,ne]=o(null),[T,D]=o(``),[O,k]=o(null),[A,N]=o(null),[ie,ae]=o(!1),{data:P}=ee({addonId:_??``,nodeId:`hub`},{enabled:_!=null}),se=r(()=>P?oe(P):null,[P]),B=m({onSuccess:()=>d.invalidateQueries({queryKey:[[`integrations`]]})}),V=g(),ce=V.data;c(()=>{f!==`discovery`||!y||!_||V.isPending||V.data||V.mutate({addonId:_})},[f,y,_,V]);let H=p({onSuccess:()=>d.invalidateQueries({queryKey:[[`deviceManager`]]})});function U(e,t,n,r,i,a,o,s){if(!B.isPending){if(v(e),ae(s),S(n),D(r),N(null),o===`broker`){if(!a){N(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}ne(a),h(`broker`);return}if(o===`account`){h(`config`);return}W(e,r)}}async function W(e,n){try{let r=await B.mutateAsync({addonId:e,name:n,settings:{}});t(),J(),u(`/integrations/${r.id}?add=1`)}catch{}}async function G(e){if(_)try{let t=await B.mutateAsync({addonId:_,name:e.name,settings:e.config});b(t.id),x===`auto`||x===`both`?h(`discovery`):q(t.id)}catch{}}async function K(e){if(_)try{let t=await B.mutateAsync({addonId:_,name:T,settings:{brokerId:e}});k(t.id),b(t.id),q(t.id)}catch{}}async function le(e){if(_){for(let t of e){let e=ce?.find(e=>e.stableId===t);e&&await H.mutateAsync({addonId:_,candidate:e,...O===null?{}:{integrationId:O}})}q()}}function q(e){let n=e??y??_;t(),J(),n&&u(`/integrations/${n}`)}function J(){h(`picker`),v(null),b(null),S(`manual`),ne(null),D(``),k(null),N(null),ae(!1)}function Y(){t(),J()}F(e);let X=B.isPending,Z=I(X,z);if(!e)return null;let Q={picker:l(`integrations.newIntegration`),config:l(`integrations.configureIntegration`),discovery:l(`integrations.importDevices`),broker:l(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},ue=X?_:null,$=B.error,de=X&&!Z;return n(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:de?void 0:Y}),n(`div`,{className:`relative z-10 w-full max-w-lg max-h-[calc(85dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[n(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:Q[f]}),s(`button`,{onClick:Y,disabled:de,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:s(j,{className:`h-4 w-4`})})]}),n(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[$&&!X&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:$ instanceof Error?$.message:String($)}),f===`picker`&&n(i,{children:[A&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:A}),s(R,{onSelect:U,onClose:Y,pendingAddonId:ue})]}),f===`config`&&_&&s(te,{addonId:_,configSchema:se??null,canTest:ie,onSave:G,onBack:()=>h(`picker`)}),f===`broker`&&w&&s(C,{kind:w,onResolved:e=>{K(e)},onBack:()=>h(`picker`)}),f===`discovery`&&y&&s(L,{providerId:y,onImport:le,onSkip:q})]}),X&&n(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm px-6 text-center`,children:[s(re,{className:`h-6 w-6 animate-spin text-primary`}),s(`p`,{className:`text-xs font-medium text-foreground`,children:l(`integrations.creating`,{defaultValue:`Creating integration…`})}),!Z&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:l(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),Z&&n(i,{children:[s(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:l(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),s(`button`,{onClick:Y,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:l(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})]})}function B({integration:e,expanded:t,onToggleExpand:r}){return n(`div`,{className:`flex items-center gap-2.5`,children:[s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e.addonId)},"aria-label":t?`Collapse`:`Expand`,"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:s(t?D:T,{className:`h-3.5 w-3.5`})}),s(b,{type:e.addonId,size:`sm`}),n(`div`,{className:`flex min-w-0 flex-col`,children:[s(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),s(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function V(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>s(B,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:`Devices`,headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>`${e.deviceCount} device${e.deviceCount===1?``:`s`}`},{key:`status`,header:`Status`,headerClassName:`w-[15%]`,cell:e=>s(P,{status:e.status})}]}t();function ce(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var H=`expand`;function U(){let{t}=M(),a=E(),c=l(),[ee]=k(),[p,m]=o(!1),g=e(()=>m(!0),[]),y=e(()=>m(!1),[]),[te,C]=o(!1),re=e(()=>C(!0),[]),T=e(()=>C(!1),[]);h([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),h([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:D,isLoading:O,refetch:A}=d(void 0),{data:j,isLoading:ie,refetch:P}=u({projection:`slim`}),F=r(()=>j??[],[j]),I=r(()=>D??[],[D]),L=r(()=>{let e=new Map;for(let t of F)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[F]),R=r(()=>{let e=new Map;for(let t of f(F)){let n=t.addonId??``;n&&e.set(n,(e.get(n)??0)+1)}return e},[F]),oe=r(()=>I.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:ce(e),deviceCount:R.get(e.addonId)??0})),[I,R]),z=ee.get(H),B=e(e=>{let t=new URLSearchParams(window.location.search);t.get(H)===e?t.delete(H):t.set(H,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),U=e(e=>a(`/integrations/${e.id}`),[a]),W=e(e=>L.get(e)??null,[L]),G=e(e=>s(b,{type:e,size:`sm`}),[]),K=e(e=>a(`/devices/${String(e)}`),[a]),le=e(e=>s(v,{context:`integration-detail`,devices:F,trpc:c.trpcClient,forceAddon:e.addonId,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:G,resolveParent:W,onNavigate:K}),[F,c.trpcClient,G,W,K]),q=e(e=>z===e.addonId,[z]),J=r(()=>V({isExpanded:q,onToggleExpand:B}),[q,B]),Y=e(e=>`${e.name} ${e.addonId}`,[]),X=e(e=>e.addonId,[]),Z=e(()=>{A(),P()},[A,P]),Q=O||ie,ue=I.length>0;return n(ae,{icon:N,title:t(`nav.integrations`,`Integrations`),actions:n(i,{children:[s(`button`,{onClick:Z,disabled:Q,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:`Refresh`,children:s(ne,{className:_(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),n(`button`,{onClick:re,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the local network for devices`,children:[s(S,{className:`h-3.5 w-3.5`}),`Scan network`]}),n(`button`,{onClick:g,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[s(x,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[Q&&s(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!ue&&n(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[s(`p`,{className:`text-sm`,children:`No integrations configured.`}),s(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!Q&&ue&&s(v,{mode:`generic`,items:oe,getKey:X,getSearchText:Y,columns:J,onRowClick:U,isExpanded:q,renderExpanded:le,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),s(se,{open:p,onClose:y}),s(w,{open:te,onClose:T})]})}export{U as IntegrationsPage};
@@ -1 +1 @@
1
- import{Q as e,S as t,W as n,q as r,x as i}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{$o as a,J as o,On as s,ia as c,kn as l,ts as u}from"./src-BZXGF7UJ.js";import{t as d}from"./layers-BbTQR4Ts.js";import{C as f,G as p,K as m,V as h,m as g,s as _,t as v,z as y}from"./index-JUF-VzOE.js";import{t as b}from"./AdminPage-CCD07UMs.js";import{t as x}from"./AdminTabs-4zkj5XSp.js";import{t as S}from"./AddonCollectionPage-DWplp-oK.js";import{t as C}from"./addon-display-names-DvSEQty-.js";var w=m(`file-text`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),T=m(`timer-reset`,[[`path`,{d:`M10 2h4`,key:`n1abiw`}],[`path`,{d:`M12 14v-4`,key:`1evpnu`}],[`path`,{d:`M4 13a8 8 0 0 1 8-7 8 8 0 1 1-5.3 14L4 17.6`,key:`1ts96g`}],[`path`,{d:`M9 17H4v5`,key:`8t5av`}]]);e();var E=5e3,D={"winston-logging":`Rotated log files on this node’s disk.`,"console-logging":`stdout / stderr of the node process.`,"loki-logging":`Pushes to a Grafana Loki instance. Off until enabled with a URL.`,"hub-forwarder":`Agent-only — forwards this node’s entries to the hub.`};function O(){let e=l({capName:`log-destination`},{refetchInterval:E}),t=s(void 0,{refetchInterval:E}),r=n(()=>C(t.data??[]),[t.data]),a=n(()=>{let e=new Map;for(let n of t.data??[]){let t=n.description,r=n.id;typeof r==`string`&&typeof t==`string`&&t.length>0&&e.set(r,t)}return e},[t.data]);return i(S,{title:`Logging`,subtitle:`Every registered log destination. Entries are fanned to all enabled destinations at once — enabling one does not disable another. Each destination's own configuration is docked under it.`,pageIcon:g,itemIcon:w,capability:`log-destination`,installButtonLabel:`Add destination`,items:n(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:r.get(e.addonId)??e.addonId,isActive:e.isActive,caption:a.get(e.addonId)??D[e.addonId]??``})),[e.data,r,a]),isLoading:e.isLoading,emptyTitle:`No log destinations registered`,emptyDescription:`This should not happen — the console and rotated-file destinations are builtins. If the list is empty, the node is still booting.`,renderStatusBadges:e=>e.caption.length>0?i(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.caption}):null})}e();var k=[12e4,3e5,6e5,18e5],A={"request-census":`Counts every tRPC call by TRANSPORT PLANE — http, ws, mesh — and by procedure, caller, address and user-agent. Subscriptions are counted apart from calls, so a long-lived stream cannot pass for a storm. Arm it, then restart: the deadline is persisted, so the window is still running when clients reconnect.`};function j(){let{t:e}=v(),n=a({},{refetchInterval:5e3}),o=u(),[s,c]=r(null),l=(e,t)=>{c(e),o.mutate({patch:{diagnostics:[{id:e,armMs:t}]}},{onSettled:()=>{c(null),n.refetch()}})},d=n.data?.activeWindows??[],m=n.data?.channels??[],h=n.data?.activeChannels??[],g=(e,t,r)=>{c(e),o.mutate({patch:{channels:[{channel:e,armMs:t,deviceIds:r}]}},{onSettled:()=>{c(null),n.refetch()}})};return t(b,{icon:p,title:e(`logging.diagnostics.title`,`Diagnostics`),subtitle:e(`logging.diagnostics.subtitle`,`Diagnostics are armed for a window, never switched on. Each carries a deadline and expires by itself — one left running is an incident of its own.`),children:[n.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(f,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}):i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:d.map(e=>i(N,{window:e,busy:s===e.id,onArm:t=>l(e.id,t)},e.id))}),i(`h3`,{className:`mt-6 text-sm font-medium text-foreground`,children:e(`logging.diagnostics.channels`,`Component channels`)}),i(`p`,{className:`mb-2 max-w-3xl text-[11px] text-foreground-subtle`,children:e(`logging.diagnostics.channelsSubtitle`,`Declared by the addons that own them — this list is not maintained by hand. Arming a channel opens a window with a deadline; it closes by itself.`)}),m.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`logging.diagnostics.noChannels`,`No addon on this cluster declares a log channel, or none could be reached right now.`)}):i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:m.map(e=>i(M,{channel:e,state:h.find(t=>t.channel===e.name),busy:s===e.name,onArm:(t,n)=>g(e.name,t,n)},e.name))})]})}function M({channel:e,state:n,busy:a,onArm:o}){let{t:s}=v(),[c,l]=r(``),u=n?.armed===!0,d=()=>{let e=c.split(/[\s,+]+/).filter(e=>/^\d+$/.test(e)).map(e=>Number(e));return e.length>0?e:null};return t(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.name}),u?t(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[i(T,{className:`h-3 w-3`}),s(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:P(n?.remainingMs??0)})]}):i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:s(`logging.diagnostics.disarmed`,`disarmed`)}),u&&n?.deviceIds!==null&&n?.deviceIds!==void 0&&t(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[i(h,{className:`h-3 w-3`}),n.deviceIds.join(`, `)]}),!e.perDevice&&i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:s(`logging.diagnostics.notPerCamera`,`not filterable per camera`)})]}),i(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:e.description})]}),t(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[e.perDevice&&i(`input`,{type:`text`,inputMode:`numeric`,value:c,disabled:a,onChange:e=>l(e.target.value),placeholder:s(`logging.diagnostics.camerasPlaceholder`,`all cameras`),className:`w-28 rounded border border-border bg-surface px-2 py-1 text-[11px] text-foreground`}),k.map(e=>i(`button`,{type:`button`,disabled:a,onClick:()=>o(e,d()),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:P(e)},e)),i(`button`,{type:`button`,disabled:a||!u,onClick:()=>o(0,null),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:s(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function N({window:e,busy:n,onArm:r}){let{t:a}=v();return t(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.id}),e.armed?t(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[i(T,{className:`h-3 w-3`}),a(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:P(e.remainingMs)})]}):i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:a(`logging.diagnostics.disarmed`,`disarmed`)}),e.armed&&!e.persisted&&i(`span`,{className:`text-[10px] text-warning`,children:a(`logging.diagnostics.notPersisted`,`not persisted — will not survive a restart`)})]}),i(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:A[e.id]??``})]}),t(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[k.map(e=>i(`button`,{type:`button`,disabled:n,onClick:()=>r(e),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:P(e)},e)),i(`button`,{type:`button`,disabled:n||!e.armed,onClick:()=>r(0),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:a(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function P(e){let t=Math.max(0,Math.round(e/1e3)),n=Math.floor(t/60),r=t%60;return n===0?`${r}s`:r===0?`${n}m`:`${n}m ${r}s`}e();var F=[`debug`,`info`,`warn`,`error`],I=``,L=``;function R(){let{t:e}=v(),[o,s]=r(I),[l,p]=r(L),m=c(void 0,{staleTime:6e4}),h=n(()=>(m.data??[]).filter(e=>typeof e.id==`string`).map(e=>({id:e.id,label:typeof e.name==`string`&&e.name?e.name:e.id})),[m.data]),g=a({...o===I?{}:{scopeNodeId:o},...l===L?{}:{scopeComponent:l}},{refetchInterval:15e3}),_=u(),y=g.data,x=_.isPending||g.isFetching,S=y?.channels??[],C=(e,t)=>{_.mutate({...e.nodeId===null?{}:{scopeNodeId:e.nodeId},...e.component===null?{}:{scopeComponent:e.component},patch:{level:t}},{onSuccess:()=>void g.refetch()})};return i(b,{icon:d,title:e(`logging.levels.title`,`Levels`),subtitle:e(`logging.levels.subtitle`,`Cluster → node, most specific wins. The floor gates what reaches the log destinations; the in-memory viewer keeps every line either way.`),actions:t(`div`,{className:`flex flex-wrap items-center gap-3`,children:[t(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[e(`logging.levels.scope`,`Scope`),t(`select`,{className:`rounded border border-border bg-surface px-2 py-1 text-xs text-foreground disabled:opacity-50`,value:o,disabled:l!==L,onChange:e=>s(e.target.value),children:[i(`option`,{value:I,children:e(`logging.levels.cluster`,`Cluster`)}),h.map(e=>i(`option`,{value:e.id,children:e.label},e.id))]})]}),t(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[e(`logging.levels.component`,`Component`),t(`select`,{className:`rounded border border-border bg-surface px-2 py-1 text-xs text-foreground`,value:l,onChange:e=>p(e.target.value),children:[i(`option`,{value:L,children:e(`logging.levels.noComponent`,`None`)}),S.map(e=>i(`option`,{value:e.name,children:e.name},e.name))]})]})]}),children:g.isLoading||y===void 0?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(f,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}):t(`div`,{className:`space-y-3`,children:[i(z,{level:y.effective.level,source:y.effective.levelSource,persisted:y.persisted}),i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:y.explicit.layers.map(e=>i(B,{layer:e,inForce:e.scope===y.effective.levelSource,busy:x,onSet:t=>C(e,t),onClear:()=>C(e,null)},`${e.scope}:${e.nodeId??e.component??`cluster`}`))}),l!==L&&i(`p`,{className:`text-[11px] text-foreground-subtle`,children:S.find(e=>e.name===l)?.description??``}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`logging.levels.componentNote`,`A component is a log channel an addon declared. Its level is cluster-wide and beats both the node and the cluster layer.`)})]})})}function z({level:e,source:n,persisted:r}){let{t:a}=v();return t(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-xs text-foreground-subtle`,children:a(`logging.levels.effective`,`In force here`)}),i(`span`,{className:`rounded bg-primary/10 px-2 py-0.5 text-xs font-semibold text-primary`,children:e}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:n==="default"?a(`logging.levels.fromDefault`,`nothing is set anywhere — this is the default`):a(`logging.levels.fromLayer`,`decided by the {{source}} layer`,{source:n})})]}),!r&&i(`p`,{className:`mt-1 text-[11px] text-warning`,children:a(`logging.levels.notPersisted`,`The settings store could not be read or written — what you see is live, but it would not survive a restart.`)})]})}function B({layer:e,inForce:n,busy:r,onSet:a,onClear:o}){let{t:s}=v();return t(`div`,{className:`flex flex-col gap-2 p-3 sm:flex-row sm:items-center sm:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.scope===`cluster`?s(`logging.levels.cluster`,`Cluster`):e.scope===`component`?e.component??``:e.nodeId??``}),n&&t(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[i(y,{className:`h-3 w-3`}),s(`logging.levels.inForce`,`in force`)]})]}),i(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:e.level===null?s(`logging.levels.inherits`,`inherits — nothing set at this layer`):s(`logging.levels.setHere`,`set here: {{level}}`,{level:e.level})})]}),t(`div`,{className:`flex shrink-0 items-center gap-1`,children:[F.map(t=>i(`button`,{type:`button`,disabled:r,onClick:()=>a(t),className:`rounded px-2 py-1 text-[11px] font-medium transition-colors disabled:opacity-50 ${e.level===t?`bg-primary text-primary-foreground`:`border border-border text-foreground-subtle hover:text-foreground`}`,children:t},t)),i(`button`,{type:`button`,disabled:r||e.level===null,onClick:o,className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-40`,children:s(`logging.levels.clear`,`Clear`)})]})]})}function V(){return i(b,{children:i(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:i(o,{limit:500,maxHeight:`max-h-[calc(100vh-310px)]`,showScope:!0,showFilters:!0})})})}function H(){return i(`div`,{className:`flex flex-col p-4`,children:i(x,{tabs:[{id:`viewer`,label:`Viewer`,icon:_,content:i(V,{})},{id:`destinations`,label:`Destinations`,icon:g,content:i(O,{})},{id:`levels`,label:`Levels`,icon:d,content:i(R,{})},{id:`diagnostics`,label:`Diagnostics`,icon:p,content:i(j,{})}]})})}export{H as LogsPage};
1
+ import{Q as e,S as t,W as n,q as r,x as i}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{$o as a,J as o,On as s,ia as c,kn as l,ts as u}from"./src-CTpgEWRF.js";import{t as d}from"./layers-Bkhxc8O8.js";import{C as f,G as p,K as m,V as h,m as g,s as _,t as v,z as y}from"./index-BWNViBw0.js";import{t as b}from"./AdminPage-CCD07UMs.js";import{t as x}from"./AdminTabs-CR-73Caj.js";import{t as S}from"./AddonCollectionPage-DH55gIbE.js";import{t as C}from"./addon-display-names-DvSEQty-.js";var w=m(`file-text`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),T=m(`timer-reset`,[[`path`,{d:`M10 2h4`,key:`n1abiw`}],[`path`,{d:`M12 14v-4`,key:`1evpnu`}],[`path`,{d:`M4 13a8 8 0 0 1 8-7 8 8 0 1 1-5.3 14L4 17.6`,key:`1ts96g`}],[`path`,{d:`M9 17H4v5`,key:`8t5av`}]]);e();var E=5e3,D={"winston-logging":`Rotated log files on this node’s disk.`,"console-logging":`stdout / stderr of the node process.`,"loki-logging":`Pushes to a Grafana Loki instance. Off until enabled with a URL.`,"hub-forwarder":`Agent-only — forwards this node’s entries to the hub.`};function O(){let e=l({capName:`log-destination`},{refetchInterval:E}),t=s(void 0,{refetchInterval:E}),r=n(()=>C(t.data??[]),[t.data]),a=n(()=>{let e=new Map;for(let n of t.data??[]){let t=n.description,r=n.id;typeof r==`string`&&typeof t==`string`&&t.length>0&&e.set(r,t)}return e},[t.data]);return i(S,{title:`Logging`,subtitle:`Every registered log destination. Entries are fanned to all enabled destinations at once — enabling one does not disable another. Each destination's own configuration is docked under it.`,pageIcon:g,itemIcon:w,capability:`log-destination`,installButtonLabel:`Add destination`,items:n(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:r.get(e.addonId)??e.addonId,isActive:e.isActive,caption:a.get(e.addonId)??D[e.addonId]??``})),[e.data,r,a]),isLoading:e.isLoading,emptyTitle:`No log destinations registered`,emptyDescription:`This should not happen — the console and rotated-file destinations are builtins. If the list is empty, the node is still booting.`,renderStatusBadges:e=>e.caption.length>0?i(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.caption}):null})}e();var k=[12e4,3e5,6e5,18e5],A={"request-census":`Counts every tRPC call by TRANSPORT PLANE — http, ws, mesh — and by procedure, caller, address and user-agent. Subscriptions are counted apart from calls, so a long-lived stream cannot pass for a storm. Arm it, then restart: the deadline is persisted, so the window is still running when clients reconnect.`};function j(){let{t:e}=v(),n=a({},{refetchInterval:5e3}),o=u(),[s,c]=r(null),l=(e,t)=>{c(e),o.mutate({patch:{diagnostics:[{id:e,armMs:t}]}},{onSettled:()=>{c(null),n.refetch()}})},d=n.data?.activeWindows??[],m=n.data?.channels??[],h=n.data?.activeChannels??[],g=(e,t,r)=>{c(e),o.mutate({patch:{channels:[{channel:e,armMs:t,deviceIds:r}]}},{onSettled:()=>{c(null),n.refetch()}})};return t(b,{icon:p,title:e(`logging.diagnostics.title`,`Diagnostics`),subtitle:e(`logging.diagnostics.subtitle`,`Diagnostics are armed for a window, never switched on. Each carries a deadline and expires by itself — one left running is an incident of its own.`),children:[n.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(f,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}):i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:d.map(e=>i(N,{window:e,busy:s===e.id,onArm:t=>l(e.id,t)},e.id))}),i(`h3`,{className:`mt-6 text-sm font-medium text-foreground`,children:e(`logging.diagnostics.channels`,`Component channels`)}),i(`p`,{className:`mb-2 max-w-3xl text-[11px] text-foreground-subtle`,children:e(`logging.diagnostics.channelsSubtitle`,`Declared by the addons that own them — this list is not maintained by hand. Arming a channel opens a window with a deadline; it closes by itself.`)}),m.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`logging.diagnostics.noChannels`,`No addon on this cluster declares a log channel, or none could be reached right now.`)}):i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:m.map(e=>i(M,{channel:e,state:h.find(t=>t.channel===e.name),busy:s===e.name,onArm:(t,n)=>g(e.name,t,n)},e.name))})]})}function M({channel:e,state:n,busy:a,onArm:o}){let{t:s}=v(),[c,l]=r(``),u=n?.armed===!0,d=()=>{let e=c.split(/[\s,+]+/).filter(e=>/^\d+$/.test(e)).map(e=>Number(e));return e.length>0?e:null};return t(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.name}),u?t(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[i(T,{className:`h-3 w-3`}),s(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:P(n?.remainingMs??0)})]}):i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:s(`logging.diagnostics.disarmed`,`disarmed`)}),u&&n?.deviceIds!==null&&n?.deviceIds!==void 0&&t(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[i(h,{className:`h-3 w-3`}),n.deviceIds.join(`, `)]}),!e.perDevice&&i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:s(`logging.diagnostics.notPerCamera`,`not filterable per camera`)})]}),i(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:e.description})]}),t(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[e.perDevice&&i(`input`,{type:`text`,inputMode:`numeric`,value:c,disabled:a,onChange:e=>l(e.target.value),placeholder:s(`logging.diagnostics.camerasPlaceholder`,`all cameras`),className:`w-28 rounded border border-border bg-surface px-2 py-1 text-[11px] text-foreground`}),k.map(e=>i(`button`,{type:`button`,disabled:a,onClick:()=>o(e,d()),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:P(e)},e)),i(`button`,{type:`button`,disabled:a||!u,onClick:()=>o(0,null),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:s(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function N({window:e,busy:n,onArm:r}){let{t:a}=v();return t(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.id}),e.armed?t(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[i(T,{className:`h-3 w-3`}),a(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:P(e.remainingMs)})]}):i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:a(`logging.diagnostics.disarmed`,`disarmed`)}),e.armed&&!e.persisted&&i(`span`,{className:`text-[10px] text-warning`,children:a(`logging.diagnostics.notPersisted`,`not persisted — will not survive a restart`)})]}),i(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:A[e.id]??``})]}),t(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[k.map(e=>i(`button`,{type:`button`,disabled:n,onClick:()=>r(e),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:P(e)},e)),i(`button`,{type:`button`,disabled:n||!e.armed,onClick:()=>r(0),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:a(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function P(e){let t=Math.max(0,Math.round(e/1e3)),n=Math.floor(t/60),r=t%60;return n===0?`${r}s`:r===0?`${n}m`:`${n}m ${r}s`}e();var F=[`debug`,`info`,`warn`,`error`],I=``,L=``;function R(){let{t:e}=v(),[o,s]=r(I),[l,p]=r(L),m=c(void 0,{staleTime:6e4}),h=n(()=>(m.data??[]).filter(e=>typeof e.id==`string`).map(e=>({id:e.id,label:typeof e.name==`string`&&e.name?e.name:e.id})),[m.data]),g=a({...o===I?{}:{scopeNodeId:o},...l===L?{}:{scopeComponent:l}},{refetchInterval:15e3}),_=u(),y=g.data,x=_.isPending||g.isFetching,S=y?.channels??[],C=(e,t)=>{_.mutate({...e.nodeId===null?{}:{scopeNodeId:e.nodeId},...e.component===null?{}:{scopeComponent:e.component},patch:{level:t}},{onSuccess:()=>void g.refetch()})};return i(b,{icon:d,title:e(`logging.levels.title`,`Levels`),subtitle:e(`logging.levels.subtitle`,`Cluster → node, most specific wins. The floor gates what reaches the log destinations; the in-memory viewer keeps every line either way.`),actions:t(`div`,{className:`flex flex-wrap items-center gap-3`,children:[t(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[e(`logging.levels.scope`,`Scope`),t(`select`,{className:`rounded border border-border bg-surface px-2 py-1 text-xs text-foreground disabled:opacity-50`,value:o,disabled:l!==L,onChange:e=>s(e.target.value),children:[i(`option`,{value:I,children:e(`logging.levels.cluster`,`Cluster`)}),h.map(e=>i(`option`,{value:e.id,children:e.label},e.id))]})]}),t(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[e(`logging.levels.component`,`Component`),t(`select`,{className:`rounded border border-border bg-surface px-2 py-1 text-xs text-foreground`,value:l,onChange:e=>p(e.target.value),children:[i(`option`,{value:L,children:e(`logging.levels.noComponent`,`None`)}),S.map(e=>i(`option`,{value:e.name,children:e.name},e.name))]})]})]}),children:g.isLoading||y===void 0?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(f,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}):t(`div`,{className:`space-y-3`,children:[i(z,{level:y.effective.level,source:y.effective.levelSource,persisted:y.persisted}),i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:y.explicit.layers.map(e=>i(B,{layer:e,inForce:e.scope===y.effective.levelSource,busy:x,onSet:t=>C(e,t),onClear:()=>C(e,null)},`${e.scope}:${e.nodeId??e.component??`cluster`}`))}),l!==L&&i(`p`,{className:`text-[11px] text-foreground-subtle`,children:S.find(e=>e.name===l)?.description??``}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`logging.levels.componentNote`,`A component is a log channel an addon declared. Its level is cluster-wide and beats both the node and the cluster layer.`)})]})})}function z({level:e,source:n,persisted:r}){let{t:a}=v();return t(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-xs text-foreground-subtle`,children:a(`logging.levels.effective`,`In force here`)}),i(`span`,{className:`rounded bg-primary/10 px-2 py-0.5 text-xs font-semibold text-primary`,children:e}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:n==="default"?a(`logging.levels.fromDefault`,`nothing is set anywhere — this is the default`):a(`logging.levels.fromLayer`,`decided by the {{source}} layer`,{source:n})})]}),!r&&i(`p`,{className:`mt-1 text-[11px] text-warning`,children:a(`logging.levels.notPersisted`,`The settings store could not be read or written — what you see is live, but it would not survive a restart.`)})]})}function B({layer:e,inForce:n,busy:r,onSet:a,onClear:o}){let{t:s}=v();return t(`div`,{className:`flex flex-col gap-2 p-3 sm:flex-row sm:items-center sm:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.scope===`cluster`?s(`logging.levels.cluster`,`Cluster`):e.scope===`component`?e.component??``:e.nodeId??``}),n&&t(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[i(y,{className:`h-3 w-3`}),s(`logging.levels.inForce`,`in force`)]})]}),i(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:e.level===null?s(`logging.levels.inherits`,`inherits — nothing set at this layer`):s(`logging.levels.setHere`,`set here: {{level}}`,{level:e.level})})]}),t(`div`,{className:`flex shrink-0 items-center gap-1`,children:[F.map(t=>i(`button`,{type:`button`,disabled:r,onClick:()=>a(t),className:`rounded px-2 py-1 text-[11px] font-medium transition-colors disabled:opacity-50 ${e.level===t?`bg-primary text-primary-foreground`:`border border-border text-foreground-subtle hover:text-foreground`}`,children:t},t)),i(`button`,{type:`button`,disabled:r||e.level===null,onClick:o,className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-40`,children:s(`logging.levels.clear`,`Clear`)})]})]})}function V(){return i(b,{children:i(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:i(o,{limit:500,maxHeight:`max-h-[calc(100vh-310px)]`,showScope:!0,showFilters:!0})})})}function H(){return i(`div`,{className:`flex flex-col p-4`,children:i(x,{tabs:[{id:`viewer`,label:`Viewer`,icon:_,content:i(V,{})},{id:`destinations`,label:`Destinations`,icon:g,content:i(O,{})},{id:`levels`,label:`Levels`,icon:d,content:i(R,{})},{id:`diagnostics`,label:`Diagnostics`,icon:p,content:i(j,{})}]})})}export{H as LogsPage};
@@ -1 +1 @@
1
- import{I as e,K as t,Q as n,S as r,W as i,b as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{J as l,U as u,W as ee,Z as d,ct as f,j as p,n as m}from"./player-overlays-C82v-qwN.js";import{MaskShapeCanvas as h}from"./MaskShapeCanvas-Dcpby34M.js";var te=f(`grid-2x2`,[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`M3 12h18`,key:`1i2n21`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}]]);n();var ne=110,g=`motion-zones`,_=0,re=[1,2,3],v=1,y=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,b=`rounded-md border border-primary/50 bg-primary/15 px-2.5 py-1 text-[11px] font-medium text-primary hover:bg-primary/25 disabled:opacity-40 transition-colors`;function x(e,t,n){let r=t*n,i=Array.from({length:r});for(let t=0;t<r;t+=1)i[t]=e[t]===!0;return i}function S(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return!1;return!0}function C(e,t){return Math.ceil(e/t)}function w(e,t,n){return Math.min(n-1,Math.floor((e+.5)/t*n))}function T(e,t,n,r){let i=C(t,r),a=C(n,r),o=Array.from({length:i*a},()=>!1);for(let r=0;r<n;r+=1){let s=w(r,n,a);for(let n=0;n<t;n+=1)e[r*t+n]===!0&&(o[s*i+w(n,t,i)]=!0)}return o}function E(e,t,n,r){let i=C(t,r),a=C(n,r),o=Array.from({length:t*n},()=>!1);for(let r=0;r<n;r+=1){let s=w(r,n,a);for(let n=0;n<t;n+=1)o[r*t+n]=e[s*i+w(n,t,i)]===!0}return o}function D({deviceId:n}){let f=ee(d().trpcClient,n),[w,D]=o(null),[O,k]=o(!1),[A,j]=o(null),[M,N]=o(null),[P,F]=o(v),[I,L]=o(!1),[R,z]=o(!1),B=t(!1);c(()=>{if(!f)return;let e=!1;return B.current=!1,D(null),k(!1),j(null),N(null),F(v),z(!1),(async()=>{try{let t=await f.motionZones?.getOptions({});if(e)return;if(!t)throw Error(`device proxy not ready`);if(D(t),B.current)return;let n=await f.motionZones?.getStatus({});if(e)return;if(!n)throw Error(`device proxy not ready`);B.current=!0;let r=n.regions.find(e=>e.shape.kind===`grid`),i=x(r?r.shape.cells:[],t.grid.width,t.grid.height);N(i),j(T(i,t.grid.width,t.grid.height,v))}catch(t){if(e)return;u(t)?k(!0):console.error(`Motion Zones load failed`,t)}})(),()=>{e=!0}},[f]);let V=w?w.grid.width:0,H=w?w.grid.height:0,U=C(V,P),W=C(H,P),G=i(()=>A&&w?E(A,V,H,P):null,[A,w,V,H,P]),K=i(()=>G!==null&&M!==null&&!S(G,M),[G,M]),q=i(()=>G?G.reduce((e,t)=>t?e+1:e,0):0,[G]),J=V*H,Y=U*W,X=e(e=>{Y>0&&j(Array.from({length:Y},()=>e))},[Y]),Z=e(()=>{j(e=>e&&e.map(e=>!e))},[]),ie=e(()=>{M&&w&&j(T(M,V,H,P))},[M,w,V,H,P]),ae=e(e=>{e===P||!w||j(t=>{if(!t)return F(e),t;let n=T(E(t,V,H,P),V,H,e);return F(e),n})},[P,w,V,H]),Q=i(()=>w&&A?[{id:_,shape:{kind:`grid`,gridWidth:U,gridHeight:W,cells:[...A]}}]:[],[w,A,U,W]),$=e((e,t)=>{t.kind===`grid`&&j(t.cells)},[]),oe=e(async()=>{if(!(!f||!A||!w)){L(!0);try{let e=E(A,w.grid.width,w.grid.height,P),t={kind:`grid`,gridWidth:w.grid.width,gridHeight:w.grid.height,cells:e};await f.motionZones?.setZone({patch:{regions:[{id:_,enabled:!0,shape:t}]}});let n=await f.motionZones?.getStatus({});if(n){let e=n.regions.find(e=>e.shape.kind===`grid`),t=x(e?e.shape.cells:[],w.grid.width,w.grid.height);N(t),j(T(t,w.grid.width,w.grid.height,P))}}catch(e){console.error(`Motion Zones save failed`,e)}finally{L(!1)}}},[f,A,w,P]);return m(i(()=>R&&!O&&w&&A?{id:g,order:ne,node:s(h,{transparent:!0,items:Q,supportedShapes:[`grid`],grid:{width:U,height:W},selectedId:_,onSelect:()=>{},onShapeChange:$,onDrawComplete:()=>{},drawingKind:null})}:null,[R,O,w,A,Q,$,U,W])),f?s(l,{title:`Motion Zones`,icon:s(te,{className:`h-3.5 w-3.5 text-foreground-subtle`}),children:s(`div`,{className:`flex flex-col gap-3`,children:O?s(`p`,{className:`${p} leading-relaxed`,children:`This camera doesn't expose an on-board motion zones grid.`}):!O&&w!==null&&A!==null?r(a,{children:[r(`p`,{className:`${p} leading-relaxed`,children:[`Toggle `,s(`strong`,{className:`text-foreground`,children:`Edit grid`}),` to paint the region directly on the live frame, then `,s(`strong`,{className:`text-foreground`,children:`Save`}),` to push the mask to the camera. Pick a bigger`,` `,s(`strong`,{className:`text-foreground`,children:`Cell size`}),` for quicker, broad-stroke painting — it's resampled to the camera's native `,w.grid.width,`×`,w.grid.height,` grid on save (×1 is the finest).`]}),r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[s(`button`,{type:`button`,onClick:()=>z(e=>!e),disabled:I,"aria-pressed":R,className:R?b:y,children:R?`Done editing`:`Edit grid`}),s(`button`,{type:`button`,onClick:()=>X(!0),disabled:I,className:y,children:`All on`}),s(`button`,{type:`button`,onClick:()=>X(!1),disabled:I,className:y,children:`All off`}),s(`button`,{type:`button`,onClick:Z,disabled:I,className:y,children:`Invert`}),r(`div`,{className:`flex items-center gap-1 ml-1`,role:`group`,"aria-label":`Cell size`,children:[s(`span`,{className:`${p} mr-0.5`,children:`Cell size`}),re.map(e=>r(`button`,{type:`button`,onClick:()=>ae(e),disabled:I,"aria-pressed":P===e,title:e===1?`Camera grid ${V}×${H} (finest)`:`${C(V,e)}×${C(H,e)} painting grid · cells ×${e} bigger`,className:P===e?b:y,children:[`×`,e]},e))]}),r(`span`,{className:`${p} ml-1 tabular-nums`,children:[q,` / `,J,` cells · `,w.grid.width,`×`,w.grid.height,P===1?``:` · paint ${U}×${W}`]}),s(`span`,{className:`flex-1`}),s(`button`,{type:`button`,onClick:ie,disabled:I||!K,className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,children:`Revert`}),s(`button`,{type:`button`,onClick:()=>void oe(),disabled:I||!K,className:b,children:I?`Saving…`:`Save`})]})]}):s(`p`,{className:`${p} leading-relaxed`,children:`Loading the camera's grid…`})})}):null}export{D as MotionZonesSettings};
1
+ import{I as e,K as t,Q as n,S as r,W as i,b as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{J as l,U as u,W as ee,Z as d,ct as f,j as p,n as m}from"./player-overlays-BrCS3AFF.js";import{MaskShapeCanvas as h}from"./MaskShapeCanvas-Dcpby34M.js";var te=f(`grid-2x2`,[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`M3 12h18`,key:`1i2n21`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}]]);n();var ne=110,g=`motion-zones`,_=0,re=[1,2,3],v=1,y=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,b=`rounded-md border border-primary/50 bg-primary/15 px-2.5 py-1 text-[11px] font-medium text-primary hover:bg-primary/25 disabled:opacity-40 transition-colors`;function x(e,t,n){let r=t*n,i=Array.from({length:r});for(let t=0;t<r;t+=1)i[t]=e[t]===!0;return i}function S(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return!1;return!0}function C(e,t){return Math.ceil(e/t)}function w(e,t,n){return Math.min(n-1,Math.floor((e+.5)/t*n))}function T(e,t,n,r){let i=C(t,r),a=C(n,r),o=Array.from({length:i*a},()=>!1);for(let r=0;r<n;r+=1){let s=w(r,n,a);for(let n=0;n<t;n+=1)e[r*t+n]===!0&&(o[s*i+w(n,t,i)]=!0)}return o}function E(e,t,n,r){let i=C(t,r),a=C(n,r),o=Array.from({length:t*n},()=>!1);for(let r=0;r<n;r+=1){let s=w(r,n,a);for(let n=0;n<t;n+=1)o[r*t+n]=e[s*i+w(n,t,i)]===!0}return o}function D({deviceId:n}){let f=ee(d().trpcClient,n),[w,D]=o(null),[O,k]=o(!1),[A,j]=o(null),[M,N]=o(null),[P,F]=o(v),[I,L]=o(!1),[R,z]=o(!1),B=t(!1);c(()=>{if(!f)return;let e=!1;return B.current=!1,D(null),k(!1),j(null),N(null),F(v),z(!1),(async()=>{try{let t=await f.motionZones?.getOptions({});if(e)return;if(!t)throw Error(`device proxy not ready`);if(D(t),B.current)return;let n=await f.motionZones?.getStatus({});if(e)return;if(!n)throw Error(`device proxy not ready`);B.current=!0;let r=n.regions.find(e=>e.shape.kind===`grid`),i=x(r?r.shape.cells:[],t.grid.width,t.grid.height);N(i),j(T(i,t.grid.width,t.grid.height,v))}catch(t){if(e)return;u(t)?k(!0):console.error(`Motion Zones load failed`,t)}})(),()=>{e=!0}},[f]);let V=w?w.grid.width:0,H=w?w.grid.height:0,U=C(V,P),W=C(H,P),G=i(()=>A&&w?E(A,V,H,P):null,[A,w,V,H,P]),K=i(()=>G!==null&&M!==null&&!S(G,M),[G,M]),q=i(()=>G?G.reduce((e,t)=>t?e+1:e,0):0,[G]),J=V*H,Y=U*W,X=e(e=>{Y>0&&j(Array.from({length:Y},()=>e))},[Y]),Z=e(()=>{j(e=>e&&e.map(e=>!e))},[]),ie=e(()=>{M&&w&&j(T(M,V,H,P))},[M,w,V,H,P]),ae=e(e=>{e===P||!w||j(t=>{if(!t)return F(e),t;let n=T(E(t,V,H,P),V,H,e);return F(e),n})},[P,w,V,H]),Q=i(()=>w&&A?[{id:_,shape:{kind:`grid`,gridWidth:U,gridHeight:W,cells:[...A]}}]:[],[w,A,U,W]),$=e((e,t)=>{t.kind===`grid`&&j(t.cells)},[]),oe=e(async()=>{if(!(!f||!A||!w)){L(!0);try{let e=E(A,w.grid.width,w.grid.height,P),t={kind:`grid`,gridWidth:w.grid.width,gridHeight:w.grid.height,cells:e};await f.motionZones?.setZone({patch:{regions:[{id:_,enabled:!0,shape:t}]}});let n=await f.motionZones?.getStatus({});if(n){let e=n.regions.find(e=>e.shape.kind===`grid`),t=x(e?e.shape.cells:[],w.grid.width,w.grid.height);N(t),j(T(t,w.grid.width,w.grid.height,P))}}catch(e){console.error(`Motion Zones save failed`,e)}finally{L(!1)}}},[f,A,w,P]);return m(i(()=>R&&!O&&w&&A?{id:g,order:ne,node:s(h,{transparent:!0,items:Q,supportedShapes:[`grid`],grid:{width:U,height:W},selectedId:_,onSelect:()=>{},onShapeChange:$,onDrawComplete:()=>{},drawingKind:null})}:null,[R,O,w,A,Q,$,U,W])),f?s(l,{title:`Motion Zones`,icon:s(te,{className:`h-3.5 w-3.5 text-foreground-subtle`}),children:s(`div`,{className:`flex flex-col gap-3`,children:O?s(`p`,{className:`${p} leading-relaxed`,children:`This camera doesn't expose an on-board motion zones grid.`}):!O&&w!==null&&A!==null?r(a,{children:[r(`p`,{className:`${p} leading-relaxed`,children:[`Toggle `,s(`strong`,{className:`text-foreground`,children:`Edit grid`}),` to paint the region directly on the live frame, then `,s(`strong`,{className:`text-foreground`,children:`Save`}),` to push the mask to the camera. Pick a bigger`,` `,s(`strong`,{className:`text-foreground`,children:`Cell size`}),` for quicker, broad-stroke painting — it's resampled to the camera's native `,w.grid.width,`×`,w.grid.height,` grid on save (×1 is the finest).`]}),r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[s(`button`,{type:`button`,onClick:()=>z(e=>!e),disabled:I,"aria-pressed":R,className:R?b:y,children:R?`Done editing`:`Edit grid`}),s(`button`,{type:`button`,onClick:()=>X(!0),disabled:I,className:y,children:`All on`}),s(`button`,{type:`button`,onClick:()=>X(!1),disabled:I,className:y,children:`All off`}),s(`button`,{type:`button`,onClick:Z,disabled:I,className:y,children:`Invert`}),r(`div`,{className:`flex items-center gap-1 ml-1`,role:`group`,"aria-label":`Cell size`,children:[s(`span`,{className:`${p} mr-0.5`,children:`Cell size`}),re.map(e=>r(`button`,{type:`button`,onClick:()=>ae(e),disabled:I,"aria-pressed":P===e,title:e===1?`Camera grid ${V}×${H} (finest)`:`${C(V,e)}×${C(H,e)} painting grid · cells ×${e} bigger`,className:P===e?b:y,children:[`×`,e]},e))]}),r(`span`,{className:`${p} ml-1 tabular-nums`,children:[q,` / `,J,` cells · `,w.grid.width,`×`,w.grid.height,P===1?``:` · paint ${U}×${W}`]}),s(`span`,{className:`flex-1`}),s(`button`,{type:`button`,onClick:ie,disabled:I||!K,className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,children:`Revert`}),s(`button`,{type:`button`,onClick:()=>void oe(),disabled:I||!K,className:b,children:I?`Saving…`:`Save`})]})]}):s(`p`,{className:`${p} leading-relaxed`,children:`Loading the camera's grid…`})})}):null}export{D as MotionZonesSettings};
@@ -1,2 +1,2 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/browser-BHo8W_uH.js","assets/rolldown-runtime-Cyuzqnbw.js"])))=>i.map(i=>d[i]);
2
- import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{t}from"./vite-preload-helper-zJ_50EbN.js";import{Q as n,S as r,W as i,a,b as o,q as s,t as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as d}from"./player-overlays-C82v-qwN.js";import{S as f,Yt as p,in as m}from"./src-BZXGF7UJ.js";import{t as h}from"./circle-check-big-BxRTF9W-.js";import{t as g}from"./copy-cBOxpZ8P.js";import{t as _}from"./key-round-CNjQoJAO.js";import{t as v}from"./pencil-Bz16G0wg.js";import{C as y,F as b,S as x,k as S,l as C,n as w,o as T,w as E,x as D}from"./index-JUF-VzOE.js";import{t as O}from"./AdminPage-CCD07UMs.js";n();function k({value:n,size:i=192}){let[a,o]=s(null),[c,d]=s(null);if(u(()=>{let r=!1;return t(()=>import(`./browser-BHo8W_uH.js`).then(t=>e(t.default,1)).then(async e=>{if(r)return;let t=e.create;if(typeof t!=`function`){d(`qrcode.create() unavailable in installed version`);return}try{let e=t(n,{errorCorrectionLevel:`M`});r||o(e)}catch(e){r||d(e instanceof Error?e.message:`QR generation failed`)}}),__vite__mapDeps([0,1])).catch(()=>{r||d(`qrcode library not installed`)}),()=>{r=!0}},[n]),c)return l(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle text-center p-4`,style:{width:i,height:i},children:`QR rendering unavailable — use the secret below.`});if(!a)return l(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle animate-pulse`,style:{width:i,height:i},children:`Generating…`});let f=a.modules.size,p=i/f,m=[];for(let e=0;e<f;e++)for(let t=0;t<f;t++)a.modules.data[e*f+t]&&m.push(l(`rect`,{x:t*p,y:e*p,width:p,height:p,fill:`currentColor`},`${t}-${e}`));return r(`svg`,{width:i,height:i,viewBox:`0 0 ${i} ${i}`,className:`text-black`,children:[l(`rect`,{x:0,y:0,width:i,height:i,fill:`white`}),m]})}n();var A={view:{icon:S,cls:`bg-foreground-subtle/15 text-foreground-subtle`},create:{icon:v,cls:`bg-primary/15 text-primary`},delete:{icon:T,cls:`bg-danger/15 text-danger`}};function j(){let{user:e,logout:t}=w();if(!e)return l(O,{children:l(`div`,{className:`text-xs text-foreground-subtle`,children:`Not signed in.`})});let n=e.isAdmin,i=e.scopes??[];return r(O,{children:[r(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3 flex items-center gap-3`,children:[l(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-full bg-primary/10 text-primary font-semibold text-base`,children:e.username.slice(0,1).toUpperCase()}),r(`div`,{className:`flex-1 min-w-0`,children:[l(`div`,{className:`text-sm font-semibold text-foreground truncate`,children:e.username}),r(`div`,{className:`text-[11px] text-foreground-subtle`,children:[n?`Administrator`:`User`,` · session id`,` `,r(`span`,{className:`font-mono`,children:[e.id.slice(0,8),`…`]})]})]})]}),n&&r(`div`,{className:`rounded-lg border border-primary/30 bg-primary/5 px-4 py-3 text-xs text-foreground flex items-start gap-2.5`,children:[l(E,{className:`h-4 w-4 text-primary mt-0.5 shrink-0`}),r(`div`,{children:[l(`div`,{className:`font-semibold text-foreground`,children:`Unrestricted access`}),l(`p`,{className:`text-foreground-subtle mt-0.5`,children:`Admin sessions bypass the per-call scope check. Every protected endpoint is reachable regardless of the list below.`})]})]}),l(M,{}),l(P,{username:e.username}),l(F,{}),i.length>0&&r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-4 py-2 border-b border-border`,children:[l(`div`,{className:`text-xs font-semibold text-foreground`,children:`Granted scopes`}),l(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Baked into your session token at login; sign out + back in to refresh after changes.`})]}),r(`div`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[l(`div`,{children:`Type`}),l(`div`,{children:`Target`}),l(`div`,{children:`Access`})]}),l(`ul`,{className:`divide-y divide-border`,children:i.map((e,t)=>r(`li`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2.5 items-center text-xs`,children:[l(`span`,{className:`font-mono text-foreground-subtle`,children:e.type}),l(`span`,{className:`font-mono text-foreground`,children:e.type===`device`?f(e.selector):e.target}),l(`div`,{className:`flex items-center gap-1`,children:[`view`,`create`,`delete`].map(t=>{let n=e.access.includes(t),{icon:i,cls:a}=A[t];return r(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${n?a:`bg-transparent text-foreground-subtle/40 line-through`}`,title:n?`Can ${t}`:`Cannot ${t}`,children:[l(i,{className:`h-3 w-3`}),t]},t)})})]},t))})]}),l(`div`,{className:`flex justify-end`,children:r(`button`,{onClick:t,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground transition-colors`,children:[l(D,{className:`h-3 w-3`}),`Sign out`]})})]})}function M(){let e=d(),[t,n]=s(``),[i,a]=s(``),[o,u]=s(``),[f,p]=s(null),m=c({mutationFn:t=>e.changeOwnPassword(t),onSuccess:()=>{p({kind:`success`,msg:`Password updated.`}),n(``),a(``),u(``)},onError:e=>{p({kind:`error`,msg:e instanceof Error?e.message:`Update failed`})}}),g=i.length>0&&o.length>0&&i!==o,v=i.length>0&&i.length<8,S=t.length>=1&&i.length>=8&&i===o;return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[l(_,{className:`h-3.5 w-3.5 text-foreground-subtle`}),l(`div`,{className:`text-xs font-semibold text-foreground`,children:`Change password`})]}),r(`div`,{className:`p-4 space-y-3`,children:[l(N,{label:`Current password`,value:t,onChange:n,autoComplete:`current-password`}),l(N,{label:`New password`,value:i,onChange:a,autoComplete:`new-password`,hint:`At least 8 characters.`}),l(N,{label:`Confirm new password`,value:o,onChange:u,autoComplete:`new-password`}),(g||v)&&l(`div`,{className:`text-[11px] text-danger`,children:g?`Passwords do not match.`:`New password must be at least 8 characters.`}),f&&r(`div`,{className:`text-[11px] flex items-center gap-1 ${f.kind===`success`?`text-emerald-500`:`text-danger`}`,children:[f.kind===`success`?l(h,{className:`h-3 w-3`}):l(b,{className:`h-3 w-3`}),f.msg]}),l(`div`,{className:`flex justify-end`,children:r(`button`,{onClick:()=>{p(null),m.mutate({currentPassword:t,newPassword:i})},disabled:!S||m.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[m.isPending?l(y,{className:`h-3 w-3 animate-spin`}):l(x,{className:`h-3 w-3`}),`Update password`]})})]})]})}function N({label:e,value:t,onChange:n,autoComplete:i,hint:a}){return r(`div`,{className:`space-y-1`,children:[l(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e}),l(`input`,{type:`password`,value:t,onChange:e=>n(e.target.value),autoComplete:i,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),a&&l(`div`,{className:`text-[10px] text-foreground-subtle`,children:a})]})}function P({username:e}){let t=d(),n=a({queryKey:[`auth`,`getOwnTotpStatus`],queryFn:()=>t.getOwnTotpStatus()}),f=n.data,[p,m]=s(null),[_,v]=s(``),[x,S]=s(null),[w,T]=s(!1),E=c({mutationFn:()=>t.setupOwnTotp(),onSuccess:e=>{m({secret:e.secret,otpauthUrl:e.otpauthUrl}),v(``),S(null)},onError:e=>S(e instanceof Error?e.message:`Setup failed`)}),D=c({mutationFn:e=>t.confirmOwnTotp(e),onSuccess:()=>{m(null),v(``),S(null),n.refetch()},onError:e=>S(e instanceof Error?e.message:`Confirmation failed — code did not match`)}),O=c({mutationFn:()=>t.disableOwnTotp(),onSuccess:()=>{S(null),n.refetch()},onError:e=>S(e instanceof Error?e.message:`Disable failed`)});u(()=>{if(!w)return;let e=setTimeout(()=>T(!1),1500);return()=>clearTimeout(e)},[w]);let A=i(()=>n.isLoading?`loading`:p?`setup_in_progress`:f?.enabled?`enrolled`:`not_enrolled`,[n.isLoading,f?.enabled,p]);return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[l(C,{className:`h-3.5 w-3.5 text-foreground-subtle`}),l(`div`,{className:`text-xs font-semibold text-foreground`,children:`Two-factor authentication`})]}),r(`div`,{className:`p-4 space-y-3`,children:[A===`loading`&&r(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[l(y,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),A===`not_enrolled`&&r(o,{children:[l(`div`,{className:`text-xs text-foreground-subtle`,children:`2FA isn't active on your account. Enable it to require a 6-digit code from your authenticator app at every login.`}),l(`div`,{className:`flex justify-end`,children:r(`button`,{onClick:()=>{S(null),E.mutate()},disabled:E.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[E.isPending?l(y,{className:`h-3 w-3 animate-spin`}):l(C,{className:`h-3 w-3`}),`Enable 2FA`]})})]}),A===`setup_in_progress`&&p&&r(o,{children:[r(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`Scan the QR code (or enter the secret manually) into your authenticator app for`,` `,l(`span`,{className:`font-mono`,children:e}),`, then enter the 6-digit code below to confirm.`]}),r(`div`,{className:`flex flex-col items-center gap-3`,children:[l(`div`,{className:`rounded-lg border border-border bg-white p-3`,children:l(k,{value:p.otpauthUrl,size:180})}),r(`div`,{className:`w-full`,children:[l(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle mb-1`,children:`Secret (manual entry)`}),r(`div`,{className:`flex items-center gap-2 rounded border border-border bg-surface-hover/30 px-2 py-1.5`,children:[l(`code`,{className:`text-[11px] font-mono text-foreground break-all flex-1`,children:p.secret}),r(`button`,{onClick:()=>{p&&navigator.clipboard.writeText(p.secret).then(()=>T(!0))},className:`inline-flex items-center gap-1 text-[10px] text-foreground-subtle hover:text-foreground`,children:[w?l(h,{className:`h-3 w-3 text-emerald-500`}):l(g,{className:`h-3 w-3`}),w?`Copied`:`Copy`]})]})]})]}),r(`div`,{className:`space-y-1`,children:[l(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`6-digit code`}),l(`input`,{type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,placeholder:`123456`,value:_,onChange:e=>v(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full rounded-md border border-border bg-surface px-3 py-2 text-center text-lg font-mono tracking-widest text-foreground focus:outline-none focus:ring-2 focus:ring-primary`})]}),x&&r(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[l(b,{className:`h-3 w-3`}),x]}),r(`div`,{className:`flex justify-end gap-2`,children:[l(`button`,{onClick:()=>{m(null),S(null),v(``)},className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),r(`button`,{onClick:()=>{S(null),D.mutate({code:_})},disabled:D.isPending||_.length!==6,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[D.isPending?l(y,{className:`h-3 w-3 animate-spin`}):l(h,{className:`h-3 w-3`}),`Confirm`]})]})]}),A===`enrolled`&&f&&r(o,{children:[r(`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:[l(h,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),r(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[l(`div`,{className:`font-medium`,children:`2FA is active`}),r(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,f.confirmedAt?new Date(f.confirmedAt).toLocaleString():`—`]})]})]}),x&&r(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[l(b,{className:`h-3 w-3`}),x]}),l(`div`,{className:`flex justify-end`,children:r(`button`,{onClick:()=>{S(null),O.mutate()},disabled:O.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:[O.isPending?l(y,{className:`h-3 w-3 animate-spin`}):l(C,{className:`h-3 w-3`}),`Disable 2FA`]})})]})]})]})}function F(){return m(`auth-webauthn/passkey-enrollment`)?l(p,{widgetId:`auth-webauthn/passkey-enrollment`,host:`dashboard`}):null}export{j as MyAccessPage};
2
+ import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{t}from"./vite-preload-helper-zJ_50EbN.js";import{Q as n,S as r,W as i,a,b as o,q as s,t as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as d}from"./player-overlays-BrCS3AFF.js";import{S as f,Yt as p,in as m}from"./src-CTpgEWRF.js";import{t as h}from"./circle-check-big-BLcbyBkC.js";import{t as g}from"./copy-2sJiEWo5.js";import{t as _}from"./key-round-Cwk2sFDK.js";import{t as v}from"./pencil-BF1cI2bF.js";import{C as y,F as b,S as x,k as S,l as C,n as w,o as T,w as E,x as D}from"./index-BWNViBw0.js";import{t as O}from"./AdminPage-CCD07UMs.js";n();function k({value:n,size:i=192}){let[a,o]=s(null),[c,d]=s(null);if(u(()=>{let r=!1;return t(()=>import(`./browser-BHo8W_uH.js`).then(t=>e(t.default,1)).then(async e=>{if(r)return;let t=e.create;if(typeof t!=`function`){d(`qrcode.create() unavailable in installed version`);return}try{let e=t(n,{errorCorrectionLevel:`M`});r||o(e)}catch(e){r||d(e instanceof Error?e.message:`QR generation failed`)}}),__vite__mapDeps([0,1])).catch(()=>{r||d(`qrcode library not installed`)}),()=>{r=!0}},[n]),c)return l(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle text-center p-4`,style:{width:i,height:i},children:`QR rendering unavailable — use the secret below.`});if(!a)return l(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle animate-pulse`,style:{width:i,height:i},children:`Generating…`});let f=a.modules.size,p=i/f,m=[];for(let e=0;e<f;e++)for(let t=0;t<f;t++)a.modules.data[e*f+t]&&m.push(l(`rect`,{x:t*p,y:e*p,width:p,height:p,fill:`currentColor`},`${t}-${e}`));return r(`svg`,{width:i,height:i,viewBox:`0 0 ${i} ${i}`,className:`text-black`,children:[l(`rect`,{x:0,y:0,width:i,height:i,fill:`white`}),m]})}n();var A={view:{icon:S,cls:`bg-foreground-subtle/15 text-foreground-subtle`},create:{icon:v,cls:`bg-primary/15 text-primary`},delete:{icon:T,cls:`bg-danger/15 text-danger`}};function j(){let{user:e,logout:t}=w();if(!e)return l(O,{children:l(`div`,{className:`text-xs text-foreground-subtle`,children:`Not signed in.`})});let n=e.isAdmin,i=e.scopes??[];return r(O,{children:[r(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3 flex items-center gap-3`,children:[l(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-full bg-primary/10 text-primary font-semibold text-base`,children:e.username.slice(0,1).toUpperCase()}),r(`div`,{className:`flex-1 min-w-0`,children:[l(`div`,{className:`text-sm font-semibold text-foreground truncate`,children:e.username}),r(`div`,{className:`text-[11px] text-foreground-subtle`,children:[n?`Administrator`:`User`,` · session id`,` `,r(`span`,{className:`font-mono`,children:[e.id.slice(0,8),`…`]})]})]})]}),n&&r(`div`,{className:`rounded-lg border border-primary/30 bg-primary/5 px-4 py-3 text-xs text-foreground flex items-start gap-2.5`,children:[l(E,{className:`h-4 w-4 text-primary mt-0.5 shrink-0`}),r(`div`,{children:[l(`div`,{className:`font-semibold text-foreground`,children:`Unrestricted access`}),l(`p`,{className:`text-foreground-subtle mt-0.5`,children:`Admin sessions bypass the per-call scope check. Every protected endpoint is reachable regardless of the list below.`})]})]}),l(M,{}),l(P,{username:e.username}),l(F,{}),i.length>0&&r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-4 py-2 border-b border-border`,children:[l(`div`,{className:`text-xs font-semibold text-foreground`,children:`Granted scopes`}),l(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Baked into your session token at login; sign out + back in to refresh after changes.`})]}),r(`div`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[l(`div`,{children:`Type`}),l(`div`,{children:`Target`}),l(`div`,{children:`Access`})]}),l(`ul`,{className:`divide-y divide-border`,children:i.map((e,t)=>r(`li`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2.5 items-center text-xs`,children:[l(`span`,{className:`font-mono text-foreground-subtle`,children:e.type}),l(`span`,{className:`font-mono text-foreground`,children:e.type===`device`?f(e.selector):e.target}),l(`div`,{className:`flex items-center gap-1`,children:[`view`,`create`,`delete`].map(t=>{let n=e.access.includes(t),{icon:i,cls:a}=A[t];return r(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${n?a:`bg-transparent text-foreground-subtle/40 line-through`}`,title:n?`Can ${t}`:`Cannot ${t}`,children:[l(i,{className:`h-3 w-3`}),t]},t)})})]},t))})]}),l(`div`,{className:`flex justify-end`,children:r(`button`,{onClick:t,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground transition-colors`,children:[l(D,{className:`h-3 w-3`}),`Sign out`]})})]})}function M(){let e=d(),[t,n]=s(``),[i,a]=s(``),[o,u]=s(``),[f,p]=s(null),m=c({mutationFn:t=>e.changeOwnPassword(t),onSuccess:()=>{p({kind:`success`,msg:`Password updated.`}),n(``),a(``),u(``)},onError:e=>{p({kind:`error`,msg:e instanceof Error?e.message:`Update failed`})}}),g=i.length>0&&o.length>0&&i!==o,v=i.length>0&&i.length<8,S=t.length>=1&&i.length>=8&&i===o;return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[l(_,{className:`h-3.5 w-3.5 text-foreground-subtle`}),l(`div`,{className:`text-xs font-semibold text-foreground`,children:`Change password`})]}),r(`div`,{className:`p-4 space-y-3`,children:[l(N,{label:`Current password`,value:t,onChange:n,autoComplete:`current-password`}),l(N,{label:`New password`,value:i,onChange:a,autoComplete:`new-password`,hint:`At least 8 characters.`}),l(N,{label:`Confirm new password`,value:o,onChange:u,autoComplete:`new-password`}),(g||v)&&l(`div`,{className:`text-[11px] text-danger`,children:g?`Passwords do not match.`:`New password must be at least 8 characters.`}),f&&r(`div`,{className:`text-[11px] flex items-center gap-1 ${f.kind===`success`?`text-emerald-500`:`text-danger`}`,children:[f.kind===`success`?l(h,{className:`h-3 w-3`}):l(b,{className:`h-3 w-3`}),f.msg]}),l(`div`,{className:`flex justify-end`,children:r(`button`,{onClick:()=>{p(null),m.mutate({currentPassword:t,newPassword:i})},disabled:!S||m.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[m.isPending?l(y,{className:`h-3 w-3 animate-spin`}):l(x,{className:`h-3 w-3`}),`Update password`]})})]})]})}function N({label:e,value:t,onChange:n,autoComplete:i,hint:a}){return r(`div`,{className:`space-y-1`,children:[l(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e}),l(`input`,{type:`password`,value:t,onChange:e=>n(e.target.value),autoComplete:i,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),a&&l(`div`,{className:`text-[10px] text-foreground-subtle`,children:a})]})}function P({username:e}){let t=d(),n=a({queryKey:[`auth`,`getOwnTotpStatus`],queryFn:()=>t.getOwnTotpStatus()}),f=n.data,[p,m]=s(null),[_,v]=s(``),[x,S]=s(null),[w,T]=s(!1),E=c({mutationFn:()=>t.setupOwnTotp(),onSuccess:e=>{m({secret:e.secret,otpauthUrl:e.otpauthUrl}),v(``),S(null)},onError:e=>S(e instanceof Error?e.message:`Setup failed`)}),D=c({mutationFn:e=>t.confirmOwnTotp(e),onSuccess:()=>{m(null),v(``),S(null),n.refetch()},onError:e=>S(e instanceof Error?e.message:`Confirmation failed — code did not match`)}),O=c({mutationFn:()=>t.disableOwnTotp(),onSuccess:()=>{S(null),n.refetch()},onError:e=>S(e instanceof Error?e.message:`Disable failed`)});u(()=>{if(!w)return;let e=setTimeout(()=>T(!1),1500);return()=>clearTimeout(e)},[w]);let A=i(()=>n.isLoading?`loading`:p?`setup_in_progress`:f?.enabled?`enrolled`:`not_enrolled`,[n.isLoading,f?.enabled,p]);return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[l(C,{className:`h-3.5 w-3.5 text-foreground-subtle`}),l(`div`,{className:`text-xs font-semibold text-foreground`,children:`Two-factor authentication`})]}),r(`div`,{className:`p-4 space-y-3`,children:[A===`loading`&&r(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[l(y,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),A===`not_enrolled`&&r(o,{children:[l(`div`,{className:`text-xs text-foreground-subtle`,children:`2FA isn't active on your account. Enable it to require a 6-digit code from your authenticator app at every login.`}),l(`div`,{className:`flex justify-end`,children:r(`button`,{onClick:()=>{S(null),E.mutate()},disabled:E.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[E.isPending?l(y,{className:`h-3 w-3 animate-spin`}):l(C,{className:`h-3 w-3`}),`Enable 2FA`]})})]}),A===`setup_in_progress`&&p&&r(o,{children:[r(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`Scan the QR code (or enter the secret manually) into your authenticator app for`,` `,l(`span`,{className:`font-mono`,children:e}),`, then enter the 6-digit code below to confirm.`]}),r(`div`,{className:`flex flex-col items-center gap-3`,children:[l(`div`,{className:`rounded-lg border border-border bg-white p-3`,children:l(k,{value:p.otpauthUrl,size:180})}),r(`div`,{className:`w-full`,children:[l(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle mb-1`,children:`Secret (manual entry)`}),r(`div`,{className:`flex items-center gap-2 rounded border border-border bg-surface-hover/30 px-2 py-1.5`,children:[l(`code`,{className:`text-[11px] font-mono text-foreground break-all flex-1`,children:p.secret}),r(`button`,{onClick:()=>{p&&navigator.clipboard.writeText(p.secret).then(()=>T(!0))},className:`inline-flex items-center gap-1 text-[10px] text-foreground-subtle hover:text-foreground`,children:[w?l(h,{className:`h-3 w-3 text-emerald-500`}):l(g,{className:`h-3 w-3`}),w?`Copied`:`Copy`]})]})]})]}),r(`div`,{className:`space-y-1`,children:[l(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`6-digit code`}),l(`input`,{type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,placeholder:`123456`,value:_,onChange:e=>v(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full rounded-md border border-border bg-surface px-3 py-2 text-center text-lg font-mono tracking-widest text-foreground focus:outline-none focus:ring-2 focus:ring-primary`})]}),x&&r(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[l(b,{className:`h-3 w-3`}),x]}),r(`div`,{className:`flex justify-end gap-2`,children:[l(`button`,{onClick:()=>{m(null),S(null),v(``)},className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),r(`button`,{onClick:()=>{S(null),D.mutate({code:_})},disabled:D.isPending||_.length!==6,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[D.isPending?l(y,{className:`h-3 w-3 animate-spin`}):l(h,{className:`h-3 w-3`}),`Confirm`]})]})]}),A===`enrolled`&&f&&r(o,{children:[r(`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:[l(h,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),r(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[l(`div`,{className:`font-medium`,children:`2FA is active`}),r(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,f.confirmedAt?new Date(f.confirmedAt).toLocaleString():`—`]})]})]}),x&&r(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[l(b,{className:`h-3 w-3`}),x]}),l(`div`,{className:`flex justify-end`,children:r(`button`,{onClick:()=>{S(null),O.mutate()},disabled:O.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:[O.isPending?l(y,{className:`h-3 w-3 animate-spin`}):l(C,{className:`h-3 w-3`}),`Disable 2FA`]})})]})]})]})}function F(){return m(`auth-webauthn/passkey-enrollment`)?l(p,{widgetId:`auth-webauthn/passkey-enrollment`,host:`dashboard`}):null}export{j as MyAccessPage};
@@ -1 +1 @@
1
- import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as l}from"./player-overlays-C82v-qwN.js";import{Ai as u,Bi as d,Fi as f,Gi as p,Hi as m,Ii as h,It as g,Ki as _,Li as v,Lt as y,Mi as b,Ni as x,Nt as S,On as C,Pi as ee,Ri as te,Rt as w,Ui as ne,Vi as T,Wi as E,Xi as D,Xt as O,Yi as re,Zi as ie,ji as ae,ki as oe,kn as k,rt as A,tt as j,vs as M,zi as se}from"./src-BZXGF7UJ.js";import{at as N,et as P}from"./src-BeRVcbbC.js";import{t as F}from"./boxes-DM1XrDXa.js";import{t as I}from"./copy-cBOxpZ8P.js";import{t as L}from"./play-Dvnd56Mu.js";import{t as ce}from"./refresh-cw-MvTOb710.js";import{t as le}from"./rotate-ccw-C8RUMp4_.js";import{t as R}from"./server-HN9uDXhM.js";import{t as z}from"./shield-CZo8EJtJ.js";import{t as B}from"./square-CWz1Ojab.js";import{t as V}from"./wifi-DgVkB_aX.js";import{C as H,E as U,K as W,S as G,a as K,c as ue,j as de,r as fe,x as pe,y as q,z as me}from"./index-JUF-VzOE.js";import{t as he}from"./AdminPage-CCD07UMs.js";import{t as ge}from"./AdminTabs-4zkj5XSp.js";import{t as _e}from"./NodeAddonsSettingsPanel-Ct93rhsv.js";import{t as J}from"./AddonCollectionPage-DWplp-oK.js";import{t as Y}from"./addon-display-names-DvSEQty-.js";var ve=W(`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`}]]),ye=W(`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`}]]),be=W(`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`}]]);t();var X=5e3,xe={connected:!1,endpoint:null};function Se(){let e=a(),t=k({capName:`network-access`},{refetchInterval:X}),n=C(void 0,{refetchInterval:X}),i=r(()=>Y(n.data??[]),[n.data]),c=r(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:i.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,i]),[l,u]=o(null),[d,f]=o({}),p=(t,n)=>{let r=n?.addonId;e.invalidateQueries({queryKey:[[`networkAccess`,`getStatus`],{input:{addonId:r},type:`query`}]}),u(null),f(e=>{if(r===void 0||!(r in e))return e;let t={...e};return delete t[r],t})},m=(e,t)=>{u(null);let n=t?.addonId;if(n===void 0)return;let r=e instanceof Error?e.message:String(e);f(e=>({...e,[n]:r}))},h=D({onSuccess:p,onError:m}),g=ie({onSuccess:p,onError:m});return s(J,{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:U,itemIcon:U,capability:`network-access`,installButtonLabel:`Add tunnel`,items:c,isLoading:t.isLoading,emptyTitle:`No remote-access providers installed`,emptyDescription:`Install a tunnel addon (e.g. @camstack/addon-cloudflare) to expose this hub publicly.`,renderStatusBadges:e=>s(we,{addonId:e.addonId}),itemError:e=>d[e.addonId]??null,renderPrimaryAction:e=>s(Te,{addonId:e.addonId,busyId:l,onStart:e=>{u(e),h.mutate({addonId:e})},onStop:e=>{u(e),g.mutate({addonId:e})}})})}function Ce(e){let{data:t}=re({addonId:e},{refetchInterval:X,retry:!1}),n=t?N.safeParse(t):null;return n?.success?n.data:xe}function we({addonId:e}){let t=Ce(e);return n(i,{children:[s(`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&&n(`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:[s(de,{className:`h-3 w-3`}),t.endpoint.url]})]})}function Te({addonId:e,busyId:t,onStart:r,onStop:i}){let a=Ce(e),o=t===e;return a.connected?n(w,{size:`sm`,variant:`secondary`,disabled:o,onClick:()=>i(e),children:[o?s(H,{className:`h-3 w-3 animate-spin`}):s(B,{className:`h-3 w-3`}),`Stop`]}):n(w,{size:`sm`,variant:`primary`,disabled:o,onClick:()=>r(e),children:[o?s(H,{className:`h-3 w-3 animate-spin`}):s(L,{className:`h-3 w-3`}),`Start`]})}t();var Ee=3e4;function De(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function Oe(){let e=k({capName:`turn-provider`},{refetchInterval:Ee}),t=C(void 0,{refetchInterval:Ee}),i=M(),a=i.data??[],o=r(()=>Y(t.data??[]),[t.data]);return s(J,{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:q,itemIcon:q,capability:`turn-provider`,installButtonLabel:`Add provider`,items:r(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:o.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,o]),isLoading:e.isLoading,emptyTitle:`No TURN providers installed`,emptyDescription:`Install a TURN addon (e.g. @camstack/addon-cloudflare) to enable WebRTC behind restrictive NATs.`,renderExpandedPanel:e=>s(ke,{addonId:e.addonId,enabled:e.isActive}),trailing:n(g,{children:[n(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[n(`div`,{children:[s(`div`,{className:`text-sm font-semibold`,children:`Combined ICE server list`}),s(`div`,{className:`text-xs text-foreground-subtle`,children:`What the WebRTC layer fetches per-session.`})]}),s(w,{size:`sm`,variant:`secondary`,onClick:()=>i.refetch(),disabled:i.isFetching,children:`Refresh`})]}),s(`div`,{className:`p-4`,children:a.length===0?s(`div`,{className:`text-xs text-foreground-subtle`,children:`No servers from enabled providers.`}):s(`div`,{className:`flex flex-col gap-3`,children:a.map((e,t)=>{let r=Array.isArray(e.urls)?e.urls:[e.urls];return n(`div`,{className:`rounded border border-border bg-surface`,children:[(e.username||e.credential)&&n(`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&&n(`span`,{children:[s(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,s(`span`,{className:`text-foreground`,children:e.username})]}),e.credential&&n(`span`,{children:[s(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,s(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),s(`ul`,{className:`divide-y divide-border`,children:r.map(e=>s(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},t)})})})]})})}function ke({addonId:e,enabled:t}){let i=M({addonId:e},{enabled:t,retry:!1}),a=r(()=>De(i.data??[]),[i.data]);return!t||a.length===0?null:n(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[n(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Discovered ICE servers (`,a.length,`)`]}),s(`div`,{className:`flex flex-wrap gap-1`,children:a.map(e=>s(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground`,children:e},e))})]})}t();var Ae={lan:q,wifi:V,docker:F,vpn:G,loopback:R,other:R},je={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},Me=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function Ne(e){let{interfaces:t,disabled:i,hideLoopback:a,ipv4Only:o,emptyMessage:c}=e,l=r(()=>t.filter(e=>!(a&&e.kind===`loopback`||o&&e.family!==`IPv4`)),[t,a,o]),u=r(()=>{let e=new Map;for(let t of l){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return Me.filter(t=>e.has(t)).map(t=>({kind:t,items:e.get(t)}))},[l]),d=t=>e.mode===`single`?e.value===t:e.value.includes(t),f=t=>{if(i||t.kind===`loopback`)return;if(e.mode===`single`){e.onChange(e.value===t.address?null:t.address);return}let n=new Set(e.value);n.has(t.address)?n.delete(t.address):n.add(t.address),e.onChange([...n])};return l.length===0?s(`div`,{className:`text-xs text-foreground-subtle italic`,children:c??`No addresses available.`}):s(`div`,{className:`flex flex-col gap-3`,children:u.map(({kind:t,items:r})=>n(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[n(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[s(Ae[t]??R,{className:`h-3.5 w-3.5 text-foreground-subtle`}),s(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:je[t]??t}),n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,r.length]})]}),s(`ul`,{className:`divide-y divide-border`,children:r.map(t=>{let r=d(t.address),a=t.kind===`loopback`,o=!t.plausible&&!a;return n(`li`,{className:`flex items-center gap-3 px-3 py-2 ${a?`opacity-60 cursor-not-allowed`:i?`opacity-60`:o?`cursor-pointer hover:bg-surface-hover/30 bg-amber-500/[0.04]`:`cursor-pointer hover:bg-surface-hover/30`}`,onClick:()=>f(t),children:[s(`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&&s(me,{className:`h-3 w-3`})}),n(`div`,{className:`flex-1 min-w-0 ${o?`text-foreground-subtle`:``}`,children:[n(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[s(`span`,{className:`font-mono text-xs font-semibold ${o?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),s(`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&&s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:`Auto-preferred`}),a&&s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:`Always included`}),o&&n(`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:[s(K,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]}),n(`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))})}t();var Pe={"lan-ipv4":{label:`IPv4`,className:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`},"lan-ipv6":{label:`IPv6`,className:`bg-violet-500/15 text-violet-700 dark:text-violet-300`},public:{label:`Public`,className:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},loopback:{label:`Loopback`,className:`bg-foreground-subtle/15 text-foreground-subtle`}};function Z(e){return e.kind!==`loopback`}function Fe(e){return e.kind!==`loopback`}function Ie(){let e=a(),t=l(),i=ee(void 0,{refetchInterval:3e4}),f=oe(void 0),p=te({onSuccess:()=>{e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),m=h({onSuccess:t=>{b(t.addresses),e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),_=r(()=>i.data?.interfaces??[],[i.data]),v=u({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}),[y,b]=o([]),[C,ne]=o(!1);c(()=>{!C&&f.data&&(b(f.data.addresses),ne(!0))},[f.data,C]);let T=f.data?.addresses??[],E=r(()=>{if(y.length!==T.length)return!0;let e=[...y].toSorted(),t=[...T].toSorted();return e.some((e,n)=>e!==t[n])},[y,T]),D=()=>{p.mutate({addresses:[...y]})},O=()=>{b(T)},re=()=>{b([])},ie=()=>{i.refetch(),v.refetch(),f.refetch(),A.refetch(),N.refetch()},k=async()=>{try{let e=await t.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info(`[network-addresses] race result`,e)}catch(e){console.warn(`[network-addresses] race failed`,e)}},A=ae(),M=se({onSuccess:()=>void A.refetch()}),N=x(),P=d({onSuccess:()=>void N.refetch()}),F=v.data?.endpoints??[],I=A.data?.baseUrl??null,L=A.data?.resolved??null,R=N.data?.baseUrls??[],z=R.length===0,B=I===null,V=e=>z?e.kind===`lan-ipv4`||e.kind===`public`&&e.interfaceKind===`public`:R.includes(e.baseUrl),H=e=>I===null?L===e.baseUrl:I===e.baseUrl,U=e=>{if(!Z(e))return;let t=z?F.filter(e=>Z(e)&&V(e)).map(e=>e.baseUrl):[...R],n=t.includes(e.baseUrl)?t.filter(t=>t!==e.baseUrl):[...t,e.baseUrl];P.mutate({baseUrls:n})},W=e=>{if(Fe(e)){if(H(e)){B||M.mutate({baseUrl:null});return}M.mutate({baseUrl:e.baseUrl})}},G=r(()=>[{key:`url`,header:`Endpoint`,render:e=>n(`div`,{className:`min-w-0 py-0.5`,children:[s(`div`,{className:`font-mono text-[12px] break-all ${e.plausible?`text-foreground`:`text-foreground-subtle`}`,children:e.baseUrl}),n(`div`,{className:`mt-0.5 flex flex-wrap items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[s(`span`,{children:e.label}),e.interfaceKind!==`lan`&&e.interfaceKind!==`public`&&s(`span`,{className:`uppercase tracking-wide`,children:e.interfaceKind}),!e.plausible&&e.interfaceKind!==`loopback`&&n(`span`,{className:`inline-flex items-center gap-1 text-amber-700 dark:text-amber-300`,title:e.plausibleReason||void 0,children:[s(K,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]})]})},{key:`kind`,header:`Kind`,nowrap:!0,render:e=>{let t=Pe[e.kind]??Pe.loopback;return s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.className}`,children:t.label})}},{key:`viewer`,headerRender:()=>n(`span`,{className:`inline-flex items-center gap-1`,children:[`Viewer`,z?s(`span`,{className:`text-[10px] font-normal normal-case text-foreground-subtle`,children:`auto`}):null]}),align:`center`,nowrap:!0,width:`w-24`,render:e=>{let t=Z(e);return s(`label`,{className:`inline-flex justify-center ${t?`cursor-pointer`:`cursor-not-allowed opacity-40`}`,title:e.kind===`loopback`?`Loopback is not a client route.`:`Use this URL in the API / viewer race.`,children:s(S,{checked:t&&V(e),disabled:!t||P.isPending,onChange:()=>U(e),"aria-label":`Viewer: ${e.baseUrl}`})})}},{key:`notifications`,headerRender:()=>n(`span`,{className:`inline-flex items-center gap-1`,children:[`Notifications`,B?s(`span`,{className:`text-[10px] font-normal normal-case text-foreground-subtle`,children:`auto`}):null]}),align:`center`,nowrap:!0,width:`w-28`,render:e=>{let t=Fe(e);return s(`label`,{className:`inline-flex justify-center ${t?`cursor-pointer`:`cursor-not-allowed opacity-40`}`,title:t?`Notification links and deep links use this address.`:`Loopback is not a client route.`,children:s(S,{checked:t&&H(e),disabled:!t||M.isPending,onChange:()=>W(e),"aria-label":`Notifications: ${e.baseUrl}`})})}}],[z,B,R,I,L,P.isPending,M.isPending,F]);return n(he,{children:[n(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[s(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Pin which host addresses exist, then tick the destinations each URL should serve. Viewer auto is IPv4 + public; every other row (including IPv6) can be ticked on.`}),n(`div`,{className:`flex items-center gap-2 shrink-0`,children:[n(w,{size:`sm`,variant:`secondary`,onClick:ie,disabled:i.isLoading,children:[s(ce,{className:`h-3 w-3 ${i.isLoading?`animate-spin`:``}`}),`Refresh`]}),s(w,{size:`sm`,variant:`secondary`,onClick:k,children:`Probe race`})]})]}),n(g,{children:[n(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between gap-3 flex-wrap`,children:[n(`div`,{children:[s(`div`,{className:`text-sm font-semibold`,children:`Allowed addresses`}),s(`div`,{className:`text-xs text-foreground-subtle`,children:y.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${y.length} pinned`})]}),n(`div`,{className:`flex items-center gap-1`,children:[n(w,{size:`sm`,variant:`secondary`,onClick:()=>m.mutate(void 0),disabled:m.isPending||p.isPending,title:`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`,children:[s(ue,{className:`h-3 w-3`}),m.isPending?`Detecting…`:`Best match`]}),n(w,{size:`sm`,variant:`secondary`,onClick:re,disabled:y.length===0||p.isPending,children:[s(le,{className:`h-3 w-3`}),`Clear`]}),E&&s(w,{size:`sm`,variant:`secondary`,onClick:O,disabled:p.isPending,children:`Discard`}),n(w,{size:`sm`,variant:`primary`,onClick:D,disabled:!E||p.isPending,children:[s(ye,{className:`h-3 w-3`}),p.isPending?`Saving…`:`Save`]})]})]}),s(`div`,{className:`p-4`,children:s(Ne,{mode:`multiple`,interfaces:_,value:y,onChange:b,disabled:p.isPending,emptyMessage:i.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),n(g,{children:[n(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between gap-3 flex-wrap`,children:[n(`div`,{children:[s(`div`,{className:`text-sm font-semibold`,children:`Connection endpoints`}),s(`div`,{className:`text-xs text-foreground-subtle`,children:`Ranked URLs this hub advertises. Tick Viewer (many) and Notifications (one).`})]}),n(`div`,{className:`flex items-center gap-1`,children:[!z&&s(w,{size:`sm`,variant:`secondary`,disabled:P.isPending,onClick:()=>P.mutate({baseUrls:[]}),children:`Viewer → auto`}),!B&&s(w,{size:`sm`,variant:`secondary`,disabled:M.isPending,onClick:()=>M.mutate({baseUrl:null}),children:`Notifications → auto`})]})]}),B&&L===null&&s(`p`,{className:`px-4 pt-3 text-[11px] text-amber-600 dark:text-amber-400`,children:`No public address is reachable, so notification media ships as bytes only — a backend that can only take links (WhatsApp, gotify) receives none.`}),s(j,{columns:G,rows:F,rowKey:e=>`${e.priority}-${e.baseUrl}`,minWidthPx:640,bordered:!1,mobileMode:`scroll`,emptyMessage:v.isLoading?`Loading…`:`No endpoints available.`,rowClassName:e=>e.plausible?void 0:`opacity-80`})]})]})}t();var Le={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},Q=5e3,Re=3e4,ze={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function Be(){let e=k({capName:`mesh-network`},{refetchInterval:Q}),t=C(void 0,{refetchInterval:Q}),n=r(()=>Y(t.data??[]),[t.data]);return s(J,{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:F,itemIcon:q,capability:`mesh-network`,installButtonLabel:`Add mesh`,items:r(()=>(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=>s(Ve,{addonId:e.addonId}),renderPrimaryAction:e=>s(He,{addonId:e.addonId}),renderExpandedPanel:e=>s(Ue,{addonId:e.addonId})})}function $(e){let{data:t,isLoading:n}=m({addonId:e},{refetchInterval:Q,retry:!1}),r=t?P.safeParse(t):null;return{status:r?.success?r.data:ze,isLoading:n}}function Ve({addonId:e}){let{status:t}=$(e);return n(i,{children:[s(`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&&n(`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 He({addonId:t}){let r=a(),[c,u]=o(!1),[d,f]=o(null),m=l(),{status:h}=$(t),g=e(()=>{r.invalidateQueries({queryKey:[[`meshNetwork`]]})},[r]),v=_(),y=ne({onSuccess:g}),b=p({onSuccess:g}),x=e(async()=>{u(!0);let e={cancelled:!1};f(e);try{let n=await v.mutateAsync({addonId:t});if(e.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!e.cancelled&&(await Xe(2e3),!e.cancelled);){let e=await m.trpcClient.meshNetwork.getStatus.query({addonId:t}).catch(()=>null),n=e?P.safeParse(e):null;if(n?.success&&n.data.joined){g();break}if(Date.now()-r>6e5)break}}finally{u(!1),f(null)}},[t,g,v,m]),S=e(()=>{d&&(d.cancelled=!0),u(!1),f(null)},[d]);return s(i,{children:h.joined?n(i,{children:[n(w,{size:`sm`,variant:`secondary`,disabled:y.isPending,onClick:()=>y.mutate({addonId:t}),children:[y.isPending?s(H,{className:`h-3 w-3 animate-spin`}):s(pe,{className:`h-3 w-3`}),`Disconnect`]}),n(w,{size:`sm`,variant:`ghost`,disabled:b.isPending,onClick:()=>b.mutate({addonId:t}),children:[b.isPending?s(H,{className:`h-3 w-3 animate-spin`}):s(be,{className:`h-3 w-3`}),`Log out`]})]}):c?n(w,{size:`sm`,variant:`ghost`,onClick:S,children:[s(fe,{className:`h-3 w-3 mr-1`}),` Cancel`]}):n(i,{children:[n(w,{size:`sm`,variant:`primary`,onClick:()=>void x(),children:[s(ve,{className:`h-3 w-3`}),`Connect`]}),n(w,{size:`sm`,variant:`ghost`,disabled:b.isPending,onClick:()=>b.mutate({addonId:t}),children:[b.isPending?s(H,{className:`h-3 w-3 animate-spin`}):s(be,{className:`h-3 w-3`}),`Log out`]})]})})}function Ue({addonId:e}){let{status:t}=$(e),r=E({addonId:e},{refetchInterval:Re,retry:!1});return n(`div`,{className:`rounded-lg border border-border bg-surface`,children:[n(`div`,{className:`p-4 space-y-4`,children:[t.error&&s(O,{message:t.error}),s(We,{status:t}),t.endpoints.length>0&&n(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Endpoints`}),t.endpoints.map(e=>n(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[n(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${Le[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?s(U,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),n(`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:[s(de,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),s(`div`,{className:`border-t border-border`,children:s(Ke,{peers:r.data?.peers??[],loading:r.isLoading})})]})}function We({status:e}){return s(`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?Ge(e.keyExpiry):`—`}].map(e=>n(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[s(`span`,{className:`text-foreground-subtle shrink-0`,children:e.label}),s(`span`,{className:`text-foreground truncate ${e.mono?`font-mono`:``}`,children:e.value})]},e.label))})}function Ge(e){let t=e-Date.now();if(t<0)return`Expired ${Ye(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 Ke({peers:t,loading:i}){let a=r(()=>t.map(e=>({...e,_id:e.id})),[t]),o=e(e=>{e&&navigator.clipboard?.writeText(e)},[]),c=r(()=>[{key:`hostname`,header:`Hostname`,render:e=>n(`div`,{className:`flex flex-col`,children:[n(`div`,{className:`flex items-center gap-1.5`,children:[s(`span`,{className:`font-medium text-foreground`,children:e.hostname||`(unknown)`}),e.isSelf&&s(y,{variant:`info`,children:`self`}),e.exitNodeOption&&s(y,{variant:`warning`,children:`exit-node`})]}),e.userLogin&&s(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.userLogin})]})},{key:`magicDns`,header:`MagicDNS`,render:e=>e.magicDns?n(`div`,{className:`flex items-center gap-1`,children:[s(`span`,{className:`font-mono text-xs truncate`,children:e.magicDns}),s(`button`,{onClick:()=>o(e.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy MagicDNS`,children:s(I,{className:`h-3 w-3 text-foreground-subtle`})})]}):s(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:e=>{let t=e.addresses[0]??``;return t?n(`div`,{className:`flex items-center gap-1`,children:[s(`span`,{className:`font-mono text-xs`,children:t}),s(`button`,{onClick:()=>o(t),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy IP`,children:s(I,{className:`h-3 w-3 text-foreground-subtle`})})]}):s(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:`Connection`,render:e=>n(`div`,{className:`flex items-center gap-1.5`,children:[s(y,{variant:qe(e.connection),children:e.connection}),e.relay&&s(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.relay})]})},{key:`routes`,header:`Routes`,render:e=>e.advertisedRoutes.length>0?s(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):s(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:`TX / RX`,render:e=>n(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,Je(e.txBytes),` · ↓ `,Je(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>s(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?Ye(e.lastSeenMs):`—`})}],[o]);return i&&t.length===0?n(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[s(H,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):t.length===0?s(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No peers visible — your tailnet may be empty or the host is not joined.`}):s(`div`,{className:`p-4`,children:s(j,{columns:c,rows:a,rowKey:e=>e._id,minWidthPx:820})})}function qe(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function Je(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 Ye(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 Xe(e){return new Promise(t=>setTimeout(t,e))}t();function Ze(e){if(e===null||e===``)return`—`;let t=e.replace(/:/g,``);return t.length<=16?e:`${t.slice(0,8)}…${t.slice(-8)}`}function Qe(){let e=a(),t=b(void 0,{refetchInterval:15e3}),r=f({onSuccess:()=>void e.invalidateQueries({queryKey:[[`localNetwork`]]})}),i=v({onSuccess:()=>void e.invalidateQueries({queryKey:[[`localNetwork`]]})}),c=T({onSuccess:()=>{d(!1),m(``),_(``),x(``),e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),l=t.data,[u,d]=o(!1),[p,m]=o(``),[h,_]=o(``),[y,x]=o(``),S=()=>{if(!l?.caCertPem)return;let e=new Blob([l.caCertPem],{type:`application/x-pem-file`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`camstack-ca.crt`,n.click(),URL.revokeObjectURL(t)},C=l?.mode===`uploaded`?`Uploaded`:l?.mode===`generated`?`Generated local CA`:`TLS disabled`;return n(`div`,{className:`flex flex-col gap-4`,children:[s(_e,{nodeId:`hub`,addonIds:[`local-network`],level:`global`,title:`LAN HTTP`,description:`Native apps on this Wi-Fi use http:// and skip the private certificate. The tunnel and this admin UI stay on HTTPS.`}),n(g,{className:`p-4 space-y-3`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(z,{className:`h-4 w-4 text-foreground-subtle`}),s(`h3`,{className:`text-sm font-semibold`,children:`Certificate`})]}),t.isError&&s(`p`,{className:`text-xs text-danger`,children:`Could not read TLS status.`}),l?.reissueError&&s(`p`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:l.reissueError}),l?.restartRequired&&s(`p`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:`Restart the hub to apply the new certificate.`}),n(`dl`,{className:`grid grid-cols-1 gap-2 text-xs sm:grid-cols-2`,children:[n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`Mode`}),s(`dd`,{className:`font-medium`,children:C})]}),n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`Valid to`}),s(`dd`,{className:`font-mono`,children:l?.validTo?new Date(l.validTo).toLocaleString():`—`})]}),n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`Leaf SHA-256`}),s(`dd`,{className:`font-mono`,title:l?.leafFingerprintSha256??void 0,children:Ze(l?.leafFingerprintSha256??null)})]}),n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`CA SHA-256`}),s(`dd`,{className:`font-mono`,title:l?.caFingerprintSha256??void 0,children:Ze(l?.caFingerprintSha256??null)})]})]}),l&&l.sans.length>0&&s(`div`,{className:`flex flex-wrap gap-1`,children:l.sans.map(e=>s(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 font-mono text-[10px] text-foreground-subtle`,children:e},e))}),n(`div`,{className:`flex flex-wrap gap-2`,children:[s(A,{label:`Regenerate`,title:`Issue a new leaf?`,description:`Issues a new leaf under the current local CA. Clients that trust the CA keep working. The HTTPS listener reloads.`,confirmLabel:`Regenerate`,disabled:l?.mode===`uploaded`||r.isPending,action:()=>r.mutateAsync({})}),s(w,{size:`sm`,variant:`outline`,onClick:()=>d(e=>!e),children:`Upload`}),l?.caCertPem&&s(w,{size:`sm`,variant:`outline`,onClick:S,children:`Download CA`}),l?.mode===`uploaded`&&s(A,{label:`Revert to generated`,title:`Drop the uploaded certificate?`,description:`Deletes the uploaded pair and returns to the generated local CA.`,confirmLabel:`Revert`,confirmVariant:`danger`,disabled:i.isPending,action:()=>i.mutateAsync({})})]}),u&&n(`div`,{className:`space-y-2 border-t border-border pt-3`,children:[n(`label`,{className:`block text-[11px] text-foreground-subtle`,children:[`Certificate PEM`,s(`textarea`,{value:p,onChange:e=>m(e.target.value),rows:6,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`})]}),n(`label`,{className:`block text-[11px] text-foreground-subtle`,children:[`Private key PEM`,s(`textarea`,{value:h,onChange:e=>_(e.target.value),rows:6,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`})]}),n(`label`,{className:`block text-[11px] text-foreground-subtle`,children:[`CA PEM (optional)`,s(`textarea`,{value:y,onChange:e=>x(e.target.value),rows:4,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`})]}),s(w,{size:`sm`,disabled:!p.trim()||!h.trim()||c.isPending,onClick:()=>c.mutate({certPem:p,keyPem:h,...y.trim()?{caPem:y}:{}}),children:`Save certificate`}),c.isError&&s(`p`,{className:`text-xs text-danger`,children:c.error instanceof Error?c.error.message:`Upload failed`})]})]})]})}function $e(){return s(`div`,{className:`flex flex-col p-4`,children:s(ge,{defaultTab:`addresses`,tabs:[{id:`local-access`,label:`Local access`,icon:V,content:s(Qe,{})},{id:`addresses`,label:`Network Addresses`,icon:R,content:s(Ie,{})},{id:`remote-access`,label:`Remote Access`,icon:U,content:s(Se,{})},{id:`mesh`,label:`Mesh Networks`,icon:F,content:s(Be,{})},{id:`turn`,label:`TURN Servers`,icon:q,content:s(Oe,{})}]})})}export{$e as NetworkPage};
1
+ import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as l}from"./player-overlays-BrCS3AFF.js";import{Ai as u,Bi as d,Fi as f,Gi as p,Hi as m,Ii as h,It as g,Ki as _,Li as v,Lt as y,Mi as b,Ni as x,Nt as S,On as C,Pi as ee,Ri as te,Rt as w,Ui as ne,Vi as T,Wi as E,Xi as D,Xt as O,Yi as re,Zi as ie,ji as ae,ki as oe,kn as k,rt as A,tt as j,vs as M,zi as se}from"./src-CTpgEWRF.js";import{at as N,et as P}from"./src-Db_n2ue2.js";import{t as F}from"./boxes-D_EBN2IO.js";import{t as I}from"./copy-2sJiEWo5.js";import{t as L}from"./play-DrhkSF52.js";import{t as ce}from"./refresh-cw-D7w1H6wV.js";import{t as le}from"./rotate-ccw-BSwQUT3g.js";import{t as R}from"./server-DhlXaMrU.js";import{t as z}from"./shield-CAl6DSIT.js";import{t as B}from"./square-DmrJdKXC.js";import{t as V}from"./wifi-ywTK10OM.js";import{C as H,E as U,K as W,S as G,a as K,c as ue,j as de,r as fe,x as pe,y as q,z as me}from"./index-BWNViBw0.js";import{t as he}from"./AdminPage-CCD07UMs.js";import{t as ge}from"./AdminTabs-CR-73Caj.js";import{t as _e}from"./NodeAddonsSettingsPanel-CZgCHLIC.js";import{t as J}from"./AddonCollectionPage-DH55gIbE.js";import{t as Y}from"./addon-display-names-DvSEQty-.js";var ve=W(`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`}]]),ye=W(`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`}]]),be=W(`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`}]]);t();var X=5e3,xe={connected:!1,endpoint:null};function Se(){let e=a(),t=k({capName:`network-access`},{refetchInterval:X}),n=C(void 0,{refetchInterval:X}),i=r(()=>Y(n.data??[]),[n.data]),c=r(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:i.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,i]),[l,u]=o(null),[d,f]=o({}),p=(t,n)=>{let r=n?.addonId;e.invalidateQueries({queryKey:[[`networkAccess`,`getStatus`],{input:{addonId:r},type:`query`}]}),u(null),f(e=>{if(r===void 0||!(r in e))return e;let t={...e};return delete t[r],t})},m=(e,t)=>{u(null);let n=t?.addonId;if(n===void 0)return;let r=e instanceof Error?e.message:String(e);f(e=>({...e,[n]:r}))},h=D({onSuccess:p,onError:m}),g=ie({onSuccess:p,onError:m});return s(J,{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:U,itemIcon:U,capability:`network-access`,installButtonLabel:`Add tunnel`,items:c,isLoading:t.isLoading,emptyTitle:`No remote-access providers installed`,emptyDescription:`Install a tunnel addon (e.g. @camstack/addon-cloudflare) to expose this hub publicly.`,renderStatusBadges:e=>s(we,{addonId:e.addonId}),itemError:e=>d[e.addonId]??null,renderPrimaryAction:e=>s(Te,{addonId:e.addonId,busyId:l,onStart:e=>{u(e),h.mutate({addonId:e})},onStop:e=>{u(e),g.mutate({addonId:e})}})})}function Ce(e){let{data:t}=re({addonId:e},{refetchInterval:X,retry:!1}),n=t?N.safeParse(t):null;return n?.success?n.data:xe}function we({addonId:e}){let t=Ce(e);return n(i,{children:[s(`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&&n(`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:[s(de,{className:`h-3 w-3`}),t.endpoint.url]})]})}function Te({addonId:e,busyId:t,onStart:r,onStop:i}){let a=Ce(e),o=t===e;return a.connected?n(w,{size:`sm`,variant:`secondary`,disabled:o,onClick:()=>i(e),children:[o?s(H,{className:`h-3 w-3 animate-spin`}):s(B,{className:`h-3 w-3`}),`Stop`]}):n(w,{size:`sm`,variant:`primary`,disabled:o,onClick:()=>r(e),children:[o?s(H,{className:`h-3 w-3 animate-spin`}):s(L,{className:`h-3 w-3`}),`Start`]})}t();var Ee=3e4;function De(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function Oe(){let e=k({capName:`turn-provider`},{refetchInterval:Ee}),t=C(void 0,{refetchInterval:Ee}),i=M(),a=i.data??[],o=r(()=>Y(t.data??[]),[t.data]);return s(J,{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:q,itemIcon:q,capability:`turn-provider`,installButtonLabel:`Add provider`,items:r(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:o.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,o]),isLoading:e.isLoading,emptyTitle:`No TURN providers installed`,emptyDescription:`Install a TURN addon (e.g. @camstack/addon-cloudflare) to enable WebRTC behind restrictive NATs.`,renderExpandedPanel:e=>s(ke,{addonId:e.addonId,enabled:e.isActive}),trailing:n(g,{children:[n(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[n(`div`,{children:[s(`div`,{className:`text-sm font-semibold`,children:`Combined ICE server list`}),s(`div`,{className:`text-xs text-foreground-subtle`,children:`What the WebRTC layer fetches per-session.`})]}),s(w,{size:`sm`,variant:`secondary`,onClick:()=>i.refetch(),disabled:i.isFetching,children:`Refresh`})]}),s(`div`,{className:`p-4`,children:a.length===0?s(`div`,{className:`text-xs text-foreground-subtle`,children:`No servers from enabled providers.`}):s(`div`,{className:`flex flex-col gap-3`,children:a.map((e,t)=>{let r=Array.isArray(e.urls)?e.urls:[e.urls];return n(`div`,{className:`rounded border border-border bg-surface`,children:[(e.username||e.credential)&&n(`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&&n(`span`,{children:[s(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,s(`span`,{className:`text-foreground`,children:e.username})]}),e.credential&&n(`span`,{children:[s(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,s(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),s(`ul`,{className:`divide-y divide-border`,children:r.map(e=>s(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},t)})})})]})})}function ke({addonId:e,enabled:t}){let i=M({addonId:e},{enabled:t,retry:!1}),a=r(()=>De(i.data??[]),[i.data]);return!t||a.length===0?null:n(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[n(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Discovered ICE servers (`,a.length,`)`]}),s(`div`,{className:`flex flex-wrap gap-1`,children:a.map(e=>s(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground`,children:e},e))})]})}t();var Ae={lan:q,wifi:V,docker:F,vpn:G,loopback:R,other:R},je={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},Me=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function Ne(e){let{interfaces:t,disabled:i,hideLoopback:a,ipv4Only:o,emptyMessage:c}=e,l=r(()=>t.filter(e=>!(a&&e.kind===`loopback`||o&&e.family!==`IPv4`)),[t,a,o]),u=r(()=>{let e=new Map;for(let t of l){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return Me.filter(t=>e.has(t)).map(t=>({kind:t,items:e.get(t)}))},[l]),d=t=>e.mode===`single`?e.value===t:e.value.includes(t),f=t=>{if(i||t.kind===`loopback`)return;if(e.mode===`single`){e.onChange(e.value===t.address?null:t.address);return}let n=new Set(e.value);n.has(t.address)?n.delete(t.address):n.add(t.address),e.onChange([...n])};return l.length===0?s(`div`,{className:`text-xs text-foreground-subtle italic`,children:c??`No addresses available.`}):s(`div`,{className:`flex flex-col gap-3`,children:u.map(({kind:t,items:r})=>n(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[n(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[s(Ae[t]??R,{className:`h-3.5 w-3.5 text-foreground-subtle`}),s(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:je[t]??t}),n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,r.length]})]}),s(`ul`,{className:`divide-y divide-border`,children:r.map(t=>{let r=d(t.address),a=t.kind===`loopback`,o=!t.plausible&&!a;return n(`li`,{className:`flex items-center gap-3 px-3 py-2 ${a?`opacity-60 cursor-not-allowed`:i?`opacity-60`:o?`cursor-pointer hover:bg-surface-hover/30 bg-amber-500/[0.04]`:`cursor-pointer hover:bg-surface-hover/30`}`,onClick:()=>f(t),children:[s(`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&&s(me,{className:`h-3 w-3`})}),n(`div`,{className:`flex-1 min-w-0 ${o?`text-foreground-subtle`:``}`,children:[n(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[s(`span`,{className:`font-mono text-xs font-semibold ${o?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),s(`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&&s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:`Auto-preferred`}),a&&s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:`Always included`}),o&&n(`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:[s(K,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]}),n(`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))})}t();var Pe={"lan-ipv4":{label:`IPv4`,className:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`},"lan-ipv6":{label:`IPv6`,className:`bg-violet-500/15 text-violet-700 dark:text-violet-300`},public:{label:`Public`,className:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},loopback:{label:`Loopback`,className:`bg-foreground-subtle/15 text-foreground-subtle`}};function Z(e){return e.kind!==`loopback`}function Fe(e){return e.kind!==`loopback`}function Ie(){let e=a(),t=l(),i=ee(void 0,{refetchInterval:3e4}),f=oe(void 0),p=te({onSuccess:()=>{e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),m=h({onSuccess:t=>{b(t.addresses),e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),_=r(()=>i.data?.interfaces??[],[i.data]),v=u({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}),[y,b]=o([]),[C,ne]=o(!1);c(()=>{!C&&f.data&&(b(f.data.addresses),ne(!0))},[f.data,C]);let T=f.data?.addresses??[],E=r(()=>{if(y.length!==T.length)return!0;let e=[...y].toSorted(),t=[...T].toSorted();return e.some((e,n)=>e!==t[n])},[y,T]),D=()=>{p.mutate({addresses:[...y]})},O=()=>{b(T)},re=()=>{b([])},ie=()=>{i.refetch(),v.refetch(),f.refetch(),A.refetch(),N.refetch()},k=async()=>{try{let e=await t.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info(`[network-addresses] race result`,e)}catch(e){console.warn(`[network-addresses] race failed`,e)}},A=ae(),M=se({onSuccess:()=>void A.refetch()}),N=x(),P=d({onSuccess:()=>void N.refetch()}),F=v.data?.endpoints??[],I=A.data?.baseUrl??null,L=A.data?.resolved??null,R=N.data?.baseUrls??[],z=R.length===0,B=I===null,V=e=>z?e.kind===`lan-ipv4`||e.kind===`public`&&e.interfaceKind===`public`:R.includes(e.baseUrl),H=e=>I===null?L===e.baseUrl:I===e.baseUrl,U=e=>{if(!Z(e))return;let t=z?F.filter(e=>Z(e)&&V(e)).map(e=>e.baseUrl):[...R],n=t.includes(e.baseUrl)?t.filter(t=>t!==e.baseUrl):[...t,e.baseUrl];P.mutate({baseUrls:n})},W=e=>{if(Fe(e)){if(H(e)){B||M.mutate({baseUrl:null});return}M.mutate({baseUrl:e.baseUrl})}},G=r(()=>[{key:`url`,header:`Endpoint`,render:e=>n(`div`,{className:`min-w-0 py-0.5`,children:[s(`div`,{className:`font-mono text-[12px] break-all ${e.plausible?`text-foreground`:`text-foreground-subtle`}`,children:e.baseUrl}),n(`div`,{className:`mt-0.5 flex flex-wrap items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[s(`span`,{children:e.label}),e.interfaceKind!==`lan`&&e.interfaceKind!==`public`&&s(`span`,{className:`uppercase tracking-wide`,children:e.interfaceKind}),!e.plausible&&e.interfaceKind!==`loopback`&&n(`span`,{className:`inline-flex items-center gap-1 text-amber-700 dark:text-amber-300`,title:e.plausibleReason||void 0,children:[s(K,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]})]})},{key:`kind`,header:`Kind`,nowrap:!0,render:e=>{let t=Pe[e.kind]??Pe.loopback;return s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.className}`,children:t.label})}},{key:`viewer`,headerRender:()=>n(`span`,{className:`inline-flex items-center gap-1`,children:[`Viewer`,z?s(`span`,{className:`text-[10px] font-normal normal-case text-foreground-subtle`,children:`auto`}):null]}),align:`center`,nowrap:!0,width:`w-24`,render:e=>{let t=Z(e);return s(`label`,{className:`inline-flex justify-center ${t?`cursor-pointer`:`cursor-not-allowed opacity-40`}`,title:e.kind===`loopback`?`Loopback is not a client route.`:`Use this URL in the API / viewer race.`,children:s(S,{checked:t&&V(e),disabled:!t||P.isPending,onChange:()=>U(e),"aria-label":`Viewer: ${e.baseUrl}`})})}},{key:`notifications`,headerRender:()=>n(`span`,{className:`inline-flex items-center gap-1`,children:[`Notifications`,B?s(`span`,{className:`text-[10px] font-normal normal-case text-foreground-subtle`,children:`auto`}):null]}),align:`center`,nowrap:!0,width:`w-28`,render:e=>{let t=Fe(e);return s(`label`,{className:`inline-flex justify-center ${t?`cursor-pointer`:`cursor-not-allowed opacity-40`}`,title:t?`Notification links and deep links use this address.`:`Loopback is not a client route.`,children:s(S,{checked:t&&H(e),disabled:!t||M.isPending,onChange:()=>W(e),"aria-label":`Notifications: ${e.baseUrl}`})})}}],[z,B,R,I,L,P.isPending,M.isPending,F]);return n(he,{children:[n(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[s(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Pin which host addresses exist, then tick the destinations each URL should serve. Viewer auto is IPv4 + public; every other row (including IPv6) can be ticked on.`}),n(`div`,{className:`flex items-center gap-2 shrink-0`,children:[n(w,{size:`sm`,variant:`secondary`,onClick:ie,disabled:i.isLoading,children:[s(ce,{className:`h-3 w-3 ${i.isLoading?`animate-spin`:``}`}),`Refresh`]}),s(w,{size:`sm`,variant:`secondary`,onClick:k,children:`Probe race`})]})]}),n(g,{children:[n(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between gap-3 flex-wrap`,children:[n(`div`,{children:[s(`div`,{className:`text-sm font-semibold`,children:`Allowed addresses`}),s(`div`,{className:`text-xs text-foreground-subtle`,children:y.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${y.length} pinned`})]}),n(`div`,{className:`flex items-center gap-1`,children:[n(w,{size:`sm`,variant:`secondary`,onClick:()=>m.mutate(void 0),disabled:m.isPending||p.isPending,title:`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`,children:[s(ue,{className:`h-3 w-3`}),m.isPending?`Detecting…`:`Best match`]}),n(w,{size:`sm`,variant:`secondary`,onClick:re,disabled:y.length===0||p.isPending,children:[s(le,{className:`h-3 w-3`}),`Clear`]}),E&&s(w,{size:`sm`,variant:`secondary`,onClick:O,disabled:p.isPending,children:`Discard`}),n(w,{size:`sm`,variant:`primary`,onClick:D,disabled:!E||p.isPending,children:[s(ye,{className:`h-3 w-3`}),p.isPending?`Saving…`:`Save`]})]})]}),s(`div`,{className:`p-4`,children:s(Ne,{mode:`multiple`,interfaces:_,value:y,onChange:b,disabled:p.isPending,emptyMessage:i.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),n(g,{children:[n(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between gap-3 flex-wrap`,children:[n(`div`,{children:[s(`div`,{className:`text-sm font-semibold`,children:`Connection endpoints`}),s(`div`,{className:`text-xs text-foreground-subtle`,children:`Ranked URLs this hub advertises. Tick Viewer (many) and Notifications (one).`})]}),n(`div`,{className:`flex items-center gap-1`,children:[!z&&s(w,{size:`sm`,variant:`secondary`,disabled:P.isPending,onClick:()=>P.mutate({baseUrls:[]}),children:`Viewer → auto`}),!B&&s(w,{size:`sm`,variant:`secondary`,disabled:M.isPending,onClick:()=>M.mutate({baseUrl:null}),children:`Notifications → auto`})]})]}),B&&L===null&&s(`p`,{className:`px-4 pt-3 text-[11px] text-amber-600 dark:text-amber-400`,children:`No public address is reachable, so notification media ships as bytes only — a backend that can only take links (WhatsApp, gotify) receives none.`}),s(j,{columns:G,rows:F,rowKey:e=>`${e.priority}-${e.baseUrl}`,minWidthPx:640,bordered:!1,mobileMode:`scroll`,emptyMessage:v.isLoading?`Loading…`:`No endpoints available.`,rowClassName:e=>e.plausible?void 0:`opacity-80`})]})]})}t();var Le={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},Q=5e3,Re=3e4,ze={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function Be(){let e=k({capName:`mesh-network`},{refetchInterval:Q}),t=C(void 0,{refetchInterval:Q}),n=r(()=>Y(t.data??[]),[t.data]);return s(J,{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:F,itemIcon:q,capability:`mesh-network`,installButtonLabel:`Add mesh`,items:r(()=>(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=>s(Ve,{addonId:e.addonId}),renderPrimaryAction:e=>s(He,{addonId:e.addonId}),renderExpandedPanel:e=>s(Ue,{addonId:e.addonId})})}function $(e){let{data:t,isLoading:n}=m({addonId:e},{refetchInterval:Q,retry:!1}),r=t?P.safeParse(t):null;return{status:r?.success?r.data:ze,isLoading:n}}function Ve({addonId:e}){let{status:t}=$(e);return n(i,{children:[s(`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&&n(`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 He({addonId:t}){let r=a(),[c,u]=o(!1),[d,f]=o(null),m=l(),{status:h}=$(t),g=e(()=>{r.invalidateQueries({queryKey:[[`meshNetwork`]]})},[r]),v=_(),y=ne({onSuccess:g}),b=p({onSuccess:g}),x=e(async()=>{u(!0);let e={cancelled:!1};f(e);try{let n=await v.mutateAsync({addonId:t});if(e.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!e.cancelled&&(await Xe(2e3),!e.cancelled);){let e=await m.trpcClient.meshNetwork.getStatus.query({addonId:t}).catch(()=>null),n=e?P.safeParse(e):null;if(n?.success&&n.data.joined){g();break}if(Date.now()-r>6e5)break}}finally{u(!1),f(null)}},[t,g,v,m]),S=e(()=>{d&&(d.cancelled=!0),u(!1),f(null)},[d]);return s(i,{children:h.joined?n(i,{children:[n(w,{size:`sm`,variant:`secondary`,disabled:y.isPending,onClick:()=>y.mutate({addonId:t}),children:[y.isPending?s(H,{className:`h-3 w-3 animate-spin`}):s(pe,{className:`h-3 w-3`}),`Disconnect`]}),n(w,{size:`sm`,variant:`ghost`,disabled:b.isPending,onClick:()=>b.mutate({addonId:t}),children:[b.isPending?s(H,{className:`h-3 w-3 animate-spin`}):s(be,{className:`h-3 w-3`}),`Log out`]})]}):c?n(w,{size:`sm`,variant:`ghost`,onClick:S,children:[s(fe,{className:`h-3 w-3 mr-1`}),` Cancel`]}):n(i,{children:[n(w,{size:`sm`,variant:`primary`,onClick:()=>void x(),children:[s(ve,{className:`h-3 w-3`}),`Connect`]}),n(w,{size:`sm`,variant:`ghost`,disabled:b.isPending,onClick:()=>b.mutate({addonId:t}),children:[b.isPending?s(H,{className:`h-3 w-3 animate-spin`}):s(be,{className:`h-3 w-3`}),`Log out`]})]})})}function Ue({addonId:e}){let{status:t}=$(e),r=E({addonId:e},{refetchInterval:Re,retry:!1});return n(`div`,{className:`rounded-lg border border-border bg-surface`,children:[n(`div`,{className:`p-4 space-y-4`,children:[t.error&&s(O,{message:t.error}),s(We,{status:t}),t.endpoints.length>0&&n(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Endpoints`}),t.endpoints.map(e=>n(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[n(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${Le[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?s(U,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),n(`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:[s(de,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),s(`div`,{className:`border-t border-border`,children:s(Ke,{peers:r.data?.peers??[],loading:r.isLoading})})]})}function We({status:e}){return s(`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?Ge(e.keyExpiry):`—`}].map(e=>n(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[s(`span`,{className:`text-foreground-subtle shrink-0`,children:e.label}),s(`span`,{className:`text-foreground truncate ${e.mono?`font-mono`:``}`,children:e.value})]},e.label))})}function Ge(e){let t=e-Date.now();if(t<0)return`Expired ${Ye(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 Ke({peers:t,loading:i}){let a=r(()=>t.map(e=>({...e,_id:e.id})),[t]),o=e(e=>{e&&navigator.clipboard?.writeText(e)},[]),c=r(()=>[{key:`hostname`,header:`Hostname`,render:e=>n(`div`,{className:`flex flex-col`,children:[n(`div`,{className:`flex items-center gap-1.5`,children:[s(`span`,{className:`font-medium text-foreground`,children:e.hostname||`(unknown)`}),e.isSelf&&s(y,{variant:`info`,children:`self`}),e.exitNodeOption&&s(y,{variant:`warning`,children:`exit-node`})]}),e.userLogin&&s(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.userLogin})]})},{key:`magicDns`,header:`MagicDNS`,render:e=>e.magicDns?n(`div`,{className:`flex items-center gap-1`,children:[s(`span`,{className:`font-mono text-xs truncate`,children:e.magicDns}),s(`button`,{onClick:()=>o(e.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy MagicDNS`,children:s(I,{className:`h-3 w-3 text-foreground-subtle`})})]}):s(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:e=>{let t=e.addresses[0]??``;return t?n(`div`,{className:`flex items-center gap-1`,children:[s(`span`,{className:`font-mono text-xs`,children:t}),s(`button`,{onClick:()=>o(t),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy IP`,children:s(I,{className:`h-3 w-3 text-foreground-subtle`})})]}):s(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:`Connection`,render:e=>n(`div`,{className:`flex items-center gap-1.5`,children:[s(y,{variant:qe(e.connection),children:e.connection}),e.relay&&s(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.relay})]})},{key:`routes`,header:`Routes`,render:e=>e.advertisedRoutes.length>0?s(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):s(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:`TX / RX`,render:e=>n(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,Je(e.txBytes),` · ↓ `,Je(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>s(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?Ye(e.lastSeenMs):`—`})}],[o]);return i&&t.length===0?n(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[s(H,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):t.length===0?s(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No peers visible — your tailnet may be empty or the host is not joined.`}):s(`div`,{className:`p-4`,children:s(j,{columns:c,rows:a,rowKey:e=>e._id,minWidthPx:820})})}function qe(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function Je(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 Ye(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 Xe(e){return new Promise(t=>setTimeout(t,e))}t();function Ze(e){if(e===null||e===``)return`—`;let t=e.replace(/:/g,``);return t.length<=16?e:`${t.slice(0,8)}…${t.slice(-8)}`}function Qe(){let e=a(),t=b(void 0,{refetchInterval:15e3}),r=f({onSuccess:()=>void e.invalidateQueries({queryKey:[[`localNetwork`]]})}),i=v({onSuccess:()=>void e.invalidateQueries({queryKey:[[`localNetwork`]]})}),c=T({onSuccess:()=>{d(!1),m(``),_(``),x(``),e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),l=t.data,[u,d]=o(!1),[p,m]=o(``),[h,_]=o(``),[y,x]=o(``),S=()=>{if(!l?.caCertPem)return;let e=new Blob([l.caCertPem],{type:`application/x-pem-file`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`camstack-ca.crt`,n.click(),URL.revokeObjectURL(t)},C=l?.mode===`uploaded`?`Uploaded`:l?.mode===`generated`?`Generated local CA`:`TLS disabled`;return n(`div`,{className:`flex flex-col gap-4`,children:[s(_e,{nodeId:`hub`,addonIds:[`local-network`],level:`global`,title:`LAN HTTP`,description:`Native apps on this Wi-Fi use http:// and skip the private certificate. The tunnel and this admin UI stay on HTTPS.`}),n(g,{className:`p-4 space-y-3`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(z,{className:`h-4 w-4 text-foreground-subtle`}),s(`h3`,{className:`text-sm font-semibold`,children:`Certificate`})]}),t.isError&&s(`p`,{className:`text-xs text-danger`,children:`Could not read TLS status.`}),l?.reissueError&&s(`p`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:l.reissueError}),l?.restartRequired&&s(`p`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:`Restart the hub to apply the new certificate.`}),n(`dl`,{className:`grid grid-cols-1 gap-2 text-xs sm:grid-cols-2`,children:[n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`Mode`}),s(`dd`,{className:`font-medium`,children:C})]}),n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`Valid to`}),s(`dd`,{className:`font-mono`,children:l?.validTo?new Date(l.validTo).toLocaleString():`—`})]}),n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`Leaf SHA-256`}),s(`dd`,{className:`font-mono`,title:l?.leafFingerprintSha256??void 0,children:Ze(l?.leafFingerprintSha256??null)})]}),n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`CA SHA-256`}),s(`dd`,{className:`font-mono`,title:l?.caFingerprintSha256??void 0,children:Ze(l?.caFingerprintSha256??null)})]})]}),l&&l.sans.length>0&&s(`div`,{className:`flex flex-wrap gap-1`,children:l.sans.map(e=>s(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 font-mono text-[10px] text-foreground-subtle`,children:e},e))}),n(`div`,{className:`flex flex-wrap gap-2`,children:[s(A,{label:`Regenerate`,title:`Issue a new leaf?`,description:`Issues a new leaf under the current local CA. Clients that trust the CA keep working. The HTTPS listener reloads.`,confirmLabel:`Regenerate`,disabled:l?.mode===`uploaded`||r.isPending,action:()=>r.mutateAsync({})}),s(w,{size:`sm`,variant:`outline`,onClick:()=>d(e=>!e),children:`Upload`}),l?.caCertPem&&s(w,{size:`sm`,variant:`outline`,onClick:S,children:`Download CA`}),l?.mode===`uploaded`&&s(A,{label:`Revert to generated`,title:`Drop the uploaded certificate?`,description:`Deletes the uploaded pair and returns to the generated local CA.`,confirmLabel:`Revert`,confirmVariant:`danger`,disabled:i.isPending,action:()=>i.mutateAsync({})})]}),u&&n(`div`,{className:`space-y-2 border-t border-border pt-3`,children:[n(`label`,{className:`block text-[11px] text-foreground-subtle`,children:[`Certificate PEM`,s(`textarea`,{value:p,onChange:e=>m(e.target.value),rows:6,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`})]}),n(`label`,{className:`block text-[11px] text-foreground-subtle`,children:[`Private key PEM`,s(`textarea`,{value:h,onChange:e=>_(e.target.value),rows:6,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`})]}),n(`label`,{className:`block text-[11px] text-foreground-subtle`,children:[`CA PEM (optional)`,s(`textarea`,{value:y,onChange:e=>x(e.target.value),rows:4,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`})]}),s(w,{size:`sm`,disabled:!p.trim()||!h.trim()||c.isPending,onClick:()=>c.mutate({certPem:p,keyPem:h,...y.trim()?{caPem:y}:{}}),children:`Save certificate`}),c.isError&&s(`p`,{className:`text-xs text-danger`,children:c.error instanceof Error?c.error.message:`Upload failed`})]})]})]})}function $e(){return s(`div`,{className:`flex flex-col p-4`,children:s(ge,{defaultTab:`addresses`,tabs:[{id:`local-access`,label:`Local access`,icon:V,content:s(Qe,{})},{id:`addresses`,label:`Network Addresses`,icon:R,content:s(Ie,{})},{id:`remote-access`,label:`Remote Access`,icon:U,content:s(Se,{})},{id:`mesh`,label:`Mesh Networks`,icon:F,content:s(Be,{})},{id:`turn`,label:`TURN Servers`,icon:q,content:s(Oe,{})}]})})}export{$e as NetworkPage};
@@ -1 +1 @@
1
- import{H as e,I as t,K as n,Q as r,S as i,W as a,b as o,i as s,k as c,o as l,p as u,q as d,t as f,x as p,z as m}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as h}from"./player-overlays-C82v-qwN.js";import{Jn as g,On as _,bn as v,gr as y,yn as ee}from"./src-BZXGF7UJ.js";import{zt as b}from"./src-BeRVcbbC.js";import{t as x}from"./FormBuilder-D_bhTf6T.js";import{n as te,r as S,t as ne}from"./SchemaTabBar-DC28nb9j.js";import{t as re}from"./StableTabPanel-Dc954AQl.js";r();var C=c(function({addonId:r,schema:i,serverValues:o,onImmediateSave:s,onStateChange:c,onAction:l,disabled:u},d){let f=S({schema:i,serverValues:o,onImmediateSave:t(e=>s(r,e),[r,s]),onDeferredSave:t(()=>{},[])});e(d,()=>({flush:()=>{let e={};for(let t of f.pendingKeys)e[t]=f.values[t];return f.handleDiscard(f.pendingKeys),e},discard:()=>f.resetAll()}),[f]);let h=f.pendingKeys,g=h.join(`|`),_=a(()=>h.map(e=>`${e}=${JSON.stringify(f.values[e])}`).join(`,`),[h,f.values]),v=n(c);m(()=>{v.current=c},[c]),m(()=>{let e={};for(let t of h)e[t]=f.values[t];v.current({addonId:r,pendingKeys:h,pendingValues:e})},[r,g,_]);let y=a(()=>{if(l)return(e,t,n)=>l(r,e,t,n)},[r,l]);return p(x,{schema:i,values:f.values,onChange:f.handleChange,disabled:u,onAction:y})});function w(e){return`perNode`in e&&e.perNode===!0}function T(e,t){if(e.type===`group`){let n=E(e.fields,t);return n.length>0?{...e,fields:n}:null}if(e.type===`sub-tabs`){let n=e.tabs.map(e=>({...e,fields:E(e.fields,t)})).filter(e=>e.fields.length>0);return n.length>0?{...e,tabs:n}:null}return w(e)===(t===`perNode`)?e:null}function E(e,t){let n=[];for(let r of e){let e=T(r,t);e!==null&&n.push(e)}return n}function ie(e,t){let n=[];for(let r of e.sections){let e=E(r.fields,t);e.length!==0&&n.push({...r,fields:e})}return{...e,sections:n}}var ae={integration:`Integration-wide settings — one value shared by every device this integration provides. These are not per-device settings: a change here applies to all of them. The same values are also reachable under System → Settings, and both write the same place.`};function D(e){return e==null?!1:e.sections.some(e=>e.fields.length>0)}r();function O(e,t){if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`){let n=e.fields.map(e=>O(e,t));return{...e,fields:n}}let n=e;t[e.key]=n.value;let{value:r,...i}=n;return i}function k(e,t){return{...e,fields:e.fields.map(e=>O(e,t))}}function oe(e){let t={};return{schema:{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>k(e,t))},values:t}}function A({nodeId:e,addonIds:r,level:c,deviceId:m,capability:x,sectionIds:S,sectionTab:C,fieldScope:w,surface:T,emptyMessage:E,extraTabs:D,schemaTabExtras:O,title:k,description:A,selfTabbed:ce}){let j=l(),M=h().trpcClient,N=v(),P=ee(),F=y(),I=g(),L=ce===!0||!!(D&&D.length>0),[R,le]=d(null);if(c===`device`&&!m)throw Error(`NodeAddonsSettingsPanel: deviceId is required when level === "device"`);if(T!==void 0){if(c!==`global`||m!==void 0)throw Error(`NodeAddonsSettingsPanel: integration-level settings are addon-wide — they cannot be mounted at device level or with a deviceId. A second page, never a second scope.`);if(e!==null)throw Error(`NodeAddonsSettingsPanel: an integration has no node behind it — pass nodeId={null}. Received ${JSON.stringify(e)}.`);if(w!==void 0)throw Error("NodeAddonsSettingsPanel: integration-level settings arrive already cluster-scoped from core — remove `fieldScope` rather than restating it.")}let z=e??`hub`,B=s({queries:r.map(e=>({queryKey:[[`addonSettings`,T===void 0?c===`global`?`getGlobalSettings`:`getDeviceSettings`:`getIntegrationSettings`],{addonId:e,nodeId:z,deviceId:m??null,cap:x??null,scope:w??null}],queryFn:async()=>{let t=e=>e!==null&&w!==void 0?ie(e,w):e;return T===void 0?c===`global`?{addonId:e,result:t(await M.addonSettings.getGlobalSettings.query({addonId:e,nodeId:z,...x?{cap:x}:{}}))}:{addonId:e,result:t(await M.addonSettings.getDeviceSettings.query({addonId:e,deviceId:m,nodeId:z}))}:{addonId:e,result:await M.addonSettings.getIntegrationSettings.query({addonId:e,nodeId:z})}},placeholderData:u}))}),V=B.some(e=>e.isLoading),H=B.map(e=>{if(!e.data)return`-`;if(e.data.result===null)return`${e.data.addonId}:n`;let t=[];for(let n of e.data.result.sections){t.push(`s:${n.id}:${n.tab??`general`}`);for(let e of n.fields){if(!(`key`in e))continue;let n=`options`in e&&Array.isArray(e.options)?e.options.map(e=>e.value).join(`,`):``,r=e.value,i=r===void 0?``:typeof r==`string`?r:JSON.stringify(r);t.push(`f:${e.key}:${n}:${i}`)}}return`${e.data.addonId}:${t.join(`|`)}`}).join(`||`),U=a(()=>{let e=new Set;for(let t of B){let n=t.data?.result?.sections;if(n)for(let t of n)e.add(t.tab??`general`)}return[...e]},[H+`::`+B.map(e=>(e.data?.result?.sections??[]).map(e=>e.tab??`general`).join(`,`)).join(`::`)]),W=a(()=>new Map((D??[]).map(e=>[e.id,e])),[D]),G=a(()=>{if(!L)return[];let e=[...new Set([...U,...(D??[]).map(e=>e.id),...(O??[]).map(e=>e.tabId)])],t=e=>{let t=W.get(e);if(t?.order!==void 0)return t.order;let n=b[e];return n?n.order:50};return e.toSorted((e,n)=>{let r=t(e),i=t(n);return r===i?e.localeCompare(n):r-i})},[L,U,D,W,O]),ue=a(()=>{let e=new Map,t=e=>b[e]?.label??e.charAt(0).toUpperCase()+e.slice(1);for(let n of U)e.set(n,t(n));for(let n of O??[])e.has(n.tabId)||e.set(n.tabId,t(n.tabId));for(let t of D??[])e.set(t.id,t.label);return e},[U,D,O]),K=L?R&&G.includes(R)?R:G[0]??null:null,de=K!==null&&W.has(K),q=L?K&&!de?K:void 0:C,{data:fe}=_(void 0),pe=a(()=>{let e=new Map;for(let t of fe??[]){let n=t.manifest?.id;if(!n)continue;let r=t.manifest?.name??t.manifest?.packageDisplayName??n;e.set(n,r)}return e},[fe]),me=n(new Map),J=a(()=>{let e=S?new Set(S):null,t=[];for(let n of B){if(!n.data)continue;let r=n.data.result??me.current.get(n.data.addonId)??null;if(n.data.result!==null&&me.current.set(n.data.addonId,n.data.result),r===null)continue;let{schema:i,values:a}=oe(r),o=i.sections.filter(t=>e?e.has(t.id):!0);if(o.length===0)continue;let s={...r,sections:r.sections.filter(t=>e?e.has(t.id):!0)},c={...i,sections:o};t.push({addonId:n.data.addonId,schemaWithValues:s,schema:c,serverValues:a})}return t},[H,S]),[Y,he]=d(new Map),ge=t(e=>{he(t=>{let n=new Map(t);return n.set(e.addonId,e),n})},[]),X=n(new Map),_e=t(e=>t=>{t?X.current.set(e,t):X.current.delete(e)},[]),ve=t(async(e,t)=>{c===`global`?await N.mutateAsync({addonId:e,nodeId:z,patch:t}):await P.mutateAsync({addonId:e,deviceId:m,nodeId:z,patch:t}),j.invalidateQueries({queryKey:[[`addonSettings`]]})},[N,P,z,c,m,j]),ye=t(async(e,t,n,r)=>{let i=z;try{switch(t){case`reprobe-hwaccel`:await F.mutateAsync({nodeId:i}),j.invalidateQueries({queryKey:[[`addonSettings`]]});return;case`reprobe-audio-engine`:await I.mutateAsync({nodeId:i}),j.invalidateQueries({queryKey:[[`addonSettings`]]});return;default:{let n=await M.addons.custom.mutate({addonId:e,action:t,input:r});return j.invalidateQueries({queryKey:[[`addonSettings`]]}),n}}}catch(n){throw console.error(`[NodeAddonsSettingsPanel] action failed`,{addonId:e,action:t,err:n}),n}},[F,I,z,j,M]),be=t((e,t)=>{ve(e,t)},[ve]),Z=f({mutationFn:async()=>{let e=[];for(let t of J){let n=Y.get(t.addonId);!n||n.pendingKeys.length===0||e.push({addonId:t.addonId,patch:n.pendingValues})}return e.length===0?{saved:[]}:{saved:await Promise.all(e.map(async({addonId:e,patch:t})=>(c===`global`?await N.mutateAsync({addonId:e,nodeId:z,patch:t}):await P.mutateAsync({addonId:e,deviceId:m,nodeId:z,patch:t}),e)))}},onSuccess:({saved:e})=>{for(let t of e)X.current.get(t)?.discard();j.invalidateQueries({queryKey:[[`addonSettings`]]})}}),xe=t(()=>{for(let e of X.current.values())e.discard()},[]),Se=a(()=>{let e=0;for(let t of J){let n=Y.get(t.addonId);n&&(e+=n.pendingKeys.length)}return e},[J,Y]),Ce=a(()=>{let e=new Map;for(let t of J){let n=Y.get(t.addonId);if(!n||n.pendingKeys.length===0)continue;let r=new Set(n.pendingKeys);for(let n of t.schema.sections){let t=n.tab??`general`;for(let i of n.fields)`key`in i&&r.has(i.key)&&e.set(t,(e.get(t)??0)+1)}}return e},[J,Y]);if(V)return p(`div`,{className:`h-24 rounded-lg border border-border bg-surface animate-pulse`});let Q=K&&de?W.get(K):void 0;if(!L&&J.length===0)return p(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:E??i(o,{children:[`No addons in`,` `,r.length>0?`[${r.join(`, `)}]`:`the current selection`,` expose`,` `,c,`-level settings on this node.`]})});let $=Z.isPending;return i(`div`,{className:`space-y-4`,children:[(k||A)&&i(`div`,{className:`border-b border-border pb-2`,children:[k&&p(`h2`,{className:`text-sm font-semibold text-foreground`,children:k}),A&&p(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:A})]}),T!==void 0&&p(`p`,{"data-testid":`settings-scope-statement`,className:`rounded-md border border-border bg-surface-hover px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:ae[T]}),L&&p(ne,{tabs:G.map(e=>({id:e,label:ue.get(e)??e})),activeId:K,onChange:le,pendingByTab:Ce}),Z.isError&&i(`div`,{className:`rounded-md border border-red-500/40 bg-red-500/10 px-3 py-2 text-[11px] text-red-400`,children:[`Save failed: `,String(Z.error?.message??Z.error)]}),p(re,{tabKey:Q?`extra:${K??``}`:`tab:${K??``}`,children:Q?Q.content:(()=>{let e=q?J.reduce((e,t)=>e+t.schemaWithValues.sections.filter(e=>(e.tab??`general`)===q).length,0):0,t=q!==null&&e<=1,n=J.map(e=>({...e,renderedWithValues:{...e.schemaWithValues,sections:e.schemaWithValues.sections.filter(e=>q?(e.tab??`general`)===q:!0).map(e=>t?{...e,title:``,description:void 0}:e)}})).filter(e=>e.renderedWithValues.sections.length>0).toSorted((e,t)=>{let n=e=>{let t=1/0;for(let n of e)typeof n.order==`number`&&n.order<t&&(t=n.order);return t},r=n(e.renderedWithValues.sections),i=n(t.renderedWithValues.sections);return r===i?0:r-i}),r=(O??[]).filter(e=>e.tabId===q),a=r.filter(e=>(e.placement??`before`)===`before`),o=r.filter(e=>e.placement===`after`);return n.length===0&&r.length===0?p(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:E??`Nothing to configure here for this node.`}):i(`div`,{className:`space-y-6`,children:[a.map((e,t)=>p(`div`,{children:e.content},`extra-before-${t}`)),n.length>0&&p(se,{entries:n,paneStates:Y,displayNames:pe,disabled:$,setPaneRef:_e,onPaneStateChange:ge,onImmediateSave:be,onAction:ye,inline:L||!!C}),o.map((e,t)=>p(`div`,{children:e.content},`extra-after-${t}`))]})})()}),!V&&p(te,{pendingCount:Se,onSave:()=>Z.mutate(),onDiscard:xe,saving:$})]})}function se({entries:e,paneStates:t,displayNames:n,disabled:r,setPaneRef:o,onPaneStateChange:s,onImmediateSave:c,onAction:l,inline:u}){let f=a(()=>[...e].toSorted((e,t)=>{if(e.addonId===`system-config`)return-1;if(t.addonId===`system-config`)return 1;let r=n.get(e.addonId)??e.addonId,i=n.get(t.addonId)??t.addonId;return r.localeCompare(i)}),[e,n]),[h,g]=d(f[0]?.addonId??``);m(()=>{f.length!==0&&(f.find(e=>e.addonId===h)||g(f[0].addonId))},[f,h]);let _=f.find(e=>e.addonId===h)??f[0];if(!_)return null;let v=a(()=>l?(e,t,n,r)=>l(e,t,n,r):void 0,[l]),y=e=>p(C,{ref:o(e.addonId),addonId:e.addonId,schema:e.renderedWithValues,serverValues:e.serverValues,onImmediateSave:c,onStateChange:s,onAction:v,disabled:r},e.addonId);return f.length===1||u?p(`div`,{className:`flex flex-col gap-4`,children:f.map(y)}):i(`div`,{className:`flex flex-col gap-3`,children:[p(`div`,{className:`flex flex-wrap items-center gap-1 border-b border-border shrink-0`,children:f.map(e=>{let r=n.get(e.addonId)??e.addonId,a=e.addonId===_.addonId,o=(t.get(e.addonId)?.pendingKeys.length??0)>0;return i(`button`,{type:`button`,onClick:()=>g(e.addonId),className:`relative px-3 py-1.5 text-xs font-medium rounded-t-md transition-colors -mb-px border-b-2 whitespace-nowrap ${a?`text-primary border-primary bg-primary/5`:`text-foreground-subtle border-transparent hover:text-foreground hover:bg-surface-hover`}`,children:[r,o&&p(`span`,{className:`ml-1.5 inline-flex h-1.5 w-1.5 rounded-full bg-amber-400`})]},e.addonId)})}),p(`div`,{className:`space-y-2`,children:f.map(e=>p(`div`,{style:e.addonId===_.addonId?void 0:{display:`none`},children:y(e)},e.addonId))})]})}export{D as n,A as t};
1
+ import{H as e,I as t,K as n,Q as r,S as i,W as a,b as o,i as s,k as c,o as l,p as u,q as d,t as f,x as p,z as m}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as h}from"./player-overlays-BrCS3AFF.js";import{Jn as g,On as _,bn as v,gr as y,yn as ee}from"./src-CTpgEWRF.js";import{zt as b}from"./src-Db_n2ue2.js";import{t as x}from"./FormBuilder-DobHTqPD.js";import{n as te,r as S,t as ne}from"./SchemaTabBar-DC28nb9j.js";import{t as re}from"./StableTabPanel-Dc954AQl.js";r();var C=c(function({addonId:r,schema:i,serverValues:o,onImmediateSave:s,onStateChange:c,onAction:l,disabled:u},d){let f=S({schema:i,serverValues:o,onImmediateSave:t(e=>s(r,e),[r,s]),onDeferredSave:t(()=>{},[])});e(d,()=>({flush:()=>{let e={};for(let t of f.pendingKeys)e[t]=f.values[t];return f.handleDiscard(f.pendingKeys),e},discard:()=>f.resetAll()}),[f]);let h=f.pendingKeys,g=h.join(`|`),_=a(()=>h.map(e=>`${e}=${JSON.stringify(f.values[e])}`).join(`,`),[h,f.values]),v=n(c);m(()=>{v.current=c},[c]),m(()=>{let e={};for(let t of h)e[t]=f.values[t];v.current({addonId:r,pendingKeys:h,pendingValues:e})},[r,g,_]);let y=a(()=>{if(l)return(e,t,n)=>l(r,e,t,n)},[r,l]);return p(x,{schema:i,values:f.values,onChange:f.handleChange,disabled:u,onAction:y})});function w(e){return`perNode`in e&&e.perNode===!0}function T(e,t){if(e.type===`group`){let n=E(e.fields,t);return n.length>0?{...e,fields:n}:null}if(e.type===`sub-tabs`){let n=e.tabs.map(e=>({...e,fields:E(e.fields,t)})).filter(e=>e.fields.length>0);return n.length>0?{...e,tabs:n}:null}return w(e)===(t===`perNode`)?e:null}function E(e,t){let n=[];for(let r of e){let e=T(r,t);e!==null&&n.push(e)}return n}function ie(e,t){let n=[];for(let r of e.sections){let e=E(r.fields,t);e.length!==0&&n.push({...r,fields:e})}return{...e,sections:n}}var ae={integration:`Integration-wide settings — one value shared by every device this integration provides. These are not per-device settings: a change here applies to all of them. The same values are also reachable under System → Settings, and both write the same place.`};function D(e){return e==null?!1:e.sections.some(e=>e.fields.length>0)}r();function O(e,t){if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`){let n=e.fields.map(e=>O(e,t));return{...e,fields:n}}let n=e;t[e.key]=n.value;let{value:r,...i}=n;return i}function k(e,t){return{...e,fields:e.fields.map(e=>O(e,t))}}function oe(e){let t={};return{schema:{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>k(e,t))},values:t}}function A({nodeId:e,addonIds:r,level:c,deviceId:m,capability:x,sectionIds:S,sectionTab:C,fieldScope:w,surface:T,emptyMessage:E,extraTabs:D,schemaTabExtras:O,title:k,description:A,selfTabbed:ce}){let j=l(),M=h().trpcClient,N=v(),P=ee(),F=y(),I=g(),L=ce===!0||!!(D&&D.length>0),[R,le]=d(null);if(c===`device`&&!m)throw Error(`NodeAddonsSettingsPanel: deviceId is required when level === "device"`);if(T!==void 0){if(c!==`global`||m!==void 0)throw Error(`NodeAddonsSettingsPanel: integration-level settings are addon-wide — they cannot be mounted at device level or with a deviceId. A second page, never a second scope.`);if(e!==null)throw Error(`NodeAddonsSettingsPanel: an integration has no node behind it — pass nodeId={null}. Received ${JSON.stringify(e)}.`);if(w!==void 0)throw Error("NodeAddonsSettingsPanel: integration-level settings arrive already cluster-scoped from core — remove `fieldScope` rather than restating it.")}let z=e??`hub`,B=s({queries:r.map(e=>({queryKey:[[`addonSettings`,T===void 0?c===`global`?`getGlobalSettings`:`getDeviceSettings`:`getIntegrationSettings`],{addonId:e,nodeId:z,deviceId:m??null,cap:x??null,scope:w??null}],queryFn:async()=>{let t=e=>e!==null&&w!==void 0?ie(e,w):e;return T===void 0?c===`global`?{addonId:e,result:t(await M.addonSettings.getGlobalSettings.query({addonId:e,nodeId:z,...x?{cap:x}:{}}))}:{addonId:e,result:t(await M.addonSettings.getDeviceSettings.query({addonId:e,deviceId:m,nodeId:z}))}:{addonId:e,result:await M.addonSettings.getIntegrationSettings.query({addonId:e,nodeId:z})}},placeholderData:u}))}),V=B.some(e=>e.isLoading),H=B.map(e=>{if(!e.data)return`-`;if(e.data.result===null)return`${e.data.addonId}:n`;let t=[];for(let n of e.data.result.sections){t.push(`s:${n.id}:${n.tab??`general`}`);for(let e of n.fields){if(!(`key`in e))continue;let n=`options`in e&&Array.isArray(e.options)?e.options.map(e=>e.value).join(`,`):``,r=e.value,i=r===void 0?``:typeof r==`string`?r:JSON.stringify(r);t.push(`f:${e.key}:${n}:${i}`)}}return`${e.data.addonId}:${t.join(`|`)}`}).join(`||`),U=a(()=>{let e=new Set;for(let t of B){let n=t.data?.result?.sections;if(n)for(let t of n)e.add(t.tab??`general`)}return[...e]},[H+`::`+B.map(e=>(e.data?.result?.sections??[]).map(e=>e.tab??`general`).join(`,`)).join(`::`)]),W=a(()=>new Map((D??[]).map(e=>[e.id,e])),[D]),G=a(()=>{if(!L)return[];let e=[...new Set([...U,...(D??[]).map(e=>e.id),...(O??[]).map(e=>e.tabId)])],t=e=>{let t=W.get(e);if(t?.order!==void 0)return t.order;let n=b[e];return n?n.order:50};return e.toSorted((e,n)=>{let r=t(e),i=t(n);return r===i?e.localeCompare(n):r-i})},[L,U,D,W,O]),ue=a(()=>{let e=new Map,t=e=>b[e]?.label??e.charAt(0).toUpperCase()+e.slice(1);for(let n of U)e.set(n,t(n));for(let n of O??[])e.has(n.tabId)||e.set(n.tabId,t(n.tabId));for(let t of D??[])e.set(t.id,t.label);return e},[U,D,O]),K=L?R&&G.includes(R)?R:G[0]??null:null,de=K!==null&&W.has(K),q=L?K&&!de?K:void 0:C,{data:fe}=_(void 0),pe=a(()=>{let e=new Map;for(let t of fe??[]){let n=t.manifest?.id;if(!n)continue;let r=t.manifest?.name??t.manifest?.packageDisplayName??n;e.set(n,r)}return e},[fe]),me=n(new Map),J=a(()=>{let e=S?new Set(S):null,t=[];for(let n of B){if(!n.data)continue;let r=n.data.result??me.current.get(n.data.addonId)??null;if(n.data.result!==null&&me.current.set(n.data.addonId,n.data.result),r===null)continue;let{schema:i,values:a}=oe(r),o=i.sections.filter(t=>e?e.has(t.id):!0);if(o.length===0)continue;let s={...r,sections:r.sections.filter(t=>e?e.has(t.id):!0)},c={...i,sections:o};t.push({addonId:n.data.addonId,schemaWithValues:s,schema:c,serverValues:a})}return t},[H,S]),[Y,he]=d(new Map),ge=t(e=>{he(t=>{let n=new Map(t);return n.set(e.addonId,e),n})},[]),X=n(new Map),_e=t(e=>t=>{t?X.current.set(e,t):X.current.delete(e)},[]),ve=t(async(e,t)=>{c===`global`?await N.mutateAsync({addonId:e,nodeId:z,patch:t}):await P.mutateAsync({addonId:e,deviceId:m,nodeId:z,patch:t}),j.invalidateQueries({queryKey:[[`addonSettings`]]})},[N,P,z,c,m,j]),ye=t(async(e,t,n,r)=>{let i=z;try{switch(t){case`reprobe-hwaccel`:await F.mutateAsync({nodeId:i}),j.invalidateQueries({queryKey:[[`addonSettings`]]});return;case`reprobe-audio-engine`:await I.mutateAsync({nodeId:i}),j.invalidateQueries({queryKey:[[`addonSettings`]]});return;default:{let n=await M.addons.custom.mutate({addonId:e,action:t,input:r});return j.invalidateQueries({queryKey:[[`addonSettings`]]}),n}}}catch(n){throw console.error(`[NodeAddonsSettingsPanel] action failed`,{addonId:e,action:t,err:n}),n}},[F,I,z,j,M]),be=t((e,t)=>{ve(e,t)},[ve]),Z=f({mutationFn:async()=>{let e=[];for(let t of J){let n=Y.get(t.addonId);!n||n.pendingKeys.length===0||e.push({addonId:t.addonId,patch:n.pendingValues})}return e.length===0?{saved:[]}:{saved:await Promise.all(e.map(async({addonId:e,patch:t})=>(c===`global`?await N.mutateAsync({addonId:e,nodeId:z,patch:t}):await P.mutateAsync({addonId:e,deviceId:m,nodeId:z,patch:t}),e)))}},onSuccess:({saved:e})=>{for(let t of e)X.current.get(t)?.discard();j.invalidateQueries({queryKey:[[`addonSettings`]]})}}),xe=t(()=>{for(let e of X.current.values())e.discard()},[]),Se=a(()=>{let e=0;for(let t of J){let n=Y.get(t.addonId);n&&(e+=n.pendingKeys.length)}return e},[J,Y]),Ce=a(()=>{let e=new Map;for(let t of J){let n=Y.get(t.addonId);if(!n||n.pendingKeys.length===0)continue;let r=new Set(n.pendingKeys);for(let n of t.schema.sections){let t=n.tab??`general`;for(let i of n.fields)`key`in i&&r.has(i.key)&&e.set(t,(e.get(t)??0)+1)}}return e},[J,Y]);if(V)return p(`div`,{className:`h-24 rounded-lg border border-border bg-surface animate-pulse`});let Q=K&&de?W.get(K):void 0;if(!L&&J.length===0)return p(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:E??i(o,{children:[`No addons in`,` `,r.length>0?`[${r.join(`, `)}]`:`the current selection`,` expose`,` `,c,`-level settings on this node.`]})});let $=Z.isPending;return i(`div`,{className:`space-y-4`,children:[(k||A)&&i(`div`,{className:`border-b border-border pb-2`,children:[k&&p(`h2`,{className:`text-sm font-semibold text-foreground`,children:k}),A&&p(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:A})]}),T!==void 0&&p(`p`,{"data-testid":`settings-scope-statement`,className:`rounded-md border border-border bg-surface-hover px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:ae[T]}),L&&p(ne,{tabs:G.map(e=>({id:e,label:ue.get(e)??e})),activeId:K,onChange:le,pendingByTab:Ce}),Z.isError&&i(`div`,{className:`rounded-md border border-red-500/40 bg-red-500/10 px-3 py-2 text-[11px] text-red-400`,children:[`Save failed: `,String(Z.error?.message??Z.error)]}),p(re,{tabKey:Q?`extra:${K??``}`:`tab:${K??``}`,children:Q?Q.content:(()=>{let e=q?J.reduce((e,t)=>e+t.schemaWithValues.sections.filter(e=>(e.tab??`general`)===q).length,0):0,t=q!==null&&e<=1,n=J.map(e=>({...e,renderedWithValues:{...e.schemaWithValues,sections:e.schemaWithValues.sections.filter(e=>q?(e.tab??`general`)===q:!0).map(e=>t?{...e,title:``,description:void 0}:e)}})).filter(e=>e.renderedWithValues.sections.length>0).toSorted((e,t)=>{let n=e=>{let t=1/0;for(let n of e)typeof n.order==`number`&&n.order<t&&(t=n.order);return t},r=n(e.renderedWithValues.sections),i=n(t.renderedWithValues.sections);return r===i?0:r-i}),r=(O??[]).filter(e=>e.tabId===q),a=r.filter(e=>(e.placement??`before`)===`before`),o=r.filter(e=>e.placement===`after`);return n.length===0&&r.length===0?p(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:E??`Nothing to configure here for this node.`}):i(`div`,{className:`space-y-6`,children:[a.map((e,t)=>p(`div`,{children:e.content},`extra-before-${t}`)),n.length>0&&p(se,{entries:n,paneStates:Y,displayNames:pe,disabled:$,setPaneRef:_e,onPaneStateChange:ge,onImmediateSave:be,onAction:ye,inline:L||!!C}),o.map((e,t)=>p(`div`,{children:e.content},`extra-after-${t}`))]})})()}),!V&&p(te,{pendingCount:Se,onSave:()=>Z.mutate(),onDiscard:xe,saving:$})]})}function se({entries:e,paneStates:t,displayNames:n,disabled:r,setPaneRef:o,onPaneStateChange:s,onImmediateSave:c,onAction:l,inline:u}){let f=a(()=>[...e].toSorted((e,t)=>{if(e.addonId===`system-config`)return-1;if(t.addonId===`system-config`)return 1;let r=n.get(e.addonId)??e.addonId,i=n.get(t.addonId)??t.addonId;return r.localeCompare(i)}),[e,n]),[h,g]=d(f[0]?.addonId??``);m(()=>{f.length!==0&&(f.find(e=>e.addonId===h)||g(f[0].addonId))},[f,h]);let _=f.find(e=>e.addonId===h)??f[0];if(!_)return null;let v=a(()=>l?(e,t,n,r)=>l(e,t,n,r):void 0,[l]),y=e=>p(C,{ref:o(e.addonId),addonId:e.addonId,schema:e.renderedWithValues,serverValues:e.serverValues,onImmediateSave:c,onStateChange:s,onAction:v,disabled:r},e.addonId);return f.length===1||u?p(`div`,{className:`flex flex-col gap-4`,children:f.map(y)}):i(`div`,{className:`flex flex-col gap-3`,children:[p(`div`,{className:`flex flex-wrap items-center gap-1 border-b border-border shrink-0`,children:f.map(e=>{let r=n.get(e.addonId)??e.addonId,a=e.addonId===_.addonId,o=(t.get(e.addonId)?.pendingKeys.length??0)>0;return i(`button`,{type:`button`,onClick:()=>g(e.addonId),className:`relative px-3 py-1.5 text-xs font-medium rounded-t-md transition-colors -mb-px border-b-2 whitespace-nowrap ${a?`text-primary border-primary bg-primary/5`:`text-foreground-subtle border-transparent hover:text-foreground hover:bg-surface-hover`}`,children:[r,o&&p(`span`,{className:`ml-1.5 inline-flex h-1.5 w-1.5 rounded-full bg-amber-400`})]},e.addonId)})}),p(`div`,{className:`space-y-2`,children:f.map(e=>p(`div`,{style:e.addonId===_.addonId?void 0:{display:`none`},children:y(e)},e.addonId))})]})}export{D as n,A as t};