@camstack/addon-admin-ui 1.2.387 → 1.2.389

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/dist/assets/{AddonAssetIcon-HvX2Jrvr.js → AddonAssetIcon-C6RFpyn9.js} +1 -1
  2. package/dist/assets/{AddonIntegrationBody-Z6od5ar6.js → AddonIntegrationBody-Bz69Wys3.js} +1 -1
  3. package/dist/assets/{Addons-BFHnQRFI.js → Addons-BPS5plEb.js} +1 -1
  4. package/dist/assets/{AdminPage-BDkIRXBS.js → AdminPage-CXLW-S6O.js} +1 -1
  5. package/dist/assets/{AdminSectionedPage-BaA4ZPOA.js → AdminSectionedPage-CzB-IV65.js} +1 -1
  6. package/dist/assets/{AiProfiles-BhMJwhZY.js → AiProfiles-CK4GSiXv.js} +1 -1
  7. package/dist/assets/{BrokerForm-D3RkMieh.js → BrokerForm-CcqnNboj.js} +1 -1
  8. package/dist/assets/{Build-1nlWh52z.js → Build-DZ-sN9T3.js} +1 -1
  9. package/dist/assets/{Calendars-CsnbL9qZ.js → Calendars-CSy4EeTY.js} +1 -1
  10. package/dist/assets/{Cluster-D7eGxsWW.js → Cluster-BxmIsg-3.js} +1 -1
  11. package/dist/assets/{ClusterStepModel-B04BNE8B.js → ClusterStepModel-Dg-XMUdq.js} +1 -1
  12. package/dist/assets/{CompositionEditor-DK6sM4hY.js → CompositionEditor-BNRcU1Rd.js} +1 -1
  13. package/dist/assets/{CompositionEditorPage-kNx6MCrI.js → CompositionEditorPage-BgAA-ipV.js} +1 -1
  14. package/dist/assets/{Data-DBZzqBKe.js → Data-X85D6e1D.js} +1 -1
  15. package/dist/assets/{DeviceDetail-GuESOZr9.js → DeviceDetail-DrdiKT5B.js} +1 -1
  16. package/dist/assets/{DeviceDoActionFields-CzyFg5ik.js → DeviceDoActionFields-DI8z_umk.js} +1 -1
  17. package/dist/assets/{Devices-CvXnKn-3.js → Devices-DLgkEh-d.js} +1 -1
  18. package/dist/assets/{EmbedPlayerPage-VOyr_wAQ.js → EmbedPlayerPage-Dh9ServI.js} +1 -1
  19. package/dist/assets/{Identity-DAig6KlS.js → Identity-BSvFEJF9.js} +1 -1
  20. package/dist/assets/{IntegrationDetail-D24QZIuN.js → IntegrationDetail-VEqENras.js} +1 -1
  21. package/dist/assets/{Integrations-CGrvamkV.js → Integrations-CNfIrinR.js} +1 -1
  22. package/dist/assets/{Integrations-C-TN4l5Y.js → Integrations-obDp7lUH.js} +1 -1
  23. package/dist/assets/{Library-1xvqTYYo.js → Library-tEQh3vju.js} +1 -1
  24. package/dist/assets/{Locations-B-0sD50Y.js → Locations-DMU97LDi.js} +1 -1
  25. package/dist/assets/{Logs-DrXgkU6k.js → Logs-ChpqdClJ.js} +1 -1
  26. package/dist/assets/{MotionZonesSettings-DQjbL4C6.js → MotionZonesSettings-BJxn277T.js} +1 -1
  27. package/dist/assets/{MyAccess-sHJZTGoi.js → MyAccess-DJ5Ix4Ax.js} +1 -1
  28. package/dist/assets/{Network-DSi3AudF.js → Network-p74ArQ7j.js} +1 -1
  29. package/dist/assets/{NodeAddonsSettingsPanel-C7wY3WPr.js → NodeAddonsSettingsPanel-6nVZk8B5.js} +1 -1
  30. package/dist/assets/{Notifications-DmrCggWz.js → Notifications-Or7Vk4qW.js} +1 -1
  31. package/dist/assets/{PrivacyMaskSettings-C57Avbio.js → PrivacyMaskSettings-BZ0ABTEX.js} +1 -1
  32. package/dist/assets/{Recordings-TeWniPr_.js → Recordings-DF6uCe7E.js} +1 -1
  33. package/dist/assets/{ScanNetworkModal-682GpB69.js → ScanNetworkModal-BHM4kv3g.js} +1 -1
  34. package/dist/assets/{SceneMonitorEditor-CIEBYXt8.js → SceneMonitorEditor-CYxRGm5O.js} +1 -1
  35. package/dist/assets/{SessionsList-lcg-Rfeb.js → SessionsList-CIZfyFLs.js} +1 -1
  36. package/dist/assets/{Showroom-CGKrpUYV.js → Showroom-CPm8XMrq.js} +1 -1
  37. package/dist/assets/{System-CU3RTrHe.js → System-i1sKeQF5.js} +1 -1
  38. package/dist/assets/{Terminal-CERM0Z7B.js → Terminal-mm-7YOUn.js} +1 -1
  39. package/dist/assets/{Viewer-BSaDYkQB.js → Viewer-kxpWKO7k.js} +1 -1
  40. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-C5m_IDMd.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Xcvpt4sc.js} +1 -1
  41. package/dist/assets/{archive-BDaYzDmX.js → archive-9DBIqUqr.js} +1 -1
  42. package/dist/assets/{authed-media-CGkdrlUT.js → authed-media-IYIQhfkg.js} +1 -1
  43. package/dist/assets/{boxes-DVhyY4Aj.js → boxes-CMaukUe8.js} +1 -1
  44. package/dist/assets/circle-slash-Cf56abhI.js +1 -0
  45. package/dist/assets/{client-D7C4n8lL.js → client-DUrWDWpW.js} +4 -4
  46. package/dist/assets/crop-S5Otyn58.js +1 -0
  47. package/dist/assets/{device-integration-icon-DV5lR5V4.js → device-integration-icon-x7RZ4Ehn.js} +1 -1
  48. package/dist/assets/device-picker-model-DQO4HeHC.js +1 -0
  49. package/dist/assets/{dist-Bk8bRPUC.js → dist-CDuNH5BU.js} +1 -1
  50. package/dist/assets/dist-yYJRijTU.js +357 -0
  51. package/dist/assets/{format-size-BLzS9JhL.js → format-size-D5aCy0Fg.js} +1 -1
  52. package/dist/assets/{history-sb4-QquS.js → history-DLbj1ReB.js} +1 -1
  53. package/dist/assets/{hostInit-3ag8feXx.js → hostInit-C5sBPmUi.js} +1 -1
  54. package/dist/assets/{index-BURcka-4.js → index-CCv7bUCn.js} +3 -3
  55. package/dist/assets/{layers-BL4e_X0k.js → layers-CC6cFDmm.js} +1 -1
  56. package/dist/assets/{location-owned-usage-D7og8Vbk.js → location-owned-usage-UNNoE6sc.js} +1 -1
  57. package/dist/assets/{mf-entry-bootstrap-0-230dd85b.js → mf-entry-bootstrap-0-cb8b0381.js} +2 -2
  58. package/dist/assets/{monitor-smartphone-Df4EIkBh.js → monitor-smartphone-CKSor6O7.js} +1 -1
  59. package/dist/assets/mount-DQO4HeHC.js +1 -0
  60. package/dist/assets/{notification-schedule-field-m8a8MJDd.js → notification-schedule-field-DeU2sP3f.js} +1 -1
  61. package/dist/assets/{octagon-alert-M7nQcsem.js → octagon-alert-DfCNk_VB.js} +1 -1
  62. package/dist/assets/{player-overlays-DJRuofy-.js → player-overlays-7BNWOeGN.js} +1 -1
  63. package/dist/assets/remoteEntry-BvmC-8wj.js +1 -0
  64. package/dist/assets/{send-CuABkX_U.js → send-DNLZf3l4.js} +1 -1
  65. package/dist/assets/{settings-2-D25S2TNc.js → settings-2-30FLZdsR.js} +1 -1
  66. package/dist/assets/{src-CmZyEJNe.js → src-qXivmhEc.js} +3 -3
  67. package/dist/assets/{use-scenes-feed-II69Smgj.js → use-scenes-feed-BNE-RXaC.js} +1 -1
  68. package/dist/assets/{use-stationary-objects-MXCyLLfn.js → use-stationary-objects-GK_6Bh_H.js} +1 -1
  69. package/dist/assets/useEventInvalidation-DQO4HeHC.js +1 -0
  70. package/dist/assets/{useNodeUrlSelection-DVDvba57.js → useNodeUrlSelection-COamsto7.js} +1 -1
  71. package/dist/assets/user-round-CG9QAcI5.js +1 -0
  72. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-D6tZ5Yp6.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BRwcuf11.js} +2 -2
  73. package/dist/index.html +7 -7
  74. package/dist/server/addon.js +47 -2
  75. package/package.json +1 -1
  76. package/dist/assets/circle-slash-CafgXSEr.js +0 -1
  77. package/dist/assets/crop-Dq68jz-v.js +0 -1
  78. package/dist/assets/device-picker-model-Gvesu9qA.js +0 -1
  79. package/dist/assets/dist-DCvvyhde.js +0 -357
  80. package/dist/assets/mount-Gvesu9qA.js +0 -1
  81. package/dist/assets/remoteEntry-rAKSCwO7.js +0 -1
  82. package/dist/assets/useEventInvalidation-Gvesu9qA.js +0 -1
  83. package/dist/assets/user-round-CypDeZjR.js +0 -1
