@camstack/addon-admin-ui 1.2.429 → 1.2.431
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.
- package/dist/assets/{AddonAssetIcon-DR35yt0E.js → AddonAssetIcon-CngGyUbH.js} +1 -1
- package/dist/assets/{Addons-gkGgGpTC.js → Addons-COSbX7Q1.js} +2 -2
- package/dist/assets/{AdminPage-DAO24U0w.js → AdminPage-BFQa1eDk.js} +1 -1
- package/dist/assets/{AdminSectionedPage-B-qoE6ra.js → AdminSectionedPage-Bb00eMTj.js} +1 -1
- package/dist/assets/AiProfiles-DGok1qYw.js +3 -0
- package/dist/assets/{BrokerForm-B3xs9aBj.js → BrokerForm-NDMOvAlu.js} +1 -1
- package/dist/assets/{Build-DeMAJfjN.js → Build-BPgFXVbn.js} +4 -4
- package/dist/assets/{Calendars-VPH-vy-o.js → Calendars-DLuwgZXW.js} +1 -1
- package/dist/assets/Cluster-BUBVih9A.js +1 -0
- package/dist/assets/ClusterStepModel-DzduELev.js +1 -0
- package/dist/assets/{CompositionEditor-BrtLjoSu.js → CompositionEditor-DTgOmFqj.js} +1 -1
- package/dist/assets/{CompositionEditorPage-D51jS9td.js → CompositionEditorPage-D73l3mqU.js} +1 -1
- package/dist/assets/Data-Wqos-WHl.js +2 -0
- package/dist/assets/{DeviceDetail-D1qU_p1k.js → DeviceDetail-CwmpXUmk.js} +2 -2
- package/dist/assets/{DeviceDoActionFields-B62Nv4K7.js → DeviceDoActionFields-DKOJoFJc.js} +1 -1
- package/dist/assets/{Devices-Cf5Exjsk.js → Devices-D_SKAo6X.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-CnEcSJ8D.js → EmbedPlayerPage-DI4ac8Wo.js} +1 -1
- package/dist/assets/Identity-C25gG2Mh.js +1 -0
- package/dist/assets/IntegrationDetail-L73oZLMf.js +1 -0
- package/dist/assets/{IntegrationHub-DdjWEObX.js → IntegrationHub-DuVgrEey.js} +1 -1
- package/dist/assets/{Integrations-CU7Ll9U_.js → Integrations-CUPpCCtl.js} +1 -1
- package/dist/assets/{Integrations-uZB2ozhn.js → Integrations-Cgm8qaox.js} +1 -1
- package/dist/assets/{Library-DSuCaXt6.js → Library-Dm0AivX3.js} +1 -1
- package/dist/assets/Locations-B2TjRBpQ.js +3 -0
- package/dist/assets/{Logs-cm-1R2Z4.js → Logs-CeX1xx9_.js} +1 -1
- package/dist/assets/{MaskShapeCanvas-CM9D4FOf.js → MaskShapeCanvas-GZ2ZMDcz.js} +1 -1
- package/dist/assets/{MotionZonesSettings-DqS8ndiK.js → MotionZonesSettings-B5gIoLVC.js} +1 -1
- package/dist/assets/MyAccess-DJvaTHrq.js +2 -0
- package/dist/assets/Network-D0uak4Dc.js +1 -0
- package/dist/assets/{NodeAddonsSettingsPanel-BMat4ckt.js → NodeAddonsSettingsPanel-kmgNnVID.js} +1 -1
- package/dist/assets/{Notifications-EPQiEZ1t.js → Notifications-DP0iwqUM.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-Bis0PO01.js → PrivacyMaskSettings-DWCvE7XZ.js} +1 -1
- package/dist/assets/Recordings-r5KE18a6.js +1 -0
- package/dist/assets/{ScanNetworkModal-dHWFmbFe.js → ScanNetworkModal-CHWsBmiM.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-SFMMIopn.js → SceneMonitorEditor-BNFYspNy.js} +1 -1
- package/dist/assets/SessionsList-OvrBa2rd.js +2 -0
- package/dist/assets/{Showroom-Er-hes9K.js → Showroom-DNgHGmg0.js} +1 -1
- package/dist/assets/{System-BDXxfgsq.js → System-CcDzJj6C.js} +1 -1
- package/dist/assets/{Terminal-B70jnm8e.js → Terminal-DpGR-56V.js} +5 -5
- package/dist/assets/{Viewer-BsGL5Dfa.js → Viewer-vqCH_LqM.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-C7iEnSHU.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DR_v3lvi.js} +1 -1
- package/dist/assets/{addon-icons-context--6Hi3qRW.js → addon-icons-context-B2Gmu49a.js} +1 -1
- package/dist/assets/{archive-DtcjevJM.js → archive-CoV271Ga.js} +1 -1
- package/dist/assets/{authed-media-LCmlAEZ5.js → authed-media-BSx10sm9.js} +1 -1
- package/dist/assets/{bell-off-eQBpwamg.js → bell-off-CQHJCxaC.js} +1 -1
- package/dist/assets/{board-model-wzCmdEKJ.js → board-model-lagHZiI7.js} +1 -1
- package/dist/assets/{boxes-DikDfAoo.js → boxes-DKr2EDaB.js} +1 -1
- package/dist/assets/circle-slash-D1CG5tRc.js +1 -0
- package/dist/assets/client-CqsEJzhO.js +358 -0
- package/dist/assets/{cloud-upload-DI9XunFf.js → cloud-upload-D3IJwdmA.js} +1 -1
- package/dist/assets/crop-sD8BDahL.js +1 -0
- package/dist/assets/{device-integration-icon-D2lWVDM2.js → device-integration-icon-BHf83qVT.js} +1 -1
- package/dist/assets/device-picker-model-JBC8n4FU.js +1 -0
- package/dist/assets/dist-C3lDDHVX.js +358 -0
- package/dist/assets/{dist-ChQzskeX.js → dist-Dlrgg5It.js} +1 -1
- package/dist/assets/{eraser-Dl5ROV0l.js → eraser-BRuYxYS4.js} +1 -1
- package/dist/assets/{hard-drive-download-B1ard6ym.js → hard-drive-download-B14E8eTo.js} +1 -1
- package/dist/assets/{history-BMhP0SFG.js → history-Dn2pnfaZ.js} +1 -1
- package/dist/assets/{hostInit-FCvre9AW.js → hostInit-3qW3eaSU.js} +1 -1
- package/dist/assets/i18n-B-IeyHf7.js +1 -0
- package/dist/assets/icons-CvJTX54k.js +1 -0
- package/dist/assets/{index-DvOECbab.js → index-mBJW996X.js} +3 -3
- package/dist/assets/key-EeG_L4W9.js +1 -0
- package/dist/assets/{key-round-yCDTbIQb.js → key-round-C9pPg55h.js} +1 -1
- package/dist/assets/{layers-c960YTPf.js → layers-DhxisKd7.js} +1 -1
- package/dist/assets/{linked-devices-model-CB7qgVjI.js → linked-devices-model-CTfAwc1p.js} +1 -1
- package/dist/assets/{list-ordered-C7hEwAd1.js → list-ordered-Ckqq8GR7.js} +1 -1
- package/dist/assets/{location-owned-usage-D28vwYJT.js → location-owned-usage-eDtNCANy.js} +1 -1
- package/dist/assets/{log-in-DFfxcqYz.js → log-in-CAiH8-Mq.js} +1 -1
- package/dist/assets/{memory-stick-BBfIGrWx.js → memory-stick-Bir-K-V7.js} +1 -1
- package/dist/assets/{message-square-plus-D8ZUT6rz.js → message-square-plus-B_0WwbBk.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-3035e647.js → mf-entry-bootstrap-0-c62ae51c.js} +2 -2
- package/dist/assets/{mic-off-w2mFOBi3.js → mic-off-D5kT_DDX.js} +1 -1
- package/dist/assets/{monitor-off-DPi_gm_c.js → monitor-off-DzKNd6eJ.js} +1 -1
- package/dist/assets/{monitor-smartphone-9Ife1Trw.js → monitor-smartphone-D3ZPy75c.js} +1 -1
- package/dist/assets/mount-JBC8n4FU.js +1 -0
- package/dist/assets/{notification-schedule-field-BuLfSYLZ.js → notification-schedule-field-DaKiveMR.js} +1 -1
- package/dist/assets/{octagon-alert-C-jH7VH_.js → octagon-alert-BYNvsZ0Q.js} +1 -1
- package/dist/assets/{player-overlays-D0U2dNvn.js → player-overlays-DFTWiQ8-.js} +1 -1
- package/dist/assets/{recycle-Bbki65G2.js → recycle-DJUuC9xt.js} +1 -1
- package/dist/assets/remoteEntry-BhYjusn-.js +1 -0
- package/dist/assets/{scan-eye-AfIM_Dlr.js → scan-eye-_otUiDbW.js} +1 -1
- package/dist/assets/{scissors-CnL6g0BO.js → scissors-BU04yNa7.js} +1 -1
- package/dist/assets/{search-x-eqJd3G8u.js → search-x-Djycej4Y.js} +1 -1
- package/dist/assets/{send-B72RQ9UL.js → send-BNY2bJqA.js} +1 -1
- package/dist/assets/{settings-2-CXZ6DVRg.js → settings-2-BxpLi7pY.js} +1 -1
- package/dist/assets/{speaker-CcCWWecW.js → speaker-BspD0ixN.js} +1 -1
- package/dist/assets/src-CE3hNyCx.js +67 -0
- package/dist/assets/{timer-reset-B9Lihcw9.js → timer-reset-CPRU92uv.js} +1 -1
- package/dist/assets/{ungroup-D753owNE.js → ungroup-oYlFn3LE.js} +1 -1
- package/dist/assets/{unlink-DzoLNfsq.js → unlink-D0eJ5vAc.js} +1 -1
- package/dist/assets/{usb-CuSU-_EY.js → usb-C24Ua3ty.js} +1 -1
- package/dist/assets/{use-scenes-feed-CZjJNxfD.js → use-scenes-feed-DzzIer2d.js} +1 -1
- package/dist/assets/{use-stationary-objects-BoGqWyLV.js → use-stationary-objects-C-l1Z5zI.js} +1 -1
- package/dist/assets/useEventInvalidation-JBC8n4FU.js +1 -0
- package/dist/assets/{useNodeUrlSelection-BA6CgjTU.js → useNodeUrlSelection-Ba-ed7zb.js} +1 -1
- package/dist/assets/user-round-JzUTTasm.js +1 -0
- package/dist/assets/{user-x-PK8sSsso.js → user-x-CdpX6b_D.js} +1 -1
- package/dist/assets/{video-BBtESt54.js → video-vLKHp9E_.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BKfTL-9e.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-D83o1ikp.js} +2 -2
- package/dist/index.html +10 -10
- package/dist/server/addon.js +192 -30
- package/package.json +1 -1
- package/dist/assets/AiProfiles-BXcreqZP.js +0 -3
- package/dist/assets/Cluster-B-k0M79z.js +0 -1
- package/dist/assets/ClusterStepModel-DaAc_6nI.js +0 -1
- package/dist/assets/Data-IfJuKcwc.js +0 -2
- package/dist/assets/Identity-DNE80jdX.js +0 -1
- package/dist/assets/IntegrationDetail-LKbiJFU3.js +0 -1
- package/dist/assets/Locations-BeaznsZS.js +0 -3
- package/dist/assets/MyAccess-Dxb11B6h.js +0 -2
- package/dist/assets/Network-BCDUHSB0.js +0 -1
- package/dist/assets/Recordings-BCeoXxL4.js +0 -1
- package/dist/assets/SessionsList-BRTwG3uv.js +0 -2
- package/dist/assets/circle-slash-YVgGJTpJ.js +0 -1
- package/dist/assets/client-DYbvGOid.js +0 -358
- package/dist/assets/crop-CxZbpOyK.js +0 -1
- package/dist/assets/device-picker-model-C4w1vbly.js +0 -1
- package/dist/assets/dist-CPO0KWoy.js +0 -358
- package/dist/assets/file-up-WS3s_T9x.js +0 -1
- package/dist/assets/i18n-Vb3uBp7P.js +0 -1
- package/dist/assets/icons-DocdgFuy.js +0 -1
- package/dist/assets/key-B1M6i1mf.js +0 -1
- package/dist/assets/mount-C4w1vbly.js +0 -1
- package/dist/assets/remoteEntry-DYVoozgD.js +0 -1
- package/dist/assets/src-CGxdJN_f.js +0 -67
- package/dist/assets/useEventInvalidation-C4w1vbly.js +0 -1
- package/dist/assets/user-round-CMg3Ndlt.js +0 -1
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{$ as e,B as t,G as n,J as r,L as i,S as a,b as o,o as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Hi as l,Hr as u,It as d,Ki as f,Kr as p,Nt as m,On as h,Pn as g,Q as _,Yr as v,_i as y,_n as b,ai as x,ar as S,di as C,dn as w,kn as T,nr as E,qi as D,ri as O,rr as k,yi as A}from"./player-overlays-D0U2dNvn.js";import{n as j,t as M}from"./cloud-upload-DI9XunFf.js";import{t as N}from"./circle-slash-YVgGJTpJ.js";import{t as P}from"./hard-drive-download-B1ard6ym.js";import{$l as F,$r as I,An as ee,Bc as L,Bn as R,Dn as te,En as z,G as B,Hc as ne,L as V,Ln as re,Nr as ie,Oc as ae,Ql as oe,Qr as se,R as ce,Rn as le,Tn as ue,Ut as de,Vc as fe,Wt as pe,Xr as me,Yr as he,Zn as H,Zr as ge,ai as _e,an as ve,ar as ye,ci as be,ea as xe,ei as Se,ii as Ce,jn as we,kn as U,li as Te,ni as Ee,oi as De,ql as Oe,ri as W,si as ke,ti as Ae,tl as je,ui as Me,z as Ne,zc as Pe}from"./src-CGxdJN_f.js";import{t as G}from"./i18n-Vb3uBp7P.js";import{t as K}from"./useTranslation-D3Is_4B6.js";import"./mount-C4w1vbly.js";import{C as Fe,Y as Ie}from"./index-DvOECbab.js";import{t as Le}from"./AdminSectionedPage-B-qoE6ra.js";import{t as Re}from"./AdminPage-DAO24U0w.js";import{n as ze}from"./authed-media-LCmlAEZ5.js";import{t as q}from"./format-size-DIxKXxtj.js";import{a as Be,c as Ve,l as He,n as Ue,o as We,s as Ge,t as Ke,u as qe}from"./location-owned-usage-D28vwYJT.js";e();function Je(e){return Object.entries(e).map(([e,t])=>`${e} ${t}`).join(` · `)}function Ye(e){return e.reduce((e,t)=>e+Object.values(t.stores).reduce((e,t)=>e+t,0),0)}function Xe(){let{t:e}=K(),t=H(),n=xe(),[i,s]=r(null),[l,u]=r(null),f=async e=>{u(null);try{s(await n.mutateAsync({confirm:e}))}catch(e){u(e instanceof Error?e.message:String(e))}},p=async()=>{i===null||i.status!==`dry-run`||await t({title:e(`systemPage.deletedDevices.confirmTitle`,`Delete the data of deleted devices?`),message:i.devices.map(e=>`#${e.deviceId}: ${Je(e.stores)}`).join(`
|
|
2
|
-
`),confirmLabel:e(`systemPage.deletedDevices.confirmLabel`,`Delete`),variant:`danger`})&&await f(!0)},m=[{key:`device`,header:e(`systemPage.deletedDevices.device`,`Device`),render:e=>`#${e.deviceId}`},{key:`stores`,header:e(`systemPage.deletedDevices.stores`,`Data held`),nowrap:!1,render:e=>Je(e.stores)}];return a(`div`,{className:`space-y-4`,"data-testid":`deleted-devices-data`,children:[c(`p`,{className:`text-sm text-muted-foreground`,children:e(`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.`)}),a(`div`,{className:`flex flex-wrap items-center gap-2`,children:[a(R,{variant:`outline`,onClick:()=>void f(!1),disabled:n.isPending,"data-testid":`deleted-devices-scan`,children:[n.isPending?c(S,{className:`mr-2 h-4 w-4 animate-spin`}):c(w,{className:`mr-2 h-4 w-4`}),e(`systemPage.deletedDevices.scan`,`Scan`)]}),i?.status===`dry-run`&&i.devices.length>0?a(R,{variant:`danger`,onClick:()=>void p(),disabled:n.isPending,"data-testid":`deleted-devices-delete`,children:[c(d,{className:`mr-2 h-4 w-4`}),e(`systemPage.deletedDevices.delete`,`Delete the data of {{count}} devices…`,{count:i.devices.length})]}):null]}),l===null?null:c(`p`,{className:`text-sm text-danger`,children:l}),i?.status===`skipped`?c(`p`,{className:`text-sm text-warning`,"data-testid":`deleted-devices-skipped`,children:e(`systemPage.deletedDevices.skipped`,`Nothing was listed or deleted: the device list could not be trusted ({{reason}}). Try again.`,{reason:i.reason??``})}):null,i!==null&&i.status!==`skipped`?a(o,{children:[c(`p`,{className:`text-sm`,"data-testid":`deleted-devices-summary`,children:i.status===`cleaned`?e(`systemPage.deletedDevices.cleaned`,`Deleted {{rows}} items of {{count}} devices.`,{rows:Ye(i.devices),count:i.devices.length}):e(`systemPage.deletedDevices.found`,`{{count}} deleted devices still hold {{rows}} items.`,{rows:Ye(i.devices),count:i.devices.length})}),c(de,{columns:m,rows:i.devices,rowKey:e=>e.deviceId,emptyMessage:e(`systemPage.deletedDevices.none`,`No data belongs to a deleted device.`)}),i.unreachable.length>0?c(`p`,{className:`text-xs text-muted-foreground`,children:e(`systemPage.deletedDevices.unreachable`,`Not asked (unreachable): {{names}}`,{names:i.unreachable.join(`, `)})}):null]}):null]})}e();function Ze(){let{t:e}=K(),r=s(),i=H(),{data:o,isLoading:l,isError:u}=ne({}),d=fe(),f=n(()=>d.data??[],[d.data]),{data:p}=ae({},{refetchOnWindowFocus:!1}),m=n(()=>Ke(o??[],p?.locations),[o,p?.locations]),{data:h}=L({},{refetchOnWindowFocus:!1}),g=n(()=>Be(h),[h]),{state:_,openNew:v,openEdit:y,close:b}=V(),[x,S]=ce(`type`),C=()=>{S(null),b()},w=e=>{S(e),v()},T=e=>{S(null),y(e.id)},E=o??[],D=_.mode===`edit`?E.find(e=>e.id===_.id)??null:null;t(()=>{_.mode===`new`&&(x===null||x===``)&&(S(null),b())},[_.mode,x,b,S]),t(()=>{_.mode===`edit`&&!l&&D===null&&(S(null),b())},[_.mode,l,D,b,S]),t(()=>{_.mode===`closed`&&x!==null&&S(null)},[_.mode,x,S]);let O=Pe({onSuccess:()=>{r.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),k=je({onSuccess:()=>{r.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),A=async(t,n)=>{He(n)&&!await i({title:e(`system.storage.disable`,`Disable "{{displayName}}"?`,{displayName:t.displayName}),message:e(`system.storage.nothingIsDeletedSetThe`,`{{consequence}} Nothing is deleted — set the location back to Read-only or Active to bring its footage back.`,{consequence:Ve(n).consequence}),confirmLabel:e(`common.disable`,`Disable`),variant:`danger`})||k.mutate(Ge(t,{mode:n}))},j=async t=>{if(await i({title:e(`system.storage.deleteLocation`,`Delete location "{{displayName}}"?`,{displayName:t.displayName}),message:e(`system.storage.thisRemovesTheLocationRecord`,`This removes the location record. Files on disk are not deleted; the underlying directory or remote path stays untouched.`),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`}))try{await O.mutateAsync({id:t.id}),_.mode===`edit`&&_.id===t.id&&C()}catch(n){await i({title:e(`system.storage.deleteAnyway`,`Delete anyway?`),message:e(`system.storage.forcingNote`,{error:n instanceof Error?n.message:String(n)}),confirmLabel:e(`system.storage.forceDelete`,`Force delete`),variant:`danger`})&&O.mutate({id:t.id,force:!0},{onSuccess:()=>{_.mode===`edit`&&_.id===t.id&&C()}})}},M=n(()=>{let e=new Map;for(let t of o??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[o]),N=l||d.isLoading,P=u||d.isError,F=_.mode===`new`&&x!==null&&x!==``,I=_.mode===`edit`&&D!==null;return a(Re,{embedded:!0,children:[N&&c(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:e(`system.storage.loadingLocations`,`Loading locations…`)}),P&&c(`div`,{className:`text-xs text-danger`,children:e(`system.storage.failedToLoadStorageLocations`,`Failed to load storage locations.`)}),!N&&!P&&a(`div`,{className:`space-y-3`,children:[f.length===0&&c(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:e(`system.storage.noStorageLocationsDeclaredBy`,`No storage locations declared by any installed addon.`)}),f.map(e=>c(Ue,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:M.get(e.id)??[],onAdd:w,onEdit:T,onDelete:e=>{j(e)},ownedBytesById:m,drainById:g,onSetMode:(e,t)=>{A(e,t)}},e.id))]}),F&&x!==null&&c(qe,{initialType:x,onClose:C,onCreated:()=>{r.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),C()}}),I&&D!==null&&c(We,{location:D,onClose:C,onSaved:()=>{r.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),C()}})]})}var Qe={settings:{labelKey:`helpers.backupDatabases.settings.label`,descriptionKey:`helpers.backupDatabases.settings.description`},events:{labelKey:`helpers.backupDatabases.events.label`,descriptionKey:`helpers.backupDatabases.events.description`},history:{labelKey:`helpers.backupDatabases.history.label`,descriptionKey:`helpers.backupDatabases.history.description`}},$e=Object.keys(Qe),J=[`settings`];function et(){return G.t(`helpers.backupDatabases.notCreated`)}function tt(e){return G.t(Qe[e].labelKey)}function nt(e){return G.t(Qe[e].descriptionKey)}function Y(e){let t=new Set(e);return $e.filter(e=>t.has(e))}function X(e){return e!==void 0&&e.length>0?Y(e):J}function rt(e){return Y(e)}function it(e,t){return t===void 0||!t.answered?`unknown`:t.databases.includes(e)?`present`:`absent`}function at(e,t,n){return it(e,t)===`absent`&&!n.has(e)}function ot(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function st(e){return!e.includes(`settings`)}function ct(e){return{databases:[...rt(e)]}}function lt(e,t){return e!==void 0&&e.length>0?Y(e):t!==void 0&&t.length>0?Y(t.map(e=>e.databaseId??`settings`)):J}function Z({databases:e}){let{t}=K();return a(`span`,{className:`flex flex-wrap items-center gap-1`,"data-testid":`backup-database-badges`,children:[e.map(e=>c(ye,{variant:e===`settings`?`primary`:`info`,style:`fill`,size:`sm`,children:tt(e)},e)),st(e)&&c(ye,{variant:`warning`,style:`fill`,size:`sm`,children:t(`backup.backupDatabaseBadges.snapshotsOnly`,`Snapshots only`)})]})}e();var ut=[[`backup`,`listDestinations`]],dt=[`backup`,`listArchives`];function ft({destinationId:e,restoreSupported:t,onOpenRestoreWizard:o}){let{t:l}=K(),f=s(),p=H(),{data:m,isLoading:h,isError:g}=Ae({destinationId:e}),_=m??[],v=me({onSuccess:()=>{f.invalidateQueries({queryKey:[[...dt]]}),f.invalidateQueries({queryKey:ut})}}),y=i(async t=>{await p({title:l(`backup.archiveList.deleteThisArchive`,`Delete this archive?`),message:l(`backup.archiveList.permanentlyDeletesAndFrees`,`Permanently deletes "{{value1}}" and frees {{value2}}.`,{value1:t.label??t.id,value2:q(t.sizeBytes)}),confirmLabel:l(`common.delete`,`Delete`),variant:`danger`})&&v.mutate({destinationId:e,backupId:t.id})},[p,e,v,l]),[x,C]=r(null),w=i(async t=>{C(t.id);try{let n=await ze(pt(e,t.id)),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${t.label??t.id}.tar.gz${t.encryption===void 0?``:`.csbk`}`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}finally{C(null)}},[e]),T=n(()=>[..._].toSorted((e,t)=>t.createdAt-e.createdAt),[_]);return h?c(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:l(`backup.archiveList.loadingArchives`,`Loading archives…`)}):g?c(`div`,{className:`text-xs text-danger py-2`,children:l(`backup.archiveList.failedToReadManifestFor`,`Failed to read manifest for this destination`)}):T.length===0?c(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:l(`backup.archiveList.noArchivesAtThisDestination`,`No archives at this destination yet.`)}):c(de,{columns:[{key:`when`,header:l(`backup.archiveList.when`,`When`),sortValue:e=>e.createdAt,render:e=>c(`span`,{className:`tabular-nums`,children:mt(e.createdAt)})},{key:`label`,header:l(`backup.archiveList.label`,`Label`),sortValue:e=>e.label??null,render:e=>a(`span`,{className:`inline-flex items-center gap-1`,children:[e.encryption!==void 0&&c(E,{className:`h-3 w-3 text-success`,"aria-label":l(`backup.archiveList.encryptedRestoreNeedsBackupKey`,`encrypted — restore needs backup key {{keyId}}`,{keyId:e.encryption.keyId})}),e.label??c(`span`,{className:`text-foreground-subtle italic`,children:`—`})]})},{key:`databases`,header:l(`backup.archiveList.databases`,`Databases`),nowrap:!1,notSortableReason:`Database badges`,render:e=>c(Z,{databases:X(e.databases)})},{key:`includes`,header:l(`backup.archiveList.files`,`Files`),nowrap:!1,notSortableReason:`Location list`,render:e=>e.locations.length>0?c(`span`,{className:`text-foreground-subtle`,children:e.locations.join(`, `)}):c(`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=>c(`span`,{className:`tabular-nums`,children:q(e.sizeBytes)})},{key:`actions`,header:``,align:`right`,notSortableReason:`Actions`,render:n=>a(`span`,{className:`flex items-center justify-end gap-1`,children:[a(R,{variant:`ghost`,size:`sm`,onClick:()=>{w(n)},disabled:x===n.id,title:l(`backup.archiveList.downloadArchive`,`Download archive`),children:[x===n.id?c(S,{className:`h-3 w-3 animate-spin`}):c(u,{className:`h-3 w-3`}),l(`backup.archiveList.download`,`Download`)]}),t&&o&&a(R,{variant:`ghost`,size:`sm`,onClick:()=>o({destinationId:e,archiveId:n.id}),title:l(`backup.archiveList.restoreFromThisArchive`,`Restore from this archive`),children:[c(b,{className:`h-3 w-3`}),l(`backup.archiveList.restore`,`Restore`)]}),c(F,{variant:`ghost`,size:`sm`,icon:d,"aria-label":l(`backup.archiveList.delete`,`Delete {{value1}}`,{value1:n.label??n.id}),disabled:v.isPending,onClick:()=>{y(n)}})]})}],rows:T,rowKey:e=>e.id,minWidthPx:760,emptyMessage:l(`backup.archiveList.noArchivesAtThisDestination`,`No archives at this destination yet.`)})}function pt(e,t){return _(`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}function mt(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}e();var ht=[[`backup`,`listSchedules`]];function gt({onEdit:e,onOpenRestoreWizard:t}){let{t:o}=K(),{data:s,isLoading:l,isError:u,error:d,refetch:f}=_e(),p=s??[],m=W().data??[],h=n(()=>{let e=new Map;for(let t of m)e.set(t.id,t);return e},[m]),[g,_]=r(null),v=i(e=>{_(t=>t===e?null:e)},[]),y=g===null?null:p.find(e=>e.id===g)??null,b=n(()=>_t({destById:h,expandedId:g,onToggleExpand:v,onEdit:e}),[h,g,v,e]);return l?a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle animate-pulse`,children:[c(S,{className:`h-3.5 w-3.5 animate-spin`}),o(`backup.backupEntriesTable.loadingBackupEntries`,`Loading backup entries…`)]}):u?c(re,{title:o(`backup.backupEntriesTable.failedToLoadBackupEntries`,`Failed to load backup entries`),message:d instanceof Error?d.message:o(`backup.backupEntriesTable.unknownError`,`Unknown error`),onRetry:()=>void f()}):p.length===0?c(le,{icon:j,title:o(`backup.backupEntriesTable.noBackupEntriesYet`,`No backup entries yet`),description:o(`backup.backupEntriesTable.createOneToScheduleBackups`,`Create one to schedule backups across one or more storage locations.`)}):a(`div`,{className:`space-y-2`,children:[c(de,{columns:b,rows:p,rowKey:e=>e.id,minWidthPx:980,maxBodyHeight:pe,emptyMessage:o(`backup.backupEntriesTable.noBackupEntriesYet`,`No backup entries yet`),onRowClick:t=>e(t)}),y!==null&&c(wt,{row:y,destById:h,...t?{onOpenRestoreWizard:t}:{}})]})}function _t(e){return[{key:`expand`,header:``,width:`w-8`,nowrap:!0,notSortableReason:`Expand control`,render:t=>{let n=e.expandedId===t.id;return c(F,{variant:`ghost`,size:`sm`,icon:n?A:y,"aria-label":n?G.t(`backup.backupEntriesTable.hideArchives`,`Hide archives`):G.t(`backup.backupEntriesTable.showArchives`,`Show archives`),"aria-expanded":n,onClick:n=>{n.stopPropagation(),e.onToggleExpand(t.id)}})}},{key:`entry`,header:G.t(`backup.backupEntriesTable.entry`,`Entry`),sortValue:e=>e.label,render:e=>a(`span`,{className:`flex min-w-0 flex-col`,children:[c(`span`,{className:`truncate font-medium text-foreground`,children:e.label||G.t(`backup.backupEntriesTable.unnamed`,`(unnamed)`)}),e.lastRunAt!==void 0&&c(`span`,{className:`text-[10px] text-foreground-subtle`,children:G.t(`backup.backupEntriesTable.lastRun`,{when:new Date(e.lastRunAt).toLocaleString()})})]})},{key:`enabled`,header:G.t(`backup.backupEntriesTable.enabled`,`Enabled`),width:`w-20`,nowrap:!0,sortValue:e=>+!!e.enabled,render:e=>c(`span`,{onClick:e=>e.stopPropagation(),children:c(xt,{row:e})})},{key:`databases`,header:G.t(`backup.backupEntriesTable.backsUp`,`Backs up`),nowrap:!1,notSortableReason:`Database badges`,render:e=>c(Z,{databases:X(e.databases)})},{key:`locations`,header:G.t(`backup.backupEntriesTable.locations`,`Locations`),nowrap:!1,notSortableReason:`Location chips`,render:t=>c(vt,{row:t,destById:e.destById})},{key:`retention`,header:G.t(`backup.backupEntriesTable.retention`,`Retention`),width:`w-24`,nowrap:!0,sortValue:e=>e.retentionCount,render:e=>c(`span`,{onClick:e=>e.stopPropagation(),children:c(St,{row:e})})},{key:`schedule`,header:G.t(`backup.backupEntriesTable.schedule`,`Schedule`),width:`w-48`,nowrap:!0,sortValue:e=>e.cron,render:e=>c(yt,{row:e})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:t=>c(`span`,{onClick:e=>e.stopPropagation(),children:c(Ct,{row:t,onEdit:()=>e.onEdit(t)})})}]}function vt({row:e,destById:t}){let{t:n}=K();return e.locationIds.length===0?c(`span`,{className:`text-[11px] italic text-danger`,children:n(`backup.backupEntriesTable.noLocations`,`No locations`)}):c(`span`,{className:`flex flex-wrap gap-1`,children:e.locationIds.map(e=>c(`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 yt({row:e}){let{t}=K(),n=e.cron.trim().length>0;return a(`span`,{className:`flex flex-col items-start gap-0.5`,children:[a(`span`,{className:`inline-flex items-center gap-1`,children:[c(j,{className:`h-3 w-3 text-foreground-subtle`}),c(`span`,{className:`font-mono text-[11px] text-foreground`,children:n?e.cron:t(`backup.backupEntriesTable.manual`,`Manual`)})]}),n&&e.nextRunAt!==void 0&&c(`span`,{className:`text-[10px] text-foreground-subtle`,children:G.t(`common.nextRun`,{when:new Date(e.nextRunAt).toLocaleString()})})]})}function bt(e){return n(()=>({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 xt({row:e}){let{t}=K(),n=s(),r=Me({onSuccess:()=>{n.invalidateQueries({queryKey:ht})}}),i=bt(e);return c(`label`,{className:`inline-flex cursor-pointer items-center`,children:c(`input`,{type:`checkbox`,className:`accent-primary`,checked:e.enabled,disabled:r.isPending,onChange:e=>r.mutate({...i,enabled:e.target.checked}),"aria-label":t(`backup.backupEntriesTable.enable`,`Enable {{value1}}`,{value1:e.label||e.id})})})}function St({row:e}){let{t:n}=K(),i=s(),a=Me({onSuccess:()=>{i.invalidateQueries({queryKey:ht})}}),o=bt(e),[l,u]=r(String(e.retentionCount));return t(()=>{u(String(e.retentionCount))},[e.retentionCount]),c(oe,{type:`number`,min:1,max:1e3,value:l,disabled:a.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&&a.mutate({...o,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":n(`backup.backupEntriesTable.retentionFor`,`Retention for {{value1}}`,{value1:e.label||e.id})})}function Ct({row:e,onEdit:t}){let{t:n}=K(),r=s(),i=H(),o=ge({onSuccess:()=>{r.invalidateQueries({queryKey:ht})}}),l=Te({onMutate:()=>{r.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})},onSuccess:()=>{r.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),r.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),r.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})}}),u=()=>{e.locationIds.length!==0&&l.mutate({destinations:[...e.locationIds],...e.dataSources&&e.dataSources.length>0?{locations:[...e.dataSources]}:{},label:e.label,retentionCount:e.retentionCount,databases:[...X(e.databases)]})},f=async()=>{await i({title:n(`backup.backupEntriesTable.deleteBackupEntry`,`Delete backup entry?`),message:n(`backup.backupEntriesTable.willStopRunningExistingArchives`,`"{{value1}}" will stop running. Existing archives are kept.`,{value1:e.label||e.id}),confirmLabel:n(`common.delete`,`Delete`),variant:`warning`})&&o.mutate({id:e.id})};return a(`span`,{className:`flex items-center justify-end gap-1.5`,children:[a(R,{size:`sm`,type:`button`,onClick:u,disabled:l.isPending||e.locationIds.length===0,title:n(`backup.backupEntriesTable.runThisEntryNow`,`Run this entry now`),children:[l.isPending?c(S,{className:`h-3 w-3 animate-spin`}):c(T,{className:`h-3 w-3`}),n(`backup.backupEntriesTable.runNow`,`Run now`)]}),c(F,{variant:`ghost`,size:`sm`,icon:g,"aria-label":n(`backup.backupEntriesTable.edit`,`Edit {{value1}}`,{value1:e.label||e.id}),onClick:t}),c(F,{variant:`ghost`,size:`sm`,icon:d,"aria-label":n(`backup.backupEntriesTable.delete`,`Delete {{value1}}`,{value1:e.label||e.id}),disabled:o.isPending,onClick:()=>{f()}})]})}function wt({row:e,destById:t,onOpenRestoreWizard:n}){let{t:r}=K();return a(`div`,{className:`space-y-4 rounded-lg border border-border bg-background/30 px-4 py-3`,children:[c(`p`,{className:`text-[11px] font-medium text-foreground-subtle`,children:r(`backup.backupEntriesTable.archivesFor`,{name:e.label||e.id})}),e.locationIds.length===0&&c(`p`,{className:`text-xs italic text-foreground-subtle`,children:r(`backup.backupEntriesTable.thisEntryHasNoLocations`,`This entry has no locations selected.`)}),e.locationIds.map(e=>a(`div`,{className:`space-y-1.5`,children:[c(`div`,{className:`text-[11px] font-medium text-foreground-subtle`,children:t.get(e)?.displayName??e}),c(ft,{destinationId:e,restoreSupported:t.get(e)?.restoreSupported??!0,...n?{onOpenRestoreWizard:n}:{}})]},e))]})}function Tt({selected:e,onChange:t,disabled:n=!1,testId:r=`backup-databases`}){let{t:i}=K(),o=Ee().data,s=e.size>0&&st(Y(e)),l=e.size===0?`Pick at least one.`:s?`Snapshots only: configuration and files are not part of this backup.`:null;return c(B,{label:i(`backup.backupDatabasePicker.whatToBackUp`,`What to back up`),required:!0,...l===null?{}:{description:l},children:c(`div`,{className:`divide-y divide-border rounded border border-border bg-background`,"data-testid":r,children:$e.map(s=>{let l=it(s,o),u=n||at(s,o,e);return a(`label`,{className:`flex items-start gap-2 px-3 py-2 text-xs ${u?`opacity-60`:`cursor-pointer hover:bg-primary/5`}`,children:[c(ve,{checked:e.has(s),disabled:u,onChange:()=>t(ot(e,s)),"data-testid":`${r}-${s}`}),a(`span`,{className:`min-w-0 flex-1`,children:[a(`span`,{className:`flex flex-wrap items-center gap-1.5 text-foreground`,children:[tt(s),l===`absent`&&c(ye,{variant:`neutral`,size:`sm`,children:i(`backup.backupDatabasePicker.notCreatedYet`,`Not created yet`)})]}),c(`span`,{className:`block text-[11px] text-foreground-subtle`,children:l===`absent`?et():nt(s)})]})]},s)})})})}e();function Et({onClose:e}){let{t}=K(),n=s(),[i,o]=r(new Set(J)),l=Te({onMutate:()=>{n.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})},onSuccess:()=>{n.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),n.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),n.invalidateQueries({queryKey:[[`backup`,`listRuns`]]}),e()}});return c(ue,{open:!0,onOpenChange:t=>!t&&e(),children:a(te,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(ee,{children:[c(we,{children:t(`backup.backupNowDialog.backUpNow`,`Back up now`)}),c(`p`,{className:`text-xs text-foreground-subtle`,children:t(`backup.backupNowDialog.runsOnceAndWritesThe`,`Runs once and writes the archive to every enabled backup location.`)})]}),c(z,{children:a(`div`,{className:`p-4`,children:[c(Tt,{selected:i,onChange:o,disabled:l.isPending,testId:`backup-now-databases`}),l.error&&c(`p`,{role:`alert`,className:`pt-2 text-xs text-danger`,children:l.error.message})]})}),a(U,{children:[c(R,{variant:`outline`,size:`sm`,onClick:e,children:t(`common.cancel`,`Cancel`)}),a(R,{size:`sm`,onClick:()=>{i.size!==0&&l.mutate(ct(i))},disabled:i.size===0||l.isPending,"data-testid":`backup-now-run`,children:[l.isPending?c(S,{className:`h-3.5 w-3.5 animate-spin`}):c(T,{className:`h-3.5 w-3.5`}),t(`backup.backupNowDialog.backUpNow`,`Back up now`)]})]})]})})}e();function Dt(e){return e===null?`—`:new Date(e).toLocaleString()}function Ot(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 kt({revealed:e,onDone:t}){let{t:n}=K(),[i,o]=r(!1),[s,l]=r(!1);return c(ue,{open:!0,onOpenChange:e=>!e&&i&&t(),children:a(te,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`border-danger/40`,"aria-labelledby":`backup-key-title`,children:[c(ee,{children:c(we,{id:`backup-key-title`,children:n(`backup.encryptionCard.yourKey`,{keyId:e.keyId})})}),a(z,{className:`space-y-3`,children:[a(`p`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 p-2 text-xs text-foreground`,children:[c(m,{className:`mt-0.5 h-4 w-4 shrink-0 text-danger`}),c(`span`,{children:n(`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.`)})]}),c(`div`,{className:`break-all rounded-md border border-border bg-background p-2 font-mono text-xs text-foreground select-all`,children:e.secretKey}),a(`div`,{className:`flex flex-wrap gap-2`,children:[a(R,{size:`sm`,variant:`outline`,onClick:()=>{navigator.clipboard?.writeText(e.secretKey).then(()=>l(!0))},children:[c(v,{className:`mr-1 h-3.5 w-3.5`}),s?n(`backup.backupEncryptionCard.copied`,`Copied`):n(`common.copy`,`Copy`)]}),a(R,{size:`sm`,variant:`outline`,onClick:()=>Ot(e),children:[c(u,{className:`mr-1 h-3.5 w-3.5`}),n(`backup.backupEncryptionCard.downloadAsFile`,`Download as file`)]})]}),a(`label`,{className:`flex items-center gap-2 text-xs text-foreground`,children:[c(`input`,{type:`checkbox`,checked:i,onChange:e=>o(e.target.checked),className:`accent-primary`}),n(`backup.backupEncryptionCard.iHaveStoredThisKey`,`I have stored this key somewhere safe, off this server.`)]})]}),c(U,{children:c(R,{size:`sm`,disabled:!i,onClick:t,children:n(`backup.backupEncryptionCard.iHaveStoredIt`,`I have stored it`)})})]})})}function At(){let{t:e}=K(),t=I(),n=be(),i=se(),s=H(),[l,u]=r(null),[d,f]=r(null),p=t.data?.enabled??!1,m=t.data?.active??null,h=(t.data?.keys??[]).filter(e=>e.retiredAt!==null),g=async()=>{if(await s({title:p?e(`backup.backupEncryptionCard.replaceTheBackupKey`,`Replace the backup key`):e(`backup.backupEncryptionCard.encryptBackups`,`Encrypt backups`),message:p?e(`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.`):e(`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:p?e(`backup.backupEncryptionCard.generateANewKey`,`Generate a new key`):e(`backup.backupEncryptionCard.generateTheKey`,`Generate the key`),variant:`warning`})){f(null);try{let e=await n.mutateAsync({});u({keyId:e.keyId,secretKey:e.secretKey})}catch(e){f(e instanceof Error?e.message:String(e))}}},_=async()=>{if(await s({title:e(`backup.backupEncryptionCard.turnBackupEncryptionOff`,`Turn backup encryption off`),message:e(`backup.backupEncryptionCard.newBackupsWillBeWritten`,`New backups will be written unencrypted. Existing encrypted backups still need their key to be restored.`),confirmLabel:e(`backup.backupEncryptionCard.turnOff`,`Turn off`),variant:`danger`})){f(null);try{await i.mutateAsync({}),t.refetch()}catch(e){f(e instanceof Error?e.message:String(e))}}};return a(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-4`,children:[a(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[a(`div`,{className:`flex items-center gap-2`,children:[p?c(E,{className:`h-4 w-4 text-success`}):c(k,{className:`h-4 w-4 text-foreground-subtle`}),c(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`backup.backupEncryptionCard.encryption`,`Encryption`)}),c(`span`,{className:`text-xs text-foreground-subtle`,children:p&&m!==null?e(`backup.backupEncryptionCard.onKeySince`,`On — key {{keyId}}, since {{value2}}`,{keyId:m.keyId,value2:Dt(m.createdAt)}):e(`backup.backupEncryptionCard.offBackupsAreNotEncrypted`,`Off — backups are not encrypted`)})]}),c(`div`,{className:`flex gap-2`,children:p?a(o,{children:[c(R,{size:`sm`,variant:`outline`,disabled:n.isPending,onClick:()=>void g(),children:e(`backup.backupEncryptionCard.replaceKey`,`Replace key`)}),c(R,{size:`sm`,variant:`outline`,disabled:i.isPending,onClick:()=>void _(),children:e(`backup.backupEncryptionCard.turnOff`,`Turn off`)})]}):c(R,{size:`sm`,disabled:n.isPending,onClick:()=>void g(),children:e(`backup.backupEncryptionCard.enableEncryption`,`Enable encryption`)})})]}),c(`p`,{className:`text-xs text-foreground-subtle`,children:e(`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, config.yaml, addon data (HomeKit pairing, Matter fabric, Tailscale state) and TLS.`)}),h.length>0&&a(`div`,{className:`text-xs`,children:[c(`p`,{className:`text-foreground-subtle`,children:e(`backup.backupEncryptionCard.olderKeysBackupsMadeWith`,`Older keys (backups made with them still need them):`)}),c(`ul`,{className:`font-mono text-foreground`,children:h.map(e=>a(`li`,{children:[e.keyId,` · `,Dt(e.createdAt),` → `,Dt(e.retiredAt)]},e.keyId))})]}),d!==null&&c(`p`,{className:`text-xs text-danger`,children:d}),l!==null&&c(kt,{revealed:l,onDone:()=>{u(null),t.refetch()}})]})}e();var jt=[{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 Mt(e){let t=e.trim();for(let e of jt)if(e.cron===t)return e.id;return`custom`}function Nt({value:e,onChange:n,previewCount:i=5,disabled:o=!1}){let{t:s}=K(),l=Mt(e),[u,d]=r(l===`custom`);t(()=>{l!==`custom`&&d(!1)},[l]);let f=It(e,250),p=De({cron:f,count:i},{enabled:f.trim().length>0}),m=p.data??null,h=e=>{d(!1),n(e.cron)},g=u||l===`custom`;return a(`div`,{className:`space-y-3`,children:[a(`div`,{className:`space-y-1`,children:[c(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:s(`backup.cronEditor.schedulePreset`,`Schedule preset`)}),a(`div`,{className:`flex flex-wrap gap-1.5`,children:[jt.map(e=>c(`button`,{type:`button`,onClick:()=>h(e),disabled:o,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??s(e.labelKey):s(e.descriptionKey),children:s(e.labelKey)},e.id)),c(`button`,{type:`button`,onClick:()=>{d(!0),e.trim().length===0&&n(`0 3 * * *`)},disabled:o,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:s(`backup.cronEditor.custom`,`Custom…`)})]})]}),g&&a(`div`,{className:`space-y-1`,children:[c(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:s(`backup.cronEditor.cronExpression5FieldPosix`,`Cron expression (5-field POSIX)`)}),c(`input`,{type:`text`,value:e,onChange:e=>n(e.target.value),disabled:o,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`}),a(`p`,{className:`text-[10px] text-foreground-subtle`,children:[s(`backup.cronEditor.format`,`Format:`),` `,c(Ie,{i18nKey:`backup.cronEditor.formatLine`,components:{code:c(`span`,{className:`font-mono`})}})]})]}),c(Pt,{cron:f,preview:m,loading:p.isFetching})]})}function Pt({cron:e,preview:t,loading:n}){let{t:r}=K();return n&&t===null?a(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[c(S,{className:`h-3 w-3 animate-spin`}),r(`backup.cronEditor.validating`,`Validating…`)]}):t===null?null:t.ok?t.nextRuns.length===0?c(`div`,{className:`rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:r(`backup.cronEditor.noFutureRunsMatchThis`,`No future runs match this expression.`)}):a(`div`,{className:`space-y-1`,children:[c(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:r(`backup.cronEditor.nextRuns`,`Next runs`)}),c(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>a(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[c(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),c(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:Ft(e)})]},`${e}-${t}`))})]}):c(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:t.error??r(`backup.cronEditor.invalidCronExpression`,`Invalid cron expression`)})}function Ft(e){let t=e-Date.now();if(t<=0)return G.t(`helpers.relativeTime.now`);let n=Math.floor(t/1e3);if(n<60)return G.t(`helpers.relativeTime.inSeconds`,{count:n});let r=Math.floor(n/60);if(r<60)return G.t(`helpers.relativeTime.inMinutes`,{count:r});let i=Math.floor(r/60);if(i<24)return G.t(`helpers.relativeTime.inHours`,{count:i});let a=Math.floor(i/24);return G.t(`helpers.relativeTime.inDays`,{count:a})}function It(e,i){let[a,o]=r(e),s=n(()=>e,[e]);return t(()=>{let e=setTimeout(()=>o(s),i);return()=>clearTimeout(e)},[s,i]),a}e();var Lt=[[`backup`,`listSchedules`]];function Rt({entry:e,onClose:t,onSaved:i}){let{t:o}=K(),l=s(),u=W(),d=u.data??[],[f,p]=r(e?.label??``),[m,h]=r(e?.cron??`0 3 * * *`),[g,_]=r(e?.enabled??!0),[v,y]=r(String(e?.retentionCount??7)),[b,x]=r(new Set(e?.locationIds??[])),[C,w]=r(new Set(e===null?J:X(e.databases))),T=Me({onSuccess:()=>{l.invalidateQueries({queryKey:Lt}),i()}}),E=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},D=Number.parseInt(v,10),O=n(()=>f.trim().length>0&&b.size>0&&C.size>0&&!Number.isNaN(D)&&D>=1&&D<=1e3,[f,b,C,D]),k=()=>{O&&T.mutate({...e?{id:e.id}:{},label:f.trim(),cron:m.trim(),enabled:g,locationIds:Array.from(b),retentionCount:D,databases:[...rt(C)]})},A=T.error instanceof Error?T.error.message:null;return c(Ne,{open:!0,onClose:t,title:e?o(`backup.backupEntryModal.editBackupEntry`,`Edit backup entry`):o(`backup.backupEntryModal.newBackupEntry`,`New backup entry`),icon:j,error:A,width:`lg`,testId:`backup-entry-form`,footer:a(R,{size:`sm`,type:`button`,onClick:k,disabled:!O||T.isPending,children:[T.isPending?c(S,{className:`h-3.5 w-3.5 animate-spin`}):null,e?o(`common.save`,`Save`):o(`backup.backupEntryModal.createEntry`,`Create entry`)]}),children:a(`div`,{className:`space-y-4`,children:[c(B,{label:o(`backup.backupEntryModal.name`,`Name`),required:!0,children:c(oe,{value:f,onChange:e=>p(e.target.value),placeholder:o(`backup.backupEntryModal.nightlyOffsite`,`Nightly offsite`),autoFocus:!0,"data-testid":`backup-entry-name`})}),a(B,{label:o(`backup.backupEntryModal.locationsSelected`,`Locations ({{value1}} selected)`,{value1:String(b.size)}),required:!0,children:[u.isLoading&&a(`div`,{className:`flex items-center gap-2 px-1 py-2 text-xs text-foreground-subtle`,children:[c(S,{className:`h-3.5 w-3.5 animate-spin`}),o(`backup.backupEntryModal.loadingLocations`,`Loading locations…`)]}),!u.isLoading&&d.length===0&&c(`div`,{className:`rounded border border-border bg-background px-3 py-2 text-xs text-foreground-subtle italic`,children:o(`backup.backupEntryModal.noBackupsStorageLocationsConfigured`,"No `backups` storage locations configured. Add one in Settings → Storage first.")}),d.length>0&&c(`div`,{className:`max-h-52 divide-y divide-border overflow-y-auto rounded border border-border bg-background`,children:d.map(e=>a(`label`,{className:`flex cursor-pointer items-center justify-between px-3 py-2 text-xs hover:bg-primary/5`,children:[a(`div`,{className:`flex items-center gap-2`,children:[c(`input`,{type:`checkbox`,checked:b.has(e.id),onChange:()=>E(e.id),className:`accent-primary`}),c(`span`,{className:`text-foreground`,children:e.displayName})]}),a(`div`,{className:`flex items-center gap-1.5`,children:[c(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e.kind}),c(`span`,{className:`font-mono text-[10px] text-foreground-subtle`,children:e.id})]})]},e.id))})]}),c(Tt,{selected:C,onChange:w,disabled:T.isPending,testId:`backup-entry-databases`}),a(`div`,{className:`grid grid-cols-2 gap-3`,children:[c(B,{label:o(`backup.backupEntryModal.retentionArchivesKept`,`Retention (archives kept)`),required:!0,children:c(oe,{type:`number`,min:1,max:1e3,value:v,onChange:e=>y(e.target.value),"data-testid":`backup-entry-retention`})}),c(B,{label:o(`backup.backupEntryModal.enabled`,`Enabled`),description:o(`backup.backupEntryModal.runOnScheduleWhenChecked`,`Run on schedule when checked.`),children:a(`label`,{className:`inline-flex cursor-pointer items-center gap-2 py-1.5 text-xs text-foreground`,children:[c(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked),className:`accent-primary`,"data-testid":`backup-entry-enabled`}),c(`span`,{children:o(`backup.backupEntryModal.runOnSchedule`,`Run on schedule`)})]})})]}),c(B,{label:o(`backup.backupEntryModal.schedule`,`Schedule`),children:c(Nt,{value:m,onChange:h,disabled:T.isPending})})]})})}e();var zt=2e3,Bt=5e3;function Q(e){return e.state===`queued`||e.state===`running`}function Vt(e){if(e.state===`queued`)return{title:G.t(`backup.backupRunsPanel.cancelQueuedBackupRun`,`Cancel queued backup run?`),message:G.t(`backup.backupRunsPanel.thisRunHasNotStarted`,`This run has not started. Cancelling removes it from the queue — nothing has been written, nothing is deleted.`),confirmLabel:G.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:G.t(`backup.backupRunsPanel.stopThisBackupRun`,`Stop this backup run?`),message:G.t(`backup.backupRunsPanel.theHalfWrittenStagingArchive`,`The half-written staging archive is deleted and the destination currently uploading discards its partial copy. {{keptSentence}}`,{keptSentence:n}),confirmLabel:G.t(`backup.backupRunsPanel.stopRun`,`Stop run`),variant:`danger`}}function Ht(){let e=H(),[t,n]=r(null),a=Ce(void 0,{refetchInterval:e=>(e.state.data??[]).some(Q)?zt:Bt}),o=he({onSettled:()=>{n(null),a.refetch()}}),s=i(async t=>{await e(Vt(t))&&(n(t.id),o.mutate({runId:t.id}))},[e,o]);return c(Ut,{queryState:a.isError?`error`:a.data===void 0?`pending`:`ready`,runs:a.data??[],cancelingId:t,onCancelRequest:e=>{s(e)},now:Date.now()})}function Ut({queryState:e,runs:t,cancelingId:n,onCancelRequest:r,now:i}){let{t:o}=K(),s=e===`ready`&&t.some(Q),l=t.filter(e=>e.state===`running`),u=t.filter(e=>e.state===`queued`),d=t.filter(e=>!Q(e)),f=[...l,...u,...d];return a(`section`,{className:`rounded-lg border border-border bg-surface`,children:[a(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-border`,children:[c(`h2`,{className:`text-xs font-semibold text-foreground`,children:o(`backup.backupRunsPanel.runs`,`Runs`)}),s&&a(`span`,{className:`inline-flex items-center gap-1 text-[10px] font-medium text-primary`,title:o(`backup.backupRunsPanel.aBackupRunIsIn`,`A backup run is in progress`),children:[c(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary animate-pulse`}),o(`backup.runsPanel.live`)]}),c(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:o(`backup.backupRunsPanel.oneRunExecutesAtA`,`One run executes at a time — queued runs wait in line.`)})]}),e===`pending`&&c(`div`,{className:`px-3 py-2.5 text-xs text-foreground-subtle animate-pulse`,children:o(`backup.backupRunsPanel.checkingForBackupRuns`,`Checking for backup runs…`)}),e===`error`&&c(`div`,{className:`px-3 py-2.5 text-xs text-danger`,children:o(`backup.backupRunsPanel.couldNotReadBackupRuns`,`Could not read backup runs — the orchestrator did not answer.`)}),e===`ready`&&t.length===0&&c(`div`,{className:`px-3 py-2.5 text-xs text-foreground-subtle italic`,children:o(`backup.backupRunsPanel.noBackupRunsYetRuns`,`No backup runs yet. Runs appear here the moment one starts — manual or scheduled.`)}),e===`ready`&&t.length>0&&c(`div`,{className:`overflow-x-auto`,children:a(`table`,{className:`w-full text-xs min-w-[720px]`,children:[c(`thead`,{children:a(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[c(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.run`,`Run`)}),c(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.state`,`State`)}),c(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.progress`,`Progress`)}),c(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.destinations`,`Destinations`)}),c(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.timing`,`Timing`)}),c(`th`,{className:`text-right px-3 py-1.5 font-medium w-28`,children:o(`backup.backupRunsPanel.actions`,`Actions`)})]})}),c(`tbody`,{children:f.map(e=>c(Wt,{run:e,canceling:n===e.id,onCancelRequest:r,now:i},e.id))})]})})]})}function Wt({run:e,canceling:t,onCancelRequest:n,now:r}){let{t:i}=K(),o=Q(e);return a(`tr`,{className:`border-t border-border hover:bg-primary/5 align-top`,children:[a(`td`,{className:`px-3 py-2`,children:[c(`div`,{className:`text-foreground`,children:e.label??c(`span`,{className:`text-foreground-subtle italic`,children:i(`backup.runsPanel.manual`)})}),c(`div`,{className:`text-[10px] text-foreground-subtle font-mono`,title:e.id,children:e.id.slice(0,8)})]}),a(`td`,{className:`px-3 py-2`,children:[c(Gt,{run:e}),e.state===`failed`&&e.error!==void 0&&c(`div`,{className:`mt-1 text-[10px] text-danger max-w-56 truncate`,title:e.error,children:e.error})]}),c(`td`,{className:`px-3 py-2`,children:c(Kt,{run:e})}),c(`td`,{className:`px-3 py-2`,children:c(qt,{run:e})}),c(`td`,{className:`px-3 py-2 text-foreground-subtle tabular-nums`,children:c(Jt,{run:e,now:r})}),c(`td`,{className:`px-3 py-2`,children:c(`div`,{className:`flex justify-end`,children:o&&a(`button`,{onClick:()=>n(e),disabled:t,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:e.state===`queued`?i(`backup.backupRunsPanel.removeThisRunFromThe`,`Remove this run from the queue before it starts`):i(`backup.backupRunsPanel.stopThisRunTheHalf`,`Stop this run — the half-written archive is discarded`),children:[t?c(S,{className:`h-3 w-3 animate-spin`}):c(l,{className:`h-3 w-3`}),e.state===`queued`?i(`common.cancel`,`Cancel`):i(`backup.backupRunsPanel.stop`,`Stop`)]})})})]})}function Gt({run:e}){let{t}=K();switch(e.state){case`queued`:return a(`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:[c(O,{className:`h-3 w-3`}),t(`backup.backupRunsPanel.queued`,`Queued`)]});case`running`:return a(`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:[c(S,{className:`h-3 w-3 animate-spin`}),e.phase===`uploading`?t(`backup.backupRunsPanel.uploading`,`Uploading`):t(`backup.backupRunsPanel.buildingArchive`,`Building archive`)]});case`succeeded`:return a(`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:[c(C,{className:`h-3 w-3`}),t(`backup.backupRunsPanel.succeeded`,`Succeeded`)]});case`failed`:return a(`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:[c(x,{className:`h-3 w-3`}),t(`backup.backupRunsPanel.failed`,`Failed`)]});case`cancelled`:return a(`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:t(`backup.backupRunsPanel.stoppedBeforeCompletingEveryDestination`,`Stopped before completing every destination — not a success`),children:[c(N,{className:`h-3 w-3`}),t(`backup.backupRunsPanel.stopped`,`Stopped`)]})}}function Kt({run:e}){let{t}=K();if(e.state===`queued`)return c(`span`,{className:`text-foreground-subtle`,children:e.queuePosition===void 0?c(`span`,{className:`italic`,children:t(`backup.backupRunsPanel.waitingItsTurn`,`waiting its turn`)}):a(`span`,{className:`inline-flex items-center gap-1`,children:[c(`span`,{className:e.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:Yt(e.queuePosition)}),t(`backup.backupRunsPanel.inLine`,`in line`)]})});if(e.state===`running`&&e.phase===`building`)return a(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[c(P,{className:`h-3 w-3 text-primary`}),c(`span`,{className:`tabular-nums font-medium animate-pulse`,children:q(e.stagedBytes)}),c(`span`,{className:`text-foreground-subtle`,children:t(`backup.backupRunsPanel.stagedSoFar`,`staged so far`)})]});if(e.state===`running`){let n=e.archiveSizeBytes;return a(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[c(M,{className:`h-3 w-3 text-primary`}),a(`span`,{className:`tabular-nums font-medium`,children:[q(e.uploadedBytes),n===void 0?``:` / ${q(n)}`]}),c(`span`,{className:`text-foreground-subtle`,children:t(`backup.backupRunsPanel.toCurrentDestination`,`to current destination`)})]})}let n=e.archiveSizeBytes??(e.stagedBytes>0?e.stagedBytes:void 0);return n===void 0?c(`span`,{className:`text-foreground-subtle italic`,children:`—`}):c(`span`,{className:`tabular-nums text-foreground`,children:t(`backup.runsPanel.archiveSize`,{size:q(n)})})}function qt({run:e}){let{t}=K(),n=e.destinationIds.length,r=e.completedDestinationIds.length,i=e.failedDestinationIds.length;return n===0?c(`span`,{className:`text-foreground-subtle italic`,children:t(`backup.backupRunsPanel.notResolvedYet`,`not resolved yet`)}):a(`div`,{className:`flex flex-col gap-0.5`,children:[c(`span`,{className:`text-foreground-subtle`,title:e.destinationIds.join(`, `),children:t(`backup.runsPanel.targets`,{count:n})}),a(`span`,{className:`inline-flex items-center gap-2 text-[10px]`,children:[r>0&&c(`span`,{className:`text-success`,title:t(`backup.backupRunsPanel.keptTheirArchive`,`Kept their archive: {{value1}}`,{value1:e.completedDestinationIds.join(`, `)}),children:t(`backup.runsPanel.completed`,{count:r})}),i>0&&c(`span`,{className:`text-danger`,title:t(`backup.backupRunsPanel.failed2`,`Failed: {{value1}}`,{value1:e.failedDestinationIds.join(`, `)}),children:t(`backup.runsPanel.failedCount`,{count:i})})]})]})}function Jt({run:e,now:t}){let{t:n}=K();return e.state===`queued`?c(`span`,{children:n(`backup.runsPanel.queuedAgo`,{elapsed:Xt(t-e.requestedAt)})}):e.startedAt===void 0?c(`span`,{children:`—`}):e.finishedAt===void 0?c(`span`,{children:n(`backup.runsPanel.runningFor`,{elapsed:Xt(t-e.startedAt)})}):a(`div`,{className:`flex flex-col gap-0.5`,children:[c(`span`,{children:Zt(e.finishedAt)}),c(`span`,{className:`text-[10px]`,children:n(`backup.runsPanel.took`,{elapsed:Xt(e.finishedAt-e.startedAt)})})]})}function Yt(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 Xt(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 Zt(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}e();var Qt=[[`backup`,`list`]];function $t({initialDestinationId:e,initialArchiveId:i,onClose:o,onScheduled:l}){let{t:u}=K(),d=s(),[p,m]=r(e&&i?2:1),[h,g]=r(e),[_,v]=r(i),[y,x]=r(new Set),[C,w]=r(``),{data:T}=W(),E=T??[],{data:O,isLoading:k}=Ae({destinationId:h??``},{enabled:!!h}),A=O??[];t(()=>{if(h!==void 0)return;let e=E.filter(e=>e.restoreSupported);e.length===1&&g(e[0].id)},[h,E]);let{data:j}=Se({destinationId:h??``,backupId:_??``},{enabled:!!h&&!!_}),M=n(()=>j?.locations??[],[j]);t(()=>{M.length!==0&&x(e=>e.size===0?new Set(M):e)},[M]);let N=ke({onSuccess:()=>{d.invalidateQueries({queryKey:Qt}),l(),o()}}),P=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},F=A.find(e=>e.id===_),I=F?.encryption!==void 0,L=lt(F?.databases,j?.sqliteSnapshots),B=st(L),ne=!!h&&!!_,V=B||y.size>0,re=ne&&V&&!N.isPending&&(!I||C.trim().length>0),ie=()=>{!h||!_||N.mutate({destinationId:h,backupId:_,...B?{}:{locations:[...y]},...I?{backupSecretKey:C.trim()}:{}})};return c(ue,{open:!0,onOpenChange:e=>!e&&o(),children:a(te,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(ee,{children:[c(we,{children:u(`backup.restoreWizard.restoreBackup`,`Restore Backup`)}),c(`p`,{className:`text-xs text-foreground-subtle`,children:u(`backup.restoreWizard.stepOf`,{step:p,name:p===1?u(`backup.restoreWizard.pickSource`,`pick source`):p===2?u(`backup.restoreWizard.pickLocations`,`pick locations`):u(`backup.restoreWizard.confirmStep`)})})]}),a(z,{children:[p===1&&c(en,{destinations:E,destinationId:h,onPickDestination:e=>{g(e),v(void 0),x(new Set)},archives:A,archivesLoading:k,archiveId:_,onPickArchive:v}),p===2&&c(tn,{locations:M,picked:y,onToggle:P,databases:L,snapshotsOnly:B}),p===3&&c(nn,{destinationName:E.find(e=>e.id===h)?.displayName??h??``,archive:F,picked:[...y],databases:L,snapshotsOnly:B}),p===3&&F?.encryption!==void 0&&c(rn,{keyId:F.encryption.keyId,value:C,onChange:w}),p===3&&N.error&&c(`p`,{role:`alert`,className:`px-4 pb-2 text-xs text-danger`,children:N.error.message})]}),a(U,{className:`justify-between`,children:[c(`div`,{children:p>1&&a(R,{variant:`outline`,size:`sm`,onClick:()=>m(e=>e===3?2:1),children:[c(D,{className:`h-3 w-3`}),u(`common.back`,`Back`)]})}),a(`div`,{className:`flex items-center gap-2`,children:[c(R,{variant:`outline`,size:`sm`,onClick:o,children:u(`common.cancel`,`Cancel`)}),p<3?a(R,{size:`sm`,disabled:p===1&&!ne||p===2&&!V,onClick:()=>m(e=>e===1?2:3),children:[u(`common.next`,`Next`),c(f,{className:`h-3 w-3`})]}):a(R,{size:`sm`,onClick:ie,disabled:!re,children:[N.isPending?c(S,{className:`h-3.5 w-3.5 animate-spin`}):c(b,{className:`h-3.5 w-3.5`}),u(`backup.restoreWizard.scheduleRestore`,`Schedule Restore`)]})]})]})]})})}function en({destinations:e,destinationId:t,onPickDestination:n,archives:r,archivesLoading:i,archiveId:o,onPickArchive:s}){let{t:l}=K(),u=e.filter(e=>e.restoreSupported);return a(`div`,{className:`p-4 space-y-3`,children:[a(`div`,{className:`space-y-1.5`,children:[c(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:l(`backup.restoreWizard.destination`,`Destination`)}),c(Oe,{value:t??``,onChange:e=>n(e.target.value),options:[{value:``,label:l(`backup.restoreWizard.selectDestination`,`Select destination…`)},...u.map(e=>({value:e.id,label:`${e.displayName} (${e.kind})`}))]})]}),a(`div`,{className:`space-y-1.5`,children:[c(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:l(`backup.restoreWizard.archive`,`Archive`)}),!t&&c(`div`,{className:`text-xs text-foreground-subtle italic`,children:l(`backup.restoreWizard.pickADestinationFirst`,`Pick a destination first.`)}),t&&i&&c(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:l(`backup.restoreWizard.readingArchives`,`Reading archives…`)}),t&&!i&&r.length===0&&c(`div`,{className:`text-xs text-foreground-subtle italic`,children:l(`backup.restoreWizard.noArchivesAvailableAtThis`,`No archives available at this destination.`)}),t&&r.length>0&&c(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:r.map(e=>{let t=o===e.id;return a(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[a(`div`,{className:`flex items-center gap-2`,children:[c(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>s(e.id),className:`accent-primary`}),a(`div`,{children:[a(`div`,{className:`flex items-center gap-1 font-medium text-foreground`,children:[e.encryption!==void 0&&c(E,{className:`h-3 w-3 text-success`,"aria-label":l(`backup.restoreWizard.encryptedKey`,`encrypted (key {{keyId}})`,{keyId:e.encryption.keyId})}),e.label??e.id]}),c(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()}),c(`div`,{className:`pt-1`,children:c(Z,{databases:lt(e.databases,void 0)})})]})]}),c(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:q(e.sizeBytes)})]},e.id)})})]})]})}function tn({locations:e,picked:t,onToggle:n,databases:r,snapshotsOnly:i}){let{t:o}=K();return i?a(`div`,{className:`space-y-3 p-4`,children:[a(`div`,{className:`space-y-1.5`,children:[c(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:o(`backup.restoreWizard.databasesInThisArchive`,`Databases in this archive`)}),c(Z,{databases:r})]}),c(`div`,{className:`rounded border border-info/30 bg-info/10 px-3 py-2 text-[11px] text-info`,children:o(`backup.restoreWizard.snapshotsOnlyRestoringThisArchive`,`Snapshots only: restoring this archive replaces just these databases. It does NOT touch configuration, addons, addon data or certificates.`)})]}):e.length===0?c(`div`,{className:`p-4`,children:c(`div`,{className:`text-xs text-foreground-subtle`,children:o(`backup.restoreWizard.loadingArchiveManifestIfThis`,`Loading archive manifest… If this persists, the archive may predate manifests — restoring will apply everything in the tarball.`)})}):a(`div`,{className:`p-4 space-y-3`,children:[a(`div`,{className:`space-y-1.5`,children:[c(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:o(`backup.restoreWizard.databasesInThisArchive`,`Databases in this archive`)}),c(Z,{databases:r})]}),c(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-[11px] text-warning`,children:o(`backup.restoreWizard.selectedEntriesWillOverwriteLive`,`Selected entries will overwrite live data on the next server restart. Unchecked entries stay current.`)}),a(`div`,{className:`space-y-1.5`,children:[c(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:o(`common.apply`,`Apply`)}),c(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>a(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[c(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>n(e),className:`accent-primary`}),c(`span`,{className:`font-mono text-foreground`,children:e}),c(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:on(e)})]},e))})]})]})}function nn({destinationName:e,archive:t,picked:n,databases:r,snapshotsOnly:i}){let{t:o}=K();return a(`div`,{className:`p-4 space-y-3 text-xs`,children:[c(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-warning`,children:o(`backup.restoreWizard.restoreIsAppliedAtNext`,`Restore is applied at next server boot. Active connections will drop when you restart.`)}),a(`dl`,{className:`space-y-1.5`,children:[c($,{term:`Destination`,value:e}),c($,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&c($,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${q(t.sizeBytes)}`}),c($,{term:`Databases`,value:r.map(e=>tt(e)).join(`, `)}),c($,{term:`Locations`,value:i?`none (configuration is not touched)`:n.length>0?n.join(`, `):`— (full archive)`})]})]})}function rn({keyId:e,value:t,onChange:n}){let{t:r}=K();return a(`div`,{className:`space-y-1.5 px-4 pb-3`,children:[c(`label`,{htmlFor:`restore-backup-key`,className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:r(`backup.restoreWizard.backupKey`,`Backup key`)}),c(`input`,{id:`restore-backup-key`,type:`password`,autoComplete:`off`,spellCheck:!1,value:t,onChange:e=>n(e.target.value),placeholder:r(`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`}),c(`p`,{className:`text-[11px] text-foreground-subtle`,children:c(Ie,{i18nKey:`backup.restoreWizard.encryptedTo`,values:{keyId:e},components:{mono:c(`span`,{className:`font-mono`})}})})]})}function $({term:e,value:t}){return a(`div`,{className:`flex justify-between gap-3`,children:[c(`dt`,{className:`text-foreground-subtle`,children:e}),c(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var an={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function on(e){return an[e]??``}e();function sn(){let{t:e}=K(),n=H(),i=ie(),{state:o,openNew:s,openEdit:l,close:u}=V({editKey:`edit`,newKey:`new`}),d=_e(),f=d.data??[],[p,m]=r(null),[g,_]=r(!1),[v,y]=r(!1),[x,C]=r(!1),w=o.mode===`edit`?f.find(e=>e.id===o.id)??null:null;t(()=>{o.mode===`edit`&&!d.isLoading&&w===null&&u()},[o.mode,d.isLoading,w,u]);let E=o.mode===`new`||o.mode===`edit`&&w!==null,D=async()=>{await n({title:e(`system.backup.restartServerNow`,`Restart server now?`),message:e(`system.backup.activeConnectionsWillDropAnd`,`Active connections will drop and the apply-backup hook will run before boot.`),confirmLabel:e(`system.backup.restart`,`Restart`),variant:`warning`})&&i.mutate({confirm:!0})};return a(Re,{embedded:!0,children:[a(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,"data-testid":`backup-actions`,children:[a(R,{variant:`outline`,size:`sm`,type:`button`,onClick:()=>C(!0),"data-testid":`backup-now`,children:[c(T,{className:`h-3.5 w-3.5`}),e(`system.backup.backUpNow`,`Back up now`)]}),a(R,{variant:`outline`,size:`sm`,type:`button`,onClick:()=>_(!0),children:[c(b,{className:`h-3.5 w-3.5`}),e(`system.backup.restore`,`Restore…`)]}),a(R,{size:`sm`,type:`button`,onClick:s,"data-testid":`backup-new-entry`,children:[c(h,{className:`h-3.5 w-3.5`}),e(`system.backup.newEntry`,`New entry`)]})]}),v&&c(`div`,{className:`rounded-lg border border-warning/30 bg-warning/10 px-3 py-2.5 text-xs text-warning`,children:a(`div`,{className:`flex items-center justify-between gap-3`,children:[a(`div`,{className:`flex items-center gap-2`,children:[c(b,{className:`h-3.5 w-3.5`}),c(`span`,{children:e(`system.backup.restoreScheduledRestartTheServer`,`Restore scheduled. Restart the server to apply.`)})]}),a(R,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>{D()},disabled:i.isPending,children:[i.isPending?c(S,{className:`h-3.5 w-3.5 animate-spin`}):c(b,{className:`h-3.5 w-3.5`}),e(`system.backup.restartNow`,`Restart Now`)]})]})}),c(At,{}),c(Ht,{}),c(gt,{onEdit:e=>l(e.id),onOpenRestoreWizard:e=>m(e)}),E&&c(Rt,{entry:w,onClose:u,onSaved:u}),x&&c(Et,{onClose:()=>C(!1)}),(p||g)&&c($t,{...p?{initialDestinationId:p.destinationId,initialArchiveId:p.archiveId}:{},onClose:()=>{m(null),_(!1)},onScheduled:()=>y(!0)})]})}function cn(){let{t:e}=K(),t=Fe(`/system/data`,{t:e,isAdmin:!0})??{icon:p,title:e(`system.data`,`Data`)};return c(Le,{icon:t.icon,title:t.title,defaultSection:`storage`,sectionsLabel:`${t.title} sections`,sections:[{id:`storage`,label:e(`systemPage.data.storage`,`Storage`),content:c(Ze,{})},{id:`backup`,label:e(`systemPage.data.backup`,`Backup`),content:c(sn,{})},{id:`deleted-devices`,label:e(`systemPage.data.deletedDevices`,`Deleted devices`),content:c(Xe,{})}]})}export{cn as DataPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{$ as e,B as t,G as n,J as r,L as i,S as a,a as o,b as s,o as c,q as l,t as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Hi as f,Hr as p,Ir as m,It as h,Nt as g,On as _,Pn as v,Qt as y,Tt as b,_i as x,ar as S,cn as C,cr as w,dt as T,fi as E,fn as D,ia as O,nr as k,on as A,ot as j,pr as M,sn as N,un as P,yi as F,yn as I}from"./player-overlays-D0U2dNvn.js";import{n as L,r as R,t as ee}from"./key-B1M6i1mf.js";import{c as z,o as B,u as V}from"./video-BBtESt54.js";import{t as H}from"./history-BMhP0SFG.js";import{t as te}from"./key-round-yCDTbIQb.js";import{t as ne}from"./monitor-smartphone-9Ife1Trw.js";import{t as re}from"./unlink-DzoLNfsq.js";import{Si as ie,a as ae,bi as oe,i as se,o as ce,s as le,xi as ue}from"./client-DYbvGOid.js";import{Al as de,An as fe,Bl as pe,Bn as U,Cn as me,Dl as he,Dn as ge,Dr as _e,En as ve,Er as ye,Fl as be,Ft as xe,G as Se,Hl as Ce,Ht as W,Il as we,Jl as Te,L as Ee,Ll as De,Ln as Oe,Ml as ke,N as Ae,Nl as je,Ol as Me,P as Ne,Pl as Pe,Ql as Fe,Qn as Ie,Rl as Le,Rn as Re,Tn as ze,Ut as Be,Vl as Ve,Wt as He,X as Ue,Xl as We,Yl as Ge,Z as Ke,Zl as qe,Zn as G,ar as K,bn as Je,en as Ye,ha as Xe,in as Ze,jl as Qe,jn as $e,jo as et,kl as tt,kn as nt,nn as rt,on as it,ql as at,rn as ot,vu as q,z as st,zl as ct,zn as lt}from"./src-CGxdJN_f.js";import{t as J}from"./i18n-Vb3uBp7P.js";import{t as Y}from"./useTranslation-D3Is_4B6.js";import{C as ut,Q as dt,X as ft,Y as pt,Z as mt,c as ht,et as gt,f as _t,m as vt,s as yt,z as bt}from"./index-DvOECbab.js";import{t as xt}from"./AdminSectionedPage-B-qoE6ra.js";import{t as St}from"./AdminPage-DAO24U0w.js";import{A as Ct,C as wt,D as Tt,E as Et,F as Dt,M as Ot,N as X,O as kt,P as Z,S as At,T as jt,_ as Mt,a as Nt,b as Pt,c as Ft,d as It,f as Lt,h as Rt,i as zt,j as Bt,k as Vt,l as Ht,m as Ut,n as Wt,o as Gt,p as Kt,s as qt,t as Jt,u as Yt,v as Xt,w as Zt,x as Qt,y as $t}from"./SessionsList-BRTwG3uv.js";import{i as en,n as tn,r as nn,t as rn}from"./IntegrationHub-DdjWEObX.js";import{n as an,t as on}from"./addon-display-names-BkwMrExv.js";e();function sn(){let{t:e}=Y(),t=G(),i=q.useUtils(),a=Dt(),{data:o,isLoading:s}=be(),c=n(()=>o??[],[o]),l=q.useQueries(e=>c.map(t=>e.userManagement.listExternalIdentities({userId:t.id}))),u=q.auth.listLoginMethods.useQuery(),[f,p]=r(null),m=Ve({onSuccess:()=>void i.userManagement.listExternalIdentities.invalidate(),onError:e=>p(`Remove failed: ${e.message}`)}),h=n(()=>new Map((u.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),[u.data]),g=c.flatMap((e,t)=>l[t]?.data??[]),_=g.map(e=>({...jt(e,a),kind:h.get(e.provider)??e.provider})),v=async n=>{let r=g.find(e=>Zt(e)===n.id);r!==void 0&&await t({title:e(`access.externalIdentitiesSection.removeSignInLink`,`Remove sign-in link`),message:e(`access.externalIdentitiesSection.willNoLongerBeAble`,`"{{ownerName}}" will no longer be able to sign in with this {{kind}} account.`,{ownerName:n.ownerName,kind:n.kind}),confirmLabel:e(`common.remove`,`Remove`),variant:`danger`})&&(p(null),m.mutate({userId:r.userId,provider:r.provider,subject:r.subject}))};return d(X,{notice:Z(f),onDismissNotice:()=>{p(null)},id:`external-identities`,title:e(`access.externalIdentitiesSection.signInLinks`,`Sign-in links`),icon:V,description:e(`access.externalIdentitiesSection.externalAccountsSingleSignOn`,`External accounts (single sign-on) each user linked to their CamStack account. Only the owner can link one, from their profile; an admin can remove it.`),children:d(Vt,{rows:_,label:`sign-in links`,isLoading:s||l.some(e=>e.isLoading),loadError:l.find(e=>e.isError)?.error?.message??null,emptyText:`No user has linked a sign-in account.`,expiresNone:`—`,action:{label:e(`common.remove`,`Remove`),icon:re,isAvailable:()=>!0,onRun:e=>void v(e),busyId:null,disabled:m.isPending}})})}e();function cn(){let{t:e}=Y(),t=G(),i=c(),a=Dt(),o=ke(),[s,l]=r(null),u=De({onSuccess:()=>void i.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),onError:e=>l(`Revoke failed: ${e.message}`)}),f=n(()=>(o.data??[]).map(e=>wt(e,a)),[o.data,a]),p=async n=>{await t({title:e(`access.legacyApiKeysSection.revoke`,`Revoke "{{name}}"?`,{name:n.name}),message:e(`access.legacyApiKeysSection.anyClientUsingThisKey`,`Any client using this key loses access immediately. This cannot be undone.`),confirmLabel:e(`access.legacyApiKeysSection.revoke2`,`Revoke`),variant:`danger`})&&(l(null),u.mutate({id:n.id}))};return d(X,{notice:Z(s),onDismissNotice:()=>{l(null)},id:`legacy-api-keys`,title:e(`access.legacyApiKeysSection.legacyApiKeys`,`Legacy API keys`),icon:H,description:e(`access.legacyApiKeysSection.keysFromBeforeScopedTokens`,`Keys from before scoped tokens. Nothing creates them any more; revoke them and issue a scoped token instead.`),children:d(Vt,{rows:f,label:e(`access.legacyApiKeysSection.legacyApiKeys2`,`legacy API keys`),isLoading:o.isLoading,loadError:o.isError?o.error?.message??`Request failed`:null,emptyText:`No legacy API keys.`,action:{label:e(`access.legacyApiKeysSection.revoke2`,`Revoke`),icon:h,isAvailable:()=>!0,onRun:e=>void p(e),busyId:u.isPending?u.variables?.id??null:null,disabled:u.isPending}})})}e();var ln={key:`access.nouns.linkedApp`};function un(e){if(e.type===`category`){let t=e.target??``;return t===`device`?J.t(`access.linkedAppsSection.allDevices`):J.t(`access.linkedAppsSection.allTarget`,{target:t})}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function dn(){let{t:e}=Y(),t=G(),i=c(),a=Pe(),[o,s]=r(null),l=()=>void i.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]}),u=Le({onSuccess:l,onError:e=>s(`Revoke failed: ${e.message}`)}),f=Ct(`oauth-session`,ln,l),p=n(()=>(a.data??[]).map(e=>Et(e,e.scopes.map(un).join(`, `))),[a.data]),m=async n=>{await t({title:e(`access.linkedAppsSection.revokeTheLink`,`Revoke the "{{name}}" link?`,{name:n.name}),message:e(`access.linkedAppsSection.losesAccessForOnIts`,`{{name}} loses access for {{ownerName}} on its next call. Linking it again needs the account-link flow from the start.`,{name:n.name,ownerName:n.ownerName}),confirmLabel:e(`access.linkedAppsSection.revoke`,`Revoke`),variant:`danger`})&&(s(null),u.mutate({id:n.id}))},g=u.isPending?u.variables?.id??null:null;return d(X,{notice:Z(o,f.outcome),onDismissNotice:()=>{s(null),f.dismiss()},id:`linked-apps`,title:e(`access.linkedAppsSection.linkedApps`,`Linked apps`),icon:w,description:e(`access.linkedAppsSection.externalIntegrationsAlexaLinkedTo`,`External integrations (Alexa, …) linked to this hub through OAuth. Revoking one stops that integration on its next call. Already-revoked rows can be selected and removed from the list.`),children:d(Vt,{rows:p,label:e(`access.linkedAppsSection.linkedApps2`,`linked apps`),isLoading:a.isLoading,loadError:a.isError?a.error?.message??`Request failed`:null,emptyText:`No linked apps — an integration appears here once it completes the account-link flow.`,expiresNone:`—`,action:{label:e(`access.linkedAppsSection.revoke`,`Revoke`),icon:h,isAvailable:e=>e.status===`active`||e.status===`revoked`,onRun:e=>void m(e),busyId:g,disabled:u.isPending||f.busy},bulk:{revoke:f,noun:ln,isSelectable:e=>e.status===`active`||e.status===`revoked`,quickSelect:[{label:e(`access.linkedAppsSection.selectRevoked`,`Select revoked`),match:e=>e.status===`revoked`}]}})})}e();var fn={key:`access.nouns.session`};function pn(){let{t:e}=Y(),t=G(),i=q.useUtils(),a=Dt(),o=q.auth.listSessions.useQuery(),[s,c]=r(null),l=()=>void i.auth.listSessions.invalidate(),u=q.auth.revokeSessions.useMutation({onSuccess:l,onError:e=>c(`Sign out failed: ${e.message}`)}),f=Ct(`login-session`,fn,l),p=n(()=>(o.data??[]).map(e=>Tt(e,a,{client:e=>Xt(e).label,method:$t})),[o.data,a]),m=async n=>{await t({title:e(`access.loginSessionsSection.signOutThisSession`,`Sign out this session`),message:e(`access.loginSessionsSection.onWillHaveToSign`,`{{ownerName}} on {{name}} will have to sign in again.`,{ownerName:n.ownerName,name:n.name}),confirmLabel:e(`access.loginSessionsSection.signOut`,`Sign out`),variant:`danger`})&&(c(null),u.mutate({id:n.id}))};return d(X,{notice:Z(s,f.outcome),onDismissNotice:()=>{c(null),f.dismiss()},id:`login-sessions`,title:e(`access.loginSessionsSection.loginSessions`,`Login sessions`),icon:ne,description:e(`access.loginSessionsSection.everyBrowserAndAppSigned`,`Every browser and app signed in to this hub, for every user. Signing one out ends it at once; it has to sign in again. Your own current session is marked and never included in a bulk sign-out.`),children:d(Vt,{rows:p,label:e(`common.sessionsLabel`),isLoading:o.isLoading,loadError:o.isError?o.error?.message??`Request failed`:null,emptyText:`No active sessions.`,action:{label:e(`access.loginSessionsSection.signOut`,`Sign out`),icon:B,isAvailable:e=>e.status===`active`,onRun:e=>void m(e),busyId:u.isPending&&u.variables!==void 0&&`id`in u.variables?u.variables.id:null,disabled:u.isPending||f.busy},bulk:{revoke:f,noun:fn,isSelectable:e=>e.status===`active`}})})}function mn({token:e,label:t,onClose:n}){let{t:r}=Y();return d(ze,{open:!0,onOpenChange:e=>!e&&n(),children:a(ge,{width:`md`,scroll:`body`,children:[d(fe,{children:d($e,{children:r(`auth.tokenModals.token`,`Token: {{label}}`,{label:t})})}),a(ve,{className:`space-y-3`,children:[d(`div`,{className:`rounded-md border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:r(`auth.tokenModals.copyThisTokenNowOnce`,`Copy this token now. Once you close this dialog the secret cannot be displayed again.`)}),d(`div`,{className:`select-all break-all rounded-md border border-border bg-background p-2 font-mono text-[11px] text-foreground`,children:e})]}),a(nt,{children:[d(xe,{value:e,label:r(`common.copy`,`Copy`),srLabel:`token`}),d(U,{type:`button`,variant:`primary`,size:`sm`,onClick:n,children:r(`auth.tokenModals.done`,`Done`)})]})]})})}var hn={token:`newToken`,scoped:`newScoped`,admin:`newAdmin`};e();var gn=7,_n=90,vn=80;function yn(e){let t=Number(e);return Number.isInteger(t)&&t>=1&&t<=_n?t:null}function bn({open:e,users:n,onClose:i,onSubmitScoped:o,onSubmitAdmin:c,submitting:l,formError:u,awaitingProof:f}){let{t:p}=Y(),m=O(),{user:h}=bt(),g=h?.isAdmin===!0,_=g?null:h?.scopes??[],[v,y]=r(!1),[b,x]=r(n[0]?.id??``),[C,w]=r(``),[T,E]=r([{type:`capability`,target:``,access:[`view`,`create`]}]),[D,k]=r(``),[j,M]=r(String(gn));t(()=>{e||(y(!1),x(n[0]?.id??``),w(``),E([{type:`capability`,target:``,access:[`view`,`create`]}]),k(``),M(String(gn)))},[e,n]);let P=C.trim(),F=Ne(T,m),I=yn(j),L=!v&&b!==``&&P.length>0&&T.length>0&&F===null&&!l,R=v&&g&&P.length>0&&P.length<=vn&&I!==null&&!l&&!f,ee=()=>{if(v){if(!R||I===null)return;c({name:P,expiresInDays:I});return}if(!L)return;let e=parseInt(D,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;o({userId:b,name:P,scopes:T,...t===void 0?{}:{expiresAt:t}})},z=v,B=v?N:A;return d(st,{open:e,onClose:i,title:v?p(`access.createTokenModal.createAdminToken`,`Create admin token`):p(`access.createTokenModal.createToken`,`Create token`),icon:v?N:te,error:u,width:`md`,testId:`create-token-dialog`,footer:a(U,{type:`button`,variant:z?`danger`:`primary`,size:`sm`,onClick:ee,disabled:v?!R:!L,children:[l||f?d(S,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}):d(B,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),v?p(`access.createTokenModal.createAdminToken`,`Create admin token`):p(`access.createTokenModal.issueToken`,`Issue token`)]}),children:a(`div`,{className:`space-y-3`,children:[g?a(`label`,{className:`flex items-start gap-2 text-sm text-foreground`,children:[d(`input`,{type:`checkbox`,className:`mt-0.5`,checked:v,onChange:e=>y(e.target.checked),"data-testid":`token-as-admin`}),a(`span`,{children:[d(`span`,{className:`font-medium`,children:p(`access.createTokenModal.administrator`,`Administrator`)}),d(`span`,{className:`block text-[11px] text-foreground-subtle`,children:p(`access.createTokenModal.offScopedToASurface`,`Off = scoped to a surface. On = full admin for scripts (audited, max 90 days).`)})]})]}):null,v?d(`div`,{className:`space-y-1 rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px] leading-relaxed text-foreground`,"data-testid":`admin-token-warning`,children:d(`p`,{children:d(pt,{i18nKey:`auth.adminTokenNoticeShort`,components:{strong:d(`strong`,{})}})})}):null,v?null:a(`div`,{className:`space-y-1`,children:[d(it,{htmlFor:`token-user`,children:p(`access.createTokenModal.onBehalfOfUser`,`On behalf of user`)}),d(at,{id:`token-user`,value:b,onChange:e=>x(e.target.value),options:n.map(e=>({value:e.id,label:e.username}))})]}),d(Se,{label:p(`access.createTokenModal.name`,`Name`),required:!0,children:d(Fe,{id:`token-name`,value:C,maxLength:vn,onChange:e=>w(e.target.value),placeholder:v?`nightly-backup`:`cloudflare-tunnel-route`,autoFocus:!0})}),v?a(`div`,{className:`space-y-1`,children:[d(it,{htmlFor:`token-admin-days`,children:p(`access.createTokenModal.expiresInDays`,`Expires in (days)`)}),d(Fe,{id:`token-admin-days`,type:`number`,min:1,max:_n,value:j,onChange:e=>M(e.target.value),state:I===null?`error`:`default`}),I===null?d(`p`,{className:`text-[11px] text-danger`,children:p(`auth.expiryInvalid`,{max:_n})}):d(`p`,{className:`text-[11px] text-foreground-subtle`,children:p(`auth.expiryHint`,{max:_n})})]}):a(s,{children:[a(`div`,{className:`space-y-1`,children:[d(it,{children:p(`access.createTokenModal.scopes`,`Scopes`)}),d(Ae,{value:T,onChange:E,clampToParent:_}),F&&d(`p`,{className:`text-[10px] text-danger`,children:F}),d(`p`,{className:`text-[10px] text-foreground-subtle`,children:p(`access.createTokenModal.eachScopePicksACap`,`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`)})]}),a(`div`,{className:`space-y-1`,children:[d(it,{htmlFor:`token-scoped-days`,children:p(`access.createTokenModal.expiresInDays`,`Expires in (days)`)}),d(Fe,{id:`token-scoped-days`,type:`number`,min:1,value:D,onChange:e=>k(e.target.value),placeholder:`30`}),d(`p`,{className:`text-[10px] text-foreground-subtle`,children:p(`access.createTokenModal.leaveBlankForNonExpiring`,`Leave blank for non-expiring.`)})]})]})]})})}e();var xn={key:`access.nouns.token`};function Sn(e,t){return e.type===`device`?`device:[${Ke(e.selector,t)}]`:`${e.type}:${e.target??``}`}function Cn({createRequested:e=!1,onCreateConsumed:i}){let{t:o}=Y(),s=O(),{user:l}=bt(),u=G(),f=c(),p=q.useUtils(),m=Dt(),{data:g,isLoading:_}=be(),v=n(()=>g??[],[g]),y=q.useQueries(e=>v.map(t=>e.userManagement.listScopedTokens({userId:t.id}))),b=q.auth.listAdminTokens.useQuery(void 0,{enabled:l?.isAdmin===!0}),{requestProof:x,dialog:S}=Mt(`Creating an admin token`),{state:C,openNew:w,close:T}=Ee({newKey:hn.token}),[E,D]=r(null),[k,A]=r(null),[j,M]=r(!1),[N,P]=r(null),[F,I]=r(null);t(()=>{e&&(w(),i?.())},[e,w,i]);let L=()=>{f.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),p.auth.listAdminTokens.invalidate(),p.auth.listAuthAudit.invalidate()},R=he({onSuccess:({token:e,record:t})=>{L(),T(),A(null),P({token:e,label:t.name})},onError:e=>{D(`Create failed: ${e.message}`),A(`Create failed: ${e.message}`)}}),ee=q.auth.createAdminToken.useMutation({onSuccess:({token:e,record:t})=>{L(),T(),A(null),M(!1),P({token:e,label:t.name})},onError:e=>{D(`Create failed: ${e.message}`),A(`Create failed: ${e.message}`),M(!1)}}),z=ct({onSuccess:()=>{I(null),L()},onError:e=>{I(null),D(`Revoke failed: ${e.message}`)}}),B=q.auth.revokeAdminToken.useMutation({onSuccess:()=>{I(null),L()},onError:e=>{I(null),D(`Revoke failed: ${e.message}`)}}),V=Ot(xn,L),H=Date.now(),ne=v.flatMap((e,t)=>(y[t]?.data??[]).map(t=>kt(t,e.id,m,t.scopes.map(e=>Sn(e,s)).join(`, `),H))),re=l?.isAdmin===!0?(b.data??[]).map(e=>At(e,m,H)):[],ie=[...ne,...re],ae=y.find(e=>e.isError)?.error?.message??(b.isError?b.error?.message??`Request failed`:null),oe=async e=>{let t=e.kind===Qt;await u({title:o(`access.tokensSection.revoke`,`Revoke "{{name}}"?`,{name:e.name}),message:t?o(`access.tokensSection.everyScriptUsingItLoses`,`Every script using it loses access immediately. This cannot be undone.`):o(`access.tokensSection.sScopedTokenStopsWorking`,`{{ownerName}}'s scoped token stops working on its next use. This cannot be undone.`,{ownerName:e.ownerName}),confirmLabel:o(`access.tokensSection.revoke2`,`Revoke`),variant:`danger`})&&(D(null),I(e.id),t?B.mutate({id:e.id}):z.mutate({id:e.id}))},se=R.isPending||ee.isPending;return a(`div`,{"data-testid":`tokens`,children:[S,d(X,{notice:Z(E,V.outcome),onDismissNotice:()=>{D(null),V.dismiss()},id:`tokens`,title:o(`access.tokensSection.tokens`,`Tokens`),icon:te,description:o(`access.tokensSection.scopedTokensForANarrow`,`Scoped tokens for a narrow surface, and admin tokens for full-administrator scripts. Revoking one stops it on its next use.`),children:d(Vt,{rows:ie,label:o(`common.tokensLabel`),isLoading:_||y.some(e=>e.isLoading)||l?.isAdmin===!0&&b.isLoading,loadError:ae,emptyText:`No tokens.`,action:{label:o(`access.tokensSection.revoke2`,`Revoke`),icon:h,isAvailable:e=>e.status===`active`,onRun:e=>void oe(e),busyId:F,disabled:V.busy||F!==null},bulk:{revoke:V,noun:xn,isSelectable:e=>e.status===`active`}})}),d(bn,{open:C.mode===`new`,users:v.map(e=>({id:e.id,username:e.username})),onClose:()=>{T(),A(null),M(!1)},submitting:se,formError:k,awaitingProof:j,onSubmitScoped:e=>R.mutate({userId:e.userId,name:e.name,scopes:e.scopes,expiresAt:e.expiresAt}),onSubmitAdmin:e=>{(async()=>{D(null),A(null),M(!0);let t=await x();M(!1),t!==null&&ee.mutate({...e,reauthToken:t})})()}}),N&&d(mn,{token:N.token,label:N.label,onClose:()=>P(null)})]})}var wn={"share-link":`helpers.authAuditWording.bulkNoun.shareLink`,"admin-token":`helpers.authAuditWording.bulkNoun.adminToken`,"login-session":`helpers.authAuditWording.bulkNoun.loginSession`};function Q(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function Tn(e,t){let n=Q(e,`tokenId`);return Q(e,`name`)??(n===null?void 0:t.get(n))??n??`?`}function En(e){return e.filter(e=>e!==null)}function Dn(e){let t=Q(e,`prefix`);return t===null?null:J.t(`helpers.authAuditWording.prefix`,{prefix:t})}function On(e,t){let n=e.detail??{};switch(e.action){case`admin-token-created`:{let e=n.expiresAt;return{title:J.t(`helpers.authAuditWording.tokenCreated`,{name:Tn(n,t)}),details:En([Dn(n),typeof e==`number`?J.t(`helpers.authAuditWording.expires`,{at:Pt(e)}):null])}}case`admin-token-used`:{let e=Q(n,`path`);return{title:J.t(`helpers.authAuditWording.tokenUsed`,{name:Tn(n,t)}),details:En([Dn(n),e===null?null:J.t(`helpers.authAuditWording.call`,{path:e})])}}case`admin-token-revoked`:return{title:J.t(`helpers.authAuditWording.tokenRevoked`,{name:Tn(n,t)}),details:En([Dn(n)])};case`credentials-revoked`:{let e=Q(n,`kind`)??`credential`,t=n.revoked,r=n.skipped,i=wn[e],a=i===void 0?`${e}s`:J.t(i);return{title:J.t(`helpers.authAuditWording.bulkRevoked`,{n:typeof t==`number`?String(t):`?`,noun:a}),details:En([typeof r==`number`&&r>0?J.t(`helpers.authAuditWording.skipped`,{count:r}):null,Q(n,`ids`)===null?null:J.t(`helpers.authAuditWording.ids`,{ids:Q(n,`ids`)??``})])}}case`second-factor-skipped`:{let e=Q(n,`method`),t=Q(n,`factors`);return{title:J.t(`helpers.authAuditWording.secondFactorSkipped`),details:En([e===null?null:J.t(`helpers.authAuditWording.signedInWith`,{method:$t(e)}),t===null?null:J.t(`helpers.authAuditWording.skippedFactors`,{factors:t.split(`,`).join(`, `)})])}}default:return{title:e.action,details:Object.entries(n).map(([e,t])=>`${e}: ${String(t)}`)}}}e();var kn=100;function An(){let{user:e}=bt();return e?.isAdmin?d(Mn,{}):null}function jn(){let{data:e}=be(),{data:t}=q.auth.listAdminTokens.useQuery();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.name);return{userNameById:n,tokenNameById:r}},[e,t])}function Mn(){let{t:e}=Y(),t=q.auth.listAuthAudit.useQuery({limit:kn}),{userNameById:n,tokenNameById:r}=jn(),i=t.data??[];return a(`div`,{"data-testid":`auth-audit`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[a(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[d(D,{className:`h-3.5 w-3.5 text-foreground-subtle`}),d(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`auth.authAuditSection.authenticationAudit`,`Authentication audit`)}),d(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:e(`auth.authAuditSection.latest`,{count:kn})})]}),d(`div`,{className:`p-4`,children:t.isLoading?a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(S,{className:`h-3.5 w-3.5 animate-spin`}),e(`auth.authAuditSection.loadingAuditTrail`,`Loading audit trail…`)]}):t.isError?a(`div`,{className:`text-[11px] text-danger`,children:[e(`auth.authAuditSection.couldNotLoadTheAudit`,`Could not load the audit trail:`),` `,t.error?.message??e(`auth.authAuditSection.requestFailed`,`Request failed`)]}):i.length===0?a(`div`,{className:`rounded border border-dashed border-border px-3 py-4 text-xs text-foreground-subtle text-center space-y-1`,children:[d(`div`,{children:e(`auth.authAuditSection.noAuthenticationEventsRecordedYet`,`No authentication events recorded yet.`)}),d(`div`,{className:`text-[11px] text-foreground-subtle/90`,children:e(`auth.authAuditSection.thisTrailRecordsAdminToken`,`This trail records admin-token create/use/revoke, trusted-network 2FA skips, and credential revokes (including single share-link revoke). Browser password logins are not listed here.`)})]}):d(`ul`,{className:`divide-y divide-border rounded-md border border-border max-h-[420px] overflow-y-auto`,children:i.map(e=>d(Nn,{record:e,userName:e.userId===void 0?null:n.get(e.userId)??e.userId,tokenNameById:r},e.id))})})]})}function Nn({record:e,userName:t,tokenNameById:n}){let r=On(e,n);return a(`li`,{"data-testid":`auth-audit-row`,className:`px-3 py-2 text-xs space-y-0.5`,children:[a(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[d(`span`,{className:`font-medium text-foreground`,children:r.title}),d(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Pt(e.at)})]}),a(`div`,{className:`flex flex-wrap gap-x-3 text-[11px] text-foreground-subtle`,children:[t!==null&&d(`span`,{className:`text-foreground`,children:t}),e.ip!==void 0&&d(`span`,{className:`font-mono`,children:e.ip}),r.details.map(e=>d(`span`,{className:`font-mono`,children:e},e))]})]})}e();var $={loginSessions:`login-sessions`,linkedApps:`linked-apps`,tokens:`tokens`,scopedTokens:`scoped-tokens`,adminTokens:`admin-tokens`,shareLinks:`share-links`,legacyApiKeys:`legacy-api-keys`,externalIdentities:`external-identities`,audit:`auth-audit`},Pn={[$.scopedTokens]:$.tokens,[$.adminTokens]:$.tokens};function Fn(e){return[{id:$.loginSessions,label:J.t(`system.access.loginSessions`,`Login sessions`),icon:ne,render:()=>d(pn,{})},{id:$.linkedApps,label:J.t(`system.access.linkedApps`,`Linked apps`),icon:w,render:()=>d(dn,{})},{id:$.tokens,label:J.t(`system.access.tokens`,`Tokens`),icon:te,render:({createRequested:e,onCreateConsumed:t})=>d(Cn,{headerOwnsCreate:!0,createRequested:e,onCreateConsumed:t})},{id:$.shareLinks,label:J.t(`system.access.shareLinks`,`Share links`),icon:C,render:()=>d(Rt,{})},...e?[{id:$.legacyApiKeys,label:J.t(`system.access.legacyApiKeys`,`Legacy API keys`),icon:H,render:()=>d(cn,{})}]:[],{id:$.externalIdentities,label:J.t(`system.access.signInLinks`,`Sign-in links`),icon:V,render:()=>d(sn,{})},{id:$.audit,label:J.t(`system.access.audit`,`Audit`),icon:D,render:()=>d(An,{})}]}function In({createRequested:e=!1,onCreateConsumed:t}){let{t:r}=Y(),i=ke(),o=(i.data??[]).length>0,s=n(()=>Fn(o),[o]),c=en({ids:n(()=>s.map(e=>e.id),[s]),answered:!i.isLoading}),l=dt(),[u]=gt(),f=u.get(`integration`),p=f===null?void 0:Pn[f];if(p!==void 0){let e=new URLSearchParams(u);return e.set(`integration`,p),d(mt,{to:`?${e.toString()}`,replace:!0})}let m=s.find(e=>e.id===c.selectedId)??s[0],h=m?.id??$.loginSessions;return i.isLoading?d(`div`,{className:`text-sm text-foreground-subtle`,"data-testid":`access-page`,children:r(`common.loading`,`Loading…`)}):a(`div`,{className:`flex flex-col gap-3`,"data-testid":`access-page`,children:[d(Ye,{appearance:`pills`,value:h,onValueChange:e=>{l(`?${vt(u,e,null,null).toString()}`)},children:d(rt,{"aria-label":r(`system.access.credentialKinds`,`Credential kinds`),children:s.map(e=>a(ot,{value:e.id,"data-testid":`access-kind-${e.id}`,children:[d(e.icon,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),e.label]},e.id))})}),m===void 0?null:d(`div`,{role:`region`,"aria-label":m.label,"data-testid":`access-kind-body`,children:m.render({createRequested:e&&m.id===$.tokens,onCreateConsumed:t??(()=>void 0)})},m.id)]})}function Ln(e,t){if(e===$.tokens)return a(U,{size:`sm`,type:`button`,"data-testid":`access-new-token`,onClick:t,children:[d(te,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),J.t(`system.access.newToken`,`New token`)]})}function Rn(){let[e,t]=r(!1);return{createRequested:e,requestCreate:()=>t(!0),clearCreate:()=>t(!1)}}e();var zn=[`oidcConnections`,`listConnections`],Bn=[`oidcConnections`,`connectionFormSchema`],Vn={displayName:`OpenID Connect`,icon:`shield-check`,issuerUrl:``,clientId:``,clientSecret:``,redirectUri:``,scopes:`openid profile email`,usernameClaim:`preferred_username`},Hn=/^[a-z0-9][a-z0-9-]{0,63}$/;function Un(e){return e instanceof Error?e.message:String(e)}function Wn(e,t){if(t)return typeof e==`string`&&e.length>0?e:void 0;if(ue(e))return oe;if(typeof e==`string`&&e.length>0)return e;ie(e)}function Gn(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function Kn({addonId:e}){let{t:f}=Y(),p=j(),m=c(),g=G(),v=Ee({editKey:`oidcEdit`,newKey:`oidcNew`}),[y,b]=r(!1),[x,S]=r(null),[C,w]=r(``),[T,E]=r({...Vn}),D=l(null),O=o({queryKey:[...zn,e],queryFn:async()=>p.trpcClient.oidcConnections.listConnections.query({})}),k=o({queryKey:Bn,queryFn:async()=>p.trpcClient.oidcConnections.connectionFormSchema.query({})}),M=O.data??[],N=Gn(k.data)?k.data:void 0,P=v.state,F=P.mode===`edit`?M.find(e=>e.id===P.id)??null:null;t(()=>{if(v.state.mode===`edit`&&F!==null){let e=`edit:${F.id}`;if(D.current===e)return;D.current=e,S(null),w(F.id),E(F.formValues===void 0?{...Vn}:{...F.formValues});return}if(v.state.mode===`new`){if(D.current===`new`)return;D.current=`new`,S(null),w(``),E({...Vn})}},[F,v.state]);let I=i(async()=>{await m.invalidateQueries({queryKey:zn})},[m]),L=u({mutationFn:async e=>p.trpcClient.oidcConnections.deleteConnection.mutate({id:e}),onSuccess:async()=>I()}),R=i(async e=>{await g({title:f(`system.oidcSettingsConnections.deleteOidcConnection`,`Delete OIDC connection?`),message:f(`system.oidcSettingsConnections.removeTheLoginButtonAnd`,`Remove “{{displayName}}” ({{id}}). The login button and IdP credentials for this id are dropped.`,{displayName:e.displayName,id:e.id}),confirmLabel:f(`common.delete`,`Delete`),cancelLabel:f(`common.cancel`,`Cancel`),variant:`danger`})&&(await L.mutateAsync(e.id),v.state.mode===`edit`&&v.state.id===e.id&&(v.close(),D.current=null))},[g,L,v,f]),ee=i(async()=>{let e=T.displayName,t=typeof e==`string`&&e.trim()!==``?e.trim():``;if(t===``){S(`Display name is required.`);return}let n=v.state.mode===`new`,r=n?C.trim():F?.id??``;if(n&&!Hn.test(r)){S(`Instance id must be a lowercase slug (e.g. authentik, google).`);return}if(r===``){S(`That connection is no longer available.`);return}let i=Wn(T.clientSecret,n),a=T.icon,o=T.issuerUrl,s=T.clientId,c=T.redirectUri,l=T.scopes,u=T.usernameClaim,d=u===`email`||u===`sub`?u:`preferred_username`;b(!0),S(null);try{n&&await p.trpcClient.oidcConnections.createConnection.mutate({id:r,displayName:t}),await p.trpcClient.oidcConnections.updateConnection.mutate({id:r,displayName:t,icon:typeof a==`string`?a:`shield-check`,issuerUrl:typeof o==`string`?o:``,clientId:typeof s==`string`?s:``,...i===void 0?{}:{clientSecret:i},redirectUri:typeof c==`string`?c:``,scopes:typeof l==`string`?l:`openid profile email`,usernameClaim:d}),await I(),v.close(),D.current=null}catch(e){S(Un(e))}finally{b(!1)}},[C,F?.id,v,T,I,p]),z=n(()=>[{key:`id`,header:f(`system.oidcSettingsConnections.id`,`Id`),sortValue:e=>e.id,render:e=>d(`span`,{className:`font-mono text-xs text-foreground`,children:e.id})},{key:`name`,header:f(`system.oidcSettingsConnections.name`,`Name`),sortValue:e=>e.displayName,render:e=>d(`span`,{className:`truncate font-medium text-foreground`,children:e.displayName})},{key:`issuer`,header:f(`system.oidcSettingsConnections.issuer`,`Issuer`),sortValue:e=>e.issuerUrl,render:e=>d(`span`,{className:`truncate text-xs text-foreground-muted`,children:e.issuerUrl===``?`—`:e.issuerUrl})},{key:`status`,header:f(`system.oidcSettingsConnections.status`,`Status`),notSortableReason:`Badge`,render:e=>d(K,{variant:e.configured?`success`:`warning`,children:e.configured?f(`system.oidcSettingsConnections.configured`,`Configured`):f(`system.oidcSettingsConnections.notConfigured`,`Not configured`)})},{key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,nowrap:!0,render:e=>a(`div`,{className:`flex justify-end gap-1`,children:[d(U,{type:`button`,size:`sm`,variant:`secondary`,onClick:t=>{t.stopPropagation(),v.openEdit(e.id)},children:f(`common.edit`,`Edit`)}),d(U,{type:`button`,size:`sm`,variant:`ghost`,"aria-label":f(`system.oidcSettingsConnections.delete`,`Delete {{displayName}}`,{displayName:e.displayName}),title:f(`common.delete`,`Delete`),onClick:t=>{t.stopPropagation(),R(e)},children:d(h,{className:`h-3.5 w-3.5 text-danger`})})]})}],[v,R,f]),B=v.state.mode===`new`,V=B||F!==null,H=B?`new`:F===null?`closed`:`edit:${F.id}:${F.configured?`cfg`:`empty`}`;return a(`div`,{className:`flex min-h-0 flex-col gap-3`,"data-testid":`oidc-settings-connections`,children:[a(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[a(`p`,{className:`text-sm text-foreground-muted`,children:[f(`system.oidcSettingsConnections.eachRowIsOneIdp`,`Each row is one IdP. Redirect URI:`),` `,d(`span`,{className:`font-mono text-xs`,children:`/addon/${e}/<id>/callback`})]}),a(U,{type:`button`,size:`sm`,"data-testid":`oidc-connections-add`,onClick:()=>v.openNew(),children:[d(_,{className:`h-3.5 w-3.5`}),f(`system.oidcSettingsConnections.addConnection`,`Add connection`)]})]}),O.isError?d(`p`,{className:`text-sm text-danger`,children:f(`system.oidcSettingsConnections.couldNotLoadConnections`,`Could not load connections.`)}):null,O.isPending?d(lt,{className:`h-32 w-full`}):d(Be,{columns:z,rows:M,rowKey:e=>e.id,pageSize:25,emptyMessage:f(`system.oidcSettingsConnections.noOidcConnectionsYetAdd`,`No OIDC connections yet. Add one to register an IdP.`),onRowClick:e=>v.openEdit(e.id),defaultSort:{columnKey:`name`,dir:`asc`}}),d(st,{open:V,onClose:()=>{v.close(),S(null),D.current=null},title:B?f(`system.oidcSettingsConnections.addOidcConnection`,`Add OIDC connection`):f(`system.oidcSettingsConnections.edit`,`Edit {{value1}}`,{value1:F?.displayName??`connection`}),icon:A,width:`xl`,testId:`oidc-connection-editor`,error:x,footer:d(U,{type:`button`,size:`sm`,disabled:y||B&&C.trim()===``,onClick:()=>void ee(),children:y?f(`system.oidcSettingsConnections.saving`,`Saving…`):f(`common.save`,`Save`)}),children:V?a(s,{children:[B?a(`div`,{children:[d(it,{htmlFor:`oidc-connection-id`,children:f(`system.oidcSettingsConnections.instanceId`,`Instance id`)}),d(Fe,{id:`oidc-connection-id`,value:C,onChange:e=>w(e.target.value),placeholder:`authentik`,autoComplete:`off`}),d(`p`,{className:`mt-1 text-xs text-foreground-muted`,children:f(`system.oidcSettingsConnections.urlSlugAppearsInAddon`,`URL slug — appears in /addon/{{addonId}}/<id>/callback. Stable; renaming is not supported after save.`,{addonId:e})})]}):a(`p`,{className:`text-sm text-foreground-muted`,children:[f(`system.oidcSettingsConnections.instanceId2`,`Instance id:`),` `,d(`span`,{className:`font-mono`,children:F?.id})]}),N===void 0?d(`p`,{className:`text-sm text-foreground-muted`,children:f(`system.oidcSettingsConnections.loadingForm`,`Loading form…`)}):d(Je,{schema:N,values:T,onChange:E,bare:!0},H)]}):null})]})}e();var qn=3e4,Jn=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],Yn={titleKey:`system.authentication.sectionTitle`,subtitleKey:`system.authentication.sectionSubtitle`,emptyTitleKey:`system.authentication.sectionEmptyTitle`,emptyDescriptionKey:`system.authentication.sectionEmptyDescription`,installLabelKey:`system.authentication.sectionInstall`};function Xn(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:L,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA is self-enrolled: each user enables it from their own profile page (My access → Two-factor authentication).`,`Scoped tokens, admin tokens and sessions are managed from Identity → Tokens & sessions.`],setupSteps:[`A fresh hub has one account, admin / changeme — the first sign-in asks for a new password. Add users from Users → New user.`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:z,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`Explicit linking only: an IdP account signs in only the CamStack user who linked it from their profile (My access → Linked sign-in accounts). No auto-created users, no email matching.`,`The linked user’s role, scopes and two-factor authentication apply.`],setupSteps:[`Register a web app at your IdP and copy the client_id + client_secret.`,"Choose a stable instance id (slug). Set the IdP redirect URI to `https://<this-hub>/addon/auth-oidc/<id>/callback`.",`In Settings below, Add connection — enter the id, issuer, and credentials; Save.`,`Each user then links their IdP account from My access → Linked sign-in accounts.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:z,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:y,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)?{headline:`TOTP — second factor.`,icon:y,bullets:[`Time-based codes from an authenticator app (RFC 6238).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:A,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Zn(){let{t:e}=Y(),t=_e({capName:Jn[0].capName},{refetchInterval:qn}),r=_e({capName:Jn[1].capName},{refetchInterval:qn}),i=ye(void 0,{refetchInterval:qn}),a=n(()=>on(i.data??[]),[i.data]),o=n(()=>{let e=[],n=[t.data??[],r.data??[]];for(let[t,r]of Jn.entries())for(let i of n[t]??[])e.push({addonId:i.addonId,displayName:a.get(i.addonId)??i.addonId,isActive:i.isActive,capName:r.capName,stageBadge:r.stageBadge});return e},[t.data,r.data,a]),s=[{id:`authentication`,label:e(`system.authentication.authenticationProviders`,`Authentication providers`),install:{capability:Jn[0].capName,label:e(Yn.installLabelKey)},entries:o.map(t=>({id:t.addonId,name:t.displayName,fallbackIcon:A,...an(t.isActive),render:()=>d(tn,{addonId:t.addonId,displayName:t.displayName,capName:t.capName,isActive:t.isActive,badges:t.stageBadge===null?null:d(K,{variant:`info`,className:nn,children:t.stageBadge}),settingsContent:t.addonId.startsWith(`auth-oidc`)?d(Kn,{addonId:t.addonId}):void 0,panels:[{id:`about`,title:e(`system.authentication.about`,`About`),icon:Xn(t.addonId).icon,content:d(Qn,{addonId:t.addonId})}]})}))}];return d(rn,{embedded:!0,icon:A,title:e(Yn.titleKey),subtitle:e(Yn.subtitleKey),groups:s,isLoading:t.isLoading||r.isLoading,emptyTitle:e(Yn.emptyTitleKey),emptyDescription:e(Yn.emptyDescriptionKey)})}function Qn({addonId:e}){let{t}=Y(),n=Xn(e),r=n.icon;return a(`div`,{className:`space-y-3 rounded-lg border border-border bg-surface p-2 sm:p-4`,children:[a(`div`,{className:`flex items-start gap-2.5`,children:[d(r,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),d(`div`,{className:`text-xs text-foreground font-medium`,children:n.headline})]}),d(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:n.bullets.map((e,t)=>d(`li`,{children:e},t))}),n.setupSteps&&n.setupSteps.length>0&&a(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[a(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[d(R,{className:`h-3 w-3`}),t(`system.authentication.setupSteps`,`Setup steps`)]}),d(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:n.setupSteps.map((e,t)=>d(`li`,{children:e},t))})]}),e===`local-auth`&&a(`div`,{className:`rounded-md border border-info/30 bg-info/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[d(M,{className:`h-3.5 w-3.5 mt-0.5 text-info shrink-0`}),d(`span`,{children:d(pt,{i18nKey:`system.authentication.totpNote`,components:{access:d(ft,{to:`/system/my-access`,className:`underline text-primary`}),users:d(ft,{to:`/system/identity?tab=users`,className:`underline text-primary`})}})})]})]})}function $n({isPending:e,error:t,what:n,onRetry:r,children:i}){let{t:o}=Y();return e?a(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,role:`status`,"data-testid":`query-pending`,children:[d(S,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),o(`certificates.queryBody.reading`,{what:n})]}):t===null?i:d(Oe,{title:o(`certificates.queryBody.couldNotRead`,`Could not read {{what}}`,{what:n}),message:t.message.length>0?t.message:o(`certificates.queryBody.requestFailed`,`Request failed`),onRetry:r})}function er(){let{t:e}=Y(),t=q.deviceCredentials.getDeviceCaStatus.useQuery({}),n=t.data;return d(X,{id:`device-ca`,title:e(`certificates.deviceCaCard.deviceCertificateAuthority`,`Device certificate authority`),icon:A,description:e(`certificates.deviceCaCard.signsTheCertificateEachPaired`,`Signs the certificate each paired device holds. It is created the first time a device is paired.`),children:d($n,{isPending:t.isPending,error:t.error,what:`the device CA`,onRetry:()=>void t.refetch(),children:n!==void 0&&a(`div`,{className:`space-y-1`,"data-testid":`device-ca-status`,children:[a(W,{label:e(`certificates.deviceCaCard.state`,`State`),children:[n.state===`ready`&&d(K,{variant:`success`,children:e(`certificates.deviceCaCard.ready`,`Ready`)}),n.state===`absent`&&d(K,{variant:`default`,children:e(`certificates.deviceCaCard.notCreatedYet`,`Not created yet`)}),n.state===`unavailable`&&d(K,{variant:`danger`,children:e(`certificates.deviceCaCard.unavailable`,`Unavailable`)})]}),n.state===`ready`&&a(s,{children:[d(W,{label:e(`certificates.deviceCaCard.subject`,`Subject`),valueClassName:`font-mono`,children:n.subject}),d(W,{label:e(`certificates.deviceCaCard.fingerprintSha256`,`Fingerprint (SHA-256)`),valueClassName:`font-mono`,children:n.fingerprintSha256}),d(W,{label:e(`certificates.deviceCaCard.validUntil`,`Valid until`),children:n.validTo})]}),n.state===`unavailable`&&d(W,{label:e(`certificates.deviceCaCard.reason`,`Reason`),children:d(`span`,{className:`text-danger`,children:n.reason})})]})})})}e();function tr(){let{t:e}=Y(),t=q.useUtils(),n=q.deviceCredentials.getDeviceCertificateSettings.useQuery({}),[i,o]=r(null),s=q.deviceCredentials.setDeviceCertificateSettings.useMutation({onSuccess:()=>{o(null),t.deviceCredentials.getDeviceCertificateSettings.invalidate()},onError:e=>o(`Could not save: ${e.message}`)});return d($n,{isPending:n.isPending,error:n.error,what:`the enrollment setting`,onRetry:()=>void n.refetch(),children:n.data!==void 0&&a(W,{label:e(`certificates.deviceSettingsRow.usersCanEnrollTheirOwn`,`Users can enroll their own devices`),actions:d(Ze,{checked:n.data.selfEnrollment===`allowed`,disabled:s.isPending,"aria-label":e(`certificates.deviceSettingsRow.usersCanEnrollTheirOwn`,`Users can enroll their own devices`),onCheckedChange:e=>s.mutate({selfEnrollment:e?`allowed`:`disabled`})}),children:[d(`span`,{className:`text-[11px] text-foreground-subtle`,children:n.data.selfEnrollment===`allowed`?e(`certificates.deviceSettingsRow.allowedAUserSignedIn`,`Allowed - a user signed in on a phone can keep it signed in. Pairing by QR works either way.`):e(`certificates.deviceSettingsRow.disabledOnlyAnAdminCan`,`Disabled - only an admin can pair a device, with a QR code.`)}),i!==null&&d(`span`,{className:`block text-[11px] text-danger`,children:i})]})})}e();function nr(e){let[n,i]=r(()=>Date.now());return t(()=>{let t=setInterval(()=>i(Date.now()),e);return()=>clearInterval(t)},[e]),n}e();var rr=80,ir=208;function ar({open:e,users:t,onClose:n,onPaired:i}){let{t:o}=Y(),s=q.deviceCredentials.startEnrollment.useMutation({onSuccess:i}),[c,l]=r(``),[u,f]=r(``),p=c===``?t[0]?.id??``:c,m=s.data,h=()=>{s.reset(),f(``),n()};return d(st,{open:e,onClose:h,title:o(`certificates.pairDeviceDialog.pairADevice`,`Pair a device`),icon:y,width:`md`,testId:`pair-device-dialog`,error:s.isError?s.error.message:null,footer:m===void 0?a(U,{type:`button`,onClick:()=>{let e=u.trim();p===``||e===``||s.mutate({userId:p,deviceName:e})},disabled:s.isPending||p===``||u.trim()===``,children:[s.isPending&&d(S,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),o(`certificates.pairDeviceDialog.createPairingCode`,`Create pairing code`)]}):d(U,{type:`button`,variant:`outline`,onClick:h,children:o(`certificates.pairDeviceDialog.done`,`Done`)}),children:m===void 0?a(`div`,{className:`space-y-3`,children:[d(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`certificates.pairDeviceDialog.createsAOneTimeCode`,`Creates a one-time code for a phone you hold. Scan it with the CamStack app on that phone; the phone then stays signed in as the chosen user until you revoke it.`)}),d(Se,{label:o(`certificates.pairDeviceDialog.user`,`User`),required:!0,children:d(at,{value:p,onChange:e=>l(e.target.value),options:t.map(e=>({value:e.id,label:e.username}))})}),d(Se,{label:o(`certificates.pairDeviceDialog.deviceName`,`Device name`),required:!0,description:o(`certificates.pairDeviceDialog.howThisPhoneIsListed`,`How this phone is listed, e.g. Anna's iPhone.`),children:d(Fe,{value:u,maxLength:rr,onChange:e=>f(e.target.value),placeholder:o(`certificates.pairDeviceDialog.annaSIphone`,`Anna's iPhone`),autoFocus:!0})})]}):d(or,{enrollUrl:m.enrollUrl,expiresAt:m.expiresAt,hubKnown:m.hubOrigin!==null,onRestart:()=>s.reset()})})}function or({enrollUrl:e,expiresAt:t,hubKnown:n,onRestart:r}){let{t:i}=Y(),o=Gt(t,nr(1e3));return d(`div`,{className:`space-y-3`,"data-testid":`pair-issued`,children:a(`div`,{className:`flex flex-col items-center gap-3 sm:flex-row sm:items-start`,children:[d(`div`,{className:o.expired?`opacity-30`:void 0,children:d(me,{value:e,size:ir,alt:i(`certificates.pairDeviceDialog.enrollmentQrCode`,`Enrollment QR code`)})}),a(`div`,{className:`min-w-0 flex-1 space-y-2`,children:[d(`p`,{className:`text-[11px] text-foreground-subtle`,children:i(`certificates.pairDeviceDialog.openTheCamstackAppOn`,`Open the CamStack app on the phone and scan this code. It works once.`)}),d(`div`,{className:`text-sm font-semibold tabular-nums text-foreground`,role:`timer`,"data-testid":`pair-countdown`,children:o.expired?i(`certificates.pairDeviceDialog.expiredCreateANewCode`,`Expired - create a new code`):i(`certificates.pairDeviceDialog.expiresIn`,`Expires in {{label}}`,{label:o.label})}),a(`div`,{className:`flex items-center gap-1 rounded-md border border-border bg-background px-2 py-1`,children:[d(`code`,{className:`min-w-0 flex-1 select-all break-all font-mono text-[11px] text-foreground`,children:e}),d(xe,{value:e,srLabel:`Enrollment link`})]}),!n&&a(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-2.5 py-1.5 text-[11px] text-foreground`,children:[d(g,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),d(`span`,{children:i(`certificates.pairDeviceDialog.theHubCouldNotName`,`The hub could not name an address for this link, so the app must already know it.`)})]}),o.expired&&d(U,{type:`button`,variant:`outline`,size:`sm`,onClick:r,children:i(`certificates.pairDeviceDialog.newCode`,`New code`)})]})]})})}e();var sr={key:`access.nouns.device`};function cr({pairOpen:e,onPairClose:t}){let{t:i}=Y(),o=G(),s=Ie(),c=q.useUtils(),l=q.deviceCredentials.listDeviceCredentials.useQuery({includeRevoked:!0}),u=be(),[p,m]=r(null),[g,_]=r(null),b=()=>void c.deviceCredentials.listDeviceCredentials.invalidate(),x=e=>t=>{_(null),m(`${e} failed: ${t.message}`)},S=()=>{_(null),b()},C=q.deviceCredentials.revokeDeviceCredential.useMutation({onSuccess:S,onError:x(`Revoke`)}),w=q.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.`),S()},onError:x(`Delete`)}),T=q.deviceCredentials.renameDeviceCredential.useMutation({onSuccess:S,onError:x(`Rename`)}),E=Bt(sr,e=>C.mutateAsync({id:e}),b),D=E.busy||g!==null,O=n(()=>(l.data??[]).map(Wt),[l.data]),k=async e=>{await o({title:i(`certificates.devicesCard.revoke`,`Revoke "{{name}}"?`,{name:e.name}),message:i(`certificates.devicesCard.sDeviceStopsSigningIn`,`{{ownerName}}'s device stops signing in at once and its open sessions end. To use it again it has to be paired anew. This cannot be undone.`,{ownerName:e.ownerName}),confirmLabel:i(`certificates.devicesCard.revoke2`,`Revoke`),variant:`danger`})&&(m(null),_(e.id),C.mutate({id:e.id}))},A=async e=>{await o({title:i(`certificates.devicesCard.delete`,`Delete "{{name}}"?`,{name:e.name}),message:i(`certificates.devicesCard.isRemovedFromTheList`,`{{name}} is removed from the list. The audit trail keeps the revocation.`,{name:e.name}),confirmLabel:i(`common.delete`,`Delete`),variant:`danger`})&&(m(null),_(e.id),w.mutate({id:e.id}))},j=async e=>{let t=(await s({title:i(`certificates.devicesCard.renameDevice`,`Rename device`),label:i(`certificates.devicesCard.deviceName`,`Device name`),defaultValue:e.name,confirmLabel:i(`certificates.devicesCard.rename`,`Rename`)}))?.trim()??``;t===``||t===e.name||(m(null),_(e.id),T.mutate({id:e.id,deviceName:t}))},M={label:i(`certificates.devicesCard.revoke2`,`Revoke`),icon:f,isAvailable:Nt,onRun:e=>void k(e),busyId:C.isPending?g:null,disabled:D},N=[{label:i(`certificates.devicesCard.rename`,`Rename`),icon:v,tone:`neutral`,isAvailable:()=>!0,onRun:e=>void j(e),busyId:T.isPending?g:null,disabled:D},{label:i(`common.delete`,`Delete`),icon:h,isAvailable:zt,onRun:e=>void A(e),busyId:w.isPending?g:null,disabled:D}];return a(X,{id:`devices`,title:i(`certificates.devicesCard.devices`,`Devices`),icon:y,description:i(`certificates.devicesCard.phonesThatStaySignedIn`,`Phones that stay signed in with a certificate instead of a login. Revoking one signs it out at once; it has to be paired again.`),notice:Z(p,E.outcome),onDismissNotice:()=>{m(null),E.dismiss()},children:[d(tr,{}),d(Vt,{rows:O,label:i(`certificates.devicesCard.label`),isLoading:l.isPending,loadError:l.error===null?null:l.error.message||`Request failed`,emptyText:`No devices paired yet.`,expiresNone:`—`,action:M,extraActions:N,bulk:{revoke:E,noun:sr,isSelectable:Nt}}),d(ar,{open:e,users:u.data??[],onClose:t,onPaired:b})]})}var lr={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`};function ur(e){let t=e.find(e=>e.isHub);return t?.https.kind===`served`?t.https.status.caFingerprintSha256:null}function dr({https:e,mesh:t,now:n}){let{t:r}=Y(),i=et().data?.caCertPem??``,o=()=>{if(i===``)return;let e=URL.createObjectURL(new Blob([i],{type:`application/x-pem-file`})),t=document.createElement(`a`);t.href=e,t.download=`camstack-ca.crt`,t.click(),URL.revokeObjectURL(e)},s=t?.ca,c=s?.state===`ready`?Date.parse(s.validTo):null,l=t?.listener;return a(`div`,{className:`space-y-1`,"data-testid":`ca-strip`,children:[d(W,{label:r(`certificates.caStrip.localHttpsCaSha256`,`Local HTTPS CA (SHA-256)`),valueClassName:`font-mono`,children:a(`span`,{className:`flex flex-wrap items-center gap-2`,children:[ur(e)??`—`,i!==``&&a(U,{type:`button`,variant:`ghost`,size:`sm`,onClick:o,children:[d(p,{className:`h-3 w-3`,"aria-hidden":!0}),r(`certificates.caStrip.downloadCa`,`Download CA`)]})]})}),d(W,{label:r(`certificates.caStrip.clusterCaSha256`,`Cluster CA (SHA-256)`),valueClassName:`font-mono`,children:s===void 0?`—`:s.state===`ready`?s.fingerprintSha256:d(`span`,{className:`text-danger`,children:r(`certificates.caStrip.unavailable`,{reason:s.reason})})}),s?.state===`ready`&&a(W,{label:r(`certificates.caStrip.clusterCaValidUntil`,`Cluster CA valid until`),children:[s.validTo,c!==null&&!Number.isNaN(c)&&a(`span`,{className:`ml-2 text-[10px] ${lr[Yt(c,n)]}`,children:[`(`,Ft(c,n),`)`]})]}),l!==void 0&&a(W,{label:r(`certificates.caStrip.nodeListener`,`Node listener`),children:[l.state===`open`&&d(K,{variant:`success`,children:r(`certificates.caStrip.open`,`Open`)}),l.state===`not-started`&&d(K,{variant:`default`,children:r(`certificates.caStrip.notStarted`,`Not started`)}),l.state===`closed`&&a(`span`,{className:`text-danger`,children:[r(`certificates.caStrip.closedSince`,{when:It(l.since)}),` `,l.reason]})]}),t!==void 0&&!t.registryAvailable&&a(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-2.5 py-1.5 text-[11px] text-foreground`,children:[d(g,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),d(`span`,{children:r(`certificates.caStrip.theCertificateRegistryIsNot`,`The certificate registry is not up, so the node list below is incomplete.`)})]})]})}function fr(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 pr(e){return e.isHub?J.t(`helpers.nodesModel.hubReissued`):e.mesh===null?J.t(`helpers.nodesModel.noCertRecorded`):e.online?null:J.t(`helpers.certificateModel.nodeOffline`)}function mr(e){return e.isHub||e.mesh===null?pr(e):null}var hr={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`},gr={enroll:`Issued at enrollment`,renewal:`Issued by a renewal`,boot:`Issued at boot`,pairing:`Issued at pairing`,observed:`Observed on its connection`},_r={uploaded:`Uploaded`,generated:`Generated`,disabled:`Disabled`};function vr(e){let t=e.https?.https;return t?.kind===`served`?qt(t.status.validTo):null}function yr({ms:e,now:t}){return e===null?d(`span`,{className:`text-foreground-subtle`,children:`—`}):a(`div`,{children:[d(`div`,{children:It(e)}),d(`div`,{className:`text-[10px] ${hr[Yt(e,t)]}`,children:Ft(e,t)})]})}function br({row:e}){let{t}=Y(),n=e.https?.https;return n===void 0?d(`span`,{className:`text-foreground-subtle`,children:`—`}):n.kind===`served`?a(`div`,{title:n.status.leafFingerprintSha256??``,children:[d(K,{variant:`success`,className:`text-[10px]`,children:t(`certificates.nodesColumns.served`,`Served`)}),d(`span`,{className:`ml-1.5 text-[10px] text-foreground-subtle`,children:_r[n.status.mode]}),d(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:Kt(n.status.leafFingerprintSha256)}),n.status.sans.length>0&&d(`div`,{className:`mt-0.5 max-w-[14rem] truncate font-mono text-[10px] text-foreground-subtle`,title:n.status.sans.join(`, `),children:n.status.sans.join(`, `)})]}):a(`div`,{className:`max-w-[16rem]`,children:[d(K,{variant:n.kind===`unreadable`?`danger`:`warning`,className:`text-[10px]`,children:n.kind===`unreadable`?t(`certificates.nodesColumns.unreadable`,`Unreadable`):t(`certificates.nodesColumns.notServed`,`Not served`)}),d(`div`,{className:`mt-1 whitespace-normal text-[10px] text-foreground-subtle`,children:n.reason})]})}function xr({row:e}){let{t}=Y(),n=e.mesh?.current??null;if(n===null)return d(`span`,{className:`text-foreground-subtle`,children:t(`certificates.nodesColumns.noneRecorded`,`None recorded`)});let r=e.mesh?.history.length??0;return a(`div`,{children:[d(`div`,{className:`font-mono text-[11px]`,title:n.serial,children:Ut(n.serial)}),d(`div`,{className:`font-mono text-[10px] text-foreground-subtle`,title:n.fingerprintSha256,children:Kt(n.fingerprintSha256)}),a(`div`,{className:`text-[10px] text-foreground-subtle`,children:[gr[n.issuedVia],r>0?` · ${t(`certificates.nodesColumns.earlier`,{count:r})}`:``]})]})}function Sr({row:e}){let{t}=Y(),n=e.mesh?.presentingCurrent??null;return n===null?d(`span`,{className:`text-foreground-subtle`,children:e.online?`—`:t(`certificates.nodesColumns.offline`,`Offline`)}):n?d(K,{variant:`success`,className:`text-[10px]`,children:t(`common.yes`,`Yes`)}):d(K,{variant:`warning`,className:`text-[10px]`,children:t(`certificates.nodesColumns.noPresentsAnother`,`No - presents another`)})}function Cr(e){let t=e.icon;return a(U,{type:`button`,variant:`ghost`,size:`sm`,className:e.danger?`text-danger hover:bg-danger/10`:void 0,disabled:e.reason!==null||e.busy,title:e.reason??void 0,"aria-label":e.ariaLabel,onClick:e.onClick,children:[e.spinning?d(S,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):d(t,{className:`h-3 w-3`,"aria-hidden":!0}),e.label]})}function wr({reasons:e}){let{t}=Y();return a(Ge,{className:`inline-block`,children:[d(qe,{children:d(`span`,{className:`cursor-help text-[11px] text-foreground-subtle`,"data-testid":`hub-managed-note`,children:t(`certificates.nodesColumns.managedByTheHub`,`Managed by the hub`)})}),d(We,{children:d(`ul`,{className:`max-w-xs space-y-1 whitespace-normal text-left text-[11px]`,children:e.map(e=>d(`li`,{children:e},e))})})]})}function Tr({row:e,o:t}){let{t:n}=Y(),r=e.https===null?`No HTTPS inventory for this node.`:Lt(e.https).reason,i=pr(e),o=mr(e),s=n=>t.running?.nodeId===e.nodeId&&t.running.action===n,c=t=>!e.isHub||t===null,l=[r,i,o].filter((e,t,n)=>e!==null&&n.indexOf(e)===t);return a(`div`,{className:`flex w-44 flex-col items-end gap-1`,children:[a(`div`,{className:`flex flex-col items-end gap-0.5`,children:[c(r)&&d(Cr,{label:n(`certificates.nodesColumns.renewHttps`,`Renew HTTPS`),ariaLabel:n(`certificates.nodesColumns.renewTheCertificateOn`,`Renew the certificate on {{nodeId}}`,{nodeId:e.nodeId}),icon:I,reason:r,busy:t.busy,spinning:s(`renew-https`),danger:!1,onClick:()=>t.onRenewHttps(e)}),c(i)&&d(Cr,{label:s(`renew-identity`)?n(`certificates.nodesColumns.renewing`,`Renewing…`):n(`certificates.nodesColumns.renewIdentity`,`Renew identity`),ariaLabel:n(`certificates.nodesColumns.renewTheClusterCertificateOf`,`Renew the cluster certificate of {{nodeId}}`,{nodeId:e.nodeId}),icon:I,reason:i,busy:t.busy,spinning:s(`renew-identity`),danger:!1,onClick:()=>t.onRenewIdentity(e)}),c(o)&&d(Cr,{label:n(`certificates.nodesColumns.revokeIdentity`,`Revoke identity`),ariaLabel:n(`certificates.nodesColumns.revokeTheClusterCertificateOf`,`Revoke the cluster certificate of {{nodeId}}`,{nodeId:e.nodeId}),icon:f,reason:o,busy:t.busy,spinning:s(`revoke-identity`),danger:!0,onClick:()=>t.onRevokeIdentity(e)})]}),e.isHub&&l.length>0&&d(wr,{reasons:l}),!e.isHub&&r!==null&&e.https!==null&&d(`div`,{className:`w-full whitespace-normal text-right text-[10px] text-foreground-subtle`,"data-testid":`renew-reason-${e.nodeId}`,children:r}),!e.isHub&&i!==null&&d(`div`,{className:`w-full whitespace-normal text-right text-[10px] text-foreground-subtle`,"data-testid":`mesh-reason-${e.nodeId}`,children:i})]})}function Er(e){return[{key:`node`,header:J.t(`certificates.nodesColumns.node`,`Node`),sortValue:e=>e.isHub?``:e.nodeId.toLowerCase(),render:e=>a(`div`,{className:`flex items-center gap-1.5`,children:[d(`span`,{className:`font-medium text-foreground`,children:e.nodeId}),e.nodeId===`hub`&&d(K,{variant:`info`,className:`text-[10px]`,children:J.t(`common.hubWord`)}),!e.online&&d(K,{variant:`default`,className:`text-[10px]`,children:J.t(`common.offline`)})]})},{key:`https-state`,header:`HTTPS`,notSortableReason:`A state with a reason has no single order.`,render:e=>d(br,{row:e})},{key:`https-expires`,header:J.t(`certificates.nodesColumns.httpsExpires`,`HTTPS expires`),sortValue:e=>vr(e),render:t=>d(yr,{ms:vr(t),now:e.now})},{key:`identity`,header:J.t(`certificates.nodesColumns.identity`,`Identity`),sortValue:e=>e.mesh?.current?.serial??null,render:e=>d(xr,{row:e})},{key:`identity-expires`,header:J.t(`certificates.nodesColumns.identityExpires`,`Identity expires`),sortValue:e=>e.mesh?.current?.notAfter??null,render:t=>d(yr,{ms:t.mesh?.current?.notAfter??null,now:e.now})},{key:`presenting`,header:J.t(`certificates.nodesColumns.inUse`,`In use`),notSortableReason:`Offline nodes have no answer to order by.`,render:e=>d(Sr,{row:e})},{key:`actions`,header:J.t(`certificates.nodesColumns.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order.`,render:t=>d(Tr,{row:t,o:e})}]}e();function Dr(){let{t:e}=Y(),t=G(),i=q.useUtils(),o=nr(6e4),s=q.certificates.listHttpsCertificates.useQuery(),c=q.certificates.getMeshCertificates.useQuery(),[l,u]=r(null),[f,p]=r(null),[m,h]=r(null),g=()=>{h(null),i.certificates.listHttpsCertificates.invalidate(),i.certificates.getMeshCertificates.invalidate()},_=e=>(t,n)=>{h(null),u(`${n.nodeId}: ${e} - ${t.message}`)},v=q.certificates.renewHttpsOnNode.useMutation({onSuccess:(t,n)=>{p({tone:`success`,message:t.restartRequired?e(`certificates.nodesCard.newCertificateIssuedRestartThe`,`{{nodeId}}: new certificate issued. Restart the node to serve it.`,{nodeId:n.nodeId}):e(`certificates.nodesCard.newCertificateIssuedAndServed`,`{{nodeId}}: new certificate issued and served.`,{nodeId:n.nodeId})}),g()},onError:_(`renewal failed`)}),y=q.certificates.renewMeshOnNode.useMutation({onSuccess:e=>{p(Ht(e)),g()},onError:_(`renewal could not start`)}),b=q.certificates.revokeMeshOnNode.useMutation({onSuccess:e=>{p({tone:`success`,message:`${e.nodeId}: ${e.next}`}),g()},onError:_(`revoke failed`)}),x=v.isPending||y.isPending||b.isPending,S=(e,t)=>{u(null),p(null),h({nodeId:e,action:t})},C=async n=>{await t({title:e(`certificates.nodesCard.renewHttpsOn`,`Renew HTTPS on "{{nodeId}}"?`,{nodeId:n.nodeId}),message:n.isHub?e(`certificates.nodesCard.aNewCertificateIsIssued`,`A new certificate is issued from the local CA. Clients that trust the CA keep working.`):e(`certificates.nodesCard.theNodeMakesANew`,`The node makes a new key, the hub signs it and the node switches over without a restart. It keeps serving what it had if anything fails.`),confirmLabel:e(`certificates.nodesCard.renew`,`Renew`)})&&(S(n.nodeId,`renew-https`),v.mutate({nodeId:n.nodeId}))},w=e=>{S(e.nodeId,`renew-identity`),y.mutate({nodeId:e.nodeId})},T=async n=>{await t({title:e(`certificates.nodesCard.revokeTheIdentityOf`,`Revoke the identity of "{{nodeId}}"?`,{nodeId:n.nodeId}),message:e(`certificates.nodesCard.isDisconnectedAtOnceAnd`,`{{nodeId}} is disconnected at once and can no longer connect. To bring it back it must be paired again from System → Cluster → Agents. It stays in the node list until you forget it on the Cluster page. This cannot be undone.`,{nodeId:n.nodeId}),confirmLabel:e(`certificates.nodesCard.revokeAndDisconnect`,`Revoke and disconnect`),variant:`danger`})&&(S(n.nodeId,`revoke-identity`),b.mutate({nodeId:n.nodeId}))},E=Er({now:o,busy:x,running:m,onRenewHttps:e=>void C(e),onRenewIdentity:w,onRevokeIdentity:e=>void T(e)}),D=n(()=>fr(s.data??[],c.data),[s.data,c.data]),O=c.data?.registryAvailable??!0;return d(X,{id:`nodes`,title:e(`certificates.nodesCard.nodes`,`Nodes`),icon:P,description:e(`certificates.nodesCard.eachNodeHoldsTwoCertificates`,`Each node holds two certificates: one it serves over HTTPS, one that proves its identity to the hub. Renewing replaces a certificate without a gap; revoking an identity cuts the node off until it re-joins.`),notice:Z(l,f),onDismissNotice:()=>{u(null),p(null)},children:d($n,{isPending:s.isPending||c.isPending,error:s.error??c.error,what:`node certificates`,onRetry:()=>{s.refetch(),c.refetch()},children:a(`div`,{className:`space-y-3`,children:[d(dr,{https:s.data??[],mesh:c.data,now:o}),d(Be,{columns:E,rows:D,rowKey:e=>e.nodeId,minWidthPx:960,maxBodyHeight:He,defaultSort:{columnKey:`node`,dir:`asc`},emptyMessage:O?e(`certificates.nodesCard.noNodesReported`,`No nodes reported.`):e(`certificates.nodesCard.theCertificateRegistryIsNot`,`The certificate registry is not available yet, so nodes cannot be listed.`)})]})})})}function Or({pairOpen:e,onPairClose:t}){return a(`div`,{className:`space-y-4`,"data-testid":`certificates-page`,children:[d(cr,{pairOpen:e,onPairClose:t}),d(er,{}),d(Dr,{})]})}function kr({userId:e,username:t,onClose:n}){let{t:r}=Y(),i=G(),o=q.useUtils(),s=je({userId:e}),c=q.auth.listLoginMethods.useQuery(),l=Ve({onSuccess:()=>void o.userManagement.listExternalIdentities.invalidate()}),u=new Map((c.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),f=s.data??[],p=async(n,a)=>{await i({title:r(`users.externalIdentitiesModal.removeSignInLink`,`Remove sign-in link`),message:r(`users.externalIdentitiesModal.willNoLongerBeAble`,`"{{username}}" will no longer be able to sign in with this {{label}} account.`,{username:t,label:a}),confirmLabel:r(`common.remove`,`Remove`),variant:`danger`})&&l.mutate({userId:e,provider:n.provider,subject:n.subject})};return d(ze,{open:!0,onOpenChange:e=>!e&&n(),children:a(ge,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`external-identities-modal`,children:[d(fe,{children:a($e,{className:`flex items-center gap-2`,children:[d(w,{className:`h-4 w-4 text-primary`}),a(`span`,{children:[r(`users.externalIdentitiesModal.linkedSignInAccounts`,`Linked sign-in accounts`),a(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[r(`users.externalIdentitiesModal.user`,`User:`),` `,d(`span`,{className:`font-mono`,children:t})]})]})]})}),d(ve,{className:`space-y-3`,children:s.isLoading?a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(S,{className:`h-3.5 w-3.5 animate-spin`}),r(`common.loading`,`Loading…`)]}):f.length===0?d(`p`,{className:`text-xs text-foreground-subtle`,children:r(`users.externalIdentitiesModal.noLinkedAccountsOnlyThe`,`No linked accounts. Only the user can link one, from their own profile page.`)}):d(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:f.map(e=>{let t=u.get(e.provider),n=t??e.provider;return a(`li`,{className:`flex items-center gap-3 px-3 py-2 text-xs`,children:[a(`div`,{className:`flex-1 min-w-0`,children:[a(`div`,{className:`font-medium text-foreground truncate`,children:[n,t===void 0&&d(`span`,{className:`ml-2 rounded bg-foreground-subtle/15 px-1.5 py-0.5 text-[10px] font-normal text-foreground-subtle`,children:r(`users.externalIdentitiesModal.providerUnavailable`,`provider unavailable`)})]}),a(`div`,{className:`text-[11px] text-foreground-subtle truncate`,children:[e.label??e.subject,` ·`,` `,new Date(e.linkedAt).toLocaleDateString()]})]}),a(`button`,{onClick:()=>void p(e,n),disabled:l.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[d(re,{className:`h-3 w-3`}),r(`common.remove`,`Remove`)]})]},`${e.provider}|${e.subject}`)})})}),d(nt,{children:d(U,{onClick:n,variant:`secondary`,children:r(`common.close`,`Close`)})})]})})}function Ar({userId:e,username:t,onClose:n}){let{t:r}=Y(),i=c(),o=G(),l=Qe({userId:e}),u=l.data,f=()=>i.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),p=de({onSuccess:()=>{f(),n()}}),m=l.isLoading?`loading`:u?.enabled?`enrolled`:`not_enrolled`;return d(ze,{open:!0,onOpenChange:e=>!e&&n(),children:a(ge,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[d(fe,{children:a($e,{className:`flex items-center gap-2`,children:[d(y,{className:`h-4 w-4 text-primary`}),a(`span`,{children:[r(`users.totpModal.twoFactorAuthentication`,`Two-factor authentication`),a(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[r(`users.totpModal.user`,`User:`),` `,d(`span`,{className:`font-mono`,children:t})]})]})]})}),a(ve,{className:`space-y-4`,children:[m===`loading`&&a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(S,{className:`h-3.5 w-3.5 animate-spin`}),r(`users.totpModal.checkingStatus`,`Checking status…`)]}),m===`not_enrolled`&&a(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[d(M,{className:`h-4 w-4 mt-0.5 shrink-0`}),a(`div`,{children:[d(`div`,{className:`font-medium text-foreground`,children:r(`users.totpModal.2faNotEnrolled`,`2FA not enrolled`)}),d(`p`,{className:`mt-0.5`,children:r(`users.totpModal.onlyTheUserThemselvesCan`,`Only the user themselves can enable 2FA, from their own profile page.`)})]})]}),m===`enrolled`&&u&&a(s,{children:[a(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[d(E,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),a(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[d(`div`,{className:`font-medium`,children:r(`users.totpModal.2faIsActive`,`2FA is active`)}),d(`div`,{className:`text-foreground-subtle`,children:r(`common.enrolledOn`,{when:u.confirmedAt?new Date(u.confirmedAt).toLocaleString():`—`})})]})]}),d(`div`,{className:`text-[11px] text-foreground-subtle`,children:r(`users.totpModal.removingHereClearsTheServer`,`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`)}),a(`div`,{className:`flex justify-end gap-2`,children:[d(U,{onClick:n,variant:`secondary`,children:r(`common.close`,`Close`)}),a(`button`,{onClick:async()=>{await o({title:r(`users.totpModal.remove2fa`,`Remove 2FA`),message:r(`users.totpModal.removeTwoFactorAuthenticationFor`,`Remove two-factor authentication for "{{username}}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,{username:t}),confirmLabel:r(`common.remove`,`Remove`),variant:`danger`})&&p.mutate({userId:e})},disabled:p.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:[p.isPending?d(S,{className:`h-3 w-3 animate-spin`}):d(T,{className:`h-3 w-3`}),r(`users.totpModal.remove2fa`,`Remove 2FA`)]})]})]})]})]})})}e();function jr({userId:e,username:t,onClose:n}){let{t:i}=Y(),{user:o,logout:s}=bt(),c=o?.id===e,l=G(),u=q.useUtils(),f=q.auth.listSessions.useQuery({userId:e}),[p,m]=r(null),h=q.auth.revokeSessions.useMutation({onSuccess:(e,t)=>{if(c&&`userId`in t){s();return}u.auth.listSessions.invalidate()},onError:e=>m(`Sign out failed: ${e.message}`)}),g=async e=>{await l({title:i(`users.userSessionsModal.signOutThisSession`,`Sign out this session`),message:i(`users.userSessionsModal.onWillHaveToSign`,`"{{username}}" on {{label}} will have to sign in again.`,{username:t,label:Xt(e.client).label}),confirmLabel:i(`users.userSessionsModal.signOut`,`Sign out`),variant:`danger`})&&(m(null),h.mutate({id:e.id}))},_=async()=>{await l({title:i(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`),message:c?i(`users.userSessionsModal.everySessionOfYourOwn`,`Every session of your own account ends, this browser included: you will be signed out here too.`):i(`users.userSessionsModal.everySessionOfEndsAt`,`Every session of "{{username}}" ends at once; each device has to sign in again.`,{username:t}),confirmLabel:i(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`),variant:`danger`})&&(m(null),h.mutate({userId:e}))},v=h.isPending&&h.variables!==void 0&&`id`in h.variables?h.variables.id:null;return d(ze,{open:!0,onOpenChange:e=>!e&&n(),children:a(ge,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`user-sessions-modal`,children:[d(fe,{children:a($e,{className:`flex items-center gap-2`,children:[d(ne,{className:`h-4 w-4 text-primary`}),a(`span`,{children:[i(`users.userSessionsModal.activeSessions`,`Active sessions`),a(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[i(`users.userSessionsModal.user`,`User:`),` `,d(`span`,{className:`font-mono`,children:t})]})]})]})}),a(ve,{className:`space-y-3`,children:[p!==null&&d(`div`,{className:`text-[11px] text-danger`,children:p}),d(Jt,{sessions:f.data??[],isLoading:f.isLoading,loadError:f.isError?f.error?.message??`Request failed`:null,emptyText:`No active sessions.`,onRevoke:e=>void g(e),revokingId:v})]}),a(nt,{className:`justify-between`,children:[a(`button`,{onClick:()=>void _(),disabled:h.isPending||(f.data??[]).length===0,className:`inline-flex items-center gap-1.5 rounded border border-danger/40 px-2.5 py-1 text-[11px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,children:[h.isPending&&v===null?d(S,{className:`h-3 w-3 animate-spin`}):d(B,{className:`h-3 w-3`}),i(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`)]}),d(U,{onClick:n,variant:`secondary`,children:i(`common.close`,`Close`)})]})]})})}function Mr({icon:e,label:t,count:n,all:r,total:i}){let{t:o}=Y();return a(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[d(e,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),d(`span`,{className:`min-w-0 flex-1 text-foreground-subtle`,children:t}),d(`span`,{className:n===0?`text-foreground-subtle`:`font-medium text-foreground`,children:n===0?o(`common.none`):r?o(`users.scopePreview.all`,`all {{total}}`,{total:i}):o(`users.scopePreview.of`,`{{count}} of {{total}}`,{count:n,total:i})})]})}function Nr({scopes:e,isAdmin:t,invalidReason:n}){let{t:r}=Y(),i=j(),c=o({queryKey:[`auth`,`previewScope`,e,t],enabled:n===null,queryFn:()=>i.trpcClient.auth.previewScope.query({scopes:[...e],isAdmin:t})}),{data:l}=Xe({projection:`slim`}),u=l?.length??0;if(n!==null)return d(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:a(`p`,{className:`flex items-center gap-1.5 text-[11px] text-warning`,children:[d(N,{className:`h-3 w-3 shrink-0`}),n]})});if(c.isLoading)return a(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface p-3 text-[11px] text-foreground-subtle`,children:[d(S,{className:`h-3 w-3 animate-spin`}),r(`users.scopePreview.resolving`,`Resolving…`)]});if(c.isError||!c.data)return d(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:d(`p`,{className:`text-[11px] text-danger`,children:r(`users.scopePreview.couldNotResolveThisGrant`,`Could not resolve this grant set. Saving is still allowed — the server enforces the same rules either way.`)})});let f=c.data;return d(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-3`,children:f.isAdmin?a(`p`,{className:`text-[11px] text-foreground`,children:[d(`span`,{className:`font-medium`,children:r(`users.scopePreview.administrator`,`Administrator`)}),` `,r(`users.scopePreview.unrestricted`)]}):a(s,{children:[d(Mr,{icon:m,label:r(`users.scopePreview.devicesTheyCanSee`,`Devices they can see`),count:f.device.view.deviceCount,all:f.device.view.all,total:u}),d(Mr,{icon:v,label:r(`users.scopePreview.devicesTheyCanOperate`,`Devices they can operate`),count:f.device.create.deviceCount,all:f.device.create.all,total:u}),d(Mr,{icon:h,label:r(`users.scopePreview.devicesTheyCanDelete`,`Devices they can delete`),count:f.device.delete.deviceCount,all:f.device.delete.all,total:u}),a(`div`,{className:`border-t border-border pt-2 text-[10px] text-foreground-subtle`,children:[r(`users.scopePreview.systemAccess`,`System access:`),` `,f.system.length===0?r(`common.none`):f.system.join(`, `),f.capabilities.length>0&&a(s,{children:[` `,r(`users.scopePreview.extraCapabilities`,`· Extra capabilities:`),` `,f.capabilities.map(e=>e.name).join(`, `)]}),f.addons.length>0&&a(s,{children:[` `,r(`users.scopePreview.addons`,`· Addons:`),` `,f.addons.map(e=>e.name).join(`, `)]})]}),f.device.view.deviceCount===0&&d(`p`,{className:`text-[10px] text-warning`,children:r(`users.scopePreview.thisUserWillNotBe`,`This user will not be able to see any device.`)})]})})}e();function Pr(e){let t=ce(e);return t===null?{mode:e.length===0?`role`:`advanced`,roleId:null,selector:{kind:`all`},includeLinked:!0,advancedScopes:e}:{mode:`role`,roleId:t.roleId,selector:t.selector,includeLinked:t.includeLinked,advancedScopes:e}}function Fr(e){return e.mode===`advanced`?e.advancedScopes:e.roleId===null?[]:ae({roleId:e.roleId,selector:e.selector,includeLinked:e.includeLinked})}function Ir({user:e,onClose:t,onSubmit:i,submitting:o,callerScopes:c}){let{t:l}=Y(),u=O(),f=n(()=>Pr(e.scopes??[]),[e.scopes]),[p,m]=r(f),[h,g]=r(f.mode===`advanced`),_=n(()=>Fr(p),[p]),v=!e.isAdmin&&p.mode===`role`&&p.roleId===null,y=n(()=>e.isAdmin?null:p.mode===`role`&&p.roleId===null?l(`users.userAccessModal.pickAccess`):Ne(_,u),[e.isAdmin,p.mode,p.roleId,_]),b=e=>m({...p,...e});return d(ze,{open:!0,onOpenChange:e=>!e&&t(),children:a(ge,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-2xl`,children:[a(fe,{children:[d($e,{children:l(`users.userAccessModal.title`,{name:e.username})}),d(`p`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?l(`users.userAccessModal.thisUserIsAnAdministrator`,`This user is an administrator — they can do everything, and the settings below are ignored.`):l(`users.userAccessModal.chooseWhatTheyCanDo`,`Choose what they can do, then which devices it applies to.`)})]}),a(ve,{className:`space-y-4`,children:[v&&a(`div`,{className:`flex items-start gap-2 rounded-lg border border-warning/40 bg-warning/10 p-3`,children:[d(N,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`}),a(`p`,{className:`text-[11px] text-foreground`,children:[d(`span`,{className:`font-medium`,children:l(`users.userAccessModal.noAccess`,`No access.`)}),` `,d(`span`,{className:`text-foreground-subtle`,children:l(`users.userAccessModal.cannotSeeAnything`,{name:e.username})})]})]}),a(`section`,{className:`space-y-2`,children:[d(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:l(`users.userAccessModal.1WhatCanTheyDo`,`1 · What can they do`)}),d(`div`,{className:`space-y-1.5`,children:se.map(e=>{let t=p.mode===`role`&&p.roleId===e.id;return a(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-lg border p-2.5 transition-colors ${t?`border-primary bg-primary/5`:`border-border hover:bg-foreground-subtle/5`}`,children:[d(`input`,{type:`radio`,name:`access-role`,checked:t,onChange:()=>b({mode:`role`,roleId:e.id}),className:`mt-0.5 border-border focus:ring-primary`}),a(`span`,{className:`min-w-0`,children:[d(`span`,{className:`block text-[12px] font-medium text-foreground`,children:e.label}),d(`span`,{className:`mt-0.5 block text-[10px] text-foreground-subtle`,children:e.description})]})]},e.id)})}),a(`button`,{type:`button`,onClick:()=>{if(!h){m({...p,mode:`advanced`,advancedScopes:_}),g(!0);return}g(!1),m(Pr(p.advancedScopes))},className:`inline-flex items-center gap-1 rounded px-1.5 py-1 text-[10px] text-foreground-subtle transition-colors hover:bg-foreground-subtle/10 hover:text-foreground`,children:[d(h?F:x,{className:`h-3 w-3`}),l(`users.userAccessModal.advancedEditRawGrants`,`Advanced — edit raw grants`)]}),h&&a(`div`,{className:`rounded-lg border border-border p-2`,children:[d(`p`,{className:`mb-2 text-[10px] text-foreground-subtle`,children:l(`users.userAccessModal.oneRowPerGrantAnything`,`One row per grant. Anything expressible here overrides the three roles above; close this section to go back to them.`)}),d(Ae,{value:p.advancedScopes,onChange:e=>b({mode:`advanced`,advancedScopes:e}),clampToParent:c,emptyHint:d(s,{children:d(pt,{i18nKey:`users.userAccessModal.noGrants`,values:{name:e.username},components:{b:d(`span`,{className:`font-medium text-foreground`})}})})})]})]}),p.mode===`role`&&a(`section`,{className:`space-y-2`,children:[d(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:l(`users.userAccessModal.2OnWhichDevices`,`2 · On which devices`)}),d(Ue,{value:p.selector,onChange:e=>b({selector:e}),includeLinked:p.includeLinked,onIncludeLinkedChange:e=>b({includeLinked:e}),clampToDeviceIds:null})]}),a(`section`,{className:`space-y-2`,children:[d(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:p.mode===`role`?l(`users.userAccessModal.3Result`,`3 · Result`):l(`users.userAccessModal.2Result`,`2 · Result`)}),d(Nr,{scopes:_,isAdmin:e.isAdmin,invalidReason:y})]})]}),a(nt,{children:[d(U,{variant:`outline`,size:`sm`,onClick:t,children:l(`common.cancel`,`Cancel`)}),d(U,{size:`sm`,onClick:()=>i([..._]),disabled:o||y!==null,children:o?d(S,{className:`h-3 w-3 animate-spin`}):l(`users.userAccessModal.saveAccess`,`Save access`)})]})]})})}e();var Lr=8;function Rr(){return{username:``,password:``,isAdmin:!1}}function zr(e){return{id:e.id,username:e.username,password:``,isAdmin:e.isAdmin}}function Br(e){return e instanceof Error?e.message:J.t(`admin.system.users.genericError`)}function Vr(){let{t:e}=Y(),n=c(),{user:i}=bt(),{state:o,openNew:l,openEdit:u,close:f}=Ee(),[p,m]=r(null),[g,x]=r(null),[C,T]=r(!1),{data:E,isLoading:D,isError:O,error:k,refetch:j}=be(),M=G(),N=Ie(),P=()=>n.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),F=Me(),I=tt({onSuccess:P}),L=Ce({onSuccess:P}),R=we({onSuccess:P}),z=pe({onSuccess:()=>{P(),V(null)}}),[B,V]=r(null),[H,te]=r(null),[re,ie]=r(null),[ae,oe]=r(null),se=E??[],ce=o.mode===`edit`?se.find(e=>e.id===o.id)??null:null,le=()=>{m(null),x(null),T(!1),F.reset(),L.reset(),f()};t(()=>{if(o.mode===`closed`){m(null),x(null),T(!1);return}if(o.mode===`new`){m(e=>e!==null&&e.id===void 0?e:Rr());return}if(ce===null){D||f();return}m(e=>e?.id===ce.id?e:zr(ce))},[o,ce,D,f]);let ue=o.mode===`new`&&p!==null&&p.id===void 0||o.mode===`edit`&&p!==null&&ce!==null;async function de(t){await M({title:e(`admin.system.users.deleteUser`,`Delete user`),message:e(`admin.system.users.permanentlyDeleteUserThisCannot`,`Permanently delete user "{{username}}"? This cannot be undone — any active sessions will be revoked on next request.`,{username:t.username}),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&(I.mutate({id:t.id}),o.mode===`edit`&&o.id===t.id&&le())}async function fe(t){let n=await N({title:e(`admin.system.users.resetPassword`,`Reset password`),message:e(`admin.system.users.setANewPasswordFor`,`Set a new password for "{{username}}".`,{username:t.username}),label:e(`admin.system.users.newPassword`,`New password`),inputType:`password`,placeholder:e(`admin.system.users.atLeast8Characters`,`At least 8 characters`),confirmLabel:e(`admin.system.users.continue`,`Continue`),validate:e=>e.length<Lr?J.t(`admin.system.users.passwordTooShort`,{min:Lr}):null});n===null||n.length===0||await M({title:e(`admin.system.users.resetPassword`,`Reset password`),message:e(`admin.system.users.resetThePasswordForThey`,`Reset the password for "{{username}}"? They will need to use the new password on their next login.`,{username:t.username}),confirmLabel:e(`common.reset`,`Reset`)})&&R.mutate({id:t.id,newPassword:n})}function me(e,t){t!==e.isAdmin&&L.mutate({id:e.id,isAdmin:t})}async function he(){if(p!==null){x(null);try{if(p.id===void 0){let e=p.username.trim();if(e===``||p.password.length<Lr)return;await F.mutateAsync({username:e,password:p.password,isAdmin:p.isAdmin})}else await L.mutateAsync({id:p.id,isAdmin:p.isAdmin});P(),le()}catch(e){x(Br(e))}}}function ge(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}let _e=F.isPending||L.isPending,ve=p!==null&&p.id===void 0&&p.username.trim()!==``&&p.password.length>=Lr,ye=p!==null&&p.id!==void 0,xe=_e||(p?.id===void 0?!ve:!ye),W=e=>I.isPending&&I.variables?.id===e.id||L.isPending&&L.variables?.id===e.id||R.isPending&&R.variables?.id===e.id,De=[{key:`username`,header:e(`admin.system.users.username`,`Username`),sortValue:e=>e.username,render:e=>d(`span`,{className:`font-medium text-foreground`,"data-testid":`user-open-${e.id}`,children:e.username})},{key:`isAdmin`,header:e(`admin.system.users.admin`,`Admin`),nowrap:!0,sortValue:e=>+!!e.isAdmin,render:t=>d(`span`,{onClick:e=>e.stopPropagation(),children:a(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[d(`input`,{type:`checkbox`,checked:t.isAdmin,onChange:e=>me(t,e.target.checked),disabled:W(t),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),d(`span`,{className:t.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:t.isAdmin?e(`admin.system.users.admin`,`Admin`):e(`admin.system.users.regular`,`Regular`)})]})})},{key:`scopes`,header:e(`admin.system.users.access`,`Access`),render:t=>t.isAdmin?d(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:e(`admin.system.users.everythingAdmin`,`everything (admin)`)}):d(`span`,{onClick:e=>e.stopPropagation(),children:a(U,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>V(t),title:e(`admin.system.users.configureAccess`,`Configure access`),children:[d(A,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),d(Hr,{scopes:t.scopes??[]})]})})},{key:`createdAt`,header:e(`admin.system.users.created`,`Created`),nowrap:!0,sortValue:e=>e.createdAt,render:e=>d(`span`,{className:`text-foreground-subtle`,children:ge(e.createdAt)})},{key:`actions`,header:e(`admin.system.users.actions`,`Actions`),align:`right`,nowrap:!0,notSortableReason:`Row actions`,render:t=>{let n=W(t),r=t.id!==i?.id&&t.totpEnabled;return a(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[a(U,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>u(t.id),disabled:n,title:e(`admin.system.users.editUser`,`Edit user`),children:[d(v,{className:`h-3 w-3`}),e(`common.edit`,`Edit`)]}),r&&a(U,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>te(t),disabled:n,title:e(`admin.system.users.removeTwoFactorAuthentication`,`Remove two-factor authentication`),children:[d(y,{className:`h-3 w-3`}),e(`admin.system.users.remove2fa`,`Remove 2FA`)]}),a(U,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>ie(t),disabled:n,title:e(`admin.system.users.linkedSignInAccounts`,`Linked sign-in accounts`),children:[d(w,{className:`h-3 w-3`}),e(`admin.system.users.signInLinks`,`Sign-in links`)]}),a(U,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>oe(t),disabled:n,title:e(`admin.system.users.activeSessions`,`Active sessions`),children:[d(ne,{className:`h-3 w-3`}),e(`admin.system.users.sessions`,`Sessions`)]}),a(U,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void fe(t),disabled:n,title:e(`admin.system.users.resetPassword`,`Reset password`),children:[d(ee,{className:`h-3 w-3`}),e(`admin.system.users.resetPassword`,`Reset password`)]}),a(U,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void de(t),disabled:n,title:e(`admin.system.users.deleteUser`,`Delete user`),className:`text-danger hover:bg-danger/10`,children:[n?d(S,{className:`h-3 w-3 animate-spin`}):d(h,{className:`h-3 w-3`}),e(`common.delete`,`Delete`)]})]})}}];return a(St,{embedded:!0,icon:b,title:e(`admin.system.users.users`,`Users`),subtitle:e(`admin.system.users.hubAccountsAdminFlagAccess`,`Hub accounts, admin flag, access scopes, sessions and sign-in links.`),actions:a(U,{size:`sm`,type:`button`,onClick:()=>{x(null),l()},children:[d(_,{className:`h-3.5 w-3.5`}),e(`admin.system.users.createUser`,`Create User`)]}),children:[O&&d(Oe,{title:e(`admin.system.users.couldNotLoadUsers`,`Could not load users`),message:Br(k),onRetry:()=>void j()}),D&&a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(S,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}),!D&&!O&&se.length===0&&d(Re,{icon:b,title:e(`admin.system.users.noUsersYet`,`No users yet`),description:e(`admin.system.users.createAUserToGrant`,`Create a user to grant hub access.`)}),!D&&!O&&se.length>0&&d(Be,{columns:De,rows:se,rowKey:e=>e.id,minWidthPx:560,maxBodyHeight:`max-h-[60vh]`,onRowClick:e=>u(e.id)}),d(st,{open:ue,onClose:le,title:p?.id===void 0?e(`admin.system.users.createUser`,`Create User`):e(`admin.system.users.edit`,`Edit {{value1}}`,{value1:p.username||`user`}),icon:b,error:g,testId:`user-form-dialog`,footer:d(U,{size:`sm`,type:`button`,disabled:xe,onClick:()=>void he(),children:_e?a(s,{children:[d(S,{className:`h-3.5 w-3.5 animate-spin`}),e(`admin.system.users.saving`,`Saving…`)]}):p?.id===void 0?e(`admin.system.users.create`,`Create`):e(`common.save`,`Save`)}),children:p!==null&&a(`div`,{className:`space-y-3`,children:[d(Se,{label:e(`admin.system.users.username`,`Username`),required:p.id===void 0,children:d(Fe,{value:p.username,onChange:e=>m({...p,username:e.target.value}),placeholder:`john`,autoFocus:p.id===void 0,disabled:p.id!==void 0,"data-testid":`user-form-username`})}),p.id===void 0&&d(Se,{label:e(`admin.system.users.password`,`Password`),required:!0,description:e(`admin.system.users.atLeastCharacters`,`At least {{value1}} characters.`,{value1:String(Lr)}),children:d(Te,{value:p.password,onValueChange:e=>m({...p,password:e}),shown:C,onToggleShown:()=>T(e=>!e),placeholder:`••••••••`,"data-testid":`user-form-password`})}),d(Se,{label:e(`admin.system.users.admin`,`Admin`),description:e(`admin.system.users.unrestrictedAccessToEveryCapability`,`Unrestricted access to every capability and device.`),children:a(`label`,{className:`inline-flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[d(`input`,{type:`checkbox`,checked:p.isAdmin,onChange:e=>m({...p,isAdmin:e.target.checked}),className:`rounded border-border focus:ring-primary`,"data-testid":`user-form-admin`}),d(`span`,{children:e(`admin.system.users.admin`,`Admin`)})]})}),p.id!==void 0&&d(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`admin.system.users.toChangeThePasswordUse`,`To change the password, use Reset password on the user's row. Access scopes are configured from the Access column.`)})]})}),H&&d(Ar,{userId:H.id,username:H.username,onClose:()=>te(null)}),re&&d(kr,{userId:re.id,username:re.username,onClose:()=>ie(null)}),ae&&d(jr,{userId:ae.id,username:ae.username,onClose:()=>oe(null)}),B&&d(Ur,{user:B,onClose:()=>V(null),onSubmit:e=>z.mutate({userId:B.id,scopes:e}),submitting:z.isPending})]})}function Hr({scopes:e}){let{t}=Y(),n=O();if(e.length===0)return d(`span`,{className:`font-medium text-warning`,children:t(`admin.system.users.noAccess`,`No access`)});let r=ce(e);return r===null?d(`span`,{className:`text-foreground-subtle`,children:t(`users.customGrants`,{count:e.length})}):a(`span`,{className:`text-foreground-subtle`,children:[d(`span`,{className:`font-medium text-foreground`,children:le(r.roleId).label}),` ·`,` `,Ke(r.selector,n)]})}function Ur(e){let{user:t}=bt(),n=t?.isAdmin===!0;return d(Ir,{...e,callerScopes:n?null:t?.scopes??[]})}e();var Wr={"api-keys":$.tokens,"linked-sessions":$.linkedApps},Gr=`certificates`;function Kr(e){return a(U,{size:`sm`,type:`button`,"data-testid":`certificates-pair-device`,onClick:e,children:[d(y,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),J.t(`systemPage.identity.pairADevice`,`Pair a device`)]})}function qr(){let{t:e}=Y(),[t]=gt(),n=Rn(),[i,a]=r(!1),o=Wr[t.get(`tab`)??``];if(o!==void 0)return d(mt,{to:_t(`access`,{integration:o}),replace:!0});let s=ut(`/system/identity`,{t:e,isAdmin:!0})??{icon:k,title:e(`system.identity`,`Identity & Access`)},c=t.get(`tab`)??`users`,l=t.get(`integration`),u=c===ht.access.tab?Ln(l,n.requestCreate):c===`certificates`?Kr(()=>a(!0)):void 0;return d(xt,{icon:s.icon,title:s.title,defaultSection:`users`,sectionsLabel:`${s.title} sections`,actions:u,sections:[{id:`users`,label:e(`systemPage.identity.users`,`Users`),content:d(Vr,{})},{id:ht.access.tab,label:e(`systemPage.identity.tokensSessions`,`Tokens & sessions`),content:d(In,{createRequested:n.createRequested,onCreateConsumed:n.clearCreate}),ownedParams:yt.concat([hn.token,hn.scoped,hn.admin])},{id:Gr,label:e(`systemPage.identity.certificates`,`Certificates`),content:d(Or,{pairOpen:i,onPairClose:()=>a(!1)})},{id:ht.authentication.tab,label:e(`systemPage.identity.authentication`,`Authentication`),content:d(Zn,{}),ownedParams:yt}]})}export{qr as IdentityPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{$ as e,B as t,G as n,J as r,L as i,S as a,o,q as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Ir as l,It as u,Lr as d,Nt as f,On as p,Sn as m,_i as h,_n as g,ai as _,ar as v,bi as y,di as b,dt as x,fn as S,ht as C,ia as w,ln as ee,ot as T,qi as E,yi as D,yn as O}from"./player-overlays-D0U2dNvn.js";import{t as k}from"./search-x-eqJd3G8u.js";import{Mr as A}from"./client-DYbvGOid.js";import{$i as j,An as M,Dn as N,En as te,It as P,Ji as ne,Kt as F,Mr as I,Sa as L,Tn as R,Tt as z,Va as B,Xi as V,Yi as H,Zi as U,ao as W,co as G,et as re,fo as ie,fu as ae,ha as oe,hr as K,in as q,jn as se,lo as ce,lu as le,mr as ue,na as de,oa as fe,oo as pe,qi as me,rt as he,sa as ge,so as _e,ta as J,tt as ve,ua as ye,uo as Y,wa as be,yn as xe}from"./src-CGxdJN_f.js";import{t as X}from"./useTranslation-D3Is_4B6.js";import{n as Se}from"./addon-icons-context--6Hi3qRW.js";import{$ as Ce,L as we,Q as Te,Y as Ee,et as De}from"./index-DvOECbab.js";import{t as Oe}from"./NodeAddonsSettingsPanel-BMat4ckt.js";import{t as ke}from"./device-integration-icon-D2lWVDM2.js";import{n as Ae,r as je,t as Me}from"./ScanNetworkModal-dHWFmbFe.js";e();function Z(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Z(n.fields));return t}function Ne(e,t,a){let[o,s]=r(`idle`),[c,l]=r({}),u=n(()=>{let t=[];for(let n of e.sections)t.push(...Z(n.fields));return t},[e]),d=u.length>0&&a!==void 0,f=i(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:o,hasProbeFields:d,probeResults:c,handleTestAll:i(async()=>{if(!a)return;let e=u.filter(e=>{let n=t[e];return n!=null&&String(n).trim()!==``});if(e.length===0)return;s(`testing`);let n={};for(let t of e)n[t]={status:`probing`};l(n);let r=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await a(e,t[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),i={};for(let e of r)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;i[t]={status:n.status===`ok`?`ok`:`error`,result:n}}l(i),s(`idle`)},[a,u,t]),clearProbeResult:f}}e();function Pe(e){let t=[];for(let n of e)`required`in n&&n.required===!0&&`key`in n&&n.key&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Pe(n.fields));return t}function Fe(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Ie(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Ie(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function Le(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function Re({open:e,integrationId:s,addonId:l,onClose:u}){let{t:d}=X(),p=o(),[m,h]=r({}),[g,_]=r(!1),[y,b]=r(null),[w,ee]=r(Le),T=L({addonId:l},{enabled:e}),E=T.data?.deviceType??null,O=ye({addonId:l,type:E??A.Camera},{enabled:e&&T.isSuccess&&E!==null}),k=O.data??null;t(()=>{e&&(h(k?Ie(k.sections.flatMap(e=>e.fields)):{}),ee(Le()),_(!1),b(null))},[e,s,k]);let j=n(()=>({...m,_probeRequestId:w}),[m,w]),M=J({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),N=B(),te=i(async(e,t)=>{_(!0);let n=await N.mutateAsync({addonId:l,type:E??A.Camera,key:e,value:t,formValues:j});return n.status===`ok`&&n.suggestedValues&&h(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Fe(e[i])&&!Fe(a)&&(r[i]=a,t=!0);return t?r:e}),n},[N,l,j,E]),{testAllStatus:P,hasProbeFields:ne,probeResults:F,handleTestAll:I,clearProbeResult:R}=Ne(k??{sections:[]},m,te);async function V(e){b(null);try{await M.mutateAsync({addonId:l,type:E??A.Camera,config:m,integrationId:s}),e?h(k?Ie(k.sections.flatMap(e=>e.fields)):{}):u()}catch(e){b(e instanceof Error?e.message:String(e))}}if(!e)return null;let H=Pe((k?.sections??[]).flatMap(e=>e.fields)).filter(e=>Fe(m[e])),U=H.length===0,W=T.isLoading||E!==null&&O.isLoading,G=T.isError||T.isSuccess&&E===null||O.isError||O.isSuccess&&k===null;return a(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:u}),a(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[calc(90dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl`,children:[a(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:d(`integrations.addDevice`)}),c(`button`,{onClick:u,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:c(x,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:W?c(`div`,{className:`flex items-center justify-center py-8`,children:c(v,{className:`h-5 w-5 animate-spin text-primary`})}):G?a(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[c(f,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),a(`div`,{className:`space-y-1`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:d(`integrations.addDeviceDialog.providerUnavailable`,`Provider unavailable`)}),c(`p`,{className:`text-xs text-foreground-subtle`,children:c(Ee,{i18nKey:`integrations.addDeviceDialog.notReady`,values:{addonId:l},components:{mono:c(`span`,{className:`font-mono`})}})})]})]}):c(we,{schema:k,values:m,onChange:h,onTestField:te,probeResults:F,onClearProbe:R})}),!G&&!W&&a(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[a(`button`,{type:`button`,onClick:()=>_(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[a(`span`,{className:`flex items-center gap-2`,children:[c(S,{className:`h-3.5 w-3.5`}),d(`integrations.addDeviceDialog.testLogs`,`Test logs`),c(`span`,{className:`font-mono text-[9px] opacity-60`,children:w.slice(0,14)})]}),c(D,{className:`h-3.5 w-3.5 transition-transform ${g?`rotate-180`:``}`})]}),g&&c(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:c(z,{addonId:l,requestId:w,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!G&&!W&&(y||H.length>0)&&c(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:a(`div`,{className:`flex items-start gap-2`,children:[c(f,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:y||d(`integrations.addDeviceDialog.required`,`Required: {{value1}}`,{value1:H.join(`, `)})})]})}),a(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[a(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:u,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:d(`integrations.cancel`)}),!G&&ne&&a(`button`,{type:`button`,onClick:I,disabled:P===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[P===`testing`?c(v,{className:`h-3.5 w-3.5 animate-spin`}):c(C,{className:`h-3.5 w-3.5`}),d(`integrations.addDeviceDialog.testAll`,`Test All`)]})]}),a(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:()=>V(!0),disabled:G||!U||M.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:d(`integrations.saveAndNew`)}),c(`button`,{onClick:()=>V(!1),disabled:G||!U||M.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:M.isPending?d(`integrations.saving`):d(`integrations.save`)})]})]})]})]})}var Q=1500;function ze({addonId:e,integrationId:t,jobId:n,onFinished:r}){let{t:i}=X(),o=me(),s=(V({addonId:e,integrationId:t},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?Q:!1}).data??[]).find(e=>e.jobId===n);if(!s)return null;let l=s.state===`running`,u=s.processed,d=s.total>0?Math.round(u/s.total*100):0;!l&&s.finishedAt!==null&&r();let p=[`${u}/${s.total} ${i(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];s.adopted>0&&p.push(`${s.adopted} ${i(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),s.alreadyAdopted>0&&p.push(`${s.alreadyAdopted} ${i(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),s.failed>0&&p.push(`${s.failed} ${i(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let m=p.join(` · `);return a(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[a(`div`,{className:`flex items-center gap-2`,children:[l?c(v,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):s.failed>0?c(f,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):s.state===`cancelled`?c(_,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):c(b,{className:`h-3.5 w-3.5 text-primary shrink-0`}),c(`p`,{className:`text-[11px] text-foreground`,children:m}),l&&c(`button`,{onClick:()=>o.mutate({jobId:n}),className:`ml-auto rounded-lg border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.adoptJobCancel`,{defaultValue:`Stop`})})]}),c(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:c(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${d}%`},role:`progressbar`,"aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100})}),s.results.filter(e=>e.outcome===`failed`).slice(0,5).map(e=>a(`p`,{className:`text-[11px] text-destructive`,children:[e.childNativeId,`: `,e.error]},e.childNativeId))]})}function Be(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}e();var $=`devices`;function Ve(e){return{id:$,label:e(`integrations.adoptDevicesModal.defaultFilter`),isDefault:!0}}var He=2e4,Ue=100;function We({addonId:e,integrationId:n,onClose:l}){let u=w(),{t:d}=X(),p=o(),[m,h]=r(new Set),[_,b]=r(new Set),[S,C]=r(new Map),[ee,T]=r(null),{data:E}=_e(),D=(E??[]).find(t=>t.addonId===e)?.supportsLocationImport??!1,[O,k]=r(!0),A=ne({addonId:e,integrationId:n}).data?.filters,M=A&&A.length>0?A:[Ve(d)],[N,te]=r(M.find(e=>e.isDefault)?.id??(M.some(e=>e.id===$)?$:M[0].id)),P=N!==$,F=U(),I=H({addonId:e,integrationId:n,page:1,pageSize:He,filter:N}),L=I.refetch,R=F.mutate,z=i(()=>{R({addonId:e,integrationId:n},{onSettled:()=>{L()}})},[R,e,n,L]),B=s(null);t(()=>{let t=`${e}::${n}`;B.current===t||I.isLoading||(B.current=t,(I.data?.candidates.length??0)===0&&z())},[e,n,I.isLoading,I.data,z]);let V=F.isPending,W=F.isError?F.error instanceof Error?F.error.message:String(F.error):null,G=typeof F.data?.lastError==`string`&&F.data.lastError.length>0?F.data.lastError:null,ie=I.data?.candidates??[],oe=I.isError?I.error instanceof Error?I.error.message:String(I.error):null,K=j(),[q,se]=r(null),ce=i(e=>{e.alreadyAdopted||h(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),ue=i(e=>{b(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),de=i((e,t)=>{C(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),fe=i(e=>{let t={};for(let n of e){let e=S.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[S]),pe=i(async()=>{T(null);let t=[...m];if(t.length!==0)try{let r=fe(t),{jobId:i}=await K.mutateAsync({addonId:e,integrationId:n,filter:N,childNativeIds:t,...r?{perCandidate:r}:{},...D?{importLocations:O}:{}});se(i),h(new Set),C(new Map)}catch(e){T(e instanceof Error?e.message:String(e))}},[m,fe,K,e,n,N,D,O]),me=s(null),he=i(()=>{q===null||me.current===q||(me.current=q,L(),p.invalidateQueries({queryKey:[[`integrations`]]}),p.invalidateQueries({queryKey:[[`deviceManager`]]}))},[q,L,p]),ge=i(e=>{te(e),h(new Set),b(new Set),C(new Map),T(null)},[]),J=m.size,ve=q!==null&&J===0&&!K.isPending;return a(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:l}),a(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] rounded-xl border border-border bg-background shadow-2xl`,children:[a(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[a(`div`,{className:`min-w-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:d(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),c(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:d(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),a(`div`,{className:`flex items-center gap-3 shrink-0`,children:[D&&a(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[c(`input`,{type:`checkbox`,checked:O,onChange:e=>k(e.target.checked),className:`accent-primary`}),d(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),c(`button`,{onClick:l,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":d(`common.close`,`Close`),children:c(x,{className:`h-4 w-4`})})]})]}),a(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(W??oe??G)&&ie.length===0&&c(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:a(`div`,{className:`flex items-start gap-2`,children:[c(f,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),a(`div`,{className:`min-w-0`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:d(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),c(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:W??oe??G})]})]})}),M.length>1&&c(Ge,{filters:M,activeFilter:N,onSelect:ge}),c(`div`,{className:`flex-1 min-h-0`,children:c(re,{mode:`generic`,items:ie,pageSize:Ue,getKey:e=>e.childNativeId,getSearchText:Be,getFilterType:e=>e.type,filterOptions:le(u),filterLabel:d(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:I.isLoading||V&&ie.length===0,searchPlaceholder:d(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(W??oe??G)&&ie.length===0?``:d(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:a(`button`,{type:`button`,onClick:z,disabled:V,title:d(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[c(g,{className:`h-3.5 w-3.5 ${V?`animate-spin`:``}`}),d(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:d(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>c(Ke,{candidate:e,expandable:!P,expanded:_.has(e.childNativeId),onToggleExpand:()=>ue(e.childNativeId),adoptedLabel:d(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:d(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=ae(e.type,u),n=t.icon;return a(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[c(n,{className:`h-3.5 w-3.5 shrink-0`}),t.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>c(`div`,{className:`flex items-center justify-end`,children:c(`button`,{onClick:()=>ce(e),disabled:e.alreadyAdopted,"aria-label":m.has(e.childNativeId)?d(`integrations.adoptDevicesModal.deselect`,`Deselect`):d(`integrations.adoptDevicesModal.select`,`Select`),className:`inline-flex h-5 w-5 items-center justify-center rounded border ${m.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:m.has(e.childNativeId)&&c(y,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!P&&_.has(e.childNativeId),renderExpanded:P?void 0:e=>c(qe,{candidate:e,hiddenChildIds:S.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>de(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:m.has(e.childNativeId)?`bg-primary/5`:``})})]}),ee&&c(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:a(`div`,{className:`flex items-start gap-2`,children:[c(f,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:ee})]})}),q!==null&&c(ze,{addonId:e,integrationId:n,jobId:q,onFinished:he}),a(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[c(`div`,{}),a(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:l,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:d(`integrations.cancel`,{defaultValue:`Cancel`})}),a(`button`,{onClick:ve?l:pe,disabled:!ve&&(J===0||K.isPending),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,children:[K.isPending&&c(v,{className:`h-3.5 w-3.5 animate-spin`}),ve?d(`integrations.close`,{defaultValue:`Close`}):d(`integrations.addSelected`,{defaultValue:`Add selected`}),!ve&&J>0?` (${J})`:``]})]})]})]})]})}function Ge({filters:e,activeFilter:t,onSelect:n}){let{t:r}=X();return c(`div`,{role:`tablist`,"aria-label":r(`integrations.adoptDevicesModal.discoveryGranularity`,`Discovery granularity`),className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return c(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function Ke({candidate:e,expandable:t,expanded:n,onToggleExpand:r,adoptedLabel:i}){let{t:o}=X(),s=(e.children??[]).length;return a(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&s>0?a(`button`,{type:`button`,onClick:r,"aria-label":n?o(`integrations.adoptDevicesModal.collapse`,`Collapse`):o(`integrations.adoptDevicesModal.expand`,`Expand`),"aria-expanded":n,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[c(n?D:h,{className:`h-3.5 w-3.5`}),s]}):c(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),c(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&c(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:i})]})}function qe({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let{t:r}=X(),i=e.children??[];return i.length===0?null:c(`div`,{className:`space-y-1 py-1`,children:i.map(e=>{let i=t.has(e.childNativeId),o=e.capabilities??[];return a(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${i?`opacity-50`:``}`,children:[c(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),o.length>0&&c(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:o.join(`, `)}),c(`button`,{onClick:()=>n(e.childNativeId),"aria-label":i?r(`integrations.adoptDevicesModal.showChild`,`Show child`):r(`integrations.adoptDevicesModal.hideChild`,`Hide child`),title:i?r(`integrations.adoptDevicesModal.showAfterAdopt`,`Show after adopt`):r(`integrations.adoptDevicesModal.hideAfterAdopt`,`Hide after adopt`),className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:c(i?d:l,{className:`h-3 w-3`})})]},e.childNativeId)})})}e();function Je(e){let t=[];for(let n of e){if(n.type===`group`){t.push(...Je(n.fields));continue}`key`in n&&typeof n.key==`string`&&t.push(n.key)}return t}function Ye(e,t){if(!e)return{};let n=new Set(e.sections.flatMap(e=>Je(e.fields))),r={};for(let e of n)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}function Xe(e){return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{if(`value`in e){let{value:t,...n}=e;return n}return e})}))}}function Ze({integrationId:e,addonId:t,name:r,kind:i,mode:s,brokerKind:l,canTest:u=!1,trpc:d,onClose:f}){let{t:p}=X(),m=o(),{data:h,isLoading:g}=G({id:e},{enabled:s===`account`||s===`broker`}),_=n(()=>{let e=h?.brokerId;return typeof e==`string`?e:null},[h]),{data:y,isLoading:b}=ue({addonId:t,nodeId:`hub`},{enabled:s===`account`}),x=n(()=>y?Xe(y):null,[y]),S=Y(),C=(t,n)=>{S.mutate({id:e,settings:t,...n?{secretKeys:[...n]}:{}},{onSuccess:()=>{m.invalidateQueries(),f()}})};return c(R,{open:!0,onOpenChange:e=>!e&&f(),children:a(N,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[c(M,{children:a(se,{children:[p(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,r]})}),c(te,{children:s===`broker`?l?a(`div`,{className:`space-y-3`,children:[c(`p`,{className:`text-[11px] text-foreground-subtle`,children:p(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),_&&a(`p`,{className:`text-[11px] text-foreground`,children:[p(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,c(`span`,{className:`font-mono text-foreground-subtle`,children:_})]}),S.isPending?a(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(v,{className:`h-3 w-3 animate-spin`}),p(`integrations.saving`,{defaultValue:`Saving…`})]}):c(je,{kind:l,onResolved:e=>{C({brokerId:e})},onBack:f}),S.isError&&c(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):c(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):s===`account`?g||b?a(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(v,{className:`h-3 w-3 animate-spin`}),p(`integrations.loading`,{defaultValue:`Loading…`})]}):c(Ae,{addonId:t,configSchema:x,canTest:u,initialName:r,initialConfig:Ye(x,h??{}),submitLabel:p(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e,secretKeys:t})=>C(e,t),onBack:f}):c(xe,{trpc:d,addonId:t,nodeId:`hub`,title:r})})]})})}function Qe(e){return e==null?!1:e.sections.some(e=>e.fields.length>0)}e();function $e(){let{t:e}=X(),{integrationId:s}=Ce(),l=o(),d=Te(),[f,h]=De(),g=T(),[_,y]=r(!1),[b,x]=r(!1),[C,w]=r(!1),[D,A]=r(!1),{data:j,isLoading:ne}=pe({id:s??``},{enabled:!!s}),{data:L}=ue({addonId:j?.addonId??``,nodeId:`hub`},{enabled:!!j?.addonId}),{data:B,isSuccess:V}=_e(),H=n(()=>{let e=j?.addonId;return!e||!V?null:(B??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[B,j?.addonId,V]),{data:U}=fe({}),G=n(()=>(U?.providers??[]).some(e=>e.addonId===j?.addonId),[U,j?.addonId]),ae=H!==null,le=j?.info?.fixed===!0,me=ae?H===`device-adoption`?e(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):e(`integrations.addDevice`):e(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),J=n(()=>{let e=j?.addonId;return!e||!V?null:(B??[]).find(t=>t.addonId===e)?.brokerKind??null},[B,j?.addonId,V]),ye=n(()=>{let e=j?.addonId;return!e||!V?!1:(B??[]).find(t=>t.addonId===e)?.canTest===!0},[B,j?.addonId,V]),Y=n(()=>{let e=j?.addonId;return!e||!V?null:(B??[]).find(t=>t.addonId===e)?.mode??null},[B,j?.addonId,V]);t(()=>{f.get(`add`)===`1`&&ae&&(y(!0),h(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[f,ae,h]);let xe=L!=null&&Array.isArray(L.sections)&&L.sections.some(e=>e.fields.length>0),{data:Se}=K({addonId:j?.addonId??``,nodeId:`hub`},{enabled:!!j?.addonId&&Y!==`account`}),we=Y!==null&&Y!==`account`&&Qe(Se),Ee=n(()=>j?.addonId?[j.addonId]:[],[j?.addonId]),{data:Ae}=oe({projection:`slim`},{refetchInterval:3e4}),je=[[`integrations`,`get`],{input:{id:s??``},type:`query`}],Z=ie({onMutate:async e=>{await l.cancelQueries({queryKey:je});let t=l.getQueryData(je);return t!=null&&l.setQueryData(je,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&l.setQueryData(je,r.previous)},onSettled:()=>{l.invalidateQueries({queryKey:[[`integrations`]]}),l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ne=W({onSuccess:()=>{l.invalidateQueries({queryKey:[[`integrations`]]}),l.invalidateQueries({queryKey:[[`deviceManager`]]}),d(`/integrations`)}}),Pe=I({onSuccess:()=>{l.invalidateQueries({queryKey:[[`integrations`]]}),l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=be({onSuccess:()=>{l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ie=de({onSuccess:()=>{l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Le=ge({onSuccess:()=>{l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=n(()=>Ae??[],[Ae]),ze=n(()=>{let e=new Map;for(let t of Q)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[Q]),Be=i(e=>ze.get(e)??null,[ze]),{data:$}=ce(void 0),Ve=n(()=>ve($),[$]),He=i(e=>d(`/devices/${String(e)}`),[d]),Ue=n(()=>{let e=j?.id;return e?Q.filter(t=>{let n=Ve(t);return n.kind===`resolved`&&n.integration.id===e}):[]},[Q,j?.id,Ve]),Ge=n(()=>$===void 0?null:he(Ue).length,[$,Ue])??`…`;return ne?a(`div`,{className:`p-4`,children:[c(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),c(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):j?a(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[c(F,{items:[{label:e(`integrationDetail.integrations`,`Integrations`),onClick:()=>d(`/integrations`)},{label:j.name}]}),a(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[a(`div`,{className:`flex items-center gap-3 min-w-0`,children:[c(et,{addonId:j.addonId}),a(`div`,{className:`min-w-0`,children:[c(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:j.name}),a(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[j.addonId,` · `,Ge,` `,e(`integrations.devices`)]})]})]}),a(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[G&&a(`button`,{onClick:()=>x(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:e(`integrationDetail.scanTheNetworkForDevices`,`Scan the network for devices (incl. a different subnet)`),children:[c(m,{className:`h-3.5 w-3.5`}),e(`integrationDetail.scanNetwork`,`Scan network`)]}),!le&&a(`button`,{onClick:()=>y(!0),disabled:!ae,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:me,children:[c(p,{className:`h-3.5 w-3.5`}),me]}),a(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Z.isPending?`opacity-60`:``} ${j.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:e(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[c(q,{checked:j.enabled,onCheckedChange:e=>Z.mutate({id:s,enabled:e}),disabled:Z.isPending,"aria-label":j.enabled?e(`integrationDetail.disableIntegration`,`Disable integration`):e(`integrationDetail.enableIntegration`,`Enable integration`)}),c(`span`,{className:`text-[11px] font-medium ${j.enabled?`text-success`:`text-foreground-subtle`}`,children:j.enabled?e(`integrationDetail.enabled`,`Enabled`):e(`integrationDetail.disabled`,`Disabled`)}),Z.isPending&&c(v,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Y!==`standalone`&&(xe||H===`device-adoption`)&&a(`button`,{onClick:()=>w(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[c(ee,{className:`h-3 w-3`}),e(`integrations.config`)]}),a(`button`,{onClick:()=>A(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:e(`integrations.logs`,{defaultValue:`View logs`}),children:[c(S,{className:`h-3 w-3`}),e(`integrations.logs`,{defaultValue:`Logs`})]}),c(P,{label:e(`integrationDetail.restart`,`Restart`),icon:O,title:e(`integrationDetail.restart2`,`Restart "{{name}}"?`,{name:j.name}),description:e(`integrationDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device backed by it ({{topLevelCountLabel}} active). Streams will reconnect automatically.`,{topLevelCountLabel:Ge}),confirmLabel:e(`integrationDetail.restart`,`Restart`),triggerVariant:`outline`,confirmVariant:`danger`,disabled:Pe.isPending,action:()=>Pe.mutateAsync({addonId:j.addonId})}),!le&&s&&c(P,{label:e(`integrations.delete`,{defaultValue:`Delete`}),icon:u,title:e(`integrations.deleteTitle`,{defaultValue:`Delete integration?`}),description:e(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:j.name,count:Ge}),confirmLabel:e(`integrations.confirmDelete`,{defaultValue:`Delete integration`}),triggerVariant:`outline`,confirmVariant:`danger`,className:`border-danger bg-danger/10 text-danger hover:bg-danger hover:text-background`,disabled:Ne.isPending,action:()=>Ne.mutateAsync({id:s})})]})]}),we&&c(Oe,{nodeId:null,addonIds:Ee,level:`global`,surface:`integration`,title:e(`integrations.settings`,{defaultValue:`Settings`})}),c(re,{context:`integration-detail`,devices:Q,trpc:g.trpcClient,integrationOf:Ve,forceIntegrationId:j.id,urlScope:`root`,lsKey:`integration-detail:${j.addonId}`,resolveIntegrationIcon:ke,resolveParent:Be,onNavigate:He,batchActions:{remove:Fe.mutate,disable:Ie.mutate,enable:Le.mutate},...le?{}:{onDeleteDevice:e=>Fe.mutate({deviceId:e.id})}}),_&&s&&H===`device-adoption`&&c(We,{addonId:j.addonId,integrationId:s,onClose:()=>y(!1)}),_&&s&&H===`device-provider`&&c(Re,{open:_,integrationId:s,addonId:j.addonId,onClose:()=>y(!1)}),b&&j&&c(Me,{open:b,scope:{addonId:j.addonId,label:j.name},onClose:()=>x(!1)}),C&&s&&H!==null&&Y!==null&&c(Ze,{integrationId:s,addonId:j.addonId,name:j.name,kind:H,mode:Y,brokerKind:J,canTest:ye,trpc:g.trpcClient,onClose:()=>w(!1)}),D&&c(R,{open:!0,onOpenChange:e=>!e&&A(!1),children:a(N,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[c(M,{className:`mb-0`,children:a(se,{className:`flex items-center gap-2 min-w-0`,children:[c(S,{className:`h-4 w-4 text-primary shrink-0`}),c(`span`,{className:`truncate`,children:j.name}),a(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate font-normal`,children:[j.addonId,s?` · ${s}`:``]})]})}),c(te,{className:`min-h-0 overflow-hidden p-0`,children:c(z,{addonId:j.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})})]}):a(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[c(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:c(k,{className:`h-6 w-6 text-foreground-subtle`})}),a(`div`,{className:`space-y-1 max-w-sm`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),c(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:s??``})})]}),a(`button`,{onClick:()=>d(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[c(E,{className:`h-3 w-3`}),e(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}function et({addonId:e}){let t=Se(e),[n,i]=r(!1);return!t||n?null:c(`img`,{src:t,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:()=>i(!0)})}export{$e as IntegrationDetailPage};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{$ as e,B as t,G as n,J as r,S as i,b as a,o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{$t as c,Br as l,Fi as u,Fr as d,Hi as f,It as p,Mr as m,O as h,On as g,Pn as _,Qi as v,Qr as y,Rt as b,V as x,Vr as S,Vt as C,Xi as w,Zi as T,_i as E,cr as D,dt as O,er as k,fn as A,hr as j,ji as ee,k as M,ki as N,lr as P,nn as F,nr as I,pt as L,sn as R,ui as z,ut as B,wi as te,yi as ne,yn as V,z as H,zt as re}from"./player-overlays-D0U2dNvn.js";import{t as ie}from"./boxes-DikDfAoo.js";import{n as ae,r as oe,t as se}from"./speaker-CcCWWecW.js";import{t as ce}from"./user-round-CMg3Ndlt.js";import{Xt as le,er as U,nr as W}from"./client-DYbvGOid.js";import{$l as ue,An as de,Bn as G,Da as fe,Dn as K,Ea as pe,En as me,Gi as he,Hi as ge,Ma as _e,Na as ve,Nt as ye,Oa as be,Pa as xe,Pt as Se,Ql as q,Ta as Ce,Tn as we,Ui as Te,Ut as J,W as Ee,Wi as De,Zn as Oe,_a as ke,an as Ae,ar as je,ba as Me,d as Ne,eu as Pe,ha as Fe,ja as Ie,jn as Le,kn as Re,on as ze,ql as Be,tr as Ve,va as He,ya as Ue,za as We}from"./src-CGxdJN_f.js";import{t as Y}from"./i18n-Vb3uBp7P.js";import{t as X}from"./useTranslation-D3Is_4B6.js";import{Q as Ge,X as Z,et as Ke,x as qe}from"./index-DvOECbab.js";import{t as Je}from"./AdminSectionedPage-B-qoE6ra.js";import{a as Ye,n as Xe,r as Ze}from"./linked-devices-model-CB7qgVjI.js";e();var Qe={camera:te,hub:ae,container:ie,light:P,siren:F,switch:re,sensor:v,thermostat:C,climate:T,button:z,"event-emitter":B,update:oe,notifier:u,script:A,automation:L,lock:I,cover:ee,valve:S,humidifier:l,"water-heater":m,fan:d,"media-player":se,"alarm-panel":R,control:c,presence:ce,weather:y,vacuum:N,"lawn-mower":b,image:j,smoke:w};function Q({type:e,className:t}){return s(Qe[e]??z,{"aria-hidden":`true`,className:t??`h-3.5 w-3.5 shrink-0 text-foreground-subtle`})}function $e({online:e,deviceName:t}){return s(`span`,{className:e?`inline-block h-1.5 w-1.5 shrink-0 rounded-full bg-success`:`inline-block h-1.5 w-1.5 shrink-0 rounded-full border border-foreground-subtle`,role:`img`,"aria-label":Y.t(`locations.deviceGlyphs.aria`,{name:t,state:e?Y.t(`common.online`):Y.t(`common.offline`)}),title:e?Y.t(`common.online`):Y.t(`common.offline`)})}function et({open:e,title:n,items:a,listState:o,lockedIds:c,lockedNote:l,suggestions:u=null,busy:d=!1,onConfirm:f,onClose:p}){let{t:m}=X(),[h,g]=r([]);t(()=>{e||g([])},[e]);let _=new Map(a.map(e=>[e.id,e.name])),v=(u?.ids??[]).filter(e=>_.has(e)&&!c.includes(e)),y=e=>g(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]);return s(we,{open:e,onOpenChange:e=>e?void 0:p(),children:i(K,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":n,children:[s(de,{children:s(Le,{children:n})}),i(me,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:[e&&u!==null&&v.length>0&&i(`section`,{"aria-label":u.heading,className:`flex flex-col gap-1`,children:[s(`h3`,{className:`text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:u.heading}),s(`div`,{className:`flex flex-wrap gap-1`,children:v.map(e=>s(`button`,{type:`button`,"aria-pressed":h.includes(e),className:`inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${h.includes(e)?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:bg-surface-hover`}`,onClick:()=>y(e),children:_.get(e)},e))})]}),e&&s(Ne,{devices:a,listState:o,value:h,onChange:e=>g(e),noun:`device`,emptyLabel:m(`locations.addDialog.nonePicked`),showAll:!0,lockedIds:c,lockedNote:l,testId:`quick-add-picker`})]}),i(Re,{children:[s(G,{variant:`ghost`,onClick:p,children:m(`locations.addDialog.cancel`)}),s(G,{disabled:h.length===0||d,onClick:()=>f(h),children:m(`locations.addDialog.confirm`,{count:h.length})})]})]})})}e();function tt({room:e,cameras:t,fleet:r}){let{t:i}=X(),a=n(()=>new Map(r.map(e=>[e.id,e])),[r]);return e===null?s(`p`,{className:`text-xs text-foreground-subtle`,children:i(`locations.links.noRoom`)}):s(`div`,{className:`flex flex-col gap-3`,"data-testid":`camera-links-section`,children:t.length===0?s(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`camera-links-empty`,children:i(`locations.links.noCameras`,{room:e})}):t.map(e=>s(rt,{camera:e,byId:a},e.id))})}function nt(e){return{id:e.deviceId,name:e.parentName===null?e.name:`${e.parentName} · ${e.name}`,type:e.type,location:e.location}}function rt({camera:e,byId:t}){let{t:n}=X(),a=o(),c=Ge(),[l,u]=r(!1),[d,f]=r(null),p=Te({deviceId:e.id}),m=Ze({status:p.status,data:p.data,error:p.error===null||p.error===void 0?null:p.error}),g=De(),_=m.kind===`present`?m:null,v=ge({deviceId:e.id,slotRef:_?.slot.slotRef??``},{enabled:l&&_!==null}),y=_===null?[]:Xe(_.slot,_.value),b=y.map(e=>e.deviceId),x=(v.data?.candidates??[]).map(nt),S=new Set(x.map(e=>e.id)),C=b.filter(e=>!S.has(e)).map(e=>{let n=t.get(e);return{id:e,name:n?.name??`#${String(e)}`,...n===void 0?{}:{type:n.type,location:n.location}}}),w=[...x,...C],T=(v.data?.candidates??[]).filter(e=>e.suggested).map(e=>e.deviceId),E=async t=>{if(_!==null){f(null);try{await g.mutateAsync({deviceId:e.id,slotRef:_.slot.slotRef,value:Ye(_.value,t)}),await p.refetch(),await a.invalidateQueries({queryKey:[[`deviceManager`]]}),u(!1)}catch(e){f(e instanceof Error?e.message:String(e))}}},O=[{key:`device`,header:n(`locations.columns.device`),notSortableReason:n(`locations.columns.noSort`),render:e=>{let r=t.get(e.deviceId),a=e.name??r?.name??`#${String(e.deviceId)}`;return i(`span`,{className:`flex items-center gap-1.5`,children:[r!==void 0&&s(Q,{type:r.type}),s(Z,{to:`/devices/${String(e.deviceId)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:a}),e.implied&&s(`span`,{className:`text-[10px] text-foreground-subtle`,children:n(`locations.links.implied`)})]})}},{key:`type`,header:n(`locations.columns.type`),notSortableReason:n(`locations.columns.noSort`),render:e=>s(`span`,{className:`text-xs text-foreground-muted`,children:t.get(e.deviceId)?.type??`—`})},{key:`status`,header:n(`locations.columns.status`),notSortableReason:n(`locations.columns.noSort`),render:e=>{let r=t.get(e.deviceId);return r===void 0?s(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):i(`span`,{className:`flex items-center gap-1.5`,children:[s($e,{online:r.online,deviceName:r.name}),s(`span`,{className:`text-xs text-foreground-muted`,children:r.online?n(`common.online`):n(`common.offline`)})]})}}];return i(`section`,{className:`min-w-0 ${h}`,"data-testid":`camera-links-${String(e.id)}`,children:[i(`header`,{className:`${M} flex min-h-9 items-center gap-1.5`,children:[s(Q,{type:e.type}),s(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:e.name}),i(G,{variant:`ghost`,size:`sm`,onClick:()=>c(qe(e.id)),children:[s(D,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),n(`locations.links.edit`)]}),s(G,{variant:`outline`,size:`sm`,disabled:_===null,onClick:()=>u(!0),"aria-label":n(`locations.links.addNamed`,{camera:e.name}),children:n(`locations.room.add`)})]}),m.kind===`pending`&&s(`p`,{role:`status`,className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:n(`locations.links.loading`)}),m.kind===`unknown`&&s(`p`,{role:`alert`,className:`px-3 py-3 text-xs text-warning sm:px-4`,children:n(`locations.links.unreadable`,{reason:m.reason})}),m.kind===`absent`&&s(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:n(`locations.links.unsupported`)}),d!==null&&s(`p`,{role:`alert`,className:`px-3 pt-2 text-xs text-danger break-words sm:px-4`,children:d}),_!==null&&(y.length===0?s(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:n(`locations.links.none`)}):s(J,{columns:O,rows:y,rowKey:e=>String(e.deviceId),bordered:!1,minWidthPx:360})),s(et,{open:l,title:n(`locations.links.pickTitle`,{camera:e.name}),items:w,listState:v.status===`error`?`failed`:v.data===void 0?`pending`:`answered`,lockedIds:b,lockedNote:n(`locations.links.alreadyLinked`),suggestions:e.location===null?null:{heading:n(`locations.links.suggested`,{room:e.location}),ids:T},busy:g.isPending,onConfirm:e=>void E(e),onClose:()=>u(!1)})]})}e();function it({name:e,description:n,busy:a,onSave:o}){let{t:c}=X(),[l,u]=r(n??``);return t(()=>{u(n??``)},[n]),i(`div`,{className:`border-t border-border px-3 py-2 sm:px-4`,children:[s(ze,{htmlFor:`location-description-${e}`,className:`block`,children:c(`locations.locationDescriptionField.whatIsThere`,`What is there`)}),s(`textarea`,{id:`location-description-${e}`,value:l,onChange:e=>u(e.target.value),onBlur:()=>{let e=l.trim();e!==(n??``)&&o(e.length===0?null:e)},disabled:a,rows:2,maxLength:400,placeholder:c(`locations.locationDescriptionField.surfacesBoundariesWhatIsNormally`,`Surfaces, boundaries, what is normally parked or stored here.`),className:`mt-1 w-full resize-y rounded-md border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-inset focus:ring-primary disabled:cursor-not-allowed disabled:opacity-50`}),s(`p`,{className:`mt-1 ${H}`,children:c(`locations.locationDescriptionField.givenToTheAiWith`,`Given to the AI with the pictures, so it knows what it is looking at. Describe the PLACE, not what happens in it — events change, the ground does not.`)})]})}function at(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0||n.description.length===0?null:n.description}var ot=` none`;function st({name:e,zones:t,zoneKey:n,busy:r,onChange:a}){let{t:o}=X();if(t.length===0)return null;let c=[{value:ot,label:o(`locations.locationZoneField.none`,`— none —`)},...t.map(e=>({value:e.zoneKey,label:e.label}))];return i(`div`,{className:`flex items-center gap-2 border-t border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:[s(ze,{htmlFor:`location-zone-${e}`,children:o(`locations.locationZoneField.zone`,`Zone`)}),s(Be,{id:`location-zone-${e}`,value:n??ot,disabled:r,onChange:e=>{let n=e.target.value;if(n===ot){a(null);return}let r=t.find(e=>e.zoneKey===n);r!==void 0&&a(r.label)},options:c})]})}function ct(e,t){return e.find(e=>e.locationKeys.includes(t))?.zoneKey??null}function lt({name:e,icon:t,busy:n,onPick:r}){return s(Pe,{value:t,onPick:r,fallbackGlyph:k,clearGlyph:f,labels:{trigger:`Change the icon of ${e}`,panel:`Icon for ${e}`,searchPlaceholder:`Search icons`,clear:`No icon`,noMatches:`No icon matches that`},disabled:n})}function ut(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0?null:W(n.icon)??`map-pin`}function $(e){if(e==null)return null;let t=e.trim();return t.length===0?null:t.toLowerCase()}function dt(e,t){let n=$(t);return n===null?[]:e.filter(e=>$(e.location)===n)}function ft(e,t){let n=dt(e,t),r=new Set(n.map(e=>e.id));return n.filter(e=>e.parentDeviceId===null||!r.has(e.parentDeviceId))}function pt(e,t){let n=$(e.location);return n===null||new Set(t.map(e=>$(e))).has(n)?null:e.location?.trim()??null}function mt(e,t){let n=$(e.location);return n!==null&&t.has(n)}function ht(e,t){let n=new Set(t.map(e=>$(e))),r=new Set(e.filter(e=>mt(e,n)).map(e=>e.id));return e.filter(e=>!(mt(e,n)||e.parentDeviceId!==null&&r.has(e.parentDeviceId)))}function gt(e,t){return ht(e,t).filter(e=>e.parentDeviceId===null)}function _t(e,t){let n=new Map;for(let t of e){if(t.parentDeviceId===null)continue;let e=n.get(t.parentDeviceId);e?e.push(t):n.set(t.parentDeviceId,[t])}let r=[],i=new Set([t]),a=[t];for(;a.length>0;){let e=[];for(let t of a)for(let a of n.get(t)??[])i.has(a.id)||(i.add(a.id),r.push(a),e.push(a.id));a=e}return r}function vt(e,t){return _t(e,t).length}function yt(e,t){return e.filter(e=>!e.isCamera&&e.parentDeviceId===t)}function bt(e,t){return t.map(t=>({name:t,members:ft(e,t)}))}function xt(e){return`${e.kind}:${String(e.device.id)}`}function St(e,t,n){return e.flatMap(e=>{let r=yt(t,e.id),i=n.has(e.id),a={kind:`member`,device:e,accessories:r,open:i};return!i||r.length===0?[a]:[a,...r.map(t=>({kind:`accessory`,device:t,parent:e}))]})}e();function Ct({name:e,members:t,devices:o,busy:c,icon:l,description:u,onRename:d,onDelete:f,onRebuildLinks:m,onAddDevices:g,onPickIcon:v,onSaveDescription:y,zones:b,zoneKey:x,onChangeZone:S}){let{t:C}=X(),[w,T]=r(!1),[E,D]=r(e),k=ye(t,n(()=>({searchText:e=>[e.name,...yt(o,e.id).map(e=>e.name)],facetValue:e=>e.type}),[o])),[A,j]=r(()=>new Set),ee=e=>j(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),N=n(()=>St(k.rows,o,A),[k.rows,o,A]),P=[{key:`name`,header:C(`locations.columns.device`),notSortableReason:C(`locations.columns.noSort`),render:e=>e.kind===`member`?s(wt,{row:e,onToggle:()=>ee(e.device.id)}):s(Tt,{row:e})},{key:`type`,header:C(`locations.columns.type`),notSortableReason:C(`locations.columns.noSort`),render:e=>s(`span`,{className:`text-xs text-foreground-muted`,children:e.device.type})},{key:`status`,header:C(`locations.columns.status`),notSortableReason:C(`locations.columns.noSort`),render:e=>i(`span`,{className:`flex items-center gap-1.5`,children:[s($e,{online:e.device.online,deviceName:e.device.name}),s(`span`,{className:`text-xs text-foreground-muted`,children:e.device.online?C(`common.online`):C(`common.offline`)})]})}],F=()=>{D(e),T(!1)},I=async()=>{let t=E.trim();if(t.length===0||t===e){F();return}await d(t),T(!1)},L=[{id:`rename`,label:C(`locations.locationCard.rename`,`Rename`),icon:_,disabled:c,onClick:()=>{D(e),T(!0)}},{id:`rebuild-links`,label:C(`locations.locationCard.rebuildLinkedDevices`,`Rebuild linked devices`),icon:V,separatorBefore:!0,disabled:c,onClick:()=>void m()},{id:`delete`,label:C(`common.delete`,`Delete`),icon:p,danger:!0,separatorBefore:!0,disabled:c,onClick:()=>void f()}];return i(`section`,{className:`min-w-0 ${h}`,children:[i(`header`,{className:`${M} flex min-h-9 items-center gap-1.5`,children:[s(lt,{name:e,icon:l,busy:c,onPick:v}),w?i(a,{children:[s(q,{value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`&&I(),e.key===`Escape`&&F()},"aria-label":C(`locations.locationCard.rename2`,`Rename {{name}}`,{name:e}),className:`min-w-0 flex-1`,autoFocus:!0}),s(G,{type:`button`,size:`sm`,onClick:()=>void I(),children:C(`common.save`,`Save`)}),s(ue,{type:`button`,variant:`ghost`,icon:O,onClick:F,"aria-label":C(`locations.locationCard.cancelRename`,`Cancel rename`)})]}):i(a,{children:[s(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:e}),s(G,{type:`button`,variant:`outline`,size:`sm`,disabled:c,onClick:g,"aria-label":C(`locations.room.addTo`,{room:e}),children:C(`locations.room.add`)}),s(Ee,{items:L,title:C(`locations.locationCard.actionsFor`,`Actions for {{name}}`,{name:e}),triggerClassName:`p-1`})]})]}),s(st,{name:e,zones:b,zoneKey:x,busy:c,onChange:S}),s(it,{name:e,description:u,busy:c,onSave:y}),t.length>0&&s(`div`,{className:`border-b border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:s(Se,{state:k.state,facets:k.facets,labels:{searchPlaceholder:C(`locations.filter.searchPlaceholder`),searchLabel:C(`locations.room.searchLabel`,{room:e}),facetsLabel:C(`locations.filter.typesLabel`),clearLabel:C(`locations.filter.clear`)},onSearch:k.setSearch,onToggleFacet:k.toggleFacet,onClear:k.clear})}),t.length===0?s(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:C(`locations.locationCard.nothingHereYetAssignA`,`Nothing here yet — assign a device from the table below.`)}):s(J,{columns:P,rows:N,rowKey:xt,bordered:!1,minWidthPx:360,emptyMessage:C(`locations.filter.noMatch`)})]})}function wt({row:e,onToggle:t}){let{t:n}=X(),{device:r,accessories:a,open:o}=e,c=o?ne:E;return i(`span`,{className:`flex items-center gap-1.5`,children:[a.length>0?i(G,{type:`button`,variant:`ghost`,onClick:t,"aria-expanded":o,"aria-label":n(o?`locations.locationCard.collapseAccessories`:`locations.locationCard.expandAccessories`,{count:a.length,name:r.name}),className:`h-auto shrink-0 gap-0.5 p-0.5 text-foreground-subtle hover:text-foreground`,children:[s(c,{className:`h-3 w-3`}),s(`span`,{className:`text-[10px] tabular-nums`,children:a.length})]}):s(`span`,{"aria-hidden":`true`,className:`w-[1.35rem] shrink-0`}),s(Q,{type:r.type}),s(Z,{to:`/devices/${String(r.id)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:r.name})]})}function Tt({row:e}){let{device:t}=e;return i(`span`,{className:`flex items-center gap-1.5 pl-6`,children:[s(`span`,{"aria-hidden":`true`,className:`text-[10px] text-foreground-subtle`,children:`└`}),s(Q,{type:t.type,className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(Z,{to:`/devices/${String(t.id)}`,className:`min-w-0 truncate text-xs text-foreground-muted hover:underline`,children:t.name})]})}e();function Et({zones:e,busy:t,onRename:n,onDelete:i,onPickIcon:a}){let{t:o}=X(),[c,l]=r(null),[u,d]=r(``),f=async e=>{let t=u.trim();l(null),!(t.length===0||t===e)&&await n(e,t)};return s(J,{columns:[{key:`icon`,header:o(`locations.siteZonesPanel.icon`,`Icon`),width:`w-12`,notSortableReason:`An icon has no order`,render:e=>s(lt,{name:e.label,icon:e.icon,busy:t,onPick:t=>a(e.label,t)})},{key:`name`,header:o(`locations.siteZonesPanel.zone`,`Zone`),sortValue:e=>e.label.toLowerCase(),render:e=>c===e.label?s(q,{value:u,onChange:e=>d(e.target.value),onKeyDown:t=>{t.key===`Enter`&&f(e.label),t.key===`Escape`&&l(null)},onBlur:()=>void f(e.label),"aria-label":o(`locations.siteZonesPanel.rename`,`Rename {{label}}`,{label:e.label}),autoFocus:!0}):s(G,{type:`button`,variant:`ghost`,size:`sm`,className:`px-0`,onClick:()=>{d(e.label),l(e.label)},disabled:t,title:o(`locations.siteZonesPanel.renameTheZone`,`Rename the zone`),children:e.label})},{key:`rooms`,header:o(`locations.siteZonesPanel.rooms`,`Rooms`),align:`right`,sortValue:e=>e.locationKeys.length,render:e=>s(`span`,{className:`tabular-nums text-foreground-subtle`,children:e.locationKeys.length===0?o(`common.empty`):o(`common.rooms`,{count:e.locationKeys.length})})},{key:`actions`,header:o(`locations.siteZonesPanel.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order`,render:e=>s(G,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void i(e.label),disabled:t,"aria-label":o(`locations.siteZonesPanel.delete`,`Delete {{label}}`,{label:e.label}),title:o(`locations.siteZonesPanel.deleteTheZoneTheRooms`,`Delete the zone — the rooms in it are kept`),children:s(p,{className:`h-3.5 w-3.5`})})}],rows:e,rowKey:e=>e.zoneKey,emptyMessage:o(`locations.siteZonesPanel.noZonesYetAZone`,`No zones yet. A zone groups rooms — “Zona notte” for the bedrooms — and shows up before them in the app’s camera filter.`)})}e();function Dt({busy:e,onCreate:t}){let{t:n}=X(),[a,o]=r(!1),[c,l]=r(``),u=()=>{l(``),o(!1)},d=async()=>{let e=c.trim();e.length!==0&&(await t(e),u())};return a?i(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),d()},children:[s(q,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&u()},placeholder:n(`locations.newLocationButton.ingressoSaloneCucina`,`Ingresso, Salone, Cucina…`),"aria-label":n(`locations.newLocationButton.newLocationName`,`New location name`),className:`min-w-[12rem] flex-1`,autoFocus:!0}),i(G,{size:`sm`,type:`submit`,disabled:c.trim().length===0||e,children:[s(g,{className:`h-3.5 w-3.5`}),n(`common.add`,`Add`)]}),s(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":n(`locations.newLocationButton.cancelNewLocation`,`Cancel new location`),children:s(O,{className:`h-3.5 w-3.5`})})]}):i(G,{size:`sm`,type:`button`,onClick:()=>o(!0),"data-testid":`new-location-button`,children:[s(g,{className:`h-3.5 w-3.5`}),n(`locations.newLocationButton.newLocation`,`New location`)]})}e();function Ot({busy:e,onCreate:t}){let{t:n}=X(),[a,o]=r(!1),[c,l]=r(``),u=()=>{l(``),o(!1)},d=async()=>{let e=c.trim();e.length!==0&&(await t(e),u())};return a?i(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),d()},children:[s(q,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&u()},placeholder:n(`locations.newZoneButton.zonaGiornoZonaNotte`,`Zona giorno, Zona notte…`),"aria-label":n(`locations.newZoneButton.newZoneName`,`New zone name`),className:`min-w-[12rem] flex-1`,autoFocus:!0}),i(G,{size:`sm`,type:`submit`,disabled:c.trim().length===0||e,children:[s(g,{className:`h-3.5 w-3.5`}),n(`common.add`,`Add`)]}),s(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":n(`locations.newZoneButton.cancelNewZone`,`Cancel new zone`),children:s(O,{className:`h-3.5 w-3.5`})})]}):i(G,{size:`sm`,type:`button`,onClick:()=>o(!0),"data-testid":`new-zone-button`,children:[s(g,{className:`h-3.5 w-3.5`}),n(`locations.newZoneButton.newZone`,`New zone`)]})}e();function kt(e,t,n,r){let i=e.map(e=>({value:e.name,label:`${e.name} · ${String(e.count)}`}));return t===void 0?i:[...i,{value:n,label:`${r} · ${String(t)}`}]}function At({rooms:e,unassignedCount:t,value:r,unassignedValue:i,onChange:a}){let{t:o}=X(),c=n(()=>kt(e,t,i,o(`locations.roomPicker.unassigned`)),[e,t,i,o]);return s(`div`,{className:`max-w-sm`,"data-testid":`room-select`,children:s(Ve,{mode:`single`,singleDisplay:`field`,label:o(`locations.roomPicker.label`),placeholder:o(`locations.roomPicker.placeholder`),options:c,value:r,onChange:a,searchable:!0,testId:`room-select-control`,optionTestIdPrefix:`room-option`})})}e();var jt={searchText:e=>[e.name],facetValue:e=>e.type};function Mt({rows:e,fleet:t,locations:a,busy:o,emptyMessage:c,onAssign:l}){let{t:u}=X(),[d,f]=r([]),[p,m]=r(``),h=ye(e,jt),g=h.rows,_=n(()=>g.map(e=>e.id),[g]),v=n(()=>d.filter(e=>_.includes(e)),[d,_]),y=g.length>0&&v.length===g.length,b=n(()=>{let n=new Map;for(let r of e)n.set(r.id,vt(t,r.id));return n},[e,t]),S=v.reduce((e,t)=>e+(b.get(t)??0),0),C=e=>f(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),w=()=>f(y?[]:_),T=()=>{p.length===0||v.length===0||(l(v,p),f([]),m(``))},E=a.map(e=>({value:e,label:e})),D=[{key:`select`,width:`w-8`,headerRender:()=>s(Ae,{checked:y,onChange:w,"aria-label":y?u(`locations.unassignedTable.clearSelection`,`Clear selection`):u(`locations.unassignedTable.selectAllUnassignedDevices`,`Select all unassigned devices`)}),render:e=>s(Ae,{checked:v.includes(e.id),onChange:()=>C(e.id),"aria-label":u(`locations.unassignedTable.select`,`Select {{name}}`,{name:e.name})})},{key:`name`,header:u(`locations.unassignedTable.device`,`Device`),sortValue:e=>e.name.toLowerCase(),render:e=>{let t=pt(e,a);return i(`span`,{className:`flex items-center gap-1.5`,children:[s(Q,{type:e.type}),s(Z,{to:`/devices/${String(e.id)}`,className:`truncate text-xs text-foreground hover:underline`,children:e.name}),t!==null&&s(je,{variant:`warning`,children:u(`locations.unassignedTable.unknownRoom`,{room:t})})]})}},{key:`type`,header:u(`locations.unassignedTable.type`,`Type`),sortValue:e=>e.type,render:e=>s(`span`,{className:`text-xs text-foreground-muted`,children:e.type})},{key:`status`,header:u(`locations.unassignedTable.status`,`Status`),sortValue:e=>+!!e.online,render:e=>i(`span`,{className:`flex items-center gap-1.5`,children:[s($e,{online:e.online,deviceName:e.name}),s(`span`,{className:`text-xs text-foreground-muted`,children:e.online?u(`common.online`):u(`common.offline`)})]})},{key:`followers`,header:u(`locations.unassignedTable.accessoriesInTowCount`,`Accessories in tow`),align:`right`,sortValue:e=>b.get(e.id)??0,render:e=>s(`span`,{className:`tabular-nums text-xs text-foreground-muted`,children:b.get(e.id)??0})},{key:`assign`,header:u(`locations.unassignedTable.assignTo`,`Assign to`),align:`right`,notSortableReason:`This column is a control, not a value.`,render:e=>s(Be,{"aria-label":u(`locations.unassignedTable.locationFor`,`Location for {{name}}`,{name:e.name}),value:``,disabled:o||a.length===0,onChange:t=>{let n=t.target.value;n.length!==0&&l([e.id],n)},className:`max-w-[11rem]`,options:[{value:``,label:`—`},...E]})}];return i(`section`,{className:`space-y-2`,children:[i(`header`,{className:`flex flex-wrap items-baseline gap-2`,children:[s(`h2`,{className:x,children:u(`locations.unassignedTable.notInARoom`,`Not in a room`)}),s(`p`,{className:H,children:u(`locations.unassignedTable.topLevelDevicesOnlyAccessories`,`Top-level devices only — accessories move with their parent.`)})]}),e.length>0&&s(Se,{state:h.state,facets:h.facets,labels:{searchPlaceholder:u(`locations.filter.searchPlaceholder`),searchLabel:u(`locations.unassigned.searchLabel`),facetsLabel:u(`locations.filter.typesLabel`),clearLabel:u(`locations.filter.clear`)},onSearch:h.setSearch,onToggleFacet:h.toggleFacet,onClear:h.clear}),v.length>0&&i(`div`,{role:`group`,"aria-label":u(`locations.unassignedTable.bulkAssignment`,`Bulk assignment`),className:`flex flex-wrap items-center gap-2 rounded border border-primary/40 bg-primary/5 px-2 py-1.5`,children:[i(`span`,{className:`text-xs text-foreground`,children:[u(`locations.unassignedTable.selected`,{count:v.length}),S>0&&` · ${u(`locations.unassignedTable.accessoriesInTowCount`,{count:S})}`]}),s(Be,{"aria-label":u(`locations.unassignedTable.assignSelectedDevicesTo`,`Assign selected devices to`),value:p,onChange:e=>m(e.target.value),className:`w-auto min-w-[10rem]`,options:[{value:``,label:u(`locations.unassignedTable.assignTo2`,`Assign to…`)},...E]}),s(G,{type:`button`,size:`sm`,onClick:T,disabled:o||p.length===0,children:u(`locations.unassignedTable.assign`,`Assign`)}),s(G,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>f([]),children:u(`locations.unassignedTable.clear`,`Clear`)})]}),s(J,{columns:D,rows:g,rowKey:e=>e.id,minWidthPx:720,emptyMessage:h.active?u(`locations.filter.noMatch`):c})]})}function Nt(e){return{id:e.id,parentDeviceId:e.parentDeviceId,location:e.location,type:e.type,stableId:e.stableId??``,...e.primaryChildEntityId===void 0?{}:{primaryChildEntityId:e.primaryChildEntityId},...e.role!==void 0&&e.role!==null?{role:e.role}:{},name:e.name}}function Pt(e,t){let n=t.map(Nt),r=[];for(let i of t)i.isCamera&&i.location===e&&r.push({deviceId:i.id,name:i.name,ids:le({selfId:i.id,selfLocation:i.location,candidates:n})});return{entries:r}}var Ft=`device-manager:linked-devices`;function It(e){return{deviceId:e.deviceId,slotRef:Ft,value:{slot:`linked-devices`,deviceIds:[...e.ids]}}}e();var Lt=`__unassigned__`;function Rt(){let{t:e}=X(),t=o(),a=Oe(),{data:c,isLoading:l}=Ue(),{data:u}=He(),{data:d}=ke(),{data:f}=Me(),{data:p,isLoading:m}=Fe({projection:`slim`}),h=()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]}),t.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),t.invalidateQueries({queryKey:[[`deviceManager`,`listLocationIcons`]]}),t.invalidateQueries({queryKey:[[`deviceManager`,`listLocationDescriptions`]]}),t.invalidateQueries({queryKey:[[`deviceManager`,`listSiteZones`]]})},g=he({onSuccess:h}),_=Ce({onSuccess:h}),v=Ie({onSuccess:h}),y=fe({onSuccess:h}),b=ve({onSuccess:h}),x=_e({onSuccess:h}),S=We({onSuccess:h}),C=pe({onSuccess:h}),w=be({onSuccess:h}),T=xe({onSuccess:h}),E=De(),D=n(()=>(p??[]).map(e=>({id:e.id,name:e.name,location:e.location??null,type:String(e.type),isCamera:e.isCamera,parentDeviceId:e.parentDeviceId,online:e.online,role:e.role??null,stableId:e.stableId,primaryChildEntityId:e.primaryChildEntityId??null})),[p]),O=c??[],A=n(()=>bt(D,O),[D,O]),[j,ee]=Ke(),M=j.get(`tab`),N=M===`zones`||M===`camera-links`?M:`locations`,P=j.get(`room`),F=n(()=>gt(D,O),[D,O]),I=P===Lt,L=I?null:P!==null&&A.some(e=>e.name===P)?P:A[0]?.name??null,R=L===null?null:A.find(e=>e.name===L)??null,z=I?Lt:L??`__unassigned__`,B=L??A[0]?.name??null,te=n(()=>A.map(e=>({name:e.name,count:e.members.length})),[A]),ne=e=>{ee(t=>{let n=new URLSearchParams(t);return n.set(`room`,e),n},{replace:!0})},V=l||m,H=v.isPending||_.isPending||g.isPending||b.isPending,re=async e=>{await g.mutateAsync({name:e})},ie=async(e,t)=>{let n=t.trim();n.length===0||n===e||await y.mutateAsync({from:e,to:n})},ae=async t=>{let n=Pt(t,D);if(n.entries.length===0){await a({title:e(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:e(`locations.noCameraIsAssignedTo`,`No camera is assigned to “{{room}}”.`,{room:t}),confirmLabel:`OK`});return}let r=n.entries.map(t=>e(`locations.rebuildEntry`,{name:t.name,count:t.ids.length})).join(`
|
|
2
|
-
`);if(!await a({title:e(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:e(`locations.replaceTheLinkedDeviceList`,`Replace the linked-device list of every camera in “{{room}}” with what the room contains? {{lines}} Anything linked by hand that is not in this room is lost.`,{room:t,lines:r}),confirmLabel:e(`locations.rebuild`,`Rebuild`),variant:`danger`}))return;let i=[];for(let e of n.entries)try{await E.mutateAsync(It(e))}catch(t){i.push(`• ${e.name}: ${t instanceof Error?t.message:String(t)}`)}h(),i.length>0&&await a({title:e(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:e(`locations.notRebuilt`,`Not rebuilt: {{value1}}`,{value1:i.join(`
|
|
3
|
-
`)}),confirmLabel:`OK`})},oe=async(t,n)=>{let r=n>0?` ${String(n)} device(s) will become unassigned.`:``;await a({title:e(`locations.deleteLocation`,`Delete location`),message:e(`locations.deleteTheLocation`,`Delete the location “{{name}}”?{{extra}}`,{name:t,extra:r}),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&await _.mutateAsync({name:t,cascade:!0})},se=async t=>{await a({title:e(`locations.deleteZone`,`Delete zone`),message:e(`locations.deleteTheZoneTheRooms`,`Delete the zone “{{name}}”? The rooms in it are kept.`,{name:t}),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&await C.mutateAsync({name:t})},ce=async(e,t)=>{await b.mutateAsync({location:e,icon:t})},le=async(e,t)=>{await x.mutateAsync({location:e,description:t})},W=f??[],ue=async(e,t)=>{await T.mutateAsync({location:e,zone:t})},de=(e,t)=>{for(let n of e)v.mutate({deviceId:n,location:t})},[G,K]=r(null),me=n(()=>D.filter(e=>e.parentDeviceId===null).map(e=>({id:e.id,name:e.name,type:e.type,location:e.location})),[D]),ge=s(At,{rooms:te,...N===`locations`?{unassignedCount:F.length}:{},value:N===`locations`?z:B??``,unassignedValue:Lt,onChange:ne}),ye=i(`div`,{className:`flex flex-col gap-3`,"data-testid":`locations-section`,children:[V&&s(`p`,{className:`text-xs text-foreground-subtle`,children:e(`locations.loadingLocationsAndDevices`,`Loading locations and devices…`)}),ge,I||R===null?s(Mt,{rows:F,fleet:D,locations:O,busy:H,emptyMessage:V?e(`common.loading`,`Loading…`):e(`locations.everyTopLevelDeviceHas`,`Every top-level device has a room.`),onAssign:de}):s(Ct,{name:R.name,members:R.members,devices:D,busy:H,icon:ut(u,U(R.name)),onPickIcon:e=>ce(R.name,e),description:at(d,U(R.name)),onSaveDescription:e=>le(R.name,e),zones:W,zoneKey:ct(W,U(R.name)),onChangeZone:e=>ue(R.name,e),onRename:e=>ie(R.name,e),onDelete:()=>oe(R.name,dt(D,R.name).length),onRebuildLinks:()=>ae(R.name),onAddDevices:()=>K(R.name)},R.name),O.length===0&&!V&&s(`p`,{className:`text-xs text-foreground-subtle`,children:e(`locations.noLocationsYetAddIngresso`,`No locations yet. Add Ingresso, Salone, Cucina…`)}),s(et,{open:G!==null,title:e(`locations.room.addDialogTitle`,{room:G??``}),items:me,listState:m?`pending`:`answered`,lockedIds:G===null?[]:(A.find(e=>e.name===G)?.members??[]).map(e=>e.id),lockedNote:e(`locations.room.alreadyHere`),suggestions:{heading:e(`locations.room.suggestedUnassigned`),ids:F.map(e=>e.id)},busy:v.isPending,onConfirm:e=>{G!==null&&de(e,G),K(null)},onClose:()=>K(null)})]}),Se=i(`div`,{className:`flex flex-col gap-3`,"data-testid":`camera-links-tab`,children:[ge,s(tt,{room:B,cameras:B===null?[]:dt(D,B).filter(e=>e.isCamera),fleet:D})]});return s(Je,{icon:k,title:e(`locations.locations`,`Locations`),subtitle:e(`locations.roomsAndAreasOfThe`,`Rooms and areas of the site. Assign any device here — storage disks are under Data → Storage.`),defaultSection:`locations`,sectionsLabel:`Locations sections`,actions:N===`zones`?s(Ot,{busy:S.isPending,onCreate:e=>S.mutateAsync({name:e})}):s(Dt,{busy:g.isPending,onCreate:re}),sections:[{id:`locations`,label:e(`locations.locations`,`Locations`),content:ye},{id:`camera-links`,label:e(`locations.cameraLinks`,`Camera links`),content:Se},{id:`zones`,label:e(`locations.zones`,`Zones`),content:s(Et,{zones:W,busy:H,onRename:(e,t)=>w.mutateAsync({from:e,to:t}),onDelete:se,onPickIcon:(e,t)=>S.mutateAsync({name:e,icon:t})})}]})}export{Rt as LocationsPage};
|