@camstack/addon-admin-ui 1.2.675 → 1.2.677

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 (102) hide show
  1. package/CHANGELOG.md +16 -4
  2. package/dist/assets/Addons-D6ah1FOW.js +5 -0
  3. package/dist/assets/{AdminPage-BKJUlsLi.js → AdminPage-CLGYxf9t.js} +1 -1
  4. package/dist/assets/{AdminSectionedPage-DSB1PxSl.js → AdminSectionedPage-B2U4ITKg.js} +1 -1
  5. package/dist/assets/{AiProfiles-CO33unzR.js → AiProfiles-BCpBMbdS.js} +2 -2
  6. package/dist/assets/{BootstrapSettingsForm-DjGLgW8y.js → BootstrapSettingsForm-B0EgeFUN.js} +1 -1
  7. package/dist/assets/{Build-BAHi2Di4.js → Build-hScgi1MH.js} +5 -5
  8. package/dist/assets/{Calendars-C0kIKe0_.js → Calendars-BsjlQ3Dn.js} +1 -1
  9. package/dist/assets/{CameraGrids-BLzTxMZq.js → CameraGrids-vmWja3kH.js} +1 -1
  10. package/dist/assets/{Cluster-DoTX3LAA.js → Cluster-Doxd6qGa.js} +1 -1
  11. package/dist/assets/{CompositionBlockEditor-DeFj50eP.js → CompositionBlockEditor-Dg_GhhSX.js} +2 -2
  12. package/dist/assets/{CompositionEditorPage-D4_TRz9X.js → CompositionEditorPage-B18GaLSe.js} +1 -1
  13. package/dist/assets/{Data-BNtLAI2a.js → Data-Ddkos7gG.js} +2 -2
  14. package/dist/assets/DeviceDetail-C_FKpCVm.js +2 -0
  15. package/dist/assets/{Devices-RlDAUC2M.js → Devices-DBZbvYo-.js} +1 -1
  16. package/dist/assets/{EmbedDevicePage-D4Eb7q8W.js → EmbedDevicePage-DLf80a5a.js} +1 -1
  17. package/dist/assets/{EmbedPlayerPage-CDyI6F2c.js → EmbedPlayerPage-DhVJ09E5.js} +1 -1
  18. package/dist/assets/{History-C4Ug3VT5.js → History-VDNlgjba.js} +1 -1
  19. package/dist/assets/Identity-DK7Ehonm.js +1 -0
  20. package/dist/assets/{InstancesTable-C6Pf-j1u.js → InstancesTable-BVlBsn4e.js} +1 -1
  21. package/dist/assets/IntegrationDetail-y5FPAuIt.js +1 -0
  22. package/dist/assets/Integrations-CN051z6f.js +1 -0
  23. package/dist/assets/{Integrations-DtDcBpo2.js → Integrations-CNA6fJTq.js} +2 -2
  24. package/dist/assets/{Library-B2JKAUaL.js → Library-Ci6lXFTr.js} +1 -1
  25. package/dist/assets/Locations-Bu7_EhSd.js +3 -0
  26. package/dist/assets/{Logs-BCZstE4C.js → Logs-BSMFAFM-.js} +1 -1
  27. package/dist/assets/{MaskShapeCanvas-CzmKAhNn.js → MaskShapeCanvas-DbmWEEiO.js} +1 -1
  28. package/dist/assets/{MotionZonesSettings-Gtxon45n.js → MotionZonesSettings-BzScgedh.js} +1 -1
  29. package/dist/assets/MyAccess-DEsI0-v1.js +2 -0
  30. package/dist/assets/{Network-DcO6iFcm.js → Network-BUVwaLPK.js} +1 -1
  31. package/dist/assets/{NodeAddonsSettingsPanel-BU4x5-7q.js → NodeAddonsSettingsPanel-CF2hybep.js} +1 -1
  32. package/dist/assets/{Notifications-BwPzQz_8.js → Notifications-si4uHCUd.js} +1 -1
  33. package/dist/assets/{Pipeline-G84v3ij0.js → Pipeline-R5hlEDdK.js} +1 -1
  34. package/dist/assets/{PrivacyMaskSettings-BY6sg6A4.js → PrivacyMaskSettings-DgBQuyh9.js} +1 -1
  35. package/dist/assets/{Recordings-CjXKbLTr.js → Recordings-CVFG3ZwY.js} +1 -1
  36. package/dist/assets/{SceneMonitorEditor-i7OhxRG-.js → SceneMonitorEditor-D5OLGtBI.js} +1 -1
  37. package/dist/assets/{ServerShell-DWxCqodO.js → ServerShell-C8V2lBdw.js} +1 -1
  38. package/dist/assets/SessionsList-UA93KdGB.js +2 -0
  39. package/dist/assets/{Showroom-CbPxSS0-.js → Showroom-OqrhFvCR.js} +1 -1
  40. package/dist/assets/{StorageLocationsTable-BAIDNYZE.js → StorageLocationsTable-e-W20Lta.js} +1 -1
  41. package/dist/assets/System-DKAXnUuh.js +1 -0
  42. package/dist/assets/Terminal-D8tSU3Ib.js +3 -0
  43. package/dist/assets/{TerminalPanel-Bp1gZQoy.js → TerminalPanel-Bbm9zDBS.js} +1 -1
  44. package/dist/assets/{TrainingProviders-BG7fk3jP.js → TrainingProviders-BJYQWLf_.js} +1 -1
  45. package/dist/assets/{Viewer-DeOj6NkB.js → Viewer-FfpTNMMQ.js} +1 -1
  46. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-l9ng6Ybr.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DnjD0nNs.js} +1 -1
  47. package/dist/assets/{action-draft-r_kKMuf2.js → action-draft-Dr5Q1lmk.js} +1 -1
  48. package/dist/assets/{ai-page.helpers-B01d73HY.js → ai-page.helpers-AOJOCF6H.js} +1 -1
  49. package/dist/assets/{assignment-candidates-tXGiM44_.js → assignment-candidates-DDkS_tzk.js} +1 -1
  50. package/dist/assets/{authed-media-u_StVFnl.js → authed-media-CecdSapa.js} +1 -1
  51. package/dist/assets/{board-model-C-1eQ0ae.js → board-model-COsjkU2L.js} +1 -1
  52. package/dist/assets/client-LrzN1ATZ.js +1119 -0
  53. package/dist/assets/{command-vocab-0n7AggZw.js → command-vocab-wRSfGsbG.js} +1 -1
  54. package/dist/assets/{device-detail-C019bGlW.js → device-detail-DnmranHV.js} +1 -1
  55. package/dist/assets/{device-integration-icon-CpZ0OBPQ.js → device-integration-icon-BMv1BZvi.js} +1 -1
  56. package/dist/assets/device-picker-model-O8VGuRKY.js +1 -0
  57. package/dist/assets/{dist-DDGjJPZi.js → dist-BnzMSUv0.js} +1 -1
  58. package/dist/assets/dist-p9ea9Hzu.js +1119 -0
  59. package/dist/assets/{format-DfOVHXCT.js → format-Fw8MrMCF.js} +1 -1
  60. package/dist/assets/{hostInit-CFCiEE_B.js → hostInit-857pzX7m.js} +1 -1
  61. package/dist/assets/i18n-DWjQ9UFE.js +1 -0
  62. package/dist/assets/{icons-CBCEFkYd.js → icons-Dfx79nBH.js} +1 -1
  63. package/dist/assets/index-BNXaxwJL.css +2 -0
  64. package/dist/assets/{index-cl6SWsBh.js → index-Cva8qUKs.js} +3 -3
  65. package/dist/assets/{linked-devices-model-lSVw-dAG.js → linked-devices-model-ko-1V3xc.js} +1 -1
  66. package/dist/assets/{mf-entry-bootstrap-0-c0f4a27e.js → mf-entry-bootstrap-0-7ba194e9.js} +2 -2
  67. package/dist/assets/mount-O8VGuRKY.js +1 -0
  68. package/dist/assets/{notification-rule-status-Nsg84Ad6.js → notification-rule-status-tbLfUZee.js} +1 -1
  69. package/dist/assets/{player-overlays-BxDm01PX.js → player-overlays-8aC2r-sd.js} +1 -1
  70. package/dist/assets/remoteEntry-Ch9X6nke.js +1 -0
  71. package/dist/assets/src-CMqAnpve.js +279 -0
  72. package/dist/assets/{sso-popup-n86tgOtV.js → sso-popup-C_VTtoWT.js} +1 -1
  73. package/dist/assets/{step-inspector-model-B1WsVC3m.js → step-inspector-model-CBsgzTmi.js} +1 -1
  74. package/dist/assets/{use-scenes-feed-BE2grUhu.js → use-scenes-feed-fmJiwExN.js} +1 -1
  75. package/dist/assets/{use-stationary-objects-C07MtPwR.js → use-stationary-objects-DgbYJ0ZF.js} +1 -1
  76. package/dist/assets/{useAdminDeviceRemoval-CVX0q4fL.js → useAdminDeviceRemoval-BrAOByYi.js} +1 -1
  77. package/dist/assets/useEventInvalidation-O8VGuRKY.js +1 -0
  78. package/dist/assets/{useNodeUrlSelection-8jpiE4sx.js → useNodeUrlSelection-D1R8H-HS.js} +1 -1
  79. package/dist/assets/{useTemplateSave-Er9UcdNY.js → useTemplateSave-BU2_hI30.js} +1 -1
  80. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DxT73bEi.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-dosLnwLg.js} +2 -2
  81. package/dist/index.html +9 -9
  82. package/dist/server/addon.js +304 -22
  83. package/package.json +2 -2
  84. package/dist/assets/Addons-B5cMCuEY.js +0 -5
  85. package/dist/assets/DeviceDetail-eIUrMHhx.js +0 -2
  86. package/dist/assets/Identity-CiVu8loN.js +0 -1
  87. package/dist/assets/IntegrationDetail-B72YnGdY.js +0 -1
  88. package/dist/assets/Integrations-CpfjcIva.js +0 -1
  89. package/dist/assets/Locations-Cw1FOrs0.js +0 -3
  90. package/dist/assets/MyAccess-HDB1zCA-.js +0 -2
  91. package/dist/assets/SessionsList-BCBUA0_b.js +0 -2
  92. package/dist/assets/System-BN_0tWnK.js +0 -1
  93. package/dist/assets/Terminal-BaeNBCrT.js +0 -3
  94. package/dist/assets/client-DbKXlEC4.js +0 -1119
  95. package/dist/assets/device-picker-model-9s4juC85.js +0 -1
  96. package/dist/assets/dist-BnoF0i0M.js +0 -1119
  97. package/dist/assets/i18n-1k63HMS1.js +0 -1
  98. package/dist/assets/index-CWyWRkhx.css +0 -2
  99. package/dist/assets/mount-9s4juC85.js +0 -1
  100. package/dist/assets/remoteEntry-COb4mVPT.js +0 -1
  101. package/dist/assets/src-Cn1TCE2g.js +0 -279
  102. package/dist/assets/useEventInvalidation-9s4juC85.js +0 -1
