@camstack/addon-admin-ui 1.2.485 → 1.2.487

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 (137) hide show
  1. package/dist/assets/{AddonAssetIcon-3vq-0y-v.js → AddonAssetIcon-C_RF_2Yp.js} +1 -1
  2. package/dist/assets/Addons-kSjXhQba.js +5 -0
  3. package/dist/assets/{AdminPage-QmLz5qjj.js → AdminPage-Qn0NDZXK.js} +1 -1
  4. package/dist/assets/{AdminSectionedPage-D9jBOpIg.js → AdminSectionedPage-xGVLV1j3.js} +1 -1
  5. package/dist/assets/AiProfiles-C7RRiZ-Y.js +3 -0
  6. package/dist/assets/{BrokerForm-D8mkRSYS.js → BrokerForm-pprTt8-v.js} +1 -1
  7. package/dist/assets/Build-BhxXDEVz.js +40 -0
  8. package/dist/assets/{Calendars-Beo-YqjO.js → Calendars-v8J_zj4w.js} +1 -1
  9. package/dist/assets/{Cluster-B-_bS1Yq.js → Cluster-dhAPfJv6.js} +1 -1
  10. package/dist/assets/{CompositionBlockEditor-iMNTwm3C.js → CompositionBlockEditor-BK2Or4Pz.js} +1 -1
  11. package/dist/assets/{CompositionEditorPage-BED3S8xk.js → CompositionEditorPage-CTPdWS1m.js} +1 -1
  12. package/dist/assets/Data-CPdzZaQ6.js +2 -0
  13. package/dist/assets/DeviceDetail-DGJeLN9c.js +2 -0
  14. package/dist/assets/{DeviceDoActionFields-BJfHVs6x.js → DeviceDoActionFields-OU-F7_Md.js} +1 -1
  15. package/dist/assets/{Devices-_2nQ8QL2.js → Devices-C9LPgFce.js} +1 -1
  16. package/dist/assets/{EmbedPlayerPage-D6aNp4TG.js → EmbedPlayerPage-8ilkZLox.js} +1 -1
  17. package/dist/assets/HelperWizard-Dq94Geed.js +2 -0
  18. package/dist/assets/History-CTyWzxbJ.js +1 -0
  19. package/dist/assets/Identity-DOSuuL8C.js +1 -0
  20. package/dist/assets/IntegrationDetail-Bj2o8Gyl.js +1 -0
  21. package/dist/assets/{IntegrationHub-D5yLfTfh.js → IntegrationHub-D-BT1i-q.js} +1 -1
  22. package/dist/assets/Integrations-CKR4hJyA.js +1 -0
  23. package/dist/assets/{Integrations-C_kA-dpe.js → Integrations-Dn8CFiTq.js} +1 -1
  24. package/dist/assets/{Library-Bx344878.js → Library-DzwP0Wnj.js} +1 -1
  25. package/dist/assets/{Locations-Do1Y0voR.js → Locations-BYPw-b2Z.js} +2 -2
  26. package/dist/assets/{Logs-svtt17dH.js → Logs-BlImwaLa.js} +1 -1
  27. package/dist/assets/{MaskShapeCanvas-CzHUGkc7.js → MaskShapeCanvas-Cs9lGzkk.js} +1 -1
  28. package/dist/assets/{MotionZonesSettings-sCDWBSMu.js → MotionZonesSettings-5ocz0RHa.js} +1 -1
  29. package/dist/assets/{MyAccess-C3MmE-Hf.js → MyAccess-VP7h9O7-.js} +1 -1
  30. package/dist/assets/Network-Bla9sJtL.js +1 -0
  31. package/dist/assets/{NodeAddonsSettingsPanel-DUUGVGQU.js → NodeAddonsSettingsPanel-AvBI4Evv.js} +1 -1
  32. package/dist/assets/Notifications-H77YTWdJ.js +1 -0
  33. package/dist/assets/Pipeline-pHUqWRzY.js +1 -0
  34. package/dist/assets/{PrivacyMaskSettings-DH3PZaEy.js → PrivacyMaskSettings-UQH7zTTO.js} +1 -1
  35. package/dist/assets/Recordings-BDCMjtre.js +1 -0
  36. package/dist/assets/{ScanNetworkModal-PQbiE2mC.js → ScanNetworkModal-B59m4nHs.js} +1 -1
  37. package/dist/assets/{SceneMonitorEditor-CLWf6Z9-.js → SceneMonitorEditor-PrBW7EMG.js} +1 -1
  38. package/dist/assets/SessionsList-CSJK-M1F.js +2 -0
  39. package/dist/assets/{Showroom-BOzjtIAL.js → Showroom-mL9KRe6u.js} +1 -1
  40. package/dist/assets/System-CW6fpBto.js +1 -0
  41. package/dist/assets/{Terminal-B2SRyo3p.js → Terminal-CLB_5tnQ.js} +5 -5
  42. package/dist/assets/{Viewer-CTvuCeo6.js → Viewer-CVsr_E-j.js} +1 -1
  43. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DAW63rZZ.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CK4gM4oq.js} +1 -1
  44. package/dist/assets/{addon-icons-context-Bzdujcmt.js → addon-icons-context-BKk0-b-B.js} +1 -1
  45. package/dist/assets/{archive-dvL2Bchb.js → archive-BR503Bgl.js} +1 -1
  46. package/dist/assets/{assignment-candidates-D1rkNXjX.js → assignment-candidates-Bt36QoWU.js} +1 -1
  47. package/dist/assets/{authed-media-B6hJJcft.js → authed-media-B5-BZoAQ.js} +1 -1
  48. package/dist/assets/{bell-off-C3flB_OF.js → bell-off-3JXpdmf4.js} +1 -1
  49. package/dist/assets/{board-model-BJ20DSDr.js → board-model-B0Q2QBXn.js} +1 -1
  50. package/dist/assets/{boxes-BiMbpzNh.js → boxes-0Xg4N6GT.js} +1 -1
  51. package/dist/assets/circle-slash-bfqjP0sy.js +1 -0
  52. package/dist/assets/client-CgAb3Nw-.js +358 -0
  53. package/dist/assets/{cloud-upload-CAJgV_u1.js → cloud-upload-BgVc9mNQ.js} +1 -1
  54. package/dist/assets/crop-DYBE_kWG.js +1 -0
  55. package/dist/assets/{device-integration-icon-Csh9ZCwn.js → device-integration-icon-CxktyXD5.js} +1 -1
  56. package/dist/assets/device-picker-model-DF4u2b9z.js +1 -0
  57. package/dist/assets/{dist-CPp8d_RN.js → dist-BCJVDfA5.js} +1 -1
  58. package/dist/assets/dist-BJ8kdWPh.js +358 -0
  59. package/dist/assets/{eraser-BL6nSeLQ.js → eraser-xkgMNpsn.js} +1 -1
  60. package/dist/assets/{format-Cl0i0-3O.js → format-6k9X14Bz.js} +1 -1
  61. package/dist/assets/{hard-drive-download-ysGKYLwW.js → hard-drive-download-CUmPIudl.js} +1 -1
  62. package/dist/assets/{hostInit-CDPK_pyj.js → hostInit-DcyTvfcE.js} +1 -1
  63. package/dist/assets/i18n-Zscg3Dkf.js +1 -0
  64. package/dist/assets/icons-D7uD703E.js +1 -0
  65. package/dist/assets/index-Cgn0pmzp.js +4 -0
  66. package/dist/assets/{key-xS-HUgNI.js → key-VxuVSDcq.js} +1 -1
  67. package/dist/assets/{key-round-BDT5O9Ed.js → key-round-DOAkaBGK.js} +1 -1
  68. package/dist/assets/{layers-BeRWYCde.js → layers-hN2OAslg.js} +1 -1
  69. package/dist/assets/{linked-devices-model-zOoasg7W.js → linked-devices-model-m3azqStw.js} +1 -1
  70. package/dist/assets/{list-ordered-DKzGLPr6.js → list-ordered-B7_m7mQG.js} +1 -1
  71. package/dist/assets/{location-owned-usage-CWUx1diZ.js → location-owned-usage-D-K-peZa.js} +1 -1
  72. package/dist/assets/{log-in-53JDrQ-P.js → log-in-CyzfmKrH.js} +1 -1
  73. package/dist/assets/{memory-stick-B9PVELyF.js → memory-stick-Bh-D1JrM.js} +1 -1
  74. package/dist/assets/{message-square-plus-B32IU45x.js → message-square-plus-Jq5Qx-ZG.js} +1 -1
  75. package/dist/assets/{mf-entry-bootstrap-0-40dc4d62.js → mf-entry-bootstrap-0-01ed437f.js} +2 -2
  76. package/dist/assets/{mic-off-B0w-1GrV.js → mic-off-HMWnEzre.js} +1 -1
  77. package/dist/assets/{monitor-off-Cz2SxBVE.js → monitor-off-jWwMgNhA.js} +1 -1
  78. package/dist/assets/{monitor-smartphone-Cqk6Z8Hg.js → monitor-smartphone-CR32s5N4.js} +1 -1
  79. package/dist/assets/mount-DF4u2b9z.js +1 -0
  80. package/dist/assets/{player-overlays-Cs6l33cj.js → player-overlays-BT3xIHAn.js} +1 -1
  81. package/dist/assets/{recycle-DpB4QxbX.js → recycle-DZmrkdVl.js} +1 -1
  82. package/dist/assets/remoteEntry-HwnLQWmW.js +1 -0
  83. package/dist/assets/{scan-eye-DcYrgFOu.js → scan-eye-B5rZ7zGT.js} +1 -1
  84. package/dist/assets/{scissors-_j_D3ONm.js → scissors-DwAZ3q7Q.js} +1 -1
  85. package/dist/assets/{search-x-9dPd-b95.js → search-x-B-oRfcQP.js} +1 -1
  86. package/dist/assets/{send-D42ODbS7.js → send-ZjS8CwTz.js} +1 -1
  87. package/dist/assets/{settings-2-zgGmo4c8.js → settings-2-5VaXifkQ.js} +1 -1
  88. package/dist/assets/sigma-Do3DgNJ1.js +1 -0
  89. package/dist/assets/{speaker-DIPHxIQ6.js → speaker-TZvdN1cH.js} +1 -1
  90. package/dist/assets/src-DX_JbsFG.js +67 -0
  91. package/dist/assets/{step-inspector-model-DTr-lHt_.js → step-inspector-model-Cge4IaLZ.js} +1 -1
  92. package/dist/assets/{table-2-lftK0wHb.js → table-2-Dqcebk-T.js} +1 -1
  93. package/dist/assets/{timer-reset-catAE_r9.js → timer-reset-y8kv-UE8.js} +1 -1
  94. package/dist/assets/{ungroup-BKImeHER.js → ungroup-Cy8_Al2f.js} +1 -1
  95. package/dist/assets/{unlink-Behl018w.js → unlink-Db_gKOzw.js} +1 -1
  96. package/dist/assets/{usb-D5kzB8kq.js → usb-B0VgCbP1.js} +1 -1
  97. package/dist/assets/{use-scenes-feed-CGDnep25.js → use-scenes-feed-BX2r5CSu.js} +1 -1
  98. package/dist/assets/{use-stationary-objects-D_R5OahX.js → use-stationary-objects-B6gvXwen.js} +1 -1
  99. package/dist/assets/useEventInvalidation-DF4u2b9z.js +1 -0
  100. package/dist/assets/{useNodeUrlSelection-nYjP8xK4.js → useNodeUrlSelection-cuUDxmhY.js} +1 -1
  101. package/dist/assets/user-round-84cYKzbg.js +1 -0
  102. package/dist/assets/{user-x-COQ6vhb4.js → user-x-CgHtIGhf.js} +1 -1
  103. package/dist/assets/{video-Byw3ItoR.js → video-DYC_GW17.js} +1 -1
  104. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CsFmgfi4.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-HxO7Tlud.js} +2 -2
  105. package/dist/index.html +9 -9
  106. package/dist/server/addon.js +244 -25
  107. package/package.json +1 -1
  108. package/dist/assets/Addons-CW_V36k4.js +0 -5
  109. package/dist/assets/AiProfiles-CP5xqeEk.js +0 -3
  110. package/dist/assets/Build-DVpLjguC.js +0 -40
  111. package/dist/assets/Data-CP80sADS.js +0 -2
  112. package/dist/assets/DeviceDetail-DEfKCzwe.js +0 -2
  113. package/dist/assets/HelperWizard-2-iOB1DP.js +0 -2
  114. package/dist/assets/History-DU5KjafA.js +0 -1
  115. package/dist/assets/Identity-Bx1SUu2F.js +0 -1
  116. package/dist/assets/IntegrationDetail-BtGF0XsO.js +0 -1
  117. package/dist/assets/Integrations-nsyVrgEK.js +0 -1
  118. package/dist/assets/Network-D3RwGDhy.js +0 -1
  119. package/dist/assets/Notifications-CProzw2o.js +0 -1
  120. package/dist/assets/Pipeline-kOwhFjIj.js +0 -1
  121. package/dist/assets/Recordings-CUmSLBG6.js +0 -1
  122. package/dist/assets/SessionsList-BNTGQ-KG.js +0 -2
  123. package/dist/assets/System-DrbzraIN.js +0 -1
  124. package/dist/assets/chart-column-BMpUb2lF.js +0 -1
  125. package/dist/assets/circle-slash-B8Tjloe5.js +0 -1
  126. package/dist/assets/client-Ct1F5MoE.js +0 -358
  127. package/dist/assets/crop-CS-td_0y.js +0 -1
  128. package/dist/assets/device-picker-model-P-UzQOB7.js +0 -1
  129. package/dist/assets/dist-B89wGMMB.js +0 -358
  130. package/dist/assets/i18n-sTui-nG3.js +0 -1
  131. package/dist/assets/icons-B7uNvSe0.js +0 -1
  132. package/dist/assets/index-Dow2-3ZC.js +0 -4
  133. package/dist/assets/mount-P-UzQOB7.js +0 -1
  134. package/dist/assets/remoteEntry-BGbchE1L.js +0 -1
  135. package/dist/assets/src-DFzrn-CX.js +0 -67
  136. package/dist/assets/useEventInvalidation-P-UzQOB7.js +0 -1
  137. package/dist/assets/user-round-BJVl6LX9.js +0 -1
