@camstack/addon-admin-ui 1.2.690 → 1.2.691

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 (123) hide show
  1. package/CHANGELOG.md +18 -2
  2. package/dist/assets/AccessSection-D8SFhAIG.js +1 -0
  3. package/dist/assets/Addons-4zb8WqsP.js +5 -0
  4. package/dist/assets/{AdminPage-z8USGyNk.js → AdminPage-Dr8PsIuX.js} +1 -1
  5. package/dist/assets/{AdminSectionedPage-CtcZ5jHa.js → AdminSectionedPage-C3NbPIMK.js} +1 -1
  6. package/dist/assets/AiProfiles-09uEdzUc.js +3 -0
  7. package/dist/assets/Archive-DDg3Te3v.js +1 -0
  8. package/dist/assets/BootstrapSettingsForm-EahE9xrT.js +1 -0
  9. package/dist/assets/Build-Dysn_dsI.js +40 -0
  10. package/dist/assets/{Calendars-DeXYk6f7.js → Calendars-DqxqjWNj.js} +1 -1
  11. package/dist/assets/{CameraGrids-A_aGLmzE.js → CameraGrids-BaVLUgNc.js} +1 -1
  12. package/dist/assets/Cluster-DCb9pTRO.js +1 -0
  13. package/dist/assets/CompositionBlockEditor-Bo7NCArN.js +2 -0
  14. package/dist/assets/{CompositionEditorPage-BvetDCib.js → CompositionEditorPage-D9gqtKg_.js} +1 -1
  15. package/dist/assets/Data-CCfGw4D3.js +2 -0
  16. package/dist/assets/{DeviceDetail-DPxmWhcP.js → DeviceDetail-DGaYflb1.js} +1 -1
  17. package/dist/assets/{Devices-3Lm2uV9o.js → Devices-PRxhQLdr.js} +1 -1
  18. package/dist/assets/{EmbedDevicePage-BgNfY1Ap.js → EmbedDevicePage-cBOLQorO.js} +1 -1
  19. package/dist/assets/{EmbedPlayerPage-BFXQpQxb.js → EmbedPlayerPage-DSZTQL2b.js} +1 -1
  20. package/dist/assets/History-BzHUR50W.js +1 -0
  21. package/dist/assets/Identity-BH_Psx-M.js +1 -0
  22. package/dist/assets/InstancesTable-BkkLy_BU.js +1 -0
  23. package/dist/assets/IntegrationDetail-Dh1zEIkB.js +1 -0
  24. package/dist/assets/{Integrations-CldsYVl0.js → Integrations-DziYFJDe.js} +2 -2
  25. package/dist/assets/{Integrations-CprYyiDb.js → Integrations-I8w-NmB5.js} +1 -1
  26. package/dist/assets/Library-CrU752kO.js +1 -0
  27. package/dist/assets/Locations-Cz9dHdgC.js +3 -0
  28. package/dist/assets/{Logs-DSr8wCY-.js → Logs-D76tMs8T.js} +1 -1
  29. package/dist/assets/{MaskShapeCanvas-_BFcQxc-.js → MaskShapeCanvas-DhkgwuqU.js} +1 -1
  30. package/dist/assets/{MotionZonesSettings-DJDcu3fl.js → MotionZonesSettings-ePEXl_eY.js} +1 -1
  31. package/dist/assets/MyAccess-DrN6K8e1.js +2 -0
  32. package/dist/assets/{Network-Csm4YFXB.js → Network-CcBl6Bv3.js} +1 -1
  33. package/dist/assets/NewExportModal-DcAnxwF1.js +1 -0
  34. package/dist/assets/NodeAddonsSettingsPanel-BUnGcCpc.js +1 -0
  35. package/dist/assets/Notifications-DC_4_Px5.js +1 -0
  36. package/dist/assets/{PanelContent-DJ8p-hQ1.js → PanelContent-BD4VlG0k.js} +2 -2
  37. package/dist/assets/Pipeline-C9c451F4.js +1 -0
  38. package/dist/assets/{PrivacyMaskSettings-Dx5nRU-t.js → PrivacyMaskSettings-BKbsxTCz.js} +1 -1
  39. package/dist/assets/{SceneMonitorEditor-DFZ94G-a.js → SceneMonitorEditor-BsG_DspV.js} +1 -1
  40. package/dist/assets/SessionsList-CXVcORvl.js +2 -0
  41. package/dist/assets/{Showroom-DO1bQcNO.js → Showroom-syizHLdc.js} +1 -1
  42. package/dist/assets/{StorageLocationsTable-BymZx5tG.js → StorageLocationsTable-DX9GAr79.js} +1 -1
  43. package/dist/assets/System-D_y9BjT7.js +1 -0
  44. package/dist/assets/TemplateEditorDialog-Dg33OIxl.js +1 -0
  45. package/dist/assets/{TerminalPanel-BeJx-I2E.js → Terminal-DNCcPfaX.js} +5 -3
  46. package/dist/assets/{TrainingProviders-CPV9_SJC.js → TrainingProviders-Kir4QyJ0.js} +1 -1
  47. package/dist/assets/{Viewer-BN42pCqQ.js → Viewer-CxhObjjY.js} +1 -1
  48. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DQNUYumg.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DrIBdeiK.js} +1 -1
  49. package/dist/assets/{action-draft-BBdPH6FV.js → action-draft-BaaZLiaa.js} +1 -1
  50. package/dist/assets/{ai-page.helpers-ChgVcsV9.js → ai-page.helpers-ByoISKAg.js} +1 -1
  51. package/dist/assets/{assignment-candidates-Bs3KAjz2.js → assignment-candidates-CfAyipS2.js} +1 -1
  52. package/dist/assets/{authed-media-BK50tJc4.js → authed-media-DHr41d8D.js} +1 -1
  53. package/dist/assets/{board-model-CWzkqJEj.js → board-model-COHOZu1s.js} +1 -1
  54. package/dist/assets/client-dUCYJcne.js +1120 -0
  55. package/dist/assets/{command-vocab-B3pUOKtp.js → command-vocab-CopJIH2j.js} +1 -1
  56. package/dist/assets/{device-detail-B0RHrAPi.js → device-detail-Bg2Ezyca.js} +1 -1
  57. package/dist/assets/{device-integration-icon-JcMIVFtX.js → device-integration-icon-C0zbgR36.js} +1 -1
  58. package/dist/assets/device-picker-model-QTALOVj9.js +1 -0
  59. package/dist/assets/{dist-BNuE6NKf.js → dist-BqygMNK3.js} +1 -1
  60. package/dist/assets/{dist-CyFeeFb8.js → dist-DcdbWcG-.js} +15 -15
  61. package/dist/assets/{format-iFFzavy7.js → format-DVtQDLvq.js} +1 -1
  62. package/dist/assets/{hostInit-CzaZPFle.js → hostInit-BTfD9BWB.js} +1 -1
  63. package/dist/assets/i18n-CtEN5OSf.js +1 -0
  64. package/dist/assets/icons-J91dUPcu.js +1 -0
  65. package/dist/assets/index-BuwKkAl-.js +6 -0
  66. package/dist/assets/index-pEaRJHY2.css +2 -0
  67. package/dist/assets/{linked-devices-model-CuXMtCW5.js → linked-devices-model-CmiXN3Md.js} +1 -1
  68. package/dist/assets/{mf-entry-bootstrap-0-02bb2c8e.js → mf-entry-bootstrap-0-8b23b2f2.js} +2 -2
  69. package/dist/assets/mount-QTALOVj9.js +1 -0
  70. package/dist/assets/{notification-rule-status-zg20pl7f.js → notification-rule-status-C6gd_uCT.js} +1 -1
  71. package/dist/assets/{player-overlays-BF9w4QU-.js → player-overlays-CMIUmcCR.js} +1 -1
  72. package/dist/assets/remoteEntry-CYYrFOe1.js +1 -0
  73. package/dist/assets/{circle-play-BxUrE_Qy.js → scissors-DpiKUioV.js} +1 -1
  74. package/dist/assets/settings-section-shape-DbQZZpNL.js +1 -0
  75. package/dist/assets/src-CZCLpkMn.js +279 -0
  76. package/dist/assets/{sso-popup-CdVjmZ9n.js → sso-popup-CH6-S_OR.js} +1 -1
  77. package/dist/assets/{step-inspector-model-CxSQZZiN.js → step-inspector-model-BG1lVQcU.js} +1 -1
  78. package/dist/assets/{use-scenes-feed-BW5wMevx.js → use-scenes-feed-CWLyPlSj.js} +1 -1
  79. package/dist/assets/{useAdminDeviceRemoval-kU8epr6n.js → useAdminDeviceRemoval-CK2_Fytr.js} +1 -1
  80. package/dist/assets/useEventInvalidation-QTALOVj9.js +1 -0
  81. package/dist/assets/{useNodeUrlSelection-CfN-OrGq.js → useNodeUrlSelection-piTRveNK.js} +1 -1
  82. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-D3AQM66O.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-ePjBjURL.js} +2 -2
  83. package/dist/index.html +9 -9
  84. package/dist/server/addon.js +81 -8
  85. package/package.json +2 -2
  86. package/dist/assets/Addons-Ckr6vlsW.js +0 -5
  87. package/dist/assets/AiProfiles-DZj0TWuh.js +0 -3
  88. package/dist/assets/Archive-B0FJwta9.js +0 -1
  89. package/dist/assets/ArchiveCamera-DdovP4ro.js +0 -1
  90. package/dist/assets/BootstrapSettingsForm-CKBDm4C-.js +0 -1
  91. package/dist/assets/Build-B3CB1er7.js +0 -40
  92. package/dist/assets/Cluster-D2auKPXI.js +0 -1
  93. package/dist/assets/CompositionBlockEditor-DtVxeX5F.js +0 -2
  94. package/dist/assets/Data-oQJyojZK.js +0 -2
  95. package/dist/assets/History-jl2iyeKb.js +0 -1
  96. package/dist/assets/Identity-BpPWgRxJ.js +0 -1
  97. package/dist/assets/InstancesTable-DIKWKA5W.js +0 -1
  98. package/dist/assets/IntegrationDetail-ClVirS0M.js +0 -1
  99. package/dist/assets/Library-B86tjZ0-.js +0 -1
  100. package/dist/assets/Locations-CpNbotTl.js +0 -3
  101. package/dist/assets/MyAccess-DqKyBAxI.js +0 -2
  102. package/dist/assets/NodeAddonsSettingsPanel-FjpwQjGM.js +0 -2
  103. package/dist/assets/Notifications-B-JLj82A.js +0 -1
  104. package/dist/assets/Pipeline-DIXgco7S.js +0 -1
  105. package/dist/assets/ServerShell-BYRylYTw.js +0 -1
  106. package/dist/assets/SessionsList-BcO2x9OZ.js +0 -2
  107. package/dist/assets/System-dsyXpTx9.js +0 -1
  108. package/dist/assets/TemplateEditorDialog-DJIaNKn3.js +0 -1
  109. package/dist/assets/Terminal-BiXbwaPr.js +0 -3
  110. package/dist/assets/client-DhfZUoXe.js +0 -1120
  111. package/dist/assets/device-picker-model-B2oUIKRS.js +0 -1
  112. package/dist/assets/i18n-DCYaeyv_.js +0 -1
  113. package/dist/assets/icons-CXirq6Hu.js +0 -1
  114. package/dist/assets/index-CpurjMmX.css +0 -2
  115. package/dist/assets/index-DPyWa2vo.js +0 -6
  116. package/dist/assets/mount-B2oUIKRS.js +0 -1
  117. package/dist/assets/remoteEntry-ZZWQQQTl.js +0 -1
  118. package/dist/assets/scissors-Bbq6WhOK.js +0 -1
  119. package/dist/assets/src-D9hgltMI.js +0 -279
  120. package/dist/assets/use-archive-data-D7nUbRKv.js +0 -1
  121. package/dist/assets/use-paged-list-DTJY2xpg.js +0 -1
  122. package/dist/assets/useEventInvalidation-B2oUIKRS.js +0 -1
  123. /package/dist/assets/{TerminalPanel-kHJ-D0s7.css → Terminal-kHJ-D0s7.css} +0 -0
