@camstack/addon-admin-ui 1.2.356 → 1.2.357

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 (87) hide show
  1. package/dist/assets/{Addons-vaVt3N8c.js → Addons-BNOOF9Mv.js} +1 -1
  2. package/dist/assets/{AdminTabs-BOhyA0v_.js → AdminTabs-Bxj9C3Dy.js} +1 -1
  3. package/dist/assets/{AiProfiles-gc9Na6rv.js → AiProfiles-CRNStk_J.js} +1 -1
  4. package/dist/assets/{BrokerForm-Bxjn8Xkb.js → BrokerForm-61eZ_BQs.js} +1 -1
  5. package/dist/assets/{Build-DNhwnx2k.js → Build-Bo19wI67.js} +1 -1
  6. package/dist/assets/{Calendars-9eEuusHn.js → Calendars-CxIkYKMB.js} +1 -1
  7. package/dist/assets/{Capabilities-BuQgXiX1.js → Capabilities-DTXiVb2I.js} +1 -1
  8. package/dist/assets/Cluster-CAwWppiE.js +11 -0
  9. package/dist/assets/{ClusterStepModel-Cg0YqJM-.js → ClusterStepModel-DhxYveGL.js} +1 -1
  10. package/dist/assets/{CompositionEditor-DsZomdtR.js → CompositionEditor-Bvf3zgNl.js} +1 -1
  11. package/dist/assets/{CompositionEditorPage-CEYhfRyr.js → CompositionEditorPage-CQgnsFrf.js} +1 -1
  12. package/dist/assets/{Data-CxzcaPPX.js → Data-BGRBmkR_.js} +1 -1
  13. package/dist/assets/{DetectionIntelligence-esy4sm8-.js → DetectionIntelligence-VZ9CIaLa.js} +1 -1
  14. package/dist/assets/{DeviceDetail-BUFpgkeN.js → DeviceDetail-CrnxJ6Hc.js} +1 -1
  15. package/dist/assets/{DeviceDoActionFields-C_OPAByq.js → DeviceDoActionFields-D3Jdh2OV.js} +1 -1
  16. package/dist/assets/{Devices-D5wKCK9_.js → Devices-CBwOsnyo.js} +1 -1
  17. package/dist/assets/{EmbedPlayerPage-xTUcKS8t.js → EmbedPlayerPage-BWcoakS7.js} +1 -1
  18. package/dist/assets/{Events-BD2v1o2Z.js → Events-Dr5IMWMQ.js} +1 -1
  19. package/dist/assets/{Identity-hydVfEcG.js → Identity-DQ7LByxK.js} +1 -1
  20. package/dist/assets/{IntegrationDetail-IjNeTPn2.js → IntegrationDetail-CskqQg63.js} +1 -1
  21. package/dist/assets/{IntegrationHub-Czg3bSVM.js → IntegrationHub-T7WCtw8g.js} +1 -1
  22. package/dist/assets/{Integrations-xrJzBxAs.js → Integrations-BqdlA2Gi.js} +1 -1
  23. package/dist/assets/{Integrations-ErVYCOG1.js → Integrations-DDDwMXbl.js} +1 -1
  24. package/dist/assets/{Locations-BBu_JUg1.js → Locations-CxMnoEvK.js} +1 -1
  25. package/dist/assets/{Logs-hVhOlpsU.js → Logs-DP7amiQW.js} +1 -1
  26. package/dist/assets/{MotionZonesSettings-B8426WyB.js → MotionZonesSettings-40HbSg1J.js} +1 -1
  27. package/dist/assets/{MyAccess-D0PqfqUg.js → MyAccess-k7c8CGXR.js} +1 -1
  28. package/dist/assets/{Network-1FUHkoPH.js → Network-wpLc77BL.js} +1 -1
  29. package/dist/assets/{NodeAddonsSettingsPanel-Bin020YC.js → NodeAddonsSettingsPanel-C1eKgxhI.js} +1 -1
  30. package/dist/assets/{Notifications-DBedpZv-.js → Notifications-DAPVC99C.js} +1 -1
  31. package/dist/assets/{Plates-D1_YX1bj.js → Plates-hAYS43bp.js} +1 -1
  32. package/dist/assets/{PrivacyMaskSettings-C-lyYBaQ.js → PrivacyMaskSettings-9mlw-Sg2.js} +1 -1
  33. package/dist/assets/{Recordings-9M71-km4.js → Recordings-CF6Q6s4b.js} +1 -1
  34. package/dist/assets/{ScanNetworkModal-DjrnLqkB.js → ScanNetworkModal-CJGyqlYW.js} +1 -1
  35. package/dist/assets/{SceneMonitorEditor-CnTzBKHk.js → SceneMonitorEditor-DNVt27Re.js} +1 -1
  36. package/dist/assets/{Scenes-9o38vvfG.js → Scenes-oXjWvgG4.js} +1 -1
  37. package/dist/assets/{Secrets-Di_XuHEM.js → Secrets-I8Q8kwRj.js} +1 -1
  38. package/dist/assets/{Settings-CdsQXImT.js → Settings-VQUbUtH9.js} +1 -1
  39. package/dist/assets/{Showroom-CueI9Hof.js → Showroom-Bp0BOf3S.js} +1 -1
  40. package/dist/assets/{Terminal-CgkhEdVL.js → Terminal-tyLcs3hl.js} +1 -1
  41. package/dist/assets/{Viewer-CXSln4qp.js → Viewer-t4jfelvu.js} +1 -1
  42. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-D23uSeCV.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CIsQtLaa.js} +1 -1
  43. package/dist/assets/{archive-HjFKqcYJ.js → archive-DeR3e4g-.js} +1 -1
  44. package/dist/assets/{authed-media-DTi-1YAt.js → authed-media-st_x8Og8.js} +1 -1
  45. package/dist/assets/{boxes-Bhz-2O4q.js → boxes-DxeTkSiW.js} +1 -1
  46. package/dist/assets/circle-slash-CttzF2br.js +1 -0
  47. package/dist/assets/client-BqN2lVYf.js +357 -0
  48. package/dist/assets/crop-BEmkkd3b.js +1 -0
  49. package/dist/assets/{debounced-invalidate-BmvWt3Mf.js → debounced-invalidate-BWOIWEOF.js} +1 -1
  50. package/dist/assets/{device-integration-icon-vpQeGGPt.js → device-integration-icon-Ce7zluJx.js} +1 -1
  51. package/dist/assets/device-picker-model-x_xV7wRP.js +1 -0
  52. package/dist/assets/{dist-BVQ0qNkk.js → dist-9DPeVlno.js} +1 -1
  53. package/dist/assets/dist-CxwXQGCF.js +357 -0
  54. package/dist/assets/{face-bbox-DIMw9bdN.js → face-bbox-Bx59CISY.js} +1 -1
  55. package/dist/assets/{hard-drive-download-DGUpD-NK.js → hard-drive-download-BT7-6QED.js} +1 -1
  56. package/dist/assets/{hostInit-jbr3yepU.js → hostInit-DQ0THwU5.js} +1 -1
  57. package/dist/assets/{index-I9Gc2ACc.js → index-BNq9yPTv.js} +3 -3
  58. package/dist/assets/{layers-TAdyTRRS.js → layers-D1ITEDh9.js} +1 -1
  59. package/dist/assets/{location-owned-usage-D5P9h6fD.js → location-owned-usage-B5PZZAJ9.js} +1 -1
  60. package/dist/assets/{mf-entry-bootstrap-0-c002b961.js → mf-entry-bootstrap-0-bd894cd4.js} +2 -2
  61. package/dist/assets/mount-x_xV7wRP.js +1 -0
  62. package/dist/assets/{notification-schedule-field-DdO5UXE-.js → notification-schedule-field-Drw0rQZp.js} +1 -1
  63. package/dist/assets/{player-overlays-PPtffSZH.js → player-overlays-D4lg_avJ.js} +1 -1
  64. package/dist/assets/remoteEntry-YA5HmvZR.js +1 -0
  65. package/dist/assets/{send-qYTKAtys.js → send-CYTiWXyC.js} +1 -1
  66. package/dist/assets/{settings-2-BfvfZMIZ.js → settings-2-DVqttbaa.js} +1 -1
  67. package/dist/assets/{src-EnVigh-D.js → src-DOjmjjKA.js} +17 -17
  68. package/dist/assets/{unlink-CvsfIFka.js → unlink-ZWAv-UAl.js} +1 -1
  69. package/dist/assets/{use-scenes-feed-DupdXK3r.js → use-scenes-feed-BgsO7otE.js} +1 -1
  70. package/dist/assets/{use-stationary-objects-Blrh3fb3.js → use-stationary-objects-e1GejQDW.js} +1 -1
  71. package/dist/assets/useEventInvalidation-x_xV7wRP.js +1 -0
  72. package/dist/assets/{useNodeUrlSelection-DemYJ0D7.js → useNodeUrlSelection-DoS5q0lF.js} +1 -1
  73. package/dist/assets/user-round-D1OVtUFE.js +1 -0
  74. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CFcHLszk.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CFTJqMAA.js} +2 -2
  75. package/dist/index.html +7 -7
  76. package/dist/server/addon.js +26 -2
  77. package/package.json +1 -1
  78. package/dist/assets/Cluster-BGpeqgpD.js +0 -11
  79. package/dist/assets/circle-slash-RDy1aZkR.js +0 -1
  80. package/dist/assets/client-DuQQ55XQ.js +0 -357
  81. package/dist/assets/crop-BWtvQsYY.js +0 -1
  82. package/dist/assets/device-picker-model-C1VaG3XC.js +0 -1
  83. package/dist/assets/dist-B46vwY9Q.js +0 -357
  84. package/dist/assets/mount-C1VaG3XC.js +0 -1
  85. package/dist/assets/remoteEntry-CdbrIBDO.js +0 -1
  86. package/dist/assets/useEventInvalidation-C1VaG3XC.js +0 -1
  87. package/dist/assets/user-round-BCwcukON.js +0 -1
