@camstack/addon-admin-ui 1.2.462 → 1.2.463

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 (121) hide show
  1. package/dist/assets/{AddonAssetIcon-DMG19u-q.js → AddonAssetIcon-C9AdDz0x.js} +1 -1
  2. package/dist/assets/Addons-BPh7Eayh.js +4 -0
  3. package/dist/assets/{AdminPage-oFm0hhFj.js → AdminPage-Bly6H-Ei.js} +1 -1
  4. package/dist/assets/{AdminSectionedPage-CXL0Cc0w.js → AdminSectionedPage-DVGnfLgr.js} +1 -1
  5. package/dist/assets/{AiProfiles-BVyp59R4.js → AiProfiles-XE0_l3jU.js} +1 -1
  6. package/dist/assets/{BrokerForm-D-QT3T4C.js → BrokerForm-XjXbfqrZ.js} +1 -1
  7. package/dist/assets/Build-D4NDTkw2.js +40 -0
  8. package/dist/assets/{Calendars-hof9Zsuo.js → Calendars-CDSTKKMT.js} +1 -1
  9. package/dist/assets/{Cluster-aDWkD3jS.js → Cluster-DKTNITYY.js} +1 -1
  10. package/dist/assets/CompositionEditor-BiWIw_xC.js +1 -0
  11. package/dist/assets/CompositionEditorPage-CRAPYt_u.js +1 -0
  12. package/dist/assets/{Data-XFdQ_CJg.js → Data-C-9OmLam.js} +2 -2
  13. package/dist/assets/DeviceDetail-CZ23_AX8.js +2 -0
  14. package/dist/assets/{DeviceDoActionFields-BfsAy1hi.js → DeviceDoActionFields-C7VbUl2q.js} +1 -1
  15. package/dist/assets/{Devices-CndVoeQ8.js → Devices-CjR3mkUm.js} +1 -1
  16. package/dist/assets/{EmbedPlayerPage-DB6Hb_mj.js → EmbedPlayerPage-DMVU4L2Z.js} +1 -1
  17. package/dist/assets/{History-DiYHtz3o.js → History-CCPlalru.js} +1 -1
  18. package/dist/assets/Identity-pegWB0x7.js +1 -0
  19. package/dist/assets/{IntegrationDetail-Bc1sRi3k.js → IntegrationDetail-DakB5HuG.js} +1 -1
  20. package/dist/assets/{IntegrationHub-DnBfbKWG.js → IntegrationHub-Cl-yRdYk.js} +1 -1
  21. package/dist/assets/Integrations-D4JXGApt.js +1 -0
  22. package/dist/assets/Integrations-DRLVrdBM.js +1 -0
  23. package/dist/assets/{Library-C-ZxsOFn.js → Library-Bzo29YWC.js} +1 -1
  24. package/dist/assets/{Locations-BlixafK7.js → Locations-DyZCCP98.js} +1 -1
  25. package/dist/assets/{Logs-DhyhktWC.js → Logs-B-7ptLpL.js} +1 -1
  26. package/dist/assets/{MaskShapeCanvas-CBL-DJGe.js → MaskShapeCanvas-BmtOGyK5.js} +1 -1
  27. package/dist/assets/{MotionZonesSettings-8vvPxjTe.js → MotionZonesSettings-CV3Xgsr4.js} +1 -1
  28. package/dist/assets/MyAccess-B37DRC8C.js +2 -0
  29. package/dist/assets/{Network-BVufubzK.js → Network-Du7T4f3O.js} +1 -1
  30. package/dist/assets/{NodeAddonsSettingsPanel-B2ppCOQm.js → NodeAddonsSettingsPanel-BdXMzxN1.js} +1 -1
  31. package/dist/assets/Notifications-D31A_aMl.js +1 -0
  32. package/dist/assets/{Pipeline-BEX8fX4r.js → Pipeline-Bz5cI-qM.js} +1 -1
  33. package/dist/assets/{PrivacyMaskSettings-Cp2TZg4d.js → PrivacyMaskSettings-BPRo3O3B.js} +1 -1
  34. package/dist/assets/{Recordings-D11aOWfh.js → Recordings-PbSzlND2.js} +1 -1
  35. package/dist/assets/{ScanNetworkModal-DFuZaP78.js → ScanNetworkModal-D7f9c95h.js} +1 -1
  36. package/dist/assets/{SceneMonitorEditor-B47BGXqI.js → SceneMonitorEditor-BA9763ix.js} +1 -1
  37. package/dist/assets/{SessionsList-C3EfpYvC.js → SessionsList-POtDsHqi.js} +2 -2
  38. package/dist/assets/{Showroom-B_K5Voir.js → Showroom-DNy-w6tP.js} +1 -1
  39. package/dist/assets/{System-B3QOfsQ-.js → System-B0A3Vybn.js} +1 -1
  40. package/dist/assets/{Terminal-CepoEWPj.js → Terminal-DAkEfEl7.js} +1 -1
  41. package/dist/assets/{Viewer-9n98n7Mc.js → Viewer-C2mhbwBs.js} +1 -1
  42. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-pwVcJ8Li.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BcUHsXvG.js} +1 -1
  43. package/dist/assets/{addon-icons-context-CfxpJVkI.js → addon-icons-context-BwHvrxKK.js} +1 -1
  44. package/dist/assets/{archive-CkpL7nYU.js → archive-D-CLwZIU.js} +1 -1
  45. package/dist/assets/{authed-media-BtcsEMhs.js → authed-media-DdZ3AKzY.js} +1 -1
  46. package/dist/assets/{bell-off-D9tHNuLX.js → bell-off-DkKnBqQi.js} +1 -1
  47. package/dist/assets/{board-model-BLL_cD-z.js → board-model-CGqWH_FA.js} +1 -1
  48. package/dist/assets/{boxes-BA8-oYCX.js → boxes-BeinIpIz.js} +1 -1
  49. package/dist/assets/circle-slash-D94rdTZs.js +1 -0
  50. package/dist/assets/{client-CNqHea-r.js → client-CJZuPHbz.js} +1 -1
  51. package/dist/assets/{cloud-upload-5unDJZ5Y.js → cloud-upload-CqA8Voyh.js} +1 -1
  52. package/dist/assets/crop-CJTlG5-P.js +1 -0
  53. package/dist/assets/{device-integration-icon-B_6sNK4Z.js → device-integration-icon-CLpD5eef.js} +1 -1
  54. package/dist/assets/device-picker-model-BHInrZJO.js +1 -0
  55. package/dist/assets/{dist-CnGggN6i.js → dist-Dmgqu93O.js} +1 -1
  56. package/dist/assets/{eraser-BehwAkha.js → eraser-B_CtxhBO.js} +1 -1
  57. package/dist/assets/{format-3n872UoD.js → format-C7c-WeCC.js} +1 -1
  58. package/dist/assets/{hard-drive-download-5P7_6z5A.js → hard-drive-download-BSXwOh9q.js} +1 -1
  59. package/dist/assets/{hostInit-DxdU_pnx.js → hostInit-W8TL-CCW.js} +1 -1
  60. package/dist/assets/i18n-CvoV4ITH.js +1 -0
  61. package/dist/assets/{icons-Clqqnzdw.js → icons-eXZhq5Wj.js} +1 -1
  62. package/dist/assets/{index-CfXsU3sZ.js → index-DgzFfJ-E.js} +3 -3
  63. package/dist/assets/{index-DhkrLRVh.css → index-z_YJmgwP.css} +1 -1
  64. package/dist/assets/{key-Dq6CiRWE.js → key-DojLc55s.js} +1 -1
  65. package/dist/assets/{key-round-DX4Tm3r5.js → key-round-BAehItCF.js} +1 -1
  66. package/dist/assets/{layers-M4OA6__8.js → layers-DAJqwsng.js} +1 -1
  67. package/dist/assets/{linked-devices-model-BT6sN3Jo.js → linked-devices-model-B8q5duvG.js} +1 -1
  68. package/dist/assets/{list-ordered-USAX-4g-.js → list-ordered-BYVhOPoV.js} +1 -1
  69. package/dist/assets/{location-owned-usage-CmhxgtcU.js → location-owned-usage-BrB6XdyC.js} +1 -1
  70. package/dist/assets/{log-in-C-sFC6o8.js → log-in-C1oX8GRe.js} +1 -1
  71. package/dist/assets/{memory-stick-CNw60CfF.js → memory-stick-H0-1j4vS.js} +1 -1
  72. package/dist/assets/{message-square-plus-BHUImv1e.js → message-square-plus-Cu3mjwr6.js} +1 -1
  73. package/dist/assets/{mf-entry-bootstrap-0-22898ca3.js → mf-entry-bootstrap-0-4d6817b1.js} +2 -2
  74. package/dist/assets/{mic-off-nZLVhgXn.js → mic-off-BZE0vpPb.js} +1 -1
  75. package/dist/assets/{monitor-off-CemGAHSc.js → monitor-off-CeoPVLdS.js} +1 -1
  76. package/dist/assets/{monitor-smartphone-DWtxkkEg.js → monitor-smartphone-X2sF7PZY.js} +1 -1
  77. package/dist/assets/mount-BHInrZJO.js +1 -0
  78. package/dist/assets/{player-overlays-BIvElXhE.js → player-overlays-D5ZBZ0eM.js} +1 -1
  79. package/dist/assets/{recycle-BxIgahL6.js → recycle-DLXIFr8U.js} +1 -1
  80. package/dist/assets/remoteEntry-BBh0_eO2.js +1 -0
  81. package/dist/assets/{scan-eye-NGftRIPn.js → scan-eye-CvEU2c_X.js} +1 -1
  82. package/dist/assets/{scissors-BHv40eB0.js → scissors-x6ajWh6r.js} +1 -1
  83. package/dist/assets/{search-x-D0cw_-38.js → search-x-5Z0cDXke.js} +1 -1
  84. package/dist/assets/{send-B63foSkK.js → send-CQyb3VPM.js} +1 -1
  85. package/dist/assets/{settings-2-DX9ytL3l.js → settings-2-BrZJLOf8.js} +1 -1
  86. package/dist/assets/{speaker-BC0GjvT5.js → speaker-BYU0CVCA.js} +1 -1
  87. package/dist/assets/{src-WNMGrUfA.js → src-El9yRQEE.js} +10 -10
  88. package/dist/assets/{step-inspector-model-BNiszF9a.js → step-inspector-model-Be_ULwEg.js} +1 -1
  89. package/dist/assets/{timer-reset-Emc4qthN.js → timer-reset-DA0wUEff.js} +1 -1
  90. package/dist/assets/{ungroup-PYWFRB_O.js → ungroup-FYon4fz1.js} +1 -1
  91. package/dist/assets/{unlink-DUoBRhNd.js → unlink-BCjfZGMX.js} +1 -1
  92. package/dist/assets/{usb-x_Sc1fcn.js → usb-BBQDAd-3.js} +1 -1
  93. package/dist/assets/{use-scenes-feed-BStfY5U_.js → use-scenes-feed-B95-25e8.js} +1 -1
  94. package/dist/assets/{use-stationary-objects-CRygyfvJ.js → use-stationary-objects-zVOdbaPk.js} +1 -1
  95. package/dist/assets/useEventInvalidation-BHInrZJO.js +1 -0
  96. package/dist/assets/{useNodeUrlSelection-CXgYDNbG.js → useNodeUrlSelection-DTDVRQ9H.js} +1 -1
  97. package/dist/assets/user-round-qrIUAwAY.js +1 -0
  98. package/dist/assets/{user-x-CBs312Q9.js → user-x-DGH-0MS_.js} +1 -1
  99. package/dist/assets/{video-D0GPir6r.js → video-CQJAIcvp.js} +1 -1
  100. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DNGcxVE-.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BDOG6ivJ.js} +2 -2
  101. package/dist/index.html +10 -10
  102. package/dist/server/addon.js +1 -1
  103. package/package.json +1 -1
  104. package/dist/assets/Addons-BgJCB4KS.js +0 -4
  105. package/dist/assets/Build-BbIlgO2k.js +0 -40
  106. package/dist/assets/CompositionEditor-DVyG_gki.js +0 -1
  107. package/dist/assets/CompositionEditorPage-7rnuVmmK.js +0 -1
  108. package/dist/assets/DeviceDetail-4xoKO2Rw.js +0 -2
  109. package/dist/assets/Identity-DBoDRsam.js +0 -1
  110. package/dist/assets/Integrations-8Pi-1QTx.js +0 -1
  111. package/dist/assets/Integrations-BXourHS8.js +0 -1
  112. package/dist/assets/MyAccess-DP1ZLrmr.js +0 -2
  113. package/dist/assets/Notifications-CebO2rH3.js +0 -1
  114. package/dist/assets/circle-slash-DF-9F9d1.js +0 -1
  115. package/dist/assets/crop-BeLqvBA7.js +0 -1
  116. package/dist/assets/device-picker-model-D7ZJEJ81.js +0 -1
  117. package/dist/assets/i18n-SRLxy4I7.js +0 -1
  118. package/dist/assets/mount-D7ZJEJ81.js +0 -1
  119. package/dist/assets/remoteEntry-BqGZp0f4.js +0 -1
  120. package/dist/assets/useEventInvalidation-D7ZJEJ81.js +0 -1
  121. package/dist/assets/user-round-CfdLlVdg.js +0 -1
