@camstack/addon-admin-ui 1.2.451 → 1.2.453

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/dist/assets/{AddonAssetIcon-tSDKYL0K.js → AddonAssetIcon-D4f5QzwX.js} +1 -1
  2. package/dist/assets/Addons-BmgETSc4.js +4 -0
  3. package/dist/assets/{AdminPage-Bc7EcIQy.js → AdminPage-D_zEoNvj.js} +1 -1
  4. package/dist/assets/{AdminSectionedPage-DorUtSBh.js → AdminSectionedPage-c5oc7MKr.js} +1 -1
  5. package/dist/assets/{AiProfiles-BdYyzFcG.js → AiProfiles-OmUyER08.js} +2 -2
  6. package/dist/assets/{BrokerForm-Deefp6zP.js → BrokerForm-WFCCMZu7.js} +1 -1
  7. package/dist/assets/{Build-D_QB0Yce.js → Build-H3rAvJYX.js} +4 -4
  8. package/dist/assets/{Calendars-BTBqj3kw.js → Calendars-DNZptD-n.js} +1 -1
  9. package/dist/assets/{Cluster-qRWUra5C.js → Cluster-BirHrmjz.js} +1 -1
  10. package/dist/assets/ClusterStepModel-DXEw1-iK.js +1 -0
  11. package/dist/assets/{CompositionEditor-sCKYBpl2.js → CompositionEditor-BruCgxbv.js} +1 -1
  12. package/dist/assets/{CompositionEditorPage-DzUj_31l.js → CompositionEditorPage-CNY8Rqx0.js} +1 -1
  13. package/dist/assets/Data-B9LAPgxz.js +2 -0
  14. package/dist/assets/{DeviceDetail-BLnowNRs.js → DeviceDetail-DB8Wa7Sv.js} +2 -2
  15. package/dist/assets/{DeviceDoActionFields-Bffr6IHD.js → DeviceDoActionFields-Drr-gpl9.js} +1 -1
  16. package/dist/assets/{Devices-IJKvm0BP.js → Devices-JQ8FIcrC.js} +1 -1
  17. package/dist/assets/{EmbedPlayerPage-B1o6udpz.js → EmbedPlayerPage-DMCMitj3.js} +1 -1
  18. package/dist/assets/History-DyW5HpVM.js +1 -0
  19. package/dist/assets/Identity-lfUuRjOX.js +1 -0
  20. package/dist/assets/IntegrationDetail-DnpseReT.js +1 -0
  21. package/dist/assets/{IntegrationHub-Bf4b3i_q.js → IntegrationHub-Db0bsfLJ.js} +1 -1
  22. package/dist/assets/{Integrations-nFhMQF34.js → Integrations-CcXy5tWR.js} +1 -1
  23. package/dist/assets/Integrations-DNPpJ4Ja.js +1 -0
  24. package/dist/assets/{Library-A6WfMhER.js → Library-C2dLqSTC.js} +1 -1
  25. package/dist/assets/Locations-e6uuHHQU.js +3 -0
  26. package/dist/assets/{Logs-C9J8k6c9.js → Logs-DWM80Ifl.js} +1 -1
  27. package/dist/assets/{MaskShapeCanvas-v8FP28QJ.js → MaskShapeCanvas-Chm66Qq5.js} +1 -1
  28. package/dist/assets/{MotionZonesSettings-Bqg-ZAEs.js → MotionZonesSettings-CQ4kMA71.js} +1 -1
  29. package/dist/assets/{MyAccess-uX46IK3F.js → MyAccess-DhDj6Dcu.js} +1 -1
  30. package/dist/assets/{Network-BR-HvAds.js → Network-DRNoFcHE.js} +1 -1
  31. package/dist/assets/{NodeAddonsSettingsPanel-BNTQVCjk.js → NodeAddonsSettingsPanel-CmUo7HL7.js} +1 -1
  32. package/dist/assets/{Notifications-BtCeEFJT.js → Notifications-BnhdNZ6f.js} +1 -1
  33. package/dist/assets/{PrivacyMaskSettings-DqyBAWCW.js → PrivacyMaskSettings-CpCCSkKp.js} +1 -1
  34. package/dist/assets/Recordings-BcWqTc1H.js +1 -0
  35. package/dist/assets/{ScanNetworkModal-DzMITtJ8.js → ScanNetworkModal-DOkg50dW.js} +1 -1
  36. package/dist/assets/{SceneMonitorEditor-365WT-vj.js → SceneMonitorEditor-C1CNWxmG.js} +1 -1
  37. package/dist/assets/SessionsList-rvronrFR.js +2 -0
  38. package/dist/assets/{Showroom-Ch7an15I.js → Showroom-BLEcXdKT.js} +1 -1
  39. package/dist/assets/{System-XW10dOJr.js → System-B6PNyCJb.js} +1 -1
  40. package/dist/assets/{Terminal-CmDRhqrR.js → Terminal-C20iOQsN.js} +1 -1
  41. package/dist/assets/{Viewer-2oJvYupj.js → Viewer-DwNTfUWw.js} +1 -1
  42. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BvyGb9Bo.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DO5DropZ.js} +1 -1
  43. package/dist/assets/{addon-icons-context-Nt5kiIqp.js → addon-icons-context-CO0pJapE.js} +1 -1
  44. package/dist/assets/{archive-BpVlUMGc.js → archive-Bp0veqaX.js} +1 -1
  45. package/dist/assets/{authed-media-CRjjClqw.js → authed-media-BukO6Htt.js} +1 -1
  46. package/dist/assets/{bell-off-DFWiqigj.js → bell-off-DNhCufqt.js} +1 -1
  47. package/dist/assets/{board-model-CbfKyLZU.js → board-model-Ci-_X0u-.js} +1 -1
  48. package/dist/assets/{boxes-DEZFxpEo.js → boxes-BaumwARG.js} +1 -1
  49. package/dist/assets/circle-slash-D7rbiin9.js +1 -0
  50. package/dist/assets/client-BggkinSi.js +358 -0
  51. package/dist/assets/{cloud-upload-DJX2vjB1.js → cloud-upload-C78OV2Vf.js} +1 -1
  52. package/dist/assets/crop-CFruzwpC.js +1 -0
  53. package/dist/assets/{device-integration-icon-eQMV6gf2.js → device-integration-icon-B2dkF6iM.js} +1 -1
  54. package/dist/assets/device-picker-model-B7xNzrPL.js +1 -0
  55. package/dist/assets/{dist-C44xoxcH.js → dist-BnhJ2JWA.js} +1 -1
  56. package/dist/assets/dist-DTzD7Qgb.js +358 -0
  57. package/dist/assets/{eraser-BJtJIM79.js → eraser-BYMxipNr.js} +1 -1
  58. package/dist/assets/{hard-drive-download-BgY0ewC_.js → hard-drive-download-ClkqTbzr.js} +1 -1
  59. package/dist/assets/{hostInit-BxKKf6O5.js → hostInit-BGNr3Jpq.js} +1 -1
  60. package/dist/assets/i18n-BimjnPQq.js +1 -0
  61. package/dist/assets/{icons-B7PsYODJ.js → icons-DHL4FRrs.js} +1 -1
  62. package/dist/assets/{index-B-H1mfMz.js → index-BVY_WMe1.js} +3 -3
  63. package/dist/assets/{key-Rj556V_5.js → key-CKrA-CfR.js} +1 -1
  64. package/dist/assets/{key-round-JtuAp3H5.js → key-round-CDKQmrbu.js} +1 -1
  65. package/dist/assets/{layers-arFC7gbL.js → layers-UfB0_N2n.js} +1 -1
  66. package/dist/assets/{linked-devices-model-Bwz1L9wp.js → linked-devices-model-BM0mB7nT.js} +1 -1
  67. package/dist/assets/{list-ordered-Dam1ZKMc.js → list-ordered-0mq_0UIh.js} +1 -1
  68. package/dist/assets/{location-owned-usage-DwnxDZWp.js → location-owned-usage-D6ooNfJc.js} +1 -1
  69. package/dist/assets/{log-in-lVU3BPjL.js → log-in-BySKT1Dy.js} +1 -1
  70. package/dist/assets/{memory-stick-Cttq5WM5.js → memory-stick-Dp1YfIBO.js} +1 -1
  71. package/dist/assets/{message-square-plus-CaNw_hMf.js → message-square-plus-BWjzgumP.js} +1 -1
  72. package/dist/assets/{mf-entry-bootstrap-0-ab6954b6.js → mf-entry-bootstrap-0-594b555b.js} +2 -2
  73. package/dist/assets/{mic-off-it4ki4Jh.js → mic-off-DiXTm9Y2.js} +1 -1
  74. package/dist/assets/{monitor-off-oHRvN7aD.js → monitor-off-D3OGcghF.js} +1 -1
  75. package/dist/assets/{monitor-smartphone-CjCMg9jw.js → monitor-smartphone-BkZrPcuL.js} +1 -1
  76. package/dist/assets/mount-B7xNzrPL.js +1 -0
  77. package/dist/assets/notification-schedule-field-BG32wqBc.js +1 -0
  78. package/dist/assets/{player-overlays-BQ-CPD3k.js → player-overlays-BYMAZza9.js} +1 -1
  79. package/dist/assets/{recycle-DLgVUrk1.js → recycle-FJ49Ydss.js} +1 -1
  80. package/dist/assets/remoteEntry-CXA3sxXs.js +1 -0
  81. package/dist/assets/{scan-eye-D3WSpR2M.js → scan-eye-Cd5UWfpf.js} +1 -1
  82. package/dist/assets/{scissors-CfXjajAo.js → scissors-BA0EAdIJ.js} +1 -1
  83. package/dist/assets/{search-x-DrZuvHV8.js → search-x-By_wSOtV.js} +1 -1
  84. package/dist/assets/{send-BGZ680If.js → send-C-dY1QlF.js} +1 -1
  85. package/dist/assets/{settings-2-WgIC2cEC.js → settings-2-CbNC1QI2.js} +1 -1
  86. package/dist/assets/{speaker-DIrTXPXW.js → speaker-1RM6dadP.js} +1 -1
  87. package/dist/assets/src-75D_Zlij.js +67 -0
  88. package/dist/assets/{timer-reset-Ba4-n5gG.js → timer-reset--avsGIJd.js} +1 -1
  89. package/dist/assets/{ungroup-DjxNnRiT.js → ungroup-D3cHvFv0.js} +1 -1
  90. package/dist/assets/{unlink-Cy4eOOGb.js → unlink-tiyUOhU3.js} +1 -1
  91. package/dist/assets/{usb-Crnw8Rqe.js → usb-Di-8wm3J.js} +1 -1
  92. package/dist/assets/{use-scenes-feed-CqavtElt.js → use-scenes-feed-CAjM8T0N.js} +1 -1
  93. package/dist/assets/{use-stationary-objects-CuD-UCH8.js → use-stationary-objects-Bjq8kJYj.js} +1 -1
  94. package/dist/assets/useEventInvalidation-B7xNzrPL.js +1 -0
  95. package/dist/assets/{useNodeUrlSelection-ChFCBb4B.js → useNodeUrlSelection-DiojZJ0u.js} +1 -1
  96. package/dist/assets/user-round-luImimaP.js +1 -0
  97. package/dist/assets/{user-x-BDmcZv0z.js → user-x-olI9Ahi1.js} +1 -1
  98. package/dist/assets/{video-JjHo3xW3.js → video-jTbj0gAQ.js} +1 -1
  99. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-3LGiNBfi.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-D8GIXJRi.js} +2 -2
  100. package/dist/index.html +10 -10
  101. package/dist/server/addon.js +115 -68
  102. package/package.json +1 -1
  103. package/dist/assets/Addons-ofsCoJ4Y.js +0 -4
  104. package/dist/assets/ClusterStepModel-CYnyPKcf.js +0 -1
  105. package/dist/assets/Data-BJuJfR0P.js +0 -2
  106. package/dist/assets/History-su2kJ1JJ.js +0 -1
  107. package/dist/assets/Identity-8srCiX2b.js +0 -1
  108. package/dist/assets/IntegrationDetail-CHtQ-0tZ.js +0 -1
  109. package/dist/assets/Integrations-Cnq7Q1qn.js +0 -1
  110. package/dist/assets/Locations-Dl_YxXoD.js +0 -3
  111. package/dist/assets/Recordings-arOpg17X.js +0 -1
  112. package/dist/assets/SessionsList-CAYqZ393.js +0 -2
  113. package/dist/assets/circle-slash-BvDvmSoU.js +0 -1
  114. package/dist/assets/client-C7mYZlqO.js +0 -358
  115. package/dist/assets/crop-BLfw1NQy.js +0 -1
  116. package/dist/assets/device-picker-model-B7n7uzAw.js +0 -1
  117. package/dist/assets/dist-4Z3hLAqT.js +0 -358
  118. package/dist/assets/i18n-CiEPJn04.js +0 -1
  119. package/dist/assets/mount-B7n7uzAw.js +0 -1
  120. package/dist/assets/notification-schedule-field-DkO0-1Tm.js +0 -1
  121. package/dist/assets/remoteEntry-5tiapUFy.js +0 -1
  122. package/dist/assets/src-DP8JO4HZ.js +0 -67
  123. package/dist/assets/useEventInvalidation-B7n7uzAw.js +0 -1
  124. package/dist/assets/user-round-7xIjUD30.js +0 -1
