@camstack/addon-admin-ui 1.2.455 → 1.2.457
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.
- package/dist/assets/{AddonAssetIcon-BYNabO6z.js → AddonAssetIcon-BOcwQMt3.js} +1 -1
- package/dist/assets/Addons-BrsHM2rE.js +4 -0
- package/dist/assets/{AdminPage-RJcN6Anu.js → AdminPage-0E8EpSO9.js} +1 -1
- package/dist/assets/{AdminSectionedPage-DvK84QvU.js → AdminSectionedPage-CxodN1sn.js} +1 -1
- package/dist/assets/AiProfiles-EJziTK6H.js +3 -0
- package/dist/assets/{BrokerForm-Bua9uB8w.js → BrokerForm-Dbs6DDhN.js} +1 -1
- package/dist/assets/Build-G3WNIoIu.js +40 -0
- package/dist/assets/{Calendars-ClbErr_S.js → Calendars-DwIn1aCE.js} +1 -1
- package/dist/assets/{Cluster-DmQM6H_p.js → Cluster-FzZaIb80.js} +1 -1
- package/dist/assets/ClusterStepModel-BKwbYUSr.js +1 -0
- package/dist/assets/CompositionEditor-Du0918m6.js +1 -0
- package/dist/assets/{CompositionEditorPage-Bicamzo6.js → CompositionEditorPage-I6-ghm-F.js} +1 -1
- package/dist/assets/Data-CWXYjuUH.js +2 -0
- package/dist/assets/{DeviceDetail-4Vysat6s.js → DeviceDetail-DEN9C3es.js} +2 -2
- package/dist/assets/{DeviceDoActionFields-lfq-_s87.js → DeviceDoActionFields-XK5u9sG-.js} +1 -1
- package/dist/assets/{Devices-BCTvzI3Z.js → Devices-CPoElWdX.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-BzklJ0a5.js → EmbedPlayerPage-CwqeH_Vp.js} +1 -1
- package/dist/assets/History-146ywVRO.js +1 -0
- package/dist/assets/Identity-NsWnwCVn.js +1 -0
- package/dist/assets/IntegrationDetail-CUffTwqo.js +1 -0
- package/dist/assets/{IntegrationHub-DHgjRUIy.js → IntegrationHub-DAndpOVJ.js} +1 -1
- package/dist/assets/{Integrations-CQ3JYsSK.js → Integrations-DaNoA1oi.js} +1 -1
- package/dist/assets/Integrations-DrSNiPXr.js +1 -0
- package/dist/assets/Library-BMJeDfUP.js +1 -0
- package/dist/assets/Locations-DpWQPPRR.js +3 -0
- package/dist/assets/{Logs-QE5m7m6F.js → Logs-ClfIrCg_.js} +1 -1
- package/dist/assets/{MaskShapeCanvas-C7r7jgVz.js → MaskShapeCanvas-BACSOVPv.js} +1 -1
- package/dist/assets/{MotionZonesSettings-qCWVDb2U.js → MotionZonesSettings-C-BWiqKl.js} +1 -1
- package/dist/assets/MyAccess-B2mddc8z.js +2 -0
- package/dist/assets/{Network-CJOuBFOQ.js → Network-CCpscaUS.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-CTmPFs3s.js → NodeAddonsSettingsPanel-J8GvbAOS.js} +1 -1
- package/dist/assets/Notifications-CJvDmENV.js +1 -0
- package/dist/assets/{PrivacyMaskSettings-CBAaR7ZM.js → PrivacyMaskSettings-_hgbaRHe.js} +1 -1
- package/dist/assets/Recordings-CmuOayrH.js +1 -0
- package/dist/assets/{ScanNetworkModal-CiOVqs0H.js → ScanNetworkModal-CHpDtEMN.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-BbPp4N2N.js → SceneMonitorEditor-DNX5LjxD.js} +1 -1
- package/dist/assets/SessionsList-CO2JCtUA.js +2 -0
- package/dist/assets/{Showroom-or-UvZ6_.js → Showroom-C1Cx5rmM.js} +1 -1
- package/dist/assets/{System-DSx33GfC.js → System-8QdXWXlv.js} +1 -1
- package/dist/assets/{Terminal-B3oKTozT.js → Terminal-D-QqW5OC.js} +5 -5
- package/dist/assets/{Viewer-CpC1lsu6.js → Viewer-DEkhIs_o.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-cERw53qT.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DXRH_g5-.js} +1 -1
- package/dist/assets/{addon-icons-context-BVO6QLZm.js → addon-icons-context-r4-8qNuL.js} +1 -1
- package/dist/assets/{archive-jvBvOOAa.js → archive-CHNksUXE.js} +1 -1
- package/dist/assets/{authed-media-DubLoRPM.js → authed-media-CLfNNAcR.js} +1 -1
- package/dist/assets/{bell-off-h_oVtaH_.js → bell-off-BQUuLgGa.js} +1 -1
- package/dist/assets/{board-model-lfov_Io5.js → board-model-CCKjMnih.js} +1 -1
- package/dist/assets/{boxes-CqZzX6pS.js → boxes-OM3WXXCF.js} +1 -1
- package/dist/assets/circle-slash-B-qX3Tzf.js +1 -0
- package/dist/assets/client-Tf7DwHzR.js +358 -0
- package/dist/assets/{cloud-upload-_iPugQ2o.js → cloud-upload-DnQzN7Zu.js} +1 -1
- package/dist/assets/crop-BXCCBrRT.js +1 -0
- package/dist/assets/{device-integration-icon-CFPzExgG.js → device-integration-icon-T6DuiFIe.js} +1 -1
- package/dist/assets/device-picker-model-CJDjbyFR.js +1 -0
- package/dist/assets/dist-COc-M7x5.js +358 -0
- package/dist/assets/{dist-BYCY5p_8.js → dist-DWpE4F9Y.js} +1 -1
- package/dist/assets/{eraser-RaYHha2L.js → eraser-2zvTICay.js} +1 -1
- package/dist/assets/{hard-drive-download-DobqoKaY.js → hard-drive-download-BuPae4i9.js} +1 -1
- package/dist/assets/{hostInit-Bk_2heUx.js → hostInit-B0H8YgMs.js} +1 -1
- package/dist/assets/i18n-dPXh_JKN.js +1 -0
- package/dist/assets/{icons-DzYBV1xx.js → icons-Bf1g4TTU.js} +1 -1
- package/dist/assets/index-BGRimCPP.css +2 -0
- package/dist/assets/index-k7RW-84l.js +4 -0
- package/dist/assets/{key-round-CNTVmlFS.js → key-round-PVl1EIeU.js} +1 -1
- package/dist/assets/{key-Dtkr3Nze.js → key-y1dQIrgn.js} +1 -1
- package/dist/assets/{layers-DGhugmpj.js → layers-BvTBL45e.js} +1 -1
- package/dist/assets/{linked-devices-model-BpGYuse3.js → linked-devices-model-NEAloVak.js} +1 -1
- package/dist/assets/{list-ordered-DR6Fc-kF.js → list-ordered-Cy6LNkX7.js} +1 -1
- package/dist/assets/{location-owned-usage-CScwnhi4.js → location-owned-usage-COJFqP2Z.js} +1 -1
- package/dist/assets/{log-in-B8yxXP-a.js → log-in-C8bG6uHT.js} +1 -1
- package/dist/assets/{memory-stick-DEd977DV.js → memory-stick-DgCbrom_.js} +1 -1
- package/dist/assets/{message-square-plus-czVBdg8z.js → message-square-plus-T2Q-JaNP.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-ffeb770c.js → mf-entry-bootstrap-0-fa03047b.js} +2 -2
- package/dist/assets/{mic-off-CuWOtzwH.js → mic-off-CQXTB132.js} +1 -1
- package/dist/assets/{monitor-off-D1_Vx25v.js → monitor-off-CvP-Xwqs.js} +1 -1
- package/dist/assets/{monitor-smartphone-EKfsOXbl.js → monitor-smartphone-DgPyh0bq.js} +1 -1
- package/dist/assets/mount-CJDjbyFR.js +1 -0
- package/dist/assets/notification-schedule-field-DXLce27m.js +1 -0
- package/dist/assets/{player-overlays-D98Lvll4.js → player-overlays-DTcu3p6k.js} +1 -1
- package/dist/assets/{recycle-BDYRIJo4.js → recycle-BgfATMDb.js} +1 -1
- package/dist/assets/remoteEntry-T1NwEQgU.js +1 -0
- package/dist/assets/{scan-eye-BF9NJNXB.js → scan-eye-Cw7uLDDg.js} +1 -1
- package/dist/assets/{scissors-BNz1ybHC.js → scissors-GZwoMkJz.js} +1 -1
- package/dist/assets/{search-x-DOr7Uth6.js → search-x-mGDaYxQw.js} +1 -1
- package/dist/assets/{send-BfMMesXE.js → send-B4zTG8IX.js} +1 -1
- package/dist/assets/{settings-2-CpTdKS6A.js → settings-2-7MkaO5_9.js} +1 -1
- package/dist/assets/{speaker-DiDPOBlm.js → speaker-iZgcW4qe.js} +1 -1
- package/dist/assets/src-CxF5mieK.js +67 -0
- package/dist/assets/{timer-reset-Dw4WCNKZ.js → timer-reset-CZOKA6Qu.js} +1 -1
- package/dist/assets/{ungroup-CLr3vekJ.js → ungroup-CmTgkman.js} +1 -1
- package/dist/assets/{unlink-pUA2UXXM.js → unlink-DgTv7GBL.js} +1 -1
- package/dist/assets/{usb-wx8HtogA.js → usb-CDpFB3qV.js} +1 -1
- package/dist/assets/{use-scenes-feed-DF4B8gD1.js → use-scenes-feed-Xf26vjq3.js} +1 -1
- package/dist/assets/{use-stationary-objects-CPcayJEy.js → use-stationary-objects-piZ9a4go.js} +1 -1
- package/dist/assets/useEventInvalidation-CJDjbyFR.js +1 -0
- package/dist/assets/{useNodeUrlSelection-Dm8ObY95.js → useNodeUrlSelection-Bmr7pzZ8.js} +1 -1
- package/dist/assets/user-round-XpdQk1Uf.js +1 -0
- package/dist/assets/{user-x-CzTAjxJ0.js → user-x-DG-dacDQ.js} +1 -1
- package/dist/assets/{video-a3E1zR0a.js → video-DSWn6X4v.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-C-d2SXqo.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-9bgJ3bqj.js} +2 -2
- package/dist/index.html +30 -11
- package/dist/server/addon.js +6817 -1413
- package/package.json +1 -1
- package/dist/assets/Addons-B7UpJkGs.js +0 -4
- package/dist/assets/AiProfiles-WyUbwQQi.js +0 -3
- package/dist/assets/Build-w6vEia_c.js +0 -40
- package/dist/assets/ClusterStepModel-hpdBn30Y.js +0 -1
- package/dist/assets/CompositionEditor-CpN510VP.js +0 -1
- package/dist/assets/Data-DoXqW90G.js +0 -2
- package/dist/assets/History-BYogPAEo.js +0 -1
- package/dist/assets/Identity-DtlH2M6Y.js +0 -1
- package/dist/assets/IntegrationDetail-B0PsG3wF.js +0 -1
- package/dist/assets/Integrations-DD48mmxj.js +0 -1
- package/dist/assets/Library-02NRO2CR.js +0 -1
- package/dist/assets/Locations-CUmRk0or.js +0 -3
- package/dist/assets/MyAccess-CIhAKN-2.js +0 -2
- package/dist/assets/Notifications-WPdPSM1o.js +0 -1
- package/dist/assets/Recordings-BeU7j2Jf.js +0 -1
- package/dist/assets/SessionsList-DTdwgdgY.js +0 -2
- package/dist/assets/circle-slash-DFnFtATu.js +0 -1
- package/dist/assets/client-Cj9cIFJV.js +0 -358
- package/dist/assets/crop-CesdRTv2.js +0 -1
- package/dist/assets/device-picker-model-CVKD2t0V.js +0 -1
- package/dist/assets/dist-o4U_Imrg.js +0 -358
- package/dist/assets/i18n-BuS8cl72.js +0 -1
- package/dist/assets/index-BuOqDa4D.css +0 -2
- package/dist/assets/index-CM1JjjBW.js +0 -4
- package/dist/assets/mount-CVKD2t0V.js +0 -1
- package/dist/assets/notification-schedule-field-i8rEjVxQ.js +0 -1
- package/dist/assets/remoteEntry-BtmyK6Gf.js +0 -1
- package/dist/assets/src-MJ2k3G6o.js +0 -67
- package/dist/assets/useEventInvalidation-CVKD2t0V.js +0 -1
- package/dist/assets/user-round-vZzgqRIQ.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{$ as e,G as t,S as n,i as r,x as i}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Ci as a,dt as o,hn as s,ot as c,sa as l,yr as u}from"./player-overlays-D98Lvll4.js";import{Gn as d,di as f}from"./client-Cj9cIFJV.js";import{A as p,Ar as m,D as h,E as g,Gu as _,M as v,O as y,S as b,T as x,Ya as S,_ as C,_n as w,b as ee,d as T,f as E,fr as D,g as te,gn as O,gr as k,hr as A,j,jr as ne,k as re,m as M,mn as N,mr as P,on as F,p as I,pr as L,sn as R,u as z,ur as B,v as V,w as ie,wl as ae,x as H,y as U}from"./src-MJ2k3G6o.js";import{t as W}from"./useTranslation-D3Is_4B6.js";import{nt as G}from"./index-CM1JjjBW.js";import{t as K}from"./AdminPage-RJcN6Anu.js";e();function q(e,t){return e.scope===``?e.displayName:`${e.displayName} · ${t?.(e)??e.scope}`}function oe(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:U(i),ref:i,info:e,subjectName:t.name,location:t.location??``,nodeId:``,metric:q(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:U(i),ref:i,info:t,subjectName:e.name,location:``,nodeId:e.id,metric:q(t,n)})}return r}function se(e){return[e.subjectName,e.location,e.metric,e.info.key,e.info.unit??``,e.nodeId].join(` `)}var ce=[`energy`,`temperatures`,`nodes`,`storage`],le=new Set([`cap:temperature-sensor.celsius`,`cap:climate-control.currentTemp`]),J=[`addon:metrics-native/node-cpu-percent`,`addon:metrics-native/node-memory-percent`],ue=`addon:storage-orchestrator/location-used-percent`;function de(e,t){let n=(e,n)=>{let r=t.filter(e);return V((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`&&le.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`&&J.includes(e.info.key)&&e.info.scope===``,(e,t)=>J.indexOf(e.info.key)-J.indexOf(t.info.key)||e.subjectName.localeCompare(t.subjectName));case`storage`:return n(e=>e.ref.subject.kind===`node`&&e.info.key===ue)}}function fe(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[],i=[],a=[],o=[];for(let t of V(e)){let e=n.get(U(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 Y(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 X=`history-page`;function Z(e){return`${e.subjectName} · ${e.metric}`}function pe({part:e,window:r}){let{t:o}=W(),s=l(),c=t(()=>[...e.lines,...e.states,...e.energy],[e]),u=I(t(()=>c.map(e=>Y(e.ref)),[c]),r,!1),d=e=>u.status===`ok`?u.data.current.get(E(Y(e.ref))):void 0,f=e=>{let t=d(e);return t?.ok?t.result:void 0};if(c.length===0)return i(L,{icon:a,title:o(`history.page.emptyTitle`,`Pick series to compare`),description:o(`history.page.emptyHint`,`Choose up to 24 series on the left, or start from a panel above.`)});if(u.status===`error`)return i(D,{title:o(`history.page.readFailed`,`History could not be read`),message:u.error});let p=u.status===`pending`,m=c.map(e=>({c:e,e:d(e)})).filter(e=>e.e?.ok===!1),h=e.lines.map((e,t)=>{let n=f(e),i=x(e.info,n,r.from);return{id:e.id,label:Z(e),unit:e.info.unit,colorIndex:t,points:i.points,gapMs:i.gapMs,interpolation:i.held&&n?.resolution===`raw`?`step`:`linear`}}),_=e.states.map((e,t)=>{let n=g(e.info,f(e),r.from,r.to),i=b(e.info.key,s);return{id:e.id,label:Z(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`?i.on:i.off:void 0}}),y=e.energy.map(e=>({c:e,...ie(f(e))})),S=y[0]?.bucketMs??36e5,C=[...new Set(y.flatMap(e=>e.buckets.map(e=>e.t)))].sort((e,t)=>e-t).map(e=>({t:e,values:y.map(t=>t.buckets.find(t=>t.t===e)?.values[0]??null)}));return n(`div`,{className:`space-y-5 min-w-0`,children:[m.length>0&&i(D,{title:o(`history.page.someFailed`,`Some series could not be read`),message:m.map(e=>`${Z(e.c)}: ${e.e.error}`).join(` · `)}),h.length>0&&i(v,{title:o(`history.page.lines`,`Measurements`),series:h,range:r,height:260,syncKey:X,pending:p}),y.length>0&&i(B,{title:o(`history.page.energy`,`Energy`),layers:y.map((e,t)=>({id:e.c.id,label:e.c.subjectName,colorIndex:t})),buckets:C,bucketMs:S,range:r,unit:`kWh`,showTotal:!0,height:160,syncKey:X,pending:p}),_.length>0&&i(j,{title:_.length===1?_[0]?.label??``:o(`history.page.states`,`States`),rows:_,range:r,syncKey:X,pending:p})]})}e();var Q=`device`,me=`node`;function he({catalog:e,selected:r,onChange:a,loading:o}){let{t:s}=W(),c=F(e,{searchText:e=>[se(e)],facetGroups:[{id:`subject`,value:e=>e.ref.subject.kind===`device`?Q:me},{id:`room`,value:e=>e.location},{id:`unit`,value:e=>e.info.unit??``}]}),l=t(()=>[{key:`metric`,header:s(`history.picker.series`,`Series`),render:e=>n(`div`,{className:`min-w-0`,children:[i(`div`,{className:`truncate text-foreground`,children:e.metric}),i(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.location===``?e.subjectName:`${e.subjectName} · ${e.location}`})]}),sortValue:e=>`${e.subjectName} ${e.metric}`},{key:`unit`,header:s(`history.picker.unit`,`Unit`),render:e=>i(`span`,{className:`text-foreground-muted`,children:e.info.unit??`—`}),sortValue:e=>e.info.unit??``}],[s]),u=r.size>=24;return n(`div`,{className:`space-y-2 min-w-0`,children:[i(R,{state:c.state,facets:[],groups:[{...c.groups.find(e=>e.id===`subject`)??{id:`subject`,facets:[],selected:[]},label:s(`history.picker.subject`,`Source`),facetLabel:e=>e===Q?s(`history.picker.devices`,`Devices`):s(`history.picker.nodes`,`Nodes`)},{...c.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},{...c.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:c.setSearch,onToggleFacet:c.toggleFacet,onToggleGroupFacet:c.toggleGroupFacet,onClear:c.clear}),i(`p`,{className:`text-[10px] text-foreground-subtle`,"aria-live":`polite`,children:s(`history.picker.count`,`{{count}} of {{max}} selected`,{count:r.size,max:24})}),i(O,{columns:l,rows:c.rows,rowKey:e=>e.id,maxBodyHeight:w,pageSize:50,defaultSort:{columnKey:`metric`,dir:`asc`},emptyMessage:o?s(`history.picker.loading`,`Reading the series of every device…`):c.active?s(`history.picker.emptyFiltered`,`No series match these filters.`):s(`history.picker.empty`,`Nothing is recorded yet.`),selection:{selected:r,onChange:e=>{let t=[...e].filter(e=>r.has(e)),n=[...e].filter(e=>!r.has(e));a(new Set([...t,...n].slice(0,24)))},isSelectable:e=>r.has(e.id)||!u,rowLabel:e=>`${e.subjectName} · ${e.metric}`,pageLabel:s(`history.picker.selectPage`,`Select every series on this page`)}})]})}e();var ge=new Set([f.Hub,f.Container]),$=5*6e4;function _e(){let{t:e}=W(),r=P(`device-history`),[c,l]=G(),d=t(()=>V(c.getAll(`s`).flatMap(e=>{let t=te(e);return t===null?[]:[t]})),[c]),f=c.get(`window`),g=re(f)?f:`7d`,_=h(c.get(`range`)),v=(e,t,n)=>{let r=new URLSearchParams;for(let t of V(e))r.append(`s`,C(t));t!==`7d`&&r.set(`window`,t);let i=n===void 0?c.get(`range`):n;t===`custom`&&i&&r.set(`range`,i),l(r,{replace:!0})},b=ve(r===`present`),x=p(g,Date.now(),_),S=p(g,T(Date.now(),x.to-x.from),_),w=t(()=>fe(d,b.candidates),[d,b.candidates]),E=t(()=>new Set(d.map(U)),[d]),O=z(),j=ne(),F=m(),I=async()=>{let t=await j({title:e(`history.page.saveTitle`,`Save as panel`),label:e(`history.page.saveName`,`Panel name`),confirmLabel:e(`history.page.save`,`Save`)});t===null||t.trim()===``||await O.update(e=>ee(e,{id:`panel-${Date.now().toString(36)}`,name:t.trim().slice(0,80),window:g,selection:[...d]}))},R=async(t,n)=>{await F({title:e(`history.page.deleteTitle`,`Delete panel`),message:e(`history.page.deleteMessage`,`The panel "{{name}}" is removed from your account.`,{name:n}),confirmLabel:e(`history.page.delete`,`Delete`),variant:`danger`})&&await O.update(e=>H(e,t))},B=t=>t===`energy`?e(`history.panels.energy`,`Total energy`):t===`temperatures`?e(`history.panels.temperatures`,`Temperatures by room`):t===`nodes`?e(`history.panels.nodes`,`Cluster nodes`):e(`history.panels.storage`,`Storage locations`);return i(K,{icon:a,title:e(`history.page.title`,`History`),subtitle:e(`history.page.subtitle`,`What devices, nodes and storage recorded over time, side by side.`),actions:r===`present`?n(A,{size:`sm`,variant:`outline`,onClick:()=>void I(),disabled:d.length===0||!O.writable,children:[i(s,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),e(`history.page.saveTitle`,`Save as panel`)]}):void 0,children:r===`pending`?i(k,{className:`h-64 w-full`}):r===`unknown`?i(D,{title:e(`history.page.presenceUnknownTitle`,`Could not reach the hub`),message:e(`history.page.presenceUnknown`,`The hub did not say whether device history is installed. Try again in a moment.`)}):r===`absent`?i(L,{icon:u,title:e(`history.page.absentTitle`,`Device history is not running on this hub`),description:e(`history.page.absent`,`Nothing is recorded until the device-history system addon is enabled.`)}):n(`div`,{className:`space-y-3 sm:space-y-4`,children:[n(`div`,{className:`flex flex-wrap items-center gap-2`,role:`group`,"aria-label":e(`history.page.panels`,`Panels`),children:[ce.map(e=>i(A,{size:`sm`,variant:`outline`,disabled:b.status!==`ok`,onClick:()=>v(de(e,b.candidates),g),children:B(e)},e)),O.value.panels.map(t=>n(`span`,{className:`inline-flex items-center`,children:[i(A,{size:`sm`,variant:`secondary`,onClick:()=>v(t.selection,t.window,null),children:t.name}),i(A,{size:`sm`,variant:`ghost`,"aria-label":e(`history.page.deleteNamed`,`Delete panel {{name}}`,{name:t.name}),onClick:()=>void R(t.id,t.name),disabled:!O.writable,children:i(o,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})]},t.id))]}),n(`div`,{className:`grid grid-cols-1 gap-3 sm:gap-4 xl:grid-cols-5`,children:[i(`div`,{className:`min-w-0 xl:col-span-2`,children:i(N,{headingId:`history-picker`,title:e(`history.picker.title`,`Series`),children:i(`div`,{className:`p-2 sm:p-3`,children:b.status===`error`?i(D,{message:b.error}):i(he,{catalog:b.candidates,loading:b.status===`pending`,selected:E,onChange:e=>{let t=d.filter(t=>e.has(U(t))),n=b.candidates.filter(t=>e.has(t.id)&&!E.has(t.id)).map(e=>e.ref);v([...t,...n],g)}})})})}),i(`div`,{className:`min-w-0 xl:col-span-3`,children:i(N,{headingId:`history-overlay`,title:e(`history.page.overlay`,`Overlay`),actions:d.length>0?i(A,{size:`sm`,variant:`ghost`,onClick:()=>v([],g),children:e(`history.page.clear`,`Clear`)}):void 0,children:n(`div`,{className:`p-2 sm:p-3 space-y-3 min-w-0`,children:[i(M,{value:g,onChange:e=>v(d,e),custom:_,onCustomChange:e=>v(d,`custom`,y(e))}),b.status===`pending`&&d.length>0?i(k,{className:`h-64 w-full`}):i(pe,{part:w,window:S}),w.missing.length>0&&b.status===`ok`&&i(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`history.page.missing`,{count:w.missing.length,defaultValue_one:`{{count}} selected series is no longer recorded.`,defaultValue_other:`{{count}} selected series are no longer recorded.`})})]})})})]})]})})}function ve(e){let{t:n}=W(),i=n(`history.picker.wholeFrame`,`Whole frame`),a=c().trpcClient,o=S({projection:`slim`},{enabled:e,staleTime:$}),{nodes:s}=_(),l=t(()=>(o.data??[]).filter(e=>!ge.has(String(e.type))),[o.data]),u=r({queries:l.map(t=>({queryKey:[`device-history`,`listSeries`,t.id],queryFn:()=>a.deviceHistory.listSeries.query({deviceId:t.id}),enabled:e,staleTime:$}))}),f=r({queries:s.map(t=>({queryKey:[`device-history`,`listNodeSeries`,t.id],queryFn:()=>a.deviceHistory.listNodeSeries.query({forNodeId:t.id}),enabled:e,staleTime:$}))}),p=ae({},{enabled:e,staleTime:$}),m=t(()=>new Map((p?.data??[]).map(e=>[e.id,e.displayName])),[p?.data]),h=u.map(e=>e.data),g=f.map(e=>e.data),v=t(()=>oe(l.flatMap((e,t)=>{let n=h[t];return n===void 0?[]:[{device:{id:e.id,name:e.name,location:e.location??null},series:n}]}),s.flatMap((e,t)=>{let n=g[t];return n===void 0?[]:[{node:{id:e.id,name:e.name},series:n}]}),e=>{if(e.key!==`addon:pipeline-analytics/occupancy`)return m.get(e.scope)??e.scope;let{zoneId:t,className:n}=d(e.scope),r=t===``?i:t;return n===void 0?r:`${r} · ${n}`}),[l,s,m,[...u,...f].map(e=>e.dataUpdatedAt).join(`,`),i]);return o.status===`error`?{status:`error`,error:o.error.message,candidates:[]}:{status:o.status===`pending`||u.some(e=>e.isPending)||f.some(e=>e.isPending)?`pending`:`ok`,error:``,candidates:v}}export{_e as HistoryPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{$ as e,B as t,G as n,J as r,L as i,S as a,a as o,b as s,o as c,q as l,t as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{$t as f,D as p,Fn as m,Gi as h,It as g,Nt as _,Rr as v,Tt as y,Wr as b,an as x,bn as S,cn as C,dn as w,dt as T,kn as E,lr as D,mi as O,mr as k,or as A,ot as ee,pn as j,rr as M,sa as N,sn as P,xi as F,yi as I}from"./player-overlays-D98Lvll4.js";import{Gi as L,Ki as te,Wi as ne,a as R,c as z,o as re,s as ie}from"./client-Cj9cIFJV.js";import{i as ae,n as oe,r as se,t as ce}from"./key-Dtkr3Nze.js";import{d as B,l as V,s as le}from"./video-a3E1zR0a.js";import{t as ue}from"./key-round-CNTVmlFS.js";import{t as de}from"./monitor-smartphone-EKfsOXbl.js";import{t as fe}from"./unlink-pUA2UXXM.js";import{$n as pe,An as me,Ar as H,Au as he,Ct as ge,Dn as _e,Du as ve,Eu as ye,Nn as be,Ou as xe,Qn as Se,Rr as U,Tu as Ce,Xn as we,Xu as W,Ya as Te,_n as Ee,_u as De,bs as Oe,bu as ke,cn as Ae,ds as je,dt as Me,du as Ne,er as Pe,fr as G,fu as Fe,gn as Ie,gr as Le,gs as Re,gu as ze,hn as K,hr as q,hu as Be,ir as Ve,it as He,jn as Ue,jr as We,kn as Ge,ku as Ke,ln as qe,lt as Je,lu as Ye,mn as Xe,mu as Ze,nr as Qe,oi as $e,pr as et,ps as tt,pu as nt,qn as rt,rr as it,rt as at,si as ot,uu as st,vt as ct,vu as lt,wt as ut,ys as dt,yu as ft}from"./src-MJ2k3G6o.js";import{t as J}from"./i18n-BuS8cl72.js";import{t as Y}from"./useTranslation-D3Is_4B6.js";import{$ as pt,Q as mt,T as ht,V as gt,Z as _t,a as vt,d as yt,et as bt,i as xt,l as St,nt as Ct}from"./index-CM1JjjBW.js";import{t as wt}from"./AdminSectionedPage-DvK84QvU.js";import{t as Tt}from"./AdminPage-RJcN6Anu.js";import{A as Et,C as Dt,D as Ot,E as kt,O as X,S as At,T as jt,a as Mt,b as Nt,c as Pt,d as Ft,f as It,g as Lt,h as Rt,i as zt,k as Bt,l as Vt,m as Ht,n as Ut,o as Wt,p as Gt,s as Kt,t as qt,u as Jt,v as Yt,w as Xt,x as Zt,y as Qt}from"./SessionsList-DTdwgdgY.js";import{i as $t,n as en,r as tn,t as nn}from"./IntegrationHub-DHgjRUIy.js";import{n as rn,t as an}from"./addon-display-names-BkwMrExv.js";e();function on(){let{t:e}=Y(),t=H(),i=W.useUtils(),a=Et(),{data:o,isLoading:s}=Be(),c=n(()=>o??[],[o]),l=W.useQueries(e=>c.map(t=>e.userManagement.listExternalIdentities({userId:t.id}))),u=W.auth.listLoginMethods.useQuery(),[f,p]=r(null),m=ft({onSuccess:()=>void i.userManagement.listExternalIdentities.invalidate(),onError:e=>p(`Remove failed: ${e.message}`)}),h=n(()=>new Map((u.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),[u.data]),g=c.flatMap((e,t)=>l[t]?.data??[]),_=g.map(e=>({...At(e,a),kind:h.get(e.provider)??e.provider})),v=async n=>{let r=g.find(e=>Zt(e)===n.id);r!==void 0&&await t({title:e(`access.externalIdentitiesSection.removeSignInLink`,`Remove sign-in link`),message:e(`access.externalIdentitiesSection.willNoLongerBeAble`,`"{{ownerName}}" will no longer be able to sign in with this {{kind}} account.`,{ownerName:n.ownerName,kind:n.kind}),confirmLabel:e(`common.remove`,`Remove`),variant:`danger`})&&(p(null),m.mutate({userId:r.userId,provider:r.provider,subject:r.subject}))};return d(X,{notice:Bt(f),onDismissNotice:()=>{p(null)},id:`external-identities`,title:e(`access.externalIdentitiesSection.signInLinks`,`Sign-in links`),icon:B,description:e(`access.externalIdentitiesSection.externalAccountsSingleSignOn`,`External accounts (single sign-on) each user linked to their CamStack account. Only the owner can link one, from their profile; an admin can remove it.`),children:d(jt,{rows:_,label:`sign-in links`,isLoading:s||l.some(e=>e.isLoading),loadError:l.find(e=>e.isError)?.error?.message??null,emptyText:`No user has linked a sign-in account.`,expiresNone:`—`,action:{label:e(`common.remove`,`Remove`),icon:fe,isAvailable:()=>!0,onRun:e=>void v(e),busyId:null,disabled:m.isPending}})})}e();var sn={key:`access.nouns.linkedApp`};function cn(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 ln(){let{t:e}=Y(),t=H(),i=c(),a=Ze(),[o,s]=r(null),l=()=>void i.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]}),u=De({onSuccess:l,onError:e=>s(`Revoke failed: ${e.message}`)}),f=kt(sn,l),p=n(()=>(a.data??[]).map(e=>Dt(e,e.scopes.map(cn).join(`, `))),[a.data]),m=async n=>{await t({title:e(`access.linkedAppsSection.revokeTheLink`,`Revoke the "{{name}}" link?`,{name:n.name}),message:e(`access.linkedAppsSection.losesAccessForOnIts`,`{{name}} loses access for {{ownerName}} on its next call. Linking it again needs the account-link flow from the start.`,{name:n.name,ownerName:n.ownerName}),confirmLabel:e(`access.linkedAppsSection.revoke`,`Revoke`),variant:`danger`})&&(s(null),u.mutate({id:n.id}))},h=u.isPending?u.variables?.id??null:null;return d(X,{notice:Bt(o,f.outcome),onDismissNotice:()=>{s(null),f.dismiss()},id:`linked-apps`,title:e(`access.linkedAppsSection.linkedApps`,`Linked apps`),icon:D,description:e(`access.linkedAppsSection.externalIntegrationsAlexaLinkedTo`,`External integrations (Alexa, …) linked to this hub through OAuth. Revoking one stops that integration on its next call. Already-revoked rows can be selected and removed from the list.`),children:d(jt,{rows:p,label:e(`access.linkedAppsSection.linkedApps2`,`linked apps`),isLoading:a.isLoading,loadError:a.isError?a.error?.message??`Request failed`:null,emptyText:`No linked apps — an integration appears here once it completes the account-link flow.`,expiresNone:`—`,action:{label:e(`access.linkedAppsSection.revoke`,`Revoke`),icon:g,isAvailable:e=>e.status===`active`||e.status===`revoked`,onRun:e=>void m(e),busyId:h,disabled:u.isPending||f.busy},bulk:{revoke:f,noun:sn,isSelectable:e=>e.status===`active`||e.status===`revoked`,quickSelect:[{label:e(`access.linkedAppsSection.selectRevoked`,`Select revoked`),match:e=>e.status===`revoked`}]}})})}e();var un={key:`access.nouns.session`};function dn(){let{t:e}=Y(),t=H(),i=W.useUtils(),a=Et(),o=W.auth.listSessions.useQuery(),[s,c]=r(null),l=()=>void i.auth.listSessions.invalidate(),u=W.auth.revokeSessions.useMutation({onSuccess:l,onError:e=>c(`Sign out failed: ${e.message}`)}),f=kt(un,l),p=n(()=>(o.data??[]).map(e=>Xt(e,a,{client:e=>Yt(e).label,method:Qt})),[o.data,a]),m=async n=>{await t({title:e(`access.loginSessionsSection.signOutThisSession`,`Sign out this session`),message:e(`access.loginSessionsSection.onWillHaveToSign`,`{{ownerName}} on {{name}} will have to sign in again.`,{ownerName:n.ownerName,name:n.name}),confirmLabel:e(`access.loginSessionsSection.signOut`,`Sign out`),variant:`danger`})&&(c(null),u.mutate({id:n.id}))};return d(X,{notice:Bt(s,f.outcome),onDismissNotice:()=>{c(null),f.dismiss()},id:`login-sessions`,title:e(`access.loginSessionsSection.loginSessions`,`Login sessions`),icon:de,description:e(`access.loginSessionsSection.everyBrowserAndAppSigned`,`Every browser and app signed in to this hub, for every user. Signing one out ends it at once; it has to sign in again. Your own current session is marked and never included in a bulk sign-out.`),children:d(jt,{rows:p,label:e(`common.sessionsLabel`),isLoading:o.isLoading,loadError:o.isError?o.error?.message??`Request failed`:null,emptyText:`No active sessions.`,action:{label:e(`access.loginSessionsSection.signOut`,`Sign out`),icon:le,isAvailable:e=>e.status===`active`,onRun:e=>void m(e),busyId:u.isPending&&u.variables!==void 0&&`id`in u.variables?u.variables.id:null,disabled:u.isPending||f.busy},bulk:{revoke:f,noun:un,isSelectable:e=>e.status===`active`}})})}var fn={"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 pn(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 mn(e){let t=Z(e,`prefix`);return t===null?null:J.t(`helpers.authAuditWording.prefix`,{prefix:t})}function hn(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:pn(n,t)}),details:Q([mn(n),typeof e==`number`?J.t(`helpers.authAuditWording.expires`,{at:Nt(e)}):null])}}case`admin-token-used`:{let e=Z(n,`path`);return{title:J.t(`helpers.authAuditWording.tokenUsed`,{name:pn(n,t)}),details:Q([mn(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:pn(n,t)}),details:Q([typeof e==`number`?J.t(`helpers.authAuditWording.expires`,{at:Nt(e)}):null])}}case`token-revoked`:return{title:J.t(`helpers.authAuditWording.anyTokenRevoked`,{name:pn(n,t)}),details:[]};case`admin-token-revoked`:return{title:J.t(`helpers.authAuditWording.tokenRevoked`,{name:pn(n,t)}),details:Q([mn(n)])};case`credentials-revoked`:{let e=Z(n,`kind`)??`credential`,t=n.revoked,r=n.skipped,i=fn[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)}`)}}}e();var gn=100;function _n(){let{user:e}=gt();return e?.isAdmin?d(yn,{}):null}function vn(){let{data:e}=Be(),{data:t}=W.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 yn(){let{t:e}=Y(),t=W.auth.listAuthAudit.useQuery({limit:gn}),{userNameById:n,tokenNameById:r}=vn(),i=t.data??[];return a(`div`,{"data-testid":`auth-audit`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[a(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[d(j,{className:`h-3.5 w-3.5 text-foreground-subtle`}),d(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`auth.authAuditSection.authenticationAudit`,`Authentication audit`)}),d(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:e(`auth.authAuditSection.latest`,{count:gn})})]}),d(`div`,{className:`p-4`,children:t.isLoading?a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(A,{className:`h-3.5 w-3.5 animate-spin`}),e(`auth.authAuditSection.loadingAuditTrail`,`Loading audit trail…`)]}):t.isError?a(`div`,{className:`text-[11px] text-danger`,children:[e(`auth.authAuditSection.couldNotLoadTheAudit`,`Could not load the audit trail:`),` `,t.error?.message??e(`auth.authAuditSection.requestFailed`,`Request failed`)]}):i.length===0?a(`div`,{className:`rounded border border-dashed border-border px-3 py-4 text-xs text-foreground-subtle text-center space-y-1`,children:[d(`div`,{children:e(`auth.authAuditSection.noAuthenticationEventsRecordedYet`,`No authentication events recorded yet.`)}),d(`div`,{className:`text-[11px] text-foreground-subtle/90`,children:e(`auth.authAuditSection.thisTrailRecordsAdminToken`,`This trail records admin-token create/use/revoke, trusted-network 2FA skips, and credential revokes (including single share-link revoke). Browser password logins are not listed here.`)})]}):d(`ul`,{className:`divide-y divide-border rounded-md border border-border max-h-[420px] overflow-y-auto`,children:i.map(e=>d(bn,{record:e,userName:e.userId===void 0?null:n.get(e.userId)??e.userId,tokenNameById:r},e.id))})})]})}function bn({record:e,userName:t,tokenNameById:n}){let r=hn(e,n);return a(`li`,{"data-testid":`auth-audit-row`,className:`px-3 py-2 text-xs space-y-0.5`,children:[a(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[d(`span`,{className:`font-medium text-foreground`,children:r.title}),d(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Nt(e.at)})]}),a(`div`,{className:`flex flex-wrap gap-x-3 text-[11px] text-foreground-subtle`,children:[t!==null&&d(`span`,{className:`text-foreground`,children:t}),e.ip!==void 0&&d(`span`,{className:`font-mono`,children:e.ip}),r.details.map(e=>d(`span`,{className:`font-mono`,children:e},e))]})]})}e();var $={loginSessions:`login-sessions`,linkedApps:`linked-apps`,tokens:`tokens`,scopedTokens:`scoped-tokens`,adminTokens:`admin-tokens`,shareLinks:`share-links`,externalIdentities:`external-identities`,audit:`auth-audit`},xn={[$.scopedTokens]:$.tokens,[$.adminTokens]:$.tokens,[$.shareLinks]:$.tokens};function Sn(){return[{id:$.loginSessions,label:J.t(`system.access.loginSessions`,`Login sessions`),icon:de,render:()=>d(dn,{})},{id:$.linkedApps,label:J.t(`system.access.linkedApps`,`Linked apps`),icon:D,render:()=>d(ln,{})},{id:$.tokens,label:J.t(`system.access.tokens`,`Tokens`),icon:ue,render:({createRequested:e,onCreateConsumed:t})=>d(Rt,{headerOwnsCreate:!0,createRequested:e,onCreateConsumed:t})},{id:$.externalIdentities,label:J.t(`system.access.signInLinks`,`Sign-in links`),icon:B,render:()=>d(on,{})},{id:$.audit,label:J.t(`system.access.audit`,`Audit`),icon:j,render:()=>d(_n,{})}]}function Cn({createRequested:e=!1,onCreateConsumed:t}){let{t:r}=Y(),i=n(()=>Sn(),[]),o=$t({ids:n(()=>i.map(e=>e.id),[i]),answered:!0}),s=bt(),[c]=Ct(),l=c.get(`integration`),u=l===null?void 0:xn[l];if(u!==void 0){let e=new URLSearchParams(c);return e.set(`integration`,u),d(pt,{to:`?${e.toString()}`,replace:!0})}let f=i.find(e=>e.id===o.selectedId)??i[0];return a(`div`,{className:`flex flex-col gap-3`,"data-testid":`access-page`,children:[d(_e,{appearance:`pills`,value:f?.id??$.loginSessions,onValueChange:e=>{s(`?${yt(c,e,null,null).toString()}`)},children:d(Ge,{"aria-label":r(`system.access.credentialKinds`,`Credential kinds`),children:i.map(e=>a(me,{value:e.id,"data-testid":`access-kind-${e.id}`,children:[d(e.icon,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),e.label]},e.id))})}),f===void 0?null:d(`div`,{role:`region`,"aria-label":f.label,"data-testid":`access-kind-body`,children:f.render({createRequested:e&&f.id===$.tokens,onCreateConsumed:t??(()=>void 0)})},f.id)]})}function wn(e,t){if(e===$.tokens)return a(q,{size:`sm`,type:`button`,"data-testid":`access-new-token`,onClick:t,children:[d(ue,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),J.t(`system.access.newToken`,`New token`)]})}function Tn(){let[e,t]=r(!1);return{createRequested:e,requestCreate:()=>t(!0),clearCreate:()=>t(!1)}}e();var En=[`oidcConnections`,`listConnections`],Dn=[`oidcConnections`,`connectionFormSchema`],On={displayName:`OpenID Connect`,icon:`shield-check`,issuerUrl:``,clientId:``,clientSecret:``,redirectUri:``,scopes:`openid profile email`,usernameClaim:`preferred_username`},kn=/^[a-z0-9][a-z0-9-]{0,63}$/;function An(e){return e instanceof Error?e.message:String(e)}function jn(e,t){if(t)return typeof e==`string`&&e.length>0?e:void 0;if(L(e))return ne;if(typeof e==`string`&&e.length>0)return e;te(e)}function Mn(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function Nn({addonId:e}){let{t:f}=Y(),p=ee(),m=c(),h=H(),_=Je({editKey:`oidcEdit`,newKey:`oidcNew`}),[v,y]=r(!1),[b,x]=r(null),[S,C]=r(``),[w,T]=r({...On}),D=l(null),O=o({queryKey:[...En,e],queryFn:async()=>p.trpcClient.oidcConnections.listConnections.query({})}),k=o({queryKey:Dn,queryFn:async()=>p.trpcClient.oidcConnections.connectionFormSchema.query({})}),A=O.data??[],j=Mn(k.data)?k.data:void 0,M=_.state,N=M.mode===`edit`?A.find(e=>e.id===M.id)??null:null;t(()=>{if(_.state.mode===`edit`&&N!==null){let e=`edit:${N.id}`;if(D.current===e)return;D.current=e,x(null),C(N.id),T(N.formValues===void 0?{...On}:{...N.formValues});return}if(_.state.mode===`new`){if(D.current===`new`)return;D.current=`new`,x(null),C(``),T({...On})}},[N,_.state]);let F=i(async()=>{await m.invalidateQueries({queryKey:En})},[m]),I=u({mutationFn:async e=>p.trpcClient.oidcConnections.deleteConnection.mutate({id:e}),onSuccess:async()=>F()}),L=i(async e=>{await h({title:f(`system.oidcSettingsConnections.deleteOidcConnection`,`Delete OIDC connection?`),message:f(`system.oidcSettingsConnections.removeTheLoginButtonAnd`,`Remove “{{displayName}}” ({{id}}). The login button and IdP credentials for this id are dropped.`,{displayName:e.displayName,id:e.id}),confirmLabel:f(`common.delete`,`Delete`),cancelLabel:f(`common.cancel`,`Cancel`),variant:`danger`})&&(await I.mutateAsync(e.id),_.state.mode===`edit`&&_.state.id===e.id&&(_.close(),D.current=null))},[h,I,_,f]),te=i(async()=>{let e=w.displayName,t=typeof e==`string`&&e.trim()!==``?e.trim():``;if(t===``){x(`Display name is required.`);return}let n=_.state.mode===`new`,r=n?S.trim():N?.id??``;if(n&&!kn.test(r)){x(`Instance id must be a lowercase slug (e.g. authentik, google).`);return}if(r===``){x(`That connection is no longer available.`);return}let i=jn(w.clientSecret,n),a=w.icon,o=w.issuerUrl,s=w.clientId,c=w.redirectUri,l=w.scopes,u=w.usernameClaim,d=u===`email`||u===`sub`?u:`preferred_username`;y(!0),x(null);try{n&&await p.trpcClient.oidcConnections.createConnection.mutate({id:r,displayName:t}),await p.trpcClient.oidcConnections.updateConnection.mutate({id:r,displayName:t,icon:typeof a==`string`?a:`shield-check`,issuerUrl:typeof o==`string`?o:``,clientId:typeof s==`string`?s:``,...i===void 0?{}:{clientSecret:i},redirectUri:typeof c==`string`?c:``,scopes:typeof l==`string`?l:`openid profile email`,usernameClaim:d}),await F(),_.close(),D.current=null}catch(e){x(An(e))}finally{y(!1)}},[S,N?.id,_,w,F,p]),ne=n(()=>[{key:`id`,header:f(`system.oidcSettingsConnections.id`,`Id`),sortValue:e=>e.id,render:e=>d(`span`,{className:`font-mono text-xs text-foreground`,children:e.id})},{key:`name`,header:f(`system.oidcSettingsConnections.name`,`Name`),sortValue:e=>e.displayName,render:e=>d(`span`,{className:`truncate font-medium text-foreground`,children:e.displayName})},{key:`issuer`,header:f(`system.oidcSettingsConnections.issuer`,`Issuer`),sortValue:e=>e.issuerUrl,render:e=>d(`span`,{className:`truncate text-xs text-foreground-muted`,children:e.issuerUrl===``?`—`:e.issuerUrl})},{key:`status`,header:f(`system.oidcSettingsConnections.status`,`Status`),notSortableReason:`Badge`,render:e=>d(U,{variant:e.configured?`success`:`warning`,children:e.configured?f(`system.oidcSettingsConnections.configured`,`Configured`):f(`system.oidcSettingsConnections.notConfigured`,`Not configured`)})},{key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,nowrap:!0,render:e=>a(`div`,{className:`flex justify-end gap-1`,children:[d(q,{type:`button`,size:`sm`,variant:`secondary`,onClick:t=>{t.stopPropagation(),_.openEdit(e.id)},children:f(`common.edit`,`Edit`)}),d(q,{type:`button`,size:`sm`,variant:`ghost`,"aria-label":f(`system.oidcSettingsConnections.delete`,`Delete {{displayName}}`,{displayName:e.displayName}),title:f(`common.delete`,`Delete`),onClick:t=>{t.stopPropagation(),L(e)},children:d(g,{className:`h-3.5 w-3.5 text-danger`})})]})}],[_,L,f]),R=_.state.mode===`new`,z=R||N!==null,re=R?`new`:N===null?`closed`:`edit:${N.id}:${N.configured?`cfg`:`empty`}`;return a(`div`,{className:`flex min-h-0 flex-col gap-3`,"data-testid":`oidc-settings-connections`,children:[a(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[a(`p`,{className:`text-sm text-foreground-muted`,children:[f(`system.oidcSettingsConnections.eachRowIsOneIdp`,`Each row is one IdP. Redirect URI:`),` `,d(`span`,{className:`font-mono text-xs`,children:`/addon/${e}/<id>/callback`})]}),a(q,{type:`button`,size:`sm`,"data-testid":`oidc-connections-add`,onClick:()=>_.openNew(),children:[d(E,{className:`h-3.5 w-3.5`}),f(`system.oidcSettingsConnections.addConnection`,`Add connection`)]})]}),O.isError?d(`p`,{className:`text-sm text-danger`,children:f(`system.oidcSettingsConnections.couldNotLoadConnections`,`Could not load connections.`)}):null,O.isPending?d(Le,{className:`h-32 w-full`}):d(Ie,{columns:ne,rows:A,rowKey:e=>e.id,pageSize:25,emptyMessage:f(`system.oidcSettingsConnections.noOidcConnectionsYetAdd`,`No OIDC connections yet. Add one to register an IdP.`),onRowClick:e=>_.openEdit(e.id),defaultSort:{columnKey:`name`,dir:`asc`}}),d(Me,{open:z,onClose:()=>{_.close(),x(null),D.current=null},title:R?f(`system.oidcSettingsConnections.addOidcConnection`,`Add OIDC connection`):f(`system.oidcSettingsConnections.edit`,`Edit {{value1}}`,{value1:N?.displayName??`connection`}),icon:P,width:`xl`,testId:`oidc-connection-editor`,error:b,footer:d(q,{type:`button`,size:`sm`,disabled:v||R&&S.trim()===``,onClick:()=>void te(),children:v?f(`system.oidcSettingsConnections.saving`,`Saving…`):f(`common.save`,`Save`)}),children:z?a(s,{children:[R?a(`div`,{children:[d(be,{htmlFor:`oidc-connection-id`,children:f(`system.oidcSettingsConnections.instanceId`,`Instance id`)}),d(he,{id:`oidc-connection-id`,value:S,onChange:e=>C(e.target.value),placeholder:`authentik`,autoComplete:`off`}),d(`p`,{className:`mt-1 text-xs text-foreground-muted`,children:f(`system.oidcSettingsConnections.urlSlugAppearsInAddon`,`URL slug — appears in /addon/{{addonId}}/<id>/callback. Stable; renaming is not supported after save.`,{addonId:e})})]}):a(`p`,{className:`text-sm text-foreground-muted`,children:[f(`system.oidcSettingsConnections.instanceId2`,`Instance id:`),` `,d(`span`,{className:`font-mono`,children:N?.id})]}),j===void 0?d(`p`,{className:`text-sm text-foreground-muted`,children:f(`system.oidcSettingsConnections.loadingForm`,`Loading form…`)}):d(rt,{schema:j,values:w,onChange:T,bare:!0},re)]}):null})]})}e();var Pn=3e4,Fn=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],In={titleKey:`system.authentication.sectionTitle`,subtitleKey:`system.authentication.sectionSubtitle`,emptyTitleKey:`system.authentication.sectionEmptyTitle`,emptyDescriptionKey:`system.authentication.sectionEmptyDescription`,installLabelKey:`system.authentication.sectionInstall`};function Ln(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:oe,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:V,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:V,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:f,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)?{headline:`TOTP — second factor.`,icon:f,bullets:[`Time-based codes from an authenticator app (RFC 6238).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:P,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Rn(){let{t:e}=Y(),t=ot({capName:Fn[0].capName},{refetchInterval:Pn}),r=ot({capName:Fn[1].capName},{refetchInterval:Pn}),i=$e(void 0,{refetchInterval:Pn}),a=n(()=>an(i.data??[]),[i.data]),o=n(()=>{let e=[],n=[t.data??[],r.data??[]];for(let[t,r]of Fn.entries())for(let i of n[t]??[])e.push({addonId:i.addonId,displayName:a.get(i.addonId)??i.addonId,isActive:i.isActive,capName:r.capName,stageBadge:r.stageBadge});return e},[t.data,r.data,a]),s=[{id:`authentication`,label:e(`system.authentication.authenticationProviders`,`Authentication providers`),install:{capability:Fn[0].capName,label:e(In.installLabelKey)},entries:o.map(t=>({id:t.addonId,name:t.displayName,fallbackIcon:P,...rn(t.isActive),render:()=>d(en,{addonId:t.addonId,displayName:t.displayName,capName:t.capName,isActive:t.isActive,badges:t.stageBadge===null?null:d(U,{variant:`info`,className:tn,children:t.stageBadge}),settingsContent:t.addonId.startsWith(`auth-oidc`)?d(Nn,{addonId:t.addonId}):void 0,panels:[{id:`about`,title:e(`system.authentication.about`,`About`),icon:Ln(t.addonId).icon,content:d(zn,{addonId:t.addonId})}]})}))}];return d(nn,{embedded:!0,icon:P,title:e(In.titleKey),subtitle:e(In.subtitleKey),groups:s,isLoading:t.isLoading||r.isLoading,emptyTitle:e(In.emptyTitleKey),emptyDescription:e(In.emptyDescriptionKey)})}function zn({addonId:e}){let{t}=Y(),n=Ln(e),r=n.icon;return a(`div`,{className:`space-y-3 rounded-lg border border-border bg-surface p-2 sm:p-4`,children:[a(`div`,{className:`flex items-start gap-2.5`,children:[d(r,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),d(`div`,{className:`text-xs text-foreground font-medium`,children:n.headline})]}),d(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:n.bullets.map((e,t)=>d(`li`,{children:e},t))}),n.setupSteps&&n.setupSteps.length>0&&a(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[a(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[d(ae,{className:`h-3 w-3`}),t(`system.authentication.setupSteps`,`Setup steps`)]}),d(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:n.setupSteps.map((e,t)=>d(`li`,{children:e},t))})]}),e===`local-auth`&&a(`div`,{className:`rounded-md border border-info/30 bg-info/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[d(k,{className:`h-3.5 w-3.5 mt-0.5 text-info shrink-0`}),d(`span`,{children:d(_t,{i18nKey:`system.authentication.totpNote`,components:{access:d(mt,{to:`/system/my-access`,className:`underline text-primary`}),users:d(mt,{to:`/system/identity?tab=users`,className:`underline text-primary`})}})})]})]})}function Bn({isPending:e,error:t,what:n,onRetry:r,children:i}){let{t:o}=Y();return e?a(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,role:`status`,"data-testid":`query-pending`,children:[d(A,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),o(`certificates.queryBody.reading`,{what:n})]}):t===null?i:d(G,{title:o(`certificates.queryBody.couldNotRead`,`Could not read {{what}}`,{what:n}),message:t.message.length>0?t.message:o(`certificates.queryBody.requestFailed`,`Request failed`),onRetry:r})}function Vn(){let{t:e}=Y(),t=W.deviceCredentials.getDeviceCaStatus.useQuery({}),n=t.data;return d(X,{id:`device-ca`,title:e(`certificates.deviceCaCard.deviceCertificateAuthority`,`Device certificate authority`),icon:P,description:e(`certificates.deviceCaCard.signsTheCertificateEachPaired`,`Signs the certificate each paired device holds. It is created the first time a device is paired.`),children:d(Bn,{isPending:t.isPending,error:t.error,what:`the device CA`,onRetry:()=>void t.refetch(),children:n!==void 0&&a(`div`,{className:`space-y-1`,"data-testid":`device-ca-status`,children:[a(K,{label:e(`certificates.deviceCaCard.state`,`State`),children:[n.state===`ready`&&d(U,{variant:`success`,children:e(`certificates.deviceCaCard.ready`,`Ready`)}),n.state===`absent`&&d(U,{variant:`default`,children:e(`certificates.deviceCaCard.notCreatedYet`,`Not created yet`)}),n.state===`unavailable`&&d(U,{variant:`danger`,children:e(`certificates.deviceCaCard.unavailable`,`Unavailable`)})]}),n.state===`ready`&&a(s,{children:[d(K,{label:e(`certificates.deviceCaCard.subject`,`Subject`),valueClassName:`font-mono`,children:n.subject}),d(K,{label:e(`certificates.deviceCaCard.fingerprintSha256`,`Fingerprint (SHA-256)`),valueClassName:`font-mono`,children:n.fingerprintSha256}),d(K,{label:e(`certificates.deviceCaCard.validUntil`,`Valid until`),children:n.validTo})]}),n.state===`unavailable`&&d(K,{label:e(`certificates.deviceCaCard.reason`,`Reason`),children:d(`span`,{className:`text-danger`,children:n.reason})})]})})})}e();function Hn(){let{t:e}=Y(),t=W.useUtils(),n=W.deviceCredentials.getDeviceCertificateSettings.useQuery({}),[i,o]=r(null),s=W.deviceCredentials.setDeviceCertificateSettings.useMutation({onSuccess:()=>{o(null),t.deviceCredentials.getDeviceCertificateSettings.invalidate()},onError:e=>o(`Could not save: ${e.message}`)});return d(Bn,{isPending:n.isPending,error:n.error,what:`the enrollment setting`,onRetry:()=>void n.refetch(),children:n.data!==void 0&&a(K,{label:e(`certificates.deviceSettingsRow.usersCanEnrollTheirOwn`,`Users can enroll their own devices`),actions:d(Ue,{checked:n.data.selfEnrollment===`allowed`,disabled:s.isPending,"aria-label":e(`certificates.deviceSettingsRow.usersCanEnrollTheirOwn`,`Users can enroll their own devices`),onCheckedChange:e=>s.mutate({selfEnrollment:e?`allowed`:`disabled`})}),children:[d(`span`,{className:`text-[11px] text-foreground-subtle`,children:n.data.selfEnrollment===`allowed`?e(`certificates.deviceSettingsRow.allowedAUserSignedIn`,`Allowed - a user signed in on a phone can keep it signed in. Pairing by QR works either way.`):e(`certificates.deviceSettingsRow.disabledOnlyAnAdminCan`,`Disabled - only an admin can pair a device, with a QR code.`)}),i!==null&&d(`span`,{className:`block text-[11px] text-danger`,children:i})]})})}e();function Un(e){let[n,i]=r(()=>Date.now());return t(()=>{let t=setInterval(()=>i(Date.now()),e);return()=>clearInterval(t)},[e]),n}e();var Wn=80,Gn=208;function Kn({open:e,users:t,onClose:n,onPaired:i}){let{t:o}=Y(),s=W.deviceCredentials.startEnrollment.useMutation({onSuccess:i}),[c,l]=r(``),[u,p]=r(``),m=c===``?t[0]?.id??``:c,h=s.data,g=()=>{s.reset(),p(``),n()};return d(Me,{open:e,onClose:g,title:o(`certificates.pairDeviceDialog.pairADevice`,`Pair a device`),icon:f,width:`md`,testId:`pair-device-dialog`,error:s.isError?s.error.message:null,footer:h===void 0?a(q,{type:`button`,onClick:()=>{let e=u.trim();m===``||e===``||s.mutate({userId:m,deviceName:e})},disabled:s.isPending||m===``||u.trim()===``,children:[s.isPending&&d(A,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),o(`certificates.pairDeviceDialog.createPairingCode`,`Create pairing code`)]}):d(q,{type:`button`,variant:`outline`,onClick:g,children:o(`certificates.pairDeviceDialog.done`,`Done`)}),children:h===void 0?a(`div`,{className:`space-y-3`,children:[d(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`certificates.pairDeviceDialog.createsAOneTimeCode`,`Creates a one-time code for a phone you hold. Scan it with the CamStack app on that phone; the phone then stays signed in as the chosen user until you revoke it.`)}),d(ct,{label:o(`certificates.pairDeviceDialog.user`,`User`),required:!0,children:d(Ce,{value:m,onChange:e=>l(e.target.value),options:t.map(e=>({value:e.id,label:e.username}))})}),d(ct,{label:o(`certificates.pairDeviceDialog.deviceName`,`Device name`),required:!0,description:o(`certificates.pairDeviceDialog.howThisPhoneIsListed`,`How this phone is listed, e.g. Anna's iPhone.`),children:d(he,{value:u,maxLength:Wn,onChange:e=>p(e.target.value),placeholder:o(`certificates.pairDeviceDialog.annaSIphone`,`Anna's iPhone`),autoFocus:!0})})]}):d(qn,{enrollUrl:h.enrollUrl,expiresAt:h.expiresAt,hubKnown:h.hubOrigin!==null,onRestart:()=>s.reset()})})}function qn({enrollUrl:e,expiresAt:t,hubKnown:n,onRestart:r}){let{t:i}=Y(),o=Wt(t,Un(1e3));return d(`div`,{className:`space-y-3`,"data-testid":`pair-issued`,children:a(`div`,{className:`flex flex-col items-center gap-3 sm:flex-row sm:items-start`,children:[d(`div`,{className:o.expired?`opacity-30`:void 0,children:d(we,{value:e,size:Gn,alt:i(`certificates.pairDeviceDialog.enrollmentQrCode`,`Enrollment QR code`)})}),a(`div`,{className:`min-w-0 flex-1 space-y-2`,children:[d(`p`,{className:`text-[11px] text-foreground-subtle`,children:i(`certificates.pairDeviceDialog.openTheCamstackAppOn`,`Open the CamStack app on the phone and scan this code. It works once.`)}),d(`div`,{className:`text-sm font-semibold tabular-nums text-foreground`,role:`timer`,"data-testid":`pair-countdown`,children:o.expired?i(`certificates.pairDeviceDialog.expiredCreateANewCode`,`Expired - create a new code`):i(`certificates.pairDeviceDialog.expiresIn`,`Expires in {{label}}`,{label:o.label})}),a(`div`,{className:`flex items-center gap-1 rounded-md border border-border bg-background px-2 py-1`,children:[d(`code`,{className:`min-w-0 flex-1 select-all break-all font-mono text-[11px] text-foreground`,children:e}),d(Ae,{value:e,srLabel:`Enrollment link`})]}),!n&&a(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-2.5 py-1.5 text-[11px] text-foreground`,children:[d(_,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),d(`span`,{children:i(`certificates.pairDeviceDialog.theHubCouldNotName`,`The hub could not name an address for this link, so the app must already know it.`)})]}),o.expired&&d(q,{type:`button`,variant:`outline`,size:`sm`,onClick:r,children:i(`certificates.pairDeviceDialog.newCode`,`New code`)})]})]})})}e();var Jn={key:`access.nouns.device`};function Yn({pairOpen:e,onPairClose:t}){let{t:i}=Y(),o=H(),s=We(),c=W.useUtils(),l=W.deviceCredentials.listDeviceCredentials.useQuery({includeRevoked:!0}),u=Be(),[p,_]=r(null),[v,y]=r(null),b=()=>void c.deviceCredentials.listDeviceCredentials.invalidate(),x=e=>t=>{y(null),_(`${e} failed: ${t.message}`)},S=()=>{y(null),b()},C=W.deviceCredentials.revokeDeviceCredential.useMutation({onSuccess:S,onError:x(`Revoke`)}),w=W.deviceCredentials.deleteDeviceCredential.useMutation({onSuccess:e=>{e.result!==`deleted`&&_(e.result===`live`?`Only a revoked device can be deleted: revoke it first.`:`That device no longer exists.`),S()},onError:x(`Delete`)}),T=W.deviceCredentials.renameDeviceCredential.useMutation({onSuccess:S,onError:x(`Rename`)}),E=Ot(Jn,e=>C.mutateAsync({id:e}),b),D=E.busy||v!==null,O=n(()=>(l.data??[]).map(Ut),[l.data]),k=async e=>{await o({title:i(`certificates.devicesCard.revoke`,`Revoke "{{name}}"?`,{name:e.name}),message:i(`certificates.devicesCard.sDeviceStopsSigningIn`,`{{ownerName}}'s device stops signing in at once and its open sessions end. To use it again it has to be paired anew. This cannot be undone.`,{ownerName:e.ownerName}),confirmLabel:i(`certificates.devicesCard.revoke2`,`Revoke`),variant:`danger`})&&(_(null),y(e.id),C.mutate({id:e.id}))},A=async e=>{await o({title:i(`certificates.devicesCard.delete`,`Delete "{{name}}"?`,{name:e.name}),message:i(`certificates.devicesCard.isRemovedFromTheList`,`{{name}} is removed from the list. The audit trail keeps the revocation.`,{name:e.name}),confirmLabel:i(`common.delete`,`Delete`),variant:`danger`})&&(_(null),y(e.id),w.mutate({id:e.id}))},ee=async e=>{let t=(await s({title:i(`certificates.devicesCard.renameDevice`,`Rename device`),label:i(`certificates.devicesCard.deviceName`,`Device name`),defaultValue:e.name,confirmLabel:i(`certificates.devicesCard.rename`,`Rename`)}))?.trim()??``;t===``||t===e.name||(_(null),y(e.id),T.mutate({id:e.id,deviceName:t}))},j={label:i(`certificates.devicesCard.revoke2`,`Revoke`),icon:h,isAvailable:Mt,onRun:e=>void k(e),busyId:C.isPending?v:null,disabled:D},M=[{label:i(`certificates.devicesCard.rename`,`Rename`),icon:m,tone:`neutral`,isAvailable:()=>!0,onRun:e=>void ee(e),busyId:T.isPending?v:null,disabled:D},{label:i(`common.delete`,`Delete`),icon:g,isAvailable:zt,onRun:e=>void A(e),busyId:w.isPending?v:null,disabled:D}];return a(X,{id:`devices`,title:i(`certificates.devicesCard.devices`,`Devices`),icon:f,description:i(`certificates.devicesCard.phonesThatStaySignedIn`,`Phones that stay signed in with a certificate instead of a login. Revoking one signs it out at once; it has to be paired again.`),notice:Bt(p,E.outcome),onDismissNotice:()=>{_(null),E.dismiss()},children:[d(Hn,{}),d(jt,{rows:O,label:i(`certificates.devicesCard.label`),isLoading:l.isPending,loadError:l.error===null?null:l.error.message||`Request failed`,emptyText:`No devices paired yet.`,expiresNone:`—`,action:j,extraActions:M,bulk:{revoke:E,noun:Jn,isSelectable:Mt}}),d(Kn,{open:e,users:u.data??[],onClose:t,onPaired:b})]})}var Xn=/-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----/,Zn=/-----BEGIN ((?:RSA |EC |ENCRYPTED )?PRIVATE KEY)-----[\s\S]+?-----END \1-----/,Qn={certificate:`.pem,.crt,.cer`,privateKey:`.pem,.key`,ca:`.pem,.crt,.cer`};function $n(e,t){if(t.trim()===``)return null;if(e===`privateKey`){let e=Zn.exec(t);return e===null?Xn.test(t)?J.t(`helpers.pemFile.isCert`):J.t(`helpers.pemFile.notKey`):e[1]===`ENCRYPTED PRIVATE KEY`?J.t(`helpers.pemFile.encrypted`):null}return Xn.test(t)?e===`certificate`&&Zn.test(t)?J.t(`helpers.pemFile.certHasKey`):null:Zn.test(t)?J.t(`helpers.pemFile.isKey`):J.t(`helpers.pemFile.notCert`)}function er(e){return e.text()}e();function tr({kind:e,label:t,value:n,onChange:i,rows:o=6}){let{t:s}=Y(),c=l(null),[u,f]=r(null),[p,m]=r(null),h=p??$n(e,n),g=`pem-${e}`,_=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t!==void 0){f(t.name);try{let e=await er(t);m(null),i(e)}catch(e){m(`Could not read ${t.name}: ${e instanceof Error?e.message:String(e)}`)}}};return a(`div`,{className:`space-y-1`,children:[a(`div`,{className:`flex items-center justify-between gap-2`,children:[d(`label`,{htmlFor:g,className:`text-[11px] text-foreground-subtle`,children:t}),a(`div`,{className:`flex min-w-0 items-center gap-2`,children:[u!==null&&d(`span`,{className:`truncate font-mono text-[10px] text-foreground-subtle`,"data-testid":`${g}-file-name`,children:u}),d(`input`,{ref:c,type:`file`,accept:Qn[e],onChange:e=>void _(e),className:`hidden`,"data-testid":`${g}-file`}),a(q,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>c.current?.click(),children:[d(se,{className:`mr-1 h-3 w-3`}),s(`system.pemField.chooseFile`,`Choose file`)]})]})]}),d(`textarea`,{id:g,value:n,onChange:e=>{f(null),m(null),i(e.target.value)},rows:o,"aria-invalid":h!==null,className:`w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`}),h!==null&&d(`p`,{className:`text-[11px] text-danger`,role:`alert`,children:h})]})}e();var nr=30;function rr(e){let t=Date.parse(e);return!Number.isNaN(t)&&Date.now()-t<nr*864e5}function ir(e){if(e===null||e===``)return`—`;let t=e.replace(/:/g,``);return t.length<=16?e:`${t.slice(0,8)}…${t.slice(-8)}`}function ar(){let{t:e}=Y(),t=c(),n=je(void 0,{refetchInterval:15e3}),i=tt({onSuccess:()=>void t.invalidateQueries({queryKey:[[`localNetwork`]]})}),o=Re({onSuccess:()=>void t.invalidateQueries({queryKey:[[`localNetwork`]]})}),s=Oe({onSuccess:()=>void t.invalidateQueries({queryKey:[[`localNetwork`]]})}),l=dt({onSuccess:()=>{m(!1),g(``),v(``),b(``),t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),u=n.data,[f,m]=r(!1),[h,g]=r(``),[_,v]=r(``),[y,b]=r(``),S=()=>{if(!u?.caCertPem)return;let e=new Blob([u.caCertPem],{type:`application/x-pem-file`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`camstack-ca.crt`,n.click(),URL.revokeObjectURL(t)},C=u?.mode===`uploaded`?`Uploaded`:u?.mode===`generated`?`Generated local CA`:`TLS disabled`;return d(Xe,{headingId:`local-access-certificate`,title:e(`system.localAccess.certificate`,`Certificate`),icon:x,children:a(`div`,{className:`${p} space-y-3`,children:[n.isError&&d(`p`,{className:`text-xs text-danger`,children:e(`system.localAccess.couldNotReadTlsStatus`,`Could not read TLS status.`)}),u?.reissueError&&d(G,{variant:`warning`,title:e(`system.localAccess.certificateReissue`,`Certificate reissue`),message:u.reissueError}),u?.restartRequired&&d(G,{variant:`warning`,title:e(`system.localAccess.restartRequired`,`Restart required`),message:e(`system.localAccess.theHttpsListenerStillServes`,`The HTTPS listener still serves the previous certificate. Restart the hub to apply it.`)}),u?.caMissing===!0&&d(G,{variant:`warning`,title:e(`system.localAccess.caMissingTitle`,`CA missing - devices cannot trust this hub`),message:e(`system.localAccess.caMissingBody`,"The uploaded certificate was not issued by a public CA and no CA was stored with it, so Download CA has nothing to hand out. Upload the certificate again together with its CA (for mkcert, the rootCA.pem in the folder `mkcert -CAROOT` prints).")}),u?.caReplacedAt!=null&&rr(u.caReplacedAt)&&d(G,{variant:`warning`,title:e(`system.localAccess.caReplacedTitle`,`The local CA was replaced - re-install it on your devices`),message:e(`system.localAccess.caReplacedBody`,`The previous local CA had no name constraints: if its key ever leaked it could vouch for any website. The hub now uses a CA limited to private addresses and local names. Download it again and trust it on every phone and computer that used the old one (replaced {{when}}).`,{when:new Date(u.caReplacedAt).toLocaleString()})}),a(`dl`,{className:`grid grid-cols-1 gap-2 text-xs sm:grid-cols-2`,children:[a(`div`,{children:[d(`dt`,{className:`text-foreground-subtle`,children:e(`system.localAccess.mode`,`Mode`)}),d(`dd`,{className:`font-medium`,children:C})]}),a(`div`,{children:[d(`dt`,{className:`text-foreground-subtle`,children:e(`system.localAccess.validTo`,`Valid to`)}),d(`dd`,{className:`font-mono`,children:u?.validTo?new Date(u.validTo).toLocaleString():`—`})]}),a(`div`,{children:[d(`dt`,{className:`text-foreground-subtle`,children:e(`system.localAccess.leafSha256`,`Leaf SHA-256`)}),d(`dd`,{className:`font-mono`,title:u?.leafFingerprintSha256??void 0,children:ir(u?.leafFingerprintSha256??null)})]}),u?.storedUpload!=null&&a(`div`,{children:[d(`dt`,{className:`text-foreground-subtle`,children:e(`system.localAccess.storedUpload`,`Stored upload`)}),d(`dd`,{className:`font-medium`,children:e(`system.localAccess.storedUploadValue`,`valid to {{validTo}}, {{ca}}`,{validTo:new Date(u.storedUpload.validTo).toLocaleDateString(),ca:u.storedUpload.hasCa?e(`system.localAccess.storedUploadWithCa`,`with its CA`):e(`system.localAccess.storedUploadNoCa`,`no CA`)})})]}),a(`div`,{children:[d(`dt`,{className:`text-foreground-subtle`,children:e(`system.localAccess.caSha256`,`CA SHA-256`)}),d(`dd`,{className:`font-mono`,title:u?.caFingerprintSha256??void 0,children:u?.mode===`uploaded`&&u.caFingerprintSha256===null?d(`span`,{className:`font-sans text-foreground-subtle`,children:e(`system.localAccess.issuerNotIncludedInThe`,`Issuer not included in the upload (not the local CA)`)}):ir(u?.caFingerprintSha256??null)})]})]}),u&&u.sans.length>0&&d(`div`,{className:`flex flex-wrap gap-1`,children:u.sans.map(e=>d(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 font-mono text-[10px] text-foreground-subtle`,children:e},e))}),a(`div`,{className:`flex flex-wrap gap-2`,children:[d(qe,{label:e(`system.localAccess.regenerate`,`Regenerate`),title:e(`system.localAccess.issueANewLeaf`,`Issue a new leaf?`),description:e(`system.localAccess.issuesANewLeafUnder`,`Issues a new leaf under the current local CA. Clients that trust the CA keep working. The HTTPS listener reloads.`),confirmLabel:e(`system.localAccess.regenerate`,`Regenerate`),disabled:u?.mode===`uploaded`||i.isPending,action:()=>i.mutateAsync({})}),d(q,{size:`sm`,variant:`outline`,onClick:()=>m(e=>!e),children:e(`system.localAccess.upload`,`Upload`)}),u?.caCertPem&&d(q,{size:`sm`,variant:`outline`,onClick:S,children:e(`system.localAccess.downloadCa`,`Download CA`)}),u?.mode===`uploaded`&&d(qe,{label:e(`system.localAccess.revertToGenerated`,`Revert to generated`),title:e(`system.localAccess.revertTitle`,`Switch back to the generated certificate?`),description:e(`system.localAccess.keepsTheUploadedPair`,`Returns to the generated local CA. The uploaded certificate and its CA stay stored here; you can select them again.`),confirmLabel:e(`system.localAccess.revert`,`Revert`),disabled:o.isPending,action:()=>o.mutateAsync({})}),u?.mode===`generated`&&u.storedUpload!=null&&d(qe,{label:e(`system.localAccess.useUploaded`,`Use uploaded certificate`),title:e(`system.localAccess.useUploadedTitle`,`Serve the stored upload again?`),description:e(`system.localAccess.useUploadedDescription`,`The stored uploaded certificate replaces the generated one on the HTTPS listener. The generated certificate stays stored.`),confirmLabel:e(`system.localAccess.useUploaded`,`Use uploaded certificate`),disabled:s.isPending,action:()=>s.mutateAsync(void 0)})]}),f&&a(`div`,{className:`space-y-2 border-t border-border pt-3`,children:[d(tr,{kind:`certificate`,label:e(`system.localAccess.certificateOrFullChainPem`,`Certificate or full chain (PEM)`),value:h,onChange:g}),d(tr,{kind:`privateKey`,label:e(`system.localAccess.privateKeyPem`,`Private key (PEM)`),value:_,onChange:v}),d(tr,{kind:`ca`,label:e(`system.localAccess.caPemRequired`,`CA (PEM) - required unless the certificate comes from a public CA`),value:y,onChange:b,rows:4}),d(q,{size:`sm`,disabled:!h.trim()||!_.trim()||$n(`certificate`,h)!==null||$n(`privateKey`,_)!==null||$n(`ca`,y)!==null||l.isPending,onClick:()=>l.mutate({certPem:h,keyPem:_,...y.trim()?{caPem:y}:{}}),children:e(`system.localAccess.saveCertificate`,`Save certificate`)}),l.isError&&d(`p`,{className:`text-xs text-danger`,children:l.error instanceof Error?l.error.message:e(`system.localAccess.uploadFailed`,`Upload failed`)})]})]})})}var or={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`};function sr(e){let t=e.find(e=>e.isHub);return t?.https.kind===`served`?t.https.status.caFingerprintSha256:null}function cr({https:e,mesh:t,now:n}){let{t:r}=Y(),i=je().data?.caCertPem??``,o=()=>{if(i===``)return;let e=URL.createObjectURL(new Blob([i],{type:`application/x-pem-file`})),t=document.createElement(`a`);t.href=e,t.download=`camstack-ca.crt`,t.click(),URL.revokeObjectURL(e)},s=t?.ca,c=s?.state===`ready`?Date.parse(s.validTo):null,l=t?.listener;return a(`div`,{className:`space-y-1`,"data-testid":`ca-strip`,children:[d(K,{label:r(`certificates.caStrip.localHttpsCaSha256`,`Local HTTPS CA (SHA-256)`),valueClassName:`font-mono`,children:a(`span`,{className:`flex flex-wrap items-center gap-2`,children:[sr(e)??`—`,i!==``&&a(q,{type:`button`,variant:`ghost`,size:`sm`,onClick:o,children:[d(b,{className:`h-3 w-3`,"aria-hidden":!0}),r(`certificates.caStrip.downloadCa`,`Download CA`)]})]})}),d(K,{label:r(`certificates.caStrip.clusterCaSha256`,`Cluster CA (SHA-256)`),valueClassName:`font-mono`,children:s===void 0?`—`:s.state===`ready`?s.fingerprintSha256:d(`span`,{className:`text-danger`,children:r(`certificates.caStrip.unavailable`,{reason:s.reason})})}),s?.state===`ready`&&a(K,{label:r(`certificates.caStrip.clusterCaValidUntil`,`Cluster CA valid until`),children:[s.validTo,c!==null&&!Number.isNaN(c)&&a(`span`,{className:`ml-2 text-[10px] ${or[Jt(c,n)]}`,children:[`(`,Pt(c,n),`)`]})]}),l!==void 0&&a(K,{label:r(`certificates.caStrip.nodeListener`,`Node listener`),children:[l.state===`open`&&d(U,{variant:`success`,children:r(`certificates.caStrip.open`,`Open`)}),l.state===`not-started`&&d(U,{variant:`default`,children:r(`certificates.caStrip.notStarted`,`Not started`)}),l.state===`closed`&&a(`span`,{className:`text-danger`,children:[r(`certificates.caStrip.closedSince`,{when:Ft(l.since)}),` `,l.reason]})]}),t!==void 0&&!t.registryAvailable&&a(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-2.5 py-1.5 text-[11px] text-foreground`,children:[d(_,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),d(`span`,{children:r(`certificates.caStrip.theCertificateRegistryIsNot`,`The certificate registry is not up, so the node list below is incomplete.`)})]})]})}function lr(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 ur(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 dr(e){return e.isHub||e.mesh===null?ur(e):null}var fr={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`},pr={enroll:`Issued at enrollment`,renewal:`Issued by a renewal`,boot:`Issued at boot`,pairing:`Issued at pairing`,observed:`Observed on its connection`},mr={uploaded:`Uploaded`,generated:`Generated`,disabled:`Disabled`};function hr(e){let t=e.https?.https;return t?.kind===`served`?Kt(t.status.validTo):null}function gr({ms:e,now:t}){return e===null?d(`span`,{className:`text-foreground-subtle`,children:`—`}):a(`div`,{children:[d(`div`,{children:Ft(e)}),d(`div`,{className:`text-[10px] ${fr[Jt(e,t)]}`,children:Pt(e,t)})]})}function _r({row:e}){let{t}=Y(),n=e.https?.https;return n===void 0?d(`span`,{className:`text-foreground-subtle`,children:`—`}):n.kind===`served`?a(`div`,{title:n.status.leafFingerprintSha256??``,children:[d(U,{variant:`success`,className:`text-[10px]`,children:t(`certificates.nodesColumns.served`,`Served`)}),d(`span`,{className:`ml-1.5 text-[10px] text-foreground-subtle`,children:mr[n.status.mode]}),d(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:Gt(n.status.leafFingerprintSha256)}),n.status.sans.length>0&&d(`div`,{className:`mt-0.5 max-w-[14rem] truncate font-mono text-[10px] text-foreground-subtle`,title:n.status.sans.join(`, `),children:n.status.sans.join(`, `)})]}):a(`div`,{className:`max-w-[16rem]`,children:[d(U,{variant:n.kind===`unreadable`?`danger`:`warning`,className:`text-[10px]`,children:n.kind===`unreadable`?t(`certificates.nodesColumns.unreadable`,`Unreadable`):t(`certificates.nodesColumns.notServed`,`Not served`)}),d(`div`,{className:`mt-1 whitespace-normal text-[10px] text-foreground-subtle`,children:n.reason})]})}function vr({row:e}){let{t}=Y(),n=e.mesh?.current??null;if(n===null)return d(`span`,{className:`text-foreground-subtle`,children:t(`certificates.nodesColumns.noneRecorded`,`None recorded`)});let r=e.mesh?.history.length??0;return a(`div`,{children:[d(`div`,{className:`font-mono text-[11px]`,title:n.serial,children:Ht(n.serial)}),d(`div`,{className:`font-mono text-[10px] text-foreground-subtle`,title:n.fingerprintSha256,children:Gt(n.fingerprintSha256)}),a(`div`,{className:`text-[10px] text-foreground-subtle`,children:[pr[n.issuedVia],r>0?` · ${t(`certificates.nodesColumns.earlier`,{count:r})}`:``]})]})}function yr({row:e}){let{t}=Y(),n=e.mesh?.presentingCurrent??null;return n===null?d(`span`,{className:`text-foreground-subtle`,children:e.online?`—`:t(`certificates.nodesColumns.offline`,`Offline`)}):n?d(U,{variant:`success`,className:`text-[10px]`,children:t(`common.yes`,`Yes`)}):d(U,{variant:`warning`,className:`text-[10px]`,children:t(`certificates.nodesColumns.noPresentsAnother`,`No - presents another`)})}function br(e){let t=e.icon;return a(q,{type:`button`,variant:`ghost`,size:`sm`,className:e.danger?`text-danger hover:bg-danger/10`:void 0,disabled:e.reason!==null||e.busy,title:e.reason??void 0,"aria-label":e.ariaLabel,onClick:e.onClick,children:[e.spinning?d(A,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):d(t,{className:`h-3 w-3`,"aria-hidden":!0}),e.label]})}function xr({reasons:e}){let{t}=Y();return a(ve,{className:`inline-block`,children:[d(Ke,{children:d(`span`,{className:`cursor-help text-[11px] text-foreground-subtle`,"data-testid":`hub-managed-note`,children:t(`certificates.nodesColumns.managedByTheHub`,`Managed by the hub`)})}),d(xe,{children:d(`ul`,{className:`max-w-xs space-y-1 whitespace-normal text-left text-[11px]`,children:e.map(e=>d(`li`,{children:e},e))})})]})}function Sr({row:e,o:t}){let{t:n}=Y(),r=e.https===null?`No HTTPS inventory for this node.`:It(e.https).reason,i=ur(e),o=dr(e),s=n=>t.running?.nodeId===e.nodeId&&t.running.action===n,c=t=>!e.isHub||t===null,l=[r,i,o].filter((e,t,n)=>e!==null&&n.indexOf(e)===t);return a(`div`,{className:`flex w-44 flex-col items-end gap-1`,children:[a(`div`,{className:`flex flex-col items-end gap-0.5`,children:[c(r)&&d(br,{label:n(`certificates.nodesColumns.renewHttps`,`Renew HTTPS`),ariaLabel:n(`certificates.nodesColumns.renewTheCertificateOn`,`Renew the certificate on {{nodeId}}`,{nodeId:e.nodeId}),icon:S,reason:r,busy:t.busy,spinning:s(`renew-https`),danger:!1,onClick:()=>t.onRenewHttps(e)}),c(i)&&d(br,{label:s(`renew-identity`)?n(`certificates.nodesColumns.renewing`,`Renewing…`):n(`certificates.nodesColumns.renewIdentity`,`Renew identity`),ariaLabel:n(`certificates.nodesColumns.renewTheClusterCertificateOf`,`Renew the cluster certificate of {{nodeId}}`,{nodeId:e.nodeId}),icon:S,reason:i,busy:t.busy,spinning:s(`renew-identity`),danger:!1,onClick:()=>t.onRenewIdentity(e)}),c(o)&&d(br,{label:n(`certificates.nodesColumns.revokeIdentity`,`Revoke identity`),ariaLabel:n(`certificates.nodesColumns.revokeTheClusterCertificateOf`,`Revoke the cluster certificate of {{nodeId}}`,{nodeId:e.nodeId}),icon:h,reason:o,busy:t.busy,spinning:s(`revoke-identity`),danger:!0,onClick:()=>t.onRevokeIdentity(e)})]}),e.isHub&&l.length>0&&d(xr,{reasons:l}),!e.isHub&&r!==null&&e.https!==null&&d(`div`,{className:`w-full whitespace-normal text-right text-[10px] text-foreground-subtle`,"data-testid":`renew-reason-${e.nodeId}`,children:r}),!e.isHub&&i!==null&&d(`div`,{className:`w-full whitespace-normal text-right text-[10px] text-foreground-subtle`,"data-testid":`mesh-reason-${e.nodeId}`,children:i})]})}function Cr(e){return[{key:`node`,header:J.t(`certificates.nodesColumns.node`,`Node`),sortValue:e=>e.isHub?``:e.nodeId.toLowerCase(),render:e=>a(`div`,{className:`flex items-center gap-1.5`,children:[d(`span`,{className:`font-medium text-foreground`,children:e.nodeId}),e.nodeId===`hub`&&d(U,{variant:`info`,className:`text-[10px]`,children:J.t(`common.hubWord`)}),!e.online&&d(U,{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=>d(_r,{row:e})},{key:`https-expires`,header:J.t(`certificates.nodesColumns.httpsExpires`,`HTTPS expires`),sortValue:e=>hr(e),render:t=>d(gr,{ms:hr(t),now:e.now})},{key:`identity`,header:J.t(`certificates.nodesColumns.identity`,`Identity`),sortValue:e=>e.mesh?.current?.serial??null,render:e=>d(vr,{row:e})},{key:`identity-expires`,header:J.t(`certificates.nodesColumns.identityExpires`,`Identity expires`),sortValue:e=>e.mesh?.current?.notAfter??null,render:t=>d(gr,{ms:t.mesh?.current?.notAfter??null,now:e.now})},{key:`presenting`,header:J.t(`certificates.nodesColumns.inUse`,`In use`),notSortableReason:`Offline nodes have no answer to order by.`,render:e=>d(yr,{row:e})},{key:`actions`,header:J.t(`certificates.nodesColumns.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order.`,render:t=>d(Sr,{row:t,o:e})}]}e();function wr(){let{t:e}=Y(),t=H(),i=W.useUtils(),o=Un(6e4),s=W.certificates.listHttpsCertificates.useQuery(),c=W.certificates.getMeshCertificates.useQuery(),[l,u]=r(null),[f,p]=r(null),[m,h]=r(null),g=()=>{h(null),i.certificates.listHttpsCertificates.invalidate(),i.certificates.getMeshCertificates.invalidate()},_=e=>(t,n)=>{h(null),u(`${n.nodeId}: ${e} - ${t.message}`)},v=W.certificates.renewHttpsOnNode.useMutation({onSuccess:(t,n)=>{p({tone:`success`,message:t.restartRequired?e(`certificates.nodesCard.newCertificateIssuedRestartThe`,`{{nodeId}}: new certificate issued. Restart the node to serve it.`,{nodeId:n.nodeId}):e(`certificates.nodesCard.newCertificateIssuedAndServed`,`{{nodeId}}: new certificate issued and served.`,{nodeId:n.nodeId})}),g()},onError:_(`renewal failed`)}),y=W.certificates.renewMeshOnNode.useMutation({onSuccess:e=>{p(Vt(e)),g()},onError:_(`renewal could not start`)}),b=W.certificates.revokeMeshOnNode.useMutation({onSuccess:e=>{p({tone:`success`,message:`${e.nodeId}: ${e.next}`}),g()},onError:_(`revoke failed`)}),x=v.isPending||y.isPending||b.isPending,S=(e,t)=>{u(null),p(null),h({nodeId:e,action:t})},C=async n=>{await t({title:e(`certificates.nodesCard.renewHttpsOn`,`Renew HTTPS on "{{nodeId}}"?`,{nodeId:n.nodeId}),message:n.isHub?e(`certificates.nodesCard.aNewCertificateIsIssued`,`A new certificate is issued from the local CA. Clients that trust the CA keep working.`):e(`certificates.nodesCard.theNodeMakesANew`,`The node makes a new key, the hub signs it and the node switches over without a restart. It keeps serving what it had if anything fails.`),confirmLabel:e(`certificates.nodesCard.renew`,`Renew`)})&&(S(n.nodeId,`renew-https`),v.mutate({nodeId:n.nodeId}))},T=e=>{S(e.nodeId,`renew-identity`),y.mutate({nodeId:e.nodeId})},E=async n=>{await t({title:e(`certificates.nodesCard.revokeTheIdentityOf`,`Revoke the identity of "{{nodeId}}"?`,{nodeId:n.nodeId}),message:e(`certificates.nodesCard.isDisconnectedAtOnceAnd`,`{{nodeId}} is disconnected at once and can no longer connect. To bring it back it must be paired again from System → Cluster → Agents. It stays in the node list until you forget it on the Cluster page. This cannot be undone.`,{nodeId:n.nodeId}),confirmLabel:e(`certificates.nodesCard.revokeAndDisconnect`,`Revoke and disconnect`),variant:`danger`})&&(S(n.nodeId,`revoke-identity`),b.mutate({nodeId:n.nodeId}))},D=Cr({now:o,busy:x,running:m,onRenewHttps:e=>void C(e),onRenewIdentity:T,onRevokeIdentity:e=>void E(e)}),O=n(()=>lr(s.data??[],c.data),[s.data,c.data]),k=c.data?.registryAvailable??!0;return d(X,{id:`nodes`,title:e(`certificates.nodesCard.nodes`,`Nodes`),icon:w,description:e(`certificates.nodesCard.eachNodeHoldsTwoCertificates`,`Each node holds two certificates: one it serves over HTTPS, one that proves its identity to the hub. Renewing replaces a certificate without a gap; revoking an identity cuts the node off until it re-joins.`),notice:Bt(l,f),onDismissNotice:()=>{u(null),p(null)},children:d(Bn,{isPending:s.isPending||c.isPending,error:s.error??c.error,what:`node certificates`,onRetry:()=>{s.refetch(),c.refetch()},children:a(`div`,{className:`space-y-3`,children:[d(cr,{https:s.data??[],mesh:c.data,now:o}),d(Ie,{columns:D,rows:O,rowKey:e=>e.nodeId,minWidthPx:960,maxBodyHeight:Ee,defaultSort:{columnKey:`node`,dir:`asc`},emptyMessage:k?e(`certificates.nodesCard.noNodesReported`,`No nodes reported.`):e(`certificates.nodesCard.theCertificateRegistryIsNot`,`The certificate registry is not available yet, so nodes cannot be listed.`)})]})})})}function Tr({pairOpen:e,onPairClose:t}){return a(`div`,{className:`space-y-4`,"data-testid":`certificates-page`,children:[d(Yn,{pairOpen:e,onPairClose:t}),d(Vn,{}),d(ar,{}),d(wr,{})]})}function Er({userId:e,username:t,onClose:n}){let{t:r}=Y(),i=H(),o=W.useUtils(),s=nt({userId:e}),c=W.auth.listLoginMethods.useQuery(),l=ft({onSuccess:()=>void o.userManagement.listExternalIdentities.invalidate()}),u=new Map((c.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),f=s.data??[],p=async(n,a)=>{await i({title:r(`users.externalIdentitiesModal.removeSignInLink`,`Remove sign-in link`),message:r(`users.externalIdentitiesModal.willNoLongerBeAble`,`"{{username}}" will no longer be able to sign in with this {{label}} account.`,{username:t,label:a}),confirmLabel:r(`common.remove`,`Remove`),variant:`danger`})&&l.mutate({userId:e,provider:n.provider,subject:n.subject})};return d(Se,{open:!0,onOpenChange:e=>!e&&n(),children:a(Pe,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`external-identities-modal`,children:[d(it,{children:a(Ve,{className:`flex items-center gap-2`,children:[d(D,{className:`h-4 w-4 text-primary`}),a(`span`,{children:[r(`users.externalIdentitiesModal.linkedSignInAccounts`,`Linked sign-in accounts`),a(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[r(`users.externalIdentitiesModal.user`,`User:`),` `,d(`span`,{className:`font-mono`,children:t})]})]})]})}),d(pe,{className:`space-y-3`,children:s.isLoading?a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(A,{className:`h-3.5 w-3.5 animate-spin`}),r(`common.loading`,`Loading…`)]}):f.length===0?d(`p`,{className:`text-xs text-foreground-subtle`,children:r(`users.externalIdentitiesModal.noLinkedAccountsOnlyThe`,`No linked accounts. Only the user can link one, from their own profile page.`)}):d(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:f.map(e=>{let t=u.get(e.provider),n=t??e.provider;return a(`li`,{className:`flex items-center gap-3 px-3 py-2 text-xs`,children:[a(`div`,{className:`flex-1 min-w-0`,children:[a(`div`,{className:`font-medium text-foreground truncate`,children:[n,t===void 0&&d(`span`,{className:`ml-2 rounded bg-foreground-subtle/15 px-1.5 py-0.5 text-[10px] font-normal text-foreground-subtle`,children:r(`users.externalIdentitiesModal.providerUnavailable`,`provider unavailable`)})]}),a(`div`,{className:`text-[11px] text-foreground-subtle truncate`,children:[e.label??e.subject,` ·`,` `,new Date(e.linkedAt).toLocaleDateString()]})]}),a(`button`,{onClick:()=>void p(e,n),disabled:l.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[d(fe,{className:`h-3 w-3`}),r(`common.remove`,`Remove`)]})]},`${e.provider}|${e.subject}`)})})}),d(Qe,{children:d(q,{onClick:n,variant:`secondary`,children:r(`common.close`,`Close`)})})]})})}function Dr({userId:e,username:t,onClose:n}){let{t:r}=Y(),i=c(),o=H(),l=Fe({userId:e}),u=l.data,p=()=>i.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),m=Ne({onSuccess:()=>{p(),n()}}),h=l.isLoading?`loading`:u?.enabled?`enrolled`:`not_enrolled`;return d(Se,{open:!0,onOpenChange:e=>!e&&n(),children:a(Pe,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[d(it,{children:a(Ve,{className:`flex items-center gap-2`,children:[d(f,{className:`h-4 w-4 text-primary`}),a(`span`,{children:[r(`users.totpModal.twoFactorAuthentication`,`Two-factor authentication`),a(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[r(`users.totpModal.user`,`User:`),` `,d(`span`,{className:`font-mono`,children:t})]})]})]})}),a(pe,{className:`space-y-4`,children:[h===`loading`&&a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(A,{className:`h-3.5 w-3.5 animate-spin`}),r(`users.totpModal.checkingStatus`,`Checking status…`)]}),h===`not_enrolled`&&a(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[d(k,{className:`h-4 w-4 mt-0.5 shrink-0`}),a(`div`,{children:[d(`div`,{className:`font-medium text-foreground`,children:r(`users.totpModal.2faNotEnrolled`,`2FA not enrolled`)}),d(`p`,{className:`mt-0.5`,children:r(`users.totpModal.onlyTheUserThemselvesCan`,`Only the user themselves can enable 2FA, from their own profile page.`)})]})]}),h===`enrolled`&&u&&a(s,{children:[a(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[d(O,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),a(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[d(`div`,{className:`font-medium`,children:r(`users.totpModal.2faIsActive`,`2FA is active`)}),d(`div`,{className:`text-foreground-subtle`,children:r(`common.enrolledOn`,{when:u.confirmedAt?new Date(u.confirmedAt).toLocaleString():`—`})})]})]}),d(`div`,{className:`text-[11px] text-foreground-subtle`,children:r(`users.totpModal.removingHereClearsTheServer`,`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`)}),a(`div`,{className:`flex justify-end gap-2`,children:[d(q,{onClick:n,variant:`secondary`,children:r(`common.close`,`Close`)}),a(`button`,{onClick:async()=>{await o({title:r(`users.totpModal.remove2fa`,`Remove 2FA`),message:r(`users.totpModal.removeTwoFactorAuthenticationFor`,`Remove two-factor authentication for "{{username}}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,{username:t}),confirmLabel:r(`common.remove`,`Remove`),variant:`danger`})&&m.mutate({userId:e})},disabled:m.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[m.isPending?d(A,{className:`h-3 w-3 animate-spin`}):d(T,{className:`h-3 w-3`}),r(`users.totpModal.remove2fa`,`Remove 2FA`)]})]})]})]})]})})}e();function Or({userId:e,username:t,onClose:n}){let{t:i}=Y(),{user:o,logout:s}=gt(),c=o?.id===e,l=H(),u=W.useUtils(),f=W.auth.listSessions.useQuery({userId:e}),[p,m]=r(null),h=W.auth.revokeSessions.useMutation({onSuccess:(e,t)=>{if(c&&`userId`in t){s();return}u.auth.listSessions.invalidate()},onError:e=>m(`Sign out failed: ${e.message}`)}),g=async e=>{await l({title:i(`users.userSessionsModal.signOutThisSession`,`Sign out this session`),message:i(`users.userSessionsModal.onWillHaveToSign`,`"{{username}}" on {{label}} will have to sign in again.`,{username:t,label:Yt(e.client).label}),confirmLabel:i(`users.userSessionsModal.signOut`,`Sign out`),variant:`danger`})&&(m(null),h.mutate({id:e.id}))},_=async()=>{await l({title:i(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`),message:c?i(`users.userSessionsModal.everySessionOfYourOwn`,`Every session of your own account ends, this browser included: you will be signed out here too.`):i(`users.userSessionsModal.everySessionOfEndsAt`,`Every session of "{{username}}" ends at once; each device has to sign in again.`,{username:t}),confirmLabel:i(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`),variant:`danger`})&&(m(null),h.mutate({userId:e}))},v=h.isPending&&h.variables!==void 0&&`id`in h.variables?h.variables.id:null;return d(Se,{open:!0,onOpenChange:e=>!e&&n(),children:a(Pe,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`user-sessions-modal`,children:[d(it,{children:a(Ve,{className:`flex items-center gap-2`,children:[d(de,{className:`h-4 w-4 text-primary`}),a(`span`,{children:[i(`users.userSessionsModal.activeSessions`,`Active sessions`),a(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[i(`users.userSessionsModal.user`,`User:`),` `,d(`span`,{className:`font-mono`,children:t})]})]})]})}),a(pe,{className:`space-y-3`,children:[p!==null&&d(`div`,{className:`text-[11px] text-danger`,children:p}),d(qt,{sessions:f.data??[],isLoading:f.isLoading,loadError:f.isError?f.error?.message??`Request failed`:null,emptyText:`No active sessions.`,onRevoke:e=>void g(e),revokingId:v})]}),a(Qe,{className:`justify-between`,children:[a(`button`,{onClick:()=>void _(),disabled:h.isPending||(f.data??[]).length===0,className:`inline-flex items-center gap-1.5 rounded border border-danger/40 px-2.5 py-1 text-[11px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,children:[h.isPending&&v===null?d(A,{className:`h-3 w-3 animate-spin`}):d(le,{className:`h-3 w-3`}),i(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`)]}),d(q,{onClick:n,variant:`secondary`,children:i(`common.close`,`Close`)})]})]})})}function kr({icon:e,label:t,count:n,all:r,total:i}){let{t:o}=Y();return a(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[d(e,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),d(`span`,{className:`min-w-0 flex-1 text-foreground-subtle`,children:t}),d(`span`,{className:n===0?`text-foreground-subtle`:`font-medium text-foreground`,children:n===0?o(`common.none`):r?o(`users.scopePreview.all`,`all {{total}}`,{total:i}):o(`users.scopePreview.of`,`{{count}} of {{total}}`,{count:n,total:i})})]})}function Ar({scopes:e,isAdmin:t,invalidReason:n}){let{t:r}=Y(),i=ee(),c=o({queryKey:[`auth`,`previewScope`,e,t],enabled:n===null,queryFn:()=>i.trpcClient.auth.previewScope.query({scopes:[...e],isAdmin:t})}),{data:l}=Te({projection:`slim`}),u=l?.length??0;if(n!==null)return d(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:a(`p`,{className:`flex items-center gap-1.5 text-[11px] text-warning`,children:[d(C,{className:`h-3 w-3 shrink-0`}),n]})});if(c.isLoading)return a(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface p-3 text-[11px] text-foreground-subtle`,children:[d(A,{className:`h-3 w-3 animate-spin`}),r(`users.scopePreview.resolving`,`Resolving…`)]});if(c.isError||!c.data)return d(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:d(`p`,{className:`text-[11px] text-danger`,children:r(`users.scopePreview.couldNotResolveThisGrant`,`Could not resolve this grant set. Saving is still allowed — the server enforces the same rules either way.`)})});let f=c.data;return d(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-3`,children:f.isAdmin?a(`p`,{className:`text-[11px] text-foreground`,children:[d(`span`,{className:`font-medium`,children:r(`users.scopePreview.administrator`,`Administrator`)}),` `,r(`users.scopePreview.unrestricted`)]}):a(s,{children:[d(kr,{icon:v,label:r(`users.scopePreview.devicesTheyCanSee`,`Devices they can see`),count:f.device.view.deviceCount,all:f.device.view.all,total:u}),d(kr,{icon:m,label:r(`users.scopePreview.devicesTheyCanOperate`,`Devices they can operate`),count:f.device.create.deviceCount,all:f.device.create.all,total:u}),d(kr,{icon:g,label:r(`users.scopePreview.devicesTheyCanDelete`,`Devices they can delete`),count:f.device.delete.deviceCount,all:f.device.delete.all,total:u}),a(`div`,{className:`border-t border-border pt-2 text-[10px] text-foreground-subtle`,children:[r(`users.scopePreview.systemAccess`,`System access:`),` `,f.system.length===0?r(`common.none`):f.system.join(`, `),f.capabilities.length>0&&a(s,{children:[` `,r(`users.scopePreview.extraCapabilities`,`· Extra capabilities:`),` `,f.capabilities.map(e=>e.name).join(`, `)]}),f.addons.length>0&&a(s,{children:[` `,r(`users.scopePreview.addons`,`· Addons:`),` `,f.addons.map(e=>e.name).join(`, `)]})]}),f.device.view.deviceCount===0&&d(`p`,{className:`text-[10px] text-warning`,children:r(`users.scopePreview.thisUserWillNotBe`,`This user will not be able to see any device.`)})]})})}e();function jr(e){let t=ie(e);return t===null?{mode:e.length===0?`role`:`advanced`,roleId:null,selector:{kind:`all`},includeLinked:!0,advancedScopes:e}:{mode:`role`,roleId:t.roleId,selector:t.selector,includeLinked:t.includeLinked,advancedScopes:e}}function Mr(e){return e.mode===`advanced`?e.advancedScopes:e.roleId===null?[]:re({roleId:e.roleId,selector:e.selector,includeLinked:e.includeLinked})}function Nr({user:e,onClose:t,onSubmit:i,submitting:o,callerScopes:c}){let{t:l}=Y(),u=N(),f=n(()=>jr(e.scopes??[]),[e.scopes]),[p,m]=r(f),[h,g]=r(f.mode===`advanced`),_=n(()=>Mr(p),[p]),v=!e.isAdmin&&p.mode===`role`&&p.roleId===null,y=n(()=>e.isAdmin?null:p.mode===`role`&&p.roleId===null?l(`users.userAccessModal.pickAccess`):He(_,u),[e.isAdmin,p.mode,p.roleId,_]),b=e=>m({...p,...e});return d(Se,{open:!0,onOpenChange:e=>!e&&t(),children:a(Pe,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-2xl`,children:[a(it,{children:[d(Ve,{children:l(`users.userAccessModal.title`,{name:e.username})}),d(`p`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?l(`users.userAccessModal.thisUserIsAnAdministrator`,`This user is an administrator — they can do everything, and the settings below are ignored.`):l(`users.userAccessModal.chooseWhatTheyCanDo`,`Choose what they can do, then which devices it applies to.`)})]}),a(pe,{className:`space-y-4`,children:[v&&a(`div`,{className:`flex items-start gap-2 rounded-lg border border-warning/40 bg-warning/10 p-3`,children:[d(C,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`}),a(`p`,{className:`text-[11px] text-foreground`,children:[d(`span`,{className:`font-medium`,children:l(`users.userAccessModal.noAccess`,`No access.`)}),` `,d(`span`,{className:`text-foreground-subtle`,children:l(`users.userAccessModal.cannotSeeAnything`,{name:e.username})})]})]}),a(`section`,{className:`space-y-2`,children:[d(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:l(`users.userAccessModal.1WhatCanTheyDo`,`1 · What can they do`)}),d(`div`,{className:`space-y-1.5`,children:R.map(e=>{let t=p.mode===`role`&&p.roleId===e.id;return a(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-lg border p-2.5 transition-colors ${t?`border-primary bg-primary/5`:`border-border hover:bg-foreground-subtle/5`}`,children:[d(`input`,{type:`radio`,name:`access-role`,checked:t,onChange:()=>b({mode:`role`,roleId:e.id}),className:`mt-0.5 border-border focus:ring-primary`}),a(`span`,{className:`min-w-0`,children:[d(`span`,{className:`block text-[12px] font-medium text-foreground`,children:e.label}),d(`span`,{className:`mt-0.5 block text-[10px] text-foreground-subtle`,children:e.description})]})]},e.id)})}),a(`button`,{type:`button`,onClick:()=>{if(!h){m({...p,mode:`advanced`,advancedScopes:_}),g(!0);return}g(!1),m(jr(p.advancedScopes))},className:`inline-flex items-center gap-1 rounded px-1.5 py-1 text-[10px] text-foreground-subtle transition-colors hover:bg-foreground-subtle/10 hover:text-foreground`,children:[d(h?F:I,{className:`h-3 w-3`}),l(`users.userAccessModal.advancedEditRawGrants`,`Advanced — edit raw grants`)]}),h&&a(`div`,{className:`rounded-lg border border-border p-2`,children:[d(`p`,{className:`mb-2 text-[10px] text-foreground-subtle`,children:l(`users.userAccessModal.oneRowPerGrantAnything`,`One row per grant. Anything expressible here overrides the three roles above; close this section to go back to them.`)}),d(at,{value:p.advancedScopes,onChange:e=>b({mode:`advanced`,advancedScopes:e}),clampToParent:c,emptyHint:d(s,{children:d(_t,{i18nKey:`users.userAccessModal.noGrants`,values:{name:e.username},components:{b:d(`span`,{className:`font-medium text-foreground`})}})})})]})]}),p.mode===`role`&&a(`section`,{className:`space-y-2`,children:[d(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:l(`users.userAccessModal.2OnWhichDevices`,`2 · On which devices`)}),d(ge,{value:p.selector,onChange:e=>b({selector:e}),includeLinked:p.includeLinked,onIncludeLinkedChange:e=>b({includeLinked:e}),clampToDeviceIds:null})]}),a(`section`,{className:`space-y-2`,children:[d(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:p.mode===`role`?l(`users.userAccessModal.3Result`,`3 · Result`):l(`users.userAccessModal.2Result`,`2 · Result`)}),d(Ar,{scopes:_,isAdmin:e.isAdmin,invalidReason:y})]})]}),a(Qe,{children:[d(q,{variant:`outline`,size:`sm`,onClick:t,children:l(`common.cancel`,`Cancel`)}),d(q,{size:`sm`,onClick:()=>i([..._]),disabled:o||y!==null,children:o?d(A,{className:`h-3 w-3 animate-spin`}):l(`users.userAccessModal.saveAccess`,`Save access`)})]})]})})}e();var Pr=8;function Fr(){return{username:``,password:``,isAdmin:!1}}function Ir(e){return{id:e.id,username:e.username,password:``,isAdmin:e.isAdmin}}function Lr(e){return e instanceof Error?e.message:J.t(`admin.system.users.genericError`)}function Rr(){let{t:e}=Y(),n=c(),{user:i}=gt(),{state:o,openNew:l,openEdit:u,close:p}=Je(),[h,_]=r(null),[v,b]=r(null),[x,S]=r(!1),{data:C,isLoading:w,isError:T,error:O,refetch:k}=Be(),ee=H(),j=We(),M=()=>n.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),N=Ye(),F=st({onSuccess:M}),I=ke({onSuccess:M}),L=ze({onSuccess:M}),te=lt({onSuccess:()=>{M(),R(null)}}),[ne,R]=r(null),[z,re]=r(null),[ie,ae]=r(null),[oe,se]=r(null),B=C??[],V=o.mode===`edit`?B.find(e=>e.id===o.id)??null:null,le=()=>{_(null),b(null),S(!1),N.reset(),I.reset(),p()};t(()=>{if(o.mode===`closed`){_(null),b(null),S(!1);return}if(o.mode===`new`){_(e=>e!==null&&e.id===void 0?e:Fr());return}if(V===null){w||p();return}_(e=>e?.id===V.id?e:Ir(V))},[o,V,w,p]);let ue=o.mode===`new`&&h!==null&&h.id===void 0||o.mode===`edit`&&h!==null&&V!==null;async function fe(t){await ee({title:e(`admin.system.users.deleteUser`,`Delete user`),message:e(`admin.system.users.permanentlyDeleteUserThisCannot`,`Permanently delete user "{{username}}"? This cannot be undone — any active sessions will be revoked on next request.`,{username:t.username}),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&(F.mutate({id:t.id}),o.mode===`edit`&&o.id===t.id&&le())}async function pe(t){let n=await j({title:e(`admin.system.users.resetPassword`,`Reset password`),message:e(`admin.system.users.setANewPasswordFor`,`Set a new password for "{{username}}".`,{username:t.username}),label:e(`admin.system.users.newPassword`,`New password`),inputType:`password`,placeholder:e(`admin.system.users.atLeast8Characters`,`At least 8 characters`),confirmLabel:e(`admin.system.users.continue`,`Continue`),validate:e=>e.length<Pr?J.t(`admin.system.users.passwordTooShort`,{min:Pr}):null});n===null||n.length===0||await ee({title:e(`admin.system.users.resetPassword`,`Reset password`),message:e(`admin.system.users.resetThePasswordForThey`,`Reset the password for "{{username}}"? They will need to use the new password on their next login.`,{username:t.username}),confirmLabel:e(`common.reset`,`Reset`)})&&L.mutate({id:t.id,newPassword:n})}function me(e,t){t!==e.isAdmin&&I.mutate({id:e.id,isAdmin:t})}async function ge(){if(h!==null){b(null);try{if(h.id===void 0){let e=h.username.trim();if(e===``||h.password.length<Pr)return;await N.mutateAsync({username:e,password:h.password,isAdmin:h.isAdmin})}else await I.mutateAsync({id:h.id,isAdmin:h.isAdmin});M(),le()}catch(e){b(Lr(e))}}}function _e(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}let ve=N.isPending||I.isPending,be=h!==null&&h.id===void 0&&h.username.trim()!==``&&h.password.length>=Pr,xe=h!==null&&h.id!==void 0,Se=ve||(h?.id===void 0?!be:!xe),U=e=>F.isPending&&F.variables?.id===e.id||I.isPending&&I.variables?.id===e.id||L.isPending&&L.variables?.id===e.id,Ce=[{key:`username`,header:e(`admin.system.users.username`,`Username`),sortValue:e=>e.username,render:e=>d(`span`,{className:`font-medium text-foreground`,"data-testid":`user-open-${e.id}`,children:e.username})},{key:`isAdmin`,header:e(`admin.system.users.admin`,`Admin`),nowrap:!0,sortValue:e=>+!!e.isAdmin,render:t=>d(`span`,{onClick:e=>e.stopPropagation(),children:a(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[d(`input`,{type:`checkbox`,checked:t.isAdmin,onChange:e=>me(t,e.target.checked),disabled:U(t),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),d(`span`,{className:t.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:t.isAdmin?e(`admin.system.users.admin`,`Admin`):e(`admin.system.users.regular`,`Regular`)})]})})},{key:`scopes`,header:e(`admin.system.users.access`,`Access`),render:t=>t.isAdmin?d(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:e(`admin.system.users.everythingAdmin`,`everything (admin)`)}):d(`span`,{onClick:e=>e.stopPropagation(),children:a(q,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>R(t),title:e(`admin.system.users.configureAccess`,`Configure access`),children:[d(P,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),d(zr,{scopes:t.scopes??[]})]})})},{key:`createdAt`,header:e(`admin.system.users.created`,`Created`),nowrap:!0,sortValue:e=>e.createdAt,render:e=>d(`span`,{className:`text-foreground-subtle`,children:_e(e.createdAt)})},{key:`actions`,header:e(`admin.system.users.actions`,`Actions`),align:`right`,nowrap:!0,notSortableReason:`Row actions`,render:t=>{let n=U(t),r=t.id!==i?.id&&t.totpEnabled;return a(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[a(q,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>u(t.id),disabled:n,title:e(`admin.system.users.editUser`,`Edit user`),children:[d(m,{className:`h-3 w-3`}),e(`common.edit`,`Edit`)]}),r&&a(q,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>re(t),disabled:n,title:e(`admin.system.users.removeTwoFactorAuthentication`,`Remove two-factor authentication`),children:[d(f,{className:`h-3 w-3`}),e(`admin.system.users.remove2fa`,`Remove 2FA`)]}),a(q,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>ae(t),disabled:n,title:e(`admin.system.users.linkedSignInAccounts`,`Linked sign-in accounts`),children:[d(D,{className:`h-3 w-3`}),e(`admin.system.users.signInLinks`,`Sign-in links`)]}),a(q,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>se(t),disabled:n,title:e(`admin.system.users.activeSessions`,`Active sessions`),children:[d(de,{className:`h-3 w-3`}),e(`admin.system.users.sessions`,`Sessions`)]}),a(q,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void pe(t),disabled:n,title:e(`admin.system.users.resetPassword`,`Reset password`),children:[d(ce,{className:`h-3 w-3`}),e(`admin.system.users.resetPassword`,`Reset password`)]}),a(q,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void fe(t),disabled:n,title:e(`admin.system.users.deleteUser`,`Delete user`),className:`text-danger hover:bg-danger/10`,children:[n?d(A,{className:`h-3 w-3 animate-spin`}):d(g,{className:`h-3 w-3`}),e(`common.delete`,`Delete`)]})]})}}];return a(Tt,{embedded:!0,icon:y,title:e(`admin.system.users.users`,`Users`),subtitle:e(`admin.system.users.hubAccountsAdminFlagAccess`,`Hub accounts, admin flag, access scopes, sessions and sign-in links.`),actions:a(q,{size:`sm`,type:`button`,onClick:()=>{b(null),l()},children:[d(E,{className:`h-3.5 w-3.5`}),e(`admin.system.users.createUser`,`Create User`)]}),children:[T&&d(G,{title:e(`admin.system.users.couldNotLoadUsers`,`Could not load users`),message:Lr(O),onRetry:()=>void k()}),w&&a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(A,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}),!w&&!T&&B.length===0&&d(et,{icon:y,title:e(`admin.system.users.noUsersYet`,`No users yet`),description:e(`admin.system.users.createAUserToGrant`,`Create a user to grant hub access.`)}),!w&&!T&&B.length>0&&d(Ie,{columns:Ce,rows:B,rowKey:e=>e.id,minWidthPx:560,maxBodyHeight:`max-h-[60vh]`,onRowClick:e=>u(e.id)}),d(Me,{open:ue,onClose:le,title:h?.id===void 0?e(`admin.system.users.createUser`,`Create User`):e(`admin.system.users.edit`,`Edit {{value1}}`,{value1:h.username||`user`}),icon:y,error:v,testId:`user-form-dialog`,footer:d(q,{size:`sm`,type:`button`,disabled:Se,onClick:()=>void ge(),children:ve?a(s,{children:[d(A,{className:`h-3.5 w-3.5 animate-spin`}),e(`admin.system.users.saving`,`Saving…`)]}):h?.id===void 0?e(`admin.system.users.create`,`Create`):e(`common.save`,`Save`)}),children:h!==null&&a(`div`,{className:`space-y-3`,children:[d(ct,{label:e(`admin.system.users.username`,`Username`),required:h.id===void 0,children:d(he,{value:h.username,onChange:e=>_({...h,username:e.target.value}),placeholder:`john`,autoFocus:h.id===void 0,disabled:h.id!==void 0,"data-testid":`user-form-username`})}),h.id===void 0&&d(ct,{label:e(`admin.system.users.password`,`Password`),required:!0,description:e(`admin.system.users.atLeastCharacters`,`At least {{value1}} characters.`,{value1:String(Pr)}),children:d(ye,{value:h.password,onValueChange:e=>_({...h,password:e}),shown:x,onToggleShown:()=>S(e=>!e),placeholder:`••••••••`,"data-testid":`user-form-password`})}),d(ct,{label:e(`admin.system.users.admin`,`Admin`),description:e(`admin.system.users.unrestrictedAccessToEveryCapability`,`Unrestricted access to every capability and device.`),children:a(`label`,{className:`inline-flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[d(`input`,{type:`checkbox`,checked:h.isAdmin,onChange:e=>_({...h,isAdmin:e.target.checked}),className:`rounded border-border focus:ring-primary`,"data-testid":`user-form-admin`}),d(`span`,{children:e(`admin.system.users.admin`,`Admin`)})]})}),h.id!==void 0&&d(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`admin.system.users.toChangeThePasswordUse`,`To change the password, use Reset password on the user's row. Access scopes are configured from the Access column.`)})]})}),z&&d(Dr,{userId:z.id,username:z.username,onClose:()=>re(null)}),ie&&d(Er,{userId:ie.id,username:ie.username,onClose:()=>ae(null)}),oe&&d(Or,{userId:oe.id,username:oe.username,onClose:()=>se(null)}),ne&&d(Br,{user:ne,onClose:()=>R(null),onSubmit:e=>te.mutate({userId:ne.id,scopes:e}),submitting:te.isPending})]})}function zr({scopes:e}){let{t}=Y(),n=N();if(e.length===0)return d(`span`,{className:`font-medium text-warning`,children:t(`admin.system.users.noAccess`,`No access`)});let r=ie(e);return r===null?d(`span`,{className:`text-foreground-subtle`,children:t(`users.customGrants`,{count:e.length})}):a(`span`,{className:`text-foreground-subtle`,children:[d(`span`,{className:`font-medium text-foreground`,children:z(r.roleId).label}),` ·`,` `,ut(r.selector,n)]})}function Br(e){let{user:t}=gt(),n=t?.isAdmin===!0;return d(Nr,{...e,callerScopes:n?null:t?.scopes??[]})}e();var Vr={"api-keys":$.tokens,"linked-sessions":$.linkedApps},Hr=`certificates`;function Ur(e){return a(q,{size:`sm`,type:`button`,"data-testid":`certificates-pair-device`,onClick:e,children:[d(f,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),J.t(`systemPage.identity.pairADevice`,`Pair a device`)]})}function Wr(){let{t:e}=Y(),[t]=Ct(),n=Tn(),[i,a]=r(!1),o=Vr[t.get(`tab`)??``];if(o!==void 0)return d(pt,{to:St(`access`,{integration:o}),replace:!0});let s=ht(`/system/identity`,{t:e,isAdmin:!0})??{icon:M,title:e(`system.identity`,`Identity & Access`)},c=t.get(`tab`)??`users`,l=t.get(`integration`),u=c===vt.access.tab?wn(l,n.requestCreate):c===`certificates`?Ur(()=>a(!0)):void 0;return d(wt,{icon:s.icon,title:s.title,defaultSection:`users`,sectionsLabel:`${s.title} sections`,actions:u,sections:[{id:`users`,label:e(`systemPage.identity.users`,`Users`),content:d(Rr,{})},{id:vt.access.tab,label:e(`systemPage.identity.tokensSessions`,`Tokens & sessions`),content:d(Cn,{createRequested:n.createRequested,onCreateConsumed:n.clearCreate}),ownedParams:xt.concat([Lt.token,Lt.scoped,Lt.admin])},{id:Hr,label:e(`systemPage.identity.certificates`,`Certificates`),content:d(Tr,{pairOpen:i,onPairClose:()=>a(!1)})},{id:vt.authentication.tab,label:e(`systemPage.identity.authentication`,`Authentication`),content:d(Rn,{}),ownedParams:xt}]})}export{Wr as IdentityPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{$ as e,B as t,G as n,J as r,L as i,S as a,o,q as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Cn as l,It as u,Nt as d,Rr as f,Si as p,Xi as m,bn as h,dt as g,ht as _,kn as v,or as y,ot as b,pi as x,pn as S,sa as C,si as w,un as ee,vn as T,xi as te,yi as E,zr as D}from"./player-overlays-D98Lvll4.js";import{di as O}from"./client-Cj9cIFJV.js";import{t as k}from"./search-x-DOr7Uth6.js";import{$n as A,Aa as j,At as ne,Ba as M,Bo as N,Da as P,Dt as re,Fa as F,Ho as I,Ia as L,Jr as R,Kn as z,Ko as B,Na as V,Oa as H,Ot as ie,Qn as U,Uo as ae,Va as W,Vo as oe,Vu as se,Wa as G,Wo as K,Wu as ce,Ya as le,Yr as ue,Zt as de,er as fe,fi as pe,io as me,ir as he,ja as ge,jn as _e,ka as ve,ln as q,no as J,rr as ye,xo as be,yn as xe,zo as Se}from"./src-MJ2k3G6o.js";import{t as Y}from"./useTranslation-D3Is_4B6.js";import{n as Ce}from"./addon-icons-context-BVO6QLZm.js";import{Z as we,et as Te,nt as Ee,tt as De,z as Oe}from"./index-CM1JjjBW.js";import{t as ke}from"./NodeAddonsSettingsPanel-CTmPFs3s.js";import{t as Ae}from"./device-integration-icon-CFPzExgG.js";import{n as je,r as X,t as Me}from"./ScanNetworkModal-CiOVqs0H.js";e();function Z(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Z(n.fields));return t}function Ne(e,t,a){let[o,s]=r(`idle`),[c,l]=r({}),u=n(()=>{let t=[];for(let n of e.sections)t.push(...Z(n.fields));return t},[e]),d=u.length>0&&a!==void 0,f=i(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:o,hasProbeFields:d,probeResults:c,handleTestAll:i(async()=>{if(!a)return;let e=u.filter(e=>{let n=t[e];return n!=null&&String(n).trim()!==``});if(e.length===0)return;s(`testing`);let n={};for(let t of e)n[t]={status:`probing`};l(n);let r=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await a(e,t[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),i={};for(let e of r)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;i[t]={status:n.status===`ok`?`ok`:`error`,result:n}}l(i),s(`idle`)},[a,u,t]),clearProbeResult:f}}e();function Pe(e){let t=[];for(let n of e)`required`in n&&n.required===!0&&`key`in n&&n.key&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Pe(n.fields));return t}function Fe(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Ie(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Ie(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function Le(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function Re({open:e,integrationId:s,addonId:l,onClose:u}){let{t:f}=Y(),p=o(),[m,h]=r({}),[v,b]=r(!1),[x,C]=r(null),[w,ee]=r(Le),T=J({addonId:l},{enabled:e}),E=T.data?.deviceType??null,D=G({addonId:l,type:E??O.Camera},{enabled:e&&T.isSuccess&&E!==null}),k=D.data??null;t(()=>{e&&(h(k?Ie(k.sections.flatMap(e=>e.fields)):{}),ee(Le()),b(!1),C(null))},[e,s,k]);let A=n(()=>({...m,_probeRequestId:w}),[m,w]),j=F({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ne=be(),M=i(async(e,t)=>{b(!0);let n=await ne.mutateAsync({addonId:l,type:E??O.Camera,key:e,value:t,formValues:A});return n.status===`ok`&&n.suggestedValues&&h(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Fe(e[i])&&!Fe(a)&&(r[i]=a,t=!0);return t?r:e}),n},[ne,l,A,E]),{testAllStatus:N,hasProbeFields:P,probeResults:re,handleTestAll:I,clearProbeResult:L}=Ne(k??{sections:[]},m,M);async function R(e){C(null);try{await j.mutateAsync({addonId:l,type:E??O.Camera,config:m,integrationId:s}),e?h(k?Ie(k.sections.flatMap(e=>e.fields)):{}):u()}catch(e){C(e instanceof Error?e.message:String(e))}}if(!e)return null;let z=Pe((k?.sections??[]).flatMap(e=>e.fields)).filter(e=>Fe(m[e])),B=z.length===0,V=T.isLoading||E!==null&&D.isLoading,H=T.isError||T.isSuccess&&E===null||D.isError||D.isSuccess&&k===null;return a(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:u}),a(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[calc(90dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl`,children:[a(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:f(`integrations.addDevice`)}),c(`button`,{onClick:u,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:c(g,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:V?c(`div`,{className:`flex items-center justify-center py-8`,children:c(y,{className:`h-5 w-5 animate-spin text-primary`})}):H?a(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[c(d,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),a(`div`,{className:`space-y-1`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:f(`integrations.addDeviceDialog.providerUnavailable`,`Provider unavailable`)}),c(`p`,{className:`text-xs text-foreground-subtle`,children:c(we,{i18nKey:`integrations.addDeviceDialog.notReady`,values:{addonId:l},components:{mono:c(`span`,{className:`font-mono`})}})})]})]}):c(Oe,{schema:k,values:m,onChange:h,onTestField:M,probeResults:re,onClearProbe:L})}),!H&&!V&&a(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[a(`button`,{type:`button`,onClick:()=>b(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[a(`span`,{className:`flex items-center gap-2`,children:[c(S,{className:`h-3.5 w-3.5`}),f(`integrations.addDeviceDialog.testLogs`,`Test logs`),c(`span`,{className:`font-mono text-[9px] opacity-60`,children:w.slice(0,14)})]}),c(te,{className:`h-3.5 w-3.5 transition-transform ${v?`rotate-180`:``}`})]}),v&&c(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:c(de,{addonId:l,requestId:w,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!H&&!V&&(x||z.length>0)&&c(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:a(`div`,{className:`flex items-start gap-2`,children:[c(d,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:x||f(`integrations.addDeviceDialog.required`,`Required: {{value1}}`,{value1:z.join(`, `)})})]})}),a(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[a(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:u,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:f(`integrations.cancel`)}),!H&&P&&a(`button`,{type:`button`,onClick:I,disabled:N===`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:[N===`testing`?c(y,{className:`h-3.5 w-3.5 animate-spin`}):c(_,{className:`h-3.5 w-3.5`}),f(`integrations.addDeviceDialog.testAll`,`Test All`)]})]}),a(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:()=>R(!0),disabled:H||!B||j.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:f(`integrations.saveAndNew`)}),c(`button`,{onClick:()=>R(!1),disabled:H||!B||j.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:j.isPending?f(`integrations.saving`):f(`integrations.save`)})]})]})]})]})}var Q=1500;function ze({addonId:e,integrationId:t,jobId:n,onFinished:r}){let{t:i}=Y(),o=P(),s=(j({addonId:e,integrationId:t},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?Q:!1}).data??[]).find(e=>e.jobId===n);if(!s)return null;let l=s.state===`running`,u=s.processed,f=s.total>0?Math.round(u/s.total*100):0;!l&&s.finishedAt!==null&&r();let p=[`${u}/${s.total} ${i(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];s.adopted>0&&p.push(`${s.adopted} ${i(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),s.alreadyAdopted>0&&p.push(`${s.alreadyAdopted} ${i(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),s.failed>0&&p.push(`${s.failed} ${i(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let m=p.join(` · `);return a(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[a(`div`,{className:`flex items-center gap-2`,children:[l?c(y,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):s.failed>0?c(d,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):s.state===`cancelled`?c(w,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):c(x,{className:`h-3.5 w-3.5 text-primary shrink-0`}),c(`p`,{className:`text-[11px] text-foreground`,children:m}),l&&c(`button`,{onClick:()=>o.mutate({jobId:n}),className:`ml-auto rounded-lg border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.adoptJobCancel`,{defaultValue:`Stop`})})]}),c(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:c(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${f}%`},role:`progressbar`,"aria-valuenow":f,"aria-valuemin":0,"aria-valuemax":100})}),s.results.filter(e=>e.outcome===`failed`).slice(0,5).map(e=>a(`p`,{className:`text-[11px] text-destructive`,children:[e.childNativeId,`: `,e.error]},e.childNativeId))]})}function Be(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}e();var $=`devices`;function Ve(e){return{id:$,label:e(`integrations.adoptDevicesModal.defaultFilter`),isDefault:!0}}var He=2e4,Ue=100;function We({addonId:e,integrationId:n,onClose:l}){let u=C(),{t:f}=Y(),m=o(),[h,_]=r(new Set),[v,b]=r(new Set),[x,S]=r(new Map),[w,ee]=r(null),{data:te}=oe(),E=(te??[]).find(t=>t.addonId===e)?.supportsLocationImport??!1,[D,O]=r(!0),k=H({addonId:e,integrationId:n}).data?.filters,A=k&&k.length>0?k:[Ve(f)],[j,ne]=r(A.find(e=>e.isDefault)?.id??(A.some(e=>e.id===$)?$:A[0].id)),M=j!==$,N=ge(),P=ve({addonId:e,integrationId:n,page:1,pageSize:He,filter:j}),F=P.refetch,I=N.mutate,L=i(()=>{I({addonId:e,integrationId:n},{onSettled:()=>{F()}})},[I,e,n,F]),R=s(null);t(()=>{let t=`${e}::${n}`;R.current===t||P.isLoading||(R.current=t,(P.data?.candidates.length??0)===0&&L())},[e,n,P.isLoading,P.data,L]);let z=N.isPending,B=N.isError?N.error instanceof Error?N.error.message:String(N.error):null,ie=typeof N.data?.lastError==`string`&&N.data.lastError.length>0?N.data.lastError:null,U=P.data?.candidates??[],ae=P.isError?P.error instanceof Error?P.error.message:String(P.error):null,W=V(),[G,K]=r(null),le=i(e=>{e.alreadyAdopted||_(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),ue=i(e=>{b(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),de=i((e,t)=>{S(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),fe=i(e=>{let t={};for(let n of e){let e=x.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[x]),pe=i(async()=>{ee(null);let t=[...h];if(t.length!==0)try{let r=fe(t),{jobId:i}=await W.mutateAsync({addonId:e,integrationId:n,filter:j,childNativeIds:t,...r?{perCandidate:r}:{},...E?{importLocations:D}:{}});K(i),_(new Set),S(new Map)}catch(e){ee(e instanceof Error?e.message:String(e))}},[h,fe,W,e,n,j,E,D]),me=s(null),he=i(()=>{G===null||me.current===G||(me.current=G,F(),m.invalidateQueries({queryKey:[[`integrations`]]}),m.invalidateQueries({queryKey:[[`deviceManager`]]}))},[G,F,m]),_e=i(e=>{ne(e),_(new Set),b(new Set),S(new Map),ee(null)},[]),q=h.size,J=G!==null&&q===0&&!W.isPending;return a(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:l}),a(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] rounded-xl border border-border bg-background shadow-2xl`,children:[a(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[a(`div`,{className:`min-w-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:f(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),c(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:f(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),a(`div`,{className:`flex items-center gap-3 shrink-0`,children:[E&&a(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[c(`input`,{type:`checkbox`,checked:D,onChange:e=>O(e.target.checked),className:`accent-primary`}),f(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),c(`button`,{onClick:l,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":f(`common.close`,`Close`),children:c(g,{className:`h-4 w-4`})})]})]}),a(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(B??ae??ie)&&U.length===0&&c(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:a(`div`,{className:`flex items-start gap-2`,children:[c(d,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),a(`div`,{className:`min-w-0`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:f(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),c(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:B??ae??ie})]})]})}),A.length>1&&c(Ge,{filters:A,activeFilter:j,onSelect:_e}),c(`div`,{className:`flex-1 min-h-0`,children:c(re,{mode:`generic`,items:U,pageSize:Ue,getKey:e=>e.childNativeId,getSearchText:Be,getFilterType:e=>e.type,filterOptions:se(u),filterLabel:f(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:P.isLoading||z&&U.length===0,searchPlaceholder:f(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(B??ae??ie)&&U.length===0?``:f(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:a(`button`,{type:`button`,onClick:L,disabled:z,title:f(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[c(T,{className:`h-3.5 w-3.5 ${z?`animate-spin`:``}`}),f(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:f(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>c(Ke,{candidate:e,expandable:!M,expanded:v.has(e.childNativeId),onToggleExpand:()=>ue(e.childNativeId),adoptedLabel:f(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:f(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=ce(e.type,u),n=t.icon;return a(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[c(n,{className:`h-3.5 w-3.5 shrink-0`}),t.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>c(`div`,{className:`flex items-center justify-end`,children:c(`button`,{onClick:()=>le(e),disabled:e.alreadyAdopted,"aria-label":h.has(e.childNativeId)?f(`integrations.adoptDevicesModal.deselect`,`Deselect`):f(`integrations.adoptDevicesModal.select`,`Select`),className:`inline-flex h-5 w-5 items-center justify-center rounded border ${h.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:h.has(e.childNativeId)&&c(p,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!M&&v.has(e.childNativeId),renderExpanded:M?void 0:e=>c(qe,{candidate:e,hiddenChildIds:x.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>de(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:h.has(e.childNativeId)?`bg-primary/5`:``})})]}),w&&c(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:a(`div`,{className:`flex items-start gap-2`,children:[c(d,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:w})]})}),G!==null&&c(ze,{addonId:e,integrationId:n,jobId:G,onFinished:he}),a(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[c(`div`,{}),a(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:l,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:f(`integrations.cancel`,{defaultValue:`Cancel`})}),a(`button`,{onClick:J?l:pe,disabled:!J&&(q===0||W.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:[W.isPending&&c(y,{className:`h-3.5 w-3.5 animate-spin`}),J?f(`integrations.close`,{defaultValue:`Close`}):f(`integrations.addSelected`,{defaultValue:`Add selected`}),!J&&q>0?` (${q})`:``]})]})]})]})]})}function Ge({filters:e,activeFilter:t,onSelect:n}){let{t:r}=Y();return c(`div`,{role:`tablist`,"aria-label":r(`integrations.adoptDevicesModal.discoveryGranularity`,`Discovery granularity`),className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return c(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function Ke({candidate:e,expandable:t,expanded:n,onToggleExpand:r,adoptedLabel:i}){let{t:o}=Y(),s=(e.children??[]).length;return a(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&s>0?a(`button`,{type:`button`,onClick:r,"aria-label":n?o(`integrations.adoptDevicesModal.collapse`,`Collapse`):o(`integrations.adoptDevicesModal.expand`,`Expand`),"aria-expanded":n,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[c(n?te:E,{className:`h-3.5 w-3.5`}),s]}):c(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),c(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&c(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:i})]})}function qe({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let{t:r}=Y(),i=e.children??[];return i.length===0?null:c(`div`,{className:`space-y-1 py-1`,children:i.map(e=>{let i=t.has(e.childNativeId),o=e.capabilities??[];return a(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${i?`opacity-50`:``}`,children:[c(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),o.length>0&&c(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:o.join(`, `)}),c(`button`,{onClick:()=>n(e.childNativeId),"aria-label":i?r(`integrations.adoptDevicesModal.showChild`,`Show child`):r(`integrations.adoptDevicesModal.hideChild`,`Hide child`),title:i?r(`integrations.adoptDevicesModal.showAfterAdopt`,`Show after adopt`):r(`integrations.adoptDevicesModal.hideAfterAdopt`,`Hide after adopt`),className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:c(i?D:f,{className:`h-3 w-3`})})]},e.childNativeId)})})}e();function Je(e){let t=[];for(let n of e){if(n.type===`group`){t.push(...Je(n.fields));continue}`key`in n&&typeof n.key==`string`&&t.push(n.key)}return t}function Ye(e,t){if(!e)return{};let n=new Set(e.sections.flatMap(e=>Je(e.fields))),r={};for(let e of n)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}function Xe(e){return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{if(`value`in e){let{value:t,...n}=e;return n}return e})}))}}function Ze({integrationId:e,addonId:t,name:r,kind:i,mode:s,brokerKind:l,canTest:u=!1,trpc:d,onClose:f}){let{t:p}=Y(),m=o(),{data:h,isLoading:g}=I({id:e},{enabled:s===`account`||s===`broker`}),_=n(()=>{let e=h?.brokerId;return typeof e==`string`?e:null},[h]),{data:v,isLoading:b}=R({addonId:t,nodeId:`hub`},{enabled:s===`account`}),x=n(()=>v?Xe(v):null,[v]),S=K(),C=(t,n)=>{S.mutate({id:e,settings:t,...n?{secretKeys:[...n]}:{}},{onSuccess:()=>{m.invalidateQueries(),f()}})};return c(U,{open:!0,onOpenChange:e=>!e&&f(),children:a(fe,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[c(ye,{children:a(he,{children:[p(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,r]})}),c(A,{children:s===`broker`?l?a(`div`,{className:`space-y-3`,children:[c(`p`,{className:`text-[11px] text-foreground-subtle`,children:p(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),_&&a(`p`,{className:`text-[11px] text-foreground`,children:[p(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,c(`span`,{className:`font-mono text-foreground-subtle`,children:_})]}),S.isPending?a(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(y,{className:`h-3 w-3 animate-spin`}),p(`integrations.saving`,{defaultValue:`Saving…`})]}):c(X,{kind:l,onResolved:e=>{C({brokerId:e})},onBack:f}),S.isError&&c(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):c(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):s===`account`?g||b?a(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(y,{className:`h-3 w-3 animate-spin`}),p(`integrations.loading`,{defaultValue:`Loading…`})]}):c(je,{addonId:t,configSchema:x,canTest:u,initialName:r,initialConfig:Ye(x,h??{}),submitLabel:p(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e,secretKeys:t})=>C(e,t),onBack:f}):c(z,{trpc:d,addonId:t,nodeId:`hub`,title:r})})]})})}function Qe(e){return e==null?!1:e.sections.some(e=>e.fields.length>0)}e();function $e(){let{t:e}=Y(),{integrationId:s}=De(),d=o(),f=Te(),[p,g]=Ee(),_=b(),[x,C]=r(!1),[w,T]=r(!1),[te,E]=r(!1),[D,O]=r(!1),{data:j,isLoading:P}=N({id:s??``},{enabled:!!s}),{data:F}=R({addonId:j?.addonId??``,nodeId:`hub`},{enabled:!!j?.addonId}),{data:I,isSuccess:z}=oe(),V=n(()=>{let e=j?.addonId;return!e||!z?null:(I??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[I,j?.addonId,z]),{data:H}=M({}),se=n(()=>(H?.providers??[]).some(e=>e.addonId===j?.addonId),[H,j?.addonId]),G=V!==null,K=j?.info?.fixed===!0,ce=G?V===`device-adoption`?e(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):e(`integrations.addDevice`):e(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),ge=n(()=>{let e=j?.addonId;return!e||!z?null:(I??[]).find(t=>t.addonId===e)?.brokerKind??null},[I,j?.addonId,z]),ve=n(()=>{let e=j?.addonId;return!e||!z?!1:(I??[]).find(t=>t.addonId===e)?.canTest===!0},[I,j?.addonId,z]),J=n(()=>{let e=j?.addonId;return!e||!z?null:(I??[]).find(t=>t.addonId===e)?.mode??null},[I,j?.addonId,z]);t(()=>{p.get(`add`)===`1`&&G&&(C(!0),g(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[p,G,g]);let be=F!=null&&Array.isArray(F.sections)&&F.sections.some(e=>e.fields.length>0),{data:Ce}=ue({addonId:j?.addonId??``,nodeId:`hub`},{enabled:!!j?.addonId&&J!==`account`}),we=J!==null&&J!==`account`&&Qe(Ce),Oe=n(()=>j?.addonId?[j.addonId]:[],[j?.addonId]),{data:je}=le({projection:`slim`},{refetchInterval:3e4}),X=[[`integrations`,`get`],{input:{id:s??``},type:`query`}],Z=B({onMutate:async e=>{await d.cancelQueries({queryKey:X});let t=d.getQueryData(X);return t!=null&&d.setQueryData(X,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&d.setQueryData(X,r.previous)},onSettled:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ne=Se({onSuccess:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]}),f(`/integrations`)}}),Pe=pe({onSuccess:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=me({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ie=L({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Le=W({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=n(()=>je??[],[je]),ze=n(()=>{let e=new Map;for(let t of Q)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[Q]),Be=i(e=>ze.get(e)??null,[ze]),{data:$}=ae(void 0),Ve=n(()=>ie($),[$]),He=i(e=>f(`/devices/${String(e)}`),[f]),Ue=n(()=>{let e=j?.id;return e?Q.filter(t=>{let n=Ve(t);return n.kind===`resolved`&&n.integration.id===e}):[]},[Q,j?.id,Ve]),Ge=n(()=>$===void 0?null:ne(Ue).length,[$,Ue])??`…`;return P?a(`div`,{className:`p-4`,children:[c(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),c(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):j?a(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[c(xe,{items:[{label:e(`integrationDetail.integrations`,`Integrations`),onClick:()=>f(`/integrations`)},{label:j.name}]}),a(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[a(`div`,{className:`flex items-center gap-3 min-w-0`,children:[c(et,{addonId:j.addonId}),a(`div`,{className:`min-w-0`,children:[c(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:j.name}),a(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[j.addonId,` · `,Ge,` `,e(`integrations.devices`)]})]})]}),a(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[se&&a(`button`,{onClick:()=>T(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:e(`integrationDetail.scanTheNetworkForDevices`,`Scan the network for devices (incl. a different subnet)`),children:[c(l,{className:`h-3.5 w-3.5`}),e(`integrationDetail.scanNetwork`,`Scan network`)]}),!K&&a(`button`,{onClick:()=>C(!0),disabled:!G,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:ce,children:[c(v,{className:`h-3.5 w-3.5`}),ce]}),a(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Z.isPending?`opacity-60`:``} ${j.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:e(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[c(_e,{checked:j.enabled,onCheckedChange:e=>Z.mutate({id:s,enabled:e}),disabled:Z.isPending,"aria-label":j.enabled?e(`integrationDetail.disableIntegration`,`Disable integration`):e(`integrationDetail.enableIntegration`,`Enable integration`)}),c(`span`,{className:`text-[11px] font-medium ${j.enabled?`text-success`:`text-foreground-subtle`}`,children:j.enabled?e(`integrationDetail.enabled`,`Enabled`):e(`integrationDetail.disabled`,`Disabled`)}),Z.isPending&&c(y,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),J!==`standalone`&&(be||V===`device-adoption`)&&a(`button`,{onClick:()=>E(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[c(ee,{className:`h-3 w-3`}),e(`integrations.config`)]}),a(`button`,{onClick:()=>O(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:e(`integrations.logs`,{defaultValue:`View logs`}),children:[c(S,{className:`h-3 w-3`}),e(`integrations.logs`,{defaultValue:`Logs`})]}),c(q,{label:e(`integrationDetail.restart`,`Restart`),icon:h,title:e(`integrationDetail.restart2`,`Restart "{{name}}"?`,{name:j.name}),description:e(`integrationDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device backed by it ({{topLevelCountLabel}} active). Streams will reconnect automatically.`,{topLevelCountLabel:Ge}),confirmLabel:e(`integrationDetail.restart`,`Restart`),triggerVariant:`outline`,confirmVariant:`danger`,disabled:Pe.isPending,action:()=>Pe.mutateAsync({addonId:j.addonId})}),!K&&s&&c(q,{label:e(`integrations.delete`,{defaultValue:`Delete`}),icon:u,title:e(`integrations.deleteTitle`,{defaultValue:`Delete integration?`}),description:e(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:j.name,count:Ge}),confirmLabel:e(`integrations.confirmDelete`,{defaultValue:`Delete integration`}),triggerVariant:`outline`,confirmVariant:`danger`,className:`border-danger bg-danger/10 text-danger hover:bg-danger hover:text-background`,disabled:Ne.isPending,action:()=>Ne.mutateAsync({id:s})})]})]}),we&&c(ke,{nodeId:null,addonIds:Oe,level:`global`,surface:`integration`,title:e(`integrations.settings`,{defaultValue:`Settings`})}),c(re,{context:`integration-detail`,devices:Q,trpc:_.trpcClient,integrationOf:Ve,forceIntegrationId:j.id,urlScope:`root`,lsKey:`integration-detail:${j.addonId}`,resolveIntegrationIcon:Ae,resolveParent:Be,onNavigate:He,batchActions:{remove:Fe.mutate,disable:Ie.mutate,enable:Le.mutate},...K?{}:{onDeleteDevice:e=>Fe.mutate({deviceId:e.id})}}),x&&s&&V===`device-adoption`&&c(We,{addonId:j.addonId,integrationId:s,onClose:()=>C(!1)}),x&&s&&V===`device-provider`&&c(Re,{open:x,integrationId:s,addonId:j.addonId,onClose:()=>C(!1)}),w&&j&&c(Me,{open:w,scope:{addonId:j.addonId,label:j.name},onClose:()=>T(!1)}),te&&s&&V!==null&&J!==null&&c(Ze,{integrationId:s,addonId:j.addonId,name:j.name,kind:V,mode:J,brokerKind:ge,canTest:ve,trpc:_.trpcClient,onClose:()=>E(!1)}),D&&c(U,{open:!0,onOpenChange:e=>!e&&O(!1),children:a(fe,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[c(ye,{className:`mb-0`,children:a(he,{className:`flex items-center gap-2 min-w-0`,children:[c(S,{className:`h-4 w-4 text-primary shrink-0`}),c(`span`,{className:`truncate`,children:j.name}),a(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate font-normal`,children:[j.addonId,s?` · ${s}`:``]})]})}),c(A,{className:`min-h-0 overflow-hidden p-0`,children:c(de,{addonId:j.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})})]}):a(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[c(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:c(k,{className:`h-6 w-6 text-foreground-subtle`})}),a(`div`,{className:`space-y-1 max-w-sm`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),c(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:s??``})})]}),a(`button`,{onClick:()=>f(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[c(m,{className:`h-3 w-3`}),e(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}function et({addonId:e}){let t=Ce(e),[n,i]=r(!1);return!t||n?null:c(`img`,{src:t,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:()=>i(!0)})}export{$e as IntegrationDetailPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{$ as e,B as t,G as n,J as r,L as i,S as a,b as o,o as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Cn as l,Di as u,On as d,Si as f,bn as p,dt as m,fn as h,kn as g,or as _,ot as v,un as y,xi as b,yi as x}from"./player-overlays-D98Lvll4.js";import{At as S,Au as C,Dt as w,Ea as T,Jr as ee,Ot as E,Ra as D,Ro as te,Ru as O,Uo as k,Vo as A,Ya as j,nt as M,r as N}from"./src-MJ2k3G6o.js";import{t as P}from"./i18n-BuS8cl72.js";import{t as F}from"./useTranslation-D3Is_4B6.js";import{Y as I,et as L,nt as R}from"./index-CM1JjjBW.js";import{t as z}from"./AdminPage-RJcN6Anu.js";import"./useEventInvalidation-CVKD2t0V.js";import{t as ne}from"./device-integration-icon-CFPzExgG.js";import{n as re,r as B,t as ie}from"./ScanNetworkModal-CiOVqs0H.js";e();function V(e=!0){t(()=>{if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=t}},[e])}e();function ae(e,n){let[i,a]=r(!1);return t(()=>{if(!e){a(!1);return}a(!1);let t=setTimeout(()=>a(!0),n);return()=>clearTimeout(t)},[e,n]),i}e();function H({providerId:e,onImport:n,onSkip:i}){let{t:o}=F(),[s,l]=r(new Set),d=D(),p=d.data,m=d.isPending||!d.data&&!d.isError;t(()=>{e&&(d.isPending||d.data||d.mutate({addonId:e}))},[e,d]);function h(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(m)return a(`div`,{className:`flex flex-col items-center py-12`,children:[c(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),c(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:o(`integrations.searchingDevices`)})]});let g=p??[];return a(`div`,{className:`space-y-4`,children:[c(`p`,{className:`text-xs text-foreground-subtle`,children:g.length>0?o(`integrations.foundDevices`,{count:g.length}):o(`integrations.noDevicesFound`)}),g.length>0&&c(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:g.map(e=>{let t=e.stableId,n=e.suggestedName??t,r=s.has(t),i=e.alreadyOnboarded===!0;return a(`button`,{onClick:()=>{i||h(t)},disabled:i,title:i?o(`integrations.alreadyAddedHint`,{defaultValue:`Already added as "{{name}}" — re-adding would overwrite its settings.`,name:e.onboardedName??n}):void 0,className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${i?`border-border bg-surface opacity-60 cursor-not-allowed`:r?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[c(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${r&&!i?`border-primary bg-primary`:`border-border`}`,children:r&&!i&&c(f,{className:`h-3 w-3 text-primary-foreground`})}),c(u,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),c(`span`,{className:`text-xs font-medium text-foreground truncate`,children:n}),i&&c(`span`,{className:`ml-auto flex-shrink-0 rounded bg-surface-muted px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:o(`integrations.alreadyAdded`,{defaultValue:`Already added`})})]},t)})}),a(`div`,{className:`flex items-center justify-between pt-2`,children:[c(`button`,{onClick:i,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:o(`integrations.skip`)}),g.length>0&&a(`button`,{onClick:()=>n(Array.from(s)),disabled:s.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[o(`integrations.importSelected`),` (`,s.size,`)`]})]})]})}e();function U({onSelect:e,onClose:t,pendingAddonId:i=null}){let{t:o}=F(),s=L(),[l,u]=r(``),{data:d,isLoading:f}=A(),p=n(()=>{let e=d??[],t=l.trim().toLowerCase();return t.length===0?e:e.filter(e=>`${e.name} ${e.description??``} ${e.addonId}`.toLowerCase().includes(t))},[d,l]);if(f)return c(`div`,{className:`grid grid-cols-2 gap-2 p-2`,children:[1,2,3,4].map(e=>c(`div`,{className:`h-24 rounded-lg bg-surface animate-pulse`},e))});let m=i!==null;return a(`div`,{className:`space-y-3`,"data-testid":`provider-picker`,children:[a(`div`,{className:`relative`,children:[c(h,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-foreground-subtle`,"aria-hidden":!0}),c(C,{type:`search`,value:l,onChange:e=>u(e.target.value),placeholder:o(`integrations.searchProviders`,`Search integrations…`),className:`pl-8`,"data-testid":`provider-picker-search`,"aria-label":o(`integrations.searchProviders`,`Search integrations…`)})]}),c(`div`,{className:`grid grid-cols-2 gap-2`,children:p.map(n=>{let r=n.instanceMode===`unique`&&n.existingInstances.length>0,l=i===n.addonId,u=m;return a(`button`,{type:`button`,disabled:u,"data-testid":`provider-pick-${n.addonId}`,onClick:()=>{if(!u)if(r){let e=n.existingInstances[0].id;t(),s(`/integrations/${e}`)}else e(n.addonId,n.instanceMode,n.discoveryMode,n.name,n.kind,n.brokerKind,n.mode,n.canTest)},className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-center text-xs hover:border-primary/50 hover:bg-surface-hover transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[n.iconUrl?c(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${n.color}15`},children:c(`img`,{src:n.iconUrl,alt:``,className:`h-5 w-5`})}):c(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${n.color}15`},children:c(`span`,{className:`text-sm`,style:{color:n.color},children:`◉`})}),c(`p`,{className:`w-full truncate text-xs font-semibold text-foreground`,children:n.name}),n.description?c(`p`,{className:`w-full line-clamp-2 text-[10px] text-foreground-subtle`,children:n.description}):null,l?c(_,{className:`h-4 w-4 animate-spin text-primary`}):r?a(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[c(y,{className:`h-3 w-3`}),o(`integrations.manage`)]}):null]},n.addonId)})}),p.length===0&&c(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:(d??[]).length===0?o(`integrations.noProviders`):o(`integrations.noProvidersMatch`,`No integrations match your search.`)})]})}e();function oe(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}var W=2e4;function se({open:e,onClose:i}){let{t:l}=F(),u=L(),d=s(),[f,p]=r(`picker`),[h,g]=r(null),[v,y]=r(null),[b,x]=r(`manual`),[S,C]=r(null),[w,E]=r(``),[O,k]=r(null),[A,j]=r(null),[M,N]=r(!1),{data:P}=ee({addonId:h??``,nodeId:`hub`},{enabled:h!=null}),I=n(()=>P?oe(P):null,[P]),R=te({onSuccess:()=>d.invalidateQueries({queryKey:[[`integrations`]]})}),z=D(),ne=z.data;t(()=>{f!==`discovery`||!v||!h||z.isPending||z.data||z.mutate({addonId:h})},[f,v,h,z]);let ie=T({onSuccess:()=>d.invalidateQueries({queryKey:[[`deviceManager`]]})});function se(e,t,n,r,i,a,o,s){if(!R.isPending){if(g(e),N(s),x(n),E(r),j(null),o===`broker`){if(!a){j(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}C(a),p(`broker`);return}if(o===`account`){p(`config`);return}G(e,r)}}async function G(e,t){try{let n=await R.mutateAsync({addonId:e,name:t,settings:{}});i(),J(),u(`/integrations/${n.id}?add=1`)}catch{}}async function ce(e){if(h)try{let t=await R.mutateAsync({addonId:h,name:e.name,settings:e.config,secretKeys:[...e.secretKeys]});y(t.id),k(t.id),b===`auto`||b===`both`?p(`discovery`):q(t.id,{openAdd:!0})}catch{}}async function le(e){if(h)try{let t=await R.mutateAsync({addonId:h,name:w,settings:{brokerId:e}});k(t.id),y(t.id),q(t.id)}catch{}}async function K(e){if(h){for(let t of e){let e=ne?.find(e=>e.stableId===t);e&&await ie.mutateAsync({addonId:h,candidate:e,...O===null?{}:{integrationId:O}})}q()}}function q(e,t){let n=e??v??h;i(),J(),n&&u(t?.openAdd===!0?`/integrations/${n}?add=1`:`/integrations/${n}`)}function J(){p(`picker`),g(null),y(null),x(`manual`),C(null),E(``),k(null),j(null),N(!1)}function Y(){i(),J()}V(e);let X=R.isPending,Z=ae(X,W);if(!e)return null;let ue={picker:l(`integrations.newIntegration`),config:l(`integrations.configureIntegration`),discovery:l(`integrations.importDevices`),broker:l(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},Q=X?h:null,$=R.error,de=X&&!Z;return a(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:de?void 0:Y}),a(`div`,{className:`relative z-10 w-full max-w-lg max-h-[calc(85dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[a(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:ue[f]}),c(`button`,{onClick:Y,disabled:de,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:c(m,{className:`h-4 w-4`})})]}),a(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[$&&!X&&c(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:$ instanceof Error?$.message:String($)}),f===`picker`&&a(o,{children:[A&&c(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:A}),c(U,{onSelect:se,onClose:Y,pendingAddonId:Q})]}),f===`config`&&h&&c(re,{addonId:h,configSchema:I??null,canTest:M,onSave:ce,onBack:()=>p(`picker`)}),f===`broker`&&S&&c(B,{kind:S,onResolved:e=>{le(e)},onBack:()=>p(`picker`)}),f===`discovery`&&v&&c(H,{providerId:v,onImport:K,onSkip:q})]}),X&&a(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm px-6 text-center`,children:[c(_,{className:`h-6 w-6 animate-spin text-primary`}),c(`p`,{className:`text-xs font-medium text-foreground`,children:l(`integrations.creating`,{defaultValue:`Creating integration…`})}),!Z&&c(`p`,{className:`text-[10px] text-foreground-subtle`,children:l(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),Z&&a(o,{children:[c(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:l(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),c(`button`,{onClick:Y,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:l(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})]})}function G({integration:e,expanded:t,onToggleExpand:n}){let{t:r}=F();return a(`div`,{className:`flex items-center gap-2.5`,children:[c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),n(e.addonId)},"aria-label":t?r(`integrations.integrationColumns.collapse`,`Collapse`):r(`integrations.integrationColumns.expand`,`Expand`),"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:c(t?b:x,{className:`h-3.5 w-3.5`})}),c(I,{type:e.addonId,size:`sm`}),a(`div`,{className:`flex min-w-0 flex-col`,children:[c(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),c(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function ce(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:P.t(`integrations.integrationColumns.integration`,`Integration`),headerClassName:`w-[55%]`,cell:e=>c(G,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:P.t(`integrations.integrationColumns.devices`,`Devices`),headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>P.t(`integrations.integrationColumns.deviceCount`,{count:e.deviceCount})},{key:`status`,header:P.t(`integrations.integrationColumns.status`,`Status`),headerClassName:`w-[15%]`,cell:e=>c(M,{status:e.status})}]}e();function le(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var K=`expand`;function q(){let{t:e}=F(),t=L(),s=v(),[u]=R(),[f,m]=r(!1),h=i(()=>m(!0),[]),_=i(()=>m(!1),[]),[y,b]=r(!1),x=i(()=>b(!0),[]),C=i(()=>b(!1),[]);N([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),N([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:T,isLoading:ee,refetch:D}=k(void 0),{data:te,isLoading:A,refetch:M}=j({projection:`slim`}),P=n(()=>te??[],[te]),I=n(()=>T??[],[T]),re=n(()=>{let e=new Map;for(let t of P)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[P]),B=n(()=>E(T),[T]),V=n(()=>{let e=new Map;for(let t of S(P)){let n=B(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[P,B]),ae=n(()=>I.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:le(e),deviceCount:V.get(e.id)??0})),[I,V]),H=u.get(K),U=i(e=>{let t=new URLSearchParams(window.location.search);t.get(K)===e?t.delete(K):t.set(K,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),oe=i(e=>t(`/integrations/${e.id}`),[t]),W=i(e=>re.get(e)??null,[re]),G=i(e=>t(`/devices/${String(e)}`),[t]),q=i(e=>c(w,{context:`integration-detail`,devices:P,trpc:s.trpcClient,integrationOf:B,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:ne,resolveParent:W,onNavigate:G}),[P,s.trpcClient,B,W,G]),J=i(e=>H===e.addonId,[H]),Y=n(()=>ce({isExpanded:J,onToggleExpand:U}),[J,U]),X=i(e=>`${e.name} ${e.addonId}`,[]),Z=i(e=>e.addonId,[]),ue=i(()=>{D(),M()},[D,M]),Q=ee||A,$=I.length>0;return a(z,{icon:d,title:e(`nav.integrations`,`Integrations`),actions:a(o,{children:[c(`button`,{onClick:ue,disabled:Q,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:e(`common.refresh`,`Refresh`),children:c(p,{className:O(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),a(`button`,{onClick:x,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:e(`integrations.scanTheLocalNetworkFor`,`Scan the local network for devices`),children:[c(l,{className:`h-3.5 w-3.5`}),e(`integrations.scanNetwork`,`Scan network`)]}),a(`button`,{onClick:h,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[c(g,{className:`h-3.5 w-3.5`}),e(`integrations.newIntegration`,`New Integration`)]})]}),children:[Q&&c(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>c(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!$&&a(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[c(`p`,{className:`text-sm`,children:e(`integrations.noIntegrationsConfigured`,`No integrations configured.`)}),c(`p`,{className:`text-xs mt-1`,children:e(`integrations.clickNewIntegrationToConnect`,`Click "New Integration" to connect cameras and devices.`)})]}),!Q&&$&&c(w,{mode:`generic`,items:ae,getKey:Z,getSearchText:X,columns:Y,onRowClick:oe,isExpanded:J,renderExpanded:q,searchPlaceholder:e(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:e(`integrations.empty`,{defaultValue:`No integrations found.`})}),c(se,{open:f,onClose:_}),c(ie,{open:y,onClose:C})]})}export{q as IntegrationsPage};
|