@camstack/addon-admin-ui 1.2.613 → 1.2.615

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 (158) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/assets/Addons-Pv3oN9IA.js +5 -0
  3. package/dist/assets/{AdminPage-CQKqrawX.js → AdminPage-D0-r_ZYa.js} +1 -1
  4. package/dist/assets/{AdminSectionedPage-DwIVrzMv.js → AdminSectionedPage-BfHOlZKL.js} +1 -1
  5. package/dist/assets/{AiProfiles-BmANABOn.js → AiProfiles-D2HKaP19.js} +2 -2
  6. package/dist/assets/{Authentication-C2KfbF99.js → Authentication-CEKlRdlg.js} +1 -1
  7. package/dist/assets/Build-Chh9rmWO.js +39 -0
  8. package/dist/assets/{Calendars-C3xWZQbZ.js → Calendars-Bm3DV2aU.js} +1 -1
  9. package/dist/assets/{CameraGrids-BBCAyFtL.js → CameraGrids-4ifvSmgD.js} +1 -1
  10. package/dist/assets/Cluster-Bu9SGmz6.js +1 -0
  11. package/dist/assets/{CompositionBlockEditor-DnMSvA7o.js → CompositionBlockEditor-BTlY2JaU.js} +2 -2
  12. package/dist/assets/{CompositionEditorPage-72libfQe.js → CompositionEditorPage-__dTh2YV.js} +1 -1
  13. package/dist/assets/Data-_vYkTPvU.js +2 -0
  14. package/dist/assets/DeviceDetail-DJJvePKr.js +2 -0
  15. package/dist/assets/{DeviceDoActionFields-B5up4yrq.js → DeviceDoActionFields-ZeqOogYx.js} +1 -1
  16. package/dist/assets/{Devices-D6FHREfO.js → Devices-CcTHzApa.js} +1 -1
  17. package/dist/assets/{EditTemplateButton-DPX0WOqP.js → EditTemplateButton-BUOIemDA.js} +1 -1
  18. package/dist/assets/{EmbedPlayerPage-C-RZWQie.js → EmbedPlayerPage-B8gUiyiM.js} +1 -1
  19. package/dist/assets/History-ClS1C4fj.js +1 -0
  20. package/dist/assets/Identity-D2V5XMWo.js +1 -0
  21. package/dist/assets/InstancesTable-Bt3T8c3h.js +1 -0
  22. package/dist/assets/IntegrationDetail-BCS78zis.js +1 -0
  23. package/dist/assets/{IntegrationHub-B9BtSaMu.js → IntegrationHub-BMmesAZ8.js} +1 -1
  24. package/dist/assets/Integrations-CFSNI8q_.js +2 -0
  25. package/dist/assets/Integrations-CfBIiUAZ.js +1 -0
  26. package/dist/assets/Library-CIjT0fJK.js +1 -0
  27. package/dist/assets/Locations-DwuLDe1T.js +3 -0
  28. package/dist/assets/{Logs-9-5UvjLl.js → Logs-CgtI-nj2.js} +1 -1
  29. package/dist/assets/{MaskShapeCanvas-DlWfqm1o.js → MaskShapeCanvas-DMXSe9GH.js} +1 -1
  30. package/dist/assets/{MotionZonesSettings-Dsogfste.js → MotionZonesSettings-BwO4KAm1.js} +1 -1
  31. package/dist/assets/MyAccess-fnsSi7Jp.js +2 -0
  32. package/dist/assets/Network-oZmdqtEy.js +1 -0
  33. package/dist/assets/NodeAddonsSettingsPanel-O52r8bjL.js +1 -0
  34. package/dist/assets/Notifications-DNQt4SU9.js +1 -0
  35. package/dist/assets/Pipeline-oTCysMv8.js +1 -0
  36. package/dist/assets/{PrivacyMaskSettings-GEXILi7D.js → PrivacyMaskSettings-tqDBT7wc.js} +1 -1
  37. package/dist/assets/Recordings-4w73eoqR.js +1 -0
  38. package/dist/assets/{ScanSubnetEditor-D8DeFgGd.js → ScanSubnetEditor-nYUrijp_.js} +1 -1
  39. package/dist/assets/{SceneMonitorEditor-DNjCVEYZ.js → SceneMonitorEditor-C0ZLt_FE.js} +1 -1
  40. package/dist/assets/SessionsList-DkEeXJyA.js +2 -0
  41. package/dist/assets/{Showroom-DpUejfiW.js → Showroom-DLM6aOsh.js} +1 -1
  42. package/dist/assets/StorageLocationsTable-C7Alsafu.js +1 -0
  43. package/dist/assets/System-BRd_mW-5.js +1 -0
  44. package/dist/assets/{Templates-sjHTHHlU.js → Templates-BilOLrUe.js} +1 -1
  45. package/dist/assets/{Terminal-k7iMG1o7.js → Terminal-ByBnD4Ac.js} +3 -3
  46. package/dist/assets/{TrainingProviders-CLlxgUAb.js → TrainingProviders-DRTjq3Jf.js} +1 -1
  47. package/dist/assets/{Viewer-CkbwufzS.js → Viewer-DhLlT5l_.js} +1 -1
  48. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DC97HC4f.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DUJyvLao.js} +1 -1
  49. package/dist/assets/{addon-icons-context-C0tNs6xW.js → addon-icons-context-DSs0oKyo.js} +1 -1
  50. package/dist/assets/{ai-page.helpers-DdhWucEq.js → ai-page.helpers-DGo3V1zm.js} +1 -1
  51. package/dist/assets/{archive-q0nUTtLZ.js → archive-CvOMe4gf.js} +1 -1
  52. package/dist/assets/{assignment-candidates-BSthRvB4.js → assignment-candidates-QJ6eLj0G.js} +1 -1
  53. package/dist/assets/{authed-media-BKgp95tT.js → authed-media-CrHwqggo.js} +1 -1
  54. package/dist/assets/{bell-off-CAtUxhvq.js → bell-off-BsP6ddBp.js} +1 -1
  55. package/dist/assets/{board-model-CtzCCjoE.js → board-model-PDKNkaLS.js} +1 -1
  56. package/dist/assets/{boxes-B_Eu0xYD.js → boxes-DIhbjn5a.js} +1 -1
  57. package/dist/assets/{calendar-clock-dlTytvhp.js → calendar-clock-BsT9Lwvq.js} +1 -1
  58. package/dist/assets/circle-slash-Csf7e9y5.js +1 -0
  59. package/dist/assets/client-Dd2wRwgL.js +809 -0
  60. package/dist/assets/create-composition-tUi_RmT3.js +2 -0
  61. package/dist/assets/crop-BwDvG8SO.js +1 -0
  62. package/dist/assets/{database-zap-DSRFTyhx.js → database-zap-CwRJ0-SM.js} +1 -1
  63. package/dist/assets/{device-integration-icon-DJJlbRLB.js → device-integration-icon-CqMezYLL.js} +1 -1
  64. package/dist/assets/device-picker-model-DsBHMvS0.js +1 -0
  65. package/dist/assets/{dist-B4-yMFSq.js → dist-BGAl5BvD.js} +1 -1
  66. package/dist/assets/dist-Cs_aK-Rt.js +809 -0
  67. package/dist/assets/{eraser-CUhE6HSY.js → eraser-CuLdbo7W.js} +1 -1
  68. package/dist/assets/{file-up-CXWI0vro.js → file-up-F0uKRM-I.js} +1 -1
  69. package/dist/assets/{format-BsOPQm9n.js → format-BflauAMX.js} +1 -1
  70. package/dist/assets/{grip-vertical-BXgHxWsV.js → grip-vertical-B-IndDz6.js} +1 -1
  71. package/dist/assets/{hard-drive-download-VeG-eE4r.js → hard-drive-download-DY-OQh0v.js} +1 -1
  72. package/dist/assets/{hostInit-C1WJ96M_.js → hostInit-DC7UILFs.js} +1 -1
  73. package/dist/assets/i18n-baNKYs_D.js +1 -0
  74. package/dist/assets/icons-ChdyRSvl.js +1 -0
  75. package/dist/assets/index-CRwZ3Qx0.js +4 -0
  76. package/dist/assets/{key-P9Z4k-0x.js → key-BCxCEqdb.js} +1 -1
  77. package/dist/assets/{key-square-DIbfpLYV.js → key-square-CxmlVr0h.js} +1 -1
  78. package/dist/assets/{layers-550lFq3G.js → layers-BQ4CfwT4.js} +1 -1
  79. package/dist/assets/{link-2-off-BdR1HwXS.js → link-2-off-KZXTolmN.js} +1 -1
  80. package/dist/assets/{linked-devices-model-CgT70tWv.js → linked-devices-model-BWO0SJ-m.js} +1 -1
  81. package/dist/assets/{list-ordered-DkmlIGQW.js → list-ordered-BD9rtsb8.js} +1 -1
  82. package/dist/assets/{memory-stick-C7a1pnZA.js → memory-stick-BWqihNRD.js} +1 -1
  83. package/dist/assets/{message-square-plus-BbSNBLpN.js → message-square-plus-BKfambdz.js} +1 -1
  84. package/dist/assets/{mf-entry-bootstrap-0-1031b78a.js → mf-entry-bootstrap-0-a916583f.js} +2 -2
  85. package/dist/assets/{mic-off-BQRhIJ6Z.js → mic-off-B6rqYts5.js} +1 -1
  86. package/dist/assets/{monitor-off-Dnx5Uidp.js → monitor-off-DHS2nIpy.js} +1 -1
  87. package/dist/assets/{monitor-smartphone-C08yRk5k.js → monitor-smartphone-CHT4W6lM.js} +1 -1
  88. package/dist/assets/mount-DsBHMvS0.js +1 -0
  89. package/dist/assets/{notification-rule-status-DORi1LR8.js → notification-rule-status-CI2WdaQz.js} +1 -1
  90. package/dist/assets/player-overlays-CDEJeChs.js +1 -0
  91. package/dist/assets/remoteEntry-O1BXa5Fk.js +1 -0
  92. package/dist/assets/{ruler-DLPl8aKF.js → ruler-CIXXEKsv.js} +1 -1
  93. package/dist/assets/{scan-eye-C7Kvo33Q.js → scan-eye-Mq4zK06M.js} +1 -1
  94. package/dist/assets/{scissors-D9pfuljG.js → scissors-BcW6Mc7M.js} +1 -1
  95. package/dist/assets/{search-x-CyWzUJHP.js → search-x-i3gDm6mI.js} +1 -1
  96. package/dist/assets/{send-DHAuefQL.js → send-wpBryEwN.js} +1 -1
  97. package/dist/assets/{settings-2-C0E3sNyV.js → settings-2-B6wA8SQQ.js} +1 -1
  98. package/dist/assets/{shapes-DUA5YHLG.js → shapes-D0lS1sG-.js} +1 -1
  99. package/dist/assets/{sigma-BDlc8TxF.js → sigma-BkoUYx-o.js} +1 -1
  100. package/dist/assets/{speaker-D8B2puzu.js → speaker-CqOk3MNB.js} +1 -1
  101. package/dist/assets/src-BcPu1yLE.js +100 -0
  102. package/dist/assets/{sso-popup-CQV5EFHP.js → sso-popup-D0lbs0XK.js} +1 -1
  103. package/dist/assets/{step-inspector-model-BQR3F7Jg.js → step-inspector-model-C-MA5cbz.js} +1 -1
  104. package/dist/assets/{table-2-Cjb75Gi9.js → table-2-C8eX9UBz.js} +1 -1
  105. package/dist/assets/{timer-reset-H8wqMb8F.js → timer-reset-DmyTvMJb.js} +1 -1
  106. package/dist/assets/{unlink-BQ-yuMty.js → unlink-C1AgH7gH.js} +1 -1
  107. package/dist/assets/{usb-DDx9zAx4.js → usb-Crbrwo0M.js} +1 -1
  108. package/dist/assets/{use-device-bound-caps-BZuh_-FO.js → use-device-bound-caps-B2MESKLy.js} +1 -1
  109. package/dist/assets/{use-scenes-feed-CYqbMC8a.js → use-scenes-feed-CXxq3tm2.js} +1 -1
  110. package/dist/assets/{use-stationary-objects-BRzkuAzf.js → use-stationary-objects-V4uqo6qu.js} +1 -1
  111. package/dist/assets/{useAdminDeviceRemoval-B3-kERGS.js → useAdminDeviceRemoval-DSV8CKY2.js} +1 -1
  112. package/dist/assets/useEventInvalidation-DsBHMvS0.js +1 -0
  113. package/dist/assets/{useNodeUrlSelection-ndIqCMdG.js → useNodeUrlSelection-a943JaGB.js} +1 -1
  114. package/dist/assets/user-round-B8uNRnbG.js +1 -0
  115. package/dist/assets/{user-x-ACxq5S24.js → user-x-CXK-3Bzx.js} +1 -1
  116. package/dist/assets/{variable-DE3g0D48.js → variable-CjnitRxC.js} +1 -1
  117. package/dist/assets/{video-BvnxG-kU.js → video-CbOJmRcC.js} +1 -1
  118. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-Kr7hlZBe.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-B3sox7Ia.js} +2 -2
  119. package/dist/index.html +10 -10
  120. package/dist/server/addon.js +447 -595
  121. package/package.json +2 -2
  122. package/dist/assets/Addons-CqYKVI-X.js +0 -5
  123. package/dist/assets/Build-D7fMtVOm.js +0 -39
  124. package/dist/assets/Cluster-Cnoc9etN.js +0 -1
  125. package/dist/assets/Data-BsFgvDDc.js +0 -2
  126. package/dist/assets/DeviceDetail-xmvg__cy.js +0 -2
  127. package/dist/assets/History-DWl0AFGJ.js +0 -1
  128. package/dist/assets/Identity-DTaZ5LwU.js +0 -1
  129. package/dist/assets/InstancesTable-CmdXLlKr.js +0 -1
  130. package/dist/assets/IntegrationDetail-Dy7KkoXf.js +0 -1
  131. package/dist/assets/Integrations-DFWCDQ4i.js +0 -2
  132. package/dist/assets/Integrations-Db97Y6T6.js +0 -1
  133. package/dist/assets/Library-0JeelG3C.js +0 -1
  134. package/dist/assets/Locations-idlnsvni.js +0 -3
  135. package/dist/assets/MyAccess-B1AP34J3.js +0 -2
  136. package/dist/assets/Network-fU18SAUw.js +0 -1
  137. package/dist/assets/NodeAddonsSettingsPanel-z9e763EA.js +0 -1
  138. package/dist/assets/Notifications-Do0-oVK9.js +0 -1
  139. package/dist/assets/Pipeline-prDhU2J4.js +0 -1
  140. package/dist/assets/Recordings-DsJl2FhW.js +0 -1
  141. package/dist/assets/SessionsList-hKb6VChZ.js +0 -2
  142. package/dist/assets/StorageLocationsTable-BTWBlLcF.js +0 -1
  143. package/dist/assets/System-BXb83rJF.js +0 -1
  144. package/dist/assets/circle-slash-w9FRTZfM.js +0 -1
  145. package/dist/assets/client-mCEzjXIR.js +0 -809
  146. package/dist/assets/create-composition-Qtc7PTdK.js +0 -2
  147. package/dist/assets/crop-D5ieSxDF.js +0 -1
  148. package/dist/assets/device-picker-model-D7WYy-h_.js +0 -1
  149. package/dist/assets/dist-1KrVcdTB.js +0 -809
  150. package/dist/assets/i18n-C6fCBciG.js +0 -1
  151. package/dist/assets/icons-VDLpNA-_.js +0 -1
  152. package/dist/assets/index-DbICehF2.js +0 -4
  153. package/dist/assets/mount-D7WYy-h_.js +0 -1
  154. package/dist/assets/player-overlays-ywd6nvhM.js +0 -1
  155. package/dist/assets/remoteEntry-LTVk7I4e.js +0 -1
  156. package/dist/assets/src-DmG3r3oz.js +0 -100
  157. package/dist/assets/useEventInvalidation-D7WYy-h_.js +0 -1
  158. package/dist/assets/user-round-BcQrMUco.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-ywd6nvhM.js";import{So as A,l as oe,xo as se}from"./client-mCEzjXIR.js";import{c as j,f as M,h as ce,r as N}from"./video-BvnxG-kU.js";import{t as le}from"./file-up-CXWI0vro.js";import{t as ue}from"./key-P9Z4k-0x.js";import{t as de}from"./monitor-smartphone-C08yRk5k.js";import{t as fe}from"./unlink-BQ-yuMty.js";import{An as pe,Bd as me,Br as P,Cc as he,Dc as ge,Ei as F,Et as _e,Fr as I,Gd as ve,Go as ye,Hd as L,In as R,Ir as z,Jd as be,Jr as B,Kd as xe,Ld as Se,Ln as V,Mr as Ce,Nf as H,Oc as we,Pr as U,Pt as W,Rd as Te,Rn as Ee,Rr as De,Ud as Oe,Vd as ke,Wd as Ae,X as je,Yr as Me,af as Ne,ar as Pe,bc as Fe,cr as Ie,er as Le,ht as Re,if as ze,ir as Be,jn as Ve,lr as He,nf as Ue,nr as We,or as Ge,qd as Ke,rf as qe,rr as Je,tf as Ye,vc as Xe,vi as G,wt as Ze,zd as Qe,zn as $e,zr as et}from"./src-DmG3r3oz.js";import{t as K}from"./i18n-C6fCBciG.js";import{t as q}from"./useTranslation-BJr-n0es.js";import{Br as tt,I as nt,Ir as rt,Rr as it,S as at,a as ot,d as st,i as ct,l as lt,t as ut}from"./index-DbICehF2.js";import{t as dt}from"./AdminSectionedPage-DwIVrzMv.js";import{t as ft}from"./AdminPage-CQKqrawX.js";import{C as pt,D as J,E as mt,O as Y,S as ht,T as gt,_ as _t,a as vt,b as yt,c as bt,d as xt,f as St,g as Ct,h as wt,i as Tt,k as Et,l as Dt,m as Ot,n as kt,o as At,p as jt,s as Mt,t as Nt,u as Pt,v as Ft,w as It,x as Lt,y as Rt}from"./SessionsList-hKb6VChZ.js";import{r as zt}from"./IntegrationHub-B9BtSaMu.js";import{n as Bt}from"./Authentication-C2KfbF99.js";s();function Vt(){let{t:e}=q(),t=w(),i=H.useUtils(),o=Et(),{data:s,isLoading:c}=Oe(),l=n(()=>s??[],[s]),u=H.useQueries(e=>l.map(t=>e.userManagement.listExternalIdentities({userId:t.id}))),d=H.auth.listLoginMethods.useQuery(),[f,p]=a(null),m=Ke({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=>({...Lt(e,o),kind:h.get(e.provider)??e.provider})),v=async n=>{let r=g.find(e=>yt(e)===n.id);r!==void 0&&await t({title:e(`access.externalIdentitiesSection.removeSignInLink`,`Remove sign-in link`),message:e(`access.externalIdentitiesSection.willNoLongerBeAble`,`"{{ownerName}}" will no longer be able to sign in with this {{kind}} account.`,{ownerName:n.ownerName,kind:n.kind}),confirmLabel:e(`common.remove`,`Remove`),variant:`danger`})&&(p(null),m.mutate({userId:r.userId,provider:r.provider,subject:r.subject}))};return r(J,{notice:Y(f),onDismissNotice:()=>{p(null)},id:`external-identities`,title:e(`access.externalIdentitiesSection.signInLinks`,`Sign-in links`),icon: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(It,{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:fe,isAvailable:()=>!0,onRun:e=>void v(e),busyId:null,disabled:m.isPending}})})}s();var Ht={key:`access.nouns.linkedApp`};function Ut(e){if(e.type===`category`){let t=e.target??``;return t===`device`?K.t(`access.linkedAppsSection.allDevices`):K.t(`access.linkedAppsSection.allTarget`,{target:t})}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function Wt(){let{t:e}=q(),t=w(),i=c(),o=L(),[s,l]=a(null),u=()=>void i.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]}),d=ve({onSuccess:u,onError:e=>l(`Revoke failed: ${e.message}`)}),f=gt(Ht,u),p=n(()=>(o.data??[]).map(e=>ht(e,e.scopes.map(Ut).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(J,{notice:Y(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(It,{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:Ht,isSelectable:e=>e.status===`active`||e.status===`revoked`,quickSelect:[{label:e(`access.linkedAppsSection.selectRevoked`,`Select revoked`),match:e=>e.status===`revoked`}]}})})}var Gt=5e3;function Kt(){let{t}=q(),n=H.useUtils(),i=H.auth.cliLoginPending.useQuery(void 0,{refetchInterval:Gt}),a=H.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(N,{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=ut(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(G,{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 qt={key:`access.nouns.session`};function Jt(){let{t}=q(),i=w(),o=H.useUtils(),s=Et(),c=H.auth.listSessions.useQuery(),[l,u]=a(null),d=()=>void o.auth.listSessions.invalidate(),f=H.auth.revokeSessions.useMutation({onSuccess:d,onError:e=>u(`Sign out failed: ${e.message}`)}),p=gt(qt,d),m=n(()=>(c.data??[]).map(e=>pt(e,s,{client:e=>_t(e).label,method:Ft})),[c.data,s]),h=async e=>{await i({title:t(`access.loginSessionsSection.signOutThisSession`,`Sign out this session`),message:t(`access.loginSessionsSection.onWillHaveToSign`,`{{ownerName}} on {{name}} will have to sign in again.`,{ownerName:e.ownerName,name:e.name}),confirmLabel:t(`access.loginSessionsSection.signOut`,`Sign out`),variant:`danger`})&&(u(null),f.mutate({id:e.id}))};return e(J,{notice:Y(l,p.outcome),onDismissNotice:()=>{u(null),p.dismiss()},id:`login-sessions`,title:t(`access.loginSessionsSection.loginSessions`,`Login sessions`),icon:de,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(Kt,{}),r(It,{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:qt,isSelectable:e=>e.status===`active`}})]})}var Yt={"by-id":`helpers.authAuditWording.bulkNoun.credential`,"share-link":`helpers.authAuditWording.bulkNoun.shareLink`,"admin-token":`helpers.authAuditWording.bulkNoun.adminToken`,"login-session":`helpers.authAuditWording.bulkNoun.loginSession`};function X(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function Z(e,t){let n=X(e,`tokenId`);return X(e,`name`)??(n===null?void 0:t.get(n))??n??`?`}function Q(e){return e.filter(e=>e!==null)}function Xt(e){let t=X(e,`prefix`);return t===null?null:K.t(`helpers.authAuditWording.prefix`,{prefix:t})}function Zt(e,t){let n=e.detail??{};switch(e.action){case`admin-token-created`:{let e=n.expiresAt;return{title:K.t(`helpers.authAuditWording.tokenCreated`,{name:Z(n,t)}),details:Q([Xt(n),typeof e==`number`?K.t(`helpers.authAuditWording.expires`,{at:Rt(e)}):null])}}case`admin-token-used`:{let e=X(n,`path`);return{title:K.t(`helpers.authAuditWording.tokenUsed`,{name:Z(n,t)}),details:Q([Xt(n),e===null?null:K.t(`helpers.authAuditWording.call`,{path:e})])}}case`token-minted`:{let e=n.expiresAt;return{title:K.t(`helpers.authAuditWording.tokenMinted`,{name:Z(n,t)}),details:Q([typeof e==`number`?K.t(`helpers.authAuditWording.expires`,{at:Rt(e)}):null])}}case`token-revoked`:return{title:K.t(`helpers.authAuditWording.anyTokenRevoked`,{name:Z(n,t)}),details:[]};case`admin-token-revoked`:return{title:K.t(`helpers.authAuditWording.tokenRevoked`,{name:Z(n,t)}),details:Q([Xt(n)])};case`credentials-revoked`:{let e=X(n,`kind`)??`credential`,t=n.revoked,r=n.skipped,i=Yt[e],a=i===void 0?`${e}s`:K.t(i);return{title:K.t(`helpers.authAuditWording.bulkRevoked`,{n:typeof t==`number`?String(t):`?`,noun:a}),details:Q([typeof r==`number`&&r>0?K.t(`helpers.authAuditWording.skipped`,{count:r}):null,X(n,`ids`)===null?null:K.t(`helpers.authAuditWording.ids`,{ids:X(n,`ids`)??``})])}}case`second-factor-skipped`:{let e=X(n,`method`),t=X(n,`factors`);return{title:K.t(`helpers.authAuditWording.secondFactorSkipped`),details:Q([e===null?null:K.t(`helpers.authAuditWording.signedInWith`,{method:Ft(e)}),t===null?null:K.t(`helpers.authAuditWording.skippedFactors`,{factors:t.split(`,`).join(`, `)})])}}default:return{title:e.action,details:Object.entries(n).map(([e,t])=>`${e}: ${String(t)}`)}}}s();var Qt=100;function $t(){let{user:e}=nt();return e?.isAdmin?r(tn,{}):null}function en(){let{data:e}=Oe(),{data:t}=H.auth.listTokens.useQuery(void 0);return n(()=>{let n=new Map;for(let t of e??[])n.set(t.id,t.username);let r=new Map;for(let e of t??[])r.set(e.id,e.label);return{userNameById:n,tokenNameById:r}},[e,t])}function tn(){let{t}=q(),n=H.auth.listAuthAudit.useQuery({limit:Qt}),{userNameById:i,tokenNameById:a}=en(),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:Qt})})]}),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(nn,{record:e,userName:e.userId===void 0?null:i.get(e.userId)??e.userId,tokenNameById:a},e.id))})})]})}function nn({record:t,userName:n,tokenNameById:i}){let a=Zt(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:Rt(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 $={loginSessions:`login-sessions`,linkedApps:`linked-apps`,tokens:`tokens`,scopedTokens:`scoped-tokens`,adminTokens:`admin-tokens`,shareLinks:`share-links`,externalIdentities:`external-identities`,audit:`auth-audit`},rn={[$.scopedTokens]:$.tokens,[$.adminTokens]:$.tokens,[$.shareLinks]:$.tokens};function an(){return[{id:$.loginSessions,label:K.t(`system.access.loginSessions`,`Login sessions`),icon:de,render:()=>r(Jt,{})},{id:$.linkedApps,label:K.t(`system.access.linkedApps`,`Linked apps`),icon:O,render:()=>r(Wt,{})},{id:$.tokens,label:K.t(`system.access.tokens`,`Tokens`),icon:M,render:({createRequested:e,onCreateConsumed:t})=>r(wt,{headerOwnsCreate:!0,createRequested:e,onCreateConsumed:t})},{id:$.externalIdentities,label:K.t(`system.access.signInLinks`,`Sign-in links`),icon:ce,render:()=>r(Vt,{})},{id:$.audit,label:K.t(`system.access.audit`,`Audit`),icon:g,render:()=>r($t,{})}]}function on({createRequested:t=!1,onCreateConsumed:i}){let{t:a}=q(),o=n(()=>an(),[]),s=zt({ids:n(()=>o.map(e=>e.id),[o]),answered:!0}),c=it(),[l]=tt(),u=l.get(`integration`),d=u===null?void 0:rn[u];if(d!==void 0){let e=new URLSearchParams(l);return e.set(`integration`,d),r(rt,{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(Le,{appearance:`pills`,value:f?.id??$.loginSessions,onValueChange:e=>{c(`?${st(l,e,null,null).toString()}`)},children:r(We,{"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===$.tokens,onCreateConsumed:i??(()=>void 0)})},f.id)]})}function sn(t,n){if(t===$.tokens)return e(G,{size:`sm`,type:`button`,"data-testid":`access-new-token`,onClick:n,children:[r(M,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),K.t(`system.access.newToken`,`New token`)]})}function cn(){let[e,t]=a(!1);return{createRequested:e,requestCreate:()=>t(!0),clearCreate:()=>t(!1)}}function ln({isPending:t,error:n,what:i,onRetry:a,children:o}){let{t:s}=q();return t?e(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,role:`status`,"data-testid":`query-pending`,children:[r(k,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),s(`certificates.queryBody.reading`,{what:i})]}):n===null?o:r(B,{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 un(){let{t}=q(),n=H.deviceCredentials.getDeviceCaStatus.useQuery({}),i=n.data;return r(J,{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(ln,{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(V,{label:t(`certificates.deviceCaCard.state`,`State`),children:[i.state===`ready`&&r(F,{variant:`success`,children:t(`certificates.deviceCaCard.ready`,`Ready`)}),i.state===`absent`&&r(F,{variant:`default`,children:t(`certificates.deviceCaCard.notCreatedYet`,`Not created yet`)}),i.state===`unavailable`&&r(F,{variant:`danger`,children:t(`certificates.deviceCaCard.unavailable`,`Unavailable`)})]}),i.state===`ready`&&e(l,{children:[r(V,{label:t(`certificates.deviceCaCard.subject`,`Subject`),valueClassName:`font-mono`,children:i.subject}),r(V,{label:t(`certificates.deviceCaCard.fingerprintSha256`,`Fingerprint (SHA-256)`),valueClassName:`font-mono`,children:i.fingerprintSha256}),r(V,{label:t(`certificates.deviceCaCard.validUntil`,`Valid until`),children:i.validTo})]}),i.state===`unavailable`&&r(V,{label:t(`certificates.deviceCaCard.reason`,`Reason`),children:r(`span`,{className:`text-danger`,children:i.reason})})]})})})}s();function dn(){let{t}=q(),n=H.useUtils(),i=H.deviceCredentials.getDeviceCertificateSettings.useQuery({}),[o,s]=a(null),c=H.deviceCredentials.setDeviceCertificateSettings.useMutation({onSuccess:()=>{s(null),n.deviceCredentials.getDeviceCertificateSettings.invalidate()},onError:e=>s(`Could not save: ${e.message}`)});return r(ln,{isPending:i.isPending,error:i.error,what:`the enrollment setting`,onRetry:()=>void i.refetch(),children:i.data!==void 0&&e(V,{label:t(`certificates.deviceSettingsRow.usersCanEnrollTheirOwn`,`Users can enroll their own devices`),actions:r(Be,{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 fn(e){let[t,n]=a(()=>Date.now());return i(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}s();var pn=80,mn=208;function hn({open:t,users:n,onClose:i,onPaired:o}){let{t:s}=q(),c=H.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(_e,{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(G,{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(G,{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(W,{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(W,{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(Ne,{value:d,maxLength:pn,onChange:e=>f(e.target.value),placeholder:s(`certificates.pairDeviceDialog.annaSIphone`,`Anna's iPhone`),autoFocus:!0})})]}):r(gn,{enrollUrl:m.enrollUrl,expiresAt:m.expiresAt,hubKnown:m.hubOrigin!==null,onRestart:()=>c.reset()})})}function gn({enrollUrl:t,expiresAt:n,hubKnown:i,onRestart:a}){let{t:o}=q(),s=At(n,fn(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(Ce,{value:t,size:mn,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(pe,{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(G,{type:`button`,variant:`outline`,size:`sm`,onClick:a,children:o(`certificates.pairDeviceDialog.newCode`,`New code`)})]})]})})}s();var _n={key:`access.nouns.device`};function vn({pairOpen:t,onPairClose:i}){let{t:o}=q(),s=w(),c=te(),l=H.useUtils(),u=H.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=H.deviceCredentials.revokeDeviceCredential.useMutation({onSuccess:b,onError:v(`Revoke`)}),S=H.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=H.deviceCredentials.renameDeviceCredential.useMutation({onSuccess:b,onError:v(`Rename`)}),T=mt(_n,e=>x.mutateAsync({id:e}),_),E=T.busy||m!==null,ee=n(()=>(u.data??[]).map(kt),[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:vt,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:Tt,onRun:e=>void ie(e),busyId:S.isPending?m:null,disabled:E}];return e(J,{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:Y(f,T.outcome),onDismissNotice:()=>{p(null),T.dismiss()},children:[r(dn,{}),r(It,{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:_n,isSelectable:vt}}),r(hn,{open:t,users:d.data??[],onClose:i,onPaired:_})]})}var yn=/-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----/,bn=/-----BEGIN ((?:RSA |EC |ENCRYPTED )?PRIVATE KEY)-----[\s\S]+?-----END \1-----/,xn={certificate:`.pem,.crt,.cer`,privateKey:`.pem,.key`,ca:`.pem,.crt,.cer`};function Sn(e,t){if(t.trim()===``)return null;if(e===`privateKey`){let e=bn.exec(t);return e===null?yn.test(t)?K.t(`helpers.pemFile.isCert`):K.t(`helpers.pemFile.notKey`):e[1]===`ENCRYPTED PRIVATE KEY`?K.t(`helpers.pemFile.encrypted`):null}return yn.test(t)?e===`certificate`&&bn.test(t)?K.t(`helpers.pemFile.certHasKey`):null:bn.test(t)?K.t(`helpers.pemFile.isKey`):K.t(`helpers.pemFile.notCert`)}function Cn(e){return e.text()}s();function wn({kind:n,label:i,value:o,onChange:s,rows:c=6}){let{t:l}=q(),u=t(null),[d,f]=a(null),[p,m]=a(null),h=p??Sn(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 Cn(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(Pe,{ref:u,accept:xn[n],onChange:e=>void _(e),className:`hidden`,"data-testid":`${g}-file`}),e(G,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>u.current?.click(),children:[r(le,{className:`mr-1 h-3 w-3`}),l(`system.pemField.chooseFile`,`Choose file`)]})]})]}),r(Ie,{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 Tn=30;function En(e){let t=Date.parse(e);return!Number.isNaN(t)&&Date.now()-t<Tn*864e5}function Dn(e){if(e===null||e===``)return`—`;let t=e.replace(/:/g,``);return t.length<=16?e:`${t.slice(0,8)}…${t.slice(-8)}`}function On(){let{t}=q(),n=c(),i=Xe(void 0,{refetchInterval:15e3}),o=Fe({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),s=he({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),l=we({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),u=ge({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(R,{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(B,{variant:`warning`,title:t(`system.localAccess.certificateReissue`,`Certificate reissue`),message:d.reissueError}),d?.restartRequired&&r(B,{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(B,{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&&En(d.caReplacedAt)&&r(B,{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:Dn(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)`)}):Dn(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(Ve,{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(G,{size:`sm`,variant:`outline`,onClick:()=>m(e=>!e),children:t(`system.localAccess.upload`,`Upload`)}),d?.caCertPem&&r(G,{size:`sm`,variant:`outline`,onClick:S,children:t(`system.localAccess.downloadCa`,`Download CA`)}),d?.mode===`uploaded`&&r(Ve,{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(Ve,{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(wn,{kind:`certificate`,label:t(`system.localAccess.certificateOrFullChainPem`,`Certificate or full chain (PEM)`),value:h,onChange:g}),r(wn,{kind:`privateKey`,label:t(`system.localAccess.privateKeyPem`,`Private key (PEM)`),value:_,onChange:v}),r(wn,{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(G,{size:`sm`,disabled:!h.trim()||!_.trim()||Sn(`certificate`,h)!==null||Sn(`privateKey`,_)!==null||Sn(`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 kn={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`};function An(e){let t=e.find(e=>e.isHub);return t?.https.kind===`served`?t.https.status.caFingerprintSha256:null}function jn({https:t,mesh:n,now:i}){let{t:a}=q(),o=Xe().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(V,{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:[An(t)??`—`,o!==``&&e(G,{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(V,{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(V,{label:a(`certificates.caStrip.clusterCaValidUntil`,`Cluster CA valid until`),children:[c.validTo,l!==null&&!Number.isNaN(l)&&e(`span`,{className:`ml-2 text-[10px] ${kn[Pt(l,i)]}`,children:[`(`,bt(l,i),`)`]})]}),u!==void 0&&e(V,{label:a(`certificates.caStrip.nodeListener`,`Node listener`),children:[u.state===`open`&&r(F,{variant:`success`,children:a(`certificates.caStrip.open`,`Open`)}),u.state===`not-started`&&r(F,{variant:`default`,children:a(`certificates.caStrip.notStarted`,`Not started`)}),u.state===`closed`&&e(`span`,{className:`text-danger`,children:[a(`certificates.caStrip.closedSince`,{when:xt(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 Mn(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 Nn(e){return e.isHub?K.t(`helpers.nodesModel.hubReissued`):e.mesh===null?K.t(`helpers.nodesModel.noCertRecorded`):e.online?null:K.t(`helpers.certificateModel.nodeOffline`)}function Pn(e){return e.isHub||e.mesh===null?Nn(e):null}var Fn={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`},In={enroll:`Issued at enrollment`,renewal:`Issued by a renewal`,boot:`Issued at boot`,pairing:`Issued at pairing`,observed:`Observed on its connection`},Ln={uploaded:`Uploaded`,generated:`Generated`,disabled:`Disabled`};function Rn(e){let t=e.https?.https;return t?.kind===`served`?Mt(t.status.validTo):null}function zn({ms:t,now:n}){return t===null?r(`span`,{className:`text-foreground-subtle`,children:`—`}):e(`div`,{children:[r(`div`,{children:xt(t)}),r(`div`,{className:`text-[10px] ${Fn[Pt(t,n)]}`,children:bt(t,n)})]})}function Bn({row:t}){let{t:n}=q(),i=t.https?.https;return i===void 0?r(`span`,{className:`text-foreground-subtle`,children:`—`}):i.kind===`served`?e(`div`,{title:i.status.leafFingerprintSha256??``,children:[r(F,{variant:`success`,className:`text-[10px]`,children:n(`certificates.nodesColumns.served`,`Served`)}),r(`span`,{className:`ml-1.5 text-[10px] text-foreground-subtle`,children:Ln[i.status.mode]}),r(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:jt(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(F,{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 Vn({row:t}){let{t:n}=q(),i=t.mesh?.current??null;if(i===null)return r(`span`,{className:`text-foreground-subtle`,children:n(`certificates.nodesColumns.noneRecorded`,`None recorded`)});let a=t.mesh?.history.length??0;return e(`div`,{children:[r(`div`,{className:`font-mono text-[11px]`,title:i.serial,children:Ot(i.serial)}),r(`div`,{className:`font-mono text-[10px] text-foreground-subtle`,title:i.fingerprintSha256,children:jt(i.fingerprintSha256)}),e(`div`,{className:`text-[10px] text-foreground-subtle`,children:[In[i.issuedVia],a>0?` · ${n(`certificates.nodesColumns.earlier`,{count:a})}`:``]})]})}function Hn({row:e}){let{t}=q(),n=e.mesh?.presentingCurrent??null;return n===null?r(`span`,{className:`text-foreground-subtle`,children:e.online?`—`:t(`certificates.nodesColumns.offline`,`Offline`)}):n?r(F,{variant:`success`,className:`text-[10px]`,children:t(`common.yes`,`Yes`)}):r(F,{variant:`warning`,className:`text-[10px]`,children:t(`certificates.nodesColumns.noPresentsAnother`,`No - presents another`)})}function Un(t){let n=t.icon;return e(G,{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 Wn({reasons:t}){let{t:n}=q();return e(Ue,{className:`inline-block`,children:[r(ze,{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(qe,{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 Gn({row:t,o:n}){let{t:i}=q(),a=t.https===null?`No HTTPS inventory for this node.`:St(t.https).reason,o=Nn(t),s=Pn(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(Un,{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(Un,{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(Un,{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(Wn,{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 Kn(t){return[{key:`node`,header:K.t(`certificates.nodesColumns.node`,`Node`),sortValue:e=>e.isHub?``:e.nodeId.toLowerCase(),render:t=>e(`div`,{className:`flex items-center gap-1.5`,children:[r(`span`,{className:`font-medium text-foreground`,children:t.nodeId}),t.nodeId===`hub`&&r(F,{variant:`info`,className:`text-[10px]`,children:K.t(`common.hubWord`)}),!t.online&&r(F,{variant:`default`,className:`text-[10px]`,children:K.t(`common.offline`)})]})},{key:`https-state`,header:`HTTPS`,notSortableReason:`A state with a reason has no single order.`,render:e=>r(Bn,{row:e})},{key:`https-expires`,header:K.t(`certificates.nodesColumns.httpsExpires`,`HTTPS expires`),sortValue:e=>Rn(e),render:e=>r(zn,{ms:Rn(e),now:t.now})},{key:`identity`,header:K.t(`certificates.nodesColumns.identity`,`Identity`),sortValue:e=>e.mesh?.current?.serial??null,render:e=>r(Vn,{row:e})},{key:`identity-expires`,header:K.t(`certificates.nodesColumns.identityExpires`,`Identity expires`),sortValue:e=>e.mesh?.current?.notAfter??null,render:e=>r(zn,{ms:e.mesh?.current?.notAfter??null,now:t.now})},{key:`presenting`,header:K.t(`certificates.nodesColumns.inUse`,`In use`),notSortableReason:`Offline nodes have no answer to order by.`,render:e=>r(Hn,{row:e})},{key:`actions`,header:K.t(`certificates.nodesColumns.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order.`,render:e=>r(Gn,{row:e,o:t})}]}s();function qn(){let{t}=q(),i=w(),o=H.useUtils(),s=fn(6e4),c=H.certificates.listHttpsCertificates.useQuery(),l=H.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=H.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=H.certificates.renewMeshOnNode.useMutation({onSuccess:e=>{m(Dt(e)),_()},onError:v(`renewal could not start`)}),x=H.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=Kn({now:s,busy:S,running:h,onRenewHttps:e=>void T(e),onRenewIdentity:E,onRevokeIdentity:e=>void ee(e)}),ne=n(()=>Mn(c.data??[],l.data),[c.data,l.data]),D=l.data?.registryAvailable??!0;return r(J,{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:Y(u,p),onDismissNotice:()=>{f(null),m(null)},children:r(ln,{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(jn,{https:c.data??[],mesh:l.data,now:s}),r(Ee,{columns:te,rows:ne,rowKey:e=>e.nodeId,minWidthPx:960,maxBodyHeight:$e,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 Jn({pairOpen:t,onPairClose:n}){return e(`div`,{className:`space-y-4`,"data-testid":`certificates-page`,children:[r(vn,{pairOpen:t,onPairClose:n}),r(un,{}),r(On,{}),r(qn,{})]})}function Yn({userId:t,username:n,onClose:i}){let{t:a}=q(),o=w(),s=H.useUtils(),c=ke({userId:t}),l=H.auth.listLoginMethods.useQuery(),u=Ke({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(U,{open:!0,onOpenChange:e=>!e&&i(),children:e(z,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`external-identities-modal`,children:[r(et,{children:e(P,{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(I,{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(G,{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(fe,{className:`h-3 w-3`}),a(`common.remove`,`Remove`)]})]},`${t.provider}|${t.subject}`)})})}),r(De,{children:r(G,{onClick:i,variant:`secondary`,children:a(`common.close`,`Close`)})})]})})}function Xn({userId:t,username:n,onClose:i}){let{t:a}=q(),o=c(),s=w(),u=me({userId:t}),d=u.data,f=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),p=Qe({onSuccess:()=>{f(),i()}}),m=u.isLoading?`loading`:d?.enabled?`enrolled`:`not_enrolled`;return r(U,{open:!0,onOpenChange:e=>!e&&i(),children:e(z,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[r(et,{children:e(P,{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(I,{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(G,{onClick:i,variant:`secondary`,children:a(`common.close`,`Close`)}),e(G,{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 Zn({userId:t,username:n,onClose:i}){let{t:o}=q(),{user:s,logout:c}=nt(),l=s?.id===t,u=w(),d=H.useUtils(),f=H.auth.listSessions.useQuery({userId:t}),[p,m]=a(null),h=H.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:_t(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(U,{open:!0,onOpenChange:e=>!e&&i(),children:e(z,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`user-sessions-modal`,children:[r(et,{children:e(P,{className:`flex items-center gap-2`,children:[r(de,{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(I,{className:`space-y-3`,children:[p!==null&&r(`div`,{className:`text-[11px] text-danger`,children:p}),r(Nt,{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(De,{className:`justify-between`,children:[e(G,{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(G,{onClick:i,variant:`secondary`,children:o(`common.close`,`Close`)})]})]})})}function Qn({scopes:t,invalidReason:n}){let{t:i}=q(),a=T(),s=o({queryKey:[`auth`,`previewScope`,t,!1],enabled:n===null,queryFn:()=>a.trpcClient.auth.previewScope.query({scopes:[...t],isAdmin:!1})}),{data:c}=ye({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 $n(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=or(t);return{role:e.isAdmin?`admin`:`viewer`,mode:n.mode,pickedIds:n.pickedIds,viewer:sr(n.mode,n.pickedIds,t.features),unconfigured:!1}}function er(e,t){return{...e,role:t}}function tr(e,t){return{...e,mode:t,viewer:sr(t,e.pickedIds,e.viewer.features)}}function nr(e,t){let n=cr(t);return{...e,pickedIds:n,viewer:sr(e.mode,n,e.viewer.features)}}function rr(e,t,n){let r=e.viewer.features.filter(e=>e!==t),i=n?[...r,t]:r;return{...e,viewer:sr(e.mode,e.pickedIds,i)}}function ir(e){return e.role===`viewer`&&e.mode===`only`&&e.pickedIds.length===0?`no-allowed-device`:null}function ar(e){return ir(e)===null?e.role===`admin`?{isAdmin:!0,scopes:[]}:{isAdmin:!1,scopes:[e.viewer]}:null}function or(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 sr(e,t,n){let r=cr(t);return e===`except`?{type:`viewer`,allow:`*`,block:r,features:[...n]}:{type:`viewer`,allow:r,block:[],features:[...n]}}function cr(e){return[...new Set(e)]}s();var lr=`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`;function ur(e,t){return e?`failed`:t===void 0?`pending`:`answered`}function dr(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 fr({user:t,isSelf:i,onClose:o,onSubmit:s,submitting:c,error:u}){let{t:d}=q(),[f,p]=a(n(()=>$n(t),[t])),m=ye({projection:`slim`}),h=m.data,g=ur(m.isError,h),_=n(()=>dr(h??[]),[h]),v=n(()=>({state:g,devices:g===`answered`?(h??[]).map(e=>({id:e.id,name:e.name})):void 0}),[g,h]),y=ir(f),b=ar(f),x=y===`no-allowed-device`?d(`users.userAccessModal.pickAllowedDevice`):null,S=e=>{p(er(f,e))},C=[{value:`except`,label:d(`users.userAccessModal.modeExcept`)},{value:`only`,label:d(`users.userAccessModal.modeOnly`)}];return r(U,{open:!0,onOpenChange:e=>!e&&o(),children:e(z,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-2xl`,children:[r(et,{children:r(P,{children:d(`users.userAccessModal.title`,{name:t.username})})}),e(I,{className:`space-y-4`,children:[f.unconfigured&&f.role===`viewer`&&r(B,{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:lr,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(pr,{name:`admin`,checked:f.role===`admin`,label:d(`users.userAccessModal.admin`),description:d(`users.userAccessModal.adminDescription`),onPick:()=>S(`admin`)}),r(pr,{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:lr,children:d(`users.userAccessModal.devices`)}),r(Re,{label:d(`users.userAccessModal.whichDevices`),value:f.mode,options:C,onChange:e=>p(tr(f,e))}),r(je,{devices:_,listState:g,fleet:v,value:[...f.pickedIds],onChange:e=>p(nr(f,e)),emptyMeansAll:f.mode===`except`,noun:`device`,testId:`viewer-device-picker`}),r(Qn,{scopes:b?.scopes??[],invalidReason:x})]}),e(`section`,{className:`space-y-2`,children:[r(`h3`,{className:lr,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(He,{className:`mt-0.5`,checked:f.viewer.features.includes(t.id),onChange:e=>p(rr(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(B,{message:u})]}),e(De,{children:[r(G,{variant:`outline`,size:`sm`,onClick:o,children:d(`common.cancel`,`Cancel`)}),r(G,{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 pr({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 mr=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:K.t(`admin.system.users.genericError`)}function vr(){let{t}=q(),n=c(),{user:o}=nt(),{state:s,openNew:u,openEdit:d,close:f}=Ze(),[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=Se(),se=Te({onSuccess:A}),j=be({onSuccess:A}),M=Ae({onSuccess:A}),ce=xe(),[N,le]=a(null),[fe,pe]=a(!1),[me,P]=a(null),[he,ge]=a(null),[F,I]=a(null),[ve,ye]=a(null),L=C??[],R=s.mode===`edit`?L.find(e=>e.id===s.id)??null:null,z=()=>{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(R===null){T||f();return}g(e=>e?.id===R.id?e:gr(R))},[s,R,T,f]);let V=s.mode===`new`&&p!==null&&p.id===void 0||s.mode===`edit`&&p!==null&&R!==null;async function Ce(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&&z())}async function H(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<mr?K.t(`admin.system.users.passwordTooShort`,{min:mr}):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 we(e){P(null),le(e)}async function U(e,t){pe(!0),P(null);try{t.isAdmin!==e.isAdmin&&await j.mutateAsync({id:e.id,isAdmin:t.isAdmin}),await ce.mutateAsync({userId:e.id,scopes:[...t.scopes]}),le(null)}catch(e){P(_r(e))}finally{pe(!1),A()}}async function De(){if(p!==null){b(null);try{if(p.id===void 0){let e=p.username.trim();if(e===``||p.password.length<mr)return;await oe.mutateAsync({username:e,password:p.password,isAdmin:p.isAdmin})}else await j.mutateAsync({id:p.id,isAdmin:p.isAdmin});A(),z()}catch(e){b(_r(e))}}}function ke(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}let je=oe.isPending||j.isPending,Pe=p!==null&&p.id===void 0&&p.username.trim()!==``&&p.password.length>=mr,Fe=p!==null&&p.id!==void 0,Ie=je||(p?.id===void 0?!Pe:!Fe),Le=e=>se.isPending&&se.variables?.id===e.id||j.isPending&&j.variables?.id===e.id||M.isPending&&M.variables?.id===e.id,Re=[{key:`username`,header:t(`admin.system.users.username`,`Username`),sortValue:e=>e.username,render:e=>r(`span`,{className:`font-medium text-foreground`,"data-testid":`user-open-${e.id}`,children:e.username})},{key:`scopes`,header:t(`admin.system.users.access`,`Access`),sortValue:e=>yr(e),render:n=>r(`span`,{onClick:e=>e.stopPropagation(),children:e(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>we(n),disabled:Le(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:ke(e.createdAt)})},{key:`actions`,header:t(`admin.system.users.actions`,`Actions`),align:`right`,nowrap:!0,notSortableReason:`Row actions`,render:n=>{let i=Le(n),a=n.id!==o?.id&&n.totpEnabled;return e(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[e(G,{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(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>ge(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(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>I(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(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>ye(n),disabled:i,title:t(`admin.system.users.activeSessions`,`Active sessions`),children:[r(de,{className:`h-3 w-3`}),t(`admin.system.users.sessions`,`Sessions`)]}),e(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void H(n),disabled:i,title:t(`admin.system.users.resetPassword`,`Reset password`),children:[r(ue,{className:`h-3 w-3`}),t(`admin.system.users.resetPassword`,`Reset password`)]}),e(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void Ce(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(ft,{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(G,{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(B,{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&&L.length===0&&r(Me,{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&&L.length>0&&r(Ee,{columns:Re,rows:L,rowKey:e=>e.id,minWidthPx:560,maxBodyHeight:`max-h-[60vh]`,onRowClick:e=>d(e.id)}),r(_e,{open:V,onClose:z,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(G,{size:`sm`,type:`button`,disabled:Ie,onClick:()=>void De(),children:je?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(W,{label:t(`admin.system.users.username`,`Username`),required:p.id===void 0,children:r(Ne,{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(W,{label:t(`admin.system.users.password`,`Password`),required:!0,description:t(`admin.system.users.atLeastCharacters`,`At least {{value1}} characters.`,{value1:String(mr)}),children:r(Ye,{value:p.password,onValueChange:e=>g({...p,password:e}),shown:x,onToggleShown:()=>S(e=>!e),placeholder:`••••••••`,"data-testid":`user-form-password`})}),r(W,{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(He,{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.`)})]})}),he&&r(Xn,{userId:he.id,username:he.username,onClose:()=>ge(null)}),F&&r(Yn,{userId:F.id,username:F.username,onClose:()=>I(null)}),ve&&r(Zn,{userId:ve.id,username:ve.username,onClose:()=>ye(null)}),N&&r(fr,{user:N,isSelf:N.id===o?.id,onClose:()=>le(null),onSubmit:e=>void U(N,e),submitting:fe,error:me})]})}function yr(e){let t=$n(e);return t.role===`admin`?0:t.unconfigured?2:1}function br({user:t}){let{t:n}=q(),i=$n(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":$.tokens,"linked-sessions":$.linkedApps},Sr=`certificates`;function Cr(t){return e(G,{size:`sm`,type:`button`,"data-testid":`certificates-pair-device`,onClick:t,children:[r(D,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),K.t(`systemPage.identity.pairADevice`,`Pair a device`)]})}function wr(){let{t:e}=q(),[t]=tt(),n=cn(),[i,o]=a(!1),s=xr[t.get(`tab`)??``];if(s!==void 0)return r(rt,{to:lt(`access`,{integration:s}),replace:!0});let c=at(`/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===ot.access.tab?sn(u,n.requestCreate):l===`certificates`?Cr(()=>o(!0)):void 0;return r(dt,{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:ot.access.tab,label:e(`systemPage.identity.tokensSessions`,`Tokens & sessions`),ownedParams:ct.concat([Ct.token,Ct.scoped,Ct.admin]),content:r(on,{createRequested:n.createRequested,onCreateConsumed:n.clearCreate})},{id:Sr,label:e(`systemPage.identity.certificates`,`Certificates`),content:r(Jn,{pairOpen:i,onPairClose:()=>o(!1)})},{id:ot.authentication.tab,label:e(`systemPage.identity.authentication`,`Authentication`),content:r(Bt,{}),ownedParams:ct}]})}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,et as s,k as c,o as l,x as u,z 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{Fn as f,Gn as p,Kt as m,Qi as h,Tn as g,V as _,Wn as ee,Xn as te,ct as ne,ht as re,on as v,wr as ie,xr as y}from"./player-overlays-ywd6nvhM.js";import{yr as ae}from"./client-mCEzjXIR.js";import{t as oe}from"./link-2-off-BdR1HwXS.js";import{Br as b,Ei as x,Et as se,Fr as S,In as ce,Ir as C,Jr as le,Oi as ue,Pr as w,Rn as de,Ws as T,Yr as fe,_n as E,fa as D,gn as O,ir as k,jn as A,kt as pe,of as j,va as M,vi as N,wt as me,zr as P}from"./src-DmG3r3oz.js";import{t as F}from"./useTranslation-BJr-n0es.js";import{n as I}from"./addon-icons-context-C0tNs6xW.js";import{$ as he,Fr as L,J as R,Mr as ge,Nr as _e,Y as ve,Z as ye,at as be,ct as xe,et as z,it as B,lt as Se,nt as Ce,q as we,r as Te,rt as V,st as Ee,tt as De}from"./index-DbICehF2.js";import{t as H}from"./NodeAddonsSettingsPanel-z9e763EA.js";s();var U=[[[`addons`,`listCapabilityProviders`]],[[`addons`,`list`]]],W=`text-[10px]`;function Oe({isActive:e}){let{t}=F();return i(x,{variant:e?`success`:`default`,className:W,children:e?t(`integrationHub.addonControls.enabled`,`Enabled`):t(`integrationHub.addonControls.disabled`,`Disabled`)})}function G({capName:t,addonId:n,isActive:r}){let{t:a}=F(),o=l(),s=M({onSuccess:()=>{for(let e of U)o.invalidateQueries({queryKey:e})}}),c=s.isPending;return e(N,{size:`sm`,variant:r?`secondary`:`primary`,disabled:c,onClick:()=>s.mutate({capName:t,addonId:n,enabled:!r}),children:[c?i(y,{className:`h-3 w-3 animate-spin`}):i(r?v:p,{className:`h-3 w-3`}),r?a(`common.disable`,`Disable`):a(`common.enable`,`Enable`)]})}function K(){let e=l();return D({onSuccess:()=>{for(let t of U)e.invalidateQueries({queryKey:t})}})}function q({addonId:e,displayName:t,message:n}){let{t:r}=F(),a=ne(),o=K();return i(j,{icon:o.isPending?y:f,variant:`ghost`,size:`sm`,"aria-label":r(`integrationHub.addonControls.restartNamed`,`Restart {{name}}`,{name:t}),disabled:o.isPending,onClick:()=>void a({title:r(`integrationHub.addonControls.restart2`,`Restart "{{displayName}}"?`,{displayName:t}),message:n,confirmLabel:r(`integrationHub.addonControls.restart`,`Restart`),variant:`danger`}).then(t=>t?o.mutateAsync({addonId:e}):void 0)})}function ke({addonId:e,displayName:t,iconOnly:n=!1,description:r}){let{t:a}=F(),o=K(),s=r??a(`integrationHub.addonControls.restartingTheAddonBouncesIts`,`Restarting the addon bounces its subprocess — the provider will briefly drop and reconnect automatically.`);return n?i(q,{addonId:e,displayName:t,message:s}):i(A,{label:a(`integrationHub.addonControls.restart`,`Restart`),icon:f,size:`sm`,title:a(`integrationHub.addonControls.restart2`,`Restart "{{displayName}}"?`,{displayName:t}),description:s,confirmLabel:a(`integrationHub.addonControls.restart`,`Restart`),triggerVariant:`ghost`,confirmVariant:`danger`,disabled:o.isPending,action:()=>o.mutateAsync({addonId:e})})}var J=600,Y=c(null);function X({id:n,title:r,icon:a,actions:o,framed:s=!1,children:c}){let{t:l}=F(),f=d(Y),p=t(null),m=`integration-section-${n}`;Z(p,f,n);let h=e(u,{children:[f===null?null:i(L,{to:f.sectionHref(n),"aria-label":l(`integrationHub.integrationSection.linkTo`,`Link to {{title}}`,{title:r}),title:l(`integrationHub.integrationSection.linkTo`,`Link to {{title}}`,{title:r}),className:`rounded p-0.5 text-foreground-subtle/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,children:i(ie,{className:`h-3 w-3`,"aria-hidden":!0})}),o]});return s?i(`div`,{ref:p,className:`scroll-mt-4`,children:i(ce,{headingId:m,title:r,icon:a,actions:h,children:c})}):e(`section`,{ref:p,"aria-labelledby":m,className:`scroll-mt-4 space-y-2`,children:[e(`header`,{className:`flex min-h-7 flex-wrap items-center gap-2 px-0.5`,children:[a!==void 0&&i(a,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),i(`h2`,{id:m,className:`${_} min-w-0 flex-1`,children:r}),h]}),c]})}function Z(e,t,n){let r=t?.requestedSection===n,i=t?.integrationId;a(()=>{if(!r)return;let t=()=>e.current?.scrollIntoView?.({block:`start`});t();let n=!1,i=()=>{n=!0},a=[`wheel`,`touchmove`,`keydown`];for(let e of a)window.addEventListener(e,i,{once:!0,passive:!0});let o=window.setTimeout(()=>{n||t()},J);return()=>{window.clearTimeout(o);for(let e of a)window.removeEventListener(e,i)}},[r,i,e])}s();var Q=`max-h-72`,$=[{kind:`logs`,labelKey:`common.logs`,icon:g},{kind:`events`,labelKey:`common.events`,icon:h}];function Ae({addonId:t,switcher:n}){let{t:r}=F(),[a,s]=o(`logs`);return e(X,{id:Te,title:r(`integrationHub.addonIntegrationBody.activity`,`Activity`),framed:!0,actions:i(`div`,{className:`flex flex-wrap items-center gap-2`,children:i(`div`,{role:`group`,"aria-label":r(`integrationHub.addonIntegrationBody.activityStream`,`Activity stream`),className:`flex items-center gap-1`,children:$.map(({kind:t,labelKey:n,icon:o})=>e(N,{variant:`unstyled`,type:`button`,"aria-pressed":a===t,onClick:()=>s(t),className:`inline-flex items-center gap-1 rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${a===t?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[i(o,{className:`h-3 w-3`,"aria-hidden":!0}),r(n)]},t))})}),children:[n!==void 0&&i(`div`,{className:`px-3 pt-2`,children:n}),a===`logs`?i(E,{addonId:t,maxHeight:Q,showFilters:!1}):i(O,{addonId:t,category:`addon.*`,maxHeight:Q})]})}function je({addonId:t,title:n=`Settings`,subtitle:r,fieldScope:a,onClose:o}){return i(w,{open:!0,onOpenChange:e=>!e&&o(),children:e(C,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-3xl`,children:[e(P,{children:[i(b,{children:n}),r&&i(`p`,{className:`text-xs text-foreground-subtle`,children:r})]}),i(S,{children:i(H,{nodeId:null,addonIds:[t],level:`global`,...a===void 0?{}:{fieldScope:a}})})]})})}function Me({addonId:e,title:t,onClose:n}){return i(je,{addonId:e,title:t,fieldScope:`cluster`,onClose:n})}var Ne=`inline-flex min-w-0 max-w-full items-center gap-1.5 rounded-full border py-1 pl-1 pr-2.5 text-xs transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,Pe=`border-primary bg-primary/10 text-primary font-medium`,Fe=`border-border bg-surface text-foreground-subtle hover:bg-surface-hover hover:text-foreground`;s();var Ie={md:{tile:`h-10 w-10 rounded-lg`,img:`h-7 w-7 rounded-md p-1`,fallback:`h-5 w-5`},sm:{tile:`h-5 w-5 rounded`,img:`h-5 w-5 rounded p-0.5`,fallback:`h-3.5 w-3.5`}};function Le({addonId:e,fallback:t,tileClassName:n,size:r=`md`}){let[a,s]=o(!1),c=I(e),l=Ie[r];return i(`div`,{className:`${l.tile} flex items-center justify-center shrink-0 ${n}`,children:a||!c?i(t,{className:l.fallback,"aria-hidden":!0}):i(`img`,{src:c,alt:``,className:`${l.img} bg-white ring-1 ring-black/5`,onError:()=>s(!0)})})}var Re={ok:`bg-success`,off:`bg-foreground-subtle/60`,error:`bg-danger`,unknown:`border border-foreground-subtle bg-transparent`};function ze(e,t){switch(t){case`ok`:return e(`instances.health.ok`,`Healthy`);case`error`:return e(`instances.health.error`,`Error`);case`off`:return e(`instances.health.off`,`Off`);case`unknown`:return e(`instances.health.unknown`,`Unknown`)}}function Be({pills:t,selected:n,onSelect:r,fallbackIcon:a,install:o}){let{t:s}=F(),c=t.length>1;return!c&&o===void 0?null:i(`div`,{className:`px-3 pt-2`,children:e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[c&&i(`div`,{role:`group`,"aria-label":s(`instances.filterByProvider`,`Filter by provider`),className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:t.map(t=>e(N,{variant:`unstyled`,type:`button`,"aria-pressed":n===t.addonId,"data-testid":`instance-pill-${t.addonId}`,onClick:()=>r(n===t.addonId?null:t.addonId),className:`inline-flex min-w-0 max-w-full items-center gap-1.5 rounded-full border py-1 pl-1 pr-2.5 text-xs transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 ${n===t.addonId?`border-primary bg-primary/10 text-primary font-medium`:`border-border bg-surface text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[i(Le,{addonId:t.addonId,fallback:a,tileClassName:``,size:`sm`}),i(`span`,{className:`truncate`,children:t.name}),i(`span`,{className:`shrink-0 text-[10px] font-normal text-foreground-subtle`,children:t.count}),i(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${Re[t.health]}`,"aria-hidden":!0}),i(`span`,{className:`sr-only`,children:ze(s,t.health)})]},t.addonId))}),o!==void 0&&e(L,{to:ae(o.capability),className:`inline-flex min-w-0 max-w-full items-center gap-1.5 rounded-full border py-1 pl-1 pr-2.5 text-xs transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 border-dashed border-border pl-2 text-foreground-subtle hover:border-primary/50 hover:text-foreground`,children:[i(ee,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),i(`span`,{className:`truncate`,children:o.label})]})]})})}function Ve({providers:t,title:n,onPick:r,onCancel:a}){let{t:o}=F();return e(se,{open:!0,onClose:a,title:n,width:`lg`,children:[i(`p`,{className:`mb-3 text-xs text-foreground-muted`,children:o(`providerInstances.pickProvider`,`Choose which provider the new one belongs to.`)}),i(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:t.map(t=>e(`button`,{type:`button`,onClick:()=>r(t.addonId),className:`flex flex-col items-start gap-1 rounded-lg border border-border bg-surface px-3 py-3 text-left text-xs transition-colors hover:border-primary/50 hover:bg-surface-hover`,children:[i(`span`,{className:`font-medium text-foreground`,children:t.name}),t.description.length>0&&i(`span`,{className:`line-clamp-2 text-[11px] text-foreground-subtle`,children:t.description})]},t.addonId))})]})}function He(e){let t=T({onSuccess:e.onSuccess});return{mutate:e=>t.mutate({...e}),isPending:t.isPending}}s();var Ue=`instance`;function We(e){let t=[e.status?.detail,e.lastCheckedAt===void 0?void 0:new Date(e.lastCheckedAt).toLocaleString()].filter(e=>e!==void 0&&e.length>0);return t.length>0?t.join(` · `):void 0}function Ge({row:t}){let{t:n}=F();return t.enabled?e(`span`,{className:`flex flex-wrap items-center gap-1`,children:[i(x,{variant:t.configured?`success`:`default`,children:t.configured?n(`providerInstances.configured`,`Configured`):n(`providerInstances.notConfigured`,`Not configured`)}),t.status!==void 0&&i(x,{variant:t.status.state===`error`?`danger`:t.status.state===`ok`?`success`:`default`,title:We(t),children:B(t.status)})]}):i(`span`,{className:`flex flex-wrap items-center gap-1`,children:i(x,{variant:`default`,children:n(`providerInstances.off`,`Off`)})})}function Ke({row:t,pinning:n}){let{t:r}=F(),a=l(),o=He({onSuccess:()=>void a.invalidateQueries({queryKey:[R]})});return e(`span`,{className:`flex flex-col gap-1`,children:[i(k,{checked:t.enabled,disabled:o.isPending,"aria-label":r(`providerInstances.enable`,`Enable {{name}}`,{name:t.name}),onCheckedChange:e=>o.mutate({addonId:t.addonId,id:t.id,enabled:e})}),n>0&&i(`span`,{className:`text-[11px] text-foreground-subtle`,children:r(`providerInstances.pinnedBy`,{count:n})})]})}function qe({row:e,functionCap:t}){let{t:n}=F(),r=l(),a=M({onSuccess:()=>void r.invalidateQueries()});return i(k,{checked:e.isActive,disabled:a.isPending,"aria-label":n(`providerInstances.enable`,`Enable {{name}}`,{name:e.providerName}),onCheckedChange:n=>a.mutate({capName:t,addonId:e.addonId,enabled:n})})}function Je({functionCap:t,icon:a,title:s,subtitle:c,emptyTitle:d,emptyDescription:f,addLabel:h,install:g,extraColumns:_,lead:v,rowActions:ae,canDelete:b,pageActions:se,typedId:S,rowFilter:C}){let{t:w}=F(),T=re(),E=l(),D=ne(),O=ve(t),k=me({editKey:Ue,newKey:`${Ue}-new`}),[A,M]=o(null),[P,I]=o(null),L=ue({functionCap:`notification-output`}),B=r(e=>be(L.data??[],e).length,[L.data]),[we,Te]=o(null),[V,De]=o(null),H=n(()=>ye(O.holders),[O.holders]),U=n(()=>Ce(O.functionProviders,O.rows,O.displayNames),[O.functionProviders,O.rows,O.displayNames]),W=U.some(e=>e.addonId===V)?V:null,Oe=n(()=>{let e=he(O.rows,W);return C===void 0?e:e.filter(C)},[O.rows,W,C]),G=r(e=>O.displayNames.get(e)??e,[O.displayNames]),K=r(async e=>{M(e.key),I(null);try{let t=await T.trpcClient.integrationInstances.testInstance.mutate({addonId:e.addonId,id:e.id,values:{}});I({name:e.name,verdict:Se(t)})}catch(t){let n=t instanceof Error?t.message:String(t);I({name:e.name,verdict:{status:`inconclusive`,error:n}})}finally{M(null)}},[T]),q=r(async e=>{let t=be(L.data??[],e.id),n=t.length>0?` ${w(`providerInstances.deletePinned`,`These notification targets use it and will stop delivering: {{names}}.`,{names:t.join(`, `)})}`:``;if(await D({title:w(`providerInstances.deleteTitle`,`Delete {{name}}?`,{name:e.name}),message:`${w(`providerInstances.deleteMessage`,`The record and its stored credentials are removed.`)}${n}`,confirmLabel:w(`common.delete`,`Delete`),variant:`danger`}))try{await T.trpcClient.integrationInstances.deleteInstance.mutate({addonId:e.addonId,id:e.id}),await E.invalidateQueries({queryKey:[R]})}catch(t){Ee({title:w(`providerInstances.deleteFailed`,`Could not delete`),message:`${e.name}: ${t instanceof Error?t.message:String(t)}`,severity:`critical`})}},[D,E,T,w,L.data]),J=n(()=>O.rows.some(e=>e.kind===`instance`&&e.kindLabel!==void 0),[O.rows]),Y=r((e,t)=>{e!==void 0&&_e(ge(e,t),()=>{E.invalidateQueries({queryKey:[R]})})},[E]),X=n(()=>[{key:`name`,nowrap:!1,header:w(`providerInstances.colName`,`Name`),sortValue:e=>e.name,render:t=>e(`span`,{className:`flex flex-col`,children:[i(`span`,{className:`font-medium ${t.kind===`instance`&&!t.enabled?`text-foreground-muted`:`text-foreground`}`,children:t.name}),t.kind===`fixed`&&t.description.length>0&&i(`span`,{className:`line-clamp-2 text-[11px] text-foreground-subtle`,title:t.description,children:t.description})]})},{key:`provider`,header:w(`providerInstances.colProvider`,`Provider`),sortValue:e=>e.providerName,render:e=>i(`span`,{className:`text-foreground-muted`,children:e.providerName})},...J?[{key:`kind`,header:w(`providerInstances.colKind`,`Kind`),sortValue:e=>e.kind===`instance`?e.kindLabel??``:``,render:e=>i(`span`,{className:`text-foreground-muted`,children:e.kind===`instance`?e.kindLabel??``:``})}]:[],{key:`state`,header:w(`instances.colStatus`,`Status`),notSortableReason:w(`providerInstances.stateNotSortable`,`A row carries a badge, not a value to order by.`),render:e=>e.kind===`instance`?i(Ge,{row:e}):i(x,{variant:e.isActive?`success`:`default`,children:e.isActive?w(`instances.active`,`Active`):w(`providerInstances.off`,`Off`)})},{key:`on`,header:w(`providerInstances.colOn`,`On`),notSortableReason:w(`providerInstances.onNotSortable`,`A switch is not a value to order by.`),render:e=>e.kind===`fixed`?i(qe,{row:e,functionCap:t}):i(Ke,{row:e,pinning:B(e.id)})},..._??[],{key:`actions`,align:`right`,notSortableReason:w(`providerInstances.actionsNotSortable`,`Row actions are not values.`),render:t=>e(`span`,{className:`inline-flex items-center gap-1`,children:[t.kind===`instance`&&t.connectPath!==void 0&&i(j,{icon:ie,variant:`ghost`,size:`sm`,"aria-label":w(`providerInstances.connectRow`,`Connect {{name}}`,{name:t.name}),onClick:()=>Y(t.connectPath,t.id)}),t.kind===`instance`&&t.disconnectPath!==void 0&&i(j,{icon:oe,variant:`ghost`,size:`sm`,"aria-label":w(`providerInstances.disconnectRow`,`Disconnect {{name}}`,{name:t.name}),onClick:()=>Y(t.disconnectPath,t.id)}),t.kind===`instance`&&t.canTest&&i(j,{icon:A===t.key?y:p,variant:`ghost`,size:`sm`,"aria-label":w(`providerInstances.testRow`,`Test {{name}}`,{name:t.name}),disabled:A!==null,onClick:()=>void K(t)}),t.kind===`instance`&&ae?.(t),i(j,{icon:te,variant:`ghost`,size:`sm`,"aria-label":w(`providerInstances.editRow`,`Edit {{name}}`,{name:t.name}),onClick:()=>k.openEdit(z(t.addonId,t.kind===`instance`?t.id:void 0))}),i(ke,{iconOnly:!0,addonId:t.addonId,displayName:t.providerName,description:w(`providerInstances.restartConfirm`,`Restarts the addon on the hub. If it shares a runner group, every addon in that group restarts with it.`)}),t.kind===`instance`&&(b?.(t)??!0)&&i(j,{icon:m,variant:`ghost`,size:`sm`,"aria-label":w(`providerInstances.deleteRow`,`Delete {{name}}`,{name:t.name}),onClick:()=>void q(t)})]})}],[_,k,t,B,ae,b,q,Y,K,J,w,A]),Z;Z=O.state===`error`?i(`div`,{className:`p-3`,children:i(le,{title:w(`providerInstances.loadFailed`,`Could not load the list`),message:O.error??``,onRetry:O.refetch})}):O.state===`pending`?e(`div`,{className:`flex items-center gap-2 p-3 text-xs text-foreground-subtle`,children:[i(y,{className:`h-3 w-3 animate-spin`}),w(`providerInstances.loading`,`Loading…`)]}):O.rows.length===0?i(fe,{icon:a,title:d,description:f}):i(de,{columns:X,rows:Oe,rowKey:e=>e.key,bordered:!1,emptyMessage:w(`instances.noneForProvider`,`This provider has no instance yet.`)});let Q=O.holders.filter(e=>!H.includes(e)).map(e=>G(e.addonId)),$=H.length>0?void 0:Q.length>0?w(`instances.addBlocked`,`{{names}}: only one instance is allowed and it already exists.`,{names:Q.join(`, `)}):w(`instances.addNone`,`No provider here can hold instances.`);return e(ce,{headingId:`provider-instances-${t}`,title:s,icon:a,children:[i(`p`,{className:`px-3 pt-2 text-xs text-foreground-muted`,children:c}),O.state===`ready`&&$!==void 0&&i(`p`,{className:`px-3 pt-1 text-[11px] text-foreground-subtle`,children:$}),O.state===`ready`&&e(u,{children:[e(pe,{children:[se?.(O.rows.filter(e=>e.kind===`instance`)),e(N,{size:`sm`,variant:`primary`,disabled:$!==void 0,title:$,onClick:()=>{let e=H.find(e=>e.addonId===W)??(H.length===1?H[0]:void 0);e===void 0?k.openNew():k.openEdit(z(e.addonId,null))},children:[i(ee,{className:`h-3.5 w-3.5`}),h]})]}),i(Be,{pills:U,selected:W,onSelect:De,fallbackIcon:a,...g===void 0?{}:{install:g}})]}),Z,O.state===`ready`&&O.rows.length>0&&i(Ye,{rows:O.rows,selected:we,onSelect:Te}),P!==null&&e(`div`,{className:`space-y-1 p-3`,children:[i(`p`,{className:`text-[11px] font-medium text-foreground`,children:P.name}),i(xe,{verdict:P.verdict})]}),O.state===`ready`&&k.state.mode===`new`&&i(Ve,{title:h,providers:H.map(e=>({addonId:e.addonId,name:G(e.addonId),description:O.descriptions.get(e.addonId)??``})),onPick:e=>k.openEdit(z(e,null)),onCancel:k.close}),O.state===`ready`&&k.state.mode===`edit`&&i(Xe,{refValue:k.state.id,data:O,nameOf:G,onClose:k.close,onOpen:(e,t)=>k.openEdit(z(e,t)),...v===void 0?{}:{lead:v},...S===void 0?{}:{typedId:S}},k.state.id)]})}function Ye({rows:e,selected:t,onSelect:r}){let{t:a}=F(),o=n(()=>V(e),[e]),s=o[0];if(s===void 0)return null;let c=o.find(e=>e.addonId===t)??s;return i(`div`,{className:`p-3`,children:i(Ae,{addonId:c.addonId,switcher:o.length>1?i(`div`,{role:`group`,"aria-label":a(`providerInstances.activityProvider`,`Activity of`),className:`flex flex-wrap items-center gap-1`,children:o.map(e=>i(N,{variant:`unstyled`,type:`button`,"aria-pressed":e.addonId===c.addonId,onClick:()=>r(e.addonId),className:`rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${e.addonId===c.addonId?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.name},e.addonId))}):void 0})})}function Xe({refValue:e,data:t,nameOf:n,onClose:r,onOpen:a,lead:o,typedId:s}){let c=De(e);if(c.kind===`fixed`)return i(Me,{addonId:c.addonId,title:n(c.addonId),onClose:r});let l=t.holders.find(e=>e.addonId===c.addonId);if(l===void 0)return null;let u=c.kind===`instance`?l.instances.find(e=>e.id===c.id)??null:null;if(c.kind===`instance`&&u===null)return null;let d=t.rows.find(e=>e.kind===`instance`&&e.addonId===c.addonId&&e.id===u?.id);return i(Ze,{addonId:c.addonId,...o!==void 0&&d!==void 0?{lead:o(d)}:{},providerName:n(c.addonId),description:l.description,instance:u,onClose:r,onOpen:a,...s===void 0?{}:{typedId:s}})}function Ze(e){let{onOpen:n,onClose:r,onSaved:a,...o}=e,s=t(null),c=e.instance===null;return i(we,{...o,onSaved:e=>{c&&(s.current=e),a?.(e)},onClose:()=>{s.current===null?r():n(e.addonId,s.current)}})}export{Fe as a,Y as c,ke as d,W as f,Pe as i,G as l,Le as n,Ae as o,Ne as r,X as s,Je as t,Oe as u};
@@ -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-ywd6nvhM.js";import{bo as N,ls as P}from"./client-mCEzjXIR.js";import{t as F}from"./search-x-CyWzUJHP.js";import{Ao as I,Bo as L,Br as R,Cf as z,Co as B,Df as V,Eo as ee,Er as H,Fo as te,Fr as U,Ga as W,Go as G,Ir as ne,Jo as K,Jr as q,Js as re,Ka as ie,Kt as ae,Lo as oe,Oo as se,Po as J,Pr as Y,Qs as ce,Rr as le,So as ue,To as de,Ut as fe,Vn as pe,Ws as me,Wt as he,Xs as ge,Ys as _e,Zs as ve,_n as ye,af as be,bs as X,er as xe,fa as Se,i as Ce,ir as we,jn as Te,jo as Ee,lr as De,nr as Oe,ns as ke,r as Ae,rr as je,tr as Me,ts as Ne,ur as Pe,vi as Z,wo as Q,xi as Fe,xo as Ie,zr as Le}from"./src-DmG3r3oz.js";import{t as $}from"./useTranslation-BJr-n0es.js";import{n as Re}from"./addon-icons-context-C0tNs6xW.js";import{Br as ze,K as Be,Pr as Ve,Q as He,Rr as Ue,b as We,st as Ge,ut as Ke,x as qe,y as Je,zr as Ye}from"./index-DbICehF2.js";import{t as Xe}from"./useAdminDeviceRemoval-B3-kERGS.js";import{t as Ze}from"./device-integration-icon-DJJlbRLB.js";import{n as Qe,o as $e,t as et}from"./ScanSubnetEditor-D8DeFgGd.js";c();function tt(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...tt(n.fields));return t}function nt(e,t,i){let[a,s]=o(`idle`),[c,l]=o({}),u=n(()=>{let t=[];for(let n of e.sections)t.push(...tt(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 rt(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(...rt(n.fields));return t}function it(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function at(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){at(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function ot(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function st(e,t){let n=Ne({addonId:e,integrationId:t}),r=n.data?.deviceType??null,i=L({addonId:e,integrationId:t,type:r??N.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 ct({integrationId:t,addonId:s,onClose:c}){let{t:u}=$(),f=l(),[p,h]=o({}),[g,_]=o(!1),[v,y]=o(null),[b,x]=o(ot),S=Ne({addonId:s,integrationId:t},{enabled:!0}),T=S.data?.deviceType??null,E=L({addonId:s,integrationId:t,type:T??N.Camera},{enabled:S.isSuccess&&T!==null}),D=E.data??null;a(()=>{h(D?at(D.sections.flatMap(e=>e.fields)):{}),x(ot()),_(!1),y(null)},[!0,t,D]);let O=n(()=>({...p,_probeRequestId:b}),[p,b]),k=I({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),A=X(),P=r(async(e,t)=>{_(!0);let n=await A.mutateAsync({addonId:s,type:T??N.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??{}))it(e[i])&&!it(a)&&(r[i]=a,t=!0);return t?r:e}),n},[A,s,O,T]),{testAllStatus:F,hasProbeFields:R,probeResults:z,handleTestAll:B,clearProbeResult:V}=nt(D??{sections:[]},p,P);async function ee(e){y(null);try{await k.mutateAsync({addonId:s,type:T??N.Camera,config:p,integrationId:t}),e?h(D?at(D.sections.flatMap(e=>e.fields)):{}):c()}catch(e){y(e instanceof Error?e.message:String(e))}}let H=rt((D?.sections??[]).flatMap(e=>e.fields)).filter(e=>it(p[e])),te=H.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(Ve,{i18nKey:`integrations.addDeviceDialog.notReady`,values:{addonId:s},components:{mono:i(`span`,{className:`font-mono`})}})})]})]}):i(Ke,{schema:D,values:p,onChange:h,onTestField:P,probeResults:z,onClearProbe:V})}),!G&&!W&&e(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[e(Z,{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(ye,{addonId:s,requestId:b,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!G&&!W&&(v||H.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:H.join(`, `)})})]})}),e(le,{className:`justify-between`,children:[e(`div`,{className:`flex items-center gap-2`,children:[i(Z,{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&&R&&e(Z,{variant:`unstyled`,type:`button`,onClick:B,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(Z,{variant:`unstyled`,onClick:()=>ee(!0),disabled:G||!te||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(Z,{variant:`unstyled`,onClick:()=>ee(!1),disabled:G||!te||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 lt=1500;function ut({addonId:t,integrationId:n,jobId:r,onFinished:a}){let{t:o}=$(),s=ue(),c=(de({addonId:t,integrationId:n},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?lt:!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(Z,{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 dt(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($e(t),0)}function ft(e){let t=e.metadata?.model,n=e.childNativeId.split(`:`).pop()??``;return[typeof t==`string`?t:``,n].filter(e=>e.length>0).join(` · `)}function pt(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 mt=`devices`;function ht(e){return{id:mt,label:e(`integrations.adoptDevicesModal.defaultFilter`),isDefault:!0}}var gt=2e4,_t=100;function vt({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}=ge(),D=(E??[]).find(e=>e.addonId===s)?.supportsLocationImport??!1,[O,k]=o(!0),j=B({addonId:s,integrationId:c}).data?.filters,N=j&&j.length>0?j:[ht(p)],[P,F]=o(N.find(e=>e.isDefault)?.id??(N.some(e=>e.id===mt)?mt:N[0].id)),I=P!==mt,L=ee(),R=Q({addonId:s,integrationId:c,page:1,pageSize:gt,filter:P}),H=R.refetch,te=L.mutate,U=r(()=>{te({addonId:s,integrationId:c},{onSettled:()=>{H()}})},[te,s,c,H]),W=t(null);a(()=>{let e=`${s}::${c}`;W.current===e||R.isLoading||(W.current=e,(R.data?.candidates.length??0)===0&&U())},[s,c,R.isLoading,R.data,U]);let G=L.isPending,ne=L.isError?L.error instanceof Error?L.error.message:String(L.error):null,K=typeof L.data?.lastError==`string`&&L.data.lastError.length>0?L.data.lastError:null,q=R.data?.candidates??[],re=n(()=>dt(q),[q]),ie=n(()=>new Map(re.map(e=>[e.candidate.childNativeId,e.depth])),[re]),ae=n(()=>new Map(re.map(e=>[e.candidate.childNativeId,e.parentName])),[re]),oe=R.isError?R.error instanceof Error?R.error.message:String(R.error):null,J=se(),[Y,ce]=o(null),ue=r(e=>{e.alreadyAdopted||_(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),de=r(e=>{y(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),pe=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})},[]),me=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]),he=r(async()=>{T(null);let e=[...h];if(e.length!==0)try{let t=me(e),{jobId:n}=await J.mutateAsync({addonId:s,integrationId:c,filter:P,childNativeIds:e,...t?{perCandidate:t}:{},...D?{importLocations:O}:{}});ce(n),_(new Set),S(new Map)}catch(e){T(e instanceof Error?e.message:String(e))}},[h,me,J,s,c,P,D,O]),_e=t(null),ve=r(()=>{Y===null||_e.current===Y||(_e.current=Y,H(),m.invalidateQueries({queryKey:[[`integrations`]]}),m.invalidateQueries({queryKey:[[`deviceManager`]]}))},[Y,H,m]),ye=r(e=>{F(e),_(new Set),y(new Set),S(new Map),T(null)},[]),be=h.size,X=Y!==null&&be===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(De,{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:[(ne??oe??K)&&q.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:ne??oe??K})]})]})}),N.length>1&&i(yt,{filters:N,activeFilter:P,onSelect:ye}),i(`div`,{className:`flex-1 min-h-0`,children:i(fe,{mode:`generic`,items:re.map(e=>e.candidate),pageSize:_t,getKey:e=>e.childNativeId,getSearchText:pt,getFilterType:e=>e.type,filterOptions:z(f),filterLabel:p(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:R.isLoading||G&&q.length===0,searchPlaceholder:p(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(ne??oe??K)&&q.length===0?``:p(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:e(Z,{variant:`unstyled`,type:`button`,onClick:U,disabled:G,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 ${G?`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(bt,{candidate:e,depth:ie.get(e.childNativeId)??0,...ae.get(e.childNativeId)===void 0?{}:{containerName:ae.get(e.childNativeId)},expandable:!I,expanded:v.has(e.childNativeId),onToggleExpand:()=>de(e.childNativeId),adoptedLabel:p(`integrations.adoptAlready`,{defaultValue:`Adopted`}),typeLabel:V(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=V(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(Z,{variant:`unstyled`,onClick:()=>ue(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(xt,{candidate:e,hiddenChildIds:x.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>pe(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(ut,{addonId:s,integrationId:c,jobId:Y,onFinished:ve}),e(le,{children:[i(Z,{variant:`outline`,size:`sm`,onClick:u,children:p(`integrations.cancel`,{defaultValue:`Cancel`})}),e(Z,{variant:`primary`,size:`sm`,onClick:X?u:he,disabled:!X&&(be===0||J.isPending),children:[J.isPending&&i(M,{className:`h-3.5 w-3.5 animate-spin`}),X?p(`integrations.close`,{defaultValue:`Close`}):p(`integrations.addSelected`,{defaultValue:`Add selected`}),!X&&be>0?` (${be})`:``]})]})]})}function yt({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(Z,{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 bt({candidate:t,depth:n,containerName:r,expandable:a,expanded:o,onToggleExpand:s,adoptedLabel:c,typeLabel:l}){let{t:u}=$(),d=(t.children??[]).length,f=ft(t);return e(`div`,{className:`flex items-center gap-2.5 min-w-0 ${n>0?`pl-5`:``}`,children:[a&&d>0?e(Z,{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 xt({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(Z,{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 St(e){let t=e.host;return typeof t==`string`&&t.length>0?t.toLowerCase():null}function Ct(e){return e===null?[]:[`host:${e}`]}function wt(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=St(t.prefilledConfig),s=r([t.stableId,...Ct(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 Tt=500;function Et(e){return e instanceof Error?e.message:String(e)}function Dt(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 Ot({addonId:t,integrationId:a,onClose:s,onSetupIntegration:c,alongsideAdoption:u=!1}){let{t:f}=$(),p=l(),m=ke({addonId:t}).data??null,[h,g]=o({}),_=J(),v=K({}),b=Q({addonId:t,integrationId:a,page:1,pageSize:Tt},{retry:!1}),{data:x}=G({projection:`slim`}),S=Ie(),C=se(),[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 wt({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(Et(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=Qe(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(jt,{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 ee=F.length===0,H=e(d,{children:[i(et,{}),m&&i(Ke,{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(Z,{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(kt,{text:f(`integrations.addDeviceModal.scanFailed`,`The scan failed. Try again.`)}),O!==null&&i(kt,{text:O}),ee&&!_.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(At,{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:H}):e(d,{children:[i(U,{className:`space-y-3`,children:H}),i(le,{children:i(Z,{variant:`outline`,size:`sm`,onClick:s,children:f(`integrations.close`,`Close`)})})]})}function kt({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 At({row:t,depth:n,busy:r,added:a,onPick:o}){let{t:s}=$(),c=t.alreadyAdded||a,l=t.hit!==null&&Qe(``,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(Z,{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 jt({addonId:t,integrationId:n,row:r,found:a,busy:s,error:c,onBack:l,onSubmit:u,embedded:f}){let{t:p}=$(),m=Ne({addonId:t,integrationId:n}),h=m.data?.deviceType??null,g=L({addonId:t,integrationId:n,type:h??N.Camera},{enabled:m.isSuccess&&h!==null}),_=g.data??null,[v,y]=o(null),b=v??Dt(_,a),x=m.error??g.error,S=m.isSuccess&&h===null,C=_!==null,w=C?i(Ke,{schema:_,values:b,onChange:y}):x?i(kt,{text:Et(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(Z,{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(kt,{text:c})]}),E=e(d,{children:[i(Z,{variant:`outline`,size:`sm`,onClick:l,children:p(`integrations.cancel`,`Cancel`)}),e(Z,{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(le,{children:E})]})}c();function Mt(e){return e===`manual`?`manual`:e===`pairing`?`pairing`:`network`}function Nt({addonId:t,integrationId:n,kind:r,canScan:a,onClose:s,pairing:c,onSetupIntegration:l}){let{t:u}=$(),f=st(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(Ot,{addonId:t,integrationId:n,onClose:s,alongsideAdoption:!0,...l?{onSetupIntegration:l}:{}}),i(vt,{addonId:t,integrationId:n,onClose:s})]}):i(Ot,{addonId:t,integrationId:n,onClose:s,...l?{onSetupIntegration:l}:{}}),x=i(ct,{integrationId:n,addonId:t,onClose:s});return i(Y,{open:!0,onOpenChange:e=>{e||s()},children:e(ne,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,className:r===`device-adoption`?`md:h-[85vh]`:void 0,children:[i(Le,{children:i(R,{children:u(`integrations.addDevice`,`Add device`)})}),y>1?e(xe,{value:v,onValueChange:e=>_(Mt(e)),children:[e(Oe,{children:[m&&i(je,{value:`network`,children:u(`integrations.addDeviceModal.tabNetwork`,`Found on the network`)}),h&&i(je,{value:`manual`,children:u(`integrations.addDeviceModal.tabManual`,`Enter parameters`)}),c!==void 0&&i(je,{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 Pt=`matter`,Ft=[`discovering`,`pase`,`commissioning`,`done`];function It(e){return!(typeof e!=`object`||!e||!(`phase`in e)||typeof e.phase!=`string`)}function Lt(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 Rt({onClose:t,onCommissioned:n}){let{t:r}=$(),s=Ce({kind:Pt}),[c,l]=o(null),u=Ae(s.data??[],c),f=u.length,p=c??u[0]?.id??null,m=ie(),[h,g]=o(``),[_,v]=o({phase:`idle`,failure:null,message:null}),y=_.phase===`discovering`||_.phase===`pase`||_.phase===`commissioning`,b=W({brokerId:p??``,key:`commission`},{enabled:p!==null&&y,refetchInterval:y?400:!1});a(()=>{y&&It(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`?Lt(_.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(Pe,{children:r(`integrations.addMatter.broker`,{defaultValue:`Matter fabric`})}),i(Be,{kind:Pt,value:p,onChange:l})]}),!w&&e(`div`,{className:`space-y-1.5`,children:[i(Pe,{htmlFor:`matter-pairing-code`,children:r(`integrations.addMatter.code`,{defaultValue:`Pairing code`})}),i(be,{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:Ft.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(q,{message:C})]}),e(le,{children:[i(Z,{variant:`ghost`,size:`sm`,onClick:t,children:r(`common.close`,{defaultValue:`Close`})}),_.phase===`done`?i(Z,{size:`sm`,onClick:n,children:r(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}):i(Z,{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 zt(e){return typeof e!=`object`||!e||!(`sections`in e)?!1:Array.isArray(Reflect.get(e,`sections`))}function Bt(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 Vt({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})}),_=Bt(g.data),v=zt(h.data)?h.data:null,y=h.isSuccess&&g.isSuccess;return i(Y,{open:!0,onOpenChange:e=>!e&&d(),children:e(ne,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(Le,{children:e(R,{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(Ht,{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 Ht({addonId:t,integrationId:n,name:r,schema:a,stored:s,onClose:c,onSaved:l}){let{t:d}=$(),f=k(),[p,m]=o({...s}),h=P(a,{...s}),g=u({mutationFn:async()=>{let e=He(s,p);await f.trpcClient.integrationInstances.updateInstance.mutate({addonId:t,id:n,values:e})},onSuccess:()=>{l(),Ge({title:d(`integrations.saved`,{defaultValue:`Configuration saved`}),message:r,severity:`info`}),c()},onError:e=>{Ge({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(H,{schema:h,values:p,onChange:m}),e(`div`,{className:`flex justify-end gap-2`,children:[i(Z,{size:`sm`,variant:`outline`,type:`button`,onClick:c,children:d(`common.cancel`,{defaultValue:`Cancel`})}),e(Z,{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`})]})]})]})}c();function Ut(){let{addonId:e=``}=Ye();return i(Gt,{addonId:e})}function Wt(){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 Gt({addonId:t}){let{t:c}=$(),u=l(),d=Ue(),[f,m]=ze(),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}=ve(void 0),A=n(()=>(O??[]).filter(e=>e.addonId===t),[O,t]),j=qe(f.get(`instance`),A)??``,N=r(e=>{m(t=>{let n=new URLSearchParams(t);return n.set(Je,e),n},{replace:!0})},[m]),P=n(()=>A.map(e=>({value:e.id,label:e.name})),[A]),{data:I,isLoading:L}=_e({id:j},{enabled:!!j}),{data:z,isSuccess:B}=ge(),V=n(()=>{let e=I?.addonId;return!e||!B?null:(z??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[z,I?.addonId,B]),{data:ee,isPending:H}=te({}),W=n(()=>H?null:(ee?.providers??[]).some(e=>e.addonId===I?.addonId),[H,ee,I?.addonId]),K=V!==null,q=I?.info?.fixed===!0,ie=n(()=>{let e=I?.addonId;return!e||!B?null:(z??[]).find(t=>t.addonId===e)?.brokerKind??null},[z,I?.addonId,B]),se=ie===`matter`,J=K?c(`integrations.addDevice`,`Add device`):c(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),le=n(()=>{let e=I?.addonId;return!e||!B?!1:(z??[]).find(t=>t.addonId===e)?.canTest===!0},[z,I?.addonId,B]),ue=n(()=>{let e=I?.addonId;return!e||!B?null:(z??[]).find(t=>t.addonId===e)?.mode??null},[z,I?.addonId,B]);a(()=>{f.get(`add`)===`1`&&K&&(v(!0),m(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[f,K,m]);let{data:de}=s({queryKey:[`integration-instance-form`,I?.addonId,I?.id],enabled:!!I?.addonId&&!!I?.id,queryFn:()=>g.trpcClient.integrationInstances.instanceFormSchema.query({addonId:I?.addonId??``,id:I?.id??``})}),be=de!=null&&Array.isArray(de.sections)&&de.sections.some(e=>e.fields.length>0),{data:X}=G({projection:`slim`},{refetchInterval:3e4}),xe=[[`integrations`,`get`],{input:{id:j},type:`query`}],Ce={onMutate:async e=>{await u.cancelQueries({queryKey:xe});let t=u.getQueryData(xe);return t!=null&&u.setQueryData(xe,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&u.setQueryData(xe,r.previous)},onSettled:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}},De=ce(Ce),Oe=me(Ce),ke={isPending:De.isPending||Oe.isPending,mutate:e=>q?De.mutate(e):Oe.mutate({...e,addonId:I?.addonId})},Ae=re({onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]}),d(A.length>1?We(t):`/integrations`)}}),je=Se({onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Me=Xe(),Ne=Ee({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Pe=oe({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=n(()=>X??[],[X]),Ie=n(()=>{let e=new Map;for(let t of Q)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[Q]),Re=r(e=>Ie.get(e)??null,[Ie]),Be=n(()=>he(O),[O]),Ve=r(e=>d(`/devices/${String(e)}`),[d]),He=n(()=>Q.filter(e=>{let t=Be(e);return t.kind===`resolved`&&t.integration.id===j}),[Q,j,Be]),Ge=n(()=>O===void 0?null:ae(He).length,[O,He])??`…`;if(L||O===void 0)return i(Wt,{});let Ke=(z??[]).find(e=>e.addonId===t)?.name??I?.name??t;return I?e(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[i(pe,{items:[{label:c(`integrationDetail.integrations`,`Integrations`),onClick:()=>d(`/integrations`)},{label:Ke}]}),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(Kt,{addonId:I.addonId}),e(`div`,{className:`min-w-0`,children:[i(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:Ke}),e(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[Ge,` `,c(`integrations.devices`)]})]})]}),e(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[!q&&e(Z,{variant:`unstyled`,onClick:()=>{v(!0)},disabled:!K,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:J,children:[i(T,{className:`h-3.5 w-3.5`}),J]}),e(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${ke.isPending?`opacity-60`:``} ${I.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:c(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[i(we,{checked:I.enabled,onCheckedChange:e=>ke.mutate({id:j,enabled:e}),disabled:ke.isPending,"aria-label":I.enabled?c(`integrationDetail.disableIntegration`,`Disable integration`):c(`integrationDetail.enableIntegration`,`Enable integration`)}),i(`span`,{className:`text-[11px] font-medium ${I.enabled?`text-success`:`text-foreground-subtle`}`,children:I.enabled?c(`integrationDetail.enabled`,`Enabled`):c(`integrationDetail.disabled`,`Disabled`)}),ke.isPending&&i(M,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),ue!==`standalone`&&(be||V===`device-adoption`)&&e(Z,{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(Z,{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(Te,{label:c(`integrationDetail.restart`,`Restart`),icon:p,title:c(`integrationDetail.restart2`,`Restart "{{name}}"?`,{name:I.name}),description:c(`integrationDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device backed by it ({{topLevelCountLabel}} active). Streams will reconnect automatically.`,{topLevelCountLabel:Ge}),confirmLabel:c(`integrationDetail.restart`,`Restart`),triggerVariant:`outline`,confirmVariant:`danger`,disabled:je.isPending,action:()=>je.mutateAsync({addonId:I.addonId})}),!q&&j&&i(Te,{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:I.name,count:Ge}),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:Ae.isPending,action:()=>Ae.mutateAsync({id:j})})]})]}),A.length>1&&i(`div`,{className:`max-w-sm`,children:i(Fe,{mode:`single`,singleDisplay:`field`,label:c(`integrationDetail.instances`,`Integration`),options:P,value:j,onChange:N,testId:`integration-instance-picker`,optionTestIdPrefix:`integration-instance`})}),i(fe,{context:`integration-detail`,devices:Q,trpc:g.trpcClient,integrationOf:Be,forceIntegrationId:j,urlScope:`root`,lsKey:`integration-detail:${I.addonId}`,resolveIntegrationIcon:Ze,resolveParent:Re,onNavigate:Ve,rowOperation:Me.rowOperation,batchActions:{remove:Me.remove,disable:Ne.mutate,enable:Pe.mutate},...q?{}:{onDeleteDevice:e=>Me.remove({deviceId:e.id})}}),_&&j&&V!==null&&i(Nt,{addonId:I.addonId,integrationId:j,kind:V,canScan:W,onSetupIntegration:y,...se?{pairing:{label:c(`integrations.addMatter.tab`,`Pairing code`),render:({onPaired:e})=>i(Rt,{onClose:()=>v(!1),onCommissioned:e})}}:{},onClose:()=>v(!1)}),b&&j&&V!==null&&ue!==null&&i(Vt,{integrationId:j,addonId:I.addonId,name:I.name,kind:V,mode:ue,brokerKind:ie,canTest:le,onClose:()=>x(!1)}),w&&i(Y,{open:!0,onOpenChange:e=>!e&&E(!1),children:e(ne,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[i(Le,{className:`mb-0`,children:e(R,{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:I.name}),e(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate font-normal`,children:[I.addonId,j?` · ${j}`:``]})]})}),i(U,{className:`min-h-0 overflow-hidden p-0`,children:i(ye,{addonId:I.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(Z,{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 Kt({addonId:e}){let t=Re(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{Ut as IntegrationDetailPage};
@@ -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-ywd6nvhM.js";import{Si as m,cn as ee}from"./client-mCEzjXIR.js";import{D as h,N as g,O as _,v}from"./__vite-browser-external-BCAtXlNQ.js";import{y}from"./video-BvnxG-kU.js";import{Br as b,Bt as x,Ei as te,Fr as ne,Ht as re,Ir as S,Pr as C,Qi as w,Vt as T,mo as E,oa as D,of as O,sa as k,vi as A,zr as j}from"./src-DmG3r3oz.js";import{t as M}from"./i18n-C6fCBciG.js";import{t as N}from"./useTranslation-BJr-n0es.js";import{Br as P,J as F,S as I,i as L}from"./index-DbICehF2.js";import{t as R}from"./AdminSectionedPage-DwIVrzMv.js";import{f as z,t as B}from"./InstancesTable-CmdXLlKr.js";import{n as V,t as ie}from"./IntegrationHub-B9BtSaMu.js";a();function H(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 U(e){let t=e,n=t?.manifest;if(n?.id===void 0)return null;let r=(n.capabilities??[]).map(H).filter(e=>e!==null);return{addonId:n.id,displayName:n.packageDisplayName??n.name??n.id,capNames:r,processState:t?.process?.state??null}}function W(e,t){return Object.entries(e).filter(([,e])=>e===t).map(([e])=>e)}function G(e,t){return t.find(t=>e.capNames.includes(t))??null}function K(e){switch(e){case`running`:return{state:`ok`,label:M.t(`helpers.connectivityModel.running`)};case`crashed`:case`failed`:return{state:`error`,label:e};case`stopped`:case`disabled`:return{state:`off`,label:M.t(`helpers.connectivityModel.stopped`)};default:return{state:`unknown`,label:e??M.t(`common.unknownWord`)}}}var q=1e4;function J({row:t}){let{t:r}=N(),[a,o]=i(!1),c=t.kind===`instance`?t.id:void 0,{data:l}=E({addonId:t.addonId,...c===void 0?{}:{instanceId:c}},{refetchInterval:q,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(A,{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(j,{children:n(b,{children:r(`system.connectivity.devicesDialogTitle`,`Devices of {{name}}`,{name:t.name})})}),n(ne,{children:c===void 0?n(T,{addonId:t.addonId,showSetup:!1}):n(x,{addonId:t.addonId,instance:{instanceId:c,name:t.name,enabled:!0},showSetup:!1})})]})})]})}function Y(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(J,{row:e})}}function ae({addonId:e,instanceId:t}){return n(re,{addonId:e,instanceId:t})}var X=`waste-collections`,Z=_({refreshed:v(_({sourceId:g(),entryCount:h().int(),error:g().optional()}))});function oe({row:e}){let{t}=N(),r=f(),i=o(),a=w({onSuccess:async n=>{let a=Z.safeParse(n),o=a.success?a.data.refreshed[0]:void 0;if(i.invalidateQueries({queryKey:[F]}),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:X,action:`fetchNow`,input:{sourceId:e.id}})})}function se(e){return e.addonId===X?n(oe,{row:e}):null}function ce(){let{t}=N(),r=f(),i=o(),a=w({onSuccess:async e=>{let n=Z.safeParse(e);i.invalidateQueries({queryKey:[F]});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(A,{size:`sm`,variant:`secondary`,disabled:a.isPending,onClick:()=>a.mutate({addonId:X,action:`fetchNow`,input:{}}),children:[n(d,{className:`h-3.5 w-3.5`}),t(`wasteFetchNow.all`,`Fetch all now`)]})}function le(e){return e.some(e=>e.addonId===X)?n(ce,{}):null}a();var Q=1e4,ue={"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=>[Y(e)],lead:e=>n(ae,{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:se,pageActions:le}}];function fe(e,t,r){let i=W(ee,e.kind),a=t.flatMap(t=>{let r=G(t,i);if(r===null)return[];let a=K(t.processState);return[{id:t.addonId,name:t.displayName,fallbackIcon:e.icon,state:a.state,stateLabel:a.label,render:()=>n(V,{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=k({capName:`integration-instances`},{refetchInterval:Q});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}=N(),o=t(()=>fe(e,r,a),[e,r,a]);return n(ie,{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}=N(),i=D(void 0,{refetchInterval:Q}),[a,o]=P(),s=I(`/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=ue[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(U).filter(e=>e!==null),[i.data]),u=t(()=>de.map(t=>{let r=t.instances,a=r===void 0?null:n(B,{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:L,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(R,{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}=K(e);return n(te,{variant:t===`ok`?`success`:t===`error`?`danger`:`default`,className:`${z} capitalize`,children:r})}export{he as IntegrationsPage};
@@ -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-ywd6nvhM.js";import{_s as O,hs as k}from"./client-mCEzjXIR.js";import{t as ee}from"./table-2-Cjb75Gi9.js";import{Br as A,Fo as te,Fr as ne,Go as re,Gs as j,Io as M,Ir as ie,Jo as ae,Jr as oe,Ki as se,Kt as ce,Mo as le,No as ue,Po as de,Pr as fe,Qi as pe,Us as me,Ut as he,W as ge,Wt as _e,Xs as ve,Zs as ye,_t as N,a as be,af as P,lr as F,ns as I,oa as xe,qs as Se,vi as L,xo as Ce,zr as R}from"./src-DmG3r3oz.js";import{t as z}from"./i18n-C6fCBciG.js";import{t as B}from"./useTranslation-BJr-n0es.js";import{Br as we,K as V,Lr as H,Rr as Te,W as U,b as Ee,ct as De,lt as Oe,ut as W}from"./index-DbICehF2.js";import{t as ke}from"./AdminPage-CQKqrawX.js";import"./useEventInvalidation-D7WYy-h_.js";import{t as Ae}from"./device-integration-icon-DJJlbRLB.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-D8DeFgGd.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(P,{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(V,{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=ue(),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=j({onSuccess:e=>S(Oe(e)),onError:e=>S({status:`inconclusive`,error:String(e)})}),w=pe(),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(P,{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:[...k(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=Te(),[f,p]=o(``),m=t(null),{data:h,isLoading:g}=ve();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}=xe(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(P,{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=Ce(),[f,p]=o(new Set),[m,h]=o(new Set),[g,v]=o(new Set),{data:y}=re({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(fe,{open:t,onOpenChange:e=>!e&&a(),children:e(ie,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(R,{children:i(A,{children:e(`span`,{className:`flex items-center gap-2`,children:[i(_,{className:`h-4 w-4 text-primary`}),E]})})}),e(ne,{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(F,{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=le(),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=de(),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=Te(),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),[O,k]=o(null),[ee,re]=o(!1),[j,M]=o({}),[ae,oe]=o(``),[ce,le]=o(!1),[de,pe]=o(0),[he,ge]=o(``),_e=te({},{enabled:t&&p===`config`}),ye=(me({addonId:h??``},{enabled:t&&p===`config`&&h!==null}).data?.kinds??[]).filter(e=>e.canTest!==!1),N=ye.length===1?ye[0]?.id:void 0,be=h!==null&&(_e.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&&ae!==F&&(oe(F),g(s.addonId),w(s.name),M({...s.config}),m(`config`));let I=ve(void 0,{enabled:t&&s!==null}),xe=I.data?.find(e=>e.addonId===h)?.mode??`account`,{data:z}=se({addonId:h??``,nodeId:`hub`,instance:{integrationId:null,mode:xe,...s?.originStableId===void 0?{}:{candidateStableId:s.originStableId}}},{enabled:h!=null}),we=n(()=>z?yt(z):null,[z]),V=Se({onSuccess:()=>f.invalidateQueries({queryKey:[[`integrations`]]})}),H=ue(),U=H.data;a(()=>{if(!t||s===null)return;let e=I.data?.find(e=>e.addonId===s.addonId);e&&(re(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=Ce({onSuccess:()=>f.invalidateQueries({queryKey:[[`deviceManager`]]})});function Oe(e,t,n,r,i,a,o,s){if(!V.isPending){if(g(e),re(s),b(n),w(r),k(null),V.reset(),o===`broker`){if(!a){k(`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),k(null),V.reset(),re(!1),M({}),oe(``)}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(fe,{open:!0,onOpenChange:e=>{!e&&!Pe&&q()},children:e(ie,{width:p===`picker`?`xl`:`lg`,scroll:`body`,onCancel:e=>{Pe&&e.preventDefault()},children:[i(R,{children:i(A,{children:Me[p]})}),e(ne,{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:[O&&i(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:O}),i(ot,{onSelect:Oe,onClose:q,pendingAddonId:Ne})]}),p===`config`&&h&&i(rt,{addonId:h,configSchema:we??null,canTest:ee,...N===void 0?{}:{instanceKind:N},initialName:C.length>0&&Object.keys(j).length>0?C:void 0,initialConfig:{...j},onScan:be?()=>{ge(C.length>0?C:h),le(!0)}:void 0,onSave:ke,onBack:()=>{M({}),m(`picker`)}},`${F.length>0?F:h}:${de}`),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`})})]})]})]})}),ce&&h!==null&&i(st,{open:ce,scope:{addonId:h,label:he},pickMode:`fill`,onClose:()=>le(!1),onSetupIntegration:e=>{w(e.name),M({...e.config}),pe(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=ae({},{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=Ce(),f=M(),[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(fe,{open:t,onOpenChange:e=>!e&&n(),children:e(ie,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(R,{children:i(A,{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(ne,{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=Te(),c=H(),d=T(),[p]=we(),[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=>{k(!1),x(e),v(!0)},[]),[O,k]=o(!1);a(()=>{let e=je(c.state);e!==null&&(x(e),v(!0),s(`/integrations`,{replace:!0,state:null}))},[c.state,s]);let A=p.get(`setup`);a(()=>{A===null||A.length===0||(x({addonId:A,name:A,config:{}}),v(!0))},[A]);let te=r(()=>k(!0),[]),ne=r(()=>k(!1),[]);be([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),be([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:j,isLoading:M,isError:ie,error:ae,errorUpdateCount:se,refetch:le}=ye(void 0,{refetchInterval:We}),{data:ue,isLoading:de,isError:fe,error:pe,errorUpdateCount:me,refetch:N}=re({projection:`slim`},{refetchInterval:We}),P=n(()=>ue??[],[ue]),F=n(()=>j??[],[j]),I=n(()=>{let e=new Map;for(let t of P)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[P]),Se=n(()=>_e(j),[j]),Ce=n(()=>{let e=new Map;for(let t of ce(P)){let n=Se(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[P,Se]),R=n(()=>F.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:Dt(e),deviceCount:Ce.get(e.id)??0})),[F,Ce]),{data:z}=ve(),V=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}=xe(void 0),W=n(()=>Ie(Oe),[Oe]),G=n(()=>Le(R,W),[R,W]),K=n(()=>Le(Pe(R,V),W),[R,V,W]),q=r(e=>s(Ee(e.addonId)),[s]),J=r(e=>s(Ee(e.addonId,e.id)),[s]),Y=r(e=>I.get(e)??null,[I]),Me=r(e=>s(`/devices/${String(e)}`),[s]),Ne=r(e=>i(he,{context:`integration-detail`,devices:P,trpc:d.trpcClient,integrationOf:Se,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:Ae,resolveParent:Y,onNavigate:Me}),[P,d.trpcClient,Se,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(he,{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(()=>{le(),N()},[le,N]),He=ie===!0&&Ue(ae,se),Ge=fe===!0&&Ue(pe,me),Ke=He||Ge,Q=ie===!0&&!He||fe===!0&&!Ge,$=!Q&&!Ke&&(M||de||j===void 0||ue===void 0),Je=F.length>0,Ye=[{id:`table`,label:t(`integrations.viewTable`,`Table`),icon:ee},{id:`grid`,label:t(`integrations.viewGrid`,`Grid`),icon:u}];return e(ke,{icon:y,title:t(`nav.integrations`,`Integrations`),actions:e(l,{children:[i(ge,{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:te,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:O,onClose:ne,onSetupIntegration:D})]})}export{kt as IntegrationsPage};