@camstack/addon-admin-ui 1.2.357 → 1.2.358

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 (74) hide show
  1. package/assets/icon.svg +5 -0
  2. package/dist/assets/Addons-BpNMAC8g.js +4 -0
  3. package/dist/assets/{AdminTabs-Bxj9C3Dy.js → AdminTabs-CjafoxvK.js} +1 -1
  4. package/dist/assets/{AiProfiles-CRNStk_J.js → AiProfiles-BeZSyNFd.js} +1 -1
  5. package/dist/assets/{BrokerForm-61eZ_BQs.js → BrokerForm-vK7o_-sd.js} +1 -1
  6. package/dist/assets/Build-CHPyiOzb.js +40 -0
  7. package/dist/assets/{Calendars-CxIkYKMB.js → Calendars-py7REb8I.js} +1 -1
  8. package/dist/assets/{Capabilities-DTXiVb2I.js → Capabilities-CTyuV2mU.js} +1 -1
  9. package/dist/assets/{Cluster-CAwWppiE.js → Cluster-Dvmv3-5C.js} +1 -1
  10. package/dist/assets/ClusterStepModel-BCXM90oM.js +1 -0
  11. package/dist/assets/{CompositionEditor-Bvf3zgNl.js → CompositionEditor-Bktdwhnn.js} +1 -1
  12. package/dist/assets/{CompositionEditorPage-CQgnsFrf.js → CompositionEditorPage-DXiq4mMC.js} +1 -1
  13. package/dist/assets/{Data-BGRBmkR_.js → Data-DtUlsreq.js} +1 -1
  14. package/dist/assets/{DetectionIntelligence-VZ9CIaLa.js → DetectionIntelligence-BHcjDiGb.js} +1 -1
  15. package/dist/assets/{DeviceDetail-CrnxJ6Hc.js → DeviceDetail-TJQ3r5Wf.js} +2 -2
  16. package/dist/assets/{DeviceDoActionFields-D3Jdh2OV.js → DeviceDoActionFields-4wfCnUDo.js} +1 -1
  17. package/dist/assets/{Devices-CBwOsnyo.js → Devices-Zuh3Gb1y.js} +1 -1
  18. package/dist/assets/{EmbedPlayerPage-BWcoakS7.js → EmbedPlayerPage-Cfayr0_2.js} +1 -1
  19. package/dist/assets/{Events-Dr5IMWMQ.js → Events-C8rtJF0X.js} +1 -1
  20. package/dist/assets/Identity-BHqbF-VQ.js +1 -0
  21. package/dist/assets/IntegrationDetail-DDZBkRYs.js +1 -0
  22. package/dist/assets/IntegrationHub-C_kwGzUm.js +1 -0
  23. package/dist/assets/Integrations-B3NL6Bhn.js +1 -0
  24. package/dist/assets/{Integrations-DDDwMXbl.js → Integrations-D3H9rujI.js} +1 -1
  25. package/dist/assets/{Locations-CxMnoEvK.js → Locations-BIetkfhV.js} +1 -1
  26. package/dist/assets/{Logs-DP7amiQW.js → Logs-BYKgLvH-.js} +1 -1
  27. package/dist/assets/{MyAccess-k7c8CGXR.js → MyAccess-B8HF1nGo.js} +1 -1
  28. package/dist/assets/Network-m6TRq9hZ.js +1 -0
  29. package/dist/assets/{NodeAddonsSettingsPanel-C1eKgxhI.js → NodeAddonsSettingsPanel-DhbzB3yG.js} +1 -1
  30. package/dist/assets/{Notifications-DAPVC99C.js → Notifications-DWpao1R2.js} +1 -1
  31. package/dist/assets/{Plates-hAYS43bp.js → Plates-BW_rdxX6.js} +1 -1
  32. package/dist/assets/{Recordings-CF6Q6s4b.js → Recordings-DJmbAZFE.js} +1 -1
  33. package/dist/assets/{ScanNetworkModal-CJGyqlYW.js → ScanNetworkModal-mYvbo8Uo.js} +1 -1
  34. package/dist/assets/{Scenes-oXjWvgG4.js → Scenes-CyjlxaOP.js} +1 -1
  35. package/dist/assets/{Secrets-I8Q8kwRj.js → Secrets-DgQr5Kxc.js} +1 -1
  36. package/dist/assets/{Settings-VQUbUtH9.js → Settings-cSyoiNRe.js} +1 -1
  37. package/dist/assets/{Showroom-Bp0BOf3S.js → Showroom-CVxQH10K.js} +1 -1
  38. package/dist/assets/{Terminal-tyLcs3hl.js → Terminal-5aXU64zN.js} +1 -1
  39. package/dist/assets/{Viewer-t4jfelvu.js → Viewer-CSSu8htq.js} +1 -1
  40. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CIsQtLaa.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DxPQ0X7S.js} +1 -1
  41. package/dist/assets/{authed-media-st_x8Og8.js → authed-media-DKCCsaRv.js} +1 -1
  42. package/dist/assets/{debounced-invalidate-BWOIWEOF.js → debounced-invalidate-7E55pOhB.js} +1 -1
  43. package/dist/assets/{device-integration-icon-Ce7zluJx.js → device-integration-icon-CPFH1cD5.js} +1 -1
  44. package/dist/assets/device-picker-model-DDC4ATOt.js +1 -0
  45. package/dist/assets/{face-bbox-Bx59CISY.js → face-bbox-BLwRunnv.js} +1 -1
  46. package/dist/assets/{hostInit-DQ0THwU5.js → hostInit-DAWBqgef.js} +1 -1
  47. package/dist/assets/index-CpGfiJoj.js +4 -0
  48. package/dist/assets/{location-owned-usage-B5PZZAJ9.js → location-owned-usage-CFYIPCzN.js} +1 -1
  49. package/dist/assets/{mf-entry-bootstrap-0-bd894cd4.js → mf-entry-bootstrap-0-127f685c.js} +2 -2
  50. package/dist/assets/mount-DDC4ATOt.js +1 -0
  51. package/dist/assets/{notification-schedule-field-Drw0rQZp.js → notification-schedule-field-CrLB-wdt.js} +1 -1
  52. package/dist/assets/remoteEntry-Cpe5-iTU.js +1 -0
  53. package/dist/assets/{src-DOjmjjKA.js → src-DzkLcOyh.js} +1 -1
  54. package/dist/assets/{use-scenes-feed-BgsO7otE.js → use-scenes-feed-BUMM_vS8.js} +1 -1
  55. package/dist/assets/{use-stationary-objects-e1GejQDW.js → use-stationary-objects-F6FJkq-t.js} +1 -1
  56. package/dist/assets/useEventInvalidation-DDC4ATOt.js +1 -0
  57. package/dist/assets/{useNodeUrlSelection-DoS5q0lF.js → useNodeUrlSelection-CWDgf9EZ.js} +1 -1
  58. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CFTJqMAA.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-D0bzMnfx.js} +2 -2
  59. package/dist/index.html +5 -5
  60. package/dist/server/addon.js +1 -1
  61. package/package.json +4 -2
  62. package/dist/assets/Addons-BNOOF9Mv.js +0 -4
  63. package/dist/assets/Build-Bo19wI67.js +0 -40
  64. package/dist/assets/ClusterStepModel-DhxYveGL.js +0 -1
  65. package/dist/assets/Identity-DQ7LByxK.js +0 -1
  66. package/dist/assets/IntegrationDetail-CskqQg63.js +0 -1
  67. package/dist/assets/IntegrationHub-T7WCtw8g.js +0 -1
  68. package/dist/assets/Integrations-BqdlA2Gi.js +0 -1
  69. package/dist/assets/Network-wpLc77BL.js +0 -1
  70. package/dist/assets/device-picker-model-x_xV7wRP.js +0 -1
  71. package/dist/assets/index-BNq9yPTv.js +0 -4
  72. package/dist/assets/mount-x_xV7wRP.js +0 -1
  73. package/dist/assets/remoteEntry-YA5HmvZR.js +0 -1
  74. package/dist/assets/useEventInvalidation-x_xV7wRP.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-D4lg_avJ.js";import{$l as p,Bd as m,Cd as h,Cr as g,Fd as _,Gl as v,H as y,Hl as b,In as x,Jl as S,Jn as C,Kl as w,Ld as T,M as E,N as D,Nt as ee,Pu as O,Ql as te,U as k,Ul as ne,Vd as A,Wl as re,Xl as j,Yl as M,Zl as ie,Zu as N,_f as P,bu as F,cf as I,ef as L,eu as R,id as z,iu as ae,nu as oe,ql as se,qn as B,rd as V,ru as ce,sa as le,tr as ue,tu as de,wr as H,wu as U,xd as fe,xf as pe,zd as me}from"./src-DOjmjjKA.js";import{t as he}from"./unlink-ZWAv-UAl.js";import{a as ge,i as _e,o as ve,s as ye}from"./client-BqN2lVYf.js";import{$ as be,F as W,G as xe,o as Se,s as Ce}from"./index-BNq9yPTv.js";import{t as G}from"./AdminPage-BSFohA3i.js";import{t as we}from"./AdminTabs-Bxj9C3Dy.js";import{n as Te,r as Ee,t as De}from"./IntegrationHub-T7WCtw8g.js";import{n as Oe,t as ke}from"./addon-display-names-BkwMrExv.js";var Ae=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`}]]),je=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`}]]),Me=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 Ne({userId:e,username:n,onClose:r}){let i=B(),a=F.useUtils(),o=S({userId:e}),c=F.auth.listLoginMethods.useQuery(),l=ce({onSuccess:()=>void a.userManagement.listExternalIdentities.invalidate()}),u=new Map((c.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),d=o.data??[],f=async(t,r)=>{await i({title:`Remove sign-in link`,message:`"${n}" will no longer be able to sign in with this ${r} account.`,confirmLabel:`Remove`,variant:`danger`})&&l.mutate({userId:e,provider:t.provider,subject:t.subject})};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`,{"data-testid":`external-identities-modal`,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(T,{className:`h-4 w-4 text-primary`}),t(`div`,{children:[s(`div`,{className:`text-sm font-medium text-foreground`,children:`Linked sign-in accounts`}),t(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,s(`span`,{className:`font-mono`,children:n})]})]})]}),s(`button`,{onClick:r,"aria-label":`Close`,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:s(U,{className:`h-4 w-4`})})]}),t(`div`,{className:`p-4 space-y-3`,children:[o.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(_,{className:`h-3.5 w-3.5 animate-spin`}),`Loading…`]}):d.length===0?s(`p`,{className:`text-xs text-foreground-subtle`,children:`No linked accounts. Only the user can link one, from their own profile page.`}):s(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:d.map(e=>{let n=u.get(e.provider),r=n??e.provider;return t(`li`,{className:`flex items-center gap-3 px-3 py-2 text-xs`,children:[t(`div`,{className:`flex-1 min-w-0`,children:[t(`div`,{className:`font-medium text-foreground truncate`,children:[r,n===void 0&&s(`span`,{className:`ml-2 rounded bg-foreground-subtle/15 px-1.5 py-0.5 text-[10px] font-normal text-foreground-subtle`,children:`provider unavailable`})]}),t(`div`,{className:`text-[11px] text-foreground-subtle truncate`,children:[e.label??e.subject,` ·`,` `,new Date(e.linkedAt).toLocaleDateString()]})]}),t(`button`,{onClick:()=>void f(e,r),disabled:l.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[s(he,{className:`h-3 w-3`}),`Remove`]})]},`${e.provider}|${e.subject}`)})}),s(`div`,{className:`flex justify-end`,children:s(x,{onClick:r,variant:`secondary`,children:`Close`})})]})]})})}function Pe({userId:e,username:n,onClose:r}){let o=a(),c=B(),l=w({userId:e}),u=l.data,d=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),f=v({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(N,{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(U,{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(_,{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(A,{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(P,{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(x,{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(_,{className:`h-3 w-3 animate-spin`}):s(U,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function K({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 Fe({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}=le({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(z,{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(_,{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(K,{icon:L,label:`Devices they can see`,count:p.device.view.deviceCount,all:p.device.view.all,total:f}),s(K,{icon:h,label:`Devices they can operate`,count:p.device.create.deviceCount,all:p.device.create.all,total:f}),s(K,{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 Ie(e){let t=ve(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 Le(e){return e.mode===`advanced`?e.advancedScopes:e.roleId===null?[]:ge({roleId:e.roleId,selector:e.selector,includeLinked:e.includeLinked})}function Re({user:e,onClose:r,onSubmit:a,submitting:c,callerScopes:d}){let f=n(()=>Ie(e.scopes??[]),[e.scopes]),[p,m]=o(f),[h,g]=o(f.mode===`advanced`),v=n(()=>Le(p),[p]),b=!e.isAdmin&&p.mode===`role`&&p.roleId===null,x=n(()=>e.isAdmin?null:p.mode===`role`&&p.roleId===null?`Pick what this user can do to see the result.`:D(v),[e.isAdmin,p.mode,p.roleId,v]),S=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(U,{className:`h-4 w-4`})})]}),t(`div`,{className:`min-h-0 flex-1 space-y-4 overflow-y-auto px-4 py-4`,children:[b&&t(`div`,{className:`flex items-start gap-2 rounded-lg border border-warning/40 bg-warning/10 p-3`,children:[s(z,{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:_e.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:()=>S({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:v}),g(!0);return}g(!1),m(Ie(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(E,{value:p.advancedScopes,onChange:e=>S({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(y,{value:p.selector,onChange:e=>S({selector:e}),includeLinked:p.includeLinked,onIncludeLinkedChange:e=>S({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(Fe,{scopes:v,isAdmin:e.isAdmin,invalidReason:x})]})]}),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([...v]),disabled:c||x!==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(_,{className:`h-3 w-3 animate-spin`}):`Save access`})]})]})})}e();var ze=8;function Be(){let e=a(),{user:n}=W(),[r,i]=o(!1),[c,l]=o(``),[u,f]=o(``),[p,m]=o(!1),[h,g]=o(null),{data:v,isLoading:y,isError:b}=ie(),x=B(),S=C(),w=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),E=ne({onSuccess:()=>{w(),i(!1),l(``),f(``),m(!1),g(null)},onError:e=>{g(e instanceof Error?e.message:`Failed to create user`)}}),D=re({onSuccess:w}),O=ae({onSuccess:w}),k=te({onSuccess:w}),A=oe({onSuccess:()=>{w(),M(null)}}),[j,M]=o(null),[P,F]=o(null),[I,L]=o(null),R=v??[];async function z(e){await x({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`})&&D.mutate({id:e.id})}async function se(e){let t=await S({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<ze?`Password must be at least ${String(ze)} characters.`:null});t===null||t.length===0||await x({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&k.mutate({id:e.id,newPassword:t})}function ce(e,t){t!==e.isAdmin&&O.mutate({id:e.id,isAdmin:t})}function le(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}return t(G,{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(fe,{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(U,{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:p,onChange:e=>m(e.target.checked),className:`rounded border-border focus:ring-primary`}),s(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),h&&s(`p`,{className:`text-[10px] text-danger`,children:h}),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:()=>E.mutate({username:c,password:u,isAdmin:p}),disabled:E.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:E.isPending?`Creating...`:`Create`})]})]}),y&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),b&&s(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!y&&!b&&R.length===0&&s(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>D.isPending&&D.variables?.id===e.id||O.isPending&&O.variables?.id===e.id||k.isPending&&k.variables?.id===e.id;return s(ee,{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=>ce(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:()=>M(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(V,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(Ve,{scopes:e.scopes??[]})]})},{key:`createdAt`,header:`Created`,render:e=>s(`span`,{className:`text-foreground-subtle`,children:le(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:()=>F(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(N,{className:`h-3 w-3`}),`Remove 2FA`]}),t(`button`,{onClick:()=>L(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:`Linked sign-in accounts`,children:[s(T,{className:`h-3 w-3`}),`Sign-in links`]}),t(`button`,{onClick:()=>se(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(me,{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(_,{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(Pe,{userId:P.id,username:P.username,onClose:()=>F(null)}),I&&s(Ne,{userId:I.id,username:I.username,onClose:()=>L(null)}),j&&s(He,{user:j,onClose:()=>M(null),onSubmit:e=>A.mutate({userId:j.id,scopes:e}),submitting:A.isPending})]})}function Ve({scopes:e}){if(e.length===0)return s(`span`,{className:`font-medium text-warning`,children:`No access`});let n=ve(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:ye(n.roleId).label}),` ·`,` `,k(n.selector)]})}function He(e){let{user:t}=W(),n=t?.isAdmin===!0;return s(Re,{...e,callerScopes:n?null:t?.scopes??[]})}e();var Ue=`bg-primary/10 text-primary`,We=`bg-foreground-subtle/10 text-foreground-subtle`;function q(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function Ge(e){return e?e===`*`?`*`:e.join(`, `):``}function Ke(){let e=a(),r=B(),{data:i,isLoading:c}=se(),{data:l}=ie(),u=n(()=>i??[],[i]),f=n(()=>l??[],[l]),m=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),h=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[g,v]=o(!1),[y,x]=o(null),S=p({onSuccess:m}),C=b({onSuccess:({token:e,record:t})=>{h(),v(!1),x({token:e,label:t.name})}}),w=de({onSuccess:h}),T=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`})&&S.mutate({id:e})},E=async(e,t)=>{await r({title:`Revoke "${t}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&w.mutate({id:e})};return t(G,{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(V,{className:`h-3.5 w-3.5`}),`New token`]})]}),t(qe,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[f.length===0&&s(Ye,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),f.map(e=>s(Ze,{userId:e.id,username:e.username,onRevoke:(e,t)=>{E(e,t)},revokePending:w.isPending,revokeId:w.variables?.id},e.id))]}),u.length>0&&s(qe,{title:`Legacy API keys`,subtitle:`${u.length} pre-existing — revoke only`,children:s(Xe,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:u.map(e=>{let n=!!e.isAdmin,r=S.isPending&&S.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?Ue:We}`,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:Ge(e.allowedProviders)||`all`}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:q(e.createdAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:q(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:t(`button`,{onClick:()=>{T(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(_,{className:`h-3 w-3 animate-spin`}):s(d,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),c&&s(Je,{}),g&&s(Qe,{users:f.map(e=>({id:e.id,username:e.username})),onClose:()=>v(!1),onSubmit:e=>C.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:C.isPending}),y&&s($e,{token:y.token,label:y.label,onClose:()=>x(null)})]})}function qe({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 Je(){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 Ye({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 Xe({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 Ze({userId:e,username:n,onRevoke:r,revokePending:i,revokeId:a}){let{data:o,isLoading:c}=j({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(Xe,{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`?`[${k(e.selector)}]`:e.target]},n))})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:q(e.expiresAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:q(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:q(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(_,{className:`h-3 w-3 animate-spin`}):s(d,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function Qe({users:e,onClose:n,onSubmit:r,submitting:i}){let{user:a}=W(),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(``),v=D(p),y=l!==``&&d.trim().length>0&&p.length>0&&v===null&&!i;return t(J,{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(E,{value:p,onChange:m,clampToParent:c}),v&&s(`p`,{className:`mt-1 text-[10px] text-danger`,children:v})]}),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(et,{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:!y,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(_,{className:`h-3.5 w-3.5 animate-spin`}):s(V,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function $e({token:e,label:n,onClose:r}){let[i,a]=o(!1),c=async()=>{try{await navigator.clipboard.writeText(e),a(!0)}catch{}};return t(J,{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(et,{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(pe,{className:`h-3.5 w-3.5 text-primary`}):s(I,{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 J({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(U,{className:`h-4 w-4`})})]}),s(`div`,{className:`p-4`,children:r})]})})}function et({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 tt(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 nt(){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 rt({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 it({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 at(){let e=a(),r=B(),{data:i,isLoading:o}=M(),c=n(()=>i??[],[i]),l=R({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(G,{icon:Me,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(nt,{}),!o&&c.length===0&&s(rt,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!o&&c.length>0&&s(it,{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:tt(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(_,{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`,subtitle:`Login providers (local password, OIDC, SAML, magic-link) and second-factor providers (passkeys / WebAuthn). They run in parallel — enable or 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 ot(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:je,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:[`A fresh hub has one account, admin / changeme — the first sign-in asks for a new password. Add users from Users → New user.`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:be,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`Explicit linking only: an IdP account signs in only the CamStack user who linked it from their profile (My access → Linked sign-in accounts). No auto-created users, no email matching.`,`The linked user’s role, scopes and two-factor authentication apply.`],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.`,`Each user then links their IdP account from My access → Linked sign-in accounts.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:be,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:N,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:N,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:V,bullets:[`Generic authentication provider. No additional hints registered.`]}}function st(){let e=H({capName:Q[0].capName},{refetchInterval:Z}),t=H({capName:Q[1].capName},{refetchInterval:Z}),r=g(void 0,{refetchInterval:Z}),i=n(()=>ke(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]),o=[{id:`authentication`,label:`Authentication providers`,install:{capability:Q[0].capName,label:$.installLabel},entries:a.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:V,...Oe(e.isActive),render:()=>s(Te,{addonId:e.addonId,displayName:e.displayName,capName:e.capName,isActive:e.isActive,badges:e.stageBadge===null?null:s(ue,{variant:`info`,className:Ee,children:e.stageBadge}),panels:[{id:`about`,title:`About`,icon:ot(e.addonId).icon,content:s(ct,{addonId:e.addonId})}]})}))}];return s(De,{icon:V,title:$.title,subtitle:$.subtitle,groups:o,isLoading:e.isLoading||t.isLoading,emptyTitle:$.emptyTitle,emptyDescription:$.emptyDescription})}function ct({addonId:e}){let n=ot(e),r=n.icon;return t(`div`,{className:`space-y-3 rounded-lg border border-border bg-surface p-2 sm:p-4`,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(Ae,{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(A,{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(xe,{to:`/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(xe,{to:`/system/identity?tab=users`,className:`underline text-primary`,children:`Users`}),` `,`page via Actions → “Remove 2FA”.`]})]})]})}function lt(){return s(`div`,{className:`flex flex-col p-4`,children:s(we,{tabs:[{id:`users`,label:`Users`,icon:O,content:s(Be,{})},{id:`api-keys`,label:`Tokens`,icon:m,content:s(Ke,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:Me,content:s(at,{})},{id:Ce.authentication.tab,label:`Authentication`,icon:V,content:s(st,{}),ownedParams:Se}]})})}export{lt as IdentityPage};
@@ -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{Z as u,at as d,gt as f,ht as p,mt as m,st as h,vt as g}from"./player-overlays-D4lg_avJ.js";import{$a as _,$i as v,Bi as y,Dt as b,Du as x,Fd as S,Hi as C,It as w,Ji as T,K as E,Ki as D,Na as ee,Qa as O,Qi as k,Qt as A,Ui as j,Vi as te,Wi as ne,Y as re,Za as M,_d as N,_t as P,dr as F,ef as I,eo as L,ff as R,fr as z,ga as ie,gf as B,hd as ae,io as V,kr as H,ld as oe,ma as se,md as ce,na as U,no as W,od as le,pn as G,pu as ue,q as de,qi as fe,sa as pe,to as me,uu as he,wu as ge,xd as _e,xf as ve,zf as ye,zu as K}from"./src-DOjmjjKA.js";import{Tr as be}from"./client-BqN2lVYf.js";import{t as xe}from"./useTranslation-Bc5yH9V9.js";import"./mount-x_xV7wRP.js";import{J as Se,K as Ce,N as we,q as Te}from"./index-BNq9yPTv.js";import{t as Ee}from"./NodeAddonsSettingsPanel-C1eKgxhI.js";import{t as De}from"./device-integration-icon-Ce7zluJx.js";import{n as Oe,r as q,t as ke}from"./ScanNetworkModal-CJGyqlYW.js";var Ae=g(`search-x`,[[`path`,{d:`m13.5 8.5-5 5`,key:`1cs55j`}],[`path`,{d:`m8.5 8.5 5 5`,key:`a8mexj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]);n();function je(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...je(n.fields));return t}function Me(t,n,r){let[a,o]=s(`idle`),[c,l]=s({}),u=i(()=>{let e=[];for(let n of t.sections)e.push(...je(n.fields));return e},[t]),d=u.length>0&&r!==void 0,f=e(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:a,hasProbeFields:d,probeResults:c,handleTestAll:e(async()=>{if(!r)return;let e=u.filter(e=>{let t=n[e];return t!=null&&String(t).trim()!==``});if(e.length===0)return;o(`testing`);let t={};for(let n of e)t[n]={status:`probing`};l(t);let i=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await r(e,n[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),a={};for(let e of i)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;a[t]={status:n.status===`ok`?`ok`:`error`,result:n}}l(a),o(`idle`)},[r,u,n]),clearProbeResult:f}}n();function Ne(e){let t=[];for(let n of e)`required`in n&&n.required===!0&&`key`in n&&n.key&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Ne(n.fields));return t}function Pe(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Fe(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Fe(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function J(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function Ie({open:t,integrationId:n,addonId:a,onClose:u}){let{t:d}=xe(),p=o(),[m,h]=s({}),[g,_]=s(!1),[v,y]=s(null),[b,C]=s(J),w=se({addonId:a},{enabled:t}),T=w.data?.deviceType??null,E=U({addonId:a,type:T??be.Camera},{enabled:t&&w.isSuccess&&T!==null}),D=E.data??null;l(()=>{t&&(h(D?Fe(D.sections.flatMap(e=>e.fields)):{}),C(J()),_(!1),y(null))},[t,n,D]);let O=i(()=>({...m,_probeRequestId:b}),[m,b]),k=fe({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),A=ee(),j=e(async(e,t)=>{_(!0);let n=await A.mutateAsync({addonId:a,type:T??be.Camera,key:e,value:t,formValues:O});return n.status===`ok`&&n.suggestedValues&&h(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Pe(e[i])&&!Pe(a)&&(r[i]=a,t=!0);return t?r:e}),n},[A,a,O,T]),{testAllStatus:te,hasProbeFields:ne,probeResults:re,handleTestAll:M,clearProbeResult:N}=Me(D??{sections:[]},m,j);async function F(e){y(null);try{await k.mutateAsync({addonId:a,type:T??be.Camera,config:m,integrationId:n}),e?h(D?Fe(D.sections.flatMap(e=>e.fields)):{}):u()}catch(e){y(e instanceof Error?e.message:String(e))}}if(!t)return null;let I=Ne((D?.sections??[]).flatMap(e=>e.fields)).filter(e=>Pe(m[e])),L=I.length===0,R=w.isLoading||T!==null&&E.isLoading,z=w.isError||w.isSuccess&&T===null||E.isError||E.isSuccess&&D===null;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:u}),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:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:d(`integrations.addDevice`)}),c(`button`,{onClick:u,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:c(ge,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:R?c(`div`,{className:`flex items-center justify-center py-8`,children:c(S,{className:`h-5 w-5 animate-spin text-primary`})}):z?r(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[c(K,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`space-y-1`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,c(`span`,{className:`font-mono`,children:a}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):c(we,{schema:D,values:m,onChange:h,onTestField:j,probeResults:re,onClearProbe:N})}),!z&&!R&&r(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[r(`button`,{type:`button`,onClick:()=>_(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[r(`span`,{className:`flex items-center gap-2`,children:[c(oe,{className:`h-3.5 w-3.5`}),`Test logs`,c(`span`,{className:`font-mono text-[9px] opacity-60`,children:b.slice(0,14)})]}),c(f,{className:`h-3.5 w-3.5 transition-transform ${g?`rotate-180`:``}`})]}),g&&c(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:c(P,{addonId:a,requestId:b,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!z&&!R&&(v||I.length>0)&&c(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[c(K,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:v||`Required: ${I.join(`, `)}`})]})}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:u,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:d(`integrations.cancel`)}),!z&&ne&&r(`button`,{type:`button`,onClick:M,disabled:te===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[te===`testing`?c(S,{className:`h-3.5 w-3.5 animate-spin`}):c(x,{className:`h-3.5 w-3.5`}),`Test All`]})]}),r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:()=>F(!0),disabled:z||!L||k.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:d(`integrations.saveAndNew`)}),c(`button`,{onClick:()=>F(!1),disabled:z||!L||k.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:k.isPending?d(`integrations.saving`):d(`integrations.save`)})]})]})]})]})}var Le=1500;function Y({addonId:e,integrationId:t,jobId:n,onFinished:i}){let{t:a}=xe(),o=y(),s=(j({addonId:e,integrationId:t},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?Le:!1}).data??[]).find(e=>e.jobId===n);if(!s)return null;let l=s.state===`running`,u=s.processed,d=s.total>0?Math.round(u/s.total*100):0;!l&&s.finishedAt!==null&&i();let f=[`${u}/${s.total} ${a(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];s.adopted>0&&f.push(`${s.adopted} ${a(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),s.alreadyAdopted>0&&f.push(`${s.alreadyAdopted} ${a(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),s.failed>0&&f.push(`${s.failed} ${a(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let p=f.join(` · `);return r(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[r(`div`,{className:`flex items-center gap-2`,children:[l?c(S,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):s.failed>0?c(K,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):s.state===`cancelled`?c(R,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):c(B,{className:`h-3.5 w-3.5 text-primary shrink-0`}),c(`p`,{className:`text-[11px] text-foreground`,children:p}),l&&c(`button`,{onClick:()=>o.mutate({jobId:n}),className:`ml-auto rounded-lg border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:a(`integrations.adoptJobCancel`,{defaultValue:`Stop`})})]}),c(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:c(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${d}%`},role:`progressbar`,"aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100})}),s.results.filter(e=>e.outcome===`failed`).slice(0,5).map(e=>r(`p`,{className:`text-[11px] text-destructive`,children:[e.childNativeId,`: `,e.error]},e.childNativeId))]})}function Re(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}n();var X=`devices`,ze={id:X,label:`Devices`,isDefault:!0},Be=2e4,Z=100;function Ve({addonId:n,integrationId:i,onClose:a}){let{t:u}=xe(),d=o(),[f,p]=s(new Set),[m,h]=s(new Set),[g,v]=s(new Map),[y,b]=s(null),{data:x}=_(),w=(x??[]).find(e=>e.addonId===n)?.supportsLocationImport??!1,[T,ee]=s(!0),O=te({addonId:n,integrationId:i}).data?.filters,k=O&&O.length>0?O:[ze],[A,j]=s(k.find(e=>e.isDefault)?.id??(k.some(e=>e.id===X)?X:k[0].id)),re=A!==X,M=ne(),N=C({addonId:n,integrationId:i,page:1,pageSize:Be,filter:A}),P=N.refetch,F=M.mutate,I=e(()=>{F({addonId:n,integrationId:i},{onSettled:()=>{P()}})},[F,n,i,P]),L=t(null);l(()=>{let e=`${n}::${i}`;L.current===e||N.isLoading||(L.current=e,(N.data?.candidates.length??0)===0&&I())},[n,i,N.isLoading,N.data,I]);let R=M.isPending,z=M.isError?M.error instanceof Error?M.error.message:String(M.error):null,ie=typeof M.data?.lastError==`string`&&M.data.lastError.length>0?M.data.lastError:null,B=N.data?.candidates??[],ae=N.isError?N.error instanceof Error?N.error.message:String(N.error):null,V=D(),[H,oe]=s(null),se=e(e=>{e.alreadyAdopted||p(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),U=e(e=>{h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),W=e((e,t)=>{v(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),le=e(e=>{let t={};for(let n of e){let e=g.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[g]),G=e(async()=>{b(null);let e=[...f];if(e.length!==0)try{let t=le(e),{jobId:r}=await V.mutateAsync({addonId:n,integrationId:i,filter:A,childNativeIds:e,...t?{perCandidate:t}:{},...w?{importLocations:T}:{}});oe(r),p(new Set),v(new Map)}catch(e){b(e instanceof Error?e.message:String(e))}},[f,le,V,n,i,A,w,T]),de=t(null),fe=e(()=>{H===null||de.current===H||(de.current=H,P(),d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]}))},[H,P,d]),pe=e(e=>{j(e),p(new Set),h(new Set),v(new Map),b(null)},[]),me=f.size,_e=H!==null&&me===0&&!V.isPending;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:a}),r(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] rounded-xl border border-border bg-background shadow-2xl`,children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[r(`div`,{className:`min-w-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:u(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),c(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:u(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),r(`div`,{className:`flex items-center gap-3 shrink-0`,children:[w&&r(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[c(`input`,{type:`checkbox`,checked:T,onChange:e=>ee(e.target.checked),className:`accent-primary`}),u(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),c(`button`,{onClick:a,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:c(ge,{className:`h-4 w-4`})})]})]}),r(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(z??ae??ie)&&B.length===0&&c(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[c(K,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`min-w-0`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:u(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),c(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:z??ae??ie})]})]})}),k.length>1&&c(He,{filters:k,activeFilter:A,onSelect:pe}),c(`div`,{className:`flex-1 min-h-0`,children:c(E,{mode:`generic`,items:B,pageSize:Z,getKey:e=>e.childNativeId,getSearchText:Re,getFilterType:e=>e.type,filterOptions:he(),filterLabel:u(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:N.isLoading||R&&B.length===0,searchPlaceholder:u(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(z??ae??ie)&&B.length===0?``:u(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:r(`button`,{type:`button`,onClick:I,disabled:R,title:u(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[c(ce,{className:`h-3.5 w-3.5 ${R?`animate-spin`:``}`}),u(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:u(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>c(Ue,{candidate:e,expandable:!re,expanded:m.has(e.childNativeId),onToggleExpand:()=>U(e.childNativeId),adoptedLabel:u(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:u(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=ue(e.type),n=t.icon;return r(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[c(n,{className:`h-3.5 w-3.5 shrink-0`}),t.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>c(`div`,{className:`flex items-center justify-end`,children:c(`button`,{onClick:()=>se(e),disabled:e.alreadyAdopted,"aria-label":f.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${f.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:f.has(e.childNativeId)&&c(ve,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!re&&m.has(e.childNativeId),renderExpanded:re?void 0:e=>c(Q,{candidate:e,hiddenChildIds:g.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>W(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:f.has(e.childNativeId)?`bg-primary/5`:``})})]}),y&&c(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[c(K,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:y})]})}),H!==null&&c(Y,{addonId:n,integrationId:i,jobId:H,onFinished:fe}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[c(`div`,{}),r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:a,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:u(`integrations.cancel`,{defaultValue:`Cancel`})}),r(`button`,{onClick:_e?a:G,disabled:!_e&&(me===0||V.isPending),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,children:[V.isPending&&c(S,{className:`h-3.5 w-3.5 animate-spin`}),_e?u(`integrations.close`,{defaultValue:`Close`}):u(`integrations.addSelected`,{defaultValue:`Add selected`}),!_e&&me>0?` (${me})`:``]})]})]})]})]})}function He({filters:e,activeFilter:t,onSelect:n}){return c(`div`,{role:`tablist`,"aria-label":`Discovery granularity`,className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return c(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function Ue({candidate:e,expandable:t,expanded:n,onToggleExpand:i,adoptedLabel:a}){let o=(e.children??[]).length;return r(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&o>0?r(`button`,{type:`button`,onClick:i,"aria-label":n?`Collapse`:`Expand`,"aria-expanded":n,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[c(n?f:p,{className:`h-3.5 w-3.5`}),o]}):c(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),c(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&c(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:a})]})}function Q({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let i=e.children??[];return i.length===0?null:c(`div`,{className:`space-y-1 py-1`,children:i.map(e=>{let i=t.has(e.childNativeId),a=e.capabilities??[];return r(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${i?`opacity-50`:``}`,children:[c(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),a.length>0&&c(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:a.join(`, `)}),c(`button`,{onClick:()=>n(e.childNativeId),"aria-label":i?`Show child`:`Hide child`,title:i?`Show after adopt`:`Hide after adopt`,className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:c(i?m:I,{className:`h-3 w-3`})})]},e.childNativeId)})})}n();function $(e){let t=[];for(let n of e){if(n.type===`group`){t.push(...$(n.fields));continue}`key`in n&&typeof n.key==`string`&&t.push(n.key)}return t}function We(e,t){if(!e)return{};let n=new Set(e.sections.flatMap(e=>$(e.fields))),r={};for(let e of n)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}function Ge(e){return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{if(`value`in e){let{value:t,...n}=e;return n}return e})}))}}function Ke({integrationId:e,addonId:t,name:n,kind:a,mode:s,brokerKind:l,canTest:u=!1,trpc:d,onClose:f}){let{t:p}=xe(),m=o(),{data:h,isLoading:g}=L({id:e},{enabled:s===`account`||s===`broker`}),_=i(()=>{let e=h?.brokerId;return typeof e==`string`?e:null},[h]),{data:v,isLoading:y}=F({addonId:t,nodeId:`hub`},{enabled:s===`account`}),b=i(()=>v?Ge(v):null,[v]),x=W(),C=(t,n)=>{x.mutate({id:e,settings:t,...n?{secretKeys:[...n]}:{}},{onSuccess:()=>{m.invalidateQueries(),f()}})};return c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onClick:f,children:r(`div`,{className:`max-h-[85vh] w-full max-w-lg overflow-y-auto rounded-xl border border-border bg-surface p-5 shadow-xl`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`mb-3 flex items-center justify-between`,children:[r(`h2`,{className:`text-sm font-semibold text-foreground`,children:[p(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]}),c(`button`,{onClick:f,className:`rounded-md p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":p(`common.close`,{defaultValue:`Close`}),children:c(ge,{className:`h-4 w-4`})})]}),s===`broker`?l?r(`div`,{className:`space-y-3`,children:[c(`p`,{className:`text-[11px] text-foreground-subtle`,children:p(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),_&&r(`p`,{className:`text-[11px] text-foreground`,children:[p(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,c(`span`,{className:`font-mono text-foreground-subtle`,children:_})]}),x.isPending?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(S,{className:`h-3 w-3 animate-spin`}),p(`integrations.saving`,{defaultValue:`Saving…`})]}):c(q,{kind:l,onResolved:e=>{C({brokerId:e})},onBack:f}),x.isError&&c(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):c(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):s===`account`?g||y?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(S,{className:`h-3 w-3 animate-spin`}),p(`integrations.loading`,{defaultValue:`Loading…`})]}):c(Oe,{addonId:t,configSchema:b,canTest:u,initialName:n,initialConfig:We(b,h??{}),submitLabel:p(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e,secretKeys:t})=>C(e,t),onBack:f}):c(G,{trpc:d,addonId:t,nodeId:`hub`,title:n})]})})}function qe(e){return e==null?!1:e.sections.some(e=>e.fields.length>0)}n();function Je(){let{t}=xe(),{integrationId:n}=Te(),f=o(),p=Ce(),[m,g]=Se(),y=d(),[x,C]=s(!1),[D,ee]=s(!1),[j,te]=s(!1),[ne,I]=s(!1),[L,R]=s(!1),{data:B,isLoading:se}=O({id:n??``},{enabled:!!n}),{data:ce}=F({addonId:B?.addonId??``,nodeId:`hub`},{enabled:!!B?.addonId}),{data:U,isSuccess:W}=_(),G=i(()=>{let e=B?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[U,B?.addonId,W]),{data:ue}=k({}),fe=i(()=>(ue?.providers??[]).some(e=>e.addonId===B?.addonId),[ue,B?.addonId]),he=G!==null,ve=B?.info?.fixed===!0,be=he?G===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),we=i(()=>{let e=B?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.brokerKind??null},[U,B?.addonId,W]),Oe=i(()=>{let e=B?.addonId;return!e||!W?!1:(U??[]).find(t=>t.addonId===e)?.canTest===!0},[U,B?.addonId,W]),q=i(()=>{let e=B?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.mode??null},[U,B?.addonId,W]);l(()=>{m.get(`add`)===`1`&&he&&(C(!0),g(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[m,he,g]);let je=ce!=null&&Array.isArray(ce.sections)&&ce.sections.some(e=>e.fields.length>0),{data:Me}=z({addonId:B?.addonId??``,nodeId:`hub`},{enabled:!!B?.addonId&&q!==`account`}),Ne=q!==null&&q!==`account`&&qe(Me),Pe=i(()=>B?.addonId?[B.addonId]:[],[B?.addonId]),{data:Fe}=pe({projection:`slim`},{refetchInterval:3e4}),J=[[`integrations`,`get`],{input:{id:n??``},type:`query`}],Le=V({onMutate:async e=>{await f.cancelQueries({queryKey:J});let t=f.getQueryData(J);return t!=null&&f.setQueryData(J,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&f.setQueryData(J,r.previous)},onSettled:()=>{f.invalidateQueries({queryKey:[[`integrations`]]}),f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Y=M({onSuccess:()=>{f.invalidateQueries({queryKey:[[`integrations`]]}),f.invalidateQueries({queryKey:[[`deviceManager`]]}),I(!1),p(`/integrations`)}}),Re=H({onSuccess:()=>{f.invalidateQueries({queryKey:[[`integrations`]]}),f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),X=ie({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ze=T({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Be=v({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Z=i(()=>Fe??[],[Fe]),He=i(()=>{let e=new Map;for(let t of Z)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[Z]),Ue=e(e=>He.get(e)??null,[He]),{data:Q}=me(void 0),$=i(()=>de(Q),[Q]),We=e(e=>p(`/devices/${String(e)}`),[p]),Ge=i(()=>{let e=B?.id;return e?Z.filter(t=>{let n=$(t);return n.kind===`resolved`&&n.integration.id===e}):[]},[Z,B?.id,$]),Je=i(()=>Q===void 0?null:re(Ge).length,[Q,Ge])??`…`;return se?r(`div`,{className:`p-4`,children:[c(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),c(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):B?r(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[c(w,{items:[{label:`Integrations`,onClick:()=>p(`/integrations`)},{label:B.name}]}),r(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[r(`div`,{className:`flex items-center gap-3 min-w-0`,children:[c(`img`,{src:u(`/api/addon-assets/${B.addonId}/assets/icon.svg`),alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:e=>{e.target.style.display=`none`}}),r(`div`,{className:`min-w-0`,children:[c(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:B.name}),r(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[B.addonId,` · `,Je,` `,t(`integrations.devices`)]})]})]}),r(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[fe&&r(`button`,{onClick:()=>ee(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the network for devices (incl. a different subnet)`,children:[c(N,{className:`h-3.5 w-3.5`}),`Scan network`]}),!ve&&r(`button`,{onClick:()=>C(!0),disabled:!he,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:be,children:[c(_e,{className:`h-3.5 w-3.5`}),be]}),r(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Le.isPending?`opacity-60`:``} ${B.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[c(A,{checked:B.enabled,onCheckedChange:e=>Le.mutate({id:n,enabled:e}),disabled:Le.isPending,"aria-label":B.enabled?`Disable integration`:`Enable integration`}),c(`span`,{className:`text-[11px] font-medium ${B.enabled?`text-success`:`text-foreground-subtle`}`,children:B.enabled?`Enabled`:`Disabled`}),Le.isPending&&c(S,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),q!==`standalone`&&(je||G===`device-adoption`)&&r(`button`,{onClick:()=>te(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[c(le,{className:`h-3 w-3`}),t(`integrations.config`)]}),r(`button`,{onClick:()=>R(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:t(`integrations.logs`,{defaultValue:`View logs`}),children:[c(oe,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),c(b,{label:`Restart`,icon:ae,title:`Restart "${B.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Je} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Re.isPending,action:()=>Re.mutateAsync({addonId:B.addonId})}),!ve&&r(`button`,{onClick:()=>I(!0),className:`flex items-center gap-1.5 rounded-lg border border-danger bg-danger/10 px-3 py-1.5 text-[11px] font-medium text-danger hover:bg-danger hover:text-background transition-colors`,title:t(`integrations.delete`,{defaultValue:`Delete integration`}),children:[c(h,{className:`h-3 w-3`}),t(`integrations.delete`,{defaultValue:`Delete`})]})]})]}),Ne&&c(Ee,{nodeId:null,addonIds:Pe,level:`global`,surface:`integration`,title:t(`integrations.settings`,{defaultValue:`Settings`})}),c(E,{context:`integration-detail`,devices:Z,trpc:y.trpcClient,integrationOf:$,forceIntegrationId:B.id,urlScope:`root`,lsKey:`integration-detail:${B.addonId}`,resolveIntegrationIcon:De,resolveParent:Ue,onNavigate:We,batchActions:{remove:X.mutate,disable:ze.mutate,enable:Be.mutate},...ve?{}:{onDeleteDevice:e=>X.mutate({deviceId:e.id})}}),x&&n&&G===`device-adoption`&&c(Ve,{addonId:B.addonId,integrationId:n,onClose:()=>C(!1)}),x&&n&&G===`device-provider`&&c(Ie,{open:x,integrationId:n,addonId:B.addonId,onClose:()=>C(!1)}),D&&B&&c(ke,{open:D,scope:{addonId:B.addonId,label:B.name},onClose:()=>ee(!1)}),j&&n&&G!==null&&q!==null&&c(Ke,{integrationId:n,addonId:B.addonId,name:B.name,kind:G,mode:q,brokerKind:we,canTest:Oe,trpc:y.trpcClient,onClose:()=>te(!1)}),L&&c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>R(!1),children:r(`div`,{className:`flex flex-col rounded-xl border border-border bg-surface shadow-xl w-full max-w-5xl h-[80vh]`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5`,children:[r(`div`,{className:`flex items-center gap-2 min-w-0`,children:[c(oe,{className:`h-4 w-4 text-primary shrink-0`}),c(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:B.name}),r(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[B.addonId,n?` · ${n}`:``]})]}),c(`button`,{onClick:()=>R(!1),className:`flex h-7 w-7 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close logs`,children:c(ge,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:c(P,{addonId:B.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})}),ne&&c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:()=>!Y.isPending&&I(!1),children:r(`div`,{className:`rounded-xl border border-border bg-background p-5 shadow-2xl w-96 space-y-3`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`flex items-start gap-3`,children:[c(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg bg-danger/10 shrink-0`,children:c(K,{className:`h-4 w-4 text-danger`})}),r(`div`,{className:`min-w-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.deleteTitle`,{defaultValue:`Delete integration?`})}),c(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:t(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:B.name,count:Je})})]})]}),Y.error&&c(`div`,{className:`rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:Y.error instanceof Error?Y.error.message:String(Y.error)}),r(`div`,{className:`flex items-center justify-end gap-2 pt-1`,children:[c(`button`,{onClick:()=>I(!1),disabled:Y.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:t(`integrations.cancel`,{defaultValue:`Cancel`})}),c(`button`,{onClick:()=>Y.mutate({id:n}),disabled:Y.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-danger px-3 py-1.5 text-[11px] font-medium text-background hover:bg-danger/90 transition-colors disabled:opacity-60 disabled:cursor-not-allowed`,children:Y.isPending?r(a,{children:[c(S,{className:`h-3 w-3 animate-spin`}),t(`integrations.deleting`,{defaultValue:`Deleting…`})]}):r(a,{children:[c(h,{className:`h-3 w-3`}),t(`integrations.confirmDelete`,{defaultValue:`Delete integration`})]})})]})]})})]}):r(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[c(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:c(Ae,{className:`h-6 w-6 text-foreground-subtle`})}),r(`div`,{className:`space-y-1 max-w-sm`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),c(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:n??``})})]}),r(`button`,{onClick:()=>p(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[c(ye,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}export{Je as IntegrationDetailPage};
@@ -1 +0,0 @@
1
- import{D as e,K as t,L as n,Q as r,S as i,W as a,b as o,o as s,q as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{B as d,Z as f,ct as p}from"./player-overlays-D4lg_avJ.js";import{An as m,Dt as h,Fd as g,Fr as _,In as v,Ld as y,Mt as b,Nn as x,Pn as S,Sd as C,_t as w,gt as ee,hd as T,kf as E,kr as te,ld as ne,tr as re,xd as D,zu as O}from"./src-DOjmjjKA.js";import{t as k}from"./settings-2-DVqttbaa.js";import"./mount-x_xV7wRP.js";import{G as A,J as j,a as M,c as N,d as P,f as F,l as I,p as L,u as R}from"./index-BNq9yPTv.js";import{t as z}from"./AdminPage-BSFohA3i.js";import{t as B}from"./NodeAddonsSettingsPanel-C1eKgxhI.js";r();var V=[[[`addons`,`listCapabilityProviders`]],[[`addons`,`list`]]],H=`text-[10px]`;function U({isActive:e}){return l(re,{variant:e?`success`:`default`,className:H,children:e?`Enabled`:`Disabled`})}function W({capName:e,addonId:t,isActive:n}){let r=s(),a=_({onSuccess:()=>{for(let e of V)r.invalidateQueries({queryKey:e})}}),o=a.isPending;return i(v,{size:`sm`,variant:n?`secondary`:`primary`,disabled:o,onClick:()=>a.mutate({capName:e,addonId:t,enabled:!n}),children:[o?l(g,{className:`h-3 w-3 animate-spin`}):l(n?p:C,{className:`h-3 w-3`}),n?`Disable`:`Enable`]})}function G({addonId:e,displayName:t}){let n=s(),r=te({onSuccess:()=>{for(let e of V)n.invalidateQueries({queryKey:e})}});return l(h,{label:`Restart`,icon:T,size:`sm`,title:`Restart "${t}"?`,description:`Restarting the addon bounces its subprocess — the provider will briefly drop and reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`ghost`,confirmVariant:`danger`,disabled:r.isPending,action:()=>r.mutateAsync({addonId:e})})}var K=600,q=e(null);function J({id:e,title:r,icon:a,actions:s,framed:c=!1,children:u}){let f=n(q),p=t(null),m=`integration-section-${e}`;Y(p,f,e);let h=i(o,{children:[f===null?null:l(A,{to:f.sectionHref(e),"aria-label":`Link to ${r}`,title:`Link to ${r}`,className:`rounded p-0.5 text-foreground-subtle/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,children:l(y,{className:`h-3 w-3`,"aria-hidden":!0})}),s]});return c?l(`div`,{ref:p,className:`scroll-mt-4`,children:l(b,{headingId:m,title:r,icon:a,actions:h,children:u})}):i(`section`,{ref:p,"aria-labelledby":m,className:`scroll-mt-4 space-y-2`,children:[i(`header`,{className:`flex min-h-7 flex-wrap items-center gap-2 px-0.5`,children:[a!==void 0&&l(a,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),l(`h2`,{id:m,className:`${d} min-w-0 flex-1`,children:r}),h]}),u]})}function Y(e,t,n){let r=t?.requestedSection===n,i=t?.integrationId;u(()=>{if(!r)return;let t=()=>e.current?.scrollIntoView?.({block:`start`});t();let n=!1,i=()=>{n=!0},a=[`wheel`,`touchmove`,`keydown`];for(let e of a)window.addEventListener(e,i,{once:!0,passive:!0});let o=window.setTimeout(()=>{n||t()},K);return()=>{window.clearTimeout(o);for(let e of a)window.removeEventListener(e,i)}},[r,i,e])}r();var X=`max-h-72`;function ie({addonId:e,displayName:t,capName:n,isActive:r,badges:a,primaryAction:o,error:s=null,lead:c,panels:u=[]}){let d=u.filter(e=>e.placement!==`end`),f=u.filter(e=>e.placement===`end`);return i(`div`,{className:`flex flex-col gap-4`,children:[l(ae,{addonId:e,displayName:t,capName:n,isActive:r,badges:a,primaryAction:o}),s!==null&&l(x,{message:s}),c,l(Z,{panels:d}),l(J,{id:R,title:`Settings`,icon:k,children:l(B,{nodeId:`hub`,addonIds:[e],level:`global`,capability:n})}),l(se,{addonId:e}),l(Z,{panels:f})]})}function Z({panels:e}){return l(o,{children:e.map(e=>l(J,{id:e.id,title:e.title,icon:e.icon,children:e.content},e.id))})}function ae({addonId:e,displayName:t,capName:n,isActive:r,badges:a,primaryAction:o}){return i(`div`,{className:`flex flex-wrap items-center justify-between gap-2 rounded-lg border border-border bg-surface px-2 py-1.5 sm:px-3`,"data-testid":`integration-status-strip`,children:[i(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[l(U,{isActive:r}),a,l(`span`,{className:`break-all font-mono text-[11px] text-foreground-subtle`,children:e})]}),i(`div`,{className:`flex flex-wrap items-center justify-end gap-1`,children:[o,l(W,{capName:n,addonId:e,isActive:r}),l(G,{addonId:e,displayName:t})]})]})}var oe=[{kind:`logs`,label:`Logs`,icon:ne},{kind:`events`,label:`Events`,icon:E}];function se({addonId:e}){let[t,n]=c(`logs`);return l(J,{id:M,title:`Activity`,framed:!0,actions:l(`div`,{role:`group`,"aria-label":`Activity stream`,className:`flex items-center gap-1`,children:oe.map(({kind:e,label:r,icon:a})=>i(`button`,{type:`button`,"aria-pressed":t===e,onClick:()=>n(e),className:`inline-flex items-center gap-1 rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${t===e?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[l(a,{className:`h-3 w-3`,"aria-hidden":!0}),r]},e))}),children:t===`logs`?l(w,{addonId:e,maxHeight:X,showFilters:!1}):l(ee,{addonId:e,category:`addon.*`,maxHeight:X})})}r();function ce(e){let{ids:t,answered:n,legacyGroupParam:r=null,groupFirst:i}=e,[o]=j(),s=o.get(N),c=r===null?null:o.get(r),l=o.get(I),u=a(()=>F({ids:t,requested:s,answered:n,legacyGroup:c,...i===void 0?{}:{groupFirst:i}}),[t,s,n,c,i]),d=a(()=>(e,t)=>`?${L(o,e,r,t??null).toString()}`,[o,r]);return{...u,requestedSection:l,hrefFor:d}}r();var le={md:{tile:`h-10 w-10 rounded-lg`,img:`h-7 w-7 rounded-md p-1`,fallback:`h-5 w-5`},sm:{tile:`h-5 w-5 rounded`,img:`h-5 w-5 rounded p-0.5`,fallback:`h-3.5 w-3.5`}};function ue({addonId:e,fallback:t,tileClassName:n,iconPath:r=`assets/icon.svg`,size:i=`md`}){let[a,o]=c(!1),s=f(`/api/addon-assets/${e}/${r}`),u=le[i];return l(`div`,{className:`${u.tile} flex items-center justify-center shrink-0 ${n}`,children:a?l(t,{className:u.fallback,"aria-hidden":!0}):l(`img`,{src:s,alt:``,className:`${u.img} bg-white ring-1 ring-black/5`,onError:()=>o(!0)})})}var Q=`inline-flex min-w-0 max-w-full items-center gap-1.5 rounded-full border py-1 pl-1 pr-2.5 text-xs transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,de=`border-primary bg-primary/10 text-primary font-medium`,fe=`border-border bg-surface text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,pe={ok:`bg-success`,off:`bg-foreground-subtle/60`,error:`bg-danger`,unknown:`border border-foreground-subtle bg-transparent`};function me({label:e,groups:t,selectedId:n,hrefFor:r}){let a=t.length>1;return l(`nav`,{"aria-label":e,className:a?`flex flex-col gap-2 sm:grid sm:grid-cols-[max-content_minmax(0,1fr)] sm:items-start sm:gap-x-3`:`flex flex-col`,children:t.map(e=>i(`div`,{role:`group`,"aria-label":e.label,className:a?`flex min-w-0 flex-col gap-1 sm:col-span-2 sm:grid sm:grid-cols-subgrid sm:items-start`:`min-w-0`,children:[a&&l(`span`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle sm:pt-2`,children:e.label}),i(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[e.entries.map(e=>l(he,{entry:e,current:e.id===n,href:r(e.id)},e.id)),e.install&&i(A,{to:P(e.install.capability),className:`${Q} border-dashed border-border pl-2 text-foreground-subtle hover:border-primary/50 hover:text-foreground`,children:[l(D,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),l(`span`,{className:`truncate`,children:e.install.label})]})]})]},e.id))})}function he({entry:e,current:t,href:n}){let r=e.state===`ok`;return i(A,{to:n,"aria-current":t?`true`:void 0,className:`${Q} ${t?de:fe}`,"data-testid":`integration-pill-${e.id}`,children:[l(ue,{addonId:e.id,fallback:e.fallbackIcon,tileClassName:``,size:`sm`}),l(`span`,{className:`truncate`,children:e.name}),l(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${pe[e.state]}`,"aria-hidden":!0}),l(`span`,{className:r?`sr-only`:`shrink-0 text-[10px] font-normal text-foreground-subtle`,children:e.stateLabel})]})}r();function ge({icon:e,title:t,subtitle:n,groups:r,isLoading:s,emptyTitle:c,emptyDescription:u,legacyGroupParam:d,trailing:f}){let p=a(()=>r.flatMap(e=>e.entries),[r]),h=a(()=>p.map(e=>e.id),[p]),g=a(()=>{let e={};for(let t of r){let n=t.entries[0];n!==void 0&&(e[t.id]=n.id)}return e},[r]),_=ce({ids:h,answered:!s,legacyGroupParam:d??null,groupFirst:g}),v=p.find(e=>e.id===_.selectedId)??null,y=a(()=>v===null?null:{integrationId:v.id,requestedSection:_.requestedSection,sectionHref:e=>_.hrefFor(v.id,e)},[v,_]);return l(z,{icon:e,title:t,subtitle:n,nav:s?null:l(me,{label:`${t} integrations`,groups:r,selectedId:_.selectedId,hrefFor:e=>_.hrefFor(e)}),children:s?l(m,{children:l(`div`,{className:`p-6 text-sm text-foreground-subtle`,children:`Loading…`})}):i(o,{children:[_.staleId!==null&&l(_e,{staleId:_.staleId,shownName:v?.name??null}),v!==null&&y!==null?l(q.Provider,{value:y,children:l(`div`,{role:`region`,"aria-label":v.name,"data-testid":`integration-body`,children:v.render()},v.id)}):l($,{groups:r,title:c,description:u}),f]})})}function $({groups:e,title:t,description:n}){let r=e.find(e=>e.install!==void 0)?.install;return l(m,{children:l(S,{title:t,description:n,action:r?l(A,{to:P(r.capability),children:i(v,{variant:`primary`,size:`sm`,children:[l(D,{className:`mr-1 h-3.5 w-3.5`}),r.label]})}):void 0})})}function _e({staleId:e,shownName:t}){return i(`div`,{role:`status`,className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-3 py-2 text-[11px] text-foreground-subtle`,children:[l(O,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),i(`span`,{children:[`This link named `,l(`span`,{className:`font-mono text-foreground`,children:e}),`, which is not installed here.`,t!==null&&i(o,{children:[` `,`Showing `,l(`span`,{className:`font-medium text-foreground`,children:t}),` instead.`]})]})]})}export{ie as n,H as r,ge as t};
@@ -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-D4lg_avJ.js";import{$a as p,Fd as m,K as h,Xa as ee,Xi as g,Y as _,_d as v,bd as y,cr as b,dr as te,hd as x,od as S,q as C,r as w,sa as ne,to as re,wu as T,xd as ie,xf as E,zi as D}from"./src-DOjmjjKA.js";import{t as O}from"./useTranslation-Bc5yH9V9.js";import{J as k,K as A,U as j}from"./index-BNq9yPTv.js";import{t as M}from"./AdminPage-BSFohA3i.js";import"./useEventInvalidation-x_xV7wRP.js";import{t as N}from"./StatusBadge-CeptlsPG.js";import{t as ae}from"./device-integration-icon-Ce7zluJx.js";import{n as oe,r as P,t as F}from"./ScanNetworkModal-CJGyqlYW.js";t();function I(e=!0){c(()=>{if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=t}},[e])}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}=O(),[a,u]=o(new Set),d=g(),f=d.data,p=d.isPending||!d.data&&!d.isError;c(()=>{e&&(d.isPending||d.data||d.mutate({addonId:e}))},[e,d]);function m(e){u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(p)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 h=f??[];return n(`div`,{className:`space-y-4`,children:[s(`p`,{className:`text-xs text-foreground-subtle`,children:h.length>0?i(`integrations.foundDevices`,{count:h.length}):i(`integrations.noDevicesFound`)}),h.length>0&&s(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:h.map(e=>{let t=e.stableId,r=e.suggestedName??t,o=a.has(t),c=e.alreadyOnboarded===!0;return n(`button`,{onClick:()=>{c||m(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(E,{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`)}),h.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}=O(),a=A(),{data:o,isLoading:c}=p();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(m,{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(S,{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}=O(),u=A(),d=a(),[f,p]=o(`picker`),[h,_]=o(null),[v,y]=o(null),[b,x]=o(`manual`),[S,C]=o(null),[w,ne]=o(``),[re,ie]=o(null),[E,k]=o(null),[j,M]=o(!1),{data:N}=te({addonId:h??``,nodeId:`hub`},{enabled:h!=null}),ae=r(()=>N?se(N):null,[N]),F=ee({onSuccess:()=>d.invalidateQueries({queryKey:[[`integrations`]]})}),V=g(),H=V.data;c(()=>{f!==`discovery`||!v||!h||V.isPending||V.data||V.mutate({addonId:h})},[f,v,h,V]);let ce=D({onSuccess:()=>d.invalidateQueries({queryKey:[[`deviceManager`]]})});function le(e,t,n,r,i,a,o,s){if(!F.isPending){if(_(e),M(s),x(n),ne(r),k(null),o===`broker`){if(!a){k(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}C(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(h)try{let t=await F.mutateAsync({addonId:h,name:e.name,settings:e.config,secretKeys:[...e.secretKeys]});y(t.id),b===`auto`||b===`both`?p(`discovery`):q(t.id)}catch{}}async function G(e){if(h)try{let t=await F.mutateAsync({addonId:h,name:w,settings:{brokerId:e}});ie(t.id),y(t.id),q(t.id)}catch{}}async function K(e){if(h){for(let t of e){let e=H?.find(e=>e.stableId===t);e&&await ce.mutateAsync({addonId:h,candidate:e,...re===null?{}:{integrationId:re}})}q()}}function q(e){let n=e??v??h;t(),J(),n&&u(`/integrations/${n}`)}function J(){p(`picker`),_(null),y(null),x(`manual`),C(null),ne(``),ie(null),k(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?h: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(T,{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:[E&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:E}),s(z,{onSelect:le,onClose:Y,pendingAddonId:Q})]}),f===`config`&&h&&s(oe,{addonId:h,configSchema:ae??null,canTest:j,onSave:W,onBack:()=>p(`picker`)}),f===`broker`&&S&&s(P,{kind:S,onResolved:e=>{G(e)},onBack:()=>p(`picker`)}),f===`discovery`&&v&&s(R,{providerId:v,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(m,{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(j,{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}=O(),a=A(),c=u(),[l]=k(),[d,f]=o(!1),p=e(()=>f(!0),[]),m=e(()=>f(!1),[]),[ee,g]=o(!1),te=e(()=>g(!0),[]),S=e(()=>g(!1),[]);w([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),w([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:T,isLoading:E,refetch:D}=re(void 0),{data:j,isLoading:N,refetch:oe}=ne({projection:`slim`}),P=r(()=>j??[],[j]),I=r(()=>T??[],[T]),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(()=>C(T),[T]),z=r(()=>{let e=new Map;for(let t of _(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:y,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(x,{className:b(`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(v,{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(ie,{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:m}),s(F,{open:ee,onClose:S})]})}export{W as IntegrationsPage};
@@ -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{E as u,I as d,X as f,at as p,ct as m,lt as h,st as g,vt as _}from"./player-overlays-D4lg_avJ.js";import{$t as v,An as y,Ao as b,Co as x,Cr as S,Do as ee,Dt as C,Du as w,Eo as T,Fd as E,Fn as te,In as D,Ju as ne,Lo as re,Mo as ie,Mt as ae,Nd as oe,Nn as se,No as ce,Nt as le,Oo as ue,Po as de,Ro as fe,Sd as pe,So as me,Td as O,To as he,Vl as k,Wf as ge,_o as _e,bn as ve,cf as ye,dd as be,hd as xe,jo as Se,jt as Ce,ko as we,kt as Te,nd as Ee,sa as De,sd as A,td as Oe,tf as ke,tr as j,vo as Ae,wo as je,wr as M,wu as Me,xd as Ne,xf as Pe,xo as Fe,yo as Ie,zo as Le,zu as N}from"./src-DOjmjjKA.js";import{t as P}from"./boxes-DxeTkSiW.js";import{Gn as Re,Kn as ze,Un as Be,yn as Ve}from"./client-BqN2lVYf.js";import"./mount-x_xV7wRP.js";import{$ as F,Q as He,o as I,s as L}from"./index-BNq9yPTv.js";import{t as Ue}from"./AdminPage-BSFohA3i.js";import{t as We}from"./NodeAddonsSettingsPanel-C1eKgxhI.js";import{t as Ge}from"./AdminTabs-Bxj9C3Dy.js";import{n as R,r as z,t as B}from"./IntegrationHub-T7WCtw8g.js";import{n as V,t as H}from"./addon-display-names-BkwMrExv.js";var Ke=_(`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`}]]),qe=_(`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 U=5e3,W=`network-access`,Je={connected:!1,endpoint:null};function Ye(){let e=o(),t=M({capName:`network-access`},{refetchInterval:U}),n=S(void 0,{refetchInterval:U}),r=i(()=>H(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=fe({onSuccess:p,onError:m}),g=Le({onSuccess:p,onError:m});return c(B,{icon:F,title:`Remote Access`,subtitle:`Public-facing tunnels that expose this hub to the internet (Cloudflare Tunnel, ngrok, …).`,groups:[{id:W,label:`Remote access`,install:{capability:W,label:`Add tunnel`},entries:a.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:F,...V(e.isActive),render:()=>c(R,{addonId:e.addonId,displayName:e.displayName,capName:W,isActive:e.isActive,badges:c(Ze,{addonId:e.addonId}),error:d[e.addonId]??null,primaryAction:c(Qe,{addonId:e.addonId,busyId:l,onStart:e=>{u(e),h.mutate({addonId:e})},onStop:e=>{u(e),g.mutate({addonId:e})}})})}))}],isLoading:t.isLoading,emptyTitle:`No remote-access providers installed`,emptyDescription:`Install a tunnel addon (e.g. @camstack/addon-cloudflare) to expose this hub publicly.`})}function Xe(e){let{data:t}=re({addonId:e},{refetchInterval:U,retry:!1}),n=t?Be.safeParse(t):null;return n?.success?n.data:Je}function Ze({addonId:e}){let t=Xe(e);return r(a,{children:[c(j,{variant:t.connected?`success`:`default`,className:z,children:t.connected?`Connected`:`Disconnected`}),t.endpoint&&r(`a`,{href:t.endpoint.url,target:`_blank`,rel:`noopener noreferrer`,className:`flex min-w-0 items-center gap-1 break-all text-[11px] text-success hover:underline`,children:[c(ke,{className:`h-3 w-3`}),t.endpoint.url]})]})}function Qe({addonId:e,busyId:t,onStart:n,onStop:i}){let a=Xe(e),o=t===e;return a.connected?r(D,{size:`sm`,variant:`secondary`,disabled:o,onClick:()=>i(e),children:[o?c(E,{className:`h-3 w-3 animate-spin`}):c(m,{className:`h-3 w-3`}),`Stop`]}):r(D,{size:`sm`,variant:`primary`,disabled:o,onClick:()=>n(e),children:[o?c(E,{className:`h-3 w-3 animate-spin`}):c(pe,{className:`h-3 w-3`}),`Start`]})}n();var $e=3e4,G=`turn-provider`;function et(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function tt(){let e=M({capName:`turn-provider`},{refetchInterval:$e}),t=S(void 0,{refetchInterval:$e}),n=k(),a=n.data??[],o=i(()=>H(t.data??[]),[t.data]),s=i(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:o.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,o]);return c(B,{icon:O,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.`,groups:[{id:G,label:`TURN providers`,install:{capability:G,label:`Add provider`},entries:s.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:O,...V(e.isActive),render:()=>c(R,{addonId:e.addonId,displayName:e.displayName,capName:G,isActive:e.isActive,panels:[{id:`ice-servers`,title:`Discovered ICE servers`,icon:O,content:c(nt,{addonId:e.addonId,enabled:e.isActive})}]})}))}],isLoading:e.isLoading,emptyTitle:`No TURN providers installed`,emptyDescription:`Install a TURN addon (e.g. @camstack/addon-cloudflare) to enable WebRTC behind restrictive NATs.`,trailing:c(ae,{headingId:`turn-combined-ice`,title:`Combined ICE server list — all enabled providers`,icon:O,actions:c(D,{size:`sm`,variant:`secondary`,onClick:()=>n.refetch(),disabled:n.isFetching,children:`Refresh`}),children:c(`div`,{className:u,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 nt({addonId:e,enabled:t}){let n=k({addonId:e},{enabled:t,retry:!1}),r=i(()=>et(n.data??[]),[n.data]),a=t?n.isLoading?`Loading…`:r.length===0?`This provider returned no servers.`:null:`Disabled — enable the provider to fetch its servers.`;return c(`div`,{className:`rounded-lg border border-border bg-surface p-2 sm:p-3`,children:a===null?c(`div`,{className:`flex flex-wrap gap-1`,children:r.map(e=>c(`span`,{className:`inline-block break-all rounded bg-foreground-subtle/10 px-1.5 py-0.5 font-mono text-[10px] text-foreground`,children:e},e))}):c(`div`,{className:`text-xs text-foreground-subtle`,children:a})})}n();var rt={lan:O,wifi:w,docker:P,vpn:oe,loopback:A,other:A},it={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},at=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function ot(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 at.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(rt[t]??A,{className:`h-3.5 w-3.5 text-foreground-subtle`}),c(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:it[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(Pe,{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(N,{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 K=[{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.`}],st=`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 q(e,t){return e.inUse.includes(t)}function ct(e,t){if(!e.eligible.includes(t))return{kind:`none`};if(e.kind===`app-link`)return q(e,t)?{kind:`none`}:{kind:`set`,input:{role:t,baseUrl:null,enabled:!0}};if(e.flags.includes(t)||t===`appConnections`&&q(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:Re}:{kind:`set`,input:n}}function lt(e){return K.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 ut={"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 dt({book:e,loading:t,saving:n,error:i,onSetRole:a,onAdd:o,onRemove:l}){let[u,d]=s(``),[f,p]=s(``),[m,h]=s(null),[_,b]=s(null),x=()=>{let e=ze(u);if(!e.ok){h(e.reason);return}h(null),d(``),p(``),o(e.baseUrl,f.trim())},S=(e,t)=>{let n=ct(e,t.role);if(n.kind!==`none`){if(n.kind===`confirm-http`){b({input:n.input,reason:n.reason});return}b(null),a(n.input)}},ee=[{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(N,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]})]})},{key:`kind`,header:`Kind`,nowrap:!0,render:e=>{let t=ut[e.kind]??ut.loopback;return c(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.className}`,children:t.label})}},...K.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=q(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(v,{checked:i&&o,disabled:!i||n,onChange:()=>S(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(D,{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(g,{className:`h-3 w-3`})}):null}],C=e===void 0?[]:lt(e);return r(y,{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:K.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:st})]})]}),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(D,{size:`sm`,variant:`secondary`,disabled:n,onClick:()=>a({role:e.role,baseUrl:null,enabled:!1}),children:`Use automatic`})]},e.role))}),_!==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(N,{className:`h-3.5 w-3.5 text-amber-600`}),c(`span`,{className:`flex-1 min-w-[220px]`,children:_.reason}),c(D,{size:`sm`,variant:`secondary`,onClick:()=>{a({..._.input,acceptInsecureHttp:!0}),b(null)},children:`Use http anyway`}),c(D,{size:`sm`,variant:`ghost`,onClick:()=>b(null),children:`Cancel`})]}),i!==null&&c(`div`,{className:`text-[11px] text-red-600 dark:text-red-400`,role:`alert`,children:i})]}),c(le,{columns:ee,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(ve,{value:u,onChange:e=>{d(e.target.value),h(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(ve,{value:f,onChange:e=>p(e.target.value),placeholder:`Label (optional)`,"aria-label":`Custom address label`,maxLength:80,disabled:n})}),r(D,{size:`sm`,variant:`secondary`,disabled:n||u.trim()===``,onClick:x,children:[c(Ne,{className:`h-3 w-3`}),`Add custom address`]})]})]})}n();function ft(){let e=o(),t=()=>{e.invalidateQueries({queryKey:[[`localNetwork`]]})},n=me(void 0,{refetchInterval:3e4}),a=Ie(void 0),u=ue({onSuccess:t}),d=he({onSuccess:e=>{S(e.addresses),t()}}),f=i(()=>n.data?.interfaces??[],[n.data]),p=Ae({scheme:typeof window<`u`&&window.location.protocol===`https:`?`https`:`http`},{refetchInterval:3e4}),m=ee({onSuccess:t}),g=_e({onSuccess:t}),_=je({onSuccess:t}),v=m.error?.message??g.error?.message??_.error?.message??null,b=m.isPending||g.isPending||_.isPending,[x,S]=s([]),[C,w]=s(!1);l(()=>{!C&&a.data&&(S(a.data.addresses),w(!0))},[a.data,C]);let T=a.data?.addresses??[],E=i(()=>{if(x.length!==T.length)return!0;let e=[...x].toSorted(),t=[...T].toSorted();return e.some((e,n)=>e!==t[n])},[x,T]);return r(Ue,{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(D,{size:`sm`,variant:`secondary`,onClick:()=>{n.refetch(),a.refetch(),p.refetch()},disabled:n.isLoading,children:[c(xe,{className:`h-3 w-3 ${n.isLoading?`animate-spin`:``}`}),`Refresh`]})})]}),r(y,{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:x.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${x.length} pinned`})]}),r(`div`,{className:`flex items-center gap-1`,children:[r(D,{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(ne,{className:`h-3 w-3`}),d.isPending?`Detecting…`:`Best match`]}),r(D,{size:`sm`,variant:`secondary`,onClick:()=>{S([])},disabled:x.length===0||u.isPending,children:[c(h,{className:`h-3 w-3`}),`Clear`]}),E&&c(D,{size:`sm`,variant:`secondary`,onClick:()=>{S(T)},disabled:u.isPending,children:`Discard`}),r(D,{size:`sm`,variant:`primary`,onClick:()=>{u.mutate({addresses:[...x]})},disabled:!E||u.isPending,children:[c(be,{className:`h-3 w-3`}),u.isPending?`Saving…`:`Save`]})]})]}),c(`div`,{className:`p-4`,children:c(ot,{mode:`multiple`,interfaces:f,value:x,onChange:S,disabled:u.isPending,emptyMessage:n.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),c(dt,{book:p.data,loading:p.isLoading,saving:b,error:v,onSetRole:e=>m.mutate({...e}),onAdd:(e,t)=>g.mutate({baseUrl:e,label:t}),onRemove:e=>_.mutate({baseUrl:e})})]})}n();var pt={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},J=5e3,Y=`mesh-network`,mt=3e4,ht={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function gt(){let e=M({capName:`mesh-network`},{refetchInterval:J}),t=S(void 0,{refetchInterval:J}),n=i(()=>H(t.data??[]),[t.data]),r=i(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,n]);return c(B,{icon:P,title:`Mesh Networks`,subtitle:`Private VPN meshes that connect CamStack to your other devices (Tailscale, Headscale, …). Each provider can also expose this hub publicly via its ingress (Tailscale Funnel).`,groups:[{id:Y,label:`Mesh networks`,install:{capability:Y,label:`Add mesh`},entries:r.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:O,...V(e.isActive),render:()=>c(R,{addonId:e.addonId,displayName:e.displayName,capName:Y,isActive:e.isActive,badges:c(_t,{addonId:e.addonId}),primaryAction:c(vt,{addonId:e.addonId}),panels:[{id:`status`,title:`Status`,icon:P,content:c(yt,{addonId:e.addonId})}]})}))}],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.`})}function X(e){let{data:t,isLoading:n}=b({addonId:e},{refetchInterval:J,retry:!1}),r=t?Ve.safeParse(t):null;return{status:r?.success?r.data:ht,isLoading:n}}function _t({addonId:e}){let{status:t}=X(e);return r(a,{children:[c(j,{variant:t.joined?`success`:`default`,className:z,children:t.joined?`Joined`:`Not joined`}),t.joined&&r(j,{className:`text-[10px]`,children:[t.peerCount,` peer`,t.peerCount===1?``:`s`]})]})}function vt({addonId:t}){let n=o(),[i,l]=s(!1),[u,d]=s(null),f=p(),{status:m}=X(t),h=e(()=>{n.invalidateQueries({queryKey:[[`meshNetwork`]]})},[n]),g=de(),_=Se({onSuccess:h}),v=ce({onSuccess:h}),y=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 Et(2e3),!e.cancelled);){let e=await f.trpcClient.meshNetwork.getStatus.query({addonId:t}).catch(()=>null),n=e?Ve.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,f]),b=e(()=>{u&&(u.cancelled=!0),l(!1),d(null)},[u]);return c(a,{children:m.joined?r(a,{children:[r(D,{size:`sm`,variant:`secondary`,disabled:_.isPending,onClick:()=>_.mutate({addonId:t}),children:[_.isPending?c(E,{className:`h-3 w-3 animate-spin`}):c(He,{className:`h-3 w-3`}),`Disconnect`]}),r(D,{size:`sm`,variant:`ghost`,disabled:v.isPending,onClick:()=>v.mutate({addonId:t}),children:[v.isPending?c(E,{className:`h-3 w-3 animate-spin`}):c(Ee,{className:`h-3 w-3`}),`Log out`]})]}):i?r(D,{size:`sm`,variant:`ghost`,onClick:b,children:[c(Me,{className:`h-3 w-3 mr-1`}),` Cancel`]}):r(a,{children:[r(D,{size:`sm`,variant:`primary`,onClick:()=>void y(),children:[c(qe,{className:`h-3 w-3`}),`Connect`]}),r(D,{size:`sm`,variant:`ghost`,disabled:v.isPending,onClick:()=>v.mutate({addonId:t}),children:[v.isPending?c(E,{className:`h-3 w-3 animate-spin`}):c(Ee,{className:`h-3 w-3`}),`Log out`]})]})})}function yt({addonId:e}){let{status:t}=X(e),n=ie({addonId:e},{refetchInterval:mt,retry:!1});return r(`div`,{className:`rounded-lg border border-border bg-surface`,children:[r(`div`,{className:`space-y-4 p-2 sm:p-4`,children:[t.error&&c(se,{message:t.error}),c(bt,{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 ${pt[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?c(F,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),r(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-emerald-700 dark:text-emerald-300 hover:underline break-all flex items-center gap-1`,children:[c(ke,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),c(`div`,{className:`border-t border-border`,children:c(St,{peers:n.data?.peers??[],loading:n.isLoading})})]})}function bt({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?xt(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 xt(e){let t=e-Date.now();if(t<0)return`Expired ${Tt(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 St({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(j,{variant:`info`,children:`self`}),e.exitNodeOption&&c(j,{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(ye,{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(ye,{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(j,{variant:Ct(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:[`↑ `,wt(e.txBytes),` · ↓ `,wt(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>c(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?Tt(e.lastSeenMs):`—`})}],[o]);return n&&t.length===0?r(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[c(E,{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(le,{columns:s,rows:a,rowKey:e=>e._id,minWidthPx:820})})}function Ct(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function wt(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 Tt(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 Et(e){return new Promise(t=>setTimeout(t,e))}var Dt=/-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----/,Z=/-----BEGIN ((?:RSA |EC |ENCRYPTED )?PRIVATE KEY)-----[\s\S]+?-----END \1-----/,Ot={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?Dt.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 Dt.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 kt(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 kt(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:Ot[e],onChange:e=>void g(e),className:`hidden`,"data-testid":`${h}-file`}),r(D,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>l.current?.click(),children:[c(Ke,{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 At(e){if(e===null||e===``)return`—`;let t=e.replace(/:/g,``);return t.length<=16?e:`${t.slice(0,8)}…${t.slice(-8)}`}function jt(){let e=o(),t=Fe(void 0,{refetchInterval:15e3}),n=x({onSuccess:()=>void e.invalidateQueries({queryKey:[[`localNetwork`]]})}),i=T({onSuccess:()=>void e.invalidateQueries({queryKey:[[`localNetwork`]]})}),a=we({onSuccess:()=>{d(!1),p(``),h(``),_(``),e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),l=t.data,[u,d]=s(!1),[f,p]=s(``),[m,h]=s(``),[g,_]=s(``),v=()=>{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)},b=l?.mode===`uploaded`?`Uploaded`:l?.mode===`generated`?`Generated local CA`:`TLS disabled`;return r(`div`,{className:`flex flex-col gap-4`,children:[c(We,{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(y,{className:`p-4 space-y-3`,children:[r(`div`,{className:`flex items-center gap-2`,children:[c(Oe,{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:b})]}),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:At(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)`}):At(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(C,{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(D,{size:`sm`,variant:`outline`,onClick:()=>d(e=>!e),children:`Upload`}),l?.caCertPem&&c(D,{size:`sm`,variant:`outline`,onClick:v,children:`Download CA`}),l?.mode===`uploaded`&&c(C,{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:_,rows:4}),c(D,{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 Mt({value:e,onChange:t}){let{data:n}=De({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(te,{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 Nt(){let t=p(),[n,i]=s(null);return r(`div`,{className:d,"data-testid":`network-diagnostics`,children:[c(Ce,{loadServers:e(async()=>t.trpcClient.turnProvider.getTurnServers.query(),[t])}),c(Te,{trpc:t.trpcClient,serverUrl:f(),deviceId:n,cameraField:c(Mt,{value:n,onChange:i})})]})}function Pt(){return c(`div`,{className:`flex flex-col p-4`,children:c(Ge,{defaultTab:`addresses`,tabs:[{id:`local-access`,label:`Local access`,icon:w,content:c(jt,{})},{id:`addresses`,label:`Network Addresses`,icon:A,content:c(ft,{})},{id:L.remoteAccess.tab,label:`Remote Access`,icon:F,content:c(Ye,{}),ownedParams:I},{id:L.mesh.tab,label:`Mesh Networks`,icon:P,content:c(gt,{}),ownedParams:I},{id:L.turn.tab,label:`TURN Servers`,icon:O,content:c(tt,{}),ownedParams:I},{id:`diagnostics`,label:`Diagnostics`,icon:ge,content:c(Nt,{})}]})})}export{Pt as NetworkPage};
@@ -1 +0,0 @@
1
- import"./src-DOjmjjKA.js";