@camstack/addon-admin-ui 1.2.289 → 1.2.291
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AddonCollectionPage-BKRsM_qT.js → AddonCollectionPage-C9l7ftV0.js} +1 -1
- package/dist/assets/Addons-TAyselNK.js +1 -0
- package/dist/assets/{AdminTabs-Os_saxNF.js → AdminTabs-CDIoD5NP.js} +1 -1
- package/dist/assets/AiProfiles-Kf7NoHuq.js +3 -0
- package/dist/assets/{BrokerForm-BhInPTAL.js → BrokerForm-DoQjILhI.js} +1 -1
- package/dist/assets/Build-rTKtg_tx.js +32 -0
- package/dist/assets/{Capabilities-CfFtLbNU.js → Capabilities-PhNKP5DZ.js} +1 -1
- package/dist/assets/{CapabilityBadges-C25C3fOL.js → CapabilityBadges-yL7FrxsG.js} +1 -1
- package/dist/assets/Cluster-DeKFim31.js +11 -0
- package/dist/assets/CompositionEditor-Bu6ufcCG.js +1 -0
- package/dist/assets/CompositionEditorPage-BekLUIPP.js +1 -0
- package/dist/assets/Data-DZ4iVZ3r.js +1 -0
- package/dist/assets/DetectionIntelligence-BAE1rpvx.js +1 -0
- package/dist/assets/DeviceAggregateSection-BEv0e5dZ.js +1 -0
- package/dist/assets/DeviceDetail-DTzUAv1F.js +2 -0
- package/dist/assets/{Devices-Dho7Ah7I.js → Devices-DnvCLFMr.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-CZNi9Xqf.js → EmbedPlayerPage-DN8DYcVD.js} +1 -1
- package/dist/assets/Events-DIW0IfdN.js +1 -0
- package/dist/assets/{FormBuilder-BAhlMxtA.js → FormBuilder-Bytus5Tf.js} +1 -1
- package/dist/assets/Identity-DuejF2qu.js +1 -0
- package/dist/assets/IntegrationDetail-ChJqGuPV.js +1 -0
- package/dist/assets/Integrations-BmXG4x-9.js +1 -0
- package/dist/assets/Integrations-aQZGbD9Y.js +1 -0
- package/dist/assets/Locations-DpmnmMuB.js +3 -0
- package/dist/assets/{Logs-DjLrB_bz.js → Logs-DPVRa9WP.js} +1 -1
- package/dist/assets/{ModelLicenses-Ju1FDfQO.js → ModelLicenses-CdSE1ZrE.js} +1 -1
- package/dist/assets/{MotionZonesSettings-B68pkoTl.js → MotionZonesSettings-Bz_Qdfpp.js} +1 -1
- package/dist/assets/{MyAccess-C3qL3L21.js → MyAccess-Bkvp6GTW.js} +1 -1
- package/dist/assets/Network-Ds6N6CJ-.js +1 -0
- package/dist/assets/{NodeAddonsSettingsPanel-Bdu5lrTB.js → NodeAddonsSettingsPanel-skqKbqMj.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-BZONzZ2s.js → NodeInferenceDevices-B2JedlHO.js} +1 -1
- package/dist/assets/Notifications-BV-4IwuU.js +1 -0
- package/dist/assets/Pipeline-CAt-bvHB.js +1 -0
- package/dist/assets/{Plates-CQyh_1JS.js → Plates-DzEWm4_s.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-DyHXfkSl.js → PrivacyMaskSettings-CbDYhk2o.js} +1 -1
- package/dist/assets/{ProviderIcon-DtoRs3L2.js → ProviderIcon-BBtV-kNn.js} +1 -1
- package/dist/assets/Recordings-DdR7d9ou.js +1 -0
- package/dist/assets/{ScanNetworkModal-BS1CjdFP.js → ScanNetworkModal-ClrFcKCl.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-DugNwyJ4.js → SceneMonitorEditor-DMCML24R.js} +1 -1
- package/dist/assets/{Scenes-DLmoTFWA.js → Scenes-C9RWMuVR.js} +1 -1
- package/dist/assets/{Settings-2K2Vjg4p.js → Settings-ucmI8LXJ.js} +1 -1
- package/dist/assets/{Showroom-DgbL-U1t.js → Showroom-Bdt-D63k.js} +1 -1
- package/dist/assets/{StorageLocationsPanel-DWjCqCv9.js → StorageLocationsPanel-4Tgyiymp.js} +1 -1
- package/dist/assets/{Terminal-CnRI_Gmz.js → Terminal-BrAUK0eG.js} +3 -3
- package/dist/assets/{Viewer-DHTF4S4u.js → Viewer-DQrms2_u.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BHZ13lQR.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Dq0fVJWM.js} +1 -1
- package/dist/assets/{archive-BmbkFLtr.js → archive-BUE32U7F.js} +1 -1
- package/dist/assets/{authed-media-Bhswngiz.js → authed-media-MbHpXS-m.js} +1 -1
- package/dist/assets/{boxes-BDauq_GC.js → boxes-CNe0g7jU.js} +1 -1
- package/dist/assets/circle-slash-fCLxXnZu.js +1 -0
- package/dist/assets/{debounced-invalidate-BMyWMwma.js → debounced-invalidate-nyczfeAF.js} +1 -1
- package/dist/assets/{device-integration-icon-CowSzbMe.js → device-integration-icon-fftDP3wp.js} +1 -1
- package/dist/assets/dist-B4mIz_Rx.js +349 -0
- package/dist/assets/{dist-CEfzm_eL.js → dist-CUNGowXS.js} +1 -1
- package/dist/assets/{face-bbox-Bw09XNv0.js → face-bbox-BDj6xgbi.js} +1 -1
- package/dist/assets/{hard-drive-download-D8cJmcOG.js → hard-drive-download-BwgF6zZo.js} +1 -1
- package/dist/assets/{hostInit-DawD1ezr.js → hostInit-BruU7SYo.js} +1 -1
- package/dist/assets/index-C8vIAU5v.css +2 -0
- package/dist/assets/index-DrF3b0h3.js +4 -0
- package/dist/assets/{layers-DRiv_qOz.js → layers-DH10EL_n.js} +1 -1
- package/dist/assets/{location-owned-usage-CqCPlIDe.js → location-owned-usage-bz1tVRVt.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-a0a0ef95.js → mf-entry-bootstrap-0-ad4a1c50.js} +2 -2
- package/dist/assets/{player-overlays-Dpyv2MuF.js → player-overlays-gbZ2vznV.js} +1 -1
- package/dist/assets/remoteEntry-BaEDGIXI.js +1 -0
- package/dist/assets/{send-DJxsQciO.js → send-BO7aVZEW.js} +1 -1
- package/dist/assets/{settings-2-DhdVszMB.js → settings-2-CYX3Zwgy.js} +1 -1
- package/dist/assets/{square-check-big-CyuyrB82.js → square-check-big-BhfLbxK8.js} +1 -1
- package/dist/assets/src-4fqKwwai.js +349 -0
- package/dist/assets/src-BqkvLgRS.js +67 -0
- package/dist/assets/{use-scenes-feed-C1fOUeee.js → use-scenes-feed-CoCQD-QZ.js} +1 -1
- package/dist/assets/{use-stationary-objects-3iUSTAxf.js → use-stationary-objects-BvLkAOl-.js} +1 -1
- package/dist/assets/useDevice-D541xOeQ.js +1 -0
- package/dist/assets/useEventInvalidation-DxM8yEtK.js +1 -0
- package/dist/assets/{useNodeUrlSelection-BAKjYDmK.js → useNodeUrlSelection-DBqemZZ0.js} +1 -1
- package/dist/assets/user-round-DMTk-6Io.js +1 -0
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DC2EQBm-.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-S6IHSmgw.js} +2 -2
- package/dist/index.html +6 -6
- package/dist/server/addon.js +232 -47
- package/package.json +1 -1
- package/dist/assets/Addons-Dd0di_Ic.js +0 -1
- package/dist/assets/AiProfiles-DXtr0dUS.js +0 -3
- package/dist/assets/Build-DTuK1-77.js +0 -32
- package/dist/assets/Cluster-CWcQYGW_.js +0 -11
- package/dist/assets/Data-DgPd7eUU.js +0 -1
- package/dist/assets/DetectionIntelligence-C3Hrp_v2.js +0 -1
- package/dist/assets/DeviceAggregateSection-DdAM0MHQ.js +0 -1
- package/dist/assets/DeviceDetail-NT2tY24m.js +0 -2
- package/dist/assets/Events-C9dSg_g9.js +0 -1
- package/dist/assets/Identity-BYdygzct.js +0 -1
- package/dist/assets/IntegrationDetail-DblGvkgb.js +0 -1
- package/dist/assets/Integrations-qYjBg30Q.js +0 -1
- package/dist/assets/Integrations-ujAFaZz4.js +0 -1
- package/dist/assets/Locations-q3oIkzY2.js +0 -3
- package/dist/assets/Network-DrRLH46C.js +0 -1
- package/dist/assets/Notifications-BCvyB2lu.js +0 -1
- package/dist/assets/Pipeline-BfuxKrMr.js +0 -1
- package/dist/assets/Recordings-C2W6EuhQ.js +0 -1
- package/dist/assets/circle-slash-OkyAP_uM.js +0 -1
- package/dist/assets/dist-B-ttjQPE.js +0 -349
- package/dist/assets/index-Cz9U1hKX.css +0 -2
- package/dist/assets/index-SOjqIyqv.js +0 -4
- package/dist/assets/remoteEntry-ahvkDE5X.js +0 -1
- package/dist/assets/src-BjMTOeHt.js +0 -349
- package/dist/assets/src-DeANpHOz.js +0 -67
- package/dist/assets/useDevice-CEHL86RO.js +0 -1
- package/dist/assets/useEventInvalidation-Bp3xnYIe.js +0 -1
- package/dist/assets/user-round-CWLSjfaj.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Q as e,S as t,W as n,a as r,b as i,o as a,q as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{_t as c,at as l,gt as u,st as d,yt as f}from"./player-overlays-gbZ2vznV.js";import{Ac as p,C as m,Cc as h,Dc as g,Du as _,Ec as v,Fc as y,Gc as b,Gn as x,Hl as S,Lu as C,Mc as w,Nc as T,Oc as E,Pc as ee,S as D,Sc as te,Tc as O,Tl as k,Vu as A,Wl as j,Wn as M,au as ne,bn as re,cn as N,jc as P,kc as ie,m as F,nu as I,ou as L,p as R,su as z,tl as ae,ut as oe,vi as se,vl as B,wc as ce,wl as V,xc as le,yn as H,yu as ue}from"./src-BqkvLgRS.js";import{a as de,i as fe,o as U,s as pe}from"./src-4fqKwwai.js";import{b as W,u as G}from"./index-DrF3b0h3.js";import{t as K}from"./AdminPage-CiKtOLQm.js";import{t as me}from"./AdminTabs-CDIoD5NP.js";import{t as he}from"./AddonCollectionPage-C9l7ftV0.js";import{t as ge}from"./addon-display-names-DvSEQty-.js";var _e=f(`book-open`,[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z`,key:`ruj8y`}]]),ve=f(`key-square`,[[`path`,{d:`M12.4 2.7a2.5 2.5 0 0 1 3.4 0l5.5 5.5a2.5 2.5 0 0 1 0 3.4l-3.7 3.7a2.5 2.5 0 0 1-3.4 0L8.7 9.8a2.5 2.5 0 0 1 0-3.4z`,key:`165ttr`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`m9.4 10.6-6.814 6.814A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814`,key:`1ubxi2`}]]),ye=f(`link`,[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]);e();function be({userId:e,username:n,onClose:r}){let o=a(),c=H(),l=O({userId:e}),u=l.data,d=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),f=ce({onSuccess:()=>{d(),r()}}),p=l.isLoading?`loading`:u?.enabled?`enrolled`:`not_enrolled`;return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4`,children:t(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden`,children:[t(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-border`,children:[t(`div`,{className:`flex items-center gap-2`,children:[s(B,{className:`h-4 w-4 text-primary`}),t(`div`,{children:[s(`div`,{className:`text-sm font-medium text-foreground`,children:`Two-factor authentication`}),t(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,s(`span`,{className:`font-mono`,children:n})]})]})]}),s(`button`,{onClick:r,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:s(b,{className:`h-4 w-4`})})]}),t(`div`,{className:`p-4 space-y-4`,children:[p===`loading`&&t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(I,{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(z,{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(C,{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(N,{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(I,{className:`h-3 w-3 animate-spin`}):s(b,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function q({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 xe({scopes:e,isAdmin:n,invalidReason:a}){let o=l(),c=r({queryKey:[`auth`,`previewScope`,e,n],enabled:a===null,queryFn:()=>o.trpcClient.auth.previewScope.query({scopes:[...e],isAdmin:n})}),{data:u}=se({projection:`slim`}),f=u?.length??0;if(a!==null)return s(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:t(`p`,{className:`flex items-center gap-1.5 text-[11px] text-warning`,children:[s(k,{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(I,{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(q,{icon:ue,label:`Devices they can see`,count:p.device.view.deviceCount,all:p.device.view.all,total:f}),s(q,{icon:j,label:`Devices they can operate`,count:p.device.create.deviceCount,all:p.device.create.all,total:f}),s(q,{icon:d,label:`Devices they can delete`,count:p.device.delete.deviceCount,all:p.device.delete.all,total:f}),t(`div`,{className:`border-t border-border pt-2 text-[10px] text-foreground-subtle`,children:[`System access: `,p.system.length===0?`none`:p.system.join(`, `),p.capabilities.length>0&&t(i,{children:[` · Extra capabilities: `,p.capabilities.map(e=>e.name).join(`, `)]}),p.addons.length>0&&t(i,{children:[` · Addons: `,p.addons.map(e=>e.name).join(`, `)]})]}),p.device.view.deviceCount===0&&s(`p`,{className:`text-[10px] text-warning`,children:`This user will not be able to see any device.`})]})})}function Se(e){let t=U(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 Ce(e){return e.mode===`advanced`?e.advancedScopes:e.roleId===null?[]:de({roleId:e.roleId,selector:e.selector,includeLinked:e.includeLinked})}function we({user:e,onClose:r,onSubmit:a,submitting:l,callerScopes:d}){let f=n(()=>Se(e.scopes??[]),[e.scopes]),[p,m]=o(f),[h,g]=o(f.mode===`advanced`),_=n(()=>Ce(p),[p]),v=!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.`:F(_),[e.isAdmin,p.mode,p.roleId,_]),x=e=>m({...p,...e});return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4 pt-[calc(1rem+env(safe-area-inset-top))] pb-[calc(1rem+env(safe-area-inset-bottom))]`,children:t(`div`,{className:`flex max-h-full w-full max-w-2xl flex-col rounded-lg border border-border bg-surface shadow-xl`,children:[t(`div`,{className:`flex shrink-0 items-start justify-between border-b border-border px-4 py-3`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`text-sm font-semibold text-foreground`,children:[`Access — `,e.username]}),s(`div`,{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.`})]}),s(`button`,{onClick:r,className:`shrink-0 text-foreground-subtle hover:text-foreground`,title:`Close`,children:s(b,{className:`h-4 w-4`})})]}),t(`div`,{className:`min-h-0 flex-1 space-y-4 overflow-y-auto px-4 py-4`,children:[v&&t(`div`,{className:`flex items-start gap-2 rounded-lg border border-warning/40 bg-warning/10 p-3`,children:[s(k,{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:fe.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:()=>x({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:_}),g(!0);return}g(!1),m(Se(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?c:u,{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(R,{value:p.advancedScopes,onChange:e=>x({mode:`advanced`,advancedScopes:e}),clampToParent:d,emptyHint:t(i,{children:[`No grants.`,` `,s(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until one is added.`]})})]})]}),p.mode===`role`&&t(`section`,{className:`space-y-2`,children:[s(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`2 · On which devices`}),s(D,{value:p.selector,onChange:e=>x({selector:e}),includeLinked:p.includeLinked,onIncludeLinkedChange:e=>x({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(xe,{scopes:_,isAdmin:e.isAdmin,invalidReason:y})]})]}),t(`div`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3`,children:[s(`button`,{onClick:r,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground`,children:`Cancel`}),s(`button`,{onClick:()=>a([..._]),disabled:l||y!==null,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:l?s(I,{className:`h-3 w-3 animate-spin`}):`Save access`})]})]})})}e();var Te=8;function Ee(){let e=a(),{user:n}=G(),[r,i]=o(!1),[c,l]=o(``),[u,f]=o(``),[m,g]=o(!1),[_,v]=o(null),{data:x,isLoading:C,isError:w}=ie(),T=H(),E=re(),D=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),O=te({onSuccess:()=>{D(),i(!1),l(``),f(``),g(!1),v(null)},onError:e=>{v(e instanceof Error?e.message:`Failed to create user`)}}),k=h({onSuccess:D}),A=y({onSuccess:D}),j=p({onSuccess:D}),M=ee({onSuccess:()=>{D(),P(null)}}),[N,P]=o(null),[F,L]=o(null),R=x??[];async function z(e){await T({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`})&&k.mutate({id:e.id})}async function ae(e){let t=await E({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<Te?`Password must be at least ${String(Te)} characters.`:null});t===null||t.length===0||await T({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&j.mutate({id:e.id,newPassword:t})}function se(e,t){t!==e.isAdmin&&A.mutate({id:e.id,isAdmin:t})}function ce(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}return t(K,{children:[s(`div`,{className:`flex items-center justify-end`,children:t(`button`,{onClick:()=>i(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm hover:bg-primary/90`,children:[s(S,{className:`h-3.5 w-3.5`}),`Create User`]})}),r&&t(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[t(`div`,{className:`flex items-center justify-between`,children:[s(`span`,{className:`text-xs font-medium text-foreground`,children:`New User`}),s(`button`,{onClick:()=>i(!1),className:`text-foreground-subtle hover:text-foreground`,children:s(b,{className:`h-4 w-4`})})]}),t(`div`,{className:`grid grid-cols-3 gap-3`,children:[t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),s(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`john`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Password`}),s(`input`,{type:`password`,value:u,onChange:e=>f(e.target.value),placeholder:`••••••••`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),t(`label`,{className:`flex items-center gap-2 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:m,onChange:e=>g(e.target.checked),className:`rounded border-border focus:ring-primary`}),s(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),_&&s(`p`,{className:`text-[10px] text-danger`,children:_}),t(`div`,{className:`flex justify-end gap-2`,children:[s(`button`,{onClick:()=>i(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),s(`button`,{onClick:()=>O.mutate({username:c,password:u,isAdmin:m}),disabled:O.isPending||!c||!u,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:O.isPending?`Creating...`:`Create`})]})]}),C&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),w&&s(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!C&&!w&&R.length===0&&s(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>k.isPending&&k.variables?.id===e.id||A.isPending&&A.variables?.id===e.id||j.isPending&&j.variables?.id===e.id;return s(oe,{columns:[{key:`username`,header:`Username`,render:e=>e.username},{key:`isAdmin`,header:`Admin`,render:n=>t(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:n.isAdmin,onChange:e=>se(n,e.target.checked),disabled:e(n),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),s(`span`,{className:n.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:n.isAdmin?`Admin`:`Regular`})]})},{key:`scopes`,header:`Access`,render:e=>e.isAdmin?s(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:`everything (admin)`}):t(`button`,{onClick:()=>P(e),className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] hover:bg-foreground-subtle/10`,title:`Configure access`,children:[s(V,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(De,{scopes:e.scopes??[]})]})},{key:`createdAt`,header:`Created`,render:e=>s(`span`,{className:`text-foreground-subtle`,children:ce(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:r=>{let i=e(r);return t(`div`,{className:`flex items-center justify-end gap-1`,children:[r.id!==n?.id&&r.totpEnabled&&t(`button`,{onClick:()=>L(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Remove two-factor authentication`,children:[s(B,{className:`h-3 w-3`}),`Remove 2FA`]}),t(`button`,{onClick:()=>ae(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Reset password`,children:[s(ne,{className:`h-3 w-3`}),`Reset password`]}),t(`button`,{onClick:()=>z(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete user`,children:[i?s(I,{className:`h-3 w-3 animate-spin`}):s(d,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:R,rowKey:e=>e.id,minWidthPx:560})})(),F&&s(be,{userId:F.id,username:F.username,onClose:()=>L(null)}),N&&s(Oe,{user:N,onClose:()=>P(null),onSubmit:e=>M.mutate({userId:N.id,scopes:e}),submitting:M.isPending})]})}function De({scopes:e}){if(e.length===0)return s(`span`,{className:`font-medium text-warning`,children:`No access`});let n=U(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:pe(n.roleId).label}),` ·`,` `,m(n.selector)]})}function Oe(e){let{user:t}=G(),n=t?.isAdmin===!0;return s(we,{...e,callerScopes:n?null:t?.scopes??[]})}e();var ke=`bg-primary/10 text-primary`,Ae=`bg-foreground-subtle/10 text-foreground-subtle`;function J(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function je(e){return e?e===`*`?`*`:e.join(`, `):``}function Me(){let e=a(),r=H(),{data:i,isLoading:c}=v(),{data:l}=ie(),u=n(()=>i??[],[i]),f=n(()=>l??[],[l]),p=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),m=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[h,g]=o(!1),[_,y]=o(null),b=P({onSuccess:p}),x=le({onSuccess:({token:e,record:t})=>{m(),g(!1),y({token:e,label:t.name})}}),S=T({onSuccess:m}),C=async(e,t)=>{await r({title:`Revoke "${t}"?`,message:`Any client using this token will lose access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&b.mutate({id:e})},w=async(e,t)=>{await r({title:`Revoke "${t}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&S.mutate({id:e})};return t(K,{children:[t(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[s(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Issue scoped tokens to grant a user a narrow surface — a specific addon, integration, or capability. Every token MUST be scoped: revoking it has predictable blast radius.`}),t(`button`,{onClick:()=>g(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,disabled:f.length===0,title:f.length===0?`Create a user first`:`Issue a scoped token`,children:[s(V,{className:`h-3.5 w-3.5`}),`New token`]})]}),t(Ne,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[f.length===0&&s(Fe,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),f.map(e=>s(Le,{userId:e.id,username:e.username,onRevoke:(e,t)=>{w(e,t)},revokePending:S.isPending,revokeId:S.variables?.id},e.id))]}),u.length>0&&s(Ne,{title:`Legacy API keys`,subtitle:`${u.length} pre-existing — revoke only`,children:s(Ie,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:u.map(e=>{let n=!!e.isAdmin,r=b.isPending&&b.variables?.id===e.id;return t(`tr`,{className:`hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.label}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:s(`span`,{className:`inline-block rounded px-2 py-0.5 text-[10px] uppercase tracking-wide ${n?ke:Ae}`,children:n?`admin`:`regular`})}),t(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border text-foreground-subtle`,children:je(e.allowedProviders)||`all`}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.createdAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:t(`button`,{onClick:()=>{C(e.id,e.label)},disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[r?s(I,{className:`h-3 w-3 animate-spin`}):s(d,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),c&&s(Pe,{}),h&&s(Re,{users:f.map(e=>({id:e.id,username:e.username})),onClose:()=>g(!1),onSubmit:e=>x.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:x.isPending}),_&&s(ze,{token:_.token,label:_.label,onClose:()=>y(null)})]})}function Ne({title:e,subtitle:n,children:r}){return t(`div`,{className:`space-y-2`,children:[t(`div`,{className:`flex items-baseline justify-between`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),n&&s(`span`,{className:`text-[10px] text-foreground-subtle`,children:n})]}),r]})}function Pe(){return s(`div`,{className:`space-y-2`,children:[1,2].map(e=>s(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function Fe({text:e}){return s(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function Ie({headers:e,rows:n}){return s(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full text-xs min-w-[640px]`,children:[s(`thead`,{children:s(`tr`,{children:e.map((t,n)=>s(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),s(`tbody`,{children:n})]})})}function Le({userId:e,username:n,onRevoke:r,revokePending:i,revokeId:a}){let{data:o,isLoading:c}=E({userId:e}),l=o??[];return c||l.length===0?null:t(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[11px] font-medium text-foreground`,children:n}),s(Ie,{headers:[`Name`,`Prefix`,`Scopes`,`Expires`,`Last used`,`Created`,``],rows:l.map(e=>{let n=i&&a===e.id;return t(`tr`,{className:`hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.name}),t(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:s(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,n)=>t(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:[e.type,`:`,e.type===`device`?`[${m(e.selector)}]`:e.target]},n))})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.expiresAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.createdAt)}),s(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:t(`button`,{onClick:()=>r(e.id,e.name),disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[n?s(I,{className:`h-3 w-3 animate-spin`}):s(d,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function Re({users:e,onClose:n,onSubmit:r,submitting:i}){let{user:a}=G(),c=a?.isAdmin===!0?null:a?.scopes??[],[l,u]=o(e[0]?.id??``),[d,f]=o(``),[p,m]=o([{type:`capability`,target:``,access:[`view`,`create`]}]),[h,g]=o(``),_=F(p),v=l!==``&&d.trim().length>0&&p.length>0&&_===null&&!i;return t(Be,{title:`Create scoped token`,onClose:n,children:[t(`div`,{className:`space-y-3`,children:[s(Y,{label:`On behalf of user`,children:s(`select`,{value:l,onChange:e=>u(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>s(`option`,{value:e.id,children:e.username},e.id))})}),s(Y,{label:`Name`,children:s(`input`,{value:d,onChange:e=>f(e.target.value),placeholder:`cloudflare-tunnel-route`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})}),t(Y,{label:`Scopes`,hint:`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`,children:[s(R,{value:p,onChange:m,clampToParent:c}),_&&s(`p`,{className:`mt-1 text-[10px] text-danger`,children:_})]}),s(Y,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:s(`input`,{type:`number`,min:1,value:h,onChange:e=>g(e.target.value),placeholder:`30`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})})]}),t(Ve,{children:[s(`button`,{onClick:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),t(`button`,{onClick:()=>{let e=parseInt(h,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;r({userId:l,name:d.trim(),scopes:p,expiresAt:t})},disabled:!v,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[i?s(I,{className:`h-3.5 w-3.5 animate-spin`}):s(V,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function ze({token:e,label:n,onClose:r}){let[i,a]=o(!1),c=async()=>{try{await navigator.clipboard.writeText(e),a(!0)}catch{}};return t(Be,{title:`Token: ${n}`,onClose:r,children:[t(`div`,{className:`space-y-3`,children:[s(`div`,{className:`rounded 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:`rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all`,children:e})]}),t(Ve,{children:[t(`button`,{onClick:()=>{c()},className:`inline-flex items-center gap-1.5 rounded bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[i?s(A,{className:`h-3.5 w-3.5 text-primary`}):s(_,{className:`h-3.5 w-3.5`}),i?`Copied`:`Copy`]}),s(`button`,{onClick:r,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Done`})]})]})}function Be({title:e,onClose:n,children:r}){return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:t(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[t(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),s(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:s(b,{className:`h-4 w-4`})})]}),s(`div`,{className:`p-4`,children:r})]})})}function Ve({children:e}){return s(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:e})}function Y({label:e,hint:n,children:r}){return t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:e}),r,n&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:n})]})}e();function X(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function He(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 Ue(){return s(`div`,{className:`space-y-2`,children:[1,2].map(e=>s(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function We({text:e}){return s(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function Ge({headers:e,rows:n}){return s(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full text-xs min-w-[640px]`,children:[s(`thead`,{children:s(`tr`,{children:e.map((t,n)=>s(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),s(`tbody`,{children:n})]})})}function Ke(){let e=a(),r=H(),{data:i,isLoading:o}=g(),c=n(()=>i??[],[i]),l=w({onSuccess:()=>e.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),u=async(e,t)=>{await r({title:`Revoke "${t}" session?`,message:`This integration will lose access immediately on its next API call. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&l.mutate({id:e})};return t(K,{icon:ye,title:`Linked Sessions`,subtitle:`External integrations (Alexa, …) linked to this hub via OAuth. Revoke a session to immediately invalidate that integration's access.`,children:[o&&s(Ue,{}),!o&&c.length===0&&s(We,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!o&&c.length>0&&s(Ge,{headers:[`Integration`,`User`,`Scopes`,`Created`,`Last used`,`Status`,``],rows:c.map(e=>{let n=e.revokedAt!==null,r=(l.isPending?l.variables?.id:void 0)===e.id;return t(`tr`,{className:`hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.integrationId}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:e.username}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:s(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>s(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:He(e)},t))})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 border-b border-border`,children:n?t(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-2 py-0.5 text-[10px] text-foreground-subtle`,children:[`Revoked `,X(e.revokedAt)]}):s(`span`,{className:`inline-block rounded bg-emerald-500/15 px-2 py-0.5 text-[10px] text-emerald-700 dark:text-emerald-300`,children:`Active`})}),s(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:!n&&t(`button`,{onClick:()=>{u(e.id,e.integrationId)},disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[r?s(I,{className:`h-3 w-3 animate-spin`}):s(d,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}e();var Z=3e4,Q=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],$={title:`Authentication providers`,subtitle:`Every registered authentication surface in one list: login providers (local password, OIDC, SAML, magic-link) and second-factor providers (passkeys / WebAuthn — configure the relying-party RP ID + origin inline; users enroll from My access → Passkeys). Multiple providers run in parallel — enable/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 qe(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:ve,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).`,`API keys + scoped tokens are managed from the API Keys page.`],setupSteps:[`Add users from Users → New user (or seed via CAMSTACK_ADMIN_USER / CAMSTACK_ADMIN_PASS).`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:W,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`First-time sign-ins are auto-provisioned with the configured Default Role.`],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.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:W,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:B,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`)||e.startsWith(`auth-magic-link`)?{headline:`TOTP / magic-link — second factor or passwordless sign-in.`,icon:B,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:V,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Je(){let e=x({capName:Q[0].capName},{refetchInterval:Z}),t=x({capName:Q[1].capName},{refetchInterval:Z}),r=M(void 0,{refetchInterval:Z}),i=n(()=>ge(r.data??[]),[r.data]),a=n(()=>{let n=[],r=[e.data??[],t.data??[]];for(let[e,t]of Q.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]);return s(he,{title:$.title,subtitle:$.subtitle,pageIcon:V,itemIcon:V,capability:Q[0].capName,installButtonLabel:$.installLabel,items:a,isLoading:e.isLoading||t.isLoading,emptyTitle:$.emptyTitle,emptyDescription:$.emptyDescription,renderStatusBadges:e=>e.stageBadge===null?null:s(`span`,{className:`inline-flex items-center rounded-full border border-primary/30 bg-primary/10 px-2 py-0.5 text-[10px] font-medium text-primary`,children:e.stageBadge}),renderExpandedPanel:e=>s(Ye,{addonId:e.addonId})})}function Ye({addonId:e}){let n=qe(e),r=n.icon;return t(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,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(_e,{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-blue-500/30 bg-blue-500/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[s(z,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),t(`span`,{children:[`TOTP / 2FA is self-service: each user enrols from their own profile page —`,` `,s(`a`,{href:`/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(`a`,{href:`/system/users`,className:`underline text-primary`,children:`Users`}),` `,`page via Actions → “Remove 2FA”.`]})]})]})}function Xe(){return s(`div`,{className:`flex flex-col p-4`,children:s(me,{tabs:[{id:`users`,label:`Users`,icon:ae,content:s(Ee,{})},{id:`api-keys`,label:`Tokens`,icon:L,content:s(Me,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:ye,content:s(Ke,{})},{id:`authentication`,label:`Authentication`,icon:V,content:s(Je,{})}]})})}export{Xe as IdentityPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{I as e,K as t,Q as n,S as r,W as i,b as a,o,q as s,x as c,z as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as u,_t as d,at as f,gt as p,mt as m,st as h,yt as g}from"./player-overlays-gbZ2vznV.js";import{$r as _,Al as v,D as y,Dl as b,E as x,Ei as S,Fl as C,Gc as ee,Gi as w,H as T,Hl as E,Il as D,Iu as O,Jc as k,Jt as te,Mn as A,Mu as j,Nn as M,Oi as N,Qr as ne,Rl as re,Rt as P,Vu as F,Xr as I,Yn as L,Zr as ie,ca as R,ci as z,da as B,ei as V,fa as ae,ft as H,ha as U,ht as oe,ii as se,k as ce,la as le,li as ue,ni as W,nu as G,ol as K,pa as q,pi as de,rd as fe,ri as pe,tt as J,ua as me,vi as he,yu as ge,z as _e}from"./src-BqkvLgRS.js";import{Sn as ve}from"./src-4fqKwwai.js";import{f as ye,l as be,m as xe,p as Se}from"./index-DrF3b0h3.js";import{t as Ce}from"./FormBuilder-Bytus5Tf.js";import{t as we}from"./device-integration-icon-fftDP3wp.js";import{n as Te,r as Y,t as Ee}from"./ScanNetworkModal-ClrFcKCl.js";import{t as De}from"./NodeAddonsSettingsPanel-skqKbqMj.js";var Oe=g(`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 ke(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...ke(n.fields));return t}function Ae(t,n,r){let[a,o]=s(`idle`),[c,l]=s({}),u=i(()=>{let e=[];for(let n of t.sections)e.push(...ke(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;o(`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),o(`idle`)},[r,u,n]),clearProbeResult:f}}n();function je(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(...je(n.fields));return t}function Me(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Ne(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Ne(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function X(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function Pe({open:t,integrationId:n,addonId:a,onClose:u}){let{t:f}=be(),p=o(),[m,h]=s({}),[g,_]=s(!1),[y,b]=s(null),[x,C]=s(X),T=S({addonId:a},{enabled:t}),E=T.data?.deviceType??null,D=de({addonId:a,type:E??ve.Camera},{enabled:t&&T.isSuccess&&E!==null}),O=D.data??null;l(()=>{t&&(h(O?Ne(O.sections.flatMap(e=>e.fields)):{}),C(X()),_(!1),b(null))},[t,n,O]);let te=i(()=>({...m,_probeRequestId:x}),[m,x]),A=pe({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),j=w(),M=e(async(e,t)=>{_(!0);let n=await j.mutateAsync({addonId:a,type:E??ve.Camera,key:e,value:t,formValues:te});return n.status===`ok`&&n.suggestedValues&&h(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Me(e[i])&&!Me(a)&&(r[i]=a,t=!0);return t?r:e}),n},[j,a,te,E]),{testAllStatus:N,hasProbeFields:ne,probeResults:re,handleTestAll:P,clearProbeResult:F}=Ae(O??{sections:[]},m,M);async function I(e){b(null);try{await A.mutateAsync({addonId:a,type:E??ve.Camera,config:m,integrationId:n}),e?h(O?Ne(O.sections.flatMap(e=>e.fields)):{}):u()}catch(e){b(e instanceof Error?e.message:String(e))}}if(!t)return null;let L=je((O?.sections??[]).flatMap(e=>e.fields)).filter(e=>Me(m[e])),ie=L.length===0,R=T.isLoading||E!==null&&D.isLoading,z=T.isError||T.isSuccess&&E===null||D.isError||D.isSuccess&&O===null;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:u}),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:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:f(`integrations.addDevice`)}),c(`button`,{onClick:u,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:c(ee,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:R?c(`div`,{className:`flex items-center justify-center py-8`,children:c(G,{className:`h-5 w-5 animate-spin text-primary`})}):z?r(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[c(K,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`space-y-1`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,c(`span`,{className:`font-mono`,children:a}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):c(Ce,{schema:O,values:m,onChange:h,onTestField:M,probeResults:re,onClearProbe:F})}),!z&&!R&&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:[c(v,{className:`h-3.5 w-3.5`}),`Test logs`,c(`span`,{className:`font-mono text-[9px] opacity-60`,children:x.slice(0,14)})]}),c(d,{className:`h-3.5 w-3.5 transition-transform ${g?`rotate-180`:``}`})]}),g&&c(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:c(J,{addonId:a,requestId:x,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!z&&!R&&(y||L.length>0)&&c(`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:[c(K,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:y||`Required: ${L.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:[c(`button`,{onClick:u,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:f(`integrations.cancel`)}),!z&&ne&&r(`button`,{type:`button`,onClick:P,disabled:N===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[N===`testing`?c(G,{className:`h-3.5 w-3.5 animate-spin`}):c(k,{className:`h-3.5 w-3.5`}),`Test All`]})]}),r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:()=>I(!0),disabled:z||!ie||A.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:f(`integrations.saveAndNew`)}),c(`button`,{onClick:()=>I(!1),disabled:z||!ie||A.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:A.isPending?f(`integrations.saving`):f(`integrations.save`)})]})]})]})]})}var Fe=1500;function Z({addonId:e,integrationId:t,jobId:n,onFinished:i}){let{t:a}=be(),o=I(),s=(_({addonId:e,integrationId:t},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?Fe:!1}).data??[]).find(e=>e.jobId===n);if(!s)return null;let l=s.state===`running`,u=s.processed,d=s.total>0?Math.round(u/s.total*100):0;!l&&s.finishedAt!==null&&i();let f=[`${u}/${s.total} ${a(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];s.adopted>0&&f.push(`${s.adopted} ${a(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),s.alreadyAdopted>0&&f.push(`${s.alreadyAdopted} ${a(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),s.failed>0&&f.push(`${s.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?c(G,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):s.failed>0?c(K,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):s.state===`cancelled`?c(j,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):c(O,{className:`h-3.5 w-3.5 text-primary shrink-0`}),c(`p`,{className:`text-[11px] text-foreground`,children:p}),l&&c(`button`,{onClick:()=>o.mutate({jobId:n}),className:`ml-auto rounded-lg border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:a(`integrations.adoptJobCancel`,{defaultValue:`Stop`})})]}),c(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:c(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${d}%`},role:`progressbar`,"aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100})}),s.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 Ie(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 Q=`devices`,Le={id:Q,label:`Devices`,isDefault:!0},Re=2e4,$=100;function ze({addonId:n,integrationId:i,onClose:a}){let{t:u}=be(),d=o(),[f,p]=s(new Set),[m,h]=s(new Set),[g,_]=s(new Map),[v,y]=s(null),{data:b}=me(),S=(b??[]).find(e=>e.addonId===n)?.supportsLocationImport??!1,[w,E]=s(!0),D=ie({addonId:n,integrationId:i}).data?.filters,O=D&&D.length>0?D:[Le],[k,te]=s(O.find(e=>e.isDefault)?.id??(O.some(e=>e.id===Q)?Q:O[0].id)),A=k!==Q,j=V(),M=ne({addonId:n,integrationId:i,page:1,pageSize:Re,filter:k}),N=M.refetch,re=j.mutate,P=e(()=>{re({addonId:n,integrationId:i},{onSettled:()=>{N()}})},[re,n,i,N]),I=t(null);l(()=>{let e=`${n}::${i}`;I.current===e||M.isLoading||(I.current=e,(M.data?.candidates.length??0)===0&&P())},[n,i,M.isLoading,M.data,P]);let L=j.isPending,R=j.isError?j.error instanceof Error?j.error.message:String(j.error):null,z=typeof j.data?.lastError==`string`&&j.data.lastError.length>0?j.data.lastError:null,B=M.data?.candidates??[],ae=M.isError?M.error instanceof Error?M.error.message:String(M.error):null,H=W(),[U,oe]=s(null),se=e(e=>{e.alreadyAdopted||p(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),ce=e(e=>{h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),le=e((e,t)=>{_(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),ue=e(e=>{let t={};for(let n of e){let e=g.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[g]),q=e(async()=>{y(null);let e=[...f];if(e.length!==0)try{let t=ue(e),{jobId:r}=await H.mutateAsync({addonId:n,integrationId:i,filter:k,childNativeIds:e,...t?{perCandidate:t}:{},...S?{importLocations:w}:{}});oe(r),p(new Set),_(new Map)}catch(e){y(e instanceof Error?e.message:String(e))}},[f,ue,H,n,i,k,S,w]),de=t(null),fe=e(()=>{U===null||de.current===U||(de.current=U,N(),d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]}))},[U,N,d]),pe=e(e=>{te(e),p(new Set),h(new Set),_(new Map),y(null)},[]),J=f.size,he=U!==null&&J===0&&!H.isPending;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:a}),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:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:u(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),c(`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:[c(`input`,{type:`checkbox`,checked:w,onChange:e=>E(e.target.checked),className:`accent-primary`}),u(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),c(`button`,{onClick:a,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:c(ee,{className:`h-4 w-4`})})]})]}),r(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(R??ae??z)&&B.length===0&&c(`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:[c(K,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`min-w-0`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:u(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),c(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:R??ae??z})]})]})}),O.length>1&&c(Be,{filters:O,activeFilter:k,onSelect:pe}),c(`div`,{className:`flex-1 min-h-0`,children:c(x,{mode:`generic`,items:B,pageSize:$,getKey:e=>e.childNativeId,getSearchText:Ie,getFilterType:e=>e.type,filterOptions:_e(),filterLabel:u(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:M.isLoading||L&&B.length===0,searchPlaceholder:u(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(R??ae??z)&&B.length===0?``:u(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:r(`button`,{type:`button`,onClick:P,disabled:L,title:u(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[c(C,{className:`h-3.5 w-3.5 ${L?`animate-spin`:``}`}),u(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:u(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>c(Ve,{candidate:e,expandable:!A,expanded:m.has(e.childNativeId),onToggleExpand:()=>ce(e.childNativeId),adoptedLabel:u(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:u(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=T(e.type),n=t.icon;return r(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[c(n,{className:`h-3.5 w-3.5 shrink-0`}),t.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>c(`div`,{className:`flex items-center justify-end`,children:c(`button`,{onClick:()=>se(e),disabled:e.alreadyAdopted,"aria-label":f.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${f.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:f.has(e.childNativeId)&&c(F,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!A&&m.has(e.childNativeId),renderExpanded:A?void 0:e=>c(He,{candidate:e,hiddenChildIds:g.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>le(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:f.has(e.childNativeId)?`bg-primary/5`:``})})]}),v&&c(`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:[c(K,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:v})]})}),U!==null&&c(Z,{addonId:n,integrationId:i,jobId:U,onFinished:fe}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[c(`div`,{}),r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:a,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:he?a:q,disabled:!he&&(J===0||H.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:[H.isPending&&c(G,{className:`h-3.5 w-3.5 animate-spin`}),he?u(`integrations.close`,{defaultValue:`Close`}):u(`integrations.addSelected`,{defaultValue:`Add selected`}),!he&&J>0?` (${J})`:``]})]})]})]})]})}function Be({filters:e,activeFilter:t,onSelect:n}){return c(`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 c(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function Ve({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:[c(n?d:p,{className:`h-3.5 w-3.5`}),o]}):c(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),c(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&c(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:a})]})}function He({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let i=e.children??[];return i.length===0?null:c(`div`,{className:`space-y-1 py-1`,children:i.map(e=>{let i=t.has(e.childNativeId),a=e.capabilities??[];return r(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${i?`opacity-50`:``}`,children:[c(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),a.length>0&&c(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:a.join(`, `)}),c(`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:c(i?m:ge,{className:`h-3 w-3`})})]},e.childNativeId)})})}n();function Ue(e){let t=[];for(let n of e){if(n.type===`group`){t.push(...Ue(n.fields));continue}`key`in n&&typeof n.key==`string`&&t.push(n.key)}return t}function We(e,t){if(!e)return{};let n=new Set(e.sections.flatMap(e=>Ue(e.fields))),r={};for(let e of n)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}function Ge(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 Ke({integrationId:e,addonId:t,name:n,kind:a,mode:s,brokerKind:l,canTest:u=!1,trpc:d,onClose:f}){let{t:p}=be(),m=o(),{data:h,isLoading:g}=B({id:e},{enabled:s===`account`||s===`broker`}),_=i(()=>{let e=h?.brokerId;return typeof e==`string`?e:null},[h]),{data:v,isLoading:y}=A({addonId:t,nodeId:`hub`},{enabled:s===`account`}),b=i(()=>v?Ge(v):null,[v]),x=q(),S=t=>{x.mutate({id:e,settings:t},{onSuccess:()=>{m.invalidateQueries(),f()}})};return c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onClick:f,children:r(`div`,{className:`max-h-[85vh] w-full max-w-lg overflow-y-auto rounded-xl border border-border bg-surface p-5 shadow-xl`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`mb-3 flex items-center justify-between`,children:[r(`h2`,{className:`text-sm font-semibold text-foreground`,children:[p(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]}),c(`button`,{onClick:f,className:`rounded-md p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":p(`common.close`,{defaultValue:`Close`}),children:c(ee,{className:`h-4 w-4`})})]}),s===`broker`?l?r(`div`,{className:`space-y-3`,children:[c(`p`,{className:`text-[11px] text-foreground-subtle`,children:p(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),_&&r(`p`,{className:`text-[11px] text-foreground`,children:[p(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,c(`span`,{className:`font-mono text-foreground-subtle`,children:_})]}),x.isPending?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(G,{className:`h-3 w-3 animate-spin`}),p(`integrations.saving`,{defaultValue:`Saving…`})]}):c(Y,{kind:l,onResolved:e=>{S({brokerId:e})},onBack:f}),x.isError&&c(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):c(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):s===`account`?g||y?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(G,{className:`h-3 w-3 animate-spin`}),p(`integrations.loading`,{defaultValue:`Loading…`})]}):c(Te,{addonId:t,configSchema:b,canTest:u,initialName:n,initialConfig:We(b,h??{}),submitLabel:p(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e})=>S(e),onBack:f}):c(te,{trpc:d,addonId:t,nodeId:`hub`,title:n})]})})}function qe(e){return e==null?!1:e.sections.some(e=>e.fields.length>0)}n();function Je(){let{t}=be(),{integrationId:n}=Se(),d=o(),p=ye(),[m,g]=xe(),_=f(),[S,C]=s(!1),[w,T]=s(!1),[O,k]=s(!1),[te,j]=s(!1),[ne,F]=s(!1),{data:I,isLoading:ie}=le({id:n??``},{enabled:!!n}),{data:B}=A({addonId:I?.addonId??``,nodeId:`hub`},{enabled:!!I?.addonId}),{data:V,isSuccess:W}=me(),q=i(()=>{let e=I?.addonId;return!e||!W?null:(V??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[V,I?.addonId,W]),{data:de}=z({}),pe=i(()=>(de?.providers??[]).some(e=>e.addonId===I?.addonId),[de,I?.addonId]),ge=q!==null,_e=I?.info?.fixed===!0,ve=ge?q===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),Ce=i(()=>{let e=I?.addonId;return!e||!W?null:(V??[]).find(t=>t.addonId===e)?.brokerKind??null},[V,I?.addonId,W]),Te=i(()=>{let e=I?.addonId;return!e||!W?!1:(V??[]).find(t=>t.addonId===e)?.canTest===!0},[V,I?.addonId,W]),Y=i(()=>{let e=I?.addonId;return!e||!W?null:(V??[]).find(t=>t.addonId===e)?.mode??null},[V,I?.addonId,W]);l(()=>{m.get(`add`)===`1`&&ge&&(C(!0),g(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[m,ge,g]);let ke=B!=null&&Array.isArray(B.sections)&&B.sections.some(e=>e.fields.length>0),{data:Ae}=M({addonId:I?.addonId??``,nodeId:`hub`},{enabled:!!I?.addonId&&Y!==`account`}),je=Y!==null&&Y!==`account`&&qe(Ae),Me=i(()=>I?.addonId?[I.addonId]:[],[I?.addonId]),{data:Ne}=he({projection:`slim`},{refetchInterval:3e4}),X=[[`integrations`,`get`],{input:{id:n??``},type:`query`}],Fe=U({onMutate:async e=>{await d.cancelQueries({queryKey:X});let t=d.getQueryData(X);return t!=null&&d.setQueryData(X,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&d.setQueryData(X,r.previous)},onSettled:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Z=R({onSuccess:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]}),j(!1),p(`/integrations`)}}),Ie=L({onSuccess:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=N({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Le=se({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Re=ue({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),$=i(()=>Ne??[],[Ne]),Be=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},[$]),Ve=e(e=>Be.get(e)??null,[Be]),{data:He}=ae(void 0),Ue=i(()=>y(He),[He]),We=e(e=>p(`/devices/${String(e)}`),[p]),Ge=i(()=>{let e=I?.id;return e?$.filter(t=>{let n=Ue(t);return n.kind===`resolved`&&n.integration.id===e}):[]},[$,I?.id,Ue]),Je=i(()=>He===void 0?null:ce(Ge).length,[He,Ge])??`…`;return ie?r(`div`,{className:`p-4`,children:[c(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),c(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):I?r(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[c(oe,{items:[{label:`Integrations`,onClick:()=>p(`/integrations`)},{label:I.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:[c(`img`,{src:u(`/api/addon-assets/${I.addonId}/assets/icon.svg`),alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:e=>{e.target.style.display=`none`}}),r(`div`,{className:`min-w-0`,children:[c(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:I.name}),r(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[I.addonId,` · `,Je,` `,t(`integrations.devices`)]})]})]}),r(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[pe&&r(`button`,{onClick:()=>T(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the network for devices (incl. a different subnet)`,children:[c(re,{className:`h-3.5 w-3.5`}),`Scan network`]}),!_e&&r(`button`,{onClick:()=>C(!0),disabled:!ge,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:ve,children:[c(E,{className:`h-3.5 w-3.5`}),ve]}),r(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Fe.isPending?`opacity-60`:``} ${I.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[c(P,{checked:I.enabled,onCheckedChange:e=>Fe.mutate({id:n,enabled:e}),disabled:Fe.isPending,"aria-label":I.enabled?`Disable integration`:`Enable integration`}),c(`span`,{className:`text-[11px] font-medium ${I.enabled?`text-success`:`text-foreground-subtle`}`,children:I.enabled?`Enabled`:`Disabled`}),Fe.isPending&&c(G,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Y!==`standalone`&&(ke||q===`device-adoption`)&&r(`button`,{onClick:()=>k(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[c(b,{className:`h-3 w-3`}),t(`integrations.config`)]}),r(`button`,{onClick:()=>F(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:t(`integrations.logs`,{defaultValue:`View logs`}),children:[c(v,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),c(H,{label:`Restart`,icon:D,title:`Restart "${I.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Je} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Ie.isPending,action:()=>Ie.mutateAsync({addonId:I.addonId})}),!_e&&r(`button`,{onClick:()=>j(!0),className:`flex items-center gap-1.5 rounded-lg border border-danger bg-danger/10 px-3 py-1.5 text-[11px] font-medium text-danger hover:bg-danger hover:text-background transition-colors`,title:t(`integrations.delete`,{defaultValue:`Delete integration`}),children:[c(h,{className:`h-3 w-3`}),t(`integrations.delete`,{defaultValue:`Delete`})]})]})]}),je&&c(De,{nodeId:null,addonIds:Me,level:`global`,surface:`integration`,title:t(`integrations.settings`,{defaultValue:`Settings`})}),c(x,{context:`integration-detail`,devices:$,trpc:_.trpcClient,integrationOf:Ue,forceIntegrationId:I.id,urlScope:`root`,lsKey:`integration-detail:${I.addonId}`,resolveIntegrationIcon:we,resolveParent:Ve,onNavigate:We,batchActions:{remove:Q.mutate,disable:Le.mutate,enable:Re.mutate},..._e?{}:{onDeleteDevice:e=>Q.mutate({deviceId:e.id})}}),S&&n&&q===`device-adoption`&&c(ze,{addonId:I.addonId,integrationId:n,onClose:()=>C(!1)}),S&&n&&q===`device-provider`&&c(Pe,{open:S,integrationId:n,addonId:I.addonId,onClose:()=>C(!1)}),w&&I&&c(Ee,{open:w,scope:{addonId:I.addonId,label:I.name},onClose:()=>T(!1)}),O&&n&&q!==null&&Y!==null&&c(Ke,{integrationId:n,addonId:I.addonId,name:I.name,kind:q,mode:Y,brokerKind:Ce,canTest:Te,trpc:_.trpcClient,onClose:()=>k(!1)}),ne&&c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>F(!1),children:r(`div`,{className:`flex flex-col rounded-xl border border-border bg-surface shadow-xl w-full max-w-5xl h-[80vh]`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5`,children:[r(`div`,{className:`flex items-center gap-2 min-w-0`,children:[c(v,{className:`h-4 w-4 text-primary shrink-0`}),c(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:I.name}),r(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[I.addonId,n?` · ${n}`:``]})]}),c(`button`,{onClick:()=>F(!1),className:`flex h-7 w-7 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close logs`,children:c(ee,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:c(J,{addonId:I.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})}),te&&c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:()=>!Z.isPending&&j(!1),children:r(`div`,{className:`rounded-xl border border-border bg-background p-5 shadow-2xl w-96 space-y-3`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`flex items-start gap-3`,children:[c(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg bg-danger/10 shrink-0`,children:c(K,{className:`h-4 w-4 text-danger`})}),r(`div`,{className:`min-w-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.deleteTitle`,{defaultValue:`Delete integration?`})}),c(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:t(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:I.name,count:Je})})]})]}),Z.error&&c(`div`,{className:`rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:Z.error instanceof Error?Z.error.message:String(Z.error)}),r(`div`,{className:`flex items-center justify-end gap-2 pt-1`,children:[c(`button`,{onClick:()=>j(!1),disabled:Z.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:t(`integrations.cancel`,{defaultValue:`Cancel`})}),c(`button`,{onClick:()=>Z.mutate({id:n}),disabled:Z.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-danger px-3 py-1.5 text-[11px] font-medium text-background hover:bg-danger/90 transition-colors disabled:opacity-60 disabled:cursor-not-allowed`,children:Z.isPending?r(a,{children:[c(G,{className:`h-3 w-3 animate-spin`}),t(`integrations.deleting`,{defaultValue:`Deleting…`})]}):r(a,{children:[c(h,{className:`h-3 w-3`}),t(`integrations.confirmDelete`,{defaultValue:`Delete integration`})]})})]})]})})]}):r(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[c(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:c(Oe,{className:`h-6 w-6 text-foreground-subtle`})}),r(`div`,{className:`space-y-1 max-w-sm`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),c(`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:()=>p(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[c(fe,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}export{Je as IntegrationDetailPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{_t as l,at as u,gt as d,vt as f}from"./player-overlays-gbZ2vznV.js";import{D as p,Dl as m,E as h,Gc as ee,Hl as g,Il as _,Mn as te,Rl as v,Vl as y,Vu as b,Yr as ne,fa as x,k as re,kn as S,nu as C,oi as w,r as T,sa as ie,ua as E,vi as D}from"./src-BqkvLgRS.js";import{t as O}from"./ProviderIcon-BBtV-kNn.js";import{f as k,l as A,m as ae}from"./index-DrF3b0h3.js";import{t as j}from"./AdminPage-CiKtOLQm.js";import"./useEventInvalidation-DxM8yEtK.js";import{t as M}from"./StatusBadge-CeptlsPG.js";import{t as oe}from"./device-integration-icon-fftDP3wp.js";import{n as N,r as P,t as F}from"./ScanNetworkModal-ClrFcKCl.js";import{t as I}from"./useBodyScrollLock-BDocajQE.js";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(b,{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=k(),{data:o,isLoading:c}=E();if(c)return s(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-14 rounded-lg bg-surface animate-pulse`},e))});let l=r!==null;return n(`div`,{className:`space-y-2`,children:[(o??[]).map(o=>{let c=o.instanceMode===`unique`&&o.existingInstances.length>0,u=r===o.addonId,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})]}),u?s(C,{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(m,{className:`h-3 w-3`}),i(`integrations.manage`)]}):s(d,{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=k(),d=a(),[f,p]=o(`picker`),[m,h]=o(null),[g,_]=o(null),[v,y]=o(`manual`),[b,x]=o(null),[re,S]=o(``),[T,E]=o(null),[D,O]=o(null),[ae,j]=o(!1),{data:M}=te({addonId:m??``,nodeId:`hub`},{enabled:m!=null}),oe=r(()=>M?se(M):null,[M]),F=ie({onSuccess:()=>d.invalidateQueries({queryKey:[[`integrations`]]})}),V=w(),H=V.data;c(()=>{f!==`discovery`||!g||!m||V.isPending||V.data||V.mutate({addonId:m})},[f,g,m,V]);let ce=ne({onSuccess:()=>d.invalidateQueries({queryKey:[[`deviceManager`]]})});function le(e,t,n,r,i,a,o,s){if(!F.isPending){if(h(e),j(s),y(n),S(r),O(null),o===`broker`){if(!a){O(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}x(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});_(t.id),v===`auto`||v===`both`?p(`discovery`):q(t.id)}catch{}}async function G(e){if(m)try{let t=await F.mutateAsync({addonId:m,name:re,settings:{brokerId:e}});E(t.id),_(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??g??m;t(),J(),n&&u(`/integrations/${n}`)}function J(){p(`picker`),h(null),_(null),y(`manual`),x(null),S(``),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(ee,{className:`h-4 w-4`})})]}),n(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[$&&!X&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:$ instanceof Error?$.message:String($)}),f===`picker`&&n(i,{children:[D&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:D}),s(z,{onSelect:le,onClose:Y,pendingAddonId:Q})]}),f===`config`&&m&&s(N,{addonId:m,configSchema:oe??null,canTest:ae,onSave:W,onBack:()=>p(`picker`)}),f===`broker`&&b&&s(P,{kind:b,onResolved:e=>{G(e)},onBack:()=>p(`picker`)}),f===`discovery`&&g&&s(R,{providerId:g,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(C,{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:d,{className:`h-3.5 w-3.5`})}),s(O,{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=k(),c=u(),[l]=ae(),[d,f]=o(!1),m=e(()=>f(!0),[]),ee=e(()=>f(!1),[]),[te,b]=o(!1),ne=e(()=>b(!0),[]),C=e(()=>b(!1),[]);T([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),T([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:w,isLoading:ie,refetch:E}=x(void 0),{data:O,isLoading:M,refetch:N}=D({projection:`slim`}),P=r(()=>O??[],[O]),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(()=>p(w),[w]),z=r(()=>{let e=new Map;for(let t of re(P)){let n=R(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[P,R]),se=r(()=>I.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:le(e),deviceCount:z.get(e.id)??0})),[I,z]),B=l.get(U),H=e(e=>{let t=new URLSearchParams(window.location.search);t.get(U)===e?t.delete(U):t.set(U,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),W=e(e=>a(`/integrations/${e.id}`),[a]),G=e(e=>L.get(e)??null,[L]),K=e(e=>a(`/devices/${String(e)}`),[a]),q=e(e=>s(h,{context:`integration-detail`,devices:P,trpc:c.trpcClient,integrationOf:R,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:oe,resolveParent:G,onNavigate:K}),[P,c.trpcClient,R,G,K]),J=e(e=>B===e.addonId,[B]),Y=r(()=>ce({isExpanded:J,onToggleExpand:H}),[J,H]),X=e(e=>`${e.name} ${e.addonId}`,[]),Z=e(e=>e.addonId,[]),ue=e(()=>{E(),N()},[E,N]),Q=ie||M,$=I.length>0;return n(j,{icon:y,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(_,{className:S(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),n(`button`,{onClick:ne,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the local network for devices`,children:[s(v,{className:`h-3.5 w-3.5`}),`Scan network`]}),n(`button`,{onClick: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(g,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[Q&&s(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!$&&n(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[s(`p`,{className:`text-sm`,children:`No integrations configured.`}),s(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!Q&&$&&s(h,{mode:`generic`,items:se,getKey:Z,getSearchText:X,columns:Y,onRowClick:W,isExpanded:J,renderExpanded:q,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),s(V,{open:d,onClose:ee}),s(F,{open:te,onClose:C})]})}export{W as IntegrationsPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Q as e,S as t,W as n,b as r,o as i,q as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{st as s}from"./player-overlays-gbZ2vznV.js";import{$l as c,Ar as l,Dr as u,El as d,Gc as f,Gr as p,Hl as m,Jc as h,Ll as g,Mr as _,Or as v,T as y,Tr as b,Vl as x,Wl as S,Wn as C,jr as w,kr as T,nu as E,wr as D,yn as O}from"./src-BqkvLgRS.js";import{nn as ee,ot as k,yn as A}from"./src-4fqKwwai.js";import{f as j}from"./index-DrF3b0h3.js";import{t as M}from"./AdminPage-CiKtOLQm.js";import{t as N}from"./AdminTabs-CDIoD5NP.js";import{t as P}from"./BrokerForm-DoQjILhI.js";import{t as F}from"./useBodyScrollLock-BDocajQE.js";import{t as I}from"./AddonCollectionPage-C9l7ftV0.js";e();var L={"home-assistant":`Home Assistant`,mqtt:`MQTT`};function R(e){return L[e]??e}function z(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var B={connected:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,connecting:`bg-amber-500/15 text-amber-700 dark:text-amber-300`,disconnected:`bg-foreground-subtle/15 text-foreground-subtle`,"auth-failed":`bg-danger/15 text-danger`,unreachable:`bg-danger/15 text-danger`,error:`bg-danger/15 text-danger`};function V({status:e}){return o(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${B[e]}`,children:e})}function H(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function U({title:e,subtitle:n,onClose:r,children:i}){return F(),o(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,children:t(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[t(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[t(`div`,{className:`space-y-0.5`,children:[o(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),n&&o(`p`,{className:`text-xs text-foreground-subtle`,children:n})]}),o(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,children:o(f,{className:`h-4 w-4`})})]}),o(`div`,{className:`p-4 max-h-[70vh] overflow-y-auto overscroll-contain`,children:i})]})})}function W({kinds:e,onClose:n,onDone:s}){let c=i(),l=e=>`${e.addonId??``}::${e.kind}`,[u,d]=a(e[0]?l(e[0]):``),[f,p]=a(``),[m,h]=a(!1),[g,_]=a(``),v=e.find(e=>l(e)===u)??e[0],y=v?.kind??``,b=v?.addonId,x=D({onSuccess:()=>{c.invalidateQueries({queryKey:[[`broker`,`list`]]}),s()}}),S=e=>{if(!y||f.trim().length===0)return;let t=m?g.trim():``;m&&t===``||x.mutate({kind:y,name:f.trim(),settings:e,...t===``?{}:{id:t},...b===void 0?{}:{addonId:b}})};return o(U,{title:`Add broker`,subtitle:`Register a message broker for exporters and automations.`,onClose:x.isPending?()=>{}:n,children:t(`div`,{className:`space-y-3`,children:[t(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Kind`}),o(`select`,{value:u,onChange:e=>d(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>o(`option`,{value:l(e),children:e.label},l(e)))})]}),t(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Name`}),o(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:`My Home Assistant`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),t(`div`,{className:`space-y-1 rounded border border-border px-3 py-2`,children:[t(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground`,children:[o(`input`,{type:`checkbox`,checked:m,onChange:e=>h(e.target.checked)}),`Restore a broker that was removed, under its original id`]}),m&&t(r,{children:[o(`input`,{type:`text`,value:g,onChange:e=>_(e.target.value),placeholder:`ha_004`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`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.`})]})]}),x.isError&&o(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:x.error instanceof Error?x.error.message:String(x.error)}),y&&o(P,{kind:y,...b===void 0?{}:{addonId:b},onSubmit:S,onCancel:n,submitLabel:x.isPending?`Adding…`:`Add broker`,disabled:x.isPending}),f.trim().length===0&&o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter a name before saving.`}),m&&g.trim().length===0&&o(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter the original id, or clear the checkbox to create a new broker.`})]})})}function G({broker:e,onClose:r,onDone:a}){let s=i(),c=b({id:e.id,addonId:e.addonId}),l=w({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(U,{title:`Edit ${e.name}`,subtitle:`${R(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(E,{className:`h-3.5 w-3.5 animate-spin`}),` Loading settings…`]}):c.isError?t(`div`,{className:`space-y-3`,children:[t(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[`Failed to load settings:`,` `,c.error instanceof Error?c.error.message:`Unknown error`]}),o(`div`,{className:`flex justify-end`,children:o(`button`,{type:`button`,onClick:r,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Close`})})]}):t(`div`,{className:`space-y-3`,children:[l.isError&&o(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:l.error instanceof Error?l.error.message:String(l.error)}),o(P,{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 K({broker:e,onEdit:n}){let r=i(),c=O(),[u,d]=a(null),f=_({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)})}),p=l({onSuccess:()=>{r.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),m=async()=>{await c({title:`Delete broker`,message:`Delete broker "${e.name}"? Integrations that depend on it will stop working.`,confirmLabel:`Delete`,variant:`danger`})&&p.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:R(e.kind)}),t(`td`,{className:`px-3 py-2`,children:[o(V,{status:e.status}),u&&o(`span`,{className:`ml-2 text-[10px] ${u.ok?`text-success`:`text-danger`}`,children:u.ok?`OK`:u.error??`failed`})]}),o(`td`,{className:`px-3 py-2`,children:t(`div`,{className:`flex items-center justify-end gap-1.5`,children:[t(`button`,{type:`button`,onClick:()=>f.mutate({id:e.id,addonId:e.addonId}),disabled:f.isPending,title:`Test connection`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10 disabled:opacity-50`,children:[f.isPending?o(E,{className:`h-3 w-3 animate-spin`}):o(h,{className:`h-3 w-3`}),`Test`]}),t(`button`,{type:`button`,onClick:()=>n(e),title:`Edit`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10`,children:[o(S,{className:`h-3 w-3`}),` Edit`]}),t(`button`,{type:`button`,onClick:()=>{m()},disabled:p.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded border border-danger/40 px-2 py-1 text-[11px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[p.isPending?o(E,{className:`h-3 w-3 animate-spin`}):o(s,{className:`h-3 w-3`}),`Delete`]})]})})]})}function q(){let e=v({}),r=T(),i=n(()=>H(e.data),[e.data]),[s,c]=a(!1),[l,u]=a(null),d=n(()=>{let e=new Map;for(let t of z(r.data))for(let n of t.kinds)e.set(`${t.addonId}::${n.kind}`,{addonId:t.addonId,kind:n.kind,label:n.label});for(let t of i)[...e.values()].some(e=>e.kind===t.kind)||e.set(`::${t.kind}`,{kind:t.kind,label:R(t.kind)});return[...e.values()]},[i,r.data]);return t(`div`,{className:`space-y-3`,children:[o(`div`,{className:`flex items-center justify-end`,children:t(`button`,{type:`button`,onClick:()=>c(!0),disabled:d.length===0,title:d.length===0?`No broker providers available`:void 0,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed`,children:[o(m,{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:[e.isLoading&&o(`tr`,{children:t(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[o(E,{className:`inline h-4 w-4 animate-spin`}),` Loading brokers…`]})}),e.isError&&o(`tr`,{children:t(`td`,{colSpan:4,className:`px-3 py-4 text-center text-xs text-danger`,children:[`Failed to load brokers:`,` `,e.error instanceof Error?e.error.message:`Unknown error`]})}),!e.isLoading&&!e.isError&&i.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.`})}),i.map(e=>o(K,{broker:e,onEdit:u},e.id))]})]})}),s&&o(W,{kinds:d,onClose:()=>c(!1),onDone:()=>c(!1)}),l&&o(G,{broker:l,onClose:()=>u(null),onDone:()=>u(null)})]})}var J=[{kind:`device-export`,tabId:`device-export`,title:`Device export`,subtitle:`Outbound exporters that publish CamStack devices to other ecosystems (HomeAssistant, HomeKit, Alexa, …).`,icon:d,emptyTitle:`No device-export providers installed`,emptyDescription:`Install an export addon (e.g. @camstack/addon-export-ha-mqtt) to surface your CamStack devices in HomeAssistant, HomeKit, …`,addLabel:`Add export`},{kind:`email`,tabId:`email`,title:`Email providers`,subtitle:`Outbound email relays used for magic-link login, notifications, and alerts (SMTP today, future SendGrid, …).`,icon:c,emptyTitle:`No email providers installed`,emptyDescription:`Install an email-provider addon (e.g. @camstack/addon-smtp) so the hub can deliver magic-link logins and notifications.`,addLabel:`Add email provider`},{kind:`broker`,tabId:`broker`,title:`Brokers`,subtitle:`Message brokers consumed by exporters and downstream automations (MQTT today, future Kafka, …).`,icon:g,emptyTitle:`No brokers installed`,emptyDescription:`Install a broker addon (e.g. @camstack/addon-mqtt-broker) to publish device events for downstream automations.`,addLabel:`Add broker`}];function Y(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e.name;if(typeof t==`string`)return t}return null}function X(e){let t=e,n=t?.manifest;if(!n?.id)return null;let r=[];for(let e of n.capabilities??[]){let t=Y(e);t!==null&&r.push(t)}let i=n.packageDisplayName??n.name??n.id,a=t?.process?.state??null;return{addonId:n.id,displayName:i,isActive:a===`running`,packageName:n.packageName??`@camstack/addon-${n.id}`,capNames:r,processState:a}}function Z(e,t){let n=new Set(t);return e.filter(e=>e.capNames.some(e=>n.has(e)))}function Q(e){for(let[t,n]of Object.entries(k))if(n===e)return t;return null}function te(e){return e===`running`?{label:`Running`,className:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`}:e===`crashed`||e===`failed`?{label:e===`failed`?`Failed`:`Crashed`,className:`bg-danger/15 text-danger`}:e===`stopped`||e===`disabled`?{label:`Stopped`,className:`bg-foreground-subtle/15 text-foreground-subtle`}:{label:e??`Unknown`,className:`bg-foreground-subtle/15 text-foreground-subtle`}}function $({label:e,className:t}){return o(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t}`,children:e})}function ne({addonId:e}){let{data:t,isLoading:n}=u({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=A.safeParse(t);if(!r.success)return null;let i=r.data;return o($,{label:`${i.brokerCount} broker${i.brokerCount===1?``:`s`}${i.connectedCount>0?` • ${i.connectedCount} connected`:``}`,className:`bg-primary/10 text-primary`})}function re({addonId:e}){let{data:t,isLoading:n}=p({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=ee.safeParse(t);if(!r.success)return null;let i=r.data,a=i.linkState===`linked`?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:i.linkState===`error`?`bg-danger/15 text-danger`:`bg-foreground-subtle/15 text-foreground-subtle`;return o($,{label:`${i.linkState} • ${i.exposedDeviceCount} exposed`,className:a})}function ie({kind:e,addonId:t}){return e===`broker`?o(ne,{addonId:t}):e===`device-export`?o(re,{addonId:t}):null}function ae({descriptor:e,rows:n,isLoading:i}){let a=Q(e.kind),s=e.kind===`device-export`,c=j();return o(I,{title:e.title,subtitle:e.subtitle,pageIcon:e.icon,itemIcon:e.icon,capability:a??e.kind,installButtonLabel:e.addLabel,items:n,isLoading:i,emptyTitle:e.emptyTitle,emptyDescription:e.emptyDescription,renderStatusBadges:n=>{let i=te(n.processState);return t(r,{children:[o($,{label:i.label,className:i.className}),o(ie,{kind:e.kind,addonId:n.addonId})]})},renderExpandedPanel:s?e=>o(y,{addonId:e.addonId,onOpenDevice:e=>c(`/devices/${e}`)}):void 0,showChrome:!0})}function oe(){let e=C(void 0,{refetchInterval:1e4}),t=(e.data??[]).map(X).filter(e=>e!==null);return o(M,{icon:x,title:`External systems`,subtitle:`External systems this hub talks to — device exporters, email relays, and message brokers. Settings, Logs and Events are docked under every provider.`,children:o(N,{tabs:J.map(n=>{let r=Object.entries(k).filter(([,e])=>e===n.kind).map(([e])=>e),i=n.kind===`broker`?o(q,{}):o(ae,{descriptor:n,rows:Z(t,r),isLoading:e.isLoading});return{id:n.tabId,label:n.title,icon:n.icon,content:i}})})})}export{oe as IntegrationsPage};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{Q as e,S as t,W as n,b as r,o as i,q as a,x as o,z as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{_t as c,gt as l,st as u,vt as d,yt as f}from"./player-overlays-gbZ2vznV.js";import{$u as p,Ai as m,Al as h,Au as g,Ci as _,Fi as v,Fu as y,Gc as b,Gl as x,Hl as S,Hu as C,Ii as w,Il as ee,Jr as T,Ku as E,Li as D,Mi as te,Nl as O,Pl as k,Pu as A,Ql as j,Ri as M,Rl as N,Si as ne,Su as P,Tl as re,Ui as ie,Wc as ae,Wl as F,Wu as I,Xc as L,Yu as R,Zc as oe,Zu as z,_l as B,_u as se,al as ce,cd as le,cl as ue,ct as V,cu as H,ed as U,el as W,eu as de,fl as fe,gl as pe,hu as me,iu as he,ji as ge,ki as _e,ll as ve,lt as G,lu as ye,od as be,pl as xe,qc as Se,qr as Ce,qu as we,sd as Te,sl as Ee,ul as De,ut as Oe,v as ke,vi as Ae,vu as je,w as Me,wi as Ne,wu as Pe,xi as Fe,xl as Ie,xu as Le,yl as Re,yn as ze,zt as Be}from"./src-BqkvLgRS.js";import{t as Ve}from"./boxes-CNe0g7jU.js";import{t as He}from"./user-round-DMTk-6Io.js";import{$t as K,en as q,tn as J,vt as Ue}from"./src-4fqKwwai.js";import{d as Y,l as We,m as Ge}from"./index-DrF3b0h3.js";import{t as Ke}from"./AdminPage-CiKtOLQm.js";var qe=f(`circle-arrow-up`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m16 12-4-4-4 4`,key:`177agl`}],[`path`,{d:`M12 16V8`,key:`1sbj14`}]]);e();var Je={camera:d,hub:O,container:Ve,light:he,siren:Ie,switch:ve,sensor:le,thermostat:De,climate:Te,button:y,"event-emitter":ae,update:qe,notifier:R,script:h,automation:Se,lock:de,cover:we,valve:P,humidifier:Le,"water-heater":me,fan:je,"media-player":pe,"alarm-panel":re,control:Re,presence:He,weather:g,vacuum:E,"lawn-mower":ue,image:H,smoke:be};function X({type:e,className:t}){return o(Je[e]??y,{"aria-hidden":`true`,className:t??`h-3.5 w-3.5 shrink-0 text-foreground-subtle`})}function Ye({online:e,deviceName:t}){return o(`span`,{className:e?`inline-block h-1.5 w-1.5 shrink-0 rounded-full bg-emerald-500`:`inline-block h-1.5 w-1.5 shrink-0 rounded-full border border-foreground-subtle`,role:`img`,"aria-label":`${t}: ${e?`online`:`offline`}`,title:e?`online`:`offline`})}function Xe({name:e,description:n,busy:r,onSave:i}){let[c,l]=a(n??``);return s(()=>{l(n??``)},[n]),t(`div`,{className:`border-t border-border px-3 py-2`,children:[o(`label`,{htmlFor:`location-description-${e}`,className:`block text-[10px] font-medium uppercase tracking-wide text-foreground-subtle`,children:`What is there`}),o(`textarea`,{id:`location-description-${e}`,value:c,onChange:e=>l(e.target.value),onBlur:()=>{let e=c.trim();e!==(n??``)&&i(e.length===0?null:e)},disabled:r,rows:2,maxLength:400,placeholder:`Surfaces, boundaries, what is normally parked or stored here.`,className:`mt-1 w-full resize-y rounded border border-border bg-background px-1.5 py-1 text-[11px] text-foreground placeholder:text-foreground-subtle disabled:opacity-50`}),o(`p`,{className:`mt-0.5 text-[10px] text-foreground-subtle`,children:`Given to the AI with the pictures, so it knows what it is looking at. Describe the PLACE, not what happens in it — events change, the ground does not.`})]})}function Ze(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0||n.description.length===0?null:n.description}var Z=` none`;function Qe({name:e,zones:n,zoneKey:r,busy:i,onChange:a}){return n.length===0?null:t(`div`,{className:`flex items-center gap-2 border-t border-border px-3 py-1.5`,children:[o(`label`,{htmlFor:`location-zone-${e}`,className:`text-[10px] font-medium uppercase tracking-wide text-foreground-subtle`,children:`Zone`}),t(`select`,{id:`location-zone-${e}`,value:r??Z,disabled:i,onChange:e=>{let t=e.target.value;if(t===Z){a(null);return}let r=n.find(e=>e.zoneKey===t);r!==void 0&&a(r.label)},className:`min-w-0 flex-1 rounded border border-border bg-background px-1.5 py-0.5 text-[11px] text-foreground disabled:opacity-50`,children:[o(`option`,{value:Z,children:`— none —`}),n.map(e=>o(`option`,{value:e.zoneKey,children:e.label},e.zoneKey))]})]})}function $e(e,t){return e.find(e=>e.locationKeys.includes(t))?.zoneKey??null}var et={"map-pin":{icon:j,label:`Pin`},house:{icon:ye,label:`Home`},"door-open":{icon:Pe,label:`Entrance`},sofa:{icon:B,label:`Living room`},utensils:{icon:W,label:`Kitchen`},"bed-double":{icon:z,label:`Bedroom`},bath:{icon:p,label:`Bathroom`},briefcase:{icon:I,label:`Office`},car:{icon:C,label:`Garage`},"circle-parking":{icon:A,label:`Parking`},route:{icon:k,label:`Street`},trees:{icon:Ee,label:`Garden`},umbrella:{icon:ce,label:`Terrace`},"waves-ladder":{icon:L,label:`Pool`},fence:{icon:se,label:`Gate`},package:{icon:x,label:`Storage`},warehouse:{icon:oe,label:`Warehouse`},store:{icon:xe,label:`Shop`},sun:{icon:fe,label:`Outdoor`},radar:{icon:N,label:`Perimeter`}},tt=K.map(e=>({id:e,...et[e]}));function nt(e){return et[J(e)].icon}var rt=new Map(tt.map(e=>[e.id,[e.label]])),it=new Map(tt.map(e=>[e.id,e.label])),at=new Set(K);function ot(e){return at.has(e)?nt(e):void 0}function Q({name:e,icon:t,busy:n,onPick:r}){return o(Me,{value:t,onPick:e=>r(e===null?null:J(e)),resolveGlyph:ot,fallbackGlyph:j,clearGlyph:U,labelFor:e=>it.get(e),labels:{trigger:`Change the icon of ${e}`,panel:`Icon for ${e}`,close:`Close icon picker`,searchPlaceholder:`Search icons`,clear:`No icon`,noMatches:`No icon matches that`,groups:{device:`Devices`,lighting:`Lights and climate`,sensing:`Sensors and weather`,place:`Rooms and places`,life:`Vehicles, animals and people`}},only:K,extraWords:rt,disabled:n})}function st(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0?null:J(n.icon)}function $(e){if(e==null)return null;let t=e.trim();return t.length===0?null:t.toLowerCase()}function ct(e,t){let n=$(t);return n===null?[]:e.filter(e=>$(e.location)===n)}function lt(e,t){let n=ct(e,t),r=new Set(n.map(e=>e.id));return n.filter(e=>e.parentDeviceId===null||!r.has(e.parentDeviceId))}function ut(e,t){let n=$(e.location);return n===null||new Set(t.map(e=>$(e))).has(n)?null:e.location?.trim()??null}function dt(e,t){let n=$(e.location);return n!==null&&t.has(n)}function ft(e,t){let n=new Set(t.map(e=>$(e))),r=new Set(e.filter(e=>dt(e,n)).map(e=>e.id));return e.filter(e=>!(dt(e,n)||e.parentDeviceId!==null&&r.has(e.parentDeviceId)))}function pt(e,t){return ft(e,t).filter(e=>e.parentDeviceId===null)}function mt(e,t){let n=new Map;for(let t of e){if(t.parentDeviceId===null)continue;let e=n.get(t.parentDeviceId);e?e.push(t):n.set(t.parentDeviceId,[t])}let r=[],i=new Set([t]),a=[t];for(;a.length>0;){let e=[];for(let t of a)for(let a of n.get(t)??[])i.has(a.id)||(i.add(a.id),r.push(a),e.push(a.id));a=e}return r}function ht(e,t){return mt(e,t).length}function gt(e,t){return e.filter(e=>!e.isCamera&&e.parentDeviceId===t)}function _t(e,t){return t.map(t=>({name:t,members:lt(e,t)}))}function vt(e){return`${e.kind}:${String(e.device.id)}`}function yt(e,t,n){return e.flatMap(e=>{let r=gt(t,e.id),i=n.has(e.id),a={kind:`member`,device:e,accessories:r,open:i};return!i||r.length===0?[a]:[a,...r.map(t=>({kind:`accessory`,device:t,parent:e}))]})}e();function bt({name:e,members:i,devices:s,busy:c,icon:l,description:d,onRename:f,onDelete:p,onRebuildLinks:m,onPickIcon:h,onSaveDescription:g,zones:_,zoneKey:v,onChangeZone:y}){let{t:x}=We(),[S,C]=a(!1),[w,T]=a(e),E=V(i,n(()=>({searchText:e=>[e.name,...gt(s,e.id).map(e=>e.name)],facetValue:e=>e.type}),[s])),[D,te]=a(()=>new Set),O=e=>te(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),k=n(()=>yt(E.rows,s,D),[E.rows,s,D]),A=[{key:`name`,header:x(`locations.columns.device`),notSortableReason:x(`locations.columns.noSort`),render:e=>e.kind===`member`?o(xt,{row:e,onToggle:()=>O(e.device.id)}):o(St,{row:e})},{key:`type`,header:x(`locations.columns.type`),notSortableReason:x(`locations.columns.noSort`),render:e=>o(`span`,{className:`text-[11px] text-foreground-muted`,children:e.device.type})},{key:`status`,header:x(`locations.columns.status`),notSortableReason:x(`locations.columns.noSort`),render:e=>t(`span`,{className:`flex items-center gap-1.5`,children:[o(Ye,{online:e.device.online,deviceName:e.device.name}),o(`span`,{className:`text-[11px] text-foreground-muted`,children:e.device.online?`online`:`offline`})]})}],j=()=>{T(e),C(!1)},M=async()=>{let t=w.trim();if(t.length===0||t===e){j();return}await f(t),C(!1)};return t(`section`,{className:`min-w-0 rounded-md border border-border bg-surface`,children:[t(`header`,{className:`flex items-center gap-1.5 border-b border-border px-3 py-1.5`,children:[o(Q,{name:e,icon:l,busy:c,onPick:h}),S?t(r,{children:[o(`input`,{value:w,onChange:e=>T(e.target.value),onKeyDown:e=>{e.key===`Enter`&&M(),e.key===`Escape`&&j()},"aria-label":`Rename ${e}`,className:`min-w-0 flex-1 rounded border border-border bg-background px-1.5 py-0.5 text-sm font-semibold text-foreground`,autoFocus:!0}),o(`button`,{type:`button`,onClick:()=>void M(),className:`text-[11px] text-foreground-subtle hover:text-foreground`,children:`Save`}),o(`button`,{type:`button`,onClick:j,"aria-label":`Cancel rename`,className:`p-0.5 text-foreground-subtle hover:text-foreground`,children:o(b,{className:`h-3.5 w-3.5`})})]}):t(r,{children:[o(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:e}),o(ke,{items:[{id:`rename`,label:`Rename`,icon:F,disabled:c,onClick:()=>{T(e),C(!0)}},{id:`rebuild-links`,label:`Rebuild linked devices`,icon:ee,separatorBefore:!0,disabled:c,onClick:()=>void m()},{id:`delete`,label:`Delete`,icon:u,danger:!0,separatorBefore:!0,disabled:c,onClick:()=>void p()}],title:`Actions for ${e}`,triggerClassName:`p-1`})]})]}),o(Qe,{name:e,zones:_,zoneKey:v,busy:c,onChange:y}),o(Xe,{name:e,description:d,busy:c,onSave:g}),i.length>0&&o(`div`,{className:`border-b border-border px-3 py-1.5`,children:o(G,{state:E.state,facets:E.facets,labels:{searchPlaceholder:x(`locations.filter.searchPlaceholder`),searchLabel:x(`locations.room.searchLabel`,{room:e}),facetsLabel:x(`locations.filter.typesLabel`),clearLabel:x(`locations.filter.clear`)},onSearch:E.setSearch,onToggleFacet:E.toggleFacet,onClear:E.clear})}),i.length===0?o(`p`,{className:`px-3 py-3 text-[11px] text-foreground-subtle`,children:`Nothing here yet — assign a device from the table below.`}):o(Oe,{columns:A,rows:k,rowKey:vt,bordered:!1,minWidthPx:360,mobileMode:`scroll`,emptyMessage:x(`locations.filter.noMatch`)})]})}function xt({row:e,onToggle:n}){let{device:r,accessories:i,open:a}=e,s=a?c:l;return t(`span`,{className:`flex items-center gap-1.5`,children:[i.length>0?t(`button`,{type:`button`,onClick:n,"aria-expanded":a,"aria-label":`${a?`Collapse`:`Expand`} ${String(i.length)} companion device(s) of ${r.name}`,className:`flex shrink-0 items-center gap-0.5 rounded p-0.5 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:[o(s,{className:`h-3 w-3`}),o(`span`,{className:`text-[10px] tabular-nums`,children:i.length})]}):o(`span`,{"aria-hidden":`true`,className:`w-[1.35rem] shrink-0`}),o(X,{type:r.type}),o(Y,{to:`/devices/${String(r.id)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:r.name})]})}function St({row:e}){let{device:n}=e;return t(`span`,{className:`flex items-center gap-1.5 pl-6`,children:[o(`span`,{"aria-hidden":`true`,className:`text-[10px] text-foreground-subtle`,children:`└`}),o(X,{type:n.type,className:`h-3 w-3 shrink-0 text-foreground-subtle`}),o(Y,{to:`/devices/${String(n.id)}`,className:`min-w-0 truncate text-[11px] text-foreground-muted hover:underline`,children:n.name})]})}e();function Ct({zones:e,busy:n,onCreate:r,onRename:i,onDelete:s,onPickIcon:c}){let[l,d]=a(!1),[f,p]=a(``),[m,h]=a(null),[g,_]=a(``),v=async()=>{let e=f.trim();e.length!==0&&(await r(e),p(``),d(!1))},y=async e=>{let t=g.trim();h(null),!(t.length===0||t===e)&&await i(e,t)};return t(`section`,{className:`rounded-md border border-border bg-surface`,children:[t(`header`,{className:`flex items-center gap-2 border-b border-border px-3 py-1.5`,children:[o(`h2`,{className:`flex-1 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Zones`}),l?null:t(`button`,{type:`button`,onClick:()=>d(!0),disabled:n,className:`flex items-center gap-1 text-[11px] text-foreground-muted hover:text-foreground disabled:opacity-50`,children:[o(S,{className:`h-3 w-3`}),` New zone`]})]}),l&&t(`div`,{className:`flex items-center gap-1.5 border-b border-border px-3 py-1.5`,children:[o(`input`,{value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&v(),e.key===`Escape`&&(p(``),d(!1))},placeholder:`Zona notte`,"aria-label":`New zone name`,autoFocus:!0,className:`min-w-0 flex-1 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`}),o(`button`,{type:`button`,onClick:()=>void v(),className:`text-[11px] text-foreground-subtle hover:text-foreground`,children:`Add`}),o(`button`,{type:`button`,onClick:()=>{p(``),d(!1)},"aria-label":`Cancel new zone`,className:`p-0.5 text-foreground-subtle hover:text-foreground`,children:o(b,{className:`h-3.5 w-3.5`})})]}),e.length===0?o(`p`,{className:`px-3 py-2 text-[11px] text-foreground-subtle`,children:`No zones yet. A zone groups rooms — “Zona notte” for the bedrooms — and shows up before them in the app’s camera filter.`}):o(`ul`,{className:`py-0.5`,children:e.map(e=>t(`li`,{className:`flex items-center gap-1.5 px-3 py-1`,children:[o(Q,{name:e.label,icon:e.icon,busy:n,onPick:t=>c(e.label,t)}),m===e.label?o(`input`,{value:g,onChange:e=>_(e.target.value),onKeyDown:t=>{t.key===`Enter`&&y(e.label),t.key===`Escape`&&h(null)},onBlur:()=>void y(e.label),"aria-label":`Rename ${e.label}`,autoFocus:!0,className:`min-w-0 flex-1 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`}):o(`button`,{type:`button`,onClick:()=>{_(e.label),h(e.label)},disabled:n,className:`min-w-0 flex-1 truncate text-left text-xs text-foreground hover:underline disabled:opacity-50`,children:e.label}),o(`span`,{className:`shrink-0 text-[10px] tabular-nums text-foreground-subtle`,children:e.locationKeys.length===0?`empty`:`${String(e.locationKeys.length)} rooms`}),o(`button`,{type:`button`,onClick:()=>void s(e.label),disabled:n,"aria-label":`Delete ${e.label}`,title:`Delete the zone — the rooms in it are kept`,className:`shrink-0 p-0.5 text-foreground-subtle hover:text-danger disabled:opacity-50`,children:o(u,{className:`h-3.5 w-3.5`})})]},e.zoneKey))})]})}e();function wt({busy:e,onCreate:n}){let[r,i]=a(!1),[s,c]=a(``),l=()=>{c(``),i(!1)},u=async()=>{let e=s.trim();e.length!==0&&(await n(e),l())};return r?t(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),u()},children:[o(`input`,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Escape`&&l()},placeholder:`Ingresso, Salone, Cucina…`,"aria-label":`New location name`,className:`min-w-[16rem] flex-1 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,autoFocus:!0}),t(`button`,{type:`submit`,disabled:s.trim().length===0||e,className:`inline-flex items-center gap-1 rounded border border-border bg-surface px-2 py-1.5 text-xs font-medium text-foreground hover:bg-surface-hover disabled:opacity-50`,children:[o(S,{className:`h-3.5 w-3.5`}),`Add`]}),o(`button`,{type:`button`,onClick:l,"aria-label":`Cancel new location`,className:`p-1 text-foreground-subtle hover:text-foreground`,children:o(b,{className:`h-3.5 w-3.5`})})]}):t(`button`,{type:`button`,onClick:()=>i(!0),className:`inline-flex w-fit items-center gap-1 rounded border border-border bg-surface px-2 py-1.5 text-xs font-medium text-foreground hover:bg-surface-hover`,children:[o(S,{className:`h-3.5 w-3.5`}),`New location`]})}e();var Tt={searchText:e=>[e.name],facetValue:e=>e.type};function Et({rows:e,fleet:r,locations:i,busy:s,emptyMessage:c,onAssign:l}){let{t:u}=We(),[d,f]=a([]),[p,m]=a(``),h=V(e,Tt),g=h.rows,_=n(()=>g.map(e=>e.id),[g]),v=n(()=>d.filter(e=>_.includes(e)),[d,_]),y=g.length>0&&v.length===g.length,b=n(()=>{let t=new Map;for(let n of e)t.set(n.id,ht(r,n.id));return t},[e,r]),x=v.reduce((e,t)=>e+(b.get(t)??0),0),S=e=>f(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),C=()=>f(y?[]:_);return t(`section`,{className:`space-y-2`,children:[t(`header`,{className:`flex flex-wrap items-baseline gap-2`,children:[o(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Not in a room`}),o(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Top-level devices only — accessories move with their parent.`})]}),e.length>0&&o(G,{state:h.state,facets:h.facets,labels:{searchPlaceholder:u(`locations.filter.searchPlaceholder`),searchLabel:u(`locations.unassigned.searchLabel`),facetsLabel:u(`locations.filter.typesLabel`),clearLabel:u(`locations.filter.clear`)},onSearch:h.setSearch,onToggleFacet:h.toggleFacet,onClear:h.clear}),v.length>0&&t(`div`,{role:`group`,"aria-label":`Bulk assignment`,className:`flex flex-wrap items-center gap-2 rounded border border-primary/40 bg-primary/5 px-2 py-1.5`,children:[t(`span`,{className:`text-[11px] text-foreground`,children:[v.length,` selected`,x>0&&` · ${String(x)} accessories in tow`]}),t(`select`,{"aria-label":`Assign selected devices to`,value:p,onChange:e=>m(e.target.value),className:`rounded border border-border bg-background px-1.5 py-0.5 text-[11px] text-foreground`,children:[o(`option`,{value:``,children:`Assign to…`}),i.map(e=>o(`option`,{value:e,children:e},e))]}),o(`button`,{type:`button`,onClick:()=>{p.length===0||v.length===0||(l(v,p),f([]),m(``))},disabled:s||p.length===0,className:`rounded border border-border bg-surface px-2 py-0.5 text-[11px] font-medium text-foreground hover:bg-surface-hover disabled:opacity-50`,children:`Assign`}),o(`button`,{type:`button`,onClick:()=>f([]),className:`text-[11px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),o(Oe,{columns:[{key:`select`,width:`w-8`,headerRender:()=>o(Be,{checked:y,onChange:C,"aria-label":y?`Clear selection`:`Select all unassigned devices`}),render:e=>o(Be,{checked:v.includes(e.id),onChange:()=>S(e.id),"aria-label":`Select ${e.name}`})},{key:`name`,header:`Device`,sortValue:e=>e.name.toLowerCase(),render:e=>{let n=ut(e,i);return t(`span`,{className:`flex items-center gap-1.5`,children:[o(X,{type:e.type}),o(Y,{to:`/devices/${String(e.id)}`,className:`truncate text-xs text-foreground hover:underline`,children:e.name}),n!==null&&t(`span`,{className:`rounded-full border border-warning/40 px-1.5 py-px text-[10px] text-warning`,children:[`unknown room “`,n,`”`]})]})}},{key:`type`,header:`Type`,sortValue:e=>e.type,render:e=>o(`span`,{className:`text-[11px] text-foreground-muted`,children:e.type})},{key:`status`,header:`Status`,sortValue:e=>+!!e.online,render:e=>t(`span`,{className:`flex items-center gap-1.5`,children:[o(Ye,{online:e.online,deviceName:e.name}),o(`span`,{className:`text-[11px] text-foreground-muted`,children:e.online?`online`:`offline`})]})},{key:`followers`,header:`Accessories in tow`,align:`right`,sortValue:e=>b.get(e.id)??0,render:e=>o(`span`,{className:`tabular-nums text-[11px] text-foreground-muted`,children:b.get(e.id)??0})},{key:`assign`,header:`Assign to`,align:`right`,notSortableReason:`This column is a control, not a value.`,render:e=>t(`select`,{"aria-label":`Location for ${e.name}`,value:``,disabled:s||i.length===0,onChange:t=>{let n=t.target.value;n.length!==0&&l([e.id],n)},className:`max-w-[11rem] rounded border border-border bg-background px-1.5 py-0.5 text-[11px] text-foreground disabled:opacity-50`,children:[o(`option`,{value:``,children:`—`}),i.map(e=>o(`option`,{value:e,children:e},e))]})}],rows:g,rowKey:e=>e.id,minWidthPx:720,mobileMode:`scroll`,emptyMessage:h.active?u(`locations.filter.noMatch`):c})]})}function Dt(e){return{id:e.id,parentDeviceId:e.parentDeviceId,location:e.location,type:e.type,stableId:e.stableId??``,...e.primaryChildEntityId===void 0?{}:{primaryChildEntityId:e.primaryChildEntityId},...e.role!==void 0&&e.role!==null?{role:e.role}:{},name:e.name}}function Ot(e,t){let n=t.map(Dt),r=[];for(let i of t)i.isCamera&&i.location===e&&r.push({deviceId:i.id,name:i.name,ids:Ue({selfId:i.id,selfLocation:i.location,candidates:n})});return{entries:r}}var kt=`device-manager:linked-devices`;function At(e){return{deviceId:e.deviceId,slotRef:kt,value:{slot:`linked-devices`,deviceIds:[...e.ids]}}}e();function jt(){let e=i(),r=ze(),{data:a,isLoading:s}=_(),{data:c}=ne(),{data:l}=Fe(),{data:u}=Ne(),{data:d,isLoading:f}=Ae({projection:`slim`}),p=()=>{e.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listLocationIcons`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listLocationDescriptions`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listSiteZones`]]})},h=T({onSuccess:p}),g=_e({onSuccess:p}),y=v({onSuccess:p}),b=ge({onSuccess:p}),x=D({onSuccess:p}),S=w({onSuccess:p}),C=ie({onSuccess:p}),ee=m({onSuccess:p}),E=te({onSuccess:p}),O=M({onSuccess:p}),k=Ce(),A=n(()=>(d??[]).map(e=>({id:e.id,name:e.name,location:e.location??null,type:String(e.type),isCamera:e.isCamera,parentDeviceId:e.parentDeviceId,online:e.online,role:e.role??null,stableId:e.stableId,primaryChildEntityId:e.primaryChildEntityId??null})),[d]),N=a??[],P=n(()=>_t(A,N),[A,N]),[re,ae]=Ge(),F=re.get(`room`),I=F!==null&&P.some(e=>e.name===F)?F:P[0]?.name??null,L=P.find(e=>e.name===I)??null,R=e=>{ae(t=>{let n=new URLSearchParams(t);return n.set(`room`,e),n},{replace:!0})},oe=n(()=>pt(A,N),[A,N]),z=s||f,B=y.isPending||g.isPending||h.isPending||x.isPending,se=async e=>{await h.mutateAsync({name:e})},ce=async(e,t)=>{let n=t.trim();n.length===0||n===e||await b.mutateAsync({from:e,to:n})},le=async e=>{let t=Ot(e,A);if(t.entries.length===0){await r({title:`Rebuild linked devices`,message:`No camera is assigned to “${e}”.`,confirmLabel:`OK`});return}if(!await r({title:`Rebuild linked devices`,message:`Replace the linked-device list of every camera in “${e}” with what the room contains?\n\n${t.entries.map(e=>`• ${e.name}: ${String(e.ids.length)} device(s)`).join(`
|
|
2
|
+
`)}\n\nAnything linked by hand that is not in this room is lost.`,confirmLabel:`Rebuild`,variant:`danger`}))return;let n=[];for(let e of t.entries)try{await k.mutateAsync(At(e))}catch(t){n.push(`• ${e.name}: ${t instanceof Error?t.message:String(t)}`)}p(),n.length>0&&await r({title:`Rebuild linked devices`,message:`Not rebuilt:\n\n${n.join(`
|
|
3
|
+
`)}`,confirmLabel:`OK`})},ue=async(e,t)=>{await r({title:`Delete location`,message:`Delete the location “${e}”?${t>0?` ${String(t)} device(s) will become unassigned.`:``}`,confirmLabel:`Delete`,variant:`danger`})&&await g.mutateAsync({name:e,cascade:!0})},V=async(e,t)=>{await x.mutateAsync({location:e,icon:t})},H=async(e,t)=>{await S.mutateAsync({location:e,description:t})},U=u??[],W=async(e,t)=>{await O.mutateAsync({location:e,zone:t})};return t(Ke,{icon:j,title:`Locations`,subtitle:`Rooms and areas of the site. Assign any device here — storage disks are under Data → Storage.`,children:[o(wt,{busy:h.isPending,onCreate:se}),o(Ct,{zones:U,busy:B,onCreate:e=>C.mutateAsync({name:e}),onRename:(e,t)=>E.mutateAsync({from:e,to:t}),onDelete:e=>ee.mutateAsync({name:e}),onPickIcon:(e,t)=>C.mutateAsync({name:e,icon:t})}),z&&o(`p`,{className:`text-xs text-foreground-subtle`,children:`Loading locations and devices…`}),P.length>0&&o(`div`,{role:`tablist`,"aria-label":`Locations`,className:`-mx-1 flex gap-1 overflow-x-auto px-1 pb-1`,children:P.map(e=>{let n=e.name===I,r=nt(st(c,q(e.name)));return t(`button`,{type:`button`,role:`tab`,"aria-selected":n,onClick:()=>R(e.name),className:n?`shrink-0 whitespace-nowrap rounded-full border border-primary bg-primary/10 px-3 py-1 text-xs text-foreground`:`shrink-0 whitespace-nowrap rounded-full border border-border px-3 py-1 text-xs text-foreground-muted hover:bg-surface-hover`,children:[o(r,{className:`mr-1 inline h-3.5 w-3.5 align-text-bottom`}),e.name,` `,o(`span`,{className:`text-foreground-subtle tabular-nums`,children:e.members.length})]},e.name)})}),L!==null&&o(bt,{name:L.name,members:L.members,devices:A,busy:B,icon:st(c,q(L.name)),onPickIcon:e=>V(L.name,e),description:Ze(l,q(L.name)),onSaveDescription:e=>H(L.name,e),zones:U,zoneKey:$e(U,q(L.name)),onChangeZone:e=>W(L.name,e),onRename:e=>ce(L.name,e),onDelete:()=>ue(L.name,ct(A,L.name).length),onRebuildLinks:()=>le(L.name)},L.name),N.length===0&&!z&&o(`p`,{className:`text-xs text-foreground-subtle`,children:`No locations yet. Add Ingresso, Salone, Cucina…`}),o(Et,{rows:oe,fleet:A,locations:N,busy:B,emptyMessage:z?`Loading…`:`Every top-level device has a room.`,onAssign:(e,t)=>{for(let n of e)y.mutate({deviceId:n,location:t})}})]})}export{jt as LocationsPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Q as e,S as t,W as n,q as r,x as i}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{vt as a,yt as o}from"./player-overlays-Dpyv2MuF.js";import{Bs as s,Gu as c,Hn as l,Rs as u,Un as d,pl as f,tt as p,wu as m,xc as h,zl as g}from"./src-DeANpHOz.js";import{t as _}from"./layers-DRiv_qOz.js";import{c as v,n as y}from"./index-SOjqIyqv.js";import{t as b}from"./AdminPage-CiKtOLQm.js";import{t as x}from"./AdminTabs-Os_saxNF.js";import{t as S}from"./AddonCollectionPage-BKRsM_qT.js";import{t as C}from"./addon-display-names-DvSEQty-.js";var w=o(`file-text`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),T=o(`timer-reset`,[[`path`,{d:`M10 2h4`,key:`n1abiw`}],[`path`,{d:`M12 14v-4`,key:`1evpnu`}],[`path`,{d:`M4 13a8 8 0 0 1 8-7 8 8 0 1 1-5.3 14L4 17.6`,key:`1ts96g`}],[`path`,{d:`M9 17H4v5`,key:`8t5av`}]]);e();var E=5e3,D={"winston-logging":`Rotated log files on this node’s disk.`,"console-logging":`stdout / stderr of the node process.`,"loki-logging":`Pushes to a Grafana Loki instance. Off until enabled with a URL.`,"hub-forwarder":`Agent-only — forwards this node’s entries to the hub.`};function O(){let e=d({capName:`log-destination`},{refetchInterval:E}),t=l(void 0,{refetchInterval:E}),r=n(()=>C(t.data??[]),[t.data]),a=n(()=>{let e=new Map;for(let n of t.data??[]){let t=n.description,r=n.id;typeof r==`string`&&typeof t==`string`&&t.length>0&&e.set(r,t)}return e},[t.data]);return i(S,{title:`Logging`,subtitle:`Every registered log destination. Entries are fanned to all enabled destinations at once — enabling one does not disable another. Each destination's own configuration is docked under it.`,pageIcon:f,itemIcon:w,capability:`log-destination`,installButtonLabel:`Add destination`,items:n(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:r.get(e.addonId)??e.addonId,isActive:e.isActive,caption:a.get(e.addonId)??D[e.addonId]??``})),[e.data,r,a]),isLoading:e.isLoading,emptyTitle:`No log destinations registered`,emptyDescription:`This should not happen — the console and rotated-file destinations are builtins. If the list is empty, the node is still booting.`,renderStatusBadges:e=>e.caption.length>0?i(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.caption}):null})}e();var k=[12e4,3e5,6e5,18e5],A={"request-census":`Counts every tRPC call by TRANSPORT PLANE — http, ws, mesh — and by procedure, caller, address and user-agent. Subscriptions are counted apart from calls, so a long-lived stream cannot pass for a storm. Arm it, then restart: the deadline is persisted, so the window is still running when clients reconnect.`};function j(){let{t:e}=y(),n=u({},{refetchInterval:5e3}),a=s(),[o,l]=r(null),d=(e,t)=>{l(e),a.mutate({patch:{diagnostics:[{id:e,armMs:t}]}},{onSettled:()=>{l(null),n.refetch()}})},f=n.data?.activeWindows??[],p=n.data?.channels??[],m=n.data?.activeChannels??[],h=(e,t,r)=>{l(e),a.mutate({patch:{channels:[{channel:e,armMs:t,deviceIds:r}]}},{onSettled:()=>{l(null),n.refetch()}})};return t(b,{icon:c,title:e(`logging.diagnostics.title`,`Diagnostics`),subtitle:e(`logging.diagnostics.subtitle`,`Diagnostics are armed for a window, never switched on. Each carries a deadline and expires by itself — one left running is an incident of its own.`),children:[n.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(g,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}):i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:f.map(e=>i(N,{window:e,busy:o===e.id,onArm:t=>d(e.id,t)},e.id))}),i(`h3`,{className:`mt-6 text-sm font-medium text-foreground`,children:e(`logging.diagnostics.channels`,`Component channels`)}),i(`p`,{className:`mb-2 max-w-3xl text-[11px] text-foreground-subtle`,children:e(`logging.diagnostics.channelsSubtitle`,`Declared by the addons that own them — this list is not maintained by hand. Arming a channel opens a window with a deadline; it closes by itself.`)}),p.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`logging.diagnostics.noChannels`,`No addon on this cluster declares a log channel, or none could be reached right now.`)}):i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:p.map(e=>i(M,{channel:e,state:m.find(t=>t.channel===e.name),busy:o===e.name,onArm:(t,n)=>h(e.name,t,n)},e.name))})]})}function M({channel:e,state:n,busy:o,onArm:s}){let{t:c}=y(),[l,u]=r(``),d=n?.armed===!0,f=()=>{let e=l.split(/[\s,+]+/).filter(e=>/^\d+$/.test(e)).map(e=>Number(e));return e.length>0?e:null};return t(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.name}),d?t(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[i(T,{className:`h-3 w-3`}),c(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:P(n?.remainingMs??0)})]}):i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:c(`logging.diagnostics.disarmed`,`disarmed`)}),d&&n?.deviceIds!==null&&n?.deviceIds!==void 0&&t(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[i(a,{className:`h-3 w-3`}),n.deviceIds.join(`, `)]}),!e.perDevice&&i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:c(`logging.diagnostics.notPerCamera`,`not filterable per camera`)})]}),i(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:e.description})]}),t(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[e.perDevice&&i(`input`,{type:`text`,inputMode:`numeric`,value:l,disabled:o,onChange:e=>u(e.target.value),placeholder:c(`logging.diagnostics.camerasPlaceholder`,`all cameras`),className:`w-28 rounded border border-border bg-surface px-2 py-1 text-[11px] text-foreground`}),k.map(e=>i(`button`,{type:`button`,disabled:o,onClick:()=>s(e,f()),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:P(e)},e)),i(`button`,{type:`button`,disabled:o||!d,onClick:()=>s(0,null),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:c(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function N({window:e,busy:n,onArm:r}){let{t:a}=y();return t(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.id}),e.armed?t(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[i(T,{className:`h-3 w-3`}),a(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:P(e.remainingMs)})]}):i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:a(`logging.diagnostics.disarmed`,`disarmed`)}),e.armed&&!e.persisted&&i(`span`,{className:`text-[10px] text-warning`,children:a(`logging.diagnostics.notPersisted`,`not persisted — will not survive a restart`)})]}),i(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:A[e.id]??``})]}),t(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[k.map(e=>i(`button`,{type:`button`,disabled:n,onClick:()=>r(e),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:P(e)},e)),i(`button`,{type:`button`,disabled:n||!e.armed,onClick:()=>r(0),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:a(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function P(e){let t=Math.max(0,Math.round(e/1e3)),n=Math.floor(t/60),r=t%60;return n===0?`${r}s`:r===0?`${n}m`:`${n}m ${r}s`}e();var F=[`debug`,`info`,`warn`,`error`],I=``,L=``;function R(){let{t:e}=y(),[a,o]=r(I),[c,l]=r(L),{nodes:d}=h(),f=n(()=>d.map(e=>({id:e.id,label:e.name||e.id})),[d]),p=u({...a===I?{}:{scopeNodeId:a},...c===L?{}:{scopeComponent:c}},{refetchInterval:15e3}),m=s(),v=p.data,x=m.isPending||p.isFetching,S=v?.channels??[],C=(e,t)=>{m.mutate({...e.nodeId===null?{}:{scopeNodeId:e.nodeId},...e.component===null?{}:{scopeComponent:e.component},patch:{level:t}},{onSuccess:()=>void p.refetch()})};return i(b,{icon:_,title:e(`logging.levels.title`,`Levels`),subtitle:e(`logging.levels.subtitle`,`Cluster → node, most specific wins. The floor gates what reaches the log destinations; the in-memory viewer keeps every line either way.`),actions:t(`div`,{className:`flex flex-wrap items-center gap-3`,children:[t(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[e(`logging.levels.scope`,`Scope`),t(`select`,{className:`rounded border border-border bg-surface px-2 py-1 text-xs text-foreground disabled:opacity-50`,value:a,disabled:c!==L,onChange:e=>o(e.target.value),children:[i(`option`,{value:I,children:e(`logging.levels.cluster`,`Cluster`)}),f.map(e=>i(`option`,{value:e.id,children:e.label},e.id))]})]}),t(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[e(`logging.levels.component`,`Component`),t(`select`,{className:`rounded border border-border bg-surface px-2 py-1 text-xs text-foreground`,value:c,onChange:e=>l(e.target.value),children:[i(`option`,{value:L,children:e(`logging.levels.noComponent`,`None`)}),S.map(e=>i(`option`,{value:e.name,children:e.name},e.name))]})]})]}),children:p.isLoading||v===void 0?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(g,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}):t(`div`,{className:`space-y-3`,children:[i(B,{level:v.effective.level,source:v.effective.levelSource,persisted:v.persisted}),i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:v.explicit.layers.map(e=>i(V,{layer:e,inForce:e.scope===v.effective.levelSource,busy:x,onSet:t=>C(e,t),onClear:()=>C(e,null)},`${e.scope}:${e.nodeId??e.component??`cluster`}`))}),c!==L&&i(`p`,{className:`text-[11px] text-foreground-subtle`,children:S.find(e=>e.name===c)?.description??``}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`logging.levels.componentNote`,`A component is a log channel an addon declared. Its level is cluster-wide and beats both the node and the cluster layer.`)}),i(z,{days:v.opsLogRetentionDays,busy:x,onSet:e=>m.mutate({patch:{opsLogRetentionDays:e}},{onSuccess:()=>void p.refetch()})})]})})}function z({days:e,busy:n,onSet:r}){let{t:a}=y();return t(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-1`,children:[t(`label`,{className:`flex items-center justify-between gap-3`,children:[i(`span`,{className:`text-xs font-medium`,children:a(`logging.levels.opsLogRetention`,`Retention audit trail`)}),t(`span`,{className:`flex items-center gap-1.5`,children:[i(`input`,{type:`number`,min:0,max:3650,step:1,defaultValue:e,disabled:n,onBlur:t=>{let n=Number.parseInt(t.target.value,10);Number.isFinite(n)&&n!==e&&r(n)},className:`w-20 rounded border border-border bg-surface px-2 py-1 text-xs`}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:a(`common.days`,`days`)})]})]}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`logging.levels.opsLogRetentionNote`,`How long the record of what retention deleted is kept. Cluster-wide, and deliberately longer than any camera window — it is the history of the sweep, not of the camera, and it is what makes a storage leak explainable after the fact. 0 keeps it forever.`)})]})}function B({level:e,source:n,persisted:r}){let{t:a}=y();return t(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-xs text-foreground-subtle`,children:a(`logging.levels.effective`,`In force here`)}),i(`span`,{className:`rounded bg-primary/10 px-2 py-0.5 text-xs font-semibold text-primary`,children:e}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:n==="default"?a(`logging.levels.fromDefault`,`nothing is set anywhere — this is the default`):a(`logging.levels.fromLayer`,`decided by the {{source}} layer`,{source:n})})]}),!r&&i(`p`,{className:`mt-1 text-[11px] text-warning`,children:a(`logging.levels.notPersisted`,`The settings store could not be read or written — what you see is live, but it would not survive a restart.`)})]})}function V({layer:e,inForce:n,busy:r,onSet:a,onClear:o}){let{t:s}=y();return t(`div`,{className:`flex flex-col gap-2 p-3 sm:flex-row sm:items-center sm:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.scope===`cluster`?s(`logging.levels.cluster`,`Cluster`):e.scope===`component`?e.component??``:e.nodeId??``}),n&&t(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[i(m,{className:`h-3 w-3`}),s(`logging.levels.inForce`,`in force`)]})]}),i(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:e.level===null?s(`logging.levels.inherits`,`inherits — nothing set at this layer`):s(`logging.levels.setHere`,`set here: {{level}}`,{level:e.level})})]}),t(`div`,{className:`flex shrink-0 items-center gap-1`,children:[F.map(t=>i(`button`,{type:`button`,disabled:r,onClick:()=>a(t),className:`rounded px-2 py-1 text-[11px] font-medium transition-colors disabled:opacity-50 ${e.level===t?`bg-primary text-primary-foreground`:`border border-border text-foreground-subtle hover:text-foreground`}`,children:t},t)),i(`button`,{type:`button`,disabled:r||e.level===null,onClick:o,className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-40`,children:s(`logging.levels.clear`,`Clear`)})]})]})}function H(){return i(b,{children:i(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:i(p,{limit:500,maxHeight:`max-h-[calc(100vh-310px)]`,showScope:!0,showFilters:!0})})})}function U(){return i(`div`,{className:`flex flex-col p-4`,children:i(x,{tabs:[{id:`viewer`,label:`Viewer`,icon:v,content:i(H,{})},{id:`destinations`,label:`Destinations`,icon:f,content:i(O,{})},{id:`levels`,label:`Levels`,icon:_,content:i(R,{})},{id:`diagnostics`,label:`Diagnostics`,icon:c,content:i(j,{})}]})})}export{U as LogsPage};
|
|
1
|
+
import{Q as e,S as t,W as n,q as r,x as i}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{vt as a,yt as o}from"./player-overlays-gbZ2vznV.js";import{Al as s,Gn as c,Rc as l,Vu as u,Wn as d,cd as f,nu as p,rc as m,tc as h,tt as g}from"./src-BqkvLgRS.js";import{t as _}from"./layers-DH10EL_n.js";import{h as v,l as y}from"./index-DrF3b0h3.js";import{t as b}from"./AdminPage-CiKtOLQm.js";import{t as x}from"./AdminTabs-CDIoD5NP.js";import{t as S}from"./AddonCollectionPage-C9l7ftV0.js";import{t as C}from"./addon-display-names-DvSEQty-.js";var w=o(`file-text`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),T=o(`timer-reset`,[[`path`,{d:`M10 2h4`,key:`n1abiw`}],[`path`,{d:`M12 14v-4`,key:`1evpnu`}],[`path`,{d:`M4 13a8 8 0 0 1 8-7 8 8 0 1 1-5.3 14L4 17.6`,key:`1ts96g`}],[`path`,{d:`M9 17H4v5`,key:`8t5av`}]]);e();var E=5e3,D={"winston-logging":`Rotated log files on this node’s disk.`,"console-logging":`stdout / stderr of the node process.`,"loki-logging":`Pushes to a Grafana Loki instance. Off until enabled with a URL.`,"hub-forwarder":`Agent-only — forwards this node’s entries to the hub.`};function O(){let e=c({capName:`log-destination`},{refetchInterval:E}),t=d(void 0,{refetchInterval:E}),r=n(()=>C(t.data??[]),[t.data]),a=n(()=>{let e=new Map;for(let n of t.data??[]){let t=n.description,r=n.id;typeof r==`string`&&typeof t==`string`&&t.length>0&&e.set(r,t)}return e},[t.data]);return i(S,{title:`Logging`,subtitle:`Every registered log destination. Entries are fanned to all enabled destinations at once — enabling one does not disable another. Each destination's own configuration is docked under it.`,pageIcon:s,itemIcon:w,capability:`log-destination`,installButtonLabel:`Add destination`,items:n(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:r.get(e.addonId)??e.addonId,isActive:e.isActive,caption:a.get(e.addonId)??D[e.addonId]??``})),[e.data,r,a]),isLoading:e.isLoading,emptyTitle:`No log destinations registered`,emptyDescription:`This should not happen — the console and rotated-file destinations are builtins. If the list is empty, the node is still booting.`,renderStatusBadges:e=>e.caption.length>0?i(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.caption}):null})}e();var k=[12e4,3e5,6e5,18e5],A={"request-census":`Counts every tRPC call by TRANSPORT PLANE — http, ws, mesh — and by procedure, caller, address and user-agent. Subscriptions are counted apart from calls, so a long-lived stream cannot pass for a storm. Arm it, then restart: the deadline is persisted, so the window is still running when clients reconnect.`};function j(){let{t:e}=y(),n=h({},{refetchInterval:5e3}),a=m(),[o,s]=r(null),c=(e,t)=>{s(e),a.mutate({patch:{diagnostics:[{id:e,armMs:t}]}},{onSettled:()=>{s(null),n.refetch()}})},l=n.data?.activeWindows??[],u=n.data?.channels??[],d=n.data?.activeChannels??[],g=(e,t,r)=>{s(e),a.mutate({patch:{channels:[{channel:e,armMs:t,deviceIds:r}]}},{onSettled:()=>{s(null),n.refetch()}})};return t(b,{icon:f,title:e(`logging.diagnostics.title`,`Diagnostics`),subtitle:e(`logging.diagnostics.subtitle`,`Diagnostics are armed for a window, never switched on. Each carries a deadline and expires by itself — one left running is an incident of its own.`),children:[n.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(p,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}):i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:l.map(e=>i(N,{window:e,busy:o===e.id,onArm:t=>c(e.id,t)},e.id))}),i(`h3`,{className:`mt-6 text-sm font-medium text-foreground`,children:e(`logging.diagnostics.channels`,`Component channels`)}),i(`p`,{className:`mb-2 max-w-3xl text-[11px] text-foreground-subtle`,children:e(`logging.diagnostics.channelsSubtitle`,`Declared by the addons that own them — this list is not maintained by hand. Arming a channel opens a window with a deadline; it closes by itself.`)}),u.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`logging.diagnostics.noChannels`,`No addon on this cluster declares a log channel, or none could be reached right now.`)}):i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:u.map(e=>i(M,{channel:e,state:d.find(t=>t.channel===e.name),busy:o===e.name,onArm:(t,n)=>g(e.name,t,n)},e.name))})]})}function M({channel:e,state:n,busy:o,onArm:s}){let{t:c}=y(),[l,u]=r(``),d=n?.armed===!0,f=()=>{let e=l.split(/[\s,+]+/).filter(e=>/^\d+$/.test(e)).map(e=>Number(e));return e.length>0?e:null};return t(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.name}),d?t(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[i(T,{className:`h-3 w-3`}),c(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:P(n?.remainingMs??0)})]}):i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:c(`logging.diagnostics.disarmed`,`disarmed`)}),d&&n?.deviceIds!==null&&n?.deviceIds!==void 0&&t(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[i(a,{className:`h-3 w-3`}),n.deviceIds.join(`, `)]}),!e.perDevice&&i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:c(`logging.diagnostics.notPerCamera`,`not filterable per camera`)})]}),i(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:e.description})]}),t(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[e.perDevice&&i(`input`,{type:`text`,inputMode:`numeric`,value:l,disabled:o,onChange:e=>u(e.target.value),placeholder:c(`logging.diagnostics.camerasPlaceholder`,`all cameras`),className:`w-28 rounded border border-border bg-surface px-2 py-1 text-[11px] text-foreground`}),k.map(e=>i(`button`,{type:`button`,disabled:o,onClick:()=>s(e,f()),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:P(e)},e)),i(`button`,{type:`button`,disabled:o||!d,onClick:()=>s(0,null),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:c(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function N({window:e,busy:n,onArm:r}){let{t:a}=y();return t(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.id}),e.armed?t(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[i(T,{className:`h-3 w-3`}),a(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:P(e.remainingMs)})]}):i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:a(`logging.diagnostics.disarmed`,`disarmed`)}),e.armed&&!e.persisted&&i(`span`,{className:`text-[10px] text-warning`,children:a(`logging.diagnostics.notPersisted`,`not persisted — will not survive a restart`)})]}),i(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:A[e.id]??``})]}),t(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[k.map(e=>i(`button`,{type:`button`,disabled:n,onClick:()=>r(e),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:P(e)},e)),i(`button`,{type:`button`,disabled:n||!e.armed,onClick:()=>r(0),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:a(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function P(e){let t=Math.max(0,Math.round(e/1e3)),n=Math.floor(t/60),r=t%60;return n===0?`${r}s`:r===0?`${n}m`:`${n}m ${r}s`}e();var F=[`debug`,`info`,`warn`,`error`],I=``,L=``;function R(){let{t:e}=y(),[a,o]=r(I),[s,c]=r(L),{nodes:u}=l(),d=n(()=>u.map(e=>({id:e.id,label:e.name||e.id})),[u]),f=h({...a===I?{}:{scopeNodeId:a},...s===L?{}:{scopeComponent:s}},{refetchInterval:15e3}),g=m(),v=f.data,x=g.isPending||f.isFetching,S=v?.channels??[],C=(e,t)=>{g.mutate({...e.nodeId===null?{}:{scopeNodeId:e.nodeId},...e.component===null?{}:{scopeComponent:e.component},patch:{level:t}},{onSuccess:()=>void f.refetch()})};return i(b,{icon:_,title:e(`logging.levels.title`,`Levels`),subtitle:e(`logging.levels.subtitle`,`Cluster → node, most specific wins. The floor gates what reaches the log destinations; the in-memory viewer keeps every line either way.`),actions:t(`div`,{className:`flex flex-wrap items-center gap-3`,children:[t(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[e(`logging.levels.scope`,`Scope`),t(`select`,{className:`rounded border border-border bg-surface px-2 py-1 text-xs text-foreground disabled:opacity-50`,value:a,disabled:s!==L,onChange:e=>o(e.target.value),children:[i(`option`,{value:I,children:e(`logging.levels.cluster`,`Cluster`)}),d.map(e=>i(`option`,{value:e.id,children:e.label},e.id))]})]}),t(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[e(`logging.levels.component`,`Component`),t(`select`,{className:`rounded border border-border bg-surface px-2 py-1 text-xs text-foreground`,value:s,onChange:e=>c(e.target.value),children:[i(`option`,{value:L,children:e(`logging.levels.noComponent`,`None`)}),S.map(e=>i(`option`,{value:e.name,children:e.name},e.name))]})]})]}),children:f.isLoading||v===void 0?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(p,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}):t(`div`,{className:`space-y-3`,children:[i(B,{level:v.effective.level,source:v.effective.levelSource,persisted:v.persisted}),i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:v.explicit.layers.map(e=>i(V,{layer:e,inForce:e.scope===v.effective.levelSource,busy:x,onSet:t=>C(e,t),onClear:()=>C(e,null)},`${e.scope}:${e.nodeId??e.component??`cluster`}`))}),s!==L&&i(`p`,{className:`text-[11px] text-foreground-subtle`,children:S.find(e=>e.name===s)?.description??``}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`logging.levels.componentNote`,`A component is a log channel an addon declared. Its level is cluster-wide and beats both the node and the cluster layer.`)}),i(z,{days:v.opsLogRetentionDays,busy:x,onSet:e=>g.mutate({patch:{opsLogRetentionDays:e}},{onSuccess:()=>void f.refetch()})})]})})}function z({days:e,busy:n,onSet:r}){let{t:a}=y();return t(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-1`,children:[t(`label`,{className:`flex items-center justify-between gap-3`,children:[i(`span`,{className:`text-xs font-medium`,children:a(`logging.levels.opsLogRetention`,`Retention audit trail`)}),t(`span`,{className:`flex items-center gap-1.5`,children:[i(`input`,{type:`number`,min:0,max:3650,step:1,defaultValue:e,disabled:n,onBlur:t=>{let n=Number.parseInt(t.target.value,10);Number.isFinite(n)&&n!==e&&r(n)},className:`w-20 rounded border border-border bg-surface px-2 py-1 text-xs`}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:a(`common.days`,`days`)})]})]}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`logging.levels.opsLogRetentionNote`,`How long the record of what retention deleted is kept. Cluster-wide, and deliberately longer than any camera window — it is the history of the sweep, not of the camera, and it is what makes a storage leak explainable after the fact. 0 keeps it forever.`)})]})}function B({level:e,source:n,persisted:r}){let{t:a}=y();return t(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-xs text-foreground-subtle`,children:a(`logging.levels.effective`,`In force here`)}),i(`span`,{className:`rounded bg-primary/10 px-2 py-0.5 text-xs font-semibold text-primary`,children:e}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:n==="default"?a(`logging.levels.fromDefault`,`nothing is set anywhere — this is the default`):a(`logging.levels.fromLayer`,`decided by the {{source}} layer`,{source:n})})]}),!r&&i(`p`,{className:`mt-1 text-[11px] text-warning`,children:a(`logging.levels.notPersisted`,`The settings store could not be read or written — what you see is live, but it would not survive a restart.`)})]})}function V({layer:e,inForce:n,busy:r,onSet:a,onClear:o}){let{t:s}=y();return t(`div`,{className:`flex flex-col gap-2 p-3 sm:flex-row sm:items-center sm:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.scope===`cluster`?s(`logging.levels.cluster`,`Cluster`):e.scope===`component`?e.component??``:e.nodeId??``}),n&&t(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[i(u,{className:`h-3 w-3`}),s(`logging.levels.inForce`,`in force`)]})]}),i(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:e.level===null?s(`logging.levels.inherits`,`inherits — nothing set at this layer`):s(`logging.levels.setHere`,`set here: {{level}}`,{level:e.level})})]}),t(`div`,{className:`flex shrink-0 items-center gap-1`,children:[F.map(t=>i(`button`,{type:`button`,disabled:r,onClick:()=>a(t),className:`rounded px-2 py-1 text-[11px] font-medium transition-colors disabled:opacity-50 ${e.level===t?`bg-primary text-primary-foreground`:`border border-border text-foreground-subtle hover:text-foreground`}`,children:t},t)),i(`button`,{type:`button`,disabled:r||e.level===null,onClick:o,className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-40`,children:s(`logging.levels.clear`,`Clear`)})]})]})}function H(){return i(b,{children:i(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:i(g,{limit:500,maxHeight:`max-h-[calc(100vh-310px)]`,showScope:!0,showFilters:!0})})})}function U(){return i(`div`,{className:`flex flex-col p-4`,children:i(x,{tabs:[{id:`viewer`,label:`Viewer`,icon:v,content:i(H,{})},{id:`destinations`,label:`Destinations`,icon:s,content:i(O,{})},{id:`levels`,label:`Levels`,icon:_,content:i(R,{})},{id:`diagnostics`,label:`Diagnostics`,icon:f,content:i(j,{})}]})})}export{U as LogsPage};
|