@camstack/addon-admin-ui 1.2.367 → 1.2.369
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AddonAssetIcon-DpOYiFwy.js → AddonAssetIcon-rRcZQtEA.js} +1 -1
- package/dist/assets/AddonIntegrationBody-EbUl8tUN.js +1 -0
- package/dist/assets/Addons-DGr0dCVs.js +4 -0
- package/dist/assets/{AdminTabs-Bw0vLcQV.js → AdminTabs-wu-aryGN.js} +1 -1
- package/dist/assets/AiProfiles-BeoeH8Zu.js +3 -0
- package/dist/assets/{BrokerForm-BOnoKZt-.js → BrokerForm-BKrrZCZh.js} +1 -1
- package/dist/assets/Build-B6IaaCld.js +40 -0
- package/dist/assets/{Calendars-CMaYwnFF.js → Calendars-Cu9XHV92.js} +1 -1
- package/dist/assets/Cluster-Cy5X6Uvg.js +1 -0
- package/dist/assets/ClusterStepModel-naRCh9Gl.js +1 -0
- package/dist/assets/{CompositionEditor-BGu7clTR.js → CompositionEditor-IHtDmqNg.js} +1 -1
- package/dist/assets/{CompositionEditorPage-Lv4rlb7_.js → CompositionEditorPage-DC8vTjNi.js} +1 -1
- package/dist/assets/Data-DYW0abTi.js +1 -0
- package/dist/assets/DetectionIntelligence-Dql2v1Z-.js +1 -0
- package/dist/assets/DeviceDetail-DnI-UCZh.js +2 -0
- package/dist/assets/{DeviceDoActionFields-DHRkE5xP.js → DeviceDoActionFields-CDcT9AGH.js} +1 -1
- package/dist/assets/{Devices-DQBiqk6T.js → Devices-BQlncmWJ.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-C6S5WEa7.js → EmbedPlayerPage-tOXvPyWI.js} +1 -1
- package/dist/assets/Events-BHrs4V4o.js +1 -0
- package/dist/assets/Identity-B0o5qgSj.js +1 -0
- package/dist/assets/IntegrationDetail-C5FRSBKl.js +1 -0
- package/dist/assets/Integrations-Y_7v1rC_.js +1 -0
- package/dist/assets/Integrations-kpJ44y4z.js +1 -0
- package/dist/assets/Locations-CcEjNLL3.js +3 -0
- package/dist/assets/{Logs-DPwwQi8h.js → Logs-CwotbBSR.js} +1 -1
- package/dist/assets/{MotionZonesSettings-CftAgxWi.js → MotionZonesSettings-DWw3QpEU.js} +1 -1
- package/dist/assets/MyAccess-FYgj8K8r.js +2 -0
- package/dist/assets/Network-CAm0gAZJ.js +1 -0
- package/dist/assets/{NodeAddonsSettingsPanel-BiE-QIvS.js → NodeAddonsSettingsPanel-Bb9dwuSU.js} +1 -1
- package/dist/assets/Notifications--kHXBEqD.js +1 -0
- package/dist/assets/{Plates-BvdnDkGc.js → Plates-BiXyRHLs.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-CUbD6k0L.js → PrivacyMaskSettings-DCTAX66L.js} +1 -1
- package/dist/assets/Recordings-DrcwnpEB.js +1 -0
- package/dist/assets/Retrain-BrINvPPp.js +1 -0
- package/dist/assets/{ScanNetworkModal-iiJJTylP.js → ScanNetworkModal-C4IaFGug.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-nRqgGlp2.js → SceneMonitorEditor-CQ2pi_Hj.js} +1 -1
- package/dist/assets/{Scenes-DgqiTzk9.js → Scenes-BLFLAgHy.js} +1 -1
- package/dist/assets/SessionsList-Yg5gVfMg.js +2 -0
- package/dist/assets/{Showroom-iXUFZXmM.js → Showroom-I56ibw6k.js} +1 -1
- package/dist/assets/System-BVjDuAwr.js +1 -0
- package/dist/assets/{Terminal-Dv-j25I5.js → Terminal-5SL5NSD1.js} +5 -5
- package/dist/assets/{Viewer-kmcfxFof.js → Viewer-C9zzDTPh.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Ca2DwjVP.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-C2fbuZJL.js} +1 -1
- package/dist/assets/{archive-C_-iEHhW.js → archive-Dkte8Y8a.js} +1 -1
- package/dist/assets/{authed-media-rH30orNX.js → authed-media-Bi2u1rSm.js} +1 -1
- package/dist/assets/{boxes-Cj3enrG0.js → boxes-CG60qRZo.js} +1 -1
- package/dist/assets/circle-slash-C3W4jvTj.js +1 -0
- package/dist/assets/client-DX0rAC3X.js +357 -0
- package/dist/assets/crop-BBN3JEL7.js +1 -0
- package/dist/assets/{debounced-invalidate-CUPcL0rQ.js → debounced-invalidate-CxaRFTpC.js} +1 -1
- package/dist/assets/{device-integration-icon-CjpZldgd.js → device-integration-icon-JFsHsv7_.js} +1 -1
- package/dist/assets/device-picker-model-BTxjd_Y8.js +1 -0
- package/dist/assets/dist-DK6qWoSo.js +357 -0
- package/dist/assets/{dist-B3-nKFP1.js → dist-DflVZo7O.js} +1 -1
- package/dist/assets/{face-bbox-CqIiQdVy.js → face-bbox-zC_kw0CX.js} +1 -1
- package/dist/assets/{hard-drive-download-B1qrAMQ7.js → hard-drive-download-C9ll-Tud.js} +1 -1
- package/dist/assets/{history-Ixgo2o2a.js → history-Bsb3o8Ph.js} +1 -1
- package/dist/assets/{hostInit-Cgl65BZF.js → hostInit-D-dSFNov.js} +1 -1
- package/dist/assets/index-BfUAV0Tt.css +2 -0
- package/dist/assets/index-D7yeH_53.js +4 -0
- package/dist/assets/{layers-JboEX-t3.js → layers-BiHKkPFk.js} +1 -1
- package/dist/assets/location-owned-usage-DQxXKxXh.js +1 -0
- package/dist/assets/{mf-entry-bootstrap-0-5f4030f8.js → mf-entry-bootstrap-0-76e50126.js} +2 -2
- package/dist/assets/{monitor-smartphone-DEvaCEpt.js → monitor-smartphone-DCj4MFCV.js} +1 -1
- package/dist/assets/mount-BTxjd_Y8.js +1 -0
- package/dist/assets/notification-schedule-field-B3G1sjYy.js +1 -0
- package/dist/assets/{octagon-alert-CQuofVwc.js → octagon-alert-uq_xpLNT.js} +1 -1
- package/dist/assets/{player-overlays-OREckyXS.js → player-overlays-D9aoM64J.js} +1 -1
- package/dist/assets/remoteEntry-CKbF9NAW.js +1 -0
- package/dist/assets/{send-CuHij6pJ.js → send-BoWu8sC3.js} +1 -1
- package/dist/assets/{settings-2-BQZcFYTR.js → settings-2-vAZgfnrs.js} +1 -1
- package/dist/assets/{src-CEnvJotZ.js → src-B-IRCQFw.js} +4 -4
- package/dist/assets/{use-scenes-feed-1Od0TZaA.js → use-scenes-feed-B67D8SNJ.js} +1 -1
- package/dist/assets/{use-stationary-objects-DqVVD1DW.js → use-stationary-objects-B5PewW7U.js} +1 -1
- package/dist/assets/useEventInvalidation-BTxjd_Y8.js +1 -0
- package/dist/assets/{useNodeUrlSelection-C3vDpTz0.js → useNodeUrlSelection-DyMwFYyx.js} +1 -1
- package/dist/assets/user-round-bqX4ogd_.js +1 -0
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CjZzajvR.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DDHU33sX.js} +2 -2
- package/dist/index.html +8 -8
- package/dist/server/addon.js +13 -2
- package/package.json +1 -1
- package/dist/assets/AddonIntegrationBody-DdNzzr-6.js +0 -1
- package/dist/assets/Addons-B0udTC2D.js +0 -4
- package/dist/assets/AiProfiles-DLiFaDiD.js +0 -3
- package/dist/assets/Build-BJlvXVpa.js +0 -40
- package/dist/assets/Cluster-DLlURHMO.js +0 -1
- package/dist/assets/ClusterStepModel-DUqB59eQ.js +0 -1
- package/dist/assets/Data-DF4tGpWD.js +0 -1
- package/dist/assets/DetectionIntelligence-fSWafsKy.js +0 -1
- package/dist/assets/DeviceDetail-nMeXPEtL.js +0 -2
- package/dist/assets/Events-CH3iXReO.js +0 -1
- package/dist/assets/Identity-CrnEnlEQ.js +0 -1
- package/dist/assets/IntegrationDetail-BLdUZANt.js +0 -1
- package/dist/assets/Integrations-DIZiDn_B.js +0 -1
- package/dist/assets/Integrations-iPnsLoVn.js +0 -1
- package/dist/assets/Locations-CXQv36Yt.js +0 -3
- package/dist/assets/MyAccess-ZAW5kVD_.js +0 -2
- package/dist/assets/Network-C6JvbIXt.js +0 -1
- package/dist/assets/Notifications-h9VuRiTF.js +0 -1
- package/dist/assets/Recordings-BdgobGao.js +0 -1
- package/dist/assets/SessionsList-Ba2Ozpmv.js +0 -2
- package/dist/assets/System-k1CqgwqI.js +0 -1
- package/dist/assets/circle-slash-B9leNw8c.js +0 -1
- package/dist/assets/client-1c3e-nOc.js +0 -357
- package/dist/assets/crop-Cz85GIsX.js +0 -1
- package/dist/assets/device-picker-model-qjRcMIFg.js +0 -1
- package/dist/assets/dist-Dp0Vbww8.js +0 -357
- package/dist/assets/index-Bq3Mrl-l.js +0 -4
- package/dist/assets/index-BrFFHBMJ.css +0 -2
- package/dist/assets/location-owned-usage-DAWlSLDx.js +0 -1
- package/dist/assets/mount-qjRcMIFg.js +0 -1
- package/dist/assets/notification-schedule-field-mbJZiR_t.js +0 -1
- package/dist/assets/remoteEntry-DAkePvGv.js +0 -1
- package/dist/assets/useEventInvalidation-qjRcMIFg.js +0 -1
- package/dist/assets/user-round-BmFyUIzE.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Q as e,S as t,W as n,a as r,b as i,o as a,q as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as c,gt as l,ht as u,st as d,vt as f}from"./player-overlays-D9aoM64J.js";import{$l as p,En as m,F as h,Fn as g,G as _,Gd as v,Gl as y,Hu as b,It as x,Jd as S,Jl as C,Kl as w,Kn as T,Mu as E,Ou as D,P as O,Pn as k,Ql as A,Sn as j,Sr as M,Tf as ee,Tn as N,Ud as P,W as te,Xl as F,Yd as ne,Yl as re,Zl as ie,_d as I,ad as ae,au as oe,bn as L,ca as se,cf as ce,dd as R,en as z,er as le,eu as ue,fd as B,iu as de,jd as fe,kd as pe,kt as me,mu as he,nu as ge,ou as _e,pd as ve,qd as ye,ql as be,qn as xe,ru as Se,tu as Ce,wn as V,xn as H,xr as we}from"./src-B-IRCQFw.js";import{t as Te}from"./history-Bsb3o8Ph.js";import{t as U}from"./monitor-smartphone-DCj4MFCV.js";import{_ as W,a as Ee,b as De,c as Oe,d as ke,f as Ae,g as je,h as G,i as Me,l as Ne,m as Pe,n as Fe,o as Ie,p as Le,s as Re,t as ze,u as Be,v as K,y as q}from"./SessionsList-Yg5gVfMg.js";import{a as Ve,i as He,o as Ue,s as We}from"./client-DX0rAC3X.js";import{$ as Ge,R as J,X as Ke,Y as qe,at as Je,c as Ye,it as Xe,p as Ze,rt as Qe,s as $e}from"./index-D7yeH_53.js";import{t as et}from"./AdminPage-BSFohA3i.js";import{t as tt}from"./AdminTabs-wu-aryGN.js";import{n as nt,r as rt,t as it}from"./AddonIntegrationBody-EbUl8tUN.js";import{n as at,t as ot}from"./addon-display-names-BkwMrExv.js";var st=f(`book-open`,[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z`,key:`ruj8y`}]]),ct=f(`key-square`,[[`path`,{d:`M12.4 2.7a2.5 2.5 0 0 1 3.4 0l5.5 5.5a2.5 2.5 0 0 1 0 3.4l-3.7 3.7a2.5 2.5 0 0 1-3.4 0L8.7 9.8a2.5 2.5 0 0 1 0-3.4z`,key:`165ttr`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`m9.4 10.6-6.814 6.814A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814`,key:`1ubxi2`}]]);e();function lt(){let e=T(),t=D.useUtils(),r=q(),{data:i,isLoading:a}=p(),c=n(()=>i??[],[i]),l=D.useQueries(e=>c.map(t=>e.userManagement.listExternalIdentities({userId:t.id}))),u=D.auth.listLoginMethods.useQuery(),[d,f]=o(null),m=oe({onSuccess:()=>void t.userManagement.listExternalIdentities.invalidate(),onError:e=>f(`Remove failed: ${e.message}`)}),h=n(()=>new Map((u.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),[u.data]),g=c.flatMap((e,t)=>l[t]?.data??[]),_=g.map(e=>({...ke(e,r),kind:h.get(e.provider)??e.provider})),v=async t=>{let n=g.find(e=>Be(e)===t.id);n!==void 0&&await e({title:`Remove sign-in link`,message:`"${t.ownerName}" will no longer be able to sign in with this ${t.kind} account.`,confirmLabel:`Remove`,variant:`danger`})&&(f(null),m.mutate({userId:n.userId,provider:n.provider,subject:n.subject}))};return s(W,{notice:K(d),onDismissNotice:()=>{f(null)},id:`external-identities`,title:`Sign-in links`,icon:Je,description:`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:s(G,{rows:_,label:`sign-in links`,isLoading:a||l.some(e=>e.isLoading),loadError:l.find(e=>e.isError)?.error?.message??null,emptyText:`No user has linked a sign-in account.`,expiresNone:`—`,action:{label:`Remove`,icon:De,isAvailable:()=>!0,onRun:e=>void v(e),busyId:null,disabled:m.isPending}})})}e();function ut(){let e=T(),t=a(),r=q(),i=F(),[c,l]=o(null),u=Ce({onSuccess:()=>void t.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),onError:e=>l(`Revoke failed: ${e.message}`)}),f=n(()=>(i.data??[]).map(e=>Ne(e,r)),[i.data,r]),p=async t=>{await e({title:`Revoke "${t.name}"?`,message:`Any client using this key loses access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&(l(null),u.mutate({id:t.id}))};return s(W,{notice:K(c),onDismissNotice:()=>{l(null)},id:`legacy-api-keys`,title:`Legacy API keys`,icon:Te,description:`Keys from before scoped tokens. Nothing creates them any more; revoke them and issue a scoped token instead.`,children:s(G,{rows:f,label:`legacy API keys`,isLoading:i.isLoading,loadError:i.isError?i.error?.message??`Request failed`:null,emptyText:`No legacy API keys.`,action:{label:`Revoke`,icon:d,isAvailable:()=>!0,onRun:e=>void p(e),busyId:u.isPending?u.variables?.id??null:null,disabled:u.isPending}})})}e();function dt(e){if(e.type===`category`){let t=e.target??``;return t===`device`?`all devices`:`all ${t}`}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function ft(){let e=T(),t=a(),r=A(),[i,c]=o(null),l=ge({onSuccess:()=>void t.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]}),onError:e=>c(`Revoke failed: ${e.message}`)}),u=n(()=>(r.data??[]).map(e=>Ae(e,e.scopes.map(dt).join(`, `))),[r.data]),f=async t=>{await e({title:`Revoke the "${t.name}" link?`,message:`${t.name} loses access for ${t.ownerName} on its next call. Linking it again needs the account-link flow from the start.`,confirmLabel:`Revoke`,variant:`danger`})&&(c(null),l.mutate({id:t.id}))},p=l.isPending?l.variables?.id??null:null;return s(W,{notice:K(i),onDismissNotice:()=>{c(null)},id:`linked-apps`,title:`Linked apps`,icon:v,description:`External integrations (Alexa, …) linked to this hub through OAuth. Revoking one stops that integration on its next call.`,children:s(G,{rows:u,label:`linked apps`,isLoading:r.isLoading,loadError:r.isError?r.error?.message??`Request failed`:null,emptyText:`No linked apps — an integration appears here once it completes the account-link flow.`,expiresNone:`—`,action:{label:`Revoke`,icon:d,isAvailable:e=>e.status===`active`,onRun:e=>void f(e),busyId:p,disabled:l.isPending}})})}e();var pt={one:`session`,many:`sessions`};function mt(){let e=T(),t=D.useUtils(),r=q(),i=D.auth.listSessions.useQuery(),[a,c]=o(null),l=()=>void t.auth.listSessions.invalidate(),u=D.auth.revokeSessions.useMutation({onSuccess:l,onError:e=>c(`Sign out failed: ${e.message}`)}),d=je(`login-session`,pt,l),f=n(()=>(i.data??[]).map(e=>Le(e,r,{client:e=>Ee(e).label,method:Ie})),[i.data,r]),p=async t=>{await e({title:`Sign out this session`,message:`${t.ownerName} on ${t.name} will have to sign in again.`,confirmLabel:`Sign out`,variant:`danger`})&&(c(null),u.mutate({id:t.id}))};return s(W,{notice:K(a,d.outcome),onDismissNotice:()=>{c(null),d.dismiss()},id:`login-sessions`,title:`Login sessions`,icon:U,description:`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:s(G,{rows:f,label:`sessions`,isLoading:i.isLoading,loadError:i.isError?i.error?.message??`Request failed`:null,emptyText:`No active sessions.`,action:{label:`Sign out`,icon:Qe,isAvailable:e=>e.status===`active`,onRun:e=>void p(e),busyId:u.isPending&&u.variables!==void 0&&`id`in u.variables?u.variables.id:null,disabled:u.isPending||d.busy},bulk:{revoke:d,noun:pt,isSelectable:e=>e.status===`active`}})})}e();function ht({users:e,onClose:n,onSubmit:r,submitting:i}){let{user:a}=J(),c=a?.isAdmin===!0?null:a?.scopes??[],[l,u]=o(e[0]?.id??``),[d,f]=o(``),[p,_]=o([{type:`capability`,target:``,access:[`view`,`create`]}]),[v,y]=o(``),b=h(p),x=l!==``&&d.trim().length>0&&p.length>0&&b===null&&!i;return s(L,{open:!0,onOpenChange:e=>!e&&n(),children:t(j,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[s(N,{children:s(m,{children:`Create scoped token`})}),t(H,{className:`space-y-3`,children:[t(`div`,{className:`space-y-1`,children:[s(z,{htmlFor:`scoped-token-user`,children:`On behalf of user`}),s(k,{id:`scoped-token-user`,value:l,onChange:e=>u(e.target.value),options:e.map(e=>({value:e.id,label:e.username}))})]}),t(`div`,{className:`space-y-1`,children:[s(z,{htmlFor:`scoped-token-name`,children:`Name`}),s(he,{id:`scoped-token-name`,value:d,onChange:e=>f(e.target.value),placeholder:`cloudflare-tunnel-route`})]}),t(`div`,{className:`space-y-1`,children:[s(z,{children:`Scopes`}),s(O,{value:p,onChange:_,clampToParent:c}),b&&s(`p`,{className:`text-[10px] text-danger`,children:b}),s(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`})]}),t(`div`,{className:`space-y-1`,children:[s(z,{htmlFor:`scoped-token-days`,children:`Expires in (days)`}),s(he,{id:`scoped-token-days`,type:`number`,min:1,value:v,onChange:e=>y(e.target.value),placeholder:`30`}),s(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Leave blank for non-expiring.`})]})]}),t(V,{children:[s(g,{type:`button`,variant:`outline`,size:`sm`,onClick:n,children:`Cancel`}),t(g,{type:`button`,variant:`primary`,size:`sm`,onClick:()=>{let e=parseInt(v,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;r({userId:l,name:d.trim(),scopes:p,expiresAt:t})},disabled:!x,children:[i?s(P,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}):s(R,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),`Issue token`]})]})]})})}function gt({token:e,label:n,onClose:r}){return s(L,{open:!0,onOpenChange:e=>!e&&r(),children:t(j,{width:`md`,scroll:`body`,children:[s(N,{children:s(m,{children:`Token: ${n}`})}),t(H,{className:`space-y-3`,children:[s(`div`,{className:`rounded-md border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:`Copy this token now. Once you close this dialog the secret cannot be displayed again.`}),s(`div`,{className:`select-all break-all rounded-md border border-border bg-background p-2 font-mono text-[11px] text-foreground`,children:e})]}),t(V,{children:[s(me,{value:e,label:`Copy`,srLabel:`token`}),s(g,{type:`button`,variant:`primary`,size:`sm`,onClick:r,children:`Done`})]})]})})}e();function _t(e){return e.type===`device`?`device:[${_(e.selector)}]`:`${e.type}:${e.target??``}`}function vt(){let e=T(),r=a(),i=q(),{data:c,isLoading:l}=p(),u=n(()=>c??[],[c]),f=D.useQueries(e=>u.map(t=>e.userManagement.listScopedTokens({userId:t.id}))),[m,h]=o(null),[_,v]=o(!1),[b,x]=o(null),C=()=>void r.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),w=y({onSuccess:({token:e,record:t})=>{C(),v(!1),x({token:e,label:t.name})},onError:e=>h(`Create failed: ${e.message}`)}),E=Se({onSuccess:C,onError:e=>h(`Revoke failed: ${e.message}`)}),O=Date.now(),k=u.flatMap((e,t)=>(f[t]?.data??[]).map(t=>Pe(t,e.id,i,t.scopes.map(_t).join(`, `),O))),A=f.find(e=>e.isError)?.error?.message??null,j=async t=>{await e({title:`Revoke "${t.name}"?`,message:`${t.ownerName}'s scoped token stops working on its next use. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&(h(null),E.mutate({id:t.id}))};return t(W,{notice:K(m),onDismissNotice:()=>{h(null)},id:`scoped-tokens`,title:`Scoped tokens`,icon:S,description:`Tokens issued on behalf of a user for one narrow surface — an addon, an integration, a capability or some devices. Every token must be scoped, so revoking one has a predictable blast radius.`,actions:t(g,{type:`button`,variant:`primary`,size:`sm`,onClick:()=>v(!0),disabled:u.length===0,title:u.length===0?`Create a user first`:`Issue a scoped token`,children:[s(R,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),`New token`]}),children:[s(G,{rows:k,label:`scoped tokens`,isLoading:l||f.some(e=>e.isLoading),loadError:A,emptyText:`No scoped tokens.`,action:{label:`Revoke`,icon:d,isAvailable:()=>!0,onRun:e=>void j(e),busyId:E.isPending?E.variables?.id??null:null,disabled:E.isPending}}),_&&s(ht,{users:u.map(e=>({id:e.id,username:e.username})),onClose:()=>v(!1),onSubmit:e=>w.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:w.isPending}),b!==null&&s(gt,{token:b.token,label:b.label,onClose:()=>x(null)})]})}e();var yt={one:`admin token`,many:`admin tokens`},bt=7,xt=90,St=80;function Ct(e){let t=Number(e);return Number.isInteger(t)&&t>=1&&t<=xt?t:null}function wt(){let{user:e}=J();return e?.isAdmin?s(Tt,{}):null}function Tt(){let e=T(),r=D.useUtils(),i=D.auth.listAdminTokens.useQuery(),a=q(),{requestProof:c,dialog:l}=Me(`Creating an admin token`),[u,f]=o(``),[p,m]=o(String(bt)),[h,_]=o(null),[v,y]=o(!1),[b,x]=o(null),S=()=>{r.auth.listAdminTokens.invalidate(),r.auth.listAuthAudit.invalidate()},C=D.auth.createAdminToken.useMutation({onSuccess:({token:e,record:t})=>{S(),f(``),m(String(bt)),x({token:e,label:t.name})},onError:e=>_(`Create failed: ${e.message}`)}),w=D.auth.revokeAdminToken.useMutation({onSuccess:S,onError:e=>_(`Revoke failed: ${e.message}`)}),E=je(`admin-token`,yt,S),O=Date.now(),k=n(()=>(i.data??[]).map(e=>Oe(e,a,O)),[i.data,a]),A=u.trim(),j=Ct(p),M=A.length>0&&A.length<=St&&j!==null&&!C.isPending&&!v,ee=async()=>{if(!M||j===null)return;_(null),y(!0);let e=await c();y(!1),e!==null&&C.mutate({name:A,expiresInDays:j,reauthToken:e})},N=async t=>{await e({title:`Revoke admin token "${t.name}"?`,message:`Every script using it loses access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&(_(null),w.mutate({id:t.id}))};return t(`div`,{"data-testid":`admin-tokens`,children:[l,t(W,{id:`admin-tokens`,title:`Admin tokens`,icon:B,tone:`danger`,notice:K(h,E.outcome),onDismissNotice:()=>{_(null),E.dismiss()},description:t(`div`,{className:`space-y-1`,children:[t(`p`,{children:[`An admin token acts as a `,s(`strong`,{children:`full administrator`}),` for scripts, e.g.`,` `,s(`code`,{className:`font-mono`,children:`node scripts/hub/hub.mjs --token-file <file> …`}),`. Anyone holding it can do anything an admin can.`]}),s(`p`,{children:`It expires in at most 90 days and every use is audited. Creating one asks you to confirm it is you.`})]}),children:[t(`form`,{className:`grid grid-cols-1 items-end gap-2 sm:grid-cols-[1fr_120px_auto]`,onSubmit:e=>{e.preventDefault(),ee()},children:[t(`div`,{className:`space-y-1`,children:[s(z,{htmlFor:`admin-token-name`,children:`Token name`}),s(he,{id:`admin-token-name`,value:u,maxLength:St,onChange:e=>f(e.target.value),placeholder:`nightly-backup`})]}),t(`div`,{className:`space-y-1`,children:[s(z,{htmlFor:`admin-token-days`,children:`Expires in (days)`}),s(he,{id:`admin-token-days`,type:`number`,min:1,max:xt,value:p,onChange:e=>m(e.target.value),state:j===null?`error`:`default`})]}),t(g,{type:`submit`,variant:`danger`,size:`sm`,disabled:!M,children:[C.isPending||v?s(P,{className:`h-3.5 w-3.5 animate-spin`}):s(B,{className:`h-3.5 w-3.5`}),`Create admin token`]})]}),j===null&&t(`div`,{className:`text-[11px] text-danger`,children:[`Expiry must be a whole number of days, 1 to `,xt,`.`]}),s(G,{rows:k,label:`admin tokens`,isLoading:i.isLoading,loadError:i.isError?i.error?.message??`Request failed`:null,emptyText:`No admin tokens.`,action:{label:`Revoke`,icon:d,isAvailable:e=>e.status===`active`,onRun:e=>void N(e),busyId:w.isPending?w.variables?.id??null:null,disabled:w.isPending||E.busy},bulk:{revoke:E,noun:yt,isSelectable:e=>e.status===`active`}})]}),b&&s(gt,{token:b.token,label:b.label,onClose:()=>x(null)})]})}var Et={"share-link":`share links`,"admin-token":`admin tokens`,"login-session":`login sessions`};function Y(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function Dt(e,t){let n=Y(e,`tokenId`);return Y(e,`name`)??(n===null?void 0:t.get(n))??n??`?`}function X(e){return e.filter(e=>e!==null)}function Ot(e){let t=Y(e,`prefix`);return t===null?null:`Prefix ${t}…`}function kt(e,t){let n=e.detail??{};switch(e.action){case`admin-token-created`:{let e=n.expiresAt;return{title:`Admin token "${Dt(n,t)}" created`,details:X([Ot(n),typeof e==`number`?`Expires ${Re(e)}`:null])}}case`admin-token-used`:{let e=Y(n,`path`);return{title:`Admin token "${Dt(n,t)}" used`,details:X([Ot(n),e===null?null:`Call ${e}`])}}case`admin-token-revoked`:return{title:`Admin token "${Dt(n,t)}" revoked`,details:X([Ot(n)])};case`credentials-revoked`:{let e=Y(n,`kind`)??`credential`,t=n.revoked,r=n.skipped,i=Et[e]??`${e}s`;return{title:`${typeof t==`number`?String(t):`?`} ${i} revoked in bulk`,details:X([typeof r==`number`&&r>0?`${String(r)} skipped`:null,Y(n,`ids`)===null?null:`Ids ${Y(n,`ids`)??``}`])}}case`second-factor-skipped`:{let e=Y(n,`method`),t=Y(n,`factors`);return{title:`Second factor skipped on a trusted network`,details:X([e===null?null:`Signed in with ${Ie(e)}`,t===null?null:`Skipped: ${t.split(`,`).join(`, `)}`])}}default:return{title:e.action,details:Object.entries(n).map(([e,t])=>`${e}: ${String(t)}`)}}}e();var At=100;function jt(){let{user:e}=J();return e?.isAdmin?s(Nt,{}):null}function Mt(){let{data:e}=p(),{data:t}=D.auth.listAdminTokens.useQuery();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.name);return{userNameById:n,tokenNameById:r}},[e,t])}function Nt(){let e=D.auth.listAuthAudit.useQuery({limit:At}),{userNameById:n,tokenNameById:r}=Mt(),i=e.data??[];return t(`div`,{"data-testid":`auth-audit`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[t(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[s(I,{className:`h-3.5 w-3.5 text-foreground-subtle`}),s(`div`,{className:`text-xs font-semibold text-foreground`,children:`Authentication audit`}),t(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[`Latest `,At,`, newest first`]})]}),s(`div`,{className:`p-4`,children:e.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(P,{className:`h-3.5 w-3.5 animate-spin`}),`Loading audit trail…`]}):e.isError?t(`div`,{className:`text-[11px] text-danger`,children:[`Could not load the audit trail: `,e.error?.message??`Request failed`]}):i.length===0?s(`div`,{className:`rounded border border-dashed border-border px-3 py-4 text-xs text-foreground-subtle text-center`,children:`No authentication events recorded yet.`}):s(`ul`,{className:`divide-y divide-border rounded-md border border-border max-h-[420px] overflow-y-auto`,children:i.map(e=>s(Pt,{record:e,userName:e.userId===void 0?null:n.get(e.userId)??e.userId,tokenNameById:r},e.id))})})]})}function Pt({record:e,userName:n,tokenNameById:r}){let i=kt(e,r);return t(`li`,{"data-testid":`auth-audit-row`,className:`px-3 py-2 text-xs space-y-0.5`,children:[t(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[s(`span`,{className:`font-medium text-foreground`,children:i.title}),s(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Re(e.at)})]}),t(`div`,{className:`flex flex-wrap gap-x-3 text-[11px] text-foreground-subtle`,children:[n!==null&&s(`span`,{className:`text-foreground`,children:n}),e.ip!==void 0&&s(`span`,{className:`font-mono`,children:e.ip}),i.details.map(e=>s(`span`,{className:`font-mono`,children:e},e))]})]})}var Z={loginSessions:`login-sessions`,linkedApps:`linked-apps`,scopedTokens:`scoped-tokens`,adminTokens:`admin-tokens`,shareLinks:`share-links`,legacyApiKeys:`legacy-api-keys`,externalIdentities:`external-identities`,audit:`auth-audit`},Ft={state:`ok`,stateLabel:`available`,showState:!1};function Q(e,t,n,r){return{id:e,name:t,fallbackIcon:n,...Ft,render:r}}function It(){let e=F(),t=(e.data??[]).length>0;return s(rt,{icon:ct,title:`Tokens & sessions`,subtitle:`Every credential this hub honours — who holds it, what it can reach, when it was last used and when it expires. Pick a kind; revoke one, or select several and revoke them after typing the count.`,groups:[{id:`sessions`,label:`Sessions`,entries:[Q(Z.loginSessions,`Login sessions`,U,()=>s(mt,{})),Q(Z.linkedApps,`Linked apps`,v,()=>s(ft,{}))]},{id:`tokens`,label:`Tokens`,entries:[Q(Z.scopedTokens,`Scoped tokens`,S,()=>s(vt,{})),Q(Z.adminTokens,`Admin tokens`,B,()=>s(wt,{})),Q(Z.shareLinks,`Share links`,ve,()=>s(Fe,{})),...t?[Q(Z.legacyApiKeys,`Legacy API keys`,Te,()=>s(ut,{}))]:[]]},{id:`identity`,label:`Identity`,entries:[Q(Z.externalIdentities,`Sign-in links`,Je,()=>s(lt,{})),Q(Z.audit,`Audit`,I,()=>s(jt,{}))]}],isLoading:e.isLoading,emptyTitle:`No credential kinds`,emptyDescription:`This hub offers no credential kinds.`})}e();var Lt=3e4,Rt=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],$={title:`Authentication`,subtitle:`Login providers (local password, OIDC, SAML) and second-factor providers (passkeys / WebAuthn). They run in parallel — enable or disable each independently; disabling one only removes that method, local password login is unaffected.`,emptyTitle:`No authentication providers registered`,emptyDescription:`Local auth should always be available — if this list is empty the local-auth builtin failed to register. Check the Addons page for load errors.`,installLabel:`Add provider`};function zt(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:ct,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:Xe,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.`,"Set the redirect URI to `https://<this-hub>/addon/<addon-id>/callback`.",`Paste issuer + credentials in the Settings panel below — saves on every change.`,`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:Xe,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:ae,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:ae,bullets:[`Time-based codes from an authenticator app (RFC 6238).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:R,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Bt(){let e=M({capName:Rt[0].capName},{refetchInterval:Lt}),t=M({capName:Rt[1].capName},{refetchInterval:Lt}),r=we(void 0,{refetchInterval:Lt}),i=n(()=>ot(r.data??[]),[r.data]),a=n(()=>{let n=[],r=[e.data??[],t.data??[]];for(let[e,t]of Rt.entries())for(let a of r[e]??[])n.push({addonId:a.addonId,displayName:i.get(a.addonId)??a.addonId,isActive:a.isActive,capName:t.capName,stageBadge:t.stageBadge});return n},[e.data,t.data,i]),o=[{id:`authentication`,label:`Authentication providers`,install:{capability:Rt[0].capName,label:$.installLabel},entries:a.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:R,...at(e.isActive),render:()=>s(it,{addonId:e.addonId,displayName:e.displayName,capName:e.capName,isActive:e.isActive,badges:e.stageBadge===null?null:s(le,{variant:`info`,className:nt,children:e.stageBadge}),panels:[{id:`about`,title:`About`,icon:zt(e.addonId).icon,content:s(Vt,{addonId:e.addonId})}]})}))}];return s(rt,{icon:R,title:$.title,subtitle:$.subtitle,groups:o,isLoading:e.isLoading||t.isLoading,emptyTitle:$.emptyTitle,emptyDescription:$.emptyDescription})}function Vt({addonId:e}){let n=zt(e),r=n.icon;return t(`div`,{className:`space-y-3 rounded-lg border border-border bg-surface p-2 sm:p-4`,children:[t(`div`,{className:`flex items-start gap-2.5`,children:[s(r,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),s(`div`,{className:`text-xs text-foreground font-medium`,children:n.headline})]}),s(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:n.bullets.map((e,t)=>s(`li`,{children:e},t))}),n.setupSteps&&n.setupSteps.length>0&&t(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[t(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[s(st,{className:`h-3 w-3`}),`Setup steps`]}),s(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:n.setupSteps.map((e,t)=>s(`li`,{children:e},t))})]}),e===`local-auth`&&t(`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:[s(ne,{className:`h-3.5 w-3.5 mt-0.5 text-info shrink-0`}),t(`span`,{children:[`TOTP / 2FA is self-service: each user enrols from their own profile page —`,` `,s(qe,{to:`/system/my-access`,className:`underline text-primary`,children:`My access`}),` `,`→ “Two-factor authentication” → Enable 2FA. Admins can only remove a user’s active enrollment (lost device) from the`,` `,s(qe,{to:`/system/identity?tab=users`,className:`underline text-primary`,children:`Users`}),` `,`page via Actions → “Remove 2FA”.`]})]})]})}function Ht({userId:e,username:n,onClose:r}){let i=T(),a=D.useUtils(),o=ie({userId:e}),c=D.auth.listLoginMethods.useQuery(),l=oe({onSuccess:()=>void a.userManagement.listExternalIdentities.invalidate()}),u=new Map((c.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),d=o.data??[],f=async(t,r)=>{await i({title:`Remove sign-in link`,message:`"${n}" will no longer be able to sign in with this ${r} account.`,confirmLabel:`Remove`,variant:`danger`})&&l.mutate({userId:e,provider:t.provider,subject:t.subject})};return s(L,{open:!0,onOpenChange:e=>!e&&r(),children:t(j,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`external-identities-modal`,children:[s(N,{children:t(m,{className:`flex items-center gap-2`,children:[s(v,{className:`h-4 w-4 text-primary`}),t(`span`,{children:[`Linked sign-in accounts`,t(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[`User: `,s(`span`,{className:`font-mono`,children:n})]})]})]})}),s(H,{className:`space-y-3`,children:o.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(P,{className:`h-3.5 w-3.5 animate-spin`}),`Loading…`]}):d.length===0?s(`p`,{className:`text-xs text-foreground-subtle`,children:`No linked accounts. Only the user can link one, from their own profile page.`}):s(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:d.map(e=>{let n=u.get(e.provider),r=n??e.provider;return t(`li`,{className:`flex items-center gap-3 px-3 py-2 text-xs`,children:[t(`div`,{className:`flex-1 min-w-0`,children:[t(`div`,{className:`font-medium text-foreground truncate`,children:[r,n===void 0&&s(`span`,{className:`ml-2 rounded bg-foreground-subtle/15 px-1.5 py-0.5 text-[10px] font-normal text-foreground-subtle`,children:`provider unavailable`})]}),t(`div`,{className:`text-[11px] text-foreground-subtle truncate`,children:[e.label??e.subject,` ·`,` `,new Date(e.linkedAt).toLocaleDateString()]})]}),t(`button`,{onClick:()=>void f(e,r),disabled:l.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[s(De,{className:`h-3 w-3`}),`Remove`]})]},`${e.provider}|${e.subject}`)})})}),s(V,{children:s(g,{onClick:r,variant:`secondary`,children:`Close`})})]})})}function Ut({userId:e,username:n,onClose:r}){let o=a(),c=T(),l=re({userId:e}),u=l.data,d=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),f=C({onSuccess:()=>{d(),r()}}),p=l.isLoading?`loading`:u?.enabled?`enrolled`:`not_enrolled`;return s(L,{open:!0,onOpenChange:e=>!e&&r(),children:t(j,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[s(N,{children:t(m,{className:`flex items-center gap-2`,children:[s(ae,{className:`h-4 w-4 text-primary`}),t(`span`,{children:[`Two-factor authentication`,t(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[`User: `,s(`span`,{className:`font-mono`,children:n})]})]})]})}),t(H,{className:`space-y-4`,children:[p===`loading`&&t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(P,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),p===`not_enrolled`&&t(`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:[s(ne,{className:`h-4 w-4 mt-0.5 shrink-0`}),t(`div`,{children:[s(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),s(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),p===`enrolled`&&u&&t(i,{children:[t(`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:[s(ee,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),t(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[s(`div`,{className:`font-medium`,children:`2FA is active`}),t(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,u.confirmedAt?new Date(u.confirmedAt).toLocaleString():`—`]})]})]}),s(`div`,{className:`text-[11px] text-foreground-subtle`,children:`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.`}),t(`div`,{className:`flex justify-end gap-2`,children:[s(g,{onClick:r,variant:`secondary`,children:`Close`}),t(`button`,{onClick:async()=>{await c({title:`Remove 2FA`,message:`Remove two-factor authentication for "${n}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,confirmLabel:`Remove`,variant:`danger`})&&f.mutate({userId:e})},disabled:f.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:[f.isPending?s(P,{className:`h-3 w-3 animate-spin`}):s(E,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}e();function Wt({userId:e,username:n,onClose:r}){let{user:i,logout:a}=J(),c=i?.id===e,l=T(),u=D.useUtils(),d=D.auth.listSessions.useQuery({userId:e}),[f,p]=o(null),h=D.auth.revokeSessions.useMutation({onSuccess:(e,t)=>{if(c&&`userId`in t){a();return}u.auth.listSessions.invalidate()},onError:e=>p(`Sign out failed: ${e.message}`)}),_=async e=>{await l({title:`Sign out this session`,message:`"${n}" on ${Ee(e.client).label} will have to sign in again.`,confirmLabel:`Sign out`,variant:`danger`})&&(p(null),h.mutate({id:e.id}))},v=async()=>{await l({title:`Sign out everywhere`,message:c?`Every session of your own account ends, this browser included: you will be signed out here too.`:`Every session of "${n}" ends at once; each device has to sign in again.`,confirmLabel:`Sign out everywhere`,variant:`danger`})&&(p(null),h.mutate({userId:e}))},y=h.isPending&&h.variables!==void 0&&`id`in h.variables?h.variables.id:null;return s(L,{open:!0,onOpenChange:e=>!e&&r(),children:t(j,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`user-sessions-modal`,children:[s(N,{children:t(m,{className:`flex items-center gap-2`,children:[s(U,{className:`h-4 w-4 text-primary`}),t(`span`,{children:[`Active sessions`,t(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[`User: `,s(`span`,{className:`font-mono`,children:n})]})]})]})}),t(H,{className:`space-y-3`,children:[f!==null&&s(`div`,{className:`text-[11px] text-danger`,children:f}),s(ze,{sessions:d.data??[],isLoading:d.isLoading,loadError:d.isError?d.error?.message??`Request failed`:null,emptyText:`No active sessions.`,onRevoke:e=>void _(e),revokingId:y})]}),t(V,{className:`justify-between`,children:[t(`button`,{onClick:()=>void v(),disabled:h.isPending||(d.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&&y===null?s(P,{className:`h-3 w-3 animate-spin`}):s(Qe,{className:`h-3 w-3`}),`Sign out everywhere`]}),s(g,{onClick:r,variant:`secondary`,children:`Close`})]})]})})}function Gt({icon:e,label:n,count:r,all:i,total:a}){return t(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[s(e,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(`span`,{className:`min-w-0 flex-1 text-foreground-subtle`,children:n}),s(`span`,{className:r===0?`text-foreground-subtle`:`font-medium text-foreground`,children:r===0?`none`:i?`all ${a}`:`${r} of ${a}`})]})}function Kt({scopes:e,isAdmin:n,invalidReason:a}){let o=c(),l=r({queryKey:[`auth`,`previewScope`,e,n],enabled:a===null,queryFn:()=>o.trpcClient.auth.previewScope.query({scopes:[...e],isAdmin:n})}),{data:u}=se({projection:`slim`}),f=u?.length??0;if(a!==null)return s(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:t(`p`,{className:`flex items-center gap-1.5 text-[11px] text-warning`,children:[s(B,{className:`h-3 w-3 shrink-0`}),a]})});if(l.isLoading)return t(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface p-3 text-[11px] text-foreground-subtle`,children:[s(P,{className:`h-3 w-3 animate-spin`}),`Resolving…`]});if(l.isError||!l.data)return s(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:s(`p`,{className:`text-[11px] text-danger`,children:`Could not resolve this grant set. Saving is still allowed — the server enforces the same rules either way.`})});let p=l.data;return s(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-3`,children:p.isAdmin?t(`p`,{className:`text-[11px] text-foreground`,children:[s(`span`,{className:`font-medium`,children:`Administrator`}),` — unrestricted. Grants are ignored for an admin.`]}):t(i,{children:[s(Gt,{icon:ce,label:`Devices they can see`,count:p.device.view.deviceCount,all:p.device.view.all,total:f}),s(Gt,{icon:fe,label:`Devices they can operate`,count:p.device.create.deviceCount,all:p.device.create.all,total:f}),s(Gt,{icon:d,label:`Devices they can delete`,count:p.device.delete.deviceCount,all:p.device.delete.all,total:f}),t(`div`,{className:`border-t border-border pt-2 text-[10px] text-foreground-subtle`,children:[`System access: `,p.system.length===0?`none`:p.system.join(`, `),p.capabilities.length>0&&t(i,{children:[` · Extra capabilities: `,p.capabilities.map(e=>e.name).join(`, `)]}),p.addons.length>0&&t(i,{children:[` · Addons: `,p.addons.map(e=>e.name).join(`, `)]})]}),p.device.view.deviceCount===0&&s(`p`,{className:`text-[10px] text-warning`,children:`This user will not be able to see any device.`})]})})}e();function qt(e){let t=Ue(e);return t===null?{mode:e.length===0?`role`:`advanced`,roleId:null,selector:{kind:`all`},includeLinked:!0,advancedScopes:e}:{mode:`role`,roleId:t.roleId,selector:t.selector,includeLinked:t.includeLinked,advancedScopes:e}}function Jt(e){return e.mode===`advanced`?e.advancedScopes:e.roleId===null?[]:Ve({roleId:e.roleId,selector:e.selector,includeLinked:e.includeLinked})}function Yt({user:e,onClose:r,onSubmit:a,submitting:c,callerScopes:d}){let f=n(()=>qt(e.scopes??[]),[e.scopes]),[p,_]=o(f),[v,y]=o(f.mode===`advanced`),b=n(()=>Jt(p),[p]),x=!e.isAdmin&&p.mode===`role`&&p.roleId===null,S=n(()=>e.isAdmin?null:p.mode===`role`&&p.roleId===null?`Pick what this user can do to see the result.`:h(b),[e.isAdmin,p.mode,p.roleId,b]),C=e=>_({...p,...e});return s(L,{open:!0,onOpenChange:e=>!e&&r(),children:t(j,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-2xl`,children:[t(N,{children:[t(m,{children:[`Access — `,e.username]}),s(`p`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?`This user is an administrator — they can do everything, and the settings below are ignored.`:`Choose what they can do, then which devices it applies to.`})]}),t(H,{className:`space-y-4`,children:[x&&t(`div`,{className:`flex items-start gap-2 rounded-lg border border-warning/40 bg-warning/10 p-3`,children:[s(B,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`}),t(`p`,{className:`text-[11px] text-foreground`,children:[s(`span`,{className:`font-medium`,children:`No access.`}),` `,t(`span`,{className:`text-foreground-subtle`,children:[e.username,` cannot see or do anything yet. Configure it below.`]})]})]}),t(`section`,{className:`space-y-2`,children:[s(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`1 · What can they do`}),s(`div`,{className:`space-y-1.5`,children:He.map(e=>{let n=p.mode===`role`&&p.roleId===e.id;return t(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-lg border p-2.5 transition-colors ${n?`border-primary bg-primary/5`:`border-border hover:bg-foreground-subtle/5`}`,children:[s(`input`,{type:`radio`,name:`access-role`,checked:n,onChange:()=>C({mode:`role`,roleId:e.id}),className:`mt-0.5 border-border focus:ring-primary`}),t(`span`,{className:`min-w-0`,children:[s(`span`,{className:`block text-[12px] font-medium text-foreground`,children:e.label}),s(`span`,{className:`mt-0.5 block text-[10px] text-foreground-subtle`,children:e.description})]})]},e.id)})}),t(`button`,{type:`button`,onClick:()=>{if(!v){_({...p,mode:`advanced`,advancedScopes:b}),y(!0);return}y(!1),_(qt(p.advancedScopes))},className:`inline-flex items-center gap-1 rounded px-1.5 py-1 text-[10px] text-foreground-subtle transition-colors hover:bg-foreground-subtle/10 hover:text-foreground`,children:[s(v?l:u,{className:`h-3 w-3`}),`Advanced — edit raw grants`]}),v&&t(`div`,{className:`rounded-lg border border-border p-2`,children:[s(`p`,{className:`mb-2 text-[10px] text-foreground-subtle`,children:`One row per grant. Anything expressible here overrides the three roles above; close this section to go back to them.`}),s(O,{value:p.advancedScopes,onChange:e=>C({mode:`advanced`,advancedScopes:e}),clampToParent:d,emptyHint:t(i,{children:[`No grants.`,` `,s(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until one is added.`]})})]})]}),p.mode===`role`&&t(`section`,{className:`space-y-2`,children:[s(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`2 · On which devices`}),s(te,{value:p.selector,onChange:e=>C({selector:e}),includeLinked:p.includeLinked,onIncludeLinkedChange:e=>C({includeLinked:e}),clampToDeviceIds:null})]}),t(`section`,{className:`space-y-2`,children:[s(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:p.mode===`role`?`3 · Result`:`2 · Result`}),s(Kt,{scopes:b,isAdmin:e.isAdmin,invalidReason:S})]})]}),t(V,{children:[s(g,{variant:`outline`,size:`sm`,onClick:r,children:`Cancel`}),s(g,{size:`sm`,onClick:()=>a([...b]),disabled:c||S!==null,children:c?s(P,{className:`h-3 w-3 animate-spin`}):`Save access`})]})]})})}e();var Xt=8;function Zt(){let e=a(),{user:n}=J(),[r,i]=o(!1),[c,l]=o(``),[u,f]=o(``),[m,h]=o(!1),[g,_]=o(null),{data:y,isLoading:b,isError:S}=p(),C=T(),D=xe(),O=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),k=w({onSuccess:()=>{O(),i(!1),l(``),f(``),h(!1),_(null)},onError:e=>{_(e instanceof Error?e.message:`Failed to create user`)}}),A=be({onSuccess:O}),j=_e({onSuccess:O}),M=ue({onSuccess:O}),ee=de({onSuccess:()=>{O(),te(null)}}),[N,te]=o(null),[F,ne]=o(null),[re,ie]=o(null),[I,oe]=o(null),L=y??[];async function se(e){await C({title:`Delete user`,message:`Permanently delete user "${e.username}"? This cannot be undone — any active sessions will be revoked on next request.`,confirmLabel:`Delete`,variant:`danger`})&&A.mutate({id:e.id})}async function ce(e){let t=await D({title:`Reset password`,message:`Set a new password for "${e.username}".`,label:`New password`,inputType:`password`,placeholder:`At least 8 characters`,confirmLabel:`Continue`,validate:e=>e.length<Xt?`Password must be at least ${String(Xt)} characters.`:null});t===null||t.length===0||await C({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&M.mutate({id:e.id,newPassword:t})}function z(e,t){t!==e.isAdmin&&j.mutate({id:e.id,isAdmin:t})}function le(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}return t(et,{children:[s(`div`,{className:`flex items-center justify-end`,children:t(`button`,{onClick:()=>i(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm hover:bg-primary/90`,children:[s(pe,{className:`h-3.5 w-3.5`}),`Create User`]})}),r&&t(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[t(`div`,{className:`flex items-center justify-between`,children:[s(`span`,{className:`text-xs font-medium text-foreground`,children:`New User`}),s(`button`,{onClick:()=>i(!1),className:`text-foreground-subtle hover:text-foreground`,children:s(E,{className:`h-4 w-4`})})]}),t(`div`,{className:`grid grid-cols-3 gap-3`,children:[t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),s(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`john`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Password`}),s(`input`,{type:`password`,value:u,onChange:e=>f(e.target.value),placeholder:`••••••••`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),t(`label`,{className:`flex items-center gap-2 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:m,onChange:e=>h(e.target.checked),className:`rounded border-border focus:ring-primary`}),s(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),g&&s(`p`,{className:`text-[10px] text-danger`,children:g}),t(`div`,{className:`flex justify-end gap-2`,children:[s(`button`,{onClick:()=>i(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),s(`button`,{onClick:()=>k.mutate({username:c,password:u,isAdmin:m}),disabled:k.isPending||!c||!u,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:k.isPending?`Creating...`:`Create`})]})]}),b&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),S&&s(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!b&&!S&&L.length===0&&s(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>A.isPending&&A.variables?.id===e.id||j.isPending&&j.variables?.id===e.id||M.isPending&&M.variables?.id===e.id;return s(x,{columns:[{key:`username`,header:`Username`,render:e=>e.username},{key:`isAdmin`,header:`Admin`,render:n=>t(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:n.isAdmin,onChange:e=>z(n,e.target.checked),disabled:e(n),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),s(`span`,{className:n.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:n.isAdmin?`Admin`:`Regular`})]})},{key:`scopes`,header:`Access`,render:e=>e.isAdmin?s(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:`everything (admin)`}):t(`button`,{onClick:()=>te(e),className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] hover:bg-foreground-subtle/10`,title:`Configure access`,children:[s(R,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(Qt,{scopes:e.scopes??[]})]})},{key:`createdAt`,header:`Created`,render:e=>s(`span`,{className:`text-foreground-subtle`,children:le(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:r=>{let i=e(r);return t(`div`,{className:`flex items-center justify-end gap-1`,children:[r.id!==n?.id&&r.totpEnabled&&t(`button`,{onClick:()=>ne(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Remove two-factor authentication`,children:[s(ae,{className:`h-3 w-3`}),`Remove 2FA`]}),t(`button`,{onClick:()=>ie(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Linked sign-in accounts`,children:[s(v,{className:`h-3 w-3`}),`Sign-in links`]}),t(`button`,{onClick:()=>oe(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Active sessions`,children:[s(U,{className:`h-3 w-3`}),`Sessions`]}),t(`button`,{onClick:()=>ce(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Reset password`,children:[s(ye,{className:`h-3 w-3`}),`Reset password`]}),t(`button`,{onClick:()=>se(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete user`,children:[i?s(P,{className:`h-3 w-3 animate-spin`}):s(d,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:L,rowKey:e=>e.id,minWidthPx:560})})(),F&&s(Ut,{userId:F.id,username:F.username,onClose:()=>ne(null)}),re&&s(Ht,{userId:re.id,username:re.username,onClose:()=>ie(null)}),I&&s(Wt,{userId:I.id,username:I.username,onClose:()=>oe(null)}),N&&s($t,{user:N,onClose:()=>te(null),onSubmit:e=>ee.mutate({userId:N.id,scopes:e}),submitting:ee.isPending})]})}function Qt({scopes:e}){if(e.length===0)return s(`span`,{className:`font-medium text-warning`,children:`No access`});let n=Ue(e);return n===null?t(`span`,{className:`text-foreground-subtle`,children:[`Custom · `,e.length,` grant`,e.length===1?``:`s`]}):t(`span`,{className:`text-foreground-subtle`,children:[s(`span`,{className:`font-medium text-foreground`,children:We(n.roleId).label}),` ·`,` `,_(n.selector)]})}function $t(e){let{user:t}=J(),n=t?.isAdmin===!0;return s(Yt,{...e,callerScopes:n?null:t?.scopes??[]})}var en={"api-keys":Z.scopedTokens,"linked-sessions":Z.linkedApps};function tn(){let[e]=Ge(),t=en[e.get(`tab`)??``];return t===void 0?s(`div`,{className:`flex flex-col p-4`,children:s(tt,{tabs:[{id:`users`,label:`Users`,icon:b,content:s(Zt,{})},{id:Ye.access.tab,label:`Tokens & sessions`,icon:S,content:s(It,{}),ownedParams:$e},{id:Ye.authentication.tab,label:`Authentication`,icon:R,content:s(Bt,{}),ownedParams:$e}]})}):s(Ke,{to:Ze(`access`,{integration:t}),replace:!0})}export{tn as IdentityPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{I as e,K as t,Q as n,S as r,W as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as l,gt as u,ht as d,mt as f,st as p,vt as m}from"./player-overlays-D9aoM64J.js";import{$a as h,$i as g,At as _,Cd as v,Dr as y,En as b,Fu as x,Gi as S,Hi as C,J as w,Ji as T,Mu as ee,Pa as te,Qa as E,Qt as D,Sd as ne,Sn as O,Td as re,Tn as k,Ud as A,Ui as j,Vi as M,Wi as N,Y as P,Yi as ie,Z as F,_a as I,_d as L,ao as R,bf as z,bn as B,ca as ae,cf as V,ea as H,eo as oe,ha as U,hu as se,kd as ce,kf as W,lr as le,md as ue,no as de,pn as G,qf as fe,qi as K,qu as q,ra as pe,ro as J,to as Y,ur as me,vu as he,wf as ge,xn as _e,xu as ve,yt as ye,zt as be}from"./src-B-IRCQFw.js";import{Er as X}from"./client-DX0rAC3X.js";import{t as xe}from"./useTranslation-Bc5yH9V9.js";import{$ as Se,I as Ce,Q as we,Z as Te,q as Ee}from"./index-D7yeH_53.js";import{t as De}from"./NodeAddonsSettingsPanel-Bb9dwuSU.js";import{t as Oe}from"./device-integration-icon-JFsHsv7_.js";import{n as ke,r as Ae,t as je}from"./ScanNetworkModal-C4IaFGug.js";var Me=m(`search-x`,[[`path`,{d:`m13.5 8.5-5 5`,key:`1cs55j`}],[`path`,{d:`m8.5 8.5 5 5`,key:`a8mexj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]);n();function Ne(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Ne(n.fields));return t}function Pe(t,n,r){let[a,s]=o(`idle`),[c,l]=o({}),u=i(()=>{let e=[];for(let n of t.sections)e.push(...Ne(n.fields));return e},[t]),d=u.length>0&&r!==void 0,f=e(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:a,hasProbeFields:d,probeResults:c,handleTestAll:e(async()=>{if(!r)return;let e=u.filter(e=>{let t=n[e];return t!=null&&String(t).trim()!==``});if(e.length===0)return;s(`testing`);let t={};for(let n of e)t[n]={status:`probing`};l(t);let i=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await r(e,n[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),a={};for(let e of i)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`)},[r,u,n]),clearProbeResult:f}}n();function Z(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(...Z(n.fields));return t}function Fe(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Ie(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Ie(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function Le(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function Re({open:t,integrationId:n,addonId:l,onClose:d}){let{t:f}=xe(),p=a(),[m,h]=o({}),[g,_]=o(!1),[v,y]=o(null),[b,S]=o(Le),C=U({addonId:l},{enabled:t}),w=C.data?.deviceType??null,E=pe({addonId:l,type:w??X.Camera},{enabled:t&&C.isSuccess&&w!==null}),D=E.data??null;c(()=>{t&&(h(D?Ie(D.sections.flatMap(e=>e.fields)):{}),S(Le()),_(!1),y(null))},[t,n,D]);let ne=i(()=>({...m,_probeRequestId:b}),[m,b]),O=T({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),re=te(),k=e(async(e,t)=>{_(!0);let n=await re.mutateAsync({addonId:l,type:w??X.Camera,key:e,value:t,formValues:ne});return n.status===`ok`&&n.suggestedValues&&h(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Fe(e[i])&&!Fe(a)&&(r[i]=a,t=!0);return t?r:e}),n},[re,l,ne,w]),{testAllStatus:j,hasProbeFields:M,probeResults:N,handleTestAll:P,clearProbeResult:ie}=Pe(D??{sections:[]},m,k);async function F(e){y(null);try{await O.mutateAsync({addonId:l,type:w??X.Camera,config:m,integrationId:n}),e?h(D?Ie(D.sections.flatMap(e=>e.fields)):{}):d()}catch(e){y(e instanceof Error?e.message:String(e))}}if(!t)return null;let I=Z((D?.sections??[]).flatMap(e=>e.fields)).filter(e=>Fe(m[e])),R=I.length===0,z=C.isLoading||w!==null&&E.isLoading,B=C.isError||C.isSuccess&&w===null||E.isError||E.isSuccess&&D===null;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:d}),r(`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:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:f(`integrations.addDevice`)}),s(`button`,{onClick:d,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:s(ee,{className:`h-4 w-4`})})]}),s(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:z?s(`div`,{className:`flex items-center justify-center py-8`,children:s(A,{className:`h-5 w-5 animate-spin text-primary`})}):B?r(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[s(q,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`space-y-1`,children:[s(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,s(`span`,{className:`font-mono`,children:l}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):s(Ce,{schema:D,values:m,onChange:h,onTestField:k,probeResults:N,onClearProbe:ie})}),!B&&!z&&r(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[r(`button`,{type:`button`,onClick:()=>_(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:[r(`span`,{className:`flex items-center gap-2`,children:[s(L,{className:`h-3.5 w-3.5`}),`Test logs`,s(`span`,{className:`font-mono text-[9px] opacity-60`,children:b.slice(0,14)})]}),s(u,{className:`h-3.5 w-3.5 transition-transform ${g?`rotate-180`:``}`})]}),g&&s(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:s(ye,{addonId:l,requestId:b,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!B&&!z&&(v||I.length>0)&&s(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[s(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),s(`p`,{className:`text-[11px] text-destructive`,children:v||`Required: ${I.join(`, `)}`})]})}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[r(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:d,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`)}),!B&&M&&r(`button`,{type:`button`,onClick:P,disabled:j===`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:[j===`testing`?s(A,{className:`h-3.5 w-3.5 animate-spin`}):s(x,{className:`h-3.5 w-3.5`}),`Test All`]})]}),r(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:()=>F(!0),disabled:B||!R||O.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:f(`integrations.saveAndNew`)}),s(`button`,{onClick:()=>F(!1),disabled:B||!R||O.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:O.isPending?f(`integrations.saving`):f(`integrations.save`)})]})]})]})]})}var ze=1500;function Be({addonId:e,integrationId:t,jobId:n,onFinished:i}){let{t:a}=xe(),o=M(),c=(N({addonId:e,integrationId:t},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?ze:!1}).data??[]).find(e=>e.jobId===n);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&&i();let f=[`${u}/${c.total} ${a(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];c.adopted>0&&f.push(`${c.adopted} ${a(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),c.alreadyAdopted>0&&f.push(`${c.alreadyAdopted} ${a(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),c.failed>0&&f.push(`${c.failed} ${a(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let p=f.join(` · `);return r(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[r(`div`,{className:`flex items-center gap-2`,children:[l?s(A,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):c.failed>0?s(q,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):c.state===`cancelled`?s(z,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):s(ge,{className:`h-3.5 w-3.5 text-primary shrink-0`}),s(`p`,{className:`text-[11px] text-foreground`,children:p}),l&&s(`button`,{onClick:()=>o.mutate({jobId:n}),className:`ml-auto rounded-lg border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:a(`integrations.adoptJobCancel`,{defaultValue:`Stop`})})]}),s(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:s(`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(e=>r(`p`,{className:`text-[11px] text-destructive`,children:[e.childNativeId,`: `,e.error]},e.childNativeId))]})}function Q(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(` `)}n();var $=`devices`,Ve={id:$,label:`Devices`,isDefault:!0},He=2e4,Ue=100;function We({addonId:n,integrationId:i,onClose:l}){let{t:u}=xe(),d=a(),[f,p]=o(new Set),[m,h]=o(new Set),[g,_]=o(new Map),[v,y]=o(null),{data:b}=oe(),x=(b??[]).find(e=>e.addonId===n)?.supportsLocationImport??!1,[T,te]=o(!0),E=C({addonId:n,integrationId:i}).data?.filters,D=E&&E.length>0?E:[Ve],[O,re]=o(D.find(e=>e.isDefault)?.id??(D.some(e=>e.id===$)?$:D[0].id)),k=O!==$,M=S(),N=j({addonId:n,integrationId:i,page:1,pageSize:He,filter:O}),P=N.refetch,ie=M.mutate,F=e(()=>{ie({addonId:n,integrationId:i},{onSettled:()=>{P()}})},[ie,n,i,P]),I=t(null);c(()=>{let e=`${n}::${i}`;I.current===e||N.isLoading||(I.current=e,(N.data?.candidates.length??0)===0&&F())},[n,i,N.isLoading,N.data,F]);let L=M.isPending,R=M.isError?M.error instanceof Error?M.error.message:String(M.error):null,z=typeof M.data?.lastError==`string`&&M.data.lastError.length>0?M.data.lastError:null,B=N.data?.candidates??[],ae=N.isError?N.error instanceof Error?N.error.message:String(N.error):null,V=K(),[H,U]=o(null),se=e(e=>{e.alreadyAdopted||p(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),ce=e(e=>{h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),le=e((e,t)=>{_(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})},[]),ue=e(e=>{let t={};for(let n of e){let e=g.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[g]),de=e(async()=>{y(null);let e=[...f];if(e.length!==0)try{let t=ue(e),{jobId:r}=await V.mutateAsync({addonId:n,integrationId:i,filter:O,childNativeIds:e,...t?{perCandidate:t}:{},...x?{importLocations:T}:{}});U(r),p(new Set),_(new Map)}catch(e){y(e instanceof Error?e.message:String(e))}},[f,ue,V,n,i,O,x,T]),G=t(null),fe=e(()=>{H===null||G.current===H||(G.current=H,P(),d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]}))},[H,P,d]),pe=e(e=>{re(e),p(new Set),h(new Set),_(new Map),y(null)},[]),J=f.size,Y=H!==null&&J===0&&!V.isPending;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:l}),r(`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:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[r(`div`,{className:`min-w-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:u(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),s(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:u(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),r(`div`,{className:`flex items-center gap-3 shrink-0`,children:[x&&r(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[s(`input`,{type:`checkbox`,checked:T,onChange:e=>te(e.target.checked),className:`accent-primary`}),u(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),s(`button`,{onClick:l,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:s(ee,{className:`h-4 w-4`})})]})]}),r(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(R??ae??z)&&B.length===0&&s(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[s(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`min-w-0`,children:[s(`p`,{className:`text-xs font-medium text-destructive`,children:u(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),s(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:R??ae??z})]})]})}),D.length>1&&s(Ge,{filters:D,activeFilter:O,onSelect:pe}),s(`div`,{className:`flex-1 min-h-0`,children:s(w,{mode:`generic`,items:B,pageSize:Ue,getKey:e=>e.childNativeId,getSearchText:Q,getFilterType:e=>e.type,filterOptions:he(),filterLabel:u(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:N.isLoading||L&&B.length===0,searchPlaceholder:u(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(R??ae??z)&&B.length===0?``:u(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:r(`button`,{type:`button`,onClick:F,disabled:L,title:u(`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:[s(ne,{className:`h-3.5 w-3.5 ${L?`animate-spin`:``}`}),u(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:u(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>s(Ke,{candidate:e,expandable:!k,expanded:m.has(e.childNativeId),onToggleExpand:()=>ce(e.childNativeId),adoptedLabel:u(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:u(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=ve(e.type),n=t.icon;return r(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[s(n,{className:`h-3.5 w-3.5 shrink-0`}),t.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>s(`div`,{className:`flex items-center justify-end`,children:s(`button`,{onClick:()=>se(e),disabled:e.alreadyAdopted,"aria-label":f.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${f.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:f.has(e.childNativeId)&&s(W,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!k&&m.has(e.childNativeId),renderExpanded:k?void 0:e=>s(qe,{candidate:e,hiddenChildIds:g.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>le(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:f.has(e.childNativeId)?`bg-primary/5`:``})})]}),v&&s(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[s(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),s(`p`,{className:`text-[11px] text-destructive`,children:v})]})}),H!==null&&s(Be,{addonId:n,integrationId:i,jobId:H,onFinished:fe}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[s(`div`,{}),r(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:l,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:u(`integrations.cancel`,{defaultValue:`Cancel`})}),r(`button`,{onClick:Y?l:de,disabled:!Y&&(J===0||V.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:[V.isPending&&s(A,{className:`h-3.5 w-3.5 animate-spin`}),Y?u(`integrations.close`,{defaultValue:`Close`}):u(`integrations.addSelected`,{defaultValue:`Add selected`}),!Y&&J>0?` (${J})`:``]})]})]})]})]})}function Ge({filters:e,activeFilter:t,onSelect:n}){return s(`div`,{role:`tablist`,"aria-label":`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 s(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function Ke({candidate:e,expandable:t,expanded:n,onToggleExpand:i,adoptedLabel:a}){let o=(e.children??[]).length;return r(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&o>0?r(`button`,{type:`button`,onClick:i,"aria-label":n?`Collapse`:`Expand`,"aria-expanded":n,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[s(n?u:d,{className:`h-3.5 w-3.5`}),o]}):s(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),s(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&s(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:a})]})}function qe({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let i=e.children??[];return i.length===0?null:s(`div`,{className:`space-y-1 py-1`,children:i.map(e=>{let i=t.has(e.childNativeId),a=e.capabilities??[];return r(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${i?`opacity-50`:``}`,children:[s(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),a.length>0&&s(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:a.join(`, `)}),s(`button`,{onClick:()=>n(e.childNativeId),"aria-label":i?`Show child`:`Hide child`,title:i?`Show after adopt`:`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:s(i?f:V,{className:`h-3 w-3`})})]},e.childNativeId)})})}n();function Je(e){let t=[];for(let n of e){if(n.type===`group`){t.push(...Je(n.fields));continue}`key`in n&&typeof n.key==`string`&&t.push(n.key)}return t}function Ye(e,t){if(!e)return{};let n=new Set(e.sections.flatMap(e=>Je(e.fields))),r={};for(let e of n)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}function Xe(e){return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{if(`value`in e){let{value:t,...n}=e;return n}return e})}))}}function Ze({integrationId:e,addonId:t,name:n,kind:o,mode:c,brokerKind:l,canTest:u=!1,trpc:d,onClose:f}){let{t:p}=xe(),m=a(),{data:h,isLoading:g}=Y({id:e},{enabled:c===`account`||c===`broker`}),_=i(()=>{let e=h?.brokerId;return typeof e==`string`?e:null},[h]),{data:v,isLoading:y}=le({addonId:t,nodeId:`hub`},{enabled:c===`account`}),x=i(()=>v?Xe(v):null,[v]),S=J(),C=(t,n)=>{S.mutate({id:e,settings:t,...n?{secretKeys:[...n]}:{}},{onSuccess:()=>{m.invalidateQueries(),f()}})};return s(B,{open:!0,onOpenChange:e=>!e&&f(),children:r(O,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[s(k,{children:r(b,{children:[p(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]})}),s(_e,{children:c===`broker`?l?r(`div`,{className:`space-y-3`,children:[s(`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.`})}),_&&r(`p`,{className:`text-[11px] text-foreground`,children:[p(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,s(`span`,{className:`font-mono text-foreground-subtle`,children:_})]}),S.isPending?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[s(A,{className:`h-3 w-3 animate-spin`}),p(`integrations.saving`,{defaultValue:`Saving…`})]}):s(Ae,{kind:l,onResolved:e=>{C({brokerId:e})},onBack:f}),S.isError&&s(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):s(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):c===`account`?g||y?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[s(A,{className:`h-3 w-3 animate-spin`}),p(`integrations.loading`,{defaultValue:`Loading…`})]}):s(ke,{addonId:t,configSchema:x,canTest:u,initialName:n,initialConfig:Ye(x,h??{}),submitLabel:p(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e,secretKeys:t})=>C(e,t),onBack:f}):s(G,{trpc:d,addonId:t,nodeId:`hub`,title:n})})]})})}function Qe(e){return e==null?!1:e.sections.some(e=>e.fields.length>0)}n();function $e(){let{t}=xe(),{integrationId:n}=we(),u=a(),d=Te(),[f,m]=Se(),x=l(),[S,C]=o(!1),[T,te]=o(!1),[ne,j]=o(!1),[M,N]=o(!1),{data:z,isLoading:V}=h({id:n??``},{enabled:!!n}),{data:U}=le({addonId:z?.addonId??``,nodeId:`hub`},{enabled:!!z?.addonId}),{data:W,isSuccess:G}=oe(),K=i(()=>{let e=z?.addonId;return!e||!G?null:(W??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[W,z?.addonId,G]),{data:q}=g({}),pe=i(()=>(q?.providers??[]).some(e=>e.addonId===z?.addonId),[q,z?.addonId]),J=K!==null,Y=z?.info?.fixed===!0,he=J?K===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),ge=i(()=>{let e=z?.addonId;return!e||!G?null:(W??[]).find(t=>t.addonId===e)?.brokerKind??null},[W,z?.addonId,G]),ve=i(()=>{let e=z?.addonId;return!e||!G?!1:(W??[]).find(t=>t.addonId===e)?.canTest===!0},[W,z?.addonId,G]),X=i(()=>{let e=z?.addonId;return!e||!G?null:(W??[]).find(t=>t.addonId===e)?.mode??null},[W,z?.addonId,G]);c(()=>{f.get(`add`)===`1`&&J&&(C(!0),m(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[f,J,m]);let Ce=U!=null&&Array.isArray(U.sections)&&U.sections.some(e=>e.fields.length>0),{data:Ee}=me({addonId:z?.addonId??``,nodeId:`hub`},{enabled:!!z?.addonId&&X!==`account`}),ke=X!==null&&X!==`account`&&Qe(Ee),Ae=i(()=>z?.addonId?[z.addonId]:[],[z?.addonId]),{data:Ne}=ae({projection:`slim`},{refetchInterval:3e4}),Pe=[[`integrations`,`get`],{input:{id:n??``},type:`query`}],Z=R({onMutate:async e=>{await u.cancelQueries({queryKey:Pe});let t=u.getQueryData(Pe);return t!=null&&u.setQueryData(Pe,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&u.setQueryData(Pe,r.previous)},onSettled:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=E({onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]}),d(`/integrations`)}}),Ie=y({onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Le=I({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ze=ie({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Be=H({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=i(()=>Ne??[],[Ne]),$=i(()=>{let e=new Map;for(let t of Q)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[Q]),Ve=e(e=>$.get(e)??null,[$]),{data:He}=de(void 0),Ue=i(()=>P(He),[He]),Ge=e(e=>d(`/devices/${String(e)}`),[d]),Ke=i(()=>{let e=z?.id;return e?Q.filter(t=>{let n=Ue(t);return n.kind===`resolved`&&n.integration.id===e}):[]},[Q,z?.id,Ue]),qe=i(()=>He===void 0?null:F(Ke).length,[He,Ke])??`…`;return V?r(`div`,{className:`p-4`,children:[s(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),s(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):z?r(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[s(be,{items:[{label:`Integrations`,onClick:()=>d(`/integrations`)},{label:z.name}]}),r(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[r(`div`,{className:`flex items-center gap-3 min-w-0`,children:[s(et,{addonId:z.addonId}),r(`div`,{className:`min-w-0`,children:[s(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:z.name}),r(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[z.addonId,` · `,qe,` `,t(`integrations.devices`)]})]})]}),r(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[pe&&r(`button`,{onClick:()=>te(!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:`Scan the network for devices (incl. a different subnet)`,children:[s(re,{className:`h-3.5 w-3.5`}),`Scan network`]}),!Y&&r(`button`,{onClick:()=>C(!0),disabled:!J,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:he,children:[s(ce,{className:`h-3.5 w-3.5`}),he]}),r(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Z.isPending?`opacity-60`:``} ${z.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[s(D,{checked:z.enabled,onCheckedChange:e=>Z.mutate({id:n,enabled:e}),disabled:Z.isPending,"aria-label":z.enabled?`Disable integration`:`Enable integration`}),s(`span`,{className:`text-[11px] font-medium ${z.enabled?`text-success`:`text-foreground-subtle`}`,children:z.enabled?`Enabled`:`Disabled`}),Z.isPending&&s(A,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),X!==`standalone`&&(Ce||K===`device-adoption`)&&r(`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:[s(ue,{className:`h-3 w-3`}),t(`integrations.config`)]}),r(`button`,{onClick:()=>N(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:t(`integrations.logs`,{defaultValue:`View logs`}),children:[s(L,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),s(_,{label:`Restart`,icon:v,title:`Restart "${z.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${qe} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Ie.isPending,action:()=>Ie.mutateAsync({addonId:z.addonId})}),!Y&&n&&s(_,{label:t(`integrations.delete`,{defaultValue:`Delete`}),icon:p,title:t(`integrations.deleteTitle`,{defaultValue:`Delete integration?`}),description:t(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:z.name,count:qe}),confirmLabel:t(`integrations.confirmDelete`,{defaultValue:`Delete integration`}),triggerVariant:`outline`,confirmVariant:`danger`,className:`border-danger bg-danger/10 text-danger hover:bg-danger hover:text-background`,disabled:Fe.isPending,action:()=>Fe.mutateAsync({id:n})})]})]}),ke&&s(De,{nodeId:null,addonIds:Ae,level:`global`,surface:`integration`,title:t(`integrations.settings`,{defaultValue:`Settings`})}),s(w,{context:`integration-detail`,devices:Q,trpc:x.trpcClient,integrationOf:Ue,forceIntegrationId:z.id,urlScope:`root`,lsKey:`integration-detail:${z.addonId}`,resolveIntegrationIcon:Oe,resolveParent:Ve,onNavigate:Ge,batchActions:{remove:Le.mutate,disable:ze.mutate,enable:Be.mutate},...Y?{}:{onDeleteDevice:e=>Le.mutate({deviceId:e.id})}}),S&&n&&K===`device-adoption`&&s(We,{addonId:z.addonId,integrationId:n,onClose:()=>C(!1)}),S&&n&&K===`device-provider`&&s(Re,{open:S,integrationId:n,addonId:z.addonId,onClose:()=>C(!1)}),T&&z&&s(je,{open:T,scope:{addonId:z.addonId,label:z.name},onClose:()=>te(!1)}),ne&&n&&K!==null&&X!==null&&s(Ze,{integrationId:n,addonId:z.addonId,name:z.name,kind:K,mode:X,brokerKind:ge,canTest:ve,trpc:x.trpcClient,onClose:()=>j(!1)}),M&&s(B,{open:!0,onOpenChange:e=>!e&&N(!1),children:r(O,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[r(k,{className:`flex-row items-center justify-between gap-2 mb-0`,children:[r(b,{className:`flex items-center gap-2 min-w-0`,children:[s(L,{className:`h-4 w-4 text-primary shrink-0`}),s(`span`,{className:`truncate`,children:z.name}),r(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate font-normal`,children:[z.addonId,n?` · ${n}`:``]})]}),s(se,{icon:ee,variant:`ghost`,size:`sm`,"aria-label":`Close`,onClick:()=>N(!1)})]}),s(_e,{className:`min-h-0 overflow-hidden p-0`,children:s(ye,{addonId:z.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})})]}):r(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[s(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:s(Me,{className:`h-6 w-6 text-foreground-subtle`})}),r(`div`,{className:`space-y-1 max-w-sm`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),s(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:n??``})})]}),r(`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:[s(fe,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}function et({addonId:e}){let t=Ee(e),[n,r]=o(!1);return!t||n?null:s(`img`,{src:t,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:()=>r(!0)})}export{$e as IntegrationDetailPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Q as e,S as t,W as n,b as r,o as i,q as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{st as s}from"./player-overlays-D9aoM64J.js";import{Bd as c,Cn as l,En as u,Fi as d,Fn as f,Fu as p,K as m,Kn as h,Mn as g,Od as _,Sn as v,Tn as y,Ud as b,ai as x,bn as ee,ci as S,di as C,er as w,fi as T,jd as E,kd as D,li as te,oi as ne,pd as re,pi as ie,q as ae,ui as oe,wd as O,xn as k,xr as A}from"./src-B-IRCQFw.js";import{t as j}from"./monitor-smartphone-DCj4MFCV.js";import{Cr as M,Nt as N,tr as P}from"./client-DX0rAC3X.js";import{I as F,Z as I}from"./index-D7yeH_53.js";import{t as L}from"./BrokerForm-BKrrZCZh.js";import{n as R,r as z,t as B}from"./AddonIntegrationBody-EbUl8tUN.js";e();var V=`kind`,H=`name`,U=`restore`,W=`restoreId`;function G(e){return{sections:[{id:`broker-identity`,title:`Broker`,columns:1,fields:[{type:`select`,key:V,label:`Kind`,options:e.map(e=>({value:e.key,label:e.label})),disabled:e.length<=1},{type:`text`,key:H,label:`Name`,placeholder:`My Home Assistant`,required:!0},{type:`boolean`,key:U,label:`Restore a broker that was removed, under its original id`,description:`Devices remember the broker id they were discovered under, so restoring the original id reconnects them instead of needing re-discovery. An id that is still in use is refused.`},{type:`text`,key:W,label:`Original broker id`,placeholder:`ha_004`,required:!0,showWhen:{field:U,equals:!0}}]}]}}function K(e){let t=t=>{let n=e[t];return typeof n==`string`?n.trim():``},n=t(V);if(n===``)return{ok:!1,problem:`Pick a kind.`};let r=t(H);if(r===``)return{ok:!1,problem:`Enter a name before saving.`};if(e.restore!==!0)return{ok:!0,identity:{kindKey:n,name:r,restoreId:null}};let i=t(W);return i===``?{ok:!1,problem:`Enter the original id, or turn restore off to create a new broker.`}:{ok:!0,identity:{kindKey:n,name:r,restoreId:i}}}var q={"home-assistant":`Home Assistant`,mqtt:`MQTT`};function J(e){return q[e]??e}function se(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var ce={connected:`success`,connecting:`warning`,disconnected:`default`,"auth-failed":`danger`,unreachable:`danger`,error:`danger`};function le({status:e}){return o(w,{variant:ce[e],className:`text-[10px]`,children:e})}function ue(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function Y({title:e,subtitle:n,onClose:r,children:i}){return o(ee,{open:!0,onOpenChange:e=>!e&&r(),children:t(v,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[t(y,{children:[o(u,{children:e}),n&&o(l,{children:n})]}),o(k,{className:`space-y-3 pr-1`,children:i})]})})}function de({kinds:e,onClose:r,onDone:s}){let c=i(),l=n(()=>G(e.map(e=>({key:X(e),label:e.label}))),[e]),[u,d]=a(()=>({[V]:X(e[0]),[H]:``,[U]:!1,[W]:``})),[f,p]=a(null),m=e.find(e=>X(e)===u.kind)??e[0],h=m?.kind??``,_=m?.addonId,v=x({onSuccess:()=>{c.invalidateQueries({queryKey:[[`broker`,`list`]]}),s()}}),y=e=>{let t=K(u);if(!t.ok){p(t.problem);return}p(null);let{name:n,restoreId:r}=t.identity;v.mutate({kind:h,name:n,settings:e,...r===null?{}:{id:r},..._===void 0?{}:{addonId:_}})};return t(Y,{title:`Add broker`,subtitle:`Register a message broker for exporters and automations.`,onClose:v.isPending?()=>{}:r,children:[o(F,{schema:l,values:u,onChange:d}),f!==null&&o(g,{message:f}),v.isError&&o(g,{message:v.error instanceof Error?v.error.message:String(v.error)}),h&&o(L,{kind:h,..._===void 0?{}:{addonId:_},onSubmit:y,onCancel:r,submitLabel:v.isPending?`Adding…`:`Add broker`,disabled:v.isPending},X(m))]})}function X(e){return e===void 0?``:`${e.addonId??``}::${e.kind}`}function fe({broker:e,onClose:r,onDone:a}){let s=i(),c=ne({id:e.id,addonId:e.addonId}),l=T({onSuccess:()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]}),s.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:e.id,addonId:e.addonId}}]}),a()}}),u=n(()=>{let e=c.data;return e&&typeof e==`object`?{...e}:{}},[c.data]);return o(Y,{title:`Edit ${e.name}`,subtitle:`${J(e.kind)} · ${e.id}`,onClose:l.isPending?()=>{}:r,children:c.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[o(b,{className:`h-3.5 w-3.5 animate-spin`}),` Loading settings…`]}):c.isError?t(`div`,{className:`space-y-3`,children:[o(g,{message:`Failed to load settings: ${c.error instanceof Error?c.error.message:`Unknown error`}`}),o(`div`,{className:`flex justify-end`,children:o(f,{variant:`outline`,size:`sm`,onClick:r,children:`Close`})})]}):t(`div`,{className:`space-y-3`,children:[l.isError&&o(g,{message:l.error instanceof Error?l.error.message:String(l.error)}),o(L,{kind:e.kind,addonId:e.addonId,initialValues:u,onSubmit:t=>{l.mutate({id:e.id,settings:t,addonId:e.addonId})},onCancel:r,submitLabel:l.isPending?`Saving…`:`Save`,disabled:l.isPending})]})})}function pe({broker:e,onEdit:n}){let r=i(),c=h(),[l,u]=a(null),d=ie({onSuccess:e=>u(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>u({ok:!1,error:e instanceof Error?e.message:String(e)})}),m=C({onSuccess:()=>{r.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),g=async()=>{await c({title:`Delete broker`,message:`Delete broker "${e.name}"? Integrations that depend on it will stop working.`,confirmLabel:`Delete`,variant:`danger`})&&m.mutate({id:e.id,addonId:e.addonId})};return t(`tr`,{className:`border-b border-border last:border-0`,children:[o(`td`,{className:`px-3 py-2 text-xs text-foreground font-medium`,children:e.name}),o(`td`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:J(e.kind)}),t(`td`,{className:`px-3 py-2`,children:[o(le,{status:e.status}),l&&o(`span`,{className:`ml-2 text-[10px] ${l.ok?`text-success`:`text-danger`}`,children:l.ok?`OK`:l.error??`failed`})]}),o(`td`,{className:`px-3 py-2`,children:t(`div`,{className:`flex items-center justify-end gap-1.5`,children:[t(f,{variant:`outline`,size:`sm`,onClick:()=>d.mutate({id:e.id,addonId:e.addonId}),disabled:d.isPending,title:`Test connection`,children:[d.isPending?o(b,{className:`h-3 w-3 animate-spin`}):o(p,{className:`h-3 w-3`}),`Test`]}),t(f,{variant:`outline`,size:`sm`,onClick:()=>n(e),title:`Edit`,children:[o(E,{className:`h-3 w-3`}),` Edit`]}),t(f,{variant:`outline`,size:`sm`,className:`border-danger/40 text-danger hover:bg-danger/10`,onClick:()=>{g()},disabled:m.isPending,title:`Delete`,children:[m.isPending?o(b,{className:`h-3 w-3 animate-spin`}):o(s,{className:`h-3 w-3`}),`Delete`]})]})})]})}function me({addonId:e}={}){let r=te({}),i=oe(),s=n(()=>ue(r.data).filter(t=>e===void 0||t.addonId===e),[r.data,e]),[c,l]=a(!1),[u,d]=a(null),p=n(()=>{let t=new Map;for(let n of se(i.data))if(!(e!==void 0&&n.addonId!==e))for(let e of n.kinds)t.set(`${n.addonId}::${e.kind}`,{addonId:n.addonId,kind:e.kind,label:e.label});for(let e of s)[...t.values()].some(t=>t.kind===e.kind)||t.set(`::${e.kind}`,{kind:e.kind,label:J(e.kind)});return[...t.values()]},[s,i.data,e]);return t(`div`,{className:`space-y-3`,children:[o(`div`,{className:`flex items-center justify-end`,children:t(f,{variant:`primary`,size:`sm`,onClick:()=>l(!0),disabled:p.length===0,title:p.length===0?`No broker providers available`:void 0,children:[o(D,{className:`h-3.5 w-3.5`}),` Add broker`]})}),o(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full min-w-[36rem] border-collapse`,children:[o(`thead`,{children:t(`tr`,{className:`border-b border-border bg-background/50`,children:[o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Name`}),o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Kind`}),o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Status`}),o(`th`,{className:`px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Actions`})]})}),t(`tbody`,{children:[r.isLoading&&o(`tr`,{children:t(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[o(b,{className:`inline h-4 w-4 animate-spin`}),` Loading brokers…`]})}),r.isError&&o(`tr`,{children:t(`td`,{colSpan:4,className:`px-3 py-4 text-center text-xs text-danger`,children:[`Failed to load brokers:`,` `,r.error instanceof Error?r.error.message:`Unknown error`]})}),!r.isLoading&&!r.isError&&s.length===0&&o(`tr`,{children:o(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`No brokers registered yet. Add one to publish device events for downstream automations.`})}),s.map(e=>o(pe,{broker:e,onEdit:d},e.id))]})]})}),c&&o(de,{kinds:p,onClose:()=>l(!1),onDone:()=>l(!1)}),u&&o(fe,{broker:u,onClose:()=>d(null),onDone:()=>d(null)})]})}function he(e){if(typeof e==`string`)return e;if(typeof e==`object`&&e){let t=e.name;if(typeof t==`string`)return t}return null}function Z(e){let t=e,n=t?.manifest;if(n?.id===void 0)return null;let r=(n.capabilities??[]).map(he).filter(e=>e!==null);return{addonId:n.id,displayName:n.packageDisplayName??n.name??n.id,capNames:r,processState:t?.process?.state??null}}function ge(e,t){return Object.entries(e).filter(([,e])=>e===t).map(([e])=>e)}function _e(e,t){return t.find(t=>e.capNames.includes(t))??null}function Q(e){switch(e){case`running`:return{state:`ok`,label:`running`};case`crashed`:case`failed`:return{state:`error`,label:e};case`stopped`:case`disabled`:return{state:`off`,label:`stopped`};default:return{state:`unknown`,label:e??`unknown`}}}e();var $=1e4,ve=[{kind:`device-export`,label:`Device export`,icon:re,installLabel:`Add export`},{kind:`email`,label:`Email`,icon:c,installLabel:`Add email provider`},{kind:`broker`,label:`Message brokers`,icon:O,installLabel:`Add broker addon`}];function ye(){let e=A(void 0,{refetchInterval:$}),i=I();return o(z,{icon:_,title:`Connectivity`,subtitle:`External systems this hub talks to — device exporters, email relays and message brokers.`,groups:n(()=>{let n=(e.data??[]).map(Z).filter(e=>e!==null);return ve.map(e=>{let a=ge(N,e.kind),s=n.flatMap(n=>{let s=_e(n,a);if(s===null)return[];let c=Q(n.processState);return[{id:n.addonId,name:n.displayName,fallbackIcon:e.icon,state:c.state,stateLabel:c.label,render:()=>o(B,{addonId:n.addonId,displayName:n.displayName,capName:s,isActive:n.processState===`running`,badges:t(r,{children:[o(xe,{processState:n.processState}),o(Se,{kind:e.kind,addonId:n.addonId})]}),lead:e.kind===`device-export`?o(ae,{addonId:n.addonId}):void 0,panels:be(e.kind,n.addonId,e=>i(`/devices/${e}`))})}]});return{id:e.kind,label:e.label,entries:s,install:{capability:a[0]??e.kind,label:e.installLabel}}})},[e.data,i]),isLoading:e.isLoading,emptyTitle:`No external systems installed`,emptyDescription:`Install an export, email or broker addon to connect this hub to another system.`,legacyGroupParam:`tab`})}function be(e,t,n){return e===`device-export`?[{id:`devices`,title:`Devices`,icon:j,placement:`end`,content:o(m,{addonId:t,onOpenDevice:n,showSetup:!1})}]:e===`broker`?[{id:`connections`,title:`Connections`,icon:O,content:o(me,{addonId:t})}]:[]}function xe({processState:e}){let{state:t,label:n}=Q(e);return o(w,{variant:t===`ok`?`success`:t===`error`?`danger`:`default`,className:`${R} capitalize`,children:n})}function Se({kind:e,addonId:t}){return e===`broker`?o(Ce,{addonId:t}):e===`device-export`?o(we,{addonId:t}):null}function Ce({addonId:e}){let{data:t}=S({addonId:e},{refetchInterval:$,retry:!1}),n=M.safeParse(t);if(!n.success)return null;let{brokerCount:r,connectedCount:i}=n.data;return o(w,{variant:`info`,className:R,children:`${r} connection${r===1?``:`s`}${i>0?` · ${i} connected`:``}`})}function we({addonId:e}){let{data:t}=d({addonId:e},{refetchInterval:$,retry:!1}),n=P.safeParse(t);if(!n.success)return null;let{linkState:r,exposedDeviceCount:i}=n.data;return o(w,{variant:r===`linked`?`success`:r===`error`?`danger`:`default`,className:R,children:`${r} · ${i} exposed`})}export{ye as IntegrationsPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{_t as l,at as u,gt as d,ht as f}from"./player-overlays-D9aoM64J.js";import{Bi as p,Cd as m,J as h,M as g,Mu as ee,Od as _,Td as v,Ud as y,Y as te,Z as b,Za as ne,Zi as x,ca as S,eo as C,gu as re,kd as w,kf as T,lr as ie,md as E,no as D,r as O}from"./src-B-IRCQFw.js";import{t as k}from"./useTranslation-Bc5yH9V9.js";import{$ as ae,K as A,Z as j}from"./index-D7yeH_53.js";import{t as M}from"./AdminPage-BSFohA3i.js";import"./useEventInvalidation-BTxjd_Y8.js";import{t as oe}from"./device-integration-icon-JFsHsv7_.js";import{n as N,r as P,t as F}from"./ScanNetworkModal-C4IaFGug.js";t();function I(e=!0){c(()=>{if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=t}},[e])}t();function L(e,t){let[n,r]=o(!1);return c(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}t();function R({providerId:e,onImport:t,onSkip:r}){let{t:i}=k(),[a,u]=o(new Set),d=x(),f=d.data,p=d.isPending||!d.data&&!d.isError;c(()=>{e&&(d.isPending||d.data||d.mutate({addonId:e}))},[e,d]);function m(e){u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(p)return n(`div`,{className:`flex flex-col items-center py-12`,children:[s(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),s(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:i(`integrations.searchingDevices`)})]});let h=f??[];return n(`div`,{className:`space-y-4`,children:[s(`p`,{className:`text-xs text-foreground-subtle`,children:h.length>0?i(`integrations.foundDevices`,{count:h.length}):i(`integrations.noDevicesFound`)}),h.length>0&&s(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:h.map(e=>{let t=e.stableId,r=e.suggestedName??t,o=a.has(t),c=e.alreadyOnboarded===!0;return n(`button`,{onClick:()=>{c||m(t)},disabled:c,title:c?i(`integrations.alreadyAddedHint`,{defaultValue:`Already added as "{{name}}" — re-adding would overwrite its settings.`,name:e.onboardedName??r}):void 0,className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${c?`border-border bg-surface opacity-60 cursor-not-allowed`:o?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[s(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${o&&!c?`border-primary bg-primary`:`border-border`}`,children:o&&!c&&s(T,{className:`h-3 w-3 text-primary-foreground`})}),s(l,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),s(`span`,{className:`text-xs font-medium text-foreground truncate`,children:r}),c&&s(`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:i(`integrations.alreadyAdded`,{defaultValue:`Already added`})})]},t)})}),n(`div`,{className:`flex items-center justify-between pt-2`,children:[s(`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:i(`integrations.skip`)}),h.length>0&&n(`button`,{onClick:()=>t(Array.from(a)),disabled:a.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:[i(`integrations.importSelected`),` (`,a.size,`)`]})]})]})}function z({onSelect:e,onClose:t,pendingAddonId:r=null}){let{t:i}=k(),a=j(),{data:o,isLoading:c}=C();if(c)return s(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-14 rounded-lg bg-surface animate-pulse`},e))});let l=r!==null;return n(`div`,{className:`space-y-2`,children:[(o??[]).map(o=>{let c=o.instanceMode===`unique`&&o.existingInstances.length>0,u=r===o.addonId,d=l;return n(`button`,{disabled:d,onClick:()=>{if(!d)if(c){let e=o.existingInstances[0].id;t(),a(`/integrations/${e}`)}else e(o.addonId,o.instanceMode,o.discoveryMode,o.name,o.kind,o.brokerKind,o.mode,o.canTest)},className:`flex w-full items-center gap-3 rounded-lg border border-border bg-surface p-3 text-left hover:border-foreground-subtle/30 transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[o.iconUrl?s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`img`,{src:o.iconUrl,alt:``,className:`h-5 w-5`})}):s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`span`,{className:`text-sm`,style:{color:o.color},children:`◉`})}),n(`div`,{className:`flex-1 min-w-0`,children:[s(`p`,{className:`text-xs font-semibold text-foreground`,children:o.name}),o.description&&s(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 truncate`,children:o.description})]}),u?s(y,{className:`h-4 w-4 animate-spin text-primary flex-shrink-0`}):c?n(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[s(E,{className:`h-3 w-3`}),i(`integrations.manage`)]}):s(f,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},o.addonId)}),(o??[]).length===0&&s(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:i(`integrations.noProviders`)})]})}t();function se(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 B=2e4;function V({open:e,onClose:t}){let{t:l}=k(),u=j(),d=a(),[f,m]=o(`picker`),[h,g]=o(null),[_,v]=o(null),[te,b]=o(`manual`),[S,C]=o(null),[re,w]=o(``),[T,E]=o(null),[D,O]=o(null),[ae,A]=o(!1),{data:M}=ie({addonId:h??``,nodeId:`hub`},{enabled:h!=null}),oe=r(()=>M?se(M):null,[M]),F=ne({onSuccess:()=>d.invalidateQueries({queryKey:[[`integrations`]]})}),V=x(),H=V.data;c(()=>{f!==`discovery`||!_||!h||V.isPending||V.data||V.mutate({addonId:h})},[f,_,h,V]);let ce=p({onSuccess:()=>d.invalidateQueries({queryKey:[[`deviceManager`]]})});function le(e,t,n,r,i,a,o,s){if(!F.isPending){if(g(e),A(s),b(n),w(r),O(null),o===`broker`){if(!a){O(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}C(a),m(`broker`);return}if(o===`account`){m(`config`);return}U(e,r)}}async function U(e,n){try{let r=await F.mutateAsync({addonId:e,name:n,settings:{}});t(),J(),u(`/integrations/${r.id}?add=1`)}catch{}}async function W(e){if(h)try{let t=await F.mutateAsync({addonId:h,name:e.name,settings:e.config,secretKeys:[...e.secretKeys]});v(t.id),te===`auto`||te===`both`?m(`discovery`):q(t.id)}catch{}}async function G(e){if(h)try{let t=await F.mutateAsync({addonId:h,name:re,settings:{brokerId:e}});E(t.id),v(t.id),q(t.id)}catch{}}async function K(e){if(h){for(let t of e){let e=H?.find(e=>e.stableId===t);e&&await ce.mutateAsync({addonId:h,candidate:e,...T===null?{}:{integrationId:T}})}q()}}function q(e){let n=e??_??h;t(),J(),n&&u(`/integrations/${n}`)}function J(){m(`picker`),g(null),v(null),b(`manual`),C(null),w(``),E(null),O(null),A(!1)}function Y(){t(),J()}I(e);let X=F.isPending,Z=L(X,B);if(!e)return null;let ue={picker:l(`integrations.newIntegration`),config:l(`integrations.configureIntegration`),discovery:l(`integrations.importDevices`),broker:l(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},Q=X?h:null,$=F.error,de=X&&!Z;return n(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:de?void 0:Y}),n(`div`,{className:`relative z-10 w-full max-w-lg max-h-[calc(85dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[n(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:ue[f]}),s(`button`,{onClick:Y,disabled:de,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:s(ee,{className:`h-4 w-4`})})]}),n(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[$&&!X&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:$ instanceof Error?$.message:String($)}),f===`picker`&&n(i,{children:[D&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:D}),s(z,{onSelect:le,onClose:Y,pendingAddonId:Q})]}),f===`config`&&h&&s(N,{addonId:h,configSchema:oe??null,canTest:ae,onSave:W,onBack:()=>m(`picker`)}),f===`broker`&&S&&s(P,{kind:S,onResolved:e=>{G(e)},onBack:()=>m(`picker`)}),f===`discovery`&&_&&s(R,{providerId:_,onImport:K,onSkip:q})]}),X&&n(`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:[s(y,{className:`h-6 w-6 animate-spin text-primary`}),s(`p`,{className:`text-xs font-medium text-foreground`,children:l(`integrations.creating`,{defaultValue:`Creating integration…`})}),!Z&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:l(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),Z&&n(i,{children:[s(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:l(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),s(`button`,{onClick:Y,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:l(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})]})}function H({integration:e,expanded:t,onToggleExpand:r}){return n(`div`,{className:`flex items-center gap-2.5`,children:[s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e.addonId)},"aria-label":t?`Collapse`:`Expand`,"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:s(t?d:f,{className:`h-3.5 w-3.5`})}),s(A,{type:e.addonId,size:`sm`}),n(`div`,{className:`flex min-w-0 flex-col`,children:[s(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),s(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function ce(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>s(H,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:`Devices`,headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>`${e.deviceCount} device${e.deviceCount===1?``:`s`}`},{key:`status`,header:`Status`,headerClassName:`w-[15%]`,cell:e=>s(g,{status:e.status})}]}t();function le(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var U=`expand`;function W(){let{t}=k(),a=j(),c=u(),[l]=ae(),[d,f]=o(!1),p=e(()=>f(!0),[]),g=e(()=>f(!1),[]),[ee,y]=o(!1),ne=e(()=>y(!0),[]),x=e(()=>y(!1),[]);O([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),O([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:C,isLoading:T,refetch:ie}=D(void 0),{data:E,isLoading:A,refetch:N}=S({projection:`slim`}),P=r(()=>E??[],[E]),I=r(()=>C??[],[C]),L=r(()=>{let e=new Map;for(let t of P)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[P]),R=r(()=>te(C),[C]),z=r(()=>{let e=new Map;for(let t of b(P)){let n=R(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[P,R]),se=r(()=>I.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:le(e),deviceCount:z.get(e.id)??0})),[I,z]),B=l.get(U),H=e(e=>{let t=new URLSearchParams(window.location.search);t.get(U)===e?t.delete(U):t.set(U,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`))},[]),W=e(e=>a(`/integrations/${e.id}`),[a]),G=e(e=>L.get(e)??null,[L]),K=e(e=>a(`/devices/${String(e)}`),[a]),q=e(e=>s(h,{context:`integration-detail`,devices:P,trpc:c.trpcClient,integrationOf:R,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:oe,resolveParent:G,onNavigate:K}),[P,c.trpcClient,R,G,K]),J=e(e=>B===e.addonId,[B]),Y=r(()=>ce({isExpanded:J,onToggleExpand:H}),[J,H]),X=e(e=>`${e.name} ${e.addonId}`,[]),Z=e(e=>e.addonId,[]),ue=e(()=>{ie(),N()},[ie,N]),Q=T||A,$=I.length>0;return n(M,{icon:_,title:t(`nav.integrations`,`Integrations`),actions:n(i,{children:[s(`button`,{onClick:ue,disabled:Q,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:`Refresh`,children:s(m,{className:re(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),n(`button`,{onClick:ne,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:`Scan the local network for devices`,children:[s(v,{className:`h-3.5 w-3.5`}),`Scan network`]}),n(`button`,{onClick:p,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:[s(w,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[Q&&s(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!$&&n(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[s(`p`,{className:`text-sm`,children:`No integrations configured.`}),s(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!Q&&$&&s(h,{mode:`generic`,items:se,getKey:Z,getSearchText:X,columns:Y,onRowClick:W,isExpanded:J,renderExpanded:q,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),s(V,{open:d,onClose:g}),s(F,{open:ee,onClose:x})]})}export{W as IntegrationsPage};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{Q as e,S as t,W as n,b as r,o as i,q as a,x as o,z as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{_t as c,gt as l,ht as u,st as d,vt as f}from"./player-overlays-D9aoM64J.js";import{$t as p,$u as m,Af as h,Bf as g,Cd as _,Cf as v,Da as y,Dt as b,Ea as x,Ff as S,If as C,It as w,Ju as T,Kd as E,Kn as D,Ku as O,Lu as k,Ma as ee,Md as A,Mu as j,Nf as M,Ot as N,Pu as P,Qf as F,R as te,Rf as I,Ri as ne,Ru as L,Sf as R,Ta as re,Td as z,Uf as B,Vd as V,Vu as H,Wf as U,Xd as ie,Xf as W,Xu as ae,Yu as oe,Zd as se,Zf as ce,Zu as le,_d as ue,_u as de,ba as fe,bd as pe,ca as me,cd as he,da as ge,df as _e,ed as ve,fa as ye,fd as be,id as xe,if as Se,jd as Ce,ju as we,kd as G,od as Te,of as Ee,pa as De,pf as Oe,rd as ke,sf as Ae,ua as je,uf as Me,va as Ne,vf as Pe,wa as Fe,xa as Ie,xd as Le,ya as Re,zd as K,zi as ze}from"./src-B-IRCQFw.js";import{t as Be}from"./boxes-CG60qRZo.js";import{t as Ve}from"./user-round-bqX4ogd_.js";import{$n as q,$t as He,Qn as J,er as Y}from"./client-DX0rAC3X.js";import{t as Ue}from"./useTranslation-Bc5yH9V9.js";import{$ as We,Y as X}from"./index-D7yeH_53.js";import{t as Ge}from"./AdminPage-BSFohA3i.js";var Ke=f(`circle-arrow-up`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m16 12-4-4-4 4`,key:`177agl`}],[`path`,{d:`M12 16V8`,key:`1sbj14`}]]);e();var qe={camera:c,hub:pe,container:Be,light:E,siren:he,switch:ae,sensor:F,thermostat:le,climate:ce,button:v,"event-emitter":we,update:Ke,notifier:I,script:ue,automation:P,lock:V,cover:C,valve:_e,humidifier:Me,"water-heater":Se,fan:Ae,"media-player":ke,"alarm-panel":be,control:Te,presence:Ve,weather:Pe,vacuum:S,"lawn-mower":oe,image:ie,smoke:W};function Z({type:e,className:t}){return o(qe[e]??v,{"aria-hidden":`true`,className:t??`h-3.5 w-3.5 shrink-0 text-foreground-subtle`})}function Je({online:e,deviceName:t}){return o(`span`,{className:e?`inline-block h-1.5 w-1.5 shrink-0 rounded-full bg-emerald-500`:`inline-block h-1.5 w-1.5 shrink-0 rounded-full border border-foreground-subtle`,role:`img`,"aria-label":`${t}: ${e?`online`:`offline`}`,title:e?`online`:`offline`})}function Ye({name:e,description:n,busy:r,onSave:i}){let[c,l]=a(n??``);return s(()=>{l(n??``)},[n]),t(`div`,{className:`border-t border-border px-3 py-2`,children:[o(`label`,{htmlFor:`location-description-${e}`,className:`block text-[10px] font-medium uppercase tracking-wide text-foreground-subtle`,children:`What is there`}),o(`textarea`,{id:`location-description-${e}`,value:c,onChange:e=>l(e.target.value),onBlur:()=>{let e=c.trim();e!==(n??``)&&i(e.length===0?null:e)},disabled:r,rows:2,maxLength:400,placeholder:`Surfaces, boundaries, what is normally parked or stored here.`,className:`mt-1 w-full resize-y rounded border border-border bg-background px-1.5 py-1 text-[11px] text-foreground placeholder:text-foreground-subtle disabled:opacity-50`}),o(`p`,{className:`mt-0.5 text-[10px] text-foreground-subtle`,children:`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 Xe(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0||n.description.length===0?null:n.description}var Q=` none`;function Ze({name:e,zones:n,zoneKey:r,busy:i,onChange:a}){return n.length===0?null:t(`div`,{className:`flex items-center gap-2 border-t border-border px-3 py-1.5`,children:[o(`label`,{htmlFor:`location-zone-${e}`,className:`text-[10px] font-medium uppercase tracking-wide text-foreground-subtle`,children:`Zone`}),t(`select`,{id:`location-zone-${e}`,value:r??Q,disabled:i,onChange:e=>{let t=e.target.value;if(t===Q){a(null);return}let r=n.find(e=>e.zoneKey===t);r!==void 0&&a(r.label)},className:`min-w-0 flex-1 rounded border border-border bg-background px-1.5 py-0.5 text-[11px] text-foreground disabled:opacity-50`,children:[o(`option`,{value:Q,children:`— none —`}),n.map(e=>o(`option`,{value:e.zoneKey,children:e.label},e.zoneKey))]})]})}function Qe(e,t){return e.find(e=>e.locationKeys.includes(t))?.zoneKey??null}var $e={"map-pin":{icon:K,label:`Pin`},house:{icon:se,label:`Home`},"door-open":{icon:Oe,label:`Entrance`},sofa:{icon:xe,label:`Living room`},utensils:{icon:H,label:`Kitchen`},"bed-double":{icon:g,label:`Bedroom`},bath:{icon:B,label:`Bathroom`},briefcase:{icon:M,label:`Office`},car:{icon:h,label:`Garage`},"circle-parking":{icon:R,label:`Parking`},route:{icon:Le,label:`Street`},trees:{icon:T,label:`Garden`},umbrella:{icon:O,label:`Terrace`},"waves-ladder":{icon:k,label:`Pool`},fence:{icon:Ee,label:`Gate`},package:{icon:A,label:`Storage`},warehouse:{icon:L,label:`Warehouse`},store:{icon:ve,label:`Shop`},sun:{icon:m,label:`Outdoor`},radar:{icon:z,label:`Perimeter`}},et=J.map(e=>({id:e,...$e[e]}));function tt(e){return $e[Y(e)].icon}var nt=new Map(et.map(e=>[e.id,[e.label]])),rt=new Map(et.map(e=>[e.id,e.label])),it=new Set(J);function at(e){return it.has(e)?tt(e):void 0}function ot({name:e,icon:t,busy:n,onPick:r}){return o(de,{value:t,onPick:e=>r(e===null?null:Y(e)),resolveGlyph:at,fallbackGlyph:K,clearGlyph:U,labelFor:e=>rt.get(e),labels:{trigger:`Change the icon of ${e}`,panel:`Icon for ${e}`,close:`Close icon picker`,searchPlaceholder:`Search icons`,clear:`No icon`,noMatches:`No icon matches that`,groups:{device:`Devices`,lighting:`Lights and climate`,sensing:`Sensors and weather`,place:`Rooms and places`,life:`Vehicles, animals and people`}},only:J,extraWords:nt,disabled:n})}function st(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0?null:Y(n.icon)}function $(e){if(e==null)return null;let t=e.trim();return t.length===0?null:t.toLowerCase()}function ct(e,t){let n=$(t);return n===null?[]:e.filter(e=>$(e.location)===n)}function lt(e,t){let n=ct(e,t),r=new Set(n.map(e=>e.id));return n.filter(e=>e.parentDeviceId===null||!r.has(e.parentDeviceId))}function ut(e,t){let n=$(e.location);return n===null||new Set(t.map(e=>$(e))).has(n)?null:e.location?.trim()??null}function dt(e,t){let n=$(e.location);return n!==null&&t.has(n)}function ft(e,t){let n=new Set(t.map(e=>$(e))),r=new Set(e.filter(e=>dt(e,n)).map(e=>e.id));return e.filter(e=>!(dt(e,n)||e.parentDeviceId!==null&&r.has(e.parentDeviceId)))}function pt(e,t){return ft(e,t).filter(e=>e.parentDeviceId===null)}function mt(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 ht(e,t){return mt(e,t).length}function gt(e,t){return e.filter(e=>!e.isCamera&&e.parentDeviceId===t)}function _t(e,t){return t.map(t=>({name:t,members:lt(e,t)}))}function vt(e){return`${e.kind}:${String(e.device.id)}`}function yt(e,t,n){return e.flatMap(e=>{let r=gt(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}))]})}e();function bt({name:e,members:i,devices:s,busy:c,icon:l,description:u,onRename:f,onDelete:p,onRebuildLinks:m,onPickIcon:h,onSaveDescription:g,zones:v,zoneKey:y,onChangeZone:x}){let{t:S}=Ue(),[C,T]=a(!1),[E,D]=a(e),O=b(i,n(()=>({searchText:e=>[e.name,...gt(s,e.id).map(e=>e.name)],facetValue:e=>e.type}),[s])),[k,ee]=a(()=>new Set),A=e=>ee(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),M=n(()=>yt(O.rows,s,k),[O.rows,s,k]),P=[{key:`name`,header:S(`locations.columns.device`),notSortableReason:S(`locations.columns.noSort`),render:e=>e.kind===`member`?o(xt,{row:e,onToggle:()=>A(e.device.id)}):o(St,{row:e})},{key:`type`,header:S(`locations.columns.type`),notSortableReason:S(`locations.columns.noSort`),render:e=>o(`span`,{className:`text-[11px] text-foreground-muted`,children:e.device.type})},{key:`status`,header:S(`locations.columns.status`),notSortableReason:S(`locations.columns.noSort`),render:e=>t(`span`,{className:`flex items-center gap-1.5`,children:[o(Je,{online:e.device.online,deviceName:e.device.name}),o(`span`,{className:`text-[11px] text-foreground-muted`,children:e.device.online?`online`:`offline`})]})}],F=()=>{D(e),T(!1)},I=async()=>{let t=E.trim();if(t.length===0||t===e){F();return}await f(t),T(!1)};return t(`section`,{className:`min-w-0 rounded-md border border-border bg-surface`,children:[t(`header`,{className:`flex items-center gap-1.5 border-b border-border px-3 py-1.5`,children:[o(ot,{name:e,icon:l,busy:c,onPick:h}),C?t(r,{children:[o(`input`,{value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`&&I(),e.key===`Escape`&&F()},"aria-label":`Rename ${e}`,className:`min-w-0 flex-1 rounded border border-border bg-background px-1.5 py-0.5 text-sm font-semibold text-foreground`,autoFocus:!0}),o(`button`,{type:`button`,onClick:()=>void I(),className:`text-[11px] text-foreground-subtle hover:text-foreground`,children:`Save`}),o(`button`,{type:`button`,onClick:F,"aria-label":`Cancel rename`,className:`p-0.5 text-foreground-subtle hover:text-foreground`,children:o(j,{className:`h-3.5 w-3.5`})})]}):t(r,{children:[o(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:e}),o(te,{items:[{id:`rename`,label:`Rename`,icon:Ce,disabled:c,onClick:()=>{D(e),T(!0)}},{id:`rebuild-links`,label:`Rebuild linked devices`,icon:_,separatorBefore:!0,disabled:c,onClick:()=>void m()},{id:`delete`,label:`Delete`,icon:d,danger:!0,separatorBefore:!0,disabled:c,onClick:()=>void p()}],title:`Actions for ${e}`,triggerClassName:`p-1`})]})]}),o(Ze,{name:e,zones:v,zoneKey:y,busy:c,onChange:x}),o(Ye,{name:e,description:u,busy:c,onSave:g}),i.length>0&&o(`div`,{className:`border-b border-border px-3 py-1.5`,children:o(N,{state:O.state,facets:O.facets,labels:{searchPlaceholder:S(`locations.filter.searchPlaceholder`),searchLabel:S(`locations.room.searchLabel`,{room:e}),facetsLabel:S(`locations.filter.typesLabel`),clearLabel:S(`locations.filter.clear`)},onSearch:O.setSearch,onToggleFacet:O.toggleFacet,onClear:O.clear})}),i.length===0?o(`p`,{className:`px-3 py-3 text-[11px] text-foreground-subtle`,children:`Nothing here yet — assign a device from the table below.`}):o(w,{columns:P,rows:M,rowKey:vt,bordered:!1,minWidthPx:360,mobileMode:`scroll`,emptyMessage:S(`locations.filter.noMatch`)})]})}function xt({row:e,onToggle:n}){let{device:r,accessories:i,open:a}=e,s=a?l:u;return t(`span`,{className:`flex items-center gap-1.5`,children:[i.length>0?t(`button`,{type:`button`,onClick:n,"aria-expanded":a,"aria-label":`${a?`Collapse`:`Expand`} ${String(i.length)} companion device(s) of ${r.name}`,className:`flex shrink-0 items-center gap-0.5 rounded p-0.5 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:[o(s,{className:`h-3 w-3`}),o(`span`,{className:`text-[10px] tabular-nums`,children:i.length})]}):o(`span`,{"aria-hidden":`true`,className:`w-[1.35rem] shrink-0`}),o(Z,{type:r.type}),o(X,{to:`/devices/${String(r.id)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:r.name})]})}function St({row:e}){let{device:n}=e;return t(`span`,{className:`flex items-center gap-1.5 pl-6`,children:[o(`span`,{"aria-hidden":`true`,className:`text-[10px] text-foreground-subtle`,children:`└`}),o(Z,{type:n.type,className:`h-3 w-3 shrink-0 text-foreground-subtle`}),o(X,{to:`/devices/${String(n.id)}`,className:`min-w-0 truncate text-[11px] text-foreground-muted hover:underline`,children:n.name})]})}e();function Ct({zones:e,busy:n,onCreate:r,onRename:i,onDelete:s,onPickIcon:c}){let[l,u]=a(!1),[f,p]=a(``),[m,h]=a(null),[g,_]=a(``),v=async()=>{let e=f.trim();e.length!==0&&(await r(e),p(``),u(!1))},y=async e=>{let t=g.trim();h(null),!(t.length===0||t===e)&&await i(e,t)};return t(`section`,{className:`rounded-md border border-border bg-surface`,children:[t(`header`,{className:`flex items-center gap-2 border-b border-border px-3 py-1.5`,children:[o(`h2`,{className:`flex-1 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Zones`}),l?null:t(`button`,{type:`button`,onClick:()=>u(!0),disabled:n,className:`flex items-center gap-1 text-[11px] text-foreground-muted hover:text-foreground disabled:opacity-50`,children:[o(G,{className:`h-3 w-3`}),` New zone`]})]}),l&&t(`div`,{className:`flex items-center gap-1.5 border-b border-border px-3 py-1.5`,children:[o(`input`,{value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&v(),e.key===`Escape`&&(p(``),u(!1))},placeholder:`Zona notte`,"aria-label":`New zone name`,autoFocus:!0,className:`min-w-0 flex-1 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`}),o(`button`,{type:`button`,onClick:()=>void v(),className:`text-[11px] text-foreground-subtle hover:text-foreground`,children:`Add`}),o(`button`,{type:`button`,onClick:()=>{p(``),u(!1)},"aria-label":`Cancel new zone`,className:`p-0.5 text-foreground-subtle hover:text-foreground`,children:o(j,{className:`h-3.5 w-3.5`})})]}),e.length===0?o(`p`,{className:`px-3 py-2 text-[11px] text-foreground-subtle`,children:`No zones yet. A zone groups rooms — “Zona notte” for the bedrooms — and shows up before them in the app’s camera filter.`}):o(`ul`,{className:`py-0.5`,children:e.map(e=>t(`li`,{className:`flex items-center gap-1.5 px-3 py-1`,children:[o(ot,{name:e.label,icon:e.icon,busy:n,onPick:t=>c(e.label,t)}),m===e.label?o(`input`,{value:g,onChange:e=>_(e.target.value),onKeyDown:t=>{t.key===`Enter`&&y(e.label),t.key===`Escape`&&h(null)},onBlur:()=>void y(e.label),"aria-label":`Rename ${e.label}`,autoFocus:!0,className:`min-w-0 flex-1 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`}):o(`button`,{type:`button`,onClick:()=>{_(e.label),h(e.label)},disabled:n,className:`min-w-0 flex-1 truncate text-left text-xs text-foreground hover:underline disabled:opacity-50`,children:e.label}),o(`span`,{className:`shrink-0 text-[10px] tabular-nums text-foreground-subtle`,children:e.locationKeys.length===0?`empty`:`${String(e.locationKeys.length)} rooms`}),o(`button`,{type:`button`,onClick:()=>void s(e.label),disabled:n,"aria-label":`Delete ${e.label}`,title:`Delete the zone — the rooms in it are kept`,className:`shrink-0 p-0.5 text-foreground-subtle hover:text-danger disabled:opacity-50`,children:o(d,{className:`h-3.5 w-3.5`})})]},e.zoneKey))})]})}e();function wt({busy:e,onCreate:n}){let[r,i]=a(!1),[s,c]=a(``),l=()=>{c(``),i(!1)},u=async()=>{let e=s.trim();e.length!==0&&(await n(e),l())};return r?t(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),u()},children:[o(`input`,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Escape`&&l()},placeholder:`Ingresso, Salone, Cucina…`,"aria-label":`New location name`,className:`min-w-[16rem] flex-1 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,autoFocus:!0}),t(`button`,{type:`submit`,disabled:s.trim().length===0||e,className:`inline-flex items-center gap-1 rounded border border-border bg-surface px-2 py-1.5 text-xs font-medium text-foreground hover:bg-surface-hover disabled:opacity-50`,children:[o(G,{className:`h-3.5 w-3.5`}),`Add`]}),o(`button`,{type:`button`,onClick:l,"aria-label":`Cancel new location`,className:`p-1 text-foreground-subtle hover:text-foreground`,children:o(j,{className:`h-3.5 w-3.5`})})]}):t(`button`,{type:`button`,onClick:()=>i(!0),className:`inline-flex w-fit items-center gap-1 rounded border border-border bg-surface px-2 py-1.5 text-xs font-medium text-foreground hover:bg-surface-hover`,children:[o(G,{className:`h-3.5 w-3.5`}),`New location`]})}e();var Tt={searchText:e=>[e.name],facetValue:e=>e.type};function Et({rows:e,fleet:r,locations:i,busy:s,emptyMessage:c,onAssign:l}){let{t:u}=Ue(),[d,f]=a([]),[m,h]=a(``),g=b(e,Tt),_=g.rows,v=n(()=>_.map(e=>e.id),[_]),y=n(()=>d.filter(e=>v.includes(e)),[d,v]),x=_.length>0&&y.length===_.length,S=n(()=>{let t=new Map;for(let n of e)t.set(n.id,ht(r,n.id));return t},[e,r]),C=y.reduce((e,t)=>e+(S.get(t)??0),0),T=e=>f(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),E=()=>f(x?[]:v);return t(`section`,{className:`space-y-2`,children:[t(`header`,{className:`flex flex-wrap items-baseline gap-2`,children:[o(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Not in a room`}),o(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Top-level devices only — accessories move with their parent.`})]}),e.length>0&&o(N,{state:g.state,facets:g.facets,labels:{searchPlaceholder:u(`locations.filter.searchPlaceholder`),searchLabel:u(`locations.unassigned.searchLabel`),facetsLabel:u(`locations.filter.typesLabel`),clearLabel:u(`locations.filter.clear`)},onSearch:g.setSearch,onToggleFacet:g.toggleFacet,onClear:g.clear}),y.length>0&&t(`div`,{role:`group`,"aria-label":`Bulk assignment`,className:`flex flex-wrap items-center gap-2 rounded border border-primary/40 bg-primary/5 px-2 py-1.5`,children:[t(`span`,{className:`text-[11px] text-foreground`,children:[y.length,` selected`,C>0&&` · ${String(C)} accessories in tow`]}),t(`select`,{"aria-label":`Assign selected devices to`,value:m,onChange:e=>h(e.target.value),className:`rounded border border-border bg-background px-1.5 py-0.5 text-[11px] text-foreground`,children:[o(`option`,{value:``,children:`Assign to…`}),i.map(e=>o(`option`,{value:e,children:e},e))]}),o(`button`,{type:`button`,onClick:()=>{m.length===0||y.length===0||(l(y,m),f([]),h(``))},disabled:s||m.length===0,className:`rounded border border-border bg-surface px-2 py-0.5 text-[11px] font-medium text-foreground hover:bg-surface-hover disabled:opacity-50`,children:`Assign`}),o(`button`,{type:`button`,onClick:()=>f([]),className:`text-[11px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),o(w,{columns:[{key:`select`,width:`w-8`,headerRender:()=>o(p,{checked:x,onChange:E,"aria-label":x?`Clear selection`:`Select all unassigned devices`}),render:e=>o(p,{checked:y.includes(e.id),onChange:()=>T(e.id),"aria-label":`Select ${e.name}`})},{key:`name`,header:`Device`,sortValue:e=>e.name.toLowerCase(),render:e=>{let n=ut(e,i);return t(`span`,{className:`flex items-center gap-1.5`,children:[o(Z,{type:e.type}),o(X,{to:`/devices/${String(e.id)}`,className:`truncate text-xs text-foreground hover:underline`,children:e.name}),n!==null&&t(`span`,{className:`rounded-full border border-warning/40 px-1.5 py-px text-[10px] text-warning`,children:[`unknown room “`,n,`”`]})]})}},{key:`type`,header:`Type`,sortValue:e=>e.type,render:e=>o(`span`,{className:`text-[11px] text-foreground-muted`,children:e.type})},{key:`status`,header:`Status`,sortValue:e=>+!!e.online,render:e=>t(`span`,{className:`flex items-center gap-1.5`,children:[o(Je,{online:e.online,deviceName:e.name}),o(`span`,{className:`text-[11px] text-foreground-muted`,children:e.online?`online`:`offline`})]})},{key:`followers`,header:`Accessories in tow`,align:`right`,sortValue:e=>S.get(e.id)??0,render:e=>o(`span`,{className:`tabular-nums text-[11px] text-foreground-muted`,children:S.get(e.id)??0})},{key:`assign`,header:`Assign to`,align:`right`,notSortableReason:`This column is a control, not a value.`,render:e=>t(`select`,{"aria-label":`Location for ${e.name}`,value:``,disabled:s||i.length===0,onChange:t=>{let n=t.target.value;n.length!==0&&l([e.id],n)},className:`max-w-[11rem] rounded border border-border bg-background px-1.5 py-0.5 text-[11px] text-foreground disabled:opacity-50`,children:[o(`option`,{value:``,children:`—`}),i.map(e=>o(`option`,{value:e,children:e},e))]})}],rows:_,rowKey:e=>e.id,minWidthPx:720,mobileMode:`scroll`,emptyMessage:g.active?u(`locations.filter.noMatch`):c})]})}function Dt(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 Ot(e,t){let n=t.map(Dt),r=[];for(let i of t)i.isCamera&&i.location===e&&r.push({deviceId:i.id,name:i.name,ids:He({selfId:i.id,selfLocation:i.location,candidates:n})});return{entries:r}}var kt=`device-manager:linked-devices`;function At(e){return{deviceId:e.deviceId,slotRef:kt,value:{slot:`linked-devices`,deviceIds:[...e.ids]}}}e();function jt(){let e=i(),r=D(),{data:a,isLoading:s}=ye(),{data:c}=ge(),{data:l}=je(),{data:u}=De(),{data:d,isLoading:f}=me({projection:`slim`}),p=()=>{e.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listLocationIcons`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listLocationDescriptions`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listSiteZones`]]})},m=ze({onSuccess:p}),h=Ne({onSuccess:p}),g=Fe({onSuccess:p}),_=fe({onSuccess:p}),v=x({onSuccess:p}),b=re({onSuccess:p}),S=ee({onSuccess:p}),C=Re({onSuccess:p}),w=Ie({onSuccess:p}),T=y({onSuccess:p}),E=ne(),O=n(()=>(d??[]).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})),[d]),k=a??[],A=n(()=>_t(O,k),[O,k]),[j,M]=We(),N=j.get(`room`),P=N!==null&&A.some(e=>e.name===N)?N:A[0]?.name??null,F=A.find(e=>e.name===P)??null,te=e=>{M(t=>{let n=new URLSearchParams(t);return n.set(`room`,e),n},{replace:!0})},I=n(()=>pt(O,k),[O,k]),L=s||f,R=g.isPending||h.isPending||m.isPending||v.isPending,z=async e=>{await m.mutateAsync({name:e})},B=async(e,t)=>{let n=t.trim();n.length===0||n===e||await _.mutateAsync({from:e,to:n})},V=async e=>{let t=Ot(e,O);if(t.entries.length===0){await r({title:`Rebuild linked devices`,message:`No camera is assigned to “${e}”.`,confirmLabel:`OK`});return}if(!await r({title:`Rebuild linked devices`,message:`Replace the linked-device list of every camera in “${e}” with what the room contains?\n\n${t.entries.map(e=>`• ${e.name}: ${String(e.ids.length)} device(s)`).join(`
|
|
2
|
+
`)}\n\nAnything linked by hand that is not in this room is lost.`,confirmLabel:`Rebuild`,variant:`danger`}))return;let n=[];for(let e of t.entries)try{await E.mutateAsync(At(e))}catch(t){n.push(`• ${e.name}: ${t instanceof Error?t.message:String(t)}`)}p(),n.length>0&&await r({title:`Rebuild linked devices`,message:`Not rebuilt:\n\n${n.join(`
|
|
3
|
+
`)}`,confirmLabel:`OK`})},H=async(e,t)=>{await r({title:`Delete location`,message:`Delete the location “${e}”?${t>0?` ${String(t)} device(s) will become unassigned.`:``}`,confirmLabel:`Delete`,variant:`danger`})&&await h.mutateAsync({name:e,cascade:!0})},U=async(e,t)=>{await v.mutateAsync({location:e,icon:t})},ie=async(e,t)=>{await b.mutateAsync({location:e,description:t})},W=u??[],ae=async(e,t)=>{await T.mutateAsync({location:e,zone:t})};return t(Ge,{icon:K,title:`Locations`,subtitle:`Rooms and areas of the site. Assign any device here — storage disks are under Data → Storage.`,children:[o(wt,{busy:m.isPending,onCreate:z}),o(Ct,{zones:W,busy:R,onCreate:e=>S.mutateAsync({name:e}),onRename:(e,t)=>w.mutateAsync({from:e,to:t}),onDelete:e=>C.mutateAsync({name:e}),onPickIcon:(e,t)=>S.mutateAsync({name:e,icon:t})}),L&&o(`p`,{className:`text-xs text-foreground-subtle`,children:`Loading locations and devices…`}),A.length>0&&o(`div`,{role:`tablist`,"aria-label":`Locations`,className:`-mx-1 flex gap-1 overflow-x-auto px-1 pb-1`,children:A.map(e=>{let n=e.name===P,r=tt(st(c,q(e.name)));return t(`button`,{type:`button`,role:`tab`,"aria-selected":n,onClick:()=>te(e.name),className:n?`shrink-0 whitespace-nowrap rounded-full border border-primary bg-primary/10 px-3 py-1 text-xs text-foreground`:`shrink-0 whitespace-nowrap rounded-full border border-border px-3 py-1 text-xs text-foreground-muted hover:bg-surface-hover`,children:[o(r,{className:`mr-1 inline h-3.5 w-3.5 align-text-bottom`}),e.name,` `,o(`span`,{className:`text-foreground-subtle tabular-nums`,children:e.members.length})]},e.name)})}),F!==null&&o(bt,{name:F.name,members:F.members,devices:O,busy:R,icon:st(c,q(F.name)),onPickIcon:e=>U(F.name,e),description:Xe(l,q(F.name)),onSaveDescription:e=>ie(F.name,e),zones:W,zoneKey:Qe(W,q(F.name)),onChangeZone:e=>ae(F.name,e),onRename:e=>B(F.name,e),onDelete:()=>H(F.name,ct(O,F.name).length),onRebuildLinks:()=>V(F.name)},F.name),k.length===0&&!L&&o(`p`,{className:`text-xs text-foreground-subtle`,children:`No locations yet. Add Ingresso, Salone, Cucina…`}),o(Et,{rows:I,fleet:O,locations:k,busy:R,emptyMessage:L?`Loading…`:`Every top-level device has a room.`,onAssign:(e,t)=>{for(let n of e)g.mutate({deviceId:n,location:t})}})]})}export{jt as LocationsPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Q as e,S as t,W as n,q as r,x as i}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{_t as a,vt as o}from"./player-overlays-OREckyXS.js";import{El as s,Hd as c,Of as l,Su as u,Zf as d,br as f,gd as p,vt as m,wl as h,xr as g}from"./src-CEnvJotZ.js";import{t as _}from"./layers-JboEX-t3.js";import{t as v}from"./useTranslation-Bc5yH9V9.js";import{c as y,et as b,s as x}from"./index-Bq3Mrl-l.js";import{t as S}from"./AdminPage-BSFohA3i.js";import{t as C}from"./AdminTabs-Bw0vLcQV.js";import{r as w,t as T}from"./AddonIntegrationBody-DdNzzr-6.js";import{n as E,t as D}from"./addon-display-names-BkwMrExv.js";var O=o(`file-text`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),k=o(`timer-reset`,[[`path`,{d:`M10 2h4`,key:`n1abiw`}],[`path`,{d:`M12 14v-4`,key:`1evpnu`}],[`path`,{d:`M4 13a8 8 0 0 1 8-7 8 8 0 1 1-5.3 14L4 17.6`,key:`1ts96g`}],[`path`,{d:`M9 17H4v5`,key:`8t5av`}]]);e();var A=5e3,j=`log-destination`,M={"winston-logging":`Rotated log files on this node’s disk.`,"console-logging":`stdout / stderr of the node process.`,"loki-logging":`Pushes to a Grafana Loki instance. Off until enabled with a URL.`,"hub-forwarder":`Agent-only — forwards this node’s entries to the hub.`};function N(){let e=g({capName:`log-destination`},{refetchInterval:A}),t=f(void 0,{refetchInterval:A}),r=n(()=>D(t.data??[]),[t.data]),a=n(()=>{let e=new Map;for(let n of t.data??[]){let t=n.description,r=n.id;typeof r==`string`&&typeof t==`string`&&t.length>0&&e.set(r,t)}return e},[t.data]),o=n(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:r.get(e.addonId)??e.addonId,isActive:e.isActive,caption:a.get(e.addonId)??M[e.addonId]??``})),[e.data,r,a]);return i(w,{icon:p,title:`Destinations`,subtitle:`Every registered log destination. Entries are fanned to all enabled destinations at once — enabling one does not disable another.`,groups:[{id:j,label:`Log destinations`,install:{capability:j,label:`Add destination`},entries:o.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:O,...E(e.isActive),render:()=>i(T,{addonId:e.addonId,displayName:e.displayName,capName:j,isActive:e.isActive,badges:e.caption.length>0?i(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.caption}):null})}))}],isLoading:e.isLoading,emptyTitle:`No log destinations registered`,emptyDescription:`This should not happen — the console and rotated-file destinations are builtins. If the list is empty, the node is still booting.`})}e();var P=[12e4,3e5,6e5,18e5],F={"request-census":`Counts every tRPC call by TRANSPORT PLANE — http, ws, mesh — and by procedure, caller, address and user-agent. Subscriptions are counted apart from calls, so a long-lived stream cannot pass for a storm. Arm it, then restart: the deadline is persisted, so the window is still running when clients reconnect.`};function I(){let{t:e}=v(),n=h({},{refetchInterval:5e3}),a=s(),[o,l]=r(null),u=(e,t)=>{l(e),a.mutate({patch:{diagnostics:[{id:e,armMs:t}]}},{onSettled:()=>{l(null),n.refetch()}})},f=n.data?.activeWindows??[],p=n.data?.channels??[],m=n.data?.activeChannels??[],g=(e,t,r)=>{l(e),a.mutate({patch:{channels:[{channel:e,armMs:t,deviceIds:r}]}},{onSettled:()=>{l(null),n.refetch()}})};return t(S,{icon:d,title:e(`logging.diagnostics.title`,`Diagnostics`),subtitle:e(`logging.diagnostics.subtitle`,`Diagnostics are armed for a window, never switched on. Each carries a deadline and expires by itself — one left running is an incident of its own.`),children:[n.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(c,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}):i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:f.map(e=>i(R,{window:e,busy:o===e.id,onArm:t=>u(e.id,t)},e.id))}),i(`h3`,{className:`mt-6 text-sm font-medium text-foreground`,children:e(`logging.diagnostics.channels`,`Component channels`)}),i(`p`,{className:`mb-2 max-w-3xl text-[11px] text-foreground-subtle`,children:e(`logging.diagnostics.channelsSubtitle`,`Declared by the addons that own them — this list is not maintained by hand. Arming a channel opens a window with a deadline; it closes by itself.`)}),p.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`logging.diagnostics.noChannels`,`No addon on this cluster declares a log channel, or none could be reached right now.`)}):i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:p.map(e=>i(L,{channel:e,state:m.find(t=>t.channel===e.name),busy:o===e.name,onArm:(t,n)=>g(e.name,t,n)},e.name))})]})}function L({channel:e,state:n,busy:o,onArm:s}){let{t:c}=v(),[l,u]=r(``),d=n?.armed===!0,f=()=>{let e=l.split(/[\s,+]+/).filter(e=>/^\d+$/.test(e)).map(e=>Number(e));return e.length>0?e:null};return t(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.name}),d?t(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[i(k,{className:`h-3 w-3`}),c(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:z(n?.remainingMs??0)})]}):i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:c(`logging.diagnostics.disarmed`,`disarmed`)}),d&&n?.deviceIds!==null&&n?.deviceIds!==void 0&&t(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[i(a,{className:`h-3 w-3`}),n.deviceIds.join(`, `)]}),!e.perDevice&&i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:c(`logging.diagnostics.notPerCamera`,`not filterable per camera`)})]}),i(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:e.description})]}),t(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[e.perDevice&&i(`input`,{type:`text`,inputMode:`numeric`,value:l,disabled:o,onChange:e=>u(e.target.value),placeholder:c(`logging.diagnostics.camerasPlaceholder`,`all cameras`),className:`w-28 rounded border border-border bg-surface px-2 py-1 text-[11px] text-foreground`}),P.map(e=>i(`button`,{type:`button`,disabled:o,onClick:()=>s(e,f()),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:z(e)},e)),i(`button`,{type:`button`,disabled:o||!d,onClick:()=>s(0,null),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:c(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function R({window:e,busy:n,onArm:r}){let{t:a}=v();return t(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.id}),e.armed?t(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[i(k,{className:`h-3 w-3`}),a(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:z(e.remainingMs)})]}):i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:a(`logging.diagnostics.disarmed`,`disarmed`)}),e.armed&&!e.persisted&&i(`span`,{className:`text-[10px] text-warning`,children:a(`logging.diagnostics.notPersisted`,`not persisted — will not survive a restart`)})]}),i(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:F[e.id]??``})]}),t(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[P.map(e=>i(`button`,{type:`button`,disabled:n,onClick:()=>r(e),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:z(e)},e)),i(`button`,{type:`button`,disabled:n||!e.armed,onClick:()=>r(0),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:a(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function z(e){let t=Math.max(0,Math.round(e/1e3)),n=Math.floor(t/60),r=t%60;return n===0?`${r}s`:r===0?`${n}m`:`${n}m ${r}s`}e();var B=[`debug`,`info`,`warn`,`error`],V=``,H=``;function U(){let{t:e}=v(),[a,o]=r(V),[l,d]=r(H),{nodes:f}=u(),p=n(()=>f.map(e=>({id:e.id,label:e.name||e.id})),[f]),m=h({...a===V?{}:{scopeNodeId:a},...l===H?{}:{scopeComponent:l}},{refetchInterval:15e3}),g=s(),y=m.data,b=g.isPending||m.isFetching,x=y?.channels??[],C=(e,t)=>{g.mutate({...e.nodeId===null?{}:{scopeNodeId:e.nodeId},...e.component===null?{}:{scopeComponent:e.component},patch:{level:t}},{onSuccess:()=>void m.refetch()})};return i(S,{icon:_,title:e(`logging.levels.title`,`Levels`),subtitle:e(`logging.levels.subtitle`,`Cluster → node, most specific wins. The floor gates what reaches the log destinations; the in-memory viewer keeps every line either way.`),actions:t(`div`,{className:`flex flex-wrap items-center gap-3`,children:[t(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[e(`logging.levels.scope`,`Scope`),t(`select`,{className:`rounded border border-border bg-surface px-2 py-1 text-xs text-foreground disabled:opacity-50`,value:a,disabled:l!==H,onChange:e=>o(e.target.value),children:[i(`option`,{value:V,children:e(`logging.levels.cluster`,`Cluster`)}),p.map(e=>i(`option`,{value:e.id,children:e.label},e.id))]})]}),t(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[e(`logging.levels.component`,`Component`),t(`select`,{className:`rounded border border-border bg-surface px-2 py-1 text-xs text-foreground`,value:l,onChange:e=>d(e.target.value),children:[i(`option`,{value:H,children:e(`logging.levels.noComponent`,`None`)}),x.map(e=>i(`option`,{value:e.name,children:e.name},e.name))]})]})]}),children:m.isLoading||y===void 0?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(c,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}):t(`div`,{className:`space-y-3`,children:[i(G,{level:y.effective.level,source:y.effective.levelSource,persisted:y.persisted}),i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:y.explicit.layers.map(e=>i(K,{layer:e,inForce:e.scope===y.effective.levelSource,busy:b,onSet:t=>C(e,t),onClear:()=>C(e,null)},`${e.scope}:${e.nodeId??e.component??`cluster`}`))}),l!==H&&i(`p`,{className:`text-[11px] text-foreground-subtle`,children:x.find(e=>e.name===l)?.description??``}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`logging.levels.componentNote`,`A component is a log channel an addon declared. Its level is cluster-wide and beats both the node and the cluster layer.`)}),i(W,{days:y.opsLogRetentionDays,busy:b,onSet:e=>g.mutate({patch:{opsLogRetentionDays:e}},{onSuccess:()=>void m.refetch()})})]})})}function W({days:e,busy:n,onSet:r}){let{t:a}=v();return t(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-1`,children:[t(`label`,{className:`flex items-center justify-between gap-3`,children:[i(`span`,{className:`text-xs font-medium`,children:a(`logging.levels.opsLogRetention`,`Retention audit trail`)}),t(`span`,{className:`flex items-center gap-1.5`,children:[i(`input`,{type:`number`,min:0,max:3650,step:1,defaultValue:e,disabled:n,onBlur:t=>{let n=Number.parseInt(t.target.value,10);Number.isFinite(n)&&n!==e&&r(n)},className:`w-20 rounded border border-border bg-surface px-2 py-1 text-xs`}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:a(`common.days`,`days`)})]})]}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`logging.levels.opsLogRetentionNote`,`How long the record of what retention deleted is kept. Cluster-wide, and deliberately longer than any camera window — it is the history of the sweep, not of the camera, and it is what makes a storage leak explainable after the fact. 0 keeps it forever.`)})]})}function G({level:e,source:n,persisted:r}){let{t:a}=v();return t(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-xs text-foreground-subtle`,children:a(`logging.levels.effective`,`In force here`)}),i(`span`,{className:`rounded bg-primary/10 px-2 py-0.5 text-xs font-semibold text-primary`,children:e}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:n==="default"?a(`logging.levels.fromDefault`,`nothing is set anywhere — this is the default`):a(`logging.levels.fromLayer`,`decided by the {{source}} layer`,{source:n})})]}),!r&&i(`p`,{className:`mt-1 text-[11px] text-warning`,children:a(`logging.levels.notPersisted`,`The settings store could not be read or written — what you see is live, but it would not survive a restart.`)})]})}function K({layer:e,inForce:n,busy:r,onSet:a,onClear:o}){let{t:s}=v();return t(`div`,{className:`flex flex-col gap-2 p-3 sm:flex-row sm:items-center sm:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.scope===`cluster`?s(`logging.levels.cluster`,`Cluster`):e.scope===`component`?e.component??``:e.nodeId??``}),n&&t(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[i(l,{className:`h-3 w-3`}),s(`logging.levels.inForce`,`in force`)]})]}),i(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:e.level===null?s(`logging.levels.inherits`,`inherits — nothing set at this layer`):s(`logging.levels.setHere`,`set here: {{level}}`,{level:e.level})})]}),t(`div`,{className:`flex shrink-0 items-center gap-1`,children:[B.map(t=>i(`button`,{type:`button`,disabled:r,onClick:()=>a(t),className:`rounded px-2 py-1 text-[11px] font-medium transition-colors disabled:opacity-50 ${e.level===t?`bg-primary text-primary-foreground`:`border border-border text-foreground-subtle hover:text-foreground`}`,children:t},t)),i(`button`,{type:`button`,disabled:r||e.level===null,onClick:o,className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-40`,children:s(`logging.levels.clear`,`Clear`)})]})]})}function q(){return i(S,{children:i(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:i(m,{limit:500,maxHeight:`max-h-[calc(100vh-310px)]`,showScope:!0,showFilters:!0})})})}function J(){return i(`div`,{className:`flex flex-col p-4`,children:i(C,{tabs:[{id:`viewer`,label:`Viewer`,icon:b,content:i(q,{})},{id:y.logging.tab,label:`Destinations`,icon:p,content:i(N,{}),ownedParams:x},{id:`levels`,label:`Levels`,icon:_,content:i(U,{})},{id:`diagnostics`,label:`Diagnostics`,icon:d,content:i(I,{})}]})})}export{J as LogsPage};
|
|
1
|
+
import{Q as e,S as t,W as n,q as r,x as i}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{_t as a,vt as o}from"./player-overlays-D9aoM64J.js";import{Cu as s,Dl as c,Qf as l,Sr as u,Tl as d,Ud as f,_d as p,kf as m,xr as h,yt as g}from"./src-B-IRCQFw.js";import{t as _}from"./layers-BiHKkPFk.js";import{t as v}from"./useTranslation-Bc5yH9V9.js";import{c as y,et as b,s as x}from"./index-D7yeH_53.js";import{t as S}from"./AdminPage-BSFohA3i.js";import{t as C}from"./AdminTabs-wu-aryGN.js";import{r as w,t as T}from"./AddonIntegrationBody-EbUl8tUN.js";import{n as E,t as D}from"./addon-display-names-BkwMrExv.js";var O=o(`file-text`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),k=o(`timer-reset`,[[`path`,{d:`M10 2h4`,key:`n1abiw`}],[`path`,{d:`M12 14v-4`,key:`1evpnu`}],[`path`,{d:`M4 13a8 8 0 0 1 8-7 8 8 0 1 1-5.3 14L4 17.6`,key:`1ts96g`}],[`path`,{d:`M9 17H4v5`,key:`8t5av`}]]);e();var A=5e3,j=`log-destination`,M={"winston-logging":`Rotated log files on this node’s disk.`,"console-logging":`stdout / stderr of the node process.`,"loki-logging":`Pushes to a Grafana Loki instance. Off until enabled with a URL.`,"hub-forwarder":`Agent-only — forwards this node’s entries to the hub.`};function N(){let e=u({capName:`log-destination`},{refetchInterval:A}),t=h(void 0,{refetchInterval:A}),r=n(()=>D(t.data??[]),[t.data]),a=n(()=>{let e=new Map;for(let n of t.data??[]){let t=n.description,r=n.id;typeof r==`string`&&typeof t==`string`&&t.length>0&&e.set(r,t)}return e},[t.data]),o=n(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:r.get(e.addonId)??e.addonId,isActive:e.isActive,caption:a.get(e.addonId)??M[e.addonId]??``})),[e.data,r,a]);return i(w,{icon:p,title:`Destinations`,subtitle:`Every registered log destination. Entries are fanned to all enabled destinations at once — enabling one does not disable another.`,groups:[{id:j,label:`Log destinations`,install:{capability:j,label:`Add destination`},entries:o.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:O,...E(e.isActive),render:()=>i(T,{addonId:e.addonId,displayName:e.displayName,capName:j,isActive:e.isActive,badges:e.caption.length>0?i(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.caption}):null})}))}],isLoading:e.isLoading,emptyTitle:`No log destinations registered`,emptyDescription:`This should not happen — the console and rotated-file destinations are builtins. If the list is empty, the node is still booting.`})}e();var P=[12e4,3e5,6e5,18e5],F={"request-census":`Counts every tRPC call by TRANSPORT PLANE — http, ws, mesh — and by procedure, caller, address and user-agent. Subscriptions are counted apart from calls, so a long-lived stream cannot pass for a storm. Arm it, then restart: the deadline is persisted, so the window is still running when clients reconnect.`};function I(){let{t:e}=v(),n=d({},{refetchInterval:5e3}),a=c(),[o,s]=r(null),u=(e,t)=>{s(e),a.mutate({patch:{diagnostics:[{id:e,armMs:t}]}},{onSettled:()=>{s(null),n.refetch()}})},p=n.data?.activeWindows??[],m=n.data?.channels??[],h=n.data?.activeChannels??[],g=(e,t,r)=>{s(e),a.mutate({patch:{channels:[{channel:e,armMs:t,deviceIds:r}]}},{onSettled:()=>{s(null),n.refetch()}})};return t(S,{icon:l,title:e(`logging.diagnostics.title`,`Diagnostics`),subtitle:e(`logging.diagnostics.subtitle`,`Diagnostics are armed for a window, never switched on. Each carries a deadline and expires by itself — one left running is an incident of its own.`),children:[n.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(f,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}):i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:p.map(e=>i(R,{window:e,busy:o===e.id,onArm:t=>u(e.id,t)},e.id))}),i(`h3`,{className:`mt-6 text-sm font-medium text-foreground`,children:e(`logging.diagnostics.channels`,`Component channels`)}),i(`p`,{className:`mb-2 max-w-3xl text-[11px] text-foreground-subtle`,children:e(`logging.diagnostics.channelsSubtitle`,`Declared by the addons that own them — this list is not maintained by hand. Arming a channel opens a window with a deadline; it closes by itself.`)}),m.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`logging.diagnostics.noChannels`,`No addon on this cluster declares a log channel, or none could be reached right now.`)}):i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:m.map(e=>i(L,{channel:e,state:h.find(t=>t.channel===e.name),busy:o===e.name,onArm:(t,n)=>g(e.name,t,n)},e.name))})]})}function L({channel:e,state:n,busy:o,onArm:s}){let{t:c}=v(),[l,u]=r(``),d=n?.armed===!0,f=()=>{let e=l.split(/[\s,+]+/).filter(e=>/^\d+$/.test(e)).map(e=>Number(e));return e.length>0?e:null};return t(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.name}),d?t(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[i(k,{className:`h-3 w-3`}),c(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:z(n?.remainingMs??0)})]}):i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:c(`logging.diagnostics.disarmed`,`disarmed`)}),d&&n?.deviceIds!==null&&n?.deviceIds!==void 0&&t(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[i(a,{className:`h-3 w-3`}),n.deviceIds.join(`, `)]}),!e.perDevice&&i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:c(`logging.diagnostics.notPerCamera`,`not filterable per camera`)})]}),i(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:e.description})]}),t(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[e.perDevice&&i(`input`,{type:`text`,inputMode:`numeric`,value:l,disabled:o,onChange:e=>u(e.target.value),placeholder:c(`logging.diagnostics.camerasPlaceholder`,`all cameras`),className:`w-28 rounded border border-border bg-surface px-2 py-1 text-[11px] text-foreground`}),P.map(e=>i(`button`,{type:`button`,disabled:o,onClick:()=>s(e,f()),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:z(e)},e)),i(`button`,{type:`button`,disabled:o||!d,onClick:()=>s(0,null),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:c(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function R({window:e,busy:n,onArm:r}){let{t:a}=v();return t(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.id}),e.armed?t(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[i(k,{className:`h-3 w-3`}),a(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:z(e.remainingMs)})]}):i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:a(`logging.diagnostics.disarmed`,`disarmed`)}),e.armed&&!e.persisted&&i(`span`,{className:`text-[10px] text-warning`,children:a(`logging.diagnostics.notPersisted`,`not persisted — will not survive a restart`)})]}),i(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:F[e.id]??``})]}),t(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[P.map(e=>i(`button`,{type:`button`,disabled:n,onClick:()=>r(e),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:z(e)},e)),i(`button`,{type:`button`,disabled:n||!e.armed,onClick:()=>r(0),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:a(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function z(e){let t=Math.max(0,Math.round(e/1e3)),n=Math.floor(t/60),r=t%60;return n===0?`${r}s`:r===0?`${n}m`:`${n}m ${r}s`}e();var B=[`debug`,`info`,`warn`,`error`],V=``,H=``;function U(){let{t:e}=v(),[a,o]=r(V),[l,u]=r(H),{nodes:p}=s(),m=n(()=>p.map(e=>({id:e.id,label:e.name||e.id})),[p]),h=d({...a===V?{}:{scopeNodeId:a},...l===H?{}:{scopeComponent:l}},{refetchInterval:15e3}),g=c(),y=h.data,b=g.isPending||h.isFetching,x=y?.channels??[],C=(e,t)=>{g.mutate({...e.nodeId===null?{}:{scopeNodeId:e.nodeId},...e.component===null?{}:{scopeComponent:e.component},patch:{level:t}},{onSuccess:()=>void h.refetch()})};return i(S,{icon:_,title:e(`logging.levels.title`,`Levels`),subtitle:e(`logging.levels.subtitle`,`Cluster → node, most specific wins. The floor gates what reaches the log destinations; the in-memory viewer keeps every line either way.`),actions:t(`div`,{className:`flex flex-wrap items-center gap-3`,children:[t(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[e(`logging.levels.scope`,`Scope`),t(`select`,{className:`rounded border border-border bg-surface px-2 py-1 text-xs text-foreground disabled:opacity-50`,value:a,disabled:l!==H,onChange:e=>o(e.target.value),children:[i(`option`,{value:V,children:e(`logging.levels.cluster`,`Cluster`)}),m.map(e=>i(`option`,{value:e.id,children:e.label},e.id))]})]}),t(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[e(`logging.levels.component`,`Component`),t(`select`,{className:`rounded border border-border bg-surface px-2 py-1 text-xs text-foreground`,value:l,onChange:e=>u(e.target.value),children:[i(`option`,{value:H,children:e(`logging.levels.noComponent`,`None`)}),x.map(e=>i(`option`,{value:e.name,children:e.name},e.name))]})]})]}),children:h.isLoading||y===void 0?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(f,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}):t(`div`,{className:`space-y-3`,children:[i(G,{level:y.effective.level,source:y.effective.levelSource,persisted:y.persisted}),i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:y.explicit.layers.map(e=>i(K,{layer:e,inForce:e.scope===y.effective.levelSource,busy:b,onSet:t=>C(e,t),onClear:()=>C(e,null)},`${e.scope}:${e.nodeId??e.component??`cluster`}`))}),l!==H&&i(`p`,{className:`text-[11px] text-foreground-subtle`,children:x.find(e=>e.name===l)?.description??``}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`logging.levels.componentNote`,`A component is a log channel an addon declared. Its level is cluster-wide and beats both the node and the cluster layer.`)}),i(W,{days:y.opsLogRetentionDays,busy:b,onSet:e=>g.mutate({patch:{opsLogRetentionDays:e}},{onSuccess:()=>void h.refetch()})})]})})}function W({days:e,busy:n,onSet:r}){let{t:a}=v();return t(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-1`,children:[t(`label`,{className:`flex items-center justify-between gap-3`,children:[i(`span`,{className:`text-xs font-medium`,children:a(`logging.levels.opsLogRetention`,`Retention audit trail`)}),t(`span`,{className:`flex items-center gap-1.5`,children:[i(`input`,{type:`number`,min:0,max:3650,step:1,defaultValue:e,disabled:n,onBlur:t=>{let n=Number.parseInt(t.target.value,10);Number.isFinite(n)&&n!==e&&r(n)},className:`w-20 rounded border border-border bg-surface px-2 py-1 text-xs`}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:a(`common.days`,`days`)})]})]}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`logging.levels.opsLogRetentionNote`,`How long the record of what retention deleted is kept. Cluster-wide, and deliberately longer than any camera window — it is the history of the sweep, not of the camera, and it is what makes a storage leak explainable after the fact. 0 keeps it forever.`)})]})}function G({level:e,source:n,persisted:r}){let{t:a}=v();return t(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-xs text-foreground-subtle`,children:a(`logging.levels.effective`,`In force here`)}),i(`span`,{className:`rounded bg-primary/10 px-2 py-0.5 text-xs font-semibold text-primary`,children:e}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:n==="default"?a(`logging.levels.fromDefault`,`nothing is set anywhere — this is the default`):a(`logging.levels.fromLayer`,`decided by the {{source}} layer`,{source:n})})]}),!r&&i(`p`,{className:`mt-1 text-[11px] text-warning`,children:a(`logging.levels.notPersisted`,`The settings store could not be read or written — what you see is live, but it would not survive a restart.`)})]})}function K({layer:e,inForce:n,busy:r,onSet:a,onClear:o}){let{t:s}=v();return t(`div`,{className:`flex flex-col gap-2 p-3 sm:flex-row sm:items-center sm:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.scope===`cluster`?s(`logging.levels.cluster`,`Cluster`):e.scope===`component`?e.component??``:e.nodeId??``}),n&&t(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[i(m,{className:`h-3 w-3`}),s(`logging.levels.inForce`,`in force`)]})]}),i(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:e.level===null?s(`logging.levels.inherits`,`inherits — nothing set at this layer`):s(`logging.levels.setHere`,`set here: {{level}}`,{level:e.level})})]}),t(`div`,{className:`flex shrink-0 items-center gap-1`,children:[B.map(t=>i(`button`,{type:`button`,disabled:r,onClick:()=>a(t),className:`rounded px-2 py-1 text-[11px] font-medium transition-colors disabled:opacity-50 ${e.level===t?`bg-primary text-primary-foreground`:`border border-border text-foreground-subtle hover:text-foreground`}`,children:t},t)),i(`button`,{type:`button`,disabled:r||e.level===null,onClick:o,className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-40`,children:s(`logging.levels.clear`,`Clear`)})]})]})}function q(){return i(S,{children:i(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:i(g,{limit:500,maxHeight:`max-h-[calc(100vh-310px)]`,showScope:!0,showFilters:!0})})})}function J(){return i(`div`,{className:`flex flex-col p-4`,children:i(C,{tabs:[{id:`viewer`,label:`Viewer`,icon:b,content:i(q,{})},{id:y.logging.tab,label:`Destinations`,icon:p,content:i(N,{}),ownedParams:x},{id:`levels`,label:`Levels`,icon:_,content:i(U,{})},{id:`diagnostics`,label:`Diagnostics`,icon:l,content:i(I,{})}]})})}export{J as LogsPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,b as a,q as o,x as s,z as ee}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{G as te,H as c,R as l,Y as u,at as d,n as f,pt as p}from"./player-overlays-
|
|
1
|
+
import{I as e,K as t,Q as n,S as r,W as i,b as a,q as o,x as s,z as ee}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{G as te,H as c,R as l,Y as u,at as d,n as f,pt as p}from"./player-overlays-D9aoM64J.js";import{MaskShapeCanvas as m}from"./MaskShapeCanvas-Dcpby34M.js";n();var h=110,g=`motion-zones`,_=0,v=[1,2,3],y=1,b=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,x=`rounded-md border border-primary/50 bg-primary/15 px-2.5 py-1 text-[11px] font-medium text-primary hover:bg-primary/25 disabled:opacity-40 transition-colors`;function S(e,t,n){let r=t*n,i=Array.from({length:r});for(let t=0;t<r;t+=1)i[t]=e[t]===!0;return i}function ne(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return!1;return!0}function C(e,t){return Math.ceil(e/t)}function w(e,t,n){return Math.min(n-1,Math.floor((e+.5)/t*n))}function T(e,t,n,r){let i=C(t,r),a=C(n,r),o=Array.from({length:i*a},()=>!1);for(let r=0;r<n;r+=1){let s=w(r,n,a);for(let n=0;n<t;n+=1)e[r*t+n]===!0&&(o[s*i+w(n,t,i)]=!0)}return o}function E(e,t,n,r){let i=C(t,r),a=C(n,r),o=Array.from({length:t*n},()=>!1);for(let r=0;r<n;r+=1){let s=w(r,n,a);for(let n=0;n<t;n+=1)o[r*t+n]=e[s*i+w(n,t,i)]===!0}return o}function D({deviceId:n}){let w=te(d().trpcClient,n),[D,O]=o(null),[k,A]=o(!1),[j,M]=o(null),[N,P]=o(null),[F,I]=o(y),[L,R]=o(!1),[z,B]=o(!1),V=t(!1);ee(()=>{if(!w)return;let e=!1;return V.current=!1,O(null),A(!1),M(null),P(null),I(y),B(!1),(async()=>{try{let t=await w.motionZones?.getOptions({});if(e)return;if(!t)throw Error(`device proxy not ready`);if(O(t),V.current)return;let n=await w.motionZones?.getStatus({});if(e)return;if(!n)throw Error(`device proxy not ready`);V.current=!0;let r=n.regions.find(e=>e.shape.kind===`grid`),i=S(r?r.shape.cells:[],t.grid.width,t.grid.height);P(i),M(T(i,t.grid.width,t.grid.height,y))}catch(t){if(e)return;c(t)?A(!0):console.error(`Motion Zones load failed`,t)}})(),()=>{e=!0}},[w]);let H=D?D.grid.width:0,U=D?D.grid.height:0,W=C(H,F),G=C(U,F),K=i(()=>j&&D?E(j,H,U,F):null,[j,D,H,U,F]),q=i(()=>K!==null&&N!==null&&!ne(K,N),[K,N]),J=i(()=>K?K.reduce((e,t)=>t?e+1:e,0):0,[K]),Y=H*U,X=W*G,Z=e(e=>{X>0&&M(Array.from({length:X},()=>e))},[X]),re=e(()=>{M(e=>e&&e.map(e=>!e))},[]),ie=e(()=>{N&&D&&M(T(N,H,U,F))},[N,D,H,U,F]),ae=e(e=>{e===F||!D||M(t=>{if(!t)return I(e),t;let n=T(E(t,H,U,F),H,U,e);return I(e),n})},[F,D,H,U]),Q=i(()=>D&&j?[{id:_,shape:{kind:`grid`,gridWidth:W,gridHeight:G,cells:[...j]}}]:[],[D,j,W,G]),$=e((e,t)=>{t.kind===`grid`&&M(t.cells)},[]),oe=e(async()=>{if(!(!w||!j||!D)){R(!0);try{let e=E(j,D.grid.width,D.grid.height,F),t={kind:`grid`,gridWidth:D.grid.width,gridHeight:D.grid.height,cells:e};await w.motionZones?.setZone({patch:{regions:[{id:_,enabled:!0,shape:t}]}});let n=await w.motionZones?.getStatus({});if(n){let e=n.regions.find(e=>e.shape.kind===`grid`),t=S(e?e.shape.cells:[],D.grid.width,D.grid.height);P(t),M(T(t,D.grid.width,D.grid.height,F))}}catch(e){console.error(`Motion Zones save failed`,e)}finally{R(!1)}}},[w,j,D,F]);return f(i(()=>z&&!k&&D&&j?{id:g,order:h,node:s(m,{transparent:!0,items:Q,supportedShapes:[`grid`],grid:{width:W,height:G},selectedId:_,onSelect:()=>{},onShapeChange:$,onDrawComplete:()=>{},drawingKind:null})}:null,[z,k,D,j,Q,$,W,G])),w?s(u,{title:`Motion Zones`,icon:s(p,{className:`h-3.5 w-3.5 text-foreground-subtle`}),children:s(`div`,{className:`flex flex-col gap-3`,children:k?s(`p`,{className:`${l} leading-relaxed`,children:`This camera doesn't expose an on-board motion zones grid.`}):!k&&D!==null&&j!==null?r(a,{children:[r(`p`,{className:`${l} leading-relaxed`,children:[`Toggle `,s(`strong`,{className:`text-foreground`,children:`Edit grid`}),` to paint the region directly on the live frame, then `,s(`strong`,{className:`text-foreground`,children:`Save`}),` to push the mask to the camera. Pick a bigger`,` `,s(`strong`,{className:`text-foreground`,children:`Cell size`}),` for quicker, broad-stroke painting — it's resampled to the camera's native `,D.grid.width,`×`,D.grid.height,` grid on save (×1 is the finest).`]}),r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[s(`button`,{type:`button`,onClick:()=>B(e=>!e),disabled:L,"aria-pressed":z,className:z?x:b,children:z?`Done editing`:`Edit grid`}),s(`button`,{type:`button`,onClick:()=>Z(!0),disabled:L,className:b,children:`All on`}),s(`button`,{type:`button`,onClick:()=>Z(!1),disabled:L,className:b,children:`All off`}),s(`button`,{type:`button`,onClick:re,disabled:L,className:b,children:`Invert`}),r(`div`,{className:`flex items-center gap-1 ml-1`,role:`group`,"aria-label":`Cell size`,children:[s(`span`,{className:`${l} mr-0.5`,children:`Cell size`}),v.map(e=>r(`button`,{type:`button`,onClick:()=>ae(e),disabled:L,"aria-pressed":F===e,title:e===1?`Camera grid ${H}×${U} (finest)`:`${C(H,e)}×${C(U,e)} painting grid · cells ×${e} bigger`,className:F===e?x:b,children:[`×`,e]},e))]}),r(`span`,{className:`${l} ml-1 tabular-nums`,children:[J,` / `,Y,` cells · `,D.grid.width,`×`,D.grid.height,F===1?``:` · paint ${W}×${G}`]}),s(`span`,{className:`flex-1`}),s(`button`,{type:`button`,onClick:ie,disabled:L||!q,className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,children:`Revert`}),s(`button`,{type:`button`,onClick:()=>void oe(),disabled:L||!q,className:x,children:L?`Saving…`:`Save`})]})]}):s(`p`,{className:`${l} leading-relaxed`,children:`Loading the camera's grid…`})})}):null}export{D as MotionZonesSettings};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./browser-BHo8W_uH.js","./rolldown-runtime-Cyuzqnbw.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{t}from"./vite-preload-helper-kNaey6uv.js";import{K as n,Q as r,S as i,W as a,a as o,b as s,q as c,t as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as f,at as p,st as m}from"./player-overlays-D9aoM64J.js";import{Co as h,Ef as g,Fn as _,G as v,Gd as y,Jd as b,Kn as x,Ou as S,Pn as C,Tf as w,Ud as T,Vd as E,Yd as D,_n as O,ad as k,cf as A,gf as j,jd as M,kt as N,qu as P,vn as ee,xo as te,zn as F}from"./src-B-IRCQFw.js";import{t as I}from"./monitor-smartphone-DCj4MFCV.js";import{a as L,b as R,i as z,r as ne,t as re}from"./SessionsList-Yg5gVfMg.js";import{Jn as ie,qn as ae}from"./client-DX0rAC3X.js";import{t as B}from"./useTranslation-Bc5yH9V9.js";import"./mount-BTxjd_Y8.js";import{R as V,i as H,n as U,r as W,rt as G,t as K}from"./index-D7yeH_53.js";import{t as q}from"./AdminPage-BSFohA3i.js";r();function oe({value:n,size:r=192}){let[a,o]=c(null),[s,l]=c(null);if(d(()=>{let r=!1;return t(()=>import(`./browser-BHo8W_uH.js`).then(t=>e(t.default,1)).then(async e=>{if(r)return;let t=e.create;if(typeof t!=`function`){l(`qrcode.create() unavailable in installed version`);return}try{let e=t(n,{errorCorrectionLevel:`M`});r||o(e)}catch(e){r||l(e instanceof Error?e.message:`QR generation failed`)}}),__vite__mapDeps([0,1]),import.meta.url).catch(()=>{r||l(`qrcode library not installed`)}),()=>{r=!0}},[n]),s)return u(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle text-center p-4`,style:{width:r,height:r},children:`QR rendering unavailable — use the secret below.`});if(!a)return u(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle animate-pulse`,style:{width:r,height:r},children:`Generating…`});let f=a.modules.size,p=r/f,m=[];for(let e=0;e<f;e++)for(let t=0;t<f;t++)a.modules.data[e*f+t]&&m.push(u(`rect`,{x:t*p,y:e*p,width:p,height:p,fill:`currentColor`},`${t}-${e}`));return i(`svg`,{width:r,height:r,viewBox:`0 0 ${r} ${r}`,className:`text-black`,children:[u(`rect`,{x:0,y:0,width:r,height:r,fill:`white`}),m]})}var se=`${ae}/connect`,J={public:0,mesh:1,lan:2,"lan-ipv6":3};function ce(e){switch(e.kind){case`public`:return e.interfaceKind===`vpn`?`mesh`:`public`;case`lan-ipv4`:return`lan`;case`lan-ipv6`:return`lan-ipv6`;case`custom`:return`public`;case`loopback`:case`app-link`:return null}}function Y(e){return ie(e)}function le(e){return e.startsWith(`https://`)}function ue(e){let t=e.flatMap(e=>{let t=ce(e),n=Y(e.baseUrl);return t===null||n===null?[]:[{endpoint:e,tier:t,origin:n}]}).toSorted((e,t)=>J[e.tier]-J[t.tier]||Number(t.endpoint.plausible)-Number(e.endpoint.plausible)||e.endpoint.priority-t.endpoint.priority),n=new Set;return t.flatMap(({endpoint:e,tier:t,origin:r})=>n.has(r)?[]:(n.add(r),[{origin:r,label:e.label,tier:t,secure:le(r),plausible:e.plausible}]))}function de(e,t,n=null){for(let r of[t,n]){if(r===null)continue;let t=Y(r),n=e.find(e=>e.origin===t);if(n!==void 0)return n}return e[0]??null}function fe(e){let t=new URL(se);return t.searchParams.set(`hub`,e),t.toString()}r();var pe=176,X={scheme:`https`};function me(){let{t:e}=B(),t=h(X),n=te(X).data?.roles.publicEndpoint.resolved??null;return i(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[i(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[u(k,{className:`h-3.5 w-3.5 text-foreground-subtle`}),u(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`connectPhone.title`)})]}),i(`div`,{className:`p-4 space-y-3`,children:[u(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`connectPhone.description`)}),t.isPending?i(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[u(T,{className:`h-3.5 w-3.5 animate-spin`}),e(`connectPhone.loading`)]}):t.isError?i(`div`,{className:`flex items-start gap-2 text-[11px] text-danger`,children:[u(P,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),i(`div`,{className:`flex-1 min-w-0 space-y-1.5`,children:[u(`div`,{className:`break-words`,children:e(`connectPhone.error`,{message:t.error.message})}),u(_,{size:`sm`,variant:`ghost`,onClick:()=>void t.refetch(),children:e(`connectPhone.retry`)})]})]}):u(he,{candidates:ue(t.data.endpoints),preferredOrigin:n})]})]})}function he({candidates:e,preferredOrigin:t}){let{t:n}=B(),[r,o]=c(null),s=de(e,r,t),l=a(()=>s?fe(s.origin):null,[s]);if(s===null||l===null)return u(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`connectPhone.empty`)});let d=e=>n(`connectPhone.tier.${e}`),f=e.map(e=>({value:e.origin,label:`${d(e.tier)} — ${e.origin}`}));return i(`div`,{className:`flex flex-col sm:flex-row gap-4`,children:[u(O,{value:l,size:pe,alt:n(`connectPhone.qrAlt`),className:`self-start`}),i(`div`,{className:`flex-1 min-w-0 space-y-3`,children:[i(`label`,{className:`block space-y-1`,children:[u(`span`,{className:`text-[11px] font-medium text-foreground`,children:n(`connectPhone.addressLabel`)}),u(C,{value:s.origin,options:f,onChange:e=>o(e.target.value)}),i(`span`,{className:`block text-[10px] text-foreground-subtle`,children:[d(s.tier),` · `,s.label]})]}),!s.secure&&u(Z,{text:n(`connectPhone.insecure`)}),!s.plausible&&u(Z,{text:n(`connectPhone.implausible`)}),i(`div`,{className:`space-y-1`,children:[u(`span`,{className:`text-[11px] font-medium text-foreground`,children:n(`connectPhone.linkLabel`)}),i(`div`,{className:`flex items-center gap-1 rounded-md border border-border bg-background px-2 py-1`,children:[u(`code`,{className:`flex-1 min-w-0 font-mono text-[11px] text-foreground break-all select-all`,children:l}),u(N,{value:l,srLabel:n(`connectPhone.linkLabel`)})]})]}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`connectPhone.signInHint`)})]})]})}function Z({text:e}){return i(`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:[u(P,{className:`h-3.5 w-3.5 text-warning mt-0.5 shrink-0`}),u(`span`,{children:e})]})}r();function ge(e){return new Date(e).toLocaleDateString()}function _e(){let e=x(),t=S.useUtils(),r=S.auth.listLinkableProviders.useQuery(),a=S.auth.listOwnExternalIdentities.useQuery(),[o,s]=c(null),[l,p]=c(()=>H(window.location.search)),m=n(null),h=z(`Linking a sign-in account`),_=n(null);d(()=>()=>_.current?.(),[]);let[v,b]=c(null);d(()=>{if(l===null)return;let e=new URL(window.location.href);e.searchParams.delete(`linked`),e.searchParams.delete(`linkError`),window.history.replaceState({},``,e.pathname+e.search+e.hash)},[l]);let C=S.auth.beginExternalLink.useMutation({onSuccess:({url:e})=>{let n=m.current;if(m.current=null,n===null||n.closed){window.location.assign(e);return}let r=e=>{b(null),p(H(`?${e}`)),t.auth.listOwnExternalIdentities.invalidate()};_.current?.(),_.current=U(n,{onReturn:e=>{e.target===`profile`&&r(e.query)},onDone:e=>{e.target===`profile`&&r(e.query)},onClosed:()=>{_.current?.(),_.current=null,t.auth.listOwnExternalIdentities.invalidate()}}),n.location.href=f(W(e))},onError:e=>{m.current?.close(),m.current=null,b(null),s(e.message)}}),E=S.auth.unlinkOwnExternalIdentity.useMutation({onSuccess:()=>void t.auth.listOwnExternalIdentities.invalidate(),onError:e=>s(e.message)}),D=r.data??[],O=a.data??[],k=v!==null&&O.some(e=>e.provider===v);if(d(()=>{!k||v===null||(b(null),p({kind:`linked`,provider:v}))},[k,v]),D.length===0&&O.length===0)return null;let A=new Set(O.map(e=>e.provider)),j=e=>D.find(t=>t.provider===e)?.label??e,M=async(t,n)=>{await e({title:`Unlink sign-in account`,message:`Stop signing in with this ${n} account?`,confirmLabel:`Unlink`,variant:`danger`})&&(s(null),E.mutate({provider:t.provider,subject:t.subject}))};return i(`div`,{"data-testid":`linked-sign-ins`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[h.dialog,i(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[u(y,{className:`h-3.5 w-3.5 text-foreground-subtle`}),u(`div`,{className:`text-xs font-semibold text-foreground`,children:`Linked sign-in accounts`})]}),i(`div`,{className:`p-4 space-y-3`,children:[u(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Sign in with an external account instead of your password. Only accounts you link here can sign you in; your two-factor authentication still applies.`}),l?.kind===`linked`&&i(`div`,{className:`flex items-center gap-2 rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2 text-xs text-foreground`,children:[u(w,{className:`h-3.5 w-3.5 text-emerald-500 shrink-0`}),`Linked your `,j(l.provider),` account.`]}),(l?.kind===`error`||o)&&i(`div`,{className:`flex items-center gap-2 rounded-md border border-danger/20 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[u(g,{className:`h-3.5 w-3.5 shrink-0`}),o??(l?.kind===`error`?l.message:``)]}),O.length>0&&u(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:O.map(e=>{let t=e.providerLabel??e.provider;return i(`li`,{className:`flex items-center gap-3 px-3 py-2 text-xs`,children:[i(`div`,{className:`flex-1 min-w-0`,children:[i(`div`,{className:`font-medium text-foreground truncate`,children:[t,!e.available&&u(`span`,{className:`ml-2 rounded bg-foreground-subtle/15 px-1.5 py-0.5 text-[10px] font-normal text-foreground-subtle`,children:`provider unavailable`})]}),i(`div`,{className:`text-[11px] text-foreground-subtle truncate`,children:[e.label??e.subject,` · linked `,ge(e.linkedAt)]})]}),i(`button`,{onClick:()=>void M(e,t),disabled:E.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:[u(R,{className:`h-3 w-3`}),`Unlink`]})]},`${e.provider}|${e.subject}`)})}),u(`div`,{className:`flex flex-wrap gap-2`,children:D.filter(e=>!A.has(e.provider)).map(e=>i(`button`,{onClick:()=>{s(null),p(null),h.requestProof().then(t=>{t!==null&&(m.current=K(null),b(m.current===null?null:e.provider),C.mutate({provider:e.provider,reauthToken:t}))})},disabled:C.isPending,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1 text-[11px] font-medium text-foreground hover:bg-surface-hover disabled:opacity-50`,children:[C.isPending&&C.variables?.provider===e.provider?u(T,{className:`h-3 w-3 animate-spin`}):u(y,{className:`h-3 w-3`}),`Link `,e.label]},e.provider))})]})]})}r();function Q(e){return e.message.length>0?e.message:`Request failed`}function ve(){let{logout:e}=V(),t=x(),n=S.useUtils(),r=S.auth.listOwnSessions.useQuery(),[a,o]=c(null),s=S.auth.revokeOwnSession.useMutation({onSuccess:()=>void n.auth.listOwnSessions.invalidate(),onError:e=>o(`Sign out failed: ${Q(e)}`)}),l=S.auth.logout.useMutation({onSuccess:()=>e(),onError:e=>o(`Sign out failed: ${Q(e)}`)}),d=async e=>{await t({title:`Sign out this session`,message:`${L(e.client).label} will have to sign in again.`,confirmLabel:`Sign out`,variant:`danger`})&&(o(null),s.mutate({id:e.id}))},f=async()=>{await t({title:`Sign out everywhere`,message:`Every session of your account ends, this browser included: you will be signed out here too and every device has to sign in again.`,confirmLabel:`Sign out everywhere`,variant:`danger`})&&(o(null),l.mutate({everywhere:!0}))};return i(`div`,{"data-testid":`my-sessions`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[i(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[u(I,{className:`h-3.5 w-3.5 text-foreground-subtle`}),u(`div`,{className:`text-xs font-semibold text-foreground`,children:`Active sessions`})]}),i(`div`,{className:`p-4 space-y-3`,children:[u(`p`,{className:`text-[11px] text-foreground-subtle`,children:`The browsers and apps signed in to your account. Signing one out ends it at once.`}),a!==null&&u(`div`,{className:`text-[11px] text-danger`,children:a}),u(re,{sessions:r.data??[],isLoading:r.isLoading,loadError:r.isError?r.error?.message??`Request failed`:null,emptyText:`No active sessions.`,onRevoke:e=>void d(e),revokingId:s.isPending?s.variables?.id??null:null}),u(`div`,{className:`flex justify-end`,children:i(`button`,{onClick:()=>void f(),disabled:l.isPending,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:[l.isPending?u(T,{className:`h-3 w-3 animate-spin`}):u(G,{className:`h-3 w-3`}),`Sign out everywhere`]})})]})]})}r();var ye={view:{icon:A,cls:`bg-foreground-subtle/15 text-foreground-subtle`},create:{icon:M,cls:`bg-primary/15 text-primary`},delete:{icon:m,cls:`bg-danger/15 text-danger`}};function be(){let{user:e,logout:t}=V();if(!e)return u(q,{children:u(`div`,{className:`text-xs text-foreground-subtle`,children:`Not signed in.`})});let n=e.isAdmin,r=e.scopes??[];return i(q,{children:[i(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3 flex items-center gap-3`,children:[u(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-full bg-primary/10 text-primary font-semibold text-base`,children:e.username.slice(0,1).toUpperCase()}),i(`div`,{className:`flex-1 min-w-0`,children:[u(`div`,{className:`text-sm font-semibold text-foreground truncate`,children:e.username}),i(`div`,{className:`text-[11px] text-foreground-subtle`,children:[n?`Administrator`:`User`,` · session id`,` `,i(`span`,{className:`font-mono`,children:[e.id.slice(0,8),`…`]})]})]})]}),n&&i(`div`,{className:`rounded-lg border border-primary/30 bg-primary/5 px-4 py-3 text-xs text-foreground flex items-start gap-2.5`,children:[u(D,{className:`h-4 w-4 text-primary mt-0.5 shrink-0`}),i(`div`,{children:[u(`div`,{className:`font-semibold text-foreground`,children:`Unrestricted access`}),u(`p`,{className:`text-foreground-subtle mt-0.5`,children:`Admin sessions bypass the per-call scope check. Every protected endpoint is reachable regardless of the list below.`})]})]}),u(xe,{}),u(Se,{username:e.username}),u(Ce,{}),u(_e,{}),u(ne,{}),u(ve,{}),u(me,{}),r.length>0&&i(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[i(`div`,{className:`px-4 py-2 border-b border-border`,children:[u(`div`,{className:`text-xs font-semibold text-foreground`,children:`Granted scopes`}),u(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Baked into your session token at login; sign out + back in to refresh after changes.`})]}),i(`div`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[u(`div`,{children:`Type`}),u(`div`,{children:`Target`}),u(`div`,{children:`Access`})]}),u(`ul`,{className:`divide-y divide-border`,children:r.map((e,t)=>i(`li`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2.5 items-center text-xs`,children:[u(`span`,{className:`font-mono text-foreground-subtle`,children:e.type}),u(`span`,{className:`font-mono text-foreground`,children:e.type===`device`?v(e.selector):e.target}),u(`div`,{className:`flex items-center gap-1`,children:[`view`,`create`,`delete`].map(t=>{let n=e.access.includes(t),{icon:r,cls:a}=ye[t];return i(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${n?a:`bg-transparent text-foreground-subtle/40 line-through`}`,title:n?`Can ${t}`:`Cannot ${t}`,children:[u(r,{className:`h-3 w-3`}),t]},t)})})]},t))})]}),u(`div`,{className:`flex justify-end`,children:i(`button`,{onClick:t,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground transition-colors`,children:[u(G,{className:`h-3 w-3`}),`Sign out`]})})]})}function xe(){let e=p(),[t,n]=c(``),[r,a]=c(``),[o,s]=c(``),[d,f]=c(null),m=l({mutationFn:t=>e.changeOwnPassword(t),onSuccess:()=>{f({kind:`success`,msg:`Password updated.`}),n(``),a(``),s(``)},onError:e=>{f({kind:`error`,msg:e instanceof Error?e.message:`Update failed`})}}),h=r.length>0&&o.length>0&&r!==o,_=r.length>0&&r.length<8,v=t.length>=1&&r.length>=8&&r===o;return i(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[i(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[u(b,{className:`h-3.5 w-3.5 text-foreground-subtle`}),u(`div`,{className:`text-xs font-semibold text-foreground`,children:`Change password`})]}),i(`div`,{className:`p-4 space-y-3`,children:[u($,{label:`Current password`,value:t,onChange:n,autoComplete:`current-password`}),u($,{label:`New password`,value:r,onChange:a,autoComplete:`new-password`,hint:`At least 8 characters.`}),u($,{label:`Confirm new password`,value:o,onChange:s,autoComplete:`new-password`}),(h||_)&&u(`div`,{className:`text-[11px] text-danger`,children:h?`Passwords do not match.`:`New password must be at least 8 characters.`}),d&&i(`div`,{className:`text-[11px] flex items-center gap-1 ${d.kind===`success`?`text-emerald-500`:`text-danger`}`,children:[d.kind===`success`?u(w,{className:`h-3 w-3`}):u(g,{className:`h-3 w-3`}),d.msg]}),u(`div`,{className:`flex justify-end`,children:i(`button`,{onClick:()=>{f(null),m.mutate({currentPassword:t,newPassword:r})},disabled:!v||m.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[m.isPending?u(T,{className:`h-3 w-3 animate-spin`}):u(E,{className:`h-3 w-3`}),`Update password`]})})]})]})}function $({label:e,value:t,onChange:n,autoComplete:r,hint:a}){return i(`div`,{className:`space-y-1`,children:[u(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e}),u(`input`,{type:`password`,value:t,onChange:e=>n(e.target.value),autoComplete:r,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),a&&u(`div`,{className:`text-[10px] text-foreground-subtle`,children:a})]})}function Se({username:e}){let t=p(),n=o({queryKey:[`auth`,`getOwnTotpStatus`],queryFn:()=>t.getOwnTotpStatus()}),r=n.data,[f,m]=c(null),[h,_]=c(``),[v,y]=c(null),[b,x]=c(!1),S=l({mutationFn:()=>t.setupOwnTotp(),onSuccess:e=>{m({secret:e.secret,otpauthUrl:e.otpauthUrl}),_(``),y(null)},onError:e=>y(e instanceof Error?e.message:`Setup failed`)}),C=l({mutationFn:e=>t.confirmOwnTotp(e),onSuccess:()=>{m(null),_(``),y(null),n.refetch()},onError:e=>y(e instanceof Error?e.message:`Confirmation failed — code did not match`)}),E=z(`Turning off two-factor authentication`),D=l({mutationFn:async()=>{let e=await E.requestProof();return e===null?null:t.disableOwnTotp({reauthToken:e})},onSuccess:()=>{y(null),n.refetch()},onError:e=>y(e instanceof Error?e.message:`Disable failed`)});d(()=>{if(!b)return;let e=setTimeout(()=>x(!1),1500);return()=>clearTimeout(e)},[b]);let O=a(()=>n.isLoading?`loading`:f?`setup_in_progress`:r?.enabled?`enrolled`:`not_enrolled`,[n.isLoading,r?.enabled,f]);return i(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[E.dialog,i(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[u(k,{className:`h-3.5 w-3.5 text-foreground-subtle`}),u(`div`,{className:`text-xs font-semibold text-foreground`,children:`Two-factor authentication`})]}),i(`div`,{className:`p-4 space-y-3`,children:[O===`loading`&&i(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[u(T,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),O===`not_enrolled`&&i(s,{children:[u(`div`,{className:`text-xs text-foreground-subtle`,children:`2FA isn't active on your account. Enable it to require a 6-digit code from your authenticator app at every login.`}),u(`div`,{className:`flex justify-end`,children:i(`button`,{onClick:()=>{y(null),S.mutate()},disabled:S.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[S.isPending?u(T,{className:`h-3 w-3 animate-spin`}):u(k,{className:`h-3 w-3`}),`Enable 2FA`]})})]}),O===`setup_in_progress`&&f&&i(s,{children:[i(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`Scan the QR code (or enter the secret manually) into your authenticator app for`,` `,u(`span`,{className:`font-mono`,children:e}),`, then enter the 6-digit code below to confirm.`]}),i(`div`,{className:`flex flex-col items-center gap-3`,children:[u(`div`,{className:`rounded-lg border border-border bg-white p-3`,children:u(oe,{value:f.otpauthUrl,size:180})}),i(`div`,{className:`w-full`,children:[u(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle mb-1`,children:`Secret (manual entry)`}),i(`div`,{className:`flex items-center gap-2 rounded border border-border bg-surface-hover/30 px-2 py-1.5`,children:[u(`code`,{className:`text-[11px] font-mono text-foreground break-all flex-1`,children:f.secret}),i(`button`,{onClick:()=>{f&&navigator.clipboard.writeText(f.secret).then(()=>x(!0))},className:`inline-flex items-center gap-1 text-[10px] text-foreground-subtle hover:text-foreground`,children:[b?u(w,{className:`h-3 w-3 text-emerald-500`}):u(j,{className:`h-3 w-3`}),b?`Copied`:`Copy`]})]})]})]}),i(`div`,{className:`space-y-1`,children:[u(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`6-digit code`}),u(`input`,{type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,placeholder:`123456`,value:h,onChange:e=>_(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full rounded-md border border-border bg-surface px-3 py-2 text-center text-lg font-mono tracking-widest text-foreground focus:outline-none focus:ring-2 focus:ring-primary`})]}),v&&i(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[u(g,{className:`h-3 w-3`}),v]}),i(`div`,{className:`flex justify-end gap-2`,children:[u(`button`,{onClick:()=>{m(null),y(null),_(``)},className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),i(`button`,{onClick:()=>{y(null),C.mutate({code:h})},disabled:C.isPending||h.length!==6,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[C.isPending?u(T,{className:`h-3 w-3 animate-spin`}):u(w,{className:`h-3 w-3`}),`Confirm`]})]})]}),O===`enrolled`&&r&&i(s,{children:[i(`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:[u(w,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),i(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[u(`div`,{className:`font-medium`,children:`2FA is active`}),i(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,r.confirmedAt?new Date(r.confirmedAt).toLocaleString():`—`]})]})]}),v&&i(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[u(g,{className:`h-3 w-3`}),v]}),u(`div`,{className:`flex justify-end`,children:i(`button`,{onClick:()=>{y(null),D.mutate()},disabled:D.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:[D.isPending?u(T,{className:`h-3 w-3 animate-spin`}):u(k,{className:`h-3 w-3`}),`Disable 2FA`]})})]})]})]})}function Ce(){return F(`auth-webauthn/passkey-enrollment`)?u(ee,{widgetId:`auth-webauthn/passkey-enrollment`,host:`dashboard`}):null}export{be as MyAccessPage};
|