@@ -1 +0,0 @@
1
- import{C as e,J as t,K as n,S as r,V as i,Y as a,a as o,et as s,o as c,x as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{An as u,Bn as d,D as f,Fr as p,Jn as m,Ln as h,Mn as g,Mr as _,Nn as v,Oa as y,Rr as b,Sn as x,Ua as S,Ur as C,Vt as w,Wi as T,Xt as E,ct as D,dt as O,en as ee,lr as te,pi as ne,rr as re,ut as ie,vt as ae,wt as oe,yi as se}from"./player-overlays-BxDm01PX.js";import{Fs as k,Ps as ce,p as le}from"./client-DbKXlEC4.js";import{f as A,l as j,n as ue,o as M,u as de}from"./terminal-DU-tvcEm.js";import{t as fe}from"./file-up-2YD_M6f_.js";import{t as pe}from"./key-CH4aXNMz.js";import{t as me}from"./monitor-smartphone-DPI9EQus.js";import{t as he}from"./unlink-D3-IGpS8.js";import{$f as ge,A as _e,Af as ve,Ai as N,Ar as ye,Cr as P,Df as be,Di as xe,Ef as Se,Ff as Ce,Fi as F,G as we,Gf as I,Gi as Te,If as Ee,Jr as L,Kr as R,Lf as De,Mf as Oe,Nf as ke,Ni as z,Ns as Ae,Of as je,Or as Me,Pf as Ne,Pi as B,Qf as Pe,Sr as Fe,Xf as Ie,Yf as Le,Yr as Re,Zf as ze,bl as Be,ct as V,ei as Ve,et as He,fa as H,fl as Ue,hl as We,jf as Ge,ji as Ke,jr as qe,kf as Je,ki as Ye,kp as U,kr as W,ma as G,ni as Xe,pa as Ze,ti as Qe,tt as $e,ul as et,yl as tt}from"./src-Cn1TCE2g.js";import{t as K}from"./i18n-1k63HMS1.js";import{t as q}from"./useTranslation-BJr-n0es.js";import{F as nt,b as rt,c as it,d as at,di as ot,f as st,hi as ct,ht as lt,l as ut,li as dt,o as ft,pi as pt,r as mt,s as ht,u as gt,ui as _t}from"./index-cl6SWsBh.js";import{t as vt}from"./AdminSectionedPage-DSB1PxSl.js";import{t as yt}from"./AdminPage-BKJUlsLi.js";import{t as bt}from"./InstancesTable-C6Pf-j1u.js";import{C as xt,D as J,E as St,O as Y,S as Ct,T as wt,_ as Tt,a as Et,b as Dt,c as Ot,d as kt,f as At,g as jt,h as Mt,i as Nt,k as Pt,l as Ft,m as It,n as Lt,o as Rt,p as zt,s as Bt,t as Vt,u as Ht,v as Ut,w as Wt,x as Gt,y as Kt}from"./SessionsList-BCBUA0_b.js";import{n as qt,t as Jt}from"./BootstrapSettingsForm-DjGLgW8y.js";s();function Yt(){let{t:e}=q(),t=D(),i=U.useUtils(),o=Pt(),{data:s,isLoading:c}=Oe(),l=n(()=>s??[],[s]),u=U.useQueries(e=>l.map(t=>e.userManagement.listExternalIdentities({userId:t.id}))),d=U.auth.listLoginMethods.useQuery(),[f,p]=a(null),m=Ee({onSuccess:()=>void i.userManagement.listExternalIdentities.invalidate(),onError:e=>p(`Remove failed: ${e.message}`)}),h=n(()=>new Map((d.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),[d.data]),g=l.flatMap((e,t)=>u[t]?.data??[]),_=g.map(e=>({...Gt(e,o),kind:h.get(e.provider)??e.provider})),v=async n=>{let r=g.find(e=>Dt(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 r(J,{notice:Y(f),onDismissNotice:()=>{p(null)},id:`external-identities`,title:e(`access.externalIdentitiesSection.signInLinks`,`Sign-in links`),icon:A,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:r(Wt,{rows:_,label:`sign-in links`,isLoading:c||u.some(e=>e.isLoading),loadError:u.find(e=>e.isError)?.error?.message??null,emptyText:`No user has linked a sign-in account.`,expiresNone:`—`,action:{label:e(`common.remove`,`Remove`),icon:he,isAvailable:()=>!0,onRun:e=>void v(e),busyId:null,disabled:m.isPending}})})}s();var Xt={key:`access.nouns.linkedApp`};function Zt(e){if(e.type===`category`){let t=e.target??``;return t===`device`?K.t(`access.linkedAppsSection.allDevices`):K.t(`access.linkedAppsSection.allTarget`,{target:t})}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function Qt(){let{t:e}=q(),t=D(),i=c(),o=Ge(),[s,l]=a(null),u=()=>void i.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]}),d=Ne({onSuccess:u,onError:e=>l(`Revoke failed: ${e.message}`)}),f=wt(Xt,u),p=n(()=>(o.data??[]).map(e=>Ct(e,e.scopes.map(Zt).join(`, `))),[o.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`})&&(l(null),d.mutate({id:n.id}))},h=d.isPending?d.variables?.id??null:null;return r(J,{notice:Y(s,f.outcome),onDismissNotice:()=>{l(null),f.dismiss()},id:`linked-apps`,title:e(`access.linkedAppsSection.linkedApps`,`Linked apps`),icon:b,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:r(Wt,{rows:p,label:e(`access.linkedAppsSection.linkedApps2`,`linked apps`),isLoading:o.isLoading,loadError:o.isError?o.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:ee,isAvailable:e=>e.status===`active`||e.status===`revoked`,onRun:e=>void m(e),busyId:h,disabled:d.isPending||f.busy},bulk:{revoke:f,noun:Xt,isSelectable:e=>e.status===`active`||e.status===`revoked`,quickSelect:[{label:e(`access.linkedAppsSection.selectRevoked`,`Select revoked`),match:e=>e.status===`revoked`}]}})})}var $t=5e3;function en(){let{t}=q(),n=U.useUtils(),i=U.auth.cliLoginPending.useQuery(void 0,{refetchInterval:$t}),a=U.auth.cliLoginDeny.useMutation({onSuccess:()=>void n.auth.cliLoginPending.invalidate()}),o=i.data??[];if(o.length===0)return null;let s=Date.now();return e(`div`,{className:`space-y-2 rounded-md border border-border bg-background-elevated p-3`,"data-testid":`pending-terminal-signins`,children:[e(`div`,{className:`flex items-center gap-2 text-xs font-medium text-foreground`,children:[r(ue,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),t(`cliLogin.pendingTitle`,`Pending terminal sign-ins`)]}),r(`ul`,{className:`space-y-1`,children:o.map(n=>{let i=mt(n.createdAt,s);return e(`li`,{className:`flex items-center justify-between gap-3 text-xs`,children:[e(`span`,{className:`min-w-0 truncate text-foreground-muted`,children:[n.userAgent??t(`cliLogin.unknownValue`,`Unknown`),` · `,n.ip??t(`cliLogin.unknownValue`,`Unknown`),` · `,i.key===`justNow`?t(`cliLogin.ageNow`,`just now`):i.key===`seconds`?t(`cliLogin.ageSeconds`,`{{count}} s ago`,{count:i.value}):t(`cliLogin.ageMinutes`,`{{count}} min ago`,{count:i.value})]}),r(I,{type:`button`,size:`sm`,variant:`ghost`,disabled:a.isPending,onClick:()=>a.mutate({requestId:n.requestId}),children:t(`cliLogin.notMe`,`Not me`)})]},n.requestId)})}),r(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`cliLogin.pendingHint`,`To approve one, open the approval page and type the code the terminal shows.`)})]})}s();var tn={key:`access.nouns.session`};function nn(){let{t}=q(),i=D(),o=U.useUtils(),s=Pt(),c=U.auth.listSessions.useQuery(),[l,u]=a(null),d=()=>void o.auth.listSessions.invalidate(),f=U.auth.revokeSessions.useMutation({onSuccess:d,onError:e=>u(`Sign out failed: ${e.message}`)}),p=wt(tn,d),m=n(()=>(c.data??[]).map(e=>xt(e,s,{client:e=>Tt(e).label,method:Ut})),[c.data,s]),h=async e=>{await i({title:t(`access.loginSessionsSection.signOutThisSession`,`Sign out this session`),message:t(`access.loginSessionsSection.onWillHaveToSign`,`{{ownerName}} on {{name}} will have to sign in again.`,{ownerName:e.ownerName,name:e.name}),confirmLabel:t(`access.loginSessionsSection.signOut`,`Sign out`),variant:`danger`})&&(u(null),f.mutate({id:e.id}))};return e(J,{notice:Y(l,p.outcome),onDismissNotice:()=>{u(null),p.dismiss()},id:`login-sessions`,title:t(`access.loginSessionsSection.loginSessions`,`Login sessions`),icon:me,description:t(`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:[r(en,{}),r(Wt,{rows:m,label:t(`common.sessionsLabel`),isLoading:c.isLoading,loadError:c.isError?c.error?.message??`Request failed`:null,emptyText:`No active sessions.`,action:{label:t(`access.loginSessionsSection.signOut`,`Sign out`),icon:M,isAvailable:e=>e.status===`active`,onRun:e=>void h(e),busyId:f.isPending&&f.variables!==void 0&&`id`in f.variables?f.variables.id:null,disabled:f.isPending||p.busy},bulk:{revoke:p,noun:tn,isSelectable:e=>e.status===`active`}})]})}var rn={"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 an(e){let t=X(e,`prefix`);return t===null?null:K.t(`helpers.authAuditWording.prefix`,{prefix:t})}function on(e,t){let n=e.detail??{};switch(e.action){case`admin-token-created`:{let e=n.expiresAt;return{title:K.t(`helpers.authAuditWording.tokenCreated`,{name:Z(n,t)}),details:Q([an(n),typeof e==`number`?K.t(`helpers.authAuditWording.expires`,{at:Kt(e)}):null])}}case`admin-token-used`:{let e=X(n,`path`);return{title:K.t(`helpers.authAuditWording.tokenUsed`,{name:Z(n,t)}),details:Q([an(n),e===null?null:K.t(`helpers.authAuditWording.call`,{path:e})])}}case`token-minted`:{let e=n.expiresAt;return{title:K.t(`helpers.authAuditWording.tokenMinted`,{name:Z(n,t)}),details:Q([typeof e==`number`?K.t(`helpers.authAuditWording.expires`,{at:Kt(e)}):null])}}case`token-revoked`:return{title:K.t(`helpers.authAuditWording.anyTokenRevoked`,{name:Z(n,t)}),details:[]};case`admin-token-revoked`:return{title:K.t(`helpers.authAuditWording.tokenRevoked`,{name:Z(n,t)}),details:Q([an(n)])};case`credentials-revoked`:{let e=X(n,`kind`)??`credential`,t=n.revoked,r=n.skipped,i=rn[e],a=i===void 0?`${e}s`:K.t(i);return{title:K.t(`helpers.authAuditWording.bulkRevoked`,{n:typeof t==`number`?String(t):`?`,noun:a}),details:Q([typeof r==`number`&&r>0?K.t(`helpers.authAuditWording.skipped`,{count:r}):null,X(n,`ids`)===null?null:K.t(`helpers.authAuditWording.ids`,{ids:X(n,`ids`)??``})])}}case`second-factor-skipped`:{let e=X(n,`method`),t=X(n,`factors`);return{title:K.t(`helpers.authAuditWording.secondFactorSkipped`),details:Q([e===null?null:K.t(`helpers.authAuditWording.signedInWith`,{method:Ut(e)}),t===null?null:K.t(`helpers.authAuditWording.skippedFactors`,{factors:t.split(`,`).join(`, `)})])}}default:return{title:e.action,details:Object.entries(n).map(([e,t])=>`${e}: ${String(t)}`)}}}s();var sn=100;function cn(){let{user:e}=nt();return e?.isAdmin?r(un,{}):null}function ln(){let{data:e}=Oe(),{data:t}=U.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 un(){let{t}=q(),n=U.auth.listAuthAudit.useQuery({limit:sn}),{userNameById:i,tokenNameById:a}=ln(),o=n.data??[];return e(`div`,{"data-testid":`auth-audit`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[e(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[r(d,{className:`h-3.5 w-3.5 text-foreground-subtle`}),r(`div`,{className:`text-xs font-semibold text-foreground`,children:t(`auth.authAuditSection.authenticationAudit`,`Authentication audit`)}),r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:t(`auth.authAuditSection.latest`,{count:sn})})]}),r(`div`,{className:`p-4`,children:n.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(p,{className:`h-3.5 w-3.5 animate-spin`}),t(`auth.authAuditSection.loadingAuditTrail`,`Loading audit trail…`)]}):n.isError?e(`div`,{className:`text-[11px] text-danger`,children:[t(`auth.authAuditSection.couldNotLoadTheAudit`,`Could not load the audit trail:`),` `,n.error?.message??t(`auth.authAuditSection.requestFailed`,`Request failed`)]}):o.length===0?e(`div`,{className:`rounded border border-dashed border-border px-3 py-4 text-xs text-foreground-subtle text-center space-y-1`,children:[r(`div`,{children:t(`auth.authAuditSection.noAuthenticationEventsRecordedYet`,`No authentication events recorded yet.`)}),r(`div`,{className:`text-[11px] text-foreground-subtle/90`,children:t(`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.`)})]}):r(`ul`,{className:`divide-y divide-border rounded-md border border-border max-h-[420px] overflow-y-auto`,children:o.map(e=>r(dn,{record:e,userName:e.userId===void 0?null:i.get(e.userId)??e.userId,tokenNameById:a},e.id))})})]})}function dn({record:t,userName:n,tokenNameById:i}){let a=on(t,i);return e(`li`,{"data-testid":`auth-audit-row`,className:`px-3 py-2 text-xs space-y-0.5`,children:[e(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[r(`span`,{className:`font-medium text-foreground`,children:a.title}),r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Kt(t.at)})]}),e(`div`,{className:`flex flex-wrap gap-x-3 text-[11px] text-foreground-subtle`,children:[n!==null&&r(`span`,{className:`text-foreground`,children:n}),t.ip!==void 0&&r(`span`,{className:`font-mono`,children:t.ip}),a.details.map(e=>r(`span`,{className:`font-mono`,children:e},e))]})]})}s();function fn(e){let{ids:t,answered:r,legacyGroupParam:i=null,groupFirst:a}=e,[o]=ct(),s=o.get(it),c=i===null?null:o.get(i),l=o.get(ut),u=n(()=>at({ids:t,requested:s,answered:r,legacyGroup:c,...a===void 0?{}:{groupFirst:a}}),[t,s,r,c,a]),d=n(()=>(e,t)=>`?${st(o,e,i,t??null).toString()}`,[o,i]);return{...u,requestedSection:l,hrefFor:d}}s();var $={loginSessions:`login-sessions`,linkedApps:`linked-apps`,tokens:`tokens`,scopedTokens:`scoped-tokens`,adminTokens:`admin-tokens`,shareLinks:`share-links`,externalIdentities:`external-identities`,audit:`auth-audit`},pn={[$.scopedTokens]:$.tokens,[$.adminTokens]:$.tokens,[$.shareLinks]:$.tokens};function mn(){return[{id:$.loginSessions,label:K.t(`system.access.loginSessions`,`Login sessions`),icon:me,render:()=>r(nn,{})},{id:$.linkedApps,label:K.t(`system.access.linkedApps`,`Linked apps`),icon:b,render:()=>r(Qt,{})},{id:$.tokens,label:K.t(`system.access.tokens`,`Tokens`),icon:j,render:({createRequested:e,onCreateConsumed:t})=>r(Mt,{headerOwnsCreate:!0,createRequested:e,onCreateConsumed:t})},{id:$.externalIdentities,label:K.t(`system.access.signInLinks`,`Sign-in links`),icon:A,render:()=>r(Yt,{})},{id:$.audit,label:K.t(`system.access.audit`,`Audit`),icon:d,render:()=>r(cn,{})}]}function hn({createRequested:t=!1,onCreateConsumed:i}){let{t:a}=q(),o=n(()=>mn(),[]),s=fn({ids:n(()=>o.map(e=>e.id),[o]),answered:!0}),c=pt(),[l]=ct(),u=l.get(`integration`),d=u===null?void 0:pn[u];if(d!==void 0){let e=new URLSearchParams(l);return e.set(`integration`,d),r(ot,{to:`?${e.toString()}`,replace:!0})}let f=o.find(e=>e.id===s.selectedId)??o[0];return e(`div`,{className:`flex flex-col gap-3`,"data-testid":`access-page`,children:[r(R,{appearance:`pills`,value:f?.id??$.loginSessions,onValueChange:e=>{c(`?${st(l,e,null,null).toString()}`)},children:r(L,{"aria-label":a(`system.access.credentialKinds`,`Credential kinds`),children:o.map(t=>e(Re,{value:t.id,"data-testid":`access-kind-${t.id}`,children:[r(t.icon,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),t.label]},t.id))})}),f===void 0?null:r(`div`,{role:`region`,"aria-label":f.label,"data-testid":`access-kind-body`,children:f.render({createRequested:t&&f.id===$.tokens,onCreateConsumed:i??(()=>void 0)})},f.id)]})}function gn(t,n){if(t===$.tokens)return e(I,{size:`sm`,type:`button`,"data-testid":`access-new-token`,onClick:n,children:[r(j,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),K.t(`system.access.newToken`,`New token`)]})}function _n(){let[e,t]=a(!1);return{createRequested:e,requestCreate:()=>t(!0),clearCreate:()=>t(!1)}}function vn(){let{t}=q();return e(`div`,{className:`space-y-3 sm:space-y-4`,children:[r(bt,{functionCap:`login-method`,icon:de,title:t(`system.authentication.connectionsTitle`,`Sign-in connections`),subtitle:t(`system.authentication.connectionsSubtitle`,`Identity providers that sign users in. Each connection has its own id, which cannot be changed later.`),emptyTitle:t(`system.authentication.connectionsEmptyTitle`,`No sign-in connections`),emptyDescription:t(`system.authentication.connectionsEmptyDescription`,`Add a connection to let users sign in through an identity provider.`),addLabel:t(`system.authentication.addConnection`,`Add connection`),install:{capability:`login-method`,label:t(`system.authentication.sectionInstall`,`Add provider`)},typedId:()=>({pattern:lt})}),r(bn,{})]})}var yn=qt;function bn(){let{t}=q();return r(Me,{headingId:`authentication-policy`,title:t(`system.authentication.policyTitle`,`Sign-in policy`),icon:g,children:e(`div`,{className:f,children:[r(`p`,{className:`text-xs text-foreground-subtle`,children:t(`system.authentication.localAlwaysOn`,`Username and password sign-in is always on and cannot be turned off. It is not a connection, so it has no row above.`)}),r(`p`,{className:`text-xs text-foreground-subtle`,children:r(dt,{i18nKey:`system.authentication.totpNote`,components:{access:r(_t,{to:`/system/my-access?tab=sign-in`,className:`underline text-primary`}),users:r(_t,{to:`/system/identity?tab=users`,className:`underline text-primary`})}})}),r(Jt,{sectionIds:[yn],hideSectionChrome:!0,emptyMessage:t(`system.authentication.policyUnavailable`,`Not available — the addon that owns these settings did not answer.`)})]})})}function xn({isPending:t,error:n,what:i,onRetry:a,children:o}){let{t:s}=q();return t?e(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,role:`status`,"data-testid":`query-pending`,children:[r(p,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),s(`certificates.queryBody.reading`,{what:i})]}):n===null?o:r(H,{title:s(`certificates.queryBody.couldNotRead`,`Could not read {{what}}`,{what:i}),message:n.message.length>0?n.message:s(`certificates.queryBody.requestFailed`,`Request failed`),onRetry:a})}function Sn(){let{t}=q(),n=U.deviceCredentials.getDeviceCaStatus.useQuery({}),i=n.data;return r(J,{id:`device-ca`,title:t(`certificates.deviceCaCard.deviceCertificateAuthority`,`Device certificate authority`),icon:g,description:t(`certificates.deviceCaCard.signsTheCertificateEachPaired`,`Signs the certificate each paired device holds. It is created the first time a device is paired.`),children:r(xn,{isPending:n.isPending,error:n.error,what:`the device CA`,onRetry:()=>void n.refetch(),children:i!==void 0&&e(`div`,{className:`space-y-1`,"data-testid":`device-ca-status`,children:[e(W,{label:t(`certificates.deviceCaCard.state`,`State`),children:[i.state===`ready`&&r(G,{variant:`success`,children:t(`certificates.deviceCaCard.ready`,`Ready`)}),i.state===`absent`&&r(G,{variant:`default`,children:t(`certificates.deviceCaCard.notCreatedYet`,`Not created yet`)}),i.state===`unavailable`&&r(G,{variant:`danger`,children:t(`certificates.deviceCaCard.unavailable`,`Unavailable`)})]}),i.state===`ready`&&e(l,{children:[r(W,{label:t(`certificates.deviceCaCard.subject`,`Subject`),valueClassName:`font-mono`,children:i.subject}),r(W,{label:t(`certificates.deviceCaCard.fingerprintSha256`,`Fingerprint (SHA-256)`),valueClassName:`font-mono`,children:i.fingerprintSha256}),r(W,{label:t(`certificates.deviceCaCard.validUntil`,`Valid until`),children:i.validTo})]}),i.state===`unavailable`&&r(W,{label:t(`certificates.deviceCaCard.reason`,`Reason`),children:r(`span`,{className:`text-danger`,children:i.reason})})]})})})}s();function Cn(){let{t}=q(),n=U.useUtils(),i=U.deviceCredentials.getDeviceCertificateSettings.useQuery({}),[o,s]=a(null),c=U.deviceCredentials.setDeviceCertificateSettings.useMutation({onSuccess:()=>{s(null),n.deviceCredentials.getDeviceCertificateSettings.invalidate()},onError:e=>s(`Could not save: ${e.message}`)});return r(xn,{isPending:i.isPending,error:i.error,what:`the enrollment setting`,onRetry:()=>void i.refetch(),children:i.data!==void 0&&e(W,{label:t(`certificates.deviceSettingsRow.usersCanEnrollTheirOwn`,`Users can enroll their own devices`),actions:r(Ve,{checked:i.data.selfEnrollment===`allowed`,disabled:c.isPending,"aria-label":t(`certificates.deviceSettingsRow.usersCanEnrollTheirOwn`,`Users can enroll their own devices`),onCheckedChange:e=>c.mutate({selfEnrollment:e?`allowed`:`disabled`})}),children:[r(`span`,{className:`text-[11px] text-foreground-subtle`,children:i.data.selfEnrollment===`allowed`?t(`certificates.deviceSettingsRow.allowedAUserSignedIn`,`Allowed - a user signed in on a phone can keep it signed in. Pairing by QR works either way.`):t(`certificates.deviceSettingsRow.disabledOnlyAnAdminCan`,`Disabled - only an admin can pair a device, with a QR code.`)}),o!==null&&r(`span`,{className:`block text-[11px] text-danger`,children:o})]})})}s();function wn(e){let[t,n]=a(()=>Date.now());return i(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}s();var Tn=80,En=208;function Dn({open:t,users:n,onClose:i,onPaired:o}){let{t:s}=q(),c=U.deviceCredentials.startEnrollment.useMutation({onSuccess:o}),[l,u]=a(``),[d,f]=a(``),m=l===``?n[0]?.id??``:l,h=c.data,g=()=>{c.reset(),f(``),i()};return r($e,{open:t,onClose:g,title:s(`certificates.pairDeviceDialog.pairADevice`,`Pair a device`),icon:x,width:`md`,testId:`pair-device-dialog`,error:c.isError?c.error.message:null,footer:h===void 0?e(I,{type:`button`,onClick:()=>{let e=d.trim();m===``||e===``||c.mutate({userId:m,deviceName:e})},disabled:c.isPending||m===``||d.trim()===``,children:[c.isPending&&r(p,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),s(`certificates.pairDeviceDialog.createPairingCode`,`Create pairing code`)]}):r(I,{type:`button`,variant:`outline`,onClick:g,children:s(`certificates.pairDeviceDialog.done`,`Done`)}),children:h===void 0?e(`div`,{className:`space-y-3`,children:[r(`p`,{className:`text-[11px] text-foreground-subtle`,children:s(`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.`)}),r(V,{label:s(`certificates.pairDeviceDialog.user`,`User`),required:!0,children:r(O,{value:m,onChange:e=>u(e.target.value),options:n.map(e=>({value:e.id,label:e.username}))})}),r(V,{label:s(`certificates.pairDeviceDialog.deviceName`,`Device name`),required:!0,description:s(`certificates.pairDeviceDialog.howThisPhoneIsListed`,`How this phone is listed, e.g. Anna's iPhone.`),children:r(ge,{value:d,maxLength:Tn,onChange:e=>f(e.target.value),placeholder:s(`certificates.pairDeviceDialog.annaSIphone`,`Anna's iPhone`),autoFocus:!0})})]}):r(On,{enrollUrl:h.enrollUrl,expiresAt:h.expiresAt,hubKnown:h.hubOrigin!==null,onRestart:()=>c.reset()})})}function On({enrollUrl:t,expiresAt:n,hubKnown:i,onRestart:a}){let{t:o}=q(),s=Rt(n,wn(1e3));return r(`div`,{className:`space-y-3`,"data-testid":`pair-issued`,children:e(`div`,{className:`flex flex-col items-center gap-3 sm:flex-row sm:items-start`,children:[r(`div`,{className:s.expired?`opacity-30`:void 0,children:r(xe,{value:t,size:En,alt:o(`certificates.pairDeviceDialog.enrollmentQrCode`,`Enrollment QR code`)})}),e(`div`,{className:`min-w-0 flex-1 space-y-2`,children:[r(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`certificates.pairDeviceDialog.openTheCamstackAppOn`,`Open the CamStack app on the phone and scan this code. It works once.`)}),r(`div`,{className:`text-sm font-semibold tabular-nums text-foreground`,role:`timer`,"data-testid":`pair-countdown`,children:s.expired?o(`certificates.pairDeviceDialog.expiredCreateANewCode`,`Expired - create a new code`):o(`certificates.pairDeviceDialog.expiresIn`,`Expires in {{label}}`,{label:s.label})}),e(`div`,{className:`flex items-center gap-1 rounded-md border border-border bg-background px-2 py-1`,children:[r(`code`,{className:`min-w-0 flex-1 select-all break-all font-mono text-[11px] text-foreground`,children:t}),r(Fe,{value:t,srLabel:`Enrollment link`})]}),!i&&e(`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:[r(E,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),r(`span`,{children:o(`certificates.pairDeviceDialog.theHubCouldNotName`,`The hub could not name an address for this link, so the app must already know it.`)})]}),s.expired&&r(I,{type:`button`,variant:`outline`,size:`sm`,onClick:a,children:o(`certificates.pairDeviceDialog.newCode`,`New code`)})]})]})})}s();var kn={key:`access.nouns.device`};function An({pairOpen:t,onPairClose:i}){let{t:o}=q(),s=D(),c=ie(),l=U.useUtils(),u=U.deviceCredentials.listDeviceCredentials.useQuery({includeRevoked:!0}),d=Oe(),[f,p]=a(null),[m,h]=a(null),g=()=>void l.deviceCredentials.listDeviceCredentials.invalidate(),_=e=>t=>{h(null),p(`${e} failed: ${t.message}`)},v=()=>{h(null),g()},b=U.deviceCredentials.revokeDeviceCredential.useMutation({onSuccess:v,onError:_(`Revoke`)}),S=U.deviceCredentials.deleteDeviceCredential.useMutation({onSuccess:e=>{e.result!==`deleted`&&p(e.result===`live`?`Only a revoked device can be deleted: revoke it first.`:`That device no longer exists.`),v()},onError:_(`Delete`)}),C=U.deviceCredentials.renameDeviceCredential.useMutation({onSuccess:v,onError:_(`Rename`)}),w=St(kn,e=>b.mutateAsync({id:e}),g),T=w.busy||m!==null,E=n(()=>(u.data??[]).map(Lt),[u.data]),O=async e=>{await s({title:o(`certificates.devicesCard.revoke`,`Revoke "{{name}}"?`,{name:e.name}),message:o(`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:o(`certificates.devicesCard.revoke2`,`Revoke`),variant:`danger`})&&(p(null),h(e.id),b.mutate({id:e.id}))},ne=async e=>{await s({title:o(`certificates.devicesCard.delete`,`Delete "{{name}}"?`,{name:e.name}),message:o(`certificates.devicesCard.isRemovedFromTheList`,`{{name}} is removed from the list. The audit trail keeps the revocation.`,{name:e.name}),confirmLabel:o(`common.delete`,`Delete`),variant:`danger`})&&(p(null),h(e.id),S.mutate({id:e.id}))},re=async e=>{let t=(await c({title:o(`certificates.devicesCard.renameDevice`,`Rename device`),label:o(`certificates.devicesCard.deviceName`,`Device name`),defaultValue:e.name,confirmLabel:o(`certificates.devicesCard.rename`,`Rename`)}))?.trim()??``;t===``||t===e.name||(p(null),h(e.id),C.mutate({id:e.id,deviceName:t}))},ae={label:o(`certificates.devicesCard.revoke2`,`Revoke`),icon:y,isAvailable:Et,onRun:e=>void O(e),busyId:b.isPending?m:null,disabled:T},oe=[{label:o(`certificates.devicesCard.rename`,`Rename`),icon:te,tone:`neutral`,isAvailable:()=>!0,onRun:e=>void re(e),busyId:C.isPending?m:null,disabled:T},{label:o(`common.delete`,`Delete`),icon:ee,isAvailable:Nt,onRun:e=>void ne(e),busyId:S.isPending?m:null,disabled:T}];return e(J,{id:`devices`,title:o(`certificates.devicesCard.devices`,`Devices`),icon:x,description:o(`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:Y(f,w.outcome),onDismissNotice:()=>{p(null),w.dismiss()},children:[r(Cn,{}),r(Wt,{rows:E,label:o(`certificates.devicesCard.label`),isLoading:u.isPending,loadError:u.error===null?null:u.error.message||`Request failed`,emptyText:`No devices paired yet.`,expiresNone:`—`,action:ae,extraActions:oe,bulk:{revoke:w,noun:kn,isSelectable:Et}}),r(Dn,{open:t,users:d.data??[],onClose:i,onPaired:g})]})}var jn=/-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----/,Mn=/-----BEGIN ((?:RSA |EC |ENCRYPTED )?PRIVATE KEY)-----[\s\S]+?-----END \1-----/,Nn={certificate:`.pem,.crt,.cer`,privateKey:`.pem,.key`,ca:`.pem,.crt,.cer`};function Pn(e,t){if(t.trim()===``)return null;if(e===`privateKey`){let e=Mn.exec(t);return e===null?jn.test(t)?K.t(`helpers.pemFile.isCert`):K.t(`helpers.pemFile.notKey`):e[1]===`ENCRYPTED PRIVATE KEY`?K.t(`helpers.pemFile.encrypted`):null}return jn.test(t)?e===`certificate`&&Mn.test(t)?K.t(`helpers.pemFile.certHasKey`):null:Mn.test(t)?K.t(`helpers.pemFile.isKey`):K.t(`helpers.pemFile.notCert`)}function Fn(e){return e.text()}s();function In({kind:n,label:i,value:o,onChange:s,rows:c=6}){let{t:l}=q(),u=t(null),[d,f]=a(null),[p,m]=a(null),h=p??Pn(n,o),g=`pem-${n}`,_=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t!==void 0){f(t.name);try{let e=await Fn(t);m(null),s(e)}catch(e){m(`Could not read ${t.name}: ${e instanceof Error?e.message:String(e)}`)}}};return e(`div`,{className:`space-y-1`,children:[e(`div`,{className:`flex items-center justify-between gap-2`,children:[r(`label`,{htmlFor:g,className:`text-[11px] text-foreground-subtle`,children:i}),e(`div`,{className:`flex min-w-0 items-center gap-2`,children:[d!==null&&r(`span`,{className:`truncate font-mono text-[10px] text-foreground-subtle`,"data-testid":`${g}-file-name`,children:d}),r(Qe,{ref:u,accept:Nn[n],onChange:e=>void _(e),className:`hidden`,"data-testid":`${g}-file`}),e(I,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>u.current?.click(),children:[r(fe,{className:`mr-1 h-3 w-3`}),l(`system.pemField.chooseFile`,`Choose file`)]})]})]}),r(Xe,{id:g,value:o,onChange:e=>{f(null),m(null),s(e.target.value)},rows:c,"aria-invalid":h!==null,className:`w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`}),h!==null&&r(`p`,{className:`text-[11px] text-danger`,role:`alert`,children:h})]})}s();var Ln=30;function Rn(e){let t=Date.parse(e);return!Number.isNaN(t)&&Date.now()-t<Ln*864e5}function zn(e){if(e===null||e===``)return`—`;let t=e.replace(/:/g,``);return t.length<=16?e:`${t.slice(0,8)}…${t.slice(-8)}`}function Bn(){let{t}=q(),n=c(),i=et(void 0,{refetchInterval:15e3}),o=Ue({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),s=We({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),l=Be({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),d=tt({onSuccess:()=>{h(!1),_(``),y(``),x(``),n.invalidateQueries({queryKey:[[`localNetwork`]]})}}),p=i.data,[m,h]=a(!1),[g,_]=a(``),[v,y]=a(``),[b,x]=a(``),S=()=>{if(!p?.caCertPem)return;let e=new Blob([p.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=p?.mode===`uploaded`?`Uploaded`:p?.mode===`generated`?`Generated local CA`:`TLS disabled`;return r(Me,{headingId:`local-access-certificate`,title:t(`system.localAccess.certificate`,`Certificate`),icon:u,children:e(`div`,{className:`${f} space-y-3`,children:[i.isError&&r(`p`,{className:`text-xs text-danger`,children:t(`system.localAccess.couldNotReadTlsStatus`,`Could not read TLS status.`)}),p?.reissueError&&r(H,{variant:`warning`,title:t(`system.localAccess.certificateReissue`,`Certificate reissue`),message:p.reissueError}),p?.restartRequired&&r(H,{variant:`warning`,title:t(`system.localAccess.restartRequired`,`Restart required`),message:t(`system.localAccess.theHttpsListenerStillServes`,`The HTTPS listener still serves the previous certificate. Restart the hub to apply it.`)}),p?.caMissing===!0&&r(H,{variant:`warning`,title:t(`system.localAccess.caMissingTitle`,`CA missing - devices cannot trust this hub`),message:t(`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).")}),p?.caReplacedAt!=null&&Rn(p.caReplacedAt)&&r(H,{variant:`warning`,title:t(`system.localAccess.caReplacedTitle`,`The local CA was replaced - re-install it on your devices`),message:t(`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(p.caReplacedAt).toLocaleString()})}),e(`dl`,{className:`grid grid-cols-1 gap-2 text-xs sm:grid-cols-2`,children:[e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.mode`,`Mode`)}),r(`dd`,{className:`font-medium`,children:C})]}),e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.validTo`,`Valid to`)}),r(`dd`,{className:`font-mono`,children:p?.validTo?new Date(p.validTo).toLocaleString():`—`})]}),e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.leafSha256`,`Leaf SHA-256`)}),r(`dd`,{className:`font-mono`,title:p?.leafFingerprintSha256??void 0,children:zn(p?.leafFingerprintSha256??null)})]}),p?.storedUpload!=null&&e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.storedUpload`,`Stored upload`)}),r(`dd`,{className:`font-medium`,children:t(`system.localAccess.storedUploadValue`,`valid to {{validTo}}, {{ca}}`,{validTo:new Date(p.storedUpload.validTo).toLocaleDateString(),ca:p.storedUpload.hasCa?t(`system.localAccess.storedUploadWithCa`,`with its CA`):t(`system.localAccess.storedUploadNoCa`,`no CA`)})})]}),e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.caSha256`,`CA SHA-256`)}),r(`dd`,{className:`font-mono`,title:p?.caFingerprintSha256??void 0,children:p?.mode===`uploaded`&&p.caFingerprintSha256===null?r(`span`,{className:`font-sans text-foreground-subtle`,children:t(`system.localAccess.issuerNotIncludedInThe`,`Issuer not included in the upload (not the local CA)`)}):zn(p?.caFingerprintSha256??null)})]})]}),p&&p.sans.length>0&&r(`div`,{className:`flex flex-wrap gap-1`,children:p.sans.map(e=>r(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 font-mono text-[10px] text-foreground-subtle`,children:e},e))}),e(`div`,{className:`flex flex-wrap gap-2`,children:[r(P,{label:t(`system.localAccess.regenerate`,`Regenerate`),title:t(`system.localAccess.issueANewLeaf`,`Issue a new leaf?`),description:t(`system.localAccess.issuesANewLeafUnder`,`Issues a new leaf under the current local CA. Clients that trust the CA keep working. The HTTPS listener reloads.`),confirmLabel:t(`system.localAccess.regenerate`,`Regenerate`),disabled:p?.mode===`uploaded`||o.isPending,action:()=>o.mutateAsync({})}),r(I,{size:`sm`,variant:`outline`,onClick:()=>h(e=>!e),children:t(`system.localAccess.upload`,`Upload`)}),p?.caCertPem&&r(I,{size:`sm`,variant:`outline`,onClick:S,children:t(`system.localAccess.downloadCa`,`Download CA`)}),p?.mode===`uploaded`&&r(P,{label:t(`system.localAccess.revertToGenerated`,`Revert to generated`),title:t(`system.localAccess.revertTitle`,`Switch back to the generated certificate?`),description:t(`system.localAccess.keepsTheUploadedPair`,`Returns to the generated local CA. The uploaded certificate and its CA stay stored here; you can select them again.`),confirmLabel:t(`system.localAccess.revert`,`Revert`),disabled:s.isPending,action:()=>s.mutateAsync({})}),p?.mode===`generated`&&p.storedUpload!=null&&r(P,{label:t(`system.localAccess.useUploaded`,`Use uploaded certificate`),title:t(`system.localAccess.useUploadedTitle`,`Serve the stored upload again?`),description:t(`system.localAccess.useUploadedDescription`,`The stored uploaded certificate replaces the generated one on the HTTPS listener. The generated certificate stays stored.`),confirmLabel:t(`system.localAccess.useUploaded`,`Use uploaded certificate`),disabled:l.isPending,action:()=>l.mutateAsync(void 0)})]}),m&&e(`div`,{className:`space-y-2 border-t border-border pt-3`,children:[r(In,{kind:`certificate`,label:t(`system.localAccess.certificateOrFullChainPem`,`Certificate or full chain (PEM)`),value:g,onChange:_}),r(In,{kind:`privateKey`,label:t(`system.localAccess.privateKeyPem`,`Private key (PEM)`),value:v,onChange:y}),r(In,{kind:`ca`,label:t(`system.localAccess.caPemRequired`,`CA (PEM) - required unless the certificate comes from a public CA`),value:b,onChange:x,rows:4}),r(I,{size:`sm`,disabled:!g.trim()||!v.trim()||Pn(`certificate`,g)!==null||Pn(`privateKey`,v)!==null||Pn(`ca`,b)!==null||d.isPending,onClick:()=>d.mutate({certPem:g,keyPem:v,...b.trim()?{caPem:b}:{}}),children:t(`system.localAccess.saveCertificate`,`Save certificate`)}),d.isError&&r(`p`,{className:`text-xs text-danger`,children:d.error instanceof Error?d.error.message:t(`system.localAccess.uploadFailed`,`Upload failed`)})]})]})})}var Vn={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`};function Hn(e){let t=e.find(e=>e.isHub);return t?.https.kind===`served`?t.https.status.caFingerprintSha256:null}function Un({https:t,mesh:n,now:i}){let{t:a}=q(),o=et().data?.caCertPem??``,s=()=>{if(o===``)return;let e=URL.createObjectURL(new Blob([o],{type:`application/x-pem-file`})),t=document.createElement(`a`);t.href=e,t.download=`camstack-ca.crt`,t.click(),URL.revokeObjectURL(e)},c=n?.ca,l=c?.state===`ready`?Date.parse(c.validTo):null,u=n?.listener;return e(`div`,{className:`space-y-1`,"data-testid":`ca-strip`,children:[r(W,{label:a(`certificates.caStrip.localHttpsCaSha256`,`Local HTTPS CA (SHA-256)`),valueClassName:`font-mono`,children:e(`span`,{className:`flex flex-wrap items-center gap-2`,children:[Hn(t)??`—`,o!==``&&e(I,{type:`button`,variant:`ghost`,size:`sm`,onClick:s,children:[r(se,{className:`h-3 w-3`,"aria-hidden":!0}),a(`certificates.caStrip.downloadCa`,`Download CA`)]})]})}),r(W,{label:a(`certificates.caStrip.clusterCaSha256`,`Cluster CA (SHA-256)`),valueClassName:`font-mono`,children:c===void 0?`—`:c.state===`ready`?c.fingerprintSha256:r(`span`,{className:`text-danger`,children:a(`certificates.caStrip.unavailable`,{reason:c.reason})})}),c?.state===`ready`&&e(W,{label:a(`certificates.caStrip.clusterCaValidUntil`,`Cluster CA valid until`),children:[c.validTo,l!==null&&!Number.isNaN(l)&&e(`span`,{className:`ml-2 text-[10px] ${Vn[Ht(l,i)]}`,children:[`(`,Ot(l,i),`)`]})]}),u!==void 0&&e(W,{label:a(`certificates.caStrip.nodeListener`,`Node listener`),children:[u.state===`open`&&r(G,{variant:`success`,children:a(`certificates.caStrip.open`,`Open`)}),u.state===`not-started`&&r(G,{variant:`default`,children:a(`certificates.caStrip.notStarted`,`Not started`)}),u.state===`closed`&&e(`span`,{className:`text-danger`,children:[a(`certificates.caStrip.closedSince`,{when:kt(u.since)}),` `,u.reason]})]}),n!==void 0&&!n.registryAvailable&&e(`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:[r(E,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),r(`span`,{children:a(`certificates.caStrip.theCertificateRegistryIsNot`,`The certificate registry is not up, so the node list below is incomplete.`)})]})]})}function Wn(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 Gn(e){return e.isHub?K.t(`helpers.nodesModel.hubReissued`):e.mesh===null?K.t(`helpers.nodesModel.noCertRecorded`):e.online?null:K.t(`helpers.certificateModel.nodeOffline`)}function Kn(e){return e.isHub||e.mesh===null?Gn(e):null}var qn={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`},Jn={enroll:`Issued at enrollment`,renewal:`Issued by a renewal`,boot:`Issued at boot`,pairing:`Issued at pairing`,observed:`Observed on its connection`},Yn={uploaded:`Uploaded`,generated:`Generated`,disabled:`Disabled`};function Xn(e){let t=e.https?.https;return t?.kind===`served`?Bt(t.status.validTo):null}function Zn({ms:t,now:n}){return t===null?r(`span`,{className:`text-foreground-subtle`,children:`—`}):e(`div`,{children:[r(`div`,{children:kt(t)}),r(`div`,{className:`text-[10px] ${qn[Ht(t,n)]}`,children:Ot(t,n)})]})}function Qn({row:t}){let{t:n}=q(),i=t.https?.https;return i===void 0?r(`span`,{className:`text-foreground-subtle`,children:`—`}):i.kind===`served`?e(`div`,{title:i.status.leafFingerprintSha256??``,children:[r(G,{variant:`success`,className:`text-[10px]`,children:n(`certificates.nodesColumns.served`,`Served`)}),r(`span`,{className:`ml-1.5 text-[10px] text-foreground-subtle`,children:Yn[i.status.mode]}),r(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:zt(i.status.leafFingerprintSha256)}),i.status.sans.length>0&&r(`div`,{className:`mt-0.5 max-w-[14rem] truncate font-mono text-[10px] text-foreground-subtle`,title:i.status.sans.join(`, `),children:i.status.sans.join(`, `)})]}):e(`div`,{className:`max-w-[16rem]`,children:[r(G,{variant:i.kind===`unreadable`?`danger`:`warning`,className:`text-[10px]`,children:i.kind===`unreadable`?n(`certificates.nodesColumns.unreadable`,`Unreadable`):n(`certificates.nodesColumns.notServed`,`Not served`)}),r(`div`,{className:`mt-1 whitespace-normal text-[10px] text-foreground-subtle`,children:i.reason})]})}function $n({row:t}){let{t:n}=q(),i=t.mesh?.current??null;if(i===null)return r(`span`,{className:`text-foreground-subtle`,children:n(`certificates.nodesColumns.noneRecorded`,`None recorded`)});let a=t.mesh?.history.length??0;return e(`div`,{children:[r(`div`,{className:`font-mono text-[11px]`,title:i.serial,children:It(i.serial)}),r(`div`,{className:`font-mono text-[10px] text-foreground-subtle`,title:i.fingerprintSha256,children:zt(i.fingerprintSha256)}),e(`div`,{className:`text-[10px] text-foreground-subtle`,children:[Jn[i.issuedVia],a>0?` · ${n(`certificates.nodesColumns.earlier`,{count:a})}`:``]})]})}function er({row:e}){let{t}=q(),n=e.mesh?.presentingCurrent??null;return n===null?r(`span`,{className:`text-foreground-subtle`,children:e.online?`—`:t(`certificates.nodesColumns.offline`,`Offline`)}):n?r(G,{variant:`success`,className:`text-[10px]`,children:t(`common.yes`,`Yes`)}):r(G,{variant:`warning`,className:`text-[10px]`,children:t(`certificates.nodesColumns.noPresentsAnother`,`No - presents another`)})}function tr(t){let n=t.icon;return e(I,{type:`button`,variant:`ghost`,size:`sm`,className:t.danger?`text-danger hover:bg-danger/10`:void 0,disabled:t.reason!==null||t.busy,title:t.reason??void 0,"aria-label":t.ariaLabel,onClick:t.onClick,children:[t.spinning?r(p,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):r(n,{className:`h-3 w-3`,"aria-hidden":!0}),t.label]})}function nr({reasons:t}){let{t:n}=q();return e(Ie,{className:`inline-block`,children:[r(Pe,{children:r(`span`,{className:`cursor-help text-[11px] text-foreground-subtle`,"data-testid":`hub-managed-note`,children:n(`certificates.nodesColumns.managedByTheHub`,`Managed by the hub`)})}),r(ze,{children:r(`ul`,{className:`max-w-xs space-y-1 whitespace-normal text-left text-[11px]`,children:t.map(e=>r(`li`,{children:e},e))})})]})}function rr({row:t,o:n}){let{t:i}=q(),a=t.https===null?`No HTTPS inventory for this node.`:At(t.https).reason,o=Gn(t),s=Kn(t),c=e=>n.running?.nodeId===t.nodeId&&n.running.action===e,l=e=>!t.isHub||e===null,u=[a,o,s].filter((e,t,n)=>e!==null&&n.indexOf(e)===t);return e(`div`,{className:`flex w-44 flex-col items-end gap-1`,children:[e(`div`,{className:`flex flex-col items-end gap-0.5`,children:[l(a)&&r(tr,{label:i(`certificates.nodesColumns.renewHttps`,`Renew HTTPS`),ariaLabel:i(`certificates.nodesColumns.renewTheCertificateOn`,`Renew the certificate on {{nodeId}}`,{nodeId:t.nodeId}),icon:m,reason:a,busy:n.busy,spinning:c(`renew-https`),danger:!1,onClick:()=>n.onRenewHttps(t)}),l(o)&&r(tr,{label:c(`renew-identity`)?i(`certificates.nodesColumns.renewing`,`Renewing…`):i(`certificates.nodesColumns.renewIdentity`,`Renew identity`),ariaLabel:i(`certificates.nodesColumns.renewTheClusterCertificateOf`,`Renew the cluster certificate of {{nodeId}}`,{nodeId:t.nodeId}),icon:m,reason:o,busy:n.busy,spinning:c(`renew-identity`),danger:!1,onClick:()=>n.onRenewIdentity(t)}),l(s)&&r(tr,{label:i(`certificates.nodesColumns.revokeIdentity`,`Revoke identity`),ariaLabel:i(`certificates.nodesColumns.revokeTheClusterCertificateOf`,`Revoke the cluster certificate of {{nodeId}}`,{nodeId:t.nodeId}),icon:y,reason:s,busy:n.busy,spinning:c(`revoke-identity`),danger:!0,onClick:()=>n.onRevokeIdentity(t)})]}),t.isHub&&u.length>0&&r(nr,{reasons:u}),!t.isHub&&a!==null&&t.https!==null&&r(`div`,{className:`w-full whitespace-normal text-right text-[10px] text-foreground-subtle`,"data-testid":`renew-reason-${t.nodeId}`,children:a}),!t.isHub&&o!==null&&r(`div`,{className:`w-full whitespace-normal text-right text-[10px] text-foreground-subtle`,"data-testid":`mesh-reason-${t.nodeId}`,children:o})]})}function ir(t){return[{key:`node`,header:K.t(`certificates.nodesColumns.node`,`Node`),sortValue:e=>e.isHub?``:e.nodeId.toLowerCase(),render:t=>e(`div`,{className:`flex items-center gap-1.5`,children:[r(`span`,{className:`font-medium text-foreground`,children:t.nodeId}),t.nodeId===`hub`&&r(G,{variant:`info`,className:`text-[10px]`,children:K.t(`common.hubWord`)}),!t.online&&r(G,{variant:`default`,className:`text-[10px]`,children:K.t(`common.offline`)})]})},{key:`https-state`,header:`HTTPS`,notSortableReason:`A state with a reason has no single order.`,render:e=>r(Qn,{row:e})},{key:`https-expires`,header:K.t(`certificates.nodesColumns.httpsExpires`,`HTTPS expires`),sortValue:e=>Xn(e),render:e=>r(Zn,{ms:Xn(e),now:t.now})},{key:`identity`,header:K.t(`certificates.nodesColumns.identity`,`Identity`),sortValue:e=>e.mesh?.current?.serial??null,render:e=>r($n,{row:e})},{key:`identity-expires`,header:K.t(`certificates.nodesColumns.identityExpires`,`Identity expires`),sortValue:e=>e.mesh?.current?.notAfter??null,render:e=>r(Zn,{ms:e.mesh?.current?.notAfter??null,now:t.now})},{key:`presenting`,header:K.t(`certificates.nodesColumns.inUse`,`In use`),notSortableReason:`Offline nodes have no answer to order by.`,render:e=>r(er,{row:e})},{key:`actions`,header:K.t(`certificates.nodesColumns.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order.`,render:e=>r(rr,{row:e,o:t})}]}s();function ar(){let{t}=q(),i=D(),o=U.useUtils(),s=wn(6e4),c=U.certificates.listHttpsCertificates.useQuery(),l=U.certificates.getMeshCertificates.useQuery(),[u,d]=a(null),[f,p]=a(null),[m,g]=a(null),_=()=>{g(null),o.certificates.listHttpsCertificates.invalidate(),o.certificates.getMeshCertificates.invalidate()},v=e=>(t,n)=>{g(null),d(`${n.nodeId}: ${e} - ${t.message}`)},y=U.certificates.renewHttpsOnNode.useMutation({onSuccess:(e,n)=>{p({tone:`success`,message:e.restartRequired?t(`certificates.nodesCard.newCertificateIssuedRestartThe`,`{{nodeId}}: new certificate issued. Restart the node to serve it.`,{nodeId:n.nodeId}):t(`certificates.nodesCard.newCertificateIssuedAndServed`,`{{nodeId}}: new certificate issued and served.`,{nodeId:n.nodeId})}),_()},onError:v(`renewal failed`)}),b=U.certificates.renewMeshOnNode.useMutation({onSuccess:e=>{p(Ft(e)),_()},onError:v(`renewal could not start`)}),x=U.certificates.revokeMeshOnNode.useMutation({onSuccess:e=>{p({tone:`success`,message:`${e.nodeId}: ${e.next}`}),_()},onError:v(`revoke failed`)}),S=y.isPending||b.isPending||x.isPending,C=(e,t)=>{d(null),p(null),g({nodeId:e,action:t})},w=async e=>{await i({title:t(`certificates.nodesCard.renewHttpsOn`,`Renew HTTPS on "{{nodeId}}"?`,{nodeId:e.nodeId}),message:e.isHub?t(`certificates.nodesCard.aNewCertificateIsIssued`,`A new certificate is issued from the local CA. Clients that trust the CA keep working.`):t(`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:t(`certificates.nodesCard.renew`,`Renew`)})&&(C(e.nodeId,`renew-https`),y.mutate({nodeId:e.nodeId}))},T=e=>{C(e.nodeId,`renew-identity`),b.mutate({nodeId:e.nodeId})},E=async e=>{await i({title:t(`certificates.nodesCard.revokeTheIdentityOf`,`Revoke the identity of "{{nodeId}}"?`,{nodeId:e.nodeId}),message:t(`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:e.nodeId}),confirmLabel:t(`certificates.nodesCard.revokeAndDisconnect`,`Revoke and disconnect`),variant:`danger`})&&(C(e.nodeId,`revoke-identity`),x.mutate({nodeId:e.nodeId}))},O=ir({now:s,busy:S,running:m,onRenewHttps:e=>void w(e),onRenewIdentity:T,onRevokeIdentity:e=>void E(e)}),ee=n(()=>Wn(c.data??[],l.data),[c.data,l.data]),te=l.data?.registryAvailable??!0;return r(J,{id:`nodes`,title:t(`certificates.nodesCard.nodes`,`Nodes`),icon:h,description:t(`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:Y(u,f),onDismissNotice:()=>{d(null),p(null)},children:r(xn,{isPending:c.isPending||l.isPending,error:c.error??l.error,what:`node certificates`,onRetry:()=>{c.refetch(),l.refetch()},children:e(`div`,{className:`space-y-3`,children:[r(Un,{https:c.data??[],mesh:l.data,now:s}),r(ye,{columns:O,rows:ee,rowKey:e=>e.nodeId,minWidthPx:960,maxBodyHeight:qe,defaultSort:{columnKey:`node`,dir:`asc`},emptyMessage:te?t(`certificates.nodesCard.noNodesReported`,`No nodes reported.`):t(`certificates.nodesCard.theCertificateRegistryIsNot`,`The certificate registry is not available yet, so nodes cannot be listed.`)})]})})})}function or({pairOpen:t,onPairClose:n}){return e(`div`,{className:`space-y-4`,"data-testid":`certificates-page`,children:[r(An,{pairOpen:t,onPairClose:n}),r(Sn,{}),r(Bn,{}),r(ar,{})]})}function sr({userId:t,username:n,onClose:i}){let{t:a}=q(),o=D(),s=U.useUtils(),c=ve({userId:t}),l=U.auth.listLoginMethods.useQuery(),u=Ee({onSuccess:()=>void s.userManagement.listExternalIdentities.invalidate()}),d=new Map((l.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),f=c.data??[],m=async(e,r)=>{await o({title:a(`users.externalIdentitiesModal.removeSignInLink`,`Remove sign-in link`),message:a(`users.externalIdentitiesModal.willNoLongerBeAble`,`"{{username}}" will no longer be able to sign in with this {{label}} account.`,{username:n,label:r}),confirmLabel:a(`common.remove`,`Remove`),variant:`danger`})&&u.mutate({userId:t,provider:e.provider,subject:e.subject})};return r(Ye,{open:!0,onOpenChange:e=>!e&&i(),children:e(Ke,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`external-identities-modal`,children:[r(B,{children:e(F,{className:`flex items-center gap-2`,children:[r(b,{className:`h-4 w-4 text-primary`}),e(`span`,{children:[a(`users.externalIdentitiesModal.linkedSignInAccounts`,`Linked sign-in accounts`),e(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[a(`users.externalIdentitiesModal.user`,`User:`),` `,r(`span`,{className:`font-mono`,children:n})]})]})]})}),r(N,{className:`space-y-3`,children:c.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(p,{className:`h-3.5 w-3.5 animate-spin`}),a(`common.loading`,`Loading…`)]}):f.length===0?r(`p`,{className:`text-xs text-foreground-subtle`,children:a(`users.externalIdentitiesModal.noLinkedAccountsOnlyThe`,`No linked accounts. Only the user can link one, from their own profile page.`)}):r(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:f.map(t=>{let n=d.get(t.provider),i=n??t.provider;return e(`li`,{className:`flex items-center gap-3 px-3 py-2 text-xs`,children:[e(`div`,{className:`flex-1 min-w-0`,children:[e(`div`,{className:`font-medium text-foreground truncate`,children:[i,n===void 0&&r(`span`,{className:`ml-2 rounded bg-foreground-subtle/15 px-1.5 py-0.5 text-[10px] font-normal text-foreground-subtle`,children:a(`users.externalIdentitiesModal.providerUnavailable`,`provider unavailable`)})]}),e(`div`,{className:`text-[11px] text-foreground-subtle truncate`,children:[t.label??t.subject,` ·`,` `,new Date(t.linkedAt).toLocaleDateString()]})]}),e(I,{variant:`unstyled`,onClick:()=>void m(t,i),disabled:u.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:[r(he,{className:`h-3 w-3`}),a(`common.remove`,`Remove`)]})]},`${t.provider}|${t.subject}`)})})}),r(z,{children:r(I,{onClick:i,variant:`secondary`,children:a(`common.close`,`Close`)})})]})})}function cr({userId:t,username:n,onClose:i}){let{t:a}=q(),o=c(),s=D(),u=Je({userId:t}),d=u.data,f=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),m=je({onSuccess:()=>{f(),i()}}),h=u.isLoading?`loading`:d?.enabled?`enrolled`:`not_enrolled`;return r(Ye,{open:!0,onOpenChange:e=>!e&&i(),children:e(Ke,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[r(B,{children:e(F,{className:`flex items-center gap-2`,children:[r(x,{className:`h-4 w-4 text-primary`}),e(`span`,{children:[a(`users.totpModal.twoFactorAuthentication`,`Two-factor authentication`),e(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[a(`users.totpModal.user`,`User:`),` `,r(`span`,{className:`font-mono`,children:n})]})]})]})}),e(N,{className:`space-y-4`,children:[h===`loading`&&e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(p,{className:`h-3.5 w-3.5 animate-spin`}),a(`users.totpModal.checkingStatus`,`Checking status…`)]}),h===`not_enrolled`&&e(`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:[r(C,{className:`h-4 w-4 mt-0.5 shrink-0`}),e(`div`,{children:[r(`div`,{className:`font-medium text-foreground`,children:a(`users.totpModal.2faNotEnrolled`,`2FA not enrolled`)}),r(`p`,{className:`mt-0.5`,children:a(`users.totpModal.onlyTheUserThemselvesCan`,`Only the user themselves can enable 2FA, from their own profile page.`)})]})]}),h===`enrolled`&&d&&e(l,{children:[e(`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:[r(T,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),e(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[r(`div`,{className:`font-medium`,children:a(`users.totpModal.2faIsActive`,`2FA is active`)}),r(`div`,{className:`text-foreground-subtle`,children:a(`common.enrolledOn`,{when:d.confirmedAt?new Date(d.confirmedAt).toLocaleString():`—`})})]})]}),r(`div`,{className:`text-[11px] text-foreground-subtle`,children:a(`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.`)}),e(`div`,{className:`flex justify-end gap-2`,children:[r(I,{onClick:i,variant:`secondary`,children:a(`common.close`,`Close`)}),e(I,{variant:`unstyled`,onClick:async()=>{await s({title:a(`users.totpModal.remove2fa`,`Remove 2FA`),message:a(`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:n}),confirmLabel:a(`common.remove`,`Remove`),variant:`danger`})&&m.mutate({userId:t})},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?r(p,{className:`h-3 w-3 animate-spin`}):r(oe,{className:`h-3 w-3`}),a(`users.totpModal.remove2fa`,`Remove 2FA`)]})]})]})]})]})})}s();function lr({userId:t,username:n,onClose:i}){let{t:o}=q(),{user:s,logout:c}=nt(),l=s?.id===t,u=D(),d=U.useUtils(),f=U.auth.listSessions.useQuery({userId:t}),[m,h]=a(null),g=U.auth.revokeSessions.useMutation({onSuccess:(e,t)=>{if(l&&`userId`in t){c();return}d.auth.listSessions.invalidate()},onError:e=>h(`Sign out failed: ${e.message}`)}),_=async e=>{await u({title:o(`users.userSessionsModal.signOutThisSession`,`Sign out this session`),message:o(`users.userSessionsModal.onWillHaveToSign`,`"{{username}}" on {{label}} will have to sign in again.`,{username:n,label:Tt(e.client).label}),confirmLabel:o(`users.userSessionsModal.signOut`,`Sign out`),variant:`danger`})&&(h(null),g.mutate({id:e.id}))},v=async()=>{await u({title:o(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`),message:l?o(`users.userSessionsModal.everySessionOfYourOwn`,`Every session of your own account ends, this browser included: you will be signed out here too.`):o(`users.userSessionsModal.everySessionOfEndsAt`,`Every session of "{{username}}" ends at once; each device has to sign in again.`,{username:n}),confirmLabel:o(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`),variant:`danger`})&&(h(null),g.mutate({userId:t}))},y=g.isPending&&g.variables!==void 0&&`id`in g.variables?g.variables.id:null;return r(Ye,{open:!0,onOpenChange:e=>!e&&i(),children:e(Ke,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`user-sessions-modal`,children:[r(B,{children:e(F,{className:`flex items-center gap-2`,children:[r(me,{className:`h-4 w-4 text-primary`}),e(`span`,{children:[o(`users.userSessionsModal.activeSessions`,`Active sessions`),e(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[o(`users.userSessionsModal.user`,`User:`),` `,r(`span`,{className:`font-mono`,children:n})]})]})]})}),e(N,{className:`space-y-3`,children:[m!==null&&r(`div`,{className:`text-[11px] text-danger`,children:m}),r(Vt,{sessions:f.data??[],isLoading:f.isLoading,loadError:f.isError?f.error?.message??`Request failed`:null,emptyText:`No active sessions.`,onRevoke:e=>void _(e),revokingId:y})]}),e(z,{className:`justify-between`,children:[e(I,{variant:`unstyled`,onClick:()=>void v(),disabled:g.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:[g.isPending&&y===null?r(p,{className:`h-3 w-3 animate-spin`}):r(M,{className:`h-3 w-3`}),o(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`)]}),r(I,{onClick:i,variant:`secondary`,children:o(`common.close`,`Close`)})]})]})})}function ur({scopes:t,invalidReason:n}){let{t:i}=q(),a=ae(),s=o({queryKey:[`auth`,`previewScope`,t,!1],enabled:n===null,queryFn:()=>a.trpcClient.auth.previewScope.query({scopes:[...t],isAdmin:!1})}),{data:c}=Ae({projection:`slim`}),l=c?.length??null;if(n!==null)return e(`p`,{className:`flex items-center gap-1.5 text-[11px] text-warning`,"data-testid":`role-preview`,children:[r(v,{className:`h-3 w-3 shrink-0`}),n]});if(s.isLoading)return e(`p`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,"data-testid":`role-preview`,children:[r(p,{className:`h-3 w-3 shrink-0 animate-spin`}),i(`users.rolePreview.resolving`)]});if(s.isError||!s.data)return r(`p`,{className:`text-[11px] text-danger`,"data-testid":`role-preview`,children:i(`users.rolePreview.couldNotResolve`)});let u=s.data.viewableDeviceCount,d=s.data.device.view.all?i(`users.rolePreview.everyDevice`,{count:u}):l===null?i(`users.rolePreview.devicesVisible`,{count:u}):i(`users.rolePreview.devicesVisibleOf`,{count:u,total:l});return e(`p`,{className:`flex items-center gap-1.5 text-[11px] ${u===0?`text-warning`:`text-foreground`}`,"data-testid":`role-preview`,children:[u===0?r(v,{className:`h-3 w-3 shrink-0`}):r(ne,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),u===0?i(`users.rolePreview.noDevice`):d]})}function dr(e){let t=le(e.scopes??[]);if(t===null)return{role:e.isAdmin?`admin`:`viewer`,mode:`except`,pickedIds:[],viewer:ce,unconfigured:!e.isAdmin};let n=vr(t);return{role:e.isAdmin?`admin`:`viewer`,mode:n.mode,pickedIds:n.pickedIds,viewer:yr(n.mode,n.pickedIds,t.features),unconfigured:!1}}function fr(e,t){return{...e,role:t}}function pr(e,t){return{...e,mode:t,viewer:yr(t,e.pickedIds,e.viewer.features)}}function mr(e,t){let n=br(t);return{...e,pickedIds:n,viewer:yr(e.mode,n,e.viewer.features)}}function hr(e,t,n){let r=e.viewer.features.filter(e=>e!==t),i=n?[...r,t]:r;return{...e,viewer:yr(e.mode,e.pickedIds,i)}}function gr(e){return e.role===`viewer`&&e.mode===`only`&&e.pickedIds.length===0?`no-allowed-device`:null}function _r(e){return gr(e)===null?e.role===`admin`?{isAdmin:!0,scopes:[]}:{isAdmin:!1,scopes:[e.viewer]}:null}function vr(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 yr(e,t,n){let r=br(t);return e===`except`?{type:`viewer`,allow:`*`,block:r,features:[...n]}:{type:`viewer`,allow:r,block:[],features:[...n]}}function br(e){return[...new Set(e)]}s();var xr=`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`;function Sr(e,t){return e?`failed`:t===void 0?`pending`:`answered`}function Cr(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 wr({user:t,isSelf:i,onClose:o,onSubmit:s,submitting:c,error:u}){let{t:d}=q(),[f,m]=a(n(()=>dr(t),[t])),h=Ae({projection:`slim`}),g=h.data,_=Sr(h.isError,g),v=n(()=>Cr(g??[]),[g]),y=n(()=>({state:_,devices:_===`answered`?(g??[]).map(e=>({id:e.id,name:e.name})):void 0}),[_,g]),b=gr(f),x=_r(f),C=b===`no-allowed-device`?d(`users.userAccessModal.pickAllowedDevice`):null,w=e=>{m(fr(f,e))},T=[{value:`except`,label:d(`users.userAccessModal.modeExcept`)},{value:`only`,label:d(`users.userAccessModal.modeOnly`)}];return r(Ye,{open:!0,onOpenChange:e=>!e&&o(),children:e(Ke,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-2xl`,children:[r(B,{children:r(F,{children:d(`users.userAccessModal.title`,{name:t.username})})}),e(N,{className:`space-y-4`,children:[f.unconfigured&&f.role===`viewer`&&r(H,{variant:`warning`,title:d(`users.userAccessModal.noAccessYet`),message:d(`users.userAccessModal.noAccessYetDetail`,{name:t.username})}),e(`section`,{className:`space-y-2`,children:[r(`h3`,{className:xr,children:d(`users.userAccessModal.role`)}),e(`div`,{role:`radiogroup`,"aria-label":d(`users.userAccessModal.role`),className:`grid gap-1.5 sm:grid-cols-2`,children:[r(Tr,{name:`admin`,checked:f.role===`admin`,label:d(`users.userAccessModal.admin`),description:d(`users.userAccessModal.adminDescription`),onPick:()=>w(`admin`)}),r(Tr,{name:`viewer`,checked:f.role===`viewer`,disabled:i,label:d(`users.userAccessModal.viewer`),description:d(i?`users.userAccessModal.cannotDemoteSelf`:`users.userAccessModal.viewerDescription`),onPick:()=>w(`viewer`)})]})]}),f.role===`viewer`&&e(l,{children:[e(`section`,{className:`space-y-3`,children:[r(`h3`,{className:xr,children:d(`users.userAccessModal.devices`)}),r(we,{label:d(`users.userAccessModal.whichDevices`),value:f.mode,options:T,onChange:e=>m(pr(f,e))}),r(_e,{devices:v,listState:_,fleet:y,value:[...f.pickedIds],onChange:e=>m(mr(f,e)),emptyMeansAll:f.mode===`except`,noun:`device`,testId:`viewer-device-picker`}),r(ur,{scopes:x?.scopes??[],invalidReason:C})]}),e(`section`,{className:`space-y-2`,children:[r(`h3`,{className:xr,children:d(`users.userAccessModal.features`)}),r(`div`,{className:`space-y-1`,children:k.map(t=>e(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-md p-1.5 hover:bg-surface-hover`,children:[r(S,{className:`mt-0.5`,checked:f.viewer.features.includes(t.id),onChange:e=>m(hr(f,t.id,e.target.checked))}),e(`span`,{className:`min-w-0`,children:[r(`span`,{className:`block text-[12px] font-medium text-foreground`,children:d(`users.viewerFeatures.${t.id}.label`,t.label)}),r(`span`,{className:`block text-[10px] text-foreground-subtle`,children:d(`users.viewerFeatures.${t.id}.description`,t.description)})]})]},t.id))})]})]}),u!==null&&r(H,{message:u})]}),e(z,{children:[r(I,{variant:`outline`,size:`sm`,onClick:o,children:d(`common.cancel`,`Cancel`)}),r(I,{size:`sm`,onClick:()=>x!==null&&s(x),disabled:c||x===null,children:c?r(p,{className:`h-3 w-3 animate-spin`}):d(`users.userAccessModal.saveAccess`)})]})]})})}function Tr({name:t,checked:n,disabled:i=!1,label:a,description:o,onPick:s}){return e(`label`,{className:`flex items-start gap-2 rounded-lg border p-2.5 transition-colors ${n?`border-primary bg-primary/5`:`border-border hover:bg-surface-hover`} ${i?`cursor-not-allowed opacity-60`:`cursor-pointer`}`,children:[r(Ze,{name:`user-role`,value:t,checked:n,disabled:i,onChange:s,className:`mt-0.5`}),e(`span`,{className:`min-w-0`,children:[r(`span`,{className:`block text-[12px] font-medium text-foreground`,children:a}),r(`span`,{className:`block text-[10px] text-foreground-subtle`,children:o})]})]})}s();var Er=8;function Dr(){return{username:``,password:``,isAdmin:!1}}function Or(e){return{id:e.id,username:e.username,password:``,isAdmin:e.isAdmin}}function kr(e){return e instanceof Error?e.message:K.t(`admin.system.users.genericError`)}function Ar(){let{t}=q(),n=c(),{user:o}=nt(),{state:s,openNew:u,openEdit:d,close:f}=He(),[m,h]=a(null),[_,v]=a(null),[y,C]=a(!1),{data:T,isLoading:E,isError:O,error:ne,refetch:ae}=Oe(),oe=D(),se=ie(),k=()=>n.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),ce=Se(),le=be({onSuccess:k}),A=De({onSuccess:k}),j=ke({onSuccess:k}),ue=Ce(),[M,de]=a(null),[fe,he]=a(!1),[_e,ve]=a(null),[N,P]=a(null),[xe,F]=a(null),[we,Ee]=a(null),L=T??[],R=s.mode===`edit`?L.find(e=>e.id===s.id)??null:null,z=()=>{h(null),v(null),C(!1),ce.reset(),A.reset(),f()};i(()=>{if(s.mode===`closed`){h(null),v(null),C(!1);return}if(s.mode===`new`){h(e=>e!==null&&e.id===void 0?e:Dr());return}if(R===null){E||f();return}h(e=>e?.id===R.id?e:Or(R))},[s,R,E,f]);let Ae=s.mode===`new`&&m!==null&&m.id===void 0||s.mode===`edit`&&m!==null&&R!==null;async function je(e){await oe({title:t(`admin.system.users.deleteUser`,`Delete user`),message:t(`admin.system.users.permanentlyDeleteUserThisCannot`,`Permanently delete user "{{username}}"? This cannot be undone — any active sessions will be revoked on next request.`,{username:e.username}),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&(le.mutate({id:e.id}),s.mode===`edit`&&s.id===e.id&&z())}async function Me(e){let n=await se({title:t(`admin.system.users.resetPassword`,`Reset password`),message:t(`admin.system.users.setANewPasswordFor`,`Set a new password for "{{username}}".`,{username:e.username}),label:t(`admin.system.users.newPassword`,`New password`),inputType:`password`,placeholder:t(`admin.system.users.atLeast8Characters`,`At least 8 characters`),confirmLabel:t(`admin.system.users.continue`,`Continue`),validate:e=>e.length<Er?K.t(`admin.system.users.passwordTooShort`,{min:Er}):null});n===null||n.length===0||await oe({title:t(`admin.system.users.resetPassword`,`Reset password`),message:t(`admin.system.users.resetThePasswordForThey`,`Reset the password for "{{username}}"? They will need to use the new password on their next login.`,{username:e.username}),confirmLabel:t(`common.reset`,`Reset`)})&&j.mutate({id:e.id,newPassword:n})}function Ne(e){ve(null),de(e)}async function B(e,t){he(!0),ve(null);try{t.isAdmin!==e.isAdmin&&await A.mutateAsync({id:e.id,isAdmin:t.isAdmin}),await ue.mutateAsync({userId:e.id,scopes:[...t.scopes]}),de(null)}catch(e){ve(kr(e))}finally{he(!1),k()}}async function Pe(){if(m!==null){v(null);try{if(m.id===void 0){let e=m.username.trim();if(e===``||m.password.length<Er)return;await ce.mutateAsync({username:e,password:m.password,isAdmin:m.isAdmin})}else await A.mutateAsync({id:m.id,isAdmin:m.isAdmin});k(),z()}catch(e){v(kr(e))}}}function Fe(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}let Ie=ce.isPending||A.isPending,Re=m!==null&&m.id===void 0&&m.username.trim()!==``&&m.password.length>=Er,ze=m!==null&&m.id!==void 0,Be=Ie||(m?.id===void 0?!Re:!ze),Ve=e=>le.isPending&&le.variables?.id===e.id||A.isPending&&A.variables?.id===e.id||j.isPending&&j.variables?.id===e.id,Ue=[{key:`username`,header:t(`admin.system.users.username`,`Username`),sortValue:e=>e.username,render:e=>r(`span`,{className:`font-medium text-foreground`,"data-testid":`user-open-${e.id}`,children:e.username})},{key:`scopes`,header:t(`admin.system.users.access`,`Access`),sortValue:e=>jr(e),render:n=>r(`span`,{onClick:e=>e.stopPropagation(),children:e(I,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>Ne(n),disabled:Ve(n),title:t(`admin.system.users.configureAccess`,`Configure access`),"data-testid":`user-access-${n.id}`,children:[r(g,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),r(Mr,{user:n})]})})},{key:`createdAt`,header:t(`admin.system.users.created`,`Created`),nowrap:!0,sortValue:e=>e.createdAt,render:e=>r(`span`,{className:`text-foreground-subtle`,children:Fe(e.createdAt)})},{key:`actions`,header:t(`admin.system.users.actions`,`Actions`),align:`right`,nowrap:!0,notSortableReason:`Row actions`,render:n=>{let i=Ve(n),a=n.id!==o?.id&&n.totpEnabled;return e(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[e(I,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>d(n.id),disabled:i,title:t(`admin.system.users.editUser`,`Edit user`),children:[r(te,{className:`h-3 w-3`}),t(`common.edit`,`Edit`)]}),a&&e(I,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>P(n),disabled:i,title:t(`admin.system.users.removeTwoFactorAuthentication`,`Remove two-factor authentication`),children:[r(x,{className:`h-3 w-3`}),t(`admin.system.users.remove2fa`,`Remove 2FA`)]}),e(I,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>F(n),disabled:i,title:t(`admin.system.users.linkedSignInAccounts`,`Linked sign-in accounts`),children:[r(b,{className:`h-3 w-3`}),t(`admin.system.users.signInLinks`,`Sign-in links`)]}),e(I,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>Ee(n),disabled:i,title:t(`admin.system.users.activeSessions`,`Active sessions`),children:[r(me,{className:`h-3 w-3`}),t(`admin.system.users.sessions`,`Sessions`)]}),e(I,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void Me(n),disabled:i,title:t(`admin.system.users.resetPassword`,`Reset password`),children:[r(pe,{className:`h-3 w-3`}),t(`admin.system.users.resetPassword`,`Reset password`)]}),e(I,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void je(n),disabled:i,title:t(`admin.system.users.deleteUser`,`Delete user`),className:`text-danger hover:bg-danger/10`,children:[i?r(p,{className:`h-3 w-3 animate-spin`}):r(ee,{className:`h-3 w-3`}),t(`common.delete`,`Delete`)]})]})}}];return e(yt,{embedded:!0,icon:w,title:t(`admin.system.users.users`,`Users`),subtitle:t(`admin.system.users.hubAccountsAdminFlagAccess`,`Hub accounts, admin flag, access scopes, sessions and sign-in links.`),actions:e(I,{size:`sm`,type:`button`,onClick:()=>{v(null),u()},children:[r(re,{className:`h-3.5 w-3.5`}),t(`admin.system.users.createUser`,`Create User`)]}),children:[O&&r(H,{title:t(`admin.system.users.couldNotLoadUsers`,`Could not load users`),message:kr(ne),onRetry:()=>void ae()}),E&&e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(p,{className:`h-3.5 w-3.5 animate-spin`}),t(`common.loading`,`Loading…`)]}),!E&&!O&&L.length===0&&r(Te,{icon:w,title:t(`admin.system.users.noUsersYet`,`No users yet`),description:t(`admin.system.users.createAUserToGrant`,`Create a user to grant hub access.`)}),!E&&!O&&L.length>0&&r(ye,{columns:Ue,rows:L,rowKey:e=>e.id,minWidthPx:560,maxBodyHeight:`max-h-[60vh]`,onRowClick:e=>d(e.id)}),r($e,{open:Ae,onClose:z,title:m?.id===void 0?t(`admin.system.users.createUser`,`Create User`):t(`admin.system.users.edit`,`Edit {{value1}}`,{value1:m.username||`user`}),icon:w,error:_,testId:`user-form-dialog`,footer:r(I,{size:`sm`,type:`button`,disabled:Be,onClick:()=>void Pe(),children:Ie?e(l,{children:[r(p,{className:`h-3.5 w-3.5 animate-spin`}),t(`admin.system.users.saving`,`Saving…`)]}):m?.id===void 0?t(`admin.system.users.create`,`Create`):t(`common.save`,`Save`)}),children:m!==null&&e(`div`,{className:`space-y-3`,children:[r(V,{label:t(`admin.system.users.username`,`Username`),required:m.id===void 0,children:r(ge,{value:m.username,onChange:e=>h({...m,username:e.target.value}),placeholder:`john`,autoFocus:m.id===void 0,disabled:m.id!==void 0,"data-testid":`user-form-username`})}),m.id===void 0&&r(V,{label:t(`admin.system.users.password`,`Password`),required:!0,description:t(`admin.system.users.atLeastCharacters`,`At least {{value1}} characters.`,{value1:String(Er)}),children:r(Le,{value:m.password,onValueChange:e=>h({...m,password:e}),shown:y,onToggleShown:()=>C(e=>!e),placeholder:`••••••••`,"data-testid":`user-form-password`})}),r(V,{label:t(`admin.system.users.admin`,`Admin`),description:t(`admin.system.users.unrestrictedAccessToEveryCapability`,`Unrestricted access to every capability and device.`),children:e(`label`,{className:`inline-flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[r(S,{checked:m.isAdmin,onChange:e=>h({...m,isAdmin:e.target.checked}),className:`rounded border-border focus:ring-primary`,"data-testid":`user-form-admin`}),r(`span`,{children:t(`admin.system.users.admin`,`Admin`)})]})}),m.id!==void 0&&r(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`admin.system.users.toChangeThePasswordUse`,`To change the password, use Reset password on the user's row. Access scopes are configured from the Access column.`)})]})}),N&&r(cr,{userId:N.id,username:N.username,onClose:()=>P(null)}),xe&&r(sr,{userId:xe.id,username:xe.username,onClose:()=>F(null)}),we&&r(lr,{userId:we.id,username:we.username,onClose:()=>Ee(null)}),M&&r(wr,{user:M,isSelf:M.id===o?.id,onClose:()=>de(null),onSubmit:e=>void B(M,e),submitting:fe,error:_e})]})}function jr(e){let t=dr(e);return t.role===`admin`?0:t.unconfigured?2:1}function Mr({user:t}){let{t:n}=q(),i=dr(t);if(i.role===`admin`)return r(`span`,{className:`font-medium text-foreground`,children:n(`users.accessSummary.admin`)});if(i.unconfigured)return r(`span`,{className:`font-medium text-warning`,children:n(`admin.system.users.noAccess`,`No access`)});let{allow:a,block:o,features:s}=i.viewer,c=a===`*`?n(`users.accessSummary.allDevices`):n(`users.accessSummary.devices`,{count:a.length});return e(`span`,{className:`text-foreground-subtle`,children:[r(`span`,{className:`font-medium text-foreground`,children:n(`users.accessSummary.viewer`)}),` ·`,` `,c,o.length>0&&e(l,{children:[` · `,n(`users.accessSummary.blocked`,{count:o.length})]}),s.length>0&&e(l,{children:[` · `,n(`users.accessSummary.features`,{count:s.length})]})]})}s();var Nr={"api-keys":$.tokens,"linked-sessions":$.linkedApps},Pr=`certificates`;function Fr(t){return e(I,{size:`sm`,type:`button`,"data-testid":`certificates-pair-device`,onClick:t,children:[r(x,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),K.t(`systemPage.identity.pairADevice`,`Pair a device`)]})}function Ir(){let{t:e}=q(),[t]=ct(),n=_n(),[i,o]=a(!1),s=Nr[t.get(`tab`)??``];if(s!==void 0)return r(ot,{to:gt(`access`,{integration:s}),replace:!0});let c=rt(`/system/identity`,{t:e,isAdmin:!0})??{icon:_,title:e(`system.identity`,`Identity & Access`)},l=t.get(`tab`)??`users`,u=t.get(`integration`),d=l===ht.access.tab?gn(u,n.requestCreate):l===`certificates`?Fr(()=>o(!0)):void 0;return r(vt,{icon:c.icon,title:c.title,defaultSection:`users`,sectionsLabel:`${c.title} sections`,actions:d,sections:[{id:`users`,label:e(`systemPage.identity.users`,`Users`),content:r(Ar,{})},{id:ht.access.tab,label:e(`systemPage.identity.tokensSessions`,`Tokens & sessions`),ownedParams:ft.concat([jt.token,jt.scoped,jt.admin]),content:r(hn,{createRequested:n.createRequested,onCreateConsumed:n.clearCreate})},{id:Pr,label:e(`systemPage.identity.certificates`,`Certificates`),content:r(or,{pairOpen:i,onPairClose:()=>o(!1)})},{id:ht.authentication.tab,label:e(`systemPage.identity.authentication`,`Authentication`),content:r(vn,{}),ownedParams:ft}]})}export{Ir as IdentityPage};
@@ -1 +0,0 @@
1
- import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,a as s,et as c,o as l,x as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Bn as d,Fa as f,Fn as p,Fr as m,Jn as h,Kn as g,Li as _,Ot as v,Qi as y,Ua as b,Ui as x,Xt as S,Za as C,Zn as w,ea as T,en as E,mi as D,pi as O,rr as ee,vt as k,yi as A}from"./player-overlays-BxDm01PX.js";import{Ns as j}from"./client-DbKXlEC4.js";import{t as M}from"./chevron-down-CBb-F8DT.js";import{t as N}from"./search-x-C5ra3Aft.js";import{$f as P,Ai as F,At as te,Bc as ne,Cr as I,Cs as L,Fc as R,Fi as z,Fo as B,Gf as V,Hc as H,Io as U,Is as W,Jr as G,Kr as K,Mc as re,Ni as ie,Nr as ae,Ns as oe,Os as q,Pi as J,Rc as Y,Ss as se,Ts as ce,Us as X,Vc as le,Ws as Z,Yr as ue,cc as de,ds as fe,ei as pe,fa as me,fs as he,gs as ge,i as Q,ji as _e,ki as ve,lr as ye,ls as be,ms as xe,no as Se,oa as Ce,ps as we,qr as Te,r as Ee,ri as De,us as Oe,vp as ke,vs as Ae,vt as je,xp as Me,xt as Ne,ys as Pe,yt as Fe,zc as Ie}from"./src-Cn1TCE2g.js";import{t as $}from"./useTranslation-BJr-n0es.js";import{J as Le,Mt as Re,X as ze,Y as Be,bt as Ve,ct as He,dt as Ue,ft as We,hi as Ge,li as Ke,lt as qe,mi as Je,nt as Ye,pi as Xe,ut as Ze}from"./index-cl6SWsBh.js";import{t as Qe}from"./useAdminDeviceRemoval-CVX0q4fL.js";import{t as $e}from"./device-integration-icon-CpZ0OBPQ.js";c();function et(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...et(n.fields));return t}function tt(e,t,i){let[a,s]=o(`idle`),[c,l]=o({}),u=n(()=>{let t=[];for(let n of e.sections)t.push(...et(n.fields));return t},[e]),d=u.length>0&&i!==void 0,f=r(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:a,hasProbeFields:d,probeResults:c,handleTestAll:r(async()=>{if(!i)return;let e=u.filter(e=>{let n=t[e];return n!=null&&String(n).trim()!==``});if(e.length===0)return;s(`testing`);let n={};for(let t of e)n[t]={status:`probing`};l(n);let r=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await i(e,t[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),a={};for(let e of r)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;a[t]={status:n.status===`ok`?`ok`:`error`,result:n}}l(a),s(`idle`)},[i,u,t]),clearProbeResult:f}}c();function nt(e){let t=[];for(let n of e)`required`in n&&n.required===!0&&`key`in n&&n.key&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...nt(n.fields));return t}function rt(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function it(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){it(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function at(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function ot(e,t){let n=X({addonId:e,integrationId:t}),r=n.data?.deviceType??null,i=q({addonId:e,integrationId:t,type:r??j.Camera},{enabled:n.isSuccess&&r!==null});return n.isError?`unavailable`:n.isLoading?`loading`:r===null||i.isError?`unavailable`:i.isLoading||!i.isSuccess?`loading`:((i.data??null)?.sections??[]).some(e=>e.fields.length>0)?`available`:`unavailable`}function st({integrationId:t,addonId:s,onClose:c}){let{t:f}=$(),p=l(),[h,g]=o({}),[_,y]=o(!1),[b,x]=o(null),[C,w]=o(at),T=X({addonId:s,integrationId:t},{enabled:!0}),E=T.data?.deviceType??null,D=q({addonId:s,integrationId:t,type:E??j.Camera},{enabled:T.isSuccess&&E!==null}),O=D.data??null;a(()=>{g(O?it(O.sections.flatMap(e=>e.fields)):{}),w(at()),y(!1),x(null)},[!0,t,O]);let ee=n(()=>({...h,_probeRequestId:C}),[h,C]),k=Ae({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),A=de(),N=r(async(e,t)=>{y(!0);let n=await A.mutateAsync({addonId:s,type:E??j.Camera,key:e,value:t,formValues:ee});return n.status===`ok`&&n.suggestedValues&&g(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))rt(e[i])&&!rt(a)&&(r[i]=a,t=!0);return t?r:e}),n},[A,s,ee,E]),{testAllStatus:P,hasProbeFields:te,probeResults:ne,handleTestAll:I,clearProbeResult:L}=tt(O??{sections:[]},h,N);async function R(e){x(null);try{await k.mutateAsync({addonId:s,type:E??j.Camera,config:h,integrationId:t}),e?g(O?it(O.sections.flatMap(e=>e.fields)):{}):c()}catch(e){x(e instanceof Error?e.message:String(e))}}let z=nt((O?.sections??[]).flatMap(e=>e.fields)).filter(e=>rt(h[e])),B=z.length===0,H=T.isLoading||E!==null&&D.isLoading,U=T.isError||T.isSuccess&&E===null||D.isError||D.isSuccess&&O===null;return e(u,{children:[i(F,{className:`space-y-3`,children:H?i(`div`,{className:`flex items-center justify-center py-8`,children:i(m,{className:`h-5 w-5 animate-spin text-primary`})}):U?e(`div`,{className:`flex items-start gap-3 rounded-lg border border-danger/40 bg-danger/10 px-4 py-3`,children:[i(S,{className:`h-4 w-4 text-danger mt-0.5 shrink-0`}),e(`div`,{className:`space-y-1`,children:[i(`p`,{className:`text-xs font-medium text-danger`,children:f(`integrations.addDeviceDialog.providerUnavailable`,`Provider unavailable`)}),i(`p`,{className:`text-xs text-foreground-subtle`,children:i(Ke,{i18nKey:`integrations.addDeviceDialog.notReady`,values:{addonId:s},components:{mono:i(`span`,{className:`font-mono`})}})})]})]}):i(Re,{schema:O,values:h,onChange:g,onTestField:N,probeResults:ne,onClearProbe:L})}),!U&&!H&&e(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[e(V,{variant:`unstyled`,type:`button`,onClick:()=>y(e=>!e),className:`flex w-full items-center justify-between px-3 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[e(`span`,{className:`flex items-center gap-2`,children:[i(d,{className:`h-3.5 w-3.5`}),f(`integrations.addDeviceDialog.testLogs`,`Test logs`),i(`span`,{className:`font-mono text-[9px] opacity-60`,children:C.slice(0,14)})]}),i(M,{className:`h-3.5 w-3.5 transition-transform ${_?`rotate-180`:``}`})]}),_&&i(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:i(ye,{addonId:s,requestId:C,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!U&&!H&&(b||z.length>0)&&i(`div`,{className:`border-t border-danger/30 bg-danger/5 px-3 py-2 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(S,{className:`h-3.5 w-3.5 text-danger mt-0.5 shrink-0`}),i(`p`,{className:`text-[11px] text-danger`,children:b||f(`integrations.addDeviceDialog.required`,`Required: {{value1}}`,{value1:z.join(`, `)})})]})}),e(ie,{className:`justify-between`,children:[e(`div`,{className:`flex items-center gap-2`,children:[i(V,{variant:`unstyled`,onClick:c,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:f(`integrations.cancel`)}),!U&&te&&e(V,{variant:`unstyled`,type:`button`,onClick:I,disabled:P===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[P===`testing`?i(m,{className:`h-3.5 w-3.5 animate-spin`}):i(v,{className:`h-3.5 w-3.5`}),f(`integrations.addDeviceDialog.testAll`,`Test All`)]})]}),e(`div`,{className:`flex items-center gap-2`,children:[i(V,{variant:`unstyled`,onClick:()=>R(!0),disabled:U||!B||k.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:f(`integrations.saveAndNew`)}),i(V,{variant:`unstyled`,onClick:()=>R(!1),disabled:U||!B||k.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:k.isPending?f(`integrations.saving`):f(`integrations.save`)})]})]})]})}var ct=1500;function lt({addonId:t,integrationId:n,jobId:r,onFinished:a}){let{t:o}=$(),s=Oe(),c=(we({addonId:t,integrationId:n},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?ct:!1}).data??[]).find(e=>e.jobId===r);if(!c)return null;let l=c.state===`running`,u=c.processed,d=c.total>0?Math.round(u/c.total*100):0;!l&&c.finishedAt!==null&&a();let f=[`${u}/${c.total} ${o(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];c.adopted>0&&f.push(`${c.adopted} ${o(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),c.alreadyAdopted>0&&f.push(`${c.alreadyAdopted} ${o(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),c.failed>0&&f.push(`${c.failed} ${o(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let p=f.join(` · `);return e(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[e(`div`,{className:`flex items-center gap-2`,children:[l?i(m,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):c.failed>0?i(S,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):c.state===`cancelled`?i(_,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):i(x,{className:`h-3.5 w-3.5 text-primary shrink-0`}),i(`p`,{className:`text-[11px] text-foreground`,children:p}),l&&i(V,{variant:`unstyled`,onClick:()=>s.mutate({jobId:r}),className:`ml-auto rounded-lg border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:o(`integrations.adoptJobCancel`,{defaultValue:`Stop`})})]}),i(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:i(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${d}%`},role:`progressbar`,"aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100})}),c.results.filter(e=>e.outcome===`failed`).slice(0,5).map(t=>e(`p`,{className:`text-[11px] text-destructive`,children:[t.childNativeId,`: `,t.error]},t.childNativeId))]})}function ut(e){let t=e.map(e=>({...e,stableId:e.childNativeId})),n=new Map(e.map(e=>[e.childNativeId,e])),r=(e,t,i)=>e.flatMap(e=>{let a=n.get(e.candidate.childNativeId);return a===void 0?[]:[{candidate:a,depth:t,...i===void 0?{}:{parentName:i}},...r(e.children,t+1,a.name)]});return r(Be(t),0)}function dt(e){let t=e.metadata?.model,n=e.childNativeId.split(`:`).pop()??``;return[typeof t==`string`?t:``,n].filter(e=>e.length>0).join(` · `)}function ft(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}c();var pt=`devices`;function mt(e){return{id:pt,label:e(`integrations.adoptDevicesModal.defaultFilter`),isDefault:!0}}var ht=2e4,gt=100;function _t({addonId:s,integrationId:c,onClose:d}){let f=C(),{t:p}=$(),h=l(),[_,v]=o(new Set),[y,x]=o(new Set),[w,E]=o(new Map),[D,O]=o(null),{data:ee}=ne(),k=(ee??[]).find(e=>e.addonId===s)?.supportsLocationImport??!1,[A,j]=o(!0),M=fe({addonId:s,integrationId:c}).data?.filters,N=M&&M.length>0?M:[mt(p)],[P,F]=o(N.find(e=>e.isDefault)?.id??(N.some(e=>e.id===pt)?pt:N[0].id)),te=P!==pt,I=xe(),L=he({addonId:s,integrationId:c,page:1,pageSize:ht,filter:P}),R=L.refetch,z=I.mutate,B=r(()=>{z({addonId:s,integrationId:c},{onSettled:()=>{R()}})},[z,s,c,R]),H=t(null);a(()=>{let e=`${s}::${c}`;H.current===e||L.isLoading||(H.current=e,(L.data?.candidates.length??0)===0&&B())},[s,c,L.isLoading,L.data,B]);let U=I.isPending,W=I.isError?I.error instanceof Error?I.error.message:String(I.error):null,G=typeof I.data?.lastError==`string`&&I.data.lastError.length>0?I.data.lastError:null,K=L.data?.candidates??[],re=n(()=>ut(K),[K]),ae=n(()=>new Map(re.map(e=>[e.candidate.childNativeId,e.depth])),[re]),oe=n(()=>new Map(re.map(e=>[e.candidate.childNativeId,e.parentName])),[re]),q=L.isError?L.error instanceof Error?L.error.message:String(L.error):null,J=ge(),[Y,se]=o(null),ce=r(e=>{e.alreadyAdopted||v(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),X=r(e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),le=r((e,t)=>{E(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),Z=r(e=>{let t={};for(let n of e){let e=w.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[w]),ue=r(async()=>{O(null);let e=[..._];if(e.length!==0)try{let t=Z(e),{jobId:n}=await J.mutateAsync({addonId:s,integrationId:c,filter:P,childNativeIds:e,...t?{perCandidate:t}:{},...k?{importLocations:A}:{}});se(n),v(new Set),E(new Map)}catch(e){O(e instanceof Error?e.message:String(e))}},[_,Z,J,s,c,P,k,A]),de=t(null),pe=r(()=>{Y===null||de.current===Y||(de.current=Y,R(),h.invalidateQueries({queryKey:[[`integrations`]]}),h.invalidateQueries({queryKey:[[`deviceManager`]]}))},[Y,R,h]),me=r(e=>{F(e),v(new Set),x(new Set),E(new Map),O(null)},[]),Q=_.size,_e=Y!==null&&Q===0&&!J.isPending;return e(u,{children:[k&&e(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[i(b,{checked:A,onChange:e=>j(e.target.checked),className:`accent-primary`}),p(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),e(`div`,{className:`flex-1 min-h-0 flex flex-col gap-2 overflow-hidden`,children:[(W??q??G)&&K.length===0&&i(`div`,{className:`rounded-lg border border-danger/30 bg-danger/5 px-4 py-3 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(S,{className:`h-3.5 w-3.5 text-danger mt-0.5 shrink-0`}),e(`div`,{className:`min-w-0`,children:[i(`p`,{className:`text-xs font-medium text-danger`,children:p(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),i(`p`,{className:`text-[11px] text-danger/90 mt-0.5`,children:W??q??G})]})]})}),N.length>1&&i(vt,{filters:N,activeFilter:P,onSelect:me}),i(`div`,{className:`flex-1 min-h-0`,children:i(je,{mode:`generic`,items:re.map(e=>e.candidate),pageSize:gt,getKey:e=>e.childNativeId,getSearchText:ft,getFilterType:e=>e.type,filterOptions:ke(f),filterLabel:p(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:L.isLoading||U&&K.length===0,searchPlaceholder:p(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(W??q??G)&&K.length===0?``:p(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:e(V,{variant:`unstyled`,type:`button`,onClick:B,disabled:U,title:p(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[i(g,{className:`h-3.5 w-3.5 ${U?`animate-spin`:``}`}),p(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:p(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-full sm:w-[55%]`,cellClassName:`max-w-0`,cell:e=>i(yt,{candidate:e,depth:ae.get(e.childNativeId)??0,...oe.get(e.childNativeId)===void 0?{}:{containerName:oe.get(e.childNativeId)},expandable:!te,expanded:y.has(e.childNativeId),onToggleExpand:()=>X(e.childNativeId),adoptedLabel:p(`integrations.adoptAlready`,{defaultValue:`Adopted`}),typeLabel:Me(e.type,f).label})},{key:`type`,header:p(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:t=>{let n=Me(t.type,f),r=n.icon;return e(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[i(r,{className:`h-3.5 w-3.5 shrink-0`}),n.label]})}},{key:`select`,header:``,headerClassName:`w-10 sm:w-[15%] text-right`,cellClassName:`text-right`,cell:e=>i(`div`,{className:`flex items-center justify-end`,children:i(V,{variant:`unstyled`,onClick:()=>ce(e),disabled:e.alreadyAdopted,"aria-label":_.has(e.childNativeId)?p(`integrations.adoptDevicesModal.deselect`,`Deselect`):p(`integrations.adoptDevicesModal.select`,`Select`),className:`inline-flex h-5 w-5 items-center justify-center rounded border ${_.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:_.has(e.childNativeId)&&i(T,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!te&&y.has(e.childNativeId),renderExpanded:te?void 0:e=>i(bt,{candidate:e,hiddenChildIds:w.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>le(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:_.has(e.childNativeId)?`bg-primary/5`:``})})]}),D&&i(`div`,{className:`border-t border-danger/30 bg-danger/5 px-3 py-2 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(S,{className:`h-3.5 w-3.5 text-danger mt-0.5 shrink-0`}),i(`p`,{className:`text-[11px] text-danger`,children:D})]})}),Y!==null&&i(lt,{addonId:s,integrationId:c,jobId:Y,onFinished:pe}),e(ie,{children:[i(V,{variant:`outline`,size:`sm`,onClick:d,children:p(`integrations.cancel`,{defaultValue:`Cancel`})}),e(V,{variant:`primary`,size:`sm`,onClick:_e?d:ue,disabled:!_e&&(Q===0||J.isPending),children:[J.isPending&&i(m,{className:`h-3.5 w-3.5 animate-spin`}),_e?p(`integrations.close`,{defaultValue:`Close`}):p(`integrations.addSelected`,{defaultValue:`Add selected`}),!_e&&Q>0?` (${Q})`:``]})]})]})}function vt({filters:e,activeFilter:t,onSelect:n}){let{t:r}=$();return i(`div`,{role:`tablist`,"aria-label":r(`integrations.adoptDevicesModal.discoveryGranularity`,`Discovery granularity`),className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return i(V,{variant:`unstyled`,type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function yt({candidate:t,depth:n,containerName:r,expandable:a,expanded:o,onToggleExpand:s,adoptedLabel:c,typeLabel:l}){let{t:u}=$(),d=(t.children??[]).length,f=dt(t);return e(`div`,{className:`flex items-center gap-2.5 min-w-0 ${n>0?`pl-5`:``}`,children:[a&&d>0?e(V,{variant:`unstyled`,type:`button`,onClick:s,"aria-label":o?u(`integrations.adoptDevicesModal.collapse`,`Collapse`):u(`integrations.adoptDevicesModal.expand`,`Expand`),"aria-expanded":o,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[i(o?M:y,{className:`h-3.5 w-3.5`}),d]}):a?i(`span`,{className:`h-5 w-5 flex-shrink-0`,"aria-hidden":`true`}):null,e(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`truncate text-xs font-medium text-foreground`,"data-testid":`candidate-name`,children:t.name}),f.length>0&&i(`div`,{className:`truncate text-[10px] text-foreground-subtle`,"data-testid":`candidate-subtitle`,children:f}),r!==void 0&&i(`div`,{className:`truncate text-[10px] text-foreground-subtle`,"data-testid":`candidate-container`,children:u(`integrations.adoptDevicesModal.inContainer`,`in {{name}}`,{name:r})}),i(`div`,{className:`truncate text-[10px] text-foreground-subtle sm:hidden`,children:l})]}),t.alreadyAdopted&&i(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:c})]})}function bt({candidate:t,hiddenChildIds:n,onToggleChildHidden:r}){let{t:a}=$(),o=t.children??[];return o.length===0?null:i(`div`,{className:`space-y-1 py-1`,children:o.map(t=>{let o=n.has(t.childNativeId),s=t.capabilities??[];return e(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${o?`opacity-50`:``}`,children:[i(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:t.name}),s.length>0&&i(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:s.join(`, `)}),i(V,{variant:`unstyled`,onClick:()=>r(t.childNativeId),"aria-label":o?a(`integrations.adoptDevicesModal.showChild`,`Show child`):a(`integrations.adoptDevicesModal.hideChild`,`Hide child`),title:o?a(`integrations.adoptDevicesModal.showAfterAdopt`,`Show after adopt`):a(`integrations.adoptDevicesModal.hideAfterAdopt`,`Hide after adopt`),className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:i(o?D:O,{className:`h-3 w-3`})})]},t.childNativeId)})})}function xt(e){let t=e.host;return typeof t==`string`&&t.length>0?t.toLowerCase():null}function St(e){return e===null?[]:[`host:${e}`]}function Ct(e){let t=[],n=new Map,r=(e,r)=>{let i=e.map(e=>n.get(e)).find(e=>e!==void 0),a=i??r();i===void 0&&t.push(a);for(let t of e)a.ids.add(t),n.set(t,a);return a},i=(e,t)=>{e.sources.includes(t)||e.sources.push(t)};for(let t of e.adoption){let e=r([t.childNativeId],()=>({key:t.childNativeId,ids:new Set,name:t.name,address:null,sources:[],hit:null,adoptionId:t.childNativeId,proposalId:null,alreadyAdded:!1,addedName:null,needsParams:[],parentId:t.parentStableId??null}));i(e,`adoption`),e.adoptionId=t.childNativeId,t.alreadyAdopted===!0&&(e.alreadyAdded=!0)}let a=(t,n,a)=>{let o=xt(t.prefilledConfig),s=r([t.stableId,...St(o)],()=>({key:t.stableId,ids:new Set,name:t.suggestedName,address:o,sources:[],hit:null,adoptionId:null,proposalId:null,alreadyAdded:!1,addedName:null,needsParams:[],parentId:null}));i(s,n),(s.hit===null||n===`scan`)&&(s.hit=t),s.name=t.suggestedName,s.address=o??s.address,a!==null&&(s.proposalId=a),s.parentId=t.parentStableId??s.parentId,s.needsParams=t.needsParams??s.needsParams,(t.alreadyOnboarded===!0||t.onboardedDeviceId!==void 0||e.existingStableIds.has(t.stableId))&&(s.alreadyAdded=!0,s.addedName=t.onboardedName??s.addedName)};for(let t of e.scan)a(t,`scan`,null);for(let t of e.proposals)a(t.candidate,`proposal`,t.id);for(let n of t)[...n.ids].some(t=>e.existingStableIds.has(t))&&(n.alreadyAdded=!0);return t.map(e=>{let t=e.parentId===null?void 0:n.get(e.parentId);return{key:e.key,name:e.name,address:e.address,sources:e.sources,hit:e.hit,adoptionId:e.adoptionId,proposalId:e.proposalId,alreadyAdded:e.alreadyAdded,addedName:e.addedName,needsParams:e.needsParams,parentKey:t!==void 0&&t!==e?t.key:null}})}c();var wt=500;function Tt(e){return e instanceof Error?e.message:String(e)}function Et(e,t){let n={};for(let t of e?.sections??[])for(let e of t.fields)`key`in e&&e.key&&`default`in e&&e.default!==void 0&&(n[e.key]=e.default);return{...n,...t}}function Dt({addonId:t,integrationId:a,onClose:s,onSetupIntegration:c,alongsideAdoption:d=!1}){let{t:f}=$(),p=l(),h=Z({addonId:t}).data??null,[g,_]=o({}),v=se(),y=W({}),b=he({addonId:t,integrationId:a,page:1,pageSize:wt},{retry:!1}),{data:x}=oe({projection:`slim`}),S=be(),C=ge(),[T,E]=o(new Set),[D,O]=o(new Set),[ee,k]=o(null),[A,j]=o(null),M=n(()=>{let e=(b.data?.candidates??[]).map(e=>({childNativeId:e.childNativeId,name:e.name,alreadyAdopted:e.alreadyAdopted,parentStableId:e.parentStableId})),n=(y.data?.proposals??[]).filter(e=>e.addonId===t).map(e=>({id:e.id,candidate:e.candidate}));return Ct({adoption:e,scan:v.data?.candidates??[],proposals:n,existingStableIds:new Set((x??[]).map(e=>e.stableId))})},[b.data,y.data,v.data,x,t]),N=e=>e.hit!==null&&(e.needsParams.length>0||e.hit.setupIntegration===!0),P=n(()=>d?M.filter(e=>!e.sources.includes(`adoption`)||N(e)):M,[M,d]),te=d?M.filter(e=>e.sources.includes(`adoption`)&&e.hit!==null&&!P.includes(e)).length:0,ne=r(e=>{let t=new Map(P.map(e=>[e.key,e])),n=0,r=e;for(;r?.parentKey!=null&&n<8&&(r=t.get(r.parentKey),r!==void 0);)n+=1;return n},[P]),I=r(()=>{k(null),v.mutate({addonId:t,params:g})},[v,t,g]),L=r(async(e,t)=>{E(t=>new Set(t).add(e)),k(null);try{await t(),O(t=>new Set(t).add(e)),p.invalidateQueries({queryKey:[[`deviceManager`]]}),p.invalidateQueries({queryKey:[[`integrations`]]})}catch(e){k(Tt(e))}finally{E(t=>{let n=new Set(t);return n.delete(e),n})}},[p]),R=r(async(e,n)=>{let r=e.hit;if(r!==null){let i=ze(t,r);if(i!==null){c?.(i),s();return}await L(e.key,async()=>{await S.mutateAsync({addonId:t,integrationId:a,candidate:{...r,prefilledConfig:{...r.prefilledConfig,...n}}}),j(null)});return}if(e.adoptionId!==null){let n=e.adoptionId;await L(e.key,async()=>{await C.mutateAsync({addonId:t,integrationId:a,childNativeIds:[n]})})}},[S,C,t,a,s,c,L]),z=r(e=>{if(e.needsParams.length>0&&e.hit!==null){k(null),j(e);return}R(e)},[R]);if(A!==null&&A.hit!==null)return i(At,{addonId:t,integrationId:a,row:A,found:A.hit.prefilledConfig,busy:T.has(A.key),error:ee,embedded:d,onBack:()=>j(null),onSubmit:e=>void R(A,e)});let B=P.length===0,H=e(u,{children:[i(Le,{}),h&&i(Re,{schema:h,values:g,onChange:_}),e(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[e(`p`,{className:`text-xs text-foreground-subtle`,children:[v.isPending?f(`integrations.addDeviceModal.scanning`,`Scanning the local network…`):P.length>0?f(`integrations.addDeviceModal.found`,{defaultValue_one:`{{count}} device found`,defaultValue_other:`{{count}} devices found`,count:P.length}):``,!v.isPending&&te>0?` · ${f(`integrations.addDeviceModal.alsoAdopted`,{defaultValue_one:`{{count}} also in the adoption list`,defaultValue_other:`{{count}} also in the adoption list`,count:te})}`:``]}),e(V,{variant:`outline`,size:`sm`,onClick:I,disabled:v.isPending,children:[v.isPending?i(m,{className:`h-3.5 w-3.5 animate-spin`}):i(w,{className:`h-3.5 w-3.5`}),f(`integrations.addDeviceModal.scanNow`,`Scan now`)]})]}),v.isError&&i(Ot,{text:f(`integrations.addDeviceModal.scanFailed`,`The scan failed. Try again.`)}),ee!==null&&i(Ot,{text:ee}),B&&!v.isPending&&i(`p`,{className:`py-6 text-center text-xs text-foreground-subtle`,children:v.data?f(`integrations.addDeviceModal.nothingFound`,`No devices responded to the scan.`):f(`integrations.addDeviceModal.scanHint`,`Scan the network to find devices to add.`)}),i(`div`,{className:d?`max-h-48 space-y-1.5 overflow-y-auto`:`space-y-1.5`,"data-testid":`network-candidates`,children:P.map(e=>i(kt,{row:e,depth:ne(e),busy:T.has(e.key),added:D.has(e.key),onPick:z},e.key))})]});return d?i(`div`,{className:`shrink-0 space-y-3 border-b border-border pb-3`,children:H}):e(u,{children:[i(F,{className:`space-y-3`,children:H}),i(ie,{children:i(V,{variant:`outline`,size:`sm`,onClick:s,children:f(`integrations.close`,`Close`)})})]})}function Ot({text:t}){return e(`div`,{className:`flex items-start gap-2 rounded-lg border border-danger/40 bg-danger/10 px-3 py-2`,children:[i(S,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-danger`}),i(`p`,{className:`text-xs text-danger`,children:t})]})}function kt({row:t,depth:n,busy:r,added:a,onPick:o}){let{t:s}=$(),c=t.alreadyAdded||a,l=t.hit!==null&&ze(``,t.hit)!==null,u=t.hit?.selectable!==!1,d=t.needsParams.length>0;return e(`div`,{className:`flex items-center gap-3 rounded-lg border border-border bg-surface px-3 py-2 ${n>0?`ml-4`:``}`,"data-testid":`network-row-${t.key}`,children:[e(`div`,{className:`min-w-0 flex-1`,children:[i(`p`,{className:`truncate text-xs font-medium text-foreground`,children:t.name}),t.address!==null&&i(`p`,{className:`truncate font-mono text-[10px] text-foreground-subtle`,children:t.address}),c&&t.addedName!==null&&i(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.addedName})]}),c?e(`span`,{className:`flex items-center gap-1 text-[11px] text-foreground-subtle`,children:[i(T,{className:`h-3.5 w-3.5`}),t.alreadyAdded?s(`integrations.scanNetworkModal.alreadyAdded`,`Already added`):s(`integrations.scanNetworkModal.added`,`Added`)]}):u?e(V,{size:`sm`,variant:l||d?`outline`:`primary`,onClick:()=>o(t),disabled:r,children:[r?i(m,{className:`h-3.5 w-3.5 animate-spin`}):l||d?null:i(A,{className:`h-3.5 w-3.5`}),l?s(`integrations.scanNetworkModal.setUp`,`Set up`):d?s(`integrations.addDeviceModal.enterDetails`,`Enter details`):s(`common.add`,`Add`)]}):null]})}function At({addonId:t,integrationId:n,row:r,found:a,busy:s,error:c,onBack:l,onSubmit:d,embedded:p}){let{t:h}=$(),g=X({addonId:t,integrationId:n}),_=g.data?.deviceType??null,v=q({addonId:t,integrationId:n,type:_??j.Camera},{enabled:g.isSuccess&&_!==null}),y=v.data??null,[b,x]=o(null),S=b??Et(y,a),C=g.error??v.error,w=g.isSuccess&&_===null,T=y!==null,E=T?i(Re,{schema:y,values:S,onChange:x}):C?i(Ot,{text:Tt(C)}):w?i(`p`,{className:`text-xs text-foreground-muted`,children:h(`integrations.addDeviceModal.noCreationType`,`This integration cannot create a device from this candidate.`)}):i(m,{className:`mx-auto h-5 w-5 animate-spin text-primary`}),D=e(u,{children:[e(V,{variant:`ghost`,size:`sm`,onClick:l,children:[i(f,{className:`h-3.5 w-3.5`}),h(`integrations.addDeviceModal.back`,`Back to the list`)]}),i(`p`,{className:`text-xs font-medium text-foreground`,children:r.name}),E,c!==null&&i(Ot,{text:c})]}),O=e(u,{children:[i(V,{variant:`outline`,size:`sm`,onClick:l,children:h(`integrations.cancel`,`Cancel`)}),e(V,{variant:`primary`,size:`sm`,onClick:()=>d(S),disabled:s||!T,children:[s&&i(m,{className:`h-3.5 w-3.5 animate-spin`}),h(`common.add`,`Add`)]})]});return p?e(`div`,{className:`shrink-0 space-y-3 border-b border-border pb-3`,children:[D,i(`div`,{className:`flex justify-end gap-2`,children:O})]}):e(u,{children:[i(F,{className:`space-y-3`,children:D}),i(ie,{children:O})]})}c();function jt(e){return e===`manual`?`manual`:e===`pairing`?`pairing`:`network`}function Mt({addonId:t,integrationId:n,kind:r,canScan:a,onClose:s,pairing:c,onSetupIntegration:l}){let{t:d}=$(),f=ot(t,n),p=r===`device-adoption`&&a===null,h=r===`device-adoption`||a===!0,g=f===`available`,[_,v]=o(null),y=_??(c===void 0?h?`network`:`manual`:`pairing`),b=[h,g,c!==void 0].filter(Boolean).length,x=p?i(F,{children:i(m,{className:`mx-auto h-5 w-5 animate-spin text-primary`})}):r===`device-adoption`?e(u,{children:[a===!0&&i(Dt,{addonId:t,integrationId:n,onClose:s,alongsideAdoption:!0,...l?{onSetupIntegration:l}:{}}),i(_t,{addonId:t,integrationId:n,onClose:s})]}):i(Dt,{addonId:t,integrationId:n,onClose:s,...l?{onSetupIntegration:l}:{}}),S=i(st,{integrationId:n,addonId:t,onClose:s});return i(ve,{open:!0,onOpenChange:e=>{e||s()},children:e(_e,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,className:r===`device-adoption`?`md:h-[85vh]`:void 0,children:[i(J,{children:i(z,{children:d(`integrations.addDevice`,`Add device`)})}),b>1?e(K,{value:y,onValueChange:e=>v(jt(e)),children:[e(G,{children:[h&&i(ue,{value:`network`,children:d(`integrations.addDeviceModal.tabNetwork`,`Found on the network`)}),g&&i(ue,{value:`manual`,children:d(`integrations.addDeviceModal.tabManual`,`Enter parameters`)}),c!==void 0&&i(ue,{value:`pairing`,children:c.label})]}),h&&i(Te,{value:`network`,children:x}),g&&i(Te,{value:`manual`,children:S}),c!==void 0&&i(`div`,{role:`tabpanel`,id:`tabpanel-pairing`,hidden:y!==`pairing`,className:`pt-3`,children:c.render({onPaired:()=>v(`network`)})})]}):c!==void 0&&!h&&!g?c.render({onPaired:()=>v(`network`)}):h?x:g?S:f===`loading`?i(F,{children:i(m,{className:`mx-auto h-5 w-5 animate-spin text-primary`})}):i(F,{children:i(`p`,{className:`py-6 text-center text-xs text-foreground-subtle`,children:d(`integrations.addDeviceModal.nothingToAdd`,`This integration has no way to add a device from here.`)})})]})})}c();var Nt=`matter`,Pt=[`discovering`,`pase`,`commissioning`,`done`];function Ft(e){return!(typeof e!=`object`||!e||!(`phase`in e)||typeof e.phase!=`string`)}function It(e,t){return e===`code-expired`||t?.includes(`matter-commission:code-expired`)?{key:`integrations.addMatter.failure.expired`,defaultValue:`The pairing code expired. Share the device again and paste the new code.`}:e===`device-not-found`||t?.includes(`matter-commission:device-not-found`)?{key:`integrations.addMatter.failure.notFound`,defaultValue:`No Matter device with that code was found on the network.`}:e===`wrong-code`||t?.includes(`matter-commission:wrong-code`)?{key:`integrations.addMatter.failure.wrongCode`,defaultValue:`The pairing code was rejected.`}:e===`invalid-code`||t?.includes(`invalid pairing code`)?{key:`integrations.addMatter.failure.invalid`,defaultValue:`Enter an 11-digit or 21-digit manual code, or a code that starts with MT:.`}:{key:`integrations.addMatter.failure.unknown`,defaultValue:t??`Commissioning failed.`}}function Lt({onClose:t,onCommissioned:n}){let{t:r}=$(),s=Q({kind:Nt}),[c,l]=o(null),d=Ee(s.data??[],c),f=d.length,p=c??d[0]?.id??null,h=U(),[g,_]=o(``),[v,y]=o({phase:`idle`,failure:null,message:null}),b=v.phase===`discovering`||v.phase===`pase`||v.phase===`commissioning`,x=B({brokerId:p??``,key:`commission`},{enabled:p!==null&&b,refetchInterval:b?400:!1});a(()=>{b&&Ft(x.data)&&x.data.phase!==`idle`&&y({phase:x.data.phase,failure:typeof x.data.failure==`string`?x.data.failure:null,message:typeof x.data.message==`string`?x.data.message:null})},[b,x.data]);let S=()=>{p!==null&&(y({phase:`discovering`,failure:null,message:null}),h.mutate({brokerId:p,target:{action:`commissionNode`},payload:{pairingCode:g.trim()}},{onSuccess:()=>y({phase:`done`,failure:null,message:null}),onError:e=>{let t=e instanceof Error?e.message:`Commissioning failed.`;y({phase:`failed`,failure:t.includes(`matter-commission:`)?t.split(`matter-commission:`)[1]?.split(`:`)[0]??`unknown`:t.includes(`invalid pairing code`)?`invalid-code`:`unknown`,message:t})}}))},C=v.phase===`failed`?It(v.failure,v.message):null,w=C===null?null:r(C.key,{defaultValue:C.defaultValue}),T=(s.isSuccess===!0||s.data!==void 0)&&p===null;return e(u,{children:[e(F,{className:`space-y-4`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:r(`integrations.addMatter.help`,{defaultValue:`In Home Assistant, open the device and choose Share device. Paste the numeric code or the MT: code here. The device stays in Home Assistant.`})}),(T||f>1)&&!b&&v.phase!==`done`&&e(`div`,{className:`space-y-1.5`,children:[i(De,{children:r(`integrations.addMatter.broker`,{defaultValue:`Matter fabric`})}),i(Ue,{kind:Nt,value:p,onChange:l})]}),!T&&e(`div`,{className:`space-y-1.5`,children:[i(De,{htmlFor:`matter-pairing-code`,children:r(`integrations.addMatter.code`,{defaultValue:`Pairing code`})}),i(P,{id:`matter-pairing-code`,value:g,autoComplete:`off`,spellCheck:!1,placeholder:`34970112332`,disabled:b||v.phase===`done`,onChange:e=>_(e.target.value)})]}),v.phase!==`idle`&&i(`ol`,{className:`space-y-1`,"aria-label":r(`integrations.addMatter.progress`,{defaultValue:`Commissioning progress`}),children:Pt.map(t=>{let n=v.phase===t;return e(`li`,{className:`text-xs ${n?`text-foreground font-medium`:`text-foreground-subtle`}`,children:[n&&b?i(m,{className:`mr-1 inline h-3 w-3 animate-spin`}):null,r(`integrations.addMatter.phase.${t}`,{defaultValue:t===`discovering`?`Discovering`:t===`pase`?`PASE`:t===`commissioning`?`Commissioning`:`Done`})]},t)})}),w!==null&&i(me,{message:w})]}),e(ie,{children:[i(V,{variant:`ghost`,size:`sm`,onClick:t,children:r(`common.close`,{defaultValue:`Close`})}),v.phase===`done`?i(V,{size:`sm`,onClick:n,children:r(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}):i(V,{size:`sm`,disabled:b||T||g.trim().length===0,onClick:S,children:b?r(`integrations.addMatter.working`,{defaultValue:`Adding…`}):r(`integrations.addMatter.submit`,{defaultValue:`Add device`})})]})]})}function Rt({addonId:t,integrationId:n,name:r,onClose:a,onSaved:o}){let{t:c}=$(),l=k(),u=s({queryKey:[`integration-instance-describe`,t],queryFn:()=>l.trpcClient.integrationInstances.describe.query({addonId:t})}),d=s({queryKey:[`integration-instance`,t,n],queryFn:()=>l.trpcClient.integrationInstances.getInstance.query({addonId:t,id:n})});if(u.isSuccess&&d.isSuccess&&d.data!==null)return i(We,{addonId:t,providerName:r,description:u.data,instance:d.data,onClose:a,onSaved:()=>o()});let f=u.isError||d.isError||d.isSuccess&&!d.data;return i(ve,{open:!0,onOpenChange:e=>!e&&a(),children:e(_e,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(J,{children:e(z,{children:[c(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,r]})}),i(F,{children:f?i(`p`,{className:`text-[11px] text-danger`,children:c(`integrations.loadFailed`,{defaultValue:`Could not load this integration.`})}):e(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[i(m,{className:`h-3 w-3 animate-spin`}),c(`integrations.loading`,{defaultValue:`Loading…`})]})})]})})}c();function zt(){let{addonId:e=``}=Je();return i(Vt,{addonId:e})}function Bt(){return e(`div`,{className:`p-4`,children:[i(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),i(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]})}function Vt({addonId:t}){let{t:c}=$(),u=l(),g=Xe(),[_,v]=Ge(),y=k(),[b,x]=o(!1),S=r(e=>{x(!1),g(`/integrations`,{state:{integrationSeed:e}})},[g]),[C,w]=o(!1),[T,D]=o(!1),{data:O}=le(void 0),A=n(()=>(O??[]).filter(e=>e.addonId===t),[O,t]),j=Ze(_.get(`instance`),A)??``,M=r(e=>{v(t=>{let n=new URLSearchParams(t);return n.set(He,e),n},{replace:!0})},[v]),P=n(()=>A.map(e=>({value:e.id,label:e.name})),[A]),{data:B,isLoading:U}=Ie({id:j},{enabled:!!j}),{data:W,isSuccess:G}=ne(),K=n(()=>{let e=B?.addonId;return!e||!G?null:(W??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[W,B?.addonId,G]),{data:ie,isPending:q}=L({}),se=n(()=>q?null:(ie?.providers??[]).some(e=>e.addonId===B?.addonId),[q,ie,B?.addonId]),X=K!==null,Z=B?.info?.fixed===!0,ue=n(()=>{let e=B?.addonId;return!e||!G?null:(W??[]).find(t=>t.addonId===e)?.brokerKind??null},[W,B?.addonId,G])===`matter`,de=X?c(`integrations.addDevice`,`Add device`):c(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),fe=n(()=>{let e=B?.addonId;return!e||!G?null:(W??[]).find(t=>t.addonId===e)?.mode??null},[W,B?.addonId,G]);a(()=>{_.get(`add`)===`1`&&X&&(x(!0),v(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[_,X,v]);let{data:me}=s({queryKey:[`integration-instance-form`,B?.addonId,B?.id],enabled:!!B?.addonId&&!!B?.id,queryFn:()=>y.trpcClient.integrationInstances.instanceFormSchema.query({addonId:B?.addonId??``,id:B?.id??``})}),he=me!=null&&Array.isArray(me.sections)&&me.sections.some(e=>e.fields.length>0),{data:ge}=oe({projection:`slim`},{refetchInterval:3e4}),Q=[[`integrations`,`get`],{input:{id:j},type:`query`}],be={onMutate:async e=>{await u.cancelQueries({queryKey:Q});let t=u.getQueryData(Q);return t!=null&&u.setQueryData(Q,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&u.setQueryData(Q,r.previous)},onSettled:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}},xe=R(be),we=H(be),Te={isPending:xe.isPending||we.isPending,mutate:e=>Z&&B?.processState!==`running`?we.mutate({id:e.id,enabled:e.enabled}):xe.mutate(e)},Ee=B?.switchUnknown===!0,De=Ve(B?.processState),Oe=Ee||!Z&&De,ke={onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]}),g(A.length>1?qe(t):`/integrations`)}},Ae=re(ke),Me=Y(ke),Le=B?.processState===`running`,Re={isPending:Ae.isPending||Me.isPending,mutateAsync:async e=>{Le?await Ae.mutateAsync(e):await Me.mutateAsync({id:e.id})}},ze=Se({onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Be=Qe(),Ue=Pe({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),We=ce({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ke=n(()=>ge??[],[ge]),Je=n(()=>te(Ke),[Ke]),Ye=r(e=>Je.get(e)??null,[Je]),et=n(()=>Fe(O),[O]),tt=r(e=>g(`/devices/${String(e)}`),[g]),nt=n(()=>Ke.filter(e=>{let t=et(e);return t.kind===`resolved`&&t.integration.id===j}),[Ke,j,et]),rt=n(()=>O===void 0?null:Ne(nt).length,[O,nt])??`…`;if(U||O===void 0)return i(Bt,{});let it=(W??[]).find(e=>e.addonId===t)?.name??B?.name??t,at=Oe&&De?c(`providerInstances.addonNotRunning`,`{{addon}} is not running: start it first`,{addon:it}):null;return B?e(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[i(ae,{items:[{label:c(`integrationDetail.integrations`,`Integrations`),onClick:()=>g(`/integrations`)},{label:it}]}),e(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[e(`div`,{className:`flex items-center gap-3 min-w-0`,children:[i(Ht,{addonId:B.addonId}),e(`div`,{className:`min-w-0`,children:[i(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:it}),e(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[rt,` `,c(`integrations.devices`)]})]})]}),e(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[!Z&&e(V,{variant:`unstyled`,onClick:()=>{x(!0)},disabled:!X,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:de,children:[i(ee,{className:`h-3.5 w-3.5`}),de]}),e(`div`,{className:`flex flex-col items-end gap-1`,children:[e(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Te.isPending?`opacity-60`:``} ${B.enabled&&!Ee?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:at??c(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[i(pe,{checked:B.enabled&&!Ee,onCheckedChange:e=>Te.mutate({id:j,addonId:B?.addonId,enabled:e}),disabled:Te.isPending||Oe,"aria-label":Ee?c(`integrationDetail.switchUnknown`,`Unknown`):B.enabled?c(`integrationDetail.disableIntegration`,`Disable integration`):c(`integrationDetail.enableIntegration`,`Enable integration`)}),i(`span`,{className:`text-[11px] font-medium ${B.enabled&&!Ee?`text-success`:`text-foreground-subtle`}`,children:Ee?c(`integrationDetail.switchUnknown`,`Unknown`):B.enabled?c(`integrationDetail.enabled`,`Enabled`):c(`integrationDetail.disabled`,`Disabled`)}),Te.isPending&&i(m,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),at!==null&&i(`span`,{className:`text-[11px] text-foreground-subtle`,children:at})]}),fe!==`standalone`&&(he||K===`device-adoption`)&&e(V,{variant:`unstyled`,onClick:()=>w(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[i(p,{className:`h-3 w-3`}),c(`integrations.config`)]}),e(V,{variant:`unstyled`,onClick:()=>D(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:c(`integrations.logs`,{defaultValue:`View logs`}),children:[i(d,{className:`h-3 w-3`}),c(`integrations.logs`,{defaultValue:`Logs`})]}),i(I,{label:c(`integrationDetail.restart`,`Restart`),icon:h,title:c(`integrationDetail.restart2`,`Restart "{{name}}"?`,{name:B.name}),description:c(`integrationDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device backed by it ({{topLevelCountLabel}} active). Streams will reconnect automatically.`,{topLevelCountLabel:rt}),confirmLabel:c(`integrationDetail.restart`,`Restart`),triggerVariant:`outline`,confirmVariant:`danger`,disabled:ze.isPending,action:()=>ze.mutateAsync({addonId:B.addonId})}),!Z&&j&&i(I,{label:c(`integrations.delete`,{defaultValue:`Delete`}),icon:E,title:c(`integrations.deleteTitle`,{defaultValue:`Delete integration?`}),description:c(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:B.name,count:rt}),confirmLabel:c(`integrations.confirmDelete`,{defaultValue:`Delete integration`}),triggerVariant:`outline`,confirmVariant:`danger`,className:`border-danger bg-danger/10 text-danger hover:bg-danger hover:text-background`,disabled:Re.isPending,action:()=>Re.mutateAsync({addonId:t,id:j})})]})]}),A.length>1&&i(`div`,{className:`max-w-sm`,children:i(Ce,{mode:`single`,singleDisplay:`field`,label:c(`integrationDetail.instances`,`Integration`),options:P,value:j,onChange:M,testId:`integration-instance-picker`,optionTestIdPrefix:`integration-instance`})}),i(je,{context:`integration-detail`,devices:Ke,trpc:y.trpcClient,integrationOf:et,forceIntegrationId:j,urlScope:`root`,lsKey:`integration-detail:${B.addonId}`,resolveIntegrationIcon:$e,resolveParent:Ye,onNavigate:tt,rowOperation:Be.rowOperation,batchActions:{remove:Be.remove,disable:Ue.mutate,enable:We.mutate},...Z?{}:{onDeleteDevice:e=>Be.remove({deviceId:e.id})}}),b&&j&&K!==null&&i(Mt,{addonId:B.addonId,integrationId:j,kind:K,canScan:se,onSetupIntegration:S,...ue?{pairing:{label:c(`integrations.addMatter.tab`,`Pairing code`),render:({onPaired:e})=>i(Lt,{onClose:()=>x(!1),onCommissioned:e})}}:{},onClose:()=>x(!1)}),C&&j&&i(Rt,{addonId:B.addonId,integrationId:j,name:B.name,onClose:()=>w(!1),onSaved:()=>{u.invalidateQueries()}}),T&&i(ve,{open:!0,onOpenChange:e=>!e&&D(!1),children:e(_e,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[i(J,{className:`mb-0`,children:e(z,{className:`flex items-center gap-2 min-w-0`,children:[i(d,{className:`h-4 w-4 text-primary shrink-0`}),i(`span`,{className:`truncate`,children:B.name}),e(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate font-normal`,children:[B.addonId,j?` · ${j}`:``]})]})}),i(F,{className:`min-h-0 overflow-hidden p-0`,children:i(ye,{addonId:B.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})})]}):e(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[i(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:i(N,{className:`h-6 w-6 text-foreground-subtle`})}),e(`div`,{className:`space-y-1 max-w-sm`,children:[i(`h2`,{className:`text-sm font-semibold text-foreground`,children:c(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:c(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:t})})]}),e(V,{variant:`unstyled`,onClick:()=>g(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[i(f,{className:`h-3 w-3`}),c(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}function Ht({addonId:e}){let t=Ye(e),[n,r]=o(!1);return!t||n?null:i(`img`,{src:t,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:()=>r(!0)})}export{zt as IntegrationDetailPage};
@@ -1 +0,0 @@
1
- import{C as e,K as t,R as n,S as r,V as i,Y as a,et as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Br as c,Fr as l,Ga as u,Jn as d,Qi as f,Zn as p,ea as m,nr as h,rr as ee,vt as g,zn as _}from"./player-overlays-BxDm01PX.js";import{t as v}from"./chevron-down-CBb-F8DT.js";import{t as te}from"./table-2-DMxm3oyu.js";import{$f as y,Ai as ne,At as re,Bc as ie,Fi as b,Gf as x,Is as S,Ns as ae,Pi as C,Vc as oe,Xa as se,a as ce,ar as le,fa as ue,ji as de,ki as fe,ls as w,q as T,vt as pe,ws as E,xt as me,yt as he}from"./src-Cn1TCE2g.js";import{t as D}from"./i18n-1k63HMS1.js";import{t as O}from"./useTranslation-BJr-n0es.js";import{$ as ge,K as _e,Q as k,X as ve,Z as ye,at as be,et as A,fi as xe,hi as Se,it as Ce,lt as we,pi as Te,q as Ee,rt as De,tt as j}from"./index-cl6SWsBh.js";import{t as Oe}from"./AdminPage-BKJUlsLi.js";import"./useEventInvalidation-9s4juC85.js";import{t as ke}from"./device-integration-icon-CpZ0OBPQ.js";o();function Ae(e){return e.some(e=>e.status===`running`)?`running`:e.some(e=>e.status===`stopped`)?`stopped`:`disabled`}function je(e,t){let n=new Map;for(let t of e){let e=n.get(t.addonId);e===void 0?n.set(t.addonId,[t]):e.push(t)}return[...n.entries()].map(([e,n])=>{let r=t.get(e)?.trim()??``;return{addonId:e,name:r.length>0?r:n[0]?.name??e,instances:n,instanceCount:n.length,deviceCount:n.reduce((e,t)=>e+t.deviceCount,0),status:Ae(n)}})}var Me=3e3,M=new Set([`no-provider`,`node-offline`,`transport-failed`]),N=[`provider not available`,`failed to fetch`,`networkerror`,`load failed`];function Ne(e){if(typeof e!=`object`||!e)return null;let t=Reflect.get(e,`data`);if(typeof t!=`object`||!t)return null;let n=Reflect.get(t,`capRouteReason`);return typeof n==`string`?n:null}function P(e,t){if(e==null||t>10)return!1;let n=Ne(e);if(n!==null)return M.has(n);let r=(e instanceof Error?e.message:String(e)).toLowerCase();return N.some(e=>r.includes(e))}function Pe(e){return P(e.state.error,e.state.errorUpdateCount)?Me:!1}function Fe({providers:n,system:i,onOpen:o,searchPlaceholder:s,emptyLabel:c}){let[l,u]=a(``),d=t(()=>{let e=l.trim().toLowerCase(),t=t=>e.length===0||`${t.name} ${t.addonId} ${t.instances.map(e=>e.name).join(` `)}`.toLowerCase().includes(e);return{providers:n.filter(t),system:i.filter(t)}},[l,n,i]),f=d.providers.length===0&&d.system.length===0;return e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`relative`,children:[r(_,{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}),r(y,{type:`search`,value:l,onChange:e=>u(e.target.value),placeholder:s,"aria-label":s,className:`pl-8`})]}),f?r(`p`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:c}):e(`div`,{className:`space-y-4`,children:[d.providers.length>0&&r(k,{kind:`providers`,children:r(F,{groups:d.providers,onOpen:o})}),d.system.length>0&&r(k,{kind:`system`,children:r(F,{groups:d.system,onOpen:o})})]})]})}function F({groups:e,onOpen:n}){let{t:i,i18n:a}=O();return r(A,{children:t(()=>De(e,a.language),[e,a.language]).map(e=>r(ge,{testId:`integration-card-${e.addonId}`,addonId:e.addonId,name:e.name,openLabel:i(`integrations.openNamed`,{name:e.name,defaultValue:`Open {{name}}`}),onOpen:()=>n(e),body:r(`p`,{className:`text-xs text-foreground-muted`,children:i(`integrations.addonCard.summary`,{integrations:i(`integrations.addonCard.integrationCount`,{count:e.instanceCount}),devices:i(`integrations.integrationColumns.deviceCount`,{count:e.deviceCount}),defaultValue:`{{integrations}} · {{devices}}`})}),footer:r(T,{status:e.status,className:`shrink-0`})},e.addonId))})}o();var I=`camstack.admin.integrations.view`;function L(e){return e===`table`||e===`grid`}function R(){try{return typeof window>`u`?null:window.localStorage}catch{return null}}function z(e=R()){if(e===null)return`table`;try{let t=e.getItem(I);return L(t)?t:`table`}catch{return`table`}}function B(e,t=R()){if(t!==null)try{t.setItem(I,e)}catch{}}function Ie(){let[e,t]=a(()=>z());return[e,n(e=>{t(e),B(e)},[])]}function V({integration:t,expanded:n,onToggleExpand:i}){let{t:a}=O();return e(`div`,{className:`flex items-center gap-2.5`,children:[r(x,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),i(t.addonId)},"aria-label":n?a(`integrations.integrationColumns.collapse`,`Collapse`):a(`integrations.integrationColumns.expand`,`Expand`),"aria-expanded":n,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:r(n?v:f,{className:`h-3.5 w-3.5`})}),r(j,{type:t.addonId,size:`sm`}),e(`div`,{className:`flex min-w-0 flex-col`,children:[r(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:t.name}),r(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.addonId})]})]})}function Le(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:D.t(`integrations.integrationColumns.integration`,`Integration`),headerClassName:`w-[55%]`,cell:e=>r(V,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:D.t(`integrations.integrationColumns.devices`,`Devices`),headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>D.t(`integrations.integrationColumns.deviceCount`,{count:e.deviceCount})},{key:`status`,header:D.t(`integrations.integrationColumns.status`,`Status`),headerClassName:`w-[15%]`,cell:e=>r(T,{status:e.status})}]}o();var H=6e4;function Re({onSetupIntegration:t}){let{t:n}=O(),[i,o]=a(!1),c=S({},{refetchInterval:H}),l=c.data?.proposals??[];return l.length===0?null:e(s,{children:[e(`div`,{role:`status`,"data-testid":`discovery-banner`,className:`flex flex-wrap items-center gap-2 rounded-lg border border-info/30 bg-info/10 px-3 py-2 text-xs text-foreground`,children:[r(p,{className:`h-3.5 w-3.5 text-info`,"aria-hidden":!0}),r(`span`,{className:`flex-1`,children:n(`integrations.discoveryBanner.count`,{defaultValue_one:`{{count}} new device found`,defaultValue_other:`{{count}} new devices found`,count:l.length})}),r(x,{variant:`secondary`,size:`sm`,onClick:()=>o(!0),children:n(`integrations.discoveryBanner.review`,`Review`)})]}),r(U,{open:i,onClose:()=>o(!1),proposals:l,onChanged:()=>void c.refetch(),onSetupIntegration:e=>{o(!1),t(e)}})]})}function U({open:t,onClose:i,proposals:o,onChanged:c,onSetupIntegration:u}){let{t:d}=O(),f=w(),h=E(),[ee,g]=a(new Set),_=n(async(e,t)=>{g(t=>new Set(t).add(e));try{await t(),c()}catch{}finally{g(t=>{let n=new Set(t);return n.delete(e),n})}},[c]),v=n(async e=>{let t=ve(e.addonId,e.candidate);if(t!==null){u(t);return}await _(e.id,()=>f.mutateAsync({addonId:e.addonId,candidate:e.candidate}))},[f,u,_]),te=n(e=>_(e.id,()=>h.mutateAsync({id:e.id})),[h,_]);return r(fe,{open:t,onOpenChange:e=>!e&&i(),children:e(de,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[r(C,{children:r(b,{children:e(`span`,{className:`flex items-center gap-2`,children:[r(p,{className:`h-4 w-4 text-primary`}),d(`integrations.discoveryBanner.title`,`New devices found`)]})})}),r(ne,{className:`space-y-1.5`,children:o.map(t=>e(`div`,{"data-testid":`discovery-proposal`,className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-2`,children:[e(`div`,{className:`min-w-0 flex-1`,children:[r(`p`,{className:`truncate text-sm font-medium text-foreground`,children:t.candidate.suggestedName}),r(`p`,{className:`truncate text-xs text-foreground-muted`,children:t.addonId})]}),ee.has(t.id)?r(l,{className:`h-4 w-4 animate-spin text-foreground-muted`,"aria-hidden":!0}):e(s,{children:[r(x,{variant:`secondary`,size:`sm`,onClick:()=>void te(t),children:d(`integrations.discoveryBanner.dismiss`,`Dismiss`)}),e(x,{size:`sm`,onClick:()=>void v(t),children:[r(m,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),d(`integrations.discoveryBanner.adopt`,`Adopt`)]})]})]},t.id))})]})})}o();function ze(e){if(!e.enabled&&e.switchUnknown!==!0)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var W=`expand`;function G(){let{t:o}=O(),l=Te(),f=xe(),m=g(),[_]=Se(),[v,y]=Ie(),[ne,b]=a(!1),[S,C]=a(null),de=n(()=>{C(null),b(!0)},[]),fe=n(()=>{b(!1),C(null)},[]),w=n(e=>{E(!1),C(e),b(!0)},[]),[T,E]=a(!1);i(()=>{let e=ye(f.state);e!==null&&(C(e),b(!0),l(`/integrations`,{replace:!0,state:null}))},[f.state,l]);let D=_.get(`setup`);i(()=>{D===null||D.length===0||(C({addonId:D,name:D,config:{}}),b(!0))},[D]);let ge=n(()=>E(!0),[]),ve=n(()=>E(!1),[]);ce([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),ce([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:A,isLoading:De,isError:j,error:Ae,errorUpdateCount:Me,refetch:M}=oe(void 0,{refetchInterval:Pe}),{data:N,isLoading:Ne,isError:F,error:I,errorUpdateCount:L,refetch:R}=ae({projection:`slim`},{refetchInterval:Pe}),z=t(()=>N??[],[N]),B=t(()=>A??[],[A]),V=t(()=>re(z),[z]),H=t(()=>he(A),[A]),U=t(()=>{let e=new Map;for(let t of me(z)){let n=H(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[z,H]),G=t(()=>B.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:ze(e),deviceCount:U.get(e.id)??0})),[B,U]),{data:Be}=ie(),Ve=t(()=>new Map((Be??[]).map(e=>[e.addonId,e.name])),[Be]),He=_.get(W),Ue=n(e=>{let t=new URLSearchParams(window.location.search);t.get(W)===e?t.delete(W):t.set(W,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`))},[]),{data:We}=se(void 0),K=t(()=>be(We),[We]),q=t(()=>Ce(G,K),[G,K]),Ge=t(()=>Ce(je(G,Ve),K),[G,Ve,K]),Ke=n(e=>l(we(e.addonId)),[l]),qe=n(e=>l(we(e.addonId,e.id)),[l]),Je=n(e=>V.get(e)??null,[V]),Ye=n(e=>l(`/devices/${String(e)}`),[l]),Xe=n(e=>r(pe,{context:`integration-detail`,devices:z,trpc:m.trpcClient,integrationOf:H,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:ke,resolveParent:Je,onNavigate:Ye}),[z,m.trpcClient,H,Je,Ye]),J=n(e=>He===e.addonId,[He]),Ze=t(()=>Le({isExpanded:J,onToggleExpand:Ue}),[J,Ue]),Qe=n(e=>`${e.name} ${e.addonId}`,[]),$e=n(e=>e.id,[]),et=e=>r(pe,{mode:`generic`,items:e,getKey:$e,getSearchText:Qe,columns:Ze,onRowClick:qe,isExpanded:J,renderExpanded:Xe,searchPlaceholder:o(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:o(`integrations.empty`,{defaultValue:`No integrations found.`})}),Y=n(()=>{M(),R()},[M,R]),tt=j===!0&&P(Ae,Me),nt=F===!0&&P(I,L),X=tt||nt,Z=j===!0&&!tt||F===!0&&!nt,Q=!Z&&!X&&(De||Ne||A===void 0||N===void 0),$=B.length>0,rt=[{id:`table`,label:o(`integrations.viewTable`,`Table`),icon:te},{id:`grid`,label:o(`integrations.viewGrid`,`Grid`),icon:c}];return e(Oe,{icon:h,title:o(`nav.integrations`,`Integrations`),actions:e(s,{children:[r(le,{ariaLabel:o(`integrations.viewLabel`,`Layout`),value:v,onChange:y,options:rt,testId:`integrations-view`}),r(x,{variant:`unstyled`,onClick:Y,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:o(`common.refresh`,`Refresh`),children:r(d,{className:u(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),e(x,{variant:`unstyled`,onClick:ge,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:o(`integrations.scanTheLocalNetworkFor`,`Scan the local network for devices`),children:[r(p,{className:`h-3.5 w-3.5`}),o(`integrations.scanNetwork`,`Scan network`)]}),e(x,{variant:`unstyled`,onClick:de,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:[r(ee,{className:`h-3.5 w-3.5`}),o(`integrations.newIntegration`,`New Integration`)]})]}),children:[r(Re,{onSetupIntegration:w}),Z&&r(ue,{message:o(`integrations.loadFailed`,`Integrations could not be loaded.`),onRetry:Y}),X&&!Z&&e(`div`,{role:`status`,"data-testid":`integrations-reconnecting`,className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground-subtle`,children:[r(d,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),o(`integrations.reconnecting`,`An integration is restarting. The list will refresh on its own.`)]}),Q&&r(`div`,{className:`space-y-2`,"data-testid":`integrations-pending`,children:[1,2,3].map(e=>r(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Z&&!Q&&!X&&!$&&e(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[r(`p`,{className:`text-sm`,children:o(`integrations.noIntegrationsConfigured`,`No integrations configured.`)}),r(`p`,{className:`text-xs mt-1`,children:o(`integrations.clickNewIntegrationToConnect`,`Click "New Integration" to connect cameras and devices.`)})]}),!Z&&!Q&&$&&v===`table`&&e(`div`,{className:`space-y-4`,children:[q.providers.length>0&&r(k,{kind:`providers`,children:et(q.providers)}),q.system.length>0&&r(k,{kind:`system`,children:et(q.system)})]}),!Z&&!Q&&$&&v===`grid`&&r(Fe,{providers:Ge.providers,system:Ge.system,onOpen:Ke,searchPlaceholder:o(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:o(`integrations.empty`,{defaultValue:`No integrations found.`})}),r(_e,{open:ne,onClose:fe,seed:S}),r(Ee,{open:T,onClose:ve,onSetupIntegration:w})]})}export{G as IntegrationsPage};
@@ -1,3 +0,0 @@
1
- import{C as e,K as t,S as n,V as r,Y as i,et as a,o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Jn as c,O as l,Oa as u,Qi as d,Rr as f,Ua as p,V as m,ct as h,dt as g,en as _,k as v,kr as y,lr as b,rr as x,wt as S,z as C}from"./player-overlays-BxDm01PX.js";import{In as w,gs as T,vs as E}from"./client-DbKXlEC4.js";import{t as D}from"./chevron-down-CBb-F8DT.js";import{$f as O,$s as k,A,Ai as j,Ar as M,Ca as N,Da as P,Fi as F,Gf as I,Js as ee,Ks as te,Ls as ne,Ni as L,Ns as re,Pi as R,Qs as ie,Rs as ae,Tn as z,Vs as oe,Xi as B,Ys as se,as as ce,ba as V,br as H,cs as le,ec as ue,ep as de,is as U,ji as fe,ki as pe,ma as W,ni as G,oa as me,oc as he,qs as ge,ri as _e,rs as ve,tc as ye,tp as be,xa as K,xr as xe,yp as Se,zs as Ce}from"./src-Cn1TCE2g.js";import{t as q}from"./i18n-1k63HMS1.js";import{t as J}from"./useTranslation-BJr-n0es.js";import{h as we,hi as Te,pi as Ee,ui as Y}from"./index-cl6SWsBh.js";import{t as De}from"./AdminSectionedPage-DSB1PxSl.js";import{c as X,n as Oe,r as ke}from"./linked-devices-model-lSVw-dAG.js";a();function Z(e){return{id:e.id,name:e.name,type:e.type,stableId:e.stableId??``,parentDeviceId:e.parentDeviceId,location:e.location,...e.role!==void 0&&e.role!==null?{role:e.role}:{},...e.primaryChildEntityId!==void 0&&e.primaryChildEntityId!==null?{primaryChildEntityId:e.primaryChildEntityId}:{},...e.primaryChildPreference!==void 0&&e.primaryChildPreference!==null?{primaryChildPreference:e.primaryChildPreference}:{}}}function Q(e){if(e==null)return null;let t=e.trim();return t.length===0?null:t.toLowerCase()}function Ae(e,t){let n=Q(t);return n===null?[]:e.filter(e=>Q(e.location)===n)}function je(e,t){let n=Ae(e,t),r=new Set(n.map(e=>e.id));return n.filter(e=>e.parentDeviceId===null||!r.has(e.parentDeviceId))}function Me(e,t){let n=Q(e.location);return n===null||new Set(t.map(e=>Q(e))).has(n)?null:e.location?.trim()??null}function Ne(e,t){let n=Q(e.location);return n!==null&&t.has(n)}function Pe(e,t){let n=new Set(t.map(e=>Q(e))),r=new Set(e.filter(e=>Ne(e,n)).map(e=>e.id));return e.filter(e=>!(Ne(e,n)||e.parentDeviceId!==null&&r.has(e.parentDeviceId)))}function Fe(e,t){return Pe(e,t).filter(e=>e.parentDeviceId===null)}function Ie(e,t){let n=new Map;for(let t of e){if(t.parentDeviceId===null)continue;let e=n.get(t.parentDeviceId);e?e.push(t):n.set(t.parentDeviceId,[t])}let r=[],i=new Set([t]),a=[t];for(;a.length>0;){let e=[];for(let t of a)for(let a of n.get(t)??[])i.has(a.id)||(i.add(a.id),r.push(a),e.push(a.id));a=e}return r}function Le(e,t){return Ie(e,t).length}function Re(e,t){return e.filter(e=>!e.isCamera&&e.parentDeviceId===t)}function ze(e,t){return t.map(t=>({name:t,members:je(e,t)}))}function $({type:e,role:t,className:r}){return n(Se(e,t),{"aria-hidden":`true`,className:r??`h-3.5 w-3.5 shrink-0 text-foreground-subtle`})}function Be({device:t}){let r=K(Z(t),`compact`);if(t.online)return n(`span`,{"aria-hidden":`true`,className:`inline-block h-1.5 w-1.5 shrink-0 rounded-full bg-success`,"data-status":`online`});let i=q.t(`common.offline`);return e(`span`,{className:`flex items-center gap-1.5`,children:[n(`span`,{className:`inline-block h-1.5 w-1.5 shrink-0 rounded-full border border-foreground-subtle`,"data-status":`offline`,role:`img`,"aria-label":q.t(`locations.deviceGlyphs.aria`,{name:r,state:i}),title:i}),n(`span`,{className:`text-xs text-foreground-muted`,children:i})]})}function Ve({open:t,title:a,items:o,listState:s,lockedIds:c,lockedNote:l,suggestions:u=null,busy:d=!1,onConfirm:f,onClose:p}){let{t:m}=J(),[h,g]=i([]);r(()=>{t||g([])},[t]);let _=new Map(o.map(e=>[e.id,e.name])),v=(u?.ids??[]).filter(e=>_.has(e)&&!c.includes(e)),y=e=>g(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]);return n(pe,{open:t,onOpenChange:e=>e?void 0:p(),children:e(fe,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":a,children:[n(R,{children:n(F,{children:a})}),e(j,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:[t&&u!==null&&v.length>0&&e(`section`,{"aria-label":u.heading,className:`flex flex-col gap-1`,children:[n(`h3`,{className:`text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:u.heading}),n(`div`,{className:`flex flex-wrap gap-1`,children:v.map(e=>n(`button`,{type:`button`,"aria-pressed":h.includes(e),className:`inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${h.includes(e)?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:bg-surface-hover`}`,onClick:()=>y(e),children:_.get(e)},e))})]}),t&&n(A,{devices:o,listState:s,value:h,onChange:e=>g(e),noun:`device`,emptyLabel:m(`locations.addDialog.nonePicked`),showAll:!0,lockedIds:c,lockedNote:l,testId:`quick-add-picker`})]}),e(L,{children:[n(I,{variant:`ghost`,onClick:p,children:m(`locations.addDialog.cancel`)}),n(I,{disabled:h.length===0||d,onClick:()=>f(h),children:m(`locations.addDialog.confirm`,{count:h.length})})]})]})})}a();function He({room:e,cameras:r,fleet:i}){let{t:a}=J(),o=t(()=>new Map(i.map(e=>[e.id,e])),[i]);return e===null?n(`p`,{className:`text-xs text-foreground-subtle`,children:a(`locations.links.noRoom`)}):n(`div`,{className:`flex flex-col gap-3`,"data-testid":`camera-links-section`,children:r.length===0?n(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`camera-links-empty`,children:a(`locations.links.noCameras`,{room:e})}):r.map(e=>n(We,{camera:e,byId:o},e.id))})}function Ue(e){return{id:e.deviceId,name:e.name,type:e.type,location:e.location}}function We({camera:t,byId:r}){let{t:a}=J(),s=K(Z(t),`full`),c=o(),u=Ee(),[d,p]=i(!1),[m,h]=i(null),g=U({deviceId:t.id}),_=ke({status:g.status,data:g.data,error:g.error===null||g.error===void 0?null:g.error}),y=ce(),b=_.kind===`present`?_:null,x=ve({deviceId:t.id,slotRef:b?.slot.slotRef??``},{enabled:d&&b!==null}),S=b===null?[]:Oe(b.slot,b.value),C=S.map(e=>e.deviceId),w=(x.data?.candidates??[]).map(Ue),T=new Set(w.map(e=>e.id)),E=C.filter(e=>!T.has(e)).map(e=>{let t=r.get(e);return{id:e,name:t?.name??`#${String(e)}`,...t===void 0?{}:{type:t.type,location:t.location}}}),D=[...w,...E],O=(x.data?.candidates??[]).filter(e=>e.suggested).map(e=>e.deviceId),k=async e=>{if(b!==null){h(null);try{await y.mutateAsync({deviceId:t.id,slotRef:b.slot.slotRef,value:X(b.value,e)}),await g.refetch(),await c.invalidateQueries({queryKey:[[`deviceManager`]]}),p(!1)}catch(e){h(e instanceof Error?e.message:String(e))}}},A=[{key:`device`,header:a(`locations.columns.device`),notSortableReason:a(`locations.columns.noSort`),render:t=>{let i=r.get(t.deviceId),o=t.name??i?.name??`#${String(t.deviceId)}`;return e(`span`,{className:`flex items-center gap-1.5`,children:[i!==void 0&&n($,{type:i.type,role:i.role}),n(Y,{to:`/devices/${String(t.deviceId)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:i===void 0?o:n(B,{device:Z(i),form:`compact`})}),t.implied&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:a(`locations.links.implied`)})]})}},{key:`type`,header:a(`locations.columns.type`),notSortableReason:a(`locations.columns.noSort`),render:e=>n(`span`,{className:`text-xs text-foreground-muted`,children:r.get(e.deviceId)?.type??`—`})},{key:`status`,header:a(`locations.columns.status`),notSortableReason:a(`locations.columns.noSort`),render:e=>{let t=r.get(e.deviceId);return t===void 0?n(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):n(Be,{device:t})}}];return e(`section`,{className:`min-w-0 ${l}`,"data-testid":`camera-links-${String(t.id)}`,children:[e(`header`,{className:`${v} flex min-h-9 items-center gap-1.5`,children:[n($,{type:t.type,role:t.role}),n(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:n(B,{device:Z(t),form:`full`})}),e(I,{variant:`ghost`,size:`sm`,onClick:()=>u(we(t.id)),children:[n(f,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),a(`locations.links.edit`)]}),n(I,{variant:`outline`,size:`sm`,disabled:b===null,onClick:()=>p(!0),"aria-label":a(`locations.links.addNamed`,{camera:s}),children:a(`locations.room.add`)})]}),_.kind===`pending`&&n(`p`,{role:`status`,className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:a(`locations.links.loading`)}),_.kind===`unknown`&&n(`p`,{role:`alert`,className:`px-3 py-3 text-xs text-warning sm:px-4`,children:a(`locations.links.unreadable`,{reason:_.reason})}),_.kind===`absent`&&n(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:a(`locations.links.unsupported`)}),m!==null&&n(`p`,{role:`alert`,className:`px-3 pt-2 text-xs text-danger break-words sm:px-4`,children:m}),b!==null&&(S.length===0?n(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:a(`locations.links.none`)}):n(M,{columns:A,rows:S,rowKey:e=>String(e.deviceId),bordered:!1,minWidthPx:360})),n(Ve,{open:d,title:a(`locations.links.pickTitle`,{camera:s}),items:D,listState:x.status===`error`?`failed`:x.data===void 0?`pending`:`answered`,lockedIds:C,lockedNote:a(`locations.links.alreadyLinked`),suggestions:t.location===null?null:{heading:a(`locations.links.suggested`,{room:t.location}),ids:O},busy:y.isPending,onConfirm:e=>void k(e),onClose:()=>p(!1)})]})}a();function Ge({name:t,description:a,busy:o,onSave:s}){let{t:c}=J(),[l,u]=i(a??``);return r(()=>{u(a??``)},[a]),e(`div`,{className:`border-t border-border px-3 py-2 sm:px-4`,children:[n(_e,{htmlFor:`location-description-${t}`,className:`block`,children:c(`locations.locationDescriptionField.whatIsThere`,`What is there`)}),n(G,{id:`location-description-${t}`,value:l,onChange:e=>u(e.target.value),onBlur:()=>{let e=l.trim();e!==(a??``)&&s(e.length===0?null:e)},disabled:o,rows:2,maxLength:400,placeholder:c(`locations.locationDescriptionField.surfacesBoundariesWhatIsNormally`,`Surfaces, boundaries, what is normally parked or stored here.`),className:`mt-1 w-full resize-y rounded-md border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-inset focus:ring-primary disabled:cursor-not-allowed disabled:opacity-50`}),n(`p`,{className:`mt-1 ${C}`,children:c(`locations.locationDescriptionField.givenToTheAiWith`,`Given to the AI with the pictures, so it knows what it is looking at. Describe the PLACE, not what happens in it — events change, the ground does not.`)})]})}function Ke(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0||n.description.length===0?null:n.description}var qe=` none`;function Je({name:t,zones:r,zoneKey:i,busy:a,onChange:o}){let{t:s}=J();if(r.length===0)return null;let c=[{value:qe,label:s(`locations.locationZoneField.none`,`— none —`)},...r.map(e=>({value:e.zoneKey,label:e.label}))];return e(`div`,{className:`flex items-center gap-2 border-t border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:[n(_e,{htmlFor:`location-zone-${t}`,children:s(`locations.locationZoneField.zone`,`Zone`)}),n(g,{id:`location-zone-${t}`,value:i??qe,disabled:a,onChange:e=>{let t=e.target.value;if(t===qe){o(null);return}let n=r.find(e=>e.zoneKey===t);n!==void 0&&o(n.label)},options:c})]})}function Ye(e,t){return e.find(e=>e.locationKeys.includes(t))?.zoneKey??null}function Xe({name:e,icon:t,busy:r,onPick:i}){return n(be,{value:t,onPick:i,fallbackGlyph:y,clearGlyph:u,labels:{trigger:`Change the icon of ${e}`,panel:`Icon for ${e}`,searchPlaceholder:`Search icons`,clear:`No icon`,noMatches:`No icon matches that`},disabled:r})}function Ze(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0?null:E(n.icon)??`map-pin`}function Qe(e){return`${e.kind}:${String(e.device.id)}`}function $e(e,t,n){return e.flatMap(e=>{let r=Re(t,e.id),i=n.has(e.id),a={kind:`member`,device:e,accessories:r,open:i};return!i||r.length===0?[a]:[a,...r.map(t=>({kind:`accessory`,device:t,parent:e}))]})}a();function et({name:r,members:a,devices:o,busy:u,icon:d,description:f,onRename:p,onDelete:m,onRebuildLinks:h,onAddDevices:g,onPickIcon:y,onSaveDescription:x,zones:C,zoneKey:w,onChangeZone:T}){let{t:E}=J(),[D,k]=i(!1),[A,j]=i(r),N=H(a,t(()=>({searchText:e=>[e.name,...Re(o,e.id).map(e=>e.name)],facetValue:e=>e.type}),[o])),[P,F]=i(()=>new Set),ee=e=>F(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),te=t(()=>$e(N.rows,o,P),[N.rows,o,P]),ne=[{key:`name`,header:E(`locations.columns.device`),notSortableReason:E(`locations.columns.noSort`),render:e=>e.kind===`member`?n(tt,{row:e,onToggle:()=>ee(e.device.id)}):n(nt,{row:e})},{key:`type`,header:E(`locations.columns.type`),notSortableReason:E(`locations.columns.noSort`),render:e=>n(`span`,{className:`text-xs text-foreground-muted`,children:e.device.type})},{key:`status`,header:E(`locations.columns.status`),notSortableReason:E(`locations.columns.noSort`),render:e=>n(Be,{device:e.device})}],L=()=>{j(r),k(!1)},re=async()=>{let e=A.trim();if(e.length===0||e===r){L();return}await p(e),k(!1)},R=[{id:`rename`,label:E(`locations.locationCard.rename`,`Rename`),icon:b,disabled:u,onClick:()=>{j(r),k(!0)}},{id:`rebuild-links`,label:E(`locations.locationCard.rebuildLinkedDevices`,`Rebuild linked devices`),icon:c,separatorBefore:!0,disabled:u,onClick:()=>void h()},{id:`delete`,label:E(`common.delete`,`Delete`),icon:_,danger:!0,separatorBefore:!0,disabled:u,onClick:()=>void m()}];return e(`section`,{className:`min-w-0 ${l}`,children:[e(`header`,{className:`${v} flex min-h-9 items-center gap-1.5`,children:[n(Xe,{name:r,icon:d,busy:u,onPick:y}),D?e(s,{children:[n(O,{value:A,onChange:e=>j(e.target.value),onKeyDown:e=>{e.key===`Enter`&&re(),e.key===`Escape`&&L()},"aria-label":E(`locations.locationCard.rename2`,`Rename {{name}}`,{name:r}),className:`min-w-0 flex-1`,autoFocus:!0}),n(I,{type:`button`,size:`sm`,onClick:()=>void re(),children:E(`common.save`,`Save`)}),n(de,{type:`button`,variant:`ghost`,icon:S,onClick:L,"aria-label":E(`locations.locationCard.cancelRename`,`Cancel rename`)})]}):e(s,{children:[n(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:r}),n(I,{type:`button`,variant:`outline`,size:`sm`,disabled:u,onClick:g,"aria-label":E(`locations.room.addTo`,{room:r}),children:E(`locations.room.add`)}),n(z,{items:R,title:E(`locations.locationCard.actionsFor`,`Actions for {{name}}`,{name:r}),triggerClassName:`p-1`})]})]}),n(Je,{name:r,zones:C,zoneKey:w,busy:u,onChange:T}),n(Ge,{name:r,description:f,busy:u,onSave:x}),a.length>0&&n(`div`,{className:`border-b border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:n(xe,{state:N.state,facets:N.facets,labels:{searchPlaceholder:E(`locations.filter.searchPlaceholder`),searchLabel:E(`locations.room.searchLabel`,{room:r}),facetsLabel:E(`locations.filter.typesLabel`),clearLabel:E(`locations.filter.clear`)},onSearch:N.setSearch,onToggleFacet:N.toggleFacet,onClear:N.clear})}),a.length===0?n(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:E(`locations.locationCard.nothingHereYetAssignA`,`Nothing here yet — assign a device from the table below.`)}):n(M,{columns:ne,rows:te,rowKey:Qe,bordered:!1,minWidthPx:360,emptyMessage:E(`locations.filter.noMatch`)})]})}function tt({row:t,onToggle:r}){let{t:i}=J(),{device:a,accessories:o,open:s}=t,c=K(Z(a),`compact`),l=s?D:d;return e(`span`,{className:`flex items-center gap-1.5`,children:[o.length>0?e(I,{type:`button`,variant:`ghost`,onClick:r,"aria-expanded":s,"aria-label":i(s?`locations.locationCard.collapseAccessories`:`locations.locationCard.expandAccessories`,{count:o.length,name:c}),className:`h-auto shrink-0 gap-0.5 p-0.5 text-foreground-subtle hover:text-foreground`,children:[n(l,{className:`h-3 w-3`}),n(`span`,{className:`text-[10px] tabular-nums`,children:o.length})]}):n(`span`,{"aria-hidden":`true`,className:`w-[1.35rem] shrink-0`}),n($,{type:a.type,role:a.role}),n(Y,{to:`/devices/${String(a.id)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:n(B,{device:Z(a),form:`compact`})})]})}function nt({row:t}){let{device:r,parent:i}=t;return e(`span`,{className:`flex items-center gap-1.5 pl-6`,children:[n(`span`,{"aria-hidden":`true`,className:`text-[10px] text-foreground-subtle`,children:`└`}),n($,{type:r.type,role:r.role,className:`h-3 w-3 shrink-0 text-foreground-subtle`}),n(Y,{to:`/devices/${String(r.id)}`,className:`min-w-0 truncate text-xs text-foreground-muted hover:underline`,children:n(B,{device:Z(r),form:`nested`,parent:Z(i)})})]})}a();function rt({zones:e,busy:t,onRename:r,onDelete:a,onPickIcon:o}){let{t:s}=J(),[c,l]=i(null),[u,d]=i(``),f=async e=>{let t=u.trim();l(null),!(t.length===0||t===e)&&await r(e,t)};return n(M,{columns:[{key:`icon`,header:s(`locations.siteZonesPanel.icon`,`Icon`),width:`w-12`,notSortableReason:`An icon has no order`,render:e=>n(Xe,{name:e.label,icon:e.icon,busy:t,onPick:t=>o(e.label,t)})},{key:`name`,header:s(`locations.siteZonesPanel.zone`,`Zone`),sortValue:e=>e.label.toLowerCase(),render:e=>c===e.label?n(O,{value:u,onChange:e=>d(e.target.value),onKeyDown:t=>{t.key===`Enter`&&f(e.label),t.key===`Escape`&&l(null)},onBlur:()=>void f(e.label),"aria-label":s(`locations.siteZonesPanel.rename`,`Rename {{label}}`,{label:e.label}),autoFocus:!0}):n(I,{type:`button`,variant:`ghost`,size:`sm`,className:`px-0`,onClick:()=>{d(e.label),l(e.label)},disabled:t,title:s(`locations.siteZonesPanel.renameTheZone`,`Rename the zone`),children:e.label})},{key:`rooms`,header:s(`locations.siteZonesPanel.rooms`,`Rooms`),align:`right`,sortValue:e=>e.locationKeys.length,render:e=>n(`span`,{className:`tabular-nums text-foreground-subtle`,children:e.locationKeys.length===0?s(`common.empty`):s(`common.rooms`,{count:e.locationKeys.length})})},{key:`actions`,header:s(`locations.siteZonesPanel.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order`,render:e=>n(I,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void a(e.label),disabled:t,"aria-label":s(`locations.siteZonesPanel.delete`,`Delete {{label}}`,{label:e.label}),title:s(`locations.siteZonesPanel.deleteTheZoneTheRooms`,`Delete the zone — the rooms in it are kept`),children:n(_,{className:`h-3.5 w-3.5`})})}],rows:e,rowKey:e=>e.zoneKey,emptyMessage:s(`locations.siteZonesPanel.noZonesYetAZone`,`No zones yet. A zone groups rooms — “Night zone” for the bedrooms — and shows up before them in the app’s camera filter.`)})}a();function it({busy:t,onCreate:r}){let{t:a}=J(),[o,s]=i(!1),[c,l]=i(``),u=()=>{l(``),s(!1)},d=async()=>{let e=c.trim();e.length!==0&&(await r(e),u())};return o?e(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),d()},children:[n(O,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&u()},placeholder:a(`locations.newLocationButton.frontDoorHallKitchen`,`Front door, Hall, Kitchen…`),"aria-label":a(`locations.newLocationButton.newLocationName`,`New location name`),className:`min-w-[12rem] flex-1`,autoFocus:!0}),e(I,{size:`sm`,type:`submit`,disabled:c.trim().length===0||t,children:[n(x,{className:`h-3.5 w-3.5`}),a(`common.add`,`Add`)]}),n(I,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":a(`locations.newLocationButton.cancelNewLocation`,`Cancel new location`),children:n(S,{className:`h-3.5 w-3.5`})})]}):e(I,{size:`sm`,type:`button`,onClick:()=>s(!0),"data-testid":`new-location-button`,children:[n(x,{className:`h-3.5 w-3.5`}),a(`locations.newLocationButton.newLocation`,`New location`)]})}a();function at({busy:t,onCreate:r}){let{t:a}=J(),[o,s]=i(!1),[c,l]=i(``),u=()=>{l(``),s(!1)},d=async()=>{let e=c.trim();e.length!==0&&(await r(e),u())};return o?e(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),d()},children:[n(O,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&u()},placeholder:a(`locations.newZoneButton.zonaGiornoZonaNotte`,`Zona giorno, Night zone…`),"aria-label":a(`locations.newZoneButton.newZoneName`,`New zone name`),className:`min-w-[12rem] flex-1`,autoFocus:!0}),e(I,{size:`sm`,type:`submit`,disabled:c.trim().length===0||t,children:[n(x,{className:`h-3.5 w-3.5`}),a(`common.add`,`Add`)]}),n(I,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":a(`locations.newZoneButton.cancelNewZone`,`Cancel new zone`),children:n(S,{className:`h-3.5 w-3.5`})})]}):e(I,{size:`sm`,type:`button`,onClick:()=>s(!0),"data-testid":`new-zone-button`,children:[n(x,{className:`h-3.5 w-3.5`}),a(`locations.newZoneButton.newZone`,`New zone`)]})}a();function ot(e,t,n,r){let i=e.map(e=>({value:e.name,label:`${e.name} · ${String(e.count)}`}));return t===void 0?i:[...i,{value:n,label:`${r} · ${String(t)}`}]}function st({rooms:e,unassignedCount:r,value:i,unassignedValue:a,onChange:o}){let{t:s}=J(),c=t(()=>ot(e,r,a,s(`locations.roomPicker.unassigned`)),[e,r,a,s]);return n(`div`,{className:`max-w-sm`,"data-testid":`room-select`,children:n(me,{mode:`single`,singleDisplay:`field`,label:s(`locations.roomPicker.label`),placeholder:s(`locations.roomPicker.placeholder`),options:c,value:i,onChange:o,searchable:!0,testId:`room-select-control`,optionTestIdPrefix:`room-option`})})}a();var ct={searchText:e=>[e.name],facetValue:e=>e.type};function lt({rows:r,fleet:a,locations:o,busy:s,emptyMessage:c,onAssign:l}){let{t:u}=J(),d=P(),f=N(),h=e=>d===null?e.name:V(Z(e),`compact`,d,f),[_,v]=i([]),[y,b]=i(``),x=H(r,ct),S=x.rows,w=t(()=>S.map(e=>e.id),[S]),T=t(()=>_.filter(e=>w.includes(e)),[_,w]),E=S.length>0&&T.length===S.length,D=t(()=>{let e=new Map;for(let t of r)e.set(t.id,Le(a,t.id));return e},[r,a]),O=T.reduce((e,t)=>e+(D.get(t)??0),0),k=e=>v(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),A=()=>v(E?[]:w),j=()=>{y.length===0||T.length===0||(l(T,y),v([]),b(``))},F=o.map(e=>({value:e,label:e})),ee=[{key:`select`,width:`w-8`,headerRender:()=>n(p,{checked:E,onChange:A,"aria-label":E?u(`locations.unassignedTable.clearSelection`,`Clear selection`):u(`locations.unassignedTable.selectAllUnassignedDevices`,`Select all unassigned devices`)}),render:e=>n(p,{checked:T.includes(e.id),onChange:()=>k(e.id),"aria-label":u(`locations.unassignedTable.select`,`Select {{name}}`,{name:h(e)})})},{key:`name`,header:u(`locations.unassignedTable.device`,`Device`),sortValue:e=>e.name.toLowerCase(),render:t=>{let r=Me(t,o);return e(`span`,{className:`flex items-center gap-1.5`,children:[n($,{type:t.type,role:t.role}),n(Y,{to:`/devices/${String(t.id)}`,className:`truncate text-xs text-foreground hover:underline`,children:n(B,{device:Z(t),form:`compact`})}),r!==null&&n(W,{variant:`warning`,children:u(`locations.unassignedTable.unknownRoom`,{room:r})})]})}},{key:`type`,header:u(`locations.unassignedTable.type`,`Type`),sortValue:e=>e.type,render:e=>n(`span`,{className:`text-xs text-foreground-muted`,children:e.type})},{key:`status`,header:u(`locations.unassignedTable.status`,`Status`),sortValue:e=>+!!e.online,render:e=>n(Be,{device:e})},{key:`followers`,header:u(`locations.unassignedTable.accessoriesInTowCount`,`Accessories in tow`),align:`right`,sortValue:e=>D.get(e.id)??0,render:e=>n(`span`,{className:`tabular-nums text-xs text-foreground-muted`,children:D.get(e.id)??0})},{key:`assign`,header:u(`locations.unassignedTable.assignTo`,`Assign to`),align:`right`,notSortableReason:`This column is a control, not a value.`,render:e=>n(g,{"aria-label":u(`locations.unassignedTable.locationFor`,`Location for {{name}}`,{name:h(e)}),value:``,disabled:s||o.length===0,onChange:t=>{let n=t.target.value;n.length!==0&&l([e.id],n)},className:`max-w-[11rem]`,options:[{value:``,label:`—`},...F]})}];return e(`section`,{className:`space-y-2`,children:[e(`header`,{className:`flex flex-wrap items-baseline gap-2`,children:[n(`h2`,{className:m,children:u(`locations.unassignedTable.notInARoom`,`Not in a room`)}),n(`p`,{className:C,children:u(`locations.unassignedTable.topLevelDevicesOnlyAccessories`,`Top-level devices only — accessories move with their parent.`)})]}),r.length>0&&n(xe,{state:x.state,facets:x.facets,labels:{searchPlaceholder:u(`locations.filter.searchPlaceholder`),searchLabel:u(`locations.unassigned.searchLabel`),facetsLabel:u(`locations.filter.typesLabel`),clearLabel:u(`locations.filter.clear`)},onSearch:x.setSearch,onToggleFacet:x.toggleFacet,onClear:x.clear}),T.length>0&&e(`div`,{role:`group`,"aria-label":u(`locations.unassignedTable.bulkAssignment`,`Bulk assignment`),className:`flex flex-wrap items-center gap-2 rounded border border-primary/40 bg-primary/5 px-2 py-1.5`,children:[e(`span`,{className:`text-xs text-foreground`,children:[u(`locations.unassignedTable.selected`,{count:T.length}),O>0&&` · ${u(`locations.unassignedTable.accessoriesInTowCount`,{count:O})}`]}),n(g,{"aria-label":u(`locations.unassignedTable.assignSelectedDevicesTo`,`Assign selected devices to`),value:y,onChange:e=>b(e.target.value),className:`w-auto min-w-[10rem]`,options:[{value:``,label:u(`locations.unassignedTable.assignTo2`,`Assign to…`)},...F]}),n(I,{type:`button`,size:`sm`,onClick:j,disabled:s||y.length===0,children:u(`locations.unassignedTable.assign`,`Assign`)}),n(I,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>v([]),children:u(`locations.unassignedTable.clear`,`Clear`)})]}),n(M,{columns:ee,rows:S,rowKey:e=>e.id,minWidthPx:720,emptyMessage:x.active?u(`locations.filter.noMatch`):c})]})}function ut(e){return{id:e.id,parentDeviceId:e.parentDeviceId,location:e.location,type:e.type,stableId:e.stableId??``,...e.primaryChildEntityId===void 0?{}:{primaryChildEntityId:e.primaryChildEntityId},...e.primaryChildPreference===void 0?{}:{primaryChildPreference:e.primaryChildPreference},...e.role!==void 0&&e.role!==null?{role:e.role}:{},name:e.name}}function dt(e,t){let n=t.map(ut),r=[];for(let i of t)i.isCamera&&i.location===e&&r.push({deviceId:i.id,name:i.name,ids:w({selfId:i.id,selfLocation:i.location,candidates:n})});return{entries:r}}var ft=`device-manager:linked-devices`;function pt(e){return{deviceId:e.deviceId,slotRef:ft,value:{slot:`linked-devices`,deviceIds:[...e.ids]}}}a();var mt=`__unassigned__`;function ht(){let{t:r}=J(),a=o(),s=h(),{data:c,isLoading:l}=Ce(),{data:u}=ae(),{data:d}=ne(),{data:f}=oe(),{data:p,isLoading:m}=re({projection:`slim`}),g=()=>{a.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listLocationIcons`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listLocationDescriptions`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listSiteZones`]]})},_=le({onSuccess:g}),v=te({onSuccess:g}),b=ie({onSuccess:g}),x=ee({onSuccess:g}),S=ue({onSuccess:g}),C=k({onSuccess:g}),w=he({onSuccess:g}),E=ge({onSuccess:g}),D=se({onSuccess:g}),O=ye({onSuccess:g}),A=ce(),j=t(()=>(p??[]).map(e=>({id:e.id,name:e.name,location:e.location??null,type:String(e.type),isCamera:e.isCamera,parentDeviceId:e.parentDeviceId,online:e.online,role:e.role??null,stableId:e.stableId,primaryChildEntityId:e.primaryChildEntityId??null,primaryChildPreference:e.primaryChildPreference??null})),[p]),M=c??[],N=t(()=>ze(j,M),[j,M]),[P,F]=Te(),I=P.get(`tab`),L=I===`zones`||I===`camera-links`?I:`locations`,R=P.get(`room`),z=t(()=>Fe(j,M),[j,M]),B=R===mt,V=B?null:R!==null&&N.some(e=>e.name===R)?R:N[0]?.name??null,H=V===null?null:N.find(e=>e.name===V)??null,de=B?mt:V??`__unassigned__`,U=V??N[0]?.name??null,fe=t(()=>N.map(e=>({name:e.name,count:e.members.length})),[N]),pe=e=>{F(t=>{let n=new URLSearchParams(t);return n.set(`room`,e),n},{replace:!0})},W=l||m,G=b.isPending||v.isPending||_.isPending||S.isPending,me=async e=>{await _.mutateAsync({name:e})},_e=async(e,t)=>{let n=t.trim();n.length===0||n===e||await x.mutateAsync({from:e,to:n})},ve=async e=>{let t=dt(e,j);if(t.entries.length===0){await s({title:r(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:r(`locations.noCameraIsAssignedTo`,`No camera is assigned to “{{room}}”.`,{room:e}),confirmLabel:`OK`});return}let n=t.entries.map(e=>r(`locations.rebuildEntry`,{name:e.name,count:e.ids.length})).join(`
2
- `);if(!await s({title:r(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:r(`locations.replaceTheLinkedDeviceList`,`Replace the linked-device list of every camera in “{{room}}” with what the room contains? {{lines}} Anything linked by hand that is not in this room is lost.`,{room:e,lines:n}),confirmLabel:r(`locations.rebuild`,`Rebuild`),variant:`danger`}))return;let i=[];for(let e of t.entries)try{await A.mutateAsync(pt(e))}catch(t){i.push(`• ${e.name}: ${t instanceof Error?t.message:String(t)}`)}g(),i.length>0&&await s({title:r(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:r(`locations.notRebuilt`,`Not rebuilt: {{value1}}`,{value1:i.join(`
3
- `)}),confirmLabel:`OK`})},be=async(e,t)=>{let n=t>0?` ${String(t)} device(s) will become unassigned.`:``;await s({title:r(`locations.deleteLocation`,`Delete location`),message:r(`locations.deleteTheLocation`,`Delete the location “{{name}}”?{{extra}}`,{name:e,extra:n}),confirmLabel:r(`common.delete`,`Delete`),variant:`danger`})&&await v.mutateAsync({name:e,cascade:!0})},K=async e=>{await s({title:r(`locations.deleteZone`,`Delete zone`),message:r(`locations.deleteTheZoneTheRooms`,`Delete the zone “{{name}}”? The rooms in it are kept.`,{name:e}),confirmLabel:r(`common.delete`,`Delete`),variant:`danger`})&&await E.mutateAsync({name:e})},xe=async(e,t)=>{await S.mutateAsync({location:e,icon:t})},Se=async(e,t)=>{await C.mutateAsync({location:e,description:t})},q=f??[],we=async(e,t)=>{await O.mutateAsync({location:e,zone:t})},Ee=(e,t)=>{for(let n of e)b.mutate({deviceId:n,location:t})},[Y,X]=i(null),Oe=t(()=>j.filter(e=>e.parentDeviceId===null).map(e=>({id:e.id,name:e.name,type:e.type,location:e.location})),[j]),ke=n(st,{rooms:fe,...L===`locations`?{unassignedCount:z.length}:{},value:L===`locations`?de:U??``,unassignedValue:mt,onChange:pe}),Z=e(`div`,{className:`flex flex-col gap-3`,"data-testid":`locations-section`,children:[W&&n(`p`,{className:`text-xs text-foreground-subtle`,children:r(`locations.loadingLocationsAndDevices`,`Loading locations and devices…`)}),ke,B||H===null?n(lt,{rows:z,fleet:j,locations:M,busy:G,emptyMessage:W?r(`common.loading`,`Loading…`):r(`locations.everyTopLevelDeviceHas`,`Every top-level device has a room.`),onAssign:Ee}):n(et,{name:H.name,members:H.members,devices:j,busy:G,icon:Ze(u,T(H.name)),onPickIcon:e=>xe(H.name,e),description:Ke(d,T(H.name)),onSaveDescription:e=>Se(H.name,e),zones:q,zoneKey:Ye(q,T(H.name)),onChangeZone:e=>we(H.name,e),onRename:e=>_e(H.name,e),onDelete:()=>be(H.name,Ae(j,H.name).length),onRebuildLinks:()=>ve(H.name),onAddDevices:()=>X(H.name)},H.name),M.length===0&&!W&&n(`p`,{className:`text-xs text-foreground-subtle`,children:r(`locations.noLocationsYetAddFrontDoor`,`No locations yet. Add Front door, Hall, Kitchen…`)}),n(Ve,{open:Y!==null,title:r(`locations.room.addDialogTitle`,{room:Y??``}),items:Oe,listState:m?`pending`:`answered`,lockedIds:Y===null?[]:(N.find(e=>e.name===Y)?.members??[]).map(e=>e.id),lockedNote:r(`locations.room.alreadyHere`),suggestions:{heading:r(`locations.room.suggestedUnassigned`),ids:z.map(e=>e.id)},busy:b.isPending,onConfirm:e=>{Y!==null&&Ee(e,Y),X(null)},onClose:()=>X(null)})]}),Q=e(`div`,{className:`flex flex-col gap-3`,"data-testid":`camera-links-tab`,children:[ke,n(He,{room:U,cameras:U===null?[]:Ae(j,U).filter(e=>e.isCamera),fleet:j})]});return n(De,{icon:y,title:r(`locations.locations`,`Locations`),subtitle:r(`locations.roomsAndAreasOfThe`,`Rooms and areas of the site. Assign any device here — storage disks are under Data → Storage.`),defaultSection:`locations`,sectionsLabel:`Locations sections`,actions:L===`zones`?n(at,{busy:w.isPending,onCreate:e=>w.mutateAsync({name:e})}):n(it,{busy:_.isPending,onCreate:me}),sections:[{id:`locations`,label:r(`locations.locations`,`Locations`),content:Z},{id:`camera-links`,label:r(`locations.cameraLinks`,`Camera links`),content:Q},{id:`zones`,label:r(`locations.zones`,`Zones`),content:n(rt,{zones:q,busy:G,onRename:(e,t)=>D.mutateAsync({from:e,to:t}),onDelete:K,onPickIcon:(e,t)=>w.mutateAsync({name:e,icon:t})})}]})}export{ht as LocationsPage};
@@ -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{C as n,J as r,K as i,S as a,V as o,Y as s,a as c,et 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-CEyXHAdg.js";import{Di as f,Fr as p,Ki as m,Mn as h,Mr as g,Oa as _,Q as v,Rr as y,Sn as b,Ur as x,Wi as S,Xt as C,Za as w,ct as T,dt as E,en as D,lr as O,pi as k,vt as A}from"./player-overlays-BxDm01PX.js";import{vi as j,yi as M}from"./client-DbKXlEC4.js";import{l as ee,o as N}from"./terminal-DU-tvcEm.js";import{t as P}from"./monitor-smartphone-DPI9EQus.js";import{t as te}from"./unlink-D3-IGpS8.js";import{$f as F,$i as ne,Di as I,Gf as L,Oi as re,Sr as ie,cl as ae,ft as oe,kp as R,ol as se}from"./src-Cn1TCE2g.js";import{t as ce}from"./i18n-1k63HMS1.js";import{t as z}from"./useTranslation-BJr-n0es.js";import"./mount-9s4juC85.js";import{c as le,i as ue,l as B,s as V}from"./sso-popup-n86tgOtV.js";import{F as H,di as U,hi as de,i as W,li as G}from"./index-cl6SWsBh.js";import{t as fe}from"./AdminSectionedPage-DSB1PxSl.js";import{t as pe}from"./AdminPage-BKJUlsLi.js";import{D as me,O as he,_ as ge,a as _e,h as ve,r as ye,t as be,w as xe}from"./SessionsList-BCBUA0_b.js";l();var Se=`${j}/connect`,K={public:0,mesh:1,lan:2,"lan-ipv6":3};function Ce(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 M(e)}function we(e){return e.startsWith(`https://`)}function Te(e){let t=e.flatMap(e=>{let t=Ce(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:we(r),plausible:e.plausible}]))}function Ee(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 De(e){let t=new URL(Se);return t.searchParams.set(`hub`,e),t.toString()}var Oe=176,J={scheme:`https`};function ke(){let{t:e}=z(),t=ae(J),r=se(J).data?.roles.publicEndpoint.resolved??null;return n(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[n(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[a(b,{className:`h-3.5 w-3.5 text-foreground-subtle`}),a(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`connectPhone.title`)})]}),n(`div`,{className:`p-4 space-y-3`,children:[a(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`connectPhone.description`)}),t.isPending?n(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[a(p,{className:`h-3.5 w-3.5 animate-spin`}),e(`connectPhone.loading`)]}):t.isError?n(`div`,{className:`flex items-start gap-2 text-[11px] text-danger`,children:[a(C,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),n(`div`,{className:`flex-1 min-w-0 space-y-1.5`,children:[a(`div`,{className:`break-words`,children:e(`connectPhone.error`,{message:t.error.message})}),a(L,{size:`sm`,variant:`ghost`,onClick:()=>void t.refetch(),children:e(`connectPhone.retry`)})]})]}):a(Ae,{candidates:Te(t.data.endpoints),preferredOrigin:r})]})]})}function Ae({candidates:e,preferredOrigin:t}){let{t:r}=z(),[o,c]=s(null),l=Ee(e,o,t),u=i(()=>l?De(l.origin):null,[l]);if(l===null||u===null)return a(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`connectPhone.empty`)});let d=e=>r(`connectPhone.tier.${e}`),f=e.map(e=>({value:e.origin,label:`${d(e.tier)} — ${e.origin}`}));return n(`div`,{className:`flex flex-col sm:flex-row gap-4`,children:[a(I,{value:u,size:Oe,alt:r(`connectPhone.qrAlt`),className:`self-start`}),n(`div`,{className:`flex-1 min-w-0 space-y-3`,children:[n(`label`,{className:`block space-y-1`,children:[a(`span`,{className:`text-[11px] font-medium text-foreground`,children:r(`connectPhone.addressLabel`)}),a(E,{value:l.origin,options:f,onChange:e=>c(e.target.value)}),n(`span`,{className:`block text-[10px] text-foreground-subtle`,children:[d(l.tier),` · `,l.label]})]}),!l.secure&&a(Y,{text:r(`connectPhone.insecure`)}),!l.plausible&&a(Y,{text:r(`connectPhone.implausible`)}),n(`div`,{className:`space-y-1`,children:[a(`span`,{className:`text-[11px] font-medium text-foreground`,children:r(`connectPhone.linkLabel`)}),n(`div`,{className:`flex items-center gap-1 rounded-md border border-border bg-background px-2 py-1`,children:[a(`code`,{className:`flex-1 min-w-0 font-mono text-[11px] text-foreground break-all select-all`,children:u}),a(ie,{value:u,srLabel:r(`connectPhone.linkLabel`)})]})]}),a(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`connectPhone.signInHint`)})]})]})}function Y({text:e}){return n(`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:[a(C,{className:`h-3.5 w-3.5 text-warning mt-0.5 shrink-0`}),a(`span`,{children:e})]})}l();function je(e){return new Date(e).toLocaleDateString()}function Me(){let{t:e}=z(),t=T(),i=R.useUtils(),c=R.auth.listLinkableProviders.useQuery(),l=R.auth.listOwnExternalIdentities.useQuery(),[u,d]=s(null),[f,h]=s(()=>B(window.location.search)),g=r(null),_=W(`Linking a sign-in account`),b=r(null);o(()=>()=>b.current?.(),[]);let[x,C]=s(null);o(()=>{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 w=R.auth.beginExternalLink.useMutation({onSuccess:({url:e})=>{let t=g.current;if(g.current=null,t===null||t.closed){window.location.assign(e);return}let n=e=>{C(null),h(B(`?${e}`)),i.auth.listOwnExternalIdentities.invalidate()};b.current?.(),b.current=V(t,{onReturn:e=>{e.target===`profile`&&n(e.query)},onDone:e=>{e.target===`profile`&&n(e.query)},onClosed:()=>{b.current?.(),b.current=null,i.auth.listOwnExternalIdentities.invalidate()}}),t.location.href=v(le(e))},onError:e=>{g.current?.close(),g.current=null,C(null),d(e.message)}}),E=R.auth.unlinkOwnExternalIdentity.useMutation({onSuccess:()=>void i.auth.listOwnExternalIdentities.invalidate(),onError:e=>d(e.message)}),D=c.data??[],O=l.data??[],k=x!==null&&O.some(e=>e.provider===x);if(o(()=>{!k||x===null||(C(null),h({kind:`linked`,provider:x}))},[k,x]),D.length===0&&O.length===0)return null;let A=new Set(O.map(e=>e.provider)),j=e=>D.find(t=>t.provider===e)?.label??e,M=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`})&&(d(null),E.mutate({provider:n.provider,subject:n.subject}))};return n(`div`,{"data-testid":`linked-sign-ins`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[_.dialog,n(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[a(y,{className:`h-3.5 w-3.5 text-foreground-subtle`}),a(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`users.linkedSignInsSection.linkedSignInAccounts`,`Linked sign-in accounts`)})]}),n(`div`,{className:`p-4 space-y-3`,children:[a(`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`&&n(`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:[a(S,{className:`h-3.5 w-3.5 text-emerald-500 shrink-0`}),e(`users.linkedSignIns.linkedNotice`,{provider:j(f.provider)})]}),(f?.kind===`error`||u)&&n(`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:[a(m,{className:`h-3.5 w-3.5 shrink-0`}),u??(f?.kind===`error`?f.message:``)]}),O.length>0&&a(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:O.map(t=>{let r=t.providerLabel??t.provider;return n(`li`,{className:`flex items-center gap-3 px-3 py-2 text-xs`,children:[n(`div`,{className:`flex-1 min-w-0`,children:[n(`div`,{className:`font-medium text-foreground truncate`,children:[r,!t.available&&a(`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`)})]}),a(`div`,{className:`text-[11px] text-foreground-subtle truncate`,children:e(`users.linkedSignIns.linkedOn`,{label:t.label??t.subject,date:je(t.linkedAt)})})]}),n(L,{variant:`unstyled`,onClick:()=>void M(t,r),disabled:E.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:[a(te,{className:`h-3 w-3`}),e(`users.linkedSignInsSection.unlink`,`Unlink`)]})]},`${t.provider}|${t.subject}`)})}),a(`div`,{className:`flex flex-wrap gap-2`,children:D.filter(e=>!A.has(e.provider)).map(t=>n(L,{variant:`unstyled`,onClick:()=>{d(null),h(null),_.requestProof().then(e=>{e!==null&&(g.current=ue(null),C(g.current===null?null:t.provider),w.mutate({provider:t.provider,reauthToken:e}))})},disabled:w.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:[w.isPending&&w.variables?.provider===t.provider?a(p,{className:`h-3 w-3 animate-spin`}):a(y,{className:`h-3 w-3`}),e(`users.linkedSignIns.link`,{provider:t.label})]},t.provider))})]})]})}l();function Ne({value:r,size:i=192}){let{t:c}=z(),[l,u]=s(null),[d,f]=s(null);if(o(()=>{let n=!1;return t(()=>import(`./browser-BHo8W_uH.js`).then(t=>e(t.default,1)).then(async e=>{if(n)return;let t=e.create;if(typeof t!=`function`){f(`qrcode.create() unavailable in installed version`);return}try{let e=t(r,{errorCorrectionLevel:`M`});n||u(e)}catch(e){n||f(e instanceof Error?e.message:`QR generation failed`)}}),__vite__mapDeps([0,1]),import.meta.url).catch(()=>{n||f(`qrcode library not installed`)}),()=>{n=!0}},[r]),d)return a(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle text-center p-4`,style:{width:i,height:i},children:c(`users.totpQrCode.qrRenderingUnavailableUseThe`,`QR rendering unavailable — use the secret below.`)});if(!l)return a(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle animate-pulse`,style:{width:i,height:i},children:c(`users.totpQrCode.generating`,`Generating…`)});let p=l.modules.size,m=i/p,h=[];for(let e=0;e<p;e++)for(let t=0;t<p;t++)l.modules.data[e*p+t]&&h.push(a(`rect`,{x:t*m,y:e*m,width:m,height:m,fill:`currentColor`},`${t}-${e}`));return n(`svg`,{width:i,height:i,viewBox:`0 0 ${i} ${i}`,className:`text-black`,children:[a(`rect`,{x:0,y:0,width:i,height:i,fill:`white`}),h]})}l();function Pe(){let{t:e}=z(),t=A(),[r,i]=s(``),[o,c]=s(``),[l,d]=s(``),[f,h]=s(null),_=u({mutationFn:e=>t.changeOwnPassword(e),onSuccess:()=>{h({kind:`success`,msg:`Password updated.`}),i(``),c(``),d(``)},onError:e=>{h({kind:`error`,msg:e instanceof Error?e.message:`Update failed`})}}),v=o.length>0&&l.length>0&&o!==l,y=o.length>0&&o.length<8,b=r.length>=1&&o.length>=8&&o===l;return n(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[n(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[a(ee,{className:`h-3.5 w-3.5 text-foreground-subtle`}),a(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`systemPage.myAccess.changePassword`,`Change password`)})]}),n(`div`,{className:`p-4 space-y-3`,children:[a(X,{label:e(`systemPage.myAccess.currentPassword`,`Current password`),value:r,onChange:i,autoComplete:`current-password`}),a(X,{label:e(`systemPage.myAccess.newPassword`,`New password`),value:o,onChange:c,autoComplete:`new-password`,hint:e(`systemPage.myAccess.atLeast8Characters`,`At least 8 characters.`)}),a(X,{label:e(`systemPage.myAccess.confirmNewPassword`,`Confirm new password`),value:l,onChange:d,autoComplete:`new-password`}),(v||y)&&a(`div`,{className:`text-[11px] text-danger`,children:v?e(`systemPage.myAccess.passwordsDoNotMatch`,`Passwords do not match.`):e(`systemPage.myAccess.newPasswordMustBeAt`,`New password must be at least 8 characters.`)}),f&&n(`div`,{className:`text-[11px] flex items-center gap-1 ${f.kind===`success`?`text-success`:`text-danger`}`,children:[f.kind===`success`?a(S,{className:`h-3 w-3`}):a(m,{className:`h-3 w-3`}),f.msg]}),a(`div`,{className:`flex justify-end`,children:n(L,{onClick:()=>{h(null),_.mutate({currentPassword:r,newPassword:o})},disabled:!b||_.isPending,children:[_.isPending?a(p,{className:`h-3 w-3 animate-spin`}):a(g,{className:`h-3 w-3`}),e(`systemPage.myAccess.updatePassword`,`Update password`)]})})]})]})}function X({label:e,value:t,onChange:r,autoComplete:i,hint:o}){return n(`div`,{className:`space-y-1`,children:[a(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e}),a(F,{type:`password`,value:t,onChange:e=>r(e.target.value),autoComplete:i,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),o&&a(`div`,{className:`text-[10px] text-foreground-subtle`,children:o})]})}function Fe({username:e}){let{t}=z(),r=A(),l=c({queryKey:[`auth`,`getOwnTotpStatus`],queryFn:()=>r.getOwnTotpStatus()}),h=l.data,[g,_]=s(null),[v,y]=s(``),[x,C]=s(null),[w,T]=s(!1),E=u({mutationFn:()=>r.setupOwnTotp(),onSuccess:e=>{_({secret:e.secret,otpauthUrl:e.otpauthUrl}),y(``),C(null)},onError:e=>C(e instanceof Error?e.message:`Setup failed`)}),D=u({mutationFn:e=>r.confirmOwnTotp(e),onSuccess:()=>{_(null),y(``),C(null),l.refetch()},onError:e=>C(e instanceof Error?e.message:`Confirmation failed — code did not match`)}),O=W(`Turning off two-factor authentication`),k=u({mutationFn:async()=>{let e=await O.requestProof();return e===null?null:r.disableOwnTotp({reauthToken:e})},onSuccess:()=>{C(null),l.refetch()},onError:e=>C(e instanceof Error?e.message:`Disable failed`)});o(()=>{if(!w)return;let e=setTimeout(()=>T(!1),1500);return()=>clearTimeout(e)},[w]);let j=i(()=>l.isLoading?`loading`:g?`setup_in_progress`:h?.enabled?`enrolled`:`not_enrolled`,[l.isLoading,h?.enabled,g]);return n(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[O.dialog,n(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[a(b,{className:`h-3.5 w-3.5 text-foreground-subtle`}),a(`div`,{className:`text-xs font-semibold text-foreground`,children:t(`systemPage.myAccess.twoFactorAuthentication`,`Two-factor authentication`)})]}),n(`div`,{className:`p-4 space-y-3`,children:[j===`loading`&&n(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[a(p,{className:`h-3.5 w-3.5 animate-spin`}),t(`systemPage.myAccess.checkingStatus`,`Checking status…`)]}),j===`not_enrolled`&&n(d,{children:[a(`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.`)}),a(`div`,{className:`flex justify-end`,children:n(L,{onClick:()=>{C(null),E.mutate()},disabled:E.isPending,children:[E.isPending?a(p,{className:`h-3 w-3 animate-spin`}):a(b,{className:`h-3 w-3`}),t(`systemPage.myAccess.enable2fa`,`Enable 2FA`)]})})]}),j===`setup_in_progress`&&g&&n(d,{children:[a(`div`,{className:`text-[11px] text-foreground-subtle`,children:a(G,{i18nKey:`systemPage.myAccess.scanQr`,values:{username:e},components:{mono:a(`span`,{className:`font-mono`})}})}),n(`div`,{className:`flex flex-col items-center gap-3`,children:[a(`div`,{className:`rounded-lg border border-border bg-white p-3`,children:a(Ne,{value:g.otpauthUrl,size:180})}),n(`div`,{className:`w-full`,children:[a(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle mb-1`,children:t(`systemPage.myAccess.secretManualEntry`,`Secret (manual entry)`)}),n(`div`,{className:`flex items-center gap-2 rounded border border-border bg-surface-hover/30 px-2 py-1.5`,children:[a(`code`,{className:`text-[11px] font-mono text-foreground break-all flex-1`,children:g.secret}),n(L,{variant:`ghost`,onClick:()=>{g&&navigator.clipboard.writeText(g.secret).then(()=>T(!0))},children:[w?a(S,{className:`h-3 w-3 text-success`}):a(f,{className:`h-3 w-3`}),w?t(`systemPage.myAccess.copied`,`Copied`):t(`common.copy`,`Copy`)]})]})]})]}),n(`div`,{className:`space-y-1`,children:[a(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`6-digit code`}),a(F,{type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,placeholder:`123456`,value:v,onChange:e=>y(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full rounded-md border border-border bg-surface px-3 py-2 text-center text-lg font-mono tracking-widest text-foreground focus:outline-none focus:ring-2 focus:ring-primary`})]}),x&&n(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[a(m,{className:`h-3 w-3`}),x]}),n(`div`,{className:`flex justify-end gap-2`,children:[a(L,{variant:`outline`,onClick:()=>{_(null),C(null),y(``)},children:t(`common.cancel`,`Cancel`)}),n(L,{onClick:()=>{C(null),D.mutate({code:v})},disabled:D.isPending||v.length!==6,children:[D.isPending?a(p,{className:`h-3 w-3 animate-spin`}):a(S,{className:`h-3 w-3`}),t(`common.confirm`,`Confirm`)]})]})]}),j===`enrolled`&&h&&n(d,{children:[n(`div`,{className:`rounded-md border border-success/30 bg-success/5 px-3 py-2.5 flex items-start gap-2.5`,children:[a(S,{className:`h-4 w-4 mt-0.5 text-success shrink-0`}),n(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[a(`div`,{className:`font-medium`,children:t(`systemPage.myAccess.2faIsActive`,`2FA is active`)}),a(`div`,{className:`text-foreground-subtle`,children:t(`common.enrolledOn`,{when:h.confirmedAt?new Date(h.confirmedAt).toLocaleString():`—`})})]})]}),x&&n(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[a(m,{className:`h-3 w-3`}),x]}),a(`div`,{className:`flex justify-end`,children:n(L,{variant:`danger`,onClick:()=>{C(null),k.mutate()},disabled:k.isPending,children:[k.isPending?a(p,{className:`h-3 w-3 animate-spin`}):a(b,{className:`h-3 w-3`}),t(`systemPage.myAccess.disable2fa`,`Disable 2FA`)]})})]})]})]})}function Ie(){return ne(`auth-webauthn/passkey-enrollment`)?a(re,{widgetId:`auth-webauthn/passkey-enrollment`,host:`dashboard`}):null}l();function Z(e){return e.message.length>0?e.message:ce.t(`auth.authAuditSection.requestFailed`)}function Le(){let{t:e}=z(),{logout:t}=H(),r=T(),i=R.useUtils(),o=R.auth.listOwnSessions.useQuery(),[c,l]=s(null),u=R.auth.revokeOwnSession.useMutation({onSuccess:()=>void i.auth.listOwnSessions.invalidate(),onError:e=>l(`Sign out failed: ${Z(e)}`)}),d=R.auth.logout.useMutation({onSuccess:()=>t(),onError:e=>l(`Sign out failed: ${Z(e)}`)}),f=async t=>{await r({title:e(`auth.mySessionsSection.signOutThisSession`,`Sign out this session`),message:e(`auth.mySessionsSection.willHaveToSignIn`,`{{label}} will have to sign in again.`,{label:ge(t.client).label}),confirmLabel:e(`auth.mySessionsSection.signOut`,`Sign out`),variant:`danger`})&&(l(null),u.mutate({id:t.id}))},m=async()=>{await r({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`})&&(l(null),d.mutate({everywhere:!0}))};return n(`div`,{"data-testid":`my-sessions`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[n(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[a(P,{className:`h-3.5 w-3.5 text-foreground-subtle`}),a(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`auth.mySessionsSection.activeSessions`,`Active sessions`)})]}),n(`div`,{className:`p-4 space-y-3`,children:[a(`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.`)}),c!==null&&a(`div`,{className:`text-[11px] text-danger`,children:c}),a(be,{sessions:o.data??[],isLoading:o.isLoading,loadError:o.isError?o.error?.message??e(`auth.authAuditSection.requestFailed`):null,emptyText:`No active sessions.`,onRevoke:e=>void f(e),revokingId:u.isPending?u.variables?.id??null:null}),a(`div`,{className:`flex justify-end`,children:n(L,{variant:`unstyled`,onClick:()=>void m(),disabled:d.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:[d.isPending?a(p,{className:`h-3 w-3 animate-spin`}):a(N,{className:`h-3 w-3`}),e(`auth.mySessionsSection.signOutEverywhere`,`Sign out everywhere`)]})})]})]})}l();var Re=`You`;function Q(){let{t:e}=z(),t=T(),n=R.useUtils(),r=R.auth.listOwnDeviceCredentials.useQuery(),[o,c]=s(null),l=R.auth.revokeOwnDeviceCredential.useMutation({onSuccess:e=>{e.revoked||c(`That device could not be revoked - it may already be gone.`),n.auth.listOwnDeviceCredentials.invalidate()},onError:e=>c(`Revoke failed: ${e.message}`)}),u=i(()=>(r.data??[]).map(e=>ye(e,Re)),[r.data]),d=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`})&&(c(null),l.mutate({id:n.id}))},f={label:e(`certificates.myDevicesSection.revoke2`,`Revoke`),icon:_,isAvailable:_e,onRun:e=>void d(e),busyId:l.isPending?l.variables?.id??null:null,disabled:l.isPending};return a(me,{id:`my-devices`,title:e(`certificates.myDevicesSection.myDevices`,`My devices`),icon:b,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:he(o),onDismissNotice:()=>c(null),children:a(xe,{rows:u,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:f})})}var $={profile:`profile`,signIn:`sign-in`,sessions:`sessions`,tokens:`tokens`},ze=[`linked`,`linkError`],Be={view:{icon:k,cls:`bg-foreground-subtle/15 text-foreground-subtle`},create:{icon:O,cls:`bg-primary/15 text-primary`},delete:{icon:D,cls:`bg-danger/15 text-danger`}};function Ve(){let{t:e}=z(),{user:t,logout:r}=H(),[i]=de(),o=e(`system.myAccess`,`My access`);if(!t)return a(pe,{icon:h,title:o,children:a(`div`,{className:`text-xs text-foreground-subtle`,children:e(`systemPage.myAccess.notSignedIn`,`Not signed in.`)})});if(i.get(`tab`)===`preferences`)return a(U,{to:`/system/settings`,replace:!0});if(ze.some(e=>i.has(e))&&!i.has(`tab`)){let e=new URLSearchParams(i);return e.set(`tab`,$.signIn),a(U,{to:`?${e.toString()}`,replace:!0})}return a(fe,{icon:h,title:o,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:n(L,{variant:`outline`,onClick:r,children:[a(N,{className:`h-3 w-3`}),e(`systemPage.myAccess.signOut`,`Sign out`)]}),sections:[{id:$.profile,label:e(`systemPage.myAccess.sections.profile`,`Profile`),content:a(He,{user:t})},{id:$.signIn,label:e(`systemPage.myAccess.sections.signIn`,`Sign-in & security`),content:n(`div`,{className:`space-y-4`,children:[a(Pe,{}),a(Fe,{username:t.username}),a(Ie,{}),a(Me,{})]})},{id:$.sessions,label:e(`systemPage.myAccess.sections.sessions`,`Sessions & devices`),content:n(`div`,{className:`space-y-4`,children:[a(Le,{}),a(Q,{}),a(ke,{})]})},{id:$.tokens,label:e(`systemPage.myAccess.sections.tokens`,`Tokens`),content:a(ve,{ownOnly:!0})}]})}function He({user:e}){let{t}=z(),r=e.isAdmin,i=e.scopes??[];return n(`div`,{className:`space-y-4`,children:[n(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3 flex items-center gap-3`,children:[a(`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()}),n(`div`,{className:`flex-1 min-w-0`,children:[a(`div`,{className:`text-sm font-semibold text-foreground truncate`,children:e.username}),n(`div`,{className:`text-[11px] text-foreground-subtle`,children:[r?t(`systemPage.myAccess.administrator`,`Administrator`):t(`systemPage.myAccess.user`,`User`),` `,a(G,{i18nKey:`systemPage.myAccess.sessionId`,values:{id:e.id.slice(0,8)},components:{mono:a(`span`,{className:`font-mono`})}})]})]})]}),r&&n(`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:[a(x,{className:`h-4 w-4 text-primary mt-0.5 shrink-0`}),n(`div`,{children:[a(`div`,{className:`font-semibold text-foreground`,children:t(`systemPage.myAccess.unrestrictedAccess`,`Unrestricted access`)}),a(`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.`)})]})]}),i.length>0&&a(Ue,{scopes:i})]})}function Ue({scopes:e}){let{t}=z(),r=w();return n(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[n(`div`,{className:`px-4 py-2 border-b border-border`,children:[a(`div`,{className:`text-xs font-semibold text-foreground`,children:t(`systemPage.myAccess.grantedScopes`,`Granted scopes`)}),a(`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.`)})]}),n(`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:[a(`div`,{children:t(`systemPage.myAccess.type`,`Type`)}),a(`div`,{children:t(`systemPage.myAccess.target`,`Target`)}),a(`div`,{children:t(`systemPage.myAccess.access`,`Access`)})]}),a(`ul`,{className:`divide-y divide-border`,children:e.map((e,i)=>n(`li`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2.5 items-center text-xs`,children:[a(`span`,{className:`font-mono text-foreground-subtle`,children:e.type}),a(`span`,{className:`font-mono text-foreground`,children:e.type===`device`?oe(e.selector,r):e.target}),a(`div`,{className:`flex items-center gap-1`,children:[`view`,`create`,`delete`].map(r=>{let i=e.access.includes(r),{icon:o,cls:s}=Be[r];return n(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${i?s:`bg-transparent text-foreground-subtle/40 line-through`}`,title:i?t(`systemPage.myAccess.can`,`Can {{a}}`,{a:r}):t(`systemPage.myAccess.cannot`,`Cannot {{a}}`,{a:r}),children:[a(o,{className:`h-3 w-3`}),r]},r)})})]},i))})]})}export{Ve as MyAccessPage};
@@ -1,2 +0,0 @@
1
- import{C as e,K as t,S as n,V as r,Y as i,et as a}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{D as o,Fr as s,Ga as c,Mn as l,Nn as u,Ua as d,Ui as f,Za as p,ct as m,dt as h,en as g,pi as ee,ut as _,wt as v}from"./player-overlays-BxDm01PX.js";import{Ns as y}from"./client-DbKXlEC4.js";import{a as b,i as x,l as S,o as C}from"./terminal-DU-tvcEm.js";import{$f as te,Ai as w,Ar as T,Fi as E,Gf as D,Jr as ne,Kr as O,Li as re,Mf as k,Ni as A,Ns as j,Or as M,Pi as N,Ri as P,Sr as F,X as ie,Y as I,Yr as L,br as R,ep as z,et as ae,fa as B,ft as V,ji as H,jr as U,ki as oe,kp as W,la as se,ma as G,ri as K,tt as ce,xr as le}from"./src-Cn1TCE2g.js";import{t as q}from"./i18n-1k63HMS1.js";import{t as J}from"./useTranslation-BJr-n0es.js";import{F as ue,i as de,li as fe}from"./index-cl6SWsBh.js";a();function Y({id:t,title:r,icon:i,description:a,actions:s,tone:l=`default`,notice:u=null,onDismissNotice:d,children:f}){return n(M,{headingId:`access-${t}`,title:r,icon:i,actions:s,testId:`access-${t}`,children:e(`div`,{className:`${o} space-y-3`,children:[n(`div`,{className:c(`text-[11px] leading-relaxed`,l===`danger`?`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-foreground`:`text-foreground-subtle`),children:a}),u!==null&&n(X,{notice:u,onDismiss:d}),f]})})}var pe={success:{icon:f,line:`border-success/30 text-foreground`,mark:`text-success`},danger:{icon:x,line:`border-danger/40 text-danger`,mark:`text-danger`}};function X({notice:t,onDismiss:r}){let{t:i}=J(),a=pe[t.tone],o=a.icon;return e(`div`,{role:t.tone===`danger`?`alert`:`status`,className:c(`flex items-start gap-2 rounded-md border bg-surface px-3 py-2 text-[11px]`,a.line),children:[n(o,{className:c(`mt-0.5 h-3.5 w-3.5 shrink-0`,a.mark),"aria-hidden":!0}),n(`span`,{className:`min-w-0 flex-1`,children:t.message}),r!==void 0&&n(z,{type:`button`,variant:`ghost`,size:`sm`,icon:v,"aria-label":i(`access.accessSection.dismiss`,`Dismiss`),onClick:r,className:`-my-1 h-5 w-5`})]})}function me(){let{data:e}=k();return t(()=>{let t=new Map;for(let n of e??[])t.set(n.id,n.username);return t},[e])}function he(e,t=null){return e===null?t:{tone:`danger`,message:e}}var ge={active:`access.credentialColumns.statusActive`,expired:`access.credentialColumns.statusExpired`,revoked:`access.credentialColumns.statusRevoked`,current:`access.credentialColumns.statusCurrent`};function _e(e){return q.t(ge[e])}var ve={active:`success`,expired:`warning`,revoked:`default`,current:`info`},ye={current:0,active:1,expired:2,revoked:3};function be(e,t){if(e===null)return t;let n=new Date(e);return Number.isNaN(n.getTime())?`—`:n.toLocaleString()}function xe({status:e}){return n(G,{variant:ve[e],className:`text-[10px]`,children:_e(e)})}function Se({row:t,action:r}){if(!r.isAvailable(t))return null;let i=r.icon,a=r.busyId===t.id;return e(D,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>r.onRun(t),disabled:r.disabled,"aria-label":q.t(`access.credentialColumns.actionOn`,{action:r.label,name:t.name}),className:r.tone===`neutral`?void 0:`text-danger hover:bg-danger/10`,children:[a?n(s,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):n(i,{className:`h-3 w-3`,"aria-hidden":!0}),r.label]})}function Ce(t){return[{key:`name`,header:q.t(`access.credentialColumns.name`,`Name`),sortValue:e=>e.name.toLowerCase(),render:t=>e(`div`,{className:`min-w-0 max-w-[18rem]`,children:[n(`div`,{className:`truncate font-medium text-foreground`,title:t.name,children:t.name}),t.detail!==null&&n(`div`,{className:`truncate font-mono text-[10px] text-foreground-subtle`,title:t.detail,children:t.detail})]})},t.hideOwner?null:{key:`owner`,header:q.t(`access.credentialColumns.owner`,`Owner`),sortValue:e=>e.ownerName.toLowerCase(),render:e=>e.ownerName},{key:`kind`,header:q.t(`access.credentialColumns.kindScope`,`Kind / scope`),sortValue:e=>e.kind.toLowerCase(),nowrap:!1,render:t=>e(`div`,{className:`min-w-[8rem] max-w-[16rem]`,children:[n(`div`,{className:`text-foreground`,children:t.kind}),t.scope!==null&&n(`div`,{className:`line-clamp-2 text-[10px] text-foreground-subtle`,title:t.scope,children:t.scope})]})},{key:`status`,header:q.t(`access.credentialColumns.status`,`Status`),sortValue:e=>ye[e.status],render:e=>n(xe,{status:e.status})},{key:`created`,header:q.t(`access.credentialColumns.created`,`Created`),sortValue:e=>e.createdAt,render:e=>n(`span`,{className:`text-foreground-subtle`,children:be(e.createdAt,`—`)})},{key:`lastUsed`,header:q.t(`access.credentialColumns.lastUsed`,`Last used`),sortValue:e=>e.lastUsedAt,render:e=>n(`span`,{className:`text-foreground-subtle`,children:be(e.lastUsedAt,q.t(`access.credentialColumns.never`))})},{key:`expires`,header:q.t(`access.credentialColumns.expires`,`Expires`),sortValue:e=>e.expiresAt,render:e=>n(`span`,{className:`text-foreground-subtle`,children:be(e.expiresAt,t.expiresNone)})},t.action===null?null:{key:`actions`,header:``,align:`right`,notSortableReason:q.t(`access.credentialColumns.actionsHeader`),render:e=>n(`div`,{className:`flex items-center justify-end gap-1`,children:[...t.extraActions??[],t.action].map(t=>t===null?null:n(Se,{row:e,action:t},t.label))})}].filter(e=>e!==null)}a();var we=6,Te={"current-session":`access.bulk.skipCurrentSession`,"not-active":`access.bulk.skipNotActive`};function Ee(e){let t=Te[e];return t===void 0?e:q.t(t)}function Z(e,t){return q.t(t.key,{count:e})}function Q(e,t){return q.t(`access.bulk.countOf`,{count:e,noun:Z(e,t)})}function De(e){let t=new Map;for(let n of e)t.set(n.status,(t.get(n.status)??0)+1);return[...t.entries()].map(([e,t])=>q.t(`access.bulk.statusCount`,{count:t,status:_e(e).toLowerCase()})).join(`, `)}function Oe(e,t){let n=e.slice(0,we).map(e=>`• ${e.name} — ${e.ownerName}`),r=e.length>we?[q.t(`access.bulk.previewMore`,{count:e.length-we})]:[];return[q.t(`access.bulk.previewIntro`,{what:Q(e.length,t),breakdown:De(e)}),``,...n,...r].join(`
2
- `)}async function ke(e,t,n){let r=String(t.length),i=await e({title:q.t(`access.bulk.confirmTitle`,{what:Q(t.length,n)}),message:Oe(t,n),label:q.t(`access.bulk.confirmLabel`,{expected:r}),placeholder:r,confirmLabel:q.t(`access.bulk.confirmButton`,{expected:r}),variant:`danger`,validate:e=>e.trim()===r?null:q.t(`access.bulk.confirmMismatch`,{expected:r,noun:Z(2,n)})});return i!==null&&i.trim()===r}function Ae(e,t){let n=_(),r=W.auth.revokeCredentials.useMutation(),[a,o]=i(null);return{run:async i=>{if(i.length===0||!await ke(n,i,e))return!1;o(null);try{let t=await r.mutateAsync({ids:i.map(e=>e.id),confirmCount:i.length}),n=t.skipped.map(e=>Ee(e.reason));return o({tone:`success`,message:n.length>0?q.t(`access.bulk.revokedSkipped`,{what:Q(t.revoked.length,e),count:n.length,reasons:[...new Set(n)].join(`, `)}):q.t(`access.bulk.revoked`,{what:Q(t.revoked.length,e)})}),!0}catch(e){return o({tone:`danger`,message:q.t(`access.bulk.revokeFailed`,{error:e instanceof Error?e.message:q.t(`access.bulk.requestFailed`)})}),!1}finally{t()}},busy:r.isPending,outcome:a,dismiss:()=>o(null)}}function je(e,t,n){let r=_(),[a,o]=i(!1),[s,c]=i(null);return{run:async i=>{if(i.length===0||!await ke(r,i,e))return!1;c(null),o(!0);let a=[],s=0;for(let e of i)try{await t(e.id),s+=1}catch(t){a.push(`${e.name}: ${t instanceof Error?t.message:q.t(`access.bulk.requestFailed`)}`)}return o(!1),n(),a.length===0?(c({tone:`success`,message:q.t(`access.bulk.revoked`,{what:Q(s,e)})}),!0):(c({tone:`danger`,message:q.t(a.length>3?`access.bulk.eachPartialMore`:`access.bulk.eachPartial`,{what:Q(s,e),count:a.length,details:a.slice(0,3).join(`; `)})}),s>0)},busy:a,outcome:s,dismiss:()=>c(null)}}a();var Me={searchText:e=>[e.name,e.detail??``,e.ownerName,e.kind,e.scope??``],facetGroups:[{id:`status`,value:e=>e.status},{id:`owner`,value:e=>e.ownerName},{id:`kind`,value:e=>e.kind}]},Ne={status:`access.credentialTable.groupStatus`,owner:`access.credentialTable.groupOwner`,kind:`access.credentialTable.groupKind`},Pe=e=>e.status!==`current`,Fe=[`active`,`current`];function Ie({rows:r,label:a,isLoading:o,loadError:c,emptyText:l,hideOwner:u=!1,expiresNone:d,action:f,extraActions:p,bulk:m,defaultStatus:h=Fe}){let{t:g}=J(),[ee]=i(()=>h.length===0?{search:``,facets:[]}:{search:``,facets:[],groups:{status:[...h]}}),_=R(r,Me,ee),[v,y]=i(()=>new Set),b=d??g(`access.credentialColumns.never`),x=t(()=>Ce({hideOwner:u,expiresNone:b,action:f??null,...p===void 0?{}:{extraActions:p}}),[u,b,f,p,g]),S=t(()=>m===void 0?()=>!1:e=>Pe(e)&&m.isSelectable(e),[m]),C=t(()=>_.rows.filter(e=>v.has(e.id)&&S(e)),[_.rows,v,S]);return o?e(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[n(s,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),g(`access.credentialTable.loading`,{label:a})]}):c===null?e(`div`,{className:`space-y-3`,children:[n(le,{state:_.state,facets:_.facets,groups:_.groups.filter(e=>!(u&&e.id===`owner`)).map(e=>({...e,label:Ne[e.id]===void 0?e.id:g(Ne[e.id]),...e.id===`status`?{facetLabel:e=>_e(e)}:{}})),labels:{searchPlaceholder:g(`access.credentialTable.searchPlaceholder`,{label:a}),searchLabel:g(`access.credentialTable.searchLabel`,{label:a}),facetsLabel:g(`access.credentialTable.facetsLabel`,{label:a}),clearLabel:g(`access.credentialTable.clearFilters`)},onSearch:_.setSearch,onToggleFacet:_.toggleFacet,onToggleGroupFacet:_.toggleGroupFacet,onClear:_.clear}),m!==void 0&&n(Le,{bulk:m,shown:_.rows.filter(S),targets:C,onSelect:y}),n(T,{columns:x,rows:_.rows,rowKey:e=>e.id,minWidthPx:u?760:860,maxBodyHeight:U,defaultSort:{columnKey:`created`,dir:`desc`},pageSize:25,paginationLabels:{navLabel:g(`access.credentialTable.pagesLabel`,{label:a}),previous:g(`access.credentialTable.previousPage`),next:g(`access.credentialTable.nextPage`),range:(e,t,n)=>g(`access.credentialTable.range`,{from:e,to:t,total:n})},emptyMessage:_.active?g(`access.credentialTable.noMatchTheFilters`,`No {{label}} match the filters.`,{label:a}):l,rowClassName:e=>e.status===`revoked`||e.status===`expired`?`opacity-70`:void 0,...m===void 0?{}:{selection:{selected:v,onChange:y,isSelectable:S,rowLabel:e=>g(`access.credentialTable.rowLabel`,{name:e.name,owner:e.ownerName}),pageLabel:g(`access.credentialTable.pageLabel`,{noun:Z(1,m.noun)})}}})]}):n(B,{title:g(`access.credentialTable.couldNotLoad`,`Could not load {{label}}`,{label:a}),message:c})}function Le({bulk:t,shown:r,targets:i,onSelect:a}){let{t:o}=J(),{revoke:c,noun:l}=t,u=(t.quickSelect??[]).map(e=>({...e,rows:r.filter(e.match)})).filter(e=>e.rows.length>0),d=async()=>{await c.run(i)&&a(new Set)};return e(`div`,{className:`flex flex-wrap items-center gap-2`,"data-testid":`bulk-bar`,children:[r.length>0&&n(D,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>a(new Set(r.map(e=>e.id))),children:o(`access.credentialTable.selectAllShown`,{count:r.length})}),u.map(t=>e(D,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>a(new Set(t.rows.map(e=>e.id))),children:[t.label,` (`,String(t.rows.length),`)`]},t.label)),i.length>0&&e(`div`,{className:`ml-auto flex flex-wrap items-center gap-2`,children:[n(`span`,{className:`text-[11px] tabular-nums text-foreground`,"aria-live":`polite`,children:o(`access.credentialTable.selectedLabel`,{what:Q(i.length,l)})}),e(D,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>a(new Set),children:[n(v,{className:`h-3 w-3`,"aria-hidden":!0}),o(`access.credentialTable.clearSelection`,`Clear selection`)]}),e(D,{type:`button`,variant:`danger`,size:`sm`,disabled:c.busy,onClick:()=>void d(),children:[c.busy?n(s,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):n(g,{className:`h-3 w-3`,"aria-hidden":!0}),o(`access.credentialTable.revoke`,{what:Q(i.length,l)})]})]})]})}var Re=(e,t)=>t===null?`—`:e.get(t)??t;function ze(e,t){return e!=null&&e<=t?`expired`:`active`}function Be(e,t,n){return{id:e.id,name:n.client(e.client),detail:e.ip,ownerId:e.userId,ownerName:Re(t,e.userId),kind:n.method(e.method),scope:null,status:e.current?`current`:`active`,createdAt:e.createdAt,lastUsedAt:e.lastUsedAt,expiresAt:e.expiresAt}}function Ve(e,t){return{id:e.id,name:e.integrationId,detail:null,ownerId:e.userId,ownerName:e.username,kind:e.integrationId,scope:t,status:e.revokedAt===null?`active`:`revoked`,createdAt:e.createdAt,lastUsedAt:e.lastUsedAt,expiresAt:null}}var He=`All permissions`,Ue=`View link`,We=`Scoped`,Ge={"grid-view":`Grid`,"events-view":`Events`};function Ke(e,t){return e.map(e=>t.get(e)??`#${String(e)}`).join(`, `)}function qe(e){return e!==`*`&&e.type===`share-view`&&`grant`in e}function Je(e,t,n){return e===`*`?He:qe(e)?`${`${Ge[e.grant.kind]} view${e.grant.talk===!0?` + talk`:``}`}: ${Ke(e.grant.deviceIds,t)}`:n(e)}function Ye(e){return e.includes(`*`)?He:e.some(qe)?Ue:We}function Xe(e,t,n,r){return{id:e.id,name:e.label,detail:null,ownerId:e.subjectId,ownerName:Re(t,e.subjectId),kind:Ye(e.scopes),scope:n,status:e.revokedAt===null?ze(e.expiresAt,r):`revoked`,createdAt:e.createdAt,lastUsedAt:e.lastUsedAt,expiresAt:e.expiresAt}}function Ze(e){return`${e.provider}\u0000${e.subject}`}function Qe(e,t){return{id:Ze(e),name:e.label??e.subject,detail:e.issuer,ownerId:e.userId,ownerName:Re(t,e.userId),kind:e.provider,scope:null,status:`active`,createdAt:e.linkedAt,lastUsedAt:null,expiresAt:null}}var $e=40,et=[{test:/Electron\//,name:`CamStack desktop`},{test:/Edg(e|A|iOS)?\//,name:`Edge`},{test:/OPR\/|Opera/,name:`Opera`},{test:/Firefox\/|FxiOS\//,name:`Firefox`},{test:/Chrome\/|CriOS\//,name:`Chrome`},{test:/Version\/[\d.]+.*Safari\//,name:`Safari`}],tt=[{test:/iPhone/,name:`iPhone`},{test:/iPad/,name:`iPad`},{test:/Android/,name:`Android`},{test:/Mac OS X|Macintosh/,name:`macOS`},{test:/Windows/,name:`Windows`},{test:/CrOS/,name:`ChromeOS`},{test:/Linux/,name:`Linux`}],nt=[{test:/CFNetwork\/.*Darwin\//,name:`CamStack app on iOS`},{test:/^okhttp\//i,name:`CamStack app on Android`},{test:/^(node|undici)\b/i,name:`Script (Node.js)`},{test:/^curl\//i,name:`curl`}];function rt(e,t){return e.find(e=>e.test.test(t))?.name??null}function it(e){return e.length<=$e?e:`${e.slice(0,$e)}…`}function at(e){if(e===null||e.trim().length===0)return{label:q.t(`helpers.sessionClient.unknownDevice`),raw:null};let t=e.trim(),n=rt(nt,t);if(n!==null)return{label:n,raw:t};let r=rt(et,t),i=rt(tt,t);return r!==null&&i!==null?{label:q.t(`helpers.sessionClient.browserOnSystem`,{browser:r,system:i}),raw:t}:r===null?{label:it(t),raw:t}:{label:r,raw:t}}var ot={password:`helpers.sessionClient.method.password`,passkey:`helpers.sessionClient.method.passkey`,sso:`helpers.sessionClient.method.sso`,handoff:`helpers.sessionClient.method.handoff`,"cli-approval":`helpers.sessionClient.method.cliApproval`,exchange:`helpers.sessionClient.method.exchange`};function st(e){let t=ot[e];return t===void 0?e:q.t(t)}function ct(e){if(e==null)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function lt({token:t,label:r,onClose:i}){let{t:a}=J();return n(oe,{open:!0,onOpenChange:e=>!e&&i(),children:e(H,{width:`md`,scroll:`body`,children:[n(N,{children:n(E,{children:a(`auth.tokenModals.token`,`Token: {{label}}`,{label:r})})}),e(w,{className:`space-y-3`,children:[n(`div`,{className:`rounded-md border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:a(`auth.tokenModals.copyThisTokenNowOnce`,`Copy this token now. Once you close this dialog the secret cannot be displayed again.`)}),n(`div`,{className:`select-all break-all rounded-md border border-border bg-background p-2 font-mono text-[11px] text-foreground`,children:t})]}),e(A,{children:[n(F,{value:t,label:a(`common.copy`,`Copy`),srLabel:`token`}),n(D,{type:`button`,variant:`primary`,size:`sm`,onClick:i,children:a(`auth.tokenModals.done`,`Done`)})]})]})})}var ut={token:`newToken`,scoped:`newScoped`,admin:`newAdmin`};a();var dt=80,$=86400,ft=[{value:`1`,seconds:$},{value:`7`,seconds:7*$},{value:`30`,seconds:30*$},{value:`90`,seconds:90*$},{value:`never`,seconds:`never`}],pt=[y.Camera],mt=64,ht={type:`capability`,target:``,access:[`view`,`create`]};function gt({open:a,users:o,onClose:c,onSubmit:f,submitting:m,formError:g,awaitingProof:_}){let{t:v}=J(),y=p(),{user:b}=ue(),x=b?.isAdmin===!0,C=x?null:b?.scopes??[],[w,T]=i(`scopes`),[E,k]=i(b?.id??``),[A,j]=i(``),[M,N]=i([ht]),[F,R]=i([]),[z,ae]=i(`grid-view`),[B,V]=i(!1),[H,U]=i(`30`);r(()=>{a||(T(`scopes`),k(b?.id??``),j(``),N([ht]),R([]),ae(`grid-view`),V(!1),U(`30`))},[a,b?.id]),r(()=>{w!==`view-link`&&H===`never`&&U(`30`)},[w,H]);let oe=t(()=>ft.filter(e=>e.seconds!==`never`||w===`view-link`).map(e=>({value:e.value,label:e.seconds===`never`?v(`access.createTokenModal.never`,`Never (until revoked)`):v(`access.createTokenModal.days`,{count:Number(e.value)})})),[w,v]),W=A.trim(),G=w===`scopes`?ie(M,y):null,le=[...F],q=ft.find(e=>e.value===H)?.seconds??30*$,de=()=>w===`all`?[`*`]:w===`view-link`?[{type:`share-view`,grant:{kind:z,deviceIds:le,...B?{talk:!0}:{}}}]:M,Y=W.length>0&&W.length<=dt&&!m&&!_&&(w===`all`?x:w===`view-link`?le.length>0:M.length>0&&G===null),pe=()=>{if(!Y)return;let e=x&&w!==`all`&&E!==``&&E!==b?.id;f({scopes:de(),expiresIn:q,label:W,...e?{subjectId:E}:{}})},X=w===`all`,me=X?u:l;return n(ce,{open:a,onClose:c,title:v(`access.createTokenModal.createToken`,`Create token`),icon:X?u:S,error:g,width:`md`,testId:`create-token-dialog`,footer:e(D,{type:`button`,variant:X?`danger`:`primary`,size:`sm`,onClick:pe,disabled:!Y,"data-testid":`create-token-submit`,children:[m||_?n(s,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}):n(me,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),v(`access.createTokenModal.issueToken`,`Issue token`)]}),children:e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`space-y-1`,children:[n(K,{children:v(`access.createTokenModal.whatItMayDo`,`What it may do`)}),n(O,{appearance:`pills`,value:w,onValueChange:e=>{(e===`scopes`||e===`view-link`||e===`all`)&&T(e)},children:e(ne,{"aria-label":v(`access.createTokenModal.whatItMayDo`,`What it may do`),children:[e(L,{value:`scopes`,"data-testid":`token-reach-scopes`,children:[n(l,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),v(`access.createTokenModal.reachScopes`,`Scopes`)]}),e(L,{value:`view-link`,"data-testid":`token-reach-view-link`,children:[n(ee,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),v(`access.createTokenModal.reachViewLink`,`View link`)]}),x?e(L,{value:`all`,"data-testid":`token-reach-all`,children:[n(u,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),v(`access.createTokenModal.reachAll`,`All permissions`)]}):null]})})]}),X?n(`div`,{className:`space-y-1 rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px] leading-relaxed text-foreground`,"data-testid":`admin-token-warning`,children:n(`p`,{children:n(fe,{i18nKey:`auth.adminTokenNoticeShort`,components:{strong:n(`strong`,{})}})})}):null,x&&w!==`all`&&o.length>1?e(`div`,{className:`space-y-1`,children:[n(K,{htmlFor:`token-user`,children:v(`access.createTokenModal.onBehalfOfUser`,`On behalf of user`)}),n(h,{id:`token-user`,value:E,onChange:e=>k(e.target.value),options:o.map(e=>({value:e.id,label:e.username}))})]}):null,e(`div`,{className:`space-y-1`,children:[n(K,{htmlFor:`token-name`,children:v(`access.createTokenModal.label`,`Label`)}),n(te,{id:`token-name`,value:A,maxLength:dt,required:!0,onChange:e=>j(e.target.value),placeholder:w===`view-link`?`kitchen-wall`:`nightly-backup`,autoFocus:!0})]}),w===`scopes`?e(`div`,{className:`space-y-1`,children:[n(K,{children:v(`access.createTokenModal.scopes`,`Scopes`)}),n(I,{value:M,onChange:N,clampToParent:C}),G&&n(`p`,{className:`text-[10px] text-danger`,children:G}),n(`p`,{className:`text-[10px] text-foreground-subtle`,children:v(`access.createTokenModal.eachScopePicksACap`,`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`)})]}):null,w===`view-link`?e(`div`,{className:`space-y-2`,"data-testid":`token-view-link`,children:[e(`div`,{className:`space-y-1`,children:[n(K,{htmlFor:`token-view-cameras`,children:v(`access.createTokenModal.cameras`,`Cameras`)}),n(se,{id:`token-view-cameras`,multiple:!0,pick:`device`,noun:`camera`,fixedTypes:pt,maxItems:mt,recentKey:`token-view-cameras`,testId:`token-view-cameras`,value:P(F),onChange:e=>R(re(e))})]}),e(`div`,{className:`space-y-1`,children:[n(K,{htmlFor:`token-view-kind`,children:v(`access.createTokenModal.viewKind`,`Shows`)}),n(h,{id:`token-view-kind`,value:z,onChange:e=>ae(e.target.value===`events-view`?`events-view`:`grid-view`),options:[{value:`grid-view`,label:v(`access.createTokenModal.viewGrid`,`Live grid`)},{value:`events-view`,label:v(`access.createTokenModal.viewEvents`,`Events`)}]})]}),z===`grid-view`?e(`label`,{className:`flex items-start gap-2 text-sm text-foreground`,children:[n(d,{className:`mt-0.5`,checked:B,onChange:e=>V(e.target.checked),"data-testid":`token-view-talk`}),n(`span`,{children:v(`access.createTokenModal.talk`,`Allow talk-back on these cameras`)})]}):null]}):null,e(`div`,{className:`space-y-1`,children:[n(K,{htmlFor:`token-lifetime`,children:v(`access.createTokenModal.expires`,`Expires after`)}),n(h,{id:`token-lifetime`,value:H,onChange:e=>U(e.target.value),options:oe})]})]})})}a();var _t={key:`access.nouns.token`};function vt(e){return typeof e==`object`&&!!e&&`kind`in e}function yt(e,t){let n=e.access===void 0?``:` [${e.access.join(`, `)}]`;return e.type===`device`?`device:[${vt(e.selector)?V(e.selector,t):`?`}]${n}`:e.type===`addon-routes`?`${t(`access.tokensSection.everyAddonRoutes`,`every addon's routes`)}${n}`:`${e.type}:${e.target??``}${n}`}function bt({headerOwnsCreate:a=!1,createRequested:o=!1,onCreateConsumed:s,ownOnly:c=!1}){let{t:l}=J(),u=p(),{user:d}=ue(),f=m(),h=W.useUtils(),ee=me(),{data:_}=k(),v=t(()=>_??[],[_]),{data:y}=j({}),b=t(()=>{let e=new Map;for(let t of y??[])e.set(t.id,t.name);return e},[y]),x=W.auth.listTokens.useQuery(void 0),{requestProof:C,dialog:te}=de(`Creating a token with all permissions`),{state:w,openNew:T,close:E}=ae({newKey:ut.token}),[ne,O]=i(null),[re,A]=i(null),[M,N]=i(!1),[P,F]=i(null),[ie,I]=i(null);r(()=>{o&&(T(),s?.())},[o,T,s]);let L=()=>{h.auth.listTokens.invalidate(),h.auth.listAuthAudit.invalidate()},R=W.auth.mintToken.useMutation({onSuccess:({token:e,record:t})=>{L(),E(),A(null),N(!1),F({token:e,label:t.label})},onError:e=>{A(`Create failed: ${e.message}`),N(!1)}}),z=W.auth.revokeToken.useMutation({onSuccess:()=>{I(null),L()},onError:e=>{I(null),O(`Revoke failed: ${e.message}`)}}),B=Ae(_t,L),V=Date.now(),H=(x.data??[]).filter(e=>!c||e.subjectId===d?.id).map(e=>Xe(e,ee,e.scopes.includes(`*`)?null:e.scopes.map(e=>Je(e,b,e=>yt(e,u))).join(`, `),V)),U=async e=>{await f({title:l(`access.tokensSection.revoke`,`Revoke "{{name}}"?`,{name:e.name}),message:e.kind===`All permissions`?l(`access.tokensSection.everyScriptUsingItLoses`,`Every script using it loses access immediately. This cannot be undone.`):l(`access.tokensSection.stopsWorking`,`Whoever holds it loses access immediately. This cannot be undone.`),confirmLabel:l(`access.tokensSection.revoke2`,`Revoke`),variant:`danger`})&&(O(null),I(e.id),z.mutate({id:e.id}))},oe=e=>{(async()=>{O(null),A(null);let t;if(e.scopes.includes(`*`)){N(!0);let e=await C();if(N(!1),e===null)return;t=e}R.mutate({scopes:[...e.scopes],expiresIn:e.expiresIn,label:e.label,...e.subjectId===void 0?{}:{subjectId:e.subjectId},...t===void 0?{}:{reauthToken:t}})})()};return e(`div`,{"data-testid":`tokens`,children:[te,n(Y,{notice:he(ne,B.outcome),onDismissNotice:()=>{O(null),B.dismiss()},id:c?`my-tokens`:`tokens`,title:c?l(`access.tokensSection.myTokens`,`My tokens`):l(`access.tokensSection.tokens`,`Tokens`),icon:S,actions:a?void 0:e(D,{size:`sm`,type:`button`,"data-testid":`tokens-new`,onClick:T,children:[n(S,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),l(`system.access.newToken`,`New token`)]}),description:l(`access.tokensSection.oneFormat`,`Every token is its scopes: a few permissions for a script, all permissions for an admin script, or a view of some cameras for a share link. Revoking one stops it on its next use.`),children:n(Ie,{rows:H,label:l(`common.tokensLabel`),isLoading:x.isLoading,loadError:x.isError?x.error?.message??`Request failed`:null,emptyText:l(`access.tokensSection.noTokens`,`No tokens.`),action:{label:l(`access.tokensSection.revoke2`,`Revoke`),icon:g,isAvailable:e=>e.status===`active`,onRun:e=>void U(e),busyId:ie,disabled:B.busy||ie!==null},...d?.isAdmin===!0?{bulk:{revoke:B,noun:_t,isSelectable:e=>e.status===`active`}}:{}})}),n(gt,{open:w.mode===`new`,users:v.map(e=>({id:e.id,username:e.username})),onClose:()=>{E(),A(null),N(!1)},submitting:R.isPending,formError:re,awaitingProof:M,onSubmit:oe}),P&&n(lt,{token:P.token,label:P.label,onClose:()=>F(null)})]})}var xt=864e5,St={qr:`QR (by an admin)`,self:`Self-enrolled`},Ct={ios:`iOS`,android:`Android`,web:`Web`,other:`Other`};function wt(e){return e.status===`revoked`}function Tt(e){return e.status!==`revoked`}function Et(e,t=`—`){if(e===null)return t;let n=new Date(e);return Number.isNaN(n.getTime())?t:n.toLocaleString()}function Dt(e,t){return e===null||Number.isNaN(e)?null:Math.floor((e-t)/xt)}function Ot(e,t){let n=Dt(e,t);return n===null?`unknown`:n<0?`expired`:n<30?`soon`:`ok`}function kt(e,t){let n=Dt(e,t);return n===null?q.t(`helpers.certificateModel.unknown`):n===0?q.t(`helpers.certificateModel.today`):n>0?q.t(`helpers.certificateModel.inDays`,{count:n}):q.t(`helpers.certificateModel.daysAgo`,{count:-n})}function At(e){if(e===null)return null;let t=Date.parse(e);return Number.isNaN(t)?null:t}function jt(e){return e===null||e.length===0?`—`:e.length<=17?e:`${e.slice(0,8)}…${e.slice(-8)}`}function Mt(e){return e.length<=10?e:`${e.slice(0,10)}…`}function Nt(e){if(!e.online)return{allowed:!1,reason:q.t(`helpers.certificateModel.nodeOffline`)};if(e.isHub&&e.https.kind===`served`){if(e.https.status.mode===`uploaded`)return{allowed:!1,reason:q.t(`helpers.certificateModel.uploadedCert`)};if(e.https.status.mode===`disabled`)return{allowed:!1,reason:q.t(`helpers.certificateModel.tlsDisabled`)}}return{allowed:!0,reason:null}}var Pt={prepare:`helpers.certificateModel.stage.prepare`,issue:`helpers.certificateModel.stage.issue`,install:`helpers.certificateModel.stage.install`,reconnect:`helpers.certificateModel.stage.reconnect`,confirm:`helpers.certificateModel.stage.confirm`};function Ft(e){if(e.ok)return{tone:`success`,message:q.t(`helpers.certificateModel.renewed`,{nodeId:e.nodeId,serial:Mt(e.newSerial)})};let t=e.keptPreviousLeaf?q.t(`helpers.certificateModel.keptPrevious`):q.t(`helpers.certificateModel.maybeNoCert`);return{tone:`danger`,message:q.t(`helpers.certificateModel.renewalFailed`,{nodeId:e.nodeId,stage:q.t(Pt[e.stage]),reason:e.reason,kept:t})}}function It(e,t){let n=Math.max(0,e-t),r=Math.ceil(n/1e3),i=Math.floor(r/60),a=r%60;return{expired:n===0,label:`${String(i)}:${String(a).padStart(2,`0`)}`}}var Lt=11;function Rt(e,t){let n=e.slice(0,Lt);return t===null?n:`${n} · ${t}`}function zt(e){return{id:e.id,name:e.deviceName,detail:Rt(e.fingerprint,e.lastUsedFrom),ownerId:e.userId,ownerName:e.username??e.userId,kind:Ct[e.platform],scope:St[e.enrolledVia],status:e.status,createdAt:e.issuedAt,lastUsedAt:e.lastUsedAt,expiresAt:e.expiresAt}}function Bt(e,t){return{id:e.id,name:e.deviceName,detail:null,ownerId:null,ownerName:t,kind:Ct[e.platform],scope:null,status:e.status,createdAt:e.issuedAt,lastUsedAt:e.lastUsedAt,expiresAt:e.expiresAt}}function Vt({sessions:t,isLoading:r,loadError:i,emptyText:a,onRevoke:o,revokingId:c}){let{t:l}=J();return r?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[n(s,{className:`h-3.5 w-3.5 animate-spin`}),l(`auth.sessionsList.loadingSessions`,`Loading sessions…`)]}):i===null?t.length===0?n(`div`,{className:`rounded border border-dashed border-border px-3 py-4 text-xs text-foreground-subtle text-center`,children:a}):n(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:t.map(e=>n(Ht,{session:e,revoking:c===e.id,onRevoke:()=>o(e)},e.id))}):e(`div`,{className:`text-[11px] text-danger`,children:[l(`auth.sessionsList.couldNotLoadSessions`,`Could not load sessions:`),` `,i]})}function Ht({session:t,revoking:r,onRevoke:i}){let{t:a}=J(),o=at(t.client);return e(`li`,{"data-testid":`session-row`,className:`flex items-start gap-3 px-3 py-2 text-xs`,children:[n(b,{className:`h-3.5 w-3.5 mt-0.5 shrink-0 text-foreground-subtle`}),e(`div`,{className:`flex-1 min-w-0 space-y-0.5`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[n(`span`,{className:`font-medium text-foreground truncate`,title:o.raw??void 0,children:o.label}),t.current&&n(`span`,{className:`rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`,children:a(`auth.sessionsList.thisDevice`,`This device`)})]}),e(`div`,{className:`flex flex-wrap gap-x-3 text-[11px] text-foreground-subtle`,children:[n(`span`,{children:st(t.method)}),n(`span`,{className:`font-mono`,children:t.ip??a(`auth.sessionsList.ipUnknown`,`IP unknown`)}),n(`span`,{children:a(`auth.sessionsList.lastActive`,{when:ct(t.lastUsedAt)})}),n(`span`,{children:a(`auth.sessionsList.expires`,{when:ct(t.expiresAt)})})]})]}),!t.current&&e(D,{variant:`unstyled`,onClick:i,disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[r?n(s,{className:`h-3 w-3 animate-spin`}):n(C,{className:`h-3 w-3`}),a(`auth.sessionsList.signOut`,`Sign out`)]})]})}export{Be as C,Y as D,je as E,he as O,Ve as S,Ae as T,at as _,Tt as a,Ze as b,kt as c,Et as d,Nt as f,ut as g,bt as h,wt as i,me as k,Ft as l,Mt as m,zt as n,It as o,jt as p,Bt as r,At as s,Vt as t,Ot as u,st as v,Ie as w,Qe as x,ct as y};