@camstack/addon-admin-ui 1.2.101 → 1.2.103

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/dist/assets/{AddLocationWizard-BaRS1vSp.js → AddLocationWizard-DaP6_A46.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-ZXOrokti.js → AddonCollectionPage-nyWYiJDc.js} +1 -1
  3. package/dist/assets/{Addons-Dye82TRM.js → Addons-CWWOTg0U.js} +1 -1
  4. package/dist/assets/{AdminTabs-Bj4P1GYJ.js → AdminTabs-Czxta2mh.js} +1 -1
  5. package/dist/assets/{AiProfiles-DOozhwy_.js → AiProfiles-C0pMBH8I.js} +1 -1
  6. package/dist/assets/{BrokerForm-C0-7inyn.js → BrokerForm-BxTezkNC.js} +1 -1
  7. package/dist/assets/{Build-BYQSYy7F.js → Build-BtEumGI6.js} +1 -1
  8. package/dist/assets/{Capabilities-BNdrW5yr.js → Capabilities-Br7NRp9v.js} +1 -1
  9. package/dist/assets/{CapabilityBadges-C1bMk_7C.js → CapabilityBadges-D0JFygyN.js} +1 -1
  10. package/dist/assets/{Cluster-B8SGnNL3.js → Cluster-CNkXokiW.js} +1 -1
  11. package/dist/assets/Data-Cpi8zlqS.js +1 -0
  12. package/dist/assets/{DetectionIntelligence-B5gdz0kC.js → DetectionIntelligence-D5457LWO.js} +1 -1
  13. package/dist/assets/{DeviceAggregateSection-CNVtSKGy.js → DeviceAggregateSection-CRGubEqf.js} +1 -1
  14. package/dist/assets/{DeviceDetail-fqRbXQOC.js → DeviceDetail-LFXiIuPr.js} +2 -2
  15. package/dist/assets/Devices-Bpwz1iYB.js +1 -0
  16. package/dist/assets/{EmbedPlayerPage-XGlgPJrB.js → EmbedPlayerPage-DGsEdaTJ.js} +1 -1
  17. package/dist/assets/Events-D6kMH49l.js +1 -0
  18. package/dist/assets/{FormBuilder-Bz6uPkMn.js → FormBuilder-ClH7B8PL.js} +1 -1
  19. package/dist/assets/Identity-ESyEdFYd.js +1 -0
  20. package/dist/assets/{IntegrationDetail-CDW7Eu_V.js → IntegrationDetail-BNWu0UHs.js} +1 -1
  21. package/dist/assets/{Integrations-BZJHGp5D.js → Integrations-C3RNkXgq.js} +1 -1
  22. package/dist/assets/{Integrations-_MxWMXKm.js → Integrations-DPNPWp1y.js} +1 -1
  23. package/dist/assets/Logs-Ds0WAXGY.js +1 -0
  24. package/dist/assets/{MotionZonesSettings-rdWjLFCA.js → MotionZonesSettings-B8AShyPC.js} +1 -1
  25. package/dist/assets/{MyAccess-De5E70Mx.js → MyAccess-CE0FuC4H.js} +1 -1
  26. package/dist/assets/{Network-3zKD5uww.js → Network-CC6Uh7my.js} +1 -1
  27. package/dist/assets/{NodeAddonsSettingsPanel-DPLZFO38.js → NodeAddonsSettingsPanel-Bg3Rx-rO.js} +1 -1
  28. package/dist/assets/NodeInferenceDevices-VZSQudL0.js +1 -0
  29. package/dist/assets/{Notifications-DRoRG3NR.js → Notifications-B_Iy7T49.js} +1 -1
  30. package/dist/assets/Pipeline-DUSuuX9E.js +1 -0
  31. package/dist/assets/{Plates-B2O3-4Uk.js → Plates-PiYyE435.js} +1 -1
  32. package/dist/assets/{PrivacyMaskSettings-Bpe_P906.js → PrivacyMaskSettings-Mkjx3Wsl.js} +1 -1
  33. package/dist/assets/{ProviderIcon-B3ZMGpmV.js → ProviderIcon--75xJaei.js} +1 -1
  34. package/dist/assets/Recordings-hKFEsNib.js +1 -0
  35. package/dist/assets/{ScanNetworkModal-C3KwS4Kk.js → ScanNetworkModal-BIf9KytP.js} +1 -1
  36. package/dist/assets/{SceneMonitorEditor-8n1BKUpz.js → SceneMonitorEditor-CjJXkyxy.js} +1 -1
  37. package/dist/assets/Scenes-CcpgVJtX.js +1 -0
  38. package/dist/assets/{Settings-rlvwMnze.js → Settings-DMs9Jd9K.js} +1 -1
  39. package/dist/assets/{Showroom-m8bxoJza.js → Showroom-B9VM3EL0.js} +1 -1
  40. package/dist/assets/{Terminal-BckLeEA9.js → Terminal-CF5uQHom.js} +3 -3
  41. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Drdd-pqm.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DK9B4R7J.js} +1 -1
  42. package/dist/assets/{bell-ring-CZRwj8zz.js → bell-ring-BVWtC7kI.js} +1 -1
  43. package/dist/assets/{boxes-BVJ0-dJL.js → boxes-Qmd6WnZ8.js} +1 -1
  44. package/dist/assets/{build-cluster-graph-DRLmLTvu.js → build-cluster-graph-Bahs_9Ho.js} +1 -1
  45. package/dist/assets/circle-check-big-hqSxF3X3.js +1 -0
  46. package/dist/assets/{circle-x-DmnziSMX.js → circle-x-C150uNWh.js} +1 -1
  47. package/dist/assets/clock-IndoSe_I.js +1 -0
  48. package/dist/assets/{copy-B89T25pr.js → copy-CVW_9pP2.js} +1 -1
  49. package/dist/assets/{debounced-invalidate-kEK1Gvwa.js → debounced-invalidate-C0yrXEMj.js} +1 -1
  50. package/dist/assets/{dist-LO0m0T5x.js → dist-CLok0S8J.js} +1 -1
  51. package/dist/assets/dist-EvnUhZFU.js +349 -0
  52. package/dist/assets/{download-BtY8Mzkb.js → download-DwUIiHtP.js} +1 -1
  53. package/dist/assets/{face-bbox-BZdruwK2.js → face-bbox-CCMxuWbS.js} +1 -1
  54. package/dist/assets/{hostInit-CTUWo00T.js → hostInit-Byx0xNZ7.js} +1 -1
  55. package/dist/assets/index-BlRpxCYM.css +2 -0
  56. package/dist/assets/index-C4ZumSL3.js +4 -0
  57. package/dist/assets/{key-round-CHpqcY9g.js → key-round-lB56F1Ys.js} +1 -1
  58. package/dist/assets/layers-CfdK3HVz.js +1 -0
  59. package/dist/assets/{mf-entry-bootstrap-0-e4f61b9c.js → mf-entry-bootstrap-0-aef68a91.js} +2 -2
  60. package/dist/assets/{pencil-WK7qCbrF.js → pencil-H6Yq51LI.js} +1 -1
  61. package/dist/assets/play-CrKYmytT.js +1 -0
  62. package/dist/assets/{player-overlays-B308H6FT.js → player-overlays-CCLUhzOH.js} +1 -1
  63. package/dist/assets/plus-BzDdzkqf.js +1 -0
  64. package/dist/assets/power-KFh7AhbJ.js +1 -0
  65. package/dist/assets/{radio-DwIVHryI.js → radio-D6LU--aB.js} +1 -1
  66. package/dist/assets/{refresh-cw-ZkEXcNt0.js → refresh-cw-BIuNSTm2.js} +1 -1
  67. package/dist/assets/remoteEntry-B8tBMyi_.js +1 -0
  68. package/dist/assets/rotate-ccw-zJuAaRRf.js +1 -0
  69. package/dist/assets/rotate-cw-CxErjJTg.js +1 -0
  70. package/dist/assets/{send-C4Hp2_AW.js → send-BUWXQB_L.js} +1 -1
  71. package/dist/assets/{server-jri2rxti.js → server-DYvYwfzj.js} +1 -1
  72. package/dist/assets/{shield-qKpb8V3c.js → shield-CBa-_zS9.js} +1 -1
  73. package/dist/assets/{square-check-big-CQJv5PGp.js → square-check-big-CoiR0MrH.js} +1 -1
  74. package/dist/assets/square-z88Fbhnc.js +1 -0
  75. package/dist/assets/{src-CRRfIT-p.js → src-Bnzp_4un.js} +17 -17
  76. package/dist/assets/src-CCyejt1U.js +349 -0
  77. package/dist/assets/{star-Dmj270Gi.js → star-DtLD0XCB.js} +1 -1
  78. package/dist/assets/{undo-2-CL7xnyv-.js → undo-2-BqRjog65.js} +1 -1
  79. package/dist/assets/{upload-DGmWKI7v.js → upload-BPwkcjcA.js} +1 -1
  80. package/dist/assets/{use-scenes-feed-DVrl7-Dv.js → use-scenes-feed-B3mLEcqD.js} +1 -1
  81. package/dist/assets/useEventInvalidation-DyLB_hSC.js +1 -0
  82. package/dist/assets/{video-DtcLus75.js → video-CGa96NMP.js} +1 -1
  83. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DqWJTfxv.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-C4zTZRyK.js} +2 -2
  84. package/dist/assets/{wifi-BrXEnGuA.js → wifi-BppHK6Ke.js} +1 -1
  85. package/dist/assets/{zap-LIk0nazc.js → zap-Bj48PE7R.js} +1 -1
  86. package/dist/index.html +6 -6
  87. package/dist/server/addon.js +573 -62
  88. package/package.json +1 -1
  89. package/dist/assets/Data-yTLKGui0.js +0 -1
  90. package/dist/assets/Devices-C4bHXSBW.js +0 -1
  91. package/dist/assets/Events-BM2eUsM0.js +0 -1
  92. package/dist/assets/Identity-pji2asLl.js +0 -1
  93. package/dist/assets/Logs-BgAQkk9B.js +0 -1
  94. package/dist/assets/NodeInferenceDevices-9ldJLPqw.js +0 -1
  95. package/dist/assets/Pipeline-Be00UqWq.js +0 -1
  96. package/dist/assets/Recordings-BXnzReYl.js +0 -1
  97. package/dist/assets/Scenes-Di16PVHl.js +0 -1
  98. package/dist/assets/circle-check-big-wJc69kBE.js +0 -1
  99. package/dist/assets/clock-CBE2-l0s.js +0 -1
  100. package/dist/assets/dist-BMaxdNnd.js +0 -349
  101. package/dist/assets/index-BJ67e-An.js +0 -4
  102. package/dist/assets/index-r1TtJ95R.css +0 -2
  103. package/dist/assets/play-BENacAEi.js +0 -1
  104. package/dist/assets/plus-BA0vJ9nq.js +0 -1
  105. package/dist/assets/power-CaTDknuZ.js +0 -1
  106. package/dist/assets/remoteEntry-DLHq_qsa.js +0 -1
  107. package/dist/assets/rotate-ccw-CCdRDDlj.js +0 -1
  108. package/dist/assets/rotate-cw-CpmhjVGV.js +0 -1
  109. package/dist/assets/square-BPeDflLw.js +0 -1
  110. package/dist/assets/src-CAbNcnj2.js +0 -349
  111. package/dist/assets/useEventInvalidation-BBS5Ap1s.js +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/addon-admin-ui",
