@camstack/addon-admin-ui 1.2.636 → 1.2.637

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 (195) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/assets/Addons-BlKy1u2u.js +5 -0
  3. package/dist/assets/{AdminPage-D13CJb8Q.js → AdminPage-_ITsYONa.js} +1 -1
  4. package/dist/assets/{AdminSectionedPage-BMFLLxeJ.js → AdminSectionedPage-Xr_hesYw.js} +1 -1
  5. package/dist/assets/AiProfiles-YERCq98T.js +3 -0
  6. package/dist/assets/{Authentication-Fcsaeo6T.js → Authentication-CWHj8Czl.js} +1 -1
  7. package/dist/assets/{Build-L6hr034C.js → Build-BmlbmwZw.js} +3 -3
  8. package/dist/assets/{Calendars-Sq4Gc6IV.js → Calendars-Bg6sl6iG.js} +1 -1
  9. package/dist/assets/{CameraGrids-SZQaxv-J.js → CameraGrids-BWF-BVdJ.js} +1 -1
  10. package/dist/assets/Cluster-BsLfi42d.js +1 -0
  11. package/dist/assets/CompositionBlockEditor-C0mH1XDD.js +2 -0
  12. package/dist/assets/{CompositionEditorPage-D9X-zVQH.js → CompositionEditorPage-5iKEcr6R.js} +1 -1
  13. package/dist/assets/Data-DSMQmnZv.js +2 -0
  14. package/dist/assets/DeviceDetail-kBF3z5wo.js +2 -0
  15. package/dist/assets/{Devices-DruLtWCC.js → Devices-DQ8VksMo.js} +1 -1
  16. package/dist/assets/EmbedDevicePage-DOj0N5Mn.js +1 -0
  17. package/dist/assets/{EmbedPlayerPage-BDyIh4lQ.js → EmbedPlayerPage-J9i3kCrj.js} +1 -1
  18. package/dist/assets/History-BFkKRlW8.js +1 -0
  19. package/dist/assets/Identity-5sx8SWa4.js +1 -0
  20. package/dist/assets/InstancesTable-BagVOERb.js +1 -0
  21. package/dist/assets/IntegrationDetail-ByG-grc8.js +1 -0
  22. package/dist/assets/Integrations-BReJ0gq9.js +1 -0
  23. package/dist/assets/{Integrations-D_D9IsZx.js → Integrations-DK9ZlSbS.js} +2 -2
  24. package/dist/assets/Library-CVdwKZBw.js +1 -0
  25. package/dist/assets/Locations-CDUPDAGA.js +3 -0
  26. package/dist/assets/{Logs-DPHzCD-k.js → Logs-qlrqjJUI.js} +1 -1
  27. package/dist/assets/{MaskShapeCanvas-ByGbdZex.js → MaskShapeCanvas-C_kXMOhj.js} +1 -1
  28. package/dist/assets/{MotionZonesSettings-CiobfarF.js → MotionZonesSettings-CarcYpLx.js} +1 -1
  29. package/dist/assets/MyAccess-sO6455Tp.js +2 -0
  30. package/dist/assets/Network-B-NGzfdC.js +1 -0
  31. package/dist/assets/{NodeAddonsSettingsPanel-8E1KZ_Zn.js → NodeAddonsSettingsPanel-BtSyXQ4v.js} +1 -1
  32. package/dist/assets/Notifications-BhHrfZKJ.js +1 -0
  33. package/dist/assets/Pipeline-C9_jNGPl.js +1 -0
  34. package/dist/assets/{PrivacyMaskSettings-CG3fC1u9.js → PrivacyMaskSettings-BCxCYZMd.js} +1 -1
  35. package/dist/assets/Recordings-DTwvvqkz.js +1 -0
  36. package/dist/assets/RemoteGrid-CDLuEg4n.js +1 -0
  37. package/dist/assets/{ScanSubnetEditor-Daxor7Ws.js → ScanSubnetEditor-L1fLOCgh.js} +1 -1
  38. package/dist/assets/SceneMonitorEditor-C6ytHNuF.js +1 -0
  39. package/dist/assets/SessionsList-WhsG7RxJ.js +2 -0
  40. package/dist/assets/{Showroom-BHPAz8BT.js → Showroom-DGD_uw5N.js} +1 -1
  41. package/dist/assets/StorageLocationsTable-CV0MMZ6R.js +1 -0
  42. package/dist/assets/{System-BP4Cs93o.js → System-CUM8c-ad.js} +1 -1
  43. package/dist/assets/{Templates-XTi8n4d2.js → Templates-B1e69LSo.js} +1 -1
  44. package/dist/assets/{Terminal-BCojSdwl.js → Terminal-BzbVWqvg.js} +3 -3
  45. package/dist/assets/{TrainingProviders-DNZfikzc.js → TrainingProviders-CF4NFH__.js} +1 -1
  46. package/dist/assets/{Viewer-B5-4q7UR.js → Viewer-XTh3fjp9.js} +1 -1
  47. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CsPCUaXy.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BezlQnHO.js} +1 -1
  48. package/dist/assets/{action-draft-BOfrcBkB.js → action-draft-DztPBE6P.js} +1 -1
  49. package/dist/assets/addon-icons-context-Bb2eBZv3.js +1 -0
  50. package/dist/assets/{ai-page.helpers-C_Yr1xBa.js → ai-page.helpers-B1a9LT5I.js} +1 -1
  51. package/dist/assets/archive-ChKlYFY2.js +1 -0
  52. package/dist/assets/{assignment-candidates-BVHvGld8.js → assignment-candidates-DtwDORE1.js} +1 -1
  53. package/dist/assets/{authed-media-D1AyMZAW.js → authed-media-C0rONCq5.js} +1 -1
  54. package/dist/assets/bell-off-ChsIJ9tx.js +1 -0
  55. package/dist/assets/{board-model-Dhq6ifuR.js → board-model-DB92Pi_O.js} +1 -1
  56. package/dist/assets/boxes-k5PsZ3NR.js +1 -0
  57. package/dist/assets/calendar-clock-Iy6okb6K.js +1 -0
  58. package/dist/assets/chevron-down-CBb-F8DT.js +1 -0
  59. package/dist/assets/circle-arrow-up-5n0C9Hkd.js +1 -0
  60. package/dist/assets/circle-slash-Duh934sZ.js +1 -0
  61. package/dist/assets/client-mnldOm50.js +921 -0
  62. package/dist/assets/create-composition-xpQJ_im0.js +2 -0
  63. package/dist/assets/crop-B-t0rzRY.js +1 -0
  64. package/dist/assets/database-zap-DHuELz_w.js +1 -0
  65. package/dist/assets/device-detail-rao8xQIi.js +1 -0
  66. package/dist/assets/{device-integration-icon-DpDOvLri.js → device-integration-icon-DSKbNj0K.js} +1 -1
  67. package/dist/assets/device-picker-model-CLxwtH6P.js +1 -0
  68. package/dist/assets/{dist-HZnBedB7.js → dist-AhzFc2N5.js} +1 -1
  69. package/dist/assets/dist-jfEaRcCl.js +921 -0
  70. package/dist/assets/eraser-B3lnG9yK.js +1 -0
  71. package/dist/assets/file-up-2YD_M6f_.js +1 -0
  72. package/dist/assets/{format-ClefNnBA.js → format-B0YD4Zes.js} +1 -1
  73. package/dist/assets/grip-vertical-C89CQZwo.js +1 -0
  74. package/dist/assets/hard-drive-download-C6N6tovA.js +1 -0
  75. package/dist/assets/{hostInit-CfH1B74s.js → hostInit-Cc2xXBkZ.js} +1 -1
  76. package/dist/assets/i18n-ByFr51sS.js +1 -0
  77. package/dist/assets/icons-B5aMnrp4.js +1 -0
  78. package/dist/assets/{index-BZIzoUuI.css → index-CcY1r6e1.css} +1 -1
  79. package/dist/assets/index-D5GcZJtC.js +4 -0
  80. package/dist/assets/key-CH4aXNMz.js +1 -0
  81. package/dist/assets/languages-Du_pOBpX.js +1 -0
  82. package/dist/assets/layers-BH9u1mrE.js +1 -0
  83. package/dist/assets/link-2-off-DmsjRAt7.js +1 -0
  84. package/dist/assets/{linked-devices-model-BTKuEEFr.js → linked-devices-model-DMdglvhv.js} +1 -1
  85. package/dist/assets/memory-stick-BQrJMbEW.js +1 -0
  86. package/dist/assets/message-square-plus-_aGccjyj.js +1 -0
  87. package/dist/assets/{mf-entry-bootstrap-0-eac89cb1.js → mf-entry-bootstrap-0-aa99f5e1.js} +2 -2
  88. package/dist/assets/mic-off-BIQ5bbUV.js +1 -0
  89. package/dist/assets/monitor-off-DnOkDa2s.js +1 -0
  90. package/dist/assets/monitor-smartphone-DPI9EQus.js +1 -0
  91. package/dist/assets/mount-CLxwtH6P.js +1 -0
  92. package/dist/assets/{notification-rule-status-CSdUF_tS.js → notification-rule-status-DfiT5MFH.js} +1 -1
  93. package/dist/assets/player-overlays-BZByYYB8.js +1 -0
  94. package/dist/assets/remoteEntry-BFXSwA_z.js +1 -0
  95. package/dist/assets/ruler-Buxogset.js +1 -0
  96. package/dist/assets/scan-eye-B0eLch9E.js +1 -0
  97. package/dist/assets/scissors-BgY-d4kD.js +1 -0
  98. package/dist/assets/search-x-C5ra3Aft.js +1 -0
  99. package/dist/assets/send-D_NAoo3n.js +1 -0
  100. package/dist/assets/settings-2-BIrKVPOG.js +1 -0
  101. package/dist/assets/shapes-BPdkDjXe.js +1 -0
  102. package/dist/assets/sigma-Bc8X6bFu.js +1 -0
  103. package/dist/assets/src-DKRp5NPI.js +169 -0
  104. package/dist/assets/{sso-popup-C1hR2YBu.js → sso-popup-CcJP5NlL.js} +1 -1
  105. package/dist/assets/{step-inspector-model-vWbbAD3j.js → step-inspector-model-DrTK6qqE.js} +1 -1
  106. package/dist/assets/table-2-DMxm3oyu.js +1 -0
  107. package/dist/assets/timer-reset-5221y6Jb.js +1 -0
  108. package/dist/assets/ungroup-BlQtUKBm.js +1 -0
  109. package/dist/assets/unlink-D3-IGpS8.js +1 -0
  110. package/dist/assets/usb-P4R9CjYI.js +1 -0
  111. package/dist/assets/{use-scenes-feed-Z9dHPg2s.js → use-scenes-feed-3gS-l6TV.js} +1 -1
  112. package/dist/assets/{use-stationary-objects-xEWFdcbm.js → use-stationary-objects-6FuPeLm0.js} +1 -1
  113. package/dist/assets/{useAdminDeviceRemoval-BskV-B_E.js → useAdminDeviceRemoval-Ds-ZvGNc.js} +1 -1
  114. package/dist/assets/useEventInvalidation-CLxwtH6P.js +1 -0
  115. package/dist/assets/{useNodeUrlSelection-PpcSePkt.js → useNodeUrlSelection-DAoFJ0Oq.js} +1 -1
  116. package/dist/assets/useTemplateSave-DZcYOuHu.js +1 -0
  117. package/dist/assets/user-round-CXEgJIXU.js +1 -0
  118. package/dist/assets/user-x-Dm3VRn93.js +1 -0
  119. package/dist/assets/variable-IcIR23WN.js +1 -0
  120. package/dist/assets/video-BV-3O_ZC.js +1 -0
  121. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BDhTmtK9.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-ZzcWUaNn.js} +2 -2
  122. package/dist/index.html +12 -10
  123. package/dist/server/addon.js +109 -8
  124. package/package.json +2 -2
  125. package/dist/assets/Addons-BPHEBwgB.js +0 -5
  126. package/dist/assets/AiProfiles-BS82tvr_.js +0 -3
  127. package/dist/assets/Cluster-AYu0bC0y.js +0 -1
  128. package/dist/assets/CompositionBlockEditor-DLKzOT_Z.js +0 -2
  129. package/dist/assets/Data-m24XW_1A.js +0 -2
  130. package/dist/assets/DeviceDetail-CtBuTHpi.js +0 -2
  131. package/dist/assets/History-B7zXtCqx.js +0 -1
  132. package/dist/assets/Identity-D7h9VlxP.js +0 -1
  133. package/dist/assets/InstancesTable-DJAoGLT7.js +0 -1
  134. package/dist/assets/IntegrationDetail-_DjBAUfS.js +0 -1
  135. package/dist/assets/Integrations-RdXuFBLO.js +0 -1
  136. package/dist/assets/Library-Bo5VMPHU.js +0 -1
  137. package/dist/assets/Locations-Bzbx2I8T.js +0 -3
  138. package/dist/assets/MyAccess-a5m99pH9.js +0 -2
  139. package/dist/assets/Network-6_mGQvda.js +0 -1
  140. package/dist/assets/Notifications-CANpi0fl.js +0 -1
  141. package/dist/assets/Pipeline-DXy1uxGI.js +0 -1
  142. package/dist/assets/Recordings-U1FdSuDg.js +0 -1
  143. package/dist/assets/SceneMonitorEditor-DoUH3vKa.js +0 -1
  144. package/dist/assets/SessionsList-CLG4ubwk.js +0 -2
  145. package/dist/assets/StorageLocationsTable-R3JA97a5.js +0 -1
  146. package/dist/assets/archive-CbCQODIH.js +0 -1
  147. package/dist/assets/bell-off-0BRa5Xnw.js +0 -1
  148. package/dist/assets/boxes-DwaGiTWo.js +0 -1
  149. package/dist/assets/calendar-clock-DxXmjbX-.js +0 -1
  150. package/dist/assets/circle-arrow-up-QFgY2pDM.js +0 -1
  151. package/dist/assets/circle-slash-D1PU0Pws.js +0 -1
  152. package/dist/assets/client-C0lbTORN.js +0 -839
  153. package/dist/assets/create-composition-rjKVG7Ea.js +0 -2
  154. package/dist/assets/crop-BE9be46d.js +0 -1
  155. package/dist/assets/database-zap-DM49YcQ2.js +0 -1
  156. package/dist/assets/device-picker-model-CUDIDEin.js +0 -1
  157. package/dist/assets/dist-CqSJqAHI.js +0 -839
  158. package/dist/assets/eraser-C49V6Xgz.js +0 -1
  159. package/dist/assets/file-up-DJCy37j8.js +0 -1
  160. package/dist/assets/hard-drive-download-CvIZPfEe.js +0 -1
  161. package/dist/assets/i18n-xBJb_nV7.js +0 -1
  162. package/dist/assets/icons-BAw5ExT5.js +0 -1
  163. package/dist/assets/index-DosV7QmO.js +0 -4
  164. package/dist/assets/key-QeyFcY2r.js +0 -1
  165. package/dist/assets/languages-flftEeCc.js +0 -1
  166. package/dist/assets/layers-I2gIsH5w.js +0 -1
  167. package/dist/assets/link-2-off-CDW3nS2X.js +0 -1
  168. package/dist/assets/memory-stick-3dE96Zxv.js +0 -1
  169. package/dist/assets/message-square-plus-DGwEztIa.js +0 -1
  170. package/dist/assets/mic-off-BmdlN5My.js +0 -1
  171. package/dist/assets/monitor-off-wdJY3-q4.js +0 -1
  172. package/dist/assets/monitor-smartphone-Bl6voNmx.js +0 -1
  173. package/dist/assets/mount-CUDIDEin.js +0 -1
  174. package/dist/assets/player-overlays-K3LnyuXU.js +0 -1
  175. package/dist/assets/remoteEntry-R0h-c7zx.js +0 -1
  176. package/dist/assets/ruler-2SK6v4x2.js +0 -1
  177. package/dist/assets/scan-eye-C8_EFUcN.js +0 -1
  178. package/dist/assets/scissors-C6KYQIFW.js +0 -1
  179. package/dist/assets/search-x-D-Hg9O-Y.js +0 -1
  180. package/dist/assets/send-CAIDeIAh.js +0 -1
  181. package/dist/assets/settings-2-CjaITzm2.js +0 -1
  182. package/dist/assets/shapes-DtaNsx8G.js +0 -1
  183. package/dist/assets/sigma-PjHLdD5t.js +0 -1
  184. package/dist/assets/src-BnhYqWbx.js +0 -169
  185. package/dist/assets/table-2-C9VskvlI.js +0 -1
  186. package/dist/assets/timer-reset-5MpoA_ms.js +0 -1
  187. package/dist/assets/ungroup-BA2l_gxU.js +0 -1
  188. package/dist/assets/unlink-iGZ9azi9.js +0 -1
  189. package/dist/assets/usb-B7ktYeJc.js +0 -1
  190. package/dist/assets/useEventInvalidation-CUDIDEin.js +0 -1
  191. package/dist/assets/useTemplateSave-DlVM9rMd.js +0 -1
  192. package/dist/assets/user-round-Bo7YdtBg.js +0 -1
  193. package/dist/assets/user-x-D3xK9W1_.js +0 -1
  194. package/dist/assets/variable-CWUlGlqi.js +0 -1
  195. package/dist/assets/video-DBmZRVRb.js +0 -1
