@camstack/addon-admin-ui 1.2.609 → 1.2.611

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 (153) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/assets/Addons-dzEoAtna.js +5 -0
  3. package/dist/assets/{AdminPage-CN1M6UZ4.js → AdminPage-BhZ_VePJ.js} +1 -1
  4. package/dist/assets/{AdminSectionedPage-ByDJLqaY.js → AdminSectionedPage-UsW8fkeW.js} +1 -1
  5. package/dist/assets/{AiProfiles-Dzwi1Fy5.js → AiProfiles-Bafd5beY.js} +2 -2
  6. package/dist/assets/Authentication-CrPmjO6x.js +1 -0
  7. package/dist/assets/Build-h7foMuCO.js +39 -0
  8. package/dist/assets/{Calendars-BYgSS8GL.js → Calendars-DWG5ZPJ3.js} +1 -1
  9. package/dist/assets/{CameraGrids-B6zMPkgA.js → CameraGrids-SlbSfzSp.js} +1 -1
  10. package/dist/assets/{Cluster-nmyC-5_B.js → Cluster-CCxXrm4a.js} +1 -1
  11. package/dist/assets/CompositionBlockEditor-DuGXbJtF.js +2 -0
  12. package/dist/assets/{CompositionEditorPage-CB_mvcO_.js → CompositionEditorPage-Q0iUJPqd.js} +1 -1
  13. package/dist/assets/{Data-BqGqagS2.js → Data-MB6zjI5c.js} +2 -2
  14. package/dist/assets/DeviceDetail-OBsa2it2.js +2 -0
  15. package/dist/assets/{DeviceDoActionFields-BUYFwU0z.js → DeviceDoActionFields-Boe7qhrE.js} +1 -1
  16. package/dist/assets/{Devices-B2TIc4iW.js → Devices-eTTJB4aq.js} +1 -1
  17. package/dist/assets/{EditTemplateButton-DGQyzrn5.js → EditTemplateButton-BbXZhb1b.js} +1 -1
  18. package/dist/assets/{EmbedPlayerPage-DS-MCVT_.js → EmbedPlayerPage-tMSOsuMm.js} +1 -1
  19. package/dist/assets/History-Cly-X0kM.js +1 -0
  20. package/dist/assets/Identity-BlWgl_Sz.js +1 -0
  21. package/dist/assets/{InstancesTable-A0I2fC4x.js → InstancesTable-BjBbsg4s.js} +1 -1
  22. package/dist/assets/IntegrationDetail-DHCf07HY.js +1 -0
  23. package/dist/assets/{IntegrationHub-C8tNL25o.js → IntegrationHub-joySlkYR.js} +1 -1
  24. package/dist/assets/Integrations-32La43u7.js +2 -0
  25. package/dist/assets/Integrations-BxzYc7P-.js +1 -0
  26. package/dist/assets/{Library-DxDzc96c.js → Library-qTq0AaC6.js} +1 -1
  27. package/dist/assets/Locations-BCMa-IeZ.js +3 -0
  28. package/dist/assets/{Logs-DN3qDokO.js → Logs-CpgTUPKb.js} +1 -1
  29. package/dist/assets/{MaskShapeCanvas-BS-uGEi7.js → MaskShapeCanvas-B7acndcq.js} +1 -1
  30. package/dist/assets/{MotionZonesSettings-DYW-5t38.js → MotionZonesSettings-CRxB6roe.js} +1 -1
  31. package/dist/assets/MyAccess-BUoYI14X.js +2 -0
  32. package/dist/assets/Network-sl4oakCw.js +1 -0
  33. package/dist/assets/NodeAddonsSettingsPanel-Dxq6lu8k.js +1 -0
  34. package/dist/assets/Notifications-2BBaGCkA.js +1 -0
  35. package/dist/assets/{Pipeline-CviU9o4K.js → Pipeline-ZpHfoCwe.js} +1 -1
  36. package/dist/assets/{PrivacyMaskSettings-BH67CESJ.js → PrivacyMaskSettings-Cqv_Alnn.js} +1 -1
  37. package/dist/assets/Recordings-C5AUJVfz.js +1 -0
  38. package/dist/assets/{ScanSubnetEditor-DxjiHfEb.js → ScanSubnetEditor-CYp-W62j.js} +1 -1
  39. package/dist/assets/{SceneMonitorEditor-DzBMI5ZF.js → SceneMonitorEditor-CuNrEnqp.js} +1 -1
  40. package/dist/assets/{SessionsList-CIy47IrP.js → SessionsList-Buq3aa4I.js} +2 -2
  41. package/dist/assets/{Showroom-BRg96hl4.js → Showroom-CQzykrxR.js} +1 -1
  42. package/dist/assets/{StorageLocationsTable-Bx4BNXOY.js → StorageLocationsTable-DdiMcYSB.js} +1 -1
  43. package/dist/assets/{System-DQmn0cvm.js → System-Dg1Sqr5Y.js} +1 -1
  44. package/dist/assets/Templates-BCEWEi2s.js +1 -0
  45. package/dist/assets/{Terminal-D6zR4uXe.js → Terminal-C2-AJvoa.js} +3 -3
  46. package/dist/assets/{TrainingProviders-BdKGyQPQ.js → TrainingProviders-DmpsT5cs.js} +1 -1
  47. package/dist/assets/{Viewer-Dz-YS30N.js → Viewer-BsgaVF35.js} +1 -1
  48. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-D1B03T4y.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Btig6zmW.js} +1 -1
  49. package/dist/assets/{addon-icons-context-vNuH_Qnv.js → addon-icons-context-DS_A8BlD.js} +1 -1
  50. package/dist/assets/{ai-page.helpers-DeJr0FK5.js → ai-page.helpers-Bj7xufkQ.js} +1 -1
  51. package/dist/assets/{archive-CACBifJW.js → archive-UoWI2uJH.js} +1 -1
  52. package/dist/assets/{assignment-candidates-7Ltc_NAB.js → assignment-candidates-DhrgOH8O.js} +1 -1
  53. package/dist/assets/{authed-media-1IBvRqSW.js → authed-media-BOb-F9Jh.js} +1 -1
  54. package/dist/assets/{bell-off-DaptuG2C.js → bell-off-B9aPvK6f.js} +1 -1
  55. package/dist/assets/{board-model-CLSE8V6_.js → board-model-DgqamWrA.js} +1 -1
  56. package/dist/assets/{boxes-BMGVI06T.js → boxes-DLKqnuEj.js} +1 -1
  57. package/dist/assets/{calendar-clock-ClkWjege.js → calendar-clock-BStqfnbg.js} +1 -1
  58. package/dist/assets/circle-slash-CPlAWJRi.js +1 -0
  59. package/dist/assets/client-Mx9AmjBL.js +809 -0
  60. package/dist/assets/create-composition-BeMU5FfH.js +2 -0
  61. package/dist/assets/crop-BaKf0XlN.js +1 -0
  62. package/dist/assets/{database-zap-DmvPI7WG.js → database-zap-BZmTPYf5.js} +1 -1
  63. package/dist/assets/{device-integration-icon-C7ZXUKQ-.js → device-integration-icon-w8yj8eHk.js} +1 -1
  64. package/dist/assets/device-picker-model-DZVTsK08.js +1 -0
  65. package/dist/assets/dist-Ba0PMcmz.js +809 -0
  66. package/dist/assets/{dist-D2xfOl5a.js → dist-crF8D7Uc.js} +1 -1
  67. package/dist/assets/{eraser-DxqE1cuz.js → eraser-j4TAiWeJ.js} +1 -1
  68. package/dist/assets/{file-up-BUxetIpi.js → file-up-zESwu296.js} +1 -1
  69. package/dist/assets/{format-3gap9qLz.js → format-DXxwNIyt.js} +1 -1
  70. package/dist/assets/{grip-vertical-BaflvEVj.js → grip-vertical-DwW4Yxs8.js} +1 -1
  71. package/dist/assets/{hard-drive-download-DuBpWHNe.js → hard-drive-download-DAJ8MOcc.js} +1 -1
  72. package/dist/assets/{hostInit-CYSA1uQA.js → hostInit-lLmzQjvA.js} +1 -1
  73. package/dist/assets/i18n-0sDSykZR.js +1 -0
  74. package/dist/assets/{icons-Ci6wTHzR.js → icons-DGcrBbZf.js} +1 -1
  75. package/dist/assets/index-DDV53vFk.js +4 -0
  76. package/dist/assets/{key-B_StsvmD.js → key-BMMDG-pV.js} +1 -1
  77. package/dist/assets/{key-square-BiZZaYF4.js → key-square-BoHZ1XjF.js} +1 -1
  78. package/dist/assets/{layers-Cq6BLvAx.js → layers-dfb9Gxfe.js} +1 -1
  79. package/dist/assets/{link-2-off-BweSCbbu.js → link-2-off-xom26Qw0.js} +1 -1
  80. package/dist/assets/linked-devices-model-BAfraTXn.js +1 -0
  81. package/dist/assets/{list-ordered-myBcF32p.js → list-ordered-B4D264-Z.js} +1 -1
  82. package/dist/assets/{memory-stick-C5Yt7QJa.js → memory-stick-DJXZ25SJ.js} +1 -1
  83. package/dist/assets/{message-square-plus-CN3RGa5P.js → message-square-plus-_77DXl5T.js} +1 -1
  84. package/dist/assets/{mf-entry-bootstrap-0-2563a517.js → mf-entry-bootstrap-0-b444926c.js} +2 -2
  85. package/dist/assets/{mic-off-DyL_bK5T.js → mic-off-BJG6Fm99.js} +1 -1
  86. package/dist/assets/{monitor-off-DROyWuBT.js → monitor-off-Czsoo7xs.js} +1 -1
  87. package/dist/assets/{monitor-smartphone-DXXBIJKP.js → monitor-smartphone-D_cdypSO.js} +1 -1
  88. package/dist/assets/mount-DZVTsK08.js +1 -0
  89. package/dist/assets/{notification-rule-status-RmDwzfG-.js → notification-rule-status-DQdXQer1.js} +1 -1
  90. package/dist/assets/{player-overlays-D5PuUVGx.js → player-overlays-CW2gZp1V.js} +1 -1
  91. package/dist/assets/remoteEntry-0iAyZT8V.js +1 -0
  92. package/dist/assets/{ruler-DpdMZDbl.js → ruler-fLB3DQQl.js} +1 -1
  93. package/dist/assets/{scan-eye-DaEhUyo3.js → scan-eye-fvTxA4BS.js} +1 -1
  94. package/dist/assets/{scissors-k-txA_Ta.js → scissors-BmmiVH2z.js} +1 -1
  95. package/dist/assets/{search-x-DTKP7R6g.js → search-x-B822AUih.js} +1 -1
  96. package/dist/assets/{send-CjwxdtWi.js → send-CcRJSMWY.js} +1 -1
  97. package/dist/assets/{settings-2-B-k-LPP_.js → settings-2-0mQ2HCMq.js} +1 -1
  98. package/dist/assets/{shapes-D8i9579Q.js → shapes-QK3PIPmq.js} +1 -1
  99. package/dist/assets/{sigma-p_PPuMYs.js → sigma-C8LUvV_G.js} +1 -1
  100. package/dist/assets/{speaker-BlIjlZin.js → speaker-DU_wbE6N.js} +1 -1
  101. package/dist/assets/src-B_7qCqtR.js +100 -0
  102. package/dist/assets/{sso-popup-Dt_Vzh3t.js → sso-popup-cY73C2uJ.js} +1 -1
  103. package/dist/assets/{step-inspector-model-B3gllf-t.js → step-inspector-model-Dh2UWMEs.js} +1 -1
  104. package/dist/assets/{table-2-QGOqxHnt.js → table-2-zWOZVjsk.js} +1 -1
  105. package/dist/assets/{timer-reset-BgLYKIXr.js → timer-reset-CYowm0Ii.js} +1 -1
  106. package/dist/assets/{unlink-B_JkAfPv.js → unlink-BrsKfTDL.js} +1 -1
  107. package/dist/assets/{usb-RrGQPjOo.js → usb-CTgGYL1V.js} +1 -1
  108. package/dist/assets/{use-device-bound-caps-Dnf6QFDN.js → use-device-bound-caps-D35kBUUJ.js} +1 -1
  109. package/dist/assets/{use-scenes-feed-C2Ax7QVi.js → use-scenes-feed-DeUtfmq0.js} +1 -1
  110. package/dist/assets/{use-stationary-objects-CV1wAJKz.js → use-stationary-objects-BlgjrUVY.js} +1 -1
  111. package/dist/assets/{useAdminDeviceRemoval-39R8KAnR.js → useAdminDeviceRemoval-CTqki1Qc.js} +1 -1
  112. package/dist/assets/useEventInvalidation-DZVTsK08.js +1 -0
  113. package/dist/assets/useInvalidateAddonSettings-CyofQfBo.js +1 -0
  114. package/dist/assets/{useNodeUrlSelection-B6F0O9xq.js → useNodeUrlSelection-DazRnggs.js} +1 -1
  115. package/dist/assets/user-round-DqgsnB_a.js +1 -0
  116. package/dist/assets/{user-x-QqdI9XGf.js → user-x-BYht-gc9.js} +1 -1
  117. package/dist/assets/{variable-DvMlG3sr.js → variable-_cUaDGra.js} +1 -1
  118. package/dist/assets/{video-y3iyn_B3.js → video-DcELsjY3.js} +1 -1
  119. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CNP8q5YO.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BsI4VtJv.js} +2 -2
  120. package/dist/index.html +10 -10
  121. package/dist/server/addon.js +57 -7
  122. package/package.json +2 -2
  123. package/dist/assets/Addons-BFxeCNAR.js +0 -5
  124. package/dist/assets/Authentication-BBQnP-Wy.js +0 -1
  125. package/dist/assets/Build-bXZZIPAp.js +0 -39
  126. package/dist/assets/CompositionBlockEditor-CEHUfg88.js +0 -2
  127. package/dist/assets/DeviceDetail-Cq10isMd.js +0 -2
  128. package/dist/assets/History-lESy3MP3.js +0 -1
  129. package/dist/assets/Identity-CQL5geAH.js +0 -1
  130. package/dist/assets/IntegrationDetail-CHXefwhx.js +0 -1
  131. package/dist/assets/Integrations-6JUMdYxT.js +0 -1
  132. package/dist/assets/Integrations-B9WX-DoF.js +0 -2
  133. package/dist/assets/Locations-CwiENy5O.js +0 -3
  134. package/dist/assets/MyAccess-q4wT3Gj9.js +0 -2
  135. package/dist/assets/Network-Cag4IB4d.js +0 -1
  136. package/dist/assets/NodeAddonsSettingsPanel-BN1rOp6t.js +0 -1
  137. package/dist/assets/Notifications-Dz9dhE9S.js +0 -1
  138. package/dist/assets/Recordings-BakzW9AU.js +0 -1
  139. package/dist/assets/Templates-DknEbt7m.js +0 -1
  140. package/dist/assets/circle-slash-DJL9iYoo.js +0 -1
  141. package/dist/assets/client-DDfmis6s.js +0 -809
  142. package/dist/assets/create-composition-gUPeU-fh.js +0 -2
  143. package/dist/assets/crop-BwQkH2qz.js +0 -1
  144. package/dist/assets/device-picker-model-Gb8kSp8V.js +0 -1
  145. package/dist/assets/dist-jpGt81zI.js +0 -809
  146. package/dist/assets/i18n-C-ZuqT0u.js +0 -1
  147. package/dist/assets/index-tVCZ0Ciq.js +0 -4
  148. package/dist/assets/linked-devices-model-CAQzz1C5.js +0 -1
  149. package/dist/assets/mount-Gb8kSp8V.js +0 -1
  150. package/dist/assets/remoteEntry-BP9XW9BC.js +0 -1
  151. package/dist/assets/src-kgyauwxD.js +0 -100
  152. package/dist/assets/useEventInvalidation-Gb8kSp8V.js +0 -1
  153. package/dist/assets/user-round-D18UTvSy.js +0 -1