@@ -1 +0,0 @@
1
- import{$ as e,B as t,G as n,J as r,L as i,S as a,a as o,b as s,o as c,q as l,t as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{$t as f,D as p,Fn as m,Gr as h,It as g,Ki as _,Nt as v,Si as y,Tt as b,an as x,bi as S,bn as C,ca as w,cn as T,dn as E,dt as D,hi as O,kn as ee,lr as k,mr as te,or as A,ot as j,pn as M,rr as N,sn as P,yr as F,zr as I}from"./player-overlays-BQ-CPD3k.js";import{Hi as ne,Ui as re,Wi as L,a as R,c as ie,o as ae,s as oe}from"./client-C7mYZlqO.js";import{i as se,n as ce,r as le,t as ue}from"./key-Rj556V_5.js";import{d as z,l as de,s as fe}from"./video-JjHo3xW3.js";import{t as pe}from"./key-round-JtuAp3H5.js";import{t as me}from"./monitor-smartphone-CjCMg9jw.js";import{t as he}from"./unlink-Cy4eOOGb.js";import{$n as ge,An as _e,Ar as B,Au as ve,Ct as ye,Dn as be,Du as xe,Mu as Se,Nn as Ce,Ou as we,Qn as V,Qu as H,Rr as U,Su as Te,Xn as Ee,Ya as De,_n as Oe,_u as ke,bs as Ae,bu as je,cn as Me,ds as Ne,dt as Pe,du as Fe,er as Ie,fr as W,fu as Le,gn as Re,gs as ze,gu as Be,hn as G,hr as K,hu as Ve,ir as He,it as Ue,jn as We,jr as Ge,ju as Ke,kn as qe,ku as Je,ln as Ye,lt as Xe,lu as Ze,mn as Qe,mr as $e,mu as et,nr as tt,oi as nt,pr as rt,ps as it,pu as at,qn as ot,rr as st,rt as ct,si as lt,uu as ut,vt as dt,vu as ft,wt as pt,xu as mt,ys as ht,yu as gt}from"./src-DP8JO4HZ.js";import{t as q}from"./i18n-CiEPJn04.js";import{t as J}from"./useTranslation-D3Is_4B6.js";import{$ as _t,Q as vt,T as yt,V as bt,Z as xt,a as St,d as Ct,et as wt,i as Tt,l as Et,nt as Dt}from"./index-B-H1mfMz.js";import{t as Ot}from"./AdminSectionedPage-DorUtSBh.js";import{t as kt}from"./AdminPage-Bc7EcIQy.js";import{A as Y,C as At,D as jt,E as Mt,O as Nt,S as Pt,T as Ft,a as It,b as Lt,c as Rt,d as zt,f as Bt,g as Vt,h as Ht,i as Ut,j as Wt,k as X,l as Gt,m as Kt,n as qt,o as Jt,p as Yt,s as Xt,t as Zt,u as Qt,v as $t,w as en,x as tn,y as nn}from"./SessionsList-CAYqZ393.js";import{i as rn,n as an,r as on,t as sn}from"./IntegrationHub-Bf4b3i_q.js";import{n as cn,t as ln}from"./addon-display-names-BkwMrExv.js";e();function un(){let{t:e}=J(),t=B(),i=H.useUtils(),a=Wt(),{data:o,isLoading:s}=Be(),c=n(()=>o??[],[o]),l=H.useQueries(e=>c.map(t=>e.userManagement.listExternalIdentities({userId:t.id}))),u=H.auth.listLoginMethods.useQuery(),[f,p]=r(null),m=mt({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=>({...At(e,a),kind:h.get(e.provider)??e.provider})),v=async n=>{let r=g.find(e=>Pt(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:Y(f),onDismissNotice:()=>{p(null)},id:`external-identities`,title:e(`access.externalIdentitiesSection.signInLinks`,`Sign-in links`),icon:z,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(Mt,{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:he,isAvailable:()=>!0,onRun:e=>void v(e),busyId:null,disabled:m.isPending}})})}e();function dn(){let{t:e}=J(),t=B(),i=c(),a=Wt(),o=at(),[s,l]=r(null),u=ft({onSuccess:()=>void i.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),onError:e=>l(`Revoke failed: ${e.message}`)}),f=n(()=>(o.data??[]).map(e=>tn(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:Y(s),onDismissNotice:()=>{l(null)},id:`legacy-api-keys`,title:e(`access.legacyApiKeysSection.legacyApiKeys`,`Legacy API keys`),icon:F,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(Mt,{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:g,isAvailable:()=>!0,onRun:e=>void p(e),busyId:u.isPending?u.variables?.id??null:null,disabled:u.isPending}})})}e();var fn={key:`access.nouns.linkedApp`};function pn(e){if(e.type===`category`){let t=e.target??``;return t===`device`?q.t(`access.linkedAppsSection.allDevices`):q.t(`access.linkedAppsSection.allTarget`,{target:t})}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function mn(){let{t:e}=J(),t=B(),i=c(),a=Ve(),[o,s]=r(null),l=()=>void i.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]}),u=gt({onSuccess:l,onError:e=>s(`Revoke failed: ${e.message}`)}),f=jt(fn,l),p=n(()=>(a.data??[]).map(e=>en(e,e.scopes.map(pn).join(`, `))),[a.data]),m=async n=>{await t({title:e(`access.linkedAppsSection.revokeTheLink`,`Revoke the "{{name}}" link?`,{name:n.name}),message:e(`access.linkedAppsSection.losesAccessForOnIts`,`{{name}} loses access for {{ownerName}} on its next call. Linking it again needs the account-link flow from the start.`,{name:n.name,ownerName:n.ownerName}),confirmLabel:e(`access.linkedAppsSection.revoke`,`Revoke`),variant:`danger`})&&(s(null),u.mutate({id:n.id}))},h=u.isPending?u.variables?.id??null:null;return d(X,{notice:Y(o,f.outcome),onDismissNotice:()=>{s(null),f.dismiss()},id:`linked-apps`,title:e(`access.linkedAppsSection.linkedApps`,`Linked apps`),icon:k,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(Mt,{rows:p,label:e(`access.linkedAppsSection.linkedApps2`,`linked apps`),isLoading:a.isLoading,loadError:a.isError?a.error?.message??`Request failed`:null,emptyText:`No linked apps — an integration appears here once it completes the account-link flow.`,expiresNone:`—`,action:{label:e(`access.linkedAppsSection.revoke`,`Revoke`),icon:g,isAvailable:e=>e.status===`active`||e.status===`revoked`,onRun:e=>void m(e),busyId:h,disabled:u.isPending||f.busy},bulk:{revoke:f,noun:fn,isSelectable:e=>e.status===`active`||e.status===`revoked`,quickSelect:[{label:e(`access.linkedAppsSection.selectRevoked`,`Select revoked`),match:e=>e.status===`revoked`}]}})})}e();var hn={key:`access.nouns.session`};function gn(){let{t:e}=J(),t=B(),i=H.useUtils(),a=Wt(),o=H.auth.listSessions.useQuery(),[s,c]=r(null),l=()=>void i.auth.listSessions.invalidate(),u=H.auth.revokeSessions.useMutation({onSuccess:l,onError:e=>c(`Sign out failed: ${e.message}`)}),f=jt(hn,l),p=n(()=>(o.data??[]).map(e=>Ft(e,a,{client:e=>$t(e).label,method:nn})),[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:Y(s,f.outcome),onDismissNotice:()=>{c(null),f.dismiss()},id:`login-sessions`,title:e(`access.loginSessionsSection.loginSessions`,`Login sessions`),icon:me,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(Mt,{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:fe,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:hn,isSelectable:e=>e.status===`active`}})})}var _n={"by-id":`helpers.authAuditWording.bulkNoun.credential`,"share-link":`helpers.authAuditWording.bulkNoun.shareLink`,"admin-token":`helpers.authAuditWording.bulkNoun.adminToken`,"login-session":`helpers.authAuditWording.bulkNoun.loginSession`};function Z(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function vn(e,t){let n=Z(e,`tokenId`);return Z(e,`name`)??(n===null?void 0:t.get(n))??n??`?`}function Q(e){return e.filter(e=>e!==null)}function yn(e){let t=Z(e,`prefix`);return t===null?null:q.t(`helpers.authAuditWording.prefix`,{prefix:t})}function bn(e,t){let n=e.detail??{};switch(e.action){case`admin-token-created`:{let e=n.expiresAt;return{title:q.t(`helpers.authAuditWording.tokenCreated`,{name:vn(n,t)}),details:Q([yn(n),typeof e==`number`?q.t(`helpers.authAuditWording.expires`,{at:Lt(e)}):null])}}case`admin-token-used`:{let e=Z(n,`path`);return{title:q.t(`helpers.authAuditWording.tokenUsed`,{name:vn(n,t)}),details:Q([yn(n),e===null?null:q.t(`helpers.authAuditWording.call`,{path:e})])}}case`token-minted`:{let e=n.expiresAt;return{title:q.t(`helpers.authAuditWording.tokenMinted`,{name:vn(n,t)}),details:Q([typeof e==`number`?q.t(`helpers.authAuditWording.expires`,{at:Lt(e)}):null])}}case`token-revoked`:return{title:q.t(`helpers.authAuditWording.anyTokenRevoked`,{name:vn(n,t)}),details:[]};case`admin-token-revoked`:return{title:q.t(`helpers.authAuditWording.tokenRevoked`,{name:vn(n,t)}),details:Q([yn(n)])};case`credentials-revoked`:{let e=Z(n,`kind`)??`credential`,t=n.revoked,r=n.skipped,i=_n[e],a=i===void 0?`${e}s`:q.t(i);return{title:q.t(`helpers.authAuditWording.bulkRevoked`,{n:typeof t==`number`?String(t):`?`,noun:a}),details:Q([typeof r==`number`&&r>0?q.t(`helpers.authAuditWording.skipped`,{count:r}):null,Z(n,`ids`)===null?null:q.t(`helpers.authAuditWording.ids`,{ids:Z(n,`ids`)??``})])}}case`second-factor-skipped`:{let e=Z(n,`method`),t=Z(n,`factors`);return{title:q.t(`helpers.authAuditWording.secondFactorSkipped`),details:Q([e===null?null:q.t(`helpers.authAuditWording.signedInWith`,{method:nn(e)}),t===null?null:q.t(`helpers.authAuditWording.skippedFactors`,{factors:t.split(`,`).join(`, `)})])}}default:return{title:e.action,details:Object.entries(n).map(([e,t])=>`${e}: ${String(t)}`)}}}e();var xn=100;function Sn(){let{user:e}=bt();return e?.isAdmin?d(wn,{}):null}function Cn(){let{data:e}=Be(),{data:t}=H.auth.listTokens.useQuery(void 0);return n(()=>{let n=new Map;for(let t of e??[])n.set(t.id,t.username);let r=new Map;for(let e of t??[])r.set(e.id,e.label);return{userNameById:n,tokenNameById:r}},[e,t])}function wn(){let{t:e}=J(),t=H.auth.listAuthAudit.useQuery({limit:xn}),{userNameById:n,tokenNameById:r}=Cn(),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(M,{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:xn})})]}),d(`div`,{className:`p-4`,children:t.isLoading?a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(A,{className:`h-3.5 w-3.5 animate-spin`}),e(`auth.authAuditSection.loadingAuditTrail`,`Loading audit trail…`)]}):t.isError?a(`div`,{className:`text-[11px] text-danger`,children:[e(`auth.authAuditSection.couldNotLoadTheAudit`,`Could not load the audit trail:`),` `,t.error?.message??e(`auth.authAuditSection.requestFailed`,`Request failed`)]}):i.length===0?a(`div`,{className:`rounded border border-dashed border-border px-3 py-4 text-xs text-foreground-subtle text-center space-y-1`,children:[d(`div`,{children:e(`auth.authAuditSection.noAuthenticationEventsRecordedYet`,`No authentication events recorded yet.`)}),d(`div`,{className:`text-[11px] text-foreground-subtle/90`,children:e(`auth.authAuditSection.thisTrailRecordsAdminToken`,`This trail records admin-token create/use/revoke, trusted-network 2FA skips, and credential revokes (including single share-link revoke). Browser password logins are not listed here.`)})]}):d(`ul`,{className:`divide-y divide-border rounded-md border border-border max-h-[420px] overflow-y-auto`,children:i.map(e=>d(Tn,{record:e,userName:e.userId===void 0?null:n.get(e.userId)??e.userId,tokenNameById:r},e.id))})})]})}function Tn({record:e,userName:t,tokenNameById:n}){let r=bn(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:Lt(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`},En={[$.scopedTokens]:$.tokens,[$.adminTokens]:$.tokens,[$.shareLinks]:$.tokens};function Dn(e){return[{id:$.loginSessions,label:q.t(`system.access.loginSessions`,`Login sessions`),icon:me,render:()=>d(gn,{})},{id:$.linkedApps,label:q.t(`system.access.linkedApps`,`Linked apps`),icon:k,render:()=>d(mn,{})},{id:$.tokens,label:q.t(`system.access.tokens`,`Tokens`),icon:pe,render:({createRequested:e,onCreateConsumed:t})=>d(Ht,{headerOwnsCreate:!0,createRequested:e,onCreateConsumed:t})},...e?[{id:$.legacyApiKeys,label:q.t(`system.access.legacyApiKeys`,`Legacy API keys`),icon:F,render:()=>d(dn,{})}]:[],{id:$.externalIdentities,label:q.t(`system.access.signInLinks`,`Sign-in links`),icon:z,render:()=>d(un,{})},{id:$.audit,label:q.t(`system.access.audit`,`Audit`),icon:M,render:()=>d(Sn,{})}]}function On({createRequested:e=!1,onCreateConsumed:t}){let{t:r}=J(),i=at(),o=(i.data??[]).length>0,s=n(()=>Dn(o),[o]),c=rn({ids:n(()=>s.map(e=>e.id),[s]),answered:!i.isLoading}),l=wt(),[u]=Dt(),f=u.get(`integration`),p=f===null?void 0:En[f];if(p!==void 0){let e=new URLSearchParams(u);return e.set(`integration`,p),d(_t,{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(be,{appearance:`pills`,value:h,onValueChange:e=>{l(`?${Ct(u,e,null,null).toString()}`)},children:d(qe,{"aria-label":r(`system.access.credentialKinds`,`Credential kinds`),children:s.map(e=>a(_e,{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 kn(e,t){if(e===$.tokens)return a(K,{size:`sm`,type:`button`,"data-testid":`access-new-token`,onClick:t,children:[d(pe,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),q.t(`system.access.newToken`,`New token`)]})}function An(){let[e,t]=r(!1);return{createRequested:e,requestCreate:()=>t(!0),clearCreate:()=>t(!1)}}e();var jn=[`oidcConnections`,`listConnections`],Mn=[`oidcConnections`,`connectionFormSchema`],Nn={displayName:`OpenID Connect`,icon:`shield-check`,issuerUrl:``,clientId:``,clientSecret:``,redirectUri:``,scopes:`openid profile email`,usernameClaim:`preferred_username`},Pn=/^[a-z0-9][a-z0-9-]{0,63}$/;function Fn(e){return e instanceof Error?e.message:String(e)}function In(e,t){if(t)return typeof e==`string`&&e.length>0?e:void 0;if(re(e))return ne;if(typeof e==`string`&&e.length>0)return e;L(e)}function Ln(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function Rn({addonId:e}){let{t:f}=J(),p=j(),m=c(),h=B(),_=Xe({editKey:`oidcEdit`,newKey:`oidcNew`}),[v,y]=r(!1),[b,x]=r(null),[S,C]=r(``),[w,T]=r({...Nn}),E=l(null),D=o({queryKey:[...jn,e],queryFn:async()=>p.trpcClient.oidcConnections.listConnections.query({})}),O=o({queryKey:Mn,queryFn:async()=>p.trpcClient.oidcConnections.connectionFormSchema.query({})}),k=D.data??[],te=Ln(O.data)?O.data:void 0,A=_.state,M=A.mode===`edit`?k.find(e=>e.id===A.id)??null:null;t(()=>{if(_.state.mode===`edit`&&M!==null){let e=`edit:${M.id}`;if(E.current===e)return;E.current=e,x(null),C(M.id),T(M.formValues===void 0?{...Nn}:{...M.formValues});return}if(_.state.mode===`new`){if(E.current===`new`)return;E.current=`new`,x(null),C(``),T({...Nn})}},[M,_.state]);let N=i(async()=>{await m.invalidateQueries({queryKey:jn})},[m]),F=u({mutationFn:async e=>p.trpcClient.oidcConnections.deleteConnection.mutate({id:e}),onSuccess:async()=>N()}),I=i(async e=>{await h({title:f(`system.oidcSettingsConnections.deleteOidcConnection`,`Delete OIDC connection?`),message:f(`system.oidcSettingsConnections.removeTheLoginButtonAnd`,`Remove “{{displayName}}” ({{id}}). The login button and IdP credentials for this id are dropped.`,{displayName:e.displayName,id:e.id}),confirmLabel:f(`common.delete`,`Delete`),cancelLabel:f(`common.cancel`,`Cancel`),variant:`danger`})&&(await F.mutateAsync(e.id),_.state.mode===`edit`&&_.state.id===e.id&&(_.close(),E.current=null))},[h,F,_,f]),ne=i(async()=>{let e=w.displayName,t=typeof e==`string`&&e.trim()!==``?e.trim():``;if(t===``){x(`Display name is required.`);return}let n=_.state.mode===`new`,r=n?S.trim():M?.id??``;if(n&&!Pn.test(r)){x(`Instance id must be a lowercase slug (e.g. authentik, google).`);return}if(r===``){x(`That connection is no longer available.`);return}let i=In(w.clientSecret,n),a=w.icon,o=w.issuerUrl,s=w.clientId,c=w.redirectUri,l=w.scopes,u=w.usernameClaim,d=u===`email`||u===`sub`?u:`preferred_username`;y(!0),x(null);try{n&&await p.trpcClient.oidcConnections.createConnection.mutate({id:r,displayName:t}),await p.trpcClient.oidcConnections.updateConnection.mutate({id:r,displayName:t,icon:typeof a==`string`?a:`shield-check`,issuerUrl:typeof o==`string`?o:``,clientId:typeof s==`string`?s:``,...i===void 0?{}:{clientSecret:i},redirectUri:typeof c==`string`?c:``,scopes:typeof l==`string`?l:`openid profile email`,usernameClaim:d}),await N(),_.close(),E.current=null}catch(e){x(Fn(e))}finally{y(!1)}},[S,M?.id,_,w,N,p]),re=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(U,{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(K,{type:`button`,size:`sm`,variant:`secondary`,onClick:t=>{t.stopPropagation(),_.openEdit(e.id)},children:f(`common.edit`,`Edit`)}),d(K,{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(),I(e)},children:d(g,{className:`h-3.5 w-3.5 text-danger`})})]})}],[_,I,f]),L=_.state.mode===`new`,R=L||M!==null,ie=L?`new`:M===null?`closed`:`edit:${M.id}:${M.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(K,{type:`button`,size:`sm`,"data-testid":`oidc-connections-add`,onClick:()=>_.openNew(),children:[d(ee,{className:`h-3.5 w-3.5`}),f(`system.oidcSettingsConnections.addConnection`,`Add connection`)]})]}),D.isError?d(`p`,{className:`text-sm text-danger`,children:f(`system.oidcSettingsConnections.couldNotLoadConnections`,`Could not load connections.`)}):null,D.isPending?d($e,{className:`h-32 w-full`}):d(Re,{columns:re,rows:k,rowKey:e=>e.id,pageSize:25,emptyMessage:f(`system.oidcSettingsConnections.noOidcConnectionsYetAdd`,`No OIDC connections yet. Add one to register an IdP.`),onRowClick:e=>_.openEdit(e.id),defaultSort:{columnKey:`name`,dir:`asc`}}),d(Pe,{open:R,onClose:()=>{_.close(),x(null),E.current=null},title:L?f(`system.oidcSettingsConnections.addOidcConnection`,`Add OIDC connection`):f(`system.oidcSettingsConnections.edit`,`Edit {{value1}}`,{value1:M?.displayName??`connection`}),icon:P,width:`xl`,testId:`oidc-connection-editor`,error:b,footer:d(K,{type:`button`,size:`sm`,disabled:v||L&&S.trim()===``,onClick:()=>void ne(),children:v?f(`system.oidcSettingsConnections.saving`,`Saving…`):f(`common.save`,`Save`)}),children:R?a(s,{children:[L?a(`div`,{children:[d(Ce,{htmlFor:`oidc-connection-id`,children:f(`system.oidcSettingsConnections.instanceId`,`Instance id`)}),d(Se,{id:`oidc-connection-id`,value:S,onChange:e=>C(e.target.value),placeholder:`authentik`,autoComplete:`off`}),d(`p`,{className:`mt-1 text-xs text-foreground-muted`,children:f(`system.oidcSettingsConnections.urlSlugAppearsInAddon`,`URL slug — appears in /addon/{{addonId}}/<id>/callback. Stable; renaming is not supported after save.`,{addonId:e})})]}):a(`p`,{className:`text-sm text-foreground-muted`,children:[f(`system.oidcSettingsConnections.instanceId2`,`Instance id:`),` `,d(`span`,{className:`font-mono`,children:M?.id})]}),te===void 0?d(`p`,{className:`text-sm text-foreground-muted`,children:f(`system.oidcSettingsConnections.loadingForm`,`Loading form…`)}):d(ot,{schema:te,values:w,onChange:T,bare:!0},ie)]}):null})]})}e();var zn=3e4,Bn=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],Vn={titleKey:`system.authentication.sectionTitle`,subtitleKey:`system.authentication.sectionSubtitle`,emptyTitleKey:`system.authentication.sectionEmptyTitle`,emptyDescriptionKey:`system.authentication.sectionEmptyDescription`,installLabelKey:`system.authentication.sectionInstall`};function Hn(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:ce,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:de,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:de,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:f,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)?{headline:`TOTP — second factor.`,icon:f,bullets:[`Time-based codes from an authenticator app (RFC 6238).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:P,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Un(){let{t:e}=J(),t=lt({capName:Bn[0].capName},{refetchInterval:zn}),r=lt({capName:Bn[1].capName},{refetchInterval:zn}),i=nt(void 0,{refetchInterval:zn}),a=n(()=>ln(i.data??[]),[i.data]),o=n(()=>{let e=[],n=[t.data??[],r.data??[]];for(let[t,r]of Bn.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:Bn[0].capName,label:e(Vn.installLabelKey)},entries:o.map(t=>({id:t.addonId,name:t.displayName,fallbackIcon:P,...cn(t.isActive),render:()=>d(an,{addonId:t.addonId,displayName:t.displayName,capName:t.capName,isActive:t.isActive,badges:t.stageBadge===null?null:d(U,{variant:`info`,className:on,children:t.stageBadge}),settingsContent:t.addonId.startsWith(`auth-oidc`)?d(Rn,{addonId:t.addonId}):void 0,panels:[{id:`about`,title:e(`system.authentication.about`,`About`),icon:Hn(t.addonId).icon,content:d(Wn,{addonId:t.addonId})}]})}))}];return d(sn,{embedded:!0,icon:P,title:e(Vn.titleKey),subtitle:e(Vn.subtitleKey),groups:s,isLoading:t.isLoading||r.isLoading,emptyTitle:e(Vn.emptyTitleKey),emptyDescription:e(Vn.emptyDescriptionKey)})}function Wn({addonId:e}){let{t}=J(),n=Hn(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(se,{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(te,{className:`h-3.5 w-3.5 mt-0.5 text-info shrink-0`}),d(`span`,{children:d(xt,{i18nKey:`system.authentication.totpNote`,components:{access:d(vt,{to:`/system/my-access`,className:`underline text-primary`}),users:d(vt,{to:`/system/identity?tab=users`,className:`underline text-primary`})}})})]})]})}function Gn({isPending:e,error:t,what:n,onRetry:r,children:i}){let{t:o}=J();return e?a(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,role:`status`,"data-testid":`query-pending`,children:[d(A,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),o(`certificates.queryBody.reading`,{what:n})]}):t===null?i:d(W,{title:o(`certificates.queryBody.couldNotRead`,`Could not read {{what}}`,{what:n}),message:t.message.length>0?t.message:o(`certificates.queryBody.requestFailed`,`Request failed`),onRetry:r})}function Kn(){let{t:e}=J(),t=H.deviceCredentials.getDeviceCaStatus.useQuery({}),n=t.data;return d(X,{id:`device-ca`,title:e(`certificates.deviceCaCard.deviceCertificateAuthority`,`Device certificate authority`),icon:P,description:e(`certificates.deviceCaCard.signsTheCertificateEachPaired`,`Signs the certificate each paired device holds. It is created the first time a device is paired.`),children:d(Gn,{isPending:t.isPending,error:t.error,what:`the device CA`,onRetry:()=>void t.refetch(),children:n!==void 0&&a(`div`,{className:`space-y-1`,"data-testid":`device-ca-status`,children:[a(G,{label:e(`certificates.deviceCaCard.state`,`State`),children:[n.state===`ready`&&d(U,{variant:`success`,children:e(`certificates.deviceCaCard.ready`,`Ready`)}),n.state===`absent`&&d(U,{variant:`default`,children:e(`certificates.deviceCaCard.notCreatedYet`,`Not created yet`)}),n.state===`unavailable`&&d(U,{variant:`danger`,children:e(`certificates.deviceCaCard.unavailable`,`Unavailable`)})]}),n.state===`ready`&&a(s,{children:[d(G,{label:e(`certificates.deviceCaCard.subject`,`Subject`),valueClassName:`font-mono`,children:n.subject}),d(G,{label:e(`certificates.deviceCaCard.fingerprintSha256`,`Fingerprint (SHA-256)`),valueClassName:`font-mono`,children:n.fingerprintSha256}),d(G,{label:e(`certificates.deviceCaCard.validUntil`,`Valid until`),children:n.validTo})]}),n.state===`unavailable`&&d(G,{label:e(`certificates.deviceCaCard.reason`,`Reason`),children:d(`span`,{className:`text-danger`,children:n.reason})})]})})})}e();function qn(){let{t:e}=J(),t=H.useUtils(),n=H.deviceCredentials.getDeviceCertificateSettings.useQuery({}),[i,o]=r(null),s=H.deviceCredentials.setDeviceCertificateSettings.useMutation({onSuccess:()=>{o(null),t.deviceCredentials.getDeviceCertificateSettings.invalidate()},onError:e=>o(`Could not save: ${e.message}`)});return d(Gn,{isPending:n.isPending,error:n.error,what:`the enrollment setting`,onRetry:()=>void n.refetch(),children:n.data!==void 0&&a(G,{label:e(`certificates.deviceSettingsRow.usersCanEnrollTheirOwn`,`Users can enroll their own devices`),actions:d(We,{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 Jn(e){let[n,i]=r(()=>Date.now());return t(()=>{let t=setInterval(()=>i(Date.now()),e);return()=>clearInterval(t)},[e]),n}e();var Yn=80,Xn=208;function Zn({open:e,users:t,onClose:n,onPaired:i}){let{t:o}=J(),s=H.deviceCredentials.startEnrollment.useMutation({onSuccess:i}),[c,l]=r(``),[u,p]=r(``),m=c===``?t[0]?.id??``:c,h=s.data,g=()=>{s.reset(),p(``),n()};return d(Pe,{open:e,onClose:g,title:o(`certificates.pairDeviceDialog.pairADevice`,`Pair a device`),icon:f,width:`md`,testId:`pair-device-dialog`,error:s.isError?s.error.message:null,footer:h===void 0?a(K,{type:`button`,onClick:()=>{let e=u.trim();m===``||e===``||s.mutate({userId:m,deviceName:e})},disabled:s.isPending||m===``||u.trim()===``,children:[s.isPending&&d(A,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),o(`certificates.pairDeviceDialog.createPairingCode`,`Create pairing code`)]}):d(K,{type:`button`,variant:`outline`,onClick:g,children:o(`certificates.pairDeviceDialog.done`,`Done`)}),children:h===void 0?a(`div`,{className:`space-y-3`,children:[d(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`certificates.pairDeviceDialog.createsAOneTimeCode`,`Creates a one-time code for a phone you hold. Scan it with the CamStack app on that phone; the phone then stays signed in as the chosen user until you revoke it.`)}),d(dt,{label:o(`certificates.pairDeviceDialog.user`,`User`),required:!0,children:d(xe,{value:m,onChange:e=>l(e.target.value),options:t.map(e=>({value:e.id,label:e.username}))})}),d(dt,{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(Se,{value:u,maxLength:Yn,onChange:e=>p(e.target.value),placeholder:o(`certificates.pairDeviceDialog.annaSIphone`,`Anna's iPhone`),autoFocus:!0})})]}):d(Qn,{enrollUrl:h.enrollUrl,expiresAt:h.expiresAt,hubKnown:h.hubOrigin!==null,onRestart:()=>s.reset()})})}function Qn({enrollUrl:e,expiresAt:t,hubKnown:n,onRestart:r}){let{t:i}=J(),o=Jt(t,Jn(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(Ee,{value:e,size:Xn,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(Me,{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(v,{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(K,{type:`button`,variant:`outline`,size:`sm`,onClick:r,children:i(`certificates.pairDeviceDialog.newCode`,`New code`)})]})]})})}e();var $n={key:`access.nouns.device`};function er({pairOpen:e,onPairClose:t}){let{t:i}=J(),o=B(),s=Ge(),c=H.useUtils(),l=H.deviceCredentials.listDeviceCredentials.useQuery({includeRevoked:!0}),u=Be(),[p,h]=r(null),[v,y]=r(null),b=()=>void c.deviceCredentials.listDeviceCredentials.invalidate(),x=e=>t=>{y(null),h(`${e} failed: ${t.message}`)},S=()=>{y(null),b()},C=H.deviceCredentials.revokeDeviceCredential.useMutation({onSuccess:S,onError:x(`Revoke`)}),w=H.deviceCredentials.deleteDeviceCredential.useMutation({onSuccess:e=>{e.result!==`deleted`&&h(e.result===`live`?`Only a revoked device can be deleted: revoke it first.`:`That device no longer exists.`),S()},onError:x(`Delete`)}),T=H.deviceCredentials.renameDeviceCredential.useMutation({onSuccess:S,onError:x(`Rename`)}),E=Nt($n,e=>C.mutateAsync({id:e}),b),D=E.busy||v!==null,O=n(()=>(l.data??[]).map(qt),[l.data]),ee=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`})&&(h(null),y(e.id),C.mutate({id:e.id}))},k=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`})&&(h(null),y(e.id),w.mutate({id:e.id}))},te=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||(h(null),y(e.id),T.mutate({id:e.id,deviceName:t}))},A={label:i(`certificates.devicesCard.revoke2`,`Revoke`),icon:_,isAvailable:It,onRun:e=>void ee(e),busyId:C.isPending?v:null,disabled:D},j=[{label:i(`certificates.devicesCard.rename`,`Rename`),icon:m,tone:`neutral`,isAvailable:()=>!0,onRun:e=>void te(e),busyId:T.isPending?v:null,disabled:D},{label:i(`common.delete`,`Delete`),icon:g,isAvailable:Ut,onRun:e=>void k(e),busyId:w.isPending?v:null,disabled:D}];return a(X,{id:`devices`,title:i(`certificates.devicesCard.devices`,`Devices`),icon:f,description:i(`certificates.devicesCard.phonesThatStaySignedIn`,`Phones that stay signed in with a certificate instead of a login. Revoking one signs it out at once; it has to be paired again.`),notice:Y(p,E.outcome),onDismissNotice:()=>{h(null),E.dismiss()},children:[d(qn,{}),d(Mt,{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:A,extraActions:j,bulk:{revoke:E,noun:$n,isSelectable:It}}),d(Zn,{open:e,users:u.data??[],onClose:t,onPaired:b})]})}var tr=/-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----/,nr=/-----BEGIN ((?:RSA |EC |ENCRYPTED )?PRIVATE KEY)-----[\s\S]+?-----END \1-----/,rr={certificate:`.pem,.crt,.cer`,privateKey:`.pem,.key`,ca:`.pem,.crt,.cer`};function ir(e,t){if(t.trim()===``)return null;if(e===`privateKey`){let e=nr.exec(t);return e===null?tr.test(t)?q.t(`helpers.pemFile.isCert`):q.t(`helpers.pemFile.notKey`):e[1]===`ENCRYPTED PRIVATE KEY`?q.t(`helpers.pemFile.encrypted`):null}return tr.test(t)?e===`certificate`&&nr.test(t)?q.t(`helpers.pemFile.certHasKey`):null:nr.test(t)?q.t(`helpers.pemFile.isKey`):q.t(`helpers.pemFile.notCert`)}function ar(e){return e.text()}e();function or({kind:e,label:t,value:n,onChange:i,rows:o=6}){let{t:s}=J(),c=l(null),[u,f]=r(null),[p,m]=r(null),h=p??ir(e,n),g=`pem-${e}`,_=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t!==void 0){f(t.name);try{let e=await ar(t);m(null),i(e)}catch(e){m(`Could not read ${t.name}: ${e instanceof Error?e.message:String(e)}`)}}};return a(`div`,{className:`space-y-1`,children:[a(`div`,{className:`flex items-center justify-between gap-2`,children:[d(`label`,{htmlFor:g,className:`text-[11px] text-foreground-subtle`,children:t}),a(`div`,{className:`flex min-w-0 items-center gap-2`,children:[u!==null&&d(`span`,{className:`truncate font-mono text-[10px] text-foreground-subtle`,"data-testid":`${g}-file-name`,children:u}),d(`input`,{ref:c,type:`file`,accept:rr[e],onChange:e=>void _(e),className:`hidden`,"data-testid":`${g}-file`}),a(K,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>c.current?.click(),children:[d(le,{className:`mr-1 h-3 w-3`}),s(`system.pemField.chooseFile`,`Choose file`)]})]})]}),d(`textarea`,{id:g,value:n,onChange:e=>{f(null),m(null),i(e.target.value)},rows:o,"aria-invalid":h!==null,className:`w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`}),h!==null&&d(`p`,{className:`text-[11px] text-danger`,role:`alert`,children:h})]})}e();var sr=30;function cr(e){let t=Date.parse(e);return!Number.isNaN(t)&&Date.now()-t<sr*864e5}function lr(e){if(e===null||e===``)return`—`;let t=e.replace(/:/g,``);return t.length<=16?e:`${t.slice(0,8)}…${t.slice(-8)}`}function ur(){let{t:e}=J(),t=c(),n=Ne(void 0,{refetchInterval:15e3}),i=it({onSuccess:()=>void t.invalidateQueries({queryKey:[[`localNetwork`]]})}),o=ze({onSuccess:()=>void t.invalidateQueries({queryKey:[[`localNetwork`]]})}),s=Ae({onSuccess:()=>void t.invalidateQueries({queryKey:[[`localNetwork`]]})}),l=ht({onSuccess:()=>{m(!1),g(``),v(``),b(``),t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),u=n.data,[f,m]=r(!1),[h,g]=r(``),[_,v]=r(``),[y,b]=r(``),S=()=>{if(!u?.caCertPem)return;let e=new Blob([u.caCertPem],{type:`application/x-pem-file`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`camstack-ca.crt`,n.click(),URL.revokeObjectURL(t)},C=u?.mode===`uploaded`?`Uploaded`:u?.mode===`generated`?`Generated local CA`:`TLS disabled`;return d(Qe,{headingId:`local-access-certificate`,title:e(`system.localAccess.certificate`,`Certificate`),icon:x,children:a(`div`,{className:`${p} space-y-3`,children:[n.isError&&d(`p`,{className:`text-xs text-danger`,children:e(`system.localAccess.couldNotReadTlsStatus`,`Could not read TLS status.`)}),u?.reissueError&&d(W,{variant:`warning`,title:e(`system.localAccess.certificateReissue`,`Certificate reissue`),message:u.reissueError}),u?.restartRequired&&d(W,{variant:`warning`,title:e(`system.localAccess.restartRequired`,`Restart required`),message:e(`system.localAccess.theHttpsListenerStillServes`,`The HTTPS listener still serves the previous certificate. Restart the hub to apply it.`)}),u?.caMissing===!0&&d(W,{variant:`warning`,title:e(`system.localAccess.caMissingTitle`,`CA missing - devices cannot trust this hub`),message:e(`system.localAccess.caMissingBody`,"The uploaded certificate was not issued by a public CA and no CA was stored with it, so Download CA has nothing to hand out. Upload the certificate again together with its CA (for mkcert, the rootCA.pem in the folder `mkcert -CAROOT` prints).")}),u?.caReplacedAt!=null&&cr(u.caReplacedAt)&&d(W,{variant:`warning`,title:e(`system.localAccess.caReplacedTitle`,`The local CA was replaced - re-install it on your devices`),message:e(`system.localAccess.caReplacedBody`,`The previous local CA had no name constraints: if its key ever leaked it could vouch for any website. The hub now uses a CA limited to private addresses and local names. Download it again and trust it on every phone and computer that used the old one (replaced {{when}}).`,{when:new Date(u.caReplacedAt).toLocaleString()})}),a(`dl`,{className:`grid grid-cols-1 gap-2 text-xs sm:grid-cols-2`,children:[a(`div`,{children:[d(`dt`,{className:`text-foreground-subtle`,children:e(`system.localAccess.mode`,`Mode`)}),d(`dd`,{className:`font-medium`,children:C})]}),a(`div`,{children:[d(`dt`,{className:`text-foreground-subtle`,children:e(`system.localAccess.validTo`,`Valid to`)}),d(`dd`,{className:`font-mono`,children:u?.validTo?new Date(u.validTo).toLocaleString():`—`})]}),a(`div`,{children:[d(`dt`,{className:`text-foreground-subtle`,children:e(`system.localAccess.leafSha256`,`Leaf SHA-256`)}),d(`dd`,{className:`font-mono`,title:u?.leafFingerprintSha256??void 0,children:lr(u?.leafFingerprintSha256??null)})]}),u?.storedUpload!=null&&a(`div`,{children:[d(`dt`,{className:`text-foreground-subtle`,children:e(`system.localAccess.storedUpload`,`Stored upload`)}),d(`dd`,{className:`font-medium`,children:e(`system.localAccess.storedUploadValue`,`valid to {{validTo}}, {{ca}}`,{validTo:new Date(u.storedUpload.validTo).toLocaleDateString(),ca:u.storedUpload.hasCa?e(`system.localAccess.storedUploadWithCa`,`with its CA`):e(`system.localAccess.storedUploadNoCa`,`no CA`)})})]}),a(`div`,{children:[d(`dt`,{className:`text-foreground-subtle`,children:e(`system.localAccess.caSha256`,`CA SHA-256`)}),d(`dd`,{className:`font-mono`,title:u?.caFingerprintSha256??void 0,children:u?.mode===`uploaded`&&u.caFingerprintSha256===null?d(`span`,{className:`font-sans text-foreground-subtle`,children:e(`system.localAccess.issuerNotIncludedInThe`,`Issuer not included in the upload (not the local CA)`)}):lr(u?.caFingerprintSha256??null)})]})]}),u&&u.sans.length>0&&d(`div`,{className:`flex flex-wrap gap-1`,children:u.sans.map(e=>d(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 font-mono text-[10px] text-foreground-subtle`,children:e},e))}),a(`div`,{className:`flex flex-wrap gap-2`,children:[d(Ye,{label:e(`system.localAccess.regenerate`,`Regenerate`),title:e(`system.localAccess.issueANewLeaf`,`Issue a new leaf?`),description:e(`system.localAccess.issuesANewLeafUnder`,`Issues a new leaf under the current local CA. Clients that trust the CA keep working. The HTTPS listener reloads.`),confirmLabel:e(`system.localAccess.regenerate`,`Regenerate`),disabled:u?.mode===`uploaded`||i.isPending,action:()=>i.mutateAsync({})}),d(K,{size:`sm`,variant:`outline`,onClick:()=>m(e=>!e),children:e(`system.localAccess.upload`,`Upload`)}),u?.caCertPem&&d(K,{size:`sm`,variant:`outline`,onClick:S,children:e(`system.localAccess.downloadCa`,`Download CA`)}),u?.mode===`uploaded`&&d(Ye,{label:e(`system.localAccess.revertToGenerated`,`Revert to generated`),title:e(`system.localAccess.revertTitle`,`Switch back to the generated certificate?`),description:e(`system.localAccess.keepsTheUploadedPair`,`Returns to the generated local CA. The uploaded certificate and its CA stay stored here; you can select them again.`),confirmLabel:e(`system.localAccess.revert`,`Revert`),disabled:o.isPending,action:()=>o.mutateAsync({})}),u?.mode===`generated`&&u.storedUpload!=null&&d(Ye,{label:e(`system.localAccess.useUploaded`,`Use uploaded certificate`),title:e(`system.localAccess.useUploadedTitle`,`Serve the stored upload again?`),description:e(`system.localAccess.useUploadedDescription`,`The stored uploaded certificate replaces the generated one on the HTTPS listener. The generated certificate stays stored.`),confirmLabel:e(`system.localAccess.useUploaded`,`Use uploaded certificate`),disabled:s.isPending,action:()=>s.mutateAsync(void 0)})]}),f&&a(`div`,{className:`space-y-2 border-t border-border pt-3`,children:[d(or,{kind:`certificate`,label:e(`system.localAccess.certificateOrFullChainPem`,`Certificate or full chain (PEM)`),value:h,onChange:g}),d(or,{kind:`privateKey`,label:e(`system.localAccess.privateKeyPem`,`Private key (PEM)`),value:_,onChange:v}),d(or,{kind:`ca`,label:e(`system.localAccess.caPemRequired`,`CA (PEM) - required unless the certificate comes from a public CA`),value:y,onChange:b,rows:4}),d(K,{size:`sm`,disabled:!h.trim()||!_.trim()||ir(`certificate`,h)!==null||ir(`privateKey`,_)!==null||ir(`ca`,y)!==null||l.isPending,onClick:()=>l.mutate({certPem:h,keyPem:_,...y.trim()?{caPem:y}:{}}),children:e(`system.localAccess.saveCertificate`,`Save certificate`)}),l.isError&&d(`p`,{className:`text-xs text-danger`,children:l.error instanceof Error?l.error.message:e(`system.localAccess.uploadFailed`,`Upload failed`)})]})]})})}var dr={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`};function fr(e){let t=e.find(e=>e.isHub);return t?.https.kind===`served`?t.https.status.caFingerprintSha256:null}function pr({https:e,mesh:t,now:n}){let{t:r}=J(),i=Ne().data?.caCertPem??``,o=()=>{if(i===``)return;let e=URL.createObjectURL(new Blob([i],{type:`application/x-pem-file`})),t=document.createElement(`a`);t.href=e,t.download=`camstack-ca.crt`,t.click(),URL.revokeObjectURL(e)},s=t?.ca,c=s?.state===`ready`?Date.parse(s.validTo):null,l=t?.listener;return a(`div`,{className:`space-y-1`,"data-testid":`ca-strip`,children:[d(G,{label:r(`certificates.caStrip.localHttpsCaSha256`,`Local HTTPS CA (SHA-256)`),valueClassName:`font-mono`,children:a(`span`,{className:`flex flex-wrap items-center gap-2`,children:[fr(e)??`—`,i!==``&&a(K,{type:`button`,variant:`ghost`,size:`sm`,onClick:o,children:[d(h,{className:`h-3 w-3`,"aria-hidden":!0}),r(`certificates.caStrip.downloadCa`,`Download CA`)]})]})}),d(G,{label:r(`certificates.caStrip.clusterCaSha256`,`Cluster CA (SHA-256)`),valueClassName:`font-mono`,children:s===void 0?`—`:s.state===`ready`?s.fingerprintSha256:d(`span`,{className:`text-danger`,children:r(`certificates.caStrip.unavailable`,{reason:s.reason})})}),s?.state===`ready`&&a(G,{label:r(`certificates.caStrip.clusterCaValidUntil`,`Cluster CA valid until`),children:[s.validTo,c!==null&&!Number.isNaN(c)&&a(`span`,{className:`ml-2 text-[10px] ${dr[Qt(c,n)]}`,children:[`(`,Rt(c,n),`)`]})]}),l!==void 0&&a(G,{label:r(`certificates.caStrip.nodeListener`,`Node listener`),children:[l.state===`open`&&d(U,{variant:`success`,children:r(`certificates.caStrip.open`,`Open`)}),l.state===`not-started`&&d(U,{variant:`default`,children:r(`certificates.caStrip.notStarted`,`Not started`)}),l.state===`closed`&&a(`span`,{className:`text-danger`,children:[r(`certificates.caStrip.closedSince`,{when:zt(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(v,{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 mr(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 hr(e){return e.isHub?q.t(`helpers.nodesModel.hubReissued`):e.mesh===null?q.t(`helpers.nodesModel.noCertRecorded`):e.online?null:q.t(`helpers.certificateModel.nodeOffline`)}function gr(e){return e.isHub||e.mesh===null?hr(e):null}var _r={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`},vr={enroll:`Issued at enrollment`,renewal:`Issued by a renewal`,boot:`Issued at boot`,pairing:`Issued at pairing`,observed:`Observed on its connection`},yr={uploaded:`Uploaded`,generated:`Generated`,disabled:`Disabled`};function br(e){let t=e.https?.https;return t?.kind===`served`?Xt(t.status.validTo):null}function xr({ms:e,now:t}){return e===null?d(`span`,{className:`text-foreground-subtle`,children:`—`}):a(`div`,{children:[d(`div`,{children:zt(e)}),d(`div`,{className:`text-[10px] ${_r[Qt(e,t)]}`,children:Rt(e,t)})]})}function Sr({row:e}){let{t}=J(),n=e.https?.https;return n===void 0?d(`span`,{className:`text-foreground-subtle`,children:`—`}):n.kind===`served`?a(`div`,{title:n.status.leafFingerprintSha256??``,children:[d(U,{variant:`success`,className:`text-[10px]`,children:t(`certificates.nodesColumns.served`,`Served`)}),d(`span`,{className:`ml-1.5 text-[10px] text-foreground-subtle`,children:yr[n.status.mode]}),d(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:Yt(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(U,{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 Cr({row:e}){let{t}=J(),n=e.mesh?.current??null;if(n===null)return d(`span`,{className:`text-foreground-subtle`,children:t(`certificates.nodesColumns.noneRecorded`,`None recorded`)});let r=e.mesh?.history.length??0;return a(`div`,{children:[d(`div`,{className:`font-mono text-[11px]`,title:n.serial,children:Kt(n.serial)}),d(`div`,{className:`font-mono text-[10px] text-foreground-subtle`,title:n.fingerprintSha256,children:Yt(n.fingerprintSha256)}),a(`div`,{className:`text-[10px] text-foreground-subtle`,children:[vr[n.issuedVia],r>0?` · ${t(`certificates.nodesColumns.earlier`,{count:r})}`:``]})]})}function wr({row:e}){let{t}=J(),n=e.mesh?.presentingCurrent??null;return n===null?d(`span`,{className:`text-foreground-subtle`,children:e.online?`—`:t(`certificates.nodesColumns.offline`,`Offline`)}):n?d(U,{variant:`success`,className:`text-[10px]`,children:t(`common.yes`,`Yes`)}):d(U,{variant:`warning`,className:`text-[10px]`,children:t(`certificates.nodesColumns.noPresentsAnother`,`No - presents another`)})}function Tr(e){let t=e.icon;return a(K,{type:`button`,variant:`ghost`,size:`sm`,className:e.danger?`text-danger hover:bg-danger/10`:void 0,disabled:e.reason!==null||e.busy,title:e.reason??void 0,"aria-label":e.ariaLabel,onClick:e.onClick,children:[e.spinning?d(A,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):d(t,{className:`h-3 w-3`,"aria-hidden":!0}),e.label]})}function Er({reasons:e}){let{t}=J();return a(Je,{className:`inline-block`,children:[d(Ke,{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(ve,{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 Dr({row:e,o:t}){let{t:n}=J(),r=e.https===null?`No HTTPS inventory for this node.`:Bt(e.https).reason,i=hr(e),o=gr(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(Tr,{label:n(`certificates.nodesColumns.renewHttps`,`Renew HTTPS`),ariaLabel:n(`certificates.nodesColumns.renewTheCertificateOn`,`Renew the certificate on {{nodeId}}`,{nodeId:e.nodeId}),icon:C,reason:r,busy:t.busy,spinning:s(`renew-https`),danger:!1,onClick:()=>t.onRenewHttps(e)}),c(i)&&d(Tr,{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:C,reason:i,busy:t.busy,spinning:s(`renew-identity`),danger:!1,onClick:()=>t.onRenewIdentity(e)}),c(o)&&d(Tr,{label:n(`certificates.nodesColumns.revokeIdentity`,`Revoke identity`),ariaLabel:n(`certificates.nodesColumns.revokeTheClusterCertificateOf`,`Revoke the cluster certificate of {{nodeId}}`,{nodeId:e.nodeId}),icon:_,reason:o,busy:t.busy,spinning:s(`revoke-identity`),danger:!0,onClick:()=>t.onRevokeIdentity(e)})]}),e.isHub&&l.length>0&&d(Er,{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 Or(e){return[{key:`node`,header:q.t(`certificates.nodesColumns.node`,`Node`),sortValue:e=>e.isHub?``:e.nodeId.toLowerCase(),render:e=>a(`div`,{className:`flex items-center gap-1.5`,children:[d(`span`,{className:`font-medium text-foreground`,children:e.nodeId}),e.nodeId===`hub`&&d(U,{variant:`info`,className:`text-[10px]`,children:q.t(`common.hubWord`)}),!e.online&&d(U,{variant:`default`,className:`text-[10px]`,children:q.t(`common.offline`)})]})},{key:`https-state`,header:`HTTPS`,notSortableReason:`A state with a reason has no single order.`,render:e=>d(Sr,{row:e})},{key:`https-expires`,header:q.t(`certificates.nodesColumns.httpsExpires`,`HTTPS expires`),sortValue:e=>br(e),render:t=>d(xr,{ms:br(t),now:e.now})},{key:`identity`,header:q.t(`certificates.nodesColumns.identity`,`Identity`),sortValue:e=>e.mesh?.current?.serial??null,render:e=>d(Cr,{row:e})},{key:`identity-expires`,header:q.t(`certificates.nodesColumns.identityExpires`,`Identity expires`),sortValue:e=>e.mesh?.current?.notAfter??null,render:t=>d(xr,{ms:t.mesh?.current?.notAfter??null,now:e.now})},{key:`presenting`,header:q.t(`certificates.nodesColumns.inUse`,`In use`),notSortableReason:`Offline nodes have no answer to order by.`,render:e=>d(wr,{row:e})},{key:`actions`,header:q.t(`certificates.nodesColumns.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order.`,render:t=>d(Dr,{row:t,o:e})}]}e();function kr(){let{t:e}=J(),t=B(),i=H.useUtils(),o=Jn(6e4),s=H.certificates.listHttpsCertificates.useQuery(),c=H.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=H.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=H.certificates.renewMeshOnNode.useMutation({onSuccess:e=>{p(Gt(e)),g()},onError:_(`renewal could not start`)}),b=H.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}))},D=Or({now:o,busy:x,running:m,onRenewHttps:e=>void C(e),onRenewIdentity:w,onRevokeIdentity:e=>void T(e)}),O=n(()=>mr(s.data??[],c.data),[s.data,c.data]),ee=c.data?.registryAvailable??!0;return d(X,{id:`nodes`,title:e(`certificates.nodesCard.nodes`,`Nodes`),icon:E,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:Y(l,f),onDismissNotice:()=>{u(null),p(null)},children:d(Gn,{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(pr,{https:s.data??[],mesh:c.data,now:o}),d(Re,{columns:D,rows:O,rowKey:e=>e.nodeId,minWidthPx:960,maxBodyHeight:Oe,defaultSort:{columnKey:`node`,dir:`asc`},emptyMessage:ee?e(`certificates.nodesCard.noNodesReported`,`No nodes reported.`):e(`certificates.nodesCard.theCertificateRegistryIsNot`,`The certificate registry is not available yet, so nodes cannot be listed.`)})]})})})}function Ar({pairOpen:e,onPairClose:t}){return a(`div`,{className:`space-y-4`,"data-testid":`certificates-page`,children:[d(er,{pairOpen:e,onPairClose:t}),d(Kn,{}),d(ur,{}),d(kr,{})]})}function jr({userId:e,username:t,onClose:n}){let{t:r}=J(),i=B(),o=H.useUtils(),s=et({userId:e}),c=H.auth.listLoginMethods.useQuery(),l=mt({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(V,{open:!0,onOpenChange:e=>!e&&n(),children:a(Ie,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`external-identities-modal`,children:[d(st,{children:a(He,{className:`flex items-center gap-2`,children:[d(k,{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(ge,{className:`space-y-3`,children:s.isLoading?a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(A,{className:`h-3.5 w-3.5 animate-spin`}),r(`common.loading`,`Loading…`)]}):f.length===0?d(`p`,{className:`text-xs text-foreground-subtle`,children:r(`users.externalIdentitiesModal.noLinkedAccountsOnlyThe`,`No linked accounts. Only the user can link one, from their own profile page.`)}):d(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:f.map(e=>{let t=u.get(e.provider),n=t??e.provider;return a(`li`,{className:`flex items-center gap-3 px-3 py-2 text-xs`,children:[a(`div`,{className:`flex-1 min-w-0`,children:[a(`div`,{className:`font-medium text-foreground truncate`,children:[n,t===void 0&&d(`span`,{className:`ml-2 rounded bg-foreground-subtle/15 px-1.5 py-0.5 text-[10px] font-normal text-foreground-subtle`,children:r(`users.externalIdentitiesModal.providerUnavailable`,`provider unavailable`)})]}),a(`div`,{className:`text-[11px] text-foreground-subtle truncate`,children:[e.label??e.subject,` ·`,` `,new Date(e.linkedAt).toLocaleDateString()]})]}),a(`button`,{onClick:()=>void p(e,n),disabled:l.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[d(he,{className:`h-3 w-3`}),r(`common.remove`,`Remove`)]})]},`${e.provider}|${e.subject}`)})})}),d(tt,{children:d(K,{onClick:n,variant:`secondary`,children:r(`common.close`,`Close`)})})]})})}function Mr({userId:e,username:t,onClose:n}){let{t:r}=J(),i=c(),o=B(),l=Le({userId:e}),u=l.data,p=()=>i.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),m=Fe({onSuccess:()=>{p(),n()}}),h=l.isLoading?`loading`:u?.enabled?`enrolled`:`not_enrolled`;return d(V,{open:!0,onOpenChange:e=>!e&&n(),children:a(Ie,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[d(st,{children:a(He,{className:`flex items-center gap-2`,children:[d(f,{className:`h-4 w-4 text-primary`}),a(`span`,{children:[r(`users.totpModal.twoFactorAuthentication`,`Two-factor authentication`),a(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[r(`users.totpModal.user`,`User:`),` `,d(`span`,{className:`font-mono`,children:t})]})]})]})}),a(ge,{className:`space-y-4`,children:[h===`loading`&&a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(A,{className:`h-3.5 w-3.5 animate-spin`}),r(`users.totpModal.checkingStatus`,`Checking status…`)]}),h===`not_enrolled`&&a(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[d(te,{className:`h-4 w-4 mt-0.5 shrink-0`}),a(`div`,{children:[d(`div`,{className:`font-medium text-foreground`,children:r(`users.totpModal.2faNotEnrolled`,`2FA not enrolled`)}),d(`p`,{className:`mt-0.5`,children:r(`users.totpModal.onlyTheUserThemselvesCan`,`Only the user themselves can enable 2FA, from their own profile page.`)})]})]}),h===`enrolled`&&u&&a(s,{children:[a(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[d(O,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),a(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[d(`div`,{className:`font-medium`,children:r(`users.totpModal.2faIsActive`,`2FA is active`)}),d(`div`,{className:`text-foreground-subtle`,children:r(`common.enrolledOn`,{when:u.confirmedAt?new Date(u.confirmedAt).toLocaleString():`—`})})]})]}),d(`div`,{className:`text-[11px] text-foreground-subtle`,children:r(`users.totpModal.removingHereClearsTheServer`,`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`)}),a(`div`,{className:`flex justify-end gap-2`,children:[d(K,{onClick:n,variant:`secondary`,children:r(`common.close`,`Close`)}),a(`button`,{onClick:async()=>{await o({title:r(`users.totpModal.remove2fa`,`Remove 2FA`),message:r(`users.totpModal.removeTwoFactorAuthenticationFor`,`Remove two-factor authentication for "{{username}}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,{username:t}),confirmLabel:r(`common.remove`,`Remove`),variant:`danger`})&&m.mutate({userId:e})},disabled:m.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[m.isPending?d(A,{className:`h-3 w-3 animate-spin`}):d(D,{className:`h-3 w-3`}),r(`users.totpModal.remove2fa`,`Remove 2FA`)]})]})]})]})]})})}e();function Nr({userId:e,username:t,onClose:n}){let{t:i}=J(),{user:o,logout:s}=bt(),c=o?.id===e,l=B(),u=H.useUtils(),f=H.auth.listSessions.useQuery({userId:e}),[p,m]=r(null),h=H.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:$t(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(V,{open:!0,onOpenChange:e=>!e&&n(),children:a(Ie,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`user-sessions-modal`,children:[d(st,{children:a(He,{className:`flex items-center gap-2`,children:[d(me,{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(ge,{className:`space-y-3`,children:[p!==null&&d(`div`,{className:`text-[11px] text-danger`,children:p}),d(Zt,{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(tt,{className:`justify-between`,children:[a(`button`,{onClick:()=>void _(),disabled:h.isPending||(f.data??[]).length===0,className:`inline-flex items-center gap-1.5 rounded border border-danger/40 px-2.5 py-1 text-[11px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,children:[h.isPending&&v===null?d(A,{className:`h-3 w-3 animate-spin`}):d(fe,{className:`h-3 w-3`}),i(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`)]}),d(K,{onClick:n,variant:`secondary`,children:i(`common.close`,`Close`)})]})]})})}function Pr({icon:e,label:t,count:n,all:r,total:i}){let{t:o}=J();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 Fr({scopes:e,isAdmin:t,invalidReason:n}){let{t:r}=J(),i=j(),c=o({queryKey:[`auth`,`previewScope`,e,t],enabled:n===null,queryFn:()=>i.trpcClient.auth.previewScope.query({scopes:[...e],isAdmin:t})}),{data:l}=De({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(T,{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(A,{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(Pr,{icon:I,label:r(`users.scopePreview.devicesTheyCanSee`,`Devices they can see`),count:f.device.view.deviceCount,all:f.device.view.all,total:u}),d(Pr,{icon:m,label:r(`users.scopePreview.devicesTheyCanOperate`,`Devices they can operate`),count:f.device.create.deviceCount,all:f.device.create.all,total:u}),d(Pr,{icon:g,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 Ir(e){let t=oe(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 Lr(e){return e.mode===`advanced`?e.advancedScopes:e.roleId===null?[]:ae({roleId:e.roleId,selector:e.selector,includeLinked:e.includeLinked})}function Rr({user:e,onClose:t,onSubmit:i,submitting:o,callerScopes:c}){let{t:l}=J(),u=w(),f=n(()=>Ir(e.scopes??[]),[e.scopes]),[p,m]=r(f),[h,g]=r(f.mode===`advanced`),_=n(()=>Lr(p),[p]),v=!e.isAdmin&&p.mode===`role`&&p.roleId===null,b=n(()=>e.isAdmin?null:p.mode===`role`&&p.roleId===null?l(`users.userAccessModal.pickAccess`):Ue(_,u),[e.isAdmin,p.mode,p.roleId,_]),x=e=>m({...p,...e});return d(V,{open:!0,onOpenChange:e=>!e&&t(),children:a(Ie,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-2xl`,children:[a(st,{children:[d(He,{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(ge,{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(T,{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:R.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:()=>x({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(Ir(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?y:S,{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(ct,{value:p.advancedScopes,onChange:e=>x({mode:`advanced`,advancedScopes:e}),clampToParent:c,emptyHint:d(s,{children:d(xt,{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(ye,{value:p.selector,onChange:e=>x({selector:e}),includeLinked:p.includeLinked,onIncludeLinkedChange:e=>x({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(Fr,{scopes:_,isAdmin:e.isAdmin,invalidReason:b})]})]}),a(tt,{children:[d(K,{variant:`outline`,size:`sm`,onClick:t,children:l(`common.cancel`,`Cancel`)}),d(K,{size:`sm`,onClick:()=>i([..._]),disabled:o||b!==null,children:o?d(A,{className:`h-3 w-3 animate-spin`}):l(`users.userAccessModal.saveAccess`,`Save access`)})]})]})})}e();var zr=8;function Br(){return{username:``,password:``,isAdmin:!1}}function Vr(e){return{id:e.id,username:e.username,password:``,isAdmin:e.isAdmin}}function Hr(e){return e instanceof Error?e.message:q.t(`admin.system.users.genericError`)}function Ur(){let{t:e}=J(),n=c(),{user:i}=bt(),{state:o,openNew:l,openEdit:u,close:p}=Xe(),[h,_]=r(null),[v,y]=r(null),[x,S]=r(!1),{data:C,isLoading:w,isError:T,error:E,refetch:D}=Be(),O=B(),te=Ge(),j=()=>n.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),M=Ze(),N=ut({onSuccess:j}),F=Te({onSuccess:j}),I=ke({onSuccess:j}),ne=je({onSuccess:()=>{j(),L(null)}}),[re,L]=r(null),[R,ie]=r(null),[ae,oe]=r(null),[se,ce]=r(null),le=C??[],z=o.mode===`edit`?le.find(e=>e.id===o.id)??null:null,de=()=>{_(null),y(null),S(!1),M.reset(),F.reset(),p()};t(()=>{if(o.mode===`closed`){_(null),y(null),S(!1);return}if(o.mode===`new`){_(e=>e!==null&&e.id===void 0?e:Br());return}if(z===null){w||p();return}_(e=>e?.id===z.id?e:Vr(z))},[o,z,w,p]);let fe=o.mode===`new`&&h!==null&&h.id===void 0||o.mode===`edit`&&h!==null&&z!==null;async function pe(t){await O({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`})&&(N.mutate({id:t.id}),o.mode===`edit`&&o.id===t.id&&de())}async function he(t){let n=await te({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<zr?q.t(`admin.system.users.passwordTooShort`,{min:zr}):null});n===null||n.length===0||await O({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`)})&&I.mutate({id:t.id,newPassword:n})}function ge(e,t){t!==e.isAdmin&&F.mutate({id:e.id,isAdmin:t})}async function _e(){if(h!==null){y(null);try{if(h.id===void 0){let e=h.username.trim();if(e===``||h.password.length<zr)return;await M.mutateAsync({username:e,password:h.password,isAdmin:h.isAdmin})}else await F.mutateAsync({id:h.id,isAdmin:h.isAdmin});j(),de()}catch(e){y(Hr(e))}}}function ve(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}let ye=M.isPending||F.isPending,be=h!==null&&h.id===void 0&&h.username.trim()!==``&&h.password.length>=zr,xe=h!==null&&h.id!==void 0,Ce=ye||(h?.id===void 0?!be:!xe),V=e=>N.isPending&&N.variables?.id===e.id||F.isPending&&F.variables?.id===e.id||I.isPending&&I.variables?.id===e.id,H=[{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=>ge(t,e.target.checked),disabled:V(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(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>L(t),title:e(`admin.system.users.configureAccess`,`Configure access`),children:[d(P,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),d(Wr,{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:ve(e.createdAt)})},{key:`actions`,header:e(`admin.system.users.actions`,`Actions`),align:`right`,nowrap:!0,notSortableReason:`Row actions`,render:t=>{let n=V(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(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>u(t.id),disabled:n,title:e(`admin.system.users.editUser`,`Edit user`),children:[d(m,{className:`h-3 w-3`}),e(`common.edit`,`Edit`)]}),r&&a(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>ie(t),disabled:n,title:e(`admin.system.users.removeTwoFactorAuthentication`,`Remove two-factor authentication`),children:[d(f,{className:`h-3 w-3`}),e(`admin.system.users.remove2fa`,`Remove 2FA`)]}),a(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>oe(t),disabled:n,title:e(`admin.system.users.linkedSignInAccounts`,`Linked sign-in accounts`),children:[d(k,{className:`h-3 w-3`}),e(`admin.system.users.signInLinks`,`Sign-in links`)]}),a(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>ce(t),disabled:n,title:e(`admin.system.users.activeSessions`,`Active sessions`),children:[d(me,{className:`h-3 w-3`}),e(`admin.system.users.sessions`,`Sessions`)]}),a(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void he(t),disabled:n,title:e(`admin.system.users.resetPassword`,`Reset password`),children:[d(ue,{className:`h-3 w-3`}),e(`admin.system.users.resetPassword`,`Reset password`)]}),a(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void pe(t),disabled:n,title:e(`admin.system.users.deleteUser`,`Delete user`),className:`text-danger hover:bg-danger/10`,children:[n?d(A,{className:`h-3 w-3 animate-spin`}):d(g,{className:`h-3 w-3`}),e(`common.delete`,`Delete`)]})]})}}];return a(kt,{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(K,{size:`sm`,type:`button`,onClick:()=>{y(null),l()},children:[d(ee,{className:`h-3.5 w-3.5`}),e(`admin.system.users.createUser`,`Create User`)]}),children:[T&&d(W,{title:e(`admin.system.users.couldNotLoadUsers`,`Could not load users`),message:Hr(E),onRetry:()=>void D()}),w&&a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(A,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}),!w&&!T&&le.length===0&&d(rt,{icon:b,title:e(`admin.system.users.noUsersYet`,`No users yet`),description:e(`admin.system.users.createAUserToGrant`,`Create a user to grant hub access.`)}),!w&&!T&&le.length>0&&d(Re,{columns:H,rows:le,rowKey:e=>e.id,minWidthPx:560,maxBodyHeight:`max-h-[60vh]`,onRowClick:e=>u(e.id)}),d(Pe,{open:fe,onClose:de,title:h?.id===void 0?e(`admin.system.users.createUser`,`Create User`):e(`admin.system.users.edit`,`Edit {{value1}}`,{value1:h.username||`user`}),icon:b,error:v,testId:`user-form-dialog`,footer:d(K,{size:`sm`,type:`button`,disabled:Ce,onClick:()=>void _e(),children:ye?a(s,{children:[d(A,{className:`h-3.5 w-3.5 animate-spin`}),e(`admin.system.users.saving`,`Saving…`)]}):h?.id===void 0?e(`admin.system.users.create`,`Create`):e(`common.save`,`Save`)}),children:h!==null&&a(`div`,{className:`space-y-3`,children:[d(dt,{label:e(`admin.system.users.username`,`Username`),required:h.id===void 0,children:d(Se,{value:h.username,onChange:e=>_({...h,username:e.target.value}),placeholder:`john`,autoFocus:h.id===void 0,disabled:h.id!==void 0,"data-testid":`user-form-username`})}),h.id===void 0&&d(dt,{label:e(`admin.system.users.password`,`Password`),required:!0,description:e(`admin.system.users.atLeastCharacters`,`At least {{value1}} characters.`,{value1:String(zr)}),children:d(we,{value:h.password,onValueChange:e=>_({...h,password:e}),shown:x,onToggleShown:()=>S(e=>!e),placeholder:`••••••••`,"data-testid":`user-form-password`})}),d(dt,{label:e(`admin.system.users.admin`,`Admin`),description:e(`admin.system.users.unrestrictedAccessToEveryCapability`,`Unrestricted access to every capability and device.`),children:a(`label`,{className:`inline-flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[d(`input`,{type:`checkbox`,checked:h.isAdmin,onChange:e=>_({...h,isAdmin:e.target.checked}),className:`rounded border-border focus:ring-primary`,"data-testid":`user-form-admin`}),d(`span`,{children:e(`admin.system.users.admin`,`Admin`)})]})}),h.id!==void 0&&d(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`admin.system.users.toChangeThePasswordUse`,`To change the password, use Reset password on the user's row. Access scopes are configured from the Access column.`)})]})}),R&&d(Mr,{userId:R.id,username:R.username,onClose:()=>ie(null)}),ae&&d(jr,{userId:ae.id,username:ae.username,onClose:()=>oe(null)}),se&&d(Nr,{userId:se.id,username:se.username,onClose:()=>ce(null)}),re&&d(Gr,{user:re,onClose:()=>L(null),onSubmit:e=>ne.mutate({userId:re.id,scopes:e}),submitting:ne.isPending})]})}function Wr({scopes:e}){let{t}=J(),n=w();if(e.length===0)return d(`span`,{className:`font-medium text-warning`,children:t(`admin.system.users.noAccess`,`No access`)});let r=oe(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:ie(r.roleId).label}),` ·`,` `,pt(r.selector,n)]})}function Gr(e){let{user:t}=bt(),n=t?.isAdmin===!0;return d(Rr,{...e,callerScopes:n?null:t?.scopes??[]})}e();var Kr={"api-keys":$.tokens,"linked-sessions":$.linkedApps},qr=`certificates`;function Jr(e){return a(K,{size:`sm`,type:`button`,"data-testid":`certificates-pair-device`,onClick:e,children:[d(f,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),q.t(`systemPage.identity.pairADevice`,`Pair a device`)]})}function Yr(){let{t:e}=J(),[t]=Dt(),n=An(),[i,a]=r(!1),o=Kr[t.get(`tab`)??``];if(o!==void 0)return d(_t,{to:Et(`access`,{integration:o}),replace:!0});let s=yt(`/system/identity`,{t:e,isAdmin:!0})??{icon:N,title:e(`system.identity`,`Identity & Access`)},c=t.get(`tab`)??`users`,l=t.get(`integration`),u=c===St.access.tab?kn(l,n.requestCreate):c===`certificates`?Jr(()=>a(!0)):void 0;return d(Ot,{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(Ur,{})},{id:St.access.tab,label:e(`systemPage.identity.tokensSessions`,`Tokens & sessions`),content:d(On,{createRequested:n.createRequested,onCreateConsumed:n.clearCreate}),ownedParams:Tt.concat([Vt.token,Vt.scoped,Vt.admin])},{id:qr,label:e(`systemPage.identity.certificates`,`Certificates`),content:d(Ar,{pairOpen:i,onPairClose:()=>a(!1)})},{id:St.authentication.tab,label:e(`systemPage.identity.authentication`,`Authentication`),content:d(Un,{}),ownedParams:Tt}]})}export{Yr 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{Br as l,Ci as u,Cn as d,It as f,Nt as p,Si as m,Zi as h,bi as g,bn as _,ca as v,ci as y,dt as b,ht as x,kn as S,mi as C,or as w,ot as T,pn as ee,un as E,vn as D,zr as O}from"./player-overlays-BQ-CPD3k.js";import{li as k}from"./client-C7mYZlqO.js";import{t as A}from"./search-x-DrZuvHV8.js";import{$n as j,Aa as M,At as te,Ba as N,Bo as P,Da as F,Dt as ne,Fa as I,Ho as L,Ia as R,Jr as z,Kn as B,Ko as V,Ku as H,Na as U,Oa as re,Ot as ie,Qn as W,Uo as ae,Uu as G,Va as K,Vo as oe,Wa as q,Wo as se,Ya as ce,Yr as le,Zt as ue,er as de,fi as fe,io as pe,ir as me,ja as he,jn as ge,ka as _e,ln as J,no as Y,rr as ve,xo as ye,yn as be,zo as xe}from"./src-DP8JO4HZ.js";import{t as X}from"./useTranslation-D3Is_4B6.js";import{n as Se}from"./addon-icons-context-Nt5kiIqp.js";import{Z as Ce,et as we,nt as Te,tt as Ee,z as De}from"./index-B-H1mfMz.js";import{t as Oe}from"./NodeAddonsSettingsPanel-BNTQVCjk.js";import{t as ke}from"./device-integration-icon-eQMV6gf2.js";import{n as Ae,r as je,t as Me}from"./ScanNetworkModal-DzMITtJ8.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(),f=o(),[h,g]=r({}),[_,v]=r(!1),[y,S]=r(null),[C,T]=r(Le),E=Y({addonId:l},{enabled:e}),D=E.data?.deviceType??null,O=q({addonId:l,type:D??k.Camera},{enabled:e&&E.isSuccess&&D!==null}),A=O.data??null;t(()=>{e&&(g(A?Ie(A.sections.flatMap(e=>e.fields)):{}),T(Le()),v(!1),S(null))},[e,s,A]);let j=n(()=>({...h,_probeRequestId:C}),[h,C]),M=I({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),te=ye(),N=i(async(e,t)=>{v(!0);let n=await te.mutateAsync({addonId:l,type:D??k.Camera,key:e,value:t,formValues:j});return n.status===`ok`&&n.suggestedValues&&g(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},[te,l,j,D]),{testAllStatus:P,hasProbeFields:F,probeResults:ne,handleTestAll:L,clearProbeResult:R}=Ne(A??{sections:[]},h,N);async function z(e){S(null);try{await M.mutateAsync({addonId:l,type:D??k.Camera,config:h,integrationId:s}),e?g(A?Ie(A.sections.flatMap(e=>e.fields)):{}):u()}catch(e){S(e instanceof Error?e.message:String(e))}}if(!e)return null;let B=Pe((A?.sections??[]).flatMap(e=>e.fields)).filter(e=>Fe(h[e])),V=B.length===0,H=E.isLoading||D!==null&&O.isLoading,U=E.isError||E.isSuccess&&D===null||O.isError||O.isSuccess&&A===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(b,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:H?c(`div`,{className:`flex items-center justify-center py-8`,children:c(w,{className:`h-5 w-5 animate-spin text-primary`})}):U?a(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[c(p,{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(Ce,{i18nKey:`integrations.addDeviceDialog.notReady`,values:{addonId:l},components:{mono:c(`span`,{className:`font-mono`})}})})]})]}):c(De,{schema:A,values:h,onChange:g,onTestField:N,probeResults:ne,onClearProbe:R})}),!U&&!H&&a(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[a(`button`,{type:`button`,onClick:()=>v(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(ee,{className:`h-3.5 w-3.5`}),d(`integrations.addDeviceDialog.testLogs`,`Test logs`),c(`span`,{className:`font-mono text-[9px] opacity-60`,children:C.slice(0,14)})]}),c(m,{className:`h-3.5 w-3.5 transition-transform ${_?`rotate-180`:``}`})]}),_&&c(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:c(ue,{addonId:l,requestId:C,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!U&&!H&&(y||B.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(p,{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:B.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`)}),!U&&F&&a(`button`,{type:`button`,onClick:L,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(w,{className:`h-3.5 w-3.5 animate-spin`}):c(x,{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:()=>z(!0),disabled:U||!V||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:()=>z(!1),disabled:U||!V||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=F(),s=(M({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 f=[`${u}/${s.total} ${i(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];s.adopted>0&&f.push(`${s.adopted} ${i(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),s.alreadyAdopted>0&&f.push(`${s.alreadyAdopted} ${i(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),s.failed>0&&f.push(`${s.failed} ${i(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let m=f.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(w,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):s.failed>0?c(p,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):s.state===`cancelled`?c(y,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):c(C,{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 d=v(),{t:f}=X(),m=o(),[h,g]=r(new Set),[_,y]=r(new Set),[x,S]=r(new Map),[C,T]=r(null),{data:ee}=oe(),E=(ee??[]).find(t=>t.addonId===e)?.supportsLocationImport??!1,[O,k]=r(!0),A=re({addonId:e,integrationId:n}).data?.filters,j=A&&A.length>0?A:[Ve(f)],[M,te]=r(j.find(e=>e.isDefault)?.id??(j.some(e=>e.id===$)?$:j[0].id)),N=M!==$,P=he(),F=_e({addonId:e,integrationId:n,page:1,pageSize:He,filter:M}),I=F.refetch,L=P.mutate,R=i(()=>{L({addonId:e,integrationId:n},{onSettled:()=>{I()}})},[L,e,n,I]),z=s(null);t(()=>{let t=`${e}::${n}`;z.current===t||F.isLoading||(z.current=t,(F.data?.candidates.length??0)===0&&R())},[e,n,F.isLoading,F.data,R]);let B=P.isPending,V=P.isError?P.error instanceof Error?P.error.message:String(P.error):null,ie=typeof P.data?.lastError==`string`&&P.data.lastError.length>0?P.data.lastError:null,W=F.data?.candidates??[],ae=F.isError?F.error instanceof Error?F.error.message:String(F.error):null,K=U(),[q,se]=r(null),ce=i(e=>{e.alreadyAdopted||g(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),le=i(e=>{y(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),ue=i((e,t)=>{S(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})},[]),de=i(e=>{let t={};for(let n of e){let e=x.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[x]),fe=i(async()=>{T(null);let t=[...h];if(t.length!==0)try{let r=de(t),{jobId:i}=await K.mutateAsync({addonId:e,integrationId:n,filter:M,childNativeIds:t,...r?{perCandidate:r}:{},...E?{importLocations:O}:{}});se(i),g(new Set),S(new Map)}catch(e){T(e instanceof Error?e.message:String(e))}},[h,de,K,e,n,M,E,O]),pe=s(null),me=i(()=>{q===null||pe.current===q||(pe.current=q,I(),m.invalidateQueries({queryKey:[[`integrations`]]}),m.invalidateQueries({queryKey:[[`deviceManager`]]}))},[q,I,m]),ge=i(e=>{te(e),g(new Set),y(new Set),S(new Map),T(null)},[]),J=h.size,Y=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:f(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),c(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:f(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),a(`div`,{className:`flex items-center gap-3 shrink-0`,children:[E&&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`}),f(`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":f(`common.close`,`Close`),children:c(b,{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:[(V??ae??ie)&&W.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(p,{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:f(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),c(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:V??ae??ie})]})]})}),j.length>1&&c(Ge,{filters:j,activeFilter:M,onSelect:ge}),c(`div`,{className:`flex-1 min-h-0`,children:c(ne,{mode:`generic`,items:W,pageSize:Ue,getKey:e=>e.childNativeId,getSearchText:Be,getFilterType:e=>e.type,filterOptions:G(d),filterLabel:f(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:F.isLoading||B&&W.length===0,searchPlaceholder:f(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(V??ae??ie)&&W.length===0?``:f(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:a(`button`,{type:`button`,onClick:R,disabled:B,title:f(`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(D,{className:`h-3.5 w-3.5 ${B?`animate-spin`:``}`}),f(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:f(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>c(Ke,{candidate:e,expandable:!N,expanded:_.has(e.childNativeId),onToggleExpand:()=>le(e.childNativeId),adoptedLabel:f(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:f(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=H(e.type,d),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":h.has(e.childNativeId)?f(`integrations.adoptDevicesModal.deselect`,`Deselect`):f(`integrations.adoptDevicesModal.select`,`Select`),className:`inline-flex h-5 w-5 items-center justify-center rounded border ${h.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:h.has(e.childNativeId)&&c(u,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!N&&_.has(e.childNativeId),renderExpanded:N?void 0:e=>c(qe,{candidate:e,hiddenChildIds:x.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>ue(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:h.has(e.childNativeId)?`bg-primary/5`:``})})]}),C&&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(p,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:C})]})}),q!==null&&c(ze,{addonId:e,integrationId:n,jobId:q,onFinished:me}),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:f(`integrations.cancel`,{defaultValue:`Cancel`})}),a(`button`,{onClick:Y?l:fe,disabled:!Y&&(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(w,{className:`h-3.5 w-3.5 animate-spin`}),Y?f(`integrations.close`,{defaultValue:`Close`}):f(`integrations.addSelected`,{defaultValue:`Add selected`}),!Y&&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?m:g,{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?l:O,{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}=L({id:e},{enabled:s===`account`||s===`broker`}),_=n(()=>{let e=h?.brokerId;return typeof e==`string`?e:null},[h]),{data:v,isLoading:y}=z({addonId:t,nodeId:`hub`},{enabled:s===`account`}),b=n(()=>v?Xe(v):null,[v]),x=se(),S=(t,n)=>{x.mutate({id:e,settings:t,...n?{secretKeys:[...n]}:{}},{onSuccess:()=>{m.invalidateQueries(),f()}})};return c(W,{open:!0,onOpenChange:e=>!e&&f(),children:a(de,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[c(ve,{children:a(me,{children:[p(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,r]})}),c(j,{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:_})]}),x.isPending?a(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(w,{className:`h-3 w-3 animate-spin`}),p(`integrations.saving`,{defaultValue:`Saving…`})]}):c(je,{kind:l,onResolved:e=>{S({brokerId:e})},onBack:f}),x.isError&&c(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):c(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):s===`account`?g||y?a(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(w,{className:`h-3 w-3 animate-spin`}),p(`integrations.loading`,{defaultValue:`Loading…`})]}):c(Ae,{addonId:t,configSchema:b,canTest:u,initialName:r,initialConfig:Ye(b,h??{}),submitLabel:p(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e,secretKeys:t})=>S(e,t),onBack:f}):c(B,{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}=Ee(),l=o(),u=we(),[p,m]=Te(),g=T(),[v,y]=r(!1),[b,x]=r(!1),[C,D]=r(!1),[O,k]=r(!1),{data:M,isLoading:F}=P({id:s??``},{enabled:!!s}),{data:I}=z({addonId:M?.addonId??``,nodeId:`hub`},{enabled:!!M?.addonId}),{data:L,isSuccess:B}=oe(),H=n(()=>{let e=M?.addonId;return!e||!B?null:(L??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[L,M?.addonId,B]),{data:U}=N({}),re=n(()=>(U?.providers??[]).some(e=>e.addonId===M?.addonId),[U,M?.addonId]),G=H!==null,q=M?.info?.fixed===!0,se=G?H===`device-adoption`?e(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):e(`integrations.addDevice`):e(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),he=n(()=>{let e=M?.addonId;return!e||!B?null:(L??[]).find(t=>t.addonId===e)?.brokerKind??null},[L,M?.addonId,B]),_e=n(()=>{let e=M?.addonId;return!e||!B?!1:(L??[]).find(t=>t.addonId===e)?.canTest===!0},[L,M?.addonId,B]),Y=n(()=>{let e=M?.addonId;return!e||!B?null:(L??[]).find(t=>t.addonId===e)?.mode??null},[L,M?.addonId,B]);t(()=>{p.get(`add`)===`1`&&G&&(y(!0),m(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[p,G,m]);let ye=I!=null&&Array.isArray(I.sections)&&I.sections.some(e=>e.fields.length>0),{data:Se}=le({addonId:M?.addonId??``,nodeId:`hub`},{enabled:!!M?.addonId&&Y!==`account`}),Ce=Y!==null&&Y!==`account`&&Qe(Se),De=n(()=>M?.addonId?[M.addonId]:[],[M?.addonId]),{data:Ae}=ce({projection:`slim`},{refetchInterval:3e4}),je=[[`integrations`,`get`],{input:{id:s??``},type:`query`}],Z=V({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=xe({onSuccess:()=>{l.invalidateQueries({queryKey:[[`integrations`]]}),l.invalidateQueries({queryKey:[[`deviceManager`]]}),u(`/integrations`)}}),Pe=fe({onSuccess:()=>{l.invalidateQueries({queryKey:[[`integrations`]]}),l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=pe({onSuccess:()=>{l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ie=R({onSuccess:()=>{l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Le=K({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:$}=ae(void 0),Ve=n(()=>ie($),[$]),He=i(e=>u(`/devices/${String(e)}`),[u]),Ue=n(()=>{let e=M?.id;return e?Q.filter(t=>{let n=Ve(t);return n.kind===`resolved`&&n.integration.id===e}):[]},[Q,M?.id,Ve]),Ge=n(()=>$===void 0?null:te(Ue).length,[$,Ue])??`…`;return F?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`})]}):M?a(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[c(be,{items:[{label:e(`integrationDetail.integrations`,`Integrations`),onClick:()=>u(`/integrations`)},{label:M.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:M.addonId}),a(`div`,{className:`min-w-0`,children:[c(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:M.name}),a(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[M.addonId,` · `,Ge,` `,e(`integrations.devices`)]})]})]}),a(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[re&&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(d,{className:`h-3.5 w-3.5`}),e(`integrationDetail.scanNetwork`,`Scan network`)]}),!q&&a(`button`,{onClick:()=>y(!0),disabled:!G,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:se,children:[c(S,{className:`h-3.5 w-3.5`}),se]}),a(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Z.isPending?`opacity-60`:``} ${M.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:e(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[c(ge,{checked:M.enabled,onCheckedChange:e=>Z.mutate({id:s,enabled:e}),disabled:Z.isPending,"aria-label":M.enabled?e(`integrationDetail.disableIntegration`,`Disable integration`):e(`integrationDetail.enableIntegration`,`Enable integration`)}),c(`span`,{className:`text-[11px] font-medium ${M.enabled?`text-success`:`text-foreground-subtle`}`,children:M.enabled?e(`integrationDetail.enabled`,`Enabled`):e(`integrationDetail.disabled`,`Disabled`)}),Z.isPending&&c(w,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Y!==`standalone`&&(ye||H===`device-adoption`)&&a(`button`,{onClick:()=>D(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[c(E,{className:`h-3 w-3`}),e(`integrations.config`)]}),a(`button`,{onClick:()=>k(!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(ee,{className:`h-3 w-3`}),e(`integrations.logs`,{defaultValue:`Logs`})]}),c(J,{label:e(`integrationDetail.restart`,`Restart`),icon:_,title:e(`integrationDetail.restart2`,`Restart "{{name}}"?`,{name:M.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:M.addonId})}),!q&&s&&c(J,{label:e(`integrations.delete`,{defaultValue:`Delete`}),icon:f,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:M.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})})]})]}),Ce&&c(Oe,{nodeId:null,addonIds:De,level:`global`,surface:`integration`,title:e(`integrations.settings`,{defaultValue:`Settings`})}),c(ne,{context:`integration-detail`,devices:Q,trpc:g.trpcClient,integrationOf:Ve,forceIntegrationId:M.id,urlScope:`root`,lsKey:`integration-detail:${M.addonId}`,resolveIntegrationIcon:ke,resolveParent:Be,onNavigate:He,batchActions:{remove:Fe.mutate,disable:Ie.mutate,enable:Le.mutate},...q?{}:{onDeleteDevice:e=>Fe.mutate({deviceId:e.id})}}),v&&s&&H===`device-adoption`&&c(We,{addonId:M.addonId,integrationId:s,onClose:()=>y(!1)}),v&&s&&H===`device-provider`&&c(Re,{open:v,integrationId:s,addonId:M.addonId,onClose:()=>y(!1)}),b&&M&&c(Me,{open:b,scope:{addonId:M.addonId,label:M.name},onClose:()=>x(!1)}),C&&s&&H!==null&&Y!==null&&c(Ze,{integrationId:s,addonId:M.addonId,name:M.name,kind:H,mode:Y,brokerKind:he,canTest:_e,trpc:g.trpcClient,onClose:()=>D(!1)}),O&&c(W,{open:!0,onOpenChange:e=>!e&&k(!1),children:a(de,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[c(ve,{className:`mb-0`,children:a(me,{className:`flex items-center gap-2 min-w-0`,children:[c(ee,{className:`h-4 w-4 text-primary shrink-0`}),c(`span`,{className:`truncate`,children:M.name}),a(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate font-normal`,children:[M.addonId,s?` · ${s}`:``]})]})}),c(j,{className:`min-h-0 overflow-hidden p-0`,children:c(ue,{addonId:M.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(A,{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:()=>u(`/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(h,{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 +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{Ci as l,Cn as u,Oi as d,On as f,Si as p,bi as m,bn as h,dt as g,fn as _,kn as v,or as y,ot as b,un as x}from"./player-overlays-BQ-CPD3k.js";import{At as S,Bu as C,Dt as ee,Ea as te,Jr as w,Mu as T,Ot as E,Ra as D,Ro as O,Uo as k,Vo as A,Ya as j,nt as M,r as N}from"./src-DP8JO4HZ.js";import{t as P}from"./i18n-CiEPJn04.js";import{t as F}from"./useTranslation-D3Is_4B6.js";import{Y as I,et as L,nt as R}from"./index-B-H1mfMz.js";import{t as z}from"./AdminPage-Bc7EcIQy.js";import"./useEventInvalidation-B7n7uzAw.js";import{t as ne}from"./device-integration-icon-eQMV6gf2.js";import{n as re,r as B,t as ie}from"./ScanNetworkModal-DzMITtJ8.js";e();function V(e=!0){t(()=>{if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=t}},[e])}e();function ae(e,n){let[i,a]=r(!1);return t(()=>{if(!e){a(!1);return}a(!1);let t=setTimeout(()=>a(!0),n);return()=>clearTimeout(t)},[e,n]),i}e();function H({providerId:e,onImport:n,onSkip:i}){let{t:o}=F(),[s,u]=r(new Set),f=D(),p=f.data,m=f.isPending||!f.data&&!f.isError;t(()=>{e&&(f.isPending||f.data||f.mutate({addonId:e}))},[e,f]);function h(e){u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(m)return a(`div`,{className:`flex flex-col items-center py-12`,children:[c(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),c(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:o(`integrations.searchingDevices`)})]});let g=p??[];return a(`div`,{className:`space-y-4`,children:[c(`p`,{className:`text-xs text-foreground-subtle`,children:g.length>0?o(`integrations.foundDevices`,{count:g.length}):o(`integrations.noDevicesFound`)}),g.length>0&&c(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:g.map(e=>{let t=e.stableId,n=e.suggestedName??t,r=s.has(t),i=e.alreadyOnboarded===!0;return a(`button`,{onClick:()=>{i||h(t)},disabled:i,title:i?o(`integrations.alreadyAddedHint`,{defaultValue:`Already added as "{{name}}" — re-adding would overwrite its settings.`,name:e.onboardedName??n}):void 0,className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${i?`border-border bg-surface opacity-60 cursor-not-allowed`:r?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[c(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${r&&!i?`border-primary bg-primary`:`border-border`}`,children:r&&!i&&c(l,{className:`h-3 w-3 text-primary-foreground`})}),c(d,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),c(`span`,{className:`text-xs font-medium text-foreground truncate`,children:n}),i&&c(`span`,{className:`ml-auto flex-shrink-0 rounded bg-surface-muted px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:o(`integrations.alreadyAdded`,{defaultValue:`Already added`})})]},t)})}),a(`div`,{className:`flex items-center justify-between pt-2`,children:[c(`button`,{onClick:i,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:o(`integrations.skip`)}),g.length>0&&a(`button`,{onClick:()=>n(Array.from(s)),disabled:s.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[o(`integrations.importSelected`),` (`,s.size,`)`]})]})]})}e();function U({onSelect:e,onClose:t,pendingAddonId:i=null}){let{t:o}=F(),s=L(),[l,u]=r(``),{data:d,isLoading:f}=A(),p=n(()=>{let e=d??[],t=l.trim().toLowerCase();return t.length===0?e:e.filter(e=>`${e.name} ${e.description??``} ${e.addonId}`.toLowerCase().includes(t))},[d,l]);if(f)return c(`div`,{className:`grid grid-cols-2 gap-2 p-2`,children:[1,2,3,4].map(e=>c(`div`,{className:`h-24 rounded-lg bg-surface animate-pulse`},e))});let m=i!==null;return a(`div`,{className:`space-y-3`,"data-testid":`provider-picker`,children:[a(`div`,{className:`relative`,children:[c(_,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-foreground-subtle`,"aria-hidden":!0}),c(T,{type:`search`,value:l,onChange:e=>u(e.target.value),placeholder:o(`integrations.searchProviders`,`Search integrations…`),className:`pl-8`,"data-testid":`provider-picker-search`,"aria-label":o(`integrations.searchProviders`,`Search integrations…`)})]}),c(`div`,{className:`grid grid-cols-2 gap-2`,children:p.map(n=>{let r=n.instanceMode===`unique`&&n.existingInstances.length>0,l=i===n.addonId,u=m;return a(`button`,{type:`button`,disabled:u,"data-testid":`provider-pick-${n.addonId}`,onClick:()=>{if(!u)if(r){let e=n.existingInstances[0].id;t(),s(`/integrations/${e}`)}else e(n.addonId,n.instanceMode,n.discoveryMode,n.name,n.kind,n.brokerKind,n.mode,n.canTest)},className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-center text-xs hover:border-primary/50 hover:bg-surface-hover transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[n.iconUrl?c(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${n.color}15`},children:c(`img`,{src:n.iconUrl,alt:``,className:`h-5 w-5`})}):c(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${n.color}15`},children:c(`span`,{className:`text-sm`,style:{color:n.color},children:`◉`})}),c(`p`,{className:`w-full truncate text-xs font-semibold text-foreground`,children:n.name}),n.description?c(`p`,{className:`w-full line-clamp-2 text-[10px] text-foreground-subtle`,children:n.description}):null,l?c(y,{className:`h-4 w-4 animate-spin text-primary`}):r?a(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[c(x,{className:`h-3 w-3`}),o(`integrations.manage`)]}):null]},n.addonId)})}),p.length===0&&c(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:(d??[]).length===0?o(`integrations.noProviders`):o(`integrations.noProvidersMatch`,`No integrations match your search.`)})]})}e();function oe(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}var W=2e4;function se({open:e,onClose:i}){let{t:l}=F(),u=L(),d=s(),[f,p]=r(`picker`),[m,h]=r(null),[_,v]=r(null),[b,x]=r(`manual`),[S,C]=r(null),[ee,T]=r(``),[E,k]=r(null),[A,j]=r(null),[M,N]=r(!1),{data:P}=w({addonId:m??``,nodeId:`hub`},{enabled:m!=null}),I=n(()=>P?oe(P):null,[P]),R=O({onSuccess:()=>d.invalidateQueries({queryKey:[[`integrations`]]})}),z=D(),ne=z.data;t(()=>{f!==`discovery`||!_||!m||z.isPending||z.data||z.mutate({addonId:m})},[f,_,m,z]);let ie=te({onSuccess:()=>d.invalidateQueries({queryKey:[[`deviceManager`]]})});function se(e,t,n,r,i,a,o,s){if(!R.isPending){if(h(e),N(s),x(n),T(r),j(null),o===`broker`){if(!a){j(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}C(a),p(`broker`);return}if(o===`account`){p(`config`);return}G(e,r)}}async function G(e,t){try{let n=await R.mutateAsync({addonId:e,name:t,settings:{}});i(),J(),u(`/integrations/${n.id}?add=1`)}catch{}}async function ce(e){if(m)try{let t=await R.mutateAsync({addonId:m,name:e.name,settings:e.config,secretKeys:[...e.secretKeys]});v(t.id),k(t.id),b===`auto`||b===`both`?p(`discovery`):q(t.id,{openAdd:!0})}catch{}}async function le(e){if(m)try{let t=await R.mutateAsync({addonId:m,name:ee,settings:{brokerId:e}});k(t.id),v(t.id),q(t.id)}catch{}}async function K(e){if(m){for(let t of e){let e=ne?.find(e=>e.stableId===t);e&&await ie.mutateAsync({addonId:m,candidate:e,...E===null?{}:{integrationId:E}})}q()}}function q(e,t){let n=e??_??m;i(),J(),n&&u(t?.openAdd===!0?`/integrations/${n}?add=1`:`/integrations/${n}`)}function J(){p(`picker`),h(null),v(null),x(`manual`),C(null),T(``),k(null),j(null),N(!1)}function Y(){i(),J()}V(e);let X=R.isPending,Z=ae(X,W);if(!e)return null;let ue={picker:l(`integrations.newIntegration`),config:l(`integrations.configureIntegration`),discovery:l(`integrations.importDevices`),broker:l(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},Q=X?m:null,$=R.error,de=X&&!Z;return a(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:de?void 0:Y}),a(`div`,{className:`relative z-10 w-full max-w-lg max-h-[calc(85dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[a(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:ue[f]}),c(`button`,{onClick:Y,disabled:de,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:c(g,{className:`h-4 w-4`})})]}),a(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[$&&!X&&c(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:$ instanceof Error?$.message:String($)}),f===`picker`&&a(o,{children:[A&&c(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:A}),c(U,{onSelect:se,onClose:Y,pendingAddonId:Q})]}),f===`config`&&m&&c(re,{addonId:m,configSchema:I??null,canTest:M,onSave:ce,onBack:()=>p(`picker`)}),f===`broker`&&S&&c(B,{kind:S,onResolved:e=>{le(e)},onBack:()=>p(`picker`)}),f===`discovery`&&_&&c(H,{providerId:_,onImport:K,onSkip:q})]}),X&&a(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm px-6 text-center`,children:[c(y,{className:`h-6 w-6 animate-spin text-primary`}),c(`p`,{className:`text-xs font-medium text-foreground`,children:l(`integrations.creating`,{defaultValue:`Creating integration…`})}),!Z&&c(`p`,{className:`text-[10px] text-foreground-subtle`,children:l(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),Z&&a(o,{children:[c(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:l(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),c(`button`,{onClick:Y,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:l(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})]})}function G({integration:e,expanded:t,onToggleExpand:n}){let{t:r}=F();return a(`div`,{className:`flex items-center gap-2.5`,children:[c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),n(e.addonId)},"aria-label":t?r(`integrations.integrationColumns.collapse`,`Collapse`):r(`integrations.integrationColumns.expand`,`Expand`),"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:c(t?p:m,{className:`h-3.5 w-3.5`})}),c(I,{type:e.addonId,size:`sm`}),a(`div`,{className:`flex min-w-0 flex-col`,children:[c(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),c(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function ce(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:P.t(`integrations.integrationColumns.integration`,`Integration`),headerClassName:`w-[55%]`,cell:e=>c(G,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:P.t(`integrations.integrationColumns.devices`,`Devices`),headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>P.t(`integrations.integrationColumns.deviceCount`,{count:e.deviceCount})},{key:`status`,header:P.t(`integrations.integrationColumns.status`,`Status`),headerClassName:`w-[15%]`,cell:e=>c(M,{status:e.status})}]}e();function le(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var K=`expand`;function q(){let{t:e}=F(),t=L(),s=b(),[l]=R(),[d,p]=r(!1),m=i(()=>p(!0),[]),g=i(()=>p(!1),[]),[_,y]=r(!1),x=i(()=>y(!0),[]),te=i(()=>y(!1),[]);N([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),N([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:w,isLoading:T,refetch:D}=k(void 0),{data:O,isLoading:A,refetch:M}=j({projection:`slim`}),P=n(()=>O??[],[O]),I=n(()=>w??[],[w]),re=n(()=>{let e=new Map;for(let t of P)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[P]),B=n(()=>E(w),[w]),V=n(()=>{let e=new Map;for(let t of S(P)){let n=B(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[P,B]),ae=n(()=>I.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:le(e),deviceCount:V.get(e.id)??0})),[I,V]),H=l.get(K),U=i(e=>{let t=new URLSearchParams(window.location.search);t.get(K)===e?t.delete(K):t.set(K,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),oe=i(e=>t(`/integrations/${e.id}`),[t]),W=i(e=>re.get(e)??null,[re]),G=i(e=>t(`/devices/${String(e)}`),[t]),q=i(e=>c(ee,{context:`integration-detail`,devices:P,trpc:s.trpcClient,integrationOf:B,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:ne,resolveParent:W,onNavigate:G}),[P,s.trpcClient,B,W,G]),J=i(e=>H===e.addonId,[H]),Y=n(()=>ce({isExpanded:J,onToggleExpand:U}),[J,U]),X=i(e=>`${e.name} ${e.addonId}`,[]),Z=i(e=>e.addonId,[]),ue=i(()=>{D(),M()},[D,M]),Q=T||A,$=I.length>0;return a(z,{icon:f,title:e(`nav.integrations`,`Integrations`),actions:a(o,{children:[c(`button`,{onClick:ue,disabled:Q,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:e(`common.refresh`,`Refresh`),children:c(h,{className:C(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),a(`button`,{onClick:x,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:e(`integrations.scanTheLocalNetworkFor`,`Scan the local network for devices`),children:[c(u,{className:`h-3.5 w-3.5`}),e(`integrations.scanNetwork`,`Scan network`)]}),a(`button`,{onClick:m,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[c(v,{className:`h-3.5 w-3.5`}),e(`integrations.newIntegration`,`New Integration`)]})]}),children:[Q&&c(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>c(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!$&&a(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[c(`p`,{className:`text-sm`,children:e(`integrations.noIntegrationsConfigured`,`No integrations configured.`)}),c(`p`,{className:`text-xs mt-1`,children:e(`integrations.clickNewIntegrationToConnect`,`Click "New Integration" to connect cameras and devices.`)})]}),!Q&&$&&c(ee,{mode:`generic`,items:ae,getKey:Z,getSearchText:X,columns:Y,onRowClick:oe,isExpanded:J,renderExpanded:q,searchPlaceholder:e(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:e(`integrations.empty`,{defaultValue:`No integrations found.`})}),c(se,{open:d,onClose:g}),c(ie,{open:_,onClose:te})]})}export{q as IntegrationsPage};
@@ -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{Fi as c,Fn as l,Fr as u,Ht as d,It as f,Ki as p,Ni as m,O as h,Oi as g,Rr as _,Rt as v,Si as y,Ur as b,V as x,Wr as S,bi as C,bn as w,cn as T,dt as E,ea as D,en as O,gr as k,k as A,kn as j,lr as M,na as N,pi as P,pn as F,pt as I,rn as L,rr as R,ta as z,ti as B,tr as ee,ur as te,ut as ne,z as V,zi as H,zt as re}from"./player-overlays-BQ-CPD3k.js";import{Sr as ie,br as ae,fn as oe}from"./client-C7mYZlqO.js";import{t as se}from"./boxes-DEZFxpEo.js";import{n as ce,r as le,t as ue}from"./speaker-DIrTXPXW.js";import{t as U}from"./user-round-7xIjUD30.js";import{$a as de,$n as fe,Ar as pe,Ca as me,Du as W,F as G,Mn as he,Mu as K,Nn as ge,Nu as _e,Pr as ve,Pu as ye,Qa as be,Qn as xe,Rr as Se,Sa as Ce,Ta as we,Ya as Te,Za as Ee,ao as De,co as Oe,do as ke,eo as Ae,er as je,fo as Me,gn as q,gt as Ne,hr as J,ir as Pe,mo as Fe,nr as Ie,on as Le,oo as Re,po as ze,rr as Be,sn as Ve,so as He,wa as Ue,yo as We}from"./src-DP8JO4HZ.js";import{t as Y}from"./i18n-CiEPJn04.js";import{t as X}from"./useTranslation-D3Is_4B6.js";import{Q as Z,et as Ge,nt as Ke,v as qe}from"./index-B-H1mfMz.js";import{t as Je}from"./AdminSectionedPage-DorUtSBh.js";import{a as Ye,n as Xe,r as Ze}from"./linked-devices-model-Bwz1L9wp.js";e();var Qe={camera:g,hub:ce,container:se,light:te,siren:L,switch:re,sensor:N,thermostat:d,climate:z,button:P,"event-emitter":ne,update:le,notifier:H,script:F,automation:I,lock:R,cover:c,valve:S,humidifier:b,"water-heater":u,fan:_,"media-player":ue,"alarm-panel":T,control:O,presence:U,weather:B,vacuum:m,"lawn-mower":v,image:k,smoke:D};function Q({type:e,className:t}){return s(Qe[e]??P,{"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(xe,{open:e,onOpenChange:e=>e?void 0:p(),children:i(je,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":n,children:[s(Be,{children:s(Pe,{children:n})}),i(fe,{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(G,{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(Ie,{children:[s(J,{variant:`ghost`,onClick:p,children:m(`locations.addDialog.cancel`)}),s(J,{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=me({deviceId:e.id}),m=Ze({status:p.status,data:p.data,error:p.error===null||p.error===void 0?null:p.error}),g=Ue(),_=m.kind===`present`?m:null,v=Ce({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))}}},D=[{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:`${A} 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(J,{variant:`ghost`,size:`sm`,onClick:()=>c(qe(e.id)),children:[s(M,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),n(`locations.links.edit`)]}),s(J,{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(q,{columns:D,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(ge,{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 ${V}`,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(ge,{htmlFor:`location-zone-${e}`,children:o(`locations.locationZoneField.zone`,`Zone`)}),s(W,{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(ye,{value:t,onPick:r,fallbackGlyph:ee,clearGlyph:p,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:ie(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:u,description:d,onRename:p,onDelete:m,onRebuildLinks:g,onAddDevices:_,onPickIcon:v,onSaveDescription:y,zones:b,zoneKey:x,onChangeZone:S}){let{t:C}=X(),[T,D]=r(!1),[O,k]=r(e),j=Le(t,n(()=>({searchText:e=>[e.name,...yt(o,e.id).map(e=>e.name)],facetValue:e=>e.type}),[o])),[M,N]=r(()=>new Set),P=e=>N(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),F=n(()=>St(j.rows,o,M),[j.rows,o,M]),I=[{key:`name`,header:C(`locations.columns.device`),notSortableReason:C(`locations.columns.noSort`),render:e=>e.kind===`member`?s(wt,{row:e,onToggle:()=>P(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`)})]})}],L=()=>{k(e),D(!1)},R=async()=>{let t=O.trim();if(t.length===0||t===e){L();return}await p(t),D(!1)},z=[{id:`rename`,label:C(`locations.locationCard.rename`,`Rename`),icon:l,disabled:c,onClick:()=>{k(e),D(!0)}},{id:`rebuild-links`,label:C(`locations.locationCard.rebuildLinkedDevices`,`Rebuild linked devices`),icon:w,separatorBefore:!0,disabled:c,onClick:()=>void g()},{id:`delete`,label:C(`common.delete`,`Delete`),icon:f,danger:!0,separatorBefore:!0,disabled:c,onClick:()=>void m()}];return i(`section`,{className:`min-w-0 ${h}`,children:[i(`header`,{className:`${A} flex min-h-9 items-center gap-1.5`,children:[s(lt,{name:e,icon:u,busy:c,onPick:v}),T?i(a,{children:[s(K,{value:O,onChange:e=>k(e.target.value),onKeyDown:e=>{e.key===`Enter`&&R(),e.key===`Escape`&&L()},"aria-label":C(`locations.locationCard.rename2`,`Rename {{name}}`,{name:e}),className:`min-w-0 flex-1`,autoFocus:!0}),s(J,{type:`button`,size:`sm`,onClick:()=>void R(),children:C(`common.save`,`Save`)}),s(_e,{type:`button`,variant:`ghost`,icon:E,onClick:L,"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(J,{type:`button`,variant:`outline`,size:`sm`,disabled:c,onClick:_,"aria-label":C(`locations.room.addTo`,{room:e}),children:C(`locations.room.add`)}),s(Ne,{items:z,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:d,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(Ve,{state:j.state,facets:j.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:j.setSearch,onToggleFacet:j.toggleFacet,onClear:j.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(q,{columns:I,rows:F,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?y:C;return i(`span`,{className:`flex items-center gap-1.5`,children:[a.length>0?i(J,{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(``),p=async e=>{let t=u.trim();l(null),!(t.length===0||t===e)&&await n(e,t)};return s(q,{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(K,{value:u,onChange:e=>d(e.target.value),onKeyDown:t=>{t.key===`Enter`&&p(e.label),t.key===`Escape`&&l(null)},onBlur:()=>void p(e.label),"aria-label":o(`locations.siteZonesPanel.rename`,`Rename {{label}}`,{label:e.label}),autoFocus:!0}):s(J,{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(J,{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(f,{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(K,{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(J,{size:`sm`,type:`submit`,disabled:c.trim().length===0||e,children:[s(j,{className:`h-3.5 w-3.5`}),n(`common.add`,`Add`)]}),s(J,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":n(`locations.newLocationButton.cancelNewLocation`,`Cancel new location`),children:s(E,{className:`h-3.5 w-3.5`})})]}):i(J,{size:`sm`,type:`button`,onClick:()=>o(!0),"data-testid":`new-location-button`,children:[s(j,{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(K,{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(J,{size:`sm`,type:`submit`,disabled:c.trim().length===0||e,children:[s(j,{className:`h-3.5 w-3.5`}),n(`common.add`,`Add`)]}),s(J,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":n(`locations.newZoneButton.cancelNewZone`,`Cancel new zone`),children:s(E,{className:`h-3.5 w-3.5`})})]}):i(J,{size:`sm`,type:`button`,onClick:()=>o(!0),"data-testid":`new-zone-button`,children:[s(j,{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=Le(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(he,{checked:y,onChange:w,"aria-label":y?u(`locations.unassignedTable.clearSelection`,`Clear selection`):u(`locations.unassignedTable.selectAllUnassignedDevices`,`Select all unassigned devices`)}),render:e=>s(he,{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(Se,{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(W,{"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:V,children:u(`locations.unassignedTable.topLevelDevicesOnlyAccessories`,`Top-level devices only — accessories move with their parent.`)})]}),e.length>0&&s(Ve,{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(W,{"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(J,{type:`button`,size:`sm`,onClick:T,disabled:o||p.length===0,children:u(`locations.unassignedTable.assign`,`Assign`)}),s(J,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>f([]),children:u(`locations.unassignedTable.clear`,`Clear`)})]}),s(q,{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:oe({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=pe(),{data:c,isLoading:l}=de(),{data:u}=be(),{data:d}=Ee(),{data:f}=Ae(),{data:p,isLoading:m}=Te({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=we({onSuccess:h}),_=De({onSuccess:h}),v=ke({onSuccess:h}),y=He({onSuccess:h}),b=ze({onSuccess:h}),x=Me({onSuccess:h}),S=We({onSuccess:h}),C=Re({onSuccess:h}),w=Oe({onSuccess:h}),T=Fe({onSuccess:h}),E=Ue(),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??[],k=n(()=>bt(D,O),[D,O]),[A,j]=Ke(),M=A.get(`tab`),N=M===`zones`||M===`camera-links`?M:`locations`,P=A.get(`room`),F=n(()=>gt(D,O),[D,O]),I=P===Lt,L=I?null:P!==null&&k.some(e=>e.name===P)?P:k[0]?.name??null,R=L===null?null:k.find(e=>e.name===L)??null,z=I?Lt:L??`__unassigned__`,B=L??k[0]?.name??null,te=n(()=>k.map(e=>({name:e.name,count:e.members.length})),[k]),ne=e=>{j(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})},oe=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`})},se=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})},ce=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})},le=async(e,t)=>{await b.mutateAsync({location:e,icon:t})},ue=async(e,t)=>{await x.mutateAsync({location:e,description:t})},U=f??[],fe=async(e,t)=>{await T.mutateAsync({location:e,zone:t})},me=(e,t)=>{for(let n of e)v.mutate({deviceId:n,location:t})},[W,G]=r(null),he=n(()=>D.filter(e=>e.parentDeviceId===null).map(e=>({id:e.id,name:e.name,type:e.type,location:e.location})),[D]),K=s(At,{rooms:te,...N===`locations`?{unassignedCount:F.length}:{},value:N===`locations`?z:B??``,unassignedValue:Lt,onChange:ne}),ge=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…`)}),K,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:me}):s(Ct,{name:R.name,members:R.members,devices:D,busy:H,icon:ut(u,ae(R.name)),onPickIcon:e=>le(R.name,e),description:at(d,ae(R.name)),onSaveDescription:e=>ue(R.name,e),zones:U,zoneKey:ct(U,ae(R.name)),onChangeZone:e=>fe(R.name,e),onRename:e=>ie(R.name,e),onDelete:()=>se(R.name,dt(D,R.name).length),onRebuildLinks:()=>oe(R.name),onAddDevices:()=>G(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:W!==null,title:e(`locations.room.addDialogTitle`,{room:W??``}),items:he,listState:m?`pending`:`answered`,lockedIds:W===null?[]:(k.find(e=>e.name===W)?.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=>{W!==null&&me(e,W),G(null)},onClose:()=>G(null)})]}),_e=i(`div`,{className:`flex flex-col gap-3`,"data-testid":`camera-links-tab`,children:[K,s(tt,{room:B,cameras:B===null?[]:dt(D,B).filter(e=>e.isCamera),fleet:D})]});return s(Je,{icon:ee,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:ge},{id:`camera-links`,label:e(`locations.cameraLinks`,`Camera links`),content:_e},{id:`zones`,label:e(`locations.zones`,`Zones`),content:s(Et,{zones:U,busy:H,onRename:(e,t)=>w.mutateAsync({from:e,to:t}),onDelete:ce,onPickIcon:(e,t)=>S.mutateAsync({name:e,icon:t})})}]})}export{Rt as LocationsPage};
@@ -1 +0,0 @@
1
- import{$ as e,B as t,G as n,J as r,L as i,S as a,b as o,o as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Gr as l,Ir as u,It as d,Nt as f,Oi as p,Sr as m,Y as h,Yr as g,ci as _,dt as v,na as y,or as b,ot as x}from"./player-overlays-BQ-CPD3k.js";import{Xi as S}from"./client-C7mYZlqO.js";import{n as C,t as w}from"./scissors-CfXjajAo.js";import{$n as T,Al as E,Ar as D,Cl as O,Dl as k,Ec as A,El as j,Fl as M,Gs as N,Il as ee,Jr as P,Ll as te,Ml as ne,Nl as re,Ol as ie,Pl as ae,Qn as oe,Sc as se,Tr as ce,Us as le,Xu as F,Ya as I,Ys as ue,Zr as de,Zs as fe,_n as pe,dl as me,er as he,fl as ge,gl as _e,gn as L,gr as R,hl as ve,hr as z,ir as ye,jl as be,kl as xe,ll as Se,ml as Ce,nr as we,pl as Te,pr as B,qu as Ee,rr as De,ul as V,wl as H,xl as Oe}from"./src-DP8JO4HZ.js";import{t as U}from"./i18n-CiEPJn04.js";import{t as W}from"./useTranslation-D3Is_4B6.js";import{T as ke,Z as Ae,j as je}from"./index-B-H1mfMz.js";import{t as Me}from"./AdminSectionedPage-DorUtSBh.js";import{n as Ne}from"./authed-media-CRjjClqw.js";import{t as G}from"./format-size-DIxKXxtj.js";import{c as Pe,i as Fe,l as Ie,n as Le,o as Re,r as ze,s as Be,t as Ve,u as He}from"./location-owned-usage-DwnxDZWp.js";e();var Ue=[{value:`all`,labelKey:`common.all`},{value:`recording`,labelKey:`recordings.activitySection.domainRecordings`},{value:`events`,labelKey:`common.events`}],We={recording:`bg-primary/10 text-primary`,events:`bg-violet-500/10 text-violet-400`},Ge={columnKey:`at`,dir:`desc`};function Ke(e){return new Date(e).toLocaleString()}function qe(){let{t:e,i18n:t}=W(),[i,s]=r(`all`),{data:l,isLoading:u,isError:d}=me({},{refetchOnWindowFocus:!1}),{data:p,isLoading:m,isError:h}=ue({},{refetchOnWindowFocus:!1}),{data:g}=I({isCamera:!0,projection:`slim`}),_=n(()=>{let e=new Map;for(let t of g??[])e.set(t.id,t.name);return e},[g]),v=n(()=>{let e=[...l??[],...p??[]];return(i===`all`?e:e.filter(e=>e.domain===i)).toSorted((e,t)=>t.at-e.at)},[l,p,i]),x=n(()=>{let t=[];return d&&i!==`events`&&t.push(e(`recordings.activitySection.domainRecordings`)),h&&i!==`recording`&&t.push(e(`common.events`)),t},[d,h,i,e]),S=n(()=>new Intl.ListFormat(t.language,{type:`conjunction`}).format(x),[x,t.language]),C=n(()=>[{key:`at`,header:e(`recordings.activitySection.when`,`When`),nowrap:!0,sortValue:e=>e.at,render:e=>c(`span`,{className:`text-foreground-subtle tabular-nums`,children:Ke(e.at)})},{key:`domain`,header:e(`recordings.activitySection.domain`,`Domain`),sortValue:e=>e.domain,render:e=>c(`span`,{className:`inline-flex rounded px-1.5 py-0.5 text-[10px] font-medium ${We[e.domain]}`,children:e.domain})},{key:`op`,header:e(`recordings.activitySection.operation`,`Operation`),sortValue:e=>e.op,render:e=>c(`span`,{className:`text-foreground`,children:e.op})},{key:`reason`,header:e(`recordings.activitySection.reason`,`Reason`),sortValue:e=>e.reason,render:e=>c(`span`,{className:`text-foreground-subtle`,children:e.reason})},{key:`device`,header:e(`recordings.activitySection.camera`,`Camera`),sortValue:e=>e.deviceId===null?`cluster`:_.get(e.deviceId)??`#${String(e.deviceId)}`,render:t=>t.deviceId===null?c(`span`,{className:`text-foreground-subtle`,children:e(`common.cluster`)}):c(`span`,{className:`text-foreground`,children:_.get(t.deviceId)??`#${String(t.deviceId)}`})},{key:`items`,header:e(`recordings.activitySection.items`,`Items`),align:`right`,nowrap:!0,sortValue:e=>e.itemsAffected,render:e=>c(`span`,{className:`tabular-nums`,children:e.itemsAffected.toLocaleString()})},{key:`bytes`,header:e(`recordings.activitySection.reclaimed`,`Reclaimed`),align:`right`,nowrap:!0,sortValue:e=>e.bytesReclaimed,render:e=>c(`span`,{className:`tabular-nums`,children:e.bytesReclaimed>0?G(e.bytesReclaimed):`—`})}],[_,e]),w=u||m;return a(`div`,{className:`flex flex-col gap-4`,children:[c(`div`,{className:`flex items-center gap-1`,children:Ue.map(t=>c(`button`,{onClick:()=>s(t.value),className:`rounded px-2 py-1 text-xs font-medium ${i===t.value?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-muted`}`,children:e(t.labelKey)},t.value))}),w&&v.length===0?a(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[c(b,{className:`h-4 w-4 animate-spin`}),e(`recordings.activitySection.loadingActivity`,`Loading activity…`)]}):v.length===0?x.length>0?c(B,{icon:f,title:e(`recordings.activitySection.activityCouldNotBeRead`,`Activity could not be read`),description:e(`recordings.activitySection.theOpsLogDidNot`,`The {{value1}} ops log did not answer. This is not "nothing happened" — retry, or check the node that owns it.`,{value1:S})}):c(B,{icon:y,title:e(`recordings.activitySection.noActivityYet`,`No activity yet`),description:e(`recordings.activitySection.pruneDeleteAndRescanOperations`,`Prune, delete and rescan operations across recordings and events show up here.`)}):a(o,{children:[x.length>0&&a(`p`,{className:`flex items-center gap-1.5 text-[11px] text-amber-500`,children:[c(f,{className:`h-3 w-3 shrink-0`}),e(`recordings.activitySection.domainsMissing`,{count:x.length,names:S})]}),c(L,{columns:C,rows:v,rowKey:e=>e.id,minWidthPx:720,maxBodyHeight:pe,defaultSort:Ge})]})]})}e();function Je(){let{t:e}=W(),t=I({isCamera:!0,projection:`slim`}),i=n(()=>(t.data??[]).toSorted((e,t)=>e.name.localeCompare(t.name)),[t.data]),[o,s]=r(null),l=o??i[0]?.id??null;return!t.isLoading&&i.length===0?c(B,{icon:p,title:e(`recordings.cameraRecordingSettingsSection.noCameras`,`No cameras`),description:e(`recordings.cameraRecordingSettingsSection.addACameraFirst`,`Add a camera first.`)}):a(`div`,{className:`space-y-3`,children:[a(`div`,{children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`recordings.cameraRecordingSettingsSection.perCameraRecordingRetention`,`Per-camera recording & retention`)}),c(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:e(`recordings.cameraRecordingSettingsSection.recordingModeScheduleBandsAnd`,`Recording mode, schedule bands and the retention policy for one camera — the same controls as the camera's own Recording tab. Retention is one policy over footage and analytics; per-camera event deletion lives on the Events tab.`)})]}),a(`div`,{className:`flex items-center gap-2`,children:[c(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e(`recordings.cameraRecordingSettingsSection.camera`,`Camera`)}),c(`select`,{value:l??``,onChange:e=>s(Number(e.target.value)),className:`rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,children:i.map(e=>c(`option`,{value:e.id,children:e.name},e.id))})]}),l!==null&&c(ce,{deviceId:l,children:c(je,{deviceId:l,sectionFilter:e=>e.location===`top-tab`&&e.tab===`recording`})},l)]})}e();function Ye({types:e}){let{t}=W(),i=s(),o=D(),{data:l}=H({}),u=O(),d=n(()=>u.data??[],[u.data]),{data:f}=V({},{refetchOnWindowFocus:!1}),p=n(()=>Ve(l??[],f?.locations),[l,f?.locations]),[m,h]=r(null),[g,_]=r(null),v=()=>{i.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})},y=te({onSuccess:v}),b=Oe({onSuccess:v}),x=n(()=>{let e=new Map;for(let t of l??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[l]),S=async(e,n)=>{Ie(n)&&!await o({title:t(`pipeline.storageLocationsPanel.disable`,`Disable "{{displayName}}"?`,{displayName:e.displayName}),message:t(`pipeline.storageLocationsPanel.nothingIsDeletedSetThe`,`{{consequence}} Nothing is deleted — set the location back to Read-only or Active to bring its footage back.`,{consequence:Pe(n).consequence}),confirmLabel:t(`common.disable`,`Disable`),variant:`danger`})||y.mutate(Be(e,{mode:n}))},C=async e=>{if(await o({title:t(`pipeline.storageLocationsPanel.deleteLocation`,`Delete location "{{displayName}}"?`,{displayName:e.displayName}),message:t(`pipeline.storageLocationsPanel.removesTheRecordFilesOn`,`Removes the record; files on disk are untouched.`),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`}))try{await b.mutateAsync({id:e.id})}catch(n){await o({title:t(`pipeline.storageLocationsPanel.deleteAnyway`,`Delete anyway?`),message:t(`pipeline.storageLocationsPanel.forcingNote`,{error:n instanceof Error?n.message:String(n)}),confirmLabel:t(`pipeline.storageLocationsPanel.forceDelete`,`Force delete`),variant:`danger`})&&b.mutate({id:e.id,force:!0})}},w=e.map(e=>d.find(t=>t.id===e)).filter(e=>e!==void 0);return a(`div`,{className:`space-y-3`,children:[w.length===0?c(`p`,{className:`text-[11px] text-foreground-subtle italic`,children:t(`pipeline.storageLocationsPanel.noStorageLocationsDeclaredFor`,`No storage locations declared for this purpose.`)}):w.map(e=>c(Le,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:x.get(e.id)??[],onAdd:e=>h(e),onEdit:e=>_(e),onDelete:e=>{C(e)},ownedBytesById:p,onSetMode:(e,t)=>{S(e,t)}},e.id)),m!==null&&c(He,{initialType:m,onClose:()=>h(null),onCreated:()=>{v(),h(null)}}),g!==null&&c(Re,{location:g,onClose:()=>_(null),onSaved:()=>{v(),_(null)}})]})}e();var Xe=`pipeline-analytics`;function Ze(e){for(let t of e?.sections??[])for(let e of t.fields??[])if(e.key===`postProcessingNodeId`&&typeof e.value==`string`)return e.value;return`hub`}function Qe(){let{t:e}=W(),t=s(),{nodes:r}=Ee(),{data:i,isLoading:o}=P({addonId:Xe}),l=Ze(i),u=de({onSuccess:()=>{t.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),d=n(()=>{let e=r.filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,l,...e])].filter(Boolean)},[r,l]);return a(`div`,{className:`flex flex-col gap-6`,children:[a(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[c(`h3`,{className:`text-sm font-semibold text-foreground`,children:e(`pipeline.clusterEventsTab.postProcessingNode`,`Post-processing node`)}),c(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:e(`pipeline.clusterEventsTab.theSingleNodeThatRuns`,`The single node that runs detection post-processing (events, media, audio & motion). Every other node stays inert — no multi-node balancing. Takes effect on addon restart.`)}),a(`div`,{className:`mt-3 flex items-center gap-2`,children:[o?c(b,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):c(`select`,{value:l,onChange:e=>{e.target.value!==l&&u.mutate({addonId:Xe,patch:{postProcessingNodeId:e.target.value}})},disabled:u.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:d.map(t=>c(`option`,{value:t,children:t===`hub`?e(`pipeline.clusterEventsTab.hubDefault`,`hub (default)`):t},t))}),u.isPending&&c(b,{className:`h-4 w-4 animate-spin text-primary`})]})]}),a(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[c(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:e(`pipeline.clusterEventsTab.eventsFolder`,`Events folder`)}),c(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:e(`pipeline.clusterEventsTab.whereEventCropsFullFrames`,`Where event crops / full frames are stored. A single folder — no collection / equal-splitting.`)}),c(Ye,{types:[`eventMedia`]})]})]})}e();var $e=[[`pipelineAnalytics`]],et=1440*60*1e3;function tt(e,t){return t.get(e)??U.t(`recordings.eventsManagementSection.removedCamera`,{id:String(e)})}var nt=[{days:1},{days:7},{days:30},{days:90}];function rt(){let{t:e}=W(),t=s(),o=D(),[l,u]=r(30),[f,p]=r(null),{data:m,isLoading:_}=N({},{refetchOnWindowFocus:!1}),{data:v}=I({isCamera:!0,projection:`slim`}),y=n(()=>{let e=new Map;for(let t of v??[])e.set(t.id,t.name);return e},[v]),x=i(()=>{t.invalidateQueries({queryKey:$e})},[t]),S=fe({onSuccess:x}),C=le(),T=i(async()=>{await o({title:e(`recordings.eventsManagementSection.pruneTitle`,{count:l}),message:e(`recordings.eventsManagementSection.permanentlyDeletesEveryEventMotion`,`Permanently deletes every event (motion / object / audio) older than the cutoff across all cameras, and their media. This cannot be undone.`),confirmLabel:e(`recordings.eventsManagementSection.pruneEvents`,`Prune events`),variant:`danger`})&&S.mutate({olderThanMs:Date.now()-l*et,reason:`retention`})},[o,S,l,e]),E=i(async t=>{let n=tt(t.deviceId,y);if(await o({title:e(`recordings.eventsManagementSection.deleteAllEventsFor`,`Delete all events for {{label}}?`,{label:n}),message:e(`recordings.eventsManagementSection.deleteRowsMessage`,{count:t.rows,size:G(t.bytes)}),confirmLabel:e(`recordings.eventsManagementSection.deleteEvents`,`Delete events`),variant:`danger`})){p(null);try{let e=await C.mutateAsync({deviceId:t.deviceId});x();let r=e.motion+e.object+e.audio;if(r===0&&t.bytes>0){p(`0 events deleted for ${n}. Media still listed (${G(t.bytes)}) — those blobs are not event rows; use Management → Count leftovers or Disk reconcile.`);return}p(`Deleted ${String(r)} event${r===1?``:`s`} for ${n}.`)}catch(e){p(e instanceof Error?e.message:String(e))}}},[o,C,y,x,e]),O=n(()=>[{key:`camera`,header:e(`recordings.eventsManagementSection.camera`,`Camera`),render:e=>c(`span`,{className:`text-foreground`,children:tt(e.deviceId,y)})},{key:`rows`,header:e(`recordings.eventsManagementSection.events`,`Events`),align:`right`,nowrap:!0,render:e=>c(`span`,{className:`tabular-nums`,children:e.rows.toLocaleString()})},{key:`bytes`,header:e(`recordings.eventsManagementSection.media`,`Media`),align:`right`,nowrap:!0,render:e=>c(`span`,{className:`tabular-nums`,children:G(e.bytes)})},{key:`actions`,header:``,align:`right`,render:t=>a(`button`,{onClick:()=>{E(t)},disabled:C.isPending,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(`recordings.eventsManagementSection.deleteAllEventsForThis`,`Delete all events for this camera`),children:[c(d,{className:`h-3 w-3`}),e(`common.delete`,`Delete`)]})}],[y,E,C.isPending,e]);return _&&!m?a(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[c(b,{className:`h-4 w-4 animate-spin`}),e(`recordings.eventsManagementSection.loadingEventStoreFootprint`,`Loading event-store footprint…`)]}):m?a(`div`,{className:`flex flex-col gap-6`,children:[a(`section`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[c(h,{label:e(`recordings.eventsManagementSection.totalEvents`,`Total events`),icon:c(g,{className:`h-3 w-3`}),footer:`across ${String(m.devices.length)} camera${m.devices.length===1?``:`s`}`,children:m.totalRows.toLocaleString()}),c(h,{label:e(`recordings.eventsManagementSection.eventMediaOnDisk`,`Event media on disk`),children:G(m.totalBytes)})]}),a(`section`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[c(`span`,{className:`text-foreground-subtle`,children:e(`recordings.eventsManagementSection.pruneEventsOlderThan`,`Prune events older than`)}),c(`select`,{value:l,onChange:e=>u(Number(e.target.value)),className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:nt.map(t=>c(`option`,{value:t.days,children:e(`recordings.eventsManagementSection.ageDays`,{count:t.days})},t.days))}),a(`button`,{onClick:()=>{T()},disabled:S.isPending,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-xs font-medium text-foreground-subtle hover:bg-warning/10 hover:text-warning disabled:opacity-50`,children:[S.isPending?c(b,{className:`h-3 w-3 animate-spin`}):c(w,{className:`h-3 w-3`}),e(`recordings.eventsManagementSection.pruneNow`,`Prune now`)]})]}),m.devices.length===0?c(B,{icon:g,title:e(`recordings.eventsManagementSection.noStoredEvents`,`No stored events`),description:e(`recordings.eventsManagementSection.noCameraHasPersistedEvents`,`No camera has persisted events yet.`)}):c(L,{columns:O,rows:[...m.devices],rowKey:e=>e.deviceId,minWidthPx:480}),f===null?null:c(`p`,{className:f.startsWith(`Deleted `)?`text-[11px] text-foreground-subtle`:`text-[11px] text-destructive`,children:f})]}):c(B,{icon:g,title:e(`recordings.eventsManagementSection.noEventData`,`No event data`),description:e(`recordings.eventsManagementSection.pipelineAnalyticsHasNotReported`,`Pipeline analytics has not reported any event-store footprint yet.`)})}function it(){let{t:e}=W();return a(`div`,{className:`flex flex-col gap-8`,children:[a(`div`,{children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`recordings.eventsSection.eventStore`,`Event store`)}),c(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:e(`recordings.eventsSection.whatTheDurableEventStore`,`What the durable event store occupies, per camera, with fleet-wide prune-by-age and delete-all-events.`)}),c(`div`,{className:`mt-3`,children:c(rt,{})})]}),a(`div`,{children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`recordings.eventsSection.postProcessingNodeFolders`,`Post-processing node & folders`)}),c(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:e(`recordings.eventsSection.theSingleNodeThatWrites`,`The single node that writes event crops, and the storage location they land in.`)}),c(`div`,{className:`mt-3`,children:c(Qe,{})})]})]})}function at(e){let t=[];return e.timelapse?t.push(`timelapse ${String(e.timelapse.everyMs/1e3)}s`):(t.push(`${String(e.speed??1)}×`),e.includeAudio&&t.push(`+ audio`)),t.join(` `)}function ot(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}function st(e,t){let n=Math.max(0,Math.round((t-e)/1e3)),r=Math.floor(n/3600),i=Math.floor(n%3600/60),a=n%60,o=r>0?`${String(r)}:${String(i).padStart(2,`0`)}:${String(a).padStart(2,`0`)}`:`${String(i)}:${String(a).padStart(2,`0`)}`;return`${ot(e)} · ${o}`}function ct(e,t){let n=e-t;if(n<=0)return U.t(`helpers.exportFormat.expired`);let r=Math.floor(n/6e4);if(r<60)return U.t(`helpers.exportFormat.inMinutes`,{n:String(r)});let i=Math.floor(r/60);return i<24?U.t(`helpers.exportFormat.inHours`,{n:String(i)}):U.t(`helpers.exportFormat.inDays`,{n:String(Math.floor(i/24))})}function lt(e,t,n,r){return e.map(e=>{if(e.state===`expired`||e.state===`deleted`)return e;let i=r.get(e.id);if(i)return{...e,state:`failed`,error:i.error,progressPct:null};let a=n.get(e.id);if(a)return{...e,state:`ready`,fileBytes:a.fileBytes,progressPct:100};let o=t.get(e.id);return o&&(e.state===`queued`||e.state===`rendering`)?{...e,state:`rendering`,progressPct:o.progressPct}:e})}e();var ut=[`high`,`mid`,`low`],dt=[{value:1,labelKey:`recordings.newExportModal.speedRealTime`},{value:2,labelKey:null},{value:4,labelKey:null},{value:8,labelKey:null},{value:16,labelKey:null}],ft=10080*60*1e3;function K(e){let t=new Date(Date.now()-e*6e4),n=e=>String(e).padStart(2,`0`);return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}T${n(t.getHours())}:${n(t.getMinutes())}`}function pt({onClose:e,onCreated:t}){let{t:i}=W(),o=I({isCamera:!0,projection:`slim`}),s=n(()=>(o.data??[]).toSorted((e,t)=>e.name.localeCompare(t.name)),[o.data]),[l,d]=r(``),[f,p]=r(`high`),[m,h]=r(K(60)),[g,_]=r(K(0)),[v,y]=r(1),[b,x]=r(!0),[S,C]=r(``),[w,E]=r(null),D=l===``?s[0]?.id??null:l,O=new Date(m).getTime(),k=new Date(g).getTime(),A=Number.isFinite(O)&&Number.isFinite(k)&&O<k,j=Ce({onSuccess:()=>{t(),e()},onError:e=>E(e instanceof Error?e.message:String(e))});return c(oe,{open:!0,onOpenChange:t=>!t&&e(),children:a(he,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[c(De,{children:a(ye,{className:`flex items-center gap-1.5`,children:[c(u,{className:`h-3.5 w-3.5`}),i(`recordings.newExportModal.newExport`,`New export`)]})}),a(T,{className:`space-y-3`,children:[a(`div`,{className:`grid grid-cols-2 gap-3`,children:[a(`div`,{className:`space-y-1`,children:[c(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:i(`recordings.newExportModal.camera`,`Camera`)}),c(`select`,{value:D??``,onChange:e=>d(Number(e.target.value)),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,children:s.map(e=>c(`option`,{value:e.id,children:e.name},e.id))})]}),a(`div`,{className:`space-y-1`,children:[c(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:i(`recordings.newExportModal.profile`,`Profile`)}),c(`select`,{value:f,onChange:e=>p(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,children:ut.map(e=>c(`option`,{value:e,children:e},e))})]})]}),a(`div`,{className:`grid grid-cols-2 gap-3`,children:[a(`div`,{className:`space-y-1`,children:[c(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:i(`recordings.newExportModal.from`,`From`)}),c(`input`,{type:`datetime-local`,value:m,onChange:e=>h(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`})]}),a(`div`,{className:`space-y-1`,children:[c(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:i(`recordings.newExportModal.to`,`To`)}),c(`input`,{type:`datetime-local`,value:g,onChange:e=>_(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`})]})]}),a(`div`,{className:`grid grid-cols-2 gap-3`,children:[a(`div`,{className:`space-y-1`,children:[c(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:i(`recordings.newExportModal.speed`,`Speed`)}),c(`select`,{value:v,onChange:e=>y(Number(e.target.value)),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,children:dt.map(e=>c(`option`,{value:e.value,children:e.labelKey===null?`${e.value}×`:i(e.labelKey)},e.value))})]}),a(`div`,{className:`space-y-1`,children:[c(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:i(`recordings.newExportModal.titleOptional`,`Title (optional)`)}),c(`input`,{type:`text`,value:S,onChange:e=>C(e.target.value),placeholder:i(`recordings.newExportModal.eGCourierAtThe`,`e.g. courier at the gate`),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle`})]})]}),a(`label`,{className:`flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[c(`input`,{type:`checkbox`,checked:b,disabled:v!==1,onChange:e=>x(e.target.checked),className:`accent-primary`}),i(v===1?`recordings.newExportModal.includeAudio`:`recordings.newExportModal.includeAudioRealtimeOnly`)]}),!A&&c(`p`,{className:`text-[11px] text-danger`,children:i(`recordings.newExportModal.fromMustBeBeforeTo`,`"From" must be before "To".`)}),w&&c(`p`,{className:`text-[11px] text-danger`,children:w})]}),a(we,{children:[c(z,{variant:`outline`,size:`sm`,onClick:e,children:i(`common.cancel`,`Cancel`)}),c(z,{size:`sm`,onClick:()=>{if(D===null||!A)return;E(null);let e=S.trim();j.mutate({deviceId:D,profile:f,fromMs:O,toMs:k,options:{includeAudio:b,maxLifeMs:ft,deleteAfterDownload:!1,...v===1?{}:{speed:v},...e.length>0?{title:e}:{}}})},disabled:D===null||!A||j.isPending,children:j.isPending?i(`recordings.newExportModal.queuing`,`Queuing…`):i(`recordings.newExportModal.createExport`,`Create export`)})]})]})})}e();var mt=[[`recordingExport`]],ht={queued:{cls:`bg-muted text-foreground-subtle`,labelKey:`recordings.exportsSection.queued`},rendering:{cls:`bg-primary/10 text-primary`,labelKey:`recordings.exportsSection.rendering`,spin:!0},ready:{cls:`bg-success/10 text-success`,labelKey:`recordings.exportsSection.ready`},failed:{cls:`bg-danger/10 text-danger`,labelKey:`recordings.exportsSection.failed`},expired:{cls:`bg-muted text-foreground-subtle`,labelKey:`recordings.exportsSection.expired`},deleted:{cls:`bg-muted text-foreground-subtle`,labelKey:`recordings.exportsSection.deleted`}};function gt(){let{data:e,isLoading:t}=_e({},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`queued`||e.state===`rendering`)?3e3:!1}),{map:r}=F(S.RecordingExportProgress,e=>e.exportId),{map:i}=F(S.RecordingExportCompleted,e=>e.exportId),{map:a}=F(S.RecordingExportFailed,e=>e.exportId);return{rows:n(()=>lt(e??[],r,i,a),[e,r,i,a]),isLoading:t}}function _t(e){let[n,i]=r(()=>Date.now());return t(()=>{let t=setInterval(()=>i(Date.now()),e);return()=>clearInterval(t)},[e]),n}function vt(){let{t:e}=W(),t=s(),[o,f]=r(!1),p=()=>{t.invalidateQueries({queryKey:[[`recordingExport`,`listExports`]]})},m=D(),h=x().trpcClient,g=_t(6e4),{rows:v,isLoading:y}=gt(),{data:S}=I({isCamera:!0,projection:`slim`}),C=n(()=>{let e=new Map;for(let t of S??[])e.set(t.id,t.name);return e},[S]),w=i(()=>{t.invalidateQueries({queryKey:mt})},[t]),T=Te({onSuccess:w}),E=ve({onSuccess:w}),[O,k]=r(null),A=i(async e=>{k(e.id);try{let{url:t}=await h.recordingExport.getDownloadUrl.query({exportId:e.id}),n=await Ne(t),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.options.title??e.id}.mp4`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r),w()}finally{k(null)}},[h,w]),j=i(async t=>{await m({title:e(`recordings.exportsSection.cancelThisExport`,`Cancel this export?`),message:e(`recordings.exportsSection.stopsTheRenderThePartial`,`Stops the render. The partial file is discarded.`),confirmLabel:e(`recordings.exportsSection.cancelExport`,`Cancel export`),variant:`danger`})&&T.mutate({exportId:t.id})},[m,T,e]),M=i(async t=>{await m({title:e(`recordings.exportsSection.deleteThisExport`,`Delete this export?`),message:e(`recordings.exportsSection.permanentlyRemovesTheRenderedFile`,`Permanently removes the rendered file and its history row.`),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&E.mutate({exportId:t.id})},[m,E,e]),N=n(()=>[{key:`camera`,header:e(`recordings.exportsSection.camera`,`Camera`),render:e=>c(`span`,{className:`text-foreground`,children:C.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`range`,header:e(`recordings.exportsSection.range`,`Range`),nowrap:!0,render:e=>c(`span`,{className:`tabular-nums`,children:st(e.fromMs,e.toMs)})},{key:`variant`,header:e(`recordings.exportsSection.variant`,`Variant`),render:e=>c(`span`,{className:`text-foreground-subtle`,children:at(e.options)})},{key:`state`,header:e(`recordings.exportsSection.state`,`State`),render:t=>{let n=ht[t.state];return a(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${n.cls}`,children:[n.spin&&c(b,{className:`h-2.5 w-2.5 animate-spin`}),e(n.labelKey),t.state===`rendering`&&t.progressPct!==null&&a(`span`,{className:`tabular-nums`,children:[t.progressPct,`%`]})]})}},{key:`expiry`,header:e(`recordings.exportsSection.expires`,`Expires`),nowrap:!0,render:e=>e.state===`deleted`?c(`span`,{className:`text-foreground-subtle`,children:`—`}):c(`span`,{className:`text-foreground-subtle tabular-nums`,children:ct(e.expiresAt,g)})},{key:`size`,header:e(`recordings.exportsSection.size`,`Size`),align:`right`,nowrap:!0,render:e=>c(`span`,{className:`tabular-nums`,children:e.fileBytes===null?`—`:G(e.fileBytes)})},{key:`actions`,header:``,align:`right`,render:t=>{let n=t.state===`ready`,r=t.state===`queued`||t.state===`rendering`,i=t.state!==`deleted`;return a(`div`,{className:`flex items-center justify-end gap-1`,children:[n&&a(`button`,{onClick:()=>{A(t)},disabled:O===t.id,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-primary/10 hover:text-foreground disabled:opacity-50`,title:e(`recordings.exportsSection.downloadMp4`,`Download MP4`),children:[O===t.id?c(b,{className:`h-3 w-3 animate-spin`}):c(l,{className:`h-3 w-3`}),e(`recordings.exportsSection.download`,`Download`)]}),r&&a(`button`,{onClick:()=>{j(t)},disabled:T.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-amber-500/10 hover:text-amber-500 disabled:opacity-50`,title:e(`recordings.exportsSection.cancelRender`,`Cancel render`),children:[c(_,{className:`h-3 w-3`}),e(`common.cancel`,`Cancel`)]}),i&&c(`button`,{onClick:()=>{M(t)},disabled:E.isPending,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(`recordings.exportsSection.deleteExport`,`Delete export`),children:c(d,{className:`h-3 w-3`})})]})}}],[C,g,O,T.isPending,E.isPending,A,j,M,e]);return y&&v.length===0?a(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[c(b,{className:`h-4 w-4 animate-spin`}),e(`recordings.exportsSection.loadingExports`,`Loading exports…`)]}):a(`div`,{className:`space-y-3`,children:[c(`div`,{className:`flex justify-end`,children:a(`button`,{onClick:()=>f(!0),className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground`,children:[c(u,{className:`h-3.5 w-3.5`}),e(`recordings.exportsSection.newExport`,`New export`)]})}),v.length===0?c(B,{icon:u,title:e(`recordings.exportsSection.noExportsYet`,`No exports yet`),description:e(`recordings.exportsSection.createOneHereNewExport`,`Create one here (New export) or from a camera's timeline in the viewer. Rendered clips show up here to download or manage.`)}):c(L,{columns:N,rows:v,rowKey:e=>e.id,minWidthPx:720}),o&&c(pt,{onClose:()=>f(!1),onCreated:p})]})}var yt=`inline-flex w-fit items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`;e();var bt=`storage-migration`,xt=new Set([`orphans`,`debug-media`,`ghost-ledger`]);function St(e){return[`${e.orphansReclaimed} orphan rows (${G(e.orphanBytesReclaimed)})`,e.includeDebugMedia?`${e.debugMediaReclaimed} debug files (${G(e.debugMediaBytesReclaimed)})`:null,`${e.ghostsForgotten} ghost rows (${G(e.ghostBytesForgotten)})`].filter(e=>e!==null).join(` · `)}function Ct(){let{t:e}=W(),t=R(bt);return t===`pending`?null:t===`unknown`?c(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:e(`recordings.cleanupSection.couldNotCheckWhetherStorage`,`Could not check whether storage cleanup is installed on this hub.`)}):t===`present`?c(wt,{}):null}function wt(){let{t:e}=W(),t=D(),[n,i]=r(!1),[o,s]=r(null),l=xe({},{refetchInterval:2e3}),u=l.data??null,f=u!==null&&xt.has(u.phase),p=ie(),m=k(),h=async()=>{if(await t({title:e(`recordings.cleanupSection.runStorageCleanup`,`Run storage cleanup?`),message:n?e(`recordings.cleanupSection.reclaimsLeftoverAnalyticsRowsAnd`,`Reclaims leftover analytics rows and files, debug stills/filmstrips, and ghost footage rows on frozen locations. Safe to re-run.`):e(`recordings.cleanupSection.reclaimsLeftoverAnalyticsRowsAnd2`,`Reclaims leftover analytics rows and files, and ghost footage rows on frozen locations. Debug stills are left alone. Safe to re-run.`),confirmLabel:e(`recordings.cleanupSection.runCleanup`,`Run cleanup`),variant:`danger`})){s(null);try{await p.mutateAsync({includeDebugMedia:n}),await l.refetch()}catch(e){s(e instanceof Error?e.message:String(e))}}},g=async()=>{if(u&&await t({title:e(`recordings.cleanupSection.cancelCleanup`,`Cancel cleanup?`),message:e(`recordings.cleanupSection.stopsAfterTheCurrentStep`,`Stops after the current step. Work already done stays done.`),confirmLabel:e(`recordings.cleanupSection.cancelCleanup2`,`Cancel cleanup`),variant:`danger`}))try{await m.mutateAsync({jobId:u.jobId}),await l.refetch()}catch{}};return a(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`recordings.cleanupSection.cleanup`,`Cleanup`)}),c(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:e(`recordings.cleanupSection.onePassOverLeftoverAnalytics`,`One pass over leftover analytics (database + files) and ghost footage rows on frozen locations. Does not time out — progress updates here until it finishes.`)}),a(`label`,{className:`mt-3 flex items-start gap-2 text-[11px] text-foreground`,children:[c(`input`,{type:`checkbox`,checked:n,disabled:f,onChange:e=>{i(e.target.checked)},className:`mt-0.5 h-3.5 w-3.5 accent-primary`}),c(`span`,{children:e(`recordings.cleanupSection.alsoRemoveDebugMediaMotion`,`Also remove debug media (motion stills and track filmstrips)`)})]}),a(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[a(`button`,{type:`button`,disabled:f||p.isPending,onClick:()=>{h()},className:yt,children:[(f||p.isPending)&&c(b,{className:`h-3 w-3 animate-spin`}),c(d,{className:`h-3 w-3`}),e(`recordings.cleanupSection.runCleanup`,`Run cleanup`)]}),f&&c(`button`,{type:`button`,onClick:()=>{g()},className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10`,children:e(`common.cancel`,`Cancel`)})]}),o&&c(`p`,{className:`mt-2 text-[11px] text-danger`,children:o}),u&&a(`div`,{className:`mt-3 space-y-1 rounded-md border border-border px-2.5 py-2`,children:[a(`p`,{className:`text-xs text-foreground`,children:[e(`recordings.cleanupSection.phase`,`Phase:`),` `,c(`span`,{className:`font-medium`,children:u.phase}),f&&c(b,{className:`ml-2 inline h-3 w-3 animate-spin text-primary`})]}),u.detail&&c(`p`,{className:`text-[11px] text-foreground-subtle`,children:u.detail}),c(`p`,{className:`text-[11px] text-foreground-subtle`,children:St(u)}),u.error&&c(`p`,{className:`text-[11px] text-danger`,children:u.error})]})]})}e();var Tt=2e3;function Et(){let{t:e}=W(),n=D(),r=s(),i=A(),o=se(void 0,{refetchInterval:e=>e.state.data?.state===`running`?Tt:!1}),l=o.data,u=l?.state===`running`,d=u||i.isPending;t(()=>{l?.state!==`done`||l.finishedAtMs===null||(r.invalidateQueries({queryKey:[[`recording`]]}),r.invalidateQueries({queryKey:[[`pipelineAnalytics`]]}))},[l?.state,l?.finishedAtMs,r]);let f=async()=>{await n({title:e(`recordings.diskReconcileSection.reconcileStorageFromDisk`,`Reconcile storage from disk?`),message:e(`recordings.diskReconcileSection.makesTheDatabaseMatchThe`,`Makes the database match the filesystem: recordings index, tracks, events and media whose files are gone. Favourited tracks without files are deleted. Snapshot-less motion/audio events are deleted. Enrolled identities stay. This cannot be undone.`),confirmLabel:e(`recordings.diskReconcileSection.reconcile`,`Reconcile`),variant:`warning`})&&(await i.mutateAsync(),await o.refetch())},p=u?l.total>0?`Reconciling ${String(l.completed)}/${String(l.total)}…`:`Reconciling…`:i.isPending?`Reconciling…`:`Reconcile from disk`;return a(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[c(`h3`,{className:`text-sm font-semibold text-foreground`,children:e(`recordings.diskReconcileSection.diskReconcile`,`Disk reconcile`)}),c(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:e(`recordings.diskReconcileSection.deletesDatabaseRowsWhoseFiles`,`Deletes database rows whose files are gone. Enrolled identities stay.`)}),a(`div`,{className:`mt-3 flex flex-col gap-2`,children:[a(`button`,{type:`button`,onClick:()=>void f(),disabled:d,className:`inline-flex w-fit items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[d?c(b,{className:`h-3.5 w-3.5 animate-spin`}):c(m,{className:`h-3.5 w-3.5`}),p]}),l?.state===`done`?a(`p`,{className:`text-[11px] text-foreground-subtle`,children:[e(`recordings.diskReconcileSection.lastRun`,`Last run:`),` `,e(`recordings.diskReconcileSection.summary`,{completed:String(l.completed),tracks:String(l.tracks),events:String(l.events),media:String(l.mediaDropped)}),l.failed.length>0?e(`recordings.diskReconcileSection.failed`,`, {{value1}} failed ({{value2}})`,{value1:String(l.failed.length),value2:l.failed.join(`, `)}):``,`.`]}):null,l?.state===`error`&&l.error!==null?a(`p`,{className:`text-[11px] text-destructive`,children:[e(`recordings.diskReconcileSection.reconcileFailed`,`Reconcile failed:`),` `,l.error]}):null]})]})}var q=1e3,J=60*q,Y=60*J;function X(e){return e.toLocaleString(`en-US`)}function Dt(e){if(!Number.isFinite(e)||e<0)return`—`;if(e>=Y){let t=Math.floor(e/Y),n=Math.round(e%Y/J);return`${t.toString()}h ${n.toString()}m`}if(e>=J){let t=Math.floor(e/J),n=Math.round(e%J/q);return`${t.toString()}m ${n.toString()}s`}return`${Math.max(0,Math.round(e/q)).toString()}s`}function Ot(e){let t=Math.max(0,e.observedAt-e.startedAt),n=e.filesTotal===null?`${X(e.filesMoved)} files`:`${X(e.filesMoved)} / ${X(e.filesTotal)} files`,r=e.filesTotal===null||e.filesTotal===0?null:Math.min(1,e.filesMoved/e.filesTotal),i=t>0&&e.filesMoved>0,a=i?`${G(e.bytesMoved/t*q)}/s`:null,o=e.filesTotal===null?null:e.filesTotal-e.filesMoved,s=!i||o===null||o<=0?null:`~${Dt(o*t/e.filesMoved)} left`;return{counted:n,fraction:r,moved:`${G(e.bytesMoved)} moved`,rate:a,eta:s}}function kt(e){let t=Ot(e);return[t.counted,t.moved,t.rate,t.eta].filter(e=>e!==null).join(` · `)}e();var At=`storage-migration`,Z=[{id:`recordings`,labelKey:`recordings.storageMigrationSection.classRecordings`,locationType:`recordings`},{id:`recordingsLow`,labelKey:`recordings.storageMigrationSection.classRecordingsLow`,locationType:`recordingsLow`},{id:`eventMedia`,labelKey:`recordings.storageMigrationSection.classEventMedia`,locationType:`eventMedia`}],jt=new Set([`planning`,`sealing`,`pausing`,`moving`,`draining`,`verifying`,`repointing`,`refreshing`,`resuming`]);function Mt(){let{t:e}=W(),t=R(At);return t===`pending`?a(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[c(b,{className:`h-4 w-4 animate-spin`}),e(`migration.storageMigrationSection.checkingWhetherStorageMigrationIs`,`Checking whether storage migration is installed…`)]}):t===`unknown`?c(B,{icon:f,title:e(`migration.storageMigrationSection.couldnTCheckWhetherStorage`,`Couldn't check whether storage migration is installed`),description:e(`migration.storageMigrationSection.theCapabilityRegistryDidNot`,`The capability registry did not answer, so this panel has nothing to report either way — it is not a statement that the capability is missing. Reload to ask again.`)}):t===`absent`?c(B,{icon:C,title:e(`migration.storageMigrationSection.storageMigrationNotInstalled`,`Storage migration not installed`),description:e(`migration.storageMigrationSection.theCapabilityRegistryAnsweredNo`,`The capability registry answered: no addon in this cluster provides storage-migration. Once one is deployed, this panel moves recordings, low-res recordings and event media to new storage locations in one coordinated, verified operation.`)}):c(Nt,{})}function Nt(){let{t:e}=W(),t=D(),{data:i}=H({}),[o,s]=r({}),[l,u]=r({}),[d,f]=r(null),[p,m]=r(null),h=n(()=>{let e=new Map;for(let t of i??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[i]),g=n(()=>{let e=new Map;for(let t of i??[]){if(t.enabled===!1)continue;let n=e.get(t.type);n?n.push(t.id):e.set(t.type,[t.id])}let t=new Map;for(let[n,r]of e)r.length===1&&t.set(n,r[0]);return t},[i]),_=ee({},{refetchInterval:2e3}),y=_.data??null,x=y!==null&&jt.has(y.phase),S=n(()=>{let e={};for(let t of Z){let n=o[t.id];n&&(e[t.id]=n)}return Object.keys(e).length>0?e:void 0},[o]),w=n(()=>{let e={};for(let t of Z){if(!o[t.id])continue;let n=l[t.id]??g.get(t.locationType);n&&(e[t.id]=n)}return Object.keys(e).length>0?e:void 0},[o,l,g]),T=n(()=>({destinations:S??{},...w?{sources:w}:{}}),[S,w]),E=re(T,{enabled:!1,retry:!1}),O=M(),k=j(),A=async()=>{if(!S)return;m(null);let e=await E.refetch();if(e.error){m(e.error instanceof Error?e.error.message:String(e.error));return}f(e.data??null)},N=async()=>{if(S&&await t({title:e(`migration.storageMigrationSection.startStorageMigration`,`Start storage migration?`),message:e(`migration.storageMigrationSection.copiesTheSelectedClassesFrom`,`Copies the selected classes from the chosen source to the destination, verifies, then either makes the destination the default (if the source was) or disables the source. Safe to re-run if interrupted.`),confirmLabel:e(`migration.storageMigrationSection.startMigration`,`Start migration`),variant:`danger`})){m(null);try{await O.mutateAsync(T),f(null),await _.refetch()}catch(e){m(e instanceof Error?e.message:String(e))}}},P=async()=>{if(y&&await t({title:e(`migration.storageMigrationSection.cancelMigration`,`Cancel migration?`),message:e(`migration.storageMigrationSection.stopsTheInProgressMigration`,`Stops the in-progress migration. Data already moved and verified stays at the destination; anything already repointed is not reverted.`),confirmLabel:e(`migration.storageMigrationSection.cancelMigration2`,`Cancel migration`),variant:`danger`}))try{await k.mutateAsync({jobId:y.jobId}),await _.refetch()}catch{}};return a(`div`,{className:`flex flex-col gap-6`,children:[a(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[a(`h3`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[c(C,{className:`h-3.5 w-3.5`}),e(`migration.storageMigrationSection.storageMigration`,`Storage migration`)]}),c(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:e(`migration.storageMigrationSection.moveRecordingsLowResRecordings`,`Move recordings, low-res recordings and/or event media from one location to another: copies via the recorder / pipeline-analytics movers, verifies, then either repoints the default (when the source was the default) or disables the source (when it was not). Skip a class with an empty destination.`)}),c(`div`,{className:`mt-3 grid grid-cols-1 gap-3 sm:grid-cols-3`,children:Z.map(t=>{let n=h.get(t.locationType)??[],r=g.get(t.locationType)??``;return a(`div`,{className:`space-y-2`,children:[c(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e(t.labelKey)}),a(`div`,{className:`space-y-1`,children:[c(`label`,{htmlFor:`migration-from-${t.id}`,className:`text-[10px] text-foreground-subtle`,children:e(`recordings.storageMigrationSection.classFrom`,{label:e(t.labelKey)})}),c(`select`,{id:`migration-from-${t.id}`,value:l[t.id]??r,onChange:e=>{let n=e.target.value;u(e=>({...e,[t.id]:n}))},disabled:x,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground disabled:opacity-50`,children:n.map(t=>a(`option`,{value:t.id,children:[t.displayName,t.enabled===!1?` (${e(`recordings.storageMigrationSection.readOnly`)})`:``]},t.id))})]}),a(`div`,{className:`space-y-1`,children:[c(`label`,{htmlFor:`migration-dest-${t.id}`,className:`text-[10px] text-foreground-subtle`,children:e(`recordings.storageMigrationSection.classTo`,{label:e(t.labelKey)})}),a(`select`,{id:`migration-dest-${t.id}`,value:o[t.id]??``,onChange:e=>{let n=e.target.value;s(e=>({...e,[t.id]:n}))},disabled:x,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground disabled:opacity-50`,children:[c(`option`,{value:``,children:e(`migration.storageMigrationSection.skip`,`— skip —`)}),n.map(e=>c(`option`,{value:e.id,children:e.displayName},e.id))]})]})]},t.id)})}),p&&c(`p`,{className:`mt-2 text-[11px] text-danger`,children:p}),a(`div`,{className:`mt-3 flex items-center gap-2`,children:[a(`button`,{type:`button`,onClick:()=>{A()},disabled:!S||E.isFetching||x,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover disabled:opacity-50`,children:[E.isFetching&&c(b,{className:`h-3 w-3 animate-spin`}),e(`migration.storageMigrationSection.plan`,`Plan`)]}),a(`button`,{type:`button`,onClick:()=>{N()},disabled:!S||O.isPending||x,className:`inline-flex items-center gap-1.5 rounded bg-primary px-2.5 py-1.5 text-xs font-medium text-primary-foreground disabled:opacity-50`,children:[O.isPending&&c(b,{className:`h-3 w-3 animate-spin`}),e(`migration.storageMigrationSection.startMigration`,`Start migration`)]})]}),d&&c(`div`,{className:`mt-3 divide-y divide-border rounded-md border border-border`,children:d.moves.length===0?c(`p`,{className:`px-2.5 py-1.5 text-[11px] text-foreground-subtle`,children:e(`migration.storageMigrationSection.nothingToMoveSelectedDestinations`,`Nothing to move — selected destinations match the current defaults.`)}):d.moves.map(e=>a(`div`,{className:`px-2.5 py-1.5 text-[11px] text-foreground`,children:[e.storageClass,`: `,e.fromLocationId,` → `,e.toLocationId]},`${e.storageClass}-${e.toLocationId}`))}),y&&a(`div`,{className:`mt-4 border-t border-border pt-3`,children:[a(`div`,{className:`flex items-center justify-between`,children:[c(`h4`,{className:`text-xs font-semibold text-foreground`,children:e(`migration.storageMigrationSection.migrationStatus`,`Migration status`)}),x&&a(`button`,{type:`button`,onClick:()=>{P()},className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10`,children:[c(v,{className:`h-3 w-3`}),e(`common.cancel`,`Cancel`)]})]}),a(`p`,{className:`mt-1 text-xs text-foreground`,children:[e(`migration.storageMigrationSection.phase`,`Phase:`),` `,c(`span`,{className:`font-medium`,children:y.phase}),x&&c(b,{className:`ml-2 inline h-3 w-3 animate-spin text-primary`})]}),y.error&&c(`p`,{className:`mt-1 text-[11px] text-danger`,children:y.error}),y.pausedParticipants.length>0&&a(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:[e(`migration.storageMigrationSection.paused`,`Paused:`),` `,y.pausedParticipants.join(`, `)]}),c(`div`,{className:`mt-2 divide-y divide-border rounded-md border border-border`,children:y.moves.map(e=>c(Pt,{move:e},`${e.storageClass}-${e.fromLocationId}`))})]}),c(Ft,{})]}),c(It,{running:x}),c(Rt,{})]})}function Pt({move:e}){let{t}=W(),n=e.progress===null?null:Ot(e.progress);return a(`div`,{className:`px-2.5 py-1.5 text-[11px]`,children:[a(`div`,{className:`flex items-center justify-between`,children:[a(`span`,{className:`text-foreground`,children:[e.storageClass,`: `,e.fromLocationId,` → `,e.toLocationId]}),a(`span`,{className:`text-foreground-subtle`,children:[e.state??t(`common.pending`),e.error?` (${e.error})`:``]})]}),e.progress!==null&&a(`div`,{className:`mt-1 space-y-1`,children:[n!==null&&n.fraction!==null&&c(`div`,{className:`h-1 w-full overflow-hidden rounded bg-border`,children:c(`div`,{className:`h-full bg-primary`,style:{width:`${(n.fraction*100).toFixed(1)}%`}})}),c(`p`,{className:`text-[10px] text-foreground-subtle`,children:kt(e.progress)})]})]})}function Ft(){let{t:e}=W(),{data:t}=be({});return!t||t.length===0?null:a(`div`,{className:`mt-4 border-t border-border pt-3`,children:[c(`h4`,{className:`text-xs font-semibold text-foreground`,children:e(`migration.storageMigrationSection.migrationHistory`,`Migration history`)}),c(`div`,{className:`mt-2 divide-y divide-border rounded-md border border-border`,children:t.map(e=>a(`div`,{className:`px-2.5 py-1.5 text-[11px] text-foreground-subtle`,children:[c(`span`,{className:`font-medium text-foreground`,children:e.phase}),` · `,Object.entries(e.destinations).filter(e=>typeof e[1]==`string`).map(([e,t])=>`${e} → ${t}`).join(`, `),` · `,new Date(e.startedAt).toLocaleString()]},e.jobId))})]})}function It({running:e}){let{t}=W(),n=D(),i=ae({},{staleTime:1/0,refetchOnWindowFocus:!1}),o=E(),[s,l]=r(null),u=i.data??[];if(u.length===0)return null;let d=async e=>{if(await n({title:t(`migration.storageMigrationSection.drainRemaining`,`Drain remaining {{storageClass}}?`,{storageClass:e.storageClass}),message:`Moves what is still on ${e.fromLocationId} to ${e.toLocationId}. Nothing is paused and no default is changed — this is the second half of a migration, run on its own. It is resumable: cancelling leaves everything readable from both locations.`,confirmLabel:t(`migration.storageMigrationSection.drainRemaining2`,`Drain remaining`),variant:`danger`})){l(null);try{await o.mutateAsync({classes:[e.storageClass]}),await i.refetch()}catch(e){l(e instanceof Error?e.message:String(e))}}};return a(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[a(`div`,{className:`flex items-start justify-between gap-2`,children:[c(`h3`,{className:`text-sm font-semibold text-foreground`,children:t(`migration.storageMigrationSection.leftOnTheOldLocation`,`Left on the old location`)}),a(`div`,{className:`flex shrink-0 items-center gap-2`,children:[c(`span`,{className:`text-[10px] text-foreground-subtle`,children:i.dataUpdatedAt>0?t(`migration.storageMigrationSection.measured`,`Measured {{value1}}`,{value1:new Date(i.dataUpdatedAt).toLocaleTimeString()}):t(`migration.storageMigrationSection.measuredNever`,`Measured — never`)}),c(`button`,{type:`button`,onClick:()=>{i.refetch()},disabled:i.isFetching,className:`rounded border border-border px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`,children:i.isFetching?t(`migration.storageMigrationSection.counting`,`Counting…`):t(`common.refresh`,`Refresh`)})]})]}),c(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:t(`migration.storageMigrationSection.aMigrationRepointsFirstAnd`,`A migration repoints first and drains behind. If the drain was cancelled, failed, or was interrupted by a restart, the data below is still on the source — readable, but not where the defaults now point. Draining moves it; it changes no default and pauses nothing.`)}),c(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:t(`migration.storageMigrationSection.thisCountIsTakenOn`,`This count is taken on demand: measuring it walks the whole media collection, so it is not refreshed on a timer. Press Refresh after a drain finishes.`)}),s&&c(`p`,{className:`mt-2 text-[11px] text-danger`,children:s}),c(`div`,{className:`mt-2 divide-y divide-border rounded-md border border-border`,children:u.map(n=>a(`div`,{className:`flex items-center justify-between gap-2 px-2.5 py-1.5 text-[11px]`,children:[a(`span`,{className:`text-foreground`,children:[n.storageClass,`: `,n.fromLocationId,` → `,n.toLocationId,c(`span`,{className:`ml-2 text-foreground-subtle`,children:Lt(n)})]}),c(`button`,{type:`button`,onClick:()=>{d(n)},disabled:e||o.isPending,className:`shrink-0 rounded border border-border px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`,children:t(`migration.storageMigrationSection.drainRemaining2`,`Drain remaining`)})]},`${n.storageClass}-${n.fromLocationId}`))})]})}function Lt(e){if(e.items===null)return U.t(`recordings.storageMigrationSection.residueUnknown`);let t=e.items.toLocaleString(`en-US`);return e.bytes===null?U.t(`recordings.storageMigrationSection.residueRows`,{count:e.items,items:t}):U.t(`recordings.storageMigrationSection.residueSegments`,{count:e.items,items:t,size:G(e.bytes)})}function Rt(){let{t:e}=W(),{data:t}=ne({},{refetchInterval:2e3}),n=(t??[]).filter(e=>e.migrationJobId===null&&e.job.state===`running`);return n.length===0?null:a(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[c(`h3`,{className:`text-sm font-semibold text-foreground`,children:e(`migration.storageMigrationSection.moversRunningOutsideAMigration`,`Movers running outside a migration`)}),c(`div`,{className:`mt-2 divide-y divide-border rounded-md border border-border`,children:n.map(e=>a(`div`,{className:`px-2.5 py-1.5 text-[11px]`,children:[a(`div`,{className:`text-foreground`,children:[e.lane,`: `,e.job.fromLocationId,` → `,e.job.toLocationId]}),c(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:kt({filesMoved:e.job.filesMoved,filesTotal:e.job.filesTotal,bytesMoved:e.job.bytesMoved,startedAt:e.job.startedAt,observedAt:e.observedAt})})]},e.job.jobId))})]})}function zt(){let{t:e}=W();return a(`div`,{className:`flex flex-col gap-4`,children:[c(Ct,{}),c(Et,{}),a(`section`,{children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`recordings.recordingsManagementSection.moveStorage`,`Move storage`)}),c(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:e(`recordings.recordingsManagementSection.copyRecordingsLowResRecordings`,`Copy recordings, low-res recordings or event media to a new location, verify, then repoint the default. Applies to every camera.`)}),c(`div`,{className:`mt-3`,children:c(Mt,{})})]})]})}e();var Bt=`recorder`;function Vt(e,t,n){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t&&typeof e.value==`string`)return e.value;return n}function Ht(){let{t:e}=W(),t=s(),{nodes:r}=Ee(),{data:i,isLoading:o}=P({addonId:Bt}),l=Vt(i,`recordingNodeId`,`hub`),u=de({onSuccess:()=>{t.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),d=n(()=>{let e=r.filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,l,...e])].filter(Boolean)},[r,l]);return a(`div`,{className:`flex flex-col gap-6`,children:[a(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[c(`h3`,{className:`text-sm font-semibold text-foreground`,children:e(`pipeline.clusterRecordingTab.recordingNode`,`Recording node`)}),c(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:e(`pipeline.clusterRecordingTab.theSingleNodeThatRecords`,`The single node that records (continuous & events) and serves playback. Every other node stays inert — no multi-node balancing. Takes effect on addon restart.`)}),a(`div`,{className:`mt-3 flex items-center gap-2`,children:[o?c(b,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):c(`select`,{value:l,onChange:e=>{e.target.value!==l&&u.mutate({addonId:Bt,patch:{recordingNodeId:e.target.value}})},disabled:u.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:d.map(t=>c(`option`,{value:t,children:t===`hub`?e(`pipeline.clusterRecordingTab.hubDefault`,`hub (default)`):t},t))}),u.isPending&&c(b,{className:`h-4 w-4 animate-spin text-primary`})]}),l!==`hub`&&c(`p`,{className:`mt-2 text-[11px] text-amber-500`,children:c(Ae,{i18nKey:`pipeline.clusterRecordingTab.hubOnlyNote`,values:{node:l},components:{b:c(`span`,{className:`font-medium`})}})})]}),a(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[c(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:e(`pipeline.clusterRecordingTab.recordingsFolders`,`Recordings folders`)}),c(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:e(`pipeline.clusterRecordingTab.whereRecordingsAreStoredMulti`,`Where recordings are stored. Multi-location collections — segments are split across the locations of a type. Add a location to grow capacity; mark one default per type.`)}),c(Ye,{types:[`recordings`,`recordingsLow`]})]})]})}function Q(e){return e.locationIds!==void 0&&e.locationIds.length>0?e.locationIds:e.locationId===null?[]:[e.locationId]}function Ut(e,t){let n=Q(e);return n.length===0?U.t(`helpers.cameraDisk.defaultRoot`):n.map(e=>t.get(e)??e).join(` + `)}function Wt(e,t,n){if(e.length===0)return null;let r=e[0];if(e.length===1&&r!==void 0)return{label:Ut(r,t),exact:!0};if(n===null)return null;let i=e.find(e=>Q(e).includes(n));return i===void 0?null:{label:Ut(i,t),exact:!1}}e();var Gt=[[`recording`]],Kt=[{value:`retention`,labelKey:`recordings.storageSection.pruneRetention`},{value:`quota`,labelKey:`recordings.storageSection.pruneQuota`},{value:`operator`,labelKey:`recordings.storageSection.pruneOperator`}],qt={ok:`bg-primary`,warn:`bg-amber-500`,critical:`bg-danger`},Jt={ok:`text-foreground-subtle`,warn:`text-amber-500`,critical:`text-danger`};function $(e){return`${String(Math.round(e*100))}%`}function Yt(e){return e==null?`—`:new Date(e).toLocaleString()}function Xt(e,t){let n=e.locationIds??(e.locationId===null?[]:[e.locationId]),r=n.map(e=>t.get(e)).filter(e=>e!==void 0);return r.length>0?r.join(` + `):e.root===void 0?n.length>0?n.join(` + `):U.t(`recordings.storageSection.defaultRoot`):e.root}function Zt(){let{t:e}=W(),t=s(),o=D(),[l,u]=r(`retention`),{data:f,isLoading:p}=V({},{refetchOnWindowFocus:!1}),{data:g}=I({isCamera:!0,projection:`slim`}),{data:_}=H({}),v=n(()=>{let e=new Map;for(let t of g??[])e.set(t.id,t.name);return e},[g]),y=n(()=>{let e=new Map;for(let t of _??[])e.set(t.id,t.displayName);return e},[_]),x=n(()=>{let e=_??[];return e.find(e=>e.type===`recordings`&&e.enabled!==!1)?.id??e.find(e=>e.type===`recordings`)?.id??null},[_]),S=n(()=>f?.locations??[],[f?.locations]),C=n(()=>Wt(S,y,x),[S,y,x]),T=n(()=>Fe(S),[S]),E=i(()=>{t.invalidateQueries({queryKey:Gt})},[t]),O=ge({onSuccess:E}),k=Se({onSuccess:E}),A=i(async t=>{await o({title:e(`recordings.storageSection.prune`,`Prune {{label}}?`,{label:v.get(t.deviceId)??`#${String(t.deviceId)}`}),message:e(`recordings.storageSection.appliesTheRetentionPolicyNow`,`Applies the retention policy now (reason: {{reason}}). Footage beyond the policy is permanently deleted.`,{reason:l}),confirmLabel:e(`recordings.storageSection.pruneNow`,`Prune now`),variant:`danger`})&&O.mutate({deviceId:t.deviceId,reason:l})},[o,O,l,v,e]),j=i(async t=>{await o({title:e(`recordings.storageSection.deleteAllFootageFor`,`Delete all footage for {{label}}?`,{label:v.get(t.deviceId)??`#${String(t.deviceId)}`}),message:e(`recordings.storageSection.permanentlyDeletesOfRecordedFootage`,`Permanently deletes {{value1}} of recorded footage for this camera. This cannot be undone.`,{value1:G(t.usedBytes)}),confirmLabel:e(`recordings.storageSection.delete`,`Delete {{value1}}`,{value1:G(t.usedBytes)}),variant:`danger`})&&k.mutate({deviceId:t.deviceId})},[o,k,v,e]),M=n(()=>[{key:`camera`,header:e(`recordings.storageSection.camera`,`Camera`),render:e=>c(`span`,{className:`text-foreground`,children:v.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`disk`,header:e(`recordings.storageSection.disk`,`Disk`),nowrap:!0,render:()=>C===null?c(`span`,{className:`text-foreground-subtle`,children:`—`}):a(`span`,{className:C.exact?`text-foreground`:`text-foreground-subtle`,title:C.exact?e(`recordings.storageSection.theOnlyRecordingsVolumeOn`,`The only recordings volume on this node — this camera can only be here.`):e(`recordings.storageSection.theRecordingsDefaultThisNode`,`The recordings DEFAULT. This node has several recordings volumes and the per-camera placement is not reported by recording.getStorageUsage, so this is where footage lands by default rather than a per-camera fact.`),children:[C.label,!C.exact&&c(`span`,{className:`ml-1 text-foreground-subtle`,children:e(`recordings.storageSection.default`,`(default)`)})]})},{key:`used`,header:e(`recordings.storageSection.used`,`Used`),align:`right`,nowrap:!0,render:e=>c(`span`,{className:`tabular-nums`,children:G(e.usedBytes)})},{key:`oldest`,header:e(`recordings.storageSection.oldestFootage`,`Oldest footage`),align:`right`,nowrap:!0,render:t=>c(`span`,{className:`tabular-nums text-foreground-subtle`,title:e(`recordings.storageSection.theOldestSegmentTheArchive`,`The oldest segment the ARCHIVE holds for this camera — the per-camera answer to 'is retention actually holding?'.`),children:Yt(t.oldestMs)})},{key:`actions`,header:``,align:`right`,render:t=>a(`div`,{className:`flex items-center justify-end gap-1`,children:[a(`button`,{onClick:()=>{A(t)},disabled:O.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-amber-500/10 hover:text-amber-500 disabled:opacity-50`,title:e(`recordings.storageSection.applyRetentionPolicyNow`,`Apply retention policy now`),children:[c(w,{className:`h-3 w-3`}),e(`recordings.storageSection.prune2`,`Prune`)]}),a(`button`,{onClick:()=>{j(t)},disabled:k.isPending,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(`recordings.storageSection.deleteAllFootage`,`Delete all footage`),children:[c(d,{className:`h-3 w-3`}),e(`common.delete`,`Delete`)]})]})}],[v,C,A,j,O.isPending,k.isPending,e]);if(p&&!f)return a(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[c(b,{className:`h-4 w-4 animate-spin`}),e(`recordings.storageSection.loadingStorageUsage`,`Loading storage usage…`)]});if(!f)return c(B,{icon:m,title:e(`recordings.storageSection.noStorageData`,`No storage data`),description:e(`recordings.storageSection.theRecordingNodeHasNot`,`The recording node has not reported any storage usage yet.`)});let N=f.devices.length;return a(`div`,{className:`flex flex-col gap-6`,children:[a(`section`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:[c(h,{label:e(`recordings.storageSection.totalUsed`,`Total used`),icon:c(m,{className:`h-3 w-3`}),footer:`${String(N)} camera${N===1?``:`s`} on ${f.nodeId}`,children:G(f.totalUsedBytes)}),T!==null&&T.severity!==null&&c(h,{label:e(`recordings.storageSection.freeOnRecordingsVolumes`,`Free on recordings volumes`),icon:c(m,{className:`h-3 w-3`}),footer:`across ${String(T.knownVolumes)} volume${T.knownVolumes===1?``:`s`} of ${G(T.totalBytes)}`+(T.unknownVolumes>0?` · ${String(T.unknownVolumes)} did not report capacity`:``),children:c(`span`,{className:`tabular-nums ${Jt[T.severity]}`,children:G(T.freeBytes)})}),S.map(t=>{let n=ze(t),r=t.locationId??t.root??`default`;return c(h,{label:e(`recordings.storageSection.disk2`,`Disk: {{label}}`,{label:Xt(t,y)}),footer:n===null?`${G(t.usedBytes)} of recordings · volume capacity unknown`:`${G(n.freeBytes)} free of ${G(n.totalBytes)} · ${G(t.usedBytes)} recordings (${$(n.recordingsFraction)})`,children:n===null?c(`span`,{className:`tabular-nums`,children:G(t.usedBytes)}):a(`div`,{className:`flex items-center gap-2`,title:e(`recordings.storageSection.volumeFillEverythingOnThe`,`Volume fill — everything on the disk, not only recordings. Warn at 85%, critical at 95%.`),children:[c(`div`,{className:`h-2 flex-1 overflow-hidden rounded bg-muted`,children:c(`div`,{className:`h-full rounded ${qt[n.severity]}`,style:{width:$(n.fraction)}})}),c(`span`,{className:`tabular-nums text-xs ${Jt[n.severity]}`,children:$(n.fraction)})]})},r)})]}),a(`section`,{className:`flex items-center gap-2 text-xs`,children:[c(`label`,{htmlFor:`prune-reason`,className:`text-foreground-subtle`,children:e(`recordings.storageSection.pruneReason`,`Prune reason`)}),c(`select`,{id:`prune-reason`,value:l,onChange:e=>{let t=Kt.find(t=>t.value===e.target.value);t&&u(t.value)},className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:Kt.map(t=>c(`option`,{value:t.value,children:e(t.labelKey)},t.value))})]}),N===0?c(B,{icon:m,title:f.devicesRead===`unavailable`?e(`recordings.storageSection.perCameraUsageUnavailable`,`Per-camera usage unavailable`):e(`recordings.storageSection.noRecordedFootage`,`No recorded footage`),description:f.devicesRead===`unavailable`?e(`recordings.storageSection.thisRecordingNodeHasNo`,`This recording node has no footage ledger, so it refused to answer the per-camera table rather than report what it happens to hold in memory. The disk totals above are unaffected.`):e(`recordings.storageSection.noCameraHasRecordedFootage`,`No camera has recorded footage on this node yet.`)}):c(L,{columns:M,rows:[...f.devices],rowKey:e=>e.deviceId,minWidthPx:480})]})}function Qt(){let{t:e}=W();return a(`div`,{className:`flex flex-col gap-8`,children:[a(`div`,{children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`recordings.recordingsStorageSection.footageOnDisk`,`Footage on disk`)}),c(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:e(`recordings.recordingsStorageSection.whatRecordedFootageOccupiesPer`,`What recorded footage occupies, per camera and per volume, with prune-by-policy and delete-all-footage.`)}),c(`div`,{className:`mt-3`,children:c(Zt,{})})]}),a(`div`,{children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`recordings.recordingsStorageSection.recordingNodeFolders`,`Recording node & folders`)}),c(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:e(`recordings.recordingsStorageSection.theSingleNodeThatRecords`,`The single node that records and serves playback, and the storage locations footage is written to.`)}),c(`div`,{className:`mt-3`,children:c(Ht,{})})]})]})}function $t(){let{t:e}=W(),t=ke(`/recordings`,{t:e,isAdmin:!0})??{icon:u,title:e(`nav.recordings`,`Recordings`)};return c(Me,{icon:t.icon,title:t.title,subtitle:e(`recordings.recordedFootageAndTheDurable`,`Recorded footage and the durable event store — what each occupies, where it is written, and the operations that move or reconcile both.`),defaultSection:`storage`,sectionsLabel:`${t.title} sections`,sections:[{id:`storage`,label:e(`recordings.recordings`,`Recordings`),content:c(Qt,{})},{id:`events`,label:e(`recordings.events`,`Events`),content:c(it,{})},{id:`cameras`,label:e(`recordings.cameras`,`Cameras`),content:c(Je,{})},{id:`exports`,label:e(`recordings.export`,`Export`),content:c(vt,{})},{id:`activity`,label:e(`recordings.activity`,`Activity`),content:c(qe,{})},{id:`management`,label:e(`recordings.management`,`Management`),content:c(zt,{})}]})}export{$t as RecordingsPage};