@@ -1,2 +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,o as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Bi as l,Bn as u,D as d,Ei as f,Fr as p,Gr as m,Ia as h,Ja as g,Ka as _,Ki as v,Lr as y,Nn as b,Pr as x,Q as S,Ra as C,Ri as w,Rn as ee,Zt as T,ar as E,ct as D,er as O,ft as k,hi as A,ir as j,ja as te,ki as M,na as ne,ot as N,qn as P,ta as F,tn as I,ua as re,ur as ie,ut as ae,xi as oe}from"./player-overlays-BF9w4QU-.js";import{Si as se}from"./client-DhfZUoXe.js";import{t as ce}from"./chevron-down-CBb-F8DT.js";import{i as le,u as ue}from"./terminal-Dgb4lrgM.js";import{t as de}from"./circle-slash-Duh934sZ.js";import{n as fe,t as pe}from"./database-zap-DHuELz_w.js";import{t as me}from"./hard-drive-download-C6N6tovA.js";import{$ as he,$f as L,Ao as ge,Bi as R,Cs as _e,Do as ve,Eo as ye,Er as be,Fo as xe,Fr as Se,Hi as z,Io as Ce,Lo as we,Lp as Te,Mo as Ee,Mr as De,No as Oe,Oo as ke,Po as Ae,Pr as B,Ri as V,Ro as je,To as Me,Tr as Ne,Ui as H,Vi as Pe,Wi as U,_a as Fe,al as Ie,cl as Le,co as Re,cp as ze,dl as Be,ea as Ve,ei as He,ep as Ue,il as We,jo as Ge,jp as Ke,ko as qe,ll as Je,ni as Ye,nl as Xe,nt as Ze,ol as Qe,ri as $e,rl as et,rt as tt,sl as nt,sp as W,ti as rt,tl as it,ul as at,ut as G,va as ot,wo as st,wr as ct,ya as K,zi as q,zo as lt}from"./src-D9hgltMI.js";import{t as J}from"./i18n-DCYaeyv_.js";import{t as Y}from"./useTranslation-BJr-n0es.js";import"./mount-B2oUIKRS.js";import{hi as ut,k as dt,pi as ft,w as pt,yi as mt}from"./index-DPyWa2vo.js";import{t as ht}from"./AdminPage-z8USGyNk.js";import{t as X}from"./format-size-DIxKXxtj.js";import{t as gt}from"./StorageLocationsTable-BymZx5tG.js";import{n as _t}from"./InstancesTable-DIKWKA5W.js";import{n as vt}from"./authed-media-BK50tJc4.js";import{t as yt}from"./AdminSectionedPage-CtcZ5jHa.js";function bt(){return r(ht,{embedded:!0,children:r(gt,{})})}o();var xt={settings:{labelKey:`helpers.backupDatabases.settings.label`,descriptionKey:`helpers.backupDatabases.settings.description`,shortKey:`helpers.backupDatabases.settings.short`},events:{labelKey:`helpers.backupDatabases.events.label`,descriptionKey:`helpers.backupDatabases.events.description`,shortKey:`helpers.backupDatabases.events.short`},history:{labelKey:`helpers.backupDatabases.history.label`,descriptionKey:`helpers.backupDatabases.history.description`,shortKey:`helpers.backupDatabases.history.short`}},St=Object.keys(xt),Ct=[`settings`];function wt(){return J.t(`helpers.backupDatabases.notCreated`)}function Tt(e){return J.t(xt[e].labelKey)}function Et(e){return J.t(xt[e].shortKey)}function Dt(e){return J.t(xt[e].descriptionKey)}function Z(e){let t=new Set(e);return St.filter(e=>t.has(e))}function Ot(e){return e!==void 0&&e.length>0?Z(e):Ct}function kt(e){return Z(e)}function At(e,t){return t===void 0||!t.answered?`unknown`:t.databases.includes(e)?`present`:`absent`}function jt(e,t,n){return At(e,t)===`absent`&&!n.has(e)}function Mt(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function Nt(e){return!e.includes(`settings`)}function Pt(e){return{databases:[...kt(e)]}}function Ft(e,t){return e!==void 0&&e.length>0?Z(e):t!==void 0&&t.length>0?Z(t.map(e=>e.databaseId??`settings`)):Ct}function Q({databases:e}){return r(`span`,{className:`text-xs font-medium uppercase tracking-wide text-foreground-muted`,"data-testid":`backup-database-badges`,children:e.map(e=>Et(e)).join(` · `)})}var It=[[`backup`,`listDestinations`]],Lt=[`backup`,`listArchives`];function Rt({destinationId:i,restoreSupported:o,onOpenRestoreWizard:c}){let{t:l}=Y(),u=s(),d=D(),{data:f,isLoading:p,isError:m}=ge({destinationId:i}),h=f??[],g=Me({onSuccess:()=>{u.invalidateQueries({queryKey:[[...Lt]]}),u.invalidateQueries({queryKey:It})}}),_=n(async e=>{await d({title:l(`backup.archiveList.deleteThisArchive`,`Delete this archive?`),message:l(`backup.archiveList.permanentlyDeletesAndFrees`,`Permanently deletes "{{value1}}" and frees {{value2}}.`,{value1:e.label??e.id,value2:X(e.sizeBytes)}),confirmLabel:l(`common.delete`,`Delete`),variant:`danger`})&&g.mutate({destinationId:i,backupId:e.id})},[d,i,g,l]),[v,b]=a(null),S=n(async e=>{b(e.id);try{let t=await vt(zt(i,e.id)),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${e.label??e.id}.tar.gz${e.encryption===void 0?``:`.csbk`}`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)}finally{b(null)}},[i]),C=t(()=>[...h].toSorted((e,t)=>t.createdAt-e.createdAt),[h]);return p?r(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:l(`backup.archiveList.loadingArchives`,`Loading archives…`)}):m?r(`div`,{className:`text-xs text-danger py-2`,children:l(`backup.archiveList.failedToReadManifestFor`,`Failed to read manifest for this destination`)}):C.length===0?r(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:l(`backup.archiveList.noArchivesAtThisDestination`,`No archives at this destination yet.`)}):r(B,{columns:[{key:`when`,header:l(`backup.archiveList.when`,`When`),sortValue:e=>e.createdAt,render:e=>r(`span`,{className:`tabular-nums`,children:Bt(e.createdAt)})},{key:`label`,header:l(`backup.archiveList.label`,`Label`),sortValue:e=>e.label??null,render:t=>e(`span`,{className:`inline-flex items-center gap-1`,children:[t.encryption!==void 0&&r(x,{className:`h-3 w-3 text-success`,"aria-label":l(`backup.archiveList.encryptedRestoreNeedsBackupKey`,`encrypted — restore needs backup key {{keyId}}`,{keyId:t.encryption.keyId})}),t.label??r(`span`,{className:`text-foreground-subtle italic`,children:`—`})]})},{key:`databases`,header:l(`backup.archiveList.databases`,`Databases`),nowrap:!1,notSortableReason:`Database badges`,render:e=>r(Q,{databases:Ot(e.databases)})},{key:`includes`,header:l(`backup.archiveList.files`,`Files`),nowrap:!1,notSortableReason:`Location list`,render:e=>e.locations.length>0?r(`span`,{className:`text-foreground-subtle`,children:e.locations.join(`, `)}):r(`span`,{className:`text-foreground-subtle italic`,children:l(`common.none`)})},{key:`size`,header:l(`backup.archiveList.size`,`Size`),align:`right`,sortValue:e=>e.sizeBytes,render:e=>r(`span`,{className:`tabular-nums`,children:X(e.sizeBytes)})},{key:`actions`,header:``,align:`right`,notSortableReason:`Actions`,render:t=>e(`span`,{className:`flex items-center justify-end gap-1`,children:[e(L,{variant:`ghost`,size:`sm`,onClick:()=>{S(t)},disabled:v===t.id,title:l(`backup.archiveList.downloadArchive`,`Download archive`),children:[v===t.id?r(y,{className:`h-3 w-3 animate-spin`}):r(oe,{className:`h-3 w-3`}),l(`backup.archiveList.download`,`Download`)]}),o&&c&&e(L,{variant:`ghost`,size:`sm`,onClick:()=>c({destinationId:i,archiveId:t.id}),title:l(`backup.archiveList.restoreFromThisArchive`,`Restore from this archive`),children:[r(P,{className:`h-3 w-3`}),l(`backup.archiveList.restore`,`Restore`)]}),r(ze,{variant:`ghost`,size:`sm`,icon:I,"aria-label":l(`backup.archiveList.delete`,`Delete {{value1}}`,{value1:t.label??t.id}),disabled:g.isPending,onClick:()=>{_(t)}})]})}],rows:C,rowKey:e=>e.id,minWidthPx:760,emptyMessage:l(`backup.archiveList.noArchivesAtThisDestination`,`No archives at this destination yet.`)})}function zt(e,t){return S(`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}function Bt(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}o();var Vt=[[`backup`,`listSchedules`]];function Ht({onEdit:i,onOpenRestoreWizard:o}){let{t:s}=Y(),{data:c,isLoading:l,isError:u,error:d,refetch:f}=Ae(),p=c??[],m=Ee().data??[],h=t(()=>{let e=new Map;for(let t of m)e.set(t.id,t);return e},[m]),[g,_]=a(null),v=n(e=>{_(t=>t===e?null:e)},[]),b=t(()=>Ut({destById:h,expandedId:g,onToggleExpand:v,onEdit:i}),[h,g,v,i]);return l?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle animate-pulse`,children:[r(y,{className:`h-3.5 w-3.5 animate-spin`}),s(`backup.backupEntriesTable.loadingBackupEntries`,`Loading backup entries…`)]}):u?r(Fe,{title:s(`backup.backupEntriesTable.failedToLoadBackupEntries`,`Failed to load backup entries`),message:d instanceof Error?d.message:s(`backup.backupEntriesTable.unknownError`,`Unknown error`),onRetry:()=>void f()}):p.length===0?r(Ve,{icon:re,title:s(`backup.backupEntriesTable.noBackupEntriesYet`,`No backup entries yet`),description:s(`backup.backupEntriesTable.createOneToScheduleBackups`,`Create one to schedule backups across one or more storage locations.`)}):r(B,{columns:b,rows:p,rowKey:e=>e.id,minWidthPx:980,maxBodyHeight:Se,emptyMessage:s(`backup.backupEntriesTable.noBackupEntriesYet`,`No backup entries yet`),onRowClick:e=>i(e),isExpanded:e=>e.id===g,renderExpanded:e=>r(Xt,{row:e,destById:h,...o?{onOpenRestoreWizard:o}:{}})})}function Ut(t){return[{key:`expand`,header:``,width:`w-8`,nowrap:!0,notSortableReason:`Expand control`,render:e=>{let n=t.expandedId===e.id;return r(ze,{variant:`ghost`,size:`sm`,icon:n?ce:F,"aria-label":n?J.t(`backup.backupEntriesTable.hideArchives`,`Hide archives`):J.t(`backup.backupEntriesTable.showArchives`,`Show archives`),"aria-expanded":n,onClick:n=>{n.stopPropagation(),t.onToggleExpand(e.id)}})}},{key:`entry`,header:J.t(`backup.backupEntriesTable.entry`,`Entry`),sortValue:e=>e.label,render:t=>e(`span`,{className:`flex min-w-0 flex-col`,children:[r(`span`,{className:`truncate font-medium text-foreground`,children:t.label||J.t(`backup.backupEntriesTable.unnamed`,`(unnamed)`)}),t.lastRunAt!==void 0&&r(`span`,{className:`text-[10px] text-foreground-subtle`,children:J.t(`backup.backupEntriesTable.lastRun`,{when:new Date(t.lastRunAt).toLocaleString()})})]})},{key:`enabled`,header:J.t(`backup.backupEntriesTable.enabled`,`Enabled`),width:`w-20`,nowrap:!0,sortValue:e=>+!!e.enabled,render:e=>r(`span`,{onClick:e=>e.stopPropagation(),children:r(qt,{row:e})})},{key:`databases`,header:J.t(`backup.backupEntriesTable.backsUp`,`Backs up`),nowrap:!1,notSortableReason:`Database badges`,render:e=>r(Q,{databases:Ot(e.databases)})},{key:`locations`,header:J.t(`backup.backupEntriesTable.locations`,`Locations`),nowrap:!1,notSortableReason:`Location chips`,render:e=>r(Wt,{row:e,destById:t.destById})},{key:`retention`,header:J.t(`backup.backupEntriesTable.retention`,`Retention`),width:`w-24`,nowrap:!0,sortValue:e=>e.retentionCount,render:e=>r(`span`,{onClick:e=>e.stopPropagation(),children:r(Jt,{row:e})})},{key:`schedule`,header:J.t(`backup.backupEntriesTable.schedule`,`Schedule`),width:`w-48`,nowrap:!0,sortValue:e=>e.cron,render:e=>r(Gt,{row:e})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:e=>r(`span`,{onClick:e=>e.stopPropagation(),children:r(Yt,{row:e,onEdit:()=>t.onEdit(e)})})}]}function Wt({row:e,destById:t}){let{t:n}=Y();return e.locationIds.length===0?r(`span`,{className:`text-[11px] italic text-danger`,children:n(`backup.backupEntriesTable.noLocations`,`No locations`)}):r(`span`,{className:`flex flex-wrap gap-1`,children:e.locationIds.map(e=>r(`span`,{className:`inline-flex items-center rounded border border-border bg-background px-1.5 py-0.5 text-[10px] text-foreground`,title:e,children:t.get(e)?.displayName??e},e))})}function Gt({row:t}){let{t:n}=Y(),i=t.cron.trim().length>0;return e(`span`,{className:`flex flex-col items-start gap-0.5`,children:[e(`span`,{className:`inline-flex items-center gap-1`,children:[r(re,{className:`h-3 w-3 text-foreground-subtle`}),r(`span`,{className:`font-mono text-[11px] text-foreground`,children:i?t.cron:n(`backup.backupEntriesTable.manual`,`Manual`)})]}),i&&t.nextRunAt!==void 0&&r(`span`,{className:`text-[10px] text-foreground-subtle`,children:J.t(`common.nextRun`,{when:new Date(t.nextRunAt).toLocaleString()})})]})}function Kt(e){return t(()=>({id:e.id,label:e.label,cron:e.cron,locationIds:[...e.locationIds],retentionCount:e.retentionCount,...e.dataSources?{dataSources:[...e.dataSources]}:{},...e.databases?{databases:[...e.databases]}:{}}),[e])}function qt({row:e}){let{t}=Y(),n=s(),i=lt({onSuccess:()=>{n.invalidateQueries({queryKey:Vt})}}),a=Kt(e);return r(`label`,{className:`inline-flex cursor-pointer items-center`,children:r(_,{className:`accent-primary`,checked:e.enabled,disabled:i.isPending,onChange:e=>i.mutate({...a,enabled:e.target.checked}),"aria-label":t(`backup.backupEntriesTable.enable`,`Enable {{value1}}`,{value1:e.label||e.id})})})}function Jt({row:e}){let{t}=Y(),n=s(),o=lt({onSuccess:()=>{n.invalidateQueries({queryKey:Vt})}}),c=Kt(e),[l,u]=a(String(e.retentionCount));return i(()=>{u(String(e.retentionCount))},[e.retentionCount]),r(W,{type:`number`,min:1,max:1e3,value:l,disabled:o.isPending,onChange:e=>u(e.target.value),onBlur:()=>{let t=Number.parseInt(l,10);if(Number.isNaN(t)||t<1){u(String(e.retentionCount));return}t!==e.retentionCount&&o.mutate({...c,enabled:e.enabled,retentionCount:t})},onKeyDown:t=>{t.key===`Enter`&&t.target.blur(),t.key===`Escape`&&u(String(e.retentionCount))},className:`w-16`,"aria-label":t(`backup.backupEntriesTable.retentionFor`,`Retention for {{value1}}`,{value1:e.label||e.id})})}function Yt({row:t,onEdit:n}){let{t:i}=Y(),a=s(),o=D(),c=ye({onSuccess:()=>{a.invalidateQueries({queryKey:Vt})}}),l=je({onMutate:()=>{a.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})},onSuccess:()=>{a.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),a.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),a.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})}}),u=()=>{t.locationIds.length!==0&&l.mutate({destinations:[...t.locationIds],...t.dataSources&&t.dataSources.length>0?{locations:[...t.dataSources]}:{},label:t.label,retentionCount:t.retentionCount,databases:[...Ot(t.databases)]})},d=async()=>{await o({title:i(`backup.backupEntriesTable.deleteBackupEntry`,`Delete backup entry?`),message:i(`backup.backupEntriesTable.willStopRunningExistingArchives`,`"{{value1}}" will stop running. Existing archives are kept.`,{value1:t.label||t.id}),confirmLabel:i(`common.delete`,`Delete`),variant:`warning`})&&c.mutate({id:t.id})};return e(`span`,{className:`flex items-center justify-end gap-1.5`,children:[e(L,{size:`sm`,type:`button`,onClick:u,disabled:l.isPending||t.locationIds.length===0,title:i(`backup.backupEntriesTable.runThisEntryNow`,`Run this entry now`),children:[l.isPending?r(y,{className:`h-3 w-3 animate-spin`}):r(E,{className:`h-3 w-3`}),i(`backup.backupEntriesTable.runNow`,`Run now`)]}),r(ze,{variant:`ghost`,size:`sm`,icon:ie,"aria-label":i(`backup.backupEntriesTable.edit`,`Edit {{value1}}`,{value1:t.label||t.id}),onClick:n}),r(ze,{variant:`ghost`,size:`sm`,icon:I,"aria-label":i(`backup.backupEntriesTable.delete`,`Delete {{value1}}`,{value1:t.label||t.id}),disabled:c.isPending,onClick:()=>{d()}})]})}function Xt({row:t,destById:n,onOpenRestoreWizard:i}){let{t:a}=Y();return e(`div`,{className:`space-y-4 rounded-lg border border-border bg-background/30 px-4 py-3`,children:[r(`p`,{className:`text-[11px] font-medium text-foreground-subtle`,children:a(`backup.backupEntriesTable.archivesFor`,{name:t.label||t.id})}),t.locationIds.length===0&&r(`p`,{className:`text-xs italic text-foreground-subtle`,children:a(`backup.backupEntriesTable.thisEntryHasNoLocations`,`This entry has no locations selected.`)}),t.locationIds.map(t=>e(`div`,{className:`space-y-1.5`,children:[r(`div`,{className:`text-[11px] font-medium text-foreground-subtle`,children:n.get(t)?.displayName??t}),r(Rt,{destinationId:t,restoreSupported:n.get(t)?.restoreSupported??!0,...i?{onOpenRestoreWizard:i}:{}})]},t))]})}function Zt({selected:t,onChange:n,disabled:i=!1,testId:a=`backup-databases`}){let{t:o}=Y(),s=Ge().data,c=t.size>0&&Nt(Z(t)),l=t.size===0?`Pick at least one.`:c?`Snapshots only: configuration and files are not part of this backup.`:null;return r(G,{label:o(`backup.backupDatabasePicker.whatToBackUp`,`What to back up`),required:!0,...l===null?{}:{description:l},children:r(`div`,{className:`divide-y divide-border rounded border border-border bg-background`,"data-testid":a,children:St.map(o=>{let c=At(o,s),l=i||jt(o,s,t);return e(`label`,{className:`flex items-start gap-2 px-3 py-2 text-xs ${l?`opacity-60`:`cursor-pointer hover:bg-primary/5`}`,children:[r(_,{checked:t.has(o),disabled:l,onChange:()=>n(Mt(t,o)),"data-testid":`${a}-${o}`}),e(`span`,{className:`min-w-0 flex-1`,children:[r(`span`,{className:`flex flex-wrap items-center gap-1.5 text-foreground`,children:Tt(o)}),r(`span`,{className:`block text-[11px] text-foreground-subtle`,children:c===`absent`?wt():Dt(o)})]})]},o)})})})}o();function Qt({onClose:t}){let{t:n}=Y(),i=s(),[o,c]=a(new Set(Ct)),l=je({onMutate:()=>{i.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})},onSuccess:()=>{i.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),i.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),i.invalidateQueries({queryKey:[[`backup`,`listRuns`]]}),t()}});return r(V,{open:!0,onOpenChange:e=>!e&&t(),children:e(R,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[e(H,{children:[r(U,{children:n(`backup.backupNowDialog.backUpNow`,`Back up now`)}),r(`p`,{className:`text-xs text-foreground-subtle`,children:n(`backup.backupNowDialog.runsOnceAndWritesThe`,`Runs once and writes the archive to every enabled backup location.`)})]}),r(q,{children:e(`div`,{className:`p-4`,children:[r(Zt,{selected:o,onChange:c,disabled:l.isPending,testId:`backup-now-databases`}),l.error&&r(`p`,{role:`alert`,className:`pt-2 text-xs text-danger`,children:l.error.message})]})}),e(z,{children:[r(L,{variant:`outline`,size:`sm`,onClick:t,children:n(`common.cancel`,`Cancel`)}),e(L,{size:`sm`,onClick:()=>{o.size!==0&&l.mutate(Pt(o))},disabled:o.size===0||l.isPending,"data-testid":`backup-now-run`,children:[l.isPending?r(y,{className:`h-3.5 w-3.5 animate-spin`}):r(E,{className:`h-3.5 w-3.5`}),n(`backup.backupNowDialog.backUpNow`,`Back up now`)]})]})]})})}o();function $t(e){return e===null?`—`:new Date(e).toLocaleString()}function en(e){let t=new Blob([`${e.secretKey}\n`],{type:`text/plain`}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`camstack-backup-key-${e.keyId}.txt`,r.click(),URL.revokeObjectURL(n)}function tn({revealed:t,onDone:n}){let{t:i}=Y(),[o,s]=a(!1),[c,l]=a(!1);return r(V,{open:!0,onOpenChange:e=>!e&&o&&n(),children:e(R,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`border-danger/40`,"aria-labelledby":`backup-key-title`,children:[r(H,{children:r(U,{id:`backup-key-title`,children:i(`backup.encryptionCard.yourKey`,{keyId:t.keyId})})}),e(q,{className:`space-y-3`,children:[e(`p`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 p-2 text-xs text-foreground`,children:[r(T,{className:`mt-0.5 h-4 w-4 shrink-0 text-danger`}),r(`span`,{children:i(`backup.backupEncryptionCard.thisKeyIsShownOnly`,`This key is shown only once. CamStack does not keep it — not the hub, not its database, not its backups. Without it, an encrypted backup cannot be restored by anyone, including you. Store it in a password manager or print it, away from this server.`)})]}),r(`div`,{className:`break-all rounded-md border border-border bg-background p-2 font-mono text-xs text-foreground select-all`,children:t.secretKey}),e(`div`,{className:`flex flex-wrap gap-2`,children:[e(L,{size:`sm`,variant:`outline`,onClick:()=>{navigator.clipboard?.writeText(t.secretKey).then(()=>l(!0))},children:[r(M,{className:`mr-1 h-3.5 w-3.5`}),c?i(`backup.backupEncryptionCard.copied`,`Copied`):i(`common.copy`,`Copy`)]}),e(L,{size:`sm`,variant:`outline`,onClick:()=>en(t),children:[r(oe,{className:`mr-1 h-3.5 w-3.5`}),i(`backup.backupEncryptionCard.downloadAsFile`,`Download as file`)]})]}),e(`label`,{className:`flex items-center gap-2 text-xs text-foreground`,children:[r(_,{checked:o,onChange:e=>s(e.target.checked),className:`accent-primary`}),i(`backup.backupEncryptionCard.iHaveStoredThisKey`,`I have stored this key somewhere safe, off this server.`)]})]}),r(z,{children:r(L,{size:`sm`,disabled:!o,onClick:n,children:i(`backup.backupEncryptionCard.iHaveStoredIt`,`I have stored it`)})})]})})}function nn(){let{t}=Y(),n=ke(),i=we(),o=ve(),s=D(),[l,u]=a(null),[d,f]=a(null),m=n.data?.enabled??!1,h=n.data?.active??null,g=(n.data?.keys??[]).filter(e=>e.retiredAt!==null),_=async()=>{if(await s({title:m?t(`backup.backupEncryptionCard.replaceTheBackupKey`,`Replace the backup key`):t(`backup.backupEncryptionCard.encryptBackups`,`Encrypt backups`),message:m?t(`backup.backupEncryptionCard.aNewKeyIsGenerated`,`A new key is generated and shown once; new backups are encrypted to it. Older backups keep needing the key they were made with — keep that one too.`):t(`backup.backupEncryptionCard.aBackupKeyIsGenerated`,`A backup key is generated and shown once. Every new backup is encrypted to it, and restoring one will ask for it. Existing backups stay as they are.`),confirmLabel:m?t(`backup.backupEncryptionCard.generateANewKey`,`Generate a new key`):t(`backup.backupEncryptionCard.generateTheKey`,`Generate the key`),variant:`warning`})){f(null);try{let e=await i.mutateAsync({});u({keyId:e.keyId,secretKey:e.secretKey})}catch(e){f(e instanceof Error?e.message:String(e))}}},v=async()=>{if(await s({title:t(`backup.backupEncryptionCard.turnBackupEncryptionOff`,`Turn backup encryption off`),message:t(`backup.backupEncryptionCard.newBackupsWillBeWritten`,`New backups will be written unencrypted. Existing encrypted backups still need their key to be restored.`),confirmLabel:t(`backup.backupEncryptionCard.turnOff`,`Turn off`),variant:`danger`})){f(null);try{await o.mutateAsync({}),n.refetch()}catch(e){f(e instanceof Error?e.message:String(e))}}};return e(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-4`,children:[e(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[e(`div`,{className:`flex items-center gap-2`,children:[m?r(x,{className:`h-4 w-4 text-success`}):r(p,{className:`h-4 w-4 text-foreground-subtle`}),r(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`backup.backupEncryptionCard.encryption`,`Encryption`)}),r(`span`,{className:`text-xs text-foreground-subtle`,children:m&&h!==null?t(`backup.backupEncryptionCard.onKeySince`,`On — key {{keyId}}, since {{value2}}`,{keyId:h.keyId,value2:$t(h.createdAt)}):t(`backup.backupEncryptionCard.offBackupsAreNotEncrypted`,`Off — backups are not encrypted`)})]}),r(`div`,{className:`flex gap-2`,children:m?e(c,{children:[r(L,{size:`sm`,variant:`outline`,disabled:i.isPending,onClick:()=>void _(),children:t(`backup.backupEncryptionCard.replaceKey`,`Replace key`)}),r(L,{size:`sm`,variant:`outline`,disabled:o.isPending,onClick:()=>void v(),children:t(`backup.backupEncryptionCard.turnOff`,`Turn off`)})]}):r(L,{size:`sm`,disabled:i.isPending,onClick:()=>void _(),children:t(`backup.backupEncryptionCard.enableEncryption`,`Enable encryption`)})})]}),r(`p`,{className:`text-xs text-foreground-subtle`,children:t(`backup.backupEncryptionCard.archivesAreEncryptedOnThis`,`Archives are encrypted on this server before they reach any destination. The server keeps only a public key, so it can encrypt scheduled backups but cannot decrypt them — only your backup key can. Covers the database snapshot, addon data (HomeKit pairing, Matter fabric, Tailscale state) and TLS.`)}),g.length>0&&e(`div`,{className:`text-xs`,children:[r(`p`,{className:`text-foreground-subtle`,children:t(`backup.backupEncryptionCard.olderKeysBackupsMadeWith`,`Older keys (backups made with them still need them):`)}),r(`ul`,{className:`font-mono text-foreground`,children:g.map(t=>e(`li`,{children:[t.keyId,` · `,$t(t.createdAt),` → `,$t(t.retiredAt)]},t.keyId))})]}),d!==null&&r(`p`,{className:`text-xs text-danger`,children:d}),l!==null&&r(tn,{revealed:l,onDone:()=>{u(null),n.refetch()}})]})}o();var rn=[{id:`manual`,labelKey:`backup.cronEditor.presetManual`,cron:``},{id:`hourly`,labelKey:`backup.cronEditor.presetHourly`,cron:`0 * * * *`,descriptionKey:`backup.cronEditor.presetHourlyDesc`},{id:`every-3h`,labelKey:`backup.cronEditor.preset3h`,cron:`0 */3 * * *`,description:`00:00, 03:00, 06:00, 09:00 …`},{id:`every-6h`,labelKey:`backup.cronEditor.preset6h`,cron:`0 */6 * * *`,description:`00:00, 06:00, 12:00, 18:00`},{id:`daily-3am`,labelKey:`backup.cronEditor.presetDaily`,cron:`0 3 * * *`,descriptionKey:`backup.cronEditor.presetDailyDesc`},{id:`weekly-sun`,labelKey:`backup.cronEditor.presetWeekly`,cron:`0 3 * * 0`,descriptionKey:`backup.cronEditor.presetWeeklyDesc`}];function an(e){let t=e.trim();for(let e of rn)if(e.cron===t)return e.id;return`custom`}function on({value:t,onChange:n,previewCount:o=5,disabled:s=!1}){let{t:c}=Y(),l=an(t),[u,d]=a(l===`custom`);i(()=>{l!==`custom`&&d(!1)},[l]);let f=ln(t,250),p=xe({cron:f,count:o},{enabled:f.trim().length>0}),m=p.data??null,h=e=>{d(!1),n(e.cron)},g=u||l===`custom`;return e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`space-y-1`,children:[r(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:c(`backup.cronEditor.schedulePreset`,`Schedule preset`)}),e(`div`,{className:`flex flex-wrap gap-1.5`,children:[rn.map(e=>r(L,{variant:`unstyled`,type:`button`,onClick:()=>h(e),disabled:s,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!u&&l===e.id?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),title:e.descriptionKey===void 0?e.description??c(e.labelKey):c(e.descriptionKey),children:c(e.labelKey)},e.id)),r(L,{variant:`unstyled`,type:`button`,onClick:()=>{d(!0),t.trim().length===0&&n(`0 3 * * *`)},disabled:s,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(g?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:c(`backup.cronEditor.custom`,`Custom…`)})]})]}),g&&e(`div`,{className:`space-y-1`,children:[r(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:c(`backup.cronEditor.cronExpression5FieldPosix`,`Cron expression (5-field POSIX)`)}),r(W,{type:`text`,value:t,onChange:e=>n(e.target.value),disabled:s,placeholder:`0 3 * * *`,spellCheck:!1,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs font-mono text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`}),e(`p`,{className:`text-[10px] text-foreground-subtle`,children:[c(`backup.cronEditor.format`,`Format:`),` `,r(ft,{i18nKey:`backup.cronEditor.formatLine`,components:{code:r(`span`,{className:`font-mono`})}})]})]}),r(sn,{cron:f,preview:m,loading:p.isFetching})]})}function sn({cron:t,preview:n,loading:i}){let{t:a}=Y();return i&&n===null?e(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[r(y,{className:`h-3 w-3 animate-spin`}),a(`backup.cronEditor.validating`,`Validating…`)]}):n===null?null:n.ok?n.nextRuns.length===0?r(`div`,{className:`rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:a(`backup.cronEditor.noFutureRunsMatchThis`,`No future runs match this expression.`)}):e(`div`,{className:`space-y-1`,children:[r(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:a(`backup.cronEditor.nextRuns`,`Next runs`)}),r(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:n.nextRuns.map((t,n)=>e(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[r(`span`,{className:`text-foreground tabular-nums`,children:new Date(t).toLocaleString()}),r(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:cn(t)})]},`${t}-${n}`))})]}):r(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:n.error??a(`backup.cronEditor.invalidCronExpression`,`Invalid cron expression`)})}function cn(e){let t=e-Date.now();if(t<=0)return J.t(`helpers.relativeTime.now`);let n=Math.floor(t/1e3);if(n<60)return J.t(`helpers.relativeTime.inSeconds`,{count:n});let r=Math.floor(n/60);if(r<60)return J.t(`helpers.relativeTime.inMinutes`,{count:r});let i=Math.floor(r/60);if(i<24)return J.t(`helpers.relativeTime.inHours`,{count:i});let a=Math.floor(i/24);return J.t(`helpers.relativeTime.inDays`,{count:a})}function ln(e,n){let[r,o]=a(e),s=t(()=>e,[e]);return i(()=>{let e=setTimeout(()=>o(s),n);return()=>clearTimeout(e)},[s,n]),r}o();var un=[[`backup`,`listSchedules`]];function dn({entry:n,onClose:i,onSaved:o}){let{t:c}=Y(),l=s(),u=Ee(),d=u.data??[],[f,p]=a(n?.label??``),[m,h]=a(n?.cron??`0 3 * * *`),[g,v]=a(n?.enabled??!0),[b,x]=a(String(n?.retentionCount??7)),[S,C]=a(new Set(n?.locationIds??[])),[w,ee]=a(new Set(n===null?Ct:Ot(n.databases))),T=lt({onSuccess:()=>{l.invalidateQueries({queryKey:un}),o()}}),E=e=>{C(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},D=Number.parseInt(b,10),O=t(()=>f.trim().length>0&&S.size>0&&w.size>0&&!Number.isNaN(D)&&D>=1&&D<=1e3,[f,S,w,D]),k=()=>{O&&T.mutate({...n?{id:n.id}:{},label:f.trim(),cron:m.trim(),enabled:g,locationIds:Array.from(S),retentionCount:D,databases:[...kt(w)]})},A=T.error instanceof Error?T.error.message:null;return r(tt,{open:!0,onClose:i,title:n?c(`backup.backupEntryModal.editBackupEntry`,`Edit backup entry`):c(`backup.backupEntryModal.newBackupEntry`,`New backup entry`),icon:re,error:A,width:`lg`,testId:`backup-entry-form`,footer:e(L,{size:`sm`,type:`button`,onClick:k,disabled:!O||T.isPending,children:[T.isPending?r(y,{className:`h-3.5 w-3.5 animate-spin`}):null,n?c(`common.save`,`Save`):c(`backup.backupEntryModal.createEntry`,`Create entry`)]}),children:e(`div`,{className:`space-y-4`,children:[r(G,{label:c(`backup.backupEntryModal.name`,`Name`),required:!0,children:r(W,{value:f,onChange:e=>p(e.target.value),placeholder:c(`backup.backupEntryModal.nightlyOffsite`,`Nightly offsite`),autoFocus:!0,"data-testid":`backup-entry-name`})}),e(G,{label:c(`backup.backupEntryModal.locationsSelected`,`Locations ({{value1}} selected)`,{value1:String(S.size)}),required:!0,children:[u.isLoading&&e(`div`,{className:`flex items-center gap-2 px-1 py-2 text-xs text-foreground-subtle`,children:[r(y,{className:`h-3.5 w-3.5 animate-spin`}),c(`backup.backupEntryModal.loadingLocations`,`Loading locations…`)]}),!u.isLoading&&d.length===0&&r(`div`,{className:`rounded border border-border bg-background px-3 py-2 text-xs text-foreground-subtle italic`,children:c(`backup.backupEntryModal.noBackupsStorageLocationsConfigured`,"No `backups` storage locations configured. Add one in Settings → Storage first.")}),d.length>0&&r(`div`,{className:`max-h-52 divide-y divide-border overflow-y-auto rounded border border-border bg-background`,children:d.map(t=>e(`label`,{className:`flex cursor-pointer items-center justify-between px-3 py-2 text-xs hover:bg-primary/5`,children:[e(`div`,{className:`flex items-center gap-2`,children:[r(_,{checked:S.has(t.id),onChange:()=>E(t.id),className:`accent-primary`}),r(`span`,{className:`text-foreground`,children:t.displayName})]}),e(`div`,{className:`flex items-center gap-1.5`,children:[r(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-foreground-subtle`,children:t.kind}),r(`span`,{className:`font-mono text-[10px] text-foreground-subtle`,children:t.id})]})]},t.id))})]}),r(Zt,{selected:w,onChange:ee,disabled:T.isPending,testId:`backup-entry-databases`}),e(`div`,{className:`grid grid-cols-2 gap-3`,children:[r(G,{label:c(`backup.backupEntryModal.retentionArchivesKept`,`Retention (archives kept)`),required:!0,children:r(W,{type:`number`,min:1,max:1e3,value:b,onChange:e=>x(e.target.value),"data-testid":`backup-entry-retention`})}),r(G,{label:c(`backup.backupEntryModal.enabled`,`Enabled`),description:c(`backup.backupEntryModal.runOnScheduleWhenChecked`,`Run on schedule when checked.`),children:e(`label`,{className:`inline-flex cursor-pointer items-center gap-2 py-1.5 text-xs text-foreground`,children:[r(_,{checked:g,onChange:e=>v(e.target.checked),className:`accent-primary`,"data-testid":`backup-entry-enabled`}),r(`span`,{children:c(`backup.backupEntryModal.runOnSchedule`,`Run on schedule`)})]})})]}),r(G,{label:c(`backup.backupEntryModal.schedule`,`Schedule`),children:r(on,{value:m,onChange:h,disabled:T.isPending})})]})})}o();var fn=2e3,pn=5e3;function mn(e){return e.state===`queued`||e.state===`running`}function hn(e){if(e.state===`queued`)return{title:J.t(`backup.backupRunsPanel.cancelQueuedBackupRun`,`Cancel queued backup run?`),message:J.t(`backup.backupRunsPanel.thisRunHasNotStarted`,`This run has not started. Cancelling removes it from the queue — nothing has been written, nothing is deleted.`),confirmLabel:J.t(`backup.backupRunsPanel.cancelRun`,`Cancel run`),variant:`warning`};let t=e.completedDestinationIds.length,n=t>0?`${t===1?`The 1 destination`:`The ${t} destinations`} that already completed KEEP${t===1?`S`:``} the archive.`:`No destination has completed yet, so nothing will be kept.`;return{title:J.t(`backup.backupRunsPanel.stopThisBackupRun`,`Stop this backup run?`),message:J.t(`backup.backupRunsPanel.theHalfWrittenStagingArchive`,`The half-written staging archive is deleted and the destination currently uploading discards its partial copy. {{keptSentence}}`,{keptSentence:n}),confirmLabel:J.t(`backup.backupRunsPanel.stopRun`,`Stop run`),variant:`danger`}}function gn(){let e=D(),[t,i]=a(null),o=Oe(void 0,{refetchInterval:e=>(e.state.data??[]).some(mn)?fn:pn}),s=st({onSettled:()=>{i(null),o.refetch()}}),c=n(async t=>{await e(hn(t))&&(i(t.id),s.mutate({runId:t.id}))},[e,s]);return r(_n,{queryState:o.isError?`error`:o.data===void 0?`pending`:`ready`,runs:o.data??[],cancelingId:t,onCancelRequest:e=>{c(e)},now:Date.now()})}function _n({queryState:t,runs:n,cancelingId:i,onCancelRequest:a,now:o}){let{t:s}=Y(),c=t===`ready`&&n.some(mn),l=n.filter(e=>e.state===`running`),u=n.filter(e=>e.state===`queued`),d=n.filter(e=>!mn(e)),f=[...l,...u,...d];return e(`section`,{className:`rounded-lg border border-border bg-surface`,children:[e(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-border`,children:[r(`h2`,{className:`text-xs font-semibold text-foreground`,children:s(`backup.backupRunsPanel.runs`,`Runs`)}),c&&e(`span`,{className:`inline-flex items-center gap-1 text-[10px] font-medium text-primary`,title:s(`backup.backupRunsPanel.aBackupRunIsIn`,`A backup run is in progress`),children:[r(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary animate-pulse`}),s(`backup.runsPanel.live`)]}),r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:s(`backup.backupRunsPanel.oneRunExecutesAtA`,`One run executes at a time — queued runs wait in line.`)})]}),t===`pending`&&r(`div`,{className:`px-3 py-2.5 text-xs text-foreground-subtle animate-pulse`,children:s(`backup.backupRunsPanel.checkingForBackupRuns`,`Checking for backup runs…`)}),t===`error`&&r(`div`,{className:`px-3 py-2.5 text-xs text-danger`,children:s(`backup.backupRunsPanel.couldNotReadBackupRuns`,`Could not read backup runs — the orchestrator did not answer.`)}),t===`ready`&&n.length===0&&r(`div`,{className:`px-3 py-2.5 text-xs text-foreground-subtle italic`,children:s(`backup.backupRunsPanel.noBackupRunsYetRuns`,`No backup runs yet. Runs appear here the moment one starts — manual or scheduled.`)}),t===`ready`&&n.length>0&&r(`div`,{className:`overflow-x-auto`,children:e(`table`,{className:`w-full text-xs min-w-[720px]`,children:[r(`thead`,{children:e(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[r(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:s(`backup.backupRunsPanel.run`,`Run`)}),r(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:s(`backup.backupRunsPanel.state`,`State`)}),r(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:s(`backup.backupRunsPanel.progress`,`Progress`)}),r(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:s(`backup.backupRunsPanel.destinations`,`Destinations`)}),r(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:s(`backup.backupRunsPanel.timing`,`Timing`)}),r(`th`,{className:`text-right px-3 py-1.5 font-medium w-28`,children:s(`backup.backupRunsPanel.actions`,`Actions`)})]})}),r(`tbody`,{children:f.map(e=>r(vn,{run:e,canceling:i===e.id,onCancelRequest:a,now:o},e.id))})]})})]})}function vn({run:t,canceling:n,onCancelRequest:i,now:a}){let{t:o}=Y(),s=mn(t);return e(`tr`,{className:`border-t border-border hover:bg-primary/5 align-top`,children:[r(`td`,{className:`px-3 py-2`,children:r(`div`,{className:`text-foreground`,title:t.id,children:t.label??r(`span`,{className:`text-foreground-subtle italic`,children:o(`backup.runsPanel.manual`)})})}),e(`td`,{className:`px-3 py-2`,children:[r(yn,{run:t}),t.state===`failed`&&t.error!==void 0&&r(`div`,{className:`mt-1 text-[10px] text-danger max-w-56 truncate`,title:t.error,children:t.error})]}),r(`td`,{className:`px-3 py-2`,children:r(bn,{run:t})}),r(`td`,{className:`px-3 py-2`,children:r(xn,{run:t})}),r(`td`,{className:`px-3 py-2 text-foreground-subtle tabular-nums`,children:r(Sn,{run:t,now:a})}),r(`td`,{className:`px-3 py-2`,children:r(`div`,{className:`flex justify-end`,children:s&&e(L,{variant:`unstyled`,onClick:()=>i(t),disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:t.state===`queued`?o(`backup.backupRunsPanel.removeThisRunFromThe`,`Remove this run from the queue before it starts`):o(`backup.backupRunsPanel.stopThisRunTheHalf`,`Stop this run — the half-written archive is discarded`),children:[n?r(y,{className:`h-3 w-3 animate-spin`}):r(te,{className:`h-3 w-3`}),t.state===`queued`?o(`common.cancel`,`Cancel`):o(`backup.backupRunsPanel.stop`,`Stop`)]})})})]})}function yn({run:t}){let{t:n}=Y();switch(t.state){case`queued`:return e(`span`,{className:`inline-flex items-center gap-1 rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:[r(w,{className:`h-3 w-3`}),n(`backup.backupRunsPanel.queued`,`Queued`)]});case`running`:return e(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`,children:[r(y,{className:`h-3 w-3 animate-spin`}),t.phase===`uploading`?n(`backup.backupRunsPanel.uploading`,`Uploading`):n(`backup.backupRunsPanel.buildingArchive`,`Building archive`)]});case`succeeded`:return e(`span`,{className:`inline-flex items-center gap-1 rounded bg-success/10 px-1.5 py-0.5 text-[10px] font-medium text-success`,children:[r(v,{className:`h-3 w-3`}),n(`backup.backupRunsPanel.succeeded`,`Succeeded`)]});case`failed`:return e(`span`,{className:`inline-flex items-center gap-1 rounded bg-danger/10 px-1.5 py-0.5 text-[10px] font-medium text-danger`,children:[r(l,{className:`h-3 w-3`}),n(`backup.backupRunsPanel.failed`,`Failed`)]});case`cancelled`:return e(`span`,{className:`inline-flex items-center gap-1 rounded bg-amber-500/10 px-1.5 py-0.5 text-[10px] font-medium text-amber-700 dark:text-amber-300`,title:n(`backup.backupRunsPanel.stoppedBeforeCompletingEveryDestination`,`Stopped before completing every destination — not a success`),children:[r(de,{className:`h-3 w-3`}),n(`backup.backupRunsPanel.stopped`,`Stopped`)]})}}function bn({run:t}){let{t:n}=Y();if(t.state===`queued`)return r(`span`,{className:`text-foreground-subtle`,children:t.queuePosition===void 0?r(`span`,{className:`italic`,children:n(`backup.backupRunsPanel.waitingItsTurn`,`waiting its turn`)}):e(`span`,{className:`inline-flex items-center gap-1`,children:[r(`span`,{className:t.queuePosition===1?`rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`:`rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium`,children:Cn(t.queuePosition)}),n(`backup.backupRunsPanel.inLine`,`in line`)]})});if(t.state===`running`&&t.phase===`building`)return e(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[r(me,{className:`h-3 w-3 text-primary`}),r(`span`,{className:`tabular-nums font-medium animate-pulse`,children:X(t.stagedBytes)}),r(`span`,{className:`text-foreground-subtle`,children:n(`backup.backupRunsPanel.stagedSoFar`,`staged so far`)})]});if(t.state===`running`){let i=t.archiveSizeBytes;return e(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[r(fe,{className:`h-3 w-3 text-primary`}),e(`span`,{className:`tabular-nums font-medium`,children:[X(t.uploadedBytes),i===void 0?``:` / ${X(i)}`]}),r(`span`,{className:`text-foreground-subtle`,children:n(`backup.backupRunsPanel.toCurrentDestination`,`to current destination`)})]})}let i=t.archiveSizeBytes??(t.stagedBytes>0?t.stagedBytes:void 0);return i===void 0?r(`span`,{className:`text-foreground-subtle italic`,children:`—`}):r(`span`,{className:`tabular-nums text-foreground`,children:n(`backup.runsPanel.archiveSize`,{size:X(i)})})}function xn({run:t}){let{t:n}=Y(),i=t.destinationIds.length,a=t.completedDestinationIds.length,o=t.failedDestinationIds.length;return i===0?r(`span`,{className:`text-foreground-subtle italic`,children:n(`backup.backupRunsPanel.notResolvedYet`,`not resolved yet`)}):e(`div`,{className:`flex flex-col gap-0.5`,children:[r(`span`,{className:`text-foreground-subtle`,title:t.destinationIds.join(`, `),children:n(`backup.runsPanel.targets`,{count:i})}),e(`span`,{className:`inline-flex items-center gap-2 text-[10px]`,children:[a>0&&r(`span`,{className:`text-success`,title:n(`backup.backupRunsPanel.keptTheirArchive`,`Kept their archive: {{value1}}`,{value1:t.completedDestinationIds.join(`, `)}),children:n(`backup.runsPanel.completed`,{count:a})}),o>0&&r(`span`,{className:`text-danger`,title:n(`backup.backupRunsPanel.failed2`,`Failed: {{value1}}`,{value1:t.failedDestinationIds.join(`, `)}),children:n(`backup.runsPanel.failedCount`,{count:o})})]})]})}function Sn({run:t,now:n}){let{t:i}=Y();return t.state===`queued`?r(`span`,{children:i(`backup.runsPanel.queuedAgo`,{elapsed:wn(n-t.requestedAt)})}):t.startedAt===void 0?r(`span`,{children:`—`}):t.finishedAt===void 0?r(`span`,{children:i(`backup.runsPanel.runningFor`,{elapsed:wn(n-t.startedAt)})}):e(`div`,{className:`flex flex-col gap-0.5`,children:[r(`span`,{children:Tn(t.finishedAt)}),r(`span`,{className:`text-[10px]`,children:i(`backup.runsPanel.took`,{elapsed:wn(t.finishedAt-t.startedAt)})})]})}function Cn(e){if(e<=1)return`next`;let t=e%100;if(t>=11&&t<=13)return`${e}th`;switch(e%10){case 1:return`${e}st`;case 2:return`${e}nd`;case 3:return`${e}rd`;default:return`${e}th`}}function wn(e){let t=Math.max(0,Math.floor(e/1e3));if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m ${String(t%60).padStart(2,`0`)}s`:`${Math.floor(n/60)}h ${String(n%60).padStart(2,`0`)}m`}function Tn(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}o();var En=[[`backup`,`list`]];function Dn({initialDestinationId:n,initialArchiveId:o,onClose:c,onScheduled:l}){let{t:u}=Y(),d=s(),[f,p]=a(n&&o?2:1),[m,g]=a(n),[_,v]=a(o),[b,x]=a(new Set),[S,w]=a(``),{data:ee}=Ee(),T=ee??[],{data:E,isLoading:D}=ge({destinationId:m??``},{enabled:!!m}),O=E??[];i(()=>{if(m!==void 0)return;let e=T.filter(e=>e.restoreSupported);e.length===1&&g(e[0].id)},[m,T]);let{data:k}=qe({destinationId:m??``,backupId:_??``},{enabled:!!m&&!!_}),A=t(()=>k?.locations??[],[k]);i(()=>{A.length!==0&&x(e=>e.size===0?new Set(A):e)},[A]);let j=Ce({onSuccess:()=>{d.invalidateQueries({queryKey:En}),l(),c()}}),te=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},M=O.find(e=>e.id===_),ne=M?.encryption!==void 0,N=Ft(M?.databases,k?.sqliteSnapshots),F=Nt(N),I=!!m&&!!_,re=F||b.size>0,ie=I&&re&&!j.isPending&&(!ne||S.trim().length>0),ae=()=>{!m||!_||j.mutate({destinationId:m,backupId:_,...F?{}:{locations:[...b]},...ne?{backupSecretKey:S.trim()}:{}})};return r(V,{open:!0,onOpenChange:e=>!e&&c(),children:e(R,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[e(H,{children:[r(U,{children:u(`backup.restoreWizard.restoreBackup`,`Restore Backup`)}),r(`p`,{className:`text-xs text-foreground-subtle`,children:u(`backup.restoreWizard.stepOf`,{step:f,name:f===1?u(`backup.restoreWizard.pickSource`,`pick source`):f===2?u(`backup.restoreWizard.pickLocations`,`pick locations`):u(`backup.restoreWizard.confirmStep`)})})]}),e(q,{children:[f===1&&r(On,{destinations:T,destinationId:m,onPickDestination:e=>{g(e),v(void 0),x(new Set)},archives:O,archivesLoading:D,archiveId:_,onPickArchive:v}),f===2&&r(kn,{locations:A,picked:b,onToggle:te,databases:N,snapshotsOnly:F}),f===3&&r(An,{destinationName:T.find(e=>e.id===m)?.displayName??m??``,archive:M,picked:[...b],databases:N,snapshotsOnly:F}),f===3&&M?.encryption!==void 0&&r(jn,{keyId:M.encryption.keyId,value:S,onChange:w}),f===3&&j.error&&r(`p`,{role:`alert`,className:`px-4 pb-2 text-xs text-danger`,children:j.error.message})]}),e(z,{className:`justify-between`,children:[r(`div`,{children:f>1&&e(L,{variant:`outline`,size:`sm`,onClick:()=>p(e=>e===3?2:1),children:[r(C,{className:`h-3 w-3`}),u(`common.back`,`Back`)]})}),e(`div`,{className:`flex items-center gap-2`,children:[r(L,{variant:`outline`,size:`sm`,onClick:c,children:u(`common.cancel`,`Cancel`)}),f<3?e(L,{size:`sm`,disabled:f===1&&!I||f===2&&!re,onClick:()=>p(e=>e===1?2:3),children:[u(`common.next`,`Next`),r(h,{className:`h-3 w-3`})]}):e(L,{size:`sm`,onClick:ae,disabled:!ie,children:[j.isPending?r(y,{className:`h-3.5 w-3.5 animate-spin`}):r(P,{className:`h-3.5 w-3.5`}),u(`backup.restoreWizard.scheduleRestore`,`Schedule Restore`)]})]})]})]})})}function On({destinations:t,destinationId:n,onPickDestination:i,archives:a,archivesLoading:o,archiveId:s,onPickArchive:c}){let{t:l}=Y(),u=t.filter(e=>e.restoreSupported);return e(`div`,{className:`p-4 space-y-3`,children:[e(`div`,{className:`space-y-1.5`,children:[r(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:l(`backup.restoreWizard.destination`,`Destination`)}),r(k,{value:n??``,onChange:e=>i(e.target.value),options:[{value:``,label:l(`backup.restoreWizard.selectDestination`,`Select destination…`)},...u.map(e=>({value:e.id,label:`${e.displayName} (${e.kind})`}))]})]}),e(`div`,{className:`space-y-1.5`,children:[r(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:l(`backup.restoreWizard.archive`,`Archive`)}),!n&&r(`div`,{className:`text-xs text-foreground-subtle italic`,children:l(`backup.restoreWizard.pickADestinationFirst`,`Pick a destination first.`)}),n&&o&&r(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:l(`backup.restoreWizard.readingArchives`,`Reading archives…`)}),n&&!o&&a.length===0&&r(`div`,{className:`text-xs text-foreground-subtle italic`,children:l(`backup.restoreWizard.noArchivesAvailableAtThis`,`No archives available at this destination.`)}),n&&a.length>0&&r(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:a.map(t=>{let n=s===t.id;return e(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${n?`bg-primary/10`:`hover:bg-primary/5`}`,children:[e(`div`,{className:`flex items-center gap-2`,children:[r(ot,{name:`archive`,checked:n,onChange:()=>c(t.id),className:`accent-primary`}),e(`div`,{children:[e(`div`,{className:`flex items-center gap-1 font-medium text-foreground`,children:[t.encryption!==void 0&&r(x,{className:`h-3 w-3 text-success`,"aria-label":l(`backup.restoreWizard.encryptedKey`,`encrypted (key {{keyId}})`,{keyId:t.encryption.keyId})}),t.label??t.id]}),r(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(t.createdAt).toLocaleString()}),r(`div`,{className:`pt-1`,children:r(Q,{databases:Ft(t.databases,void 0)})})]})]}),r(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:X(t.sizeBytes)})]},t.id)})})]})]})}function kn({locations:t,picked:n,onToggle:i,databases:a,snapshotsOnly:o}){let{t:s}=Y();return o?e(`div`,{className:`space-y-3 p-4`,children:[e(`div`,{className:`space-y-1.5`,children:[r(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:s(`backup.restoreWizard.databasesInThisArchive`,`Databases in this archive`)}),r(Q,{databases:a})]}),r(`div`,{className:`rounded border border-info/30 bg-info/10 px-3 py-2 text-[11px] text-info`,children:s(`backup.restoreWizard.snapshotsOnlyRestoringThisArchive`,`Snapshots only: restoring this archive replaces just these databases. It does NOT touch configuration, addons, addon data or certificates.`)})]}):t.length===0?r(`div`,{className:`p-4`,children:r(`div`,{className:`text-xs text-foreground-subtle`,children:s(`backup.restoreWizard.loadingArchiveManifestIfThis`,`Loading archive manifest… If this persists, the archive may predate manifests — restoring will apply everything in the tarball.`)})}):e(`div`,{className:`p-4 space-y-3`,children:[e(`div`,{className:`space-y-1.5`,children:[r(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:s(`backup.restoreWizard.databasesInThisArchive`,`Databases in this archive`)}),r(Q,{databases:a})]}),r(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-[11px] text-warning`,children:s(`backup.restoreWizard.selectedEntriesWillOverwriteLive`,`Selected entries will overwrite live data on the next server restart. Unchecked entries stay current.`)}),e(`div`,{className:`space-y-1.5`,children:[r(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:s(`common.apply`,`Apply`)}),r(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:t.map(t=>e(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[r(_,{checked:n.has(t),onChange:()=>i(t),className:`accent-primary`}),r(`span`,{className:`font-mono text-foreground`,children:t}),r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Pn(t)})]},t))})]})]})}function An({destinationName:t,archive:n,picked:i,databases:a,snapshotsOnly:o}){let{t:s}=Y();return e(`div`,{className:`p-4 space-y-3 text-xs`,children:[r(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-warning`,children:s(`backup.restoreWizard.restoreIsAppliedAtNext`,`Restore is applied at next server boot. Active connections will drop when you restart.`)}),e(`dl`,{className:`space-y-1.5`,children:[r(Mn,{term:`Destination`,value:t}),r(Mn,{term:`Archive`,value:n?.label??n?.id??`—`}),n&&r(Mn,{term:`Created`,value:`${new Date(n.createdAt).toLocaleString()} · ${X(n.sizeBytes)}`}),e(`div`,{className:`flex justify-between gap-3`,children:[r(`dt`,{className:`text-foreground-subtle`,children:s(`backup.restoreWizard.databases`,`Databases`)}),r(`dd`,{className:`text-right`,children:r(Q,{databases:a})})]}),r(Mn,{term:`Locations`,value:o?`none (configuration is not touched)`:i.length>0?i.join(`, `):`— (full archive)`})]})]})}function jn({keyId:t,value:n,onChange:i}){let{t:a}=Y();return e(`div`,{className:`space-y-1.5 px-4 pb-3`,children:[r(`label`,{htmlFor:`restore-backup-key`,className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:a(`backup.restoreWizard.backupKey`,`Backup key`)}),r(W,{id:`restore-backup-key`,type:`password`,autoComplete:`off`,spellCheck:!1,value:n,onChange:e=>i(e.target.value),placeholder:a(`backup.restoreWizard.camstackBackupSecretV1`,`camstack-backup-secret-v1:…`),className:`w-full rounded border border-border bg-background px-2 py-1.5 font-mono text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),r(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(ft,{i18nKey:`backup.restoreWizard.encryptedTo`,values:{keyId:t},components:{mono:r(`span`,{className:`font-mono`})}})})]})}function Mn({term:t,value:n}){return e(`div`,{className:`flex justify-between gap-3`,children:[r(`dt`,{className:`text-foreground-subtle`,children:t}),r(`dd`,{className:`text-foreground font-mono text-right truncate`,children:n})]})}var Nn={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function Pn(e){return Nn[e]??``}o();function Fn(){let{t}=Y(),n=D(),o=Re(),{state:s,openNew:c,openEdit:l,close:u}=Ze({editKey:`edit`,newKey:`new`}),d=Ae(),f=d.data??[],[p,m]=a(null),[h,g]=a(!1),[_,v]=a(!1),[b,x]=a(!1),S=s.mode===`edit`?f.find(e=>e.id===s.id)??null:null;i(()=>{s.mode===`edit`&&!d.isLoading&&S===null&&u()},[s.mode,d.isLoading,S,u]);let C=s.mode===`new`||s.mode===`edit`&&S!==null,w=async()=>{await n({title:t(`system.backup.restartServerNow`,`Restart server now?`),message:t(`system.backup.activeConnectionsWillDropAnd`,`Active connections will drop and the apply-backup hook will run before boot.`),confirmLabel:t(`system.backup.restart`,`Restart`),variant:`warning`})&&o.mutate({confirm:!0})};return e(ht,{embedded:!0,children:[e(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,"data-testid":`backup-actions`,children:[e(L,{variant:`outline`,size:`sm`,type:`button`,onClick:()=>x(!0),"data-testid":`backup-now`,children:[r(E,{className:`h-3.5 w-3.5`}),t(`system.backup.backUpNow`,`Back up now`)]}),e(L,{variant:`outline`,size:`sm`,type:`button`,onClick:()=>g(!0),children:[r(P,{className:`h-3.5 w-3.5`}),t(`system.backup.restore`,`Restore…`)]}),e(L,{size:`sm`,type:`button`,onClick:c,"data-testid":`backup-new-entry`,children:[r(j,{className:`h-3.5 w-3.5`}),t(`system.backup.newEntry`,`New entry`)]})]}),_&&r(`div`,{className:`rounded-lg border border-warning/30 bg-warning/10 px-3 py-2.5 text-xs text-warning`,children:e(`div`,{className:`flex items-center justify-between gap-3`,children:[e(`div`,{className:`flex items-center gap-2`,children:[r(P,{className:`h-3.5 w-3.5`}),r(`span`,{children:t(`system.backup.restoreScheduledRestartTheServer`,`Restore scheduled. Restart the server to apply.`)})]}),e(L,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>{w()},disabled:o.isPending,children:[o.isPending?r(y,{className:`h-3.5 w-3.5 animate-spin`}):r(P,{className:`h-3.5 w-3.5`}),t(`system.backup.restartNow`,`Restart Now`)]})]})}),r(nn,{}),r(gn,{}),r(Ht,{onEdit:e=>l(e.id),onOpenRestoreWizard:e=>m(e)}),C&&r(dn,{entry:S,onClose:u,onSaved:u}),b&&r(Qt,{onClose:()=>x(!1)}),(p||h)&&r(Dn,{...p?{initialDestinationId:p.destinationId,initialArchiveId:p.archiveId}:{},onClose:()=>{m(null),g(!1)},onScheduled:()=>v(!0)})]})}var In=[`locked`,`reset`,`shares-backup`,`recovery-key`,`rotation-pending`,`orphans`],Ln={"key-missing":`helpers.keychainNotices.lockedKeyMissing`,"wrong-key":`helpers.keychainNotices.lockedWrongKey`,"key-file-unreadable":`helpers.keychainNotices.lockedKeyFileUnreadable`,"store-unavailable":`helpers.keychainNotices.lockedStoreUnavailable`,"not-initialized":`helpers.keychainNotices.lockedNotInitialized`,"decrypt-failed":`helpers.keychainNotices.lockedDecryptFailed`};function Rn(e){let t=Ln[e];return t===void 0?e:J.t(t)}function zn({status:e,reset:t,pendingReentry:n,orphans:r}){let i=e.keychain.state===`locked`,a=e.keySource??e.configuredSource,o=[];return e.keychain.state===`locked`&&o.push({id:`locked`,tone:`danger`,title:J.t(`helpers.keychainNotices.locked`,{reason:Rn(e.keychain.reason)})}),t!==null&&t.acknowledgedAt===null&&o.push({id:`reset`,tone:`danger`,title:n>0?J.t(`helpers.keychainNotices.resetPending`,{count:n}):J.t(`helpers.keychainNotices.resetDone`)}),a.sharesBackupWithDatabase&&o.push({id:`shares-backup`,tone:`warning`,title:J.t(`helpers.keychainNotices.sharesBackup`)}),!i&&e.recoveryKeyDownloadedAt===null&&o.push({id:`recovery-key`,tone:`warning`,title:J.t(`helpers.keychainNotices.recoveryKey`)}),!i&&e.rotationPending&&o.push({id:`rotation-pending`,tone:`info`,title:J.t(`helpers.keychainNotices.rotationPending`)}),!i&&r>0&&o.push({id:`orphans`,tone:`info`,title:J.t(`helpers.keychainNotices.orphans`,{count:r})}),[...o].sort((e,t)=>In.indexOf(e.id)-In.indexOf(t.id))}var Bn={dateStyle:`short`,timeStyle:`short`};function Vn(e){return e===null?`—`:new Date(e).toLocaleString(void 0,Bn)}function Hn({value:t,copyValue:n,srLabel:i,maxWidthClass:a,className:o}){let s=n??t;return e(`span`,{className:g(`flex min-w-0 items-center gap-0.5`,a),children:[r(`span`,{className:g(`min-w-0 truncate font-mono`,o),title:s,children:t}),r(be,{value:s,srLabel:i,className:`h-6 shrink-0 px-1.5`})]})}o();var Un=new Set([`reveal`,`download-recovery-key`,`rotate-master-key`,`reset`]);function Wn(e){return[{key:`at`,header:e(`system.keychainAuditTable.colWhen`),render:e=>Vn(e.at)},{key:`action`,header:e(`system.keychainAuditTable.colAction`),render:e=>r(K,{variant:Un.has(e.action)?`warning`:`default`,children:e.action})},{key:`actor`,header:e(`system.keychainAuditTable.colActor`),render:e=>r(`span`,{className:`font-mono`,children:e.actor})},{key:`ref`,header:e(`system.keychainAuditTable.colRef`),render:e=>e.ref===null?r(`span`,{className:`text-foreground-subtle`,children:`—`}):r(Hn,{value:e.ref,srLabel:`secret ref`,maxWidthClass:`max-w-[22rem]`})},{key:`detail`,header:e(`system.keychainAuditTable.colDetail`),render:e=>r(`span`,{className:`text-foreground-muted`,children:e.detail??``})}]}function Gn({entries:n}){let{t:i}=Y(),[o,s]=a(0),c=t(()=>Wn(i),[i]);if(n===void 0)return r(`p`,{className:`text-xs text-foreground-subtle`,children:i(`common.loading`,`Loading…`)});let l=Math.max(1,Math.ceil(n.length/25)),u=Math.min(o,l-1),d=u*25,f=n.slice(d,d+25);return e(`div`,{className:`space-y-2`,children:[r(B,{columns:c,rows:f,rowKey:e=>e.id,minWidthPx:760,emptyMessage:i(`secrets.keychainAuditTable.nothingHasBeenAuditedYet`,`Nothing has been audited yet.`)}),n.length>25&&e(`div`,{className:`flex flex-wrap items-center justify-between gap-2 text-[11px] text-foreground-subtle`,children:[r(`span`,{children:i(n.length>=500?`system.keychainAuditTable.rangeRecent`:`system.keychainAuditTable.range`,{from:d+1,to:d+f.length,total:n.length})}),e(`span`,{className:`inline-flex items-center gap-1`,children:[r(L,{size:`sm`,variant:`outline`,"aria-label":i(`secrets.keychainAuditTable.previousPage`,`Previous page`),disabled:u===0,onClick:()=>s(u-1),children:r(ne,{className:`h-3.5 w-3.5`,"aria-hidden":!0})}),e(`span`,{className:`tabular-nums`,children:[u+1,` / `,l]}),r(L,{size:`sm`,variant:`outline`,"aria-label":i(`secrets.keychainAuditTable.nextPage`,`Next page`),disabled:u>=l-1,onClick:()=>s(u+1),children:r(F,{className:`h-3.5 w-3.5`,"aria-hidden":!0})})]})]})]})}function Kn(e,t){switch(e){case`locked`:return r(L,{size:`sm`,variant:`danger`,disabled:t.busy,onClick:t.onReset,children:J.t(`secrets.keychainNoticeContent.resetKeychain`,`Reset keychain`)});case`reset`:return r(L,{size:`sm`,variant:`outline`,disabled:t.busy,onClick:t.onAcknowledgeReset,children:J.t(`secrets.keychainNoticeContent.dismiss`,`Dismiss`)});case`recovery-key`:return r(L,{size:`sm`,variant:`outline`,disabled:t.busy,onClick:t.onDownload,children:J.t(`secrets.keychainNoticeContent.download`,`Download`)});case`rotation-pending`:return r(L,{size:`sm`,variant:`outline`,disabled:t.busy,onClick:t.onRotate,children:J.t(`secrets.keychainNoticeContent.rotate`,`Rotate`)});case`orphans`:return r(L,{size:`sm`,variant:`outline`,onClick:t.onShowOrphans,children:J.t(`secrets.keychainNoticeContent.review`,`Review`)});case`shares-backup`:return null}}function qn(e,t){switch(e){case`locked`:return r(`p`,{children:J.t(`secrets.keychainNoticeContent.noValueCanBeRead`,`No value can be read or stored. If the master key is lost for good, Reset archives every stored value and starts a new keychain; every secret field then reads “not set”.`)});case`reset`:return t.reset===null?null:r(Jn,{reset:t.reset,pending:t.pendingReentry});case`shares-backup`:return r(`p`,{children:r(ft,{i18nKey:`secrets.keychainNoticeContent.backupKeyFile`,components:{code:r(`code`,{className:`font-mono`})}})});case`recovery-key`:return r(`p`,{children:J.t(`secrets.keychainNoticeContent.withoutACopyOfThe`,`Without a copy of the master key, the stored values cannot be recovered.`)});case`rotation-pending`:return r(`p`,{children:J.t(`secrets.keychainNoticeContent.theKeychainUnlockedWithA`,`The keychain unlocked with a previous key. Rotate to move onto the configured one.`)});case`orphans`:return null}}function Jn({reset:t,pending:n}){let{t:i}=Y(),a=t.actor===`trigger-file`?i(`secrets.keychainNoticeContent.resetByTrigger`):i(`secrets.keychainNoticeContent.resetByAdmin`,{actor:t.actor});return e(`div`,{className:`space-y-1.5`,children:[r(`p`,{children:i(`secrets.keychainNoticeContent.resetDetail`,{when:Vn(t.at),by:a,archived:t.archived})}),n.length>0&&r(`ul`,{className:`max-h-40 space-y-0.5 overflow-y-auto rounded-md border border-border bg-background p-2 font-mono text-[11px] text-foreground`,children:n.map(t=>e(`li`,{className:`break-all`,children:[t.owner,` · `,t.scope,` · `,t.fieldPath]},t.ref))})]})}o();var Yn=2,Xn={danger:{icon:le,text:`text-danger`,border:`border-danger/40`},warning:{icon:T,text:`text-warning`,border:`border-warning/40`},info:{icon:m,text:`text-info`,border:`border-border`}};function Zn({notices:t,renderAction:n,renderDetail:i}){let{t:o}=Y(),[s,c]=a(!1),l=t[0];if(l===void 0)return null;let u=t.length>Yn,d=u&&!s?t.slice(0,1):t,f=t.length-d.length;return e(`section`,{"aria-label":o(`secrets.keychainNotices.keychainNotices`,`Keychain notices`),className:g(`rounded-lg border bg-surface`,Xn[l.tone].border),children:[r(`ul`,{className:`divide-y divide-border`,children:d.map(e=>r(Qn,{notice:e,action:n(e.id),detail:i(e.id)},e.id))}),u&&r(`div`,{className:`border-t border-border px-3 py-1`,children:e(L,{size:`sm`,variant:`ghost`,"aria-expanded":s,onClick:()=>c(e=>!e),children:[r(ce,{className:g(`h-3.5 w-3.5 transition-transform`,s&&`rotate-180`),"aria-hidden":!0}),s?o(`secrets.keychainNotices.showLess`,`Show less`):o(`secrets.keychainNotices.more`,`{{hidden}} more`,{hidden:f})]})})]})}function Qn({notice:t,action:n,detail:i}){let{t:o}=Y(),[s,c]=a(!1),l=Xn[t.tone],u=l.icon,d=i!=null,f=`keychain-notice-${t.id}`;return e(`li`,{className:`px-3 py-2`,children:[e(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[e(`p`,{className:`flex min-w-0 flex-1 items-start gap-2 text-xs text-foreground`,children:[r(u,{className:g(`mt-0.5 h-3.5 w-3.5 shrink-0`,l.text),"aria-hidden":!0}),r(`span`,{className:`min-w-0 break-words`,children:t.title})]}),e(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1.5 pl-5 sm:pl-0`,children:[d&&r(L,{size:`sm`,variant:`ghost`,"aria-expanded":s,"aria-controls":f,onClick:()=>c(e=>!e),children:o(`secrets.keychainNotices.details`,`Details`)}),n]})]}),d&&s&&r(`div`,{id:f,className:`mt-2 pl-5 text-xs text-foreground-muted`,children:i})]})}var $n={"mounted-file":`Mounted key file (/run/secrets)`,"previous-mounted-file":`Previous mounted key file`,platform:`OS keychain`,"default-file":`Default key file (data volume)`},er=8;function tr({status:t,busy:n,onDownload:i,onRotate:a,onPurge:o}){let{t:s}=Y(),c=t.keychain.state===`locked`,l=t.keySource??t.configuredSource;return r(De,{headingId:`keychain-status`,title:s(`secrets.keychainStatusCard.keychain`,`Keychain`),icon:ue,actions:e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[t.retiredWraps>0&&r(L,{size:`sm`,variant:`ghost`,disabled:n||c,onClick:o,children:s(`secrets.keychainStatusCard.purge`,{count:t.retiredWraps})}),r(L,{size:`sm`,variant:`outline`,disabled:n||c,onClick:a,children:s(`secrets.keychainStatusCard.rotateKey`,`Rotate key`)}),r(L,{size:`sm`,variant:`outline`,disabled:n||c,onClick:i,children:s(`secrets.keychainStatusCard.downloadRecoveryKey`,`Download recovery key`)})]}),children:e(`dl`,{className:`${d} grid grid-cols-1 gap-x-6 gap-y-3 sm:grid-cols-2 xl:grid-cols-4`,children:[e(nr,{label:s(`secrets.keychainStatusCard.state`,`State`),children:[c?e(K,{variant:`danger`,className:`gap-1`,children:[r(x,{className:`h-3 w-3`,"aria-hidden":!0}),s(`secrets.keychainStatusCard.locked`,`Locked`)]}):e(K,{variant:`success`,className:`gap-1`,children:[r(b,{className:`h-3 w-3`,"aria-hidden":!0}),s(`secrets.keychainStatusCard.unlocked`,`Unlocked`)]}),r(`span`,{className:`ml-2 text-foreground-subtle`,children:s(`common.stored`,{count:t.secretCount})})]}),e(nr,{label:s(`secrets.keychainStatusCard.keySource`,`Key source`),children:[r(`span`,{className:`block`,children:$n[l.kind]}),l.path!==void 0&&r(Hn,{value:l.path,srLabel:`key path`})]}),r(nr,{label:s(`secrets.keychainStatusCard.fingerprint`,`Fingerprint`),children:t.fingerprint===null?r(`span`,{className:`text-foreground-subtle`,children:`—`}):e(`span`,{className:`inline-flex items-center gap-0.5`,children:[r(`span`,{className:`font-mono`,title:t.fingerprint,children:t.fingerprint.slice(0,er)}),r(be,{value:t.fingerprint,srLabel:`fingerprint`})]})}),r(nr,{label:s(`secrets.keychainStatusCard.recoveryKey`,`Recovery key`),children:t.recoveryKeyDownloadedAt===null?r(K,{variant:`warning`,children:s(`secrets.keychainStatusCard.notTaken`,`Not taken`)}):r(`span`,{children:s(`secrets.keychainStatusCard.taken`,{when:Vn(t.recoveryKeyDownloadedAt)})})})]})})}function nr({label:t,children:n}){return e(`div`,{className:`min-w-0 text-xs`,children:[r(`dt`,{className:`text-foreground-subtle`,children:t}),r(`dd`,{className:`mt-0.5 min-w-0 text-foreground`,children:n})]})}o();var rr=1e3;function ir({revealed:t,onClose:n}){let{t:o}=Y(),[s,l]=a(Ue);i(()=>{if(t===null)return;let e=Date.now();l(Ue);let r=setTimeout(n,Ue),i=setInterval(()=>l(Math.max(0,Ue-(Date.now()-e))),rr);return()=>{clearTimeout(r),clearInterval(i)}},[t,n]);let u=Math.ceil(s/1e3);return r(V,{open:t!==null,onOpenChange:e=>!e&&n(),children:r(R,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:t!==null&&e(c,{children:[e(H,{children:[r(U,{className:`break-all`,children:t.entry.fieldPath}),e(Pe,{className:`break-all`,children:[t.entry.owner,` · `,t.entry.scope]})]}),r(q,{children:r(`pre`,{"data-testid":`revealed-value`,className:`whitespace-pre-wrap break-all rounded-md border border-border bg-background p-3 font-mono text-xs text-foreground`,children:t.value})}),e(z,{className:`flex-col items-stretch gap-2 sm:flex-row sm:items-center sm:justify-between`,children:[r(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`secrets.revealDialog.recorded`,{seconds:u})}),e(`div`,{className:`flex justify-end gap-2`,children:[r(be,{value:t.value,label:o(`common.copy`,`Copy`),srLabel:`revealed value`}),r(L,{size:`sm`,variant:`outline`,onClick:n,children:o(`secrets.revealDialog.hide`,`Hide`)})]})]})]})})})}var ar={orphan:{labelKey:`secrets.secretsTableState.usageOrphan`,variant:`warning`,hintKey:`secrets.secretsTableState.usageOrphanHint`,rank:0},unknown:{labelKey:`secrets.secretsTableState.usageUnknown`,variant:`default`,hintKey:`secrets.secretsTableState.usageUnknownHint`,rank:1},"in-use":{labelKey:`secrets.secretsTableState.usageInUse`,variant:`success`,hintKey:`secrets.secretsTableState.usageInUseHint`,rank:2}},or=[{id:`all`,labelKey:`common.all`},{id:`in-use`,labelKey:`secrets.secretsTableState.usageInUse`},{id:`orphan`,labelKey:`secrets.secretsTableState.filterOrphans`},{id:`unknown`,labelKey:`secrets.secretsTableState.usageUnknown`}],sr=`system`;function cr(t){let{t:n}=Y(),{secrets:i,filter:a,onFilterChange:o,onDeleteOrphans:s,deleting:c,locked:l}=t;if(i===void 0)return r(`p`,{className:`text-xs text-foreground-subtle`,children:n(`common.loading`,`Loading…`)});let u=e=>e===`all`?i.length:i.filter(t=>t.usage===e).length,d=i.filter(e=>e.usage===`orphan`).map(e=>e.ref),f=a===`all`?i:i.filter(e=>e.usage===a);return e(`div`,{className:`space-y-2`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[r(`div`,{className:`flex flex-wrap gap-1`,role:`group`,"aria-label":n(`secrets.secretsTable.filterByUsage`,`Filter by usage`),children:or.map(t=>e(L,{size:`sm`,variant:a===t.id?`secondary`:`ghost`,"aria-pressed":a===t.id,className:a===t.id?`ring-1 ring-border`:void 0,onClick:()=>o(t.id),children:[n(t.labelKey),r(`span`,{className:`text-foreground-subtle tabular-nums`,children:u(t.id)})]},t.id))}),d.length>0&&e(L,{size:`sm`,variant:`outline`,className:`ml-auto`,disabled:c||l,onClick:()=>s(d),children:[r(I,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),n(`secrets.secretsTableState.deleteOrphans`,{count:d.length})]})]}),r(B,{columns:ur(t),rows:f,rowKey:e=>e.ref,minWidthPx:860,maxBodyHeight:Se,defaultSort:{columnKey:`owner`,dir:`asc`},emptyMessage:i.length===0?n(`secrets.secretsTable.noValueIsStoredIn`,`No value is stored in the keychain yet.`):n(`secrets.secretsTable.noStoredValueMatchesThis`,`No stored value matches this filter.`)})]})}function lr({owner:t}){let{t:n}=Y();return e(`span`,{className:`flex items-center gap-2`,children:[r(_t,{addonId:t,fallback:t===sr?ee:O,tileClassName:`bg-surface-hover text-foreground-subtle`,size:`sm`}),r(`span`,{className:`font-medium`,children:t===sr?n(`secrets.secretsTable.hubSystem`,`Hub (system)`):t})]})}function ur({locked:t,onReveal:n,revealing:i}){return[{key:`owner`,header:J.t(`secrets.secretsTable.owner`,`Owner`),render:e=>r(lr,{owner:e.owner}),sortValue:e=>e.owner},{key:`scope`,header:J.t(`secrets.secretsTable.scope`,`Scope`),render:e=>r(`span`,{className:`block max-w-[11rem] truncate font-mono`,title:e.scope,children:e.scope}),sortValue:e=>e.scope},{key:`field`,header:J.t(`secrets.secretsTable.field`,`Field`),render:e=>r(Hn,{value:e.fieldPath,copyValue:e.ref,srLabel:`secret ref`,maxWidthClass:`max-w-[16rem]`}),sortValue:e=>e.fieldPath},{key:`updated`,header:J.t(`secrets.secretsTable.updated`,`Updated`),render:e=>Vn(e.updatedAt),sortValue:e=>e.updatedAt},{key:`last-read`,header:J.t(`secrets.secretsTable.lastRead`,`Last read`),render:e=>Vn(e.lastReadAt),sortValue:e=>e.lastReadAt},{key:`status`,header:J.t(`secrets.secretsTable.status`,`Status`),render:e=>r(K,{variant:ar[e.usage].variant,title:J.t(ar[e.usage].hintKey),children:J.t(ar[e.usage].labelKey)}),sortValue:e=>ar[e.usage].rank},{key:`actions`,header:``,align:`right`,notSortableReason:`Actions`,render:a=>e(L,{size:`sm`,variant:`ghost`,disabled:t||i,"aria-label":J.t(`secrets.secretsTable.reveal`,`Reveal {{fieldPath}}`,{fieldPath:a.fieldPath}),title:t?J.t(`secrets.secretsTable.theKeychainIsLocked`,`The keychain is locked`):J.t(`secrets.secretsTable.revealAudited`,`Reveal (audited)`),onClick:()=>n(a),children:[r(A,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),J.t(`secrets.secretsTable.reveal2`,`Reveal`)]})}]}function dr(e){return e instanceof Error?e.message:String(e)}function fr(e){let{t}=Y(),n=D(),r=N(),i=ae(),a=et(),o=at(),s=Qe(),c=nt(),l=it(),u=Xe(),d=async(t,n)=>{try{await n()}catch(e){await r({title:t,message:dr(e),variant:`danger`})}e()};return{busy:a.isPending||o.isPending||s.isPending||c.isPending,deleting:u.isPending,download:async()=>{await n({title:t(`secrets.useKeychainActions.downloadTitle`),message:t(`secrets.useKeychainActions.downloadMessage`),confirmLabel:t(`secrets.useKeychainActions.downloadConfirm`),variant:`warning`})&&await d(t(`secrets.useKeychainActions.downloadRefused`),async()=>{let e=await a.mutateAsync({});await i({title:t(`secrets.useKeychainActions.recoveryTitle`,{fingerprint:e.fingerprint}),message:t(`secrets.useKeychainActions.recoveryMessage`),defaultValue:e.key,readOnly:!0,confirmLabel:t(`secrets.useKeychainActions.recoveryDone`)})})},rotate:async()=>{await n({title:t(`secrets.useKeychainActions.rotateTitle`),message:t(`secrets.useKeychainActions.rotateMessage`),confirmLabel:t(`secrets.useKeychainActions.rotateConfirm`),variant:`warning`})&&await d(t(`secrets.useKeychainActions.rotateRefused`),async()=>{let e=await o.mutateAsync({});await r({title:t(`secrets.useKeychainActions.rotatedTitle`),message:t(`secrets.useKeychainActions.rotatedMessage`,{fingerprint:e.fingerprint})})})},purge:async()=>{await n({title:t(`secrets.useKeychainActions.purgeTitle`),message:t(`secrets.useKeychainActions.purgeMessage`),confirmLabel:t(`secrets.useKeychainActions.purgeConfirm`),variant:`warning`})&&await d(t(`secrets.useKeychainActions.purgeRefused`),async()=>{await s.mutateAsync({})})},reset:async()=>{await i({title:t(`secrets.useKeychainActions.resetTitle`),message:t(`secrets.useKeychainActions.resetMessage`,{confirmation:`RESET KEYCHAIN`}),confirmLabel:t(`secrets.useKeychainActions.resetConfirm`),validate:e=>e===`RESET KEYCHAIN`?null:t(`secrets.useKeychainActions.resetMismatch`)})===`RESET KEYCHAIN`&&await d(t(`secrets.useKeychainActions.resetRefused`),async()=>{await c.mutateAsync({confirm:se})})},acknowledgeReset:async()=>{await d(t(`secrets.useKeychainActions.dismissFailed`),async()=>{await l.mutateAsync({})})},deleteOrphans:async e=>{await n({title:t(`secrets.useKeychainActions.orphansTitle`,{count:e.length}),message:t(`secrets.useKeychainActions.orphansMessage`),confirmLabel:t(`secrets.useKeychainActions.orphansConfirm`),variant:`danger`})&&await d(t(`secrets.useKeychainActions.orphansRefused`),async()=>{let n=await u.mutateAsync({refs:[...e]});n.kept.length>0&&await r({title:t(`secrets.useKeychainActions.keptTitle`),message:t(`secrets.useKeychainActions.keptMessage`,{deleted:n.deleted.length,kept:n.kept.length})})})}}}o();var pr=`secretsView`;function mr(){let[e,t]=mt();return[e.get(pr)===`audit`?`audit`:`values`,n=>{let r=new URLSearchParams(e);n===`values`?r.delete(pr):r.set(pr,n),t(r,{replace:!0})}]}function hr(){let{t:i}=Y(),o=Be({}),s=Ie({}),c=We({limit:500}),l=Le({}),u=Je(),d=N(),[f,p]=mr(),[m,h]=a(`all`),[g,_]=a(null),v=fr(()=>{o.refetch(),s.refetch(),c.refetch(),l.refetch()}),y=o.data?.keychain.state===`locked`,b=t(()=>(s.data??[]).filter(e=>e.usage===`orphan`).length,[s.data]),x=t(()=>o.data===void 0?[]:zn({status:o.data,reset:l.data?.reset??null,pendingReentry:l.data?.pendingReentry.length??0,orphans:b}),[o.data,l.data,b]),S={reset:l.data?.reset??null,pendingReentry:l.data?.pendingReentry??[],busy:v.busy,onReset:()=>void v.reset(),onAcknowledgeReset:()=>void v.acknowledgeReset(),onDownload:()=>void v.download(),onRotate:()=>void v.rotate(),onShowOrphans:()=>{h(`orphan`),p(`values`)}},C=async e=>{try{_({entry:e,value:(await u.mutateAsync({ref:e.ref})).value}),s.refetch()}catch(e){await d({title:i(`admin.system.secrets.revealRefused`,`Reveal refused`),message:dt(e),variant:`danger`})}},w=n(()=>_(null),[]);return e(ht,{embedded:!0,icon:ue,title:i(`admin.system.secrets.secrets`,`Secrets`),subtitle:i(`admin.system.secrets.passwordsTokensAndKeysEncrypted`,`Passwords, tokens and keys, encrypted in the hub keychain. Values leave the hub only through an audited reveal.`),children:[r(Zn,{notices:x,renderAction:e=>Kn(e,S),renderDetail:e=>qn(e,S)}),o.data!==void 0&&r(tr,{status:o.data,busy:v.busy,onDownload:S.onDownload,onRotate:S.onRotate,onPurge:()=>void v.purge()}),e(He,{value:f,onValueChange:e=>p(e===`audit`?`audit`:`values`),children:[e(Ye,{children:[r($e,{value:`values`,children:i(`admin.system.secrets.storedValues`,`Stored values`)}),r($e,{value:`audit`,children:i(`admin.system.secrets.audit`,`Audit`)})]}),r(rt,{value:`values`,children:r(cr,{secrets:s.data,locked:y,filter:m,onFilterChange:h,onReveal:e=>void C(e),revealing:u.isPending,onDeleteOrphans:e=>void v.deleteOrphans(e),deleting:v.deleting})}),r(rt,{value:`audit`,children:r(Gn,{entries:c.data})})]}),r(ir,{revealed:g,onClose:w})]})}o();function gr(e){return Object.entries(e).map(([e,t])=>`${e} ${t}`).join(` · `)}function _r(e){return e.reduce((e,t)=>e+Object.values(t.stores).reduce((e,t)=>e+t,0),0)}function vr(){let{t}=Y(),n=D(),i=_e(),[o,s]=a(null),[l,d]=a(null),f=async e=>{d(null);try{s(await i.mutateAsync({confirm:e}))}catch(e){d(e instanceof Error?e.message:String(e))}},p=async()=>{o===null||o.status!==`dry-run`||await n({title:t(`systemPage.deletedDevices.confirmTitle`,`Delete the data of deleted devices?`),message:o.devices.map(e=>`#${e.deviceId}: ${gr(e.stores)}`).join(`
2
- `),confirmLabel:t(`systemPage.deletedDevices.confirmLabel`,`Delete`),variant:`danger`})&&await f(!0)},m=[{key:`device`,header:t(`systemPage.deletedDevices.device`,`Device`),render:e=>`#${e.deviceId}`},{key:`stores`,header:t(`systemPage.deletedDevices.stores`,`Data held`),nowrap:!1,render:e=>gr(e.stores)}];return e(`div`,{className:`space-y-4`,"data-testid":`deleted-devices-data`,children:[r(`p`,{className:`text-sm text-foreground-muted`,children:t(`systemPage.deletedDevices.intro`,`Data that still belongs to devices that were deleted before deletions were recorded: footage, events, history and per-addon settings. Scanning deletes nothing; deleting asks first and shows what goes.`)}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(L,{variant:`outline`,onClick:()=>void f(!1),disabled:i.isPending,"data-testid":`deleted-devices-scan`,children:[i.isPending?r(y,{className:`mr-2 h-4 w-4 animate-spin`}):r(u,{className:`mr-2 h-4 w-4`}),t(`systemPage.deletedDevices.scan`,`Scan`)]}),o?.status===`dry-run`&&o.devices.length>0?e(L,{variant:`danger`,onClick:()=>void p(),disabled:i.isPending,"data-testid":`deleted-devices-delete`,children:[r(I,{className:`mr-2 h-4 w-4`}),t(`systemPage.deletedDevices.delete`,`Delete the data of {{count}} devices…`,{count:o.devices.length})]}):null]}),l===null?null:r(`p`,{className:`text-sm text-danger`,children:l}),o?.status===`skipped`?r(`p`,{className:`text-sm text-warning`,"data-testid":`deleted-devices-skipped`,children:t(`systemPage.deletedDevices.skipped`,`Nothing was listed or deleted: the device list could not be trusted ({{reason}}). Try again.`,{reason:o.reason??``})}):null,o!==null&&o.status!==`skipped`?e(c,{children:[r(`p`,{className:`text-sm`,"data-testid":`deleted-devices-summary`,children:o.status===`cleaned`?t(`systemPage.deletedDevices.cleaned`,`Deleted {{rows}} items of {{count}} devices.`,{rows:_r(o.devices),count:o.devices.length}):t(`systemPage.deletedDevices.found`,`{{count}} deleted devices still hold {{rows}} items.`,{rows:_r(o.devices),count:o.devices.length})}),r(B,{columns:m,rows:o.devices,rowKey:e=>e.deviceId,emptyMessage:t(`systemPage.deletedDevices.none`,`No data belongs to a deleted device.`)}),o.unreachable.length>0?r(`p`,{className:`text-xs text-foreground-muted`,children:t(`systemPage.deletedDevices.unreachable`,`Not asked (unreachable): {{names}}`,{names:o.unreachable.join(`, `)})}):null]}):null]})}var yr=`view`,br=`kinds`,xr=`deleted-devices`;function Sr(){let{t}=Y(),[n,i]=mt(),a=n.get(`view`)===`deleted-devices`?xr:br;return e(`div`,{className:d,children:[e(`div`,{className:`mb-3 space-y-2`,children:[r(He,{appearance:`pills`,value:a,onValueChange:e=>{i(t=>{let n=new URLSearchParams(t);return e===`kinds`?n.delete(yr):n.set(yr,e),n},{replace:!0})},children:e(Ye,{className:`flex flex-wrap gap-1`,children:[r($e,{value:br,children:t(`systemPage.data.viewKinds`,`Record kinds`)}),r($e,{value:xr,children:t(`systemPage.data.viewDeletedDevices`,`Deleted devices`)})]})}),a===`kinds`?r(`p`,{className:`text-xs text-foreground-muted`,children:t(`systemPage.data.recordsUnifiedIntro`,`Every declared record kind on this hub. Entry kinds can be added, edited and deleted; the rest are read-only. Secret fields are redacted.`)}):null]}),r(a===`kinds`?he:vr,{})]})}var Cr={applied:`success`,failed:`danger`,blocked:`warning`,held:`warning`,running:`info`,pending:`default`,"skipped-newer":`neutral`},wr={applied:`migrations.status.applied`,failed:`migrations.status.failed`,blocked:`migrations.status.blocked`,held:`migrations.status.held`,running:`migrations.status.running`,pending:`migrations.status.pending`,"skipped-newer":`migrations.status.skippedNewer`};function Tr({status:e}){let{t}=Y();return r(K,{variant:Cr[e],className:`text-[10px]`,children:t(wr[e])})}var Er=[`failed`,`blocked`,`held`,`running`,`pending`,`applied`,`skipped-newer`];function Dr(e){return Er.indexOf(e)}function Or(e,t){let n=new Map(t.map(e=>[e.meta.id,e])),r=new Map;for(let t of e){let e=n.get(t.id)??null;r.set(t.id,{id:t.id,owner:t.owner,status:t.status,meta:t.meta??e?.meta??null,ledger:t,pending:e,database:t.database,seq:t.seq,appliedAt:t.appliedAt,reason:t.reason??e?.reason??null,error:t.error})}for(let e of t)r.has(e.meta.id)||r.set(e.meta.id,{id:e.meta.id,owner:e.meta.owner,status:e.state===`pending`?`pending`:e.state,meta:e.meta,ledger:null,pending:e,database:e.database,seq:e.meta.seq,appliedAt:null,reason:e.reason,error:null});return[...r.values()]}function kr(e){return e.owner===`hub`&&e.meta!==null&&e.meta.bodyKind!==`procedure`}o();var Ar={searchText:e=>[e.id,e.owner,e.meta?.description??``],facetGroups:[{id:`owner`,value:e=>e.owner},{id:`status`,value:e=>e.status}]};function jr(e){if(e===null)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function Mr({rows:n,onOpen:i}){let{t:a}=Y(),o=ct(n,Ar),s=t(()=>[{key:`id`,header:a(`migrations.col.id`,`Migration`),sortValue:e=>e.id,render:t=>e(`div`,{className:`min-w-0 max-w-[22rem]`,children:[r(`div`,{className:`truncate font-mono text-xs text-foreground`,title:t.id,children:t.id}),t.meta!==null&&r(`div`,{className:`truncate text-[10px] text-foreground-subtle`,title:t.meta.description,children:t.meta.description})]})},{key:`owner`,header:a(`migrations.col.owner`,`Owner`),sortValue:e=>e.owner,render:e=>e.owner},{key:`status`,header:a(`migrations.col.status`,`Status`),sortValue:e=>Dr(e.status),render:e=>r(Tr,{status:e.status})},{key:`level`,header:a(`migrations.col.level`,`Level`),sortValue:e=>e.meta?.level??null,render:e=>e.meta?.level??`—`},{key:`body`,header:a(`migrations.col.body`,`Body`),sortValue:e=>e.meta?.bodyKind??null,render:e=>e.meta?.bodyKind??`—`},{key:`applied`,header:a(`migrations.col.applied`,`Applied`),sortValue:e=>e.appliedAt,render:e=>r(`span`,{className:`text-foreground-subtle`,children:jr(e.appliedAt)})}],[a]),c=a(`migrations.label`,`migrations`);return e(`div`,{className:`space-y-3`,children:[r(Ne,{state:o.state,facets:o.facets,groups:o.groups.map(e=>({...e,label:e.id===`owner`?a(`migrations.col.owner`):a(`migrations.col.status`),...e.id===`status`?{facetLabel:e=>a(wr[e])}:{}})),labels:{searchPlaceholder:a(`migrations.searchPlaceholder`,`Search migrations`),searchLabel:a(`migrations.searchLabel`,`Search migrations`),facetsLabel:a(`migrations.facetsLabel`,`Filter migrations`),clearLabel:a(`migrations.clearFilters`,`Clear filters`)},onSearch:o.setSearch,onToggleFacet:o.toggleFacet,onToggleGroupFacet:o.toggleGroupFacet,onClear:o.clear}),r(B,{columns:s,rows:o.rows,rowKey:e=>e.id,minWidthPx:820,maxBodyHeight:Se,defaultSort:{columnKey:`status`,dir:`asc`},pageSize:25,onRowClick:e=>i(e.id),paginationLabels:{navLabel:a(`migrations.pagesLabel`,`Migration pages`),previous:a(`migrations.previousPage`,`Previous`),next:a(`migrations.nextPage`,`Next`),range:(e,t,n)=>a(`migrations.range`,`{{from}}–{{to}} of {{total}}`,{from:e,to:t,total:n})},emptyMessage:o.active?a(`migrations.noMatch`,`No {{label}} match the filters.`,{label:c}):a(`migrations.empty`,`No migrations.`)})]})}function $({label:t,children:n}){return e(`div`,{className:`grid gap-0.5 py-1.5 sm:grid-cols-[10rem_1fr] sm:gap-3`,children:[r(`dt`,{className:`text-xs text-foreground-muted`,children:t}),r(`dd`,{className:`min-w-0 break-words text-sm text-foreground`,children:n})]})}function Nr({value:e}){return e===null?r(`span`,{className:`text-foreground-subtle`,children:`—`}):r(`pre`,{className:`max-h-40 overflow-auto rounded-md bg-surface p-2 font-mono text-xs text-foreground`,children:JSON.stringify(e,null,2)})}function Pr({id:t}){let{t:n}=Y(),i=Te.migrations.dryRun.useQuery({id:t},{enabled:!1});return e(`div`,{className:`space-y-2`,children:[e(L,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>void i.refetch(),disabled:i.isFetching,children:[i.isFetching&&r(y,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}),n(`migrations.detail.dryRun`,`Run a dry run`)]}),r(`p`,{className:`text-xs text-foreground-muted`,children:n(`migrations.detail.dryRunHint`,`Runs the migration in a transaction and rolls it back. Nothing is written.`)}),i.isError&&r(Fe,{title:n(`migrations.detail.dryRunFailed`,`The dry run could not run`),message:i.error.message}),i.data!==void 0&&e(`div`,{className:`space-y-1 text-xs`,"data-testid":`dry-run-result`,children:[r(`div`,{className:`text-foreground`,children:i.data.ok?n(`migrations.detail.dryRunOk`,`Would change {{count}} rows`,{count:i.data.rowsChanged}):i.data.error??n(`migrations.detail.dryRunThrows`,`It would fail`)}),i.data.tables.map(t=>e(`div`,{className:`font-mono text-foreground-muted`,children:[t.table,`: `,t.before,` → `,t.after]},t.table))]})]})}function Fr({row:t,knownIds:n,onOpenRow:i,onClose:a}){let{t:o}=Y(),s=r(`span`,{className:`text-foreground-subtle`,children:`—`}),l=t?.meta??null,u=t?.ledger??null;return r(V,{open:t!==null,onOpenChange:e=>!e&&a(),children:r(R,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:t!==null&&e(c,{children:[e(H,{children:[r(U,{className:`break-all font-mono text-base`,children:t.id}),r(Pe,{children:l?.description??o(`migrations.detail.noMeta`,`No catalogue on this hub lists this migration.`)})]}),e(q,{children:[e(`dl`,{className:`divide-y divide-border-subtle`,children:[r($,{label:o(`migrations.col.status`,`Status`),children:r(Tr,{status:t.status})}),t.error!==null&&r($,{label:o(`migrations.detail.error`,`Error`),children:r(`span`,{className:`text-danger`,"data-testid":`migration-error`,children:t.error})}),t.reason!==null&&r($,{label:o(`migrations.detail.reason`,`Reason`),children:t.reason}),r($,{label:o(`migrations.col.owner`,`Owner`),children:t.owner}),r($,{label:o(`migrations.col.level`,`Level`),children:l?.level??s}),r($,{label:o(`migrations.col.body`,`Body`),children:l?.bodyKind??s}),e($,{label:o(`migrations.detail.store`,`Store`),children:[l?.store??s,` · `,t.database]}),r($,{label:o(`migrations.detail.scope`,`Scope`),children:l?.scope??s}),r($,{label:o(`migrations.detail.onFailure`,`On failure`),children:l?.onFailure??s}),r($,{label:o(`migrations.detail.seq`,`Sequence in owner`),children:t.seq}),r($,{label:o(`migrations.detail.fixtureMark`,`Fixture mark`),children:l?.fixtureMark??s}),r($,{label:o(`migrations.detail.dependsOn`,`Depends on`),children:l===null||l.dependsOn.length===0?s:r(`div`,{className:`flex flex-wrap gap-1.5`,children:l.dependsOn.map(e=>n.has(e)?r(L,{type:`button`,variant:`outline`,size:`sm`,className:`font-mono text-xs`,onClick:()=>i(e),children:e},e):r(K,{variant:`neutral`,className:`font-mono text-xs`,children:e},e))})}),r($,{label:o(`migrations.col.applied`,`Applied`),children:jr(t.appliedAt)}),r($,{label:o(`migrations.detail.attempts`,`Attempts`),children:u?.attempts??s}),r($,{label:o(`migrations.detail.codeVersion`,`Code version`),children:u?.codeVersion??s}),r($,{label:o(`migrations.detail.node`,`Node`),children:u?.nodeId??s}),r($,{label:o(`migrations.detail.boot`,`Boot (snapshot id prefix)`),children:r(`span`,{className:`font-mono text-xs`,children:u?.bootId??s})}),r($,{label:o(`migrations.detail.planSummary`,`Rows changed`),children:r(Nr,{value:u?.planSummary??null})}),r($,{label:o(`migrations.detail.progress`,`Progress`),children:r(Nr,{value:u?.progress??null})})]}),kr(t)&&r(Pr,{id:t.id},t.id)]}),r(z,{children:r(L,{type:`button`,variant:`outline`,onClick:a,children:o(`migrations.detail.close`,`Close`)})})]})})})}o();var Ir=`migration`;function Lr(){let{t:n}=Y(),i=Ke(`migrations`),a=i===`present`,o=Te.migrations.listLedger.useQuery({},{enabled:a}),s=Te.migrations.listPending.useQuery({},{enabled:a}),[c,l]=mt(),u=c.get(Ir),f=t(()=>o.data===void 0||s.data===void 0?null:Or(o.data.entries,s.data.pending),[o.data,s.data]),p=t(()=>new Set((f??[]).map(e=>e.id)),[f]),m=f?.find(e=>e.id===u)??null,h=e=>l(t=>{let n=new URLSearchParams(t);return e===null?n.delete(Ir):n.set(Ir,e),n},{replace:!0}),g;return g=i===`pending`?r(Rr,{label:n(`migrations.loading`,`Loading migrations…`)}):i===`unknown`?r(Fe,{title:n(`migrations.unknownTitle`,`Could not check the migration ledger`),message:n(`migrations.unknownBody`,`The hub did not answer. Try again in a moment.`)}):i===`absent`?r(Ve,{icon:pe,title:n(`migrations.absentTitle`,`No migration ledger on this hub`),description:n(`migrations.absentBody`,`Nothing on this hub provides the migrations capability.`)}):o.isError||s.isError?r(Fe,{title:n(`migrations.loadFailed`,`Could not load the migrations`),message:(o.error??s.error)?.message??``}):f===null?r(Rr,{label:n(`migrations.loading`,`Loading migrations…`)}):f.length===0?r(Ve,{icon:pe,title:n(`migrations.empty`,`No migrations.`),description:n(`migrations.emptyBody`,`The ledger and the catalogues are both empty.`)}):r(Mr,{rows:f,onOpen:h}),e(`div`,{className:d,children:[r(`p`,{className:`mb-3 text-xs text-foreground-muted`,children:n(`migrations.intro`,`Every data migration this hub knows: what ran, what is waiting and what failed. Read-only.`)}),g,r(Fr,{row:m,knownIds:p,onOpenRow:h,onClose:()=>h(null)})]})}function Rr({label:t}){return e(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,role:`status`,children:[r(y,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),t]})}var zr={entries:null,"deleted-devices":`deleted-devices`};function Br(){let{t:e}=Y(),t=pt(`/system/data`,{t:e,isAdmin:!0})??{icon:f,title:e(`system.data`,`Data`)},[n]=mt(),i=zr[n.get(`tab`)??``];if(i!==void 0){let e=new URLSearchParams(n);return e.set(`tab`,`records`),i!==null&&e.set(`view`,i),r(ut,{replace:!0,to:{search:e.toString()}})}return r(yt,{icon:t.icon,title:t.title,defaultSection:`storage`,sectionsLabel:`${t.title} sections`,sections:[{id:`storage`,label:e(`systemPage.data.storage`,`Storage`),content:r(bt,{})},{id:`records`,label:e(`systemPage.data.records`,`Records`),content:r(Sr,{}),ownedParams:[`view`,`recordsOwner`,`recordsKind`,`entryNew`,`entryEdit`]},{id:`backup`,label:e(`systemPage.data.backup`,`Backup`),content:r(Fn,{})},{id:`secrets`,label:e(`systemPage.data.secrets`,`Secrets`),content:r(hr,{}),ownedParams:[`secretsView`]},{id:`migrations`,label:e(`systemPage.data.migrations`,`Migrations`),content:r(Lr,{}),ownedParams:[`migration`]}]})}export{Br as DataPage};
@@ -1 +0,0 @@
1
- import{C as e,K as t,S as n,Y as r,et as i,i as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Lr as s,Tt as c,Un as l,Xr as u,Yn as d,ct as f,eo as p,ia as m,tn as h,ut as g,yt as _}from"./player-overlays-BF9w4QU-.js";import{Rs as v,si as y}from"./client-DhfZUoXe.js";import{$f as b,Bi as x,Cn as S,En as C,Fr as w,Hi as T,Ma as E,Mp as D,Mr as O,Oa as k,Pr as A,Qi as j,Ri as ee,Sn as M,Ta as N,Tn as te,Tr as ne,Ui as re,Wi as ie,Zd as ae,_a as P,ba as F,bn as oe,ea as I,fn as L,fs as se,gn as ce,hn as le,in as ue,jp as de,ln as fe,mn as pe,nn as me,on as he,pn as R,ps as ge,rn as _e,sn as ve,un as ye,vn as be,wn as z,wr as xe,xn as Se,ya as B,yn as Ce,zi as we,zs as V}from"./src-D9hgltMI.js";import{t as H}from"./useTranslation-BJr-n0es.js";import{yi as Te}from"./index-DPyWa2vo.js";import{t as Ee}from"./AdminPage-z8USGyNk.js";i();function U(e,t){return e.scope===``?e.displayName:`${e.displayName} · ${t?.(e)??e.scope}`}function De(e,t,n){let r=[];for(let{device:t,series:i}of e)for(let e of i){let i={subject:{kind:`device`,deviceId:t.id},key:e.key,scope:e.scope};r.push({id:R(i),ref:i,info:e,subjectName:t.name,location:t.location??``,nodeId:``,metric:U(e,n)})}for(let{node:e,series:i}of t)for(let t of i){let i={subject:{kind:`node`,nodeId:e.id},key:t.key,scope:t.scope};r.push({id:R(i),ref:i,info:t,subjectName:e.name,location:``,nodeId:e.id,metric:U(t,n)})}return r}function Oe(e){return[e.subjectName,e.location,e.metric,e.info.key,e.info.unit??``,e.nodeId].join(` `)}function W(e,t,n){if(e.ref.subject.kind!==`device`||t===null)return e.subjectName;let r=t.byId.get(e.ref.subject.deviceId);return r===void 0?e.subjectName:N(r,`compact`,t,n)}var ke=[`energy`,`temperatures`,`nodes`,`storage`],Ae=new Set([`cap:temperature-sensor.temperature`,`cap:climate-control.currentTemp`]),G=[`addon:metrics-native/node-cpu-percent`,`addon:metrics-native/node-memory-percent`],je=`addon:storage-orchestrator/location-used-percent`;function Me(e,t){let n=(e,n)=>{let r=t.filter(e);return L((n?[...r].sort(n):r).map(e=>e.ref))};switch(e){case`energy`:return n(e=>e.ref.subject.kind===`device`&&e.info.key===`derived:energy.kwh`);case`temperatures`:return n(e=>e.ref.subject.kind===`device`&&Ae.has(e.info.key)&&e.info.scope===``,(e,t)=>e.location.localeCompare(t.location)||e.subjectName.localeCompare(t.subjectName));case`nodes`:return n(e=>e.ref.subject.kind===`node`&&G.includes(e.info.key)&&e.info.scope===``,(e,t)=>G.indexOf(e.info.key)-G.indexOf(t.info.key)||e.subjectName.localeCompare(t.subjectName));case`storage`:return n(e=>e.ref.subject.kind===`node`&&e.info.key===je)}}function Ne(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[],i=[],a=[],o=[];for(let t of L(e)){let e=n.get(R(t));if(e===void 0){o.push(t);continue}e.info.key===`derived:energy.kwh`?a.push(e):e.info.kind===`boolean`||e.info.kind===`enum`?i.push(e):r.push(e)}return{lines:r,states:i,energy:a,missing:o}}function K(e){return e.subject.kind===`device`?{deviceId:e.subject.deviceId,key:e.key,scope:e.scope}:{forNodeId:e.subject.nodeId,key:e.key,scope:e.scope}}var q=`history-page`;function Pe({part:r,window:i}){let{t:a}=H(),o=p(),s=E(),c=k(),l=e=>`${W(e,s,c)} · ${e.metric}`,u=t(()=>[...r.lines,...r.states,...r.energy],[r]),d=he(t(()=>u.map(e=>K(e.ref)),[u]),i,!1),f=e=>d.status===`ok`?d.data.current.get(ue(K(e.ref))):void 0,h=e=>{let t=f(e);return t?.ok?t.result:void 0};if(u.length===0)return n(I,{icon:m,title:a(`history.page.emptyTitle`,`Pick series to compare`),description:a(`history.page.emptyHint`,`Choose up to 24 series on the left, or start from a panel above.`)});if(d.status===`error`)return n(P,{title:a(`history.page.readFailed`,`History could not be read`),message:d.error});let g=d.status===`pending`,_=u.map(e=>({c:e,e:f(e)})).filter(e=>e.e?.ok===!1),v=r.lines.map((e,t)=>{let n=h(e),r=Ce(e.info,n,i.from);return{id:e.id,label:l(e),unit:e.info.unit,colorIndex:t,points:r.points,gapMs:r.gapMs,interpolation:r.held&&n?.resolution===`raw`?`step`:`linear`}}),y=r.states.map((e,t)=>{let n=oe(e.info,h(e),i.from,i.to),r=ce(e.info.key,o);return{id:e.id,label:l(e),kind:e.info.kind===`boolean`?`boolean`:`enum`,colorIndex:e.info.kind===`boolean`?t:0,states:n.states,segments:n.segments,totals:n.totals,stateLabel:e.info.kind===`boolean`?e=>e===`true`?r.on:r.off:void 0}}),b=r.energy.map(e=>({c:e,...be(h(e))})),x=b[0]?.bucketMs??36e5,S=[...new Set(b.flatMap(e=>e.buckets.map(e=>e.t)))].sort((e,t)=>e-t).map(e=>({t:e,values:b.map(t=>t.buckets.find(t=>t.t===e)?.values[0]??null)}));return e(`div`,{className:`space-y-5 min-w-0`,children:[_.length>0&&n(P,{title:a(`history.page.someFailed`,`Some series could not be read`),message:_.map(e=>`${l(e.c)}: ${e.e.error}`).join(` · `)}),v.length>0&&n(te,{title:a(`history.page.lines`,`Measurements`),series:v,range:i,height:260,syncKey:q,pending:g}),b.length>0&&n(j,{title:a(`history.page.energy`,`Energy`),layers:b.map((e,t)=>({id:e.c.id,label:W(e.c,s,c),colorIndex:t})),buckets:S,bucketMs:x,range:i,unit:`kWh`,showTotal:!0,height:160,syncKey:q,pending:g}),y.length>0&&n(C,{title:y.length===1?y[0]?.label??``:a(`history.page.states`,`States`),rows:y,range:i,syncKey:q,pending:g})]})}function Fe(e,t){let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}async function Ie(e,t){let n=[];for(let r of Fe(e,50))try{let{results:e}=await t(r),i=new Map(e.map(e=>[e.seriesId,e]));for(let e of r)n.push(i.get(e)??{seriesId:e,ok:!1,reason:`not-found`})}catch(e){let t=e instanceof Error?e.message:String(e);for(let e of r)n.push({seriesId:e,ok:!1,reason:`request-failed`,message:t})}return n}function J(e){return e.raw+e[`5m`]+e[`1h`]+e[`1d`]}function Le(e){return e.reduce((e,t)=>t.ok?{...e,deleted:e.deleted+1,points:e.points+J(t.deleted)}:{...e,refused:e.refused+1},{deleted:0,refused:0,points:0})}function Re(e,t){let n=new Map(e.map(e=>[e.seriesId,e]));return t.flatMap(e=>{let t=n.get(e.seriesId);return t===void 0?[]:[{series:t,outcome:e}]})}var Y=e=>new Date(e).toLocaleDateString(void 0,{dateStyle:`short`});function X(e,t,n){let r=t.get(e.deviceId);return r===void 0?e.reason===`device-gone`?n(`history.orphans.deviceRemoved`,`#{{id}} (removed)`,{id:e.deviceId}):n(`history.orphans.deviceId`,`#{{id}}`,{id:e.deviceId}):r}function Z(e){let t=e.displayName??e.key;return e.scope===``?t:`${t} · ${e.scope}`}function Q(t,r,i){return{key:`series`,header:i(`history.orphans.colSeries`,`Series`),render:a=>{let o=t(a);return e(`div`,{className:`min-w-0 max-w-[16rem]`,children:[n(`div`,{className:`truncate text-foreground`,title:o.key,children:Z(o)}),n(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:X(o,r,i)})]})},sortValue:e=>`${X(t(e),r,i)} ${Z(t(e))}`}}var ze=[`raw`,`5m`,`1h`,`1d`];function Be(e,t){return e===`raw`?t(`history.orphans.colRaw`,`Raw points`):e===`5m`?t(`history.orphans.col5m`,`5 min`):e===`1h`?t(`history.orphans.col1h`,`1 h`):t(`history.orphans.col1d`,`1 day`)}function Ve(t,r){return[Q(e=>e,t,r),{key:`reason`,header:r(`history.orphans.colReason`,`Reason`),render:t=>e(`div`,{className:`flex flex-col items-start gap-0.5`,children:[n(B,{variant:t.reason===`device-gone`?`warning`:`neutral`,className:`text-[10px]`,children:t.reason===`device-gone`?r(`history.orphans.deviceGone`,`Device removed`):r(`history.orphans.undeclared`,`No longer declared`)}),t.missingSince!==null&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:r(`history.orphans.since`,`since {{date}}`,{date:Y(t.missingSince)})})]}),sortValue:e=>e.reason},{key:`span`,header:r(`history.orphans.colSpan`,`Recorded`),render:t=>e(`span`,{className:`tabular-nums text-foreground-muted`,children:[Y(t.firstTs),` → `,Y(t.lastTs)]}),sortValue:e=>e.lastTs},...ze.map(e=>({key:`rows-${e}`,header:Be(e,r),align:`right`,render:t=>n(`span`,{className:`tabular-nums text-foreground-muted`,children:t.rows[e].toLocaleString()}),sortValue:t=>t.rows[e]}))]}function He(e,t){if(e.ok)return n(B,{variant:`success`,className:`text-[10px]`,children:t(`history.orphans.deleted`,{count:J(e.deleted),points:J(e.deleted).toLocaleString(),defaultValue_one:`Deleted · {{points}} point`,defaultValue_other:`Deleted · {{points}} points`})});let r=e.reason===`request-failed`?t(`history.orphans.requestFailed`,`Not sent: {{message}}`,{message:e.message}):e.reason===`not-orphan`?t(`history.orphans.refusedNotOrphan`,`Kept: no longer orphan`):e.reason===`not-found`?t(`history.orphans.refusedNotFound`,`Already gone`):t(`history.orphans.refusedFailed`,`The hub could not delete it`);return n(B,{variant:e.reason===`not-found`?`neutral`:`warning`,className:`text-[10px]`,children:r})}function Ue(e,t){return[Q(e=>e.series,e,t),{key:`result`,header:t(`history.orphans.colResult`,`Result`),render:e=>He(e.outcome,t),sortValue:e=>+!e.outcome.ok}]}i();function We({open:i,onClose:a,list:o,deviceNames:c,onDelete:l,onRefresh:u,refreshing:p}){let{t:m}=H(),g=f(),[_,v]=r(new Set),[y,S]=r(!1),[C,E]=r([]),D=t(()=>Ve(c,m),[c,m]),O=t(()=>Ue(c,m),[c,m]),k=t(()=>new Set(o.series.map(e=>String(e.seriesId))),[o.series]),j=[..._].filter(e=>k.has(e)).map(Number),M=Le(C.map(e=>e.outcome)),N=async()=>{if(await g({title:m(`history.orphans.confirmTitle`,{count:j.length,defaultValue_one:`Delete {{count}} series`,defaultValue_other:`Delete {{count}} series`}),message:m(`history.orphans.confirmMessage`,`Every recorded point of these series is removed from the hub. This cannot be undone.`),confirmLabel:m(`history.orphans.confirmLabel`,`Delete`),variant:`danger`})){S(!0);try{let e=await Ie(j,l);E(Re(o.series,e)),v(new Set)}finally{S(!1),u()}}};return n(ee,{open:i,onOpenChange:e=>!e&&a(),children:e(x,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`orphan-series-dialog`,children:[n(re,{children:n(ie,{children:m(`history.orphans.title`,`Series no longer linked to a device`)})}),e(we,{className:`space-y-3`,children:[n(`p`,{className:`text-xs text-foreground-muted`,children:m(`history.orphans.intro`,`Nothing records into these series any more: their device was removed, or no capability declares them now. Select the ones to delete.`)}),o.truncated&&e(`div`,{className:`flex flex-wrap items-center gap-2`,"data-testid":`orphan-truncated`,children:[n(`p`,{className:`text-xs text-warning`,children:m(`history.orphans.truncated`,`More series are unlinked than are listed here. Delete these, then load the rest.`)}),e(b,{size:`sm`,variant:`outline`,onClick:u,disabled:p,children:[n(d,{className:`h-3 w-3`,"aria-hidden":!0}),m(`history.orphans.loadAgain`,`Load again`)]})]}),C.length>0&&e(`div`,{className:`space-y-2`,"data-testid":`orphan-outcomes`,children:[n(`p`,{className:`text-xs text-foreground`,"aria-live":`polite`,children:m(`history.orphans.summary`,{count:M.deleted,refused:M.refused,points:M.points.toLocaleString(),defaultValue_one:`{{count}} series deleted ({{points}} points), {{refused}} kept.`,defaultValue_other:`{{count}} series deleted ({{points}} points), {{refused}} kept.`})}),n(A,{columns:O,rows:C,rowKey:e=>String(e.series.seriesId),minWidthPx:420,maxBodyHeight:`max-h-[60vh]`,emptyMessage:``})]}),n(A,{columns:D,rows:o.series,rowKey:e=>String(e.seriesId),minWidthPx:760,maxBodyHeight:w,defaultSort:{columnKey:`series`,dir:`asc`},emptyMessage:m(`history.orphans.empty`,`Every series is linked to a device.`),selection:{selected:_,onChange:v,rowLabel:e=>`${Z(e)} — ${X(e,c,m)}`,pageLabel:m(`history.orphans.selectAll`,`Select every listed series`)}})]}),e(T,{children:[n(`span`,{className:`mr-auto text-[11px] tabular-nums text-foreground`,"aria-live":`polite`,children:m(`history.orphans.selected`,{count:j.length,defaultValue_one:`{{count}} selected`,defaultValue_other:`{{count}} selected`})}),n(b,{variant:`ghost`,size:`sm`,onClick:a,children:m(`history.orphans.close`,`Close`)}),e(b,{variant:`danger`,size:`sm`,disabled:j.length===0||y,onClick:()=>void N(),children:[y?n(s,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):n(h,{className:`h-3 w-3`,"aria-hidden":!0}),m(`history.orphans.deleteSelected`,`Delete selected`)]})]})]})})}i();var Ge=5*6e4;function Ke({enabled:i}){let{t:a}=H(),[s,c]=r(!1),l=ge({},{enabled:i,staleTime:Ge}),u=V({projection:`slim`},{enabled:i}),d=se(),f=t(()=>new Map((u.data??[]).map(e=>[e.id,e.name])),[u.data]),p=e=>d.mutateAsync({seriesIds:[...e]});if(!i||l.status===`pending`)return null;if(l.status===`error`)return n(P,{variant:`warning`,title:a(`history.orphans.checkFailedTitle`,`Could not check for unlinked series`),message:l.error.message,onRetry:()=>void l.refetch()});let m=l.data;if(m.series.length===0&&!s)return null;let h=m.series.length;return e(o,{children:[h>0&&n(P,{variant:`warning`,message:m.truncated?a(`history.orphans.noticeMore`,{count:h,defaultValue_one:`More than {{count}} series are no longer linked to a device.`,defaultValue_other:`More than {{count}} series are no longer linked to a device.`}):a(`history.orphans.notice`,{count:h,defaultValue_one:`{{count}} series is no longer linked to a device.`,defaultValue_other:`{{count}} series are no longer linked to a device.`}),action:n(b,{size:`sm`,variant:`outline`,onClick:()=>c(!0),children:a(`history.orphans.review`,`Review`)})}),n(We,{open:s,onClose:()=>c(!1),list:m,deviceNames:f,onDelete:p,onRefresh:()=>void l.refetch(),refreshing:l.isFetching})]})}i();var qe=`device`,Je=`node`;function Ye({catalog:r,selected:i,onChange:a,loading:o}){let{t:s}=H(),c=E(),l=k(),u=e=>W(e,c,l),d=xe(r,{searchText:e=>[Oe(e)],facetGroups:[{id:`subject`,value:e=>e.ref.subject.kind===`device`?qe:Je},{id:`room`,value:e=>e.location},{id:`unit`,value:e=>e.info.unit??``}]}),f=t(()=>[{key:`metric`,header:s(`history.picker.series`,`Series`),render:t=>e(`div`,{className:`min-w-0`,children:[n(`div`,{className:`truncate text-foreground`,children:t.metric}),n(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.location===``?u(t):`${u(t)} · ${t.location}`})]}),sortValue:e=>`${e.subjectName} ${e.metric}`},{key:`unit`,header:s(`history.picker.unit`,`Unit`),render:e=>n(`span`,{className:`text-foreground-muted`,children:e.info.unit??`—`}),sortValue:e=>e.info.unit??``}],[s,c,l]),p=i.size>=24;return e(`div`,{className:`space-y-2 min-w-0`,children:[n(ne,{state:d.state,facets:[],groups:[{...d.groups.find(e=>e.id===`subject`)??{id:`subject`,facets:[],selected:[]},label:s(`history.picker.subject`,`Source`),facetLabel:e=>e===qe?s(`history.picker.devices`,`Devices`):s(`history.picker.nodes`,`Nodes`)},{...d.groups.find(e=>e.id===`room`)??{id:`room`,facets:[],selected:[]},label:s(`history.picker.room`,`Room`),facetLabel:e=>e===``?s(`history.picker.noRoom`,`No room`):e},{...d.groups.find(e=>e.id===`unit`)??{id:`unit`,facets:[],selected:[]},label:s(`history.picker.metricType`,`Unit`),facetLabel:e=>e===``?s(`history.picker.noUnit`,`States & counts`):e}],labels:{searchPlaceholder:s(`history.picker.search`,`Search device, room, metric or node…`),searchLabel:s(`history.picker.searchLabel`,`Search series`),facetsLabel:s(`history.picker.facets`,`Filters`),clearLabel:s(`history.picker.clear`,`Clear`)},onSearch:d.setSearch,onToggleFacet:d.toggleFacet,onToggleGroupFacet:d.toggleGroupFacet,onClear:d.clear}),n(`p`,{className:`text-[10px] text-foreground-subtle`,"aria-live":`polite`,children:s(`history.picker.count`,`{{count}} of {{max}} selected`,{count:i.size,max:24})}),n(A,{columns:f,rows:d.rows,rowKey:e=>e.id,maxBodyHeight:w,pageSize:50,defaultSort:{columnKey:`metric`,dir:`asc`},emptyMessage:o?s(`history.picker.loading`,`Reading the series of every device…`):d.active?s(`history.picker.emptyFiltered`,`No series match these filters.`):s(`history.picker.empty`,`Nothing is recorded yet.`),selection:{selected:i,onChange:e=>{let t=[...e].filter(e=>i.has(e)),n=[...e].filter(e=>!i.has(e));a(new Set([...t,...n].slice(0,24)))},isSelectable:e=>i.has(e.id)||!p,rowLabel:e=>`${u(e)} · ${e.metric}`,pageLabel:s(`history.picker.selectPage`,`Select every series on this page`)}})]})}i();var Xe=new Set([v.Container]),$=5*6e4;function Ze(){let{t:r}=H(),i=de(`device-history`),[a,o]=Te(),s=t(()=>L(a.getAll(`s`).flatMap(e=>{let t=fe(e);return t===null?[]:[t]})),[a]),d=a.get(`window`),p=S(d)?d:`7d`,h=Se(a.get(`range`)),_=(e,t,n)=>{let r=new URLSearchParams;for(let t of L(e))r.append(`s`,ye(t));t!==`7d`&&r.set(`window`,t);let i=n===void 0?a.get(`range`):n;t===`custom`&&i&&r.set(`range`,i),o(r,{replace:!0})},v=Qe(i===`present`),y=z(p,Date.now(),h),x=z(p,_e(Date.now(),y.to-y.from),h),C=t(()=>Ne(s,v.candidates),[s,v.candidates]),w=t(()=>new Set(s.map(R)),[s]),T=me(),E=g(),D=f(),k=async()=>{let e=await E({title:r(`history.page.saveTitle`,`Save as panel`),label:r(`history.page.saveName`,`Panel name`),confirmLabel:r(`history.page.save`,`Save`)});e===null||e.trim()===``||await T.update(t=>pe(t,{id:`panel-${Date.now().toString(36)}`,name:e.trim().slice(0,80),window:p,selection:[...s]}))},A=async(e,t)=>{await D({title:r(`history.page.deleteTitle`,`Delete panel`),message:r(`history.page.deleteMessage`,`The panel "{{name}}" is removed from your account.`,{name:t}),confirmLabel:r(`history.page.delete`,`Delete`),variant:`danger`})&&await T.update(t=>le(t,e))},j=e=>e===`energy`?r(`history.panels.energy`,`Total energy`):e===`temperatures`?r(`history.panels.temperatures`,`Temperatures by room`):e===`nodes`?r(`history.panels.nodes`,`Cluster nodes`):r(`history.panels.storage`,`Storage locations`);return n(Ee,{icon:m,title:r(`history.page.title`,`History`),subtitle:r(`history.page.subtitle`,`What devices, nodes and storage recorded over time, side by side.`),actions:i===`present`?e(b,{size:`sm`,variant:`outline`,onClick:()=>void k(),disabled:s.length===0||!T.writable,children:[n(l,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),r(`history.page.saveTitle`,`Save as panel`)]}):void 0,children:i===`pending`?n(F,{className:`h-64 w-full`}):i===`unknown`?n(P,{title:r(`history.page.presenceUnknownTitle`,`Could not reach the hub`),message:r(`history.page.presenceUnknown`,`The hub did not say whether device history is installed. Try again in a moment.`)}):i===`absent`?n(I,{icon:u,title:r(`history.page.absentTitle`,`Device history is not running on this hub`),description:r(`history.page.absent`,`Nothing is recorded until the device-history system addon is enabled.`)}):e(`div`,{className:`space-y-3 sm:space-y-4`,children:[n(Ke,{enabled:i===`present`}),e(`div`,{className:`flex flex-wrap items-center gap-2`,role:`group`,"aria-label":r(`history.page.panels`,`Panels`),children:[ke.map(e=>n(b,{size:`sm`,variant:`outline`,disabled:v.status!==`ok`,onClick:()=>_(Me(e,v.candidates),p),children:j(e)},e)),T.value.panels.map(t=>e(`span`,{className:`inline-flex items-center`,children:[n(b,{size:`sm`,variant:`secondary`,onClick:()=>_(t.selection,t.window,null),children:t.name}),n(b,{size:`sm`,variant:`ghost`,"aria-label":r(`history.page.deleteNamed`,`Delete panel {{name}}`,{name:t.name}),onClick:()=>void A(t.id,t.name),disabled:!T.writable,children:n(c,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})]},t.id))]}),e(`div`,{className:`grid grid-cols-1 gap-3 sm:gap-4 xl:grid-cols-5`,children:[n(`div`,{className:`min-w-0 xl:col-span-2`,children:n(O,{headingId:`history-picker`,title:r(`history.picker.title`,`Series`),children:n(`div`,{className:`p-2 sm:p-3`,children:v.status===`error`?n(P,{message:v.error}):n(Ye,{catalog:v.candidates,loading:v.status===`pending`,selected:w,onChange:e=>{let t=s.filter(t=>e.has(R(t))),n=v.candidates.filter(t=>e.has(t.id)&&!w.has(t.id)).map(e=>e.ref);_([...t,...n],p)}})})})}),n(`div`,{className:`min-w-0 xl:col-span-3`,children:n(O,{headingId:`history-overlay`,title:r(`history.page.overlay`,`Overlay`),actions:s.length>0?n(b,{size:`sm`,variant:`ghost`,onClick:()=>_([],p),children:r(`history.page.clear`,`Clear`)}):void 0,children:e(`div`,{className:`p-2 sm:p-3 space-y-3 min-w-0`,children:[n(ve,{value:p,onChange:e=>_(s,e),custom:h,onCustomChange:e=>_(s,`custom`,M(e))}),v.status===`pending`&&s.length>0?n(F,{className:`h-64 w-full`}):n(Pe,{part:C,window:x}),C.missing.length>0&&v.status===`ok`&&n(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`history.page.missing`,{count:C.missing.length,defaultValue_one:`{{count}} selected series is no longer recorded.`,defaultValue_other:`{{count}} selected series are no longer recorded.`})})]})})})]})]})})}function Qe(e){let{t:n}=H(),r=n(`history.picker.wholeFrame`,`Whole frame`),i=_().trpcClient,o=V({projection:`slim`},{enabled:e}),{nodes:s}=D(),c=t(()=>(o.data??[]).filter(e=>!Xe.has(String(e.type))),[o.data]),l=a({queries:c.map(t=>({queryKey:[`device-history`,`listSeries`,t.id],queryFn:()=>i.deviceHistory.listSeries.query({deviceId:t.id}),enabled:e,staleTime:$}))}),u=a({queries:s.map(t=>({queryKey:[`device-history`,`listNodeSeries`,t.id],queryFn:()=>i.deviceHistory.listNodeSeries.query({forNodeId:t.id}),enabled:e,staleTime:$}))}),d=ae({},{enabled:e,staleTime:$}),f=t(()=>new Map((d?.data??[]).map(e=>[e.id,e.displayName])),[d?.data]),p=l.map(e=>e.data),m=u.map(e=>e.data),h=t(()=>De(c.flatMap((e,t)=>{let n=p[t];return n===void 0?[]:[{device:{id:e.id,name:e.name,location:e.location??null},series:n}]}),s.flatMap((e,t)=>{let n=m[t];return n===void 0?[]:[{node:{id:e.id,name:e.name},series:n}]}),e=>{if(e.key!==`addon:pipeline-analytics/occupancy`)return f.get(e.scope)??e.scope;let{zoneId:t,className:n}=y(e.scope),i=t===``?r:t;return n===void 0?i:`${i} · ${n}`}),[c,s,f,[...l,...u].map(e=>e.dataUpdatedAt).join(`,`),r]);return o.status===`error`?{status:`error`,error:o.error.message,candidates:[]}:{status:o.status===`pending`||l.some(e=>e.isPending)||u.some(e=>e.isPending)?`pending`:`ok`,error:``,candidates:h}}export{Ze as HistoryPage};
@@ -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{Br as u,Cn as d,D as f,Gr as p,Ht as m,Ka as h,Lr as g,Nn as _,Pn as v,Pr as y,Rn as b,Tt as x,Vn as S,Yn as C,Zt as w,ct as T,ft as ee,hi as E,ir as te,ja as D,jn as ne,qi as re,tn as ie,ur as ae,ut as oe,xi as se,yt as ce}from"./player-overlays-BF9w4QU-.js";import{Bs as O,m as le,zs as ue}from"./client-DhfZUoXe.js";import{d as k,n as de,o as fe,p as A,u as j}from"./terminal-Dgb4lrgM.js";import{t as pe}from"./file-up-2YD_M6f_.js";import{t as me}from"./key-CH4aXNMz.js";import{t as he}from"./monitor-smartphone-DPI9EQus.js";import{t as ge}from"./unlink-D3-IGpS8.js";import{$f as M,Bf as _e,Bi as N,Dl as ve,Dr as P,El as ye,Er as be,Ff as xe,Fi as Se,Fr as Ce,Gf as we,Hf as Te,Hi as F,If as I,Lf as Ee,Lp as L,M as De,Mr as Oe,Nr as R,Pf as ke,Pr as Ae,Rf as je,Ri as z,Sl as Me,Uf as Ne,Ui as B,Vf as Pe,Wf as Fe,Wi as V,_a as H,_l as Ie,ap as Le,ci as Re,ea as ze,ei as Be,ip as Ve,li as He,ni as Ue,nt as We,op as Ge,q as Ke,ri as qe,rp as Je,rt as Ye,sp as Xe,ui as Ze,ut as U,va as Qe,ya as W,yl as $e,zf as et,zi as tt,zs as nt}from"./src-D9hgltMI.js";import{t as G}from"./i18n-DCYaeyv_.js";import{t as K}from"./useTranslation-BJr-n0es.js";import{_i as rt,a as it,c as at,hi as ot,i as st,l as ct,mi as lt,o as ut,pi as dt,s as ft,t as pt,u as mt,w as ht,yi as gt,yt as _t,z as vt}from"./index-DPyWa2vo.js";import{t as yt}from"./AdminPage-z8USGyNk.js";import{t as bt}from"./InstancesTable-DIKWKA5W.js";import{t as xt}from"./AdminSectionedPage-CtcZ5jHa.js";import{C as St,D as q,E as Ct,O as J,S as wt,T as Tt,_ as Et,a as Dt,b as Ot,c as kt,d as At,f as jt,g as Mt,h as Nt,i as Pt,k as Ft,l as It,m as Lt,n as Rt,o as zt,p as Bt,s as Vt,t as Ht,u as Ut,v as Wt,w as Gt,x as Kt,y as qt}from"./SessionsList-BcO2x9OZ.js";import{n as Jt,t as Yt}from"./BootstrapSettingsForm-CKBDm4C-.js";s();function Xt(){let{t:e}=K(),t=T(),i=L.useUtils(),o=Ft(),{data:s,isLoading:c}=_e(),l=n(()=>s??[],[s]),u=L.useQueries(e=>l.map(t=>e.userManagement.listExternalIdentities({userId:t.id}))),d=L.auth.listLoginMethods.useQuery(),[f,p]=a(null),m=Fe({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=>({...Kt(e,o),kind:h.get(e.provider)??e.provider})),v=async n=>{let r=g.find(e=>Ot(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(q,{notice:J(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(Gt,{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:ge,isAvailable:()=>!0,onRun:e=>void v(e),busyId:null,disabled:m.isPending}})})}s();var Zt={key:`access.nouns.linkedApp`};function Qt(e){if(e.type===`category`){let t=e.target??``;return t===`device`?G.t(`access.linkedAppsSection.allDevices`):G.t(`access.linkedAppsSection.allTarget`,{target:t})}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function $t(){let{t:e}=K(),t=T(),i=c(),o=et(),[s,l]=a(null),d=()=>void i.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]}),f=Te({onSuccess:d,onError:e=>l(`Revoke failed: ${e.message}`)}),p=Tt(Zt,d),m=n(()=>(o.data??[]).map(e=>wt(e,e.scopes.map(Qt).join(`, `))),[o.data]),h=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),f.mutate({id:n.id}))},g=f.isPending?f.variables?.id??null:null;return r(q,{notice:J(s,p.outcome),onDismissNotice:()=>{l(null),p.dismiss()},id:`linked-apps`,title:e(`access.linkedAppsSection.linkedApps`,`Linked apps`),icon:u,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(Gt,{rows:m,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:ie,isAvailable:e=>e.status===`active`||e.status===`revoked`,onRun:e=>void h(e),busyId:g,disabled:f.isPending||p.busy},bulk:{revoke:p,noun:Zt,isSelectable:e=>e.status===`active`||e.status===`revoked`,quickSelect:[{label:e(`access.linkedAppsSection.selectRevoked`,`Select revoked`),match:e=>e.status===`revoked`}]}})})}var en=5e3;function tn(){let{t}=K(),n=L.useUtils(),i=L.auth.cliLoginPending.useQuery(void 0,{refetchInterval:en}),a=L.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(de,{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=pt(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(M,{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 nn={key:`access.nouns.session`};function rn(){let{t}=K(),i=T(),o=L.useUtils(),s=Ft(),c=L.auth.listSessions.useQuery(),[l,u]=a(null),d=()=>void o.auth.listSessions.invalidate(),f=L.auth.revokeSessions.useMutation({onSuccess:d,onError:e=>u(`Sign out failed: ${e.message}`)}),p=Tt(nn,d),m=n(()=>(c.data??[]).map(e=>St(e,s,{client:e=>Et(e).label,method:Wt})),[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(q,{notice:J(l,p.outcome),onDismissNotice:()=>{u(null),p.dismiss()},id:`login-sessions`,title:t(`access.loginSessionsSection.loginSessions`,`Login sessions`),icon:he,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(tn,{}),r(Gt,{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:fe,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:nn,isSelectable:e=>e.status===`active`}})]})}var an={"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 Y(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function X(e,t){let n=Y(e,`tokenId`);return Y(e,`name`)??(n===null?void 0:t.get(n))??n??`?`}function Z(e){return e.filter(e=>e!==null)}function on(e){let t=Y(e,`prefix`);return t===null?null:G.t(`helpers.authAuditWording.prefix`,{prefix:t})}function sn(e,t){let n=e.detail??{};switch(e.action){case`admin-token-created`:{let e=n.expiresAt;return{title:G.t(`helpers.authAuditWording.tokenCreated`,{name:X(n,t)}),details:Z([on(n),typeof e==`number`?G.t(`helpers.authAuditWording.expires`,{at:qt(e)}):null])}}case`admin-token-used`:{let e=Y(n,`path`);return{title:G.t(`helpers.authAuditWording.tokenUsed`,{name:X(n,t)}),details:Z([on(n),e===null?null:G.t(`helpers.authAuditWording.call`,{path:e})])}}case`token-minted`:{let e=n.expiresAt;return{title:G.t(`helpers.authAuditWording.tokenMinted`,{name:X(n,t)}),details:Z([typeof e==`number`?G.t(`helpers.authAuditWording.expires`,{at:qt(e)}):null])}}case`token-revoked`:return{title:G.t(`helpers.authAuditWording.anyTokenRevoked`,{name:X(n,t)}),details:[]};case`admin-token-revoked`:return{title:G.t(`helpers.authAuditWording.tokenRevoked`,{name:X(n,t)}),details:Z([on(n)])};case`credentials-revoked`:{let e=Y(n,`kind`)??`credential`,t=n.revoked,r=n.skipped,i=an[e],a=i===void 0?`${e}s`:G.t(i);return{title:G.t(`helpers.authAuditWording.bulkRevoked`,{n:typeof t==`number`?String(t):`?`,noun:a}),details:Z([typeof r==`number`&&r>0?G.t(`helpers.authAuditWording.skipped`,{count:r}):null,Y(n,`ids`)===null?null:G.t(`helpers.authAuditWording.ids`,{ids:Y(n,`ids`)??``})])}}case`second-factor-skipped`:{let e=Y(n,`method`),t=Y(n,`factors`);return{title:G.t(`helpers.authAuditWording.secondFactorSkipped`),details:Z([e===null?null:G.t(`helpers.authAuditWording.signedInWith`,{method:Wt(e)}),t===null?null:G.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 cn=100;function ln(){let{user:e}=vt();return e?.isAdmin?r(dn,{}):null}function un(){let{data:e}=_e(),{data:t}=L.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 dn(){let{t}=K(),n=L.auth.listAuthAudit.useQuery({limit:cn}),{userNameById:i,tokenNameById:a}=un(),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(S,{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:cn})})]}),r(`div`,{className:`p-4`,children:n.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(g,{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(fn,{record:e,userName:e.userId===void 0?null:i.get(e.userId)??e.userId,tokenNameById:a},e.id))})})]})}function fn({record:t,userName:n,tokenNameById:i}){let a=sn(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:qt(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 pn(e){let{ids:t,answered:r,legacyGroupParam:i=null,groupFirst:a}=e,[o]=gt(),s=o.get(ut),c=i===null?null:o.get(i),l=o.get(ft),u=n(()=>ct({ids:t,requested:s,answered:r,legacyGroup:c,...a===void 0?{}:{groupFirst:a}}),[t,s,r,c,a]),d=n(()=>(e,t)=>`?${mt(o,e,i,t??null).toString()}`,[o,i]);return{...u,requestedSection:l,hrefFor:d}}s();var Q={loginSessions:`login-sessions`,linkedApps:`linked-apps`,tokens:`tokens`,scopedTokens:`scoped-tokens`,adminTokens:`admin-tokens`,shareLinks:`share-links`,externalIdentities:`external-identities`,audit:`auth-audit`},mn={[Q.scopedTokens]:Q.tokens,[Q.adminTokens]:Q.tokens,[Q.shareLinks]:Q.tokens};function hn(){return[{id:Q.loginSessions,label:G.t(`system.access.loginSessions`,`Login sessions`),icon:he,render:()=>r(rn,{})},{id:Q.linkedApps,label:G.t(`system.access.linkedApps`,`Linked apps`),icon:u,render:()=>r($t,{})},{id:Q.tokens,label:G.t(`system.access.tokens`,`Tokens`),icon:j,render:({createRequested:e,onCreateConsumed:t})=>r(Nt,{headerOwnsCreate:!0,createRequested:e,onCreateConsumed:t})},{id:Q.externalIdentities,label:G.t(`system.access.signInLinks`,`Sign-in links`),icon:A,render:()=>r(Xt,{})},{id:Q.audit,label:G.t(`system.access.audit`,`Audit`),icon:S,render:()=>r(ln,{})}]}function gn({createRequested:t=!1,onCreateConsumed:i}){let{t:a}=K(),o=n(()=>hn(),[]),s=pn({ids:n(()=>o.map(e=>e.id),[o]),answered:!0}),c=rt(),[l]=gt(),u=l.get(`integration`),d=u===null?void 0:mn[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(Be,{appearance:`pills`,value:f?.id??Q.loginSessions,onValueChange:e=>{c(`?${mt(l,e,null,null).toString()}`)},children:r(Ue,{"aria-label":a(`system.access.credentialKinds`,`Credential kinds`),children:o.map(t=>e(qe,{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===Q.tokens,onCreateConsumed:i??(()=>void 0)})},f.id)]})}function _n(t,n){if(t===Q.tokens)return e(M,{size:`sm`,type:`button`,"data-testid":`access-new-token`,onClick:n,children:[r(j,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),G.t(`system.access.newToken`,`New token`)]})}function vn(){let[e,t]=a(!1);return{createRequested:e,requestCreate:()=>t(!0),clearCreate:()=>t(!1)}}function yn(){let{t}=K();return e(`div`,{className:`space-y-3 sm:space-y-4`,children:[r(bt,{functionCap:`login-method`,icon:k,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:_t})}),r(xn,{})]})}var bn=Jt;function xn(){let{t}=K();return r(Oe,{headingId:`authentication-policy`,title:t(`system.authentication.policyTitle`,`Sign-in policy`),icon:_,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(lt,{to:`/system/my-access?tab=sign-in`,className:`underline text-primary`}),users:r(lt,{to:`/system/identity?tab=users`,className:`underline text-primary`})}})}),r(Yt,{sectionIds:[bn],hideSectionChrome:!0,emptyMessage:t(`system.authentication.policyUnavailable`,`Not available — the addon that owns these settings did not answer.`)})]})})}function Sn({isPending:t,error:n,what:i,onRetry:a,children:o}){let{t:s}=K();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(g,{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 Cn(){let{t}=K(),n=L.deviceCredentials.getDeviceCaStatus.useQuery({}),i=n.data;return r(q,{id:`device-ca`,title:t(`certificates.deviceCaCard.deviceCertificateAuthority`,`Device certificate authority`),icon:_,description:t(`certificates.deviceCaCard.signsTheCertificateEachPaired`,`Signs the certificate each paired device holds. It is created the first time a device is paired.`),children:r(Sn,{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(R,{label:t(`certificates.deviceCaCard.state`,`State`),children:[i.state===`ready`&&r(W,{variant:`success`,children:t(`certificates.deviceCaCard.ready`,`Ready`)}),i.state===`absent`&&r(W,{variant:`default`,children:t(`certificates.deviceCaCard.notCreatedYet`,`Not created yet`)}),i.state===`unavailable`&&r(W,{variant:`danger`,children:t(`certificates.deviceCaCard.unavailable`,`Unavailable`)})]}),i.state===`ready`&&e(l,{children:[r(R,{label:t(`certificates.deviceCaCard.subject`,`Subject`),valueClassName:`font-mono`,children:i.subject}),r(R,{label:t(`certificates.deviceCaCard.fingerprintSha256`,`Fingerprint (SHA-256)`),valueClassName:`font-mono`,children:i.fingerprintSha256}),r(R,{label:t(`certificates.deviceCaCard.validUntil`,`Valid until`),children:i.validTo})]}),i.state===`unavailable`&&r(R,{label:t(`certificates.deviceCaCard.reason`,`Reason`),children:r(`span`,{className:`text-danger`,children:i.reason})})]})})})}s();function wn(){let{t}=K(),n=L.useUtils(),i=L.deviceCredentials.getDeviceCertificateSettings.useQuery({}),[o,s]=a(null),c=L.deviceCredentials.setDeviceCertificateSettings.useMutation({onSuccess:()=>{s(null),n.deviceCredentials.getDeviceCertificateSettings.invalidate()},onError:e=>s(`Could not save: ${e.message}`)});return r(Sn,{isPending:i.isPending,error:i.error,what:`the enrollment setting`,onRetry:()=>void i.refetch(),children:i.data!==void 0&&e(R,{label:t(`certificates.deviceSettingsRow.usersCanEnrollTheirOwn`,`Users can enroll their own devices`),actions:r(Re,{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 Tn(e){let[t,n]=a(()=>Date.now());return i(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}s();var En=80,Dn=208;function On({open:t,users:n,onClose:i,onPaired:o}){let{t:s}=K(),c=L.deviceCredentials.startEnrollment.useMutation({onSuccess:o}),[l,u]=a(``),[f,p]=a(``),m=l===``?n[0]?.id??``:l,h=c.data,_=()=>{c.reset(),p(``),i()};return r(Ye,{open:t,onClose:_,title:s(`certificates.pairDeviceDialog.pairADevice`,`Pair a device`),icon:d,width:`md`,testId:`pair-device-dialog`,error:c.isError?c.error.message:null,footer:h===void 0?e(M,{type:`button`,onClick:()=>{let e=f.trim();m===``||e===``||c.mutate({userId:m,deviceName:e})},disabled:c.isPending||m===``||f.trim()===``,children:[c.isPending&&r(g,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),s(`certificates.pairDeviceDialog.createPairingCode`,`Create pairing code`)]}):r(M,{type:`button`,variant:`outline`,onClick:_,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(U,{label:s(`certificates.pairDeviceDialog.user`,`User`),required:!0,children:r(ee,{value:m,onChange:e=>u(e.target.value),options:n.map(e=>({value:e.id,label:e.username}))})}),r(U,{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(Xe,{value:f,maxLength:En,onChange:e=>p(e.target.value),placeholder:s(`certificates.pairDeviceDialog.annaSIphone`,`Anna's iPhone`),autoFocus:!0})})]}):r(kn,{enrollUrl:h.enrollUrl,expiresAt:h.expiresAt,hubKnown:h.hubOrigin!==null,onRestart:()=>c.reset()})})}function kn({enrollUrl:t,expiresAt:n,hubKnown:i,onRestart:a}){let{t:o}=K(),s=zt(n,Tn(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(Se,{value:t,size:Dn,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(be,{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(w,{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(M,{type:`button`,variant:`outline`,size:`sm`,onClick:a,children:o(`certificates.pairDeviceDialog.newCode`,`New code`)})]})]})})}s();var An={key:`access.nouns.device`};function jn({pairOpen:t,onPairClose:i}){let{t:o}=K(),s=T(),c=oe(),l=L.useUtils(),u=L.deviceCredentials.listDeviceCredentials.useQuery({includeRevoked:!0}),f=_e(),[p,m]=a(null),[h,g]=a(null),_=()=>void l.deviceCredentials.listDeviceCredentials.invalidate(),v=e=>t=>{g(null),m(`${e} failed: ${t.message}`)},y=()=>{g(null),_()},b=L.deviceCredentials.revokeDeviceCredential.useMutation({onSuccess:y,onError:v(`Revoke`)}),x=L.deviceCredentials.deleteDeviceCredential.useMutation({onSuccess:e=>{e.result!==`deleted`&&m(e.result===`live`?`Only a revoked device can be deleted: revoke it first.`:`That device no longer exists.`),y()},onError:v(`Delete`)}),S=L.deviceCredentials.renameDeviceCredential.useMutation({onSuccess:y,onError:v(`Rename`)}),C=Ct(An,e=>b.mutateAsync({id:e}),_),w=C.busy||h!==null,ee=n(()=>(u.data??[]).map(Rt),[u.data]),E=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`})&&(m(null),g(e.id),b.mutate({id:e.id}))},te=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`})&&(m(null),g(e.id),x.mutate({id:e.id}))},ne=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||(m(null),g(e.id),S.mutate({id:e.id,deviceName:t}))},re={label:o(`certificates.devicesCard.revoke2`,`Revoke`),icon:D,isAvailable:Dt,onRun:e=>void E(e),busyId:b.isPending?h:null,disabled:w},se=[{label:o(`certificates.devicesCard.rename`,`Rename`),icon:ae,tone:`neutral`,isAvailable:()=>!0,onRun:e=>void ne(e),busyId:S.isPending?h:null,disabled:w},{label:o(`common.delete`,`Delete`),icon:ie,isAvailable:Pt,onRun:e=>void te(e),busyId:x.isPending?h:null,disabled:w}];return e(q,{id:`devices`,title:o(`certificates.devicesCard.devices`,`Devices`),icon:d,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:J(p,C.outcome),onDismissNotice:()=>{m(null),C.dismiss()},children:[r(wn,{}),r(Gt,{rows:ee,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:re,extraActions:se,bulk:{revoke:C,noun:An,isSelectable:Dt}}),r(On,{open:t,users:f.data??[],onClose:i,onPaired:_})]})}var Mn=/-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----/,Nn=/-----BEGIN ((?:RSA |EC |ENCRYPTED )?PRIVATE KEY)-----[\s\S]+?-----END \1-----/,Pn={certificate:`.pem,.crt,.cer`,privateKey:`.pem,.key`,ca:`.pem,.crt,.cer`};function Fn(e,t){if(t.trim()===``)return null;if(e===`privateKey`){let e=Nn.exec(t);return e===null?Mn.test(t)?G.t(`helpers.pemFile.isCert`):G.t(`helpers.pemFile.notKey`):e[1]===`ENCRYPTED PRIVATE KEY`?G.t(`helpers.pemFile.encrypted`):null}return Mn.test(t)?e===`certificate`&&Nn.test(t)?G.t(`helpers.pemFile.certHasKey`):null:Nn.test(t)?G.t(`helpers.pemFile.isKey`):G.t(`helpers.pemFile.notCert`)}function In(e){return e.text()}s();function Ln({kind:n,label:i,value:o,onChange:s,rows:c=6}){let{t:l}=K(),u=t(null),[d,f]=a(null),[p,m]=a(null),h=p??Fn(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 In(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(He,{ref:u,accept:Pn[n],onChange:e=>void _(e),className:`hidden`,"data-testid":`${g}-file`}),e(M,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>u.current?.click(),children:[r(pe,{className:`mr-1 h-3 w-3`}),l(`system.pemField.chooseFile`,`Choose file`)]})]})]}),r(Ze,{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 Rn=30;function zn(e){let t=Date.parse(e);return!Number.isNaN(t)&&Date.now()-t<Rn*864e5}function Bn(e){if(e===null||e===``)return`—`;let t=e.replace(/:/g,``);return t.length<=16?e:`${t.slice(0,8)}…${t.slice(-8)}`}function Vn(){let{t}=K(),n=c(),i=Ie(void 0,{refetchInterval:15e3}),o=$e({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),s=Me({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),l=ve({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),u=ye({onSuccess:()=>{m(!1),g(``),v(``),b(``),n.invalidateQueries({queryKey:[[`localNetwork`]]})}}),d=i.data,[p,m]=a(!1),[h,g]=a(``),[_,v]=a(``),[y,b]=a(``),x=()=>{if(!d?.caCertPem)return;let e=new Blob([d.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)},S=d?.mode===`uploaded`?`Uploaded`:d?.mode===`generated`?`Generated local CA`:`TLS disabled`;return r(Oe,{headingId:`local-access-certificate`,title:t(`system.localAccess.certificate`,`Certificate`),icon:ne,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.`)}),d?.reissueError&&r(H,{variant:`warning`,title:t(`system.localAccess.certificateReissue`,`Certificate reissue`),message:d.reissueError}),d?.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.`)}),d?.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).")}),d?.caReplacedAt!=null&&zn(d.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(d.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:S})]}),e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.validTo`,`Valid to`)}),r(`dd`,{className:`font-mono`,children:d?.validTo?new Date(d.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:d?.leafFingerprintSha256??void 0,children:Bn(d?.leafFingerprintSha256??null)})]}),d?.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(d.storedUpload.validTo).toLocaleDateString(),ca:d.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:d?.caFingerprintSha256??void 0,children:d?.mode===`uploaded`&&d.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)`)}):Bn(d?.caFingerprintSha256??null)})]})]}),d&&d.sans.length>0&&r(`div`,{className:`flex flex-wrap gap-1`,children:d.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:d?.mode===`uploaded`||o.isPending,action:()=>o.mutateAsync({})}),r(M,{size:`sm`,variant:`outline`,onClick:()=>m(e=>!e),children:t(`system.localAccess.upload`,`Upload`)}),d?.caCertPem&&r(M,{size:`sm`,variant:`outline`,onClick:x,children:t(`system.localAccess.downloadCa`,`Download CA`)}),d?.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({})}),d?.mode===`generated`&&d.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)})]}),p&&e(`div`,{className:`space-y-2 border-t border-border pt-3`,children:[r(Ln,{kind:`certificate`,label:t(`system.localAccess.certificateOrFullChainPem`,`Certificate or full chain (PEM)`),value:h,onChange:g}),r(Ln,{kind:`privateKey`,label:t(`system.localAccess.privateKeyPem`,`Private key (PEM)`),value:_,onChange:v}),r(Ln,{kind:`ca`,label:t(`system.localAccess.caPemRequired`,`CA (PEM) - required unless the certificate comes from a public CA`),value:y,onChange:b,rows:4}),r(M,{size:`sm`,disabled:!h.trim()||!_.trim()||Fn(`certificate`,h)!==null||Fn(`privateKey`,_)!==null||Fn(`ca`,y)!==null||u.isPending,onClick:()=>u.mutate({certPem:h,keyPem:_,...y.trim()?{caPem:y}:{}}),children:t(`system.localAccess.saveCertificate`,`Save certificate`)}),u.isError&&r(`p`,{className:`text-xs text-danger`,children:u.error instanceof Error?u.error.message:t(`system.localAccess.uploadFailed`,`Upload failed`)})]})]})})}var Hn={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`};function Un(e){let t=e.find(e=>e.isHub);return t?.https.kind===`served`?t.https.status.caFingerprintSha256:null}function Wn({https:t,mesh:n,now:i}){let{t:a}=K(),o=Ie().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(R,{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:[Un(t)??`—`,o!==``&&e(M,{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(R,{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(R,{label:a(`certificates.caStrip.clusterCaValidUntil`,`Cluster CA valid until`),children:[c.validTo,l!==null&&!Number.isNaN(l)&&e(`span`,{className:`ml-2 text-[10px] ${Hn[Ut(l,i)]}`,children:[`(`,kt(l,i),`)`]})]}),u!==void 0&&e(R,{label:a(`certificates.caStrip.nodeListener`,`Node listener`),children:[u.state===`open`&&r(W,{variant:`success`,children:a(`certificates.caStrip.open`,`Open`)}),u.state===`not-started`&&r(W,{variant:`default`,children:a(`certificates.caStrip.notStarted`,`Not started`)}),u.state===`closed`&&e(`span`,{className:`text-danger`,children:[a(`certificates.caStrip.closedSince`,{when:At(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(w,{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 Gn(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 Kn(e){return e.isHub?G.t(`helpers.nodesModel.hubReissued`):e.mesh===null?G.t(`helpers.nodesModel.noCertRecorded`):e.online?null:G.t(`helpers.certificateModel.nodeOffline`)}function qn(e){return e.isHub||e.mesh===null?Kn(e):null}var Jn={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`},Yn={enroll:`Issued at enrollment`,renewal:`Issued by a renewal`,boot:`Issued at boot`,pairing:`Issued at pairing`,observed:`Observed on its connection`},Xn={uploaded:`Uploaded`,generated:`Generated`,disabled:`Disabled`};function Zn(e){let t=e.https?.https;return t?.kind===`served`?Vt(t.status.validTo):null}function Qn({ms:t,now:n}){return t===null?r(`span`,{className:`text-foreground-subtle`,children:`—`}):e(`div`,{children:[r(`div`,{children:At(t)}),r(`div`,{className:`text-[10px] ${Jn[Ut(t,n)]}`,children:kt(t,n)})]})}function $n({row:t}){let{t:n}=K(),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(W,{variant:`success`,className:`text-[10px]`,children:n(`certificates.nodesColumns.served`,`Served`)}),r(`span`,{className:`ml-1.5 text-[10px] text-foreground-subtle`,children:Xn[i.status.mode]}),r(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:Bt(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(W,{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 er({row:t}){let{t:n}=K(),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:Lt(i.serial)}),r(`div`,{className:`font-mono text-[10px] text-foreground-subtle`,title:i.fingerprintSha256,children:Bt(i.fingerprintSha256)}),e(`div`,{className:`text-[10px] text-foreground-subtle`,children:[Yn[i.issuedVia],a>0?` · ${n(`certificates.nodesColumns.earlier`,{count:a})}`:``]})]})}function tr({row:e}){let{t}=K(),n=e.mesh?.presentingCurrent??null;return n===null?r(`span`,{className:`text-foreground-subtle`,children:e.online?`—`:t(`certificates.nodesColumns.offline`,`Offline`)}):n?r(W,{variant:`success`,className:`text-[10px]`,children:t(`common.yes`,`Yes`)}):r(W,{variant:`warning`,className:`text-[10px]`,children:t(`certificates.nodesColumns.noPresentsAnother`,`No - presents another`)})}function nr(t){let n=t.icon;return e(M,{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(g,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):r(n,{className:`h-3 w-3`,"aria-hidden":!0}),t.label]})}function rr({reasons:t}){let{t:n}=K();return e(Ve,{className:`inline-block`,children:[r(Ge,{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(Le,{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 ir({row:t,o:n}){let{t:i}=K(),a=t.https===null?`No HTTPS inventory for this node.`:jt(t.https).reason,o=Kn(t),s=qn(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(nr,{label:i(`certificates.nodesColumns.renewHttps`,`Renew HTTPS`),ariaLabel:i(`certificates.nodesColumns.renewTheCertificateOn`,`Renew the certificate on {{nodeId}}`,{nodeId:t.nodeId}),icon:C,reason:a,busy:n.busy,spinning:c(`renew-https`),danger:!1,onClick:()=>n.onRenewHttps(t)}),l(o)&&r(nr,{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:C,reason:o,busy:n.busy,spinning:c(`renew-identity`),danger:!1,onClick:()=>n.onRenewIdentity(t)}),l(s)&&r(nr,{label:i(`certificates.nodesColumns.revokeIdentity`,`Revoke identity`),ariaLabel:i(`certificates.nodesColumns.revokeTheClusterCertificateOf`,`Revoke the cluster certificate of {{nodeId}}`,{nodeId:t.nodeId}),icon:D,reason:s,busy:n.busy,spinning:c(`revoke-identity`),danger:!0,onClick:()=>n.onRevokeIdentity(t)})]}),t.isHub&&u.length>0&&r(rr,{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 ar(t){return[{key:`node`,header:G.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(W,{variant:`info`,className:`text-[10px]`,children:G.t(`common.hubWord`)}),!t.online&&r(W,{variant:`default`,className:`text-[10px]`,children:G.t(`common.offline`)})]})},{key:`https-state`,header:`HTTPS`,notSortableReason:`A state with a reason has no single order.`,render:e=>r($n,{row:e})},{key:`https-expires`,header:G.t(`certificates.nodesColumns.httpsExpires`,`HTTPS expires`),sortValue:e=>Zn(e),render:e=>r(Qn,{ms:Zn(e),now:t.now})},{key:`identity`,header:G.t(`certificates.nodesColumns.identity`,`Identity`),sortValue:e=>e.mesh?.current?.serial??null,render:e=>r(er,{row:e})},{key:`identity-expires`,header:G.t(`certificates.nodesColumns.identityExpires`,`Identity expires`),sortValue:e=>e.mesh?.current?.notAfter??null,render:e=>r(Qn,{ms:e.mesh?.current?.notAfter??null,now:t.now})},{key:`presenting`,header:G.t(`certificates.nodesColumns.inUse`,`In use`),notSortableReason:`Offline nodes have no answer to order by.`,render:e=>r(tr,{row:e})},{key:`actions`,header:G.t(`certificates.nodesColumns.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order.`,render:e=>r(ir,{row:e,o:t})}]}s();function or(){let{t}=K(),i=T(),o=L.useUtils(),s=Tn(6e4),c=L.certificates.listHttpsCertificates.useQuery(),l=L.certificates.getMeshCertificates.useQuery(),[u,d]=a(null),[f,p]=a(null),[m,h]=a(null),g=()=>{h(null),o.certificates.listHttpsCertificates.invalidate(),o.certificates.getMeshCertificates.invalidate()},_=e=>(t,n)=>{h(null),d(`${n.nodeId}: ${e} - ${t.message}`)},v=L.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})}),g()},onError:_(`renewal failed`)}),y=L.certificates.renewMeshOnNode.useMutation({onSuccess:e=>{p(It(e)),g()},onError:_(`renewal could not start`)}),x=L.certificates.revokeMeshOnNode.useMutation({onSuccess:e=>{p({tone:`success`,message:`${e.nodeId}: ${e.next}`}),g()},onError:_(`revoke failed`)}),S=v.isPending||y.isPending||x.isPending,C=(e,t)=>{d(null),p(null),h({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`),v.mutate({nodeId:e.nodeId}))},ee=e=>{C(e.nodeId,`renew-identity`),y.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}))},te=ar({now:s,busy:S,running:m,onRenewHttps:e=>void w(e),onRenewIdentity:ee,onRevokeIdentity:e=>void E(e)}),D=n(()=>Gn(c.data??[],l.data),[c.data,l.data]),ne=l.data?.registryAvailable??!0;return r(q,{id:`nodes`,title:t(`certificates.nodesCard.nodes`,`Nodes`),icon:b,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:J(u,f),onDismissNotice:()=>{d(null),p(null)},children:r(Sn,{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(Wn,{https:c.data??[],mesh:l.data,now:s}),r(Ae,{columns:te,rows:D,rowKey:e=>e.nodeId,minWidthPx:960,maxBodyHeight:Ce,defaultSort:{columnKey:`node`,dir:`asc`},emptyMessage:ne?t(`certificates.nodesCard.noNodesReported`,`No nodes reported.`):t(`certificates.nodesCard.theCertificateRegistryIsNot`,`The certificate registry is not available yet, so nodes cannot be listed.`)})]})})})}function sr({pairOpen:t,onPairClose:n}){return e(`div`,{className:`space-y-4`,"data-testid":`certificates-page`,children:[r(jn,{pairOpen:t,onPairClose:n}),r(Cn,{}),r(Vn,{}),r(or,{})]})}function cr({userId:t,username:n,onClose:i}){let{t:a}=K(),o=T(),s=L.useUtils(),c=je({userId:t}),l=L.auth.listLoginMethods.useQuery(),d=Fe({onSuccess:()=>void s.userManagement.listExternalIdentities.invalidate()}),f=new Map((l.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),p=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`})&&d.mutate({userId:t,provider:e.provider,subject:e.subject})};return r(z,{open:!0,onOpenChange:e=>!e&&i(),children:e(N,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`external-identities-modal`,children:[r(B,{children:e(V,{className:`flex items-center gap-2`,children:[r(u,{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(tt,{className:`space-y-3`,children:c.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(g,{className:`h-3.5 w-3.5 animate-spin`}),a(`common.loading`,`Loading…`)]}):p.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:p.map(t=>{let n=f.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(M,{variant:`unstyled`,onClick:()=>void m(t,i),disabled:d.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(ge,{className:`h-3 w-3`}),a(`common.remove`,`Remove`)]})]},`${t.provider}|${t.subject}`)})})}),r(F,{children:r(M,{onClick:i,variant:`secondary`,children:a(`common.close`,`Close`)})})]})})}function lr({userId:t,username:n,onClose:i}){let{t:a}=K(),o=c(),s=T(),u=Ee({userId:t}),f=u.data,m=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),h=I({onSuccess:()=>{m(),i()}}),_=u.isLoading?`loading`:f?.enabled?`enrolled`:`not_enrolled`;return r(z,{open:!0,onOpenChange:e=>!e&&i(),children:e(N,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[r(B,{children:e(V,{className:`flex items-center gap-2`,children:[r(d,{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(tt,{className:`space-y-4`,children:[_===`loading`&&e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(g,{className:`h-3.5 w-3.5 animate-spin`}),a(`users.totpModal.checkingStatus`,`Checking status…`)]}),_===`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(p,{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.`)})]})]}),_===`enrolled`&&f&&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(re,{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:f.confirmedAt?new Date(f.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(M,{onClick:i,variant:`secondary`,children:a(`common.close`,`Close`)}),e(M,{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`})&&h.mutate({userId:t})},disabled:h.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:[h.isPending?r(g,{className:`h-3 w-3 animate-spin`}):r(x,{className:`h-3 w-3`}),a(`users.totpModal.remove2fa`,`Remove 2FA`)]})]})]})]})]})})}s();function ur({userId:t,username:n,onClose:i}){let{t:o}=K(),{user:s,logout:c}=vt(),l=s?.id===t,u=T(),d=L.useUtils(),f=L.auth.listSessions.useQuery({userId:t}),[p,m]=a(null),h=L.auth.revokeSessions.useMutation({onSuccess:(e,t)=>{if(l&&`userId`in t){c();return}d.auth.listSessions.invalidate()},onError:e=>m(`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:Et(e.client).label}),confirmLabel:o(`users.userSessionsModal.signOut`,`Sign out`),variant:`danger`})&&(m(null),h.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`})&&(m(null),h.mutate({userId:t}))},y=h.isPending&&h.variables!==void 0&&`id`in h.variables?h.variables.id:null;return r(z,{open:!0,onOpenChange:e=>!e&&i(),children:e(N,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`user-sessions-modal`,children:[r(B,{children:e(V,{className:`flex items-center gap-2`,children:[r(he,{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(tt,{className:`space-y-3`,children:[p!==null&&r(`div`,{className:`text-[11px] text-danger`,children:p}),r(Ht,{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(F,{className:`justify-between`,children:[e(M,{variant:`unstyled`,onClick:()=>void v(),disabled:h.isPending||(f.data??[]).length===0,className:`inline-flex items-center gap-1.5 rounded border border-danger/40 px-2.5 py-1 text-[11px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,children:[h.isPending&&y===null?r(g,{className:`h-3 w-3 animate-spin`}):r(fe,{className:`h-3 w-3`}),o(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`)]}),r(M,{onClick:i,variant:`secondary`,children:o(`common.close`,`Close`)})]})]})})}function dr({scopes:t,invalidReason:n}){let{t:i}=K(),a=ce(),s=o({queryKey:[`auth`,`previewScope`,t,!1],enabled:n===null,queryFn:()=>a.trpcClient.auth.previewScope.query({scopes:[...t],isAdmin:!1})}),{data:c}=nt({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(g,{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(E,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),u===0?i(`users.rolePreview.noDevice`):d]})}function fr(e){let t=le(e.scopes??[]);if(t===null)return{role:e.isAdmin?`admin`:`viewer`,mode:`except`,pickedIds:[],viewer:ue,unconfigured:!e.isAdmin};let n=yr(t);return{role:e.isAdmin?`admin`:`viewer`,mode:n.mode,pickedIds:n.pickedIds,viewer:br(n.mode,n.pickedIds,t.features),unconfigured:!1}}function pr(e,t){return{...e,role:t}}function mr(e,t){return{...e,mode:t,viewer:br(t,e.pickedIds,e.viewer.features)}}function hr(e,t){let n=xr(t);return{...e,pickedIds:n,viewer:br(e.mode,n,e.viewer.features)}}function gr(e,t,n){let r=e.viewer.features.filter(e=>e!==t),i=n?[...r,t]:r;return{...e,viewer:br(e.mode,e.pickedIds,i)}}function _r(e){return e.role===`viewer`&&e.mode===`only`&&e.pickedIds.length===0?`no-allowed-device`:null}function vr(e){return _r(e)===null?e.role===`admin`?{isAdmin:!0,scopes:[]}:{isAdmin:!1,scopes:[e.viewer]}:null}function yr(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 br(e,t,n){let r=xr(t);return e===`except`?{type:`viewer`,allow:`*`,block:r,features:[...n]}:{type:`viewer`,allow:r,block:[],features:[...n]}}function xr(e){return[...new Set(e)]}s();var Sr=`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`;function Cr(e,t){return e?`failed`:t===void 0?`pending`:`answered`}function wr(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 Tr({user:t,isSelf:i,onClose:o,onSubmit:s,submitting:c,error:u}){let{t:d}=K(),[f,p]=a(n(()=>fr(t),[t])),m=nt({projection:`slim`}),_=m.data,v=Cr(m.isError,_),y=n(()=>wr(_??[]),[_]),b=n(()=>({state:v,devices:v===`answered`?(_??[]).map(e=>({id:e.id,name:e.name})):void 0}),[v,_]),x=_r(f),S=vr(f),C=x===`no-allowed-device`?d(`users.userAccessModal.pickAllowedDevice`):null,w=e=>{p(pr(f,e))},T=[{value:`except`,label:d(`users.userAccessModal.modeExcept`)},{value:`only`,label:d(`users.userAccessModal.modeOnly`)}];return r(z,{open:!0,onOpenChange:e=>!e&&o(),children:e(N,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-2xl`,children:[r(B,{children:r(V,{children:d(`users.userAccessModal.title`,{name:t.username})})}),e(tt,{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:Sr,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(Er,{name:`admin`,checked:f.role===`admin`,label:d(`users.userAccessModal.admin`),description:d(`users.userAccessModal.adminDescription`),onPick:()=>w(`admin`)}),r(Er,{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:Sr,children:d(`users.userAccessModal.devices`)}),r(Ke,{label:d(`users.userAccessModal.whichDevices`),value:f.mode,options:T,onChange:e=>p(mr(f,e))}),r(De,{devices:y,listState:v,fleet:b,value:[...f.pickedIds],onChange:e=>p(hr(f,e)),emptyMeansAll:f.mode===`except`,noun:`device`,testId:`viewer-device-picker`}),r(dr,{scopes:S?.scopes??[],invalidReason:C})]}),e(`section`,{className:`space-y-2`,children:[r(`h3`,{className:Sr,children:d(`users.userAccessModal.features`)}),r(`div`,{className:`space-y-1`,children:O.map(t=>e(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-md p-1.5 hover:bg-surface-hover`,children:[r(h,{className:`mt-0.5`,checked:f.viewer.features.includes(t.id),onChange:e=>p(gr(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(F,{children:[r(M,{variant:`outline`,size:`sm`,onClick:o,children:d(`common.cancel`,`Cancel`)}),r(M,{size:`sm`,onClick:()=>S!==null&&s(S),disabled:c||S===null,children:c?r(g,{className:`h-3 w-3 animate-spin`}):d(`users.userAccessModal.saveAccess`)})]})]})})}function Er({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(Qe,{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 $=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:G.t(`admin.system.users.genericError`)}function Ar(){let{t}=K(),n=c(),{user:o}=vt(),{state:s,openNew:f,openEdit:p,close:v}=We(),[y,b]=a(null),[x,S]=a(null),[C,w]=a(!1),{data:ee,isLoading:E,isError:D,error:ne,refetch:re}=_e(),se=T(),ce=oe(),O=()=>n.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),le=ke(),ue=xe({onSuccess:O}),k=we({onSuccess:O}),de=Pe({onSuccess:O}),fe=Ne(),[A,j]=a(null),[pe,ge]=a(!1),[N,ve]=a(null),[P,ye]=a(null),[be,Se]=a(null),[Ce,Te]=a(null),F=ee??[],I=s.mode===`edit`?F.find(e=>e.id===s.id)??null:null,Ee=()=>{b(null),S(null),w(!1),le.reset(),k.reset(),v()};i(()=>{if(s.mode===`closed`){b(null),S(null),w(!1);return}if(s.mode===`new`){b(e=>e!==null&&e.id===void 0?e:Dr());return}if(I===null){E||v();return}b(e=>e?.id===I.id?e:Or(I))},[s,I,E,v]);let L=s.mode===`new`&&y!==null&&y.id===void 0||s.mode===`edit`&&y!==null&&I!==null;async function De(e){await se({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`})&&(ue.mutate({id:e.id}),s.mode===`edit`&&s.id===e.id&&Ee())}async function Oe(e){let n=await ce({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<$?G.t(`admin.system.users.passwordTooShort`,{min:$}):null});n===null||n.length===0||await se({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`)})&&de.mutate({id:e.id,newPassword:n})}function R(e){ve(null),j(e)}async function je(e,t){ge(!0),ve(null);try{t.isAdmin!==e.isAdmin&&await k.mutateAsync({id:e.id,isAdmin:t.isAdmin}),await fe.mutateAsync({userId:e.id,scopes:[...t.scopes]}),j(null)}catch(e){ve(kr(e))}finally{ge(!1),O()}}async function z(){if(y!==null){S(null);try{if(y.id===void 0){let e=y.username.trim();if(e===``||y.password.length<$)return;await le.mutateAsync({username:e,password:y.password,isAdmin:y.isAdmin})}else await k.mutateAsync({id:y.id,isAdmin:y.isAdmin});O(),Ee()}catch(e){S(kr(e))}}}function Me(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}let B=le.isPending||k.isPending,Fe=y!==null&&y.id===void 0&&y.username.trim()!==``&&y.password.length>=$,V=y!==null&&y.id!==void 0,Ie=B||(y?.id===void 0?!Fe:!V),Le=e=>ue.isPending&&ue.variables?.id===e.id||k.isPending&&k.variables?.id===e.id||de.isPending&&de.variables?.id===e.id,Re=[{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(M,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>R(n),disabled:Le(n),title:t(`admin.system.users.configureAccess`,`Configure access`),"data-testid":`user-access-${n.id}`,children:[r(_,{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:Me(e.createdAt)})},{key:`actions`,header:t(`admin.system.users.actions`,`Actions`),align:`right`,nowrap:!0,notSortableReason:`Row actions`,render:n=>{let i=Le(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(M,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>p(n.id),disabled:i,title:t(`admin.system.users.editUser`,`Edit user`),children:[r(ae,{className:`h-3 w-3`}),t(`common.edit`,`Edit`)]}),a&&e(M,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>ye(n),disabled:i,title:t(`admin.system.users.removeTwoFactorAuthentication`,`Remove two-factor authentication`),children:[r(d,{className:`h-3 w-3`}),t(`admin.system.users.remove2fa`,`Remove 2FA`)]}),e(M,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>Se(n),disabled:i,title:t(`admin.system.users.linkedSignInAccounts`,`Linked sign-in accounts`),children:[r(u,{className:`h-3 w-3`}),t(`admin.system.users.signInLinks`,`Sign-in links`)]}),e(M,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>Te(n),disabled:i,title:t(`admin.system.users.activeSessions`,`Active sessions`),children:[r(he,{className:`h-3 w-3`}),t(`admin.system.users.sessions`,`Sessions`)]}),e(M,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void Oe(n),disabled:i,title:t(`admin.system.users.resetPassword`,`Reset password`),children:[r(me,{className:`h-3 w-3`}),t(`admin.system.users.resetPassword`,`Reset password`)]}),e(M,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void De(n),disabled:i,title:t(`admin.system.users.deleteUser`,`Delete user`),className:`text-danger hover:bg-danger/10`,children:[i?r(g,{className:`h-3 w-3 animate-spin`}):r(ie,{className:`h-3 w-3`}),t(`common.delete`,`Delete`)]})]})}}];return e(yt,{embedded:!0,icon:m,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(M,{size:`sm`,type:`button`,onClick:()=>{S(null),f()},children:[r(te,{className:`h-3.5 w-3.5`}),t(`admin.system.users.createUser`,`Create User`)]}),children:[D&&r(H,{title:t(`admin.system.users.couldNotLoadUsers`,`Could not load users`),message:kr(ne),onRetry:()=>void re()}),E&&e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(g,{className:`h-3.5 w-3.5 animate-spin`}),t(`common.loading`,`Loading…`)]}),!E&&!D&&F.length===0&&r(ze,{icon:m,title:t(`admin.system.users.noUsersYet`,`No users yet`),description:t(`admin.system.users.createAUserToGrant`,`Create a user to grant hub access.`)}),!E&&!D&&F.length>0&&r(Ae,{columns:Re,rows:F,rowKey:e=>e.id,minWidthPx:560,maxBodyHeight:`max-h-[60vh]`,onRowClick:e=>p(e.id)}),r(Ye,{open:L,onClose:Ee,title:y?.id===void 0?t(`admin.system.users.createUser`,`Create User`):t(`admin.system.users.edit`,`Edit {{value1}}`,{value1:y.username||`user`}),icon:m,error:x,testId:`user-form-dialog`,footer:r(M,{size:`sm`,type:`button`,disabled:Ie,onClick:()=>void z(),children:B?e(l,{children:[r(g,{className:`h-3.5 w-3.5 animate-spin`}),t(`admin.system.users.saving`,`Saving…`)]}):y?.id===void 0?t(`admin.system.users.create`,`Create`):t(`common.save`,`Save`)}),children:y!==null&&e(`div`,{className:`space-y-3`,children:[r(U,{label:t(`admin.system.users.username`,`Username`),required:y.id===void 0,children:r(Xe,{value:y.username,onChange:e=>b({...y,username:e.target.value}),placeholder:`john`,autoFocus:y.id===void 0,disabled:y.id!==void 0,"data-testid":`user-form-username`})}),y.id===void 0&&r(U,{label:t(`admin.system.users.password`,`Password`),required:!0,description:t(`admin.system.users.atLeastCharacters`,`At least {{value1}} characters.`,{value1:String($)}),children:r(Je,{value:y.password,onValueChange:e=>b({...y,password:e}),shown:C,onToggleShown:()=>w(e=>!e),placeholder:`••••••••`,"data-testid":`user-form-password`})}),r(U,{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(h,{checked:y.isAdmin,onChange:e=>b({...y,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`)})]})}),y.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.`)})]})}),P&&r(lr,{userId:P.id,username:P.username,onClose:()=>ye(null)}),be&&r(cr,{userId:be.id,username:be.username,onClose:()=>Se(null)}),Ce&&r(ur,{userId:Ce.id,username:Ce.username,onClose:()=>Te(null)}),A&&r(Tr,{user:A,isSelf:A.id===o?.id,onClose:()=>j(null),onSubmit:e=>void je(A,e),submitting:pe,error:N})]})}function jr(e){let t=fr(e);return t.role===`admin`?0:t.unconfigured?2:1}function Mr({user:t}){let{t:n}=K(),i=fr(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":Q.tokens,"linked-sessions":Q.linkedApps},Pr=`certificates`;function Fr(t){return e(M,{size:`sm`,type:`button`,"data-testid":`certificates-pair-device`,onClick:t,children:[r(d,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),G.t(`systemPage.identity.pairADevice`,`Pair a device`)]})}function Ir(){let{t:e}=K(),[t]=gt(),n=vn(),[i,o]=a(!1),s=Nr[t.get(`tab`)??``];if(s!==void 0)return r(ot,{to:at(`access`,{integration:s}),replace:!0});let c=ht(`/system/identity`,{t:e,isAdmin:!0})??{icon:y,title:e(`system.identity`,`Identity & Access`)},l=t.get(`tab`)??`users`,u=t.get(`integration`),d=l===it.access.tab?_n(u,n.requestCreate):l===`certificates`?Fr(()=>o(!0)):void 0;return r(xt,{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:it.access.tab,label:e(`systemPage.identity.tokensSessions`,`Tokens & sessions`),ownedParams:st.concat([Mt.token,Mt.scoped,Mt.admin]),content:r(gn,{createRequested:n.createRequested,onCreateConsumed:n.clearCreate})},{id:Pr,label:e(`systemPage.identity.certificates`,`Certificates`),content:r(sr,{pairOpen:i,onPairClose:()=>o(!1)})},{id:it.authentication.tab,label:e(`systemPage.identity.authentication`,`Authentication`),content:r(yn,{}),ownedParams:st}]})}export{Ir as IdentityPage};
@@ -1 +0,0 @@
1
- import{C as e,G as t,J as n,K as r,R as i,S as a,V as o,Y as s,et as c,k as l,o as u,x as d,z as f}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 p,Lr as m,O as h,Q as g,Sa as _,V as v,Vn as ee,Yn as y,ar as te,ct as ne,ir as re,tn as ie,ur as ae,yt as oe}from"./player-overlays-BF9w4QU-.js";import{Ar as se}from"./client-DhfZUoXe.js";import{t as ce}from"./link-2-off-DmsjRAt7.js";import{$f as b,Bi as le,Dr as x,Hc as ue,Mr as de,Pr as fe,Ri as S,Ui as C,Wi as w,_a as pe,ap as T,ci as E,cp as D,ea as me,fr as O,ip as k,nt as he,op as A,ot as ge,pa as _e,po as j,pr as M,so as N,ya as P,zi as F}from"./src-D9hgltMI.js";import{t as I}from"./useTranslation-BJr-n0es.js";import"./mount-B2oUIKRS.js";import{At as L,Ct as R,Dt as z,Et as B,Ft as ve,Mt as ye,Nt as be,Ot as xe,Pt as Se,St as Ce,Tt as V,X as we,_t as H,bt as Te,di as Ee,fi as De,gt as Oe,jt as ke,kt as U,mi as W,ot as G,r as Ae,vt as je,xt as Me}from"./index-DPyWa2vo.js";import{t as K}from"./NodeAddonsSettingsPanel-FjpwQjGM.js";c();function Ne(e,t){return e!==void 0&&e!==``?e:t??void 0}function q(e,t,n,r,i){let a=e(`instances.kindIconTip`,`{{kind}} · {{provider}}`,{kind:t,provider:n}),o=new Set((r??[]).map(e=>`${e.field}:${e.instanceId}`)),s=Object.entries(i).filter(([e])=>o.has(e)).map(([,e])=>e);return s.length===0?a:`${a} · ${s.map(t=>e(`instances.sendsVia`,`Sends via {{name}}`,{name:t})).join(` · `)}`}function Pe({addonId:t,label:n,providerName:r,iconUrl:o,links:c}){let{t:l}=I(),u=Ne(o,G(t)),[d,f]=s({}),p=i((e,t)=>{f(n=>{if(t===null){if(!(e in n))return n;let t={};for(let[r,i]of Object.entries(n))r!==e&&(t[r]=i);return t}return n[e]===t?n:{...n,[e]:t}})},[]),m=q(l,n,r,c,d);return e(`span`,{className:`inline-flex items-center gap-1.5 text-foreground-muted`,children:[e(k,{children:[a(A,{"aria-label":m,"data-testid":`kind-icon`,children:a(J,{addonId:t,...o===void 0?{}:{iconUrl:o}})}),a(T,{children:m})]}),(c??[]).map(e=>a(Fe,{link:e,ownIcon:u,onFold:p},`${e.field}:${e.instanceId}`)),n]})}function Fe({link:n,ownIcon:r,onFold:i}){let{t:o}=I(),s=V(_e({functionCap:n.cap,...n.kind===void 0?{}:{kind:n.kind}}).data??[],n),c=Ne(s?.iconUrl,G(s?.addonId)),l=s!==void 0&&c===r,u=`${n.field}:${n.instanceId}`,d=l&&s!==void 0?s.name:null;if(t(()=>{i(u,d)},[d,u,i]),s===void 0||l)return null;let f=o(`instances.sendsVia`,`Sends via {{name}}`,{name:s.name});return e(k,{children:[a(A,{"aria-label":f,"data-testid":`linked-instance-badge`,children:a(J,{addonId:s.addonId,...s.iconUrl===void 0?{}:{iconUrl:s.iconUrl},small:!0})}),a(T,{children:f})]})}function J({addonId:e,iconUrl:t,small:n}){let r=G(e),[i,o]=s(new Set),c=[t,r].find(e=>typeof e==`string`&&e!==``&&!i.has(e));return c===void 0?null:a(`img`,{src:g(c),alt:``,className:n===!0?`h-3 w-3 max-w-none shrink-0 rounded-sm`:`h-4 w-4 max-w-none shrink-0 rounded`,onError:()=>o(e=>new Set([...e,c]))})}var Ie=[[[`addons`,`listCapabilityProviders`]],[[`addons`,`list`]]],Y=`text-[10px]`;function Le(){let e=u();return N({onSuccess:()=>{for(let t of Ie)e.invalidateQueries({queryKey:t})}})}function Re({addonId:t,displayName:n,message:r}){let{t:i}=I(),o=ne(),s=Le(),c=i(`integrationHub.addonControls.restartNamed`,`Restart {{name}}`,{name:n});return e(k,{children:[a(A,{children:a(D,{icon:s.isPending?m:y,variant:`ghost`,size:`sm`,"aria-label":c,disabled:s.isPending,onClick:()=>void o({title:i(`integrationHub.addonControls.restart2`,`Restart "{{displayName}}"?`,{displayName:n}),message:r,confirmLabel:i(`integrationHub.addonControls.restart`,`Restart`),variant:`danger`}).then(e=>e?s.mutateAsync({addonId:t}):void 0)})}),a(T,{children:c})]})}function ze({addonId:e,displayName:t,iconOnly:n=!1,description:r}){let{t:i}=I(),o=Le(),s=r??i(`integrationHub.addonControls.restartingTheAddonBouncesIts`,`Restarting the addon bounces its subprocess — the provider will briefly drop and reconnect automatically.`);return n?a(Re,{addonId:e,displayName:t,message:s}):a(x,{label:i(`integrationHub.addonControls.restart`,`Restart`),icon:y,size:`sm`,title:i(`integrationHub.addonControls.restart2`,`Restart "{{displayName}}"?`,{displayName:t}),description:s,confirmLabel:i(`integrationHub.addonControls.restart`,`Restart`),triggerVariant:`ghost`,confirmVariant:`danger`,disabled:o.isPending,action:()=>o.mutateAsync({addonId:e})})}c();var Be=600,X=l(null);function Ve({id:t,title:r,icon:i,actions:o,framed:s=!1,children:c}){let{t:l}=I(),u=f(X),m=n(null),h=`integration-section-${t}`;Z(m,u,t);let g=e(d,{children:[u===null?null:a(W,{to:u.sectionHref(t),"aria-label":l(`integrationHub.integrationSection.linkTo`,`Link to {{title}}`,{title:r}),title:l(`integrationHub.integrationSection.linkTo`,`Link to {{title}}`,{title:r}),className:`rounded p-0.5 text-foreground-subtle/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,children:a(p,{className:`h-3 w-3`,"aria-hidden":!0})}),o]});return s?a(`div`,{ref:m,className:`scroll-mt-4`,children:a(de,{headingId:h,title:r,icon:i,actions:g,children:c})}):e(`section`,{ref:m,"aria-labelledby":h,className:`scroll-mt-4 space-y-2`,children:[e(`header`,{className:`flex min-h-7 flex-wrap items-center gap-2 px-0.5`,children:[i!==void 0&&a(i,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),a(`h2`,{id:h,className:`${v} min-w-0 flex-1`,children:r}),g]}),c]})}function Z(e,t,n){let r=t?.requestedSection===n,i=t?.integrationId;o(()=>{if(!r)return;let t=()=>e.current?.scrollIntoView?.({block:`start`});t();let n=!1,i=()=>{n=!0},a=[`wheel`,`touchmove`,`keydown`];for(let e of a)window.addEventListener(e,i,{once:!0,passive:!0});let o=window.setTimeout(()=>{n||t()},Be);return()=>{window.clearTimeout(o);for(let e of a)window.removeEventListener(e,i)}},[r,i,e])}c();var Q=`max-h-72`,He=[{kind:`logs`,labelKey:`common.logs`,icon:ee},{kind:`events`,labelKey:`common.events`,icon:_}];function Ue({addonId:t,switcher:n}){let{t:r}=I(),[i,o]=s(`logs`);return e(Ve,{id:Ae,title:r(`integrationHub.addonIntegrationBody.activity`,`Activity`),framed:!0,actions:a(`div`,{className:`flex flex-wrap items-center gap-2`,children:a(`div`,{role:`group`,"aria-label":r(`integrationHub.addonIntegrationBody.activityStream`,`Activity stream`),className:`flex items-center gap-1`,children:He.map(({kind:t,labelKey:n,icon:s})=>e(b,{variant:`unstyled`,type:`button`,"aria-pressed":i===t,onClick:()=>o(t),className:`inline-flex items-center gap-1 rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${i===t?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(s,{className:`h-3 w-3`,"aria-hidden":!0}),r(n)]},t))})}),children:[n!==void 0&&a(`div`,{className:`px-3 pt-2`,children:n}),i===`logs`?a(M,{addonId:t,maxHeight:Q,showFilters:!1}):a(O,{addonId:t,category:`addon.*`,maxHeight:Q})]})}function We({addonId:t,title:n=`Settings`,subtitle:r,fieldScope:i,onClose:o}){return a(S,{open:!0,onOpenChange:e=>!e&&o(),children:e(le,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-3xl`,children:[e(C,{children:[a(w,{children:n}),r&&a(`p`,{className:`text-xs text-foreground-subtle`,children:r})]}),a(F,{children:a(K,{nodeId:null,addonIds:[t],level:`global`,...i===void 0?{}:{fieldScope:i}})})]})})}function Ge({addonId:e,title:t,onClose:n}){return a(We,{addonId:e,title:t,fieldScope:`cluster`,onClose:n})}c();var Ke={md:{tile:`h-10 w-10 rounded-lg`,img:`h-7 w-7 rounded-md p-1`,fallback:`h-5 w-5`},sm:{tile:`h-5 w-5 rounded`,img:`h-5 w-5 rounded p-0.5`,fallback:`h-3.5 w-3.5`}};function qe({addonId:e,fallback:t,tileClassName:n,size:r=`md`}){let[i,o]=s(!1),c=G(e),l=Ke[r];return a(`div`,{className:`${l.tile} flex items-center justify-center shrink-0 ${n}`,children:i||!c?a(t,{className:l.fallback,"aria-hidden":!0}):a(`img`,{src:c,alt:``,className:`${l.img} bg-white ring-1 ring-black/5`,onError:()=>o(!0)})})}var Je={ok:`bg-success`,off:`bg-foreground-subtle/60`,error:`bg-danger`,unknown:`border border-foreground-subtle bg-transparent`};function Ye(e,t){switch(t){case`ok`:return e(`instances.health.ok`,`Healthy`);case`error`:return e(`instances.health.error`,`Error`);case`off`:return e(`instances.health.off`,`Off`);case`unknown`:return e(`instances.health.unknown`,`Unknown`)}}function Xe({pills:t,selected:n,onSelect:r,fallbackIcon:i,install:o}){let{t:s}=I(),c=t.length>1;return!c&&o===void 0?null:a(`div`,{className:`px-3 pt-2`,children:e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[c&&a(`div`,{role:`group`,"aria-label":s(`instances.filterByProvider`,`Filter by provider`),className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:t.map(t=>e(b,{variant:`unstyled`,type:`button`,"aria-pressed":n===t.addonId,"data-testid":`instance-pill-${t.addonId}`,onClick:()=>r(n===t.addonId?null:t.addonId),className:`inline-flex min-w-0 max-w-full items-center gap-1.5 rounded-full border py-1 pl-1 pr-2.5 text-xs transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 ${n===t.addonId?`border-primary bg-primary/10 text-primary font-medium`:`border-border bg-surface text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(qe,{addonId:t.addonId,fallback:i,tileClassName:``,size:`sm`}),a(`span`,{className:`truncate`,children:t.name}),a(`span`,{className:`shrink-0 text-[10px] font-normal text-foreground-subtle`,children:t.count}),a(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${Je[t.health]}`,"aria-hidden":!0}),a(`span`,{className:`sr-only`,children:Ye(s,t.health)})]},t.addonId))}),o!==void 0&&e(W,{to:se(o.capability),className:`inline-flex min-w-0 max-w-full items-center gap-1.5 rounded-full border py-1 pl-1 pr-2.5 text-xs transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 border-dashed border-border pl-2 text-foreground-subtle hover:border-primary/50 hover:text-foreground`,children:[a(re,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),a(`span`,{className:`truncate`,children:o.label})]})]})})}function Ze(e){let t=ue({onSuccess:e.onSuccess,onError:t=>e.onError?.(t.message)});return{mutate:e=>t.mutate({...e}),isPending:t.isPending}}c();function Qe({row:t,pinning:n,onChanged:r}){let{t:i}=I(),o=u(),[c,l]=s(null),d=Ze({onSuccess:()=>{l(null),o.invalidateQueries({queryKey:[H]}),r?.()},onError:l}),f=t.notRunning===void 0?null:i(`providerInstances.addonNotRunning`,`{{addon}} is not running: start it first`,{addon:t.providerName});return e(`span`,{className:`flex flex-col items-start gap-1`,title:f??void 0,children:[a(E,{checked:t.enabled,disabled:d.isPending||f!==null,"aria-label":i(`providerInstances.enable`,`Enable {{name}}`,{name:t.name}),"data-testid":`instance-switch-${t.id}`,onCheckedChange:e=>{l(null),d.mutate({addonId:t.addonId,id:t.id,enabled:e})}}),f!==null&&a(`span`,{className:`text-[11px] text-foreground-subtle`,children:f}),n>0&&a(`span`,{className:`text-[11px] text-foreground-subtle`,children:i(`providerInstances.pinnedBy`,{count:n})}),c!==null&&a(`span`,{className:`text-[11px] text-danger`,role:`alert`,children:i(`providerInstances.switchFailed`,`Could not change {{name}}: {{message}}`,{name:t.name,message:c})})]})}c();var $e=`instance`;function $(t){return e(k,{children:[a(A,{children:a(D,{...t})}),a(T,{children:t[`aria-label`]})]})}function et(e){let t=[e.status?.detail,e.lastCheckedAt===void 0?void 0:new Date(e.lastCheckedAt).toLocaleString()].filter(e=>e!==void 0&&e.length>0);return t.length>0?t.join(` · `):void 0}function tt({row:t}){let{t:n}=I();return t.enabled?e(`span`,{className:`flex flex-wrap items-center gap-1`,children:[a(P,{variant:t.configured?`success`:`default`,children:t.configured?n(`providerInstances.configured`,`Configured`):n(`providerInstances.notConfigured`,`Not configured`)}),t.status!==void 0&&a(P,{variant:t.status.state===`error`?`danger`:t.status.state===`ok`?`success`:`default`,title:et(t),children:ke(t.status)})]}):a(`span`,{className:`flex flex-wrap items-center gap-1`,children:a(P,{variant:`default`,children:n(`providerInstances.off`,`Off`)})})}function nt(e,t){return e.kind===`instance`&&e.kindLabel!==void 0&&e.kindLabel.length>0?e.kindLabel:t??``}function rt({row:e,functionCap:t}){let{t:n}=I(),r=u(),i=j({onSuccess:()=>void r.invalidateQueries()});return a(E,{checked:e.isActive,disabled:i.isPending,"aria-label":n(`providerInstances.enable`,`Enable {{name}}`,{name:e.providerName}),onCheckedChange:n=>i.mutate({capName:t,addonId:e.addonId,enabled:n})})}function it({functionCap:t,icon:n,title:o,subtitle:c,emptyTitle:l,emptyDescription:f,addLabel:g,install:_,extraColumns:v,lead:ee,rowActions:y,fixedRowActions:se,canDelete:le,onDeleteRefused:x,pageActions:ue,typedId:S,rowFilter:C,testLabel:w,testHint:T,defaultKindLabel:E}){let{t:D}=I(),O=oe(),k=u(),A=ne(),j=je(t),M=he({editKey:$e,newKey:`${$e}-new`}),[N,F]=s(null),[L,z]=s(null),B=_e({functionCap:`notification-output`}),V=i(e=>ye(B.data??[],e).length,[B.data]),[Oe,ke]=s(null),[U,W]=s(null),G=r(()=>Me(j.holders),[j.holders]),Ae=r(()=>xe(j.functionProviders,j.rows,j.displayNames),[j.functionProviders,j.rows,j.displayNames]),K=Ae.some(e=>e.addonId===U)?U:null,Ne=r(()=>{let e=Ce(j.rows,K);return C===void 0?e:e.filter(C)},[j.rows,K,C]),q=i(e=>j.displayNames.get(e)??e,[j.displayNames]),Fe=i(async e=>{F(e.key),z(null);try{let t=await O.trpcClient.integrationInstances.testInstance.mutate({addonId:e.addonId,id:e.id,values:{}});z({name:e.name,verdict:ve(t)})}catch(t){let n=t instanceof Error?t.message:String(t);z({name:e.name,verdict:{status:`inconclusive`,error:n}})}finally{F(null)}},[O]),J=i(async e=>{let t=ye(B.data??[],e.id),n=t.length>0?` ${D(`providerInstances.deletePinned`,`These notification targets use it and will stop delivering: {{names}}.`,{names:t.join(`, `)})}`:``;if(await A({title:D(`providerInstances.deleteTitle`,`Delete {{name}}?`,{name:e.name}),message:`${D(`providerInstances.deleteMessage`,`The record and its stored credentials are removed.`)}${n}`,confirmLabel:D(`common.delete`,`Delete`),variant:`danger`}))try{await O.trpcClient.integrationInstances.deleteInstance.mutate({addonId:e.addonId,id:e.id}),await k.invalidateQueries({queryKey:[H]})}catch(t){if(x!==void 0&&await x(e,t))return;be({title:D(`providerInstances.deleteFailed`,`Could not delete`),message:`${e.name}: ${t instanceof Error?t.message:String(t)}`,severity:`critical`})}},[A,x,k,O,D,B.data]),Ie=r(()=>E!==void 0||j.rows.some(e=>e.kind===`instance`&&e.kindLabel!==void 0),[j.rows,E]),Y=i((e,t)=>{e!==void 0&&De(Ee(e,t),()=>{k.invalidateQueries({queryKey:[H]})})},[k]),Le=r(()=>[{key:`name`,nowrap:!1,header:D(`providerInstances.colName`,`Name`),sortValue:e=>e.name,render:t=>e(`span`,{className:`flex flex-col`,children:[a(`span`,{className:`font-medium ${t.kind===`instance`&&!t.enabled?`text-foreground-muted`:`text-foreground`}`,children:t.name}),t.kind===`fixed`&&t.description.length>0&&a(`span`,{className:`line-clamp-2 text-[11px] text-foreground-subtle`,title:t.description,children:t.description})]})},{key:`provider`,header:D(`providerInstances.colProvider`,`Provider`),sortValue:e=>e.providerName,render:e=>a(`span`,{className:`text-foreground-muted`,children:e.providerName})},...Ie?[{key:`kind`,header:D(`providerInstances.colKind`,`Kind`),sortValue:e=>nt(e,E),render:e=>{let t=nt(e,E);return t===``?a(`span`,{className:`text-foreground-muted`}):a(Pe,{addonId:e.addonId,providerName:e.providerName,label:t,...e.kind===`instance`&&e.kindIconUrl!==void 0?{iconUrl:e.kindIconUrl}:{},...e.kind===`instance`&&e.links!==void 0?{links:e.links}:{}})}}]:[],{key:`state`,header:D(`instances.colStatus`,`Status`),notSortableReason:D(`providerInstances.stateNotSortable`,`A row carries a badge, not a value to order by.`),render:e=>e.kind===`instance`?a(tt,{row:e}):a(P,{variant:e.isActive?`success`:`default`,children:e.isActive?D(`instances.active`,`Active`):D(`providerInstances.off`,`Off`)})},{key:`on`,header:D(`providerInstances.colOn`,`On`),notSortableReason:D(`providerInstances.onNotSortable`,`A switch is not a value to order by.`),render:e=>e.kind===`fixed`?a(rt,{row:e,functionCap:t}):a(Qe,{row:e,pinning:V(e.id)})},...v??[],{key:`actions`,align:`right`,notSortableReason:D(`providerInstances.actionsNotSortable`,`Row actions are not values.`),render:t=>e(`span`,{className:`inline-flex items-center gap-1`,children:[t.kind===`instance`&&t.connectPath!==void 0&&a($,{icon:p,variant:`ghost`,size:`sm`,"aria-label":D(`providerInstances.connectRow`,`Connect {{name}}`,{name:t.name}),onClick:()=>Y(t.connectPath,t.id)}),t.kind===`instance`&&t.disconnectPath!==void 0&&a($,{icon:ce,variant:`ghost`,size:`sm`,"aria-label":D(`providerInstances.disconnectRow`,`Disconnect {{name}}`,{name:t.name}),onClick:()=>Y(t.disconnectPath,t.id)}),t.kind===`instance`&&t.canTest&&a($,{icon:N===t.key?m:te,variant:`ghost`,size:`sm`,"aria-label":D(`providerInstances.testRow`,`Test {{name}}`,{name:t.name}),disabled:N!==null,onClick:()=>void Fe(t)}),t.kind===`instance`&&y?.(t),t.kind===`fixed`&&se?.(t),a($,{icon:ae,variant:`ghost`,size:`sm`,"aria-label":D(`providerInstances.editRow`,`Edit {{name}}`,{name:t.name}),onClick:()=>M.openEdit(R(t.addonId,t.kind===`instance`?t.id:void 0))}),a(ze,{iconOnly:!0,addonId:t.addonId,displayName:t.providerName,description:D(`providerInstances.restartConfirm`,`Restarts the addon on the hub. If it shares a runner group, every addon in that group restarts with it.`)}),t.kind===`instance`&&(le?.(t)??!0)&&a($,{icon:ie,variant:`ghost`,size:`sm`,"aria-label":D(`providerInstances.deleteRow`,`Delete {{name}}`,{name:t.name}),onClick:()=>void J(t)})]})}],[v,M,t,V,y,se,le,J,Y,Fe,Ie,E,D,N]),Re;Re=j.state===`error`?a(`div`,{className:`p-3`,children:a(pe,{title:D(`providerInstances.loadFailed`,`Could not load the list`),message:j.error??``,onRetry:j.refetch})}):j.state===`pending`?e(`div`,{className:`flex items-center gap-2 p-3 text-xs text-foreground-subtle`,children:[a(m,{className:`h-3 w-3 animate-spin`}),D(`providerInstances.loading`,`Loading…`)]}):j.rows.length===0?a(me,{icon:n,title:l,description:f}):a(fe,{columns:Le,rows:Ne,rowKey:e=>e.key,bordered:!1,emptyMessage:D(`instances.noneForProvider`,`This provider has no instance yet.`)});let Be=j.holders.filter(e=>!G.includes(e)).map(e=>q(e.addonId)),X=G.length>0?void 0:Be.length>0?D(`instances.addBlocked`,`{{names}}: only one instance is allowed and it already exists.`,{names:Be.join(`, `)}):D(`instances.addNone`,`No provider here can hold instances.`),Ve=G.filter(e=>e.addonId===K),Z=Te(Ve.length>0?Ve:G,q),Q=e(d,{children:[c!==void 0&&a(`p`,{className:`px-3 pt-2 text-xs text-foreground-muted`,children:c}),j.state===`ready`&&X!==void 0&&a(`p`,{className:`px-3 pt-1 text-[11px] text-foreground-subtle`,children:X}),j.state===`ready`&&e(d,{children:[e(ge,{children:[ue?.(j.rows.filter(e=>e.kind===`instance`)),e(b,{size:`sm`,variant:`primary`,disabled:X!==void 0,title:X,onClick:()=>{let e=Z.length===1?Z[0]:void 0;e===void 0?M.openNew():M.openEdit(R(e.addonId,null,e.kind))},children:[a(re,{className:`h-3.5 w-3.5`}),g]})]}),a(Xe,{pills:Ae,selected:K,onSelect:W,fallbackIcon:n,..._===void 0?{}:{install:_}})]}),Re,j.state===`ready`&&j.rows.length>0&&a(at,{rows:j.rows,selected:Oe,onSelect:ke}),L!==null&&e(`div`,{className:`space-y-1 p-3`,children:[a(`p`,{className:`text-[11px] font-medium text-foreground`,children:L.name}),a(Se,{verdict:L.verdict})]}),j.state===`ready`&&M.state.mode===`new`&&a(we,{open:!0,onClose:M.close,pickFrom:{title:g,providers:Z.map(e=>({addonId:e.addonId,name:e.label,description:e.kind===void 0?j.descriptions.get(e.addonId)??``:e.providerName,...e.kind===void 0?{}:{kind:e.kind},...e.iconUrl===void 0?{}:{iconUrl:e.iconUrl}})),onPick:(e,t)=>M.openEdit(R(e,null,t))}}),j.state===`ready`&&M.state.mode===`edit`&&a(ot,{refValue:M.state.id,data:j,nameOf:q,onClose:M.close,functionCap:t,onOpen:(e,t)=>M.openEdit(R(e,t)),...ee===void 0?{}:{lead:ee},...S===void 0?{}:{typedId:S},...w===void 0?{}:{testLabel:w},...T===void 0?{}:{testHint:T}},M.state.id)]});return o===void 0?a(`section`,{"aria-label":g,className:h,children:Q}):a(de,{headingId:`provider-instances-${t}`,title:o,icon:n,children:Q})}function at({rows:e,selected:t,onSelect:n}){let{t:i}=I(),o=r(()=>U(e),[e]),s=o[0];if(s===void 0)return null;let c=o.find(e=>e.addonId===t)??s;return a(`div`,{className:`p-3`,children:a(Ue,{addonId:c.addonId,switcher:o.length>1?a(`div`,{role:`group`,"aria-label":i(`providerInstances.activityProvider`,`Activity of`),className:`flex flex-wrap items-center gap-1`,children:o.map(e=>a(b,{variant:`unstyled`,type:`button`,"aria-pressed":e.addonId===c.addonId,onClick:()=>n(e.addonId),className:`rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${e.addonId===c.addonId?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.name},e.addonId))}):void 0})})}function ot({refValue:e,data:t,nameOf:n,onClose:r,onOpen:i,lead:o,typedId:s,functionCap:c,testLabel:l,testHint:u}){let d=z(e);if(d.kind===`fixed`)return a(Ge,{addonId:d.addonId,title:n(d.addonId),onClose:r});let f=t.holders.find(e=>e.addonId===d.addonId);if(f===void 0)return null;let p=d.kind===`instance`?f.instances.find(e=>e.id===d.id)??null:null;if(d.kind===`instance`&&p===null)return null;let m=d.kind===`create`&&d.kindId!==void 0?L(f.description,c,d.kindId):null,h=m??f.description,g=m!==null&&B(f.description)?m.kinds?.[0]?.label:void 0,_=t.rows.find(e=>e.kind===`instance`&&e.addonId===d.addonId&&e.id===p?.id);return a(st,{addonId:d.addonId,...o!==void 0&&_!==void 0?{lead:o(_)}:{},providerName:g??n(d.addonId),description:h,instance:p,onClose:r,onOpen:i,...s===void 0?{}:{typedId:s},...l===void 0?{}:{testLabel:l},...u===void 0?{}:{testHint:u}})}function st(e){let{onOpen:t,onClose:r,onSaved:i,...o}=e,s=n(null),c=e.instance===null;return a(Oe,{...o,onSaved:e=>{c&&(s.current=e),i?.(e)},onClose:()=>{s.current===null?r():t(e.addonId,s.current)}})}export{qe as n,Y as r,it as t};