@@ -1 +0,0 @@
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{Lt as s,br as c,ca as l,dt as u,gn as d,ot as f,sr as p,wi as m,xn as h}from"./player-overlays-Cs6l33cj.js";import{Yi as g,cr as _}from"./client-Ct1F5MoE.js";import{$r as v,A as y,C as b,Cn as x,D as S,Dr as C,E as w,Er as T,Fr as E,Hr as D,M as O,N as k,O as A,Or as ee,P as j,Qr as M,Rr as N,S as te,So as P,Td as ne,Xa as re,Za as ie,_ as ae,_r as oe,b as F,d as se,ei as I,f as ce,fr as le,gr as ue,h as de,j as fe,k as pe,kr as L,m as me,mn as he,mr as ge,pn as _e,pr as ve,ru as ye,si as R,u as be,v as xe,vr as Se,w as Ce,wn as z,wr as we,x as B,xn as V}from"./src-DFzrn-CX.js";import{t as H}from"./useTranslation-BJr-n0es.js";import{hr as Te}from"./index-Dow2-3ZC.js";import{t as Ee}from"./AdminPage-QmLz5qjj.js";i();function U(e,t){return e.scope===``?e.displayName:`${e.displayName} · ${t?.(e)??e.scope}`}function De(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:B(i),ref:i,info:e,subjectName:t.name,location:t.location??``,nodeId:``,metric:U(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:B(i),ref:i,info:t,subjectName:e.name,location:``,nodeId:e.id,metric:U(t,n)})}return r}function Oe(e){return[e.subjectName,e.location,e.metric,e.info.key,e.info.unit??``,e.nodeId].join(` `)}function W(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 ke=[`energy`,`temperatures`,`nodes`,`storage`],Ae=new Set([`cap:temperature-sensor.celsius`,`cap:climate-control.currentTemp`]),G=[`addon:metrics-native/node-cpu-percent`,`addon:metrics-native/node-memory-percent`],je=`addon:storage-orchestrator/location-used-percent`;function Me(e,t){let n=(e,n)=>{let r=t.filter(e);return F((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`&&Ae.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`&&G.includes(e.info.key)&&e.info.scope===``,(e,t)=>G.indexOf(e.info.key)-G.indexOf(t.info.key)||e.subjectName.localeCompare(t.subjectName));case`storage`:return n(e=>e.ref.subject.kind===`node`&&e.info.key===je)}}function Ne(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[],i=[],a=[],o=[];for(let t of F(e)){let e=n.get(B(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 K(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 q=`history-page`;function Pe({part:r,window:i}){let{t:a}=H(),o=l(),s=D(),c=N(),u=e=>`${W(e,s,c)} · ${e.metric}`,d=t(()=>[...r.lines,...r.states,...r.energy],[r]),f=me(t(()=>d.map(e=>K(e.ref)),[d]),i,!1),p=e=>f.status===`ok`?f.data.current.get(ce(K(e.ref))):void 0,h=e=>{let t=p(e);return t?.ok?t.result:void 0};if(d.length===0)return n(C,{icon:m,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(f.status===`error`)return n(T,{title:a(`history.page.readFailed`,`History could not be read`),message:f.error});let g=f.status===`pending`,_=d.map(e=>({c:e,e:p(e)})).filter(e=>e.e?.ok===!1),v=r.lines.map((e,t)=>{let n=h(e),r=S(e.info,n,i.from);return{id:e.id,label:u(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=A(e.info,h(e),i.from,i.to),r=Ce(e.info.key,o);return{id:e.id,label:u(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,...w(h(e))})),x=b[0]?.bucketMs??36e5,E=[...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(T,{title:a(`history.page.someFailed`,`Some series could not be read`),message:_.map(e=>`${u(e.c)}: ${e.e.error}`).join(` · `)}),v.length>0&&n(j,{title:a(`history.page.lines`,`Measurements`),series:v,range:i,height:260,syncKey:q,pending:g}),b.length>0&&n(we,{title:a(`history.page.energy`,`Energy`),layers:b.map((e,t)=>({id:e.c.id,label:W(e.c,s,c),colorIndex:t})),buckets:E,bucketMs:x,range:i,unit:`kWh`,showTotal:!0,height:160,syncKey:q,pending:g}),y.length>0&&n(k,{title:y.length===1?y[0]?.label??``:a(`history.page.states`,`States`),rows:y,range:i,syncKey:q,pending:g})]})}function Fe(e,t){let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}async function Ie(e,t){let n=[];for(let r of Fe(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 J(e){return e.raw+e[`5m`]+e[`1h`]+e[`1d`]}function Le(e){return e.reduce((e,t)=>t.ok?{...e,deleted:e.deleted+1,points:e.points+J(t.deleted)}:{...e,refused:e.refused+1},{deleted:0,refused:0,points:0})}function Re(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 Y=e=>new Date(e).toLocaleDateString(void 0,{dateStyle:`short`});function X(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 Z(e){let t=e.displayName??e.key;return e.scope===``?t:`${t} · ${e.scope}`}function Q(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:Z(o)}),n(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:X(o,r,i)})]})},sortValue:e=>`${X(t(e),r,i)} ${Z(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[Q(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(R,{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:Y(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:[Y(t.firstTs),` → `,Y(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(R,{variant:`success`,className:`text-[10px]`,children:t(`history.orphans.deleted`,{count:J(e.deleted),points:J(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(R,{variant:e.reason===`not-found`?`neutral`:`warning`,className:`text-[10px]`,children:r})}function Ue(e,t){return[Q(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:c,onDelete:l,onRefresh:u,refreshing:d}){let{t:f}=H(),m=M(),[g,_]=r(new Set),[v,y]=r(!1),[b,S]=r([]),C=t(()=>Ve(c,f),[c,f]),w=t(()=>Ue(c,f),[c,f]),T=t(()=>new Set(o.series.map(e=>String(e.seriesId))),[o.series]),E=[...g].filter(e=>T.has(e)).map(Number),D=Le(b.map(e=>e.outcome)),O=async()=>{if(await m({title:f(`history.orphans.confirmTitle`,{count:E.length,defaultValue_one:`Delete {{count}} series`,defaultValue_other:`Delete {{count}} series`}),message:f(`history.orphans.confirmMessage`,`Every recorded point of these series is removed from the hub. This cannot be undone.`),confirmLabel:f(`history.orphans.confirmLabel`,`Delete`),variant:`danger`})){y(!0);try{let e=await Ie(E,l);S(Re(o.series,e)),_(new Set)}finally{y(!1),u()}}};return n(le,{open:i,onOpenChange:e=>!e&&a(),children:e(ge,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`orphan-series-dialog`,children:[n(oe,{children:n(Se,{children:f(`history.orphans.title`,`Series no longer linked to a device`)})}),e(ve,{className:`space-y-3`,children:[n(`p`,{className:`text-xs text-foreground-muted`,children:f(`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:f(`history.orphans.truncated`,`More series are unlinked than are listed here. Delete these, then load the rest.`)}),e(I,{size:`sm`,variant:`outline`,onClick:u,disabled:d,children:[n(h,{className:`h-3 w-3`,"aria-hidden":!0}),f(`history.orphans.loadAgain`,`Load again`)]})]}),b.length>0&&e(`div`,{className:`space-y-2`,"data-testid":`orphan-outcomes`,children:[n(`p`,{className:`text-xs text-foreground`,"aria-live":`polite`,children:f(`history.orphans.summary`,{count:D.deleted,refused:D.refused,points:D.points.toLocaleString(),defaultValue_one:`{{count}} series deleted ({{points}} points), {{refused}} kept.`,defaultValue_other:`{{count}} series deleted ({{points}} points), {{refused}} kept.`})}),n(x,{columns:w,rows:b,rowKey:e=>String(e.series.seriesId),minWidthPx:420,maxBodyHeight:`max-h-[60vh]`,emptyMessage:``})]}),n(x,{columns:C,rows:o.series,rowKey:e=>String(e.seriesId),minWidthPx:760,maxBodyHeight:z,defaultSort:{columnKey:`series`,dir:`asc`},emptyMessage:f(`history.orphans.empty`,`Every series is linked to a device.`),selection:{selected:g,onChange:_,rowLabel:e=>`${Z(e)} — ${X(e,c,f)}`,pageLabel:f(`history.orphans.selectAll`,`Select every listed series`)}})]}),e(ue,{children:[n(`span`,{className:`mr-auto text-[11px] tabular-nums text-foreground`,"aria-live":`polite`,children:f(`history.orphans.selected`,{count:E.length,defaultValue_one:`{{count}} selected`,defaultValue_other:`{{count}} selected`})}),n(I,{variant:`ghost`,size:`sm`,onClick:a,children:f(`history.orphans.close`,`Close`)}),e(I,{variant:`danger`,size:`sm`,disabled:E.length===0||v,onClick:()=>void O(),children:[v?n(p,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):n(s,{className:`h-3 w-3`,"aria-hidden":!0}),f(`history.orphans.deleteSelected`,`Delete selected`)]})]})]})})}i();var Ge=5*6e4;function Ke({enabled:i}){let{t:a}=H(),[s,c]=r(!1),l=ie({},{enabled:i,staleTime:Ge}),u=P({projection:`slim`},{enabled:i}),d=re(),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(T,{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(T,{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(I,{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}=H(),c=D(),l=N(),u=e=>W(e,c,l),d=_e(r,{searchText:e=>[Oe(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(he,{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(x,{columns:f,rows:d.rows,rowKey:e=>e.id,maxBodyHeight:z,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([g.Hub,g.Container]),$=5*6e4;function Ze(){let{t:r}=H(),i=ee(`device-history`),[a,o]=Te(),s=t(()=>F(a.getAll(`s`).flatMap(e=>{let t=ae(e);return t===null?[]:[t]})),[a]),l=a.get(`window`),f=fe(l)?l:`7d`,p=pe(a.get(`range`)),h=(e,t,n)=>{let r=new URLSearchParams;for(let t of F(e))r.append(`s`,xe(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})},g=Qe(i===`present`),_=O(f,Date.now(),p),x=O(f,se(Date.now(),_.to-_.from),p),S=t(()=>Ne(s,g.candidates),[s,g.candidates]),w=t(()=>new Set(s.map(B)),[s]),E=be(),D=v(),k=M(),A=async()=>{let e=await D({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 E.update(t=>te(t,{id:`panel-${Date.now().toString(36)}`,name:e.trim().slice(0,80),window:f,selection:[...s]}))},j=async(e,t)=>{await k({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 E.update(t=>b(t,e))},N=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(Ee,{icon:m,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(I,{size:`sm`,variant:`outline`,onClick:()=>void A(),disabled:s.length===0||!E.writable,children:[n(d,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),r(`history.page.saveTitle`,`Save as panel`)]}):void 0,children:i===`pending`?n(L,{className:`h-64 w-full`}):i===`unknown`?n(T,{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(C,{icon:c,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:[ke.map(e=>n(I,{size:`sm`,variant:`outline`,disabled:g.status!==`ok`,onClick:()=>h(Me(e,g.candidates),f),children:N(e)},e)),E.value.panels.map(t=>e(`span`,{className:`inline-flex items-center`,children:[n(I,{size:`sm`,variant:`secondary`,onClick:()=>h(t.selection,t.window,null),children:t.name}),n(I,{size:`sm`,variant:`ghost`,"aria-label":r(`history.page.deleteNamed`,`Delete panel {{name}}`,{name:t.name}),onClick:()=>void j(t.id,t.name),disabled:!E.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(V,{headingId:`history-picker`,title:r(`history.picker.title`,`Series`),children:n(`div`,{className:`p-2 sm:p-3`,children:g.status===`error`?n(T,{message:g.error}):n(Ye,{catalog:g.candidates,loading:g.status===`pending`,selected:w,onChange:e=>{let t=s.filter(t=>e.has(B(t))),n=g.candidates.filter(t=>e.has(t.id)&&!w.has(t.id)).map(e=>e.ref);h([...t,...n],f)}})})})}),n(`div`,{className:`min-w-0 xl:col-span-3`,children:n(V,{headingId:`history-overlay`,title:r(`history.page.overlay`,`Overlay`),actions:s.length>0?n(I,{size:`sm`,variant:`ghost`,onClick:()=>h([],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(de,{value:f,onChange:e=>h(s,e),custom:p,onCustomChange:e=>h(s,`custom`,y(e))}),g.status===`pending`&&s.length>0?n(L,{className:`h-64 w-full`}):n(Pe,{part:S,window:x}),S.missing.length>0&&g.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}=H(),r=n(`history.picker.wholeFrame`,`Whole frame`),i=f().trpcClient,o=P({projection:`slim`},{enabled:e}),{nodes:s}=ne(),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=ye({},{enabled:e,staleTime:$}),p=t(()=>new Map((d?.data??[]).map(e=>[e.id,e.displayName])),[d?.data]),m=l.map(e=>e.data),h=u.map(e=>e.data),g=t(()=>De(c.flatMap((e,t)=>{let n=m[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 p.get(e.scope)??e.scope;let{zoneId:t,className:n}=_(e.scope),i=t===``?r:t;return n===void 0?i:`${i} · ${n}`}),[c,s,p,[...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};
@@ -1 +0,0 @@
1
- import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,a as s,et as c,o as l,t as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{An as f,D as p,Et as m,Gr as h,In as g,Ki as _,Lt as v,Pt as y,cn as b,dt as x,en as S,fn as C,hi as w,hr as T,ir as E,ln as D,mn as O,on as k,ot as ee,sr as A,ur as j,xn as M,zr as N}from"./player-overlays-Cs6l33cj.js";import{Ia as P,La as F,Ra as I,Xi as L,Zi as te,s as R}from"./client-Ct1F5MoE.js";import{i as z,n as ne,r as re,t as ie}from"./key-xS-HUgNI.js";import{d as ae,l as oe,s as se}from"./video-Byw3ItoR.js";import{t as ce}from"./key-round-BDT5O9Ed.js";import{t as le}from"./monitor-smartphone-Cqk6Z8Hg.js";import{t as ue}from"./unlink-Behl018w.js";import{$r as de,$u as fe,Ad as B,Ai as pe,Cn as me,Dr as he,Er as V,Gn as ge,Gu as _e,Hn as H,Hs as U,Hu as ve,Ju as ye,Ku as be,Qr as W,Qu as xe,R as Se,Sn as G,So as Ce,St as we,Un as Te,Uu as Ee,Vn as De,Wn as Oe,Ws as ke,Wu as Ae,Xs as je,Xu as Me,Yu as Ne,Zs as Pe,Zu as Fe,_r as Ie,ad as Le,cd as Re,ei as K,fr as ze,gn as Be,gr as Ve,hn as He,ht as Ue,id as We,ji as Ge,kr as Ke,ld as qe,mr as Je,od as Ye,pr as Xe,pt as Ze,qs as Qe,qu as $e,rt as et,sd as tt,si as q,sr as nt,ur as rt,vr as it,wn as at,xn as ot,zn as st}from"./src-DFzrn-CX.js";import{t as J}from"./i18n-sTui-nG3.js";import{t as Y}from"./useTranslation-BJr-n0es.js";import{$n as ct,S as lt,a as ut,d as dt,dr as ft,hr as pt,i as mt,l as ht,lr as gt,pr as _t,ur as vt}from"./index-Dow2-3ZC.js";import{t as yt}from"./AdminSectionedPage-D9jBOpIg.js";import{t as bt}from"./AdminPage-QmLz5qjj.js";import{A as xt,C as St,D as Ct,E as wt,O as X,S as Tt,T as Et,a as Dt,b as Ot,c as kt,d as At,f as jt,g as Mt,h as Nt,i as Pt,k as Ft,l as It,m as Lt,n as Rt,o as zt,p as Bt,s as Vt,t as Ht,u as Ut,v as Wt,w as Gt,x as Kt,y as qt}from"./SessionsList-BNTGQ-KG.js";import{i as Jt,n as Yt,r as Xt,t as Zt}from"./IntegrationHub-D5yLfTfh.js";import{n as Qt,t as $t}from"./addon-display-names-BkwMrExv.js";c();function en(){let{t:e}=Y(),t=W(),r=B.useUtils(),a=xt(),{data:s,isLoading:c}=ye(),l=n(()=>s??[],[s]),u=B.useQueries(e=>l.map(t=>e.userManagement.listExternalIdentities({userId:t.id}))),d=B.auth.listLoginMethods.useQuery(),[f,p]=o(null),m=xe({onSuccess:()=>void r.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=>({...Tt(e,a),kind:h.get(e.provider)??e.provider})),v=async n=>{let r=g.find(e=>Kt(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 i(X,{notice:Ft(f),onDismissNotice:()=>{p(null)},id:`external-identities`,title:e(`access.externalIdentitiesSection.signInLinks`,`Sign-in links`),icon:ae,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:i(Et,{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:ue,isAvailable:()=>!0,onRun:e=>void v(e),busyId:null,disabled:m.isPending}})})}c();var tn={key:`access.nouns.linkedApp`};function nn(e){if(e.type===`category`){let t=e.target??``;return t===`device`?J.t(`access.linkedAppsSection.allDevices`):J.t(`access.linkedAppsSection.allTarget`,{target:t})}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function rn(){let{t:e}=Y(),t=W(),r=l(),a=$e(),[s,c]=o(null),u=()=>void r.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]}),d=Me({onSuccess:u,onError:e=>c(`Revoke failed: ${e.message}`)}),f=wt(tn,u),p=n(()=>(a.data??[]).map(e=>St(e,e.scopes.map(nn).join(`, `))),[a.data]),m=async n=>{await t({title:e(`access.linkedAppsSection.revokeTheLink`,`Revoke the "{{name}}" link?`,{name:n.name}),message:e(`access.linkedAppsSection.losesAccessForOnIts`,`{{name}} loses access for {{ownerName}} on its next call. Linking it again needs the account-link flow from the start.`,{name:n.name,ownerName:n.ownerName}),confirmLabel:e(`access.linkedAppsSection.revoke`,`Revoke`),variant:`danger`})&&(c(null),d.mutate({id:n.id}))},h=d.isPending?d.variables?.id??null:null;return i(X,{notice:Ft(s,f.outcome),onDismissNotice:()=>{c(null),f.dismiss()},id:`linked-apps`,title:e(`access.linkedAppsSection.linkedApps`,`Linked apps`),icon:j,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:i(Et,{rows:p,label:e(`access.linkedAppsSection.linkedApps2`,`linked apps`),isLoading:a.isLoading,loadError:a.isError?a.error?.message??`Request failed`:null,emptyText:`No linked apps — an integration appears here once it completes the account-link flow.`,expiresNone:`—`,action:{label:e(`access.linkedAppsSection.revoke`,`Revoke`),icon:v,isAvailable:e=>e.status===`active`||e.status===`revoked`,onRun:e=>void m(e),busyId:h,disabled:d.isPending||f.busy},bulk:{revoke:f,noun:tn,isSelectable:e=>e.status===`active`||e.status===`revoked`,quickSelect:[{label:e(`access.linkedAppsSection.selectRevoked`,`Select revoked`),match:e=>e.status===`revoked`}]}})})}c();var an={key:`access.nouns.session`};function on(){let{t:e}=Y(),t=W(),r=B.useUtils(),a=xt(),s=B.auth.listSessions.useQuery(),[c,l]=o(null),u=()=>void r.auth.listSessions.invalidate(),d=B.auth.revokeSessions.useMutation({onSuccess:u,onError:e=>l(`Sign out failed: ${e.message}`)}),f=wt(an,u),p=n(()=>(s.data??[]).map(e=>Gt(e,a,{client:e=>Wt(e).label,method:qt})),[s.data,a]),m=async n=>{await t({title:e(`access.loginSessionsSection.signOutThisSession`,`Sign out this session`),message:e(`access.loginSessionsSection.onWillHaveToSign`,`{{ownerName}} on {{name}} will have to sign in again.`,{ownerName:n.ownerName,name:n.name}),confirmLabel:e(`access.loginSessionsSection.signOut`,`Sign out`),variant:`danger`})&&(l(null),d.mutate({id:n.id}))};return i(X,{notice:Ft(c,f.outcome),onDismissNotice:()=>{l(null),f.dismiss()},id:`login-sessions`,title:e(`access.loginSessionsSection.loginSessions`,`Login sessions`),icon:le,description:e(`access.loginSessionsSection.everyBrowserAndAppSigned`,`Every browser and app signed in to this hub, for every user. Signing one out ends it at once; it has to sign in again. Your own current session is marked and never included in a bulk sign-out.`),children:i(Et,{rows:p,label:e(`common.sessionsLabel`),isLoading:s.isLoading,loadError:s.isError?s.error?.message??`Request failed`:null,emptyText:`No active sessions.`,action:{label:e(`access.loginSessionsSection.signOut`,`Sign out`),icon:se,isAvailable:e=>e.status===`active`,onRun:e=>void m(e),busyId:d.isPending&&d.variables!==void 0&&`id`in d.variables?d.variables.id:null,disabled:d.isPending||f.busy},bulk:{revoke:f,noun:an,isSelectable:e=>e.status===`active`}})})}var sn={"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 cn(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 ln(e){let t=Z(e,`prefix`);return t===null?null:J.t(`helpers.authAuditWording.prefix`,{prefix:t})}function un(e,t){let n=e.detail??{};switch(e.action){case`admin-token-created`:{let e=n.expiresAt;return{title:J.t(`helpers.authAuditWording.tokenCreated`,{name:cn(n,t)}),details:Q([ln(n),typeof e==`number`?J.t(`helpers.authAuditWording.expires`,{at:Ot(e)}):null])}}case`admin-token-used`:{let e=Z(n,`path`);return{title:J.t(`helpers.authAuditWording.tokenUsed`,{name:cn(n,t)}),details:Q([ln(n),e===null?null:J.t(`helpers.authAuditWording.call`,{path:e})])}}case`token-minted`:{let e=n.expiresAt;return{title:J.t(`helpers.authAuditWording.tokenMinted`,{name:cn(n,t)}),details:Q([typeof e==`number`?J.t(`helpers.authAuditWording.expires`,{at:Ot(e)}):null])}}case`token-revoked`:return{title:J.t(`helpers.authAuditWording.anyTokenRevoked`,{name:cn(n,t)}),details:[]};case`admin-token-revoked`:return{title:J.t(`helpers.authAuditWording.tokenRevoked`,{name:cn(n,t)}),details:Q([ln(n)])};case`credentials-revoked`:{let e=Z(n,`kind`)??`credential`,t=n.revoked,r=n.skipped,i=sn[e],a=i===void 0?`${e}s`:J.t(i);return{title:J.t(`helpers.authAuditWording.bulkRevoked`,{n:typeof t==`number`?String(t):`?`,noun:a}),details:Q([typeof r==`number`&&r>0?J.t(`helpers.authAuditWording.skipped`,{count:r}):null,Z(n,`ids`)===null?null:J.t(`helpers.authAuditWording.ids`,{ids:Z(n,`ids`)??``})])}}case`second-factor-skipped`:{let e=Z(n,`method`),t=Z(n,`factors`);return{title:J.t(`helpers.authAuditWording.secondFactorSkipped`),details:Q([e===null?null:J.t(`helpers.authAuditWording.signedInWith`,{method:qt(e)}),t===null?null:J.t(`helpers.authAuditWording.skippedFactors`,{factors:t.split(`,`).join(`, `)})])}}default:return{title:e.action,details:Object.entries(n).map(([e,t])=>`${e}: ${String(t)}`)}}}c();var dn=100;function fn(){let{user:e}=ct();return e?.isAdmin?i(mn,{}):null}function pn(){let{data:e}=ye(),{data:t}=B.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 mn(){let{t}=Y(),n=B.auth.listAuthAudit.useQuery({limit:dn}),{userNameById:r,tokenNameById:a}=pn(),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:[i(O,{className:`h-3.5 w-3.5 text-foreground-subtle`}),i(`div`,{className:`text-xs font-semibold text-foreground`,children:t(`auth.authAuditSection.authenticationAudit`,`Authentication audit`)}),i(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:t(`auth.authAuditSection.latest`,{count:dn})})]}),i(`div`,{className:`p-4`,children:n.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(A,{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:[i(`div`,{children:t(`auth.authAuditSection.noAuthenticationEventsRecordedYet`,`No authentication events recorded yet.`)}),i(`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.`)})]}):i(`ul`,{className:`divide-y divide-border rounded-md border border-border max-h-[420px] overflow-y-auto`,children:o.map(e=>i(hn,{record:e,userName:e.userId===void 0?null:r.get(e.userId)??e.userId,tokenNameById:a},e.id))})})]})}function hn({record:t,userName:n,tokenNameById:r}){let a=un(t,r);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:[i(`span`,{className:`font-medium text-foreground`,children:a.title}),i(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Ot(t.at)})]}),e(`div`,{className:`flex flex-wrap gap-x-3 text-[11px] text-foreground-subtle`,children:[n!==null&&i(`span`,{className:`text-foreground`,children:n}),t.ip!==void 0&&i(`span`,{className:`font-mono`,children:t.ip}),a.details.map(e=>i(`span`,{className:`font-mono`,children:e},e))]})]})}c();var $={loginSessions:`login-sessions`,linkedApps:`linked-apps`,tokens:`tokens`,scopedTokens:`scoped-tokens`,adminTokens:`admin-tokens`,shareLinks:`share-links`,externalIdentities:`external-identities`,audit:`auth-audit`},gn={[$.scopedTokens]:$.tokens,[$.adminTokens]:$.tokens,[$.shareLinks]:$.tokens};function _n(){return[{id:$.loginSessions,label:J.t(`system.access.loginSessions`,`Login sessions`),icon:le,render:()=>i(on,{})},{id:$.linkedApps,label:J.t(`system.access.linkedApps`,`Linked apps`),icon:j,render:()=>i(rn,{})},{id:$.tokens,label:J.t(`system.access.tokens`,`Tokens`),icon:ce,render:({createRequested:e,onCreateConsumed:t})=>i(Nt,{headerOwnsCreate:!0,createRequested:e,onCreateConsumed:t})},{id:$.externalIdentities,label:J.t(`system.access.signInLinks`,`Sign-in links`),icon:ae,render:()=>i(en,{})},{id:$.audit,label:J.t(`system.access.audit`,`Audit`),icon:O,render:()=>i(fn,{})}]}function vn({createRequested:t=!1,onCreateConsumed:r}){let{t:a}=Y(),o=n(()=>_n(),[]),s=Jt({ids:n(()=>o.map(e=>e.id),[o]),answered:!0}),c=_t(),[l]=pt(),u=l.get(`integration`),d=u===null?void 0:gn[u];if(d!==void 0){let e=new URLSearchParams(l);return e.set(`integration`,d),i(ft,{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:[i(st,{appearance:`pills`,value:f?.id??$.loginSessions,onValueChange:e=>{c(`?${dt(l,e,null,null).toString()}`)},children:i(De,{"aria-label":a(`system.access.credentialKinds`,`Credential kinds`),children:o.map(t=>e(H,{value:t.id,"data-testid":`access-kind-${t.id}`,children:[i(t.icon,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),t.label]},t.id))})}),f===void 0?null:i(`div`,{role:`region`,"aria-label":f.label,"data-testid":`access-kind-body`,children:f.render({createRequested:t&&f.id===$.tokens,onCreateConsumed:r??(()=>void 0)})},f.id)]})}function yn(t,n){if(t===$.tokens)return e(K,{size:`sm`,type:`button`,"data-testid":`access-new-token`,onClick:n,children:[i(ce,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),J.t(`system.access.newToken`,`New token`)]})}function bn(){let[e,t]=o(!1);return{createRequested:e,requestCreate:()=>t(!0),clearCreate:()=>t(!1)}}c();var xn=[`oidcConnections`,`listConnections`],Sn=[`oidcConnections`,`connectionFormSchema`],Cn={displayName:`OpenID Connect`,icon:`shield-check`,issuerUrl:``,clientId:``,clientSecret:``,redirectUri:``,scopes:`openid profile email`,usernameClaim:`preferred_username`},wn=/^[a-z0-9][a-z0-9-]{0,63}$/;function Tn(e){return e instanceof Error?e.message:String(e)}function En(e,t){if(t)return typeof e==`string`&&e.length>0?e:void 0;if(F(e))return P;if(typeof e==`string`&&e.length>0)return e;I(e)}function Dn(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function On({addonId:c}){let{t:p}=Y(),m=ee(),h=l(),g=W(),_=Ze({editKey:`oidcEdit`,newKey:`oidcNew`}),[y,x]=o(!1),[S,C]=o(null),[w,T]=o(``),[E,D]=o({...Cn}),O=t(null),k=s({queryKey:[...xn,c],queryFn:async()=>m.trpcClient.oidcConnections.listConnections.query({})}),A=s({queryKey:Sn,queryFn:async()=>m.trpcClient.oidcConnections.connectionFormSchema.query({})}),j=k.data??[],M=Dn(A.data)?A.data:void 0,N=_.state,P=N.mode===`edit`?j.find(e=>e.id===N.id)??null:null;a(()=>{if(_.state.mode===`edit`&&P!==null){let e=`edit:${P.id}`;if(O.current===e)return;O.current=e,C(null),T(P.id),D(P.formValues===void 0?{...Cn}:{...P.formValues});return}if(_.state.mode===`new`){if(O.current===`new`)return;O.current=`new`,C(null),T(``),D({...Cn})}},[P,_.state]);let F=r(async()=>{await h.invalidateQueries({queryKey:xn})},[h]),I=u({mutationFn:async e=>m.trpcClient.oidcConnections.deleteConnection.mutate({id:e}),onSuccess:async()=>F()}),L=r(async e=>{await g({title:p(`system.oidcSettingsConnections.deleteOidcConnection`,`Delete OIDC connection?`),message:p(`system.oidcSettingsConnections.removeTheLoginButtonAnd`,`Remove “{{displayName}}” ({{id}}). The login button and IdP credentials for this id are dropped.`,{displayName:e.displayName,id:e.id}),confirmLabel:p(`common.delete`,`Delete`),cancelLabel:p(`common.cancel`,`Cancel`),variant:`danger`})&&(await I.mutateAsync(e.id),_.state.mode===`edit`&&_.state.id===e.id&&(_.close(),O.current=null))},[g,I,_,p]),te=r(async()=>{let e=E.displayName,t=typeof e==`string`&&e.trim()!==``?e.trim():``;if(t===``){C(`Display name is required.`);return}let n=_.state.mode===`new`,r=n?w.trim():P?.id??``;if(n&&!wn.test(r)){C(`Instance id must be a lowercase slug (e.g. authentik, google).`);return}if(r===``){C(`That connection is no longer available.`);return}let i=En(E.clientSecret,n),a=E.icon,o=E.issuerUrl,s=E.clientId,c=E.redirectUri,l=E.scopes,u=E.usernameClaim,d=u===`email`||u===`sub`?u:`preferred_username`;x(!0),C(null);try{n&&await m.trpcClient.oidcConnections.createConnection.mutate({id:r,displayName:t}),await m.trpcClient.oidcConnections.updateConnection.mutate({id:r,displayName:t,icon:typeof a==`string`?a:`shield-check`,issuerUrl:typeof o==`string`?o:``,clientId:typeof s==`string`?s:``,...i===void 0?{}:{clientSecret:i},redirectUri:typeof c==`string`?c:``,scopes:typeof l==`string`?l:`openid profile email`,usernameClaim:d}),await F(),_.close(),O.current=null}catch(e){C(Tn(e))}finally{x(!1)}},[w,P?.id,_,E,F,m]),R=n(()=>[{key:`id`,header:p(`system.oidcSettingsConnections.id`,`Id`),sortValue:e=>e.id,render:e=>i(`span`,{className:`font-mono text-xs text-foreground`,children:e.id})},{key:`name`,header:p(`system.oidcSettingsConnections.name`,`Name`),sortValue:e=>e.displayName,render:e=>i(`span`,{className:`truncate font-medium text-foreground`,children:e.displayName})},{key:`issuer`,header:p(`system.oidcSettingsConnections.issuer`,`Issuer`),sortValue:e=>e.issuerUrl,render:e=>i(`span`,{className:`truncate text-xs text-foreground-muted`,children:e.issuerUrl===``?`—`:e.issuerUrl})},{key:`status`,header:p(`system.oidcSettingsConnections.status`,`Status`),notSortableReason:`Badge`,render:e=>i(q,{variant:e.configured?`success`:`warning`,children:e.configured?p(`system.oidcSettingsConnections.configured`,`Configured`):p(`system.oidcSettingsConnections.notConfigured`,`Not configured`)})},{key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,nowrap:!0,render:t=>e(`div`,{className:`flex justify-end gap-1`,children:[i(K,{type:`button`,size:`sm`,variant:`secondary`,onClick:e=>{e.stopPropagation(),_.openEdit(t.id)},children:p(`common.edit`,`Edit`)}),i(K,{type:`button`,size:`sm`,variant:`ghost`,"aria-label":p(`system.oidcSettingsConnections.delete`,`Delete {{displayName}}`,{displayName:t.displayName}),title:p(`common.delete`,`Delete`),onClick:e=>{e.stopPropagation(),L(t)},children:i(v,{className:`h-3.5 w-3.5 text-danger`})})]})}],[_,L,p]),z=_.state.mode===`new`,ne=z||P!==null,re=z?`new`:P===null?`closed`:`edit:${P.id}:${P.configured?`cfg`:`empty`}`,ie=`/addon/${c}/<id>/callback`;return e(`div`,{className:`flex min-h-0 flex-col gap-3`,"data-testid":`oidc-settings-connections`,children:[e(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[e(`p`,{className:`text-sm text-foreground-muted`,children:[p(`system.oidcSettingsConnections.eachRowIsOneIdp`,`Each row is one IdP. Redirect URI:`),` `,i(`span`,{className:`font-mono text-xs`,children:ie})]}),e(K,{type:`button`,size:`sm`,"data-testid":`oidc-connections-add`,onClick:()=>_.openNew(),children:[i(f,{className:`h-3.5 w-3.5`}),p(`system.oidcSettingsConnections.addConnection`,`Add connection`)]})]}),k.isError?i(`p`,{className:`text-sm text-danger`,children:p(`system.oidcSettingsConnections.couldNotLoadConnections`,`Could not load connections.`)}):null,k.isPending?i(Ke,{className:`h-32 w-full`}):i(me,{columns:R,rows:j,rowKey:e=>e.id,pageSize:25,emptyMessage:p(`system.oidcSettingsConnections.noOidcConnectionsYetAdd`,`No OIDC connections yet. Add one to register an IdP.`),onRowClick:e=>_.openEdit(e.id),defaultSort:{columnKey:`name`,dir:`asc`}}),i(Ue,{open:ne,onClose:()=>{_.close(),C(null),O.current=null},title:z?p(`system.oidcSettingsConnections.addOidcConnection`,`Add OIDC connection`):p(`system.oidcSettingsConnections.edit`,`Edit {{value1}}`,{value1:P?.displayName??`connection`}),icon:b,width:`xl`,testId:`oidc-connection-editor`,error:S,footer:i(K,{type:`button`,size:`sm`,disabled:y||z&&w.trim()===``,onClick:()=>void te(),children:y?p(`system.oidcSettingsConnections.saving`,`Saving…`):p(`common.save`,`Save`)}),children:ne?e(d,{children:[z?e(`div`,{children:[i(ge,{htmlFor:`oidc-connection-id`,children:p(`system.oidcSettingsConnections.instanceId`,`Instance id`)}),i(qe,{id:`oidc-connection-id`,value:w,onChange:e=>T(e.target.value),placeholder:`authentik`,autoComplete:`off`}),i(`p`,{className:`mt-1 text-xs text-foreground-muted`,children:p(`system.oidcSettingsConnections.urlSlugAppearsInAddon`,`URL slug — appears in /addon/{{addonId}}/<id>/callback. Stable; renaming is not supported after save.`,{addonId:c})})]}):e(`p`,{className:`text-sm text-foreground-muted`,children:[p(`system.oidcSettingsConnections.instanceId2`,`Instance id:`),` `,i(`span`,{className:`font-mono`,children:P?.id})]}),M===void 0?i(`p`,{className:`text-sm text-foreground-muted`,children:p(`system.oidcSettingsConnections.loadingForm`,`Loading form…`)}):i(nt,{schema:M,values:E,onChange:D,bare:!0},re)]}):null})]})}c();var kn=3e4,An=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],jn={titleKey:`system.authentication.sectionTitle`,subtitleKey:`system.authentication.sectionSubtitle`,emptyTitleKey:`system.authentication.sectionEmptyTitle`,emptyDescriptionKey:`system.authentication.sectionEmptyDescription`,installLabelKey:`system.authentication.sectionInstall`};function Mn(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:ne,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA is self-enrolled: each user enables it from their own profile page (My access → Two-factor authentication).`,`Scoped tokens, admin tokens and sessions are managed from Identity → Tokens & sessions.`],setupSteps:[`A fresh hub has one account, admin / changeme — the first sign-in asks for a new password. Add users from Users → New user.`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:oe,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`Explicit linking only: an IdP account signs in only the CamStack user who linked it from their profile (My access → Linked sign-in accounts). No auto-created users, no email matching.`,`The linked user’s role, scopes and two-factor authentication apply.`],setupSteps:[`Register a web app at your IdP and copy the client_id + client_secret.`,"Choose a stable instance id (slug). Set the IdP redirect URI to `https://<this-hub>/addon/auth-oidc/<id>/callback`.",`In Settings below, Add connection — enter the id, issuer, and credentials; Save.`,`Each user then links their IdP account from My access → Linked sign-in accounts.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:oe,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:S,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)?{headline:`TOTP — second factor.`,icon:S,bullets:[`Time-based codes from an authenticator app (RFC 6238).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:b,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Nn(){let{t:e}=Y(),t=Ge({capName:An[0].capName},{refetchInterval:kn}),r=Ge({capName:An[1].capName},{refetchInterval:kn}),a=pe(void 0,{refetchInterval:kn}),o=n(()=>$t(a.data??[]),[a.data]),s=n(()=>{let e=[],n=[t.data??[],r.data??[]];for(let[t,r]of An.entries())for(let i of n[t]??[])e.push({addonId:i.addonId,displayName:o.get(i.addonId)??i.addonId,isActive:i.isActive,capName:r.capName,stageBadge:r.stageBadge});return e},[t.data,r.data,o]),c=[{id:`authentication`,label:e(`system.authentication.authenticationProviders`,`Authentication providers`),install:{capability:An[0].capName,label:e(jn.installLabelKey)},entries:s.map(t=>({id:t.addonId,name:t.displayName,fallbackIcon:b,...Qt(t.isActive),render:()=>i(Yt,{addonId:t.addonId,displayName:t.displayName,capName:t.capName,isActive:t.isActive,badges:t.stageBadge===null?null:i(q,{variant:`info`,className:Xt,children:t.stageBadge}),settingsContent:t.addonId.startsWith(`auth-oidc`)?i(On,{addonId:t.addonId}):void 0,panels:[{id:`about`,title:e(`system.authentication.about`,`About`),icon:Mn(t.addonId).icon,content:i(Pn,{addonId:t.addonId})}]})}))}];return i(Zt,{embedded:!0,icon:b,title:e(jn.titleKey),subtitle:e(jn.subtitleKey),groups:c,isLoading:t.isLoading||r.isLoading,emptyTitle:e(jn.emptyTitleKey),emptyDescription:e(jn.emptyDescriptionKey)})}function Pn({addonId:t}){let{t:n}=Y(),r=Mn(t),a=r.icon;return e(`div`,{className:`space-y-3 rounded-lg border border-border bg-surface p-2 sm:p-4`,children:[e(`div`,{className:`flex items-start gap-2.5`,children:[i(a,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),i(`div`,{className:`text-xs text-foreground font-medium`,children:r.headline})]}),i(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:r.bullets.map((e,t)=>i(`li`,{children:e},t))}),r.setupSteps&&r.setupSteps.length>0&&e(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[e(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[i(z,{className:`h-3 w-3`}),n(`system.authentication.setupSteps`,`Setup steps`)]}),i(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:r.setupSteps.map((e,t)=>i(`li`,{children:e},t))})]}),t===`local-auth`&&e(`div`,{className:`rounded-md border border-info/30 bg-info/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[i(T,{className:`h-3.5 w-3.5 mt-0.5 text-info shrink-0`}),i(`span`,{children:i(gt,{i18nKey:`system.authentication.totpNote`,components:{access:i(vt,{to:`/system/my-access?tab=sign-in`,className:`underline text-primary`}),users:i(vt,{to:`/system/identity?tab=users`,className:`underline text-primary`})}})})]})]})}function Fn({isPending:t,error:n,what:r,onRetry:a,children:o}){let{t:s}=Y();return t?e(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,role:`status`,"data-testid":`query-pending`,children:[i(A,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),s(`certificates.queryBody.reading`,{what:r})]}):n===null?o:i(V,{title:s(`certificates.queryBody.couldNotRead`,`Could not read {{what}}`,{what:r}),message:n.message.length>0?n.message:s(`certificates.queryBody.requestFailed`,`Request failed`),onRetry:a})}function In(){let{t}=Y(),n=B.deviceCredentials.getDeviceCaStatus.useQuery({}),r=n.data;return i(X,{id:`device-ca`,title:t(`certificates.deviceCaCard.deviceCertificateAuthority`,`Device certificate authority`),icon:b,description:t(`certificates.deviceCaCard.signsTheCertificateEachPaired`,`Signs the certificate each paired device holds. It is created the first time a device is paired.`),children:i(Fn,{isPending:n.isPending,error:n.error,what:`the device CA`,onRetry:()=>void n.refetch(),children:r!==void 0&&e(`div`,{className:`space-y-1`,"data-testid":`device-ca-status`,children:[e(G,{label:t(`certificates.deviceCaCard.state`,`State`),children:[r.state===`ready`&&i(q,{variant:`success`,children:t(`certificates.deviceCaCard.ready`,`Ready`)}),r.state===`absent`&&i(q,{variant:`default`,children:t(`certificates.deviceCaCard.notCreatedYet`,`Not created yet`)}),r.state===`unavailable`&&i(q,{variant:`danger`,children:t(`certificates.deviceCaCard.unavailable`,`Unavailable`)})]}),r.state===`ready`&&e(d,{children:[i(G,{label:t(`certificates.deviceCaCard.subject`,`Subject`),valueClassName:`font-mono`,children:r.subject}),i(G,{label:t(`certificates.deviceCaCard.fingerprintSha256`,`Fingerprint (SHA-256)`),valueClassName:`font-mono`,children:r.fingerprintSha256}),i(G,{label:t(`certificates.deviceCaCard.validUntil`,`Valid until`),children:r.validTo})]}),r.state===`unavailable`&&i(G,{label:t(`certificates.deviceCaCard.reason`,`Reason`),children:i(`span`,{className:`text-danger`,children:r.reason})})]})})})}c();function Ln(){let{t}=Y(),n=B.useUtils(),r=B.deviceCredentials.getDeviceCertificateSettings.useQuery({}),[a,s]=o(null),c=B.deviceCredentials.setDeviceCertificateSettings.useMutation({onSuccess:()=>{s(null),n.deviceCredentials.getDeviceCertificateSettings.invalidate()},onError:e=>s(`Could not save: ${e.message}`)});return i(Fn,{isPending:r.isPending,error:r.error,what:`the enrollment setting`,onRetry:()=>void r.refetch(),children:r.data!==void 0&&e(G,{label:t(`certificates.deviceSettingsRow.usersCanEnrollTheirOwn`,`Users can enroll their own devices`),actions:i(Te,{checked:r.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:[i(`span`,{className:`text-[11px] text-foreground-subtle`,children:r.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.`)}),a!==null&&i(`span`,{className:`block text-[11px] text-danger`,children:a})]})})}c();function Rn(e){let[t,n]=o(()=>Date.now());return a(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}c();var zn=80,Bn=208;function Vn({open:t,users:n,onClose:r,onPaired:a}){let{t:s}=Y(),c=B.deviceCredentials.startEnrollment.useMutation({onSuccess:a}),[l,u]=o(``),[d,f]=o(``),p=l===``?n[0]?.id??``:l,m=c.data,h=()=>{c.reset(),f(``),r()};return i(Ue,{open:t,onClose:h,title:s(`certificates.pairDeviceDialog.pairADevice`,`Pair a device`),icon:S,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&&i(A,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),s(`certificates.pairDeviceDialog.createPairingCode`,`Create pairing code`)]}):i(K,{type:`button`,variant:`outline`,onClick:h,children:s(`certificates.pairDeviceDialog.done`,`Done`)}),children:m===void 0?e(`div`,{className:`space-y-3`,children:[i(`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.`)}),i(we,{label:s(`certificates.pairDeviceDialog.user`,`User`),required:!0,children:i(We,{value:p,onChange:e=>u(e.target.value),options:n.map(e=>({value:e.id,label:e.username}))})}),i(we,{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:i(qe,{value:d,maxLength:zn,onChange:e=>f(e.target.value),placeholder:s(`certificates.pairDeviceDialog.annaSIphone`,`Anna's iPhone`),autoFocus:!0})})]}):i(Hn,{enrollUrl:m.enrollUrl,expiresAt:m.expiresAt,hubKnown:m.hubOrigin!==null,onRestart:()=>c.reset()})})}function Hn({enrollUrl:t,expiresAt:n,hubKnown:r,onRestart:a}){let{t:o}=Y(),s=zt(n,Rn(1e3));return i(`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:[i(`div`,{className:s.expired?`opacity-30`:void 0,children:i(rt,{value:t,size:Bn,alt:o(`certificates.pairDeviceDialog.enrollmentQrCode`,`Enrollment QR code`)})}),e(`div`,{className:`min-w-0 flex-1 space-y-2`,children:[i(`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.`)}),i(`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:[i(`code`,{className:`min-w-0 flex-1 select-all break-all font-mono text-[11px] text-foreground`,children:t}),i(He,{value:t,srLabel:`Enrollment link`})]}),!r&&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:[i(y,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),i(`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&&i(K,{type:`button`,variant:`outline`,size:`sm`,onClick:a,children:o(`certificates.pairDeviceDialog.newCode`,`New code`)})]})]})})}c();var Un={key:`access.nouns.device`};function Wn({pairOpen:t,onPairClose:r}){let{t:a}=Y(),s=W(),c=de(),l=B.useUtils(),u=B.deviceCredentials.listDeviceCredentials.useQuery({includeRevoked:!0}),d=ye(),[f,p]=o(null),[m,h]=o(null),y=()=>void l.deviceCredentials.listDeviceCredentials.invalidate(),b=e=>t=>{h(null),p(`${e} failed: ${t.message}`)},x=()=>{h(null),y()},C=B.deviceCredentials.revokeDeviceCredential.useMutation({onSuccess:x,onError:b(`Revoke`)}),w=B.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.`),x()},onError:b(`Delete`)}),T=B.deviceCredentials.renameDeviceCredential.useMutation({onSuccess:x,onError:b(`Rename`)}),E=Ct(Un,e=>C.mutateAsync({id:e}),y),D=E.busy||m!==null,O=n(()=>(u.data??[]).map(Rt),[u.data]),k=async e=>{await s({title:a(`certificates.devicesCard.revoke`,`Revoke "{{name}}"?`,{name:e.name}),message:a(`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:a(`certificates.devicesCard.revoke2`,`Revoke`),variant:`danger`})&&(p(null),h(e.id),C.mutate({id:e.id}))},ee=async e=>{await s({title:a(`certificates.devicesCard.delete`,`Delete "{{name}}"?`,{name:e.name}),message:a(`certificates.devicesCard.isRemovedFromTheList`,`{{name}} is removed from the list. The audit trail keeps the revocation.`,{name:e.name}),confirmLabel:a(`common.delete`,`Delete`),variant:`danger`})&&(p(null),h(e.id),w.mutate({id:e.id}))},A=async e=>{let t=(await c({title:a(`certificates.devicesCard.renameDevice`,`Rename device`),label:a(`certificates.devicesCard.deviceName`,`Device name`),defaultValue:e.name,confirmLabel:a(`certificates.devicesCard.rename`,`Rename`)}))?.trim()??``;t===``||t===e.name||(p(null),h(e.id),T.mutate({id:e.id,deviceName:t}))},j={label:a(`certificates.devicesCard.revoke2`,`Revoke`),icon:_,isAvailable:Dt,onRun:e=>void k(e),busyId:C.isPending?m:null,disabled:D},M=[{label:a(`certificates.devicesCard.rename`,`Rename`),icon:g,tone:`neutral`,isAvailable:()=>!0,onRun:e=>void A(e),busyId:T.isPending?m:null,disabled:D},{label:a(`common.delete`,`Delete`),icon:v,isAvailable:Pt,onRun:e=>void ee(e),busyId:w.isPending?m:null,disabled:D}];return e(X,{id:`devices`,title:a(`certificates.devicesCard.devices`,`Devices`),icon:S,description:a(`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:Ft(f,E.outcome),onDismissNotice:()=>{p(null),E.dismiss()},children:[i(Ln,{}),i(Et,{rows:O,label:a(`certificates.devicesCard.label`),isLoading:u.isPending,loadError:u.error===null?null:u.error.message||`Request failed`,emptyText:`No devices paired yet.`,expiresNone:`—`,action:j,extraActions:M,bulk:{revoke:E,noun:Un,isSelectable:Dt}}),i(Vn,{open:t,users:d.data??[],onClose:r,onPaired:y})]})}var Gn=/-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----/,Kn=/-----BEGIN ((?:RSA |EC |ENCRYPTED )?PRIVATE KEY)-----[\s\S]+?-----END \1-----/,qn={certificate:`.pem,.crt,.cer`,privateKey:`.pem,.key`,ca:`.pem,.crt,.cer`};function Jn(e,t){if(t.trim()===``)return null;if(e===`privateKey`){let e=Kn.exec(t);return e===null?Gn.test(t)?J.t(`helpers.pemFile.isCert`):J.t(`helpers.pemFile.notKey`):e[1]===`ENCRYPTED PRIVATE KEY`?J.t(`helpers.pemFile.encrypted`):null}return Gn.test(t)?e===`certificate`&&Kn.test(t)?J.t(`helpers.pemFile.certHasKey`):null:Kn.test(t)?J.t(`helpers.pemFile.isKey`):J.t(`helpers.pemFile.notCert`)}function Yn(e){return e.text()}c();function Xn({kind:n,label:r,value:a,onChange:s,rows:c=6}){let{t:l}=Y(),u=t(null),[d,f]=o(null),[p,m]=o(null),h=p??Jn(n,a),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 Yn(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:[i(`label`,{htmlFor:g,className:`text-[11px] text-foreground-subtle`,children:r}),e(`div`,{className:`flex min-w-0 items-center gap-2`,children:[d!==null&&i(`span`,{className:`truncate font-mono text-[10px] text-foreground-subtle`,"data-testid":`${g}-file-name`,children:d}),i(`input`,{ref:u,type:`file`,accept:qn[n],onChange:e=>void _(e),className:`hidden`,"data-testid":`${g}-file`}),e(K,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>u.current?.click(),children:[i(re,{className:`mr-1 h-3 w-3`}),l(`system.pemField.chooseFile`,`Choose file`)]})]})]}),i(`textarea`,{id:g,value:a,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&&i(`p`,{className:`text-[11px] text-danger`,role:`alert`,children:h})]})}c();var Zn=30;function Qn(e){let t=Date.parse(e);return!Number.isNaN(t)&&Date.now()-t<Zn*864e5}function $n(e){if(e===null||e===``)return`—`;let t=e.replace(/:/g,``);return t.length<=16?e:`${t.slice(0,8)}…${t.slice(-8)}`}function er(){let{t}=Y(),n=l(),r=U(void 0,{refetchInterval:15e3}),a=ke({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),s=Qe({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),c=Pe({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),u=je({onSuccess:()=>{m(!1),g(``),v(``),b(``),n.invalidateQueries({queryKey:[[`localNetwork`]]})}}),d=r.data,[f,m]=o(!1),[h,g]=o(``),[_,v]=o(``),[y,b]=o(``),x=()=>{if(!d?.caCertPem)return;let e=new Blob([d.caCertPem],{type:`application/x-pem-file`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`camstack-ca.crt`,n.click(),URL.revokeObjectURL(t)},S=d?.mode===`uploaded`?`Uploaded`:d?.mode===`generated`?`Generated local CA`:`TLS disabled`;return i(ot,{headingId:`local-access-certificate`,title:t(`system.localAccess.certificate`,`Certificate`),icon:k,children:e(`div`,{className:`${p} space-y-3`,children:[r.isError&&i(`p`,{className:`text-xs text-danger`,children:t(`system.localAccess.couldNotReadTlsStatus`,`Could not read TLS status.`)}),d?.reissueError&&i(V,{variant:`warning`,title:t(`system.localAccess.certificateReissue`,`Certificate reissue`),message:d.reissueError}),d?.restartRequired&&i(V,{variant:`warning`,title:t(`system.localAccess.restartRequired`,`Restart required`),message:t(`system.localAccess.theHttpsListenerStillServes`,`The HTTPS listener still serves the previous certificate. Restart the hub to apply it.`)}),d?.caMissing===!0&&i(V,{variant:`warning`,title:t(`system.localAccess.caMissingTitle`,`CA missing - devices cannot trust this hub`),message:t(`system.localAccess.caMissingBody`,"The uploaded certificate was not issued by a public CA and no CA was stored with it, so Download CA has nothing to hand out. Upload the certificate again together with its CA (for mkcert, the rootCA.pem in the folder `mkcert -CAROOT` prints).")}),d?.caReplacedAt!=null&&Qn(d.caReplacedAt)&&i(V,{variant:`warning`,title:t(`system.localAccess.caReplacedTitle`,`The local CA was replaced - re-install it on your devices`),message:t(`system.localAccess.caReplacedBody`,`The previous local CA had no name constraints: if its key ever leaked it could vouch for any website. The hub now uses a CA limited to private addresses and local names. Download it again and trust it on every phone and computer that used the old one (replaced {{when}}).`,{when:new Date(d.caReplacedAt).toLocaleString()})}),e(`dl`,{className:`grid grid-cols-1 gap-2 text-xs sm:grid-cols-2`,children:[e(`div`,{children:[i(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.mode`,`Mode`)}),i(`dd`,{className:`font-medium`,children:S})]}),e(`div`,{children:[i(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.validTo`,`Valid to`)}),i(`dd`,{className:`font-mono`,children:d?.validTo?new Date(d.validTo).toLocaleString():`—`})]}),e(`div`,{children:[i(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.leafSha256`,`Leaf SHA-256`)}),i(`dd`,{className:`font-mono`,title:d?.leafFingerprintSha256??void 0,children:$n(d?.leafFingerprintSha256??null)})]}),d?.storedUpload!=null&&e(`div`,{children:[i(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.storedUpload`,`Stored upload`)}),i(`dd`,{className:`font-medium`,children:t(`system.localAccess.storedUploadValue`,`valid to {{validTo}}, {{ca}}`,{validTo:new Date(d.storedUpload.validTo).toLocaleDateString(),ca:d.storedUpload.hasCa?t(`system.localAccess.storedUploadWithCa`,`with its CA`):t(`system.localAccess.storedUploadNoCa`,`no CA`)})})]}),e(`div`,{children:[i(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.caSha256`,`CA SHA-256`)}),i(`dd`,{className:`font-mono`,title:d?.caFingerprintSha256??void 0,children:d?.mode===`uploaded`&&d.caFingerprintSha256===null?i(`span`,{className:`font-sans text-foreground-subtle`,children:t(`system.localAccess.issuerNotIncludedInThe`,`Issuer not included in the upload (not the local CA)`)}):$n(d?.caFingerprintSha256??null)})]})]}),d&&d.sans.length>0&&i(`div`,{className:`flex flex-wrap gap-1`,children:d.sans.map(e=>i(`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:[i(Be,{label:t(`system.localAccess.regenerate`,`Regenerate`),title:t(`system.localAccess.issueANewLeaf`,`Issue a new leaf?`),description:t(`system.localAccess.issuesANewLeafUnder`,`Issues a new leaf under the current local CA. Clients that trust the CA keep working. The HTTPS listener reloads.`),confirmLabel:t(`system.localAccess.regenerate`,`Regenerate`),disabled:d?.mode===`uploaded`||a.isPending,action:()=>a.mutateAsync({})}),i(K,{size:`sm`,variant:`outline`,onClick:()=>m(e=>!e),children:t(`system.localAccess.upload`,`Upload`)}),d?.caCertPem&&i(K,{size:`sm`,variant:`outline`,onClick:x,children:t(`system.localAccess.downloadCa`,`Download CA`)}),d?.mode===`uploaded`&&i(Be,{label:t(`system.localAccess.revertToGenerated`,`Revert to generated`),title:t(`system.localAccess.revertTitle`,`Switch back to the generated certificate?`),description:t(`system.localAccess.keepsTheUploadedPair`,`Returns to the generated local CA. The uploaded certificate and its CA stay stored here; you can select them again.`),confirmLabel:t(`system.localAccess.revert`,`Revert`),disabled:s.isPending,action:()=>s.mutateAsync({})}),d?.mode===`generated`&&d.storedUpload!=null&&i(Be,{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:c.isPending,action:()=>c.mutateAsync(void 0)})]}),f&&e(`div`,{className:`space-y-2 border-t border-border pt-3`,children:[i(Xn,{kind:`certificate`,label:t(`system.localAccess.certificateOrFullChainPem`,`Certificate or full chain (PEM)`),value:h,onChange:g}),i(Xn,{kind:`privateKey`,label:t(`system.localAccess.privateKeyPem`,`Private key (PEM)`),value:_,onChange:v}),i(Xn,{kind:`ca`,label:t(`system.localAccess.caPemRequired`,`CA (PEM) - required unless the certificate comes from a public CA`),value:y,onChange:b,rows:4}),i(K,{size:`sm`,disabled:!h.trim()||!_.trim()||Jn(`certificate`,h)!==null||Jn(`privateKey`,_)!==null||Jn(`ca`,y)!==null||u.isPending,onClick:()=>u.mutate({certPem:h,keyPem:_,...y.trim()?{caPem:y}:{}}),children:t(`system.localAccess.saveCertificate`,`Save certificate`)}),u.isError&&i(`p`,{className:`text-xs text-danger`,children:u.error instanceof Error?u.error.message:t(`system.localAccess.uploadFailed`,`Upload failed`)})]})]})})}var tr={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`};function nr(e){let t=e.find(e=>e.isHub);return t?.https.kind===`served`?t.https.status.caFingerprintSha256:null}function rr({https:t,mesh:n,now:r}){let{t:a}=Y(),o=U().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:[i(G,{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:[nr(t)??`—`,o!==``&&e(K,{type:`button`,variant:`ghost`,size:`sm`,onClick:s,children:[i(h,{className:`h-3 w-3`,"aria-hidden":!0}),a(`certificates.caStrip.downloadCa`,`Download CA`)]})]})}),i(G,{label:a(`certificates.caStrip.clusterCaSha256`,`Cluster CA (SHA-256)`),valueClassName:`font-mono`,children:c===void 0?`—`:c.state===`ready`?c.fingerprintSha256:i(`span`,{className:`text-danger`,children:a(`certificates.caStrip.unavailable`,{reason:c.reason})})}),c?.state===`ready`&&e(G,{label:a(`certificates.caStrip.clusterCaValidUntil`,`Cluster CA valid until`),children:[c.validTo,l!==null&&!Number.isNaN(l)&&e(`span`,{className:`ml-2 text-[10px] ${tr[Ut(l,r)]}`,children:[`(`,kt(l,r),`)`]})]}),u!==void 0&&e(G,{label:a(`certificates.caStrip.nodeListener`,`Node listener`),children:[u.state===`open`&&i(q,{variant:`success`,children:a(`certificates.caStrip.open`,`Open`)}),u.state===`not-started`&&i(q,{variant:`default`,children:a(`certificates.caStrip.notStarted`,`Not started`)}),u.state===`closed`&&e(`span`,{className:`text-danger`,children:[a(`certificates.caStrip.closedSince`,{when:At(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:[i(y,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),i(`span`,{children:a(`certificates.caStrip.theCertificateRegistryIsNot`,`The certificate registry is not up, so the node list below is incomplete.`)})]})]})}function ir(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 ar(e){return e.isHub?J.t(`helpers.nodesModel.hubReissued`):e.mesh===null?J.t(`helpers.nodesModel.noCertRecorded`):e.online?null:J.t(`helpers.certificateModel.nodeOffline`)}function or(e){return e.isHub||e.mesh===null?ar(e):null}var sr={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`},cr={enroll:`Issued at enrollment`,renewal:`Issued by a renewal`,boot:`Issued at boot`,pairing:`Issued at pairing`,observed:`Observed on its connection`},lr={uploaded:`Uploaded`,generated:`Generated`,disabled:`Disabled`};function ur(e){let t=e.https?.https;return t?.kind===`served`?Vt(t.status.validTo):null}function dr({ms:t,now:n}){return t===null?i(`span`,{className:`text-foreground-subtle`,children:`—`}):e(`div`,{children:[i(`div`,{children:At(t)}),i(`div`,{className:`text-[10px] ${sr[Ut(t,n)]}`,children:kt(t,n)})]})}function fr({row:t}){let{t:n}=Y(),r=t.https?.https;return r===void 0?i(`span`,{className:`text-foreground-subtle`,children:`—`}):r.kind===`served`?e(`div`,{title:r.status.leafFingerprintSha256??``,children:[i(q,{variant:`success`,className:`text-[10px]`,children:n(`certificates.nodesColumns.served`,`Served`)}),i(`span`,{className:`ml-1.5 text-[10px] text-foreground-subtle`,children:lr[r.status.mode]}),i(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:Bt(r.status.leafFingerprintSha256)}),r.status.sans.length>0&&i(`div`,{className:`mt-0.5 max-w-[14rem] truncate font-mono text-[10px] text-foreground-subtle`,title:r.status.sans.join(`, `),children:r.status.sans.join(`, `)})]}):e(`div`,{className:`max-w-[16rem]`,children:[i(q,{variant:r.kind===`unreadable`?`danger`:`warning`,className:`text-[10px]`,children:r.kind===`unreadable`?n(`certificates.nodesColumns.unreadable`,`Unreadable`):n(`certificates.nodesColumns.notServed`,`Not served`)}),i(`div`,{className:`mt-1 whitespace-normal text-[10px] text-foreground-subtle`,children:r.reason})]})}function pr({row:t}){let{t:n}=Y(),r=t.mesh?.current??null;if(r===null)return i(`span`,{className:`text-foreground-subtle`,children:n(`certificates.nodesColumns.noneRecorded`,`None recorded`)});let a=t.mesh?.history.length??0;return e(`div`,{children:[i(`div`,{className:`font-mono text-[11px]`,title:r.serial,children:Lt(r.serial)}),i(`div`,{className:`font-mono text-[10px] text-foreground-subtle`,title:r.fingerprintSha256,children:Bt(r.fingerprintSha256)}),e(`div`,{className:`text-[10px] text-foreground-subtle`,children:[cr[r.issuedVia],a>0?` · ${n(`certificates.nodesColumns.earlier`,{count:a})}`:``]})]})}function mr({row:e}){let{t}=Y(),n=e.mesh?.presentingCurrent??null;return n===null?i(`span`,{className:`text-foreground-subtle`,children:e.online?`—`:t(`certificates.nodesColumns.offline`,`Offline`)}):n?i(q,{variant:`success`,className:`text-[10px]`,children:t(`common.yes`,`Yes`)}):i(q,{variant:`warning`,className:`text-[10px]`,children:t(`certificates.nodesColumns.noPresentsAnother`,`No - presents another`)})}function hr(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?i(A,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):i(n,{className:`h-3 w-3`,"aria-hidden":!0}),t.label]})}function gr({reasons:t}){let{t:n}=Y();return e(Ye,{className:`inline-block`,children:[i(Re,{children:i(`span`,{className:`cursor-help text-[11px] text-foreground-subtle`,"data-testid":`hub-managed-note`,children:n(`certificates.nodesColumns.managedByTheHub`,`Managed by the hub`)})}),i(tt,{children:i(`ul`,{className:`max-w-xs space-y-1 whitespace-normal text-left text-[11px]`,children:t.map(e=>i(`li`,{children:e},e))})})]})}function _r({row:t,o:n}){let{t:r}=Y(),a=t.https===null?`No HTTPS inventory for this node.`:jt(t.https).reason,o=ar(t),s=or(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)&&i(hr,{label:r(`certificates.nodesColumns.renewHttps`,`Renew HTTPS`),ariaLabel:r(`certificates.nodesColumns.renewTheCertificateOn`,`Renew the certificate on {{nodeId}}`,{nodeId:t.nodeId}),icon:M,reason:a,busy:n.busy,spinning:c(`renew-https`),danger:!1,onClick:()=>n.onRenewHttps(t)}),l(o)&&i(hr,{label:c(`renew-identity`)?r(`certificates.nodesColumns.renewing`,`Renewing…`):r(`certificates.nodesColumns.renewIdentity`,`Renew identity`),ariaLabel:r(`certificates.nodesColumns.renewTheClusterCertificateOf`,`Renew the cluster certificate of {{nodeId}}`,{nodeId:t.nodeId}),icon:M,reason:o,busy:n.busy,spinning:c(`renew-identity`),danger:!1,onClick:()=>n.onRenewIdentity(t)}),l(s)&&i(hr,{label:r(`certificates.nodesColumns.revokeIdentity`,`Revoke identity`),ariaLabel:r(`certificates.nodesColumns.revokeTheClusterCertificateOf`,`Revoke the cluster certificate of {{nodeId}}`,{nodeId:t.nodeId}),icon:_,reason:s,busy:n.busy,spinning:c(`revoke-identity`),danger:!0,onClick:()=>n.onRevokeIdentity(t)})]}),t.isHub&&u.length>0&&i(gr,{reasons:u}),!t.isHub&&a!==null&&t.https!==null&&i(`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&&i(`div`,{className:`w-full whitespace-normal text-right text-[10px] text-foreground-subtle`,"data-testid":`mesh-reason-${t.nodeId}`,children:o})]})}function vr(t){return[{key:`node`,header:J.t(`certificates.nodesColumns.node`,`Node`),sortValue:e=>e.isHub?``:e.nodeId.toLowerCase(),render:t=>e(`div`,{className:`flex items-center gap-1.5`,children:[i(`span`,{className:`font-medium text-foreground`,children:t.nodeId}),t.nodeId===`hub`&&i(q,{variant:`info`,className:`text-[10px]`,children:J.t(`common.hubWord`)}),!t.online&&i(q,{variant:`default`,className:`text-[10px]`,children:J.t(`common.offline`)})]})},{key:`https-state`,header:`HTTPS`,notSortableReason:`A state with a reason has no single order.`,render:e=>i(fr,{row:e})},{key:`https-expires`,header:J.t(`certificates.nodesColumns.httpsExpires`,`HTTPS expires`),sortValue:e=>ur(e),render:e=>i(dr,{ms:ur(e),now:t.now})},{key:`identity`,header:J.t(`certificates.nodesColumns.identity`,`Identity`),sortValue:e=>e.mesh?.current?.serial??null,render:e=>i(pr,{row:e})},{key:`identity-expires`,header:J.t(`certificates.nodesColumns.identityExpires`,`Identity expires`),sortValue:e=>e.mesh?.current?.notAfter??null,render:e=>i(dr,{ms:e.mesh?.current?.notAfter??null,now:t.now})},{key:`presenting`,header:J.t(`certificates.nodesColumns.inUse`,`In use`),notSortableReason:`Offline nodes have no answer to order by.`,render:e=>i(mr,{row:e})},{key:`actions`,header:J.t(`certificates.nodesColumns.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order.`,render:e=>i(_r,{row:e,o:t})}]}c();function yr(){let{t}=Y(),r=W(),a=B.useUtils(),s=Rn(6e4),c=B.certificates.listHttpsCertificates.useQuery(),l=B.certificates.getMeshCertificates.useQuery(),[u,d]=o(null),[f,p]=o(null),[m,h]=o(null),g=()=>{h(null),a.certificates.listHttpsCertificates.invalidate(),a.certificates.getMeshCertificates.invalidate()},_=e=>(t,n)=>{h(null),d(`${n.nodeId}: ${e} - ${t.message}`)},v=B.certificates.renewHttpsOnNode.useMutation({onSuccess:(e,n)=>{p({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})}),g()},onError:_(`renewal failed`)}),y=B.certificates.renewMeshOnNode.useMutation({onSuccess:e=>{p(It(e)),g()},onError:_(`renewal could not start`)}),b=B.certificates.revokeMeshOnNode.useMutation({onSuccess:e=>{p({tone:`success`,message:`${e.nodeId}: ${e.next}`}),g()},onError:_(`revoke failed`)}),x=v.isPending||y.isPending||b.isPending,S=(e,t)=>{d(null),p(null),h({nodeId:e,action:t})},w=async e=>{await r({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`)})&&(S(e.nodeId,`renew-https`),v.mutate({nodeId:e.nodeId}))},T=e=>{S(e.nodeId,`renew-identity`),y.mutate({nodeId:e.nodeId})},E=async e=>{await r({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`})&&(S(e.nodeId,`revoke-identity`),b.mutate({nodeId:e.nodeId}))},D=vr({now:s,busy:x,running:m,onRenewHttps:e=>void w(e),onRenewIdentity:T,onRevokeIdentity:e=>void E(e)}),O=n(()=>ir(c.data??[],l.data),[c.data,l.data]),k=l.data?.registryAvailable??!0;return i(X,{id:`nodes`,title:t(`certificates.nodesCard.nodes`,`Nodes`),icon:C,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:Ft(u,f),onDismissNotice:()=>{d(null),p(null)},children:i(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:[i(rr,{https:c.data??[],mesh:l.data,now:s}),i(me,{columns:D,rows:O,rowKey:e=>e.nodeId,minWidthPx:960,maxBodyHeight:at,defaultSort:{columnKey:`node`,dir:`asc`},emptyMessage:k?t(`certificates.nodesCard.noNodesReported`,`No nodes reported.`):t(`certificates.nodesCard.theCertificateRegistryIsNot`,`The certificate registry is not available yet, so nodes cannot be listed.`)})]})})})}function br({pairOpen:t,onPairClose:n}){return e(`div`,{className:`space-y-4`,"data-testid":`certificates-page`,children:[i(Wn,{pairOpen:t,onPairClose:n}),i(In,{}),i(er,{}),i(yr,{})]})}function xr({userId:t,username:n,onClose:r}){let{t:a}=Y(),o=W(),s=B.useUtils(),c=be({userId:t}),l=B.auth.listLoginMethods.useQuery(),u=xe({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 i(ze,{open:!0,onOpenChange:e=>!e&&r(),children:e(Je,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`external-identities-modal`,children:[i(Ie,{children:e(it,{className:`flex items-center gap-2`,children:[i(j,{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:`),` `,i(`span`,{className:`font-mono`,children:n})]})]})]})}),i(Xe,{className:`space-y-3`,children:c.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(A,{className:`h-3.5 w-3.5 animate-spin`}),a(`common.loading`,`Loading…`)]}):f.length===0?i(`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.`)}):i(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:f.map(t=>{let n=d.get(t.provider),r=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:[r,n===void 0&&i(`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(`button`,{onClick:()=>void p(t,r),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:[i(ue,{className:`h-3 w-3`}),a(`common.remove`,`Remove`)]})]},`${t.provider}|${t.subject}`)})})}),i(Ve,{children:i(K,{onClick:r,variant:`secondary`,children:a(`common.close`,`Close`)})})]})})}function Sr({userId:t,username:n,onClose:r}){let{t:a}=Y(),o=l(),s=W(),c=_e({userId:t}),u=c.data,f=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),p=Ae({onSuccess:()=>{f(),r()}}),m=c.isLoading?`loading`:u?.enabled?`enrolled`:`not_enrolled`;return i(ze,{open:!0,onOpenChange:e=>!e&&r(),children:e(Je,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(Ie,{children:e(it,{className:`flex items-center gap-2`,children:[i(S,{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:`),` `,i(`span`,{className:`font-mono`,children:n})]})]})]})}),e(Xe,{className:`space-y-4`,children:[m===`loading`&&e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(A,{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:[i(T,{className:`h-4 w-4 mt-0.5 shrink-0`}),e(`div`,{children:[i(`div`,{className:`font-medium text-foreground`,children:a(`users.totpModal.2faNotEnrolled`,`2FA not enrolled`)}),i(`p`,{className:`mt-0.5`,children:a(`users.totpModal.onlyTheUserThemselvesCan`,`Only the user themselves can enable 2FA, from their own profile page.`)})]})]}),m===`enrolled`&&u&&e(d,{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:[i(w,{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:[i(`div`,{className:`font-medium`,children:a(`users.totpModal.2faIsActive`,`2FA is active`)}),i(`div`,{className:`text-foreground-subtle`,children:a(`common.enrolledOn`,{when:u.confirmedAt?new Date(u.confirmedAt).toLocaleString():`—`})})]})]}),i(`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:[i(K,{onClick:r,variant:`secondary`,children:a(`common.close`,`Close`)}),e(`button`,{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?i(A,{className:`h-3 w-3 animate-spin`}):i(x,{className:`h-3 w-3`}),a(`users.totpModal.remove2fa`,`Remove 2FA`)]})]})]})]})]})})}c();function Cr({userId:t,username:n,onClose:r}){let{t:a}=Y(),{user:s,logout:c}=ct(),l=s?.id===t,u=W(),d=B.useUtils(),f=B.auth.listSessions.useQuery({userId:t}),[p,m]=o(null),h=B.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:a(`users.userSessionsModal.signOutThisSession`,`Sign out this session`),message:a(`users.userSessionsModal.onWillHaveToSign`,`"{{username}}" on {{label}} will have to sign in again.`,{username:n,label:Wt(e.client).label}),confirmLabel:a(`users.userSessionsModal.signOut`,`Sign out`),variant:`danger`})&&(m(null),h.mutate({id:e.id}))},_=async()=>{await u({title:a(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`),message:l?a(`users.userSessionsModal.everySessionOfYourOwn`,`Every session of your own account ends, this browser included: you will be signed out here too.`):a(`users.userSessionsModal.everySessionOfEndsAt`,`Every session of "{{username}}" ends at once; each device has to sign in again.`,{username:n}),confirmLabel:a(`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 i(ze,{open:!0,onOpenChange:e=>!e&&r(),children:e(Je,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`user-sessions-modal`,children:[i(Ie,{children:e(it,{className:`flex items-center gap-2`,children:[i(le,{className:`h-4 w-4 text-primary`}),e(`span`,{children:[a(`users.userSessionsModal.activeSessions`,`Active sessions`),e(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[a(`users.userSessionsModal.user`,`User:`),` `,i(`span`,{className:`font-mono`,children:n})]})]})]})}),e(Xe,{className:`space-y-3`,children:[p!==null&&i(`div`,{className:`text-[11px] text-danger`,children:p}),i(Ht,{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(Ve,{className:`justify-between`,children:[e(`button`,{onClick:()=>void _(),disabled:h.isPending||(f.data??[]).length===0,className:`inline-flex items-center gap-1.5 rounded border border-danger/40 px-2.5 py-1 text-[11px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,children:[h.isPending&&v===null?i(A,{className:`h-3 w-3 animate-spin`}):i(se,{className:`h-3 w-3`}),a(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`)]}),i(K,{onClick:r,variant:`secondary`,children:a(`common.close`,`Close`)})]})]})})}function wr({scopes:t,invalidReason:n}){let{t:r}=Y(),a=ee(),o=s({queryKey:[`auth`,`previewScope`,t,!1],enabled:n===null,queryFn:()=>a.trpcClient.auth.previewScope.query({scopes:[...t],isAdmin:!1})}),{data:c}=Ce({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:[i(D,{className:`h-3 w-3 shrink-0`}),n]});if(o.isLoading)return e(`p`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,"data-testid":`role-preview`,children:[i(A,{className:`h-3 w-3 shrink-0 animate-spin`}),r(`users.rolePreview.resolving`)]});if(o.isError||!o.data)return i(`p`,{className:`text-[11px] text-danger`,"data-testid":`role-preview`,children:r(`users.rolePreview.couldNotResolve`)});let u=o.data.viewableDeviceCount,d=o.data.device.view.all?r(`users.rolePreview.everyDevice`,{count:u}):l===null?r(`users.rolePreview.devicesVisible`,{count:u}):r(`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?i(D,{className:`h-3 w-3 shrink-0`}):i(N,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),u===0?r(`users.rolePreview.noDevice`):d]})}function Tr(e){let t=R(e.scopes??[]);if(t===null)return{role:e.isAdmin?`admin`:`viewer`,mode:`except`,pickedIds:[],viewer:L,unconfigured:!e.isAdmin};let n=Mr(t);return{role:e.isAdmin?`admin`:`viewer`,mode:n.mode,pickedIds:n.pickedIds,viewer:Nr(n.mode,n.pickedIds,t.features),unconfigured:!1}}function Er(e,t){return{...e,role:t}}function Dr(e,t){return{...e,mode:t,viewer:Nr(t,e.pickedIds,e.viewer.features)}}function Or(e,t){let n=Pr(t);return{...e,pickedIds:n,viewer:Nr(e.mode,n,e.viewer.features)}}function kr(e,t,n){let r=e.viewer.features.filter(e=>e!==t),i=n?[...r,t]:r;return{...e,viewer:Nr(e.mode,e.pickedIds,i)}}function Ar(e){return e.role===`viewer`&&e.mode===`only`&&e.pickedIds.length===0?`no-allowed-device`:null}function jr(e){return Ar(e)===null?e.role===`admin`?{isAdmin:!0,scopes:[]}:{isAdmin:!1,scopes:[e.viewer]}:null}function Mr(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 Nr(e,t,n){let r=Pr(t);return e===`except`?{type:`viewer`,allow:`*`,block:r,features:[...n]}:{type:`viewer`,allow:r,block:[],features:[...n]}}function Pr(e){return[...new Set(e)]}c();var Fr=`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`;function Ir(e,t){return e?`failed`:t===void 0?`pending`:`answered`}function Lr(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 Rr({user:t,isSelf:r,onClose:a,onSubmit:s,submitting:c,error:l}){let{t:u}=Y(),[f,p]=o(n(()=>Tr(t),[t])),m=Ce({projection:`slim`}),h=m.data,g=Ir(m.isError,h),_=n(()=>Lr(h??[]),[h]),v=n(()=>({state:g,devices:g===`answered`?(h??[]).map(e=>({id:e.id,name:e.name})):void 0}),[g,h]),y=Ar(f),b=jr(f),x=y===`no-allowed-device`?u(`users.userAccessModal.pickAllowedDevice`):null,S=e=>{p(Er(f,e))},C=[{value:`except`,label:u(`users.userAccessModal.modeExcept`)},{value:`only`,label:u(`users.userAccessModal.modeOnly`)}];return i(ze,{open:!0,onOpenChange:e=>!e&&a(),children:e(Je,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-2xl`,children:[i(Ie,{children:i(it,{children:u(`users.userAccessModal.title`,{name:t.username})})}),e(Xe,{className:`space-y-4`,children:[f.unconfigured&&f.role===`viewer`&&i(V,{variant:`warning`,title:u(`users.userAccessModal.noAccessYet`),message:u(`users.userAccessModal.noAccessYetDetail`,{name:t.username})}),e(`section`,{className:`space-y-2`,children:[i(`h3`,{className:Fr,children:u(`users.userAccessModal.role`)}),e(`div`,{role:`radiogroup`,"aria-label":u(`users.userAccessModal.role`),className:`grid gap-1.5 sm:grid-cols-2`,children:[i(zr,{name:`admin`,checked:f.role===`admin`,label:u(`users.userAccessModal.admin`),description:u(`users.userAccessModal.adminDescription`),onPick:()=>S(`admin`)}),i(zr,{name:`viewer`,checked:f.role===`viewer`,disabled:r,label:u(`users.userAccessModal.viewer`),description:u(r?`users.userAccessModal.cannotDemoteSelf`:`users.userAccessModal.viewerDescription`),onPick:()=>S(`viewer`)})]})]}),f.role===`viewer`&&e(d,{children:[e(`section`,{className:`space-y-3`,children:[i(`h3`,{className:Fr,children:u(`users.userAccessModal.devices`)}),i(et,{label:u(`users.userAccessModal.whichDevices`),value:f.mode,options:C,onChange:e=>p(Dr(f,e))}),i(Se,{devices:_,listState:g,fleet:v,value:[...f.pickedIds],onChange:e=>p(Or(f,e)),emptyMeansAll:f.mode===`except`,noun:`device`,testId:`viewer-device-picker`}),i(wr,{scopes:b?.scopes??[],invalidReason:x})]}),e(`section`,{className:`space-y-2`,children:[i(`h3`,{className:Fr,children:u(`users.userAccessModal.features`)}),i(`div`,{className:`space-y-1`,children:te.map(t=>e(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-md p-1.5 hover:bg-surface-hover`,children:[i(Oe,{className:`mt-0.5`,checked:f.viewer.features.includes(t.id),onChange:e=>p(kr(f,t.id,e.target.checked))}),e(`span`,{className:`min-w-0`,children:[i(`span`,{className:`block text-[12px] font-medium text-foreground`,children:u(`users.viewerFeatures.${t.id}.label`,t.label)}),i(`span`,{className:`block text-[10px] text-foreground-subtle`,children:u(`users.viewerFeatures.${t.id}.description`,t.description)})]})]},t.id))})]})]}),l!==null&&i(V,{message:l})]}),e(Ve,{children:[i(K,{variant:`outline`,size:`sm`,onClick:a,children:u(`common.cancel`,`Cancel`)}),i(K,{size:`sm`,onClick:()=>b!==null&&s(b),disabled:c||b===null,children:c?i(A,{className:`h-3 w-3 animate-spin`}):u(`users.userAccessModal.saveAccess`)})]})]})})}function zr({name:t,checked:n,disabled:r=!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`} ${r?`cursor-not-allowed opacity-60`:`cursor-pointer`}`,children:[i(`input`,{type:`radio`,name:`user-role`,value:t,checked:n,disabled:r,onChange:s,className:`mt-0.5`}),e(`span`,{className:`min-w-0`,children:[i(`span`,{className:`block text-[12px] font-medium text-foreground`,children:a}),i(`span`,{className:`block text-[10px] text-foreground-subtle`,children:o})]})]})}c();var Br=8;function Vr(){return{username:``,password:``,isAdmin:!1}}function Hr(e){return{id:e.id,username:e.username,password:``,isAdmin:e.isAdmin}}function Ur(e){return e instanceof Error?e.message:J.t(`admin.system.users.genericError`)}function Wr(){let{t}=Y(),n=l(),{user:r}=ct(),{state:s,openNew:c,openEdit:u,close:p}=Ze(),[h,_]=o(null),[y,x]=o(null),[C,w]=o(!1),{data:T,isLoading:E,isError:D,error:O,refetch:k}=ye(),ee=W(),M=de(),N=()=>n.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),P=ve(),F=Ee({onSuccess:N}),I=fe({onSuccess:N}),L=Ne({onSuccess:N}),te=Fe(),[R,z]=o(null),[ne,re]=o(!1),[ae,oe]=o(null),[se,ce]=o(null),[ue,B]=o(null),[pe,ge]=o(null),_e=T??[],H=s.mode===`edit`?_e.find(e=>e.id===s.id)??null:null,U=()=>{_(null),x(null),w(!1),P.reset(),I.reset(),p()};a(()=>{if(s.mode===`closed`){_(null),x(null),w(!1);return}if(s.mode===`new`){_(e=>e!==null&&e.id===void 0?e:Vr());return}if(H===null){E||p();return}_(e=>e?.id===H.id?e:Hr(H))},[s,H,E,p]);let be=s.mode===`new`&&h!==null&&h.id===void 0||s.mode===`edit`&&h!==null&&H!==null;async function xe(e){await ee({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`})&&(F.mutate({id:e.id}),s.mode===`edit`&&s.id===e.id&&U())}async function Se(e){let n=await M({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<Br?J.t(`admin.system.users.passwordTooShort`,{min:Br}):null});n===null||n.length===0||await ee({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`)})&&L.mutate({id:e.id,newPassword:n})}function G(e){oe(null),z(e)}async function Ce(e,t){re(!0),oe(null);try{t.isAdmin!==e.isAdmin&&await I.mutateAsync({id:e.id,isAdmin:t.isAdmin}),await te.mutateAsync({userId:e.id,scopes:[...t.scopes]}),z(null)}catch(e){oe(Ur(e))}finally{re(!1),N()}}async function Te(){if(h!==null){x(null);try{if(h.id===void 0){let e=h.username.trim();if(e===``||h.password.length<Br)return;await P.mutateAsync({username:e,password:h.password,isAdmin:h.isAdmin})}else await I.mutateAsync({id:h.id,isAdmin:h.isAdmin});N(),U()}catch(e){x(Ur(e))}}}function De(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}let Oe=P.isPending||I.isPending,ke=h!==null&&h.id===void 0&&h.username.trim()!==``&&h.password.length>=Br,Ae=h!==null&&h.id!==void 0,je=Oe||(h?.id===void 0?!ke:!Ae),Me=e=>F.isPending&&F.variables?.id===e.id||I.isPending&&I.variables?.id===e.id||L.isPending&&L.variables?.id===e.id,Pe=[{key:`username`,header:t(`admin.system.users.username`,`Username`),sortValue:e=>e.username,render:e=>i(`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=>Gr(e),render:n=>i(`span`,{onClick:e=>e.stopPropagation(),children:e(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>G(n),disabled:Me(n),title:t(`admin.system.users.configureAccess`,`Configure access`),"data-testid":`user-access-${n.id}`,children:[i(b,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),i(Kr,{user:n})]})})},{key:`createdAt`,header:t(`admin.system.users.created`,`Created`),nowrap:!0,sortValue:e=>e.createdAt,render:e=>i(`span`,{className:`text-foreground-subtle`,children:De(e.createdAt)})},{key:`actions`,header:t(`admin.system.users.actions`,`Actions`),align:`right`,nowrap:!0,notSortableReason:`Row actions`,render:n=>{let a=Me(n),o=n.id!==r?.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:()=>u(n.id),disabled:a,title:t(`admin.system.users.editUser`,`Edit user`),children:[i(g,{className:`h-3 w-3`}),t(`common.edit`,`Edit`)]}),o&&e(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>ce(n),disabled:a,title:t(`admin.system.users.removeTwoFactorAuthentication`,`Remove two-factor authentication`),children:[i(S,{className:`h-3 w-3`}),t(`admin.system.users.remove2fa`,`Remove 2FA`)]}),e(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>B(n),disabled:a,title:t(`admin.system.users.linkedSignInAccounts`,`Linked sign-in accounts`),children:[i(j,{className:`h-3 w-3`}),t(`admin.system.users.signInLinks`,`Sign-in links`)]}),e(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>ge(n),disabled:a,title:t(`admin.system.users.activeSessions`,`Active sessions`),children:[i(le,{className:`h-3 w-3`}),t(`admin.system.users.sessions`,`Sessions`)]}),e(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void Se(n),disabled:a,title:t(`admin.system.users.resetPassword`,`Reset password`),children:[i(ie,{className:`h-3 w-3`}),t(`admin.system.users.resetPassword`,`Reset password`)]}),e(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void xe(n),disabled:a,title:t(`admin.system.users.deleteUser`,`Delete user`),className:`text-danger hover:bg-danger/10`,children:[a?i(A,{className:`h-3 w-3 animate-spin`}):i(v,{className:`h-3 w-3`}),t(`common.delete`,`Delete`)]})]})}}];return e(bt,{embedded:!0,icon:m,title:t(`admin.system.users.users`,`Users`),subtitle:t(`admin.system.users.hubAccountsAdminFlagAccess`,`Hub accounts, admin flag, access scopes, sessions and sign-in links.`),actions:e(K,{size:`sm`,type:`button`,onClick:()=>{x(null),c()},children:[i(f,{className:`h-3.5 w-3.5`}),t(`admin.system.users.createUser`,`Create User`)]}),children:[D&&i(V,{title:t(`admin.system.users.couldNotLoadUsers`,`Could not load users`),message:Ur(O),onRetry:()=>void k()}),E&&e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(A,{className:`h-3.5 w-3.5 animate-spin`}),t(`common.loading`,`Loading…`)]}),!E&&!D&&_e.length===0&&i(he,{icon:m,title:t(`admin.system.users.noUsersYet`,`No users yet`),description:t(`admin.system.users.createAUserToGrant`,`Create a user to grant hub access.`)}),!E&&!D&&_e.length>0&&i(me,{columns:Pe,rows:_e,rowKey:e=>e.id,minWidthPx:560,maxBodyHeight:`max-h-[60vh]`,onRowClick:e=>u(e.id)}),i(Ue,{open:be,onClose:U,title:h?.id===void 0?t(`admin.system.users.createUser`,`Create User`):t(`admin.system.users.edit`,`Edit {{value1}}`,{value1:h.username||`user`}),icon:m,error:y,testId:`user-form-dialog`,footer:i(K,{size:`sm`,type:`button`,disabled:je,onClick:()=>void Te(),children:Oe?e(d,{children:[i(A,{className:`h-3.5 w-3.5 animate-spin`}),t(`admin.system.users.saving`,`Saving…`)]}):h?.id===void 0?t(`admin.system.users.create`,`Create`):t(`common.save`,`Save`)}),children:h!==null&&e(`div`,{className:`space-y-3`,children:[i(we,{label:t(`admin.system.users.username`,`Username`),required:h.id===void 0,children:i(qe,{value:h.username,onChange:e=>_({...h,username:e.target.value}),placeholder:`john`,autoFocus:h.id===void 0,disabled:h.id!==void 0,"data-testid":`user-form-username`})}),h.id===void 0&&i(we,{label:t(`admin.system.users.password`,`Password`),required:!0,description:t(`admin.system.users.atLeastCharacters`,`At least {{value1}} characters.`,{value1:String(Br)}),children:i(Le,{value:h.password,onValueChange:e=>_({...h,password:e}),shown:C,onToggleShown:()=>w(e=>!e),placeholder:`••••••••`,"data-testid":`user-form-password`})}),i(we,{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:[i(`input`,{type:`checkbox`,checked:h.isAdmin,onChange:e=>_({...h,isAdmin:e.target.checked}),className:`rounded border-border focus:ring-primary`,"data-testid":`user-form-admin`}),i(`span`,{children:t(`admin.system.users.admin`,`Admin`)})]})}),h.id!==void 0&&i(`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.`)})]})}),se&&i(Sr,{userId:se.id,username:se.username,onClose:()=>ce(null)}),ue&&i(xr,{userId:ue.id,username:ue.username,onClose:()=>B(null)}),pe&&i(Cr,{userId:pe.id,username:pe.username,onClose:()=>ge(null)}),R&&i(Rr,{user:R,isSelf:R.id===r?.id,onClose:()=>z(null),onSubmit:e=>void Ce(R,e),submitting:ne,error:ae})]})}function Gr(e){let t=Tr(e);return t.role===`admin`?0:t.unconfigured?2:1}function Kr({user:t}){let{t:n}=Y(),r=Tr(t);if(r.role===`admin`)return i(`span`,{className:`font-medium text-foreground`,children:n(`users.accessSummary.admin`)});if(r.unconfigured)return i(`span`,{className:`font-medium text-warning`,children:n(`admin.system.users.noAccess`,`No access`)});let{allow:a,block:o,features:s}=r.viewer,c=a===`*`?n(`users.accessSummary.allDevices`):n(`users.accessSummary.devices`,{count:a.length});return e(`span`,{className:`text-foreground-subtle`,children:[i(`span`,{className:`font-medium text-foreground`,children:n(`users.accessSummary.viewer`)}),` ·`,` `,c,o.length>0&&e(d,{children:[` · `,n(`users.accessSummary.blocked`,{count:o.length})]}),s.length>0&&e(d,{children:[` · `,n(`users.accessSummary.features`,{count:s.length})]})]})}c();var qr={"api-keys":$.tokens,"linked-sessions":$.linkedApps},Jr=`certificates`;function Yr(t){return e(K,{size:`sm`,type:`button`,"data-testid":`certificates-pair-device`,onClick:t,children:[i(S,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),J.t(`systemPage.identity.pairADevice`,`Pair a device`)]})}function Xr(){let{t:e}=Y(),[t]=pt(),n=bn(),[r,a]=o(!1),s=qr[t.get(`tab`)??``];if(s!==void 0)return i(ft,{to:ht(`access`,{integration:s}),replace:!0});let c=lt(`/system/identity`,{t:e,isAdmin:!0})??{icon:E,title:e(`system.identity`,`Identity & Access`)},l=t.get(`tab`)??`users`,u=t.get(`integration`),d=l===ut.access.tab?yn(u,n.requestCreate):l===`certificates`?Yr(()=>a(!0)):void 0;return i(yt,{icon:c.icon,title:c.title,defaultSection:`users`,sectionsLabel:`${c.title} sections`,actions:d,sections:[{id:`users`,label:e(`systemPage.identity.users`,`Users`),content:i(Wr,{})},{id:ut.access.tab,label:e(`systemPage.identity.tokensSessions`,`Tokens & sessions`),ownedParams:mt.concat([Mt.token,Mt.scoped,Mt.admin]),content:i(vn,{createRequested:n.createRequested,onCreateConsumed:n.clearCreate})},{id:Jr,label:e(`systemPage.identity.certificates`,`Certificates`),content:i(br,{pairOpen:r,onPairClose:()=>a(!1)})},{id:ut.authentication.tab,label:e(`systemPage.identity.authentication`,`Authentication`),content:i(Nn,{}),ownedParams:mt}]})}export{Xr as IdentityPage};
@@ -1 +0,0 @@
1
- import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,et as s,o as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{An as l,Br as u,Ci as d,Lt as f,Pt as p,Si as m,Zi as h,bi as g,ca as _,ci as v,dn as y,dt as b,ht as x,mi as S,mn as ee,ot as C,sr as w,wn as te,xn as T,yn as E,zr as D}from"./player-overlays-Cs6l33cj.js";import{Yi as ne}from"./client-Ct1F5MoE.js";import{t as O}from"./search-x-9dPd-b95.js";import{Ao as k,At as re,Cs as A,En as ie,Er as j,Gn as M,Ii as N,Mo as P,Nt as ae,Sa as F,So as I,Un as L,Yo as R,_i as z,_o as B,_r as V,_s as H,ba as U,bd as W,bs as oe,co as G,ei as K,eo as se,fr as q,gn as ce,gr as J,gs as le,io as ue,jt as de,ld as Y,lo as fe,mo as pe,mr as me,no as he,oo as ge,or as _e,po as ve,pr as ye,ro as X,tn as be,to as xe,va as Se,vi as Ce,vr as we,vs as Te,wd as Ee,xs as De,ys as Oe}from"./src-DFzrn-CX.js";import{t as Z}from"./useTranslation-BJr-n0es.js";import{n as ke}from"./addon-icons-context-Bzdujcmt.js";import{P as Ae,hr as je,lr as Me,mr as Ne,pr as Pe}from"./index-Dow2-3ZC.js";import{t as Fe}from"./device-integration-icon-Csh9ZCwn.js";import{i as Ie,r as Le,t as Re}from"./ScanNetworkModal-PQbiE2mC.js";import{t as ze}from"./NodeAddonsSettingsPanel-DUUGVGQU.js";s();function Be(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Be(n.fields));return t}function Ve(e,t,i){let[a,s]=o(`idle`),[c,l]=o({}),u=n(()=>{let t=[];for(let n of e.sections)t.push(...Be(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}}s();function Q(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(...Q(n.fields));return t}function He(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Ue(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Ue(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function $(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function We({open:t,integrationId:s,addonId:l,onClose:u}){let{t:d}=Z(),f=c(),[h,g]=o({}),[_,v]=o(!1),[y,S]=o(null),[C,te]=o($),T=k({addonId:l},{enabled:t}),E=T.data?.deviceType??null,D=B({addonId:l,type:E??ne.Camera},{enabled:t&&T.isSuccess&&E!==null}),O=D.data??null;a(()=>{t&&(g(O?Ue(O.sections.flatMap(e=>e.fields)):{}),te($()),v(!1),S(null))},[t,s,O]);let re=n(()=>({...h,_probeRequestId:C}),[h,C]),A=G({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ie=R(),j=r(async(e,t)=>{v(!0);let n=await ie.mutateAsync({addonId:l,type:E??ne.Camera,key:e,value:t,formValues:re});return n.status===`ok`&&n.suggestedValues&&g(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))He(e[i])&&!He(a)&&(r[i]=a,t=!0);return t?r:e}),n},[ie,l,re,E]),{testAllStatus:M,hasProbeFields:N,probeResults:P,handleTestAll:ae,clearProbeResult:F}=Ve(O??{sections:[]},h,j);async function I(e){S(null);try{await A.mutateAsync({addonId:l,type:E??ne.Camera,config:h,integrationId:s}),e?g(O?Ue(O.sections.flatMap(e=>e.fields)):{}):u()}catch(e){S(e instanceof Error?e.message:String(e))}}if(!t)return null;let L=Q((O?.sections??[]).flatMap(e=>e.fields)).filter(e=>He(h[e])),z=L.length===0,V=T.isLoading||E!==null&&D.isLoading,H=T.isError||T.isSuccess&&E===null||D.isError||D.isSuccess&&O===null;return e(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[i(`div`,{className:`absolute inset-0 bg-black/60`,onClick:u}),e(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[calc(90dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl`,children:[e(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[i(`h2`,{className:`text-sm font-semibold text-foreground`,children:d(`integrations.addDevice`)}),i(`button`,{onClick:u,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:i(b,{className:`h-4 w-4`})})]}),i(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:V?i(`div`,{className:`flex items-center justify-center py-8`,children:i(w,{className:`h-5 w-5 animate-spin text-primary`})}):H?e(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[i(p,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),e(`div`,{className:`space-y-1`,children:[i(`p`,{className:`text-xs font-medium text-destructive`,children:d(`integrations.addDeviceDialog.providerUnavailable`,`Provider unavailable`)}),i(`p`,{className:`text-xs text-foreground-subtle`,children:i(Me,{i18nKey:`integrations.addDeviceDialog.notReady`,values:{addonId:l},components:{mono:i(`span`,{className:`font-mono`})}})})]})]}):i(Ae,{schema:O,values:h,onChange:g,onTestField:j,probeResults:P,onClearProbe:F})}),!H&&!V&&e(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[e(`button`,{type:`button`,onClick:()=>v(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[e(`span`,{className:`flex items-center gap-2`,children:[i(ee,{className:`h-3.5 w-3.5`}),d(`integrations.addDeviceDialog.testLogs`,`Test logs`),i(`span`,{className:`font-mono text-[9px] opacity-60`,children:C.slice(0,14)})]}),i(m,{className:`h-3.5 w-3.5 transition-transform ${_?`rotate-180`:``}`})]}),_&&i(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:i(be,{addonId:l,requestId:C,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!H&&!V&&(y||L.length>0)&&i(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(p,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),i(`p`,{className:`text-[11px] text-destructive`,children:y||d(`integrations.addDeviceDialog.required`,`Required: {{value1}}`,{value1:L.join(`, `)})})]})}),e(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[e(`div`,{className:`flex items-center gap-2`,children:[i(`button`,{onClick:u,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:d(`integrations.cancel`)}),!H&&N&&e(`button`,{type:`button`,onClick:ae,disabled:M===`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:[M===`testing`?i(w,{className:`h-3.5 w-3.5 animate-spin`}):i(x,{className:`h-3.5 w-3.5`}),d(`integrations.addDeviceDialog.testAll`,`Test All`)]})]}),e(`div`,{className:`flex items-center gap-2`,children:[i(`button`,{onClick:()=>I(!0),disabled:H||!z||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(`button`,{onClick:()=>I(!1),disabled:H||!z||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`)})]})]})]})]})}s();var Ge=[`discovering`,`pase`,`commissioning`,`done`];function Ke(e){return!(typeof e!=`object`||!e||!(`phase`in e)||typeof e.phase!=`string`)}function qe(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 Je({onClose:t,onCommissioned:n}){let{t:r}=Z(),s=U({kind:`matter`}),c=s.data?.[0]?.id??null,l=F(),[u,d]=o(``),[f,p]=o({phase:`idle`,failure:null,message:null}),m=f.phase===`discovering`||f.phase===`pase`||f.phase===`commissioning`,h=Se({brokerId:c??``,key:`commission`},{enabled:c!==null&&m,refetchInterval:m?400:!1});a(()=>{m&&Ke(h.data)&&h.data.phase!==`idle`&&p({phase:h.data.phase,failure:typeof h.data.failure==`string`?h.data.failure:null,message:typeof h.data.message==`string`?h.data.message:null})},[m,h.data]);let g=()=>{c!==null&&(p({phase:`discovering`,failure:null,message:null}),l.mutate({brokerId:c,target:{action:`commissionNode`},payload:{pairingCode:u.trim()}},{onSuccess:()=>p({phase:`done`,failure:null,message:null}),onError:e=>{let t=e instanceof Error?e.message:`Commissioning failed.`;p({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})}}))},_=f.phase===`failed`?qe(f.failure,f.message):null,v=_===null?null:r(_.key,{defaultValue:_.defaultValue}),y=(s.isSuccess===!0||s.data!==void 0)&&c===null;return i(q,{open:!0,onOpenChange:e=>!e&&t(),children:e(me,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(V,{children:i(we,{children:r(`integrations.addMatter.title`,{defaultValue:`Add Matter device`})})}),e(ye,{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.`})}),y?i(j,{message:r(`integrations.addMatter.noBroker`,{defaultValue:`Create the Matter fabric from this integration’s settings first.`})}):e(`div`,{className:`space-y-1.5`,children:[i(M,{htmlFor:`matter-pairing-code`,children:r(`integrations.addMatter.code`,{defaultValue:`Pairing code`})}),i(Y,{id:`matter-pairing-code`,value:u,autoComplete:`off`,spellCheck:!1,placeholder:`34970112332`,disabled:m||f.phase===`done`,onChange:e=>d(e.target.value)})]}),f.phase!==`idle`&&i(`ol`,{className:`space-y-1`,"aria-label":r(`integrations.addMatter.progress`,{defaultValue:`Commissioning progress`}),children:Ge.map(t=>{let n=f.phase===t;return e(`li`,{className:`text-xs ${n?`text-foreground font-medium`:`text-foreground-subtle`}`,children:[n&&m?i(w,{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)})}),v!==null&&i(j,{message:v})]}),e(J,{children:[i(K,{variant:`ghost`,size:`sm`,onClick:t,children:r(`common.close`,{defaultValue:`Close`})}),f.phase===`done`?i(K,{size:`sm`,onClick:n,children:r(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}):i(K,{size:`sm`,disabled:m||y||u.trim().length===0,onClick:g,children:m?r(`integrations.addMatter.working`,{defaultValue:`Adding…`}):r(`integrations.addMatter.submit`,{defaultValue:`Add device`})})]})]})})}var Ye=1500;function Xe({addonId:t,integrationId:n,jobId:r,onFinished:a}){let{t:o}=Z(),s=se(),c=(X({addonId:t,integrationId:n},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?Ye:!1}).data??[]).find(e=>e.jobId===r);if(!c)return null;let l=c.state===`running`,u=c.processed,d=c.total>0?Math.round(u/c.total*100):0;!l&&c.finishedAt!==null&&a();let f=[`${u}/${c.total} ${o(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];c.adopted>0&&f.push(`${c.adopted} ${o(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),c.alreadyAdopted>0&&f.push(`${c.alreadyAdopted} ${o(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),c.failed>0&&f.push(`${c.failed} ${o(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let m=f.join(` · `);return e(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[e(`div`,{className:`flex items-center gap-2`,children:[l?i(w,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):c.failed>0?i(p,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):c.state===`cancelled`?i(v,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):i(S,{className:`h-3.5 w-3.5 text-primary shrink-0`}),i(`p`,{className:`text-[11px] text-foreground`,children:m}),l&&i(`button`,{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 Ze(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(` `)}s();var Qe=`devices`;function $e(e){return{id:Qe,label:e(`integrations.adoptDevicesModal.defaultFilter`),isDefault:!0}}var et=2e4,tt=100;function nt({addonId:n,integrationId:s,onClose:l}){let u=_(),{t:f}=Z(),m=c(),[h,g]=o(new Set),[v,y]=o(new Set),[x,S]=o(new Map),[ee,C]=o(null),{data:te}=Te(),T=(te??[]).find(e=>e.addonId===n)?.supportsLocationImport??!1,[D,ne]=o(!0),O=xe({addonId:n,integrationId:s}).data?.filters,k=O&&O.length>0?O:[$e(f)],[A,ie]=o(k.find(e=>e.isDefault)?.id??(k.some(e=>e.id===Qe)?Qe:k[0].id)),j=A!==Qe,M=ue(),N=he({addonId:n,integrationId:s,page:1,pageSize:et,filter:A}),P=N.refetch,ae=M.mutate,F=r(()=>{ae({addonId:n,integrationId:s},{onSettled:()=>{P()}})},[ae,n,s,P]),I=t(null);a(()=>{let e=`${n}::${s}`;I.current===e||N.isLoading||(I.current=e,(N.data?.candidates.length??0)===0&&F())},[n,s,N.isLoading,N.data,F]);let L=M.isPending,R=M.isError?M.error instanceof Error?M.error.message:String(M.error):null,z=typeof M.data?.lastError==`string`&&M.data.lastError.length>0?M.data.lastError:null,B=N.data?.candidates??[],V=N.isError?N.error instanceof Error?N.error.message:String(N.error):null,H=ge(),[U,oe]=o(null),G=r(e=>{e.alreadyAdopted||g(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),K=r(e=>{y(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),se=r((e,t)=>{S(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),q=r(e=>{let t={};for(let n of e){let e=x.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[x]),ce=r(async()=>{C(null);let e=[...h];if(e.length!==0)try{let t=q(e),{jobId:r}=await H.mutateAsync({addonId:n,integrationId:s,filter:A,childNativeIds:e,...t?{perCandidate:t}:{},...T?{importLocations:D}:{}});oe(r),g(new Set),S(new Map)}catch(e){C(e instanceof Error?e.message:String(e))}},[h,q,H,n,s,A,T,D]),J=t(null),le=r(()=>{U===null||J.current===U||(J.current=U,P(),m.invalidateQueries({queryKey:[[`integrations`]]}),m.invalidateQueries({queryKey:[[`deviceManager`]]}))},[U,P,m]),de=r(e=>{ie(e),g(new Set),y(new Set),S(new Map),C(null)},[]),Y=h.size,fe=U!==null&&Y===0&&!H.isPending;return e(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[i(`div`,{className:`absolute inset-0 bg-black/60`,onClick:l}),e(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] rounded-xl border border-border bg-background shadow-2xl`,children:[e(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[e(`div`,{className:`min-w-0`,children:[i(`h2`,{className:`text-sm font-semibold text-foreground`,children:f(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),i(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:f(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),e(`div`,{className:`flex items-center gap-3 shrink-0`,children:[T&&e(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[i(`input`,{type:`checkbox`,checked:D,onChange:e=>ne(e.target.checked),className:`accent-primary`}),f(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),i(`button`,{onClick:l,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":f(`common.close`,`Close`),children:i(b,{className:`h-4 w-4`})})]})]}),e(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(R??V??z)&&B.length===0&&i(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(p,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),e(`div`,{className:`min-w-0`,children:[i(`p`,{className:`text-xs font-medium text-destructive`,children:f(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),i(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:R??V??z})]})]})}),k.length>1&&i(rt,{filters:k,activeFilter:A,onSelect:de}),i(`div`,{className:`flex-1 min-h-0`,children:i(re,{mode:`generic`,items:B,pageSize:tt,getKey:e=>e.childNativeId,getSearchText:Ze,getFilterType:e=>e.type,filterOptions:W(u),filterLabel:f(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:N.isLoading||L&&B.length===0,searchPlaceholder:f(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(R??V??z)&&B.length===0?``:f(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:e(`button`,{type:`button`,onClick:F,disabled:L,title:f(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[i(E,{className:`h-3.5 w-3.5 ${L?`animate-spin`:``}`}),f(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:f(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>i(it,{candidate:e,expandable:!j,expanded:v.has(e.childNativeId),onToggleExpand:()=>K(e.childNativeId),adoptedLabel:f(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:f(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:t=>{let n=Ee(t.type,u),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-[15%] text-right`,cellClassName:`text-right`,cell:e=>i(`div`,{className:`flex items-center justify-end`,children:i(`button`,{onClick:()=>G(e),disabled:e.alreadyAdopted,"aria-label":h.has(e.childNativeId)?f(`integrations.adoptDevicesModal.deselect`,`Deselect`):f(`integrations.adoptDevicesModal.select`,`Select`),className:`inline-flex h-5 w-5 items-center justify-center rounded border ${h.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:h.has(e.childNativeId)&&i(d,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!j&&v.has(e.childNativeId),renderExpanded:j?void 0:e=>i(at,{candidate:e,hiddenChildIds:x.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>se(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:h.has(e.childNativeId)?`bg-primary/5`:``})})]}),ee&&i(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(p,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),i(`p`,{className:`text-[11px] text-destructive`,children:ee})]})}),U!==null&&i(Xe,{addonId:n,integrationId:s,jobId:U,onFinished:le}),e(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[i(`div`,{}),e(`div`,{className:`flex items-center gap-2`,children:[i(`button`,{onClick:l,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:f(`integrations.cancel`,{defaultValue:`Cancel`})}),e(`button`,{onClick:fe?l:ce,disabled:!fe&&(Y===0||H.isPending),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,children:[H.isPending&&i(w,{className:`h-3.5 w-3.5 animate-spin`}),fe?f(`integrations.close`,{defaultValue:`Close`}):f(`integrations.addSelected`,{defaultValue:`Add selected`}),!fe&&Y>0?` (${Y})`:``]})]})]})]})]})}function rt({filters:e,activeFilter:t,onSelect:n}){let{t:r}=Z();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(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function it({candidate:t,expandable:n,expanded:r,onToggleExpand:a,adoptedLabel:o}){let{t:s}=Z(),c=(t.children??[]).length;return e(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[n&&c>0?e(`button`,{type:`button`,onClick:a,"aria-label":r?s(`integrations.adoptDevicesModal.collapse`,`Collapse`):s(`integrations.adoptDevicesModal.expand`,`Expand`),"aria-expanded":r,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(r?m:g,{className:`h-3.5 w-3.5`}),c]}):i(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),i(`span`,{className:`truncate text-xs font-medium text-foreground`,children:t.name}),t.alreadyAdopted&&i(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:o})]})}function at({candidate:t,hiddenChildIds:n,onToggleChildHidden:r}){let{t:a}=Z(),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(`button`,{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?u:D,{className:`h-3 w-3`})})]},t.childNativeId)})})}s();function ot(e){let t=[];for(let n of e){if(n.type===`group`){t.push(...ot(n.fields));continue}`key`in n&&typeof n.key==`string`&&t.push(n.key)}return t}function st(e,t){if(!e)return{};let n=new Set(e.sections.flatMap(e=>ot(e.fields))),r={};for(let e of n)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}function ct(e){return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{if(`value`in e){let{value:t,...n}=e;return n}return e})}))}}function lt({integrationId:t,addonId:r,name:a,kind:o,mode:s,brokerKind:l,canTest:u=!1,trpc:d,onClose:f}){let{t:p}=Z(),m=c(),{data:h,isLoading:g}=Oe({id:t},{enabled:s===`account`||s===`broker`}),_=n(()=>{let e=h?.brokerId;return typeof e==`string`?e:null},[h]),{data:v,isLoading:y}=z({addonId:r,nodeId:`hub`},{enabled:s===`account`}),b=n(()=>v?ct(v):null,[v]),x=De(),S=(e,n)=>{x.mutate({id:t,settings:e,...n?{secretKeys:[...n]}:{}},{onSuccess:()=>{m.invalidateQueries(),f()}})};return i(q,{open:!0,onOpenChange:e=>!e&&f(),children:e(me,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(V,{children:e(we,{children:[p(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,a]})}),i(ye,{children:s===`broker`?l?e(`div`,{className:`space-y-3`,children:[i(`p`,{className:`text-[11px] text-foreground-subtle`,children:p(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),_&&e(`p`,{className:`text-[11px] text-foreground`,children:[p(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,i(`span`,{className:`font-mono text-foreground-subtle`,children:_})]}),x.isPending?e(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[i(w,{className:`h-3 w-3 animate-spin`}),p(`integrations.saving`,{defaultValue:`Saving…`})]}):i(Ie,{kind:l,onResolved:e=>{S({brokerId:e})},onBack:f}),x.isError&&i(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):i(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):s===`account`?g||y?e(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[i(w,{className:`h-3 w-3 animate-spin`}),p(`integrations.loading`,{defaultValue:`Loading…`})]}):i(Le,{addonId:r,configSchema:b,canTest:u,initialName:a,initialConfig:st(b,h??{}),submitLabel:p(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e,secretKeys:t})=>S(e,t),onBack:f}):i(_e,{trpc:d,addonId:r,nodeId:`hub`,title:a})})]})})}function ut(e){return e==null?!1:e.sections.some(e=>e.fields.length>0)}s();function dt(){let{t}=Z(),{integrationId:s}=Ne(),u=c(),d=Pe(),[p,m]=je(),g=C(),[_,v]=o(!1),[b,x]=o(!1),[S,E]=o(!1),D=r(e=>{E(!1),d(`/integrations`,{state:{integrationSeed:e}})},[d]),[ne,k]=o(!1),[j,M]=o(!1),{data:F,isLoading:R}=H({id:s??``},{enabled:!!s}),{data:B}=z({addonId:F?.addonId??``,nodeId:`hub`},{enabled:!!F?.addonId}),{data:U,isSuccess:W}=Te(),G=n(()=>{let e=F?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[U,F?.addonId,W]),{data:K}=ve({}),se=n(()=>(K?.providers??[]).some(e=>e.addonId===F?.addonId),[K,F?.addonId]),J=G!==null,ue=F?.info?.fixed===!0,Y=n(()=>{let e=F?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.brokerKind??null},[U,F?.addonId,W]),he=Y===`matter`,ge=J?he?t(`integrations.addMatter.title`,{defaultValue:`Add Matter device`}):G===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),_e=n(()=>{let e=F?.addonId;return!e||!W?!1:(U??[]).find(t=>t.addonId===e)?.canTest===!0},[U,F?.addonId,W]),X=n(()=>{let e=F?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.mode??null},[U,F?.addonId,W]);a(()=>{p.get(`add`)===`1`&&J&&(x(!1),v(!0),m(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[p,J,m]);let xe=B!=null&&Array.isArray(B.sections)&&B.sections.some(e=>e.fields.length>0),{data:Se}=Ce({addonId:F?.addonId??``,nodeId:`hub`},{enabled:!!F?.addonId&&X!==`account`}),Ee=X!==null&&X!==`account`&&ut(Se),De=n(()=>F?.addonId?[F.addonId]:[],[F?.addonId]),{data:Oe}=I({projection:`slim`},{refetchInterval:3e4}),ke=[[`integrations`,`get`],{input:{id:s??``},type:`query`}],Ae=A({onMutate:async e=>{await u.cancelQueries({queryKey:ke});let t=u.getQueryData(ke);return t!=null&&u.setQueryData(ke,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&u.setQueryData(ke,r.previous)},onSettled:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Me=le({onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]}),d(`/integrations`)}}),Ie=N({onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Le=P({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Be=fe({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ve=pe({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=n(()=>Oe??[],[Oe]),He=n(()=>{let e=new Map;for(let t of Q)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[Q]),Ue=r(e=>He.get(e)??null,[He]),{data:$}=oe(void 0),Ge=n(()=>de($),[$]),Ke=r(e=>d(`/devices/${String(e)}`),[d]),qe=n(()=>{let e=F?.id;return e?Q.filter(t=>{let n=Ge(t);return n.kind===`resolved`&&n.integration.id===e}):[]},[Q,F?.id,Ge]),Ye=n(()=>$===void 0?null:ae(qe).length,[$,qe])??`…`;return R?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`})]}):F?e(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[i(ie,{items:[{label:t(`integrationDetail.integrations`,`Integrations`),onClick:()=>d(`/integrations`)},{label:F.name}]}),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(ft,{addonId:F.addonId}),e(`div`,{className:`min-w-0`,children:[i(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:F.name}),e(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[F.addonId,` · `,Ye,` `,t(`integrations.devices`)]})]})]}),e(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[se&&e(`button`,{onClick:()=>E(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:t(`integrationDetail.scanTheNetworkForDevices`,`Scan the network for devices (incl. a different subnet)`),children:[i(te,{className:`h-3.5 w-3.5`}),t(`integrationDetail.scanNetwork`,`Scan network`)]}),!ue&&e(`button`,{onClick:()=>{x(!1),v(!0)},disabled:!J,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:ge,children:[i(l,{className:`h-3.5 w-3.5`}),ge]}),e(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Ae.isPending?`opacity-60`:``} ${F.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[i(L,{checked:F.enabled,onCheckedChange:e=>Ae.mutate({id:s,enabled:e}),disabled:Ae.isPending,"aria-label":F.enabled?t(`integrationDetail.disableIntegration`,`Disable integration`):t(`integrationDetail.enableIntegration`,`Enable integration`)}),i(`span`,{className:`text-[11px] font-medium ${F.enabled?`text-success`:`text-foreground-subtle`}`,children:F.enabled?t(`integrationDetail.enabled`,`Enabled`):t(`integrationDetail.disabled`,`Disabled`)}),Ae.isPending&&i(w,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),X!==`standalone`&&(xe||G===`device-adoption`)&&e(`button`,{onClick:()=>k(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[i(y,{className:`h-3 w-3`}),t(`integrations.config`)]}),e(`button`,{onClick:()=>M(!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:t(`integrations.logs`,{defaultValue:`View logs`}),children:[i(ee,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),i(ce,{label:t(`integrationDetail.restart`,`Restart`),icon:T,title:t(`integrationDetail.restart2`,`Restart "{{name}}"?`,{name:F.name}),description:t(`integrationDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device backed by it ({{topLevelCountLabel}} active). Streams will reconnect automatically.`,{topLevelCountLabel:Ye}),confirmLabel:t(`integrationDetail.restart`,`Restart`),triggerVariant:`outline`,confirmVariant:`danger`,disabled:Ie.isPending,action:()=>Ie.mutateAsync({addonId:F.addonId})}),!ue&&s&&i(ce,{label:t(`integrations.delete`,{defaultValue:`Delete`}),icon:f,title:t(`integrations.deleteTitle`,{defaultValue:`Delete integration?`}),description:t(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:F.name,count:Ye}),confirmLabel:t(`integrations.confirmDelete`,{defaultValue:`Delete integration`}),triggerVariant:`outline`,confirmVariant:`danger`,className:`border-danger bg-danger/10 text-danger hover:bg-danger hover:text-background`,disabled:Me.isPending,action:()=>Me.mutateAsync({id:s})})]})]}),Ee&&i(ze,{nodeId:null,addonIds:De,level:`global`,surface:`integration`,title:t(`integrations.settings`,{defaultValue:`Settings`})}),i(re,{context:`integration-detail`,devices:Q,trpc:g.trpcClient,integrationOf:Ge,forceIntegrationId:F.id,urlScope:`root`,lsKey:`integration-detail:${F.addonId}`,resolveIntegrationIcon:Fe,resolveParent:Ue,onNavigate:Ke,batchActions:{remove:Le.mutate,disable:Be.mutate,enable:Ve.mutate},...ue?{}:{onDeleteDevice:e=>Le.mutate({deviceId:e.id})}}),_&&s&&he&&!b&&i(Je,{onClose:()=>v(!1),onCommissioned:()=>x(!0)}),_&&s&&G===`device-adoption`&&(!he||b)&&i(nt,{addonId:F.addonId,integrationId:s,onClose:()=>{v(!1),x(!1)}}),_&&s&&G===`device-provider`&&i(We,{open:_,integrationId:s,addonId:F.addonId,onClose:()=>v(!1)}),S&&F&&i(Re,{open:S,scope:{addonId:F.addonId,label:F.name},onClose:()=>E(!1),onSetupIntegration:D}),ne&&s&&G!==null&&X!==null&&i(lt,{integrationId:s,addonId:F.addonId,name:F.name,kind:G,mode:X,brokerKind:Y,canTest:_e,trpc:g.trpcClient,onClose:()=>k(!1)}),j&&i(q,{open:!0,onOpenChange:e=>!e&&M(!1),children:e(me,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[i(V,{className:`mb-0`,children:e(we,{className:`flex items-center gap-2 min-w-0`,children:[i(ee,{className:`h-4 w-4 text-primary shrink-0`}),i(`span`,{className:`truncate`,children:F.name}),e(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate font-normal`,children:[F.addonId,s?` · ${s}`:``]})]})}),i(ye,{className:`min-h-0 overflow-hidden p-0`,children:i(be,{addonId:F.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(O,{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:t(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:s??``})})]}),e(`button`,{onClick:()=>d(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[i(h,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}function ft({addonId:e}){let t=ke(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{dt as IntegrationDetailPage};
@@ -1 +0,0 @@
1
- import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,et as s,o as c,x as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{An as u,Ci as d,Oi as f,Si as p,bi as m,dn as h,dt as g,kn as _,ot as v,pn as y,pr as ee,sr as b,wn as x,xn as te}from"./player-overlays-Cs6l33cj.js";import{t as ne}from"./table-2-lftK0wHb.js";import{$a as re,At as S,Er as C,F as ie,Nt as w,So as ae,_d as T,_i as oe,at as E,bs as D,do as se,ei as O,hs as k,jt as A,ld as ce,r as j,ud as le,vs as M}from"./src-DFzrn-CX.js";import{t as N}from"./i18n-sTui-nG3.js";import{t as P}from"./useTranslation-BJr-n0es.js";import{fr as ue,hr as F,pr as de,sr as I}from"./index-Dow2-3ZC.js";import{t as L}from"./AdminPage-QmLz5qjj.js";import"./useEventInvalidation-P-UzQOB7.js";import{t as R}from"./device-integration-icon-Csh9ZCwn.js";import{i as fe,n as pe,r as z,t as me}from"./ScanNetworkModal-PQbiE2mC.js";s();function he({rows:t,isExpanded:r,onToggleExpand:a,onOpen:s,renderExpanded:c,searchPlaceholder:l,emptyLabel:u}){let[d,f]=o(``),p=n(()=>{let e=d.trim().toLowerCase();return e.length===0?t:t.filter(t=>`${t.name} ${t.addonId}`.toLowerCase().includes(e))},[d,t]);return e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`relative`,children:[i(y,{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(ce,{type:`search`,value:d,onChange:e=>f(e.target.value),placeholder:l,"aria-label":l,className:`pl-8`})]}),p.length===0?i(`p`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:u}):i(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2 sm:gap-3 lg:grid-cols-3`,children:p.map(e=>i(ge,{integration:e,expanded:r(e),onToggleExpand:a,onOpen:s,renderExpanded:c},e.id))})]})}function ge({integration:t,expanded:n,onToggleExpand:r,onOpen:a,renderExpanded:o}){return e(`article`,{"data-testid":`integration-card-${t.id}`,className:T(`flex min-w-0 flex-col gap-2 overflow-x-clip rounded-lg border border-border bg-surface p-3`,n&&`sm:col-span-2 lg:col-span-3`),children:[i(_e,{integration:t,expanded:n,onToggleExpand:r,onOpen:a}),n?i(`div`,{className:`min-w-0`,children:o(t)}):null]})}function _e({integration:t,expanded:n,onToggleExpand:r,onOpen:a}){let{t:o}=P(),s=n?o(`integrations.integrationColumns.collapse`,`Collapse`):o(`integrations.integrationColumns.expand`,`Expand`);return e(`div`,{className:`relative flex min-w-0 items-stretch gap-3`,children:[i(O,{type:`button`,variant:`ghost`,"aria-label":o(`integrations.openNamed`,{name:t.name,defaultValue:`Open {{name}}`}),onClick:()=>a(t),className:`absolute inset-0 z-0 h-auto w-auto rounded-lg p-0 focus-visible:ring-2 focus-visible:ring-primary`}),i(B,{integration:t}),e(`div`,{className:`pointer-events-none relative z-10 flex min-w-0 flex-1 flex-col items-start gap-1.5`,children:[i(E,{status:t.status,className:`shrink-0`}),i(`p`,{className:`text-[11px] text-foreground-muted`,children:o(`integrations.integrationColumns.deviceCount`,{count:t.deviceCount})}),i(`div`,{className:`pointer-events-auto mt-auto self-end`,children:i(le,{type:`button`,variant:`ghost`,size:`sm`,icon:n?p:m,"aria-label":s,"aria-expanded":n,onClick:e=>H(e,t.addonId,r)})})]})]})}function B({integration:t}){return e(`div`,{className:`pointer-events-none relative z-10 flex w-28 shrink-0 flex-col items-center gap-1 lg:w-24`,children:[i(I,{type:t.addonId,size:`xl`}),i(`p`,{className:`w-full text-center text-xs font-semibold text-foreground`,children:t.name}),i(V,{addonId:t.addonId})]})}function V({addonId:t}){return i(`p`,{className:`w-full text-center text-[10px] leading-tight text-foreground-subtle`,children:t.split(`-`).map((t,n)=>e(`span`,{children:[n>0?e(l,{children:[`-`,i(`wbr`,{})]}):null,t]},`${t}-${String(n)}`))})}function H(e,t,n){e.stopPropagation(),n(t)}s();var U=`camstack.admin.integrations.view`;function W(e){return e===`table`||e===`grid`}function G(){try{return typeof window>`u`?null:window.localStorage}catch{return null}}function K(e=G()){if(e===null)return`table`;try{let t=e.getItem(U);return W(t)?t:`table`}catch{return`table`}}function q(e,t=G()){if(t!==null)try{t.setItem(U,e)}catch{}}function ve(){let[e,t]=o(()=>K());return[e,r(e=>{t(e),q(e)},[])]}s();function J(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 ye(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 be({providerId:t,onImport:n,onSkip:r}){let{t:s}=P(),[c,l]=o(new Set),u=se(),p=u.data,m=u.isPending||!u.data&&!u.isError;a(()=>{t&&(u.isPending||u.data||u.mutate({addonId:t}))},[t,u]);function h(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(m)return e(`div`,{className:`flex flex-col items-center py-12`,children:[i(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),i(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:s(`integrations.searchingDevices`)})]});let g=p??[];return e(`div`,{className:`space-y-4`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:g.length>0?s(`integrations.foundDevices`,{count:g.length}):s(`integrations.noDevicesFound`)}),g.length>0&&i(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:g.map(t=>{let n=t.stableId,r=t.suggestedName??n,a=c.has(n),o=t.alreadyOnboarded===!0;return e(`button`,{onClick:()=>{o||h(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(d,{className:`h-3 w-3 text-primary-foreground`})}),i(f,{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(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:s(`integrations.skip`)}),g.length>0&&e(`button`,{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,`)`]})]})]})}var Y=`(hover: none) and (pointer: coarse)`;function X(){if(typeof window>`u`||typeof window.matchMedia!=`function`)return!0;try{return!window.matchMedia(Y).matches}catch{return!0}}s();function Z({onSelect:r,onClose:s,pendingAddonId:c=null}){let{t:l}=P(),u=de(),[d,f]=o(``),p=t(null),{data:m,isLoading:g}=M();a(()=>{g||!X()||p.current?.focus()},[g]);let _=n(()=>{let e=m??[],t=d.trim().toLowerCase();return t.length===0?e:e.filter(e=>`${e.name} ${e.description??``} ${e.addonId}`.toLowerCase().includes(t))},[m,d]);if(g)return i(`div`,{className:`grid grid-cols-2 gap-2 p-2`,children:[1,2,3,4].map(e=>i(`div`,{className:`h-24 rounded-lg bg-surface animate-pulse`},e))});let v=c!==null;return e(`div`,{className:`space-y-3`,"data-testid":`provider-picker`,children:[e(`div`,{className:`relative`,children:[i(y,{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(ce,{ref:p,type:`search`,value:d,onChange:e=>f(e.target.value),placeholder:l(`integrations.searchProviders`,`Search integrations…`),className:`pl-8`,"data-testid":`provider-picker-search`,"aria-label":l(`integrations.searchProviders`,`Search integrations…`)})]}),i(`div`,{className:`grid grid-cols-2 gap-2`,children:_.map(t=>{let n=t.instanceMode===`unique`&&t.existingInstances.length>0,a=c===t.addonId,o=v;return e(`button`,{type:`button`,disabled:o,"data-testid":`provider-pick-${t.addonId}`,onClick:()=>{if(!o)if(n){let e=t.existingInstances[0].id;s(),u(`/integrations/${e}`)}else r(t.addonId,t.instanceMode,t.discoveryMode,t.name,t.kind,t.brokerKind,t.mode,t.canTest)},className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-center text-xs hover:border-primary/50 hover:bg-surface-hover transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[t.iconUrl?i(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${t.color}15`},children:i(`img`,{src:t.iconUrl,alt:``,className:`h-5 w-5`})}):i(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${t.color}15`},children:i(`span`,{className:`text-sm`,style:{color:t.color},children:`◉`})}),i(`p`,{className:`w-full truncate text-xs font-semibold text-foreground`,children:t.name}),t.description?i(`p`,{className:`w-full line-clamp-2 text-[10px] text-foreground-subtle`,children:t.description}):null,a?i(b,{className:`h-4 w-4 animate-spin text-primary`}):n?e(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[i(h,{className:`h-3 w-3`}),l(`integrations.manage`)]}):null]},t.addonId)})}),_.length===0&&i(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:(m??[]).length===0?l(`integrations.noProviders`):l(`integrations.noProvidersMatch`,`No integrations match your search.`)})]})}s();function xe(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 Se=2e4;function Ce({open:t,onClose:r,seed:s=null}){let{t:u}=P(),d=de(),f=c(),[p,m]=o(`picker`),[h,_]=o(null),[v,y]=o(null),[ee,x]=o(`manual`),[te,ne]=o(null),[S,C]=o(``),[ie,w]=o(null),[ae,T]=o(null),[E,D]=o(!1),[O,A]=o({}),[ce,j]=o(``),le=s?.config.host,N=s===null?``:`${s.addonId}\0${s.name}\0${typeof le==`string`?le:``}`;t&&s!==null&&ce!==N&&(j(N),_(s.addonId),C(s.name),A({...s.config}),m(`config`));let ue=M(void 0,{enabled:t&&s!==null}),{data:F}=oe({addonId:h??``,nodeId:`hub`},{enabled:h!=null}),I=n(()=>F?xe(F):null,[F]),L=k({onSuccess:()=>f.invalidateQueries({queryKey:[[`integrations`]]})}),R=se(),pe=R.data;a(()=>{if(!t||s===null)return;let e=ue.data?.find(e=>e.addonId===s.addonId);e&&(D(e.canTest),x(e.discoveryMode))},[t,s,ue.data]),a(()=>{p!==`discovery`||!v||!h||R.isPending||R.data||R.mutate({addonId:h})},[p,v,h,R]);let me=re({onSuccess:()=>f.invalidateQueries({queryKey:[[`deviceManager`]]})});function he(e,t,n,r,i,a,o,s){if(!L.isPending){if(_(e),D(s),x(n),C(r),T(null),o===`broker`){if(!a){T(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}ne(a),m(`broker`);return}if(o===`account`){m(`config`);return}ge(e,r)}}async function ge(e,t){try{let n=await L.mutateAsync({addonId:e,name:t,settings:{}});r(),U(),d(`/integrations/${n.id}?add=1`)}catch{}}async function _e(e){if(h)try{let t=await L.mutateAsync({addonId:h,name:e.name,settings:e.config,secretKeys:[...e.secretKeys]});y(t.id),w(t.id),ee===`auto`||ee===`both`?m(`discovery`):H(t.id,{openAdd:!0})}catch{}}async function B(e){if(h)try{let t=await L.mutateAsync({addonId:h,name:S,settings:{brokerId:e}});w(t.id),y(t.id),H(t.id)}catch{}}async function V(e){if(h){for(let t of e){let e=pe?.find(e=>e.stableId===t);e&&await me.mutateAsync({addonId:h,candidate:e,...ie===null?{}:{integrationId:ie}})}H()}}function H(e,t){let n=e??v??h;r(),U(),n&&d(t?.openAdd===!0?`/integrations/${n}?add=1`:`/integrations/${n}`)}function U(){m(`picker`),_(null),y(null),x(`manual`),ne(null),C(``),w(null),T(null),D(!1),A({}),j(``)}function W(){r(),U()}J(t);let G=L.isPending,K=ye(G,Se);if(!t)return null;let q={picker:u(`integrations.newIntegration`),config:u(`integrations.configureIntegration`),discovery:u(`integrations.importDevices`),broker:u(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},ve=G?h:null,Y=L.error,X=G&&!K;return e(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[i(`div`,{className:`absolute inset-0 bg-black/60`,onClick:X?void 0:W}),e(`div`,{className:`relative z-10 w-full max-w-lg max-h-[calc(85dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[e(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[i(`h2`,{className:`text-sm font-semibold text-foreground`,children:q[p]}),i(`button`,{onClick:W,disabled:X,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:i(g,{className:`h-4 w-4`})})]}),e(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[Y&&!G&&i(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:Y instanceof Error?Y.message:String(Y)}),p===`picker`&&e(l,{children:[ae&&i(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:ae}),i(Z,{onSelect:he,onClose:W,pendingAddonId:ve})]}),p===`config`&&h&&i(z,{addonId:h,configSchema:I??null,canTest:E,initialName:typeof O.host==`string`?S:void 0,initialConfig:{...O},onSave:_e,onBack:()=>{A({}),m(`picker`)}},N.length>0?N:h),p===`broker`&&te&&i(fe,{kind:te,onResolved:e=>{B(e)},onBack:()=>m(`picker`)}),p===`discovery`&&v&&i(be,{providerId:v,onImport:V,onSkip:H})]}),G&&e(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm px-6 text-center`,children:[i(b,{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…`})}),!K&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:u(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),K&&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(`button`,{onClick:W,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`})})]})]})]})]})}function we({integration:t,expanded:n,onToggleExpand:r}){let{t:a}=P();return e(`div`,{className:`flex items-center gap-2.5`,children:[i(`button`,{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?p:m,{className:`h-3.5 w-3.5`})}),i(I,{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 Te(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:N.t(`integrations.integrationColumns.integration`,`Integration`),headerClassName:`w-[55%]`,cell:e=>i(we,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:N.t(`integrations.integrationColumns.devices`,`Devices`),headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>N.t(`integrations.integrationColumns.deviceCount`,{count:e.deviceCount})},{key:`status`,header:N.t(`integrations.integrationColumns.status`,`Status`),headerClassName:`w-[15%]`,cell:e=>i(E,{status:e.status})}]}s();function Ee(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var De=`expand`;function Oe(){let{t}=P(),s=de(),c=ue(),d=v(),[f]=F(),[p,m]=ve(),[h,g]=o(!1),[y,b]=o(null),re=r(()=>{b(null),g(!0)},[]),oe=r(()=>{g(!1),b(null)},[]),E=r(e=>{O(!1),b(e),g(!0)},[]),[se,O]=o(!1);a(()=>{let e=pe(c.state);e!==null&&(b(e),g(!0),s(`/integrations`,{replace:!0,state:null}))},[c.state,s]);let k=f.get(`setup`);a(()=>{k===null||k.length===0||(b({addonId:k,name:k,config:{}}),g(!0))},[k]);let ce=r(()=>O(!0),[]),le=r(()=>O(!1),[]);j([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),j([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:M,isLoading:N,isError:I,refetch:fe}=D(void 0),{data:z,isLoading:ge,isError:_e,refetch:B}=ae({projection:`slim`}),V=n(()=>z??[],[z]),H=n(()=>M??[],[M]),U=n(()=>{let e=new Map;for(let t of V)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[V]),W=n(()=>A(M),[M]),G=n(()=>{let e=new Map;for(let t of w(V)){let n=W(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[V,W]),K=n(()=>H.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:Ee(e),deviceCount:G.get(e.id)??0})),[H,G]),q=f.get(De),J=r(e=>{let t=new URLSearchParams(window.location.search);t.get(De)===e?t.delete(De):t.set(De,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`))},[]),ye=r(e=>s(`/integrations/${e.id}`),[s]),be=r(e=>U.get(e)??null,[U]),Y=r(e=>s(`/devices/${String(e)}`),[s]),X=r(e=>i(S,{context:`integration-detail`,devices:V,trpc:d.trpcClient,integrationOf:W,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:R,resolveParent:be,onNavigate:Y}),[V,d.trpcClient,W,be,Y]),Z=r(e=>q===e.addonId,[q]),xe=n(()=>Te({isExpanded:Z,onToggleExpand:J}),[Z,J]),Se=r(e=>`${e.name} ${e.addonId}`,[]),we=r(e=>e.addonId,[]),Oe=r(()=>{fe(),B()},[fe,B]),Q=I===!0||_e===!0,$=!Q&&(N||ge||M===void 0||z===void 0),ke=H.length>0,Ae=[{id:`table`,label:t(`integrations.viewTable`,`Table`),icon:ne},{id:`grid`,label:t(`integrations.viewGrid`,`Grid`),icon:ee}];return e(L,{icon:_,title:t(`nav.integrations`,`Integrations`),actions:e(l,{children:[i(ie,{ariaLabel:t(`integrations.viewLabel`,`Layout`),value:p,onChange:m,options:Ae,testId:`integrations-view`}),i(`button`,{onClick:Oe,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(te,{className:T(`h-3.5 w-3.5`,$&&`animate-spin`)})}),e(`button`,{onClick:ce,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(x,{className:`h-3.5 w-3.5`}),t(`integrations.scanNetwork`,`Scan network`)]}),e(`button`,{onClick:re,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(u,{className:`h-3.5 w-3.5`}),t(`integrations.newIntegration`,`New Integration`)]})]}),children:[Q&&i(C,{message:t(`integrations.loadFailed`,`Integrations could not be loaded.`),onRetry:Oe}),$&&i(`div`,{className:`space-y-2`,"data-testid":`integrations-pending`,children:[1,2,3].map(e=>i(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!$&&!ke&&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&&!$&&ke&&p===`table`&&i(S,{mode:`generic`,items:K,getKey:we,getSearchText:Se,columns:xe,onRowClick:ye,isExpanded:Z,renderExpanded:X,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),!Q&&!$&&ke&&p===`grid`&&i(he,{rows:K,isExpanded:Z,onToggleExpand:J,onOpen:ye,renderExpanded:X,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),i(Ce,{open:h,onClose:oe,seed:y}),i(me,{open:se,onClose:le,onSetupIntegration:E})]})}export{Oe as IntegrationsPage};
@@ -1 +0,0 @@
1
- import{C as e,K as t,R as n,S as r,V as i,Y as a,et as o,o as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{An as l,Bn as u,Ci as d,D as f,L as p,Lt as m,Pt as h,Qr as g,Qt as _,Vr as v,Xt as y,Z as b,bn as x,dt as S,fn as C,gn as ee,ht as w,ir as T,jn as te,ot as E,sn as D,sr as O,xn as ne}from"./player-overlays-Cs6l33cj.js";import{Ar as re,Fr as ie,Pr as ae,Xn as oe}from"./client-Ct1F5MoE.js";import{t as k}from"./boxes-BiMbpzNh.js";import{l as A,s as se}from"./video-Byw3ItoR.js";import{t as ce}from"./log-in-53JDrQ-P.js";import{$s as le,Ai as j,Bs as ue,Cn as de,Er as fe,Gs as pe,Js as me,Ks as he,Qs as ge,Rs as _e,So as ve,Us as ye,Vu as be,Wn as xe,Ys as Se,ac as Ce,bn as we,ec as Te,ei as M,id as Ee,ji as N,ld as De,nc as Oe,oc as ke,sc as Ae,si as P,tc as je,vn as Me,xn as Ne,xr as Pe,zs as Fe}from"./src-DFzrn-CX.js";import{t as F}from"./i18n-sTui-nG3.js";import{t as I}from"./useTranslation-BJr-n0es.js";import"./mount-P-UzQOB7.js";import{S as Ie,a as L,dr as Le,hr as Re,i as R,ur as ze}from"./index-Dow2-3ZC.js";import{t as Be}from"./AdminSectionedPage-D9jBOpIg.js";import{t as z}from"./AdminPage-QmLz5qjj.js";import{t as Ve}from"./NodeAddonsSettingsPanel-DUUGVGQU.js";import{n as B,r as He,t as V}from"./IntegrationHub-D5yLfTfh.js";import{n as H,t as U}from"./addon-display-names-BkwMrExv.js";o();var W=5e3,G=`network-access`,Ue={connected:!1,endpoint:null};function We(){let{t:e}=I(),n=s(),i=N({capName:`network-access`},{refetchInterval:W}),o=j(void 0,{refetchInterval:W}),c=t(()=>U(o.data??[]),[o.data]),l=t(()=>(i.data??[]).map(e=>({addonId:e.addonId,displayName:c.get(e.addonId)??e.addonId,isActive:e.isActive})),[i.data,c]),[u,d]=a(null),[f,p]=a({}),m=(e,t)=>{let r=t?.addonId;n.invalidateQueries({queryKey:[[`networkAccess`,`getStatus`],{input:{addonId:r},type:`query`}]}),d(null),p(e=>{if(r===void 0||!(r in e))return e;let t={...e};return delete t[r],t})},h=(e,t)=>{d(null);let n=t?.addonId;if(n===void 0)return;let r=e instanceof Error?e.message:String(e);p(e=>({...e,[n]:r}))},g=ke({onSuccess:m,onError:h}),_=Ae({onSuccess:m,onError:h}),v=[{id:G,label:e(`system.remoteAccess.remoteAccess`,`Remote access`),install:{capability:G,label:e(`system.remoteAccess.addTunnel`,`Add tunnel`)},entries:l.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:A,...H(e.isActive),render:()=>r(B,{addonId:e.addonId,displayName:e.displayName,capName:G,isActive:e.isActive,badges:r(Ke,{addonId:e.addonId}),error:f[e.addonId]??null,primaryAction:r(qe,{addonId:e.addonId,busyId:u,onStart:e=>{d(e),g.mutate({addonId:e})},onStop:e=>{d(e),_.mutate({addonId:e})}})})}))}];return r(V,{embedded:!0,icon:A,title:e(`system.remoteAccess.remoteAccess2`,`Remote Access`),subtitle:e(`system.remoteAccess.publicFacingTunnelsThatExpose`,`Public-facing tunnels that expose this hub to the internet (Cloudflare Tunnel, ngrok, …).`),groups:v,isLoading:i.isLoading,emptyTitle:e(`system.remoteAccess.noRemoteAccessProvidersInstalled`,`No remote-access providers installed`),emptyDescription:e(`system.remoteAccess.installATunnelAddonE`,`Install a tunnel addon (e.g. @camstack/addon-cloudflare) to expose this hub publicly.`)})}function Ge(e){let{data:t}=Ce({addonId:e},{refetchInterval:W,retry:!1}),n=t?re.safeParse(t):null;return n?.success?n.data:Ue}function Ke({addonId:t}){let{t:n}=I(),i=Ge(t);return e(c,{children:[r(P,{variant:i.connected?`success`:`default`,className:He,children:i.connected?n(`system.remoteAccess.connected`,`Connected`):n(`system.remoteAccess.disconnected`,`Disconnected`)}),i.endpoint&&e(`a`,{href:i.endpoint.url,target:`_blank`,rel:`noopener noreferrer`,className:`flex min-w-0 items-center gap-1 break-all text-[11px] text-success hover:underline`,children:[r(v,{className:`h-3 w-3`}),i.endpoint.url]})]})}function qe({addonId:t,busyId:n,onStart:i,onStop:a}){let{t:o}=I(),s=Ge(t),c=n===t;return s.connected?e(M,{size:`sm`,variant:`secondary`,disabled:c,onClick:()=>a(t),children:[c?r(O,{className:`h-3 w-3 animate-spin`}):r(y,{className:`h-3 w-3`}),o(`system.remoteAccess.stop`,`Stop`)]}):e(M,{size:`sm`,variant:`primary`,disabled:c,onClick:()=>i(t),children:[c?r(O,{className:`h-3 w-3 animate-spin`}):r(te,{className:`h-3 w-3`}),o(`system.remoteAccess.start`,`Start`)]})}o();var Je=3e4,K=`turn-provider`;function Ye(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function Xe(){let{t:n}=I(),i=N({capName:`turn-provider`},{refetchInterval:Je}),a=j(void 0,{refetchInterval:Je}),o=be(),s=o.data??[],c=t(()=>U(a.data??[]),[a.data]),l=t(()=>(i.data??[]).map(e=>({addonId:e.addonId,displayName:c.get(e.addonId)??e.addonId,isActive:e.isActive})),[i.data,c]),d=[{id:K,label:n(`system.turnServers.turnProviders`,`TURN providers`),install:{capability:K,label:n(`system.turnServers.addProvider`,`Add provider`)},entries:l.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:u,...H(e.isActive),render:()=>r(B,{addonId:e.addonId,displayName:e.displayName,capName:K,isActive:e.isActive,panels:[{id:`ice-servers`,title:n(`system.turnServers.discoveredIceServers`,`Discovered ICE servers`),icon:u,content:r(Ze,{addonId:e.addonId,enabled:e.isActive})}]})}))}];return r(V,{embedded:!0,icon:u,title:n(`system.turnServers.turnServers`,`TURN Servers`),subtitle:n(`system.turnServers.iceServersUsedForWebrtc`,`ICE servers used for WebRTC NAT traversal. Multiple providers can coexist — the WebRTC layer concatenates servers from all enabled providers per session.`),groups:d,isLoading:i.isLoading,emptyTitle:n(`system.turnServers.noTurnProvidersInstalled`,`No TURN providers installed`),emptyDescription:n(`system.turnServers.installATurnAddonE`,`Install a TURN addon (e.g. @camstack/addon-cloudflare) to enable WebRTC behind restrictive NATs.`),trailing:r(Ne,{headingId:`turn-combined-ice`,title:n(`system.turnServers.combinedIceServerListAll`,`Combined ICE server list — all enabled providers`),icon:u,actions:r(M,{size:`sm`,variant:`secondary`,onClick:()=>o.refetch(),disabled:o.isFetching,children:n(`common.refresh`,`Refresh`)}),children:r(`div`,{className:f,children:s.length===0?r(`div`,{className:`text-xs text-foreground-subtle`,children:n(`system.turnServers.noServersFromEnabledProviders`,`No servers from enabled providers.`)}):r(`div`,{className:`flex flex-col gap-3`,children:s.map((t,n)=>{let i=Array.isArray(t.urls)?t.urls:[t.urls];return e(`div`,{className:`rounded border border-border bg-surface`,children:[(t.username||t.credential)&&e(`div`,{className:`px-3 py-1.5 border-b border-border text-[10px] font-mono text-foreground-subtle flex items-center gap-3`,children:[t.username&&e(`span`,{children:[r(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,r(`span`,{className:`text-foreground`,children:t.username})]}),t.credential&&e(`span`,{children:[r(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,r(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),r(`ul`,{className:`divide-y divide-border`,children:i.map(e=>r(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},n)})})})})})}function Ze({addonId:e,enabled:n}){let i=be({addonId:e},{enabled:n,retry:!1}),a=t(()=>Ye(i.data??[]),[i.data]),o=n?i.isLoading?`Loading…`:a.length===0?`This provider returned no servers.`:null:`Disabled — enable the provider to fetch its servers.`;return r(`div`,{className:`rounded-lg border border-border bg-surface p-2 sm:p-3`,children:o===null?r(`div`,{className:`flex flex-wrap gap-1`,children:a.map(e=>r(`span`,{className:`inline-block break-all rounded bg-foreground-subtle/10 px-1.5 py-0.5 font-mono text-[10px] text-foreground`,children:e},e))}):r(`div`,{className:`text-xs text-foreground-subtle`,children:o})})}o();var Qe={lan:u,wifi:w,docker:k,vpn:T,loopback:C,other:C},$e={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},et=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function tt(n){let{t:i}=I(),{interfaces:a,disabled:o,hideLoopback:s,ipv4Only:c,emptyMessage:l}=n,u=t(()=>a.filter(e=>!(s&&e.kind===`loopback`||c&&e.family!==`IPv4`)),[a,s,c]),f=t(()=>{let e=new Map;for(let t of u){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return et.filter(t=>e.has(t)).map(t=>({kind:t,items:e.get(t)}))},[u]),p=e=>n.mode===`single`?n.value===e:n.value.includes(e),m=e=>{if(o||e.kind===`loopback`)return;if(n.mode===`single`){n.onChange(n.value===e.address?null:e.address);return}let t=new Set(n.value);t.has(e.address)?t.delete(e.address):t.add(e.address),n.onChange([...t])};return u.length===0?r(`div`,{className:`text-xs text-foreground-subtle italic`,children:l??i(`shared.addressSelector.noAddressesAvailable`,`No addresses available.`)}):r(`div`,{className:`flex flex-col gap-3`,children:f.map(({kind:t,items:a})=>e(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[e(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[r(Qe[t]??C,{className:`h-3.5 w-3.5 text-foreground-subtle`}),r(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:$e[t]??t}),e(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,a.length]})]}),r(`ul`,{className:`divide-y divide-border`,children:a.map(t=>{let a=p(t.address),s=t.kind===`loopback`,c=!t.plausible&&!s;return e(`li`,{className:`flex items-center gap-3 px-3 py-2 ${s?`opacity-60 cursor-not-allowed`:o?`opacity-60`:c?`cursor-pointer hover:bg-surface-hover/30 bg-amber-500/[0.04]`:`cursor-pointer hover:bg-surface-hover/30`}`,onClick:()=>m(t),children:[r(`span`,{className:`flex items-center justify-center h-4 w-4 rounded ${n.mode===`single`?`rounded-full`:`rounded`} border ${a?`border-primary bg-primary text-primary-foreground`:`border-border bg-surface`}`,children:a&&r(d,{className:`h-3 w-3`})}),e(`div`,{className:`flex-1 min-w-0 ${c?`text-foreground-subtle`:``}`,children:[e(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[r(`span`,{className:`font-mono text-xs font-semibold ${c?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),r(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-mono`,children:t.family}),t.preferred&&r(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:i(`shared.addressSelector.autoPreferred`,`Auto-preferred`)}),s&&r(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:i(`shared.addressSelector.alwaysIncluded`,`Always included`)}),c&&e(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:t.plausibleReason||void 0,children:[r(h,{className:`h-2.5 w-2.5`}),i(`shared.addressSelector.unlikelyUsable`,`Unlikely usable`)]})]}),e(`div`,{className:`text-xs text-foreground-subtle mt-0.5 font-mono break-all`,children:[t.address,t.cidr&&t.cidr!==t.address?` (${t.cidr})`:``]})]})]},`${t.name}-${t.family}-${t.address}`)})})]},t))})}var q=[{role:`appConnections`,get title(){return F.t(`helpers.addressTableModel.appConnectionsTitle`)},single:!1,get help(){return F.t(`helpers.addressTableModel.appConnectionsHelp`)}},{role:`notificationTaps`,get title(){return F.t(`helpers.addressTableModel.notificationTapsTitle`)},single:!0,get help(){return F.t(`helpers.addressTableModel.notificationTapsHelp`)}},{role:`publicEndpoint`,get title(){return F.t(`helpers.addressTableModel.publicEndpointTitle`)},single:!0,get help(){return F.t(`helpers.addressTableModel.publicEndpointHelp`)}},{role:`internal`,get title(){return F.t(`helpers.addressTableModel.internalTitle`)},single:!0,get help(){return F.t(`helpers.addressTableModel.internalHelp`)}}],nt=`A role with nothing ticked is automatic. Add a custom address when the hub is reached at an address it cannot see itself (NAT, reverse proxy, VPN, Docker bridge).`;function J(e,t){return e.inUse.includes(t)}function rt(e,t){if(!e.eligible.includes(t))return{kind:`none`};if(e.kind===`app-link`)return J(e,t)?{kind:`none`}:{kind:`set`,input:{role:t,baseUrl:null,enabled:!0}};if(e.flags.includes(t)||t===`appConnections`&&J(e,t))return{kind:`set`,input:{role:t,baseUrl:e.baseUrl,enabled:!1}};let n={role:t,baseUrl:e.baseUrl,enabled:!0};return t===`publicEndpoint`&&e.baseUrl.startsWith(`http:`)?{kind:`confirm-http`,input:n,reason:ae}:{kind:`set`,input:n}}function it(e){return q.map(({role:t,title:n})=>{if(t===`appConnections`){let r=e.roles.appConnections;return{role:t,title:n,inUse:r.resolved.length===0?`nothing reachable`:r.resolved.join(`, `),automatic:r.source!==`flagged`}}let r=e.roles[t];return{role:t,title:n,inUse:r.resolved===null?`nothing reachable`:t===`notificationTaps`&&r.source===`auto`?`CamStack app link`:r.resolved,automatic:r.source!==`flagged`}})}o();var at={"lan-ipv4":{labelKey:`system.addressesCard.kindIpv4`,className:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`},"lan-ipv6":{labelKey:`system.addressesCard.kindIpv6`,className:`bg-violet-500/15 text-violet-700 dark:text-violet-300`},public:{labelKey:`system.addressesCard.kindPublic`,className:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},"app-link":{labelKey:`system.addressesCard.kindAppLink`,className:`bg-amber-500/15 text-amber-700 dark:text-amber-300`},custom:{labelKey:`system.addressesCard.kindCustom`,className:`bg-sky-500/15 text-sky-700 dark:text-sky-300`},loopback:{labelKey:`system.addressesCard.kindLoopback`,className:`bg-foreground-subtle/15 text-foreground-subtle`}};function ot({book:t,loading:n,saving:i,error:o,onSetRole:s,onAdd:c,onRemove:u}){let{t:d}=I(),[f,p]=a(``),[g,_]=a(``),[v,y]=a(null),[b,x]=a(null),S=()=>{let e=ie(f);if(!e.ok){y(e.reason);return}y(null),p(``),_(``),c(e.baseUrl,g.trim())},C=(e,t)=>{let n=rt(e,t.role);if(n.kind!==`none`){if(n.kind===`confirm-http`){x({input:n.input,reason:n.reason});return}x(null),s(n.input)}},ee=[{key:`url`,header:d(`system.addressesCard.address`,`Address`),render:n=>e(`div`,{className:`min-w-0 py-0.5`,children:[r(`div`,{className:`font-mono text-[12px] break-all ${n.plausible?`text-foreground`:`text-foreground-subtle`}`,children:n.baseUrl}),e(`div`,{className:`mt-0.5 flex flex-wrap items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[r(`span`,{children:n.label}),n.kind===`app-link`&&e(`span`,{className:`font-mono`,children:[`hub=`,` `,t?.appLinkHub??d(`system.addressesCard.noneNoTunnelOrTailscale`,`none (no tunnel or Tailscale)`)]}),n.custom&&n.detected&&r(`span`,{children:d(`system.addressesCard.alsoAddedAsACustom`,`also added as a custom address`)}),n.kind!==`custom`&&n.interfaceKind!==`lan`&&n.interfaceKind!==`public`&&n.interfaceKind!==`other`&&r(`span`,{className:`uppercase tracking-wide`,children:n.interfaceKind}),!n.plausible&&n.interfaceKind!==`loopback`&&e(`span`,{className:`inline-flex items-center gap-1 text-amber-700 dark:text-amber-300`,title:n.plausibleReason||void 0,children:[r(h,{className:`h-2.5 w-2.5`}),d(`system.addressesCard.unlikelyUsable`,`Unlikely usable`)]})]})]})},{key:`kind`,header:d(`system.addressesCard.kind`,`Kind`),nowrap:!0,render:e=>{let t=at[e.kind]??at.loopback;return r(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.className}`,children:d(t.labelKey)})}},...q.map(t=>({key:t.role,headerRender:()=>r(`span`,{title:t.help,children:t.title}),align:`center`,nowrap:!0,width:`w-24`,render:n=>{let a=n.eligible.includes(t.role),o=n.flags.includes(t.role),s=J(n,t.role);return e(`label`,{className:`inline-flex items-center justify-center gap-1 ${a?`cursor-pointer`:`cursor-not-allowed opacity-40`}`,title:a?s&&!o?d(`system.addressesCard.inUseAutomatically`,`{{title}}: in use automatically. {{help}}`,{title:t.title,help:t.help}):t.help:d(`system.addressesCard.thisAddressCannotBeUsed`,`This address cannot be used for this.`),children:[r(xe,{checked:a&&s,disabled:!a||i,onChange:()=>C(n,t),"aria-label":`${t.title}: ${n.baseUrl}`}),s&&!o&&a&&r(`span`,{className:`text-[9px] text-foreground-subtle`,children:d(`common.auto`)})]})}})),{key:`actions`,header:``,align:`right`,nowrap:!0,render:e=>e.custom?r(M,{size:`sm`,variant:`ghost`,disabled:i,onClick:()=>u(e.baseUrl),"aria-label":d(`system.addressesCard.remove`,`Remove {{baseUrl}}`,{baseUrl:e.baseUrl}),title:d(`system.addressesCard.removeThisCustomAddressIts`,`Remove this custom address (its roles turn automatic)`),children:r(m,{className:`h-3 w-3`})}):null}],w=t===void 0?[]:it(t);return e(Pe,{children:[e(`div`,{className:`px-4 py-3 border-b border-border flex flex-col gap-2`,children:[e(`div`,{children:[r(`div`,{className:`text-sm font-semibold`,children:d(`system.addressesCard.addresses`,`Addresses`)}),r(`div`,{className:`text-xs text-foreground-subtle max-w-3xl`,children:d(`system.addressesCard.everyAddressThisHubIs`,`Every address this hub is reached at, detected or added by you. Tick what each one is used for.`)}),e(`details`,{className:`mt-1.5 text-xs max-w-3xl`,"data-testid":`address-roles-help`,children:[r(`summary`,{className:`cursor-pointer select-none text-foreground-subtle hover:text-foreground`,children:d(`system.addressesCard.whatAreRoles`,`What are roles?`)}),r(`dl`,{className:`mt-1.5 grid grid-cols-[auto_1fr] gap-x-3 gap-y-1`,children:q.map(t=>e(`div`,{className:`contents`,children:[r(`dt`,{className:`font-medium`,children:t.title}),r(`dd`,{className:`text-foreground-subtle`,children:t.help})]},t.role))}),r(`p`,{className:`mt-1.5 text-foreground-subtle`,children:nt})]})]}),w.length>0&&r(`div`,{className:`grid grid-cols-[auto_1fr_auto] gap-x-3 gap-y-1 items-baseline text-xs`,"data-testid":`address-roles-summary`,children:w.map(t=>e(`div`,{className:`contents`,children:[r(`span`,{className:`text-foreground-subtle`,children:t.title}),e(`span`,{className:`font-mono break-all`,"data-testid":`address-role-${t.role}`,children:[t.inUse,r(`span`,{className:`ml-1.5 font-sans text-foreground-subtle`,children:t.automatic?d(`system.addressesCard.automatic`,`(automatic)`):d(`system.addressesCard.setByYou`,`(set by you)`)})]}),t.automatic?r(`span`,{}):r(M,{size:`sm`,variant:`secondary`,disabled:i,onClick:()=>s({role:t.role,baseUrl:null,enabled:!1}),children:d(`system.addressesCard.useAutomatic`,`Use automatic`)})]},t.role))}),b!==null&&e(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-xs flex flex-wrap items-center gap-2`,children:[r(h,{className:`h-3.5 w-3.5 text-amber-600`}),r(`span`,{className:`flex-1 min-w-[220px]`,children:b.reason}),r(M,{size:`sm`,variant:`secondary`,onClick:()=>{s({...b.input,acceptInsecureHttp:!0}),x(null)},children:d(`system.addressesCard.useHttpAnyway`,`Use http anyway`)}),r(M,{size:`sm`,variant:`ghost`,onClick:()=>x(null),children:d(`common.cancel`,`Cancel`)})]}),o!==null&&r(`div`,{className:`text-[11px] text-red-600 dark:text-red-400`,role:`alert`,children:o})]}),r(de,{columns:ee,rows:t?.rows??[],rowKey:e=>`${e.kind}-${e.baseUrl}`,minWidthPx:760,bordered:!1,emptyMessage:n?d(`common.loading`,`Loading…`):d(`system.addressesCard.noAddressesAvailable`,`No addresses available.`),rowClassName:e=>e.plausible?void 0:`opacity-80`}),e(`div`,{className:`px-4 py-3 border-t border-border flex flex-wrap items-start gap-2`,children:[e(`div`,{className:`flex-1 min-w-[220px]`,children:[r(De,{value:f,onChange:e=>{p(e.target.value),y(null)},placeholder:`https://cams.example.com or https://192.0.2.20:4443`,"aria-label":d(`system.addressesCard.customAddress`,`Custom address`),disabled:i}),v!==null&&r(`div`,{className:`mt-1 text-[11px] text-red-600 dark:text-red-400`,children:v})]}),r(`div`,{className:`w-48`,children:r(De,{value:g,onChange:e=>_(e.target.value),placeholder:d(`system.addressesCard.labelOptional`,`Label (optional)`),"aria-label":d(`system.addressesCard.customAddressLabel`,`Custom address label`),maxLength:80,disabled:i})}),e(M,{size:`sm`,variant:`secondary`,disabled:i||f.trim()===``,onClick:S,children:[r(l,{className:`h-3 w-3`}),d(`system.addressesCard.addCustomAddress`,`Add custom address`)]})]})]})}o();function st(){let{t:n}=I(),o=s(),c=()=>{o.invalidateQueries({queryKey:[[`localNetwork`]]})},l=ye(void 0,{refetchInterval:3e4}),u=ue(void 0),d=Se({onSuccess:c}),p=he({onSuccess:e=>{w(e.addresses),c()}}),m=t(()=>l.data?.interfaces??[],[l.data]),h=Fe({scheme:typeof window<`u`&&window.location.protocol===`https:`?`https`:`http`},{refetchInterval:3e4}),g=me({onSuccess:c}),v=_e({onSuccess:c}),y=pe({onSuccess:c}),b=g.error?.message??v.error?.message??y.error?.message??null,S=g.isPending||v.isPending||y.isPending,[C,w]=a([]),[T,te]=a(!1);i(()=>{!T&&u.data&&(w(u.data.addresses),te(!0))},[u.data,T]);let E=u.data?.addresses??[],D=t(()=>{if(C.length!==E.length)return!0;let e=[...C].toSorted(),t=[...E].toSorted();return e.some((e,n)=>e!==t[n])},[C,E]);return e(z,{embedded:!0,children:[e(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[r(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:n(`system.networkAddresses.pinWhichHostInterfacesExist`,`Pin which host interfaces exist, then tick what each address is used for. Add a custom address when this hub is reached at one it cannot detect.`)}),r(`div`,{className:`flex items-center gap-2 shrink-0`,children:e(M,{size:`sm`,variant:`secondary`,onClick:()=>{l.refetch(),u.refetch(),h.refetch()},disabled:l.isLoading,children:[r(ne,{className:`h-3 w-3 ${l.isLoading?`animate-spin`:``}`}),n(`common.refresh`,`Refresh`)]})})]}),r(Ne,{headingId:`network-allowed-addresses`,title:n(`system.networkAddresses.allowedAddresses`,`Allowed addresses`),actions:e(`div`,{className:`flex flex-wrap items-center gap-1`,children:[e(M,{size:`sm`,variant:`secondary`,onClick:()=>p.mutate(void 0),disabled:p.isPending||d.isPending,title:n(`system.networkAddresses.reRunTheAutoDetection`,`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`),children:[r(_,{className:`h-3 w-3`}),p.isPending?n(`system.networkAddresses.detecting`,`Detecting…`):n(`system.networkAddresses.bestMatch`,`Best match`)]}),e(M,{size:`sm`,variant:`secondary`,onClick:()=>{w([])},disabled:C.length===0||d.isPending,children:[r(x,{className:`h-3 w-3`}),n(`system.networkAddresses.clear`,`Clear`)]}),D&&r(M,{size:`sm`,variant:`secondary`,onClick:()=>{w(E)},disabled:d.isPending,children:n(`system.networkAddresses.discard`,`Discard`)}),e(M,{size:`sm`,variant:`primary`,onClick:()=>{d.mutate({addresses:[...C]})},disabled:!D||d.isPending,children:[r(ee,{className:`h-3 w-3`}),d.isPending?n(`system.networkAddresses.saving`,`Saving…`):n(`common.save`,`Save`)]})]}),children:e(`div`,{className:f,children:[r(`p`,{className:`mb-3 text-xs text-foreground-subtle`,children:C.length===0?n(`system.networkAddresses.autoEveryNonLoopbackNon`,`Auto — every non-loopback / non-link-local interface participates.`):n(`system.networkAddresses.pinned`,`{{value1}} pinned`,{value1:String(C.length)})}),r(tt,{mode:`multiple`,interfaces:m,value:C,onChange:w,disabled:d.isPending,emptyMessage:l.isLoading?n(`system.networkAddresses.loadingInterfaces`,`Loading interfaces…`):n(`system.networkAddresses.noInterfacesDetected`,`No interfaces detected.`)})]})}),r(ot,{book:h.data,loading:h.isLoading,saving:S,error:b,onSetRole:e=>g.mutate({...e}),onAdd:(e,t)=>v.mutate({baseUrl:e,label:t}),onRemove:e=>y.mutate({baseUrl:e})})]})}o();var ct={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},Y=5e3,X=`mesh-network`,lt=3e4,ut={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function dt(){let{t:e}=I(),n=N({capName:`mesh-network`},{refetchInterval:Y}),i=j(void 0,{refetchInterval:Y}),a=t(()=>U(i.data??[]),[i.data]),o=t(()=>(n.data??[]).map(e=>({addonId:e.addonId,displayName:a.get(e.addonId)??e.addonId,isActive:e.isActive})),[n.data,a]),s=[{id:X,label:e(`system.meshNetworks.meshNetworks`,`Mesh networks`),install:{capability:X,label:e(`system.meshNetworks.addMesh`,`Add mesh`)},entries:o.map(t=>({id:t.addonId,name:t.displayName,fallbackIcon:u,...H(t.isActive),render:()=>r(B,{addonId:t.addonId,displayName:t.displayName,capName:X,isActive:t.isActive,badges:r(ft,{addonId:t.addonId}),primaryAction:r(pt,{addonId:t.addonId}),panels:[{id:`status`,title:e(`system.meshNetworks.status`,`Status`),icon:k,content:r(mt,{addonId:t.addonId})}]})}))}];return r(V,{embedded:!0,icon:k,title:e(`system.meshNetworks.meshNetworks2`,`Mesh Networks`),subtitle:e(`system.meshNetworks.privateVpnMeshesThatConnect`,`Private VPN meshes that connect CamStack to your other devices (Tailscale, Headscale, …). Each provider can also expose this hub publicly via its ingress (Tailscale Funnel).`),groups:s,isLoading:n.isLoading,emptyTitle:e(`system.meshNetworks.noMeshNetworkProvidersInstalled`,`No mesh-network providers installed`),emptyDescription:e(`system.meshNetworks.installAMeshAddonE`,`Install a mesh addon (e.g. @camstack/addon-tailscale) to join this hub into a private VPN mesh.`)})}function Z(e){let{data:t,isLoading:n}=ge({addonId:e},{refetchInterval:Y,retry:!1}),r=t?oe.safeParse(t):null;return{status:r?.success?r.data:ut,isLoading:n}}function ft({addonId:t}){let{t:n}=I(),{status:i}=Z(t);return e(c,{children:[r(P,{variant:i.joined?`success`:`default`,className:He,children:i.joined?n(`system.meshNetworks.joined`,`Joined`):n(`system.meshNetworks.notJoined`,`Not joined`)}),i.joined&&r(P,{className:`text-[10px]`,children:n(`common.peers`,{count:i.peerCount})})]})}function pt({addonId:t}){let{t:i}=I(),o=s(),[l,u]=a(!1),[d,f]=a(null),p=E(),{status:m}=Z(t),h=n(()=>{o.invalidateQueries({queryKey:[[`meshNetwork`]]})},[o]),g=Oe(),_=le({onSuccess:h}),v=je({onSuccess:h}),y=n(async()=>{u(!0);let e={cancelled:!1};f(e);try{let n=await g.mutateAsync({addonId:t});if(e.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!e.cancelled&&(await bt(2e3),!e.cancelled);){let e=await p.trpcClient.meshNetwork.getStatus.query({addonId:t}).catch(()=>null),n=e?oe.safeParse(e):null;if(n?.success&&n.data.joined){h();break}if(Date.now()-r>6e5)break}}finally{u(!1),f(null)}},[t,h,g,p]),b=n(()=>{d&&(d.cancelled=!0),u(!1),f(null)},[d]);return r(c,{children:m.joined?e(c,{children:[e(M,{size:`sm`,variant:`secondary`,disabled:_.isPending,onClick:()=>_.mutate({addonId:t}),children:[_.isPending?r(O,{className:`h-3 w-3 animate-spin`}):r(se,{className:`h-3 w-3`}),i(`system.meshNetworks.disconnect`,`Disconnect`)]}),e(M,{size:`sm`,variant:`ghost`,disabled:v.isPending,onClick:()=>v.mutate({addonId:t}),children:[v.isPending?r(O,{className:`h-3 w-3 animate-spin`}):r(D,{className:`h-3 w-3`}),i(`system.meshNetworks.logOut`,`Log out`)]})]}):l?e(M,{size:`sm`,variant:`ghost`,onClick:b,children:[r(S,{className:`h-3 w-3 mr-1`}),` `,i(`common.cancel`)]}):e(c,{children:[e(M,{size:`sm`,variant:`primary`,onClick:()=>void y(),children:[r(ce,{className:`h-3 w-3`}),i(`system.meshNetworks.connect`,`Connect`)]}),e(M,{size:`sm`,variant:`ghost`,disabled:v.isPending,onClick:()=>v.mutate({addonId:t}),children:[v.isPending?r(O,{className:`h-3 w-3 animate-spin`}):r(D,{className:`h-3 w-3`}),i(`system.meshNetworks.logOut`,`Log out`)]})]})})}function mt({addonId:t}){let{t:n}=I(),{status:i}=Z(t),a=Te({addonId:t},{refetchInterval:lt,retry:!1});return e(`div`,{className:`rounded-lg border border-border bg-surface`,children:[e(`div`,{className:`space-y-4 p-2 sm:p-4`,children:[i.error&&r(fe,{message:i.error}),r(ht,{status:i}),i.endpoints.length>0&&e(`div`,{className:`space-y-1.5`,children:[r(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:n(`system.meshNetworks.endpoints`,`Endpoints`)}),i.endpoints.map(t=>e(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[e(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${ct[t.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[t.scope===`public`?r(A,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,t.label]}),e(`a`,{href:t.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-emerald-700 dark:text-emerald-300 hover:underline break-all flex items-center gap-1`,children:[r(v,{className:`h-3 w-3 shrink-0`}),t.url]})]},t.id))]})]}),r(`div`,{className:`border-t border-border`,children:r(_t,{peers:a.data?.peers??[],loading:a.isLoading})})]})}function ht({status:t}){let{t:n}=I();return r(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-1.5`,children:[{label:n(`system.meshNetworks.tenant`,`Tenant`),value:t.tenantName||`—`},{label:n(`system.meshNetworks.user`,`User`),value:t.userLogin??`—`},{label:n(`system.meshNetworks.controlPlane`,`Control plane`),value:t.controlPlaneUrl||`—`},{label:n(`system.meshNetworks.meshIp`,`Mesh IP`),value:t.meshIp||`—`,mono:!0},{label:n(`system.meshNetworks.magicdns`,`MagicDNS`),value:t.magicDnsHostname||`—`,mono:!0},{label:n(`system.meshNetworks.dnsSuffix`,`DNS suffix`),value:t.magicDnsSuffix||`—`,mono:!0},{label:n(`system.meshNetworks.peers`,`Peers`),value:String(t.peerCount)},{label:n(`system.meshNetworks.keyExpiry`,`Key expiry`),value:t.keyExpiry?gt(t.keyExpiry):`—`}].map(t=>e(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[r(`span`,{className:`text-foreground-subtle shrink-0`,children:t.label}),r(`span`,{className:`text-foreground truncate ${t.mono?`font-mono`:``}`,children:t.value})]},t.label))})}function gt(e){let t=e-Date.now();if(t<0)return F.t(`system.meshNetworks.expiredAgo`,{when:Q(e)});let n=Math.floor(t/864e5);if(n>60)return new Date(e).toLocaleDateString();if(n>1)return F.t(`system.meshNetworks.expiryDays`,{count:n});let r=Math.floor(t/36e5);return r>1?F.t(`system.meshNetworks.expiryHours`,{count:r}):F.t(`system.meshNetworks.expiryMin`,{count:Math.max(1,Math.floor(t/6e4))})}function _t({peers:i,loading:a}){let{t:o}=I(),s=t(()=>i.map(e=>({...e,_id:e.id})),[i]),c=n(e=>{e&&navigator.clipboard?.writeText(e)},[]),l=t(()=>[{key:`hostname`,header:o(`system.meshNetworks.hostname`,`Hostname`),render:t=>e(`div`,{className:`flex flex-col`,children:[e(`div`,{className:`flex items-center gap-1.5`,children:[r(`span`,{className:`font-medium text-foreground`,children:t.hostname||o(`system.meshNetworks.unknown`,`(unknown)`)}),t.isSelf&&r(P,{variant:`info`,children:o(`common.self`)}),t.exitNodeOption&&r(P,{variant:`warning`,children:`exit-node`})]}),t.userLogin&&r(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:t.userLogin})]})},{key:`magicDns`,header:o(`system.meshNetworks.magicdns`,`MagicDNS`),render:t=>t.magicDns?e(`div`,{className:`flex items-center gap-1`,children:[r(`span`,{className:`font-mono text-xs truncate`,children:t.magicDns}),r(`button`,{onClick:()=>c(t.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":o(`system.meshNetworks.copyMagicdns`,`Copy MagicDNS`),children:r(g,{className:`h-3 w-3 text-foreground-subtle`})})]}):r(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:t=>{let n=t.addresses[0]??``;return n?e(`div`,{className:`flex items-center gap-1`,children:[r(`span`,{className:`font-mono text-xs`,children:n}),r(`button`,{onClick:()=>c(n),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":o(`system.meshNetworks.copyIp`,`Copy IP`),children:r(g,{className:`h-3 w-3 text-foreground-subtle`})})]}):r(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:o(`system.meshNetworks.connection`,`Connection`),render:t=>e(`div`,{className:`flex items-center gap-1.5`,children:[r(P,{variant:vt(t.connection),children:t.connection}),t.relay&&r(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:t.relay})]})},{key:`routes`,header:o(`system.meshNetworks.routes`,`Routes`),render:e=>e.advertisedRoutes.length>0?r(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):r(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:o(`system.meshNetworks.txRx`,`TX / RX`),render:t=>e(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,yt(t.txBytes),` · ↓ `,yt(t.rxBytes)]})},{key:`lastSeen`,header:o(`system.meshNetworks.lastSeen`,`Last seen`),render:e=>r(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?Q(e.lastSeenMs):`—`})}],[c,o]);return a&&i.length===0?e(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[r(O,{className:`h-3 w-3 animate-spin inline mr-1`}),` `,o(`systemPage.meshNetworks.loadingPeers`)]}):i.length===0?r(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:o(`system.meshNetworks.noPeersVisibleYourTailnet`,`No peers visible — your tailnet may be empty or the host is not joined.`)}):r(`div`,{className:`p-4`,children:r(de,{columns:l,rows:s,rowKey:e=>e._id,minWidthPx:820})})}function vt(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function yt(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)}MB`:`${(e/1024/1024/1024).toFixed(2)}GB`}function Q(e){let t=Date.now()-e;return t<6e4?F.t(`system.meshNetworks.justNow`):t<36e5?F.t(`system.meshNetworks.agoMin`,{count:Math.round(t/6e4)}):t<864e5?F.t(`system.meshNetworks.agoHour`,{count:Math.round(t/36e5)}):F.t(`system.meshNetworks.agoDay`,{count:Math.round(t/864e5)})}function bt(e){return new Promise(t=>setTimeout(t,e))}var $=`/system/identity?tab=certificates`;function xt(){let{t}=I();return r(z,{embedded:!0,children:e(`div`,{className:p,children:[r(Ve,{nodeId:`hub`,addonIds:[`local-network`],level:`global`,title:t(`system.localAccess.lanHttp`,`LAN HTTP`),description:t(`system.localAccess.nativeAppsOnThisWi`,`Native apps on this Wi-Fi use http:// and skip the private certificate. The tunnel and this admin UI stay on HTTPS.`)}),e(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`https-certificate-hint`,children:[t(`system.localAccess.certificateMoved`,`The HTTPS certificate and the local CA are managed under`),` `,r(ze,{className:`underline`,to:$,children:t(`system.localAccess.certificateMovedLink`,`Identity → Certificates`)}),`.`]})]})})}o();function St({value:n,onChange:i}){let{t:a}=I(),{data:o}=ve({isCamera:!0,projection:`slim`}),s=t(()=>o===void 0?[{value:``,label:a(`system.networkDiagnostics.loadingCameras`,`Loading cameras…`)}]:o.length===0?[{value:``,label:a(`system.networkDiagnostics.noCameras`,`No cameras`)}]:[{value:``,label:a(`system.networkDiagnostics.pickACamera`,`Pick a camera`)},...o.toSorted((e,t)=>e.name.localeCompare(t.name)).map(e=>({value:String(e.id),label:`${e.name} (#${String(e.id)})`}))],[o,a]);return e(`label`,{className:`flex min-w-0 flex-col gap-1`,children:[r(`span`,{className:`text-[11px] text-foreground-subtle`,children:a(`system.networkDiagnostics.camera`,`Camera`)}),r(Ee,{value:n===null?``:String(n),disabled:o===void 0||o.length===0,onChange:e=>i(e.target.value===``?null:Number(e.target.value)),options:s})]})}function Ct(){let t=E(),[i,o]=a(null);return r(z,{embedded:!0,children:e(`div`,{className:p,"data-testid":`network-diagnostics`,children:[r(we,{loadServers:n(async()=>t.trpcClient.turnProvider.getTurnServers.query(),[t])}),r(Me,{trpc:t.trpcClient,serverUrl:b(),deviceId:i,cameraField:r(St,{value:i,onChange:o})})]})})}var wt=[`certificate`,`certificates`,`https`];function Tt(){let{t:e}=I(),[t]=Re();if(wt.includes(t.get(`tab`)??``))return r(Le,{to:$,replace:!0});let n=Ie(`/system/network`,{t:e,isAdmin:!0})??{icon:A,title:e(`system.network`,`Network`)};return r(Be,{icon:n.icon,title:n.title,defaultSection:`addresses`,sectionsLabel:`${n.title} sections`,sections:[{id:`local-access`,label:e(`systemPage.network.localAccess`,`Local access`),content:r(xt,{})},{id:`addresses`,label:e(`systemPage.network.networkAddresses`,`Network Addresses`),content:r(st,{})},{id:L.remoteAccess.tab,label:e(`systemPage.network.remoteAccess`,`Remote Access`),content:r(We,{}),ownedParams:R},{id:L.mesh.tab,label:e(`systemPage.network.meshNetworks`,`Mesh Networks`),content:r(dt,{}),ownedParams:R},{id:L.turn.tab,label:e(`systemPage.network.turnServers`,`TURN Servers`),content:r(Xe,{}),ownedParams:R},{id:`diagnostics`,label:e(`systemPage.network.diagnostics`,`Diagnostics`),content:r(Ct,{})}]})}export{Tt as NetworkPage};