@@ -1 +1 @@
1
- import{C as e,K as t,S as n,V as r,Y as i,d as a,et as o,u 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{pt as c}from"./player-overlays-K3LnyuXU.js";import{ws as l}from"./client-C0lbTORN.js";import{D as u,F as d,N as f,O as p,T as m,y as h}from"./__vite-browser-external-BCAtXlNQ.js";import{Gn as g,Hf as _,Nn as v,Zn as y,kn as b}from"./src-BnhYqWbx.js";import{t as x}from"./useTranslation-BJr-n0es.js";o();var S=d([p({kind:m(`adaptive`)}),p({kind:m(`profile`),profile:l})]),C=p({serverUrl:f().min(1),token:f().min(1),deviceId:u().int().nonnegative(),target:S,muted:h()});function w(e,t){let n=t===void 0?{type:`state`,state:e}:{type:`state`,state:e,message:t};window.ReactNativeWebView?.postMessage(JSON.stringify(n))}function T(e){switch(e){case`playing`:return`playing`;case`error`:return`error`;case`connecting`:case`disconnected`:case`idle`:return`connecting`}}function E(e){return e.kind===`adaptive`?{kind:`adaptive`}:{kind:`profile`,profile:e.profile}}function D(e){return e.kind===`adaptive`?`embed:adaptive`:`embed:profile:${e.profile}`}function O(){let e=window.__CAMSTACK_EMBED__;if(e==null)return{ok:!1,error:`window.__CAMSTACK_EMBED__ is not set`};let t=C.safeParse(e);return t.success?{ok:!0,config:t.data}:{ok:!1,error:t.error.issues.map(e=>`${e.path.join(`.`)||`(root)`}: ${e.message}`).join(`; `)}}function k({message:t}){let{t:n}=x();return r(()=>{w(`error`,t)},[t]),e(`div`,{style:{position:`fixed`,inset:0,display:`flex`,alignItems:`center`,justifyContent:`center`,background:`#000`,color:`#f87171`,fontFamily:`system-ui, sans-serif`,fontSize:13,padding:16,textAlign:`center`},children:[n(`embedPlayerPage.embedConfigError`,`Embed config error:`),` `,t]})}function A({system:e,deviceId:a,initialTarget:o,initialMuted:s}){let[c,l]=i(o),[u,d]=i(s),{handleOffer:f,getIceServers:p,addIceCandidate:m,getIceCandidates:h,closeSession:_,getSessionState:v,getSessionDebug:b,applyDownlinkProbe:x}=g(e.trpcClient,a),C=t(()=>E(c),[c]),O=t(()=>(e,t)=>f(C,e,t),[f,C]),k=t(()=>(e,t,n)=>f(n,t,e),[f]);r(()=>(window.__camstackEmbed={setMuted:e=>d(e),setTarget:e=>{let t=S.safeParse(e);t.success&&l(t.data)}},()=>{window.__camstackEmbed&&delete window.__camstackEmbed}),[]);let A=D(c);return n(`div`,{style:{position:`fixed`,inset:0,width:`100vw`,height:`100vh`,background:`#000`},children:n(y,{serverUrl:e.serverUrl,streamKey:A,autoPlay:!0,muted:u,showControls:!1,className:`w-full h-full`,getSessionDebug:b,applyDownlinkProbe:x,handleOffer:O,reoffer:k,getSessionState:v,getIceServers:p,addIceCandidate:m,getIceCandidates:h,closeSession:_,onStateChange:e=>w(T(e)),onError:e=>w(`error`,e)},A)})}function j(){let{t:e}=x(),i=t(()=>O(),[]),o=t(()=>{if(!i.ok)return null;let e=v({serverUrl:i.config.serverUrl,token:i.config.token}),t=new a({defaultOptions:{queries:{retry:!1,refetchOnWindowFocus:!1}}});return b(t),{system:e,queryClient:t}},[i]);return r(()=>{if(o)return()=>{o.system.close()}},[o]),i.ok?o?n(c,{system:o.system,children:n(s,{client:o.queryClient,children:n(_.Provider,{client:o.system.trpcClient,queryClient:o.queryClient,children:n(A,{system:o.system,deviceId:i.config.deviceId,initialTarget:i.config.target,initialMuted:i.config.muted})})})}):n(k,{message:e(`embedPlayerPage.failedToInitialiseTheEmbed`,`Failed to initialise the embed player`)}):n(k,{message:i.error})}export{j as EmbedPlayerPage};
1
+ import{C as e,K as t,S as n,V as r,Y as i,d as a,et as o,u 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{pt as c}from"./player-overlays-BZByYYB8.js";import{Es as l}from"./client-mnldOm50.js";import{D as u,F as d,N as f,O as p,T as m,y as h}from"./__vite-browser-external-BCAtXlNQ.js";import{Cn as g,Dn as _,Gn as v,Nf as y,zn as b}from"./src-DKRp5NPI.js";import{t as x}from"./useTranslation-BJr-n0es.js";o();var S=d([p({kind:m(`adaptive`)}),p({kind:m(`profile`),profile:l})]),C=p({serverUrl:f().min(1),token:f().min(1),deviceId:u().int().nonnegative(),target:S,muted:h()});function w(e,t){let n=t===void 0?{type:`state`,state:e}:{type:`state`,state:e,message:t};window.ReactNativeWebView?.postMessage(JSON.stringify(n))}function T(e){switch(e){case`playing`:return`playing`;case`error`:return`error`;case`connecting`:case`disconnected`:case`idle`:return`connecting`}}function E(e){return e.kind===`adaptive`?{kind:`adaptive`}:{kind:`profile`,profile:e.profile}}function D(e){return e.kind===`adaptive`?`embed:adaptive`:`embed:profile:${e.profile}`}function O(){let e=window.__CAMSTACK_EMBED__;if(e==null)return{ok:!1,error:`window.__CAMSTACK_EMBED__ is not set`};let t=C.safeParse(e);return t.success?{ok:!0,config:t.data}:{ok:!1,error:t.error.issues.map(e=>`${e.path.join(`.`)||`(root)`}: ${e.message}`).join(`; `)}}function k({message:t}){let{t:n}=x();return r(()=>{w(`error`,t)},[t]),e(`div`,{style:{position:`fixed`,inset:0,display:`flex`,alignItems:`center`,justifyContent:`center`,background:`#000`,color:`#f87171`,fontFamily:`system-ui, sans-serif`,fontSize:13,padding:16,textAlign:`center`},children:[n(`embedPlayerPage.embedConfigError`,`Embed config error:`),` `,t]})}function A({system:e,deviceId:a,initialTarget:o,initialMuted:s}){let[c,l]=i(o),[u,d]=i(s),{handleOffer:f,getIceServers:p,addIceCandidate:m,getIceCandidates:h,closeSession:g,getSessionState:_,getSessionDebug:y,applyDownlinkProbe:x}=b(e.trpcClient,a),C=t(()=>E(c),[c]),O=t(()=>(e,t)=>f(C,e,t),[f,C]),k=t(()=>(e,t,n)=>f(n,t,e),[f]);r(()=>(window.__camstackEmbed={setMuted:e=>d(e),setTarget:e=>{let t=S.safeParse(e);t.success&&l(t.data)}},()=>{window.__camstackEmbed&&delete window.__camstackEmbed}),[]);let A=D(c);return n(`div`,{style:{position:`fixed`,inset:0,width:`100vw`,height:`100vh`,background:`#000`},children:n(v,{serverUrl:e.serverUrl,streamKey:A,autoPlay:!0,muted:u,showControls:!1,className:`w-full h-full`,getSessionDebug:y,applyDownlinkProbe:x,handleOffer:O,reoffer:k,getSessionState:_,getIceServers:p,addIceCandidate:m,getIceCandidates:h,closeSession:g,onStateChange:e=>w(T(e)),onError:e=>w(`error`,e)},A)})}function j(){let{t:e}=x(),i=t(()=>O(),[]),o=t(()=>{if(!i.ok)return null;let e=_({serverUrl:i.config.serverUrl,token:i.config.token}),t=new a({defaultOptions:{queries:{retry:!1,refetchOnWindowFocus:!1}}});return g(t),{system:e,queryClient:t}},[i]);return r(()=>{if(o)return()=>{o.system.close()}},[o]),i.ok?o?n(c,{system:o.system,children:n(s,{client:o.queryClient,children:n(y.Provider,{client:o.system.trpcClient,queryClient:o.queryClient,children:n(A,{system:o.system,deviceId:i.config.deviceId,initialTarget:i.config.target,initialMuted:i.config.muted})})})}):n(k,{message:e(`embedPlayerPage.failedToInitialiseTheEmbed`,`Failed to initialise the embed player`)}):n(k,{message:i.error})}export{j as EmbedPlayerPage};
@@ -0,0 +1 @@
1
+ import{C as e,K as t,S as n,Y as r,et as i,i as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Aa as s,Hi as c,Rr as l,St as u,Tr as d,Yt as f,ct as p,gt as m,jn as h,lt as g,zn as _}from"./player-overlays-BZByYYB8.js";import{Zo as v,ii as y}from"./client-mnldOm50.js";import{A as b,B as x,Br as S,C,Ci as w,D as T,E,Ei as D,F as O,G as k,H as ee,Hr as A,I as j,Ir as te,Jr as ne,K as M,Ko as N,Lr as re,M as P,N as F,Nn as ie,Of as ae,P as oe,Pn as se,R as ce,Rr as le,S as ue,Ti as I,U as de,Un as L,V as fe,Vn as R,Vr as pe,W as z,Wn as B,Xr as V,Zr as me,bo as he,ji as H,k as ge,oi as U,ri as _e,td as ve,ui as W,w as ye,yo as be,z as xe}from"./src-DKRp5NPI.js";import{t as G}from"./useTranslation-BJr-n0es.js";import{Kr as Se}from"./index-D5GcZJtC.js";import{t as Ce}from"./AdminPage-_ITsYONa.js";i();function we(e,t){return e.scope===``?e.displayName:`${e.displayName} · ${t?.(e)??e.scope}`}function Te(e,t,n){let r=[];for(let{device:t,series:i}of e)for(let e of i){let i={subject:{kind:`device`,deviceId:t.id},key:e.key,scope:e.scope};r.push({id:F(i),ref:i,info:e,subjectName:t.name,location:t.location??``,nodeId:``,metric:we(e,n)})}for(let{node:e,series:i}of t)for(let t of i){let i={subject:{kind:`node`,nodeId:e.id},key:t.key,scope:t.scope};r.push({id:F(i),ref:i,info:t,subjectName:e.name,location:``,nodeId:e.id,metric:we(t,n)})}return r}function Ee(e){return[e.subjectName,e.location,e.metric,e.info.key,e.info.unit??``,e.nodeId].join(` `)}function K(e,t,n){if(e.ref.subject.kind!==`device`||t===null)return e.subjectName;let r=t.byId.get(e.ref.subject.deviceId);return r===void 0?e.subjectName:_e(r,`compact`,t,n)}var De=[`energy`,`temperatures`,`nodes`,`storage`],Oe=new Set([`cap:temperature-sensor.temperature`,`cap:climate-control.currentTemp`]),q=[`addon:metrics-native/node-cpu-percent`,`addon:metrics-native/node-memory-percent`],ke=`addon:storage-orchestrator/location-used-percent`;function Ae(e,t){let n=(e,n)=>{let r=t.filter(e);return P((n?[...r].sort(n):r).map(e=>e.ref))};switch(e){case`energy`:return n(e=>e.ref.subject.kind===`device`&&e.info.key===`derived:energy.kwh`);case`temperatures`:return n(e=>e.ref.subject.kind===`device`&&Oe.has(e.info.key)&&e.info.scope===``,(e,t)=>e.location.localeCompare(t.location)||e.subjectName.localeCompare(t.subjectName));case`nodes`:return n(e=>e.ref.subject.kind===`node`&&q.includes(e.info.key)&&e.info.scope===``,(e,t)=>q.indexOf(e.info.key)-q.indexOf(t.info.key)||e.subjectName.localeCompare(t.subjectName));case`storage`:return n(e=>e.ref.subject.kind===`node`&&e.info.key===ke)}}function je(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[],i=[],a=[],o=[];for(let t of P(e)){let e=n.get(F(t));if(e===void 0){o.push(t);continue}e.info.key===`derived:energy.kwh`?a.push(e):e.info.kind===`boolean`||e.info.kind===`enum`?i.push(e):r.push(e)}return{lines:r,states:i,energy:a,missing:o}}function Me(e){return e.subject.kind===`device`?{deviceId:e.subject.deviceId,key:e.key,scope:e.scope}:{forNodeId:e.subject.nodeId,key:e.key,scope:e.scope}}var J=`history-page`;function Ne({part:r,window:i}){let{t:a}=G(),o=s(),l=W(),u=U(),d=e=>`${K(e,l,u)} · ${e.metric}`,f=t(()=>[...r.lines,...r.states,...r.energy],[r]),p=E(t(()=>f.map(e=>Me(e.ref)),[f]),i,!1),m=e=>p.status===`ok`?p.data.current.get(ye(Me(e.ref))):void 0,h=e=>{let t=m(e);return t?.ok?t.result:void 0};if(f.length===0)return n(V,{icon:c,title:a(`history.page.emptyTitle`,`Pick series to compare`),description:a(`history.page.emptyHint`,`Choose up to 24 series on the left, or start from a panel above.`)});if(p.status===`error`)return n(w,{title:a(`history.page.readFailed`,`History could not be read`),message:p.error});let g=p.status===`pending`,_=f.map(e=>({c:e,e:m(e)})).filter(e=>e.e?.ok===!1),v=r.lines.map((e,t)=>{let n=h(e),r=xe(e.info,n,i.from);return{id:e.id,label:d(e),unit:e.info.unit,colorIndex:t,points:r.points,gapMs:r.gapMs,interpolation:r.held&&n?.resolution===`raw`?`step`:`linear`}}),y=r.states.map((e,t)=>{let n=x(e.info,h(e),i.from,i.to),r=j(e.info.key,o);return{id:e.id,label:d(e),kind:e.info.kind===`boolean`?`boolean`:`enum`,colorIndex:e.info.kind===`boolean`?t:0,states:n.states,segments:n.segments,totals:n.totals,stateLabel:e.info.kind===`boolean`?e=>e===`true`?r.on:r.off:void 0}}),b=r.energy.map(e=>({c:e,...ce(h(e))})),S=b[0]?.bucketMs??36e5,C=[...new Set(b.flatMap(e=>e.buckets.map(e=>e.t)))].sort((e,t)=>e-t).map(e=>({t:e,values:b.map(t=>t.buckets.find(t=>t.t===e)?.values[0]??null)}));return e(`div`,{className:`space-y-5 min-w-0`,children:[_.length>0&&n(w,{title:a(`history.page.someFailed`,`Some series could not be read`),message:_.map(e=>`${d(e.c)}: ${e.e.error}`).join(` · `)}),v.length>0&&n(M,{title:a(`history.page.lines`,`Measurements`),series:v,range:i,height:260,syncKey:J,pending:g}),b.length>0&&n(ne,{title:a(`history.page.energy`,`Energy`),layers:b.map((e,t)=>({id:e.c.id,label:K(e.c,l,u),colorIndex:t})),buckets:C,bucketMs:S,range:i,unit:`kWh`,showTotal:!0,height:160,syncKey:J,pending:g}),y.length>0&&n(k,{title:y.length===1?y[0]?.label??``:a(`history.page.states`,`States`),rows:y,range:i,syncKey:J,pending:g})]})}function Pe(e,t){let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}async function Fe(e,t){let n=[];for(let r of Pe(e,50))try{let{results:e}=await t(r),i=new Map(e.map(e=>[e.seriesId,e]));for(let e of r)n.push(i.get(e)??{seriesId:e,ok:!1,reason:`not-found`})}catch(e){let t=e instanceof Error?e.message:String(e);for(let e of r)n.push({seriesId:e,ok:!1,reason:`request-failed`,message:t})}return n}function Y(e){return e.raw+e[`5m`]+e[`1h`]+e[`1d`]}function Ie(e){return e.reduce((e,t)=>t.ok?{...e,deleted:e.deleted+1,points:e.points+Y(t.deleted)}:{...e,refused:e.refused+1},{deleted:0,refused:0,points:0})}function Le(e,t){let n=new Map(e.map(e=>[e.seriesId,e]));return t.flatMap(e=>{let t=n.get(e.seriesId);return t===void 0?[]:[{series:t,outcome:e}]})}var X=e=>new Date(e).toLocaleDateString(void 0,{dateStyle:`short`});function Z(e,t,n){let r=t.get(e.deviceId);return r===void 0?e.reason===`device-gone`?n(`history.orphans.deviceRemoved`,`#{{id}} (removed)`,{id:e.deviceId}):n(`history.orphans.deviceId`,`#{{id}}`,{id:e.deviceId}):r}function Q(e){let t=e.displayName??e.key;return e.scope===``?t:`${t} · ${e.scope}`}function Re(t,r,i){return{key:`series`,header:i(`history.orphans.colSeries`,`Series`),render:a=>{let o=t(a);return e(`div`,{className:`min-w-0 max-w-[16rem]`,children:[n(`div`,{className:`truncate text-foreground`,title:o.key,children:Q(o)}),n(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:Z(o,r,i)})]})},sortValue:e=>`${Z(t(e),r,i)} ${Q(t(e))}`}}var ze=[`raw`,`5m`,`1h`,`1d`];function Be(e,t){return e===`raw`?t(`history.orphans.colRaw`,`Raw points`):e===`5m`?t(`history.orphans.col5m`,`5 min`):e===`1h`?t(`history.orphans.col1h`,`1 h`):t(`history.orphans.col1d`,`1 day`)}function Ve(t,r){return[Re(e=>e,t,r),{key:`reason`,header:r(`history.orphans.colReason`,`Reason`),render:t=>e(`div`,{className:`flex flex-col items-start gap-0.5`,children:[n(I,{variant:t.reason===`device-gone`?`warning`:`neutral`,className:`text-[10px]`,children:t.reason===`device-gone`?r(`history.orphans.deviceGone`,`Device removed`):r(`history.orphans.undeclared`,`No longer declared`)}),t.missingSince!==null&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:r(`history.orphans.since`,`since {{date}}`,{date:X(t.missingSince)})})]}),sortValue:e=>e.reason},{key:`span`,header:r(`history.orphans.colSpan`,`Recorded`),render:t=>e(`span`,{className:`tabular-nums text-foreground-muted`,children:[X(t.firstTs),` → `,X(t.lastTs)]}),sortValue:e=>e.lastTs},...ze.map(e=>({key:`rows-${e}`,header:Be(e,r),align:`right`,render:t=>n(`span`,{className:`tabular-nums text-foreground-muted`,children:t.rows[e].toLocaleString()}),sortValue:t=>t.rows[e]}))]}function He(e,t){if(e.ok)return n(I,{variant:`success`,className:`text-[10px]`,children:t(`history.orphans.deleted`,{count:Y(e.deleted),points:Y(e.deleted).toLocaleString(),defaultValue_one:`Deleted · {{points}} point`,defaultValue_other:`Deleted · {{points}} points`})});let r=e.reason===`request-failed`?t(`history.orphans.requestFailed`,`Not sent: {{message}}`,{message:e.message}):e.reason===`not-orphan`?t(`history.orphans.refusedNotOrphan`,`Kept: no longer orphan`):e.reason===`not-found`?t(`history.orphans.refusedNotFound`,`Already gone`):t(`history.orphans.refusedFailed`,`The hub could not delete it`);return n(I,{variant:e.reason===`not-found`?`neutral`:`warning`,className:`text-[10px]`,children:r})}function Ue(e,t){return[Re(e=>e.series,e,t),{key:`result`,header:t(`history.orphans.colResult`,`Result`),render:e=>He(e.outcome,t),sortValue:e=>+!e.outcome.ok}]}i();function We({open:i,onClose:a,list:o,deviceNames:s,onDelete:c,onRefresh:l,refreshing:u}){let{t:m}=G(),h=p(),[g,v]=r(new Set),[y,b]=r(!1),[x,C]=r([]),w=t(()=>Ve(s,m),[s,m]),T=t(()=>Ue(s,m),[s,m]),E=t(()=>new Set(o.series.map(e=>String(e.seriesId))),[o.series]),D=[...g].filter(e=>E.has(e)).map(Number),O=Ie(x.map(e=>e.outcome)),k=async()=>{if(await h({title:m(`history.orphans.confirmTitle`,{count:D.length,defaultValue_one:`Delete {{count}} series`,defaultValue_other:`Delete {{count}} series`}),message:m(`history.orphans.confirmMessage`,`Every recorded point of these series is removed from the hub. This cannot be undone.`),confirmLabel:m(`history.orphans.confirmLabel`,`Delete`),variant:`danger`})){b(!0);try{let e=await Fe(D,c);C(Le(o.series,e)),v(new Set)}finally{b(!1),l()}}};return n(te,{open:i,onOpenChange:e=>!e&&a(),children:e(le,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`orphan-series-dialog`,children:[n(pe,{children:n(A,{children:m(`history.orphans.title`,`Series no longer linked to a device`)})}),e(re,{className:`space-y-3`,children:[n(`p`,{className:`text-xs text-foreground-muted`,children:m(`history.orphans.intro`,`Nothing records into these series any more: their device was removed, or no capability declares them now. Select the ones to delete.`)}),o.truncated&&e(`div`,{className:`flex flex-wrap items-center gap-2`,"data-testid":`orphan-truncated`,children:[n(`p`,{className:`text-xs text-warning`,children:m(`history.orphans.truncated`,`More series are unlinked than are listed here. Delete these, then load the rest.`)}),e(H,{size:`sm`,variant:`outline`,onClick:l,disabled:u,children:[n(_,{className:`h-3 w-3`,"aria-hidden":!0}),m(`history.orphans.loadAgain`,`Load again`)]})]}),x.length>0&&e(`div`,{className:`space-y-2`,"data-testid":`orphan-outcomes`,children:[n(`p`,{className:`text-xs text-foreground`,"aria-live":`polite`,children:m(`history.orphans.summary`,{count:O.deleted,refused:O.refused,points:O.points.toLocaleString(),defaultValue_one:`{{count}} series deleted ({{points}} points), {{refused}} kept.`,defaultValue_other:`{{count}} series deleted ({{points}} points), {{refused}} kept.`})}),n(L,{columns:T,rows:x,rowKey:e=>String(e.series.seriesId),minWidthPx:420,maxBodyHeight:`max-h-[60vh]`,emptyMessage:``})]}),n(L,{columns:w,rows:o.series,rowKey:e=>String(e.seriesId),minWidthPx:760,maxBodyHeight:B,defaultSort:{columnKey:`series`,dir:`asc`},emptyMessage:m(`history.orphans.empty`,`Every series is linked to a device.`),selection:{selected:g,onChange:v,rowLabel:e=>`${Q(e)} — ${Z(e,s,m)}`,pageLabel:m(`history.orphans.selectAll`,`Select every listed series`)}})]}),e(S,{children:[n(`span`,{className:`mr-auto text-[11px] tabular-nums text-foreground`,"aria-live":`polite`,children:m(`history.orphans.selected`,{count:D.length,defaultValue_one:`{{count}} selected`,defaultValue_other:`{{count}} selected`})}),n(H,{variant:`ghost`,size:`sm`,onClick:a,children:m(`history.orphans.close`,`Close`)}),e(H,{variant:`danger`,size:`sm`,disabled:D.length===0||y,onClick:()=>void k(),children:[y?n(d,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):n(f,{className:`h-3 w-3`,"aria-hidden":!0}),m(`history.orphans.deleteSelected`,`Delete selected`)]})]})]})})}i();var Ge=5*6e4;function Ke({enabled:i}){let{t:a}=G(),[s,c]=r(!1),l=he({},{enabled:i,staleTime:Ge}),u=N({projection:`slim`},{enabled:i}),d=be(),f=t(()=>new Map((u.data??[]).map(e=>[e.id,e.name])),[u.data]),p=e=>d.mutateAsync({seriesIds:[...e]});if(!i||l.status===`pending`)return null;if(l.status===`error`)return n(w,{variant:`warning`,title:a(`history.orphans.checkFailedTitle`,`Could not check for unlinked series`),message:l.error.message,onRetry:()=>void l.refetch()});let m=l.data;if(m.series.length===0&&!s)return null;let h=m.series.length;return e(o,{children:[h>0&&n(w,{variant:`warning`,message:m.truncated?a(`history.orphans.noticeMore`,{count:h,defaultValue_one:`More than {{count}} series are no longer linked to a device.`,defaultValue_other:`More than {{count}} series are no longer linked to a device.`}):a(`history.orphans.notice`,{count:h,defaultValue_one:`{{count}} series is no longer linked to a device.`,defaultValue_other:`{{count}} series are no longer linked to a device.`}),action:n(H,{size:`sm`,variant:`outline`,onClick:()=>c(!0),children:a(`history.orphans.review`,`Review`)})}),n(We,{open:s,onClose:()=>c(!1),list:m,deviceNames:f,onDelete:p,onRefresh:()=>void l.refetch(),refreshing:l.isFetching})]})}i();var qe=`device`,Je=`node`;function Ye({catalog:r,selected:i,onChange:a,loading:o}){let{t:s}=G(),c=W(),l=U(),u=e=>K(e,c,l),d=ie(r,{searchText:e=>[Ee(e)],facetGroups:[{id:`subject`,value:e=>e.ref.subject.kind===`device`?qe:Je},{id:`room`,value:e=>e.location},{id:`unit`,value:e=>e.info.unit??``}]}),f=t(()=>[{key:`metric`,header:s(`history.picker.series`,`Series`),render:t=>e(`div`,{className:`min-w-0`,children:[n(`div`,{className:`truncate text-foreground`,children:t.metric}),n(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.location===``?u(t):`${u(t)} · ${t.location}`})]}),sortValue:e=>`${e.subjectName} ${e.metric}`},{key:`unit`,header:s(`history.picker.unit`,`Unit`),render:e=>n(`span`,{className:`text-foreground-muted`,children:e.info.unit??`—`}),sortValue:e=>e.info.unit??``}],[s,c,l]),p=i.size>=24;return e(`div`,{className:`space-y-2 min-w-0`,children:[n(se,{state:d.state,facets:[],groups:[{...d.groups.find(e=>e.id===`subject`)??{id:`subject`,facets:[],selected:[]},label:s(`history.picker.subject`,`Source`),facetLabel:e=>e===qe?s(`history.picker.devices`,`Devices`):s(`history.picker.nodes`,`Nodes`)},{...d.groups.find(e=>e.id===`room`)??{id:`room`,facets:[],selected:[]},label:s(`history.picker.room`,`Room`),facetLabel:e=>e===``?s(`history.picker.noRoom`,`No room`):e},{...d.groups.find(e=>e.id===`unit`)??{id:`unit`,facets:[],selected:[]},label:s(`history.picker.metricType`,`Unit`),facetLabel:e=>e===``?s(`history.picker.noUnit`,`States & counts`):e}],labels:{searchPlaceholder:s(`history.picker.search`,`Search device, room, metric or node…`),searchLabel:s(`history.picker.searchLabel`,`Search series`),facetsLabel:s(`history.picker.facets`,`Filters`),clearLabel:s(`history.picker.clear`,`Clear`)},onSearch:d.setSearch,onToggleFacet:d.toggleFacet,onToggleGroupFacet:d.toggleGroupFacet,onClear:d.clear}),n(`p`,{className:`text-[10px] text-foreground-subtle`,"aria-live":`polite`,children:s(`history.picker.count`,`{{count}} of {{max}} selected`,{count:i.size,max:24})}),n(L,{columns:f,rows:d.rows,rowKey:e=>e.id,maxBodyHeight:B,pageSize:50,defaultSort:{columnKey:`metric`,dir:`asc`},emptyMessage:o?s(`history.picker.loading`,`Reading the series of every device…`):d.active?s(`history.picker.emptyFiltered`,`No series match these filters.`):s(`history.picker.empty`,`Nothing is recorded yet.`),selection:{selected:i,onChange:e=>{let t=[...e].filter(e=>i.has(e)),n=[...e].filter(e=>!i.has(e));a(new Set([...t,...n].slice(0,24)))},isSelectable:e=>i.has(e.id)||!p,rowLabel:e=>`${u(e)} · ${e.metric}`,pageLabel:s(`history.picker.selectPage`,`Select every series on this page`)}})]})}i();var Xe=new Set([v.Hub,v.Container]),$=5*6e4;function Ze(){let{t:r}=G(),i=me(`device-history`),[a,o]=Se(),s=t(()=>P(a.getAll(`s`).flatMap(e=>{let t=ge(e);return t===null?[]:[t]})),[a]),d=a.get(`window`),f=de(d)?d:`7d`,m=fe(a.get(`range`)),_=(e,t,n)=>{let r=new URLSearchParams;for(let t of P(e))r.append(`s`,b(t));t!==`7d`&&r.set(`window`,t);let i=n===void 0?a.get(`range`):n;t===`custom`&&i&&r.set(`range`,i),o(r,{replace:!0})},v=Qe(i===`present`),y=z(f,Date.now(),m),x=z(f,C(Date.now(),y.to-y.from),m),S=t(()=>je(s,v.candidates),[s,v.candidates]),E=t(()=>new Set(s.map(F)),[s]),k=ue(),A=g(),j=p(),te=async()=>{let e=await A({title:r(`history.page.saveTitle`,`Save as panel`),label:r(`history.page.saveName`,`Panel name`),confirmLabel:r(`history.page.save`,`Save`)});e===null||e.trim()===``||await k.update(t=>oe(t,{id:`panel-${Date.now().toString(36)}`,name:e.trim().slice(0,80),window:f,selection:[...s]}))},ne=async(e,t)=>{await j({title:r(`history.page.deleteTitle`,`Delete panel`),message:r(`history.page.deleteMessage`,`The panel "{{name}}" is removed from your account.`,{name:t}),confirmLabel:r(`history.page.delete`,`Delete`),variant:`danger`})&&await k.update(t=>O(t,e))},M=e=>e===`energy`?r(`history.panels.energy`,`Total energy`):e===`temperatures`?r(`history.panels.temperatures`,`Temperatures by room`):e===`nodes`?r(`history.panels.nodes`,`Cluster nodes`):r(`history.panels.storage`,`Storage locations`);return n(Ce,{icon:c,title:r(`history.page.title`,`History`),subtitle:r(`history.page.subtitle`,`What devices, nodes and storage recorded over time, side by side.`),actions:i===`present`?e(H,{size:`sm`,variant:`outline`,onClick:()=>void te(),disabled:s.length===0||!k.writable,children:[n(h,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),r(`history.page.saveTitle`,`Save as panel`)]}):void 0,children:i===`pending`?n(D,{className:`h-64 w-full`}):i===`unknown`?n(w,{title:r(`history.page.presenceUnknownTitle`,`Could not reach the hub`),message:r(`history.page.presenceUnknown`,`The hub did not say whether device history is installed. Try again in a moment.`)}):i===`absent`?n(V,{icon:l,title:r(`history.page.absentTitle`,`Device history is not running on this hub`),description:r(`history.page.absent`,`Nothing is recorded until the device-history system addon is enabled.`)}):e(`div`,{className:`space-y-3 sm:space-y-4`,children:[n(Ke,{enabled:i===`present`}),e(`div`,{className:`flex flex-wrap items-center gap-2`,role:`group`,"aria-label":r(`history.page.panels`,`Panels`),children:[De.map(e=>n(H,{size:`sm`,variant:`outline`,disabled:v.status!==`ok`,onClick:()=>_(Ae(e,v.candidates),f),children:M(e)},e)),k.value.panels.map(t=>e(`span`,{className:`inline-flex items-center`,children:[n(H,{size:`sm`,variant:`secondary`,onClick:()=>_(t.selection,t.window,null),children:t.name}),n(H,{size:`sm`,variant:`ghost`,"aria-label":r(`history.page.deleteNamed`,`Delete panel {{name}}`,{name:t.name}),onClick:()=>void ne(t.id,t.name),disabled:!k.writable,children:n(u,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})]},t.id))]}),e(`div`,{className:`grid grid-cols-1 gap-3 sm:gap-4 xl:grid-cols-5`,children:[n(`div`,{className:`min-w-0 xl:col-span-2`,children:n(R,{headingId:`history-picker`,title:r(`history.picker.title`,`Series`),children:n(`div`,{className:`p-2 sm:p-3`,children:v.status===`error`?n(w,{message:v.error}):n(Ye,{catalog:v.candidates,loading:v.status===`pending`,selected:E,onChange:e=>{let t=s.filter(t=>e.has(F(t))),n=v.candidates.filter(t=>e.has(t.id)&&!E.has(t.id)).map(e=>e.ref);_([...t,...n],f)}})})})}),n(`div`,{className:`min-w-0 xl:col-span-3`,children:n(R,{headingId:`history-overlay`,title:r(`history.page.overlay`,`Overlay`),actions:s.length>0?n(H,{size:`sm`,variant:`ghost`,onClick:()=>_([],f),children:r(`history.page.clear`,`Clear`)}):void 0,children:e(`div`,{className:`p-2 sm:p-3 space-y-3 min-w-0`,children:[n(T,{value:f,onChange:e=>_(s,e),custom:m,onCustomChange:e=>_(s,`custom`,ee(e))}),v.status===`pending`&&s.length>0?n(D,{className:`h-64 w-full`}):n(Ne,{part:S,window:x}),S.missing.length>0&&v.status===`ok`&&n(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`history.page.missing`,{count:S.missing.length,defaultValue_one:`{{count}} selected series is no longer recorded.`,defaultValue_other:`{{count}} selected series are no longer recorded.`})})]})})})]})]})})}function Qe(e){let{t:n}=G(),r=n(`history.picker.wholeFrame`,`Whole frame`),i=m().trpcClient,o=N({projection:`slim`},{enabled:e}),{nodes:s}=ae(),c=t(()=>(o.data??[]).filter(e=>!Xe.has(String(e.type))),[o.data]),l=a({queries:c.map(t=>({queryKey:[`device-history`,`listSeries`,t.id],queryFn:()=>i.deviceHistory.listSeries.query({deviceId:t.id}),enabled:e,staleTime:$}))}),u=a({queries:s.map(t=>({queryKey:[`device-history`,`listNodeSeries`,t.id],queryFn:()=>i.deviceHistory.listNodeSeries.query({forNodeId:t.id}),enabled:e,staleTime:$}))}),d=ve({},{enabled:e,staleTime:$}),f=t(()=>new Map((d?.data??[]).map(e=>[e.id,e.displayName])),[d?.data]),p=l.map(e=>e.data),h=u.map(e=>e.data),g=t(()=>Te(c.flatMap((e,t)=>{let n=p[t];return n===void 0?[]:[{device:{id:e.id,name:e.name,location:e.location??null},series:n}]}),s.flatMap((e,t)=>{let n=h[t];return n===void 0?[]:[{node:{id:e.id,name:e.name},series:n}]}),e=>{if(e.key!==`addon:pipeline-analytics/occupancy`)return f.get(e.scope)??e.scope;let{zoneId:t,className:n}=y(e.scope),i=t===``?r:t;return n===void 0?i:`${i} · ${n}`}),[c,s,f,[...l,...u].map(e=>e.dataUpdatedAt).join(`,`),r]);return o.status===`error`?{status:`error`,error:o.error.message,candidates:[]}:{status:o.status===`pending`||l.some(e=>e.isPending)||u.some(e=>e.isPending)?`pending`:`ok`,error:``,candidates:g}}export{Ze as HistoryPage};
@@ -0,0 +1 @@
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{Cn as u,D as d,Dn as f,Jn as p,Kt as m,Lt as h,Nr as g,Or as _,Pi as v,Sa as y,Sr as b,St as x,Tr as S,Yt as C,ct as w,da as ee,er as te,gt as T,kn as E,li as D,lt as ne,pn as O,ri as k,ut as re,wn as ie,xn as ae,zn as oe}from"./player-overlays-BZByYYB8.js";import{$o as A,Qo as se,l as ce}from"./client-mnldOm50.js";import{c as j,f as M,h as le,r as N}from"./video-BV-3O_ZC.js";import{t as ue}from"./file-up-2YD_M6f_.js";import{t as de}from"./key-CH4aXNMz.js";import{t as fe}from"./monitor-smartphone-DPI9EQus.js";import{t as pe}from"./unlink-D3-IGpS8.js";import{$ as me,Ac as he,Bd as ge,Br as P,Cc as _e,Ci as F,Dt as ve,Ec as ye,Fn as be,Gd as xe,Hd as Se,Hn as I,Hr as L,In as R,Ir as z,Jd as Ce,Kd as we,Ko as Te,Ld as Ee,Lr as B,Lt as V,Nf as H,Pr as De,Rd as Oe,Rr as U,Ti as W,Ud as ke,Un as Ae,Vd as je,Vn as Me,Vr as G,Wd as Ne,Wn as Pe,Xr as Fe,af as Ie,ar as Le,cr as Re,dr as ze,if as Be,jc as Ve,ji as K,kt as He,lr as Ue,nf as We,qd as Ge,rf as Ke,sr as qe,tf as Je,ur as Ye,vt as Xe,wi as Ze,xc as Qe,zd as $e}from"./src-DKRp5NPI.js";import{t as q}from"./i18n-ByFr51sS.js";import{t as J}from"./useTranslation-BJr-n0es.js";import{Hr as et,I as tt,Kr as nt,Wr as rt,a as it,c as at,i as ot,l as st,o as ct,s as lt,t as ut,u as dt,x as ft}from"./index-D5GcZJtC.js";import{t as pt}from"./AdminSectionedPage-Xr_hesYw.js";import{t as mt}from"./AdminPage-_ITsYONa.js";import{C as ht,D as Y,E as gt,O as X,S as _t,T as vt,_ as yt,a as bt,b as xt,c as St,d as Ct,f as wt,g as Tt,h as Et,i as Dt,k as Ot,l as kt,m as At,n as jt,o as Mt,p as Nt,s as Pt,t as Ft,u as It,v as Lt,w as Rt,x as zt,y as Bt}from"./SessionsList-WhsG7RxJ.js";import{n as Vt}from"./Authentication-CWHj8Czl.js";s();function Ht(){let{t:e}=J(),t=w(),i=H.useUtils(),o=Ot(),{data:s,isLoading:c}=ke(),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=Ge({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=>({...zt(e,o),kind:h.get(e.provider)??e.provider})),v=async n=>{let r=g.find(e=>xt(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(Y,{notice:X(f),onDismissNotice:()=>{p(null)},id:`external-identities`,title:e(`access.externalIdentitiesSection.signInLinks`,`Sign-in links`),icon:le,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(Rt,{rows:_,label:`sign-in links`,isLoading:c||u.some(e=>e.isLoading),loadError:u.find(e=>e.isError)?.error?.message??null,emptyText:`No user has linked a sign-in account.`,expiresNone:`—`,action:{label:e(`common.remove`,`Remove`),icon:pe,isAvailable:()=>!0,onRun:e=>void v(e),busyId:null,disabled:m.isPending}})})}s();var Ut={key:`access.nouns.linkedApp`};function Wt(e){if(e.type===`category`){let t=e.target??``;return t===`device`?q.t(`access.linkedAppsSection.allDevices`):q.t(`access.linkedAppsSection.allTarget`,{target:t})}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function Gt(){let{t:e}=J(),t=w(),i=c(),o=Se(),[s,l]=a(null),u=()=>void i.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]}),d=xe({onSuccess:u,onError:e=>l(`Revoke failed: ${e.message}`)}),f=vt(Ut,u),p=n(()=>(o.data??[]).map(e=>_t(e,e.scopes.map(Wt).join(`, `))),[o.data]),m=async n=>{await t({title:e(`access.linkedAppsSection.revokeTheLink`,`Revoke the "{{name}}" link?`,{name:n.name}),message:e(`access.linkedAppsSection.losesAccessForOnIts`,`{{name}} loses access for {{ownerName}} on its next call. Linking it again needs the account-link flow from the start.`,{name:n.name,ownerName:n.ownerName}),confirmLabel:e(`access.linkedAppsSection.revoke`,`Revoke`),variant:`danger`})&&(l(null),d.mutate({id:n.id}))},h=d.isPending?d.variables?.id??null:null;return r(Y,{notice:X(s,f.outcome),onDismissNotice:()=>{l(null),f.dismiss()},id:`linked-apps`,title:e(`access.linkedAppsSection.linkedApps`,`Linked apps`),icon:_,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(Rt,{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:C,isAvailable:e=>e.status===`active`||e.status===`revoked`,onRun:e=>void m(e),busyId:h,disabled:d.isPending||f.busy},bulk:{revoke:f,noun:Ut,isSelectable:e=>e.status===`active`||e.status===`revoked`,quickSelect:[{label:e(`access.linkedAppsSection.selectRevoked`,`Select revoked`),match:e=>e.status===`revoked`}]}})})}var Kt=5e3;function qt(){let{t}=J(),n=H.useUtils(),i=H.auth.cliLoginPending.useQuery(void 0,{refetchInterval:Kt}),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(K,{type:`button`,size:`sm`,variant:`ghost`,disabled:a.isPending,onClick:()=>a.mutate({requestId:n.requestId}),children:t(`cliLogin.notMe`,`Not me`)})]},n.requestId)})}),r(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`cliLogin.pendingHint`,`To approve one, open the approval page and type the code the terminal shows.`)})]})}s();var Jt={key:`access.nouns.session`};function Yt(){let{t}=J(),i=w(),o=H.useUtils(),s=Ot(),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=vt(Jt,d),m=n(()=>(c.data??[]).map(e=>ht(e,s,{client:e=>yt(e).label,method:Lt})),[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(Y,{notice:X(l,p.outcome),onDismissNotice:()=>{u(null),p.dismiss()},id:`login-sessions`,title:t(`access.loginSessionsSection.loginSessions`,`Login sessions`),icon:fe,description:t(`access.loginSessionsSection.everyBrowserAndAppSigned`,`Every browser and app signed in to this hub, for every user. Signing one out ends it at once; it has to sign in again. Your own current session is marked and never included in a bulk sign-out.`),children:[r(qt,{}),r(Rt,{rows:m,label:t(`common.sessionsLabel`),isLoading:c.isLoading,loadError:c.isError?c.error?.message??`Request failed`:null,emptyText:`No active sessions.`,action:{label:t(`access.loginSessionsSection.signOut`,`Sign out`),icon:j,isAvailable:e=>e.status===`active`,onRun:e=>void h(e),busyId:f.isPending&&f.variables!==void 0&&`id`in f.variables?f.variables.id:null,disabled:f.isPending||p.busy},bulk:{revoke:p,noun:Jt,isSelectable:e=>e.status===`active`}})]})}var Xt={"by-id":`helpers.authAuditWording.bulkNoun.credential`,"share-link":`helpers.authAuditWording.bulkNoun.shareLink`,"admin-token":`helpers.authAuditWording.bulkNoun.adminToken`,"login-session":`helpers.authAuditWording.bulkNoun.loginSession`};function Z(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function Zt(e,t){let n=Z(e,`tokenId`);return Z(e,`name`)??(n===null?void 0:t.get(n))??n??`?`}function Q(e){return e.filter(e=>e!==null)}function Qt(e){let t=Z(e,`prefix`);return t===null?null:q.t(`helpers.authAuditWording.prefix`,{prefix:t})}function $t(e,t){let n=e.detail??{};switch(e.action){case`admin-token-created`:{let e=n.expiresAt;return{title:q.t(`helpers.authAuditWording.tokenCreated`,{name:Zt(n,t)}),details:Q([Qt(n),typeof e==`number`?q.t(`helpers.authAuditWording.expires`,{at:Bt(e)}):null])}}case`admin-token-used`:{let e=Z(n,`path`);return{title:q.t(`helpers.authAuditWording.tokenUsed`,{name:Zt(n,t)}),details:Q([Qt(n),e===null?null:q.t(`helpers.authAuditWording.call`,{path:e})])}}case`token-minted`:{let e=n.expiresAt;return{title:q.t(`helpers.authAuditWording.tokenMinted`,{name:Zt(n,t)}),details:Q([typeof e==`number`?q.t(`helpers.authAuditWording.expires`,{at:Bt(e)}):null])}}case`token-revoked`:return{title:q.t(`helpers.authAuditWording.anyTokenRevoked`,{name:Zt(n,t)}),details:[]};case`admin-token-revoked`:return{title:q.t(`helpers.authAuditWording.tokenRevoked`,{name:Zt(n,t)}),details:Q([Qt(n)])};case`credentials-revoked`:{let e=Z(n,`kind`)??`credential`,t=n.revoked,r=n.skipped,i=Xt[e],a=i===void 0?`${e}s`:q.t(i);return{title:q.t(`helpers.authAuditWording.bulkRevoked`,{n:typeof t==`number`?String(t):`?`,noun:a}),details:Q([typeof r==`number`&&r>0?q.t(`helpers.authAuditWording.skipped`,{count:r}):null,Z(n,`ids`)===null?null:q.t(`helpers.authAuditWording.ids`,{ids:Z(n,`ids`)??``})])}}case`second-factor-skipped`:{let e=Z(n,`method`),t=Z(n,`factors`);return{title:q.t(`helpers.authAuditWording.secondFactorSkipped`),details:Q([e===null?null:q.t(`helpers.authAuditWording.signedInWith`,{method:Lt(e)}),t===null?null:q.t(`helpers.authAuditWording.skippedFactors`,{factors:t.split(`,`).join(`, `)})])}}default:return{title:e.action,details:Object.entries(n).map(([e,t])=>`${e}: ${String(t)}`)}}}s();var en=100;function tn(){let{user:e}=tt();return e?.isAdmin?r(rn,{}):null}function nn(){let{data:e}=ke(),{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 rn(){let{t}=J(),n=H.auth.listAuthAudit.useQuery({limit:en}),{userNameById:i,tokenNameById:a}=nn(),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(E,{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:en})})]}),r(`div`,{className:`p-4`,children:n.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(S,{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(an,{record:e,userName:e.userId===void 0?null:i.get(e.userId)??e.userId,tokenNameById:a},e.id))})})]})}function an({record:t,userName:n,tokenNameById:i}){let a=$t(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:Bt(t.at)})]}),e(`div`,{className:`flex flex-wrap gap-x-3 text-[11px] text-foreground-subtle`,children:[n!==null&&r(`span`,{className:`text-foreground`,children:n}),t.ip!==void 0&&r(`span`,{className:`font-mono`,children:t.ip}),a.details.map(e=>r(`span`,{className:`font-mono`,children:e},e))]})]})}s();function on(e){let{ids:t,answered:r,legacyGroupParam:i=null,groupFirst:a}=e,[o]=nt(),s=o.get(ct),c=i===null?null:o.get(i),l=o.get(lt),u=n(()=>st({ids:t,requested:s,answered:r,legacyGroup:c,...a===void 0?{}:{groupFirst:a}}),[t,s,r,c,a]),d=n(()=>(e,t)=>`?${dt(o,e,i,t??null).toString()}`,[o,i]);return{...u,requestedSection:l,hrefFor:d}}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`},sn={[$.scopedTokens]:$.tokens,[$.adminTokens]:$.tokens,[$.shareLinks]:$.tokens};function cn(){return[{id:$.loginSessions,label:q.t(`system.access.loginSessions`,`Login sessions`),icon:fe,render:()=>r(Yt,{})},{id:$.linkedApps,label:q.t(`system.access.linkedApps`,`Linked apps`),icon:_,render:()=>r(Gt,{})},{id:$.tokens,label:q.t(`system.access.tokens`,`Tokens`),icon:M,render:({createRequested:e,onCreateConsumed:t})=>r(Et,{headerOwnsCreate:!0,createRequested:e,onCreateConsumed:t})},{id:$.externalIdentities,label:q.t(`system.access.signInLinks`,`Sign-in links`),icon:le,render:()=>r(Ht,{})},{id:$.audit,label:q.t(`system.access.audit`,`Audit`),icon:E,render:()=>r(tn,{})}]}function ln({createRequested:t=!1,onCreateConsumed:i}){let{t:a}=J(),o=n(()=>cn(),[]),s=on({ids:n(()=>o.map(e=>e.id),[o]),answered:!0}),c=rt(),[l]=nt(),u=l.get(`integration`),d=u===null?void 0:sn[u];if(d!==void 0){let e=new URLSearchParams(l);return e.set(`integration`,d),r(et,{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(`?${dt(l,e,null,null).toString()}`)},children:r(qe,{"aria-label":a(`system.access.credentialKinds`,`Credential kinds`),children:o.map(t=>e(Re,{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 un(t,n){if(t===$.tokens)return e(K,{size:`sm`,type:`button`,"data-testid":`access-new-token`,onClick:n,children:[r(M,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),q.t(`system.access.newToken`,`New token`)]})}function dn(){let[e,t]=a(!1);return{createRequested:e,requestCreate:()=>t(!0),clearCreate:()=>t(!1)}}function fn({isPending:t,error:n,what:i,onRetry:a,children:o}){let{t:s}=J();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(S,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),s(`certificates.queryBody.reading`,{what:i})]}):n===null?o:r(F,{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 pn(){let{t}=J(),n=H.deviceCredentials.getDeviceCaStatus.useQuery({}),i=n.data;return r(Y,{id:`device-ca`,title:t(`certificates.deviceCaCard.deviceCertificateAuthority`,`Device certificate authority`),icon:u,description:t(`certificates.deviceCaCard.signsTheCertificateEachPaired`,`Signs the certificate each paired device holds. It is created the first time a device is paired.`),children:r(fn,{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(I,{label:t(`certificates.deviceCaCard.state`,`State`),children:[i.state===`ready`&&r(W,{variant:`success`,children:t(`certificates.deviceCaCard.ready`,`Ready`)}),i.state===`absent`&&r(W,{variant:`default`,children:t(`certificates.deviceCaCard.notCreatedYet`,`Not created yet`)}),i.state===`unavailable`&&r(W,{variant:`danger`,children:t(`certificates.deviceCaCard.unavailable`,`Unavailable`)})]}),i.state===`ready`&&e(l,{children:[r(I,{label:t(`certificates.deviceCaCard.subject`,`Subject`),valueClassName:`font-mono`,children:i.subject}),r(I,{label:t(`certificates.deviceCaCard.fingerprintSha256`,`Fingerprint (SHA-256)`),valueClassName:`font-mono`,children:i.fingerprintSha256}),r(I,{label:t(`certificates.deviceCaCard.validUntil`,`Valid until`),children:i.validTo})]}),i.state===`unavailable`&&r(I,{label:t(`certificates.deviceCaCard.reason`,`Reason`),children:r(`span`,{className:`text-danger`,children:i.reason})})]})})})}s();function mn(){let{t}=J(),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(fn,{isPending:i.isPending,error:i.error,what:`the enrollment setting`,onRetry:()=>void i.refetch(),children:i.data!==void 0&&e(I,{label:t(`certificates.deviceSettingsRow.usersCanEnrollTheirOwn`,`Users can enroll their own devices`),actions:r(Ue,{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 hn(e){let[t,n]=a(()=>Date.now());return i(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}s();var gn=80,_n=208;function vn({open:t,users:n,onClose:i,onPaired:o}){let{t:s}=J(),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(He,{open:t,onClose:h,title:s(`certificates.pairDeviceDialog.pairADevice`,`Pair a device`),icon:O,width:`md`,testId:`pair-device-dialog`,error:c.isError?c.error.message:null,footer:m===void 0?e(K,{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(S,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),s(`certificates.pairDeviceDialog.createPairingCode`,`Create pairing code`)]}):r(K,{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(V,{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(V,{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(Ie,{value:d,maxLength:gn,onChange:e=>f(e.target.value),placeholder:s(`certificates.pairDeviceDialog.annaSIphone`,`Anna's iPhone`),autoFocus:!0})})]}):r(yn,{enrollUrl:m.enrollUrl,expiresAt:m.expiresAt,hubKnown:m.hubOrigin!==null,onRestart:()=>c.reset()})})}function yn({enrollUrl:t,expiresAt:n,hubKnown:i,onRestart:a}){let{t:o}=J(),s=Mt(n,hn(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(De,{value:t,size:_n,alt:o(`certificates.pairDeviceDialog.enrollmentQrCode`,`Enrollment QR code`)})}),e(`div`,{className:`min-w-0 flex-1 space-y-2`,children:[r(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`certificates.pairDeviceDialog.openTheCamstackAppOn`,`Open the CamStack app on the phone and scan this code. It works once.`)}),r(`div`,{className:`text-sm font-semibold tabular-nums text-foreground`,role:`timer`,"data-testid":`pair-countdown`,children:s.expired?o(`certificates.pairDeviceDialog.expiredCreateANewCode`,`Expired - create a new code`):o(`certificates.pairDeviceDialog.expiresIn`,`Expires in {{label}}`,{label:s.label})}),e(`div`,{className:`flex items-center gap-1 rounded-md border border-border bg-background px-2 py-1`,children:[r(`code`,{className:`min-w-0 flex-1 select-all break-all font-mono text-[11px] text-foreground`,children:t}),r(be,{value:t,srLabel:`Enrollment link`})]}),!i&&e(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-2.5 py-1.5 text-[11px] text-foreground`,children:[r(m,{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(K,{type:`button`,variant:`outline`,size:`sm`,onClick:a,children:o(`certificates.pairDeviceDialog.newCode`,`New code`)})]})]})})}s();var bn={key:`access.nouns.device`};function xn({pairOpen:t,onPairClose:i}){let{t:o}=J(),s=w(),c=ne(),l=H.useUtils(),u=H.deviceCredentials.listDeviceCredentials.useQuery({includeRevoked:!0}),d=ke(),[f,p]=a(null),[m,h]=a(null),g=()=>void l.deviceCredentials.listDeviceCredentials.invalidate(),_=e=>t=>{h(null),p(`${e} failed: ${t.message}`)},v=()=>{h(null),g()},y=H.deviceCredentials.revokeDeviceCredential.useMutation({onSuccess:v,onError:_(`Revoke`)}),b=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.`),v()},onError:_(`Delete`)}),x=H.deviceCredentials.renameDeviceCredential.useMutation({onSuccess:v,onError:_(`Rename`)}),S=gt(bn,e=>y.mutateAsync({id:e}),g),T=S.busy||m!==null,E=n(()=>(u.data??[]).map(jt),[u.data]),D=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),h(e.id),y.mutate({id:e.id}))},k=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),h(e.id),b.mutate({id:e.id}))},re=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),h(e.id),x.mutate({id:e.id,deviceName:t}))},ie={label:o(`certificates.devicesCard.revoke2`,`Revoke`),icon:ee,isAvailable:bt,onRun:e=>void D(e),busyId:y.isPending?m:null,disabled:T},ae=[{label:o(`certificates.devicesCard.rename`,`Rename`),icon:te,tone:`neutral`,isAvailable:()=>!0,onRun:e=>void re(e),busyId:x.isPending?m:null,disabled:T},{label:o(`common.delete`,`Delete`),icon:C,isAvailable:Dt,onRun:e=>void k(e),busyId:b.isPending?m:null,disabled:T}];return e(Y,{id:`devices`,title:o(`certificates.devicesCard.devices`,`Devices`),icon:O,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:X(f,S.outcome),onDismissNotice:()=>{p(null),S.dismiss()},children:[r(mn,{}),r(Rt,{rows:E,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:ie,extraActions:ae,bulk:{revoke:S,noun:bn,isSelectable:bt}}),r(vn,{open:t,users:d.data??[],onClose:i,onPaired:g})]})}var Sn=/-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----/,Cn=/-----BEGIN ((?:RSA |EC |ENCRYPTED )?PRIVATE KEY)-----[\s\S]+?-----END \1-----/,wn={certificate:`.pem,.crt,.cer`,privateKey:`.pem,.key`,ca:`.pem,.crt,.cer`};function Tn(e,t){if(t.trim()===``)return null;if(e===`privateKey`){let e=Cn.exec(t);return e===null?Sn.test(t)?q.t(`helpers.pemFile.isCert`):q.t(`helpers.pemFile.notKey`):e[1]===`ENCRYPTED PRIVATE KEY`?q.t(`helpers.pemFile.encrypted`):null}return Sn.test(t)?e===`certificate`&&Cn.test(t)?q.t(`helpers.pemFile.certHasKey`):null:Cn.test(t)?q.t(`helpers.pemFile.isKey`):q.t(`helpers.pemFile.notCert`)}function En(e){return e.text()}s();function Dn({kind:n,label:i,value:o,onChange:s,rows:c=6}){let{t:l}=J(),u=t(null),[d,f]=a(null),[p,m]=a(null),h=p??Tn(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 En(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(Ye,{ref:u,accept:wn[n],onChange:e=>void _(e),className:`hidden`,"data-testid":`${g}-file`}),e(K,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>u.current?.click(),children:[r(ue,{className:`mr-1 h-3 w-3`}),l(`system.pemField.chooseFile`,`Choose file`)]})]})]}),r(ze,{id:g,value:o,onChange:e=>{f(null),m(null),s(e.target.value)},rows:c,"aria-invalid":h!==null,className:`w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`}),h!==null&&r(`p`,{className:`text-[11px] text-danger`,role:`alert`,children:h})]})}s();var On=30;function kn(e){let t=Date.parse(e);return!Number.isNaN(t)&&Date.now()-t<On*864e5}function An(e){if(e===null||e===``)return`—`;let t=e.replace(/:/g,``);return t.length<=16?e:`${t.slice(0,8)}…${t.slice(-8)}`}function jn(){let{t}=J(),n=c(),i=Qe(void 0,{refetchInterval:15e3}),o=_e({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),s=ye({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),l=Ve({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),u=he({onSuccess:()=>{m(!1),g(``),v(``),b(``),n.invalidateQueries({queryKey:[[`localNetwork`]]})}}),f=i.data,[p,m]=a(!1),[h,g]=a(``),[_,v]=a(``),[y,b]=a(``),x=()=>{if(!f?.caCertPem)return;let e=new Blob([f.caCertPem],{type:`application/x-pem-file`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`camstack-ca.crt`,n.click(),URL.revokeObjectURL(t)},S=f?.mode===`uploaded`?`Uploaded`:f?.mode===`generated`?`Generated local CA`:`TLS disabled`;return r(Me,{headingId:`local-access-certificate`,title:t(`system.localAccess.certificate`,`Certificate`),icon:ae,children:e(`div`,{className:`${d} space-y-3`,children:[i.isError&&r(`p`,{className:`text-xs text-danger`,children:t(`system.localAccess.couldNotReadTlsStatus`,`Could not read TLS status.`)}),f?.reissueError&&r(F,{variant:`warning`,title:t(`system.localAccess.certificateReissue`,`Certificate reissue`),message:f.reissueError}),f?.restartRequired&&r(F,{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.`)}),f?.caMissing===!0&&r(F,{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).")}),f?.caReplacedAt!=null&&kn(f.caReplacedAt)&&r(F,{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(f.caReplacedAt).toLocaleString()})}),e(`dl`,{className:`grid grid-cols-1 gap-2 text-xs sm:grid-cols-2`,children:[e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.mode`,`Mode`)}),r(`dd`,{className:`font-medium`,children:S})]}),e(`div`,{children:[r(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.validTo`,`Valid to`)}),r(`dd`,{className:`font-mono`,children:f?.validTo?new Date(f.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:f?.leafFingerprintSha256??void 0,children:An(f?.leafFingerprintSha256??null)})]}),f?.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(f.storedUpload.validTo).toLocaleDateString(),ca:f.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:f?.caFingerprintSha256??void 0,children:f?.mode===`uploaded`&&f.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)`)}):An(f?.caFingerprintSha256??null)})]})]}),f&&f.sans.length>0&&r(`div`,{className:`flex flex-wrap gap-1`,children:f.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(R,{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:f?.mode===`uploaded`||o.isPending,action:()=>o.mutateAsync({})}),r(K,{size:`sm`,variant:`outline`,onClick:()=>m(e=>!e),children:t(`system.localAccess.upload`,`Upload`)}),f?.caCertPem&&r(K,{size:`sm`,variant:`outline`,onClick:x,children:t(`system.localAccess.downloadCa`,`Download CA`)}),f?.mode===`uploaded`&&r(R,{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({})}),f?.mode===`generated`&&f.storedUpload!=null&&r(R,{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(Dn,{kind:`certificate`,label:t(`system.localAccess.certificateOrFullChainPem`,`Certificate or full chain (PEM)`),value:h,onChange:g}),r(Dn,{kind:`privateKey`,label:t(`system.localAccess.privateKeyPem`,`Private key (PEM)`),value:_,onChange:v}),r(Dn,{kind:`ca`,label:t(`system.localAccess.caPemRequired`,`CA (PEM) - required unless the certificate comes from a public CA`),value:y,onChange:b,rows:4}),r(K,{size:`sm`,disabled:!h.trim()||!_.trim()||Tn(`certificate`,h)!==null||Tn(`privateKey`,_)!==null||Tn(`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 Mn={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`};function Nn(e){let t=e.find(e=>e.isHub);return t?.https.kind===`served`?t.https.status.caFingerprintSha256:null}function Pn({https:t,mesh:n,now:i}){let{t:a}=J(),o=Qe().data?.caCertPem??``,s=()=>{if(o===``)return;let e=URL.createObjectURL(new Blob([o],{type:`application/x-pem-file`})),t=document.createElement(`a`);t.href=e,t.download=`camstack-ca.crt`,t.click(),URL.revokeObjectURL(e)},c=n?.ca,l=c?.state===`ready`?Date.parse(c.validTo):null,u=n?.listener;return e(`div`,{className:`space-y-1`,"data-testid":`ca-strip`,children:[r(I,{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:[Nn(t)??`—`,o!==``&&e(K,{type:`button`,variant:`ghost`,size:`sm`,onClick:s,children:[r(D,{className:`h-3 w-3`,"aria-hidden":!0}),a(`certificates.caStrip.downloadCa`,`Download CA`)]})]})}),r(I,{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(I,{label:a(`certificates.caStrip.clusterCaValidUntil`,`Cluster CA valid until`),children:[c.validTo,l!==null&&!Number.isNaN(l)&&e(`span`,{className:`ml-2 text-[10px] ${Mn[It(l,i)]}`,children:[`(`,St(l,i),`)`]})]}),u!==void 0&&e(I,{label:a(`certificates.caStrip.nodeListener`,`Node listener`),children:[u.state===`open`&&r(W,{variant:`success`,children:a(`certificates.caStrip.open`,`Open`)}),u.state===`not-started`&&r(W,{variant:`default`,children:a(`certificates.caStrip.notStarted`,`Not started`)}),u.state===`closed`&&e(`span`,{className:`text-danger`,children:[a(`certificates.caStrip.closedSince`,{when:Ct(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(m,{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 Fn(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 In(e){return e.isHub?q.t(`helpers.nodesModel.hubReissued`):e.mesh===null?q.t(`helpers.nodesModel.noCertRecorded`):e.online?null:q.t(`helpers.certificateModel.nodeOffline`)}function Ln(e){return e.isHub||e.mesh===null?In(e):null}var Rn={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`},zn={enroll:`Issued at enrollment`,renewal:`Issued by a renewal`,boot:`Issued at boot`,pairing:`Issued at pairing`,observed:`Observed on its connection`},Bn={uploaded:`Uploaded`,generated:`Generated`,disabled:`Disabled`};function Vn(e){let t=e.https?.https;return t?.kind===`served`?Pt(t.status.validTo):null}function Hn({ms:t,now:n}){return t===null?r(`span`,{className:`text-foreground-subtle`,children:`—`}):e(`div`,{children:[r(`div`,{children:Ct(t)}),r(`div`,{className:`text-[10px] ${Rn[It(t,n)]}`,children:St(t,n)})]})}function Un({row:t}){let{t:n}=J(),i=t.https?.https;return i===void 0?r(`span`,{className:`text-foreground-subtle`,children:`—`}):i.kind===`served`?e(`div`,{title:i.status.leafFingerprintSha256??``,children:[r(W,{variant:`success`,className:`text-[10px]`,children:n(`certificates.nodesColumns.served`,`Served`)}),r(`span`,{className:`ml-1.5 text-[10px] text-foreground-subtle`,children:Bn[i.status.mode]}),r(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:Nt(i.status.leafFingerprintSha256)}),i.status.sans.length>0&&r(`div`,{className:`mt-0.5 max-w-[14rem] truncate font-mono text-[10px] text-foreground-subtle`,title:i.status.sans.join(`, `),children:i.status.sans.join(`, `)})]}):e(`div`,{className:`max-w-[16rem]`,children:[r(W,{variant:i.kind===`unreadable`?`danger`:`warning`,className:`text-[10px]`,children:i.kind===`unreadable`?n(`certificates.nodesColumns.unreadable`,`Unreadable`):n(`certificates.nodesColumns.notServed`,`Not served`)}),r(`div`,{className:`mt-1 whitespace-normal text-[10px] text-foreground-subtle`,children:i.reason})]})}function Wn({row:t}){let{t:n}=J(),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:At(i.serial)}),r(`div`,{className:`font-mono text-[10px] text-foreground-subtle`,title:i.fingerprintSha256,children:Nt(i.fingerprintSha256)}),e(`div`,{className:`text-[10px] text-foreground-subtle`,children:[zn[i.issuedVia],a>0?` · ${n(`certificates.nodesColumns.earlier`,{count:a})}`:``]})]})}function Gn({row:e}){let{t}=J(),n=e.mesh?.presentingCurrent??null;return n===null?r(`span`,{className:`text-foreground-subtle`,children:e.online?`—`:t(`certificates.nodesColumns.offline`,`Offline`)}):n?r(W,{variant:`success`,className:`text-[10px]`,children:t(`common.yes`,`Yes`)}):r(W,{variant:`warning`,className:`text-[10px]`,children:t(`certificates.nodesColumns.noPresentsAnother`,`No - presents another`)})}function Kn(t){let n=t.icon;return e(K,{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(S,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):r(n,{className:`h-3 w-3`,"aria-hidden":!0}),t.label]})}function qn({reasons:t}){let{t:n}=J();return e(We,{className:`inline-block`,children:[r(Be,{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(Ke,{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 Jn({row:t,o:n}){let{t:i}=J(),a=t.https===null?`No HTTPS inventory for this node.`:wt(t.https).reason,o=In(t),s=Ln(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(Kn,{label:i(`certificates.nodesColumns.renewHttps`,`Renew HTTPS`),ariaLabel:i(`certificates.nodesColumns.renewTheCertificateOn`,`Renew the certificate on {{nodeId}}`,{nodeId:t.nodeId}),icon:oe,reason:a,busy:n.busy,spinning:c(`renew-https`),danger:!1,onClick:()=>n.onRenewHttps(t)}),l(o)&&r(Kn,{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:oe,reason:o,busy:n.busy,spinning:c(`renew-identity`),danger:!1,onClick:()=>n.onRenewIdentity(t)}),l(s)&&r(Kn,{label:i(`certificates.nodesColumns.revokeIdentity`,`Revoke identity`),ariaLabel:i(`certificates.nodesColumns.revokeTheClusterCertificateOf`,`Revoke the cluster certificate of {{nodeId}}`,{nodeId:t.nodeId}),icon:ee,reason:s,busy:n.busy,spinning:c(`revoke-identity`),danger:!0,onClick:()=>n.onRevokeIdentity(t)})]}),t.isHub&&u.length>0&&r(qn,{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 Yn(t){return[{key:`node`,header:q.t(`certificates.nodesColumns.node`,`Node`),sortValue:e=>e.isHub?``:e.nodeId.toLowerCase(),render:t=>e(`div`,{className:`flex items-center gap-1.5`,children:[r(`span`,{className:`font-medium text-foreground`,children:t.nodeId}),t.nodeId===`hub`&&r(W,{variant:`info`,className:`text-[10px]`,children:q.t(`common.hubWord`)}),!t.online&&r(W,{variant:`default`,className:`text-[10px]`,children:q.t(`common.offline`)})]})},{key:`https-state`,header:`HTTPS`,notSortableReason:`A state with a reason has no single order.`,render:e=>r(Un,{row:e})},{key:`https-expires`,header:q.t(`certificates.nodesColumns.httpsExpires`,`HTTPS expires`),sortValue:e=>Vn(e),render:e=>r(Hn,{ms:Vn(e),now:t.now})},{key:`identity`,header:q.t(`certificates.nodesColumns.identity`,`Identity`),sortValue:e=>e.mesh?.current?.serial??null,render:e=>r(Wn,{row:e})},{key:`identity-expires`,header:q.t(`certificates.nodesColumns.identityExpires`,`Identity expires`),sortValue:e=>e.mesh?.current?.notAfter??null,render:e=>r(Hn,{ms:e.mesh?.current?.notAfter??null,now:t.now})},{key:`presenting`,header:q.t(`certificates.nodesColumns.inUse`,`In use`),notSortableReason:`Offline nodes have no answer to order by.`,render:e=>r(Gn,{row:e})},{key:`actions`,header:q.t(`certificates.nodesColumns.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order.`,render:e=>r(Jn,{row:e,o:t})}]}s();function Xn(){let{t}=J(),i=w(),o=H.useUtils(),s=hn(6e4),c=H.certificates.listHttpsCertificates.useQuery(),l=H.certificates.getMeshCertificates.useQuery(),[u,d]=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),d(`${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(kt(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)=>{d(null),m(null),g({nodeId:e,action:t})},ee=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}))},te=e=>{C(e.nodeId,`renew-identity`),b.mutate({nodeId:e.nodeId})},T=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}))},E=Yn({now:s,busy:S,running:h,onRenewHttps:e=>void ee(e),onRenewIdentity:te,onRevokeIdentity:e=>void T(e)}),D=n(()=>Fn(c.data??[],l.data),[c.data,l.data]),ne=l.data?.registryAvailable??!0;return r(Y,{id:`nodes`,title:t(`certificates.nodesCard.nodes`,`Nodes`),icon:f,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:X(u,p),onDismissNotice:()=>{d(null),m(null)},children:r(fn,{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(Pn,{https:c.data??[],mesh:l.data,now:s}),r(Ae,{columns:E,rows:D,rowKey:e=>e.nodeId,minWidthPx:960,maxBodyHeight:Pe,defaultSort:{columnKey:`node`,dir:`asc`},emptyMessage:ne?t(`certificates.nodesCard.noNodesReported`,`No nodes reported.`):t(`certificates.nodesCard.theCertificateRegistryIsNot`,`The certificate registry is not available yet, so nodes cannot be listed.`)})]})})})}function Zn({pairOpen:t,onPairClose:n}){return e(`div`,{className:`space-y-4`,"data-testid":`certificates-page`,children:[r(xn,{pairOpen:t,onPairClose:n}),r(pn,{}),r(jn,{}),r(Xn,{})]})}function Qn({userId:t,username:n,onClose:i}){let{t:a}=J(),o=w(),s=H.useUtils(),c=je({userId:t}),l=H.auth.listLoginMethods.useQuery(),u=Ge({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(z,{open:!0,onOpenChange:e=>!e&&i(),children:e(U,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`external-identities-modal`,children:[r(G,{children:e(L,{className:`flex items-center gap-2`,children:[r(_,{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(B,{className:`space-y-3`,children:c.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(S,{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(K,{variant:`unstyled`,onClick:()=>void p(t,i),disabled:u.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[r(pe,{className:`h-3 w-3`}),a(`common.remove`,`Remove`)]})]},`${t.provider}|${t.subject}`)})})}),r(P,{children:r(K,{onClick:i,variant:`secondary`,children:a(`common.close`,`Close`)})})]})})}function $n({userId:t,username:n,onClose:i}){let{t:a}=J(),o=c(),s=w(),u=ge({userId:t}),d=u.data,f=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),p=$e({onSuccess:()=>{f(),i()}}),m=u.isLoading?`loading`:d?.enabled?`enrolled`:`not_enrolled`;return r(z,{open:!0,onOpenChange:e=>!e&&i(),children:e(U,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[r(G,{children:e(L,{className:`flex items-center gap-2`,children:[r(O,{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(B,{className:`space-y-4`,children:[m===`loading`&&e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(S,{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(g,{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(v,{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(K,{onClick:i,variant:`secondary`,children:a(`common.close`,`Close`)}),e(K,{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(S,{className:`h-3 w-3 animate-spin`}):r(x,{className:`h-3 w-3`}),a(`users.totpModal.remove2fa`,`Remove 2FA`)]})]})]})]})]})})}s();function er({userId:t,username:n,onClose:i}){let{t:o}=J(),{user:s,logout:c}=tt(),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:yt(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(z,{open:!0,onOpenChange:e=>!e&&i(),children:e(U,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`user-sessions-modal`,children:[r(G,{children:e(L,{className:`flex items-center gap-2`,children:[r(fe,{className:`h-4 w-4 text-primary`}),e(`span`,{children:[o(`users.userSessionsModal.activeSessions`,`Active sessions`),e(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[o(`users.userSessionsModal.user`,`User:`),` `,r(`span`,{className:`font-mono`,children:n})]})]})]})}),e(B,{className:`space-y-3`,children:[p!==null&&r(`div`,{className:`text-[11px] text-danger`,children:p}),r(Ft,{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(P,{className:`justify-between`,children:[e(K,{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(S,{className:`h-3 w-3 animate-spin`}):r(j,{className:`h-3 w-3`}),o(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`)]}),r(K,{onClick:i,variant:`secondary`,children:o(`common.close`,`Close`)})]})]})})}function tr({scopes:t,invalidReason:n}){let{t:i}=J(),a=T(),s=o({queryKey:[`auth`,`previewScope`,t,!1],enabled:n===null,queryFn:()=>a.trpcClient.auth.previewScope.query({scopes:[...t],isAdmin:!1})}),{data:c}=Te({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(ie,{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(S,{className:`h-3 w-3 shrink-0 animate-spin`}),i(`users.rolePreview.resolving`)]});if(s.isError||!s.data)return r(`p`,{className:`text-[11px] text-danger`,"data-testid":`role-preview`,children:i(`users.rolePreview.couldNotResolve`)});let u=s.data.viewableDeviceCount,d=s.data.device.view.all?i(`users.rolePreview.everyDevice`,{count:u}):l===null?i(`users.rolePreview.devicesVisible`,{count:u}):i(`users.rolePreview.devicesVisibleOf`,{count:u,total:l});return e(`p`,{className:`flex items-center gap-1.5 text-[11px] ${u===0?`text-warning`:`text-foreground`}`,"data-testid":`role-preview`,children:[u===0?r(ie,{className:`h-3 w-3 shrink-0`}):r(k,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),u===0?i(`users.rolePreview.noDevice`):d]})}function nr(e){let t=ce(e.scopes??[]);if(t===null)return{role:e.isAdmin?`admin`:`viewer`,mode:`except`,pickedIds:[],viewer:se,unconfigured:!e.isAdmin};let n=lr(t);return{role:e.isAdmin?`admin`:`viewer`,mode:n.mode,pickedIds:n.pickedIds,viewer:ur(n.mode,n.pickedIds,t.features),unconfigured:!1}}function rr(e,t){return{...e,role:t}}function ir(e,t){return{...e,mode:t,viewer:ur(t,e.pickedIds,e.viewer.features)}}function ar(e,t){let n=dr(t);return{...e,pickedIds:n,viewer:ur(e.mode,n,e.viewer.features)}}function or(e,t,n){let r=e.viewer.features.filter(e=>e!==t),i=n?[...r,t]:r;return{...e,viewer:ur(e.mode,e.pickedIds,i)}}function sr(e){return e.role===`viewer`&&e.mode===`only`&&e.pickedIds.length===0?`no-allowed-device`:null}function cr(e){return sr(e)===null?e.role===`admin`?{isAdmin:!0,scopes:[]}:{isAdmin:!1,scopes:[e.viewer]}:null}function lr(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 ur(e,t,n){let r=dr(t);return e===`except`?{type:`viewer`,allow:`*`,block:r,features:[...n]}:{type:`viewer`,allow:r,block:[],features:[...n]}}function dr(e){return[...new Set(e)]}s();var fr=`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`;function pr(e,t){return e?`failed`:t===void 0?`pending`:`answered`}function mr(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 hr({user:t,isSelf:i,onClose:o,onSubmit:s,submitting:c,error:u}){let{t:d}=J(),[f,p]=a(n(()=>nr(t),[t])),m=Te({projection:`slim`}),h=m.data,g=pr(m.isError,h),_=n(()=>mr(h??[]),[h]),v=n(()=>({state:g,devices:g===`answered`?(h??[]).map(e=>({id:e.id,name:e.name})):void 0}),[g,h]),b=sr(f),x=cr(f),C=b===`no-allowed-device`?d(`users.userAccessModal.pickAllowedDevice`):null,w=e=>{p(rr(f,e))},ee=[{value:`except`,label:d(`users.userAccessModal.modeExcept`)},{value:`only`,label:d(`users.userAccessModal.modeOnly`)}];return r(z,{open:!0,onOpenChange:e=>!e&&o(),children:e(U,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-2xl`,children:[r(G,{children:r(L,{children:d(`users.userAccessModal.title`,{name:t.username})})}),e(B,{className:`space-y-4`,children:[f.unconfigured&&f.role===`viewer`&&r(F,{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:fr,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(gr,{name:`admin`,checked:f.role===`admin`,label:d(`users.userAccessModal.admin`),description:d(`users.userAccessModal.adminDescription`),onPick:()=>w(`admin`)}),r(gr,{name:`viewer`,checked:f.role===`viewer`,disabled:i,label:d(`users.userAccessModal.viewer`),description:d(i?`users.userAccessModal.cannotDemoteSelf`:`users.userAccessModal.viewerDescription`),onPick:()=>w(`viewer`)})]})]}),f.role===`viewer`&&e(l,{children:[e(`section`,{className:`space-y-3`,children:[r(`h3`,{className:fr,children:d(`users.userAccessModal.devices`)}),r(Xe,{label:d(`users.userAccessModal.whichDevices`),value:f.mode,options:ee,onChange:e=>p(ir(f,e))}),r(me,{devices:_,listState:g,fleet:v,value:[...f.pickedIds],onChange:e=>p(ar(f,e)),emptyMeansAll:f.mode===`except`,noun:`device`,testId:`viewer-device-picker`}),r(tr,{scopes:x?.scopes??[],invalidReason:C})]}),e(`section`,{className:`space-y-2`,children:[r(`h3`,{className:fr,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(y,{className:`mt-0.5`,checked:f.viewer.features.includes(t.id),onChange:e=>p(or(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(F,{message:u})]}),e(P,{children:[r(K,{variant:`outline`,size:`sm`,onClick:o,children:d(`common.cancel`,`Cancel`)}),r(K,{size:`sm`,onClick:()=>x!==null&&s(x),disabled:c||x===null,children:c?r(S,{className:`h-3 w-3 animate-spin`}):d(`users.userAccessModal.saveAccess`)})]})]})})}function gr({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(Ze,{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 _r=8;function vr(){return{username:``,password:``,isAdmin:!1}}function yr(e){return{id:e.id,username:e.username,password:``,isAdmin:e.isAdmin}}function br(e){return e instanceof Error?e.message:q.t(`admin.system.users.genericError`)}function xr(){let{t}=J(),n=c(),{user:o}=tt(),{state:s,openNew:d,openEdit:f,close:m}=ve(),[g,v]=a(null),[b,x]=a(null),[ee,T]=a(!1),{data:E,isLoading:D,isError:k,error:re,refetch:ie}=ke(),ae=w(),oe=ne(),A=()=>n.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),se=Ee(),ce=Oe({onSuccess:A}),j=Ce({onSuccess:A}),M=Ne({onSuccess:A}),le=we(),[N,ue]=a(null),[pe,me]=a(!1),[he,ge]=a(null),[P,_e]=a(null),[ye,be]=a(null),[xe,Se]=a(null),I=E??[],L=s.mode===`edit`?I.find(e=>e.id===s.id)??null:null,R=()=>{v(null),x(null),T(!1),se.reset(),j.reset(),m()};i(()=>{if(s.mode===`closed`){v(null),x(null),T(!1);return}if(s.mode===`new`){v(e=>e!==null&&e.id===void 0?e:vr());return}if(L===null){D||m();return}v(e=>e?.id===L.id?e:yr(L))},[s,L,D,m]);let z=s.mode===`new`&&g!==null&&g.id===void 0||s.mode===`edit`&&g!==null&&L!==null;async function Te(e){await ae({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`})&&(ce.mutate({id:e.id}),s.mode===`edit`&&s.id===e.id&&R())}async function B(e){let n=await oe({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<_r?q.t(`admin.system.users.passwordTooShort`,{min:_r}):null});n===null||n.length===0||await ae({title:t(`admin.system.users.resetPassword`,`Reset password`),message:t(`admin.system.users.resetThePasswordForThey`,`Reset the password for "{{username}}"? They will need to use the new password on their next login.`,{username:e.username}),confirmLabel:t(`common.reset`,`Reset`)})&&M.mutate({id:e.id,newPassword:n})}function H(e){ge(null),ue(e)}async function De(e,t){me(!0),ge(null);try{t.isAdmin!==e.isAdmin&&await j.mutateAsync({id:e.id,isAdmin:t.isAdmin}),await le.mutateAsync({userId:e.id,scopes:[...t.scopes]}),ue(null)}catch(e){ge(br(e))}finally{me(!1),A()}}async function U(){if(g!==null){x(null);try{if(g.id===void 0){let e=g.username.trim();if(e===``||g.password.length<_r)return;await se.mutateAsync({username:e,password:g.password,isAdmin:g.isAdmin})}else await j.mutateAsync({id:g.id,isAdmin:g.isAdmin});A(),R()}catch(e){x(br(e))}}}function W(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}let je=se.isPending||j.isPending,Me=g!==null&&g.id===void 0&&g.username.trim()!==``&&g.password.length>=_r,G=g!==null&&g.id!==void 0,Pe=je||(g?.id===void 0?!Me:!G),Le=e=>ce.isPending&&ce.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=>Sr(e),render:n=>r(`span`,{onClick:e=>e.stopPropagation(),children:e(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>H(n),disabled:Le(n),title:t(`admin.system.users.configureAccess`,`Configure access`),"data-testid":`user-access-${n.id}`,children:[r(u,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),r(Cr,{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:W(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(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>f(n.id),disabled:i,title:t(`admin.system.users.editUser`,`Edit user`),children:[r(te,{className:`h-3 w-3`}),t(`common.edit`,`Edit`)]}),a&&e(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>_e(n),disabled:i,title:t(`admin.system.users.removeTwoFactorAuthentication`,`Remove two-factor authentication`),children:[r(O,{className:`h-3 w-3`}),t(`admin.system.users.remove2fa`,`Remove 2FA`)]}),e(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>be(n),disabled:i,title:t(`admin.system.users.linkedSignInAccounts`,`Linked sign-in accounts`),children:[r(_,{className:`h-3 w-3`}),t(`admin.system.users.signInLinks`,`Sign-in links`)]}),e(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>Se(n),disabled:i,title:t(`admin.system.users.activeSessions`,`Active sessions`),children:[r(fe,{className:`h-3 w-3`}),t(`admin.system.users.sessions`,`Sessions`)]}),e(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void B(n),disabled:i,title:t(`admin.system.users.resetPassword`,`Reset password`),children:[r(de,{className:`h-3 w-3`}),t(`admin.system.users.resetPassword`,`Reset password`)]}),e(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void Te(n),disabled:i,title:t(`admin.system.users.deleteUser`,`Delete user`),className:`text-danger hover:bg-danger/10`,children:[i?r(S,{className:`h-3 w-3 animate-spin`}):r(C,{className:`h-3 w-3`}),t(`common.delete`,`Delete`)]})]})}}];return e(mt,{embedded:!0,icon:h,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(K,{size:`sm`,type:`button`,onClick:()=>{x(null),d()},children:[r(p,{className:`h-3.5 w-3.5`}),t(`admin.system.users.createUser`,`Create User`)]}),children:[k&&r(F,{title:t(`admin.system.users.couldNotLoadUsers`,`Could not load users`),message:br(re),onRetry:()=>void ie()}),D&&e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(S,{className:`h-3.5 w-3.5 animate-spin`}),t(`common.loading`,`Loading…`)]}),!D&&!k&&I.length===0&&r(Fe,{icon:h,title:t(`admin.system.users.noUsersYet`,`No users yet`),description:t(`admin.system.users.createAUserToGrant`,`Create a user to grant hub access.`)}),!D&&!k&&I.length>0&&r(Ae,{columns:Re,rows:I,rowKey:e=>e.id,minWidthPx:560,maxBodyHeight:`max-h-[60vh]`,onRowClick:e=>f(e.id)}),r(He,{open:z,onClose:R,title:g?.id===void 0?t(`admin.system.users.createUser`,`Create User`):t(`admin.system.users.edit`,`Edit {{value1}}`,{value1:g.username||`user`}),icon:h,error:b,testId:`user-form-dialog`,footer:r(K,{size:`sm`,type:`button`,disabled:Pe,onClick:()=>void U(),children:je?e(l,{children:[r(S,{className:`h-3.5 w-3.5 animate-spin`}),t(`admin.system.users.saving`,`Saving…`)]}):g?.id===void 0?t(`admin.system.users.create`,`Create`):t(`common.save`,`Save`)}),children:g!==null&&e(`div`,{className:`space-y-3`,children:[r(V,{label:t(`admin.system.users.username`,`Username`),required:g.id===void 0,children:r(Ie,{value:g.username,onChange:e=>v({...g,username:e.target.value}),placeholder:`john`,autoFocus:g.id===void 0,disabled:g.id!==void 0,"data-testid":`user-form-username`})}),g.id===void 0&&r(V,{label:t(`admin.system.users.password`,`Password`),required:!0,description:t(`admin.system.users.atLeastCharacters`,`At least {{value1}} characters.`,{value1:String(_r)}),children:r(Je,{value:g.password,onValueChange:e=>v({...g,password:e}),shown:ee,onToggleShown:()=>T(e=>!e),placeholder:`••••••••`,"data-testid":`user-form-password`})}),r(V,{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(y,{checked:g.isAdmin,onChange:e=>v({...g,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`)})]})}),g.id!==void 0&&r(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`admin.system.users.toChangeThePasswordUse`,`To change the password, use Reset password on the user's row. Access scopes are configured from the Access column.`)})]})}),P&&r($n,{userId:P.id,username:P.username,onClose:()=>_e(null)}),ye&&r(Qn,{userId:ye.id,username:ye.username,onClose:()=>be(null)}),xe&&r(er,{userId:xe.id,username:xe.username,onClose:()=>Se(null)}),N&&r(hr,{user:N,isSelf:N.id===o?.id,onClose:()=>ue(null),onSubmit:e=>void De(N,e),submitting:pe,error:he})]})}function Sr(e){let t=nr(e);return t.role===`admin`?0:t.unconfigured?2:1}function Cr({user:t}){let{t:n}=J(),i=nr(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 wr={"api-keys":$.tokens,"linked-sessions":$.linkedApps},Tr=`certificates`;function Er(t){return e(K,{size:`sm`,type:`button`,"data-testid":`certificates-pair-device`,onClick:t,children:[r(O,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),q.t(`systemPage.identity.pairADevice`,`Pair a device`)]})}function Dr(){let{t:e}=J(),[t]=nt(),n=dn(),[i,o]=a(!1),s=wr[t.get(`tab`)??``];if(s!==void 0)return r(et,{to:at(`access`,{integration:s}),replace:!0});let c=ft(`/system/identity`,{t:e,isAdmin:!0})??{icon:b,title:e(`system.identity`,`Identity & Access`)},l=t.get(`tab`)??`users`,u=t.get(`integration`),d=l===it.access.tab?un(u,n.requestCreate):l===`certificates`?Er(()=>o(!0)):void 0;return r(pt,{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(xr,{})},{id:it.access.tab,label:e(`systemPage.identity.tokensSessions`,`Tokens & sessions`),ownedParams:ot.concat([Tt.token,Tt.scoped,Tt.admin]),content:r(ln,{createRequested:n.createRequested,onCreateConsumed:n.clearCreate})},{id:Tr,label:e(`systemPage.identity.certificates`,`Certificates`),content:r(Zn,{pairOpen:i,onPairClose:()=>o(!1)})},{id:it.authentication.tab,label:e(`systemPage.identity.authentication`,`Authentication`),content:r(Vt,{}),ownedParams:ot}]})}export{Dr as IdentityPage};
@@ -0,0 +1 @@
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{Jn as f,Or as ee,Tr as p,V as te,Yn as m,Yt as h,ct as ne,er as re,gt as ie,kn as g,ra as _,zn as v}from"./player-overlays-BZByYYB8.js";import{Mr as y}from"./client-mnldOm50.js";import{t as ae}from"./link-2-off-DmsjRAt7.js";import{Ci as oe,Dt as se,Hr as b,In as x,Ir as S,Js as ce,Lr as C,Mt as le,Rr as w,Si as ue,Sn as T,Ti as E,Un as de,Vn as fe,Vr as D,Xr as pe,ji as O,kt as k,lr as A,of as j,pa as M,xn as N,ya as P}from"./src-DKRp5NPI.js";import{t as F}from"./useTranslation-BJr-n0es.js";import{n as I}from"./addon-icons-context-Bb2eBZv3.js";import{$ as me,J as L,Q as he,Rr as ge,Vr as R,X as _e,Y as z,at as ve,ct as ye,et as B,it as V,nt as be,ot as xe,r as H,rt as Se,st as Ce,tt as we,zr as Te}from"./index-D5GcZJtC.js";import{t as U}from"./NodeAddonsSettingsPanel-BtSyXQ4v.js";s();var Ee=[[[`addons`,`listCapabilityProviders`]],[[`addons`,`list`]]],W=`text-[10px]`;function G(){let e=l();return M({onSuccess:()=>{for(let t of Ee)e.invalidateQueries({queryKey:t})}})}function K({addonId:e,displayName:t,message:n}){let{t:r}=F(),a=ne(),o=G();return i(j,{icon:o.isPending?p:v,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 De({addonId:e,displayName:t,iconOnly:n=!1,description:r}){let{t:a}=F(),o=G(),s=r??a(`integrationHub.addonControls.restartingTheAddonBouncesIts`,`Restarting the addon bounces its subprocess — the provider will briefly drop and reconnect automatically.`);return n?i(K,{addonId:e,displayName:t,message:s}):i(x,{label:a(`integrationHub.addonControls.restart`,`Restart`),icon:v,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 Oe=600,q=c(null);function J({id:n,title:r,icon:a,actions:o,framed:s=!1,children:c}){let{t:l}=F(),f=d(q),p=t(null),m=`integration-section-${n}`;Y(p,f,n);let h=e(u,{children:[f===null?null:i(R,{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(ee,{className:`h-3 w-3`,"aria-hidden":!0})}),o]});return s?i(`div`,{ref:p,className:`scroll-mt-4`,children:i(fe,{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:`${te} min-w-0 flex-1`,children:r}),h]}),c]})}function Y(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()},Oe);return()=>{window.clearTimeout(o);for(let e of a)window.removeEventListener(e,i)}},[r,i,e])}s();var X=`max-h-72`,Z=[{kind:`logs`,labelKey:`common.logs`,icon:g},{kind:`events`,labelKey:`common.events`,icon:_}];function ke({addonId:t,switcher:n}){let{t:r}=F(),[a,s]=o(`logs`);return e(J,{id:H,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:Z.map(({kind:t,labelKey:n,icon:o})=>e(O,{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(T,{addonId:t,maxHeight:X,showFilters:!1}):i(N,{addonId:t,category:`addon.*`,maxHeight:X})]})}function Q({addonId:t,title:n=`Settings`,subtitle:r,fieldScope:a,onClose:o}){return i(S,{open:!0,onOpenChange:e=>!e&&o(),children:e(w,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-3xl`,children:[e(D,{children:[i(b,{children:n}),r&&i(`p`,{className:`text-xs text-foreground-subtle`,children:r})]}),i(C,{children:i(U,{nodeId:null,addonIds:[t],level:`global`,...a===void 0?{}:{fieldScope:a}})})]})})}function Ae({addonId:e,title:t,onClose:n}){return i(Q,{addonId:e,title:t,fieldScope:`cluster`,onClose:n})}s();var $={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 je({addonId:e,fallback:t,tileClassName:n,size:r=`md`}){let[a,s]=o(!1),c=I(e),l=$[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 Me={ok:`bg-success`,off:`bg-foreground-subtle/60`,error:`bg-danger`,unknown:`border border-foreground-subtle bg-transparent`};function Ne(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 Pe({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(O,{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(je,{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 ${Me[t.health]}`,"aria-hidden":!0}),i(`span`,{className:`sr-only`,children:Ne(s,t.health)})]},t.addonId))}),o!==void 0&&e(R,{to:y(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(f,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),i(`span`,{className:`truncate`,children:o.label})]})]})})}function Fe({providers:t,title:n,onPick:r,onCancel:a}){let{t:o}=F();return e(k,{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 Ie(e){let t=ce({onSuccess:e.onSuccess,onError:t=>e.onError?.(t.message)});return{mutate:e=>t.mutate({...e}),isPending:t.isPending}}s();function Le({row:t,pinning:n,onChanged:r}){let{t:a}=F(),s=l(),[c,u]=o(null),d=Ie({onSuccess:()=>{u(null),s.invalidateQueries({queryKey:[z]}),r?.()},onError:u});return e(`span`,{className:`flex flex-col items-end gap-1`,children:[i(A,{checked:t.enabled,disabled:d.isPending,"aria-label":a(`providerInstances.enable`,`Enable {{name}}`,{name:t.name}),"data-testid":`instance-switch-${t.id}`,onCheckedChange:e=>{u(null),d.mutate({addonId:t.addonId,id:t.id,enabled:e})}}),n>0&&i(`span`,{className:`text-[11px] text-foreground-subtle`,children:a(`providerInstances.pinnedBy`,{count:n})}),c!==null&&i(`span`,{className:`text-[11px] text-danger`,role:`alert`,children:a(`providerInstances.switchFailed`,`Could not change {{name}}: {{message}}`,{name:t.name,message:c})})]})}s();var Re=`instance`;function ze(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 Be({row:t}){let{t:n}=F();return t.enabled?e(`span`,{className:`flex flex-wrap items-center gap-1`,children:[i(E,{variant:t.configured?`success`:`default`,children:t.configured?n(`providerInstances.configured`,`Configured`):n(`providerInstances.notConfigured`,`Not configured`)}),t.status!==void 0&&i(E,{variant:t.status.state===`error`?`danger`:t.status.state===`ok`?`success`:`default`,title:ze(t),children:V(t.status)})]}):i(`span`,{className:`flex flex-wrap items-center gap-1`,children:i(E,{variant:`default`,children:n(`providerInstances.off`,`Off`)})})}function Ve({row:e,functionCap:t}){let{t:n}=F(),r=l(),a=P({onSuccess:()=>void r.invalidateQueries()});return i(A,{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 He({functionCap:t,icon:a,title:s,subtitle:c,emptyTitle:d,emptyDescription:te,addLabel:g,install:_,extraColumns:v,lead:y,rowActions:b,fixedRowActions:x,canDelete:S,pageActions:ce,typedId:C,rowFilter:w}){let{t:T}=F(),D=ie(),k=l(),A=ne(),M=_e(t),N=se({editKey:Re,newKey:`${Re}-new`}),[P,I]=o(null),[L,R]=o(null),V=ue({functionCap:`notification-output`}),H=r(e=>ve(V.data??[],e).length,[V.data]),[Se,we]=o(null),[U,Ee]=o(null),W=n(()=>he(M.holders),[M.holders]),G=n(()=>be(M.functionProviders,M.rows,M.displayNames),[M.functionProviders,M.rows,M.displayNames]),K=G.some(e=>e.addonId===U)?U:null,Oe=n(()=>{let e=me(M.rows,K);return w===void 0?e:e.filter(w)},[M.rows,K,w]),q=r(e=>M.displayNames.get(e)??e,[M.displayNames]),J=r(async e=>{I(e.key),R(null);try{let t=await D.trpcClient.integrationInstances.testInstance.mutate({addonId:e.addonId,id:e.id,values:{}});R({name:e.name,verdict:ye(t)})}catch(t){let n=t instanceof Error?t.message:String(t);R({name:e.name,verdict:{status:`inconclusive`,error:n}})}finally{I(null)}},[D]),Y=r(async e=>{let t=ve(V.data??[],e.id),n=t.length>0?` ${T(`providerInstances.deletePinned`,`These notification targets use it and will stop delivering: {{names}}.`,{names:t.join(`, `)})}`:``;if(await A({title:T(`providerInstances.deleteTitle`,`Delete {{name}}?`,{name:e.name}),message:`${T(`providerInstances.deleteMessage`,`The record and its stored credentials are removed.`)}${n}`,confirmLabel:T(`common.delete`,`Delete`),variant:`danger`}))try{await D.trpcClient.integrationInstances.deleteInstance.mutate({addonId:e.addonId,id:e.id}),await k.invalidateQueries({queryKey:[z]})}catch(t){xe({title:T(`providerInstances.deleteFailed`,`Could not delete`),message:`${e.name}: ${t instanceof Error?t.message:String(t)}`,severity:`critical`})}},[A,k,D,T,V.data]),X=n(()=>M.rows.some(e=>e.kind===`instance`&&e.kindLabel!==void 0),[M.rows]),Z=r((e,t)=>{e!==void 0&&Te(ge(e,t),()=>{k.invalidateQueries({queryKey:[z]})})},[k]),ke=n(()=>[{key:`name`,nowrap:!1,header:T(`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:T(`providerInstances.colProvider`,`Provider`),sortValue:e=>e.providerName,render:e=>i(`span`,{className:`text-foreground-muted`,children:e.providerName})},...X?[{key:`kind`,header:T(`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:T(`instances.colStatus`,`Status`),notSortableReason:T(`providerInstances.stateNotSortable`,`A row carries a badge, not a value to order by.`),render:e=>e.kind===`instance`?i(Be,{row:e}):i(E,{variant:e.isActive?`success`:`default`,children:e.isActive?T(`instances.active`,`Active`):T(`providerInstances.off`,`Off`)})},{key:`on`,header:T(`providerInstances.colOn`,`On`),notSortableReason:T(`providerInstances.onNotSortable`,`A switch is not a value to order by.`),render:e=>e.kind===`fixed`?i(Ve,{row:e,functionCap:t}):i(Le,{row:e,pinning:H(e.id)})},...v??[],{key:`actions`,align:`right`,notSortableReason:T(`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:ee,variant:`ghost`,size:`sm`,"aria-label":T(`providerInstances.connectRow`,`Connect {{name}}`,{name:t.name}),onClick:()=>Z(t.connectPath,t.id)}),t.kind===`instance`&&t.disconnectPath!==void 0&&i(j,{icon:ae,variant:`ghost`,size:`sm`,"aria-label":T(`providerInstances.disconnectRow`,`Disconnect {{name}}`,{name:t.name}),onClick:()=>Z(t.disconnectPath,t.id)}),t.kind===`instance`&&t.canTest&&i(j,{icon:P===t.key?p:m,variant:`ghost`,size:`sm`,"aria-label":T(`providerInstances.testRow`,`Test {{name}}`,{name:t.name}),disabled:P!==null,onClick:()=>void J(t)}),t.kind===`instance`&&b?.(t),t.kind===`fixed`&&x?.(t),i(j,{icon:re,variant:`ghost`,size:`sm`,"aria-label":T(`providerInstances.editRow`,`Edit {{name}}`,{name:t.name}),onClick:()=>N.openEdit(B(t.addonId,t.kind===`instance`?t.id:void 0))}),i(De,{iconOnly:!0,addonId:t.addonId,displayName:t.providerName,description:T(`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`&&(S?.(t)??!0)&&i(j,{icon:h,variant:`ghost`,size:`sm`,"aria-label":T(`providerInstances.deleteRow`,`Delete {{name}}`,{name:t.name}),onClick:()=>void Y(t)})]})}],[v,N,t,H,b,x,S,Y,Z,J,X,T,P]),Q;Q=M.state===`error`?i(`div`,{className:`p-3`,children:i(oe,{title:T(`providerInstances.loadFailed`,`Could not load the list`),message:M.error??``,onRetry:M.refetch})}):M.state===`pending`?e(`div`,{className:`flex items-center gap-2 p-3 text-xs text-foreground-subtle`,children:[i(p,{className:`h-3 w-3 animate-spin`}),T(`providerInstances.loading`,`Loading…`)]}):M.rows.length===0?i(pe,{icon:a,title:d,description:te}):i(de,{columns:ke,rows:Oe,rowKey:e=>e.key,bordered:!1,emptyMessage:T(`instances.noneForProvider`,`This provider has no instance yet.`)});let Ae=M.holders.filter(e=>!W.includes(e)).map(e=>q(e.addonId)),$=W.length>0?void 0:Ae.length>0?T(`instances.addBlocked`,`{{names}}: only one instance is allowed and it already exists.`,{names:Ae.join(`, `)}):T(`instances.addNone`,`No provider here can hold instances.`);return e(fe,{headingId:`provider-instances-${t}`,title:s,icon:a,children:[i(`p`,{className:`px-3 pt-2 text-xs text-foreground-muted`,children:c}),M.state===`ready`&&$!==void 0&&i(`p`,{className:`px-3 pt-1 text-[11px] text-foreground-subtle`,children:$}),M.state===`ready`&&e(u,{children:[e(le,{children:[ce?.(M.rows.filter(e=>e.kind===`instance`)),e(O,{size:`sm`,variant:`primary`,disabled:$!==void 0,title:$,onClick:()=>{let e=W.find(e=>e.addonId===K)??(W.length===1?W[0]:void 0);e===void 0?N.openNew():N.openEdit(B(e.addonId,null))},children:[i(f,{className:`h-3.5 w-3.5`}),g]})]}),i(Pe,{pills:G,selected:K,onSelect:Ee,fallbackIcon:a,..._===void 0?{}:{install:_}})]}),Q,M.state===`ready`&&M.rows.length>0&&i(Ue,{rows:M.rows,selected:Se,onSelect:we}),L!==null&&e(`div`,{className:`space-y-1 p-3`,children:[i(`p`,{className:`text-[11px] font-medium text-foreground`,children:L.name}),i(Ce,{verdict:L.verdict})]}),M.state===`ready`&&N.state.mode===`new`&&i(Fe,{title:g,providers:W.map(e=>({addonId:e.addonId,name:q(e.addonId),description:M.descriptions.get(e.addonId)??``})),onPick:e=>N.openEdit(B(e,null)),onCancel:N.close}),M.state===`ready`&&N.state.mode===`edit`&&i(We,{refValue:N.state.id,data:M,nameOf:q,onClose:N.close,onOpen:(e,t)=>N.openEdit(B(e,t)),...y===void 0?{}:{lead:y},...C===void 0?{}:{typedId:C}},N.state.id)]})}function Ue({rows:e,selected:t,onSelect:r}){let{t:a}=F(),o=n(()=>Se(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(ke,{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(O,{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 We({refValue:e,data:t,nameOf:n,onClose:r,onOpen:a,lead:o,typedId:s}){let c=we(e);if(c.kind===`fixed`)return i(Ae,{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(Ge,{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 Ge(e){let{onOpen:n,onClose:r,onSaved:a,...o}=e,s=t(null),c=e.instance===null;return i(L,{...o,onSaved:e=>{c&&(s.current=e),a?.(e)},onClose:()=>{s.current===null?r():n(e.addonId,s.current)}})}export{je as n,W as r,He as t};
@@ -0,0 +1 @@
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,x as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Aa as d,Di as f,En as p,Et as m,Fn as h,Hn as g,Jn as _,Kt as v,Ni as y,Sa as b,Tr as x,Vi as S,Yt as C,ga as w,gt as T,ii as E,kn as D,li as O,ri as k,zi as A,zn as j}from"./player-overlays-BZByYYB8.js";import{Zo as M}from"./client-mnldOm50.js";import{t as N}from"./chevron-down-CBb-F8DT.js";import{t as P}from"./search-x-C5ra3Aft.js";import{$s as F,Br as ee,Cf as I,Ci as L,Co as R,Df as z,Do as B,Eo as V,Fo as H,Gs as U,Hr as W,In as te,Io as ne,Ir as re,Js as ie,Ka as ae,Kn as oe,Ko as G,Kt as se,Lr as K,Mo as ce,Qs as le,Ro as ue,Rr as q,Sn as J,So as de,To as fe,Vo as pe,Vr as me,Yo as he,Yt as ge,Zs as _e,a as ve,af as ye,ar as be,bi as xe,cr as Y,ec as Se,fr as Ce,i as we,ji as X,jo as Te,ko as Ee,lr as De,ns as Oe,or as Z,pa as ke,qa as Ae,qt as je,rs as Me,sr as Ne,tc as Pe,wo as Fe,xs as Ie}from"./src-DKRp5NPI.js";import{t as Q}from"./useTranslation-BJr-n0es.js";import{n as Le}from"./addon-icons-context-Bb2eBZv3.js";import{Br as Re,Gr as ze,J as Be,Kr as Ve,Wr as He,b as Ue,lt as $,q as We,v as Ge,y as Ke}from"./index-D5GcZJtC.js";import{t as qe}from"./useAdminDeviceRemoval-Ds-ZvGNc.js";import{t as Je}from"./device-integration-icon-DSKbNj0K.js";import{n as Ye,o as Xe,t as Ze}from"./ScanSubnetEditor-L1fLOCgh.js";c();function Qe(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Qe(n.fields));return t}function $e(e,t,i){let[a,s]=o(`idle`),[c,l]=o({}),u=n(()=>{let t=[];for(let n of e.sections)t.push(...Qe(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 et(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(...et(n.fields));return t}function tt(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function nt(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){nt(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function rt(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function it(e,t){let n=Oe({addonId:e,integrationId:t}),r=n.data?.deviceType??null,i=pe({addonId:e,integrationId:t,type:r??M.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 at({integrationId:t,addonId:s,onClose:c}){let{t:d}=Q(),f=l(),[p,h]=o({}),[g,_]=o(!1),[y,b]=o(null),[S,C]=o(rt),w=Oe({addonId:s,integrationId:t},{enabled:!0}),T=w.data?.deviceType??null,E=pe({addonId:s,integrationId:t,type:T??M.Camera},{enabled:w.isSuccess&&T!==null}),O=E.data??null;a(()=>{h(O?nt(O.sections.flatMap(e=>e.fields)):{}),C(rt()),_(!1),b(null)},[!0,t,O]);let k=n(()=>({...p,_probeRequestId:S}),[p,S]),A=Te({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),j=Ie(),P=r(async(e,t)=>{_(!0);let n=await j.mutateAsync({addonId:s,type:T??M.Camera,key:e,value:t,formValues:k});return n.status===`ok`&&n.suggestedValues&&h(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))tt(e[i])&&!tt(a)&&(r[i]=a,t=!0);return t?r:e}),n},[j,s,k,T]),{testAllStatus:F,hasProbeFields:I,probeResults:L,handleTestAll:R,clearProbeResult:z}=$e(O??{sections:[]},p,P);async function B(e){b(null);try{await A.mutateAsync({addonId:s,type:T??M.Camera,config:p,integrationId:t}),e?h(O?nt(O.sections.flatMap(e=>e.fields)):{}):c()}catch(e){b(e instanceof Error?e.message:String(e))}}let V=et((O?.sections??[]).flatMap(e=>e.fields)).filter(e=>tt(p[e])),H=V.length===0,U=w.isLoading||T!==null&&E.isLoading,W=w.isError||w.isSuccess&&T===null||E.isError||E.isSuccess&&O===null;return e(u,{children:[i(K,{className:`space-y-3`,children:U?i(`div`,{className:`flex items-center justify-center py-8`,children:i(x,{className:`h-5 w-5 animate-spin text-primary`})}):W?e(`div`,{className:`flex items-start gap-3 rounded-lg border border-danger/40 bg-danger/10 px-4 py-3`,children:[i(v,{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:d(`integrations.addDeviceDialog.providerUnavailable`,`Provider unavailable`)}),i(`p`,{className:`text-xs text-foreground-subtle`,children:i(Re,{i18nKey:`integrations.addDeviceDialog.notReady`,values:{addonId:s},components:{mono:i(`span`,{className:`font-mono`})}})})]})]}):i($,{schema:O,values:p,onChange:h,onTestField:P,probeResults:L,onClearProbe:z})}),!W&&!U&&e(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[e(X,{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(D,{className:`h-3.5 w-3.5`}),d(`integrations.addDeviceDialog.testLogs`,`Test logs`),i(`span`,{className:`font-mono text-[9px] opacity-60`,children:S.slice(0,14)})]}),i(N,{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(J,{addonId:s,requestId:S,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!W&&!U&&(y||V.length>0)&&i(`div`,{className:`border-t border-danger/30 bg-danger/5 px-3 py-2 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(v,{className:`h-3.5 w-3.5 text-danger mt-0.5 shrink-0`}),i(`p`,{className:`text-[11px] text-danger`,children:y||d(`integrations.addDeviceDialog.required`,`Required: {{value1}}`,{value1:V.join(`, `)})})]})}),e(ee,{className:`justify-between`,children:[e(`div`,{className:`flex items-center gap-2`,children:[i(X,{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:d(`integrations.cancel`)}),!W&&I&&e(X,{variant:`unstyled`,type:`button`,onClick:R,disabled:F===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[F===`testing`?i(x,{className:`h-3.5 w-3.5 animate-spin`}):i(m,{className:`h-3.5 w-3.5`}),d(`integrations.addDeviceDialog.testAll`,`Test All`)]})]}),e(`div`,{className:`flex items-center gap-2`,children:[i(X,{variant:`unstyled`,onClick:()=>B(!0),disabled:W||!H||A.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:d(`integrations.saveAndNew`)}),i(X,{variant:`unstyled`,onClick:()=>B(!1),disabled:W||!H||A.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:A.isPending?d(`integrations.saving`):d(`integrations.save`)})]})]})]})}var ot=1500;function st({addonId:t,integrationId:n,jobId:r,onFinished:a}){let{t:o}=Q(),s=R(),c=(V({addonId:t,integrationId:n},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?ot:!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 p=[`${u}/${c.total} ${o(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];c.adopted>0&&p.push(`${c.adopted} ${o(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),c.alreadyAdopted>0&&p.push(`${c.alreadyAdopted} ${o(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),c.failed>0&&p.push(`${c.failed} ${o(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let m=p.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(x,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):c.failed>0?i(v,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):c.state===`cancelled`?i(f,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):i(y,{className:`h-3.5 w-3.5 text-primary shrink-0`}),i(`p`,{className:`text-[11px] text-foreground`,children:m}),l&&i(X,{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 ct(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(Xe(t),0)}function lt(e){let t=e.metadata?.model,n=e.childNativeId.split(`:`).pop()??``;return[typeof t==`string`?t:``,n].filter(e=>e.length>0).join(` · `)}function ut(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 dt=`devices`;function ft(e){return{id:dt,label:e(`integrations.adoptDevicesModal.defaultFilter`),isDefault:!0}}var pt=2e4,mt=100;function ht({addonId:s,integrationId:c,onClose:f}){let p=d(),{t:m}=Q(),g=l(),[_,y]=o(new Set),[C,w]=o(new Set),[T,E]=o(new Map),[D,O]=o(null),{data:k}=F(),A=(k??[]).find(e=>e.addonId===s)?.supportsLocationImport??!1,[j,M]=o(!0),N=Fe({addonId:s,integrationId:c}).data?.filters,P=N&&N.length>0?N:[ft(m)],[L,R]=o(P.find(e=>e.isDefault)?.id??(P.some(e=>e.id===dt)?dt:P[0].id)),V=L!==dt,H=B(),U=fe({addonId:s,integrationId:c,page:1,pageSize:pt,filter:L}),W=U.refetch,te=H.mutate,ne=r(()=>{te({addonId:s,integrationId:c},{onSettled:()=>{W()}})},[te,s,c,W]),re=t(null);a(()=>{let e=`${s}::${c}`;re.current===e||U.isLoading||(re.current=e,(U.data?.candidates.length??0)===0&&ne())},[s,c,U.isLoading,U.data,ne]);let ie=H.isPending,ae=H.isError?H.error instanceof Error?H.error.message:String(H.error):null,oe=typeof H.data?.lastError==`string`&&H.data.lastError.length>0?H.data.lastError:null,G=U.data?.candidates??[],K=n(()=>ct(G),[G]),ce=n(()=>new Map(K.map(e=>[e.candidate.childNativeId,e.depth])),[K]),le=n(()=>new Map(K.map(e=>[e.candidate.childNativeId,e.parentName])),[K]),ue=U.isError?U.error instanceof Error?U.error.message:String(U.error):null,q=Ee(),[J,de]=o(null),pe=r(e=>{e.alreadyAdopted||y(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),me=r(e=>{w(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),he=r((e,t)=>{E(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})},[]),ge=r(e=>{let t={};for(let n of e){let e=T.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[T]),_e=r(async()=>{O(null);let e=[..._];if(e.length!==0)try{let t=ge(e),{jobId:n}=await q.mutateAsync({addonId:s,integrationId:c,filter:L,childNativeIds:e,...t?{perCandidate:t}:{},...A?{importLocations:j}:{}});de(n),y(new Set),E(new Map)}catch(e){O(e instanceof Error?e.message:String(e))}},[_,ge,q,s,c,L,A,j]),ve=t(null),ye=r(()=>{J===null||ve.current===J||(ve.current=J,W(),g.invalidateQueries({queryKey:[[`integrations`]]}),g.invalidateQueries({queryKey:[[`deviceManager`]]}))},[J,W,g]),be=r(e=>{R(e),y(new Set),w(new Set),E(new Map),O(null)},[]),xe=_.size,Y=J!==null&&xe===0&&!q.isPending;return e(u,{children:[A&&e(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[i(b,{checked:j,onChange:e=>M(e.target.checked),className:`accent-primary`}),m(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),e(`div`,{className:`flex-1 min-h-0 flex flex-col gap-2 overflow-hidden`,children:[(ae??ue??oe)&&G.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(v,{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:m(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),i(`p`,{className:`text-[11px] text-danger/90 mt-0.5`,children:ae??ue??oe})]})]})}),P.length>1&&i(gt,{filters:P,activeFilter:L,onSelect:be}),i(`div`,{className:`flex-1 min-h-0`,children:i(se,{mode:`generic`,items:K.map(e=>e.candidate),pageSize:mt,getKey:e=>e.childNativeId,getSearchText:ut,getFilterType:e=>e.type,filterOptions:I(p),filterLabel:m(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:U.isLoading||ie&&G.length===0,searchPlaceholder:m(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(ae??ue??oe)&&G.length===0?``:m(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:e(X,{variant:`unstyled`,type:`button`,onClick:ne,disabled:ie,title:m(`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(h,{className:`h-3.5 w-3.5 ${ie?`animate-spin`:``}`}),m(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:m(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-full sm:w-[55%]`,cellClassName:`max-w-0`,cell:e=>i(_t,{candidate:e,depth:ce.get(e.childNativeId)??0,...le.get(e.childNativeId)===void 0?{}:{containerName:le.get(e.childNativeId)},expandable:!V,expanded:C.has(e.childNativeId),onToggleExpand:()=>me(e.childNativeId),adoptedLabel:m(`integrations.adoptAlready`,{defaultValue:`Adopted`}),typeLabel:z(e.type,p).label})},{key:`type`,header:m(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:t=>{let n=z(t.type,p),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(X,{variant:`unstyled`,onClick:()=>pe(e),disabled:e.alreadyAdopted,"aria-label":_.has(e.childNativeId)?m(`integrations.adoptDevicesModal.deselect`,`Deselect`):m(`integrations.adoptDevicesModal.select`,`Select`),className:`inline-flex h-5 w-5 items-center justify-center rounded border ${_.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:_.has(e.childNativeId)&&i(S,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!V&&C.has(e.childNativeId),renderExpanded:V?void 0:e=>i(vt,{candidate:e,hiddenChildIds:T.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>he(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:_.has(e.childNativeId)?`bg-primary/5`:``})})]}),D&&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(v,{className:`h-3.5 w-3.5 text-danger mt-0.5 shrink-0`}),i(`p`,{className:`text-[11px] text-danger`,children:D})]})}),J!==null&&i(st,{addonId:s,integrationId:c,jobId:J,onFinished:ye}),e(ee,{children:[i(X,{variant:`outline`,size:`sm`,onClick:f,children:m(`integrations.cancel`,{defaultValue:`Cancel`})}),e(X,{variant:`primary`,size:`sm`,onClick:Y?f:_e,disabled:!Y&&(xe===0||q.isPending),children:[q.isPending&&i(x,{className:`h-3.5 w-3.5 animate-spin`}),Y?m(`integrations.close`,{defaultValue:`Close`}):m(`integrations.addSelected`,{defaultValue:`Add selected`}),!Y&&xe>0?` (${xe})`:``]})]})]})}function gt({filters:e,activeFilter:t,onSelect:n}){let{t:r}=Q();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(X,{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 _t({candidate:t,depth:n,containerName:r,expandable:a,expanded:o,onToggleExpand:s,adoptedLabel:c,typeLabel:l}){let{t:u}=Q(),d=(t.children??[]).length,f=lt(t);return e(`div`,{className:`flex items-center gap-2.5 min-w-0 ${n>0?`pl-5`:``}`,children:[a&&d>0?e(X,{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?N:A,{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 vt({candidate:t,hiddenChildIds:n,onToggleChildHidden:r}){let{t:a}=Q(),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(X,{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?E:k,{className:`h-3 w-3`})})]},t.childNativeId)})})}function yt(e){let t=e.host;return typeof t==`string`&&t.length>0?t.toLowerCase():null}function bt(e){return e===null?[]:[`host:${e}`]}function xt(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=yt(t.prefilledConfig),s=r([t.stableId,...bt(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 St=500;function Ct(e){return e instanceof Error?e.message:String(e)}function wt(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 Tt({addonId:t,integrationId:a,onClose:s,onSetupIntegration:c,alongsideAdoption:d=!1}){let{t:f}=Q(),p=l(),m=Me({addonId:t}).data??null,[h,_]=o({}),v=H(),y=he({}),b=fe({addonId:t,integrationId:a,page:1,pageSize:St},{retry:!1}),{data:S}=G({projection:`slim`}),C=de(),w=Ee(),[T,E]=o(new Set),[D,O]=o(new Set),[k,A]=o(null),[j,M]=o(null),N=n(()=>{let e=(b.data?.candidates??[]).map(e=>({childNativeId:e.childNativeId,name:e.name,alreadyAdopted:e.alreadyAdopted,parentStableId:e.parentStableId})),n=(y.data?.proposals??[]).filter(e=>e.addonId===t).map(e=>({id:e.id,candidate:e.candidate}));return xt({adoption:e,scan:v.data?.candidates??[],proposals:n,existingStableIds:new Set((S??[]).map(e=>e.stableId))})},[b.data,y.data,v.data,S,t]),P=e=>e.hit!==null&&(e.needsParams.length>0||e.hit.setupIntegration===!0),F=n(()=>d?N.filter(e=>!e.sources.includes(`adoption`)||P(e)):N,[N,d]),I=d?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(()=>{A(null),v.mutate({addonId:t,params:h})},[v,t,h]),z=r(async(e,t)=>{E(t=>new Set(t).add(e)),A(null);try{await t(),O(t=>new Set(t).add(e)),p.invalidateQueries({queryKey:[[`deviceManager`]]}),p.invalidateQueries({queryKey:[[`integrations`]]})}catch(e){A(Ct(e))}finally{E(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=Ye(t,r);if(i!==null){c?.(i),s();return}await z(e.key,async()=>{await C.mutateAsync({addonId:t,integrationId:a,candidate:{...r,prefilledConfig:{...r.prefilledConfig,...n}}}),M(null)});return}if(e.adoptionId!==null){let n=e.adoptionId;await z(e.key,async()=>{await w.mutateAsync({addonId:t,integrationId:a,childNativeIds:[n]})})}},[C,w,t,a,s,c,z]),V=r(e=>{if(e.needsParams.length>0&&e.hit!==null){A(null),M(e);return}B(e)},[B]);if(j!==null&&j.hit!==null)return i(Ot,{addonId:t,integrationId:a,row:j,found:j.hit.prefilledConfig,busy:T.has(j.key),error:k,embedded:d,onBack:()=>M(null),onSubmit:e=>void B(j,e)});let U=F.length===0,W=e(u,{children:[i(Ze,{}),m&&i($,{schema:m,values:h,onChange:_}),e(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[e(`p`,{className:`text-xs text-foreground-subtle`,children:[v.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}):``,!v.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(X,{variant:`outline`,size:`sm`,onClick:R,disabled:v.isPending,children:[v.isPending?i(x,{className:`h-3.5 w-3.5 animate-spin`}):i(g,{className:`h-3.5 w-3.5`}),f(`integrations.addDeviceModal.scanNow`,`Scan now`)]})]}),v.isError&&i(Et,{text:f(`integrations.addDeviceModal.scanFailed`,`The scan failed. Try again.`)}),k!==null&&i(Et,{text:k}),U&&!v.isPending&&i(`p`,{className:`py-6 text-center text-xs text-foreground-subtle`,children:v.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:d?`max-h-48 space-y-1.5 overflow-y-auto`:`space-y-1.5`,"data-testid":`network-candidates`,children:F.map(e=>i(Dt,{row:e,depth:L(e),busy:T.has(e.key),added:D.has(e.key),onPick:V},e.key))})]});return d?i(`div`,{className:`shrink-0 space-y-3 border-b border-border pb-3`,children:W}):e(u,{children:[i(K,{className:`space-y-3`,children:W}),i(ee,{children:i(X,{variant:`outline`,size:`sm`,onClick:s,children:f(`integrations.close`,`Close`)})})]})}function Et({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(v,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-danger`}),i(`p`,{className:`text-xs text-danger`,children:t})]})}function Dt({row:t,depth:n,busy:r,added:a,onPick:o}){let{t:s}=Q(),c=t.alreadyAdded||a,l=t.hit!==null&&Ye(``,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(S,{className:`h-3.5 w-3.5`}),t.alreadyAdded?s(`integrations.scanNetworkModal.alreadyAdded`,`Already added`):s(`integrations.scanNetworkModal.added`,`Added`)]}):u?e(X,{size:`sm`,variant:l||d?`outline`:`primary`,onClick:()=>o(t),disabled:r,children:[r?i(x,{className:`h-3.5 w-3.5 animate-spin`}):l||d?null:i(O,{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 Ot({addonId:t,integrationId:n,row:r,found:a,busy:s,error:c,onBack:l,onSubmit:d,embedded:f}){let{t:p}=Q(),m=Oe({addonId:t,integrationId:n}),h=m.data?.deviceType??null,g=pe({addonId:t,integrationId:n,type:h??M.Camera},{enabled:m.isSuccess&&h!==null}),_=g.data??null,[v,y]=o(null),b=v??wt(_,a),S=m.error??g.error,C=m.isSuccess&&h===null,T=_!==null,E=T?i($,{schema:_,values:b,onChange:y}):S?i(Et,{text:Ct(S)}):C?i(`p`,{className:`text-xs text-foreground-muted`,children:p(`integrations.addDeviceModal.noCreationType`,`This integration cannot create a device from this candidate.`)}):i(x,{className:`mx-auto h-5 w-5 animate-spin text-primary`}),D=e(u,{children:[e(X,{variant:`ghost`,size:`sm`,onClick:l,children:[i(w,{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}),E,c!==null&&i(Et,{text:c})]}),O=e(u,{children:[i(X,{variant:`outline`,size:`sm`,onClick:l,children:p(`integrations.cancel`,`Cancel`)}),e(X,{variant:`primary`,size:`sm`,onClick:()=>d(b),disabled:s||!T,children:[s&&i(x,{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:[D,i(`div`,{className:`flex justify-end gap-2`,children:O})]}):e(u,{children:[i(K,{className:`space-y-3`,children:D}),i(ee,{children:O})]})}c();function kt(e){return e===`manual`?`manual`:e===`pairing`?`pairing`:`network`}function At({addonId:t,integrationId:n,kind:r,canScan:a,onClose:s,pairing:c,onSetupIntegration:l}){let{t:d}=Q(),f=it(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(K,{children:i(x,{className:`mx-auto h-5 w-5 animate-spin text-primary`})}):r===`device-adoption`?e(u,{children:[a===!0&&i(Tt,{addonId:t,integrationId:n,onClose:s,alongsideAdoption:!0,...l?{onSetupIntegration:l}:{}}),i(ht,{addonId:t,integrationId:n,onClose:s})]}):i(Tt,{addonId:t,integrationId:n,onClose:s,...l?{onSetupIntegration:l}:{}}),S=i(at,{integrationId:n,addonId:t,onClose:s});return i(re,{open:!0,onOpenChange:e=>{e||s()},children:e(q,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,className:r===`device-adoption`?`md:h-[85vh]`:void 0,children:[i(me,{children:i(W,{children:d(`integrations.addDevice`,`Add device`)})}),y>1?e(be,{value:v,onValueChange:e=>_(kt(e)),children:[e(Ne,{children:[m&&i(Y,{value:`network`,children:d(`integrations.addDeviceModal.tabNetwork`,`Found on the network`)}),h&&i(Y,{value:`manual`,children:d(`integrations.addDeviceModal.tabManual`,`Enter parameters`)}),c!==void 0&&i(Y,{value:`pairing`,children:c.label})]}),m&&i(Z,{value:`network`,children:b}),h&&i(Z,{value:`manual`,children:S}),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?S:f===`loading`?i(K,{children:i(x,{className:`mx-auto h-5 w-5 animate-spin text-primary`})}):i(K,{children:i(`p`,{className:`py-6 text-center text-xs text-foreground-subtle`,children:d(`integrations.addDeviceModal.nothingToAdd`,`This integration has no way to add a device from here.`)})})]})})}c();var jt=`matter`,Mt=[`discovering`,`pase`,`commissioning`,`done`];function Nt(e){return!(typeof e!=`object`||!e||!(`phase`in e)||typeof e.phase!=`string`)}function Pt(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 Ft({onClose:t,onCommissioned:n}){let{t:r}=Q(),s=ve({kind:jt}),[c,l]=o(null),d=we(s.data??[],c),f=d.length,p=c??d[0]?.id??null,m=Ae(),[h,g]=o(``),[_,v]=o({phase:`idle`,failure:null,message:null}),y=_.phase===`discovering`||_.phase===`pase`||_.phase===`commissioning`,b=ae({brokerId:p??``,key:`commission`},{enabled:p!==null&&y,refetchInterval:y?400:!1});a(()=>{y&&Nt(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 S=()=>{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})}}))},C=_.phase===`failed`?Pt(_.failure,_.message):null,w=C===null?null:r(C.key,{defaultValue:C.defaultValue}),T=(s.isSuccess===!0||s.data!==void 0)&&p===null;return e(u,{children:[e(K,{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.`})}),(T||f>1)&&!y&&_.phase!==`done`&&e(`div`,{className:`space-y-1.5`,children:[i(Ce,{children:r(`integrations.addMatter.broker`,{defaultValue:`Matter fabric`})}),i(We,{kind:jt,value:p,onChange:l})]}),!T&&e(`div`,{className:`space-y-1.5`,children:[i(Ce,{htmlFor:`matter-pairing-code`,children:r(`integrations.addMatter.code`,{defaultValue:`Pairing code`})}),i(ye,{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:Mt.map(t=>{let n=_.phase===t;return e(`li`,{className:`text-xs ${n?`text-foreground font-medium`:`text-foreground-subtle`}`,children:[n&&y?i(x,{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)})}),w!==null&&i(L,{message:w})]}),e(ee,{children:[i(X,{variant:`ghost`,size:`sm`,onClick:t,children:r(`common.close`,{defaultValue:`Close`})}),_.phase===`done`?i(X,{size:`sm`,onClick:n,children:r(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}):i(X,{size:`sm`,disabled:y||T||h.trim().length===0,onClick:S,children:y?r(`integrations.addMatter.working`,{defaultValue:`Adding…`}):r(`integrations.addMatter.submit`,{defaultValue:`Add device`})})]})]})}function It({addonId:t,integrationId:n,name:r,onClose:a,onSaved:o}){let{t:c}=Q(),l=T(),u=s({queryKey:[`integration-instance-describe`,t],queryFn:()=>l.trpcClient.integrationInstances.describe.query({addonId:t})}),d=s({queryKey:[`integration-instance`,t,n],queryFn:()=>l.trpcClient.integrationInstances.getInstance.query({addonId:t,id:n})});if(u.isSuccess&&d.isSuccess&&d.data!==null)return i(Be,{addonId:t,providerName:r,description:u.data,instance:d.data,onClose:a,onSaved:()=>o()});let f=u.isError||d.isError||d.isSuccess&&!d.data;return i(re,{open:!0,onOpenChange:e=>!e&&a(),children:e(q,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(me,{children:e(W,{children:[c(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,r]})}),i(K,{children:f?i(`p`,{className:`text-[11px] text-danger`,children:c(`integrations.loadFailed`,{defaultValue:`Could not load this integration.`})}):e(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[i(x,{className:`h-3 w-3 animate-spin`}),c(`integrations.loading`,{defaultValue:`Loading…`})]})})]})})}c();function Lt(){let{addonId:e=``}=ze();return i(zt,{addonId:e})}function Rt(){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 zt({addonId:t}){let{t:c}=Q(),u=l(),d=He(),[f,m]=Ve(),h=T(),[g,v]=o(!1),y=r(e=>{v(!1),d(`/integrations`,{state:{integrationSeed:e}})},[d]),[b,S]=o(!1),[E,O]=o(!1),{data:k}=Se(void 0),A=n(()=>(k??[]).filter(e=>e.addonId===t),[k,t]),M=Ue(f.get(`instance`),A)??``,N=r(e=>{m(t=>{let n=new URLSearchParams(t);return n.set(Ge,e),n},{replace:!0})},[m]),ee=n(()=>A.map(e=>({value:e.id,label:e.name})),[A]),{data:I,isLoading:L}=le({id:M},{enabled:!!M}),{data:R,isSuccess:z}=F(),B=n(()=>{let e=I?.addonId;return!e||!z?null:(R??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[R,I?.addonId,z]),{data:V,isPending:H}=ne({}),ae=n(()=>H?null:(V?.providers??[]).some(e=>e.addonId===I?.addonId),[H,V,I?.addonId]),de=B!==null,fe=I?.info?.fixed===!0,pe=n(()=>{let e=I?.addonId;return!e||!z?null:(R??[]).find(t=>t.addonId===e)?.brokerKind??null},[R,I?.addonId,z])===`matter`,he=de?c(`integrations.addDevice`,`Add device`):c(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),ve=n(()=>{let e=I?.addonId;return!e||!z?null:(R??[]).find(t=>t.addonId===e)?.mode??null},[R,I?.addonId,z]);a(()=>{f.get(`add`)===`1`&&de&&(v(!0),m(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[f,de,m]);let{data:ye}=s({queryKey:[`integration-instance-form`,I?.addonId,I?.id],enabled:!!I?.addonId&&!!I?.id,queryFn:()=>h.trpcClient.integrationInstances.instanceFormSchema.query({addonId:I?.addonId??``,id:I?.id??``})}),be=ye!=null&&Array.isArray(ye.sections)&&ye.sections.some(e=>e.fields.length>0),{data:Y}=G({projection:`slim`},{refetchInterval:3e4}),Ce=[[`integrations`,`get`],{input:{id:M},type:`query`}],we={onMutate:async e=>{await u.cancelQueries({queryKey:Ce});let t=u.getQueryData(Ce);return t!=null&&u.setQueryData(Ce,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&u.setQueryData(Ce,r.previous)},onSettled:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}},Te=ie(we),Ee=Pe(we),Oe={isPending:Te.isPending||Ee.isPending,mutate:e=>fe&&I?.processState!==`running`?Ee.mutate({id:e.id,enabled:e.enabled}):Te.mutate(e)},Z=I?.switchUnknown===!0,Ae={onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]}),d(A.length>1?Ke(t):`/integrations`)}},Me=U(Ae),Ne=_e(Ae),Fe=I?.processState===`running`,Ie={isPending:Me.isPending||Ne.isPending,mutateAsync:async e=>{Fe?await Me.mutateAsync(e):await Ne.mutateAsync({id:e.id})}},Le=ke({onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Re=qe(),ze=ce({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Be=ue({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),$=n(()=>Y??[],[Y]),We=n(()=>{let e=new Map;for(let t of $)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[$]),Ye=r(e=>We.get(e)??null,[We]),Xe=n(()=>je(k),[k]),Ze=r(e=>d(`/devices/${String(e)}`),[d]),Qe=n(()=>$.filter(e=>{let t=Xe(e);return t.kind===`resolved`&&t.integration.id===M}),[$,M,Xe]),$e=n(()=>k===void 0?null:ge(Qe).length,[k,Qe])??`…`;if(L||k===void 0)return i(Rt,{});let et=(R??[]).find(e=>e.addonId===t)?.name??I?.name??t;return I?e(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[i(oe,{items:[{label:c(`integrationDetail.integrations`,`Integrations`),onClick:()=>d(`/integrations`)},{label:et}]}),e(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[e(`div`,{className:`flex items-center gap-3 min-w-0`,children:[i(Bt,{addonId:I.addonId}),e(`div`,{className:`min-w-0`,children:[i(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:et}),e(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[$e,` `,c(`integrations.devices`)]})]})]}),e(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[!fe&&e(X,{variant:`unstyled`,onClick:()=>{v(!0)},disabled:!de,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:he,children:[i(_,{className:`h-3.5 w-3.5`}),he]}),e(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Oe.isPending?`opacity-60`:``} ${I.enabled&&!Z?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:c(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[i(De,{checked:I.enabled&&!Z,onCheckedChange:e=>Oe.mutate({id:M,addonId:I?.addonId,enabled:e}),disabled:Oe.isPending||Z,"aria-label":Z?c(`integrationDetail.switchUnknown`,`Unknown`):I.enabled?c(`integrationDetail.disableIntegration`,`Disable integration`):c(`integrationDetail.enableIntegration`,`Enable integration`)}),i(`span`,{className:`text-[11px] font-medium ${I.enabled&&!Z?`text-success`:`text-foreground-subtle`}`,children:Z?c(`integrationDetail.switchUnknown`,`Unknown`):I.enabled?c(`integrationDetail.enabled`,`Enabled`):c(`integrationDetail.disabled`,`Disabled`)}),Oe.isPending&&i(x,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),ve!==`standalone`&&(be||B===`device-adoption`)&&e(X,{variant:`unstyled`,onClick:()=>S(!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(p,{className:`h-3 w-3`}),c(`integrations.config`)]}),e(X,{variant:`unstyled`,onClick:()=>O(!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(D,{className:`h-3 w-3`}),c(`integrations.logs`,{defaultValue:`Logs`})]}),i(te,{label:c(`integrationDetail.restart`,`Restart`),icon:j,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:$e}),confirmLabel:c(`integrationDetail.restart`,`Restart`),triggerVariant:`outline`,confirmVariant:`danger`,disabled:Le.isPending,action:()=>Le.mutateAsync({addonId:I.addonId})}),!fe&&M&&i(te,{label:c(`integrations.delete`,{defaultValue:`Delete`}),icon:C,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:$e}),confirmLabel:c(`integrations.confirmDelete`,{defaultValue:`Delete integration`}),triggerVariant:`outline`,confirmVariant:`danger`,className:`border-danger bg-danger/10 text-danger hover:bg-danger hover:text-background`,disabled:Ie.isPending,action:()=>Ie.mutateAsync({addonId:t,id:M})})]})]}),A.length>1&&i(`div`,{className:`max-w-sm`,children:i(xe,{mode:`single`,singleDisplay:`field`,label:c(`integrationDetail.instances`,`Integration`),options:ee,value:M,onChange:N,testId:`integration-instance-picker`,optionTestIdPrefix:`integration-instance`})}),i(se,{context:`integration-detail`,devices:$,trpc:h.trpcClient,integrationOf:Xe,forceIntegrationId:M,urlScope:`root`,lsKey:`integration-detail:${I.addonId}`,resolveIntegrationIcon:Je,resolveParent:Ye,onNavigate:Ze,rowOperation:Re.rowOperation,batchActions:{remove:Re.remove,disable:ze.mutate,enable:Be.mutate},...fe?{}:{onDeleteDevice:e=>Re.remove({deviceId:e.id})}}),g&&M&&B!==null&&i(At,{addonId:I.addonId,integrationId:M,kind:B,canScan:ae,onSetupIntegration:y,...pe?{pairing:{label:c(`integrations.addMatter.tab`,`Pairing code`),render:({onPaired:e})=>i(Ft,{onClose:()=>v(!1),onCommissioned:e})}}:{},onClose:()=>v(!1)}),b&&M&&i(It,{addonId:I.addonId,integrationId:M,name:I.name,onClose:()=>S(!1),onSaved:()=>{u.invalidateQueries()}}),E&&i(re,{open:!0,onOpenChange:e=>!e&&O(!1),children:e(q,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[i(me,{className:`mb-0`,children:e(W,{className:`flex items-center gap-2 min-w-0`,children:[i(D,{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,M?` · ${M}`:``]})]})}),i(K,{className:`min-h-0 overflow-hidden p-0`,children:i(J,{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(P,{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(X,{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(w,{className:`h-3 w-3`}),c(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}function Bt({addonId:e}){let t=Le(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{Lt as IntegrationDetailPage};
@@ -0,0 +1 @@
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{Bi as u,En as d,Hn as f,Jn as p,Ki as m,Kt as h,On as g,Sa as _,Tr as v,V as y,Vi as b,gt as x,jr as S,li as C,qn as w,wa as T,zi as E,zn as D}from"./player-overlays-BZByYYB8.js";import{qs as O}from"./client-mnldOm50.js";import{t as k}from"./chevron-down-CBb-F8DT.js";import{t as ee}from"./table-2-DMxm3oyu.js";import{$i as A,$s as te,Ci as ne,Fo as j,Hr as re,Io as M,Ir as ie,Ko as ae,Ks as oe,Kt as se,Lo as ce,Lr as le,No as ue,Po as de,Rr as fe,So as pe,Vr as me,Ws as he,Yo as ge,Ys as N,Yt as _e,af as P,bt as F,ec as ve,ji as I,o as L,q as ye,qs as R,qt as be,rs as z,sa as xe}from"./src-DKRp5NPI.js";import{t as B}from"./i18n-ByFr51sS.js";import{t as V}from"./useTranslation-BJr-n0es.js";import{Kr as Se,Ur as Ce,W as H,Wr as we,ct as U,lt as Te,q as Ee,st as De,y as Oe}from"./index-D5GcZJtC.js";import{t as ke}from"./AdminPage-_ITsYONa.js";import"./useEventInvalidation-CLxwtH6P.js";import{t as Ae}from"./device-integration-icon-DSKbNj0K.js";import{a as W,i as je,n as G,o as K,r as q,s as J,t as Y}from"./ScanSubnetEditor-L1fLOCgh.js";import{t as Me}from"./framework-packages-B0ugw-Ay.js";s();function Ne(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:Ne(n)}})}function X(e){return e.integrationSection===void 0?Me(e.packageName)?`system`:`providers`:e.integrationSection}function Fe(e){let t=new Set;for(let n of e??[])X(n.manifest)===`system`&&t.add(n.manifest.id);return t}function Ie(e,t){return{providers:e.filter(e=>!t.has(e.addonId)),system:e.filter(e=>t.has(e.addonId))}}function Le(e,t){return[...e].sort((e,n)=>e.name.localeCompare(n.name,t,{sensitivity:`base`}))}var Re=3e3,ze=new Set([`no-provider`,`node-offline`,`transport-failed`]),Be=[`provider not available`,`failed to fetch`,`networkerror`,`load failed`];function Ve(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 He(e,t){if(e==null||t>10)return!1;let n=Ve(e);if(n!==null)return ze.has(n);let r=(e instanceof Error?e.message:String(e)).toLowerCase();return Be.some(e=>r.includes(e))}function Ue(e){return He(e.state.error,e.state.errorUpdateCount)?Re:!1}function Z({kind:t,children:n}){let{t:r}=V(),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:y,children:t===`providers`?r(`integrations.sections.providers`,`Providers`):r(`integrations.sections.system`,`System`)}),n]})}function We({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 Ge({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(I,{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(H,{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 Ke({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(g,{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(qe,{groups:d.providers,onOpen:a})}),d.system.length>0&&i(Z,{kind:`system`,children:i(qe,{groups:d.system,onOpen:a})})]})]})}function qe({groups:e,onOpen:t}){let{t:r,i18n:a}=V();return i(We,{children:n(()=>Le(e,a.language),[e,a.language]).map(e=>i(Ge,{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(F,{status:e.status,className:`shrink-0`})},e.addonId))})}s();var Q=`camstack.admin.integrations.view`;function $(e){return e===`table`||e===`grid`}function Je(){try{return typeof window>`u`?null:window.localStorage}catch{return null}}function Ye(e=Je()){if(e===null)return`table`;try{let t=e.getItem(Q);return $(t)?t:`table`}catch{return`table`}}function Xe(e,t=Je()){if(t!==null)try{t.setItem(Q,e)}catch{}}function Ze(){let[e,t]=o(()=>Ye());return[e,r(e=>{t(e),Xe(e)},[])]}s();function Qe(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 $e(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 et({kind:t,onResolved:n,onBack:r}){let{t:a}=V(),[s,c]=o(null);return e(`div`,{className:`space-y-4`,children:[e(I,{variant:`ghost`,size:`sm`,onClick:r,children:[i(u,{className:`h-3.5 w-3.5`}),` `,a(`common.back`)]}),i(Ee,{kind:t,value:s,onChange:c}),i(`div`,{className:`flex justify-end pt-1`,children:i(I,{variant:`primary`,size:`sm`,disabled:s===null,onClick:()=>s!==null&&n(s),children:a(`integrations.brokerStep.useThisBroker`,`Use this broker`)})})]})}s();function tt({providerId:t,onImport:n,onSkip:r}){let{t:s}=V(),[c,l]=o(new Set),u=de(),d=u.data,f=u.isPending||!u.data&&!u.isError;a(()=>{t&&(u.isPending||u.data||u.mutate({addonId:t}))},[t,u]);function p(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 h=d??[];return e(`div`,{className:`space-y-4`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:h.length>0?s(`integrations.foundDevices`,{count:h.length}):s(`integrations.noDevicesFound`)}),h.length>0&&i(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:h.map(t=>{let n=t.stableId,r=t.suggestedName??n,a=c.has(n),o=t.alreadyOnboarded===!0;return e(I,{variant:`unstyled`,onClick:()=>{o||p(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(b,{className:`h-3 w-3 text-primary-foreground`})}),i(m,{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(I,{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`)}),h.length>0&&e(I,{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 nt({addonId:t,configSchema:n,canTest:r=!0,instanceKind:a,initialName:s,initialConfig:c,submitLabel:l,hideName:u=!1,saving:d=!1,onScan:p,onSave:m,onBack:h}){let{t:g}=V(),[_,v]=o(s??``),[y,b]=o(c??{}),[x,S]=o(null),C=N({onSuccess:e=>S(U(e)),onError:e=>S({status:`inconclusive`,error:String(e)})}),w=A(),T=!r||x?.status===`validated`,E=!u&&_.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:g(`integrations.integrationName`)}),i(P,{id:`integration-name`,type:`text`,value:_,onChange:e=>v(e.target.value),placeholder:g(`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:g(`integrations.nameRequired`,`Name is required`)})]}),n&&i(Te,{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(I,{variant:`unstyled`,onClick:h,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:g(`integrations.back`)}),e(`div`,{className:`flex items-center gap-2`,children:[p&&e(I,{variant:`outline`,size:`sm`,onClick:p,"data-testid":`integration-scan`,children:[i(f,{className:`h-3.5 w-3.5`}),g(`integrations.scanFromForm`,`Scan the network`)]}),i(I,{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:g(`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?g(`integrations.testing`):g(`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:g(`integrations.nameRequiredSubmit`,`Enter a name before continuing.`)}),i(I,{variant:`unstyled`,onClick:()=>{E||m({name:_,config:O(n,y)})},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?g(`integrations.saving`,{defaultValue:`Saving…`}):l??g(`integrations.forward`)})]})]})]})]})}var rt=`(hover: none) and (pointer: coarse)`;function it(){if(typeof window>`u`||typeof window.matchMedia!=`function`)return!0;try{return!window.matchMedia(rt).matches}catch{return!0}}s();function at({onSelect:r,onClose:s,pendingAddonId:c=null}){let{t:l,i18n:u}=V(),f=we(),[p,m]=o(``),h=t(null),{data:_,isLoading:y}=te();a(()=>{y||!it()||h.current?.focus()},[y]);let b=n(()=>{let e=_??[],t=p.trim().toLowerCase();return t.length===0?e:e.filter(e=>`${e.name} ${e.description??``} ${e.addonId}`.toLowerCase().includes(t))},[_,p]),{data:x}=xe(void 0),S=n(()=>{let e=Ie(b,Fe(x));return{providers:Le(e.providers,u.language),system:Le(e.system,u.language)}},[b,x,u.language]);if(y)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 C=c!==null,w=t=>i(We,{children:t.map(t=>{let n=t.instanceMode===`unique`&&t.existingInstances.length>0,a=c===t.addonId;return i(Ge,{testId:`provider-card-${t.addonId}`,buttonTestId:`provider-pick-${t.addonId}`,addonId:t.addonId,name:t.name,openLabel:t.name,disabled:C,onOpen:()=>{if(n){let e=t.existingInstances[0].id;s(),f(Oe(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(v,{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(d,{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(g,{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:h,type:`search`,value:p,onChange:e=>m(e.target.value),placeholder:l(`integrations.searchProviders`,`Search integrations…`),className:`pl-8`,"data-testid":`provider-picker-search`,"aria-label":l(`integrations.searchProviders`,`Search integrations…`)})]}),S.providers.length>0&&i(Z,{kind:`providers`,children:w(S.providers)}),S.system.length>0&&i(Z,{kind:`system`,children:w(S.system)}),b.length===0&&i(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:(_??[]).length===0?l(`integrations.noProviders`):l(`integrations.noProvidersMatch`,`No integrations match your search.`)})]})}s();function ot({open:t,onClose:a,scope:s,onSetupIntegration:c,pickMode:l=`adopt`}){let{t:u}=V(),d=pe(),[p,m]=o(new Set),[h,g]=o(new Set),[_,v]=o(new Set),{data:y}=ae({projection:`slim`}),b=n(()=>new Set((y??[]).map(e=>e.stableId)),[y]),x=r(async(e,t)=>{g(e=>new Set(e).add(t.stableId));try{await d.mutateAsync({addonId:e,candidate:t}),m(e=>new Set(e).add(t.stableId)),v(e=>{let n=new Set(e);return n.delete(t.stableId),n})}catch{}finally{g(e=>{let n=new Set(e);return n.delete(t.stableId),n})}},[d]),S=r(async(e,t)=>{let n=l===`fill`?W(e,t):G(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(()=>{m(new Set),v(new Set)},[]),T=n(()=>({existingStableIds:b,adopted:p,adopting:h,selection:{selected:_,toggle:C},pick:S,adoptOne:x,fill:l===`fill`}),[b,p,h,_,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(ie,{open:t,onOpenChange:e=>!e&&a(),children:e(fe,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(me,{children:i(re,{children:e(`span`,{className:`flex items-center gap-2`,children:[i(f,{className:`h-4 w-4 text-primary`}),E]})})}),e(le,{className:`space-y-4`,children:[i(Y,{}),s?i(pt,{scope:s,row:T,onReset:w}):i(ft,{row:T,onReset:w})]})]})})}function st(e,t){return!t&&e.selectable!==!1&&!q(e)}function ct({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(lt,{addonId:t,candidate:n.candidate,row:r}),n.children.length>0&&i(ct,{addonId:t,nodes:n.children,row:r,depth:a+1})]},n.candidate.stableId))})}function lt({addonId:t,candidate:n,row:r}){let{t:a}=V(),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||q(n),f=!l&&(d||n.selectable!==!1),p=f&&st(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(_,{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(b,{className:`h-3.5 w-3.5`}),` `,c?a(`integrations.scanNetworkModal.alreadyAdded`,`Already added`):a(`integrations.scanNetworkModal.added`,`Added`)]}):f?e(I,{size:`sm`,variant:d?`outline`:`primary`,onClick:()=>void r.pick(t,n),disabled:u,children:[u?i(v,{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 ut({addonId:t,label:r,candidates:a,row:o}){let s=n(()=>K(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(H,{type:t,size:`sm`}),i(`span`,{className:y,children:r}),e(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`(`,a.length,`)`]})]}),i(ct,{addonId:t,nodes:s,row:o,depth:0})]})}function dt(e,t){return e.flatMap(e=>J(K(e.candidates)).filter(e=>st(e,t)).map(t=>({addonId:e.addonId,candidate:t})))}function ft({row:t,onReset:o}){let{t:s}=V(),c=ue(),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]),f=n(()=>dt(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(mt,{entries:f,row:t}),e(I,{variant:`outline`,size:`sm`,onClick:l,disabled:c.isPending,children:[i(D,{className:`h-3.5 w-3.5 ${c.isPending?`animate-spin`:``}`}),s(`integrations.scanNetworkModal.reScan`,`Re-scan`)]})]})]}),c.isPending&&i(gt,{label:s(`integrations.scanNetworkModal.scanningTheLocalNetwork`,`Scanning the local network…`)}),!c.isPending&&c.isError&&i(_t,{}),!c.isPending&&c.data&&u.length===0&&i(ht,{}),!c.isPending&&u.map(e=>i(ut,{addonId:e.addonId,label:e.label,candidates:e.candidates,row:t},e.addonId))]})}function pt({scope:t,row:a,onReset:s}){let{t:c}=V(),l=z({addonId:t.addonId}).data??null,[u,d]=o({}),p=j(),m=r(()=>{s(),p.mutate({addonId:t.addonId,params:u})},[p,t.addonId,u,s]),h=n(()=>p.data?.candidates??[],[p.data]),g=n(()=>dt([{addonId:t.addonId,candidates:h}],a.fill),[t.addonId,h,a.fill]);return e(`div`,{className:`space-y-4`,children:[l&&i(Te,{schema:l,values:u,onChange:d}),e(I,{onClick:m,disabled:p.isPending,children:[p.isPending?i(v,{className:`h-3.5 w-3.5 animate-spin`}):i(f,{className:`h-3.5 w-3.5`}),p.isPending?c(`integrations.scanNetworkModal.scanning`,`Scanning…`):c(`integrations.scanNetworkModal.scan`,`Scan`)]}),i(mt,{entries:g,row:a}),p.isError&&i(_t,{}),!p.isPending&&p.data&&h.length===0&&i(ht,{}),!p.isPending&&h.length>0&&e(`div`,{className:`space-y-2`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:c(`integrations.scanNetworkModal.foundShort`,{count:h.length})}),i(ut,{addonId:t.addonId,label:t.label,candidates:h,row:a})]})]})}function mt({entries:t,row:n}){let{t:r}=V(),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(I,{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 ht(){let{t:e}=V();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 gt({label:t}){return e(`div`,{className:`flex flex-col items-center py-12`,children:[i(v,{className:`h-6 w-6 animate-spin text-primary`}),i(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:t})]})}function _t(){let{t}=V();return e(`div`,{className:`flex items-start gap-3 rounded-lg border border-danger/40 bg-danger/10 px-4 py-3`,children:[i(h,{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 vt(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 yt=2e4;function bt({open:t,onClose:r,seed:s=null}){let{t:u}=V(),d=we(),f=c(),[p,m]=o(`picker`),[h,g]=o(null),[_,y]=o(null),[b,x]=o(`manual`),[S,C]=o(null),[w,T]=o(``),[E,D]=o(null),[O,k]=o(null),[ee,A]=o(!1),[ne,j]=o({}),[ae,se]=o(``),[ce,ue]=o(!1),[ge,N]=o(0),[_e,P]=o(``),F=M({},{enabled:t&&p===`config`}),ve=(oe({addonId:h??``},{enabled:t&&p===`config`&&h!==null}).data?.kinds??[]).filter(e=>e.canTest!==!1),L=ve.length===1?ve[0]?.id:void 0,ye=h!==null&&(F.data?.providers??[]).some(e=>e.addonId===h),be=s?.config.host,z=s===null?``:`${s.addonId}\0${s.name}\0${typeof be==`string`?be:``}`;t&&s!==null&&ae!==z&&(se(z),g(s.addonId),T(s.name),j({...s.config}),m(`config`));let xe=te(void 0,{enabled:t&&s!==null}),B=xe.data?.find(e=>e.addonId===h)?.mode??`account`,{data:Se}=R({addonId:h??``,id:null,mode:B,...s?.originStableId===void 0?{}:{candidateStableId:s.originStableId}},{enabled:h!=null}),Ce=n(()=>Se?vt(Se):null,[Se]),H=he({onSuccess:()=>{f.invalidateQueries({queryKey:[[`integrations`]]}),f.invalidateQueries({queryKey:[[`integrationInstances`]]})}}),U=de(),Te=U.data;a(()=>{if(!t||s===null)return;let e=xe.data?.find(e=>e.addonId===s.addonId);e&&(A(e.canTest),x(e.discoveryMode))},[t,s,xe.data]),a(()=>{p!==`discovery`||!_||!h||U.isPending||U.data||U.mutate({addonId:h})},[p,_,h,U]);let Ee=pe({onSuccess:()=>f.invalidateQueries({queryKey:[[`deviceManager`]]})});function De(e,t,n,r,i,a,o,s){if(!H.isPending){if(g(e),A(s),x(n),T(r),k(null),H.reset(),o===`broker`){if(!a){k(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}C(a),m(`broker`);return}if(o===`account`){m(`config`);return}ke(e,r)}}async function ke(e,t){try{let n=await H.mutateAsync({addonId:e,name:t,values:{}});r(),K(),d(`${Oe(e,n.id)}&add=1`)}catch{}}async function Ae(e){if(h)try{let t=await H.mutateAsync({addonId:h,name:e.name,values:e.config,...L===void 0?{}:{kind:L},...s!==null&&s.addonId===h&&s.originStableId!==void 0?{originStableId:s.originStableId}:{}});y(t.id),D(t.id),b===`auto`||b===`both`?m(`discovery`):G(t.id,{openAdd:!0})}catch{}}async function W(e){if(h)try{let t=await H.mutateAsync({addonId:h,name:w,values:{brokerId:e}});D(t.id),y(t.id),G(t.id)}catch{}}async function je(e){if(h){for(let t of e){let e=Te?.find(e=>e.stableId===t);e&&await Ee.mutateAsync({addonId:h,candidate:e,...E===null?{}:{integrationId:E}})}G()}}function G(e,t){let n=e??_??h;if(r(),K(),n&&h){let e=Oe(h,n);d(t?.openAdd===!0?`${e}&add=1`:e)}}function K(){m(`picker`),g(null),y(null),x(`manual`),C(null),T(``),D(null),k(null),H.reset(),A(!1),j({}),se(``)}function q(){r(),K()}Qe(t);let J=H.isPending,Y=$e(J,yt);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,Pe=H.error,X=J&&!Y;return e(l,{children:[i(ie,{open:!0,onOpenChange:e=>{!e&&!X&&q()},children:e(fe,{width:p===`picker`?`xl`:`lg`,scroll:`body`,onCancel:e=>{X&&e.preventDefault()},children:[i(me,{children:i(re,{children:Me[p]})}),e(le,{children:[Pe&&!J&&i(`div`,{className:`mb-3 rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:Pe instanceof Error?Pe.message:String(Pe)}),p===`picker`&&e(l,{children:[O&&i(`div`,{className:`mb-3 rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:O}),i(at,{onSelect:De,onClose:q,pendingAddonId:Ne})]}),p===`config`&&h&&i(nt,{addonId:h,configSchema:Ce??null,canTest:ee,...L===void 0?{}:{instanceKind:L},initialName:w.length>0&&Object.keys(ne).length>0?w:void 0,initialConfig:{...ne},onScan:ye?()=>{P(w.length>0?w:h),ue(!0)}:void 0,onSave:Ae,onBack:()=>{j({}),m(`picker`)}},`${z.length>0?z:h}:${ge}`),p===`broker`&&S&&i(et,{kind:S,onResolved:e=>{W(e)},onBack:()=>m(`picker`)}),p===`discovery`&&_&&i(tt,{providerId:_,onImport:je,onSkip:G})]}),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(v,{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(I,{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(ot,{open:ce,scope:{addonId:h,label:_e},pickMode:`fill`,onClose:()=>ue(!1),onSetupIntegration:e=>{T(e.name),j({...e.config}),N(e=>e+1)}})]})}function xt({integration:t,expanded:n,onToggleExpand:r}){let{t:a}=V();return e(`div`,{className:`flex items-center gap-2.5`,children:[i(I,{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?k:E,{className:`h-3.5 w-3.5`})}),i(H,{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 St(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:B.t(`integrations.integrationColumns.integration`,`Integration`),headerClassName:`w-[55%]`,cell:e=>i(xt,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:B.t(`integrations.integrationColumns.devices`,`Devices`),headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>B.t(`integrations.integrationColumns.deviceCount`,{count:e.deviceCount})},{key:`status`,header:B.t(`integrations.integrationColumns.status`,`Status`),headerClassName:`w-[15%]`,cell:e=>i(F,{status:e.status})}]}s();var Ct=6e4;function wt({onSetupIntegration:t}){let{t:n}=V(),[r,a]=o(!1),s=ge({},{refetchInterval:Ct}),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(f,{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(I,{variant:`secondary`,size:`sm`,onClick:()=>a(!0),children:n(`integrations.discoveryBanner.review`,`Review`)})]}),i(Tt,{open:r,onClose:()=>a(!1),proposals:c,onChanged:()=>void s.refetch(),onSetupIntegration:e=>{a(!1),t(e)}})]})}function Tt({open:t,onClose:n,proposals:a,onChanged:s,onSetupIntegration:c}){let{t:u}=V(),d=pe(),p=ce(),[m,h]=o(new Set),g=r(async(e,t)=>{h(t=>new Set(t).add(e));try{await t(),s()}catch{}finally{h(t=>{let n=new Set(t);return n.delete(e),n})}},[s]),_=r(async e=>{let t=G(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,()=>p.mutateAsync({id:e.id})),[p,g]);return i(ie,{open:t,onOpenChange:e=>!e&&n(),children:e(fe,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(me,{children:i(re,{children:e(`span`,{className:`flex items-center gap-2`,children:[i(f,{className:`h-4 w-4 text-primary`}),u(`integrations.discoveryBanner.title`,`New devices found`)]})})}),i(le,{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})]}),m.has(t.id)?i(v,{className:`h-4 w-4 animate-spin text-foreground-muted`,"aria-hidden":!0}):e(l,{children:[i(I,{variant:`secondary`,size:`sm`,onClick:()=>void y(t),children:u(`integrations.discoveryBanner.dismiss`,`Dismiss`)}),e(I,{size:`sm`,onClick:()=>void _(t),children:[i(b,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),u(`integrations.discoveryBanner.adopt`,`Adopt`)]})]})]},t.id))})]})})}s();function Et(e){if(!e.enabled&&e.switchUnknown!==!0)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var Dt=`expand`;function Ot(){let{t}=V(),s=we(),c=Ce(),u=x(),[d]=Se(),[m,h]=Ze(),[g,_]=o(!1),[v,y]=o(null),b=r(()=>{y(null),_(!0)},[]),C=r(()=>{_(!1),y(null)},[]),E=r(e=>{k(!1),y(e),_(!0)},[]),[O,k]=o(!1);a(()=>{let e=je(c.state);e!==null&&(y(e),_(!0),s(`/integrations`,{replace:!0,state:null}))},[c.state,s]);let A=d.get(`setup`);a(()=>{A===null||A.length===0||(y({addonId:A,name:A,config:{}}),_(!0))},[A]);let j=r(()=>k(!0),[]),re=r(()=>k(!1),[]);L([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),L([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:M,isLoading:ie,isError:oe,error:ce,errorUpdateCount:le,refetch:ue}=ve(void 0,{refetchInterval:Ue}),{data:de,isLoading:fe,isError:pe,error:me,errorUpdateCount:he,refetch:ge}=ae({projection:`slim`},{refetchInterval:Ue}),N=n(()=>de??[],[de]),P=n(()=>M??[],[M]),F=n(()=>{let e=new Map;for(let t of N)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[N]),R=n(()=>be(M),[M]),z=n(()=>{let e=new Map;for(let t of _e(N)){let n=R(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[N,R]),B=n(()=>P.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:Et(e),deviceCount:z.get(e.id)??0})),[P,z]),{data:H}=te(),U=n(()=>new Map((H??[]).map(e=>[e.addonId,e.name])),[H]),Te=d.get(Dt),Ee=r(e=>{let t=new URLSearchParams(window.location.search);t.get(Dt)===e?t.delete(Dt):t.set(Dt,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:De}=xe(void 0),W=n(()=>Fe(De),[De]),G=n(()=>Ie(B,W),[B,W]),K=n(()=>Ie(Pe(B,U),W),[B,U,W]),q=r(e=>s(Oe(e.addonId)),[s]),J=r(e=>s(Oe(e.addonId,e.id)),[s]),Y=r(e=>F.get(e)??null,[F]),Me=r(e=>s(`/devices/${String(e)}`),[s]),Ne=r(e=>i(se,{context:`integration-detail`,devices:N,trpc:u.trpcClient,integrationOf:R,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:Ae,resolveParent:Y,onNavigate:Me}),[N,u.trpcClient,R,Y,Me]),X=r(e=>Te===e.addonId,[Te]),Le=n(()=>St({isExpanded:X,onToggleExpand:Ee}),[X,Ee]),Re=r(e=>`${e.name} ${e.addonId}`,[]),ze=r(e=>e.id,[]),Be=e=>i(se,{mode:`generic`,items:e,getKey:ze,getSearchText:Re,columns:Le,onRowClick:J,isExpanded:X,renderExpanded:Ne,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),Ve=r(()=>{ue(),ge()},[ue,ge]),We=oe===!0&&He(ce,le),Ge=pe===!0&&He(me,he),qe=We||Ge,Q=oe===!0&&!We||pe===!0&&!Ge,$=!Q&&!qe&&(ie||fe||M===void 0||de===void 0),Je=P.length>0,Ye=[{id:`table`,label:t(`integrations.viewTable`,`Table`),icon:ee},{id:`grid`,label:t(`integrations.viewGrid`,`Grid`),icon:S}];return e(ke,{icon:w,title:t(`nav.integrations`,`Integrations`),actions:e(l,{children:[i(ye,{ariaLabel:t(`integrations.viewLabel`,`Layout`),value:m,onChange:h,options:Ye,testId:`integrations-view`}),i(I,{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(D,{className:T(`h-3.5 w-3.5`,$&&`animate-spin`)})}),e(I,{variant:`unstyled`,onClick:j,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(f,{className:`h-3.5 w-3.5`}),t(`integrations.scanNetwork`,`Scan network`)]}),e(I,{variant:`unstyled`,onClick:b,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(p,{className:`h-3.5 w-3.5`}),t(`integrations.newIntegration`,`New Integration`)]})]}),children:[i(wt,{onSetupIntegration:E}),Q&&i(ne,{message:t(`integrations.loadFailed`,`Integrations could not be loaded.`),onRetry:Ve}),qe&&!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(D,{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&&!$&&!qe&&!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(Ke,{providers:K.providers,system:K.system,onOpen:q,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),i(bt,{open:g,onClose:C,seed:v}),i(ot,{open:O,onClose:re,onSetupIntegration:E})]})}export{Ot as IntegrationsPage};
@@ -1,2 +1,2 @@
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{Bn as c,Tn as l,li as u,ot as d,qn as f,xr as p}from"./player-overlays-K3LnyuXU.js";import{Bi as m}from"./client-C0lbTORN.js";import{D as h,N as g,O as _,v}from"./__vite-browser-external-BCAtXlNQ.js";import{y}from"./video-DBmZRVRb.js";import{Co as b,Gr as x,Gt as S,Jr as C,Ur as w,Ut as T,Wr as E,Wt as D,Yr as O,hf as k,sa as A,zi as j}from"./src-BnhYqWbx.js";import{t as M}from"./useTranslation-BJr-n0es.js";import{X as N,qr as P,x as F}from"./index-DosV7QmO.js";import{t as I}from"./AdminSectionedPage-BMFLLxeJ.js";import{t as L}from"./InstancesTable-DJAoGLT7.js";a();var R=1e4;function z({row:t}){let{t:r}=M(),[a,o]=i(!1),c=t.kind===`instance`?t.id:void 0,{data:l}=b({addonId:t.addonId,...c===void 0?{}:{instanceId:c}},{refetchInterval:R,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(j,{variant:`ghost`,size:`sm`,type:`button`,onClick:()=>o(!0),children:r(`system.connectivity.devicesExported`,`{{count}} devices exported`,{count:d})}),a&&n(w,{open:!0,onOpenChange:o,children:e(x,{width:`full`,scroll:`body`,children:[n(C,{children:n(O,{children:r(`system.connectivity.devicesDialogTitle`,`Devices of {{name}}`,{name:t.name})})}),n(E,{children:c===void 0?n(D,{addonId:t.addonId,showSetup:!1}):n(T,{addonId:t.addonId,instance:{instanceId:c,name:t.name,enabled:!0},showSetup:!1})})]})})]})}function B(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(z,{row:e})}}function V({addonId:e,instanceId:t}){return n(S,{addonId:e,instanceId:t})}var H=`waste-collections`,U=_({refreshed:v(_({sourceId:g(),entryCount:h().int(),error:g().optional()}))});function W({row:e}){let{t}=M(),r=d(),i=o(),a=A({onSuccess:async n=>{let a=U.safeParse(n),o=a.success?a.data.refreshed[0]:void 0;if(i.invalidateQueries({queryKey:[N]}),o===void 0){await r({title:t(`wasteFetchNow.nothingFetched`,`Nothing to fetch`),message:t(`wasteFetchNow.sourceIsOff`,`{{name}} is switched off, so it was not fetched.`,{name:e.name})});return}await r({title:o.error===void 0?t(`wasteFetchNow.fetched`,`{{name}} fetched`,{name:e.name}):t(`wasteFetchNow.failed`,`{{name}} could not be fetched`,{name:e.name}),message:o.error??t(`wasteFetchNow.collections`,`{{count}} collections read.`,{count:o.entryCount}),variant:o.error===void 0?`default`:`danger`})},onError:async n=>{await r({title:t(`wasteFetchNow.failed`,`{{name}} could not be fetched`,{name:e.name}),message:n.message,variant:`danger`})}});return n(k,{icon:u,variant:`ghost`,size:`sm`,"aria-label":t(`wasteFetchNow.label`,`Fetch {{name}} now`,{name:e.name}),disabled:a.isPending,onClick:()=>a.mutate({addonId:H,action:`fetchNow`,input:{sourceId:e.id}})})}function G(e){return e.addonId===H?n(W,{row:e}):null}function K(){let{t}=M(),r=d(),i=o(),a=A({onSuccess:async e=>{let n=U.safeParse(e);i.invalidateQueries({queryKey:[N]});let a=n.success?n.data.refreshed:[],o=a.filter(e=>e.error!==void 0);await r({title:o.length===0?t(`wasteFetchNow.allFetched`,`Calendars fetched`):t(`wasteFetchNow.allFailed`,`{{count}} calendars could not be fetched`,{count:o.length}),message:o.length===0?t(`wasteFetchNow.allCollections`,`{{count}} sources refreshed.`,{count:a.length}):o.map(e=>`${e.sourceId}: ${e.error}`).join(`
2
- `),variant:o.length===0?`default`:`danger`})},onError:async e=>{await r({title:t(`wasteFetchNow.allNotFetched`,`The calendars could not be fetched`),message:e.message,variant:`danger`})}});return e(j,{size:`sm`,variant:`secondary`,disabled:a.isPending,onClick:()=>a.mutate({addonId:H,action:`fetchNow`,input:{}}),children:[n(u,{className:`h-3.5 w-3.5`}),t(`wasteFetchNow.all`,`Fetch all now`)]})}function q(e){return e.some(e=>e.addonId===H)?n(K,{}):null}a();var J={"device-export":`exporters`,exporters:`exporters`,email:`email`,broker:`brokers`,brokers:`brokers`,"message-brokers":`brokers`,calendar:`calendars`,calendars:`calendars`,"calendar-source":`calendars`},Y=[{sectionId:`exporters`,labelKey:`system.connectivity.exporters`,icon:l,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=>[B(e)],lead:e=>n(V,{addonId:e.addonId,instanceId:e.id})}},{sectionId:`email`,labelKey:`system.connectivity.email`,icon:p,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`,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`,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`,rowActions:G,pageActions:q}}];function X(){let{t:e}=M(),[i,a]=P(),o=F(`/system/integrations`,{t:e,isAdmin:!0})??{icon:f,title:e(`admin.system.integrations.connectivity`,`Connectivity`)};r(()=>{let e=i.get(`tab`);if(e===null)return;let t=J[e];t===void 0||t===e||a(e=>{let n=new URLSearchParams(e);return n.set(`tab`,t),n},{replace:!0})},[i,a]);let s=t(()=>Y.map(t=>{let r=t.instances;return{id:t.sectionId,label:e(t.labelKey),content:n(L,{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),install:{capability:r.functionCap,label:e(t.installLabelKey)},...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}})}}),[e]);return n(I,{icon:o.icon,title:o.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:s})}export{X as IntegrationsPage};
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{Bn as c,Tn as l,li as u,ot as d,qn as f,xr as p}from"./player-overlays-BZByYYB8.js";import{Bi as m}from"./client-mnldOm50.js";import{D as h,N as g,O as _,v}from"./__vite-browser-external-BCAtXlNQ.js";import{y}from"./video-BV-3O_ZC.js";import{$i as b,Gt as x,Hr as S,Ir as C,Lr as w,Rr as T,Ut as E,Vr as D,Wt as O,ho as k,ji as A,of as j}from"./src-DKRp5NPI.js";import{t as M}from"./useTranslation-BJr-n0es.js";import{Kr as N,Y as P,x as F}from"./index-D5GcZJtC.js";import{t as I}from"./AdminSectionedPage-Xr_hesYw.js";import{t as L}from"./InstancesTable-BagVOERb.js";a();var R=1e4;function z({row:t}){let{t:r}=M(),[a,o]=i(!1),c=t.kind===`instance`?t.id:void 0,{data:l}=k({addonId:t.addonId,...c===void 0?{}:{instanceId:c}},{refetchInterval:R,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(T,{width:`full`,scroll:`body`,children:[n(D,{children:n(S,{children:r(`system.connectivity.devicesDialogTitle`,`Devices of {{name}}`,{name:t.name})})}),n(w,{children:c===void 0?n(O,{addonId:t.addonId,showSetup:!1}):n(E,{addonId:t.addonId,instance:{instanceId:c,name:t.name,enabled:!0},showSetup:!1})})]})})]})}function B(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(z,{row:e})}}function V({addonId:e,instanceId:t}){return n(x,{addonId:e,instanceId:t})}var H=`waste-collections`,U=_({refreshed:v(_({sourceId:g(),entryCount:h().int(),error:g().optional()}))});function W({row:e}){let{t}=M(),r=d(),i=o(),a=b({onSuccess:async n=>{let a=U.safeParse(n),o=a.success?a.data.refreshed[0]:void 0;if(i.invalidateQueries({queryKey:[P]}),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(j,{icon:u,variant:`ghost`,size:`sm`,"aria-label":t(`wasteFetchNow.label`,`Fetch {{name}} now`,{name:e.name}),disabled:a.isPending,onClick:()=>a.mutate({addonId:H,action:`fetchNow`,input:{sourceId:e.id}})})}function G(e){return e.addonId===H?n(W,{row:e}):null}function K(){let{t}=M(),r=d(),i=o(),a=b({onSuccess:async e=>{let n=U.safeParse(e);i.invalidateQueries({queryKey:[P]});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:H,action:`fetchNow`,input:{}}),children:[n(u,{className:`h-3.5 w-3.5`}),t(`wasteFetchNow.all`,`Fetch all now`)]})}function q(e){return e.some(e=>e.addonId===H)?n(K,{}):null}a();var J={"device-export":`exporters`,exporters:`exporters`,email:`email`,broker:`brokers`,brokers:`brokers`,"message-brokers":`brokers`,calendar:`calendars`,calendars:`calendars`,"calendar-source":`calendars`},Y=[{sectionId:`exporters`,labelKey:`system.connectivity.exporters`,icon:l,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=>[B(e)],lead:e=>n(V,{addonId:e.addonId,instanceId:e.id})}},{sectionId:`email`,labelKey:`system.connectivity.email`,icon:p,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`,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`,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`,rowActions:G,pageActions:q}}];function X(){let{t:e}=M(),[i,a]=N(),o=F(`/system/integrations`,{t:e,isAdmin:!0})??{icon:f,title:e(`admin.system.integrations.connectivity`,`Connectivity`)};r(()=>{let e=i.get(`tab`);if(e===null)return;let t=J[e];t===void 0||t===e||a(e=>{let n=new URLSearchParams(e);return n.set(`tab`,t),n},{replace:!0})},[i,a]);let s=t(()=>Y.map(t=>{let r=t.instances;return{id:t.sectionId,label:e(t.labelKey),content:n(L,{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),install:{capability:r.functionCap,label:e(t.installLabelKey)},...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}})}}),[e]);return n(I,{icon:o.icon,title:o.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:s})}export{X as IntegrationsPage};