@camstack/addon-admin-ui 1.2.526 → 1.2.527
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/CHANGELOG.md +11 -0
- package/dist/assets/{AddonAssetIcon-Bk09xHqf.js → AddonAssetIcon-BZ0hQcho.js} +1 -1
- package/dist/assets/Addons-BAqAfY0r.js +5 -0
- package/dist/assets/{AdminPage-CYSYefaL.js → AdminPage-7avIuDBh.js} +1 -1
- package/dist/assets/{AdminSectionedPage-B4MRvqE8.js → AdminSectionedPage-Bd2owMGm.js} +1 -1
- package/dist/assets/AiProfiles-aCDtxD2T.js +3 -0
- package/dist/assets/BrokerEditorDialog-Cp7neyJC.js +1 -0
- package/dist/assets/Build-SObpGxas.js +40 -0
- package/dist/assets/{Calendars-D4ed6Nqc.js → Calendars-B2TORAnq.js} +1 -1
- package/dist/assets/Cluster-CD4DYic_.js +1 -0
- package/dist/assets/{ComposedDeviceEditDialog-DJ5mqI6C.js → ComposedDeviceEditDialog-BiIiBFG-.js} +1 -1
- package/dist/assets/CompositionBlockEditor-BXYXXUEU.js +2 -0
- package/dist/assets/{CompositionEditorPage-4rHclFIA.js → CompositionEditorPage-Cm4C-7Z-.js} +1 -1
- package/dist/assets/Data-CRPVPhFT.js +2 -0
- package/dist/assets/{DeviceDetail-3jKJ80IC.js → DeviceDetail-DNsWQGiy.js} +2 -2
- package/dist/assets/{DeviceDoActionFields-1jte2ge2.js → DeviceDoActionFields-BEhy6_KW.js} +1 -1
- package/dist/assets/{Devices-Bq4yRli5.js → Devices-CS5P4d9n.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-DlIQigBi.js → EmbedPlayerPage-B7MIw7cv.js} +1 -1
- package/dist/assets/History-BbOfWf-p.js +1 -0
- package/dist/assets/Identity-Df140-fX.js +1 -0
- package/dist/assets/IntegrationDetail-B7sqZ94w.js +1 -0
- package/dist/assets/{IntegrationHub-8GCewFBs.js → IntegrationHub-DndCuqMe.js} +1 -1
- package/dist/assets/Integrations-BJh_WZAT.js +1 -0
- package/dist/assets/{Integrations-Bt3Im7Mh.js → Integrations-DRCpstaG.js} +1 -1
- package/dist/assets/{Library-DTn9Nkjs.js → Library-Cx17_SRL.js} +1 -1
- package/dist/assets/Locations-Dt9LOu5v.js +3 -0
- package/dist/assets/{Logs-BxTfJ-wk.js → Logs-CrxQn3Uq.js} +1 -1
- package/dist/assets/{MaskShapeCanvas-DBEbXuH2.js → MaskShapeCanvas-tJyuoOTy.js} +1 -1
- package/dist/assets/{MotionZonesSettings-D3Xxjf5N.js → MotionZonesSettings-DaGyceJa.js} +1 -1
- package/dist/assets/{MyAccess-BTEJNJtS.js → MyAccess-Bp2dsON4.js} +1 -1
- package/dist/assets/Network-DftlNAIH.js +1 -0
- package/dist/assets/{NodeAddonsSettingsPanel-Do_I93Mx.js → NodeAddonsSettingsPanel-JIXh-CLX.js} +1 -1
- package/dist/assets/Notifications-2tj0VaIS.js +1 -0
- package/dist/assets/{Pipeline-Cjj8XOuS.js → Pipeline-CqZqLWQZ.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-CswE6pks.js → PrivacyMaskSettings-zzQcpeb0.js} +1 -1
- package/dist/assets/Recordings-DoAJqZqc.js +1 -0
- package/dist/assets/{RemoteGrid-BjtzHkpg.js → RemoteGrid-Bz_u9tq6.js} +1 -1
- package/dist/assets/ScanNetworkModal-DL-mWRtG.js +1 -0
- package/dist/assets/{SceneMonitorEditor-C2X6jZvS.js → SceneMonitorEditor-B0ICySEi.js} +1 -1
- package/dist/assets/SessionsList-QvqpXCDN.js +2 -0
- package/dist/assets/{Showroom-CHwcC6p6.js → Showroom-B6CDELO1.js} +1 -1
- package/dist/assets/System-C0KUcOaJ.js +1 -0
- package/dist/assets/{Templates-tilFwunF.js → Templates-uAAxbV9V.js} +1 -1
- package/dist/assets/{Terminal-DiMnsE8i.js → Terminal-D1fhPY66.js} +5 -5
- package/dist/assets/{Viewer-BwirleAM.js → Viewer-BWN8qfBa.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-w6FCrjgB.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-sshFQYnL.js} +1 -1
- package/dist/assets/{addon-icons-context-CHk3ePjj.js → addon-icons-context-BHF-RdY-.js} +1 -1
- package/dist/assets/{archive-BU_eXxQC.js → archive-2V-x_y9T.js} +1 -1
- package/dist/assets/{assignment-candidates-B4bOK7k8.js → assignment-candidates-BpC51VXR.js} +1 -1
- package/dist/assets/{authed-media-BYuQnqbF.js → authed-media-CdbbdgDZ.js} +1 -1
- package/dist/assets/{bell-off-DCQedZIx.js → bell-off-DDQ8FbF1.js} +1 -1
- package/dist/assets/{board-model-t0EX_kXW.js → board-model-D3wYwuI4.js} +1 -1
- package/dist/assets/{boxes-BZMO9uMf.js → boxes-BwEV9Act.js} +1 -1
- package/dist/assets/circle-slash-BjzSCz4-.js +1 -0
- package/dist/assets/client-r4i0EpF6.js +711 -0
- package/dist/assets/{cloud-upload-CApwQ18P.js → cloud-upload-BII8r4p9.js} +1 -1
- package/dist/assets/crop-D9cpl5_W.js +1 -0
- package/dist/assets/{device-integration-icon-CXG5v8dp.js → device-integration-icon-Cf2JTj5q.js} +1 -1
- package/dist/assets/device-picker-model-B_Zjyqyk.js +1 -0
- package/dist/assets/{dist-Hz1nnJDv.js → dist-B0LFF94V.js} +1 -1
- package/dist/assets/dist-BOdjk8IV.js +711 -0
- package/dist/assets/{file-up-cso0QIDs.js → file-up-Bizrs9Ca.js} +1 -1
- package/dist/assets/{format-Csy9sDox.js → format-Bqo-j708.js} +1 -1
- package/dist/assets/{grip-vertical-DqjjXK1h.js → grip-vertical-C-qhB3oM.js} +1 -1
- package/dist/assets/{hard-drive-download-D-ykdsm5.js → hard-drive-download-Dym9jihx.js} +1 -1
- package/dist/assets/{hostInit-CTFssGi8.js → hostInit-bmlgmSTk.js} +1 -1
- package/dist/assets/i18n-BE1bPZOs.js +1 -0
- package/dist/assets/icons-BZ8D05w2.js +1 -0
- package/dist/assets/index-DimGtYV1.css +2 -0
- package/dist/assets/index-Ohn-2iW_.js +4 -0
- package/dist/assets/{key-C_dbeH7F.js → key-DddJ6bil.js} +1 -1
- package/dist/assets/{key-round-CPg0Y5qN.js → key-round-CbCqycf3.js} +1 -1
- package/dist/assets/{layers-Cb-ro1vb.js → layers-C-ZqYk3U.js} +1 -1
- package/dist/assets/{linked-devices-model-ZCUJsj_d.js → linked-devices-model-BPUD1khJ.js} +1 -1
- package/dist/assets/{list-ordered-V6P5uujF.js → list-ordered-Cxznlat2.js} +1 -1
- package/dist/assets/{location-owned-usage-C6DcC3IT.js → location-owned-usage-DOmOvdiG.js} +1 -1
- package/dist/assets/{log-in-Cxvw8rxc.js → log-in-9Uirjetj.js} +1 -1
- package/dist/assets/{memory-stick-Mm_iVwSZ.js → memory-stick-CLL3KiND.js} +1 -1
- package/dist/assets/{message-square-plus-Bfam15lf.js → message-square-plus-C2nVnMG1.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-019f9c14.js → mf-entry-bootstrap-0-edf9b20a.js} +2 -2
- package/dist/assets/{mic-off-CeSZf8K2.js → mic-off-CcHQBwDt.js} +1 -1
- package/dist/assets/{monitor-off-U-RK64kw.js → monitor-off-DUE1gt1S.js} +1 -1
- package/dist/assets/{monitor-smartphone-DezRerVw.js → monitor-smartphone-CwOoXB0L.js} +1 -1
- package/dist/assets/mount-B_Zjyqyk.js +1 -0
- package/dist/assets/{player-overlays-DgedyCX9.js → player-overlays-Cw_gjG75.js} +1 -1
- package/dist/assets/{recycle-Dkb1d-SV.js → recycle-hW2Os1lc.js} +1 -1
- package/dist/assets/remoteEntry-CHuAXwj-.js +1 -0
- package/dist/assets/{ruler-DzpBI-EP.js → ruler-SYjqj9n_.js} +1 -1
- package/dist/assets/{scan-eye-BmLTXsIf.js → scan-eye-BZlKp5Ev.js} +1 -1
- package/dist/assets/{scissors-lBRCylhQ.js → scissors-Prn6Kbb7.js} +1 -1
- package/dist/assets/{search-x-BRhrXpKx.js → search-x-CCA8373c.js} +1 -1
- package/dist/assets/{send-DVJoNc0-.js → send-C5rCH5_0.js} +1 -1
- package/dist/assets/{settings-2-D6sp_FTm.js → settings-2-wlw_-rxi.js} +1 -1
- package/dist/assets/{shapes-CQn3wvpk.js → shapes-Kj0bK1D8.js} +1 -1
- package/dist/assets/{sigma-CKK8bLRa.js → sigma-NPxR3lj1.js} +1 -1
- package/dist/assets/{speaker-BYorOPbN.js → speaker-CIKbprnA.js} +1 -1
- package/dist/assets/src-nnHXOip7.js +67 -0
- package/dist/assets/{step-inspector-model-DEfajBM3.js → step-inspector-model-BKKc_lkM.js} +1 -1
- package/dist/assets/{table-2-BPB4V5Fg.js → table-2-Sw__YAPa.js} +1 -1
- package/dist/assets/{timer-reset-Cu_VSXbl.js → timer-reset-BhPZYoCT.js} +1 -1
- package/dist/assets/{unlink-BcrHT0zX.js → unlink-DNy8sNAV.js} +1 -1
- package/dist/assets/{usb-DhXPqJtn.js → usb-CyQsTtlO.js} +1 -1
- package/dist/assets/{use-device-bound-caps-K47AcsQ5.js → use-device-bound-caps-BQo_OD1O.js} +1 -1
- package/dist/assets/{use-scenes-feed-DQrMGL5E.js → use-scenes-feed-BCDAv1nN.js} +1 -1
- package/dist/assets/{use-stationary-objects-yu-O0RPa.js → use-stationary-objects-BnIfyZw5.js} +1 -1
- package/dist/assets/useEventInvalidation-B_Zjyqyk.js +1 -0
- package/dist/assets/{useNodeUrlSelection-BuraZwll.js → useNodeUrlSelection-CR_BnlEg.js} +1 -1
- package/dist/assets/user-round-BY4YxbLZ.js +1 -0
- package/dist/assets/{user-x-DRSOzwTr.js → user-x-CUkBojXx.js} +1 -1
- package/dist/assets/variable-CpgCMY_Q.js +1 -0
- package/dist/assets/{video-5IaJhdjU.js → video-DXegVNA2.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BtgDin-X.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-2LL0aB_0.js} +2 -2
- package/dist/index.html +10 -10
- package/dist/server/addon.js +902 -116
- package/package.json +1 -1
- package/dist/assets/Addons-BwXNg54C.js +0 -5
- package/dist/assets/AiProfiles-CRZH6xR0.js +0 -3
- package/dist/assets/BrokerEditorDialog-D9rZCGl9.js +0 -1
- package/dist/assets/Build-BJaqr-_Y.js +0 -40
- package/dist/assets/Cluster-Dkt_tVUy.js +0 -1
- package/dist/assets/CompositionBlockEditor-BEondavu.js +0 -2
- package/dist/assets/Data-pZe3A7Va.js +0 -2
- package/dist/assets/History-DTt-NAMR.js +0 -1
- package/dist/assets/Identity-C3GHYP7_.js +0 -1
- package/dist/assets/IntegrationDetail-EOwq3jVG.js +0 -1
- package/dist/assets/Integrations-BocurtE0.js +0 -1
- package/dist/assets/Locations-chgnzdWz.js +0 -3
- package/dist/assets/Network-plYS78UN.js +0 -1
- package/dist/assets/Notifications-mslnotOB.js +0 -1
- package/dist/assets/Recordings-BpB53ln_.js +0 -1
- package/dist/assets/ScanNetworkModal-BR3tzZcL.js +0 -1
- package/dist/assets/SessionsList-BOjlUhj5.js +0 -2
- package/dist/assets/System-CiZ0xcyP.js +0 -1
- package/dist/assets/circle-slash-DFl97Cbx.js +0 -1
- package/dist/assets/client-F3l12jEi.js +0 -674
- package/dist/assets/crop-gfwPOF8e.js +0 -1
- package/dist/assets/device-picker-model-Fpx4y0MY.js +0 -1
- package/dist/assets/dist-B2m_6_7g.js +0 -674
- package/dist/assets/i18n-BH0PY6IL.js +0 -1
- package/dist/assets/icons-B9uR9qKs.js +0 -1
- package/dist/assets/index-CQ7TjSgs.js +0 -4
- package/dist/assets/index-DjwiZ7qT.css +0 -2
- package/dist/assets/mount-Fpx4y0MY.js +0 -1
- package/dist/assets/remoteEntry-DpkkaSO3.js +0 -1
- package/dist/assets/src-B0EA_4Ed.js +0 -67
- package/dist/assets/useEventInvalidation-Fpx4y0MY.js +0 -1
- package/dist/assets/user-round-D6wDvac9.js +0 -1
- package/dist/assets/variable-cv0ONmJ-.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as e,K as t,S as n,et as r}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{cn as i,dn as a,fn as o,hn as s,ln as c,mn as l,pn as u,un as d}from"./client-
|
|
1
|
+
import{C as e,K as t,S as n,et as r}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{cn as i,dn as a,fn as o,hn as s,ln as c,mn as l,pn as u,un as d}from"./client-r4i0EpF6.js";import{U as f}from"./src-nnHXOip7.js";import{t as p}from"./i18n-BE1bPZOs.js";import{t as m}from"./useTranslation-BJr-n0es.js";import"./index-Ohn-2iW_.js";import{n as h,t as g}from"./use-device-bound-caps-BQo_OD1O.js";r();var _=`mt-1 w-full rounded border border-border bg-background px-2 py-1 text-xs`,v=`block text-[11px] font-medium text-foreground`,y=`deviceId`;function b(e,t){return t.length===0?0:t.length===1?t[0]:t.find(t=>!e.includes(t))??t[t.length-1]}function x(e,t,n){if(t.length===0)return[];if(t.length===1)return t;let r=t.find(t=>!e.includes(t));if(r===void 0)return t;let i=n(r);if(i===void 0)return[r];let a=e[0]??t.find(e=>e!==r);if(a===void 0)return[r];let o=n(a);return o===void 0||!s(o,i)?[r]:t.filter(e=>{let t=n(e);return t!==void 0&&s(o,t)})}function S(e){return e.length===0?0:e.length===1?e[0]:[...e]}function C(e){return typeof e==`number`?e>0?[e]:[]:Array.isArray(e)?e.filter(e=>e>0):[]}function w(e,t){return{deviceId:e,cap:t.cap,method:t.method,...t.args===void 0?{}:{args:{...t.args}}}}function T(e,t){return p.t(`deviceDoAction.customLabel`,{name:`${e}.${t}`})}function E({value:r,onChange:p,devices:E,listState:D,fleet:O,allowTriggerDevice:k=!1,allowMultiSameFamily:A=!1,testId:j=`device-do-action`}){let{t:M}=m(),N=typeof r.deviceId!=`number`&&!Array.isArray(r.deviceId),P=C(r.deviceId),F=t(()=>E.filter(e=>u(String(e.type??``))),[E]),I=t(()=>{let e=new Map;for(let t of F)t.type!==void 0&&t.type!==null&&e.set(t.id,String(t.type));return e},[F]),L=t(()=>{if(!A||P.length===0)return F;let e=I.get(P[0]);return e===void 0?F:F.filter(t=>{if(P.includes(t.id))return!0;let n=t.type!==void 0&&t.type!==null?String(t.type):void 0;return n!==void 0&&s(e,n)})},[A,P,F,I]),R=g(!A&&P.length===1?P[0]:0),z=h(A?P:[]),B=t(()=>N?a():P.length===0?[]:A?z.isLoading&&z.data===void 0?[]:d(P.map(e=>({boundCaps:z.data?.get(e),deviceType:I.get(e)}))):R.data===void 0&&R.isLoading?[]:c({boundCaps:R.data,deviceType:I.get(P[0])}),[N,P,A,z.data,z.isLoading,R.data,R.isLoading,I]),V=o(r.cap,r.method,r.args),H=l(r.cap,r.method,r.args),U=r.cap!==``&&r.method!==``&&H===null&&(N||P.length>0),W=A?z.isLoading:R.isLoading,G=A?z.isError:R.isError,K=e=>{if(e.startsWith(`custom:`))return;let t=i.find(t=>t.id===e);t!==void 0&&p(w(N?r.deviceId:P.length>0?S(P):F[0]?.id??0,t))};return e(`div`,{className:`flex min-w-0 flex-1 flex-col gap-2`,"data-testid":j,children:[k&&e(`div`,{className:`w-full max-w-xs`,children:[n(`label`,{className:v,children:M(`deviceDoAction.deviceDoActionFields.target`,`Target`)}),e(`select`,{className:_,"data-testid":`${j}-target`,value:N?`trigger`:`device`,onChange:e=>{if(e.target.value===`trigger`){p({deviceId:{$var:y},cap:``,method:``});return}p({deviceId:F[0]?.id??0,cap:``,method:``})},children:[n(`option`,{value:`device`,children:M(`deviceDoAction.deviceDoActionFields.specificDevice`,`Specific device`)}),n(`option`,{value:`trigger`,children:M(`deviceDoAction.deviceDoActionFields.theDeviceThatTriggeredThis`,`The device that triggered this run`)})]})]}),!N&&e(`div`,{"data-testid":`${j}-device`,children:[n(`label`,{className:v,children:M(`deviceDoAction.deviceLabel`,{count:A?2:1})}),n(f,{devices:L,listState:D,...O===void 0?{}:{fleet:O},value:[...P],onChange:e=>{p({deviceId:S(A?x(P,e,e=>I.get(e)):(()=>{let t=b(P,e);return t>0?[t]:[]})()),cap:``,method:``})},emptyLabel:A?`No devices selected`:`No device selected`,noun:`device`,testId:`${j}-device-picker`}),A&&P.length>1&&n(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:M(`deviceDoAction.deviceDoActionFields.sameFamilyOnlyTheAction`,`Same family only — the action runs on each selected device.`)})]}),e(`div`,{className:`w-full max-w-sm`,children:[n(`label`,{className:v,children:M(`deviceDoAction.deviceDoActionFields.action`,`Action`)}),e(`select`,{className:_,"data-testid":`${j}-action`,value:V===`custom:${r.cap}.${r.method}`?V:H?.id??``,disabled:!N&&(P.length===0||W),onChange:e=>K(e.target.value),children:[n(`option`,{value:``,children:!N&&P.length===0?M(`deviceDoAction.deviceDoActionFields.pickADeviceFirst`,`Pick a device first`):W?M(`deviceDoAction.deviceDoActionFields.loadingActions`,`Loading actions…`):B.length===0?M(`deviceDoAction.deviceDoActionFields.noActionsForThisDevice`,`No actions for this device`):M(`deviceDoAction.deviceDoActionFields.selectAnAction`,`Select an action…`)}),U&&n(`option`,{value:V,children:T(r.cap,r.method)}),B.map(e=>n(`option`,{value:e.id,children:e.label},e.id))]}),G&&n(`p`,{className:`mt-1 text-[11px] text-warning`,children:M(`deviceDoAction.deviceDoActionFields.couldNotReadThisDevice`,`Could not read this device’s capabilities.`)})]}),H?.openArgs!==void 0&&H.openArgs.length>0&&n(`div`,{className:`flex flex-col gap-2`,children:H.openArgs.map(t=>{let i=r.args?.[t.key],a=typeof i==`string`||typeof i==`number`?String(i):``;return e(`div`,{className:`w-full max-w-sm`,children:[n(`label`,{className:v,htmlFor:`${j}-${t.key}`,children:t.label}),n(`input`,{id:`${j}-${t.key}`,className:_,"data-testid":`${j}-${t.key}`,type:t.kind===`number`?`number`:`text`,value:a,onChange:e=>{let n=e.target.value,i=r.args===void 0?{}:{...r.args};if(n===``)delete i[t.key];else if(t.kind===`number`){let e=Number(n);Number.isNaN(e)?delete i[t.key]:i[t.key]=e}else i[t.key]=n;p(Object.keys(i).length>0?{...r,args:i}:{deviceId:r.deviceId,cap:r.cap,method:r.method})}})]},t.key)})})]})}export{E as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as e,K as t,R as n,S as r,et as i,o as a}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Fi as o,dt as s,zt as c}from"./player-overlays-
|
|
1
|
+
import{C as e,K as t,R as n,S as r,et as i,o as a}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Fi as o,dt as s,zt as c}from"./player-overlays-Cw_gjG75.js";import{Do as l,Fo as u,Ft as d,Ko as f,Ps as p,Pt as m,So as h,r as g}from"./src-nnHXOip7.js";import{t as _}from"./useTranslation-BJr-n0es.js";import{fr as v,vr as y}from"./index-Ohn-2iW_.js";import{t as b}from"./AdminPage-7avIuDBh.js";import"./useEventInvalidation-B_Zjyqyk.js";import{t as x}from"./device-integration-icon-Cf2JTj5q.js";i();var S=32;function C(e,t){let n=e=>t(e).kind===`orphan`,r=new Set;for(let t of e)n(t)&&r.add(t.id);let i=new Map;for(let t of e)i.set(t.id,t);let a=(e,t=0)=>{if(t>S)return!1;if(r.has(e.id))return!0;if(e.parentDeviceId==null)return!1;let n=i.get(e.parentDeviceId);return n?a(n,t+1):!1},o=[],s=[];for(let t of e)a(t)?s.push(t):o.push(t);return{activeDevices:o,orphanDevices:s}}function w(){let{t:i}=_(),S=y(),w=s(),T=a();g([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]),g([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`]);let{data:E}=u({projection:`slim`}),{data:D}=p(void 0),O=f({onSuccess:()=>{T.invalidateQueries({queryKey:[[`deviceManager`]]})}}),k=h({onSuccess:()=>{T.invalidateQueries({queryKey:[[`deviceManager`]]})}}),A=l({onSuccess:()=>{T.invalidateQueries({queryKey:[[`deviceManager`]]})}}),j=t(()=>E??[],[E]),M=t(()=>d(D),[D]),{activeDevices:N,orphanDevices:P}=t(()=>C(j,M),[j,M]),F=t(()=>{let e=new Map;for(let t of j)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[j]),I=n(e=>F.get(e)??null,[F]),L=t(()=>(D??[]).map(e=>({id:e.id,name:e.name??e.addonId,icon:r(v,{type:e.addonId,size:`sm`})})),[D]),R=n(e=>S(`/devices/${String(e)}`),[S]);return e(b,{icon:o,title:i(`nav.devices`,`Devices`),children:[r(m,{context:`devices`,devices:N,trpc:w.trpcClient,filters:{integrations:L},integrationOf:M,resolveIntegrationIcon:x,resolveParent:I,onNavigate:R,batchActions:{remove:O.mutate,disable:k.mutate,enable:A.mutate}}),P.length>0&&e(`div`,{className:`mt-6 space-y-2`,children:[e(`div`,{className:`flex items-baseline gap-2`,children:[r(c,{className:`h-3.5 w-3.5 text-warning shrink-0`}),r(`h2`,{className:`text-sm font-semibold text-foreground`,children:i(`devices.orphanDevices`,`Orphan devices`)}),r(`span`,{className:`text-[10px] text-foreground-subtle`,children:i(`common.deviceOrphans`,{count:P.length})})]}),e(`div`,{className:`rounded-lg border border-warning/30 bg-warning/5 p-2`,children:[r(`p`,{className:`text-[11px] text-foreground-subtle px-2 pb-2`,children:i(`devices.theseDevicesReferenceAnIntegration`,"These devices reference an integration that is no longer registered (their `integrationId`, or — for older devices without one — their `addonId`). Delete them, or re-install the missing integration to bring them back online. The provider badge beside each row is the addon that serves it.")}),r(m,{context:`devices`,devices:P,trpc:w.trpcClient,integrationOf:M,urlScope:`nested`,lsKey:`devices:orphan`,resolveIntegrationIcon:x,resolveParent:I,onNavigate:R})]})]})]})}export{w as DevicesPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as e,K as t,S as n,V as r,Y as i,d as a,et as o,u as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{lt as c}from"./player-overlays-
|
|
1
|
+
import{C as e,K as t,S as n,V as r,Y as i,d as a,et as o,u as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{lt as c}from"./player-overlays-Cw_gjG75.js";import{Oo as l}from"./client-r4i0EpF6.js";import{D as u,F as d,N as f,O as p,T as m,y as h}from"./__vite-browser-external-BCAtXlNQ.js";import{En as g,Mn as _,lf as v,mn as y,un as b}from"./src-nnHXOip7.js";import{t as x}from"./useTranslation-BJr-n0es.js";o();var S=d([p({kind:m(`adaptive`)}),p({kind:m(`profile`),profile:l})]),C=p({serverUrl:f().min(1),token:f().min(1),deviceId:u().int().nonnegative(),target:S,muted:h()});function w(e,t){let n=t===void 0?{type:`state`,state:e}:{type:`state`,state:e,message:t};window.ReactNativeWebView?.postMessage(JSON.stringify(n))}function T(e){switch(e){case`playing`:return`playing`;case`error`:return`error`;case`connecting`:case`disconnected`:case`idle`:return`connecting`}}function E(e){return e.kind===`adaptive`?{kind:`adaptive`}:{kind:`profile`,profile:e.profile}}function D(e){return e.kind===`adaptive`?`embed:adaptive`:`embed:profile:${e.profile}`}function O(){let e=window.__CAMSTACK_EMBED__;if(e==null)return{ok:!1,error:`window.__CAMSTACK_EMBED__ is not set`};let t=C.safeParse(e);return t.success?{ok:!0,config:t.data}:{ok:!1,error:t.error.issues.map(e=>`${e.path.join(`.`)||`(root)`}: ${e.message}`).join(`; `)}}function k({message:t}){let{t:n}=x();return r(()=>{w(`error`,t)},[t]),e(`div`,{style:{position:`fixed`,inset:0,display:`flex`,alignItems:`center`,justifyContent:`center`,background:`#000`,color:`#f87171`,fontFamily:`system-ui, sans-serif`,fontSize:13,padding:16,textAlign:`center`},children:[n(`embedPlayerPage.embedConfigError`,`Embed config error:`),` `,t]})}function A({system:e,deviceId:a,initialTarget:o,initialMuted:s}){let[c,l]=i(o),[u,d]=i(s),{handleOffer:f,getIceServers:p,addIceCandidate:m,getIceCandidates:h,closeSession:v,getSessionState:y,getSessionDebug:b,applyDownlinkProbe:x}=g(e.trpcClient,a),C=t(()=>E(c),[c]),O=t(()=>(e,t)=>f(C,e,t),[f,C]),k=t(()=>(e,t,n)=>f(n,t,e),[f]);r(()=>(window.__camstackEmbed={setMuted:e=>d(e),setTarget:e=>{let t=S.safeParse(e);t.success&&l(t.data)}},()=>{window.__camstackEmbed&&delete window.__camstackEmbed}),[]);let A=D(c);return n(`div`,{style:{position:`fixed`,inset:0,width:`100vw`,height:`100vh`,background:`#000`},children:n(_,{serverUrl:e.serverUrl,streamKey:A,autoPlay:!0,muted:u,showControls:!1,className:`w-full h-full`,getSessionDebug:b,applyDownlinkProbe:x,handleOffer:O,reoffer:k,getSessionState:y,getIceServers:p,addIceCandidate:m,getIceCandidates:h,closeSession:v,onStateChange:e=>w(T(e)),onError:e=>w(`error`,e)},A)})}function j(){let{t:e}=x(),i=t(()=>O(),[]),o=t(()=>{if(!i.ok)return null;let e=y({serverUrl:i.config.serverUrl,token:i.config.token}),t=new a({defaultOptions:{queries:{retry:!1,refetchOnWindowFocus:!1}}});return b(t),{system:e,queryClient:t}},[i]);return r(()=>{if(o)return()=>{o.system.close()}},[o]),i.ok?o?n(c,{system:o.system,children:n(s,{client:o.queryClient,children:n(v.Provider,{client:o.system.trpcClient,queryClient:o.queryClient,children:n(A,{system:o.system,deviceId:i.config.deviceId,initialTarget:i.config.target,initialMuted:i.config.muted})})})}):n(k,{message:e(`embedPlayerPage.failedToInitialiseTheEmbed`,`Failed to initialise the embed player`)}):n(k,{message:i.error})}export{j as EmbedPlayerPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{C as e,K as t,S as n,Y as r,et as i,i as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Dn as s,Er as c,Ht as l,ct as u,dt as d,gt as f,ha as p,ji as m,pr as h,st as g,xn as _}from"./player-overlays-Cw_gjG75.js";import{Fr as v,eo as y}from"./client-r4i0EpF6.js";import{A as b,An as x,C as S,Cr as C,E as w,Eu as T,F as E,Fo as D,Fr as O,Gr as k,Hr as A,I as ee,Ir as j,M as te,N as ne,Nr as M,O as re,On as N,P,Pr as F,S as I,T as ie,Tr as ae,Yr as L,_ as oe,b as se,bn as ce,br as le,di as R,f as ue,g as de,if as fe,j as pe,jn as z,jr as me,k as he,lo as ge,m as _e,p as ve,ri as B,uo as ye,w as be,wr as xe,xn as Se,xr as Ce,y as we,yr as Te}from"./src-nnHXOip7.js";import{t as V}from"./useTranslation-BJr-n0es.js";import{br as Ee}from"./index-Ohn-2iW_.js";import{t as De}from"./AdminPage-7avIuDBh.js";i();function H(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:S(i),ref:i,info:e,subjectName:t.name,location:t.location??``,nodeId:``,metric:H(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:S(i),ref:i,info:t,subjectName:e.name,location:``,nodeId:e.id,metric:H(t,n)})}return r}function ke(e){return[e.subjectName,e.location,e.metric,e.info.key,e.info.unit??``,e.nodeId].join(` `)}function U(e,t,n){if(e.ref.subject.kind!==`device`||t===null)return e.subjectName;let r=t.byId.get(e.ref.subject.deviceId);return r===void 0?e.subjectName:A(r,`compact`,t,n)}var Ae=[`energy`,`temperatures`,`nodes`,`storage`],je=new Set([`cap:temperature-sensor.temperature`,`cap:climate-control.currentTemp`]),W=[`addon:metrics-native/node-cpu-percent`,`addon:metrics-native/node-memory-percent`],Me=`addon:storage-orchestrator/location-used-percent`;function Ne(e,t){let n=(e,n)=>{let r=t.filter(e);return I((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`&&je.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`&&W.includes(e.info.key)&&e.info.scope===``,(e,t)=>W.indexOf(e.info.key)-W.indexOf(t.info.key)||e.subjectName.localeCompare(t.subjectName));case`storage`:return n(e=>e.ref.subject.kind===`node`&&e.info.key===Me)}}function Pe(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[],i=[],a=[],o=[];for(let t of I(e)){let e=n.get(S(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 G(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 K=`history-page`;function Fe({part:r,window:i}){let{t:a}=V(),o=p(),s=L(),c=k(),l=e=>`${U(e,s,c)} · ${e.metric}`,u=t(()=>[...r.lines,...r.states,...r.energy],[r]),d=de(t(()=>u.map(e=>G(e.ref)),[u]),i,!1),f=e=>d.status===`ok`?d.data.current.get(_e(G(e.ref))):void 0,h=e=>{let t=f(e);return t?.ok?t.result:void 0};if(u.length===0)return n(F,{icon:m,title:a(`history.page.emptyTitle`,`Pick series to compare`),description:a(`history.page.emptyHint`,`Choose up to 24 series on the left, or start from a panel above.`)});if(d.status===`error`)return n(M,{title:a(`history.page.readFailed`,`History could not be read`),message:d.error});let g=d.status===`pending`,_=u.map(e=>({c:e,e:f(e)})).filter(e=>e.e?.ok===!1),v=r.lines.map((e,t)=>{let n=h(e),r=he(e.info,n,i.from);return{id:e.id,label:l(e),unit:e.info.unit,colorIndex:t,points:r.points,gapMs:r.gapMs,interpolation:r.held&&n?.resolution===`raw`?`step`:`linear`}}),y=r.states.map((e,t)=>{let n=b(e.info,h(e),i.from,i.to),r=w(e.info.key,o);return{id:e.id,label:l(e),kind:e.info.kind===`boolean`?`boolean`:`enum`,colorIndex:e.info.kind===`boolean`?t:0,states:n.states,segments:n.segments,totals:n.totals,stateLabel:e.info.kind===`boolean`?e=>e===`true`?r.on:r.off:void 0}}),x=r.energy.map(e=>({c:e,...re(h(e))})),S=x[0]?.bucketMs??36e5,C=[...new Set(x.flatMap(e=>e.buckets.map(e=>e.t)))].sort((e,t)=>e-t).map(e=>({t:e,values:x.map(t=>t.buckets.find(t=>t.t===e)?.values[0]??null)}));return e(`div`,{className:`space-y-5 min-w-0`,children:[_.length>0&&n(M,{title:a(`history.page.someFailed`,`Some series could not be read`),message:_.map(e=>`${l(e.c)}: ${e.e.error}`).join(` · `)}),v.length>0&&n(ee,{title:a(`history.page.lines`,`Measurements`),series:v,range:i,height:260,syncKey:K,pending:g}),x.length>0&&n(me,{title:a(`history.page.energy`,`Energy`),layers:x.map((e,t)=>({id:e.c.id,label:U(e.c,s,c),colorIndex:t})),buckets:C,bucketMs:S,range:i,unit:`kWh`,showTotal:!0,height:160,syncKey:K,pending:g}),y.length>0&&n(E,{title:y.length===1?y[0]?.label??``:a(`history.page.states`,`States`),rows:y,range:i,syncKey:K,pending:g})]})}function Ie(e,t){let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}async function Le(e,t){let n=[];for(let r of Ie(e,50))try{let{results:e}=await t(r),i=new Map(e.map(e=>[e.seriesId,e]));for(let e of r)n.push(i.get(e)??{seriesId:e,ok:!1,reason:`not-found`})}catch(e){let t=e instanceof Error?e.message:String(e);for(let e of r)n.push({seriesId:e,ok:!1,reason:`request-failed`,message:t})}return n}function q(e){return e.raw+e[`5m`]+e[`1h`]+e[`1d`]}function Re(e){return e.reduce((e,t)=>t.ok?{...e,deleted:e.deleted+1,points:e.points+q(t.deleted)}:{...e,refused:e.refused+1},{deleted:0,refused:0,points:0})}function ze(e,t){let n=new Map(e.map(e=>[e.seriesId,e]));return t.flatMap(e=>{let t=n.get(e.seriesId);return t===void 0?[]:[{series:t,outcome:e}]})}var J=e=>new Date(e).toLocaleDateString(void 0,{dateStyle:`short`});function Y(e,t,n){let r=t.get(e.deviceId);return r===void 0?e.reason===`device-gone`?n(`history.orphans.deviceRemoved`,`#{{id}} (removed)`,{id:e.deviceId}):n(`history.orphans.deviceId`,`#{{id}}`,{id:e.deviceId}):r}function X(e){let t=e.displayName??e.key;return e.scope===``?t:`${t} · ${e.scope}`}function Z(t,r,i){return{key:`series`,header:i(`history.orphans.colSeries`,`Series`),render:a=>{let o=t(a);return e(`div`,{className:`min-w-0 max-w-[16rem]`,children:[n(`div`,{className:`truncate text-foreground`,title:o.key,children:X(o)}),n(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:Y(o,r,i)})]})},sortValue:e=>`${Y(t(e),r,i)} ${X(t(e))}`}}var Be=[`raw`,`5m`,`1h`,`1d`];function Ve(e,t){return e===`raw`?t(`history.orphans.colRaw`,`Raw points`):e===`5m`?t(`history.orphans.col5m`,`5 min`):e===`1h`?t(`history.orphans.col1h`,`1 h`):t(`history.orphans.col1d`,`1 day`)}function He(t,r){return[Z(e=>e,t,r),{key:`reason`,header:r(`history.orphans.colReason`,`Reason`),render:t=>e(`div`,{className:`flex flex-col items-start gap-0.5`,children:[n(R,{variant:t.reason===`device-gone`?`warning`:`neutral`,className:`text-[10px]`,children:t.reason===`device-gone`?r(`history.orphans.deviceGone`,`Device removed`):r(`history.orphans.undeclared`,`No longer declared`)}),t.missingSince!==null&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:r(`history.orphans.since`,`since {{date}}`,{date:J(t.missingSince)})})]}),sortValue:e=>e.reason},{key:`span`,header:r(`history.orphans.colSpan`,`Recorded`),render:t=>e(`span`,{className:`tabular-nums text-foreground-muted`,children:[J(t.firstTs),` → `,J(t.lastTs)]}),sortValue:e=>e.lastTs},...Be.map(e=>({key:`rows-${e}`,header:Ve(e,r),align:`right`,render:t=>n(`span`,{className:`tabular-nums text-foreground-muted`,children:t.rows[e].toLocaleString()}),sortValue:t=>t.rows[e]}))]}function Ue(e,t){if(e.ok)return n(R,{variant:`success`,className:`text-[10px]`,children:t(`history.orphans.deleted`,{count:q(e.deleted),points:q(e.deleted).toLocaleString(),defaultValue_one:`Deleted · {{points}} point`,defaultValue_other:`Deleted · {{points}} points`})});let r=e.reason===`request-failed`?t(`history.orphans.requestFailed`,`Not sent: {{message}}`,{message:e.message}):e.reason===`not-orphan`?t(`history.orphans.refusedNotOrphan`,`Kept: no longer orphan`):e.reason===`not-found`?t(`history.orphans.refusedNotFound`,`Already gone`):t(`history.orphans.refusedFailed`,`The hub could not delete it`);return n(R,{variant:e.reason===`not-found`?`neutral`:`warning`,className:`text-[10px]`,children:r})}function We(e,t){return[Z(e=>e.series,e,t),{key:`result`,header:t(`history.orphans.colResult`,`Result`),render:e=>Ue(e.outcome,t),sortValue:e=>+!e.outcome.ok}]}i();function Ge({open:i,onClose:a,list:o,deviceNames:c,onDelete:u,onRefresh:d,refreshing:f}){let{t:p}=V(),m=g(),[_,v]=r(new Set),[y,b]=r(!1),[S,w]=r([]),T=t(()=>He(c,p),[c,p]),E=t(()=>We(c,p),[c,p]),D=t(()=>new Set(o.series.map(e=>String(e.seriesId))),[o.series]),O=[..._].filter(e=>D.has(e)).map(Number),k=Re(S.map(e=>e.outcome)),A=async()=>{if(await m({title:p(`history.orphans.confirmTitle`,{count:O.length,defaultValue_one:`Delete {{count}} series`,defaultValue_other:`Delete {{count}} series`}),message:p(`history.orphans.confirmMessage`,`Every recorded point of these series is removed from the hub. This cannot be undone.`),confirmLabel:p(`history.orphans.confirmLabel`,`Delete`),variant:`danger`})){b(!0);try{let e=await Le(O,u);w(ze(o.series,e)),v(new Set)}finally{b(!1),d()}}};return n(Te,{open:i,onOpenChange:e=>!e&&a(),children:e(Ce,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`orphan-series-dialog`,children:[n(xe,{children:n(ae,{children:p(`history.orphans.title`,`Series no longer linked to a device`)})}),e(le,{className:`space-y-3`,children:[n(`p`,{className:`text-xs text-foreground-muted`,children:p(`history.orphans.intro`,`Nothing records into these series any more: their device was removed, or no capability declares them now. Select the ones to delete.`)}),o.truncated&&e(`div`,{className:`flex flex-wrap items-center gap-2`,"data-testid":`orphan-truncated`,children:[n(`p`,{className:`text-xs text-warning`,children:p(`history.orphans.truncated`,`More series are unlinked than are listed here. Delete these, then load the rest.`)}),e(B,{size:`sm`,variant:`outline`,onClick:d,disabled:f,children:[n(s,{className:`h-3 w-3`,"aria-hidden":!0}),p(`history.orphans.loadAgain`,`Load again`)]})]}),S.length>0&&e(`div`,{className:`space-y-2`,"data-testid":`orphan-outcomes`,children:[n(`p`,{className:`text-xs text-foreground`,"aria-live":`polite`,children:p(`history.orphans.summary`,{count:k.deleted,refused:k.refused,points:k.points.toLocaleString(),defaultValue_one:`{{count}} series deleted ({{points}} points), {{refused}} kept.`,defaultValue_other:`{{count}} series deleted ({{points}} points), {{refused}} kept.`})}),n(x,{columns:E,rows:S,rowKey:e=>String(e.series.seriesId),minWidthPx:420,maxBodyHeight:`max-h-[60vh]`,emptyMessage:``})]}),n(x,{columns:T,rows:o.series,rowKey:e=>String(e.seriesId),minWidthPx:760,maxBodyHeight:z,defaultSort:{columnKey:`series`,dir:`asc`},emptyMessage:p(`history.orphans.empty`,`Every series is linked to a device.`),selection:{selected:_,onChange:v,rowLabel:e=>`${X(e)} — ${Y(e,c,p)}`,pageLabel:p(`history.orphans.selectAll`,`Select every listed series`)}})]}),e(C,{children:[n(`span`,{className:`mr-auto text-[11px] tabular-nums text-foreground`,"aria-live":`polite`,children:p(`history.orphans.selected`,{count:O.length,defaultValue_one:`{{count}} selected`,defaultValue_other:`{{count}} selected`})}),n(B,{variant:`ghost`,size:`sm`,onClick:a,children:p(`history.orphans.close`,`Close`)}),e(B,{variant:`danger`,size:`sm`,disabled:O.length===0||y,onClick:()=>void A(),children:[y?n(h,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):n(l,{className:`h-3 w-3`,"aria-hidden":!0}),p(`history.orphans.deleteSelected`,`Delete selected`)]})]})]})})}i();var Ke=5*6e4;function qe({enabled:i}){let{t:a}=V(),[s,c]=r(!1),l=ye({},{enabled:i,staleTime:Ke}),u=D({projection:`slim`},{enabled:i}),d=ge(),f=t(()=>new Map((u.data??[]).map(e=>[e.id,e.name])),[u.data]),p=e=>d.mutateAsync({seriesIds:[...e]});if(!i||l.status===`pending`)return null;if(l.status===`error`)return n(M,{variant:`warning`,title:a(`history.orphans.checkFailedTitle`,`Could not check for unlinked series`),message:l.error.message,onRetry:()=>void l.refetch()});let m=l.data;if(m.series.length===0&&!s)return null;let h=m.series.length;return e(o,{children:[h>0&&n(M,{variant:`warning`,message:m.truncated?a(`history.orphans.noticeMore`,{count:h,defaultValue_one:`More than {{count}} series are no longer linked to a device.`,defaultValue_other:`More than {{count}} series are no longer linked to a device.`}):a(`history.orphans.notice`,{count:h,defaultValue_one:`{{count}} series is no longer linked to a device.`,defaultValue_other:`{{count}} series are no longer linked to a device.`}),action:n(B,{size:`sm`,variant:`outline`,onClick:()=>c(!0),children:a(`history.orphans.review`,`Review`)})}),n(Ge,{open:s,onClose:()=>c(!1),list:m,deviceNames:f,onDelete:p,onRefresh:()=>void l.refetch(),refreshing:l.isFetching})]})}i();var Q=`device`,Je=`node`;function Ye({catalog:r,selected:i,onChange:a,loading:o}){let{t:s}=V(),c=L(),l=k(),u=e=>U(e,c,l),d=ce(r,{searchText:e=>[ke(e)],facetGroups:[{id:`subject`,value:e=>e.ref.subject.kind===`device`?Q:Je},{id:`room`,value:e=>e.location},{id:`unit`,value:e=>e.info.unit??``}]}),f=t(()=>[{key:`metric`,header:s(`history.picker.series`,`Series`),render:t=>e(`div`,{className:`min-w-0`,children:[n(`div`,{className:`truncate text-foreground`,children:t.metric}),n(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.location===``?u(t):`${u(t)} · ${t.location}`})]}),sortValue:e=>`${e.subjectName} ${e.metric}`},{key:`unit`,header:s(`history.picker.unit`,`Unit`),render:e=>n(`span`,{className:`text-foreground-muted`,children:e.info.unit??`—`}),sortValue:e=>e.info.unit??``}],[s,c,l]),p=i.size>=24;return e(`div`,{className:`space-y-2 min-w-0`,children:[n(Se,{state:d.state,facets:[],groups:[{...d.groups.find(e=>e.id===`subject`)??{id:`subject`,facets:[],selected:[]},label:s(`history.picker.subject`,`Source`),facetLabel:e=>e===Q?s(`history.picker.devices`,`Devices`):s(`history.picker.nodes`,`Nodes`)},{...d.groups.find(e=>e.id===`room`)??{id:`room`,facets:[],selected:[]},label:s(`history.picker.room`,`Room`),facetLabel:e=>e===``?s(`history.picker.noRoom`,`No room`):e},{...d.groups.find(e=>e.id===`unit`)??{id:`unit`,facets:[],selected:[]},label:s(`history.picker.metricType`,`Unit`),facetLabel:e=>e===``?s(`history.picker.noUnit`,`States & counts`):e}],labels:{searchPlaceholder:s(`history.picker.search`,`Search device, room, metric or node…`),searchLabel:s(`history.picker.searchLabel`,`Search series`),facetsLabel:s(`history.picker.facets`,`Filters`),clearLabel:s(`history.picker.clear`,`Clear`)},onSearch:d.setSearch,onToggleFacet:d.toggleFacet,onToggleGroupFacet:d.toggleGroupFacet,onClear:d.clear}),n(`p`,{className:`text-[10px] text-foreground-subtle`,"aria-live":`polite`,children:s(`history.picker.count`,`{{count}} of {{max}} selected`,{count:i.size,max:24})}),n(x,{columns:f,rows:d.rows,rowKey:e=>e.id,maxBodyHeight:z,pageSize:50,defaultSort:{columnKey:`metric`,dir:`asc`},emptyMessage:o?s(`history.picker.loading`,`Reading the series of every device…`):d.active?s(`history.picker.emptyFiltered`,`No series match these filters.`):s(`history.picker.empty`,`Nothing is recorded yet.`),selection:{selected:i,onChange:e=>{let t=[...e].filter(e=>i.has(e)),n=[...e].filter(e=>!i.has(e));a(new Set([...t,...n].slice(0,24)))},isSelectable:e=>i.has(e.id)||!p,rowLabel:e=>`${u(e)} · ${e.metric}`,pageLabel:s(`history.picker.selectPage`,`Select every series on this page`)}})]})}i();var Xe=new Set([y.Hub,y.Container]),$=5*6e4;function Ze(){let{t:r}=V(),i=O(`device-history`),[a,o]=Ee(),s=t(()=>I(a.getAll(`s`).flatMap(e=>{let t=we(e);return t===null?[]:[t]})),[a]),l=a.get(`window`),d=ne(l)?l:`7d`,p=pe(a.get(`range`)),h=(e,t,n)=>{let r=new URLSearchParams;for(let t of I(e))r.append(`s`,se(t));t!==`7d`&&r.set(`window`,t);let i=n===void 0?a.get(`range`):n;t===`custom`&&i&&r.set(`range`,i),o(r,{replace:!0})},v=Qe(i===`present`),y=P(d,Date.now(),p),b=P(d,ve(Date.now(),y.to-y.from),p),x=t(()=>Pe(s,v.candidates),[s,v.candidates]),C=t(()=>new Set(s.map(S)),[s]),w=ue(),T=u(),E=g(),D=async()=>{let e=await T({title:r(`history.page.saveTitle`,`Save as panel`),label:r(`history.page.saveName`,`Panel name`),confirmLabel:r(`history.page.save`,`Save`)});e===null||e.trim()===``||await w.update(t=>be(t,{id:`panel-${Date.now().toString(36)}`,name:e.trim().slice(0,80),window:d,selection:[...s]}))},k=async(e,t)=>{await E({title:r(`history.page.deleteTitle`,`Delete panel`),message:r(`history.page.deleteMessage`,`The panel "{{name}}" is removed from your account.`,{name:t}),confirmLabel:r(`history.page.delete`,`Delete`),variant:`danger`})&&await w.update(t=>ie(t,e))},A=e=>e===`energy`?r(`history.panels.energy`,`Total energy`):e===`temperatures`?r(`history.panels.temperatures`,`Temperatures by room`):e===`nodes`?r(`history.panels.nodes`,`Cluster nodes`):r(`history.panels.storage`,`Storage locations`);return n(De,{icon:m,title:r(`history.page.title`,`History`),subtitle:r(`history.page.subtitle`,`What devices, nodes and storage recorded over time, side by side.`),actions:i===`present`?e(B,{size:`sm`,variant:`outline`,onClick:()=>void D(),disabled:s.length===0||!w.writable,children:[n(_,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),r(`history.page.saveTitle`,`Save as panel`)]}):void 0,children:i===`pending`?n(j,{className:`h-64 w-full`}):i===`unknown`?n(M,{title:r(`history.page.presenceUnknownTitle`,`Could not reach the hub`),message:r(`history.page.presenceUnknown`,`The hub did not say whether device history is installed. Try again in a moment.`)}):i===`absent`?n(F,{icon:c,title:r(`history.page.absentTitle`,`Device history is not running on this hub`),description:r(`history.page.absent`,`Nothing is recorded until the device-history system addon is enabled.`)}):e(`div`,{className:`space-y-3 sm:space-y-4`,children:[n(qe,{enabled:i===`present`}),e(`div`,{className:`flex flex-wrap items-center gap-2`,role:`group`,"aria-label":r(`history.page.panels`,`Panels`),children:[Ae.map(e=>n(B,{size:`sm`,variant:`outline`,disabled:v.status!==`ok`,onClick:()=>h(Ne(e,v.candidates),d),children:A(e)},e)),w.value.panels.map(t=>e(`span`,{className:`inline-flex items-center`,children:[n(B,{size:`sm`,variant:`secondary`,onClick:()=>h(t.selection,t.window,null),children:t.name}),n(B,{size:`sm`,variant:`ghost`,"aria-label":r(`history.page.deleteNamed`,`Delete panel {{name}}`,{name:t.name}),onClick:()=>void k(t.id,t.name),disabled:!w.writable,children:n(f,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})]},t.id))]}),e(`div`,{className:`grid grid-cols-1 gap-3 sm:gap-4 xl:grid-cols-5`,children:[n(`div`,{className:`min-w-0 xl:col-span-2`,children:n(N,{headingId:`history-picker`,title:r(`history.picker.title`,`Series`),children:n(`div`,{className:`p-2 sm:p-3`,children:v.status===`error`?n(M,{message:v.error}):n(Ye,{catalog:v.candidates,loading:v.status===`pending`,selected:C,onChange:e=>{let t=s.filter(t=>e.has(S(t))),n=v.candidates.filter(t=>e.has(t.id)&&!C.has(t.id)).map(e=>e.ref);h([...t,...n],d)}})})})}),n(`div`,{className:`min-w-0 xl:col-span-3`,children:n(N,{headingId:`history-overlay`,title:r(`history.page.overlay`,`Overlay`),actions:s.length>0?n(B,{size:`sm`,variant:`ghost`,onClick:()=>h([],d),children:r(`history.page.clear`,`Clear`)}):void 0,children:e(`div`,{className:`p-2 sm:p-3 space-y-3 min-w-0`,children:[n(oe,{value:d,onChange:e=>h(s,e),custom:p,onCustomChange:e=>h(s,`custom`,te(e))}),v.status===`pending`&&s.length>0?n(j,{className:`h-64 w-full`}):n(Fe,{part:x,window:b}),x.missing.length>0&&v.status===`ok`&&n(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`history.page.missing`,{count:x.missing.length,defaultValue_one:`{{count}} selected series is no longer recorded.`,defaultValue_other:`{{count}} selected series are no longer recorded.`})})]})})})]})]})})}function Qe(e){let{t:n}=V(),r=n(`history.picker.wholeFrame`,`Whole frame`),i=d().trpcClient,o=D({projection:`slim`},{enabled:e}),{nodes:s}=fe(),c=t(()=>(o.data??[]).filter(e=>!Xe.has(String(e.type))),[o.data]),l=a({queries:c.map(t=>({queryKey:[`device-history`,`listSeries`,t.id],queryFn:()=>i.deviceHistory.listSeries.query({deviceId:t.id}),enabled:e,staleTime:$}))}),u=a({queries:s.map(t=>({queryKey:[`device-history`,`listNodeSeries`,t.id],queryFn:()=>i.deviceHistory.listNodeSeries.query({forNodeId:t.id}),enabled:e,staleTime:$}))}),f=T({},{enabled:e,staleTime:$}),p=t(()=>new Map((f?.data??[]).map(e=>[e.id,e.displayName])),[f?.data]),m=l.map(e=>e.data),h=u.map(e=>e.data),g=t(()=>Oe(c.flatMap((e,t)=>{let n=m[t];return n===void 0?[]:[{device:{id:e.id,name:e.name,location:e.location??null},series:n}]}),s.flatMap((e,t)=>{let n=h[t];return n===void 0?[]:[{node:{id:e.id,name:e.name},series:n}]}),e=>{if(e.key!==`addon:pipeline-analytics/occupancy`)return p.get(e.scope)??e.scope;let{zoneId:t,className:n}=v(e.scope),i=t===``?r:t;return n===void 0?i:`${i} · ${n}`}),[c,s,p,[...l,...u].map(e=>e.dataUpdatedAt).join(`,`),r]);return o.status===`error`?{status:`error`,error:o.error.message,candidates:[]}:{status:o.status===`pending`||l.some(e=>e.isPending)||u.some(e=>e.isPending)?`pending`:`ok`,error:``,candidates:g}}export{Ze as HistoryPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,a as s,et as c,o as l,t as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$i as f,D as p,Dn as m,Gr as h,Hn as g,Ht as _,In as v,Qr as y,Si as b,_n as x,an as S,ct as C,dn as w,dt as T,gr as E,gt as D,jt as O,mn as k,pn as A,pr as j,st as M,ur as ee,xr as N,yn as P,zt as F}from"./player-overlays-Cw_gjG75.js";import{Ho as I,Uo as L,Wo as R,c as te,no as ne,to as z}from"./client-r4i0EpF6.js";import{n as B,r as re,t as ie}from"./key-DddJ6bil.js";import{f as ae,s as oe,u as se}from"./video-DXegVNA2.js";import{t as ce}from"./file-up-Bizrs9Ca.js";import{t as le}from"./key-round-CbCqycf3.js";import{t as ue}from"./monitor-smartphone-CwOoXB0L.js";import{t as de}from"./unlink-DNy8sNAV.js";import{An as fe,Cd as pe,Cn as V,Cr as me,Ed as he,Et as ge,Fd as _e,Fo as H,Hi as ve,Id as ye,Ir as be,Jn as xe,Kn as Se,Ld as Ce,Nd as we,Nr as U,On as Te,Pd as Ee,Pr as De,Qn as Oe,Rd as ke,Sd as Ae,Sn as je,Td as Me,Tr as Ne,U as Pe,Ui as Fe,Xn as Ie,Yn as Le,Zn as Re,_d as ze,_r as Be,_t as Ve,ac as He,bd as Ue,br as We,cc as Ge,ct as Ke,di as W,fc as qe,gd as Je,hd as Ye,jn as Xe,kn as G,lf as K,mr as Ze,pc as Qe,rc as $e,ri as q,vd as et,wd as tt,wr as nt,xd as rt,xr as it,yd as at,yr as ot,yt as st}from"./src-nnHXOip7.js";import{t as J}from"./i18n-BE1bPZOs.js";import{t as Y}from"./useTranslation-BJr-n0es.js";import{T as ct,a as lt,br as ut,d as dt,gr as ft,hr as pt,i as mt,ir as ht,l as gt,mr as _t,vr as vt}from"./index-Ohn-2iW_.js";import{t as yt}from"./AdminSectionedPage-Bd2owMGm.js";import{t as bt}from"./AdminPage-7avIuDBh.js";import{A as xt,C as St,D as Ct,E as wt,O as X,S as Tt,T as Et,a as Dt,b as Ot,c as kt,d as At,f as jt,g as Mt,h as Nt,i as Pt,k as Ft,l as It,m as Lt,n as Rt,o as zt,p as Bt,s as Vt,t as Ht,u as Ut,v as Wt,w as Gt,x as Kt,y as qt}from"./SessionsList-QvqpXCDN.js";import{i as Jt,n as Yt,r as Xt,t as Zt}from"./IntegrationHub-DndCuqMe.js";import{n as Qt,t as $t}from"./addon-display-names-BkwMrExv.js";c();function en(){let{t:e}=Y(),t=M(),r=K.useUtils(),a=xt(),{data:s,isLoading:c}=rt(),l=n(()=>s??[],[s]),u=K.useQueries(e=>l.map(t=>e.userManagement.listExternalIdentities({userId:t.id}))),d=K.auth.listLoginMethods.useQuery(),[f,p]=o(null),m=Me({onSuccess:()=>void r.userManagement.listExternalIdentities.invalidate(),onError:e=>p(`Remove failed: ${e.message}`)}),h=n(()=>new Map((d.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),[d.data]),g=l.flatMap((e,t)=>u[t]?.data??[]),_=g.map(e=>({...Tt(e,a),kind:h.get(e.provider)??e.provider})),v=async n=>{let r=g.find(e=>Kt(e)===n.id);r!==void 0&&await t({title:e(`access.externalIdentitiesSection.removeSignInLink`,`Remove sign-in link`),message:e(`access.externalIdentitiesSection.willNoLongerBeAble`,`"{{ownerName}}" will no longer be able to sign in with this {{kind}} account.`,{ownerName:n.ownerName,kind:n.kind}),confirmLabel:e(`common.remove`,`Remove`),variant:`danger`})&&(p(null),m.mutate({userId:r.userId,provider:r.provider,subject:r.subject}))};return i(X,{notice:Ft(f),onDismissNotice:()=>{p(null)},id:`external-identities`,title:e(`access.externalIdentitiesSection.signInLinks`,`Sign-in links`),icon:ae,description:e(`access.externalIdentitiesSection.externalAccountsSingleSignOn`,`External accounts (single sign-on) each user linked to their CamStack account. Only the owner can link one, from their profile; an admin can remove it.`),children:i(Et,{rows:_,label:`sign-in links`,isLoading:c||u.some(e=>e.isLoading),loadError:u.find(e=>e.isError)?.error?.message??null,emptyText:`No user has linked a sign-in account.`,expiresNone:`—`,action:{label:e(`common.remove`,`Remove`),icon:de,isAvailable:()=>!0,onRun:e=>void v(e),busyId:null,disabled:m.isPending}})})}c();var tn={key:`access.nouns.linkedApp`};function nn(e){if(e.type===`category`){let t=e.target??``;return t===`device`?J.t(`access.linkedAppsSection.allDevices`):J.t(`access.linkedAppsSection.allTarget`,{target:t})}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function rn(){let{t:e}=Y(),t=M(),r=l(),a=Ue(),[s,c]=o(null),u=()=>void r.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]}),d=pe({onSuccess:u,onError:e=>c(`Revoke failed: ${e.message}`)}),f=wt(tn,u),p=n(()=>(a.data??[]).map(e=>St(e,e.scopes.map(nn).join(`, `))),[a.data]),m=async n=>{await t({title:e(`access.linkedAppsSection.revokeTheLink`,`Revoke the "{{name}}" link?`,{name:n.name}),message:e(`access.linkedAppsSection.losesAccessForOnIts`,`{{name}} loses access for {{ownerName}} on its next call. Linking it again needs the account-link flow from the start.`,{name:n.name,ownerName:n.ownerName}),confirmLabel:e(`access.linkedAppsSection.revoke`,`Revoke`),variant:`danger`})&&(c(null),d.mutate({id:n.id}))},h=d.isPending?d.variables?.id??null:null;return i(X,{notice:Ft(s,f.outcome),onDismissNotice:()=>{c(null),f.dismiss()},id:`linked-apps`,title:e(`access.linkedAppsSection.linkedApps`,`Linked apps`),icon:E,description:e(`access.linkedAppsSection.externalIntegrationsAlexaLinkedTo`,`External integrations (Alexa, …) linked to this hub through OAuth. Revoking one stops that integration on its next call. Already-revoked rows can be selected and removed from the list.`),children:i(Et,{rows:p,label:e(`access.linkedAppsSection.linkedApps2`,`linked apps`),isLoading:a.isLoading,loadError:a.isError?a.error?.message??`Request failed`:null,emptyText:`No linked apps — an integration appears here once it completes the account-link flow.`,expiresNone:`—`,action:{label:e(`access.linkedAppsSection.revoke`,`Revoke`),icon:_,isAvailable:e=>e.status===`active`||e.status===`revoked`,onRun:e=>void m(e),busyId:h,disabled:d.isPending||f.busy},bulk:{revoke:f,noun:tn,isSelectable:e=>e.status===`active`||e.status===`revoked`,quickSelect:[{label:e(`access.linkedAppsSection.selectRevoked`,`Select revoked`),match:e=>e.status===`revoked`}]}})})}c();var an={key:`access.nouns.session`};function on(){let{t:e}=Y(),t=M(),r=K.useUtils(),a=xt(),s=K.auth.listSessions.useQuery(),[c,l]=o(null),u=()=>void r.auth.listSessions.invalidate(),d=K.auth.revokeSessions.useMutation({onSuccess:u,onError:e=>l(`Sign out failed: ${e.message}`)}),f=wt(an,u),p=n(()=>(s.data??[]).map(e=>Gt(e,a,{client:e=>Wt(e).label,method:qt})),[s.data,a]),m=async n=>{await t({title:e(`access.loginSessionsSection.signOutThisSession`,`Sign out this session`),message:e(`access.loginSessionsSection.onWillHaveToSign`,`{{ownerName}} on {{name}} will have to sign in again.`,{ownerName:n.ownerName,name:n.name}),confirmLabel:e(`access.loginSessionsSection.signOut`,`Sign out`),variant:`danger`})&&(l(null),d.mutate({id:n.id}))};return i(X,{notice:Ft(c,f.outcome),onDismissNotice:()=>{l(null),f.dismiss()},id:`login-sessions`,title:e(`access.loginSessionsSection.loginSessions`,`Login sessions`),icon:ue,description:e(`access.loginSessionsSection.everyBrowserAndAppSigned`,`Every browser and app signed in to this hub, for every user. Signing one out ends it at once; it has to sign in again. Your own current session is marked and never included in a bulk sign-out.`),children:i(Et,{rows:p,label:e(`common.sessionsLabel`),isLoading:s.isLoading,loadError:s.isError?s.error?.message??`Request failed`:null,emptyText:`No active sessions.`,action:{label:e(`access.loginSessionsSection.signOut`,`Sign out`),icon:oe,isAvailable:e=>e.status===`active`,onRun:e=>void m(e),busyId:d.isPending&&d.variables!==void 0&&`id`in d.variables?d.variables.id:null,disabled:d.isPending||f.busy},bulk:{revoke:f,noun:an,isSelectable:e=>e.status===`active`}})})}var sn={"by-id":`helpers.authAuditWording.bulkNoun.credential`,"share-link":`helpers.authAuditWording.bulkNoun.shareLink`,"admin-token":`helpers.authAuditWording.bulkNoun.adminToken`,"login-session":`helpers.authAuditWording.bulkNoun.loginSession`};function Z(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function cn(e,t){let n=Z(e,`tokenId`);return Z(e,`name`)??(n===null?void 0:t.get(n))??n??`?`}function Q(e){return e.filter(e=>e!==null)}function ln(e){let t=Z(e,`prefix`);return t===null?null:J.t(`helpers.authAuditWording.prefix`,{prefix:t})}function un(e,t){let n=e.detail??{};switch(e.action){case`admin-token-created`:{let e=n.expiresAt;return{title:J.t(`helpers.authAuditWording.tokenCreated`,{name:cn(n,t)}),details:Q([ln(n),typeof e==`number`?J.t(`helpers.authAuditWording.expires`,{at:Ot(e)}):null])}}case`admin-token-used`:{let e=Z(n,`path`);return{title:J.t(`helpers.authAuditWording.tokenUsed`,{name:cn(n,t)}),details:Q([ln(n),e===null?null:J.t(`helpers.authAuditWording.call`,{path:e})])}}case`token-minted`:{let e=n.expiresAt;return{title:J.t(`helpers.authAuditWording.tokenMinted`,{name:cn(n,t)}),details:Q([typeof e==`number`?J.t(`helpers.authAuditWording.expires`,{at:Ot(e)}):null])}}case`token-revoked`:return{title:J.t(`helpers.authAuditWording.anyTokenRevoked`,{name:cn(n,t)}),details:[]};case`admin-token-revoked`:return{title:J.t(`helpers.authAuditWording.tokenRevoked`,{name:cn(n,t)}),details:Q([ln(n)])};case`credentials-revoked`:{let e=Z(n,`kind`)??`credential`,t=n.revoked,r=n.skipped,i=sn[e],a=i===void 0?`${e}s`:J.t(i);return{title:J.t(`helpers.authAuditWording.bulkRevoked`,{n:typeof t==`number`?String(t):`?`,noun:a}),details:Q([typeof r==`number`&&r>0?J.t(`helpers.authAuditWording.skipped`,{count:r}):null,Z(n,`ids`)===null?null:J.t(`helpers.authAuditWording.ids`,{ids:Z(n,`ids`)??``})])}}case`second-factor-skipped`:{let e=Z(n,`method`),t=Z(n,`factors`);return{title:J.t(`helpers.authAuditWording.secondFactorSkipped`),details:Q([e===null?null:J.t(`helpers.authAuditWording.signedInWith`,{method:qt(e)}),t===null?null:J.t(`helpers.authAuditWording.skippedFactors`,{factors:t.split(`,`).join(`, `)})])}}default:return{title:e.action,details:Object.entries(n).map(([e,t])=>`${e}: ${String(t)}`)}}}c();var dn=100;function fn(){let{user:e}=ht();return e?.isAdmin?i(mn,{}):null}function pn(){let{data:e}=rt(),{data:t}=K.auth.listTokens.useQuery(void 0);return n(()=>{let n=new Map;for(let t of e??[])n.set(t.id,t.username);let r=new Map;for(let e of t??[])r.set(e.id,e.label);return{userNameById:n,tokenNameById:r}},[e,t])}function mn(){let{t}=Y(),n=K.auth.listAuthAudit.useQuery({limit:dn}),{userNameById:r,tokenNameById:a}=pn(),o=n.data??[];return e(`div`,{"data-testid":`auth-audit`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[e(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[i(P,{className:`h-3.5 w-3.5 text-foreground-subtle`}),i(`div`,{className:`text-xs font-semibold text-foreground`,children:t(`auth.authAuditSection.authenticationAudit`,`Authentication audit`)}),i(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:t(`auth.authAuditSection.latest`,{count:dn})})]}),i(`div`,{className:`p-4`,children:n.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(j,{className:`h-3.5 w-3.5 animate-spin`}),t(`auth.authAuditSection.loadingAuditTrail`,`Loading audit trail…`)]}):n.isError?e(`div`,{className:`text-[11px] text-danger`,children:[t(`auth.authAuditSection.couldNotLoadTheAudit`,`Could not load the audit trail:`),` `,n.error?.message??t(`auth.authAuditSection.requestFailed`,`Request failed`)]}):o.length===0?e(`div`,{className:`rounded border border-dashed border-border px-3 py-4 text-xs text-foreground-subtle text-center space-y-1`,children:[i(`div`,{children:t(`auth.authAuditSection.noAuthenticationEventsRecordedYet`,`No authentication events recorded yet.`)}),i(`div`,{className:`text-[11px] text-foreground-subtle/90`,children:t(`auth.authAuditSection.thisTrailRecordsAdminToken`,`This trail records admin-token create/use/revoke, trusted-network 2FA skips, and credential revokes (including single share-link revoke). Browser password logins are not listed here.`)})]}):i(`ul`,{className:`divide-y divide-border rounded-md border border-border max-h-[420px] overflow-y-auto`,children:o.map(e=>i(hn,{record:e,userName:e.userId===void 0?null:r.get(e.userId)??e.userId,tokenNameById:a},e.id))})})]})}function hn({record:t,userName:n,tokenNameById:r}){let a=un(t,r);return e(`li`,{"data-testid":`auth-audit-row`,className:`px-3 py-2 text-xs space-y-0.5`,children:[e(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[i(`span`,{className:`font-medium text-foreground`,children:a.title}),i(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Ot(t.at)})]}),e(`div`,{className:`flex flex-wrap gap-x-3 text-[11px] text-foreground-subtle`,children:[n!==null&&i(`span`,{className:`text-foreground`,children:n}),t.ip!==void 0&&i(`span`,{className:`font-mono`,children:t.ip}),a.details.map(e=>i(`span`,{className:`font-mono`,children:e},e))]})]})}c();var $={loginSessions:`login-sessions`,linkedApps:`linked-apps`,tokens:`tokens`,scopedTokens:`scoped-tokens`,adminTokens:`admin-tokens`,shareLinks:`share-links`,externalIdentities:`external-identities`,audit:`auth-audit`},gn={[$.scopedTokens]:$.tokens,[$.adminTokens]:$.tokens,[$.shareLinks]:$.tokens};function _n(){return[{id:$.loginSessions,label:J.t(`system.access.loginSessions`,`Login sessions`),icon:ue,render:()=>i(on,{})},{id:$.linkedApps,label:J.t(`system.access.linkedApps`,`Linked apps`),icon:E,render:()=>i(rn,{})},{id:$.tokens,label:J.t(`system.access.tokens`,`Tokens`),icon:le,render:({createRequested:e,onCreateConsumed:t})=>i(Nt,{headerOwnsCreate:!0,createRequested:e,onCreateConsumed:t})},{id:$.externalIdentities,label:J.t(`system.access.signInLinks`,`Sign-in links`),icon:ae,render:()=>i(en,{})},{id:$.audit,label:J.t(`system.access.audit`,`Audit`),icon:P,render:()=>i(fn,{})}]}function vn({createRequested:t=!1,onCreateConsumed:r}){let{t:a}=Y(),o=n(()=>_n(),[]),s=Jt({ids:n(()=>o.map(e=>e.id),[o]),answered:!0}),c=vt(),[l]=ut(),u=l.get(`integration`),d=u===null?void 0:gn[u];if(d!==void 0){let e=new URLSearchParams(l);return e.set(`integration`,d),i(ft,{to:`?${e.toString()}`,replace:!0})}let f=o.find(e=>e.id===s.selectedId)??o[0];return e(`div`,{className:`flex flex-col gap-3`,"data-testid":`access-page`,children:[i(Se,{appearance:`pills`,value:f?.id??$.loginSessions,onValueChange:e=>{c(`?${dt(l,e,null,null).toString()}`)},children:i(xe,{"aria-label":a(`system.access.credentialKinds`,`Credential kinds`),children:o.map(t=>e(Le,{value:t.id,"data-testid":`access-kind-${t.id}`,children:[i(t.icon,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),t.label]},t.id))})}),f===void 0?null:i(`div`,{role:`region`,"aria-label":f.label,"data-testid":`access-kind-body`,children:f.render({createRequested:t&&f.id===$.tokens,onCreateConsumed:r??(()=>void 0)})},f.id)]})}function yn(t,n){if(t===$.tokens)return e(q,{size:`sm`,type:`button`,"data-testid":`access-new-token`,onClick:n,children:[i(le,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),J.t(`system.access.newToken`,`New token`)]})}function bn(){let[e,t]=o(!1);return{createRequested:e,requestCreate:()=>t(!0),clearCreate:()=>t(!1)}}c();var xn=[`oidcConnections`,`listConnections`],Sn=[`oidcConnections`,`connectionFormSchema`],Cn={displayName:`OpenID Connect`,icon:`shield-check`,issuerUrl:``,clientId:``,clientSecret:``,redirectUri:``,scopes:`openid profile email`,usernameClaim:`preferred_username`},wn=/^[a-z0-9][a-z0-9-]{0,63}$/;function Tn(e){return e instanceof Error?e.message:String(e)}function En(e,t){if(t)return typeof e==`string`&&e.length>0?e:void 0;if(L(e))return I;if(typeof e==`string`&&e.length>0)return e;R(e)}function Dn(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function On({addonId:c}){let{t:f}=Y(),p=T(),m=l(),h=M(),g=Ve({editKey:`oidcEdit`,newKey:`oidcNew`}),[y,b]=o(!1),[x,S]=o(null),[C,w]=o(``),[E,D]=o({...Cn}),O=t(null),k=s({queryKey:[...xn,c],queryFn:async()=>p.trpcClient.oidcConnections.listConnections.query({})}),j=s({queryKey:Sn,queryFn:async()=>p.trpcClient.oidcConnections.connectionFormSchema.query({})}),ee=k.data??[],N=Dn(j.data)?j.data:void 0,P=g.state,F=P.mode===`edit`?ee.find(e=>e.id===P.id)??null:null;a(()=>{if(g.state.mode===`edit`&&F!==null){let e=`edit:${F.id}`;if(O.current===e)return;O.current=e,S(null),w(F.id),D(F.formValues===void 0?{...Cn}:{...F.formValues});return}if(g.state.mode===`new`){if(O.current===`new`)return;O.current=`new`,S(null),w(``),D({...Cn})}},[F,g.state]);let I=r(async()=>{await m.invalidateQueries({queryKey:xn})},[m]),L=u({mutationFn:async e=>p.trpcClient.oidcConnections.deleteConnection.mutate({id:e}),onSuccess:async()=>I()}),R=r(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 L.mutateAsync(e.id),g.state.mode===`edit`&&g.state.id===e.id&&(g.close(),O.current=null))},[h,L,g,f]),te=r(async()=>{let e=E.displayName,t=typeof e==`string`&&e.trim()!==``?e.trim():``;if(t===``){S(`Display name is required.`);return}let n=g.state.mode===`new`,r=n?C.trim():F?.id??``;if(n&&!wn.test(r)){S(`Instance id must be a lowercase slug (e.g. authentik, google).`);return}if(r===``){S(`That connection is no longer available.`);return}let i=En(E.clientSecret,n),a=E.icon,o=E.issuerUrl,s=E.clientId,c=E.redirectUri,l=E.scopes,u=E.usernameClaim,d=u===`email`||u===`sub`?u:`preferred_username`;b(!0),S(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 I(),g.close(),O.current=null}catch(e){S(Tn(e))}finally{b(!1)}},[C,F?.id,g,E,I,p]),ne=n(()=>[{key:`id`,header:f(`system.oidcSettingsConnections.id`,`Id`),sortValue:e=>e.id,render:e=>i(`span`,{className:`font-mono text-xs text-foreground`,children:e.id})},{key:`name`,header:f(`system.oidcSettingsConnections.name`,`Name`),sortValue:e=>e.displayName,render:e=>i(`span`,{className:`truncate font-medium text-foreground`,children:e.displayName})},{key:`issuer`,header:f(`system.oidcSettingsConnections.issuer`,`Issuer`),sortValue:e=>e.issuerUrl,render:e=>i(`span`,{className:`truncate text-xs text-foreground-muted`,children:e.issuerUrl===``?`—`:e.issuerUrl})},{key:`status`,header:f(`system.oidcSettingsConnections.status`,`Status`),notSortableReason:`Badge`,render:e=>i(W,{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:t=>e(`div`,{className:`flex justify-end gap-1`,children:[i(q,{type:`button`,size:`sm`,variant:`secondary`,onClick:e=>{e.stopPropagation(),g.openEdit(t.id)},children:f(`common.edit`,`Edit`)}),i(q,{type:`button`,size:`sm`,variant:`ghost`,"aria-label":f(`system.oidcSettingsConnections.delete`,`Delete {{displayName}}`,{displayName:t.displayName}),title:f(`common.delete`,`Delete`),onClick:e=>{e.stopPropagation(),R(t)},children:i(_,{className:`h-3.5 w-3.5 text-danger`})})]})}],[g,R,f]),z=g.state.mode===`new`,B=z||F!==null,re=z?`new`:F===null?`closed`:`edit:${F.id}:${F.configured?`cfg`:`empty`}`,ie=`/addon/${c}/<id>/callback`;return e(`div`,{className:`flex min-h-0 flex-col gap-3`,"data-testid":`oidc-settings-connections`,children:[e(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[e(`p`,{className:`text-sm text-foreground-muted`,children:[f(`system.oidcSettingsConnections.eachRowIsOneIdp`,`Each row is one IdP. Redirect URI:`),` `,i(`span`,{className:`font-mono text-xs`,children:ie})]}),e(q,{type:`button`,size:`sm`,"data-testid":`oidc-connections-add`,onClick:()=>g.openNew(),children:[i(v,{className:`h-3.5 w-3.5`}),f(`system.oidcSettingsConnections.addConnection`,`Add connection`)]})]}),k.isError?i(`p`,{className:`text-sm text-danger`,children:f(`system.oidcSettingsConnections.couldNotLoadConnections`,`Could not load connections.`)}):null,k.isPending?i(be,{className:`h-32 w-full`}):i(fe,{columns:ne,rows:ee,rowKey:e=>e.id,pageSize:25,emptyMessage:f(`system.oidcSettingsConnections.noOidcConnectionsYetAdd`,`No OIDC connections yet. Add one to register an IdP.`),onRowClick:e=>g.openEdit(e.id),defaultSort:{columnKey:`name`,dir:`asc`}}),i(st,{open:B,onClose:()=>{g.close(),S(null),O.current=null},title:z?f(`system.oidcSettingsConnections.addOidcConnection`,`Add OIDC connection`):f(`system.oidcSettingsConnections.edit`,`Edit {{value1}}`,{value1:F?.displayName??`connection`}),icon:A,width:`xl`,testId:`oidc-connection-editor`,error:x,footer:i(q,{type:`button`,size:`sm`,disabled:y||z&&C.trim()===``,onClick:()=>void te(),children:y?f(`system.oidcSettingsConnections.saving`,`Saving…`):f(`common.save`,`Save`)}),children:B?e(d,{children:[z?e(`div`,{children:[i(Oe,{htmlFor:`oidc-connection-id`,children:f(`system.oidcSettingsConnections.instanceId`,`Instance id`)}),i(ke,{id:`oidc-connection-id`,value:C,onChange:e=>w(e.target.value),placeholder:`authentik`,autoComplete:`off`}),i(`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:c})})]}):e(`p`,{className:`text-sm text-foreground-muted`,children:[f(`system.oidcSettingsConnections.instanceId2`,`Instance id:`),` `,i(`span`,{className:`font-mono`,children:F?.id})]}),N===void 0?i(`p`,{className:`text-sm text-foreground-muted`,children:f(`system.oidcSettingsConnections.loadingForm`,`Loading form…`)}):i(Ze,{schema:N,values:E,onChange:D,bare:!0},re)]}):null})]})}c();var kn=3e4,An=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],jn={titleKey:`system.authentication.sectionTitle`,subtitleKey:`system.authentication.sectionSubtitle`,emptyTitleKey:`system.authentication.sectionEmptyTitle`,emptyDescriptionKey:`system.authentication.sectionEmptyDescription`,installLabelKey:`system.authentication.sectionInstall`};function Mn(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:B,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:se,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:se,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:S,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)?{headline:`TOTP — second factor.`,icon:S,bullets:[`Time-based codes from an authenticator app (RFC 6238).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:A,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Nn(){let{t:e}=Y(),t=Fe({capName:An[0].capName},{refetchInterval:kn}),r=Fe({capName:An[1].capName},{refetchInterval:kn}),a=ve(void 0,{refetchInterval:kn}),o=n(()=>$t(a.data??[]),[a.data]),s=n(()=>{let e=[],n=[t.data??[],r.data??[]];for(let[t,r]of An.entries())for(let i of n[t]??[])e.push({addonId:i.addonId,displayName:o.get(i.addonId)??i.addonId,isActive:i.isActive,capName:r.capName,stageBadge:r.stageBadge});return e},[t.data,r.data,o]),c=[{id:`authentication`,label:e(`system.authentication.authenticationProviders`,`Authentication providers`),install:{capability:An[0].capName,label:e(jn.installLabelKey)},entries:s.map(t=>({id:t.addonId,name:t.displayName,fallbackIcon:A,...Qt(t.isActive),render:()=>i(Yt,{addonId:t.addonId,displayName:t.displayName,capName:t.capName,isActive:t.isActive,badges:t.stageBadge===null?null:i(W,{variant:`info`,className:Xt,children:t.stageBadge}),settingsContent:t.addonId.startsWith(`auth-oidc`)?i(On,{addonId:t.addonId}):void 0,panels:[{id:`about`,title:e(`system.authentication.about`,`About`),icon:Mn(t.addonId).icon,content:i(Pn,{addonId:t.addonId})}]})}))}];return i(Zt,{embedded:!0,icon:A,title:e(jn.titleKey),subtitle:e(jn.subtitleKey),groups:c,isLoading:t.isLoading||r.isLoading,emptyTitle:e(jn.emptyTitleKey),emptyDescription:e(jn.emptyDescriptionKey)})}function Pn({addonId:t}){let{t:n}=Y(),r=Mn(t),a=r.icon;return e(`div`,{className:`space-y-3 rounded-lg border border-border bg-surface p-2 sm:p-4`,children:[e(`div`,{className:`flex items-start gap-2.5`,children:[i(a,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),i(`div`,{className:`text-xs text-foreground font-medium`,children:r.headline})]}),i(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:r.bullets.map((e,t)=>i(`li`,{children:e},t))}),r.setupSteps&&r.setupSteps.length>0&&e(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[e(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[i(re,{className:`h-3 w-3`}),n(`system.authentication.setupSteps`,`Setup steps`)]}),i(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:r.setupSteps.map((e,t)=>i(`li`,{children:e},t))})]}),t===`local-auth`&&e(`div`,{className:`rounded-md border border-info/30 bg-info/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[i(N,{className:`h-3.5 w-3.5 mt-0.5 text-info shrink-0`}),i(`span`,{children:i(_t,{i18nKey:`system.authentication.totpNote`,components:{access:i(pt,{to:`/system/my-access?tab=sign-in`,className:`underline text-primary`}),users:i(pt,{to:`/system/identity?tab=users`,className:`underline text-primary`})}})})]})]})}function Fn({isPending:t,error:n,what:r,onRetry:a,children:o}){let{t:s}=Y();return t?e(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,role:`status`,"data-testid":`query-pending`,children:[i(j,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),s(`certificates.queryBody.reading`,{what:r})]}):n===null?o:i(U,{title:s(`certificates.queryBody.couldNotRead`,`Could not read {{what}}`,{what:r}),message:n.message.length>0?n.message:s(`certificates.queryBody.requestFailed`,`Request failed`),onRetry:a})}function In(){let{t}=Y(),n=K.deviceCredentials.getDeviceCaStatus.useQuery({}),r=n.data;return i(X,{id:`device-ca`,title:t(`certificates.deviceCaCard.deviceCertificateAuthority`,`Device certificate authority`),icon:A,description:t(`certificates.deviceCaCard.signsTheCertificateEachPaired`,`Signs the certificate each paired device holds. It is created the first time a device is paired.`),children:i(Fn,{isPending:n.isPending,error:n.error,what:`the device CA`,onRetry:()=>void n.refetch(),children:r!==void 0&&e(`div`,{className:`space-y-1`,"data-testid":`device-ca-status`,children:[e(G,{label:t(`certificates.deviceCaCard.state`,`State`),children:[r.state===`ready`&&i(W,{variant:`success`,children:t(`certificates.deviceCaCard.ready`,`Ready`)}),r.state===`absent`&&i(W,{variant:`default`,children:t(`certificates.deviceCaCard.notCreatedYet`,`Not created yet`)}),r.state===`unavailable`&&i(W,{variant:`danger`,children:t(`certificates.deviceCaCard.unavailable`,`Unavailable`)})]}),r.state===`ready`&&e(d,{children:[i(G,{label:t(`certificates.deviceCaCard.subject`,`Subject`),valueClassName:`font-mono`,children:r.subject}),i(G,{label:t(`certificates.deviceCaCard.fingerprintSha256`,`Fingerprint (SHA-256)`),valueClassName:`font-mono`,children:r.fingerprintSha256}),i(G,{label:t(`certificates.deviceCaCard.validUntil`,`Valid until`),children:r.validTo})]}),r.state===`unavailable`&&i(G,{label:t(`certificates.deviceCaCard.reason`,`Reason`),children:i(`span`,{className:`text-danger`,children:r.reason})})]})})})}c();function Ln(){let{t}=Y(),n=K.useUtils(),r=K.deviceCredentials.getDeviceCertificateSettings.useQuery({}),[a,s]=o(null),c=K.deviceCredentials.setDeviceCertificateSettings.useMutation({onSuccess:()=>{s(null),n.deviceCredentials.getDeviceCertificateSettings.invalidate()},onError:e=>s(`Could not save: ${e.message}`)});return i(Fn,{isPending:r.isPending,error:r.error,what:`the enrollment setting`,onRetry:()=>void r.refetch(),children:r.data!==void 0&&e(G,{label:t(`certificates.deviceSettingsRow.usersCanEnrollTheirOwn`,`Users can enroll their own devices`),actions:i(Ie,{checked:r.data.selfEnrollment===`allowed`,disabled:c.isPending,"aria-label":t(`certificates.deviceSettingsRow.usersCanEnrollTheirOwn`,`Users can enroll their own devices`),onCheckedChange:e=>c.mutate({selfEnrollment:e?`allowed`:`disabled`})}),children:[i(`span`,{className:`text-[11px] text-foreground-subtle`,children:r.data.selfEnrollment===`allowed`?t(`certificates.deviceSettingsRow.allowedAUserSignedIn`,`Allowed - a user signed in on a phone can keep it signed in. Pairing by QR works either way.`):t(`certificates.deviceSettingsRow.disabledOnlyAnAdminCan`,`Disabled - only an admin can pair a device, with a QR code.`)}),a!==null&&i(`span`,{className:`block text-[11px] text-danger`,children:a})]})})}c();function Rn(e){let[t,n]=o(()=>Date.now());return a(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}c();var zn=80,Bn=208;function Vn({open:t,users:n,onClose:r,onPaired:a}){let{t:s}=Y(),c=K.deviceCredentials.startEnrollment.useMutation({onSuccess:a}),[l,u]=o(``),[d,f]=o(``),p=l===``?n[0]?.id??``:l,m=c.data,h=()=>{c.reset(),f(``),r()};return i(st,{open:t,onClose:h,title:s(`certificates.pairDeviceDialog.pairADevice`,`Pair a device`),icon:S,width:`md`,testId:`pair-device-dialog`,error:c.isError?c.error.message:null,footer:m===void 0?e(q,{type:`button`,onClick:()=>{let e=d.trim();p===``||e===``||c.mutate({userId:p,deviceName:e})},disabled:c.isPending||p===``||d.trim()===``,children:[c.isPending&&i(j,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),s(`certificates.pairDeviceDialog.createPairingCode`,`Create pairing code`)]}):i(q,{type:`button`,variant:`outline`,onClick:h,children:s(`certificates.pairDeviceDialog.done`,`Done`)}),children:m===void 0?e(`div`,{className:`space-y-3`,children:[i(`p`,{className:`text-[11px] text-foreground-subtle`,children:s(`certificates.pairDeviceDialog.createsAOneTimeCode`,`Creates a one-time code for a phone you hold. Scan it with the CamStack app on that phone; the phone then stays signed in as the chosen user until you revoke it.`)}),i(ge,{label:s(`certificates.pairDeviceDialog.user`,`User`),required:!0,children:i(we,{value:p,onChange:e=>u(e.target.value),options:n.map(e=>({value:e.id,label:e.username}))})}),i(ge,{label:s(`certificates.pairDeviceDialog.deviceName`,`Device name`),required:!0,description:s(`certificates.pairDeviceDialog.howThisPhoneIsListed`,`How this phone is listed, e.g. Anna's iPhone.`),children:i(ke,{value:d,maxLength:zn,onChange:e=>f(e.target.value),placeholder:s(`certificates.pairDeviceDialog.annaSIphone`,`Anna's iPhone`),autoFocus:!0})})]}):i(Hn,{enrollUrl:m.enrollUrl,expiresAt:m.expiresAt,hubKnown:m.hubOrigin!==null,onRestart:()=>c.reset()})})}function Hn({enrollUrl:t,expiresAt:n,hubKnown:r,onRestart:a}){let{t:o}=Y(),s=zt(n,Rn(1e3));return i(`div`,{className:`space-y-3`,"data-testid":`pair-issued`,children:e(`div`,{className:`flex flex-col items-center gap-3 sm:flex-row sm:items-start`,children:[i(`div`,{className:s.expired?`opacity-30`:void 0,children:i(Be,{value:t,size:Bn,alt:o(`certificates.pairDeviceDialog.enrollmentQrCode`,`Enrollment QR code`)})}),e(`div`,{className:`min-w-0 flex-1 space-y-2`,children:[i(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`certificates.pairDeviceDialog.openTheCamstackAppOn`,`Open the CamStack app on the phone and scan this code. It works once.`)}),i(`div`,{className:`text-sm font-semibold tabular-nums text-foreground`,role:`timer`,"data-testid":`pair-countdown`,children:s.expired?o(`certificates.pairDeviceDialog.expiredCreateANewCode`,`Expired - create a new code`):o(`certificates.pairDeviceDialog.expiresIn`,`Expires in {{label}}`,{label:s.label})}),e(`div`,{className:`flex items-center gap-1 rounded-md border border-border bg-background px-2 py-1`,children:[i(`code`,{className:`min-w-0 flex-1 select-all break-all font-mono text-[11px] text-foreground`,children:t}),i(je,{value:t,srLabel:`Enrollment link`})]}),!r&&e(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-2.5 py-1.5 text-[11px] text-foreground`,children:[i(F,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),i(`span`,{children:o(`certificates.pairDeviceDialog.theHubCouldNotName`,`The hub could not name an address for this link, so the app must already know it.`)})]}),s.expired&&i(q,{type:`button`,variant:`outline`,size:`sm`,onClick:a,children:o(`certificates.pairDeviceDialog.newCode`,`New code`)})]})]})})}c();var Un={key:`access.nouns.device`};function Wn({pairOpen:t,onPairClose:r}){let{t:a}=Y(),s=M(),c=C(),l=K.useUtils(),u=K.deviceCredentials.listDeviceCredentials.useQuery({includeRevoked:!0}),d=rt(),[p,m]=o(null),[h,v]=o(null),y=()=>void l.deviceCredentials.listDeviceCredentials.invalidate(),b=e=>t=>{v(null),m(`${e} failed: ${t.message}`)},x=()=>{v(null),y()},w=K.deviceCredentials.revokeDeviceCredential.useMutation({onSuccess:x,onError:b(`Revoke`)}),T=K.deviceCredentials.deleteDeviceCredential.useMutation({onSuccess:e=>{e.result!==`deleted`&&m(e.result===`live`?`Only a revoked device can be deleted: revoke it first.`:`That device no longer exists.`),x()},onError:b(`Delete`)}),E=K.deviceCredentials.renameDeviceCredential.useMutation({onSuccess:x,onError:b(`Rename`)}),D=Ct(Un,e=>w.mutateAsync({id:e}),y),O=D.busy||h!==null,k=n(()=>(u.data??[]).map(Rt),[u.data]),A=async e=>{await s({title:a(`certificates.devicesCard.revoke`,`Revoke "{{name}}"?`,{name:e.name}),message:a(`certificates.devicesCard.sDeviceStopsSigningIn`,`{{ownerName}}'s device stops signing in at once and its open sessions end. To use it again it has to be paired anew. This cannot be undone.`,{ownerName:e.ownerName}),confirmLabel:a(`certificates.devicesCard.revoke2`,`Revoke`),variant:`danger`})&&(m(null),v(e.id),w.mutate({id:e.id}))},j=async e=>{await s({title:a(`certificates.devicesCard.delete`,`Delete "{{name}}"?`,{name:e.name}),message:a(`certificates.devicesCard.isRemovedFromTheList`,`{{name}} is removed from the list. The audit trail keeps the revocation.`,{name:e.name}),confirmLabel:a(`common.delete`,`Delete`),variant:`danger`})&&(m(null),v(e.id),T.mutate({id:e.id}))},ee=async e=>{let t=(await c({title:a(`certificates.devicesCard.renameDevice`,`Rename device`),label:a(`certificates.devicesCard.deviceName`,`Device name`),defaultValue:e.name,confirmLabel:a(`certificates.devicesCard.rename`,`Rename`)}))?.trim()??``;t===``||t===e.name||(m(null),v(e.id),E.mutate({id:e.id,deviceName:t}))},N={label:a(`certificates.devicesCard.revoke2`,`Revoke`),icon:f,isAvailable:Dt,onRun:e=>void A(e),busyId:w.isPending?h:null,disabled:O},P=[{label:a(`certificates.devicesCard.rename`,`Rename`),icon:g,tone:`neutral`,isAvailable:()=>!0,onRun:e=>void ee(e),busyId:E.isPending?h:null,disabled:O},{label:a(`common.delete`,`Delete`),icon:_,isAvailable:Pt,onRun:e=>void j(e),busyId:T.isPending?h:null,disabled:O}];return e(X,{id:`devices`,title:a(`certificates.devicesCard.devices`,`Devices`),icon:S,description:a(`certificates.devicesCard.phonesThatStaySignedIn`,`Phones that stay signed in with a certificate instead of a login. Revoking one signs it out at once; it has to be paired again.`),notice:Ft(p,D.outcome),onDismissNotice:()=>{m(null),D.dismiss()},children:[i(Ln,{}),i(Et,{rows:k,label:a(`certificates.devicesCard.label`),isLoading:u.isPending,loadError:u.error===null?null:u.error.message||`Request failed`,emptyText:`No devices paired yet.`,expiresNone:`—`,action:N,extraActions:P,bulk:{revoke:D,noun:Un,isSelectable:Dt}}),i(Vn,{open:t,users:d.data??[],onClose:r,onPaired:y})]})}var Gn=/-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----/,Kn=/-----BEGIN ((?:RSA |EC |ENCRYPTED )?PRIVATE KEY)-----[\s\S]+?-----END \1-----/,qn={certificate:`.pem,.crt,.cer`,privateKey:`.pem,.key`,ca:`.pem,.crt,.cer`};function Jn(e,t){if(t.trim()===``)return null;if(e===`privateKey`){let e=Kn.exec(t);return e===null?Gn.test(t)?J.t(`helpers.pemFile.isCert`):J.t(`helpers.pemFile.notKey`):e[1]===`ENCRYPTED PRIVATE KEY`?J.t(`helpers.pemFile.encrypted`):null}return Gn.test(t)?e===`certificate`&&Kn.test(t)?J.t(`helpers.pemFile.certHasKey`):null:Kn.test(t)?J.t(`helpers.pemFile.isKey`):J.t(`helpers.pemFile.notCert`)}function Yn(e){return e.text()}c();function Xn({kind:n,label:r,value:a,onChange:s,rows:c=6}){let{t:l}=Y(),u=t(null),[d,f]=o(null),[p,m]=o(null),h=p??Jn(n,a),g=`pem-${n}`,_=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t!==void 0){f(t.name);try{let e=await Yn(t);m(null),s(e)}catch(e){m(`Could not read ${t.name}: ${e instanceof Error?e.message:String(e)}`)}}};return e(`div`,{className:`space-y-1`,children:[e(`div`,{className:`flex items-center justify-between gap-2`,children:[i(`label`,{htmlFor:g,className:`text-[11px] text-foreground-subtle`,children:r}),e(`div`,{className:`flex min-w-0 items-center gap-2`,children:[d!==null&&i(`span`,{className:`truncate font-mono text-[10px] text-foreground-subtle`,"data-testid":`${g}-file-name`,children:d}),i(`input`,{ref:u,type:`file`,accept:qn[n],onChange:e=>void _(e),className:`hidden`,"data-testid":`${g}-file`}),e(q,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>u.current?.click(),children:[i(ce,{className:`mr-1 h-3 w-3`}),l(`system.pemField.chooseFile`,`Choose file`)]})]})]}),i(`textarea`,{id:g,value:a,onChange:e=>{f(null),m(null),s(e.target.value)},rows:c,"aria-invalid":h!==null,className:`w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`}),h!==null&&i(`p`,{className:`text-[11px] text-danger`,role:`alert`,children:h})]})}c();var Zn=30;function Qn(e){let t=Date.parse(e);return!Number.isNaN(t)&&Date.now()-t<Zn*864e5}function $n(e){if(e===null||e===``)return`—`;let t=e.replace(/:/g,``);return t.length<=16?e:`${t.slice(0,8)}…${t.slice(-8)}`}function er(){let{t}=Y(),n=l(),r=$e(void 0,{refetchInterval:15e3}),a=He({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),s=Ge({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),c=Qe({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),u=qe({onSuccess:()=>{m(!1),g(``),v(``),b(``),n.invalidateQueries({queryKey:[[`localNetwork`]]})}}),d=r.data,[f,m]=o(!1),[h,g]=o(``),[_,v]=o(``),[y,b]=o(``),x=()=>{if(!d?.caCertPem)return;let e=new Blob([d.caCertPem],{type:`application/x-pem-file`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`camstack-ca.crt`,n.click(),URL.revokeObjectURL(t)},S=d?.mode===`uploaded`?`Uploaded`:d?.mode===`generated`?`Generated local CA`:`TLS disabled`;return i(Te,{headingId:`local-access-certificate`,title:t(`system.localAccess.certificate`,`Certificate`),icon:w,children:e(`div`,{className:`${p} space-y-3`,children:[r.isError&&i(`p`,{className:`text-xs text-danger`,children:t(`system.localAccess.couldNotReadTlsStatus`,`Could not read TLS status.`)}),d?.reissueError&&i(U,{variant:`warning`,title:t(`system.localAccess.certificateReissue`,`Certificate reissue`),message:d.reissueError}),d?.restartRequired&&i(U,{variant:`warning`,title:t(`system.localAccess.restartRequired`,`Restart required`),message:t(`system.localAccess.theHttpsListenerStillServes`,`The HTTPS listener still serves the previous certificate. Restart the hub to apply it.`)}),d?.caMissing===!0&&i(U,{variant:`warning`,title:t(`system.localAccess.caMissingTitle`,`CA missing - devices cannot trust this hub`),message:t(`system.localAccess.caMissingBody`,"The uploaded certificate was not issued by a public CA and no CA was stored with it, so Download CA has nothing to hand out. Upload the certificate again together with its CA (for mkcert, the rootCA.pem in the folder `mkcert -CAROOT` prints).")}),d?.caReplacedAt!=null&&Qn(d.caReplacedAt)&&i(U,{variant:`warning`,title:t(`system.localAccess.caReplacedTitle`,`The local CA was replaced - re-install it on your devices`),message:t(`system.localAccess.caReplacedBody`,`The previous local CA had no name constraints: if its key ever leaked it could vouch for any website. The hub now uses a CA limited to private addresses and local names. Download it again and trust it on every phone and computer that used the old one (replaced {{when}}).`,{when:new Date(d.caReplacedAt).toLocaleString()})}),e(`dl`,{className:`grid grid-cols-1 gap-2 text-xs sm:grid-cols-2`,children:[e(`div`,{children:[i(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.mode`,`Mode`)}),i(`dd`,{className:`font-medium`,children:S})]}),e(`div`,{children:[i(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.validTo`,`Valid to`)}),i(`dd`,{className:`font-mono`,children:d?.validTo?new Date(d.validTo).toLocaleString():`—`})]}),e(`div`,{children:[i(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.leafSha256`,`Leaf SHA-256`)}),i(`dd`,{className:`font-mono`,title:d?.leafFingerprintSha256??void 0,children:$n(d?.leafFingerprintSha256??null)})]}),d?.storedUpload!=null&&e(`div`,{children:[i(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.storedUpload`,`Stored upload`)}),i(`dd`,{className:`font-medium`,children:t(`system.localAccess.storedUploadValue`,`valid to {{validTo}}, {{ca}}`,{validTo:new Date(d.storedUpload.validTo).toLocaleDateString(),ca:d.storedUpload.hasCa?t(`system.localAccess.storedUploadWithCa`,`with its CA`):t(`system.localAccess.storedUploadNoCa`,`no CA`)})})]}),e(`div`,{children:[i(`dt`,{className:`text-foreground-subtle`,children:t(`system.localAccess.caSha256`,`CA SHA-256`)}),i(`dd`,{className:`font-mono`,title:d?.caFingerprintSha256??void 0,children:d?.mode===`uploaded`&&d.caFingerprintSha256===null?i(`span`,{className:`font-sans text-foreground-subtle`,children:t(`system.localAccess.issuerNotIncludedInThe`,`Issuer not included in the upload (not the local CA)`)}):$n(d?.caFingerprintSha256??null)})]})]}),d&&d.sans.length>0&&i(`div`,{className:`flex flex-wrap gap-1`,children:d.sans.map(e=>i(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 font-mono text-[10px] text-foreground-subtle`,children:e},e))}),e(`div`,{className:`flex flex-wrap gap-2`,children:[i(V,{label:t(`system.localAccess.regenerate`,`Regenerate`),title:t(`system.localAccess.issueANewLeaf`,`Issue a new leaf?`),description:t(`system.localAccess.issuesANewLeafUnder`,`Issues a new leaf under the current local CA. Clients that trust the CA keep working. The HTTPS listener reloads.`),confirmLabel:t(`system.localAccess.regenerate`,`Regenerate`),disabled:d?.mode===`uploaded`||a.isPending,action:()=>a.mutateAsync({})}),i(q,{size:`sm`,variant:`outline`,onClick:()=>m(e=>!e),children:t(`system.localAccess.upload`,`Upload`)}),d?.caCertPem&&i(q,{size:`sm`,variant:`outline`,onClick:x,children:t(`system.localAccess.downloadCa`,`Download CA`)}),d?.mode===`uploaded`&&i(V,{label:t(`system.localAccess.revertToGenerated`,`Revert to generated`),title:t(`system.localAccess.revertTitle`,`Switch back to the generated certificate?`),description:t(`system.localAccess.keepsTheUploadedPair`,`Returns to the generated local CA. The uploaded certificate and its CA stay stored here; you can select them again.`),confirmLabel:t(`system.localAccess.revert`,`Revert`),disabled:s.isPending,action:()=>s.mutateAsync({})}),d?.mode===`generated`&&d.storedUpload!=null&&i(V,{label:t(`system.localAccess.useUploaded`,`Use uploaded certificate`),title:t(`system.localAccess.useUploadedTitle`,`Serve the stored upload again?`),description:t(`system.localAccess.useUploadedDescription`,`The stored uploaded certificate replaces the generated one on the HTTPS listener. The generated certificate stays stored.`),confirmLabel:t(`system.localAccess.useUploaded`,`Use uploaded certificate`),disabled:c.isPending,action:()=>c.mutateAsync(void 0)})]}),f&&e(`div`,{className:`space-y-2 border-t border-border pt-3`,children:[i(Xn,{kind:`certificate`,label:t(`system.localAccess.certificateOrFullChainPem`,`Certificate or full chain (PEM)`),value:h,onChange:g}),i(Xn,{kind:`privateKey`,label:t(`system.localAccess.privateKeyPem`,`Private key (PEM)`),value:_,onChange:v}),i(Xn,{kind:`ca`,label:t(`system.localAccess.caPemRequired`,`CA (PEM) - required unless the certificate comes from a public CA`),value:y,onChange:b,rows:4}),i(q,{size:`sm`,disabled:!h.trim()||!_.trim()||Jn(`certificate`,h)!==null||Jn(`privateKey`,_)!==null||Jn(`ca`,y)!==null||u.isPending,onClick:()=>u.mutate({certPem:h,keyPem:_,...y.trim()?{caPem:y}:{}}),children:t(`system.localAccess.saveCertificate`,`Save certificate`)}),u.isError&&i(`p`,{className:`text-xs text-danger`,children:u.error instanceof Error?u.error.message:t(`system.localAccess.uploadFailed`,`Upload failed`)})]})]})})}var tr={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`};function nr(e){let t=e.find(e=>e.isHub);return t?.https.kind===`served`?t.https.status.caFingerprintSha256:null}function rr({https:t,mesh:n,now:r}){let{t:a}=Y(),o=$e().data?.caCertPem??``,s=()=>{if(o===``)return;let e=URL.createObjectURL(new Blob([o],{type:`application/x-pem-file`})),t=document.createElement(`a`);t.href=e,t.download=`camstack-ca.crt`,t.click(),URL.revokeObjectURL(e)},c=n?.ca,l=c?.state===`ready`?Date.parse(c.validTo):null,u=n?.listener;return e(`div`,{className:`space-y-1`,"data-testid":`ca-strip`,children:[i(G,{label:a(`certificates.caStrip.localHttpsCaSha256`,`Local HTTPS CA (SHA-256)`),valueClassName:`font-mono`,children:e(`span`,{className:`flex flex-wrap items-center gap-2`,children:[nr(t)??`—`,o!==``&&e(q,{type:`button`,variant:`ghost`,size:`sm`,onClick:s,children:[i(y,{className:`h-3 w-3`,"aria-hidden":!0}),a(`certificates.caStrip.downloadCa`,`Download CA`)]})]})}),i(G,{label:a(`certificates.caStrip.clusterCaSha256`,`Cluster CA (SHA-256)`),valueClassName:`font-mono`,children:c===void 0?`—`:c.state===`ready`?c.fingerprintSha256:i(`span`,{className:`text-danger`,children:a(`certificates.caStrip.unavailable`,{reason:c.reason})})}),c?.state===`ready`&&e(G,{label:a(`certificates.caStrip.clusterCaValidUntil`,`Cluster CA valid until`),children:[c.validTo,l!==null&&!Number.isNaN(l)&&e(`span`,{className:`ml-2 text-[10px] ${tr[Ut(l,r)]}`,children:[`(`,kt(l,r),`)`]})]}),u!==void 0&&e(G,{label:a(`certificates.caStrip.nodeListener`,`Node listener`),children:[u.state===`open`&&i(W,{variant:`success`,children:a(`certificates.caStrip.open`,`Open`)}),u.state===`not-started`&&i(W,{variant:`default`,children:a(`certificates.caStrip.notStarted`,`Not started`)}),u.state===`closed`&&e(`span`,{className:`text-danger`,children:[a(`certificates.caStrip.closedSince`,{when:At(u.since)}),` `,u.reason]})]}),n!==void 0&&!n.registryAvailable&&e(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-2.5 py-1.5 text-[11px] text-foreground`,children:[i(F,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),i(`span`,{children:a(`certificates.caStrip.theCertificateRegistryIsNot`,`The certificate registry is not up, so the node list below is incomplete.`)})]})]})}function ir(e,t){let n=new Set;for(let t of e)n.add(t.nodeId);for(let e of t?.nodes??[])n.add(e.nodeId);return[...n].map(n=>{let r=e.find(e=>e.nodeId===n)??null,i=t?.nodes.find(e=>e.nodeId===n)??null;return{nodeId:n,isHub:r?.isHub??n===`hub`,online:r?.online??i?.online??!1,https:r,mesh:i}}).toSorted((e,t)=>Number(t.isHub)-Number(e.isHub)||e.nodeId.localeCompare(t.nodeId))}function ar(e){return e.isHub?J.t(`helpers.nodesModel.hubReissued`):e.mesh===null?J.t(`helpers.nodesModel.noCertRecorded`):e.online?null:J.t(`helpers.certificateModel.nodeOffline`)}function or(e){return e.isHub||e.mesh===null?ar(e):null}var sr={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`},cr={enroll:`Issued at enrollment`,renewal:`Issued by a renewal`,boot:`Issued at boot`,pairing:`Issued at pairing`,observed:`Observed on its connection`},lr={uploaded:`Uploaded`,generated:`Generated`,disabled:`Disabled`};function ur(e){let t=e.https?.https;return t?.kind===`served`?Vt(t.status.validTo):null}function dr({ms:t,now:n}){return t===null?i(`span`,{className:`text-foreground-subtle`,children:`—`}):e(`div`,{children:[i(`div`,{children:At(t)}),i(`div`,{className:`text-[10px] ${sr[Ut(t,n)]}`,children:kt(t,n)})]})}function fr({row:t}){let{t:n}=Y(),r=t.https?.https;return r===void 0?i(`span`,{className:`text-foreground-subtle`,children:`—`}):r.kind===`served`?e(`div`,{title:r.status.leafFingerprintSha256??``,children:[i(W,{variant:`success`,className:`text-[10px]`,children:n(`certificates.nodesColumns.served`,`Served`)}),i(`span`,{className:`ml-1.5 text-[10px] text-foreground-subtle`,children:lr[r.status.mode]}),i(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:Bt(r.status.leafFingerprintSha256)}),r.status.sans.length>0&&i(`div`,{className:`mt-0.5 max-w-[14rem] truncate font-mono text-[10px] text-foreground-subtle`,title:r.status.sans.join(`, `),children:r.status.sans.join(`, `)})]}):e(`div`,{className:`max-w-[16rem]`,children:[i(W,{variant:r.kind===`unreadable`?`danger`:`warning`,className:`text-[10px]`,children:r.kind===`unreadable`?n(`certificates.nodesColumns.unreadable`,`Unreadable`):n(`certificates.nodesColumns.notServed`,`Not served`)}),i(`div`,{className:`mt-1 whitespace-normal text-[10px] text-foreground-subtle`,children:r.reason})]})}function pr({row:t}){let{t:n}=Y(),r=t.mesh?.current??null;if(r===null)return i(`span`,{className:`text-foreground-subtle`,children:n(`certificates.nodesColumns.noneRecorded`,`None recorded`)});let a=t.mesh?.history.length??0;return e(`div`,{children:[i(`div`,{className:`font-mono text-[11px]`,title:r.serial,children:Lt(r.serial)}),i(`div`,{className:`font-mono text-[10px] text-foreground-subtle`,title:r.fingerprintSha256,children:Bt(r.fingerprintSha256)}),e(`div`,{className:`text-[10px] text-foreground-subtle`,children:[cr[r.issuedVia],a>0?` · ${n(`certificates.nodesColumns.earlier`,{count:a})}`:``]})]})}function mr({row:e}){let{t}=Y(),n=e.mesh?.presentingCurrent??null;return n===null?i(`span`,{className:`text-foreground-subtle`,children:e.online?`—`:t(`certificates.nodesColumns.offline`,`Offline`)}):n?i(W,{variant:`success`,className:`text-[10px]`,children:t(`common.yes`,`Yes`)}):i(W,{variant:`warning`,className:`text-[10px]`,children:t(`certificates.nodesColumns.noPresentsAnother`,`No - presents another`)})}function hr(t){let n=t.icon;return e(q,{type:`button`,variant:`ghost`,size:`sm`,className:t.danger?`text-danger hover:bg-danger/10`:void 0,disabled:t.reason!==null||t.busy,title:t.reason??void 0,"aria-label":t.ariaLabel,onClick:t.onClick,children:[t.spinning?i(j,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):i(n,{className:`h-3 w-3`,"aria-hidden":!0}),t.label]})}function gr({reasons:t}){let{t:n}=Y();return e(_e,{className:`inline-block`,children:[i(Ce,{children:i(`span`,{className:`cursor-help text-[11px] text-foreground-subtle`,"data-testid":`hub-managed-note`,children:n(`certificates.nodesColumns.managedByTheHub`,`Managed by the hub`)})}),i(ye,{children:i(`ul`,{className:`max-w-xs space-y-1 whitespace-normal text-left text-[11px]`,children:t.map(e=>i(`li`,{children:e},e))})})]})}function _r({row:t,o:n}){let{t:r}=Y(),a=t.https===null?`No HTTPS inventory for this node.`:jt(t.https).reason,o=ar(t),s=or(t),c=e=>n.running?.nodeId===t.nodeId&&n.running.action===e,l=e=>!t.isHub||e===null,u=[a,o,s].filter((e,t,n)=>e!==null&&n.indexOf(e)===t);return e(`div`,{className:`flex w-44 flex-col items-end gap-1`,children:[e(`div`,{className:`flex flex-col items-end gap-0.5`,children:[l(a)&&i(hr,{label:r(`certificates.nodesColumns.renewHttps`,`Renew HTTPS`),ariaLabel:r(`certificates.nodesColumns.renewTheCertificateOn`,`Renew the certificate on {{nodeId}}`,{nodeId:t.nodeId}),icon:m,reason:a,busy:n.busy,spinning:c(`renew-https`),danger:!1,onClick:()=>n.onRenewHttps(t)}),l(o)&&i(hr,{label:c(`renew-identity`)?r(`certificates.nodesColumns.renewing`,`Renewing…`):r(`certificates.nodesColumns.renewIdentity`,`Renew identity`),ariaLabel:r(`certificates.nodesColumns.renewTheClusterCertificateOf`,`Renew the cluster certificate of {{nodeId}}`,{nodeId:t.nodeId}),icon:m,reason:o,busy:n.busy,spinning:c(`renew-identity`),danger:!1,onClick:()=>n.onRenewIdentity(t)}),l(s)&&i(hr,{label:r(`certificates.nodesColumns.revokeIdentity`,`Revoke identity`),ariaLabel:r(`certificates.nodesColumns.revokeTheClusterCertificateOf`,`Revoke the cluster certificate of {{nodeId}}`,{nodeId:t.nodeId}),icon:f,reason:s,busy:n.busy,spinning:c(`revoke-identity`),danger:!0,onClick:()=>n.onRevokeIdentity(t)})]}),t.isHub&&u.length>0&&i(gr,{reasons:u}),!t.isHub&&a!==null&&t.https!==null&&i(`div`,{className:`w-full whitespace-normal text-right text-[10px] text-foreground-subtle`,"data-testid":`renew-reason-${t.nodeId}`,children:a}),!t.isHub&&o!==null&&i(`div`,{className:`w-full whitespace-normal text-right text-[10px] text-foreground-subtle`,"data-testid":`mesh-reason-${t.nodeId}`,children:o})]})}function vr(t){return[{key:`node`,header:J.t(`certificates.nodesColumns.node`,`Node`),sortValue:e=>e.isHub?``:e.nodeId.toLowerCase(),render:t=>e(`div`,{className:`flex items-center gap-1.5`,children:[i(`span`,{className:`font-medium text-foreground`,children:t.nodeId}),t.nodeId===`hub`&&i(W,{variant:`info`,className:`text-[10px]`,children:J.t(`common.hubWord`)}),!t.online&&i(W,{variant:`default`,className:`text-[10px]`,children:J.t(`common.offline`)})]})},{key:`https-state`,header:`HTTPS`,notSortableReason:`A state with a reason has no single order.`,render:e=>i(fr,{row:e})},{key:`https-expires`,header:J.t(`certificates.nodesColumns.httpsExpires`,`HTTPS expires`),sortValue:e=>ur(e),render:e=>i(dr,{ms:ur(e),now:t.now})},{key:`identity`,header:J.t(`certificates.nodesColumns.identity`,`Identity`),sortValue:e=>e.mesh?.current?.serial??null,render:e=>i(pr,{row:e})},{key:`identity-expires`,header:J.t(`certificates.nodesColumns.identityExpires`,`Identity expires`),sortValue:e=>e.mesh?.current?.notAfter??null,render:e=>i(dr,{ms:e.mesh?.current?.notAfter??null,now:t.now})},{key:`presenting`,header:J.t(`certificates.nodesColumns.inUse`,`In use`),notSortableReason:`Offline nodes have no answer to order by.`,render:e=>i(mr,{row:e})},{key:`actions`,header:J.t(`certificates.nodesColumns.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order.`,render:e=>i(_r,{row:e,o:t})}]}c();function yr(){let{t}=Y(),r=M(),a=K.useUtils(),s=Rn(6e4),c=K.certificates.listHttpsCertificates.useQuery(),l=K.certificates.getMeshCertificates.useQuery(),[u,d]=o(null),[f,p]=o(null),[m,h]=o(null),g=()=>{h(null),a.certificates.listHttpsCertificates.invalidate(),a.certificates.getMeshCertificates.invalidate()},_=e=>(t,n)=>{h(null),d(`${n.nodeId}: ${e} - ${t.message}`)},v=K.certificates.renewHttpsOnNode.useMutation({onSuccess:(e,n)=>{p({tone:`success`,message:e.restartRequired?t(`certificates.nodesCard.newCertificateIssuedRestartThe`,`{{nodeId}}: new certificate issued. Restart the node to serve it.`,{nodeId:n.nodeId}):t(`certificates.nodesCard.newCertificateIssuedAndServed`,`{{nodeId}}: new certificate issued and served.`,{nodeId:n.nodeId})}),g()},onError:_(`renewal failed`)}),y=K.certificates.renewMeshOnNode.useMutation({onSuccess:e=>{p(It(e)),g()},onError:_(`renewal could not start`)}),b=K.certificates.revokeMeshOnNode.useMutation({onSuccess:e=>{p({tone:`success`,message:`${e.nodeId}: ${e.next}`}),g()},onError:_(`revoke failed`)}),S=v.isPending||y.isPending||b.isPending,C=(e,t)=>{d(null),p(null),h({nodeId:e,action:t})},w=async e=>{await r({title:t(`certificates.nodesCard.renewHttpsOn`,`Renew HTTPS on "{{nodeId}}"?`,{nodeId:e.nodeId}),message:e.isHub?t(`certificates.nodesCard.aNewCertificateIsIssued`,`A new certificate is issued from the local CA. Clients that trust the CA keep working.`):t(`certificates.nodesCard.theNodeMakesANew`,`The node makes a new key, the hub signs it and the node switches over without a restart. It keeps serving what it had if anything fails.`),confirmLabel:t(`certificates.nodesCard.renew`,`Renew`)})&&(C(e.nodeId,`renew-https`),v.mutate({nodeId:e.nodeId}))},T=e=>{C(e.nodeId,`renew-identity`),y.mutate({nodeId:e.nodeId})},E=async e=>{await r({title:t(`certificates.nodesCard.revokeTheIdentityOf`,`Revoke the identity of "{{nodeId}}"?`,{nodeId:e.nodeId}),message:t(`certificates.nodesCard.isDisconnectedAtOnceAnd`,`{{nodeId}} is disconnected at once and can no longer connect. To bring it back it must be paired again from System → Cluster → Agents. It stays in the node list until you forget it on the Cluster page. This cannot be undone.`,{nodeId:e.nodeId}),confirmLabel:t(`certificates.nodesCard.revokeAndDisconnect`,`Revoke and disconnect`),variant:`danger`})&&(C(e.nodeId,`revoke-identity`),b.mutate({nodeId:e.nodeId}))},D=vr({now:s,busy:S,running:m,onRenewHttps:e=>void w(e),onRenewIdentity:T,onRevokeIdentity:e=>void E(e)}),O=n(()=>ir(c.data??[],l.data),[c.data,l.data]),k=l.data?.registryAvailable??!0;return i(X,{id:`nodes`,title:t(`certificates.nodesCard.nodes`,`Nodes`),icon:x,description:t(`certificates.nodesCard.eachNodeHoldsTwoCertificates`,`Each node holds two certificates: one it serves over HTTPS, one that proves its identity to the hub. Renewing replaces a certificate without a gap; revoking an identity cuts the node off until it re-joins.`),notice:Ft(u,f),onDismissNotice:()=>{d(null),p(null)},children:i(Fn,{isPending:c.isPending||l.isPending,error:c.error??l.error,what:`node certificates`,onRetry:()=>{c.refetch(),l.refetch()},children:e(`div`,{className:`space-y-3`,children:[i(rr,{https:c.data??[],mesh:l.data,now:s}),i(fe,{columns:D,rows:O,rowKey:e=>e.nodeId,minWidthPx:960,maxBodyHeight:Xe,defaultSort:{columnKey:`node`,dir:`asc`},emptyMessage:k?t(`certificates.nodesCard.noNodesReported`,`No nodes reported.`):t(`certificates.nodesCard.theCertificateRegistryIsNot`,`The certificate registry is not available yet, so nodes cannot be listed.`)})]})})})}function br({pairOpen:t,onPairClose:n}){return e(`div`,{className:`space-y-4`,"data-testid":`certificates-page`,children:[i(Wn,{pairOpen:t,onPairClose:n}),i(In,{}),i(er,{}),i(yr,{})]})}function xr({userId:t,username:n,onClose:r}){let{t:a}=Y(),o=M(),s=K.useUtils(),c=at({userId:t}),l=K.auth.listLoginMethods.useQuery(),u=Me({onSuccess:()=>void s.userManagement.listExternalIdentities.invalidate()}),d=new Map((l.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),f=c.data??[],p=async(e,r)=>{await o({title:a(`users.externalIdentitiesModal.removeSignInLink`,`Remove sign-in link`),message:a(`users.externalIdentitiesModal.willNoLongerBeAble`,`"{{username}}" will no longer be able to sign in with this {{label}} account.`,{username:n,label:r}),confirmLabel:a(`common.remove`,`Remove`),variant:`danger`})&&u.mutate({userId:t,provider:e.provider,subject:e.subject})};return i(ot,{open:!0,onOpenChange:e=>!e&&r(),children:e(it,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`external-identities-modal`,children:[i(nt,{children:e(Ne,{className:`flex items-center gap-2`,children:[i(E,{className:`h-4 w-4 text-primary`}),e(`span`,{children:[a(`users.externalIdentitiesModal.linkedSignInAccounts`,`Linked sign-in accounts`),e(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[a(`users.externalIdentitiesModal.user`,`User:`),` `,i(`span`,{className:`font-mono`,children:n})]})]})]})}),i(We,{className:`space-y-3`,children:c.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(j,{className:`h-3.5 w-3.5 animate-spin`}),a(`common.loading`,`Loading…`)]}):f.length===0?i(`p`,{className:`text-xs text-foreground-subtle`,children:a(`users.externalIdentitiesModal.noLinkedAccountsOnlyThe`,`No linked accounts. Only the user can link one, from their own profile page.`)}):i(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:f.map(t=>{let n=d.get(t.provider),r=n??t.provider;return e(`li`,{className:`flex items-center gap-3 px-3 py-2 text-xs`,children:[e(`div`,{className:`flex-1 min-w-0`,children:[e(`div`,{className:`font-medium text-foreground truncate`,children:[r,n===void 0&&i(`span`,{className:`ml-2 rounded bg-foreground-subtle/15 px-1.5 py-0.5 text-[10px] font-normal text-foreground-subtle`,children:a(`users.externalIdentitiesModal.providerUnavailable`,`provider unavailable`)})]}),e(`div`,{className:`text-[11px] text-foreground-subtle truncate`,children:[t.label??t.subject,` ·`,` `,new Date(t.linkedAt).toLocaleDateString()]})]}),e(`button`,{onClick:()=>void p(t,r),disabled:u.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[i(de,{className:`h-3 w-3`}),a(`common.remove`,`Remove`)]})]},`${t.provider}|${t.subject}`)})})}),i(me,{children:i(q,{onClick:r,variant:`secondary`,children:a(`common.close`,`Close`)})})]})})}function Sr({userId:t,username:n,onClose:r}){let{t:a}=Y(),o=l(),s=M(),c=et({userId:t}),u=c.data,f=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),p=ze({onSuccess:()=>{f(),r()}}),m=c.isLoading?`loading`:u?.enabled?`enrolled`:`not_enrolled`;return i(ot,{open:!0,onOpenChange:e=>!e&&r(),children:e(it,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(nt,{children:e(Ne,{className:`flex items-center gap-2`,children:[i(S,{className:`h-4 w-4 text-primary`}),e(`span`,{children:[a(`users.totpModal.twoFactorAuthentication`,`Two-factor authentication`),e(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[a(`users.totpModal.user`,`User:`),` `,i(`span`,{className:`font-mono`,children:n})]})]})]})}),e(We,{className:`space-y-4`,children:[m===`loading`&&e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(j,{className:`h-3.5 w-3.5 animate-spin`}),a(`users.totpModal.checkingStatus`,`Checking status…`)]}),m===`not_enrolled`&&e(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[i(N,{className:`h-4 w-4 mt-0.5 shrink-0`}),e(`div`,{children:[i(`div`,{className:`font-medium text-foreground`,children:a(`users.totpModal.2faNotEnrolled`,`2FA not enrolled`)}),i(`p`,{className:`mt-0.5`,children:a(`users.totpModal.onlyTheUserThemselvesCan`,`Only the user themselves can enable 2FA, from their own profile page.`)})]})]}),m===`enrolled`&&u&&e(d,{children:[e(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[i(b,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),e(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[i(`div`,{className:`font-medium`,children:a(`users.totpModal.2faIsActive`,`2FA is active`)}),i(`div`,{className:`text-foreground-subtle`,children:a(`common.enrolledOn`,{when:u.confirmedAt?new Date(u.confirmedAt).toLocaleString():`—`})})]})]}),i(`div`,{className:`text-[11px] text-foreground-subtle`,children:a(`users.totpModal.removingHereClearsTheServer`,`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`)}),e(`div`,{className:`flex justify-end gap-2`,children:[i(q,{onClick:r,variant:`secondary`,children:a(`common.close`,`Close`)}),e(`button`,{onClick:async()=>{await s({title:a(`users.totpModal.remove2fa`,`Remove 2FA`),message:a(`users.totpModal.removeTwoFactorAuthenticationFor`,`Remove two-factor authentication for "{{username}}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,{username:n}),confirmLabel:a(`common.remove`,`Remove`),variant:`danger`})&&p.mutate({userId:t})},disabled:p.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[p.isPending?i(j,{className:`h-3 w-3 animate-spin`}):i(D,{className:`h-3 w-3`}),a(`users.totpModal.remove2fa`,`Remove 2FA`)]})]})]})]})]})})}c();function Cr({userId:t,username:n,onClose:r}){let{t:a}=Y(),{user:s,logout:c}=ht(),l=s?.id===t,u=M(),d=K.useUtils(),f=K.auth.listSessions.useQuery({userId:t}),[p,m]=o(null),h=K.auth.revokeSessions.useMutation({onSuccess:(e,t)=>{if(l&&`userId`in t){c();return}d.auth.listSessions.invalidate()},onError:e=>m(`Sign out failed: ${e.message}`)}),g=async e=>{await u({title:a(`users.userSessionsModal.signOutThisSession`,`Sign out this session`),message:a(`users.userSessionsModal.onWillHaveToSign`,`"{{username}}" on {{label}} will have to sign in again.`,{username:n,label:Wt(e.client).label}),confirmLabel:a(`users.userSessionsModal.signOut`,`Sign out`),variant:`danger`})&&(m(null),h.mutate({id:e.id}))},_=async()=>{await u({title:a(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`),message:l?a(`users.userSessionsModal.everySessionOfYourOwn`,`Every session of your own account ends, this browser included: you will be signed out here too.`):a(`users.userSessionsModal.everySessionOfEndsAt`,`Every session of "{{username}}" ends at once; each device has to sign in again.`,{username:n}),confirmLabel:a(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`),variant:`danger`})&&(m(null),h.mutate({userId:t}))},v=h.isPending&&h.variables!==void 0&&`id`in h.variables?h.variables.id:null;return i(ot,{open:!0,onOpenChange:e=>!e&&r(),children:e(it,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`user-sessions-modal`,children:[i(nt,{children:e(Ne,{className:`flex items-center gap-2`,children:[i(ue,{className:`h-4 w-4 text-primary`}),e(`span`,{children:[a(`users.userSessionsModal.activeSessions`,`Active sessions`),e(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[a(`users.userSessionsModal.user`,`User:`),` `,i(`span`,{className:`font-mono`,children:n})]})]})]})}),e(We,{className:`space-y-3`,children:[p!==null&&i(`div`,{className:`text-[11px] text-danger`,children:p}),i(Ht,{sessions:f.data??[],isLoading:f.isLoading,loadError:f.isError?f.error?.message??`Request failed`:null,emptyText:`No active sessions.`,onRevoke:e=>void g(e),revokingId:v})]}),e(me,{className:`justify-between`,children:[e(`button`,{onClick:()=>void _(),disabled:h.isPending||(f.data??[]).length===0,className:`inline-flex items-center gap-1.5 rounded border border-danger/40 px-2.5 py-1 text-[11px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,children:[h.isPending&&v===null?i(j,{className:`h-3 w-3 animate-spin`}):i(oe,{className:`h-3 w-3`}),a(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`)]}),i(q,{onClick:r,variant:`secondary`,children:a(`common.close`,`Close`)})]})]})})}function wr({scopes:t,invalidReason:n}){let{t:r}=Y(),a=T(),o=s({queryKey:[`auth`,`previewScope`,t,!1],enabled:n===null,queryFn:()=>a.trpcClient.auth.previewScope.query({scopes:[...t],isAdmin:!1})}),{data:c}=H({projection:`slim`}),l=c?.length??null;if(n!==null)return e(`p`,{className:`flex items-center gap-1.5 text-[11px] text-warning`,"data-testid":`role-preview`,children:[i(k,{className:`h-3 w-3 shrink-0`}),n]});if(o.isLoading)return e(`p`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,"data-testid":`role-preview`,children:[i(j,{className:`h-3 w-3 shrink-0 animate-spin`}),r(`users.rolePreview.resolving`)]});if(o.isError||!o.data)return i(`p`,{className:`text-[11px] text-danger`,"data-testid":`role-preview`,children:r(`users.rolePreview.couldNotResolve`)});let u=o.data.viewableDeviceCount,d=o.data.device.view.all?r(`users.rolePreview.everyDevice`,{count:u}):l===null?r(`users.rolePreview.devicesVisible`,{count:u}):r(`users.rolePreview.devicesVisibleOf`,{count:u,total:l});return e(`p`,{className:`flex items-center gap-1.5 text-[11px] ${u===0?`text-warning`:`text-foreground`}`,"data-testid":`role-preview`,children:[u===0?i(k,{className:`h-3 w-3 shrink-0`}):i(h,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),u===0?r(`users.rolePreview.noDevice`):d]})}function Tr(e){let t=te(e.scopes??[]);if(t===null)return{role:e.isAdmin?`admin`:`viewer`,mode:`except`,pickedIds:[],viewer:z,unconfigured:!e.isAdmin};let n=Mr(t);return{role:e.isAdmin?`admin`:`viewer`,mode:n.mode,pickedIds:n.pickedIds,viewer:Nr(n.mode,n.pickedIds,t.features),unconfigured:!1}}function Er(e,t){return{...e,role:t}}function Dr(e,t){return{...e,mode:t,viewer:Nr(t,e.pickedIds,e.viewer.features)}}function Or(e,t){let n=Pr(t);return{...e,pickedIds:n,viewer:Nr(e.mode,n,e.viewer.features)}}function kr(e,t,n){let r=e.viewer.features.filter(e=>e!==t),i=n?[...r,t]:r;return{...e,viewer:Nr(e.mode,e.pickedIds,i)}}function Ar(e){return e.role===`viewer`&&e.mode===`only`&&e.pickedIds.length===0?`no-allowed-device`:null}function jr(e){return Ar(e)===null?e.role===`admin`?{isAdmin:!0,scopes:[]}:{isAdmin:!1,scopes:[e.viewer]}:null}function Mr(e){if(e.allow===`*`)return{mode:`except`,pickedIds:e.block};let t=new Set(e.block);return{mode:`only`,pickedIds:e.allow.filter(e=>!t.has(e))}}function Nr(e,t,n){let r=Pr(t);return e===`except`?{type:`viewer`,allow:`*`,block:r,features:[...n]}:{type:`viewer`,allow:r,block:[],features:[...n]}}function Pr(e){return[...new Set(e)]}c();var Fr=`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`;function Ir(e,t){return e?`failed`:t===void 0?`pending`:`answered`}function Lr(e){let t=[];for(let n of e)n.parentDeviceId===null&&t.push({id:n.id,name:n.name,type:String(n.type),...n.location===null?{}:{location:n.location}});return t}function Rr({user:t,isSelf:r,onClose:a,onSubmit:s,submitting:c,error:l}){let{t:u}=Y(),[f,p]=o(n(()=>Tr(t),[t])),m=H({projection:`slim`}),h=m.data,g=Ir(m.isError,h),_=n(()=>Lr(h??[]),[h]),v=n(()=>({state:g,devices:g===`answered`?(h??[]).map(e=>({id:e.id,name:e.name})):void 0}),[g,h]),y=Ar(f),b=jr(f),x=y===`no-allowed-device`?u(`users.userAccessModal.pickAllowedDevice`):null,S=e=>{p(Er(f,e))},C=[{value:`except`,label:u(`users.userAccessModal.modeExcept`)},{value:`only`,label:u(`users.userAccessModal.modeOnly`)}];return i(ot,{open:!0,onOpenChange:e=>!e&&a(),children:e(it,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-2xl`,children:[i(nt,{children:i(Ne,{children:u(`users.userAccessModal.title`,{name:t.username})})}),e(We,{className:`space-y-4`,children:[f.unconfigured&&f.role===`viewer`&&i(U,{variant:`warning`,title:u(`users.userAccessModal.noAccessYet`),message:u(`users.userAccessModal.noAccessYetDetail`,{name:t.username})}),e(`section`,{className:`space-y-2`,children:[i(`h3`,{className:Fr,children:u(`users.userAccessModal.role`)}),e(`div`,{role:`radiogroup`,"aria-label":u(`users.userAccessModal.role`),className:`grid gap-1.5 sm:grid-cols-2`,children:[i(zr,{name:`admin`,checked:f.role===`admin`,label:u(`users.userAccessModal.admin`),description:u(`users.userAccessModal.adminDescription`),onPick:()=>S(`admin`)}),i(zr,{name:`viewer`,checked:f.role===`viewer`,disabled:r,label:u(`users.userAccessModal.viewer`),description:u(r?`users.userAccessModal.cannotDemoteSelf`:`users.userAccessModal.viewerDescription`),onPick:()=>S(`viewer`)})]})]}),f.role===`viewer`&&e(d,{children:[e(`section`,{className:`space-y-3`,children:[i(`h3`,{className:Fr,children:u(`users.userAccessModal.devices`)}),i(Ke,{label:u(`users.userAccessModal.whichDevices`),value:f.mode,options:C,onChange:e=>p(Dr(f,e))}),i(Pe,{devices:_,listState:g,fleet:v,value:[...f.pickedIds],onChange:e=>p(Or(f,e)),emptyMeansAll:f.mode===`except`,noun:`device`,testId:`viewer-device-picker`}),i(wr,{scopes:b?.scopes??[],invalidReason:x})]}),e(`section`,{className:`space-y-2`,children:[i(`h3`,{className:Fr,children:u(`users.userAccessModal.features`)}),i(`div`,{className:`space-y-1`,children:ne.map(t=>e(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-md p-1.5 hover:bg-surface-hover`,children:[i(Re,{className:`mt-0.5`,checked:f.viewer.features.includes(t.id),onChange:e=>p(kr(f,t.id,e.target.checked))}),e(`span`,{className:`min-w-0`,children:[i(`span`,{className:`block text-[12px] font-medium text-foreground`,children:u(`users.viewerFeatures.${t.id}.label`,t.label)}),i(`span`,{className:`block text-[10px] text-foreground-subtle`,children:u(`users.viewerFeatures.${t.id}.description`,t.description)})]})]},t.id))})]})]}),l!==null&&i(U,{message:l})]}),e(me,{children:[i(q,{variant:`outline`,size:`sm`,onClick:a,children:u(`common.cancel`,`Cancel`)}),i(q,{size:`sm`,onClick:()=>b!==null&&s(b),disabled:c||b===null,children:c?i(j,{className:`h-3 w-3 animate-spin`}):u(`users.userAccessModal.saveAccess`)})]})]})})}function zr({name:t,checked:n,disabled:r=!1,label:a,description:o,onPick:s}){return e(`label`,{className:`flex items-start gap-2 rounded-lg border p-2.5 transition-colors ${n?`border-primary bg-primary/5`:`border-border hover:bg-surface-hover`} ${r?`cursor-not-allowed opacity-60`:`cursor-pointer`}`,children:[i(`input`,{type:`radio`,name:`user-role`,value:t,checked:n,disabled:r,onChange:s,className:`mt-0.5`}),e(`span`,{className:`min-w-0`,children:[i(`span`,{className:`block text-[12px] font-medium text-foreground`,children:a}),i(`span`,{className:`block text-[10px] text-foreground-subtle`,children:o})]})]})}c();var Br=8;function Vr(){return{username:``,password:``,isAdmin:!1}}function Hr(e){return{id:e.id,username:e.username,password:``,isAdmin:e.isAdmin}}function Ur(e){return e instanceof Error?e.message:J.t(`admin.system.users.genericError`)}function Wr(){let{t}=Y(),n=l(),{user:r}=ht(),{state:s,openNew:c,openEdit:u,close:f}=Ve(),[p,m]=o(null),[h,y]=o(null),[b,x]=o(!1),{data:w,isLoading:T,isError:D,error:k,refetch:ee}=rt(),N=M(),P=C(),F=()=>n.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),I=Ye(),L=Je({onSuccess:F}),R=he({onSuccess:F}),te=Ae({onSuccess:F}),ne=tt(),[z,B]=o(null),[re,ae]=o(!1),[oe,se]=o(null),[ce,le]=o(null),[de,pe]=o(null),[V,me]=o(null),_e=w??[],H=s.mode===`edit`?_e.find(e=>e.id===s.id)??null:null,ve=()=>{m(null),y(null),x(!1),I.reset(),R.reset(),f()};a(()=>{if(s.mode===`closed`){m(null),y(null),x(!1);return}if(s.mode===`new`){m(e=>e!==null&&e.id===void 0?e:Vr());return}if(H===null){T||f();return}m(e=>e?.id===H.id?e:Hr(H))},[s,H,T,f]);let ye=s.mode===`new`&&p!==null&&p.id===void 0||s.mode===`edit`&&p!==null&&H!==null;async function be(e){await N({title:t(`admin.system.users.deleteUser`,`Delete user`),message:t(`admin.system.users.permanentlyDeleteUserThisCannot`,`Permanently delete user "{{username}}"? This cannot be undone — any active sessions will be revoked on next request.`,{username:e.username}),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&(L.mutate({id:e.id}),s.mode===`edit`&&s.id===e.id&&ve())}async function xe(e){let n=await P({title:t(`admin.system.users.resetPassword`,`Reset password`),message:t(`admin.system.users.setANewPasswordFor`,`Set a new password for "{{username}}".`,{username:e.username}),label:t(`admin.system.users.newPassword`,`New password`),inputType:`password`,placeholder:t(`admin.system.users.atLeast8Characters`,`At least 8 characters`),confirmLabel:t(`admin.system.users.continue`,`Continue`),validate:e=>e.length<Br?J.t(`admin.system.users.passwordTooShort`,{min:Br}):null});n===null||n.length===0||await N({title:t(`admin.system.users.resetPassword`,`Reset password`),message:t(`admin.system.users.resetThePasswordForThey`,`Reset the password for "{{username}}"? They will need to use the new password on their next login.`,{username:e.username}),confirmLabel:t(`common.reset`,`Reset`)})&&te.mutate({id:e.id,newPassword:n})}function Se(e){se(null),B(e)}async function Ce(e,t){ae(!0),se(null);try{t.isAdmin!==e.isAdmin&&await R.mutateAsync({id:e.id,isAdmin:t.isAdmin}),await ne.mutateAsync({userId:e.id,scopes:[...t.scopes]}),B(null)}catch(e){se(Ur(e))}finally{ae(!1),F()}}async function we(){if(p!==null){y(null);try{if(p.id===void 0){let e=p.username.trim();if(e===``||p.password.length<Br)return;await I.mutateAsync({username:e,password:p.password,isAdmin:p.isAdmin})}else await R.mutateAsync({id:p.id,isAdmin:p.isAdmin});F(),ve()}catch(e){y(Ur(e))}}}function Te(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}let Oe=I.isPending||R.isPending,je=p!==null&&p.id===void 0&&p.username.trim()!==``&&p.password.length>=Br,Me=p!==null&&p.id!==void 0,Ne=Oe||(p?.id===void 0?!je:!Me),Pe=e=>L.isPending&&L.variables?.id===e.id||R.isPending&&R.variables?.id===e.id||te.isPending&&te.variables?.id===e.id,Fe=[{key:`username`,header:t(`admin.system.users.username`,`Username`),sortValue:e=>e.username,render:e=>i(`span`,{className:`font-medium text-foreground`,"data-testid":`user-open-${e.id}`,children:e.username})},{key:`scopes`,header:t(`admin.system.users.access`,`Access`),sortValue:e=>Gr(e),render:n=>i(`span`,{onClick:e=>e.stopPropagation(),children:e(q,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>Se(n),disabled:Pe(n),title:t(`admin.system.users.configureAccess`,`Configure access`),"data-testid":`user-access-${n.id}`,children:[i(A,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),i(Kr,{user:n})]})})},{key:`createdAt`,header:t(`admin.system.users.created`,`Created`),nowrap:!0,sortValue:e=>e.createdAt,render:e=>i(`span`,{className:`text-foreground-subtle`,children:Te(e.createdAt)})},{key:`actions`,header:t(`admin.system.users.actions`,`Actions`),align:`right`,nowrap:!0,notSortableReason:`Row actions`,render:n=>{let a=Pe(n),o=n.id!==r?.id&&n.totpEnabled;return e(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[e(q,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>u(n.id),disabled:a,title:t(`admin.system.users.editUser`,`Edit user`),children:[i(g,{className:`h-3 w-3`}),t(`common.edit`,`Edit`)]}),o&&e(q,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>le(n),disabled:a,title:t(`admin.system.users.removeTwoFactorAuthentication`,`Remove two-factor authentication`),children:[i(S,{className:`h-3 w-3`}),t(`admin.system.users.remove2fa`,`Remove 2FA`)]}),e(q,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>pe(n),disabled:a,title:t(`admin.system.users.linkedSignInAccounts`,`Linked sign-in accounts`),children:[i(E,{className:`h-3 w-3`}),t(`admin.system.users.signInLinks`,`Sign-in links`)]}),e(q,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>me(n),disabled:a,title:t(`admin.system.users.activeSessions`,`Active sessions`),children:[i(ue,{className:`h-3 w-3`}),t(`admin.system.users.sessions`,`Sessions`)]}),e(q,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void xe(n),disabled:a,title:t(`admin.system.users.resetPassword`,`Reset password`),children:[i(ie,{className:`h-3 w-3`}),t(`admin.system.users.resetPassword`,`Reset password`)]}),e(q,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void be(n),disabled:a,title:t(`admin.system.users.deleteUser`,`Delete user`),className:`text-danger hover:bg-danger/10`,children:[a?i(j,{className:`h-3 w-3 animate-spin`}):i(_,{className:`h-3 w-3`}),t(`common.delete`,`Delete`)]})]})}}];return e(bt,{embedded:!0,icon:O,title:t(`admin.system.users.users`,`Users`),subtitle:t(`admin.system.users.hubAccountsAdminFlagAccess`,`Hub accounts, admin flag, access scopes, sessions and sign-in links.`),actions:e(q,{size:`sm`,type:`button`,onClick:()=>{y(null),c()},children:[i(v,{className:`h-3.5 w-3.5`}),t(`admin.system.users.createUser`,`Create User`)]}),children:[D&&i(U,{title:t(`admin.system.users.couldNotLoadUsers`,`Could not load users`),message:Ur(k),onRetry:()=>void ee()}),T&&e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(j,{className:`h-3.5 w-3.5 animate-spin`}),t(`common.loading`,`Loading…`)]}),!T&&!D&&_e.length===0&&i(De,{icon:O,title:t(`admin.system.users.noUsersYet`,`No users yet`),description:t(`admin.system.users.createAUserToGrant`,`Create a user to grant hub access.`)}),!T&&!D&&_e.length>0&&i(fe,{columns:Fe,rows:_e,rowKey:e=>e.id,minWidthPx:560,maxBodyHeight:`max-h-[60vh]`,onRowClick:e=>u(e.id)}),i(st,{open:ye,onClose:ve,title:p?.id===void 0?t(`admin.system.users.createUser`,`Create User`):t(`admin.system.users.edit`,`Edit {{value1}}`,{value1:p.username||`user`}),icon:O,error:h,testId:`user-form-dialog`,footer:i(q,{size:`sm`,type:`button`,disabled:Ne,onClick:()=>void we(),children:Oe?e(d,{children:[i(j,{className:`h-3.5 w-3.5 animate-spin`}),t(`admin.system.users.saving`,`Saving…`)]}):p?.id===void 0?t(`admin.system.users.create`,`Create`):t(`common.save`,`Save`)}),children:p!==null&&e(`div`,{className:`space-y-3`,children:[i(ge,{label:t(`admin.system.users.username`,`Username`),required:p.id===void 0,children:i(ke,{value:p.username,onChange:e=>m({...p,username:e.target.value}),placeholder:`john`,autoFocus:p.id===void 0,disabled:p.id!==void 0,"data-testid":`user-form-username`})}),p.id===void 0&&i(ge,{label:t(`admin.system.users.password`,`Password`),required:!0,description:t(`admin.system.users.atLeastCharacters`,`At least {{value1}} characters.`,{value1:String(Br)}),children:i(Ee,{value:p.password,onValueChange:e=>m({...p,password:e}),shown:b,onToggleShown:()=>x(e=>!e),placeholder:`••••••••`,"data-testid":`user-form-password`})}),i(ge,{label:t(`admin.system.users.admin`,`Admin`),description:t(`admin.system.users.unrestrictedAccessToEveryCapability`,`Unrestricted access to every capability and device.`),children:e(`label`,{className:`inline-flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[i(`input`,{type:`checkbox`,checked:p.isAdmin,onChange:e=>m({...p,isAdmin:e.target.checked}),className:`rounded border-border focus:ring-primary`,"data-testid":`user-form-admin`}),i(`span`,{children:t(`admin.system.users.admin`,`Admin`)})]})}),p.id!==void 0&&i(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`admin.system.users.toChangeThePasswordUse`,`To change the password, use Reset password on the user's row. Access scopes are configured from the Access column.`)})]})}),ce&&i(Sr,{userId:ce.id,username:ce.username,onClose:()=>le(null)}),de&&i(xr,{userId:de.id,username:de.username,onClose:()=>pe(null)}),V&&i(Cr,{userId:V.id,username:V.username,onClose:()=>me(null)}),z&&i(Rr,{user:z,isSelf:z.id===r?.id,onClose:()=>B(null),onSubmit:e=>void Ce(z,e),submitting:re,error:oe})]})}function Gr(e){let t=Tr(e);return t.role===`admin`?0:t.unconfigured?2:1}function Kr({user:t}){let{t:n}=Y(),r=Tr(t);if(r.role===`admin`)return i(`span`,{className:`font-medium text-foreground`,children:n(`users.accessSummary.admin`)});if(r.unconfigured)return i(`span`,{className:`font-medium text-warning`,children:n(`admin.system.users.noAccess`,`No access`)});let{allow:a,block:o,features:s}=r.viewer,c=a===`*`?n(`users.accessSummary.allDevices`):n(`users.accessSummary.devices`,{count:a.length});return e(`span`,{className:`text-foreground-subtle`,children:[i(`span`,{className:`font-medium text-foreground`,children:n(`users.accessSummary.viewer`)}),` ·`,` `,c,o.length>0&&e(d,{children:[` · `,n(`users.accessSummary.blocked`,{count:o.length})]}),s.length>0&&e(d,{children:[` · `,n(`users.accessSummary.features`,{count:s.length})]})]})}c();var qr={"api-keys":$.tokens,"linked-sessions":$.linkedApps},Jr=`certificates`;function Yr(t){return e(q,{size:`sm`,type:`button`,"data-testid":`certificates-pair-device`,onClick:t,children:[i(S,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),J.t(`systemPage.identity.pairADevice`,`Pair a device`)]})}function Xr(){let{t:e}=Y(),[t]=ut(),n=bn(),[r,a]=o(!1),s=qr[t.get(`tab`)??``];if(s!==void 0)return i(ft,{to:gt(`access`,{integration:s}),replace:!0});let c=ct(`/system/identity`,{t:e,isAdmin:!0})??{icon:ee,title:e(`system.identity`,`Identity & Access`)},l=t.get(`tab`)??`users`,u=t.get(`integration`),d=l===lt.access.tab?yn(u,n.requestCreate):l===`certificates`?Yr(()=>a(!0)):void 0;return i(yt,{icon:c.icon,title:c.title,defaultSection:`users`,sectionsLabel:`${c.title} sections`,actions:d,sections:[{id:`users`,label:e(`systemPage.identity.users`,`Users`),content:i(Wr,{})},{id:lt.access.tab,label:e(`systemPage.identity.tokensSessions`,`Tokens & sessions`),ownedParams:mt.concat([Mt.token,Mt.scoped,Mt.admin]),content:i(vn,{createRequested:n.createRequested,onCreateConsumed:n.clearCreate})},{id:Jr,label:e(`systemPage.identity.certificates`,`Certificates`),content:i(br,{pairOpen:r,onPairClose:()=>a(!1)})},{id:lt.authentication.tab,label:e(`systemPage.identity.authentication`,`Authentication`),content:i(Nn,{}),ownedParams:mt}]})}export{Xr as IdentityPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,et as s,o as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Ai as l,An as u,Di as d,Dn as f,Gr as p,Ht as m,In as h,Kr as g,Tn as _,bt as v,dt as y,gn as b,ha as x,hi as S,ia as C,ki as w,pr as T,xi as E,yn as D,zt as O}from"./player-overlays-Cw_gjG75.js";import{eo as ee}from"./client-r4i0EpF6.js";import{t as k}from"./search-x-CCA8373c.js";import{$d as te,Aa as A,Ai as j,Ao as ne,As as M,Cn as N,Cr as re,Do as P,Eo as F,Fo as ie,Fs as I,Ft as ae,Ji as L,Ko as R,Ls as z,Lt as B,Ma as V,Ms as oe,Nn as H,Nr as U,Ns as se,Pa as ce,Ps as le,Pt as ue,Qn as W,Rd as de,So as fe,Sr as pe,Tr as me,Wo as G,Xn as he,_o as K,br as ge,cn as q,go as J,ho as _e,js as ve,ki as ye,ls as be,mo as xe,oi as Se,po as Ce,pr as we,rf as Te,ri as Y,wr as Ee,xo as De,xr as X,yo as Z,yr as Oe}from"./src-nnHXOip7.js";import{t as Q}from"./useTranslation-BJr-n0es.js";import{n as ke}from"./addon-icons-context-BHF-RdY-.js";import{C as Ae,R as je,S as Me,br as Ne,mr as Pe,vr as Fe,w as Ie,yr as Le}from"./index-Ohn-2iW_.js";import{t as Re}from"./device-integration-icon-Cf2JTj5q.js";import{a as ze,i as Be,r as Ve,t as He}from"./ScanNetworkModal-DL-mWRtG.js";import{t as Ue}from"./NodeAddonsSettingsPanel-JIXh-CLX.js";s();function We(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...We(n.fields));return t}function Ge(e,t,i){let[a,s]=o(`idle`),[c,l]=o({}),u=n(()=>{let t=[];for(let n of e.sections)t.push(...We(n.fields));return t},[e]),d=u.length>0&&i!==void 0,f=r(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:a,hasProbeFields:d,probeResults:c,handleTestAll:r(async()=>{if(!i)return;let e=u.filter(e=>{let n=t[e];return n!=null&&String(n).trim()!==``});if(e.length===0)return;s(`testing`);let n={};for(let t of e)n[t]={status:`probing`};l(n);let r=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await i(e,t[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),a={};for(let e of r)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;a[t]={status:n.status===`ok`?`ok`:`error`,result:n}}l(a),s(`idle`)},[i,u,t]),clearProbeResult:f}}s();function Ke(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(...Ke(n.fields));return t}function qe(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Je(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Je(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function $(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function Ye({open:t,integrationId:s,addonId:l,onClose:u}){let{t:d}=Q(),f=c(),[p,m]=o({}),[h,g]=o(!1),[_,y]=o(null),[b,x]=o($),S=G({addonId:l},{enabled:t}),C=S.data?.deviceType??null,E=ne({addonId:l,type:C??ee.Camera},{enabled:t&&S.isSuccess&&C!==null}),k=E.data??null;a(()=>{t&&(m(k?Je(k.sections.flatMap(e=>e.fields)):{}),x($()),g(!1),y(null))},[t,s,k]);let te=n(()=>({...p,_probeRequestId:b}),[p,b]),A=De({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),j=be(),M=r(async(e,t)=>{g(!0);let n=await j.mutateAsync({addonId:l,type:C??ee.Camera,key:e,value:t,formValues:te});return n.status===`ok`&&n.suggestedValues&&m(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))qe(e[i])&&!qe(a)&&(r[i]=a,t=!0);return t?r:e}),n},[j,l,te,C]),{testAllStatus:N,hasProbeFields:P,probeResults:F,handleTestAll:ie,clearProbeResult:I}=Ge(k??{sections:[]},p,M);async function ae(e){y(null);try{await A.mutateAsync({addonId:l,type:C??ee.Camera,config:p,integrationId:s}),e?m(k?Je(k.sections.flatMap(e=>e.fields)):{}):u()}catch(e){y(e instanceof Error?e.message:String(e))}}if(!t)return null;let L=Ke((k?.sections??[]).flatMap(e=>e.fields)).filter(e=>qe(p[e])),R=L.length===0,z=S.isLoading||C!==null&&E.isLoading,B=S.isError||S.isSuccess&&C===null||E.isError||E.isSuccess&&k===null;return i(Oe,{open:!0,onOpenChange:e=>{e||u()},children:e(X,{width:`lg`,scroll:`body`,children:[i(Ee,{children:i(me,{children:d(`integrations.addDevice`)})}),i(ge,{className:`space-y-3`,children:z?i(`div`,{className:`flex items-center justify-center py-8`,children:i(T,{className:`h-5 w-5 animate-spin text-primary`})}):B?e(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[i(O,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),e(`div`,{className:`space-y-1`,children:[i(`p`,{className:`text-xs font-medium text-destructive`,children:d(`integrations.addDeviceDialog.providerUnavailable`,`Provider unavailable`)}),i(`p`,{className:`text-xs text-foreground-subtle`,children:i(Pe,{i18nKey:`integrations.addDeviceDialog.notReady`,values:{addonId:l},components:{mono:i(`span`,{className:`font-mono`})}})})]})]}):i(je,{schema:k,values:p,onChange:m,onTestField:M,probeResults:F,onClearProbe:I})}),!B&&!z&&e(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[e(`button`,{type:`button`,onClick:()=>g(e=>!e),className:`flex w-full items-center justify-between px-3 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[e(`span`,{className:`flex items-center gap-2`,children:[i(D,{className:`h-3.5 w-3.5`}),d(`integrations.addDeviceDialog.testLogs`,`Test logs`),i(`span`,{className:`font-mono text-[9px] opacity-60`,children:b.slice(0,14)})]}),i(w,{className:`h-3.5 w-3.5 transition-transform ${h?`rotate-180`:``}`})]}),h&&i(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:i(q,{addonId:l,requestId:b,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!B&&!z&&(_||L.length>0)&&i(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-3 py-2 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(O,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),i(`p`,{className:`text-[11px] text-destructive`,children:_||d(`integrations.addDeviceDialog.required`,`Required: {{value1}}`,{value1:L.join(`, `)})})]})}),e(re,{className:`justify-between`,children:[e(`div`,{className:`flex items-center gap-2`,children:[i(`button`,{onClick:u,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:d(`integrations.cancel`)}),!B&&P&&e(`button`,{type:`button`,onClick:ie,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`?i(T,{className:`h-3.5 w-3.5 animate-spin`}):i(v,{className:`h-3.5 w-3.5`}),d(`integrations.addDeviceDialog.testAll`,`Test All`)]})]}),e(`div`,{className:`flex items-center gap-2`,children:[i(`button`,{onClick:()=>ae(!0),disabled:B||!R||A.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:d(`integrations.saveAndNew`)}),i(`button`,{onClick:()=>ae(!1),disabled:B||!R||A.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:A.isPending?d(`integrations.saving`):d(`integrations.save`)})]})]})]})})}s();var Xe=`matter`,Ze=[`discovering`,`pase`,`commissioning`,`done`];function Qe(e){return!(typeof e!=`object`||!e||!(`phase`in e)||typeof e.phase!=`string`)}function $e(e,t){return e===`code-expired`||t?.includes(`matter-commission:code-expired`)?{key:`integrations.addMatter.failure.expired`,defaultValue:`The pairing code expired. Share the device again and paste the new code.`}:e===`device-not-found`||t?.includes(`matter-commission:device-not-found`)?{key:`integrations.addMatter.failure.notFound`,defaultValue:`No Matter device with that code was found on the network.`}:e===`wrong-code`||t?.includes(`matter-commission:wrong-code`)?{key:`integrations.addMatter.failure.wrongCode`,defaultValue:`The pairing code was rejected.`}:e===`invalid-code`||t?.includes(`invalid pairing code`)?{key:`integrations.addMatter.failure.invalid`,defaultValue:`Enter an 11-digit or 21-digit manual code, or a code that starts with MT:.`}:{key:`integrations.addMatter.failure.unknown`,defaultValue:t??`Commissioning failed.`}}function et({onClose:t,onCommissioned:n}){let{t:r}=Q(),s=V({kind:Xe}),[c,l]=o(null),u=s.data?.length??0,d=c??s.data?.[0]?.id??null,f=ce(),[p,m]=o(``),[h,g]=o({phase:`idle`,failure:null,message:null}),_=h.phase===`discovering`||h.phase===`pase`||h.phase===`commissioning`,v=A({brokerId:d??``,key:`commission`},{enabled:d!==null&&_,refetchInterval:_?400:!1});a(()=>{_&&Qe(v.data)&&v.data.phase!==`idle`&&g({phase:v.data.phase,failure:typeof v.data.failure==`string`?v.data.failure:null,message:typeof v.data.message==`string`?v.data.message:null})},[_,v.data]);let y=()=>{d!==null&&(g({phase:`discovering`,failure:null,message:null}),f.mutate({brokerId:d,target:{action:`commissionNode`},payload:{pairingCode:p.trim()}},{onSuccess:()=>g({phase:`done`,failure:null,message:null}),onError:e=>{let t=e instanceof Error?e.message:`Commissioning failed.`;g({phase:`failed`,failure:t.includes(`matter-commission:`)?t.split(`matter-commission:`)[1]?.split(`:`)[0]??`unknown`:t.includes(`invalid pairing code`)?`invalid-code`:`unknown`,message:t})}}))},b=h.phase===`failed`?$e(h.failure,h.message):null,x=b===null?null:r(b.key,{defaultValue:b.defaultValue}),S=(s.isSuccess===!0||s.data!==void 0)&&d===null;return i(Oe,{open:!0,onOpenChange:e=>!e&&t(),children:e(X,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(Ee,{children:i(me,{children:r(`integrations.addMatter.title`,{defaultValue:`Add Matter device`})})}),e(ge,{className:`space-y-4`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:r(`integrations.addMatter.help`,{defaultValue:`In Home Assistant, open the device and choose Share device. Paste the numeric code or the MT: code here. The device stays in Home Assistant.`})}),(S||u>1)&&!_&&h.phase!==`done`&&e(`div`,{className:`space-y-1.5`,children:[i(W,{children:r(`integrations.addMatter.broker`,{defaultValue:`Matter fabric`})}),i(ze,{kind:Xe,value:d,onChange:l})]}),!S&&e(`div`,{className:`space-y-1.5`,children:[i(W,{htmlFor:`matter-pairing-code`,children:r(`integrations.addMatter.code`,{defaultValue:`Pairing code`})}),i(de,{id:`matter-pairing-code`,value:p,autoComplete:`off`,spellCheck:!1,placeholder:`34970112332`,disabled:_||h.phase===`done`,onChange:e=>m(e.target.value)})]}),h.phase!==`idle`&&i(`ol`,{className:`space-y-1`,"aria-label":r(`integrations.addMatter.progress`,{defaultValue:`Commissioning progress`}),children:Ze.map(t=>{let n=h.phase===t;return e(`li`,{className:`text-xs ${n?`text-foreground font-medium`:`text-foreground-subtle`}`,children:[n&&_?i(T,{className:`mr-1 inline h-3 w-3 animate-spin`}):null,r(`integrations.addMatter.phase.${t}`,{defaultValue:t===`discovering`?`Discovering`:t===`pase`?`PASE`:t===`commissioning`?`Commissioning`:`Done`})]},t)})}),x!==null&&i(U,{message:x})]}),e(re,{children:[i(Y,{variant:`ghost`,size:`sm`,onClick:t,children:r(`common.close`,{defaultValue:`Close`})}),h.phase===`done`?i(Y,{size:`sm`,onClick:n,children:r(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}):i(Y,{size:`sm`,disabled:_||S||p.trim().length===0,onClick:y,children:_?r(`integrations.addMatter.working`,{defaultValue:`Adding…`}):r(`integrations.addMatter.submit`,{defaultValue:`Add device`})})]})]})})}var tt=1500;function nt({addonId:t,integrationId:n,jobId:r,onFinished:a}){let{t:o}=Q(),s=Ce(),c=(J({addonId:t,integrationId:n},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?tt:!1}).data??[]).find(e=>e.jobId===r);if(!c)return null;let l=c.state===`running`,u=c.processed,d=c.total>0?Math.round(u/c.total*100):0;!l&&c.finishedAt!==null&&a();let f=[`${u}/${c.total} ${o(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];c.adopted>0&&f.push(`${c.adopted} ${o(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),c.alreadyAdopted>0&&f.push(`${c.alreadyAdopted} ${o(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),c.failed>0&&f.push(`${c.failed} ${o(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let p=f.join(` · `);return e(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[e(`div`,{className:`flex items-center gap-2`,children:[l?i(T,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):c.failed>0?i(O,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):c.state===`cancelled`?i(S,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):i(E,{className:`h-3.5 w-3.5 text-primary shrink-0`}),i(`p`,{className:`text-[11px] text-foreground`,children:p}),l&&i(`button`,{onClick:()=>s.mutate({jobId:r}),className:`ml-auto rounded-lg border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:o(`integrations.adoptJobCancel`,{defaultValue:`Stop`})})]}),i(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:i(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${d}%`},role:`progressbar`,"aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100})}),c.results.filter(e=>e.outcome===`failed`).slice(0,5).map(t=>e(`p`,{className:`text-[11px] text-destructive`,children:[t.childNativeId,`: `,t.error]},t.childNativeId))]})}function rt(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}s();var it=`devices`;function at(e){return{id:it,label:e(`integrations.adoptDevicesModal.defaultFilter`),isDefault:!0}}var ot=2e4,st=100;function ct({addonId:n,integrationId:s,onClose:u}){let d=x(),{t:f}=Q(),p=c(),[m,h]=o(new Set),[g,v]=o(new Set),[y,b]=o(new Map),[S,C]=o(null),{data:w}=oe(),E=(w??[]).find(e=>e.addonId===n)?.supportsLocationImport??!1,[D,ee]=o(!0),k=xe({addonId:n,integrationId:s}).data?.filters,A=k&&k.length>0?k:[at(f)],[j,ne]=o(A.find(e=>e.isDefault)?.id??(A.some(e=>e.id===it)?it:A[0].id)),M=j!==it,N=K(),P=_e({addonId:n,integrationId:s,page:1,pageSize:ot,filter:j}),F=P.refetch,ie=N.mutate,I=r(()=>{ie({addonId:n,integrationId:s},{onSettled:()=>{F()}})},[ie,n,s,F]),ae=t(null);a(()=>{let e=`${n}::${s}`;ae.current===e||P.isLoading||(ae.current=e,(P.data?.candidates.length??0)===0&&I())},[n,s,P.isLoading,P.data,I]);let L=N.isPending,R=N.isError?N.error instanceof Error?N.error.message:String(N.error):null,z=typeof N.data?.lastError==`string`&&N.data.lastError.length>0?N.data.lastError:null,B=P.data?.candidates??[],V=P.isError?P.error instanceof Error?P.error.message:String(P.error):null,H=Z(),[U,se]=o(null),ce=r(e=>{e.alreadyAdopted||h(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),le=r(e=>{v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),W=r((e,t)=>{b(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),de=r(e=>{let t={};for(let n of e){let e=y.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[y]),fe=r(async()=>{C(null);let e=[...m];if(e.length!==0)try{let t=de(e),{jobId:r}=await H.mutateAsync({addonId:n,integrationId:s,filter:j,childNativeIds:e,...t?{perCandidate:t}:{},...E?{importLocations:D}:{}});se(r),h(new Set),b(new Map)}catch(e){C(e instanceof Error?e.message:String(e))}},[m,de,H,n,s,j,E,D]),G=t(null),he=r(()=>{U===null||G.current===U||(G.current=U,F(),p.invalidateQueries({queryKey:[[`integrations`]]}),p.invalidateQueries({queryKey:[[`deviceManager`]]}))},[U,F,p]),ge=r(e=>{ne(e),h(new Set),v(new Set),b(new Map),C(null)},[]),q=m.size,J=U!==null&&q===0&&!H.isPending;return i(Oe,{open:!0,onOpenChange:e=>{e||u()},children:e(X,{width:`xl`,scroll:`body`,className:`md:h-[85vh]`,children:[e(Ee,{children:[i(me,{children:f(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),i(pe,{children:f(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})}),E&&e(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[i(`input`,{type:`checkbox`,checked:D,onChange:e=>ee(e.target.checked),className:`accent-primary`}),f(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]})]}),e(`div`,{className:`flex-1 min-h-0 flex flex-col gap-2 overflow-hidden`,children:[(R??V??z)&&B.length===0&&i(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(O,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),e(`div`,{className:`min-w-0`,children:[i(`p`,{className:`text-xs font-medium text-destructive`,children:f(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),i(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:R??V??z})]})]})}),A.length>1&&i(lt,{filters:A,activeFilter:j,onSelect:ge}),i(`div`,{className:`flex-1 min-h-0`,children:i(ue,{mode:`generic`,items:B,pageSize:st,getKey:e=>e.childNativeId,getSearchText:rt,getFilterType:e=>e.type,filterOptions:te(d),filterLabel:f(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:P.isLoading||L&&B.length===0,searchPlaceholder:f(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(R??V??z)&&B.length===0?``:f(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:e(`button`,{type:`button`,onClick:I,disabled:L,title:f(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[i(_,{className:`h-3.5 w-3.5 ${L?`animate-spin`:``}`}),f(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:f(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>i(ut,{candidate:e,expandable:!M,expanded:g.has(e.childNativeId),onToggleExpand:()=>le(e.childNativeId),adoptedLabel:f(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:f(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:t=>{let n=Te(t.type,d),r=n.icon;return e(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[i(r,{className:`h-3.5 w-3.5 shrink-0`}),n.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>i(`div`,{className:`flex items-center justify-end`,children:i(`button`,{onClick:()=>ce(e),disabled:e.alreadyAdopted,"aria-label":m.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 ${m.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:m.has(e.childNativeId)&&i(l,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!M&&g.has(e.childNativeId),renderExpanded:M?void 0:e=>i(dt,{candidate:e,hiddenChildIds:y.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>W(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:m.has(e.childNativeId)?`bg-primary/5`:``})})]}),S&&i(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-3 py-2 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(O,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),i(`p`,{className:`text-[11px] text-destructive`,children:S})]})}),U!==null&&i(nt,{addonId:n,integrationId:s,jobId:U,onFinished:he}),e(re,{children:[i(Y,{variant:`outline`,size:`sm`,onClick:u,children:f(`integrations.cancel`,{defaultValue:`Cancel`})}),e(Y,{variant:`primary`,size:`sm`,onClick:J?u:fe,disabled:!J&&(q===0||H.isPending),children:[H.isPending&&i(T,{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 lt({filters:e,activeFilter:t,onSelect:n}){let{t:r}=Q();return i(`div`,{role:`tablist`,"aria-label":r(`integrations.adoptDevicesModal.discoveryGranularity`,`Discovery granularity`),className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return i(`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 ut({candidate:t,expandable:n,expanded:r,onToggleExpand:a,adoptedLabel:o}){let{t:s}=Q(),c=(t.children??[]).length;return e(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[n&&c>0?e(`button`,{type:`button`,onClick:a,"aria-label":r?s(`integrations.adoptDevicesModal.collapse`,`Collapse`):s(`integrations.adoptDevicesModal.expand`,`Expand`),"aria-expanded":r,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[i(r?w:d,{className:`h-3.5 w-3.5`}),c]}):i(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),i(`span`,{className:`truncate text-xs font-medium text-foreground`,children:t.name}),t.alreadyAdopted&&i(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:o})]})}function dt({candidate:t,hiddenChildIds:n,onToggleChildHidden:r}){let{t:a}=Q(),o=t.children??[];return o.length===0?null:i(`div`,{className:`space-y-1 py-1`,children:o.map(t=>{let o=n.has(t.childNativeId),s=t.capabilities??[];return e(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${o?`opacity-50`:``}`,children:[i(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:t.name}),s.length>0&&i(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:s.join(`, `)}),i(`button`,{onClick:()=>r(t.childNativeId),"aria-label":o?a(`integrations.adoptDevicesModal.showChild`,`Show child`):a(`integrations.adoptDevicesModal.hideChild`,`Hide child`),title:o?a(`integrations.adoptDevicesModal.showAfterAdopt`,`Show after adopt`):a(`integrations.adoptDevicesModal.hideAfterAdopt`,`Hide after adopt`),className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:i(o?g:p,{className:`h-3 w-3`})})]},t.childNativeId)})})}s();function ft(e){let t=[];for(let n of e){if(n.type===`group`){t.push(...ft(n.fields));continue}`key`in n&&typeof n.key==`string`&&t.push(n.key)}return t}function pt(e,t){if(!e)return{};let n=new Set(e.sections.flatMap(e=>ft(e.fields))),r={};for(let e of n)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}function mt(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 ht({integrationId:t,addonId:r,name:a,kind:o,mode:s,brokerKind:l,canTest:u=!1,trpc:d,onClose:f}){let{t:p}=Q(),m=c(),{data:h,isLoading:g}=se({id:t},{enabled:s===`account`||s===`broker`}),_=n(()=>{let e=h?.brokerId;return typeof e==`string`?e:null},[h]),{data:v,isLoading:y}=ye({addonId:r,nodeId:`hub`},{enabled:s===`account`}),b=n(()=>v?mt(v):null,[v]),x=I(),S=(e,n)=>{x.mutate({id:t,settings:e,...n?{secretKeys:[...n]}:{}},{onSuccess:()=>{m.invalidateQueries(),f()}})};return i(Oe,{open:!0,onOpenChange:e=>!e&&f(),children:e(X,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(Ee,{children:e(me,{children:[p(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,a]})}),i(ge,{children:s===`broker`?l?e(`div`,{className:`space-y-3`,children:[i(`p`,{className:`text-[11px] text-foreground-subtle`,children:p(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),_&&e(`p`,{className:`text-[11px] text-foreground`,children:[p(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,i(`span`,{className:`font-mono text-foreground-subtle`,children:_})]}),x.isPending?e(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[i(T,{className:`h-3 w-3 animate-spin`}),p(`integrations.saving`,{defaultValue:`Saving…`})]}):i(Be,{kind:l,onResolved:e=>{S({brokerId:e})},onBack:f}),x.isError&&i(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):i(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):s===`account`?g||y?e(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[i(T,{className:`h-3 w-3 animate-spin`}),p(`integrations.loading`,{defaultValue:`Loading…`})]}):i(Ve,{addonId:r,configSchema:b,canTest:u,initialName:a,initialConfig:pt(b,h??{}),submitLabel:p(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e,secretKeys:t})=>S(e,t),onBack:f}):i(we,{trpc:d,addonId:r,nodeId:`hub`,title:a})})]})})}function gt(e){return e==null?!1:e.sections.some(e=>e.fields.length>0)}s();function _t(){let{addonId:e=``}=Le();return i(yt,{addonId:e})}function vt(){return e(`div`,{className:`p-4`,children:[i(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),i(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]})}function yt({addonId:t}){let{t:s}=Q(),l=c(),d=Fe(),[p,g]=Ne(),_=y(),[v,x]=o(!1),[S,w]=o(!1),[E,O]=o(!1),ee=r(e=>{O(!1),d(`/integrations`,{state:{integrationSeed:e}})},[d]),[te,A]=o(!1),[ne,re]=o(!1),{data:I}=le(void 0),V=n(()=>(I??[]).filter(e=>e.addonId===t),[I,t]),U=Ie(p.get(`instance`),V)??``,se=r(e=>{g(t=>{let n=new URLSearchParams(t);return n.set(Me,e),n},{replace:!0})},[g]),ce=n(()=>V.map(e=>({value:e.id,label:e.name})),[V]),{data:W,isLoading:de}=ve({id:U},{enabled:!!U}),{data:pe}=ye({addonId:W?.addonId??``,nodeId:`hub`},{enabled:!!W?.addonId}),{data:G,isSuccess:K}=oe(),J=n(()=>{let e=W?.addonId;return!e||!K?null:(G??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[G,W?.addonId,K]),{data:_e}=F({}),be=n(()=>(_e?.providers??[]).some(e=>e.addonId===W?.addonId),[_e,W?.addonId]),xe=J!==null,Ce=W?.info?.fixed===!0,we=n(()=>{let e=W?.addonId;return!e||!K?null:(G??[]).find(t=>t.addonId===e)?.brokerKind??null},[G,W?.addonId,K]),Te=we===`matter`,Y=xe?Te?s(`integrations.addMatter.title`,{defaultValue:`Add Matter device`}):J===`device-adoption`?s(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):s(`integrations.addDevice`):s(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),De=n(()=>{let e=W?.addonId;return!e||!K?!1:(G??[]).find(t=>t.addonId===e)?.canTest===!0},[G,W?.addonId,K]),Z=n(()=>{let e=W?.addonId;return!e||!K?null:(G??[]).find(t=>t.addonId===e)?.mode??null},[G,W?.addonId,K]);a(()=>{p.get(`add`)===`1`&&xe&&(w(!1),x(!0),g(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[p,xe,g]);let ke=pe!=null&&Array.isArray(pe.sections)&&pe.sections.some(e=>e.fields.length>0),{data:je}=j({addonId:W?.addonId??``,nodeId:`hub`},{enabled:!!W?.addonId&&Z!==`account`}),Pe=Z!==null&&Z!==`account`&>(je),Le=n(()=>W?.addonId?[W.addonId]:[],[W?.addonId]),{data:ze}=ie({projection:`slim`},{refetchInterval:3e4}),Be=[[`integrations`,`get`],{input:{id:U},type:`query`}],Ve=z({onMutate:async e=>{await l.cancelQueries({queryKey:Be});let t=l.getQueryData(Be);return t!=null&&l.setQueryData(Be,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&l.setQueryData(Be,r.previous)},onSettled:()=>{l.invalidateQueries({queryKey:[[`integrations`]]}),l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),We=M({onSuccess:()=>{l.invalidateQueries({queryKey:[[`integrations`]]}),l.invalidateQueries({queryKey:[[`deviceManager`]]}),d(V.length>1?Ae(t):`/integrations`)}}),Ge=L({onSuccess:()=>{l.invalidateQueries({queryKey:[[`integrations`]]}),l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ke=R({onSuccess:()=>{l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),qe=fe({onSuccess:()=>{l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Je=P({onSuccess:()=>{l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),$=n(()=>ze??[],[ze]),Xe=n(()=>{let e=new Map;for(let t of $)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[$]),Ze=r(e=>Xe.get(e)??null,[Xe]),Qe=n(()=>ae(I),[I]),$e=r(e=>d(`/devices/${String(e)}`),[d]),tt=n(()=>$.filter(e=>{let t=Qe(e);return t.kind===`resolved`&&t.integration.id===U}),[$,U,Qe]),nt=n(()=>I===void 0?null:B(tt).length,[I,tt])??`…`;if(de||I===void 0)return i(vt,{});let rt=(G??[]).find(e=>e.addonId===t)?.name??W?.name??t;return W?e(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[i(H,{items:[{label:s(`integrationDetail.integrations`,`Integrations`),onClick:()=>d(`/integrations`)},{label:rt}]}),e(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[e(`div`,{className:`flex items-center gap-3 min-w-0`,children:[i(bt,{addonId:W.addonId}),e(`div`,{className:`min-w-0`,children:[i(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:rt}),e(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[nt,` `,s(`integrations.devices`)]})]})]}),e(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[be&&e(`button`,{onClick:()=>O(!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:s(`integrationDetail.scanTheNetworkForDevices`,`Scan the network for devices (incl. a different subnet)`),children:[i(u,{className:`h-3.5 w-3.5`}),s(`integrationDetail.scanNetwork`,`Scan network`)]}),!Ce&&e(`button`,{onClick:()=>{w(!1),x(!0)},disabled:!xe,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:Y,children:[i(h,{className:`h-3.5 w-3.5`}),Y]}),e(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Ve.isPending?`opacity-60`:``} ${W.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:s(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[i(he,{checked:W.enabled,onCheckedChange:e=>Ve.mutate({id:U,enabled:e}),disabled:Ve.isPending,"aria-label":W.enabled?s(`integrationDetail.disableIntegration`,`Disable integration`):s(`integrationDetail.enableIntegration`,`Enable integration`)}),i(`span`,{className:`text-[11px] font-medium ${W.enabled?`text-success`:`text-foreground-subtle`}`,children:W.enabled?s(`integrationDetail.enabled`,`Enabled`):s(`integrationDetail.disabled`,`Disabled`)}),Ve.isPending&&i(T,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Z!==`standalone`&&(ke||J===`device-adoption`)&&e(`button`,{onClick:()=>A(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[i(b,{className:`h-3 w-3`}),s(`integrations.config`)]}),e(`button`,{onClick:()=>re(!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:s(`integrations.logs`,{defaultValue:`View logs`}),children:[i(D,{className:`h-3 w-3`}),s(`integrations.logs`,{defaultValue:`Logs`})]}),i(N,{label:s(`integrationDetail.restart`,`Restart`),icon:f,title:s(`integrationDetail.restart2`,`Restart "{{name}}"?`,{name:W.name}),description:s(`integrationDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device backed by it ({{topLevelCountLabel}} active). Streams will reconnect automatically.`,{topLevelCountLabel:nt}),confirmLabel:s(`integrationDetail.restart`,`Restart`),triggerVariant:`outline`,confirmVariant:`danger`,disabled:Ge.isPending,action:()=>Ge.mutateAsync({addonId:W.addonId})}),!Ce&&U&&i(N,{label:s(`integrations.delete`,{defaultValue:`Delete`}),icon:m,title:s(`integrations.deleteTitle`,{defaultValue:`Delete integration?`}),description:s(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:W.name,count:nt}),confirmLabel:s(`integrations.confirmDelete`,{defaultValue:`Delete integration`}),triggerVariant:`outline`,confirmVariant:`danger`,className:`border-danger bg-danger/10 text-danger hover:bg-danger hover:text-background`,disabled:We.isPending,action:()=>We.mutateAsync({id:U})})]})]}),V.length>1&&i(`div`,{className:`max-w-sm`,children:i(Se,{mode:`single`,singleDisplay:`field`,label:s(`integrationDetail.instances`,`Integration`),options:ce,value:U,onChange:se,testId:`integration-instance-picker`,optionTestIdPrefix:`integration-instance`})}),Pe&&i(Ue,{nodeId:null,addonIds:Le,level:`global`,surface:`integration`,title:s(`integrations.settings`,{defaultValue:`Settings`})}),i(ue,{context:`integration-detail`,devices:$,trpc:_.trpcClient,integrationOf:Qe,forceIntegrationId:U,urlScope:`root`,lsKey:`integration-detail:${W.addonId}`,resolveIntegrationIcon:Re,resolveParent:Ze,onNavigate:$e,batchActions:{remove:Ke.mutate,disable:qe.mutate,enable:Je.mutate},...Ce?{}:{onDeleteDevice:e=>Ke.mutate({deviceId:e.id})}}),v&&U&&Te&&!S&&i(et,{onClose:()=>x(!1),onCommissioned:()=>w(!0)}),v&&U&&J===`device-adoption`&&(!Te||S)&&i(ct,{addonId:W.addonId,integrationId:U,onClose:()=>{x(!1),w(!1)}}),v&&U&&J===`device-provider`&&i(Ye,{open:v,integrationId:U,addonId:W.addonId,onClose:()=>x(!1)}),E&&W&&i(He,{open:E,scope:{addonId:W.addonId,label:W.name},onClose:()=>O(!1),onSetupIntegration:ee}),te&&U&&J!==null&&Z!==null&&i(ht,{integrationId:U,addonId:W.addonId,name:W.name,kind:J,mode:Z,brokerKind:we,canTest:De,trpc:_.trpcClient,onClose:()=>A(!1)}),ne&&i(Oe,{open:!0,onOpenChange:e=>!e&&re(!1),children:e(X,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[i(Ee,{className:`mb-0`,children:e(me,{className:`flex items-center gap-2 min-w-0`,children:[i(D,{className:`h-4 w-4 text-primary shrink-0`}),i(`span`,{className:`truncate`,children:W.name}),e(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate font-normal`,children:[W.addonId,U?` · ${U}`:``]})]})}),i(ge,{className:`min-h-0 overflow-hidden p-0`,children:i(q,{addonId:W.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})})]}):e(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[i(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:i(k,{className:`h-6 w-6 text-foreground-subtle`})}),e(`div`,{className:`space-y-1 max-w-sm`,children:[i(`h2`,{className:`text-sm font-semibold text-foreground`,children:s(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:s(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:t})})]}),e(`button`,{onClick:()=>d(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[i(C,{className:`h-3 w-3`}),s(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}function bt({addonId:e}){let t=ke(e),[n,r]=o(!1);return!t||n?null:i(`img`,{src:t,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:()=>r(!0)})}export{_t as IntegrationDetailPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as e,J as t,K as n,S as r,V as i,Y as a,et as o,k as s,o as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Dn as d,Gi as f,In as p,Ln as m,V as h,gr as g,pr as _,tn as v,yn as y,zt as b}from"./player-overlays-DgedyCX9.js";import{si as x}from"./client-F3l12jEi.js";import{t as S}from"./settings-2-D6sp_FTm.js";import{Cn as C,Ji as ee,Nr as te,On as w,Or as T,Pr as E,cn as D,di as O,ea as k,ri as A,sn as ne}from"./src-B0EA_4Ed.js";import{t as j}from"./useTranslation-BJr-n0es.js";import{c as re,d as M,mr as N,o as P,pr as F,r as I,s as L,u as R,yr as z}from"./index-CQ7TjSgs.js";import{t as B}from"./AdminPage-CYSYefaL.js";import{t as V}from"./NodeAddonsSettingsPanel-Do_I93Mx.js";import{t as H}from"./AddonAssetIcon-Bk09xHqf.js";o();function U(e){let{ids:t,answered:r,legacyGroupParam:i=null,groupFirst:a}=e,[o]=z(),s=o.get(P),c=i===null?null:o.get(i),l=o.get(L),u=n(()=>R({ids:t,requested:s,answered:r,legacyGroup:c,...a===void 0?{}:{groupFirst:a}}),[t,s,r,c,a]),d=n(()=>(e,t)=>`?${M(o,e,i,t??null).toString()}`,[o,i]);return{...u,requestedSection:l,hrefFor:d}}var W=[[[`addons`,`listCapabilityProviders`]],[[`addons`,`list`]]],G=`text-[10px]`;function K({isActive:e}){let{t}=j();return r(O,{variant:e?`success`:`default`,className:G,children:e?t(`integrationHub.addonControls.enabled`,`Enabled`):t(`integrationHub.addonControls.disabled`,`Disabled`)})}function q({capName:t,addonId:n,isActive:i}){let{t:a}=j(),o=c(),s=k({onSuccess:()=>{for(let e of W)o.invalidateQueries({queryKey:e})}}),l=s.isPending;return e(A,{size:`sm`,variant:i?`secondary`:`primary`,disabled:l,onClick:()=>s.mutate({capName:t,addonId:n,enabled:!i}),children:[l?r(_,{className:`h-3 w-3 animate-spin`}):r(i?v:m,{className:`h-3 w-3`}),i?a(`common.disable`,`Disable`):a(`common.enable`,`Enable`)]})}function ie({addonId:e,displayName:t}){let{t:n}=j(),i=c(),a=ee({onSuccess:()=>{for(let e of W)i.invalidateQueries({queryKey:e})}});return r(C,{label:n(`integrationHub.addonControls.restart`,`Restart`),icon:d,size:`sm`,title:n(`integrationHub.addonControls.restart2`,`Restart "{{displayName}}"?`,{displayName:t}),description:n(`integrationHub.addonControls.restartingTheAddonBouncesIts`,`Restarting the addon bounces its subprocess — the provider will briefly drop and reconnect automatically.`),confirmLabel:n(`integrationHub.addonControls.restart`,`Restart`),triggerVariant:`ghost`,confirmVariant:`danger`,disabled:a.isPending,action:()=>a.mutateAsync({addonId:e})})}o();var J=600,Y=s(null);function X({id:n,title:i,icon:a,actions:o,framed:s=!1,children:c}){let{t:d}=j(),f=u(Y),p=t(null),m=`integration-section-${n}`;ae(p,f,n);let _=e(l,{children:[f===null?null:r(N,{to:f.sectionHref(n),"aria-label":d(`integrationHub.integrationSection.linkTo`,`Link to {{title}}`,{title:i}),title:d(`integrationHub.integrationSection.linkTo`,`Link to {{title}}`,{title:i}),className:`rounded p-0.5 text-foreground-subtle/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,children:r(g,{className:`h-3 w-3`,"aria-hidden":!0})}),o]});return s?r(`div`,{ref:p,className:`scroll-mt-4`,children:r(w,{headingId:m,title:i,icon:a,actions:_,children:c})}):e(`section`,{ref:p,"aria-labelledby":m,className:`scroll-mt-4 space-y-2`,children:[e(`header`,{className:`flex min-h-7 flex-wrap items-center gap-2 px-0.5`,children:[a!==void 0&&r(a,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),r(`h2`,{id:m,className:`${h} min-w-0 flex-1`,children:i}),_]}),c]})}function ae(e,t,n){let r=t?.requestedSection===n,a=t?.integrationId;i(()=>{if(!r)return;let t=()=>e.current?.scrollIntoView?.({block:`start`});t();let n=!1,i=()=>{n=!0},a=[`wheel`,`touchmove`,`keydown`];for(let e of a)window.addEventListener(e,i,{once:!0,passive:!0});let o=window.setTimeout(()=>{n||t()},J);return()=>{window.clearTimeout(o);for(let e of a)window.removeEventListener(e,i)}},[r,a,e])}o();var Z=`max-h-72`;function oe({addonId:t,displayName:n,capName:i,isActive:a,badges:o,primaryAction:s,error:c=null,lead:l,panels:u=[],settingsContent:d}){let{t:f}=j(),p=u.filter(e=>e.placement!==`end`),m=u.filter(e=>e.placement===`end`);return e(`div`,{className:`flex flex-col gap-4`,children:[r(se,{addonId:t,displayName:n,capName:i,isActive:a,badges:o,primaryAction:s}),c!==null&&r(te,{message:c}),l,r(Q,{panels:p}),r(X,{id:re,title:f(`integrationHub.addonIntegrationBody.settings`,`Settings`),icon:S,children:d===void 0?r(V,{nodeId:`hub`,addonIds:[t],level:`global`,capability:i}):d}),r(le,{addonId:t}),r(Q,{panels:m})]})}function Q({panels:e}){return r(l,{children:e.map(e=>r(X,{id:e.id,title:e.title,icon:e.icon,children:e.content},e.id))})}function se({addonId:t,displayName:n,capName:i,isActive:a,badges:o,primaryAction:s}){return e(`div`,{className:`flex flex-wrap items-center justify-between gap-2 rounded-lg border border-border bg-surface px-2 py-1.5 sm:px-3`,"data-testid":`integration-status-strip`,children:[e(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[r(K,{isActive:a}),o,r(`span`,{className:`break-all font-mono text-[11px] text-foreground-subtle`,children:t})]}),e(`div`,{className:`flex flex-wrap items-center justify-end gap-1`,children:[s,r(q,{capName:i,addonId:t,isActive:a}),r(ie,{addonId:t,displayName:n})]})]})}var ce=[{kind:`logs`,labelKey:`common.logs`,icon:y},{kind:`events`,labelKey:`common.events`,icon:f}];function le({addonId:t}){let{t:n}=j(),[i,o]=a(`logs`);return r(X,{id:I,title:n(`integrationHub.addonIntegrationBody.activity`,`Activity`),framed:!0,actions:r(`div`,{role:`group`,"aria-label":n(`integrationHub.addonIntegrationBody.activityStream`,`Activity stream`),className:`flex items-center gap-1`,children:ce.map(({kind:t,labelKey:a,icon:s})=>e(`button`,{type:`button`,"aria-pressed":i===t,onClick:()=>o(t),className:`inline-flex items-center gap-1 rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${i===t?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[r(s,{className:`h-3 w-3`,"aria-hidden":!0}),n(a)]},t))}),children:i===`logs`?r(D,{addonId:t,maxHeight:Z,showFilters:!1}):r(ne,{addonId:t,category:`addon.*`,maxHeight:Z})})}var ue=`inline-flex min-w-0 max-w-full items-center gap-1.5 rounded-full border py-1 pl-1 pr-2.5 text-xs transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,de=`border-primary bg-primary/10 text-primary font-medium`,fe=`border-border bg-surface text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,pe={ok:`bg-success`,off:`bg-foreground-subtle/60`,error:`bg-danger`,unknown:`border border-foreground-subtle bg-transparent`};function $({label:t,groups:n,selectedId:i,hrefFor:a}){let o=n.length>1;return r(`nav`,{"aria-label":t,className:o?`flex flex-col gap-2 sm:grid sm:grid-cols-[max-content_minmax(0,1fr)] sm:items-start sm:gap-x-3`:`flex flex-col`,children:n.map(t=>e(`div`,{role:`group`,"aria-label":t.label,className:o?`flex min-w-0 flex-col gap-1 sm:col-span-2 sm:grid sm:grid-cols-subgrid sm:items-start`:`min-w-0`,children:[o&&r(`span`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle sm:pt-2`,children:t.label}),e(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[t.entries.map(e=>r(me,{entry:e,current:e.id===i,href:a(e.id)},e.id)),t.install&&e(N,{to:x(t.install.capability),className:`inline-flex min-w-0 max-w-full items-center gap-1.5 rounded-full border py-1 pl-1 pr-2.5 text-xs transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 border-dashed border-border pl-2 text-foreground-subtle hover:border-primary/50 hover:text-foreground`,children:[r(p,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),r(`span`,{className:`truncate`,children:t.install.label})]})]})]},t.id))})}function me({entry:t,current:n,href:i}){let a=t.state===`ok`;return e(N,{to:i,"aria-current":n?`true`:void 0,className:`${ue} ${n?de:fe}`,"data-testid":`integration-pill-${t.id}`,children:[r(H,{addonId:t.id,fallback:t.fallbackIcon,tileClassName:``,size:`sm`}),r(`span`,{className:`truncate`,children:t.name}),t.showState!==!1&&r(he,{entry:t,quiet:a})]})}function he({entry:t,quiet:n}){return e(l,{children:[r(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${pe[t.state]}`,"aria-hidden":!0}),r(`span`,{className:n?`sr-only`:`shrink-0 text-[10px] font-normal text-foreground-subtle`,children:t.stateLabel})]})}o();function ge({icon:t,title:i,subtitle:a,groups:o,isLoading:s,emptyTitle:c,emptyDescription:u,legacyGroupParam:d,trailing:f,embedded:p=!1}){let{t:m}=j(),h=n(()=>o.flatMap(e=>e.entries),[o]),g=n(()=>h.map(e=>e.id),[h]),_=n(()=>{let e={};for(let t of o){let n=t.entries[0];n!==void 0&&(e[t.id]=n.id)}return e},[o]),v=U({ids:g,answered:!s,legacyGroupParam:d??null,groupFirst:_}),y=h.find(e=>e.id===v.selectedId)??null,b=n(()=>y===null?null:{integrationId:y.id,requestedSection:v.requestedSection,sectionHref:e=>v.hrefFor(y.id,e)},[y,v]),x=s?null:r($,{label:m(`integrationHub.integrationHub.integrations`,`{{title}} integrations`,{title:i}),groups:o,selectedId:v.selectedId,hrefFor:e=>v.hrefFor(e)}),S=s?r(T,{children:r(`div`,{className:`p-6 text-sm text-foreground-subtle`,children:m(`common.loading`,`Loading…`)})}):e(l,{children:[v.staleId!==null&&r(ve,{staleId:v.staleId,shownName:y?.name??null}),y!==null&&b!==null?r(Y.Provider,{value:b,children:r(`div`,{role:`region`,"aria-label":y.name,"data-testid":`integration-body`,children:y.render()},y.id)}):r(_e,{groups:o,title:c,description:u}),f]});return p?e(`div`,{className:`space-y-3`,"data-testid":`integration-hub-embedded`,children:[x,S]}):r(B,{icon:t,title:i,subtitle:a,nav:x,children:S})}function _e({groups:t,title:n,description:i}){let a=t.find(e=>e.install!==void 0)?.install;return r(T,{children:r(E,{title:n,description:i,action:a?r(N,{to:x(a.capability),children:e(A,{variant:`primary`,size:`sm`,children:[r(p,{className:`mr-1 h-3.5 w-3.5`}),a.label]})}):void 0})})}function ve({staleId:t,shownName:n}){let{t:i}=j();return e(`div`,{role:`status`,className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-3 py-2 text-[11px] text-foreground-subtle`,children:[r(b,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),e(`span`,{children:[r(F,{i18nKey:`integrationHub.staleIntegration.notice`,values:{id:t},components:{mono:r(`span`,{className:`font-mono text-foreground`})}}),n!==null&&e(l,{children:[` `,r(F,{i18nKey:`integrationHub.staleIntegration.showing`,values:{name:n},components:{b:r(`span`,{className:`font-medium text-foreground`})}})]})]})]})}export{U as i,oe as n,G as r,ge as t};
|
|
1
|
+
import{C as e,J as t,K as n,S as r,V as i,Y as a,et as o,k as s,o as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Dn as d,Gi as f,In as p,Ln as m,V as h,gr as g,pr as _,tn as v,yn as y,zt as b}from"./player-overlays-Cw_gjG75.js";import{si as x}from"./client-r4i0EpF6.js";import{t as S}from"./settings-2-wlw_-rxi.js";import{Cn as C,Ji as ee,Nr as te,On as w,Or as T,Pr as E,cn as D,di as O,ea as k,ri as A,sn as ne}from"./src-nnHXOip7.js";import{t as j}from"./useTranslation-BJr-n0es.js";import{br as re,c as M,d as N,hr as P,mr as F,o as I,r as L,s as R,u as z}from"./index-Ohn-2iW_.js";import{t as B}from"./AdminPage-7avIuDBh.js";import{t as V}from"./NodeAddonsSettingsPanel-JIXh-CLX.js";import{t as H}from"./AddonAssetIcon-BZ0hQcho.js";o();function U(e){let{ids:t,answered:r,legacyGroupParam:i=null,groupFirst:a}=e,[o]=re(),s=o.get(I),c=i===null?null:o.get(i),l=o.get(R),u=n(()=>z({ids:t,requested:s,answered:r,legacyGroup:c,...a===void 0?{}:{groupFirst:a}}),[t,s,r,c,a]),d=n(()=>(e,t)=>`?${N(o,e,i,t??null).toString()}`,[o,i]);return{...u,requestedSection:l,hrefFor:d}}var W=[[[`addons`,`listCapabilityProviders`]],[[`addons`,`list`]]],G=`text-[10px]`;function K({isActive:e}){let{t}=j();return r(O,{variant:e?`success`:`default`,className:G,children:e?t(`integrationHub.addonControls.enabled`,`Enabled`):t(`integrationHub.addonControls.disabled`,`Disabled`)})}function q({capName:t,addonId:n,isActive:i}){let{t:a}=j(),o=c(),s=k({onSuccess:()=>{for(let e of W)o.invalidateQueries({queryKey:e})}}),l=s.isPending;return e(A,{size:`sm`,variant:i?`secondary`:`primary`,disabled:l,onClick:()=>s.mutate({capName:t,addonId:n,enabled:!i}),children:[l?r(_,{className:`h-3 w-3 animate-spin`}):r(i?v:m,{className:`h-3 w-3`}),i?a(`common.disable`,`Disable`):a(`common.enable`,`Enable`)]})}function ie({addonId:e,displayName:t}){let{t:n}=j(),i=c(),a=ee({onSuccess:()=>{for(let e of W)i.invalidateQueries({queryKey:e})}});return r(C,{label:n(`integrationHub.addonControls.restart`,`Restart`),icon:d,size:`sm`,title:n(`integrationHub.addonControls.restart2`,`Restart "{{displayName}}"?`,{displayName:t}),description:n(`integrationHub.addonControls.restartingTheAddonBouncesIts`,`Restarting the addon bounces its subprocess — the provider will briefly drop and reconnect automatically.`),confirmLabel:n(`integrationHub.addonControls.restart`,`Restart`),triggerVariant:`ghost`,confirmVariant:`danger`,disabled:a.isPending,action:()=>a.mutateAsync({addonId:e})})}o();var J=600,Y=s(null);function X({id:n,title:i,icon:a,actions:o,framed:s=!1,children:c}){let{t:d}=j(),f=u(Y),p=t(null),m=`integration-section-${n}`;ae(p,f,n);let _=e(l,{children:[f===null?null:r(P,{to:f.sectionHref(n),"aria-label":d(`integrationHub.integrationSection.linkTo`,`Link to {{title}}`,{title:i}),title:d(`integrationHub.integrationSection.linkTo`,`Link to {{title}}`,{title:i}),className:`rounded p-0.5 text-foreground-subtle/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,children:r(g,{className:`h-3 w-3`,"aria-hidden":!0})}),o]});return s?r(`div`,{ref:p,className:`scroll-mt-4`,children:r(w,{headingId:m,title:i,icon:a,actions:_,children:c})}):e(`section`,{ref:p,"aria-labelledby":m,className:`scroll-mt-4 space-y-2`,children:[e(`header`,{className:`flex min-h-7 flex-wrap items-center gap-2 px-0.5`,children:[a!==void 0&&r(a,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),r(`h2`,{id:m,className:`${h} min-w-0 flex-1`,children:i}),_]}),c]})}function ae(e,t,n){let r=t?.requestedSection===n,a=t?.integrationId;i(()=>{if(!r)return;let t=()=>e.current?.scrollIntoView?.({block:`start`});t();let n=!1,i=()=>{n=!0},a=[`wheel`,`touchmove`,`keydown`];for(let e of a)window.addEventListener(e,i,{once:!0,passive:!0});let o=window.setTimeout(()=>{n||t()},J);return()=>{window.clearTimeout(o);for(let e of a)window.removeEventListener(e,i)}},[r,a,e])}o();var Z=`max-h-72`;function oe({addonId:t,displayName:n,capName:i,isActive:a,badges:o,primaryAction:s,error:c=null,lead:l,panels:u=[],settingsContent:d}){let{t:f}=j(),p=u.filter(e=>e.placement!==`end`),m=u.filter(e=>e.placement===`end`);return e(`div`,{className:`flex flex-col gap-4`,children:[r(se,{addonId:t,displayName:n,capName:i,isActive:a,badges:o,primaryAction:s}),c!==null&&r(te,{message:c}),l,r(Q,{panels:p}),r(X,{id:M,title:f(`integrationHub.addonIntegrationBody.settings`,`Settings`),icon:S,children:d===void 0?r(V,{nodeId:`hub`,addonIds:[t],level:`global`,capability:i}):d}),r(le,{addonId:t}),r(Q,{panels:m})]})}function Q({panels:e}){return r(l,{children:e.map(e=>r(X,{id:e.id,title:e.title,icon:e.icon,children:e.content},e.id))})}function se({addonId:t,displayName:n,capName:i,isActive:a,badges:o,primaryAction:s}){return e(`div`,{className:`flex flex-wrap items-center justify-between gap-2 rounded-lg border border-border bg-surface px-2 py-1.5 sm:px-3`,"data-testid":`integration-status-strip`,children:[e(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[r(K,{isActive:a}),o,r(`span`,{className:`break-all font-mono text-[11px] text-foreground-subtle`,children:t})]}),e(`div`,{className:`flex flex-wrap items-center justify-end gap-1`,children:[s,r(q,{capName:i,addonId:t,isActive:a}),r(ie,{addonId:t,displayName:n})]})]})}var ce=[{kind:`logs`,labelKey:`common.logs`,icon:y},{kind:`events`,labelKey:`common.events`,icon:f}];function le({addonId:t}){let{t:n}=j(),[i,o]=a(`logs`);return r(X,{id:L,title:n(`integrationHub.addonIntegrationBody.activity`,`Activity`),framed:!0,actions:r(`div`,{role:`group`,"aria-label":n(`integrationHub.addonIntegrationBody.activityStream`,`Activity stream`),className:`flex items-center gap-1`,children:ce.map(({kind:t,labelKey:a,icon:s})=>e(`button`,{type:`button`,"aria-pressed":i===t,onClick:()=>o(t),className:`inline-flex items-center gap-1 rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${i===t?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[r(s,{className:`h-3 w-3`,"aria-hidden":!0}),n(a)]},t))}),children:i===`logs`?r(D,{addonId:t,maxHeight:Z,showFilters:!1}):r(ne,{addonId:t,category:`addon.*`,maxHeight:Z})})}var ue=`inline-flex min-w-0 max-w-full items-center gap-1.5 rounded-full border py-1 pl-1 pr-2.5 text-xs transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,de=`border-primary bg-primary/10 text-primary font-medium`,fe=`border-border bg-surface text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,pe={ok:`bg-success`,off:`bg-foreground-subtle/60`,error:`bg-danger`,unknown:`border border-foreground-subtle bg-transparent`};function $({label:t,groups:n,selectedId:i,hrefFor:a}){let o=n.length>1;return r(`nav`,{"aria-label":t,className:o?`flex flex-col gap-2 sm:grid sm:grid-cols-[max-content_minmax(0,1fr)] sm:items-start sm:gap-x-3`:`flex flex-col`,children:n.map(t=>e(`div`,{role:`group`,"aria-label":t.label,className:o?`flex min-w-0 flex-col gap-1 sm:col-span-2 sm:grid sm:grid-cols-subgrid sm:items-start`:`min-w-0`,children:[o&&r(`span`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle sm:pt-2`,children:t.label}),e(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[t.entries.map(e=>r(me,{entry:e,current:e.id===i,href:a(e.id)},e.id)),t.install&&e(P,{to:x(t.install.capability),className:`inline-flex min-w-0 max-w-full items-center gap-1.5 rounded-full border py-1 pl-1 pr-2.5 text-xs transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 border-dashed border-border pl-2 text-foreground-subtle hover:border-primary/50 hover:text-foreground`,children:[r(p,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),r(`span`,{className:`truncate`,children:t.install.label})]})]})]},t.id))})}function me({entry:t,current:n,href:i}){let a=t.state===`ok`;return e(P,{to:i,"aria-current":n?`true`:void 0,className:`${ue} ${n?de:fe}`,"data-testid":`integration-pill-${t.id}`,children:[r(H,{addonId:t.id,fallback:t.fallbackIcon,tileClassName:``,size:`sm`}),r(`span`,{className:`truncate`,children:t.name}),t.showState!==!1&&r(he,{entry:t,quiet:a})]})}function he({entry:t,quiet:n}){return e(l,{children:[r(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${pe[t.state]}`,"aria-hidden":!0}),r(`span`,{className:n?`sr-only`:`shrink-0 text-[10px] font-normal text-foreground-subtle`,children:t.stateLabel})]})}o();function ge({icon:t,title:i,subtitle:a,groups:o,isLoading:s,emptyTitle:c,emptyDescription:u,legacyGroupParam:d,trailing:f,embedded:p=!1}){let{t:m}=j(),h=n(()=>o.flatMap(e=>e.entries),[o]),g=n(()=>h.map(e=>e.id),[h]),_=n(()=>{let e={};for(let t of o){let n=t.entries[0];n!==void 0&&(e[t.id]=n.id)}return e},[o]),v=U({ids:g,answered:!s,legacyGroupParam:d??null,groupFirst:_}),y=h.find(e=>e.id===v.selectedId)??null,b=n(()=>y===null?null:{integrationId:y.id,requestedSection:v.requestedSection,sectionHref:e=>v.hrefFor(y.id,e)},[y,v]),x=s?null:r($,{label:m(`integrationHub.integrationHub.integrations`,`{{title}} integrations`,{title:i}),groups:o,selectedId:v.selectedId,hrefFor:e=>v.hrefFor(e)}),S=s?r(T,{children:r(`div`,{className:`p-6 text-sm text-foreground-subtle`,children:m(`common.loading`,`Loading…`)})}):e(l,{children:[v.staleId!==null&&r(ve,{staleId:v.staleId,shownName:y?.name??null}),y!==null&&b!==null?r(Y.Provider,{value:b,children:r(`div`,{role:`region`,"aria-label":y.name,"data-testid":`integration-body`,children:y.render()},y.id)}):r(_e,{groups:o,title:c,description:u}),f]});return p?e(`div`,{className:`space-y-3`,"data-testid":`integration-hub-embedded`,children:[x,S]}):r(B,{icon:t,title:i,subtitle:a,nav:x,children:S})}function _e({groups:t,title:n,description:i}){let a=t.find(e=>e.install!==void 0)?.install;return r(T,{children:r(E,{title:n,description:i,action:a?r(P,{to:x(a.capability),children:e(A,{variant:`primary`,size:`sm`,children:[r(p,{className:`mr-1 h-3.5 w-3.5`}),a.label]})}):void 0})})}function ve({staleId:t,shownName:n}){let{t:i}=j();return e(`div`,{role:`status`,className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-3 py-2 text-[11px] text-foreground-subtle`,children:[r(b,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),e(`span`,{children:[r(F,{i18nKey:`integrationHub.staleIntegration.notice`,values:{id:t},components:{mono:r(`span`,{className:`font-mono text-foreground`})}}),n!==null&&e(l,{children:[` `,r(F,{i18nKey:`integrationHub.staleIntegration.showing`,values:{name:n},components:{b:r(`span`,{className:`font-medium text-foreground`})}})]})]})]})}export{U as i,oe as n,G as r,ge as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,et as s,o as c,x as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Ai as u,An as d,Di as f,Dn as p,Fi as m,Fn as h,In as g,V as _,dt as v,gn as ee,ki as y,pr as te,vn as b,yr as ne}from"./player-overlays-Cw_gjG75.js";import{t as x}from"./table-2-Sw__YAPa.js";import{Eo as re,Fo as S,Ft as ie,Hi as C,Kd as ae,L as w,Lt as oe,Ms as se,Nr as ce,Ps as le,Pt as T,Rd as ue,Tr as de,br as fe,fo as pe,ki as E,ks as me,r as he,ri as ge,ut as D,wo as _e,wr as ve,xr as ye,yr as O}from"./src-nnHXOip7.js";import{t as k}from"./i18n-BE1bPZOs.js";import{t as A}from"./useTranslation-BJr-n0es.js";import{C as j,_r as be,br as xe,fr as M,vr as Se}from"./index-Ohn-2iW_.js";import{t as Ce}from"./AdminPage-7avIuDBh.js";import"./useEventInvalidation-B_Zjyqyk.js";import{t as we}from"./device-integration-icon-Cf2JTj5q.js";import{i as Te,n as Ee,r as N,t as De}from"./ScanNetworkModal-DL-mWRtG.js";import{t as P}from"./framework-packages-B7oma9J4.js";s();function F(e){return e.some(e=>e.status===`running`)?`running`:e.some(e=>e.status===`stopped`)?`stopped`:`disabled`}function I(e,t){let n=new Map;for(let t of e){let e=n.get(t.addonId);e===void 0?n.set(t.addonId,[t]):e.push(t)}return[...n.entries()].map(([e,n])=>{let r=t.get(e)?.trim()??``;return{addonId:e,name:r.length>0?r:n[0]?.name??e,instances:n,instanceCount:n.length,deviceCount:n.reduce((e,t)=>e+t.deviceCount,0),status:F(n)}})}function L(e){return e.integrationSection===void 0?P(e.packageName)?`system`:`providers`:e.integrationSection}function R(e){let t=new Set;for(let n of e??[])L(n.manifest)===`system`&&t.add(n.manifest.id);return t}function z(e,t){return{providers:e.filter(e=>!t.has(e.addonId)),system:e.filter(e=>t.has(e.addonId))}}function B(e,t){return[...e].sort((e,n)=>e.name.localeCompare(n.name,t,{sensitivity:`base`}))}function V({kind:t,children:n}){let{t:r}=A(),a=`integrations-section-${t}`;return e(`section`,{"aria-labelledby":a,"data-testid":a,className:`min-w-0 space-y-2`,children:[i(`h2`,{id:a,className:_,children:t===`providers`?r(`integrations.sections.providers`,`Providers`):r(`integrations.sections.system`,`System`)}),n]})}function H({children:e}){return i(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2 sm:gap-3 lg:grid-cols-3`,children:e})}function U({addonId:t,name:n,openLabel:r,onOpen:a,body:o,footer:s,disabled:c=!1,testId:l,buttonTestId:u}){return e(`article`,{"data-testid":l,className:`relative flex min-w-0 items-stretch gap-3 overflow-x-clip rounded-lg border border-border bg-surface p-3`,children:[i(ge,{type:`button`,variant:`ghost`,"aria-label":r,disabled:c,"data-testid":u,onClick:a,className:`absolute inset-0 z-0 h-auto w-auto rounded-lg p-0 focus-visible:ring-2 focus-visible:ring-primary`}),i(`div`,{className:`pointer-events-none relative z-10 flex w-20 shrink-0 items-center justify-center`,children:i(M,{type:t,size:`xl`})}),e(`div`,{className:`pointer-events-none relative z-10 grid min-w-0 flex-1 grid-rows-[1fr_auto_1fr] gap-1`,children:[i(`p`,{className:`min-w-0 self-start truncate text-sm font-semibold text-foreground`,children:n}),o,i(`div`,{className:`self-end justify-self-start`,children:s})]})]})}function Oe({providers:t,system:r,onOpen:a,searchPlaceholder:s,emptyLabel:c}){let[l,u]=o(``),d=n(()=>{let e=l.trim().toLowerCase(),n=t=>e.length===0||`${t.name} ${t.addonId} ${t.instances.map(e=>e.name).join(` `)}`.toLowerCase().includes(e);return{providers:t.filter(n),system:r.filter(n)}},[l,t,r]),f=d.providers.length===0&&d.system.length===0;return e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`relative`,children:[i(b,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-foreground-subtle`,"aria-hidden":!0}),i(ue,{type:`search`,value:l,onChange:e=>u(e.target.value),placeholder:s,"aria-label":s,className:`pl-8`})]}),f?i(`p`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:c}):e(`div`,{className:`space-y-4`,children:[d.providers.length>0&&i(V,{kind:`providers`,children:i(W,{groups:d.providers,onOpen:a})}),d.system.length>0&&i(V,{kind:`system`,children:i(W,{groups:d.system,onOpen:a})})]})]})}function W({groups:e,onOpen:t}){let{t:r,i18n:a}=A();return i(H,{children:n(()=>B(e,a.language),[e,a.language]).map(e=>i(U,{testId:`integration-card-${e.addonId}`,addonId:e.addonId,name:e.name,openLabel:r(`integrations.openNamed`,{name:e.name,defaultValue:`Open {{name}}`}),onOpen:()=>t(e),body:i(`p`,{className:`text-xs text-foreground-muted`,children:r(`integrations.addonCard.summary`,{integrations:r(`integrations.addonCard.integrationCount`,{count:e.instanceCount}),devices:r(`integrations.integrationColumns.deviceCount`,{count:e.deviceCount}),defaultValue:`{{integrations}} · {{devices}}`})}),footer:i(D,{status:e.status,className:`shrink-0`})},e.addonId))})}s();var G=`camstack.admin.integrations.view`;function K(e){return e===`table`||e===`grid`}function q(){try{return typeof window>`u`?null:window.localStorage}catch{return null}}function J(e=q()){if(e===null)return`table`;try{let t=e.getItem(G);return K(t)?t:`table`}catch{return`table`}}function Y(e,t=q()){if(t!==null)try{t.setItem(G,e)}catch{}}function ke(){let[e,t]=o(()=>J());return[e,r(e=>{t(e),Y(e)},[])]}s();function Ae(e=!0){a(()=>{if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=t}},[e])}s();function je(e,t){let[n,r]=o(!1);return a(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}s();function Me({providerId:t,onImport:n,onSkip:r}){let{t:s}=A(),[c,l]=o(new Set),d=_e(),f=d.data,p=d.isPending||!d.data&&!d.isError;a(()=>{t&&(d.isPending||d.data||d.mutate({addonId:t}))},[t,d]);function h(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(p)return e(`div`,{className:`flex flex-col items-center py-12`,children:[i(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),i(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:s(`integrations.searchingDevices`)})]});let g=f??[];return e(`div`,{className:`space-y-4`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:g.length>0?s(`integrations.foundDevices`,{count:g.length}):s(`integrations.noDevicesFound`)}),g.length>0&&i(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:g.map(t=>{let n=t.stableId,r=t.suggestedName??n,a=c.has(n),o=t.alreadyOnboarded===!0;return e(`button`,{onClick:()=>{o||h(n)},disabled:o,title:o?s(`integrations.alreadyAddedHint`,{defaultValue:`Already added as "{{name}}" — re-adding would overwrite its settings.`,name:t.onboardedName??r}):void 0,className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${o?`border-border bg-surface opacity-60 cursor-not-allowed`:a?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[i(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${a&&!o?`border-primary bg-primary`:`border-border`}`,children:a&&!o&&i(u,{className:`h-3 w-3 text-primary-foreground`})}),i(m,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),i(`span`,{className:`text-xs font-medium text-foreground truncate`,children:r}),o&&i(`span`,{className:`ml-auto flex-shrink-0 rounded bg-surface-muted px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:s(`integrations.alreadyAdded`,{defaultValue:`Already added`})})]},n)})}),e(`div`,{className:`flex items-center justify-between pt-2`,children:[i(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:s(`integrations.skip`)}),g.length>0&&e(`button`,{onClick:()=>n(Array.from(c)),disabled:c.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[s(`integrations.importSelected`),` (`,c.size,`)`]})]})]})}var Ne=`(hover: none) and (pointer: coarse)`;function X(){if(typeof window>`u`||typeof window.matchMedia!=`function`)return!0;try{return!window.matchMedia(Ne).matches}catch{return!0}}s();function Pe({onSelect:r,onClose:s,pendingAddonId:c=null}){let{t:l,i18n:u}=A(),d=Se(),[f,p]=o(``),m=t(null),{data:h,isLoading:g}=se();a(()=>{g||!X()||m.current?.focus()},[g]);let _=n(()=>{let e=h??[],t=f.trim().toLowerCase();return t.length===0?e:e.filter(e=>`${e.name} ${e.description??``} ${e.addonId}`.toLowerCase().includes(t))},[h,f]),{data:v}=C(void 0),y=n(()=>{let e=z(_,R(v));return{providers:B(e.providers,u.language),system:B(e.system,u.language)}},[_,v,u.language]);if(g)return i(`div`,{className:`grid grid-cols-1 gap-2 p-2 sm:grid-cols-2 lg:grid-cols-3`,children:[1,2,3,4].map(e=>i(`div`,{className:`h-24 rounded-lg bg-surface animate-pulse`},e))});let ne=c!==null,x=t=>i(H,{children:t.map(t=>{let n=t.instanceMode===`unique`&&t.existingInstances.length>0,a=c===t.addonId;return i(U,{testId:`provider-card-${t.addonId}`,buttonTestId:`provider-pick-${t.addonId}`,addonId:t.addonId,name:t.name,openLabel:t.name,disabled:ne,onOpen:()=>{if(n){let e=t.existingInstances[0].id;s(),d(j(t.addonId,e))}else r(t.addonId,t.instanceMode,t.discoveryMode,t.name,t.kind,t.brokerKind,t.mode,t.canTest)},body:t.description?i(`p`,{className:`line-clamp-2 text-xs text-foreground-muted`,children:t.description}):i(`span`,{}),footer:a?i(te,{className:`h-4 w-4 animate-spin text-primary`}):n?e(`span`,{className:`flex items-center gap-1 text-xs font-medium text-foreground-subtle`,children:[i(ee,{className:`h-3 w-3`}),l(`integrations.manage`)]}):null},t.addonId)})});return e(`div`,{className:`space-y-3`,"data-testid":`provider-picker`,children:[e(`div`,{className:`relative`,children:[i(b,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-foreground-subtle`,"aria-hidden":!0}),i(ue,{ref:m,type:`search`,value:f,onChange:e=>p(e.target.value),placeholder:l(`integrations.searchProviders`,`Search integrations…`),className:`pl-8`,"data-testid":`provider-picker-search`,"aria-label":l(`integrations.searchProviders`,`Search integrations…`)})]}),y.providers.length>0&&i(V,{kind:`providers`,children:x(y.providers)}),y.system.length>0&&i(V,{kind:`system`,children:x(y.system)}),_.length===0&&i(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:(h??[]).length===0?l(`integrations.noProviders`):l(`integrations.noProvidersMatch`,`No integrations match your search.`)})]})}s();function Fe(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 Ie=2e4;function Z({open:t,onClose:r,seed:s=null}){let{t:u}=A(),d=Se(),f=c(),[p,m]=o(`picker`),[h,g]=o(null),[_,v]=o(null),[ee,y]=o(`manual`),[b,ne]=o(null),[x,S]=o(``),[ie,C]=o(null),[ae,w]=o(null),[oe,ce]=o(!1),[le,T]=o({}),[ue,he]=o(``),[ge,D]=o(!1),[k,be]=o(0),[xe,M]=o(``),Ce=re({},{enabled:t&&p===`config`}),we=h!==null&&(Ce.data?.providers??[]).some(e=>e.addonId===h),Ee=s?.config.host,P=s===null?``:`${s.addonId}\0${s.name}\0${typeof Ee==`string`?Ee:``}`;t&&s!==null&&ue!==P&&(he(P),g(s.addonId),S(s.name),T({...s.config}),m(`config`));let F=se(void 0,{enabled:t&&s!==null}),{data:I}=E({addonId:h??``,nodeId:`hub`},{enabled:h!=null}),L=n(()=>I?Fe(I):null,[I]),R=me({onSuccess:()=>f.invalidateQueries({queryKey:[[`integrations`]]})}),z=_e(),B=z.data;a(()=>{if(!t||s===null)return;let e=F.data?.find(e=>e.addonId===s.addonId);e&&(ce(e.canTest),y(e.discoveryMode))},[t,s,F.data]),a(()=>{p!==`discovery`||!_||!h||z.isPending||z.data||z.mutate({addonId:h})},[p,_,h,z]);let V=pe({onSuccess:()=>f.invalidateQueries({queryKey:[[`deviceManager`]]})});function H(e,t,n,r,i,a,o,s){if(!R.isPending){if(g(e),ce(s),y(n),S(r),w(null),R.reset(),o===`broker`){if(!a){w(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}ne(a),m(`broker`);return}if(o===`account`){m(`config`);return}U(e,r)}}async function U(e,t){try{let n=await R.mutateAsync({addonId:e,name:t,settings:{}});r(),q(),d(`${j(e,n.id)}&add=1`)}catch{}}async function Oe(e){if(h)try{let t=await R.mutateAsync({addonId:h,name:e.name,settings:e.config,secretKeys:[...e.secretKeys]});v(t.id),C(t.id),ee===`auto`||ee===`both`?m(`discovery`):K(t.id,{openAdd:!0})}catch{}}async function W(e){if(h)try{let t=await R.mutateAsync({addonId:h,name:x,settings:{brokerId:e}});C(t.id),v(t.id),K(t.id)}catch{}}async function G(e){if(h){for(let t of e){let e=B?.find(e=>e.stableId===t);e&&await V.mutateAsync({addonId:h,candidate:e,...ie===null?{}:{integrationId:ie}})}K()}}function K(e,t){let n=e??_??h;if(r(),q(),n&&h){let e=j(h,n);d(t?.openAdd===!0?`${e}&add=1`:e)}}function q(){m(`picker`),g(null),v(null),y(`manual`),ne(null),S(``),C(null),w(null),R.reset(),ce(!1),T({}),he(``)}function J(){r(),q()}Ae(t);let Y=R.isPending,ke=je(Y,Ie);if(!t)return null;let Ne={picker:u(`integrations.newIntegration`),config:u(`integrations.configureIntegration`),discovery:u(`integrations.importDevices`),broker:u(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},X=Y?h:null,Z=R.error,Le=Y&&!ke;return e(l,{children:[i(O,{open:!0,onOpenChange:e=>{!e&&!Le&&J()},children:e(ye,{width:p===`picker`?`xl`:`lg`,scroll:`body`,onCancel:e=>{Le&&e.preventDefault()},children:[i(ve,{children:i(de,{children:Ne[p]})}),e(fe,{children:[Z&&!Y&&i(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:Z instanceof Error?Z.message:String(Z)}),p===`picker`&&e(l,{children:[ae&&i(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:ae}),i(Pe,{onSelect:H,onClose:J,pendingAddonId:X})]}),p===`config`&&h&&i(N,{addonId:h,configSchema:L??null,canTest:oe,initialName:x.length>0&&Object.keys(le).length>0?x:void 0,initialConfig:{...le},onScan:we?()=>{M(x.length>0?x:h),D(!0)}:void 0,onSave:Oe,onBack:()=>{T({}),m(`picker`)}},`${P.length>0?P:h}:${k}`),p===`broker`&&b&&i(Te,{kind:b,onResolved:e=>{W(e)},onBack:()=>m(`picker`)}),p===`discovery`&&_&&i(Me,{providerId:_,onImport:G,onSkip:K})]}),Y&&e(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-lg bg-background/85 backdrop-blur-sm px-6 text-center`,children:[i(te,{className:`h-6 w-6 animate-spin text-primary`}),i(`p`,{className:`text-xs font-medium text-foreground`,children:u(`integrations.creating`,{defaultValue:`Creating integration…`})}),!ke&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:u(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),ke&&e(l,{children:[i(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:u(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),i(`button`,{onClick:J,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:u(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})}),ge&&h!==null&&i(De,{open:ge,scope:{addonId:h,label:xe},pickMode:`fill`,onClose:()=>D(!1),onSetupIntegration:e=>{S(e.name),T({...e.config}),be(e=>e+1)}})]})}function Le({integration:t,expanded:n,onToggleExpand:r}){let{t:a}=A();return e(`div`,{className:`flex items-center gap-2.5`,children:[i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),r(t.addonId)},"aria-label":n?a(`integrations.integrationColumns.collapse`,`Collapse`):a(`integrations.integrationColumns.expand`,`Expand`),"aria-expanded":n,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:i(n?y:f,{className:`h-3.5 w-3.5`})}),i(M,{type:t.addonId,size:`sm`}),e(`div`,{className:`flex min-w-0 flex-col`,children:[i(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:t.name}),i(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.addonId})]})]})}function Re(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:k.t(`integrations.integrationColumns.integration`,`Integration`),headerClassName:`w-[55%]`,cell:e=>i(Le,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:k.t(`integrations.integrationColumns.devices`,`Devices`),headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>k.t(`integrations.integrationColumns.deviceCount`,{count:e.deviceCount})},{key:`status`,header:k.t(`integrations.integrationColumns.status`,`Status`),headerClassName:`w-[15%]`,cell:e=>i(D,{status:e.status})}]}s();function ze(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var Be=`expand`;function Ve(){let{t}=A(),s=Se(),c=be(),u=v(),[f]=xe(),[m,_]=ke(),[ee,y]=o(!1),[te,b]=o(null),re=r(()=>{b(null),y(!0)},[]),ue=r(()=>{y(!1),b(null)},[]),de=r(e=>{pe(!1),b(e),y(!0)},[]),[fe,pe]=o(!1);a(()=>{let e=Ee(c.state);e!==null&&(b(e),y(!0),s(`/integrations`,{replace:!0,state:null}))},[c.state,s]);let E=f.get(`setup`);a(()=>{E===null||E.length===0||(b({addonId:E,name:E,config:{}}),y(!0))},[E]);let me=r(()=>pe(!0),[]),ge=r(()=>pe(!1),[]);he([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),he([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:D,isLoading:_e,isError:ve,refetch:ye}=le(void 0),{data:O,isLoading:k,isError:M,refetch:Te}=S({projection:`slim`}),N=n(()=>O??[],[O]),P=n(()=>D??[],[D]),F=n(()=>{let e=new Map;for(let t of N)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[N]),L=n(()=>ie(D),[D]),B=n(()=>{let e=new Map;for(let t of oe(N)){let n=L(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[N,L]),H=n(()=>P.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:ze(e),deviceCount:B.get(e.id)??0})),[P,B]),{data:U}=se(),W=n(()=>new Map((U??[]).map(e=>[e.addonId,e.name])),[U]),G=f.get(Be),K=r(e=>{let t=new URLSearchParams(window.location.search);t.get(Be)===e?t.delete(Be):t.set(Be,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),{data:q}=C(void 0),J=n(()=>R(q),[q]),Y=n(()=>z(H,J),[H,J]),Ae=n(()=>z(I(H,W),J),[H,W,J]),je=r(e=>s(j(e.addonId)),[s]),Me=r(e=>s(j(e.addonId,e.id)),[s]),Ne=r(e=>F.get(e)??null,[F]),X=r(e=>s(`/devices/${String(e)}`),[s]),Pe=r(e=>i(T,{context:`integration-detail`,devices:N,trpc:u.trpcClient,integrationOf:L,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:we,resolveParent:Ne,onNavigate:X}),[N,u.trpcClient,L,Ne,X]),Fe=r(e=>G===e.addonId,[G]),Ie=n(()=>Re({isExpanded:Fe,onToggleExpand:K}),[Fe,K]),Le=r(e=>`${e.name} ${e.addonId}`,[]),Ve=r(e=>e.id,[]),He=e=>i(T,{mode:`generic`,items:e,getKey:Ve,getSearchText:Le,columns:Ie,onRowClick:Me,isExpanded:Fe,renderExpanded:Pe,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),Ue=r(()=>{ye(),Te()},[ye,Te]),Q=ve===!0||M===!0,$=!Q&&(_e||k||D===void 0||O===void 0),We=P.length>0,Ge=[{id:`table`,label:t(`integrations.viewTable`,`Table`),icon:x},{id:`grid`,label:t(`integrations.viewGrid`,`Grid`),icon:ne}];return e(Ce,{icon:h,title:t(`nav.integrations`,`Integrations`),actions:e(l,{children:[i(w,{ariaLabel:t(`integrations.viewLabel`,`Layout`),value:m,onChange:_,options:Ge,testId:`integrations-view`}),i(`button`,{onClick:Ue,disabled:$,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:t(`common.refresh`,`Refresh`),children:i(p,{className:ae(`h-3.5 w-3.5`,$&&`animate-spin`)})}),e(`button`,{onClick:me,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:t(`integrations.scanTheLocalNetworkFor`,`Scan the local network for devices`),children:[i(d,{className:`h-3.5 w-3.5`}),t(`integrations.scanNetwork`,`Scan network`)]}),e(`button`,{onClick:re,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[i(g,{className:`h-3.5 w-3.5`}),t(`integrations.newIntegration`,`New Integration`)]})]}),children:[Q&&i(ce,{message:t(`integrations.loadFailed`,`Integrations could not be loaded.`),onRetry:Ue}),$&&i(`div`,{className:`space-y-2`,"data-testid":`integrations-pending`,children:[1,2,3].map(e=>i(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!$&&!We&&e(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[i(`p`,{className:`text-sm`,children:t(`integrations.noIntegrationsConfigured`,`No integrations configured.`)}),i(`p`,{className:`text-xs mt-1`,children:t(`integrations.clickNewIntegrationToConnect`,`Click "New Integration" to connect cameras and devices.`)})]}),!Q&&!$&&We&&m===`table`&&e(`div`,{className:`space-y-4`,children:[Y.providers.length>0&&i(V,{kind:`providers`,children:He(Y.providers)}),Y.system.length>0&&i(V,{kind:`system`,children:He(Y.system)})]}),!Q&&!$&&We&&m===`grid`&&i(Oe,{providers:Ae.providers,system:Ae.system,onOpen:je,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),i(Z,{open:ee,onClose:ue,seed:te}),i(De,{open:fe,onClose:ge,onSetupIntegration:de})]})}export{Ve as IntegrationsPage};
|