@@ -1 +1 @@
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{X as f,Z as p,at as m,ct as h,ft as g,gt as _,ht as v,st as y,vt as b}from"./player-overlays-PPtffSZH.js";import{$n as x,$o as S,$t as C,An as w,As as T,Bt as E,Cd as D,Cn as O,Cs as k,Dn as A,Dt as j,En as M,Es as N,Fd as P,Fn as F,Fs as I,Gd as L,Gt as R,Ht as z,If as B,In as V,Is as ee,Jn as te,Ju as H,Kn as U,Kt as W,Lo as G,Lu as K,Ms as ne,Nn as q,Ns as re,Nt as ie,Os as ae,Pd as oe,Ps as se,Qo as ce,Qs as le,Ss as ue,Su as de,Tn as fe,Ts as pe,Ut as me,Vd as he,Wf as ge,Wt as _e,Wu as ve,Xt as ye,Yt as be,Zd as xe,Zt as Se,_s as Ce,as as we,at as Te,au as Ee,bn as J,bs as De,cd as Oe,cf as ke,cs as Ae,df as je,ds as Me,er as Ne,es as Pe,fs as Fe,gf as Ie,gs as Le,hd as Re,if as ze,is as Be,js as Ve,ks as He,lc as Ue,ls as We,ms as Ge,on as Ke,os as qe,ou as Je,ps as Ye,qd as Xe,qn as Ze,qs as Qe,qu as $e,rd as et,rs as tt,sa as nt,sn as rt,tr as Y,ts as it,us as at,vs as ot,wf as st,wn as ct,wr as lt,ws as ut,wu as dt,xf as ft,xn as pt,xs as mt,xu as ht,yn as gt,ys as _t,yu as vt}from"./src-EnVigh-D.js";import{a as yt,c as bt,d as xt,f as St,i as Ct,m as wt,n as Tt,o as Et,p as Dt,r as Ot,s as kt,t as At}from"./debounced-invalidate-BmvWt3Mf.js";import{Un as jt,pi as Mt}from"./client-DuQQ55XQ.js";import{t as Nt}from"./useTranslation-Bc5yH9V9.js";import"./mount-C1VaG3XC.js";import{et as Pt}from"./index-I9Gc2ACc.js";import{t as Ft}from"./AdminPage-BSFohA3i.js";import{a as It,i as Lt,r as Rt,t as zt}from"./authed-media-DTi-1YAt.js";import{t as Bt}from"./use-stationary-objects-Blrh3fb3.js";import{t as Vt}from"./AdminTabs-BOhyA0v_.js";import{t as Ht}from"./format-size-DIxKXxtj.js";var Ut=b(`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`}]]),Wt=b(`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`}]]),Gt=b(`circle`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),Kt=b(`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`}]]),qt=b(`folder-plus`,[[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`M9 13h6`,key:`1uhe8q`}],[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]),Jt=b(`keyboard`,[[`path`,{d:`M10 8h.01`,key:`1r9ogq`}],[`path`,{d:`M12 12h.01`,key:`1mp3jc`}],[`path`,{d:`M14 8h.01`,key:`1primd`}],[`path`,{d:`M16 12h.01`,key:`1l6xoz`}],[`path`,{d:`M18 8h.01`,key:`emo2bl`}],[`path`,{d:`M6 8h.01`,key:`x9i8wu`}],[`path`,{d:`M7 16h10`,key:`wp8him`}],[`path`,{d:`M8 12h.01`,key:`czm47f`}],[`rect`,{width:`20`,height:`16`,x:`2`,y:`4`,rx:`2`,key:`18n3k1`}]]),Yt=b(`list-video`,[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M10 12H3`,key:`1ulcyk`}],[`path`,{d:`M10 19H3`,key:`108z41`}],[`path`,{d:`M15 12.003a1 1 0 0 1 1.517-.859l4.997 2.997a1 1 0 0 1 0 1.718l-4.997 2.997a1 1 0 0 1-1.517-.86z`,key:`ms4nik`}]]),Xt=b(`maximize`,[[`path`,{d:`M8 3H5a2 2 0 0 0-2 2v3`,key:`1dcmit`}],[`path`,{d:`M21 8V5a2 2 0 0 0-2-2h-3`,key:`1e4gt3`}],[`path`,{d:`M3 16v3a2 2 0 0 0 2 2h3`,key:`wsl5sc`}],[`path`,{d:`M16 21h3a2 2 0 0 0 2-2v-3`,key:`18trek`}]]),Zt=b(`package-plus`,[[`path`,{d:`M12 22V12`,key:`d0xqtd`}],[`path`,{d:`M16 17h6`,key:`1ook5g`}],[`path`,{d:`M19 14v6`,key:`1ckrd5`}],[`path`,{d:`M21 10.535V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.729l7 4a2 2 0 0 0 2 .001l1.675-.955`,key:`28k6lz`}],[`path`,{d:`M3.29 7 12 12l8.71-5`,key:`19ckod`}],[`path`,{d:`m7.5 4.27 8.997 5.148`,key:`9yrvtv`}]]),Qt=b(`redo-2`,[[`path`,{d:`m15 14 5-5-5-5`,key:`12vg1m`}],[`path`,{d:`M20 9H9.5A5.5 5.5 0 0 0 4 14.5A5.5 5.5 0 0 0 9.5 20H13`,key:`6uklza`}]]),$t=b(`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`}]]),en=b(`wand-sparkles`,[[`path`,{d:`m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72`,key:`ul74o6`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`M5 6v4`,key:`ilb8ba`}],[`path`,{d:`M19 14v4`,key:`blhpug`}],[`path`,{d:`M10 2v2`,key:`7u0qdc`}],[`path`,{d:`M7 8H3`,key:`zfb6yr`}],[`path`,{d:`M21 16h-4`,key:`1cnmox`}],[`path`,{d:`M11 3H9`,key:`1obp7u`}]]);n();function tn(e){let t=e.subLabel??e.label;if(t!==void 0)return t;let n=e.audioLabels?.[0]?.label;return n!==void 0&&n.length>0?n:void 0}var nn=720*60*60*1e3;function rn(e){let t=[];for(let n of e)t.push(...n);return t}function an(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function on(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 sn(e,t){return`${String(e)}:${t}`}function cn(e,t){let n=new Map,r=new Set;for(let i of e){let e=sn(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 ln(e,t){return{since:e.fromMs??t-nn,until:e.toMs??t}}var un=[`native`,`raster`,`standin`];function dn(e){return un.some(t=>t===e)}var fn={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 pn(e){return e===`standin`?fn.standin:e===`raster`?fn.raster:null}var mn={"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 hn(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:mn[r]??r,detail:i,raw:t}}function gn(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 _n({row:e,cameraName:t,nowMs:n,onOpenDetail:i,selected:a=!1,onToggleSelect:o,score:s,provenance:c,footer:l}){let d=It(e.mediaId===void 0?Lt(`track`,e.trackId):Rt(e.mediaId)),f=Math.round(e.importance*100),p=s===void 0?void 0:Math.round(s*100),m=gn(e.windowMs),_=()=>i(e),v=pn(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:_,className:`h-full w-full cursor-zoom-in object-cover`}):u(`button`,{type:`button`,onClick:_,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(g,{className:`h-6 w-6 opacity-60`})}),o&&u(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(sn(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(wt,{className:`h-4 w-4 text-primary`}):u(h,{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)}),v!==null&&u(`span`,{className:`absolute bottom-1 right-1 z-10 rounded px-1.5 py-0.5 text-[10px] font-semibold text-white ${v.tone===`warning`?`bg-warning/90`:`bg-black/70`}`,title:v.title,children:v.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(Xe,{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(st,{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($e,{className:`h-3 w-3`})})]})]}),r(`button`,{type:`button`,onClick:_,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,tn(e)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,tn(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:St(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 vn=1400,yn=`Admin-gated URL — opens only inside an authenticated session`;function bn({label:t,value:n,title:i}){let[a,o]=l(!1),s=te();return d(()=>{if(!a)return;let e=setTimeout(()=>o(!1),vn);return()=>clearTimeout(e)},[a]),r(`button`,{type:`button`,onClick:e(()=>{(async()=>{try{await navigator.clipboard.writeText(n),o(!0)}catch{await s({title:`Copy the media URL`,message:`Clipboard access was refused. Select the URL below and copy it manually.`,label:`${t} URL`,defaultValue:n,readOnly:!0,cancelLabel:`Close`})}})()},[n,t,s]),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?ft:ke,{className:`h-2.5 w-2.5 shrink-0`}),u(`span`,{className:`truncate`,children:a?`Copied`:t})]})}function xn({localUrl:e,publicUrl:t}){return r(`div`,{className:`flex flex-wrap gap-1`,children:[u(bn,{label:`Local`,value:e,title:`Copy LAN URL — ${yn}`}),t&&u(bn,{label:`Public`,value:t,title:`Copy public URL — ${yn}`})]})}var Sn={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`,confirmationCrop:`Confirmation crop (what the gate saw)`,debugCrop:`Debug crop (why this decision)`,sceneFrame:`Scene frame (clean)`,lastSceneFrame:`Last frame (clean)`};function Cn(e){return e in Sn}function wn(e){return Cn(e)?Sn[e]:e}function Tn(e,t){return`${e}${t}`}n();var En=3e4;function Dn(t){let[n,r]=l(null),i=e(e=>{r(t=>t??e)},[]);return d(()=>{t||r(null)},[t]),{publicOrigin:n,probes:t?u(On,{onOrigin:i}):null}}function On({onOrigin:e}){let{data:t}=lt({capName:`network-access`});return u(s,{children:(t??[]).map(t=>u(kn,{addonId:t.addonId,onOrigin:e},t.addonId))})}function kn({addonId:e,onOrigin:t}){let{data:n}=G({addonId:e},{refetchInterval:En,retry:!1});return d(()=>{let e=n?jt.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 An=typeof se==`function`,jn=`Track flags arrive with the next server update`;function Mn(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var Nn=An?se:Mn;function Pn(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 Fn({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 In({deviceId:e,trackId:t,markForTrain:n,debug:i,favourited:a,onChange:o}){let s=Nn(),c=U(),[d,f]=l(null),p=d?.markForTrain??n===!0,m=d?.debug??i===!0,h=d?.favourited??a===!0,g=!An||s.isPending,_=An?void 0:jn,v=n=>{g||(async()=>{try{let r=Pn(await s.mutateAsync({deviceId:e,trackId:t,flags:n}));if(!r)return;f(r),o?.(r)}catch(e){let t=e instanceof Error?e.message:``;await c({title:`Could not update this track`,message:t===``?`Could not update this track. Check the server logs.`:t,variant:`danger`})}})()};return r(`div`,{className:`grid gap-1.5 sm:grid-cols-2`,children:[u(Fn,{label:`Mark for training`,hint:`Keeps this track and its media past retention`,checked:p,disabled:g,..._===void 0?{}:{title:_},icon:u(Xe,{className:`h-4 w-4`}),onToggle:()=>v({markForTrain:!p})}),u(Fn,{label:`Debug`,hint:`Flag this track for diagnostic attention`,checked:m,disabled:g,..._===void 0?{}:{title:_},icon:u(st,{className:`h-4 w-4`}),onToggle:()=>v({debug:!m})}),u(Fn,{label:`Favourited`,hint:`Keeps this track and its media past retention`,checked:h,disabled:g,..._===void 0?{}:{title:_},icon:u($e,{className:`h-4 w-4`}),onToggle:()=>v({favourited:!h})})]})}var Ln=100,Rn=120,zn={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Bn=e=>e<0?0:e>1?1:e,Vn=e=>Math.round(e*100)/100;function Hn(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 Un(e,t,n){if(e.length===0||t===null)return zn;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return zn;let a=Hn(e,n?.maxPoints??Rn).map(e=>({x:Vn(Bn(e.x/r)*Ln),y:Vn(Bn(e.y/i)*Ln)})),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:Vn(Bn(e.x/r)*Ln),y:Vn(Bn(e.y/i)*Ln),mediaId:e.mediaId})),u=null,d=-1;for(let t of e){let e=Bn(t.bbox.w/r)*Bn(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:Vn(Bn(u.bbox.x/r)*Ln),y:Vn(Bn(u.bbox.y/i)*Ln),w:Vn(Bn(u.bbox.w/r)*Ln),h:Vn(Bn(u.bbox.h/i)*Ln)}:null}}var Wn=typeof we==`function`,Gn=`Track deletion arrives with the next server update`;function Kn(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var qn=Wn?we:Kn;n();var Jn=15e3,Yn=f();function Xn({url:e,label:t}){let{src:n,failed:r}=It(e);return n===null?u(`div`,{className:`flex h-full w-full items-center justify-center bg-surface-hover`,children:r?u(g,{className:`h-4 w-4 text-foreground-subtle opacity-60`}):u(P,{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 Zn=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),Qn=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`,`sceneFrame`,`lastSceneFrame`]);function $n(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 er({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.mediaId)}:void 0,children:u(`title`,{children:`Snapshot checkpoint — click to view this frame`})},`snap-${String(e.mediaId)}-${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 X({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 tr({row:t,cameraName:n,deleteAvailable:i,onClose:o,onDeleted:c,onFlagsChanged:f}){let p=m(),h=U(),_=Ze(),v=qn(),b=t!==null,x=t?.deviceId??0,S=t?.trackId??``,C=t?.timestamp??0,w=t?.windowMs??0,{data:T}=at({deviceId:x,trackId:S},{enabled:b}),{data:E}=k({trackId:S,deviceId:x},{enabled:b}),D=T?.bestEventId===void 0?void 0:Number(T.bestEventId),{data:A}=Ge({ownerType:`object`,eventId:D??0,deviceId:x},{enabled:b&&D!==void 0&&Number.isFinite(D)}),{data:j}=Je({deviceId:x},{enabled:b}),M=(j??[]).find(e=>e.addonId!==void 0)?.addonId,{data:N}=Ee({deviceId:x,since:C-Jn,until:C+w+Jn,provider:M??``},{enabled:b&&M!==void 0}),[F,I]=l(null),[L,R]=l(!1),{publicOrigin:z,probes:B}=Dn(b);d(()=>{I(null)},[x,S]);let ee=a(()=>{let e=E??[],t=A??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[E,A]),te=F??ee,H=It(te?te.url:void 0),W=a(()=>{let e=new Set,t=[];for(let n of[...A??[],...E??[]])e.has(n.mediaId)||(e.add(n.mediaId),t.push(n));return t},[A,E]),G=a(()=>W.find(e=>Zn.has(e.kind))??null,[W]),K=$n(It(G?G.url:void 0).src),ne=a(()=>Un(T?.positions??[],K,{snapshots:(T?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaId:e.mediaId}))}),[T?.positions,T?.snapshots,K]),q=e(e=>{let t=W.find(t=>t.mediaId===e);t&&I(t)},[W]);if(t===null)return null;let re=H.src,ie=te?.kind,ae=ie!==void 0&&Qn.has(ie)&&K!==null&&(T?.positions.length??0)>=2,oe=N&&N.length>0?N[0]:null,se=()=>{oe&&(R(!0),(async()=>{try{let e=await p.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:oe.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{h({title:`Clip unavailable`,message:`Could not resolve clip playback. Check the server logs.`,variant:`warning`})}finally{R(!1)}})())},ce=()=>{!i||v.isPending||(async()=>{if(await _({title:`Delete track`,message:`Delete this track and every image and clip captured for it? This cannot be undone.`,confirmLabel:`Delete`,variant:`danger`}))try{await v.mutateAsync({deviceId:t.deviceId,trackIds:[t.trackId]}),c()}catch{await h({title:`Delete failed`,message:`Failed to delete this track. Check the server logs.`,variant:`danger`})}})()},le=Math.round(t.importance*100),ue=T?.importanceReason?`${String(le)}% · ${T.importanceReason}`:`${String(le)}%`,de=T?.zonesVisited&&T.zonesVisited.length>0?T.zonesVisited.join(`, `):`—`,fe=T?.audioLabels&&T.audioLabels.length>0?T.audioLabels:t.audioLabels&&t.audioLabels.length>0?t.audioLabels:void 0,pe=fe===void 0?`—`:fe.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `),me=T?T.totalDistance.toFixed(2):`—`,he=hn(T?.previewMissReason),ge=Dt(T?T.firstSeen:C),_e=T?Dt(T.lastSeen):`—`;return u(pt,{open:!0,onOpenChange:e=>!e&&o(),children:r(O,{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,tn(t)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,tn(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(dt,{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:[re?u(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:u(Tt,{src:re,alt:`Key frame from ${n}`,fit:`natural`,className:`w-full`,overlay:ae?u(er,{overlay:ne,onPickSnapshot:q}):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:H.failed?r(s,{children:[u(g,{className:`h-8 w-8 opacity-60`}),u(`span`,{className:`text-[11px]`,children:`Key-frame media unavailable`})]}):u(P,{className:`h-6 w-6 animate-spin opacity-70`})}),W.length>0&&u(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:W.map(e=>{let t=wn(e.kind),n=Tn(Yn,e.url),i=z?Tn(z,e.url):null;return r(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[u(`button`,{type:`button`,onClick:()=>I(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${t} · ${Dt(e.timestamp)}`,children:u(Xn,{url:e.url,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:Dt(e.timestamp),children:xt(e.timestamp)})]}),u(xn,{localUrl:n,publicUrl:i})]},e.mediaId)})}),B,oe&&r(V,{variant:`secondary`,onClick:se,disabled:L,children:[L?u(P,{className:`h-3.5 w-3.5 animate-spin`}):u(xe,{className:`h-3.5 w-3.5`}),` `,`View clip`]}),u(In,{deviceId:t.deviceId,trackId:t.trackId,...(T?.markForTrain??t.markForTrain)===void 0?{}:{markForTrain:T?.markForTrain??t.markForTrain},...(T?.debug??t.debug)===void 0?{}:{debug:T?.debug??t.debug},...(T?.favourited??t.favourited)===void 0?{}:{favourited:T?.favourited??t.favourited},onChange:f}),he!==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:he.sentence}),u(`code`,{className:`mt-1 block break-all font-mono text-[10px] text-foreground-subtle`,children:he.raw})]}),r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[u(X,{label:`Camera`,value:n}),u(X,{label:`Class`,value:t.className}),u(X,{label:`Label`,value:t.label??`—`}),u(X,{label:`Sub-label`,value:t.subLabel??`—`}),u(X,{label:`Importance`,value:ue}),u(X,{label:`Zones visited`,value:de}),u(X,{label:`Audio heard`,value:pe}),u(X,{label:`Total distance`,value:me}),u(X,{label:`First seen`,value:ge}),u(X,{label:`Last seen`,value:_e}),u(X,{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:Gn,children:r(V,{variant:`secondary`,onClick:ce,disabled:!i||v.isPending,children:[v.isPending?u(P,{className:`h-3.5 w-3.5 animate-spin`}):u(y,{className:`h-3.5 w-3.5`}),` `,`Delete track`]})})})]})})}var nr={status:`debug.tape.status`,promote:`debug.tape.promote`,list:`debug.tape.list`,tracks:`debug.tape.tracks`,review:`debug.tape.review`,release:`debug.tape.release`,remove:`debug.tape.delete`},rr={setRelation:`debug.gt.setRelation`,setPurity:`debug.gt.setPurity`,list:`debug.gt.list`},ir=p(`/addon/pipeline-analytics/tape-export`),ar=10*6e4;function or(e){return`${ir}?tapeId=${encodeURIComponent(e)}`}var sr=`The server answered in a shape this build does not understand.`;function cr(e){return e instanceof Error?e.message:`The action failed.`}function Z(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Q(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function lr(e,t){if(!(t in e))return;let n=e[t];return n===null?null:typeof n==`number`&&Number.isFinite(n)?n:void 0}function $(e,t){let n=e[t];return typeof n==`string`?n:null}function ur(e,t){let n=e[t];return typeof n==`boolean`?n:null}function dr(e,t){if(!Array.isArray(e))return null;let n=[];for(let r of e){let e=t(r);if(e===null)return null;n.push(e)}return n}function fr(e){return e===`off`||e===`recording`||e===`refused`||e===`failing`||e===`unknown`}function pr(e){if(!Z(e))return null;let t=Q(e,`deviceId`),n=e.state,r=Q(e,`gapsSinceArmed`),i=lr(e,`segmentsHeld`),a=lr(e,`bytesLastHour`),o=lr(e,`bytesHeld`);if(t===null||!fr(n)||r===null||i===void 0||a===void 0||o===void 0)return null;let s=$(e,`reason`),c=Q(e,`segmentOriginMs`),l=Q(e,`framesPerMin`),u=Q(e,`heldFromMs`),d=Q(e,`heldToMs`),f=$(e,`shelfError`);return{deviceId:t,state:n,gapsSinceArmed:r,segmentsHeld:i,bytesLastHour:a,bytesHeld:o,...s===null?{}:{reason:s},...c===null?{}:{segmentOriginMs:c},...l===null?{}:{framesPerMin:l},...u===null?{}:{heldFromMs:u},...d===null?{}:{heldToMs:d},...f===null?{}:{shelfError:f}}}function mr(e){return Z(e)?dr(e.cameras,pr):null}function hr(e){if(!Z(e))return null;let t=$(e,`id`),n=Q(e,`deviceId`),r=$(e,`scenario`),i=e.lighting,a=Q(e,`fromMs`),o=Q(e,`toMs`),s=e.state,c=Q(e,`frames`),l=Q(e,`gaps`),u=Q(e,`bytes`),d=ur(e,`reviewed`),f=ur(e,`released`),p=dr(e.tracks,e=>typeof e==`string`?e:null),m=Q(e,`tracksStillStored`);return t===null||n===null||r===null||i!==`day`&&i!==`ir`||a===null||o===null||s!==`complete`&&s!==`incomplete`||c===null||l===null||u===null||d===null||f===null||p===null||m===null?null:{id:t,deviceId:n,scenario:r,note:$(e,`note`),lighting:i,fromMs:a,toMs:o,state:s,frames:c,gaps:l,bytes:u,reviewed:d,released:f,tracks:p,tracksStillStored:m}}function gr(e){return Z(e)?dr(e.tapes,hr):null}function _r(e){if(!Z(e))return null;let t=$(e,`trackId`),n=Q(e,`firstT`),r=Q(e,`lastT`),i=Q(e,`boundFrames`),a=$(e,`cls`),o=ur(e,`stillStored`);return t===null||n===null||r===null||i===null||a===null||o===null?null:{trackId:t,firstT:n,lastT:r,boundFrames:i,cls:a,stillStored:o}}function vr(e){if(!Z(e))return null;let t=$(e,`tapeId`),n=Q(e,`deviceId`),r=Q(e,`fromMs`),i=Q(e,`toMs`),a=ur(e,`reviewed`),o=dr(e.lanes,_r);return t===null||n===null||r===null||i===null||a===null||o===null?null:{tapeId:t,deviceId:n,fromMs:r,toMs:i,reviewed:a,lanes:o}}function yr(e){if(!Z(e))return null;if(e.ok===!1){let t=$(e,`reason`),n=$(e,`detail`);return t===null||n===null?null:{ok:!1,reason:t,detail:n}}if(e.ok!==!0)return null;let t=$(e,`tapeId`),n=e.state,r=Q(e,`frames`),i=Q(e,`gaps`),a=Q(e,`pinnedTracks`),o=Q(e,`bytes`);return t===null||n!==`complete`&&n!==`incomplete`||r===null||i===null||a===null||o===null?null:{ok:!0,tapeId:t,state:n,frames:r,gaps:i,pinnedTracks:a,bytes:o}}function br(e){if(!Z(e))return null;let t=e.status;if(t===`released`){let n=Q(e,`unpinned`),r=ur(e,`pinsSettled`);return n===null||r===null?null:{status:t,unpinned:n,pinsSettled:r}}if(t===`already-released`||t===`not-found`)return{status:t};if(t===`unavailable`){let n=$(e,`reason`);return n===null?null:{status:t,reason:n}}return null}function xr(e){if(!Z(e))return null;let t=e.status;if(t===`deleted`||t===`pins-owed`||t===`not-found`)return{status:t};if(t===`unavailable`){let n=$(e,`reason`);return n===null?null:{status:t,reason:n}}return null}function Sr(e){switch(e.status){case`released`:case`deleted`:return null;case`already-released`:return`This tape was already released.`;case`not-found`:return`That tape no longer exists — it may have been released or deleted elsewhere.`;case`pins-owed`:return`Refused: this tape still names pins not yet taken back. Try again shortly — the ledger settles them automatically.`;case`unavailable`:return`Unavailable on this node: ${e.reason}`}}function Cr(e){if(!Z(e))return null;let t=$(e,`leftTrackId`),n=$(e,`rightTrackId`),r=e.relation,i=e.presence;return t===null||n===null||r!==`same-subject`&&r!==`different-subjects`?null:{leftTrackId:t,rightTrackId:n,relation:r,presence:i===`continuous`?`continuous`:null}}function wr(e){if(!Z(e))return null;let t=$(e,`sourceTrackId`),n=e.purity;return t===null||n!==`mixed`&&n!==`not-a-subject`?null:{sourceTrackId:t,purity:n,switchAtMs:Q(e,`switchAtMs`)}}function Tr(e){if(!Z(e))return null;let t=dr(e.relations,Cr),n=dr(e.purities,wr),r=ur(e,`truncated`);return t===null||n===null||r===null?null:{relations:t,purities:n,truncated:r}}function Er(e){if(!e.truncated)return null;let t=e.relations.length+e.purities.length;return`Showing the first ${String(t)} marks — more exist for this window.`}function Dr(e){return e.filter(e=>e.segmentsHeld===null||e.segmentsHeld>0).map(e=>({deviceId:e.deviceId,segmentsUnknown:e.segmentsHeld===null}))}function Or(e){return e.slice(1).map((t,n)=>({trackId:e[n]??t,otherTrackId:t}))}function kr(e){return e.flatMap((t,n)=>e.slice(n+1).map(e=>({trackId:t,otherTrackId:e})))}function Ar(e,t){let n=[];for(let r of t.relations){let t=r.leftTrackId===e?r.rightTrackId:r.rightTrackId===e?r.leftTrackId:null;if(t===null)continue;let i=r.relation===`same-subject`?`same as`:`different from`;n.push(`${i} ${t}${r.presence===`continuous`?` (continuous)`:``}`)}for(let r of t.purities)r.sourceTrackId===e&&n.push(r.purity===`not-a-subject`?`not a subject`:r.switchAtMs===null?`mixed`:`mixed at switch`);return n}function jr(e){switch(e.state){case`off`:return`Off`;case`recording`:return`Recording`;case`refused`:return`Refused: ${e.reason??`unknown reason`}`;case`failing`:return`Failing: ${e.reason??`unknown reason`}`;case`unknown`:return`Unknown: ${e.reason??`unknown reason`}`}}var Mr={"window-too-long":`A promoted window is at most 30 minutes.`,"window-in-future":`The window ends in the future.`,"window-not-recorded":`No segment covers that window — the camera was not recording then, or it is older than 24 h.`,"invalid-scenario":`The scenario must be a slug: lowercase letters, digits and dashes, 3–64 characters.`,"promotion-budget":`A promotion budget is full (60 tapes, 1 GiB, 3 000 pinned tracks). Release or delete a tape already committed as a case first.`,"empty-window":`No frame was recorded in that window.`,"shelf-unreadable":`The camera's recorded segments could not be listed, so the window cannot be proven whole.`,"not-post-processing-node":`This node does not post-process frames, so it records no tracking tapes.`,"artifacts-elsewhere":`The artifacts storage location is on another node; tapes are recorded only where it lives.`,"tapes-not-started":`The tape recorder has not started on this node (or failed to).`};function Nr(e,t){let n=Mr[e]??`Refused (${e}).`;return t.length>0?`${n} ${t}`:n}function Pr(e){if(e.length===0)return null;let t=new Date(e).getTime();return Number.isFinite(t)?t:null}function Fr(e){return e<1024*1024?`${(e/1024).toFixed(0)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function Ir(e){return e===null?`unknown`:Fr(e)}function Lr(e){return e===null?`unknown`:String(e)}function Rr(e,t){let n=t.trim();return e===404?`This tape no longer exists on this node (unknown tape).`:e===503?n.length>0?n:`Tapes are unavailable on this node.`:e===500?n.length>0?n:`The export could not be read (the tape may have just been released or deleted).`:`Download failed (${String(e)}).`}n();function zr({cameras:e,call:t,onPromoted:n}){let[i,a]=l(``),[o,s]=l(``),[c,d]=l(``),[f,p]=l(``),[m,h]=l(``),[g,_]=l(`auto`),[v,y]=l(!1),[b,x]=l(null),S=async()=>{let r=Number.parseInt(i===``?e[0]?.value??``:i,10),a=Pr(o),s=Pr(c);if(!Number.isFinite(r)||a===null||s===null){x(`Pick a camera and both ends of the window.`);return}y(!0),x(null);try{let e=yr(await t(nr.promote,{deviceId:r,fromMs:a,toMs:s,scenario:f,...m.trim().length>0?{note:m.trim()}:{},...g===`day`||g===`ir`?{lighting:g}:{}}));e===null?x(sr):e.ok?(x(`Promoted ${e.tapeId}: ${String(e.frames)} frames, ${Fr(e.bytes)}, ${String(e.pinnedTracks)} tracks pinned`+(e.state===`incomplete`?` — incomplete (it has gaps) and cannot become a case.`:`.`)),n()):x(Nr(e.reason,e.detail))}catch(e){x(cr(e))}finally{y(!1)}};return r(`div`,{className:`flex flex-wrap items-end gap-2 rounded-md border border-border px-3 py-2`,children:[u(`div`,{className:`w-40`,children:u(F,{value:i,options:[...e],onChange:e=>a(e.target.value),"aria-label":`Camera`})}),u(J,{type:`datetime-local`,"aria-label":`From`,value:o,onChange:e=>s(e.target.value),className:`w-48`}),u(J,{type:`datetime-local`,"aria-label":`To`,value:c,onChange:e=>d(e.target.value),className:`w-48`}),u(J,{"aria-label":`Scenario`,placeholder:`615-door-groups`,value:f,onChange:e=>p(e.target.value),className:`w-44`}),u(J,{"aria-label":`Note`,placeholder:`optional note`,value:m,onChange:e=>h(e.target.value),className:`w-52`}),u(`div`,{className:`w-28`,children:u(F,{value:g,"aria-label":`Lighting`,options:[{value:`auto`,label:`Lighting: auto`},{value:`day`,label:`day`},{value:`ir`,label:`ir`}],onChange:e=>_(e.target.value)})}),r(V,{onClick:()=>void S(),disabled:v||e.length===0,children:[v?u(P,{className:`h-3.5 w-3.5 animate-spin`}):null,` Promote window`]}),u(`p`,{className:`w-full text-xs text-foreground-subtle`,children:`A promoted tape may be shared as a test case — keep the scenario slug and note free of names or other personal data.`}),b!==null&&u(`p`,{className:`w-full text-xs text-foreground`,children:b})]})}var Br=`pipeline-analytics`,Vr=`debug.listTracks`,Hr=`debug.analyze`,Ur=p(`/addon/pipeline-analytics/debug-export`);function Wr(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Gr(e,t){let n=e[t];return typeof n==`string`?n:null}function Kr(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function qr(e,t){let n=e[t];return typeof n==`boolean`?n:null}function Jr(e){return e===`error`||e===`warn`||e===`info`}function Yr(e){if(!Wr(e))return null;let t=Gr(e,`code`),n=Gr(e,`detail`),r=e.severity;return t===null||n===null||!Jr(r)?null:{code:t,severity:r,detail:n}}function Xr(e){if(!Wr(e))return null;let t=Gr(e,`trackId`),n=Kr(e,`deviceId`),r=Gr(e,`className`),i=Kr(e,`firstSeen`),a=Kr(e,`lastSeen`),o=Kr(e,`durationMs`),s=qr(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=Gr(e,`label`),l=Gr(e,`subLabel`),u=Gr(e,`previewMissReason`),d=qr(e,`markForTrain`),f=qr(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:Kr(e,`importance`)??0,bestEventId:Gr(e,`bestEventId`)??``,...d===null?{}:{markForTrain:d},...f===null?{}:{favourited:f},debug:!0,...u===null||u.length===0?{}:{previewMissReason:u}}}function Zr(e){let t=Xr(e);if(t===null||!Wr(e))return null;let n=Kr(e,`mediaCount`),r=Kr(e,`eventCount`),i=Kr(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=Yr(e);t!==null&&c.push(t)}let l=e.thumbnailProvenance;return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c,...dn(l)?{thumbnailProvenance:l}:{}}}function Qr(e){if(!Wr(e))return null;let t=qr(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=Xr(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function $r(e){if(!Wr(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=Zr(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var ei={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`,UNSCORED_LABEL:`unscored label`,BEST_SHOT_STANDIN:`stand-in best shot`,BEST_SHOT_RASTER:`low-res best shot`};function ti(e){return ei[e]??e}var ni={error:0,warn:1,info:2};function ri(e){return e.toSorted((e,t)=>ni[e.severity]-ni[t.severity]||e.code.localeCompare(t.code))}function ii(e){return e.length===0?Ur:`${Ur}?deviceIds=${e.join(`,`)}`}function ai(e){if(e<1e4)return`${(e/1e3).toFixed(1)}s`;let t=Math.round(e/1e3);if(t<60)return`${String(t)}s`;let n=Math.floor(t/60);return`${String(n)}m ${String(t%60).padStart(2,`0`)}s`}function oi(e,t){return`${String(e)}:${t}`}function si(e,t){let n=[],r=new Set;for(let i of e){let e=oi(i.deviceId,i.trackId);!t.has(e)||r.has(e)||(r.add(e),n.push({deviceId:i.deviceId,trackId:i.trackId}))}return n}n();function ci({tapeId:e,call:t,onClose:n,onChanged:i}){let a=o({queryKey:[`events-debug`,`tapes`,`tracks`,e],queryFn:async()=>vr(await t(nr.tracks,{tapeId:e}))}),s=a.data??null,c=o({queryKey:[`events-debug`,`tapes`,`marks`,e],enabled:s!==null,queryFn:async()=>s===null?null:Tr(await t(rr.list,{deviceId:s.deviceId,since:s.fromMs-ar,until:s.toMs+ar,limit:5e3}))}),[d,f]=l([]),[p,m]=l(``),[h,g]=l(null),_=e=>f(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),v=async e=>{g(null);try{for(let[n,r]of e)await t(n,r);f([]),await c.refetch(),i()}catch(e){g(cr(e))}};if(s===null)return a.isLoading?u(`p`,{className:`text-xs`,children:`Loading the tape…`}):u(q,{message:sr});let y=s.deviceId,b=(e,t)=>v(e.map(e=>[rr.setRelation,{deviceId:y,...e,relation:t}])),x=e=>{let t=Number.parseFloat(p),n=e===`mixed`&&Number.isFinite(t)?s.fromMs+t*1e3:void 0;return v(d.map(t=>[rr.setPurity,{deviceId:y,trackId:t,purity:e,...n===void 0?{}:{switchAtMs:Math.round(n)}}]))},S=c.data==null?null:Er(c.data);return r(`div`,{className:`space-y-2 rounded-md border border-primary/40 px-3 py-2`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[r(`span`,{className:`text-xs font-medium`,children:[s.tapeId,` — `,String(s.lanes.length),` tracks`]}),u(V,{disabled:d.length<2,onClick:()=>void b(Or(d),`same-subject`),children:`Same subject`}),u(V,{variant:`secondary`,disabled:d.length<2,onClick:()=>void b(kr(d),`different-subjects`),children:`Different subjects`}),u(J,{"aria-label":`Changed at (s from tape start)`,placeholder:`changed at s`,value:p,onChange:e=>m(e.target.value),className:`w-28`}),u(V,{variant:`secondary`,disabled:d.length!==1,onClick:()=>void x(`mixed`),children:`Mixed`}),u(V,{variant:`secondary`,disabled:d.length===0,onClick:()=>void x(`not-a-subject`),children:`Not a subject`}),u(V,{variant:s.reviewed?`secondary`:`primary`,onClick:()=>void v([[nr.review,{tapeId:s.tapeId,reviewed:!s.reviewed}]]).then(()=>a.refetch()),children:s.reviewed?`Mark not reviewed`:`Mark reviewed`}),u(V,{variant:`ghost`,onClick:n,children:`Close`})]}),h!==null&&u(q,{message:h}),S!==null&&u(q,{variant:`warning`,message:S}),u(`ul`,{className:`space-y-1`,children:s.lanes.toSorted((e,t)=>e.firstT-t.firstT).map(e=>u(li,{lane:e,marks:c.data===null||c.data===void 0?[]:Ar(e.trackId,c.data),selected:d.includes(e.trackId),onToggle:()=>_(e.trackId)},e.trackId))})]})}function li({lane:e,marks:t,selected:n,onToggle:i}){let{src:a}=It(e.stillStored?Lt(`track`,e.trackId):void 0);return r(`li`,{className:`flex items-center gap-2 text-xs`,children:[u(`input`,{type:`checkbox`,"aria-label":`select ${e.trackId}`,checked:n,onChange:i}),a===null?u(`div`,{className:`h-10 w-10 rounded bg-surface-hover`}):u(`img`,{src:a,alt:e.trackId,className:`h-10 w-10 rounded object-cover`}),u(`span`,{className:`font-mono`,children:e.trackId}),u(`span`,{children:e.cls}),r(`span`,{className:`text-foreground-subtle`,children:[ai(e.firstT),` → `,ai(e.lastT),` · `,String(e.boundFrames),` `,`frames`]}),!e.stillStored&&u(`span`,{className:`text-foreground-subtle`,children:`not stored — marked through the tape`}),t.map(e=>u(Y,{variant:`info`,children:e},e))]})}n();var ui=`camstack_admin_token`;function di(){let e=m();return(t,n)=>e.trpcClient.addons.custom.mutate({addonId:Br,action:t,input:n})}async function fi(e,t){let n=localStorage.getItem(ui),r={};n!==null&&(r.Authorization=`Bearer ${n}`);let i=await fetch(or(e),{headers:r});if(!i.ok){let e=await i.text().catch(()=>``);throw Error(Rr(i.status,e))}let a=await i.blob(),o=i.headers.get(`content-disposition`),s=(o===null?null:/filename="?([^";]+)"?/i.exec(o))?.[1]?.trim()??t,c=URL.createObjectURL(a),l=document.createElement(`a`);l.href=c,l.download=s,l.click(),setTimeout(()=>URL.revokeObjectURL(c),6e4)}function pi(){let[e,t]=l(!1);return u(Ke,{expanded:e,onExpandedChange:t,header:u(`span`,{className:`text-sm font-medium text-foreground`,children:`Tracking tapes`}),children:u(mi,{})})}function mi(){let e=di(),t=nt({isCamera:!0,projection:`slim`}),n=a(()=>{let e=new Map;for(let n of t.data??[])e.set(n.id,n.name);return t=>e.get(t)??`Camera ${String(t)}`},[t.data]),i=o({queryKey:[`events-debug`,`tapes`,`status`],queryFn:async()=>mr(await e(nr.status,{}))}),s=o({queryKey:[`events-debug`,`tapes`,`list`],queryFn:async()=>gr(await e(nr.list,{}))}),[c,d]=l(null),[f,p]=l(null),m=async e=>{p(null);try{await fi(e.id,`${e.scenario}.tape-bundle.json.gz`)}catch(e){p(cr(e))}},h=async t=>{let n=br(await e(nr.release,{tapeId:t.id}));if(n===null)throw Error(sr);let r=Sr(n);if(r!==null)throw Error(r);await s.refetch()},g=async t=>{let n=xr(await e(nr.remove,{tapeId:t.id}));if(n===null)throw Error(sr);let r=Sr(n);if(r!==null)throw Error(r);await s.refetch()};return r(`div`,{className:`space-y-3`,children:[r(`p`,{className:`text-xs text-foreground-subtle`,children:[`A camera records while its `,u(`strong`,{children:`Record the track history`}),` switch (camera settings → Tracking) is on; segments are kept 24 h. Promote a window worth keeping, label it in the review, mark it reviewed, download it and turn it into a test case with`,` `,u(`code`,{children:`npm run tracking-bench -- case`}),`.`]}),f!==null&&u(q,{message:f}),i.isLoading&&u(`p`,{className:`text-xs text-foreground-subtle`,children:`Loading camera status…`}),i.data===null&&u(q,{message:`The server answered in a shape this build does not understand.`}),r(`table`,{className:`w-full text-xs`,children:[u(`thead`,{children:r(`tr`,{className:`text-left text-foreground-subtle`,children:[u(`th`,{children:`Camera`}),u(`th`,{children:`State`}),u(`th`,{children:`Frames/min`}),u(`th`,{children:`Last hour`}),u(`th`,{children:`Held`}),u(`th`,{children:`Gaps`})]})}),u(`tbody`,{children:(i.data??[]).map(e=>r(`tr`,{children:[u(`td`,{children:n(e.deviceId)}),u(`td`,{children:u(Y,{variant:e.state===`recording`?`success`:e.state===`off`?`default`:e.state===`unknown`?`warning`:`danger`,children:jr(e)})}),u(`td`,{children:e.framesPerMin===void 0?`—`:String(Math.round(e.framesPerMin))}),u(`td`,{title:e.shelfError,children:Ir(e.bytesLastHour)}),r(`td`,{title:e.shelfError,children:[Lr(e.segmentsHeld),` seg · `,Ir(e.bytesHeld)]}),u(`td`,{children:String(e.gapsSinceArmed)})]},e.deviceId))})]}),u(zr,{cameras:Dr(i.data??[]).map(e=>({value:String(e.deviceId),label:e.segmentsUnknown?`${n(e.deviceId)} (segments unknown)`:n(e.deviceId)})),call:e,onPromoted:()=>void s.refetch()}),s.isLoading&&u(`p`,{className:`text-xs text-foreground-subtle`,children:`Loading promoted tapes…`}),s.data===null&&u(q,{message:`The server answered in a shape this build does not understand.`}),r(`table`,{className:`w-full text-xs`,children:[u(`thead`,{children:r(`tr`,{className:`text-left text-foreground-subtle`,children:[u(`th`,{children:`Scenario`}),u(`th`,{children:`Camera`}),u(`th`,{children:`Window`}),u(`th`,{children:`State`}),u(`th`,{children:`Tracks`}),u(`th`,{})]})}),u(`tbody`,{children:(s.data??[]).map(e=>r(`tr`,{children:[u(`td`,{children:e.scenario}),u(`td`,{children:n(e.deviceId)}),r(`td`,{children:[new Date(e.fromMs).toLocaleString(),` · `,ai(e.toMs-e.fromMs),` `,`· `,e.lighting]}),r(`td`,{children:[u(Y,{variant:e.state===`complete`?`success`:`warning`,children:e.state}),` `,e.reviewed&&u(Y,{variant:`info`,children:`reviewed`}),` `,e.released&&u(Y,{children:`released`})]}),r(`td`,{children:[String(e.tracksStillStored),`/`,String(e.tracks.length),` stored`]}),r(`td`,{className:`space-x-1 text-right`,children:[u(V,{variant:`secondary`,"aria-label":`Review ${e.scenario}`,onClick:()=>d(e.id),children:`Review`}),u(V,{variant:`ghost`,"aria-label":`Download ${e.scenario}`,onClick:()=>void m(e),children:u(ze,{className:`h-3.5 w-3.5`})}),u(j,{label:`Release`,icon:oe,title:`Release ${e.scenario}?`,description:`Releasing returns this tape's pinned tracks to ordinary retention — they can be pruned from then on. The promoted bundle itself is kept until deleted.`,confirmLabel:`Release`,triggerVariant:`ghost`,confirmVariant:`danger`,disabled:e.released,action:()=>h(e)}),u(j,{label:`Delete`,icon:y,title:`Delete ${e.scenario}?`,description:`Deleting removes the promoted bundle and its index row for good. Its tracks' pins are released first — this cannot be undone.`,confirmLabel:`Delete`,triggerVariant:`ghost`,confirmVariant:`danger`,action:()=>g(e)})]})]},e.id))})]}),c!==null&&u(ci,{tapeId:c,call:e,onClose:()=>d(null),onChanged:()=>void s.refetch()})]})}n();var hi=`all`,gi=`The server answered in a shape this build does not understand.`,_i={error:`danger`,warn:`warning`,info:`info`};function vi({findings:e}){return e.length===0?u(Y,{variant:`success`,children:`no anomaly found`}):u(`div`,{className:`flex flex-wrap gap-1`,children:ri(e).map(e=>u(Y,{variant:_i[e.severity],title:e.detail,children:ti(e.code)},e.code))})}function yi({track:e,report:t,analyzing:n}){let i=hn(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(vi,{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 bi(){let e=m(),[t,n]=l(hi),[i,s]=l(!1),[c,d]=l(null),[f,p]=l(new Set),[h,g]=l(null),[_,v]=l(null),[y,b]=l(null),[x,S]=l([]),C=Nn(),T=nt({isCamera:!0,projection:`slim`}),E=a(()=>[{value:hi,label:`All cameras`},...(T.data??[]).map(e=>({value:String(e.id),label:e.name}))],[T.data]),D=a(()=>{let e=new Map;for(let t of T.data??[])e.set(t.id,t.name);return e},[T.data]),O=e=>D.get(e)??`Camera ${String(e)}`,k=a(()=>t===hi?[]:[Number.parseInt(t,10)],[t]),A=o({queryKey:[`events-debug`,`list`,k],queryFn:async()=>Qr(await e.trpcClient.addons.custom.mutate({addonId:Br,action:Vr,input:k.length===0?{}:{deviceIds:k}}))}),j=a(()=>(A.data?.tracks??[]).map(e=>e.trackId),[A.data]),M=o({queryKey:[`events-debug`,`analyze`,j],enabled:j.length>0,queryFn:async()=>$r(await e.trpcClient.addons.custom.mutate({addonId:Br,action:Hr,input:{trackIds:j}}))}),N=a(()=>{let e=new Map;for(let t of M.data?.reports??[])e.set(t.trackId,t);return e},[M.data]),I=A.data?.tracks??[],L=A.data===null||M.data===null,R=()=>{A.refetch(),M.refetch()},z=e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},B=()=>{p(new Set(I.map(e=>oi(e.deviceId,e.trackId))))},ee=()=>p(new Set),te=async(e,t)=>{let n=e===`analyzed`?{debug:!1}:{favourited:!0},r=0,i=[];for(let e of t)try{await C.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,flags:n}),r+=1}catch{i.push(e.trackId)}return{applied:r,refused:i}},H=e=>{if(!An||_!==null)return;let t=si(I,f);t.length!==0&&(v(e),b(null),(async()=>{let n=await te(e,t);v(null);let r=new Set(n.refused);p(new Set(t.filter(e=>r.has(e.trackId)).map(e=>oi(e.deviceId,e.trackId)))),e===`analyzed`&&S(t.filter(e=>!r.has(e.trackId))),n.refused.length>0&&b(`${String(n.refused.length)} of ${String(t.length)} were refused by the server and are still selected. Check the hub log.`),A.refetch()})())},U=()=>{let e=x;e.length===0||_!==null||(v(`analyzed`),b(null),(async()=>{for(let t of e)try{await C.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,flags:{debug:!0}})}catch{b(`Some tracks could not be re-marked. Refresh and try again.`)}v(null),S([]),A.refetch()})())},W=async()=>{s(!0),d(null);try{await zt(ii(k),`camstack-debug.zip`)}catch(e){d(e instanceof Error?e.message:`Export failed.`)}finally{s(!1)}},G=_!==null;return u(Ft,{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(F,{value:t,options:E,onChange:e=>n(e.target.value)})}),r(V,{variant:`secondary`,onClick:R,disabled:A.isFetching,children:[A.isFetching?u(P,{className:`h-3.5 w-3.5 animate-spin`}):u(Re,{className:`h-3.5 w-3.5`}),`Refresh`]}),r(V,{onClick:()=>void W(),disabled:i||I.length===0,children:[i?u(P,{className:`h-3.5 w-3.5 animate-spin`}):u(ze,{className:`h-3.5 w-3.5`}),`Export all (`,String(I.length),`)`]}),I.length>0&&f.size<I.length&&u(V,{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.`]}),u(pi,{}),A.isError&&u(q,{message:`Could not load the marked tracks.`}),L&&!A.isError&&u(q,{message:gi}),c!==null&&u(q,{message:c}),y!==null&&u(q,{message:y}),A.data?.truncated===!0&&u(q,{message:`A camera filled the per-camera cap — some marked tracks are not listed. Un-mark a few, or filter to one camera.`}),(M.data?.vanished.length??0)>0&&r(`p`,{className:`text-xs text-foreground-subtle`,children:[String(M.data?.vanished.length),` marked track(s) were evicted between the list and the analysis.`]}),f.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(f.size),` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[u(`span`,{title:An?void 0:`Track flags arrive with the next server update`,children:r(V,{variant:`secondary`,onClick:()=>H(`keep`),disabled:!An||G,children:[_===`keep`?u(P,{className:`h-3.5 w-3.5 animate-spin`}):u($e,{className:`h-3.5 w-3.5`}),` `,`Keep`]})}),u(`span`,{title:An?void 0:`Track flags arrive with the next server update`,children:r(V,{onClick:()=>H(`analyzed`),disabled:!An||G,children:[_===`analyzed`?u(P,{className:`h-3.5 w-3.5 animate-spin`}):u(ft,{className:`h-3.5 w-3.5`}),` `,`Analyzed`]})}),u(V,{variant:`ghost`,onClick:ee,disabled:G,children:u(dt,{className:`h-3.5 w-3.5`})})]})]}),x.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(x.length),` track(s) marked analyzed and removed from this list.`]}),r(V,{variant:`ghost`,onClick:U,disabled:G,children:[u(K,{className:`h-3.5 w-3.5`}),` Undo`]}),u(V,{variant:`ghost`,onClick:()=>S([]),disabled:G,children:u(dt,{className:`h-3.5 w-3.5`})})]}),A.isLoading?u(w,{children:u(`div`,{className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`Loading…`})}):I.length===0?u(w,{children:r(`div`,{className:`flex flex-col items-center gap-2 px-3 py-8 text-center`,children:[u(st,{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:I.map(e=>{let t=N.get(e.trackId);return u(_n,{row:e,cameraName:O(e.deviceId),nowMs:e.lastSeen,selected:f.has(oi(e.deviceId,e.trackId)),onToggleSelect:z,onOpenDetail:g,...t?.thumbnailProvenance===void 0?{}:{provenance:t.thumbnailProvenance},footer:u(yi,{track:e,report:t,analyzing:M.isFetching})},oi(e.deviceId,e.trackId))})}),h&&u(tr,{row:h,cameraName:O(h.deviceId),deleteAvailable:Wn,onClose:()=>g(null),onDeleted:()=>{g(null),A.refetch()},onFlagsChanged:e=>{e.debug||(g(null),A.refetch())}})]})})}var xi=200,Si=3e4,Ci=[];function wi(e){let t=m(),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:Si,refetchInterval:Si,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEventsBatch.query({deviceIds:r,since:e.since,until:e.until,limit:xi,...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:an(rn(i??Ci),`importance`),isLoading:n&&a}}n();var Ti=[`events-feed`],Ei=2e3;function Di(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:Ti})},[]),p=t(void 0);p.current||=At({delayMs:Ei,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 vt(Mt.PipelineAnalyticsDetectionEvent,()=>{p.current?.trigger()}),vt(Mt.PipelineAnalyticsTrackEnded,()=>{p.current?.trigger()}),{pending:s,refreshNow:m}}n();function Oi({groups:e,selected:t,onChange:n,loading:i=!1}){let{t:o}=Nt(),[s,c]=l(!1),[d,f]=l(``),[p,m]=l(new Set),h=d.trim().toLowerCase(),g=e=>h.length===0||x(e,o).toLowerCase().includes(h),y=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]),b=e=>m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),S=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)},C=e=>{let r=new Set(t);r.has(e)?r.delete(e):r.add(e),n(r)},w=()=>n(new Set),T=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 ${T>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[u(ve,{className:`h-3.5 w-3.5`}),T>0?`Kinds (${String(T)})`:`Kinds`,u(_,{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`}),T>0&&u(`button`,{type:`button`,onClick:w,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),y.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.`}),y.map(e=>{let n=Ne(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:()=>b(e.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Expand`,children:u(i?_:v,{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:()=>S(e),className:`accent-primary`}),u(n,{className:`h-3.5 w-3.5`,style:{color:e.macro.color}}),u(`span`,{className:`font-medium`,children:x(e.macro,o)})]})]}),i&&e.subs.map(e=>{let n=Ne(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:()=>C(e.kind),className:`accent-primary`}),u(n,{className:`h-3.5 w-3.5`,style:{color:e.color}}),u(`span`,{children:x(e,o)})]},e.kind)})]},e.macro.kind)})]})]})}function ki(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 Ai(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var ji=new Set([`detection`,`package`]);function Mi(e,t){return[...ki(e,t).values()].filter(e=>e.parentKind===null&&ji.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function Ni(e,t){let n=ki(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,Ai(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 Pi(){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 Fi=[`events-feed`],Ii=60,Li=[{value:`importance`,label:`Importance`,icon:Ut},{value:`time`,label:`Recent`,icon:je}];function Ri(){let e=c(),t=U(),n=Ze(),[i,o]=l(kt),[f,p]=l(new Set),[m,h]=l(new Set),[g,_]=l(0),[v,b]=l(`time`),[x,S]=l(new Set),[C,w]=l(null),[T,E]=l(()=>Date.now());d(()=>{let e=setInterval(()=>E(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:D,until:O}=a(()=>ln({fromMs:i.fromMs,toMs:i.toMs},T),[i.fromMs,i.toMs,T]),k=Pi(),{pending:A,refreshNow:j}=Di({paused:C!==null||x.size>0||k.scrolledPast}),{data:M=[]}=nt({isCamera:!0,projection:`slim`}),N=a(()=>M.map(e=>e.id),[M]),{data:F,isLoading:I}=Ye({deviceIds:N},{enabled:N.length>0,staleTime:5*6e4}),L=a(()=>Ni(F??[],f),[F,f]),R=qn(),z=R.isPending,{rows:B,isLoading:ee}=wi({deviceIds:N,since:D,until:O,minImportance:g>0?g:void 0,classFilter:m.size===1?[...m][0]:void 0}),te=a(()=>{let e=new Map;for(let t of M??[])e.set(t.id,t.name);return e},[M]),H=e=>te.get(e)??`Camera #${String(e)}`,W=a(()=>bt(B).map(e=>({id:e,name:H(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[B,te]),G=a(()=>an(on(B,{cameras:f,classes:m,minImportance:g}),v),[B,f,m,g,v]),K=Et(G,Ii,a(()=>JSON.stringify([[...f].sort((e,t)=>e-t),[...m].sort(),g,v,D,O]),[f,m,g,v,D,O])),ne=()=>{e.invalidateQueries({queryKey:Fi})},q=()=>S(new Set);function re(e){S(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function ie(){if(x.size===0||!Wn)return;let e=cn(B,x),t=[...e.values()].reduce((e,t)=>e+t.length,0);t!==0&&(async()=>{await n({title:`Delete ${String(t)} track${t===1?``:`s`}`,message:`Delete ${String(t)} track${t===1?``:`s`} and every image and clip captured for ${t===1?`it`:`them`}? This cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&ae(e)})()}function ae(e){let n=[...e];Promise.allSettled(n.map(([e,t])=>R.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{ne();let r=[],i=new Set;e.forEach((e,t)=>{let a=n[t];if(!a)return;let[o,s]=a;if(e.status===`fulfilled`)for(let e of s)i.add(sn(o,e));else r.push(o)}),S(e=>{let t=new Set(e);for(let e of i)t.delete(e);return t}),r.length>0&&t({title:`Some tracks were not deleted`,message:`Failed to delete tracks on: ${r.map(e=>H(e)).join(`, `)}. They remain selected — retry, or check the server logs.`,variant:`danger`})})}let oe=G.length!==B.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[u(Ot,{onChange:o}),u(Ct,{cameras:W,selected:f,onChange:p}),u(Oi,{groups:L,selected:m,onChange:h,loading:I}),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:g,onChange:e=>_(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(g*100)})]}),u(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Li.map(e=>{let t=e.icon;return r(`button`,{type:`button`,onClick:()=>b(e.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${v===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)})}),!ee&&u(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:oe?`${String(G.length)} of ${String(B.length)} events`:`${String(G.length)} event${G.length===1?``:`s`}`})]}),x.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:[x.size,` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[u(`span`,{title:Wn?void 0:`Track deletion arrives with the next server update`,children:r(V,{variant:`secondary`,onClick:ie,disabled:!Wn||z,children:[z?u(P,{className:`h-3.5 w-3.5 animate-spin`}):u(y,{className:`h-3.5 w-3.5`}),` `,`Delete`]})}),u(V,{variant:`ghost`,onClick:q,disabled:z,children:u(dt,{className:`h-3.5 w-3.5`})})]})]}),ee&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[u(P,{className:`h-4 w-4 animate-spin`}),` Loading events…`]}),!ee&&G.length===0&&u(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No key events in this window.`}),A&&u(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:u(`button`,{type:`button`,onClick:j,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`})}),!ee&&G.length>0&&r(s,{children:[u(`div`,{ref:k.ref,"aria-hidden":!0,className:`h-0`}),u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:K.pageItems.map(e=>u(_n,{row:e,cameraName:H(e.deviceId),nowMs:T,selected:x.has(sn(e.deviceId,e.trackId)),onToggleSelect:re,onOpenDetail:w},sn(e.deviceId,e.trackId)))}),u(yt,{currentPage:K.page,totalItems:K.totalItems,pageSize:K.pageSize,onPageChange:K.setPage,itemNoun:`events`})]}),C&&u(tr,{row:C,cameraName:H(C.deviceId),deleteAvailable:Wn,onClose:()=>w(null),onDeleted:()=>{ne(),w(null)},onFlagsChanged:e=>{w(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug,favourited:e.favourited}:t)}})]})}n();var zi=50,Bi=350,Vi=[{value:`loose`,label:`Loose`,title:`The search model's own floor`},{value:`balanced`,label:`Balanced`,title:`1.25× the search model's floor`},{value:`strict`,label:`Strict`,title:`1.5× the search model's floor`}];function Hi(e){let t=String(e.id);return{id:t,trackId:e.trackId??t,deviceId:e.deviceId,timestamp:e.timestamp,className:e.className,label:e.label,subLabel:e.subLabel,importance:e.importance??0,bestEventId:t,mediaId:e.keyFrameMediaId??e.mediaId,windowMs:void 0}}function Ui({onActiveChange:e}){let[t,n]=l(``),[i,o]=l(`loose`),[s,c]=l(null),[f,p]=l(null),[m,h]=l(null),g=Te(t,Bi).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=[]}=nt({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}=Ye({deviceIds:w},{enabled:w.length>0,staleTime:5*6e4}),E=a(()=>Mi(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}=Ve({text:g,strictness:i,limit:zi,classFilter:s??void 0,deviceId:f??void 0},{enabled:_}),j=a(()=>[...D??[]].sort((e,t)=>t.score-e.score).map(e=>({...Hi(e),score:e.score})),[D]);function M(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(dt,{className:`h-3.5 w-3.5`})})]}),O&&_&&u(P,{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:()=>M(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:x(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:Vi.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:e.title,children:e.label},e.value))})]}),_&&!O&&!k&&r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[j.length,` match`,j.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&&j.length===0&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[u(P,{className:`h-4 w-4 animate-spin`}),` Searching…`]}),!k&&!O&&j.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&&j.length>0&&u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:j.map(e=>u(_n,{row:e,cameraName:C(e.deviceId),nowMs:v,score:e.score,onOpenDetail:h},e.id))})]}),m&&u(tr,{row:m,cameraName:C(m.deviceId),deleteAvailable:Wn,onClose:()=>h(null),onDeleted:()=>h(null)})]})}n();function Wi(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 Gi({row:e,cameraName:t,nowMs:n}){let i=It(e.keyFrameMediaId===void 0?void 0:Rt(e.keyFrameMediaId));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:[i.src?u(`img`,{src:i.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($t,{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 `,Wi(n,e.becameStationaryAt)]})]})]})}function Ki(){let[e,t]=l(!1),n=Date.now(),{data:i=[]}=nt({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}=Bt(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?_:v,{className:`h-4 w-4 text-foreground-subtle`}),u($t,{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(Gi,{row:e,cameraName:s.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:n},e.id))})]})}n();function qi(){let[e,t]=l(!1);return u(Ft,{children:r(`section`,{className:`space-y-3`,children:[u(Ui,{onActiveChange:t}),!e&&u(Ki,{}),!e&&u(Ri,{})]})})}n();function Ji({frameId:e,onAdded:t}){let n=ce(),[i,a]=l(null),[o,s]=l(null),c=async()=>{if(i===null)return;let r=await n.mutateAsync({collectionId:i,frameIds:[e]});s(r.added>0?`Added.`:r.alreadyMember>0?`Already in that collection.`:`That frame or collection no longer exists.`),await t()};return r(_e,{children:[r(W,{className:`mt-1 flex items-center gap-1 text-foreground-muted hover:text-foreground`,"aria-label":`Add this frame to a collection`,children:[u(qt,{className:`h-3 w-3`}),`collection`]}),r(R,{className:`w-72 space-y-2 p-3`,children:[u(gt,{value:i,onChange:a}),r(`div`,{className:`flex items-center justify-between gap-2`,children:[u(`span`,{className:`text-[11px] text-foreground-subtle`,children:o}),u(V,{size:`sm`,disabled:i===null||n.isPending,onClick:()=>void c(),children:`Add`})]})]})]})}function Yi(e){let t=e.capturedAt??e.copiedAt;return new Date(t).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function Xi({frames:e,isLoading:t,activeFrameId:n,deviceNames:i,onOpen:a,onRemove:o}){return e.length===0?u(`p`,{className:`text-[11px] text-foreground-subtle`,children:t?`Reading the collection…`:`This collection is empty. Add frames with "Send frame to training" on a camera’s recording timeline, or "Add to collection" on a track’s copied frame.`}):u(`ul`,{className:`flex flex-wrap gap-2`,children:e.map(e=>u(`li`,{children:r(`div`,{className:`rounded-md border px-2 py-1.5 text-[11px] flex items-start gap-1.5 ${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:()=>{a(e.frameId)},children:[e.origin===`recording`?u(xe,{className:`h-3 w-3 text-info`,"aria-label":`From the recording`}):u(Yt,{className:`h-3 w-3 text-success`,"aria-label":`From a track`}),u(`span`,{className:`font-medium text-foreground`,children:i.get(e.deviceId)??`Camera ${String(e.deviceId)}`}),u(`span`,{className:`text-foreground-subtle`,children:Yi(e)}),e.complete&&u(Y,{variant:`success`,children:`complete`})]}),u(`button`,{type:`button`,"aria-label":`Remove from this collection`,title:e.origin===`recording`?`Remove from this collection. If no other collection holds it, the frame and its boxes leave the dataset.`:`Remove from this collection. The frame stays in the dataset with its track.`,className:`text-foreground-muted hover:text-danger`,onClick:()=>{o(e)},children:u(dt,{className:`h-3 w-3`})})]})},e.frameId))})}n();function Zi({collections:e,isLoading:t,selectedId:n,onSelect:i,onCreate:a,onRename:o,onDelete:c}){let[d,f]=l(``),[p,m]=l(null),[h,g]=l(null),_=async()=>{let e=await a(d);m(e),e===null&&f(``)},v=async()=>{if(h===null)return;let e=await o(h.id,h.name);m(e),e===null&&g(null)};return r(`div`,{className:`divide-y divide-border`,children:[r(`div`,{className:`p-2 space-y-1.5`,children:[r(`div`,{className:`flex items-center gap-1.5`,children:[u(J,{className:`flex-1`,"aria-label":`New collection name`,placeholder:`New collection`,value:d,onChange:e=>{f(e.target.value)}}),u(V,{size:`sm`,disabled:d.trim()===``,onClick:()=>void _(),children:`Create`})]}),p!==null&&u(`p`,{className:`text-[11px] text-danger`,children:p})]}),e.length===0?u(`p`,{className:`p-3 text-[11px] text-foreground-subtle`,children:t?`Reading the collections…`:`No collection yet. Create one here, or use "Send frame to training" on a camera’s recording timeline.`}):u(`ul`,{className:`divide-y divide-border`,children:e.map(e=>u(`li`,{className:`px-3 py-2 flex items-center gap-2 text-xs ${e.id===n?`bg-surface-hover`:``}`,children:h?.id===e.id?r(s,{children:[u(J,{className:`flex-1`,"aria-label":`Collection name`,value:h.name,onChange:t=>{g({id:e.id,name:t.target.value})}}),u(V,{variant:`ghost`,size:`sm`,"aria-label":`Save the name`,onClick:()=>void v(),children:u(ft,{className:`h-3 w-3`})}),u(V,{variant:`ghost`,size:`sm`,"aria-label":`Cancel renaming`,onClick:()=>{g(null)},children:u(dt,{className:`h-3 w-3`})})]}):r(s,{children:[u(`button`,{type:`button`,className:`flex-1 min-w-0 text-left truncate text-foreground`,onClick:()=>{i(e)},children:e.name}),u(Y,{children:e.frameCount}),u(V,{variant:`ghost`,size:`sm`,"aria-label":`Rename ${e.name}`,onClick:()=>{g({id:e.id,name:e.name})},children:u(D,{className:`h-3 w-3`})}),u(j,{label:`Delete`,icon:y,triggerVariant:`ghost`,size:`sm`,title:`Delete "${e.name}"?`,description:`Frames taken from the recording that are in no other collection are deleted with their boxes. Frames copied from tracks stay in the dataset.`,confirmLabel:`Delete`,confirmVariant:`danger`,action:()=>c(e.id)})]})},e.id))})]})}n();var Qi={"empty-name":`Give the version a name.`,"duplicate-name":`A version with that name already exists.`,"no-frames":`This selection holds no annotated or complete frame — nothing to freeze.`},$i=e=>`${String(Math.round(e*100))}%`;function ea(e,t){return e.includes(t)?e.filter(e=>e!==t):[...e,t]}function ta({on:e,label:t,onClick:n}){return u(`button`,{type:`button`,"aria-pressed":e,className:`rounded-full border px-2 py-0.5 text-[11px] ${e?`border-primary text-primary`:`border-border text-foreground-muted hover:text-foreground`}`,onClick:n,children:t})}function na({stats:e,deviceNames:t}){let n=e=>t.get(e)??`Camera ${String(e)}`;return r(`div`,{className:`space-y-2`,"data-testid":`retrain-dataset-stats`,children:[r(`div`,{className:`flex flex-wrap gap-1.5 text-[11px]`,children:[r(Y,{children:[e.frames,` frames`]}),r(Y,{variant:e.completeness>=.9?`success`:`warning`,children:[$i(e.completeness),` complete (`,e.completeFrames,`)`]}),r(Y,{children:[e.subjects,` boxes`]}),r(Y,{variant:`danger`,children:[e.modelErrors,` model errors`]}),r(Y,{variant:`info`,children:[e.hardNegatives,` hard negatives`]}),e.cameras.map(e=>r(Y,{children:[n(e.deviceId),`: `,e.frames,` ·`,` `,$i(e.frames>0?e.completeFrames/e.frames:0),` complete`]},e.deviceId))]}),u(ie,{columns:[{key:`class`,header:`Class`,render:e=>e.macroClass,sortValue:e=>e.macroClass},{key:`camera`,header:`Camera`,render:e=>n(e.deviceId),sortValue:e=>n(e.deviceId)},{key:`light`,header:`Light`,render:e=>e.lighting,sortValue:e=>e.lighting},{key:`subjects`,header:`Boxes`,align:`right`,render:e=>e.subjects,sortValue:e=>e.subjects},{key:`frames`,header:`Frames`,align:`right`,render:e=>e.frames,sortValue:e=>e.frames}],rows:e.cells,rowKey:e=>`${e.macroClass}-${String(e.deviceId)}-${e.lighting}`,emptyMessage:`No box in this selection.`,minWidthPx:360})]})}function ra({id:e}){let[t,n]=l(!1),i=I({id:e},{enabled:t});return t?i.data===void 0?u(P,{className:`h-3 w-3 animate-spin`}):i.data.matches?u(Y,{variant:`success`,children:`unchanged`}):r(Y,{variant:`warning`,children:[`changed`,i.data.missingFrames>0?` · ${String(i.data.missingFrames)} missing`:``]}):r(V,{variant:`ghost`,size:`sm`,onClick:()=>n(!0),children:[u(et,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Verify`})]})}function ia({deviceNames:e,collections:t,pickedFrameIds:n,onClearPicked:i}){let a=c(),o=m(),[s,d]=l([]),[f,h]=l([]),[g,_]=l(!1),[v,b]=l(!1),[x,S]=l(`frames`),[w,T]=l(``),[E,D]=l(null),[O,k]=l(null),A={...s.length>0?{deviceIds:[...s]}:{},...f.length>0?{collectionIds:[...f]}:{},...g&&n.length>0?{frameIds:[...n]}:{}},M=ut({selection:A,completeOnly:v}),N=De({}),I=it(),L=Be(),R=async()=>{D(null);let e=await I.mutateAsync({name:w,selection:A,layout:x,completeOnly:v});if(e.kind===`refused`){D(Qi[e.reason]??e.reason);return}T(``),D(`Version "${e.version.name}" frozen: ${String(e.version.frameCount)} frames.`),await N.refetch()},z=async e=>{k(e.id);try{let{url:t}=await o.trpcClient.pipelineAnalytics.getRetrainExportUrl.query({datasetVersionId:e.id,layout:e.layout});await zt(p(t),`camstack-dataset-${e.name.replace(/[^a-z0-9_-]+/gi,`-`)}.tar`)}catch(e){D(`Download failed: ${e instanceof Error?e.message:String(e)}`)}finally{k(null)}},B=[...e.keys()].toSorted((e,t)=>e-t);return r(`div`,{className:`space-y-3`,children:[r(`div`,{className:`rounded-md border border-border bg-surface p-3 space-y-2`,children:[u(`h2`,{className:`text-xs font-semibold text-foreground`,children:`New dataset version`}),r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[u(`span`,{className:`text-[11px] text-foreground-subtle w-20`,children:`Cameras`}),s.length===0&&u(Y,{children:`all`}),B.map(t=>u(ta,{on:s.includes(t),label:e.get(t)??String(t),onClick:()=>d(e=>ea(e,t))},t))]}),r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[u(`span`,{className:`text-[11px] text-foreground-subtle w-20`,children:`Collections`}),f.length===0&&u(Y,{children:`any frame`}),t.map(e=>u(ta,{on:f.includes(e.id),label:`${e.name} · ${String(e.frameCount)}`,onClick:()=>h(t=>ea(t,e.id))},e.id))]}),r(`div`,{className:`flex flex-wrap items-center gap-3 text-[11px]`,children:[r(`label`,{className:`flex items-center gap-1.5`,children:[u(C,{"aria-label":`Only the frames picked in the workbench`,checked:g,disabled:n.length===0,onChange:e=>_(e.target.checked)}),`Only the `,n.length,` picked frame`,n.length===1?``:`s`]}),n.length>0&&u(V,{variant:`ghost`,size:`sm`,onClick:i,children:`Clear picks`}),r(`label`,{className:`flex items-center gap-1.5`,children:[u(C,{"aria-label":`Only complete frames`,checked:v,onChange:e=>b(e.target.checked)}),`Only frames marked "all subjects boxed"`]}),u(F,{className:`w-36`,"aria-label":`Layout`,value:x,options:[{value:`frames`,label:`Frames (detector)`},{value:`crops`,label:`Frames + crops (classifier)`}],onChange:e=>S(e.target.value===`crops`?`crops`:`frames`)})]}),M.data===void 0?u(`p`,{className:`text-[11px] text-foreground-subtle`,children:M.isError?`The selection could not be counted.`:`Counting the selection…`}):u(na,{stats:M.data,deviceNames:e}),r(`div`,{className:`flex items-center gap-2`,children:[u(J,{className:`flex-1`,"aria-label":`Version name`,placeholder:`Version name (e.g. night person v1)`,value:w,onChange:e=>T(e.target.value)}),u(V,{size:`sm`,disabled:w.trim()===``||I.isPending||(M.data?.frames??0)===0,onClick:()=>void R(),children:`Freeze version`})]}),E!==null&&u(`p`,{className:`text-[11px] text-foreground`,children:E})]}),r(`div`,{className:`rounded-md border border-border bg-surface p-3 space-y-2`,children:[u(`h2`,{className:`text-xs font-semibold text-foreground`,children:`Versions`}),u(ie,{columns:[{key:`name`,header:`Version`,render:e=>e.name,sortValue:e=>e.name},{key:`created`,header:`Frozen`,render:e=>new Date(e.createdAt).toLocaleString(),sortValue:e=>e.createdAt},{key:`frames`,header:`Frames`,align:`right`,render:e=>e.frameCount,sortValue:e=>e.frameCount},{key:`boxes`,header:`Boxes`,align:`right`,render:e=>e.stats.subjects,sortValue:e=>e.stats.subjects},{key:`complete`,header:`Complete`,align:`right`,render:e=>$i(e.stats.completeness),sortValue:e=>e.stats.completeness},{key:`layout`,header:`Layout`,render:e=>e.layout},{key:`hash`,header:`Hash`,render:e=>u(`code`,{title:e.annotationHash,children:e.annotationHash.slice(0,10)})},{key:`actions`,header:``,render:e=>r(`div`,{className:`flex items-center gap-1 justify-end`,children:[u(ra,{id:e.id}),u(V,{variant:`ghost`,size:`sm`,"aria-label":`Download ${e.name}`,disabled:O!==null,onClick:()=>void z(e),children:O===e.id?u(P,{className:`h-3 w-3 animate-spin`}):u(ze,{className:`h-3 w-3`})}),u(j,{label:`Delete`,icon:y,triggerVariant:`ghost`,size:`sm`,title:`Delete version "${e.name}"?`,description:`The version's record goes. Its frames stay in the dataset.`,confirmLabel:`Delete`,action:async()=>{await L.mutateAsync({id:e.id}),await a.invalidateQueries()}})]})}],rows:N.data??[],rowKey:e=>e.id,emptyMessage:N.isLoading?`Reading the versions…`:`No version frozen yet.`,minWidthPx:640})]})]})}n();function aa(){let e=Me({}),t=_t({}),[n,i]=l([]),a=Ae(n.length>0?{collectionIds:[...n]}:{}),o=Fe({}),[s,c]=l(null),[d,f]=l(null),m=async(e,t,n)=>{c(e),f(null);try{await zt(p(t),n)}catch(e){f(e instanceof Error?e.message:String(e))}finally{c(null)}},h=e.data,g=h!==void 0&&h.trackCount===0;return r(`div`,{className:`rounded-md border border-border bg-surface p-3 space-y-2`,children:[r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u(`h2`,{className:`text-xs font-semibold text-foreground flex-1`,children:`Export dataset`}),r(V,{variant:`secondary`,size:`sm`,disabled:a.data===void 0||s!==null,onClick:()=>{a.data!==void 0&&m(`annotated`,a.data.url,`camstack-retrain-export.tar`)},children:[s===`annotated`?u(P,{className:`h-3 w-3 animate-spin`}):u(ze,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Annotated dataset`})]}),r(V,{variant:`secondary`,size:`sm`,disabled:o.data===void 0||g||s!==null,onClick:()=>{o.data!==void 0&&m(`marked`,o.data.url,`camstack-training-export.tar`)},children:[s===`marked`?u(P,{className:`h-3 w-3 animate-spin`}):u(ze,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Marked media`})]})]}),(t.data??[]).length>0&&r(`div`,{className:`flex items-center gap-1.5 flex-wrap text-[11px]`,children:[u(`span`,{className:`text-foreground-subtle`,children:`Annotated dataset from:`}),n.length===0&&u(Y,{children:`every collection and track`}),(t.data??[]).map(e=>{let t=n.includes(e.id);return r(`button`,{type:`button`,"aria-pressed":t,className:`rounded-full border px-2 py-0.5 ${t?`border-primary text-primary`:`border-border text-foreground-muted hover:text-foreground`}`,onClick:()=>{i(n=>t?n.filter(t=>t!==e.id):[...n,e.id])},children:[e.name,` · `,e.frameCount]},e.id)})]}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.isError?`The export summary could not be read, so the size of the marked set is unknown — not zero.`:h===void 0?`Measuring the marked set…`:g?`No track is marked for training: the marked-media archive would be empty. The annotated dataset can still hold frames from tracks already completed — this count does not measure those.`:`${String(h.trackCount)} marked track${h.trackCount===1?``:`s`} · ${String(h.fileCount)} file${h.fileCount===1?``:`s`} · ${Ht(h.byteCount)}${h.truncated?` · more marked tracks exist than one pass carries`:``}`}),(a.isError||o.isError)&&u(`p`,{className:`text-[11px] text-danger`,children:`An export data plane is not available on the node that answered — no archive can be streamed from here.`}),d!==null&&r(`p`,{className:`text-[11px] text-danger`,children:[`Download failed: `,d]})]})}function oa(e){return e>=1e6?`${(e/1e6).toFixed(1)} MB`:`${Math.round(e/1e3)} KB`}function sa({candidates:e,copies:t,activeFrameId:n,refusals:i,isSelecting:a,onSelectCandidate:o,onOpenCopy:s,onRemoveCopy:c,renderCopyActions:l}){let d=new Set(t.map(e=>e.sourceMediaId)),f=e.filter(e=>!d.has(e.mediaId));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(ft,{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,` · `,oa(e.sizeBytes)]}),e.complete&&u(Y,{variant:`success`,children:`complete`})]}),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(y,{className:`h-3 w-3`}),`remove`]}),l?.(e)]})},e.frameId))})]}),r(`section`,{children:[r(`h3`,{className:`text-xs font-semibold text-foreground mb-1.5`,children:[`Available frames (`,f.length,`)`]}),f.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:f.map(e=>{let t=i.get(e.mediaId);return r(`li`,{children:[r(V,{variant:`secondary`,size:`sm`,disabled:a||t!==void 0,onClick:()=>{o(e.mediaId)},children:[a?u(P,{className:`h-3 w-3 animate-spin`}):u(t===void 0?Kt:g,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:e.kind}),u(`span`,{className:`ml-1 text-foreground-subtle`,children:oa(e.sizeBytes)})]}),t!==void 0&&u(Y,{variant:`danger`,className:`ml-1`,children:t})]},e.mediaId)})})]})]})}function ca(e){return e.frameCount===0?`untouched`:e.annotationCount===0?`started`:`ready`}var la={untouched:{icon:Gt,label:`to do`,variant:`default`},started:{icon:Wt,label:`frames only`,variant:`info`},ready:{icon:Ie,label:`annotated`,variant:`success`}};function ua(e){return new Date(e).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function da({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(P,{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=la[ca(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(Y,{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)}`,` ·`,` `,ua(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)})})}function fa(e){return{deviceId:e.deviceId,...e.trackId===void 0?{}:{trackId:e.trackId},frameId:e.frameId}}var pa=`object-detection`;function ma(e,t){for(let n of e){if(n.addonId===t)return n;let e=n.children===void 0?void 0:ma(n.children,t);if(e!==void 0)return e}}function ha(e,t){for(let n of e.slots){let e=n.addons.find(e=>e.id===t);if(e!==void 0)return e}}function ga(e){let{status:t,nodeDevices:n,schema:r,resolvedSteps:i}=e;if(t===void 0)return{kind:`unknown`,gap:`pending`};if(t.detection===null)return{kind:`unknown`,gap:t.degraded.some(e=>e.stage===`detection`)?`placement-unreadable`:`detection-off`};let a=t.detection;if(n===void 0||r===void 0||i===void 0)return{kind:`unknown`,gap:`pending`};if(!n.reachable)return{kind:`unknown`,gap:`node-unreachable`};let o=n.devices.find(e=>e.backend===a.engine.backend&&e.device===a.engine.device);if(o===void 0)return{kind:`unknown`,gap:`device-unknown`};let s=ha(r,pa);if(s===void 0)return{kind:`unknown`,gap:`step-unknown`};let c=rt({catalog:s,device:o,override:ma(i,pa)?.modelId,base:o.steps?.[pa]?.modelId});return c===void 0?{kind:`unknown`,gap:`no-model`}:{kind:`resolved`,nodeId:a.nodeId,modelId:c,minScore:s.models.find(e=>e.id===c)?.defaultConfidence??s.defaultConfidence}}function _a(e,t){let n=Math.max(0,Math.min(e.x+e.w,t.x+t.w)-Math.max(e.x,t.x))*Math.max(0,Math.min(e.y+e.h,t.y+t.h)-Math.max(e.y,t.y)),r=e.w*e.h+t.w*t.h-n;return r>0?n/r:0}function va(e,t){let n=e.nextKey;return{boxes:t.map(e=>{let t=`b${String(n)}`;return n+=1,{...e,key:t}}),nextKey:n}}function ya(e){return{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},draft:!1}}function ba(e){return e.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},...e.subLabel===void 0?{}:{subLabel:e.subLabel},kind:`subject`,source:`pipeline`,...e.modelId===void 0?{}:{assistModelId:e.modelId},...e.score===void 0?{}:{assistScore:e.score},draft:!0,note:e.basis===`subject-box`?`The box the pipeline recorded on this very frame.`:`The pipeline's track position ${String(Math.round(e.deltaMs))} ms from this frame.`}))}var xa={boxes:[],selectedKey:null,nextKey:0};function Sa(e,t){let n=va(xa,e.map(ya));return Ca({boxes:n.boxes,selectedKey:null,nextKey:n.nextKey},ba(t)).state}function Ca(e,t){let n=[],r=0;for(let i of t){if([...e.boxes,...n].some(e=>_a(e.bbox,i.bbox)>=.8)){r+=1;continue}n.push({...i,draft:!0})}let i=va(e,n);return{state:{...e,boxes:[...e.boxes,...i.boxes],nextKey:i.nextKey},skipped:r}}function wa(e,t,n){let r=va(e,[{bbox:t,macroClass:n,kind:`subject`,source:`operator`,draft:!1}]),i=r.boxes[0];return i===void 0?e:{boxes:[...e.boxes,i],selectedKey:i.key,nextKey:r.nextKey}}function Ta(e,t,n){return{...e,boxes:e.boxes.map(e=>e.key===t?n(e):e)}}function Ea(e,t,n){return Ta(e,t,e=>({...e,...n,draft:!1}))}function Da(e,t){return Ta(e,t,e=>({...e,draft:!1}))}function Oa(e){return{...e,boxes:e.boxes.map(e=>e.draft?{...e,draft:!1}:e)}}function ka(e,t){return Ta(e,t,e=>({...e,kind:e.kind===`model_error`?`subject`:`model_error`,draft:!1}))}function Aa(e,t){return{...e,boxes:e.boxes.filter(e=>e.key!==t),selectedKey:e.selectedKey===t?null:e.selectedKey}}function ja(e,t){return{...e,selectedKey:t}}function Ma(e,t){return{...e,boxes:e.boxes.map(e=>{let n=t.get(e.key);return n===void 0?e:{...e,flag:n}})}}function Na(e,t){return new Map(e.map(e=>[e.ref,{verdict:e.verdict,reason:e.reason,by:t,...e.suggestedClass===void 0?{}:{suggestedClass:e.suggestedClass}}]))}function Pa(e){return e.boxes.filter(e=>e.draft).length}function Fa(e){let t=e?.trim();return t===void 0||t===``?void 0:t}function Ia(e){return e.boxes.filter(e=>!e.draft).map(e=>{let t=Fa(e.label),n=Fa(e.subLabel);return{bbox:e.bbox,macroClass:e.macroClass,...t===void 0?{}:{label:t},...n===void 0?{}:{subLabel:n},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}})}var La=[`person`,`vehicle`,`animal`,`package`,`face`,`plate`],Ra=new Set(La),za={operator:`drawn`,pipeline:`pipeline`,assist:`detector`,llm:`AI vision`};function Ba(e){let t=e?.trim().toLowerCase();return t===void 0||t===``?null:Ra.has(t)?`"${t}" is a macro class, not a label — person / postman / Marco are three different tiers`:null}function Va(e){if(e.source===`operator`)return null;let t=[za[e.source]];return e.assistModelId!==void 0&&t.push(e.assistModelId),e.assistScore!==void 0&&t.push(e.assistScore.toFixed(2)),t.join(` · `)}function Ha({boxes:e,selectedKey:t,onSelect:n,onChange:i,onAccept:a,onToggleModelError:o,onDelete:s}){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 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=>{let c=e.key===t,l=Ba(e.label),d=Ba(e.subLabel),f=Va(e);return r(`li`,{"data-testid":`retrain-row-${e.key}`,className:`p-2.5 space-y-1.5 ${c?`bg-surface-hover`:``}`,onFocus:()=>{n(e.key)},onClick:()=>{n(e.key)},children:[r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u(F,{className:`w-28`,"aria-label":`Class`,value:e.macroClass,options:La.map(e=>({value:e,label:e})),onChange:t=>{let n=La.find(e=>e===t.target.value);n!==void 0&&i(e.key,{macroClass:n})}}),e.draft&&u(Y,{variant:`warning`,children:`draft`}),e.kind===`model_error`&&u(Y,{variant:`danger`,children:`model error`}),f!==null&&u(Y,{variant:`info`,children:f}),(e.note!==void 0||e.flag!==void 0)&&r(be,{children:[u(Se,{children:u(he,{className:`h-3.5 w-3.5 ${e.flag!==void 0&&e.flag.verdict!==`confirmed`?`text-warning`:`text-foreground-subtle`}`,"aria-label":`Why this box is here`})}),r(ye,{className:`whitespace-normal w-64 text-left`,children:[e.note!==void 0&&u(`p`,{children:e.note}),e.flag!==void 0&&r(`p`,{children:[e.flag.by,`: `,e.flag.verdict,e.flag.suggestedClass===void 0?``:` (suggests ${e.flag.suggestedClass})`,` `,`— `,e.flag.reason]})]})]}),u(`span`,{className:`flex-1`}),e.draft&&u(V,{variant:`secondary`,size:`sm`,"aria-label":`Accept this proposal`,onClick:()=>{a(e.key)},children:u(ft,{className:`h-3 w-3`})}),u(V,{variant:`ghost`,size:`sm`,"aria-label":e.kind===`model_error`?`This is a real subject`:`Mark as model error`,onClick:()=>{o(e.key)},children:u(B,{className:`h-3 w-3`})}),u(V,{variant:`ghost`,size:`sm`,"aria-label":`Delete this subject`,onClick:()=>{s(e.key)},children:u(y,{className:`h-3 w-3`})})]}),r(`div`,{className:`flex items-center gap-2`,children:[u(J,{className:`flex-1`,placeholder:`label (postman, van, cat…)`,value:e.label??``,onChange:t=>{i(e.key,{label:t.target.value})}}),u(J,{className:`flex-1`,placeholder:`sub-label (a name, a plate…)`,value:e.subLabel??``,onChange:t=>{i(e.key,{subLabel:t.target.value})}})]}),l!==null&&u(`p`,{className:`text-[11px] text-danger`,children:l}),d!==null&&u(`p`,{className:`text-[11px] text-danger`,children:d})]},e.key)})})}function Ua(e){return e.filter(e=>!e.draft).every(e=>Ba(e.label)===null&&Ba(e.subLabel)===null&&Ra.has(e.macroClass))}var Wa=.25;function Ga(e,t){if(e===void 0)return[];let n=e.selectedEngine.format,r=e.slots.flatMap(e=>e.addons).find(e=>e.id===pa);if(r===void 0)return[];let i=r.models.filter(e=>e.legacy!==!0&&e.provider===void 0).flatMap(e=>{let t=e.formats[n];return t===void 0?[]:[{modelId:e.id,name:e.name,sizeMB:t.sizeMB??0}]}),a=i.find(e=>e.modelId===t);return i.filter(e=>e.modelId!==t&&(a===void 0||e.sizeMB>a.sizeMB)).toSorted((e,t)=>t.sizeMB-e.sizeMB)}n();var Ka=[{value:`teacher`,label:`Bigger detector`},{value:`llm`,label:`AI vision`},{value:`both`,label:`Both`}],qa=[`person`,`vehicle`,`animal`,`package`],Ja=[`person`,`vehicle`,`animal`,`package`,`face`,`plate`],Ya={"unknown-frame":`The frame is no longer in the dataset.`,"unreadable-frame":`The frame copy could not be read.`,"unknown-profile":`That AI profile no longer exists.`,"profile-disabled":`That AI profile is disabled.`,"no-vision":`That AI profile cannot read images.`,"cloud-not-confirmed":`The frame was not sent: sending it outside the house needs your confirmation.`,"llm-error":`The AI model call failed.`,"malformed-answer":`The AI answered in a shape that cannot be trusted, so nothing was drawn.`};function Xa({frame:e,history:n,detector:i,schema:o,setNotice:s}){let c=Ce({},{retry:!1}),d=pe(),f=N(),[p,m]=l(`teacher`),h=a(()=>Ga(o,i.kind===`resolved`?i.modelId:void 0),[o,i]),[g,_]=l(null),v=h.find(e=>e.modelId===g)??h[0],[y,b]=l(Wa),[x,S]=l(null),C=(c.data??[]).find(e=>e.id===x)??c.data?.[0],[w,T]=l(qa),[E,D]=l(!1),[k,j]=l(!1),I=t(n.editor);I.current=n.editor;let L=p!==`llm`,R=p!==`teacher`,z=i.kind===`resolved`&&v!==void 0,B=C!==void 0&&w.length>0,ee=(!L||z)&&(!R||B),te=async()=>{if(i.kind!==`resolved`||v===void 0)return``;let t=await d.mutateAsync({...fa(e),subject:{kind:`objects`,modelId:v.modelId,minScore:y},nodeId:i.nodeId});if(t.kind===`refused`)return`${v.name} refused: ${t.reason}${t.detail===void 0?``:` — ${t.detail}`}.`;let r=Ca(I.current,t.proposals.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},kind:e.kind,source:`assist`,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore},draft:!0,note:`Proposed by the larger detector ${t.modelId} on ${i.nodeId}.`})));I.current=r.state,n.setEditor(r.state);let a=t.proposals.length-r.skipped;return`${v.name}: ${String(a)} new draft${a===1?``:`s`}${r.skipped>0?`, ${String(r.skipped)} already on the frame`:``}.`},H=async t=>{if(C===void 0)return``;let r=I.current,i=await f.mutateAsync({...fa(e),profileId:C.id,classes:[...w],boxes:r.boxes.slice(0,50).map(e=>({ref:e.key,bbox:e.bbox,macroClass:e.macroClass,...e.label!==void 0&&e.label!==``?{label:e.label}:{}})),allowCloud:t});if(i.kind===`refused`)return`${Ya[i.reason]??i.reason}${i.detail===void 0?``:` (${i.detail})`}`;let a=i.proposals.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},kind:`subject`,source:`llm`,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore},draft:!0,note:`${i.model}: ${e.reason}`})),o=Na(i.reviews,i.model),s=Ca(I.current,a);n.setEditor(e=>Ma(Ca(e,a).state,o));let c=i.proposals.length-s.skipped,l=i.reviews.filter(e=>e.verdict!==`confirmed`).length;return`${C.name}: ${String(c)} new draft${c===1?``:`s`}, ${String(l)} box${l===1?``:`es`} questioned${i.rejected>0?`, ${String(i.rejected)} unusable item${i.rejected===1?``:`s`} dropped`:``}.`},U=async e=>{D(!1),j(!0),s(null);try{let t=[];L&&t.push(await te()),R&&t.push(await H(e)),s(`${t.filter(e=>e!==``).join(` `)} Drafts are not saved until you accept or correct them.`)}catch(e){s(`The assist failed: ${e instanceof Error?e.message:String(e)}`)}finally{j(!1)}};return r(`div`,{className:`px-3 py-2 border-b border-border space-y-2 text-[11px]`,"data-testid":`retrain-assist`,children:[r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u(`span`,{className:`font-semibold text-foreground`,children:`Assist`}),u(F,{className:`w-36`,"aria-label":`Assist engine`,value:p,options:Ka.map(e=>({value:e.value,label:e.label})),onChange:e=>{let t=Ka.find(t=>t.value===e.target.value);t!==void 0&&m(t.value)}}),u(`span`,{className:`flex-1`}),r(V,{size:`sm`,variant:`secondary`,disabled:!ee||k,onClick:()=>{if(R&&C?.leavesHouse===!0){D(!0);return}U(!1)},children:[k?u(P,{className:`h-3 w-3 animate-spin`}):u(en,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Run`})]})]}),L&&(h.length===0||i.kind!==`resolved`?u(`p`,{className:`text-foreground-subtle`,children:i.kind===`resolved`?`The detection node’s catalog has no detector larger than this camera’s for its format.`:`The camera’s detection node is not known, so no larger detector can be run there.`}):r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u(F,{className:`flex-1 min-w-40`,"aria-label":`Larger detector`,value:v?.modelId??``,options:h.map(e=>({value:e.modelId,label:`${e.name} (${String(Math.round(e.sizeMB))} MB)`})),onChange:e=>{_(e.target.value)}}),u(J,{className:`w-20`,"aria-label":`Minimum score`,type:`number`,min:.05,max:.95,step:.05,value:y,onChange:e=>{let t=Number.parseFloat(e.target.value);Number.isFinite(t)&&b(Math.min(.95,Math.max(.05,t)))}}),r(`span`,{className:`text-foreground-subtle`,children:[`on `,i.nodeId]})]})),R&&((c.data??[]).length===0?u(`p`,{className:`text-foreground-subtle`,children:c.isError?`The AI profiles could not be read.`:`No enabled AI profile can read images. Add one under AI settings.`}):r(`div`,{className:`space-y-1.5`,children:[u(F,{"aria-label":`AI profile`,value:C?.id??``,options:(c.data??[]).map(e=>({value:e.id,label:`${e.name} · ${e.model}${e.leavesHouse?` · cloud`:` · local`}`})),onChange:e=>{S(e.target.value)}}),C?.leavesHouse===!0&&u(`p`,{className:`text-warning`,children:`This profile sends the frame outside your home, to a cloud service. Each run asks first.`}),r(`div`,{className:`flex items-center gap-1 flex-wrap`,children:[u(`span`,{className:`text-foreground-subtle`,children:`Look for:`}),Ja.map(e=>{let t=w.includes(e);return u(`button`,{type:`button`,"aria-pressed":t,className:`rounded-full border px-2 py-0.5 ${t?`border-primary text-primary`:`border-border text-foreground-muted`}`,onClick:()=>{T(n=>t?n.filter(t=>t!==e):[...n,e])},children:e},e)})]})]})),u(pt,{open:E,onOpenChange:D,children:r(O,{children:[r(M,{children:[u(A,{children:`Send this frame outside your home?`}),u(ct,{children:`The frame from ${e.origin===`recording`?`the recording`:`this track`} will be sent to ${C?.name??`the AI profile`} (${C?.kind??`cloud`}, model ${C?.model??``}), a service outside your network, to be analysed. Only this frame, for this run.`})]}),r(fe,{children:[u(V,{variant:`ghost`,size:`sm`,onClick:()=>{D(!1)},children:`Cancel`}),u(V,{size:`sm`,onClick:()=>void U(!0),children:`Send this frame`})]})]})})]})}function Za(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 Qa(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)}}var $a=.01;function eo(e){return e.w>=.01&&e.h>=.01}function to(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}var no=[`nw`,`n`,`ne`,`e`,`se`,`s`,`sw`,`w`];function ro(e,t,n){return{x:Math.min(Math.max(0,e.x+t),Math.max(0,1-e.w)),y:Math.min(Math.max(0,e.y+n),Math.max(0,1-e.h)),w:e.w,h:e.h}}function io(e,t,n,r){if(n){let e=Math.min(Math.max(0,r),t-$a);return{start:e,size:t-e}}return{start:e,size:Math.max(Math.min(1,r),e+$a)-e}}function ao(e,t,n){let r=t.includes(`w`)||t.includes(`e`)?io(e.x,e.x+e.w,t.includes(`w`),n.x):{start:e.x,size:e.w},i=t.includes(`n`)||t.includes(`s`)?io(e.y,e.y+e.h,t.includes(`n`),n.y):{start:e.y,size:e.h};return{x:r.start,y:i.start,w:r.size,h:i.size}}function oo(e,t){return{x:t.includes(`w`)?e.x:t.includes(`e`)?e.x+e.w:e.x+e.w/2,y:t.includes(`n`)?e.y:t.includes(`s`)?e.y+e.h:e.y+e.h/2}}function so(e,t,n){let r=(e,t,n)=>Math.abs(e-t)<=n,i=r(t.x,e.x,n.x),a=r(t.x,e.x+e.w,n.x),o=r(t.y,e.y,n.y),s=r(t.y,e.y+e.h,n.y),c=t.x>=e.x-n.x&&t.x<=e.x+e.w+n.x,l=t.y>=e.y-n.y&&t.y<=e.y+e.h+n.y;return!c||!l?null:o&&i?`nw`:o&&a?`ne`:s&&i?`sw`:s&&a?`se`:o?`n`:s?`s`:i?`w`:a?`e`:t.x>=e.x&&t.x<=e.x+e.w&&t.y>=e.y&&t.y<=e.y+e.h?`body`:null}var co={x:0,y:0,w:1,h:1},lo=1.5;function uo(e,t,n){return e<t?t:e>n?n:e}function fo(e){return 1/e.w}function po(e,t,n,r){return{x:uo(r.x+(e-n.left)/n.width*r.w,0,1),y:uo(r.y+(t-n.top)/n.height*r.h,0,1)}}function mo(e,t,n){return{x:t.left+(e.x-n.x)/n.w*t.width,y:t.top+(e.y-n.y)/n.h*t.height}}function ho(e,t,n){let r=mo(e,t,n);return{left:r.x,top:r.y,width:e.w/n.w*t.width,height:e.h/n.h*t.height}}function go(e,t){return{left:e.left-t.x/t.w*e.width,top:e.top-t.y/t.h*e.height,width:e.width/t.w,height:e.height/t.h}}function _o(e,t,n){let r=uo(e.w/n,1/16,1),i=r/e.w;return{x:uo(t.x-(t.x-e.x)*i,0,1-r),y:uo(t.y-(t.y-e.y)*i,0,1-r),w:r,h:r}}function vo(e,t,n){return{x:uo(e.x+t,0,1-e.w),y:uo(e.y+n,0,1-e.h),w:e.w,h:e.h}}function yo(e){return{x:e.x+e.w/2,y:e.y+e.h/2}}var bo=[`person`,`vehicle`,`animal`,`package`,`face`,`plate`];function xo(e){if(typeof e!=`object`||!e||!(`tagName`in e))return!1;let t=String(e.tagName).toUpperCase();return t===`INPUT`||t===`TEXTAREA`||t===`SELECT`?!0:`isContentEditable`in e&&e.isContentEditable===!0}function So(e){let t=e.ctrlKey||e.metaKey,n=e.key.toLowerCase();if(t&&!e.altKey)return n===`s`&&!e.shiftKey?{kind:`save`}:e.typing?null:n===`z`?e.shiftKey?{kind:`redo`}:{kind:`undo`}:n===`y`&&!e.shiftKey?{kind:`redo`}:null;if(e.typing||t||e.altKey)return null;switch(e.key){case`ArrowRight`:return{kind:`next-frame`};case`ArrowLeft`:return{kind:`prev-frame`};case`Delete`:case`Backspace`:return{kind:`delete`};case`Escape`:return{kind:`deselect`};case`Tab`:return e.shiftKey?{kind:`select-prev`}:{kind:`select-next`};case`+`:case`=`:return{kind:`zoom-in`};case`-`:case`_`:return{kind:`zoom-out`};case`0`:return{kind:`zoom-fit`};default:break}let r=Number.parseInt(e.key,10);if(Number.isInteger(r)&&r>=1&&r<=bo.length){let e=bo[r-1];return e===void 0?null:{kind:`set-class`,macroClass:e}}return n===`a`?e.shiftKey?{kind:`accept-all`}:{kind:`accept`}:n===`e`&&!e.shiftKey?{kind:`toggle-model-error`}:n===`c`&&!e.shiftKey?{kind:`toggle-complete`}:null}var Co=[{keys:`← / →`,does:`Previous / next frame`},{keys:`Drag on empty frame`,does:`Draw a box`},{keys:`Drag a box / its handles`,does:`Move / resize it`},{keys:`Delete, Backspace`,does:`Delete the selected box`},{keys:`1 – 6`,does:`Class: person, vehicle, animal, package, face, plate`},{keys:`A`,does:`Accept the selected draft`},{keys:`Shift + A`,does:`Accept every draft`},{keys:`E`,does:`Mark / unmark the selected box as a model error`},{keys:`C`,does:`Toggle "all subjects boxed"`},{keys:`Tab / Shift + Tab`,does:`Select the next / previous box`},{keys:`Esc`,does:`Deselect`},{keys:`Ctrl/⌘ + Z`,does:`Undo`},{keys:`Ctrl/⌘ + Shift + Z, Ctrl/⌘ + Y`,does:`Redo`},{keys:`Ctrl/⌘ + S`,does:`Save the frame`},{keys:`+ / − / 0, wheel, pinch`,does:`Zoom in / out / fit`},{keys:`Space + drag, middle drag, two fingers`,does:`Pan`}];n();var wo=.0015,To={pipeline:`var(--color-foreground-muted)`,assist:`var(--color-info)`,llm:`var(--color-warning)`,operator:`var(--color-success)`};function Eo(e,t){return e.kind===`model_error`?{color:`var(--color-danger)`,dashed:!0,opacity:1}:t?{color:`var(--color-primary)`,dashed:e.draft,opacity:1}:e.draft?{color:To[e.source],dashed:!0,opacity:.8}:{color:`var(--color-success)`,dashed:!1,opacity:1}}function Do(e,t){return Math.hypot(e.x-t.x,e.y-t.y)}function Oo(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}function ko({imageSrc:n,imageWidth:a,imageHeight:o,boxes:s,selectedKey:c,viewport:f,onViewportChange:p,panMode:m,onSelect:h,onDraw:g,onGestureStart:_,onGestureBox:v,onGestureEnd:y}){let b=t(null),[x,S]=l({w:0,h:0}),[C,w]=l(null),[T,E]=l(!1),D=t(new Map),O=t({mode:`none`});i(()=>{let e=b.current;if(e===null)return;let t=()=>S({w:e.clientWidth,h:e.clientHeight});if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return n.observe(e),()=>{n.disconnect()}},[]);let k=Za(x.w,x.h,a,o);d(()=>{let e=e=>{e.key!==` `||xo(e.target)||(e.preventDefault(),E(!0))},t=e=>{e.key===` `&&E(!1)};return window.addEventListener(`keydown`,e),window.addEventListener(`keyup`,t),()=>{window.removeEventListener(`keydown`,e),window.removeEventListener(`keyup`,t)}},[]);let A=t({image:k,viewport:f,onViewportChange:p});A.current={image:k,viewport:f,onViewportChange:p},d(()=>{let e=b.current;if(e===null)return;let t=t=>{let{image:n,viewport:r,onViewportChange:i}=A.current;if(n===null)return;t.preventDefault();let a=e.getBoundingClientRect();i(_o(r,po(t.clientX-a.left,t.clientY-a.top,n,r),Math.exp(-t.deltaY*wo)))};return e.addEventListener(`wheel`,t,{passive:!1}),()=>{e.removeEventListener(`wheel`,t)}},[]);let j=e(e=>{let t=b.current?.getBoundingClientRect();return{x:e.clientX-(t?.left??0),y:e.clientY-(t?.top??0)}},[]),M=e(e=>k===null?null:po(e.x,e.y,k,f),[k,f]),N=e(()=>{let e=O.current;(e.mode===`move`||e.mode===`resize`)&&y(),e.mode===`draw`&&w(null),O.current={mode:`none`}},[y]),P=e=>{if(k===null)return;let t=j(e);if(D.current.set(e.pointerId,t),e.currentTarget.setPointerCapture?.(e.pointerId),D.current.size===2){N();let[e,t]=[...D.current.values()];if(e===void 0||t===void 0)return;let n=Oo(e,t);O.current={mode:`pinch`,startDistance:Math.max(1,Do(e,t)),anchor:po(n.x,n.y,k,f),from:f};return}if(D.current.size>2)return;if(e.button===1||T||m){e.preventDefault(),O.current={mode:`pan`,startPx:t,from:f};return}if(e.button!==0)return;let n=po(t.x,t.y,k,f),r={x:12/k.width*f.w,y:12/k.height*f.h},i=s.find(e=>e.key===c);if(i!==void 0){let e=so(i.bbox,n,r);if(e!==null&&e!==`body`){_(),O.current={mode:`resize`,key:i.key,handle:e,from:i.bbox};return}}let a=s[to(s.map(e=>e.bbox),n)];if(a!==void 0){a.key!==c&&h(a.key),_(),O.current={mode:`move`,key:a.key,start:n,from:a.bbox};return}O.current={mode:`draw`,start:n},w(Qa(n,n))},F=e=>{if(!D.current.has(e.pointerId)||k===null)return;let t=j(e);D.current.set(e.pointerId,t);let n=O.current;switch(n.mode){case`pinch`:{let[e,t]=[...D.current.values()];if(e===void 0||t===void 0)return;let r=_o(n.from,n.anchor,Do(e,t)/n.startDistance),i=Oo(e,t),a=po(i.x,i.y,k,r);p(vo(r,n.anchor.x-a.x,n.anchor.y-a.y));return}case`pan`:{let e=(t.x-n.startPx.x)/k.width*n.from.w,r=(t.y-n.startPx.y)/k.height*n.from.h;p(vo(n.from,-e,-r));return}case`move`:{let e=po(t.x,t.y,k,f);v(n.key,ro(n.from,e.x-n.start.x,e.y-n.start.y));return}case`resize`:{let e=po(t.x,t.y,k,f);v(n.key,ao(n.from,n.handle,e));return}case`draw`:{let e=po(t.x,t.y,k,f);w(Qa(n.start,e));return}default:return}},I=e=>{if(!D.current.has(e.pointerId))return;D.current.delete(e.pointerId);let t=O.current;if(t.mode===`pinch`){D.current.size<2&&(O.current={mode:`none`});return}if(t.mode===`draw`){let n=M(j(e)),r=n===null?null:Qa(t.start,n);w(null),O.current={mode:`none`},r!==null&&eo(r)?g(r):h(null);return}N()},L=s.find(e=>e.key===c),R=T||m,z=k===null?null:go(k,f);return r(`div`,{ref:b,"data-testid":`retrain-canvas`,className:`relative w-full h-full min-h-[280px] bg-surface-sunken select-none touch-none overflow-hidden`,style:{cursor:R?`grab`:`crosshair`},onPointerDown:P,onPointerMove:F,onPointerUp:I,onPointerCancel:I,children:[z!==null&&u(`img`,{src:n,alt:`Frame being annotated`,draggable:!1,className:`absolute max-w-none pointer-events-none`,style:z}),k!==null&&s.map(e=>{let t=ho(e.bbox,k,f),n=e.key===c,i=Eo(e,n);return u(`div`,{"data-testid":`retrain-box-${e.key}`,"data-draft":e.draft?`true`:`false`,"data-source":e.source,className:`absolute pointer-events-none`,style:{left:t.left,top:t.top,width:t.width,height:t.height,border:`${n?`2px`:`1px`} ${i.dashed?`dashed`:`solid`} ${i.color}`,opacity:i.opacity},children:r(`span`,{className:`absolute -top-4 left-0 text-[10px] px-1 rounded whitespace-nowrap text-background`,style:{background:i.color},children:[e.label??e.macroClass,e.kind===`model_error`?` ✕`:``,e.draft?` ?`:``,e.flag!==void 0&&e.flag.verdict!==`confirmed`?` !`:``]})},e.key)}),k!==null&&L!==void 0&&no.map(e=>{let t=mo(oo(L.bbox,e),k,f);return u(`div`,{"data-testid":`retrain-handle-${e}`,className:`absolute h-2.5 w-2.5 -translate-x-1/2 -translate-y-1/2 rounded-sm border border-background bg-primary pointer-events-none`,style:{left:t.x,top:t.y}},e)}),C!==null&&k!==null&&u(`div`,{className:`absolute border border-dashed border-primary pointer-events-none`,style:ho(C,k,f)})]})}n();function Ao(){let[t,n]=l(co),[r,i]=l(!1);return{viewport:t,setViewport:n,zoomIn:e(()=>{n(e=>_o(e,yo(e),lo))},[]),zoomOut:e(()=>{n(e=>_o(e,yo(e),1/lo))},[]),fit:e(()=>{n(co)},[]),panMode:r,togglePan:e(()=>{i(e=>!e)},[])}}function jo({view:e,canUndo:t,canRedo:n,onUndo:i,onRedo:a}){let o=fo(e.viewport);return r(`div`,{className:`flex items-center gap-1 px-2 py-1 border-b border-border bg-surface`,children:[u(V,{variant:`ghost`,size:`sm`,"aria-label":`Zoom out`,onClick:e.zoomOut,children:u(ht,{className:`h-3.5 w-3.5`})}),r(`span`,{className:`w-12 text-center text-[11px] tabular-nums text-foreground-subtle`,children:[Math.round(o*100),`%`]}),u(V,{variant:`ghost`,size:`sm`,"aria-label":`Zoom in`,onClick:e.zoomIn,children:u(de,{className:`h-3.5 w-3.5`})}),u(V,{variant:`ghost`,size:`sm`,"aria-label":`Fit the whole frame`,disabled:o<=1,onClick:e.fit,children:u(Xt,{className:`h-3.5 w-3.5`})}),u(V,{variant:e.panMode?`secondary`:`ghost`,size:`sm`,"aria-label":`Pan tool`,"aria-pressed":e.panMode,onClick:e.togglePan,children:u(L,{className:`h-3.5 w-3.5`})}),u(`span`,{className:`flex-1`}),u(V,{variant:`ghost`,size:`sm`,"aria-label":`Undo`,disabled:!t,onClick:i,children:u(K,{className:`h-3.5 w-3.5`})}),u(V,{variant:`ghost`,size:`sm`,"aria-label":`Redo`,disabled:!n,onClick:a,children:u(Qt,{className:`h-3.5 w-3.5`})}),r(_e,{children:[u(W,{"aria-label":`Keyboard shortcuts`,className:`inline-flex h-7 items-center rounded-md px-2 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:u(Jt,{className:`h-3.5 w-3.5`})}),r(R,{className:`w-80`,children:[u(`h3`,{className:`mb-2 text-xs font-semibold text-foreground`,children:`Keyboard and gestures`}),u(`table`,{className:`w-full text-[11px]`,children:u(`tbody`,{children:Co.map(e=>r(`tr`,{className:`align-top`,children:[u(`td`,{className:`py-0.5 pr-2 font-mono whitespace-nowrap text-foreground`,children:e.keys}),u(`td`,{className:`py-0.5 text-foreground-subtle`,children:e.does})]},e.keys))})})]})]})]})}function Mo(e){return{past:[],present:e,future:[],gestureBase:null}}function No(e,t){let n=[...e,t];return n.length>100?n.slice(n.length-100):n}function Po(e,t){return t===e.present?e:{past:No(e.past,e.present),present:t,future:[],gestureBase:null}}function Fo(e,t){return{...e,present:t}}function Io(e){let t=e.past[e.past.length-1];return t===void 0?e:{past:e.past.slice(0,-1),present:t,future:[e.present,...e.future],gestureBase:null}}function Lo(e){let[t,...n]=e.future;return t===void 0?e:{past:No(e.past,e.present),present:t,future:n,gestureBase:null}}function Ro(e){return{...e,gestureBase:e.present}}function zo(e,t){return{...e,present:t}}function Bo(e){let t=e.gestureBase;return t===null?e:t===e.present?{...e,gestureBase:null}:{past:No(e.past,t),present:e.present,future:[],gestureBase:null}}function Vo(e){return e.past.length>0}function Ho(e){return e.future.length>0}n();function Uo(e,t){return typeof e==`function`?e(t):e}function Wo(t){let[n,r]=l(()=>Mo(t())),i=e(e=>{r(t=>Po(t,Uo(e,t.present)))},[]),a=e(e=>{r(Mo(e))},[]),o=e(e=>{r(t=>Fo(t,Uo(e,t.present)))},[]),s=e(()=>{r(e=>Ro(e))},[]),c=e(e=>{r(t=>zo(t,Uo(e,t.present)))},[]),u=e(()=>{r(e=>Bo(e))},[]),d=e(()=>{r(e=>Io(e))},[]),f=e(()=>{r(e=>Lo(e))},[]);return{editor:n.present,setEditor:i,resetEditor:a,selectOnly:o,beginGesture:s,updateGesture:c,endGesture:u,undo:d,redo:f,canUndo:Vo(n),canRedo:Ho(n)}}n();function Go(e,t){let n=e.boxes.length;if(n===0)return null;let r=e.boxes.findIndex(t=>t.key===e.selectedKey),i=r<0?t===1?0:n-1:(r+t+n)%n;return e.boxes[i]?.key??null}function Ko(e,t){let{history:n}=t,r=n.editor.selectedKey;switch(e.kind){case`next-frame`:return t.onNextFrame();case`prev-frame`:return t.onPrevFrame();case`toggle-complete`:return t.onToggleComplete();case`save`:return t.onSave();case`undo`:return n.canUndo?(n.undo(),!0):!1;case`redo`:return n.canRedo?(n.redo(),!0):!1;case`zoom-in`:return t.onZoomIn(),!0;case`zoom-out`:return t.onZoomOut(),!0;case`zoom-fit`:return t.onZoomFit(),!0;case`accept-all`:return n.setEditor(e=>Oa(e)),!0;case`select-next`:case`select-prev`:{let t=Go(n.editor,e.kind===`select-next`?1:-1);return t===null?!1:(n.selectOnly(e=>ja(e,t)),!0)}case`deselect`:return r===null?!1:(n.selectOnly(e=>ja(e,null)),!0);default:break}if(r===null)return!1;switch(e.kind){case`delete`:return n.setEditor(e=>Aa(e,r)),!0;case`set-class`:return n.setEditor(t=>Ea(t,r,{macroClass:e.macroClass})),!0;case`accept`:return n.setEditor(e=>Da(e,r)),!0;case`toggle-model-error`:return n.setEditor(e=>ka(e,r)),!0;default:return!1}}function qo(e,n){let r=t(n);r.current=n,d(()=>{if(!e)return;let t=e=>{if(e.defaultPrevented||e.isComposing)return;let t=So({key:e.key,ctrlKey:e.ctrlKey,metaKey:e.metaKey,shiftKey:e.shiftKey,altKey:e.altKey,typing:xo(e.target)});t!==null&&Ko(t,r.current)&&e.preventDefault()};return window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`keydown`,t)}},[e])}n();var Jo=`person`,Yo={pending:`Reading which detector this camera runs…`,"placement-unreadable":`The detection stage of this camera could not be read, so the model it runs is unknown — not absent.`,"detection-off":`This camera runs no object detector, so there is no proposal to mirror.`,"node-unreachable":`The node that detects for this camera did not answer about its accelerators.`,"device-unknown":`The node does not list the accelerator this camera detects on — asking another one would propose with a different model.`,"step-unknown":`That node carries no object-detection step in its catalog.`,"no-model":`No object-detection model on that accelerator can be resolved for this camera.`};function Xo({frames:n,activeFrameId:i,onActiveFrame:o,onFramesChanged:s,onSaved:c,setNotice:f,picked:p=!1,onTogglePick:m}){let h=n.find(e=>e.frameId===i),g=h?.deviceId??null,_=Wo(()=>Sa([],[])),{editor:v,setEditor:y,resetEditor:b,selectOnly:x}=_,S=Ao(),w=Le({frameIds:[i]}),E=We({frameId:i}),D=pe(),O=T(),k=re(),A=Qe({deviceIds:g===null?[]:[g]},{enabled:g!==null,staleTime:3e4}),j=A.data?.[0]?.detection?.nodeId??null,M=le({nodeId:j??``},{enabled:j!==null,staleTime:3e4}),N=ee({nodeId:j??``},{enabled:j!==null,staleTime:3e4}),F=Ue({deviceId:g??0},{enabled:g!==null,staleTime:3e4}),I=a(()=>ga({status:A.data?.[0],nodeDevices:M.data,schema:N.data,resolvedSteps:F.data?.steps}),[A.data,M.data,N.data,F.data]),L=t({stored:w.data,copy:h});L.current={stored:w.data,copy:h};let R=h!==void 0;d(()=>{S.fit();let{stored:e,copy:t}=L.current;b(Sa((e??[]).filter(e=>e.mediaKey===i),t?.pipelineBoxes??[]))},[i,w.dataUpdatedAt,R,b,S.fit]);let z=e(async e=>{h!==void 0&&(await k.mutateAsync({...fa(h),complete:e}),await s())},[h,k,s]),B=e(async e=>{if(h===void 0)return;if(f(null),I.kind!==`resolved`){f(Yo[I.gap]);return}let t=await D.mutateAsync({...fa(h),subject:e===`package`?{kind:`package`}:{kind:`objects`,modelId:I.modelId,minScore:I.minScore},nodeId:I.nodeId});if(t.kind===`refused`){f(t.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: ${t.reason}${t.detail===void 0?``:` — ${t.detail}`}`);return}let n=Ca(v,t.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},draft:!0})));y(n.state),f(`${t.proposals.length} proposal${t.proposals.length===1?``:`s`} from ${t.modelId}`+(n.skipped>0?` — ${n.skipped} already on the frame`:``)+(t.belowThreshold>0?` — ${t.belowThreshold} more were below ${t.minScore.toFixed(2)}`:``)+`. Accept or correct each one; drafts are not saved.`)},[h,D,I,v,y,f]),te=e(e=>{y(t=>wa(t,e,Jo))},[y]),[U,W]=l(!1),G=e(async()=>{if(h===void 0)return;let e=Pa(v);W(!0);try{await O.mutateAsync({...fa(h),annotations:[...Ia(v)]}),await w.refetch()}finally{W(!1)}await c?.(),f(e>0?`Annotations saved. ${String(e)} unconfirmed draft${e===1?` was`:`s were`} not saved.`:`Annotations saved.`)},[h,v,O,w,c,f]),K=E.data,ne=Ua(v.boxes)&&h!==void 0,q=Pa(v),ie=n.map(e=>e.frameId),ae=e=>{let t=ie.indexOf(i),n=ie[t+e];return t<0||n===void 0?!1:(o(n),!0)};return qo(!U,{history:_,onNextFrame:()=>ae(1),onPrevFrame:()=>ae(-1),onToggleComplete:()=>h===void 0||k.isPending?!1:(z(!h.complete),!0),onSave:()=>!ne||U?!1:(G(),!0),onZoomIn:S.zoomIn,onZoomOut:S.zoomOut,onZoomFit:S.fit}),r(`div`,{className:`grid grid-cols-1 xl:grid-cols-[minmax(0,1fr)_minmax(0,380px)] gap-3 ${U?`pointer-events-none opacity-70`:``}`,"aria-busy":U,children:[r(`div`,{className:`rounded-md border border-border overflow-hidden flex flex-col`,children:[u(jo,{view:S,canUndo:_.canUndo,canRedo:_.canRedo,onUndo:_.undo,onRedo:_.redo}),K===void 0?r(`div`,{className:`flex items-center gap-2 p-6 text-xs text-foreground-subtle`,children:[u(P,{className:`h-3.5 w-3.5 animate-spin`}),`Loading the frame…`]}):u(ko,{imageSrc:`data:image/jpeg;base64,${K.base64}`,imageWidth:K.width,imageHeight:K.height,boxes:v.boxes,selectedKey:v.selectedKey,viewport:S.viewport,onViewportChange:S.setViewport,panMode:S.panMode,onSelect:e=>{x(t=>ja(t,e))},onDraw:te,onGestureStart:_.beginGesture,onGestureBox:(e,t)=>{_.updateGesture(n=>Ea(n,e,{bbox:t}))},onGestureEnd:_.endGesture})]}),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 flex-wrap`,children:[u(`h2`,{className:`text-xs font-semibold text-foreground flex-1`,children:`Subjects`}),h?.origin===`recording`&&u(Y,{variant:`info`,children:`from the recording`}),m!==void 0&&r(V,{variant:p?`primary`:`ghost`,size:`sm`,"aria-pressed":p,title:`Pick this frame for a dataset version (Datasets tab)`,onClick:m,children:[u(Zt,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:p?`Picked`:`Pick for dataset`})]}),r(V,{variant:`secondary`,size:`sm`,disabled:D.isPending||I.kind!==`resolved`,onClick:()=>void B(`objects`),children:[u(H,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Propose`})]}),r(V,{variant:`secondary`,size:`sm`,disabled:D.isPending||I.kind!==`resolved`,onClick:()=>void B(`package`),children:[u(H,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Packages`})]})]}),u(`div`,{className:`px-3 py-1 border-b border-border text-[11px] text-foreground-subtle`,children:I.kind===`resolved`?`Proposals come from ${I.modelId} at ${I.minScore.toFixed(2)}, on ${I.nodeId} — what this camera really runs.`:Yo[I.gap]}),h!==void 0&&u(Xa,{frame:h,history:_,detector:I,schema:N.data,setNotice:f}),u(`div`,{className:`flex-1 overflow-y-auto`,children:u(Ha,{boxes:v.boxes,selectedKey:v.selectedKey,onSelect:e=>{x(t=>ja(t,e))},onChange:(e,t)=>{y(n=>Ea(n,e,t))},onAccept:e=>{y(t=>Da(t,e))},onToggleModelError:e=>{y(t=>ka(t,e))},onDelete:e=>{y(t=>Aa(t,e))}})}),r(`label`,{className:`px-3 py-2 border-t border-border flex items-center gap-2 text-[11px] text-foreground`,children:[u(C,{"aria-label":`All subjects in this frame are boxed`,checked:h?.complete===!0,disabled:h===void 0||k.isPending,onChange:e=>void z(e.target.checked)}),r(`span`,{className:`flex-1`,children:[`All subjects boxed`,u(`span`,{className:`block text-foreground-subtle`,children:`Detector evaluation uses only these frames — an unboxed person counts as a false alarm. A frame with nothing in it, ticked, is a negative example.`})]})]}),q>0&&r(`div`,{className:`px-3 py-2 border-t border-border flex items-center gap-2 text-[11px] text-warning`,children:[r(`span`,{className:`flex-1`,children:[q,` draft`,q===1?``:`s`,` not confirmed — a draft is never saved. Accept, correct or delete each one.`]}),r(V,{variant:`secondary`,size:`sm`,onClick:()=>{y(e=>Oa(e))},children:[u(Pt,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Accept all`})]})]}),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:[v.boxes.filter(e=>e.kind===`model_error`).length,` marked as model errors`]}),u(V,{size:`sm`,disabled:!ne||U,onClick:()=>void G(),children:`Save frame`})]})]})]})}n();var Zo={"empty-name":`Give the collection a name.`,"duplicate-name":`A collection with that name already exists.`,"unknown-collection":`That collection no longer exists.`};function Qo(){let[t,n]=l(`tracks`),[i,o]=l(null),[c,f]=l(null),[p,m]=l(null),[h,g]=l(new Map),[_,v]=l(null),[y,b]=l([]),x=nt({projection:`slim`,isCamera:!0}),C=a(()=>{let e=new Map;for(let t of x.data??[])e.set(t.id,t.name);return e},[x.data]),w=ue({}),T=mt({trackId:i?.trackId??``},{enabled:t===`tracks`&&i!==null}),D=ne(),O=qe(),k=S(),A=_t({}),j=ot({collectionId:c?.id??``},{enabled:t===`collections`&&c!==null}),M=Pe(),N=He(),P=tt(),F=ae(),I=t===`tracks`?T.data?.copies??[]:j.data??[],L=e(()=>t===`tracks`?T.refetch():j.refetch(),[t,T,j]);d(()=>{p===null&&I.length>0&&m(I[0].frameId)},[I,p]);let R=e(()=>{m(null),g(new Map),v(null)},[]),B=e(e=>{o(e),R()},[R]),ee=e(e=>{f(e),R()},[R]),te=e(async e=>{if(i===null)return;let t=await D.mutateAsync({deviceId:i.deviceId,trackId:i.trackId,mediaIds:[e]});if(t.refused.length>0){let e=new Map(h);for(let n of t.refused)e.set(n.sourceMediaId,n.reason);g(e)}t.copied.length>0&&m(t.copied[0].frameId),await T.refetch(),await w.refetch()},[i,D,h,T,w]),H=e(async e=>{let t=(T.data?.copies??[]).find(t=>t.frameId===e);t!==void 0&&(await O.mutateAsync(fa(t)),p===e&&m(null),await T.refetch(),await w.refetch(),await A.refetch())},[T,O,p,w,A]),U=e(async()=>{if(i===null)return;let e=await k.mutateAsync({deviceId:i.deviceId,trackId:i.trackId});v(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 w.refetch(),e.changed&&o(null)},[i,k,w]),W=e(async e=>{let t=await M.mutateAsync({name:e});return await A.refetch(),t.kind===`refused`?Zo[t.reason]??t.reason:(f(t.collection),R(),null)},[M,A,R]),G=e(async(e,t)=>{let n=await N.mutateAsync({id:e,name:t});return await A.refetch(),n.kind===`refused`?Zo[n.reason]??n.reason:(c?.id===e&&f(n.collection),null)},[N,A,c]),K=e(async e=>{let t=await P.mutateAsync({id:e});c?.id===e&&(f(null),R()),await A.refetch(),v(t.deleted?`Collection deleted${t.removedFrames>0?` — ${String(t.removedFrames)} recording frame${t.removedFrames===1?``:`s`} no other collection held left the dataset`:``}.`:`That collection no longer existed.`)},[P,c,A,R]),q=e(async e=>{if(c===null)return;let t=await F.mutateAsync({collectionId:c.id,frameId:e.frameId});p===e.frameId&&m(null),await j.refetch(),await A.refetch(),v(t.deletedFrame?`Removed — it was a recording frame no other collection held, so it left the dataset with its boxes.`:`Removed from the collection.`)},[c,F,p,j,A]),re=e(async()=>{await w.refetch()},[w]),ie=t===`tracks`?i!==null:c!==null,oe=I.some(e=>e.frameId===p);return r(Ft,{subtitle:`Turn marked tracks and frames sent from recordings into an annotated dataset. Every frame is a copy the dataset owns — it never depends on media that can be swept.`,actions:t===`tracks`&&i!==null?r(V,{size:`sm`,onClick:()=>void U(),children:[u(Xe,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Complete track`})]}):null,children:[_!==null&&u(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-xs text-foreground`,children:_}),u(aa,{}),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:[u(E,{value:t,onValueChange:e=>{n(e===`collections`||e===`datasets`?e:`tracks`),R()},children:r(z,{className:`px-2 pt-2`,children:[r(me,{value:`tracks`,children:[`Tracks `,u(Y,{className:`ml-1`,children:w.data?.length??0})]}),r(me,{value:`collections`,children:[`Collections `,u(Y,{className:`ml-1`,children:A.data?.length??0})]}),u(me,{value:`datasets`,children:`Datasets`})]})}),t===`tracks`?u(da,{tracks:w.data??[],isLoading:w.isLoading,selectedTrackId:i?.trackId??null,deviceNames:C,onSelect:B}):t===`datasets`?u(`p`,{className:`p-3 text-[11px] text-foreground-subtle`,children:`A dataset version freezes the frames a selection of cameras, collections and picked frames yields, with the hash of their boxes, so a training run can name exactly what it learned from. Pick frames with "Pick for dataset" in the frame workbench.`}):u(Zi,{collections:A.data??[],isLoading:A.isLoading,selectedId:c?.id??null,onSelect:ee,onCreate:W,onRename:G,onDelete:K})]}),u(`section`,{className:`space-y-3 min-w-0`,children:t===`datasets`?u(ia,{deviceNames:C,collections:A.data??[],pickedFrameIds:y,onClearPicked:()=>{b([])}}):ie?r(s,{children:[u(`div`,{className:`rounded-md border border-border bg-surface p-3`,children:t===`tracks`?u(sa,{candidates:T.data?.candidates??[],copies:T.data?.copies??[],activeFrameId:p,refusals:h,isSelecting:D.isPending,onSelectCandidate:e=>void te(e),onOpenCopy:m,onRemoveCopy:e=>void H(e),renderCopyActions:e=>u(Ji,{frameId:e.frameId,onAdded:()=>A.refetch()})}):u(Xi,{frames:j.data??[],isLoading:j.isLoading,activeFrameId:p,deviceNames:C,onOpen:m,onRemove:e=>void q(e)})}),p!==null&&oe&&u(Xo,{frames:I,activeFrameId:p,onActiveFrame:m,onFramesChanged:L,onSaved:re,setNotice:v,picked:y.includes(p),onTogglePick:()=>{b(e=>e.includes(p)?e.filter(e=>e!==p):[...e,p])}})]}):u(`p`,{className:`text-xs text-foreground-subtle`,children:t===`tracks`?`Pick a track from the staging list to start annotating it.`:`Pick or create a collection.`})})]})]})}function $o(){return u(`div`,{className:`flex flex-col p-4`,children:u(Vt,{tabs:[{id:`feed`,label:`Feed`,icon:ge,content:u(qi,{})},{id:`retrain`,label:`Retrain`,icon:Xe,content:u(Qo,{})},{id:`debug`,label:`Debug`,icon:st,content:u(bi,{})}]})})}export{$o as EventsPage};
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{X as f,Z as p,at as m,ct as h,ft as g,gt as _,ht as v,st as y,vt as b}from"./player-overlays-D4lg_avJ.js";import{$n as x,$o as S,$t as C,An as w,As as T,Bt as E,Cd as D,Cn as O,Cs as k,Dn as A,Dt as j,En as M,Es as N,Fd as P,Fn as F,Fs as I,Gd as L,Gt as R,Ht as z,If as B,In as V,Is as ee,Jn as te,Ju as H,Kn as U,Kt as W,Lo as G,Lu as K,Ms as ne,Nn as q,Ns as re,Nt as ie,Os as ae,Pd as oe,Ps as se,Qo as ce,Qs as le,Ss as ue,Su as de,Tn as fe,Ts as pe,Ut as me,Vd as he,Wf as ge,Wt as _e,Wu as ve,Xt as ye,Yt as be,Zd as xe,Zt as Se,_s as Ce,as as we,at as Te,au as Ee,bn as J,bs as De,cd as Oe,cf as ke,cs as Ae,df as je,ds as Me,er as Ne,es as Pe,fs as Fe,gf as Ie,gs as Le,hd as Re,if as ze,is as Be,js as Ve,ks as He,lc as Ue,ls as We,ms as Ge,on as Ke,os as qe,ou as Je,ps as Ye,qd as Xe,qn as Ze,qs as Qe,qu as $e,rd as et,rs as tt,sa as nt,sn as rt,tr as Y,ts as it,us as at,vs as ot,wf as st,wn as ct,wr as lt,ws as ut,wu as dt,xf as ft,xn as pt,xs as mt,xu as ht,yn as gt,ys as _t,yu as vt}from"./src-DOjmjjKA.js";import{a as yt,c as bt,d as xt,f as St,i as Ct,m as wt,n as Tt,o as Et,p as Dt,r as Ot,s as kt,t as At}from"./debounced-invalidate-BWOIWEOF.js";import{Un as jt,pi as Mt}from"./client-BqN2lVYf.js";import{t as Nt}from"./useTranslation-Bc5yH9V9.js";import"./mount-x_xV7wRP.js";import{et as Pt}from"./index-BNq9yPTv.js";import{t as Ft}from"./AdminPage-BSFohA3i.js";import{a as It,i as Lt,r as Rt,t as zt}from"./authed-media-st_x8Og8.js";import{t as Bt}from"./use-stationary-objects-e1GejQDW.js";import{t as Vt}from"./AdminTabs-Bxj9C3Dy.js";import{t as Ht}from"./format-size-DIxKXxtj.js";var Ut=b(`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`}]]),Wt=b(`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`}]]),Gt=b(`circle`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),Kt=b(`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`}]]),qt=b(`folder-plus`,[[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`M9 13h6`,key:`1uhe8q`}],[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]),Jt=b(`keyboard`,[[`path`,{d:`M10 8h.01`,key:`1r9ogq`}],[`path`,{d:`M12 12h.01`,key:`1mp3jc`}],[`path`,{d:`M14 8h.01`,key:`1primd`}],[`path`,{d:`M16 12h.01`,key:`1l6xoz`}],[`path`,{d:`M18 8h.01`,key:`emo2bl`}],[`path`,{d:`M6 8h.01`,key:`x9i8wu`}],[`path`,{d:`M7 16h10`,key:`wp8him`}],[`path`,{d:`M8 12h.01`,key:`czm47f`}],[`rect`,{width:`20`,height:`16`,x:`2`,y:`4`,rx:`2`,key:`18n3k1`}]]),Yt=b(`list-video`,[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M10 12H3`,key:`1ulcyk`}],[`path`,{d:`M10 19H3`,key:`108z41`}],[`path`,{d:`M15 12.003a1 1 0 0 1 1.517-.859l4.997 2.997a1 1 0 0 1 0 1.718l-4.997 2.997a1 1 0 0 1-1.517-.86z`,key:`ms4nik`}]]),Xt=b(`maximize`,[[`path`,{d:`M8 3H5a2 2 0 0 0-2 2v3`,key:`1dcmit`}],[`path`,{d:`M21 8V5a2 2 0 0 0-2-2h-3`,key:`1e4gt3`}],[`path`,{d:`M3 16v3a2 2 0 0 0 2 2h3`,key:`wsl5sc`}],[`path`,{d:`M16 21h3a2 2 0 0 0 2-2v-3`,key:`18trek`}]]),Zt=b(`package-plus`,[[`path`,{d:`M12 22V12`,key:`d0xqtd`}],[`path`,{d:`M16 17h6`,key:`1ook5g`}],[`path`,{d:`M19 14v6`,key:`1ckrd5`}],[`path`,{d:`M21 10.535V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.729l7 4a2 2 0 0 0 2 .001l1.675-.955`,key:`28k6lz`}],[`path`,{d:`M3.29 7 12 12l8.71-5`,key:`19ckod`}],[`path`,{d:`m7.5 4.27 8.997 5.148`,key:`9yrvtv`}]]),Qt=b(`redo-2`,[[`path`,{d:`m15 14 5-5-5-5`,key:`12vg1m`}],[`path`,{d:`M20 9H9.5A5.5 5.5 0 0 0 4 14.5A5.5 5.5 0 0 0 9.5 20H13`,key:`6uklza`}]]),$t=b(`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`}]]),en=b(`wand-sparkles`,[[`path`,{d:`m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72`,key:`ul74o6`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`M5 6v4`,key:`ilb8ba`}],[`path`,{d:`M19 14v4`,key:`blhpug`}],[`path`,{d:`M10 2v2`,key:`7u0qdc`}],[`path`,{d:`M7 8H3`,key:`zfb6yr`}],[`path`,{d:`M21 16h-4`,key:`1cnmox`}],[`path`,{d:`M11 3H9`,key:`1obp7u`}]]);n();function tn(e){let t=e.subLabel??e.label;if(t!==void 0)return t;let n=e.audioLabels?.[0]?.label;return n!==void 0&&n.length>0?n:void 0}var nn=720*60*60*1e3;function rn(e){let t=[];for(let n of e)t.push(...n);return t}function an(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function on(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 sn(e,t){return`${String(e)}:${t}`}function cn(e,t){let n=new Map,r=new Set;for(let i of e){let e=sn(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 ln(e,t){return{since:e.fromMs??t-nn,until:e.toMs??t}}var un=[`native`,`raster`,`standin`];function dn(e){return un.some(t=>t===e)}var fn={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 pn(e){return e===`standin`?fn.standin:e===`raster`?fn.raster:null}var mn={"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 hn(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:mn[r]??r,detail:i,raw:t}}function gn(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 _n({row:e,cameraName:t,nowMs:n,onOpenDetail:i,selected:a=!1,onToggleSelect:o,score:s,provenance:c,footer:l}){let d=It(e.mediaId===void 0?Lt(`track`,e.trackId):Rt(e.mediaId)),f=Math.round(e.importance*100),p=s===void 0?void 0:Math.round(s*100),m=gn(e.windowMs),_=()=>i(e),v=pn(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:_,className:`h-full w-full cursor-zoom-in object-cover`}):u(`button`,{type:`button`,onClick:_,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(g,{className:`h-6 w-6 opacity-60`})}),o&&u(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(sn(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(wt,{className:`h-4 w-4 text-primary`}):u(h,{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)}),v!==null&&u(`span`,{className:`absolute bottom-1 right-1 z-10 rounded px-1.5 py-0.5 text-[10px] font-semibold text-white ${v.tone===`warning`?`bg-warning/90`:`bg-black/70`}`,title:v.title,children:v.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(Xe,{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(st,{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($e,{className:`h-3 w-3`})})]})]}),r(`button`,{type:`button`,onClick:_,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,tn(e)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,tn(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:St(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 vn=1400,yn=`Admin-gated URL — opens only inside an authenticated session`;function bn({label:t,value:n,title:i}){let[a,o]=l(!1),s=te();return d(()=>{if(!a)return;let e=setTimeout(()=>o(!1),vn);return()=>clearTimeout(e)},[a]),r(`button`,{type:`button`,onClick:e(()=>{(async()=>{try{await navigator.clipboard.writeText(n),o(!0)}catch{await s({title:`Copy the media URL`,message:`Clipboard access was refused. Select the URL below and copy it manually.`,label:`${t} URL`,defaultValue:n,readOnly:!0,cancelLabel:`Close`})}})()},[n,t,s]),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?ft:ke,{className:`h-2.5 w-2.5 shrink-0`}),u(`span`,{className:`truncate`,children:a?`Copied`:t})]})}function xn({localUrl:e,publicUrl:t}){return r(`div`,{className:`flex flex-wrap gap-1`,children:[u(bn,{label:`Local`,value:e,title:`Copy LAN URL — ${yn}`}),t&&u(bn,{label:`Public`,value:t,title:`Copy public URL — ${yn}`})]})}var Sn={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`,confirmationCrop:`Confirmation crop (what the gate saw)`,debugCrop:`Debug crop (why this decision)`,sceneFrame:`Scene frame (clean)`,lastSceneFrame:`Last frame (clean)`};function Cn(e){return e in Sn}function wn(e){return Cn(e)?Sn[e]:e}function Tn(e,t){return`${e}${t}`}n();var En=3e4;function Dn(t){let[n,r]=l(null),i=e(e=>{r(t=>t??e)},[]);return d(()=>{t||r(null)},[t]),{publicOrigin:n,probes:t?u(On,{onOrigin:i}):null}}function On({onOrigin:e}){let{data:t}=lt({capName:`network-access`});return u(s,{children:(t??[]).map(t=>u(kn,{addonId:t.addonId,onOrigin:e},t.addonId))})}function kn({addonId:e,onOrigin:t}){let{data:n}=G({addonId:e},{refetchInterval:En,retry:!1});return d(()=>{let e=n?jt.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 An=typeof se==`function`,jn=`Track flags arrive with the next server update`;function Mn(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var Nn=An?se:Mn;function Pn(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 Fn({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 In({deviceId:e,trackId:t,markForTrain:n,debug:i,favourited:a,onChange:o}){let s=Nn(),c=U(),[d,f]=l(null),p=d?.markForTrain??n===!0,m=d?.debug??i===!0,h=d?.favourited??a===!0,g=!An||s.isPending,_=An?void 0:jn,v=n=>{g||(async()=>{try{let r=Pn(await s.mutateAsync({deviceId:e,trackId:t,flags:n}));if(!r)return;f(r),o?.(r)}catch(e){let t=e instanceof Error?e.message:``;await c({title:`Could not update this track`,message:t===``?`Could not update this track. Check the server logs.`:t,variant:`danger`})}})()};return r(`div`,{className:`grid gap-1.5 sm:grid-cols-2`,children:[u(Fn,{label:`Mark for training`,hint:`Keeps this track and its media past retention`,checked:p,disabled:g,..._===void 0?{}:{title:_},icon:u(Xe,{className:`h-4 w-4`}),onToggle:()=>v({markForTrain:!p})}),u(Fn,{label:`Debug`,hint:`Flag this track for diagnostic attention`,checked:m,disabled:g,..._===void 0?{}:{title:_},icon:u(st,{className:`h-4 w-4`}),onToggle:()=>v({debug:!m})}),u(Fn,{label:`Favourited`,hint:`Keeps this track and its media past retention`,checked:h,disabled:g,..._===void 0?{}:{title:_},icon:u($e,{className:`h-4 w-4`}),onToggle:()=>v({favourited:!h})})]})}var Ln=100,Rn=120,zn={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Bn=e=>e<0?0:e>1?1:e,Vn=e=>Math.round(e*100)/100;function Hn(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 Un(e,t,n){if(e.length===0||t===null)return zn;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return zn;let a=Hn(e,n?.maxPoints??Rn).map(e=>({x:Vn(Bn(e.x/r)*Ln),y:Vn(Bn(e.y/i)*Ln)})),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:Vn(Bn(e.x/r)*Ln),y:Vn(Bn(e.y/i)*Ln),mediaId:e.mediaId})),u=null,d=-1;for(let t of e){let e=Bn(t.bbox.w/r)*Bn(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:Vn(Bn(u.bbox.x/r)*Ln),y:Vn(Bn(u.bbox.y/i)*Ln),w:Vn(Bn(u.bbox.w/r)*Ln),h:Vn(Bn(u.bbox.h/i)*Ln)}:null}}var Wn=typeof we==`function`,Gn=`Track deletion arrives with the next server update`;function Kn(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var qn=Wn?we:Kn;n();var Jn=15e3,Yn=f();function Xn({url:e,label:t}){let{src:n,failed:r}=It(e);return n===null?u(`div`,{className:`flex h-full w-full items-center justify-center bg-surface-hover`,children:r?u(g,{className:`h-4 w-4 text-foreground-subtle opacity-60`}):u(P,{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 Zn=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),Qn=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`,`sceneFrame`,`lastSceneFrame`]);function $n(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 er({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.mediaId)}:void 0,children:u(`title`,{children:`Snapshot checkpoint — click to view this frame`})},`snap-${String(e.mediaId)}-${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 X({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 tr({row:t,cameraName:n,deleteAvailable:i,onClose:o,onDeleted:c,onFlagsChanged:f}){let p=m(),h=U(),_=Ze(),v=qn(),b=t!==null,x=t?.deviceId??0,S=t?.trackId??``,C=t?.timestamp??0,w=t?.windowMs??0,{data:T}=at({deviceId:x,trackId:S},{enabled:b}),{data:E}=k({trackId:S,deviceId:x},{enabled:b}),D=T?.bestEventId===void 0?void 0:Number(T.bestEventId),{data:A}=Ge({ownerType:`object`,eventId:D??0,deviceId:x},{enabled:b&&D!==void 0&&Number.isFinite(D)}),{data:j}=Je({deviceId:x},{enabled:b}),M=(j??[]).find(e=>e.addonId!==void 0)?.addonId,{data:N}=Ee({deviceId:x,since:C-Jn,until:C+w+Jn,provider:M??``},{enabled:b&&M!==void 0}),[F,I]=l(null),[L,R]=l(!1),{publicOrigin:z,probes:B}=Dn(b);d(()=>{I(null)},[x,S]);let ee=a(()=>{let e=E??[],t=A??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[E,A]),te=F??ee,H=It(te?te.url:void 0),W=a(()=>{let e=new Set,t=[];for(let n of[...A??[],...E??[]])e.has(n.mediaId)||(e.add(n.mediaId),t.push(n));return t},[A,E]),G=a(()=>W.find(e=>Zn.has(e.kind))??null,[W]),K=$n(It(G?G.url:void 0).src),ne=a(()=>Un(T?.positions??[],K,{snapshots:(T?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaId:e.mediaId}))}),[T?.positions,T?.snapshots,K]),q=e(e=>{let t=W.find(t=>t.mediaId===e);t&&I(t)},[W]);if(t===null)return null;let re=H.src,ie=te?.kind,ae=ie!==void 0&&Qn.has(ie)&&K!==null&&(T?.positions.length??0)>=2,oe=N&&N.length>0?N[0]:null,se=()=>{oe&&(R(!0),(async()=>{try{let e=await p.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:oe.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{h({title:`Clip unavailable`,message:`Could not resolve clip playback. Check the server logs.`,variant:`warning`})}finally{R(!1)}})())},ce=()=>{!i||v.isPending||(async()=>{if(await _({title:`Delete track`,message:`Delete this track and every image and clip captured for it? This cannot be undone.`,confirmLabel:`Delete`,variant:`danger`}))try{await v.mutateAsync({deviceId:t.deviceId,trackIds:[t.trackId]}),c()}catch{await h({title:`Delete failed`,message:`Failed to delete this track. Check the server logs.`,variant:`danger`})}})()},le=Math.round(t.importance*100),ue=T?.importanceReason?`${String(le)}% · ${T.importanceReason}`:`${String(le)}%`,de=T?.zonesVisited&&T.zonesVisited.length>0?T.zonesVisited.join(`, `):`—`,fe=T?.audioLabels&&T.audioLabels.length>0?T.audioLabels:t.audioLabels&&t.audioLabels.length>0?t.audioLabels:void 0,pe=fe===void 0?`—`:fe.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `),me=T?T.totalDistance.toFixed(2):`—`,he=hn(T?.previewMissReason),ge=Dt(T?T.firstSeen:C),_e=T?Dt(T.lastSeen):`—`;return u(pt,{open:!0,onOpenChange:e=>!e&&o(),children:r(O,{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,tn(t)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,tn(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(dt,{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:[re?u(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:u(Tt,{src:re,alt:`Key frame from ${n}`,fit:`natural`,className:`w-full`,overlay:ae?u(er,{overlay:ne,onPickSnapshot:q}):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:H.failed?r(s,{children:[u(g,{className:`h-8 w-8 opacity-60`}),u(`span`,{className:`text-[11px]`,children:`Key-frame media unavailable`})]}):u(P,{className:`h-6 w-6 animate-spin opacity-70`})}),W.length>0&&u(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:W.map(e=>{let t=wn(e.kind),n=Tn(Yn,e.url),i=z?Tn(z,e.url):null;return r(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[u(`button`,{type:`button`,onClick:()=>I(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${t} · ${Dt(e.timestamp)}`,children:u(Xn,{url:e.url,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:Dt(e.timestamp),children:xt(e.timestamp)})]}),u(xn,{localUrl:n,publicUrl:i})]},e.mediaId)})}),B,oe&&r(V,{variant:`secondary`,onClick:se,disabled:L,children:[L?u(P,{className:`h-3.5 w-3.5 animate-spin`}):u(xe,{className:`h-3.5 w-3.5`}),` `,`View clip`]}),u(In,{deviceId:t.deviceId,trackId:t.trackId,...(T?.markForTrain??t.markForTrain)===void 0?{}:{markForTrain:T?.markForTrain??t.markForTrain},...(T?.debug??t.debug)===void 0?{}:{debug:T?.debug??t.debug},...(T?.favourited??t.favourited)===void 0?{}:{favourited:T?.favourited??t.favourited},onChange:f}),he!==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:he.sentence}),u(`code`,{className:`mt-1 block break-all font-mono text-[10px] text-foreground-subtle`,children:he.raw})]}),r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[u(X,{label:`Camera`,value:n}),u(X,{label:`Class`,value:t.className}),u(X,{label:`Label`,value:t.label??`—`}),u(X,{label:`Sub-label`,value:t.subLabel??`—`}),u(X,{label:`Importance`,value:ue}),u(X,{label:`Zones visited`,value:de}),u(X,{label:`Audio heard`,value:pe}),u(X,{label:`Total distance`,value:me}),u(X,{label:`First seen`,value:ge}),u(X,{label:`Last seen`,value:_e}),u(X,{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:Gn,children:r(V,{variant:`secondary`,onClick:ce,disabled:!i||v.isPending,children:[v.isPending?u(P,{className:`h-3.5 w-3.5 animate-spin`}):u(y,{className:`h-3.5 w-3.5`}),` `,`Delete track`]})})})]})})}var nr={status:`debug.tape.status`,promote:`debug.tape.promote`,list:`debug.tape.list`,tracks:`debug.tape.tracks`,review:`debug.tape.review`,release:`debug.tape.release`,remove:`debug.tape.delete`},rr={setRelation:`debug.gt.setRelation`,setPurity:`debug.gt.setPurity`,list:`debug.gt.list`},ir=p(`/addon/pipeline-analytics/tape-export`),ar=10*6e4;function or(e){return`${ir}?tapeId=${encodeURIComponent(e)}`}var sr=`The server answered in a shape this build does not understand.`;function cr(e){return e instanceof Error?e.message:`The action failed.`}function Z(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Q(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function lr(e,t){if(!(t in e))return;let n=e[t];return n===null?null:typeof n==`number`&&Number.isFinite(n)?n:void 0}function $(e,t){let n=e[t];return typeof n==`string`?n:null}function ur(e,t){let n=e[t];return typeof n==`boolean`?n:null}function dr(e,t){if(!Array.isArray(e))return null;let n=[];for(let r of e){let e=t(r);if(e===null)return null;n.push(e)}return n}function fr(e){return e===`off`||e===`recording`||e===`refused`||e===`failing`||e===`unknown`}function pr(e){if(!Z(e))return null;let t=Q(e,`deviceId`),n=e.state,r=Q(e,`gapsSinceArmed`),i=lr(e,`segmentsHeld`),a=lr(e,`bytesLastHour`),o=lr(e,`bytesHeld`);if(t===null||!fr(n)||r===null||i===void 0||a===void 0||o===void 0)return null;let s=$(e,`reason`),c=Q(e,`segmentOriginMs`),l=Q(e,`framesPerMin`),u=Q(e,`heldFromMs`),d=Q(e,`heldToMs`),f=$(e,`shelfError`);return{deviceId:t,state:n,gapsSinceArmed:r,segmentsHeld:i,bytesLastHour:a,bytesHeld:o,...s===null?{}:{reason:s},...c===null?{}:{segmentOriginMs:c},...l===null?{}:{framesPerMin:l},...u===null?{}:{heldFromMs:u},...d===null?{}:{heldToMs:d},...f===null?{}:{shelfError:f}}}function mr(e){return Z(e)?dr(e.cameras,pr):null}function hr(e){if(!Z(e))return null;let t=$(e,`id`),n=Q(e,`deviceId`),r=$(e,`scenario`),i=e.lighting,a=Q(e,`fromMs`),o=Q(e,`toMs`),s=e.state,c=Q(e,`frames`),l=Q(e,`gaps`),u=Q(e,`bytes`),d=ur(e,`reviewed`),f=ur(e,`released`),p=dr(e.tracks,e=>typeof e==`string`?e:null),m=Q(e,`tracksStillStored`);return t===null||n===null||r===null||i!==`day`&&i!==`ir`||a===null||o===null||s!==`complete`&&s!==`incomplete`||c===null||l===null||u===null||d===null||f===null||p===null||m===null?null:{id:t,deviceId:n,scenario:r,note:$(e,`note`),lighting:i,fromMs:a,toMs:o,state:s,frames:c,gaps:l,bytes:u,reviewed:d,released:f,tracks:p,tracksStillStored:m}}function gr(e){return Z(e)?dr(e.tapes,hr):null}function _r(e){if(!Z(e))return null;let t=$(e,`trackId`),n=Q(e,`firstT`),r=Q(e,`lastT`),i=Q(e,`boundFrames`),a=$(e,`cls`),o=ur(e,`stillStored`);return t===null||n===null||r===null||i===null||a===null||o===null?null:{trackId:t,firstT:n,lastT:r,boundFrames:i,cls:a,stillStored:o}}function vr(e){if(!Z(e))return null;let t=$(e,`tapeId`),n=Q(e,`deviceId`),r=Q(e,`fromMs`),i=Q(e,`toMs`),a=ur(e,`reviewed`),o=dr(e.lanes,_r);return t===null||n===null||r===null||i===null||a===null||o===null?null:{tapeId:t,deviceId:n,fromMs:r,toMs:i,reviewed:a,lanes:o}}function yr(e){if(!Z(e))return null;if(e.ok===!1){let t=$(e,`reason`),n=$(e,`detail`);return t===null||n===null?null:{ok:!1,reason:t,detail:n}}if(e.ok!==!0)return null;let t=$(e,`tapeId`),n=e.state,r=Q(e,`frames`),i=Q(e,`gaps`),a=Q(e,`pinnedTracks`),o=Q(e,`bytes`);return t===null||n!==`complete`&&n!==`incomplete`||r===null||i===null||a===null||o===null?null:{ok:!0,tapeId:t,state:n,frames:r,gaps:i,pinnedTracks:a,bytes:o}}function br(e){if(!Z(e))return null;let t=e.status;if(t===`released`){let n=Q(e,`unpinned`),r=ur(e,`pinsSettled`);return n===null||r===null?null:{status:t,unpinned:n,pinsSettled:r}}if(t===`already-released`||t===`not-found`)return{status:t};if(t===`unavailable`){let n=$(e,`reason`);return n===null?null:{status:t,reason:n}}return null}function xr(e){if(!Z(e))return null;let t=e.status;if(t===`deleted`||t===`pins-owed`||t===`not-found`)return{status:t};if(t===`unavailable`){let n=$(e,`reason`);return n===null?null:{status:t,reason:n}}return null}function Sr(e){switch(e.status){case`released`:case`deleted`:return null;case`already-released`:return`This tape was already released.`;case`not-found`:return`That tape no longer exists — it may have been released or deleted elsewhere.`;case`pins-owed`:return`Refused: this tape still names pins not yet taken back. Try again shortly — the ledger settles them automatically.`;case`unavailable`:return`Unavailable on this node: ${e.reason}`}}function Cr(e){if(!Z(e))return null;let t=$(e,`leftTrackId`),n=$(e,`rightTrackId`),r=e.relation,i=e.presence;return t===null||n===null||r!==`same-subject`&&r!==`different-subjects`?null:{leftTrackId:t,rightTrackId:n,relation:r,presence:i===`continuous`?`continuous`:null}}function wr(e){if(!Z(e))return null;let t=$(e,`sourceTrackId`),n=e.purity;return t===null||n!==`mixed`&&n!==`not-a-subject`?null:{sourceTrackId:t,purity:n,switchAtMs:Q(e,`switchAtMs`)}}function Tr(e){if(!Z(e))return null;let t=dr(e.relations,Cr),n=dr(e.purities,wr),r=ur(e,`truncated`);return t===null||n===null||r===null?null:{relations:t,purities:n,truncated:r}}function Er(e){if(!e.truncated)return null;let t=e.relations.length+e.purities.length;return`Showing the first ${String(t)} marks — more exist for this window.`}function Dr(e){return e.filter(e=>e.segmentsHeld===null||e.segmentsHeld>0).map(e=>({deviceId:e.deviceId,segmentsUnknown:e.segmentsHeld===null}))}function Or(e){return e.slice(1).map((t,n)=>({trackId:e[n]??t,otherTrackId:t}))}function kr(e){return e.flatMap((t,n)=>e.slice(n+1).map(e=>({trackId:t,otherTrackId:e})))}function Ar(e,t){let n=[];for(let r of t.relations){let t=r.leftTrackId===e?r.rightTrackId:r.rightTrackId===e?r.leftTrackId:null;if(t===null)continue;let i=r.relation===`same-subject`?`same as`:`different from`;n.push(`${i} ${t}${r.presence===`continuous`?` (continuous)`:``}`)}for(let r of t.purities)r.sourceTrackId===e&&n.push(r.purity===`not-a-subject`?`not a subject`:r.switchAtMs===null?`mixed`:`mixed at switch`);return n}function jr(e){switch(e.state){case`off`:return`Off`;case`recording`:return`Recording`;case`refused`:return`Refused: ${e.reason??`unknown reason`}`;case`failing`:return`Failing: ${e.reason??`unknown reason`}`;case`unknown`:return`Unknown: ${e.reason??`unknown reason`}`}}var Mr={"window-too-long":`A promoted window is at most 30 minutes.`,"window-in-future":`The window ends in the future.`,"window-not-recorded":`No segment covers that window — the camera was not recording then, or it is older than 24 h.`,"invalid-scenario":`The scenario must be a slug: lowercase letters, digits and dashes, 3–64 characters.`,"promotion-budget":`A promotion budget is full (60 tapes, 1 GiB, 3 000 pinned tracks). Release or delete a tape already committed as a case first.`,"empty-window":`No frame was recorded in that window.`,"shelf-unreadable":`The camera's recorded segments could not be listed, so the window cannot be proven whole.`,"not-post-processing-node":`This node does not post-process frames, so it records no tracking tapes.`,"artifacts-elsewhere":`The artifacts storage location is on another node; tapes are recorded only where it lives.`,"tapes-not-started":`The tape recorder has not started on this node (or failed to).`};function Nr(e,t){let n=Mr[e]??`Refused (${e}).`;return t.length>0?`${n} ${t}`:n}function Pr(e){if(e.length===0)return null;let t=new Date(e).getTime();return Number.isFinite(t)?t:null}function Fr(e){return e<1024*1024?`${(e/1024).toFixed(0)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function Ir(e){return e===null?`unknown`:Fr(e)}function Lr(e){return e===null?`unknown`:String(e)}function Rr(e,t){let n=t.trim();return e===404?`This tape no longer exists on this node (unknown tape).`:e===503?n.length>0?n:`Tapes are unavailable on this node.`:e===500?n.length>0?n:`The export could not be read (the tape may have just been released or deleted).`:`Download failed (${String(e)}).`}n();function zr({cameras:e,call:t,onPromoted:n}){let[i,a]=l(``),[o,s]=l(``),[c,d]=l(``),[f,p]=l(``),[m,h]=l(``),[g,_]=l(`auto`),[v,y]=l(!1),[b,x]=l(null),S=async()=>{let r=Number.parseInt(i===``?e[0]?.value??``:i,10),a=Pr(o),s=Pr(c);if(!Number.isFinite(r)||a===null||s===null){x(`Pick a camera and both ends of the window.`);return}y(!0),x(null);try{let e=yr(await t(nr.promote,{deviceId:r,fromMs:a,toMs:s,scenario:f,...m.trim().length>0?{note:m.trim()}:{},...g===`day`||g===`ir`?{lighting:g}:{}}));e===null?x(sr):e.ok?(x(`Promoted ${e.tapeId}: ${String(e.frames)} frames, ${Fr(e.bytes)}, ${String(e.pinnedTracks)} tracks pinned`+(e.state===`incomplete`?` — incomplete (it has gaps) and cannot become a case.`:`.`)),n()):x(Nr(e.reason,e.detail))}catch(e){x(cr(e))}finally{y(!1)}};return r(`div`,{className:`flex flex-wrap items-end gap-2 rounded-md border border-border px-3 py-2`,children:[u(`div`,{className:`w-40`,children:u(F,{value:i,options:[...e],onChange:e=>a(e.target.value),"aria-label":`Camera`})}),u(J,{type:`datetime-local`,"aria-label":`From`,value:o,onChange:e=>s(e.target.value),className:`w-48`}),u(J,{type:`datetime-local`,"aria-label":`To`,value:c,onChange:e=>d(e.target.value),className:`w-48`}),u(J,{"aria-label":`Scenario`,placeholder:`615-door-groups`,value:f,onChange:e=>p(e.target.value),className:`w-44`}),u(J,{"aria-label":`Note`,placeholder:`optional note`,value:m,onChange:e=>h(e.target.value),className:`w-52`}),u(`div`,{className:`w-28`,children:u(F,{value:g,"aria-label":`Lighting`,options:[{value:`auto`,label:`Lighting: auto`},{value:`day`,label:`day`},{value:`ir`,label:`ir`}],onChange:e=>_(e.target.value)})}),r(V,{onClick:()=>void S(),disabled:v||e.length===0,children:[v?u(P,{className:`h-3.5 w-3.5 animate-spin`}):null,` Promote window`]}),u(`p`,{className:`w-full text-xs text-foreground-subtle`,children:`A promoted tape may be shared as a test case — keep the scenario slug and note free of names or other personal data.`}),b!==null&&u(`p`,{className:`w-full text-xs text-foreground`,children:b})]})}var Br=`pipeline-analytics`,Vr=`debug.listTracks`,Hr=`debug.analyze`,Ur=p(`/addon/pipeline-analytics/debug-export`);function Wr(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Gr(e,t){let n=e[t];return typeof n==`string`?n:null}function Kr(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function qr(e,t){let n=e[t];return typeof n==`boolean`?n:null}function Jr(e){return e===`error`||e===`warn`||e===`info`}function Yr(e){if(!Wr(e))return null;let t=Gr(e,`code`),n=Gr(e,`detail`),r=e.severity;return t===null||n===null||!Jr(r)?null:{code:t,severity:r,detail:n}}function Xr(e){if(!Wr(e))return null;let t=Gr(e,`trackId`),n=Kr(e,`deviceId`),r=Gr(e,`className`),i=Kr(e,`firstSeen`),a=Kr(e,`lastSeen`),o=Kr(e,`durationMs`),s=qr(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=Gr(e,`label`),l=Gr(e,`subLabel`),u=Gr(e,`previewMissReason`),d=qr(e,`markForTrain`),f=qr(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:Kr(e,`importance`)??0,bestEventId:Gr(e,`bestEventId`)??``,...d===null?{}:{markForTrain:d},...f===null?{}:{favourited:f},debug:!0,...u===null||u.length===0?{}:{previewMissReason:u}}}function Zr(e){let t=Xr(e);if(t===null||!Wr(e))return null;let n=Kr(e,`mediaCount`),r=Kr(e,`eventCount`),i=Kr(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=Yr(e);t!==null&&c.push(t)}let l=e.thumbnailProvenance;return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c,...dn(l)?{thumbnailProvenance:l}:{}}}function Qr(e){if(!Wr(e))return null;let t=qr(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=Xr(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function $r(e){if(!Wr(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=Zr(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var ei={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`,UNSCORED_LABEL:`unscored label`,BEST_SHOT_STANDIN:`stand-in best shot`,BEST_SHOT_RASTER:`low-res best shot`};function ti(e){return ei[e]??e}var ni={error:0,warn:1,info:2};function ri(e){return e.toSorted((e,t)=>ni[e.severity]-ni[t.severity]||e.code.localeCompare(t.code))}function ii(e){return e.length===0?Ur:`${Ur}?deviceIds=${e.join(`,`)}`}function ai(e){if(e<1e4)return`${(e/1e3).toFixed(1)}s`;let t=Math.round(e/1e3);if(t<60)return`${String(t)}s`;let n=Math.floor(t/60);return`${String(n)}m ${String(t%60).padStart(2,`0`)}s`}function oi(e,t){return`${String(e)}:${t}`}function si(e,t){let n=[],r=new Set;for(let i of e){let e=oi(i.deviceId,i.trackId);!t.has(e)||r.has(e)||(r.add(e),n.push({deviceId:i.deviceId,trackId:i.trackId}))}return n}n();function ci({tapeId:e,call:t,onClose:n,onChanged:i}){let a=o({queryKey:[`events-debug`,`tapes`,`tracks`,e],queryFn:async()=>vr(await t(nr.tracks,{tapeId:e}))}),s=a.data??null,c=o({queryKey:[`events-debug`,`tapes`,`marks`,e],enabled:s!==null,queryFn:async()=>s===null?null:Tr(await t(rr.list,{deviceId:s.deviceId,since:s.fromMs-ar,until:s.toMs+ar,limit:5e3}))}),[d,f]=l([]),[p,m]=l(``),[h,g]=l(null),_=e=>f(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),v=async e=>{g(null);try{for(let[n,r]of e)await t(n,r);f([]),await c.refetch(),i()}catch(e){g(cr(e))}};if(s===null)return a.isLoading?u(`p`,{className:`text-xs`,children:`Loading the tape…`}):u(q,{message:sr});let y=s.deviceId,b=(e,t)=>v(e.map(e=>[rr.setRelation,{deviceId:y,...e,relation:t}])),x=e=>{let t=Number.parseFloat(p),n=e===`mixed`&&Number.isFinite(t)?s.fromMs+t*1e3:void 0;return v(d.map(t=>[rr.setPurity,{deviceId:y,trackId:t,purity:e,...n===void 0?{}:{switchAtMs:Math.round(n)}}]))},S=c.data==null?null:Er(c.data);return r(`div`,{className:`space-y-2 rounded-md border border-primary/40 px-3 py-2`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[r(`span`,{className:`text-xs font-medium`,children:[s.tapeId,` — `,String(s.lanes.length),` tracks`]}),u(V,{disabled:d.length<2,onClick:()=>void b(Or(d),`same-subject`),children:`Same subject`}),u(V,{variant:`secondary`,disabled:d.length<2,onClick:()=>void b(kr(d),`different-subjects`),children:`Different subjects`}),u(J,{"aria-label":`Changed at (s from tape start)`,placeholder:`changed at s`,value:p,onChange:e=>m(e.target.value),className:`w-28`}),u(V,{variant:`secondary`,disabled:d.length!==1,onClick:()=>void x(`mixed`),children:`Mixed`}),u(V,{variant:`secondary`,disabled:d.length===0,onClick:()=>void x(`not-a-subject`),children:`Not a subject`}),u(V,{variant:s.reviewed?`secondary`:`primary`,onClick:()=>void v([[nr.review,{tapeId:s.tapeId,reviewed:!s.reviewed}]]).then(()=>a.refetch()),children:s.reviewed?`Mark not reviewed`:`Mark reviewed`}),u(V,{variant:`ghost`,onClick:n,children:`Close`})]}),h!==null&&u(q,{message:h}),S!==null&&u(q,{variant:`warning`,message:S}),u(`ul`,{className:`space-y-1`,children:s.lanes.toSorted((e,t)=>e.firstT-t.firstT).map(e=>u(li,{lane:e,marks:c.data===null||c.data===void 0?[]:Ar(e.trackId,c.data),selected:d.includes(e.trackId),onToggle:()=>_(e.trackId)},e.trackId))})]})}function li({lane:e,marks:t,selected:n,onToggle:i}){let{src:a}=It(e.stillStored?Lt(`track`,e.trackId):void 0);return r(`li`,{className:`flex items-center gap-2 text-xs`,children:[u(`input`,{type:`checkbox`,"aria-label":`select ${e.trackId}`,checked:n,onChange:i}),a===null?u(`div`,{className:`h-10 w-10 rounded bg-surface-hover`}):u(`img`,{src:a,alt:e.trackId,className:`h-10 w-10 rounded object-cover`}),u(`span`,{className:`font-mono`,children:e.trackId}),u(`span`,{children:e.cls}),r(`span`,{className:`text-foreground-subtle`,children:[ai(e.firstT),` → `,ai(e.lastT),` · `,String(e.boundFrames),` `,`frames`]}),!e.stillStored&&u(`span`,{className:`text-foreground-subtle`,children:`not stored — marked through the tape`}),t.map(e=>u(Y,{variant:`info`,children:e},e))]})}n();var ui=`camstack_admin_token`;function di(){let e=m();return(t,n)=>e.trpcClient.addons.custom.mutate({addonId:Br,action:t,input:n})}async function fi(e,t){let n=localStorage.getItem(ui),r={};n!==null&&(r.Authorization=`Bearer ${n}`);let i=await fetch(or(e),{headers:r});if(!i.ok){let e=await i.text().catch(()=>``);throw Error(Rr(i.status,e))}let a=await i.blob(),o=i.headers.get(`content-disposition`),s=(o===null?null:/filename="?([^";]+)"?/i.exec(o))?.[1]?.trim()??t,c=URL.createObjectURL(a),l=document.createElement(`a`);l.href=c,l.download=s,l.click(),setTimeout(()=>URL.revokeObjectURL(c),6e4)}function pi(){let[e,t]=l(!1);return u(Ke,{expanded:e,onExpandedChange:t,header:u(`span`,{className:`text-sm font-medium text-foreground`,children:`Tracking tapes`}),children:u(mi,{})})}function mi(){let e=di(),t=nt({isCamera:!0,projection:`slim`}),n=a(()=>{let e=new Map;for(let n of t.data??[])e.set(n.id,n.name);return t=>e.get(t)??`Camera ${String(t)}`},[t.data]),i=o({queryKey:[`events-debug`,`tapes`,`status`],queryFn:async()=>mr(await e(nr.status,{}))}),s=o({queryKey:[`events-debug`,`tapes`,`list`],queryFn:async()=>gr(await e(nr.list,{}))}),[c,d]=l(null),[f,p]=l(null),m=async e=>{p(null);try{await fi(e.id,`${e.scenario}.tape-bundle.json.gz`)}catch(e){p(cr(e))}},h=async t=>{let n=br(await e(nr.release,{tapeId:t.id}));if(n===null)throw Error(sr);let r=Sr(n);if(r!==null)throw Error(r);await s.refetch()},g=async t=>{let n=xr(await e(nr.remove,{tapeId:t.id}));if(n===null)throw Error(sr);let r=Sr(n);if(r!==null)throw Error(r);await s.refetch()};return r(`div`,{className:`space-y-3`,children:[r(`p`,{className:`text-xs text-foreground-subtle`,children:[`A camera records while its `,u(`strong`,{children:`Record the track history`}),` switch (camera settings → Tracking) is on; segments are kept 24 h. Promote a window worth keeping, label it in the review, mark it reviewed, download it and turn it into a test case with`,` `,u(`code`,{children:`npm run tracking-bench -- case`}),`.`]}),f!==null&&u(q,{message:f}),i.isLoading&&u(`p`,{className:`text-xs text-foreground-subtle`,children:`Loading camera status…`}),i.data===null&&u(q,{message:`The server answered in a shape this build does not understand.`}),r(`table`,{className:`w-full text-xs`,children:[u(`thead`,{children:r(`tr`,{className:`text-left text-foreground-subtle`,children:[u(`th`,{children:`Camera`}),u(`th`,{children:`State`}),u(`th`,{children:`Frames/min`}),u(`th`,{children:`Last hour`}),u(`th`,{children:`Held`}),u(`th`,{children:`Gaps`})]})}),u(`tbody`,{children:(i.data??[]).map(e=>r(`tr`,{children:[u(`td`,{children:n(e.deviceId)}),u(`td`,{children:u(Y,{variant:e.state===`recording`?`success`:e.state===`off`?`default`:e.state===`unknown`?`warning`:`danger`,children:jr(e)})}),u(`td`,{children:e.framesPerMin===void 0?`—`:String(Math.round(e.framesPerMin))}),u(`td`,{title:e.shelfError,children:Ir(e.bytesLastHour)}),r(`td`,{title:e.shelfError,children:[Lr(e.segmentsHeld),` seg · `,Ir(e.bytesHeld)]}),u(`td`,{children:String(e.gapsSinceArmed)})]},e.deviceId))})]}),u(zr,{cameras:Dr(i.data??[]).map(e=>({value:String(e.deviceId),label:e.segmentsUnknown?`${n(e.deviceId)} (segments unknown)`:n(e.deviceId)})),call:e,onPromoted:()=>void s.refetch()}),s.isLoading&&u(`p`,{className:`text-xs text-foreground-subtle`,children:`Loading promoted tapes…`}),s.data===null&&u(q,{message:`The server answered in a shape this build does not understand.`}),r(`table`,{className:`w-full text-xs`,children:[u(`thead`,{children:r(`tr`,{className:`text-left text-foreground-subtle`,children:[u(`th`,{children:`Scenario`}),u(`th`,{children:`Camera`}),u(`th`,{children:`Window`}),u(`th`,{children:`State`}),u(`th`,{children:`Tracks`}),u(`th`,{})]})}),u(`tbody`,{children:(s.data??[]).map(e=>r(`tr`,{children:[u(`td`,{children:e.scenario}),u(`td`,{children:n(e.deviceId)}),r(`td`,{children:[new Date(e.fromMs).toLocaleString(),` · `,ai(e.toMs-e.fromMs),` `,`· `,e.lighting]}),r(`td`,{children:[u(Y,{variant:e.state===`complete`?`success`:`warning`,children:e.state}),` `,e.reviewed&&u(Y,{variant:`info`,children:`reviewed`}),` `,e.released&&u(Y,{children:`released`})]}),r(`td`,{children:[String(e.tracksStillStored),`/`,String(e.tracks.length),` stored`]}),r(`td`,{className:`space-x-1 text-right`,children:[u(V,{variant:`secondary`,"aria-label":`Review ${e.scenario}`,onClick:()=>d(e.id),children:`Review`}),u(V,{variant:`ghost`,"aria-label":`Download ${e.scenario}`,onClick:()=>void m(e),children:u(ze,{className:`h-3.5 w-3.5`})}),u(j,{label:`Release`,icon:oe,title:`Release ${e.scenario}?`,description:`Releasing returns this tape's pinned tracks to ordinary retention — they can be pruned from then on. The promoted bundle itself is kept until deleted.`,confirmLabel:`Release`,triggerVariant:`ghost`,confirmVariant:`danger`,disabled:e.released,action:()=>h(e)}),u(j,{label:`Delete`,icon:y,title:`Delete ${e.scenario}?`,description:`Deleting removes the promoted bundle and its index row for good. Its tracks' pins are released first — this cannot be undone.`,confirmLabel:`Delete`,triggerVariant:`ghost`,confirmVariant:`danger`,action:()=>g(e)})]})]},e.id))})]}),c!==null&&u(ci,{tapeId:c,call:e,onClose:()=>d(null),onChanged:()=>void s.refetch()})]})}n();var hi=`all`,gi=`The server answered in a shape this build does not understand.`,_i={error:`danger`,warn:`warning`,info:`info`};function vi({findings:e}){return e.length===0?u(Y,{variant:`success`,children:`no anomaly found`}):u(`div`,{className:`flex flex-wrap gap-1`,children:ri(e).map(e=>u(Y,{variant:_i[e.severity],title:e.detail,children:ti(e.code)},e.code))})}function yi({track:e,report:t,analyzing:n}){let i=hn(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(vi,{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 bi(){let e=m(),[t,n]=l(hi),[i,s]=l(!1),[c,d]=l(null),[f,p]=l(new Set),[h,g]=l(null),[_,v]=l(null),[y,b]=l(null),[x,S]=l([]),C=Nn(),T=nt({isCamera:!0,projection:`slim`}),E=a(()=>[{value:hi,label:`All cameras`},...(T.data??[]).map(e=>({value:String(e.id),label:e.name}))],[T.data]),D=a(()=>{let e=new Map;for(let t of T.data??[])e.set(t.id,t.name);return e},[T.data]),O=e=>D.get(e)??`Camera ${String(e)}`,k=a(()=>t===hi?[]:[Number.parseInt(t,10)],[t]),A=o({queryKey:[`events-debug`,`list`,k],queryFn:async()=>Qr(await e.trpcClient.addons.custom.mutate({addonId:Br,action:Vr,input:k.length===0?{}:{deviceIds:k}}))}),j=a(()=>(A.data?.tracks??[]).map(e=>e.trackId),[A.data]),M=o({queryKey:[`events-debug`,`analyze`,j],enabled:j.length>0,queryFn:async()=>$r(await e.trpcClient.addons.custom.mutate({addonId:Br,action:Hr,input:{trackIds:j}}))}),N=a(()=>{let e=new Map;for(let t of M.data?.reports??[])e.set(t.trackId,t);return e},[M.data]),I=A.data?.tracks??[],L=A.data===null||M.data===null,R=()=>{A.refetch(),M.refetch()},z=e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},B=()=>{p(new Set(I.map(e=>oi(e.deviceId,e.trackId))))},ee=()=>p(new Set),te=async(e,t)=>{let n=e===`analyzed`?{debug:!1}:{favourited:!0},r=0,i=[];for(let e of t)try{await C.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,flags:n}),r+=1}catch{i.push(e.trackId)}return{applied:r,refused:i}},H=e=>{if(!An||_!==null)return;let t=si(I,f);t.length!==0&&(v(e),b(null),(async()=>{let n=await te(e,t);v(null);let r=new Set(n.refused);p(new Set(t.filter(e=>r.has(e.trackId)).map(e=>oi(e.deviceId,e.trackId)))),e===`analyzed`&&S(t.filter(e=>!r.has(e.trackId))),n.refused.length>0&&b(`${String(n.refused.length)} of ${String(t.length)} were refused by the server and are still selected. Check the hub log.`),A.refetch()})())},U=()=>{let e=x;e.length===0||_!==null||(v(`analyzed`),b(null),(async()=>{for(let t of e)try{await C.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,flags:{debug:!0}})}catch{b(`Some tracks could not be re-marked. Refresh and try again.`)}v(null),S([]),A.refetch()})())},W=async()=>{s(!0),d(null);try{await zt(ii(k),`camstack-debug.zip`)}catch(e){d(e instanceof Error?e.message:`Export failed.`)}finally{s(!1)}},G=_!==null;return u(Ft,{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(F,{value:t,options:E,onChange:e=>n(e.target.value)})}),r(V,{variant:`secondary`,onClick:R,disabled:A.isFetching,children:[A.isFetching?u(P,{className:`h-3.5 w-3.5 animate-spin`}):u(Re,{className:`h-3.5 w-3.5`}),`Refresh`]}),r(V,{onClick:()=>void W(),disabled:i||I.length===0,children:[i?u(P,{className:`h-3.5 w-3.5 animate-spin`}):u(ze,{className:`h-3.5 w-3.5`}),`Export all (`,String(I.length),`)`]}),I.length>0&&f.size<I.length&&u(V,{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.`]}),u(pi,{}),A.isError&&u(q,{message:`Could not load the marked tracks.`}),L&&!A.isError&&u(q,{message:gi}),c!==null&&u(q,{message:c}),y!==null&&u(q,{message:y}),A.data?.truncated===!0&&u(q,{message:`A camera filled the per-camera cap — some marked tracks are not listed. Un-mark a few, or filter to one camera.`}),(M.data?.vanished.length??0)>0&&r(`p`,{className:`text-xs text-foreground-subtle`,children:[String(M.data?.vanished.length),` marked track(s) were evicted between the list and the analysis.`]}),f.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(f.size),` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[u(`span`,{title:An?void 0:`Track flags arrive with the next server update`,children:r(V,{variant:`secondary`,onClick:()=>H(`keep`),disabled:!An||G,children:[_===`keep`?u(P,{className:`h-3.5 w-3.5 animate-spin`}):u($e,{className:`h-3.5 w-3.5`}),` `,`Keep`]})}),u(`span`,{title:An?void 0:`Track flags arrive with the next server update`,children:r(V,{onClick:()=>H(`analyzed`),disabled:!An||G,children:[_===`analyzed`?u(P,{className:`h-3.5 w-3.5 animate-spin`}):u(ft,{className:`h-3.5 w-3.5`}),` `,`Analyzed`]})}),u(V,{variant:`ghost`,onClick:ee,disabled:G,children:u(dt,{className:`h-3.5 w-3.5`})})]})]}),x.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(x.length),` track(s) marked analyzed and removed from this list.`]}),r(V,{variant:`ghost`,onClick:U,disabled:G,children:[u(K,{className:`h-3.5 w-3.5`}),` Undo`]}),u(V,{variant:`ghost`,onClick:()=>S([]),disabled:G,children:u(dt,{className:`h-3.5 w-3.5`})})]}),A.isLoading?u(w,{children:u(`div`,{className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`Loading…`})}):I.length===0?u(w,{children:r(`div`,{className:`flex flex-col items-center gap-2 px-3 py-8 text-center`,children:[u(st,{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:I.map(e=>{let t=N.get(e.trackId);return u(_n,{row:e,cameraName:O(e.deviceId),nowMs:e.lastSeen,selected:f.has(oi(e.deviceId,e.trackId)),onToggleSelect:z,onOpenDetail:g,...t?.thumbnailProvenance===void 0?{}:{provenance:t.thumbnailProvenance},footer:u(yi,{track:e,report:t,analyzing:M.isFetching})},oi(e.deviceId,e.trackId))})}),h&&u(tr,{row:h,cameraName:O(h.deviceId),deleteAvailable:Wn,onClose:()=>g(null),onDeleted:()=>{g(null),A.refetch()},onFlagsChanged:e=>{e.debug||(g(null),A.refetch())}})]})})}var xi=200,Si=3e4,Ci=[];function wi(e){let t=m(),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:Si,refetchInterval:Si,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEventsBatch.query({deviceIds:r,since:e.since,until:e.until,limit:xi,...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:an(rn(i??Ci),`importance`),isLoading:n&&a}}n();var Ti=[`events-feed`],Ei=2e3;function Di(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:Ti})},[]),p=t(void 0);p.current||=At({delayMs:Ei,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 vt(Mt.PipelineAnalyticsDetectionEvent,()=>{p.current?.trigger()}),vt(Mt.PipelineAnalyticsTrackEnded,()=>{p.current?.trigger()}),{pending:s,refreshNow:m}}n();function Oi({groups:e,selected:t,onChange:n,loading:i=!1}){let{t:o}=Nt(),[s,c]=l(!1),[d,f]=l(``),[p,m]=l(new Set),h=d.trim().toLowerCase(),g=e=>h.length===0||x(e,o).toLowerCase().includes(h),y=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]),b=e=>m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),S=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)},C=e=>{let r=new Set(t);r.has(e)?r.delete(e):r.add(e),n(r)},w=()=>n(new Set),T=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 ${T>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[u(ve,{className:`h-3.5 w-3.5`}),T>0?`Kinds (${String(T)})`:`Kinds`,u(_,{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`}),T>0&&u(`button`,{type:`button`,onClick:w,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),y.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.`}),y.map(e=>{let n=Ne(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:()=>b(e.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Expand`,children:u(i?_:v,{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:()=>S(e),className:`accent-primary`}),u(n,{className:`h-3.5 w-3.5`,style:{color:e.macro.color}}),u(`span`,{className:`font-medium`,children:x(e.macro,o)})]})]}),i&&e.subs.map(e=>{let n=Ne(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:()=>C(e.kind),className:`accent-primary`}),u(n,{className:`h-3.5 w-3.5`,style:{color:e.color}}),u(`span`,{children:x(e,o)})]},e.kind)})]},e.macro.kind)})]})]})}function ki(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 Ai(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var ji=new Set([`detection`,`package`]);function Mi(e,t){return[...ki(e,t).values()].filter(e=>e.parentKind===null&&ji.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function Ni(e,t){let n=ki(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,Ai(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 Pi(){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 Fi=[`events-feed`],Ii=60,Li=[{value:`importance`,label:`Importance`,icon:Ut},{value:`time`,label:`Recent`,icon:je}];function Ri(){let e=c(),t=U(),n=Ze(),[i,o]=l(kt),[f,p]=l(new Set),[m,h]=l(new Set),[g,_]=l(0),[v,b]=l(`time`),[x,S]=l(new Set),[C,w]=l(null),[T,E]=l(()=>Date.now());d(()=>{let e=setInterval(()=>E(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:D,until:O}=a(()=>ln({fromMs:i.fromMs,toMs:i.toMs},T),[i.fromMs,i.toMs,T]),k=Pi(),{pending:A,refreshNow:j}=Di({paused:C!==null||x.size>0||k.scrolledPast}),{data:M=[]}=nt({isCamera:!0,projection:`slim`}),N=a(()=>M.map(e=>e.id),[M]),{data:F,isLoading:I}=Ye({deviceIds:N},{enabled:N.length>0,staleTime:5*6e4}),L=a(()=>Ni(F??[],f),[F,f]),R=qn(),z=R.isPending,{rows:B,isLoading:ee}=wi({deviceIds:N,since:D,until:O,minImportance:g>0?g:void 0,classFilter:m.size===1?[...m][0]:void 0}),te=a(()=>{let e=new Map;for(let t of M??[])e.set(t.id,t.name);return e},[M]),H=e=>te.get(e)??`Camera #${String(e)}`,W=a(()=>bt(B).map(e=>({id:e,name:H(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[B,te]),G=a(()=>an(on(B,{cameras:f,classes:m,minImportance:g}),v),[B,f,m,g,v]),K=Et(G,Ii,a(()=>JSON.stringify([[...f].sort((e,t)=>e-t),[...m].sort(),g,v,D,O]),[f,m,g,v,D,O])),ne=()=>{e.invalidateQueries({queryKey:Fi})},q=()=>S(new Set);function re(e){S(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function ie(){if(x.size===0||!Wn)return;let e=cn(B,x),t=[...e.values()].reduce((e,t)=>e+t.length,0);t!==0&&(async()=>{await n({title:`Delete ${String(t)} track${t===1?``:`s`}`,message:`Delete ${String(t)} track${t===1?``:`s`} and every image and clip captured for ${t===1?`it`:`them`}? This cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&ae(e)})()}function ae(e){let n=[...e];Promise.allSettled(n.map(([e,t])=>R.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{ne();let r=[],i=new Set;e.forEach((e,t)=>{let a=n[t];if(!a)return;let[o,s]=a;if(e.status===`fulfilled`)for(let e of s)i.add(sn(o,e));else r.push(o)}),S(e=>{let t=new Set(e);for(let e of i)t.delete(e);return t}),r.length>0&&t({title:`Some tracks were not deleted`,message:`Failed to delete tracks on: ${r.map(e=>H(e)).join(`, `)}. They remain selected — retry, or check the server logs.`,variant:`danger`})})}let oe=G.length!==B.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[u(Ot,{onChange:o}),u(Ct,{cameras:W,selected:f,onChange:p}),u(Oi,{groups:L,selected:m,onChange:h,loading:I}),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:g,onChange:e=>_(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(g*100)})]}),u(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Li.map(e=>{let t=e.icon;return r(`button`,{type:`button`,onClick:()=>b(e.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${v===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)})}),!ee&&u(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:oe?`${String(G.length)} of ${String(B.length)} events`:`${String(G.length)} event${G.length===1?``:`s`}`})]}),x.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:[x.size,` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[u(`span`,{title:Wn?void 0:`Track deletion arrives with the next server update`,children:r(V,{variant:`secondary`,onClick:ie,disabled:!Wn||z,children:[z?u(P,{className:`h-3.5 w-3.5 animate-spin`}):u(y,{className:`h-3.5 w-3.5`}),` `,`Delete`]})}),u(V,{variant:`ghost`,onClick:q,disabled:z,children:u(dt,{className:`h-3.5 w-3.5`})})]})]}),ee&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[u(P,{className:`h-4 w-4 animate-spin`}),` Loading events…`]}),!ee&&G.length===0&&u(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No key events in this window.`}),A&&u(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:u(`button`,{type:`button`,onClick:j,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`})}),!ee&&G.length>0&&r(s,{children:[u(`div`,{ref:k.ref,"aria-hidden":!0,className:`h-0`}),u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:K.pageItems.map(e=>u(_n,{row:e,cameraName:H(e.deviceId),nowMs:T,selected:x.has(sn(e.deviceId,e.trackId)),onToggleSelect:re,onOpenDetail:w},sn(e.deviceId,e.trackId)))}),u(yt,{currentPage:K.page,totalItems:K.totalItems,pageSize:K.pageSize,onPageChange:K.setPage,itemNoun:`events`})]}),C&&u(tr,{row:C,cameraName:H(C.deviceId),deleteAvailable:Wn,onClose:()=>w(null),onDeleted:()=>{ne(),w(null)},onFlagsChanged:e=>{w(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug,favourited:e.favourited}:t)}})]})}n();var zi=50,Bi=350,Vi=[{value:`loose`,label:`Loose`,title:`The search model's own floor`},{value:`balanced`,label:`Balanced`,title:`1.25× the search model's floor`},{value:`strict`,label:`Strict`,title:`1.5× the search model's floor`}];function Hi(e){let t=String(e.id);return{id:t,trackId:e.trackId??t,deviceId:e.deviceId,timestamp:e.timestamp,className:e.className,label:e.label,subLabel:e.subLabel,importance:e.importance??0,bestEventId:t,mediaId:e.keyFrameMediaId??e.mediaId,windowMs:void 0}}function Ui({onActiveChange:e}){let[t,n]=l(``),[i,o]=l(`loose`),[s,c]=l(null),[f,p]=l(null),[m,h]=l(null),g=Te(t,Bi).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=[]}=nt({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}=Ye({deviceIds:w},{enabled:w.length>0,staleTime:5*6e4}),E=a(()=>Mi(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}=Ve({text:g,strictness:i,limit:zi,classFilter:s??void 0,deviceId:f??void 0},{enabled:_}),j=a(()=>[...D??[]].sort((e,t)=>t.score-e.score).map(e=>({...Hi(e),score:e.score})),[D]);function M(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(dt,{className:`h-3.5 w-3.5`})})]}),O&&_&&u(P,{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:()=>M(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:x(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:Vi.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:e.title,children:e.label},e.value))})]}),_&&!O&&!k&&r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[j.length,` match`,j.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&&j.length===0&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[u(P,{className:`h-4 w-4 animate-spin`}),` Searching…`]}),!k&&!O&&j.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&&j.length>0&&u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:j.map(e=>u(_n,{row:e,cameraName:C(e.deviceId),nowMs:v,score:e.score,onOpenDetail:h},e.id))})]}),m&&u(tr,{row:m,cameraName:C(m.deviceId),deleteAvailable:Wn,onClose:()=>h(null),onDeleted:()=>h(null)})]})}n();function Wi(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 Gi({row:e,cameraName:t,nowMs:n}){let i=It(e.keyFrameMediaId===void 0?void 0:Rt(e.keyFrameMediaId));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:[i.src?u(`img`,{src:i.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($t,{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 `,Wi(n,e.becameStationaryAt)]})]})]})}function Ki(){let[e,t]=l(!1),n=Date.now(),{data:i=[]}=nt({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}=Bt(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?_:v,{className:`h-4 w-4 text-foreground-subtle`}),u($t,{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(Gi,{row:e,cameraName:s.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:n},e.id))})]})}n();function qi(){let[e,t]=l(!1);return u(Ft,{children:r(`section`,{className:`space-y-3`,children:[u(Ui,{onActiveChange:t}),!e&&u(Ki,{}),!e&&u(Ri,{})]})})}n();function Ji({frameId:e,onAdded:t}){let n=ce(),[i,a]=l(null),[o,s]=l(null),c=async()=>{if(i===null)return;let r=await n.mutateAsync({collectionId:i,frameIds:[e]});s(r.added>0?`Added.`:r.alreadyMember>0?`Already in that collection.`:`That frame or collection no longer exists.`),await t()};return r(_e,{children:[r(W,{className:`mt-1 flex items-center gap-1 text-foreground-muted hover:text-foreground`,"aria-label":`Add this frame to a collection`,children:[u(qt,{className:`h-3 w-3`}),`collection`]}),r(R,{className:`w-72 space-y-2 p-3`,children:[u(gt,{value:i,onChange:a}),r(`div`,{className:`flex items-center justify-between gap-2`,children:[u(`span`,{className:`text-[11px] text-foreground-subtle`,children:o}),u(V,{size:`sm`,disabled:i===null||n.isPending,onClick:()=>void c(),children:`Add`})]})]})]})}function Yi(e){let t=e.capturedAt??e.copiedAt;return new Date(t).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function Xi({frames:e,isLoading:t,activeFrameId:n,deviceNames:i,onOpen:a,onRemove:o}){return e.length===0?u(`p`,{className:`text-[11px] text-foreground-subtle`,children:t?`Reading the collection…`:`This collection is empty. Add frames with "Send frame to training" on a camera’s recording timeline, or "Add to collection" on a track’s copied frame.`}):u(`ul`,{className:`flex flex-wrap gap-2`,children:e.map(e=>u(`li`,{children:r(`div`,{className:`rounded-md border px-2 py-1.5 text-[11px] flex items-start gap-1.5 ${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:()=>{a(e.frameId)},children:[e.origin===`recording`?u(xe,{className:`h-3 w-3 text-info`,"aria-label":`From the recording`}):u(Yt,{className:`h-3 w-3 text-success`,"aria-label":`From a track`}),u(`span`,{className:`font-medium text-foreground`,children:i.get(e.deviceId)??`Camera ${String(e.deviceId)}`}),u(`span`,{className:`text-foreground-subtle`,children:Yi(e)}),e.complete&&u(Y,{variant:`success`,children:`complete`})]}),u(`button`,{type:`button`,"aria-label":`Remove from this collection`,title:e.origin===`recording`?`Remove from this collection. If no other collection holds it, the frame and its boxes leave the dataset.`:`Remove from this collection. The frame stays in the dataset with its track.`,className:`text-foreground-muted hover:text-danger`,onClick:()=>{o(e)},children:u(dt,{className:`h-3 w-3`})})]})},e.frameId))})}n();function Zi({collections:e,isLoading:t,selectedId:n,onSelect:i,onCreate:a,onRename:o,onDelete:c}){let[d,f]=l(``),[p,m]=l(null),[h,g]=l(null),_=async()=>{let e=await a(d);m(e),e===null&&f(``)},v=async()=>{if(h===null)return;let e=await o(h.id,h.name);m(e),e===null&&g(null)};return r(`div`,{className:`divide-y divide-border`,children:[r(`div`,{className:`p-2 space-y-1.5`,children:[r(`div`,{className:`flex items-center gap-1.5`,children:[u(J,{className:`flex-1`,"aria-label":`New collection name`,placeholder:`New collection`,value:d,onChange:e=>{f(e.target.value)}}),u(V,{size:`sm`,disabled:d.trim()===``,onClick:()=>void _(),children:`Create`})]}),p!==null&&u(`p`,{className:`text-[11px] text-danger`,children:p})]}),e.length===0?u(`p`,{className:`p-3 text-[11px] text-foreground-subtle`,children:t?`Reading the collections…`:`No collection yet. Create one here, or use "Send frame to training" on a camera’s recording timeline.`}):u(`ul`,{className:`divide-y divide-border`,children:e.map(e=>u(`li`,{className:`px-3 py-2 flex items-center gap-2 text-xs ${e.id===n?`bg-surface-hover`:``}`,children:h?.id===e.id?r(s,{children:[u(J,{className:`flex-1`,"aria-label":`Collection name`,value:h.name,onChange:t=>{g({id:e.id,name:t.target.value})}}),u(V,{variant:`ghost`,size:`sm`,"aria-label":`Save the name`,onClick:()=>void v(),children:u(ft,{className:`h-3 w-3`})}),u(V,{variant:`ghost`,size:`sm`,"aria-label":`Cancel renaming`,onClick:()=>{g(null)},children:u(dt,{className:`h-3 w-3`})})]}):r(s,{children:[u(`button`,{type:`button`,className:`flex-1 min-w-0 text-left truncate text-foreground`,onClick:()=>{i(e)},children:e.name}),u(Y,{children:e.frameCount}),u(V,{variant:`ghost`,size:`sm`,"aria-label":`Rename ${e.name}`,onClick:()=>{g({id:e.id,name:e.name})},children:u(D,{className:`h-3 w-3`})}),u(j,{label:`Delete`,icon:y,triggerVariant:`ghost`,size:`sm`,title:`Delete "${e.name}"?`,description:`Frames taken from the recording that are in no other collection are deleted with their boxes. Frames copied from tracks stay in the dataset.`,confirmLabel:`Delete`,confirmVariant:`danger`,action:()=>c(e.id)})]})},e.id))})]})}n();var Qi={"empty-name":`Give the version a name.`,"duplicate-name":`A version with that name already exists.`,"no-frames":`This selection holds no annotated or complete frame — nothing to freeze.`},$i=e=>`${String(Math.round(e*100))}%`;function ea(e,t){return e.includes(t)?e.filter(e=>e!==t):[...e,t]}function ta({on:e,label:t,onClick:n}){return u(`button`,{type:`button`,"aria-pressed":e,className:`rounded-full border px-2 py-0.5 text-[11px] ${e?`border-primary text-primary`:`border-border text-foreground-muted hover:text-foreground`}`,onClick:n,children:t})}function na({stats:e,deviceNames:t}){let n=e=>t.get(e)??`Camera ${String(e)}`;return r(`div`,{className:`space-y-2`,"data-testid":`retrain-dataset-stats`,children:[r(`div`,{className:`flex flex-wrap gap-1.5 text-[11px]`,children:[r(Y,{children:[e.frames,` frames`]}),r(Y,{variant:e.completeness>=.9?`success`:`warning`,children:[$i(e.completeness),` complete (`,e.completeFrames,`)`]}),r(Y,{children:[e.subjects,` boxes`]}),r(Y,{variant:`danger`,children:[e.modelErrors,` model errors`]}),r(Y,{variant:`info`,children:[e.hardNegatives,` hard negatives`]}),e.cameras.map(e=>r(Y,{children:[n(e.deviceId),`: `,e.frames,` ·`,` `,$i(e.frames>0?e.completeFrames/e.frames:0),` complete`]},e.deviceId))]}),u(ie,{columns:[{key:`class`,header:`Class`,render:e=>e.macroClass,sortValue:e=>e.macroClass},{key:`camera`,header:`Camera`,render:e=>n(e.deviceId),sortValue:e=>n(e.deviceId)},{key:`light`,header:`Light`,render:e=>e.lighting,sortValue:e=>e.lighting},{key:`subjects`,header:`Boxes`,align:`right`,render:e=>e.subjects,sortValue:e=>e.subjects},{key:`frames`,header:`Frames`,align:`right`,render:e=>e.frames,sortValue:e=>e.frames}],rows:e.cells,rowKey:e=>`${e.macroClass}-${String(e.deviceId)}-${e.lighting}`,emptyMessage:`No box in this selection.`,minWidthPx:360})]})}function ra({id:e}){let[t,n]=l(!1),i=I({id:e},{enabled:t});return t?i.data===void 0?u(P,{className:`h-3 w-3 animate-spin`}):i.data.matches?u(Y,{variant:`success`,children:`unchanged`}):r(Y,{variant:`warning`,children:[`changed`,i.data.missingFrames>0?` · ${String(i.data.missingFrames)} missing`:``]}):r(V,{variant:`ghost`,size:`sm`,onClick:()=>n(!0),children:[u(et,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Verify`})]})}function ia({deviceNames:e,collections:t,pickedFrameIds:n,onClearPicked:i}){let a=c(),o=m(),[s,d]=l([]),[f,h]=l([]),[g,_]=l(!1),[v,b]=l(!1),[x,S]=l(`frames`),[w,T]=l(``),[E,D]=l(null),[O,k]=l(null),A={...s.length>0?{deviceIds:[...s]}:{},...f.length>0?{collectionIds:[...f]}:{},...g&&n.length>0?{frameIds:[...n]}:{}},M=ut({selection:A,completeOnly:v}),N=De({}),I=it(),L=Be(),R=async()=>{D(null);let e=await I.mutateAsync({name:w,selection:A,layout:x,completeOnly:v});if(e.kind===`refused`){D(Qi[e.reason]??e.reason);return}T(``),D(`Version "${e.version.name}" frozen: ${String(e.version.frameCount)} frames.`),await N.refetch()},z=async e=>{k(e.id);try{let{url:t}=await o.trpcClient.pipelineAnalytics.getRetrainExportUrl.query({datasetVersionId:e.id,layout:e.layout});await zt(p(t),`camstack-dataset-${e.name.replace(/[^a-z0-9_-]+/gi,`-`)}.tar`)}catch(e){D(`Download failed: ${e instanceof Error?e.message:String(e)}`)}finally{k(null)}},B=[...e.keys()].toSorted((e,t)=>e-t);return r(`div`,{className:`space-y-3`,children:[r(`div`,{className:`rounded-md border border-border bg-surface p-3 space-y-2`,children:[u(`h2`,{className:`text-xs font-semibold text-foreground`,children:`New dataset version`}),r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[u(`span`,{className:`text-[11px] text-foreground-subtle w-20`,children:`Cameras`}),s.length===0&&u(Y,{children:`all`}),B.map(t=>u(ta,{on:s.includes(t),label:e.get(t)??String(t),onClick:()=>d(e=>ea(e,t))},t))]}),r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[u(`span`,{className:`text-[11px] text-foreground-subtle w-20`,children:`Collections`}),f.length===0&&u(Y,{children:`any frame`}),t.map(e=>u(ta,{on:f.includes(e.id),label:`${e.name} · ${String(e.frameCount)}`,onClick:()=>h(t=>ea(t,e.id))},e.id))]}),r(`div`,{className:`flex flex-wrap items-center gap-3 text-[11px]`,children:[r(`label`,{className:`flex items-center gap-1.5`,children:[u(C,{"aria-label":`Only the frames picked in the workbench`,checked:g,disabled:n.length===0,onChange:e=>_(e.target.checked)}),`Only the `,n.length,` picked frame`,n.length===1?``:`s`]}),n.length>0&&u(V,{variant:`ghost`,size:`sm`,onClick:i,children:`Clear picks`}),r(`label`,{className:`flex items-center gap-1.5`,children:[u(C,{"aria-label":`Only complete frames`,checked:v,onChange:e=>b(e.target.checked)}),`Only frames marked "all subjects boxed"`]}),u(F,{className:`w-36`,"aria-label":`Layout`,value:x,options:[{value:`frames`,label:`Frames (detector)`},{value:`crops`,label:`Frames + crops (classifier)`}],onChange:e=>S(e.target.value===`crops`?`crops`:`frames`)})]}),M.data===void 0?u(`p`,{className:`text-[11px] text-foreground-subtle`,children:M.isError?`The selection could not be counted.`:`Counting the selection…`}):u(na,{stats:M.data,deviceNames:e}),r(`div`,{className:`flex items-center gap-2`,children:[u(J,{className:`flex-1`,"aria-label":`Version name`,placeholder:`Version name (e.g. night person v1)`,value:w,onChange:e=>T(e.target.value)}),u(V,{size:`sm`,disabled:w.trim()===``||I.isPending||(M.data?.frames??0)===0,onClick:()=>void R(),children:`Freeze version`})]}),E!==null&&u(`p`,{className:`text-[11px] text-foreground`,children:E})]}),r(`div`,{className:`rounded-md border border-border bg-surface p-3 space-y-2`,children:[u(`h2`,{className:`text-xs font-semibold text-foreground`,children:`Versions`}),u(ie,{columns:[{key:`name`,header:`Version`,render:e=>e.name,sortValue:e=>e.name},{key:`created`,header:`Frozen`,render:e=>new Date(e.createdAt).toLocaleString(),sortValue:e=>e.createdAt},{key:`frames`,header:`Frames`,align:`right`,render:e=>e.frameCount,sortValue:e=>e.frameCount},{key:`boxes`,header:`Boxes`,align:`right`,render:e=>e.stats.subjects,sortValue:e=>e.stats.subjects},{key:`complete`,header:`Complete`,align:`right`,render:e=>$i(e.stats.completeness),sortValue:e=>e.stats.completeness},{key:`layout`,header:`Layout`,render:e=>e.layout},{key:`hash`,header:`Hash`,render:e=>u(`code`,{title:e.annotationHash,children:e.annotationHash.slice(0,10)})},{key:`actions`,header:``,render:e=>r(`div`,{className:`flex items-center gap-1 justify-end`,children:[u(ra,{id:e.id}),u(V,{variant:`ghost`,size:`sm`,"aria-label":`Download ${e.name}`,disabled:O!==null,onClick:()=>void z(e),children:O===e.id?u(P,{className:`h-3 w-3 animate-spin`}):u(ze,{className:`h-3 w-3`})}),u(j,{label:`Delete`,icon:y,triggerVariant:`ghost`,size:`sm`,title:`Delete version "${e.name}"?`,description:`The version's record goes. Its frames stay in the dataset.`,confirmLabel:`Delete`,action:async()=>{await L.mutateAsync({id:e.id}),await a.invalidateQueries()}})]})}],rows:N.data??[],rowKey:e=>e.id,emptyMessage:N.isLoading?`Reading the versions…`:`No version frozen yet.`,minWidthPx:640})]})]})}n();function aa(){let e=Me({}),t=_t({}),[n,i]=l([]),a=Ae(n.length>0?{collectionIds:[...n]}:{}),o=Fe({}),[s,c]=l(null),[d,f]=l(null),m=async(e,t,n)=>{c(e),f(null);try{await zt(p(t),n)}catch(e){f(e instanceof Error?e.message:String(e))}finally{c(null)}},h=e.data,g=h!==void 0&&h.trackCount===0;return r(`div`,{className:`rounded-md border border-border bg-surface p-3 space-y-2`,children:[r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u(`h2`,{className:`text-xs font-semibold text-foreground flex-1`,children:`Export dataset`}),r(V,{variant:`secondary`,size:`sm`,disabled:a.data===void 0||s!==null,onClick:()=>{a.data!==void 0&&m(`annotated`,a.data.url,`camstack-retrain-export.tar`)},children:[s===`annotated`?u(P,{className:`h-3 w-3 animate-spin`}):u(ze,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Annotated dataset`})]}),r(V,{variant:`secondary`,size:`sm`,disabled:o.data===void 0||g||s!==null,onClick:()=>{o.data!==void 0&&m(`marked`,o.data.url,`camstack-training-export.tar`)},children:[s===`marked`?u(P,{className:`h-3 w-3 animate-spin`}):u(ze,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Marked media`})]})]}),(t.data??[]).length>0&&r(`div`,{className:`flex items-center gap-1.5 flex-wrap text-[11px]`,children:[u(`span`,{className:`text-foreground-subtle`,children:`Annotated dataset from:`}),n.length===0&&u(Y,{children:`every collection and track`}),(t.data??[]).map(e=>{let t=n.includes(e.id);return r(`button`,{type:`button`,"aria-pressed":t,className:`rounded-full border px-2 py-0.5 ${t?`border-primary text-primary`:`border-border text-foreground-muted hover:text-foreground`}`,onClick:()=>{i(n=>t?n.filter(t=>t!==e.id):[...n,e.id])},children:[e.name,` · `,e.frameCount]},e.id)})]}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.isError?`The export summary could not be read, so the size of the marked set is unknown — not zero.`:h===void 0?`Measuring the marked set…`:g?`No track is marked for training: the marked-media archive would be empty. The annotated dataset can still hold frames from tracks already completed — this count does not measure those.`:`${String(h.trackCount)} marked track${h.trackCount===1?``:`s`} · ${String(h.fileCount)} file${h.fileCount===1?``:`s`} · ${Ht(h.byteCount)}${h.truncated?` · more marked tracks exist than one pass carries`:``}`}),(a.isError||o.isError)&&u(`p`,{className:`text-[11px] text-danger`,children:`An export data plane is not available on the node that answered — no archive can be streamed from here.`}),d!==null&&r(`p`,{className:`text-[11px] text-danger`,children:[`Download failed: `,d]})]})}function oa(e){return e>=1e6?`${(e/1e6).toFixed(1)} MB`:`${Math.round(e/1e3)} KB`}function sa({candidates:e,copies:t,activeFrameId:n,refusals:i,isSelecting:a,onSelectCandidate:o,onOpenCopy:s,onRemoveCopy:c,renderCopyActions:l}){let d=new Set(t.map(e=>e.sourceMediaId)),f=e.filter(e=>!d.has(e.mediaId));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(ft,{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,` · `,oa(e.sizeBytes)]}),e.complete&&u(Y,{variant:`success`,children:`complete`})]}),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(y,{className:`h-3 w-3`}),`remove`]}),l?.(e)]})},e.frameId))})]}),r(`section`,{children:[r(`h3`,{className:`text-xs font-semibold text-foreground mb-1.5`,children:[`Available frames (`,f.length,`)`]}),f.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:f.map(e=>{let t=i.get(e.mediaId);return r(`li`,{children:[r(V,{variant:`secondary`,size:`sm`,disabled:a||t!==void 0,onClick:()=>{o(e.mediaId)},children:[a?u(P,{className:`h-3 w-3 animate-spin`}):u(t===void 0?Kt:g,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:e.kind}),u(`span`,{className:`ml-1 text-foreground-subtle`,children:oa(e.sizeBytes)})]}),t!==void 0&&u(Y,{variant:`danger`,className:`ml-1`,children:t})]},e.mediaId)})})]})]})}function ca(e){return e.frameCount===0?`untouched`:e.annotationCount===0?`started`:`ready`}var la={untouched:{icon:Gt,label:`to do`,variant:`default`},started:{icon:Wt,label:`frames only`,variant:`info`},ready:{icon:Ie,label:`annotated`,variant:`success`}};function ua(e){return new Date(e).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function da({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(P,{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=la[ca(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(Y,{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)}`,` ·`,` `,ua(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)})})}function fa(e){return{deviceId:e.deviceId,...e.trackId===void 0?{}:{trackId:e.trackId},frameId:e.frameId}}var pa=`object-detection`;function ma(e,t){for(let n of e){if(n.addonId===t)return n;let e=n.children===void 0?void 0:ma(n.children,t);if(e!==void 0)return e}}function ha(e,t){for(let n of e.slots){let e=n.addons.find(e=>e.id===t);if(e!==void 0)return e}}function ga(e){let{status:t,nodeDevices:n,schema:r,resolvedSteps:i}=e;if(t===void 0)return{kind:`unknown`,gap:`pending`};if(t.detection===null)return{kind:`unknown`,gap:t.degraded.some(e=>e.stage===`detection`)?`placement-unreadable`:`detection-off`};let a=t.detection;if(n===void 0||r===void 0||i===void 0)return{kind:`unknown`,gap:`pending`};if(!n.reachable)return{kind:`unknown`,gap:`node-unreachable`};let o=n.devices.find(e=>e.backend===a.engine.backend&&e.device===a.engine.device);if(o===void 0)return{kind:`unknown`,gap:`device-unknown`};let s=ha(r,pa);if(s===void 0)return{kind:`unknown`,gap:`step-unknown`};let c=rt({catalog:s,device:o,override:ma(i,pa)?.modelId,base:o.steps?.[pa]?.modelId});return c===void 0?{kind:`unknown`,gap:`no-model`}:{kind:`resolved`,nodeId:a.nodeId,modelId:c,minScore:s.models.find(e=>e.id===c)?.defaultConfidence??s.defaultConfidence}}function _a(e,t){let n=Math.max(0,Math.min(e.x+e.w,t.x+t.w)-Math.max(e.x,t.x))*Math.max(0,Math.min(e.y+e.h,t.y+t.h)-Math.max(e.y,t.y)),r=e.w*e.h+t.w*t.h-n;return r>0?n/r:0}function va(e,t){let n=e.nextKey;return{boxes:t.map(e=>{let t=`b${String(n)}`;return n+=1,{...e,key:t}}),nextKey:n}}function ya(e){return{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},draft:!1}}function ba(e){return e.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},...e.subLabel===void 0?{}:{subLabel:e.subLabel},kind:`subject`,source:`pipeline`,...e.modelId===void 0?{}:{assistModelId:e.modelId},...e.score===void 0?{}:{assistScore:e.score},draft:!0,note:e.basis===`subject-box`?`The box the pipeline recorded on this very frame.`:`The pipeline's track position ${String(Math.round(e.deltaMs))} ms from this frame.`}))}var xa={boxes:[],selectedKey:null,nextKey:0};function Sa(e,t){let n=va(xa,e.map(ya));return Ca({boxes:n.boxes,selectedKey:null,nextKey:n.nextKey},ba(t)).state}function Ca(e,t){let n=[],r=0;for(let i of t){if([...e.boxes,...n].some(e=>_a(e.bbox,i.bbox)>=.8)){r+=1;continue}n.push({...i,draft:!0})}let i=va(e,n);return{state:{...e,boxes:[...e.boxes,...i.boxes],nextKey:i.nextKey},skipped:r}}function wa(e,t,n){let r=va(e,[{bbox:t,macroClass:n,kind:`subject`,source:`operator`,draft:!1}]),i=r.boxes[0];return i===void 0?e:{boxes:[...e.boxes,i],selectedKey:i.key,nextKey:r.nextKey}}function Ta(e,t,n){return{...e,boxes:e.boxes.map(e=>e.key===t?n(e):e)}}function Ea(e,t,n){return Ta(e,t,e=>({...e,...n,draft:!1}))}function Da(e,t){return Ta(e,t,e=>({...e,draft:!1}))}function Oa(e){return{...e,boxes:e.boxes.map(e=>e.draft?{...e,draft:!1}:e)}}function ka(e,t){return Ta(e,t,e=>({...e,kind:e.kind===`model_error`?`subject`:`model_error`,draft:!1}))}function Aa(e,t){return{...e,boxes:e.boxes.filter(e=>e.key!==t),selectedKey:e.selectedKey===t?null:e.selectedKey}}function ja(e,t){return{...e,selectedKey:t}}function Ma(e,t){return{...e,boxes:e.boxes.map(e=>{let n=t.get(e.key);return n===void 0?e:{...e,flag:n}})}}function Na(e,t){return new Map(e.map(e=>[e.ref,{verdict:e.verdict,reason:e.reason,by:t,...e.suggestedClass===void 0?{}:{suggestedClass:e.suggestedClass}}]))}function Pa(e){return e.boxes.filter(e=>e.draft).length}function Fa(e){let t=e?.trim();return t===void 0||t===``?void 0:t}function Ia(e){return e.boxes.filter(e=>!e.draft).map(e=>{let t=Fa(e.label),n=Fa(e.subLabel);return{bbox:e.bbox,macroClass:e.macroClass,...t===void 0?{}:{label:t},...n===void 0?{}:{subLabel:n},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}})}var La=[`person`,`vehicle`,`animal`,`package`,`face`,`plate`],Ra=new Set(La),za={operator:`drawn`,pipeline:`pipeline`,assist:`detector`,llm:`AI vision`};function Ba(e){let t=e?.trim().toLowerCase();return t===void 0||t===``?null:Ra.has(t)?`"${t}" is a macro class, not a label — person / postman / Marco are three different tiers`:null}function Va(e){if(e.source===`operator`)return null;let t=[za[e.source]];return e.assistModelId!==void 0&&t.push(e.assistModelId),e.assistScore!==void 0&&t.push(e.assistScore.toFixed(2)),t.join(` · `)}function Ha({boxes:e,selectedKey:t,onSelect:n,onChange:i,onAccept:a,onToggleModelError:o,onDelete:s}){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 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=>{let c=e.key===t,l=Ba(e.label),d=Ba(e.subLabel),f=Va(e);return r(`li`,{"data-testid":`retrain-row-${e.key}`,className:`p-2.5 space-y-1.5 ${c?`bg-surface-hover`:``}`,onFocus:()=>{n(e.key)},onClick:()=>{n(e.key)},children:[r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u(F,{className:`w-28`,"aria-label":`Class`,value:e.macroClass,options:La.map(e=>({value:e,label:e})),onChange:t=>{let n=La.find(e=>e===t.target.value);n!==void 0&&i(e.key,{macroClass:n})}}),e.draft&&u(Y,{variant:`warning`,children:`draft`}),e.kind===`model_error`&&u(Y,{variant:`danger`,children:`model error`}),f!==null&&u(Y,{variant:`info`,children:f}),(e.note!==void 0||e.flag!==void 0)&&r(be,{children:[u(Se,{children:u(he,{className:`h-3.5 w-3.5 ${e.flag!==void 0&&e.flag.verdict!==`confirmed`?`text-warning`:`text-foreground-subtle`}`,"aria-label":`Why this box is here`})}),r(ye,{className:`whitespace-normal w-64 text-left`,children:[e.note!==void 0&&u(`p`,{children:e.note}),e.flag!==void 0&&r(`p`,{children:[e.flag.by,`: `,e.flag.verdict,e.flag.suggestedClass===void 0?``:` (suggests ${e.flag.suggestedClass})`,` `,`— `,e.flag.reason]})]})]}),u(`span`,{className:`flex-1`}),e.draft&&u(V,{variant:`secondary`,size:`sm`,"aria-label":`Accept this proposal`,onClick:()=>{a(e.key)},children:u(ft,{className:`h-3 w-3`})}),u(V,{variant:`ghost`,size:`sm`,"aria-label":e.kind===`model_error`?`This is a real subject`:`Mark as model error`,onClick:()=>{o(e.key)},children:u(B,{className:`h-3 w-3`})}),u(V,{variant:`ghost`,size:`sm`,"aria-label":`Delete this subject`,onClick:()=>{s(e.key)},children:u(y,{className:`h-3 w-3`})})]}),r(`div`,{className:`flex items-center gap-2`,children:[u(J,{className:`flex-1`,placeholder:`label (postman, van, cat…)`,value:e.label??``,onChange:t=>{i(e.key,{label:t.target.value})}}),u(J,{className:`flex-1`,placeholder:`sub-label (a name, a plate…)`,value:e.subLabel??``,onChange:t=>{i(e.key,{subLabel:t.target.value})}})]}),l!==null&&u(`p`,{className:`text-[11px] text-danger`,children:l}),d!==null&&u(`p`,{className:`text-[11px] text-danger`,children:d})]},e.key)})})}function Ua(e){return e.filter(e=>!e.draft).every(e=>Ba(e.label)===null&&Ba(e.subLabel)===null&&Ra.has(e.macroClass))}var Wa=.25;function Ga(e,t){if(e===void 0)return[];let n=e.selectedEngine.format,r=e.slots.flatMap(e=>e.addons).find(e=>e.id===pa);if(r===void 0)return[];let i=r.models.filter(e=>e.legacy!==!0&&e.provider===void 0).flatMap(e=>{let t=e.formats[n];return t===void 0?[]:[{modelId:e.id,name:e.name,sizeMB:t.sizeMB??0}]}),a=i.find(e=>e.modelId===t);return i.filter(e=>e.modelId!==t&&(a===void 0||e.sizeMB>a.sizeMB)).toSorted((e,t)=>t.sizeMB-e.sizeMB)}n();var Ka=[{value:`teacher`,label:`Bigger detector`},{value:`llm`,label:`AI vision`},{value:`both`,label:`Both`}],qa=[`person`,`vehicle`,`animal`,`package`],Ja=[`person`,`vehicle`,`animal`,`package`,`face`,`plate`],Ya={"unknown-frame":`The frame is no longer in the dataset.`,"unreadable-frame":`The frame copy could not be read.`,"unknown-profile":`That AI profile no longer exists.`,"profile-disabled":`That AI profile is disabled.`,"no-vision":`That AI profile cannot read images.`,"cloud-not-confirmed":`The frame was not sent: sending it outside the house needs your confirmation.`,"llm-error":`The AI model call failed.`,"malformed-answer":`The AI answered in a shape that cannot be trusted, so nothing was drawn.`};function Xa({frame:e,history:n,detector:i,schema:o,setNotice:s}){let c=Ce({},{retry:!1}),d=pe(),f=N(),[p,m]=l(`teacher`),h=a(()=>Ga(o,i.kind===`resolved`?i.modelId:void 0),[o,i]),[g,_]=l(null),v=h.find(e=>e.modelId===g)??h[0],[y,b]=l(Wa),[x,S]=l(null),C=(c.data??[]).find(e=>e.id===x)??c.data?.[0],[w,T]=l(qa),[E,D]=l(!1),[k,j]=l(!1),I=t(n.editor);I.current=n.editor;let L=p!==`llm`,R=p!==`teacher`,z=i.kind===`resolved`&&v!==void 0,B=C!==void 0&&w.length>0,ee=(!L||z)&&(!R||B),te=async()=>{if(i.kind!==`resolved`||v===void 0)return``;let t=await d.mutateAsync({...fa(e),subject:{kind:`objects`,modelId:v.modelId,minScore:y},nodeId:i.nodeId});if(t.kind===`refused`)return`${v.name} refused: ${t.reason}${t.detail===void 0?``:` — ${t.detail}`}.`;let r=Ca(I.current,t.proposals.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},kind:e.kind,source:`assist`,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore},draft:!0,note:`Proposed by the larger detector ${t.modelId} on ${i.nodeId}.`})));I.current=r.state,n.setEditor(r.state);let a=t.proposals.length-r.skipped;return`${v.name}: ${String(a)} new draft${a===1?``:`s`}${r.skipped>0?`, ${String(r.skipped)} already on the frame`:``}.`},H=async t=>{if(C===void 0)return``;let r=I.current,i=await f.mutateAsync({...fa(e),profileId:C.id,classes:[...w],boxes:r.boxes.slice(0,50).map(e=>({ref:e.key,bbox:e.bbox,macroClass:e.macroClass,...e.label!==void 0&&e.label!==``?{label:e.label}:{}})),allowCloud:t});if(i.kind===`refused`)return`${Ya[i.reason]??i.reason}${i.detail===void 0?``:` (${i.detail})`}`;let a=i.proposals.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},kind:`subject`,source:`llm`,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore},draft:!0,note:`${i.model}: ${e.reason}`})),o=Na(i.reviews,i.model),s=Ca(I.current,a);n.setEditor(e=>Ma(Ca(e,a).state,o));let c=i.proposals.length-s.skipped,l=i.reviews.filter(e=>e.verdict!==`confirmed`).length;return`${C.name}: ${String(c)} new draft${c===1?``:`s`}, ${String(l)} box${l===1?``:`es`} questioned${i.rejected>0?`, ${String(i.rejected)} unusable item${i.rejected===1?``:`s`} dropped`:``}.`},U=async e=>{D(!1),j(!0),s(null);try{let t=[];L&&t.push(await te()),R&&t.push(await H(e)),s(`${t.filter(e=>e!==``).join(` `)} Drafts are not saved until you accept or correct them.`)}catch(e){s(`The assist failed: ${e instanceof Error?e.message:String(e)}`)}finally{j(!1)}};return r(`div`,{className:`px-3 py-2 border-b border-border space-y-2 text-[11px]`,"data-testid":`retrain-assist`,children:[r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u(`span`,{className:`font-semibold text-foreground`,children:`Assist`}),u(F,{className:`w-36`,"aria-label":`Assist engine`,value:p,options:Ka.map(e=>({value:e.value,label:e.label})),onChange:e=>{let t=Ka.find(t=>t.value===e.target.value);t!==void 0&&m(t.value)}}),u(`span`,{className:`flex-1`}),r(V,{size:`sm`,variant:`secondary`,disabled:!ee||k,onClick:()=>{if(R&&C?.leavesHouse===!0){D(!0);return}U(!1)},children:[k?u(P,{className:`h-3 w-3 animate-spin`}):u(en,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Run`})]})]}),L&&(h.length===0||i.kind!==`resolved`?u(`p`,{className:`text-foreground-subtle`,children:i.kind===`resolved`?`The detection node’s catalog has no detector larger than this camera’s for its format.`:`The camera’s detection node is not known, so no larger detector can be run there.`}):r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u(F,{className:`flex-1 min-w-40`,"aria-label":`Larger detector`,value:v?.modelId??``,options:h.map(e=>({value:e.modelId,label:`${e.name} (${String(Math.round(e.sizeMB))} MB)`})),onChange:e=>{_(e.target.value)}}),u(J,{className:`w-20`,"aria-label":`Minimum score`,type:`number`,min:.05,max:.95,step:.05,value:y,onChange:e=>{let t=Number.parseFloat(e.target.value);Number.isFinite(t)&&b(Math.min(.95,Math.max(.05,t)))}}),r(`span`,{className:`text-foreground-subtle`,children:[`on `,i.nodeId]})]})),R&&((c.data??[]).length===0?u(`p`,{className:`text-foreground-subtle`,children:c.isError?`The AI profiles could not be read.`:`No enabled AI profile can read images. Add one under AI settings.`}):r(`div`,{className:`space-y-1.5`,children:[u(F,{"aria-label":`AI profile`,value:C?.id??``,options:(c.data??[]).map(e=>({value:e.id,label:`${e.name} · ${e.model}${e.leavesHouse?` · cloud`:` · local`}`})),onChange:e=>{S(e.target.value)}}),C?.leavesHouse===!0&&u(`p`,{className:`text-warning`,children:`This profile sends the frame outside your home, to a cloud service. Each run asks first.`}),r(`div`,{className:`flex items-center gap-1 flex-wrap`,children:[u(`span`,{className:`text-foreground-subtle`,children:`Look for:`}),Ja.map(e=>{let t=w.includes(e);return u(`button`,{type:`button`,"aria-pressed":t,className:`rounded-full border px-2 py-0.5 ${t?`border-primary text-primary`:`border-border text-foreground-muted`}`,onClick:()=>{T(n=>t?n.filter(t=>t!==e):[...n,e])},children:e},e)})]})]})),u(pt,{open:E,onOpenChange:D,children:r(O,{children:[r(M,{children:[u(A,{children:`Send this frame outside your home?`}),u(ct,{children:`The frame from ${e.origin===`recording`?`the recording`:`this track`} will be sent to ${C?.name??`the AI profile`} (${C?.kind??`cloud`}, model ${C?.model??``}), a service outside your network, to be analysed. Only this frame, for this run.`})]}),r(fe,{children:[u(V,{variant:`ghost`,size:`sm`,onClick:()=>{D(!1)},children:`Cancel`}),u(V,{size:`sm`,onClick:()=>void U(!0),children:`Send this frame`})]})]})})]})}function Za(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 Qa(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)}}var $a=.01;function eo(e){return e.w>=.01&&e.h>=.01}function to(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}var no=[`nw`,`n`,`ne`,`e`,`se`,`s`,`sw`,`w`];function ro(e,t,n){return{x:Math.min(Math.max(0,e.x+t),Math.max(0,1-e.w)),y:Math.min(Math.max(0,e.y+n),Math.max(0,1-e.h)),w:e.w,h:e.h}}function io(e,t,n,r){if(n){let e=Math.min(Math.max(0,r),t-$a);return{start:e,size:t-e}}return{start:e,size:Math.max(Math.min(1,r),e+$a)-e}}function ao(e,t,n){let r=t.includes(`w`)||t.includes(`e`)?io(e.x,e.x+e.w,t.includes(`w`),n.x):{start:e.x,size:e.w},i=t.includes(`n`)||t.includes(`s`)?io(e.y,e.y+e.h,t.includes(`n`),n.y):{start:e.y,size:e.h};return{x:r.start,y:i.start,w:r.size,h:i.size}}function oo(e,t){return{x:t.includes(`w`)?e.x:t.includes(`e`)?e.x+e.w:e.x+e.w/2,y:t.includes(`n`)?e.y:t.includes(`s`)?e.y+e.h:e.y+e.h/2}}function so(e,t,n){let r=(e,t,n)=>Math.abs(e-t)<=n,i=r(t.x,e.x,n.x),a=r(t.x,e.x+e.w,n.x),o=r(t.y,e.y,n.y),s=r(t.y,e.y+e.h,n.y),c=t.x>=e.x-n.x&&t.x<=e.x+e.w+n.x,l=t.y>=e.y-n.y&&t.y<=e.y+e.h+n.y;return!c||!l?null:o&&i?`nw`:o&&a?`ne`:s&&i?`sw`:s&&a?`se`:o?`n`:s?`s`:i?`w`:a?`e`:t.x>=e.x&&t.x<=e.x+e.w&&t.y>=e.y&&t.y<=e.y+e.h?`body`:null}var co={x:0,y:0,w:1,h:1},lo=1.5;function uo(e,t,n){return e<t?t:e>n?n:e}function fo(e){return 1/e.w}function po(e,t,n,r){return{x:uo(r.x+(e-n.left)/n.width*r.w,0,1),y:uo(r.y+(t-n.top)/n.height*r.h,0,1)}}function mo(e,t,n){return{x:t.left+(e.x-n.x)/n.w*t.width,y:t.top+(e.y-n.y)/n.h*t.height}}function ho(e,t,n){let r=mo(e,t,n);return{left:r.x,top:r.y,width:e.w/n.w*t.width,height:e.h/n.h*t.height}}function go(e,t){return{left:e.left-t.x/t.w*e.width,top:e.top-t.y/t.h*e.height,width:e.width/t.w,height:e.height/t.h}}function _o(e,t,n){let r=uo(e.w/n,1/16,1),i=r/e.w;return{x:uo(t.x-(t.x-e.x)*i,0,1-r),y:uo(t.y-(t.y-e.y)*i,0,1-r),w:r,h:r}}function vo(e,t,n){return{x:uo(e.x+t,0,1-e.w),y:uo(e.y+n,0,1-e.h),w:e.w,h:e.h}}function yo(e){return{x:e.x+e.w/2,y:e.y+e.h/2}}var bo=[`person`,`vehicle`,`animal`,`package`,`face`,`plate`];function xo(e){if(typeof e!=`object`||!e||!(`tagName`in e))return!1;let t=String(e.tagName).toUpperCase();return t===`INPUT`||t===`TEXTAREA`||t===`SELECT`?!0:`isContentEditable`in e&&e.isContentEditable===!0}function So(e){let t=e.ctrlKey||e.metaKey,n=e.key.toLowerCase();if(t&&!e.altKey)return n===`s`&&!e.shiftKey?{kind:`save`}:e.typing?null:n===`z`?e.shiftKey?{kind:`redo`}:{kind:`undo`}:n===`y`&&!e.shiftKey?{kind:`redo`}:null;if(e.typing||t||e.altKey)return null;switch(e.key){case`ArrowRight`:return{kind:`next-frame`};case`ArrowLeft`:return{kind:`prev-frame`};case`Delete`:case`Backspace`:return{kind:`delete`};case`Escape`:return{kind:`deselect`};case`Tab`:return e.shiftKey?{kind:`select-prev`}:{kind:`select-next`};case`+`:case`=`:return{kind:`zoom-in`};case`-`:case`_`:return{kind:`zoom-out`};case`0`:return{kind:`zoom-fit`};default:break}let r=Number.parseInt(e.key,10);if(Number.isInteger(r)&&r>=1&&r<=bo.length){let e=bo[r-1];return e===void 0?null:{kind:`set-class`,macroClass:e}}return n===`a`?e.shiftKey?{kind:`accept-all`}:{kind:`accept`}:n===`e`&&!e.shiftKey?{kind:`toggle-model-error`}:n===`c`&&!e.shiftKey?{kind:`toggle-complete`}:null}var Co=[{keys:`← / →`,does:`Previous / next frame`},{keys:`Drag on empty frame`,does:`Draw a box`},{keys:`Drag a box / its handles`,does:`Move / resize it`},{keys:`Delete, Backspace`,does:`Delete the selected box`},{keys:`1 – 6`,does:`Class: person, vehicle, animal, package, face, plate`},{keys:`A`,does:`Accept the selected draft`},{keys:`Shift + A`,does:`Accept every draft`},{keys:`E`,does:`Mark / unmark the selected box as a model error`},{keys:`C`,does:`Toggle "all subjects boxed"`},{keys:`Tab / Shift + Tab`,does:`Select the next / previous box`},{keys:`Esc`,does:`Deselect`},{keys:`Ctrl/⌘ + Z`,does:`Undo`},{keys:`Ctrl/⌘ + Shift + Z, Ctrl/⌘ + Y`,does:`Redo`},{keys:`Ctrl/⌘ + S`,does:`Save the frame`},{keys:`+ / − / 0, wheel, pinch`,does:`Zoom in / out / fit`},{keys:`Space + drag, middle drag, two fingers`,does:`Pan`}];n();var wo=.0015,To={pipeline:`var(--color-foreground-muted)`,assist:`var(--color-info)`,llm:`var(--color-warning)`,operator:`var(--color-success)`};function Eo(e,t){return e.kind===`model_error`?{color:`var(--color-danger)`,dashed:!0,opacity:1}:t?{color:`var(--color-primary)`,dashed:e.draft,opacity:1}:e.draft?{color:To[e.source],dashed:!0,opacity:.8}:{color:`var(--color-success)`,dashed:!1,opacity:1}}function Do(e,t){return Math.hypot(e.x-t.x,e.y-t.y)}function Oo(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}function ko({imageSrc:n,imageWidth:a,imageHeight:o,boxes:s,selectedKey:c,viewport:f,onViewportChange:p,panMode:m,onSelect:h,onDraw:g,onGestureStart:_,onGestureBox:v,onGestureEnd:y}){let b=t(null),[x,S]=l({w:0,h:0}),[C,w]=l(null),[T,E]=l(!1),D=t(new Map),O=t({mode:`none`});i(()=>{let e=b.current;if(e===null)return;let t=()=>S({w:e.clientWidth,h:e.clientHeight});if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return n.observe(e),()=>{n.disconnect()}},[]);let k=Za(x.w,x.h,a,o);d(()=>{let e=e=>{e.key!==` `||xo(e.target)||(e.preventDefault(),E(!0))},t=e=>{e.key===` `&&E(!1)};return window.addEventListener(`keydown`,e),window.addEventListener(`keyup`,t),()=>{window.removeEventListener(`keydown`,e),window.removeEventListener(`keyup`,t)}},[]);let A=t({image:k,viewport:f,onViewportChange:p});A.current={image:k,viewport:f,onViewportChange:p},d(()=>{let e=b.current;if(e===null)return;let t=t=>{let{image:n,viewport:r,onViewportChange:i}=A.current;if(n===null)return;t.preventDefault();let a=e.getBoundingClientRect();i(_o(r,po(t.clientX-a.left,t.clientY-a.top,n,r),Math.exp(-t.deltaY*wo)))};return e.addEventListener(`wheel`,t,{passive:!1}),()=>{e.removeEventListener(`wheel`,t)}},[]);let j=e(e=>{let t=b.current?.getBoundingClientRect();return{x:e.clientX-(t?.left??0),y:e.clientY-(t?.top??0)}},[]),M=e(e=>k===null?null:po(e.x,e.y,k,f),[k,f]),N=e(()=>{let e=O.current;(e.mode===`move`||e.mode===`resize`)&&y(),e.mode===`draw`&&w(null),O.current={mode:`none`}},[y]),P=e=>{if(k===null)return;let t=j(e);if(D.current.set(e.pointerId,t),e.currentTarget.setPointerCapture?.(e.pointerId),D.current.size===2){N();let[e,t]=[...D.current.values()];if(e===void 0||t===void 0)return;let n=Oo(e,t);O.current={mode:`pinch`,startDistance:Math.max(1,Do(e,t)),anchor:po(n.x,n.y,k,f),from:f};return}if(D.current.size>2)return;if(e.button===1||T||m){e.preventDefault(),O.current={mode:`pan`,startPx:t,from:f};return}if(e.button!==0)return;let n=po(t.x,t.y,k,f),r={x:12/k.width*f.w,y:12/k.height*f.h},i=s.find(e=>e.key===c);if(i!==void 0){let e=so(i.bbox,n,r);if(e!==null&&e!==`body`){_(),O.current={mode:`resize`,key:i.key,handle:e,from:i.bbox};return}}let a=s[to(s.map(e=>e.bbox),n)];if(a!==void 0){a.key!==c&&h(a.key),_(),O.current={mode:`move`,key:a.key,start:n,from:a.bbox};return}O.current={mode:`draw`,start:n},w(Qa(n,n))},F=e=>{if(!D.current.has(e.pointerId)||k===null)return;let t=j(e);D.current.set(e.pointerId,t);let n=O.current;switch(n.mode){case`pinch`:{let[e,t]=[...D.current.values()];if(e===void 0||t===void 0)return;let r=_o(n.from,n.anchor,Do(e,t)/n.startDistance),i=Oo(e,t),a=po(i.x,i.y,k,r);p(vo(r,n.anchor.x-a.x,n.anchor.y-a.y));return}case`pan`:{let e=(t.x-n.startPx.x)/k.width*n.from.w,r=(t.y-n.startPx.y)/k.height*n.from.h;p(vo(n.from,-e,-r));return}case`move`:{let e=po(t.x,t.y,k,f);v(n.key,ro(n.from,e.x-n.start.x,e.y-n.start.y));return}case`resize`:{let e=po(t.x,t.y,k,f);v(n.key,ao(n.from,n.handle,e));return}case`draw`:{let e=po(t.x,t.y,k,f);w(Qa(n.start,e));return}default:return}},I=e=>{if(!D.current.has(e.pointerId))return;D.current.delete(e.pointerId);let t=O.current;if(t.mode===`pinch`){D.current.size<2&&(O.current={mode:`none`});return}if(t.mode===`draw`){let n=M(j(e)),r=n===null?null:Qa(t.start,n);w(null),O.current={mode:`none`},r!==null&&eo(r)?g(r):h(null);return}N()},L=s.find(e=>e.key===c),R=T||m,z=k===null?null:go(k,f);return r(`div`,{ref:b,"data-testid":`retrain-canvas`,className:`relative w-full h-full min-h-[280px] bg-surface-sunken select-none touch-none overflow-hidden`,style:{cursor:R?`grab`:`crosshair`},onPointerDown:P,onPointerMove:F,onPointerUp:I,onPointerCancel:I,children:[z!==null&&u(`img`,{src:n,alt:`Frame being annotated`,draggable:!1,className:`absolute max-w-none pointer-events-none`,style:z}),k!==null&&s.map(e=>{let t=ho(e.bbox,k,f),n=e.key===c,i=Eo(e,n);return u(`div`,{"data-testid":`retrain-box-${e.key}`,"data-draft":e.draft?`true`:`false`,"data-source":e.source,className:`absolute pointer-events-none`,style:{left:t.left,top:t.top,width:t.width,height:t.height,border:`${n?`2px`:`1px`} ${i.dashed?`dashed`:`solid`} ${i.color}`,opacity:i.opacity},children:r(`span`,{className:`absolute -top-4 left-0 text-[10px] px-1 rounded whitespace-nowrap text-background`,style:{background:i.color},children:[e.label??e.macroClass,e.kind===`model_error`?` ✕`:``,e.draft?` ?`:``,e.flag!==void 0&&e.flag.verdict!==`confirmed`?` !`:``]})},e.key)}),k!==null&&L!==void 0&&no.map(e=>{let t=mo(oo(L.bbox,e),k,f);return u(`div`,{"data-testid":`retrain-handle-${e}`,className:`absolute h-2.5 w-2.5 -translate-x-1/2 -translate-y-1/2 rounded-sm border border-background bg-primary pointer-events-none`,style:{left:t.x,top:t.y}},e)}),C!==null&&k!==null&&u(`div`,{className:`absolute border border-dashed border-primary pointer-events-none`,style:ho(C,k,f)})]})}n();function Ao(){let[t,n]=l(co),[r,i]=l(!1);return{viewport:t,setViewport:n,zoomIn:e(()=>{n(e=>_o(e,yo(e),lo))},[]),zoomOut:e(()=>{n(e=>_o(e,yo(e),1/lo))},[]),fit:e(()=>{n(co)},[]),panMode:r,togglePan:e(()=>{i(e=>!e)},[])}}function jo({view:e,canUndo:t,canRedo:n,onUndo:i,onRedo:a}){let o=fo(e.viewport);return r(`div`,{className:`flex items-center gap-1 px-2 py-1 border-b border-border bg-surface`,children:[u(V,{variant:`ghost`,size:`sm`,"aria-label":`Zoom out`,onClick:e.zoomOut,children:u(ht,{className:`h-3.5 w-3.5`})}),r(`span`,{className:`w-12 text-center text-[11px] tabular-nums text-foreground-subtle`,children:[Math.round(o*100),`%`]}),u(V,{variant:`ghost`,size:`sm`,"aria-label":`Zoom in`,onClick:e.zoomIn,children:u(de,{className:`h-3.5 w-3.5`})}),u(V,{variant:`ghost`,size:`sm`,"aria-label":`Fit the whole frame`,disabled:o<=1,onClick:e.fit,children:u(Xt,{className:`h-3.5 w-3.5`})}),u(V,{variant:e.panMode?`secondary`:`ghost`,size:`sm`,"aria-label":`Pan tool`,"aria-pressed":e.panMode,onClick:e.togglePan,children:u(L,{className:`h-3.5 w-3.5`})}),u(`span`,{className:`flex-1`}),u(V,{variant:`ghost`,size:`sm`,"aria-label":`Undo`,disabled:!t,onClick:i,children:u(K,{className:`h-3.5 w-3.5`})}),u(V,{variant:`ghost`,size:`sm`,"aria-label":`Redo`,disabled:!n,onClick:a,children:u(Qt,{className:`h-3.5 w-3.5`})}),r(_e,{children:[u(W,{"aria-label":`Keyboard shortcuts`,className:`inline-flex h-7 items-center rounded-md px-2 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:u(Jt,{className:`h-3.5 w-3.5`})}),r(R,{className:`w-80`,children:[u(`h3`,{className:`mb-2 text-xs font-semibold text-foreground`,children:`Keyboard and gestures`}),u(`table`,{className:`w-full text-[11px]`,children:u(`tbody`,{children:Co.map(e=>r(`tr`,{className:`align-top`,children:[u(`td`,{className:`py-0.5 pr-2 font-mono whitespace-nowrap text-foreground`,children:e.keys}),u(`td`,{className:`py-0.5 text-foreground-subtle`,children:e.does})]},e.keys))})})]})]})]})}function Mo(e){return{past:[],present:e,future:[],gestureBase:null}}function No(e,t){let n=[...e,t];return n.length>100?n.slice(n.length-100):n}function Po(e,t){return t===e.present?e:{past:No(e.past,e.present),present:t,future:[],gestureBase:null}}function Fo(e,t){return{...e,present:t}}function Io(e){let t=e.past[e.past.length-1];return t===void 0?e:{past:e.past.slice(0,-1),present:t,future:[e.present,...e.future],gestureBase:null}}function Lo(e){let[t,...n]=e.future;return t===void 0?e:{past:No(e.past,e.present),present:t,future:n,gestureBase:null}}function Ro(e){return{...e,gestureBase:e.present}}function zo(e,t){return{...e,present:t}}function Bo(e){let t=e.gestureBase;return t===null?e:t===e.present?{...e,gestureBase:null}:{past:No(e.past,t),present:e.present,future:[],gestureBase:null}}function Vo(e){return e.past.length>0}function Ho(e){return e.future.length>0}n();function Uo(e,t){return typeof e==`function`?e(t):e}function Wo(t){let[n,r]=l(()=>Mo(t())),i=e(e=>{r(t=>Po(t,Uo(e,t.present)))},[]),a=e(e=>{r(Mo(e))},[]),o=e(e=>{r(t=>Fo(t,Uo(e,t.present)))},[]),s=e(()=>{r(e=>Ro(e))},[]),c=e(e=>{r(t=>zo(t,Uo(e,t.present)))},[]),u=e(()=>{r(e=>Bo(e))},[]),d=e(()=>{r(e=>Io(e))},[]),f=e(()=>{r(e=>Lo(e))},[]);return{editor:n.present,setEditor:i,resetEditor:a,selectOnly:o,beginGesture:s,updateGesture:c,endGesture:u,undo:d,redo:f,canUndo:Vo(n),canRedo:Ho(n)}}n();function Go(e,t){let n=e.boxes.length;if(n===0)return null;let r=e.boxes.findIndex(t=>t.key===e.selectedKey),i=r<0?t===1?0:n-1:(r+t+n)%n;return e.boxes[i]?.key??null}function Ko(e,t){let{history:n}=t,r=n.editor.selectedKey;switch(e.kind){case`next-frame`:return t.onNextFrame();case`prev-frame`:return t.onPrevFrame();case`toggle-complete`:return t.onToggleComplete();case`save`:return t.onSave();case`undo`:return n.canUndo?(n.undo(),!0):!1;case`redo`:return n.canRedo?(n.redo(),!0):!1;case`zoom-in`:return t.onZoomIn(),!0;case`zoom-out`:return t.onZoomOut(),!0;case`zoom-fit`:return t.onZoomFit(),!0;case`accept-all`:return n.setEditor(e=>Oa(e)),!0;case`select-next`:case`select-prev`:{let t=Go(n.editor,e.kind===`select-next`?1:-1);return t===null?!1:(n.selectOnly(e=>ja(e,t)),!0)}case`deselect`:return r===null?!1:(n.selectOnly(e=>ja(e,null)),!0);default:break}if(r===null)return!1;switch(e.kind){case`delete`:return n.setEditor(e=>Aa(e,r)),!0;case`set-class`:return n.setEditor(t=>Ea(t,r,{macroClass:e.macroClass})),!0;case`accept`:return n.setEditor(e=>Da(e,r)),!0;case`toggle-model-error`:return n.setEditor(e=>ka(e,r)),!0;default:return!1}}function qo(e,n){let r=t(n);r.current=n,d(()=>{if(!e)return;let t=e=>{if(e.defaultPrevented||e.isComposing)return;let t=So({key:e.key,ctrlKey:e.ctrlKey,metaKey:e.metaKey,shiftKey:e.shiftKey,altKey:e.altKey,typing:xo(e.target)});t!==null&&Ko(t,r.current)&&e.preventDefault()};return window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`keydown`,t)}},[e])}n();var Jo=`person`,Yo={pending:`Reading which detector this camera runs…`,"placement-unreadable":`The detection stage of this camera could not be read, so the model it runs is unknown — not absent.`,"detection-off":`This camera runs no object detector, so there is no proposal to mirror.`,"node-unreachable":`The node that detects for this camera did not answer about its accelerators.`,"device-unknown":`The node does not list the accelerator this camera detects on — asking another one would propose with a different model.`,"step-unknown":`That node carries no object-detection step in its catalog.`,"no-model":`No object-detection model on that accelerator can be resolved for this camera.`};function Xo({frames:n,activeFrameId:i,onActiveFrame:o,onFramesChanged:s,onSaved:c,setNotice:f,picked:p=!1,onTogglePick:m}){let h=n.find(e=>e.frameId===i),g=h?.deviceId??null,_=Wo(()=>Sa([],[])),{editor:v,setEditor:y,resetEditor:b,selectOnly:x}=_,S=Ao(),w=Le({frameIds:[i]}),E=We({frameId:i}),D=pe(),O=T(),k=re(),A=Qe({deviceIds:g===null?[]:[g]},{enabled:g!==null,staleTime:3e4}),j=A.data?.[0]?.detection?.nodeId??null,M=le({nodeId:j??``},{enabled:j!==null,staleTime:3e4}),N=ee({nodeId:j??``},{enabled:j!==null,staleTime:3e4}),F=Ue({deviceId:g??0},{enabled:g!==null,staleTime:3e4}),I=a(()=>ga({status:A.data?.[0],nodeDevices:M.data,schema:N.data,resolvedSteps:F.data?.steps}),[A.data,M.data,N.data,F.data]),L=t({stored:w.data,copy:h});L.current={stored:w.data,copy:h};let R=h!==void 0;d(()=>{S.fit();let{stored:e,copy:t}=L.current;b(Sa((e??[]).filter(e=>e.mediaKey===i),t?.pipelineBoxes??[]))},[i,w.dataUpdatedAt,R,b,S.fit]);let z=e(async e=>{h!==void 0&&(await k.mutateAsync({...fa(h),complete:e}),await s())},[h,k,s]),B=e(async e=>{if(h===void 0)return;if(f(null),I.kind!==`resolved`){f(Yo[I.gap]);return}let t=await D.mutateAsync({...fa(h),subject:e===`package`?{kind:`package`}:{kind:`objects`,modelId:I.modelId,minScore:I.minScore},nodeId:I.nodeId});if(t.kind===`refused`){f(t.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: ${t.reason}${t.detail===void 0?``:` — ${t.detail}`}`);return}let n=Ca(v,t.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},draft:!0})));y(n.state),f(`${t.proposals.length} proposal${t.proposals.length===1?``:`s`} from ${t.modelId}`+(n.skipped>0?` — ${n.skipped} already on the frame`:``)+(t.belowThreshold>0?` — ${t.belowThreshold} more were below ${t.minScore.toFixed(2)}`:``)+`. Accept or correct each one; drafts are not saved.`)},[h,D,I,v,y,f]),te=e(e=>{y(t=>wa(t,e,Jo))},[y]),[U,W]=l(!1),G=e(async()=>{if(h===void 0)return;let e=Pa(v);W(!0);try{await O.mutateAsync({...fa(h),annotations:[...Ia(v)]}),await w.refetch()}finally{W(!1)}await c?.(),f(e>0?`Annotations saved. ${String(e)} unconfirmed draft${e===1?` was`:`s were`} not saved.`:`Annotations saved.`)},[h,v,O,w,c,f]),K=E.data,ne=Ua(v.boxes)&&h!==void 0,q=Pa(v),ie=n.map(e=>e.frameId),ae=e=>{let t=ie.indexOf(i),n=ie[t+e];return t<0||n===void 0?!1:(o(n),!0)};return qo(!U,{history:_,onNextFrame:()=>ae(1),onPrevFrame:()=>ae(-1),onToggleComplete:()=>h===void 0||k.isPending?!1:(z(!h.complete),!0),onSave:()=>!ne||U?!1:(G(),!0),onZoomIn:S.zoomIn,onZoomOut:S.zoomOut,onZoomFit:S.fit}),r(`div`,{className:`grid grid-cols-1 xl:grid-cols-[minmax(0,1fr)_minmax(0,380px)] gap-3 ${U?`pointer-events-none opacity-70`:``}`,"aria-busy":U,children:[r(`div`,{className:`rounded-md border border-border overflow-hidden flex flex-col`,children:[u(jo,{view:S,canUndo:_.canUndo,canRedo:_.canRedo,onUndo:_.undo,onRedo:_.redo}),K===void 0?r(`div`,{className:`flex items-center gap-2 p-6 text-xs text-foreground-subtle`,children:[u(P,{className:`h-3.5 w-3.5 animate-spin`}),`Loading the frame…`]}):u(ko,{imageSrc:`data:image/jpeg;base64,${K.base64}`,imageWidth:K.width,imageHeight:K.height,boxes:v.boxes,selectedKey:v.selectedKey,viewport:S.viewport,onViewportChange:S.setViewport,panMode:S.panMode,onSelect:e=>{x(t=>ja(t,e))},onDraw:te,onGestureStart:_.beginGesture,onGestureBox:(e,t)=>{_.updateGesture(n=>Ea(n,e,{bbox:t}))},onGestureEnd:_.endGesture})]}),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 flex-wrap`,children:[u(`h2`,{className:`text-xs font-semibold text-foreground flex-1`,children:`Subjects`}),h?.origin===`recording`&&u(Y,{variant:`info`,children:`from the recording`}),m!==void 0&&r(V,{variant:p?`primary`:`ghost`,size:`sm`,"aria-pressed":p,title:`Pick this frame for a dataset version (Datasets tab)`,onClick:m,children:[u(Zt,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:p?`Picked`:`Pick for dataset`})]}),r(V,{variant:`secondary`,size:`sm`,disabled:D.isPending||I.kind!==`resolved`,onClick:()=>void B(`objects`),children:[u(H,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Propose`})]}),r(V,{variant:`secondary`,size:`sm`,disabled:D.isPending||I.kind!==`resolved`,onClick:()=>void B(`package`),children:[u(H,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Packages`})]})]}),u(`div`,{className:`px-3 py-1 border-b border-border text-[11px] text-foreground-subtle`,children:I.kind===`resolved`?`Proposals come from ${I.modelId} at ${I.minScore.toFixed(2)}, on ${I.nodeId} — what this camera really runs.`:Yo[I.gap]}),h!==void 0&&u(Xa,{frame:h,history:_,detector:I,schema:N.data,setNotice:f}),u(`div`,{className:`flex-1 overflow-y-auto`,children:u(Ha,{boxes:v.boxes,selectedKey:v.selectedKey,onSelect:e=>{x(t=>ja(t,e))},onChange:(e,t)=>{y(n=>Ea(n,e,t))},onAccept:e=>{y(t=>Da(t,e))},onToggleModelError:e=>{y(t=>ka(t,e))},onDelete:e=>{y(t=>Aa(t,e))}})}),r(`label`,{className:`px-3 py-2 border-t border-border flex items-center gap-2 text-[11px] text-foreground`,children:[u(C,{"aria-label":`All subjects in this frame are boxed`,checked:h?.complete===!0,disabled:h===void 0||k.isPending,onChange:e=>void z(e.target.checked)}),r(`span`,{className:`flex-1`,children:[`All subjects boxed`,u(`span`,{className:`block text-foreground-subtle`,children:`Detector evaluation uses only these frames — an unboxed person counts as a false alarm. A frame with nothing in it, ticked, is a negative example.`})]})]}),q>0&&r(`div`,{className:`px-3 py-2 border-t border-border flex items-center gap-2 text-[11px] text-warning`,children:[r(`span`,{className:`flex-1`,children:[q,` draft`,q===1?``:`s`,` not confirmed — a draft is never saved. Accept, correct or delete each one.`]}),r(V,{variant:`secondary`,size:`sm`,onClick:()=>{y(e=>Oa(e))},children:[u(Pt,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Accept all`})]})]}),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:[v.boxes.filter(e=>e.kind===`model_error`).length,` marked as model errors`]}),u(V,{size:`sm`,disabled:!ne||U,onClick:()=>void G(),children:`Save frame`})]})]})]})}n();var Zo={"empty-name":`Give the collection a name.`,"duplicate-name":`A collection with that name already exists.`,"unknown-collection":`That collection no longer exists.`};function Qo(){let[t,n]=l(`tracks`),[i,o]=l(null),[c,f]=l(null),[p,m]=l(null),[h,g]=l(new Map),[_,v]=l(null),[y,b]=l([]),x=nt({projection:`slim`,isCamera:!0}),C=a(()=>{let e=new Map;for(let t of x.data??[])e.set(t.id,t.name);return e},[x.data]),w=ue({}),T=mt({trackId:i?.trackId??``},{enabled:t===`tracks`&&i!==null}),D=ne(),O=qe(),k=S(),A=_t({}),j=ot({collectionId:c?.id??``},{enabled:t===`collections`&&c!==null}),M=Pe(),N=He(),P=tt(),F=ae(),I=t===`tracks`?T.data?.copies??[]:j.data??[],L=e(()=>t===`tracks`?T.refetch():j.refetch(),[t,T,j]);d(()=>{p===null&&I.length>0&&m(I[0].frameId)},[I,p]);let R=e(()=>{m(null),g(new Map),v(null)},[]),B=e(e=>{o(e),R()},[R]),ee=e(e=>{f(e),R()},[R]),te=e(async e=>{if(i===null)return;let t=await D.mutateAsync({deviceId:i.deviceId,trackId:i.trackId,mediaIds:[e]});if(t.refused.length>0){let e=new Map(h);for(let n of t.refused)e.set(n.sourceMediaId,n.reason);g(e)}t.copied.length>0&&m(t.copied[0].frameId),await T.refetch(),await w.refetch()},[i,D,h,T,w]),H=e(async e=>{let t=(T.data?.copies??[]).find(t=>t.frameId===e);t!==void 0&&(await O.mutateAsync(fa(t)),p===e&&m(null),await T.refetch(),await w.refetch(),await A.refetch())},[T,O,p,w,A]),U=e(async()=>{if(i===null)return;let e=await k.mutateAsync({deviceId:i.deviceId,trackId:i.trackId});v(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 w.refetch(),e.changed&&o(null)},[i,k,w]),W=e(async e=>{let t=await M.mutateAsync({name:e});return await A.refetch(),t.kind===`refused`?Zo[t.reason]??t.reason:(f(t.collection),R(),null)},[M,A,R]),G=e(async(e,t)=>{let n=await N.mutateAsync({id:e,name:t});return await A.refetch(),n.kind===`refused`?Zo[n.reason]??n.reason:(c?.id===e&&f(n.collection),null)},[N,A,c]),K=e(async e=>{let t=await P.mutateAsync({id:e});c?.id===e&&(f(null),R()),await A.refetch(),v(t.deleted?`Collection deleted${t.removedFrames>0?` — ${String(t.removedFrames)} recording frame${t.removedFrames===1?``:`s`} no other collection held left the dataset`:``}.`:`That collection no longer existed.`)},[P,c,A,R]),q=e(async e=>{if(c===null)return;let t=await F.mutateAsync({collectionId:c.id,frameId:e.frameId});p===e.frameId&&m(null),await j.refetch(),await A.refetch(),v(t.deletedFrame?`Removed — it was a recording frame no other collection held, so it left the dataset with its boxes.`:`Removed from the collection.`)},[c,F,p,j,A]),re=e(async()=>{await w.refetch()},[w]),ie=t===`tracks`?i!==null:c!==null,oe=I.some(e=>e.frameId===p);return r(Ft,{subtitle:`Turn marked tracks and frames sent from recordings into an annotated dataset. Every frame is a copy the dataset owns — it never depends on media that can be swept.`,actions:t===`tracks`&&i!==null?r(V,{size:`sm`,onClick:()=>void U(),children:[u(Xe,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Complete track`})]}):null,children:[_!==null&&u(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-xs text-foreground`,children:_}),u(aa,{}),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:[u(E,{value:t,onValueChange:e=>{n(e===`collections`||e===`datasets`?e:`tracks`),R()},children:r(z,{className:`px-2 pt-2`,children:[r(me,{value:`tracks`,children:[`Tracks `,u(Y,{className:`ml-1`,children:w.data?.length??0})]}),r(me,{value:`collections`,children:[`Collections `,u(Y,{className:`ml-1`,children:A.data?.length??0})]}),u(me,{value:`datasets`,children:`Datasets`})]})}),t===`tracks`?u(da,{tracks:w.data??[],isLoading:w.isLoading,selectedTrackId:i?.trackId??null,deviceNames:C,onSelect:B}):t===`datasets`?u(`p`,{className:`p-3 text-[11px] text-foreground-subtle`,children:`A dataset version freezes the frames a selection of cameras, collections and picked frames yields, with the hash of their boxes, so a training run can name exactly what it learned from. Pick frames with "Pick for dataset" in the frame workbench.`}):u(Zi,{collections:A.data??[],isLoading:A.isLoading,selectedId:c?.id??null,onSelect:ee,onCreate:W,onRename:G,onDelete:K})]}),u(`section`,{className:`space-y-3 min-w-0`,children:t===`datasets`?u(ia,{deviceNames:C,collections:A.data??[],pickedFrameIds:y,onClearPicked:()=>{b([])}}):ie?r(s,{children:[u(`div`,{className:`rounded-md border border-border bg-surface p-3`,children:t===`tracks`?u(sa,{candidates:T.data?.candidates??[],copies:T.data?.copies??[],activeFrameId:p,refusals:h,isSelecting:D.isPending,onSelectCandidate:e=>void te(e),onOpenCopy:m,onRemoveCopy:e=>void H(e),renderCopyActions:e=>u(Ji,{frameId:e.frameId,onAdded:()=>A.refetch()})}):u(Xi,{frames:j.data??[],isLoading:j.isLoading,activeFrameId:p,deviceNames:C,onOpen:m,onRemove:e=>void q(e)})}),p!==null&&oe&&u(Xo,{frames:I,activeFrameId:p,onActiveFrame:m,onFramesChanged:L,onSaved:re,setNotice:v,picked:y.includes(p),onTogglePick:()=>{b(e=>e.includes(p)?e.filter(e=>e!==p):[...e,p])}})]}):u(`p`,{className:`text-xs text-foreground-subtle`,children:t===`tracks`?`Pick a track from the staging list to start annotating it.`:`Pick or create a collection.`})})]})]})}function $o(){return u(`div`,{className:`flex flex-col p-4`,children:u(Vt,{tabs:[{id:`feed`,label:`Feed`,icon:ge,content:u(qi,{})},{id:`retrain`,label:`Retrain`,icon:Xe,content:u(Qo,{})},{id:`debug`,label:`Debug`,icon:st,content:u(bi,{})}]})})}export{$o as EventsPage};