@camstack/addon-admin-ui 1.2.145 → 1.2.146

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-B0XgVUkl.js → AddLocationWizard-B_v3_-q2.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-BSXsNPWa.js → AddonCollectionPage-BKxMCdfj.js} +1 -1
  3. package/dist/assets/{Addons-BuR_C0eS.js → Addons-uo-RnQb3.js} +1 -1
  4. package/dist/assets/{AdminTabs-C0Wy66CI.js → AdminTabs-BNDJF9Qn.js} +1 -1
  5. package/dist/assets/AiProfiles-CwYSHcVy.js +3 -0
  6. package/dist/assets/{BrokerForm-BX6AttuI.js → BrokerForm-BB4pqG0G.js} +1 -1
  7. package/dist/assets/{Build-Dvqt9QDv.js → Build-CHk_Yjpz.js} +4 -4
  8. package/dist/assets/{Capabilities-BZFqFApr.js → Capabilities-B_huMwwS.js} +1 -1
  9. package/dist/assets/{CapabilityBadges-DHiglzcF.js → CapabilityBadges-CqcESV5N.js} +1 -1
  10. package/dist/assets/Cluster-B3kYCIoc.js +11 -0
  11. package/dist/assets/{Data-HKGuihDf.js → Data-JYE2Pixe.js} +1 -1
  12. package/dist/assets/DetectionIntelligence-BGa9dVKw.js +1 -0
  13. package/dist/assets/{DeviceAggregateSection-CcX4k8-q.js → DeviceAggregateSection-C81XukSC.js} +1 -1
  14. package/dist/assets/DeviceDetail-BsO0DSEO.js +2 -0
  15. package/dist/assets/{Devices-ZO32PCtE.js → Devices-dTqer6hB.js} +1 -1
  16. package/dist/assets/{EmbedPlayerPage-Br-4Lr5p.js → EmbedPlayerPage-D9NnUYQI.js} +1 -1
  17. package/dist/assets/Events-BrM610Rd.js +1 -0
  18. package/dist/assets/{FormBuilder-_6fIxweR.js → FormBuilder-CdyTwa-f.js} +1 -1
  19. package/dist/assets/Identity-BDEnepFx.js +1 -0
  20. package/dist/assets/IntegrationDetail-Bz70mdcB.js +1 -0
  21. package/dist/assets/{Integrations-cAbw0w85.js → Integrations-BORpNJ6d.js} +1 -1
  22. package/dist/assets/Integrations-znA53TWE.js +1 -0
  23. package/dist/assets/{Locations-BlIhXPkH.js → Locations-BhX67xof.js} +1 -1
  24. package/dist/assets/{Logs-DG5UAAGL.js → Logs-DIj2eWr2.js} +1 -1
  25. package/dist/assets/{MyAccess-BI1Sl1bS.js → MyAccess--_A4pycf.js} +1 -1
  26. package/dist/assets/Network-DYFcvZ3K.js +1 -0
  27. package/dist/assets/{NodeAddonsSettingsPanel-D95kz9WA.js → NodeAddonsSettingsPanel-JZ7DosK5.js} +1 -1
  28. package/dist/assets/{NodeInferenceDevices-nT7Ymhdz.js → NodeInferenceDevices-DP0WhV9a.js} +1 -1
  29. package/dist/assets/{Notifications-DIwIuSpC.js → Notifications-BVYK1yfk.js} +1 -1
  30. package/dist/assets/Pipeline-h4cFYMMd.js +1 -0
  31. package/dist/assets/{Plates-B2JnhZCt.js → Plates-CBnNiDE_.js} +1 -1
  32. package/dist/assets/{ProviderIcon-1oq0Ms1x.js → ProviderIcon-Gh81TA-Z.js} +1 -1
  33. package/dist/assets/{Recordings-DSzP9BG1.js → Recordings-DAcoiK8h.js} +1 -1
  34. package/dist/assets/{ScanNetworkModal-Cq19W7kZ.js → ScanNetworkModal-DfuRqIQ1.js} +1 -1
  35. package/dist/assets/{Scenes-_-20SYul.js → Scenes-Di_VW2Uj.js} +1 -1
  36. package/dist/assets/{Settings-BVDU_Zky.js → Settings-Ck6vQm1B.js} +1 -1
  37. package/dist/assets/{Showroom-B7Rclfaz.js → Showroom-BOIQu6VJ.js} +1 -1
  38. package/dist/assets/{StorageLocationsPanel-C4G571sM.js → StorageLocationsPanel-DGutC7NG.js} +1 -1
  39. package/dist/assets/{Terminal-CSI1IFCJ.js → Terminal-CZ42jdz0.js} +3 -3
  40. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host--4aBBHE7.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BAfRTUSv.js} +1 -1
  41. package/dist/assets/{bell-off-D_75Utqd.js → bell-off-izzu8rxR.js} +1 -1
  42. package/dist/assets/{bell-ring-DnD47Mx3.js → bell-ring-Bm35nOdv.js} +1 -1
  43. package/dist/assets/{boxes-AZJJIRLF.js → boxes-DXGdoPql.js} +1 -1
  44. package/dist/assets/circle-check-big-DjHf7fE7.js +1 -0
  45. package/dist/assets/circle-dot-Dufzdrcn.js +1 -0
  46. package/dist/assets/circle-slash-CKURZHPb.js +1 -0
  47. package/dist/assets/{circle-x-B2sS9Wtz.js → circle-x-VB610_7n.js} +1 -1
  48. package/dist/assets/clock-Dr8e-kwq.js +1 -0
  49. package/dist/assets/{copy-F3szhd3t.js → copy-YZzoU3uu.js} +1 -1
  50. package/dist/assets/{debounced-invalidate-Y2LajOxM.js → debounced-invalidate-JPE7iG0t.js} +1 -1
  51. package/dist/assets/{download-DnqiWXDn.js → download-BK0s6UmU.js} +1 -1
  52. package/dist/assets/{face-bbox-BYxYON7A.js → face-bbox-C6vTaB7Y.js} +1 -1
  53. package/dist/assets/{flame-DbNaCnop.js → flame-DRRhw5IG.js} +1 -1
  54. package/dist/assets/{hard-drive-DmXRXyph.js → hard-drive-DM5xIiWQ.js} +1 -1
  55. package/dist/assets/{hard-drive-download-BsqsPikG.js → hard-drive-download-RFNMjzeA.js} +1 -1
  56. package/dist/assets/{hostInit-DlqdjGgg.js → hostInit-C0TVXYps.js} +1 -1
  57. package/dist/assets/{index-CTFcrmzA.js → index-3RAAt2lz.js} +3 -3
  58. package/dist/assets/{key-round-C0iKExnu.js → key-round-BmmrFRdW.js} +1 -1
  59. package/dist/assets/{layers-DuXbonTl.js → layers-CSts6k97.js} +1 -1
  60. package/dist/assets/{mf-entry-bootstrap-0-8829f80e.js → mf-entry-bootstrap-0-e27c9b2e.js} +2 -2
  61. package/dist/assets/{pencil-BgaAECPD.js → pencil-qkG_UFdV.js} +1 -1
  62. package/dist/assets/play-BxoAm3NC.js +1 -0
  63. package/dist/assets/plus-CnlB1Aqy.js +1 -0
  64. package/dist/assets/power-B0FRkm1q.js +1 -0
  65. package/dist/assets/{radio-ArS_Bync.js → radio-1O0-Z2DG.js} +1 -1
  66. package/dist/assets/{refresh-cw-DC4HHe02.js → refresh-cw-a5xmeoSl.js} +1 -1
  67. package/dist/assets/remoteEntry-MVkKhglR.js +1 -0
  68. package/dist/assets/rotate-ccw-BQzqeXJ8.js +1 -0
  69. package/dist/assets/rotate-cw-d4a6cNsY.js +1 -0
  70. package/dist/assets/{send-CdJJqhYS.js → send-CiizG9DW.js} +1 -1
  71. package/dist/assets/{server-Dg0FD7ES.js → server-Cf1umSmF.js} +1 -1
  72. package/dist/assets/{shield-HNSKTw2D.js → shield-B5o0xe8e.js} +1 -1
  73. package/dist/assets/{shield-alert-B11i706j.js → shield-alert-Yj35LrcX.js} +1 -1
  74. package/dist/assets/square-C0i7ZjCv.js +1 -0
  75. package/dist/assets/{square-check-big-mN6bZ6kq.js → square-check-big-Dyo1ii-M.js} +1 -1
  76. package/dist/assets/{src-Do9J_PcR.js → src-BA0oAiLX.js} +8 -8
  77. package/dist/assets/{undo-2-DpekImhR.js → undo-2-xsXq3X0T.js} +1 -1
  78. package/dist/assets/{use-scenes-feed-vgguqKGz.js → use-scenes-feed-D6reBy5v.js} +1 -1
  79. package/dist/assets/useEventInvalidation-BuBQ0kxe.js +1 -0
  80. package/dist/assets/{useNodeUrlSelection-DfIsku0v.js → useNodeUrlSelection-Cv4VeXrh.js} +1 -1
  81. package/dist/assets/user-round-DX2RUHxm.js +1 -0
  82. package/dist/assets/{video-CE7WfIFH.js → video-igi5FReX.js} +1 -1
  83. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CX_CfTzi.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-ff2kl65X.js} +2 -2
  84. package/dist/assets/{wifi-CBHL4Gpd.js → wifi-BJ3H0SaI.js} +1 -1
  85. package/dist/assets/{zap-D2opssTE.js → zap-B_V9qFsO.js} +1 -1
  86. package/dist/index.html +3 -3
  87. package/dist/server/addon.js +1 -1
  88. package/package.json +1 -1
  89. package/dist/assets/AiProfiles-CTUs9OUv.js +0 -3
  90. package/dist/assets/Cluster-Buhi663h.js +0 -11
  91. package/dist/assets/DetectionIntelligence-4_rkKgKo.js +0 -1
  92. package/dist/assets/DeviceDetail-CNnpYgHT.js +0 -2
  93. package/dist/assets/Events-C6OKlkgI.js +0 -1
  94. package/dist/assets/Identity-CmfXPJLx.js +0 -1
  95. package/dist/assets/IntegrationDetail-Dmvg9eDV.js +0 -1
  96. package/dist/assets/Integrations-D1uPIHQm.js +0 -1
  97. package/dist/assets/Network-vElzsaIZ.js +0 -1
  98. package/dist/assets/Pipeline-ClqwksTd.js +0 -1
  99. package/dist/assets/circle-check-big-B9ac961J.js +0 -1
  100. package/dist/assets/circle-dot-086oHDQt.js +0 -1
  101. package/dist/assets/circle-slash-DjQFaxAz.js +0 -1
  102. package/dist/assets/clock-8Zcz1IDK.js +0 -1
  103. package/dist/assets/play-Bj2uDa-E.js +0 -1
  104. package/dist/assets/plus-VwU2KiHj.js +0 -1
  105. package/dist/assets/power-B91QD9GW.js +0 -1
  106. package/dist/assets/remoteEntry-Dv92zYK0.js +0 -1
  107. package/dist/assets/rotate-ccw-DMm-mk2i.js +0 -1
  108. package/dist/assets/rotate-cw-Bg20q2cx.js +0 -1
  109. package/dist/assets/square-DOxz21cx.js +0 -1
  110. package/dist/assets/useEventInvalidation-DL8D3OJq.js +0 -1
  111. package/dist/assets/user-round-FOv66iz2.js +0 -1