3
- "version": "1.2.101",
3
+ "version": "1.2.103",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Admin UI — Vite frontend build and server-side addon",
@@ -1 +0,0 @@
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{$n as l,Dn as u,Ho as d,Nn as f,On as p,Qn as m,Uo as h,Vo as g,Xn as _,Yn as v,Yo as y,Zn as b,er as x,ir as S,nr as C,rr as w,tr as T,un as E}from"./src-CRRfIT-p.js";import{t as D}from"./download-BtY8Mzkb.js";import{a as O,i as k,n as A,r as j,t as M}from"./AddLocationWizard-BaRS1vSp.js";import{t as N}from"./pencil-WK7qCbrF.js";import{t as P}from"./play-BENacAEi.js";import{t as F}from"./plus-BA0vJ9nq.js";import{t as I}from"./rotate-cw-CpmhjVGV.js";import{G as ee,L as te,h as L,i as R,q as z,s as B,w as V,z as ne}from"./index-BJ67e-An.js";import{t as H}from"./AdminPage-CCD07UMs.js";import{r as re}from"./authed-media-BPd_L9jr.js";import{t as ie}from"./AdminTabs-Bj4P1GYJ.js";import{t as U}from"./format-size-DIxKXxtj.js";import{t as ae}from"./AddonCollectionPage-ZXOrokti.js";import{t as W}from"./addon-display-names-DvSEQty-.js";var G=z(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),K=z(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),q=z(`calendar-clock`,[[`path`,{d:`M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5`,key:`1osxxc`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`path`,{d:`M3 10h5`,key:`r794hk`}],[`path`,{d:`M17.5 17.5 16 16.3V14`,key:`akvzfd`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]),J=z(`file-text`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]);t();function oe(){let e=a(),t=E(),{data:i,isLoading:c,isError:l}=h({}),u=d(),f=r(()=>u.data??[],[u.data]),[p,m]=o(null),[_,v]=o(null),b=g({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),x=y({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),S=e=>{e.isDefault||x.mutate(k(e,{isDefault:!0}))},C=(e,t)=>{x.mutate(k(e,{enabled:t}))},w=async e=>{if(e.isDefault){await t({title:`Cannot delete default location`,message:`"${e.displayName}" is the default for type "${e.type}". Mark another location as default first, then delete this one.`,confirmLabel:`OK`,variant:`warning`});return}await t({title:`Delete location "${e.displayName}"?`,message:`This removes the location record. Files on disk are not deleted; the underlying directory or remote path stays untouched.`,confirmLabel:`Delete`,variant:`danger`})&&b.mutate({id:e.id})},T=r(()=>{let e=new Map;for(let t of i??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[i]),D=c||u.isLoading,O=l||u.isError;return n(H,{children:[D&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),O&&s(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!D&&!O&&n(`div`,{className:`space-y-3`,children:[f.length===0&&s(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:`No storage locations declared by any installed addon.`}),f.map(e=>s(j,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:T.get(e.id)??[],onAdd:e=>m(e),onEdit:e=>v(e),onDelete:e=>{w(e)},onSetDefault:e=>S(e),onToggleEnabled:(e,t)=>C(e,t)},e.id))]}),p!==null&&s(M,{initialType:p,onClose:()=>m(null),onCreated:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),m(null)}}),_!==null&&s(A,{location:_,onClose:()=>v(null),onSaved:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),v(null)}})]})}t();var se=[[`backup`,`listDestinations`]],ce=[`backup`,`listArchives`];function le({destinationId:t,restoreSupported:i,onOpenRestoreWizard:c}){let l=a(),u=E(),{data:d,isLoading:f,isError:p}=m({destinationId:t}),h=d??[],g=v({onSuccess:()=>{l.invalidateQueries({queryKey:[[...ce]]}),l.invalidateQueries({queryKey:se})}}),_=e(async e=>{await u({title:`Delete this archive?`,message:`Permanently deletes "${e.label??e.id}" and frees ${U(e.sizeBytes)}.`,confirmLabel:`Delete`,variant:`danger`})&&g.mutate({destinationId:t,backupId:e.id})},[u,t,g]),[y,b]=o(null),x=e(async e=>{b(e.id);try{let n=await re(ue(t,e.id)),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.label??e.id}.tar.gz`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}finally{b(null)}},[t]),S=r(()=>[...h].toSorted((e,t)=>t.createdAt-e.createdAt),[h]);return f?s(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):p?s(`div`,{className:`text-xs text-danger py-2`,children:`Failed to read manifest for this destination`}):S.length===0?s(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:`No archives at this destination yet.`}):s(`div`,{className:`rounded border border-border bg-surface overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[640px]`,children:[s(`thead`,{children:n(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`When`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Label`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Includes`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium`,children:`Size`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium w-52`,children:`Actions`})]})}),s(`tbody`,{children:S.map(e=>n(`tr`,{className:`border-t border-border hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-1.5 text-foreground tabular-nums`,children:de(e.createdAt)}),s(`td`,{className:`px-3 py-1.5 text-foreground`,children:e.label??s(`span`,{className:`text-foreground-subtle italic`,children:`—`})}),s(`td`,{className:`px-3 py-1.5 text-foreground-subtle`,children:e.locations.join(`, `)}),s(`td`,{className:`px-3 py-1.5 text-foreground text-right tabular-nums`,children:U(e.sizeBytes)}),s(`td`,{className:`px-3 py-1.5`,children:n(`div`,{className:`flex items-center justify-end gap-1`,children:[n(`button`,{onClick:()=>{x(e)},disabled:y===e.id,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:text-foreground hover:bg-primary/10 disabled:opacity-50`,title:`Download archive`,children:[y===e.id?s(V,{className:`h-3 w-3 animate-spin`}):s(D,{className:`h-3 w-3`}),`Download`]}),i&&c&&n(`button`,{onClick:()=>c({destinationId:t,archiveId:e.id}),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-primary hover:bg-primary/10`,title:`Restore from this archive`,children:[s(I,{className:`h-3 w-3`}),`Restore`]}),s(`button`,{onClick:()=>{_(e)},disabled:g.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete archive`,children:g.isPending?s(V,{className:`h-3 w-3 animate-spin`}):s(B,{className:`h-3 w-3`})})]})})]},e.id))})]})})}function ue(e,t){return`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}function de(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}t();var Y=[[`backup`,`listSchedules`]];function fe({onEdit:e,onOpenRestoreWizard:t}){let{data:i,isLoading:a,isError:c}=x(),u=i??[],d=l().data??[],f=r(()=>{let e=new Map;for(let t of d)e.set(t.id,t);return e},[d]),[p,m]=o(null),h=e=>{m(t=>t===e?null:e)};return a?s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading backup entries…`}):c?s(`div`,{className:`text-xs text-danger`,children:`Failed to load backup entries`}):u.length===0?s(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-8 text-center`,children:s(`p`,{className:`text-xs text-foreground-subtle`,children:`No backup entries yet. Create one to schedule backups across one or more storage locations.`})}):s(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[820px]`,children:[s(`thead`,{children:n(`tr`,{className:`text-foreground-subtle border-b border-border bg-background/40`,children:[s(`th`,{className:`text-left px-3 py-2 font-medium w-6`}),s(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Entry`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-20`,children:`Enabled`}),s(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Locations`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-24`,children:`Retention`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-48`,children:`Schedule`}),s(`th`,{className:`text-right px-3 py-2 font-medium w-52`,children:`Actions`})]})}),s(`tbody`,{children:u.map(n=>s(pe,{row:n,destById:f,isOpen:p===n.id,onToggle:()=>h(n.id),onEdit:()=>e(n),...t?{onOpenRestoreWizard:t}:{}},n.id))})]})})}function pe({row:t,destById:l,isOpen:u,onToggle:d,onEdit:f,onOpenRestoreWizard:p}){let m=a(),h=E(),g=S({onSuccess:()=>{m.invalidateQueries({queryKey:Y})}}),v=_({onSuccess:()=>{m.invalidateQueries({queryKey:Y})}}),y=w({onSuccess:()=>{m.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),m.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]})}}),[b,x]=o(String(t.retentionCount));c(()=>{x(String(t.retentionCount))},[t.retentionCount]);let C=r(()=>({id:t.id,label:t.label,cron:t.cron,locationIds:[...t.locationIds],retentionCount:t.retentionCount,...t.dataSources?{dataSources:[...t.dataSources]}:{}}),[t]),T=e(e=>{g.mutate({...C,enabled:e})},[g,C]),D=e(()=>{let e=Number.parseInt(b,10);if(Number.isNaN(e)||e<1){x(String(t.retentionCount));return}e!==t.retentionCount&&g.mutate({...C,enabled:t.enabled,retentionCount:e})},[g,C,b,t.retentionCount,t.enabled]),O=e(()=>{t.locationIds.length!==0&&y.mutate({destinations:[...t.locationIds],...t.dataSources&&t.dataSources.length>0?{locations:[...t.dataSources]}:{},label:t.label,retentionCount:t.retentionCount})},[y,t]),k=e(async()=>{await h({title:`Delete backup entry?`,message:`"${t.label||t.id}" will stop running. Existing archives are kept.`,confirmLabel:`Delete`,variant:`warning`})&&v.mutate({id:t.id})},[h,v,t.id,t.label]),A=t.cron.trim().length>0,j=g.isPending||v.isPending;return n(i,{children:[n(`tr`,{className:`border-t border-border first:border-t-0 hover:bg-primary/5`,children:[s(`td`,{className:`px-2 py-2`,children:s(`button`,{onClick:d,className:`inline-flex items-center justify-center rounded p-1 text-foreground-subtle hover:bg-primary/10 hover:text-foreground`,title:u?`Hide archives`:`Show archives`,children:s(u?ne:te,{className:`h-3.5 w-3.5`})})}),s(`td`,{className:`px-3 py-2`,children:n(`button`,{onClick:f,className:`text-left hover:underline focus:outline-none`,children:[s(`div`,{className:`text-foreground font-medium`,children:t.label||`(unnamed)`}),t.lastRunAt!==void 0&&n(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:[`last run `,new Date(t.lastRunAt).toLocaleString()]})]})}),s(`td`,{className:`px-3 py-2`,children:s(`label`,{className:`inline-flex items-center cursor-pointer`,children:s(`input`,{type:`checkbox`,className:`accent-primary`,checked:t.enabled,disabled:j,onChange:e=>T(e.target.checked)})})}),s(`td`,{className:`px-3 py-2`,children:n(`div`,{className:`flex flex-wrap gap-1`,children:[t.locationIds.length===0&&s(`span`,{className:`text-[11px] text-danger italic`,children:`No locations`}),t.locationIds.map(e=>s(`span`,{className:`inline-flex items-center rounded border border-border bg-background px-1.5 py-0.5 text-[10px] text-foreground`,title:e,children:l.get(e)?.displayName??e},e))]})}),s(`td`,{className:`px-3 py-2`,children:s(`input`,{type:`number`,min:1,max:1e3,value:b,disabled:j,onChange:e=>x(e.target.value),onBlur:D,onKeyDown:e=>{e.key===`Enter`&&e.target.blur(),e.key===`Escape`&&x(String(t.retentionCount))},className:`w-16 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})}),s(`td`,{className:`px-3 py-2`,children:n(`button`,{onClick:f,className:`group flex flex-col items-start gap-0.5 text-left`,title:`Edit schedule`,children:[n(`span`,{className:`inline-flex items-center gap-1`,children:[s(q,{className:`h-3 w-3 text-foreground-subtle group-hover:text-foreground`}),s(`span`,{className:`font-mono text-[11px] text-foreground`,children:A?t.cron:`Manual`})]}),A&&t.nextRunAt!==void 0&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`next `,new Date(t.nextRunAt).toLocaleString()]})]})}),s(`td`,{className:`px-3 py-2`,children:n(`div`,{className:`flex items-center justify-end gap-1.5`,children:[n(`button`,{onClick:O,disabled:y.isPending||t.locationIds.length===0,className:`inline-flex items-center gap-1 rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,title:`Run this entry now`,children:[y.isPending?s(V,{className:`h-3 w-3 animate-spin`}):s(P,{className:`h-3 w-3`}),`Run now`]}),s(`button`,{onClick:f,className:`inline-flex items-center justify-center rounded border border-border p-1 text-foreground-subtle hover:text-foreground hover:bg-primary/5`,title:`Edit entry`,children:s(N,{className:`h-3 w-3`})}),s(`button`,{onClick:()=>{k()},disabled:j,className:`inline-flex items-center justify-center rounded border border-border p-1 text-foreground-subtle hover:text-danger hover:border-danger/40 disabled:opacity-50`,title:`Delete entry`,children:s(B,{className:`h-3 w-3`})})]})})]}),u&&s(`tr`,{className:`border-t border-border bg-background/30`,children:n(`td`,{colSpan:7,className:`px-4 py-3 space-y-4`,children:[t.locationIds.length===0&&s(`p`,{className:`text-xs text-foreground-subtle italic`,children:`This entry has no locations selected.`}),t.locationIds.map(e=>n(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[11px] font-medium text-foreground-subtle`,children:l.get(e)?.displayName??e}),s(le,{destinationId:e,restoreSupported:l.get(e)?.restoreSupported??!0,...p?{onOpenRestoreWizard:p}:{}})]},e))]})})]})}t();var X=[{id:`manual`,label:`Manual only`,cron:``},{id:`hourly`,label:`Every hour`,cron:`0 * * * *`,description:`On the hour`},{id:`every-3h`,label:`Every 3 hours`,cron:`0 */3 * * *`,description:`00:00, 03:00, 06:00, 09:00 …`},{id:`every-6h`,label:`Every 6 hours`,cron:`0 */6 * * *`,description:`00:00, 06:00, 12:00, 18:00`},{id:`daily-3am`,label:`Daily at 03:00`,cron:`0 3 * * *`,description:`Every night at 3 AM`},{id:`weekly-sun`,label:`Weekly Sunday 03:00`,cron:`0 3 * * 0`,description:`Sunday morning at 3 AM`}];function me(e){let t=e.trim();for(let e of X)if(e.cron===t)return e.id;return`custom`}function he({value:e,onChange:t,previewCount:r=5,disabled:i=!1}){let a=me(e),[l,u]=o(a===`custom`);c(()=>{a!==`custom`&&u(!1)},[a]);let d=ve(e,250),f=T({cron:d,count:r},{enabled:d.trim().length>0}),p=f.data??null,m=e=>{u(!1),t(e.cron)},h=l||a===`custom`;return n(`div`,{className:`space-y-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Schedule preset`}),n(`div`,{className:`flex flex-wrap gap-1.5`,children:[X.map(e=>s(`button`,{type:`button`,onClick:()=>m(e),disabled:i,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!l&&a===e.id?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),title:e.description??e.label,children:e.label},e.id)),s(`button`,{type:`button`,onClick:()=>{u(!0),e.trim().length===0&&t(`0 3 * * *`)},disabled:i,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(h?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:`Custom…`})]})]}),h&&n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Cron expression (5-field POSIX)`}),s(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),disabled:i,placeholder:`0 3 * * *`,spellCheck:!1,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs font-mono text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`}),n(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,s(`span`,{className:`font-mono`,children:`minute hour day-of-month month day-of-week`}),` · all times server-local`]})]}),s(ge,{cron:d,preview:p,loading:f.isFetching})]})}function ge({cron:e,preview:t,loading:r}){return r&&t===null?n(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[s(V,{className:`h-3 w-3 animate-spin`}),`Validating…`]}):t===null?null:t.ok?t.nextRuns.length===0?s(`div`,{className:`rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:`No future runs match this expression.`}):n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Next runs`}),s(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>n(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[s(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),s(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:_e(e)})]},`${e}-${t}`))})]}):s(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:t.error??`Invalid cron expression`})}function _e(e){let t=e-Date.now();if(t<=0)return`now`;let n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;let r=Math.floor(n/60);if(r<60)return`in ${r}m`;let i=Math.floor(r/60);return i<24?`in ${i}h`:`in ${Math.floor(i/24)}d`}function ve(e,t){let[n,i]=o(e),a=r(()=>e,[e]);return c(()=>{let e=setTimeout(()=>i(a),t);return()=>clearTimeout(e)},[a,t]),n}t();var ye=[[`backup`,`listSchedules`]];function be({entry:e,onClose:t,onSaved:i}){let c=a(),u=l(),d=u.data??[],[f,p]=o(e?.label??``),[m,h]=o(e?.cron??`0 3 * * *`),[g,_]=o(e?.enabled??!0),[v,y]=o(String(e?.retentionCount??7)),[b,x]=o(new Set(e?.locationIds??[])),C=S({onSuccess:()=>{c.invalidateQueries({queryKey:ye}),i()}}),w=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},T=Number.parseInt(v,10),E=r(()=>f.trim().length>0&&b.size>0&&!Number.isNaN(T)&&T>=1&&T<=1e3,[f,b,T]),D=()=>{E&&C.mutate({...e?{id:e.id}:{},label:f.trim(),cron:m.trim(),enabled:g,locationIds:Array.from(b),retentionCount:T})},O=C.error instanceof Error?C.error.message:null;return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:n(`div`,{className:`w-full max-w-lg rounded-xl border border-border bg-surface shadow-2xl max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[n(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3 sticky top-0 bg-surface`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e?`Edit backup entry`:`New backup entry`}),s(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:s(R,{className:`h-4 w-4`})})]}),n(`div`,{className:`p-4 space-y-4`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Name`}),s(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:`Nightly offsite`,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`})]}),n(`div`,{className:`space-y-1.5`,children:[n(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:[`Locations (`,b.size,` selected)`]}),u.isLoading&&n(`div`,{className:`flex items-center gap-2 px-1 py-2 text-xs text-foreground-subtle`,children:[s(V,{className:`h-3.5 w-3.5 animate-spin`}),`Loading locations…`]}),!u.isLoading&&d.length===0&&s(`div`,{className:`rounded border border-border bg-background px-3 py-2 text-xs text-foreground-subtle italic`,children:"No `backups` storage locations configured. Add one in Settings → Storage first."}),d.length>0&&s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-52 overflow-y-auto`,children:d.map(e=>n(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`checkbox`,checked:b.has(e.id),onChange:()=>w(e.id),className:`accent-primary`}),s(`span`,{className:`text-foreground`,children:e.displayName})]}),n(`div`,{className:`flex items-center gap-1.5`,children:[s(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-surface border border-border rounded px-1.5 py-0.5`,children:e.kind}),s(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.id})]})]},e.id))})]}),n(`div`,{className:`grid grid-cols-2 gap-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Retention (archives kept)`}),s(`input`,{type:`number`,min:1,max:1e3,value:v,onChange:e=>y(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`})]}),n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Enabled`}),n(`label`,{className:`inline-flex items-center gap-2 py-1.5 cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked),className:`accent-primary`}),s(`span`,{className:`text-xs text-foreground-subtle`,children:`Run on schedule`})]})]})]}),n(`div`,{className:`space-y-1.5 border-t border-border pt-3`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Schedule`}),s(he,{value:m,onChange:h,disabled:C.isPending})]}),O&&s(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:O})]}),n(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3 sticky bottom-0 bg-surface`,children:[s(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),n(`button`,{onClick:D,disabled:!E||C.isPending,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:[C.isPending&&s(V,{className:`h-3.5 w-3.5 animate-spin`}),e?`Save`:`Create entry`]})]})]})})}t();var xe=[[`backup`,`list`]];function Se({initialDestinationId:e,initialArchiveId:t,onClose:i,onScheduled:u}){let d=a(),[f,p]=o(e&&t?2:1),[h,g]=o(e),[_,v]=o(t),[y,x]=o(new Set),{data:S}=l(),w=S??[],{data:T,isLoading:E}=m({destinationId:h??``},{enabled:!!h}),D=T??[];c(()=>{if(h!==void 0)return;let e=w.filter(e=>e.restoreSupported);e.length===1&&g(e[0].id)},[h,w]);let{data:O}=b({destinationId:h??``,backupId:_??``},{enabled:!!h&&!!_}),k=r(()=>O?.locations??[],[O]);c(()=>{k.length!==0&&x(e=>e.size===0?new Set(k):e)},[k]);let A=C({onSuccess:()=>{d.invalidateQueries({queryKey:xe}),u(),i()}}),j=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},M=!!h&&!!_,N=y.size>0,P=M&&N&&!A.isPending,F=()=>{!h||!_||A.mutate({destinationId:h,backupId:_,locations:[...y]})};return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:i,children:n(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[n(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[n(`div`,{className:`space-y-0.5`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Restore Backup`}),n(`p`,{className:`text-xs text-foreground-subtle`,children:[`Step `,f,` of 3 —`,` `,f===1?`pick source`:f===2?`pick locations`:`confirm`]})]}),s(`button`,{onClick:i,className:`text-foreground-subtle hover:text-foreground`,children:s(R,{className:`h-4 w-4`})})]}),f===1&&s(Z,{destinations:w,destinationId:h,onPickDestination:e=>{g(e),v(void 0),x(new Set)},archives:D,archivesLoading:E,archiveId:_,onPickArchive:v}),f===2&&s(Ce,{locations:k,picked:y,onToggle:j}),f===3&&s(we,{destinationName:w.find(e=>e.id===h)?.displayName??h??``,archive:D.find(e=>e.id===_),picked:[...y]}),n(`div`,{className:`flex justify-between gap-2 border-t border-border px-4 py-3`,children:[s(`div`,{children:f>1&&n(`button`,{onClick:()=>p(e=>e===3?2:1),className:`inline-flex items-center gap-1 rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:[s(ee,{className:`h-3 w-3`}),`Back`]})}),n(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:i,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),f<3?n(`button`,{disabled:f===1&&!M||f===2&&!N,onClick:()=>p(e=>e===1?2:3),className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[`Next`,s(K,{className:`h-3 w-3`})]}):n(`button`,{onClick:F,disabled:!P,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:[A.isPending?s(V,{className:`h-3.5 w-3.5 animate-spin`}):s(I,{className:`h-3.5 w-3.5`}),`Schedule Restore`]})]})]})]})})}function Z({destinations:e,destinationId:t,onPickDestination:r,archives:i,archivesLoading:a,archiveId:o,onPickArchive:c}){let l=e.filter(e=>e.restoreSupported);return n(`div`,{className:`p-4 space-y-3`,children:[n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Destination`}),n(`select`,{value:t??``,onChange:e=>r(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:[s(`option`,{value:``,disabled:!0,children:`Select destination…`}),l.map(e=>n(`option`,{value:e.id,children:[e.displayName,` (`,e.kind,`)`]},e.id))]})]}),n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Archive`}),!t&&s(`div`,{className:`text-xs text-foreground-subtle italic`,children:`Pick a destination first.`}),t&&a&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Reading archives…`}),t&&!a&&i.length===0&&s(`div`,{className:`text-xs text-foreground-subtle italic`,children:`No archives available at this destination.`}),t&&i.length>0&&s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:i.map(e=>{let t=o===e.id;return n(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>c(e.id),className:`accent-primary`}),n(`div`,{children:[s(`div`,{className:`font-medium text-foreground`,children:e.label??e.id}),s(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})]})]}),s(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:U(e.sizeBytes)})]},e.id)})})]})]})}function Ce({locations:e,picked:t,onToggle:r}){return e.length===0?s(`div`,{className:`p-4`,children:s(`div`,{className:`text-xs text-foreground-subtle`,children:`Loading archive manifest… If this persists, the archive may predate manifests — restoring will apply everything in the tarball.`})}):n(`div`,{className:`p-4 space-y-3`,children:[s(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:`Selected entries will overwrite live data on the next server restart. Unchecked entries stay current.`}),n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Apply`}),s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>n(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>r(e),className:`accent-primary`}),s(`span`,{className:`font-mono text-foreground`,children:e}),s(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Ee(e)})]},e))})]})]})}function we({destinationName:e,archive:t,picked:r}){return n(`div`,{className:`p-4 space-y-3 text-xs`,children:[s(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-amber-700 dark:text-amber-300`,children:`Restore is applied at next server boot. Active connections will drop when you restart.`}),n(`dl`,{className:`space-y-1.5`,children:[s(Q,{term:`Destination`,value:e}),s(Q,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&s(Q,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${U(t.sizeBytes)}`}),s(Q,{term:`Locations`,value:r.length>0?r.join(`, `):`— (full archive)`})]})]})}function Q({term:e,value:t}){return n(`div`,{className:`flex justify-between gap-3`,children:[s(`dt`,{className:`text-foreground-subtle`,children:e}),s(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var Te={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function Ee(e){return Te[e]??``}t();function De(){let e=E(),t=f(),[r,i]=o(null),[a,c]=o(!1),[l,u]=o(!1),[d,p]=o(void 0),m=async()=>{await e({title:`Restart server now?`,message:`Active connections will drop and the apply-backup hook will run before boot.`,confirmLabel:`Restart`,variant:`warning`})&&t.mutate({confirm:!0})};return n(H,{children:[n(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[n(`button`,{onClick:()=>c(!0),className:`inline-flex items-center gap-1.5 rounded-lg 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:[s(I,{className:`h-3.5 w-3.5`}),`Restore…`]}),n(`button`,{onClick:()=>p(null),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`,children:[s(F,{className:`h-3.5 w-3.5`}),`New entry`]})]}),l&&s(`div`,{className:`rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2.5 text-xs text-amber-700 dark:text-amber-300`,children:n(`div`,{className:`flex items-center justify-between gap-3`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(I,{className:`h-3.5 w-3.5`}),s(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),n(`button`,{onClick:()=>{m()},disabled:t.isPending,className:`inline-flex items-center gap-1.5 rounded bg-amber-500/20 px-2 py-1 font-medium text-amber-800 dark:text-amber-200 hover:bg-amber-500/30 disabled:opacity-50`,children:[t.isPending?s(V,{className:`h-3.5 w-3.5 animate-spin`}):s(I,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),s(fe,{onEdit:e=>p(e),onOpenRestoreWizard:e=>i(e)}),d!==void 0&&s(be,{entry:d,onClose:()=>p(void 0),onSaved:()=>p(void 0)}),(r||a)&&s(Se,{...r?{initialDestinationId:r.destinationId,initialArchiveId:r.archiveId}:{},onClose:()=>{i(null),c(!1)},onScheduled:()=>u(!0)})]})}t();var $=5e3,Oe={"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 ke(){let e=p({capName:`log-destination`},{refetchInterval:$}),t=u(void 0,{refetchInterval:$}),n=r(()=>W(t.data??[]),[t.data]),i=r(()=>{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 s(ae,{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:L,itemIcon:J,capability:`log-destination`,installButtonLabel:`Add destination`,items:r(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive,caption:i.get(e.addonId)??Oe[e.addonId]??``})),[e.data,n,i]),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?s(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.caption}):null})}function Ae(){return s(`div`,{className:`flex flex-col p-4`,children:s(ie,{tabs:[{id:`storage`,label:`Storage`,icon:O,content:s(oe,{})},{id:`backup`,label:`Backup`,icon:G,content:s(De,{})},{id:`logging`,label:`Logging`,icon:L,content:s(ke,{})}]})})}export{Ae as DataPage};
@@ -1 +0,0 @@
1
- import{I as e,Q as t,S as n,W as r,o as i,x as a}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 o}from"./player-overlays-B308H6FT.js";import{Kr as s,Nr as c,Or as l,Vr as u,i as d,w as f,xi as p}from"./src-CRRfIT-p.js";import{t as m}from"./ProviderIcon-B3ZMGpmV.js";import{H as h,Y as g,o as _,t as v}from"./index-BJ67e-An.js";import{t as y}from"./AdminPage-CCD07UMs.js";import"./useEventInvalidation-BBS5Ap1s.js";t();var b=32;function x(e,t){if(t===null)return{activeDevices:e,orphanDevices:[]};let n=e=>typeof e.addonId==`string`&&e.addonId.length>0&&!t.has(e.addonId),r=new Set;for(let t of e)n(t)&&r.add(t.id);let i=new Map;for(let t of e)i.set(t.id,t);let a=(e,t=0)=>{if(t>b)return!1;if(r.has(e.id))return!0;if(e.parentDeviceId==null)return!1;let n=i.get(e.parentDeviceId);return n?a(n,t+1):!1},o=[],s=[];for(let t of e)a(t)?s.push(t):o.push(t);return{activeDevices:o,orphanDevices:s}}function S(){let{t}=v(),b=g(),S=o(),C=i();d([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]),d([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`]);let{data:w}=u({}),{data:T}=p(void 0),E=s({onSuccess:()=>{C.invalidateQueries({queryKey:[[`deviceManager`]]})}}),D=l({onSuccess:()=>{C.invalidateQueries({queryKey:[[`deviceManager`]]})}}),O=c({onSuccess:()=>{C.invalidateQueries({queryKey:[[`deviceManager`]]})}}),k=r(()=>w??[],[w]),{activeDevices:A,orphanDevices:j}=r(()=>x(k,T===void 0?null:new Set(T.map(e=>e.addonId))),[k,T]),M=r(()=>{let e=new Map;for(let t of k)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[k]),N=e(e=>M.get(e)??null,[M]),P=r(()=>(T??[]).map(e=>({id:e.addonId,name:e.name??e.addonId,icon:a(m,{type:e.addonId,size:`sm`})})),[T]),F=e(e=>a(m,{type:e,size:`sm`}),[]),I=e(e=>b(`/devices/${String(e)}`),[b]);return n(y,{icon:h,title:t(`nav.devices`,`Devices`),children:[a(f,{context:`devices`,devices:A,trpc:S.trpcClient,filters:{addons:P},resolveIntegrationIcon:F,resolveParent:N,onNavigate:I,batchActions:{remove:E.mutate,disable:D.mutate,enable:O.mutate}}),j.length>0&&n(`div`,{className:`mt-6 space-y-2`,children:[n(`div`,{className:`flex items-baseline gap-2`,children:[a(_,{className:`h-3.5 w-3.5 text-warning shrink-0`}),a(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Orphan devices`}),n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[j.length,` device`,j.length===1?``:`s`,` pointing at integrations no longer registered`]})]}),n(`div`,{className:`rounded-lg border border-warning/30 bg-warning/5 p-2`,children:[a(`p`,{className:`text-[11px] text-foreground-subtle px-2 pb-2`,children:"These devices reference an addonId that has no matching integration. Delete them, or re-install the missing integration to bring them back online. The provider scope (`addonId`) shown beside each row is what's failing to resolve."}),a(f,{context:`devices`,devices:j,trpc:S.trpcClient,filters:{addons:P},urlScope:`nested`,lsKey:`devices:orphan`,resolveIntegrationIcon:F,resolveParent:N,onNavigate:I})]})]})]})}export{S as DevicesPage};
@@ -1 +0,0 @@
1
- import{I as e,K as t,Q as n,S as r,U as i,W as a,a as o,b as s,i as c,o as l,q as u,x as d,z as f}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 p}from"./player-overlays-B308H6FT.js";import{Da as m,Dt as h,Ea as g,Ft as _,Is as v,It as y,Ji as b,Lt as x,Ms as S,Oa as C,On as w,Pt as T,Rt as E,Sa as D,Ta as O,Tt as k,Vr as ee,Xt as A,ba as j,ca as M,da as N,fa as te,fn as P,ga as F,ha as ne,j as I,ma as L,pn as R,ua as z,va as B,wa as re,xa as V,ya as H}from"./src-CRRfIT-p.js";import{Rt as U,at as ie,mt as ae}from"./src-CAbNcnj2.js";import{t as W}from"./clock-CBE2-l0s.js";import{t as oe}from"./copy-B89T25pr.js";import{t as se}from"./download-BtY8Mzkb.js";import{a as ce,c as G,d as le,f as ue,i as de,m as fe,n as pe,o as me,p as he,r as ge,s as _e,t as ve}from"./debounced-invalidate-kEK1Gvwa.js";import{t as ye}from"./refresh-cw-ZkEXcNt0.js";import{t as be}from"./square-check-big-CQJv5PGp.js";import{t as xe}from"./square-BPeDflLw.js";import{t as Se}from"./star-Dmj270Gi.js";import{t as Ce}from"./undo-2-CL7xnyv-.js";import{B as we,F as Te,K as Ee,L as De,i as Oe,k as ke,l as Ae,m as je,q as K,s as Me,t as Ne,w as q,z as Pe}from"./index-BJ67e-An.js";import{t as Fe}from"./AdminPage-CCD07UMs.js";import{i as Ie,n as Le,t as Re}from"./authed-media-BPd_L9jr.js";import{t as ze}from"./AdminTabs-Bj4P1GYJ.js";var Be=K(`arrow-down-wide-narrow`,[[`path`,{d:`m3 16 4 4 4-4`,key:`1co6wj`}],[`path`,{d:`M7 20V4`,key:`1yoxec`}],[`path`,{d:`M11 4h10`,key:`1w87gc`}],[`path`,{d:`M11 8h7`,key:`djye34`}],[`path`,{d:`M11 12h4`,key:`q8tih4`}]]),Ve=K(`bug`,[[`path`,{d:`m8 2 1.88 1.88`,key:`fmnt4t`}],[`path`,{d:`M14.12 3.88 16 2`,key:`qol33r`}],[`path`,{d:`M9 7.13v-1a3.003 3.003 0 1 1 6 0v1`,key:`d7y7pr`}],[`path`,{d:`M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6`,key:`xs1cw7`}],[`path`,{d:`M12 20v-9`,key:`1qisl0`}],[`path`,{d:`M6.53 9C4.6 8.8 3 7.1 3 5`,key:`32zzws`}],[`path`,{d:`M6 13H2`,key:`82j7cp`}],[`path`,{d:`M3 21c0-2.1 1.7-3.9 3.8-4`,key:`4p0ekp`}],[`path`,{d:`M20.97 5c0 2.1-1.6 3.8-3.5 4`,key:`18gb23`}],[`path`,{d:`M22 13h-4`,key:`1jl80f`}],[`path`,{d:`M17.2 17c2.1.1 3.8 1.9 3.8 4`,key:`k3fwyw`}]]),He=K(`circle-dashed`,[[`path`,{d:`M10.1 2.182a10 10 0 0 1 3.8 0`,key:`5ilxe3`}],[`path`,{d:`M13.9 21.818a10 10 0 0 1-3.8 0`,key:`11zvb9`}],[`path`,{d:`M17.609 3.721a10 10 0 0 1 2.69 2.7`,key:`1iw5b2`}],[`path`,{d:`M2.182 13.9a10 10 0 0 1 0-3.8`,key:`c0bmvh`}],[`path`,{d:`M20.279 17.609a10 10 0 0 1-2.7 2.69`,key:`1ruxm7`}],[`path`,{d:`M21.818 10.1a10 10 0 0 1 0 3.8`,key:`qkgqxc`}],[`path`,{d:`M3.721 6.391a10 10 0 0 1 2.7-2.69`,key:`1mcia2`}],[`path`,{d:`M6.391 20.279a10 10 0 0 1-2.69-2.7`,key:`1fvljs`}]]),Ue=K(`circle`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),We=K(`copy-plus`,[[`line`,{x1:`15`,x2:`15`,y1:`12`,y2:`18`,key:`1p7wdc`}],[`line`,{x1:`12`,x2:`18`,y1:`15`,y2:`15`,key:`1nscbv`}],[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]),Ge=K(`graduation-cap`,[[`path`,{d:`M21.42 10.922a1 1 0 0 0-.019-1.838L12.83 5.18a2 2 0 0 0-1.66 0L2.6 9.08a1 1 0 0 0 0 1.832l8.57 3.908a2 2 0 0 0 1.66 0z`,key:`j76jl0`}],[`path`,{d:`M22 10v6`,key:`1lu8f3`}],[`path`,{d:`M6 12.5V16a6 3 0 0 0 12 0v-3.5`,key:`1r8lef`}]]),Ke=K(`square-parking`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 17V7h4a3 3 0 0 1 0 6H9`,key:`1dfk2c`}]]),qe=K(`tag`,[[`path`,{d:`M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z`,key:`vktsd0`}],[`circle`,{cx:`7.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`kqv944`}]]);n();var Je=`pipeline-analytics`,Ye=`debug.listTracks`,Xe=`debug.analyze`,Ze=`/addon/pipeline-analytics/debug-export`;function Qe(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function $e(e,t){let n=e[t];return typeof n==`string`?n:null}function J(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function et(e,t){let n=e[t];return typeof n==`boolean`?n:null}function tt(e){return e===`error`||e===`warn`||e===`info`}function nt(e){if(!Qe(e))return null;let t=$e(e,`code`),n=$e(e,`detail`),r=e.severity;return t===null||n===null||!tt(r)?null:{code:t,severity:r,detail:n}}function rt(e){if(!Qe(e))return null;let t=$e(e,`trackId`),n=J(e,`deviceId`),r=$e(e,`className`),i=J(e,`firstSeen`),a=J(e,`lastSeen`),o=J(e,`durationMs`),s=et(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=$e(e,`label`);return{trackId:t,deviceId:n,className:r,...c===null?{}:{label:c},firstSeen:i,lastSeen:a,durationMs:o,active:s}}function it(e){let t=rt(e);if(t===null||!Qe(e))return null;let n=J(e,`mediaCount`),r=J(e,`eventCount`),i=J(e,`positionCount`);if(n===null||r===null||i===null)return null;let a=e.mediaKinds,o=e.findings;if(!Array.isArray(a)||!Array.isArray(o))return null;let s=a.filter(e=>typeof e==`string`),c=[];for(let e of o){let t=nt(e);t!==null&&c.push(t)}return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c}}function at(e){if(!Qe(e))return null;let t=et(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=rt(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function ot(e){if(!Qe(e))return null;let t=e.reports,n=e.vanished;if(!Array.isArray(t)||!Array.isArray(n))return null;let r=[];for(let e of t){let t=it(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var st={MEDIA_EVICTED_OR_NEVER:`no media`,MISSING_KEYFRAME:`no keyframe`,MISSING_FIRSTFRAME:`no first frame`,MISSING_LASTFRAME:`no last frame`,MISSING_THUMBNAIL:`no thumbnail`,MISSING_BEST_CROP:`no crop`,SHORT_TRACK:`very short`,ZERO_EVENTS:`no events`,ZERO_POSITIONS:`no trajectory`,NO_PERIODIC_SNAPSHOTS:`no snapshots`,LASTFRAME_STALE:`stale last frame`,MEDIA_STOPPED_EARLY:`media stopped early`,NO_BEST_EVENT:`no best event`,LOW_BEST_SCORE:`low score`};function ct(e){return st[e]??e}var lt={error:0,warn:1,info:2};function ut(e){return e.toSorted((e,t)=>lt[e.severity]-lt[t.severity]||e.code.localeCompare(t.code))}function dt(e){return e.length===0?Ze:`${Ze}?deviceIds=${e.join(`,`)}`}function ft(e){if(e<1e4)return`${(e/1e3).toFixed(1)}s`;let t=Math.round(e/1e3);if(t<60)return`${String(t)}s`;let n=Math.floor(t/60);return`${String(n)}m ${String(t%60).padStart(2,`0`)}s`}var pt=`all`,mt=`The server answered in a shape this build does not understand.`,ht={error:`danger`,warn:`warning`,info:`info`};function gt({findings:e}){return e.length===0?d(x,{variant:`success`,children:`no anomaly found`}):d(`div`,{className:`flex flex-wrap gap-1`,children:ut(e).map(e=>d(x,{variant:ht[e.severity],title:e.detail,children:ct(e.code)},e.code))})}function _t({track:e,report:t,cameraName:n,analyzing:i}){return r(`div`,{className:`flex flex-col gap-1.5 border-b border-border px-3 py-2.5 last:border-b-0`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[d(`span`,{className:`font-medium text-foreground`,children:n}),d(`span`,{className:`text-foreground-subtle`,children:e.label??e.className}),r(`span`,{className:`text-foreground-subtle`,children:[new Date(e.lastSeen).toLocaleString(),` · `,ft(e.durationMs)]}),e.active&&d(x,{variant:`default`,children:`still open`}),t!==void 0&&r(`span`,{className:`text-foreground-subtle`,children:[String(t.mediaCount),` media · `,String(t.eventCount),` events ·`,` `,String(t.positionCount),` positions`]})]}),d(`div`,{className:`flex items-center gap-2`,children:t===void 0?d(`span`,{className:`text-xs text-foreground-subtle`,children:i?`analysing…`:`not analysed`}):d(gt,{findings:t.findings})}),d(`code`,{className:`text-[10px] text-foreground-subtle`,children:e.trackId})]})}function vt(){let e=p(),[t,n]=u(pt),[i,s]=u(!1),[c,l]=u(null),f=ee({}),m=a(()=>[{value:pt,label:`All cameras`},...(f.data??[]).map(e=>({value:String(e.id),label:e.name}))],[f.data]),h=a(()=>{let e=new Map;for(let t of f.data??[])e.set(t.id,t.name);return e},[f.data]),g=a(()=>t===pt?[]:[Number.parseInt(t,10)],[t]),_=o({queryKey:[`events-debug`,`list`,g],queryFn:async()=>at(await e.trpcClient.addons.custom.mutate({addonId:Je,action:Ye,input:g.length===0?{}:{deviceIds:g}}))}),v=a(()=>(_.data?.tracks??[]).map(e=>e.trackId),[_.data]),b=o({queryKey:[`events-debug`,`analyze`,v],enabled:v.length>0,queryFn:async()=>ot(await e.trpcClient.addons.custom.mutate({addonId:Je,action:Xe,input:{trackIds:v}}))}),x=a(()=>{let e=new Map;for(let t of b.data?.reports??[])e.set(t.trackId,t);return e},[b.data]),S=()=>{_.refetch(),b.refetch()},C=async()=>{s(!0),l(null);try{await Le(dt(g),`camstack-debug.zip`)}catch(e){l(e instanceof Error?e.message:`Export failed.`)}finally{s(!1)}},w=_.data?.tracks??[],D=_.data===null||b.data===null;return d(Fe,{children:r(`section`,{className:`space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`div`,{className:`w-44`,children:d(T,{value:t,options:m,onChange:e=>n(e.target.value)})}),r(E,{variant:`secondary`,onClick:S,disabled:_.isFetching,children:[_.isFetching?d(q,{className:`h-3.5 w-3.5 animate-spin`}):d(ye,{className:`h-3.5 w-3.5`}),`Refresh`]}),r(E,{onClick:()=>void C(),disabled:i||w.length===0,children:[i?d(q,{className:`h-3.5 w-3.5 animate-spin`}):d(se,{className:`h-3.5 w-3.5`}),`Export all (`,String(w.length),`)`]})]}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`A `,d(`code`,{children:`debug`}),` mark does not pin retention — this lists the marked tracks that still exist. A track whose media was evicted shows as missing media.`]}),_.isError&&d(A,{message:`Could not load the marked tracks.`}),D&&!_.isError&&d(A,{message:mt}),c!==null&&d(A,{message:c}),_.data?.truncated===!0&&d(A,{message:`A camera filled the per-camera cap — some marked tracks are not listed. Un-mark a few, or filter to one camera.`}),(b.data?.vanished.length??0)>0&&r(`p`,{className:`text-xs text-foreground-subtle`,children:[String(b.data?.vanished.length),` marked track(s) were evicted between the list and the analysis.`]}),d(y,{children:_.isLoading?d(`div`,{className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`Loading…`}):w.length===0?r(`div`,{className:`flex flex-col items-center gap-2 px-3 py-8 text-center`,children:[d(Ve,{className:`h-5 w-5 text-foreground-subtle`}),d(`p`,{className:`text-xs text-foreground-subtle`,children:`No track is marked for debug. Mark one from a track's actions to see it here.`})]}):w.map(e=>d(_t,{track:e,report:x.get(e.trackId),cameraName:h.get(e.deviceId)??`Camera ${String(e.deviceId)}`,analyzing:b.isFetching},e.trackId))})]})})}function yt(e){return e.subLabel??e.label}var bt=720*60*60*1e3;function xt(e){let t=[];for(let n of e)t.push(...n);return t}function St(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function Ct(e,t){return e.filter(e=>!(e.importance<t.minImportance||t.cameras.size>0&&!t.cameras.has(e.deviceId)||t.classes.size>0&&!t.classes.has(e.className)))}function wt(e,t){return`${String(e)}:${t}`}function Tt(e,t){let n=new Map,r=new Set;for(let i of e){let e=wt(i.deviceId,i.trackId);if(!t.has(e)||r.has(e))continue;r.add(e);let a=n.get(i.deviceId);a?a.push(i.trackId):n.set(i.deviceId,[i.trackId])}return n}function Et(e,t){return{since:e.fromMs??t-bt,until:e.toMs??t}}var Y=typeof z==`function`,Dt=`Track deletion arrives with the next server update`;function Ot(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var kt=Y?z:Ot,At=200,jt=3e4;function Mt(e){let t=p(),n=c({queries:e.deviceIds.map(n=>({queryKey:[`events-feed`,n,e.since,e.until,e.minImportance??null,e.classFilter??null],staleTime:jt,refetchInterval:jt,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEvents.query({deviceId:n,since:e.since,until:e.until,limit:At,...e.minImportance===void 0?{}:{minImportance:e.minImportance},...e.classFilter===void 0?{}:{classFilter:e.classFilter}})).map(e=>({...e,deviceId:n}))}))});return{rows:St(xt(n.map(e=>e.data??[])),`importance`),isLoading:n.some(e=>e.isLoading)}}n();var Nt=[`events-feed`],Pt=2e3;function Ft(n){let r=l(),i=n?.paused===!0,a=t(r);a.current=r;let o=t(i);o.current=i;let[s,c]=u(!1),d=e(()=>{a.current.invalidateQueries({queryKey:Nt})},[]),p=t(void 0);p.current||=ve({delayMs:Pt,invalidate:()=>{o.current?c(!0):d()}}),f(()=>()=>p.current?.cancel(),[]),f(()=>{i||!s||(c(!1),d())},[i,s,d]);let m=e(()=>{c(!1),d()},[d]);return v(U.PipelineAnalyticsDetectionEvent,()=>{p.current?.trigger()}),v(U.PipelineAnalyticsTrackEnded,()=>{p.current?.trigger()}),{pending:s,refreshNow:m}}n();function It({groups:e,selected:t,onChange:n,loading:i=!1}){let{t:o}=Ne(),[s,c]=u(!1),[l,f]=u(``),[p,m]=u(new Set),h=l.trim().toLowerCase(),g=e=>h.length===0||P(e,o).toLowerCase().includes(h),_=a(()=>e.map(e=>({macro:e.macro,subs:e.subs.filter(t=>g(t)||g(e.macro))})).filter(e=>g(e.macro)||e.subs.length>0),[e,h]),v=e=>m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),y=e=>{let r=new Set(t),i=t.has(e.macro.kind)&&e.subs.every(e=>t.has(e.kind)),a=[e.macro.kind,...e.subs.map(e=>e.kind)];if(i)for(let e of a)r.delete(e);else for(let e of a)r.add(e);n(r)},b=e=>{let r=new Set(t);r.has(e)?r.delete(e):r.add(e),n(r)},x=()=>n(new Set),S=t.size;return r(`div`,{className:`relative`,children:[r(`button`,{type:`button`,onClick:()=>c(e=>!e),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${S>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[d(qe,{className:`h-3.5 w-3.5`}),S>0?`Kinds (${String(S)})`:`Kinds`,d(Pe,{className:`h-3 w-3`})]}),s&&r(`div`,{className:`absolute z-20 mt-1 max-h-80 w-64 overflow-auto rounded-md border border-border bg-surface p-2 shadow-lg`,children:[r(`div`,{className:`mb-2 flex items-center gap-1 rounded border border-border px-1.5`,children:[d(je,{className:`h-3.5 w-3.5 text-foreground-subtle`}),d(`input`,{type:`text`,value:l,onChange:e=>f(e.target.value),placeholder:`Search kinds…`,className:`w-full bg-transparent py-1 text-xs outline-none`}),S>0&&d(`button`,{type:`button`,onClick:x,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),_.length===0&&d(`div`,{className:`px-1 py-2 text-[11px] text-foreground-subtle`,children:i?`Loading kinds…`:h.length>0?`No kind matches that search.`:`These cameras advertise no event kinds.`}),_.map(e=>{let n=R(e.macro.iconId),i=p.has(e.macro.kind)||h.length>0,a=t.has(e.macro.kind);return r(`div`,{className:`mb-0.5`,children:[r(`div`,{className:`flex items-center gap-1`,children:[e.subs.length>0?d(`button`,{type:`button`,onClick:()=>v(e.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Expand`,children:d(i?Pe:De,{className:`h-3 w-3`})}):d(`span`,{className:`w-3`}),r(`label`,{className:`flex flex-1 cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[d(`input`,{type:`checkbox`,checked:a,onChange:()=>y(e),className:`accent-primary`}),d(n,{className:`h-3.5 w-3.5`,style:{color:e.macro.color}}),d(`span`,{className:`font-medium`,children:P(e.macro,o)})]})]}),i&&e.subs.map(e=>{let n=R(e.iconId);return r(`label`,{className:`ml-5 flex cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[d(`input`,{type:`checkbox`,checked:t.has(e.kind),onChange:()=>b(e.kind),className:`accent-primary`}),d(n,{className:`h-3.5 w-3.5`,style:{color:e.color}}),d(`span`,{children:P(e,o)})]},e.kind)})]},e.macro.kind)})]})]})}function Lt(e,t){let n=new Map;for(let r of e)if(!(t.size>0&&!t.has(r.deviceId)))for(let e of r.kinds)n.has(e.kind)||n.set(e.kind,e);return n}function Rt(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var zt=new Set([`detection`,`package`]);function Bt(e,t){return[...Lt(e,t).values()].filter(e=>e.parentKind===null&&zt.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function Vt(e,t){let n=Lt(e,t),r=new Map,i=new Map;for(let e of n.values()){if(e.parentKind===null){i.set(e.kind,e);continue}let t=r.get(e.parentKind);t===void 0?r.set(e.parentKind,[e]):t.push(e)}for(let[e,t]of r){if(i.has(e))continue;let n=t[0];n!==void 0&&i.set(e,Rt(e,n))}return[...i.values()].map(e=>({macro:e,subs:[...r.get(e.kind)??[]].sort((e,t)=>e.label.localeCompare(t.label))})).sort((e,t)=>e.macro.label.localeCompare(t.macro.label))}n();var Ht=1400,Ut=`Admin-gated URL — opens only inside an authenticated session`;function Wt({label:t,value:n,title:i}){let[a,o]=u(!1);return f(()=>{if(!a)return;let e=setTimeout(()=>o(!1),Ht);return()=>clearTimeout(e)},[a]),r(`button`,{type:`button`,onClick:e(()=>{(async()=>{try{await navigator.clipboard.writeText(n),o(!0)}catch{window.prompt(`Copy the media URL:`,n)}})()},[n]),title:i,"aria-label":`Copy ${t} URL`,className:`flex min-w-0 items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${a?`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:`border-border text-foreground-subtle hover:border-primary hover:text-foreground`}`,children:[d(a?we:oe,{className:`h-2.5 w-2.5 shrink-0`}),d(`span`,{className:`truncate`,children:a?`Copied`:t})]})}function Gt({localUrl:e,publicUrl:t}){return r(`div`,{className:`flex flex-wrap gap-1`,children:[d(Wt,{label:`Local`,value:e,title:`Copy LAN URL — ${Ut}`}),t&&d(Wt,{label:`Public`,value:t,title:`Copy public URL — ${Ut}`})]})}var Kt={firstFrame:`First frame (track start)`,lastFrame:`Last frame (track end)`,thumbnail:`Best detection`,thumbnailSmall:`Best detection (480)`,snapshot:`Snapshot`,keyFrame:`Key frame (native-res)`,keyFrameSmall:`Key frame (960)`,crop:`Object crop`,fullFrame:`Full frame`,fullFrameBoxed:`Full frame (boxed)`,faceCrop:`Face crop`,plateCrop:`Plate crop`};function qt(e){return e in Kt}function Jt(e){return qt(e)?Kt[e]:e}function Yt(e,t){return`${e}${Re}/${encodeURIComponent(t)}`}n();var Xt=3e4;function Zt(t){let[n,r]=u(null),i=e(e=>{r(t=>t??e)},[]);return f(()=>{t||r(null)},[t]),{publicOrigin:n,probes:t?d(Qt,{onOrigin:i}):null}}function Qt({onOrigin:e}){let{data:t}=w({capName:`network-access`});return d(s,{children:(t??[]).map(t=>d($t,{addonId:t.addonId,onOrigin:e},t.addonId))})}function $t({addonId:e,onOrigin:t}){let{data:n}=b({addonId:e},{refetchInterval:Xt,retry:!1});return f(()=>{let e=n?ie.safeParse(n):null,r=e?.success?e.data.endpoint?.url:void 0;if(r)try{t(new URL(r).origin)}catch{}},[n,t]),null}var en=typeof C==`function`,tn=`Track flags arrive with the next server update`;function nn(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var rn=en?C:nn;function an(e){if(typeof e!=`object`||!e||!(`trackId`in e)||!(`markForTrain`in e)||!(`debug`in e)||!(`favourited`in e))return null;let{trackId:t,markForTrain:n,debug:r,favourited:i}=e;return typeof t!=`string`||typeof n!=`boolean`||typeof r!=`boolean`||typeof i!=`boolean`?null:{trackId:t,markForTrain:n,debug:r,favourited:i}}n();function on({label:e,hint:t,checked:n,disabled:i,title:a,icon:o,onToggle:s}){return r(`button`,{type:`button`,role:`switch`,"aria-checked":n,"aria-label":e,disabled:i,title:a,onClick:s,className:`flex w-full items-center gap-2 rounded-md border px-2 py-1.5 text-left transition-colors disabled:opacity-50 ${n?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[d(`span`,{className:n?`text-primary`:`text-foreground-subtle`,children:o}),r(`span`,{className:`min-w-0 flex-1`,children:[d(`span`,{className:`block text-[11px] font-medium text-foreground`,children:e}),d(`span`,{className:`block text-[10px] text-foreground-subtle`,children:t})]}),d(`span`,{"aria-hidden":`true`,className:`h-4 w-7 shrink-0 rounded-full p-0.5 transition-colors ${n?`bg-primary`:`bg-border`}`,children:d(`span`,{className:`block h-3 w-3 rounded-full bg-white transition-transform ${n?`translate-x-3`:``}`})})]})}function sn({deviceId:e,trackId:t,markForTrain:n,debug:i,favourited:a,onChange:o}){let s=rn(),[c,l]=u(null),f=c?.markForTrain??n===!0,p=c?.debug??i===!0,m=c?.favourited??a===!0,h=!en||s.isPending,g=en?void 0:tn,_=n=>{h||(async()=>{try{let r=an(await s.mutateAsync({deviceId:e,trackId:t,flags:n}));if(!r)return;l(r),o?.(r)}catch(e){let t=e instanceof Error?e.message:``;window.alert(t===``?`Could not update this track. Check the server logs.`:`Could not update this track — ${t}`)}})()};return r(`div`,{className:`grid gap-1.5 sm:grid-cols-2`,children:[d(on,{label:`Mark for training`,hint:`Keeps this track and its media past retention`,checked:f,disabled:h,...g===void 0?{}:{title:g},icon:d(Ge,{className:`h-4 w-4`}),onToggle:()=>_({markForTrain:!f})}),d(on,{label:`Debug`,hint:`Flag this track for diagnostic attention`,checked:p,disabled:h,...g===void 0?{}:{title:g},icon:d(Ve,{className:`h-4 w-4`}),onToggle:()=>_({debug:!p})}),d(on,{label:`Favourited`,hint:`Keeps this track and its media past retention`,checked:m,disabled:h,...g===void 0?{}:{title:g},icon:d(Se,{className:`h-4 w-4`}),onToggle:()=>_({favourited:!m})})]})}var X=100,cn=120,ln={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Z=e=>e<0?0:e>1?1:e,Q=e=>Math.round(e*100)/100;function un(e,t){if(e.length<=t)return[...e];let n=(e.length-1)/(t-1),r=[];for(let i=0;i<t;i++)r.push(e[Math.round(i*n)]);return r[r.length-1]=e[e.length-1],r}function dn(e,t,n){if(e.length===0||t===null)return ln;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return ln;let a=un(e,n?.maxPoints??cn).map(e=>({x:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X)})),o=a[0]??null,s=a[a.length-1]??null,c=a.length>=2?a.map(e=>`${e.x},${e.y}`).join(` `):``,l=(n?.snapshots??[]).map(e=>({x:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X),mediaKey:e.mediaKey})),u=null,d=-1;for(let t of e){let e=Z(t.bbox.w/r)*Z(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:Q(Z(u.bbox.x/r)*X),y:Q(Z(u.bbox.y/i)*X),w:Q(Z(u.bbox.w/r)*X),h:Q(Z(u.bbox.h/i)*X)}:null}}n();var fn=15e3;function pn(e){return`${Re}/${encodeURIComponent(e)}`}var mn=window.location.origin;function hn({mediaKey:e,label:t}){let{src:n,failed:r}=Ie(pn(e));return n===null?d(`div`,{className:`flex h-full w-full items-center justify-center bg-surface-hover`,children:r?d(fe,{className:`h-4 w-4 text-foreground-subtle opacity-60`}):d(q,{className:`h-4 w-4 animate-spin text-foreground-subtle opacity-70`})}):d(`img`,{src:n,alt:t,className:`h-full w-full object-cover`})}var gn=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),_n=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]);function vn(e){let[t,n]=u(null);return f(()=>{if(n(null),!e)return;let t=!1,r=new Image;return r.onload=()=>{t||n({width:r.naturalWidth,height:r.naturalHeight})},r.src=e,()=>{t=!0,r.onload=null}},[e]),t}function yn({overlay:e,onPickSnapshot:t}){return!e.polyline&&!e.peakBox&&e.snapshots.length===0?null:r(`svg`,{viewBox:`0 0 100 100`,preserveAspectRatio:`none`,className:`pointer-events-none absolute inset-0 h-full w-full`,children:[e.peakBox&&d(`rect`,{x:e.peakBox.x,y:e.peakBox.y,width:e.peakBox.w,height:e.peakBox.h,fill:`none`,stroke:`#f59e0b`,strokeWidth:2,vectorEffect:`non-scaling-stroke`,rx:1}),e.polyline&&d(`polyline`,{points:e.polyline,fill:`none`,stroke:`#38bdf8`,strokeWidth:2,strokeLinejoin:`round`,strokeLinecap:`round`,strokeOpacity:.85,vectorEffect:`non-scaling-stroke`}),e.points.map((e,t)=>d(`circle`,{cx:e.x,cy:e.y,r:1,fill:`#38bdf8`,fillOpacity:.6,vectorEffect:`non-scaling-stroke`},`${String(e.x)}-${String(e.y)}-${String(t)}`)),e.snapshots.map((e,n)=>d(`circle`,{cx:e.x,cy:e.y,r:1.9,fill:`#0ea5e9`,fillOpacity:.95,stroke:`#082f49`,strokeWidth:.7,vectorEffect:`non-scaling-stroke`,className:t?`pointer-events-auto cursor-pointer`:void 0,onClick:t?n=>{n.stopPropagation(),t(e.mediaKey)}:void 0,children:d(`title`,{children:`Snapshot checkpoint — click to view this frame`})},`snap-${e.mediaKey}-${String(n)}`)),e.start&&d(`circle`,{cx:e.start.x,cy:e.start.y,r:2.4,fill:`#22c55e`,stroke:`#052e16`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`}),e.end&&d(`circle`,{cx:e.end.x,cy:e.end.y,r:2.4,fill:`#ef4444`,stroke:`#450a0a`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`})]})}function $({label:e,value:t,mono:n}){return r(`div`,{className:`flex items-baseline justify-between gap-3 border-b border-border/60 py-1.5 last:border-0`,children:[d(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),d(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono text-[11px]`:``}`,title:t,children:t})]})}function bn({row:t,cameraName:n,deleteAvailable:i,onClose:o,onDeleted:c,onFlagsChanged:l}){let m=p(),g=kt(),_=t!==null,v=t?.deviceId??0,y=t?.trackId??``,b=t?.bestEventId??``,x=t?.timestamp??0,C=t?.windowMs??0,{data:w}=ne({deviceId:v,trackId:y},{enabled:_}),{data:T}=V({trackId:y,deviceId:v},{enabled:_}),{data:D}=te({eventId:b,deviceId:v},{enabled:_&&b!==``}),{data:O}=S({deviceId:v,since:x-fn,until:x+C+fn},{enabled:_}),[ee,A]=u(null),[j,M]=u(!1),{publicOrigin:N,probes:P}=Zt(_);f(()=>{A(null)},[v,y]);let F=a(()=>{let e=T??[],t=D??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[T,D]),I=ee??F,L=Ie(I?pn(I.key):void 0),R=a(()=>{let e=new Set,t=[];for(let n of[...D??[],...T??[]])n.key===``||e.has(n.key)||(e.add(n.key),t.push(n));return t},[D,T]),z=a(()=>R.find(e=>gn.has(e.kind))??null,[R]),B=vn(Ie(z?pn(z.key):void 0).src),re=a(()=>dn(w?.positions??[],B,{snapshots:(w?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaKey:e.mediaKey}))}),[w?.positions,w?.snapshots,B]),H=e(e=>{let t=R.find(t=>t.key===e);t&&A(t)},[R]);if(t===null)return null;let U=L.src,ie=I?.kind,ae=ie!==void 0&&_n.has(ie)&&B!==null&&(w?.positions.length??0)>=2,W=O&&O.length>0?O[0]:null,oe=()=>{W&&(M(!0),(async()=>{try{let e=await m.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:W.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{window.alert(`Could not resolve clip playback. Check the server logs.`)}finally{M(!1)}})())},se=()=>{!i||g.isPending||window.confirm(`Delete this track and all its media? This cannot be undone.`)&&(async()=>{try{await g.mutateAsync({deviceId:t.deviceId,trackIds:[t.trackId]}),c()}catch{window.alert(`Failed to delete this track. Check the server logs.`)}})()},ce=Math.round(t.importance*100),G=w?.importanceReason?`${String(ce)}% · ${w.importanceReason}`:`${String(ce)}%`,ue=w?.zonesVisited&&w.zonesVisited.length>0?w.zonesVisited.join(`, `):`—`,de=w?.audioLabels&&w.audioLabels.length>0?w.audioLabels.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `):`—`,me=w?w.totalDistance.toFixed(2):`—`,ge=he(w?w.firstSeen:x),_e=w?he(w.lastSeen):`—`;return d(k,{open:!0,onOpenChange:e=>!e&&o(),children:r(h,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Event detail`,className:`flex h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:h-auto md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[r(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[r(`div`,{className:`min-w-0`,children:[r(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:[t.className,yt(t)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,yt(t)]}):null]}),d(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:n})]}),d(`button`,{type:`button`,onClick:o,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:d(Oe,{className:`h-4 w-4`})})]}),r(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[U?d(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:d(pe,{src:U,alt:`Key frame from ${n}`,fit:`natural`,className:`w-full`,overlay:ae?d(yn,{overlay:re,onPickSnapshot:H}):void 0})}):d(`div`,{className:`flex aspect-video w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-surface-hover text-foreground-subtle`,children:L.failed?r(s,{children:[d(fe,{className:`h-8 w-8 opacity-60`}),d(`span`,{className:`text-[11px]`,children:`Key-frame media unavailable`})]}):d(q,{className:`h-6 w-6 animate-spin opacity-70`})}),R.length>0&&d(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:R.map(e=>{let t=Jt(e.kind),n=Yt(mn,e.key),i=N?Yt(N,e.key):null;return r(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[d(`button`,{type:`button`,onClick:()=>A(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${t} · ${he(e.timestamp)}`,children:d(hn,{mediaKey:e.key,label:t})}),r(`figcaption`,{className:`min-w-0 px-0.5`,children:[d(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:t,children:t}),d(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:he(e.timestamp),children:le(e.timestamp)})]}),d(Gt,{localUrl:n,publicUrl:i})]},e.key)})}),P,W&&r(E,{variant:`secondary`,onClick:oe,disabled:j,children:[j?d(q,{className:`h-3.5 w-3.5 animate-spin`}):d(ke,{className:`h-3.5 w-3.5`}),` `,`View clip`]}),d(sn,{deviceId:t.deviceId,trackId:t.trackId,...(w?.markForTrain??t.markForTrain)===void 0?{}:{markForTrain:w?.markForTrain??t.markForTrain},...(w?.debug??t.debug)===void 0?{}:{debug:w?.debug??t.debug},...(w?.favourited??t.favourited)===void 0?{}:{favourited:w?.favourited??t.favourited},onChange:l}),r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[d($,{label:`Camera`,value:n}),d($,{label:`Class`,value:t.className}),d($,{label:`Label`,value:t.label??`—`}),d($,{label:`Sub-label`,value:t.subLabel??`—`}),d($,{label:`Importance`,value:G}),d($,{label:`Zones visited`,value:ue}),d($,{label:`Audio heard`,value:de}),d($,{label:`Total distance`,value:me}),d($,{label:`First seen`,value:ge}),d($,{label:`Last seen`,value:_e}),d($,{label:`Track`,value:t.trackId,mono:!0})]})]}),d(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:d(`span`,{title:i?void 0:Dt,children:r(E,{variant:`secondary`,onClick:se,disabled:!i||g.isPending,children:[g.isPending?d(q,{className:`h-3.5 w-3.5 animate-spin`}):d(Me,{className:`h-3.5 w-3.5`}),` `,`Delete track`]})})})]})})}function xn(e){if(e===void 0||!Number.isFinite(e)||e<=0)return``;let t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return`${String(n)}m ${String(r).padStart(2,`0`)}s`}function Sn({row:e,cameraName:t,nowMs:n,onOpenDetail:i,selected:a=!1,onToggleSelect:o,score:s}){let c=Ie(e.bestEventId?`${Re}/${e.bestEventId}`:void 0),l=Math.round(e.importance*100),u=s===void 0?void 0:Math.round(s*100),f=xn(e.windowMs),p=()=>i(e);return r(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${a?`border-primary ring-1 ring-primary`:`border-border`}`,children:[r(`div`,{className:`aspect-video relative overflow-hidden bg-surface-hover`,children:[c.src?d(`img`,{src:c.src,alt:`Event from ${t}`,onClick:p,className:`h-full w-full cursor-zoom-in object-cover`}):d(`button`,{type:`button`,onClick:p,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-surface-hover text-foreground-subtle`,title:c.failed?`Key-event media unavailable`:`No key-event media`,children:d(fe,{className:`h-6 w-6 opacity-60`})}),o&&d(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(wt(e.deviceId,e.trackId))},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":a?`Deselect`:`Select`,children:a?d(be,{className:`h-4 w-4 text-primary`}):d(xe,{className:`h-4 w-4`})}),u!==void 0&&r(`span`,{className:`absolute left-1 top-1 z-10 rounded bg-primary/85 px-1.5 py-0.5 text-[10px] font-semibold text-white tabular-nums`,title:`CLIP semantic-match score`,children:[String(u),`%`]}),l>0&&d(`span`,{className:`absolute right-1 top-1 z-10 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-semibold text-white`,children:String(l)}),(e.markForTrain===!0||e.debug===!0||e.favourited===!0)&&r(`span`,{className:`absolute bottom-1 left-1 z-10 flex gap-1`,children:[e.markForTrain===!0&&d(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:`Marked for training`,"aria-label":`Marked for training`,children:d(Ge,{className:`h-3 w-3`})}),e.debug===!0&&d(`span`,{className:`rounded bg-black/70 p-0.5 text-white`,title:`Flagged for debug`,"aria-label":`Flagged for debug`,children:d(Ve,{className:`h-3 w-3`})}),e.favourited===!0&&d(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:`Favourited`,"aria-label":`Favourited`,children:d(Se,{className:`h-3 w-3`})})]})]}),r(`button`,{type:`button`,onClick:p,className:`min-w-0 px-2 py-1.5 text-left space-y-0.5`,children:[r(`p`,{className:`text-[11px] font-medium text-foreground truncate`,title:e.className,children:[e.className,yt(e)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,yt(e)]}):null]}),d(`p`,{className:`text-[10px] text-foreground-subtle truncate`,title:t,children:t}),r(`div`,{className:`flex items-center justify-between gap-2`,children:[d(`span`,{className:`text-[10px] text-foreground-subtle truncate`,children:ue(e.timestamp,n)}),f&&d(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:f})]})]})]})}n();function Cn(){let[n,r]=u(!1),i=t(null),[a,o]=u(0),s=e(e=>{i.current!==e&&(i.current=e,o(e=>e+1))},[]);return f(()=>{let e=i.current;if(!e||typeof IntersectionObserver>`u`){r(!1);return}let t=new IntersectionObserver(e=>{let t=e[e.length-1];t&&r(!t.isIntersecting)},{rootMargin:`64px 0px 0px 0px`,threshold:0});return t.observe(e),()=>t.disconnect()},[a]),{ref:s,scrolledPast:n}}n();var wn=[`events-feed`],Tn=60,En=[{value:`importance`,label:`Importance`,icon:Be},{value:`time`,label:`Recent`,icon:W}];function Dn(){let e=l(),[t,n]=u(_e),[i,o]=u(new Set),[c,p]=u(new Set),[m,h]=u(0),[g,_]=u(`time`),[v,y]=u(new Set),[b,x]=u(null),[S,C]=u(()=>Date.now());f(()=>{let e=setInterval(()=>C(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:w,until:T}=a(()=>Et({fromMs:t.fromMs,toMs:t.toMs},S),[t.fromMs,t.toMs,S]),D=Cn(),{pending:O,refreshNow:k}=Ft({paused:b!==null||v.size>0||D.scrolledPast}),{data:A}=ee({}),j=a(()=>(A??[]).filter(e=>e.type===ae.Camera),[A]),M=a(()=>j.map(e=>e.id),[j]),{data:N,isLoading:te}=F({deviceIds:M},{enabled:M.length>0,staleTime:5*6e4}),P=a(()=>Vt(N??[],i),[N,i]),ne=kt(),I=ne.isPending,{rows:L,isLoading:R}=Mt({deviceIds:M,since:w,until:T,minImportance:m>0?m:void 0,classFilter:c.size===1?[...c][0]:void 0}),z=a(()=>{let e=new Map;for(let t of j??[])e.set(t.id,t.name);return e},[j]),B=e=>z.get(e)??`Camera #${String(e)}`,re=a(()=>G(L).map(e=>({id:e,name:B(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[L,z]),V=a(()=>St(Ct(L,{cameras:i,classes:c,minImportance:m}),g),[L,i,c,m,g]),H=me(V,Tn,a(()=>JSON.stringify([[...i].sort((e,t)=>e-t),[...c].sort(),m,g,w,T]),[i,c,m,g,w,T])),U=()=>{e.invalidateQueries({queryKey:wn})},ie=()=>y(new Set);function W(e){y(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function oe(){if(v.size===0||!Y)return;let e=Tt(L,v),t=[...e.values()].reduce((e,t)=>e+t.length,0);if(t===0||!window.confirm(`Delete ${String(t)} track${t===1?``:`s`} and all their media? This cannot be undone.`))return;let n=[...e];Promise.allSettled(n.map(([e,t])=>ne.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{U();let t=[],r=new Set;if(e.forEach((e,i)=>{let a=n[i];if(!a)return;let[o,s]=a;if(e.status===`fulfilled`)for(let e of s)r.add(wt(o,e));else t.push(o)}),y(e=>{let t=new Set(e);for(let e of r)t.delete(e);return t}),t.length>0){let e=t.map(e=>B(e)).join(`, `);window.alert(`Failed to delete tracks on: ${e}. They remain selected — retry, or check the server logs.`)}})}let se=V.length!==L.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d(ge,{onChange:n}),d(de,{cameras:re,selected:i,onChange:o}),d(It,{groups:P,selected:c,onChange:p,loading:te}),r(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[d(`span`,{children:`Min score`}),d(`input`,{type:`range`,min:0,max:1,step:.05,value:m,onChange:e=>h(Number(e.target.value)),className:`h-1 w-24 cursor-pointer accent-primary`,"aria-label":`Minimum importance`}),d(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(m*100)})]}),d(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:En.map(e=>{let t=e.icon;return r(`button`,{type:`button`,onClick:()=>_(e.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${g===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[d(t,{className:`h-3.5 w-3.5`}),` `,e.label]},e.value)})}),!R&&d(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:se?`${String(V.length)} of ${String(L.length)} events`:`${String(V.length)} event${V.length===1?``:`s`}`})]}),v.size>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[r(`span`,{className:`text-xs font-medium text-foreground`,children:[v.size,` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[d(`span`,{title:Y?void 0:`Track deletion arrives with the next server update`,children:r(E,{variant:`secondary`,onClick:oe,disabled:!Y||I,children:[I?d(q,{className:`h-3.5 w-3.5 animate-spin`}):d(Me,{className:`h-3.5 w-3.5`}),` `,`Delete`]})}),d(E,{variant:`ghost`,onClick:ie,disabled:I,children:d(Oe,{className:`h-3.5 w-3.5`})})]})]}),R&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[d(q,{className:`h-4 w-4 animate-spin`}),` Loading events…`]}),!R&&V.length===0&&d(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No key events in this window.`}),O&&d(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:d(`button`,{type:`button`,onClick:k,className:`rounded-full border border-primary/40 bg-surface px-3 py-1 text-[11px] font-medium text-primary shadow-sm hover:bg-primary/10`,children:`New events — refresh`})}),!R&&V.length>0&&r(s,{children:[d(`div`,{ref:D.ref,"aria-hidden":!0,className:`h-0`}),d(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:H.pageItems.map(e=>d(Sn,{row:e,cameraName:B(e.deviceId),nowMs:S,selected:v.has(wt(e.deviceId,e.trackId)),onToggleSelect:W,onOpenDetail:x},wt(e.deviceId,e.trackId)))}),d(ce,{currentPage:H.page,totalItems:H.totalItems,pageSize:H.pageSize,onPageChange:H.setPage,itemNoun:`events`})]}),b&&d(bn,{row:b,cameraName:B(b.deviceId),deleteAvailable:Y,onClose:()=>x(null),onDeleted:()=>{U(),x(null)},onFlagsChanged:e=>{x(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug,favourited:e.favourited}:t)}})]})}n();var On=50,kn=350,An=[{value:.2,label:`Loose`},{value:.25,label:`Balanced`},{value:.3,label:`Strict`}];function jn(e){return{id:e.id,trackId:e.trackId??e.id,deviceId:e.deviceId,timestamp:e.timestamp,className:e.className,label:e.label,subLabel:e.subLabel,importance:e.importance??0,bestEventId:e.mediaKey??e.trackId??e.id,windowMs:void 0}}function Mn({onActiveChange:e}){let[t,n]=u(``),[i,o]=u(.2),[s,c]=u(null),[l,p]=u(null),[m,h]=u(null),_=I(t,kn).trim(),v=_.length>0;f(()=>{e(v)},[v,e]);let[y,b]=u(()=>Date.now());f(()=>{let e=setInterval(()=>b(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:x}=ee({}),S=a(()=>(x??[]).filter(e=>e.type===ae.Camera),[x]),C=a(()=>{let e=new Map;for(let t of x??[])e.set(t.id,t.name);return e},[x]),w=e=>C.get(e)??`Camera #${String(e)}`,T=a(()=>S.map(e=>e.id),[S]),{data:E}=F({deviceIds:T},{enabled:T.length>0,staleTime:5*6e4}),D=a(()=>Bt(E??[],new Set(l===null?[]:[l])),[E,l]);f(()=>{s!==null&&(D.some(e=>e.kind===s)||c(null))},[D,s]);let{data:O,isFetching:k,isError:A,error:j}=g({text:_,minScore:i,limit:On,classFilter:s??void 0,deviceId:l??void 0},{enabled:v}),M=a(()=>[...O??[]].sort((e,t)=>t.score-e.score).map(e=>({...jn(e),score:e.score})),[O]);function N(e){c(t=>t===e?null:e)}return r(`div`,{className:`space-y-3`,children:[r(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(`div`,{className:`relative min-w-[16rem] flex-1`,children:[d(je,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),d(`input`,{type:`text`,value:t,onChange:e=>n(e.target.value),placeholder:`Semantic search — describe what you're looking for…`,className:`h-9 w-full rounded-md border border-border bg-background pl-8 pr-8 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary`,"aria-label":`Semantic event search`}),t&&d(`button`,{type:`button`,onClick:()=>n(``),className:`absolute right-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Clear search`,children:d(Oe,{className:`h-3.5 w-3.5`})})]}),k&&v&&d(q,{className:`h-4 w-4 shrink-0 animate-spin text-foreground-subtle`})]}),r(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[d(`div`,{className:`flex items-center gap-1`,children:D.map(e=>d(`button`,{type:`button`,onClick:()=>N(e.kind),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${s===e.kind?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:P(e)},e.kind))}),r(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[d(`span`,{children:`Camera`}),r(`select`,{value:l===null?``:String(l),onChange:e=>p(e.target.value===``?null:Number(e.target.value)),className:`h-7 rounded-md border border-border bg-background px-1.5 text-xs text-foreground focus:border-primary focus:outline-none`,"aria-label":`Filter by camera`,children:[d(`option`,{value:``,children:`All`}),S.map(e=>d(`option`,{value:String(e.id),children:e.name},e.id))]})]}),r(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[d(`span`,{children:`Match`}),d(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:An.map(e=>d(`button`,{type:`button`,onClick:()=>o(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${i===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:`Minimum CLIP score ${e.value.toFixed(2)}`,children:e.label},e.value))})]}),v&&!k&&!A&&r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[M.length,` match`,M.length===1?``:`es`]})]})]}),v&&r(`div`,{className:`space-y-3`,children:[A&&r(`p`,{className:`py-4 text-xs text-danger`,children:[`Search failed: `,j instanceof Error?j.message:`unknown error`,`. Check that the CLIP embedding step is enabled.`]}),!A&&k&&M.length===0&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[d(q,{className:`h-4 w-4 animate-spin`}),` Searching…`]}),!A&&!k&&M.length===0&&r(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:[`No semantic matches for “`,_,`”. Try a looser match threshold or a different phrasing.`]}),!A&&M.length>0&&d(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:M.map(e=>d(Sn,{row:e,cameraName:w(e.deviceId),nowMs:y,score:e.score,onOpenDetail:h},e.id))})]}),m&&d(bn,{row:m,cameraName:w(m.deviceId),deleteAvailable:Y,onClose:()=>h(null),onDeleted:()=>h(null)})]})}var Nn=15e3;function Pn(e){let t=p(),n=c({queries:e.map(e=>({queryKey:[`stationary-objects`,e],staleTime:Nn,refetchInterval:Nn,queryFn:async()=>((await t.trpcClient.zoneAnalytics.getCurrentSnapshot.query({deviceId:e}))?.stationaryObjects??[]).map(t=>({...t,deviceId:e}))}))});return{rows:n.flatMap(e=>e.data??[]).toSorted((e,t)=>t.becameStationaryAt-e.becameStationaryAt),isLoading:n.some(e=>e.isLoading)}}n();function Fn(e,t){let n=Math.max(0,Math.round((e-t)/6e4));if(n<1)return`just now`;if(n<60)return`${String(n)}m`;let r=Math.floor(n/60);return`${String(r)}h ${String(n%60)}m`}function In({row:e,cameraName:t,nowMs:n}){let i=e.keyFrameMediaKey?.startsWith(`track:`)?e.keyFrameMediaKey.split(`:`)[1]:e.keyFrameMediaKey,a=Ie(i?`${Re}/${i}`:void 0);return r(`div`,{className:`flex flex-col overflow-hidden rounded-md border border-border bg-surface`,children:[r(`div`,{className:`relative aspect-video overflow-hidden bg-surface-hover`,children:[a.src?d(`img`,{src:a.src,alt:`Parked ${e.className} on ${t}`,className:`h-full w-full object-cover`}):d(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:d(Ke,{className:`h-6 w-6`})}),d(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-medium capitalize text-white`,children:e.label??e.className})]}),r(`div`,{className:`flex flex-col gap-0.5 p-1.5`,children:[d(`span`,{className:`truncate text-[11px] text-foreground`,children:t}),r(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`parked `,Fn(n,e.becameStationaryAt)]})]})]})}function Ln(){let[e,t]=u(!1),n=Date.now(),{data:i}=ee({}),o=a(()=>(i??[]).filter(e=>e.type===ae.Camera),[i]),s=a(()=>o.map(e=>e.id),[o]),c=a(()=>{let e=new Map;for(let t of o)e.set(t.id,t.name);return e},[o]),{rows:l}=Pn(s);return l.length===0?null:r(`div`,{className:`rounded-md border border-border bg-surface/40`,children:[r(`button`,{type:`button`,onClick:()=>t(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,children:[d(e?Pe:De,{className:`h-4 w-4 text-foreground-subtle`}),d(Ke,{className:`h-4 w-4 text-foreground-subtle`}),d(`span`,{className:`text-sm font-semibold text-foreground`,children:`Stationary`}),d(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:l.length}),d(`span`,{className:`ml-2 text-[11px] text-foreground-subtle`,children:`Parked objects — kept out of the event feed`})]}),e&&d(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:l.map(e=>d(In,{row:e,cameraName:c.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:n},e.id))})]})}n();function Rn(){let[e,t]=u(!1);return d(Fe,{children:r(`section`,{className:`space-y-3`,children:[d(Mn,{onActiveChange:t}),!e&&d(Ln,{}),!e&&d(Dn,{})]})})}var zn=[`person`,`vehicle`,`animal`,`package`,`face`,`plate`],Bn=new Set(zn);function Vn(e){let t=e?.trim().toLowerCase();return t===void 0||t===``?null:Bn.has(t)?`"${t}" is a macro class, not a label — person / postman / Marco are three different tiers`:null}function Hn({annotations:e,selectedIndex:t,onSelect:n,onChange:i,onDelete:a}){return e.length===0?r(`p`,{className:`text-[11px] text-foreground-subtle p-3`,children:[`No subject on this frame yet. Drag on the image to draw one, or ask the pipeline for a proposal. Annotate `,d(`strong`,{children:`every`}),` subject — a frame with one box and three unlabelled people teaches the model that two thirds of the people in it are background.`]}):d(`ul`,{className:`divide-y divide-border`,children:e.map((e,o)=>{let s=o===t,c=Vn(e.label),l=Vn(e.subLabel);return r(`li`,{className:`p-2.5 space-y-1.5 ${s?`bg-surface-hover`:``}`,onFocus:()=>{n(o)},children:[r(`div`,{className:`flex items-center gap-2`,children:[d(T,{className:`w-28`,value:e.macroClass,options:zn.map(e=>({value:e,label:e})),onChange:e=>{let t=zn.find(t=>t===e.target.value);t!==void 0&&i(o,{macroClass:t})}}),d(T,{className:`w-32`,value:e.kind,options:[{value:`subject`,label:`subject`},{value:`model_error`,label:`model error`}],onChange:e=>{i(o,{kind:e.target.value===`model_error`?`model_error`:`subject`})}}),e.source===`assist`&&r(x,{variant:`info`,children:[e.assistModelId??`assist`,e.assistScore===void 0?``:` ${e.assistScore.toFixed(2)}`]}),d(E,{variant:`ghost`,size:`sm`,"aria-label":`Delete this subject`,onClick:()=>{a(o)},children:d(Me,{className:`h-3 w-3`})})]}),r(`div`,{className:`flex items-center gap-2`,children:[d(_,{className:`flex-1`,placeholder:`label (postman, van, cat…)`,value:e.label??``,onChange:e=>{i(o,{label:e.target.value})}}),d(_,{className:`flex-1`,placeholder:`sub-label (a name, a plate…)`,value:e.subLabel??``,onChange:e=>{i(o,{subLabel:e.target.value})}})]}),c!==null&&d(`p`,{className:`text-[11px] text-danger`,children:c}),l!==null&&d(`p`,{className:`text-[11px] text-danger`,children:l})]},`${String(o)}-${String(e.bbox.x)}`)})})}function Un(e){return e.every(e=>Vn(e.label)===null&&Vn(e.subLabel)===null&&Bn.has(e.macroClass))}function Wn(e){return e<0?0:e>1?1:e}function Gn(e,t,n,r){if(!(e>0)||!(t>0)||!(n>0)||!(r>0))return null;let i=Math.min(e/n,t/r),a=n*i,o=r*i;return{left:(e-a)/2,top:(t-o)/2,width:a,height:o}}function Kn(e,t,n){return{x:Wn((e-n.left)/n.width),y:Wn((t-n.top)/n.height)}}function qn(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),w:Math.abs(t.x-e.x),h:Math.abs(t.y-e.y)}}function Jn(e){return e.w>=.01&&e.h>=.01}function Yn(e,t){return{left:t.left+e.x*t.width,top:t.top+e.y*t.height,width:e.w*t.width,height:e.h*t.height}}function Xn(e,t){let n=-1,r=1/0;return e.forEach((e,i)=>{if(!(t.x>=e.x&&t.x<=e.x+e.w&&t.y>=e.y&&t.y<=e.y+e.h))return;let a=e.w*e.h;a<r&&(n=i,r=a)}),n}n();function Zn({imageSrc:n,imageWidth:a,imageHeight:o,boxes:s,selectedIndex:c,onSelect:l,onDraw:f}){let p=t(null),[m,h]=u({w:0,h:0}),[g,_]=u(null);i(()=>{let e=p.current;if(e===null)return;let t=new ResizeObserver(()=>{h({w:e.clientWidth,h:e.clientHeight})});return t.observe(e),h({w:e.clientWidth,h:e.clientHeight}),()=>{t.disconnect()}},[]);let v=Gn(m.w,m.h,a,o),y=e(e=>{let t=p.current;if(t===null||v===null)return null;let n=t.getBoundingClientRect();return Kn(e.clientX-n.left,e.clientY-n.top,v)},[v]);return r(`div`,{ref:p,className:`relative w-full h-full min-h-[280px] bg-surface-sunken select-none touch-none`,onPointerDown:e=>{let t=y(e);t!==null&&(e.currentTarget.setPointerCapture(e.pointerId),_({start:t,current:qn(t,t)}))},onPointerMove:e=>{if(g===null)return;let t=y(e);t!==null&&_({start:g.start,current:qn(g.start,t)})},onPointerUp:()=>{if(g===null)return;let e=g.current;_(null),Jn(e)?f(e):l(Xn(s.map(e=>e.bbox),g.start))},children:[d(`img`,{src:n,alt:`Frame being annotated`,className:`absolute inset-0 w-full h-full object-contain pointer-events-none`}),v!==null&&s.map((e,t)=>{let n=Yn(e.bbox,v),i=e.kind===`model_error`,a=t===c,o=i?`#ef4444`:a?`#22c55e`:`#3b82f6`;return d(`div`,{className:`absolute pointer-events-none`,style:{left:n.left,top:n.top,width:n.width,height:n.height,border:`${a?`2px`:`1px`} ${i?`dashed`:`solid`} ${o}`,opacity:e.source===`assist`&&!a?.65:1},children:r(`span`,{className:`absolute -top-4 left-0 text-[10px] px-1 rounded`,style:{background:o,color:`#08121f`},children:[e.label??e.macroClass,i?` ✕`:``]})},`${String(t)}-${String(e.bbox.x)}-${String(e.bbox.y)}`)}),g!==null&&v!==null&&d(`div`,{className:`absolute border border-dashed border-primary pointer-events-none`,style:Yn(g.current,v)})]})}function Qn(e){return e>=1e6?`${(e/1e6).toFixed(1)} MB`:`${Math.round(e/1e3)} KB`}function $n({candidates:e,copies:t,activeFrameId:n,refusals:i,isSelecting:a,onSelectCandidate:o,onOpenCopy:s,onRemoveCopy:c}){let l=new Set(t.map(e=>e.sourceMediaKey)),u=e.filter(e=>!l.has(e.mediaKey));return r(`div`,{className:`space-y-3`,children:[r(`section`,{children:[r(`h3`,{className:`text-xs font-semibold text-foreground mb-1.5`,children:[`In the dataset (`,t.length,`)`]}),t.length===0?d(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No frame copied yet. Selecting a frame copies it into retrain storage immediately — the dataset stops depending on the track's own media from that moment.`}):d(`ul`,{className:`flex flex-wrap gap-2`,children:t.map(e=>d(`li`,{children:r(`div`,{className:`rounded-md border px-2 py-1.5 text-[11px] ${e.frameId===n?`border-primary bg-surface-hover`:`border-border`}`,children:[r(`button`,{type:`button`,className:`flex items-center gap-1.5 text-left`,onClick:()=>{s(e.frameId)},children:[d(we,{className:`h-3 w-3 text-success`}),d(`span`,{className:`font-medium text-foreground`,children:e.sourceKind}),r(`span`,{className:`text-foreground-subtle`,children:[e.width,`×`,e.height,` · `,Qn(e.sizeBytes)]})]}),r(`button`,{type:`button`,"aria-label":`Remove this frame from the dataset`,className:`mt-1 flex items-center gap-1 text-foreground-muted hover:text-danger`,onClick:()=>{c(e.frameId)},children:[d(Me,{className:`h-3 w-3`}),`remove`]})]})},e.frameId))})]}),r(`section`,{children:[r(`h3`,{className:`text-xs font-semibold text-foreground mb-1.5`,children:[`Available frames (`,u.length,`)`]}),u.length===0?d(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.length===0?`This track has no whole, unannotated frame left — its media aged out before it was marked. Anything already copied above is still usable.`:`Every available frame is already in the dataset.`}):d(`ul`,{className:`flex flex-wrap gap-2`,children:u.map(e=>{let t=i.get(e.mediaKey);return r(`li`,{children:[r(E,{variant:`secondary`,size:`sm`,disabled:a||t!==void 0,onClick:()=>{o(e.mediaKey)},children:[a?d(q,{className:`h-3 w-3 animate-spin`}):d(t===void 0?We:fe,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:e.kind}),d(`span`,{className:`ml-1 text-foreground-subtle`,children:Qn(e.sizeBytes)})]}),t!==void 0&&d(x,{variant:`danger`,className:`ml-1`,children:t})]},e.mediaKey)})})]})]})}function er(e){return e.frameCount===0?`untouched`:e.annotationCount===0?`started`:`ready`}var tr={untouched:{icon:Ue,label:`to do`,variant:`default`},started:{icon:He,label:`frames only`,variant:`info`},ready:{icon:Te,label:`annotated`,variant:`success`}};function nr(e){return new Date(e).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function rr({tracks:e,isLoading:t,selectedTrackId:n,deviceNames:i,onSelect:a}){return t?r(`div`,{className:`flex items-center gap-2 p-4 text-xs text-foreground-subtle`,children:[d(q,{className:`h-3.5 w-3.5 animate-spin`}),`Loading staging tracks…`]}):e.length===0?d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`Nothing in staging. Mark a track for training from the viewer or the Events grid and it appears here.`}):d(`ul`,{className:`divide-y divide-border`,children:e.map(e=>{let t=tr[er(e)],o=t.icon;return d(`li`,{children:r(`button`,{type:`button`,onClick:()=>{a(e)},className:`w-full text-left px-3 py-2 flex items-start gap-2 hover:bg-surface-hover ${e.trackId===n?`bg-surface-hover`:``}`,children:[d(o,{className:`h-3.5 w-3.5 mt-0.5 shrink-0 text-foreground-subtle`}),r(`span`,{className:`min-w-0 flex-1`,children:[r(`span`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs font-medium text-foreground truncate`,children:e.label??e.className}),d(x,{variant:t.variant,children:t.label})]}),r(`span`,{className:`block text-[11px] text-foreground-subtle truncate`,children:[i.get(e.deviceId)??`Camera ${String(e.deviceId)}`,` ·`,` `,nr(e.lastSeen)]}),r(`span`,{className:`block text-[11px] text-foreground-muted`,children:[e.frameCount,` frame`,e.frameCount===1?``:`s`,` ·`,` `,e.annotationCount,` subject`,e.annotationCount===1?``:`s`]})]})]})},e.trackId)})})}n();var ir=`person`;function ar(){let[t,n]=u(null),[i,o]=u(null),[c,l]=u([]),[p,h]=u(-1),[g,_]=u(new Map),[v,y]=u(null),b=ee({projection:`slim`,isCamera:!0}),S=a(()=>{let e=new Map;for(let t of b.data??[])e.set(t.id,t.name);return e},[b.data]),C=j({}),w=H({trackId:t?.trackId??``},{enabled:t!==null}),T=B({trackId:t?.trackId??``},{enabled:t!==null}),k=L({frameId:i??``},{enabled:i!==null}),A=m(),te=N(),P=D(),F=O(),ne=M(),I=re();f(()=>{if(i===null){l([]);return}l((T.data??[]).filter(e=>e.mediaKey===i).map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},...e.subLabel===void 0?{}:{subLabel:e.subLabel},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))),h(-1)},[i,T.data]),f(()=>{let e=w.data?.copies??[];i===null&&e.length>0&&o(e[0].frameId)},[w.data,i]);let R=e(e=>{n(e),o(null),l([]),_(new Map),y(null)},[]),z=e(async e=>{if(t===null)return;let n=await A.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,mediaKeys:[e]});if(n.refused.length>0){let e=new Map(g);for(let t of n.refused)e.set(t.sourceMediaKey,t.reason);_(e)}n.copied.length>0&&o(n.copied[0].frameId),await w.refetch(),await C.refetch()},[t,A,g,w,C]),V=e(async e=>{t!==null&&(await te.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:e}),i===e&&o(null),await w.refetch(),await T.refetch(),await C.refetch())},[t,te,i,w,T,C]),U=e(async e=>{if(t===null||i===null)return;y(null);let n=await P.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:i,subject:e===`package`?{kind:`package`}:{kind:`objects`,modelId:`yolo26n`,minScore:.3}});if(n.kind===`refused`){y(n.reason===`no-zone`?`A package proposal runs on the zone crop only — this camera has no zone, and running the detector on the whole frame at 0.35 proposes furniture.`:`The pipeline refused: ${n.reason}${n.detail===void 0?``:` — ${n.detail}`}`);return}l(e=>[...e,...n.proposals.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))]),y(`${n.proposals.length} proposal${n.proposals.length===1?``:`s`} from ${n.modelId}`+(n.belowThreshold>0?` — ${n.belowThreshold} more were below ${n.minScore.toFixed(2)}`:``))},[t,i,P]),ie=e(e=>{l(t=>[...t,{bbox:e,macroClass:ir,kind:`subject`,source:`operator`}]),h(c.length)},[c.length]),ae=e((e,t)=>{l(n=>n.map((n,r)=>r===e?{...n,...t}:n))},[]),W=e(e=>{l(t=>t.filter((t,n)=>n!==e)),h(-1)},[]),oe=e(async()=>{t===null||i===null||(await F.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:i,annotations:c.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label!==void 0&&e.label!==``?{label:e.label}:{},...e.subLabel!==void 0&&e.subLabel!==``?{subLabel:e.subLabel}:{},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))}),await T.refetch(),await C.refetch(),y(`Annotations saved.`))},[t,i,c,F,T,C]),se=e(async()=>{if(t===null)return;let e=await ne.mutateAsync({deviceId:t.deviceId,trackId:t.trackId});y(e.changed?`Track completed — it is now trained, and its own media is evictable again.`:e.reason===`no-frames-copied`?`Refused: no frame was ever copied into the dataset. Completing would let retention delete material nothing was extracted from.`:`Refused: ${e.reason??`unknown`}`),await C.refetch(),e.changed&&n(null)},[t,ne,C]),ce=e(async()=>{if(t===null)return;let e=await I.mutateAsync({deviceId:t.deviceId,trackId:t.trackId});y(e.changed?`Track returned to staging. Its copies and annotations were left alone.`:`Refused: ${e.reason??`unknown`}`),await C.refetch()},[t,I,C]),G=k.data,le=Un(c)&&i!==null;return r(Fe,{subtitle:`Turn the tracks you marked for training into an annotated dataset. Selecting a frame copies it — the dataset never depends on media that can be swept.`,actions:t===null?null:r(`div`,{className:`flex items-center gap-2`,children:[r(E,{variant:`secondary`,size:`sm`,onClick:()=>void ce(),children:[d(Ce,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:`Back to staging`})]}),r(E,{size:`sm`,onClick:()=>void se(),children:[d(Ge,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:`Complete track`})]})]}),children:[v!==null&&d(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-xs text-foreground`,children:v}),r(`div`,{className:`grid grid-cols-1 lg:grid-cols-[minmax(0,260px)_minmax(0,1fr)] gap-4`,children:[r(`aside`,{className:`rounded-md border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-3 py-2 border-b border-border flex items-center justify-between`,children:[d(`h2`,{className:`text-xs font-semibold text-foreground`,children:`Staging`}),d(x,{children:C.data?.length??0})]}),d(rr,{tracks:C.data??[],isLoading:C.isLoading,selectedTrackId:t?.trackId??null,deviceNames:S,onSelect:R})]}),d(`section`,{className:`space-y-3 min-w-0`,children:t===null?d(`p`,{className:`text-xs text-foreground-subtle`,children:`Pick a track from the staging list to start annotating it.`}):r(s,{children:[d(`div`,{className:`rounded-md border border-border bg-surface p-3`,children:d($n,{candidates:w.data?.candidates??[],copies:w.data?.copies??[],activeFrameId:i,refusals:g,isSelecting:A.isPending,onSelectCandidate:e=>void z(e),onOpenCopy:o,onRemoveCopy:e=>void V(e)})}),i!==null&&r(`div`,{className:`grid grid-cols-1 xl:grid-cols-[minmax(0,1fr)_minmax(0,380px)] gap-3`,children:[d(`div`,{className:`rounded-md border border-border overflow-hidden`,children:G===void 0?r(`div`,{className:`flex items-center gap-2 p-6 text-xs text-foreground-subtle`,children:[d(q,{className:`h-3.5 w-3.5 animate-spin`}),`Loading the frame…`]}):d(Zn,{imageSrc:`data:image/jpeg;base64,${G.base64}`,imageWidth:G.width,imageHeight:G.height,boxes:c,selectedIndex:p,onSelect:h,onDraw:ie})}),r(`div`,{className:`rounded-md border border-border bg-surface flex flex-col min-h-0`,children:[r(`div`,{className:`px-3 py-2 border-b border-border flex items-center gap-2`,children:[d(`h2`,{className:`text-xs font-semibold text-foreground flex-1`,children:`Subjects`}),r(E,{variant:`secondary`,size:`sm`,disabled:P.isPending,onClick:()=>void U(`objects`),children:[d(Ae,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:`Propose`})]}),r(E,{variant:`secondary`,size:`sm`,disabled:P.isPending,onClick:()=>void U(`package`),children:[d(Ae,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:`Packages`})]})]}),d(`div`,{className:`flex-1 overflow-y-auto`,children:d(Hn,{annotations:c,selectedIndex:p,onSelect:h,onChange:ae,onDelete:W})}),r(`div`,{className:`px-3 py-2 border-t border-border flex items-center justify-between`,children:[r(`span`,{className:`text-[11px] text-foreground-subtle`,children:[c.filter(e=>e.kind===`model_error`).length,` marked as model errors`]}),d(E,{size:`sm`,disabled:!le||F.isPending,onClick:()=>void oe(),children:`Save frame`})]})]})]})]})})]})]})}function or(){return d(`div`,{className:`flex flex-col p-4`,children:d(ze,{tabs:[{id:`feed`,label:`Feed`,icon:Ee,content:d(Rn,{})},{id:`retrain`,label:`Retrain`,icon:Ge,content:d(ar,{})},{id:`debug`,label:`Debug`,icon:Ve,content:d(vt,{})}]})})}export{or as EventsPage};
@@ -1 +0,0 @@
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{Z as c}from"./player-overlays-B308H6FT.js";import{As as l,Cs as u,Dn as d,Ds as f,Es as p,On as m,Os as h,Rt as g,S as _,Ss as v,Ts as y,Vr as b,_s as x,bs as S,f as C,js as w,ks as T,p as E,tt as ee,un as D,vs as te,ws as O,x as k,xs as A,ys as ne}from"./src-CRRfIT-p.js";import{c as j,d as M,l as N,u as P}from"./src-CAbNcnj2.js";import{t as F}from"./circle-check-big-wJc69kBE.js";import{t as re}from"./copy-B89T25pr.js";import{t as ie}from"./key-round-CHpqcY9g.js";import{t as ae}from"./pencil-WK7qCbrF.js";import{t as oe}from"./plus-BA0vJ9nq.js";import{A as I,B as se,D as L,L as ce,T as R,f as z,i as B,q as V,r as H,s as U,u as W,w as G,z as le}from"./index-BJ67e-An.js";import{t as K}from"./AdminPage-CCD07UMs.js";import{t as ue}from"./AdminTabs-Bj4P1GYJ.js";import{t as de}from"./AddonCollectionPage-ZXOrokti.js";import{t as fe}from"./addon-display-names-DvSEQty-.js";var pe=V(`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`}]]),me=V(`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`}]]),he=V(`key`,[[`path`,{d:`m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4`,key:`g0fldk`}],[`path`,{d:`m21 2-9.6 9.6`,key:`1j0ho8`}],[`circle`,{cx:`7.5`,cy:`15.5`,r:`5.5`,key:`yqb3hr`}]]),ge=V(`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=V(`shield-alert`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M12 16h.01`,key:`1drbdi`}]]),ve=V(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]);e();function ye({userId:e,username:n,onClose:r}){let o=a(),c=D(),l=A({userId:e}),u=l.data,d=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),f=S({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(W,{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(G,{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(R,{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(F,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),t(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[s(`div`,{className:`font-medium`,children:`2FA is active`}),t(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,u.confirmedAt?new Date(u.confirmedAt).toLocaleString():`—`]})]})]}),s(`div`,{className:`text-[11px] text-foreground-subtle`,children:`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`}),t(`div`,{className:`flex justify-end gap-2`,children:[s(g,{onClick:r,variant:`secondary`,children:`Close`}),t(`button`,{onClick:async()=>{await c({title:`Remove 2FA`,message:`Remove two-factor authentication for "${n}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,confirmLabel:`Remove`,variant:`danger`})&&f.mutate({userId:e})},disabled:f.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[f.isPending?s(G,{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 be({scopes:e,isAdmin:n,invalidReason:a}){let o=c(),l=r({queryKey:[`auth`,`previewScope`,e,n],enabled:a===null,queryFn:()=>o.trpcClient.auth.previewScope.query({scopes:[...e],isAdmin:n})}),{data:u}=b({}),d=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(_e,{className:`h-3 w-3 shrink-0`}),a]})});if(l.isLoading)return t(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface p-3 text-[11px] text-foreground-subtle`,children:[s(G,{className:`h-3 w-3 animate-spin`}),`Resolving…`]});if(l.isError||!l.data)return s(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:s(`p`,{className:`text-[11px] text-danger`,children:`Could not resolve this grant set. Saving is still allowed — the server enforces the same rules either way.`})});let f=l.data;return s(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-3`,children:f.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:I,label:`Devices they can see`,count:f.device.view.deviceCount,all:f.device.view.all,total:d}),s(q,{icon:ae,label:`Devices they can operate`,count:f.device.create.deviceCount,all:f.device.create.all,total:d}),s(q,{icon:U,label:`Devices they can delete`,count:f.device.delete.deviceCount,all:f.device.delete.all,total:d}),t(`div`,{className:`border-t border-border pt-2 text-[10px] text-foreground-subtle`,children:[`System access: `,f.system.length===0?`none`:f.system.join(`, `),f.capabilities.length>0&&t(i,{children:[` · Extra capabilities: `,f.capabilities.map(e=>e.name).join(`, `)]}),f.addons.length>0&&t(i,{children:[` · Addons: `,f.addons.map(e=>e.name).join(`, `)]})]}),f.device.view.deviceCount===0&&s(`p`,{className:`text-[10px] text-warning`,children:`This user will not be able to see any device.`})]})})}function xe(e){let t=P(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 Se(e){return e.mode===`advanced`?e.advancedScopes:e.roleId===null?[]:N({roleId:e.roleId,selector:e.selector,includeLinked:e.includeLinked})}function Ce({user:e,onClose:r,onSubmit:a,submitting:c,callerScopes:l}){let u=n(()=>xe(e.scopes??[]),[e.scopes]),[d,f]=o(u),[p,m]=o(u.mode===`advanced`),h=n(()=>Se(d),[d]),g=!e.isAdmin&&d.mode===`role`&&d.roleId===null,_=n(()=>e.isAdmin?null:d.mode===`role`&&d.roleId===null?`Pick what this user can do to see the result.`:E(h),[e.isAdmin,d.mode,d.roleId,h]),v=e=>f({...d,...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:[g&&t(`div`,{className:`flex items-start gap-2 rounded-lg border border-warning/40 bg-warning/10 p-3`,children:[s(_e,{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:j.map(e=>{let n=d.mode===`role`&&d.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:()=>v({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(!p){f({...d,mode:`advanced`,advancedScopes:h}),m(!0);return}m(!1),f(xe(d.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(p?le:ce,{className:`h-3 w-3`}),`Advanced — edit raw grants`]}),p&&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(C,{value:d.advancedScopes,onChange:e=>v({mode:`advanced`,advancedScopes:e}),clampToParent:l,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.`]})})]})]}),d.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(k,{value:d.selector,onChange:e=>v({selector:e}),includeLinked:d.includeLinked,onIncludeLinkedChange:e=>v({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:d.mode===`role`?`3 · Result`:`2 · Result`}),s(be,{scopes:h,isAdmin:e.isAdmin,invalidReason:_})]})]}),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([...h]),disabled:c||_!==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:c?s(G,{className:`h-3 w-3 animate-spin`}):`Save access`})]})]})})}e();function we(){let e=a(),{user:n}=H(),[r,i]=o(!1),[c,u]=o(``),[d,f]=o(``),[m,h]=o(!1),[g,_]=o(null),{data:v,isLoading:b,isError:x}=y(),S=D(),C=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),T=te({onSuccess:()=>{C(),i(!1),u(``),f(``),h(!1),_(null)},onError:e=>{_(e instanceof Error?e.message:`Failed to create user`)}}),E=ne({onSuccess:C}),O=w({onSuccess:C}),k=p({onSuccess:C}),A=l({onSuccess:()=>{C(),M(null)}}),[j,M]=o(null),[N,P]=o(null),F=v??[];async function re(e){await S({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`})&&E.mutate({id:e.id})}async function ie(e){let t=window.prompt(`New password for "${e.username}":`);if(t){if(t.length<8){window.alert(`Password must be at least 8 characters.`);return}await S({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&k.mutate({id:e.id,newPassword:t})}}function ae(e,t){t!==e.isAdmin&&O.mutate({id:e.id,isAdmin:t})}function I(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(oe,{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=>u(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:d,onChange:e=>f(e.target.value),placeholder:`••••••••`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),t(`label`,{className:`flex items-center gap-2 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:m,onChange:e=>h(e.target.checked),className:`rounded border-border focus:ring-primary`}),s(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),g&&s(`p`,{className:`text-[10px] text-danger`,children:g}),t(`div`,{className:`flex justify-end gap-2`,children:[s(`button`,{onClick:()=>i(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),s(`button`,{onClick:()=>T.mutate({username:c,password:d,isAdmin:m}),disabled:T.isPending||!c||!d,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:T.isPending?`Creating...`:`Create`})]})]}),b&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),x&&s(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!b&&!x&&F.length===0&&s(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>E.isPending&&E.variables?.id===e.id||O.isPending&&O.variables?.id===e.id||k.isPending&&k.variables?.id===e.id;return s(ee,{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=>ae(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:()=>M(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(z,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(Te,{scopes:e.scopes??[]})]})},{key:`createdAt`,header:`Created`,render:e=>s(`span`,{className:`text-foreground-subtle`,children:I(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:()=>P(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(W,{className:`h-3 w-3`}),`Remove 2FA`]}),t(`button`,{onClick:()=>ie(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Reset password`,children:[s(he,{className:`h-3 w-3`}),`Reset password`]}),t(`button`,{onClick:()=>re(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(G,{className:`h-3 w-3 animate-spin`}):s(U,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:F,rowKey:e=>e.id,minWidthPx:560})})(),N&&s(ye,{userId:N.id,username:N.username,onClose:()=>P(null)}),j&&s(Ee,{user:j,onClose:()=>M(null),onSubmit:e=>A.mutate({userId:j.id,scopes:e}),submitting:A.isPending})]})}function Te({scopes:e}){if(e.length===0)return s(`span`,{className:`font-medium text-warning`,children:`No access`});let n=P(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:M(n.roleId).label}),` ·`,` `,_(n.selector)]})}function Ee(e){let{user:t}=H(),n=t?.isAdmin===!0;return s(Ce,{...e,callerScopes:n?null:t?.scopes??[]})}e();var De=`bg-primary/10 text-primary`,Oe=`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 ke(e){return e?e===`*`?`*`:e.join(`, `):``}function Ae(){let e=a(),r=D(),{data:i,isLoading:c}=v(),{data:l}=y(),u=n(()=>i??[],[i]),d=n(()=>l??[],[l]),p=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),m=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[h,g]=o(!1),[_,b]=o(null),S=f({onSuccess:p}),C=x({onSuccess:({token:e,record:t})=>{m(),g(!1),b({token:e,label:t.name})}}),w=T({onSuccess:m}),E=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`})&&S.mutate({id:e})},ee=async(e,t)=>{await r({title:`Revoke "${t}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&w.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:d.length===0,title:d.length===0?`Create a user first`:`Issue a scoped token`,children:[s(z,{className:`h-3.5 w-3.5`}),`New token`]})]}),t(je,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[d.length===0&&s(Ne,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),d.map(e=>s(Fe,{userId:e.id,username:e.username,onRevoke:(e,t)=>{ee(e,t)},revokePending:w.isPending,revokeId:w.variables?.id},e.id))]}),u.length>0&&s(je,{title:`Legacy API keys`,subtitle:`${u.length} pre-existing — revoke only`,children:s(Pe,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:u.map(e=>{let n=!!e.isAdmin,r=S.isPending&&S.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?De:Oe}`,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:ke(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:()=>{E(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(G,{className:`h-3 w-3 animate-spin`}):s(U,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),c&&s(Me,{}),h&&s(Ie,{users:d.map(e=>({id:e.id,username:e.username})),onClose:()=>g(!1),onSubmit:e=>C.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:C.isPending}),_&&s(Le,{token:_.token,label:_.label,onClose:()=>b(null)})]})}function je({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 Me(){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 Ne({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 Pe({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 Fe({userId:e,username:n,onRevoke:r,revokePending:i,revokeId:a}){let{data:o,isLoading:c}=O({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(Pe,{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`?`[${_(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(G,{className:`h-3 w-3 animate-spin`}):s(U,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function Ie({users:e,onClose:n,onSubmit:r,submitting:i}){let{user:a}=H(),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(``),_=E(p),v=l!==``&&d.trim().length>0&&p.length>0&&_===null&&!i;return t(Re,{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(C,{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(ze,{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(G,{className:`h-3.5 w-3.5 animate-spin`}):s(z,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function Le({token:e,label:n,onClose:r}){let[i,a]=o(!1),c=async()=>{try{await navigator.clipboard.writeText(e),a(!0)}catch{}};return t(Re,{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(ze,{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(se,{className:`h-3.5 w-3.5 text-primary`}):s(re,{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 Re({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 ze({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 Be(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 Ve(){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 He({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 Ue({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 We(){let e=a(),r=D(),{data:i,isLoading:o}=u(),c=n(()=>i??[],[i]),l=h({onSuccess:()=>e.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),d=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:ge,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(Ve,{}),!o&&c.length===0&&s(He,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!o&&c.length>0&&s(Ue,{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:Be(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:()=>{d(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(G,{className:`h-3 w-3 animate-spin`}):s(U,{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 Ge(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:me,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:L,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:L,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:W,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:W,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:z,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Ke(){let e=m({capName:Q[0].capName},{refetchInterval:Z}),t=m({capName:Q[1].capName},{refetchInterval:Z}),r=d(void 0,{refetchInterval:Z}),i=n(()=>fe(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(de,{title:$.title,subtitle:$.subtitle,pageIcon:z,itemIcon:z,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(qe,{addonId:e.addonId})})}function qe({addonId:e}){let n=Ge(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(pe,{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(R,{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 Je(){return s(`div`,{className:`flex flex-col p-4`,children:s(ue,{tabs:[{id:`users`,label:`Users`,icon:ve,content:s(we,{})},{id:`api-keys`,label:`Tokens`,icon:ie,content:s(Ae,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:ge,content:s(We,{})},{id:`authentication`,label:`Authentication`,icon:z,content:s(Ke,{})}]})})}export{Je as IdentityPage};
@@ -1 +0,0 @@
1
- import{x as e}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Y as t}from"./src-CRRfIT-p.js";import{t as n}from"./AdminPage-CCD07UMs.js";function r(){return e(n,{children:e(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:e(t,{limit:500,maxHeight:`max-h-[calc(100vh-250px)]`,showScope:!0,showFilters:!0})})})}export{r as LogsPage};
@@ -1 +0,0 @@
1
- import{K 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{Fr as l,Ha as u,Lr as d,Lt as f,Mt as p,Vr as m,to as h}from"./src-CRRfIT-p.js";import{t as g}from"./zap-LIk0nazc.js";import{C as _,L as v,P as y,a as b,q as x}from"./index-BJ67e-An.js";var S=x(`circuit-board`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M11 9h4a2 2 0 0 0 2-2V3`,key:`1ve2rv`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`M7 21v-4a2 2 0 0 1 2-2h4`,key:`1fwkro`}],[`circle`,{cx:`15`,cy:`15`,r:`2`,key:`3i40o0`}]]),C=x(`layers`,[[`path`,{d:`M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z`,key:`zw3jo`}],[`path`,{d:`M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12`,key:`1wduqc`}],[`path`,{d:`M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17`,key:`kqbvx6`}]]),w=x(`lock-open`,[[`rect`,{width:`18`,height:`11`,x:`3`,y:`11`,rx:`2`,ry:`2`,key:`1w4ew1`}],[`path`,{d:`M7 11V7a5 5 0 0 1 9.9-1`,key:`1mm8w8`}]]),T=x(`minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),E=x(`scale`,[[`path`,{d:`m16 16 3-8 3 8c-.87.65-1.92 1-3 1s-2.13-.35-3-1Z`,key:`7g6ntu`}],[`path`,{d:`m2 16 3-8 3 8c-.87.65-1.92 1-3 1s-2.13-.35-3-1Z`,key:`ijws7r`}],[`path`,{d:`M7 21h10`,key:`1b0cd5`}],[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`M3 7h2c2 0 5-1 7-2 2 1 5 2 7 2h2`,key:`3gwbw2`}]]),D=x(`usb`,[[`circle`,{cx:`10`,cy:`7`,r:`1`,key:`dypaad`}],[`circle`,{cx:`4`,cy:`20`,r:`1`,key:`22iqad`}],[`path`,{d:`M4.7 19.3 19 5`,key:`1enqfc`}],[`path`,{d:`m21 3-3 1 2 2Z`,key:`d3ov82`}],[`path`,{d:`M9.26 7.68 5 12l2 5`,key:`1esawj`}],[`path`,{d:`m10 14 5 2 3.5-3.5`,key:`v8oal5`}],[`path`,{d:`m18 12 1-1 1 1-1 1Z`,key:`1bh22v`}]]);t();function O(e){return m({addonId:e})}function k(e){return d({deviceId:e},{enabled:Number.isFinite(e)})}var A=3e4,j=2e3;function M(t){let n=e(0);return n.current===0&&(n.current=Date.now()),l({parentDeviceId:t},{enabled:Number.isFinite(t),staleTime:0,refetchOnMount:`always`,refetchInterval:e=>{let t=e.state.data;return t&&t.length>0||Date.now()-n.current>=A?!1:j}})}function N(e,t,n){return e.map(e=>{if(e.key===t)return e;let r=e.steps[n];if(!r||r.settings===void 0)return e;let{settings:i,...a}=r,o={...e.steps};return Object.keys(a).length>0?o[n]=a:delete o[n],{...e,steps:o}})}function P(e,t,n){let r=e.filter(e=>e.key!==t).toSorted((e,t)=>e.key.localeCompare(t.key)),i=[...r.filter(e=>!e.enabled),...r.filter(e=>e.enabled),...e.filter(e=>e.key===t)],a;for(let e of i){let t=e.steps[n]?.settings;!t||Object.keys(t).length===0||(a={...a,...t})}return a}function F(e){let t={};for(let n of e){let e=Object.keys(n.steps).length>0;t[n.key]={enabled:n.enabled,weight:Math.max(1,n.weight),...n.maxSessions!==null&&n.maxSessions>0?{maxSessions:n.maxSessions}:{},...e?{steps:n.steps}:{}}}return t}t();function I(e,t,n){return Math.min(Math.max(e,t),n)}function L(e){let t=e.reduce((e,t)=>e+Math.max(t.weight,0),0);if(t<=0){let t=e.length>0?100/e.length:0;return Object.fromEntries(e.map(e=>[e.id,t]))}return Object.fromEntries(e.map(e=>[e.id,Math.max(e.weight,0)/t*100]))}function R(e,t,n,r,i){let a=i.filter(e=>e!==t&&r.has(e)).reduce((t,n)=>t+Math.max(e[n]??0,0),0),o=Math.max(0,100-a),s=i.filter(e=>e!==t&&!r.has(e)),c=s.length===0?o:I(n,0,o),l={...e,[t]:c};if(s.length>0){let e=Math.max(0,o-c)/s.length;for(let t of s)l[t]=e}return l}function z(e,t,n){let r={},i=0,a=[];for(let o of t){let t=Math.max(e[o]??0,0);if(n.has(o)){let e=Math.round(t);r[o]=e,i+=e}else{let e=Math.floor(t);r[o]=e,a.push({id:o,floor:e,frac:t-e})}}let o=Math.max(0,100-i)-a.reduce((e,t)=>e+t.floor,0),s=[...a].sort((e,t)=>t.frac-e.frac);for(let e=0;o>0&&s.length>0;e+=1)r[s[e%s.length].id]+=1,--o;let c=[...a].sort((e,t)=>e.frac-t.frac);for(let e=0;o<0&&c.length>0;e+=1){let t=c[e%c.length].id;r[t]>0&&(--r[t],o+=1)}return r}function B({nodes:e,pending:t,onCommitWeights:r,weightLabel:a=`Detection weight`,emptyHint:l,footnote:u}){let[d,f]=o(()=>L(e)),[p,m]=o(new Set);c(()=>{f(L(e)),m(t=>new Set([...t].filter(t=>e.some(e=>e.id===t))))},[e.map(e=>`${e.id}:${e.weight}`).join(`|`)]);let h=e.map(e=>e.id),g=e=>{m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},v=(e,t)=>{f(n=>R(n,e,t,p,h))},y=()=>{let t=z(d,h,p),n=e.filter(e=>(t[e.id]??0)!==e.weight).map(e=>e.id);if(n.length===0)return;let i=new Set([...n,...p]);r(e.filter(e=>i.has(e.id)).map(e=>({nodeId:e.id,weight:t[e.id]??0})))};if(e.length===0)return s(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:l??`No detect-enabled nodes. Enable “Detect” on a node above to distribute detection weight.`});let b=e.length===1;return n(`div`,{className:`space-y-3`,children:[e.map(e=>{let r=d[e.id]??0,i=p.has(e.id);return n(`div`,{className:`flex items-center gap-3`,children:[s(`span`,{className:`w-28 shrink-0 truncate text-xs font-medium text-foreground`,title:e.name,children:e.name}),s(`input`,{"aria-label":`${a} for ${e.name}`,type:`range`,min:0,max:100,step:1,value:Math.round(r),disabled:t||i||b,onChange:t=>v(e.id,Number(t.target.value)),onPointerUp:()=>y(),onKeyUp:()=>y(),className:`h-1.5 flex-1 cursor-pointer accent-primary disabled:cursor-not-allowed disabled:opacity-50`}),n(`span`,{className:`w-10 shrink-0 text-right font-mono text-xs tabular-nums text-foreground`,children:[Math.round(r),`%`]}),s(`button`,{type:`button`,onClick:()=>g(e.id),disabled:t||b,"aria-pressed":i,title:i?`Unlock — allow rebalancing`:`Lock this share when others change`,className:`shrink-0 rounded p-1 hover:bg-surface-hover disabled:opacity-40 ${i?`text-amber-400`:`text-foreground-subtle`}`,children:s(i?_:w,{className:`h-3.5 w-3.5`})})]},e.id)}),s(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:u??s(i,{children:`Dragging one slider splits the rest equally across the unlocked nodes; lock a node to pin its share — locked nodes never move and the total always stays at 100%, so a drag is bounded by the room the unlocked nodes leave. Detection only distributes across nodes that can source a camera’s frames.`})})]})}t();function V(e){let t=e.backend.toLowerCase(),n=e.device.toLowerCase();return e.key===`cpu`||n===`cpu`?{label:`CPU`,Icon:y,hue:`slate`}:t===`openvino`&&n===`npu`?{label:`Intel NPU (AI Boost)`,Icon:g,hue:`sky`}:t===`openvino`&&(n===`gpu`||n===`igpu`)?{label:`Intel iGPU`,Icon:S,hue:`violet`}:t===`edgetpu`?{label:`Coral Edge TPU`,Icon:D,hue:`emerald`}:{label:`${e.backend} ${e.device}`.replace(/\b\w/g,e=>e.toUpperCase()).trim(),Icon:y,hue:`slate`}}var H={sky:`bg-sky-500/12 text-sky-400 ring-sky-500/25`,violet:`bg-violet-500/12 text-violet-400 ring-violet-500/25`,emerald:`bg-emerald-500/12 text-emerald-400 ring-emerald-500/25`,slate:`bg-surface-hover text-foreground-subtle ring-border`};function U({nodeId:e,nodeName:t,isOnline:l}){let d=a(),{data:m,isLoading:g}=u({nodeId:e},{refetchInterval:15e3}),_=h({onSettled:()=>{d.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),y=m?.devices??[],x=m?.reachable??l,[S,w]=o({});c(()=>{w(Object.fromEntries(y.map(e=>[e.key,{enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}])))},[y.map(e=>`${e.key}:${e.enabled}:${e.weight}:${e.maxSessions}:${JSON.stringify(e.steps??{})}`).join(`|`)]);let T=r(()=>y.filter(e=>S[e.key]?.enabled??e.enabled).length,[y,S]),[D,O]=o(null),k=D??T>0,A=t=>{let n=y.map(e=>{let n=t[e.key]??j(e);return{key:e.key,enabled:n.enabled,weight:n.weight,maxSessions:n.maxSessions,steps:n.steps}});_.mutate({agentNodeId:e,inferenceDevices:F(n)})},j=e=>({enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}),M=e=>{if(!e.available)return;let t=S[e.key]??j(e),n={...S,[e.key]:{...t,enabled:!t.enabled}};w(n),A(n)},N=(e,t)=>{let n=S[e.key]??j(e),r={...S,[e.key]:{...n,maxSessions:t}};w(r),A(r)},P=r(()=>y.filter(e=>(S[e.key]?.enabled??e.enabled)&&e.available),[y,S]),I=r(()=>P.map(e=>({id:e.key,name:V(e).label,weight:S[e.key]?.weight??e.weight})),[P,S]);return n(`div`,{className:`rounded-lg border border-border bg-surface/60`,children:[n(`button`,{type:`button`,onClick:()=>O(!k),className:`flex w-full items-center gap-2.5 px-3.5 py-2.5 text-left`,"aria-expanded":k,children:[s(v,{className:`h-4 w-4 shrink-0 text-foreground-subtle transition-transform ${k?`rotate-90`:``}`}),s(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t}),s(`span`,{className:`ml-auto flex items-center gap-2 text-[11px]`,children:x?T>=2?n(`span`,{className:`inline-flex items-center gap-1 text-emerald-400`,children:[s(C,{className:`h-3.5 w-3.5`}),T,` accelerators`]}):T===1?s(`span`,{className:`text-foreground-subtle`,children:`single default`}):s(`span`,{className:`text-foreground-subtle/70`,children:`auto default`}):n(`span`,{className:`inline-flex items-center gap-1 text-foreground-subtle`,children:[s(b,{className:`h-3.5 w-3.5`}),` unreachable`]})})]}),k&&n(`div`,{className:`space-y-3 border-t border-border px-3.5 py-3`,children:[x?g&&y.length===0?s(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`Probing accelerators…`}):y.length===0?s(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No inference devices reported by this node's platform probe.`}):s(`ul`,{className:`space-y-2`,children:y.map(e=>{let t=V(e),r=S[e.key]??j(e),a=r.enabled&&e.available;return n(`li`,{className:`flex items-center gap-3 rounded-lg border px-3 py-2.5 transition-colors ${e.available?a?`border-primary/40 bg-primary/[0.04] ring-1 ring-inset ring-primary/20`:`border-border bg-surface`:`border-border/60 bg-background opacity-55`}`,children:[s(`span`,{className:`grid h-9 w-9 shrink-0 place-items-center rounded-md ring-1 ring-inset ${H[t.hue]}`,children:s(t.Icon,{className:`h-4.5 w-4.5`})}),n(`div`,{className:`min-w-0 flex-1`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t.label}),s(f,{variant:`default`,style:`outline`,className:`font-mono text-[9px]`,children:e.format}),!e.available&&s(f,{variant:`warning`,className:`text-[9px]`,children:`unavailable`})]}),n(`div`,{className:`mt-0.5 flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[s(`span`,{className:`font-mono`,children:e.key}),!a&&n(i,{children:[s(`span`,{"aria-hidden":!0,children:`·`}),n(`span`,{children:[`default model`,` `,s(`span`,{className:`font-mono text-foreground/80`,children:e.defaultModelId})]})]})]})]}),a&&n(`label`,{className:`flex shrink-0 items-center gap-1 text-[10px] text-foreground-subtle`,children:[s(`span`,{className:`hidden @sm/clustertab:inline`,children:`cap`}),s(`input`,{type:`number`,min:1,placeholder:`∞`,value:r.maxSessions??``,onChange:t=>{let n=t.target.value.trim(),r=n===``?null:Number.parseInt(n,10);N(e,r!=null&&r>0?r:null)},disabled:_.isPending,"aria-label":`Max concurrent sessions for ${t.label}`,className:`w-14 rounded border border-border bg-background px-1.5 py-1 text-right font-mono text-[11px] text-foreground focus:border-primary focus:outline-none`})]}),s(p,{checked:a,onCheckedChange:()=>M(e),disabled:!e.available||_.isPending,"aria-label":`Enable ${t.label}`,className:e.available?``:`cursor-not-allowed opacity-50`})]},e.key)})}):s(W,{}),x&&P.length>=2&&n(`div`,{className:`space-y-3 rounded-lg border border-border bg-background/60 p-3.5`,children:[n(`h4`,{className:`flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:[s(E,{className:`h-3.5 w-3.5`}),`Balancer weight`]}),s(B,{nodes:I,pending:_.isPending,onCommitWeights:e=>{let t={...S};for(let n of e){let e=t[n.nodeId];e&&(t[n.nodeId]={...e,weight:n.weight})}w(t),A(t)},weightLabel:`Balancer weight`,footnote:s(i,{children:`Drag to shift the share of detection sessions each accelerator handles; lock one to pin its share while the others rebalance. Shares always sum to 100%.`})})]}),_.isError&&n(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px] text-danger`,children:[`Failed to save inference devices:`,` `,_.error instanceof Error?_.error.message:`unknown error`]})]})]})}function W(){return n(`div`,{className:`flex flex-col items-center gap-2 rounded-lg border border-dashed border-border bg-background px-4 py-8 text-center`,children:[s(b,{className:`h-6 w-6 text-foreground-subtle/60`}),s(`p`,{className:`text-xs font-medium text-foreground`,children:`Node unreachable`}),s(`p`,{className:`max-w-sm text-[11px] text-foreground-subtle`,children:`The platform probe couldn't be reached, so its live accelerator set is unavailable. Settings resume once the node reconnects.`})]})}export{P as a,M as c,C as d,F as i,O as l,V as n,N as o,B as r,k as s,U as t,T as u};