@camstack/addon-admin-ui 1.2.351 → 1.2.353

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 (99) hide show
  1. package/dist/assets/Addons-CSSlxmKX.js +4 -0
  2. package/dist/assets/AdminPage-BSFohA3i.js +1 -0
  3. package/dist/assets/{AdminTabs-CLXyClcg.js → AdminTabs-D2EUE5A0.js} +1 -1
  4. package/dist/assets/{AiProfiles-ChIr3l8J.js → AiProfiles-ZTs3hQfG.js} +1 -1
  5. package/dist/assets/BrokerForm-jvEIkwfE.js +1 -0
  6. package/dist/assets/{Build-ByqfAJAw.js → Build-D-cQZg2g.js} +3 -3
  7. package/dist/assets/{Calendars-B4BPsOl1.js → Calendars-BCpPE1jT.js} +1 -1
  8. package/dist/assets/{Capabilities-70q-pu5f.js → Capabilities-WsxtQm6G.js} +1 -1
  9. package/dist/assets/{Cluster-2DoknXyA.js → Cluster-BZpFTXoQ.js} +1 -1
  10. package/dist/assets/{ClusterStepModel-B-xVF7M9.js → ClusterStepModel-Hz5Uy3Lc.js} +1 -1
  11. package/dist/assets/{CompositionEditor-DewhGunb.js → CompositionEditor-DlXjZmuS.js} +1 -1
  12. package/dist/assets/{CompositionEditorPage-DTanATOp.js → CompositionEditorPage-DN1jwFte.js} +1 -1
  13. package/dist/assets/{Data-ovpjy5aC.js → Data-BiwkrKto.js} +1 -1
  14. package/dist/assets/{DetectionIntelligence-CJMGXsWL.js → DetectionIntelligence-C_6PVnNp.js} +1 -1
  15. package/dist/assets/{DeviceDetail-BuLCyjcK.js → DeviceDetail-Dd16eq5_.js} +2 -2
  16. package/dist/assets/{DeviceDoActionFields-DBwevgKK.js → DeviceDoActionFields-C9efvuLy.js} +1 -1
  17. package/dist/assets/{Devices-DvSDZeG9.js → Devices-uRSR1KF9.js} +1 -1
  18. package/dist/assets/{EmbedPlayerPage-enhtADF7.js → EmbedPlayerPage-B0M5LCl6.js} +1 -1
  19. package/dist/assets/{Events-Dv_1XIVc.js → Events-BqYGW97U.js} +1 -1
  20. package/dist/assets/Identity-CwF15mWM.js +1 -0
  21. package/dist/assets/{IntegrationDetail-DSqCZO4S.js → IntegrationDetail-KiizjQky.js} +1 -1
  22. package/dist/assets/IntegrationHub-CtZ9pFUl.js +1 -0
  23. package/dist/assets/Integrations-5D0W0NO_.js +1 -0
  24. package/dist/assets/Integrations-8JethkBu.js +1 -0
  25. package/dist/assets/{Locations-BNBOCArW.js → Locations-C0VGgBDh.js} +1 -1
  26. package/dist/assets/Logs-BdD9ktZ1.js +1 -0
  27. package/dist/assets/{MotionZonesSettings-aDMRPb0C.js → MotionZonesSettings-BMZDT9aS.js} +1 -1
  28. package/dist/assets/{MyAccess-bpwJEqEY.js → MyAccess-VT-IYS_0.js} +1 -1
  29. package/dist/assets/Network-DAS4ofeO.js +1 -0
  30. package/dist/assets/NodeAddonsSettingsPanel-2ImNi4l_.js +1 -0
  31. package/dist/assets/{Notifications-ML8zmn39.js → Notifications-CtpsBCVg.js} +1 -1
  32. package/dist/assets/{Plates-DIoGtVsY.js → Plates-DRYDfqhl.js} +1 -1
  33. package/dist/assets/{PrivacyMaskSettings-DFTAA5dg.js → PrivacyMaskSettings-e1shTFq0.js} +1 -1
  34. package/dist/assets/{Recordings-CoOwir1H.js → Recordings-Cp1t8Lsr.js} +1 -1
  35. package/dist/assets/ScanNetworkModal-CtcUY86A.js +1 -0
  36. package/dist/assets/{SceneMonitorEditor-rhbNHUiH.js → SceneMonitorEditor-B8SaYaRg.js} +1 -1
  37. package/dist/assets/{Scenes-B6vGKWeX.js → Scenes-UX3CQiSD.js} +1 -1
  38. package/dist/assets/{Settings-PKIvMwLh.js → Settings-hvJAx444.js} +1 -1
  39. package/dist/assets/{Showroom-CiPParUW.js → Showroom-DGF0GI0t.js} +1 -1
  40. package/dist/assets/{Terminal-yp9gTtPT.js → Terminal-CnAgipZG.js} +1 -1
  41. package/dist/assets/{Viewer-CrwFaVq7.js → Viewer-u429VTlj.js} +1 -1
  42. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Cc2A3Ptb.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Dmoq9iz_.js} +1 -1
  43. package/dist/assets/addon-display-names-BkwMrExv.js +1 -0
  44. package/dist/assets/{archive-D5jN_xRr.js → archive-DEGN5b-2.js} +1 -1
  45. package/dist/assets/{authed-media-DIbw4JLn.js → authed-media-zoQQL-DU.js} +1 -1
  46. package/dist/assets/{boxes-Cz0W-SHm.js → boxes-D53xb3mF.js} +1 -1
  47. package/dist/assets/circle-slash-g5R19IPN.js +1 -0
  48. package/dist/assets/{client-DWiaUxRQ.js → client-CxHFB-xR.js} +2 -2
  49. package/dist/assets/crop-DTBzwOc0.js +1 -0
  50. package/dist/assets/{debounced-invalidate-BhgMMKYH.js → debounced-invalidate-Di49k3Ur.js} +1 -1
  51. package/dist/assets/{device-integration-icon-BnWP0LSQ.js → device-integration-icon-C44r3pOz.js} +1 -1
  52. package/dist/assets/device-picker-model-Y21yLCDr.js +1 -0
  53. package/dist/assets/{dist-brqlsTXV.js → dist-B_y7Xf3Y.js} +2 -2
  54. package/dist/assets/{dist-BvHPU1Ls.js → dist-CupCPVu2.js} +1 -1
  55. package/dist/assets/{face-bbox--pttun6Q.js → face-bbox-BekWkYM8.js} +1 -1
  56. package/dist/assets/{hard-drive-download-DvX0zc41.js → hard-drive-download-CaBI4JJt.js} +1 -1
  57. package/dist/assets/{hostInit-BxEpkmct.js → hostInit-LeZtjcV4.js} +1 -1
  58. package/dist/assets/{index-Buq71VHG.js → index-BdYsVZMw.js} +3 -3
  59. package/dist/assets/index-CFkS00_M.css +2 -0
  60. package/dist/assets/{layers-CTxykl5p.js → layers-Bl4GXnaV.js} +1 -1
  61. package/dist/assets/{location-owned-usage-CV2yEH4j.js → location-owned-usage-B2EH12kQ.js} +1 -1
  62. package/dist/assets/{mf-entry-bootstrap-0-9f9ea6de.js → mf-entry-bootstrap-0-f71236c8.js} +2 -2
  63. package/dist/assets/mount-Y21yLCDr.js +1 -0
  64. package/dist/assets/{notification-schedule-field-CQPEDiDO.js → notification-schedule-field-CX_ISfhK.js} +1 -1
  65. package/dist/assets/{player-overlays-CrKWnjLj.js → player-overlays-CHWCYkGf.js} +1 -1
  66. package/dist/assets/remoteEntry-D2L5CI92.js +1 -0
  67. package/dist/assets/{send-SN1L0Kiz.js → send-BxCvGnMf.js} +1 -1
  68. package/dist/assets/{settings-2-BY8TSBhz.js → settings-2-CWTgzyTw.js} +1 -1
  69. package/dist/assets/{src-Bkpo8B0D.js → src-Crb8RLzq.js} +3 -3
  70. package/dist/assets/{use-scenes-feed-Dwp-15g8.js → use-scenes-feed-CsZwOmyp.js} +1 -1
  71. package/dist/assets/{use-stationary-objects-CCknD3DG.js → use-stationary-objects-DTKCTzni.js} +1 -1
  72. package/dist/assets/useEventInvalidation-Y21yLCDr.js +1 -0
  73. package/dist/assets/{useNodeUrlSelection-NjZtQ6mH.js → useNodeUrlSelection-BSYJnQKG.js} +1 -1
  74. package/dist/assets/user-round-BR8uDCSh.js +1 -0
  75. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-Cok7af3G.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-mzuJ2veF.js} +2 -2
  76. package/dist/index.html +8 -8
  77. package/dist/server/addon.js +17 -2
  78. package/package.json +1 -1
  79. package/dist/assets/AddonCollectionPage-BwMkNEOp.js +0 -1
  80. package/dist/assets/Addons-80LT7Kq1.js +0 -4
  81. package/dist/assets/AdminPage-CiKtOLQm.js +0 -1
  82. package/dist/assets/BrokerForm-DGnvvf1S.js +0 -1
  83. package/dist/assets/Identity-Cc3G2Fa0.js +0 -1
  84. package/dist/assets/Integrations-Beb2EhOS.js +0 -1
  85. package/dist/assets/Integrations-DYhW5V60.js +0 -1
  86. package/dist/assets/Logs-CScz1BkD.js +0 -1
  87. package/dist/assets/Network-Bx7uEVdz.js +0 -1
  88. package/dist/assets/NodeAddonsSettingsPanel-BgxOJU3d.js +0 -1
  89. package/dist/assets/ScanNetworkModal-BPZGLiZQ.js +0 -1
  90. package/dist/assets/addon-display-names-DvSEQty-.js +0 -1
  91. package/dist/assets/circle-slash-tZFznooZ.js +0 -1
  92. package/dist/assets/crop-B8tpwR6u.js +0 -1
  93. package/dist/assets/device-picker-model-D1aOGj40.js +0 -1
  94. package/dist/assets/index-CFu9bpWo.css +0 -2
  95. package/dist/assets/mount-D1aOGj40.js +0 -1
  96. package/dist/assets/remoteEntry-BFpE5_8_.js +0 -1
  97. package/dist/assets/useBodyScrollLock-BDocajQE.js +0 -1
  98. package/dist/assets/useEventInvalidation-D1aOGj40.js +0 -1
  99. package/dist/assets/user-round-DCIxbUZ9.js +0 -1