@@ -1 +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,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,ct as u,gt as d,ot as f,yt as p}from"./player-overlays-DJRuofy-.js";import{Ad as m,Al as h,An as g,Bl as _,Bu as v,Cd as ee,Cu as y,Dd as b,Dl as x,Fl as S,Fn as C,Ft as w,G as T,Gn as E,Hl as D,Hn as te,Ht as O,Il as k,In as A,Ju as ne,Ku as j,L as re,Ll as M,Ml as N,Mn as P,Mr as F,N as I,Nl as ie,Ol as ae,P as L,Pl as oe,Pn as R,Qu as se,Rl as ce,Td as z,Un as le,Vl as ue,Wd as de,Wn as fe,X as pe,Z as me,Zl as he,dn as B,du as V,jd as H,jl as ge,jn as U,jr as _e,kd as ve,kl as ye,nr as W,pd as be,pu as xe,ql as Se,qu as G,rr as Ce,sf as we,ud as Te,ur as Ee,va as De,z as Oe,zl as ke}from"./src-CmZyEJNe.js";import{t as Ae}from"./history-sb4-QquS.js";import{t as je}from"./monitor-smartphone-Df4EIkBh.js";import{_ as K,a as Me,b as Ne,c as Pe,d as Fe,f as Ie,g as Le,h as q,i as Re,l as ze,m as Be,n as Ve,o as He,p as Ue,s as We,t as Ge,u as Ke,v as J,y as qe}from"./SessionsList-lcg-Rfeb.js";import{a as Je,i as Ye,o as Xe,s as Ze}from"./client-D7C4n8lL.js";import{t as Qe}from"./useTranslation-Bc5yH9V9.js";import{$ as $e,C as et,R as Y,X as tt,Y as nt,at as rt,c as it,p as at,rt as ot,s as st,tt as ct}from"./index-BURcka-4.js";import{t as lt}from"./AdminSectionedPage-BaA4ZPOA.js";import{t as ut}from"./AdminPage-BDkIRXBS.js";import{n as dt,r as ft,t as pt}from"./AddonIntegrationBody-Z6od5ar6.js";import{n as mt,t as ht}from"./addon-display-names-BkwMrExv.js";var gt=p(`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`}]]),_t=p(`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 vt(){let e=W(),t=V.useUtils(),r=qe(),{data:i,isLoading:a}=S(),c=n(()=>i??[],[i]),l=V.useQueries(e=>c.map(t=>e.userManagement.listExternalIdentities({userId:t.id}))),u=V.auth.listLoginMethods.useQuery(),[d,f]=o(null),p=ue({onSuccess:()=>void t.userManagement.listExternalIdentities.invalidate(),onError:e=>f(`Remove failed: ${e.message}`)}),m=n(()=>new Map((u.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),[u.data]),h=c.flatMap((e,t)=>l[t]?.data??[]),g=h.map(e=>({...Fe(e,r),kind:m.get(e.provider)??e.provider})),_=async t=>{let n=h.find(e=>Ke(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),p.mutate({userId:n.userId,provider:n.provider,subject:n.subject}))};return s(K,{notice:J(d),onDismissNotice:()=>{f(null)},id:`external-identities`,title:`Sign-in links`,icon:rt,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(q,{rows:g,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:Ne,isAvailable:()=>!0,onRun:e=>void _(e),busyId:null,disabled:p.isPending}})})}e();function yt(){let e=W(),t=a(),r=qe(),i=N(),[c,l]=o(null),d=M({onSuccess:()=>void t.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),onError:e=>l(`Revoke failed: ${e.message}`)}),f=n(()=>(i.data??[]).map(e=>ze(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),d.mutate({id:t.id}))};return s(K,{notice:J(c),onDismissNotice:()=>{l(null)},id:`legacy-api-keys`,title:`Legacy API keys`,icon:Ae,description:`Keys from before scoped tokens. Nothing creates them any more; revoke them and issue a scoped token instead.`,children:s(q,{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:u,isAvailable:()=>!0,onRun:e=>void p(e),busyId:d.isPending?d.variables?.id??null:null,disabled:d.isPending}})})}e();function bt(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 xt(){let e=W(),t=a(),r=oe(),[i,c]=o(null),l=ce({onSuccess:()=>void t.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]}),onError:e=>c(`Revoke failed: ${e.message}`)}),d=n(()=>(r.data??[]).map(e=>Ie(e,e.scopes.map(bt).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(K,{notice:J(i),onDismissNotice:()=>{c(null)},id:`linked-apps`,title:`Linked apps`,icon:b,description:`External integrations (Alexa, …) linked to this hub through OAuth. Revoking one stops that integration on its next call.`,children:s(q,{rows:d,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:u,isAvailable:e=>e.status===`active`,onRun:e=>void f(e),busyId:p,disabled:l.isPending}})})}e();var St={one:`session`,many:`sessions`};function Ct(){let e=W(),t=V.useUtils(),r=qe(),i=V.auth.listSessions.useQuery(),[a,c]=o(null),l=()=>void t.auth.listSessions.invalidate(),u=V.auth.revokeSessions.useMutation({onSuccess:l,onError:e=>c(`Sign out failed: ${e.message}`)}),d=Le(`login-session`,St,l),f=n(()=>(i.data??[]).map(e=>Ue(e,r,{client:e=>Me(e).label,method:He})),[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(K,{notice:J(a,d.outcome),onDismissNotice:()=>{c(null),d.dismiss()},id:`login-sessions`,title:`Login sessions`,icon:je,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(q,{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:ct,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:St,isSelectable:e=>e.status===`active`}})})}e();function wt({open:e,users:n,onClose:r,onSubmit:i,submitting:a}){let{user:c}=Y(),l=c?.isAdmin===!0?null:c?.scopes??[],[u,d]=o(n[0]?.id??``),[f,p]=o(``),[m,h]=o([{type:`capability`,target:``,access:[`view`,`create`]}]),[g,_]=o(``),v=L(m);return s(Oe,{open:e,onClose:r,title:`Create scoped token`,icon:j,width:`md`,testId:`create-scoped-token-dialog`,footer:t(E,{type:`button`,variant:`primary`,size:`sm`,onClick:()=>{let e=parseInt(g,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;i({userId:u,name:f.trim(),scopes:m,expiresAt:t})},disabled:!(u!==``&&f.trim().length>0&&m.length>0&&v===null&&!a),children:[a?s(z,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}):s(j,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),`Issue token`]}),children:t(`div`,{className:`space-y-3`,children:[t(`div`,{className:`space-y-1`,children:[s(B,{htmlFor:`scoped-token-user`,children:`On behalf of user`}),s(fe,{id:`scoped-token-user`,value:u,onChange:e=>d(e.target.value),options:n.map(e=>({value:e.id,label:e.username}))})]}),s(T,{label:`Name`,required:!0,children:s(he,{id:`scoped-token-name`,value:f,onChange:e=>p(e.target.value),placeholder:`cloudflare-tunnel-route`,autoFocus:!0})}),t(`div`,{className:`space-y-1`,children:[s(B,{children:`Scopes`}),s(I,{value:m,onChange:h,clampToParent:l}),v&&s(`p`,{className:`text-[10px] text-danger`,children:v}),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(B,{htmlFor:`scoped-token-days`,children:`Expires in (days)`}),s(he,{id:`scoped-token-days`,type:`number`,min:1,value:g,onChange:e=>_(e.target.value),placeholder:`30`}),s(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Leave blank for non-expiring.`})]})]})})}var Tt={scoped:`newScoped`,admin:`newAdmin`};function Et({token:e,label:n,onClose:r}){return s(g,{open:!0,onOpenChange:e=>!e&&r(),children:t(P,{width:`md`,scroll:`body`,children:[s(C,{children:s(A,{children:`Token: ${n}`})}),t(U,{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(R,{children:[s(w,{value:e,label:`Copy`,srLabel:`token`}),s(E,{type:`button`,variant:`primary`,size:`sm`,onClick:r,children:`Done`})]})]})})}e();function Dt(e){return e.type===`device`?`device:[${me(e.selector)}]`:`${e.type}:${e.target??``}`}function Ot(){let e=W(),r=a(),i=qe(),{data:c,isLoading:l}=S(),d=n(()=>c??[],[c]),f=V.useQueries(e=>d.map(t=>e.userManagement.listScopedTokens({userId:t.id}))),[p,h]=o(null),[g,_]=o(null),{state:v,openNew:ee,close:y}=re({newKey:Tt.scoped}),b=()=>void r.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),C=x({onSuccess:({token:e,record:t})=>{b(),y(),_({token:e,label:t.name})},onError:e=>h(`Create failed: ${e.message}`)}),w=ke({onSuccess:b,onError:e=>h(`Revoke failed: ${e.message}`)}),T=Date.now(),D=d.flatMap((e,t)=>(f[t]?.data??[]).map(t=>Be(t,e.id,i,t.scopes.map(Dt).join(`, `),T))),te=f.find(e=>e.isError)?.error?.message??null,O=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),w.mutate({id:t.id}))};return t(K,{notice:J(p),onDismissNotice:()=>{h(null)},id:`scoped-tokens`,title:`Scoped tokens`,icon:m,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(E,{type:`button`,variant:`primary`,size:`sm`,onClick:ee,disabled:d.length===0,title:d.length===0?`Create a user first`:`Issue a scoped token`,children:[s(j,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),`New token`]}),children:[s(q,{rows:D,label:`scoped tokens`,isLoading:l||f.some(e=>e.isLoading),loadError:te,emptyText:`No scoped tokens.`,action:{label:`Revoke`,icon:u,isAvailable:()=>!0,onRun:e=>void O(e),busyId:w.isPending?w.variables?.id??null:null,disabled:w.isPending}}),s(wt,{open:v.mode===`new`,users:d.map(e=>({id:e.id,username:e.username})),onClose:y,onSubmit:e=>C.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:C.isPending}),g!==null&&s(Et,{token:g.token,label:g.label,onClose:()=>_(null)})]})}e();var kt={one:`admin token`,many:`admin tokens`},At=7,jt=90,Mt=80;function Nt(e){let t=Number(e);return Number.isInteger(t)&&t>=1&&t<=jt?t:null}function Pt(){let{user:e}=Y();return e?.isAdmin?s(Ft,{}):null}function Ft(){let e=W(),r=V.useUtils(),i=V.auth.listAdminTokens.useQuery(),a=qe(),{requestProof:l,dialog:d}=Re(`Creating an admin token`),{state:f,openNew:p,close:m}=re({newKey:Tt.admin}),[h,g]=o(``),[_,v]=o(String(At)),[ee,y]=o(null),[b,x]=o(null),[S,C]=o(!1),[w,T]=o(null),D=()=>{r.auth.listAdminTokens.invalidate(),r.auth.listAuthAudit.invalidate()},te=V.auth.createAdminToken.useMutation({onSuccess:({token:e,record:t})=>{D(),g(``),v(String(At)),x(null),m(),T({token:e,label:t.name})},onError:e=>{y(`Create failed: ${e.message}`),x(`Create failed: ${e.message}`)}}),O=V.auth.revokeAdminToken.useMutation({onSuccess:D,onError:e=>y(`Revoke failed: ${e.message}`)}),k=Le(`admin-token`,kt,D);c(()=>{f.mode===`closed`&&(g(``),v(String(At)),x(null),C(!1))},[f.mode]);let A=Date.now(),ne=n(()=>(i.data??[]).map(e=>Pe(e,a,A)),[i.data,a]),j=h.trim(),M=Nt(_),N=j.length>0&&j.length<=Mt&&M!==null&&!te.isPending&&!S,P=async()=>{if(!N||M===null)return;y(null),x(null),C(!0);let e=await l();C(!1),e!==null&&te.mutate({name:j,expiresInDays:M,reauthToken:e})},F=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`})&&(y(null),O.mutate({id:t.id}))};return t(`div`,{"data-testid":`admin-tokens`,children:[d,s(K,{id:`admin-tokens`,title:`Admin tokens`,icon:G,tone:`danger`,notice:J(ee,k.outcome),onDismissNotice:()=>{y(null),k.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.`})]}),actions:t(E,{type:`button`,variant:`danger`,size:`sm`,onClick:p,children:[s(G,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),`New admin token`]}),children:s(q,{rows:ne,label:`admin tokens`,isLoading:i.isLoading,loadError:i.isError?i.error?.message??`Request failed`:null,emptyText:`No admin tokens.`,action:{label:`Revoke`,icon:u,isAvailable:e=>e.status===`active`,onRun:e=>void F(e),busyId:O.isPending?O.variables?.id??null:null,disabled:O.isPending||k.busy},bulk:{revoke:k,noun:kt,isSelectable:e=>e.status===`active`}})}),s(Oe,{open:f.mode===`new`,onClose:m,title:`Create admin token`,icon:G,error:b,width:`md`,testId:`admin-token-form-dialog`,footer:t(E,{type:`button`,variant:`danger`,size:`sm`,disabled:!N,onClick:()=>void P(),children:[te.isPending||S?s(z,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}):s(G,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),`Create admin token`]}),children:t(`div`,{className:`space-y-3`,children:[t(`div`,{className:`space-y-1`,children:[s(B,{htmlFor:`admin-token-name`,children:`Token name`}),s(he,{id:`admin-token-name`,value:h,maxLength:Mt,onChange:e=>g(e.target.value),placeholder:`nightly-backup`,autoFocus:!0})]}),t(`div`,{className:`space-y-1`,children:[s(B,{htmlFor:`admin-token-days`,children:`Expires in (days)`}),s(he,{id:`admin-token-days`,type:`number`,min:1,max:jt,value:_,onChange:e=>v(e.target.value),state:M===null?`error`:`default`}),M===null?t(`p`,{className:`text-[11px] text-danger`,children:[`Expiry must be a whole number of days, 1 to `,jt,`.`]}):t(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Whole number of days, 1 to `,jt,`.`]})]})]})}),w&&s(Et,{token:w.token,label:w.label,onClose:()=>T(null)})]})}var It={"share-link":`share links`,"admin-token":`admin tokens`,"login-session":`login sessions`};function X(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function Lt(e,t){let n=X(e,`tokenId`);return X(e,`name`)??(n===null?void 0:t.get(n))??n??`?`}function Rt(e){return e.filter(e=>e!==null)}function zt(e){let t=X(e,`prefix`);return t===null?null:`Prefix ${t}…`}function Bt(e,t){let n=e.detail??{};switch(e.action){case`admin-token-created`:{let e=n.expiresAt;return{title:`Admin token "${Lt(n,t)}" created`,details:Rt([zt(n),typeof e==`number`?`Expires ${We(e)}`:null])}}case`admin-token-used`:{let e=X(n,`path`);return{title:`Admin token "${Lt(n,t)}" used`,details:Rt([zt(n),e===null?null:`Call ${e}`])}}case`admin-token-revoked`:return{title:`Admin token "${Lt(n,t)}" revoked`,details:Rt([zt(n)])};case`credentials-revoked`:{let e=X(n,`kind`)??`credential`,t=n.revoked,r=n.skipped,i=It[e]??`${e}s`;return{title:`${typeof t==`number`?String(t):`?`} ${i} revoked in bulk`,details:Rt([typeof r==`number`&&r>0?`${String(r)} skipped`:null,X(n,`ids`)===null?null:`Ids ${X(n,`ids`)??``}`])}}case`second-factor-skipped`:{let e=X(n,`method`),t=X(n,`factors`);return{title:`Second factor skipped on a trusted network`,details:Rt([e===null?null:`Signed in with ${He(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 Vt=100;function Ht(){let{user:e}=Y();return e?.isAdmin?s(Wt,{}):null}function Ut(){let{data:e}=S(),{data:t}=V.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 Wt(){let e=V.auth.listAuthAudit.useQuery({limit:Vt}),{userNameById:n,tokenNameById:r}=Ut(),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(se,{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 `,Vt,`, 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(z,{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(Gt,{record:e,userName:e.userId===void 0?null:n.get(e.userId)??e.userId,tokenNameById:r},e.id))})})]})}function Gt({record:e,userName:n,tokenNameById:r}){let i=Bt(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:We(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`},Kt={state:`ok`,stateLabel:`available`,showState:!1};function Q(e,t,n,r){return{id:e,name:t,fallbackIcon:n,...Kt,render:r}}function qt(){let e=N(),t=(e.data??[]).length>0;return s(ft,{embedded:!0,icon:_t,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`,je,()=>s(Ct,{})),Q(Z.linkedApps,`Linked apps`,b,()=>s(xt,{}))]},{id:`tokens`,label:`Tokens`,entries:[Q(Z.scopedTokens,`Scoped tokens`,m,()=>s(Ot,{})),Q(Z.adminTokens,`Admin tokens`,G,()=>s(Pt,{})),Q(Z.shareLinks,`Share links`,ne,()=>s(Ve,{})),...t?[Q(Z.legacyApiKeys,`Legacy API keys`,Ae,()=>s(yt,{}))]:[]]},{id:`identity`,label:`Identity`,entries:[Q(Z.externalIdentities,`Sign-in links`,rt,()=>s(vt,{})),Q(Z.audit,`Audit`,se,()=>s(Ht,{}))]}],isLoading:e.isLoading,emptyTitle:`No credential kinds`,emptyDescription:`This hub offers no credential kinds.`})}e();var Jt=3e4,Yt=[{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 Xt(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:_t,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:ot,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:ot,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:v,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:v,bullets:[`Time-based codes from an authenticator app (RFC 6238).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:j,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Zt(){let e=F({capName:Yt[0].capName},{refetchInterval:Jt}),t=F({capName:Yt[1].capName},{refetchInterval:Jt}),r=_e(void 0,{refetchInterval:Jt}),i=n(()=>ht(r.data??[]),[r.data]),a=n(()=>{let n=[],r=[e.data??[],t.data??[]];for(let[e,t]of Yt.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:Yt[0].capName,label:$.installLabel},entries:a.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:j,...mt(e.isActive),render:()=>s(pt,{addonId:e.addonId,displayName:e.displayName,capName:e.capName,isActive:e.isActive,badges:e.stageBadge===null?null:s(Ee,{variant:`info`,className:dt,children:e.stageBadge}),panels:[{id:`about`,title:`About`,icon:Xt(e.addonId).icon,content:s(Qt,{addonId:e.addonId})}]})}))}];return s(ft,{embedded:!0,icon:j,title:$.title,subtitle:$.subtitle,groups:o,isLoading:e.isLoading||t.isLoading,emptyTitle:$.emptyTitle,emptyDescription:$.emptyDescription})}function Qt({addonId:e}){let n=Xt(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(gt,{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(H,{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(nt,{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(nt,{to:`/system/identity?tab=users`,className:`underline text-primary`,children:`Users`}),` `,`page via Actions → “Remove 2FA”.`]})]})]})}function $t({userId:e,username:n,onClose:r}){let i=W(),a=V.useUtils(),o=ie({userId:e}),c=V.auth.listLoginMethods.useQuery(),l=ue({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(g,{open:!0,onOpenChange:e=>!e&&r(),children:t(P,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`external-identities-modal`,children:[s(C,{children:t(A,{className:`flex items-center gap-2`,children:[s(b,{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(U,{className:`space-y-3`,children:o.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(z,{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(Ne,{className:`h-3 w-3`}),`Remove`]})]},`${e.provider}|${e.subject}`)})})}),s(R,{children:s(E,{onClick:r,variant:`secondary`,children:`Close`})})]})})}function en({userId:e,username:n,onClose:r}){let o=a(),c=W(),l=ge({userId:e}),u=l.data,d=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),f=h({onSuccess:()=>{d(),r()}}),p=l.isLoading?`loading`:u?.enabled?`enrolled`:`not_enrolled`;return s(g,{open:!0,onOpenChange:e=>!e&&r(),children:t(P,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[s(C,{children:t(A,{className:`flex items-center gap-2`,children:[s(v,{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(U,{className:`space-y-4`,children:[p===`loading`&&t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(z,{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(H,{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(we,{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(E,{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(z,{className:`h-3 w-3 animate-spin`}):s(xe,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}e();function tn({userId:e,username:n,onClose:r}){let{user:i,logout:a}=Y(),c=i?.id===e,l=W(),u=V.useUtils(),d=V.auth.listSessions.useQuery({userId:e}),[f,p]=o(null),m=V.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}`)}),h=async e=>{await l({title:`Sign out this session`,message:`"${n}" on ${Me(e.client).label} will have to sign in again.`,confirmLabel:`Sign out`,variant:`danger`})&&(p(null),m.mutate({id:e.id}))},_=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),m.mutate({userId:e}))},v=m.isPending&&m.variables!==void 0&&`id`in m.variables?m.variables.id:null;return s(g,{open:!0,onOpenChange:e=>!e&&r(),children:t(P,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`user-sessions-modal`,children:[s(C,{children:t(A,{className:`flex items-center gap-2`,children:[s(je,{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(U,{className:`space-y-3`,children:[f!==null&&s(`div`,{className:`text-[11px] text-danger`,children:f}),s(Ge,{sessions:d.data??[],isLoading:d.isLoading,loadError:d.isError?d.error?.message??`Request failed`:null,emptyText:`No active sessions.`,onRevoke:e=>void h(e),revokingId:v})]}),t(R,{className:`justify-between`,children:[t(`button`,{onClick:()=>void _(),disabled:m.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:[m.isPending&&v===null?s(z,{className:`h-3 w-3 animate-spin`}):s(ct,{className:`h-3 w-3`}),`Sign out everywhere`]}),s(E,{onClick:r,variant:`secondary`,children:`Close`})]})]})})}function nn({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 rn({scopes:e,isAdmin:n,invalidReason:a}){let o=f(),c=r({queryKey:[`auth`,`previewScope`,e,n],enabled:a===null,queryFn:()=>o.trpcClient.auth.previewScope.query({scopes:[...e],isAdmin:n})}),{data:l}=De({projection:`slim`}),d=l?.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(G,{className:`h-3 w-3 shrink-0`}),a]})});if(c.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(z,{className:`h-3 w-3 animate-spin`}),`Resolving…`]});if(c.isError||!c.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=c.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(nn,{icon:de,label:`Devices they can see`,count:p.device.view.deviceCount,all:p.device.view.all,total:d}),s(nn,{icon:be,label:`Devices they can operate`,count:p.device.create.deviceCount,all:p.device.create.all,total:d}),s(nn,{icon:u,label:`Devices they can delete`,count:p.device.delete.deviceCount,all:p.device.delete.all,total:d}),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 an(e){let t=Xe(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 on(e){return e.mode===`advanced`?e.advancedScopes:e.roleId===null?[]:Je({roleId:e.roleId,selector:e.selector,includeLinked:e.includeLinked})}function sn({user:e,onClose:r,onSubmit:a,submitting:c,callerScopes:u}){let f=n(()=>an(e.scopes??[]),[e.scopes]),[p,m]=o(f),[h,_]=o(f.mode===`advanced`),v=n(()=>on(p),[p]),ee=!e.isAdmin&&p.mode===`role`&&p.roleId===null,y=n(()=>e.isAdmin?null:p.mode===`role`&&p.roleId===null?`Pick what this user can do to see the result.`:L(v),[e.isAdmin,p.mode,p.roleId,v]),b=e=>m({...p,...e});return s(g,{open:!0,onOpenChange:e=>!e&&r(),children:t(P,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-2xl`,children:[t(C,{children:[t(A,{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(U,{className:`space-y-4`,children:[ee&&t(`div`,{className:`flex items-start gap-2 rounded-lg border border-warning/40 bg-warning/10 p-3`,children:[s(G,{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:Ye.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:()=>b({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(!h){m({...p,mode:`advanced`,advancedScopes:v}),_(!0);return}_(!1),m(an(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(h?l:d,{className:`h-3 w-3`}),`Advanced — edit raw grants`]}),h&&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(I,{value:p.advancedScopes,onChange:e=>b({mode:`advanced`,advancedScopes:e}),clampToParent:u,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(pe,{value:p.selector,onChange:e=>b({selector:e}),includeLinked:p.includeLinked,onIncludeLinkedChange:e=>b({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(rn,{scopes:v,isAdmin:e.isAdmin,invalidReason:y})]})]}),t(R,{children:[s(E,{variant:`outline`,size:`sm`,onClick:r,children:`Cancel`}),s(E,{size:`sm`,onClick:()=>a([...v]),disabled:c||y!==null,children:c?s(z,{className:`h-3 w-3 animate-spin`}):`Save access`})]})]})})}e();var cn=8;function ln(){return{username:``,password:``,isAdmin:!1}}function un(e){return{id:e.id,username:e.username,password:``,isAdmin:e.isAdmin}}function dn(e){return e instanceof Error?e.message:`Something went wrong`}function fn(){let e=a(),{user:n}=Y(),{state:r,openNew:l,openEdit:d,close:f}=re(),[p,m]=o(null),[h,g]=o(null),[ee,x]=o(!1),{data:C,isLoading:w,isError:A,error:ne,refetch:M}=S(),N=W(),P=Ce(),F=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),I=ae(),ie=ye({onSuccess:F}),L=D({onSuccess:F}),oe=k({onSuccess:F}),R=_({onSuccess:()=>{F(),ce(null)}}),[se,ce]=o(null),[ue,de]=o(null),[fe,pe]=o(null),[me,B]=o(null),V=C??[],H=r.mode===`edit`?V.find(e=>e.id===r.id)??null:null,ge=()=>{m(null),g(null),x(!1),I.reset(),L.reset(),f()};c(()=>{if(r.mode===`closed`){m(null),g(null),x(!1);return}if(r.mode===`new`){m(e=>e!==null&&e.id===void 0?e:ln());return}if(H===null){w||f();return}m(e=>e?.id===H.id?e:un(H))},[r,H,w,f]);let U=r.mode===`new`&&p!==null&&p.id===void 0||r.mode===`edit`&&p!==null&&H!==null;async function _e(e){await N({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`})&&(ie.mutate({id:e.id}),r.mode===`edit`&&r.id===e.id&&ge())}async function xe(e){let t=await P({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<cn?`Password must be at least ${String(cn)} characters.`:null});t===null||t.length===0||await N({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&oe.mutate({id:e.id,newPassword:t})}function G(e,t){t!==e.isAdmin&&L.mutate({id:e.id,isAdmin:t})}async function we(){if(p!==null){g(null);try{if(p.id===void 0){let e=p.username.trim();if(e===``||p.password.length<cn)return;await I.mutateAsync({username:e,password:p.password,isAdmin:p.isAdmin})}else await L.mutateAsync({id:p.id,isAdmin:p.isAdmin});F(),ge()}catch(e){g(dn(e))}}}function Ee(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}let De=I.isPending||L.isPending,ke=p!==null&&p.id===void 0&&p.username.trim()!==``&&p.password.length>=cn,Ae=p!==null&&p.id!==void 0,K=De||(p?.id===void 0?!ke:!Ae),Me=e=>ie.isPending&&ie.variables?.id===e.id||L.isPending&&L.variables?.id===e.id||oe.isPending&&oe.variables?.id===e.id;return t(ut,{embedded:!0,icon:y,title:`Users`,subtitle:`Hub accounts, admin flag, access scopes, sessions and sign-in links.`,actions:t(E,{size:`sm`,type:`button`,onClick:()=>{g(null),l()},children:[s(Te,{className:`h-3.5 w-3.5`}),`Create User`]}),children:[A&&s(te,{title:`Could not load users`,message:dn(ne),onRetry:()=>void M()}),w&&t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(z,{className:`h-3.5 w-3.5 animate-spin`}),`Loading…`]}),!w&&!A&&V.length===0&&s(le,{icon:y,title:`No users yet`,description:`Create a user to grant hub access.`}),!w&&!A&&V.length>0&&s(O,{columns:[{key:`username`,header:`Username`,sortValue:e=>e.username,render:e=>s(`span`,{className:`font-medium text-foreground`,"data-testid":`user-open-${e.id}`,children:e.username})},{key:`isAdmin`,header:`Admin`,nowrap:!0,sortValue:e=>+!!e.isAdmin,render:e=>s(`span`,{onClick:e=>e.stopPropagation(),children:t(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:e.isAdmin,onChange:t=>G(e,t.target.checked),disabled:Me(e),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),s(`span`,{className:e.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:e.isAdmin?`Admin`:`Regular`})]})})},{key:`scopes`,header:`Access`,render:e=>e.isAdmin?s(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:`everything (admin)`}):s(`span`,{onClick:e=>e.stopPropagation(),children:t(E,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>ce(e),title:`Configure access`,children:[s(j,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(pn,{scopes:e.scopes??[]})]})})},{key:`createdAt`,header:`Created`,nowrap:!0,sortValue:e=>e.createdAt,render:e=>s(`span`,{className:`text-foreground-subtle`,children:Ee(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,nowrap:!0,notSortableReason:`Row actions`,render:e=>{let r=Me(e),i=e.id!==n?.id&&e.totpEnabled;return t(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[t(E,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>d(e.id),disabled:r,title:`Edit user`,children:[s(be,{className:`h-3 w-3`}),`Edit`]}),i&&t(E,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>de(e),disabled:r,title:`Remove two-factor authentication`,children:[s(v,{className:`h-3 w-3`}),`Remove 2FA`]}),t(E,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>pe(e),disabled:r,title:`Linked sign-in accounts`,children:[s(b,{className:`h-3 w-3`}),`Sign-in links`]}),t(E,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>B(e),disabled:r,title:`Active sessions`,children:[s(je,{className:`h-3 w-3`}),`Sessions`]}),t(E,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void xe(e),disabled:r,title:`Reset password`,children:[s(ve,{className:`h-3 w-3`}),`Reset password`]}),t(E,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void _e(e),disabled:r,title:`Delete user`,className:`text-danger hover:bg-danger/10`,children:[r?s(z,{className:`h-3 w-3 animate-spin`}):s(u,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:V,rowKey:e=>e.id,minWidthPx:560,maxBodyHeight:`max-h-[60vh]`,mobileMode:`scroll`,onRowClick:e=>d(e.id)}),s(Oe,{open:U,onClose:ge,title:p?.id===void 0?`Create User`:`Edit ${p.username||`user`}`,icon:y,error:h,testId:`user-form-dialog`,footer:s(E,{size:`sm`,type:`button`,disabled:K,onClick:()=>void we(),children:De?t(i,{children:[s(z,{className:`h-3.5 w-3.5 animate-spin`}),`Saving…`]}):p?.id===void 0?`Create`:`Save`}),children:p!==null&&t(`div`,{className:`space-y-3`,children:[s(T,{label:`Username`,required:p.id===void 0,children:s(he,{value:p.username,onChange:e=>m({...p,username:e.target.value}),placeholder:`john`,autoFocus:p.id===void 0,disabled:p.id!==void 0,"data-testid":`user-form-username`})}),p.id===void 0&&s(T,{label:`Password`,required:!0,description:`At least ${String(cn)} characters.`,children:s(Se,{value:p.password,onValueChange:e=>m({...p,password:e}),shown:ee,onToggleShown:()=>x(e=>!e),placeholder:`••••••••`,"data-testid":`user-form-password`})}),s(T,{label:`Admin`,description:`Unrestricted access to every capability and device.`,children:t(`label`,{className:`inline-flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:p.isAdmin,onChange:e=>m({...p,isAdmin:e.target.checked}),className:`rounded border-border focus:ring-primary`,"data-testid":`user-form-admin`}),s(`span`,{children:`Admin`})]})}),p.id!==void 0&&s(`p`,{className:`text-[11px] text-foreground-subtle`,children:`To change the password, use Reset password on the user's row. Access scopes are configured from the Access column.`})]})}),ue&&s(en,{userId:ue.id,username:ue.username,onClose:()=>de(null)}),fe&&s($t,{userId:fe.id,username:fe.username,onClose:()=>pe(null)}),me&&s(tn,{userId:me.id,username:me.username,onClose:()=>B(null)}),se&&s(mn,{user:se,onClose:()=>ce(null),onSubmit:e=>R.mutate({userId:se.id,scopes:e}),submitting:R.isPending})]})}function pn({scopes:e}){if(e.length===0)return s(`span`,{className:`font-medium text-warning`,children:`No access`});let n=Xe(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:Ze(n.roleId).label}),` ·`,` `,me(n.selector)]})}function mn(e){let{user:t}=Y(),n=t?.isAdmin===!0;return s(sn,{...e,callerScopes:n?null:t?.scopes??[]})}var hn={"api-keys":Z.scopedTokens,"linked-sessions":Z.linkedApps};function gn(){let{t:e}=Qe(),[t]=$e(),n=hn[t.get(`tab`)??``];if(n!==void 0)return s(tt,{to:at(`access`,{integration:n}),replace:!0});let r=et(`/system/identity`,{t:e,isAdmin:!0})??{icon:ee,title:e(`system.identity`,`Identity & Access`)};return s(lt,{icon:r.icon,title:r.title,defaultSection:`users`,sectionsLabel:`${r.title} sections`,sections:[{id:`users`,label:`Users`,content:s(fn,{})},{id:it.access.tab,label:`Tokens & sessions`,content:s(qt,{}),ownedParams:st.concat([Tt.scoped,Tt.admin])},{id:it.authentication.tab,label:`Authentication`,content:s(Zt,{}),ownedParams:st}]})}export{gn as IdentityPage};
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,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,ct as u,gt as d,ot as f,yt as p}from"./player-overlays-7BNWOeGN.js";import{Ad as m,Al as h,An as g,Bl as _,Bu as v,Cd as ee,Cu as y,Dd as b,Dl as x,Fl as S,Fn as C,Ft as w,G as T,Gn as E,Hl as D,Hn as te,Ht as O,Il as k,In as A,Ju as ne,Ku as j,L as re,Ll as M,Ml as N,Mn as P,Mr as F,N as I,Nl as ie,Ol as ae,P as L,Pl as oe,Pn as R,Qu as se,Rl as ce,Td as z,Un as le,Vl as ue,Wd as de,Wn as fe,X as pe,Z as me,Zl as he,dn as B,du as V,jd as H,jl as ge,jn as U,jr as _e,kd as ve,kl as ye,nr as W,pd as be,pu as xe,ql as Se,qu as G,rr as Ce,sf as we,ud as Te,ur as Ee,va as De,z as Oe,zl as ke}from"./src-qXivmhEc.js";import{t as Ae}from"./history-DLbj1ReB.js";import{t as je}from"./monitor-smartphone-CKSor6O7.js";import{_ as K,a as Me,b as Ne,c as Pe,d as Fe,f as Ie,g as Le,h as q,i as Re,l as ze,m as Be,n as Ve,o as He,p as Ue,s as We,t as Ge,u as Ke,v as J,y as qe}from"./SessionsList-CIZfyFLs.js";import{a as Je,i as Ye,o as Xe,s as Ze}from"./client-DUrWDWpW.js";import{t as Qe}from"./useTranslation-Bc5yH9V9.js";import{$ as $e,C as et,R as Y,X as tt,Y as nt,at as rt,c as it,p as at,rt as ot,s as st,tt as ct}from"./index-CCv7bUCn.js";import{t as lt}from"./AdminSectionedPage-CzB-IV65.js";import{t as ut}from"./AdminPage-CXLW-S6O.js";import{n as dt,r as ft,t as pt}from"./AddonIntegrationBody-Bz69Wys3.js";import{n as mt,t as ht}from"./addon-display-names-BkwMrExv.js";var gt=p(`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`}]]),_t=p(`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 vt(){let e=W(),t=V.useUtils(),r=qe(),{data:i,isLoading:a}=S(),c=n(()=>i??[],[i]),l=V.useQueries(e=>c.map(t=>e.userManagement.listExternalIdentities({userId:t.id}))),u=V.auth.listLoginMethods.useQuery(),[d,f]=o(null),p=ue({onSuccess:()=>void t.userManagement.listExternalIdentities.invalidate(),onError:e=>f(`Remove failed: ${e.message}`)}),m=n(()=>new Map((u.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),[u.data]),h=c.flatMap((e,t)=>l[t]?.data??[]),g=h.map(e=>({...Fe(e,r),kind:m.get(e.provider)??e.provider})),_=async t=>{let n=h.find(e=>Ke(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),p.mutate({userId:n.userId,provider:n.provider,subject:n.subject}))};return s(K,{notice:J(d),onDismissNotice:()=>{f(null)},id:`external-identities`,title:`Sign-in links`,icon:rt,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(q,{rows:g,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:Ne,isAvailable:()=>!0,onRun:e=>void _(e),busyId:null,disabled:p.isPending}})})}e();function yt(){let e=W(),t=a(),r=qe(),i=N(),[c,l]=o(null),d=M({onSuccess:()=>void t.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),onError:e=>l(`Revoke failed: ${e.message}`)}),f=n(()=>(i.data??[]).map(e=>ze(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),d.mutate({id:t.id}))};return s(K,{notice:J(c),onDismissNotice:()=>{l(null)},id:`legacy-api-keys`,title:`Legacy API keys`,icon:Ae,description:`Keys from before scoped tokens. Nothing creates them any more; revoke them and issue a scoped token instead.`,children:s(q,{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:u,isAvailable:()=>!0,onRun:e=>void p(e),busyId:d.isPending?d.variables?.id??null:null,disabled:d.isPending}})})}e();function bt(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 xt(){let e=W(),t=a(),r=oe(),[i,c]=o(null),l=ce({onSuccess:()=>void t.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]}),onError:e=>c(`Revoke failed: ${e.message}`)}),d=n(()=>(r.data??[]).map(e=>Ie(e,e.scopes.map(bt).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(K,{notice:J(i),onDismissNotice:()=>{c(null)},id:`linked-apps`,title:`Linked apps`,icon:b,description:`External integrations (Alexa, …) linked to this hub through OAuth. Revoking one stops that integration on its next call.`,children:s(q,{rows:d,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:u,isAvailable:e=>e.status===`active`,onRun:e=>void f(e),busyId:p,disabled:l.isPending}})})}e();var St={one:`session`,many:`sessions`};function Ct(){let e=W(),t=V.useUtils(),r=qe(),i=V.auth.listSessions.useQuery(),[a,c]=o(null),l=()=>void t.auth.listSessions.invalidate(),u=V.auth.revokeSessions.useMutation({onSuccess:l,onError:e=>c(`Sign out failed: ${e.message}`)}),d=Le(`login-session`,St,l),f=n(()=>(i.data??[]).map(e=>Ue(e,r,{client:e=>Me(e).label,method:He})),[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(K,{notice:J(a,d.outcome),onDismissNotice:()=>{c(null),d.dismiss()},id:`login-sessions`,title:`Login sessions`,icon:je,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(q,{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:ct,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:St,isSelectable:e=>e.status===`active`}})})}e();function wt({open:e,users:n,onClose:r,onSubmit:i,submitting:a}){let{user:c}=Y(),l=c?.isAdmin===!0?null:c?.scopes??[],[u,d]=o(n[0]?.id??``),[f,p]=o(``),[m,h]=o([{type:`capability`,target:``,access:[`view`,`create`]}]),[g,_]=o(``),v=L(m);return s(Oe,{open:e,onClose:r,title:`Create scoped token`,icon:j,width:`md`,testId:`create-scoped-token-dialog`,footer:t(E,{type:`button`,variant:`primary`,size:`sm`,onClick:()=>{let e=parseInt(g,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;i({userId:u,name:f.trim(),scopes:m,expiresAt:t})},disabled:!(u!==``&&f.trim().length>0&&m.length>0&&v===null&&!a),children:[a?s(z,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}):s(j,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),`Issue token`]}),children:t(`div`,{className:`space-y-3`,children:[t(`div`,{className:`space-y-1`,children:[s(B,{htmlFor:`scoped-token-user`,children:`On behalf of user`}),s(fe,{id:`scoped-token-user`,value:u,onChange:e=>d(e.target.value),options:n.map(e=>({value:e.id,label:e.username}))})]}),s(T,{label:`Name`,required:!0,children:s(he,{id:`scoped-token-name`,value:f,onChange:e=>p(e.target.value),placeholder:`cloudflare-tunnel-route`,autoFocus:!0})}),t(`div`,{className:`space-y-1`,children:[s(B,{children:`Scopes`}),s(I,{value:m,onChange:h,clampToParent:l}),v&&s(`p`,{className:`text-[10px] text-danger`,children:v}),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(B,{htmlFor:`scoped-token-days`,children:`Expires in (days)`}),s(he,{id:`scoped-token-days`,type:`number`,min:1,value:g,onChange:e=>_(e.target.value),placeholder:`30`}),s(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Leave blank for non-expiring.`})]})]})})}var Tt={scoped:`newScoped`,admin:`newAdmin`};function Et({token:e,label:n,onClose:r}){return s(g,{open:!0,onOpenChange:e=>!e&&r(),children:t(P,{width:`md`,scroll:`body`,children:[s(C,{children:s(A,{children:`Token: ${n}`})}),t(U,{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(R,{children:[s(w,{value:e,label:`Copy`,srLabel:`token`}),s(E,{type:`button`,variant:`primary`,size:`sm`,onClick:r,children:`Done`})]})]})})}e();function Dt(e){return e.type===`device`?`device:[${me(e.selector)}]`:`${e.type}:${e.target??``}`}function Ot(){let e=W(),r=a(),i=qe(),{data:c,isLoading:l}=S(),d=n(()=>c??[],[c]),f=V.useQueries(e=>d.map(t=>e.userManagement.listScopedTokens({userId:t.id}))),[p,h]=o(null),[g,_]=o(null),{state:v,openNew:ee,close:y}=re({newKey:Tt.scoped}),b=()=>void r.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),C=x({onSuccess:({token:e,record:t})=>{b(),y(),_({token:e,label:t.name})},onError:e=>h(`Create failed: ${e.message}`)}),w=ke({onSuccess:b,onError:e=>h(`Revoke failed: ${e.message}`)}),T=Date.now(),D=d.flatMap((e,t)=>(f[t]?.data??[]).map(t=>Be(t,e.id,i,t.scopes.map(Dt).join(`, `),T))),te=f.find(e=>e.isError)?.error?.message??null,O=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),w.mutate({id:t.id}))};return t(K,{notice:J(p),onDismissNotice:()=>{h(null)},id:`scoped-tokens`,title:`Scoped tokens`,icon:m,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(E,{type:`button`,variant:`primary`,size:`sm`,onClick:ee,disabled:d.length===0,title:d.length===0?`Create a user first`:`Issue a scoped token`,children:[s(j,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),`New token`]}),children:[s(q,{rows:D,label:`scoped tokens`,isLoading:l||f.some(e=>e.isLoading),loadError:te,emptyText:`No scoped tokens.`,action:{label:`Revoke`,icon:u,isAvailable:()=>!0,onRun:e=>void O(e),busyId:w.isPending?w.variables?.id??null:null,disabled:w.isPending}}),s(wt,{open:v.mode===`new`,users:d.map(e=>({id:e.id,username:e.username})),onClose:y,onSubmit:e=>C.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:C.isPending}),g!==null&&s(Et,{token:g.token,label:g.label,onClose:()=>_(null)})]})}e();var kt={one:`admin token`,many:`admin tokens`},At=7,jt=90,Mt=80;function Nt(e){let t=Number(e);return Number.isInteger(t)&&t>=1&&t<=jt?t:null}function Pt(){let{user:e}=Y();return e?.isAdmin?s(Ft,{}):null}function Ft(){let e=W(),r=V.useUtils(),i=V.auth.listAdminTokens.useQuery(),a=qe(),{requestProof:l,dialog:d}=Re(`Creating an admin token`),{state:f,openNew:p,close:m}=re({newKey:Tt.admin}),[h,g]=o(``),[_,v]=o(String(At)),[ee,y]=o(null),[b,x]=o(null),[S,C]=o(!1),[w,T]=o(null),D=()=>{r.auth.listAdminTokens.invalidate(),r.auth.listAuthAudit.invalidate()},te=V.auth.createAdminToken.useMutation({onSuccess:({token:e,record:t})=>{D(),g(``),v(String(At)),x(null),m(),T({token:e,label:t.name})},onError:e=>{y(`Create failed: ${e.message}`),x(`Create failed: ${e.message}`)}}),O=V.auth.revokeAdminToken.useMutation({onSuccess:D,onError:e=>y(`Revoke failed: ${e.message}`)}),k=Le(`admin-token`,kt,D);c(()=>{f.mode===`closed`&&(g(``),v(String(At)),x(null),C(!1))},[f.mode]);let A=Date.now(),ne=n(()=>(i.data??[]).map(e=>Pe(e,a,A)),[i.data,a]),j=h.trim(),M=Nt(_),N=j.length>0&&j.length<=Mt&&M!==null&&!te.isPending&&!S,P=async()=>{if(!N||M===null)return;y(null),x(null),C(!0);let e=await l();C(!1),e!==null&&te.mutate({name:j,expiresInDays:M,reauthToken:e})},F=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`})&&(y(null),O.mutate({id:t.id}))};return t(`div`,{"data-testid":`admin-tokens`,children:[d,s(K,{id:`admin-tokens`,title:`Admin tokens`,icon:G,tone:`danger`,notice:J(ee,k.outcome),onDismissNotice:()=>{y(null),k.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.`})]}),actions:t(E,{type:`button`,variant:`danger`,size:`sm`,onClick:p,children:[s(G,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),`New admin token`]}),children:s(q,{rows:ne,label:`admin tokens`,isLoading:i.isLoading,loadError:i.isError?i.error?.message??`Request failed`:null,emptyText:`No admin tokens.`,action:{label:`Revoke`,icon:u,isAvailable:e=>e.status===`active`,onRun:e=>void F(e),busyId:O.isPending?O.variables?.id??null:null,disabled:O.isPending||k.busy},bulk:{revoke:k,noun:kt,isSelectable:e=>e.status===`active`}})}),s(Oe,{open:f.mode===`new`,onClose:m,title:`Create admin token`,icon:G,error:b,width:`md`,testId:`admin-token-form-dialog`,footer:t(E,{type:`button`,variant:`danger`,size:`sm`,disabled:!N,onClick:()=>void P(),children:[te.isPending||S?s(z,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}):s(G,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),`Create admin token`]}),children:t(`div`,{className:`space-y-3`,children:[t(`div`,{className:`space-y-1`,children:[s(B,{htmlFor:`admin-token-name`,children:`Token name`}),s(he,{id:`admin-token-name`,value:h,maxLength:Mt,onChange:e=>g(e.target.value),placeholder:`nightly-backup`,autoFocus:!0})]}),t(`div`,{className:`space-y-1`,children:[s(B,{htmlFor:`admin-token-days`,children:`Expires in (days)`}),s(he,{id:`admin-token-days`,type:`number`,min:1,max:jt,value:_,onChange:e=>v(e.target.value),state:M===null?`error`:`default`}),M===null?t(`p`,{className:`text-[11px] text-danger`,children:[`Expiry must be a whole number of days, 1 to `,jt,`.`]}):t(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Whole number of days, 1 to `,jt,`.`]})]})]})}),w&&s(Et,{token:w.token,label:w.label,onClose:()=>T(null)})]})}var It={"share-link":`share links`,"admin-token":`admin tokens`,"login-session":`login sessions`};function X(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function Lt(e,t){let n=X(e,`tokenId`);return X(e,`name`)??(n===null?void 0:t.get(n))??n??`?`}function Rt(e){return e.filter(e=>e!==null)}function zt(e){let t=X(e,`prefix`);return t===null?null:`Prefix ${t}…`}function Bt(e,t){let n=e.detail??{};switch(e.action){case`admin-token-created`:{let e=n.expiresAt;return{title:`Admin token "${Lt(n,t)}" created`,details:Rt([zt(n),typeof e==`number`?`Expires ${We(e)}`:null])}}case`admin-token-used`:{let e=X(n,`path`);return{title:`Admin token "${Lt(n,t)}" used`,details:Rt([zt(n),e===null?null:`Call ${e}`])}}case`admin-token-revoked`:return{title:`Admin token "${Lt(n,t)}" revoked`,details:Rt([zt(n)])};case`credentials-revoked`:{let e=X(n,`kind`)??`credential`,t=n.revoked,r=n.skipped,i=It[e]??`${e}s`;return{title:`${typeof t==`number`?String(t):`?`} ${i} revoked in bulk`,details:Rt([typeof r==`number`&&r>0?`${String(r)} skipped`:null,X(n,`ids`)===null?null:`Ids ${X(n,`ids`)??``}`])}}case`second-factor-skipped`:{let e=X(n,`method`),t=X(n,`factors`);return{title:`Second factor skipped on a trusted network`,details:Rt([e===null?null:`Signed in with ${He(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 Vt=100;function Ht(){let{user:e}=Y();return e?.isAdmin?s(Wt,{}):null}function Ut(){let{data:e}=S(),{data:t}=V.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 Wt(){let e=V.auth.listAuthAudit.useQuery({limit:Vt}),{userNameById:n,tokenNameById:r}=Ut(),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(se,{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 `,Vt,`, 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(z,{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(Gt,{record:e,userName:e.userId===void 0?null:n.get(e.userId)??e.userId,tokenNameById:r},e.id))})})]})}function Gt({record:e,userName:n,tokenNameById:r}){let i=Bt(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:We(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`},Kt={state:`ok`,stateLabel:`available`,showState:!1};function Q(e,t,n,r){return{id:e,name:t,fallbackIcon:n,...Kt,render:r}}function qt(){let e=N(),t=(e.data??[]).length>0;return s(ft,{embedded:!0,icon:_t,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`,je,()=>s(Ct,{})),Q(Z.linkedApps,`Linked apps`,b,()=>s(xt,{}))]},{id:`tokens`,label:`Tokens`,entries:[Q(Z.scopedTokens,`Scoped tokens`,m,()=>s(Ot,{})),Q(Z.adminTokens,`Admin tokens`,G,()=>s(Pt,{})),Q(Z.shareLinks,`Share links`,ne,()=>s(Ve,{})),...t?[Q(Z.legacyApiKeys,`Legacy API keys`,Ae,()=>s(yt,{}))]:[]]},{id:`identity`,label:`Identity`,entries:[Q(Z.externalIdentities,`Sign-in links`,rt,()=>s(vt,{})),Q(Z.audit,`Audit`,se,()=>s(Ht,{}))]}],isLoading:e.isLoading,emptyTitle:`No credential kinds`,emptyDescription:`This hub offers no credential kinds.`})}e();var Jt=3e4,Yt=[{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 Xt(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:_t,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:ot,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:ot,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:v,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:v,bullets:[`Time-based codes from an authenticator app (RFC 6238).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:j,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Zt(){let e=F({capName:Yt[0].capName},{refetchInterval:Jt}),t=F({capName:Yt[1].capName},{refetchInterval:Jt}),r=_e(void 0,{refetchInterval:Jt}),i=n(()=>ht(r.data??[]),[r.data]),a=n(()=>{let n=[],r=[e.data??[],t.data??[]];for(let[e,t]of Yt.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:Yt[0].capName,label:$.installLabel},entries:a.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:j,...mt(e.isActive),render:()=>s(pt,{addonId:e.addonId,displayName:e.displayName,capName:e.capName,isActive:e.isActive,badges:e.stageBadge===null?null:s(Ee,{variant:`info`,className:dt,children:e.stageBadge}),panels:[{id:`about`,title:`About`,icon:Xt(e.addonId).icon,content:s(Qt,{addonId:e.addonId})}]})}))}];return s(ft,{embedded:!0,icon:j,title:$.title,subtitle:$.subtitle,groups:o,isLoading:e.isLoading||t.isLoading,emptyTitle:$.emptyTitle,emptyDescription:$.emptyDescription})}function Qt({addonId:e}){let n=Xt(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(gt,{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(H,{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(nt,{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(nt,{to:`/system/identity?tab=users`,className:`underline text-primary`,children:`Users`}),` `,`page via Actions → “Remove 2FA”.`]})]})]})}function $t({userId:e,username:n,onClose:r}){let i=W(),a=V.useUtils(),o=ie({userId:e}),c=V.auth.listLoginMethods.useQuery(),l=ue({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(g,{open:!0,onOpenChange:e=>!e&&r(),children:t(P,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`external-identities-modal`,children:[s(C,{children:t(A,{className:`flex items-center gap-2`,children:[s(b,{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(U,{className:`space-y-3`,children:o.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(z,{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(Ne,{className:`h-3 w-3`}),`Remove`]})]},`${e.provider}|${e.subject}`)})})}),s(R,{children:s(E,{onClick:r,variant:`secondary`,children:`Close`})})]})})}function en({userId:e,username:n,onClose:r}){let o=a(),c=W(),l=ge({userId:e}),u=l.data,d=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),f=h({onSuccess:()=>{d(),r()}}),p=l.isLoading?`loading`:u?.enabled?`enrolled`:`not_enrolled`;return s(g,{open:!0,onOpenChange:e=>!e&&r(),children:t(P,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[s(C,{children:t(A,{className:`flex items-center gap-2`,children:[s(v,{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(U,{className:`space-y-4`,children:[p===`loading`&&t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(z,{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(H,{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(we,{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(E,{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(z,{className:`h-3 w-3 animate-spin`}):s(xe,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}e();function tn({userId:e,username:n,onClose:r}){let{user:i,logout:a}=Y(),c=i?.id===e,l=W(),u=V.useUtils(),d=V.auth.listSessions.useQuery({userId:e}),[f,p]=o(null),m=V.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}`)}),h=async e=>{await l({title:`Sign out this session`,message:`"${n}" on ${Me(e.client).label} will have to sign in again.`,confirmLabel:`Sign out`,variant:`danger`})&&(p(null),m.mutate({id:e.id}))},_=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),m.mutate({userId:e}))},v=m.isPending&&m.variables!==void 0&&`id`in m.variables?m.variables.id:null;return s(g,{open:!0,onOpenChange:e=>!e&&r(),children:t(P,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`user-sessions-modal`,children:[s(C,{children:t(A,{className:`flex items-center gap-2`,children:[s(je,{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(U,{className:`space-y-3`,children:[f!==null&&s(`div`,{className:`text-[11px] text-danger`,children:f}),s(Ge,{sessions:d.data??[],isLoading:d.isLoading,loadError:d.isError?d.error?.message??`Request failed`:null,emptyText:`No active sessions.`,onRevoke:e=>void h(e),revokingId:v})]}),t(R,{className:`justify-between`,children:[t(`button`,{onClick:()=>void _(),disabled:m.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:[m.isPending&&v===null?s(z,{className:`h-3 w-3 animate-spin`}):s(ct,{className:`h-3 w-3`}),`Sign out everywhere`]}),s(E,{onClick:r,variant:`secondary`,children:`Close`})]})]})})}function nn({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 rn({scopes:e,isAdmin:n,invalidReason:a}){let o=f(),c=r({queryKey:[`auth`,`previewScope`,e,n],enabled:a===null,queryFn:()=>o.trpcClient.auth.previewScope.query({scopes:[...e],isAdmin:n})}),{data:l}=De({projection:`slim`}),d=l?.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(G,{className:`h-3 w-3 shrink-0`}),a]})});if(c.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(z,{className:`h-3 w-3 animate-spin`}),`Resolving…`]});if(c.isError||!c.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=c.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(nn,{icon:de,label:`Devices they can see`,count:p.device.view.deviceCount,all:p.device.view.all,total:d}),s(nn,{icon:be,label:`Devices they can operate`,count:p.device.create.deviceCount,all:p.device.create.all,total:d}),s(nn,{icon:u,label:`Devices they can delete`,count:p.device.delete.deviceCount,all:p.device.delete.all,total:d}),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 an(e){let t=Xe(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 on(e){return e.mode===`advanced`?e.advancedScopes:e.roleId===null?[]:Je({roleId:e.roleId,selector:e.selector,includeLinked:e.includeLinked})}function sn({user:e,onClose:r,onSubmit:a,submitting:c,callerScopes:u}){let f=n(()=>an(e.scopes??[]),[e.scopes]),[p,m]=o(f),[h,_]=o(f.mode===`advanced`),v=n(()=>on(p),[p]),ee=!e.isAdmin&&p.mode===`role`&&p.roleId===null,y=n(()=>e.isAdmin?null:p.mode===`role`&&p.roleId===null?`Pick what this user can do to see the result.`:L(v),[e.isAdmin,p.mode,p.roleId,v]),b=e=>m({...p,...e});return s(g,{open:!0,onOpenChange:e=>!e&&r(),children:t(P,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-2xl`,children:[t(C,{children:[t(A,{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(U,{className:`space-y-4`,children:[ee&&t(`div`,{className:`flex items-start gap-2 rounded-lg border border-warning/40 bg-warning/10 p-3`,children:[s(G,{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:Ye.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:()=>b({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(!h){m({...p,mode:`advanced`,advancedScopes:v}),_(!0);return}_(!1),m(an(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(h?l:d,{className:`h-3 w-3`}),`Advanced — edit raw grants`]}),h&&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(I,{value:p.advancedScopes,onChange:e=>b({mode:`advanced`,advancedScopes:e}),clampToParent:u,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(pe,{value:p.selector,onChange:e=>b({selector:e}),includeLinked:p.includeLinked,onIncludeLinkedChange:e=>b({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(rn,{scopes:v,isAdmin:e.isAdmin,invalidReason:y})]})]}),t(R,{children:[s(E,{variant:`outline`,size:`sm`,onClick:r,children:`Cancel`}),s(E,{size:`sm`,onClick:()=>a([...v]),disabled:c||y!==null,children:c?s(z,{className:`h-3 w-3 animate-spin`}):`Save access`})]})]})})}e();var cn=8;function ln(){return{username:``,password:``,isAdmin:!1}}function un(e){return{id:e.id,username:e.username,password:``,isAdmin:e.isAdmin}}function dn(e){return e instanceof Error?e.message:`Something went wrong`}function fn(){let e=a(),{user:n}=Y(),{state:r,openNew:l,openEdit:d,close:f}=re(),[p,m]=o(null),[h,g]=o(null),[ee,x]=o(!1),{data:C,isLoading:w,isError:A,error:ne,refetch:M}=S(),N=W(),P=Ce(),F=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),I=ae(),ie=ye({onSuccess:F}),L=D({onSuccess:F}),oe=k({onSuccess:F}),R=_({onSuccess:()=>{F(),ce(null)}}),[se,ce]=o(null),[ue,de]=o(null),[fe,pe]=o(null),[me,B]=o(null),V=C??[],H=r.mode===`edit`?V.find(e=>e.id===r.id)??null:null,ge=()=>{m(null),g(null),x(!1),I.reset(),L.reset(),f()};c(()=>{if(r.mode===`closed`){m(null),g(null),x(!1);return}if(r.mode===`new`){m(e=>e!==null&&e.id===void 0?e:ln());return}if(H===null){w||f();return}m(e=>e?.id===H.id?e:un(H))},[r,H,w,f]);let U=r.mode===`new`&&p!==null&&p.id===void 0||r.mode===`edit`&&p!==null&&H!==null;async function _e(e){await N({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`})&&(ie.mutate({id:e.id}),r.mode===`edit`&&r.id===e.id&&ge())}async function xe(e){let t=await P({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<cn?`Password must be at least ${String(cn)} characters.`:null});t===null||t.length===0||await N({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&oe.mutate({id:e.id,newPassword:t})}function G(e,t){t!==e.isAdmin&&L.mutate({id:e.id,isAdmin:t})}async function we(){if(p!==null){g(null);try{if(p.id===void 0){let e=p.username.trim();if(e===``||p.password.length<cn)return;await I.mutateAsync({username:e,password:p.password,isAdmin:p.isAdmin})}else await L.mutateAsync({id:p.id,isAdmin:p.isAdmin});F(),ge()}catch(e){g(dn(e))}}}function Ee(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}let De=I.isPending||L.isPending,ke=p!==null&&p.id===void 0&&p.username.trim()!==``&&p.password.length>=cn,Ae=p!==null&&p.id!==void 0,K=De||(p?.id===void 0?!ke:!Ae),Me=e=>ie.isPending&&ie.variables?.id===e.id||L.isPending&&L.variables?.id===e.id||oe.isPending&&oe.variables?.id===e.id;return t(ut,{embedded:!0,icon:y,title:`Users`,subtitle:`Hub accounts, admin flag, access scopes, sessions and sign-in links.`,actions:t(E,{size:`sm`,type:`button`,onClick:()=>{g(null),l()},children:[s(Te,{className:`h-3.5 w-3.5`}),`Create User`]}),children:[A&&s(te,{title:`Could not load users`,message:dn(ne),onRetry:()=>void M()}),w&&t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(z,{className:`h-3.5 w-3.5 animate-spin`}),`Loading…`]}),!w&&!A&&V.length===0&&s(le,{icon:y,title:`No users yet`,description:`Create a user to grant hub access.`}),!w&&!A&&V.length>0&&s(O,{columns:[{key:`username`,header:`Username`,sortValue:e=>e.username,render:e=>s(`span`,{className:`font-medium text-foreground`,"data-testid":`user-open-${e.id}`,children:e.username})},{key:`isAdmin`,header:`Admin`,nowrap:!0,sortValue:e=>+!!e.isAdmin,render:e=>s(`span`,{onClick:e=>e.stopPropagation(),children:t(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:e.isAdmin,onChange:t=>G(e,t.target.checked),disabled:Me(e),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),s(`span`,{className:e.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:e.isAdmin?`Admin`:`Regular`})]})})},{key:`scopes`,header:`Access`,render:e=>e.isAdmin?s(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:`everything (admin)`}):s(`span`,{onClick:e=>e.stopPropagation(),children:t(E,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>ce(e),title:`Configure access`,children:[s(j,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(pn,{scopes:e.scopes??[]})]})})},{key:`createdAt`,header:`Created`,nowrap:!0,sortValue:e=>e.createdAt,render:e=>s(`span`,{className:`text-foreground-subtle`,children:Ee(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,nowrap:!0,notSortableReason:`Row actions`,render:e=>{let r=Me(e),i=e.id!==n?.id&&e.totpEnabled;return t(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[t(E,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>d(e.id),disabled:r,title:`Edit user`,children:[s(be,{className:`h-3 w-3`}),`Edit`]}),i&&t(E,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>de(e),disabled:r,title:`Remove two-factor authentication`,children:[s(v,{className:`h-3 w-3`}),`Remove 2FA`]}),t(E,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>pe(e),disabled:r,title:`Linked sign-in accounts`,children:[s(b,{className:`h-3 w-3`}),`Sign-in links`]}),t(E,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>B(e),disabled:r,title:`Active sessions`,children:[s(je,{className:`h-3 w-3`}),`Sessions`]}),t(E,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void xe(e),disabled:r,title:`Reset password`,children:[s(ve,{className:`h-3 w-3`}),`Reset password`]}),t(E,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void _e(e),disabled:r,title:`Delete user`,className:`text-danger hover:bg-danger/10`,children:[r?s(z,{className:`h-3 w-3 animate-spin`}):s(u,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:V,rowKey:e=>e.id,minWidthPx:560,maxBodyHeight:`max-h-[60vh]`,mobileMode:`scroll`,onRowClick:e=>d(e.id)}),s(Oe,{open:U,onClose:ge,title:p?.id===void 0?`Create User`:`Edit ${p.username||`user`}`,icon:y,error:h,testId:`user-form-dialog`,footer:s(E,{size:`sm`,type:`button`,disabled:K,onClick:()=>void we(),children:De?t(i,{children:[s(z,{className:`h-3.5 w-3.5 animate-spin`}),`Saving…`]}):p?.id===void 0?`Create`:`Save`}),children:p!==null&&t(`div`,{className:`space-y-3`,children:[s(T,{label:`Username`,required:p.id===void 0,children:s(he,{value:p.username,onChange:e=>m({...p,username:e.target.value}),placeholder:`john`,autoFocus:p.id===void 0,disabled:p.id!==void 0,"data-testid":`user-form-username`})}),p.id===void 0&&s(T,{label:`Password`,required:!0,description:`At least ${String(cn)} characters.`,children:s(Se,{value:p.password,onValueChange:e=>m({...p,password:e}),shown:ee,onToggleShown:()=>x(e=>!e),placeholder:`••••••••`,"data-testid":`user-form-password`})}),s(T,{label:`Admin`,description:`Unrestricted access to every capability and device.`,children:t(`label`,{className:`inline-flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:p.isAdmin,onChange:e=>m({...p,isAdmin:e.target.checked}),className:`rounded border-border focus:ring-primary`,"data-testid":`user-form-admin`}),s(`span`,{children:`Admin`})]})}),p.id!==void 0&&s(`p`,{className:`text-[11px] text-foreground-subtle`,children:`To change the password, use Reset password on the user's row. Access scopes are configured from the Access column.`})]})}),ue&&s(en,{userId:ue.id,username:ue.username,onClose:()=>de(null)}),fe&&s($t,{userId:fe.id,username:fe.username,onClose:()=>pe(null)}),me&&s(tn,{userId:me.id,username:me.username,onClose:()=>B(null)}),se&&s(mn,{user:se,onClose:()=>ce(null),onSubmit:e=>R.mutate({userId:se.id,scopes:e}),submitting:R.isPending})]})}function pn({scopes:e}){if(e.length===0)return s(`span`,{className:`font-medium text-warning`,children:`No access`});let n=Xe(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:Ze(n.roleId).label}),` ·`,` `,me(n.selector)]})}function mn(e){let{user:t}=Y(),n=t?.isAdmin===!0;return s(sn,{...e,callerScopes:n?null:t?.scopes??[]})}var hn={"api-keys":Z.scopedTokens,"linked-sessions":Z.linkedApps};function gn(){let{t:e}=Qe(),[t]=$e(),n=hn[t.get(`tab`)??``];if(n!==void 0)return s(tt,{to:at(`access`,{integration:n}),replace:!0});let r=et(`/system/identity`,{t:e,isAdmin:!0})??{icon:ee,title:e(`system.identity`,`Identity & Access`)};return s(lt,{icon:r.icon,title:r.title,defaultSection:`users`,sectionsLabel:`${r.title} sections`,sections:[{id:`users`,label:`Users`,content:s(fn,{})},{id:it.access.tab,label:`Tokens & sessions`,content:s(qt,{}),ownedParams:st.concat([Tt.scoped,Tt.admin])},{id:it.authentication.tab,label:`Authentication`,content:s(Zt,{}),ownedParams:st}]})}export{gn as IdentityPage};
@@ -1 +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{_t as l,ct as u,gt as d,ht as f,ot as p,yt as m}from"./player-overlays-DJRuofy-.js";import{$i as h,An as g,Da as _,Fn as v,In as y,It as b,Kt as x,Lr as S,Mn as C,Ou as w,Qi as T,Qu as E,Ta as D,Td as O,Tt as k,Wa as A,Wd as j,Yu as M,Zi as N,aa as P,br as F,co as I,df as ee,do as L,ea as R,et as te,fo as z,gu as B,ho as V,ia as H,id as U,iu as W,jn as G,kf as K,la as ne,ln as re,lo as ie,nf as q,od as ae,of as J,pa as Y,po as oe,pu as X,ra as se,rd as ce,rt as le,ta as ue,tt as de,tu as fe,ua as pe,ud as me,uo as he,va as ge,wn as Z,yr as _e}from"./src-CmZyEJNe.js";import{Er as ve}from"./client-D7C4n8lL.js";import{t as ye}from"./useTranslation-Bc5yH9V9.js";import{$ as be,I as xe,Q as Se,Z as Ce,q as we}from"./index-BURcka-4.js";import{t as Te}from"./NodeAddonsSettingsPanel-C7wY3WPr.js";import{t as Ee}from"./device-integration-icon-DV5lR5V4.js";import{n as De,r as Oe,t as ke}from"./ScanNetworkModal-682GpB69.js";var Ae=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 Q(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Q(n.fields));return t}function je(t,n,r){let[a,s]=o(`idle`),[c,l]=o({}),u=i(()=>{let e=[];for(let n of t.sections)e.push(...Q(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 Me(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(...Me(n.fields));return t}function Ne(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Pe(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Pe(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function Fe(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function Ie({open:t,integrationId:n,addonId:u,onClose:d}){let{t:f}=ye(),p=a(),[m,h]=o({}),[g,_]=o(!1),[v,y]=o(null),[b,x]=o(Fe),S=D({addonId:u},{enabled:t}),C=S.data?.deviceType??null,T=Y({addonId:u,type:C??ve.Camera},{enabled:t&&S.isSuccess&&C!==null}),j=T.data??null;c(()=>{t&&(h(j?Pe(j.sections.flatMap(e=>e.fields)):{}),x(Fe()),_(!1),y(null))},[t,n,j]);let M=i(()=>({...m,_probeRequestId:b}),[m,b]),N=H({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),P=A(),F=e(async(e,t)=>{_(!0);let n=await P.mutateAsync({addonId:u,type:C??ve.Camera,key:e,value:t,formValues:M});return n.status===`ok`&&n.suggestedValues&&h(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Ne(e[i])&&!Ne(a)&&(r[i]=a,t=!0);return t?r:e}),n},[P,u,M,C]),{testAllStatus:I,hasProbeFields:ee,probeResults:L,handleTestAll:R,clearProbeResult:te}=je(j??{sections:[]},m,F);async function z(e){y(null);try{await N.mutateAsync({addonId:u,type:C??ve.Camera,config:m,integrationId:n}),e?h(j?Pe(j.sections.flatMap(e=>e.fields)):{}):d()}catch(e){y(e instanceof Error?e.message:String(e))}}if(!t)return null;let V=Me((j?.sections??[]).flatMap(e=>e.fields)).filter(e=>Ne(m[e])),U=V.length===0,W=S.isLoading||C!==null&&T.isLoading,G=S.isError||S.isSuccess&&C===null||T.isError||T.isSuccess&&j===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(X,{className:`h-4 w-4`})})]}),s(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:W?s(`div`,{className:`flex items-center justify-center py-8`,children:s(O,{className:`h-5 w-5 animate-spin text-primary`})}):G?r(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[s(w,{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:u}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):s(xe,{schema:j,values:m,onChange:h,onTestField:F,probeResults:L,onClearProbe:te})}),!G&&!W&&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(E,{className:`h-3.5 w-3.5`}),`Test logs`,s(`span`,{className:`font-mono text-[9px] opacity-60`,children:b.slice(0,14)})]}),s(l,{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(k,{addonId:u,requestId:b,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!G&&!W&&(v||V.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(w,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),s(`p`,{className:`text-[11px] text-destructive`,children:v||`Required: ${V.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`)}),!G&&ee&&r(`button`,{type:`button`,onClick:R,disabled:I===`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:[I===`testing`?s(O,{className:`h-3.5 w-3.5 animate-spin`}):s(B,{className:`h-3.5 w-3.5`}),`Test All`]})]}),r(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:()=>z(!0),disabled:G||!U||N.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:()=>z(!1),disabled:G||!U||N.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:N.isPending?f(`integrations.saving`):f(`integrations.save`)})]})]})]})]})}var Le=1500;function $({addonId:e,integrationId:t,jobId:n,onFinished:i}){let{t:a}=ye(),o=N(),c=(R({addonId:e,integrationId:t},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?Le:!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(O,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):c.failed>0?s(w,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):c.state===`cancelled`?s(q,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):s(J,{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 Re(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 ze=`devices`,Be={id:ze,label:`Devices`,isDefault:!0},Ve=2e4,He=100;function Ue({addonId:n,integrationId:i,onClose:l}){let{t:u}=ye(),d=a(),[f,p]=o(new Set),[m,g]=o(new Set),[_,v]=o(new Map),[y,b]=o(null),{data:x}=he(),S=(x??[]).find(e=>e.addonId===n)?.supportsLocationImport??!1,[C,E]=o(!0),D=T({addonId:n,integrationId:i}).data?.filters,k=D&&D.length>0?D:[Be],[A,j]=o(k.find(e=>e.isDefault)?.id??(k.some(e=>e.id===ze)?ze:k[0].id)),M=A!==ze,N=ue(),P=h({addonId:n,integrationId:i,page:1,pageSize:Ve,filter:A}),F=P.refetch,I=N.mutate,L=e(()=>{I({addonId:n,integrationId:i},{onSettled:()=>{F()}})},[I,n,i,F]),R=t(null);c(()=>{let e=`${n}::${i}`;R.current===e||P.isLoading||(R.current=e,(P.data?.candidates.length??0)===0&&L())},[n,i,P.isLoading,P.data,L]);let z=N.isPending,B=N.isError?N.error instanceof Error?N.error.message:String(N.error):null,V=typeof N.data?.lastError==`string`&&N.data.lastError.length>0?N.data.lastError:null,H=P.data?.candidates??[],U=P.isError?P.error instanceof Error?P.error.message:String(P.error):null,G=se(),[K,ne]=o(null),re=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})},[]),ie=e(e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),q=e((e,t)=>{v(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})},[]),ae=e(e=>{let t={};for(let n of e){let e=_.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[_]),J=e(async()=>{b(null);let e=[...f];if(e.length!==0)try{let t=ae(e),{jobId:r}=await G.mutateAsync({addonId:n,integrationId:i,filter:A,childNativeIds:e,...t?{perCandidate:t}:{},...S?{importLocations:C}:{}});ne(r),p(new Set),v(new Map)}catch(e){b(e instanceof Error?e.message:String(e))}},[f,ae,G,n,i,A,S,C]),Y=t(null),oe=e(()=>{K===null||Y.current===K||(Y.current=K,F(),d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]}))},[K,F,d]),le=e(e=>{j(e),p(new Set),g(new Set),v(new Map),b(null)},[]),de=f.size,pe=K!==null&&de===0&&!G.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:[S&&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:C,onChange:e=>E(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(X,{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:[(B??U??V)&&H.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(w,{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:B??U??V})]})]})}),k.length>1&&s(We,{filters:k,activeFilter:A,onSelect:le}),s(`div`,{className:`flex-1 min-h-0`,children:s(te,{mode:`generic`,items:H,pageSize:He,getKey:e=>e.childNativeId,getSearchText:Re,getFilterType:e=>e.type,filterOptions:fe(),filterLabel:u(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:P.isLoading||z&&H.length===0,searchPlaceholder:u(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(B??U??V)&&H.length===0?``:u(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:r(`button`,{type:`button`,onClick:L,disabled:z,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(ce,{className:`h-3.5 w-3.5 ${z?`animate-spin`:``}`}),u(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:u(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>s(Ge,{candidate:e,expandable:!M,expanded:m.has(e.childNativeId),onToggleExpand:()=>ie(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=W(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:()=>re(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(ee,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!M&&m.has(e.childNativeId),renderExpanded:M?void 0:e=>s(Ke,{candidate:e,hiddenChildIds:_.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>q(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:f.has(e.childNativeId)?`bg-primary/5`:``})})]}),y&&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(w,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),s(`p`,{className:`text-[11px] text-destructive`,children:y})]})}),K!==null&&s($,{addonId:n,integrationId:i,jobId:K,onFinished:oe}),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:pe?l:J,disabled:!pe&&(de===0||G.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:[G.isPending&&s(O,{className:`h-3.5 w-3.5 animate-spin`}),pe?u(`integrations.close`,{defaultValue:`Close`}):u(`integrations.addSelected`,{defaultValue:`Add selected`}),!pe&&de>0?` (${de})`:``]})]})]})]})]})}function We({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 Ge({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?l: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 Ke({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:j,{className:`h-3 w-3`})})]},e.childNativeId)})})}n();function qe(e){let t=[];for(let n of e){if(n.type===`group`){t.push(...qe(n.fields));continue}`key`in n&&typeof n.key==`string`&&t.push(n.key)}return t}function Je(e,t){if(!e)return{};let n=new Set(e.sections.flatMap(e=>qe(e.fields))),r={};for(let e of n)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}function Ye(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 Xe({integrationId:e,addonId:t,name:n,kind:o,mode:c,brokerKind:l,canTest:u=!1,trpc:d,onClose:f}){let{t:p}=ye(),m=a(),{data:h,isLoading:_}=L({id:e},{enabled:c===`account`||c===`broker`}),b=i(()=>{let e=h?.brokerId;return typeof e==`string`?e:null},[h]),{data:x,isLoading:S}=_e({addonId:t,nodeId:`hub`},{enabled:c===`account`}),w=i(()=>x?Ye(x):null,[x]),T=oe(),E=(t,n)=>{T.mutate({id:e,settings:t,...n?{secretKeys:[...n]}:{}},{onSuccess:()=>{m.invalidateQueries(),f()}})};return s(g,{open:!0,onOpenChange:e=>!e&&f(),children:r(C,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[s(v,{children:r(y,{children:[p(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]})}),s(G,{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.`})}),b&&r(`p`,{className:`text-[11px] text-foreground`,children:[p(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,s(`span`,{className:`font-mono text-foreground-subtle`,children:b})]}),T.isPending?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[s(O,{className:`h-3 w-3 animate-spin`}),p(`integrations.saving`,{defaultValue:`Saving…`})]}):s(Oe,{kind:l,onResolved:e=>{E({brokerId:e})},onBack:f}),T.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`?_||S?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[s(O,{className:`h-3 w-3 animate-spin`}),p(`integrations.loading`,{defaultValue:`Loading…`})]}):s(De,{addonId:t,configSchema:w,canTest:u,initialName:n,initialConfig:Je(w,h??{}),submitLabel:p(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e,secretKeys:t})=>E(e,t),onBack:f}):s(Z,{trpc:d,addonId:t,nodeId:`hub`,title:n})})]})})}function Ze(e){return e==null?!1:e.sections.some(e=>e.fields.length>0)}n();function Qe(){let{t}=ye(),{integrationId:n}=Se(),l=a(),d=Ce(),[f,m]=be(),h=p(),[w,T]=o(!1),[D,A]=o(!1),[j,N]=o(!1),[ee,L]=o(!1),{data:R,isLoading:B}=ie({id:n??``},{enabled:!!n}),{data:H}=_e({addonId:R?.addonId??``,nodeId:`hub`},{enabled:!!R?.addonId}),{data:W,isSuccess:q}=he(),J=i(()=>{let e=R?.addonId;return!e||!q?null:(W??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[W,R?.addonId,q]),{data:Y}=ne({}),oe=i(()=>(Y?.providers??[]).some(e=>e.addonId===R?.addonId),[Y,R?.addonId]),X=J!==null,se=R?.info?.fixed===!0,ce=X?J===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),ue=i(()=>{let e=R?.addonId;return!e||!q?null:(W??[]).find(t=>t.addonId===e)?.brokerKind??null},[W,R?.addonId,q]),fe=i(()=>{let e=R?.addonId;return!e||!q?!1:(W??[]).find(t=>t.addonId===e)?.canTest===!0},[W,R?.addonId,q]),Z=i(()=>{let e=R?.addonId;return!e||!q?null:(W??[]).find(t=>t.addonId===e)?.mode??null},[W,R?.addonId,q]);c(()=>{f.get(`add`)===`1`&&X&&(T(!0),m(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[f,X,m]);let ve=H!=null&&Array.isArray(H.sections)&&H.sections.some(e=>e.fields.length>0),{data:xe}=F({addonId:R?.addonId??``,nodeId:`hub`},{enabled:!!R?.addonId&&Z!==`account`}),we=Z!==null&&Z!==`account`&&Ze(xe),De=i(()=>R?.addonId?[R.addonId]:[],[R?.addonId]),{data:Oe}=ge({projection:`slim`},{refetchInterval:3e4}),Q=[[`integrations`,`get`],{input:{id:n??``},type:`query`}],je=V({onMutate:async e=>{await l.cancelQueries({queryKey:Q});let t=l.getQueryData(Q);return t!=null&&l.setQueryData(Q,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&l.setQueryData(Q,r.previous)},onSettled:()=>{l.invalidateQueries({queryKey:[[`integrations`]]}),l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Me=I({onSuccess:()=>{l.invalidateQueries({queryKey:[[`integrations`]]}),l.invalidateQueries({queryKey:[[`deviceManager`]]}),d(`/integrations`)}}),Ne=S({onSuccess:()=>{l.invalidateQueries({queryKey:[[`integrations`]]}),l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Pe=_({onSuccess:()=>{l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=P({onSuccess:()=>{l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Le=pe({onSuccess:()=>{l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),$=i(()=>Oe??[],[Oe]),Re=i(()=>{let e=new Map;for(let t of $)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[$]),ze=e(e=>Re.get(e)??null,[Re]),{data:Be}=z(void 0),Ve=i(()=>de(Be),[Be]),He=e(e=>d(`/devices/${String(e)}`),[d]),We=i(()=>{let e=R?.id;return e?$.filter(t=>{let n=Ve(t);return n.kind===`resolved`&&n.integration.id===e}):[]},[$,R?.id,Ve]),Ge=i(()=>Be===void 0?null:le(We).length,[Be,We])??`…`;return B?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`})]}):R?r(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[s(x,{items:[{label:`Integrations`,onClick:()=>d(`/integrations`)},{label:R.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($e,{addonId:R.addonId}),r(`div`,{className:`min-w-0`,children:[s(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:R.name}),r(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[R.addonId,` · `,Ge,` `,t(`integrations.devices`)]})]})]}),r(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[oe&&r(`button`,{onClick:()=>A(!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(ae,{className:`h-3.5 w-3.5`}),`Scan network`]}),!se&&r(`button`,{onClick:()=>T(!0),disabled:!X,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:ce,children:[s(me,{className:`h-3.5 w-3.5`}),ce]}),r(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${je.isPending?`opacity-60`:``} ${R.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[s(re,{checked:R.enabled,onCheckedChange:e=>je.mutate({id:n,enabled:e}),disabled:je.isPending,"aria-label":R.enabled?`Disable integration`:`Enable integration`}),s(`span`,{className:`text-[11px] font-medium ${R.enabled?`text-success`:`text-foreground-subtle`}`,children:R.enabled?`Enabled`:`Disabled`}),je.isPending&&s(O,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Z!==`standalone`&&(ve||J===`device-adoption`)&&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`,children:[s(M,{className:`h-3 w-3`}),t(`integrations.config`)]}),r(`button`,{onClick:()=>L(!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(E,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),s(b,{label:`Restart`,icon:U,title:`Restart "${R.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Ge} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Ne.isPending,action:()=>Ne.mutateAsync({addonId:R.addonId})}),!se&&n&&s(b,{label:t(`integrations.delete`,{defaultValue:`Delete`}),icon:u,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:R.name,count:Ge}),confirmLabel:t(`integrations.confirmDelete`,{defaultValue:`Delete integration`}),triggerVariant:`outline`,confirmVariant:`danger`,className:`border-danger bg-danger/10 text-danger hover:bg-danger hover:text-background`,disabled:Me.isPending,action:()=>Me.mutateAsync({id:n})})]})]}),we&&s(Te,{nodeId:null,addonIds:De,level:`global`,surface:`integration`,title:t(`integrations.settings`,{defaultValue:`Settings`})}),s(te,{context:`integration-detail`,devices:$,trpc:h.trpcClient,integrationOf:Ve,forceIntegrationId:R.id,urlScope:`root`,lsKey:`integration-detail:${R.addonId}`,resolveIntegrationIcon:Ee,resolveParent:ze,onNavigate:He,batchActions:{remove:Pe.mutate,disable:Fe.mutate,enable:Le.mutate},...se?{}:{onDeleteDevice:e=>Pe.mutate({deviceId:e.id})}}),w&&n&&J===`device-adoption`&&s(Ue,{addonId:R.addonId,integrationId:n,onClose:()=>T(!1)}),w&&n&&J===`device-provider`&&s(Ie,{open:w,integrationId:n,addonId:R.addonId,onClose:()=>T(!1)}),D&&R&&s(ke,{open:D,scope:{addonId:R.addonId,label:R.name},onClose:()=>A(!1)}),j&&n&&J!==null&&Z!==null&&s(Xe,{integrationId:n,addonId:R.addonId,name:R.name,kind:J,mode:Z,brokerKind:ue,canTest:fe,trpc:h.trpcClient,onClose:()=>N(!1)}),ee&&s(g,{open:!0,onOpenChange:e=>!e&&L(!1),children:r(C,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[s(v,{className:`mb-0`,children:r(y,{className:`flex items-center gap-2 min-w-0`,children:[s(E,{className:`h-4 w-4 text-primary shrink-0`}),s(`span`,{className:`truncate`,children:R.name}),r(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate font-normal`,children:[R.addonId,n?` · ${n}`:``]})]})}),s(G,{className:`min-h-0 overflow-hidden p-0`,children:s(k,{addonId:R.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(Ae,{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(K,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}function $e({addonId:e}){let t=we(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{Qe as IntegrationDetailPage};
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{_t as l,ct as u,gt as d,ht as f,ot as p,yt as m}from"./player-overlays-7BNWOeGN.js";import{$i as h,An as g,Da as _,Fn as v,In as y,It as b,Kt as x,Lr as S,Mn as C,Ou as w,Qi as T,Qu as E,Ta as D,Td as O,Tt as k,Wa as A,Wd as j,Yu as M,Zi as N,aa as P,br as F,co as I,df as ee,do as L,ea as R,et as te,fo as z,gu as B,ho as V,ia as H,id as U,iu as W,jn as G,kf as K,la as ne,ln as re,lo as ie,nf as q,od as ae,of as J,pa as Y,po as oe,pu as X,ra as se,rd as ce,rt as le,ta as ue,tt as de,tu as fe,ua as pe,ud as me,uo as he,va as ge,wn as Z,yr as _e}from"./src-qXivmhEc.js";import{Er as ve}from"./client-DUrWDWpW.js";import{t as ye}from"./useTranslation-Bc5yH9V9.js";import{$ as be,I as xe,Q as Se,Z as Ce,q as we}from"./index-CCv7bUCn.js";import{t as Te}from"./NodeAddonsSettingsPanel-6nVZk8B5.js";import{t as Ee}from"./device-integration-icon-x7RZ4Ehn.js";import{n as De,r as Oe,t as ke}from"./ScanNetworkModal-BHM4kv3g.js";var Ae=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 Q(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Q(n.fields));return t}function je(t,n,r){let[a,s]=o(`idle`),[c,l]=o({}),u=i(()=>{let e=[];for(let n of t.sections)e.push(...Q(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 Me(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(...Me(n.fields));return t}function Ne(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Pe(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Pe(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function Fe(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function Ie({open:t,integrationId:n,addonId:u,onClose:d}){let{t:f}=ye(),p=a(),[m,h]=o({}),[g,_]=o(!1),[v,y]=o(null),[b,x]=o(Fe),S=D({addonId:u},{enabled:t}),C=S.data?.deviceType??null,T=Y({addonId:u,type:C??ve.Camera},{enabled:t&&S.isSuccess&&C!==null}),j=T.data??null;c(()=>{t&&(h(j?Pe(j.sections.flatMap(e=>e.fields)):{}),x(Fe()),_(!1),y(null))},[t,n,j]);let M=i(()=>({...m,_probeRequestId:b}),[m,b]),N=H({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),P=A(),F=e(async(e,t)=>{_(!0);let n=await P.mutateAsync({addonId:u,type:C??ve.Camera,key:e,value:t,formValues:M});return n.status===`ok`&&n.suggestedValues&&h(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Ne(e[i])&&!Ne(a)&&(r[i]=a,t=!0);return t?r:e}),n},[P,u,M,C]),{testAllStatus:I,hasProbeFields:ee,probeResults:L,handleTestAll:R,clearProbeResult:te}=je(j??{sections:[]},m,F);async function z(e){y(null);try{await N.mutateAsync({addonId:u,type:C??ve.Camera,config:m,integrationId:n}),e?h(j?Pe(j.sections.flatMap(e=>e.fields)):{}):d()}catch(e){y(e instanceof Error?e.message:String(e))}}if(!t)return null;let V=Me((j?.sections??[]).flatMap(e=>e.fields)).filter(e=>Ne(m[e])),U=V.length===0,W=S.isLoading||C!==null&&T.isLoading,G=S.isError||S.isSuccess&&C===null||T.isError||T.isSuccess&&j===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(X,{className:`h-4 w-4`})})]}),s(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:W?s(`div`,{className:`flex items-center justify-center py-8`,children:s(O,{className:`h-5 w-5 animate-spin text-primary`})}):G?r(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[s(w,{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:u}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):s(xe,{schema:j,values:m,onChange:h,onTestField:F,probeResults:L,onClearProbe:te})}),!G&&!W&&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(E,{className:`h-3.5 w-3.5`}),`Test logs`,s(`span`,{className:`font-mono text-[9px] opacity-60`,children:b.slice(0,14)})]}),s(l,{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(k,{addonId:u,requestId:b,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!G&&!W&&(v||V.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(w,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),s(`p`,{className:`text-[11px] text-destructive`,children:v||`Required: ${V.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`)}),!G&&ee&&r(`button`,{type:`button`,onClick:R,disabled:I===`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:[I===`testing`?s(O,{className:`h-3.5 w-3.5 animate-spin`}):s(B,{className:`h-3.5 w-3.5`}),`Test All`]})]}),r(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:()=>z(!0),disabled:G||!U||N.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:()=>z(!1),disabled:G||!U||N.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:N.isPending?f(`integrations.saving`):f(`integrations.save`)})]})]})]})]})}var Le=1500;function $({addonId:e,integrationId:t,jobId:n,onFinished:i}){let{t:a}=ye(),o=N(),c=(R({addonId:e,integrationId:t},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?Le:!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(O,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):c.failed>0?s(w,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):c.state===`cancelled`?s(q,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):s(J,{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 Re(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 ze=`devices`,Be={id:ze,label:`Devices`,isDefault:!0},Ve=2e4,He=100;function Ue({addonId:n,integrationId:i,onClose:l}){let{t:u}=ye(),d=a(),[f,p]=o(new Set),[m,g]=o(new Set),[_,v]=o(new Map),[y,b]=o(null),{data:x}=he(),S=(x??[]).find(e=>e.addonId===n)?.supportsLocationImport??!1,[C,E]=o(!0),D=T({addonId:n,integrationId:i}).data?.filters,k=D&&D.length>0?D:[Be],[A,j]=o(k.find(e=>e.isDefault)?.id??(k.some(e=>e.id===ze)?ze:k[0].id)),M=A!==ze,N=ue(),P=h({addonId:n,integrationId:i,page:1,pageSize:Ve,filter:A}),F=P.refetch,I=N.mutate,L=e(()=>{I({addonId:n,integrationId:i},{onSettled:()=>{F()}})},[I,n,i,F]),R=t(null);c(()=>{let e=`${n}::${i}`;R.current===e||P.isLoading||(R.current=e,(P.data?.candidates.length??0)===0&&L())},[n,i,P.isLoading,P.data,L]);let z=N.isPending,B=N.isError?N.error instanceof Error?N.error.message:String(N.error):null,V=typeof N.data?.lastError==`string`&&N.data.lastError.length>0?N.data.lastError:null,H=P.data?.candidates??[],U=P.isError?P.error instanceof Error?P.error.message:String(P.error):null,G=se(),[K,ne]=o(null),re=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})},[]),ie=e(e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),q=e((e,t)=>{v(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})},[]),ae=e(e=>{let t={};for(let n of e){let e=_.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[_]),J=e(async()=>{b(null);let e=[...f];if(e.length!==0)try{let t=ae(e),{jobId:r}=await G.mutateAsync({addonId:n,integrationId:i,filter:A,childNativeIds:e,...t?{perCandidate:t}:{},...S?{importLocations:C}:{}});ne(r),p(new Set),v(new Map)}catch(e){b(e instanceof Error?e.message:String(e))}},[f,ae,G,n,i,A,S,C]),Y=t(null),oe=e(()=>{K===null||Y.current===K||(Y.current=K,F(),d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]}))},[K,F,d]),le=e(e=>{j(e),p(new Set),g(new Set),v(new Map),b(null)},[]),de=f.size,pe=K!==null&&de===0&&!G.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:[S&&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:C,onChange:e=>E(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(X,{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:[(B??U??V)&&H.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(w,{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:B??U??V})]})]})}),k.length>1&&s(We,{filters:k,activeFilter:A,onSelect:le}),s(`div`,{className:`flex-1 min-h-0`,children:s(te,{mode:`generic`,items:H,pageSize:He,getKey:e=>e.childNativeId,getSearchText:Re,getFilterType:e=>e.type,filterOptions:fe(),filterLabel:u(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:P.isLoading||z&&H.length===0,searchPlaceholder:u(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(B??U??V)&&H.length===0?``:u(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:r(`button`,{type:`button`,onClick:L,disabled:z,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(ce,{className:`h-3.5 w-3.5 ${z?`animate-spin`:``}`}),u(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:u(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>s(Ge,{candidate:e,expandable:!M,expanded:m.has(e.childNativeId),onToggleExpand:()=>ie(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=W(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:()=>re(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(ee,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!M&&m.has(e.childNativeId),renderExpanded:M?void 0:e=>s(Ke,{candidate:e,hiddenChildIds:_.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>q(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:f.has(e.childNativeId)?`bg-primary/5`:``})})]}),y&&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(w,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),s(`p`,{className:`text-[11px] text-destructive`,children:y})]})}),K!==null&&s($,{addonId:n,integrationId:i,jobId:K,onFinished:oe}),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:pe?l:J,disabled:!pe&&(de===0||G.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:[G.isPending&&s(O,{className:`h-3.5 w-3.5 animate-spin`}),pe?u(`integrations.close`,{defaultValue:`Close`}):u(`integrations.addSelected`,{defaultValue:`Add selected`}),!pe&&de>0?` (${de})`:``]})]})]})]})]})}function We({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 Ge({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?l: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 Ke({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:j,{className:`h-3 w-3`})})]},e.childNativeId)})})}n();function qe(e){let t=[];for(let n of e){if(n.type===`group`){t.push(...qe(n.fields));continue}`key`in n&&typeof n.key==`string`&&t.push(n.key)}return t}function Je(e,t){if(!e)return{};let n=new Set(e.sections.flatMap(e=>qe(e.fields))),r={};for(let e of n)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}function Ye(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 Xe({integrationId:e,addonId:t,name:n,kind:o,mode:c,brokerKind:l,canTest:u=!1,trpc:d,onClose:f}){let{t:p}=ye(),m=a(),{data:h,isLoading:_}=L({id:e},{enabled:c===`account`||c===`broker`}),b=i(()=>{let e=h?.brokerId;return typeof e==`string`?e:null},[h]),{data:x,isLoading:S}=_e({addonId:t,nodeId:`hub`},{enabled:c===`account`}),w=i(()=>x?Ye(x):null,[x]),T=oe(),E=(t,n)=>{T.mutate({id:e,settings:t,...n?{secretKeys:[...n]}:{}},{onSuccess:()=>{m.invalidateQueries(),f()}})};return s(g,{open:!0,onOpenChange:e=>!e&&f(),children:r(C,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[s(v,{children:r(y,{children:[p(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]})}),s(G,{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.`})}),b&&r(`p`,{className:`text-[11px] text-foreground`,children:[p(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,s(`span`,{className:`font-mono text-foreground-subtle`,children:b})]}),T.isPending?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[s(O,{className:`h-3 w-3 animate-spin`}),p(`integrations.saving`,{defaultValue:`Saving…`})]}):s(Oe,{kind:l,onResolved:e=>{E({brokerId:e})},onBack:f}),T.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`?_||S?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[s(O,{className:`h-3 w-3 animate-spin`}),p(`integrations.loading`,{defaultValue:`Loading…`})]}):s(De,{addonId:t,configSchema:w,canTest:u,initialName:n,initialConfig:Je(w,h??{}),submitLabel:p(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e,secretKeys:t})=>E(e,t),onBack:f}):s(Z,{trpc:d,addonId:t,nodeId:`hub`,title:n})})]})})}function Ze(e){return e==null?!1:e.sections.some(e=>e.fields.length>0)}n();function Qe(){let{t}=ye(),{integrationId:n}=Se(),l=a(),d=Ce(),[f,m]=be(),h=p(),[w,T]=o(!1),[D,A]=o(!1),[j,N]=o(!1),[ee,L]=o(!1),{data:R,isLoading:B}=ie({id:n??``},{enabled:!!n}),{data:H}=_e({addonId:R?.addonId??``,nodeId:`hub`},{enabled:!!R?.addonId}),{data:W,isSuccess:q}=he(),J=i(()=>{let e=R?.addonId;return!e||!q?null:(W??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[W,R?.addonId,q]),{data:Y}=ne({}),oe=i(()=>(Y?.providers??[]).some(e=>e.addonId===R?.addonId),[Y,R?.addonId]),X=J!==null,se=R?.info?.fixed===!0,ce=X?J===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),ue=i(()=>{let e=R?.addonId;return!e||!q?null:(W??[]).find(t=>t.addonId===e)?.brokerKind??null},[W,R?.addonId,q]),fe=i(()=>{let e=R?.addonId;return!e||!q?!1:(W??[]).find(t=>t.addonId===e)?.canTest===!0},[W,R?.addonId,q]),Z=i(()=>{let e=R?.addonId;return!e||!q?null:(W??[]).find(t=>t.addonId===e)?.mode??null},[W,R?.addonId,q]);c(()=>{f.get(`add`)===`1`&&X&&(T(!0),m(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[f,X,m]);let ve=H!=null&&Array.isArray(H.sections)&&H.sections.some(e=>e.fields.length>0),{data:xe}=F({addonId:R?.addonId??``,nodeId:`hub`},{enabled:!!R?.addonId&&Z!==`account`}),we=Z!==null&&Z!==`account`&&Ze(xe),De=i(()=>R?.addonId?[R.addonId]:[],[R?.addonId]),{data:Oe}=ge({projection:`slim`},{refetchInterval:3e4}),Q=[[`integrations`,`get`],{input:{id:n??``},type:`query`}],je=V({onMutate:async e=>{await l.cancelQueries({queryKey:Q});let t=l.getQueryData(Q);return t!=null&&l.setQueryData(Q,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&l.setQueryData(Q,r.previous)},onSettled:()=>{l.invalidateQueries({queryKey:[[`integrations`]]}),l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Me=I({onSuccess:()=>{l.invalidateQueries({queryKey:[[`integrations`]]}),l.invalidateQueries({queryKey:[[`deviceManager`]]}),d(`/integrations`)}}),Ne=S({onSuccess:()=>{l.invalidateQueries({queryKey:[[`integrations`]]}),l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Pe=_({onSuccess:()=>{l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=P({onSuccess:()=>{l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Le=pe({onSuccess:()=>{l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),$=i(()=>Oe??[],[Oe]),Re=i(()=>{let e=new Map;for(let t of $)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[$]),ze=e(e=>Re.get(e)??null,[Re]),{data:Be}=z(void 0),Ve=i(()=>de(Be),[Be]),He=e(e=>d(`/devices/${String(e)}`),[d]),We=i(()=>{let e=R?.id;return e?$.filter(t=>{let n=Ve(t);return n.kind===`resolved`&&n.integration.id===e}):[]},[$,R?.id,Ve]),Ge=i(()=>Be===void 0?null:le(We).length,[Be,We])??`…`;return B?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`})]}):R?r(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[s(x,{items:[{label:`Integrations`,onClick:()=>d(`/integrations`)},{label:R.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($e,{addonId:R.addonId}),r(`div`,{className:`min-w-0`,children:[s(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:R.name}),r(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[R.addonId,` · `,Ge,` `,t(`integrations.devices`)]})]})]}),r(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[oe&&r(`button`,{onClick:()=>A(!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(ae,{className:`h-3.5 w-3.5`}),`Scan network`]}),!se&&r(`button`,{onClick:()=>T(!0),disabled:!X,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:ce,children:[s(me,{className:`h-3.5 w-3.5`}),ce]}),r(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${je.isPending?`opacity-60`:``} ${R.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[s(re,{checked:R.enabled,onCheckedChange:e=>je.mutate({id:n,enabled:e}),disabled:je.isPending,"aria-label":R.enabled?`Disable integration`:`Enable integration`}),s(`span`,{className:`text-[11px] font-medium ${R.enabled?`text-success`:`text-foreground-subtle`}`,children:R.enabled?`Enabled`:`Disabled`}),je.isPending&&s(O,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Z!==`standalone`&&(ve||J===`device-adoption`)&&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`,children:[s(M,{className:`h-3 w-3`}),t(`integrations.config`)]}),r(`button`,{onClick:()=>L(!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(E,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),s(b,{label:`Restart`,icon:U,title:`Restart "${R.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Ge} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Ne.isPending,action:()=>Ne.mutateAsync({addonId:R.addonId})}),!se&&n&&s(b,{label:t(`integrations.delete`,{defaultValue:`Delete`}),icon:u,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:R.name,count:Ge}),confirmLabel:t(`integrations.confirmDelete`,{defaultValue:`Delete integration`}),triggerVariant:`outline`,confirmVariant:`danger`,className:`border-danger bg-danger/10 text-danger hover:bg-danger hover:text-background`,disabled:Me.isPending,action:()=>Me.mutateAsync({id:n})})]})]}),we&&s(Te,{nodeId:null,addonIds:De,level:`global`,surface:`integration`,title:t(`integrations.settings`,{defaultValue:`Settings`})}),s(te,{context:`integration-detail`,devices:$,trpc:h.trpcClient,integrationOf:Ve,forceIntegrationId:R.id,urlScope:`root`,lsKey:`integration-detail:${R.addonId}`,resolveIntegrationIcon:Ee,resolveParent:ze,onNavigate:He,batchActions:{remove:Pe.mutate,disable:Fe.mutate,enable:Le.mutate},...se?{}:{onDeleteDevice:e=>Pe.mutate({deviceId:e.id})}}),w&&n&&J===`device-adoption`&&s(Ue,{addonId:R.addonId,integrationId:n,onClose:()=>T(!1)}),w&&n&&J===`device-provider`&&s(Ie,{open:w,integrationId:n,addonId:R.addonId,onClose:()=>T(!1)}),D&&R&&s(ke,{open:D,scope:{addonId:R.addonId,label:R.name},onClose:()=>A(!1)}),j&&n&&J!==null&&Z!==null&&s(Xe,{integrationId:n,addonId:R.addonId,name:R.name,kind:J,mode:Z,brokerKind:ue,canTest:fe,trpc:h.trpcClient,onClose:()=>N(!1)}),ee&&s(g,{open:!0,onOpenChange:e=>!e&&L(!1),children:r(C,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[s(v,{className:`mb-0`,children:r(y,{className:`flex items-center gap-2 min-w-0`,children:[s(E,{className:`h-4 w-4 text-primary shrink-0`}),s(`span`,{className:`truncate`,children:R.name}),r(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate font-normal`,children:[R.addonId,n?` · ${n}`:``]})]})}),s(G,{className:`min-h-0 overflow-hidden p-0`,children:s(k,{addonId:R.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(Ae,{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(K,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}function $e({addonId:e}){let t=we(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{Qe as IntegrationDetailPage};
@@ -1 +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,gt as u,ot as d,vt as f}from"./player-overlays-DJRuofy-.js";import{$l as p,M as m,Td as h,Xi as ee,Yu as g,df as _,et as v,fo as y,id as b,ld as x,od as S,pu as te,r as C,rt as ne,sa as w,so as re,tt as T,ud as E,uo as D,va as O,yr as k}from"./src-CmZyEJNe.js";import{t as A}from"./useTranslation-Bc5yH9V9.js";import{$ as ie,K as j,Z as M}from"./index-BURcka-4.js";import{t as N}from"./AdminPage-BDkIRXBS.js";import"./useEventInvalidation-Gvesu9qA.js";import{t as ae}from"./device-integration-icon-DV5lR5V4.js";import{n as oe,r as P,t as F}from"./ScanNetworkModal-682GpB69.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}=A(),[a,l]=o(new Set),u=w(),d=u.data,p=u.isPending||!u.data&&!u.isError;c(()=>{e&&(u.isPending||u.data||u.mutate({addonId:e}))},[e,u]);function m(e){l(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=d??[];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(_,{className:`h-3 w-3 text-primary-foreground`})}),s(f,{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}=A(),a=M(),{data:o,isLoading:c}=D();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,d=r===o.addonId,f=l;return n(`button`,{disabled:f,onClick:()=>{if(!f)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})]}),d?s(h,{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(g,{className:`h-3 w-3`}),i(`integrations.manage`)]}):s(u,{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}=A(),u=M(),d=a(),[f,p]=o(`picker`),[m,g]=o(null),[_,v]=o(null),[y,b]=o(`manual`),[x,S]=o(null),[C,ne]=o(``),[T,E]=o(null),[D,O]=o(null),[ie,j]=o(!1),{data:N}=k({addonId:m??``,nodeId:`hub`},{enabled:m!=null}),ae=r(()=>N?se(N):null,[N]),F=re({onSuccess:()=>d.invalidateQueries({queryKey:[[`integrations`]]})}),V=w(),H=V.data;c(()=>{f!==`discovery`||!_||!m||V.isPending||V.data||V.mutate({addonId:m})},[f,_,m,V]);let ce=ee({onSuccess:()=>d.invalidateQueries({queryKey:[[`deviceManager`]]})});function le(e,t,n,r,i,a,o,s){if(!F.isPending){if(g(e),j(s),b(n),ne(r),O(null),o===`broker`){if(!a){O(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}S(a),p(`broker`);return}if(o===`account`){p(`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(m)try{let t=await F.mutateAsync({addonId:m,name:e.name,settings:e.config,secretKeys:[...e.secretKeys]});v(t.id),y===`auto`||y===`both`?p(`discovery`):q(t.id)}catch{}}async function G(e){if(m)try{let t=await F.mutateAsync({addonId:m,name:C,settings:{brokerId:e}});E(t.id),v(t.id),q(t.id)}catch{}}async function K(e){if(m){for(let t of e){let e=H?.find(e=>e.stableId===t);e&&await ce.mutateAsync({addonId:m,candidate:e,...T===null?{}:{integrationId:T}})}q()}}function q(e){let n=e??_??m;t(),J(),n&&u(`/integrations/${n}`)}function J(){p(`picker`),g(null),v(null),b(`manual`),S(null),ne(``),E(null),O(null),j(!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?m: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(te,{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`&&m&&s(oe,{addonId:m,configSchema:ae??null,canTest:ie,onSave:W,onBack:()=>p(`picker`)}),f===`broker`&&x&&s(P,{kind:x,onResolved:e=>{G(e)},onBack:()=>p(`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(h,{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?l:u,{className:`h-3.5 w-3.5`})}),s(j,{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(m,{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}=A(),a=M(),c=d(),[l]=ie(),[u,f]=o(!1),m=e(()=>f(!0),[]),h=e(()=>f(!1),[]),[ee,g]=o(!1),_=e(()=>g(!0),[]),te=e(()=>g(!1),[]);C([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),C([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:w,isLoading:re,refetch:D}=y(void 0),{data:k,isLoading:j,refetch:oe}=O({projection:`slim`}),P=r(()=>k??[],[k]),I=r(()=>w??[],[w]),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(()=>T(w),[w]),z=r(()=>{let e=new Map;for(let t of ne(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(v,{context:`integration-detail`,devices:P,trpc:c.trpcClient,integrationOf:R,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:ae,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(()=>{D(),oe()},[D,oe]),Q=re||j,$=I.length>0;return n(N,{icon:x,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(b,{className:p(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),n(`button`,{onClick:_,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(S,{className:`h-3.5 w-3.5`}),`Scan network`]}),n(`button`,{onClick:m,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(E,{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(v,{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:u,onClose:h}),s(F,{open:ee,onClose:te})]})}export{W as IntegrationsPage};
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,gt as u,ot as d,vt as f}from"./player-overlays-7BNWOeGN.js";import{$l as p,M as m,Td as h,Xi as ee,Yu as g,df as _,et as v,fo as y,id as b,ld as x,od as S,pu as te,r as C,rt as ne,sa as w,so as re,tt as T,ud as E,uo as D,va as O,yr as k}from"./src-qXivmhEc.js";import{t as A}from"./useTranslation-Bc5yH9V9.js";import{$ as ie,K as j,Z as M}from"./index-CCv7bUCn.js";import{t as N}from"./AdminPage-CXLW-S6O.js";import"./useEventInvalidation-DQO4HeHC.js";import{t as ae}from"./device-integration-icon-x7RZ4Ehn.js";import{n as oe,r as P,t as F}from"./ScanNetworkModal-BHM4kv3g.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}=A(),[a,l]=o(new Set),u=w(),d=u.data,p=u.isPending||!u.data&&!u.isError;c(()=>{e&&(u.isPending||u.data||u.mutate({addonId:e}))},[e,u]);function m(e){l(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=d??[];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(_,{className:`h-3 w-3 text-primary-foreground`})}),s(f,{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}=A(),a=M(),{data:o,isLoading:c}=D();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,d=r===o.addonId,f=l;return n(`button`,{disabled:f,onClick:()=>{if(!f)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})]}),d?s(h,{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(g,{className:`h-3 w-3`}),i(`integrations.manage`)]}):s(u,{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}=A(),u=M(),d=a(),[f,p]=o(`picker`),[m,g]=o(null),[_,v]=o(null),[y,b]=o(`manual`),[x,S]=o(null),[C,ne]=o(``),[T,E]=o(null),[D,O]=o(null),[ie,j]=o(!1),{data:N}=k({addonId:m??``,nodeId:`hub`},{enabled:m!=null}),ae=r(()=>N?se(N):null,[N]),F=re({onSuccess:()=>d.invalidateQueries({queryKey:[[`integrations`]]})}),V=w(),H=V.data;c(()=>{f!==`discovery`||!_||!m||V.isPending||V.data||V.mutate({addonId:m})},[f,_,m,V]);let ce=ee({onSuccess:()=>d.invalidateQueries({queryKey:[[`deviceManager`]]})});function le(e,t,n,r,i,a,o,s){if(!F.isPending){if(g(e),j(s),b(n),ne(r),O(null),o===`broker`){if(!a){O(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}S(a),p(`broker`);return}if(o===`account`){p(`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(m)try{let t=await F.mutateAsync({addonId:m,name:e.name,settings:e.config,secretKeys:[...e.secretKeys]});v(t.id),y===`auto`||y===`both`?p(`discovery`):q(t.id)}catch{}}async function G(e){if(m)try{let t=await F.mutateAsync({addonId:m,name:C,settings:{brokerId:e}});E(t.id),v(t.id),q(t.id)}catch{}}async function K(e){if(m){for(let t of e){let e=H?.find(e=>e.stableId===t);e&&await ce.mutateAsync({addonId:m,candidate:e,...T===null?{}:{integrationId:T}})}q()}}function q(e){let n=e??_??m;t(),J(),n&&u(`/integrations/${n}`)}function J(){p(`picker`),g(null),v(null),b(`manual`),S(null),ne(``),E(null),O(null),j(!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?m: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(te,{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`&&m&&s(oe,{addonId:m,configSchema:ae??null,canTest:ie,onSave:W,onBack:()=>p(`picker`)}),f===`broker`&&x&&s(P,{kind:x,onResolved:e=>{G(e)},onBack:()=>p(`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(h,{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?l:u,{className:`h-3.5 w-3.5`})}),s(j,{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(m,{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}=A(),a=M(),c=d(),[l]=ie(),[u,f]=o(!1),m=e(()=>f(!0),[]),h=e(()=>f(!1),[]),[ee,g]=o(!1),_=e(()=>g(!0),[]),te=e(()=>g(!1),[]);C([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),C([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:w,isLoading:re,refetch:D}=y(void 0),{data:k,isLoading:j,refetch:oe}=O({projection:`slim`}),P=r(()=>k??[],[k]),I=r(()=>w??[],[w]),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(()=>T(w),[w]),z=r(()=>{let e=new Map;for(let t of ne(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(v,{context:`integration-detail`,devices:P,trpc:c.trpcClient,integrationOf:R,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:ae,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(()=>{D(),oe()},[D,oe]),Q=re||j,$=I.length>0;return n(N,{icon:x,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(b,{className:p(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),n(`button`,{onClick:_,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(S,{className:`h-3.5 w-3.5`}),`Scan network`]}),n(`button`,{onClick:m,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(E,{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(v,{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:u,onClose:h}),s(F,{open:ee,onClose:te})]})}export{W as IntegrationsPage};
@@ -1 +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{ct as s}from"./player-overlays-DJRuofy-.js";import{$ as c,An as l,Ci as u,Fn as d,Gi as f,Gn as p,Hn as m,In as h,Ju as g,Mn as _,Nn as v,Q as y,Sd as ee,Si as b,Td as x,ad as S,bi as C,gi as w,gu as T,hi as E,jn as D,jr as te,ld as ne,nr as re,pd as ie,ud as ae,ur as O,vi as oe,xi as k,yi as A}from"./src-CmZyEJNe.js";import{t as j}from"./monitor-smartphone-Df4EIkBh.js";import{Cr as M,Nt as N,tr as P}from"./client-D7C4n8lL.js";import{I as F,Z as I}from"./index-BURcka-4.js";import{t as L}from"./BrokerForm-D3RkMieh.js";import{n as R,r as z,t as B}from"./AddonIntegrationBody-Z6od5ar6.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(O,{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(l,{open:!0,onOpenChange:e=>!e&&r(),children:t(_,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[t(d,{children:[o(h,{children:e}),n&&o(v,{children:n})]}),o(D,{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),h=e.find(e=>X(e)===u.kind)??e[0],g=h?.kind??``,_=h?.addonId,v=E({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:g,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(m,{message:f}),v.isError&&o(m,{message:v.error instanceof Error?v.error.message:String(v.error)}),g&&o(L,{kind:g,..._===void 0?{}:{addonId:_},onSubmit:y,onCancel:r,submitLabel:v.isPending?`Adding…`:`Add broker`,disabled:v.isPending},X(h))]})}function X(e){return e===void 0?``:`${e.addonId??``}::${e.kind}`}function fe({broker:e,onClose:r,onDone:a}){let s=i(),c=w({id:e.id,addonId:e.addonId}),l=b({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(x,{className:`h-3.5 w-3.5 animate-spin`}),` Loading settings…`]}):c.isError?t(`div`,{className:`space-y-3`,children:[o(m,{message:`Failed to load settings: ${c.error instanceof Error?c.error.message:`Unknown error`}`}),o(`div`,{className:`flex justify-end`,children:o(p,{variant:`outline`,size:`sm`,onClick:r,children:`Close`})})]}):t(`div`,{className:`space-y-3`,children:[l.isError&&o(m,{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=re(),[l,d]=a(null),f=u({onSuccess:e=>d(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>d({ok:!1,error:e instanceof Error?e.message:String(e)})}),m=k({onSuccess:()=>{r.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),h=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(p,{variant:`outline`,size:`sm`,onClick:()=>f.mutate({id:e.id,addonId:e.addonId}),disabled:f.isPending,title:`Test connection`,children:[f.isPending?o(x,{className:`h-3 w-3 animate-spin`}):o(T,{className:`h-3 w-3`}),`Test`]}),t(p,{variant:`outline`,size:`sm`,onClick:()=>n(e),title:`Edit`,children:[o(ie,{className:`h-3 w-3`}),` Edit`]}),t(p,{variant:`outline`,size:`sm`,className:`border-danger/40 text-danger hover:bg-danger/10`,onClick:()=>{h()},disabled:m.isPending,title:`Delete`,children:[m.isPending?o(x,{className:`h-3 w-3 animate-spin`}):o(s,{className:`h-3 w-3`}),`Delete`]})]})})]})}function me({addonId:e}={}){let r=A({}),i=C(),s=n(()=>ue(r.data).filter(t=>e===void 0||t.addonId===e),[r.data,e]),[c,l]=a(!1),[u,d]=a(null),f=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(p,{variant:`primary`,size:`sm`,onClick:()=>l(!0),disabled:f.length===0,title:f.length===0?`No broker providers available`:void 0,children:[o(ae,{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(x,{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:f,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:g,installLabel:`Add export`},{kind:`email`,label:`Email`,icon:ee,installLabel:`Add email provider`},{kind:`broker`,label:`Message brokers`,icon:S,installLabel:`Add broker addon`}];function ye(){let e=te(void 0,{refetchInterval:$}),i=I();return o(z,{icon:ne,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 l=Q(n.processState);return[{id:n.addonId,name:n.displayName,fallbackIcon:e.icon,state:l.state,stateLabel:l.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(c,{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(y,{addonId:t,onOpenDevice:n,showSetup:!1})}]:e===`broker`?[{id:`connections`,title:`Connections`,icon:S,content:o(me,{addonId:t})}]:[]}function xe({processState:e}){let{state:t,label:n}=Q(e);return o(O,{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}=oe({addonId:e},{refetchInterval:$,retry:!1}),n=M.safeParse(t);if(!n.success)return null;let{brokerCount:r,connectedCount:i}=n.data;return o(O,{variant:`info`,className:R,children:`${r} connection${r===1?``:`s`}${i>0?` · ${i} connected`:``}`})}function we({addonId:e}){let{data:t}=f({addonId:e},{refetchInterval:$,retry:!1}),n=P.safeParse(t);if(!n.success)return null;let{linkState:r,exposedDeviceCount:i}=n.data;return o(O,{variant:r===`linked`?`success`:r===`error`?`danger`:`default`,className:R,children:`${r} · ${i} exposed`})}export{ye as IntegrationsPage};
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{ct as s}from"./player-overlays-7BNWOeGN.js";import{$ as c,An as l,Ci as u,Fn as d,Gi as f,Gn as p,Hn as m,In as h,Ju as g,Mn as _,Nn as v,Q as y,Sd as ee,Si as b,Td as x,ad as S,bi as C,gi as w,gu as T,hi as E,jn as D,jr as te,ld as ne,nr as re,pd as ie,ud as ae,ur as O,vi as oe,xi as k,yi as A}from"./src-qXivmhEc.js";import{t as j}from"./monitor-smartphone-CKSor6O7.js";import{Cr as M,Nt as N,tr as P}from"./client-DUrWDWpW.js";import{I as F,Z as I}from"./index-CCv7bUCn.js";import{t as L}from"./BrokerForm-CcqnNboj.js";import{n as R,r as z,t as B}from"./AddonIntegrationBody-Bz69Wys3.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(O,{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(l,{open:!0,onOpenChange:e=>!e&&r(),children:t(_,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[t(d,{children:[o(h,{children:e}),n&&o(v,{children:n})]}),o(D,{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),h=e.find(e=>X(e)===u.kind)??e[0],g=h?.kind??``,_=h?.addonId,v=E({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:g,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(m,{message:f}),v.isError&&o(m,{message:v.error instanceof Error?v.error.message:String(v.error)}),g&&o(L,{kind:g,..._===void 0?{}:{addonId:_},onSubmit:y,onCancel:r,submitLabel:v.isPending?`Adding…`:`Add broker`,disabled:v.isPending},X(h))]})}function X(e){return e===void 0?``:`${e.addonId??``}::${e.kind}`}function fe({broker:e,onClose:r,onDone:a}){let s=i(),c=w({id:e.id,addonId:e.addonId}),l=b({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(x,{className:`h-3.5 w-3.5 animate-spin`}),` Loading settings…`]}):c.isError?t(`div`,{className:`space-y-3`,children:[o(m,{message:`Failed to load settings: ${c.error instanceof Error?c.error.message:`Unknown error`}`}),o(`div`,{className:`flex justify-end`,children:o(p,{variant:`outline`,size:`sm`,onClick:r,children:`Close`})})]}):t(`div`,{className:`space-y-3`,children:[l.isError&&o(m,{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=re(),[l,d]=a(null),f=u({onSuccess:e=>d(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>d({ok:!1,error:e instanceof Error?e.message:String(e)})}),m=k({onSuccess:()=>{r.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),h=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(p,{variant:`outline`,size:`sm`,onClick:()=>f.mutate({id:e.id,addonId:e.addonId}),disabled:f.isPending,title:`Test connection`,children:[f.isPending?o(x,{className:`h-3 w-3 animate-spin`}):o(T,{className:`h-3 w-3`}),`Test`]}),t(p,{variant:`outline`,size:`sm`,onClick:()=>n(e),title:`Edit`,children:[o(ie,{className:`h-3 w-3`}),` Edit`]}),t(p,{variant:`outline`,size:`sm`,className:`border-danger/40 text-danger hover:bg-danger/10`,onClick:()=>{h()},disabled:m.isPending,title:`Delete`,children:[m.isPending?o(x,{className:`h-3 w-3 animate-spin`}):o(s,{className:`h-3 w-3`}),`Delete`]})]})})]})}function me({addonId:e}={}){let r=A({}),i=C(),s=n(()=>ue(r.data).filter(t=>e===void 0||t.addonId===e),[r.data,e]),[c,l]=a(!1),[u,d]=a(null),f=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(p,{variant:`primary`,size:`sm`,onClick:()=>l(!0),disabled:f.length===0,title:f.length===0?`No broker providers available`:void 0,children:[o(ae,{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(x,{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:f,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:g,installLabel:`Add export`},{kind:`email`,label:`Email`,icon:ee,installLabel:`Add email provider`},{kind:`broker`,label:`Message brokers`,icon:S,installLabel:`Add broker addon`}];function ye(){let e=te(void 0,{refetchInterval:$}),i=I();return o(z,{icon:ne,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 l=Q(n.processState);return[{id:n.addonId,name:n.displayName,fallbackIcon:e.icon,state:l.state,stateLabel:l.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(c,{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(y,{addonId:t,onOpenDevice:n,showSetup:!1})}]:e===`broker`?[{id:`connections`,title:`Connections`,icon:S,content:o(me,{addonId:t})}]:[]}function xe({processState:e}){let{state:t,label:n}=Q(e);return o(O,{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}=oe({addonId:e},{refetchInterval:$,retry:!1}),n=M.safeParse(t);if(!n.success)return null;let{brokerCount:r,connectedCount:i}=n.data;return o(O,{variant:`info`,className:R,children:`${r} connection${r===1?``:`s`}${i>0?` · ${i} connected`:``}`})}function we({addonId:e}){let{data:t}=f({addonId:e},{refetchInterval:$,retry:!1}),n=P.safeParse(t);if(!n.success)return null;let{linkState:r,exposedDeviceCount:i}=n.data;return o(O,{variant:r===`linked`?`success`:r===`error`?`danger`:`default`,className:R,children:`${r} · ${i} exposed`})}export{ye as IntegrationsPage};