@@ -1 +0,0 @@
1
- import{C as e,J as t,K as n,S as r,V as i,Y as a,a as o,et as s,o as c,x as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$r as u,Cn as d,D as f,Fn as p,Ft as m,Kt as h,Tn as g,Ut as _,Wn as v,Xn as y,_n as b,ai as x,bn as S,bt as C,ct as w,ht as T,ki as E,kr as ee,lt as te,oa as ne,un as D,ut as re,vr as ie,wr as O,xr as k,yn as ae}from"./player-overlays-D5PuUVGx.js";import{ho as A,l as oe,mo as se}from"./client-DDfmis6s.js";import{c as j,f as M,h as ce,r as le}from"./video-y3iyn_B3.js";import{t as ue}from"./file-up-BUxetIpi.js";import{t as de}from"./key-B_StsvmD.js";import{t as fe}from"./monitor-smartphone-DXXBIJKP.js";import{t as pe}from"./unlink-B_JkAfPv.js";import{An as me,Bd as he,Br as N,Ei as P,Et as ge,Fr as F,Gd as _e,Hd as ve,In as ye,Ir as I,Jd as be,Jr as L,Kd as R,Ko as z,Ln as B,Mr as xe,Oc as Se,Pf as V,Pr as H,Pt as U,Rd as Ce,Rn as we,Rr as Te,Ud as Ee,Vd as De,Wd as Oe,X as ke,Yd as Ae,Yr as je,af as Me,ar as Ne,cr as Pe,er as Fe,ht as Ie,if as Le,ir as Re,jn as ze,kc as Be,lr as Ve,nf as He,nr as Ue,of as We,or as Ge,qd as Ke,rf as qe,rr as Je,vi as W,wc as Ye,wt as Xe,xc as Ze,yc as Qe,zd as $e,zn as et,zr as tt}from"./src-kgyauwxD.js";import{t as G}from"./i18n-C-ZuqT0u.js";import{t as K}from"./useTranslation-BJr-n0es.js";import{Fr as nt,I as rt,Lr as it,Nr as at,S as ot,a as st,d as ct,i as lt,l as ut,t as dt}from"./index-tVCZ0Ciq.js";import{t as ft}from"./AdminSectionedPage-ByDJLqaY.js";import{t as pt}from"./AdminPage-CN1M6UZ4.js";import{C as mt,D as q,E as ht,O as J,S as gt,T as _t,_ as vt,a as yt,b as bt,c as xt,d as St,f as Ct,g as wt,h as Tt,i as Et,k as Dt,l as Ot,m as kt,n as At,o as jt,p as Mt,s as Nt,t as Pt,u as Ft,v as It,w as Lt,x as Rt,y as zt}from"./SessionsList-CIy47IrP.js";import{r as Bt}from"./IntegrationHub-C8tNL25o.js";import{n as Vt}from"./Authentication-BBQnP-Wy.js";s();function Ht(){let{t:e}=K(),t=w(),i=V.useUtils(),o=Dt(),{data:s,isLoading:c}=Oe(),l=n(()=>s??[],[s]),u=V.useQueries(e=>l.map(t=>e.userManagement.listExternalIdentities({userId:t.id}))),d=V.auth.listLoginMethods.useQuery(),[f,p]=a(null),m=be({onSuccess:()=>void i.userManagement.listExternalIdentities.invalidate(),onError:e=>p(`Remove failed: ${e.message}`)}),h=n(()=>new Map((d.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),[d.data]),g=l.flatMap((e,t)=>u[t]?.data??[]),_=g.map(e=>({...Rt(e,o),kind:h.get(e.provider)??e.provider})),v=async n=>{let r=g.find(e=>bt(e)===n.id);r!==void 0&&await t({title:e(`access.externalIdentitiesSection.removeSignInLink`,`Remove sign-in link`),message:e(`access.externalIdentitiesSection.willNoLongerBeAble`,`"{{ownerName}}" will no longer be able to sign in with this {{kind}} account.`,{ownerName:n.ownerName,kind:n.kind}),confirmLabel:e(`common.remove`,`Remove`),variant:`danger`})&&(p(null),m.mutate({userId:r.userId,provider:r.provider,subject:r.subject}))};return r(q,{notice:J(f),onDismissNotice:()=>{p(null)},id:`external-identities`,title:e(`access.externalIdentitiesSection.signInLinks`,`Sign-in links`),icon:ce,description:e(`access.externalIdentitiesSection.externalAccountsSingleSignOn`,`External accounts (single sign-on) each user linked to their CamStack account. Only the owner can link one, from their profile; an admin can remove it.`),children:r(Lt,{rows:_,label:`sign-in links`,isLoading:c||u.some(e=>e.isLoading),loadError:u.find(e=>e.isError)?.error?.message??null,emptyText:`No user has linked a sign-in account.`,expiresNone:`—`,action:{label:e(`common.remove`,`Remove`),icon:pe,isAvailable:()=>!0,onRun:e=>void v(e),busyId:null,disabled:m.isPending}})})}s();var Ut={key:`access.nouns.linkedApp`};function Wt(e){if(e.type===`category`){let t=e.target??``;return t===`device`?G.t(`access.linkedAppsSection.allDevices`):G.t(`access.linkedAppsSection.allTarget`,{target:t})}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function Gt(){let{t:e}=K(),t=w(),i=c(),o=Ee(),[s,l]=a(null),u=()=>void i.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]}),d=R({onSuccess:u,onError:e=>l(`Revoke failed: ${e.message}`)}),f=_t(Ut,u),p=n(()=>(o.data??[]).map(e=>gt(e,e.scopes.map(Wt).join(`, `))),[o.data]),m=async n=>{await t({title:e(`access.linkedAppsSection.revokeTheLink`,`Revoke the "{{name}}" link?`,{name:n.name}),message:e(`access.linkedAppsSection.losesAccessForOnIts`,`{{name}} loses access for {{ownerName}} on its next call. Linking it again needs the account-link flow from the start.`,{name:n.name,ownerName:n.ownerName}),confirmLabel:e(`access.linkedAppsSection.revoke`,`Revoke`),variant:`danger`})&&(l(null),d.mutate({id:n.id}))},g=d.isPending?d.variables?.id??null:null;return r(q,{notice:J(s,f.outcome),onDismissNotice:()=>{l(null),f.dismiss()},id:`linked-apps`,title:e(`access.linkedAppsSection.linkedApps`,`Linked apps`),icon:O,description:e(`access.linkedAppsSection.externalIntegrationsAlexaLinkedTo`,`External integrations (Alexa, …) linked to this hub through OAuth. Revoking one stops that integration on its next call. Already-revoked rows can be selected and removed from the list.`),children:r(Lt,{rows:p,label:e(`access.linkedAppsSection.linkedApps2`,`linked apps`),isLoading:o.isLoading,loadError:o.isError?o.error?.message??`Request failed`:null,emptyText:`No linked apps — an integration appears here once it completes the account-link flow.`,expiresNone:`—`,action:{label:e(`access.linkedAppsSection.revoke`,`Revoke`),icon:h,isAvailable:e=>e.status===`active`||e.status===`revoked`,onRun:e=>void m(e),busyId:g,disabled:d.isPending||f.busy},bulk:{revoke:f,noun:Ut,isSelectable:e=>e.status===`active`||e.status===`revoked`,quickSelect:[{label:e(`access.linkedAppsSection.selectRevoked`,`Select revoked`),match:e=>e.status===`revoked`}]}})})}var Kt=5e3;function qt(){let{t}=K(),n=V.useUtils(),i=V.auth.cliLoginPending.useQuery(void 0,{refetchInterval:Kt}),a=V.auth.cliLoginDeny.useMutation({onSuccess:()=>void n.auth.cliLoginPending.invalidate()}),o=i.data??[];if(o.length===0)return null;let s=Date.now();return e(`div`,{className:`space-y-2 rounded-md border border-border bg-background-elevated p-3`,"data-testid":`pending-terminal-signins`,children:[e(`div`,{className:`flex items-center gap-2 text-xs font-medium text-foreground`,children:[r(le,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),t(`cliLogin.pendingTitle`,`Pending terminal sign-ins`)]}),r(`ul`,{className:`space-y-1`,children:o.map(n=>{let i=dt(n.createdAt,s);return e(`li`,{className:`flex items-center justify-between gap-3 text-xs`,children:[e(`span`,{className:`min-w-0 truncate text-foreground-muted`,children:[n.userAgent??t(`cliLogin.unknownValue`,`Unknown`),` · `,n.ip??t(`cliLogin.unknownValue`,`Unknown`),` · `,i.key===`justNow`?t(`cliLogin.ageNow`,`just now`):i.key===`seconds`?t(`cliLogin.ageSeconds`,`{{count}} s ago`,{count:i.value}):t(`cliLogin.ageMinutes`,`{{count}} min ago`,{count:i.value})]}),r(W,{type:`button`,size:`sm`,variant:`ghost`,disabled:a.isPending,onClick:()=>a.mutate({requestId:n.requestId}),children:t(`cliLogin.notMe`,`Not me`)})]},n.requestId)})}),r(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`cliLogin.pendingHint`,`To approve one, open the approval page and type the code the terminal shows.`)})]})}s();var Jt={key:`access.nouns.session`};function Yt(){let{t}=K(),i=w(),o=V.useUtils(),s=Dt(),c=V.auth.listSessions.useQuery(),[l,u]=a(null),d=()=>void o.auth.listSessions.invalidate(),f=V.auth.revokeSessions.useMutation({onSuccess:d,onError:e=>u(`Sign out failed: ${e.message}`)}),p=_t(Jt,d),m=n(()=>(c.data??[]).map(e=>mt(e,s,{client:e=>vt(e).label,method:It})),[c.data,s]),h=async e=>{await i({title:t(`access.loginSessionsSection.signOutThisSession`,`Sign out this session`),message:t(`access.loginSessionsSection.onWillHaveToSign`,`{{ownerName}} on {{name}} will have to sign in again.`,{ownerName:e.ownerName,name:e.name}),confirmLabel:t(`access.loginSessionsSection.signOut`,`Sign out`),variant:`danger`})&&(u(null),f.mutate({id:e.id}))};return e(q,{notice:J(l,p.outcome),onDismissNotice:()=>{u(null),p.dismiss()},id:`login-sessions`,title:t(`access.loginSessionsSection.loginSessions`,`Login sessions`),icon:fe,description:t(`access.loginSessionsSection.everyBrowserAndAppSigned`,`Every browser and app signed in to this hub, for every user. Signing one out ends it at once; it has to sign in again. Your own current session is marked and never included in a bulk sign-out.`),children:[r(qt,{}),r(Lt,{rows:m,label:t(`common.sessionsLabel`),isLoading:c.isLoading,loadError:c.isError?c.error?.message??`Request failed`:null,emptyText:`No active sessions.`,action:{label:t(`access.loginSessionsSection.signOut`,`Sign out`),icon:j,isAvailable:e=>e.status===`active`,onRun:e=>void h(e),busyId:f.isPending&&f.variables!==void 0&&`id`in f.variables?f.variables.id:null,disabled:f.isPending||p.busy},bulk:{revoke:p,noun:Jt,isSelectable:e=>e.status===`active`}})]})}var Xt={"by-id":`helpers.authAuditWording.bulkNoun.credential`,"share-link":`helpers.authAuditWording.bulkNoun.shareLink`,"admin-token":`helpers.authAuditWording.bulkNoun.adminToken`,"login-session":`helpers.authAuditWording.bulkNoun.loginSession`};function Y(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function X(e,t){let n=Y(e,`tokenId`);return Y(e,`name`)??(n===null?void 0:t.get(n))??n??`?`}function Z(e){return e.filter(e=>e!==null)}function Zt(e){let t=Y(e,`prefix`);return t===null?null:G.t(`helpers.authAuditWording.prefix`,{prefix:t})}function Qt(e,t){let n=e.detail??{};switch(e.action){case`admin-token-created`:{let e=n.expiresAt;return{title:G.t(`helpers.authAuditWording.tokenCreated`,{name:X(n,t)}),details:Z([Zt(n),typeof e==`number`?G.t(`helpers.authAuditWording.expires`,{at:zt(e)}):null])}}case`admin-token-used`:{let e=Y(n,`path`);return{title:G.t(`helpers.authAuditWording.tokenUsed`,{name:X(n,t)}),details:Z([Zt(n),e===null?null:G.t(`helpers.authAuditWording.call`,{path:e})])}}case`token-minted`:{let e=n.expiresAt;return{title:G.t(`helpers.authAuditWording.tokenMinted`,{name:X(n,t)}),details:Z([typeof e==`number`?G.t(`helpers.authAuditWording.expires`,{at:zt(e)}):null])}}case`token-revoked`:return{title:G.t(`helpers.authAuditWording.anyTokenRevoked`,{name:X(n,t)}),details:[]};case`admin-token-revoked`:return{title:G.t(`helpers.authAuditWording.tokenRevoked`,{name:X(n,t)}),details:Z([Zt(n)])};case`credentials-revoked`:{let e=Y(n,`kind`)??`credential`,t=n.revoked,r=n.skipped,i=Xt[e],a=i===void 0?`${e}s`:G.t(i);return{title:G.t(`helpers.authAuditWording.bulkRevoked`,{n:typeof t==`number`?String(t):`?`,noun:a}),details:Z([typeof r==`number`&&r>0?G.t(`helpers.authAuditWording.skipped`,{count:r}):null,Y(n,`ids`)===null?null:G.t(`helpers.authAuditWording.ids`,{ids:Y(n,`ids`)??``})])}}case`second-factor-skipped`:{let e=Y(n,`method`),t=Y(n,`factors`);return{title:G.t(`helpers.authAuditWording.secondFactorSkipped`),details:Z([e===null?null:G.t(`helpers.authAuditWording.signedInWith`,{method:It(e)}),t===null?null:G.t(`helpers.authAuditWording.skippedFactors`,{factors:t.split(`,`).join(`, `)})])}}default:return{title:e.action,details:Object.entries(n).map(([e,t])=>`${e}: ${String(t)}`)}}}s();var $t=100;function en(){let{user:e}=rt();return e?.isAdmin?r(nn,{}):null}function tn(){let{data:e}=Oe(),{data:t}=V.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 nn(){let{t}=K(),n=V.auth.listAuthAudit.useQuery({limit:$t}),{userNameById:i,tokenNameById:a}=tn(),o=n.data??[];return e(`div`,{"data-testid":`auth-audit`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[e(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[r(g,{className:`h-3.5 w-3.5 text-foreground-subtle`}),r(`div`,{className:`text-xs font-semibold text-foreground`,children:t(`auth.authAuditSection.authenticationAudit`,`Authentication audit`)}),r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:t(`auth.authAuditSection.latest`,{count:$t})})]}),r(`div`,{className:`p-4`,children:n.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(k,{className:`h-3.5 w-3.5 animate-spin`}),t(`auth.authAuditSection.loadingAuditTrail`,`Loading audit trail…`)]}):n.isError?e(`div`,{className:`text-[11px] text-danger`,children:[t(`auth.authAuditSection.couldNotLoadTheAudit`,`Could not load the audit trail:`),` `,n.error?.message??t(`auth.authAuditSection.requestFailed`,`Request failed`)]}):o.length===0?e(`div`,{className:`rounded border border-dashed border-border px-3 py-4 text-xs text-foreground-subtle text-center space-y-1`,children:[r(`div`,{children:t(`auth.authAuditSection.noAuthenticationEventsRecordedYet`,`No authentication events recorded yet.`)}),r(`div`,{className:`text-[11px] text-foreground-subtle/90`,children:t(`auth.authAuditSection.thisTrailRecordsAdminToken`,`This trail records admin-token create/use/revoke, trusted-network 2FA skips, and credential revokes (including single share-link revoke). Browser password logins are not listed here.`)})]}):r(`ul`,{className:`divide-y divide-border rounded-md border border-border max-h-[420px] overflow-y-auto`,children:o.map(e=>r(rn,{record:e,userName:e.userId===void 0?null:i.get(e.userId)??e.userId,tokenNameById:a},e.id))})})]})}function rn({record:t,userName:n,tokenNameById:i}){let a=Qt(t,i);return e(`li`,{"data-testid":`auth-audit-row`,className:`px-3 py-2 text-xs space-y-0.5`,children:[e(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[r(`span`,{className:`font-medium text-foreground`,children:a.title}),r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:zt(t.at)})]}),e(`div`,{className:`flex flex-wrap gap-x-3 text-[11px] text-foreground-subtle`,children:[n!==null&&r(`span`,{className:`text-foreground`,children:n}),t.ip!==void 0&&r(`span`,{className:`font-mono`,children:t.ip}),a.details.map(e=>r(`span`,{className:`font-mono`,children:e},e))]})]})}s();var Q={loginSessions:`login-sessions`,linkedApps:`linked-apps`,tokens:`tokens`,scopedTokens:`scoped-tokens`,adminTokens:`admin-tokens`,shareLinks:`share-links`,externalIdentities:`external-identities`,audit:`auth-audit`},an={[Q.scopedTokens]:Q.tokens,[Q.adminTokens]:Q.tokens,[Q.shareLinks]:Q.tokens};function on(){return[{id:Q.loginSessions,label:G.t(`system.access.loginSessions`,`Login sessions`),icon:fe,render:()=>r(Yt,{})},{id:Q.linkedApps,label:G.t(`system.access.linkedApps`,`Linked apps`),icon:O,render:()=>r(Gt,{})},{id:Q.tokens,label:G.t(`system.access.tokens`,`Tokens`),icon:M,render:({createRequested:e,onCreateConsumed:t})=>r(Tt,{headerOwnsCreate:!0,createRequested:e,onCreateConsumed:t})},{id:Q.externalIdentities,label:G.t(`system.access.signInLinks`,`Sign-in links`),icon:ce,render:()=>r(Ht,{})},{id:Q.audit,label:G.t(`system.access.audit`,`Audit`),icon:g,render:()=>r(en,{})}]}function sn({createRequested:t=!1,onCreateConsumed:i}){let{t:a}=K(),o=n(()=>on(),[]),s=Bt({ids:n(()=>o.map(e=>e.id),[o]),answered:!0}),c=nt(),[l]=it(),u=l.get(`integration`),d=u===null?void 0:an[u];if(d!==void 0){let e=new URLSearchParams(l);return e.set(`integration`,d),r(at,{to:`?${e.toString()}`,replace:!0})}let f=o.find(e=>e.id===s.selectedId)??o[0];return e(`div`,{className:`flex flex-col gap-3`,"data-testid":`access-page`,children:[r(Fe,{appearance:`pills`,value:f?.id??Q.loginSessions,onValueChange:e=>{c(`?${ct(l,e,null,null).toString()}`)},children:r(Ue,{"aria-label":a(`system.access.credentialKinds`,`Credential kinds`),children:o.map(t=>e(Je,{value:t.id,"data-testid":`access-kind-${t.id}`,children:[r(t.icon,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),t.label]},t.id))})}),f===void 0?null:r(`div`,{role:`region`,"aria-label":f.label,"data-testid":`access-kind-body`,children:f.render({createRequested:t&&f.id===Q.tokens,onCreateConsumed:i??(()=>void 0)})},f.id)]})}function cn(t,n){if(t===Q.tokens)return e(W,{size:`sm`,type:`button`,"data-testid":`access-new-token`,onClick:n,children:[r(M,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),G.t(`system.access.newToken`,`New token`)]})}function ln(){let[e,t]=a(!1);return{createRequested:e,requestCreate:()=>t(!0),clearCreate:()=>t(!1)}}function un({isPending:t,error:n,what:i,onRetry:a,children:o}){let{t:s}=K();return t?e(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,role:`status`,"data-testid":`query-pending`,children:[r(k,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),s(`certificates.queryBody.reading`,{what:i})]}):n===null?o:r(L,{title:s(`certificates.queryBody.couldNotRead`,`Could not read {{what}}`,{what:i}),message:n.message.length>0?n.message:s(`certificates.queryBody.requestFailed`,`Request failed`),onRetry:a})}function dn(){let{t}=K(),n=V.deviceCredentials.getDeviceCaStatus.useQuery({}),i=n.data;return r(q,{id:`device-ca`,title:t(`certificates.deviceCaCard.deviceCertificateAuthority`,`Device certificate authority`),icon:ae,description:t(`certificates.deviceCaCard.signsTheCertificateEachPaired`,`Signs the certificate each paired device holds. It is created the first time a device is paired.`),children:r(un,{isPending:n.isPending,error:n.error,what:`the device CA`,onRetry:()=>void n.refetch(),children:i!==void 0&&e(`div`,{className:`space-y-1`,"data-testid":`device-ca-status`,children:[e(B,{label:t(`certificates.deviceCaCard.state`,`State`),children:[i.state===`ready`&&r(P,{variant:`success`,children:t(`certificates.deviceCaCard.ready`,`Ready`)}),i.state===`absent`&&r(P,{variant:`default`,children:t(`certificates.deviceCaCard.notCreatedYet`,`Not created yet`)}),i.state===`unavailable`&&r(P,{variant:`danger`,children:t(`certificates.deviceCaCard.unavailable`,`Unavailable`)})]}),i.state===`ready`&&e(l,{children:[r(B,{label:t(`certificates.deviceCaCard.subject`,`Subject`),valueClassName:`font-mono`,children:i.subject}),r(B,{label:t(`certificates.deviceCaCard.fingerprintSha256`,`Fingerprint (SHA-256)`),valueClassName:`font-mono`,children:i.fingerprintSha256}),r(B,{label:t(`certificates.deviceCaCard.validUntil`,`Valid until`),children:i.validTo})]}),i.state===`unavailable`&&r(B,{label:t(`certificates.deviceCaCard.reason`,`Reason`),children:r(`span`,{className:`text-danger`,children:i.reason})})]})})})}s();function fn(){let{t}=K(),n=V.useUtils(),i=V.deviceCredentials.getDeviceCertificateSettings.useQuery({}),[o,s]=a(null),c=V.deviceCredentials.setDeviceCertificateSettings.useMutation({onSuccess:()=>{s(null),n.deviceCredentials.getDeviceCertificateSettings.invalidate()},onError:e=>s(`Could not save: ${e.message}`)});return r(un,{isPending:i.isPending,error:i.error,what:`the enrollment setting`,onRetry:()=>void i.refetch(),children:i.data!==void 0&&e(B,{label:t(`certificates.deviceSettingsRow.usersCanEnrollTheirOwn`,`Users can enroll their own devices`),actions:r(Re,{checked:i.data.selfEnrollment===`allowed`,disabled:c.isPending,"aria-label":t(`certificates.deviceSettingsRow.usersCanEnrollTheirOwn`,`Users can enroll their own devices`),onCheckedChange:e=>c.mutate({selfEnrollment:e?`allowed`:`disabled`})}),children:[r(`span`,{className:`text-[11px] text-foreground-subtle`,children:i.data.selfEnrollment===`allowed`?t(`certificates.deviceSettingsRow.allowedAUserSignedIn`,`Allowed - a user signed in on a phone can keep it signed in. Pairing by QR works either way.`):t(`certificates.deviceSettingsRow.disabledOnlyAnAdminCan`,`Disabled - only an admin can pair a device, with a QR code.`)}),o!==null&&r(`span`,{className:`block text-[11px] text-danger`,children:o})]})})}s();function pn(e){let[t,n]=a(()=>Date.now());return i(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}s();var mn=80,hn=208;function gn({open:t,users:n,onClose:i,onPaired:o}){let{t:s}=K(),c=V.deviceCredentials.startEnrollment.useMutation({onSuccess:o}),[l,u]=a(``),[d,f]=a(``),p=l===``?n[0]?.id??``:l,m=c.data,h=()=>{c.reset(),f(``),i()};return r(ge,{open:t,onClose:h,title:s(`certificates.pairDeviceDialog.pairADevice`,`Pair a device`),icon:D,width:`md`,testId:`pair-device-dialog`,error:c.isError?c.error.message:null,footer:m===void 0?e(W,{type:`button`,onClick:()=>{let e=d.trim();p===``||e===``||c.mutate({userId:p,deviceName:e})},disabled:c.isPending||p===``||d.trim()===``,children:[c.isPending&&r(k,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),s(`certificates.pairDeviceDialog.createPairingCode`,`Create pairing code`)]}):r(W,{type:`button`,variant:`outline`,onClick:h,children:s(`certificates.pairDeviceDialog.done`,`Done`)}),children:m===void 0?e(`div`,{className:`space-y-3`,children:[r(`p`,{className:`text-[11px] text-foreground-subtle`,children:s(`certificates.pairDeviceDialog.createsAOneTimeCode`,`Creates a one-time code for a phone you hold. Scan it with the CamStack app on that phone; the phone then stays signed in as the chosen user until you revoke it.`)}),r(U,{label:s(`certificates.pairDeviceDialog.user`,`User`),required:!0,children:r(re,{value:p,onChange:e=>u(e.target.value),options:n.map(e=>({value:e.id,label:e.username}))})}),r(U,{label:s(`certificates.pairDeviceDialog.deviceName`,`Device name`),required:!0,description:s(`certificates.pairDeviceDialog.howThisPhoneIsListed`,`How this phone is listed, e.g. Anna's iPhone.`),children:r(We,{value:d,maxLength:mn,onChange:e=>f(e.target.value),placeholder:s(`certificates.pairDeviceDialog.annaSIphone`,`Anna's iPhone`),autoFocus:!0})})]}):r(_n,{enrollUrl:m.enrollUrl,expiresAt:m.expiresAt,hubKnown:m.hubOrigin!==null,onRestart:()=>c.reset()})})}function _n({enrollUrl:t,expiresAt:n,hubKnown:i,onRestart:a}){let{t:o}=K(),s=jt(n,pn(1e3));return r(`div`,{className:`space-y-3`,"data-testid":`pair-issued`,children:e(`div`,{className:`flex flex-col items-center gap-3 sm:flex-row sm:items-start`,children:[r(`div`,{className:s.expired?`opacity-30`:void 0,children:r(xe,{value:t,size:hn,alt:o(`certificates.pairDeviceDialog.enrollmentQrCode`,`Enrollment QR code`)})}),e(`div`,{className:`min-w-0 flex-1 space-y-2`,children:[r(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`certificates.pairDeviceDialog.openTheCamstackAppOn`,`Open the CamStack app on the phone and scan this code. It works once.`)}),r(`div`,{className:`text-sm font-semibold tabular-nums text-foreground`,role:`timer`,"data-testid":`pair-countdown`,children:s.expired?o(`certificates.pairDeviceDialog.expiredCreateANewCode`,`Expired - create a new code`):o(`certificates.pairDeviceDialog.expiresIn`,`Expires in {{label}}`,{label:s.label})}),e(`div`,{className:`flex items-center gap-1 rounded-md border border-border bg-background px-2 py-1`,children:[r(`code`,{className:`min-w-0 flex-1 select-all break-all font-mono text-[11px] text-foreground`,children:t}),r(me,{value:t,srLabel:`Enrollment link`})]}),!i&&e(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-2.5 py-1.5 text-[11px] text-foreground`,children:[r(_,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),r(`span`,{children:o(`certificates.pairDeviceDialog.theHubCouldNotName`,`The hub could not name an address for this link, so the app must already know it.`)})]}),s.expired&&r(W,{type:`button`,variant:`outline`,size:`sm`,onClick:a,children:o(`certificates.pairDeviceDialog.newCode`,`New code`)})]})]})})}s();var vn={key:`access.nouns.device`};function yn({pairOpen:t,onPairClose:i}){let{t:o}=K(),s=w(),c=te(),l=V.useUtils(),u=V.deviceCredentials.listDeviceCredentials.useQuery({includeRevoked:!0}),d=Oe(),[f,p]=a(null),[m,g]=a(null),_=()=>void l.deviceCredentials.listDeviceCredentials.invalidate(),v=e=>t=>{g(null),p(`${e} failed: ${t.message}`)},b=()=>{g(null),_()},x=V.deviceCredentials.revokeDeviceCredential.useMutation({onSuccess:b,onError:v(`Revoke`)}),S=V.deviceCredentials.deleteDeviceCredential.useMutation({onSuccess:e=>{e.result!==`deleted`&&p(e.result===`live`?`Only a revoked device can be deleted: revoke it first.`:`That device no longer exists.`),b()},onError:v(`Delete`)}),C=V.deviceCredentials.renameDeviceCredential.useMutation({onSuccess:b,onError:v(`Rename`)}),T=ht(vn,e=>x.mutateAsync({id:e}),_),E=T.busy||m!==null,ee=n(()=>(u.data??[]).map(At),[u.data]),re=async e=>{await s({title:o(`certificates.devicesCard.revoke`,`Revoke "{{name}}"?`,{name:e.name}),message:o(`certificates.devicesCard.sDeviceStopsSigningIn`,`{{ownerName}}'s device stops signing in at once and its open sessions end. To use it again it has to be paired anew. This cannot be undone.`,{ownerName:e.ownerName}),confirmLabel:o(`certificates.devicesCard.revoke2`,`Revoke`),variant:`danger`})&&(p(null),g(e.id),x.mutate({id:e.id}))},ie=async e=>{await s({title:o(`certificates.devicesCard.delete`,`Delete "{{name}}"?`,{name:e.name}),message:o(`certificates.devicesCard.isRemovedFromTheList`,`{{name}} is removed from the list. The audit trail keeps the revocation.`,{name:e.name}),confirmLabel:o(`common.delete`,`Delete`),variant:`danger`})&&(p(null),g(e.id),S.mutate({id:e.id}))},O=async e=>{let t=(await c({title:o(`certificates.devicesCard.renameDevice`,`Rename device`),label:o(`certificates.devicesCard.deviceName`,`Device name`),defaultValue:e.name,confirmLabel:o(`certificates.devicesCard.rename`,`Rename`)}))?.trim()??``;t===``||t===e.name||(p(null),g(e.id),C.mutate({id:e.id,deviceName:t}))},k={label:o(`certificates.devicesCard.revoke2`,`Revoke`),icon:ne,isAvailable:yt,onRun:e=>void re(e),busyId:x.isPending?m:null,disabled:E},ae=[{label:o(`certificates.devicesCard.rename`,`Rename`),icon:y,tone:`neutral`,isAvailable:()=>!0,onRun:e=>void O(e),busyId:C.isPending?m:null,disabled:E},{label:o(`common.delete`,`Delete`),icon:h,isAvailable:Et,onRun:e=>void ie(e),busyId:S.isPending?m:null,disabled:E}];return e(q,{id:`devices`,title:o(`certificates.devicesCard.devices`,`Devices`),icon:D,description:o(`certificates.devicesCard.phonesThatStaySignedIn`,`Phones that stay signed in with a certificate instead of a login. Revoking one signs it out at once; it has to be paired again.`),notice:J(f,T.outcome),onDismissNotice:()=>{p(null),T.dismiss()},children:[r(fn,{}),r(Lt,{rows:ee,label:o(`certificates.devicesCard.label`),isLoading:u.isPending,loadError:u.error===null?null:u.error.message||`Request failed`,emptyText:`No devices paired yet.`,expiresNone:`—`,action:k,extraActions:ae,bulk:{revoke:T,noun:vn,isSelectable:yt}}),r(gn,{open:t,users:d.data??[],onClose:i,onPaired:_})]})}var bn=/-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----/,xn=/-----BEGIN ((?:RSA |EC |ENCRYPTED )?PRIVATE KEY)-----[\s\S]+?-----END \1-----/,Sn={certificate:`.pem,.crt,.cer`,privateKey:`.pem,.key`,ca:`.pem,.crt,.cer`};function Cn(e,t){if(t.trim()===``)return null;if(e===`privateKey`){let e=xn.exec(t);return e===null?bn.test(t)?G.t(`helpers.pemFile.isCert`):G.t(`helpers.pemFile.notKey`):e[1]===`ENCRYPTED PRIVATE KEY`?G.t(`helpers.pemFile.encrypted`):null}return bn.test(t)?e===`certificate`&&xn.test(t)?G.t(`helpers.pemFile.certHasKey`):null:xn.test(t)?G.t(`helpers.pemFile.isKey`):G.t(`helpers.pemFile.notCert`)}function wn(e){return e.text()}s();function Tn({kind:n,label:i,value:o,onChange:s,rows:c=6}){let{t:l}=K(),u=t(null),[d,f]=a(null),[p,m]=a(null),h=p??Cn(n,o),g=`pem-${n}`,_=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t!==void 0){f(t.name);try{let e=await wn(t);m(null),s(e)}catch(e){m(`Could not read ${t.name}: ${e instanceof Error?e.message:String(e)}`)}}};return e(`div`,{className:`space-y-1`,children:[e(`div`,{className:`flex items-center justify-between gap-2`,children:[r(`label`,{htmlFor:g,className:`text-[11px] text-foreground-subtle`,children:i}),e(`div`,{className:`flex min-w-0 items-center gap-2`,children:[d!==null&&r(`span`,{className:`truncate font-mono text-[10px] text-foreground-subtle`,"data-testid":`${g}-file-name`,children:d}),r(Ne,{ref:u,accept:Sn[n],onChange:e=>void _(e),className:`hidden`,"data-testid":`${g}-file`}),e(W,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>u.current?.click(),children:[r(ue,{className:`mr-1 h-3 w-3`}),l(`system.pemField.chooseFile`,`Choose file`)]})]})]}),r(Pe,{id:g,value:o,onChange:e=>{f(null),m(null),s(e.target.value)},rows:c,"aria-invalid":h!==null,className:`w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`}),h!==null&&r(`p`,{className:`text-[11px] text-danger`,role:`alert`,children:h})]})}s();var En=30;function Dn(e){let t=Date.parse(e);return!Number.isNaN(t)&&Date.now()-t<En*864e5}function On(e){if(e===null||e===``)return`—`;let t=e.replace(/:/g,``);return t.length<=16?e:`${t.slice(0,8)}…${t.slice(-8)}`}function kn(){let{t}=K(),n=c(),i=Qe(void 0,{refetchInterval:15e3}),o=Ze({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),s=Ye({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),l=Be({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),u=Se({onSuccess:()=>{m(!1),g(``),v(``),x(``),n.invalidateQueries({queryKey:[[`localNetwork`]]})}}),d=i.data,[p,m]=a(!1),[h,g]=a(``),[_,v]=a(``),[y,x]=a(``),S=()=>{if(!d?.caCertPem)return;let e=new Blob([d.caCertPem],{type:`application/x-pem-file`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`camstack-ca.crt`,n.click(),URL.revokeObjectURL(t)},C=d?.mode===`uploaded`?`Uploaded`:d?.mode===`generated`?`Generated local CA`:`TLS disabled`;return r(ye,{headingId:`local-access-certificate`,title:t(`system.localAccess.certificate`,`Certificate`),icon:b,children:e(`div`,{className:`${f} space-y-3`,children:[i.isError&&r(`p`,{className:`text-xs text-danger`,children:t(`system.localAccess.couldNotReadTlsStatus`,`Could not read TLS status.`)}),d?.reissueError&&r(L,{variant:`warning`,title:t(`system.localAccess.certificateReissue`,`Certificate reissue`),message:d.reissueError}),d?.restartRequired&&r(L,{variant:`warning`,title:t(`system.localAccess.restartRequired`,`Restart required`),message:t(`system.localAccess.theHttpsListenerStillServes`,`The HTTPS listener still serves the previous certificate. Restart the hub to apply it.`)}),d?.caMissing===!0&&r(L,{variant:`warning`,title:t(`system.localAccess.caMissingTitle`,`CA missing - devices cannot trust this hub`),message:t(`system.localAccess.caMissingBody`,"The uploaded certificate was not issued by a public CA and no CA was stored with it, so Download CA has nothing to hand out. Upload the certificate again together with its CA (for mkcert, the rootCA.pem in the folder `mkcert -CAROOT` prints).")}),d?.caReplacedAt!=null&&Dn(d.caReplacedAt)&&r(L,{variant:`warning`,title:t(`system.localAccess.caReplacedTitle`,`The local CA was replaced - re-install it on your devices`),message:t(`system.localAccess.caReplacedBody`,`The previous local CA had no name constraints: if its key ever leaked it could vouch for any website. The hub now uses a CA limited to private addresses and local names. Download it again and trust it on every phone and computer that used the old one (replaced {{when}}).`,{when:new Date(d.caReplacedAt).toLocaleString()})}),e(`dl`,{className:`grid grid-cols-1 gap-2 text-xs sm:grid-cols-2`,children:[e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.mode`,`Mode`)}),r(`dd`,{className:`font-medium`,children:C})]}),e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.validTo`,`Valid to`)}),r(`dd`,{className:`font-mono`,children:d?.validTo?new Date(d.validTo).toLocaleString():`—`})]}),e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.leafSha256`,`Leaf SHA-256`)}),r(`dd`,{className:`font-mono`,title:d?.leafFingerprintSha256??void 0,children:On(d?.leafFingerprintSha256??null)})]}),d?.storedUpload!=null&&e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.storedUpload`,`Stored upload`)}),r(`dd`,{className:`font-medium`,children:t(`system.localAccess.storedUploadValue`,`valid to {{validTo}}, {{ca}}`,{validTo:new Date(d.storedUpload.validTo).toLocaleDateString(),ca:d.storedUpload.hasCa?t(`system.localAccess.storedUploadWithCa`,`with its CA`):t(`system.localAccess.storedUploadNoCa`,`no CA`)})})]}),e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.caSha256`,`CA SHA-256`)}),r(`dd`,{className:`font-mono`,title:d?.caFingerprintSha256??void 0,children:d?.mode===`uploaded`&&d.caFingerprintSha256===null?r(`span`,{className:`font-sans text-foreground-subtle`,children:t(`system.localAccess.issuerNotIncludedInThe`,`Issuer not included in the upload (not the local CA)`)}):On(d?.caFingerprintSha256??null)})]})]}),d&&d.sans.length>0&&r(`div`,{className:`flex flex-wrap gap-1`,children:d.sans.map(e=>r(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 font-mono text-[10px] text-foreground-subtle`,children:e},e))}),e(`div`,{className:`flex flex-wrap gap-2`,children:[r(ze,{label:t(`system.localAccess.regenerate`,`Regenerate`),title:t(`system.localAccess.issueANewLeaf`,`Issue a new leaf?`),description:t(`system.localAccess.issuesANewLeafUnder`,`Issues a new leaf under the current local CA. Clients that trust the CA keep working. The HTTPS listener reloads.`),confirmLabel:t(`system.localAccess.regenerate`,`Regenerate`),disabled:d?.mode===`uploaded`||o.isPending,action:()=>o.mutateAsync({})}),r(W,{size:`sm`,variant:`outline`,onClick:()=>m(e=>!e),children:t(`system.localAccess.upload`,`Upload`)}),d?.caCertPem&&r(W,{size:`sm`,variant:`outline`,onClick:S,children:t(`system.localAccess.downloadCa`,`Download CA`)}),d?.mode===`uploaded`&&r(ze,{label:t(`system.localAccess.revertToGenerated`,`Revert to generated`),title:t(`system.localAccess.revertTitle`,`Switch back to the generated certificate?`),description:t(`system.localAccess.keepsTheUploadedPair`,`Returns to the generated local CA. The uploaded certificate and its CA stay stored here; you can select them again.`),confirmLabel:t(`system.localAccess.revert`,`Revert`),disabled:s.isPending,action:()=>s.mutateAsync({})}),d?.mode===`generated`&&d.storedUpload!=null&&r(ze,{label:t(`system.localAccess.useUploaded`,`Use uploaded certificate`),title:t(`system.localAccess.useUploadedTitle`,`Serve the stored upload again?`),description:t(`system.localAccess.useUploadedDescription`,`The stored uploaded certificate replaces the generated one on the HTTPS listener. The generated certificate stays stored.`),confirmLabel:t(`system.localAccess.useUploaded`,`Use uploaded certificate`),disabled:l.isPending,action:()=>l.mutateAsync(void 0)})]}),p&&e(`div`,{className:`space-y-2 border-t border-border pt-3`,children:[r(Tn,{kind:`certificate`,label:t(`system.localAccess.certificateOrFullChainPem`,`Certificate or full chain (PEM)`),value:h,onChange:g}),r(Tn,{kind:`privateKey`,label:t(`system.localAccess.privateKeyPem`,`Private key (PEM)`),value:_,onChange:v}),r(Tn,{kind:`ca`,label:t(`system.localAccess.caPemRequired`,`CA (PEM) - required unless the certificate comes from a public CA`),value:y,onChange:x,rows:4}),r(W,{size:`sm`,disabled:!h.trim()||!_.trim()||Cn(`certificate`,h)!==null||Cn(`privateKey`,_)!==null||Cn(`ca`,y)!==null||u.isPending,onClick:()=>u.mutate({certPem:h,keyPem:_,...y.trim()?{caPem:y}:{}}),children:t(`system.localAccess.saveCertificate`,`Save certificate`)}),u.isError&&r(`p`,{className:`text-xs text-danger`,children:u.error instanceof Error?u.error.message:t(`system.localAccess.uploadFailed`,`Upload failed`)})]})]})})}var An={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`};function jn(e){let t=e.find(e=>e.isHub);return t?.https.kind===`served`?t.https.status.caFingerprintSha256:null}function Mn({https:t,mesh:n,now:i}){let{t:a}=K(),o=Qe().data?.caCertPem??``,s=()=>{if(o===``)return;let e=URL.createObjectURL(new Blob([o],{type:`application/x-pem-file`})),t=document.createElement(`a`);t.href=e,t.download=`camstack-ca.crt`,t.click(),URL.revokeObjectURL(e)},c=n?.ca,l=c?.state===`ready`?Date.parse(c.validTo):null,u=n?.listener;return e(`div`,{className:`space-y-1`,"data-testid":`ca-strip`,children:[r(B,{label:a(`certificates.caStrip.localHttpsCaSha256`,`Local HTTPS CA (SHA-256)`),valueClassName:`font-mono`,children:e(`span`,{className:`flex flex-wrap items-center gap-2`,children:[jn(t)??`—`,o!==``&&e(W,{type:`button`,variant:`ghost`,size:`sm`,onClick:s,children:[r(x,{className:`h-3 w-3`,"aria-hidden":!0}),a(`certificates.caStrip.downloadCa`,`Download CA`)]})]})}),r(B,{label:a(`certificates.caStrip.clusterCaSha256`,`Cluster CA (SHA-256)`),valueClassName:`font-mono`,children:c===void 0?`—`:c.state===`ready`?c.fingerprintSha256:r(`span`,{className:`text-danger`,children:a(`certificates.caStrip.unavailable`,{reason:c.reason})})}),c?.state===`ready`&&e(B,{label:a(`certificates.caStrip.clusterCaValidUntil`,`Cluster CA valid until`),children:[c.validTo,l!==null&&!Number.isNaN(l)&&e(`span`,{className:`ml-2 text-[10px] ${An[Ft(l,i)]}`,children:[`(`,xt(l,i),`)`]})]}),u!==void 0&&e(B,{label:a(`certificates.caStrip.nodeListener`,`Node listener`),children:[u.state===`open`&&r(P,{variant:`success`,children:a(`certificates.caStrip.open`,`Open`)}),u.state===`not-started`&&r(P,{variant:`default`,children:a(`certificates.caStrip.notStarted`,`Not started`)}),u.state===`closed`&&e(`span`,{className:`text-danger`,children:[a(`certificates.caStrip.closedSince`,{when:St(u.since)}),` `,u.reason]})]}),n!==void 0&&!n.registryAvailable&&e(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-2.5 py-1.5 text-[11px] text-foreground`,children:[r(_,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),r(`span`,{children:a(`certificates.caStrip.theCertificateRegistryIsNot`,`The certificate registry is not up, so the node list below is incomplete.`)})]})]})}function Nn(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 Pn(e){return e.isHub?G.t(`helpers.nodesModel.hubReissued`):e.mesh===null?G.t(`helpers.nodesModel.noCertRecorded`):e.online?null:G.t(`helpers.certificateModel.nodeOffline`)}function Fn(e){return e.isHub||e.mesh===null?Pn(e):null}var In={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`},Ln={enroll:`Issued at enrollment`,renewal:`Issued by a renewal`,boot:`Issued at boot`,pairing:`Issued at pairing`,observed:`Observed on its connection`},Rn={uploaded:`Uploaded`,generated:`Generated`,disabled:`Disabled`};function zn(e){let t=e.https?.https;return t?.kind===`served`?Nt(t.status.validTo):null}function Bn({ms:t,now:n}){return t===null?r(`span`,{className:`text-foreground-subtle`,children:`—`}):e(`div`,{children:[r(`div`,{children:St(t)}),r(`div`,{className:`text-[10px] ${In[Ft(t,n)]}`,children:xt(t,n)})]})}function Vn({row:t}){let{t:n}=K(),i=t.https?.https;return i===void 0?r(`span`,{className:`text-foreground-subtle`,children:`—`}):i.kind===`served`?e(`div`,{title:i.status.leafFingerprintSha256??``,children:[r(P,{variant:`success`,className:`text-[10px]`,children:n(`certificates.nodesColumns.served`,`Served`)}),r(`span`,{className:`ml-1.5 text-[10px] text-foreground-subtle`,children:Rn[i.status.mode]}),r(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:Mt(i.status.leafFingerprintSha256)}),i.status.sans.length>0&&r(`div`,{className:`mt-0.5 max-w-[14rem] truncate font-mono text-[10px] text-foreground-subtle`,title:i.status.sans.join(`, `),children:i.status.sans.join(`, `)})]}):e(`div`,{className:`max-w-[16rem]`,children:[r(P,{variant:i.kind===`unreadable`?`danger`:`warning`,className:`text-[10px]`,children:i.kind===`unreadable`?n(`certificates.nodesColumns.unreadable`,`Unreadable`):n(`certificates.nodesColumns.notServed`,`Not served`)}),r(`div`,{className:`mt-1 whitespace-normal text-[10px] text-foreground-subtle`,children:i.reason})]})}function Hn({row:t}){let{t:n}=K(),i=t.mesh?.current??null;if(i===null)return r(`span`,{className:`text-foreground-subtle`,children:n(`certificates.nodesColumns.noneRecorded`,`None recorded`)});let a=t.mesh?.history.length??0;return e(`div`,{children:[r(`div`,{className:`font-mono text-[11px]`,title:i.serial,children:kt(i.serial)}),r(`div`,{className:`font-mono text-[10px] text-foreground-subtle`,title:i.fingerprintSha256,children:Mt(i.fingerprintSha256)}),e(`div`,{className:`text-[10px] text-foreground-subtle`,children:[Ln[i.issuedVia],a>0?` · ${n(`certificates.nodesColumns.earlier`,{count:a})}`:``]})]})}function Un({row:e}){let{t}=K(),n=e.mesh?.presentingCurrent??null;return n===null?r(`span`,{className:`text-foreground-subtle`,children:e.online?`—`:t(`certificates.nodesColumns.offline`,`Offline`)}):n?r(P,{variant:`success`,className:`text-[10px]`,children:t(`common.yes`,`Yes`)}):r(P,{variant:`warning`,className:`text-[10px]`,children:t(`certificates.nodesColumns.noPresentsAnother`,`No - presents another`)})}function Wn(t){let n=t.icon;return e(W,{type:`button`,variant:`ghost`,size:`sm`,className:t.danger?`text-danger hover:bg-danger/10`:void 0,disabled:t.reason!==null||t.busy,title:t.reason??void 0,"aria-label":t.ariaLabel,onClick:t.onClick,children:[t.spinning?r(k,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):r(n,{className:`h-3 w-3`,"aria-hidden":!0}),t.label]})}function Gn({reasons:t}){let{t:n}=K();return e(qe,{className:`inline-block`,children:[r(Me,{children:r(`span`,{className:`cursor-help text-[11px] text-foreground-subtle`,"data-testid":`hub-managed-note`,children:n(`certificates.nodesColumns.managedByTheHub`,`Managed by the hub`)})}),r(Le,{children:r(`ul`,{className:`max-w-xs space-y-1 whitespace-normal text-left text-[11px]`,children:t.map(e=>r(`li`,{children:e},e))})})]})}function Kn({row:t,o:n}){let{t:i}=K(),a=t.https===null?`No HTTPS inventory for this node.`:Ct(t.https).reason,o=Pn(t),s=Fn(t),c=e=>n.running?.nodeId===t.nodeId&&n.running.action===e,l=e=>!t.isHub||e===null,u=[a,o,s].filter((e,t,n)=>e!==null&&n.indexOf(e)===t);return e(`div`,{className:`flex w-44 flex-col items-end gap-1`,children:[e(`div`,{className:`flex flex-col items-end gap-0.5`,children:[l(a)&&r(Wn,{label:i(`certificates.nodesColumns.renewHttps`,`Renew HTTPS`),ariaLabel:i(`certificates.nodesColumns.renewTheCertificateOn`,`Renew the certificate on {{nodeId}}`,{nodeId:t.nodeId}),icon:p,reason:a,busy:n.busy,spinning:c(`renew-https`),danger:!1,onClick:()=>n.onRenewHttps(t)}),l(o)&&r(Wn,{label:c(`renew-identity`)?i(`certificates.nodesColumns.renewing`,`Renewing…`):i(`certificates.nodesColumns.renewIdentity`,`Renew identity`),ariaLabel:i(`certificates.nodesColumns.renewTheClusterCertificateOf`,`Renew the cluster certificate of {{nodeId}}`,{nodeId:t.nodeId}),icon:p,reason:o,busy:n.busy,spinning:c(`renew-identity`),danger:!1,onClick:()=>n.onRenewIdentity(t)}),l(s)&&r(Wn,{label:i(`certificates.nodesColumns.revokeIdentity`,`Revoke identity`),ariaLabel:i(`certificates.nodesColumns.revokeTheClusterCertificateOf`,`Revoke the cluster certificate of {{nodeId}}`,{nodeId:t.nodeId}),icon:ne,reason:s,busy:n.busy,spinning:c(`revoke-identity`),danger:!0,onClick:()=>n.onRevokeIdentity(t)})]}),t.isHub&&u.length>0&&r(Gn,{reasons:u}),!t.isHub&&a!==null&&t.https!==null&&r(`div`,{className:`w-full whitespace-normal text-right text-[10px] text-foreground-subtle`,"data-testid":`renew-reason-${t.nodeId}`,children:a}),!t.isHub&&o!==null&&r(`div`,{className:`w-full whitespace-normal text-right text-[10px] text-foreground-subtle`,"data-testid":`mesh-reason-${t.nodeId}`,children:o})]})}function qn(t){return[{key:`node`,header:G.t(`certificates.nodesColumns.node`,`Node`),sortValue:e=>e.isHub?``:e.nodeId.toLowerCase(),render:t=>e(`div`,{className:`flex items-center gap-1.5`,children:[r(`span`,{className:`font-medium text-foreground`,children:t.nodeId}),t.nodeId===`hub`&&r(P,{variant:`info`,className:`text-[10px]`,children:G.t(`common.hubWord`)}),!t.online&&r(P,{variant:`default`,className:`text-[10px]`,children:G.t(`common.offline`)})]})},{key:`https-state`,header:`HTTPS`,notSortableReason:`A state with a reason has no single order.`,render:e=>r(Vn,{row:e})},{key:`https-expires`,header:G.t(`certificates.nodesColumns.httpsExpires`,`HTTPS expires`),sortValue:e=>zn(e),render:e=>r(Bn,{ms:zn(e),now:t.now})},{key:`identity`,header:G.t(`certificates.nodesColumns.identity`,`Identity`),sortValue:e=>e.mesh?.current?.serial??null,render:e=>r(Hn,{row:e})},{key:`identity-expires`,header:G.t(`certificates.nodesColumns.identityExpires`,`Identity expires`),sortValue:e=>e.mesh?.current?.notAfter??null,render:e=>r(Bn,{ms:e.mesh?.current?.notAfter??null,now:t.now})},{key:`presenting`,header:G.t(`certificates.nodesColumns.inUse`,`In use`),notSortableReason:`Offline nodes have no answer to order by.`,render:e=>r(Un,{row:e})},{key:`actions`,header:G.t(`certificates.nodesColumns.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order.`,render:e=>r(Kn,{row:e,o:t})}]}s();function Jn(){let{t}=K(),i=w(),o=V.useUtils(),s=pn(6e4),c=V.certificates.listHttpsCertificates.useQuery(),l=V.certificates.getMeshCertificates.useQuery(),[u,f]=a(null),[p,m]=a(null),[h,g]=a(null),_=()=>{g(null),o.certificates.listHttpsCertificates.invalidate(),o.certificates.getMeshCertificates.invalidate()},v=e=>(t,n)=>{g(null),f(`${n.nodeId}: ${e} - ${t.message}`)},y=V.certificates.renewHttpsOnNode.useMutation({onSuccess:(e,n)=>{m({tone:`success`,message:e.restartRequired?t(`certificates.nodesCard.newCertificateIssuedRestartThe`,`{{nodeId}}: new certificate issued. Restart the node to serve it.`,{nodeId:n.nodeId}):t(`certificates.nodesCard.newCertificateIssuedAndServed`,`{{nodeId}}: new certificate issued and served.`,{nodeId:n.nodeId})}),_()},onError:v(`renewal failed`)}),b=V.certificates.renewMeshOnNode.useMutation({onSuccess:e=>{m(Ot(e)),_()},onError:v(`renewal could not start`)}),x=V.certificates.revokeMeshOnNode.useMutation({onSuccess:e=>{m({tone:`success`,message:`${e.nodeId}: ${e.next}`}),_()},onError:v(`revoke failed`)}),S=y.isPending||b.isPending||x.isPending,C=(e,t)=>{f(null),m(null),g({nodeId:e,action:t})},T=async e=>{await i({title:t(`certificates.nodesCard.renewHttpsOn`,`Renew HTTPS on "{{nodeId}}"?`,{nodeId:e.nodeId}),message:e.isHub?t(`certificates.nodesCard.aNewCertificateIsIssued`,`A new certificate is issued from the local CA. Clients that trust the CA keep working.`):t(`certificates.nodesCard.theNodeMakesANew`,`The node makes a new key, the hub signs it and the node switches over without a restart. It keeps serving what it had if anything fails.`),confirmLabel:t(`certificates.nodesCard.renew`,`Renew`)})&&(C(e.nodeId,`renew-https`),y.mutate({nodeId:e.nodeId}))},E=e=>{C(e.nodeId,`renew-identity`),b.mutate({nodeId:e.nodeId})},ee=async e=>{await i({title:t(`certificates.nodesCard.revokeTheIdentityOf`,`Revoke the identity of "{{nodeId}}"?`,{nodeId:e.nodeId}),message:t(`certificates.nodesCard.isDisconnectedAtOnceAnd`,`{{nodeId}} is disconnected at once and can no longer connect. To bring it back it must be paired again from System → Cluster → Agents. It stays in the node list until you forget it on the Cluster page. This cannot be undone.`,{nodeId:e.nodeId}),confirmLabel:t(`certificates.nodesCard.revokeAndDisconnect`,`Revoke and disconnect`),variant:`danger`})&&(C(e.nodeId,`revoke-identity`),x.mutate({nodeId:e.nodeId}))},te=qn({now:s,busy:S,running:h,onRenewHttps:e=>void T(e),onRenewIdentity:E,onRevokeIdentity:e=>void ee(e)}),ne=n(()=>Nn(c.data??[],l.data),[c.data,l.data]),D=l.data?.registryAvailable??!0;return r(q,{id:`nodes`,title:t(`certificates.nodesCard.nodes`,`Nodes`),icon:d,description:t(`certificates.nodesCard.eachNodeHoldsTwoCertificates`,`Each node holds two certificates: one it serves over HTTPS, one that proves its identity to the hub. Renewing replaces a certificate without a gap; revoking an identity cuts the node off until it re-joins.`),notice:J(u,p),onDismissNotice:()=>{f(null),m(null)},children:r(un,{isPending:c.isPending||l.isPending,error:c.error??l.error,what:`node certificates`,onRetry:()=>{c.refetch(),l.refetch()},children:e(`div`,{className:`space-y-3`,children:[r(Mn,{https:c.data??[],mesh:l.data,now:s}),r(we,{columns:te,rows:ne,rowKey:e=>e.nodeId,minWidthPx:960,maxBodyHeight:et,defaultSort:{columnKey:`node`,dir:`asc`},emptyMessage:D?t(`certificates.nodesCard.noNodesReported`,`No nodes reported.`):t(`certificates.nodesCard.theCertificateRegistryIsNot`,`The certificate registry is not available yet, so nodes cannot be listed.`)})]})})})}function Yn({pairOpen:t,onPairClose:n}){return e(`div`,{className:`space-y-4`,"data-testid":`certificates-page`,children:[r(yn,{pairOpen:t,onPairClose:n}),r(dn,{}),r(kn,{}),r(Jn,{})]})}function Xn({userId:t,username:n,onClose:i}){let{t:a}=K(),o=w(),s=V.useUtils(),c=ve({userId:t}),l=V.auth.listLoginMethods.useQuery(),u=be({onSuccess:()=>void s.userManagement.listExternalIdentities.invalidate()}),d=new Map((l.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),f=c.data??[],p=async(e,r)=>{await o({title:a(`users.externalIdentitiesModal.removeSignInLink`,`Remove sign-in link`),message:a(`users.externalIdentitiesModal.willNoLongerBeAble`,`"{{username}}" will no longer be able to sign in with this {{label}} account.`,{username:n,label:r}),confirmLabel:a(`common.remove`,`Remove`),variant:`danger`})&&u.mutate({userId:t,provider:e.provider,subject:e.subject})};return r(H,{open:!0,onOpenChange:e=>!e&&i(),children:e(I,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`external-identities-modal`,children:[r(tt,{children:e(N,{className:`flex items-center gap-2`,children:[r(O,{className:`h-4 w-4 text-primary`}),e(`span`,{children:[a(`users.externalIdentitiesModal.linkedSignInAccounts`,`Linked sign-in accounts`),e(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[a(`users.externalIdentitiesModal.user`,`User:`),` `,r(`span`,{className:`font-mono`,children:n})]})]})]})}),r(F,{className:`space-y-3`,children:c.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(k,{className:`h-3.5 w-3.5 animate-spin`}),a(`common.loading`,`Loading…`)]}):f.length===0?r(`p`,{className:`text-xs text-foreground-subtle`,children:a(`users.externalIdentitiesModal.noLinkedAccountsOnlyThe`,`No linked accounts. Only the user can link one, from their own profile page.`)}):r(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:f.map(t=>{let n=d.get(t.provider),i=n??t.provider;return e(`li`,{className:`flex items-center gap-3 px-3 py-2 text-xs`,children:[e(`div`,{className:`flex-1 min-w-0`,children:[e(`div`,{className:`font-medium text-foreground truncate`,children:[i,n===void 0&&r(`span`,{className:`ml-2 rounded bg-foreground-subtle/15 px-1.5 py-0.5 text-[10px] font-normal text-foreground-subtle`,children:a(`users.externalIdentitiesModal.providerUnavailable`,`provider unavailable`)})]}),e(`div`,{className:`text-[11px] text-foreground-subtle truncate`,children:[t.label??t.subject,` ·`,` `,new Date(t.linkedAt).toLocaleDateString()]})]}),e(W,{variant:`unstyled`,onClick:()=>void p(t,i),disabled:u.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[r(pe,{className:`h-3 w-3`}),a(`common.remove`,`Remove`)]})]},`${t.provider}|${t.subject}`)})})}),r(Te,{children:r(W,{onClick:i,variant:`secondary`,children:a(`common.close`,`Close`)})})]})})}function Zn({userId:t,username:n,onClose:i}){let{t:a}=K(),o=c(),s=w(),u=De({userId:t}),d=u.data,f=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),p=he({onSuccess:()=>{f(),i()}}),m=u.isLoading?`loading`:d?.enabled?`enrolled`:`not_enrolled`;return r(H,{open:!0,onOpenChange:e=>!e&&i(),children:e(I,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[r(tt,{children:e(N,{className:`flex items-center gap-2`,children:[r(D,{className:`h-4 w-4 text-primary`}),e(`span`,{children:[a(`users.totpModal.twoFactorAuthentication`,`Two-factor authentication`),e(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[a(`users.totpModal.user`,`User:`),` `,r(`span`,{className:`font-mono`,children:n})]})]})]})}),e(F,{className:`space-y-4`,children:[m===`loading`&&e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(k,{className:`h-3.5 w-3.5 animate-spin`}),a(`users.totpModal.checkingStatus`,`Checking status…`)]}),m===`not_enrolled`&&e(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[r(ee,{className:`h-4 w-4 mt-0.5 shrink-0`}),e(`div`,{children:[r(`div`,{className:`font-medium text-foreground`,children:a(`users.totpModal.2faNotEnrolled`,`2FA not enrolled`)}),r(`p`,{className:`mt-0.5`,children:a(`users.totpModal.onlyTheUserThemselvesCan`,`Only the user themselves can enable 2FA, from their own profile page.`)})]})]}),m===`enrolled`&&d&&e(l,{children:[e(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[r(E,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),e(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[r(`div`,{className:`font-medium`,children:a(`users.totpModal.2faIsActive`,`2FA is active`)}),r(`div`,{className:`text-foreground-subtle`,children:a(`common.enrolledOn`,{when:d.confirmedAt?new Date(d.confirmedAt).toLocaleString():`—`})})]})]}),r(`div`,{className:`text-[11px] text-foreground-subtle`,children:a(`users.totpModal.removingHereClearsTheServer`,`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`)}),e(`div`,{className:`flex justify-end gap-2`,children:[r(W,{onClick:i,variant:`secondary`,children:a(`common.close`,`Close`)}),e(W,{variant:`unstyled`,onClick:async()=>{await s({title:a(`users.totpModal.remove2fa`,`Remove 2FA`),message:a(`users.totpModal.removeTwoFactorAuthenticationFor`,`Remove two-factor authentication for "{{username}}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,{username:n}),confirmLabel:a(`common.remove`,`Remove`),variant:`danger`})&&p.mutate({userId:t})},disabled:p.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[p.isPending?r(k,{className:`h-3 w-3 animate-spin`}):r(C,{className:`h-3 w-3`}),a(`users.totpModal.remove2fa`,`Remove 2FA`)]})]})]})]})]})})}s();function Qn({userId:t,username:n,onClose:i}){let{t:o}=K(),{user:s,logout:c}=rt(),l=s?.id===t,u=w(),d=V.useUtils(),f=V.auth.listSessions.useQuery({userId:t}),[p,m]=a(null),h=V.auth.revokeSessions.useMutation({onSuccess:(e,t)=>{if(l&&`userId`in t){c();return}d.auth.listSessions.invalidate()},onError:e=>m(`Sign out failed: ${e.message}`)}),g=async e=>{await u({title:o(`users.userSessionsModal.signOutThisSession`,`Sign out this session`),message:o(`users.userSessionsModal.onWillHaveToSign`,`"{{username}}" on {{label}} will have to sign in again.`,{username:n,label:vt(e.client).label}),confirmLabel:o(`users.userSessionsModal.signOut`,`Sign out`),variant:`danger`})&&(m(null),h.mutate({id:e.id}))},_=async()=>{await u({title:o(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`),message:l?o(`users.userSessionsModal.everySessionOfYourOwn`,`Every session of your own account ends, this browser included: you will be signed out here too.`):o(`users.userSessionsModal.everySessionOfEndsAt`,`Every session of "{{username}}" ends at once; each device has to sign in again.`,{username:n}),confirmLabel:o(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`),variant:`danger`})&&(m(null),h.mutate({userId:t}))},v=h.isPending&&h.variables!==void 0&&`id`in h.variables?h.variables.id:null;return r(H,{open:!0,onOpenChange:e=>!e&&i(),children:e(I,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`user-sessions-modal`,children:[r(tt,{children:e(N,{className:`flex items-center gap-2`,children:[r(fe,{className:`h-4 w-4 text-primary`}),e(`span`,{children:[o(`users.userSessionsModal.activeSessions`,`Active sessions`),e(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[o(`users.userSessionsModal.user`,`User:`),` `,r(`span`,{className:`font-mono`,children:n})]})]})]})}),e(F,{className:`space-y-3`,children:[p!==null&&r(`div`,{className:`text-[11px] text-danger`,children:p}),r(Pt,{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})]}),e(Te,{className:`justify-between`,children:[e(W,{variant:`unstyled`,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?r(k,{className:`h-3 w-3 animate-spin`}):r(j,{className:`h-3 w-3`}),o(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`)]}),r(W,{onClick:i,variant:`secondary`,children:o(`common.close`,`Close`)})]})]})})}function $n({scopes:t,invalidReason:n}){let{t:i}=K(),a=T(),s=o({queryKey:[`auth`,`previewScope`,t,!1],enabled:n===null,queryFn:()=>a.trpcClient.auth.previewScope.query({scopes:[...t],isAdmin:!1})}),{data:c}=z({projection:`slim`}),l=c?.length??null;if(n!==null)return e(`p`,{className:`flex items-center gap-1.5 text-[11px] text-warning`,"data-testid":`role-preview`,children:[r(S,{className:`h-3 w-3 shrink-0`}),n]});if(s.isLoading)return e(`p`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,"data-testid":`role-preview`,children:[r(k,{className:`h-3 w-3 shrink-0 animate-spin`}),i(`users.rolePreview.resolving`)]});if(s.isError||!s.data)return r(`p`,{className:`text-[11px] text-danger`,"data-testid":`role-preview`,children:i(`users.rolePreview.couldNotResolve`)});let d=s.data.viewableDeviceCount,f=s.data.device.view.all?i(`users.rolePreview.everyDevice`,{count:d}):l===null?i(`users.rolePreview.devicesVisible`,{count:d}):i(`users.rolePreview.devicesVisibleOf`,{count:d,total:l});return e(`p`,{className:`flex items-center gap-1.5 text-[11px] ${d===0?`text-warning`:`text-foreground`}`,"data-testid":`role-preview`,children:[d===0?r(S,{className:`h-3 w-3 shrink-0`}):r(u,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),d===0?i(`users.rolePreview.noDevice`):f]})}function er(e){let t=oe(e.scopes??[]);if(t===null)return{role:e.isAdmin?`admin`:`viewer`,mode:`except`,pickedIds:[],viewer:se,unconfigured:!e.isAdmin};let n=sr(t);return{role:e.isAdmin?`admin`:`viewer`,mode:n.mode,pickedIds:n.pickedIds,viewer:cr(n.mode,n.pickedIds,t.features),unconfigured:!1}}function tr(e,t){return{...e,role:t}}function nr(e,t){return{...e,mode:t,viewer:cr(t,e.pickedIds,e.viewer.features)}}function rr(e,t){let n=lr(t);return{...e,pickedIds:n,viewer:cr(e.mode,n,e.viewer.features)}}function ir(e,t,n){let r=e.viewer.features.filter(e=>e!==t),i=n?[...r,t]:r;return{...e,viewer:cr(e.mode,e.pickedIds,i)}}function ar(e){return e.role===`viewer`&&e.mode===`only`&&e.pickedIds.length===0?`no-allowed-device`:null}function or(e){return ar(e)===null?e.role===`admin`?{isAdmin:!0,scopes:[]}:{isAdmin:!1,scopes:[e.viewer]}:null}function sr(e){if(e.allow===`*`)return{mode:`except`,pickedIds:e.block};let t=new Set(e.block);return{mode:`only`,pickedIds:e.allow.filter(e=>!t.has(e))}}function cr(e,t,n){let r=lr(t);return e===`except`?{type:`viewer`,allow:`*`,block:r,features:[...n]}:{type:`viewer`,allow:r,block:[],features:[...n]}}function lr(e){return[...new Set(e)]}s();var ur=`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`;function dr(e,t){return e?`failed`:t===void 0?`pending`:`answered`}function fr(e){let t=[];for(let n of e)n.parentDeviceId===null&&t.push({id:n.id,name:n.name,type:String(n.type),...n.location===null?{}:{location:n.location}});return t}function pr({user:t,isSelf:i,onClose:o,onSubmit:s,submitting:c,error:u}){let{t:d}=K(),[f,p]=a(n(()=>er(t),[t])),m=z({projection:`slim`}),h=m.data,g=dr(m.isError,h),_=n(()=>fr(h??[]),[h]),v=n(()=>({state:g,devices:g===`answered`?(h??[]).map(e=>({id:e.id,name:e.name})):void 0}),[g,h]),y=ar(f),b=or(f),x=y===`no-allowed-device`?d(`users.userAccessModal.pickAllowedDevice`):null,S=e=>{p(tr(f,e))},C=[{value:`except`,label:d(`users.userAccessModal.modeExcept`)},{value:`only`,label:d(`users.userAccessModal.modeOnly`)}];return r(H,{open:!0,onOpenChange:e=>!e&&o(),children:e(I,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-2xl`,children:[r(tt,{children:r(N,{children:d(`users.userAccessModal.title`,{name:t.username})})}),e(F,{className:`space-y-4`,children:[f.unconfigured&&f.role===`viewer`&&r(L,{variant:`warning`,title:d(`users.userAccessModal.noAccessYet`),message:d(`users.userAccessModal.noAccessYetDetail`,{name:t.username})}),e(`section`,{className:`space-y-2`,children:[r(`h3`,{className:ur,children:d(`users.userAccessModal.role`)}),e(`div`,{role:`radiogroup`,"aria-label":d(`users.userAccessModal.role`),className:`grid gap-1.5 sm:grid-cols-2`,children:[r(mr,{name:`admin`,checked:f.role===`admin`,label:d(`users.userAccessModal.admin`),description:d(`users.userAccessModal.adminDescription`),onPick:()=>S(`admin`)}),r(mr,{name:`viewer`,checked:f.role===`viewer`,disabled:i,label:d(`users.userAccessModal.viewer`),description:d(i?`users.userAccessModal.cannotDemoteSelf`:`users.userAccessModal.viewerDescription`),onPick:()=>S(`viewer`)})]})]}),f.role===`viewer`&&e(l,{children:[e(`section`,{className:`space-y-3`,children:[r(`h3`,{className:ur,children:d(`users.userAccessModal.devices`)}),r(Ie,{label:d(`users.userAccessModal.whichDevices`),value:f.mode,options:C,onChange:e=>p(nr(f,e))}),r(ke,{devices:_,listState:g,fleet:v,value:[...f.pickedIds],onChange:e=>p(rr(f,e)),emptyMeansAll:f.mode===`except`,noun:`device`,testId:`viewer-device-picker`}),r($n,{scopes:b?.scopes??[],invalidReason:x})]}),e(`section`,{className:`space-y-2`,children:[r(`h3`,{className:ur,children:d(`users.userAccessModal.features`)}),r(`div`,{className:`space-y-1`,children:A.map(t=>e(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-md p-1.5 hover:bg-surface-hover`,children:[r(Ve,{className:`mt-0.5`,checked:f.viewer.features.includes(t.id),onChange:e=>p(ir(f,t.id,e.target.checked))}),e(`span`,{className:`min-w-0`,children:[r(`span`,{className:`block text-[12px] font-medium text-foreground`,children:d(`users.viewerFeatures.${t.id}.label`,t.label)}),r(`span`,{className:`block text-[10px] text-foreground-subtle`,children:d(`users.viewerFeatures.${t.id}.description`,t.description)})]})]},t.id))})]})]}),u!==null&&r(L,{message:u})]}),e(Te,{children:[r(W,{variant:`outline`,size:`sm`,onClick:o,children:d(`common.cancel`,`Cancel`)}),r(W,{size:`sm`,onClick:()=>b!==null&&s(b),disabled:c||b===null,children:c?r(k,{className:`h-3 w-3 animate-spin`}):d(`users.userAccessModal.saveAccess`)})]})]})})}function mr({name:t,checked:n,disabled:i=!1,label:a,description:o,onPick:s}){return e(`label`,{className:`flex items-start gap-2 rounded-lg border p-2.5 transition-colors ${n?`border-primary bg-primary/5`:`border-border hover:bg-surface-hover`} ${i?`cursor-not-allowed opacity-60`:`cursor-pointer`}`,children:[r(Ge,{name:`user-role`,value:t,checked:n,disabled:i,onChange:s,className:`mt-0.5`}),e(`span`,{className:`min-w-0`,children:[r(`span`,{className:`block text-[12px] font-medium text-foreground`,children:a}),r(`span`,{className:`block text-[10px] text-foreground-subtle`,children:o})]})]})}s();var $=8;function hr(){return{username:``,password:``,isAdmin:!1}}function gr(e){return{id:e.id,username:e.username,password:``,isAdmin:e.isAdmin}}function _r(e){return e instanceof Error?e.message:G.t(`admin.system.users.genericError`)}function vr(){let{t}=K(),n=c(),{user:o}=rt(),{state:s,openNew:u,openEdit:d,close:f}=Xe(),[p,g]=a(null),[_,b]=a(null),[x,S]=a(!1),{data:C,isLoading:T,isError:E,error:ee,refetch:ne}=Oe(),re=w(),ie=te(),A=()=>n.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),oe=Ce(),se=$e({onSuccess:A}),j=Ae({onSuccess:A}),M=_e({onSuccess:A}),ce=Ke(),[le,ue]=a(null),[pe,me]=a(!1),[he,N]=a(null),[P,F]=a(null),[ve,ye]=a(null),[I,be]=a(null),R=C??[],z=s.mode===`edit`?R.find(e=>e.id===s.id)??null:null,B=()=>{g(null),b(null),S(!1),oe.reset(),j.reset(),f()};i(()=>{if(s.mode===`closed`){g(null),b(null),S(!1);return}if(s.mode===`new`){g(e=>e!==null&&e.id===void 0?e:hr());return}if(z===null){T||f();return}g(e=>e?.id===z.id?e:gr(z))},[s,z,T,f]);let xe=s.mode===`new`&&p!==null&&p.id===void 0||s.mode===`edit`&&p!==null&&z!==null;async function Se(e){await re({title:t(`admin.system.users.deleteUser`,`Delete user`),message:t(`admin.system.users.permanentlyDeleteUserThisCannot`,`Permanently delete user "{{username}}"? This cannot be undone — any active sessions will be revoked on next request.`,{username:e.username}),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&(se.mutate({id:e.id}),s.mode===`edit`&&s.id===e.id&&B())}async function V(e){let n=await ie({title:t(`admin.system.users.resetPassword`,`Reset password`),message:t(`admin.system.users.setANewPasswordFor`,`Set a new password for "{{username}}".`,{username:e.username}),label:t(`admin.system.users.newPassword`,`New password`),inputType:`password`,placeholder:t(`admin.system.users.atLeast8Characters`,`At least 8 characters`),confirmLabel:t(`admin.system.users.continue`,`Continue`),validate:e=>e.length<$?G.t(`admin.system.users.passwordTooShort`,{min:$}):null});n===null||n.length===0||await re({title:t(`admin.system.users.resetPassword`,`Reset password`),message:t(`admin.system.users.resetThePasswordForThey`,`Reset the password for "{{username}}"? They will need to use the new password on their next login.`,{username:e.username}),confirmLabel:t(`common.reset`,`Reset`)})&&M.mutate({id:e.id,newPassword:n})}function H(e){N(null),ue(e)}async function Te(e,t){me(!0),N(null);try{t.isAdmin!==e.isAdmin&&await j.mutateAsync({id:e.id,isAdmin:t.isAdmin}),await ce.mutateAsync({userId:e.id,scopes:[...t.scopes]}),ue(null)}catch(e){N(_r(e))}finally{me(!1),A()}}async function Ee(){if(p!==null){b(null);try{if(p.id===void 0){let e=p.username.trim();if(e===``||p.password.length<$)return;await oe.mutateAsync({username:e,password:p.password,isAdmin:p.isAdmin})}else await j.mutateAsync({id:p.id,isAdmin:p.isAdmin});A(),B()}catch(e){b(_r(e))}}}function De(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}let ke=oe.isPending||j.isPending,Me=p!==null&&p.id===void 0&&p.username.trim()!==``&&p.password.length>=$,Ne=p!==null&&p.id!==void 0,Pe=ke||(p?.id===void 0?!Me:!Ne),Fe=e=>se.isPending&&se.variables?.id===e.id||j.isPending&&j.variables?.id===e.id||M.isPending&&M.variables?.id===e.id,Ie=[{key:`username`,header:t(`admin.system.users.username`,`Username`),sortValue:e=>e.username,render:e=>r(`span`,{className:`font-medium text-foreground`,"data-testid":`user-open-${e.id}`,children:e.username})},{key:`scopes`,header:t(`admin.system.users.access`,`Access`),sortValue:e=>yr(e),render:n=>r(`span`,{onClick:e=>e.stopPropagation(),children:e(W,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>H(n),disabled:Fe(n),title:t(`admin.system.users.configureAccess`,`Configure access`),"data-testid":`user-access-${n.id}`,children:[r(ae,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),r(br,{user:n})]})})},{key:`createdAt`,header:t(`admin.system.users.created`,`Created`),nowrap:!0,sortValue:e=>e.createdAt,render:e=>r(`span`,{className:`text-foreground-subtle`,children:De(e.createdAt)})},{key:`actions`,header:t(`admin.system.users.actions`,`Actions`),align:`right`,nowrap:!0,notSortableReason:`Row actions`,render:n=>{let i=Fe(n),a=n.id!==o?.id&&n.totpEnabled;return e(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[e(W,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>d(n.id),disabled:i,title:t(`admin.system.users.editUser`,`Edit user`),children:[r(y,{className:`h-3 w-3`}),t(`common.edit`,`Edit`)]}),a&&e(W,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>F(n),disabled:i,title:t(`admin.system.users.removeTwoFactorAuthentication`,`Remove two-factor authentication`),children:[r(D,{className:`h-3 w-3`}),t(`admin.system.users.remove2fa`,`Remove 2FA`)]}),e(W,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>ye(n),disabled:i,title:t(`admin.system.users.linkedSignInAccounts`,`Linked sign-in accounts`),children:[r(O,{className:`h-3 w-3`}),t(`admin.system.users.signInLinks`,`Sign-in links`)]}),e(W,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>be(n),disabled:i,title:t(`admin.system.users.activeSessions`,`Active sessions`),children:[r(fe,{className:`h-3 w-3`}),t(`admin.system.users.sessions`,`Sessions`)]}),e(W,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void V(n),disabled:i,title:t(`admin.system.users.resetPassword`,`Reset password`),children:[r(de,{className:`h-3 w-3`}),t(`admin.system.users.resetPassword`,`Reset password`)]}),e(W,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void Se(n),disabled:i,title:t(`admin.system.users.deleteUser`,`Delete user`),className:`text-danger hover:bg-danger/10`,children:[i?r(k,{className:`h-3 w-3 animate-spin`}):r(h,{className:`h-3 w-3`}),t(`common.delete`,`Delete`)]})]})}}];return e(pt,{embedded:!0,icon:m,title:t(`admin.system.users.users`,`Users`),subtitle:t(`admin.system.users.hubAccountsAdminFlagAccess`,`Hub accounts, admin flag, access scopes, sessions and sign-in links.`),actions:e(W,{size:`sm`,type:`button`,onClick:()=>{b(null),u()},children:[r(v,{className:`h-3.5 w-3.5`}),t(`admin.system.users.createUser`,`Create User`)]}),children:[E&&r(L,{title:t(`admin.system.users.couldNotLoadUsers`,`Could not load users`),message:_r(ee),onRetry:()=>void ne()}),T&&e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(k,{className:`h-3.5 w-3.5 animate-spin`}),t(`common.loading`,`Loading…`)]}),!T&&!E&&R.length===0&&r(je,{icon:m,title:t(`admin.system.users.noUsersYet`,`No users yet`),description:t(`admin.system.users.createAUserToGrant`,`Create a user to grant hub access.`)}),!T&&!E&&R.length>0&&r(we,{columns:Ie,rows:R,rowKey:e=>e.id,minWidthPx:560,maxBodyHeight:`max-h-[60vh]`,onRowClick:e=>d(e.id)}),r(ge,{open:xe,onClose:B,title:p?.id===void 0?t(`admin.system.users.createUser`,`Create User`):t(`admin.system.users.edit`,`Edit {{value1}}`,{value1:p.username||`user`}),icon:m,error:_,testId:`user-form-dialog`,footer:r(W,{size:`sm`,type:`button`,disabled:Pe,onClick:()=>void Ee(),children:ke?e(l,{children:[r(k,{className:`h-3.5 w-3.5 animate-spin`}),t(`admin.system.users.saving`,`Saving…`)]}):p?.id===void 0?t(`admin.system.users.create`,`Create`):t(`common.save`,`Save`)}),children:p!==null&&e(`div`,{className:`space-y-3`,children:[r(U,{label:t(`admin.system.users.username`,`Username`),required:p.id===void 0,children:r(We,{value:p.username,onChange:e=>g({...p,username:e.target.value}),placeholder:`john`,autoFocus:p.id===void 0,disabled:p.id!==void 0,"data-testid":`user-form-username`})}),p.id===void 0&&r(U,{label:t(`admin.system.users.password`,`Password`),required:!0,description:t(`admin.system.users.atLeastCharacters`,`At least {{value1}} characters.`,{value1:String($)}),children:r(He,{value:p.password,onValueChange:e=>g({...p,password:e}),shown:x,onToggleShown:()=>S(e=>!e),placeholder:`••••••••`,"data-testid":`user-form-password`})}),r(U,{label:t(`admin.system.users.admin`,`Admin`),description:t(`admin.system.users.unrestrictedAccessToEveryCapability`,`Unrestricted access to every capability and device.`),children:e(`label`,{className:`inline-flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[r(Ve,{checked:p.isAdmin,onChange:e=>g({...p,isAdmin:e.target.checked}),className:`rounded border-border focus:ring-primary`,"data-testid":`user-form-admin`}),r(`span`,{children:t(`admin.system.users.admin`,`Admin`)})]})}),p.id!==void 0&&r(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`admin.system.users.toChangeThePasswordUse`,`To change the password, use Reset password on the user's row. Access scopes are configured from the Access column.`)})]})}),P&&r(Zn,{userId:P.id,username:P.username,onClose:()=>F(null)}),ve&&r(Xn,{userId:ve.id,username:ve.username,onClose:()=>ye(null)}),I&&r(Qn,{userId:I.id,username:I.username,onClose:()=>be(null)}),le&&r(pr,{user:le,isSelf:le.id===o?.id,onClose:()=>ue(null),onSubmit:e=>void Te(le,e),submitting:pe,error:he})]})}function yr(e){let t=er(e);return t.role===`admin`?0:t.unconfigured?2:1}function br({user:t}){let{t:n}=K(),i=er(t);if(i.role===`admin`)return r(`span`,{className:`font-medium text-foreground`,children:n(`users.accessSummary.admin`)});if(i.unconfigured)return r(`span`,{className:`font-medium text-warning`,children:n(`admin.system.users.noAccess`,`No access`)});let{allow:a,block:o,features:s}=i.viewer,c=a===`*`?n(`users.accessSummary.allDevices`):n(`users.accessSummary.devices`,{count:a.length});return e(`span`,{className:`text-foreground-subtle`,children:[r(`span`,{className:`font-medium text-foreground`,children:n(`users.accessSummary.viewer`)}),` ·`,` `,c,o.length>0&&e(l,{children:[` · `,n(`users.accessSummary.blocked`,{count:o.length})]}),s.length>0&&e(l,{children:[` · `,n(`users.accessSummary.features`,{count:s.length})]})]})}s();var xr={"api-keys":Q.tokens,"linked-sessions":Q.linkedApps},Sr=`certificates`;function Cr(t){return e(W,{size:`sm`,type:`button`,"data-testid":`certificates-pair-device`,onClick:t,children:[r(D,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),G.t(`systemPage.identity.pairADevice`,`Pair a device`)]})}function wr(){let{t:e}=K(),[t]=it(),n=ln(),[i,o]=a(!1),s=xr[t.get(`tab`)??``];if(s!==void 0)return r(at,{to:ut(`access`,{integration:s}),replace:!0});let c=ot(`/system/identity`,{t:e,isAdmin:!0})??{icon:ie,title:e(`system.identity`,`Identity & Access`)},l=t.get(`tab`)??`users`,u=t.get(`integration`),d=l===st.access.tab?cn(u,n.requestCreate):l===`certificates`?Cr(()=>o(!0)):void 0;return r(ft,{icon:c.icon,title:c.title,defaultSection:`users`,sectionsLabel:`${c.title} sections`,actions:d,sections:[{id:`users`,label:e(`systemPage.identity.users`,`Users`),content:r(vr,{})},{id:st.access.tab,label:e(`systemPage.identity.tokensSessions`,`Tokens & sessions`),ownedParams:lt.concat([wt.token,wt.scoped,wt.admin]),content:r(sn,{createRequested:n.createRequested,onCreateConsumed:n.clearCreate})},{id:Sr,label:e(`systemPage.identity.certificates`,`Certificates`),content:r(Yn,{pairOpen:i,onPairClose:()=>o(!1)})},{id:st.authentication.tab,label:e(`systemPage.identity.authentication`,`Authentication`),content:r(Vt,{}),ownedParams:lt}]})}export{wr as IdentityPage};
@@ -1 +0,0 @@
1
- import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,a as s,et as c,o as l,t as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$r as f,Fn as p,Ii as m,Kt as h,Li as g,Oi as _,Pi as v,Rn as y,Sa as b,Si as x,Sn as S,Tn as C,Ut as w,Wn as T,ai as E,da as D,ei as O,ht as k,jn as A,wt as j,xr as M}from"./player-overlays-D5PuUVGx.js";import{ns as N,po as P}from"./client-DDfmis6s.js";import{t as F}from"./search-x-DTKP7R6g.js";import{$s as I,Br as L,Co as R,Do as z,Eo as B,Er as V,Fo as H,Fr as U,Gs as W,Io as G,Ir as ee,Jr as K,Ka as q,Ko as te,Kt as ne,Mo as re,Of as ie,Pr as J,Qs as Y,Ro as ae,Rr as X,So as oe,To as se,Ut as ce,Vn as le,Vo as ue,Wt as de,Xs as fe,Yo as pe,Ys as me,Zs as he,_n as ge,er as _e,i as Z,ir as ve,jn as ye,jo as be,ko as xe,lr as Se,nr as Ce,ns as we,of as Te,pa as Ee,qa as De,qi as Oe,r as ke,rr as Ae,rs as je,tr as Me,ur as Ne,vi as Q,wf as Pe,wo as Fe,xi as Ie,xs as Le,zr as Re}from"./src-kgyauwxD.js";import{t as $}from"./useTranslation-BJr-n0es.js";import{n as ze}from"./addon-icons-context-vNuH_Qnv.js";import{Fr as Be,Ir as Ve,K as He,Lr as Ue,Q as We,b as Ge,jr as Ke,st as qe,ut as Je,x as Ye,y as Xe}from"./index-tVCZ0Ciq.js";import{t as Ze}from"./useAdminDeviceRemoval-39R8KAnR.js";import{t as Qe}from"./device-integration-icon-C7ZXUKQ-.js";import{n as $e,o as et,t as tt}from"./ScanSubnetEditor-DxjiHfEb.js";import{t as nt}from"./NodeAddonsSettingsPanel-BN1rOp6t.js";c();function rt(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...rt(n.fields));return t}function it(e,t,i){let[a,s]=o(`idle`),[c,l]=o({}),u=n(()=>{let t=[];for(let n of e.sections)t.push(...rt(n.fields));return t},[e]),d=u.length>0&&i!==void 0,f=r(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:a,hasProbeFields:d,probeResults:c,handleTestAll:r(async()=>{if(!i)return;let e=u.filter(e=>{let n=t[e];return n!=null&&String(n).trim()!==``});if(e.length===0)return;s(`testing`);let n={};for(let t of e)n[t]={status:`probing`};l(n);let r=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await i(e,t[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),a={};for(let e of r)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;a[t]={status:n.status===`ok`?`ok`:`error`,result:n}}l(a),s(`idle`)},[i,u,t]),clearProbeResult:f}}c();function at(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(...at(n.fields));return t}function ot(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function st(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){st(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function ct(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function lt(e,t){let n=we({addonId:e,integrationId:t}),r=n.data?.deviceType??null,i=ue({addonId:e,integrationId:t,type:r??P.Camera},{enabled:n.isSuccess&&r!==null});return n.isError?`unavailable`:n.isLoading?`loading`:r===null||i.isError?`unavailable`:i.isLoading||!i.isSuccess?`loading`:((i.data??null)?.sections??[]).some(e=>e.fields.length>0)?`available`:`unavailable`}function ut({integrationId:t,addonId:s,onClose:c}){let{t:u}=$(),f=l(),[p,h]=o({}),[g,_]=o(!1),[v,y]=o(null),[b,x]=o(ct),S=we({addonId:s,integrationId:t},{enabled:!0}),T=S.data?.deviceType??null,E=ue({addonId:s,integrationId:t,type:T??P.Camera},{enabled:S.isSuccess&&T!==null}),D=E.data??null;a(()=>{h(D?st(D.sections.flatMap(e=>e.fields)):{}),x(ct()),_(!1),y(null)},[!0,t,D]);let O=n(()=>({...p,_probeRequestId:b}),[p,b]),k=be({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),A=Le(),N=r(async(e,t)=>{_(!0);let n=await A.mutateAsync({addonId:s,type:T??P.Camera,key:e,value:t,formValues:O});return n.status===`ok`&&n.suggestedValues&&h(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))ot(e[i])&&!ot(a)&&(r[i]=a,t=!0);return t?r:e}),n},[A,s,O,T]),{testAllStatus:F,hasProbeFields:I,probeResults:L,handleTestAll:R,clearProbeResult:z}=it(D??{sections:[]},p,N);async function B(e){y(null);try{await k.mutateAsync({addonId:s,type:T??P.Camera,config:p,integrationId:t}),e?h(D?st(D.sections.flatMap(e=>e.fields)):{}):c()}catch(e){y(e instanceof Error?e.message:String(e))}}let V=at((D?.sections??[]).flatMap(e=>e.fields)).filter(e=>ot(p[e])),H=V.length===0,W=S.isLoading||T!==null&&E.isLoading,G=S.isError||S.isSuccess&&T===null||E.isError||E.isSuccess&&D===null;return e(d,{children:[i(U,{className:`space-y-3`,children:W?i(`div`,{className:`flex items-center justify-center py-8`,children:i(M,{className:`h-5 w-5 animate-spin text-primary`})}):G?e(`div`,{className:`flex items-start gap-3 rounded-lg border border-danger/40 bg-danger/10 px-4 py-3`,children:[i(w,{className:`h-4 w-4 text-danger mt-0.5 shrink-0`}),e(`div`,{className:`space-y-1`,children:[i(`p`,{className:`text-xs font-medium text-danger`,children:u(`integrations.addDeviceDialog.providerUnavailable`,`Provider unavailable`)}),i(`p`,{className:`text-xs text-foreground-subtle`,children:i(Ke,{i18nKey:`integrations.addDeviceDialog.notReady`,values:{addonId:s},components:{mono:i(`span`,{className:`font-mono`})}})})]})]}):i(Je,{schema:D,values:p,onChange:h,onTestField:N,probeResults:L,onClearProbe:z})}),!G&&!W&&e(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[e(Q,{variant:`unstyled`,type:`button`,onClick:()=>_(e=>!e),className:`flex w-full items-center justify-between px-3 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[e(`span`,{className:`flex items-center gap-2`,children:[i(C,{className:`h-3.5 w-3.5`}),u(`integrations.addDeviceDialog.testLogs`,`Test logs`),i(`span`,{className:`font-mono text-[9px] opacity-60`,children:b.slice(0,14)})]}),i(m,{className:`h-3.5 w-3.5 transition-transform ${g?`rotate-180`:``}`})]}),g&&i(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:i(ge,{addonId:s,requestId:b,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!G&&!W&&(v||V.length>0)&&i(`div`,{className:`border-t border-danger/30 bg-danger/5 px-3 py-2 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(w,{className:`h-3.5 w-3.5 text-danger mt-0.5 shrink-0`}),i(`p`,{className:`text-[11px] text-danger`,children:v||u(`integrations.addDeviceDialog.required`,`Required: {{value1}}`,{value1:V.join(`, `)})})]})}),e(X,{className:`justify-between`,children:[e(`div`,{className:`flex items-center gap-2`,children:[i(Q,{variant:`unstyled`,onClick:c,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:u(`integrations.cancel`)}),!G&&I&&e(Q,{variant:`unstyled`,type:`button`,onClick:R,disabled:F===`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:[F===`testing`?i(M,{className:`h-3.5 w-3.5 animate-spin`}):i(j,{className:`h-3.5 w-3.5`}),u(`integrations.addDeviceDialog.testAll`,`Test All`)]})]}),e(`div`,{className:`flex items-center gap-2`,children:[i(Q,{variant:`unstyled`,onClick:()=>B(!0),disabled:G||!H||k.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:u(`integrations.saveAndNew`)}),i(Q,{variant:`unstyled`,onClick:()=>B(!1),disabled:G||!H||k.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:k.isPending?u(`integrations.saving`):u(`integrations.save`)})]})]})]})}var dt=1500;function ft({addonId:t,integrationId:n,jobId:r,onFinished:a}){let{t:o}=$(),s=R(),c=(B({addonId:t,integrationId:n},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?dt:!1}).data??[]).find(e=>e.jobId===r);if(!c)return null;let l=c.state===`running`,u=c.processed,d=c.total>0?Math.round(u/c.total*100):0;!l&&c.finishedAt!==null&&a();let f=[`${u}/${c.total} ${o(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];c.adopted>0&&f.push(`${c.adopted} ${o(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),c.alreadyAdopted>0&&f.push(`${c.alreadyAdopted} ${o(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),c.failed>0&&f.push(`${c.failed} ${o(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let p=f.join(` · `);return e(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[e(`div`,{className:`flex items-center gap-2`,children:[l?i(M,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):c.failed>0?i(w,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):c.state===`cancelled`?i(x,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):i(_,{className:`h-3.5 w-3.5 text-primary shrink-0`}),i(`p`,{className:`text-[11px] text-foreground`,children:p}),l&&i(Q,{variant:`unstyled`,onClick:()=>s.mutate({jobId:r}),className:`ml-auto rounded-lg border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:o(`integrations.adoptJobCancel`,{defaultValue:`Stop`})})]}),i(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:i(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${d}%`},role:`progressbar`,"aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100})}),c.results.filter(e=>e.outcome===`failed`).slice(0,5).map(t=>e(`p`,{className:`text-[11px] text-destructive`,children:[t.childNativeId,`: `,t.error]},t.childNativeId))]})}function pt(e){let t=e.map(e=>({...e,stableId:e.childNativeId})),n=new Map(e.map(e=>[e.childNativeId,e])),r=(e,t,i)=>e.flatMap(e=>{let a=n.get(e.candidate.childNativeId);return a===void 0?[]:[{candidate:a,depth:t,...i===void 0?{}:{parentName:i}},...r(e.children,t+1,a.name)]});return r(et(t),0)}function mt(e){let t=e.metadata?.model,n=e.childNativeId.split(`:`).pop()??``;return[typeof t==`string`?t:``,n].filter(e=>e.length>0).join(` · `)}function ht(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}c();var gt=`devices`;function _t(e){return{id:gt,label:e(`integrations.adoptDevicesModal.defaultFilter`),isDefault:!0}}var vt=2e4,yt=100;function bt({addonId:s,integrationId:c,onClose:u}){let f=b(),{t:p}=$(),m=l(),[h,_]=o(new Set),[v,y]=o(new Set),[x,S]=o(new Map),[C,T]=o(null),{data:E}=he(),D=(E??[]).find(e=>e.addonId===s)?.supportsLocationImport??!1,[O,k]=o(!0),j=Fe({addonId:s,integrationId:c}).data?.filters,N=j&&j.length>0?j:[_t(p)],[P,F]=o(N.find(e=>e.isDefault)?.id??(N.some(e=>e.id===gt)?gt:N[0].id)),I=P!==gt,L=z(),R=se({addonId:s,integrationId:c,page:1,pageSize:vt,filter:P}),B=R.refetch,V=L.mutate,H=r(()=>{V({addonId:s,integrationId:c},{onSettled:()=>{B()}})},[V,s,c,B]),U=t(null);a(()=>{let e=`${s}::${c}`;U.current===e||R.isLoading||(U.current=e,(R.data?.candidates.length??0)===0&&H())},[s,c,R.isLoading,R.data,H]);let W=L.isPending,G=L.isError?L.error instanceof Error?L.error.message:String(L.error):null,ee=typeof L.data?.lastError==`string`&&L.data.lastError.length>0?L.data.lastError:null,K=R.data?.candidates??[],q=n(()=>pt(K),[K]),te=n(()=>new Map(q.map(e=>[e.candidate.childNativeId,e.depth])),[q]),ne=n(()=>new Map(q.map(e=>[e.candidate.childNativeId,e.parentName])),[q]),re=R.isError?R.error instanceof Error?R.error.message:String(R.error):null,J=xe(),[Y,ae]=o(null),oe=r(e=>{e.alreadyAdopted||_(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),le=r(e=>{y(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),ue=r((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=r(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=r(async()=>{T(null);let e=[...h];if(e.length!==0)try{let t=de(e),{jobId:n}=await J.mutateAsync({addonId:s,integrationId:c,filter:P,childNativeIds:e,...t?{perCandidate:t}:{},...D?{importLocations:O}:{}});ae(n),_(new Set),S(new Map)}catch(e){T(e instanceof Error?e.message:String(e))}},[h,de,J,s,c,P,D,O]),pe=t(null),me=r(()=>{Y===null||pe.current===Y||(pe.current=Y,B(),m.invalidateQueries({queryKey:[[`integrations`]]}),m.invalidateQueries({queryKey:[[`deviceManager`]]}))},[Y,B,m]),ge=r(e=>{F(e),_(new Set),y(new Set),S(new Map),T(null)},[]),_e=h.size,Z=Y!==null&&_e===0&&!J.isPending;return e(d,{children:[D&&e(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[i(Se,{checked:O,onChange:e=>k(e.target.checked),className:`accent-primary`}),p(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),e(`div`,{className:`flex-1 min-h-0 flex flex-col gap-2 overflow-hidden`,children:[(G??re??ee)&&K.length===0&&i(`div`,{className:`rounded-lg border border-danger/30 bg-danger/5 px-4 py-3 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(w,{className:`h-3.5 w-3.5 text-danger mt-0.5 shrink-0`}),e(`div`,{className:`min-w-0`,children:[i(`p`,{className:`text-xs font-medium text-danger`,children:p(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),i(`p`,{className:`text-[11px] text-danger/90 mt-0.5`,children:G??re??ee})]})]})}),N.length>1&&i(xt,{filters:N,activeFilter:P,onSelect:ge}),i(`div`,{className:`flex-1 min-h-0`,children:i(ce,{mode:`generic`,items:q.map(e=>e.candidate),pageSize:yt,getKey:e=>e.childNativeId,getSearchText:ht,getFilterType:e=>e.type,filterOptions:Pe(f),filterLabel:p(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:R.isLoading||W&&K.length===0,searchPlaceholder:p(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(G??re??ee)&&K.length===0?``:p(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:e(Q,{variant:`unstyled`,type:`button`,onClick:H,disabled:W,title:p(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[i(A,{className:`h-3.5 w-3.5 ${W?`animate-spin`:``}`}),p(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:p(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-full sm:w-[55%]`,cellClassName:`max-w-0`,cell:e=>i(St,{candidate:e,depth:te.get(e.childNativeId)??0,...ne.get(e.childNativeId)===void 0?{}:{containerName:ne.get(e.childNativeId)},expandable:!I,expanded:v.has(e.childNativeId),onToggleExpand:()=>le(e.childNativeId),adoptedLabel:p(`integrations.adoptAlready`,{defaultValue:`Adopted`}),typeLabel:ie(e.type,f).label})},{key:`type`,header:p(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:t=>{let n=ie(t.type,f),r=n.icon;return e(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[i(r,{className:`h-3.5 w-3.5 shrink-0`}),n.label]})}},{key:`select`,header:``,headerClassName:`w-10 sm:w-[15%] text-right`,cellClassName:`text-right`,cell:e=>i(`div`,{className:`flex items-center justify-end`,children:i(Q,{variant:`unstyled`,onClick:()=>oe(e),disabled:e.alreadyAdopted,"aria-label":h.has(e.childNativeId)?p(`integrations.adoptDevicesModal.deselect`,`Deselect`):p(`integrations.adoptDevicesModal.select`,`Select`),className:`inline-flex h-5 w-5 items-center justify-center rounded border ${h.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:h.has(e.childNativeId)&&i(g,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!I&&v.has(e.childNativeId),renderExpanded:I?void 0:e=>i(Ct,{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&&i(`div`,{className:`border-t border-danger/30 bg-danger/5 px-3 py-2 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(w,{className:`h-3.5 w-3.5 text-danger mt-0.5 shrink-0`}),i(`p`,{className:`text-[11px] text-danger`,children:C})]})}),Y!==null&&i(ft,{addonId:s,integrationId:c,jobId:Y,onFinished:me}),e(X,{children:[i(Q,{variant:`outline`,size:`sm`,onClick:u,children:p(`integrations.cancel`,{defaultValue:`Cancel`})}),e(Q,{variant:`primary`,size:`sm`,onClick:Z?u:fe,disabled:!Z&&(_e===0||J.isPending),children:[J.isPending&&i(M,{className:`h-3.5 w-3.5 animate-spin`}),Z?p(`integrations.close`,{defaultValue:`Close`}):p(`integrations.addSelected`,{defaultValue:`Add selected`}),!Z&&_e>0?` (${_e})`:``]})]})]})}function xt({filters:e,activeFilter:t,onSelect:n}){let{t:r}=$();return i(`div`,{role:`tablist`,"aria-label":r(`integrations.adoptDevicesModal.discoveryGranularity`,`Discovery granularity`),className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return i(Q,{variant:`unstyled`,type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function St({candidate:t,depth:n,containerName:r,expandable:a,expanded:o,onToggleExpand:s,adoptedLabel:c,typeLabel:l}){let{t:u}=$(),d=(t.children??[]).length,f=mt(t);return e(`div`,{className:`flex items-center gap-2.5 min-w-0 ${n>0?`pl-5`:``}`,children:[a&&d>0?e(Q,{variant:`unstyled`,type:`button`,onClick:s,"aria-label":o?u(`integrations.adoptDevicesModal.collapse`,`Collapse`):u(`integrations.adoptDevicesModal.expand`,`Expand`),"aria-expanded":o,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[i(o?m:v,{className:`h-3.5 w-3.5`}),d]}):a?i(`span`,{className:`h-5 w-5 flex-shrink-0`,"aria-hidden":`true`}):null,e(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`truncate text-xs font-medium text-foreground`,"data-testid":`candidate-name`,children:t.name}),f.length>0&&i(`div`,{className:`truncate text-[10px] text-foreground-subtle`,"data-testid":`candidate-subtitle`,children:f}),r!==void 0&&i(`div`,{className:`truncate text-[10px] text-foreground-subtle`,"data-testid":`candidate-container`,children:u(`integrations.adoptDevicesModal.inContainer`,`in {{name}}`,{name:r})}),i(`div`,{className:`truncate text-[10px] text-foreground-subtle sm:hidden`,children:l})]}),t.alreadyAdopted&&i(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:c})]})}function Ct({candidate:t,hiddenChildIds:n,onToggleChildHidden:r}){let{t:a}=$(),o=t.children??[];return o.length===0?null:i(`div`,{className:`space-y-1 py-1`,children:o.map(t=>{let o=n.has(t.childNativeId),s=t.capabilities??[];return e(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${o?`opacity-50`:``}`,children:[i(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:t.name}),s.length>0&&i(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:s.join(`, `)}),i(Q,{variant:`unstyled`,onClick:()=>r(t.childNativeId),"aria-label":o?a(`integrations.adoptDevicesModal.showChild`,`Show child`):a(`integrations.adoptDevicesModal.hideChild`,`Hide child`),title:o?a(`integrations.adoptDevicesModal.showAfterAdopt`,`Show after adopt`):a(`integrations.adoptDevicesModal.hideAfterAdopt`,`Hide after adopt`),className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:i(o?O:f,{className:`h-3 w-3`})})]},t.childNativeId)})})}function wt(e){let t=e.host;return typeof t==`string`&&t.length>0?t.toLowerCase():null}function Tt(e){return e===null?[]:[`host:${e}`]}function Et(e){let t=[],n=new Map,r=(e,r)=>{let i=e.map(e=>n.get(e)).find(e=>e!==void 0),a=i??r();i===void 0&&t.push(a);for(let t of e)a.ids.add(t),n.set(t,a);return a},i=(e,t)=>{e.sources.includes(t)||e.sources.push(t)};for(let t of e.adoption){let e=r([t.childNativeId],()=>({key:t.childNativeId,ids:new Set,name:t.name,address:null,sources:[],hit:null,adoptionId:t.childNativeId,proposalId:null,alreadyAdded:!1,addedName:null,needsParams:[],parentId:t.parentStableId??null}));i(e,`adoption`),e.adoptionId=t.childNativeId,t.alreadyAdopted===!0&&(e.alreadyAdded=!0)}let a=(t,n,a)=>{let o=wt(t.prefilledConfig),s=r([t.stableId,...Tt(o)],()=>({key:t.stableId,ids:new Set,name:t.suggestedName,address:o,sources:[],hit:null,adoptionId:null,proposalId:null,alreadyAdded:!1,addedName:null,needsParams:[],parentId:null}));i(s,n),(s.hit===null||n===`scan`)&&(s.hit=t),s.name=t.suggestedName,s.address=o??s.address,a!==null&&(s.proposalId=a),s.parentId=t.parentStableId??s.parentId,s.needsParams=t.needsParams??s.needsParams,(t.alreadyOnboarded===!0||t.onboardedDeviceId!==void 0||e.existingStableIds.has(t.stableId))&&(s.alreadyAdded=!0,s.addedName=t.onboardedName??s.addedName)};for(let t of e.scan)a(t,`scan`,null);for(let t of e.proposals)a(t.candidate,`proposal`,t.id);for(let n of t)[...n.ids].some(t=>e.existingStableIds.has(t))&&(n.alreadyAdded=!0);return t.map(e=>{let t=e.parentId===null?void 0:n.get(e.parentId);return{key:e.key,name:e.name,address:e.address,sources:e.sources,hit:e.hit,adoptionId:e.adoptionId,proposalId:e.proposalId,alreadyAdded:e.alreadyAdded,addedName:e.addedName,needsParams:e.needsParams,parentKey:t!==void 0&&t!==e?t.key:null}})}c();var Dt=500;function Ot(e){return e instanceof Error?e.message:String(e)}function kt(e,t){let n={};for(let t of e?.sections??[])for(let e of t.fields)`key`in e&&e.key&&`default`in e&&e.default!==void 0&&(n[e.key]=e.default);return{...n,...t}}function At({addonId:t,integrationId:a,onClose:s,onSetupIntegration:c,alongsideAdoption:u=!1}){let{t:f}=$(),p=l(),m=je({addonId:t}).data??null,[h,g]=o({}),_=H(),v=pe({}),b=se({addonId:t,integrationId:a,page:1,pageSize:Dt},{retry:!1}),{data:x}=te({projection:`slim`}),S=oe(),C=xe(),[w,T]=o(new Set),[E,D]=o(new Set),[O,k]=o(null),[A,j]=o(null),N=n(()=>{let e=(b.data?.candidates??[]).map(e=>({childNativeId:e.childNativeId,name:e.name,alreadyAdopted:e.alreadyAdopted,parentStableId:e.parentStableId})),n=(v.data?.proposals??[]).filter(e=>e.addonId===t).map(e=>({id:e.id,candidate:e.candidate}));return Et({adoption:e,scan:_.data?.candidates??[],proposals:n,existingStableIds:new Set((x??[]).map(e=>e.stableId))})},[b.data,v.data,_.data,x,t]),P=e=>e.hit!==null&&(e.needsParams.length>0||e.hit.setupIntegration===!0),F=n(()=>u?N.filter(e=>!e.sources.includes(`adoption`)||P(e)):N,[N,u]),I=u?N.filter(e=>e.sources.includes(`adoption`)&&e.hit!==null&&!F.includes(e)).length:0,L=r(e=>{let t=new Map(F.map(e=>[e.key,e])),n=0,r=e;for(;r?.parentKey!=null&&n<8&&(r=t.get(r.parentKey),r!==void 0);)n+=1;return n},[F]),R=r(()=>{k(null),_.mutate({addonId:t,params:h})},[_,t,h]),z=r(async(e,t)=>{T(t=>new Set(t).add(e)),k(null);try{await t(),D(t=>new Set(t).add(e)),p.invalidateQueries({queryKey:[[`deviceManager`]]}),p.invalidateQueries({queryKey:[[`integrations`]]})}catch(e){k(Ot(e))}finally{T(t=>{let n=new Set(t);return n.delete(e),n})}},[p]),B=r(async(e,n)=>{let r=e.hit;if(r!==null){let i=$e(t,r);if(i!==null){c?.(i),s();return}await z(e.key,async()=>{await S.mutateAsync({addonId:t,integrationId:a,candidate:{...r,prefilledConfig:{...r.prefilledConfig,...n}}}),j(null)});return}if(e.adoptionId!==null){let n=e.adoptionId;await z(e.key,async()=>{await C.mutateAsync({addonId:t,integrationId:a,childNativeIds:[n]})})}},[S,C,t,a,s,c,z]),V=r(e=>{if(e.needsParams.length>0&&e.hit!==null){k(null),j(e);return}B(e)},[B]);if(A!==null&&A.hit!==null)return i(Nt,{addonId:t,integrationId:a,row:A,found:A.hit.prefilledConfig,busy:w.has(A.key),error:O,embedded:u,onBack:()=>j(null),onSubmit:e=>void B(A,e)});let W=F.length===0,G=e(d,{children:[i(tt,{}),m&&i(Je,{schema:m,values:h,onChange:g}),e(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[e(`p`,{className:`text-xs text-foreground-subtle`,children:[_.isPending?f(`integrations.addDeviceModal.scanning`,`Scanning the local network…`):F.length>0?f(`integrations.addDeviceModal.found`,{defaultValue_one:`{{count}} device found`,defaultValue_other:`{{count}} devices found`,count:F.length}):``,!_.isPending&&I>0?` · ${f(`integrations.addDeviceModal.alsoAdopted`,{defaultValue_one:`{{count}} also in the adoption list`,defaultValue_other:`{{count}} also in the adoption list`,count:I})}`:``]}),e(Q,{variant:`outline`,size:`sm`,onClick:R,disabled:_.isPending,children:[_.isPending?i(M,{className:`h-3.5 w-3.5 animate-spin`}):i(y,{className:`h-3.5 w-3.5`}),f(`integrations.addDeviceModal.scanNow`,`Scan now`)]})]}),_.isError&&i(jt,{text:f(`integrations.addDeviceModal.scanFailed`,`The scan failed. Try again.`)}),O!==null&&i(jt,{text:O}),W&&!_.isPending&&i(`p`,{className:`py-6 text-center text-xs text-foreground-subtle`,children:_.data?f(`integrations.addDeviceModal.nothingFound`,`No devices responded to the scan.`):f(`integrations.addDeviceModal.scanHint`,`Scan the network to find devices to add.`)}),i(`div`,{className:u?`max-h-48 space-y-1.5 overflow-y-auto`:`space-y-1.5`,"data-testid":`network-candidates`,children:F.map(e=>i(Mt,{row:e,depth:L(e),busy:w.has(e.key),added:E.has(e.key),onPick:V},e.key))})]});return u?i(`div`,{className:`shrink-0 space-y-3 border-b border-border pb-3`,children:G}):e(d,{children:[i(U,{className:`space-y-3`,children:G}),i(X,{children:i(Q,{variant:`outline`,size:`sm`,onClick:s,children:f(`integrations.close`,`Close`)})})]})}function jt({text:t}){return e(`div`,{className:`flex items-start gap-2 rounded-lg border border-danger/40 bg-danger/10 px-3 py-2`,children:[i(w,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-danger`}),i(`p`,{className:`text-xs text-danger`,children:t})]})}function Mt({row:t,depth:n,busy:r,added:a,onPick:o}){let{t:s}=$(),c=t.alreadyAdded||a,l=t.hit!==null&&$e(``,t.hit)!==null,u=t.hit?.selectable!==!1,d=t.needsParams.length>0;return e(`div`,{className:`flex items-center gap-3 rounded-lg border border-border bg-surface px-3 py-2 ${n>0?`ml-4`:``}`,"data-testid":`network-row-${t.key}`,children:[e(`div`,{className:`min-w-0 flex-1`,children:[i(`p`,{className:`truncate text-xs font-medium text-foreground`,children:t.name}),t.address!==null&&i(`p`,{className:`truncate font-mono text-[10px] text-foreground-subtle`,children:t.address}),c&&t.addedName!==null&&i(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.addedName})]}),c?e(`span`,{className:`flex items-center gap-1 text-[11px] text-foreground-subtle`,children:[i(g,{className:`h-3.5 w-3.5`}),t.alreadyAdded?s(`integrations.scanNetworkModal.alreadyAdded`,`Already added`):s(`integrations.scanNetworkModal.added`,`Added`)]}):u?e(Q,{size:`sm`,variant:l||d?`outline`:`primary`,onClick:()=>o(t),disabled:r,children:[r?i(M,{className:`h-3.5 w-3.5 animate-spin`}):l||d?null:i(E,{className:`h-3.5 w-3.5`}),l?s(`integrations.scanNetworkModal.setUp`,`Set up`):d?s(`integrations.addDeviceModal.enterDetails`,`Enter details`):s(`common.add`,`Add`)]}):null]})}function Nt({addonId:t,integrationId:n,row:r,found:a,busy:s,error:c,onBack:l,onSubmit:u,embedded:f}){let{t:p}=$(),m=we({addonId:t,integrationId:n}),h=m.data?.deviceType??null,g=ue({addonId:t,integrationId:n,type:h??P.Camera},{enabled:m.isSuccess&&h!==null}),_=g.data??null,[v,y]=o(null),b=v??kt(_,a),x=m.error??g.error,S=m.isSuccess&&h===null,C=_!==null,w=C?i(Je,{schema:_,values:b,onChange:y}):x?i(jt,{text:Ot(x)}):S?i(`p`,{className:`text-xs text-foreground-muted`,children:p(`integrations.addDeviceModal.noCreationType`,`This integration cannot create a device from this candidate.`)}):i(M,{className:`mx-auto h-5 w-5 animate-spin text-primary`}),T=e(d,{children:[e(Q,{variant:`ghost`,size:`sm`,onClick:l,children:[i(D,{className:`h-3.5 w-3.5`}),p(`integrations.addDeviceModal.back`,`Back to the list`)]}),i(`p`,{className:`text-xs font-medium text-foreground`,children:r.name}),w,c!==null&&i(jt,{text:c})]}),E=e(d,{children:[i(Q,{variant:`outline`,size:`sm`,onClick:l,children:p(`integrations.cancel`,`Cancel`)}),e(Q,{variant:`primary`,size:`sm`,onClick:()=>u(b),disabled:s||!C,children:[s&&i(M,{className:`h-3.5 w-3.5 animate-spin`}),p(`common.add`,`Add`)]})]});return f?e(`div`,{className:`shrink-0 space-y-3 border-b border-border pb-3`,children:[T,i(`div`,{className:`flex justify-end gap-2`,children:E})]}):e(d,{children:[i(U,{className:`space-y-3`,children:T}),i(X,{children:E})]})}c();function Pt(e){return e===`manual`?`manual`:e===`pairing`?`pairing`:`network`}function Ft({addonId:t,integrationId:n,kind:r,canScan:a,onClose:s,pairing:c,onSetupIntegration:l}){let{t:u}=$(),f=lt(t,n),p=r===`device-adoption`&&a===null,m=r===`device-adoption`||a===!0,h=f===`available`,[g,_]=o(null),v=g??(c===void 0?m?`network`:`manual`:`pairing`),y=[m,h,c!==void 0].filter(Boolean).length,b=p?i(U,{children:i(M,{className:`mx-auto h-5 w-5 animate-spin text-primary`})}):r===`device-adoption`?e(d,{children:[a===!0&&i(At,{addonId:t,integrationId:n,onClose:s,alongsideAdoption:!0,...l?{onSetupIntegration:l}:{}}),i(bt,{addonId:t,integrationId:n,onClose:s})]}):i(At,{addonId:t,integrationId:n,onClose:s,...l?{onSetupIntegration:l}:{}}),x=i(ut,{integrationId:n,addonId:t,onClose:s});return i(J,{open:!0,onOpenChange:e=>{e||s()},children:e(ee,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,className:r===`device-adoption`?`md:h-[85vh]`:void 0,children:[i(Re,{children:i(L,{children:u(`integrations.addDevice`,`Add device`)})}),y>1?e(_e,{value:v,onValueChange:e=>_(Pt(e)),children:[e(Ce,{children:[m&&i(Ae,{value:`network`,children:u(`integrations.addDeviceModal.tabNetwork`,`Found on the network`)}),h&&i(Ae,{value:`manual`,children:u(`integrations.addDeviceModal.tabManual`,`Enter parameters`)}),c!==void 0&&i(Ae,{value:`pairing`,children:c.label})]}),m&&i(Me,{value:`network`,children:b}),h&&i(Me,{value:`manual`,children:x}),c!==void 0&&i(`div`,{role:`tabpanel`,id:`tabpanel-pairing`,hidden:v!==`pairing`,className:`pt-3`,children:c.render({onPaired:()=>_(`network`)})})]}):c!==void 0&&!m&&!h?c.render({onPaired:()=>_(`network`)}):m?b:h?x:f===`loading`?i(U,{children:i(M,{className:`mx-auto h-5 w-5 animate-spin text-primary`})}):i(U,{children:i(`p`,{className:`py-6 text-center text-xs text-foreground-subtle`,children:u(`integrations.addDeviceModal.nothingToAdd`,`This integration has no way to add a device from here.`)})})]})})}c();var It=`matter`,Lt=[`discovering`,`pase`,`commissioning`,`done`];function Rt(e){return!(typeof e!=`object`||!e||!(`phase`in e)||typeof e.phase!=`string`)}function zt(e,t){return e===`code-expired`||t?.includes(`matter-commission:code-expired`)?{key:`integrations.addMatter.failure.expired`,defaultValue:`The pairing code expired. Share the device again and paste the new code.`}:e===`device-not-found`||t?.includes(`matter-commission:device-not-found`)?{key:`integrations.addMatter.failure.notFound`,defaultValue:`No Matter device with that code was found on the network.`}:e===`wrong-code`||t?.includes(`matter-commission:wrong-code`)?{key:`integrations.addMatter.failure.wrongCode`,defaultValue:`The pairing code was rejected.`}:e===`invalid-code`||t?.includes(`invalid pairing code`)?{key:`integrations.addMatter.failure.invalid`,defaultValue:`Enter an 11-digit or 21-digit manual code, or a code that starts with MT:.`}:{key:`integrations.addMatter.failure.unknown`,defaultValue:t??`Commissioning failed.`}}function Bt({onClose:t,onCommissioned:n}){let{t:r}=$(),s=Z({kind:It}),[c,l]=o(null),u=ke(s.data??[],c),f=u.length,p=c??u[0]?.id??null,m=De(),[h,g]=o(``),[_,v]=o({phase:`idle`,failure:null,message:null}),y=_.phase===`discovering`||_.phase===`pase`||_.phase===`commissioning`,b=q({brokerId:p??``,key:`commission`},{enabled:p!==null&&y,refetchInterval:y?400:!1});a(()=>{y&&Rt(b.data)&&b.data.phase!==`idle`&&v({phase:b.data.phase,failure:typeof b.data.failure==`string`?b.data.failure:null,message:typeof b.data.message==`string`?b.data.message:null})},[y,b.data]);let x=()=>{p!==null&&(v({phase:`discovering`,failure:null,message:null}),m.mutate({brokerId:p,target:{action:`commissionNode`},payload:{pairingCode:h.trim()}},{onSuccess:()=>v({phase:`done`,failure:null,message:null}),onError:e=>{let t=e instanceof Error?e.message:`Commissioning failed.`;v({phase:`failed`,failure:t.includes(`matter-commission:`)?t.split(`matter-commission:`)[1]?.split(`:`)[0]??`unknown`:t.includes(`invalid pairing code`)?`invalid-code`:`unknown`,message:t})}}))},S=_.phase===`failed`?zt(_.failure,_.message):null,C=S===null?null:r(S.key,{defaultValue:S.defaultValue}),w=(s.isSuccess===!0||s.data!==void 0)&&p===null;return e(d,{children:[e(U,{className:`space-y-4`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:r(`integrations.addMatter.help`,{defaultValue:`In Home Assistant, open the device and choose Share device. Paste the numeric code or the MT: code here. The device stays in Home Assistant.`})}),(w||f>1)&&!y&&_.phase!==`done`&&e(`div`,{className:`space-y-1.5`,children:[i(Ne,{children:r(`integrations.addMatter.broker`,{defaultValue:`Matter fabric`})}),i(He,{kind:It,value:p,onChange:l})]}),!w&&e(`div`,{className:`space-y-1.5`,children:[i(Ne,{htmlFor:`matter-pairing-code`,children:r(`integrations.addMatter.code`,{defaultValue:`Pairing code`})}),i(Te,{id:`matter-pairing-code`,value:h,autoComplete:`off`,spellCheck:!1,placeholder:`34970112332`,disabled:y||_.phase===`done`,onChange:e=>g(e.target.value)})]}),_.phase!==`idle`&&i(`ol`,{className:`space-y-1`,"aria-label":r(`integrations.addMatter.progress`,{defaultValue:`Commissioning progress`}),children:Lt.map(t=>{let n=_.phase===t;return e(`li`,{className:`text-xs ${n?`text-foreground font-medium`:`text-foreground-subtle`}`,children:[n&&y?i(M,{className:`mr-1 inline h-3 w-3 animate-spin`}):null,r(`integrations.addMatter.phase.${t}`,{defaultValue:t===`discovering`?`Discovering`:t===`pase`?`PASE`:t===`commissioning`?`Commissioning`:`Done`})]},t)})}),C!==null&&i(K,{message:C})]}),e(X,{children:[i(Q,{variant:`ghost`,size:`sm`,onClick:t,children:r(`common.close`,{defaultValue:`Close`})}),_.phase===`done`?i(Q,{size:`sm`,onClick:n,children:r(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}):i(Q,{size:`sm`,disabled:y||w||h.trim().length===0,onClick:x,children:y?r(`integrations.addMatter.working`,{defaultValue:`Adding…`}):r(`integrations.addMatter.submit`,{defaultValue:`Add device`})})]})]})}c();function Vt(e){return typeof e!=`object`||!e||!(`sections`in e)?!1:Array.isArray(Reflect.get(e,`sections`))}function Ht(e){if(typeof e!=`object`||!e||!(`formValues`in e))return{};let t=Reflect.get(e,`formValues`);return typeof t!=`object`||!t||Array.isArray(t)?{}:{...t}}function Ut({integrationId:t,addonId:n,name:r,kind:a,mode:o,brokerKind:c,canTest:u=!1,onClose:d}){let{t:f}=$(),p=k(),m=l(),h=s({queryKey:[`integration-instance-form`,n,t],queryFn:()=>p.trpcClient.integrationInstances.instanceFormSchema.query({addonId:n,id:t})}),g=s({queryKey:[`integration-instance`,n,t],queryFn:()=>p.trpcClient.integrationInstances.getInstance.query({addonId:n,id:t})}),_=Ht(g.data),v=Vt(h.data)?h.data:null,y=h.isSuccess&&g.isSuccess;return i(J,{open:!0,onOpenChange:e=>!e&&d(),children:e(ee,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(Re,{children:e(L,{children:[f(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,r]})}),i(U,{children:h.isError||g.isError?i(`p`,{className:`text-[11px] text-danger`,children:f(`integrations.loadFailed`,{defaultValue:`Could not load this integration.`})}):y?v===null?i(`p`,{className:`text-[11px] text-foreground-muted`,children:f(`integrations.noInstanceForm`,{defaultValue:`This integration has no configuration form.`})}):i(Wt,{addonId:n,integrationId:t,name:r,schema:v,stored:_,onClose:d,onSaved:()=>{m.invalidateQueries()}}):e(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[i(M,{className:`h-3 w-3 animate-spin`}),f(`integrations.loading`,{defaultValue:`Loading…`})]})})]})})}function Wt({addonId:t,integrationId:n,name:r,schema:a,stored:s,onClose:c,onSaved:l}){let{t:d}=$(),f=k(),[p,m]=o({...s}),h=N(a,{...s}),g=u({mutationFn:async()=>{let e=We(s,p);await f.trpcClient.integrationInstances.updateInstance.mutate({addonId:t,id:n,values:e})},onSuccess:()=>{l(),qe({title:d(`integrations.saved`,{defaultValue:`Configuration saved`}),message:r,severity:`info`}),c()},onError:e=>{qe({title:d(`integrations.saveFailed`,{defaultValue:`Could not save the configuration`}),message:`${r}: ${e.message}`,severity:`critical`})}});return e(`div`,{className:`space-y-3`,children:[i(V,{schema:h,values:p,onChange:m}),e(`div`,{className:`flex justify-end gap-2`,children:[i(Q,{size:`sm`,variant:`outline`,type:`button`,onClick:c,children:d(`common.cancel`,{defaultValue:`Cancel`})}),e(Q,{size:`sm`,type:`button`,disabled:g.isPending,onClick:()=>g.mutate(),children:[g.isPending?i(M,{className:`h-3 w-3 animate-spin`}):null,d(`integrations.save`,{defaultValue:`Save`})]})]})]})}function Gt(e){return e==null?!1:e.sections.some(e=>e.fields.length>0)}c();function Kt(){let{addonId:e=``}=Ve();return i(Jt,{addonId:e})}function qt(){return e(`div`,{className:`p-4`,children:[i(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),i(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]})}function Jt({addonId:t}){let{t:c}=$(),u=l(),d=Be(),[f,m]=Ue(),g=k(),[_,v]=o(!1),y=r(e=>{v(!1),d(`/integrations`,{state:{integrationSeed:e}})},[d]),[b,x]=o(!1),[w,E]=o(!1),{data:O}=Y(void 0),A=n(()=>(O??[]).filter(e=>e.addonId===t),[O,t]),j=Ye(f.get(`instance`),A)??``,N=r(e=>{m(t=>{let n=new URLSearchParams(t);return n.set(Xe,e),n},{replace:!0})},[m]),P=n(()=>A.map(e=>({value:e.id,label:e.name})),[A]),{data:R,isLoading:z}=fe({id:j},{enabled:!!j}),{data:B,isSuccess:V}=he(),H=n(()=>{let e=R?.addonId;return!e||!V?null:(B??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[B,R?.addonId,V]),{data:K,isPending:q}=G({}),ie=n(()=>q?null:(K?.providers??[]).some(e=>e.addonId===R?.addonId),[q,K,R?.addonId]),X=H!==null,oe=R?.info?.fixed===!0,se=n(()=>{let e=R?.addonId;return!e||!V?null:(B??[]).find(t=>t.addonId===e)?.brokerKind??null},[B,R?.addonId,V]),ue=se===`matter`,pe=X?c(`integrations.addDevice`,`Add device`):c(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),_e=n(()=>{let e=R?.addonId;return!e||!V?!1:(B??[]).find(t=>t.addonId===e)?.canTest===!0},[B,R?.addonId,V]),Z=n(()=>{let e=R?.addonId;return!e||!V?null:(B??[]).find(t=>t.addonId===e)?.mode??null},[B,R?.addonId,V]);a(()=>{f.get(`add`)===`1`&&X&&(v(!0),m(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[f,X,m]);let{data:be}=s({queryKey:[`integration-instance-form`,R?.addonId,R?.id],enabled:!!R?.addonId&&!!R?.id,queryFn:()=>g.trpcClient.integrationInstances.instanceFormSchema.query({addonId:R?.addonId??``,id:R?.id??``})}),xe=be!=null&&Array.isArray(be.sections)&&be.sections.some(e=>e.fields.length>0),{data:Se}=Oe({addonId:R?.addonId??``,nodeId:`hub`},{enabled:!!R?.addonId&&Z!==`account`}),Ce=Z!==null&&Z!==`account`&&Gt(Se),we=n(()=>R?.addonId?[R.addonId]:[],[R?.addonId]),{data:Te}=te({projection:`slim`},{refetchInterval:3e4}),De=[[`integrations`,`get`],{input:{id:j},type:`query`}],ke={onMutate:async e=>{await u.cancelQueries({queryKey:De});let t=u.getQueryData(De);return t!=null&&u.setQueryData(De,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&u.setQueryData(De,r.previous)},onSettled:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}},Ae=I(ke),je=W(ke),Me={isPending:Ae.isPending||je.isPending,mutate:e=>oe?Ae.mutate(e):je.mutate({...e,addonId:R?.addonId})},Ne=me({onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]}),d(A.length>1?Ge(t):`/integrations`)}}),Pe=Ee({onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=Ze(),Le=re({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ze=ae({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ve=n(()=>Te??[],[Te]),He=n(()=>{let e=new Map;for(let t of Ve)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[Ve]),We=r(e=>He.get(e)??null,[He]),Ke=n(()=>de(O),[O]),qe=r(e=>d(`/devices/${String(e)}`),[d]),Je=n(()=>Ve.filter(e=>{let t=Ke(e);return t.kind===`resolved`&&t.integration.id===j}),[Ve,j,Ke]),$e=n(()=>O===void 0?null:ne(Je).length,[O,Je])??`…`;if(z||O===void 0)return i(qt,{});let et=(B??[]).find(e=>e.addonId===t)?.name??R?.name??t;return R?e(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[i(le,{items:[{label:c(`integrationDetail.integrations`,`Integrations`),onClick:()=>d(`/integrations`)},{label:et}]}),e(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[e(`div`,{className:`flex items-center gap-3 min-w-0`,children:[i(Yt,{addonId:R.addonId}),e(`div`,{className:`min-w-0`,children:[i(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:et}),e(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[$e,` `,c(`integrations.devices`)]})]})]}),e(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[!oe&&e(Q,{variant:`unstyled`,onClick:()=>{v(!0)},disabled:!X,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:pe,children:[i(T,{className:`h-3.5 w-3.5`}),pe]}),e(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Me.isPending?`opacity-60`:``} ${R.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:c(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[i(ve,{checked:R.enabled,onCheckedChange:e=>Me.mutate({id:j,enabled:e}),disabled:Me.isPending,"aria-label":R.enabled?c(`integrationDetail.disableIntegration`,`Disable integration`):c(`integrationDetail.enableIntegration`,`Enable integration`)}),i(`span`,{className:`text-[11px] font-medium ${R.enabled?`text-success`:`text-foreground-subtle`}`,children:R.enabled?c(`integrationDetail.enabled`,`Enabled`):c(`integrationDetail.disabled`,`Disabled`)}),Me.isPending&&i(M,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Z!==`standalone`&&(xe||H===`device-adoption`)&&e(Q,{variant:`unstyled`,onClick:()=>x(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[i(S,{className:`h-3 w-3`}),c(`integrations.config`)]}),e(Q,{variant:`unstyled`,onClick:()=>E(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:c(`integrations.logs`,{defaultValue:`View logs`}),children:[i(C,{className:`h-3 w-3`}),c(`integrations.logs`,{defaultValue:`Logs`})]}),i(ye,{label:c(`integrationDetail.restart`,`Restart`),icon:p,title:c(`integrationDetail.restart2`,`Restart "{{name}}"?`,{name:R.name}),description:c(`integrationDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device backed by it ({{topLevelCountLabel}} active). Streams will reconnect automatically.`,{topLevelCountLabel:$e}),confirmLabel:c(`integrationDetail.restart`,`Restart`),triggerVariant:`outline`,confirmVariant:`danger`,disabled:Pe.isPending,action:()=>Pe.mutateAsync({addonId:R.addonId})}),!oe&&j&&i(ye,{label:c(`integrations.delete`,{defaultValue:`Delete`}),icon:h,title:c(`integrations.deleteTitle`,{defaultValue:`Delete integration?`}),description:c(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:R.name,count:$e}),confirmLabel:c(`integrations.confirmDelete`,{defaultValue:`Delete integration`}),triggerVariant:`outline`,confirmVariant:`danger`,className:`border-danger bg-danger/10 text-danger hover:bg-danger hover:text-background`,disabled:Ne.isPending,action:()=>Ne.mutateAsync({id:j})})]})]}),A.length>1&&i(`div`,{className:`max-w-sm`,children:i(Ie,{mode:`single`,singleDisplay:`field`,label:c(`integrationDetail.instances`,`Integration`),options:P,value:j,onChange:N,testId:`integration-instance-picker`,optionTestIdPrefix:`integration-instance`})}),Ce&&i(nt,{nodeId:null,addonIds:we,level:`global`,surface:`integration`,title:c(`integrations.settings`,{defaultValue:`Settings`})}),i(ce,{context:`integration-detail`,devices:Ve,trpc:g.trpcClient,integrationOf:Ke,forceIntegrationId:j,urlScope:`root`,lsKey:`integration-detail:${R.addonId}`,resolveIntegrationIcon:Qe,resolveParent:We,onNavigate:qe,rowOperation:Fe.rowOperation,batchActions:{remove:Fe.remove,disable:Le.mutate,enable:ze.mutate},...oe?{}:{onDeleteDevice:e=>Fe.remove({deviceId:e.id})}}),_&&j&&H!==null&&i(Ft,{addonId:R.addonId,integrationId:j,kind:H,canScan:ie,onSetupIntegration:y,...ue?{pairing:{label:c(`integrations.addMatter.tab`,`Pairing code`),render:({onPaired:e})=>i(Bt,{onClose:()=>v(!1),onCommissioned:e})}}:{},onClose:()=>v(!1)}),b&&j&&H!==null&&Z!==null&&i(Ut,{integrationId:j,addonId:R.addonId,name:R.name,kind:H,mode:Z,brokerKind:se,canTest:_e,onClose:()=>x(!1)}),w&&i(J,{open:!0,onOpenChange:e=>!e&&E(!1),children:e(ee,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[i(Re,{className:`mb-0`,children:e(L,{className:`flex items-center gap-2 min-w-0`,children:[i(C,{className:`h-4 w-4 text-primary shrink-0`}),i(`span`,{className:`truncate`,children:R.name}),e(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate font-normal`,children:[R.addonId,j?` · ${j}`:``]})]})}),i(U,{className:`min-h-0 overflow-hidden p-0`,children:i(ge,{addonId:R.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})})]}):e(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[i(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:i(F,{className:`h-6 w-6 text-foreground-subtle`})}),e(`div`,{className:`space-y-1 max-w-sm`,children:[i(`h2`,{className:`text-sm font-semibold text-foreground`,children:c(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:c(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:t})})]}),e(Q,{variant:`unstyled`,onClick:()=>d(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[i(D,{className:`h-3 w-3`}),c(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}function Yt({addonId:e}){let t=ze(e),[n,r]=o(!1);return!t||n?null:i(`img`,{src:t,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:()=>r(!0)})}export{Kt as IntegrationDetailPage};
@@ -1 +0,0 @@
1
- import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,et as s,o as c,x as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Dr as u,Fi as d,Fn as f,Hi as p,Ii as m,Li as h,Pi as g,Rn as _,Sn as v,Un as y,Ut as b,V as x,Wn as S,ai as C,dt as w,ht as T,wn as E,xr as D}from"./player-overlays-D5PuUVGx.js";import{cs as ee,us as O}from"./client-DDfmis6s.js";import{t as te}from"./table-2-QGOqxHnt.js";import{$i as k,Br as ne,Fo as re,Fr as A,Io as ie,Ir as ae,Jr as oe,Js as se,Ki as ce,Ko as le,Ks as ue,Kt as de,Lo as j,No as fe,Po as pe,Pr as me,Qs as he,So as ge,Ut as _e,W as ve,Ws as ye,Wt as be,Yo as M,Zs as xe,_t as N,a as Se,lr as P,of as F,rs as I,sa as Ce,vi as L,zr as R}from"./src-kgyauwxD.js";import{t as z}from"./i18n-C-ZuqT0u.js";import{t as B}from"./useTranslation-BJr-n0es.js";import{Fr as we,K as Te,Lr as V,Pr as H,W as U,b as Ee,ct as De,lt as Oe,ut as W}from"./index-tVCZ0Ciq.js";import{t as ke}from"./AdminPage-CN1M6UZ4.js";import"./useEventInvalidation-Gb8kSp8V.js";import{t as Ae}from"./device-integration-icon-C7ZXUKQ-.js";import{a as G,i as je,n as K,o as q,r as J,s as Y,t as Me}from"./ScanSubnetEditor-DxjiHfEb.js";import{t as Ne}from"./framework-packages-DoBKjjer.js";s();function X(e){return e.some(e=>e.status===`running`)?`running`:e.some(e=>e.status===`stopped`)?`stopped`:`disabled`}function Pe(e,t){let n=new Map;for(let t of e){let e=n.get(t.addonId);e===void 0?n.set(t.addonId,[t]):e.push(t)}return[...n.entries()].map(([e,n])=>{let r=t.get(e)?.trim()??``;return{addonId:e,name:r.length>0?r:n[0]?.name??e,instances:n,instanceCount:n.length,deviceCount:n.reduce((e,t)=>e+t.deviceCount,0),status:X(n)}})}function Fe(e){return e.integrationSection===void 0?Ne(e.packageName)?`system`:`providers`:e.integrationSection}function Ie(e){let t=new Set;for(let n of e??[])Fe(n.manifest)===`system`&&t.add(n.manifest.id);return t}function Le(e,t){return{providers:e.filter(e=>!t.has(e.addonId)),system:e.filter(e=>t.has(e.addonId))}}function Re(e,t){return[...e].sort((e,n)=>e.name.localeCompare(n.name,t,{sensitivity:`base`}))}var ze=3e3,Be=new Set([`no-provider`,`node-offline`,`transport-failed`]),Ve=[`provider not available`,`failed to fetch`,`networkerror`,`load failed`];function He(e){if(typeof e!=`object`||!e)return null;let t=Reflect.get(e,`data`);if(typeof t!=`object`||!t)return null;let n=Reflect.get(t,`capRouteReason`);return typeof n==`string`?n:null}function Ue(e,t){if(e==null||t>10)return!1;let n=He(e);if(n!==null)return Be.has(n);let r=(e instanceof Error?e.message:String(e)).toLowerCase();return Ve.some(e=>r.includes(e))}function We(e){return Ue(e.state.error,e.state.errorUpdateCount)?ze:!1}function Z({kind:t,children:n}){let{t:r}=B(),a=`integrations-section-${t}`;return e(`section`,{"aria-labelledby":a,"data-testid":a,className:`min-w-0 space-y-2`,children:[i(`h2`,{id:a,className:x,children:t===`providers`?r(`integrations.sections.providers`,`Providers`):r(`integrations.sections.system`,`System`)}),n]})}function Ge({children:e}){return i(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2 sm:gap-3 lg:grid-cols-3`,children:e})}function Ke({addonId:t,name:n,openLabel:r,onOpen:a,body:o,footer:s,disabled:c=!1,testId:l,buttonTestId:u}){return e(`article`,{"data-testid":l,className:`relative flex min-w-0 items-stretch gap-3 overflow-x-clip rounded-lg border border-border bg-surface p-3`,children:[i(L,{type:`button`,variant:`ghost`,"aria-label":r,disabled:c,"data-testid":u,onClick:a,className:`absolute inset-0 z-0 h-auto w-auto rounded-lg p-0 focus-visible:ring-2 focus-visible:ring-primary`}),i(`div`,{className:`pointer-events-none relative z-10 flex w-20 shrink-0 items-center justify-center`,children:i(U,{type:t,size:`xl`})}),e(`div`,{className:`pointer-events-none relative z-10 grid min-w-0 flex-1 grid-rows-[1fr_auto_1fr] gap-1`,children:[i(`p`,{className:`min-w-0 self-start truncate text-sm font-semibold text-foreground`,children:n}),o,i(`div`,{className:`self-end justify-self-start`,children:s})]})]})}function qe({providers:t,system:r,onOpen:a,searchPlaceholder:s,emptyLabel:c}){let[l,u]=o(``),d=n(()=>{let e=l.trim().toLowerCase(),n=t=>e.length===0||`${t.name} ${t.addonId} ${t.instances.map(e=>e.name).join(` `)}`.toLowerCase().includes(e);return{providers:t.filter(n),system:r.filter(n)}},[l,t,r]),f=d.providers.length===0&&d.system.length===0;return e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`relative`,children:[i(E,{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}),i(F,{type:`search`,value:l,onChange:e=>u(e.target.value),placeholder:s,"aria-label":s,className:`pl-8`})]}),f?i(`p`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:c}):e(`div`,{className:`space-y-4`,children:[d.providers.length>0&&i(Z,{kind:`providers`,children:i(Q,{groups:d.providers,onOpen:a})}),d.system.length>0&&i(Z,{kind:`system`,children:i(Q,{groups:d.system,onOpen:a})})]})]})}function Q({groups:e,onOpen:t}){let{t:r,i18n:a}=B();return i(Ge,{children:n(()=>Re(e,a.language),[e,a.language]).map(e=>i(Ke,{testId:`integration-card-${e.addonId}`,addonId:e.addonId,name:e.name,openLabel:r(`integrations.openNamed`,{name:e.name,defaultValue:`Open {{name}}`}),onOpen:()=>t(e),body:i(`p`,{className:`text-xs text-foreground-muted`,children:r(`integrations.addonCard.summary`,{integrations:r(`integrations.addonCard.integrationCount`,{count:e.instanceCount}),devices:r(`integrations.integrationColumns.deviceCount`,{count:e.deviceCount}),defaultValue:`{{integrations}} · {{devices}}`})}),footer:i(N,{status:e.status,className:`shrink-0`})},e.addonId))})}s();var $=`camstack.admin.integrations.view`;function Je(e){return e===`table`||e===`grid`}function Ye(){try{return typeof window>`u`?null:window.localStorage}catch{return null}}function Xe(e=Ye()){if(e===null)return`table`;try{let t=e.getItem($);return Je(t)?t:`table`}catch{return`table`}}function Ze(e,t=Ye()){if(t!==null)try{t.setItem($,e)}catch{}}function Qe(){let[e,t]=o(()=>Xe());return[e,r(e=>{t(e),Ze(e)},[])]}s();function $e(e=!0){a(()=>{if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=t}},[e])}s();function et(e,t){let[n,r]=o(!1);return a(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}s();function tt({kind:t,onResolved:n,onBack:r}){let{t:a}=B(),[s,c]=o(null);return e(`div`,{className:`space-y-4`,children:[e(L,{variant:`ghost`,size:`sm`,onClick:r,children:[i(d,{className:`h-3.5 w-3.5`}),` `,a(`common.back`)]}),i(Te,{kind:t,value:s,onChange:c}),i(`div`,{className:`flex justify-end pt-1`,children:i(L,{variant:`primary`,size:`sm`,disabled:s===null,onClick:()=>s!==null&&n(s),children:a(`integrations.brokerStep.useThisBroker`,`Use this broker`)})})]})}s();function nt({providerId:t,onImport:n,onSkip:r}){let{t:s}=B(),[c,l]=o(new Set),u=pe(),d=u.data,f=u.isPending||!u.data&&!u.isError;a(()=>{t&&(u.isPending||u.data||u.mutate({addonId:t}))},[t,u]);function m(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(f)return e(`div`,{className:`flex flex-col items-center py-12`,children:[i(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),i(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:s(`integrations.searchingDevices`)})]});let g=d??[];return e(`div`,{className:`space-y-4`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:g.length>0?s(`integrations.foundDevices`,{count:g.length}):s(`integrations.noDevicesFound`)}),g.length>0&&i(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:g.map(t=>{let n=t.stableId,r=t.suggestedName??n,a=c.has(n),o=t.alreadyOnboarded===!0;return e(L,{variant:`unstyled`,onClick:()=>{o||m(n)},disabled:o,title:o?s(`integrations.alreadyAddedHint`,{defaultValue:`Already added as "{{name}}" — re-adding would overwrite its settings.`,name:t.onboardedName??r}):void 0,className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${o?`border-border bg-surface opacity-60 cursor-not-allowed`:a?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[i(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${a&&!o?`border-primary bg-primary`:`border-border`}`,children:a&&!o&&i(h,{className:`h-3 w-3 text-primary-foreground`})}),i(p,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),i(`span`,{className:`text-xs font-medium text-foreground truncate`,children:r}),o&&i(`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:s(`integrations.alreadyAdded`,{defaultValue:`Already added`})})]},n)})}),e(`div`,{className:`flex items-center justify-between pt-2`,children:[i(L,{variant:`unstyled`,onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:s(`integrations.skip`)}),g.length>0&&e(L,{variant:`unstyled`,onClick:()=>n(Array.from(c)),disabled:c.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:[s(`integrations.importSelected`),` (`,c.size,`)`]})]})]})}s();function rt({addonId:t,configSchema:n,canTest:r=!0,instanceKind:a,initialName:s,initialConfig:c,submitLabel:l,hideName:u=!1,saving:d=!1,onScan:f,onSave:p,onBack:m}){let{t:h}=B(),[g,v]=o(s??``),[y,b]=o(c??{}),[x,S]=o(null),C=ue({onSuccess:e=>S(Oe(e)),onError:e=>S({status:`inconclusive`,error:String(e)})}),w=k(),T=!r||x?.status===`validated`,E=!u&&g.trim().length===0,D=!E&&T;return e(`div`,{className:`space-y-4`,children:[!u&&e(`div`,{children:[i(`label`,{htmlFor:`integration-name`,className:`block text-[11px] font-medium text-foreground mb-1`,children:h(`integrations.integrationName`)}),i(F,{id:`integration-name`,type:`text`,value:g,onChange:e=>v(e.target.value),placeholder:h(`integrations.integrationNamePlaceholder`),"aria-invalid":E,"aria-describedby":E?`integration-name-error`:void 0,className:`w-full rounded-lg border bg-surface px-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none ${E?`border-danger focus:border-danger`:`border-border focus:border-primary/50`}`}),E&&i(`p`,{id:`integration-name-error`,"data-testid":`integration-name-error`,className:`mt-1 text-xs text-danger`,children:h(`integrations.nameRequired`,`Name is required`)})]}),n&&i(W,{schema:n,values:y,onChange:e=>{b(e),S(null)},onAction:async(e,i,o)=>{let s=await w.mutateAsync({addonId:t,action:e,input:o??{}});if(r&&typeof s==`object`&&s){let e=s;if(!(typeof e.token==`string`||typeof e.sslCertificate==`string`||typeof e.host==`string`))return s;let r={...y};for(let[t,n]of Object.entries(e))typeof n==`string`&&t!==`summary`&&(r[t]=n);let i=O(n,r);b(i),S(null),C.mutate({addonId:t,id:null,values:i,...a===void 0?{}:{kind:a}})}return s}}),x&&i(De,{verdict:x}),e(`div`,{className:`flex items-center justify-between pt-2`,children:[i(L,{variant:`unstyled`,onClick:m,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:h(`integrations.back`)}),e(`div`,{className:`flex items-center gap-2`,children:[f&&e(L,{variant:`outline`,size:`sm`,onClick:f,"data-testid":`integration-scan`,children:[i(_,{className:`h-3.5 w-3.5`}),h(`integrations.scanFromForm`,`Scan the network`)]}),i(L,{variant:`unstyled`,onClick:()=>C.mutate({addonId:t,id:null,values:O(n,y),...a===void 0?{}:{kind:a}}),disabled:C.isPending||!r,title:r?void 0:h(`integrations.connectionUntestable`,{defaultValue:`This integration cannot be tested before it is created.`}),className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:C.isPending?h(`integrations.testing`):h(`integrations.testConnection`)}),e(`div`,{className:`flex flex-col items-end gap-1`,children:[E&&i(`p`,{"data-testid":`integration-name-submit-error`,className:`text-xs text-danger`,children:h(`integrations.nameRequiredSubmit`,`Enter a name before continuing.`)}),i(L,{variant:`unstyled`,onClick:()=>{E||p({name:g,config:O(n,y),secretKeys:[...ee(n)]})},disabled:!D||d,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:d?h(`integrations.saving`,{defaultValue:`Saving…`}):l??h(`integrations.forward`)})]})]})]})]})}var it=`(hover: none) and (pointer: coarse)`;function at(){if(typeof window>`u`||typeof window.matchMedia!=`function`)return!0;try{return!window.matchMedia(it).matches}catch{return!0}}s();function ot({onSelect:r,onClose:s,pendingAddonId:c=null}){let{t:l,i18n:u}=B(),d=we(),[f,p]=o(``),m=t(null),{data:h,isLoading:g}=xe();a(()=>{g||!at()||m.current?.focus()},[g]);let _=n(()=>{let e=h??[],t=f.trim().toLowerCase();return t.length===0?e:e.filter(e=>`${e.name} ${e.description??``} ${e.addonId}`.toLowerCase().includes(t))},[h,f]),{data:y}=Ce(void 0),b=n(()=>{let e=Le(_,Ie(y));return{providers:Re(e.providers,u.language),system:Re(e.system,u.language)}},[_,y,u.language]);if(g)return i(`div`,{className:`grid grid-cols-1 gap-2 p-2 sm:grid-cols-2 lg:grid-cols-3`,children:[1,2,3,4].map(e=>i(`div`,{className:`h-24 rounded-lg bg-surface animate-pulse`},e))});let x=c!==null,S=t=>i(Ge,{children:t.map(t=>{let n=t.instanceMode===`unique`&&t.existingInstances.length>0,a=c===t.addonId;return i(Ke,{testId:`provider-card-${t.addonId}`,buttonTestId:`provider-pick-${t.addonId}`,addonId:t.addonId,name:t.name,openLabel:t.name,disabled:x,onOpen:()=>{if(n){let e=t.existingInstances[0].id;s(),d(Ee(t.addonId,e))}else r(t.addonId,t.instanceMode,t.discoveryMode,t.name,t.kind,t.brokerKind,t.mode,t.canTest)},body:t.description?i(`p`,{className:`line-clamp-2 text-xs text-foreground-muted`,children:t.description}):i(`span`,{}),footer:a?i(D,{className:`h-4 w-4 animate-spin text-primary`}):n?e(`span`,{className:`flex items-center gap-1 text-xs font-medium text-foreground-subtle`,children:[i(v,{className:`h-3 w-3`}),l(`integrations.manage`)]}):null},t.addonId)})});return e(`div`,{className:`space-y-3`,"data-testid":`provider-picker`,children:[e(`div`,{className:`relative`,children:[i(E,{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}),i(F,{ref:m,type:`search`,value:f,onChange:e=>p(e.target.value),placeholder:l(`integrations.searchProviders`,`Search integrations…`),className:`pl-8`,"data-testid":`provider-picker-search`,"aria-label":l(`integrations.searchProviders`,`Search integrations…`)})]}),b.providers.length>0&&i(Z,{kind:`providers`,children:S(b.providers)}),b.system.length>0&&i(Z,{kind:`system`,children:S(b.system)}),_.length===0&&i(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:(h??[]).length===0?l(`integrations.noProviders`):l(`integrations.noProvidersMatch`,`No integrations match your search.`)})]})}s();function st({open:t,onClose:a,scope:s,onSetupIntegration:c,pickMode:l=`adopt`}){let{t:u}=B(),d=ge(),[f,p]=o(new Set),[m,h]=o(new Set),[g,v]=o(new Set),{data:y}=le({projection:`slim`}),b=n(()=>new Set((y??[]).map(e=>e.stableId)),[y]),x=r(async(e,t)=>{h(e=>new Set(e).add(t.stableId));try{await d.mutateAsync({addonId:e,candidate:t}),p(e=>new Set(e).add(t.stableId)),v(e=>{let n=new Set(e);return n.delete(t.stableId),n})}catch{}finally{h(e=>{let n=new Set(e);return n.delete(t.stableId),n})}},[d]),S=r(async(e,t)=>{let n=l===`fill`?G(e,t):K(e,t);if(n!==null){c?.(n),a();return}await x(e,t)},[x,a,c,l]),C=r(e=>{v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),w=r(()=>{p(new Set),v(new Set)},[]),T=n(()=>({existingStableIds:b,adopted:f,adopting:m,selection:{selected:g,toggle:C},pick:S,adoptOne:x,fill:l===`fill`}),[b,f,m,g,C,S,l]),E=s?u(`integrations.scanNetworkModal.titleScoped`,`Scan network — {{label}}`,{label:s.label}):u(`integrations.scanNetworkModal.title`,`Scan network for devices`);return i(me,{open:t,onOpenChange:e=>!e&&a(),children:e(ae,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(R,{children:i(ne,{children:e(`span`,{className:`flex items-center gap-2`,children:[i(_,{className:`h-4 w-4 text-primary`}),E]})})}),e(A,{className:`space-y-4`,children:[i(Me,{}),s?i(mt,{scope:s,row:T,onReset:w}):i(pt,{row:T,onReset:w})]})]})})}function ct(e,t){return!t&&e.selectable!==!1&&!J(e)}function lt({addonId:t,nodes:n,row:r,depth:a}){return i(`div`,{className:a===0?`space-y-1.5`:`ml-4 space-y-1.5 border-l border-border pl-3`,"data-testid":a===0?void 0:`scan-children`,children:n.map(n=>e(`div`,{className:`space-y-1.5`,children:[i(ut,{addonId:t,candidate:n.candidate,row:r}),n.children.length>0&&i(lt,{addonId:t,nodes:n.children,row:r,depth:a+1})]},n.candidate.stableId))})}function ut({addonId:t,candidate:n,row:r}){let{t:a}=B(),o=n.prefilledConfig.host,s=typeof o==`string`?o:null,c=r.existingStableIds.has(n.stableId)||n.alreadyOnboarded===!0||n.onboardedDeviceId!==void 0,l=r.adopted.has(n.stableId)||c,u=r.adopting.has(n.stableId),d=r.fill||J(n),f=!l&&(d||n.selectable!==!1),p=f&&ct(n,r.fill);return e(`div`,{className:`flex items-center gap-3 rounded-lg border border-border bg-surface px-3 py-2`,"data-testid":`scan-row-${n.stableId}`,children:[p&&i(P,{checked:r.selection.selected.has(n.stableId),onChange:()=>r.selection.toggle(n.stableId),disabled:u,"aria-label":a(`integrations.scanNetworkModal.select`,`Select {{name}}`,{name:n.suggestedName})}),e(`div`,{className:`min-w-0 flex-1`,children:[i(`p`,{className:`truncate text-xs font-medium text-foreground`,children:n.suggestedName}),s&&i(`p`,{className:`truncate font-mono text-[10px] text-foreground-subtle`,children:s}),c&&n.onboardedName!==void 0&&i(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:n.onboardedName})]}),l?e(`span`,{className:`flex items-center gap-1 text-[11px] text-foreground-subtle`,children:[i(h,{className:`h-3.5 w-3.5`}),` `,c?a(`integrations.scanNetworkModal.alreadyAdded`,`Already added`):a(`integrations.scanNetworkModal.added`,`Added`)]}):f?e(L,{size:`sm`,variant:d?`outline`:`primary`,onClick:()=>void r.pick(t,n),disabled:u,children:[u?i(D,{className:`h-3.5 w-3.5 animate-spin`}):d?null:i(C,{className:`h-3.5 w-3.5`}),d?r.fill?a(`integrations.scanNetworkModal.use`,`Use`):a(`integrations.scanNetworkModal.setUp`,`Set up`):a(`common.add`,`Add`)]}):null]})}function dt({addonId:t,label:r,candidates:a,row:o}){let s=n(()=>q(a),[a]);return e(`section`,{className:`space-y-2`,"data-testid":`scan-group-${t}`,children:[e(`h3`,{className:`flex items-center gap-2`,children:[i(U,{type:t,size:`sm`}),i(`span`,{className:x,children:r}),e(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`(`,a.length,`)`]})]}),i(lt,{addonId:t,nodes:s,row:o,depth:0})]})}function ft(e,t){return e.flatMap(e=>Y(q(e.candidates)).filter(e=>ct(e,t)).map(t=>({addonId:e.addonId,candidate:t})))}function pt({row:t,onReset:o}){let{t:s}=B(),c=fe(),l=r(()=>{o(),c.mutate({})},[c,o]);a(()=>{!c.isPending&&!c.data&&l()},[]);let u=n(()=>(c.data?.groups??[]).filter(e=>e.candidates.length>0),[c.data]),d=n(()=>u.reduce((e,t)=>e+t.candidates.length,0),[u]),p=n(()=>ft(u,t.fill),[u,t.fill]);return e(`div`,{className:`space-y-4`,children:[e(`div`,{className:`flex items-center justify-between gap-2`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:!c.isPending&&u.length>0?s(`integrations.scanNetworkModal.found`,{count:d}):null}),e(`div`,{className:`flex items-center gap-2`,children:[i(ht,{entries:p,row:t}),e(L,{variant:`outline`,size:`sm`,onClick:l,disabled:c.isPending,children:[i(f,{className:`h-3.5 w-3.5 ${c.isPending?`animate-spin`:``}`}),s(`integrations.scanNetworkModal.reScan`,`Re-scan`)]})]})]}),c.isPending&&i(_t,{label:s(`integrations.scanNetworkModal.scanningTheLocalNetwork`,`Scanning the local network…`)}),!c.isPending&&c.isError&&i(vt,{}),!c.isPending&&c.data&&u.length===0&&i(gt,{}),!c.isPending&&u.map(e=>i(dt,{addonId:e.addonId,label:e.label,candidates:e.candidates,row:t},e.addonId))]})}function mt({scope:t,row:a,onReset:s}){let{t:c}=B(),l=I({addonId:t.addonId}).data??null,[u,d]=o({}),f=re(),p=r(()=>{s(),f.mutate({addonId:t.addonId,params:u})},[f,t.addonId,u,s]),m=n(()=>f.data?.candidates??[],[f.data]),h=n(()=>ft([{addonId:t.addonId,candidates:m}],a.fill),[t.addonId,m,a.fill]);return e(`div`,{className:`space-y-4`,children:[l&&i(W,{schema:l,values:u,onChange:d}),e(L,{onClick:p,disabled:f.isPending,children:[f.isPending?i(D,{className:`h-3.5 w-3.5 animate-spin`}):i(_,{className:`h-3.5 w-3.5`}),f.isPending?c(`integrations.scanNetworkModal.scanning`,`Scanning…`):c(`integrations.scanNetworkModal.scan`,`Scan`)]}),i(ht,{entries:h,row:a}),f.isError&&i(vt,{}),!f.isPending&&f.data&&m.length===0&&i(gt,{}),!f.isPending&&m.length>0&&e(`div`,{className:`space-y-2`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:c(`integrations.scanNetworkModal.foundShort`,{count:m.length})}),i(dt,{addonId:t.addonId,label:t.label,candidates:m,row:a})]})]})}function ht({entries:t,row:n}){let{t:r}=B(),a=t.filter(e=>n.selection.selected.has(e.candidate.stableId));if(a.length===0)return null;let o=async()=>{for(let e of a)await n.adoptOne(e.addonId,e.candidate)};return e(L,{size:`sm`,onClick:()=>void o(),"data-testid":`scan-add-selected`,children:[i(C,{className:`h-3.5 w-3.5`}),r(`integrations.scanNetworkModal.addSelected`,`Add selected ({{count}})`,{count:a.length})]})}function gt(){let{t:e}=B();return i(`p`,{className:`py-6 text-center text-xs text-foreground-subtle`,children:e(`integrations.scanNetworkModal.noDevicesRespondedToThe`,`No devices responded to the scan.`)})}function _t({label:t}){return e(`div`,{className:`flex flex-col items-center py-12`,children:[i(D,{className:`h-6 w-6 animate-spin text-primary`}),i(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:t})]})}function vt(){let{t}=B();return e(`div`,{className:`flex items-start gap-3 rounded-lg border border-danger/40 bg-danger/10 px-4 py-3`,children:[i(b,{className:`mt-0.5 h-4 w-4 shrink-0 text-danger`}),i(`p`,{className:`text-xs text-danger`,children:t(`integrations.scanNetworkModal.theScanFailedTryAgain`,`The scan failed. Try again.`)})]})}s();function yt(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 bt=2e4;function xt({open:t,onClose:r,seed:s=null}){let{t:u}=B(),d=we(),f=c(),[p,m]=o(`picker`),[h,g]=o(null),[_,v]=o(null),[y,b]=o(`manual`),[x,S]=o(null),[C,w]=o(``),[T,E]=o(null),[ee,O]=o(null),[te,k]=o(!1),[re,oe]=o({}),[le,ue]=o(``),[de,j]=o(!1),[fe,he]=o(0),[_e,ve]=o(``),be=ie({},{enabled:t&&p===`config`}),M=(ye({addonId:h??``},{enabled:t&&p===`config`&&h!==null}).data?.kinds??[]).filter(e=>e.canTest!==!1),N=M.length===1?M[0]?.id:void 0,Se=h!==null&&(be.data?.providers??[]).some(e=>e.addonId===h),P=s?.config.host,F=s===null?``:`${s.addonId}\0${s.name}\0${typeof P==`string`?P:``}`;t&&s!==null&&le!==F&&(ue(F),g(s.addonId),w(s.name),oe({...s.config}),m(`config`));let I=xe(void 0,{enabled:t&&s!==null}),Ce=I.data?.find(e=>e.addonId===h)?.mode??`account`,{data:z}=ce({addonId:h??``,nodeId:`hub`,instance:{integrationId:null,mode:Ce,...s?.originStableId===void 0?{}:{candidateStableId:s.originStableId}}},{enabled:h!=null}),Te=n(()=>z?yt(z):null,[z]),V=se({onSuccess:()=>f.invalidateQueries({queryKey:[[`integrations`]]})}),H=pe(),U=H.data;a(()=>{if(!t||s===null)return;let e=I.data?.find(e=>e.addonId===s.addonId);e&&(k(e.canTest),b(e.discoveryMode))},[t,s,I.data]),a(()=>{p!==`discovery`||!_||!h||H.isPending||H.data||H.mutate({addonId:h})},[p,_,h,H]);let De=ge({onSuccess:()=>f.invalidateQueries({queryKey:[[`deviceManager`]]})});function Oe(e,t,n,r,i,a,o,s){if(!V.isPending){if(g(e),k(s),b(n),w(r),O(null),V.reset(),o===`broker`){if(!a){O(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}S(a),m(`broker`);return}if(o===`account`){m(`config`);return}W(e,r)}}async function W(e,t){try{let n=await V.mutateAsync({addonId:e,name:t,settings:{}});r(),K(),d(`${Ee(e,n.id)}&add=1`)}catch{}}async function ke(e){if(h)try{let t=await V.mutateAsync({addonId:h,name:e.name,settings:e.config,secretKeys:[...e.secretKeys],...N===void 0?{}:{kind:N},...s!==null&&s.addonId===h&&s.originStableId!==void 0?{originStableId:s.originStableId}:{}});v(t.id),E(t.id),y===`auto`||y===`both`?m(`discovery`):je(t.id,{openAdd:!0})}catch{}}async function Ae(e){if(h)try{let t=await V.mutateAsync({addonId:h,name:C,settings:{brokerId:e}});E(t.id),v(t.id),je(t.id)}catch{}}async function G(e){if(h){for(let t of e){let e=U?.find(e=>e.stableId===t);e&&await De.mutateAsync({addonId:h,candidate:e,...T===null?{}:{integrationId:T}})}je()}}function je(e,t){let n=e??_??h;if(r(),K(),n&&h){let e=Ee(h,n);d(t?.openAdd===!0?`${e}&add=1`:e)}}function K(){m(`picker`),g(null),v(null),b(`manual`),S(null),w(``),E(null),O(null),V.reset(),k(!1),oe({}),ue(``)}function q(){r(),K()}$e(t);let J=V.isPending,Y=et(J,bt);if(!t)return null;let Me={picker:u(`integrations.newIntegration`),config:u(`integrations.configureIntegration`),discovery:u(`integrations.importDevices`),broker:u(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},Ne=J?h:null,X=V.error,Pe=J&&!Y;return e(l,{children:[i(me,{open:!0,onOpenChange:e=>{!e&&!Pe&&q()},children:e(ae,{width:p===`picker`?`xl`:`lg`,scroll:`body`,onCancel:e=>{Pe&&e.preventDefault()},children:[i(R,{children:i(ne,{children:Me[p]})}),e(A,{children:[X&&!J&&i(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:X instanceof Error?X.message:String(X)}),p===`picker`&&e(l,{children:[ee&&i(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:ee}),i(ot,{onSelect:Oe,onClose:q,pendingAddonId:Ne})]}),p===`config`&&h&&i(rt,{addonId:h,configSchema:Te??null,canTest:te,...N===void 0?{}:{instanceKind:N},initialName:C.length>0&&Object.keys(re).length>0?C:void 0,initialConfig:{...re},onScan:Se?()=>{ve(C.length>0?C:h),j(!0)}:void 0,onSave:ke,onBack:()=>{oe({}),m(`picker`)}},`${F.length>0?F:h}:${fe}`),p===`broker`&&x&&i(tt,{kind:x,onResolved:e=>{Ae(e)},onBack:()=>m(`picker`)}),p===`discovery`&&_&&i(nt,{providerId:_,onImport:G,onSkip:je})]}),J&&e(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-lg bg-background/85 backdrop-blur-sm px-6 text-center`,children:[i(D,{className:`h-6 w-6 animate-spin text-primary`}),i(`p`,{className:`text-xs font-medium text-foreground`,children:u(`integrations.creating`,{defaultValue:`Creating integration…`})}),!Y&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:u(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),Y&&e(l,{children:[i(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:u(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),i(L,{variant:`unstyled`,onClick:q,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:u(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})}),de&&h!==null&&i(st,{open:de,scope:{addonId:h,label:_e},pickMode:`fill`,onClose:()=>j(!1),onSetupIntegration:e=>{w(e.name),oe({...e.config}),he(e=>e+1)}})]})}function St({integration:t,expanded:n,onToggleExpand:r}){let{t:a}=B();return e(`div`,{className:`flex items-center gap-2.5`,children:[i(L,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),r(t.addonId)},"aria-label":n?a(`integrations.integrationColumns.collapse`,`Collapse`):a(`integrations.integrationColumns.expand`,`Expand`),"aria-expanded":n,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:i(n?m:g,{className:`h-3.5 w-3.5`})}),i(U,{type:t.addonId,size:`sm`}),e(`div`,{className:`flex min-w-0 flex-col`,children:[i(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:t.name}),i(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.addonId})]})]})}function Ct(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:z.t(`integrations.integrationColumns.integration`,`Integration`),headerClassName:`w-[55%]`,cell:e=>i(St,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:z.t(`integrations.integrationColumns.devices`,`Devices`),headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>z.t(`integrations.integrationColumns.deviceCount`,{count:e.deviceCount})},{key:`status`,header:z.t(`integrations.integrationColumns.status`,`Status`),headerClassName:`w-[15%]`,cell:e=>i(N,{status:e.status})}]}s();var wt=6e4;function Tt({onSetupIntegration:t}){let{t:n}=B(),[r,a]=o(!1),s=M({},{refetchInterval:wt}),c=s.data?.proposals??[];return c.length===0?null:e(l,{children:[e(`div`,{role:`status`,"data-testid":`discovery-banner`,className:`flex flex-wrap items-center gap-2 rounded-lg border border-info/30 bg-info/10 px-3 py-2 text-xs text-foreground`,children:[i(_,{className:`h-3.5 w-3.5 text-info`,"aria-hidden":!0}),i(`span`,{className:`flex-1`,children:n(`integrations.discoveryBanner.count`,{defaultValue_one:`{{count}} new device found`,defaultValue_other:`{{count}} new devices found`,count:c.length})}),i(L,{variant:`secondary`,size:`sm`,onClick:()=>a(!0),children:n(`integrations.discoveryBanner.review`,`Review`)})]}),i(Et,{open:r,onClose:()=>a(!1),proposals:c,onChanged:()=>void s.refetch(),onSetupIntegration:e=>{a(!1),t(e)}})]})}function Et({open:t,onClose:n,proposals:a,onChanged:s,onSetupIntegration:c}){let{t:u}=B(),d=ge(),f=j(),[p,m]=o(new Set),g=r(async(e,t)=>{m(t=>new Set(t).add(e));try{await t(),s()}catch{}finally{m(t=>{let n=new Set(t);return n.delete(e),n})}},[s]),v=r(async e=>{let t=K(e.addonId,e.candidate);if(t!==null){c(t);return}await g(e.id,()=>d.mutateAsync({addonId:e.addonId,candidate:e.candidate}))},[d,c,g]),y=r(e=>g(e.id,()=>f.mutateAsync({id:e.id})),[f,g]);return i(me,{open:t,onOpenChange:e=>!e&&n(),children:e(ae,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(R,{children:i(ne,{children:e(`span`,{className:`flex items-center gap-2`,children:[i(_,{className:`h-4 w-4 text-primary`}),u(`integrations.discoveryBanner.title`,`New devices found`)]})})}),i(A,{className:`space-y-1.5`,children:a.map(t=>e(`div`,{"data-testid":`discovery-proposal`,className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-2`,children:[e(`div`,{className:`min-w-0 flex-1`,children:[i(`p`,{className:`truncate text-sm font-medium text-foreground`,children:t.candidate.suggestedName}),i(`p`,{className:`truncate text-xs text-foreground-muted`,children:t.addonId})]}),p.has(t.id)?i(D,{className:`h-4 w-4 animate-spin text-foreground-muted`,"aria-hidden":!0}):e(l,{children:[i(L,{variant:`secondary`,size:`sm`,onClick:()=>void y(t),children:u(`integrations.discoveryBanner.dismiss`,`Dismiss`)}),e(L,{size:`sm`,onClick:()=>void v(t),children:[i(h,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),u(`integrations.discoveryBanner.adopt`,`Adopt`)]})]})]},t.id))})]})})}s();function Dt(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var Ot=`expand`;function kt(){let{t}=B(),s=we(),c=H(),d=T(),[p]=V(),[m,h]=Qe(),[g,v]=o(!1),[b,x]=o(null),C=r(()=>{x(null),v(!0)},[]),E=r(()=>{v(!1),x(null)},[]),D=r(e=>{O(!1),x(e),v(!0)},[]),[ee,O]=o(!1);a(()=>{let e=je(c.state);e!==null&&(x(e),v(!0),s(`/integrations`,{replace:!0,state:null}))},[c.state,s]);let k=p.get(`setup`);a(()=>{k===null||k.length===0||(x({addonId:k,name:k,config:{}}),v(!0))},[k]);let ne=r(()=>O(!0),[]),re=r(()=>O(!1),[]);Se([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),Se([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:A,isLoading:ie,isError:ae,error:se,errorUpdateCount:ce,refetch:ue}=he(void 0,{refetchInterval:We}),{data:j,isLoading:fe,isError:pe,error:me,errorUpdateCount:ge,refetch:ye}=le({projection:`slim`},{refetchInterval:We}),M=n(()=>j??[],[j]),N=n(()=>A??[],[A]),P=n(()=>{let e=new Map;for(let t of M)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[M]),F=n(()=>be(A),[A]),I=n(()=>{let e=new Map;for(let t of de(M)){let n=F(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[M,F]),R=n(()=>N.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:Dt(e),deviceCount:I.get(e.id)??0})),[N,I]),{data:z}=xe(),Te=n(()=>new Map((z??[]).map(e=>[e.addonId,e.name])),[z]),U=p.get(Ot),De=r(e=>{let t=new URLSearchParams(window.location.search);t.get(Ot)===e?t.delete(Ot):t.set(Ot,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),{data:Oe}=Ce(void 0),W=n(()=>Ie(Oe),[Oe]),G=n(()=>Le(R,W),[R,W]),K=n(()=>Le(Pe(R,Te),W),[R,Te,W]),q=r(e=>s(Ee(e.addonId)),[s]),J=r(e=>s(Ee(e.addonId,e.id)),[s]),Y=r(e=>P.get(e)??null,[P]),Me=r(e=>s(`/devices/${String(e)}`),[s]),Ne=r(e=>i(_e,{context:`integration-detail`,devices:M,trpc:d.trpcClient,integrationOf:F,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:Ae,resolveParent:Y,onNavigate:Me}),[M,d.trpcClient,F,Y,Me]),X=r(e=>U===e.addonId,[U]),Fe=n(()=>Ct({isExpanded:X,onToggleExpand:De}),[X,De]),Re=r(e=>`${e.name} ${e.addonId}`,[]),ze=r(e=>e.id,[]),Be=e=>i(_e,{mode:`generic`,items:e,getKey:ze,getSearchText:Re,columns:Fe,onRowClick:J,isExpanded:X,renderExpanded:Ne,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),Ve=r(()=>{ue(),ye()},[ue,ye]),He=ae===!0&&Ue(se,ce),Ge=pe===!0&&Ue(me,ge),Ke=He||Ge,Q=ae===!0&&!He||pe===!0&&!Ge,$=!Q&&!Ke&&(ie||fe||A===void 0||j===void 0),Je=N.length>0,Ye=[{id:`table`,label:t(`integrations.viewTable`,`Table`),icon:te},{id:`grid`,label:t(`integrations.viewGrid`,`Grid`),icon:u}];return e(ke,{icon:y,title:t(`nav.integrations`,`Integrations`),actions:e(l,{children:[i(ve,{ariaLabel:t(`integrations.viewLabel`,`Layout`),value:m,onChange:h,options:Ye,testId:`integrations-view`}),i(L,{variant:`unstyled`,onClick:Ve,disabled:$,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:t(`common.refresh`,`Refresh`),children:i(f,{className:w(`h-3.5 w-3.5`,$&&`animate-spin`)})}),e(L,{variant:`unstyled`,onClick:ne,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:t(`integrations.scanTheLocalNetworkFor`,`Scan the local network for devices`),children:[i(_,{className:`h-3.5 w-3.5`}),t(`integrations.scanNetwork`,`Scan network`)]}),e(L,{variant:`unstyled`,onClick:C,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:[i(S,{className:`h-3.5 w-3.5`}),t(`integrations.newIntegration`,`New Integration`)]})]}),children:[i(Tt,{onSetupIntegration:D}),Q&&i(oe,{message:t(`integrations.loadFailed`,`Integrations could not be loaded.`),onRetry:Ve}),Ke&&!Q&&e(`div`,{role:`status`,"data-testid":`integrations-reconnecting`,className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground-subtle`,children:[i(f,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),t(`integrations.reconnecting`,`An integration is restarting. The list will refresh on its own.`)]}),$&&i(`div`,{className:`space-y-2`,"data-testid":`integrations-pending`,children:[1,2,3].map(e=>i(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!$&&!Ke&&!Je&&e(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[i(`p`,{className:`text-sm`,children:t(`integrations.noIntegrationsConfigured`,`No integrations configured.`)}),i(`p`,{className:`text-xs mt-1`,children:t(`integrations.clickNewIntegrationToConnect`,`Click "New Integration" to connect cameras and devices.`)})]}),!Q&&!$&&Je&&m===`table`&&e(`div`,{className:`space-y-4`,children:[G.providers.length>0&&i(Z,{kind:`providers`,children:Be(G.providers)}),G.system.length>0&&i(Z,{kind:`system`,children:Be(G.system)})]}),!Q&&!$&&Je&&m===`grid`&&i(qe,{providers:K.providers,system:K.system,onOpen:q,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),i(xt,{open:g,onClose:E,seed:b}),i(st,{open:ee,onClose:re,onSetupIntegration:D})]})}export{kt as IntegrationsPage};
@@ -1,2 +0,0 @@
1
- import{C as e,K as t,S as n,V as r,Y as i,et as a,o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{In as c,Un as l,_r as u,ai as d,ot as f,xn as p}from"./player-overlays-D5PuUVGx.js";import{hi as m,in as ee}from"./client-DDfmis6s.js";import{D as h,N as g,O as _,v}from"./__vite-browser-external-BCAtXlNQ.js";import{y}from"./video-y3iyn_B3.js";import{$i as b,Br as te,Bt as ne,Ei as re,Fr as ie,Ht as x,Ir as S,Pr as C,Vt as w,ca as T,ho as E,sa as D,sf as O,vi as k,zr as A}from"./src-kgyauwxD.js";import{t as j}from"./i18n-C-ZuqT0u.js";import{t as M}from"./useTranslation-BJr-n0es.js";import{J as N,Lr as P,S as F,i as I}from"./index-tVCZ0Ciq.js";import{t as L}from"./AdminSectionedPage-ByDJLqaY.js";import{f as R,t as z}from"./InstancesTable-A0I2fC4x.js";import{n as B,t as ae}from"./IntegrationHub-C8tNL25o.js";a();function V(e){if(typeof e==`string`)return e;if(typeof e==`object`&&e){let t=e.name;if(typeof t==`string`)return t}return null}function H(e){let t=e,n=t?.manifest;if(n?.id===void 0)return null;let r=(n.capabilities??[]).map(V).filter(e=>e!==null);return{addonId:n.id,displayName:n.packageDisplayName??n.name??n.id,capNames:r,processState:t?.process?.state??null}}function U(e,t){return Object.entries(e).filter(([,e])=>e===t).map(([e])=>e)}function W(e,t){return t.find(t=>e.capNames.includes(t))??null}function G(e){switch(e){case`running`:return{state:`ok`,label:j.t(`helpers.connectivityModel.running`)};case`crashed`:case`failed`:return{state:`error`,label:e};case`stopped`:case`disabled`:return{state:`off`,label:j.t(`helpers.connectivityModel.stopped`)};default:return{state:`unknown`,label:e??j.t(`common.unknownWord`)}}}var K=1e4;function q({row:t}){let{t:r}=M(),[a,o]=i(!1),c=t.kind===`instance`?t.id:void 0,{data:l}=E({addonId:t.addonId,...c===void 0?{}:{instanceId:c}},{refetchInterval:K,retry:!1}),u=m.safeParse(l);if(!u.success||t.kind===`instance`&&!t.enabled)return null;let d=u.data.exposedDeviceCount;return e(s,{children:[n(k,{variant:`ghost`,size:`sm`,type:`button`,onClick:()=>o(!0),children:r(`system.connectivity.devicesExported`,`{{count}} devices exported`,{count:d})}),a&&n(C,{open:!0,onOpenChange:o,children:e(S,{width:`full`,scroll:`body`,children:[n(A,{children:n(te,{children:r(`system.connectivity.devicesDialogTitle`,`Devices of {{name}}`,{name:t.name})})}),n(ie,{children:c===void 0?n(w,{addonId:t.addonId,showSetup:!1}):n(ne,{addonId:t.addonId,instance:{instanceId:c,name:t.name,enabled:!0},showSetup:!1})})]})})]})}function J(e){return{key:`devices`,header:e(`system.connectivity.devicesColumn`,`Devices`),notSortableReason:e(`system.connectivity.devicesNotSortable`,`A button that opens the list is not a value to order by.`),render:e=>n(q,{row:e})}}function oe({addonId:e,instanceId:t}){return n(x,{addonId:e,instanceId:t})}var Y=`waste-collections`,X=_({refreshed:v(_({sourceId:g(),entryCount:h().int(),error:g().optional()}))});function se({row:e}){let{t}=M(),r=f(),i=o(),a=b({onSuccess:async n=>{let a=X.safeParse(n),o=a.success?a.data.refreshed[0]:void 0;if(i.invalidateQueries({queryKey:[N]}),o===void 0){await r({title:t(`wasteFetchNow.nothingFetched`,`Nothing to fetch`),message:t(`wasteFetchNow.sourceIsOff`,`{{name}} is switched off, so it was not fetched.`,{name:e.name})});return}await r({title:o.error===void 0?t(`wasteFetchNow.fetched`,`{{name}} fetched`,{name:e.name}):t(`wasteFetchNow.failed`,`{{name}} could not be fetched`,{name:e.name}),message:o.error??t(`wasteFetchNow.collections`,`{{count}} collections read.`,{count:o.entryCount}),variant:o.error===void 0?`default`:`danger`})},onError:async n=>{await r({title:t(`wasteFetchNow.failed`,`{{name}} could not be fetched`,{name:e.name}),message:n.message,variant:`danger`})}});return n(O,{icon:d,variant:`ghost`,size:`sm`,"aria-label":t(`wasteFetchNow.label`,`Fetch {{name}} now`,{name:e.name}),disabled:a.isPending,onClick:()=>a.mutate({addonId:Y,action:`fetchNow`,input:{sourceId:e.id}})})}function ce(e){return e.addonId===Y?n(se,{row:e}):null}function le(){let{t}=M(),r=f(),i=o(),a=b({onSuccess:async e=>{let n=X.safeParse(e);i.invalidateQueries({queryKey:[N]});let a=n.success?n.data.refreshed:[],o=a.filter(e=>e.error!==void 0);await r({title:o.length===0?t(`wasteFetchNow.allFetched`,`Calendars fetched`):t(`wasteFetchNow.allFailed`,`{{count}} calendars could not be fetched`,{count:o.length}),message:o.length===0?t(`wasteFetchNow.allCollections`,`{{count}} sources refreshed.`,{count:a.length}):o.map(e=>`${e.sourceId}: ${e.error}`).join(`
2
- `),variant:o.length===0?`default`:`danger`})},onError:async e=>{await r({title:t(`wasteFetchNow.allNotFetched`,`The calendars could not be fetched`),message:e.message,variant:`danger`})}});return e(k,{size:`sm`,variant:`secondary`,disabled:a.isPending,onClick:()=>a.mutate({addonId:Y,action:`fetchNow`,input:{}}),children:[n(d,{className:`h-3.5 w-3.5`}),t(`wasteFetchNow.all`,`Fetch all now`)]})}function ue(e){return e.some(e=>e.addonId===Y)?n(le,{}):null}a();var Z=1e4,Q={"device-export":`exporters`,exporters:`exporters`,email:`email`,broker:`brokers`,brokers:`brokers`,"message-brokers":`brokers`,calendar:`calendars`,calendars:`calendars`,"calendar-source":`calendars`},de=[{sectionId:`exporters`,kind:`device-export`,labelKey:`system.connectivity.exporters`,icon:p,installLabelKey:`system.connectivity.exportersInstall`,emptyTitleKey:`system.connectivity.exportersEmptyTitle`,emptyDescriptionKey:`system.connectivity.exportersEmptyDescription`,instances:{functionCap:`device-export`,subtitleKey:`system.connectivity.exportersSubtitle`,subtitleDefault:`The ecosystems and hubs this hub publishes its devices to.`,addLabelKey:`system.connectivity.exportersAdd`,addLabelDefault:`Add export`,extraColumns:e=>[J(e)],lead:e=>n(oe,{addonId:e.addonId,instanceId:e.id})}},{sectionId:`email`,kind:`email`,labelKey:`system.connectivity.email`,icon:u,installLabelKey:`system.connectivity.emailInstall`,emptyTitleKey:`system.connectivity.emailEmptyTitle`,emptyDescriptionKey:`system.connectivity.emailEmptyDescription`,instances:{functionCap:`smtp-provider`,subtitleKey:`system.connectivity.emailSubtitle`,subtitleDefault:`The SMTP relays that notification targets send mail through.`,addLabelKey:`system.connectivity.emailAdd`,addLabelDefault:`Add relay`}},{sectionId:`brokers`,kind:`broker`,labelKey:`system.connectivity.brokers`,icon:c,installLabelKey:`system.connectivity.brokersInstall`,emptyTitleKey:`system.connectivity.brokersEmptyTitle`,emptyDescriptionKey:`system.connectivity.brokersEmptyDescription`,instances:{functionCap:`broker`,subtitleKey:`system.connectivity.brokersSubtitle`,subtitleDefault:`The accounts and connections this hub reaches its devices through.`,addLabelKey:`system.connectivity.brokersAdd`,addLabelDefault:`Add connection`}},{sectionId:`calendars`,kind:`calendar`,labelKey:`system.connectivity.calendars`,icon:y,installLabelKey:`system.connectivity.calendarsInstall`,emptyTitleKey:`system.connectivity.calendarsEmptyTitle`,emptyDescriptionKey:`system.connectivity.calendarsEmptyDescription`,instances:{functionCap:`calendar-source`,subtitleKey:`system.connectivity.calendarsSubtitle`,subtitleDefault:`The calendars this hub reads events from.`,addLabelKey:`system.connectivity.calendarsAdd`,addLabelDefault:`Add calendar`,keepProviderPills:!0,rowActions:ce,pageActions:ue}}];function fe(e,t,r){let i=U(ee,e.kind),a=t.flatMap(t=>{let r=W(t,i);if(r===null)return[];let a=G(t.processState);return[{id:t.addonId,name:t.displayName,fallbackIcon:e.icon,state:a.state,stateLabel:a.label,render:()=>n(B,{addonId:t.addonId,displayName:t.displayName,capName:r,isActive:t.processState===`running`,badges:n(s,{children:n(ge,{processState:t.processState})})})}]});return{id:e.sectionId,label:r(e.labelKey),entries:a,install:{capability:i[0]??e.kind,label:r(e.installLabelKey)}}}function pe(){let e=T({capName:`integration-instances`},{refetchInterval:Z});return t(()=>e.data===void 0?null:new Set(e.data.map(e=>e.addonId)),[e.data])}function me({descriptor:r,instances:i,rows:a,isLoading:o}){let c=pe(),l=t(()=>c===null?[]:a.filter(e=>!c.has(e.addonId)),[c,a]);return e(s,{children:[i,l.length>0&&n($,{descriptor:r,rows:l,isLoading:o})]})}function $({descriptor:e,rows:r,isLoading:i}){let{t:a}=M(),o=t(()=>fe(e,r,a),[e,r,a]);return n(ae,{embedded:!0,icon:e.icon,title:a(e.labelKey),subtitle:null,groups:[o],isLoading:i,emptyTitle:a(e.emptyTitleKey),emptyDescription:a(e.emptyDescriptionKey)})}function he(){let{t:e}=M(),i=D(void 0,{refetchInterval:Z}),[a,o]=P(),s=F(`/system/integrations`,{t:e,isAdmin:!0})??{icon:l,title:e(`admin.system.integrations.connectivity`,`Connectivity`)};r(()=>{let e=a.get(`tab`);if(e===null)return;let t=Q[e];t===void 0||t===e||o(e=>{let n=new URLSearchParams(e);return n.set(`tab`,t),n},{replace:!0})},[a,o]);let c=t(()=>(i.data??[]).map(H).filter(e=>e!==null),[i.data]),u=t(()=>de.map(t=>{let r=t.instances,a=r===void 0?null:n(z,{functionCap:r.functionCap,icon:t.icon,title:e(t.labelKey),subtitle:e(r.subtitleKey,r.subtitleDefault),emptyTitle:e(t.emptyTitleKey),emptyDescription:e(t.emptyDescriptionKey),addLabel:e(r.addLabelKey,r.addLabelDefault),...r.extraColumns===void 0?{}:{extraColumns:r.extraColumns(e)},...r.lead===void 0?{}:{lead:r.lead},...r.rowActions===void 0?{}:{rowActions:r.rowActions},...r.pageActions===void 0?{}:{pageActions:r.pageActions}}),o=n($,{descriptor:t,rows:c,isLoading:i.isLoading});return{id:t.sectionId,label:e(t.labelKey),ownedParams:I,content:a===null?o:r?.keepProviderPills===!0?n(me,{descriptor:t,instances:a,rows:c,isLoading:i.isLoading}):a}}),[i.isLoading,c,e]);return n(L,{icon:s.icon,title:s.title,subtitle:e(`admin.system.integrations.externalSystemsThisHubTalks`,`External systems this hub talks to — exporters, email, brokers and calendar sources.`),defaultSection:`exporters`,sectionsLabel:`Connectivity sections`,sections:u})}function ge({processState:e}){let{state:t,label:r}=G(e);return n(re,{variant:t===`ok`?`success`:t===`error`?`danger`:`default`,className:`${R} capitalize`,children:r})}export{he as IntegrationsPage};
@@ -1,3 +0,0 @@
1
- import{C as e,K as t,S as n,V as r,Y as i,et as a,o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$i as c,$t as l,Di as u,Fn as d,Hi as f,Ii as p,Jt as m,Kt as h,O as g,Pi as _,Qr as v,St as y,Tn as b,Tr as x,V as S,Wn as C,Xn as w,Yi as T,Yr as E,Yt as D,bn as O,bt as k,ct as A,dn as j,ga as ee,gr as te,ha as M,hi as N,ii as P,jr as F,k as I,kn as L,ma as R,mn as ne,oa as z,qi as re,ri as ie,ut as B,vr as ae,wr as oe,yt as se,z as ce}from"./player-overlays-D5PuUVGx.js";import{io as le,no as ue,xn as de}from"./client-DDfmis6s.js";import{t as fe}from"./boxes-BMGVI06T.js";import{n as pe,t as V}from"./speaker-BlIjlZin.js";import{t as me}from"./user-round-D18UTvSy.js";import{Br as he,Ei as H,Fr as U,Ir as ge,Ko as _e,Mt as ve,On as ye,Pr as be,Qo as xe,Rn as W,Rr as Se,X as Ce,Xo as we,Zo as Te,_o as Ee,as as De,cf as Oe,cr as ke,cs as Ae,ds as je,es as Me,fs as Ne,go as Pe,ii as Fe,kn as Ie,lr as Le,ms as Re,ni as G,of as K,oi as ze,os as Be,ps as Ve,ri as He,sf as Ue,ss as We,ui as Ge,ur as Ke,vi as q,vo as qe,xi as Je,xo as Ye,ys as Xe,zr as Ze}from"./src-kgyauwxD.js";import{t as J}from"./i18n-C-ZuqT0u.js";import{t as Y}from"./useTranslation-BJr-n0es.js";import{Fr as Qe,Lr as $e,Mr as X,m as et}from"./index-tVCZ0Ciq.js";import{t as tt}from"./AdminSectionedPage-ByDJLqaY.js";import{a as nt,n as rt,r as it}from"./linked-devices-model-CAQzz1C5.js";a();function Z(e){return{id:e.id,name:e.name,type:e.type,stableId:e.stableId??``,parentDeviceId:e.parentDeviceId,location:e.location,...e.role!==void 0&&e.role!==null?{role:e.role}:{},...e.primaryChildEntityId!==void 0&&e.primaryChildEntityId!==null?{primaryChildEntityId:e.primaryChildEntityId}:{}}}function Q(e){if(e==null)return null;let t=e.trim();return t.length===0?null:t.toLowerCase()}function at(e,t){let n=Q(t);return n===null?[]:e.filter(e=>Q(e.location)===n)}function ot(e,t){let n=at(e,t),r=new Set(n.map(e=>e.id));return n.filter(e=>e.parentDeviceId===null||!r.has(e.parentDeviceId))}function st(e,t){let n=Q(e.location);return n===null||new Set(t.map(e=>Q(e))).has(n)?null:e.location?.trim()??null}function ct(e,t){let n=Q(e.location);return n!==null&&t.has(n)}function lt(e,t){let n=new Set(t.map(e=>Q(e))),r=new Set(e.filter(e=>ct(e,n)).map(e=>e.id));return e.filter(e=>!(ct(e,n)||e.parentDeviceId!==null&&r.has(e.parentDeviceId)))}function ut(e,t){return lt(e,t).filter(e=>e.parentDeviceId===null)}function dt(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 ft(e,t){return dt(e,t).length}function pt(e,t){return e.filter(e=>!e.isCamera&&e.parentDeviceId===t)}function mt(e,t){return t.map(t=>({name:t,members:ot(e,t)}))}var ht={camera:f,hub:L,container:fe,light:x,siren:ne,switch:D,sensor:ee,thermostat:l,climate:M,button:u,"event-emitter":se,update:pe,notifier:c,script:b,automation:y,lock:ae,cover:T,valve:P,humidifier:ie,"water-heater":E,fan:v,"media-player":V,"alarm-panel":O,control:j,presence:me,weather:N,vacuum:re,"lawn-mower":m,image:F,smoke:R};function $({type:e,className:t}){return n(ht[e]??u,{"aria-hidden":`true`,className:t??`h-3.5 w-3.5 shrink-0 text-foreground-subtle`})}function gt({device:e}){let t=Fe(Z(e),`compact`);return n(_t,{online:e.online,deviceName:t})}function _t({online:e,deviceName:t}){return n(`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":J.t(`locations.deviceGlyphs.aria`,{name:t,state:e?J.t(`common.online`):J.t(`common.offline`)}),title:e?J.t(`common.online`):J.t(`common.offline`)})}function vt({open:t,title:a,items:o,listState:s,lockedIds:c,lockedNote:l,suggestions:u=null,busy:d=!1,onConfirm:f,onClose:p}){let{t:m}=Y(),[h,g]=i([]);r(()=>{t||g([])},[t]);let _=new Map(o.map(e=>[e.id,e.name])),v=(u?.ids??[]).filter(e=>_.has(e)&&!c.includes(e)),y=e=>g(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]);return n(be,{open:t,onOpenChange:e=>e?void 0:p(),children:e(ge,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":a,children:[n(Ze,{children:n(he,{children:a})}),e(U,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:[t&&u!==null&&v.length>0&&e(`section`,{"aria-label":u.heading,className:`flex flex-col gap-1`,children:[n(`h3`,{className:`text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:u.heading}),n(`div`,{className:`flex flex-wrap gap-1`,children:v.map(e=>n(`button`,{type:`button`,"aria-pressed":h.includes(e),className:`inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${h.includes(e)?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:bg-surface-hover`}`,onClick:()=>y(e),children:_.get(e)},e))})]}),t&&n(Ce,{devices:o,listState:s,value:h,onChange:e=>g(e),noun:`device`,emptyLabel:m(`locations.addDialog.nonePicked`),showAll:!0,lockedIds:c,lockedNote:l,testId:`quick-add-picker`})]}),e(Se,{children:[n(q,{variant:`ghost`,onClick:p,children:m(`locations.addDialog.cancel`)}),n(q,{disabled:h.length===0||d,onClick:()=>f(h),children:m(`locations.addDialog.confirm`,{count:h.length})})]})]})})}a();function yt({room:e,cameras:r,fleet:i}){let{t:a}=Y(),o=t(()=>new Map(i.map(e=>[e.id,e])),[i]);return e===null?n(`p`,{className:`text-xs text-foreground-subtle`,children:a(`locations.links.noRoom`)}):n(`div`,{className:`flex flex-col gap-3`,"data-testid":`camera-links-section`,children:r.length===0?n(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`camera-links-empty`,children:a(`locations.links.noCameras`,{room:e})}):r.map(e=>n(xt,{camera:e,byId:o},e.id))})}function bt(e){return{id:e.deviceId,name:e.name,type:e.type,location:e.location}}function xt({camera:t,byId:r}){let{t:a}=Y(),s=Fe(Z(t),`full`),c=o(),l=Qe(),[u,d]=i(!1),[f,p]=i(null),m=Ee({deviceId:t.id}),h=it({status:m.status,data:m.data,error:m.error===null||m.error===void 0?null:m.error}),_=qe(),v=h.kind===`present`?h:null,y=Pe({deviceId:t.id,slotRef:v?.slot.slotRef??``},{enabled:u&&v!==null}),b=v===null?[]:rt(v.slot,v.value),x=b.map(e=>e.deviceId),S=(y.data?.candidates??[]).map(bt),C=new Set(S.map(e=>e.id)),w=x.filter(e=>!C.has(e)).map(e=>{let t=r.get(e);return{id:e,name:t?.name??`#${String(e)}`,...t===void 0?{}:{type:t.type,location:t.location}}}),T=[...S,...w],E=(y.data?.candidates??[]).filter(e=>e.suggested).map(e=>e.deviceId),D=async e=>{if(v!==null){p(null);try{await _.mutateAsync({deviceId:t.id,slotRef:v.slot.slotRef,value:nt(v.value,e)}),await m.refetch(),await c.invalidateQueries({queryKey:[[`deviceManager`]]}),d(!1)}catch(e){p(e instanceof Error?e.message:String(e))}}},O=[{key:`device`,header:a(`locations.columns.device`),notSortableReason:a(`locations.columns.noSort`),render:t=>{let i=r.get(t.deviceId),o=t.name??i?.name??`#${String(t.deviceId)}`;return e(`span`,{className:`flex items-center gap-1.5`,children:[i!==void 0&&n($,{type:i.type}),n(X,{to:`/devices/${String(t.deviceId)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:i===void 0?o:n(G,{device:Z(i),form:`compact`})}),t.implied&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:a(`locations.links.implied`)})]})}},{key:`type`,header:a(`locations.columns.type`),notSortableReason:a(`locations.columns.noSort`),render:e=>n(`span`,{className:`text-xs text-foreground-muted`,children:r.get(e.deviceId)?.type??`—`})},{key:`status`,header:a(`locations.columns.status`),notSortableReason:a(`locations.columns.noSort`),render:t=>{let i=r.get(t.deviceId);return i===void 0?n(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):e(`span`,{className:`flex items-center gap-1.5`,children:[n(gt,{device:i}),n(`span`,{className:`text-xs text-foreground-muted`,children:i.online?a(`common.online`):a(`common.offline`)})]})}}];return e(`section`,{className:`min-w-0 ${g}`,"data-testid":`camera-links-${String(t.id)}`,children:[e(`header`,{className:`${I} flex min-h-9 items-center gap-1.5`,children:[n($,{type:t.type}),n(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:n(G,{device:Z(t),form:`full`})}),e(q,{variant:`ghost`,size:`sm`,onClick:()=>l(et(t.id)),children:[n(oe,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),a(`locations.links.edit`)]}),n(q,{variant:`outline`,size:`sm`,disabled:v===null,onClick:()=>d(!0),"aria-label":a(`locations.links.addNamed`,{camera:s}),children:a(`locations.room.add`)})]}),h.kind===`pending`&&n(`p`,{role:`status`,className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:a(`locations.links.loading`)}),h.kind===`unknown`&&n(`p`,{role:`alert`,className:`px-3 py-3 text-xs text-warning sm:px-4`,children:a(`locations.links.unreadable`,{reason:h.reason})}),h.kind===`absent`&&n(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:a(`locations.links.unsupported`)}),f!==null&&n(`p`,{role:`alert`,className:`px-3 pt-2 text-xs text-danger break-words sm:px-4`,children:f}),v!==null&&(b.length===0?n(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:a(`locations.links.none`)}):n(W,{columns:O,rows:b,rowKey:e=>String(e.deviceId),bordered:!1,minWidthPx:360})),n(vt,{open:u,title:a(`locations.links.pickTitle`,{camera:s}),items:T,listState:y.status===`error`?`failed`:y.data===void 0?`pending`:`answered`,lockedIds:x,lockedNote:a(`locations.links.alreadyLinked`),suggestions:t.location===null?null:{heading:a(`locations.links.suggested`,{room:t.location}),ids:E},busy:_.isPending,onConfirm:e=>void D(e),onClose:()=>d(!1)})]})}a();function St({name:t,description:a,busy:o,onSave:s}){let{t:c}=Y(),[l,u]=i(a??``);return r(()=>{u(a??``)},[a]),e(`div`,{className:`border-t border-border px-3 py-2 sm:px-4`,children:[n(Ke,{htmlFor:`location-description-${t}`,className:`block`,children:c(`locations.locationDescriptionField.whatIsThere`,`What is there`)}),n(ke,{id:`location-description-${t}`,value:l,onChange:e=>u(e.target.value),onBlur:()=>{let e=l.trim();e!==(a??``)&&s(e.length===0?null:e)},disabled:o,rows:2,maxLength:400,placeholder:c(`locations.locationDescriptionField.surfacesBoundariesWhatIsNormally`,`Surfaces, boundaries, what is normally parked or stored here.`),className:`mt-1 w-full resize-y rounded-md border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-inset focus:ring-primary disabled:cursor-not-allowed disabled:opacity-50`}),n(`p`,{className:`mt-1 ${ce}`,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 Ct(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0||n.description.length===0?null:n.description}var wt=` none`;function Tt({name:t,zones:r,zoneKey:i,busy:a,onChange:o}){let{t:s}=Y();if(r.length===0)return null;let c=[{value:wt,label:s(`locations.locationZoneField.none`,`— none —`)},...r.map(e=>({value:e.zoneKey,label:e.label}))];return e(`div`,{className:`flex items-center gap-2 border-t border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:[n(Ke,{htmlFor:`location-zone-${t}`,children:s(`locations.locationZoneField.zone`,`Zone`)}),n(B,{id:`location-zone-${t}`,value:i??wt,disabled:a,onChange:e=>{let t=e.target.value;if(t===wt){o(null);return}let n=r.find(e=>e.zoneKey===t);n!==void 0&&o(n.label)},options:c})]})}function Et(e,t){return e.find(e=>e.locationKeys.includes(t))?.zoneKey??null}function Dt({name:e,icon:t,busy:r,onPick:i}){return n(Oe,{value:t,onPick:i,fallbackGlyph:te,clearGlyph:z,labels:{trigger:`Change the icon of ${e}`,panel:`Icon for ${e}`,searchPlaceholder:`Search icons`,clear:`No icon`,noMatches:`No icon matches that`},disabled:r})}function Ot(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0?null:le(n.icon)??`map-pin`}function kt(e){return`${e.kind}:${String(e.device.id)}`}function At(e,t,n){return e.flatMap(e=>{let r=pt(t,e.id),i=n.has(e.id),a={kind:`member`,device:e,accessories:r,open:i};return!i||r.length===0?[a]:[a,...r.map(t=>({kind:`accessory`,device:t,parent:e}))]})}a();function jt({name:r,members:a,devices:o,busy:c,icon:l,description:u,onRename:f,onDelete:p,onRebuildLinks:m,onAddDevices:_,onPickIcon:v,onSaveDescription:y,zones:b,zoneKey:x,onChangeZone:S}){let{t:C}=Y(),[T,E]=i(!1),[D,O]=i(r),A=ye(a,t(()=>({searchText:e=>[e.name,...pt(o,e.id).map(e=>e.name)],facetValue:e=>e.type}),[o])),[j,ee]=i(()=>new Set),te=e=>ee(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),M=t(()=>At(A.rows,o,j),[A.rows,o,j]),N=[{key:`name`,header:C(`locations.columns.device`),notSortableReason:C(`locations.columns.noSort`),render:e=>e.kind===`member`?n(Mt,{row:e,onToggle:()=>te(e.device.id)}):n(Nt,{row:e})},{key:`type`,header:C(`locations.columns.type`),notSortableReason:C(`locations.columns.noSort`),render:e=>n(`span`,{className:`text-xs text-foreground-muted`,children:e.device.type})},{key:`status`,header:C(`locations.columns.status`),notSortableReason:C(`locations.columns.noSort`),render:t=>e(`span`,{className:`flex items-center gap-1.5`,children:[n(gt,{device:t.device}),n(`span`,{className:`text-xs text-foreground-muted`,children:t.device.online?C(`common.online`):C(`common.offline`)})]})}],P=()=>{O(r),E(!1)},F=async()=>{let e=D.trim();if(e.length===0||e===r){P();return}await f(e),E(!1)},L=[{id:`rename`,label:C(`locations.locationCard.rename`,`Rename`),icon:w,disabled:c,onClick:()=>{O(r),E(!0)}},{id:`rebuild-links`,label:C(`locations.locationCard.rebuildLinkedDevices`,`Rebuild linked devices`),icon:d,separatorBefore:!0,disabled:c,onClick:()=>void m()},{id:`delete`,label:C(`common.delete`,`Delete`),icon:h,danger:!0,separatorBefore:!0,disabled:c,onClick:()=>void p()}];return e(`section`,{className:`min-w-0 ${g}`,children:[e(`header`,{className:`${I} flex min-h-9 items-center gap-1.5`,children:[n(Dt,{name:r,icon:l,busy:c,onPick:v}),T?e(s,{children:[n(K,{value:D,onChange:e=>O(e.target.value),onKeyDown:e=>{e.key===`Enter`&&F(),e.key===`Escape`&&P()},"aria-label":C(`locations.locationCard.rename2`,`Rename {{name}}`,{name:r}),className:`min-w-0 flex-1`,autoFocus:!0}),n(q,{type:`button`,size:`sm`,onClick:()=>void F(),children:C(`common.save`,`Save`)}),n(Ue,{type:`button`,variant:`ghost`,icon:k,onClick:P,"aria-label":C(`locations.locationCard.cancelRename`,`Cancel rename`)})]}):e(s,{children:[n(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:r}),n(q,{type:`button`,variant:`outline`,size:`sm`,disabled:c,onClick:_,"aria-label":C(`locations.room.addTo`,{room:r}),children:C(`locations.room.add`)}),n(ve,{items:L,title:C(`locations.locationCard.actionsFor`,`Actions for {{name}}`,{name:r}),triggerClassName:`p-1`})]})]}),n(Tt,{name:r,zones:b,zoneKey:x,busy:c,onChange:S}),n(St,{name:r,description:u,busy:c,onSave:y}),a.length>0&&n(`div`,{className:`border-b border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:n(Ie,{state:A.state,facets:A.facets,labels:{searchPlaceholder:C(`locations.filter.searchPlaceholder`),searchLabel:C(`locations.room.searchLabel`,{room:r}),facetsLabel:C(`locations.filter.typesLabel`),clearLabel:C(`locations.filter.clear`)},onSearch:A.setSearch,onToggleFacet:A.toggleFacet,onClear:A.clear})}),a.length===0?n(`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.`)}):n(W,{columns:N,rows:M,rowKey:kt,bordered:!1,minWidthPx:360,emptyMessage:C(`locations.filter.noMatch`)})]})}function Mt({row:t,onToggle:r}){let{t:i}=Y(),{device:a,accessories:o,open:s}=t,c=Fe(Z(a),`compact`),l=s?p:_;return e(`span`,{className:`flex items-center gap-1.5`,children:[o.length>0?e(q,{type:`button`,variant:`ghost`,onClick:r,"aria-expanded":s,"aria-label":i(s?`locations.locationCard.collapseAccessories`:`locations.locationCard.expandAccessories`,{count:o.length,name:c}),className:`h-auto shrink-0 gap-0.5 p-0.5 text-foreground-subtle hover:text-foreground`,children:[n(l,{className:`h-3 w-3`}),n(`span`,{className:`text-[10px] tabular-nums`,children:o.length})]}):n(`span`,{"aria-hidden":`true`,className:`w-[1.35rem] shrink-0`}),n($,{type:a.type}),n(X,{to:`/devices/${String(a.id)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:n(G,{device:Z(a),form:`compact`})})]})}function Nt({row:t}){let{device:r,parent:i}=t;return e(`span`,{className:`flex items-center gap-1.5 pl-6`,children:[n(`span`,{"aria-hidden":`true`,className:`text-[10px] text-foreground-subtle`,children:`└`}),n($,{type:r.type,className:`h-3 w-3 shrink-0 text-foreground-subtle`}),n(X,{to:`/devices/${String(r.id)}`,className:`min-w-0 truncate text-xs text-foreground-muted hover:underline`,children:n(G,{device:Z(r),form:`nested`,parent:Z(i)})})]})}a();function Pt({zones:e,busy:t,onRename:r,onDelete:a,onPickIcon:o}){let{t:s}=Y(),[c,l]=i(null),[u,d]=i(``),f=async e=>{let t=u.trim();l(null),!(t.length===0||t===e)&&await r(e,t)};return n(W,{columns:[{key:`icon`,header:s(`locations.siteZonesPanel.icon`,`Icon`),width:`w-12`,notSortableReason:`An icon has no order`,render:e=>n(Dt,{name:e.label,icon:e.icon,busy:t,onPick:t=>o(e.label,t)})},{key:`name`,header:s(`locations.siteZonesPanel.zone`,`Zone`),sortValue:e=>e.label.toLowerCase(),render:e=>c===e.label?n(K,{value:u,onChange:e=>d(e.target.value),onKeyDown:t=>{t.key===`Enter`&&f(e.label),t.key===`Escape`&&l(null)},onBlur:()=>void f(e.label),"aria-label":s(`locations.siteZonesPanel.rename`,`Rename {{label}}`,{label:e.label}),autoFocus:!0}):n(q,{type:`button`,variant:`ghost`,size:`sm`,className:`px-0`,onClick:()=>{d(e.label),l(e.label)},disabled:t,title:s(`locations.siteZonesPanel.renameTheZone`,`Rename the zone`),children:e.label})},{key:`rooms`,header:s(`locations.siteZonesPanel.rooms`,`Rooms`),align:`right`,sortValue:e=>e.locationKeys.length,render:e=>n(`span`,{className:`tabular-nums text-foreground-subtle`,children:e.locationKeys.length===0?s(`common.empty`):s(`common.rooms`,{count:e.locationKeys.length})})},{key:`actions`,header:s(`locations.siteZonesPanel.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order`,render:e=>n(q,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void a(e.label),disabled:t,"aria-label":s(`locations.siteZonesPanel.delete`,`Delete {{label}}`,{label:e.label}),title:s(`locations.siteZonesPanel.deleteTheZoneTheRooms`,`Delete the zone — the rooms in it are kept`),children:n(h,{className:`h-3.5 w-3.5`})})}],rows:e,rowKey:e=>e.zoneKey,emptyMessage:s(`locations.siteZonesPanel.noZonesYetAZone`,`No zones yet. A zone groups rooms — “Night zone” for the bedrooms — and shows up before them in the app’s camera filter.`)})}a();function Ft({busy:t,onCreate:r}){let{t:a}=Y(),[o,s]=i(!1),[c,l]=i(``),u=()=>{l(``),s(!1)},d=async()=>{let e=c.trim();e.length!==0&&(await r(e),u())};return o?e(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),d()},children:[n(K,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&u()},placeholder:a(`locations.newLocationButton.frontDoorHallKitchen`,`Front door, Hall, Kitchen…`),"aria-label":a(`locations.newLocationButton.newLocationName`,`New location name`),className:`min-w-[12rem] flex-1`,autoFocus:!0}),e(q,{size:`sm`,type:`submit`,disabled:c.trim().length===0||t,children:[n(C,{className:`h-3.5 w-3.5`}),a(`common.add`,`Add`)]}),n(q,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":a(`locations.newLocationButton.cancelNewLocation`,`Cancel new location`),children:n(k,{className:`h-3.5 w-3.5`})})]}):e(q,{size:`sm`,type:`button`,onClick:()=>s(!0),"data-testid":`new-location-button`,children:[n(C,{className:`h-3.5 w-3.5`}),a(`locations.newLocationButton.newLocation`,`New location`)]})}a();function It({busy:t,onCreate:r}){let{t:a}=Y(),[o,s]=i(!1),[c,l]=i(``),u=()=>{l(``),s(!1)},d=async()=>{let e=c.trim();e.length!==0&&(await r(e),u())};return o?e(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),d()},children:[n(K,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&u()},placeholder:a(`locations.newZoneButton.zonaGiornoZonaNotte`,`Zona giorno, Night zone…`),"aria-label":a(`locations.newZoneButton.newZoneName`,`New zone name`),className:`min-w-[12rem] flex-1`,autoFocus:!0}),e(q,{size:`sm`,type:`submit`,disabled:c.trim().length===0||t,children:[n(C,{className:`h-3.5 w-3.5`}),a(`common.add`,`Add`)]}),n(q,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":a(`locations.newZoneButton.cancelNewZone`,`Cancel new zone`),children:n(k,{className:`h-3.5 w-3.5`})})]}):e(q,{size:`sm`,type:`button`,onClick:()=>s(!0),"data-testid":`new-zone-button`,children:[n(C,{className:`h-3.5 w-3.5`}),a(`locations.newZoneButton.newZone`,`New zone`)]})}a();function Lt(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 Rt({rooms:e,unassignedCount:r,value:i,unassignedValue:a,onChange:o}){let{t:s}=Y(),c=t(()=>Lt(e,r,a,s(`locations.roomPicker.unassigned`)),[e,r,a,s]);return n(`div`,{className:`max-w-sm`,"data-testid":`room-select`,children:n(Je,{mode:`single`,singleDisplay:`field`,label:s(`locations.roomPicker.label`),placeholder:s(`locations.roomPicker.placeholder`),options:c,value:i,onChange:o,searchable:!0,testId:`room-select-control`,optionTestIdPrefix:`room-option`})})}a();var zt={searchText:e=>[e.name],facetValue:e=>e.type};function Bt({rows:r,fleet:a,locations:o,busy:s,emptyMessage:c,onAssign:l}){let{t:u}=Y(),d=Ge(),f=ze(),p=e=>d===null?e.name:He(Z(e),`compact`,d,f),[m,h]=i([]),[g,_]=i(``),v=ye(r,zt),y=v.rows,b=t(()=>y.map(e=>e.id),[y]),x=t(()=>m.filter(e=>b.includes(e)),[m,b]),C=y.length>0&&x.length===y.length,w=t(()=>{let e=new Map;for(let t of r)e.set(t.id,ft(a,t.id));return e},[r,a]),T=x.reduce((e,t)=>e+(w.get(t)??0),0),E=e=>h(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),D=()=>h(C?[]:b),O=()=>{g.length===0||x.length===0||(l(x,g),h([]),_(``))},k=o.map(e=>({value:e,label:e})),A=[{key:`select`,width:`w-8`,headerRender:()=>n(Le,{checked:C,onChange:D,"aria-label":C?u(`locations.unassignedTable.clearSelection`,`Clear selection`):u(`locations.unassignedTable.selectAllUnassignedDevices`,`Select all unassigned devices`)}),render:e=>n(Le,{checked:x.includes(e.id),onChange:()=>E(e.id),"aria-label":u(`locations.unassignedTable.select`,`Select {{name}}`,{name:p(e)})})},{key:`name`,header:u(`locations.unassignedTable.device`,`Device`),sortValue:e=>e.name.toLowerCase(),render:t=>{let r=st(t,o);return e(`span`,{className:`flex items-center gap-1.5`,children:[n($,{type:t.type}),n(X,{to:`/devices/${String(t.id)}`,className:`truncate text-xs text-foreground hover:underline`,children:n(G,{device:Z(t),form:`compact`})}),r!==null&&n(H,{variant:`warning`,children:u(`locations.unassignedTable.unknownRoom`,{room:r})})]})}},{key:`type`,header:u(`locations.unassignedTable.type`,`Type`),sortValue:e=>e.type,render:e=>n(`span`,{className:`text-xs text-foreground-muted`,children:e.type})},{key:`status`,header:u(`locations.unassignedTable.status`,`Status`),sortValue:e=>+!!e.online,render:t=>e(`span`,{className:`flex items-center gap-1.5`,children:[n(gt,{device:t}),n(`span`,{className:`text-xs text-foreground-muted`,children:t.online?u(`common.online`):u(`common.offline`)})]})},{key:`followers`,header:u(`locations.unassignedTable.accessoriesInTowCount`,`Accessories in tow`),align:`right`,sortValue:e=>w.get(e.id)??0,render:e=>n(`span`,{className:`tabular-nums text-xs text-foreground-muted`,children:w.get(e.id)??0})},{key:`assign`,header:u(`locations.unassignedTable.assignTo`,`Assign to`),align:`right`,notSortableReason:`This column is a control, not a value.`,render:e=>n(B,{"aria-label":u(`locations.unassignedTable.locationFor`,`Location for {{name}}`,{name:p(e)}),value:``,disabled:s||o.length===0,onChange:t=>{let n=t.target.value;n.length!==0&&l([e.id],n)},className:`max-w-[11rem]`,options:[{value:``,label:`—`},...k]})}];return e(`section`,{className:`space-y-2`,children:[e(`header`,{className:`flex flex-wrap items-baseline gap-2`,children:[n(`h2`,{className:S,children:u(`locations.unassignedTable.notInARoom`,`Not in a room`)}),n(`p`,{className:ce,children:u(`locations.unassignedTable.topLevelDevicesOnlyAccessories`,`Top-level devices only — accessories move with their parent.`)})]}),r.length>0&&n(Ie,{state:v.state,facets:v.facets,labels:{searchPlaceholder:u(`locations.filter.searchPlaceholder`),searchLabel:u(`locations.unassigned.searchLabel`),facetsLabel:u(`locations.filter.typesLabel`),clearLabel:u(`locations.filter.clear`)},onSearch:v.setSearch,onToggleFacet:v.toggleFacet,onClear:v.clear}),x.length>0&&e(`div`,{role:`group`,"aria-label":u(`locations.unassignedTable.bulkAssignment`,`Bulk assignment`),className:`flex flex-wrap items-center gap-2 rounded border border-primary/40 bg-primary/5 px-2 py-1.5`,children:[e(`span`,{className:`text-xs text-foreground`,children:[u(`locations.unassignedTable.selected`,{count:x.length}),T>0&&` · ${u(`locations.unassignedTable.accessoriesInTowCount`,{count:T})}`]}),n(B,{"aria-label":u(`locations.unassignedTable.assignSelectedDevicesTo`,`Assign selected devices to`),value:g,onChange:e=>_(e.target.value),className:`w-auto min-w-[10rem]`,options:[{value:``,label:u(`locations.unassignedTable.assignTo2`,`Assign to…`)},...k]}),n(q,{type:`button`,size:`sm`,onClick:O,disabled:s||g.length===0,children:u(`locations.unassignedTable.assign`,`Assign`)}),n(q,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>h([]),children:u(`locations.unassignedTable.clear`,`Clear`)})]}),n(W,{columns:A,rows:y,rowKey:e=>e.id,minWidthPx:720,emptyMessage:v.active?u(`locations.filter.noMatch`):c})]})}function Vt(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 Ht(e,t){let n=t.map(Vt),r=[];for(let i of t)i.isCamera&&i.location===e&&r.push({deviceId:i.id,name:i.name,ids:de({selfId:i.id,selfLocation:i.location,candidates:n})});return{entries:r}}var Ut=`device-manager:linked-devices`;function Wt(e){return{deviceId:e.deviceId,slotRef:Ut,value:{slot:`linked-devices`,deviceIds:[...e.ids]}}}a();var Gt=`__unassigned__`;function Kt(){let{t:r}=Y(),a=o(),s=A(),{data:c,isLoading:l}=xe(),{data:u}=Te(),{data:d}=we(),{data:f}=Me(),{data:p,isLoading:m}=_e({projection:`slim`}),h=()=>{a.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listLocationIcons`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listLocationDescriptions`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listSiteZones`]]})},g=Ye({onSuccess:h}),_=De({onSuccess:h}),v=je({onSuccess:h}),y=We({onSuccess:h}),b=Ve({onSuccess:h}),x=Ne({onSuccess:h}),S=Xe({onSuccess:h}),C=Be({onSuccess:h}),w=Ae({onSuccess:h}),T=Re({onSuccess:h}),E=qe(),D=t(()=>(p??[]).map(e=>({id:e.id,name:e.name,location:e.location??null,type:String(e.type),isCamera:e.isCamera,parentDeviceId:e.parentDeviceId,online:e.online,role:e.role??null,stableId:e.stableId,primaryChildEntityId:e.primaryChildEntityId??null})),[p]),O=c??[],k=t(()=>mt(D,O),[D,O]),[j,ee]=$e(),M=j.get(`tab`),N=M===`zones`||M===`camera-links`?M:`locations`,P=j.get(`room`),F=t(()=>ut(D,O),[D,O]),I=P===Gt,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,ne=I?Gt:L??`__unassigned__`,z=L??k[0]?.name??null,re=t(()=>k.map(e=>({name:e.name,count:e.members.length})),[k]),ie=e=>{ee(t=>{let n=new URLSearchParams(t);return n.set(`room`,e),n},{replace:!0})},B=l||m,ae=v.isPending||_.isPending||g.isPending||b.isPending,oe=async e=>{await g.mutateAsync({name:e})},se=async(e,t)=>{let n=t.trim();n.length===0||n===e||await y.mutateAsync({from:e,to:n})},ce=async e=>{let t=Ht(e,D);if(t.entries.length===0){await s({title:r(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:r(`locations.noCameraIsAssignedTo`,`No camera is assigned to “{{room}}”.`,{room:e}),confirmLabel:`OK`});return}let n=t.entries.map(e=>r(`locations.rebuildEntry`,{name:e.name,count:e.ids.length})).join(`
2
- `);if(!await s({title:r(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:r(`locations.replaceTheLinkedDeviceList`,`Replace the linked-device list of every camera in “{{room}}” with what the room contains? {{lines}} Anything linked by hand that is not in this room is lost.`,{room:e,lines:n}),confirmLabel:r(`locations.rebuild`,`Rebuild`),variant:`danger`}))return;let i=[];for(let e of t.entries)try{await E.mutateAsync(Wt(e))}catch(t){i.push(`• ${e.name}: ${t instanceof Error?t.message:String(t)}`)}h(),i.length>0&&await s({title:r(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:r(`locations.notRebuilt`,`Not rebuilt: {{value1}}`,{value1:i.join(`
3
- `)}),confirmLabel:`OK`})},le=async(e,t)=>{let n=t>0?` ${String(t)} device(s) will become unassigned.`:``;await s({title:r(`locations.deleteLocation`,`Delete location`),message:r(`locations.deleteTheLocation`,`Delete the location “{{name}}”?{{extra}}`,{name:e,extra:n}),confirmLabel:r(`common.delete`,`Delete`),variant:`danger`})&&await _.mutateAsync({name:e,cascade:!0})},de=async e=>{await s({title:r(`locations.deleteZone`,`Delete zone`),message:r(`locations.deleteTheZoneTheRooms`,`Delete the zone “{{name}}”? The rooms in it are kept.`,{name:e}),confirmLabel:r(`common.delete`,`Delete`),variant:`danger`})&&await C.mutateAsync({name:e})},fe=async(e,t)=>{await b.mutateAsync({location:e,icon:t})},pe=async(e,t)=>{await x.mutateAsync({location:e,description:t})},V=f??[],me=async(e,t)=>{await T.mutateAsync({location:e,zone:t})},he=(e,t)=>{for(let n of e)v.mutate({deviceId:n,location:t})},[H,U]=i(null),ge=t(()=>D.filter(e=>e.parentDeviceId===null).map(e=>({id:e.id,name:e.name,type:e.type,location:e.location})),[D]),ve=n(Rt,{rooms:re,...N===`locations`?{unassignedCount:F.length}:{},value:N===`locations`?ne:z??``,unassignedValue:Gt,onChange:ie}),ye=e(`div`,{className:`flex flex-col gap-3`,"data-testid":`locations-section`,children:[B&&n(`p`,{className:`text-xs text-foreground-subtle`,children:r(`locations.loadingLocationsAndDevices`,`Loading locations and devices…`)}),ve,I||R===null?n(Bt,{rows:F,fleet:D,locations:O,busy:ae,emptyMessage:B?r(`common.loading`,`Loading…`):r(`locations.everyTopLevelDeviceHas`,`Every top-level device has a room.`),onAssign:he}):n(jt,{name:R.name,members:R.members,devices:D,busy:ae,icon:Ot(u,ue(R.name)),onPickIcon:e=>fe(R.name,e),description:Ct(d,ue(R.name)),onSaveDescription:e=>pe(R.name,e),zones:V,zoneKey:Et(V,ue(R.name)),onChangeZone:e=>me(R.name,e),onRename:e=>se(R.name,e),onDelete:()=>le(R.name,at(D,R.name).length),onRebuildLinks:()=>ce(R.name),onAddDevices:()=>U(R.name)},R.name),O.length===0&&!B&&n(`p`,{className:`text-xs text-foreground-subtle`,children:r(`locations.noLocationsYetAddFrontDoor`,`No locations yet. Add Front door, Hall, Kitchen…`)}),n(vt,{open:H!==null,title:r(`locations.room.addDialogTitle`,{room:H??``}),items:ge,listState:m?`pending`:`answered`,lockedIds:H===null?[]:(k.find(e=>e.name===H)?.members??[]).map(e=>e.id),lockedNote:r(`locations.room.alreadyHere`),suggestions:{heading:r(`locations.room.suggestedUnassigned`),ids:F.map(e=>e.id)},busy:v.isPending,onConfirm:e=>{H!==null&&he(e,H),U(null)},onClose:()=>U(null)})]}),be=e(`div`,{className:`flex flex-col gap-3`,"data-testid":`camera-links-tab`,children:[ve,n(yt,{room:z,cameras:z===null?[]:at(D,z).filter(e=>e.isCamera),fleet:D})]});return n(tt,{icon:te,title:r(`locations.locations`,`Locations`),subtitle:r(`locations.roomsAndAreasOfThe`,`Rooms and areas of the site. Assign any device here — storage disks are under Data → Storage.`),defaultSection:`locations`,sectionsLabel:`Locations sections`,actions:N===`zones`?n(It,{busy:S.isPending,onCreate:e=>S.mutateAsync({name:e})}):n(Ft,{busy:g.isPending,onCreate:oe}),sections:[{id:`locations`,label:r(`locations.locations`,`Locations`),content:ye},{id:`camera-links`,label:r(`locations.cameraLinks`,`Camera links`),content:be},{id:`zones`,label:r(`locations.zones`,`Zones`),content:n(Pt,{zones:V,busy:ae,onRename:(e,t)=>w.mutateAsync({from:e,to:t}),onDelete:de,onPickIcon:(e,t)=>S.mutateAsync({name:e,icon:t})})}]})}export{Kt as LocationsPage};
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./browser-BHo8W_uH.js","./rolldown-runtime-Cyuzqnbw.js"])))=>i.map(i=>d[i]);
2
- import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{t}from"./vite-preload-helper-kNaey6uv.js";import{C as n,J as r,K as i,S as a,V as o,Y as s,a as c,et as l,t as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$r as f,Ai as p,Kt as m,Q as h,Sa as g,Ut as _,Xn as v,ct as y,fi as b,ht as x,ki as S,kr as C,oa as w,un as T,ut as E,vr as D,wr as O,xr as k,yn as A}from"./player-overlays-D5PuUVGx.js";import{$r as j,Qr as M}from"./client-DDfmis6s.js";import{c as N,f as ee}from"./video-y3iyn_B3.js";import{t as te}from"./monitor-smartphone-DXXBIJKP.js";import{t as ne}from"./unlink-B_JkAfPv.js";import{An as re,Mr as ie,Nr as ae,Pf as P,_c as oe,hc as se,of as F,pi as I,vi as L,zt as ce}from"./src-kgyauwxD.js";import{t as le}from"./i18n-C-ZuqT0u.js";import{t as R}from"./useTranslation-BJr-n0es.js";import"./mount-Gb8kSp8V.js";import{c as ue,i as de,l as z,s as B}from"./sso-popup-Dt_Vzh3t.js";import{I as V,Lr as H,Nr as U,jr as W,n as G}from"./index-tVCZ0Ciq.js";import{t as fe}from"./AdminSectionedPage-ByDJLqaY.js";import{t as pe}from"./AdminPage-CN1M6UZ4.js";import{D as me,O as he,_ as ge,a as _e,h as ve,r as ye,t as K,w as be}from"./SessionsList-CIy47IrP.js";l();var xe=`${M}/connect`,q={public:0,mesh:1,lan:2,"lan-ipv6":3};function Se(e){switch(e.kind){case`public`:return e.interfaceKind===`vpn`?`mesh`:`public`;case`lan-ipv4`:return`lan`;case`lan-ipv6`:return`lan-ipv6`;case`custom`:return`public`;case`loopback`:case`app-link`:return null}}function J(e){return j(e)}function Ce(e){return e.startsWith(`https://`)}function we(e){let t=e.flatMap(e=>{let t=Se(e),n=J(e.baseUrl);return t===null||n===null?[]:[{endpoint:e,tier:t,origin:n}]}).toSorted((e,t)=>q[e.tier]-q[t.tier]||Number(t.endpoint.plausible)-Number(e.endpoint.plausible)||e.endpoint.priority-t.endpoint.priority),n=new Set;return t.flatMap(({endpoint:e,tier:t,origin:r})=>n.has(r)?[]:(n.add(r),[{origin:r,label:e.label,tier:t,secure:Ce(r),plausible:e.plausible}]))}function Te(e,t,n=null){for(let r of[t,n]){if(r===null)continue;let t=J(r),n=e.find(e=>e.origin===t);if(n!==void 0)return n}return e[0]??null}function Ee(e){let t=new URL(xe);return t.searchParams.set(`hub`,e),t.toString()}var De=176,Y={scheme:`https`};function Oe(){let{t:e}=R(),t=oe(Y),r=se(Y).data?.roles.publicEndpoint.resolved??null;return n(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[n(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[a(T,{className:`h-3.5 w-3.5 text-foreground-subtle`}),a(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`connectPhone.title`)})]}),n(`div`,{className:`p-4 space-y-3`,children:[a(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`connectPhone.description`)}),t.isPending?n(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[a(k,{className:`h-3.5 w-3.5 animate-spin`}),e(`connectPhone.loading`)]}):t.isError?n(`div`,{className:`flex items-start gap-2 text-[11px] text-danger`,children:[a(_,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),n(`div`,{className:`flex-1 min-w-0 space-y-1.5`,children:[a(`div`,{className:`break-words`,children:e(`connectPhone.error`,{message:t.error.message})}),a(L,{size:`sm`,variant:`ghost`,onClick:()=>void t.refetch(),children:e(`connectPhone.retry`)})]})]}):a(ke,{candidates:we(t.data.endpoints),preferredOrigin:r})]})]})}function ke({candidates:e,preferredOrigin:t}){let{t:r}=R(),[o,c]=s(null),l=Te(e,o,t),u=i(()=>l?Ee(l.origin):null,[l]);if(l===null||u===null)return a(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`connectPhone.empty`)});let d=e=>r(`connectPhone.tier.${e}`),f=e.map(e=>({value:e.origin,label:`${d(e.tier)} — ${e.origin}`}));return n(`div`,{className:`flex flex-col sm:flex-row gap-4`,children:[a(ie,{value:u,size:De,alt:r(`connectPhone.qrAlt`),className:`self-start`}),n(`div`,{className:`flex-1 min-w-0 space-y-3`,children:[n(`label`,{className:`block space-y-1`,children:[a(`span`,{className:`text-[11px] font-medium text-foreground`,children:r(`connectPhone.addressLabel`)}),a(E,{value:l.origin,options:f,onChange:e=>c(e.target.value)}),n(`span`,{className:`block text-[10px] text-foreground-subtle`,children:[d(l.tier),` · `,l.label]})]}),!l.secure&&a(X,{text:r(`connectPhone.insecure`)}),!l.plausible&&a(X,{text:r(`connectPhone.implausible`)}),n(`div`,{className:`space-y-1`,children:[a(`span`,{className:`text-[11px] font-medium text-foreground`,children:r(`connectPhone.linkLabel`)}),n(`div`,{className:`flex items-center gap-1 rounded-md border border-border bg-background px-2 py-1`,children:[a(`code`,{className:`flex-1 min-w-0 font-mono text-[11px] text-foreground break-all select-all`,children:u}),a(re,{value:u,srLabel:r(`connectPhone.linkLabel`)})]})]}),a(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`connectPhone.signInHint`)})]})]})}function X({text:e}){return n(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-2.5 py-1.5 text-[11px] text-foreground`,children:[a(_,{className:`h-3.5 w-3.5 text-warning mt-0.5 shrink-0`}),a(`span`,{children:e})]})}l();function Ae(e){return new Date(e).toLocaleDateString()}function je(){let{t:e}=R(),t=y(),i=P.useUtils(),c=P.auth.listLinkableProviders.useQuery(),l=P.auth.listOwnExternalIdentities.useQuery(),[u,d]=s(null),[f,m]=s(()=>z(window.location.search)),g=r(null),_=G(`Linking a sign-in account`),v=r(null);o(()=>()=>v.current?.(),[]);let[b,x]=s(null);o(()=>{if(f===null)return;let e=new URL(window.location.href);e.searchParams.delete(`linked`),e.searchParams.delete(`linkError`),window.history.replaceState({},``,e.pathname+e.search+e.hash)},[f]);let C=P.auth.beginExternalLink.useMutation({onSuccess:({url:e})=>{let t=g.current;if(g.current=null,t===null||t.closed){window.location.assign(e);return}let n=e=>{x(null),m(z(`?${e}`)),i.auth.listOwnExternalIdentities.invalidate()};v.current?.(),v.current=B(t,{onReturn:e=>{e.target===`profile`&&n(e.query)},onDone:e=>{e.target===`profile`&&n(e.query)},onClosed:()=>{v.current?.(),v.current=null,i.auth.listOwnExternalIdentities.invalidate()}}),t.location.href=h(ue(e))},onError:e=>{g.current?.close(),g.current=null,x(null),d(e.message)}}),w=P.auth.unlinkOwnExternalIdentity.useMutation({onSuccess:()=>void i.auth.listOwnExternalIdentities.invalidate(),onError:e=>d(e.message)}),T=c.data??[],E=l.data??[],D=b!==null&&E.some(e=>e.provider===b);if(o(()=>{!D||b===null||(x(null),m({kind:`linked`,provider:b}))},[D,b]),T.length===0&&E.length===0)return null;let A=new Set(E.map(e=>e.provider)),j=e=>T.find(t=>t.provider===e)?.label??e,M=async(n,r)=>{await t({title:e(`users.linkedSignInsSection.unlinkSignInAccount`,`Unlink sign-in account`),message:e(`users.linkedSignInsSection.stopSigningInWithThis`,`Stop signing in with this {{label}} account?`,{label:r}),confirmLabel:e(`users.linkedSignInsSection.unlink`,`Unlink`),variant:`danger`})&&(d(null),w.mutate({provider:n.provider,subject:n.subject}))};return n(`div`,{"data-testid":`linked-sign-ins`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[_.dialog,n(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[a(O,{className:`h-3.5 w-3.5 text-foreground-subtle`}),a(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`users.linkedSignInsSection.linkedSignInAccounts`,`Linked sign-in accounts`)})]}),n(`div`,{className:`p-4 space-y-3`,children:[a(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`users.linkedSignInsSection.signInWithAnExternal`,`Sign in with an external account instead of your password. Only accounts you link here can sign you in; your two-factor authentication still applies.`)}),f?.kind===`linked`&&n(`div`,{className:`flex items-center gap-2 rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2 text-xs text-foreground`,children:[a(S,{className:`h-3.5 w-3.5 text-emerald-500 shrink-0`}),e(`users.linkedSignIns.linkedNotice`,{provider:j(f.provider)})]}),(f?.kind===`error`||u)&&n(`div`,{className:`flex items-center gap-2 rounded-md border border-danger/20 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[a(p,{className:`h-3.5 w-3.5 shrink-0`}),u??(f?.kind===`error`?f.message:``)]}),E.length>0&&a(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:E.map(t=>{let r=t.providerLabel??t.provider;return n(`li`,{className:`flex items-center gap-3 px-3 py-2 text-xs`,children:[n(`div`,{className:`flex-1 min-w-0`,children:[n(`div`,{className:`font-medium text-foreground truncate`,children:[r,!t.available&&a(`span`,{className:`ml-2 rounded bg-foreground-subtle/15 px-1.5 py-0.5 text-[10px] font-normal text-foreground-subtle`,children:e(`users.linkedSignInsSection.providerUnavailable`,`provider unavailable`)})]}),a(`div`,{className:`text-[11px] text-foreground-subtle truncate`,children:e(`users.linkedSignIns.linkedOn`,{label:t.label??t.subject,date:Ae(t.linkedAt)})})]}),n(L,{variant:`unstyled`,onClick:()=>void M(t,r),disabled:w.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[a(ne,{className:`h-3 w-3`}),e(`users.linkedSignInsSection.unlink`,`Unlink`)]})]},`${t.provider}|${t.subject}`)})}),a(`div`,{className:`flex flex-wrap gap-2`,children:T.filter(e=>!A.has(e.provider)).map(t=>n(L,{variant:`unstyled`,onClick:()=>{d(null),m(null),_.requestProof().then(e=>{e!==null&&(g.current=de(null),x(g.current===null?null:t.provider),C.mutate({provider:t.provider,reauthToken:e}))})},disabled:C.isPending,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1 text-[11px] font-medium text-foreground hover:bg-surface-hover disabled:opacity-50`,children:[C.isPending&&C.variables?.provider===t.provider?a(k,{className:`h-3 w-3 animate-spin`}):a(O,{className:`h-3 w-3`}),e(`users.linkedSignIns.link`,{provider:t.label})]},t.provider))})]})]})}l();function Me({value:r,size:i=192}){let{t:c}=R(),[l,u]=s(null),[d,f]=s(null);if(o(()=>{let n=!1;return t(()=>import(`./browser-BHo8W_uH.js`).then(t=>e(t.default,1)).then(async e=>{if(n)return;let t=e.create;if(typeof t!=`function`){f(`qrcode.create() unavailable in installed version`);return}try{let e=t(r,{errorCorrectionLevel:`M`});n||u(e)}catch(e){n||f(e instanceof Error?e.message:`QR generation failed`)}}),__vite__mapDeps([0,1]),import.meta.url).catch(()=>{n||f(`qrcode library not installed`)}),()=>{n=!0}},[r]),d)return a(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle text-center p-4`,style:{width:i,height:i},children:c(`users.totpQrCode.qrRenderingUnavailableUseThe`,`QR rendering unavailable — use the secret below.`)});if(!l)return a(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle animate-pulse`,style:{width:i,height:i},children:c(`users.totpQrCode.generating`,`Generating…`)});let p=l.modules.size,m=i/p,h=[];for(let e=0;e<p;e++)for(let t=0;t<p;t++)l.modules.data[e*p+t]&&h.push(a(`rect`,{x:t*m,y:e*m,width:m,height:m,fill:`currentColor`},`${t}-${e}`));return n(`svg`,{width:i,height:i,viewBox:`0 0 ${i} ${i}`,className:`text-black`,children:[a(`rect`,{x:0,y:0,width:i,height:i,fill:`white`}),h]})}l();function Ne(){let{t:e}=R(),t=x(),[r,i]=s(``),[o,c]=s(``),[l,d]=s(``),[f,m]=s(null),h=u({mutationFn:e=>t.changeOwnPassword(e),onSuccess:()=>{m({kind:`success`,msg:`Password updated.`}),i(``),c(``),d(``)},onError:e=>{m({kind:`error`,msg:e instanceof Error?e.message:`Update failed`})}}),g=o.length>0&&l.length>0&&o!==l,_=o.length>0&&o.length<8,v=r.length>=1&&o.length>=8&&o===l;return n(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[n(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[a(ee,{className:`h-3.5 w-3.5 text-foreground-subtle`}),a(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`systemPage.myAccess.changePassword`,`Change password`)})]}),n(`div`,{className:`p-4 space-y-3`,children:[a(Z,{label:e(`systemPage.myAccess.currentPassword`,`Current password`),value:r,onChange:i,autoComplete:`current-password`}),a(Z,{label:e(`systemPage.myAccess.newPassword`,`New password`),value:o,onChange:c,autoComplete:`new-password`,hint:e(`systemPage.myAccess.atLeast8Characters`,`At least 8 characters.`)}),a(Z,{label:e(`systemPage.myAccess.confirmNewPassword`,`Confirm new password`),value:l,onChange:d,autoComplete:`new-password`}),(g||_)&&a(`div`,{className:`text-[11px] text-danger`,children:g?e(`systemPage.myAccess.passwordsDoNotMatch`,`Passwords do not match.`):e(`systemPage.myAccess.newPasswordMustBeAt`,`New password must be at least 8 characters.`)}),f&&n(`div`,{className:`text-[11px] flex items-center gap-1 ${f.kind===`success`?`text-success`:`text-danger`}`,children:[f.kind===`success`?a(S,{className:`h-3 w-3`}):a(p,{className:`h-3 w-3`}),f.msg]}),a(`div`,{className:`flex justify-end`,children:n(L,{onClick:()=>{m(null),h.mutate({currentPassword:r,newPassword:o})},disabled:!v||h.isPending,children:[h.isPending?a(k,{className:`h-3 w-3 animate-spin`}):a(D,{className:`h-3 w-3`}),e(`systemPage.myAccess.updatePassword`,`Update password`)]})})]})]})}function Z({label:e,value:t,onChange:r,autoComplete:i,hint:o}){return n(`div`,{className:`space-y-1`,children:[a(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e}),a(F,{type:`password`,value:t,onChange:e=>r(e.target.value),autoComplete:i,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),o&&a(`div`,{className:`text-[10px] text-foreground-subtle`,children:o})]})}function Pe({username:e}){let{t}=R(),r=x(),l=c({queryKey:[`auth`,`getOwnTotpStatus`],queryFn:()=>r.getOwnTotpStatus()}),f=l.data,[m,h]=s(null),[g,_]=s(``),[v,y]=s(null),[C,w]=s(!1),E=u({mutationFn:()=>r.setupOwnTotp(),onSuccess:e=>{h({secret:e.secret,otpauthUrl:e.otpauthUrl}),_(``),y(null)},onError:e=>y(e instanceof Error?e.message:`Setup failed`)}),D=u({mutationFn:e=>r.confirmOwnTotp(e),onSuccess:()=>{h(null),_(``),y(null),l.refetch()},onError:e=>y(e instanceof Error?e.message:`Confirmation failed — code did not match`)}),O=G(`Turning off two-factor authentication`),A=u({mutationFn:async()=>{let e=await O.requestProof();return e===null?null:r.disableOwnTotp({reauthToken:e})},onSuccess:()=>{y(null),l.refetch()},onError:e=>y(e instanceof Error?e.message:`Disable failed`)});o(()=>{if(!C)return;let e=setTimeout(()=>w(!1),1500);return()=>clearTimeout(e)},[C]);let j=i(()=>l.isLoading?`loading`:m?`setup_in_progress`:f?.enabled?`enrolled`:`not_enrolled`,[l.isLoading,f?.enabled,m]);return n(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[O.dialog,n(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[a(T,{className:`h-3.5 w-3.5 text-foreground-subtle`}),a(`div`,{className:`text-xs font-semibold text-foreground`,children:t(`systemPage.myAccess.twoFactorAuthentication`,`Two-factor authentication`)})]}),n(`div`,{className:`p-4 space-y-3`,children:[j===`loading`&&n(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[a(k,{className:`h-3.5 w-3.5 animate-spin`}),t(`systemPage.myAccess.checkingStatus`,`Checking status…`)]}),j===`not_enrolled`&&n(d,{children:[a(`div`,{className:`text-xs text-foreground-subtle`,children:t(`systemPage.myAccess.2faIsnTActiveOn`,`2FA isn't active on your account. Enable it to require a 6-digit code from your authenticator app at every login.`)}),a(`div`,{className:`flex justify-end`,children:n(L,{onClick:()=>{y(null),E.mutate()},disabled:E.isPending,children:[E.isPending?a(k,{className:`h-3 w-3 animate-spin`}):a(T,{className:`h-3 w-3`}),t(`systemPage.myAccess.enable2fa`,`Enable 2FA`)]})})]}),j===`setup_in_progress`&&m&&n(d,{children:[a(`div`,{className:`text-[11px] text-foreground-subtle`,children:a(W,{i18nKey:`systemPage.myAccess.scanQr`,values:{username:e},components:{mono:a(`span`,{className:`font-mono`})}})}),n(`div`,{className:`flex flex-col items-center gap-3`,children:[a(`div`,{className:`rounded-lg border border-border bg-white p-3`,children:a(Me,{value:m.otpauthUrl,size:180})}),n(`div`,{className:`w-full`,children:[a(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle mb-1`,children:t(`systemPage.myAccess.secretManualEntry`,`Secret (manual entry)`)}),n(`div`,{className:`flex items-center gap-2 rounded border border-border bg-surface-hover/30 px-2 py-1.5`,children:[a(`code`,{className:`text-[11px] font-mono text-foreground break-all flex-1`,children:m.secret}),n(L,{variant:`ghost`,onClick:()=>{m&&navigator.clipboard.writeText(m.secret).then(()=>w(!0))},children:[C?a(S,{className:`h-3 w-3 text-success`}):a(b,{className:`h-3 w-3`}),C?t(`systemPage.myAccess.copied`,`Copied`):t(`common.copy`,`Copy`)]})]})]})]}),n(`div`,{className:`space-y-1`,children:[a(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`6-digit code`}),a(F,{type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,placeholder:`123456`,value:g,onChange:e=>_(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full rounded-md border border-border bg-surface px-3 py-2 text-center text-lg font-mono tracking-widest text-foreground focus:outline-none focus:ring-2 focus:ring-primary`})]}),v&&n(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[a(p,{className:`h-3 w-3`}),v]}),n(`div`,{className:`flex justify-end gap-2`,children:[a(L,{variant:`outline`,onClick:()=>{h(null),y(null),_(``)},children:t(`common.cancel`,`Cancel`)}),n(L,{onClick:()=>{y(null),D.mutate({code:g})},disabled:D.isPending||g.length!==6,children:[D.isPending?a(k,{className:`h-3 w-3 animate-spin`}):a(S,{className:`h-3 w-3`}),t(`common.confirm`,`Confirm`)]})]})]}),j===`enrolled`&&f&&n(d,{children:[n(`div`,{className:`rounded-md border border-success/30 bg-success/5 px-3 py-2.5 flex items-start gap-2.5`,children:[a(S,{className:`h-4 w-4 mt-0.5 text-success shrink-0`}),n(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[a(`div`,{className:`font-medium`,children:t(`systemPage.myAccess.2faIsActive`,`2FA is active`)}),a(`div`,{className:`text-foreground-subtle`,children:t(`common.enrolledOn`,{when:f.confirmedAt?new Date(f.confirmedAt).toLocaleString():`—`})})]})]}),v&&n(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[a(p,{className:`h-3 w-3`}),v]}),a(`div`,{className:`flex justify-end`,children:n(L,{variant:`danger`,onClick:()=>{y(null),A.mutate()},disabled:A.isPending,children:[A.isPending?a(k,{className:`h-3 w-3 animate-spin`}):a(T,{className:`h-3 w-3`}),t(`systemPage.myAccess.disable2fa`,`Disable 2FA`)]})})]})]})]})}function Fe(){return I(`auth-webauthn/passkey-enrollment`)?a(ae,{widgetId:`auth-webauthn/passkey-enrollment`,host:`dashboard`}):null}l();function Q(e){return e.message.length>0?e.message:le.t(`auth.authAuditSection.requestFailed`)}function Ie(){let{t:e}=R(),{logout:t}=V(),r=y(),i=P.useUtils(),o=P.auth.listOwnSessions.useQuery(),[c,l]=s(null),u=P.auth.revokeOwnSession.useMutation({onSuccess:()=>void i.auth.listOwnSessions.invalidate(),onError:e=>l(`Sign out failed: ${Q(e)}`)}),d=P.auth.logout.useMutation({onSuccess:()=>t(),onError:e=>l(`Sign out failed: ${Q(e)}`)}),f=async t=>{await r({title:e(`auth.mySessionsSection.signOutThisSession`,`Sign out this session`),message:e(`auth.mySessionsSection.willHaveToSignIn`,`{{label}} will have to sign in again.`,{label:ge(t.client).label}),confirmLabel:e(`auth.mySessionsSection.signOut`,`Sign out`),variant:`danger`})&&(l(null),u.mutate({id:t.id}))},p=async()=>{await r({title:e(`auth.mySessionsSection.signOutEverywhere`,`Sign out everywhere`),message:e(`auth.mySessionsSection.everySessionOfYourAccount`,`Every session of your account ends, this browser included: you will be signed out here too and every device has to sign in again.`),confirmLabel:e(`auth.mySessionsSection.signOutEverywhere`,`Sign out everywhere`),variant:`danger`})&&(l(null),d.mutate({everywhere:!0}))};return n(`div`,{"data-testid":`my-sessions`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[n(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[a(te,{className:`h-3.5 w-3.5 text-foreground-subtle`}),a(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`auth.mySessionsSection.activeSessions`,`Active sessions`)})]}),n(`div`,{className:`p-4 space-y-3`,children:[a(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`auth.mySessionsSection.theBrowsersAndAppsSigned`,`The browsers and apps signed in to your account. Signing one out ends it at once.`)}),c!==null&&a(`div`,{className:`text-[11px] text-danger`,children:c}),a(K,{sessions:o.data??[],isLoading:o.isLoading,loadError:o.isError?o.error?.message??e(`auth.authAuditSection.requestFailed`):null,emptyText:`No active sessions.`,onRevoke:e=>void f(e),revokingId:u.isPending?u.variables?.id??null:null}),a(`div`,{className:`flex justify-end`,children:n(L,{variant:`unstyled`,onClick:()=>void p(),disabled:d.isPending,className:`inline-flex items-center gap-1.5 rounded border border-danger/40 px-2.5 py-1 text-[11px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,children:[d.isPending?a(k,{className:`h-3 w-3 animate-spin`}):a(N,{className:`h-3 w-3`}),e(`auth.mySessionsSection.signOutEverywhere`,`Sign out everywhere`)]})})]})]})}l();var Le=`You`;function Re(){let{t:e}=R(),t=y(),n=P.useUtils(),r=P.auth.listOwnDeviceCredentials.useQuery(),[o,c]=s(null),l=P.auth.revokeOwnDeviceCredential.useMutation({onSuccess:e=>{e.revoked||c(`That device could not be revoked - it may already be gone.`),n.auth.listOwnDeviceCredentials.invalidate()},onError:e=>c(`Revoke failed: ${e.message}`)}),u=i(()=>(r.data??[]).map(e=>ye(e,Le)),[r.data]),d=async n=>{await t({title:e(`certificates.myDevicesSection.revoke`,`Revoke "{{name}}"?`,{name:n.name}),message:e(`certificates.myDevicesSection.theDeviceStopsSigningIn`,`The device stops signing in at once and its open sessions end. To use it again you have to pair it anew. This cannot be undone.`),confirmLabel:e(`certificates.myDevicesSection.revoke2`,`Revoke`),variant:`danger`})&&(c(null),l.mutate({id:n.id}))},f={label:e(`certificates.myDevicesSection.revoke2`,`Revoke`),icon:w,isAvailable:_e,onRun:e=>void d(e),busyId:l.isPending?l.variables?.id??null:null,disabled:l.isPending};return a(me,{id:`my-devices`,title:e(`certificates.myDevicesSection.myDevices`,`My devices`),icon:T,description:e(`certificates.myDevicesSection.phonesThatStaySignedIn`,`Phones that stay signed in to your account with a certificate. If one is lost, revoke it here and it is signed out at once.`),notice:he(o),onDismissNotice:()=>c(null),children:a(be,{rows:u,label:e(`certificates.devicesCard.label`),isLoading:r.isPending,loadError:r.error===null?null:r.error.message||`Request failed`,emptyText:`No devices are signed in with a certificate.`,hideOwner:!0,expiresNone:`—`,action:f})})}var $={profile:`profile`,signIn:`sign-in`,sessions:`sessions`,tokens:`tokens`},ze=[`linked`,`linkError`],Be={view:{icon:f,cls:`bg-foreground-subtle/15 text-foreground-subtle`},create:{icon:v,cls:`bg-primary/15 text-primary`},delete:{icon:m,cls:`bg-danger/15 text-danger`}};function Ve(){let{t:e}=R(),{user:t,logout:r}=V(),[i]=H(),o=e(`system.myAccess`,`My access`);if(!t)return a(pe,{icon:A,title:o,children:a(`div`,{className:`text-xs text-foreground-subtle`,children:e(`systemPage.myAccess.notSignedIn`,`Not signed in.`)})});if(i.get(`tab`)===`preferences`)return a(U,{to:`/system/settings`,replace:!0});if(ze.some(e=>i.has(e))&&!i.has(`tab`)){let e=new URLSearchParams(i);return e.set(`tab`,$.signIn),a(U,{to:`?${e.toString()}`,replace:!0})}return a(fe,{icon:A,title:o,subtitle:e(`systemPage.myAccess.subtitle`,`Your account, how you sign in, where you are signed in, and your tokens.`),sectionsLabel:e(`systemPage.myAccess.sectionsLabel`,`My access sections`),defaultSection:$.profile,actions:n(L,{variant:`outline`,onClick:r,children:[a(N,{className:`h-3 w-3`}),e(`systemPage.myAccess.signOut`,`Sign out`)]}),sections:[{id:$.profile,label:e(`systemPage.myAccess.sections.profile`,`Profile`),content:a(He,{user:t})},{id:$.signIn,label:e(`systemPage.myAccess.sections.signIn`,`Sign-in & security`),content:n(`div`,{className:`space-y-4`,children:[a(Ne,{}),a(Pe,{username:t.username}),a(Fe,{}),a(je,{})]})},{id:$.sessions,label:e(`systemPage.myAccess.sections.sessions`,`Sessions & devices`),content:n(`div`,{className:`space-y-4`,children:[a(Ie,{}),a(Re,{}),a(Oe,{})]})},{id:$.tokens,label:e(`systemPage.myAccess.sections.tokens`,`Tokens`),content:a(ve,{ownOnly:!0})}]})}function He({user:e}){let{t}=R(),r=e.isAdmin,i=e.scopes??[];return n(`div`,{className:`space-y-4`,children:[n(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3 flex items-center gap-3`,children:[a(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-full bg-primary/10 text-primary font-semibold text-base`,children:e.username.slice(0,1).toUpperCase()}),n(`div`,{className:`flex-1 min-w-0`,children:[a(`div`,{className:`text-sm font-semibold text-foreground truncate`,children:e.username}),n(`div`,{className:`text-[11px] text-foreground-subtle`,children:[r?t(`systemPage.myAccess.administrator`,`Administrator`):t(`systemPage.myAccess.user`,`User`),` `,a(W,{i18nKey:`systemPage.myAccess.sessionId`,values:{id:e.id.slice(0,8)},components:{mono:a(`span`,{className:`font-mono`})}})]})]})]}),r&&n(`div`,{className:`rounded-lg border border-primary/30 bg-primary/5 px-4 py-3 text-xs text-foreground flex items-start gap-2.5`,children:[a(C,{className:`h-4 w-4 text-primary mt-0.5 shrink-0`}),n(`div`,{children:[a(`div`,{className:`font-semibold text-foreground`,children:t(`systemPage.myAccess.unrestrictedAccess`,`Unrestricted access`)}),a(`p`,{className:`text-foreground-subtle mt-0.5`,children:t(`systemPage.myAccess.adminSessionsBypassThePer`,`Admin sessions bypass the per-call scope check. Every protected endpoint is reachable regardless of the list below.`)})]})]}),i.length>0&&a(Ue,{scopes:i})]})}function Ue({scopes:e}){let{t}=R(),r=g();return n(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[n(`div`,{className:`px-4 py-2 border-b border-border`,children:[a(`div`,{className:`text-xs font-semibold text-foreground`,children:t(`systemPage.myAccess.grantedScopes`,`Granted scopes`)}),a(`div`,{className:`text-[10px] text-foreground-subtle`,children:t(`systemPage.myAccess.bakedIntoYourSessionToken`,`Baked into your session token at login; sign out + back in to refresh after changes.`)})]}),n(`div`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[a(`div`,{children:t(`systemPage.myAccess.type`,`Type`)}),a(`div`,{children:t(`systemPage.myAccess.target`,`Target`)}),a(`div`,{children:t(`systemPage.myAccess.access`,`Access`)})]}),a(`ul`,{className:`divide-y divide-border`,children:e.map((e,i)=>n(`li`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2.5 items-center text-xs`,children:[a(`span`,{className:`font-mono text-foreground-subtle`,children:e.type}),a(`span`,{className:`font-mono text-foreground`,children:e.type===`device`?ce(e.selector,r):e.target}),a(`div`,{className:`flex items-center gap-1`,children:[`view`,`create`,`delete`].map(r=>{let i=e.access.includes(r),{icon:o,cls:s}=Be[r];return n(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${i?s:`bg-transparent text-foreground-subtle/40 line-through`}`,title:i?t(`systemPage.myAccess.can`,`Can {{a}}`,{a:r}):t(`systemPage.myAccess.cannot`,`Cannot {{a}}`,{a:r}),children:[a(o,{className:`h-3 w-3`}),r]},r)})})]},i))})]})}export{Ve as MyAccessPage};