@@ -1 +0,0 @@
1
- import{Q as e,S as t,W as n,a as r,b as i,o as a,q as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as c,gt as l,ht as u,st as d,vt as f}from"./player-overlays-CrKWnjLj.js";import{Al as p,Bn as m,Cl as h,Dl as g,Dr as _,El as v,Eu as y,Fl as b,Gu as x,H as S,Hd as C,Il as ee,Kl as w,M as T,Ml as E,N as D,Nl as O,Ol as k,Or as A,Pl as j,Qn as te,Rd as M,Rt as ne,Sl as N,Tl as P,Tu as F,U as I,Uu as re,Zn as L,cd as R,da as z,jl as ie,kd as ae,kl as B,ld as V,nu as oe,rd as H,sd as se,wl as ce,xd as le,yu as U}from"./src-Bkpo8B0D.js";import{a as ue,i as de,o as W,s as fe}from"./client-DWiaUxRQ.js";import{B as pe,S as G}from"./index-Buq71VHG.js";import{t as K}from"./AdminPage-CiKtOLQm.js";import{t as me}from"./AdminTabs-CLXyClcg.js";import{t as he}from"./AddonCollectionPage-BwMkNEOp.js";import{t as ge}from"./addon-display-names-DvSEQty-.js";var _e=f(`book-open`,[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z`,key:`ruj8y`}]]),ve=f(`key-square`,[[`path`,{d:`M12.4 2.7a2.5 2.5 0 0 1 3.4 0l5.5 5.5a2.5 2.5 0 0 1 0 3.4l-3.7 3.7a2.5 2.5 0 0 1-3.4 0L8.7 9.8a2.5 2.5 0 0 1 0-3.4z`,key:`165ttr`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`m9.4 10.6-6.814 6.814A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814`,key:`1ubxi2`}]]),ye=f(`link`,[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]);e();function be({userId:e,username:n,onClose:r}){let o=a(),c=L(),l=v({userId:e}),u=l.data,d=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),f=P({onSuccess:()=>{d(),r()}}),p=l.isLoading?`loading`:u?.enabled?`enrolled`:`not_enrolled`;return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4`,children:t(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden`,children:[t(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-border`,children:[t(`div`,{className:`flex items-center gap-2`,children:[s(U,{className:`h-4 w-4 text-primary`}),t(`div`,{children:[s(`div`,{className:`text-sm font-medium text-foreground`,children:`Two-factor authentication`}),t(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,s(`span`,{className:`font-mono`,children:n})]})]})]}),s(`button`,{onClick:r,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:s(w,{className:`h-4 w-4`})})]}),t(`div`,{className:`p-4 space-y-4`,children:[p===`loading`&&t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(H,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),p===`not_enrolled`&&t(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[s(V,{className:`h-4 w-4 mt-0.5 shrink-0`}),t(`div`,{children:[s(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),s(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),p===`enrolled`&&u&&t(i,{children:[t(`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:[s(M,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),t(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[s(`div`,{className:`font-medium`,children:`2FA is active`}),t(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,u.confirmedAt?new Date(u.confirmedAt).toLocaleString():`—`]})]})]}),s(`div`,{className:`text-[11px] text-foreground-subtle`,children:`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`}),t(`div`,{className:`flex justify-end gap-2`,children:[s(m,{onClick:r,variant:`secondary`,children:`Close`}),t(`button`,{onClick:async()=>{await c({title:`Remove 2FA`,message:`Remove two-factor authentication for "${n}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,confirmLabel:`Remove`,variant:`danger`})&&f.mutate({userId:e})},disabled:f.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:[f.isPending?s(H,{className:`h-3 w-3 animate-spin`}):s(w,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function q({icon:e,label:n,count:r,all:i,total:a}){return t(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[s(e,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(`span`,{className:`min-w-0 flex-1 text-foreground-subtle`,children:n}),s(`span`,{className:r===0?`text-foreground-subtle`:`font-medium text-foreground`,children:r===0?`none`:i?`all ${a}`:`${r} of ${a}`})]})}function xe({scopes:e,isAdmin:n,invalidReason:a}){let o=c(),l=r({queryKey:[`auth`,`previewScope`,e,n],enabled:a===null,queryFn:()=>o.trpcClient.auth.previewScope.query({scopes:[...e],isAdmin:n})}),{data:u}=z({projection:`slim`}),f=u?.length??0;if(a!==null)return s(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:t(`p`,{className:`flex items-center gap-1.5 text-[11px] text-warning`,children:[s(y,{className:`h-3 w-3 shrink-0`}),a]})});if(l.isLoading)return t(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface p-3 text-[11px] text-foreground-subtle`,children:[s(H,{className:`h-3 w-3 animate-spin`}),`Resolving…`]});if(l.isError||!l.data)return s(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:s(`p`,{className:`text-[11px] text-danger`,children:`Could not resolve this grant set. Saving is still allowed — the server enforces the same rules either way.`})});let p=l.data;return s(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-3`,children:p.isAdmin?t(`p`,{className:`text-[11px] text-foreground`,children:[s(`span`,{className:`font-medium`,children:`Administrator`}),` — unrestricted. Grants are ignored for an admin.`]}):t(i,{children:[s(q,{icon:le,label:`Devices they can see`,count:p.device.view.deviceCount,all:p.device.view.all,total:f}),s(q,{icon:x,label:`Devices they can operate`,count:p.device.create.deviceCount,all:p.device.create.all,total:f}),s(q,{icon:d,label:`Devices they can delete`,count:p.device.delete.deviceCount,all:p.device.delete.all,total:f}),t(`div`,{className:`border-t border-border pt-2 text-[10px] text-foreground-subtle`,children:[`System access: `,p.system.length===0?`none`:p.system.join(`, `),p.capabilities.length>0&&t(i,{children:[` · Extra capabilities: `,p.capabilities.map(e=>e.name).join(`, `)]}),p.addons.length>0&&t(i,{children:[` · Addons: `,p.addons.map(e=>e.name).join(`, `)]})]}),p.device.view.deviceCount===0&&s(`p`,{className:`text-[10px] text-warning`,children:`This user will not be able to see any device.`})]})})}function Se(e){let t=W(e);return t===null?{mode:e.length===0?`role`:`advanced`,roleId:null,selector:{kind:`all`},includeLinked:!0,advancedScopes:e}:{mode:`role`,roleId:t.roleId,selector:t.selector,includeLinked:t.includeLinked,advancedScopes:e}}function Ce(e){return e.mode===`advanced`?e.advancedScopes:e.roleId===null?[]:ue({roleId:e.roleId,selector:e.selector,includeLinked:e.includeLinked})}function we({user:e,onClose:r,onSubmit:a,submitting:c,callerScopes:d}){let f=n(()=>Se(e.scopes??[]),[e.scopes]),[p,m]=o(f),[h,g]=o(f.mode===`advanced`),_=n(()=>Ce(p),[p]),v=!e.isAdmin&&p.mode===`role`&&p.roleId===null,b=n(()=>e.isAdmin?null:p.mode===`role`&&p.roleId===null?`Pick what this user can do to see the result.`:D(_),[e.isAdmin,p.mode,p.roleId,_]),x=e=>m({...p,...e});return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4 pt-[calc(1rem+env(safe-area-inset-top))] pb-[calc(1rem+env(safe-area-inset-bottom))]`,children:t(`div`,{className:`flex max-h-full w-full max-w-2xl flex-col rounded-lg border border-border bg-surface shadow-xl`,children:[t(`div`,{className:`flex shrink-0 items-start justify-between border-b border-border px-4 py-3`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`text-sm font-semibold text-foreground`,children:[`Access — `,e.username]}),s(`div`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?`This user is an administrator — they can do everything, and the settings below are ignored.`:`Choose what they can do, then which devices it applies to.`})]}),s(`button`,{onClick:r,className:`shrink-0 text-foreground-subtle hover:text-foreground`,title:`Close`,children:s(w,{className:`h-4 w-4`})})]}),t(`div`,{className:`min-h-0 flex-1 space-y-4 overflow-y-auto px-4 py-4`,children:[v&&t(`div`,{className:`flex items-start gap-2 rounded-lg border border-warning/40 bg-warning/10 p-3`,children:[s(y,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`}),t(`p`,{className:`text-[11px] text-foreground`,children:[s(`span`,{className:`font-medium`,children:`No access.`}),` `,t(`span`,{className:`text-foreground-subtle`,children:[e.username,` cannot see or do anything yet. Configure it below.`]})]})]}),t(`section`,{className:`space-y-2`,children:[s(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`1 · What can they do`}),s(`div`,{className:`space-y-1.5`,children:de.map(e=>{let n=p.mode===`role`&&p.roleId===e.id;return t(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-lg border p-2.5 transition-colors ${n?`border-primary bg-primary/5`:`border-border hover:bg-foreground-subtle/5`}`,children:[s(`input`,{type:`radio`,name:`access-role`,checked:n,onChange:()=>x({mode:`role`,roleId:e.id}),className:`mt-0.5 border-border focus:ring-primary`}),t(`span`,{className:`min-w-0`,children:[s(`span`,{className:`block text-[12px] font-medium text-foreground`,children:e.label}),s(`span`,{className:`mt-0.5 block text-[10px] text-foreground-subtle`,children:e.description})]})]},e.id)})}),t(`button`,{type:`button`,onClick:()=>{if(!h){m({...p,mode:`advanced`,advancedScopes:_}),g(!0);return}g(!1),m(Se(p.advancedScopes))},className:`inline-flex items-center gap-1 rounded px-1.5 py-1 text-[10px] text-foreground-subtle transition-colors hover:bg-foreground-subtle/10 hover:text-foreground`,children:[s(h?l:u,{className:`h-3 w-3`}),`Advanced — edit raw grants`]}),h&&t(`div`,{className:`rounded-lg border border-border p-2`,children:[s(`p`,{className:`mb-2 text-[10px] text-foreground-subtle`,children:`One row per grant. Anything expressible here overrides the three roles above; close this section to go back to them.`}),s(T,{value:p.advancedScopes,onChange:e=>x({mode:`advanced`,advancedScopes:e}),clampToParent:d,emptyHint:t(i,{children:[`No grants.`,` `,s(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until one is added.`]})})]})]}),p.mode===`role`&&t(`section`,{className:`space-y-2`,children:[s(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`2 · On which devices`}),s(S,{value:p.selector,onChange:e=>x({selector:e}),includeLinked:p.includeLinked,onIncludeLinkedChange:e=>x({includeLinked:e}),clampToDeviceIds:null})]}),t(`section`,{className:`space-y-2`,children:[s(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:p.mode===`role`?`3 · Result`:`2 · Result`}),s(xe,{scopes:_,isAdmin:e.isAdmin,invalidReason:b})]})]}),t(`div`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3`,children:[s(`button`,{onClick:r,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground`,children:`Cancel`}),s(`button`,{onClick:()=>a([..._]),disabled:c||b!==null,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:c?s(H,{className:`h-3 w-3 animate-spin`}):`Save access`})]})]})})}e();var Te=8;function Ee(){let e=a(),{user:n}=G(),[r,i]=o(!1),[c,l]=o(``),[u,f]=o(``),[m,g]=o(!1),[_,v]=o(null),{data:y,isLoading:x,isError:S}=p(),C=L(),T=te(),E=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),D=h({onSuccess:()=>{E(),i(!1),l(``),f(``),g(!1),v(null)},onError:e=>{v(e instanceof Error?e.message:`Failed to create user`)}}),O=ce({onSuccess:E}),k=ee({onSuccess:E}),A=ie({onSuccess:E}),j=b({onSuccess:()=>{E(),N(null)}}),[M,N]=o(null),[P,I]=o(null),R=y??[];async function z(e){await C({title:`Delete user`,message:`Permanently delete user "${e.username}"? This cannot be undone — any active sessions will be revoked on next request.`,confirmLabel:`Delete`,variant:`danger`})&&O.mutate({id:e.id})}async function ae(e){let t=await T({title:`Reset password`,message:`Set a new password for "${e.username}".`,label:`New password`,inputType:`password`,placeholder:`At least 8 characters`,confirmLabel:`Continue`,validate:e=>e.length<Te?`Password must be at least ${String(Te)} characters.`:null});t===null||t.length===0||await C({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&A.mutate({id:e.id,newPassword:t})}function B(e,t){t!==e.isAdmin&&k.mutate({id:e.id,isAdmin:t})}function V(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}return t(K,{children:[s(`div`,{className:`flex items-center justify-end`,children:t(`button`,{onClick:()=>i(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm hover:bg-primary/90`,children:[s(re,{className:`h-3.5 w-3.5`}),`Create User`]})}),r&&t(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[t(`div`,{className:`flex items-center justify-between`,children:[s(`span`,{className:`text-xs font-medium text-foreground`,children:`New User`}),s(`button`,{onClick:()=>i(!1),className:`text-foreground-subtle hover:text-foreground`,children:s(w,{className:`h-4 w-4`})})]}),t(`div`,{className:`grid grid-cols-3 gap-3`,children:[t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),s(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`john`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Password`}),s(`input`,{type:`password`,value:u,onChange:e=>f(e.target.value),placeholder:`••••••••`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),t(`label`,{className:`flex items-center gap-2 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:m,onChange:e=>g(e.target.checked),className:`rounded border-border focus:ring-primary`}),s(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),_&&s(`p`,{className:`text-[10px] text-danger`,children:_}),t(`div`,{className:`flex justify-end gap-2`,children:[s(`button`,{onClick:()=>i(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),s(`button`,{onClick:()=>D.mutate({username:c,password:u,isAdmin:m}),disabled:D.isPending||!c||!u,className:`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?`Creating...`:`Create`})]})]}),x&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),S&&s(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!x&&!S&&R.length===0&&s(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>O.isPending&&O.variables?.id===e.id||k.isPending&&k.variables?.id===e.id||A.isPending&&A.variables?.id===e.id;return s(ne,{columns:[{key:`username`,header:`Username`,render:e=>e.username},{key:`isAdmin`,header:`Admin`,render:n=>t(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:n.isAdmin,onChange:e=>B(n,e.target.checked),disabled:e(n),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),s(`span`,{className:n.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:n.isAdmin?`Admin`:`Regular`})]})},{key:`scopes`,header:`Access`,render:e=>e.isAdmin?s(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:`everything (admin)`}):t(`button`,{onClick:()=>N(e),className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] hover:bg-foreground-subtle/10`,title:`Configure access`,children:[s(F,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(De,{scopes:e.scopes??[]})]})},{key:`createdAt`,header:`Created`,render:e=>s(`span`,{className:`text-foreground-subtle`,children:V(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:r=>{let i=e(r);return t(`div`,{className:`flex items-center justify-end gap-1`,children:[r.id!==n?.id&&r.totpEnabled&&t(`button`,{onClick:()=>I(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Remove two-factor authentication`,children:[s(U,{className:`h-3 w-3`}),`Remove 2FA`]}),t(`button`,{onClick:()=>ae(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Reset password`,children:[s(se,{className:`h-3 w-3`}),`Reset password`]}),t(`button`,{onClick:()=>z(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete user`,children:[i?s(H,{className:`h-3 w-3 animate-spin`}):s(d,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:R,rowKey:e=>e.id,minWidthPx:560})})(),P&&s(be,{userId:P.id,username:P.username,onClose:()=>I(null)}),M&&s(Oe,{user:M,onClose:()=>N(null),onSubmit:e=>j.mutate({userId:M.id,scopes:e}),submitting:j.isPending})]})}function De({scopes:e}){if(e.length===0)return s(`span`,{className:`font-medium text-warning`,children:`No access`});let n=W(e);return n===null?t(`span`,{className:`text-foreground-subtle`,children:[`Custom · `,e.length,` grant`,e.length===1?``:`s`]}):t(`span`,{className:`text-foreground-subtle`,children:[s(`span`,{className:`font-medium text-foreground`,children:fe(n.roleId).label}),` ·`,` `,I(n.selector)]})}function Oe(e){let{user:t}=G(),n=t?.isAdmin===!0;return s(we,{...e,callerScopes:n?null:t?.scopes??[]})}e();var ke=`bg-primary/10 text-primary`,Ae=`bg-foreground-subtle/10 text-foreground-subtle`;function J(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function je(e){return e?e===`*`?`*`:e.join(`, `):``}function Me(){let e=a(),r=L(),{data:i,isLoading:c}=g(),{data:l}=p(),u=n(()=>i??[],[i]),f=n(()=>l??[],[l]),m=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),h=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[_,v]=o(!1),[y,b]=o(null),x=E({onSuccess:m}),S=N({onSuccess:({token:e,record:t})=>{h(),v(!1),b({token:e,label:t.name})}}),C=j({onSuccess:h}),ee=async(e,t)=>{await r({title:`Revoke "${t}"?`,message:`Any client using this token will lose access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&x.mutate({id:e})},w=async(e,t)=>{await r({title:`Revoke "${t}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&C.mutate({id:e})};return t(K,{children:[t(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[s(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Issue scoped tokens to grant a user a narrow surface — a specific addon, integration, or capability. Every token MUST be scoped: revoking it has predictable blast radius.`}),t(`button`,{onClick:()=>v(!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:f.length===0,title:f.length===0?`Create a user first`:`Issue a scoped token`,children:[s(F,{className:`h-3.5 w-3.5`}),`New token`]})]}),t(Ne,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[f.length===0&&s(Fe,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),f.map(e=>s(Le,{userId:e.id,username:e.username,onRevoke:(e,t)=>{w(e,t)},revokePending:C.isPending,revokeId:C.variables?.id},e.id))]}),u.length>0&&s(Ne,{title:`Legacy API keys`,subtitle:`${u.length} pre-existing — revoke only`,children:s(Ie,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:u.map(e=>{let n=!!e.isAdmin,r=x.isPending&&x.variables?.id===e.id;return t(`tr`,{className:`hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.label}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:s(`span`,{className:`inline-block rounded px-2 py-0.5 text-[10px] uppercase tracking-wide ${n?ke:Ae}`,children:n?`admin`:`regular`})}),t(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border text-foreground-subtle`,children:je(e.allowedProviders)||`all`}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.createdAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:t(`button`,{onClick:()=>{ee(e.id,e.label)},disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[r?s(H,{className:`h-3 w-3 animate-spin`}):s(d,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),c&&s(Pe,{}),_&&s(Re,{users:f.map(e=>({id:e.id,username:e.username})),onClose:()=>v(!1),onSubmit:e=>S.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:S.isPending}),y&&s(ze,{token:y.token,label:y.label,onClose:()=>b(null)})]})}function Ne({title:e,subtitle:n,children:r}){return t(`div`,{className:`space-y-2`,children:[t(`div`,{className:`flex items-baseline justify-between`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),n&&s(`span`,{className:`text-[10px] text-foreground-subtle`,children:n})]}),r]})}function Pe(){return s(`div`,{className:`space-y-2`,children:[1,2].map(e=>s(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function Fe({text:e}){return s(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function Ie({headers:e,rows:n}){return s(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full text-xs min-w-[640px]`,children:[s(`thead`,{children:s(`tr`,{children:e.map((t,n)=>s(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),s(`tbody`,{children:n})]})})}function Le({userId:e,username:n,onRevoke:r,revokePending:i,revokeId:a}){let{data:o,isLoading:c}=B({userId:e}),l=o??[];return c||l.length===0?null:t(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[11px] font-medium text-foreground`,children:n}),s(Ie,{headers:[`Name`,`Prefix`,`Scopes`,`Expires`,`Last used`,`Created`,``],rows:l.map(e=>{let n=i&&a===e.id;return t(`tr`,{className:`hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.name}),t(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:s(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,n)=>t(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:[e.type,`:`,e.type===`device`?`[${I(e.selector)}]`:e.target]},n))})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.expiresAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.createdAt)}),s(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:t(`button`,{onClick:()=>r(e.id,e.name),disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[n?s(H,{className:`h-3 w-3 animate-spin`}):s(d,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function Re({users:e,onClose:n,onSubmit:r,submitting:i}){let{user:a}=G(),c=a?.isAdmin===!0?null:a?.scopes??[],[l,u]=o(e[0]?.id??``),[d,f]=o(``),[p,m]=o([{type:`capability`,target:``,access:[`view`,`create`]}]),[h,g]=o(``),_=D(p),v=l!==``&&d.trim().length>0&&p.length>0&&_===null&&!i;return t(Be,{title:`Create scoped token`,onClose:n,children:[t(`div`,{className:`space-y-3`,children:[s(Y,{label:`On behalf of user`,children:s(`select`,{value:l,onChange:e=>u(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>s(`option`,{value:e.id,children:e.username},e.id))})}),s(Y,{label:`Name`,children:s(`input`,{value:d,onChange:e=>f(e.target.value),placeholder:`cloudflare-tunnel-route`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})}),t(Y,{label:`Scopes`,hint:`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`,children:[s(T,{value:p,onChange:m,clampToParent:c}),_&&s(`p`,{className:`mt-1 text-[10px] text-danger`,children:_})]}),s(Y,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:s(`input`,{type:`number`,min:1,value:h,onChange:e=>g(e.target.value),placeholder:`30`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})})]}),t(Ve,{children:[s(`button`,{onClick:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),t(`button`,{onClick:()=>{let e=parseInt(h,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;r({userId:l,name:d.trim(),scopes:p,expiresAt:t})},disabled:!v,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[i?s(H,{className:`h-3.5 w-3.5 animate-spin`}):s(F,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function ze({token:e,label:n,onClose:r}){let[i,a]=o(!1),c=async()=>{try{await navigator.clipboard.writeText(e),a(!0)}catch{}};return t(Be,{title:`Token: ${n}`,onClose:r,children:[t(`div`,{className:`space-y-3`,children:[s(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:`Copy this token now. Once you close this dialog the secret cannot be displayed again.`}),s(`div`,{className:`rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all`,children:e})]}),t(Ve,{children:[t(`button`,{onClick:()=>{c()},className:`inline-flex items-center gap-1.5 rounded bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[i?s(C,{className:`h-3.5 w-3.5 text-primary`}):s(ae,{className:`h-3.5 w-3.5`}),i?`Copied`:`Copy`]}),s(`button`,{onClick:r,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Done`})]})]})}function Be({title:e,onClose:n,children:r}){return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,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:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),s(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:s(w,{className:`h-4 w-4`})})]}),s(`div`,{className:`p-4`,children:r})]})})}function Ve({children:e}){return s(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:e})}function Y({label:e,hint:n,children:r}){return t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:e}),r,n&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:n})]})}e();function X(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function He(e){if(e.type===`category`){let t=e.target??``;return t===`device`?`all devices`:`all ${t}`}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function Ue(){return s(`div`,{className:`space-y-2`,children:[1,2].map(e=>s(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function We({text:e}){return s(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function Ge({headers:e,rows:n}){return s(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full text-xs min-w-[640px]`,children:[s(`thead`,{children:s(`tr`,{children:e.map((t,n)=>s(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),s(`tbody`,{children:n})]})})}function Ke(){let e=a(),r=L(),{data:i,isLoading:o}=k(),c=n(()=>i??[],[i]),l=O({onSuccess:()=>e.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),u=async(e,t)=>{await r({title:`Revoke "${t}" session?`,message:`This integration will lose access immediately on its next API call. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&l.mutate({id:e})};return t(K,{icon:ye,title:`Linked Sessions`,subtitle:`External integrations (Alexa, …) linked to this hub via OAuth. Revoke a session to immediately invalidate that integration's access.`,children:[o&&s(Ue,{}),!o&&c.length===0&&s(We,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!o&&c.length>0&&s(Ge,{headers:[`Integration`,`User`,`Scopes`,`Created`,`Last used`,`Status`,``],rows:c.map(e=>{let n=e.revokedAt!==null,r=(l.isPending?l.variables?.id:void 0)===e.id;return t(`tr`,{className:`hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.integrationId}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:e.username}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:s(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>s(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:He(e)},t))})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 border-b border-border`,children:n?t(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-2 py-0.5 text-[10px] text-foreground-subtle`,children:[`Revoked `,X(e.revokedAt)]}):s(`span`,{className:`inline-block rounded bg-emerald-500/15 px-2 py-0.5 text-[10px] text-emerald-700 dark:text-emerald-300`,children:`Active`})}),s(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:!n&&t(`button`,{onClick:()=>{u(e.id,e.integrationId)},disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[r?s(H,{className:`h-3 w-3 animate-spin`}):s(d,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}e();var Z=3e4,Q=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],$={title:`Authentication providers`,subtitle:`Every registered authentication surface in one list: login providers (local password, OIDC, SAML, magic-link) and second-factor providers (passkeys / WebAuthn — configure the relying-party RP ID + origin inline; users enroll from My access → Passkeys). Multiple providers run in parallel — enable/disable each independently. Disabling one only removes that method; local password login is unaffected.`,emptyTitle:`No authentication providers registered`,emptyDescription:`Local auth should always be available — if this list is empty the local-auth builtin failed to register. Check the Addons page for load errors.`,installLabel:`Add provider`};function qe(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:ve,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA is self-enrolled: each user enables it from their own profile page (My access → Two-factor authentication).`,`API keys + scoped tokens are managed from the API Keys page.`],setupSteps:[`Add users from Users → New user (or seed via CAMSTACK_ADMIN_USER / CAMSTACK_ADMIN_PASS).`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:pe,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`First-time sign-ins are auto-provisioned with the configured Default Role.`],setupSteps:[`Register a web app at your IdP and copy the client_id + client_secret.`,"Set the redirect URI to `https://<this-hub>/addon/<addon-id>/callback`.",`Paste issuer + credentials in the Settings panel below — saves on every change.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:pe,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:U,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)||e.startsWith(`auth-magic-link`)?{headline:`TOTP / magic-link — second factor or passwordless sign-in.`,icon:U,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:F,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Je(){let e=A({capName:Q[0].capName},{refetchInterval:Z}),t=A({capName:Q[1].capName},{refetchInterval:Z}),r=_(void 0,{refetchInterval:Z}),i=n(()=>ge(r.data??[]),[r.data]),a=n(()=>{let n=[],r=[e.data??[],t.data??[]];for(let[e,t]of Q.entries())for(let a of r[e]??[])n.push({addonId:a.addonId,displayName:i.get(a.addonId)??a.addonId,isActive:a.isActive,capName:t.capName,stageBadge:t.stageBadge});return n},[e.data,t.data,i]);return s(he,{title:$.title,subtitle:$.subtitle,pageIcon:F,itemIcon:F,capability:Q[0].capName,installButtonLabel:$.installLabel,items:a,isLoading:e.isLoading||t.isLoading,emptyTitle:$.emptyTitle,emptyDescription:$.emptyDescription,renderStatusBadges:e=>e.stageBadge===null?null:s(`span`,{className:`inline-flex items-center rounded-full border border-primary/30 bg-primary/10 px-2 py-0.5 text-[10px] font-medium text-primary`,children:e.stageBadge}),renderExpandedPanel:e=>s(Ye,{addonId:e.addonId})})}function Ye({addonId:e}){let n=qe(e),r=n.icon;return t(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[t(`div`,{className:`flex items-start gap-2.5`,children:[s(r,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),s(`div`,{className:`text-xs text-foreground font-medium`,children:n.headline})]}),s(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:n.bullets.map((e,t)=>s(`li`,{children:e},t))}),n.setupSteps&&n.setupSteps.length>0&&t(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[t(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[s(_e,{className:`h-3 w-3`}),`Setup steps`]}),s(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:n.setupSteps.map((e,t)=>s(`li`,{children:e},t))})]}),e===`local-auth`&&t(`div`,{className:`rounded-md border border-blue-500/30 bg-blue-500/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[s(V,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),t(`span`,{children:[`TOTP / 2FA is self-service: each user enrols from their own profile page —`,` `,s(`a`,{href:`/system/my-access`,className:`underline text-primary`,children:`My access`}),` `,`→ “Two-factor authentication” → Enable 2FA. Admins can only remove a user’s active enrollment (lost device) from the`,` `,s(`a`,{href:`/system/users`,className:`underline text-primary`,children:`Users`}),` `,`page via Actions → “Remove 2FA”.`]})]})]})}function Xe(){return s(`div`,{className:`flex flex-col p-4`,children:s(me,{tabs:[{id:`users`,label:`Users`,icon:oe,content:s(Ee,{})},{id:`api-keys`,label:`Tokens`,icon:R,content:s(Me,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:ye,content:s(Ke,{})},{id:`authentication`,label:`Authentication`,icon:F,content:s(Je,{})}]})})}export{Xe as IdentityPage};
@@ -1 +0,0 @@
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{st as s}from"./player-overlays-CrKWnjLj.js";import{Dr as c,Du as l,G as u,Gu as d,Hu as f,Kl as p,Ri as m,Ru as h,Uu as g,Yl as _,Zn as v,ci as ee,di as y,ed as b,fi as x,gi as S,hi as C,li as te,mi as w,pi as T,rd as E}from"./src-Bkpo8B0D.js";import{Nt as D,br as O,er as k}from"./client-DWiaUxRQ.js";import{N as A}from"./index-Buq71VHG.js";import{t as j}from"./AdminPage-CiKtOLQm.js";import{t as M}from"./AdminTabs-CLXyClcg.js";import{t as N}from"./BrokerForm-DGnvvf1S.js";import{t as P}from"./useBodyScrollLock-BDocajQE.js";import{t as F}from"./AddonCollectionPage-BwMkNEOp.js";e();var I={"home-assistant":`Home Assistant`,mqtt:`MQTT`};function L(e){return I[e]??e}function R(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var z={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 B({status:e}){return o(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${z[e]}`,children:e})}function V(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function H({title:e,subtitle:n,onClose:r,children:i}){return P(),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(p,{className:`h-4 w-4`})})]}),o(`div`,{className:`p-4 max-h-[70vh] overflow-y-auto overscroll-contain`,children:i})]})})}function U({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(``),[m,h]=a(!1),[g,_]=a(``),v=e.find(e=>l(e)===u)??e[0],y=v?.kind??``,b=v?.addonId,x=ee({onSuccess:()=>{c.invalidateQueries({queryKey:[[`broker`,`list`]]}),s()}}),S=e=>{if(!y||f.trim().length===0)return;let t=m?g.trim():``;m&&t===``||x.mutate({kind:y,name:f.trim(),settings:e,...t===``?{}:{id:t},...b===void 0?{}:{addonId:b}})};return o(H,{title:`Add broker`,subtitle:`Register a message broker for exporters and automations.`,onClose:x.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:m,onChange:e=>h(e.target.checked)}),`Restore a broker that was removed, under its original id`]}),m&&t(r,{children:[o(`input`,{type:`text`,value:g,onChange:e=>_(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.`})]})]}),x.isError&&o(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:x.error instanceof Error?x.error.message:String(x.error)}),y&&o(N,{kind:y,...b===void 0?{}:{addonId:b},onSubmit:S,onCancel:n,submitLabel:x.isPending?`Adding…`:`Add broker`,disabled:x.isPending}),f.trim().length===0&&o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter a name before saving.`}),m&&g.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 W({broker:e,onClose:r,onDone:a}){let s=i(),c=te({id:e.id,addonId:e.addonId}),l=C({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(H,{title:`Edit ${e.name}`,subtitle:`${L(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(E,{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(N,{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 G({broker:e,onEdit:n}){let r=i(),c=v(),[l,u]=a(null),f=S({onSuccess:e=>u(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>u({ok:!1,error:e instanceof Error?e.message:String(e)})}),p=w({onSuccess:()=>{r.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),m=async()=>{await c({title:`Delete broker`,message:`Delete broker "${e.name}"? Integrations that depend on it will stop working.`,confirmLabel:`Delete`,variant:`danger`})&&p.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:L(e.kind)}),t(`td`,{className:`px-3 py-2`,children:[o(B,{status:e.status}),l&&o(`span`,{className:`ml-2 text-[10px] ${l.ok?`text-success`:`text-danger`}`,children:l.ok?`OK`:l.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:()=>f.mutate({id:e.id,addonId:e.addonId}),disabled:f.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:[f.isPending?o(E,{className:`h-3 w-3 animate-spin`}):o(_,{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(d,{className:`h-3 w-3`}),` Edit`]}),t(`button`,{type:`button`,onClick:()=>{m()},disabled:p.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:[p.isPending?o(E,{className:`h-3 w-3 animate-spin`}):o(s,{className:`h-3 w-3`}),`Delete`]})]})})]})}function K(){let e=x({}),r=T(),i=n(()=>V(e.data),[e.data]),[s,c]=a(!1),[l,u]=a(null),d=n(()=>{let e=new Map;for(let t of R(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:L(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:d.length===0,title:d.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(g,{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(E,{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(G,{broker:e,onEdit:u},e.id))]})]})}),s&&o(U,{kinds:d,onClose:()=>c(!1),onDone:()=>c(!1)}),l&&o(W,{broker:l,onClose:()=>u(null),onDone:()=>u(null)})]})}var q=[{kind:`device-export`,tabId:`device-export`,title:`Device export`,subtitle:`Outbound exporters that publish CamStack devices to other ecosystems (HomeAssistant, HomeKit, Alexa, …).`,icon:l,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:b,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:h,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 J(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 Y(e){let t=e,n=t?.manifest;if(!n?.id)return null;let r=[];for(let e of n.capabilities??[]){let t=J(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 X(e,t){let n=new Set(t);return e.filter(e=>e.capNames.some(e=>n.has(e)))}function Z(e){for(let[t,n]of Object.entries(D))if(n===e)return t;return null}function Q(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 ne({addonId:e}){let{data:t,isLoading:n}=y({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=O.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 re({addonId:e}){let{data:t,isLoading:n}=m({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=k.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 ie({kind:e,addonId:t}){return e===`broker`?o(ne,{addonId:t}):e===`device-export`?o(re,{addonId:t}):null}function ae({descriptor:e,rows:n,isLoading:i}){let a=Z(e.kind),s=e.kind===`device-export`,c=A();return o(F,{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=Q(n.processState);return t(r,{children:[o($,{label:i.label,className:i.className}),o(ie,{kind:e.kind,addonId:n.addonId})]})},renderExpandedPanel:s?e=>o(u,{addonId:e.addonId,onOpenDevice:e=>c(`/devices/${e}`)}):void 0,showChrome:!0})}function oe(){let e=c(void 0,{refetchInterval:1e4}),t=(e.data??[]).map(Y).filter(e=>e!==null);return o(j,{icon:f,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(M,{tabs:q.map(n=>{let r=Object.entries(D).filter(([,e])=>e===n.kind).map(([e])=>e),i=n.kind===`broker`?o(K,{}):o(ae,{descriptor:n,rows:X(t,r),isLoading:e.isLoading});return{id:n.tabId,label:n.title,icon:n.icon,content:i}})})})}export{oe as IntegrationsPage};
@@ -1 +0,0 @@
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{_t as l,at as u,gt as d,ht as f}from"./player-overlays-CrKWnjLj.js";import{Hd as p,Hu as m,K as h,Kl as g,Lu as _,Ou as v,Ui as ee,Uu as y,Y as b,ao as x,da as S,ea as te,eo as ne,fr as re,hr as C,q as w,r as T,rd as E,ro as D,zu as O}from"./src-Bkpo8B0D.js";import{t as k}from"./useTranslation-Bc5yH9V9.js";import{A,F as ie,N as j}from"./index-Buq71VHG.js";import{t as M}from"./AdminPage-CiKtOLQm.js";import"./useEventInvalidation-D1aOGj40.js";import{t as N}from"./StatusBadge-CeptlsPG.js";import{t as ae}from"./device-integration-icon-BnWP0LSQ.js";import{n as oe,r as P,t as F}from"./ScanNetworkModal-BPZGLiZQ.js";import{t as I}from"./useBodyScrollLock-BDocajQE.js";t();function L(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 R({providerId:e,onImport:t,onSkip:r}){let{t:i}=k(),[a,u]=o(new Set),d=te(),f=d.data,m=d.isPending||!d.data&&!d.isError;c(()=>{e&&(d.isPending||d.data||d.mutate({addonId:e}))},[e,d]);function h(e){u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(m)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 g=f??[];return n(`div`,{className:`space-y-4`,children:[s(`p`,{className:`text-xs text-foreground-subtle`,children:g.length>0?i(`integrations.foundDevices`,{count:g.length}):i(`integrations.noDevicesFound`)}),g.length>0&&s(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:g.map(e=>{let t=e.stableId,r=e.suggestedName??t,o=a.has(t),c=e.alreadyOnboarded===!0;return n(`button`,{onClick:()=>{c||h(t)},disabled:c,title:c?i(`integrations.alreadyAddedHint`,{defaultValue:`Already added as "{{name}}" — re-adding would overwrite its settings.`,name:e.onboardedName??r}):void 0,className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${c?`border-border bg-surface opacity-60 cursor-not-allowed`:o?`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 ${o&&!c?`border-primary bg-primary`:`border-border`}`,children:o&&!c&&s(p,{className:`h-3 w-3 text-primary-foreground`})}),s(l,{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}),c&&s(`span`,{className:`ml-auto flex-shrink-0 rounded bg-surface-muted px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:i(`integrations.alreadyAdded`,{defaultValue:`Already added`})})]},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`)}),g.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 z({onSelect:e,onClose:t,pendingAddonId:r=null}){let{t:i}=k(),a=j(),{data:o,isLoading:c}=D();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(E,{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(v,{className:`h-3 w-3`}),i(`integrations.manage`)]}):s(f,{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 se(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 B=2e4;function V({open:e,onClose:t}){let{t:l}=k(),u=j(),d=a(),[f,p]=o(`picker`),[m,h]=o(null),[_,v]=o(null),[y,b]=o(`manual`),[x,S]=o(null),[re,w]=o(``),[T,D]=o(null),[O,A]=o(null),[ie,M]=o(!1),{data:N}=C({addonId:m??``,nodeId:`hub`},{enabled:m!=null}),ae=r(()=>N?se(N):null,[N]),F=ne({onSuccess:()=>d.invalidateQueries({queryKey:[[`integrations`]]})}),V=te(),H=V.data;c(()=>{f!==`discovery`||!_||!m||V.isPending||V.data||V.mutate({addonId:m})},[f,_,m,V]);let ce=ee({onSuccess:()=>d.invalidateQueries({queryKey:[[`deviceManager`]]})});function le(e,t,n,r,i,a,o,s){if(!F.isPending){if(h(e),M(s),b(n),w(r),A(null),o===`broker`){if(!a){A(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}S(a),p(`broker`);return}if(o===`account`){p(`config`);return}U(e,r)}}async function U(e,n){try{let r=await F.mutateAsync({addonId:e,name:n,settings:{}});t(),J(),u(`/integrations/${r.id}?add=1`)}catch{}}async function W(e){if(m)try{let t=await F.mutateAsync({addonId:m,name:e.name,settings:e.config});v(t.id),y===`auto`||y===`both`?p(`discovery`):q(t.id)}catch{}}async function G(e){if(m)try{let t=await F.mutateAsync({addonId:m,name:re,settings:{brokerId:e}});D(t.id),v(t.id),q(t.id)}catch{}}async function K(e){if(m){for(let t of e){let e=H?.find(e=>e.stableId===t);e&&await ce.mutateAsync({addonId:m,candidate:e,...T===null?{}:{integrationId:T}})}q()}}function q(e){let n=e??_??m;t(),J(),n&&u(`/integrations/${n}`)}function J(){p(`picker`),h(null),v(null),b(`manual`),S(null),w(``),D(null),A(null),M(!1)}function Y(){t(),J()}I(e);let X=F.isPending,Z=L(X,B);if(!e)return null;let ue={picker:l(`integrations.newIntegration`),config:l(`integrations.configureIntegration`),discovery:l(`integrations.importDevices`),broker:l(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},Q=X?m:null,$=F.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:ue[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(g,{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:[O&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:O}),s(z,{onSelect:le,onClose:Y,pendingAddonId:Q})]}),f===`config`&&m&&s(oe,{addonId:m,configSchema:ae??null,canTest:ie,onSave:W,onBack:()=>p(`picker`)}),f===`broker`&&x&&s(P,{kind:x,onResolved:e=>{G(e)},onBack:()=>p(`picker`)}),f===`discovery`&&_&&s(R,{providerId:_,onImport:K,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(E,{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 H({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:f,{className:`h-3.5 w-3.5`})}),s(A,{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 ce(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>s(H,{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(N,{status:e.status})}]}t();function le(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var U=`expand`;function W(){let{t}=k(),a=j(),c=u(),[l]=ie(),[d,f]=o(!1),p=e(()=>f(!0),[]),g=e(()=>f(!1),[]),[v,ee]=o(!1),te=e(()=>ee(!0),[]),ne=e(()=>ee(!1),[]);T([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),T([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:C,isLoading:E,refetch:D}=x(void 0),{data:A,isLoading:N,refetch:oe}=S({projection:`slim`}),P=r(()=>A??[],[A]),I=r(()=>C??[],[C]),L=r(()=>{let e=new Map;for(let t of P)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[P]),R=r(()=>w(C),[C]),z=r(()=>{let e=new Map;for(let t of b(P)){let n=R(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[P,R]),se=r(()=>I.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:le(e),deviceCount:z.get(e.id)??0})),[I,z]),B=l.get(U),H=e(e=>{let t=new URLSearchParams(window.location.search);t.get(U)===e?t.delete(U):t.set(U,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`))},[]),W=e(e=>a(`/integrations/${e.id}`),[a]),G=e(e=>L.get(e)??null,[L]),K=e(e=>a(`/devices/${String(e)}`),[a]),q=e(e=>s(h,{context:`integration-detail`,devices:P,trpc:c.trpcClient,integrationOf:R,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:ae,resolveParent:G,onNavigate:K}),[P,c.trpcClient,R,G,K]),J=e(e=>B===e.addonId,[B]),Y=r(()=>ce({isExpanded:J,onToggleExpand:H}),[J,H]),X=e(e=>`${e.name} ${e.addonId}`,[]),Z=e(e=>e.addonId,[]),ue=e(()=>{D(),oe()},[D,oe]),Q=E||N,$=I.length>0;return n(M,{icon:m,title:t(`nav.integrations`,`Integrations`),actions:n(i,{children:[s(`button`,{onClick:ue,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(_,{className:re(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),n(`button`,{onClick:te,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the local network for devices`,children:[s(O,{className:`h-3.5 w-3.5`}),`Scan network`]}),n(`button`,{onClick:p,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(y,{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&&!$&&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&&$&&s(h,{mode:`generic`,items:se,getKey:Z,getSearchText:X,columns:Y,onRowClick:W,isExpanded:J,renderExpanded:q,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),s(V,{open:d,onClose:g}),s(F,{open:v,onClose:ne})]})}export{W as IntegrationsPage};
@@ -1 +0,0 @@
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{_t as a,vt as o}from"./player-overlays-CrKWnjLj.js";import{Dr as s,Hd as c,Or as l,St as u,df as d,il as f,ju as p,nl as m,rd as h,zl as g}from"./src-Bkpo8B0D.js";import{t as _}from"./layers-CTxykl5p.js";import{t as v}from"./useTranslation-Bc5yH9V9.js";import{I as y}from"./index-Buq71VHG.js";import{t as b}from"./AdminPage-CiKtOLQm.js";import{t as x}from"./AdminTabs-CLXyClcg.js";import{t as S}from"./AddonCollectionPage-BwMkNEOp.js";import{t as C}from"./addon-display-names-DvSEQty-.js";var w=o(`file-text`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),T=o(`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:p,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=m({},{refetchInterval:5e3}),a=f(),[o,s]=r(null),c=(e,t)=>{s(e),a.mutate({patch:{diagnostics:[{id:e,armMs:t}]}},{onSettled:()=>{s(null),n.refetch()}})},l=n.data?.activeWindows??[],u=n.data?.channels??[],p=n.data?.activeChannels??[],g=(e,t,r)=>{s(e),a.mutate({patch:{channels:[{channel:e,armMs:t,deviceIds:r}]}},{onSettled:()=>{s(null),n.refetch()}})};return t(b,{icon:d,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(h,{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:l.map(e=>i(N,{window:e,busy:o===e.id,onArm:t=>c(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.`)}),u.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:u.map(e=>i(M,{channel:e,state:p.find(t=>t.channel===e.name),busy:o===e.name,onArm:(t,n)=>g(e.name,t,n)},e.name))})]})}function M({channel:e,state:n,busy:o,onArm:s}){let{t:c}=v(),[l,u]=r(``),d=n?.armed===!0,f=()=>{let e=l.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}),d?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`}),c(`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:c(`logging.diagnostics.disarmed`,`disarmed`)}),d&&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(a,{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:c(`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:l,disabled:o,onChange:e=>u(e.target.value),placeholder:c(`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:o,onClick:()=>s(e,f()),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:o||!d,onClick:()=>s(0,null),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:c(`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(),[a,o]=r(I),[s,c]=r(L),{nodes:l}=g(),u=n(()=>l.map(e=>({id:e.id,label:e.name||e.id})),[l]),d=m({...a===I?{}:{scopeNodeId:a},...s===L?{}:{scopeComponent:s}},{refetchInterval:15e3}),p=f(),y=d.data,x=p.isPending||d.isFetching,S=y?.channels??[],C=(e,t)=>{p.mutate({...e.nodeId===null?{}:{scopeNodeId:e.nodeId},...e.component===null?{}:{scopeComponent:e.component},patch:{level:t}},{onSuccess:()=>void d.refetch()})};return i(b,{icon:_,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:a,disabled:s!==L,onChange:e=>o(e.target.value),children:[i(`option`,{value:I,children:e(`logging.levels.cluster`,`Cluster`)}),u.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:s,onChange:e=>c(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:d.isLoading||y===void 0?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(h,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}):t(`div`,{className:`space-y-3`,children:[i(B,{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(V,{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`}`))}),s!==L&&i(`p`,{className:`text-[11px] text-foreground-subtle`,children:S.find(e=>e.name===s)?.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.`)}),i(z,{days:y.opsLogRetentionDays,busy:x,onSet:e=>p.mutate({patch:{opsLogRetentionDays:e}},{onSuccess:()=>void d.refetch()})})]})})}function z({days:e,busy:n,onSet:r}){let{t:a}=v();return t(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-1`,children:[t(`label`,{className:`flex items-center justify-between gap-3`,children:[i(`span`,{className:`text-xs font-medium`,children:a(`logging.levels.opsLogRetention`,`Retention audit trail`)}),t(`span`,{className:`flex items-center gap-1.5`,children:[i(`input`,{type:`number`,min:0,max:3650,step:1,defaultValue:e,disabled:n,onBlur:t=>{let n=Number.parseInt(t.target.value,10);Number.isFinite(n)&&n!==e&&r(n)},className:`w-20 rounded border border-border bg-surface px-2 py-1 text-xs`}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:a(`common.days`,`days`)})]})]}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`logging.levels.opsLogRetentionNote`,`How long the record of what retention deleted is kept. Cluster-wide, and deliberately longer than any camera window — it is the history of the sweep, not of the camera, and it is what makes a storage leak explainable after the fact. 0 keeps it forever.`)})]})}function B({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 V({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(c,{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 H(){return i(b,{children:i(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:i(u,{limit:500,maxHeight:`max-h-[calc(100vh-310px)]`,showScope:!0,showFilters:!0})})})}function U(){return i(`div`,{className:`flex flex-col p-4`,children:i(x,{tabs:[{id:`viewer`,label:`Viewer`,icon:y,content:i(H,{})},{id:`destinations`,label:`Destinations`,icon:p,content:i(O,{})},{id:`levels`,label:`Levels`,icon:_,content:i(R,{})},{id:`diagnostics`,label:`Diagnostics`,icon:d,content:i(j,{})}]})})}export{U as LogsPage};
@@ -1 +0,0 @@
1
- import{I as e,K as t,Q as n,S as r,W as i,b as a,o,q as s,x as c,z as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{I as u,X as d,at as f,ct as p,lt as m,st as h,vt as g}from"./player-overlays-CrKWnjLj.js";import{Bn as _,Co as v,Cu as y,Do as b,Dr as x,Eo as S,Hd as C,It as w,Kl as T,Ln as E,Lu as ee,Mo as D,Mt as O,No as te,Nu as ne,Oo as re,Or as k,Pn as A,Po as ie,Pt as ae,Rt as oe,Sd as se,So as ce,To as le,Uu as ue,Wu as de,Yl as j,_o as fe,ar as M,bo as pe,da as me,df as he,dn as ge,fn as N,fo as _e,go as ve,gu as ye,kd as P,ko as be,ku as F,mo as xe,po as Se,qu as I,rd as L,su as R,td as Ce,vo as we,wo as Te,wu as z,xl as B,xo as Ee,yo as De,zn as Oe}from"./src-Bkpo8B0D.js";import{t as V}from"./boxes-Cz0W-SHm.js";import{Gn as ke,Hn as Ae,Wn as je,vn as H}from"./client-DWiaUxRQ.js";import"./mount-D1aOGj40.js";import{B as U,z as Me}from"./index-Buq71VHG.js";import{t as Ne}from"./AdminPage-CiKtOLQm.js";import{t as Pe}from"./NodeAddonsSettingsPanel-BgxOJU3d.js";import{t as Fe}from"./AdminTabs-CLXyClcg.js";import{t as W}from"./AddonCollectionPage-BwMkNEOp.js";import{t as G}from"./addon-display-names-DvSEQty-.js";var Ie=g(`file-up`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M12 12v6`,key:`3ahymv`}],[`path`,{d:`m15 15-3-3-3 3`,key:`15xj92`}]]),Le=g(`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`}]]);n();var K=5e3,Re={connected:!1,endpoint:null};function ze(){let e=o(),t=k({capName:`network-access`},{refetchInterval:K}),n=x(void 0,{refetchInterval:K}),r=i(()=>G(n.data??[]),[n.data]),a=i(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:r.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,r]),[l,u]=s(null),[d,f]=s({}),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=te({onSuccess:p,onError:m}),g=ie({onSuccess:p,onError:m});return c(W,{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:a,isLoading:t.isLoading,emptyTitle:`No remote-access providers installed`,emptyDescription:`Install a tunnel addon (e.g. @camstack/addon-cloudflare) to expose this hub publicly.`,renderStatusBadges:e=>c(Ve,{addonId:e.addonId}),itemError:e=>d[e.addonId]??null,renderPrimaryAction:e=>c(He,{addonId:e.addonId,busyId:l,onStart:e=>{u(e),h.mutate({addonId:e})},onStop:e=>{u(e),g.mutate({addonId:e})}})})}function Be(e){let{data:t}=D({addonId:e},{refetchInterval:K,retry:!1}),n=t?Ae.safeParse(t):null;return n?.success?n.data:Re}function Ve({addonId:e}){let t=Be(e);return r(a,{children:[c(`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&&r(`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:[c(se,{className:`h-3 w-3`}),t.endpoint.url]})]})}function He({addonId:e,busyId:t,onStart:n,onStop:i}){let a=Be(e),o=t===e;return a.connected?r(_,{size:`sm`,variant:`secondary`,disabled:o,onClick:()=>i(e),children:[o?c(L,{className:`h-3 w-3 animate-spin`}):c(p,{className:`h-3 w-3`}),`Stop`]}):r(_,{size:`sm`,variant:`primary`,disabled:o,onClick:()=>n(e),children:[o?c(L,{className:`h-3 w-3 animate-spin`}):c(de,{className:`h-3 w-3`}),`Start`]})}n();var Ue=3e4;function We(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function Ge(){let e=k({capName:`turn-provider`},{refetchInterval:Ue}),t=x(void 0,{refetchInterval:Ue}),n=B(),a=n.data??[],o=i(()=>G(t.data??[]),[t.data]);return c(W,{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:I,itemIcon:I,capability:`turn-provider`,installButtonLabel:`Add provider`,items:i(()=>(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=>c(Ke,{addonId:e.addonId,enabled:e.isActive}),trailing:r(A,{children:[r(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[r(`div`,{children:[c(`div`,{className:`text-sm font-semibold`,children:`Combined ICE server list`}),c(`div`,{className:`text-xs text-foreground-subtle`,children:`What the WebRTC layer fetches per-session.`})]}),c(_,{size:`sm`,variant:`secondary`,onClick:()=>n.refetch(),disabled:n.isFetching,children:`Refresh`})]}),c(`div`,{className:`p-4`,children:a.length===0?c(`div`,{className:`text-xs text-foreground-subtle`,children:`No servers from enabled providers.`}):c(`div`,{className:`flex flex-col gap-3`,children:a.map((e,t)=>{let n=Array.isArray(e.urls)?e.urls:[e.urls];return r(`div`,{className:`rounded border border-border bg-surface`,children:[(e.username||e.credential)&&r(`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&&r(`span`,{children:[c(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,c(`span`,{className:`text-foreground`,children:e.username})]}),e.credential&&r(`span`,{children:[c(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,c(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),c(`ul`,{className:`divide-y divide-border`,children:n.map(e=>c(`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 n=B({addonId:e},{enabled:t,retry:!1}),a=i(()=>We(n.data??[]),[n.data]);return!t||a.length===0?null:r(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[r(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Discovered ICE servers (`,a.length,`)`]}),c(`div`,{className:`flex flex-wrap gap-1`,children:a.map(e=>c(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground`,children:e},e))})]})}n();var qe={lan:I,wifi:j,docker:V,vpn:Ce,loopback:F,other:F},Je={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},Ye=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function Xe(e){let{interfaces:t,disabled:n,hideLoopback:a,ipv4Only:o,emptyMessage:s}=e,l=i(()=>t.filter(e=>!(a&&e.kind===`loopback`||o&&e.family!==`IPv4`)),[t,a,o]),u=i(()=>{let e=new Map;for(let t of l){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return Ye.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(n||t.kind===`loopback`)return;if(e.mode===`single`){e.onChange(e.value===t.address?null:t.address);return}let r=new Set(e.value);r.has(t.address)?r.delete(t.address):r.add(t.address),e.onChange([...r])};return l.length===0?c(`div`,{className:`text-xs text-foreground-subtle italic`,children:s??`No addresses available.`}):c(`div`,{className:`flex flex-col gap-3`,children:u.map(({kind:t,items:i})=>r(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[r(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[c(qe[t]??F,{className:`h-3.5 w-3.5 text-foreground-subtle`}),c(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:Je[t]??t}),r(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,i.length]})]}),c(`ul`,{className:`divide-y divide-border`,children:i.map(t=>{let i=d(t.address),a=t.kind===`loopback`,o=!t.plausible&&!a;return r(`li`,{className:`flex items-center gap-3 px-3 py-2 ${a?`opacity-60 cursor-not-allowed`:n?`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:[c(`span`,{className:`flex items-center justify-center h-4 w-4 rounded ${e.mode===`single`?`rounded-full`:`rounded`} border ${i?`border-primary bg-primary text-primary-foreground`:`border-border bg-surface`}`,children:i&&c(C,{className:`h-3 w-3`})}),r(`div`,{className:`flex-1 min-w-0 ${o?`text-foreground-subtle`:``}`,children:[r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[c(`span`,{className:`font-mono text-xs font-semibold ${o?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),c(`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&&c(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:`Auto-preferred`}),a&&c(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:`Always included`}),o&&r(`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:[c(R,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]}),r(`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))})}var q=[{role:`appConnections`,title:`App connections`,single:!1,help:`Addresses the CamStack apps try when connecting; tick several. Automatic: LAN addresses plus your public tunnel.`},{role:`notificationTaps`,title:`Notification taps`,single:!0,help:`Only where tapping a notification opens; one address. Automatic: the CamStack app link (opens the app if installed, otherwise the web app).`},{role:`publicEndpoint`,title:`Public endpoint`,single:!0,help:`Every link that must work away from home: sign-in, single sign-on and account linking, passkeys, and the buttons, attachments and admin links in notifications; one address. Automatic: your public tunnel, then Tailscale, then the LAN. Changing it invalidates registered passkeys.`},{role:`internal`,title:`Internal`,single:!0,help:`Where other CamStack machines and LAN devices download addons, models and media from; one address. Automatic: the hub's LAN address.`}],Ze=`A role with nothing ticked is automatic. Add a custom address when the hub is reached at an address it cannot see itself (NAT, reverse proxy, VPN, Docker bridge).`;function J(e,t){return e.inUse.includes(t)}function Qe(e,t){if(!e.eligible.includes(t))return{kind:`none`};if(e.kind===`app-link`)return J(e,t)?{kind:`none`}:{kind:`set`,input:{role:t,baseUrl:null,enabled:!0}};if(e.flags.includes(t)||t===`appConnections`&&J(e,t))return{kind:`set`,input:{role:t,baseUrl:e.baseUrl,enabled:!1}};let n={role:t,baseUrl:e.baseUrl,enabled:!0};return t===`publicEndpoint`&&e.baseUrl.startsWith(`http:`)?{kind:`confirm-http`,input:n,reason:je}:{kind:`set`,input:n}}function $e(e){return q.map(({role:t,title:n})=>{if(t===`appConnections`){let r=e.roles.appConnections;return{role:t,title:n,inUse:r.resolved.length===0?`nothing reachable`:r.resolved.join(`, `),automatic:r.source!==`flagged`}}let r=e.roles[t];return{role:t,title:n,inUse:r.resolved===null?`nothing reachable`:t===`notificationTaps`&&r.source===`auto`?`CamStack app link`:r.resolved,automatic:r.source!==`flagged`}})}n();var et={"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`},"app-link":{label:`App link`,className:`bg-amber-500/15 text-amber-700 dark:text-amber-300`},custom:{label:`Custom`,className:`bg-sky-500/15 text-sky-700 dark:text-sky-300`},loopback:{label:`Loopback`,className:`bg-foreground-subtle/15 text-foreground-subtle`}};function tt({book:e,loading:t,saving:n,error:i,onSetRole:a,onAdd:o,onRemove:l}){let[u,d]=s(``),[f,p]=s(``),[m,g]=s(null),[v,y]=s(null),b=()=>{let e=ke(u);if(!e.ok){g(e.reason);return}g(null),d(``),p(``),o(e.baseUrl,f.trim())},x=(e,t)=>{let n=Qe(e,t.role);if(n.kind!==`none`){if(n.kind===`confirm-http`){y({input:n.input,reason:n.reason});return}y(null),a(n.input)}},S=[{key:`url`,header:`Address`,render:t=>r(`div`,{className:`min-w-0 py-0.5`,children:[c(`div`,{className:`font-mono text-[12px] break-all ${t.plausible?`text-foreground`:`text-foreground-subtle`}`,children:t.baseUrl}),r(`div`,{className:`mt-0.5 flex flex-wrap items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[c(`span`,{children:t.label}),t.kind===`app-link`&&r(`span`,{className:`font-mono`,children:[`hub= `,e?.appLinkHub??`none (no tunnel or Tailscale)`]}),t.custom&&t.detected&&c(`span`,{children:`also added as a custom address`}),t.kind!==`custom`&&t.interfaceKind!==`lan`&&t.interfaceKind!==`public`&&t.interfaceKind!==`other`&&c(`span`,{className:`uppercase tracking-wide`,children:t.interfaceKind}),!t.plausible&&t.interfaceKind!==`loopback`&&r(`span`,{className:`inline-flex items-center gap-1 text-amber-700 dark:text-amber-300`,title:t.plausibleReason||void 0,children:[c(R,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]})]})},{key:`kind`,header:`Kind`,nowrap:!0,render:e=>{let t=et[e.kind]??et.loopback;return c(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.className}`,children:t.label})}},...q.map(e=>({key:e.role,headerRender:()=>c(`span`,{title:e.help,children:e.title}),align:`center`,nowrap:!0,width:`w-24`,render:t=>{let i=t.eligible.includes(e.role),a=t.flags.includes(e.role),o=J(t,e.role);return r(`label`,{className:`inline-flex items-center justify-center gap-1 ${i?`cursor-pointer`:`cursor-not-allowed opacity-40`}`,title:i?o&&!a?`${e.title}: in use automatically. ${e.help}`:e.help:`This address cannot be used for this.`,children:[c(ge,{checked:i&&o,disabled:!i||n,onChange:()=>x(t,e),"aria-label":`${e.title}: ${t.baseUrl}`}),o&&!a&&i&&c(`span`,{className:`text-[9px] text-foreground-subtle`,children:`auto`})]})}})),{key:`actions`,header:``,align:`right`,nowrap:!0,render:e=>e.custom?c(_,{size:`sm`,variant:`ghost`,disabled:n,onClick:()=>l(e.baseUrl),"aria-label":`Remove ${e.baseUrl}`,title:`Remove this custom address (its roles turn automatic)`,children:c(h,{className:`h-3 w-3`})}):null}],C=e===void 0?[]:$e(e);return r(A,{children:[r(`div`,{className:`px-4 py-3 border-b border-border flex flex-col gap-2`,children:[r(`div`,{children:[c(`div`,{className:`text-sm font-semibold`,children:`Addresses`}),c(`div`,{className:`text-xs text-foreground-subtle max-w-3xl`,children:`Every address this hub is reached at, detected or added by you. Tick what each one is used for.`}),r(`details`,{className:`mt-1.5 text-xs max-w-3xl`,"data-testid":`address-roles-help`,children:[c(`summary`,{className:`cursor-pointer select-none text-foreground-subtle hover:text-foreground`,children:`What are roles?`}),c(`dl`,{className:`mt-1.5 grid grid-cols-[auto_1fr] gap-x-3 gap-y-1`,children:q.map(e=>r(`div`,{className:`contents`,children:[c(`dt`,{className:`font-medium`,children:e.title}),c(`dd`,{className:`text-foreground-subtle`,children:e.help})]},e.role))}),c(`p`,{className:`mt-1.5 text-foreground-subtle`,children:Ze})]})]}),C.length>0&&c(`div`,{className:`grid grid-cols-[auto_1fr_auto] gap-x-3 gap-y-1 items-baseline text-xs`,"data-testid":`address-roles-summary`,children:C.map(e=>r(`div`,{className:`contents`,children:[c(`span`,{className:`text-foreground-subtle`,children:e.title}),r(`span`,{className:`font-mono break-all`,"data-testid":`address-role-${e.role}`,children:[e.inUse,c(`span`,{className:`ml-1.5 font-sans text-foreground-subtle`,children:e.automatic?`(automatic)`:`(set by you)`})]}),e.automatic?c(`span`,{}):c(_,{size:`sm`,variant:`secondary`,disabled:n,onClick:()=>a({role:e.role,baseUrl:null,enabled:!1}),children:`Use automatic`})]},e.role))}),v!==null&&r(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-xs flex flex-wrap items-center gap-2`,children:[c(R,{className:`h-3.5 w-3.5 text-amber-600`}),c(`span`,{className:`flex-1 min-w-[220px]`,children:v.reason}),c(_,{size:`sm`,variant:`secondary`,onClick:()=>{a({...v.input,acceptInsecureHttp:!0}),y(null)},children:`Use http anyway`}),c(_,{size:`sm`,variant:`ghost`,onClick:()=>y(null),children:`Cancel`})]}),i!==null&&c(`div`,{className:`text-[11px] text-red-600 dark:text-red-400`,role:`alert`,children:i})]}),c(oe,{columns:S,rows:e?.rows??[],rowKey:e=>`${e.kind}-${e.baseUrl}`,minWidthPx:760,bordered:!1,mobileMode:`scroll`,emptyMessage:t?`Loading…`:`No addresses available.`,rowClassName:e=>e.plausible?void 0:`opacity-80`}),r(`div`,{className:`px-4 py-3 border-t border-border flex flex-wrap items-start gap-2`,children:[r(`div`,{className:`flex-1 min-w-[220px]`,children:[c(N,{value:u,onChange:e=>{d(e.target.value),g(null)},placeholder:`https://cams.example.com or https://192.168.1.50:4443`,"aria-label":`Custom address`,disabled:n}),m!==null&&c(`div`,{className:`mt-1 text-[11px] text-red-600 dark:text-red-400`,children:m})]}),c(`div`,{className:`w-48`,children:c(N,{value:f,onChange:e=>p(e.target.value),placeholder:`Label (optional)`,"aria-label":`Custom address label`,maxLength:80,disabled:n})}),r(_,{size:`sm`,variant:`secondary`,disabled:n||u.trim()===``,onClick:b,children:[c(ue,{className:`h-3 w-3`}),`Add custom address`]})]})]})}n();function nt(){let e=o(),t=()=>{e.invalidateQueries({queryKey:[[`localNetwork`]]})},n=fe(void 0,{refetchInterval:3e4}),a=xe(void 0),u=v({onSuccess:t}),d=pe({onSuccess:e=>{C(e.addresses),t()}}),f=i(()=>n.data?.interfaces??[],[n.data]),p=Se({scheme:typeof window<`u`&&window.location.protocol===`https:`?`https`:`http`},{refetchInterval:3e4}),h=ce({onSuccess:t}),g=_e({onSuccess:t}),y=De({onSuccess:t}),b=h.error?.message??g.error?.message??y.error?.message??null,x=h.isPending||g.isPending||y.isPending,[S,C]=s([]),[w,T]=s(!1);l(()=>{!w&&a.data&&(C(a.data.addresses),T(!0))},[a.data,w]);let E=a.data?.addresses??[],D=i(()=>{if(S.length!==E.length)return!0;let e=[...S].toSorted(),t=[...E].toSorted();return e.some((e,n)=>e!==t[n])},[S,E]);return r(Ne,{children:[r(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[c(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Pin which host interfaces exist, then tick what each address is used for. Add a custom address when this hub is reached at one it cannot detect.`}),c(`div`,{className:`flex items-center gap-2 shrink-0`,children:r(_,{size:`sm`,variant:`secondary`,onClick:()=>{n.refetch(),a.refetch(),p.refetch()},disabled:n.isLoading,children:[c(ee,{className:`h-3 w-3 ${n.isLoading?`animate-spin`:``}`}),`Refresh`]})})]}),r(A,{children:[r(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between gap-3 flex-wrap`,children:[r(`div`,{children:[c(`div`,{className:`text-sm font-semibold`,children:`Allowed addresses`}),c(`div`,{className:`text-xs text-foreground-subtle`,children:S.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${S.length} pinned`})]}),r(`div`,{className:`flex items-center gap-1`,children:[r(_,{size:`sm`,variant:`secondary`,onClick:()=>d.mutate(void 0),disabled:d.isPending||u.isPending,title:`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`,children:[c(ye,{className:`h-3 w-3`}),d.isPending?`Detecting…`:`Best match`]}),r(_,{size:`sm`,variant:`secondary`,onClick:()=>{C([])},disabled:S.length===0||u.isPending,children:[c(m,{className:`h-3 w-3`}),`Clear`]}),D&&c(_,{size:`sm`,variant:`secondary`,onClick:()=>{C(E)},disabled:u.isPending,children:`Discard`}),r(_,{size:`sm`,variant:`primary`,onClick:()=>{u.mutate({addresses:[...S]})},disabled:!D||u.isPending,children:[c(ne,{className:`h-3 w-3`}),u.isPending?`Saving…`:`Save`]})]})]}),c(`div`,{className:`p-4`,children:c(Xe,{mode:`multiple`,interfaces:f,value:S,onChange:C,disabled:u.isPending,emptyMessage:n.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),c(tt,{book:p.data,loading:p.isLoading,saving:x,error:b,onSetRole:e=>h.mutate({...e}),onAdd:(e,t)=>g.mutate({baseUrl:e,label:t}),onRemove:e=>y.mutate({baseUrl:e})})]})}n();var rt={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},Y=5e3,it=3e4,at={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function ot(){let e=k({capName:`mesh-network`},{refetchInterval:Y}),t=x(void 0,{refetchInterval:Y}),n=i(()=>G(t.data??[]),[t.data]);return c(W,{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:V,itemIcon:I,capability:`mesh-network`,installButtonLabel:`Add mesh`,items:i(()=>(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=>c(st,{addonId:e.addonId}),renderPrimaryAction:e=>c(ct,{addonId:e.addonId}),renderExpandedPanel:e=>c(lt,{addonId:e.addonId})})}function X(e){let{data:t,isLoading:n}=le({addonId:e},{refetchInterval:Y,retry:!1}),r=t?H.safeParse(t):null;return{status:r?.success?r.data:at,isLoading:n}}function st({addonId:e}){let{status:t}=X(e);return r(a,{children:[c(`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&&r(`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 ct({addonId:t}){let n=o(),[i,l]=s(!1),[u,d]=s(null),p=f(),{status:m}=X(t),h=e(()=>{n.invalidateQueries({queryKey:[[`meshNetwork`]]})},[n]),g=be(),v=S({onSuccess:h}),y=re({onSuccess:h}),b=e(async()=>{l(!0);let e={cancelled:!1};d(e);try{let n=await g.mutateAsync({addonId:t});if(e.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!e.cancelled&&(await gt(2e3),!e.cancelled);){let e=await p.trpcClient.meshNetwork.getStatus.query({addonId:t}).catch(()=>null),n=e?H.safeParse(e):null;if(n?.success&&n.data.joined){h();break}if(Date.now()-r>6e5)break}}finally{l(!1),d(null)}},[t,h,g,p]),x=e(()=>{u&&(u.cancelled=!0),l(!1),d(null)},[u]);return c(a,{children:m.joined?r(a,{children:[r(_,{size:`sm`,variant:`secondary`,disabled:v.isPending,onClick:()=>v.mutate({addonId:t}),children:[v.isPending?c(L,{className:`h-3 w-3 animate-spin`}):c(Me,{className:`h-3 w-3`}),`Disconnect`]}),r(_,{size:`sm`,variant:`ghost`,disabled:y.isPending,onClick:()=>y.mutate({addonId:t}),children:[y.isPending?c(L,{className:`h-3 w-3 animate-spin`}):c(z,{className:`h-3 w-3`}),`Log out`]})]}):i?r(_,{size:`sm`,variant:`ghost`,onClick:x,children:[c(T,{className:`h-3 w-3 mr-1`}),` Cancel`]}):r(a,{children:[r(_,{size:`sm`,variant:`primary`,onClick:()=>void b(),children:[c(Le,{className:`h-3 w-3`}),`Connect`]}),r(_,{size:`sm`,variant:`ghost`,disabled:y.isPending,onClick:()=>y.mutate({addonId:t}),children:[y.isPending?c(L,{className:`h-3 w-3 animate-spin`}):c(z,{className:`h-3 w-3`}),`Log out`]})]})})}function lt({addonId:e}){let{status:t}=X(e),n=b({addonId:e},{refetchInterval:it,retry:!1});return r(`div`,{className:`rounded-lg border border-border bg-surface`,children:[r(`div`,{className:`p-4 space-y-4`,children:[t.error&&c(E,{message:t.error}),c(ut,{status:t}),t.endpoints.length>0&&r(`div`,{className:`space-y-1.5`,children:[c(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Endpoints`}),t.endpoints.map(e=>r(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[r(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${rt[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?c(U,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),r(`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:[c(se,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),c(`div`,{className:`border-t border-border`,children:c(ft,{peers:n.data?.peers??[],loading:n.isLoading})})]})}function ut({status:e}){return c(`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?dt(e.keyExpiry):`—`}].map(e=>r(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[c(`span`,{className:`text-foreground-subtle shrink-0`,children:e.label}),c(`span`,{className:`text-foreground truncate ${e.mono?`font-mono`:``}`,children:e.value})]},e.label))})}function dt(e){let t=e-Date.now();if(t<0)return`Expired ${ht(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 ft({peers:t,loading:n}){let a=i(()=>t.map(e=>({...e,_id:e.id})),[t]),o=e(e=>{e&&navigator.clipboard?.writeText(e)},[]),s=i(()=>[{key:`hostname`,header:`Hostname`,render:e=>r(`div`,{className:`flex flex-col`,children:[r(`div`,{className:`flex items-center gap-1.5`,children:[c(`span`,{className:`font-medium text-foreground`,children:e.hostname||`(unknown)`}),e.isSelf&&c(M,{variant:`info`,children:`self`}),e.exitNodeOption&&c(M,{variant:`warning`,children:`exit-node`})]}),e.userLogin&&c(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.userLogin})]})},{key:`magicDns`,header:`MagicDNS`,render:e=>e.magicDns?r(`div`,{className:`flex items-center gap-1`,children:[c(`span`,{className:`font-mono text-xs truncate`,children:e.magicDns}),c(`button`,{onClick:()=>o(e.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy MagicDNS`,children:c(P,{className:`h-3 w-3 text-foreground-subtle`})})]}):c(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:e=>{let t=e.addresses[0]??``;return t?r(`div`,{className:`flex items-center gap-1`,children:[c(`span`,{className:`font-mono text-xs`,children:t}),c(`button`,{onClick:()=>o(t),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy IP`,children:c(P,{className:`h-3 w-3 text-foreground-subtle`})})]}):c(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:`Connection`,render:e=>r(`div`,{className:`flex items-center gap-1.5`,children:[c(M,{variant:pt(e.connection),children:e.connection}),e.relay&&c(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.relay})]})},{key:`routes`,header:`Routes`,render:e=>e.advertisedRoutes.length>0?c(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):c(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:`TX / RX`,render:e=>r(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,mt(e.txBytes),` · ↓ `,mt(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>c(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?ht(e.lastSeenMs):`—`})}],[o]);return n&&t.length===0?r(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[c(L,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):t.length===0?c(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No peers visible — your tailnet may be empty or the host is not joined.`}):c(`div`,{className:`p-4`,children:c(oe,{columns:s,rows:a,rowKey:e=>e._id,minWidthPx:820})})}function pt(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function mt(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 ht(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 gt(e){return new Promise(t=>setTimeout(t,e))}var _t=/-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----/,Z=/-----BEGIN ((?:RSA |EC |ENCRYPTED )?PRIVATE KEY)-----[\s\S]+?-----END \1-----/,vt={certificate:`.pem,.crt,.cer`,privateKey:`.pem,.key`,ca:`.pem,.crt,.cer`};function Q(e,t){if(t.trim()===``)return null;if(e===`privateKey`){let e=Z.exec(t);return e===null?_t.test(t)?`This is a certificate, not a private key.`:`Not a PEM private key — expected -----BEGIN … PRIVATE KEY-----.`:e[1]===`ENCRYPTED PRIVATE KEY`?`The private key is password-protected. Export it without a passphrase.`:null}return _t.test(t)?e===`certificate`&&Z.test(t)?`This file also contains a private key. Pick the certificate file, and the key in its own field.`:null:Z.test(t)?`This is a private key, not a certificate.`:`Not a PEM certificate — expected -----BEGIN CERTIFICATE-----.`}function yt(e){return e.text()}n();function $({kind:e,label:n,value:i,onChange:a,rows:o=6}){let l=t(null),[u,d]=s(null),[f,p]=s(null),m=f??Q(e,i),h=`pem-${e}`,g=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t!==void 0){d(t.name);try{let e=await yt(t);p(null),a(e)}catch(e){p(`Could not read ${t.name}: ${e instanceof Error?e.message:String(e)}`)}}};return r(`div`,{className:`space-y-1`,children:[r(`div`,{className:`flex items-center justify-between gap-2`,children:[c(`label`,{htmlFor:h,className:`text-[11px] text-foreground-subtle`,children:n}),r(`div`,{className:`flex min-w-0 items-center gap-2`,children:[u!==null&&c(`span`,{className:`truncate font-mono text-[10px] text-foreground-subtle`,"data-testid":`${h}-file-name`,children:u}),c(`input`,{ref:l,type:`file`,accept:vt[e],onChange:e=>void g(e),className:`hidden`,"data-testid":`${h}-file`}),r(_,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>l.current?.click(),children:[c(Ie,{className:`mr-1 h-3 w-3`}),`Choose file`]})]})]}),c(`textarea`,{id:h,value:i,onChange:e=>{d(null),p(null),a(e.target.value)},rows:o,"aria-invalid":m!==null,className:`w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`}),m!==null&&c(`p`,{className:`text-[11px] text-danger`,role:`alert`,children:m})]})}n();function bt(e){if(e===null||e===``)return`—`;let t=e.replace(/:/g,``);return t.length<=16?e:`${t.slice(0,8)}…${t.slice(-8)}`}function xt(){let e=o(),t=ve(void 0,{refetchInterval:15e3}),n=we({onSuccess:()=>void e.invalidateQueries({queryKey:[[`localNetwork`]]})}),i=Ee({onSuccess:()=>void e.invalidateQueries({queryKey:[[`localNetwork`]]})}),a=Te({onSuccess:()=>{d(!1),p(``),h(``),v(``),e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),l=t.data,[u,d]=s(!1),[f,p]=s(``),[m,h]=s(``),[g,v]=s(``),b=()=>{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)},x=l?.mode===`uploaded`?`Uploaded`:l?.mode===`generated`?`Generated local CA`:`TLS disabled`;return r(`div`,{className:`flex flex-col gap-4`,children:[c(Pe,{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.`}),r(A,{className:`p-4 space-y-3`,children:[r(`div`,{className:`flex items-center gap-2`,children:[c(y,{className:`h-4 w-4 text-foreground-subtle`}),c(`h3`,{className:`text-sm font-semibold`,children:`Certificate`})]}),t.isError&&c(`p`,{className:`text-xs text-danger`,children:`Could not read TLS status.`}),l?.reissueError&&c(`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&&c(`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:`The HTTPS listener still serves the previous certificate. Restart the hub to apply it.`}),r(`dl`,{className:`grid grid-cols-1 gap-2 text-xs sm:grid-cols-2`,children:[r(`div`,{children:[c(`dt`,{className:`text-foreground-subtle`,children:`Mode`}),c(`dd`,{className:`font-medium`,children:x})]}),r(`div`,{children:[c(`dt`,{className:`text-foreground-subtle`,children:`Valid to`}),c(`dd`,{className:`font-mono`,children:l?.validTo?new Date(l.validTo).toLocaleString():`—`})]}),r(`div`,{children:[c(`dt`,{className:`text-foreground-subtle`,children:`Leaf SHA-256`}),c(`dd`,{className:`font-mono`,title:l?.leafFingerprintSha256??void 0,children:bt(l?.leafFingerprintSha256??null)})]}),r(`div`,{children:[c(`dt`,{className:`text-foreground-subtle`,children:`CA SHA-256`}),c(`dd`,{className:`font-mono`,title:l?.caFingerprintSha256??void 0,children:l?.mode===`uploaded`&&l.caFingerprintSha256===null?c(`span`,{className:`font-sans text-foreground-subtle`,children:`Issuer not included in the upload (not the local CA)`}):bt(l?.caFingerprintSha256??null)})]})]}),l&&l.sans.length>0&&c(`div`,{className:`flex flex-wrap gap-1`,children:l.sans.map(e=>c(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 font-mono text-[10px] text-foreground-subtle`,children:e},e))}),r(`div`,{className:`flex flex-wrap gap-2`,children:[c(O,{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`||n.isPending,action:()=>n.mutateAsync({})}),c(_,{size:`sm`,variant:`outline`,onClick:()=>d(e=>!e),children:`Upload`}),l?.caCertPem&&c(_,{size:`sm`,variant:`outline`,onClick:b,children:`Download CA`}),l?.mode===`uploaded`&&c(O,{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&&r(`div`,{className:`space-y-2 border-t border-border pt-3`,children:[c($,{kind:`certificate`,label:`Certificate or full chain (PEM)`,value:f,onChange:p}),c($,{kind:`privateKey`,label:`Private key (PEM)`,value:m,onChange:h}),c($,{kind:`ca`,label:`CA (PEM, optional)`,value:g,onChange:v,rows:4}),c(_,{size:`sm`,disabled:!f.trim()||!m.trim()||Q(`certificate`,f)!==null||Q(`privateKey`,m)!==null||Q(`ca`,g)!==null||a.isPending,onClick:()=>a.mutate({certPem:f,keyPem:m,...g.trim()?{caPem:g}:{}}),children:`Save certificate`}),a.isError&&c(`p`,{className:`text-xs text-danger`,children:a.error instanceof Error?a.error.message:`Upload failed`})]})]})]})}n();function St({value:e,onChange:t}){let{data:n}=me({isCamera:!0,projection:`slim`}),a=i(()=>n===void 0?[{value:``,label:`Loading cameras…`}]:n.length===0?[{value:``,label:`No cameras`}]:[{value:``,label:`Pick a camera`},...n.toSorted((e,t)=>e.name.localeCompare(t.name)).map(e=>({value:String(e.id),label:`${e.name} (#${String(e.id)})`}))],[n]);return r(`label`,{className:`flex min-w-0 flex-col gap-1`,children:[c(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Camera`}),c(Oe,{value:e===null?``:String(e),disabled:n===void 0||n.length===0,onChange:e=>t(e.target.value===``?null:Number(e.target.value)),options:a})]})}function Ct(){let t=f(),[n,i]=s(null);return r(`div`,{className:u,"data-testid":`network-diagnostics`,children:[c(w,{loadServers:e(async()=>t.trpcClient.turnProvider.getTurnServers.query(),[t])}),c(ae,{trpc:t.trpcClient,serverUrl:d(),deviceId:n,cameraField:c(St,{value:n,onChange:i})})]})}function wt(){return c(`div`,{className:`flex flex-col p-4`,children:c(Fe,{defaultTab:`addresses`,tabs:[{id:`local-access`,label:`Local access`,icon:j,content:c(xt,{})},{id:`addresses`,label:`Network Addresses`,icon:F,content:c(nt,{})},{id:`remote-access`,label:`Remote Access`,icon:U,content:c(ze,{})},{id:`mesh`,label:`Mesh Networks`,icon:V,content:c(ot,{})},{id:`turn`,label:`TURN Servers`,icon:I,content:c(Ge,{})},{id:`diagnostics`,label:`Diagnostics`,icon:he,content:c(Ct,{})}]})})}export{wt as NetworkPage};
@@ -1 +0,0 @@
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{at as h}from"./player-overlays-CrKWnjLj.js";import{Dr as g,Fi as _,Jr as v,_r as y,vr as ee}from"./src-Bkpo8B0D.js";import{ii as te}from"./client-DWiaUxRQ.js";import{_ as ne,b,v as re,x,y as ie}from"./index-Buq71VHG.js";r();var S=c(function({addonId:r,schema:i,serverValues:o,onImmediateSave:s,onStateChange:c,onAction:l,disabled:u},d){let f=x({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(b,{schema:i,values:f.values,onChange:f.handleChange,disabled:u,onAction:y})});function C(e){return`perNode`in e&&e.perNode===!0}function w(e,t){if(e.type===`group`){let n=T(e.fields,t);return n.length>0?{...e,fields:n}:null}if(e.type===`sub-tabs`){let n=e.tabs.map(e=>({...e,fields:T(e.fields,t)})).filter(e=>e.fields.length>0);return n.length>0?{...e,tabs:n}:null}return C(e)===(t===`perNode`)?e:null}function T(e,t){let n=[];for(let r of e){let e=w(r,t);e!==null&&n.push(e)}return n}function ae(e,t){let n=[];for(let r of e.sections){let e=T(r.fields,t);e.length!==0&&n.push({...r,fields:e})}return{...e,sections:n}}function oe(e,t){let n=e??`general`;return t?.[n]??n}function E(e){return typeof e!=`object`||!e||!(`key`in e)?null:typeof e.key==`string`?e.key:null}function se(e,t){let n=t.fieldKeys===void 0?null:new Set(t.fieldKeys),r=[];for(let i of e){let e=n===null?i.fields:i.fields.filter(e=>{let t=E(e);return t!==null&&n.has(t)});e.length!==0&&r.push({...i,fields:e,...t.tabAliases===void 0?{}:{tab:oe(i.tab,t.tabAliases)},...t.hideSectionChrome===!0?{title:``,description:void 0}:{}})}return r}r();function D(e,t){if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`){let n=e.fields.map(e=>D(e,t));return{...e,fields:n}}let n=e;t[e.key]=n.value;let{value:r,...i}=n;return i}function O(e,t){return{...e,fields:e.fields.map(e=>D(e,t))}}function ce(e){let t={};return{schema:{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>O(e,t))},values:t}}function k({nodeId:e,addonIds:r,level:c,deviceId:m,capability:b,sectionIds:x,omitSectionIds:S,fieldKeys:C,hideSectionChrome:w,tabAliases:T,tabLabelOverrides:E,sectionTab:D,fieldScope:O,surface:k,emptyMessage:ue,extraTabs:A,schemaTabExtras:j,title:M,description:N,selfTabbed:de,activeTab:fe,onActiveTabChange:pe}){let P=l(),F=h().trpcClient,I=ee(),L=y(),me=_(),he=v(),R=de===!0||!!(A&&A.length>0),[ge,_e]=d(null);if(c===`device`&&!m)throw Error(`NodeAddonsSettingsPanel: deviceId is required when level === "device"`);if(k!==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(O!==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`,k===void 0?c===`global`?`getGlobalSettings`:`getDeviceSettings`:`getIntegrationSettings`],{addonId:e,nodeId:z,deviceId:m??null,cap:b??null,scope:O??null}],queryFn:async()=>{let t=e=>e!==null&&O!==void 0?ae(e,O):e;return k===void 0?c===`global`?{addonId:e,result:t(await F.addonSettings.getGlobalSettings.query({addonId:e,nodeId:z,...b?{cap:b}:{}}))}:{addonId:e,result:t(await F.addonSettings.getDeviceSettings.query({addonId:e,deviceId:m,nodeId:z}))}:{addonId:e,result:await F.addonSettings.getIntegrationSettings.query({addonId:e,nodeId:z})}},placeholderData:u}))}),ve=B.some(e=>e.isLoading),ye=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(`||`),V=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(oe(t.tab,T))}return[...e]},[T,ye+`::`+B.map(e=>(e.data?.result?.sections??[]).map(e=>e.tab??`general`).join(`,`)).join(`::`)]),H=a(()=>new Map((A??[]).map(e=>[e.id,e])),[A]),U=a(()=>{if(!R)return[];let e=[...new Set([...V,...(A??[]).map(e=>e.id),...(j??[]).map(e=>e.tabId)])],t=e=>{let t=H.get(e);if(t?.order!==void 0)return t.order;let n=te[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})},[R,V,A,H,j]),be=a(()=>{let e=new Map,t=e=>te[e]?.label??e.charAt(0).toUpperCase()+e.slice(1);for(let n of V)e.set(n,t(n));for(let n of j??[])e.has(n.tabId)||e.set(n.tabId,t(n.tabId));for(let t of A??[])e.set(t.id,t.label);for(let[t,n]of Object.entries(E??{}))e.set(t,n);return e},[V,A,j,E]),W=fe===void 0?ge:fe,G=R?W&&U.includes(W)?W:U[0]??null:null,xe=e=>{_e(e),pe?.(e)},Se=G!==null&&H.has(G),K=R?G&&!Se?G:void 0:D,{data:Ce}=g(void 0),we=a(()=>{let e=new Map;for(let t of Ce??[]){let n=t.manifest?.id;if(!n)continue;let r=t.manifest?.name??t.manifest?.packageDisplayName??n;e.set(n,r)}return e},[Ce]),Te=n(new Map),q=a(()=>{let e=x?new Set(x):null,t=S?new Set(S):null,n=n=>!(e!==null&&!e.has(n)||t!==null&&t.has(n)),r=[];for(let e of B){if(!e.data)continue;let t=e.data.result??Te.current.get(e.data.addonId)??null;if(e.data.result!==null&&Te.current.set(e.data.addonId,e.data.result),t===null)continue;let{schema:i,values:a}=ce(t),o={...C===void 0?{}:{fieldKeys:C},...w===void 0?{}:{hideSectionChrome:w},...T===void 0?{}:{tabAliases:T}},s=se(i.sections.filter(e=>n(e.id)),o);if(s.length===0)continue;let c={...t,sections:se(t.sections.filter(e=>n(e.id)),o)},l={...i,sections:s};r.push({addonId:e.data.addonId,schemaWithValues:c,schema:l,serverValues:a})}return r},[ye,x,S,C,w,T]),[J,Ee]=d(new Map),De=t(e=>{Ee(t=>{let n=new Map(t);return n.set(e.addonId,e),n})},[]),Y=n(new Map),Oe=t(e=>t=>{t?Y.current.set(e,t):Y.current.delete(e)},[]),X=t(async(e,t)=>{c===`global`?await I.mutateAsync({addonId:e,nodeId:z,patch:t}):await L.mutateAsync({addonId:e,deviceId:m,nodeId:z,patch:t}),P.invalidateQueries({queryKey:[[`addonSettings`]]})},[I,L,z,c,m,P]),ke=t(async(e,t,n,r)=>{let i=z;try{switch(t){case`reprobe-hwaccel`:await me.mutateAsync({nodeId:i}),P.invalidateQueries({queryKey:[[`addonSettings`]]});return;case`reprobe-audio-engine`:await he.mutateAsync({nodeId:i}),P.invalidateQueries({queryKey:[[`addonSettings`]]});return;default:{let n=await F.addons.custom.mutate({addonId:e,action:t,input:r});return P.invalidateQueries({queryKey:[[`addonSettings`]]}),n}}}catch(n){throw console.error(`[NodeAddonsSettingsPanel] action failed`,{addonId:e,action:t,err:n}),n}},[me,he,z,P,F]),Ae=t((e,t)=>{X(e,t)},[X]),Z=f({mutationFn:async()=>{let e=[];for(let t of q){let n=J.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 I.mutateAsync({addonId:e,nodeId:z,patch:t}):await L.mutateAsync({addonId:e,deviceId:m,nodeId:z,patch:t}),e)))}},onSuccess:({saved:e})=>{for(let t of e)Y.current.get(t)?.discard();P.invalidateQueries({queryKey:[[`addonSettings`]]})}}),je=t(()=>{for(let e of Y.current.values())e.discard()},[]),Me=a(()=>{let e=0;for(let t of q){let n=J.get(t.addonId);n&&(e+=n.pendingKeys.length)}return e},[q,J]),Ne=a(()=>{let e=new Map;for(let t of q){let n=J.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},[q,J]);if(ve)return p(`div`,{className:`h-24 rounded-lg border border-border bg-surface animate-pulse`});let Q=G&&Se?H.get(G):void 0;if(!R&&q.length===0)return p(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:ue??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:[(M||N)&&i(`div`,{className:`border-b border-border pb-2`,children:[M&&p(`h2`,{className:`text-sm font-semibold text-foreground`,children:M}),N&&p(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:N})]}),R&&p(re,{tabs:U.map(e=>({id:e,label:be.get(e)??e})),activeId:G,onChange:xe,pendingByTab:Ne}),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(ne,{tabKey:Q?`extra:${G??``}`:`tab:${G??``}`,children:Q?Q.content:(()=>{let e=K?q.reduce((e,t)=>e+t.schemaWithValues.sections.filter(e=>(e.tab??`general`)===K).length,0):0,t=K!==null&&e<=1,n=q.map(e=>({...e,renderedWithValues:{...e.schemaWithValues,sections:e.schemaWithValues.sections.filter(e=>K?(e.tab??`general`)===K:!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=(j??[]).filter(e=>e.tabId===K),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:ue??`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(le,{entries:n,paneStates:J,displayNames:we,disabled:$,setPaneRef:Oe,onPaneStateChange:De,onImmediateSave:Ae,onAction:ke,inline:R||!!D}),o.map((e,t)=>p(`div`,{children:e.content},`extra-after-${t}`))]})})()}),!ve&&p(ie,{pendingCount:Me,onSave:()=>Z.mutate(),onDiscard:je,saving:$})]})}function le({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(S,{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{k as t};
@@ -1 +0,0 @@
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{Z as l}from"./player-overlays-CrKWnjLj.js";import{$i as u,Hd as d,Kl as f,Lu as p,Sd as m,Td as h,Ui as g,Vd as _,ci as v,da as y,fi as b,pi as x,rd as S,so as C,su as w,ta as T,ya as E,zu as D}from"./src-Bkpo8B0D.js";import{t as O}from"./useTranslation-Bc5yH9V9.js";import"./mount-D1aOGj40.js";import{b as k}from"./index-Buq71VHG.js";import{t as A}from"./BrokerForm-DGnvvf1S.js";n();var j=[`amazon.com`,`amazon.it`,`amazon.de`,`amazon.co.uk`,`amazon.fr`,`amazon.es`,`amazon.ca`,`amazon.com.au`,`amazon.co.jp`,`amazon.in`,`amazon.com.br`,`amazon.com.mx`],M=l(`/addon/import-alexa`),N=2e3;function P(e){return typeof e==`object`&&!!e&&typeof e.sessionId==`string`&&typeof e.loginUrl==`string`}function F(e){return typeof e==`object`&&!!e&&typeof e.phase==`string`&&typeof e.sessionId==`string`}function I(e){return typeof e==`object`&&!!e&&typeof e.brokerId==`string`}function L(e){return{"Content-Type":`application/json`,Authorization:`Bearer ${localStorage.getItem(`camstack_admin_token`)??``}`,...e}}async function R(e,t,n){let r=await fetch(`${M}${e}`,{method:`POST`,headers:L(),body:JSON.stringify(t)}),i=await r.json();if(!r.ok){let e=typeof i==`object`&&i?i.error??`Unknown error`:`Unknown error`;throw Error(String(e))}if(!n(i))throw Error(`Unexpected response from server`);return i}async function z(e){let t=new URLSearchParams({sessionId:e}),n=localStorage.getItem(`camstack_admin_token`)??``,r=await fetch(`${M}/login/status?${t.toString()}`,{headers:{Authorization:`Bearer ${n}`}}),i=await r.json();if(!r.ok){let e=typeof i==`object`&&i?i.error??`Unknown error`:`Unknown error`;throw Error(String(e))}if(!F(i))throw Error(`Unexpected status response from server`);return i}async function B(e){try{await fetch(`${M}/login/cancel`,{method:`POST`,headers:L(),body:JSON.stringify({sessionId:e})})}catch{}}function V({brokerId:n,onResolved:i,onCancel:a}){let[l,u]=o(`amazon.it`),[d,f]=o(`Alexa account`),[h,g]=o({kind:`idle`}),_=t(!0);c(()=>(_.current=!0,()=>{_.current=!1}),[]);let v=t(null),y=t(null),b=e(()=>{y.current!==null&&(clearInterval(y.current),y.current=null)},[]),x=e(async e=>{b(),_.current&&g({kind:`committing`,sessionId:e});try{let t=await R(`/login/commit`,{sessionId:e,name:d.trim().length>0?d.trim():`Alexa account`,...n===void 0?{}:{brokerId:n}},I);v.current=null,i(t.brokerId)}catch(t){let n=t instanceof Error?t.message:String(t);_.current&&g({kind:`error`,message:n,sessionId:e})}},[n,d,i,b]),C=e((e,t)=>{b();let n=async()=>{try{let n=await z(e);if(n.phase===`captured`){b(),x(e);return}if(n.phase===`error`){b(),_.current&&g({kind:`error`,message:n.error??`Login proxy returned an error`,sessionId:e});return}if(n.phase===`cancelled`){b(),_.current&&g({kind:`idle`});return}_.current&&g({kind:`polling`,sessionId:e,loginUrl:n.loginUrl||t,phase:n.phase})}catch(e){let t=e instanceof Error?e.message:String(e);_.current&&g(e=>e.kind===`polling`?{...e}:{kind:`error`,message:t,sessionId:null})}};y.current=setInterval(()=>{n()},N)},[b,x]);c(()=>()=>{b(),v.current!==null&&B(v.current)},[b]);let T=async()=>{b(),v.current!==null&&(B(v.current),v.current=null),g({kind:`starting`});try{let e=await R(`/login/start`,{amazonDomain:l},P);v.current=e.sessionId,g({kind:`polling`,sessionId:e.sessionId,loginUrl:e.loginUrl,phase:`starting`}),C(e.sessionId,e.loginUrl)}catch(e){g({kind:`error`,message:e instanceof Error?e.message:String(e),sessionId:null})}},E=()=>{b(),v.current!==null&&(B(v.current),v.current=null),g({kind:`idle`})},D=()=>{E()},O=h.kind===`idle`,k=h.kind===`starting`,A=h.kind===`polling`,M=h.kind===`committing`,F=h.kind===`error`,L=k||A||M,V=h.kind===`polling`?h.phase:null,H=h.kind===`polling`?h.loginUrl:null,U=A&&V===`awaiting-login`,W=A&&(V===`starting`||V===null);return r(`div`,{className:`space-y-4`,children:[(O||F)&&r(`div`,{className:`space-y-3`,children:[n===void 0&&r(`div`,{className:`space-y-1`,children:[s(`label`,{htmlFor:`alexa-account-name`,className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Account name`}),s(`input`,{id:`alexa-account-name`,type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:`Alexa account`,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`})]}),r(`div`,{className:`space-y-1`,children:[s(`label`,{htmlFor:`alexa-amazon-region`,className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Amazon region`}),s(`select`,{id:`alexa-amazon-region`,value:l,onChange:e=>u(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:j.map(e=>s(`option`,{value:e,children:e},e))})]})]}),F&&r(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px] flex items-start gap-2`,children:[s(w,{className:`h-3.5 w-3.5 mt-0.5 flex-shrink-0`}),s(`span`,{children:h.message})]}),k&&r(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-3 text-xs text-foreground-subtle`,children:[s(S,{className:`h-4 w-4 animate-spin flex-shrink-0`}),`Starting login proxy…`]}),W&&r(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-3 text-xs text-foreground-subtle`,children:[s(S,{className:`h-4 w-4 animate-spin flex-shrink-0`}),`Waiting for proxy to be ready…`]}),M&&r(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-3 text-xs text-foreground-subtle`,children:[s(S,{className:`h-4 w-4 animate-spin flex-shrink-0`}),`Saving credentials…`]}),U&&H!==null&&r(`div`,{className:`space-y-3`,children:[r(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-2`,children:[s(`p`,{className:`text-xs font-semibold text-foreground`,children:`Open the link below to log in to your Amazon account`}),s(`p`,{className:`text-[10px] text-foreground-subtle`,children:`After completing the login and any 2FA steps, this wizard will continue automatically.`}),r(`a`,{href:H,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:[s(m,{className:`h-3.5 w-3.5`}),`Login to Amazon`]})]}),r(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[10px] text-amber-700 dark:text-amber-300`,children:[s(`strong`,{children:`Note:`}),` The login proxy runs directly on the hub. If the link does not open or the page does not load, make sure the hub's proxy host and port are reachable from your browser. You can configure `,s(`code`,{className:`font-mono`,children:`proxyHost`}),` in the Alexa addon settings and ensure the proxy port is published (Docker port mapping).`]}),r(`div`,{className:`flex items-center gap-2 text-[10px] text-foreground-subtle`,children:[s(S,{className:`h-3 w-3 animate-spin`}),`Waiting for Amazon login to complete…`]})]}),r(`div`,{className:`flex items-center justify-between gap-2 pt-1`,children:[s(`button`,{type:`button`,onClick:L?E:a,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:L?`Cancel login`:`Back`}),r(`div`,{className:`flex items-center gap-2`,children:[F&&r(`button`,{type:`button`,onClick:D,className:`inline-flex items-center gap-1.5 rounded border border-border px-3 py-1.5 text-xs text-foreground hover:bg-primary/10`,children:[s(p,{className:`h-3.5 w-3.5`}),`Retry`]}),O&&s(`button`,{type:`button`,onClick:()=>{T()},disabled:n===void 0&&d.trim().length===0,className:`inline-flex items-center gap-1.5 rounded bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:`Start login`})]})]})]})}n();var H=`alexa`;function U(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function W(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var G={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 K({kind:e,onResolved:t,onBack:n}){let[a,c]=o(e===H?`alexa-login`:`existing`),l=b({kind:e}),u=i(()=>U(l.data).filter(t=>t.kind===e),[l.data,e]),d=x(),f=i(()=>{for(let t of W(d.data))if(t.kinds.some(t=>t.kind===e))return t.addonId},[d.data,e]),[p,m]=o(null),[h,g]=o(``),y=v({}),C=()=>{p&&t(p)},w=async n=>{h.trim().length!==0&&t((await y.mutateAsync({kind:e,name:h.trim(),settings:n,...f===void 0?{}:{addonId:f}})).id)},T=e=>{e===`new`?m(null):y.reset(),c(e)};return r(`div`,{className:`space-y-4`,children:[r(`button`,{type:`button`,onClick:n,className:`inline-flex items-center gap-1 text-[11px] text-foreground-subtle hover:text-foreground`,children:[s(_,{className:`h-3.5 w-3.5`}),` Back`]}),r(`div`,{className:`inline-flex rounded-lg border border-border p-0.5 flex-wrap gap-0.5`,children:[e===H&&s(`button`,{type:`button`,onClick:()=>T(`alexa-login`),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${a===`alexa-login`?`bg-primary text-primary-foreground`:`text-foreground-subtle hover:text-foreground`}`,children:`Login interactively`}),s(`button`,{type:`button`,onClick:()=>T(`existing`),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${a===`existing`?`bg-primary text-primary-foreground`:`text-foreground-subtle hover:text-foreground`}`,children:`Use existing`}),s(`button`,{type:`button`,onClick:()=>T(`new`),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${a===`new`?`bg-primary text-primary-foreground`:`text-foreground-subtle hover:text-foreground`}`,children:e===H?`Paste cookie`:`Create new`})]}),a===`alexa-login`&&s(V,{onResolved:t,onCancel:n}),a===`existing`&&r(`div`,{className:`space-y-3`,children:[l.isLoading&&r(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(S,{className:`h-3.5 w-3.5 animate-spin`}),` Loading brokers…`]}),l.isError&&r(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[`Failed to load brokers:`,` `,l.error instanceof Error?l.error.message:`Unknown error`]}),!l.isLoading&&!l.isError&&u.length===0&&r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-6 text-center text-xs text-foreground-subtle`,children:[`No brokers of this kind yet. Switch to`,` `,s(`span`,{className:`font-medium text-foreground`,children:e===H?`Login interactively`:`Create new`}),` `,`to register one.`]}),s(`div`,{className:`space-y-2`,children:u.map(e=>r(`button`,{type:`button`,onClick:()=>m(e.id),className:`flex w-full items-center justify-between gap-3 rounded-lg border bg-surface p-3 text-left transition-colors ${p===e.id?`border-primary ring-1 ring-primary`:`border-border hover:border-foreground-subtle/30`}`,children:[s(`span`,{className:`text-xs font-semibold text-foreground`,children:e.name}),s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${G[e.status]}`,children:e.status})]},e.id))}),u.length>0&&s(`div`,{className:`flex justify-end pt-1`,children:s(`button`,{type:`button`,onClick:C,disabled:!p,className:`inline-flex items-center gap-1.5 rounded bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:`Use this broker`})})]}),a===`new`&&r(`div`,{className:`space-y-3`,children:[r(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Name`}),s(`input`,{type:`text`,value:h,onChange:e=>g(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`})]}),y.isError&&s(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:y.error instanceof Error?y.error.message:String(y.error)}),s(A,{kind:e,...f===void 0?{}:{addonId:f},onSubmit:e=>{w(e).catch(()=>{})},onCancel:n,submitLabel:y.isPending?`Creating…`:`Create broker`,disabled:y.isPending||h.trim().length===0}),h.trim().length===0&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter a name before creating.`})]})]})}n();function q(e){return{status:e.status===`validated`||e.status===`rejected`||e.status===`inconclusive`||e.status===`unsupported`?e.status:e.success?`validated`:`rejected`,...e.error===void 0?{}:{error:e.error},...e.detail===void 0?{}:{detail:e.detail}}}var J={validated:`border-success/30 bg-success/5 text-success`,rejected:`border-danger/30 bg-danger/5 text-danger`,inconclusive:`border-warning/30 bg-warning/5 text-warning`,unsupported:`border-border bg-surface text-foreground-subtle`};function Y({addonId:e,configSchema:t,canTest:n=!0,initialName:i,initialConfig:a,submitLabel:c,hideName:l=!1,onSave:u,onBack:d}){let{t:f}=O(),[p,m]=o(i??``),[h,g]=o(a??{}),[_,v]=o(null),y=C({onSuccess:e=>v(q(e)),onError:e=>v({status:`inconclusive`,error:String(e)})});return r(`div`,{className:`space-y-4`,children:[!l&&r(`div`,{children:[s(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:f(`integrations.integrationName`)}),s(`input`,{type:`text`,value:p,onChange:e=>m(e.target.value),placeholder:f(`integrations.integrationNamePlaceholder`),className:`w-full rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:border-primary/50`})]}),t&&s(k,{schema:t,values:h,onChange:g}),_&&s(`div`,{className:`rounded-lg border px-3 py-2 text-xs ${J[_.status]}`,children:(e=>{switch(e.status){case`validated`:return e.detail?`${f(`integrations.connectionSuccess`)} — ${e.detail}`:f(`integrations.connectionSuccess`);case`rejected`:return`${f(`integrations.errorPrefix`)} ${e.error??``}`;case`inconclusive`:return`${f(`integrations.connectionInconclusive`,{defaultValue:`Could not be checked:`})} ${e.error??``}`;case`unsupported`:return e.error??f(`integrations.connectionUntestable`,{defaultValue:`This integration cannot be tested before it is created.`})}})(_)}),r(`div`,{className:`flex items-center justify-between pt-2`,children:[s(`button`,{onClick:d,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:f(`integrations.back`)}),r(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:()=>y.mutate({addonId:e,settings:h}),disabled:y.isPending||!n,title:n?void 0:f(`integrations.connectionUntestable`,{defaultValue:`This integration cannot be tested before it is created.`}),className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:y.isPending?f(`integrations.testing`):f(`integrations.testConnection`)}),s(`button`,{onClick:()=>u({name:p,config:h}),disabled:l?!1:!p.trim(),className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:c??f(`integrations.forward`)})]})]})]})}n();function X({open:t,onClose:n,scope:a}){let c=g(),[l,u]=o(new Set),[p,m]=o(new Set),{data:_}=y({projection:`slim`}),v=i(()=>new Set((_??[]).map(e=>e.stableId)),[_]),b=e(async(e,t)=>{m(e=>new Set(e).add(t.stableId));try{await c.mutateAsync({addonId:e,candidate:t}),u(e=>new Set(e).add(t.stableId))}catch{}finally{m(e=>{let n=new Set(e);return n.delete(t.stableId),n})}},[c]),x=e((e,t)=>{let n=typeof t.prefilledConfig.host==`string`?t.prefilledConfig.host:null,i=v.has(t.stableId),a=l.has(t.stableId)||i,o=p.has(t.stableId);return r(`div`,{className:`flex items-center justify-between rounded-lg border border-border bg-surface px-3 py-2`,children:[r(`div`,{className:`min-w-0`,children:[s(`p`,{className:`truncate text-xs font-medium text-foreground`,children:t.suggestedName}),n&&s(`p`,{className:`truncate text-[10px] font-mono text-foreground-subtle`,children:n})]}),a?r(`span`,{className:`flex items-center gap-1 text-[11px] text-foreground-subtle`,children:[s(d,{className:`h-3.5 w-3.5`}),` `,i?`Already added`:`Added`]}):r(`button`,{type:`button`,onClick:()=>void b(e,t),disabled:o,className:`flex items-center gap-1 rounded-md bg-primary px-2.5 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-50`,children:[o?s(S,{className:`h-3.5 w-3.5 animate-spin`}):s(h,{className:`h-3.5 w-3.5`}),`Add`]})]},t.stableId)},[l,p,v,b]);if(!t)return null;let C=a?`Scan network — ${a.label}`:`Scan network for devices`;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:n}),r(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[calc(90dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl`,children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[r(`div`,{className:`flex items-center gap-2`,children:[s(D,{className:`h-4 w-4 text-primary`}),s(`h2`,{className:`text-sm font-semibold text-foreground`,children:C})]}),s(`button`,{onClick:n,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:s(f,{className:`h-4 w-4`})})]}),a?s(Q,{scope:a,onAdopt:x,onReset:()=>u(new Set)}):s(Z,{onAdopt:x,onReset:()=>u(new Set)})]})]})}function Z({onAdopt:t,onReset:n}){let o=u(),l=e(()=>{n(),o.mutate({})},[o,n]);c(()=>{!o.isPending&&!o.data&&l()},[]);let d=i(()=>(o.data?.groups??[]).filter(e=>e.candidates.length>0),[o.data]),f=i(()=>d.reduce((e,t)=>e+t.candidates.length,0),[d]);return r(a,{children:[s(`div`,{className:`flex items-center justify-end gap-2 border-b border-border px-5 py-2 shrink-0`,children:r(`button`,{onClick:l,disabled:o.isPending,className:`flex items-center gap-1 rounded-md border border-border px-2 py-1 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[s(p,{className:`h-3.5 w-3.5 ${o.isPending?`animate-spin`:``}`}),`Re-scan`]})}),r(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-4`,children:[o.isPending&&s(ee,{label:`Scanning the local network…`}),!o.isPending&&o.isError&&s($,{}),!o.isPending&&o.data&&d.length===0&&s(`p`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:`No devices responded to the scan.`}),!o.isPending&&d.length>0&&r(`p`,{className:`text-xs text-foreground-subtle`,children:[`Found `,f,` device`,f===1?``:`s`,` on the network.`]}),!o.isPending&&d.map(e=>r(`div`,{className:`space-y-1.5`,children:[r(`div`,{className:`flex items-center gap-2`,children:[s(`span`,{className:`text-[11px] font-semibold text-foreground`,children:e.label}),r(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`(`,e.candidates.length,`)`]})]}),e.candidates.map(n=>t(e.addonId,n))]},e.addonId))]})]})}function Q({scope:t,onAdopt:n,onReset:i}){let c=E({addonId:t.addonId}).data??null,[l,u]=o({}),d=T(),f=e(()=>{i(),d.mutate({addonId:t.addonId,params:l})},[d,t.addonId,l,i]),p=d.data?.candidates??[];return s(a,{children:r(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-4`,children:[c&&s(k,{schema:c,values:l,onChange:u}),r(`button`,{onClick:f,disabled:d.isPending,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground disabled:opacity-50`,children:[d.isPending?s(S,{className:`h-3.5 w-3.5 animate-spin`}):s(D,{className:`h-3.5 w-3.5`}),d.isPending?`Scanning…`:`Scan`]}),d.isError&&s($,{}),!d.isPending&&d.data&&p.length===0&&s(`p`,{className:`py-6 text-center text-xs text-foreground-subtle`,children:`No devices responded to the scan.`}),!d.isPending&&p.length>0&&r(`div`,{className:`space-y-1.5`,children:[r(`p`,{className:`text-xs text-foreground-subtle`,children:[`Found `,p.length,` device`,p.length===1?``:`s`,`.`]}),p.map(e=>n(t.addonId,e))]})]})})}function ee({label:e}){return r(`div`,{className:`flex flex-col items-center py-12`,children:[s(S,{className:`h-6 w-6 animate-spin text-primary`}),s(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:e})]})}function $(){return r(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[s(w,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),s(`p`,{className:`text-xs text-destructive`,children:`The scan failed. Try again.`})]})}export{Y as n,K as r,X as t};
@@ -1 +0,0 @@
1
- function e(e){let t=new Map;for(let n of e){let e=n?.manifest;e?.id&&t.set(e.id,e.name??e.packageDisplayName??e.id)}return t}export{e as t};
@@ -1 +0,0 @@
1
- import{vt as e}from"./player-overlays-CrKWnjLj.js";var t=e(`circle-slash`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`9`,x2:`15`,y1:`15`,y2:`9`,key:`1dfufj`}]]);export{t};
@@ -1 +0,0 @@
1
- import{vt as e}from"./player-overlays-CrKWnjLj.js";var t=e(`crop`,[[`path`,{d:`M6 2v14a2 2 0 0 0 2 2h14`,key:`ron5a4`}],[`path`,{d:`M18 22V8a2 2 0 0 0-2-2H2`,key:`7s9ehn`}]]);export{t};
@@ -1 +0,0 @@
1
- import"./src-Bkpo8B0D.js";