@@ -1 +0,0 @@
1
- import{$ as e,B as t,G as n,J as r,L as i,S as a,a as o,b as s,o as c,q as l,t as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{$t as f,D as p,Fn as m,Gi as h,It as g,Nt as _,Rr as v,Tt as y,Wr as b,an as x,bn as S,cn as C,dn as w,dt as T,kn as E,lr as D,mi as O,mr as k,or as A,ot as ee,pn as j,rr as M,sn as N}from"./player-overlays-BIvElXhE.js";import{Ci as P,Si as F,aa as I,ia as L,o as te,ra as R}from"./client-CNqHea-r.js";import{i as z,n as ne,r as re,t as ie}from"./key-Dq6CiRWE.js";import{d as ae,l as B,s as oe}from"./video-D0GPir6r.js";import{t as se}from"./key-round-DX4Tm3r5.js";import{t as ce}from"./monitor-smartphone-DWtxkkEg.js";import{t as le}from"./unlink-DUoBRhNd.js";import{Cu as ue,Du as de,Es as fe,Eu as pe,Fn as me,Fr as V,Fu as he,Hr as H,Iu as ge,L as _e,Lu as ve,Mn as ye,Nn as be,Nr as U,Nu as xe,Ou as Se,Pn as Ce,Pr as we,Pu as Te,Ru as Ee,Ss as De,Su as Oe,Ts as ke,Tu as Ae,Zn as je,_n as Me,_r as Ne,_s as Pe,_u as Fe,bu as Ie,cn as Le,cr as Re,di as ze,er as Be,ft as Ve,gn as He,gr as W,hn as G,id as K,ir as Ue,jn as We,kn as Ge,ln as Ke,mn as qe,nr as Je,or as Ye,rr as Xe,sr as Ze,to as Qe,tt as $e,ui as et,ut as tt,vu as nt,wu as rt,xu as it,yr as at,ys as ot,yt as st,yu as ct}from"./src-WNMGrUfA.js";import{t as q}from"./i18n-SRLxy4I7.js";import{t as J}from"./useTranslation-D3Is_4B6.js";import{T as lt,_r as ut,a as dt,d as ft,gr as pt,hr as mt,i as ht,ir as gt,l as _t,mr as vt,yr as yt}from"./index-CfXsU3sZ.js";import{t as bt}from"./AdminSectionedPage-CXL0Cc0w.js";import{t as xt}from"./AdminPage-oFm0hhFj.js";import{A as St,C as Ct,D as wt,E as Tt,O as Y,S as Et,T as Dt,a as Ot,b as kt,c as At,d as jt,f as Mt,g as Nt,h as Pt,i as Ft,k as It,l as Lt,m as Rt,n as zt,o as Bt,p as Vt,s as Ht,t as Ut,u as Wt,v as Gt,w as Kt,x as qt,y as Jt}from"./SessionsList-C3EfpYvC.js";import{i as Yt,n as Xt,r as Zt,t as Qt}from"./IntegrationHub-DnBfbKWG.js";import{n as $t,t as en}from"./addon-display-names-BkwMrExv.js";e();function tn(){let{t:e}=J(),t=U(),i=K.useUtils(),a=St(),{data:o,isLoading:s}=ue(),c=n(()=>o??[],[o]),l=K.useQueries(e=>c.map(t=>e.userManagement.listExternalIdentities({userId:t.id}))),u=K.auth.listLoginMethods.useQuery(),[f,p]=r(null),m=de({onSuccess:()=>void i.userManagement.listExternalIdentities.invalidate(),onError:e=>p(`Remove failed: ${e.message}`)}),h=n(()=>new Map((u.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),[u.data]),g=c.flatMap((e,t)=>l[t]?.data??[]),_=g.map(e=>({...Et(e,a),kind:h.get(e.provider)??e.provider})),v=async n=>{let r=g.find(e=>qt(e)===n.id);r!==void 0&&await t({title:e(`access.externalIdentitiesSection.removeSignInLink`,`Remove sign-in link`),message:e(`access.externalIdentitiesSection.willNoLongerBeAble`,`"{{ownerName}}" will no longer be able to sign in with this {{kind}} account.`,{ownerName:n.ownerName,kind:n.kind}),confirmLabel:e(`common.remove`,`Remove`),variant:`danger`})&&(p(null),m.mutate({userId:r.userId,provider:r.provider,subject:r.subject}))};return d(Y,{notice:It(f),onDismissNotice:()=>{p(null)},id:`external-identities`,title:e(`access.externalIdentitiesSection.signInLinks`,`Sign-in links`),icon:ae,description:e(`access.externalIdentitiesSection.externalAccountsSingleSignOn`,`External accounts (single sign-on) each user linked to their CamStack account. Only the owner can link one, from their profile; an admin can remove it.`),children:d(Dt,{rows:_,label:`sign-in links`,isLoading:s||l.some(e=>e.isLoading),loadError:l.find(e=>e.isError)?.error?.message??null,emptyText:`No user has linked a sign-in account.`,expiresNone:`—`,action:{label:e(`common.remove`,`Remove`),icon:le,isAvailable:()=>!0,onRun:e=>void v(e),busyId:null,disabled:m.isPending}})})}e();var nn={key:`access.nouns.linkedApp`};function rn(e){if(e.type===`category`){let t=e.target??``;return t===`device`?q.t(`access.linkedAppsSection.allDevices`):q.t(`access.linkedAppsSection.allTarget`,{target:t})}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function an(){let{t:e}=J(),t=U(),i=c(),a=Oe(),[o,s]=r(null),l=()=>void i.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]}),u=Ae({onSuccess:l,onError:e=>s(`Revoke failed: ${e.message}`)}),f=Tt(nn,l),p=n(()=>(a.data??[]).map(e=>Ct(e,e.scopes.map(rn).join(`, `))),[a.data]),m=async n=>{await t({title:e(`access.linkedAppsSection.revokeTheLink`,`Revoke the "{{name}}" link?`,{name:n.name}),message:e(`access.linkedAppsSection.losesAccessForOnIts`,`{{name}} loses access for {{ownerName}} on its next call. Linking it again needs the account-link flow from the start.`,{name:n.name,ownerName:n.ownerName}),confirmLabel:e(`access.linkedAppsSection.revoke`,`Revoke`),variant:`danger`})&&(s(null),u.mutate({id:n.id}))},h=u.isPending?u.variables?.id??null:null;return d(Y,{notice:It(o,f.outcome),onDismissNotice:()=>{s(null),f.dismiss()},id:`linked-apps`,title:e(`access.linkedAppsSection.linkedApps`,`Linked apps`),icon:D,description:e(`access.linkedAppsSection.externalIntegrationsAlexaLinkedTo`,`External integrations (Alexa, …) linked to this hub through OAuth. Revoking one stops that integration on its next call. Already-revoked rows can be selected and removed from the list.`),children:d(Dt,{rows:p,label:e(`access.linkedAppsSection.linkedApps2`,`linked apps`),isLoading:a.isLoading,loadError:a.isError?a.error?.message??`Request failed`:null,emptyText:`No linked apps — an integration appears here once it completes the account-link flow.`,expiresNone:`—`,action:{label:e(`access.linkedAppsSection.revoke`,`Revoke`),icon:g,isAvailable:e=>e.status===`active`||e.status===`revoked`,onRun:e=>void m(e),busyId:h,disabled:u.isPending||f.busy},bulk:{revoke:f,noun:nn,isSelectable:e=>e.status===`active`||e.status===`revoked`,quickSelect:[{label:e(`access.linkedAppsSection.selectRevoked`,`Select revoked`),match:e=>e.status===`revoked`}]}})})}e();var on={key:`access.nouns.session`};function sn(){let{t:e}=J(),t=U(),i=K.useUtils(),a=St(),o=K.auth.listSessions.useQuery(),[s,c]=r(null),l=()=>void i.auth.listSessions.invalidate(),u=K.auth.revokeSessions.useMutation({onSuccess:l,onError:e=>c(`Sign out failed: ${e.message}`)}),f=Tt(on,l),p=n(()=>(o.data??[]).map(e=>Kt(e,a,{client:e=>Gt(e).label,method:Jt})),[o.data,a]),m=async n=>{await t({title:e(`access.loginSessionsSection.signOutThisSession`,`Sign out this session`),message:e(`access.loginSessionsSection.onWillHaveToSign`,`{{ownerName}} on {{name}} will have to sign in again.`,{ownerName:n.ownerName,name:n.name}),confirmLabel:e(`access.loginSessionsSection.signOut`,`Sign out`),variant:`danger`})&&(c(null),u.mutate({id:n.id}))};return d(Y,{notice:It(s,f.outcome),onDismissNotice:()=>{c(null),f.dismiss()},id:`login-sessions`,title:e(`access.loginSessionsSection.loginSessions`,`Login sessions`),icon:ce,description:e(`access.loginSessionsSection.everyBrowserAndAppSigned`,`Every browser and app signed in to this hub, for every user. Signing one out ends it at once; it has to sign in again. Your own current session is marked and never included in a bulk sign-out.`),children:d(Dt,{rows:p,label:e(`common.sessionsLabel`),isLoading:o.isLoading,loadError:o.isError?o.error?.message??`Request failed`:null,emptyText:`No active sessions.`,action:{label:e(`access.loginSessionsSection.signOut`,`Sign out`),icon:oe,isAvailable:e=>e.status===`active`,onRun:e=>void m(e),busyId:u.isPending&&u.variables!==void 0&&`id`in u.variables?u.variables.id:null,disabled:u.isPending||f.busy},bulk:{revoke:f,noun:on,isSelectable:e=>e.status===`active`}})})}var cn={"by-id":`helpers.authAuditWording.bulkNoun.credential`,"share-link":`helpers.authAuditWording.bulkNoun.shareLink`,"admin-token":`helpers.authAuditWording.bulkNoun.adminToken`,"login-session":`helpers.authAuditWording.bulkNoun.loginSession`};function X(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function Z(e,t){let n=X(e,`tokenId`);return X(e,`name`)??(n===null?void 0:t.get(n))??n??`?`}function Q(e){return e.filter(e=>e!==null)}function ln(e){let t=X(e,`prefix`);return t===null?null:q.t(`helpers.authAuditWording.prefix`,{prefix:t})}function un(e,t){let n=e.detail??{};switch(e.action){case`admin-token-created`:{let e=n.expiresAt;return{title:q.t(`helpers.authAuditWording.tokenCreated`,{name:Z(n,t)}),details:Q([ln(n),typeof e==`number`?q.t(`helpers.authAuditWording.expires`,{at:kt(e)}):null])}}case`admin-token-used`:{let e=X(n,`path`);return{title:q.t(`helpers.authAuditWording.tokenUsed`,{name:Z(n,t)}),details:Q([ln(n),e===null?null:q.t(`helpers.authAuditWording.call`,{path:e})])}}case`token-minted`:{let e=n.expiresAt;return{title:q.t(`helpers.authAuditWording.tokenMinted`,{name:Z(n,t)}),details:Q([typeof e==`number`?q.t(`helpers.authAuditWording.expires`,{at:kt(e)}):null])}}case`token-revoked`:return{title:q.t(`helpers.authAuditWording.anyTokenRevoked`,{name:Z(n,t)}),details:[]};case`admin-token-revoked`:return{title:q.t(`helpers.authAuditWording.tokenRevoked`,{name:Z(n,t)}),details:Q([ln(n)])};case`credentials-revoked`:{let e=X(n,`kind`)??`credential`,t=n.revoked,r=n.skipped,i=cn[e],a=i===void 0?`${e}s`:q.t(i);return{title:q.t(`helpers.authAuditWording.bulkRevoked`,{n:typeof t==`number`?String(t):`?`,noun:a}),details:Q([typeof r==`number`&&r>0?q.t(`helpers.authAuditWording.skipped`,{count:r}):null,X(n,`ids`)===null?null:q.t(`helpers.authAuditWording.ids`,{ids:X(n,`ids`)??``})])}}case`second-factor-skipped`:{let e=X(n,`method`),t=X(n,`factors`);return{title:q.t(`helpers.authAuditWording.secondFactorSkipped`),details:Q([e===null?null:q.t(`helpers.authAuditWording.signedInWith`,{method:Jt(e)}),t===null?null:q.t(`helpers.authAuditWording.skippedFactors`,{factors:t.split(`,`).join(`, `)})])}}default:return{title:e.action,details:Object.entries(n).map(([e,t])=>`${e}: ${String(t)}`)}}}e();var dn=100;function fn(){let{user:e}=gt();return e?.isAdmin?d(mn,{}):null}function pn(){let{data:e}=ue(),{data:t}=K.auth.listTokens.useQuery(void 0);return n(()=>{let n=new Map;for(let t of e??[])n.set(t.id,t.username);let r=new Map;for(let e of t??[])r.set(e.id,e.label);return{userNameById:n,tokenNameById:r}},[e,t])}function mn(){let{t:e}=J(),t=K.auth.listAuthAudit.useQuery({limit:dn}),{userNameById:n,tokenNameById:r}=pn(),i=t.data??[];return a(`div`,{"data-testid":`auth-audit`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[a(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[d(j,{className:`h-3.5 w-3.5 text-foreground-subtle`}),d(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`auth.authAuditSection.authenticationAudit`,`Authentication audit`)}),d(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:e(`auth.authAuditSection.latest`,{count:dn})})]}),d(`div`,{className:`p-4`,children:t.isLoading?a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(A,{className:`h-3.5 w-3.5 animate-spin`}),e(`auth.authAuditSection.loadingAuditTrail`,`Loading audit trail…`)]}):t.isError?a(`div`,{className:`text-[11px] text-danger`,children:[e(`auth.authAuditSection.couldNotLoadTheAudit`,`Could not load the audit trail:`),` `,t.error?.message??e(`auth.authAuditSection.requestFailed`,`Request failed`)]}):i.length===0?a(`div`,{className:`rounded border border-dashed border-border px-3 py-4 text-xs text-foreground-subtle text-center space-y-1`,children:[d(`div`,{children:e(`auth.authAuditSection.noAuthenticationEventsRecordedYet`,`No authentication events recorded yet.`)}),d(`div`,{className:`text-[11px] text-foreground-subtle/90`,children:e(`auth.authAuditSection.thisTrailRecordsAdminToken`,`This trail records admin-token create/use/revoke, trusted-network 2FA skips, and credential revokes (including single share-link revoke). Browser password logins are not listed here.`)})]}):d(`ul`,{className:`divide-y divide-border rounded-md border border-border max-h-[420px] overflow-y-auto`,children:i.map(e=>d(hn,{record:e,userName:e.userId===void 0?null:n.get(e.userId)??e.userId,tokenNameById:r},e.id))})})]})}function hn({record:e,userName:t,tokenNameById:n}){let r=un(e,n);return a(`li`,{"data-testid":`auth-audit-row`,className:`px-3 py-2 text-xs space-y-0.5`,children:[a(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[d(`span`,{className:`font-medium text-foreground`,children:r.title}),d(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:kt(e.at)})]}),a(`div`,{className:`flex flex-wrap gap-x-3 text-[11px] text-foreground-subtle`,children:[t!==null&&d(`span`,{className:`text-foreground`,children:t}),e.ip!==void 0&&d(`span`,{className:`font-mono`,children:e.ip}),r.details.map(e=>d(`span`,{className:`font-mono`,children:e},e))]})]})}e();var $={loginSessions:`login-sessions`,linkedApps:`linked-apps`,tokens:`tokens`,scopedTokens:`scoped-tokens`,adminTokens:`admin-tokens`,shareLinks:`share-links`,externalIdentities:`external-identities`,audit:`auth-audit`},gn={[$.scopedTokens]:$.tokens,[$.adminTokens]:$.tokens,[$.shareLinks]:$.tokens};function _n(){return[{id:$.loginSessions,label:q.t(`system.access.loginSessions`,`Login sessions`),icon:ce,render:()=>d(sn,{})},{id:$.linkedApps,label:q.t(`system.access.linkedApps`,`Linked apps`),icon:D,render:()=>d(an,{})},{id:$.tokens,label:q.t(`system.access.tokens`,`Tokens`),icon:se,render:({createRequested:e,onCreateConsumed:t})=>d(Pt,{headerOwnsCreate:!0,createRequested:e,onCreateConsumed:t})},{id:$.externalIdentities,label:q.t(`system.access.signInLinks`,`Sign-in links`),icon:ae,render:()=>d(tn,{})},{id:$.audit,label:q.t(`system.access.audit`,`Audit`),icon:j,render:()=>d(fn,{})}]}function vn({createRequested:e=!1,onCreateConsumed:t}){let{t:r}=J(),i=n(()=>_n(),[]),o=Yt({ids:n(()=>i.map(e=>e.id),[i]),answered:!0}),s=ut(),[c]=yt(),l=c.get(`integration`),u=l===null?void 0:gn[l];if(u!==void 0){let e=new URLSearchParams(c);return e.set(`integration`,u),d(pt,{to:`?${e.toString()}`,replace:!0})}let f=i.find(e=>e.id===o.selectedId)??i[0];return a(`div`,{className:`flex flex-col gap-3`,"data-testid":`access-page`,children:[d(Ge,{appearance:`pills`,value:f?.id??$.loginSessions,onValueChange:e=>{s(`?${ft(c,e,null,null).toString()}`)},children:d(We,{"aria-label":r(`system.access.credentialKinds`,`Credential kinds`),children:i.map(e=>a(ye,{value:e.id,"data-testid":`access-kind-${e.id}`,children:[d(e.icon,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),e.label]},e.id))})}),f===void 0?null:d(`div`,{role:`region`,"aria-label":f.label,"data-testid":`access-kind-body`,children:f.render({createRequested:e&&f.id===$.tokens,onCreateConsumed:t??(()=>void 0)})},f.id)]})}function yn(e,t){if(e===$.tokens)return a(V,{size:`sm`,type:`button`,"data-testid":`access-new-token`,onClick:t,children:[d(se,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),q.t(`system.access.newToken`,`New token`)]})}function bn(){let[e,t]=r(!1);return{createRequested:e,requestCreate:()=>t(!0),clearCreate:()=>t(!1)}}e();var xn=[`oidcConnections`,`listConnections`],Sn=[`oidcConnections`,`connectionFormSchema`],Cn={displayName:`OpenID Connect`,icon:`shield-check`,issuerUrl:``,clientId:``,clientSecret:``,redirectUri:``,scopes:`openid profile email`,usernameClaim:`preferred_username`},wn=/^[a-z0-9][a-z0-9-]{0,63}$/;function Tn(e){return e instanceof Error?e.message:String(e)}function En(e,t){if(t)return typeof e==`string`&&e.length>0?e:void 0;if(L(e))return R;if(typeof e==`string`&&e.length>0)return e;I(e)}function Dn(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function On({addonId:e}){let{t:f}=J(),p=ee(),m=c(),h=U(),_=tt({editKey:`oidcEdit`,newKey:`oidcNew`}),[v,y]=r(!1),[b,x]=r(null),[S,C]=r(``),[w,T]=r({...Cn}),D=l(null),O=o({queryKey:[...xn,e],queryFn:async()=>p.trpcClient.oidcConnections.listConnections.query({})}),k=o({queryKey:Sn,queryFn:async()=>p.trpcClient.oidcConnections.connectionFormSchema.query({})}),A=O.data??[],j=Dn(k.data)?k.data:void 0,M=_.state,P=M.mode===`edit`?A.find(e=>e.id===M.id)??null:null;t(()=>{if(_.state.mode===`edit`&&P!==null){let e=`edit:${P.id}`;if(D.current===e)return;D.current=e,x(null),C(P.id),T(P.formValues===void 0?{...Cn}:{...P.formValues});return}if(_.state.mode===`new`){if(D.current===`new`)return;D.current=`new`,x(null),C(``),T({...Cn})}},[P,_.state]);let F=i(async()=>{await m.invalidateQueries({queryKey:xn})},[m]),I=u({mutationFn:async e=>p.trpcClient.oidcConnections.deleteConnection.mutate({id:e}),onSuccess:async()=>F()}),L=i(async e=>{await h({title:f(`system.oidcSettingsConnections.deleteOidcConnection`,`Delete OIDC connection?`),message:f(`system.oidcSettingsConnections.removeTheLoginButtonAnd`,`Remove “{{displayName}}” ({{id}}). The login button and IdP credentials for this id are dropped.`,{displayName:e.displayName,id:e.id}),confirmLabel:f(`common.delete`,`Delete`),cancelLabel:f(`common.cancel`,`Cancel`),variant:`danger`})&&(await I.mutateAsync(e.id),_.state.mode===`edit`&&_.state.id===e.id&&(_.close(),D.current=null))},[h,I,_,f]),te=i(async()=>{let e=w.displayName,t=typeof e==`string`&&e.trim()!==``?e.trim():``;if(t===``){x(`Display name is required.`);return}let n=_.state.mode===`new`,r=n?S.trim():P?.id??``;if(n&&!wn.test(r)){x(`Instance id must be a lowercase slug (e.g. authentik, google).`);return}if(r===``){x(`That connection is no longer available.`);return}let i=En(w.clientSecret,n),a=w.icon,o=w.issuerUrl,s=w.clientId,c=w.redirectUri,l=w.scopes,u=w.usernameClaim,d=u===`email`||u===`sub`?u:`preferred_username`;y(!0),x(null);try{n&&await p.trpcClient.oidcConnections.createConnection.mutate({id:r,displayName:t}),await p.trpcClient.oidcConnections.updateConnection.mutate({id:r,displayName:t,icon:typeof a==`string`?a:`shield-check`,issuerUrl:typeof o==`string`?o:``,clientId:typeof s==`string`?s:``,...i===void 0?{}:{clientSecret:i},redirectUri:typeof c==`string`?c:``,scopes:typeof l==`string`?l:`openid profile email`,usernameClaim:d}),await F(),_.close(),D.current=null}catch(e){x(Tn(e))}finally{y(!1)}},[S,P?.id,_,w,F,p]),R=n(()=>[{key:`id`,header:f(`system.oidcSettingsConnections.id`,`Id`),sortValue:e=>e.id,render:e=>d(`span`,{className:`font-mono text-xs text-foreground`,children:e.id})},{key:`name`,header:f(`system.oidcSettingsConnections.name`,`Name`),sortValue:e=>e.displayName,render:e=>d(`span`,{className:`truncate font-medium text-foreground`,children:e.displayName})},{key:`issuer`,header:f(`system.oidcSettingsConnections.issuer`,`Issuer`),sortValue:e=>e.issuerUrl,render:e=>d(`span`,{className:`truncate text-xs text-foreground-muted`,children:e.issuerUrl===``?`—`:e.issuerUrl})},{key:`status`,header:f(`system.oidcSettingsConnections.status`,`Status`),notSortableReason:`Badge`,render:e=>d(H,{variant:e.configured?`success`:`warning`,children:e.configured?f(`system.oidcSettingsConnections.configured`,`Configured`):f(`system.oidcSettingsConnections.notConfigured`,`Not configured`)})},{key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,nowrap:!0,render:e=>a(`div`,{className:`flex justify-end gap-1`,children:[d(V,{type:`button`,size:`sm`,variant:`secondary`,onClick:t=>{t.stopPropagation(),_.openEdit(e.id)},children:f(`common.edit`,`Edit`)}),d(V,{type:`button`,size:`sm`,variant:`ghost`,"aria-label":f(`system.oidcSettingsConnections.delete`,`Delete {{displayName}}`,{displayName:e.displayName}),title:f(`common.delete`,`Delete`),onClick:t=>{t.stopPropagation(),L(e)},children:d(g,{className:`h-3.5 w-3.5 text-danger`})})]})}],[_,L,f]),z=_.state.mode===`new`,ne=z||P!==null,re=z?`new`:P===null?`closed`:`edit:${P.id}:${P.configured?`cfg`:`empty`}`,ie=`/addon/${e}/<id>/callback`;return a(`div`,{className:`flex min-h-0 flex-col gap-3`,"data-testid":`oidc-settings-connections`,children:[a(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[a(`p`,{className:`text-sm text-foreground-muted`,children:[f(`system.oidcSettingsConnections.eachRowIsOneIdp`,`Each row is one IdP. Redirect URI:`),` `,d(`span`,{className:`font-mono text-xs`,children:ie})]}),a(V,{type:`button`,size:`sm`,"data-testid":`oidc-connections-add`,onClick:()=>_.openNew(),children:[d(E,{className:`h-3.5 w-3.5`}),f(`system.oidcSettingsConnections.addConnection`,`Add connection`)]})]}),O.isError?d(`p`,{className:`text-sm text-danger`,children:f(`system.oidcSettingsConnections.couldNotLoadConnections`,`Could not load connections.`)}):null,O.isPending?d(at,{className:`h-32 w-full`}):d(He,{columns:R,rows:A,rowKey:e=>e.id,pageSize:25,emptyMessage:f(`system.oidcSettingsConnections.noOidcConnectionsYetAdd`,`No OIDC connections yet. Add one to register an IdP.`),onRowClick:e=>_.openEdit(e.id),defaultSort:{columnKey:`name`,dir:`asc`}}),d(Ve,{open:ne,onClose:()=>{_.close(),x(null),D.current=null},title:z?f(`system.oidcSettingsConnections.addOidcConnection`,`Add OIDC connection`):f(`system.oidcSettingsConnections.edit`,`Edit {{value1}}`,{value1:P?.displayName??`connection`}),icon:N,width:`xl`,testId:`oidc-connection-editor`,error:b,footer:d(V,{type:`button`,size:`sm`,disabled:v||z&&S.trim()===``,onClick:()=>void te(),children:v?f(`system.oidcSettingsConnections.saving`,`Saving…`):f(`common.save`,`Save`)}),children:ne?a(s,{children:[z?a(`div`,{children:[d(me,{htmlFor:`oidc-connection-id`,children:f(`system.oidcSettingsConnections.instanceId`,`Instance id`)}),d(Ee,{id:`oidc-connection-id`,value:S,onChange:e=>C(e.target.value),placeholder:`authentik`,autoComplete:`off`}),d(`p`,{className:`mt-1 text-xs text-foreground-muted`,children:f(`system.oidcSettingsConnections.urlSlugAppearsInAddon`,`URL slug — appears in /addon/{{addonId}}/<id>/callback. Stable; renaming is not supported after save.`,{addonId:e})})]}):a(`p`,{className:`text-sm text-foreground-muted`,children:[f(`system.oidcSettingsConnections.instanceId2`,`Instance id:`),` `,d(`span`,{className:`font-mono`,children:P?.id})]}),j===void 0?d(`p`,{className:`text-sm text-foreground-muted`,children:f(`system.oidcSettingsConnections.loadingForm`,`Loading form…`)}):d(je,{schema:j,values:w,onChange:T,bare:!0},re)]}):null})]})}e();var kn=3e4,An=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],jn={titleKey:`system.authentication.sectionTitle`,subtitleKey:`system.authentication.sectionSubtitle`,emptyTitleKey:`system.authentication.sectionEmptyTitle`,emptyDescriptionKey:`system.authentication.sectionEmptyDescription`,installLabelKey:`system.authentication.sectionInstall`};function Mn(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:ne,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).`,`Scoped tokens, admin tokens and sessions are managed from Identity → Tokens & sessions.`],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:B,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.`,"Choose a stable instance id (slug). Set the IdP redirect URI to `https://<this-hub>/addon/auth-oidc/<id>/callback`.",`In Settings below, Add connection — enter the id, issuer, and credentials; Save.`,`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:B,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:f,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`)?{headline:`TOTP — second factor.`,icon:f,bullets:[`Time-based codes from an authenticator app (RFC 6238).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:N,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Nn(){let{t:e}=J(),t=ze({capName:An[0].capName},{refetchInterval:kn}),r=ze({capName:An[1].capName},{refetchInterval:kn}),i=et(void 0,{refetchInterval:kn}),a=n(()=>en(i.data??[]),[i.data]),o=n(()=>{let e=[],n=[t.data??[],r.data??[]];for(let[t,r]of An.entries())for(let i of n[t]??[])e.push({addonId:i.addonId,displayName:a.get(i.addonId)??i.addonId,isActive:i.isActive,capName:r.capName,stageBadge:r.stageBadge});return e},[t.data,r.data,a]),s=[{id:`authentication`,label:e(`system.authentication.authenticationProviders`,`Authentication providers`),install:{capability:An[0].capName,label:e(jn.installLabelKey)},entries:o.map(t=>({id:t.addonId,name:t.displayName,fallbackIcon:N,...$t(t.isActive),render:()=>d(Xt,{addonId:t.addonId,displayName:t.displayName,capName:t.capName,isActive:t.isActive,badges:t.stageBadge===null?null:d(H,{variant:`info`,className:Zt,children:t.stageBadge}),settingsContent:t.addonId.startsWith(`auth-oidc`)?d(On,{addonId:t.addonId}):void 0,panels:[{id:`about`,title:e(`system.authentication.about`,`About`),icon:Mn(t.addonId).icon,content:d(Pn,{addonId:t.addonId})}]})}))}];return d(Qt,{embedded:!0,icon:N,title:e(jn.titleKey),subtitle:e(jn.subtitleKey),groups:s,isLoading:t.isLoading||r.isLoading,emptyTitle:e(jn.emptyTitleKey),emptyDescription:e(jn.emptyDescriptionKey)})}function Pn({addonId:e}){let{t}=J(),n=Mn(e),r=n.icon;return a(`div`,{className:`space-y-3 rounded-lg border border-border bg-surface p-2 sm:p-4`,children:[a(`div`,{className:`flex items-start gap-2.5`,children:[d(r,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),d(`div`,{className:`text-xs text-foreground font-medium`,children:n.headline})]}),d(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:n.bullets.map((e,t)=>d(`li`,{children:e},t))}),n.setupSteps&&n.setupSteps.length>0&&a(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[a(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[d(z,{className:`h-3 w-3`}),t(`system.authentication.setupSteps`,`Setup steps`)]}),d(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:n.setupSteps.map((e,t)=>d(`li`,{children:e},t))})]}),e===`local-auth`&&a(`div`,{className:`rounded-md border border-info/30 bg-info/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[d(k,{className:`h-3.5 w-3.5 mt-0.5 text-info shrink-0`}),d(`span`,{children:d(vt,{i18nKey:`system.authentication.totpNote`,components:{access:d(mt,{to:`/system/my-access?tab=sign-in`,className:`underline text-primary`}),users:d(mt,{to:`/system/identity?tab=users`,className:`underline text-primary`})}})})]})]})}function Fn({isPending:e,error:t,what:n,onRetry:r,children:i}){let{t:o}=J();return e?a(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,role:`status`,"data-testid":`query-pending`,children:[d(A,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),o(`certificates.queryBody.reading`,{what:n})]}):t===null?i:d(W,{title:o(`certificates.queryBody.couldNotRead`,`Could not read {{what}}`,{what:n}),message:t.message.length>0?t.message:o(`certificates.queryBody.requestFailed`,`Request failed`),onRetry:r})}function In(){let{t:e}=J(),t=K.deviceCredentials.getDeviceCaStatus.useQuery({}),n=t.data;return d(Y,{id:`device-ca`,title:e(`certificates.deviceCaCard.deviceCertificateAuthority`,`Device certificate authority`),icon:N,description:e(`certificates.deviceCaCard.signsTheCertificateEachPaired`,`Signs the certificate each paired device holds. It is created the first time a device is paired.`),children:d(Fn,{isPending:t.isPending,error:t.error,what:`the device CA`,onRetry:()=>void t.refetch(),children:n!==void 0&&a(`div`,{className:`space-y-1`,"data-testid":`device-ca-status`,children:[a(G,{label:e(`certificates.deviceCaCard.state`,`State`),children:[n.state===`ready`&&d(H,{variant:`success`,children:e(`certificates.deviceCaCard.ready`,`Ready`)}),n.state===`absent`&&d(H,{variant:`default`,children:e(`certificates.deviceCaCard.notCreatedYet`,`Not created yet`)}),n.state===`unavailable`&&d(H,{variant:`danger`,children:e(`certificates.deviceCaCard.unavailable`,`Unavailable`)})]}),n.state===`ready`&&a(s,{children:[d(G,{label:e(`certificates.deviceCaCard.subject`,`Subject`),valueClassName:`font-mono`,children:n.subject}),d(G,{label:e(`certificates.deviceCaCard.fingerprintSha256`,`Fingerprint (SHA-256)`),valueClassName:`font-mono`,children:n.fingerprintSha256}),d(G,{label:e(`certificates.deviceCaCard.validUntil`,`Valid until`),children:n.validTo})]}),n.state===`unavailable`&&d(G,{label:e(`certificates.deviceCaCard.reason`,`Reason`),children:d(`span`,{className:`text-danger`,children:n.reason})})]})})})}e();function Ln(){let{t:e}=J(),t=K.useUtils(),n=K.deviceCredentials.getDeviceCertificateSettings.useQuery({}),[i,o]=r(null),s=K.deviceCredentials.setDeviceCertificateSettings.useMutation({onSuccess:()=>{o(null),t.deviceCredentials.getDeviceCertificateSettings.invalidate()},onError:e=>o(`Could not save: ${e.message}`)});return d(Fn,{isPending:n.isPending,error:n.error,what:`the enrollment setting`,onRetry:()=>void n.refetch(),children:n.data!==void 0&&a(G,{label:e(`certificates.deviceSettingsRow.usersCanEnrollTheirOwn`,`Users can enroll their own devices`),actions:d(be,{checked:n.data.selfEnrollment===`allowed`,disabled:s.isPending,"aria-label":e(`certificates.deviceSettingsRow.usersCanEnrollTheirOwn`,`Users can enroll their own devices`),onCheckedChange:e=>s.mutate({selfEnrollment:e?`allowed`:`disabled`})}),children:[d(`span`,{className:`text-[11px] text-foreground-subtle`,children:n.data.selfEnrollment===`allowed`?e(`certificates.deviceSettingsRow.allowedAUserSignedIn`,`Allowed - a user signed in on a phone can keep it signed in. Pairing by QR works either way.`):e(`certificates.deviceSettingsRow.disabledOnlyAnAdminCan`,`Disabled - only an admin can pair a device, with a QR code.`)}),i!==null&&d(`span`,{className:`block text-[11px] text-danger`,children:i})]})})}e();function Rn(e){let[n,i]=r(()=>Date.now());return t(()=>{let t=setInterval(()=>i(Date.now()),e);return()=>clearInterval(t)},[e]),n}e();var zn=80,Bn=208;function Vn({open:e,users:t,onClose:n,onPaired:i}){let{t:o}=J(),s=K.deviceCredentials.startEnrollment.useMutation({onSuccess:i}),[c,l]=r(``),[u,p]=r(``),m=c===``?t[0]?.id??``:c,h=s.data,g=()=>{s.reset(),p(``),n()};return d(Ve,{open:e,onClose:g,title:o(`certificates.pairDeviceDialog.pairADevice`,`Pair a device`),icon:f,width:`md`,testId:`pair-device-dialog`,error:s.isError?s.error.message:null,footer:h===void 0?a(V,{type:`button`,onClick:()=>{let e=u.trim();m===``||e===``||s.mutate({userId:m,deviceName:e})},disabled:s.isPending||m===``||u.trim()===``,children:[s.isPending&&d(A,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),o(`certificates.pairDeviceDialog.createPairingCode`,`Create pairing code`)]}):d(V,{type:`button`,variant:`outline`,onClick:g,children:o(`certificates.pairDeviceDialog.done`,`Done`)}),children:h===void 0?a(`div`,{className:`space-y-3`,children:[d(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`certificates.pairDeviceDialog.createsAOneTimeCode`,`Creates a one-time code for a phone you hold. Scan it with the CamStack app on that phone; the phone then stays signed in as the chosen user until you revoke it.`)}),d(st,{label:o(`certificates.pairDeviceDialog.user`,`User`),required:!0,children:d(xe,{value:m,onChange:e=>l(e.target.value),options:t.map(e=>({value:e.id,label:e.username}))})}),d(st,{label:o(`certificates.pairDeviceDialog.deviceName`,`Device name`),required:!0,description:o(`certificates.pairDeviceDialog.howThisPhoneIsListed`,`How this phone is listed, e.g. Anna's iPhone.`),children:d(Ee,{value:u,maxLength:zn,onChange:e=>p(e.target.value),placeholder:o(`certificates.pairDeviceDialog.annaSIphone`,`Anna's iPhone`),autoFocus:!0})})]}):d(Hn,{enrollUrl:h.enrollUrl,expiresAt:h.expiresAt,hubKnown:h.hubOrigin!==null,onRestart:()=>s.reset()})})}function Hn({enrollUrl:e,expiresAt:t,hubKnown:n,onRestart:r}){let{t:i}=J(),o=Bt(t,Rn(1e3));return d(`div`,{className:`space-y-3`,"data-testid":`pair-issued`,children:a(`div`,{className:`flex flex-col items-center gap-3 sm:flex-row sm:items-start`,children:[d(`div`,{className:o.expired?`opacity-30`:void 0,children:d(Be,{value:e,size:Bn,alt:i(`certificates.pairDeviceDialog.enrollmentQrCode`,`Enrollment QR code`)})}),a(`div`,{className:`min-w-0 flex-1 space-y-2`,children:[d(`p`,{className:`text-[11px] text-foreground-subtle`,children:i(`certificates.pairDeviceDialog.openTheCamstackAppOn`,`Open the CamStack app on the phone and scan this code. It works once.`)}),d(`div`,{className:`text-sm font-semibold tabular-nums text-foreground`,role:`timer`,"data-testid":`pair-countdown`,children:o.expired?i(`certificates.pairDeviceDialog.expiredCreateANewCode`,`Expired - create a new code`):i(`certificates.pairDeviceDialog.expiresIn`,`Expires in {{label}}`,{label:o.label})}),a(`div`,{className:`flex items-center gap-1 rounded-md border border-border bg-background px-2 py-1`,children:[d(`code`,{className:`min-w-0 flex-1 select-all break-all font-mono text-[11px] text-foreground`,children:e}),d(Le,{value:e,srLabel:`Enrollment link`})]}),!n&&a(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-2.5 py-1.5 text-[11px] text-foreground`,children:[d(_,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),d(`span`,{children:i(`certificates.pairDeviceDialog.theHubCouldNotName`,`The hub could not name an address for this link, so the app must already know it.`)})]}),o.expired&&d(V,{type:`button`,variant:`outline`,size:`sm`,onClick:r,children:i(`certificates.pairDeviceDialog.newCode`,`New code`)})]})]})})}e();var Un={key:`access.nouns.device`};function Wn({pairOpen:e,onPairClose:t}){let{t:i}=J(),o=U(),s=we(),c=K.useUtils(),l=K.deviceCredentials.listDeviceCredentials.useQuery({includeRevoked:!0}),u=ue(),[p,_]=r(null),[v,y]=r(null),b=()=>void c.deviceCredentials.listDeviceCredentials.invalidate(),x=e=>t=>{y(null),_(`${e} failed: ${t.message}`)},S=()=>{y(null),b()},C=K.deviceCredentials.revokeDeviceCredential.useMutation({onSuccess:S,onError:x(`Revoke`)}),w=K.deviceCredentials.deleteDeviceCredential.useMutation({onSuccess:e=>{e.result!==`deleted`&&_(e.result===`live`?`Only a revoked device can be deleted: revoke it first.`:`That device no longer exists.`),S()},onError:x(`Delete`)}),T=K.deviceCredentials.renameDeviceCredential.useMutation({onSuccess:S,onError:x(`Rename`)}),E=wt(Un,e=>C.mutateAsync({id:e}),b),D=E.busy||v!==null,O=n(()=>(l.data??[]).map(zt),[l.data]),k=async e=>{await o({title:i(`certificates.devicesCard.revoke`,`Revoke "{{name}}"?`,{name:e.name}),message:i(`certificates.devicesCard.sDeviceStopsSigningIn`,`{{ownerName}}'s device stops signing in at once and its open sessions end. To use it again it has to be paired anew. This cannot be undone.`,{ownerName:e.ownerName}),confirmLabel:i(`certificates.devicesCard.revoke2`,`Revoke`),variant:`danger`})&&(_(null),y(e.id),C.mutate({id:e.id}))},A=async e=>{await o({title:i(`certificates.devicesCard.delete`,`Delete "{{name}}"?`,{name:e.name}),message:i(`certificates.devicesCard.isRemovedFromTheList`,`{{name}} is removed from the list. The audit trail keeps the revocation.`,{name:e.name}),confirmLabel:i(`common.delete`,`Delete`),variant:`danger`})&&(_(null),y(e.id),w.mutate({id:e.id}))},ee=async e=>{let t=(await s({title:i(`certificates.devicesCard.renameDevice`,`Rename device`),label:i(`certificates.devicesCard.deviceName`,`Device name`),defaultValue:e.name,confirmLabel:i(`certificates.devicesCard.rename`,`Rename`)}))?.trim()??``;t===``||t===e.name||(_(null),y(e.id),T.mutate({id:e.id,deviceName:t}))},j={label:i(`certificates.devicesCard.revoke2`,`Revoke`),icon:h,isAvailable:Ot,onRun:e=>void k(e),busyId:C.isPending?v:null,disabled:D},M=[{label:i(`certificates.devicesCard.rename`,`Rename`),icon:m,tone:`neutral`,isAvailable:()=>!0,onRun:e=>void ee(e),busyId:T.isPending?v:null,disabled:D},{label:i(`common.delete`,`Delete`),icon:g,isAvailable:Ft,onRun:e=>void A(e),busyId:w.isPending?v:null,disabled:D}];return a(Y,{id:`devices`,title:i(`certificates.devicesCard.devices`,`Devices`),icon:f,description:i(`certificates.devicesCard.phonesThatStaySignedIn`,`Phones that stay signed in with a certificate instead of a login. Revoking one signs it out at once; it has to be paired again.`),notice:It(p,E.outcome),onDismissNotice:()=>{_(null),E.dismiss()},children:[d(Ln,{}),d(Dt,{rows:O,label:i(`certificates.devicesCard.label`),isLoading:l.isPending,loadError:l.error===null?null:l.error.message||`Request failed`,emptyText:`No devices paired yet.`,expiresNone:`—`,action:j,extraActions:M,bulk:{revoke:E,noun:Un,isSelectable:Ot}}),d(Vn,{open:e,users:u.data??[],onClose:t,onPaired:b})]})}var Gn=/-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----/,Kn=/-----BEGIN ((?:RSA |EC |ENCRYPTED )?PRIVATE KEY)-----[\s\S]+?-----END \1-----/,qn={certificate:`.pem,.crt,.cer`,privateKey:`.pem,.key`,ca:`.pem,.crt,.cer`};function Jn(e,t){if(t.trim()===``)return null;if(e===`privateKey`){let e=Kn.exec(t);return e===null?Gn.test(t)?q.t(`helpers.pemFile.isCert`):q.t(`helpers.pemFile.notKey`):e[1]===`ENCRYPTED PRIVATE KEY`?q.t(`helpers.pemFile.encrypted`):null}return Gn.test(t)?e===`certificate`&&Kn.test(t)?q.t(`helpers.pemFile.certHasKey`):null:Kn.test(t)?q.t(`helpers.pemFile.isKey`):q.t(`helpers.pemFile.notCert`)}function Yn(e){return e.text()}e();function Xn({kind:e,label:t,value:n,onChange:i,rows:o=6}){let{t:s}=J(),c=l(null),[u,f]=r(null),[p,m]=r(null),h=p??Jn(e,n),g=`pem-${e}`,_=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t!==void 0){f(t.name);try{let e=await Yn(t);m(null),i(e)}catch(e){m(`Could not read ${t.name}: ${e instanceof Error?e.message:String(e)}`)}}};return a(`div`,{className:`space-y-1`,children:[a(`div`,{className:`flex items-center justify-between gap-2`,children:[d(`label`,{htmlFor:g,className:`text-[11px] text-foreground-subtle`,children:t}),a(`div`,{className:`flex min-w-0 items-center gap-2`,children:[u!==null&&d(`span`,{className:`truncate font-mono text-[10px] text-foreground-subtle`,"data-testid":`${g}-file-name`,children:u}),d(`input`,{ref:c,type:`file`,accept:qn[e],onChange:e=>void _(e),className:`hidden`,"data-testid":`${g}-file`}),a(V,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>c.current?.click(),children:[d(re,{className:`mr-1 h-3 w-3`}),s(`system.pemField.chooseFile`,`Choose file`)]})]})]}),d(`textarea`,{id:g,value:n,onChange:e=>{f(null),m(null),i(e.target.value)},rows:o,"aria-invalid":h!==null,className:`w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`}),h!==null&&d(`p`,{className:`text-[11px] text-danger`,role:`alert`,children:h})]})}e();var Zn=30;function Qn(e){let t=Date.parse(e);return!Number.isNaN(t)&&Date.now()-t<Zn*864e5}function $n(e){if(e===null||e===``)return`—`;let t=e.replace(/:/g,``);return t.length<=16?e:`${t.slice(0,8)}…${t.slice(-8)}`}function er(){let{t:e}=J(),t=c(),n=Pe(void 0,{refetchInterval:15e3}),i=ot({onSuccess:()=>void t.invalidateQueries({queryKey:[[`localNetwork`]]})}),o=De({onSuccess:()=>void t.invalidateQueries({queryKey:[[`localNetwork`]]})}),s=fe({onSuccess:()=>void t.invalidateQueries({queryKey:[[`localNetwork`]]})}),l=ke({onSuccess:()=>{m(!1),g(``),v(``),b(``),t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),u=n.data,[f,m]=r(!1),[h,g]=r(``),[_,v]=r(``),[y,b]=r(``),S=()=>{if(!u?.caCertPem)return;let e=new Blob([u.caCertPem],{type:`application/x-pem-file`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`camstack-ca.crt`,n.click(),URL.revokeObjectURL(t)},C=u?.mode===`uploaded`?`Uploaded`:u?.mode===`generated`?`Generated local CA`:`TLS disabled`;return d(qe,{headingId:`local-access-certificate`,title:e(`system.localAccess.certificate`,`Certificate`),icon:x,children:a(`div`,{className:`${p} space-y-3`,children:[n.isError&&d(`p`,{className:`text-xs text-danger`,children:e(`system.localAccess.couldNotReadTlsStatus`,`Could not read TLS status.`)}),u?.reissueError&&d(W,{variant:`warning`,title:e(`system.localAccess.certificateReissue`,`Certificate reissue`),message:u.reissueError}),u?.restartRequired&&d(W,{variant:`warning`,title:e(`system.localAccess.restartRequired`,`Restart required`),message:e(`system.localAccess.theHttpsListenerStillServes`,`The HTTPS listener still serves the previous certificate. Restart the hub to apply it.`)}),u?.caMissing===!0&&d(W,{variant:`warning`,title:e(`system.localAccess.caMissingTitle`,`CA missing - devices cannot trust this hub`),message:e(`system.localAccess.caMissingBody`,"The uploaded certificate was not issued by a public CA and no CA was stored with it, so Download CA has nothing to hand out. Upload the certificate again together with its CA (for mkcert, the rootCA.pem in the folder `mkcert -CAROOT` prints).")}),u?.caReplacedAt!=null&&Qn(u.caReplacedAt)&&d(W,{variant:`warning`,title:e(`system.localAccess.caReplacedTitle`,`The local CA was replaced - re-install it on your devices`),message:e(`system.localAccess.caReplacedBody`,`The previous local CA had no name constraints: if its key ever leaked it could vouch for any website. The hub now uses a CA limited to private addresses and local names. Download it again and trust it on every phone and computer that used the old one (replaced {{when}}).`,{when:new Date(u.caReplacedAt).toLocaleString()})}),a(`dl`,{className:`grid grid-cols-1 gap-2 text-xs sm:grid-cols-2`,children:[a(`div`,{children:[d(`dt`,{className:`text-foreground-subtle`,children:e(`system.localAccess.mode`,`Mode`)}),d(`dd`,{className:`font-medium`,children:C})]}),a(`div`,{children:[d(`dt`,{className:`text-foreground-subtle`,children:e(`system.localAccess.validTo`,`Valid to`)}),d(`dd`,{className:`font-mono`,children:u?.validTo?new Date(u.validTo).toLocaleString():`—`})]}),a(`div`,{children:[d(`dt`,{className:`text-foreground-subtle`,children:e(`system.localAccess.leafSha256`,`Leaf SHA-256`)}),d(`dd`,{className:`font-mono`,title:u?.leafFingerprintSha256??void 0,children:$n(u?.leafFingerprintSha256??null)})]}),u?.storedUpload!=null&&a(`div`,{children:[d(`dt`,{className:`text-foreground-subtle`,children:e(`system.localAccess.storedUpload`,`Stored upload`)}),d(`dd`,{className:`font-medium`,children:e(`system.localAccess.storedUploadValue`,`valid to {{validTo}}, {{ca}}`,{validTo:new Date(u.storedUpload.validTo).toLocaleDateString(),ca:u.storedUpload.hasCa?e(`system.localAccess.storedUploadWithCa`,`with its CA`):e(`system.localAccess.storedUploadNoCa`,`no CA`)})})]}),a(`div`,{children:[d(`dt`,{className:`text-foreground-subtle`,children:e(`system.localAccess.caSha256`,`CA SHA-256`)}),d(`dd`,{className:`font-mono`,title:u?.caFingerprintSha256??void 0,children:u?.mode===`uploaded`&&u.caFingerprintSha256===null?d(`span`,{className:`font-sans text-foreground-subtle`,children:e(`system.localAccess.issuerNotIncludedInThe`,`Issuer not included in the upload (not the local CA)`)}):$n(u?.caFingerprintSha256??null)})]})]}),u&&u.sans.length>0&&d(`div`,{className:`flex flex-wrap gap-1`,children:u.sans.map(e=>d(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 font-mono text-[10px] text-foreground-subtle`,children:e},e))}),a(`div`,{className:`flex flex-wrap gap-2`,children:[d(Ke,{label:e(`system.localAccess.regenerate`,`Regenerate`),title:e(`system.localAccess.issueANewLeaf`,`Issue a new leaf?`),description:e(`system.localAccess.issuesANewLeafUnder`,`Issues a new leaf under the current local CA. Clients that trust the CA keep working. The HTTPS listener reloads.`),confirmLabel:e(`system.localAccess.regenerate`,`Regenerate`),disabled:u?.mode===`uploaded`||i.isPending,action:()=>i.mutateAsync({})}),d(V,{size:`sm`,variant:`outline`,onClick:()=>m(e=>!e),children:e(`system.localAccess.upload`,`Upload`)}),u?.caCertPem&&d(V,{size:`sm`,variant:`outline`,onClick:S,children:e(`system.localAccess.downloadCa`,`Download CA`)}),u?.mode===`uploaded`&&d(Ke,{label:e(`system.localAccess.revertToGenerated`,`Revert to generated`),title:e(`system.localAccess.revertTitle`,`Switch back to the generated certificate?`),description:e(`system.localAccess.keepsTheUploadedPair`,`Returns to the generated local CA. The uploaded certificate and its CA stay stored here; you can select them again.`),confirmLabel:e(`system.localAccess.revert`,`Revert`),disabled:o.isPending,action:()=>o.mutateAsync({})}),u?.mode===`generated`&&u.storedUpload!=null&&d(Ke,{label:e(`system.localAccess.useUploaded`,`Use uploaded certificate`),title:e(`system.localAccess.useUploadedTitle`,`Serve the stored upload again?`),description:e(`system.localAccess.useUploadedDescription`,`The stored uploaded certificate replaces the generated one on the HTTPS listener. The generated certificate stays stored.`),confirmLabel:e(`system.localAccess.useUploaded`,`Use uploaded certificate`),disabled:s.isPending,action:()=>s.mutateAsync(void 0)})]}),f&&a(`div`,{className:`space-y-2 border-t border-border pt-3`,children:[d(Xn,{kind:`certificate`,label:e(`system.localAccess.certificateOrFullChainPem`,`Certificate or full chain (PEM)`),value:h,onChange:g}),d(Xn,{kind:`privateKey`,label:e(`system.localAccess.privateKeyPem`,`Private key (PEM)`),value:_,onChange:v}),d(Xn,{kind:`ca`,label:e(`system.localAccess.caPemRequired`,`CA (PEM) - required unless the certificate comes from a public CA`),value:y,onChange:b,rows:4}),d(V,{size:`sm`,disabled:!h.trim()||!_.trim()||Jn(`certificate`,h)!==null||Jn(`privateKey`,_)!==null||Jn(`ca`,y)!==null||l.isPending,onClick:()=>l.mutate({certPem:h,keyPem:_,...y.trim()?{caPem:y}:{}}),children:e(`system.localAccess.saveCertificate`,`Save certificate`)}),l.isError&&d(`p`,{className:`text-xs text-danger`,children:l.error instanceof Error?l.error.message:e(`system.localAccess.uploadFailed`,`Upload failed`)})]})]})})}var tr={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`};function nr(e){let t=e.find(e=>e.isHub);return t?.https.kind===`served`?t.https.status.caFingerprintSha256:null}function rr({https:e,mesh:t,now:n}){let{t:r}=J(),i=Pe().data?.caCertPem??``,o=()=>{if(i===``)return;let e=URL.createObjectURL(new Blob([i],{type:`application/x-pem-file`})),t=document.createElement(`a`);t.href=e,t.download=`camstack-ca.crt`,t.click(),URL.revokeObjectURL(e)},s=t?.ca,c=s?.state===`ready`?Date.parse(s.validTo):null,l=t?.listener;return a(`div`,{className:`space-y-1`,"data-testid":`ca-strip`,children:[d(G,{label:r(`certificates.caStrip.localHttpsCaSha256`,`Local HTTPS CA (SHA-256)`),valueClassName:`font-mono`,children:a(`span`,{className:`flex flex-wrap items-center gap-2`,children:[nr(e)??`—`,i!==``&&a(V,{type:`button`,variant:`ghost`,size:`sm`,onClick:o,children:[d(b,{className:`h-3 w-3`,"aria-hidden":!0}),r(`certificates.caStrip.downloadCa`,`Download CA`)]})]})}),d(G,{label:r(`certificates.caStrip.clusterCaSha256`,`Cluster CA (SHA-256)`),valueClassName:`font-mono`,children:s===void 0?`—`:s.state===`ready`?s.fingerprintSha256:d(`span`,{className:`text-danger`,children:r(`certificates.caStrip.unavailable`,{reason:s.reason})})}),s?.state===`ready`&&a(G,{label:r(`certificates.caStrip.clusterCaValidUntil`,`Cluster CA valid until`),children:[s.validTo,c!==null&&!Number.isNaN(c)&&a(`span`,{className:`ml-2 text-[10px] ${tr[Wt(c,n)]}`,children:[`(`,At(c,n),`)`]})]}),l!==void 0&&a(G,{label:r(`certificates.caStrip.nodeListener`,`Node listener`),children:[l.state===`open`&&d(H,{variant:`success`,children:r(`certificates.caStrip.open`,`Open`)}),l.state===`not-started`&&d(H,{variant:`default`,children:r(`certificates.caStrip.notStarted`,`Not started`)}),l.state===`closed`&&a(`span`,{className:`text-danger`,children:[r(`certificates.caStrip.closedSince`,{when:jt(l.since)}),` `,l.reason]})]}),t!==void 0&&!t.registryAvailable&&a(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-2.5 py-1.5 text-[11px] text-foreground`,children:[d(_,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),d(`span`,{children:r(`certificates.caStrip.theCertificateRegistryIsNot`,`The certificate registry is not up, so the node list below is incomplete.`)})]})]})}function ir(e,t){let n=new Set;for(let t of e)n.add(t.nodeId);for(let e of t?.nodes??[])n.add(e.nodeId);return[...n].map(n=>{let r=e.find(e=>e.nodeId===n)??null,i=t?.nodes.find(e=>e.nodeId===n)??null;return{nodeId:n,isHub:r?.isHub??n===`hub`,online:r?.online??i?.online??!1,https:r,mesh:i}}).toSorted((e,t)=>Number(t.isHub)-Number(e.isHub)||e.nodeId.localeCompare(t.nodeId))}function ar(e){return e.isHub?q.t(`helpers.nodesModel.hubReissued`):e.mesh===null?q.t(`helpers.nodesModel.noCertRecorded`):e.online?null:q.t(`helpers.certificateModel.nodeOffline`)}function or(e){return e.isHub||e.mesh===null?ar(e):null}var sr={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`},cr={enroll:`Issued at enrollment`,renewal:`Issued by a renewal`,boot:`Issued at boot`,pairing:`Issued at pairing`,observed:`Observed on its connection`},lr={uploaded:`Uploaded`,generated:`Generated`,disabled:`Disabled`};function ur(e){let t=e.https?.https;return t?.kind===`served`?Ht(t.status.validTo):null}function dr({ms:e,now:t}){return e===null?d(`span`,{className:`text-foreground-subtle`,children:`—`}):a(`div`,{children:[d(`div`,{children:jt(e)}),d(`div`,{className:`text-[10px] ${sr[Wt(e,t)]}`,children:At(e,t)})]})}function fr({row:e}){let{t}=J(),n=e.https?.https;return n===void 0?d(`span`,{className:`text-foreground-subtle`,children:`—`}):n.kind===`served`?a(`div`,{title:n.status.leafFingerprintSha256??``,children:[d(H,{variant:`success`,className:`text-[10px]`,children:t(`certificates.nodesColumns.served`,`Served`)}),d(`span`,{className:`ml-1.5 text-[10px] text-foreground-subtle`,children:lr[n.status.mode]}),d(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:Vt(n.status.leafFingerprintSha256)}),n.status.sans.length>0&&d(`div`,{className:`mt-0.5 max-w-[14rem] truncate font-mono text-[10px] text-foreground-subtle`,title:n.status.sans.join(`, `),children:n.status.sans.join(`, `)})]}):a(`div`,{className:`max-w-[16rem]`,children:[d(H,{variant:n.kind===`unreadable`?`danger`:`warning`,className:`text-[10px]`,children:n.kind===`unreadable`?t(`certificates.nodesColumns.unreadable`,`Unreadable`):t(`certificates.nodesColumns.notServed`,`Not served`)}),d(`div`,{className:`mt-1 whitespace-normal text-[10px] text-foreground-subtle`,children:n.reason})]})}function pr({row:e}){let{t}=J(),n=e.mesh?.current??null;if(n===null)return d(`span`,{className:`text-foreground-subtle`,children:t(`certificates.nodesColumns.noneRecorded`,`None recorded`)});let r=e.mesh?.history.length??0;return a(`div`,{children:[d(`div`,{className:`font-mono text-[11px]`,title:n.serial,children:Rt(n.serial)}),d(`div`,{className:`font-mono text-[10px] text-foreground-subtle`,title:n.fingerprintSha256,children:Vt(n.fingerprintSha256)}),a(`div`,{className:`text-[10px] text-foreground-subtle`,children:[cr[n.issuedVia],r>0?` · ${t(`certificates.nodesColumns.earlier`,{count:r})}`:``]})]})}function mr({row:e}){let{t}=J(),n=e.mesh?.presentingCurrent??null;return n===null?d(`span`,{className:`text-foreground-subtle`,children:e.online?`—`:t(`certificates.nodesColumns.offline`,`Offline`)}):n?d(H,{variant:`success`,className:`text-[10px]`,children:t(`common.yes`,`Yes`)}):d(H,{variant:`warning`,className:`text-[10px]`,children:t(`certificates.nodesColumns.noPresentsAnother`,`No - presents another`)})}function hr(e){let t=e.icon;return a(V,{type:`button`,variant:`ghost`,size:`sm`,className:e.danger?`text-danger hover:bg-danger/10`:void 0,disabled:e.reason!==null||e.busy,title:e.reason??void 0,"aria-label":e.ariaLabel,onClick:e.onClick,children:[e.spinning?d(A,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):d(t,{className:`h-3 w-3`,"aria-hidden":!0}),e.label]})}function gr({reasons:e}){let{t}=J();return a(he,{className:`inline-block`,children:[d(ve,{children:d(`span`,{className:`cursor-help text-[11px] text-foreground-subtle`,"data-testid":`hub-managed-note`,children:t(`certificates.nodesColumns.managedByTheHub`,`Managed by the hub`)})}),d(ge,{children:d(`ul`,{className:`max-w-xs space-y-1 whitespace-normal text-left text-[11px]`,children:e.map(e=>d(`li`,{children:e},e))})})]})}function _r({row:e,o:t}){let{t:n}=J(),r=e.https===null?`No HTTPS inventory for this node.`:Mt(e.https).reason,i=ar(e),o=or(e),s=n=>t.running?.nodeId===e.nodeId&&t.running.action===n,c=t=>!e.isHub||t===null,l=[r,i,o].filter((e,t,n)=>e!==null&&n.indexOf(e)===t);return a(`div`,{className:`flex w-44 flex-col items-end gap-1`,children:[a(`div`,{className:`flex flex-col items-end gap-0.5`,children:[c(r)&&d(hr,{label:n(`certificates.nodesColumns.renewHttps`,`Renew HTTPS`),ariaLabel:n(`certificates.nodesColumns.renewTheCertificateOn`,`Renew the certificate on {{nodeId}}`,{nodeId:e.nodeId}),icon:S,reason:r,busy:t.busy,spinning:s(`renew-https`),danger:!1,onClick:()=>t.onRenewHttps(e)}),c(i)&&d(hr,{label:s(`renew-identity`)?n(`certificates.nodesColumns.renewing`,`Renewing…`):n(`certificates.nodesColumns.renewIdentity`,`Renew identity`),ariaLabel:n(`certificates.nodesColumns.renewTheClusterCertificateOf`,`Renew the cluster certificate of {{nodeId}}`,{nodeId:e.nodeId}),icon:S,reason:i,busy:t.busy,spinning:s(`renew-identity`),danger:!1,onClick:()=>t.onRenewIdentity(e)}),c(o)&&d(hr,{label:n(`certificates.nodesColumns.revokeIdentity`,`Revoke identity`),ariaLabel:n(`certificates.nodesColumns.revokeTheClusterCertificateOf`,`Revoke the cluster certificate of {{nodeId}}`,{nodeId:e.nodeId}),icon:h,reason:o,busy:t.busy,spinning:s(`revoke-identity`),danger:!0,onClick:()=>t.onRevokeIdentity(e)})]}),e.isHub&&l.length>0&&d(gr,{reasons:l}),!e.isHub&&r!==null&&e.https!==null&&d(`div`,{className:`w-full whitespace-normal text-right text-[10px] text-foreground-subtle`,"data-testid":`renew-reason-${e.nodeId}`,children:r}),!e.isHub&&i!==null&&d(`div`,{className:`w-full whitespace-normal text-right text-[10px] text-foreground-subtle`,"data-testid":`mesh-reason-${e.nodeId}`,children:i})]})}function vr(e){return[{key:`node`,header:q.t(`certificates.nodesColumns.node`,`Node`),sortValue:e=>e.isHub?``:e.nodeId.toLowerCase(),render:e=>a(`div`,{className:`flex items-center gap-1.5`,children:[d(`span`,{className:`font-medium text-foreground`,children:e.nodeId}),e.nodeId===`hub`&&d(H,{variant:`info`,className:`text-[10px]`,children:q.t(`common.hubWord`)}),!e.online&&d(H,{variant:`default`,className:`text-[10px]`,children:q.t(`common.offline`)})]})},{key:`https-state`,header:`HTTPS`,notSortableReason:`A state with a reason has no single order.`,render:e=>d(fr,{row:e})},{key:`https-expires`,header:q.t(`certificates.nodesColumns.httpsExpires`,`HTTPS expires`),sortValue:e=>ur(e),render:t=>d(dr,{ms:ur(t),now:e.now})},{key:`identity`,header:q.t(`certificates.nodesColumns.identity`,`Identity`),sortValue:e=>e.mesh?.current?.serial??null,render:e=>d(pr,{row:e})},{key:`identity-expires`,header:q.t(`certificates.nodesColumns.identityExpires`,`Identity expires`),sortValue:e=>e.mesh?.current?.notAfter??null,render:t=>d(dr,{ms:t.mesh?.current?.notAfter??null,now:e.now})},{key:`presenting`,header:q.t(`certificates.nodesColumns.inUse`,`In use`),notSortableReason:`Offline nodes have no answer to order by.`,render:e=>d(mr,{row:e})},{key:`actions`,header:q.t(`certificates.nodesColumns.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order.`,render:t=>d(_r,{row:t,o:e})}]}e();function yr(){let{t:e}=J(),t=U(),i=K.useUtils(),o=Rn(6e4),s=K.certificates.listHttpsCertificates.useQuery(),c=K.certificates.getMeshCertificates.useQuery(),[l,u]=r(null),[f,p]=r(null),[m,h]=r(null),g=()=>{h(null),i.certificates.listHttpsCertificates.invalidate(),i.certificates.getMeshCertificates.invalidate()},_=e=>(t,n)=>{h(null),u(`${n.nodeId}: ${e} - ${t.message}`)},v=K.certificates.renewHttpsOnNode.useMutation({onSuccess:(t,n)=>{p({tone:`success`,message:t.restartRequired?e(`certificates.nodesCard.newCertificateIssuedRestartThe`,`{{nodeId}}: new certificate issued. Restart the node to serve it.`,{nodeId:n.nodeId}):e(`certificates.nodesCard.newCertificateIssuedAndServed`,`{{nodeId}}: new certificate issued and served.`,{nodeId:n.nodeId})}),g()},onError:_(`renewal failed`)}),y=K.certificates.renewMeshOnNode.useMutation({onSuccess:e=>{p(Lt(e)),g()},onError:_(`renewal could not start`)}),b=K.certificates.revokeMeshOnNode.useMutation({onSuccess:e=>{p({tone:`success`,message:`${e.nodeId}: ${e.next}`}),g()},onError:_(`revoke failed`)}),x=v.isPending||y.isPending||b.isPending,S=(e,t)=>{u(null),p(null),h({nodeId:e,action:t})},C=async n=>{await t({title:e(`certificates.nodesCard.renewHttpsOn`,`Renew HTTPS on "{{nodeId}}"?`,{nodeId:n.nodeId}),message:n.isHub?e(`certificates.nodesCard.aNewCertificateIsIssued`,`A new certificate is issued from the local CA. Clients that trust the CA keep working.`):e(`certificates.nodesCard.theNodeMakesANew`,`The node makes a new key, the hub signs it and the node switches over without a restart. It keeps serving what it had if anything fails.`),confirmLabel:e(`certificates.nodesCard.renew`,`Renew`)})&&(S(n.nodeId,`renew-https`),v.mutate({nodeId:n.nodeId}))},T=e=>{S(e.nodeId,`renew-identity`),y.mutate({nodeId:e.nodeId})},E=async n=>{await t({title:e(`certificates.nodesCard.revokeTheIdentityOf`,`Revoke the identity of "{{nodeId}}"?`,{nodeId:n.nodeId}),message:e(`certificates.nodesCard.isDisconnectedAtOnceAnd`,`{{nodeId}} is disconnected at once and can no longer connect. To bring it back it must be paired again from System → Cluster → Agents. It stays in the node list until you forget it on the Cluster page. This cannot be undone.`,{nodeId:n.nodeId}),confirmLabel:e(`certificates.nodesCard.revokeAndDisconnect`,`Revoke and disconnect`),variant:`danger`})&&(S(n.nodeId,`revoke-identity`),b.mutate({nodeId:n.nodeId}))},D=vr({now:o,busy:x,running:m,onRenewHttps:e=>void C(e),onRenewIdentity:T,onRevokeIdentity:e=>void E(e)}),O=n(()=>ir(s.data??[],c.data),[s.data,c.data]),k=c.data?.registryAvailable??!0;return d(Y,{id:`nodes`,title:e(`certificates.nodesCard.nodes`,`Nodes`),icon:w,description:e(`certificates.nodesCard.eachNodeHoldsTwoCertificates`,`Each node holds two certificates: one it serves over HTTPS, one that proves its identity to the hub. Renewing replaces a certificate without a gap; revoking an identity cuts the node off until it re-joins.`),notice:It(l,f),onDismissNotice:()=>{u(null),p(null)},children:d(Fn,{isPending:s.isPending||c.isPending,error:s.error??c.error,what:`node certificates`,onRetry:()=>{s.refetch(),c.refetch()},children:a(`div`,{className:`space-y-3`,children:[d(rr,{https:s.data??[],mesh:c.data,now:o}),d(He,{columns:D,rows:O,rowKey:e=>e.nodeId,minWidthPx:960,maxBodyHeight:Me,defaultSort:{columnKey:`node`,dir:`asc`},emptyMessage:k?e(`certificates.nodesCard.noNodesReported`,`No nodes reported.`):e(`certificates.nodesCard.theCertificateRegistryIsNot`,`The certificate registry is not available yet, so nodes cannot be listed.`)})]})})})}function br({pairOpen:e,onPairClose:t}){return a(`div`,{className:`space-y-4`,"data-testid":`certificates-page`,children:[d(Wn,{pairOpen:e,onPairClose:t}),d(In,{}),d(er,{}),d(yr,{})]})}function xr({userId:e,username:t,onClose:n}){let{t:r}=J(),i=U(),o=K.useUtils(),s=it({userId:e}),c=K.auth.listLoginMethods.useQuery(),l=de({onSuccess:()=>void o.userManagement.listExternalIdentities.invalidate()}),u=new Map((c.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),f=s.data??[],p=async(n,a)=>{await i({title:r(`users.externalIdentitiesModal.removeSignInLink`,`Remove sign-in link`),message:r(`users.externalIdentitiesModal.willNoLongerBeAble`,`"{{username}}" will no longer be able to sign in with this {{label}} account.`,{username:t,label:a}),confirmLabel:r(`common.remove`,`Remove`),variant:`danger`})&&l.mutate({userId:e,provider:n.provider,subject:n.subject})};return d(Je,{open:!0,onOpenChange:e=>!e&&n(),children:a(Ue,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`external-identities-modal`,children:[d(Ze,{children:a(Re,{className:`flex items-center gap-2`,children:[d(D,{className:`h-4 w-4 text-primary`}),a(`span`,{children:[r(`users.externalIdentitiesModal.linkedSignInAccounts`,`Linked sign-in accounts`),a(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[r(`users.externalIdentitiesModal.user`,`User:`),` `,d(`span`,{className:`font-mono`,children:t})]})]})]})}),d(Xe,{className:`space-y-3`,children:s.isLoading?a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(A,{className:`h-3.5 w-3.5 animate-spin`}),r(`common.loading`,`Loading…`)]}):f.length===0?d(`p`,{className:`text-xs text-foreground-subtle`,children:r(`users.externalIdentitiesModal.noLinkedAccountsOnlyThe`,`No linked accounts. Only the user can link one, from their own profile page.`)}):d(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:f.map(e=>{let t=u.get(e.provider),n=t??e.provider;return a(`li`,{className:`flex items-center gap-3 px-3 py-2 text-xs`,children:[a(`div`,{className:`flex-1 min-w-0`,children:[a(`div`,{className:`font-medium text-foreground truncate`,children:[n,t===void 0&&d(`span`,{className:`ml-2 rounded bg-foreground-subtle/15 px-1.5 py-0.5 text-[10px] font-normal text-foreground-subtle`,children:r(`users.externalIdentitiesModal.providerUnavailable`,`provider unavailable`)})]}),a(`div`,{className:`text-[11px] text-foreground-subtle truncate`,children:[e.label??e.subject,` ·`,` `,new Date(e.linkedAt).toLocaleDateString()]})]}),a(`button`,{onClick:()=>void p(e,n),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:[d(le,{className:`h-3 w-3`}),r(`common.remove`,`Remove`)]})]},`${e.provider}|${e.subject}`)})})}),d(Ye,{children:d(V,{onClick:n,variant:`secondary`,children:r(`common.close`,`Close`)})})]})})}function Sr({userId:e,username:t,onClose:n}){let{t:r}=J(),i=c(),o=U(),l=Ie({userId:e}),u=l.data,p=()=>i.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),m=ct({onSuccess:()=>{p(),n()}}),h=l.isLoading?`loading`:u?.enabled?`enrolled`:`not_enrolled`;return d(Je,{open:!0,onOpenChange:e=>!e&&n(),children:a(Ue,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[d(Ze,{children:a(Re,{className:`flex items-center gap-2`,children:[d(f,{className:`h-4 w-4 text-primary`}),a(`span`,{children:[r(`users.totpModal.twoFactorAuthentication`,`Two-factor authentication`),a(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[r(`users.totpModal.user`,`User:`),` `,d(`span`,{className:`font-mono`,children:t})]})]})]})}),a(Xe,{className:`space-y-4`,children:[h===`loading`&&a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(A,{className:`h-3.5 w-3.5 animate-spin`}),r(`users.totpModal.checkingStatus`,`Checking status…`)]}),h===`not_enrolled`&&a(`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:[d(k,{className:`h-4 w-4 mt-0.5 shrink-0`}),a(`div`,{children:[d(`div`,{className:`font-medium text-foreground`,children:r(`users.totpModal.2faNotEnrolled`,`2FA not enrolled`)}),d(`p`,{className:`mt-0.5`,children:r(`users.totpModal.onlyTheUserThemselvesCan`,`Only the user themselves can enable 2FA, from their own profile page.`)})]})]}),h===`enrolled`&&u&&a(s,{children:[a(`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:[d(O,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),a(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[d(`div`,{className:`font-medium`,children:r(`users.totpModal.2faIsActive`,`2FA is active`)}),d(`div`,{className:`text-foreground-subtle`,children:r(`common.enrolledOn`,{when:u.confirmedAt?new Date(u.confirmedAt).toLocaleString():`—`})})]})]}),d(`div`,{className:`text-[11px] text-foreground-subtle`,children:r(`users.totpModal.removingHereClearsTheServer`,`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.`)}),a(`div`,{className:`flex justify-end gap-2`,children:[d(V,{onClick:n,variant:`secondary`,children:r(`common.close`,`Close`)}),a(`button`,{onClick:async()=>{await o({title:r(`users.totpModal.remove2fa`,`Remove 2FA`),message:r(`users.totpModal.removeTwoFactorAuthenticationFor`,`Remove two-factor authentication for "{{username}}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,{username:t}),confirmLabel:r(`common.remove`,`Remove`),variant:`danger`})&&m.mutate({userId:e})},disabled:m.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:[m.isPending?d(A,{className:`h-3 w-3 animate-spin`}):d(T,{className:`h-3 w-3`}),r(`users.totpModal.remove2fa`,`Remove 2FA`)]})]})]})]})]})})}e();function Cr({userId:e,username:t,onClose:n}){let{t:i}=J(),{user:o,logout:s}=gt(),c=o?.id===e,l=U(),u=K.useUtils(),f=K.auth.listSessions.useQuery({userId:e}),[p,m]=r(null),h=K.auth.revokeSessions.useMutation({onSuccess:(e,t)=>{if(c&&`userId`in t){s();return}u.auth.listSessions.invalidate()},onError:e=>m(`Sign out failed: ${e.message}`)}),g=async e=>{await l({title:i(`users.userSessionsModal.signOutThisSession`,`Sign out this session`),message:i(`users.userSessionsModal.onWillHaveToSign`,`"{{username}}" on {{label}} will have to sign in again.`,{username:t,label:Gt(e.client).label}),confirmLabel:i(`users.userSessionsModal.signOut`,`Sign out`),variant:`danger`})&&(m(null),h.mutate({id:e.id}))},_=async()=>{await l({title:i(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`),message:c?i(`users.userSessionsModal.everySessionOfYourOwn`,`Every session of your own account ends, this browser included: you will be signed out here too.`):i(`users.userSessionsModal.everySessionOfEndsAt`,`Every session of "{{username}}" ends at once; each device has to sign in again.`,{username:t}),confirmLabel:i(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`),variant:`danger`})&&(m(null),h.mutate({userId:e}))},v=h.isPending&&h.variables!==void 0&&`id`in h.variables?h.variables.id:null;return d(Je,{open:!0,onOpenChange:e=>!e&&n(),children:a(Ue,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`user-sessions-modal`,children:[d(Ze,{children:a(Re,{className:`flex items-center gap-2`,children:[d(ce,{className:`h-4 w-4 text-primary`}),a(`span`,{children:[i(`users.userSessionsModal.activeSessions`,`Active sessions`),a(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[i(`users.userSessionsModal.user`,`User:`),` `,d(`span`,{className:`font-mono`,children:t})]})]})]})}),a(Xe,{className:`space-y-3`,children:[p!==null&&d(`div`,{className:`text-[11px] text-danger`,children:p}),d(Ut,{sessions:f.data??[],isLoading:f.isLoading,loadError:f.isError?f.error?.message??`Request failed`:null,emptyText:`No active sessions.`,onRevoke:e=>void g(e),revokingId:v})]}),a(Ye,{className:`justify-between`,children:[a(`button`,{onClick:()=>void _(),disabled:h.isPending||(f.data??[]).length===0,className:`inline-flex items-center gap-1.5 rounded border border-danger/40 px-2.5 py-1 text-[11px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,children:[h.isPending&&v===null?d(A,{className:`h-3 w-3 animate-spin`}):d(oe,{className:`h-3 w-3`}),i(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`)]}),d(V,{onClick:n,variant:`secondary`,children:i(`common.close`,`Close`)})]})]})})}function wr({scopes:e,invalidReason:t}){let{t:n}=J(),r=ee(),i=o({queryKey:[`auth`,`previewScope`,e,!1],enabled:t===null,queryFn:()=>r.trpcClient.auth.previewScope.query({scopes:[...e],isAdmin:!1})}),{data:s}=Qe({projection:`slim`}),c=s?.length??null;if(t!==null)return a(`p`,{className:`flex items-center gap-1.5 text-[11px] text-warning`,"data-testid":`role-preview`,children:[d(C,{className:`h-3 w-3 shrink-0`}),t]});if(i.isLoading)return a(`p`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,"data-testid":`role-preview`,children:[d(A,{className:`h-3 w-3 shrink-0 animate-spin`}),n(`users.rolePreview.resolving`)]});if(i.isError||!i.data)return d(`p`,{className:`text-[11px] text-danger`,"data-testid":`role-preview`,children:n(`users.rolePreview.couldNotResolve`)});let l=i.data.viewableDeviceCount,u=i.data.device.view.all?n(`users.rolePreview.everyDevice`,{count:l}):c===null?n(`users.rolePreview.devicesVisible`,{count:l}):n(`users.rolePreview.devicesVisibleOf`,{count:l,total:c});return a(`p`,{className:`flex items-center gap-1.5 text-[11px] ${l===0?`text-warning`:`text-foreground`}`,"data-testid":`role-preview`,children:[l===0?d(C,{className:`h-3 w-3 shrink-0`}):d(v,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),l===0?n(`users.rolePreview.noDevice`):u]})}function Tr(e){let t=te(e.scopes??[]);if(t===null)return{role:e.isAdmin?`admin`:`viewer`,mode:`except`,pickedIds:[],viewer:F,unconfigured:!e.isAdmin};let n=Mr(t);return{role:e.isAdmin?`admin`:`viewer`,mode:n.mode,pickedIds:n.pickedIds,viewer:Nr(n.mode,n.pickedIds,t.features),unconfigured:!1}}function Er(e,t){return{...e,role:t}}function Dr(e,t){return{...e,mode:t,viewer:Nr(t,e.pickedIds,e.viewer.features)}}function Or(e,t){let n=Pr(t);return{...e,pickedIds:n,viewer:Nr(e.mode,n,e.viewer.features)}}function kr(e,t,n){let r=e.viewer.features.filter(e=>e!==t),i=n?[...r,t]:r;return{...e,viewer:Nr(e.mode,e.pickedIds,i)}}function Ar(e){return e.role===`viewer`&&e.mode===`only`&&e.pickedIds.length===0?`no-allowed-device`:null}function jr(e){return Ar(e)===null?e.role===`admin`?{isAdmin:!0,scopes:[]}:{isAdmin:!1,scopes:[e.viewer]}:null}function Mr(e){if(e.allow===`*`)return{mode:`except`,pickedIds:e.block};let t=new Set(e.block);return{mode:`only`,pickedIds:e.allow.filter(e=>!t.has(e))}}function Nr(e,t,n){let r=Pr(t);return e===`except`?{type:`viewer`,allow:`*`,block:r,features:[...n]}:{type:`viewer`,allow:r,block:[],features:[...n]}}function Pr(e){return[...new Set(e)]}e();var Fr=`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`;function Ir(e,t){return e?`failed`:t===void 0?`pending`:`answered`}function Lr(e){let t=[];for(let n of e)n.parentDeviceId===null&&t.push({id:n.id,name:n.name,type:String(n.type),...n.location===null?{}:{location:n.location}});return t}function Rr({user:e,isSelf:t,onClose:i,onSubmit:o,submitting:c,error:l}){let{t:u}=J(),[f,p]=r(n(()=>Tr(e),[e])),m=Qe({projection:`slim`}),h=m.data,g=Ir(m.isError,h),_=n(()=>Lr(h??[]),[h]),v=n(()=>({state:g,devices:g===`answered`?(h??[]).map(e=>({id:e.id,name:e.name})):void 0}),[g,h]),y=Ar(f),b=jr(f),x=y===`no-allowed-device`?u(`users.userAccessModal.pickAllowedDevice`):null,S=e=>{p(Er(f,e))},C=[{value:`except`,label:u(`users.userAccessModal.modeExcept`)},{value:`only`,label:u(`users.userAccessModal.modeOnly`)}];return d(Je,{open:!0,onOpenChange:e=>!e&&i(),children:a(Ue,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-2xl`,children:[d(Ze,{children:d(Re,{children:u(`users.userAccessModal.title`,{name:e.username})})}),a(Xe,{className:`space-y-4`,children:[f.unconfigured&&f.role===`viewer`&&d(W,{variant:`warning`,title:u(`users.userAccessModal.noAccessYet`),message:u(`users.userAccessModal.noAccessYetDetail`,{name:e.username})}),a(`section`,{className:`space-y-2`,children:[d(`h3`,{className:Fr,children:u(`users.userAccessModal.role`)}),a(`div`,{role:`radiogroup`,"aria-label":u(`users.userAccessModal.role`),className:`grid gap-1.5 sm:grid-cols-2`,children:[d(zr,{name:`admin`,checked:f.role===`admin`,label:u(`users.userAccessModal.admin`),description:u(`users.userAccessModal.adminDescription`),onPick:()=>S(`admin`)}),d(zr,{name:`viewer`,checked:f.role===`viewer`,disabled:t,label:u(`users.userAccessModal.viewer`),description:u(t?`users.userAccessModal.cannotDemoteSelf`:`users.userAccessModal.viewerDescription`),onPick:()=>S(`viewer`)})]})]}),f.role===`viewer`&&a(s,{children:[a(`section`,{className:`space-y-3`,children:[d(`h3`,{className:Fr,children:u(`users.userAccessModal.devices`)}),d($e,{label:u(`users.userAccessModal.whichDevices`),value:f.mode,options:C,onChange:e=>p(Dr(f,e))}),d(_e,{devices:_,listState:g,fleet:v,value:[...f.pickedIds],onChange:e=>p(Or(f,e)),emptyMeansAll:f.mode===`except`,noun:`device`,testId:`viewer-device-picker`}),d(wr,{scopes:b?.scopes??[],invalidReason:x})]}),a(`section`,{className:`space-y-2`,children:[d(`h3`,{className:Fr,children:u(`users.userAccessModal.features`)}),d(`div`,{className:`space-y-1`,children:P.map(e=>a(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-md p-1.5 hover:bg-surface-hover`,children:[d(Ce,{className:`mt-0.5`,checked:f.viewer.features.includes(e.id),onChange:t=>p(kr(f,e.id,t.target.checked))}),a(`span`,{className:`min-w-0`,children:[d(`span`,{className:`block text-[12px] font-medium text-foreground`,children:u(`users.viewerFeatures.${e.id}.label`,e.label)}),d(`span`,{className:`block text-[10px] text-foreground-subtle`,children:u(`users.viewerFeatures.${e.id}.description`,e.description)})]})]},e.id))})]})]}),l!==null&&d(W,{message:l})]}),a(Ye,{children:[d(V,{variant:`outline`,size:`sm`,onClick:i,children:u(`common.cancel`,`Cancel`)}),d(V,{size:`sm`,onClick:()=>b!==null&&o(b),disabled:c||b===null,children:c?d(A,{className:`h-3 w-3 animate-spin`}):u(`users.userAccessModal.saveAccess`)})]})]})})}function zr({name:e,checked:t,disabled:n=!1,label:r,description:i,onPick:o}){return a(`label`,{className:`flex items-start gap-2 rounded-lg border p-2.5 transition-colors ${t?`border-primary bg-primary/5`:`border-border hover:bg-surface-hover`} ${n?`cursor-not-allowed opacity-60`:`cursor-pointer`}`,children:[d(`input`,{type:`radio`,name:`user-role`,value:e,checked:t,disabled:n,onChange:o,className:`mt-0.5`}),a(`span`,{className:`min-w-0`,children:[d(`span`,{className:`block text-[12px] font-medium text-foreground`,children:r}),d(`span`,{className:`block text-[10px] text-foreground-subtle`,children:i})]})]})}e();var Br=8;function Vr(){return{username:``,password:``,isAdmin:!1}}function Hr(e){return{id:e.id,username:e.username,password:``,isAdmin:e.isAdmin}}function Ur(e){return e instanceof Error?e.message:q.t(`admin.system.users.genericError`)}function Wr(){let{t:e}=J(),n=c(),{user:i}=gt(),{state:o,openNew:l,openEdit:u,close:p}=tt(),[h,_]=r(null),[v,b]=r(null),[x,S]=r(!1),{data:C,isLoading:w,isError:T,error:O,refetch:k}=ue(),ee=U(),j=we(),M=()=>n.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),P=Fe(),F=nt({onSuccess:M}),I=Se({onSuccess:M}),L=rt({onSuccess:M}),te=pe(),[R,z]=r(null),[ne,re]=r(!1),[ae,B]=r(null),[oe,se]=r(null),[le,de]=r(null),[fe,me]=r(null),he=C??[],H=o.mode===`edit`?he.find(e=>e.id===o.id)??null:null,ge=()=>{_(null),b(null),S(!1),P.reset(),I.reset(),p()};t(()=>{if(o.mode===`closed`){_(null),b(null),S(!1);return}if(o.mode===`new`){_(e=>e!==null&&e.id===void 0?e:Vr());return}if(H===null){w||p();return}_(e=>e?.id===H.id?e:Hr(H))},[o,H,w,p]);let _e=o.mode===`new`&&h!==null&&h.id===void 0||o.mode===`edit`&&h!==null&&H!==null;async function ve(t){await ee({title:e(`admin.system.users.deleteUser`,`Delete user`),message:e(`admin.system.users.permanentlyDeleteUserThisCannot`,`Permanently delete user "{{username}}"? This cannot be undone — any active sessions will be revoked on next request.`,{username:t.username}),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&(F.mutate({id:t.id}),o.mode===`edit`&&o.id===t.id&&ge())}async function ye(t){let n=await j({title:e(`admin.system.users.resetPassword`,`Reset password`),message:e(`admin.system.users.setANewPasswordFor`,`Set a new password for "{{username}}".`,{username:t.username}),label:e(`admin.system.users.newPassword`,`New password`),inputType:`password`,placeholder:e(`admin.system.users.atLeast8Characters`,`At least 8 characters`),confirmLabel:e(`admin.system.users.continue`,`Continue`),validate:e=>e.length<Br?q.t(`admin.system.users.passwordTooShort`,{min:Br}):null});n===null||n.length===0||await ee({title:e(`admin.system.users.resetPassword`,`Reset password`),message:e(`admin.system.users.resetThePasswordForThey`,`Reset the password for "{{username}}"? They will need to use the new password on their next login.`,{username:t.username}),confirmLabel:e(`common.reset`,`Reset`)})&&L.mutate({id:t.id,newPassword:n})}function be(e){B(null),z(e)}async function xe(e,t){re(!0),B(null);try{t.isAdmin!==e.isAdmin&&await I.mutateAsync({id:e.id,isAdmin:t.isAdmin}),await te.mutateAsync({userId:e.id,scopes:[...t.scopes]}),z(null)}catch(e){B(Ur(e))}finally{re(!1),M()}}async function Ce(){if(h!==null){b(null);try{if(h.id===void 0){let e=h.username.trim();if(e===``||h.password.length<Br)return;await P.mutateAsync({username:e,password:h.password,isAdmin:h.isAdmin})}else await I.mutateAsync({id:h.id,isAdmin:h.isAdmin});M(),ge()}catch(e){b(Ur(e))}}}function De(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}let Oe=P.isPending||I.isPending,ke=h!==null&&h.id===void 0&&h.username.trim()!==``&&h.password.length>=Br,Ae=h!==null&&h.id!==void 0,je=Oe||(h?.id===void 0?!ke:!Ae),Me=e=>F.isPending&&F.variables?.id===e.id||I.isPending&&I.variables?.id===e.id||L.isPending&&L.variables?.id===e.id,Pe=[{key:`username`,header:e(`admin.system.users.username`,`Username`),sortValue:e=>e.username,render:e=>d(`span`,{className:`font-medium text-foreground`,"data-testid":`user-open-${e.id}`,children:e.username})},{key:`scopes`,header:e(`admin.system.users.access`,`Access`),sortValue:e=>Gr(e),render:t=>d(`span`,{onClick:e=>e.stopPropagation(),children:a(V,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>be(t),disabled:Me(t),title:e(`admin.system.users.configureAccess`,`Configure access`),"data-testid":`user-access-${t.id}`,children:[d(N,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),d(Kr,{user:t})]})})},{key:`createdAt`,header:e(`admin.system.users.created`,`Created`),nowrap:!0,sortValue:e=>e.createdAt,render:e=>d(`span`,{className:`text-foreground-subtle`,children:De(e.createdAt)})},{key:`actions`,header:e(`admin.system.users.actions`,`Actions`),align:`right`,nowrap:!0,notSortableReason:`Row actions`,render:t=>{let n=Me(t),r=t.id!==i?.id&&t.totpEnabled;return a(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[a(V,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>u(t.id),disabled:n,title:e(`admin.system.users.editUser`,`Edit user`),children:[d(m,{className:`h-3 w-3`}),e(`common.edit`,`Edit`)]}),r&&a(V,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>se(t),disabled:n,title:e(`admin.system.users.removeTwoFactorAuthentication`,`Remove two-factor authentication`),children:[d(f,{className:`h-3 w-3`}),e(`admin.system.users.remove2fa`,`Remove 2FA`)]}),a(V,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>de(t),disabled:n,title:e(`admin.system.users.linkedSignInAccounts`,`Linked sign-in accounts`),children:[d(D,{className:`h-3 w-3`}),e(`admin.system.users.signInLinks`,`Sign-in links`)]}),a(V,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>me(t),disabled:n,title:e(`admin.system.users.activeSessions`,`Active sessions`),children:[d(ce,{className:`h-3 w-3`}),e(`admin.system.users.sessions`,`Sessions`)]}),a(V,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void ye(t),disabled:n,title:e(`admin.system.users.resetPassword`,`Reset password`),children:[d(ie,{className:`h-3 w-3`}),e(`admin.system.users.resetPassword`,`Reset password`)]}),a(V,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void ve(t),disabled:n,title:e(`admin.system.users.deleteUser`,`Delete user`),className:`text-danger hover:bg-danger/10`,children:[n?d(A,{className:`h-3 w-3 animate-spin`}):d(g,{className:`h-3 w-3`}),e(`common.delete`,`Delete`)]})]})}}];return a(xt,{embedded:!0,icon:y,title:e(`admin.system.users.users`,`Users`),subtitle:e(`admin.system.users.hubAccountsAdminFlagAccess`,`Hub accounts, admin flag, access scopes, sessions and sign-in links.`),actions:a(V,{size:`sm`,type:`button`,onClick:()=>{b(null),l()},children:[d(E,{className:`h-3.5 w-3.5`}),e(`admin.system.users.createUser`,`Create User`)]}),children:[T&&d(W,{title:e(`admin.system.users.couldNotLoadUsers`,`Could not load users`),message:Ur(O),onRetry:()=>void k()}),w&&a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(A,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}),!w&&!T&&he.length===0&&d(Ne,{icon:y,title:e(`admin.system.users.noUsersYet`,`No users yet`),description:e(`admin.system.users.createAUserToGrant`,`Create a user to grant hub access.`)}),!w&&!T&&he.length>0&&d(He,{columns:Pe,rows:he,rowKey:e=>e.id,minWidthPx:560,maxBodyHeight:`max-h-[60vh]`,onRowClick:e=>u(e.id)}),d(Ve,{open:_e,onClose:ge,title:h?.id===void 0?e(`admin.system.users.createUser`,`Create User`):e(`admin.system.users.edit`,`Edit {{value1}}`,{value1:h.username||`user`}),icon:y,error:v,testId:`user-form-dialog`,footer:d(V,{size:`sm`,type:`button`,disabled:je,onClick:()=>void Ce(),children:Oe?a(s,{children:[d(A,{className:`h-3.5 w-3.5 animate-spin`}),e(`admin.system.users.saving`,`Saving…`)]}):h?.id===void 0?e(`admin.system.users.create`,`Create`):e(`common.save`,`Save`)}),children:h!==null&&a(`div`,{className:`space-y-3`,children:[d(st,{label:e(`admin.system.users.username`,`Username`),required:h.id===void 0,children:d(Ee,{value:h.username,onChange:e=>_({...h,username:e.target.value}),placeholder:`john`,autoFocus:h.id===void 0,disabled:h.id!==void 0,"data-testid":`user-form-username`})}),h.id===void 0&&d(st,{label:e(`admin.system.users.password`,`Password`),required:!0,description:e(`admin.system.users.atLeastCharacters`,`At least {{value1}} characters.`,{value1:String(Br)}),children:d(Te,{value:h.password,onValueChange:e=>_({...h,password:e}),shown:x,onToggleShown:()=>S(e=>!e),placeholder:`••••••••`,"data-testid":`user-form-password`})}),d(st,{label:e(`admin.system.users.admin`,`Admin`),description:e(`admin.system.users.unrestrictedAccessToEveryCapability`,`Unrestricted access to every capability and device.`),children:a(`label`,{className:`inline-flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[d(`input`,{type:`checkbox`,checked:h.isAdmin,onChange:e=>_({...h,isAdmin:e.target.checked}),className:`rounded border-border focus:ring-primary`,"data-testid":`user-form-admin`}),d(`span`,{children:e(`admin.system.users.admin`,`Admin`)})]})}),h.id!==void 0&&d(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`admin.system.users.toChangeThePasswordUse`,`To change the password, use Reset password on the user's row. Access scopes are configured from the Access column.`)})]})}),oe&&d(Sr,{userId:oe.id,username:oe.username,onClose:()=>se(null)}),le&&d(xr,{userId:le.id,username:le.username,onClose:()=>de(null)}),fe&&d(Cr,{userId:fe.id,username:fe.username,onClose:()=>me(null)}),R&&d(Rr,{user:R,isSelf:R.id===i?.id,onClose:()=>z(null),onSubmit:e=>void xe(R,e),submitting:ne,error:ae})]})}function Gr(e){let t=Tr(e);return t.role===`admin`?0:t.unconfigured?2:1}function Kr({user:e}){let{t}=J(),n=Tr(e);if(n.role===`admin`)return d(`span`,{className:`font-medium text-foreground`,children:t(`users.accessSummary.admin`)});if(n.unconfigured)return d(`span`,{className:`font-medium text-warning`,children:t(`admin.system.users.noAccess`,`No access`)});let{allow:r,block:i,features:o}=n.viewer,c=r===`*`?t(`users.accessSummary.allDevices`):t(`users.accessSummary.devices`,{count:r.length});return a(`span`,{className:`text-foreground-subtle`,children:[d(`span`,{className:`font-medium text-foreground`,children:t(`users.accessSummary.viewer`)}),` ·`,` `,c,i.length>0&&a(s,{children:[` · `,t(`users.accessSummary.blocked`,{count:i.length})]}),o.length>0&&a(s,{children:[` · `,t(`users.accessSummary.features`,{count:o.length})]})]})}e();var qr={"api-keys":$.tokens,"linked-sessions":$.linkedApps},Jr=`certificates`;function Yr(e){return a(V,{size:`sm`,type:`button`,"data-testid":`certificates-pair-device`,onClick:e,children:[d(f,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),q.t(`systemPage.identity.pairADevice`,`Pair a device`)]})}function Xr(){let{t:e}=J(),[t]=yt(),n=bn(),[i,a]=r(!1),o=qr[t.get(`tab`)??``];if(o!==void 0)return d(pt,{to:_t(`access`,{integration:o}),replace:!0});let s=lt(`/system/identity`,{t:e,isAdmin:!0})??{icon:M,title:e(`system.identity`,`Identity & Access`)},c=t.get(`tab`)??`users`,l=t.get(`integration`),u=c===dt.access.tab?yn(l,n.requestCreate):c===`certificates`?Yr(()=>a(!0)):void 0;return d(bt,{icon:s.icon,title:s.title,defaultSection:`users`,sectionsLabel:`${s.title} sections`,actions:u,sections:[{id:`users`,label:e(`systemPage.identity.users`,`Users`),content:d(Wr,{})},{id:dt.access.tab,label:e(`systemPage.identity.tokensSessions`,`Tokens & sessions`),ownedParams:ht.concat([Nt.token,Nt.scoped,Nt.admin]),content:d(vn,{createRequested:n.createRequested,onCreateConsumed:n.clearCreate})},{id:Jr,label:e(`systemPage.identity.certificates`,`Certificates`),content:d(br,{pairOpen:i,onPairClose:()=>a(!1)})},{id:dt.authentication.tab,label:e(`systemPage.identity.authentication`,`Authentication`),content:d(Nn,{}),ownedParams:ht}]})}export{Xr as IdentityPage};
@@ -1 +0,0 @@
1
- import{$ as e,B as t,G as n,J as r,L as i,S as a,a as o,b as s,o as c,q as l,t as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Fn as f,It as p,On as m,ht as h,kn as g,ln as _,nr as v,or as y,ot as b,xn as x}from"./player-overlays-BIvElXhE.js";import{cn as S,si as ee,zr as C}from"./client-CNqHea-r.js";import{h as w,s as T}from"./video-D0GPir6r.js";import{t as E}from"./log-in-C-sFC6o8.js";import{t as D}from"./monitor-smartphone-DWtxkkEg.js";import{t as te}from"./recycle-BxIgahL6.js";import{$i as O,Et as k,Fr as A,Hr as j,Nr as ne,Qi as M,Ta as N,Tt as P,Xi as re,Yi as ie,Zn as ae,ar as F,cr as I,ea as L,ft as oe,gl as R,gn as se,gr as z,ir as ce,na as B,nr as V,ra as le,rr as H,sr as U,st as W,ta as ue,ui as de,ut as fe,yr as pe}from"./src-WNMGrUfA.js";import{t as G}from"./i18n-SRLxy4I7.js";import{t as K}from"./useTranslation-D3Is_4B6.js";import{T as q,_r as me,i as he,y as J,yr as ge,z as _e}from"./index-CfXsU3sZ.js";import{t as ve}from"./AdminSectionedPage-CXL0Cc0w.js";import{t as ye}from"./BrokerForm-D-QT3T4C.js";import{t as be}from"./NodeAddonsSettingsPanel-B2ppCOQm.js";import{n as xe,r as Y,t as Se}from"./IntegrationHub-DnBfbKWG.js";e();var X=`kind`,Z=`name`,Q=`restore`,Ce=`restoreId`;function we(e){return{sections:[{id:`broker-identity`,title:G.t(`helpers.brokerIdentitySchema.title`),columns:1,fields:[{type:`select`,key:X,label:G.t(`helpers.brokerIdentitySchema.kind`),options:e.map(e=>({value:e.key,label:e.label})),disabled:e.length<=1},{type:`text`,key:Z,label:G.t(`helpers.brokerIdentitySchema.name`),placeholder:G.t(`helpers.brokerIdentitySchema.namePlaceholder`),required:!0},{type:`boolean`,key:Q,label:G.t(`helpers.brokerIdentitySchema.restore`),description:G.t(`helpers.brokerIdentitySchema.restoreHint`)},{type:`text`,key:Ce,label:G.t(`helpers.brokerIdentitySchema.originalId`),placeholder:`ha_004`,required:!0,showWhen:{field:Q,equals:!0}}]}]}}function Te(e){let t=t=>{let n=e[t];return typeof n==`string`?n.trim():``},n=t(X);if(n===``)return{ok:!1,problem:`Pick a kind.`};let r=t(Z);if(r===``)return{ok:!1,problem:`Enter a name before saving.`};if(e.restore!==!0)return{ok:!0,identity:{kindKey:n,name:r,restoreId:null}};let i=t(Ce);return i===``?{ok:!1,problem:`Enter the original id, or turn restore off to create a new broker.`}:{ok:!0,identity:{kindKey:n,name:r,restoreId:i}}}var Ee={"home-assistant":`Home Assistant`,mqtt:`MQTT`};function De(e){return Ee[e]??e}function Oe(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var ke={connected:`success`,connecting:`warning`,disconnected:`default`,"auth-failed":`danger`,unreachable:`danger`,error:`danger`};function Ae({status:e}){return d(j,{variant:ke[e],className:`text-[10px]`,children:e})}function je(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function Me({title:e,subtitle:t,onClose:n,children:r}){return d(V,{open:!0,onOpenChange:e=>!e&&n(),children:a(ce,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(U,{children:[d(I,{children:e}),t&&d(F,{children:t})]}),d(H,{className:`space-y-3 pr-1`,children:r})]})})}function Ne({kinds:e,onClose:t,onDone:i}){let{t:o}=K(),s=c(),l=n(()=>we(e.map(e=>({key:$(e),label:e.label}))),[e]),[u,f]=r(()=>({[X]:$(e[0]),[Z]:``,[Q]:!1,[Ce]:``})),[p,m]=r(null),h=e.find(e=>$(e)===u.kind)??e[0],g=h?.kind??``,_=h?.addonId,v=h?.interactiveConnectPath,y=ie({onSuccess:e=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]});let t=typeof e==`object`&&e&&typeof e.id==`string`?e.id:null;t!==null&&v!==void 0&&v.length>0&&J(v,t,()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]})}),i()}}),b=e=>{let t=Te(u);if(!t.ok){m(t.problem);return}m(null);let{name:n,restoreId:r}=t.identity;y.mutate({kind:g,name:n,settings:e,...r===null?{}:{id:r},..._===void 0?{}:{addonId:_}})};return a(Me,{title:o(`brokers.brokerManager.addBroker`,`Add broker`),subtitle:o(`brokers.brokerManager.registerAMessageBrokerFor`,`Register a message broker for exporters and automations.`),onClose:y.isPending?()=>{}:t,children:[d(_e,{schema:l,values:u,onChange:f}),p!==null&&d(z,{message:p}),y.isError&&d(z,{message:y.error instanceof Error?y.error.message:String(y.error)}),g&&d(ye,{kind:g,..._===void 0?{}:{addonId:_},onSubmit:b,onCancel:t,submitLabel:y.isPending?o(`brokers.brokerManager.adding`,`Adding…`):o(`brokers.brokerManager.addBroker`,`Add broker`),disabled:y.isPending},$(h))]})}function $(e){return e===void 0?``:`${e.addonId??``}::${e.kind}`}function Pe({broker:e,onClose:t,onDone:r}){let{t:i}=K(),o=c(),s=re({id:e.id,addonId:e.addonId}),l=B({onSuccess:()=>{o.invalidateQueries({queryKey:[[`broker`,`list`]]}),o.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:e.id,addonId:e.addonId}}]}),r()}}),u=n(()=>{let e=s.data;return e&&typeof e==`object`?{...e}:{}},[s.data]);return d(Me,{title:i(`brokers.brokerManager.edit`,`Edit {{name}}`,{name:e.name}),subtitle:`${De(e.kind)} · ${e.id}`,onClose:l.isPending?()=>{}:t,children:s.isLoading?a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(y,{className:`h-3.5 w-3.5 animate-spin`}),` `,i(`brokers.brokerManager.loadingSettings`)]}):s.isError?a(`div`,{className:`space-y-3`,children:[d(z,{message:i(`brokers.brokerManager.loadSettingsFailed`,{message:s.error instanceof Error?s.error.message:i(`common.unknownError`)})}),d(`div`,{className:`flex justify-end`,children:d(A,{variant:`outline`,size:`sm`,onClick:t,children:i(`common.close`,`Close`)})})]}):a(`div`,{className:`space-y-3`,children:[l.isError&&d(z,{message:l.error instanceof Error?l.error.message:String(l.error)}),d(ye,{kind:e.kind,addonId:e.addonId,brokerId:e.id,initialValues:u,onSubmit:t=>{l.mutate({id:e.id,settings:t,addonId:e.addonId})},onCancel:t,submitLabel:l.isPending?i(`brokers.brokerManager.saving`,`Saving…`):i(`common.save`,`Save`),disabled:l.isPending})]})})}function Fe({broker:e,interactiveConnectPath:t,interactiveDisconnectPath:n,onEdit:i}){let{t:o}=K(),s=c(),l=ne(),[u,m]=r(null),g=le({onSuccess:e=>m(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>m({ok:!1,error:e instanceof Error?e.message:String(e)})}),_=ue({onSuccess:()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),v=async()=>{await l({title:o(`brokers.brokerManager.deleteBroker`,`Delete broker`),message:o(`brokers.brokerManager.deleteBrokerIntegrationsThatDepend`,`Delete broker "{{name}}"? Integrations that depend on it will stop working.`,{name:e.name}),confirmLabel:o(`common.delete`,`Delete`),variant:`danger`})&&_.mutate({id:e.id,addonId:e.addonId})},b=t!==void 0&&t.length>0&&e.status!==`connected`,x=n!==void 0&&n.length>0&&e.status===`connected`;return a(`tr`,{className:`border-b border-border last:border-0`,children:[d(`td`,{className:`px-3 py-2 text-xs text-foreground font-medium`,children:e.name}),d(`td`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:De(e.kind)}),a(`td`,{className:`px-3 py-2`,children:[d(Ae,{status:e.status}),u&&d(`span`,{className:`ml-2 text-[10px] ${u.ok?`text-success`:`text-danger`}`,children:u.ok?`OK`:u.error??o(`common.failedWord`)})]}),d(`td`,{className:`px-3 py-2`,children:a(`div`,{className:`flex items-center justify-end gap-1.5`,children:[b&&a(A,{variant:`primary`,size:`sm`,onClick:()=>{J(t,e.id,()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]})})},title:o(`brokers.brokerManager.signInOpensAPopup`,`Sign in — opens a popup that closes when done`),children:[d(E,{className:`h-3 w-3`}),` `,o(`brokers.brokerManager.signIn`)]}),x&&a(A,{variant:`outline`,size:`sm`,onClick:()=>{J(n,e.id,()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]})})},title:o(`brokers.brokerManager.signOutClearsTheLinked`,`Sign out — clears the linked Google account on this broker`),children:[d(T,{className:`h-3 w-3`}),` `,o(`brokers.brokerManager.signOut`)]}),a(A,{variant:`outline`,size:`sm`,onClick:()=>g.mutate({id:e.id,addonId:e.addonId}),disabled:g.isPending,title:o(`brokers.brokerManager.testConnection`,`Test connection`),children:[g.isPending?d(y,{className:`h-3 w-3 animate-spin`}):d(h,{className:`h-3 w-3`}),o(`brokers.brokerManager.test`,`Test`)]}),a(A,{variant:`outline`,size:`sm`,onClick:()=>i(e),title:o(`common.edit`,`Edit`),children:[d(f,{className:`h-3 w-3`}),` `,o(`common.edit`)]}),a(A,{variant:`outline`,size:`sm`,className:`border-danger/40 text-danger hover:bg-danger/10`,onClick:()=>{v()},disabled:_.isPending,title:o(`common.delete`,`Delete`),children:[_.isPending?d(y,{className:`h-3 w-3 animate-spin`}):d(p,{className:`h-3 w-3`}),o(`common.delete`,`Delete`)]})]})})]})}function Ie({addonId:e}={}){let{t}=K(),i=O({}),o=L(),s=n(()=>je(i.data).filter(t=>e===void 0||t.addonId===e),[i.data,e]),[c,l]=r(!1),[u,f]=r(null),p=n(()=>{let t=new Map;for(let n of Oe(o.data))if(!(e!==void 0&&n.addonId!==e))for(let e of n.kinds){let r=typeof e.interactiveConnectPath==`string`&&e.interactiveConnectPath.length>0?e.interactiveConnectPath:void 0,i=typeof e.interactiveDisconnectPath==`string`&&e.interactiveDisconnectPath.length>0?e.interactiveDisconnectPath:void 0;t.set(`${n.addonId}::${e.kind}`,{addonId:n.addonId,kind:e.kind,label:e.label,...r===void 0?{}:{interactiveConnectPath:r},...i===void 0?{}:{interactiveDisconnectPath:i}})}for(let e of s)[...t.values()].some(t=>t.kind===e.kind)||t.set(`::${e.kind}`,{kind:e.kind,label:De(e.kind)});return[...t.values()]},[s,o.data,e]),m=n(()=>{let e=new Map;for(let t of p)e.has(t.kind)||e.set(t.kind,{...t.interactiveConnectPath===void 0?{}:{connect:t.interactiveConnectPath},...t.interactiveDisconnectPath===void 0?{}:{disconnect:t.interactiveDisconnectPath}});return e},[p]);return a(`div`,{className:`space-y-3`,children:[d(`div`,{className:`flex items-center justify-end`,children:a(A,{variant:`primary`,size:`sm`,onClick:()=>l(!0),disabled:p.length===0,title:p.length===0?t(`brokers.brokerManager.noBrokerProvidersAvailable`,`No broker providers available`):void 0,children:[d(g,{className:`h-3.5 w-3.5`}),` `,t(`brokers.brokerManager.addBroker`)]})}),d(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:a(`table`,{className:`w-full min-w-[36rem] border-collapse`,children:[d(`thead`,{children:a(`tr`,{className:`border-b border-border bg-background/50`,children:[d(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:t(`brokers.brokerManager.name`,`Name`)}),d(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:t(`brokers.brokerManager.kind`,`Kind`)}),d(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:t(`brokers.brokerManager.status`,`Status`)}),d(`th`,{className:`px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:t(`brokers.brokerManager.actions`,`Actions`)})]})}),a(`tbody`,{children:[i.isLoading&&d(`tr`,{children:a(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[d(y,{className:`inline h-4 w-4 animate-spin`}),` `,t(`brokers.brokerManager.loadingBrokers`)]})}),i.isError&&d(`tr`,{children:a(`td`,{colSpan:4,className:`px-3 py-4 text-center text-xs text-danger`,children:[t(`brokers.brokerManager.failedToLoadBrokers`,`Failed to load brokers:`),` `,i.error instanceof Error?i.error.message:t(`brokers.brokerManager.unknownError`,`Unknown error`)]})}),!i.isLoading&&!i.isError&&s.length===0&&d(`tr`,{children:d(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:t(`brokers.brokerManager.noBrokersRegisteredYetAdd`,`No brokers registered yet. Add one to publish device events for downstream automations.`)})}),s.map(e=>{let t=m.get(e.kind);return d(Fe,{broker:e,...t?.connect===void 0?{}:{interactiveConnectPath:t.connect},...t?.disconnect===void 0?{}:{interactiveDisconnectPath:t.disconnect},onEdit:f},e.id)})]})]})}),c&&d(Ne,{kinds:p,onClose:()=>l(!1),onDone:()=>l(!1)}),u&&d(Pe,{broker:u,onClose:()=>f(null),onDone:()=>f(null)})]})}e();function Le({addonId:e,fallback:t}){let{t:n}=K(),r=R({});if(r.isPending)return d(`div`,{className:`flex justify-center py-8`,children:d(y,{className:`size-6 animate-spin text-muted-foreground`})});if(r.isError)return d(z,{message:n(`brokers.brokerRecordEntriesPanel.loadKindsFailed`,`Could not load entry kinds`)});let i=r.data.kinds.find(t=>t.owner===e&&t.kind===`brokers`);return i===void 0?t:d(Re,{addonId:e,kind:i})}function Re({addonId:e,kind:t}){let{t:r}=K(),i=c(),o=O({}),l=L(),u=n(()=>{let t=new Map;for(let n of je(o.data))n.addonId===e&&t.set(n.id,n);return t},[o.data,e]),f=n(()=>{let e=new Map;for(let t of Oe(l.data))for(let n of t.kinds){let r=n.interactiveConnectPath,i=n.interactiveDisconnectPath;e.set(`${t.addonId}::${n.kind}`,{...typeof r==`string`&&r.length>0?{connect:r}:{},...typeof i==`string`&&i.length>0?{disconnect:i}:{}})}return e},[l.data]),p=()=>{i.invalidateQueries({queryKey:[[`broker`]]}),i.invalidateQueries({queryKey:[[`recordEntries`]]})};return d(W,{kind:t,extraColumns:n(()=>[{key:`status`,header:r(`brokers.brokerManager.status`,`Status`),nowrap:!0,width:`w-px`,render:e=>{let t=u.get(e.id);return t===void 0?null:d(Ae,{status:t.status})}}],[u,r]),rowActions:e=>{let t=u.get(e.id);if(t===void 0)return null;let n=f.get(`${t.addonId}::${t.kind}`);if(n===void 0)return null;let i=t.status===`connected`;return a(s,{children:[n.connect!==void 0&&!i&&a(A,{variant:`primary`,size:`sm`,"aria-label":r(`brokers.brokerManager.signIn`),onClick:()=>J(n.connect??``,t.id,p),title:r(`brokers.brokerManager.signInOpensAPopup`,`Sign in — opens a popup that closes when done`),children:[d(E,{className:`h-3 w-3`}),d(`span`,{className:`hidden sm:inline`,children:r(`brokers.brokerManager.signIn`)})]}),n.disconnect!==void 0&&i&&a(A,{variant:`outline`,size:`sm`,"aria-label":r(`brokers.brokerManager.signOut`),onClick:()=>J(n.disconnect??``,t.id,p),title:r(`brokers.brokerManager.signOutClearsTheLinked`,`Sign out — clears the linked Google account on this broker`),children:[d(T,{className:`h-3 w-3`}),d(`span`,{className:`hidden sm:inline`,children:r(`brokers.brokerManager.signOut`)})]})]})},showUpdated:!1,minWidthPx:340})}function ze(e){if(typeof e==`string`)return e;if(typeof e==`object`&&e){let t=e.name;if(typeof t==`string`)return t}return null}function Be(e){let t=e,n=t?.manifest;if(n?.id===void 0)return null;let r=(n.capabilities??[]).map(ze).filter(e=>e!==null);return{addonId:n.id,displayName:n.packageDisplayName??n.name??n.id,capNames:r,processState:t?.process?.state??null}}function Ve(e,t){return Object.entries(e).filter(([,e])=>e===t).map(([e])=>e)}function He(e,t){return t.find(t=>e.capNames.includes(t))??null}function Ue(e){switch(e){case`running`:return{state:`ok`,label:G.t(`helpers.connectivityModel.running`)};case`crashed`:case`failed`:return{state:`error`,label:e};case`stopped`:case`disabled`:return{state:`off`,label:G.t(`helpers.connectivityModel.stopped`)};default:return{state:`unknown`,label:e??G.t(`common.unknownWord`)}}}e();var We=[`wasteCollections`,`listSources`],Ge=[`wasteCollections`,`listCountries`];function Ke(e){return e instanceof Error?e.message:String(e)}function qe(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function Je(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(typeof n!=`object`||!n)continue;let e=Reflect.get(n,`id`),r=Reflect.get(n,`label`),i=Reflect.get(n,`module`);if(typeof e!=`string`||typeof r!=`string`||typeof i!=`string`)continue;let a=Reflect.get(n,`enabled`),o=Reflect.get(n,`formValues`),s=Reflect.get(n,`serviceId`),c=Reflect.get(n,`countryId`);t.push({id:e,label:r,module:i,enabled:typeof a==`boolean`?a:!0,formValues:typeof o==`object`&&o&&!Array.isArray(o)?o:void 0,serviceId:typeof s==`string`?s:void 0,countryId:typeof c==`string`?c:void 0})}return t}function Ye(e){return Array.isArray(e)?e.flatMap(e=>{if(typeof e!=`object`||!e)return[];let t=Reflect.get(e,`id`),n=Reflect.get(e,`label`);return typeof t!=`string`||typeof n!=`string`?[]:[{id:t,label:n}]}):[]}function Xe(e){return Array.isArray(e)?e.flatMap(e=>{if(typeof e!=`object`||!e)return[];let t=Reflect.get(e,`id`),n=Reflect.get(e,`label`),r=Reflect.get(e,`module`);if(typeof t!=`string`||typeof n!=`string`||typeof r!=`string`)return[];let i=Reflect.get(e,`title`);return[{id:t,label:n,title:typeof i==`string`&&i.length>0?i:n,module:r}]}):[]}function Ze(e,t,n){return{sections:[{id:`picker`,title:G.t(`system.wasteSettingsSources.countryService`,`Country & service`),columns:2,fields:[{type:`select`,key:`countryId`,label:G.t(`system.wasteSettingsSources.country`,`Country`),options:[{value:``,label:G.t(`system.wasteSettingsSources.selectCountry`,`Select country…`)},...e.map(e=>({value:e.id,label:e.label}))]},{type:`select`,key:`serviceId`,label:G.t(`system.wasteSettingsSources.service`,`Service`),options:[{value:``,label:n===``?G.t(`system.wasteSettingsSources.pickACountryFirst`,`Pick a country first`):G.t(`system.wasteSettingsSources.selectService`,`Select service…`)},...t.map(e=>({value:e.id,label:e.label}))]}]}]}}function Qe({addonId:e,capName:f}){let{t:m}=K(),h=b(),_=c(),v=ne(),y=fe({editKey:`wasteEdit`,newKey:`wasteNew`}),[x,S]=r(!1),[ee,C]=r(null),[w,T]=r({countryId:``,serviceId:``}),[E,D]=r({label:m(`system.wasteSettingsSources.newSource`,`New source`),enabled:!0}),O=l(null),k=typeof w.countryId==`string`?w.countryId:``,M=typeof w.serviceId==`string`?w.serviceId:``,N=i((t,n)=>h.trpcClient.addons.custom.mutate({addonId:e,action:t,input:n}),[e,h]),P=o({queryKey:[...We,e],queryFn:async()=>Je(await N(`listSources`,{}))}),re=o({queryKey:[...Ge,e],queryFn:async()=>Ye(await N(`listCountries`,{}))}),ie=o({queryKey:[`wasteCollections`,`listServices`,e,k],enabled:k!==``,queryFn:async()=>Xe(await N(`listServices`,{countryId:k}))}),F=o({queryKey:[`wasteCollections`,`serviceFormSchema`,e,M],enabled:M!==``,queryFn:async()=>N(`serviceFormSchema`,{serviceId:M})}),I=P.data??[],L=re.data??[],R=ie.data??[],z=qe(F.data)?F.data:void 0,ce=n(()=>Ze(L,k===``?[]:R,k),[L,R,k]),B=y.state,V=B.mode===`edit`?I.find(e=>e.id===B.id)??null:null;t(()=>{if(y.state.mode===`edit`&&V!==null){let e=`edit:${V.id}`;if(O.current===e)return;O.current=e,C(null),T({countryId:V.countryId??``,serviceId:V.serviceId??``}),D(V.formValues===void 0?{label:V.label,enabled:V.enabled}:{...V.formValues});return}if(y.state.mode===`new`){if(O.current===`new`)return;O.current=`new`,C(null),T({countryId:``,serviceId:``}),D({label:m(`system.wasteSettingsSources.newSource`,`New source`),enabled:!0})}},[V,y.state]),t(()=>{if(y.state.mode!==`new`||M===``)return;let e=R.find(e=>e.id===M);e&&D(t=>{let n=t.label;return typeof n==`string`&&n!==``&&n!==`New source`?t:{...t,label:e.title}})},[y.state.mode,M,R]);let le=i(e=>{T(t=>{let n=typeof e.countryId==`string`?e.countryId:``;return n===(typeof t.countryId==`string`?t.countryId:``)?e:{countryId:n,serviceId:``}})},[]),H=i(async()=>{await _.invalidateQueries({queryKey:We})},[_]),U=u({mutationFn:async e=>N(`deleteSource`,{id:e}),onSuccess:async()=>H()}),W=i(async e=>{await v({title:m(`system.wasteSettingsSources.deleteWasteSource`,`Delete waste source?`),message:m(`system.wasteSettingsSources.removeItsCalendarUnderSystem`,`Remove “{{label}}” ({{id}}). Its calendar under System → Calendars is dropped.`,{label:e.label,id:e.id}),confirmLabel:m(`common.delete`,`Delete`),cancelLabel:m(`common.cancel`,`Cancel`),variant:`danger`})&&(await U.mutateAsync(e.id),y.state.mode===`edit`&&y.state.id===e.id&&(y.close(),O.current=null))},[v,U,y,m]),ue=i(async()=>{let e=E.label,t=typeof e==`string`&&e.trim()!==``?e.trim():``;if(t===``){C(`Label is required.`);return}if(M===``){C(`Pick a country and a service.`);return}let n=y.state.mode===`new`,r=V?.id;if(!n&&(r===void 0||r===``)){C(`That source is no longer available.`);return}let i=E.enabled,a={...E};delete a.label,delete a.enabled,S(!0),C(null);try{n?await N(`createSource`,{label:t,serviceId:M,args:a,enabled:typeof i==`boolean`?i:!0}):r!==void 0&&await N(`updateSource`,{id:r,label:t,serviceId:M,args:a,enabled:typeof i==`boolean`?i:!0}),await H(),y.close(),O.current=null}catch(e){C(Ke(e))}finally{S(!1)}},[N,V,y,E,H,M]),de=n(()=>[{key:`label`,header:m(`system.wasteSettingsSources.label`,`Label`),sortValue:e=>e.label,render:e=>d(`span`,{className:`text-sm text-foreground`,children:e.label})},{key:`module`,header:m(`system.wasteSettingsSources.module`,`Module`),sortValue:e=>e.module,render:e=>d(`span`,{className:`font-mono text-xs text-foreground-muted`,children:e.module})},{key:`enabled`,header:m(`system.wasteSettingsSources.enabled`,`Enabled`),sortValue:e=>+!!e.enabled,render:e=>d(j,{variant:e.enabled?`success`:`default`,children:e.enabled?m(`system.wasteSettingsSources.on`,`On`):m(`system.wasteSettingsSources.off`,`Off`)})},{key:`actions`,header:``,notSortableReason:`actions`,render:e=>d(A,{type:`button`,size:`sm`,variant:`ghost`,"aria-label":m(`system.wasteSettingsSources.delete`,`Delete {{label}}`,{label:e.label}),"data-testid":`waste-source-delete-${e.id}`,onClick:t=>{t.stopPropagation(),W(e)},children:d(p,{className:`h-3.5 w-3.5 text-danger`})})}],[W,m]),G=y.state.mode===`new`,q=G||V!==null,me=`${M}:${G?`new`:V?.id??`closed`}`;return a(`div`,{className:`flex min-h-0 flex-col gap-4`,"data-testid":`waste-settings-sources`,children:[a(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[d(`p`,{className:`text-sm text-foreground-muted`,children:m(`system.wasteSettingsSources.pickACountryAndA`,`Pick a country and a service — configuration fields come from that HACS source.`)}),a(A,{type:`button`,size:`sm`,"data-testid":`waste-sources-add`,onClick:()=>y.openNew(),children:[d(g,{className:`h-3.5 w-3.5`}),m(`system.wasteSettingsSources.addSource`,`Add source`)]})]}),P.isError?d(`p`,{className:`text-sm text-danger`,children:m(`system.wasteSettingsSources.couldNotLoadSources`,`Could not load sources.`)}):null,P.isPending?d(pe,{className:`h-32 w-full`}):d(se,{columns:de,rows:I,rowKey:e=>e.id,pageSize:25,emptyMessage:m(`system.wasteSettingsSources.noWasteSourcesYetAdd`,`No waste sources yet. Add one to register a municipal service.`),onRowClick:e=>y.openEdit(e.id),defaultSort:{columnKey:`label`,dir:`asc`}}),d(oe,{open:q,onClose:()=>{y.close(),C(null),O.current=null},title:G?m(`system.wasteSettingsSources.addWasteSource`,`Add waste source`):m(`system.wasteSettingsSources.edit`,`Edit {{value1}}`,{value1:V?.label??`source`}),icon:te,width:`xl`,testId:`waste-source-editor`,error:ee,footer:d(A,{type:`button`,size:`sm`,disabled:x||M===``,onClick:()=>void ue(),children:x?m(`system.wasteSettingsSources.saving`,`Saving…`):m(`common.save`,`Save`)}),children:q?a(s,{children:[d(`div`,{"data-testid":`waste-country-service`,children:d(ae,{schema:ce,values:w,onChange:le},`picker:${k}:${R.length}`)}),M!==``&&z!==void 0?d(ae,{schema:z,values:E,onChange:D,bare:!0},me):M!==``&&F.isPending?d(`p`,{className:`text-sm text-foreground-muted`,children:m(`system.wasteSettingsSources.loadingFields`,`Loading fields…`)}):d(`p`,{className:`text-sm text-foreground-muted`,children:m(`system.wasteSettingsSources.chooseACountryAndService`,`Choose a country and service to see the required fields.`)})]}):null}),d(be,{nodeId:`hub`,addonIds:[e],level:`global`,capability:f,hideSectionChrome:!0})]})}e();var $e=1e4,et={"device-export":`exporters`,exporters:`exporters`,email:`email`,broker:`brokers`,brokers:`brokers`,"message-brokers":`brokers`,calendar:`calendars`,calendars:`calendars`,"calendar-source":`calendars`},tt=[{sectionId:`exporters`,kind:`device-export`,labelKey:`system.connectivity.exporters`,icon:_,installLabelKey:`system.connectivity.exportersInstall`,emptyTitleKey:`system.connectivity.exportersEmptyTitle`,emptyDescriptionKey:`system.connectivity.exportersEmptyDescription`},{sectionId:`email`,kind:`email`,labelKey:`system.connectivity.email`,icon:v,installLabelKey:`system.connectivity.emailInstall`,emptyTitleKey:`system.connectivity.emailEmptyTitle`,emptyDescriptionKey:`system.connectivity.emailEmptyDescription`},{sectionId:`brokers`,kind:`broker`,labelKey:`system.connectivity.brokers`,icon:x,installLabelKey:`system.connectivity.brokersInstall`,emptyTitleKey:`system.connectivity.brokersEmptyTitle`,emptyDescriptionKey:`system.connectivity.brokersEmptyDescription`},{sectionId:`calendars`,kind:`calendar`,labelKey:`system.connectivity.calendars`,icon:w,installLabelKey:`system.connectivity.calendarsInstall`,emptyTitleKey:`system.connectivity.calendarsEmptyTitle`,emptyDescriptionKey:`system.connectivity.calendarsEmptyDescription`}];function nt(e,t,n,r){let i=Ve(S,e.kind),o=t.flatMap(t=>{let r=He(t,i);if(r===null)return[];let o=Ue(t.processState);return[{id:t.addonId,name:t.displayName,fallbackIcon:e.icon,state:o.state,stateLabel:o.label,render:()=>d(xe,{addonId:t.addonId,displayName:t.displayName,capName:r,isActive:t.processState===`running`,badges:a(s,{children:[d(ot,{processState:t.processState}),d(st,{kind:e.kind,addonId:t.addonId})]}),lead:e.kind===`device-export`?d(k,{addonId:t.addonId}):void 0,panels:at(e.kind,t.addonId,e=>n(`/devices/${e}`)),settingsContent:t.addonId===`waste-collections`?d(Qe,{addonId:t.addonId,capName:r}):void 0})}]});return{id:e.sectionId,label:r(e.labelKey),entries:o,install:{capability:i[0]??e.kind,label:r(e.installLabelKey)}}}function rt({descriptor:e,rows:t,isLoading:r}){let{t:i}=K(),a=me(),o=n(()=>nt(e,t,a,i),[e,t,a,i]);return d(Se,{embedded:!0,icon:e.icon,title:i(e.labelKey),subtitle:null,groups:[o],isLoading:r,emptyTitle:i(e.emptyTitleKey),emptyDescription:i(e.emptyDescriptionKey)})}function it(){let{t:e}=K(),r=de(void 0,{refetchInterval:$e}),[i,a]=ge(),o=q(`/system/integrations`,{t:e,isAdmin:!0})??{icon:m,title:e(`admin.system.integrations.connectivity`,`Connectivity`)};t(()=>{let e=i.get(`tab`);if(e===null)return;let t=et[e];t===void 0||t===e||a(e=>{let n=new URLSearchParams(e);return n.set(`tab`,t),n},{replace:!0})},[i,a]);let s=n(()=>(r.data??[]).map(Be).filter(e=>e!==null),[r.data]),c=n(()=>tt.map(t=>({id:t.sectionId,label:e(t.labelKey),ownedParams:he,content:d(rt,{descriptor:t,rows:s,isLoading:r.isLoading})})),[r.isLoading,s,e]);return d(ve,{icon:o.icon,title:o.title,subtitle:e(`admin.system.integrations.externalSystemsThisHubTalks`,`External systems this hub talks to — exporters, email, brokers and calendar sources.`),defaultSection:`exporters`,sectionsLabel:`Connectivity sections`,sections:c})}function at(e,t,n){return e===`device-export`?[{id:`devices`,title:G.t(`admin.system.integrations.devices`,`Devices`),icon:D,placement:`end`,content:d(P,{addonId:t,onOpenDevice:n,showSetup:!1})}]:e===`broker`?[{id:`connections`,title:G.t(`admin.system.integrations.connections`,`Connections`),icon:x,content:d(Le,{addonId:t,fallback:d(Ie,{addonId:t})})}]:[]}function ot({processState:e}){let{state:t,label:n}=Ue(e);return d(j,{variant:t===`ok`?`success`:t===`error`?`danger`:`default`,className:`${Y} capitalize`,children:n})}function st({kind:e,addonId:t}){return e===`broker`?d(ct,{addonId:t}):e===`device-export`?d(lt,{addonId:t}):null}function ct({addonId:e}){let{t}=K(),{data:n}=M({addonId:e},{refetchInterval:$e,retry:!1}),r=ee.safeParse(n);if(!r.success)return null;let{brokerCount:i,connectedCount:a}=r.data;return d(j,{variant:`info`,className:Y,children:a>0?t(`system.connectivity.connectionsConnected`,{count:i,connected:a}):t(`system.connectivity.connections`,{count:i})})}function lt({addonId:e}){let{t}=K(),{data:n}=N({addonId:e},{refetchInterval:$e,retry:!1}),r=C.safeParse(n);if(!r.success)return null;let{linkState:i,exposedDeviceCount:a}=r.data;return d(j,{variant:i===`linked`?`success`:i===`error`?`danger`:`default`,className:Y,children:t(`admin.system.integrations.exposed`,`{{linkState}} · {{exposedDeviceCount}} exposed`,{linkState:i,exposedDeviceCount:a})})}export{it as IntegrationsPage};
@@ -1 +0,0 @@
1
- import{$ as e,B as t,G as n,J as r,L as i,S as a,b as o,o as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Cn as l,Di as u,On as d,Si as f,bn as p,dt as m,fn as h,kn as g,or as _,ot as v,un as y,xi as b,yi as x}from"./player-overlays-BIvElXhE.js";import{At as S,Dt as C,Ku as ee,Ma as te,Ot as ne,Qr as w,Ru as T,Wa as E,Wo as D,Yo as O,qo as k,r as A,rt as j,to as M}from"./src-WNMGrUfA.js";import{t as N}from"./i18n-SRLxy4I7.js";import{t as P}from"./useTranslation-D3Is_4B6.js";import{_r as F,fr as I,yr as L}from"./index-CfXsU3sZ.js";import{t as R}from"./AdminPage-oFm0hhFj.js";import"./useEventInvalidation-D7ZJEJ81.js";import{t as re}from"./device-integration-icon-B_6sNK4Z.js";import{n as z,r as B,t as ie}from"./ScanNetworkModal-DFuZaP78.js";e();function V(e=!0){t(()=>{if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=t}},[e])}e();function ae(e,n){let[i,a]=r(!1);return t(()=>{if(!e){a(!1);return}a(!1);let t=setTimeout(()=>a(!0),n);return()=>clearTimeout(t)},[e,n]),i}e();function H({providerId:e,onImport:n,onSkip:i}){let{t:o}=P(),[s,l]=r(new Set),d=E(),p=d.data,m=d.isPending||!d.data&&!d.isError;t(()=>{e&&(d.isPending||d.data||d.mutate({addonId:e}))},[e,d]);function h(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(m)return a(`div`,{className:`flex flex-col items-center py-12`,children:[c(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),c(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:o(`integrations.searchingDevices`)})]});let g=p??[];return a(`div`,{className:`space-y-4`,children:[c(`p`,{className:`text-xs text-foreground-subtle`,children:g.length>0?o(`integrations.foundDevices`,{count:g.length}):o(`integrations.noDevicesFound`)}),g.length>0&&c(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:g.map(e=>{let t=e.stableId,n=e.suggestedName??t,r=s.has(t),i=e.alreadyOnboarded===!0;return a(`button`,{onClick:()=>{i||h(t)},disabled:i,title:i?o(`integrations.alreadyAddedHint`,{defaultValue:`Already added as "{{name}}" — re-adding would overwrite its settings.`,name:e.onboardedName??n}):void 0,className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${i?`border-border bg-surface opacity-60 cursor-not-allowed`:r?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[c(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${r&&!i?`border-primary bg-primary`:`border-border`}`,children:r&&!i&&c(f,{className:`h-3 w-3 text-primary-foreground`})}),c(u,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),c(`span`,{className:`text-xs font-medium text-foreground truncate`,children:n}),i&&c(`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:o(`integrations.alreadyAdded`,{defaultValue:`Already added`})})]},t)})}),a(`div`,{className:`flex items-center justify-between pt-2`,children:[c(`button`,{onClick:i,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:o(`integrations.skip`)}),g.length>0&&a(`button`,{onClick:()=>n(Array.from(s)),disabled:s.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:[o(`integrations.importSelected`),` (`,s.size,`)`]})]})]})}e();function U({onSelect:e,onClose:t,pendingAddonId:i=null}){let{t:o}=P(),s=F(),[l,u]=r(``),{data:d,isLoading:f}=k(),p=n(()=>{let e=d??[],t=l.trim().toLowerCase();return t.length===0?e:e.filter(e=>`${e.name} ${e.description??``} ${e.addonId}`.toLowerCase().includes(t))},[d,l]);if(f)return c(`div`,{className:`grid grid-cols-2 gap-2 p-2`,children:[1,2,3,4].map(e=>c(`div`,{className:`h-24 rounded-lg bg-surface animate-pulse`},e))});let m=i!==null;return a(`div`,{className:`space-y-3`,"data-testid":`provider-picker`,children:[a(`div`,{className:`relative`,children:[c(h,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-foreground-subtle`,"aria-hidden":!0}),c(T,{type:`search`,value:l,onChange:e=>u(e.target.value),placeholder:o(`integrations.searchProviders`,`Search integrations…`),className:`pl-8`,"data-testid":`provider-picker-search`,"aria-label":o(`integrations.searchProviders`,`Search integrations…`)})]}),c(`div`,{className:`grid grid-cols-2 gap-2`,children:p.map(n=>{let r=n.instanceMode===`unique`&&n.existingInstances.length>0,l=i===n.addonId,u=m;return a(`button`,{type:`button`,disabled:u,"data-testid":`provider-pick-${n.addonId}`,onClick:()=>{if(!u)if(r){let e=n.existingInstances[0].id;t(),s(`/integrations/${e}`)}else e(n.addonId,n.instanceMode,n.discoveryMode,n.name,n.kind,n.brokerKind,n.mode,n.canTest)},className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-center text-xs hover:border-primary/50 hover:bg-surface-hover transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[n.iconUrl?c(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${n.color}15`},children:c(`img`,{src:n.iconUrl,alt:``,className:`h-5 w-5`})}):c(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${n.color}15`},children:c(`span`,{className:`text-sm`,style:{color:n.color},children:`◉`})}),c(`p`,{className:`w-full truncate text-xs font-semibold text-foreground`,children:n.name}),n.description?c(`p`,{className:`w-full line-clamp-2 text-[10px] text-foreground-subtle`,children:n.description}):null,l?c(_,{className:`h-4 w-4 animate-spin text-primary`}):r?a(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[c(y,{className:`h-3 w-3`}),o(`integrations.manage`)]}):null]},n.addonId)})}),p.length===0&&c(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:(d??[]).length===0?o(`integrations.noProviders`):o(`integrations.noProvidersMatch`,`No integrations match your search.`)})]})}e();function oe(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}var W=2e4;function se({open:e,onClose:i}){let{t:l}=P(),u=F(),d=s(),[f,p]=r(`picker`),[h,g]=r(null),[v,y]=r(null),[b,x]=r(`manual`),[S,C]=r(null),[ee,ne]=r(``),[T,O]=r(null),[k,A]=r(null),[j,M]=r(!1),{data:N}=w({addonId:h??``,nodeId:`hub`},{enabled:h!=null}),I=n(()=>N?oe(N):null,[N]),L=D({onSuccess:()=>d.invalidateQueries({queryKey:[[`integrations`]]})}),R=E(),re=R.data;t(()=>{f!==`discovery`||!v||!h||R.isPending||R.data||R.mutate({addonId:h})},[f,v,h,R]);let ie=te({onSuccess:()=>d.invalidateQueries({queryKey:[[`deviceManager`]]})});function se(e,t,n,r,i,a,o,s){if(!L.isPending){if(g(e),M(s),x(n),ne(r),A(null),o===`broker`){if(!a){A(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}C(a),p(`broker`);return}if(o===`account`){p(`config`);return}G(e,r)}}async function G(e,t){try{let n=await L.mutateAsync({addonId:e,name:t,settings:{}});i(),J(),u(`/integrations/${n.id}?add=1`)}catch{}}async function ce(e){if(h)try{let t=await L.mutateAsync({addonId:h,name:e.name,settings:e.config,secretKeys:[...e.secretKeys]});y(t.id),O(t.id),b===`auto`||b===`both`?p(`discovery`):q(t.id,{openAdd:!0})}catch{}}async function le(e){if(h)try{let t=await L.mutateAsync({addonId:h,name:ee,settings:{brokerId:e}});O(t.id),y(t.id),q(t.id)}catch{}}async function K(e){if(h){for(let t of e){let e=re?.find(e=>e.stableId===t);e&&await ie.mutateAsync({addonId:h,candidate:e,...T===null?{}:{integrationId:T}})}q()}}function q(e,t){let n=e??v??h;i(),J(),n&&u(t?.openAdd===!0?`/integrations/${n}?add=1`:`/integrations/${n}`)}function J(){p(`picker`),g(null),y(null),x(`manual`),C(null),ne(``),O(null),A(null),M(!1)}function Y(){i(),J()}V(e);let X=L.isPending,Z=ae(X,W);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,$=L.error,de=X&&!Z;return a(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:de?void 0:Y}),a(`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:[a(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:ue[f]}),c(`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:c(m,{className:`h-4 w-4`})})]}),a(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[$&&!X&&c(`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`&&a(o,{children:[k&&c(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:k}),c(U,{onSelect:se,onClose:Y,pendingAddonId:Q})]}),f===`config`&&h&&c(z,{addonId:h,configSchema:I??null,canTest:j,onSave:ce,onBack:()=>p(`picker`)}),f===`broker`&&S&&c(B,{kind:S,onResolved:e=>{le(e)},onBack:()=>p(`picker`)}),f===`discovery`&&v&&c(H,{providerId:v,onImport:K,onSkip:q})]}),X&&a(`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:[c(_,{className:`h-6 w-6 animate-spin text-primary`}),c(`p`,{className:`text-xs font-medium text-foreground`,children:l(`integrations.creating`,{defaultValue:`Creating integration…`})}),!Z&&c(`p`,{className:`text-[10px] text-foreground-subtle`,children:l(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),Z&&a(o,{children:[c(`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.`})}),c(`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 G({integration:e,expanded:t,onToggleExpand:n}){let{t:r}=P();return a(`div`,{className:`flex items-center gap-2.5`,children:[c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),n(e.addonId)},"aria-label":t?r(`integrations.integrationColumns.collapse`,`Collapse`):r(`integrations.integrationColumns.expand`,`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:c(t?b:x,{className:`h-3.5 w-3.5`})}),c(I,{type:e.addonId,size:`sm`}),a(`div`,{className:`flex min-w-0 flex-col`,children:[c(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),c(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function ce(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:N.t(`integrations.integrationColumns.integration`,`Integration`),headerClassName:`w-[55%]`,cell:e=>c(G,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:N.t(`integrations.integrationColumns.devices`,`Devices`),headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>N.t(`integrations.integrationColumns.deviceCount`,{count:e.deviceCount})},{key:`status`,header:N.t(`integrations.integrationColumns.status`,`Status`),headerClassName:`w-[15%]`,cell:e=>c(j,{status:e.status})}]}e();function le(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var K=`expand`;function q(){let{t:e}=P(),t=F(),s=v(),[u]=L(),[f,m]=r(!1),h=i(()=>m(!0),[]),_=i(()=>m(!1),[]),[y,b]=r(!1),x=i(()=>b(!0),[]),te=i(()=>b(!1),[]);A([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),A([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:w,isLoading:T,refetch:E}=O(void 0),{data:D,isLoading:k,refetch:j}=M({projection:`slim`}),N=n(()=>D??[],[D]),I=n(()=>w??[],[w]),z=n(()=>{let e=new Map;for(let t of N)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[N]),B=n(()=>ne(w),[w]),V=n(()=>{let e=new Map;for(let t of S(N)){let n=B(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[N,B]),ae=n(()=>I.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:le(e),deviceCount:V.get(e.id)??0})),[I,V]),H=u.get(K),U=i(e=>{let t=new URLSearchParams(window.location.search);t.get(K)===e?t.delete(K):t.set(K,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`))},[]),oe=i(e=>t(`/integrations/${e.id}`),[t]),W=i(e=>z.get(e)??null,[z]),G=i(e=>t(`/devices/${String(e)}`),[t]),q=i(e=>c(C,{context:`integration-detail`,devices:N,trpc:s.trpcClient,integrationOf:B,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:re,resolveParent:W,onNavigate:G}),[N,s.trpcClient,B,W,G]),J=i(e=>H===e.addonId,[H]),Y=n(()=>ce({isExpanded:J,onToggleExpand:U}),[J,U]),X=i(e=>`${e.name} ${e.addonId}`,[]),Z=i(e=>e.addonId,[]),ue=i(()=>{E(),j()},[E,j]),Q=T||k,$=I.length>0;return a(R,{icon:d,title:e(`nav.integrations`,`Integrations`),actions:a(o,{children:[c(`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:e(`common.refresh`,`Refresh`),children:c(p,{className:ee(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),a(`button`,{onClick:x,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:e(`integrations.scanTheLocalNetworkFor`,`Scan the local network for devices`),children:[c(l,{className:`h-3.5 w-3.5`}),e(`integrations.scanNetwork`,`Scan network`)]}),a(`button`,{onClick:h,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:[c(g,{className:`h-3.5 w-3.5`}),e(`integrations.newIntegration`,`New Integration`)]})]}),children:[Q&&c(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>c(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!$&&a(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[c(`p`,{className:`text-sm`,children:e(`integrations.noIntegrationsConfigured`,`No integrations configured.`)}),c(`p`,{className:`text-xs mt-1`,children:e(`integrations.clickNewIntegrationToConnect`,`Click "New Integration" to connect cameras and devices.`)})]}),!Q&&$&&c(C,{mode:`generic`,items:ae,getKey:Z,getSearchText:X,columns:Y,onRowClick:oe,isExpanded:J,renderExpanded:q,searchPlaceholder:e(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:e(`integrations.empty`,{defaultValue:`No integrations found.`})}),c(se,{open:f,onClose:_}),c(ie,{open:y,onClose:te})]})}export{q as IntegrationsPage};
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./browser-BHo8W_uH.js","./rolldown-runtime-Cyuzqnbw.js"])))=>i.map(i=>d[i]);
2
- import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{t}from"./vite-preload-helper-kNaey6uv.js";import{$ as n,B as r,G as i,J as a,S as o,a as s,b as c,q as l,t as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{$t as f,Fn as p,Gi as m,It as h,Nt as g,Q as _,Rr as v,Zr as y,hi as b,lr as x,mi as S,mr as C,or as w,ot as T,rr as E,sa as D,sn as O}from"./player-overlays-BIvElXhE.js";import{Dr as k,Er as A}from"./client-CNqHea-r.js";import{s as j}from"./video-D0GPir6r.js";import{t as ee}from"./key-round-DX4Tm3r5.js";import{t as te}from"./monitor-smartphone-DWtxkkEg.js";import{t as ne}from"./unlink-DUoBRhNd.js";import{Er as re,Fr as M,Nr as N,Nu as ie,cn as ae,er as P,gs as F,id as I,ms as oe,tr as se,wt as ce}from"./src-WNMGrUfA.js";import{t as le}from"./i18n-SRLxy4I7.js";import{t as L}from"./useTranslation-D3Is_4B6.js";import"./mount-D7ZJEJ81.js";import{C as R,S as z,b as B,gr as V,ir as H,mr as U,x as W,yr as ue}from"./index-CfXsU3sZ.js";import{t as de}from"./AdminSectionedPage-CXL0Cc0w.js";import{t as fe}from"./AdminPage-oFm0hhFj.js";import{O as pe,T as me,_ as G,a as he,h as ge,k as _e,r as ve,t as ye,v as be}from"./SessionsList-C3EfpYvC.js";n();var xe=`${A}/connect`,K={public:0,mesh:1,lan:2,"lan-ipv6":3};function Se(e){switch(e.kind){case`public`:return e.interfaceKind===`vpn`?`mesh`:`public`;case`lan-ipv4`:return`lan`;case`lan-ipv6`:return`lan-ipv6`;case`custom`:return`public`;case`loopback`:case`app-link`:return null}}function q(e){return k(e)}function Ce(e){return e.startsWith(`https://`)}function we(e){let t=e.flatMap(e=>{let t=Se(e),n=q(e.baseUrl);return t===null||n===null?[]:[{endpoint:e,tier:t,origin:n}]}).toSorted((e,t)=>K[e.tier]-K[t.tier]||Number(t.endpoint.plausible)-Number(e.endpoint.plausible)||e.endpoint.priority-t.endpoint.priority),n=new Set;return t.flatMap(({endpoint:e,tier:t,origin:r})=>n.has(r)?[]:(n.add(r),[{origin:r,label:e.label,tier:t,secure:Ce(r),plausible:e.plausible}]))}function Te(e,t,n=null){for(let r of[t,n]){if(r===null)continue;let t=q(r),n=e.find(e=>e.origin===t);if(n!==void 0)return n}return e[0]??null}function Ee(e){let t=new URL(xe);return t.searchParams.set(`hub`,e),t.toString()}var De=176,J={scheme:`https`};function Oe(){let{t:e}=L(),t=F(J),n=oe(J).data?.roles.publicEndpoint.resolved??null;return o(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[o(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[d(f,{className:`h-3.5 w-3.5 text-foreground-subtle`}),d(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`connectPhone.title`)})]}),o(`div`,{className:`p-4 space-y-3`,children:[d(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`connectPhone.description`)}),t.isPending?o(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[d(w,{className:`h-3.5 w-3.5 animate-spin`}),e(`connectPhone.loading`)]}):t.isError?o(`div`,{className:`flex items-start gap-2 text-[11px] text-danger`,children:[d(g,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),o(`div`,{className:`flex-1 min-w-0 space-y-1.5`,children:[d(`div`,{className:`break-words`,children:e(`connectPhone.error`,{message:t.error.message})}),d(M,{size:`sm`,variant:`ghost`,onClick:()=>void t.refetch(),children:e(`connectPhone.retry`)})]})]}):d(ke,{candidates:we(t.data.endpoints),preferredOrigin:n})]})]})}function ke({candidates:e,preferredOrigin:t}){let{t:n}=L(),[r,s]=a(null),c=Te(e,r,t),l=i(()=>c?Ee(c.origin):null,[c]);if(c===null||l===null)return d(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`connectPhone.empty`)});let u=e=>n(`connectPhone.tier.${e}`),f=e.map(e=>({value:e.origin,label:`${u(e.tier)} — ${e.origin}`}));return o(`div`,{className:`flex flex-col sm:flex-row gap-4`,children:[d(P,{value:l,size:De,alt:n(`connectPhone.qrAlt`),className:`self-start`}),o(`div`,{className:`flex-1 min-w-0 space-y-3`,children:[o(`label`,{className:`block space-y-1`,children:[d(`span`,{className:`text-[11px] font-medium text-foreground`,children:n(`connectPhone.addressLabel`)}),d(ie,{value:c.origin,options:f,onChange:e=>s(e.target.value)}),o(`span`,{className:`block text-[10px] text-foreground-subtle`,children:[u(c.tier),` · `,c.label]})]}),!c.secure&&d(Y,{text:n(`connectPhone.insecure`)}),!c.plausible&&d(Y,{text:n(`connectPhone.implausible`)}),o(`div`,{className:`space-y-1`,children:[d(`span`,{className:`text-[11px] font-medium text-foreground`,children:n(`connectPhone.linkLabel`)}),o(`div`,{className:`flex items-center gap-1 rounded-md border border-border bg-background px-2 py-1`,children:[d(`code`,{className:`flex-1 min-w-0 font-mono text-[11px] text-foreground break-all select-all`,children:l}),d(ae,{value:l,srLabel:n(`connectPhone.linkLabel`)})]})]}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`connectPhone.signInHint`)})]})]})}function Y({text:e}){return o(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-2.5 py-1.5 text-[11px] text-foreground`,children:[d(g,{className:`h-3.5 w-3.5 text-warning mt-0.5 shrink-0`}),d(`span`,{children:e})]})}n();function Ae(e){return new Date(e).toLocaleDateString()}function je(){let{t:e}=L(),t=N(),n=I.useUtils(),i=I.auth.listLinkableProviders.useQuery(),s=I.auth.listOwnExternalIdentities.useQuery(),[c,u]=a(null),[f,p]=a(()=>R(window.location.search)),m=l(null),h=G(`Linking a sign-in account`),g=l(null);r(()=>()=>g.current?.(),[]);let[v,y]=a(null);r(()=>{if(f===null)return;let e=new URL(window.location.href);e.searchParams.delete(`linked`),e.searchParams.delete(`linkError`),window.history.replaceState({},``,e.pathname+e.search+e.hash)},[f]);let C=I.auth.beginExternalLink.useMutation({onSuccess:({url:e})=>{let t=m.current;if(m.current=null,t===null||t.closed){window.location.assign(e);return}let r=e=>{y(null),p(R(`?${e}`)),n.auth.listOwnExternalIdentities.invalidate()};g.current?.(),g.current=W(t,{onReturn:e=>{e.target===`profile`&&r(e.query)},onDone:e=>{e.target===`profile`&&r(e.query)},onClosed:()=>{g.current?.(),g.current=null,n.auth.listOwnExternalIdentities.invalidate()}}),t.location.href=_(z(e))},onError:e=>{m.current?.close(),m.current=null,y(null),u(e.message)}}),T=I.auth.unlinkOwnExternalIdentity.useMutation({onSuccess:()=>void n.auth.listOwnExternalIdentities.invalidate(),onError:e=>u(e.message)}),E=i.data??[],D=s.data??[],O=v!==null&&D.some(e=>e.provider===v);if(r(()=>{!O||v===null||(y(null),p({kind:`linked`,provider:v}))},[O,v]),E.length===0&&D.length===0)return null;let k=new Set(D.map(e=>e.provider)),A=e=>E.find(t=>t.provider===e)?.label??e,j=async(n,r)=>{await t({title:e(`users.linkedSignInsSection.unlinkSignInAccount`,`Unlink sign-in account`),message:e(`users.linkedSignInsSection.stopSigningInWithThis`,`Stop signing in with this {{label}} account?`,{label:r}),confirmLabel:e(`users.linkedSignInsSection.unlink`,`Unlink`),variant:`danger`})&&(u(null),T.mutate({provider:n.provider,subject:n.subject}))};return o(`div`,{"data-testid":`linked-sign-ins`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[h.dialog,o(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[d(x,{className:`h-3.5 w-3.5 text-foreground-subtle`}),d(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`users.linkedSignInsSection.linkedSignInAccounts`,`Linked sign-in accounts`)})]}),o(`div`,{className:`p-4 space-y-3`,children:[d(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`users.linkedSignInsSection.signInWithAnExternal`,`Sign in with an external account instead of your password. Only accounts you link here can sign you in; your two-factor authentication still applies.`)}),f?.kind===`linked`&&o(`div`,{className:`flex items-center gap-2 rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2 text-xs text-foreground`,children:[d(S,{className:`h-3.5 w-3.5 text-emerald-500 shrink-0`}),e(`users.linkedSignIns.linkedNotice`,{provider:A(f.provider)})]}),(f?.kind===`error`||c)&&o(`div`,{className:`flex items-center gap-2 rounded-md border border-danger/20 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[d(b,{className:`h-3.5 w-3.5 shrink-0`}),c??(f?.kind===`error`?f.message:``)]}),D.length>0&&d(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:D.map(t=>{let n=t.providerLabel??t.provider;return o(`li`,{className:`flex items-center gap-3 px-3 py-2 text-xs`,children:[o(`div`,{className:`flex-1 min-w-0`,children:[o(`div`,{className:`font-medium text-foreground truncate`,children:[n,!t.available&&d(`span`,{className:`ml-2 rounded bg-foreground-subtle/15 px-1.5 py-0.5 text-[10px] font-normal text-foreground-subtle`,children:e(`users.linkedSignInsSection.providerUnavailable`,`provider unavailable`)})]}),d(`div`,{className:`text-[11px] text-foreground-subtle truncate`,children:e(`users.linkedSignIns.linkedOn`,{label:t.label??t.subject,date:Ae(t.linkedAt)})})]}),o(`button`,{onClick:()=>void j(t,n),disabled:T.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:[d(ne,{className:`h-3 w-3`}),e(`users.linkedSignInsSection.unlink`,`Unlink`)]})]},`${t.provider}|${t.subject}`)})}),d(`div`,{className:`flex flex-wrap gap-2`,children:E.filter(e=>!k.has(e.provider)).map(t=>o(`button`,{onClick:()=>{u(null),p(null),h.requestProof().then(e=>{e!==null&&(m.current=B(null),y(m.current===null?null:t.provider),C.mutate({provider:t.provider,reauthToken:e}))})},disabled:C.isPending,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1 text-[11px] font-medium text-foreground hover:bg-surface-hover disabled:opacity-50`,children:[C.isPending&&C.variables?.provider===t.provider?d(w,{className:`h-3 w-3 animate-spin`}):d(x,{className:`h-3 w-3`}),e(`users.linkedSignIns.link`,{provider:t.label})]},t.provider))})]})]})}n();function Me({value:n,size:i=192}){let{t:s}=L(),[c,l]=a(null),[u,f]=a(null);if(r(()=>{let r=!1;return t(()=>import(`./browser-BHo8W_uH.js`).then(t=>e(t.default,1)).then(async e=>{if(r)return;let t=e.create;if(typeof t!=`function`){f(`qrcode.create() unavailable in installed version`);return}try{let e=t(n,{errorCorrectionLevel:`M`});r||l(e)}catch(e){r||f(e instanceof Error?e.message:`QR generation failed`)}}),__vite__mapDeps([0,1]),import.meta.url).catch(()=>{r||f(`qrcode library not installed`)}),()=>{r=!0}},[n]),u)return d(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle text-center p-4`,style:{width:i,height:i},children:s(`users.totpQrCode.qrRenderingUnavailableUseThe`,`QR rendering unavailable — use the secret below.`)});if(!c)return d(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle animate-pulse`,style:{width:i,height:i},children:s(`users.totpQrCode.generating`,`Generating…`)});let p=c.modules.size,m=i/p,h=[];for(let e=0;e<p;e++)for(let t=0;t<p;t++)c.modules.data[e*p+t]&&h.push(d(`rect`,{x:t*m,y:e*m,width:m,height:m,fill:`currentColor`},`${t}-${e}`));return o(`svg`,{width:i,height:i,viewBox:`0 0 ${i} ${i}`,className:`text-black`,children:[d(`rect`,{x:0,y:0,width:i,height:i,fill:`white`}),h]})}n();function Ne(){let{t:e}=L(),t=T(),[n,r]=a(``),[i,s]=a(``),[c,l]=a(``),[f,p]=a(null),m=u({mutationFn:e=>t.changeOwnPassword(e),onSuccess:()=>{p({kind:`success`,msg:`Password updated.`}),r(``),s(``),l(``)},onError:e=>{p({kind:`error`,msg:e instanceof Error?e.message:`Update failed`})}}),h=i.length>0&&c.length>0&&i!==c,g=i.length>0&&i.length<8,_=n.length>=1&&i.length>=8&&i===c;return o(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[o(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[d(ee,{className:`h-3.5 w-3.5 text-foreground-subtle`}),d(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`systemPage.myAccess.changePassword`,`Change password`)})]}),o(`div`,{className:`p-4 space-y-3`,children:[d(X,{label:e(`systemPage.myAccess.currentPassword`,`Current password`),value:n,onChange:r,autoComplete:`current-password`}),d(X,{label:e(`systemPage.myAccess.newPassword`,`New password`),value:i,onChange:s,autoComplete:`new-password`,hint:e(`systemPage.myAccess.atLeast8Characters`,`At least 8 characters.`)}),d(X,{label:e(`systemPage.myAccess.confirmNewPassword`,`Confirm new password`),value:c,onChange:l,autoComplete:`new-password`}),(h||g)&&d(`div`,{className:`text-[11px] text-danger`,children:h?e(`systemPage.myAccess.passwordsDoNotMatch`,`Passwords do not match.`):e(`systemPage.myAccess.newPasswordMustBeAt`,`New password must be at least 8 characters.`)}),f&&o(`div`,{className:`text-[11px] flex items-center gap-1 ${f.kind===`success`?`text-success`:`text-danger`}`,children:[f.kind===`success`?d(S,{className:`h-3 w-3`}):d(b,{className:`h-3 w-3`}),f.msg]}),d(`div`,{className:`flex justify-end`,children:o(M,{onClick:()=>{p(null),m.mutate({currentPassword:n,newPassword:i})},disabled:!_||m.isPending,children:[m.isPending?d(w,{className:`h-3 w-3 animate-spin`}):d(E,{className:`h-3 w-3`}),e(`systemPage.myAccess.updatePassword`,`Update password`)]})})]})]})}function X({label:e,value:t,onChange:n,autoComplete:r,hint:i}){return o(`div`,{className:`space-y-1`,children:[d(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e}),d(`input`,{type:`password`,value:t,onChange:e=>n(e.target.value),autoComplete:r,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),i&&d(`div`,{className:`text-[10px] text-foreground-subtle`,children:i})]})}function Pe({username:e}){let{t}=L(),n=T(),l=s({queryKey:[`auth`,`getOwnTotpStatus`],queryFn:()=>n.getOwnTotpStatus()}),p=l.data,[m,h]=a(null),[g,_]=a(``),[v,x]=a(null),[C,E]=a(!1),D=u({mutationFn:()=>n.setupOwnTotp(),onSuccess:e=>{h({secret:e.secret,otpauthUrl:e.otpauthUrl}),_(``),x(null)},onError:e=>x(e instanceof Error?e.message:`Setup failed`)}),O=u({mutationFn:e=>n.confirmOwnTotp(e),onSuccess:()=>{h(null),_(``),x(null),l.refetch()},onError:e=>x(e instanceof Error?e.message:`Confirmation failed — code did not match`)}),k=G(`Turning off two-factor authentication`),A=u({mutationFn:async()=>{let e=await k.requestProof();return e===null?null:n.disableOwnTotp({reauthToken:e})},onSuccess:()=>{x(null),l.refetch()},onError:e=>x(e instanceof Error?e.message:`Disable failed`)});r(()=>{if(!C)return;let e=setTimeout(()=>E(!1),1500);return()=>clearTimeout(e)},[C]);let j=i(()=>l.isLoading?`loading`:m?`setup_in_progress`:p?.enabled?`enrolled`:`not_enrolled`,[l.isLoading,p?.enabled,m]);return o(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[k.dialog,o(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[d(f,{className:`h-3.5 w-3.5 text-foreground-subtle`}),d(`div`,{className:`text-xs font-semibold text-foreground`,children:t(`systemPage.myAccess.twoFactorAuthentication`,`Two-factor authentication`)})]}),o(`div`,{className:`p-4 space-y-3`,children:[j===`loading`&&o(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(w,{className:`h-3.5 w-3.5 animate-spin`}),t(`systemPage.myAccess.checkingStatus`,`Checking status…`)]}),j===`not_enrolled`&&o(c,{children:[d(`div`,{className:`text-xs text-foreground-subtle`,children:t(`systemPage.myAccess.2faIsnTActiveOn`,`2FA isn't active on your account. Enable it to require a 6-digit code from your authenticator app at every login.`)}),d(`div`,{className:`flex justify-end`,children:o(M,{onClick:()=>{x(null),D.mutate()},disabled:D.isPending,children:[D.isPending?d(w,{className:`h-3 w-3 animate-spin`}):d(f,{className:`h-3 w-3`}),t(`systemPage.myAccess.enable2fa`,`Enable 2FA`)]})})]}),j===`setup_in_progress`&&m&&o(c,{children:[d(`div`,{className:`text-[11px] text-foreground-subtle`,children:d(U,{i18nKey:`systemPage.myAccess.scanQr`,values:{username:e},components:{mono:d(`span`,{className:`font-mono`})}})}),o(`div`,{className:`flex flex-col items-center gap-3`,children:[d(`div`,{className:`rounded-lg border border-border bg-white p-3`,children:d(Me,{value:m.otpauthUrl,size:180})}),o(`div`,{className:`w-full`,children:[d(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle mb-1`,children:t(`systemPage.myAccess.secretManualEntry`,`Secret (manual entry)`)}),o(`div`,{className:`flex items-center gap-2 rounded border border-border bg-surface-hover/30 px-2 py-1.5`,children:[d(`code`,{className:`text-[11px] font-mono text-foreground break-all flex-1`,children:m.secret}),o(M,{variant:`ghost`,onClick:()=>{m&&navigator.clipboard.writeText(m.secret).then(()=>E(!0))},children:[C?d(S,{className:`h-3 w-3 text-success`}):d(y,{className:`h-3 w-3`}),C?t(`systemPage.myAccess.copied`,`Copied`):t(`common.copy`,`Copy`)]})]})]})]}),o(`div`,{className:`space-y-1`,children:[d(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`6-digit code`}),d(`input`,{type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,placeholder:`123456`,value:g,onChange:e=>_(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full rounded-md border border-border bg-surface px-3 py-2 text-center text-lg font-mono tracking-widest text-foreground focus:outline-none focus:ring-2 focus:ring-primary`})]}),v&&o(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[d(b,{className:`h-3 w-3`}),v]}),o(`div`,{className:`flex justify-end gap-2`,children:[d(M,{variant:`outline`,onClick:()=>{h(null),x(null),_(``)},children:t(`common.cancel`,`Cancel`)}),o(M,{onClick:()=>{x(null),O.mutate({code:g})},disabled:O.isPending||g.length!==6,children:[O.isPending?d(w,{className:`h-3 w-3 animate-spin`}):d(S,{className:`h-3 w-3`}),t(`common.confirm`,`Confirm`)]})]})]}),j===`enrolled`&&p&&o(c,{children:[o(`div`,{className:`rounded-md border border-success/30 bg-success/5 px-3 py-2.5 flex items-start gap-2.5`,children:[d(S,{className:`h-4 w-4 mt-0.5 text-success shrink-0`}),o(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[d(`div`,{className:`font-medium`,children:t(`systemPage.myAccess.2faIsActive`,`2FA is active`)}),d(`div`,{className:`text-foreground-subtle`,children:t(`common.enrolledOn`,{when:p.confirmedAt?new Date(p.confirmedAt).toLocaleString():`—`})})]})]}),v&&o(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[d(b,{className:`h-3 w-3`}),v]}),d(`div`,{className:`flex justify-end`,children:o(M,{variant:`danger`,onClick:()=>{x(null),A.mutate()},disabled:A.isPending,children:[A.isPending?d(w,{className:`h-3 w-3 animate-spin`}):d(f,{className:`h-3 w-3`}),t(`systemPage.myAccess.disable2fa`,`Disable 2FA`)]})})]})]})]})}function Z(){return re(`auth-webauthn/passkey-enrollment`)?d(se,{widgetId:`auth-webauthn/passkey-enrollment`,host:`dashboard`}):null}n();function Q(e){return e.message.length>0?e.message:le.t(`auth.authAuditSection.requestFailed`)}function Fe(){let{t:e}=L(),{logout:t}=H(),n=N(),r=I.useUtils(),i=I.auth.listOwnSessions.useQuery(),[s,c]=a(null),l=I.auth.revokeOwnSession.useMutation({onSuccess:()=>void r.auth.listOwnSessions.invalidate(),onError:e=>c(`Sign out failed: ${Q(e)}`)}),u=I.auth.logout.useMutation({onSuccess:()=>t(),onError:e=>c(`Sign out failed: ${Q(e)}`)}),f=async t=>{await n({title:e(`auth.mySessionsSection.signOutThisSession`,`Sign out this session`),message:e(`auth.mySessionsSection.willHaveToSignIn`,`{{label}} will have to sign in again.`,{label:be(t.client).label}),confirmLabel:e(`auth.mySessionsSection.signOut`,`Sign out`),variant:`danger`})&&(c(null),l.mutate({id:t.id}))},p=async()=>{await n({title:e(`auth.mySessionsSection.signOutEverywhere`,`Sign out everywhere`),message:e(`auth.mySessionsSection.everySessionOfYourAccount`,`Every session of your account ends, this browser included: you will be signed out here too and every device has to sign in again.`),confirmLabel:e(`auth.mySessionsSection.signOutEverywhere`,`Sign out everywhere`),variant:`danger`})&&(c(null),u.mutate({everywhere:!0}))};return o(`div`,{"data-testid":`my-sessions`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[o(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[d(te,{className:`h-3.5 w-3.5 text-foreground-subtle`}),d(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`auth.mySessionsSection.activeSessions`,`Active sessions`)})]}),o(`div`,{className:`p-4 space-y-3`,children:[d(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`auth.mySessionsSection.theBrowsersAndAppsSigned`,`The browsers and apps signed in to your account. Signing one out ends it at once.`)}),s!==null&&d(`div`,{className:`text-[11px] text-danger`,children:s}),d(ye,{sessions:i.data??[],isLoading:i.isLoading,loadError:i.isError?i.error?.message??e(`auth.authAuditSection.requestFailed`):null,emptyText:`No active sessions.`,onRevoke:e=>void f(e),revokingId:l.isPending?l.variables?.id??null:null}),d(`div`,{className:`flex justify-end`,children:o(`button`,{onClick:()=>void p(),disabled:u.isPending,className:`inline-flex items-center gap-1.5 rounded border border-danger/40 px-2.5 py-1 text-[11px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,children:[u.isPending?d(w,{className:`h-3 w-3 animate-spin`}):d(j,{className:`h-3 w-3`}),e(`auth.mySessionsSection.signOutEverywhere`,`Sign out everywhere`)]})})]})]})}n();var Ie=`You`;function Le(){let{t:e}=L(),t=N(),n=I.useUtils(),r=I.auth.listOwnDeviceCredentials.useQuery(),[o,s]=a(null),c=I.auth.revokeOwnDeviceCredential.useMutation({onSuccess:e=>{e.revoked||s(`That device could not be revoked - it may already be gone.`),n.auth.listOwnDeviceCredentials.invalidate()},onError:e=>s(`Revoke failed: ${e.message}`)}),l=i(()=>(r.data??[]).map(e=>ve(e,Ie)),[r.data]),u=async n=>{await t({title:e(`certificates.myDevicesSection.revoke`,`Revoke "{{name}}"?`,{name:n.name}),message:e(`certificates.myDevicesSection.theDeviceStopsSigningIn`,`The device stops signing in at once and its open sessions end. To use it again you have to pair it anew. This cannot be undone.`),confirmLabel:e(`certificates.myDevicesSection.revoke2`,`Revoke`),variant:`danger`})&&(s(null),c.mutate({id:n.id}))},p={label:e(`certificates.myDevicesSection.revoke2`,`Revoke`),icon:m,isAvailable:he,onRun:e=>void u(e),busyId:c.isPending?c.variables?.id??null:null,disabled:c.isPending};return d(pe,{id:`my-devices`,title:e(`certificates.myDevicesSection.myDevices`,`My devices`),icon:f,description:e(`certificates.myDevicesSection.phonesThatStaySignedIn`,`Phones that stay signed in to your account with a certificate. If one is lost, revoke it here and it is signed out at once.`),notice:_e(o),onDismissNotice:()=>s(null),children:d(me,{rows:l,label:e(`certificates.devicesCard.label`),isLoading:r.isPending,loadError:r.error===null?null:r.error.message||`Request failed`,emptyText:`No devices are signed in with a certificate.`,hideOwner:!0,expiresNone:`—`,action:p})})}var $={profile:`profile`,signIn:`sign-in`,sessions:`sessions`,tokens:`tokens`},Re=[`linked`,`linkError`],ze={view:{icon:v,cls:`bg-foreground-subtle/15 text-foreground-subtle`},create:{icon:p,cls:`bg-primary/15 text-primary`},delete:{icon:h,cls:`bg-danger/15 text-danger`}};function Be(){let{t:e}=L(),{user:t,logout:n}=H(),[r]=ue(),i=e(`system.myAccess`,`My access`);if(!t)return d(fe,{icon:O,title:i,children:d(`div`,{className:`text-xs text-foreground-subtle`,children:e(`systemPage.myAccess.notSignedIn`,`Not signed in.`)})});if(Re.some(e=>r.has(e))&&!r.has(`tab`)){let e=new URLSearchParams(r);return e.set(`tab`,$.signIn),d(V,{to:`?${e.toString()}`,replace:!0})}return d(de,{icon:O,title:i,subtitle:e(`systemPage.myAccess.subtitle`,`Your account, how you sign in, where you are signed in, and your tokens.`),sectionsLabel:e(`systemPage.myAccess.sectionsLabel`,`My access sections`),defaultSection:$.profile,actions:o(M,{variant:`outline`,onClick:n,children:[d(j,{className:`h-3 w-3`}),e(`systemPage.myAccess.signOut`,`Sign out`)]}),sections:[{id:$.profile,label:e(`systemPage.myAccess.sections.profile`,`Profile`),content:d(Ve,{user:t})},{id:$.signIn,label:e(`systemPage.myAccess.sections.signIn`,`Sign-in & security`),content:o(`div`,{className:`space-y-4`,children:[d(Ne,{}),d(Pe,{username:t.username}),d(Z,{}),d(je,{})]})},{id:$.sessions,label:e(`systemPage.myAccess.sections.sessions`,`Sessions & devices`),content:o(`div`,{className:`space-y-4`,children:[d(Fe,{}),d(Le,{}),d(Oe,{})]})},{id:$.tokens,label:e(`systemPage.myAccess.sections.tokens`,`Tokens`),content:d(ge,{ownOnly:!0})}]})}function Ve({user:e}){let{t}=L(),n=e.isAdmin,r=e.scopes??[];return o(`div`,{className:`space-y-4`,children:[o(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3 flex items-center gap-3`,children:[d(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-full bg-primary/10 text-primary font-semibold text-base`,children:e.username.slice(0,1).toUpperCase()}),o(`div`,{className:`flex-1 min-w-0`,children:[d(`div`,{className:`text-sm font-semibold text-foreground truncate`,children:e.username}),o(`div`,{className:`text-[11px] text-foreground-subtle`,children:[n?t(`systemPage.myAccess.administrator`,`Administrator`):t(`systemPage.myAccess.user`,`User`),` `,d(U,{i18nKey:`systemPage.myAccess.sessionId`,values:{id:e.id.slice(0,8)},components:{mono:d(`span`,{className:`font-mono`})}})]})]})]}),n&&o(`div`,{className:`rounded-lg border border-primary/30 bg-primary/5 px-4 py-3 text-xs text-foreground flex items-start gap-2.5`,children:[d(C,{className:`h-4 w-4 text-primary mt-0.5 shrink-0`}),o(`div`,{children:[d(`div`,{className:`font-semibold text-foreground`,children:t(`systemPage.myAccess.unrestrictedAccess`,`Unrestricted access`)}),d(`p`,{className:`text-foreground-subtle mt-0.5`,children:t(`systemPage.myAccess.adminSessionsBypassThePer`,`Admin sessions bypass the per-call scope check. Every protected endpoint is reachable regardless of the list below.`)})]})]}),r.length>0&&d(He,{scopes:r})]})}function He({scopes:e}){let{t}=L(),n=D();return o(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[o(`div`,{className:`px-4 py-2 border-b border-border`,children:[d(`div`,{className:`text-xs font-semibold text-foreground`,children:t(`systemPage.myAccess.grantedScopes`,`Granted scopes`)}),d(`div`,{className:`text-[10px] text-foreground-subtle`,children:t(`systemPage.myAccess.bakedIntoYourSessionToken`,`Baked into your session token at login; sign out + back in to refresh after changes.`)})]}),o(`div`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[d(`div`,{children:t(`systemPage.myAccess.type`,`Type`)}),d(`div`,{children:t(`systemPage.myAccess.target`,`Target`)}),d(`div`,{children:t(`systemPage.myAccess.access`,`Access`)})]}),d(`ul`,{className:`divide-y divide-border`,children:e.map((e,r)=>o(`li`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2.5 items-center text-xs`,children:[d(`span`,{className:`font-mono text-foreground-subtle`,children:e.type}),d(`span`,{className:`font-mono text-foreground`,children:e.type===`device`?ce(e.selector,n):e.target}),d(`div`,{className:`flex items-center gap-1`,children:[`view`,`create`,`delete`].map(n=>{let r=e.access.includes(n),{icon:i,cls:a}=ze[n];return o(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${r?a:`bg-transparent text-foreground-subtle/40 line-through`}`,title:r?t(`systemPage.myAccess.can`,`Can {{a}}`,{a:n}):t(`systemPage.myAccess.cannot`,`Cannot {{a}}`,{a:n}),children:[d(i,{className:`h-3 w-3`}),n]},n)})})]},r))})]})}export{Be as MyAccessPage};