@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 +0,0 @@
|
|
|
1
|
-
import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,a as s,et as c,o as l,t as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$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-DgedyCX9.js";import{Io as I,Lo as L,Ro as R,Xa as te,Ya as ne,c as z}from"./client-F3l12jEi.js";import{n as B,r as re,t as ie}from"./key-C_dbeH7F.js";import{f as ae,s as oe,u as se}from"./video-5IaJhdjU.js";import{t as ce}from"./file-up-cso0QIDs.js";import{t as le}from"./key-round-CPg0Y5qN.js";import{t as ue}from"./monitor-smartphone-DezRerVw.js";import{t as de}from"./unlink-BcrHT0zX.js";import{Ad as fe,An as pe,Cd as me,Cn as he,Cr as V,Et as ge,Fd as _e,Fo as H,Hi as ve,Ir as ye,Jn as be,Kn as xe,Md as Se,Nd as Ce,Nr as U,On as we,Pd as Te,Pr as Ee,Qn as De,Sd as Oe,Sn as ke,Tr as Ae,U as je,Ui as Me,Xn as Ne,Yn as Pe,Zn as Fe,_d as Ie,_r as Le,_t as Re,bd as ze,br as Be,ct as Ve,dc as He,di as W,gd as Ue,hd as We,ic as Ge,jd as Ke,jn as qe,kn as G,md as Je,mr as Ye,nc as Xe,of as K,pd as Ze,ri as q,sc as Qe,uc as $e,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-B0EA_4Ed.js";import{t as J}from"./i18n-BH0PY6IL.js";import{t as Y}from"./useTranslation-BJr-n0es.js";import{T as ct,_r as lt,a as ut,d as dt,hr as ft,i as pt,l as mt,mr as ht,pr as gt,rr as _t,yr as vt}from"./index-CQ7TjSgs.js";import{t as yt}from"./AdminSectionedPage-B4MRvqE8.js";import{t as bt}from"./AdminPage-CYSYefaL.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-BOjlUhj5.js";import{i as Jt,n as Yt,r as Xt,t as Zt}from"./IntegrationHub-8GCewFBs.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}=at(),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=et(),[s,c]=o(null),u=()=>void r.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]}),d=rt({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}=_t();return e?.isAdmin?i(mn,{}):null}function pn(){let{data:e}=at(),{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=lt(),[l]=vt(),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(xe,{appearance:`pills`,value:f?.id??$.loginSessions,onValueChange:e=>{c(`?${dt(l,e,null,null).toString()}`)},children:i(be,{"aria-label":a(`system.access.credentialKinds`,`Credential kinds`),children:o.map(t=>e(Pe,{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=Re({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(ye,{className:`h-32 w-full`}):i(pe,{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(De,{htmlFor:`oidc-connection-id`,children:f(`system.oidcSettingsConnections.instanceId`,`Instance id`)}),i(_e,{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(Ye,{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=Me({capName:An[0].capName},{refetchInterval:kn}),r=Me({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(gt,{i18nKey:`system.authentication.totpNote`,components:{access:i(ht,{to:`/system/my-access?tab=sign-in`,className:`underline text-primary`}),users:i(ht,{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(Ne,{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(fe,{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(_e,{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(Le,{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(ke,{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=at(),[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=Xe(void 0,{refetchInterval:15e3}),a=Ge({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),s=Qe({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),c=He({onSuccess:()=>void n.invalidateQueries({queryKey:[[`localNetwork`]]})}),u=$e({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(we,{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(he,{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(he,{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(he,{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=Xe().data?.caCertPem??``,s=()=>{if(o===``)return;let e=URL.createObjectURL(new Blob([o],{type:`application/x-pem-file`})),t=document.createElement(`a`);t.href=e,t.download=`camstack-ca.crt`,t.click(),URL.revokeObjectURL(e)},c=n?.ca,l=c?.state===`ready`?Date.parse(c.validTo):null,u=n?.listener;return e(`div`,{className:`space-y-1`,"data-testid":`ca-strip`,children:[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(Se,{className:`inline-block`,children:[i(Te,{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(Ce,{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(pe,{columns:D,rows:O,rowKey:e=>e.nodeId,minWidthPx:960,maxBodyHeight:qe,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=Ie({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(Ae,{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(Be,{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(V,{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=Ue({userId:t}),u=c.data,f=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),p=We({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(Ae,{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(Be,{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}=_t(),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(Ae,{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(Be,{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(V,{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=z(e.scopes??[]);if(t===null)return{role:e.isAdmin?`admin`:`viewer`,mode:`except`,pickedIds:[],viewer:ne,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(Ae,{children:u(`users.userAccessModal.title`,{name:t.username})})}),e(Be,{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(Ve,{label:u(`users.userAccessModal.whichDevices`),value:f.mode,options:C,onChange:e=>p(Dr(f,e))}),i(je,{devices:_,listState:g,fleet:v,value:[...f.pickedIds],onChange:e=>p(Or(f,e)),emptyMeansAll:f.mode===`except`,noun:`device`,testId:`viewer-device-picker`}),i(wr,{scopes:b?.scopes??[],invalidReason:x})]}),e(`section`,{className:`space-y-2`,children:[i(`h3`,{className:Fr,children:u(`users.userAccessModal.features`)}),i(`div`,{className:`space-y-1`,children:te.map(t=>e(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-md p-1.5 hover:bg-surface-hover`,children:[i(Fe,{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(V,{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}=_t(),{state:s,openNew:c,openEdit:u,close:f}=Re(),[p,m]=o(null),[h,y]=o(null),[b,x]=o(!1),{data:w,isLoading:T,isError:D,error:k,refetch:ee}=at(),N=M(),P=C(),F=()=>n.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),I=Ze(),L=Je({onSuccess:F}),R=tt({onSuccess:F}),te=ze({onSuccess:F}),ne=Oe(),[z,B]=o(null),[re,ae]=o(!1),[oe,se]=o(null),[ce,le]=o(null),[de,fe]=o(null),[me,he]=o(null),V=w??[],H=s.mode===`edit`?V.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 De=I.isPending||R.isPending,ke=p!==null&&p.id===void 0&&p.username.trim()!==``&&p.password.length>=Br,Ae=p!==null&&p.id!==void 0,je=De||(p?.id===void 0?!ke:!Ae),Me=e=>L.isPending&&L.variables?.id===e.id||R.isPending&&R.variables?.id===e.id||te.isPending&&te.variables?.id===e.id,Ne=[{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:Me(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=Me(n),o=n.id!==r?.id&&n.totpEnabled;return e(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[e(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:()=>fe(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:()=>he(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&&V.length===0&&i(Ee,{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&&V.length>0&&i(pe,{columns:Ne,rows:V,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:je,onClick:()=>void we(),children:De?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(_e,{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(Ke,{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:()=>fe(null)}),me&&i(Cr,{userId:me.id,username:me.username,onClose:()=>he(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]=vt(),n=bn(),[r,a]=o(!1),s=qr[t.get(`tab`)??``];if(s!==void 0)return i(ft,{to:mt(`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===ut.access.tab?yn(u,n.requestCreate):l===`certificates`?Yr(()=>a(!0)):void 0;return i(yt,{icon:c.icon,title:c.title,defaultSection:`users`,sectionsLabel:`${c.title} sections`,actions:d,sections:[{id:`users`,label:e(`systemPage.identity.users`,`Users`),content:i(Wr,{})},{id:ut.access.tab,label:e(`systemPage.identity.tokensSessions`,`Tokens & sessions`),ownedParams:pt.concat([Mt.token,Mt.scoped,Mt.admin]),content:i(vn,{createRequested:n.createRequested,onCreateConsumed:n.clearCreate})},{id:Jr,label:e(`systemPage.identity.certificates`,`Certificates`),content:i(br,{pairOpen:r,onPairClose:()=>a(!1)})},{id:ut.authentication.tab,label:e(`systemPage.identity.authentication`,`Authentication`),content:i(Nn,{}),ownedParams:pt}]})}export{Xr as IdentityPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,et as s,o as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{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,gt as x,ha as S,hi as C,ia as w,ki as T,pr as E,xi as D,yn as O,zt as k}from"./player-overlays-DgedyCX9.js";import{Ja as ee}from"./client-F3l12jEi.js";import{t as A}from"./search-x-BRhrXpKx.js";import{Aa as j,Ai as M,Ao as te,As as N,Cn as P,Cr as F,Do as I,Eo as ne,Fd as L,Fo as re,Fs as R,Ft as z,Ji as B,Ko as V,Ls as H,Lt as U,Ma as W,Ms as ie,Nn as ae,Nr as oe,Ns as se,Pa as G,Ps as ce,Pt as le,Qn as ue,So as de,Tr as fe,Wo as K,Xd as q,Xn as pe,_o as J,br as Y,cn as me,ef as X,go as he,ho as ge,js as _e,ki as ve,ls as ye,mo as be,oi as xe,po as Se,pr as Ce,ri as we,wr as Te,xo as Ee,xr as De,yo as Z,yr as Oe}from"./src-B0EA_4Ed.js";import{t as Q}from"./useTranslation-BJr-n0es.js";import{n as ke}from"./addon-icons-context-CHk3ePjj.js";import{C as Ae,L as je,S as Me,_r as Ne,pr as Pe,vr as Fe,w as Ie,yr as Le}from"./index-CQ7TjSgs.js";import{t as Re}from"./device-integration-icon-CXG5v8dp.js";import{a as ze,i as Be,r as Ve,t as He}from"./ScanNetworkModal-BR3tzZcL.js";import{t as Ue}from"./NodeAddonsSettingsPanel-Do_I93Mx.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,S]=o($),C=K({addonId:l},{enabled:t}),w=C.data?.deviceType??null,D=te({addonId:l,type:w??ee.Camera},{enabled:t&&C.isSuccess&&w!==null}),A=D.data??null;a(()=>{t&&(m(A?Je(A.sections.flatMap(e=>e.fields)):{}),S($()),g(!1),y(null))},[t,s,A]);let j=n(()=>({...p,_probeRequestId:b}),[p,b]),M=Ee({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),N=ye(),P=r(async(e,t)=>{g(!0);let n=await N.mutateAsync({addonId:l,type:w??ee.Camera,key:e,value:t,formValues:j});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},[N,l,j,w]),{testAllStatus:F,hasProbeFields:I,probeResults:ne,handleTestAll:L,clearProbeResult:re}=Ge(A??{sections:[]},p,P);async function R(e){y(null);try{await M.mutateAsync({addonId:l,type:w??ee.Camera,config:p,integrationId:s}),e?m(A?Je(A.sections.flatMap(e=>e.fields)):{}):u()}catch(e){y(e instanceof Error?e.message:String(e))}}if(!t)return null;let z=Ke((A?.sections??[]).flatMap(e=>e.fields)).filter(e=>qe(p[e])),B=z.length===0,V=C.isLoading||w!==null&&D.isLoading,H=C.isError||C.isSuccess&&w===null||D.isError||D.isSuccess&&A===null;return e(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[i(`div`,{className:`absolute inset-0 bg-black/60`,onClick:u}),e(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[calc(90dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl`,children:[e(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[i(`h2`,{className:`text-sm font-semibold text-foreground`,children:d(`integrations.addDevice`)}),i(`button`,{onClick:u,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:i(x,{className:`h-4 w-4`})})]}),i(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:V?i(`div`,{className:`flex items-center justify-center py-8`,children:i(E,{className:`h-5 w-5 animate-spin text-primary`})}):H?e(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[i(k,{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:A,values:p,onChange:m,onTestField:P,probeResults:ne,onClearProbe:re})}),!H&&!V&&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-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[e(`span`,{className:`flex items-center gap-2`,children:[i(O,{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(T,{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(me,{addonId:l,requestId:b,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!H&&!V&&(_||z.length>0)&&i(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(k,{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:z.join(`, `)})})]})}),e(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[e(`div`,{className:`flex items-center gap-2`,children:[i(`button`,{onClick:u,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:d(`integrations.cancel`)}),!H&&I&&e(`button`,{type:`button`,onClick:L,disabled:F===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[F===`testing`?i(E,{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:()=>R(!0),disabled:H||!B||M.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:()=>R(!1),disabled:H||!B||M.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:M.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=W({kind:Xe}),[c,l]=o(null),u=s.data?.length??0,d=c??s.data?.[0]?.id??null,f=G(),[p,m]=o(``),[h,g]=o({phase:`idle`,failure:null,message:null}),_=h.phase===`discovering`||h.phase===`pase`||h.phase===`commissioning`,v=j({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(De,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(Te,{children:i(fe,{children:r(`integrations.addMatter.title`,{defaultValue:`Add Matter device`})})}),e(Y,{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(ue,{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(ue,{htmlFor:`matter-pairing-code`,children:r(`integrations.addMatter.code`,{defaultValue:`Pairing code`})}),i(L,{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(E,{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(oe,{message:x})]}),e(F,{children:[i(we,{variant:`ghost`,size:`sm`,onClick:t,children:r(`common.close`,{defaultValue:`Close`})}),h.phase===`done`?i(we,{size:`sm`,onClick:n,children:r(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}):i(we,{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=Se(),c=(he({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(E,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):c.failed>0?i(k,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):c.state===`cancelled`?i(C,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):i(D,{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=S(),{t:f}=Q(),p=c(),[m,h]=o(new Set),[g,v]=o(new Set),[y,b]=o(new Map),[C,w]=o(null),{data:T}=ie(),D=(T??[]).find(e=>e.addonId===n)?.supportsLocationImport??!1,[O,ee]=o(!0),A=be({addonId:n,integrationId:s}).data?.filters,j=A&&A.length>0?A:[at(f)],[M,te]=o(j.find(e=>e.isDefault)?.id??(j.some(e=>e.id===it)?it:j[0].id)),N=M!==it,P=J(),F=ge({addonId:n,integrationId:s,page:1,pageSize:ot,filter:M}),I=F.refetch,ne=P.mutate,L=r(()=>{ne({addonId:n,integrationId:s},{onSettled:()=>{I()}})},[ne,n,s,I]),re=t(null);a(()=>{let e=`${n}::${s}`;re.current===e||F.isLoading||(re.current=e,(F.data?.candidates.length??0)===0&&L())},[n,s,F.isLoading,F.data,L]);let R=P.isPending,z=P.isError?P.error instanceof Error?P.error.message:String(P.error):null,B=typeof P.data?.lastError==`string`&&P.data.lastError.length>0?P.data.lastError:null,V=F.data?.candidates??[],H=F.isError?F.error instanceof Error?F.error.message:String(F.error):null,U=Z(),[W,ae]=o(null),oe=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})},[]),se=r(e=>{v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),G=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})},[]),ce=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]),ue=r(async()=>{w(null);let e=[...m];if(e.length!==0)try{let t=ce(e),{jobId:r}=await U.mutateAsync({addonId:n,integrationId:s,filter:M,childNativeIds:e,...t?{perCandidate:t}:{},...D?{importLocations:O}:{}});ae(r),h(new Set),b(new Map)}catch(e){w(e instanceof Error?e.message:String(e))}},[m,ce,U,n,s,M,D,O]),de=t(null),fe=r(()=>{W===null||de.current===W||(de.current=W,I(),p.invalidateQueries({queryKey:[[`integrations`]]}),p.invalidateQueries({queryKey:[[`deviceManager`]]}))},[W,I,p]),K=r(e=>{te(e),h(new Set),v(new Set),b(new Map),w(null)},[]),pe=m.size,Y=W!==null&&pe===0&&!U.isPending;return e(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[i(`div`,{className:`absolute inset-0 bg-black/60`,onClick:u}),e(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] rounded-xl border border-border bg-background shadow-2xl`,children:[e(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[e(`div`,{className:`min-w-0`,children:[i(`h2`,{className:`text-sm font-semibold text-foreground`,children:f(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),i(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:f(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),e(`div`,{className:`flex items-center gap-3 shrink-0`,children:[D&&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:O,onChange:e=>ee(e.target.checked),className:`accent-primary`}),f(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),i(`button`,{onClick:u,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":f(`common.close`,`Close`),children:i(x,{className:`h-4 w-4`})})]})]}),e(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(z??H??B)&&V.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(k,{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:z??H??B})]})]})}),j.length>1&&i(lt,{filters:j,activeFilter:M,onSelect:K}),i(`div`,{className:`flex-1 min-h-0`,children:i(le,{mode:`generic`,items:V,pageSize:st,getKey:e=>e.childNativeId,getSearchText:rt,getFilterType:e=>e.type,filterOptions:q(d),filterLabel:f(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:F.isLoading||R&&V.length===0,searchPlaceholder:f(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(z??H??B)&&V.length===0?``:f(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:e(`button`,{type:`button`,onClick:L,disabled:R,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 ${R?`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:!N,expanded:g.has(e.childNativeId),onToggleExpand:()=>se(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=X(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:()=>oe(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=>!N&&g.has(e.childNativeId),renderExpanded:N?void 0:e=>i(dt,{candidate:e,hiddenChildIds:y.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>G(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:m.has(e.childNativeId)?`bg-primary/5`:``})})]}),C&&i(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(k,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),i(`p`,{className:`text-[11px] text-destructive`,children:C})]})}),W!==null&&i(nt,{addonId:n,integrationId:s,jobId:W,onFinished:fe}),e(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[i(`div`,{}),e(`div`,{className:`flex items-center gap-2`,children:[i(`button`,{onClick:u,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:f(`integrations.cancel`,{defaultValue:`Cancel`})}),e(`button`,{onClick:Y?u:ue,disabled:!Y&&(pe===0||U.isPending),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,children:[U.isPending&&i(E,{className:`h-3.5 w-3.5 animate-spin`}),Y?f(`integrations.close`,{defaultValue:`Close`}):f(`integrations.addSelected`,{defaultValue:`Add selected`}),!Y&&pe>0?` (${pe})`:``]})]})]})]})]})}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?T: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}=ve({addonId:r,nodeId:`hub`},{enabled:s===`account`}),b=n(()=>v?mt(v):null,[v]),x=R(),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(De,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(Te,{children:e(fe,{children:[p(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,a]})}),i(Y,{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(E,{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(E,{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(Ce,{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=``}=Fe();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=Ne(),[p,g]=Le(),_=y(),[v,x]=o(!1),[S,C]=o(!1),[T,D]=o(!1),k=r(e=>{D(!1),d(`/integrations`,{state:{integrationSeed:e}})},[d]),[ee,j]=o(!1),[te,F]=o(!1),{data:L}=ce(void 0),R=n(()=>(L??[]).filter(e=>e.addonId===t),[L,t]),W=Ie(p.get(`instance`),R)??``,oe=r(e=>{g(t=>{let n=new URLSearchParams(t);return n.set(Me,e),n},{replace:!0})},[g]),se=n(()=>R.map(e=>({value:e.id,label:e.name})),[R]),{data:G,isLoading:ue}=_e({id:W},{enabled:!!W}),{data:K}=ve({addonId:G?.addonId??``,nodeId:`hub`},{enabled:!!G?.addonId}),{data:q,isSuccess:J}=ie(),X=n(()=>{let e=G?.addonId;return!e||!J?null:(q??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[q,G?.addonId,J]),{data:he}=ne({}),ge=n(()=>(he?.providers??[]).some(e=>e.addonId===G?.addonId),[he,G?.addonId]),ye=X!==null,be=G?.info?.fixed===!0,Se=n(()=>{let e=G?.addonId;return!e||!J?null:(q??[]).find(t=>t.addonId===e)?.brokerKind??null},[q,G?.addonId,J]),Ce=Se===`matter`,we=ye?Ce?s(`integrations.addMatter.title`,{defaultValue:`Add Matter device`}):X===`device-adoption`?s(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):s(`integrations.addDevice`):s(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),Ee=n(()=>{let e=G?.addonId;return!e||!J?!1:(q??[]).find(t=>t.addonId===e)?.canTest===!0},[q,G?.addonId,J]),Z=n(()=>{let e=G?.addonId;return!e||!J?null:(q??[]).find(t=>t.addonId===e)?.mode??null},[q,G?.addonId,J]);a(()=>{p.get(`add`)===`1`&&ye&&(C(!1),x(!0),g(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[p,ye,g]);let ke=K!=null&&Array.isArray(K.sections)&&K.sections.some(e=>e.fields.length>0),{data:je}=M({addonId:G?.addonId??``,nodeId:`hub`},{enabled:!!G?.addonId&&Z!==`account`}),Pe=Z!==null&&Z!==`account`&>(je),Fe=n(()=>G?.addonId?[G.addonId]:[],[G?.addonId]),{data:ze}=re({projection:`slim`},{refetchInterval:3e4}),Be=[[`integrations`,`get`],{input:{id:W},type:`query`}],Ve=H({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=N({onSuccess:()=>{l.invalidateQueries({queryKey:[[`integrations`]]}),l.invalidateQueries({queryKey:[[`deviceManager`]]}),d(R.length>1?Ae(t):`/integrations`)}}),Ge=B({onSuccess:()=>{l.invalidateQueries({queryKey:[[`integrations`]]}),l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ke=V({onSuccess:()=>{l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),qe=de({onSuccess:()=>{l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Je=I({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(()=>z(L),[L]),$e=r(e=>d(`/devices/${String(e)}`),[d]),tt=n(()=>$.filter(e=>{let t=Qe(e);return t.kind===`resolved`&&t.integration.id===W}),[$,W,Qe]),nt=n(()=>L===void 0?null:U(tt).length,[L,tt])??`…`;if(ue||L===void 0)return i(vt,{});let rt=(q??[]).find(e=>e.addonId===t)?.name??G?.name??t;return G?e(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[i(ae,{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:G.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:[ge&&e(`button`,{onClick:()=>D(!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`)]}),!be&&e(`button`,{onClick:()=>{C(!1),x(!0)},disabled:!ye,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:we,children:[i(h,{className:`h-3.5 w-3.5`}),we]}),e(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Ve.isPending?`opacity-60`:``} ${G.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:s(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[i(pe,{checked:G.enabled,onCheckedChange:e=>Ve.mutate({id:W,enabled:e}),disabled:Ve.isPending,"aria-label":G.enabled?s(`integrationDetail.disableIntegration`,`Disable integration`):s(`integrationDetail.enableIntegration`,`Enable integration`)}),i(`span`,{className:`text-[11px] font-medium ${G.enabled?`text-success`:`text-foreground-subtle`}`,children:G.enabled?s(`integrationDetail.enabled`,`Enabled`):s(`integrationDetail.disabled`,`Disabled`)}),Ve.isPending&&i(E,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Z!==`standalone`&&(ke||X===`device-adoption`)&&e(`button`,{onClick:()=>j(!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:()=>F(!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(O,{className:`h-3 w-3`}),s(`integrations.logs`,{defaultValue:`Logs`})]}),i(P,{label:s(`integrationDetail.restart`,`Restart`),icon:f,title:s(`integrationDetail.restart2`,`Restart "{{name}}"?`,{name:G.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:G.addonId})}),!be&&W&&i(P,{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:G.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:W})})]})]}),R.length>1&&i(`div`,{className:`max-w-sm`,children:i(xe,{mode:`single`,singleDisplay:`field`,label:s(`integrationDetail.instances`,`Integration`),options:se,value:W,onChange:oe,testId:`integration-instance-picker`,optionTestIdPrefix:`integration-instance`})}),Pe&&i(Ue,{nodeId:null,addonIds:Fe,level:`global`,surface:`integration`,title:s(`integrations.settings`,{defaultValue:`Settings`})}),i(le,{context:`integration-detail`,devices:$,trpc:_.trpcClient,integrationOf:Qe,forceIntegrationId:W,urlScope:`root`,lsKey:`integration-detail:${G.addonId}`,resolveIntegrationIcon:Re,resolveParent:Ze,onNavigate:$e,batchActions:{remove:Ke.mutate,disable:qe.mutate,enable:Je.mutate},...be?{}:{onDeleteDevice:e=>Ke.mutate({deviceId:e.id})}}),v&&W&&Ce&&!S&&i(et,{onClose:()=>x(!1),onCommissioned:()=>C(!0)}),v&&W&&X===`device-adoption`&&(!Ce||S)&&i(ct,{addonId:G.addonId,integrationId:W,onClose:()=>{x(!1),C(!1)}}),v&&W&&X===`device-provider`&&i(Ye,{open:v,integrationId:W,addonId:G.addonId,onClose:()=>x(!1)}),T&&G&&i(He,{open:T,scope:{addonId:G.addonId,label:G.name},onClose:()=>D(!1),onSetupIntegration:k}),ee&&W&&X!==null&&Z!==null&&i(ht,{integrationId:W,addonId:G.addonId,name:G.name,kind:X,mode:Z,brokerKind:Se,canTest:Ee,trpc:_.trpcClient,onClose:()=>j(!1)}),te&&i(Oe,{open:!0,onOpenChange:e=>!e&&F(!1),children:e(De,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[i(Te,{className:`mb-0`,children:e(fe,{className:`flex items-center gap-2 min-w-0`,children:[i(O,{className:`h-4 w-4 text-primary shrink-0`}),i(`span`,{className:`truncate`,children:G.name}),e(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate font-normal`,children:[G.addonId,W?` · ${W}`:``]})]})}),i(Y,{className:`min-h-0 overflow-hidden p-0`,children:i(me,{addonId:G.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(A,{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(w,{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 +0,0 @@
|
|
|
1
|
-
import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,et as s,o as c,x as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{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 y,gt as b,ki as x,pr as S,vn as C,yr as w}from"./player-overlays-DgedyCX9.js";import{t as ee}from"./table-2-BPB4V5Fg.js";import{Fd as T,Fo as te,Ft as E,Hi as D,L as O,Lt as ne,Ms as re,Nr as k,Ps as ie,Pt as A,Ud as ae,fo as oe,ki as se,ks as ce,r as j,ri as M,ut as N,wo as le}from"./src-B0EA_4Ed.js";import{t as P}from"./i18n-BH0PY6IL.js";import{t as F}from"./useTranslation-BJr-n0es.js";import{C as I,_r as ue,dr as L,gr as de,yr as R}from"./index-CQ7TjSgs.js";import{t as z}from"./AdminPage-CYSYefaL.js";import"./useEventInvalidation-Fpx4y0MY.js";import{t as fe}from"./device-integration-icon-CXG5v8dp.js";import{i as pe,n as me,r as he,t as ge}from"./ScanNetworkModal-BR3tzZcL.js";import{t as B}from"./framework-packages-B7oma9J4.js";s();function _e(e){return e.some(e=>e.status===`running`)?`running`:e.some(e=>e.status===`stopped`)?`stopped`:`disabled`}function ve(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:_e(n)}})}function ye(e){return e.integrationSection===void 0?B(e.packageName)?`system`:`providers`:e.integrationSection}function V(e){let t=new Set;for(let n of e??[])ye(n.manifest)===`system`&&t.add(n.manifest.id);return t}function H(e,t){return{providers:e.filter(e=>!t.has(e.addonId)),system:e.filter(e=>t.has(e.addonId))}}function U(e,t){return[...e].sort((e,n)=>e.name.localeCompare(n.name,t,{sensitivity:`base`}))}function W({kind:t,children:n}){let{t:r}=F(),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 G({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 K({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(M,{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(L,{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 be({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(C,{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(T,{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(W,{kind:`providers`,children:i(q,{groups:d.providers,onOpen:a})}),d.system.length>0&&i(W,{kind:`system`,children:i(q,{groups:d.system,onOpen:a})})]})]})}function q({groups:e,onOpen:t}){let{t:r,i18n:a}=F();return i(G,{children:n(()=>U(e,a.language),[e,a.language]).map(e=>i(K,{testId:`integration-card-${e.addonId}`,addonId:e.addonId,name:e.name,openLabel:r(`integrations.openNamed`,{name:e.name,defaultValue:`Open {{name}}`}),onOpen:()=>t(e),body:i(`p`,{className:`text-xs text-foreground-muted`,children:r(`integrations.addonCard.summary`,{integrations:r(`integrations.addonCard.integrationCount`,{count:e.instanceCount}),devices:r(`integrations.integrationColumns.deviceCount`,{count:e.deviceCount}),defaultValue:`{{integrations}} · {{devices}}`})}),footer:i(N,{status:e.status,className:`shrink-0`})},e.addonId))})}s();var J=`camstack.admin.integrations.view`;function xe(e){return e===`table`||e===`grid`}function Y(){try{return typeof window>`u`?null:window.localStorage}catch{return null}}function Se(e=Y()){if(e===null)return`table`;try{let t=e.getItem(J);return xe(t)?t:`table`}catch{return`table`}}function Ce(e,t=Y()){if(t!==null)try{t.setItem(J,e)}catch{}}function we(){let[e,t]=o(()=>Se());return[e,r(e=>{t(e),Ce(e)},[])]}s();function Te(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 Ee(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 De({providerId:t,onImport:n,onSkip:r}){let{t:s}=F(),[c,l]=o(new Set),d=le(),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 X=`(hover: none) and (pointer: coarse)`;function Z(){if(typeof window>`u`||typeof window.matchMedia!=`function`)return!0;try{return!window.matchMedia(X).matches}catch{return!0}}s();function Oe({onSelect:r,onClose:s,pendingAddonId:c=null}){let{t:l,i18n:u}=F(),d=ue(),[f,p]=o(``),m=t(null),{data:h,isLoading:g}=re();a(()=>{g||!Z()||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}=D(void 0),b=n(()=>{let e=H(_,V(v));return{providers:U(e.providers,u.language),system:U(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 x=c!==null,w=t=>i(G,{children:t.map(t=>{let n=t.instanceMode===`unique`&&t.existingInstances.length>0,a=c===t.addonId;return i(K,{testId:`provider-card-${t.addonId}`,buttonTestId:`provider-pick-${t.addonId}`,addonId:t.addonId,name:t.name,openLabel:t.name,disabled:x,onOpen:()=>{if(n){let e=t.existingInstances[0].id;s(),d(I(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(S,{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(y,{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(C,{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(T,{ref:m,type:`search`,value:f,onChange:e=>p(e.target.value),placeholder:l(`integrations.searchProviders`,`Search integrations…`),className:`pl-8`,"data-testid":`provider-picker-search`,"aria-label":l(`integrations.searchProviders`,`Search integrations…`)})]}),b.providers.length>0&&i(W,{kind:`providers`,children:w(b.providers)}),b.system.length>0&&i(W,{kind:`system`,children:w(b.system)}),_.length===0&&i(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:(h??[]).length===0?l(`integrations.noProviders`):l(`integrations.noProvidersMatch`,`No integrations match your search.`)})]})}s();function ke(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 Ae=2e4;function je({open:t,onClose:r,seed:s=null}){let{t:u}=F(),d=ue(),f=c(),[p,m]=o(`picker`),[h,g]=o(null),[_,v]=o(null),[y,x]=o(`manual`),[C,w]=o(null),[ee,T]=o(``),[te,E]=o(null),[D,O]=o(null),[ne,k]=o(!1),[ie,A]=o({}),[ae,j]=o(``),M=s?.config.host,N=s===null?``:`${s.addonId}\0${s.name}\0${typeof M==`string`?M:``}`;t&&s!==null&&ae!==N&&(j(N),g(s.addonId),T(s.name),A({...s.config}),m(`config`));let P=re(void 0,{enabled:t&&s!==null}),{data:L}=se({addonId:h??``,nodeId:`hub`},{enabled:h!=null}),de=n(()=>L?ke(L):null,[L]),R=ce({onSuccess:()=>f.invalidateQueries({queryKey:[[`integrations`]]})}),z=le(),fe=z.data;a(()=>{if(!t||s===null)return;let e=P.data?.find(e=>e.addonId===s.addonId);e&&(k(e.canTest),x(e.discoveryMode))},[t,s,P.data]),a(()=>{p!==`discovery`||!_||!h||z.isPending||z.data||z.mutate({addonId:h})},[p,_,h,z]);let me=oe({onSuccess:()=>f.invalidateQueries({queryKey:[[`deviceManager`]]})});function ge(e,t,n,r,i,a,o,s){if(!R.isPending){if(g(e),k(s),x(n),T(r),O(null),o===`broker`){if(!a){O(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}w(a),m(`broker`);return}if(o===`account`){m(`config`);return}B(e,r)}}async function B(e,t){try{let n=await R.mutateAsync({addonId:e,name:t,settings:{}});r(),H(),d(`${I(e,n.id)}&add=1`)}catch{}}async function _e(e){if(h)try{let t=await R.mutateAsync({addonId:h,name:e.name,settings:e.config,secretKeys:[...e.secretKeys]});v(t.id),E(t.id),y===`auto`||y===`both`?m(`discovery`):V(t.id,{openAdd:!0})}catch{}}async function ve(e){if(h)try{let t=await R.mutateAsync({addonId:h,name:ee,settings:{brokerId:e}});E(t.id),v(t.id),V(t.id)}catch{}}async function ye(e){if(h){for(let t of e){let e=fe?.find(e=>e.stableId===t);e&&await me.mutateAsync({addonId:h,candidate:e,...te===null?{}:{integrationId:te}})}V()}}function V(e,t){let n=e??_??h;if(r(),H(),n&&h){let e=I(h,n);d(t?.openAdd===!0?`${e}&add=1`:e)}}function H(){m(`picker`),g(null),v(null),x(`manual`),w(null),T(``),E(null),O(null),k(!1),A({}),j(``)}function U(){r(),H()}Te(t);let W=R.isPending,G=Ee(W,Ae);if(!t)return null;let K={picker:u(`integrations.newIntegration`),config:u(`integrations.configureIntegration`),discovery:u(`integrations.importDevices`),broker:u(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},be=W?h:null,q=R.error,J=W&&!G;return e(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[i(`div`,{className:`absolute inset-0 bg-black/60`,onClick:J?void 0:U}),e(`div`,{className:`relative z-10 w-full ${p===`picker`?`max-w-5xl`:`max-w-lg`} max-h-[calc(85dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[e(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[i(`h2`,{className:`text-sm font-semibold text-foreground`,children:K[p]}),i(`button`,{onClick:U,disabled:J,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:i(b,{className:`h-4 w-4`})})]}),e(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[q&&!W&&i(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:q instanceof Error?q.message:String(q)}),p===`picker`&&e(l,{children:[D&&i(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:D}),i(Oe,{onSelect:ge,onClose:U,pendingAddonId:be})]}),p===`config`&&h&&i(he,{addonId:h,configSchema:de??null,canTest:ne,initialName:typeof ie.host==`string`?ee:void 0,initialConfig:{...ie},onSave:_e,onBack:()=>{A({}),m(`picker`)}},N.length>0?N:h),p===`broker`&&C&&i(pe,{kind:C,onResolved:e=>{ve(e)},onBack:()=>m(`picker`)}),p===`discovery`&&_&&i(De,{providerId:_,onImport:ye,onSkip:V})]}),W&&e(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm px-6 text-center`,children:[i(S,{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…`})}),!G&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:u(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),G&&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:U,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:u(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})]})}function Me({integration:t,expanded:n,onToggleExpand:r}){let{t:a}=F();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?x:f,{className:`h-3.5 w-3.5`})}),i(L,{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 Ne(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:P.t(`integrations.integrationColumns.integration`,`Integration`),headerClassName:`w-[55%]`,cell:e=>i(Me,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:P.t(`integrations.integrationColumns.devices`,`Devices`),headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>P.t(`integrations.integrationColumns.deviceCount`,{count:e.deviceCount})},{key:`status`,header:P.t(`integrations.integrationColumns.status`,`Status`),headerClassName:`w-[15%]`,cell:e=>i(N,{status:e.status})}]}s();function Pe(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var Fe=`expand`;function Ie(){let{t}=F(),s=ue(),c=de(),u=v(),[f]=R(),[m,_]=we(),[y,b]=o(!1),[x,S]=o(null),C=r(()=>{S(null),b(!0)},[]),T=r(()=>{b(!1),S(null)},[]),oe=r(e=>{ce(!1),S(e),b(!0)},[]),[se,ce]=o(!1);a(()=>{let e=me(c.state);e!==null&&(S(e),b(!0),s(`/integrations`,{replace:!0,state:null}))},[c.state,s]);let M=f.get(`setup`);a(()=>{M===null||M.length===0||(S({addonId:M,name:M,config:{}}),b(!0))},[M]);let N=r(()=>ce(!0),[]),le=r(()=>ce(!1),[]);j([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),j([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:P,isLoading:L,isError:pe,refetch:he}=ie(void 0),{data:B,isLoading:_e,isError:ye,refetch:U}=te({projection:`slim`}),G=n(()=>B??[],[B]),K=n(()=>P??[],[P]),q=n(()=>{let e=new Map;for(let t of G)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[G]),J=n(()=>E(P),[P]),xe=n(()=>{let e=new Map;for(let t of ne(G)){let n=J(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[G,J]),Y=n(()=>K.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:Pe(e),deviceCount:xe.get(e.id)??0})),[K,xe]),{data:Se}=re(),Ce=n(()=>new Map((Se??[]).map(e=>[e.addonId,e.name])),[Se]),Te=f.get(Fe),Ee=r(e=>{let t=new URLSearchParams(window.location.search);t.get(Fe)===e?t.delete(Fe):t.set(Fe,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),{data:De}=D(void 0),X=n(()=>V(De),[De]),Z=n(()=>H(Y,X),[Y,X]),Oe=n(()=>H(ve(Y,Ce),X),[Y,Ce,X]),ke=r(e=>s(I(e.addonId)),[s]),Ae=r(e=>s(I(e.addonId,e.id)),[s]),Me=r(e=>q.get(e)??null,[q]),Ie=r(e=>s(`/devices/${String(e)}`),[s]),Le=r(e=>i(A,{context:`integration-detail`,devices:G,trpc:u.trpcClient,integrationOf:J,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:fe,resolveParent:Me,onNavigate:Ie}),[G,u.trpcClient,J,Me,Ie]),Re=r(e=>Te===e.addonId,[Te]),ze=n(()=>Ne({isExpanded:Re,onToggleExpand:Ee}),[Re,Ee]),Be=r(e=>`${e.name} ${e.addonId}`,[]),Ve=r(e=>e.id,[]),He=e=>i(A,{mode:`generic`,items:e,getKey:Ve,getSearchText:Be,columns:ze,onRowClick:Ae,isExpanded:Re,renderExpanded:Le,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),Ue=r(()=>{he(),U()},[he,U]),Q=pe===!0||ye===!0,$=!Q&&(L||_e||P===void 0||B===void 0),We=K.length>0,Ge=[{id:`table`,label:t(`integrations.viewTable`,`Table`),icon:ee},{id:`grid`,label:t(`integrations.viewGrid`,`Grid`),icon:w}];return e(z,{icon:h,title:t(`nav.integrations`,`Integrations`),actions:e(l,{children:[i(O,{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:N,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:C,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[i(g,{className:`h-3.5 w-3.5`}),t(`integrations.newIntegration`,`New Integration`)]})]}),children:[Q&&i(k,{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:[Z.providers.length>0&&i(W,{kind:`providers`,children:He(Z.providers)}),Z.system.length>0&&i(W,{kind:`system`,children:He(Z.system)})]}),!Q&&!$&&We&&m===`grid`&&i(be,{providers:Oe.providers,system:Oe.system,onOpen:ke,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),i(je,{open:y,onClose:T,seed:x}),i(ge,{open:se,onClose:le,onSetupIntegration:oe})]})}export{Ie as IntegrationsPage};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{C as e,K as t,S as n,V as r,Y as i,et as a,o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$i as c,Bi as l,Cn as u,Cr as d,Di as f,Dn as p,Fi as m,Gt as h,Hi as g,Hn as _,Ht as v,In as y,Jt as b,Ki as x,O as S,V as C,Vr as w,Wr as T,Wt as E,Xr as D,Zr as O,_r as k,bi as A,ca as ee,ci as j,cr as te,gr as M,gt as N,ht as P,k as F,ki as I,la as L,ln as ne,mn as R,on as re,sa as ie,st as ae,ur as z,vt as B,yn as oe,z as se}from"./player-overlays-DgedyCX9.js";import{bn as ce,gi as le,vi as ue}from"./client-F3l12jEi.js";import{t as de}from"./boxes-BZMO9uMf.js";import{n as fe,t as pe}from"./speaker-BYorOPbN.js";import{t as V}from"./user-round-D6wDvac9.js";import{$o as me,Ad as H,An as U,Bo as he,Cr as W,Fd as G,Fo as ge,Gr as _e,Ho as ve,Hr as ye,Id as be,Jo as xe,Ld as Se,Qn as Ce,Ro as we,Tr as Te,U as Ee,Ur as De,Vr as K,Xo as Oe,Yo as ke,Yr as Ae,Zn as je,bn as Me,br as Ne,co as Pe,di as Fe,do as Ie,es as Le,ns as Re,oi as ze,oo as Be,qo as Ve,ri as q,so as He,ss as Ue,ts as We,wr as Ge,wt as Ke,xn as qe,xr as Je,yr as Ye,zo as Xe}from"./src-B0EA_4Ed.js";import{t as J}from"./i18n-BH0PY6IL.js";import{t as Y}from"./useTranslation-BJr-n0es.js";import{_r as Ze,m as Qe,mr as X,yr as $e}from"./index-CQ7TjSgs.js";import{t as et}from"./AdminSectionedPage-B4MRvqE8.js";import{a as tt,n as nt,r as rt}from"./linked-devices-model-ZCUJsj_d.js";a();function Z(e){return{id:e.id,name:e.name,type:e.type,stableId:e.stableId??``,parentDeviceId:e.parentDeviceId,location:e.location,...e.role!==void 0&&e.role!==null?{role:e.role}:{},...e.primaryChildEntityId!==void 0&&e.primaryChildEntityId!==null?{primaryChildEntityId:e.primaryChildEntityId}:{}}}function Q(e){if(e==null)return null;let t=e.trim();return t.length===0?null:t.toLowerCase()}function it(e,t){let n=Q(t);return n===null?[]:e.filter(e=>Q(e.location)===n)}function at(e,t){let n=it(e,t),r=new Set(n.map(e=>e.id));return n.filter(e=>e.parentDeviceId===null||!r.has(e.parentDeviceId))}function ot(e,t){let n=Q(e.location);return n===null||new Set(t.map(e=>Q(e))).has(n)?null:e.location?.trim()??null}function st(e,t){let n=Q(e.location);return n!==null&&t.has(n)}function ct(e,t){let n=new Set(t.map(e=>Q(e))),r=new Set(e.filter(e=>st(e,n)).map(e=>e.id));return e.filter(e=>!(st(e,n)||e.parentDeviceId!==null&&r.has(e.parentDeviceId)))}function lt(e,t){return ct(e,t).filter(e=>e.parentDeviceId===null)}function ut(e,t){let n=new Map;for(let t of e){if(t.parentDeviceId===null)continue;let e=n.get(t.parentDeviceId);e?e.push(t):n.set(t.parentDeviceId,[t])}let r=[],i=new Set([t]),a=[t];for(;a.length>0;){let e=[];for(let t of a)for(let a of n.get(t)??[])i.has(a.id)||(i.add(a.id),r.push(a),e.push(a.id));a=e}return r}function dt(e,t){return ut(e,t).length}function ft(e,t){return e.filter(e=>!e.isCamera&&e.parentDeviceId===t)}function pt(e,t){return t.map(t=>({name:t,members:at(e,t)}))}var mt={camera:m,hub:u,container:de,light:k,siren:ne,switch:h,sensor:L,thermostat:b,climate:ee,button:A,"event-emitter":P,update:fe,notifier:x,script:oe,automation:B,lock:z,cover:g,valve:O,humidifier:D,"water-heater":w,fan:T,"media-player":pe,"alarm-panel":R,control:re,presence:V,weather:j,vacuum:l,"lawn-mower":E,image:d,smoke:ie};function $({type:e,className:t}){return n(mt[e]??A,{"aria-hidden":`true`,className:t??`h-3.5 w-3.5 shrink-0 text-foreground-subtle`})}function ht({device:e}){let t=De(Z(e),`compact`);return n(gt,{online:e.online,deviceName:t})}function gt({online:e,deviceName:t}){return n(`span`,{className:e?`inline-block h-1.5 w-1.5 shrink-0 rounded-full bg-success`:`inline-block h-1.5 w-1.5 shrink-0 rounded-full border border-foreground-subtle`,role:`img`,"aria-label":J.t(`locations.deviceGlyphs.aria`,{name:t,state:e?J.t(`common.online`):J.t(`common.offline`)}),title:e?J.t(`common.online`):J.t(`common.offline`)})}function _t({open:t,title:a,items:o,listState:s,lockedIds:c,lockedNote:l,suggestions:u=null,busy:d=!1,onConfirm:f,onClose:p}){let{t:m}=Y(),[h,g]=i([]);r(()=>{t||g([])},[t]);let _=new Map(o.map(e=>[e.id,e.name])),v=(u?.ids??[]).filter(e=>_.has(e)&&!c.includes(e)),y=e=>g(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]);return n(Ye,{open:t,onOpenChange:e=>e?void 0:p(),children:e(Je,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":a,children:[n(Ge,{children:n(Te,{children:a})}),e(Ne,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:[t&&u!==null&&v.length>0&&e(`section`,{"aria-label":u.heading,className:`flex flex-col gap-1`,children:[n(`h3`,{className:`text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:u.heading}),n(`div`,{className:`flex flex-wrap gap-1`,children:v.map(e=>n(`button`,{type:`button`,"aria-pressed":h.includes(e),className:`inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${h.includes(e)?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:bg-surface-hover`}`,onClick:()=>y(e),children:_.get(e)},e))})]}),t&&n(Ee,{devices:o,listState:s,value:h,onChange:e=>g(e),noun:`device`,emptyLabel:m(`locations.addDialog.nonePicked`),showAll:!0,lockedIds:c,lockedNote:l,testId:`quick-add-picker`})]}),e(W,{children:[n(q,{variant:`ghost`,onClick:p,children:m(`locations.addDialog.cancel`)}),n(q,{disabled:h.length===0||d,onClick:()=>f(h),children:m(`locations.addDialog.confirm`,{count:h.length})})]})]})})}a();function vt({room:e,cameras:r,fleet:i}){let{t:a}=Y(),o=t(()=>new Map(i.map(e=>[e.id,e])),[i]);return e===null?n(`p`,{className:`text-xs text-foreground-subtle`,children:a(`locations.links.noRoom`)}):n(`div`,{className:`flex flex-col gap-3`,"data-testid":`camera-links-section`,children:r.length===0?n(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`camera-links-empty`,children:a(`locations.links.noCameras`,{room:e})}):r.map(e=>n(bt,{camera:e,byId:o},e.id))})}function yt(e){return{id:e.deviceId,name:e.name,type:e.type,location:e.location}}function bt({camera:t,byId:r}){let{t:a}=Y(),s=De(Z(t),`full`),c=o(),l=Ze(),[u,d]=i(!1),[f,p]=i(null),m=He({deviceId:t.id}),h=rt({status:m.status,data:m.data,error:m.error===null||m.error===void 0?null:m.error}),g=Pe(),_=h.kind===`present`?h:null,v=Be({deviceId:t.id,slotRef:_?.slot.slotRef??``},{enabled:u&&_!==null}),y=_===null?[]:nt(_.slot,_.value),b=y.map(e=>e.deviceId),x=(v.data?.candidates??[]).map(yt),C=new Set(x.map(e=>e.id)),w=b.filter(e=>!C.has(e)).map(e=>{let t=r.get(e);return{id:e,name:t?.name??`#${String(e)}`,...t===void 0?{}:{type:t.type,location:t.location}}}),T=[...x,...w],E=(v.data?.candidates??[]).filter(e=>e.suggested).map(e=>e.deviceId),D=async e=>{if(_!==null){p(null);try{await g.mutateAsync({deviceId:t.id,slotRef:_.slot.slotRef,value:tt(_.value,e)}),await m.refetch(),await c.invalidateQueries({queryKey:[[`deviceManager`]]}),d(!1)}catch(e){p(e instanceof Error?e.message:String(e))}}},O=[{key:`device`,header:a(`locations.columns.device`),notSortableReason:a(`locations.columns.noSort`),render:t=>{let i=r.get(t.deviceId),o=t.name??i?.name??`#${String(t.deviceId)}`;return e(`span`,{className:`flex items-center gap-1.5`,children:[i!==void 0&&n($,{type:i.type}),n(X,{to:`/devices/${String(t.deviceId)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:i===void 0?o:n(K,{device:Z(i),form:`compact`})}),t.implied&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:a(`locations.links.implied`)})]})}},{key:`type`,header:a(`locations.columns.type`),notSortableReason:a(`locations.columns.noSort`),render:e=>n(`span`,{className:`text-xs text-foreground-muted`,children:r.get(e.deviceId)?.type??`—`})},{key:`status`,header:a(`locations.columns.status`),notSortableReason:a(`locations.columns.noSort`),render:t=>{let i=r.get(t.deviceId);return i===void 0?n(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):e(`span`,{className:`flex items-center gap-1.5`,children:[n(ht,{device:i}),n(`span`,{className:`text-xs text-foreground-muted`,children:i.online?a(`common.online`):a(`common.offline`)})]})}}];return e(`section`,{className:`min-w-0 ${S}`,"data-testid":`camera-links-${String(t.id)}`,children:[e(`header`,{className:`${F} flex min-h-9 items-center gap-1.5`,children:[n($,{type:t.type}),n(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:n(K,{device:Z(t),form:`full`})}),e(q,{variant:`ghost`,size:`sm`,onClick:()=>l(Qe(t.id)),children:[n(M,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),a(`locations.links.edit`)]}),n(q,{variant:`outline`,size:`sm`,disabled:_===null,onClick:()=>d(!0),"aria-label":a(`locations.links.addNamed`,{camera:s}),children:a(`locations.room.add`)})]}),h.kind===`pending`&&n(`p`,{role:`status`,className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:a(`locations.links.loading`)}),h.kind===`unknown`&&n(`p`,{role:`alert`,className:`px-3 py-3 text-xs text-warning sm:px-4`,children:a(`locations.links.unreadable`,{reason:h.reason})}),h.kind===`absent`&&n(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:a(`locations.links.unsupported`)}),f!==null&&n(`p`,{role:`alert`,className:`px-3 pt-2 text-xs text-danger break-words sm:px-4`,children:f}),_!==null&&(y.length===0?n(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:a(`locations.links.none`)}):n(U,{columns:O,rows:y,rowKey:e=>String(e.deviceId),bordered:!1,minWidthPx:360})),n(_t,{open:u,title:a(`locations.links.pickTitle`,{camera:s}),items:T,listState:v.status===`error`?`failed`:v.data===void 0?`pending`:`answered`,lockedIds:b,lockedNote:a(`locations.links.alreadyLinked`),suggestions:t.location===null?null:{heading:a(`locations.links.suggested`,{room:t.location}),ids:E},busy:g.isPending,onConfirm:e=>void D(e),onClose:()=>d(!1)})]})}a();function xt({name:t,description:a,busy:o,onSave:s}){let{t:c}=Y(),[l,u]=i(a??``);return r(()=>{u(a??``)},[a]),e(`div`,{className:`border-t border-border px-3 py-2 sm:px-4`,children:[n(Ce,{htmlFor:`location-description-${t}`,className:`block`,children:c(`locations.locationDescriptionField.whatIsThere`,`What is there`)}),n(`textarea`,{id:`location-description-${t}`,value:l,onChange:e=>u(e.target.value),onBlur:()=>{let e=l.trim();e!==(a??``)&&s(e.length===0?null:e)},disabled:o,rows:2,maxLength:400,placeholder:c(`locations.locationDescriptionField.surfacesBoundariesWhatIsNormally`,`Surfaces, boundaries, what is normally parked or stored here.`),className:`mt-1 w-full resize-y rounded-md border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-inset focus:ring-primary disabled:cursor-not-allowed disabled:opacity-50`}),n(`p`,{className:`mt-1 ${se}`,children:c(`locations.locationDescriptionField.givenToTheAiWith`,`Given to the AI with the pictures, so it knows what it is looking at. Describe the PLACE, not what happens in it — events change, the ground does not.`)})]})}function St(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0||n.description.length===0?null:n.description}var Ct=` none`;function wt({name:t,zones:r,zoneKey:i,busy:a,onChange:o}){let{t:s}=Y();if(r.length===0)return null;let c=[{value:Ct,label:s(`locations.locationZoneField.none`,`— none —`)},...r.map(e=>({value:e.zoneKey,label:e.label}))];return e(`div`,{className:`flex items-center gap-2 border-t border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:[n(Ce,{htmlFor:`location-zone-${t}`,children:s(`locations.locationZoneField.zone`,`Zone`)}),n(H,{id:`location-zone-${t}`,value:i??Ct,disabled:a,onChange:e=>{let t=e.target.value;if(t===Ct){o(null);return}let n=r.find(e=>e.zoneKey===t);n!==void 0&&o(n.label)},options:c})]})}function Tt(e,t){return e.find(e=>e.locationKeys.includes(t))?.zoneKey??null}function Et({name:e,icon:t,busy:r,onPick:i}){return n(Se,{value:t,onPick:i,fallbackGlyph:te,clearGlyph:c,labels:{trigger:`Change the icon of ${e}`,panel:`Icon for ${e}`,searchPlaceholder:`Search icons`,clear:`No icon`,noMatches:`No icon matches that`},disabled:r})}function Dt(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0?null:ue(n.icon)??`map-pin`}function Ot(e){return`${e.kind}:${String(e.device.id)}`}function kt(e,t,n){return e.flatMap(e=>{let r=ft(t,e.id),i=n.has(e.id),a={kind:`member`,device:e,accessories:r,open:i};return!i||r.length===0?[a]:[a,...r.map(t=>({kind:`accessory`,device:t,parent:e}))]})}a();function At({name:r,members:a,devices:o,busy:c,icon:l,description:u,onRename:d,onDelete:f,onRebuildLinks:m,onAddDevices:h,onPickIcon:g,onSaveDescription:y,zones:b,zoneKey:x,onChangeZone:C}){let{t:w}=Y(),[T,E]=i(!1),[D,O]=i(r),k=Me(a,t(()=>({searchText:e=>[e.name,...ft(o,e.id).map(e=>e.name)],facetValue:e=>e.type}),[o])),[A,ee]=i(()=>new Set),j=e=>ee(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),te=t(()=>kt(k.rows,o,A),[k.rows,o,A]),M=[{key:`name`,header:w(`locations.columns.device`),notSortableReason:w(`locations.columns.noSort`),render:e=>e.kind===`member`?n(jt,{row:e,onToggle:()=>j(e.device.id)}):n(Mt,{row:e})},{key:`type`,header:w(`locations.columns.type`),notSortableReason:w(`locations.columns.noSort`),render:e=>n(`span`,{className:`text-xs text-foreground-muted`,children:e.device.type})},{key:`status`,header:w(`locations.columns.status`),notSortableReason:w(`locations.columns.noSort`),render:t=>e(`span`,{className:`flex items-center gap-1.5`,children:[n(ht,{device:t.device}),n(`span`,{className:`text-xs text-foreground-muted`,children:t.device.online?w(`common.online`):w(`common.offline`)})]})}],P=()=>{O(r),E(!1)},I=async()=>{let e=D.trim();if(e.length===0||e===r){P();return}await d(e),E(!1)},L=[{id:`rename`,label:w(`locations.locationCard.rename`,`Rename`),icon:_,disabled:c,onClick:()=>{O(r),E(!0)}},{id:`rebuild-links`,label:w(`locations.locationCard.rebuildLinkedDevices`,`Rebuild linked devices`),icon:p,separatorBefore:!0,disabled:c,onClick:()=>void m()},{id:`delete`,label:w(`common.delete`,`Delete`),icon:v,danger:!0,separatorBefore:!0,disabled:c,onClick:()=>void f()}];return e(`section`,{className:`min-w-0 ${S}`,children:[e(`header`,{className:`${F} flex min-h-9 items-center gap-1.5`,children:[n(Et,{name:r,icon:l,busy:c,onPick:g}),T?e(s,{children:[n(G,{value:D,onChange:e=>O(e.target.value),onKeyDown:e=>{e.key===`Enter`&&I(),e.key===`Escape`&&P()},"aria-label":w(`locations.locationCard.rename2`,`Rename {{name}}`,{name:r}),className:`min-w-0 flex-1`,autoFocus:!0}),n(q,{type:`button`,size:`sm`,onClick:()=>void I(),children:w(`common.save`,`Save`)}),n(be,{type:`button`,variant:`ghost`,icon:N,onClick:P,"aria-label":w(`locations.locationCard.cancelRename`,`Cancel rename`)})]}):e(s,{children:[n(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:r}),n(q,{type:`button`,variant:`outline`,size:`sm`,disabled:c,onClick:h,"aria-label":w(`locations.room.addTo`,{room:r}),children:w(`locations.room.add`)}),n(Ke,{items:L,title:w(`locations.locationCard.actionsFor`,`Actions for {{name}}`,{name:r}),triggerClassName:`p-1`})]})]}),n(wt,{name:r,zones:b,zoneKey:x,busy:c,onChange:C}),n(xt,{name:r,description:u,busy:c,onSave:y}),a.length>0&&n(`div`,{className:`border-b border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:n(qe,{state:k.state,facets:k.facets,labels:{searchPlaceholder:w(`locations.filter.searchPlaceholder`),searchLabel:w(`locations.room.searchLabel`,{room:r}),facetsLabel:w(`locations.filter.typesLabel`),clearLabel:w(`locations.filter.clear`)},onSearch:k.setSearch,onToggleFacet:k.toggleFacet,onClear:k.clear})}),a.length===0?n(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:w(`locations.locationCard.nothingHereYetAssignA`,`Nothing here yet — assign a device from the table below.`)}):n(U,{columns:M,rows:te,rowKey:Ot,bordered:!1,minWidthPx:360,emptyMessage:w(`locations.filter.noMatch`)})]})}function jt({row:t,onToggle:r}){let{t:i}=Y(),{device:a,accessories:o,open:s}=t,c=De(Z(a),`compact`),l=s?I:f;return e(`span`,{className:`flex items-center gap-1.5`,children:[o.length>0?e(q,{type:`button`,variant:`ghost`,onClick:r,"aria-expanded":s,"aria-label":i(s?`locations.locationCard.collapseAccessories`:`locations.locationCard.expandAccessories`,{count:o.length,name:c}),className:`h-auto shrink-0 gap-0.5 p-0.5 text-foreground-subtle hover:text-foreground`,children:[n(l,{className:`h-3 w-3`}),n(`span`,{className:`text-[10px] tabular-nums`,children:o.length})]}):n(`span`,{"aria-hidden":`true`,className:`w-[1.35rem] shrink-0`}),n($,{type:a.type}),n(X,{to:`/devices/${String(a.id)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:n(K,{device:Z(a),form:`compact`})})]})}function Mt({row:t}){let{device:r,parent:i}=t;return e(`span`,{className:`flex items-center gap-1.5 pl-6`,children:[n(`span`,{"aria-hidden":`true`,className:`text-[10px] text-foreground-subtle`,children:`└`}),n($,{type:r.type,className:`h-3 w-3 shrink-0 text-foreground-subtle`}),n(X,{to:`/devices/${String(r.id)}`,className:`min-w-0 truncate text-xs text-foreground-muted hover:underline`,children:n(K,{device:Z(r),form:`nested`,parent:Z(i)})})]})}a();function Nt({zones:e,busy:t,onRename:r,onDelete:a,onPickIcon:o}){let{t:s}=Y(),[c,l]=i(null),[u,d]=i(``),f=async e=>{let t=u.trim();l(null),!(t.length===0||t===e)&&await r(e,t)};return n(U,{columns:[{key:`icon`,header:s(`locations.siteZonesPanel.icon`,`Icon`),width:`w-12`,notSortableReason:`An icon has no order`,render:e=>n(Et,{name:e.label,icon:e.icon,busy:t,onPick:t=>o(e.label,t)})},{key:`name`,header:s(`locations.siteZonesPanel.zone`,`Zone`),sortValue:e=>e.label.toLowerCase(),render:e=>c===e.label?n(G,{value:u,onChange:e=>d(e.target.value),onKeyDown:t=>{t.key===`Enter`&&f(e.label),t.key===`Escape`&&l(null)},onBlur:()=>void f(e.label),"aria-label":s(`locations.siteZonesPanel.rename`,`Rename {{label}}`,{label:e.label}),autoFocus:!0}):n(q,{type:`button`,variant:`ghost`,size:`sm`,className:`px-0`,onClick:()=>{d(e.label),l(e.label)},disabled:t,title:s(`locations.siteZonesPanel.renameTheZone`,`Rename the zone`),children:e.label})},{key:`rooms`,header:s(`locations.siteZonesPanel.rooms`,`Rooms`),align:`right`,sortValue:e=>e.locationKeys.length,render:e=>n(`span`,{className:`tabular-nums text-foreground-subtle`,children:e.locationKeys.length===0?s(`common.empty`):s(`common.rooms`,{count:e.locationKeys.length})})},{key:`actions`,header:s(`locations.siteZonesPanel.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order`,render:e=>n(q,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void a(e.label),disabled:t,"aria-label":s(`locations.siteZonesPanel.delete`,`Delete {{label}}`,{label:e.label}),title:s(`locations.siteZonesPanel.deleteTheZoneTheRooms`,`Delete the zone — the rooms in it are kept`),children:n(v,{className:`h-3.5 w-3.5`})})}],rows:e,rowKey:e=>e.zoneKey,emptyMessage:s(`locations.siteZonesPanel.noZonesYetAZone`,`No zones yet. A zone groups rooms — “Night zone” for the bedrooms — and shows up before them in the app’s camera filter.`)})}a();function Pt({busy:t,onCreate:r}){let{t:a}=Y(),[o,s]=i(!1),[c,l]=i(``),u=()=>{l(``),s(!1)},d=async()=>{let e=c.trim();e.length!==0&&(await r(e),u())};return o?e(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),d()},children:[n(G,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&u()},placeholder:a(`locations.newLocationButton.frontDoorHallKitchen`,`Front door, Hall, Kitchen…`),"aria-label":a(`locations.newLocationButton.newLocationName`,`New location name`),className:`min-w-[12rem] flex-1`,autoFocus:!0}),e(q,{size:`sm`,type:`submit`,disabled:c.trim().length===0||t,children:[n(y,{className:`h-3.5 w-3.5`}),a(`common.add`,`Add`)]}),n(q,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":a(`locations.newLocationButton.cancelNewLocation`,`Cancel new location`),children:n(N,{className:`h-3.5 w-3.5`})})]}):e(q,{size:`sm`,type:`button`,onClick:()=>s(!0),"data-testid":`new-location-button`,children:[n(y,{className:`h-3.5 w-3.5`}),a(`locations.newLocationButton.newLocation`,`New location`)]})}a();function Ft({busy:t,onCreate:r}){let{t:a}=Y(),[o,s]=i(!1),[c,l]=i(``),u=()=>{l(``),s(!1)},d=async()=>{let e=c.trim();e.length!==0&&(await r(e),u())};return o?e(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),d()},children:[n(G,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&u()},placeholder:a(`locations.newZoneButton.zonaGiornoZonaNotte`,`Zona giorno, Night zone…`),"aria-label":a(`locations.newZoneButton.newZoneName`,`New zone name`),className:`min-w-[12rem] flex-1`,autoFocus:!0}),e(q,{size:`sm`,type:`submit`,disabled:c.trim().length===0||t,children:[n(y,{className:`h-3.5 w-3.5`}),a(`common.add`,`Add`)]}),n(q,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":a(`locations.newZoneButton.cancelNewZone`,`Cancel new zone`),children:n(N,{className:`h-3.5 w-3.5`})})]}):e(q,{size:`sm`,type:`button`,onClick:()=>s(!0),"data-testid":`new-zone-button`,children:[n(y,{className:`h-3.5 w-3.5`}),a(`locations.newZoneButton.newZone`,`New zone`)]})}a();function It(e,t,n,r){let i=e.map(e=>({value:e.name,label:`${e.name} · ${String(e.count)}`}));return t===void 0?i:[...i,{value:n,label:`${r} · ${String(t)}`}]}function Lt({rooms:e,unassignedCount:r,value:i,unassignedValue:a,onChange:o}){let{t:s}=Y(),c=t(()=>It(e,r,a,s(`locations.roomPicker.unassigned`)),[e,r,a,s]);return n(`div`,{className:`max-w-sm`,"data-testid":`room-select`,children:n(ze,{mode:`single`,singleDisplay:`field`,label:s(`locations.roomPicker.label`),placeholder:s(`locations.roomPicker.placeholder`),options:c,value:i,onChange:o,searchable:!0,testId:`room-select-control`,optionTestIdPrefix:`room-option`})})}a();var Rt={searchText:e=>[e.name],facetValue:e=>e.type};function zt({rows:r,fleet:a,locations:o,busy:s,emptyMessage:c,onAssign:l}){let{t:u}=Y(),d=Ae(),f=_e(),p=e=>d===null?e.name:ye(Z(e),`compact`,d,f),[m,h]=i([]),[g,_]=i(``),v=Me(r,Rt),y=v.rows,b=t(()=>y.map(e=>e.id),[y]),x=t(()=>m.filter(e=>b.includes(e)),[m,b]),S=y.length>0&&x.length===y.length,w=t(()=>{let e=new Map;for(let t of r)e.set(t.id,dt(a,t.id));return e},[r,a]),T=x.reduce((e,t)=>e+(w.get(t)??0),0),E=e=>h(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),D=()=>h(S?[]:b),O=()=>{g.length===0||x.length===0||(l(x,g),h([]),_(``))},k=o.map(e=>({value:e,label:e})),A=[{key:`select`,width:`w-8`,headerRender:()=>n(je,{checked:S,onChange:D,"aria-label":S?u(`locations.unassignedTable.clearSelection`,`Clear selection`):u(`locations.unassignedTable.selectAllUnassignedDevices`,`Select all unassigned devices`)}),render:e=>n(je,{checked:x.includes(e.id),onChange:()=>E(e.id),"aria-label":u(`locations.unassignedTable.select`,`Select {{name}}`,{name:p(e)})})},{key:`name`,header:u(`locations.unassignedTable.device`,`Device`),sortValue:e=>e.name.toLowerCase(),render:t=>{let r=ot(t,o);return e(`span`,{className:`flex items-center gap-1.5`,children:[n($,{type:t.type}),n(X,{to:`/devices/${String(t.id)}`,className:`truncate text-xs text-foreground hover:underline`,children:n(K,{device:Z(t),form:`compact`})}),r!==null&&n(Fe,{variant:`warning`,children:u(`locations.unassignedTable.unknownRoom`,{room:r})})]})}},{key:`type`,header:u(`locations.unassignedTable.type`,`Type`),sortValue:e=>e.type,render:e=>n(`span`,{className:`text-xs text-foreground-muted`,children:e.type})},{key:`status`,header:u(`locations.unassignedTable.status`,`Status`),sortValue:e=>+!!e.online,render:t=>e(`span`,{className:`flex items-center gap-1.5`,children:[n(ht,{device:t}),n(`span`,{className:`text-xs text-foreground-muted`,children:t.online?u(`common.online`):u(`common.offline`)})]})},{key:`followers`,header:u(`locations.unassignedTable.accessoriesInTowCount`,`Accessories in tow`),align:`right`,sortValue:e=>w.get(e.id)??0,render:e=>n(`span`,{className:`tabular-nums text-xs text-foreground-muted`,children:w.get(e.id)??0})},{key:`assign`,header:u(`locations.unassignedTable.assignTo`,`Assign to`),align:`right`,notSortableReason:`This column is a control, not a value.`,render:e=>n(H,{"aria-label":u(`locations.unassignedTable.locationFor`,`Location for {{name}}`,{name:p(e)}),value:``,disabled:s||o.length===0,onChange:t=>{let n=t.target.value;n.length!==0&&l([e.id],n)},className:`max-w-[11rem]`,options:[{value:``,label:`—`},...k]})}];return e(`section`,{className:`space-y-2`,children:[e(`header`,{className:`flex flex-wrap items-baseline gap-2`,children:[n(`h2`,{className:C,children:u(`locations.unassignedTable.notInARoom`,`Not in a room`)}),n(`p`,{className:se,children:u(`locations.unassignedTable.topLevelDevicesOnlyAccessories`,`Top-level devices only — accessories move with their parent.`)})]}),r.length>0&&n(qe,{state:v.state,facets:v.facets,labels:{searchPlaceholder:u(`locations.filter.searchPlaceholder`),searchLabel:u(`locations.unassigned.searchLabel`),facetsLabel:u(`locations.filter.typesLabel`),clearLabel:u(`locations.filter.clear`)},onSearch:v.setSearch,onToggleFacet:v.toggleFacet,onClear:v.clear}),x.length>0&&e(`div`,{role:`group`,"aria-label":u(`locations.unassignedTable.bulkAssignment`,`Bulk assignment`),className:`flex flex-wrap items-center gap-2 rounded border border-primary/40 bg-primary/5 px-2 py-1.5`,children:[e(`span`,{className:`text-xs text-foreground`,children:[u(`locations.unassignedTable.selected`,{count:x.length}),T>0&&` · ${u(`locations.unassignedTable.accessoriesInTowCount`,{count:T})}`]}),n(H,{"aria-label":u(`locations.unassignedTable.assignSelectedDevicesTo`,`Assign selected devices to`),value:g,onChange:e=>_(e.target.value),className:`w-auto min-w-[10rem]`,options:[{value:``,label:u(`locations.unassignedTable.assignTo2`,`Assign to…`)},...k]}),n(q,{type:`button`,size:`sm`,onClick:O,disabled:s||g.length===0,children:u(`locations.unassignedTable.assign`,`Assign`)}),n(q,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>h([]),children:u(`locations.unassignedTable.clear`,`Clear`)})]}),n(U,{columns:A,rows:y,rowKey:e=>e.id,minWidthPx:720,emptyMessage:v.active?u(`locations.filter.noMatch`):c})]})}function Bt(e){return{id:e.id,parentDeviceId:e.parentDeviceId,location:e.location,type:e.type,stableId:e.stableId??``,...e.primaryChildEntityId===void 0?{}:{primaryChildEntityId:e.primaryChildEntityId},...e.role!==void 0&&e.role!==null?{role:e.role}:{},name:e.name}}function Vt(e,t){let n=t.map(Bt),r=[];for(let i of t)i.isCamera&&i.location===e&&r.push({deviceId:i.id,name:i.name,ids:ce({selfId:i.id,selfLocation:i.location,candidates:n})});return{entries:r}}var Ht=`device-manager:linked-devices`;function Ut(e){return{deviceId:e.deviceId,slotRef:Ht,value:{slot:`linked-devices`,deviceIds:[...e.ids]}}}a();var Wt=`__unassigned__`;function Gt(){let{t:r}=Y(),a=o(),s=ae(),{data:c,isLoading:l}=he(),{data:u}=Xe(),{data:d}=we(),{data:f}=ve(),{data:p,isLoading:m}=ge({projection:`slim`}),h=()=>{a.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listLocationIcons`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listLocationDescriptions`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listSiteZones`]]})},g=Ie({onSuccess:h}),_=Ve({onSuccess:h}),v=me({onSuccess:h}),y=ke({onSuccess:h}),b=We({onSuccess:h}),x=Le({onSuccess:h}),S=Ue({onSuccess:h}),C=xe({onSuccess:h}),w=Oe({onSuccess:h}),T=Re({onSuccess:h}),E=Pe(),D=t(()=>(p??[]).map(e=>({id:e.id,name:e.name,location:e.location??null,type:String(e.type),isCamera:e.isCamera,parentDeviceId:e.parentDeviceId,online:e.online,role:e.role??null,stableId:e.stableId,primaryChildEntityId:e.primaryChildEntityId??null})),[p]),O=c??[],k=t(()=>pt(D,O),[D,O]),[A,ee]=$e(),j=A.get(`tab`),M=j===`zones`||j===`camera-links`?j:`locations`,N=A.get(`room`),P=t(()=>lt(D,O),[D,O]),F=N===Wt,I=F?null:N!==null&&k.some(e=>e.name===N)?N:k[0]?.name??null,L=I===null?null:k.find(e=>e.name===I)??null,ne=F?Wt:I??`__unassigned__`,R=I??k[0]?.name??null,re=t(()=>k.map(e=>({name:e.name,count:e.members.length})),[k]),ie=e=>{ee(t=>{let n=new URLSearchParams(t);return n.set(`room`,e),n},{replace:!0})},z=l||m,B=v.isPending||_.isPending||g.isPending||b.isPending,oe=async e=>{await g.mutateAsync({name:e})},se=async(e,t)=>{let n=t.trim();n.length===0||n===e||await y.mutateAsync({from:e,to:n})},ce=async e=>{let t=Vt(e,D);if(t.entries.length===0){await s({title:r(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:r(`locations.noCameraIsAssignedTo`,`No camera is assigned to “{{room}}”.`,{room:e}),confirmLabel:`OK`});return}let n=t.entries.map(e=>r(`locations.rebuildEntry`,{name:e.name,count:e.ids.length})).join(`
|
|
2
|
-
`);if(!await s({title:r(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:r(`locations.replaceTheLinkedDeviceList`,`Replace the linked-device list of every camera in “{{room}}” with what the room contains? {{lines}} Anything linked by hand that is not in this room is lost.`,{room:e,lines:n}),confirmLabel:r(`locations.rebuild`,`Rebuild`),variant:`danger`}))return;let i=[];for(let e of t.entries)try{await E.mutateAsync(Ut(e))}catch(t){i.push(`• ${e.name}: ${t instanceof Error?t.message:String(t)}`)}h(),i.length>0&&await s({title:r(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:r(`locations.notRebuilt`,`Not rebuilt: {{value1}}`,{value1:i.join(`
|
|
3
|
-
`)}),confirmLabel:`OK`})},ue=async(e,t)=>{let n=t>0?` ${String(t)} device(s) will become unassigned.`:``;await s({title:r(`locations.deleteLocation`,`Delete location`),message:r(`locations.deleteTheLocation`,`Delete the location “{{name}}”?{{extra}}`,{name:e,extra:n}),confirmLabel:r(`common.delete`,`Delete`),variant:`danger`})&&await _.mutateAsync({name:e,cascade:!0})},de=async e=>{await s({title:r(`locations.deleteZone`,`Delete zone`),message:r(`locations.deleteTheZoneTheRooms`,`Delete the zone “{{name}}”? The rooms in it are kept.`,{name:e}),confirmLabel:r(`common.delete`,`Delete`),variant:`danger`})&&await C.mutateAsync({name:e})},fe=async(e,t)=>{await b.mutateAsync({location:e,icon:t})},pe=async(e,t)=>{await x.mutateAsync({location:e,description:t})},V=f??[],H=async(e,t)=>{await T.mutateAsync({location:e,zone:t})},U=(e,t)=>{for(let n of e)v.mutate({deviceId:n,location:t})},[W,G]=i(null),_e=t(()=>D.filter(e=>e.parentDeviceId===null).map(e=>({id:e.id,name:e.name,type:e.type,location:e.location})),[D]),ye=n(Lt,{rooms:re,...M===`locations`?{unassignedCount:P.length}:{},value:M===`locations`?ne:R??``,unassignedValue:Wt,onChange:ie}),be=e(`div`,{className:`flex flex-col gap-3`,"data-testid":`locations-section`,children:[z&&n(`p`,{className:`text-xs text-foreground-subtle`,children:r(`locations.loadingLocationsAndDevices`,`Loading locations and devices…`)}),ye,F||L===null?n(zt,{rows:P,fleet:D,locations:O,busy:B,emptyMessage:z?r(`common.loading`,`Loading…`):r(`locations.everyTopLevelDeviceHas`,`Every top-level device has a room.`),onAssign:U}):n(At,{name:L.name,members:L.members,devices:D,busy:B,icon:Dt(u,le(L.name)),onPickIcon:e=>fe(L.name,e),description:St(d,le(L.name)),onSaveDescription:e=>pe(L.name,e),zones:V,zoneKey:Tt(V,le(L.name)),onChangeZone:e=>H(L.name,e),onRename:e=>se(L.name,e),onDelete:()=>ue(L.name,it(D,L.name).length),onRebuildLinks:()=>ce(L.name),onAddDevices:()=>G(L.name)},L.name),O.length===0&&!z&&n(`p`,{className:`text-xs text-foreground-subtle`,children:r(`locations.noLocationsYetAddFrontDoor`,`No locations yet. Add Front door, Hall, Kitchen…`)}),n(_t,{open:W!==null,title:r(`locations.room.addDialogTitle`,{room:W??``}),items:_e,listState:m?`pending`:`answered`,lockedIds:W===null?[]:(k.find(e=>e.name===W)?.members??[]).map(e=>e.id),lockedNote:r(`locations.room.alreadyHere`),suggestions:{heading:r(`locations.room.suggestedUnassigned`),ids:P.map(e=>e.id)},busy:v.isPending,onConfirm:e=>{W!==null&&U(e,W),G(null)},onClose:()=>G(null)})]}),Se=e(`div`,{className:`flex flex-col gap-3`,"data-testid":`camera-links-tab`,children:[ye,n(vt,{room:R,cameras:R===null?[]:it(D,R).filter(e=>e.isCamera),fleet:D})]});return n(et,{icon:te,title:r(`locations.locations`,`Locations`),subtitle:r(`locations.roomsAndAreasOfThe`,`Rooms and areas of the site. Assign any device here — storage disks are under Data → Storage.`),defaultSection:`locations`,sectionsLabel:`Locations sections`,actions:M===`zones`?n(Ft,{busy:S.isPending,onCreate:e=>S.mutateAsync({name:e})}):n(Pt,{busy:g.isPending,onCreate:oe}),sections:[{id:`locations`,label:r(`locations.locations`,`Locations`),content:be},{id:`camera-links`,label:r(`locations.cameraLinks`,`Camera links`),content:Se},{id:`zones`,label:r(`locations.zones`,`Zones`),content:n(Nt,{zones:V,busy:B,onRename:(e,t)=>w.mutateAsync({from:e,to:t}),onDelete:de,onPickIcon:(e,t)=>S.mutateAsync({name:e,icon:t})})}]})}export{Gt as LocationsPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{C as e,K as t,R as n,S as r,V as i,Y as a,et as o,o as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Ai as l,D as u,Dn as d,En as f,Ht as p,In as m,Kn as h,L as g,Ln as _,Z as v,_n as y,ai as b,bt as x,dt as S,fn as C,gt as w,pr as T,qr as E,rn as ee,tn as D,ur as O,xn as te,zt as k}from"./player-overlays-DgedyCX9.js";import{ci as ne,dr as re,li as ie,ri as ae}from"./client-F3l12jEi.js";import{t as A}from"./boxes-BZMO9uMf.js";import{s as oe,u as j}from"./video-5IaJhdjU.js";import{t as se}from"./log-in-Cxvw8rxc.js";import{$s as ce,Ad as le,An as ue,Cc as de,Dn as fe,Fd as pe,Fo as me,Hi as M,Nr as he,On as ge,Or as _e,Qs as ve,Sc as ye,Tn as be,Ui as N,Zn as xe,_c as Se,ac as Ce,cc as we,di as P,ec as Te,fd as Ee,gc as De,hc as Oe,lc as ke,mc as Ae,oc as je,rc as Me,ri as F,vc as Ne,xc as Pe}from"./src-B0EA_4Ed.js";import{t as I}from"./i18n-BH0PY6IL.js";import{t as L}from"./useTranslation-BJr-n0es.js";import"./mount-Fpx4y0MY.js";import{T as Fe,a as R,hr as Ie,i as z,mr as Le,yr as Re}from"./index-CQ7TjSgs.js";import{t as ze}from"./AdminSectionedPage-B4MRvqE8.js";import{t as B}from"./AdminPage-CYSYefaL.js";import{t as Be}from"./NodeAddonsSettingsPanel-Do_I93Mx.js";import{n as V,r as Ve,t as H}from"./IntegrationHub-8GCewFBs.js";import{n as U,t as W}from"./addon-display-names-BkwMrExv.js";o();var G=5e3,K=`network-access`,He={connected:!1,endpoint:null};function Ue(){let{t:e}=L(),n=s(),i=N({capName:`network-access`},{refetchInterval:G}),o=M(void 0,{refetchInterval:G}),c=t(()=>W(o.data??[]),[o.data]),l=t(()=>(i.data??[]).map(e=>({addonId:e.addonId,displayName:c.get(e.addonId)??e.addonId,isActive:e.isActive})),[i.data,c]),[u,d]=a(null),[f,p]=a({}),m=(e,t)=>{let r=t?.addonId;n.invalidateQueries({queryKey:[[`networkAccess`,`getStatus`],{input:{addonId:r},type:`query`}]}),d(null),p(e=>{if(r===void 0||!(r in e))return e;let t={...e};return delete t[r],t})},h=(e,t)=>{d(null);let n=t?.addonId;if(n===void 0)return;let r=e instanceof Error?e.message:String(e);p(e=>({...e,[n]:r}))},g=ye({onSuccess:m,onError:h}),_=de({onSuccess:m,onError:h}),v=[{id:K,label:e(`system.remoteAccess.remoteAccess`,`Remote access`),install:{capability:K,label:e(`system.remoteAccess.addTunnel`,`Add tunnel`)},entries:l.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:j,...U(e.isActive),render:()=>r(V,{addonId:e.addonId,displayName:e.displayName,capName:K,isActive:e.isActive,badges:r(Ge,{addonId:e.addonId}),error:f[e.addonId]??null,primaryAction:r(Ke,{addonId:e.addonId,busyId:u,onStart:e=>{d(e),g.mutate({addonId:e})},onStop:e=>{d(e),_.mutate({addonId:e})}})})}))}];return r(H,{embedded:!0,icon:j,title:e(`system.remoteAccess.remoteAccess2`,`Remote Access`),subtitle:e(`system.remoteAccess.publicFacingTunnelsThatExpose`,`Public-facing tunnels that expose this hub to the internet (Cloudflare Tunnel, ngrok, …).`),groups:v,isLoading:i.isLoading,emptyTitle:e(`system.remoteAccess.noRemoteAccessProvidersInstalled`,`No remote-access providers installed`),emptyDescription:e(`system.remoteAccess.installATunnelAddonE`,`Install a tunnel addon (e.g. @camstack/addon-cloudflare) to expose this hub publicly.`)})}function We(e){let{data:t}=Pe({addonId:e},{refetchInterval:G,retry:!1}),n=t?ae.safeParse(t):null;return n?.success?n.data:He}function Ge({addonId:t}){let{t:n}=L(),i=We(t);return e(c,{children:[r(P,{variant:i.connected?`success`:`default`,className:Ve,children:i.connected?n(`system.remoteAccess.connected`,`Connected`):n(`system.remoteAccess.disconnected`,`Disconnected`)}),i.endpoint&&e(`a`,{href:i.endpoint.url,target:`_blank`,rel:`noopener noreferrer`,className:`flex min-w-0 items-center gap-1 break-all text-[11px] text-success hover:underline`,children:[r(E,{className:`h-3 w-3`}),i.endpoint.url]})]})}function Ke({addonId:t,busyId:n,onStart:i,onStop:a}){let{t:o}=L(),s=We(t),c=n===t;return s.connected?e(F,{size:`sm`,variant:`secondary`,disabled:c,onClick:()=>a(t),children:[c?r(T,{className:`h-3 w-3 animate-spin`}):r(D,{className:`h-3 w-3`}),o(`system.remoteAccess.stop`,`Stop`)]}):e(F,{size:`sm`,variant:`primary`,disabled:c,onClick:()=>i(t),children:[c?r(T,{className:`h-3 w-3 animate-spin`}):r(_,{className:`h-3 w-3`}),o(`system.remoteAccess.start`,`Start`)]})}o();var qe=3e4,q=`turn-provider`;function Je(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function Ye(){let{t:n}=L(),i=N({capName:`turn-provider`},{refetchInterval:qe}),a=M(void 0,{refetchInterval:qe}),o=Ee(),s=o.data??[],c=t(()=>W(a.data??[]),[a.data]),l=t(()=>(i.data??[]).map(e=>({addonId:e.addonId,displayName:c.get(e.addonId)??e.addonId,isActive:e.isActive})),[i.data,c]),d=[{id:q,label:n(`system.turnServers.turnProviders`,`TURN providers`),install:{capability:q,label:n(`system.turnServers.addProvider`,`Add provider`)},entries:l.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:h,...U(e.isActive),render:()=>r(V,{addonId:e.addonId,displayName:e.displayName,capName:q,isActive:e.isActive,panels:[{id:`ice-servers`,title:n(`system.turnServers.discoveredIceServers`,`Discovered ICE servers`),icon:h,content:r(Xe,{addonId:e.addonId,enabled:e.isActive})}]})}))}];return r(H,{embedded:!0,icon:h,title:n(`system.turnServers.turnServers`,`TURN Servers`),subtitle:n(`system.turnServers.iceServersUsedForWebrtc`,`ICE servers used for WebRTC NAT traversal. Multiple providers can coexist — the WebRTC layer concatenates servers from all enabled providers per session.`),groups:d,isLoading:i.isLoading,emptyTitle:n(`system.turnServers.noTurnProvidersInstalled`,`No TURN providers installed`),emptyDescription:n(`system.turnServers.installATurnAddonE`,`Install a TURN addon (e.g. @camstack/addon-cloudflare) to enable WebRTC behind restrictive NATs.`),trailing:r(ge,{headingId:`turn-combined-ice`,title:n(`system.turnServers.combinedIceServerListAll`,`Combined ICE server list — all enabled providers`),icon:h,actions:r(F,{size:`sm`,variant:`secondary`,onClick:()=>o.refetch(),disabled:o.isFetching,children:n(`common.refresh`,`Refresh`)}),children:r(`div`,{className:u,children:s.length===0?r(`div`,{className:`text-xs text-foreground-subtle`,children:n(`system.turnServers.noServersFromEnabledProviders`,`No servers from enabled providers.`)}):r(`div`,{className:`flex flex-col gap-3`,children:s.map((t,n)=>{let i=Array.isArray(t.urls)?t.urls:[t.urls];return e(`div`,{className:`rounded border border-border bg-surface`,children:[(t.username||t.credential)&&e(`div`,{className:`px-3 py-1.5 border-b border-border text-[10px] font-mono text-foreground-subtle flex items-center gap-3`,children:[t.username&&e(`span`,{children:[r(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,r(`span`,{className:`text-foreground`,children:t.username})]}),t.credential&&e(`span`,{children:[r(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,r(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),r(`ul`,{className:`divide-y divide-border`,children:i.map(e=>r(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},n)})})})})})}function Xe({addonId:e,enabled:n}){let i=Ee({addonId:e},{enabled:n,retry:!1}),a=t(()=>Je(i.data??[]),[i.data]),o=n?i.isLoading?`Loading…`:a.length===0?`This provider returned no servers.`:null:`Disabled — enable the provider to fetch its servers.`;return r(`div`,{className:`rounded-lg border border-border bg-surface p-2 sm:p-3`,children:o===null?r(`div`,{className:`flex flex-wrap gap-1`,children:a.map(e=>r(`span`,{className:`inline-block break-all rounded bg-foreground-subtle/10 px-1.5 py-0.5 font-mono text-[10px] text-foreground`,children:e},e))}):r(`div`,{className:`text-xs text-foreground-subtle`,children:o})})}o();var Ze={lan:h,wifi:x,docker:A,vpn:O,loopback:y,other:y},Qe={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},$e=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function et(n){let{t:i}=L(),{interfaces:a,disabled:o,hideLoopback:s,ipv4Only:c,emptyMessage:u}=n,d=t(()=>a.filter(e=>!(s&&e.kind===`loopback`||c&&e.family!==`IPv4`)),[a,s,c]),f=t(()=>{let e=new Map;for(let t of d){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return $e.filter(t=>e.has(t)).map(t=>({kind:t,items:e.get(t)}))},[d]),p=e=>n.mode===`single`?n.value===e:n.value.includes(e),m=e=>{if(o||e.kind===`loopback`)return;if(n.mode===`single`){n.onChange(n.value===e.address?null:e.address);return}let t=new Set(n.value);t.has(e.address)?t.delete(e.address):t.add(e.address),n.onChange([...t])};return d.length===0?r(`div`,{className:`text-xs text-foreground-subtle italic`,children:u??i(`shared.addressSelector.noAddressesAvailable`,`No addresses available.`)}):r(`div`,{className:`flex flex-col gap-3`,children:f.map(({kind:t,items:a})=>e(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[e(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[r(Ze[t]??y,{className:`h-3.5 w-3.5 text-foreground-subtle`}),r(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:Qe[t]??t}),e(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,a.length]})]}),r(`ul`,{className:`divide-y divide-border`,children:a.map(t=>{let a=p(t.address),s=t.kind===`loopback`,c=!t.plausible&&!s;return e(`li`,{className:`flex items-center gap-3 px-3 py-2 ${s?`opacity-60 cursor-not-allowed`:o?`opacity-60`:c?`cursor-pointer hover:bg-surface-hover/30 bg-amber-500/[0.04]`:`cursor-pointer hover:bg-surface-hover/30`}`,onClick:()=>m(t),children:[r(`span`,{className:`flex items-center justify-center h-4 w-4 rounded ${n.mode===`single`?`rounded-full`:`rounded`} border ${a?`border-primary bg-primary text-primary-foreground`:`border-border bg-surface`}`,children:a&&r(l,{className:`h-3 w-3`})}),e(`div`,{className:`flex-1 min-w-0 ${c?`text-foreground-subtle`:``}`,children:[e(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[r(`span`,{className:`font-mono text-xs font-semibold ${c?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),r(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-mono`,children:t.family}),t.preferred&&r(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:i(`shared.addressSelector.autoPreferred`,`Auto-preferred`)}),s&&r(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:i(`shared.addressSelector.alwaysIncluded`,`Always included`)}),c&&e(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:t.plausibleReason||void 0,children:[r(k,{className:`h-2.5 w-2.5`}),i(`shared.addressSelector.unlikelyUsable`,`Unlikely usable`)]})]}),e(`div`,{className:`text-xs text-foreground-subtle mt-0.5 font-mono break-all`,children:[t.address,t.cidr&&t.cidr!==t.address?` (${t.cidr})`:``]})]})]},`${t.name}-${t.family}-${t.address}`)})})]},t))})}var J=[{role:`appConnections`,get title(){return I.t(`helpers.addressTableModel.appConnectionsTitle`)},single:!1,get help(){return I.t(`helpers.addressTableModel.appConnectionsHelp`)}},{role:`notificationTaps`,get title(){return I.t(`helpers.addressTableModel.notificationTapsTitle`)},single:!0,get help(){return I.t(`helpers.addressTableModel.notificationTapsHelp`)}},{role:`publicEndpoint`,get title(){return I.t(`helpers.addressTableModel.publicEndpointTitle`)},single:!0,get help(){return I.t(`helpers.addressTableModel.publicEndpointHelp`)}},{role:`internal`,get title(){return I.t(`helpers.addressTableModel.internalTitle`)},single:!0,get help(){return I.t(`helpers.addressTableModel.internalHelp`)}}],tt=`A role with nothing ticked is automatic. Add a custom address when the hub is reached at an address it cannot see itself (NAT, reverse proxy, VPN, Docker bridge).`;function Y(e,t){return e.inUse.includes(t)}function nt(e,t){if(!e.eligible.includes(t))return{kind:`none`};if(e.kind===`app-link`)return Y(e,t)?{kind:`none`}:{kind:`set`,input:{role:t,baseUrl:null,enabled:!0}};if(e.flags.includes(t)||t===`appConnections`&&Y(e,t))return{kind:`set`,input:{role:t,baseUrl:e.baseUrl,enabled:!1}};let n={role:t,baseUrl:e.baseUrl,enabled:!0};return t===`publicEndpoint`&&e.baseUrl.startsWith(`http:`)?{kind:`confirm-http`,input:n,reason:ne}:{kind:`set`,input:n}}function rt(e){return J.map(({role:t,title:n})=>{if(t===`appConnections`){let r=e.roles.appConnections;return{role:t,title:n,inUse:r.resolved.length===0?`nothing reachable`:r.resolved.join(`, `),automatic:r.source!==`flagged`}}let r=e.roles[t];return{role:t,title:n,inUse:r.resolved===null?`nothing reachable`:t===`notificationTaps`&&r.source===`auto`?`CamStack app link`:r.resolved,automatic:r.source!==`flagged`}})}o();var it={"lan-ipv4":{labelKey:`system.addressesCard.kindIpv4`,className:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`},"lan-ipv6":{labelKey:`system.addressesCard.kindIpv6`,className:`bg-violet-500/15 text-violet-700 dark:text-violet-300`},public:{labelKey:`system.addressesCard.kindPublic`,className:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},"app-link":{labelKey:`system.addressesCard.kindAppLink`,className:`bg-amber-500/15 text-amber-700 dark:text-amber-300`},custom:{labelKey:`system.addressesCard.kindCustom`,className:`bg-sky-500/15 text-sky-700 dark:text-sky-300`},loopback:{labelKey:`system.addressesCard.kindLoopback`,className:`bg-foreground-subtle/15 text-foreground-subtle`}};function at({book:t,loading:n,saving:i,error:o,onSetRole:s,onAdd:c,onRemove:l}){let{t:u}=L(),[d,f]=a(``),[h,g]=a(``),[_,v]=a(null),[y,b]=a(null),x=()=>{let e=ie(d);if(!e.ok){v(e.reason);return}v(null),f(``),g(``),c(e.baseUrl,h.trim())},S=(e,t)=>{let n=nt(e,t.role);if(n.kind!==`none`){if(n.kind===`confirm-http`){b({input:n.input,reason:n.reason});return}b(null),s(n.input)}},C=[{key:`url`,header:u(`system.addressesCard.address`,`Address`),render:n=>e(`div`,{className:`min-w-0 py-0.5`,children:[r(`div`,{className:`font-mono text-[12px] break-all ${n.plausible?`text-foreground`:`text-foreground-subtle`}`,children:n.baseUrl}),e(`div`,{className:`mt-0.5 flex flex-wrap items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[r(`span`,{children:n.label}),n.kind===`app-link`&&e(`span`,{className:`font-mono`,children:[`hub=`,` `,t?.appLinkHub??u(`system.addressesCard.noneNoTunnelOrTailscale`,`none (no tunnel or Tailscale)`)]}),n.custom&&n.detected&&r(`span`,{children:u(`system.addressesCard.alsoAddedAsACustom`,`also added as a custom address`)}),n.kind!==`custom`&&n.interfaceKind!==`lan`&&n.interfaceKind!==`public`&&n.interfaceKind!==`other`&&r(`span`,{className:`uppercase tracking-wide`,children:n.interfaceKind}),!n.plausible&&n.interfaceKind!==`loopback`&&e(`span`,{className:`inline-flex items-center gap-1 text-amber-700 dark:text-amber-300`,title:n.plausibleReason||void 0,children:[r(k,{className:`h-2.5 w-2.5`}),u(`system.addressesCard.unlikelyUsable`,`Unlikely usable`)]})]})]})},{key:`kind`,header:u(`system.addressesCard.kind`,`Kind`),nowrap:!0,render:e=>{let t=it[e.kind]??it.loopback;return r(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.className}`,children:u(t.labelKey)})}},...J.map(t=>({key:t.role,headerRender:()=>r(`span`,{title:t.help,children:t.title}),align:`center`,nowrap:!0,width:`w-24`,render:n=>{let a=n.eligible.includes(t.role),o=n.flags.includes(t.role),s=Y(n,t.role);return e(`label`,{className:`inline-flex items-center justify-center gap-1 ${a?`cursor-pointer`:`cursor-not-allowed opacity-40`}`,title:a?s&&!o?u(`system.addressesCard.inUseAutomatically`,`{{title}}: in use automatically. {{help}}`,{title:t.title,help:t.help}):t.help:u(`system.addressesCard.thisAddressCannotBeUsed`,`This address cannot be used for this.`),children:[r(xe,{checked:a&&s,disabled:!a||i,onChange:()=>S(n,t),"aria-label":`${t.title}: ${n.baseUrl}`}),s&&!o&&a&&r(`span`,{className:`text-[9px] text-foreground-subtle`,children:u(`common.auto`)})]})}})),{key:`actions`,header:``,align:`right`,nowrap:!0,render:e=>e.custom?r(F,{size:`sm`,variant:`ghost`,disabled:i,onClick:()=>l(e.baseUrl),"aria-label":u(`system.addressesCard.remove`,`Remove {{baseUrl}}`,{baseUrl:e.baseUrl}),title:u(`system.addressesCard.removeThisCustomAddressIts`,`Remove this custom address (its roles turn automatic)`),children:r(p,{className:`h-3 w-3`})}):null}],w=t===void 0?[]:rt(t);return e(_e,{children:[e(`div`,{className:`px-4 py-3 border-b border-border flex flex-col gap-2`,children:[e(`div`,{children:[r(`div`,{className:`text-sm font-semibold`,children:u(`system.addressesCard.addresses`,`Addresses`)}),r(`div`,{className:`text-xs text-foreground-subtle max-w-3xl`,children:u(`system.addressesCard.everyAddressThisHubIs`,`Every address this hub is reached at, detected or added by you. Tick what each one is used for.`)}),e(`details`,{className:`mt-1.5 text-xs max-w-3xl`,"data-testid":`address-roles-help`,children:[r(`summary`,{className:`cursor-pointer select-none text-foreground-subtle hover:text-foreground`,children:u(`system.addressesCard.whatAreRoles`,`What are roles?`)}),r(`dl`,{className:`mt-1.5 grid grid-cols-[auto_1fr] gap-x-3 gap-y-1`,children:J.map(t=>e(`div`,{className:`contents`,children:[r(`dt`,{className:`font-medium`,children:t.title}),r(`dd`,{className:`text-foreground-subtle`,children:t.help})]},t.role))}),r(`p`,{className:`mt-1.5 text-foreground-subtle`,children:tt})]})]}),w.length>0&&r(`div`,{className:`grid grid-cols-[auto_1fr_auto] gap-x-3 gap-y-1 items-baseline text-xs`,"data-testid":`address-roles-summary`,children:w.map(t=>e(`div`,{className:`contents`,children:[r(`span`,{className:`text-foreground-subtle`,children:t.title}),e(`span`,{className:`font-mono break-all`,"data-testid":`address-role-${t.role}`,children:[t.inUse,r(`span`,{className:`ml-1.5 font-sans text-foreground-subtle`,children:t.automatic?u(`system.addressesCard.automatic`,`(automatic)`):u(`system.addressesCard.setByYou`,`(set by you)`)})]}),t.automatic?r(`span`,{}):r(F,{size:`sm`,variant:`secondary`,disabled:i,onClick:()=>s({role:t.role,baseUrl:null,enabled:!1}),children:u(`system.addressesCard.useAutomatic`,`Use automatic`)})]},t.role))}),y!==null&&e(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-xs flex flex-wrap items-center gap-2`,children:[r(k,{className:`h-3.5 w-3.5 text-amber-600`}),r(`span`,{className:`flex-1 min-w-[220px]`,children:y.reason}),r(F,{size:`sm`,variant:`secondary`,onClick:()=>{s({...y.input,acceptInsecureHttp:!0}),b(null)},children:u(`system.addressesCard.useHttpAnyway`,`Use http anyway`)}),r(F,{size:`sm`,variant:`ghost`,onClick:()=>b(null),children:u(`common.cancel`,`Cancel`)})]}),o!==null&&r(`div`,{className:`text-[11px] text-red-600 dark:text-red-400`,role:`alert`,children:o})]}),r(ue,{columns:C,rows:t?.rows??[],rowKey:e=>`${e.kind}-${e.baseUrl}`,minWidthPx:760,bordered:!1,emptyMessage:n?u(`common.loading`,`Loading…`):u(`system.addressesCard.noAddressesAvailable`,`No addresses available.`),rowClassName:e=>e.plausible?void 0:`opacity-80`}),e(`div`,{className:`px-4 py-3 border-t border-border flex flex-wrap items-start gap-2`,children:[e(`div`,{className:`flex-1 min-w-[220px]`,children:[r(pe,{value:d,onChange:e=>{f(e.target.value),v(null)},placeholder:`https://cams.example.com or https://192.0.2.20:4443`,"aria-label":u(`system.addressesCard.customAddress`,`Custom address`),disabled:i}),_!==null&&r(`div`,{className:`mt-1 text-[11px] text-red-600 dark:text-red-400`,children:_})]}),r(`div`,{className:`w-48`,children:r(pe,{value:h,onChange:e=>g(e.target.value),placeholder:u(`system.addressesCard.labelOptional`,`Label (optional)`),"aria-label":u(`system.addressesCard.customAddressLabel`,`Custom address label`),maxLength:80,disabled:i})}),e(F,{size:`sm`,variant:`secondary`,disabled:i||d.trim()===``,onClick:x,children:[r(m,{className:`h-3 w-3`}),u(`system.addressesCard.addCustomAddress`,`Add custom address`)]})]})]})}o();function ot(){let{t:n}=L(),o=s(),c=()=>{o.invalidateQueries({queryKey:[[`localNetwork`]]})},l=Me(void 0,{refetchInterval:3e4}),p=Te(void 0),m=ke({onSuccess:c}),h=je({onSuccess:e=>{w(e.addresses),c()}}),g=t(()=>l.data?.interfaces??[],[l.data]),_=ce({scheme:typeof window<`u`&&window.location.protocol===`https:`?`https`:`http`},{refetchInterval:3e4}),v=we({onSuccess:c}),y=ve({onSuccess:c}),b=Ce({onSuccess:c}),x=v.error?.message??y.error?.message??b.error?.message??null,S=v.isPending||y.isPending||b.isPending,[C,w]=a([]),[T,E]=a(!1);i(()=>{!T&&p.data&&(w(p.data.addresses),E(!0))},[p.data,T]);let D=p.data?.addresses??[],O=t(()=>{if(C.length!==D.length)return!0;let e=[...C].toSorted(),t=[...D].toSorted();return e.some((e,n)=>e!==t[n])},[C,D]);return e(B,{embedded:!0,children:[e(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[r(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:n(`system.networkAddresses.pinWhichHostInterfacesExist`,`Pin which host interfaces exist, then tick what each address is used for. Add a custom address when this hub is reached at one it cannot detect.`)}),r(`div`,{className:`flex items-center gap-2 shrink-0`,children:e(F,{size:`sm`,variant:`secondary`,onClick:()=>{l.refetch(),p.refetch(),_.refetch()},disabled:l.isLoading,children:[r(d,{className:`h-3 w-3 ${l.isLoading?`animate-spin`:``}`}),n(`common.refresh`,`Refresh`)]})})]}),r(ge,{headingId:`network-allowed-addresses`,title:n(`system.networkAddresses.allowedAddresses`,`Allowed addresses`),actions:e(`div`,{className:`flex flex-wrap items-center gap-1`,children:[e(F,{size:`sm`,variant:`secondary`,onClick:()=>h.mutate(void 0),disabled:h.isPending||m.isPending,title:n(`system.networkAddresses.reRunTheAutoDetection`,`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`),children:[r(ee,{className:`h-3 w-3`}),h.isPending?n(`system.networkAddresses.detecting`,`Detecting…`):n(`system.networkAddresses.bestMatch`,`Best match`)]}),e(F,{size:`sm`,variant:`secondary`,onClick:()=>{w([])},disabled:C.length===0||m.isPending,children:[r(f,{className:`h-3 w-3`}),n(`system.networkAddresses.clear`,`Clear`)]}),O&&r(F,{size:`sm`,variant:`secondary`,onClick:()=>{w(D)},disabled:m.isPending,children:n(`system.networkAddresses.discard`,`Discard`)}),e(F,{size:`sm`,variant:`primary`,onClick:()=>{m.mutate({addresses:[...C]})},disabled:!O||m.isPending,children:[r(te,{className:`h-3 w-3`}),m.isPending?n(`system.networkAddresses.saving`,`Saving…`):n(`common.save`,`Save`)]})]}),children:e(`div`,{className:u,children:[r(`p`,{className:`mb-3 text-xs text-foreground-subtle`,children:C.length===0?n(`system.networkAddresses.autoEveryNonLoopbackNon`,`Auto — every non-loopback / non-link-local interface participates.`):n(`system.networkAddresses.pinned`,`{{value1}} pinned`,{value1:String(C.length)})}),r(et,{mode:`multiple`,interfaces:g,value:C,onChange:w,disabled:m.isPending,emptyMessage:l.isLoading?n(`system.networkAddresses.loadingInterfaces`,`Loading interfaces…`):n(`system.networkAddresses.noInterfacesDetected`,`No interfaces detected.`)})]})}),r(at,{book:_.data,loading:_.isLoading,saving:S,error:x,onSetRole:e=>v.mutate({...e}),onAdd:(e,t)=>y.mutate({baseUrl:e,label:t}),onRemove:e=>b.mutate({baseUrl:e})})]})}o();var st={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},X=5e3,Z=`mesh-network`,ct=3e4,lt={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function ut(){let{t:e}=L(),n=N({capName:`mesh-network`},{refetchInterval:X}),i=M(void 0,{refetchInterval:X}),a=t(()=>W(i.data??[]),[i.data]),o=t(()=>(n.data??[]).map(e=>({addonId:e.addonId,displayName:a.get(e.addonId)??e.addonId,isActive:e.isActive})),[n.data,a]),s=[{id:Z,label:e(`system.meshNetworks.meshNetworks`,`Mesh networks`),install:{capability:Z,label:e(`system.meshNetworks.addMesh`,`Add mesh`)},entries:o.map(t=>({id:t.addonId,name:t.displayName,fallbackIcon:h,...U(t.isActive),render:()=>r(V,{addonId:t.addonId,displayName:t.displayName,capName:Z,isActive:t.isActive,badges:r(dt,{addonId:t.addonId}),primaryAction:r(ft,{addonId:t.addonId}),panels:[{id:`status`,title:e(`system.meshNetworks.status`,`Status`),icon:A,content:r(pt,{addonId:t.addonId})}]})}))}];return r(H,{embedded:!0,icon:A,title:e(`system.meshNetworks.meshNetworks2`,`Mesh Networks`),subtitle:e(`system.meshNetworks.privateVpnMeshesThatConnect`,`Private VPN meshes that connect CamStack to your other devices (Tailscale, Headscale, …). Each provider can also expose this hub publicly via its ingress (Tailscale Funnel).`),groups:s,isLoading:n.isLoading,emptyTitle:e(`system.meshNetworks.noMeshNetworkProvidersInstalled`,`No mesh-network providers installed`),emptyDescription:e(`system.meshNetworks.installAMeshAddonE`,`Install a mesh addon (e.g. @camstack/addon-tailscale) to join this hub into a private VPN mesh.`)})}function Q(e){let{data:t,isLoading:n}=Ae({addonId:e},{refetchInterval:X,retry:!1}),r=t?re.safeParse(t):null;return{status:r?.success?r.data:lt,isLoading:n}}function dt({addonId:t}){let{t:n}=L(),{status:i}=Q(t);return e(c,{children:[r(P,{variant:i.joined?`success`:`default`,className:Ve,children:i.joined?n(`system.meshNetworks.joined`,`Joined`):n(`system.meshNetworks.notJoined`,`Not joined`)}),i.joined&&r(P,{className:`text-[10px]`,children:n(`common.peers`,{count:i.peerCount})})]})}function ft({addonId:t}){let{t:i}=L(),o=s(),[l,u]=a(!1),[d,f]=a(null),p=S(),{status:m}=Q(t),h=n(()=>{o.invalidateQueries({queryKey:[[`meshNetwork`]]})},[o]),g=Ne(),_=Oe({onSuccess:h}),v=Se({onSuccess:h}),y=n(async()=>{u(!0);let e={cancelled:!1};f(e);try{let n=await g.mutateAsync({addonId:t});if(e.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!e.cancelled&&(await yt(2e3),!e.cancelled);){let e=await p.trpcClient.meshNetwork.getStatus.query({addonId:t}).catch(()=>null),n=e?re.safeParse(e):null;if(n?.success&&n.data.joined){h();break}if(Date.now()-r>6e5)break}}finally{u(!1),f(null)}},[t,h,g,p]),b=n(()=>{d&&(d.cancelled=!0),u(!1),f(null)},[d]);return r(c,{children:m.joined?e(c,{children:[e(F,{size:`sm`,variant:`secondary`,disabled:_.isPending,onClick:()=>_.mutate({addonId:t}),children:[_.isPending?r(T,{className:`h-3 w-3 animate-spin`}):r(oe,{className:`h-3 w-3`}),i(`system.meshNetworks.disconnect`,`Disconnect`)]}),e(F,{size:`sm`,variant:`ghost`,disabled:v.isPending,onClick:()=>v.mutate({addonId:t}),children:[v.isPending?r(T,{className:`h-3 w-3 animate-spin`}):r(C,{className:`h-3 w-3`}),i(`system.meshNetworks.logOut`,`Log out`)]})]}):l?e(F,{size:`sm`,variant:`ghost`,onClick:b,children:[r(w,{className:`h-3 w-3 mr-1`}),` `,i(`common.cancel`)]}):e(c,{children:[e(F,{size:`sm`,variant:`primary`,onClick:()=>void y(),children:[r(se,{className:`h-3 w-3`}),i(`system.meshNetworks.connect`,`Connect`)]}),e(F,{size:`sm`,variant:`ghost`,disabled:v.isPending,onClick:()=>v.mutate({addonId:t}),children:[v.isPending?r(T,{className:`h-3 w-3 animate-spin`}):r(C,{className:`h-3 w-3`}),i(`system.meshNetworks.logOut`,`Log out`)]})]})})}function pt({addonId:t}){let{t:n}=L(),{status:i}=Q(t),a=De({addonId:t},{refetchInterval:ct,retry:!1});return e(`div`,{className:`rounded-lg border border-border bg-surface`,children:[e(`div`,{className:`space-y-4 p-2 sm:p-4`,children:[i.error&&r(he,{message:i.error}),r(mt,{status:i}),i.endpoints.length>0&&e(`div`,{className:`space-y-1.5`,children:[r(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:n(`system.meshNetworks.endpoints`,`Endpoints`)}),i.endpoints.map(t=>e(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[e(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${st[t.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[t.scope===`public`?r(j,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,t.label]}),e(`a`,{href:t.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-emerald-700 dark:text-emerald-300 hover:underline break-all flex items-center gap-1`,children:[r(E,{className:`h-3 w-3 shrink-0`}),t.url]})]},t.id))]})]}),r(`div`,{className:`border-t border-border`,children:r(gt,{peers:a.data?.peers??[],loading:a.isLoading})})]})}function mt({status:t}){let{t:n}=L();return r(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-1.5`,children:[{label:n(`system.meshNetworks.tenant`,`Tenant`),value:t.tenantName||`—`},{label:n(`system.meshNetworks.user`,`User`),value:t.userLogin??`—`},{label:n(`system.meshNetworks.controlPlane`,`Control plane`),value:t.controlPlaneUrl||`—`},{label:n(`system.meshNetworks.meshIp`,`Mesh IP`),value:t.meshIp||`—`,mono:!0},{label:n(`system.meshNetworks.magicdns`,`MagicDNS`),value:t.magicDnsHostname||`—`,mono:!0},{label:n(`system.meshNetworks.dnsSuffix`,`DNS suffix`),value:t.magicDnsSuffix||`—`,mono:!0},{label:n(`system.meshNetworks.peers`,`Peers`),value:String(t.peerCount)},{label:n(`system.meshNetworks.keyExpiry`,`Key expiry`),value:t.keyExpiry?ht(t.keyExpiry):`—`}].map(t=>e(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[r(`span`,{className:`text-foreground-subtle shrink-0`,children:t.label}),r(`span`,{className:`text-foreground truncate ${t.mono?`font-mono`:``}`,children:t.value})]},t.label))})}function ht(e){let t=e-Date.now();if(t<0)return I.t(`system.meshNetworks.expiredAgo`,{when:$(e)});let n=Math.floor(t/864e5);if(n>60)return new Date(e).toLocaleDateString();if(n>1)return I.t(`system.meshNetworks.expiryDays`,{count:n});let r=Math.floor(t/36e5);return r>1?I.t(`system.meshNetworks.expiryHours`,{count:r}):I.t(`system.meshNetworks.expiryMin`,{count:Math.max(1,Math.floor(t/6e4))})}function gt({peers:i,loading:a}){let{t:o}=L(),s=t(()=>i.map(e=>({...e,_id:e.id})),[i]),c=n(e=>{e&&navigator.clipboard?.writeText(e)},[]),l=t(()=>[{key:`hostname`,header:o(`system.meshNetworks.hostname`,`Hostname`),render:t=>e(`div`,{className:`flex flex-col`,children:[e(`div`,{className:`flex items-center gap-1.5`,children:[r(`span`,{className:`font-medium text-foreground`,children:t.hostname||o(`system.meshNetworks.unknown`,`(unknown)`)}),t.isSelf&&r(P,{variant:`info`,children:o(`common.self`)}),t.exitNodeOption&&r(P,{variant:`warning`,children:`exit-node`})]}),t.userLogin&&r(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:t.userLogin})]})},{key:`magicDns`,header:o(`system.meshNetworks.magicdns`,`MagicDNS`),render:t=>t.magicDns?e(`div`,{className:`flex items-center gap-1`,children:[r(`span`,{className:`font-mono text-xs truncate`,children:t.magicDns}),r(`button`,{onClick:()=>c(t.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":o(`system.meshNetworks.copyMagicdns`,`Copy MagicDNS`),children:r(b,{className:`h-3 w-3 text-foreground-subtle`})})]}):r(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:t=>{let n=t.addresses[0]??``;return n?e(`div`,{className:`flex items-center gap-1`,children:[r(`span`,{className:`font-mono text-xs`,children:n}),r(`button`,{onClick:()=>c(n),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":o(`system.meshNetworks.copyIp`,`Copy IP`),children:r(b,{className:`h-3 w-3 text-foreground-subtle`})})]}):r(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:o(`system.meshNetworks.connection`,`Connection`),render:t=>e(`div`,{className:`flex items-center gap-1.5`,children:[r(P,{variant:_t(t.connection),children:t.connection}),t.relay&&r(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:t.relay})]})},{key:`routes`,header:o(`system.meshNetworks.routes`,`Routes`),render:e=>e.advertisedRoutes.length>0?r(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):r(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:o(`system.meshNetworks.txRx`,`TX / RX`),render:t=>e(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,vt(t.txBytes),` · ↓ `,vt(t.rxBytes)]})},{key:`lastSeen`,header:o(`system.meshNetworks.lastSeen`,`Last seen`),render:e=>r(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?$(e.lastSeenMs):`—`})}],[c,o]);return a&&i.length===0?e(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[r(T,{className:`h-3 w-3 animate-spin inline mr-1`}),` `,o(`systemPage.meshNetworks.loadingPeers`)]}):i.length===0?r(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:o(`system.meshNetworks.noPeersVisibleYourTailnet`,`No peers visible — your tailnet may be empty or the host is not joined.`)}):r(`div`,{className:`p-4`,children:r(ue,{columns:l,rows:s,rowKey:e=>e._id,minWidthPx:820})})}function _t(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function vt(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)}MB`:`${(e/1024/1024/1024).toFixed(2)}GB`}function $(e){let t=Date.now()-e;return t<6e4?I.t(`system.meshNetworks.justNow`):t<36e5?I.t(`system.meshNetworks.agoMin`,{count:Math.round(t/6e4)}):t<864e5?I.t(`system.meshNetworks.agoHour`,{count:Math.round(t/36e5)}):I.t(`system.meshNetworks.agoDay`,{count:Math.round(t/864e5)})}function yt(e){return new Promise(t=>setTimeout(t,e))}var bt=`/system/identity?tab=certificates`;function xt(){let{t}=L();return r(B,{embedded:!0,children:e(`div`,{className:g,children:[r(Be,{nodeId:`hub`,addonIds:[`local-network`],level:`global`,title:t(`system.localAccess.lanHttp`,`LAN HTTP`),description:t(`system.localAccess.nativeAppsOnThisWi`,`Native apps on this Wi-Fi use http:// and skip the private certificate. The tunnel and this admin UI stay on HTTPS.`)}),e(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`https-certificate-hint`,children:[t(`system.localAccess.certificateMoved`,`The HTTPS certificate and the local CA are managed under`),` `,r(Le,{className:`underline`,to:bt,children:t(`system.localAccess.certificateMovedLink`,`Identity → Certificates`)}),`.`]})]})})}o();function St({value:n,onChange:i}){let{t:a}=L(),{data:o}=me({isCamera:!0,projection:`slim`}),s=t(()=>o===void 0?[{value:``,label:a(`system.networkDiagnostics.loadingCameras`,`Loading cameras…`)}]:o.length===0?[{value:``,label:a(`system.networkDiagnostics.noCameras`,`No cameras`)}]:[{value:``,label:a(`system.networkDiagnostics.pickACamera`,`Pick a camera`)},...o.toSorted((e,t)=>e.name.localeCompare(t.name)).map(e=>({value:String(e.id),label:`${e.name} (#${String(e.id)})`}))],[o,a]);return e(`label`,{className:`flex min-w-0 flex-col gap-1`,children:[r(`span`,{className:`text-[11px] text-foreground-subtle`,children:a(`system.networkDiagnostics.camera`,`Camera`)}),r(le,{value:n===null?``:String(n),disabled:o===void 0||o.length===0,onChange:e=>i(e.target.value===``?null:Number(e.target.value)),options:s})]})}function Ct(){let t=S(),[i,o]=a(null);return r(B,{embedded:!0,children:e(`div`,{className:g,"data-testid":`network-diagnostics`,children:[r(fe,{loadServers:n(async()=>t.trpcClient.turnProvider.getTurnServers.query(),[t])}),r(be,{trpc:t.trpcClient,serverUrl:v(),deviceId:i,cameraField:r(St,{value:i,onChange:o})})]})})}var wt=[`certificate`,`certificates`,`https`];function Tt(){let{t:e}=L(),[t]=Re();if(wt.includes(t.get(`tab`)??``))return r(Ie,{to:bt,replace:!0});let n=Fe(`/system/network`,{t:e,isAdmin:!0})??{icon:j,title:e(`system.network`,`Network`)};return r(ze,{icon:n.icon,title:n.title,defaultSection:`addresses`,sectionsLabel:`${n.title} sections`,sections:[{id:`local-access`,label:e(`systemPage.network.localAccess`,`Local access`),content:r(xt,{})},{id:`addresses`,label:e(`systemPage.network.networkAddresses`,`Network Addresses`),content:r(ot,{})},{id:R.remoteAccess.tab,label:e(`systemPage.network.remoteAccess`,`Remote Access`),content:r(Ue,{}),ownedParams:z},{id:R.mesh.tab,label:e(`systemPage.network.meshNetworks`,`Mesh Networks`),content:r(ut,{}),ownedParams:z},{id:R.turn.tab,label:e(`systemPage.network.turnServers`,`TURN Servers`),content:r(Ye,{}),ownedParams:z},{id:`diagnostics`,label:e(`systemPage.network.diagnostics`,`Diagnostics`),content:r(Ct,{})}]})}export{Tt as NetworkPage};
|