@@ -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,o as c,q as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Q as f}from"./player-overlays-Bjt3KKaE.js";import{Aa as p,An as m,Ca as h,Da as g,Dt as _,Ea as v,Ft as y,It as b,Kr as x,Lt as S,Ma as C,Na as w,Pt as T,Qs as E,Rt as D,Ta as O,Tt as k,Xt as A,ba as j,fn as M,ga as N,ha as P,j as F,ja as I,ka as ee,na as L,pa as R,pn as z,qs as te,va as B,wa as ne,xa as V,ya as H}from"./src-Do9J_PcR.js";import{Ut as re,st as U}from"./src-Dz-5lByR.js";import{t as W}from"./clock-8Zcz1IDK.js";import{t as ie}from"./copy-F3szhd3t.js";import{t as ae}from"./download-DnqiWXDn.js";import{a as oe,c as se,d as ce,f as le,i as ue,m as de,n as fe,o as pe,p as me,r as he,s as ge,t as _e}from"./debounced-invalidate-Y2LajOxM.js";import{t as ve}from"./refresh-cw-DC4HHe02.js";import{t as ye}from"./square-check-big-mN6bZ6kq.js";import{t as be}from"./square-DOxz21cx.js";import{t as xe}from"./undo-2-DpekImhR.js";import{B as Se,F as Ce,J as G,L as we,c as Te,k as Ee,o as De,p as Oe,q as ke,r as Ae,t as je,w as K,z as Me}from"./index-CTFcrmzA.js";import{t as Ne}from"./AdminPage-CCD07UMs.js";import{i as Pe,n as Fe,t as Ie}from"./authed-media-BPd_L9jr.js";import{t as Le}from"./AdminTabs-C0Wy66CI.js";var Re=G(`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`}]]),ze=G(`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`}]]),Be=G(`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`}]]),Ve=G(`circle`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),He=G(`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`}]]),Ue=G(`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`}]]),We=G(`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`}]]),Ge=G(`star`,[[`path`,{d:`M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z`,key:`r04s7s`}]]),Ke=G(`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();function qe(e){return e.subLabel??e.label}var Je=720*60*60*1e3;function Ye(e){let t=[];for(let n of e)t.push(...n);return t}function Xe(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function Ze(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 Qe(e,t){return`${String(e)}:${t}`}function $e(e,t){let n=new Map,r=new Set;for(let i of e){let e=Qe(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-Je,until:e.toMs??t}}var tt=[`native`,`raster`,`standin`];function nt(e){return tt.some(t=>t===e)}var rt={standin:{label:`stand-in`,title:`Stand-in: this tile is a face or plate detail crop copied in because no frame of the subject was captured. It is not a best shot.`,tone:`warning`},raster:{label:`low-res`,title:`Raster crop: a sub-native cut of the subject, not a native capture. Honest, but lower resolution than a best shot.`,tone:`info`}};function it(e){return e===`standin`?rt.standin:e===`raster`?rt.raster:null}var at={"no-key-frame":`No key frame existed at close, so no native tile could be cut.`,"no-best-seen-bbox":`No subject box was ever recorded, so there was nothing to cut around.`,"derive-returned-null":`The close-time crop was attempted and produced nothing.`,"derive-threw":`The close-time crop failed with an error.`,"derive-not-wired":`No close-time crop was wired on this node.`,"no-media-store":`The node was shutting down mid-close.`,"no-thumbnail":`The track closed with no tile of any kind.`,"standin-tile":`The track closed with a detail crop standing in for the subject.`,"raster-tile":`The track closed with a sub-native raster crop of the subject.`,"native-tile":`The track closed with a native tile.`};function ot(e){if(e===void 0)return null;let t=e.trim();if(t.length===0)return null;let n=t.split(/\s+/),r=n[0]??t,i=[];for(let e of n.slice(1)){let t=e.indexOf(`=`);t===-1?i.push({key:e,value:null}):i.push({key:e.slice(0,t),value:e.slice(t+1)})}return{sentence:at[r]??r,detail:i,raw:t}}function st(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 ct({row:e,cameraName:t,nowMs:n,onOpenDetail:i,selected:a=!1,onToggleSelect:o,score:s,provenance:c,footer:l}){let d=Pe(e.bestEventId?`${Ie}/${e.bestEventId}`:void 0),f=Math.round(e.importance*100),p=s===void 0?void 0:Math.round(s*100),m=st(e.windowMs),h=()=>i(e),g=it(c);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:[d.src?u(`img`,{src:d.src,alt:`Event from ${t}`,onClick:h,className:`h-full w-full cursor-zoom-in object-cover`}):u(`button`,{type:`button`,onClick:h,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-surface-hover text-foreground-subtle`,title:d.failed?`Key-event media unavailable`:`No key-event media`,children:u(de,{className:`h-6 w-6 opacity-60`})}),o&&u(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(Qe(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?u(ye,{className:`h-4 w-4 text-primary`}):u(be,{className:`h-4 w-4`})}),p!==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(p),`%`]}),f>0&&u(`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(f)}),g!==null&&u(`span`,{className:`absolute bottom-1 right-1 z-10 rounded px-1.5 py-0.5 text-[10px] font-semibold text-white ${g.tone===`warning`?`bg-warning/90`:`bg-black/70`}`,title:g.title,children:g.label}),(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&&u(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:`Marked for training`,"aria-label":`Marked for training`,children:u(Ue,{className:`h-3 w-3`})}),e.debug===!0&&u(`span`,{className:`rounded bg-black/70 p-0.5 text-white`,title:`Flagged for debug`,"aria-label":`Flagged for debug`,children:u(ze,{className:`h-3 w-3`})}),e.favourited===!0&&u(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:`Favourited`,"aria-label":`Favourited`,children:u(Ge,{className:`h-3 w-3`})})]})]}),r(`button`,{type:`button`,onClick:h,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,qe(e)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,qe(e)]}):null]}),u(`p`,{className:`text-[10px] text-foreground-subtle truncate`,title:t,children:t}),r(`div`,{className:`flex items-center justify-between gap-2`,children:[u(`span`,{className:`text-[10px] text-foreground-subtle truncate`,children:le(e.timestamp,n)}),m&&u(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:m})]})]}),l!==void 0&&u(`div`,{className:`px-2 pb-1.5`,children:l})]})}var lt=1400,ut=`Admin-gated URL — opens only inside an authenticated session`;function dt({label:t,value:n,title:i}){let[a,o]=l(!1);return d(()=>{if(!a)return;let e=setTimeout(()=>o(!1),lt);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:[u(a?Se:ie,{className:`h-2.5 w-2.5 shrink-0`}),u(`span`,{className:`truncate`,children:a?`Copied`:t})]})}function ft({localUrl:e,publicUrl:t}){return r(`div`,{className:`flex flex-wrap gap-1`,children:[u(dt,{label:`Local`,value:e,title:`Copy LAN URL — ${ut}`}),t&&u(dt,{label:`Public`,value:t,title:`Copy public URL — ${ut}`})]})}var pt={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`,sceneFrame:`Scene frame (clean, retired)`};function mt(e){return e in pt}function ht(e){return mt(e)?pt[e]:e}function gt(e,t){return`${e}${Ie}/${encodeURIComponent(t)}`}n();var _t=3e4;function vt(t){let[n,r]=l(null),i=e(e=>{r(t=>t??e)},[]);return d(()=>{t||r(null)},[t]),{publicOrigin:n,probes:t?u(yt,{onOrigin:i}):null}}function yt({onOrigin:e}){let{data:t}=m({capName:`network-access`});return u(s,{children:(t??[]).map(t=>u(bt,{addonId:t.addonId,onOrigin:e},t.addonId))})}function bt({addonId:e,onOrigin:t}){let{data:n}=L({addonId:e},{refetchInterval:_t,retry:!1});return d(()=>{let e=n?U.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 q=typeof w==`function`,xt=`Track flags arrive with the next server update`;function St(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var Ct=q?w:St;function wt(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 Tt({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:[u(`span`,{className:n?`text-primary`:`text-foreground-subtle`,children:o}),r(`span`,{className:`min-w-0 flex-1`,children:[u(`span`,{className:`block text-[11px] font-medium text-foreground`,children:e}),u(`span`,{className:`block text-[10px] text-foreground-subtle`,children:t})]}),u(`span`,{"aria-hidden":`true`,className:`h-4 w-7 shrink-0 rounded-full p-0.5 transition-colors ${n?`bg-primary`:`bg-border`}`,children:u(`span`,{className:`block h-3 w-3 rounded-full bg-white transition-transform ${n?`translate-x-3`:``}`})})]})}function Et({deviceId:e,trackId:t,markForTrain:n,debug:i,favourited:a,onChange:o}){let s=Ct(),[c,d]=l(null),f=c?.markForTrain??n===!0,p=c?.debug??i===!0,m=c?.favourited??a===!0,h=!q||s.isPending,g=q?void 0:xt,_=n=>{h||(async()=>{try{let r=wt(await s.mutateAsync({deviceId:e,trackId:t,flags:n}));if(!r)return;d(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:[u(Tt,{label:`Mark for training`,hint:`Keeps this track and its media past retention`,checked:f,disabled:h,...g===void 0?{}:{title:g},icon:u(Ue,{className:`h-4 w-4`}),onToggle:()=>_({markForTrain:!f})}),u(Tt,{label:`Debug`,hint:`Flag this track for diagnostic attention`,checked:p,disabled:h,...g===void 0?{}:{title:g},icon:u(ze,{className:`h-4 w-4`}),onToggle:()=>_({debug:!p})}),u(Tt,{label:`Favourited`,hint:`Keeps this track and its media past retention`,checked:m,disabled:h,...g===void 0?{}:{title:g},icon:u(Ge,{className:`h-4 w-4`}),onToggle:()=>_({favourited:!m})})]})}var J=100,Dt=120,Ot={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Y=e=>e<0?0:e>1?1:e,X=e=>Math.round(e*100)/100;function kt(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 At(e,t,n){if(e.length===0||t===null)return Ot;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return Ot;let a=kt(e,n?.maxPoints??Dt).map(e=>({x:X(Y(e.x/r)*J),y:X(Y(e.y/i)*J)})),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:X(Y(e.x/r)*J),y:X(Y(e.y/i)*J),mediaKey:e.mediaKey})),u=null,d=-1;for(let t of e){let e=Y(t.bbox.w/r)*Y(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:X(Y(u.bbox.x/r)*J),y:X(Y(u.bbox.y/i)*J),w:X(Y(u.bbox.w/r)*J),h:X(Y(u.bbox.h/i)*J)}:null}}var jt=typeof P==`function`,Mt=`Track deletion arrives with the next server update`;function Nt(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var Pt=jt?P:Nt;n();var Ft=15e3;function It(e){return`${Ie}/${encodeURIComponent(e)}`}var Lt=window.location.origin;function Rt({mediaKey:e,label:t}){let{src:n,failed:r}=Pe(It(e));return n===null?u(`div`,{className:`flex h-full w-full items-center justify-center bg-surface-hover`,children:r?u(de,{className:`h-4 w-4 text-foreground-subtle opacity-60`}):u(K,{className:`h-4 w-4 animate-spin text-foreground-subtle opacity-70`})}):u(`img`,{src:n,alt:t,className:`h-full w-full object-cover`})}var zt=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),Bt=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]);function Vt(e){let[t,n]=l(null);return d(()=>{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 Ht({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&&u(`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&&u(`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)=>u(`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)=>u(`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:u(`title`,{children:`Snapshot checkpoint — click to view this frame`})},`snap-${e.mediaKey}-${String(n)}`)),e.start&&u(`circle`,{cx:e.start.x,cy:e.start.y,r:2.4,fill:`#22c55e`,stroke:`#052e16`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`}),e.end&&u(`circle`,{cx:e.end.x,cy:e.end.y,r:2.4,fill:`#ef4444`,stroke:`#450a0a`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`})]})}function Z({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:[u(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),u(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono text-[11px]`:``}`,title:t,children:t})]})}function Ut({row:t,cameraName:n,deleteAvailable:i,onClose:o,onDeleted:c,onFlagsChanged:p}){let m=f(),h=Pt(),g=t!==null,y=t?.deviceId??0,b=t?.trackId??``,x=t?.bestEventId??``,S=t?.timestamp??0,C=t?.windowMs??0,{data:w}=H({deviceId:y,trackId:b},{enabled:g}),{data:T}=v({trackId:b,deviceId:y},{enabled:g}),{data:E}=V({eventId:x,deviceId:y},{enabled:g&&x!==``}),{data:O}=te({deviceId:y,since:S-Ft,until:S+C+Ft},{enabled:g}),[A,j]=l(null),[M,N]=l(!1),{publicOrigin:P,probes:F}=vt(g);d(()=>{j(null)},[y,b]);let I=a(()=>{let e=T??[],t=E??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[T,E]),ee=A??I,L=Pe(ee?It(ee.key):void 0),R=a(()=>{let e=new Set,t=[];for(let n of[...E??[],...T??[]])n.key===``||e.has(n.key)||(e.add(n.key),t.push(n));return t},[E,T]),z=a(()=>R.find(e=>zt.has(e.kind))??null,[R]),B=Vt(Pe(z?It(z.key):void 0).src),ne=a(()=>At(w?.positions??[],B,{snapshots:(w?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaKey:e.mediaKey}))}),[w?.positions,w?.snapshots,B]),re=e(e=>{let t=R.find(t=>t.key===e);t&&j(t)},[R]);if(t===null)return null;let U=L.src,W=ee?.kind,ie=W!==void 0&&Bt.has(W)&&B!==null&&(w?.positions.length??0)>=2,ae=O&&O.length>0?O[0]:null,oe=()=>{ae&&(N(!0),(async()=>{try{let e=await m.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:ae.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{window.alert(`Could not resolve clip playback. Check the server logs.`)}finally{N(!1)}})())},se=()=>{!i||h.isPending||window.confirm(`Delete this track and all its media? This cannot be undone.`)&&(async()=>{try{await h.mutateAsync({deviceId:t.deviceId,trackIds:[t.trackId]}),c()}catch{window.alert(`Failed to delete this track. Check the server logs.`)}})()},le=Math.round(t.importance*100),ue=w?.importanceReason?`${String(le)}% · ${w.importanceReason}`:`${String(le)}%`,pe=w?.zonesVisited&&w.zonesVisited.length>0?w.zonesVisited.join(`, `):`—`,he=w?.audioLabels&&w.audioLabels.length>0?w.audioLabels.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `):`—`,ge=w?w.totalDistance.toFixed(2):`—`,_e=ot(w?.previewMissReason),ve=me(w?w.firstSeen:S),ye=w?me(w.lastSeen):`—`;return u(k,{open:!0,onOpenChange:e=>!e&&o(),children:r(_,{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,qe(t)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,qe(t)]}):null]}),u(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:n})]}),u(`button`,{type:`button`,onClick:o,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:u(Ae,{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?u(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:u(fe,{src:U,alt:`Key frame from ${n}`,fit:`natural`,className:`w-full`,overlay:ie?u(Ht,{overlay:ne,onPickSnapshot:re}):void 0})}):u(`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:[u(de,{className:`h-8 w-8 opacity-60`}),u(`span`,{className:`text-[11px]`,children:`Key-frame media unavailable`})]}):u(K,{className:`h-6 w-6 animate-spin opacity-70`})}),R.length>0&&u(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:R.map(e=>{let t=ht(e.kind),n=gt(Lt,e.key),i=P?gt(P,e.key):null;return r(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[u(`button`,{type:`button`,onClick:()=>j(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${t} · ${me(e.timestamp)}`,children:u(Rt,{mediaKey:e.key,label:t})}),r(`figcaption`,{className:`min-w-0 px-0.5`,children:[u(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:t,children:t}),u(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:me(e.timestamp),children:ce(e.timestamp)})]}),u(ft,{localUrl:n,publicUrl:i})]},e.key)})}),F,ae&&r(D,{variant:`secondary`,onClick:oe,disabled:M,children:[M?u(K,{className:`h-3.5 w-3.5 animate-spin`}):u(Ee,{className:`h-3.5 w-3.5`}),` `,`View clip`]}),u(Et,{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:p}),_e!==null&&r(`div`,{className:`rounded-lg border border-warning/40 bg-warning/8 px-3 py-2`,children:[u(`p`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Best shot`}),u(`p`,{className:`mt-0.5 text-xs text-foreground`,children:_e.sentence}),u(`code`,{className:`mt-1 block break-all font-mono text-[10px] text-foreground-subtle`,children:_e.raw})]}),r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[u(Z,{label:`Camera`,value:n}),u(Z,{label:`Class`,value:t.className}),u(Z,{label:`Label`,value:t.label??`—`}),u(Z,{label:`Sub-label`,value:t.subLabel??`—`}),u(Z,{label:`Importance`,value:ue}),u(Z,{label:`Zones visited`,value:pe}),u(Z,{label:`Audio heard`,value:he}),u(Z,{label:`Total distance`,value:ge}),u(Z,{label:`First seen`,value:ve}),u(Z,{label:`Last seen`,value:ye}),u(Z,{label:`Track`,value:t.trackId,mono:!0})]})]}),u(`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:u(`span`,{title:i?void 0:Mt,children:r(D,{variant:`secondary`,onClick:se,disabled:!i||h.isPending,children:[h.isPending?u(K,{className:`h-3.5 w-3.5 animate-spin`}):u(De,{className:`h-3.5 w-3.5`}),` `,`Delete track`]})})})]})})}var Wt=`pipeline-analytics`,Gt=`debug.listTracks`,Kt=`debug.analyze`,qt=`/addon/pipeline-analytics/debug-export`;function Jt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Q(e,t){let n=e[t];return typeof n==`string`?n:null}function $(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Yt(e,t){let n=e[t];return typeof n==`boolean`?n:null}function Xt(e){return e===`error`||e===`warn`||e===`info`}function Zt(e){if(!Jt(e))return null;let t=Q(e,`code`),n=Q(e,`detail`),r=e.severity;return t===null||n===null||!Xt(r)?null:{code:t,severity:r,detail:n}}function Qt(e){if(!Jt(e))return null;let t=Q(e,`trackId`),n=$(e,`deviceId`),r=Q(e,`className`),i=$(e,`firstSeen`),a=$(e,`lastSeen`),o=$(e,`durationMs`),s=Yt(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=Q(e,`label`),l=Q(e,`subLabel`),u=Q(e,`previewMissReason`),d=Yt(e,`markForTrain`),f=Yt(e,`favourited`);return{trackId:t,deviceId:n,className:r,...c===null?{}:{label:c},...l===null?{}:{subLabel:l},firstSeen:i,lastSeen:a,durationMs:o,active:s,timestamp:i,windowMs:o,importance:$(e,`importance`)??0,bestEventId:Q(e,`bestEventId`)??``,...d===null?{}:{markForTrain:d},...f===null?{}:{favourited:f},debug:!0,...u===null||u.length===0?{}:{previewMissReason:u}}}function $t(e){let t=Qt(e);if(t===null||!Jt(e))return null;let n=$(e,`mediaCount`),r=$(e,`eventCount`),i=$(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=Zt(e);t!==null&&c.push(t)}let l=e.thumbnailProvenance;return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c,...nt(l)?{thumbnailProvenance:l}:{}}}function en(e){if(!Jt(e))return null;let t=Yt(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=Qt(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function tn(e){if(!Jt(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=$t(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var nn={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`,BEST_SHOT_STANDIN:`stand-in best shot`,BEST_SHOT_RASTER:`low-res best shot`};function rn(e){return nn[e]??e}var an={error:0,warn:1,info:2};function on(e){return e.toSorted((e,t)=>an[e.severity]-an[t.severity]||e.code.localeCompare(t.code))}function sn(e){return e.length===0?qt:`${qt}?deviceIds=${e.join(`,`)}`}function cn(e,t){return`${String(e)}:${t}`}function ln(e,t){let n=[],r=new Set;for(let i of e){let e=cn(i.deviceId,i.trackId);!t.has(e)||r.has(e)||(r.add(e),n.push({deviceId:i.deviceId,trackId:i.trackId}))}return n}n();var un=`all`,dn=`The server answered in a shape this build does not understand.`,fn={error:`danger`,warn:`warning`,info:`info`};function pn({findings:e}){return e.length===0?u(S,{variant:`success`,children:`no anomaly found`}):u(`div`,{className:`flex flex-wrap gap-1`,children:on(e).map(e=>u(S,{variant:fn[e.severity],title:e.detail,children:rn(e.code)},e.code))})}function mn({track:e,report:t,analyzing:n}){let i=ot(t?.previewMissReason??e.previewMissReason);return r(`div`,{className:`space-y-1 border-t border-border pt-1.5`,children:[t===void 0?u(`span`,{className:`text-[10px] text-foreground-subtle`,children:n?`analysing…`:`not analysed`}):r(s,{children:[u(pn,{findings:t.findings}),r(`p`,{className:`text-[10px] text-foreground-subtle`,title:t.mediaKinds.length>0?t.mediaKinds.join(`, `):`no media of any kind`,children:[String(t.mediaCount),` media · `,String(t.eventCount),` events ·`,` `,String(t.positionCount),` positions`]})]}),i!==null&&u(`p`,{className:`text-[10px] text-foreground-subtle`,title:i.raw,children:i.sentence})]})}function hn(){let e=f(),[t,n]=l(un),[i,s]=l(!1),[c,d]=l(null),[p,m]=l(new Set),[h,g]=l(null),[_,v]=l(null),[y,S]=l(null),[C,w]=l([]),E=Ct(),O=x({isCamera:!0,projection:`slim`}),k=a(()=>[{value:un,label:`All cameras`},...(O.data??[]).map(e=>({value:String(e.id),label:e.name}))],[O.data]),j=a(()=>{let e=new Map;for(let t of O.data??[])e.set(t.id,t.name);return e},[O.data]),M=e=>j.get(e)??`Camera ${String(e)}`,N=a(()=>t===un?[]:[Number.parseInt(t,10)],[t]),P=o({queryKey:[`events-debug`,`list`,N],queryFn:async()=>en(await e.trpcClient.addons.custom.mutate({addonId:Wt,action:Gt,input:N.length===0?{}:{deviceIds:N}}))}),F=a(()=>(P.data?.tracks??[]).map(e=>e.trackId),[P.data]),I=o({queryKey:[`events-debug`,`analyze`,F],enabled:F.length>0,queryFn:async()=>tn(await e.trpcClient.addons.custom.mutate({addonId:Wt,action:Kt,input:{trackIds:F}}))}),ee=a(()=>{let e=new Map;for(let t of I.data?.reports??[])e.set(t.trackId,t);return e},[I.data]),L=P.data?.tracks??[],R=P.data===null||I.data===null,z=()=>{P.refetch(),I.refetch()},te=e=>{m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},B=()=>{m(new Set(L.map(e=>cn(e.deviceId,e.trackId))))},ne=()=>m(new Set),V=async(e,t)=>{let n=e===`analyzed`?{debug:!1}:{favourited:!0},r=0,i=[];for(let e of t)try{await E.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,flags:n}),r+=1}catch{i.push(e.trackId)}return{applied:r,refused:i}},H=e=>{if(!q||_!==null)return;let t=ln(L,p);t.length!==0&&(v(e),S(null),(async()=>{let n=await V(e,t);v(null);let r=new Set(n.refused);m(new Set(t.filter(e=>r.has(e.trackId)).map(e=>cn(e.deviceId,e.trackId)))),e===`analyzed`&&w(t.filter(e=>!r.has(e.trackId))),n.refused.length>0&&S(`${String(n.refused.length)} of ${String(t.length)} were refused by the server and are still selected. Check the hub log.`),P.refetch()})())},re=()=>{let e=C;e.length===0||_!==null||(v(`analyzed`),S(null),(async()=>{for(let t of e)try{await E.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,flags:{debug:!0}})}catch{S(`Some tracks could not be re-marked. Refresh and try again.`)}v(null),w([]),P.refetch()})())},U=async()=>{s(!0),d(null);try{await Fe(sn(N),`camstack-debug.zip`)}catch(e){d(e instanceof Error?e.message:`Export failed.`)}finally{s(!1)}},W=_!==null;return u(Ne,{children:r(`section`,{className:`space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[u(`div`,{className:`w-44`,children:u(T,{value:t,options:k,onChange:e=>n(e.target.value)})}),r(D,{variant:`secondary`,onClick:z,disabled:P.isFetching,children:[P.isFetching?u(K,{className:`h-3.5 w-3.5 animate-spin`}):u(ve,{className:`h-3.5 w-3.5`}),`Refresh`]}),r(D,{onClick:()=>void U(),disabled:i||L.length===0,children:[i?u(K,{className:`h-3.5 w-3.5 animate-spin`}):u(ae,{className:`h-3.5 w-3.5`}),`Export all (`,String(L.length),`)`]}),L.length>0&&p.size<L.length&&u(D,{variant:`ghost`,onClick:B,children:`Select all`})]}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`A `,u(`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. Use `,u(`strong`,{children:`Keep`}),` `,`to hold a selection against pruning while you investigate, and `,u(`strong`,{children:`Analyzed`}),` `,`to un-mark the ones you are finished with.`]}),P.isError&&u(A,{message:`Could not load the marked tracks.`}),R&&!P.isError&&u(A,{message:dn}),c!==null&&u(A,{message:c}),y!==null&&u(A,{message:y}),P.data?.truncated===!0&&u(A,{message:`A camera filled the per-camera cap — some marked tracks are not listed. Un-mark a few, or filter to one camera.`}),(I.data?.vanished.length??0)>0&&r(`p`,{className:`text-xs text-foreground-subtle`,children:[String(I.data?.vanished.length),` marked track(s) were evicted between the list and the analysis.`]}),p.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:[String(p.size),` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[u(`span`,{title:q?void 0:`Track flags arrive with the next server update`,children:r(D,{variant:`secondary`,onClick:()=>H(`keep`),disabled:!q||W,children:[_===`keep`?u(K,{className:`h-3.5 w-3.5 animate-spin`}):u(Ge,{className:`h-3.5 w-3.5`}),` `,`Keep`]})}),u(`span`,{title:q?void 0:`Track flags arrive with the next server update`,children:r(D,{onClick:()=>H(`analyzed`),disabled:!q||W,children:[_===`analyzed`?u(K,{className:`h-3.5 w-3.5 animate-spin`}):u(Se,{className:`h-3.5 w-3.5`}),` `,`Analyzed`]})}),u(D,{variant:`ghost`,onClick:ne,disabled:W,children:u(Ae,{className:`h-3.5 w-3.5`})})]})]}),C.length>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-border bg-surface px-3 py-2`,children:[r(`span`,{className:`text-xs text-foreground`,children:[String(C.length),` track(s) marked analyzed and removed from this list.`]}),r(D,{variant:`ghost`,onClick:re,disabled:W,children:[u(xe,{className:`h-3.5 w-3.5`}),` Undo`]}),u(D,{variant:`ghost`,onClick:()=>w([]),disabled:W,children:u(Ae,{className:`h-3.5 w-3.5`})})]}),P.isLoading?u(b,{children:u(`div`,{className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`Loading…`})}):L.length===0?u(b,{children:r(`div`,{className:`flex flex-col items-center gap-2 px-3 py-8 text-center`,children:[u(ze,{className:`h-5 w-5 text-foreground-subtle`}),u(`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.`})]})}):u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:L.map(e=>{let t=ee.get(e.trackId);return u(ct,{row:e,cameraName:M(e.deviceId),nowMs:e.lastSeen,selected:p.has(cn(e.deviceId,e.trackId)),onToggleSelect:te,onOpenDetail:g,...t?.thumbnailProvenance===void 0?{}:{provenance:t.thumbnailProvenance},footer:u(mn,{track:e,report:t,analyzing:I.isFetching})},cn(e.deviceId,e.trackId))})}),h&&u(Ut,{row:h,cameraName:M(h.deviceId),deleteAvailable:jt,onClose:()=>g(null),onDeleted:()=>{g(null),P.refetch()},onFlagsChanged:e=>{e.debug||(g(null),P.refetch())}})]})})}var gn=200,_n=3e4,vn=[];function yn(e){let t=f(),n=e.deviceIds.length>0,r=[...e.deviceIds].sort((e,t)=>e-t),{data:i,isLoading:a}=o({queryKey:[`events-feed`,r,e.since,e.until,e.minImportance??null,e.classFilter??null],enabled:n,staleTime:_n,refetchInterval:_n,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEventsBatch.query({deviceIds:r,since:e.since,until:e.until,limit:gn,...e.minImportance===void 0?{}:{minImportance:e.minImportance},...e.classFilter===void 0?{}:{classFilter:e.classFilter}})).map(e=>e.events.map(t=>({...t,deviceId:e.deviceId})))});return{rows:Xe(Ye(i??vn),`importance`),isLoading:n&&a}}n();var bn=[`events-feed`],xn=2e3;function Sn(n){let r=c(),i=n?.paused===!0,a=t(r);a.current=r;let o=t(i);o.current=i;let[s,u]=l(!1),f=e(()=>{a.current.invalidateQueries({queryKey:bn})},[]),p=t(void 0);p.current||=_e({delayMs:xn,invalidate:()=>{o.current?u(!0):f()}}),d(()=>()=>p.current?.cancel(),[]),d(()=>{i||!s||(u(!1),f())},[i,s,f]);let m=e(()=>{u(!1),f()},[f]);return E(re.PipelineAnalyticsDetectionEvent,()=>{p.current?.trigger()}),E(re.PipelineAnalyticsTrackEnded,()=>{p.current?.trigger()}),{pending:s,refreshNow:m}}n();function Cn({groups:e,selected:t,onChange:n,loading:i=!1}){let{t:o}=je(),[s,c]=l(!1),[d,f]=l(``),[p,m]=l(new Set),h=d.trim().toLowerCase(),g=e=>h.length===0||M(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:[u(Ke,{className:`h-3.5 w-3.5`}),S>0?`Kinds (${String(S)})`:`Kinds`,u(Me,{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:[u(Oe,{className:`h-3.5 w-3.5 text-foreground-subtle`}),u(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:`Search kinds…`,className:`w-full bg-transparent py-1 text-xs outline-none`}),S>0&&u(`button`,{type:`button`,onClick:x,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),_.length===0&&u(`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=z(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?u(`button`,{type:`button`,onClick:()=>v(e.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Expand`,children:u(i?Me:we,{className:`h-3 w-3`})}):u(`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:[u(`input`,{type:`checkbox`,checked:a,onChange:()=>y(e),className:`accent-primary`}),u(n,{className:`h-3.5 w-3.5`,style:{color:e.macro.color}}),u(`span`,{className:`font-medium`,children:M(e.macro,o)})]})]}),i&&e.subs.map(e=>{let n=z(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:[u(`input`,{type:`checkbox`,checked:t.has(e.kind),onChange:()=>b(e.kind),className:`accent-primary`}),u(n,{className:`h-3.5 w-3.5`,style:{color:e.color}}),u(`span`,{children:M(e,o)})]},e.kind)})]},e.macro.kind)})]})]})}function wn(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 Tn(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var En=new Set([`detection`,`package`]);function Dn(e,t){return[...wn(e,t).values()].filter(e=>e.parentKind===null&&En.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function On(e,t){let n=wn(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,Tn(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();function kn(){let[n,r]=l(!1),i=t(null),[a,o]=l(0),s=e(e=>{i.current!==e&&(i.current=e,o(e=>e+1))},[]);return d(()=>{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 An=[`events-feed`],jn=60,Mn=[{value:`importance`,label:`Importance`,icon:Re},{value:`time`,label:`Recent`,icon:W}];function Nn(){let e=c(),[t,n]=l(ge),[i,o]=l(new Set),[f,p]=l(new Set),[m,h]=l(0),[g,_]=l(`time`),[v,y]=l(new Set),[b,S]=l(null),[C,w]=l(()=>Date.now());d(()=>{let e=setInterval(()=>w(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:T,until:E}=a(()=>et({fromMs:t.fromMs,toMs:t.toMs},C),[t.fromMs,t.toMs,C]),O=kn(),{pending:k,refreshNow:A}=Sn({paused:b!==null||v.size>0||O.scrolledPast}),{data:M=[]}=x({isCamera:!0,projection:`slim`}),N=a(()=>M.map(e=>e.id),[M]),{data:P,isLoading:F}=j({deviceIds:N},{enabled:N.length>0,staleTime:5*6e4}),I=a(()=>On(P??[],i),[P,i]),ee=Pt(),L=ee.isPending,{rows:R,isLoading:z}=yn({deviceIds:N,since:T,until:E,minImportance:m>0?m:void 0,classFilter:f.size===1?[...f][0]:void 0}),te=a(()=>{let e=new Map;for(let t of M??[])e.set(t.id,t.name);return e},[M]),B=e=>te.get(e)??`Camera #${String(e)}`,ne=a(()=>se(R).map(e=>({id:e,name:B(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[R,te]),V=a(()=>Xe(Ze(R,{cameras:i,classes:f,minImportance:m}),g),[R,i,f,m,g]),H=pe(V,jn,a(()=>JSON.stringify([[...i].sort((e,t)=>e-t),[...f].sort(),m,g,T,E]),[i,f,m,g,T,E])),re=()=>{e.invalidateQueries({queryKey:An})},U=()=>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 ie(){if(v.size===0||!jt)return;let e=$e(R,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])=>ee.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{re();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(Qe(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 ae=V.length!==R.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[u(he,{onChange:n}),u(ue,{cameras:ne,selected:i,onChange:o}),u(Cn,{groups:I,selected:f,onChange:p,loading:F}),r(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[u(`span`,{children:`Min score`}),u(`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`}),u(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(m*100)})]}),u(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Mn.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:[u(t,{className:`h-3.5 w-3.5`}),` `,e.label]},e.value)})}),!z&&u(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:ae?`${String(V.length)} of ${String(R.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:[u(`span`,{title:jt?void 0:`Track deletion arrives with the next server update`,children:r(D,{variant:`secondary`,onClick:ie,disabled:!jt||L,children:[L?u(K,{className:`h-3.5 w-3.5 animate-spin`}):u(De,{className:`h-3.5 w-3.5`}),` `,`Delete`]})}),u(D,{variant:`ghost`,onClick:U,disabled:L,children:u(Ae,{className:`h-3.5 w-3.5`})})]})]}),z&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[u(K,{className:`h-4 w-4 animate-spin`}),` Loading events…`]}),!z&&V.length===0&&u(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No key events in this window.`}),k&&u(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:u(`button`,{type:`button`,onClick:A,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`})}),!z&&V.length>0&&r(s,{children:[u(`div`,{ref:O.ref,"aria-hidden":!0,className:`h-0`}),u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:H.pageItems.map(e=>u(ct,{row:e,cameraName:B(e.deviceId),nowMs:C,selected:v.has(Qe(e.deviceId,e.trackId)),onToggleSelect:W,onOpenDetail:S},Qe(e.deviceId,e.trackId)))}),u(oe,{currentPage:H.page,totalItems:H.totalItems,pageSize:H.pageSize,onPageChange:H.setPage,itemNoun:`events`})]}),b&&u(Ut,{row:b,cameraName:B(b.deviceId),deleteAvailable:jt,onClose:()=>S(null),onDeleted:()=>{re(),S(null)},onFlagsChanged:e=>{S(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug,favourited:e.favourited}:t)}})]})}n();var Pn=50,Fn=350,In=[{value:.2,label:`Loose`},{value:.25,label:`Balanced`},{value:.3,label:`Strict`}];function Ln(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 Rn({onActiveChange:e}){let[t,n]=l(``),[i,o]=l(.2),[s,c]=l(null),[f,p]=l(null),[m,h]=l(null),g=F(t,Fn).trim(),_=g.length>0;d(()=>{e(_)},[_,e]);let[v,y]=l(()=>Date.now());d(()=>{let e=setInterval(()=>y(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:b=[]}=x({isCamera:!0,projection:`slim`}),S=a(()=>{let e=new Map;for(let t of b)e.set(t.id,t.name);return e},[b]),C=e=>S.get(e)??`Camera #${String(e)}`,w=a(()=>b.map(e=>e.id),[b]),{data:T}=j({deviceIds:w},{enabled:w.length>0,staleTime:5*6e4}),E=a(()=>Dn(T??[],new Set(f===null?[]:[f])),[T,f]);d(()=>{s!==null&&(E.some(e=>e.kind===s)||c(null))},[E,s]);let{data:D,isFetching:O,isError:k,error:A}=I({text:g,minScore:i,limit:Pn,classFilter:s??void 0,deviceId:f??void 0},{enabled:_}),N=a(()=>[...D??[]].sort((e,t)=>t.score-e.score).map(e=>({...Ln(e),score:e.score})),[D]);function P(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:[u(Oe,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),u(`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&&u(`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:u(Ae,{className:`h-3.5 w-3.5`})})]}),O&&_&&u(K,{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:[u(`div`,{className:`flex items-center gap-1`,children:E.map(e=>u(`button`,{type:`button`,onClick:()=>P(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:M(e)},e.kind))}),r(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[u(`span`,{children:`Camera`}),r(`select`,{value:f===null?``:String(f),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:[u(`option`,{value:``,children:`All`}),b.map(e=>u(`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:[u(`span`,{children:`Match`}),u(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:In.map(e=>u(`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))})]}),_&&!O&&!k&&r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[N.length,` match`,N.length===1?``:`es`]})]})]}),_&&r(`div`,{className:`space-y-3`,children:[k&&r(`p`,{className:`py-4 text-xs text-danger`,children:[`Search failed: `,A instanceof Error?A.message:`unknown error`,`. Check that the CLIP embedding step is enabled.`]}),!k&&O&&N.length===0&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[u(K,{className:`h-4 w-4 animate-spin`}),` Searching…`]}),!k&&!O&&N.length===0&&r(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:[`No semantic matches for “`,g,`”. Try a looser match threshold or a different phrasing.`]}),!k&&N.length>0&&u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:N.map(e=>u(ct,{row:e,cameraName:C(e.deviceId),nowMs:v,score:e.score,onOpenDetail:h},e.id))})]}),m&&u(Ut,{row:m,cameraName:C(m.deviceId),deleteAvailable:jt,onClose:()=>h(null),onDeleted:()=>h(null)})]})}var zn=15e3,Bn={rows:[],unreadableCount:0};function Vn(e){let t=f(),n=e.length>0,r=[...e].sort((e,t)=>e-t),{data:i,isLoading:a}=o({queryKey:[`stationary-objects`,r],enabled:n,staleTime:zn,refetchInterval:zn,queryFn:async()=>{let e=await t.trpcClient.zoneAnalytics.getCurrentSnapshotBatch.query({deviceIds:r}),n=[],i=0;for(let t of e){if(t.read===`unreadable`){i++;continue}for(let e of t.snapshot?.stationaryObjects??[])n.push({...e,deviceId:t.deviceId})}return{rows:n,unreadableCount:i}}}),s=i??Bn;return{rows:s.rows.toSorted((e,t)=>t.becameStationaryAt-e.becameStationaryAt),isLoading:n&&a,unreadableCount:s.unreadableCount}}n();function Hn(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 Un({row:e,cameraName:t,nowMs:n}){let i=e.keyFrameMediaKey?.startsWith(`track:`)?e.keyFrameMediaKey.split(`:`)[1]:e.keyFrameMediaKey,a=Pe(i?`${Ie}/${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?u(`img`,{src:a.src,alt:`Parked ${e.className} on ${t}`,className:`h-full w-full object-cover`}):u(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:u(We,{className:`h-6 w-6`})}),u(`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:[u(`span`,{className:`truncate text-[11px] text-foreground`,children:t}),r(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`parked `,Hn(n,e.becameStationaryAt)]})]})]})}function Wn(){let[e,t]=l(!1),n=Date.now(),{data:i=[]}=x({isCamera:!0,projection:`slim`}),o=a(()=>i.map(e=>e.id),[i]),s=a(()=>{let e=new Map;for(let t of i)e.set(t.id,t.name);return e},[i]),{rows:c,unreadableCount:d}=Vn(o);return c.length===0&&d===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:[u(e?Me:we,{className:`h-4 w-4 text-foreground-subtle`}),u(We,{className:`h-4 w-4 text-foreground-subtle`}),u(`span`,{className:`text-sm font-semibold text-foreground`,children:`Stationary`}),u(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:c.length}),u(`span`,{className:`ml-2 text-[11px] text-foreground-subtle`,children:`Parked objects — kept out of the event feed`}),d>0?r(`span`,{className:`ml-2 text-[11px] text-warning`,children:[d,` camera`,d===1?``:`s`,` could not be read`]}):null]}),e&&u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:c.map(e=>u(Un,{row:e,cameraName:s.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:n},e.id))})]})}n();function Gn(){let[e,t]=l(!1);return u(Ne,{children:r(`section`,{className:`space-y-3`,children:[u(Rn,{onActiveChange:t}),!e&&u(Wn,{}),!e&&u(Nn,{})]})})}var Kn=[`person`,`vehicle`,`animal`,`package`,`face`,`plate`],qn=new Set(Kn);function Jn(e){let t=e?.trim().toLowerCase();return t===void 0||t===``?null:qn.has(t)?`"${t}" is a macro class, not a label — person / postman / Marco are three different tiers`:null}function Yn({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 `,u(`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.`]}):u(`ul`,{className:`divide-y divide-border`,children:e.map((e,o)=>{let s=o===t,c=Jn(e.label),l=Jn(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:[u(T,{className:`w-28`,value:e.macroClass,options:Kn.map(e=>({value:e,label:e})),onChange:e=>{let t=Kn.find(t=>t===e.target.value);t!==void 0&&i(o,{macroClass:t})}}),u(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(S,{variant:`info`,children:[e.assistModelId??`assist`,e.assistScore===void 0?``:` ${e.assistScore.toFixed(2)}`]}),u(D,{variant:`ghost`,size:`sm`,"aria-label":`Delete this subject`,onClick:()=>{a(o)},children:u(De,{className:`h-3 w-3`})})]}),r(`div`,{className:`flex items-center gap-2`,children:[u(y,{className:`flex-1`,placeholder:`label (postman, van, cat…)`,value:e.label??``,onChange:e=>{i(o,{label:e.target.value})}}),u(y,{className:`flex-1`,placeholder:`sub-label (a name, a plate…)`,value:e.subLabel??``,onChange:e=>{i(o,{subLabel:e.target.value})}})]}),c!==null&&u(`p`,{className:`text-[11px] text-danger`,children:c}),l!==null&&u(`p`,{className:`text-[11px] text-danger`,children:l})]},`${String(o)}-${String(e.bbox.x)}`)})})}function Xn(e){return e.every(e=>Jn(e.label)===null&&Jn(e.subLabel)===null&&qn.has(e.macroClass))}function Zn(e){return e<0?0:e>1?1:e}function Qn(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 $n(e,t,n){return{x:Zn((e-n.left)/n.width),y:Zn((t-n.top)/n.height)}}function er(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 tr(e){return e.w>=.01&&e.h>=.01}function nr(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 rr(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 ir({imageSrc:n,imageWidth:a,imageHeight:o,boxes:s,selectedIndex:c,onSelect:d,onDraw:f}){let p=t(null),[m,h]=l({w:0,h:0}),[g,_]=l(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=Qn(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 $n(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:er(t,t)}))},onPointerMove:e=>{if(g===null)return;let t=y(e);t!==null&&_({start:g.start,current:er(g.start,t)})},onPointerUp:()=>{if(g===null)return;let e=g.current;_(null),tr(e)?f(e):d(rr(s.map(e=>e.bbox),g.start))},children:[u(`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=nr(e.bbox,v),i=e.kind===`model_error`,a=t===c,o=i?`#ef4444`:a?`#22c55e`:`#3b82f6`;return u(`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&&u(`div`,{className:`absolute border border-dashed border-primary pointer-events-none`,style:nr(g.current,v)})]})}function ar(e){return e>=1e6?`${(e/1e6).toFixed(1)} MB`:`${Math.round(e/1e3)} KB`}function or({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)),d=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?u(`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.`}):u(`ul`,{className:`flex flex-wrap gap-2`,children:t.map(e=>u(`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:[u(Se,{className:`h-3 w-3 text-success`}),u(`span`,{className:`font-medium text-foreground`,children:e.sourceKind}),r(`span`,{className:`text-foreground-subtle`,children:[e.width,`×`,e.height,` · `,ar(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:[u(De,{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 (`,d.length,`)`]}),d.length===0?u(`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.`}):u(`ul`,{className:`flex flex-wrap gap-2`,children:d.map(e=>{let t=i.get(e.mediaKey);return r(`li`,{children:[r(D,{variant:`secondary`,size:`sm`,disabled:a||t!==void 0,onClick:()=>{o(e.mediaKey)},children:[a?u(K,{className:`h-3 w-3 animate-spin`}):u(t===void 0?He:de,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:e.kind}),u(`span`,{className:`ml-1 text-foreground-subtle`,children:ar(e.sizeBytes)})]}),t!==void 0&&u(S,{variant:`danger`,className:`ml-1`,children:t})]},e.mediaKey)})})]})]})}function sr(e){return e.frameCount===0?`untouched`:e.annotationCount===0?`started`:`ready`}var cr={untouched:{icon:Ve,label:`to do`,variant:`default`},started:{icon:Be,label:`frames only`,variant:`info`},ready:{icon:Ce,label:`annotated`,variant:`success`}};function lr(e){return new Date(e).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function ur({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:[u(K,{className:`h-3.5 w-3.5 animate-spin`}),`Loading staging tracks…`]}):e.length===0?u(`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.`}):u(`ul`,{className:`divide-y divide-border`,children:e.map(e=>{let t=cr[sr(e)],o=t.icon;return u(`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:[u(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:[u(`span`,{className:`text-xs font-medium text-foreground truncate`,children:e.label??e.className}),u(S,{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)}`,` ·`,` `,lr(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 dr=`person`;function fr(){let[t,n]=l(null),[i,o]=l(null),[c,f]=l([]),[m,_]=l(-1),[v,y]=l(new Map),[b,w]=l(null),T=x({projection:`slim`,isCamera:!0}),E=a(()=>{let e=new Map;for(let t of T.data??[])e.set(t.id,t.name);return e},[T.data]),k=O({}),A=ne({trackId:t?.trackId??``},{enabled:t!==null}),j=h({trackId:t?.trackId??``},{enabled:t!==null}),M=B({frameId:i??``},{enabled:i!==null}),P=C(),F=N(),I=g(),L=p(),z=R(),te=ee();d(()=>{if(i===null){f([]);return}f((j.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}}))),_(-1)},[i,j.data]),d(()=>{let e=A.data?.copies??[];i===null&&e.length>0&&o(e[0].frameId)},[A.data,i]);let V=e(e=>{n(e),o(null),f([]),y(new Map),w(null)},[]),H=e(async e=>{if(t===null)return;let n=await P.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,mediaKeys:[e]});if(n.refused.length>0){let e=new Map(v);for(let t of n.refused)e.set(t.sourceMediaKey,t.reason);y(e)}n.copied.length>0&&o(n.copied[0].frameId),await A.refetch(),await k.refetch()},[t,P,v,A,k]),re=e(async e=>{t!==null&&(await F.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:e}),i===e&&o(null),await A.refetch(),await j.refetch(),await k.refetch())},[t,F,i,A,j,k]),U=e(async e=>{if(t===null||i===null)return;w(null);let n=await I.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:i,subject:e===`package`?{kind:`package`}:{kind:`objects`,modelId:`yolo26n`,minScore:.3}});if(n.kind===`refused`){w(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}f(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}}))]),w(`${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,I]),W=e(e=>{f(t=>[...t,{bbox:e,macroClass:dr,kind:`subject`,source:`operator`}]),_(c.length)},[c.length]),ie=e((e,t)=>{f(n=>n.map((n,r)=>r===e?{...n,...t}:n))},[]),ae=e(e=>{f(t=>t.filter((t,n)=>n!==e)),_(-1)},[]),oe=e(async()=>{t===null||i===null||(await L.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 j.refetch(),await k.refetch(),w(`Annotations saved.`))},[t,i,c,L,j,k]),se=e(async()=>{if(t===null)return;let e=await z.mutateAsync({deviceId:t.deviceId,trackId:t.trackId});w(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 k.refetch(),e.changed&&n(null)},[t,z,k]),ce=e(async()=>{if(t===null)return;let e=await te.mutateAsync({deviceId:t.deviceId,trackId:t.trackId});w(e.changed?`Track returned to staging. Its copies and annotations were left alone.`:`Refused: ${e.reason??`unknown`}`),await k.refetch()},[t,te,k]),le=M.data,ue=Xn(c)&&i!==null;return r(Ne,{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(D,{variant:`secondary`,size:`sm`,onClick:()=>void ce(),children:[u(xe,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Back to staging`})]}),r(D,{size:`sm`,onClick:()=>void se(),children:[u(Ue,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Complete track`})]})]}),children:[b!==null&&u(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-xs text-foreground`,children:b}),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:[u(`h2`,{className:`text-xs font-semibold text-foreground`,children:`Staging`}),u(S,{children:k.data?.length??0})]}),u(ur,{tracks:k.data??[],isLoading:k.isLoading,selectedTrackId:t?.trackId??null,deviceNames:E,onSelect:V})]}),u(`section`,{className:`space-y-3 min-w-0`,children:t===null?u(`p`,{className:`text-xs text-foreground-subtle`,children:`Pick a track from the staging list to start annotating it.`}):r(s,{children:[u(`div`,{className:`rounded-md border border-border bg-surface p-3`,children:u(or,{candidates:A.data?.candidates??[],copies:A.data?.copies??[],activeFrameId:i,refusals:v,isSelecting:P.isPending,onSelectCandidate:e=>void H(e),onOpenCopy:o,onRemoveCopy:e=>void re(e)})}),i!==null&&r(`div`,{className:`grid grid-cols-1 xl:grid-cols-[minmax(0,1fr)_minmax(0,380px)] gap-3`,children:[u(`div`,{className:`rounded-md border border-border overflow-hidden`,children:le===void 0?r(`div`,{className:`flex items-center gap-2 p-6 text-xs text-foreground-subtle`,children:[u(K,{className:`h-3.5 w-3.5 animate-spin`}),`Loading the frame…`]}):u(ir,{imageSrc:`data:image/jpeg;base64,${le.base64}`,imageWidth:le.width,imageHeight:le.height,boxes:c,selectedIndex:m,onSelect:_,onDraw:W})}),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:[u(`h2`,{className:`text-xs font-semibold text-foreground flex-1`,children:`Subjects`}),r(D,{variant:`secondary`,size:`sm`,disabled:I.isPending,onClick:()=>void U(`objects`),children:[u(Te,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Propose`})]}),r(D,{variant:`secondary`,size:`sm`,disabled:I.isPending,onClick:()=>void U(`package`),children:[u(Te,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Packages`})]})]}),u(`div`,{className:`flex-1 overflow-y-auto`,children:u(Yn,{annotations:c,selectedIndex:m,onSelect:_,onChange:ie,onDelete:ae})}),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`]}),u(D,{size:`sm`,disabled:!ue||L.isPending,onClick:()=>void oe(),children:`Save frame`})]})]})]})]})})]})]})}function pr(){return u(`div`,{className:`flex flex-col p-4`,children:u(Le,{tabs:[{id:`feed`,label:`Feed`,icon:ke,content:u(Gn,{})},{id:`retrain`,label:`Retrain`,icon:Ue,content:u(fr,{})},{id:`debug`,label:`Debug`,icon:ze,content:u(hn,{})}]})})}export{pr 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{Q as c}from"./player-overlays-Bjt3KKaE.js";import{An as l,Bs as u,Fs as d,Gs as f,Hs as p,Is as m,Kr as h,Ks as g,Ls as _,Ms as v,Ns as y,Ps as b,Rs as x,Rt as S,S as C,Us as w,Vs as ee,Ws as T,f as E,kn as D,p as O,tt as te,un as k,x as A,zs as j}from"./src-Do9J_PcR.js";import{c as M,d as N,l as P,u as F}from"./src-Dz-5lByR.js";import{t as I}from"./circle-check-big-B9ac961J.js";import{t as ne}from"./copy-F3szhd3t.js";import{t as re}from"./key-round-C0iKExnu.js";import{t as ie}from"./pencil-BgaAECPD.js";import{t as ae}from"./plus-VwU2KiHj.js";import{t as L}from"./shield-alert-B11i706j.js";import{A as oe,B as se,D as ce,J as R,L as le,T as z,d as B,l as V,n as H,o as U,r as W,w as G,z as ue}from"./index-CTFcrmzA.js";import{t as K}from"./AdminPage-CCD07UMs.js";import{t as de}from"./AdminTabs-C0Wy66CI.js";import{t as fe}from"./AddonCollectionPage-BSXsNPWa.js";import{t as pe}from"./addon-display-names-DvSEQty-.js";var me=R(`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`}]]),he=R(`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`}]]),ge=R(`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`}]]),_e=R(`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`}]]),ve=R(`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=k(),l=m({userId:e}),u=l.data,f=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),p=d({onSuccess:()=>{f(),r()}}),h=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(V,{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(W,{className:`h-4 w-4`})})]}),t(`div`,{className:`p-4 space-y-4`,children:[h===`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…`]}),h===`not_enrolled`&&t(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[s(z,{className:`h-4 w-4 mt-0.5 shrink-0`}),t(`div`,{children:[s(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),s(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),h===`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(I,{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(S,{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`})&&p.mutate({userId:e})},disabled:p.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[p.isPending?s(G,{className:`h-3 w-3 animate-spin`}):s(W,{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}=h({projection:`slim`}),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(L,{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:oe,label:`Devices they can see`,count:f.device.view.deviceCount,all:f.device.view.all,total:d}),s(q,{icon:ie,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=F(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?[]:P({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.`:O(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(W,{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(L,{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:M.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?ue:le,{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(E,{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(A,{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,l]=o(``),[d,p]=o(``),[m,h]=o(!1),[_,v]=o(null),{data:x,isLoading:S,isError:C}=u(),w=k(),T=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),E=y({onSuccess:()=>{T(),i(!1),l(``),p(``),h(!1),v(null)},onError:e=>{v(e instanceof Error?e.message:`Failed to create user`)}}),D=b({onSuccess:T}),O=g({onSuccess:T}),A=ee({onSuccess:T}),j=f({onSuccess:()=>{T(),N(null)}}),[M,N]=o(null),[P,F]=o(null),I=x??[];async function ne(e){await w({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`})&&D.mutate({id:e.id})}async function re(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 w({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&A.mutate({id:e.id,newPassword:t})}}function ie(e,t){t!==e.isAdmin&&O.mutate({id:e.id,isAdmin:t})}function L(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(ae,{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(W,{className:`h-4 w-4`})})]}),t(`div`,{className:`grid grid-cols-3 gap-3`,children:[t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),s(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`john`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Password`}),s(`input`,{type:`password`,value:d,onChange:e=>p(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`})]})]})]}),_&&s(`p`,{className:`text-[10px] text-danger`,children:_}),t(`div`,{className:`flex justify-end gap-2`,children:[s(`button`,{onClick:()=>i(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),s(`button`,{onClick:()=>E.mutate({username:c,password:d,isAdmin:m}),disabled:E.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:E.isPending?`Creating...`:`Create`})]})]}),S&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),C&&s(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!S&&!C&&I.length===0&&s(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>D.isPending&&D.variables?.id===e.id||O.isPending&&O.variables?.id===e.id||A.isPending&&A.variables?.id===e.id;return s(te,{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=>ie(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:()=>N(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(B,{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:L(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:()=>F(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(V,{className:`h-3 w-3`}),`Remove 2FA`]}),t(`button`,{onClick:()=>re(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(ge,{className:`h-3 w-3`}),`Reset password`]}),t(`button`,{onClick:()=>ne(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:I,rowKey:e=>e.id,minWidthPx:560})})(),P&&s(ye,{userId:P.id,username:P.username,onClose:()=>F(null)}),M&&s(Ee,{user:M,onClose:()=>N(null),onSubmit:e=>j.mutate({userId:M.id,scopes:e}),submitting:j.isPending})]})}function Te({scopes:e}){if(e.length===0)return s(`span`,{className:`font-medium text-warning`,children:`No access`});let n=F(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:N(n.roleId).label}),` ·`,` `,C(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=k(),{data:i,isLoading:c}=_(),{data:l}=u(),d=n(()=>i??[],[i]),f=n(()=>l??[],[l]),m=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),h=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[g,y]=o(!1),[b,x]=o(null),S=p({onSuccess:m}),C=v({onSuccess:({token:e,record:t})=>{h(),y(!1),x({token:e,label:t.name})}}),w=T({onSuccess:h}),ee=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})},E=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:()=>y(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,disabled:f.length===0,title:f.length===0?`Create a user first`:`Issue a scoped token`,children:[s(B,{className:`h-3.5 w-3.5`}),`New token`]})]}),t(je,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[f.length===0&&s(Ne,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),f.map(e=>s(Fe,{userId:e.id,username:e.username,onRevoke:(e,t)=>{E(e,t)},revokePending:w.isPending,revokeId:w.variables?.id},e.id))]}),d.length>0&&s(je,{title:`Legacy API keys`,subtitle:`${d.length} pre-existing — revoke only`,children:s(Pe,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:d.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:()=>{ee(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,{}),g&&s(Ie,{users:f.map(e=>({id:e.id,username:e.username})),onClose:()=>y(!1),onSubmit:e=>C.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:C.isPending}),b&&s(Le,{token:b.token,label:b.label,onClose:()=>x(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}=j({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`?`[${C(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(``),_=O(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(E,{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(B,{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(ne,{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(W,{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=k(),{data:i,isLoading:o}=x(),c=n(()=>i??[],[i]),l=w({onSuccess:()=>e.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),u=async(e,t)=>{await r({title:`Revoke "${t}" session?`,message:`This integration will lose access immediately on its next API call. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&l.mutate({id:e})};return t(K,{icon:_e,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:()=>{u(e.id,e.integrationId)},disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[r?s(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:he,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:ce,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:ce,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:V,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)||e.startsWith(`auth-magic-link`)?{headline:`TOTP / magic-link — second factor or passwordless sign-in.`,icon:V,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:B,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Ke(){let e=l({capName:Q[0].capName},{refetchInterval:Z}),t=l({capName:Q[1].capName},{refetchInterval:Z}),r=D(void 0,{refetchInterval:Z}),i=n(()=>pe(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(fe,{title:$.title,subtitle:$.subtitle,pageIcon:B,itemIcon:B,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(me,{className:`h-3 w-3`}),`Setup steps`]}),s(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:n.setupSteps.map((e,t)=>s(`li`,{children:e},t))})]}),e===`local-auth`&&t(`div`,{className:`rounded-md border border-blue-500/30 bg-blue-500/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[s(z,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),t(`span`,{children:[`TOTP / 2FA is self-service: each user enrols from their own profile page —`,` `,s(`a`,{href:`/system/my-access`,className:`underline text-primary`,children:`My access`}),` `,`→ “Two-factor authentication” → Enable 2FA. Admins can only remove a user’s active enrollment (lost device) from the`,` `,s(`a`,{href:`/system/users`,className:`underline text-primary`,children:`Users`}),` `,`page via Actions → “Remove 2FA”.`]})]})]})}function Je(){return s(`div`,{className:`flex flex-col p-4`,children:s(de,{tabs:[{id:`users`,label:`Users`,icon:ve,content:s(we,{})},{id:`api-keys`,label:`Tokens`,icon:re,content:s(Ae,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:_e,content:s(We,{})},{id:`authentication`,label:`Authentication`,icon:B,content:s(Ke,{})}]})})}export{Je as IdentityPage};
@@ -1 +0,0 @@
1
- import{I as e,K as t,Q as n,S as r,W as i,b as a,o,q as s,x as c,z as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Q as u}from"./player-overlays-Bjt3KKaE.js";import{Ai as d,Dr as f,Ei as p,Er as m,Gt as h,I as g,J as _,Kr as v,Lr as y,Mi as b,Mr as x,Mt as ee,N as S,Nr as C,Oi as w,Or as T,Pn as E,Qr as D,Rr as O,T as te,Ti as k,Tr as A,Vr as j,Xr as M,_n as N,ci as P,jr as ne,kr as F,ot as re,rt as I,vn as L,w as ie,wi as R}from"./src-Do9J_PcR.js";import{ht as z}from"./src-Dz-5lByR.js";import{t as ae}from"./ProviderIcon-1oq0Ms1x.js";import{t as B}from"./circle-x-B2sS9Wtz.js";import{t as V}from"./plus-VwU2KiHj.js";import{i as oe,n as H,r as U,t as se}from"./ScanNetworkModal-Cq19W7kZ.js";import{t as ce}from"./refresh-cw-DC4HHe02.js";import{t as W}from"./rotate-cw-Bg20q2cx.js";import{t as G}from"./wifi-CBHL4Gpd.js";import{A as le,B as ue,F as K,J as de,K as fe,L as pe,Q as me,X as he,Z as ge,a as q,f as _e,j as ve,m as ye,o as be,r as xe,t as Se,w as J,z as Ce}from"./index-CTFcrmzA.js";import{t as Y}from"./FormBuilder-_6fIxweR.js";import{t as we}from"./NodeAddonsSettingsPanel-D95kz9WA.js";var Te=de(`search-x`,[[`path`,{d:`m13.5 8.5-5 5`,key:`1cs55j`}],[`path`,{d:`m8.5 8.5 5 5`,key:`a8mexj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]);n();function Ee(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Ee(n.fields));return t}function De(t,n,r){let[a,o]=s(`idle`),[c,l]=s({}),u=i(()=>{let e=[];for(let n of t.sections)e.push(...Ee(n.fields));return e},[t]),d=u.length>0&&r!==void 0,f=e(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:a,hasProbeFields:d,probeResults:c,handleTestAll:e(async()=>{if(!r)return;let e=u.filter(e=>{let t=n[e];return t!=null&&String(t).trim()!==``});if(e.length===0)return;o(`testing`);let t={};for(let n of e)t[n]={status:`probing`};l(t);let i=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await r(e,n[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),a={};for(let e of i)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;a[t]={status:n.status===`ok`?`ok`:`error`,result:n}}l(a),o(`idle`)},[r,u,n]),clearProbeResult:f}}n();function Oe(e){let t=[];for(let n of e)`required`in n&&n.required===!0&&`key`in n&&n.key&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Oe(n.fields));return t}function ke(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Ae(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Ae(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function X(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function je({open:t,integrationId:n,addonId:a,onClose:u}){let{t:d}=Se(),f=o(),[p,m]=s({}),[h,g]=s(!1),[v,y]=s(null),[b,ee]=s(X),S=M({addonId:a},{enabled:t}),C=S.data?.deviceType??null,w=j({addonId:a,type:C??z.Camera},{enabled:t&&S.isSuccess&&C!==null}),T=w.data??null;l(()=>{t&&(m(T?Ae(T.sections.flatMap(e=>e.fields)):{}),ee(X()),g(!1),y(null))},[t,n,T]);let E=i(()=>({...p,_probeRequestId:b}),[p,b]),D=x({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),O=P(),te=e(async(e,t)=>{g(!0);let n=await O.mutateAsync({addonId:a,type:C??z.Camera,key:e,value:t,formValues:E});return n.status===`ok`&&n.suggestedValues&&m(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))ke(e[i])&&!ke(a)&&(r[i]=a,t=!0);return t?r:e}),n},[O,a,E,C]),{testAllStatus:k,hasProbeFields:A,probeResults:N,handleTestAll:ne,clearProbeResult:F}=De(T??{sections:[]},p,te);async function re(e){y(null);try{await D.mutateAsync({addonId:a,type:C??z.Camera,config:p,integrationId:n}),e?m(T?Ae(T.sections.flatMap(e=>e.fields)):{}):u()}catch(e){y(e instanceof Error?e.message:String(e))}}if(!t)return null;let I=Oe((T?.sections??[]).flatMap(e=>e.fields)).filter(e=>ke(p[e])),L=I.length===0,ie=S.isLoading||C!==null&&w.isLoading,R=S.isError||S.isSuccess&&C===null||w.isError||w.isSuccess&&T===null;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:u}),r(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[calc(90dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl`,children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:d(`integrations.addDevice`)}),c(`button`,{onClick:u,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:c(xe,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:ie?c(`div`,{className:`flex items-center justify-center py-8`,children:c(J,{className:`h-5 w-5 animate-spin text-primary`})}):R?r(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[c(q,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`space-y-1`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,c(`span`,{className:`font-mono`,children:a}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):c(Y,{schema:T,values:p,onChange:m,onTestField:te,probeResults:N,onClearProbe:F})}),!R&&!ie&&r(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[r(`button`,{type:`button`,onClick:()=>g(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[r(`span`,{className:`flex items-center gap-2`,children:[c(ye,{className:`h-3.5 w-3.5`}),`Test logs`,c(`span`,{className:`font-mono text-[9px] opacity-60`,children:b.slice(0,14)})]}),c(Ce,{className:`h-3.5 w-3.5 transition-transform ${h?`rotate-180`:``}`})]}),h&&c(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:c(_,{addonId:a,requestId:b,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!R&&!ie&&(v||I.length>0)&&c(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[c(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:v||`Required: ${I.join(`, `)}`})]})}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:u,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:d(`integrations.cancel`)}),!R&&A&&r(`button`,{type:`button`,onClick:ne,disabled:k===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[k===`testing`?c(J,{className:`h-3.5 w-3.5 animate-spin`}):c(G,{className:`h-3.5 w-3.5`}),`Test All`]})]}),r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:()=>re(!0),disabled:R||!L||D.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:d(`integrations.saveAndNew`)}),c(`button`,{onClick:()=>re(!1),disabled:R||!L||D.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:D.isPending?d(`integrations.saving`):d(`integrations.save`)})]})]})]})]})}var Me=1500;function Z({addonId:e,integrationId:t,jobId:n,onFinished:i}){let{t:a}=Se(),o=A(),s=(T({addonId:e,integrationId:t},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?Me:!1}).data??[]).find(e=>e.jobId===n);if(!s)return null;let l=s.state===`running`,u=s.processed,d=s.total>0?Math.round(u/s.total*100):0;!l&&s.finishedAt!==null&&i();let f=[`${u}/${s.total} ${a(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];s.adopted>0&&f.push(`${s.adopted} ${a(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),s.alreadyAdopted>0&&f.push(`${s.alreadyAdopted} ${a(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),s.failed>0&&f.push(`${s.failed} ${a(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let p=f.join(` · `);return r(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[r(`div`,{className:`flex items-center gap-2`,children:[l?c(J,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):s.failed>0?c(q,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):s.state===`cancelled`?c(B,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):c(K,{className:`h-3.5 w-3.5 text-primary shrink-0`}),c(`p`,{className:`text-[11px] text-foreground`,children:p}),l&&c(`button`,{onClick:()=>o.mutate({jobId:n}),className:`ml-auto rounded-lg border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:a(`integrations.adoptJobCancel`,{defaultValue:`Stop`})})]}),c(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:c(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${d}%`},role:`progressbar`,"aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100})}),s.results.filter(e=>e.outcome===`failed`).slice(0,5).map(e=>r(`p`,{className:`text-[11px] text-destructive`,children:[e.childNativeId,`: `,e.error]},e.childNativeId))]})}function Ne(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}n();var Q=`devices`,Pe={id:Q,label:`Devices`,isDefault:!0},Fe=2e4,$=100;function Ie({addonId:n,integrationId:i,onClose:a}){let{t:o}=Se(),[u,d]=s(new Set),[h,_]=s(new Set),[v,y]=s(new Map),[b,x]=s(null),{data:ee}=p(),C=(ee??[]).find(e=>e.addonId===n)?.supportsLocationImport??!1,[w,T]=s(!0),E=m({addonId:n,integrationId:i}).data?.filters,D=E&&E.length>0?E:[Pe],[O,te]=s(D.find(e=>e.isDefault)?.id??(D.some(e=>e.id===Q)?Q:D[0].id)),k=O!==Q,A=F(),j=f({addonId:n,integrationId:i,page:1,pageSize:Fe,filter:O}),M=j.refetch,N=A.mutate,P=e(()=>{N({addonId:n,integrationId:i},{onSettled:()=>{M()}})},[N,n,i,M]),re=t(null);l(()=>{let e=`${n}::${i}`;re.current===e||j.isLoading||(re.current=e,(j.data?.candidates.length??0)===0&&P())},[n,i,j.isLoading,j.data,P]);let I=A.isPending,L=A.isError?A.error instanceof Error?A.error.message:String(A.error):null,R=typeof A.data?.lastError==`string`&&A.data.lastError.length>0?A.data.lastError:null,z=j.data?.candidates??[],ae=j.isError?j.error instanceof Error?j.error.message:String(j.error):null,B=ne(),[V,oe]=s(null),H=e(e=>{e.alreadyAdopted||d(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),U=e(e=>{_(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),se=e((e,t)=>{y(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),ce=e(e=>{let t={};for(let n of e){let e=v.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[v]),G=e(async()=>{x(null);let e=[...u];if(e.length!==0)try{let t=ce(e),{jobId:r}=await B.mutateAsync({addonId:n,integrationId:i,filter:O,childNativeIds:e,...t?{perCandidate:t}:{},...C?{importLocations:w}:{}});oe(r),d(new Set),y(new Map)}catch(e){x(e instanceof Error?e.message:String(e))}},[u,ce,B,n,i,O,C,w]),le=t(null),K=e(()=>{V===null||le.current===V||(le.current=V,M())},[V,M]),de=e(e=>{te(e),d(new Set),_(new Set),y(new Map),x(null)},[]),fe=u.size;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:a}),r(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] rounded-xl border border-border bg-background shadow-2xl`,children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[r(`div`,{className:`min-w-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:o(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),c(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:o(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),r(`div`,{className:`flex items-center gap-3 shrink-0`,children:[C&&r(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[c(`input`,{type:`checkbox`,checked:w,onChange:e=>T(e.target.checked),className:`accent-primary`}),o(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),c(`button`,{onClick:a,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:c(xe,{className:`h-4 w-4`})})]})]}),r(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(L??ae??R)&&z.length===0&&c(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[c(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`min-w-0`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:o(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),c(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:L??ae??R})]})]})}),D.length>1&&c(Le,{filters:D,activeFilter:O,onSelect:de}),c(`div`,{className:`flex-1 min-h-0`,children:c(ie,{mode:`generic`,items:z,pageSize:$,getKey:e=>e.childNativeId,getSearchText:Ne,getFilterType:e=>e.type,filterOptions:S(),filterLabel:o(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:j.isLoading||I&&z.length===0,searchPlaceholder:o(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(L??ae??R)&&z.length===0?``:o(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:r(`button`,{type:`button`,onClick:P,disabled:I,title:o(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[c(W,{className:`h-3.5 w-3.5 ${I?`animate-spin`:``}`}),o(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:o(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>c(Re,{candidate:e,expandable:!k,expanded:h.has(e.childNativeId),onToggleExpand:()=>U(e.childNativeId),adoptedLabel:o(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:o(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=g(e.type),n=t.icon;return r(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[c(n,{className:`h-3.5 w-3.5 shrink-0`}),t.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>c(`div`,{className:`flex items-center justify-end`,children:c(`button`,{onClick:()=>H(e),disabled:e.alreadyAdopted,"aria-label":u.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${u.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:u.has(e.childNativeId)&&c(ue,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!k&&h.has(e.childNativeId),renderExpanded:k?void 0:e=>c(ze,{candidate:e,hiddenChildIds:v.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>se(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:u.has(e.childNativeId)?`bg-primary/5`:``})})]}),b&&c(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[c(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:b})]})}),V!==null&&c(Z,{addonId:n,integrationId:i,jobId:V,onFinished:K}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[c(`div`,{}),r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:a,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:o(`integrations.cancel`,{defaultValue:`Cancel`})}),r(`button`,{onClick:G,disabled:fe===0||B.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,children:[B.isPending&&c(J,{className:`h-3.5 w-3.5 animate-spin`}),o(`integrations.addSelected`,{defaultValue:`Add selected`}),fe>0?` (${fe})`:``]})]})]})]})]})}function Le({filters:e,activeFilter:t,onSelect:n}){return c(`div`,{role:`tablist`,"aria-label":`Discovery granularity`,className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return c(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function Re({candidate:e,expandable:t,expanded:n,onToggleExpand:i,adoptedLabel:a}){let o=(e.children??[]).length;return r(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&o>0?r(`button`,{type:`button`,onClick:i,"aria-label":n?`Collapse`:`Expand`,"aria-expanded":n,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[c(n?Ce:pe,{className:`h-3.5 w-3.5`}),o]}):c(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),c(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&c(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:a})]})}function ze({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let i=e.children??[];return i.length===0?null:c(`div`,{className:`space-y-1 py-1`,children:i.map(e=>{let i=t.has(e.childNativeId),a=e.capabilities??[];return r(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${i?`opacity-50`:``}`,children:[c(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),a.length>0&&c(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:a.join(`, `)}),c(`button`,{onClick:()=>n(e.childNativeId),"aria-label":i?`Show child`:`Hide child`,title:i?`Show after adopt`:`Hide after adopt`,className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:c(i?ve:le,{className:`h-3 w-3`})})]},e.childNativeId)})})}n();function Be(e){let t=[];for(let n of e){if(n.type===`group`){t.push(...Be(n.fields));continue}`key`in n&&typeof n.key==`string`&&t.push(n.key)}return t}function Ve(e,t){if(!e)return{};let n=new Set(e.sections.flatMap(e=>Be(e.fields))),r={};for(let e of n)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}function He(e){return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{if(`value`in e){let{value:t,...n}=e;return n}return e})}))}}function Ue({integrationId:e,addonId:t,name:n,kind:a,mode:s,brokerKind:l,canTest:u=!1,trpc:f,onClose:p}){let{t:m}=Se(),g=o(),{data:_,isLoading:v}=w({id:e},{enabled:s===`account`||s===`broker`}),y=i(()=>{let e=_?.brokerId;return typeof e==`string`?e:null},[_]),{data:b,isLoading:x}=N({addonId:t,nodeId:`hub`},{enabled:s===`account`}),ee=i(()=>b?He(b):null,[b]),S=d(),C=t=>{S.mutate({id:e,settings:t},{onSuccess:()=>{g.invalidateQueries(),p()}})};return c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onClick:p,children:r(`div`,{className:`max-h-[85vh] w-full max-w-lg overflow-y-auto rounded-xl border border-border bg-surface p-5 shadow-xl`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`mb-3 flex items-center justify-between`,children:[r(`h2`,{className:`text-sm font-semibold text-foreground`,children:[m(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]}),c(`button`,{onClick:p,className:`rounded-md p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":m(`common.close`,{defaultValue:`Close`}),children:c(xe,{className:`h-4 w-4`})})]}),s===`broker`?l?r(`div`,{className:`space-y-3`,children:[c(`p`,{className:`text-[11px] text-foreground-subtle`,children:m(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),y&&r(`p`,{className:`text-[11px] text-foreground`,children:[m(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,c(`span`,{className:`font-mono text-foreground-subtle`,children:y})]}),S.isPending?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(J,{className:`h-3 w-3 animate-spin`}),m(`integrations.saving`,{defaultValue:`Saving…`})]}):c(U,{kind:l,onResolved:e=>{C({brokerId:e})},onBack:p}),S.isError&&c(`p`,{className:`text-[11px] text-danger`,children:m(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):c(`p`,{className:`text-[11px] text-danger`,children:m(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):s===`account`?v||x?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(J,{className:`h-3 w-3 animate-spin`}),m(`integrations.loading`,{defaultValue:`Loading…`})]}):c(H,{addonId:t,configSchema:ee,canTest:u,initialName:n,initialConfig:Ve(ee,_??{}),submitLabel:m(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e})=>C(e),onBack:p}):c(h,{trpc:f,addonId:t,nodeId:`hub`,title:n})]})})}function We(e){return e==null?!1:e.sections.some(e=>e.fields.length>0)}n();function Ge(){let{t}=Se(),{integrationId:n}=ge(),d=o(),f=he(),[m,h]=me(),g=u(),[x,S]=s(!1),[w,T]=s(!1),[A,j]=s(!1),[M,P]=s(!1),[ne,F]=s(!1),{data:z,isLoading:B}=k({id:n??``},{enabled:!!n}),{data:H}=N({addonId:z?.addonId??``,nodeId:`hub`},{enabled:!!z?.addonId}),{data:U,isSuccess:W}=p(),G=i(()=>{let e=z?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[U,z?.addonId,W]),{data:le}=y({}),ue=i(()=>(le?.providers??[]).some(e=>e.addonId===z?.addonId),[le,z?.addonId]),K=G!==null,de=z?.info?.fixed===!0,pe=K?G===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),ve=i(()=>{let e=z?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.brokerKind??null},[U,z?.addonId,W]),Ce=i(()=>{let e=z?.addonId;return!e||!W?!1:(U??[]).find(t=>t.addonId===e)?.canTest===!0},[U,z?.addonId,W]),Y=i(()=>{let e=z?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.mode??null},[U,z?.addonId,W]);l(()=>{m.get(`add`)===`1`&&K&&(S(!0),h(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[m,K,h]);let Ee=H!=null&&Array.isArray(H.sections)&&H.sections.some(e=>e.fields.length>0),{data:De}=L({addonId:z?.addonId??``,nodeId:`hub`},{enabled:!!z?.addonId&&Y!==`account`}),Oe=Y!==null&&Y!==`account`&&We(De),ke=i(()=>z?.addonId?[z.addonId]:[],[z?.addonId]),{data:Ae}=v({projection:`slim`},{refetchInterval:3e4}),X=[[`integrations`,`get`],{input:{id:n??``},type:`query`}],Me=b({onMutate:async e=>{await d.cancelQueries({queryKey:X});let t=d.getQueryData(X);return t!=null&&d.setQueryData(X,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&d.setQueryData(X,r.previous)},onSettled:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Z=R({onSuccess:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]}),P(!1),f(`/integrations`)}}),Ne=E({onSuccess:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=D({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Pe=C({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=O({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),$=i(()=>Ae??[],[Ae]),Le=i(()=>{let e=new Map;for(let t of $)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[$]),Re=e(e=>Le.get(e)??null,[Le]),ze=e(e=>c(ae,{type:e,size:`sm`}),[]),Be=e(e=>f(`/devices/${String(e)}`),[f]),Ve=i(()=>{let e=z?.addonId;return e?$.filter(t=>t.addonId===e):[]},[$,z?.addonId]),He=i(()=>te(Ve).length,[Ve]);return B?r(`div`,{className:`p-4`,children:[c(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),c(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):z?r(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[c(re,{items:[{label:`Integrations`,onClick:()=>f(`/integrations`)},{label:z.name}]}),r(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[r(`div`,{className:`flex items-center gap-3 min-w-0`,children:[c(`img`,{src:`/api/addon-assets/${z.addonId}/assets/icon.svg`,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:e=>{e.target.style.display=`none`}}),r(`div`,{className:`min-w-0`,children:[c(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:z.name}),r(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[z.addonId,` · `,He,` `,t(`integrations.devices`)]})]})]}),r(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[ue&&r(`button`,{onClick:()=>T(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the network for devices (incl. a different subnet)`,children:[c(oe,{className:`h-3.5 w-3.5`}),`Scan network`]}),!de&&r(`button`,{onClick:()=>S(!0),disabled:!K,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:pe,children:[c(V,{className:`h-3.5 w-3.5`}),pe]}),r(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Me.isPending?`opacity-60`:``} ${z.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[c(ee,{checked:z.enabled,onCheckedChange:e=>Me.mutate({id:n,enabled:e}),disabled:Me.isPending,"aria-label":z.enabled?`Disable integration`:`Enable integration`}),c(`span`,{className:`text-[11px] font-medium ${z.enabled?`text-success`:`text-foreground-subtle`}`,children:z.enabled?`Enabled`:`Disabled`}),Me.isPending&&c(J,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Y!==`standalone`&&(Ee||G===`device-adoption`)&&r(`button`,{onClick:()=>j(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[c(_e,{className:`h-3 w-3`}),t(`integrations.config`)]}),r(`button`,{onClick:()=>F(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:t(`integrations.logs`,{defaultValue:`View logs`}),children:[c(ye,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),c(I,{label:`Restart`,icon:ce,title:`Restart "${z.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${He} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Ne.isPending,action:()=>Ne.mutateAsync({addonId:z.addonId})}),!de&&r(`button`,{onClick:()=>P(!0),className:`flex items-center gap-1.5 rounded-lg border border-danger bg-danger/10 px-3 py-1.5 text-[11px] font-medium text-danger hover:bg-danger hover:text-background transition-colors`,title:t(`integrations.delete`,{defaultValue:`Delete integration`}),children:[c(be,{className:`h-3 w-3`}),t(`integrations.delete`,{defaultValue:`Delete`})]})]})]}),Oe&&c(we,{nodeId:null,addonIds:ke,level:`global`,surface:`integration`,title:t(`integrations.settings`,{defaultValue:`Settings`})}),c(ie,{context:`integration-detail`,devices:$,trpc:g.trpcClient,forceAddon:z.addonId,urlScope:`root`,lsKey:`integration-detail:${z.addonId}`,resolveIntegrationIcon:ze,resolveParent:Re,onNavigate:Be,batchActions:{remove:Q.mutate,disable:Pe.mutate,enable:Fe.mutate},...de?{}:{onDeleteDevice:e=>Q.mutate({deviceId:e.id})}}),x&&n&&G===`device-adoption`&&c(Ie,{addonId:z.addonId,integrationId:n,onClose:()=>S(!1)}),x&&n&&G===`device-provider`&&c(je,{open:x,integrationId:n,addonId:z.addonId,onClose:()=>S(!1)}),w&&z&&c(se,{open:w,scope:{addonId:z.addonId,label:z.name},onClose:()=>T(!1)}),A&&n&&G!==null&&Y!==null&&c(Ue,{integrationId:n,addonId:z.addonId,name:z.name,kind:G,mode:Y,brokerKind:ve,canTest:Ce,trpc:g.trpcClient,onClose:()=>j(!1)}),ne&&c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>F(!1),children:r(`div`,{className:`flex flex-col rounded-xl border border-border bg-surface shadow-xl w-full max-w-5xl h-[80vh]`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5`,children:[r(`div`,{className:`flex items-center gap-2 min-w-0`,children:[c(ye,{className:`h-4 w-4 text-primary shrink-0`}),c(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:z.name}),r(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[z.addonId,n?` · ${n}`:``]})]}),c(`button`,{onClick:()=>F(!1),className:`flex h-7 w-7 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close logs`,children:c(xe,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:c(_,{addonId:z.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})}),M&&c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:()=>!Z.isPending&&P(!1),children:r(`div`,{className:`rounded-xl border border-border bg-background p-5 shadow-2xl w-96 space-y-3`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`flex items-start gap-3`,children:[c(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg bg-danger/10 shrink-0`,children:c(q,{className:`h-4 w-4 text-danger`})}),r(`div`,{className:`min-w-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.deleteTitle`,{defaultValue:`Delete integration?`})}),c(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:t(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:z.name,count:He})})]})]}),Z.error&&c(`div`,{className:`rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:Z.error instanceof Error?Z.error.message:String(Z.error)}),r(`div`,{className:`flex items-center justify-end gap-2 pt-1`,children:[c(`button`,{onClick:()=>P(!1),disabled:Z.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:t(`integrations.cancel`,{defaultValue:`Cancel`})}),c(`button`,{onClick:()=>Z.mutate({id:n}),disabled:Z.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-danger px-3 py-1.5 text-[11px] font-medium text-background hover:bg-danger/90 transition-colors disabled:opacity-60 disabled:cursor-not-allowed`,children:Z.isPending?r(a,{children:[c(J,{className:`h-3 w-3 animate-spin`}),t(`integrations.deleting`,{defaultValue:`Deleting…`})]}):r(a,{children:[c(be,{className:`h-3 w-3`}),t(`integrations.confirmDelete`,{defaultValue:`Delete integration`})]})})]})]})})]}):r(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[c(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:c(Te,{className:`h-6 w-6 text-foreground-subtle`})}),r(`div`,{className:`space-y-1 max-w-sm`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),c(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:n??``})})]}),r(`button`,{onClick:()=>f(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[c(fe,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}export{Ge as IntegrationDetailPage};
@@ -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{Q as l}from"./player-overlays-Bjt3KKaE.js";import{Ci as u,Ei as d,Fr as f,Kr as p,T as m,_n as h,ki as g,r as _,tn as v,w as y,wr as ee}from"./src-Do9J_PcR.js";import{t as b}from"./ProviderIcon-1oq0Ms1x.js";import{t as x}from"./plus-VwU2KiHj.js";import{i as te,n as ne,r as re,t as S}from"./ScanNetworkModal-Cq19W7kZ.js";import{t as C}from"./refresh-cw-DC4HHe02.js";import{B as w,H as T,L as E,Q as D,X as O,f as k,r as ie,t as A,v as j,w as M,z as ae}from"./index-CTFcrmzA.js";import{t as oe}from"./AdminPage-CCD07UMs.js";import"./useEventInvalidation-DL8D3OJq.js";import{t as N}from"./StatusBadge-CeptlsPG.js";import{t as P}from"./useBodyScrollLock-BDocajQE.js";t();function F(e,t){let[n,r]=o(!1);return c(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}t();function I({providerId:e,onImport:t,onSkip:r}){let{t:i}=A(),[a,l]=o(new Set),u=f(),d=u.data,p=u.isPending||!u.data&&!u.isError;c(()=>{e&&(u.isPending||u.data||u.mutate({addonId:e}))},[e,u]);function m(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(p)return n(`div`,{className:`flex flex-col items-center py-12`,children:[s(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),s(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:i(`integrations.searchingDevices`)})]});let h=d??[];return n(`div`,{className:`space-y-4`,children:[s(`p`,{className:`text-xs text-foreground-subtle`,children:h.length>0?i(`integrations.foundDevices`,{count:h.length}):i(`integrations.noDevicesFound`)}),h.length>0&&s(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:h.map(e=>{let t=e.stableId,r=e.suggestedName??t,o=a.has(t),c=e.alreadyOnboarded===!0;return n(`button`,{onClick:()=>{c||m(t)},disabled:c,title:c?i(`integrations.alreadyAddedHint`,{defaultValue:`Already added as "{{name}}" — re-adding would overwrite its settings.`,name:e.onboardedName??r}):void 0,className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${c?`border-border bg-surface opacity-60 cursor-not-allowed`:o?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[s(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${o&&!c?`border-primary bg-primary`:`border-border`}`,children:o&&!c&&s(w,{className:`h-3 w-3 text-primary-foreground`})}),s(T,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),s(`span`,{className:`text-xs font-medium text-foreground truncate`,children:r}),c&&s(`span`,{className:`ml-auto flex-shrink-0 rounded bg-surface-muted px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:i(`integrations.alreadyAdded`,{defaultValue:`Already added`})})]},t)})}),n(`div`,{className:`flex items-center justify-between pt-2`,children:[s(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.skip`)}),h.length>0&&n(`button`,{onClick:()=>t(Array.from(a)),disabled:a.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[i(`integrations.importSelected`),` (`,a.size,`)`]})]})]})}function L({onSelect:e,onClose:t,pendingAddonId:r=null}){let{t:i}=A(),a=O(),{data:o,isLoading:c}=d();if(c)return s(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-14 rounded-lg bg-surface animate-pulse`},e))});let l=r!==null;return n(`div`,{className:`space-y-2`,children:[(o??[]).map(o=>{let c=o.instanceMode===`unique`&&o.existingInstances.length>0,u=r===o.addonId,d=l;return n(`button`,{disabled:d,onClick:()=>{if(!d)if(c){let e=o.existingInstances[0].id;t(),a(`/integrations/${e}`)}else e(o.addonId,o.instanceMode,o.discoveryMode,o.name,o.kind,o.brokerKind,o.mode,o.canTest)},className:`flex w-full items-center gap-3 rounded-lg border border-border bg-surface p-3 text-left hover:border-foreground-subtle/30 transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[o.iconUrl?s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`img`,{src:o.iconUrl,alt:``,className:`h-5 w-5`})}):s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`span`,{className:`text-sm`,style:{color:o.color},children:`◉`})}),n(`div`,{className:`flex-1 min-w-0`,children:[s(`p`,{className:`text-xs font-semibold text-foreground`,children:o.name}),o.description&&s(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 truncate`,children:o.description})]}),u?s(M,{className:`h-4 w-4 animate-spin text-primary flex-shrink-0`}):c?n(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[s(k,{className:`h-3 w-3`}),i(`integrations.manage`)]}):s(E,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},o.addonId)}),(o??[]).length===0&&s(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:i(`integrations.noProviders`)})]})}t();function se(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}var R=2e4;function ce({open:e,onClose:t}){let{t:l}=A(),d=O(),p=a(),[m,g]=o(`picker`),[_,v]=o(null),[y,b]=o(null),[x,te]=o(`manual`),[S,C]=o(null),[w,T]=o(``),[E,D]=o(null),[k,j]=o(null),[ae,oe]=o(!1),{data:N}=h({addonId:_??``,nodeId:`hub`},{enabled:_!=null}),ce=r(()=>N?se(N):null,[N]),z=u({onSuccess:()=>p.invalidateQueries({queryKey:[[`integrations`]]})}),B=f(),le=B.data;c(()=>{m!==`discovery`||!y||!_||B.isPending||B.data||B.mutate({addonId:_})},[m,y,_,B]);let V=ee({onSuccess:()=>p.invalidateQueries({queryKey:[[`deviceManager`]]})});function H(e,t,n,r,i,a,o,s){if(!z.isPending){if(v(e),oe(s),te(n),T(r),j(null),o===`broker`){if(!a){j(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}C(a),g(`broker`);return}if(o===`account`){g(`config`);return}U(e,r)}}async function U(e,n){try{let r=await z.mutateAsync({addonId:e,name:n,settings:{}});t(),q(),d(`/integrations/${r.id}?add=1`)}catch{}}async function W(e){if(_)try{let t=await z.mutateAsync({addonId:_,name:e.name,settings:e.config});b(t.id),x===`auto`||x===`both`?g(`discovery`):K(t.id)}catch{}}async function G(e){if(_)try{let t=await z.mutateAsync({addonId:_,name:w,settings:{brokerId:e}});D(t.id),b(t.id),K(t.id)}catch{}}async function ue(e){if(_){for(let t of e){let e=le?.find(e=>e.stableId===t);e&&await V.mutateAsync({addonId:_,candidate:e,...E===null?{}:{integrationId:E}})}K()}}function K(e){let n=e??y??_;t(),q(),n&&d(`/integrations/${n}`)}function q(){g(`picker`),v(null),b(null),te(`manual`),C(null),T(``),D(null),j(null),oe(!1)}function J(){t(),q()}P(e);let Y=z.isPending,X=F(Y,R);if(!e)return null;let Z={picker:l(`integrations.newIntegration`),config:l(`integrations.configureIntegration`),discovery:l(`integrations.importDevices`),broker:l(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},Q=Y?_:null,$=z.error,de=Y&&!X;return n(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:de?void 0:J}),n(`div`,{className:`relative z-10 w-full max-w-lg max-h-[calc(85dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[n(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:Z[m]}),s(`button`,{onClick:J,disabled:de,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:s(ie,{className:`h-4 w-4`})})]}),n(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[$&&!Y&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:$ instanceof Error?$.message:String($)}),m===`picker`&&n(i,{children:[k&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:k}),s(L,{onSelect:H,onClose:J,pendingAddonId:Q})]}),m===`config`&&_&&s(ne,{addonId:_,configSchema:ce??null,canTest:ae,onSave:W,onBack:()=>g(`picker`)}),m===`broker`&&S&&s(re,{kind:S,onResolved:e=>{G(e)},onBack:()=>g(`picker`)}),m===`discovery`&&y&&s(I,{providerId:y,onImport:ue,onSkip:K})]}),Y&&n(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm px-6 text-center`,children:[s(M,{className:`h-6 w-6 animate-spin text-primary`}),s(`p`,{className:`text-xs font-medium text-foreground`,children:l(`integrations.creating`,{defaultValue:`Creating integration…`})}),!X&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:l(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),X&&n(i,{children:[s(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:l(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),s(`button`,{onClick:J,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:l(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})]})}function z({integration:e,expanded:t,onToggleExpand:r}){return n(`div`,{className:`flex items-center gap-2.5`,children:[s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e.addonId)},"aria-label":t?`Collapse`:`Expand`,"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:s(t?ae:E,{className:`h-3.5 w-3.5`})}),s(b,{type:e.addonId,size:`sm`}),n(`div`,{className:`flex min-w-0 flex-col`,children:[s(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),s(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function B(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>s(z,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:`Devices`,headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>`${e.deviceCount} device${e.deviceCount===1?``:`s`}`},{key:`status`,header:`Status`,headerClassName:`w-[15%]`,cell:e=>s(N,{status:e.status})}]}t();function le(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var V=`expand`;function H(){let{t}=A(),a=O(),c=l(),[u]=D(),[d,f]=o(!1),h=e(()=>f(!0),[]),ee=e(()=>f(!1),[]),[ne,re]=o(!1),w=e(()=>re(!0),[]),T=e(()=>re(!1),[]);_([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),_([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:E,isLoading:k,refetch:ie}=g(void 0),{data:M,isLoading:ae,refetch:N}=p({projection:`slim`}),P=r(()=>M??[],[M]),F=r(()=>E??[],[E]),I=r(()=>{let e=new Map;for(let t of P)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[P]),L=r(()=>{let e=new Map;for(let t of m(P)){let n=t.addonId??``;n&&e.set(n,(e.get(n)??0)+1)}return e},[P]),se=r(()=>F.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:le(e),deviceCount:L.get(e.addonId)??0})),[F,L]),R=u.get(V),z=e(e=>{let t=new URLSearchParams(window.location.search);t.get(V)===e?t.delete(V):t.set(V,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),H=e(e=>a(`/integrations/${e.id}`),[a]),U=e(e=>I.get(e)??null,[I]),W=e(e=>s(b,{type:e,size:`sm`}),[]),G=e(e=>a(`/devices/${String(e)}`),[a]),ue=e(e=>s(y,{context:`integration-detail`,devices:P,trpc:c.trpcClient,forceAddon:e.addonId,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:W,resolveParent:U,onNavigate:G}),[P,c.trpcClient,W,U,G]),K=e(e=>R===e.addonId,[R]),q=r(()=>B({isExpanded:K,onToggleExpand:z}),[K,z]),J=e(e=>`${e.name} ${e.addonId}`,[]),Y=e(e=>e.addonId,[]),X=e(()=>{ie(),N()},[ie,N]),Z=k||ae,Q=F.length>0;return n(oe,{icon:j,title:t(`nav.integrations`,`Integrations`),actions:n(i,{children:[s(`button`,{onClick:X,disabled:Z,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:`Refresh`,children:s(C,{className:v(`h-3.5 w-3.5`,Z&&`animate-spin`)})}),n(`button`,{onClick:w,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the local network for devices`,children:[s(te,{className:`h-3.5 w-3.5`}),`Scan network`]}),n(`button`,{onClick:h,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[s(x,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[Z&&s(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Z&&!Q&&n(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[s(`p`,{className:`text-sm`,children:`No integrations configured.`}),s(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!Z&&Q&&s(y,{mode:`generic`,items:se,getKey:Y,getSearchText:J,columns:q,onRowClick:H,isExpanded:K,renderExpanded:ue,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),s(ce,{open:d,onClose:ee}),s(S,{open:ne,onClose:T})]})}export{H as IntegrationsPage};
@@ -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{Q as l}from"./player-overlays-Bjt3KKaE.js";import{$i as u,An as d,Bi as f,Gi as p,Hi as m,Ii as h,It as g,Ji as _,Ki as v,Li as y,Lt as b,Nt as x,Qi as S,Ri as ee,Rt as C,Ui as te,Vi as ne,Wi as w,Xi as T,Xt as re,Yi as E,Zi as D,ia as ie,js as O,kn as k,na as ae,qi as oe,ra as se,rt as A,tt as ce,zi as j}from"./src-Do9J_PcR.js";import{nt as M,st as N}from"./src-Dz-5lByR.js";import{t as P}from"./boxes-AZJJIRLF.js";import{t as F}from"./copy-F3szhd3t.js";import{t as I}from"./play-Bj2uDa-E.js";import{t as le}from"./refresh-cw-DC4HHe02.js";import{t as ue}from"./rotate-ccw-DMm-mk2i.js";import{t as L}from"./server-Dg0FD7ES.js";import{t as R}from"./shield-HNSKTw2D.js";import{t as z}from"./square-DOxz21cx.js";import{t as B}from"./wifi-CBHL4Gpd.js";import{B as V,C as de,D as H,J as U,M as W,S as fe,a as pe,c as me,r as he,w as G,y as K}from"./index-CTFcrmzA.js";import{t as ge}from"./AdminPage-CCD07UMs.js";import{t as _e}from"./AdminTabs-C0Wy66CI.js";import{t as ve}from"./NodeAddonsSettingsPanel-D95kz9WA.js";import{t as q}from"./AddonCollectionPage-BSXsNPWa.js";import{t as J}from"./addon-display-names-DvSEQty-.js";var ye=U(`log-in`,[[`path`,{d:`m10 17 5-5-5-5`,key:`1bsop3`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`,key:`u53s6r`}]]),be=U(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]),xe=U(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]);t();var Y=5e3,Se={connected:!1,endpoint:null};function Ce(){let e=a(),t=d({capName:`network-access`},{refetchInterval:Y}),n=k(void 0,{refetchInterval:Y}),i=r(()=>J(n.data??[]),[n.data]),c=r(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:i.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,i]),[l,u]=o(null),[f,p]=o({}),m=(t,n)=>{let r=n?.addonId;e.invalidateQueries({queryKey:[[`networkAccess`,`getStatus`],{input:{addonId:r},type:`query`}]}),u(null),p(e=>{if(r===void 0||!(r in e))return e;let t={...e};return delete t[r],t})},h=(e,t)=>{u(null);let n=t?.addonId;if(n===void 0)return;let r=e instanceof Error?e.message:String(e);p(e=>({...e,[n]:r}))},g=se({onSuccess:m,onError:h}),_=ie({onSuccess:m,onError:h});return s(q,{title:`Remote Access`,subtitle:`Public-facing tunnels that expose this hub to the internet (Cloudflare Tunnel, ngrok, …). Settings, Logs and Events are docked under every provider.`,pageIcon:H,itemIcon:H,capability:`network-access`,installButtonLabel:`Add tunnel`,items:c,isLoading:t.isLoading,emptyTitle:`No remote-access providers installed`,emptyDescription:`Install a tunnel addon (e.g. @camstack/addon-cloudflare) to expose this hub publicly.`,renderStatusBadges:e=>s(Te,{addonId:e.addonId}),itemError:e=>f[e.addonId]??null,renderPrimaryAction:e=>s(Ee,{addonId:e.addonId,busyId:l,onStart:e=>{u(e),g.mutate({addonId:e})},onStop:e=>{u(e),_.mutate({addonId:e})}})})}function we(e){let{data:t}=ae({addonId:e},{refetchInterval:Y,retry:!1}),n=t?N.safeParse(t):null;return n?.success?n.data:Se}function Te({addonId:e}){let t=we(e);return n(i,{children:[s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.connected?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.connected?`Connected`:`Disconnected`}),t.endpoint&&n(`a`,{href:t.endpoint.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-[10px] text-emerald-700 dark:text-emerald-300 hover:underline flex items-center gap-1`,children:[s(W,{className:`h-3 w-3`}),t.endpoint.url]})]})}function Ee({addonId:e,busyId:t,onStart:r,onStop:i}){let a=we(e),o=t===e;return a.connected?n(C,{size:`sm`,variant:`secondary`,disabled:o,onClick:()=>i(e),children:[o?s(G,{className:`h-3 w-3 animate-spin`}):s(z,{className:`h-3 w-3`}),`Stop`]}):n(C,{size:`sm`,variant:`primary`,disabled:o,onClick:()=>r(e),children:[o?s(G,{className:`h-3 w-3 animate-spin`}):s(I,{className:`h-3 w-3`}),`Start`]})}t();var De=3e4;function Oe(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function ke(){let e=d({capName:`turn-provider`},{refetchInterval:De}),t=k(void 0,{refetchInterval:De}),i=O(),a=i.data??[],o=r(()=>J(t.data??[]),[t.data]);return s(q,{title:`TURN Servers`,subtitle:`ICE servers used for WebRTC NAT traversal. Multiple providers can coexist — the WebRTC layer concatenates servers from all enabled providers per session.`,pageIcon:K,itemIcon:K,capability:`turn-provider`,installButtonLabel:`Add provider`,items:r(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:o.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,o]),isLoading:e.isLoading,emptyTitle:`No TURN providers installed`,emptyDescription:`Install a TURN addon (e.g. @camstack/addon-cloudflare) to enable WebRTC behind restrictive NATs.`,renderExpandedPanel:e=>s(Ae,{addonId:e.addonId,enabled:e.isActive}),trailing:n(g,{children:[n(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[n(`div`,{children:[s(`div`,{className:`text-sm font-semibold`,children:`Combined ICE server list`}),s(`div`,{className:`text-xs text-foreground-subtle`,children:`What the WebRTC layer fetches per-session.`})]}),s(C,{size:`sm`,variant:`secondary`,onClick:()=>i.refetch(),disabled:i.isFetching,children:`Refresh`})]}),s(`div`,{className:`p-4`,children:a.length===0?s(`div`,{className:`text-xs text-foreground-subtle`,children:`No servers from enabled providers.`}):s(`div`,{className:`flex flex-col gap-3`,children:a.map((e,t)=>{let r=Array.isArray(e.urls)?e.urls:[e.urls];return n(`div`,{className:`rounded border border-border bg-surface`,children:[(e.username||e.credential)&&n(`div`,{className:`px-3 py-1.5 border-b border-border text-[10px] font-mono text-foreground-subtle flex items-center gap-3`,children:[e.username&&n(`span`,{children:[s(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,s(`span`,{className:`text-foreground`,children:e.username})]}),e.credential&&n(`span`,{children:[s(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,s(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),s(`ul`,{className:`divide-y divide-border`,children:r.map(e=>s(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},t)})})})]})})}function Ae({addonId:e,enabled:t}){let i=O({addonId:e},{enabled:t,retry:!1}),a=r(()=>Oe(i.data??[]),[i.data]);return!t||a.length===0?null:n(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[n(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Discovered ICE servers (`,a.length,`)`]}),s(`div`,{className:`flex flex-wrap gap-1`,children:a.map(e=>s(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground`,children:e},e))})]})}t();var je={lan:K,wifi:B,docker:P,vpn:de,loopback:L,other:L},Me={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},Ne=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function Pe(e){let{interfaces:t,disabled:i,hideLoopback:a,ipv4Only:o,emptyMessage:c}=e,l=r(()=>t.filter(e=>!(a&&e.kind===`loopback`||o&&e.family!==`IPv4`)),[t,a,o]),u=r(()=>{let e=new Map;for(let t of l){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return Ne.filter(t=>e.has(t)).map(t=>({kind:t,items:e.get(t)}))},[l]),d=t=>e.mode===`single`?e.value===t:e.value.includes(t),f=t=>{if(i||t.kind===`loopback`)return;if(e.mode===`single`){e.onChange(e.value===t.address?null:t.address);return}let n=new Set(e.value);n.has(t.address)?n.delete(t.address):n.add(t.address),e.onChange([...n])};return l.length===0?s(`div`,{className:`text-xs text-foreground-subtle italic`,children:c??`No addresses available.`}):s(`div`,{className:`flex flex-col gap-3`,children:u.map(({kind:t,items:r})=>n(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[n(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[s(je[t]??L,{className:`h-3.5 w-3.5 text-foreground-subtle`}),s(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:Me[t]??t}),n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,r.length]})]}),s(`ul`,{className:`divide-y divide-border`,children:r.map(t=>{let r=d(t.address),a=t.kind===`loopback`,o=!t.plausible&&!a;return n(`li`,{className:`flex items-center gap-3 px-3 py-2 ${a?`opacity-60 cursor-not-allowed`:i?`opacity-60`:o?`cursor-pointer hover:bg-surface-hover/30 bg-amber-500/[0.04]`:`cursor-pointer hover:bg-surface-hover/30`}`,onClick:()=>f(t),children:[s(`span`,{className:`flex items-center justify-center h-4 w-4 rounded ${e.mode===`single`?`rounded-full`:`rounded`} border ${r?`border-primary bg-primary text-primary-foreground`:`border-border bg-surface`}`,children:r&&s(V,{className:`h-3 w-3`})}),n(`div`,{className:`flex-1 min-w-0 ${o?`text-foreground-subtle`:``}`,children:[n(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[s(`span`,{className:`font-mono text-xs font-semibold ${o?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),s(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-mono`,children:t.family}),t.preferred&&s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:`Auto-preferred`}),a&&s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:`Always included`}),o&&n(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:t.plausibleReason||void 0,children:[s(pe,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]}),n(`div`,{className:`text-xs text-foreground-subtle mt-0.5 font-mono break-all`,children:[t.address,t.cidr&&t.cidr!==t.address?` (${t.cidr})`:``]})]})]},`${t.name}-${t.family}-${t.address}`)})})]},t))})}t();var Fe={"lan-ipv4":{label:`IPv4`,className:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`},"lan-ipv6":{label:`IPv6`,className:`bg-violet-500/15 text-violet-700 dark:text-violet-300`},public:{label:`Public`,className:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},loopback:{label:`Loopback`,className:`bg-foreground-subtle/15 text-foreground-subtle`}};function X(e){return e.kind!==`loopback`}function Ie(e){return e.kind!==`loopback`}function Le(){let e=a(),t=l(),i=ne(void 0,{refetchInterval:3e4}),u=h(void 0),d=p({onSuccess:()=>{e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),m=te({onSuccess:t=>{w(t.addresses),e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),_=r(()=>i.data?.interfaces??[],[i.data]),b=y({port:typeof window<`u`?Number(window.location.port)||(window.location.protocol===`https:`?443:80):4e3,scheme:typeof window<`u`&&window.location.protocol===`https:`?`https`:`http`},{refetchInterval:3e4}),[S,w]=o([]),[T,re]=o(!1);c(()=>{!T&&u.data&&(w(u.data.addresses),re(!0))},[u.data,T]);let E=u.data?.addresses??[],D=r(()=>{if(S.length!==E.length)return!0;let e=[...S].toSorted(),t=[...E].toSorted();return e.some((e,n)=>e!==t[n])},[S,E]),ie=()=>{d.mutate({addresses:[...S]})},O=()=>{w(E)},k=()=>{w([])},ae=()=>{i.refetch(),b.refetch(),u.refetch(),A.refetch(),M.refetch()},se=async()=>{try{let e=await t.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info(`[network-addresses] race result`,e)}catch(e){console.warn(`[network-addresses] race failed`,e)}},A=ee(),j=v({onSuccess:()=>void A.refetch()}),M=f(),N=oe({onSuccess:()=>void M.refetch()}),P=b.data?.endpoints??[],F=A.data?.baseUrl??null,I=A.data?.resolved??null,L=M.data?.baseUrls??[],R=L.length===0,z=F===null,B=e=>R?e.kind===`lan-ipv4`||e.kind===`public`&&e.interfaceKind===`public`:L.includes(e.baseUrl),V=e=>F===null?I===e.baseUrl:F===e.baseUrl,de=e=>{if(!X(e))return;let t=R?P.filter(e=>X(e)&&B(e)).map(e=>e.baseUrl):[...L],n=t.includes(e.baseUrl)?t.filter(t=>t!==e.baseUrl):[...t,e.baseUrl];N.mutate({baseUrls:n})},H=e=>{if(Ie(e)){if(V(e)){z||j.mutate({baseUrl:null});return}j.mutate({baseUrl:e.baseUrl})}},U=r(()=>[{key:`url`,header:`Endpoint`,render:e=>n(`div`,{className:`min-w-0 py-0.5`,children:[s(`div`,{className:`font-mono text-[12px] break-all ${e.plausible?`text-foreground`:`text-foreground-subtle`}`,children:e.baseUrl}),n(`div`,{className:`mt-0.5 flex flex-wrap items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[s(`span`,{children:e.label}),e.interfaceKind!==`lan`&&e.interfaceKind!==`public`&&s(`span`,{className:`uppercase tracking-wide`,children:e.interfaceKind}),!e.plausible&&e.interfaceKind!==`loopback`&&n(`span`,{className:`inline-flex items-center gap-1 text-amber-700 dark:text-amber-300`,title:e.plausibleReason||void 0,children:[s(pe,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]})]})},{key:`kind`,header:`Kind`,nowrap:!0,render:e=>{let t=Fe[e.kind]??Fe.loopback;return s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.className}`,children:t.label})}},{key:`viewer`,headerRender:()=>n(`span`,{className:`inline-flex items-center gap-1`,children:[`Viewer`,R?s(`span`,{className:`text-[10px] font-normal normal-case text-foreground-subtle`,children:`auto`}):null]}),align:`center`,nowrap:!0,width:`w-24`,render:e=>{let t=X(e);return s(`label`,{className:`inline-flex justify-center ${t?`cursor-pointer`:`cursor-not-allowed opacity-40`}`,title:e.kind===`loopback`?`Loopback is not a client route.`:`Use this URL in the API / viewer race.`,children:s(x,{checked:t&&B(e),disabled:!t||N.isPending,onChange:()=>de(e),"aria-label":`Viewer: ${e.baseUrl}`})})}},{key:`notifications`,headerRender:()=>n(`span`,{className:`inline-flex items-center gap-1`,children:[`Notifications`,z?s(`span`,{className:`text-[10px] font-normal normal-case text-foreground-subtle`,children:`auto`}):null]}),align:`center`,nowrap:!0,width:`w-28`,render:e=>{let t=Ie(e);return s(`label`,{className:`inline-flex justify-center ${t?`cursor-pointer`:`cursor-not-allowed opacity-40`}`,title:t?`Notification links and deep links use this address.`:`Loopback is not a client route.`,children:s(x,{checked:t&&V(e),disabled:!t||j.isPending,onChange:()=>H(e),"aria-label":`Notifications: ${e.baseUrl}`})})}}],[R,z,L,F,I,N.isPending,j.isPending,P]);return n(ge,{children:[n(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[s(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Pin which host addresses exist, then tick the destinations each URL should serve. Viewer auto is IPv4 + public; every other row (including IPv6) can be ticked on.`}),n(`div`,{className:`flex items-center gap-2 shrink-0`,children:[n(C,{size:`sm`,variant:`secondary`,onClick:ae,disabled:i.isLoading,children:[s(le,{className:`h-3 w-3 ${i.isLoading?`animate-spin`:``}`}),`Refresh`]}),s(C,{size:`sm`,variant:`secondary`,onClick:se,children:`Probe race`})]})]}),n(g,{children:[n(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between gap-3 flex-wrap`,children:[n(`div`,{children:[s(`div`,{className:`text-sm font-semibold`,children:`Allowed addresses`}),s(`div`,{className:`text-xs text-foreground-subtle`,children:S.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${S.length} pinned`})]}),n(`div`,{className:`flex items-center gap-1`,children:[n(C,{size:`sm`,variant:`secondary`,onClick:()=>m.mutate(void 0),disabled:m.isPending||d.isPending,title:`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`,children:[s(me,{className:`h-3 w-3`}),m.isPending?`Detecting…`:`Best match`]}),n(C,{size:`sm`,variant:`secondary`,onClick:k,disabled:S.length===0||d.isPending,children:[s(ue,{className:`h-3 w-3`}),`Clear`]}),D&&s(C,{size:`sm`,variant:`secondary`,onClick:O,disabled:d.isPending,children:`Discard`}),n(C,{size:`sm`,variant:`primary`,onClick:ie,disabled:!D||d.isPending,children:[s(be,{className:`h-3 w-3`}),d.isPending?`Saving…`:`Save`]})]})]}),s(`div`,{className:`p-4`,children:s(Pe,{mode:`multiple`,interfaces:_,value:S,onChange:w,disabled:d.isPending,emptyMessage:i.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),n(g,{children:[n(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between gap-3 flex-wrap`,children:[n(`div`,{children:[s(`div`,{className:`text-sm font-semibold`,children:`Connection endpoints`}),s(`div`,{className:`text-xs text-foreground-subtle`,children:`Ranked URLs this hub advertises. Tick Viewer (many) and Notifications (one).`})]}),n(`div`,{className:`flex items-center gap-1`,children:[!R&&s(C,{size:`sm`,variant:`secondary`,disabled:N.isPending,onClick:()=>N.mutate({baseUrls:[]}),children:`Viewer → auto`}),!z&&s(C,{size:`sm`,variant:`secondary`,disabled:j.isPending,onClick:()=>j.mutate({baseUrl:null}),children:`Notifications → auto`})]})]}),z&&I===null&&s(`p`,{className:`px-4 pt-3 text-[11px] text-amber-600 dark:text-amber-400`,children:`No public address is reachable, so notification media ships as bytes only — a backend that can only take links (WhatsApp, gotify) receives none.`}),s(ce,{columns:U,rows:P,rowKey:e=>`${e.priority}-${e.baseUrl}`,minWidthPx:640,bordered:!1,mobileMode:`scroll`,emptyMessage:b.isLoading?`Loading…`:`No endpoints available.`,rowClassName:e=>e.plausible?void 0:`opacity-80`})]})]})}t();var Re={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},Z=5e3,ze=3e4,Be={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function Ve(){let e=d({capName:`mesh-network`},{refetchInterval:Z}),t=k(void 0,{refetchInterval:Z}),n=r(()=>J(t.data??[]),[t.data]);return s(q,{title:`Mesh Networks`,subtitle:`Private VPN meshes that connect CamStack to your other devices (Tailscale, Headscale, …). Each provider can also expose this hub publicly via its ingress (Tailscale Funnel).`,pageIcon:P,itemIcon:K,capability:`mesh-network`,installButtonLabel:`Add mesh`,items:r(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,n]),isLoading:e.isLoading,emptyTitle:`No mesh-network providers installed`,emptyDescription:`Install a mesh addon (e.g. @camstack/addon-tailscale) to join this hub into a private VPN mesh.`,renderStatusBadges:e=>s(He,{addonId:e.addonId}),renderPrimaryAction:e=>s(Ue,{addonId:e.addonId}),renderExpandedPanel:e=>s(We,{addonId:e.addonId})})}function Q(e){let{data:t,isLoading:n}=E({addonId:e},{refetchInterval:Z,retry:!1}),r=t?M.safeParse(t):null;return{status:r?.success?r.data:Be,isLoading:n}}function He({addonId:e}){let{status:t}=Q(e);return n(i,{children:[s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.joined?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.joined?`Joined`:`Not joined`}),t.joined&&n(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:[t.peerCount,` peer`,t.peerCount===1?``:`s`]})]})}function Ue({addonId:t}){let r=a(),[c,d]=o(!1),[f,p]=o(null),m=l(),{status:h}=Q(t),g=e(()=>{r.invalidateQueries({queryKey:[[`meshNetwork`]]})},[r]),_=u(),v=T({onSuccess:g}),y=S({onSuccess:g}),b=e(async()=>{d(!0);let e={cancelled:!1};p(e);try{let n=await _.mutateAsync({addonId:t});if(e.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!e.cancelled&&(await Ze(2e3),!e.cancelled);){let e=await m.trpcClient.meshNetwork.getStatus.query({addonId:t}).catch(()=>null),n=e?M.safeParse(e):null;if(n?.success&&n.data.joined){g();break}if(Date.now()-r>6e5)break}}finally{d(!1),p(null)}},[t,g,_,m]),x=e(()=>{f&&(f.cancelled=!0),d(!1),p(null)},[f]);return s(i,{children:h.joined?n(i,{children:[n(C,{size:`sm`,variant:`secondary`,disabled:v.isPending,onClick:()=>v.mutate({addonId:t}),children:[v.isPending?s(G,{className:`h-3 w-3 animate-spin`}):s(fe,{className:`h-3 w-3`}),`Disconnect`]}),n(C,{size:`sm`,variant:`ghost`,disabled:y.isPending,onClick:()=>y.mutate({addonId:t}),children:[y.isPending?s(G,{className:`h-3 w-3 animate-spin`}):s(xe,{className:`h-3 w-3`}),`Log out`]})]}):c?n(C,{size:`sm`,variant:`ghost`,onClick:x,children:[s(he,{className:`h-3 w-3 mr-1`}),` Cancel`]}):n(i,{children:[n(C,{size:`sm`,variant:`primary`,onClick:()=>void b(),children:[s(ye,{className:`h-3 w-3`}),`Connect`]}),n(C,{size:`sm`,variant:`ghost`,disabled:y.isPending,onClick:()=>y.mutate({addonId:t}),children:[y.isPending?s(G,{className:`h-3 w-3 animate-spin`}):s(xe,{className:`h-3 w-3`}),`Log out`]})]})})}function We({addonId:e}){let{status:t}=Q(e),r=D({addonId:e},{refetchInterval:ze,retry:!1});return n(`div`,{className:`rounded-lg border border-border bg-surface`,children:[n(`div`,{className:`p-4 space-y-4`,children:[t.error&&s(re,{message:t.error}),s(Ge,{status:t}),t.endpoints.length>0&&n(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Endpoints`}),t.endpoints.map(e=>n(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[n(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${Re[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?s(H,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),n(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-emerald-700 dark:text-emerald-300 hover:underline break-all flex items-center gap-1`,children:[s(W,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),s(`div`,{className:`border-t border-border`,children:s(qe,{peers:r.data?.peers??[],loading:r.isLoading})})]})}function Ge({status:e}){return s(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-1.5`,children:[{label:`Tenant`,value:e.tenantName||`—`},{label:`User`,value:e.userLogin??`—`},{label:`Control plane`,value:e.controlPlaneUrl||`—`},{label:`Mesh IP`,value:e.meshIp||`—`,mono:!0},{label:`MagicDNS`,value:e.magicDnsHostname||`—`,mono:!0},{label:`DNS suffix`,value:e.magicDnsSuffix||`—`,mono:!0},{label:`Peers`,value:String(e.peerCount)},{label:`Key expiry`,value:e.keyExpiry?Ke(e.keyExpiry):`—`}].map(e=>n(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[s(`span`,{className:`text-foreground-subtle shrink-0`,children:e.label}),s(`span`,{className:`text-foreground truncate ${e.mono?`font-mono`:``}`,children:e.value})]},e.label))})}function Ke(e){let t=e-Date.now();if(t<0)return`Expired ${Xe(e)}`;let n=Math.floor(t/864e5);if(n>60)return new Date(e).toLocaleDateString();if(n>1)return`in ${n} days`;let r=Math.floor(t/36e5);return r>1?`in ${r}h`:`in ${Math.max(1,Math.floor(t/6e4))} min`}function qe({peers:t,loading:i}){let a=r(()=>t.map(e=>({...e,_id:e.id})),[t]),o=e(e=>{e&&navigator.clipboard?.writeText(e)},[]),c=r(()=>[{key:`hostname`,header:`Hostname`,render:e=>n(`div`,{className:`flex flex-col`,children:[n(`div`,{className:`flex items-center gap-1.5`,children:[s(`span`,{className:`font-medium text-foreground`,children:e.hostname||`(unknown)`}),e.isSelf&&s(b,{variant:`info`,children:`self`}),e.exitNodeOption&&s(b,{variant:`warning`,children:`exit-node`})]}),e.userLogin&&s(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.userLogin})]})},{key:`magicDns`,header:`MagicDNS`,render:e=>e.magicDns?n(`div`,{className:`flex items-center gap-1`,children:[s(`span`,{className:`font-mono text-xs truncate`,children:e.magicDns}),s(`button`,{onClick:()=>o(e.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy MagicDNS`,children:s(F,{className:`h-3 w-3 text-foreground-subtle`})})]}):s(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:e=>{let t=e.addresses[0]??``;return t?n(`div`,{className:`flex items-center gap-1`,children:[s(`span`,{className:`font-mono text-xs`,children:t}),s(`button`,{onClick:()=>o(t),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy IP`,children:s(F,{className:`h-3 w-3 text-foreground-subtle`})})]}):s(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:`Connection`,render:e=>n(`div`,{className:`flex items-center gap-1.5`,children:[s(b,{variant:Je(e.connection),children:e.connection}),e.relay&&s(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.relay})]})},{key:`routes`,header:`Routes`,render:e=>e.advertisedRoutes.length>0?s(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):s(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:`TX / RX`,render:e=>n(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,Ye(e.txBytes),` · ↓ `,Ye(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>s(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?Xe(e.lastSeenMs):`—`})}],[o]);return i&&t.length===0?n(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[s(G,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):t.length===0?s(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No peers visible — your tailnet may be empty or the host is not joined.`}):s(`div`,{className:`p-4`,children:s(ce,{columns:c,rows:a,rowKey:e=>e._id,minWidthPx:820})})}function Je(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function Ye(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)}MB`:`${(e/1024/1024/1024).toFixed(2)}GB`}function Xe(e){let t=Date.now()-e;return t<6e4?`just now`:t<36e5?`${Math.round(t/6e4)}m ago`:t<864e5?`${Math.round(t/36e5)}h ago`:`${Math.round(t/864e5)}d ago`}function Ze(e){return new Promise(t=>setTimeout(t,e))}t();function $(e){if(e===null||e===``)return`—`;let t=e.replace(/:/g,``);return t.length<=16?e:`${t.slice(0,8)}…${t.slice(-8)}`}function Qe(){let e=a(),t=j(void 0,{refetchInterval:15e3}),r=m({onSuccess:()=>void e.invalidateQueries({queryKey:[[`localNetwork`]]})}),i=w({onSuccess:()=>void e.invalidateQueries({queryKey:[[`localNetwork`]]})}),c=_({onSuccess:()=>{d(!1),p(``),v(``),b(``),e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),l=t.data,[u,d]=o(!1),[f,p]=o(``),[h,v]=o(``),[y,b]=o(``),x=()=>{if(!l?.caCertPem)return;let e=new Blob([l.caCertPem],{type:`application/x-pem-file`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`camstack-ca.crt`,n.click(),URL.revokeObjectURL(t)},S=l?.mode===`uploaded`?`Uploaded`:l?.mode===`generated`?`Generated local CA`:`TLS disabled`;return n(`div`,{className:`flex flex-col gap-4`,children:[s(ve,{nodeId:`hub`,addonIds:[`local-network`],level:`global`,title:`LAN HTTP`,description:`Native apps on this Wi-Fi use http:// and skip the private certificate. The tunnel and this admin UI stay on HTTPS.`}),n(g,{className:`p-4 space-y-3`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(R,{className:`h-4 w-4 text-foreground-subtle`}),s(`h3`,{className:`text-sm font-semibold`,children:`Certificate`})]}),t.isError&&s(`p`,{className:`text-xs text-danger`,children:`Could not read TLS status.`}),l?.reissueError&&s(`p`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:l.reissueError}),l?.restartRequired&&s(`p`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:`Restart the hub to apply the new certificate.`}),n(`dl`,{className:`grid grid-cols-1 gap-2 text-xs sm:grid-cols-2`,children:[n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`Mode`}),s(`dd`,{className:`font-medium`,children:S})]}),n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`Valid to`}),s(`dd`,{className:`font-mono`,children:l?.validTo?new Date(l.validTo).toLocaleString():`—`})]}),n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`Leaf SHA-256`}),s(`dd`,{className:`font-mono`,title:l?.leafFingerprintSha256??void 0,children:$(l?.leafFingerprintSha256??null)})]}),n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`CA SHA-256`}),s(`dd`,{className:`font-mono`,title:l?.caFingerprintSha256??void 0,children:$(l?.caFingerprintSha256??null)})]})]}),l&&l.sans.length>0&&s(`div`,{className:`flex flex-wrap gap-1`,children:l.sans.map(e=>s(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 font-mono text-[10px] text-foreground-subtle`,children:e},e))}),n(`div`,{className:`flex flex-wrap gap-2`,children:[s(A,{label:`Regenerate`,title:`Issue a new leaf?`,description:`Issues a new leaf under the current local CA. Clients that trust the CA keep working. The HTTPS listener reloads.`,confirmLabel:`Regenerate`,disabled:l?.mode===`uploaded`||r.isPending,action:()=>r.mutateAsync({})}),s(C,{size:`sm`,variant:`outline`,onClick:()=>d(e=>!e),children:`Upload`}),l?.caCertPem&&s(C,{size:`sm`,variant:`outline`,onClick:x,children:`Download CA`}),l?.mode===`uploaded`&&s(A,{label:`Revert to generated`,title:`Drop the uploaded certificate?`,description:`Deletes the uploaded pair and returns to the generated local CA.`,confirmLabel:`Revert`,confirmVariant:`danger`,disabled:i.isPending,action:()=>i.mutateAsync({})})]}),u&&n(`div`,{className:`space-y-2 border-t border-border pt-3`,children:[n(`label`,{className:`block text-[11px] text-foreground-subtle`,children:[`Certificate PEM`,s(`textarea`,{value:f,onChange:e=>p(e.target.value),rows:6,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`})]}),n(`label`,{className:`block text-[11px] text-foreground-subtle`,children:[`Private key PEM`,s(`textarea`,{value:h,onChange:e=>v(e.target.value),rows:6,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`})]}),n(`label`,{className:`block text-[11px] text-foreground-subtle`,children:[`CA PEM (optional)`,s(`textarea`,{value:y,onChange:e=>b(e.target.value),rows:4,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`})]}),s(C,{size:`sm`,disabled:!f.trim()||!h.trim()||c.isPending,onClick:()=>c.mutate({certPem:f,keyPem:h,...y.trim()?{caPem:y}:{}}),children:`Save certificate`}),c.isError&&s(`p`,{className:`text-xs text-danger`,children:c.error instanceof Error?c.error.message:`Upload failed`})]})]})]})}function $e(){return s(`div`,{className:`flex flex-col p-4`,children:s(_e,{defaultTab:`addresses`,tabs:[{id:`local-access`,label:`Local access`,icon:B,content:s(Qe,{})},{id:`addresses`,label:`Network Addresses`,icon:L,content:s(Le,{})},{id:`remote-access`,label:`Remote Access`,icon:H,content:s(Ce,{})},{id:`mesh`,label:`Mesh Networks`,icon:P,content:s(Ve,{})},{id:`turn`,label:`TURN Servers`,icon:K,content:s(ke,{})}]})})}export{$e as NetworkPage};