@camstack/addon-admin-ui 1.2.483 → 1.2.484

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 (127) hide show
  1. package/dist/assets/{AddonAssetIcon-DG82cOOB.js → AddonAssetIcon-3vq-0y-v.js} +1 -1
  2. package/dist/assets/{Addons-B7pn0v6S.js → Addons-Bk1BZHnK.js} +1 -1
  3. package/dist/assets/{AdminPage-CNutWOEU.js → AdminPage-QmLz5qjj.js} +1 -1
  4. package/dist/assets/{AdminSectionedPage-Dm8ND20L.js → AdminSectionedPage-DYCbg6TR.js} +1 -1
  5. package/dist/assets/AiProfiles-ZWSpLyRc.js +3 -0
  6. package/dist/assets/{BrokerForm-DijcT6td.js → BrokerForm-C0PFW-8b.js} +1 -1
  7. package/dist/assets/Build-Dnm_I3D9.js +40 -0
  8. package/dist/assets/{Calendars-Ck9cG0iB.js → Calendars-DvjofwPU.js} +1 -1
  9. package/dist/assets/{Cluster-yiPXhRl-.js → Cluster-CrfYNPnJ.js} +1 -1
  10. package/dist/assets/{CompositionBlockEditor-BxkWKOxd.js → CompositionBlockEditor-BcDYEyOm.js} +1 -1
  11. package/dist/assets/{CompositionEditorPage-C7aaI4Ga.js → CompositionEditorPage-DpKcmhYi.js} +1 -1
  12. package/dist/assets/{Data-Cker1tA1.js → Data-BqyCS1VW.js} +1 -1
  13. package/dist/assets/DeviceDetail-DfLnQGqY.js +2 -0
  14. package/dist/assets/{DeviceDoActionFields-CP-EliT2.js → DeviceDoActionFields-CJj4-67I.js} +1 -1
  15. package/dist/assets/{Devices-DmVvfG_b.js → Devices-DQnrgH0r.js} +1 -1
  16. package/dist/assets/{EmbedPlayerPage-CoSlXnQ9.js → EmbedPlayerPage-D6aNp4TG.js} +1 -1
  17. package/dist/assets/HelperWizard-BM-npSft.js +2 -0
  18. package/dist/assets/{History-gocAbU36.js → History-DZ_p9s8N.js} +1 -1
  19. package/dist/assets/Identity-B-pYFi7F.js +1 -0
  20. package/dist/assets/{IntegrationDetail-B17OUQKx.js → IntegrationDetail-CvtkeTns.js} +1 -1
  21. package/dist/assets/{IntegrationHub-D6NA9UIc.js → IntegrationHub-Crv-Ut8D.js} +1 -1
  22. package/dist/assets/{Integrations-UBtD6K0x.js → Integrations-BpVqgjFG.js} +1 -1
  23. package/dist/assets/{Integrations-DHGfNtpw.js → Integrations-tTRZOlex.js} +1 -1
  24. package/dist/assets/{Library-BbuNPwa4.js → Library-BFFl1PFs.js} +1 -1
  25. package/dist/assets/{Locations-BHhCef1F.js → Locations-sD9PMtF8.js} +2 -2
  26. package/dist/assets/{Logs-BdiPIKKN.js → Logs-ByKgDjzR.js} +1 -1
  27. package/dist/assets/{MaskShapeCanvas-B-Co3EcK.js → MaskShapeCanvas-CzHUGkc7.js} +1 -1
  28. package/dist/assets/{MotionZonesSettings-rYNi0IyL.js → MotionZonesSettings-sCDWBSMu.js} +1 -1
  29. package/dist/assets/{MyAccess-DqlunIKb.js → MyAccess-_FlzEnLb.js} +1 -1
  30. package/dist/assets/{Network-rDYYtzyq.js → Network-U-uppn3V.js} +1 -1
  31. package/dist/assets/{NodeAddonsSettingsPanel-mj1x8pib.js → NodeAddonsSettingsPanel-DOuw1uWS.js} +1 -1
  32. package/dist/assets/Notifications-AkbB0Ya7.js +1 -0
  33. package/dist/assets/Pipeline-CMwJb0kX.js +1 -0
  34. package/dist/assets/{PrivacyMaskSettings-B_ZOhHsa.js → PrivacyMaskSettings-DH3PZaEy.js} +1 -1
  35. package/dist/assets/{Recordings-CHeLoIRU.js → Recordings-BJVAQK7Q.js} +1 -1
  36. package/dist/assets/{ScanNetworkModal-DDNyXnXJ.js → ScanNetworkModal-qjbQd1Q4.js} +1 -1
  37. package/dist/assets/{SceneMonitorEditor-CyHwjdzH.js → SceneMonitorEditor-CLWf6Z9-.js} +1 -1
  38. package/dist/assets/{SessionsList-B27Ne5e_.js → SessionsList-DSaSTSfg.js} +1 -1
  39. package/dist/assets/{Showroom-CxOhuFLC.js → Showroom-yf_2TnT8.js} +1 -1
  40. package/dist/assets/{System-T0PZXCE1.js → System-BKoiOnT6.js} +1 -1
  41. package/dist/assets/{Terminal-BA3WpGbf.js → Terminal-CGMRAh-D.js} +1 -1
  42. package/dist/assets/{Viewer-BIZ2-AWC.js → Viewer-CTvuCeo6.js} +1 -1
  43. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-XyNfp-21.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DAW63rZZ.js} +1 -1
  44. package/dist/assets/{addon-icons-context-IF2bAKB7.js → addon-icons-context-Bzdujcmt.js} +1 -1
  45. package/dist/assets/{archive-DwK992kq.js → archive-dvL2Bchb.js} +1 -1
  46. package/dist/assets/{assignment-candidates-BfYuVkll.js → assignment-candidates-Zc8Nwi6m.js} +1 -1
  47. package/dist/assets/{authed-media-2wArFI8C.js → authed-media-B6hJJcft.js} +1 -1
  48. package/dist/assets/{bell-off-BT9N_y5z.js → bell-off-C3flB_OF.js} +1 -1
  49. package/dist/assets/{board-model-C79CsHea.js → board-model-h3RS4HY8.js} +1 -1
  50. package/dist/assets/{boxes-Brm6PKBJ.js → boxes-BiMbpzNh.js} +1 -1
  51. package/dist/assets/chart-column-BMpUb2lF.js +1 -0
  52. package/dist/assets/circle-slash-B8Tjloe5.js +1 -0
  53. package/dist/assets/client-Ct1F5MoE.js +358 -0
  54. package/dist/assets/{cloud-upload-BWBb35pQ.js → cloud-upload-CAJgV_u1.js} +1 -1
  55. package/dist/assets/crop-CS-td_0y.js +1 -0
  56. package/dist/assets/{device-integration-icon-CfmyHq1L.js → device-integration-icon-DukkUZAm.js} +1 -1
  57. package/dist/assets/device-picker-model-P-UzQOB7.js +1 -0
  58. package/dist/assets/dist-B89wGMMB.js +358 -0
  59. package/dist/assets/{dist-v4PTiFhI.js → dist-CPp8d_RN.js} +1 -1
  60. package/dist/assets/{eraser-DOQYm-bd.js → eraser-BL6nSeLQ.js} +1 -1
  61. package/dist/assets/{format-DZdW_-La.js → format-ChtZgmyh.js} +1 -1
  62. package/dist/assets/{hard-drive-download-BomHKdQ6.js → hard-drive-download-ysGKYLwW.js} +1 -1
  63. package/dist/assets/{hostInit-Y3_WOWpF.js → hostInit-CDPK_pyj.js} +1 -1
  64. package/dist/assets/i18n-DJ4egBMY.js +1 -0
  65. package/dist/assets/icons-B7uNvSe0.js +1 -0
  66. package/dist/assets/index-hKEeWkm1.js +4 -0
  67. package/dist/assets/{key-round-HMiyn866.js → key-round-BDT5O9Ed.js} +1 -1
  68. package/dist/assets/{key-BjcxiZfv.js → key-xS-HUgNI.js} +1 -1
  69. package/dist/assets/{layers-71beSjbX.js → layers-BeRWYCde.js} +1 -1
  70. package/dist/assets/{linked-devices-model-CGjAZM4f.js → linked-devices-model-DOZONZiM.js} +1 -1
  71. package/dist/assets/{list-ordered-B00NsDtF.js → list-ordered-DKzGLPr6.js} +1 -1
  72. package/dist/assets/{location-owned-usage-C-GlyOpT.js → location-owned-usage-BxmUSyXj.js} +1 -1
  73. package/dist/assets/{log-in-CqClOuyv.js → log-in-53JDrQ-P.js} +1 -1
  74. package/dist/assets/{memory-stick-GbtuW7Ii.js → memory-stick-B9PVELyF.js} +1 -1
  75. package/dist/assets/{message-square-plus-BCFV5CXr.js → message-square-plus-B32IU45x.js} +1 -1
  76. package/dist/assets/{mf-entry-bootstrap-0-426ce71a.js → mf-entry-bootstrap-0-65d35510.js} +2 -2
  77. package/dist/assets/{mic-off-COk2FYD5.js → mic-off-B0w-1GrV.js} +1 -1
  78. package/dist/assets/{monitor-off-nojFqJI5.js → monitor-off-Cz2SxBVE.js} +1 -1
  79. package/dist/assets/{monitor-smartphone-BuxgqmtR.js → monitor-smartphone-Cqk6Z8Hg.js} +1 -1
  80. package/dist/assets/mount-P-UzQOB7.js +1 -0
  81. package/dist/assets/{player-overlays-BoPcGTkt.js → player-overlays-Cs6l33cj.js} +1 -1
  82. package/dist/assets/{recycle-Cbhp7tZj.js → recycle-DpB4QxbX.js} +1 -1
  83. package/dist/assets/remoteEntry-BGbchE1L.js +1 -0
  84. package/dist/assets/{scan-eye-COINNEut.js → scan-eye-DcYrgFOu.js} +1 -1
  85. package/dist/assets/{scissors-CU5rKPA8.js → scissors-_j_D3ONm.js} +1 -1
  86. package/dist/assets/{search-x-BEiDgxD-.js → search-x-9dPd-b95.js} +1 -1
  87. package/dist/assets/{send-CNx75CN6.js → send-D42ODbS7.js} +1 -1
  88. package/dist/assets/{settings-2-yfTMebsz.js → settings-2-zgGmo4c8.js} +1 -1
  89. package/dist/assets/{speaker-DzqHMf19.js → speaker-DIPHxIQ6.js} +1 -1
  90. package/dist/assets/src-DFzrn-CX.js +67 -0
  91. package/dist/assets/{step-inspector-model-BPPs6HSK.js → step-inspector-model-CS79liRv.js} +1 -1
  92. package/dist/assets/{table-2-CysTnRKy.js → table-2-lftK0wHb.js} +1 -1
  93. package/dist/assets/{timer-reset-BgIXd7hf.js → timer-reset-catAE_r9.js} +1 -1
  94. package/dist/assets/{ungroup-fAQCZXka.js → ungroup-BKImeHER.js} +1 -1
  95. package/dist/assets/{unlink-DSg9bFwt.js → unlink-Behl018w.js} +1 -1
  96. package/dist/assets/{usb-D-DRV1uf.js → usb-D5kzB8kq.js} +1 -1
  97. package/dist/assets/{use-scenes-feed-DO_UdVPf.js → use-scenes-feed-CGDnep25.js} +1 -1
  98. package/dist/assets/{use-stationary-objects-BXlbjYsd.js → use-stationary-objects-D_R5OahX.js} +1 -1
  99. package/dist/assets/useEventInvalidation-P-UzQOB7.js +1 -0
  100. package/dist/assets/{useNodeUrlSelection-BtOB6Z9m.js → useNodeUrlSelection-PBAYjRo5.js} +1 -1
  101. package/dist/assets/user-round-BJVl6LX9.js +1 -0
  102. package/dist/assets/{user-x-CPWIU9qV.js → user-x-COQ6vhb4.js} +1 -1
  103. package/dist/assets/{video-BM3o6nmQ.js → video-Byw3ItoR.js} +1 -1
  104. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-Bw4dQyg1.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CsFmgfi4.js} +2 -2
  105. package/dist/index.html +9 -9
  106. package/dist/server/addon.js +169 -29
  107. package/package.json +1 -1
  108. package/dist/assets/AiProfiles-CaJWaXuB.js +0 -3
  109. package/dist/assets/Build-Cq96yUoY.js +0 -40
  110. package/dist/assets/DeviceDetail-CIT2D5yf.js +0 -2
  111. package/dist/assets/HelperWizard-DS_R_NlR.js +0 -2
  112. package/dist/assets/Identity-CuazTQNS.js +0 -1
  113. package/dist/assets/Notifications-RMkYxLsU.js +0 -1
  114. package/dist/assets/Pipeline-DeamCmUq.js +0 -1
  115. package/dist/assets/circle-slash-DbVS3C3N.js +0 -1
  116. package/dist/assets/client-xX9FBBul.js +0 -358
  117. package/dist/assets/crop-Cwf2hMEp.js +0 -1
  118. package/dist/assets/device-picker-model-BqREn4Hm.js +0 -1
  119. package/dist/assets/dist-BBQqVqgg.js +0 -358
  120. package/dist/assets/i18n-B_TdOOX_.js +0 -1
  121. package/dist/assets/icons-GyTqKSGv.js +0 -1
  122. package/dist/assets/index-Df_Bqvin.js +0 -4
  123. package/dist/assets/mount-BqREn4Hm.js +0 -1
  124. package/dist/assets/remoteEntry-C1jeRZii.js +0 -1
  125. package/dist/assets/src-B9Sp1iss.js +0 -67
  126. package/dist/assets/useEventInvalidation-BqREn4Hm.js +0 -1
  127. package/dist/assets/user-round-DKD1XSci.js +0 -1
@@ -1 +1 @@
1
- import{C as e,J as t,K as n,Q as r,R as i,S as a,V as o,Y as s,a as c,et as l,o as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{An as f,Ci as p,D as m,Di as h,Gr as g,Gt as _,In as v,Ir as y,Lt as b,Oi as x,Or as S,Ot as C,Pt as w,Q as T,Qr as E,Qt as D,Si as O,Xt as k,Yt as A,Z as j,ar as M,bi as N,c as P,dt as F,f as I,hn as L,ji as R,jt as z,l as B,na as V,oi as H,ot as U,pn as W,sr as G,u as ee,vr as K,xi as te,xn as q,yn as ne,z as re}from"./player-overlays-BoPcGTkt.js";import{Ra as J,kr as ie,nt as ae}from"./client-xX9FBBul.js";import{a as oe,c as se,i as ce,n as le,o as ue,r as de,s as fe,t as pe}from"./user-x-CPWIU9qV.js";import{c as me}from"./video-BM3o6nmQ.js";import{t as he}from"./crop-Cwf2hMEp.js";import{t as ge}from"./user-round-DKD1XSci.js";import{$n as _e,$r as ve,Ac as ye,Al as be,Cc as xe,Cn as Se,Dc as Ce,Dl as we,Dr as Te,Er as Ee,Fl as De,Il as Oe,Ll as ke,Ml as Ae,Nl as je,Ol as Me,Pl as Ne,Qr as Pe,Rl as Fe,So as Ie,St as Le,Tc as Re,Zr as ze,_r as Be,ac as Ve,ai as He,as as Ue,cs as We,dn as Ge,ds as Ke,ed as qe,ei as Y,fr as Je,fs as Ye,ft as Xe,gn as Ze,gr as Qe,hr as $e,ht as et,id as tt,is as nt,ji as rt,jl as it,kc as at,kd as ot,kl as st,ld as ct,ls as lt,mn as ut,mr as dt,ms as ft,nn as pt,ns as mt,oi as ht,os as gt,pn as _t,ps as vt,pt as yt,rs as bt,si as xt,ss as St,t as Ct,td as wt,ud as Tt,us as Et,vr as Dt,wc as Ot,wn as kt,xc as At,xn as jt,xr as Mt,zl as Nt}from"./src-B9Sp1iss.js";import{t as X}from"./i18n-B_TdOOX_.js";import{t as Z}from"./useTranslation-BJr-n0es.js";import"./mount-BqREn4Hm.js";import{S as Pt,dr as Ft,hr as It,lr as Lt,pr as Rt}from"./index-Df_Bqvin.js";import{t as zt}from"./AdminSectionedPage-Dm8ND20L.js";import{t as Bt}from"./use-stationary-objects-BXlbjYsd.js";import{a as Vt,i as Ht,n as Ut,r as Wt,t as Gt}from"./authed-media-2wArFI8C.js";import{t as Kt}from"./use-scenes-feed-DO_UdVPf.js";l();function qt({mediaId:e,base64:t,alt:n,className:r,placeholder:i}){let{src:o,failed:s}=Vt(e===void 0?void 0:Wt(e));return o===null?(e===void 0||s)&&t!==void 0&&t!==``?a(`img`,{src:`data:image/jpeg;base64,${t}`,alt:n,className:r}):i:a(`img`,{src:o,alt:n,className:r})}var Jt=`pipeline-analytics`,Yt=`photo.analyze`,Xt=`photo.enroll`,Zt=`photo.discard`,Qt=18*1024*1024;function $t(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function en(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function tn(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function nn(e,t){let n=e[t];return typeof n==`boolean`?n:null}function rn(e){if(!$t(e))return null;let t=tn(e,`x`),n=tn(e,`y`),r=tn(e,`width`),i=tn(e,`height`);return t===null||n===null||r===null||i===null?null:{x:t,y:n,width:r,height:i}}function an(e){if(!$t(e))return null;let t=tn(e,`detectionShortSidePx`),n=tn(e,`score`);if(t===null||n===null)return null;let r=tn(e,`magnitude`);return{detectionShortSidePx:t,score:n,...r===null?{}:{magnitude:r}}}function on(e){if(!$t(e))return null;let t=tn(e,`faceIndex`),n=tn(e,`score`),r=nn(e,`enrollable`),i=rn(e.bbox),a=an(e.quality);if(t===null||n===null||r===null||i===null||a===null)return null;let o=en(e,`refusedReason`),s=en(e,`alignedCropBase64`),c=en(e,`modelId`);return{faceIndex:t,bbox:i,score:n,enrollable:r,quality:a,...o===null?{}:{refusedReason:o},...s===null?{}:{alignedCropBase64:s},...c===null?{}:{modelId:c}}}function sn(e){if(!$t(e))return null;let t=en(e,`sessionId`),n=en(e,`ranOnNodeId`),r=e.faces;if(t===null||n===null||!Array.isArray(r))return null;let i=[];for(let e of r){let t=on(e);t!==null&&i.push(t)}return{sessionId:t,ranOnNodeId:n,faces:i}}function cn(e){if(!$t(e))return null;let t=en(e,`sampleId`),n=en(e,`identityId`),r=en(e,`modelId`);return t===null||n===null||r===null?null:{sampleId:t,identityId:n,modelId:r}}function ln(e,t,n){let r={...e};return n===null||n===``?delete r[t]:r[t]=n,r}function un(e,t){return e.filter(e=>e.enrollable&&t[e.faceIndex]!==void 0).length}function dn(e,t,n){let r=[];for(let i of t){if(!i.enrollable)continue;let t=n[i.faceIndex];t!==void 0&&r.push({sessionId:e,faceIndex:i.faceIndex,identityId:t})}return r}function fn(e){switch(e){case`no-embedding`:return X.t(`helpers.photoEnroll.refusal.noEmbedding`);case`no-model-id`:return X.t(`helpers.photoEnroll.refusal.noModelId`);case`no-aligned-crop`:return X.t(`helpers.photoEnroll.refusal.noAlignedCrop`);case`magnitude`:return X.t(`helpers.photoEnroll.refusal.magnitude`);default:return X.t(`helpers.photoEnroll.refusal.default`)}}function pn(e,t){let n=[],r=[];for(let i of e)i.size>t.maxBytes?n.push(i.name):r.push(i);return{accepted:r.slice(0,t.maxCount),oversize:n,overflow:r.slice(t.maxCount).map(e=>e.name)}}async function mn(e,t,n){let r=Array(e.length),i=e.map((e,t)=>({item:e,index:t})),a=0,o=async()=>{for(;;){let e=i[a];if(a+=1,e===void 0)return;r[e.index]=await n(e.item,e.index)}},s=Array.from({length:Math.max(1,Math.min(t,e.length))},()=>o());return await Promise.all(s),r}function hn(e,t,n){return e.map(e=>e.photoIndex===t?{...e,...n}:e)}function gn(e,t){return`${e}:${t}`}function _n(e,t,n,r){let i=ln(e[t]??{},n,r),a={...e};return Object.keys(i).length===0?delete a[t]:a[t]=i,a}function vn(e,t){let n=0;for(let r of e)r.analysis!==void 0&&(n+=un(r.analysis.faces,t[r.photoIndex]??{}));return n}var yn=`__new__`;function bn(e,t,n){let r=[];for(let i of e){if(i.analysis===void 0)continue;let e=t[i.photoIndex]??{};for(let t of i.analysis.faces){if(!t.enrollable||e[t.faceIndex]!==`__new__`)continue;let a=(n[gn(i.photoIndex,t.faceIndex)]??``).trim();if(a===``)return{kind:`error`,message:X.t(`helpers.photoEnrollBatch.newPersonNoName`,{filename:i.filename,face:t.faceIndex+1})};r.includes(a)||r.push(a)}}return{kind:`ok`,names:r}}function xn(e,t,n){let r={};for(let[i,a]of Object.entries(e)){let e=Number(i),o={};for(let[r,i]of Object.entries(a)){let a=Number(r);if(i!==`__new__`){o[a]=i;continue}let s=n[(t[gn(e,a)]??``).trim()];s!==void 0&&(o[a]=s)}r[e]=o}return r}function Sn(e,t){let n=[];for(let r of e){if(r.analysis===void 0)continue;let e=dn(r.analysis.sessionId,r.analysis.faces,t[r.photoIndex]??{});for(let t of e)n.push({photoIndex:r.photoIndex,request:t})}return n}function Cn(e){return/expired/i.test(e)}function wn(e){return e instanceof Error?e.message:String(e)}async function Tn(e,t,n){let r=new Map(e.map(e=>[e.photoIndex,e])),i={},a=[],o=0,s=null,c=(e,t)=>{let n=r.get(e)?.filename??X.t(`helpers.photoEnrollBatch.photoFallback`,{n:e+1});return X.t(`helpers.photoEnrollBatch.faceLabel`,{filename:n,face:t+1})};for(let l of Sn(e,t)){let e=i[l.photoIndex],t=e===void 0?l.request:{...l.request,sessionId:e.sessionId};try{let e=await n.enroll(t);o+=1,s=e.modelId}catch(t){let u=wn(t);if(!Cn(u)||e!==void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${u}`);continue}let d=r.get(l.photoIndex);if(d===void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${u}`);continue}let f;try{f=await n.reanalyze(d)}catch(e){a.push(`${c(l.photoIndex,l.request.faceIndex)}: the analysis expired and re-analysing failed (${wn(e)})`);continue}if(i[l.photoIndex]=f,f.faces.find(e=>e.faceIndex===l.request.faceIndex&&e.enrollable)===void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: the analysis expired, and re-analysing no longer finds this face — assign it again from the fresh result`);continue}try{let e=await n.enroll({...l.request,sessionId:f.sessionId});o+=1,s=e.modelId}catch(e){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${wn(e)}`)}}}return{enrolled:o,stampedModelId:s,failures:a,refreshedAnalyses:i}}var En=[[`faceGallery`]],Dn=``;function On(e){return new Promise((t,n)=>{let r=new FileReader;r.addEventListener(`error`,()=>n(Error(`the file could not be read`)),{once:!0}),r.addEventListener(`load`,()=>{let e=r.result;if(typeof e!=`string`){n(Error(`the file could not be read`));return}let i=e.indexOf(`,`);t(i>=0?e.slice(i+1):e)},{once:!0}),r.readAsDataURL(e)})}function kn(e){return e instanceof Error?e.message:String(e)}function An({face:t,identities:r,value:i,onChange:o,disabled:s}){let{t:c}=Z(),l=n(()=>[{value:Dn,label:c(`detectionIntelligence.photoEnrollDialog.ignoreThisFace`,`Ignore this face`)},...r.map(e=>({value:e.id,label:e.name})),{value:yn,label:c(`detectionIntelligence.photoEnrollDialog.newPerson`,`+ New person…`)}],[r,c]);return e(`div`,{className:`rounded-md border border-border bg-surface p-2`,children:[a(`div`,{className:`mb-2 aspect-square w-full overflow-hidden rounded border border-border bg-surface-hover`,children:t.alignedCropBase64?a(`img`,{src:`data:image/jpeg;base64,${t.alignedCropBase64}`,alt:c(`detectionIntelligence.photoEnrollDialog.face`,`Face {{value1}}`,{value1:t.faceIndex+1}),className:`h-full w-full object-cover`}):a(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:a(ge,{className:`h-8 w-8`})})}),a(`div`,{className:`min-h-[4.75rem]`,children:t.enrollable?e(d,{children:[a(tt,{options:l,value:i,disabled:s,onChange:e=>o(e.target.value),"aria-label":c(`detectionIntelligence.photoEnrollDialog.assignFace`,`Assign face {{value1}}`,{value1:t.faceIndex+1})}),e(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:[Math.round(t.quality.detectionShortSidePx),` px`,t.modelId?` · ${t.modelId}`:``]})]}):e(`div`,{className:`space-y-1`,children:[a(xt,{variant:`warning`,className:`text-[10px]`,children:c(`detectionIntelligence.photoEnrollDialog.notUsable`,`Not usable`)}),a(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:fn(t.refusedReason)})]})})]})}function jn({photo:t,identities:n,draft:r,newNames:i,disabled:o,onAssign:s,onNameChange:c,onRetry:l}){let{t:u}=Z(),d=t.analysis?.faces??[],f=r[t.photoIndex]??{};return e(`div`,{className:`space-y-2`,children:[e(`div`,{className:`flex items-center gap-2 border-b border-border pb-1`,children:[a(`span`,{className:`truncate text-xs font-medium text-foreground`,children:t.filename}),t.status===`analyzing`||t.status===`queued`?e(`span`,{className:`flex items-center gap-1 text-xs text-foreground-subtle`,children:[a(G,{className:`h-3 w-3 animate-spin`}),` `,u(`detectionIntelligence.photoEnrollDialog.analysing`)]}):null,t.status===`analyzed`&&t.analysis!==void 0&&a(`span`,{className:`text-xs text-foreground-subtle`,children:u(`detectionIntelligence.photoEnrollDialog.facesAnalysedOn`,{count:d.length,node:t.analysis.ranOnNodeId})}),t.status===`failed`&&e(Y,{variant:`secondary`,size:`sm`,disabled:o,onClick:l,children:[a(ne,{className:`h-3 w-3`}),` `,u(`common.retry`)]})]}),t.status===`failed`&&e(`div`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[a(w,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),e(`span`,{children:[u(`detectionIntelligence.photoEnrollDialog.thisPhotoCouldNotBe`,`This photo could not be analysed:`),` `,t.error??u(`detectionIntelligence.photoEnrollDialog.unknownError`,`unknown error`),`. The other photos are unaffected.`]})]}),t.status===`analyzed`&&d.length===0&&a(`p`,{className:`text-xs text-foreground-subtle`,children:u(`detectionIntelligence.photoEnrollDialog.noFacesWereFoundIn`,`No faces were found in this photo. A face has to be reasonably large and facing the camera for the detector to measure it.`)}),d.length>0&&a(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(7rem,7rem))] justify-start gap-3`,children:d.map(e=>a(An,{face:e,identities:n,value:f[e.faceIndex]??Dn,disabled:o,onChange:t=>s(e.faceIndex,t)},e.faceIndex))}),d.filter(e=>f[e.faceIndex]===yn).map(n=>e(`div`,{className:`flex items-center gap-2`,children:[a(`span`,{className:`w-28 shrink-0 truncate text-xs text-foreground-subtle`,children:u(`detectionIntelligence.photoEnrollDialog.faceN`,{n:n.faceIndex+1})}),a(`input`,{className:`h-7 flex-1 rounded-md border border-border bg-surface px-2.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,placeholder:u(`detectionIntelligence.photoEnrollDialog.newPersonNameTypeThe`,`New person name… (type the same name under another face to reuse it)`),value:i[gn(t.photoIndex,n.faceIndex)]??``,onChange:e=>c(n.faceIndex,e.target.value)})]},n.faceIndex))]})}function Mn({open:r,onOpenChange:o}){let{t:c}=Z(),l=U(),d=u(),f=t(null),{data:p}=St(),m=bt(),[h,g]=s([]),[_,v]=s(!1),[y,b]=s(null),[x,S]=s({}),[C,T]=s({}),[E,D]=s(null),O=n(()=>(p??[]).map(e=>({id:e.id,name:e.name})),[p]),k=h.some(e=>e.status===`queued`||e.status===`analyzing`),A=k||_,j=i(e=>{for(let t of e){let e=t.analysis?.sessionId;e!==void 0&&l.trpcClient.addons.custom.mutate({addonId:Jt,action:Zt,input:{sessionId:e}}).catch(()=>void 0)}},[l]),M=i(()=>{g([]),S({}),T({}),b(null),D(null),f.current&&(f.current.value=``)},[]),N=i(()=>{j(h),M(),o(!1)},[j,o,h,M]),P=i(async e=>{let t=sn(await l.trpcClient.addons.custom.mutate({addonId:Jt,action:Yt,input:{photoBase64:e.photoBase64,filename:e.filename}}));if(t===null)throw Error(`the server replied with something this page could not read`);return t},[l]),F=i(async e=>{g(t=>hn(t,e.photoIndex,{status:`analyzing`,error:void 0}));try{let t=await P(e);g(n=>hn(n,e.photoIndex,{status:`analyzed`,analysis:t}))}catch(t){g(n=>hn(n,e.photoIndex,{status:`failed`,error:kn(t)}))}},[P]),I=i(async e=>{if(e.length===0)return;j(h),M();let t=pn(e,{maxCount:12,maxBytes:Qt}),n=[];t.oversize.length>0&&n.push(`Over the ${Math.round(Qt/(1024*1024))} MB limit and skipped: ${t.oversize.join(`, `)}.`),t.overflow.length>0&&n.push(`A batch holds at most 12 photos — not analysed: ${t.overflow.join(`, `)}. Enrol them in a second round.`),n.length>0&&b(n.join(` `));let r;try{r=await Promise.all(t.accepted.map(async(e,t)=>({photoIndex:t,filename:e.name,photoBase64:await On(e),status:`queued`})))}catch(e){b(kn(e));return}g(r),await mn(r,2,e=>F(e))},[j,h,M,F]),L=vn(h,x),R=i(async()=>{v(!0),b(null),D(null);try{let e=bn(h,x,C);if(e.kind===`error`){b(e.message);return}let t={};for(let n of e.names)t[n]=(await m.mutateAsync({name:n})).id;let n=await Tn(h,xn(x,C,t),{enroll:async e=>{let t=cn(await l.trpcClient.addons.custom.mutate({addonId:Jt,action:Xt,input:e}));if(t===null)throw Error(`unreadable reply`);return t},reanalyze:e=>P(e)});Object.keys(n.refreshedAnalyses).length>0&&g(e=>e.map(e=>{let t=n.refreshedAnalyses[e.photoIndex];return t===void 0?e:{...e,status:`analyzed`,analysis:t}})),d.invalidateQueries({queryKey:En}),n.failures.length>0&&b(n.failures.join(` · `)),D(n.enrolled===0?`Nothing was enrolled.`:`Enrolled ${n.enrolled} sample${n.enrolled===1?``:`s`}${n.stampedModelId===null?``:` with ${n.stampedModelId}`}.`)}catch(e){b(kn(e))}finally{v(!1)}},[P,m,x,C,h,d,l]),z=h.filter(e=>e.status===`analyzed`).length;return a(Je,{open:r,onOpenChange:e=>e?o(!0):N(),children:e(dt,{className:`max-w-3xl`,children:[e(Be,{children:[a(Dt,{children:c(`detectionIntelligence.photoEnrollDialog.enrolFromPhotos`,`Enrol from photos`)}),a($e,{children:c(`detectionIntelligence.photoEnrollDialog.everyPhotoIsAnalysedWith`,`Every photo is analysed with the same face detector the cameras use, and all the faces found are reviewed below in one pass, grouped by photo. Assign each face to a person, or leave it ignored.`)})]}),a(`div`,{className:`rounded-md border border-border bg-surface-hover px-3 py-2 text-xs text-foreground-subtle`,children:a(Lt,{i18nKey:`detectionIntelligence.photoEnrollDialog.reliableRecognition`,components:{strong:a(`strong`,{})}})}),e(`div`,{className:`flex items-center gap-2`,children:[a(`input`,{ref:f,type:`file`,accept:`image/jpeg,image/png,image/webp`,multiple:!0,className:`hidden`,onChange:e=>void I(Array.from(e.target.files??[]))}),e(Y,{variant:`secondary`,size:`sm`,disabled:A,onClick:()=>f.current?.click(),children:[k?a(G,{className:`h-3.5 w-3.5 animate-spin`}):a(ue,{className:`h-3.5 w-3.5`}),c(`detectionIntelligence.photoEnrollDialog.choosePhotos`,`Choose photos`)]}),h.length>0&&a(`span`,{className:`text-xs text-foreground-subtle`,children:c(`detectionIntelligence.photoEnrollDialog.photosAnalysed`,{done:z,count:h.length})})]}),a(`div`,{className:`min-h-11`,"aria-live":`polite`,children:y===null?E===null?null:a(`div`,{className:`rounded-md border border-success/40 bg-success/10 px-3 py-2 text-xs text-success`,children:E}):e(`div`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[a(w,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),a(`span`,{children:y})]})}),h.length>0&&a(`div`,{className:`max-h-[50vh] space-y-4 overflow-y-auto pr-1`,children:h.map(e=>a(jn,{photo:e,identities:O,draft:x,newNames:C,disabled:A,onAssign:(t,n)=>S(r=>_n(r,e.photoIndex,t,n===Dn?null:n)),onNameChange:(t,n)=>T(r=>({...r,[gn(e.photoIndex,t)]:n})),onRetry:()=>void F(e)},e.photoIndex))}),e(Qe,{children:[a(Y,{variant:`secondary`,onClick:N,disabled:_,children:c(`common.close`,`Close`)}),e(Y,{variant:`primary`,onClick:()=>void R(),disabled:A||L===0,children:[_?a(G,{className:`h-3.5 w-3.5 animate-spin`}):null,c(`detectionIntelligence.photoEnrollDialog.enrolFaces`,{count:L})]})]})]})})}l();var Nn=[[`faceGallery`]];function Pn({identityId:t}){let{t:n}=Z(),r=u(),{data:i,isLoading:o}=We({identityId:t}),s=Et();function c(e){s.mutate({identityId:t,sampleId:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:Nn})}})}return o?e(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[a(G,{className:`h-3.5 w-3.5 animate-spin`}),n(`detectionIntelligence.peopleList.loadingSamples`,`Loading samples…`)]}):!i||i.length===0?a(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:n(`detectionIntelligence.peopleList.noSamplesYet`,`No samples yet.`)}):a(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:i.map(t=>e(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[t.base64?a(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:n(`detectionIntelligence.peopleList.sample`,`Sample`),className:`h-full w-full object-cover`}):a(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:a(ge,{className:`h-6 w-6`})}),t.source===`photo`&&a(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 p-0.5 text-white`,title:n(`detectionIntelligence.peopleList.enrolledFromAnUploadedPhoto`,`Enrolled from an uploaded photo`),children:a(ue,{className:`h-3 w-3`})}),a(`button`,{type:`button`,onClick:()=>c(t),disabled:s.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":n(`detectionIntelligence.peopleList.removeSample`,`Remove sample`),children:a(F,{className:`h-4 w-4 text-white`})})]},t.id))})}function Fn(t){return[{key:`person`,header:X.t(`detectionIntelligence.peopleList.person`,`Person`),sortValue:e=>e.name,render:t=>e(`span`,{className:`flex min-w-0 items-center gap-2`,children:[a(`span`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:a(qt,{mediaId:t.coverMediaId,base64:t.coverBase64,alt:t.name,className:`h-full w-full object-cover`,placeholder:a(`span`,{className:`flex h-full w-full items-center justify-center`,children:a(ge,{className:`h-4 w-4 text-foreground-subtle`})})})}),a(`span`,{className:`truncate text-sm font-medium text-foreground`,children:t.name})]})},{key:`samples`,header:X.t(`detectionIntelligence.peopleList.samples`,`Samples`),align:`center`,nowrap:!0,sortValue:e=>e.sampleCount,render:e=>a(xt,{variant:`default`,className:`text-[10px]`,children:e.sampleCount})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:n=>e(`span`,{className:`flex items-center justify-end gap-1`,children:[a(Tt,{variant:`ghost`,size:`sm`,icon:v,"aria-label":X.t(`detectionIntelligence.peopleList.edit`,`Edit {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onEdit(n)}}),a(Tt,{variant:`ghost`,size:`sm`,icon:b,"aria-label":X.t(`detectionIntelligence.peopleList.delete`,`Delete {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onDelete(n)}})]})}]}function In({mode:t,identity:n,onClose:r}){let{t:i}=Z(),c=u(),[l,d]=s(t===`edit`?n?.name??``:``),f=bt(),p=Ke();o(()=>{d(t===`edit`?n?.name??``:``)},[t,n?.id,n?.name]);let m=f.isPending||p.isPending,h=l.trim(),g=t===`edit`&&n!==null&&h===n.name,_=m||h.length===0||g;function v(){c.invalidateQueries({queryKey:Nn})}function y(){if(!_){if(t===`new`){f.mutate({name:h},{onSuccess:()=>{v(),r()}});return}if(n===null){r();return}p.mutate({id:n.id,name:h},{onSuccess:()=>{v(),r()}})}}return a(et,{open:!0,onClose:r,title:t===`new`?`Add person`:`Edit ${n?.name??`person`}`,icon:ge,width:t===`edit`?`xl`:`lg`,testId:`people-person-form`,footer:e(Y,{variant:`primary`,size:`sm`,type:`button`,onClick:y,disabled:_,children:[m?a(G,{className:`h-3.5 w-3.5 animate-spin`}):null,t===`new`?i(`common.add`,`Add`):i(`common.save`,`Save`)]}),children:e(`div`,{className:`space-y-4`,children:[a(Le,{label:i(`detectionIntelligence.peopleList.name`,`Name`),required:!0,children:a(ct,{value:l,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&y()},placeholder:i(`detectionIntelligence.peopleList.personName`,`Person name…`),autoFocus:!0})}),t===`edit`&&n!==null&&e(`div`,{children:[a(`p`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:i(`detectionIntelligence.peopleList.trainingSamples`,`Training samples`)}),a(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:i(`detectionIntelligence.peopleList.removeASampleToDrop`,`Remove a sample to drop it from recognition training for this person.`)}),a(Pn,{identityId:n.id})]})]})})}function Ln(){let{t}=Z(),r=u(),i=Pe(),{data:c,isLoading:l}=St(),d=Ue(),{state:p,openNew:m,openEdit:h,close:g}=yt(),[_,v]=s(!1),y=c??[],b=_t(y,{searchText:e=>[e.name]}),x=p.mode===`edit`?y.find(e=>e.id===p.id)??null:null;o(()=>{p.mode===`edit`&&!l&&x===null&&g()},[p.mode,l,x,g]);let S=n(()=>Fn({onEdit:e=>h(e.id),onDelete:e=>{(async()=>{await i({title:t(`detectionIntelligence.peopleList.deletePerson`,`Delete person`),message:t(`detectionIntelligence.peopleList.deleteAndAllTheirSamples`,`Delete {{name}} and all their samples? This cannot be undone.`,{name:e.name}),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&d.mutate({id:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:Nn}),p.mode===`edit`&&p.id===e.id&&g()}})})()}}),[i,g,d,p,h,r,t]);if(l)return e(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[a(G,{className:`h-4 w-4 animate-spin`}),t(`detectionIntelligence.peopleList.loadingPeople`,`Loading people…`)]});let C=p.mode===`new`||p.mode===`edit`&&x!==null;return e(`div`,{className:`space-y-2`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(Y,{variant:`primary`,size:`sm`,type:`button`,onClick:m,children:[a(f,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.peopleList.addPerson`,`Add person`)]}),e(Y,{variant:`secondary`,size:`sm`,type:`button`,onClick:()=>v(!0),children:[a(ue,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.peopleList.enrolFromAPhoto`,`Enrol from a photo`)]})]}),(y.length>0||b.active)&&a(ut,{state:b.state,facets:b.facets,labels:{searchPlaceholder:`Search people…`,searchLabel:`Search people`,facetsLabel:`Filter`,clearLabel:`Clear`},onSearch:b.setSearch,onToggleFacet:b.toggleFacet,onClear:b.clear}),b.rows.length===0?a(Te,{icon:ge,title:b.active?t(`detectionIntelligence.peopleList.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.peopleList.noPeopleEnrolledYet`,`No people enrolled yet`),description:b.active?t(`detectionIntelligence.peopleList.clearTheSearchOrTry`,`Clear the search or try another name.`):t(`detectionIntelligence.peopleList.addAPersonOrEnrol`,`Add a person, or enrol faces from a photo.`)}):a(Se,{columns:S,rows:b.rows,rowKey:e=>e.id,maxBodyHeight:kt,emptyMessage:t(`detectionIntelligence.peopleList.noPeopleEnrolledYet2`,`No people enrolled yet.`),onRowClick:e=>h(e.id)}),C&&a(In,{mode:p.mode===`new`?`new`:`edit`,identity:x,onClose:g}),a(Mn,{open:_,onOpenChange:v})]})}var Rn={fromMs:null,toMs:null},zn=36e5,Bn=24*zn;function Vn(e,t){switch(e){case`24h`:return{fromMs:t-Bn,toMs:null};case`7d`:return{fromMs:t-7*Bn,toMs:null};case`30d`:return{fromMs:t-30*Bn,toMs:null};case`all`:return Rn}}function Hn(e){return e.fromMs!==null||e.toMs!==null}function Un(e,t){return Hn(t)?e.filter(e=>!(t.fromMs!==null&&e.timestamp<t.fromMs||t.toMs!==null&&e.timestamp>t.toMs)):[...e]}function Wn(e,t){return t.size===0?[...e]:e.filter(e=>t.has(e.deviceId))}function Gn(e){let t=new Set,n=[];for(let r of e)t.has(r.deviceId)||(t.add(r.deviceId),n.push(r.deviceId));return n}function Kn(e){if(!e)return null;let t=Date.parse(`${e}T00:00:00`);return Number.isNaN(t)?null:t}function qn(e){if(!e)return null;let t=Date.parse(`${e}T23:59:59.999`);return Number.isNaN(t)?null:t}function Jn(e,t){if(!Number.isFinite(e)||e<=0)return`—`;let n=t-e;return n<6e4?X.t(`helpers.relativeTime.justNow`):n<zn?X.t(`helpers.relativeTime.minutesAgo`,{count:Math.floor(n/6e4)}):n<Bn?X.t(`helpers.relativeTime.hoursAgo`,{count:Math.floor(n/zn)}):n<7*Bn?X.t(`helpers.relativeTime.daysAgo`,{count:Math.floor(n/Bn)}):new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function Yn(e){return!Number.isFinite(e)||e<=0?`—`:new Date(e).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function Xn(e){return!Number.isFinite(e)||e<=0?`—`:new Date(e).toLocaleString(void 0,{year:`numeric`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function Zn(e){let t=e.cropUrl!==void 0&&e.cropUrl.length>0,n=e.base64!==void 0&&e.base64.length>0;return!t&&!n}function Qn(e){return e.filter(Zn).map(e=>e.faceId)}function $n(e){let t=0;for(let n of e)Zn(n)&&(t+=1);return t}function er(e){return e==null?null:e.cropUrl!==void 0&&e.cropUrl.length>0?e.cropUrl:e.base64!==void 0&&e.base64.length>0?`data:image/jpeg;base64,${e.base64}`:null}l();function tr(e,t,r){let[i,a]=s(1);o(()=>{a(1)},[r]);let c=e.length,l=Math.max(1,Math.ceil(c/t)),u=Math.min(i,l);return o(()=>{u!==i&&a(u)},[u,i]),{page:u,setPage:a,pageItems:n(()=>{let n=(u-1)*t;return e.slice(n,n+t)},[e,u,t]),totalPages:l,totalItems:c,pageSize:t}}var nr=2;function rr(e,t){if(t<=1)return[{kind:`page`,n:1}];if(t<=7){let e=[];for(let n=1;n<=t;n++)e.push({kind:`page`,n});return e}let n=[],r=Math.max(2,e-nr),i=Math.min(t-1,e+nr);n.push({kind:`page`,n:1}),r>2&&n.push({kind:`ellipsis`,side:`left`});for(let e=r;e<=i;e++)n.push({kind:`page`,n:e});return i<t-1&&n.push({kind:`ellipsis`,side:`right`}),n.push({kind:`page`,n:t}),n}function ir({currentPage:t,totalItems:n,pageSize:r,onPageChange:i,itemNoun:o=`items`}){let{t:s}=Z();if(n<=r)return null;let c=Math.ceil(n/r),l=(t-1)*r+1,u=Math.min(t*r,n),d=rr(t,c),f=`inline-flex h-7 min-w-7 items-center justify-center rounded-md px-2 text-[11px] transition-colors disabled:opacity-40`;return e(`div`,{className:`flex items-center justify-between gap-4 flex-wrap pt-2 text-[11px] text-foreground-subtle`,children:[a(`span`,{children:s(`galleryPager.showing`,{from:l,to:u,total:n,noun:o})}),e(`div`,{className:`flex items-center gap-1`,children:[a(`button`,{type:`button`,className:`${f} hover:bg-surface-hover`,onClick:()=>i(t-1),disabled:t<=1,"aria-label":s(`galleryPager.previousPage`,`Previous page`),children:a(te,{className:`h-3.5 w-3.5`})}),d.map(e=>e.kind===`ellipsis`?a(`span`,{className:`px-1 opacity-60`,children:`…`},`ellipsis-${e.side}`):a(`button`,{type:`button`,className:`${f} ${e.n===t?`bg-primary/12 text-primary font-medium`:`hover:bg-surface-hover hover:text-foreground`}`,onClick:()=>i(e.n),"aria-current":e.n===t?`page`:void 0,children:e.n},e.n)),a(`button`,{type:`button`,className:`${f} hover:bg-surface-hover`,onClick:()=>i(t+1),disabled:t>=c,"aria-label":s(`galleryPager.nextPage`,`Next page`),children:a(N,{className:`h-3.5 w-3.5`})})]})]})}l();var ar=[[`faceGallery`]];function or({faceIds:t,identities:n,onDone:r}){let{t:i}=Z(),o=u(),c=mt(),l=bt(),[d,f]=s(``),[p,m]=s(!1),[h,g]=s(null),_=t!==null&&t.length>0,v=t?.length??0;function y(){m(!1),f(``),g(null)}function b(){y(),r()}function x(e){!t||t.length===0||c.mutate({faceIds:[...t],identityId:e},{onSettled:()=>{o.invalidateQueries({queryKey:ar}),b()}})}function S(){!t||!d.trim()||l.mutate({name:d.trim()},{onSuccess:e=>{e?.id&&x(e.id)},onError:()=>{o.invalidateQueries({queryKey:ar}),b()}})}let C=c.isPending||l.isPending;return a(Je,{open:_,onOpenChange:e=>!e&&b(),children:e(dt,{children:[e(Be,{children:[a(Dt,{children:v>1?i(`detectionIntelligence.assignDialog.assignFacesToPerson`,`Assign {{value1}} faces to person`,{value1:String(v)}):i(`detectionIntelligence.assignDialog.assignFaceToPerson`,`Assign face to person`)}),a($e,{children:i(`detectionIntelligence.assignDialog.selectAnExistingPersonOr`,`Select an existing person or create a new one.`)})]}),a(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:n.map(t=>e(`button`,{type:`button`,onClick:()=>g(t.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${h===t.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[a(`span`,{className:`font-medium`,children:t.name}),a(`span`,{className:`ml-2 text-foreground-subtle`,children:i(`detectionIntelligence.assignDialog.samples`,{count:t.sampleCount})})]},t.id))}),a(`div`,{className:`min-h-[2.75rem] border-t border-border pt-2`,children:p?a(`div`,{className:`flex items-center gap-2`,children:a(ct,{placeholder:i(`detectionIntelligence.assignDialog.newPersonName`,`New person name…`),value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&S()},autoFocus:!0,className:`flex-1`})}):a(`button`,{type:`button`,onClick:()=>{g(null),m(!0)},className:`w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle transition-colors hover:border-primary hover:text-primary`,children:i(`detectionIntelligence.assignDialog.newPerson`,`+ New person…`)})}),e(Qe,{className:`min-h-[2.75rem]`,children:[a(Y,{variant:`secondary`,onClick:b,disabled:C,children:i(`common.cancel`,`Cancel`)}),p?e(Y,{variant:`primary`,onClick:S,disabled:C||!d.trim(),children:[C&&a(G,{className:`h-3.5 w-3.5 animate-spin`}),i(`detectionIntelligence.assignDialog.createAssign`,`Create & assign`)]}):e(Y,{variant:`primary`,onClick:()=>h&&x(h),disabled:C||!h,children:[C&&a(G,{className:`h-3.5 w-3.5 animate-spin`}),v>1?i(`detectionIntelligence.assignCount`,{count:v}):i(`common.assign`)]})]})]})})}l();function sr({cameras:n,selected:r,onChange:i}){let{t:c}=Z(),[l,u]=s(!1),d=t(null);o(()=>{if(!l)return;function e(e){d.current&&e.target instanceof Node&&!d.current.contains(e.target)&&u(!1)}function t(e){e.key===`Escape`&&u(!1)}return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[l]);function f(e){let t=new Set(r);t.has(e)?t.delete(e):t.add(e),i(t)}let m=r.size,h=m===0?`All cameras`:m===1?n.find(e=>r.has(e.id))?.name??`1 camera`:`${String(m)} cameras`;return e(`div`,{ref:d,className:`relative`,children:[e(`button`,{type:`button`,onClick:()=>u(e=>!e),disabled:n.length===0,className:`flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs transition-colors disabled:opacity-40 ${m>0?`border-primary/40 bg-primary/8 text-primary`:`border-border text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(x,{className:`h-3.5 w-3.5`}),a(`span`,{className:`max-w-[10rem] truncate`,children:h}),a(O,{className:`h-3 w-3 opacity-70`})]}),l&&e(`div`,{className:`absolute left-0 z-30 mt-1 max-h-64 w-[min(15rem,calc(100vw-1.5rem))] overflow-y-auto rounded-md border border-border bg-surface p-1 shadow-lg shadow-black/30`,children:[m>0&&a(`button`,{type:`button`,onClick:()=>i(new Set),className:`mb-1 w-full rounded px-2 py-1 text-left text-[11px] text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:c(`detectionIntelligence.cameraMultiSelect.clearSelection`,`Clear selection`)}),n.map(t=>{let n=r.has(t.id);return e(`button`,{type:`button`,onClick:()=>f(t.id),className:`flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-xs transition-colors ${n?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[a(`span`,{className:`flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded-sm border ${n?`border-primary bg-primary text-white`:`border-border`}`,children:n&&a(p,{className:`h-2.5 w-2.5`})}),a(`span`,{className:`truncate`,children:t.name})]},t.id)})]})]})}l();var cr=[{label:`24h`,value:`24h`},{label:`7d`,value:`7d`},{label:`30d`,value:`30d`},{labelKey:`common.all`,value:`all`}];function lr({onChange:t}){let{t:n}=Z(),[r,i]=s(`all`),[o,c]=s(``),[l,u]=s(``);function d(e){i(e),c(``),u(``),t(Vn(e,Date.now()))}function f(e,n){i(`custom`),c(e),u(n),t({fromMs:Kn(e),toMs:qn(n)})}let p=`rounded-md border border-border bg-surface px-2 py-1.5 text-[11px] text-foreground outline-none focus:border-primary [color-scheme:light] dark:[color-scheme:dark]`;return e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[a(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:cr.map(e=>a(`button`,{type:`button`,onClick:()=>d(e.value),className:`rounded px-2.5 py-1 text-[11px] transition-colors ${r===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.labelKey===void 0?e.label:n(e.labelKey)},e.value))}),e(`div`,{className:`flex items-center gap-1`,children:[a(`input`,{type:`date`,"aria-label":n(`detectionIntelligence.dateRangeFilter.fromDate`,`From date`),value:o,max:l||void 0,onChange:e=>f(e.target.value,l),className:`${p} ${r===`custom`&&o?`border-primary/50`:``}`}),a(`span`,{className:`text-[11px] text-foreground-subtle`,children:`→`}),a(`input`,{type:`date`,"aria-label":n(`detectionIntelligence.dateRangeFilter.toDate`,`To date`),value:l,min:o||void 0,onChange:e=>f(o,e.target.value),className:`${p} ${r===`custom`&&l?`border-primary/50`:``}`})]})]})}function ur(e){return e<0?0:e>1?1:e}function dr(e,t,n){if(!Number.isFinite(t)||!Number.isFinite(n)||t<=0||n<=0)return null;let r=ur(e.x/t),i=ur(e.y/n),a=ur((e.x+e.w)/t),o=ur((e.y+e.h)/n);return{x:r,y:i,width:Math.max(0,a-r),height:Math.max(0,o-i)}}l();var fr=2.6;function pr({src:t,alt:n,className:r,overlay:i,fit:c=`contain`}){let[l,u]=s(!1),[d,f]=s(`50% 50%`);o(()=>{u(!1),f(`50% 50%`)},[t]);function p(e){if(!l){let t=e.currentTarget.getBoundingClientRect(),n=(e.clientX-t.left)/t.width*100,r=(e.clientY-t.top)/t.height*100;f(`${String(n)}% ${String(r)}%`)}u(e=>!e)}let m=c===`natural`;return a(`div`,{className:`relative overflow-hidden bg-background ${r??``}`,onClick:p,children:e(`div`,{className:`relative select-none transition-transform duration-200 ease-out ${m?`w-full`:`h-full w-full`} ${l?`cursor-zoom-out`:`cursor-zoom-in`}`,style:{transformOrigin:d,transform:l?`scale(${String(fr)})`:`scale(1)`},children:[a(`img`,{src:t,alt:n,draggable:!1,className:m?`block h-auto w-full object-contain`:`h-full w-full object-contain`}),i]})})}l();function mr(e){let[t,n]=s(null),[r,i]=s(null),[a,c]=s(!1);return o(()=>{if(n(null),i(null),c(!1),e===void 0)return;let t=!1,r=null;return(async()=>{try{let i=await Ut(Wt(e));if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||c(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),o(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>c(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function hr(e){let t=e.filter(e=>e.url.length>0);return t.length===0?null:t.find(e=>/crop|face/i.test(e.kind))??t[0]}function gr({label:t,value:n}){return e(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[a(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:t}),a(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground`,children:n})]})}function _r({box:e}){let{t}=Z();return a(`div`,{className:`pointer-events-none absolute rounded-[3px] border-2 border-primary shadow-[0_0_0_9999px_rgba(0,0,0,0.28)]`,style:{left:`${String(e.x*100)}%`,top:`${String(e.y*100)}%`,width:`${String(e.width*100)}%`,height:`${String(e.height*100)}%`},children:a(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:t(`detectionIntelligence.faceDetailPanel.face`,`Face`)})})}function vr({face:t,cameraName:r,onClose:i,onAssign:o,onUnassign:c,onDelete:l,actionsPending:u}){let{t:d}=Z(),{data:f,isFetching:p}=gt({faceId:t?.faceId??``},{enabled:t!==null}),[m,h]=s(`frame`),{frameSrc:g,naturalWidth:_,naturalHeight:v,failed:y}=mr(t?.keyFrameMediaId),x=n(()=>{let e=hr(f??[]);return e?e.url:er(t)},[f,t]),S=n(()=>!t?.faceBbox||_===null||v===null?null:dr(t.faceBbox,_,v),[t?.faceBbox,_,v]);if(t===null)return null;let w=t.keyFrameMediaId!==void 0&&!y,T=w&&m===`frame`,E=t.assigned?t.identityName??`Assigned`:t.recognizedIdentityId?`${t.identityName??`Recognized`} (suggested)`:`Unassigned`;return a(Je,{open:!0,onOpenChange:e=>!e&&i(),children:e(dt,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":d(`detectionIntelligence.faceDetailPanel.faceDetail`,`Face detail`),className:`flex max-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: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:[a(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:e(`div`,{className:`min-w-0`,children:[a(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:d(`detectionIntelligence.faceDetailPanel.faceDetail`,`Face detail`)}),a(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:r})]})}),e(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[w&&e(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[e(`button`,{type:`button`,onClick:()=>h(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${m===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(L,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.fullFrame`)]}),e(`button`,{type:`button`,onClick:()=>h(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${m===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(he,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.crop`)]})]}),T&&g?a(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:a(pr,{src:g,alt:d(`detectionIntelligence.faceDetailPanel.fullFrameWithDetectedFace`,`Full frame with detected face`),fit:`natural`,className:`w-full`,overlay:S?a(_r,{box:S}):void 0})}):x?e(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[a(pr,{src:x,alt:d(`detectionIntelligence.faceDetailPanel.detectedFace`,`Detected face`),className:`h-full w-full`}),p&&a(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:a(G,{className:`h-3.5 w-3.5 animate-spin`})})]}):e(`div`,{className:`flex aspect-square w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[a(K,{className:`h-8 w-8 text-warning/70`}),a(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:d(`detectionIntelligence.faceDetailPanel.noImage`,`No image`)}),a(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:d(`detectionIntelligence.faceDetailPanel.theCropMediaForThis`,`The crop media for this face could not be resolved (a pre-fix orphan). Safe to delete.`)})]}),e(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[a(gr,{label:d(`detectionIntelligence.faceDetailPanel.camera`,`Camera`),value:r}),a(gr,{label:d(`detectionIntelligence.faceDetailPanel.captured`,`Captured`),value:Xn(t.timestamp)}),a(gr,{label:d(`detectionIntelligence.faceDetailPanel.track`,`Track`),value:t.trackId}),a(gr,{label:d(`detectionIntelligence.faceDetailPanel.identity`,`Identity`),value:E})]})]}),e(`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:[t.assigned?e(Y,{variant:`secondary`,onClick:()=>c(t.faceId),disabled:u,children:[a(pe,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.detach`)]}):e(Y,{variant:`primary`,onClick:()=>o(t.faceId),disabled:u,children:[a(C,{className:`h-3.5 w-3.5`}),` `,d(`common.assign`)]}),e(Y,{variant:`secondary`,onClick:()=>l(t.faceId),disabled:u,children:[a(b,{className:`h-3.5 w-3.5`}),` `,d(`common.delete`)]})]})]})})}function yr(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function br(e,t){return e.faceIds.filter(e=>!t.has(e))}function xr(e,t){return e.faceIds.filter(e=>t(e))}l();var Sr=[[`faceGallery`]],Cr=20,wr=.3,Tr=.9,Er=.05,Dr=.5,Or=2,kr=10,Ar=2;function jr({cluster:t,face:n,active:r,onSelect:i}){let{t:o}=Z(),s=er(n);return e(`button`,{type:`button`,onClick:i,className:`flex shrink-0 flex-col items-center gap-1.5 rounded-md border p-2 text-center transition-colors md:w-full md:flex-row md:gap-2.5 md:text-left ${r?`border-primary bg-primary/8`:`border-border bg-surface hover:bg-surface-hover`}`,children:[a(`div`,{className:`h-24 w-24 shrink-0 overflow-hidden rounded bg-surface-hover`,children:s===null?a(K,{className:`h-24 w-24 p-6 text-foreground-subtle`}):a(`img`,{src:s,alt:``,loading:`lazy`,decoding:`async`,className:`h-24 w-24 object-cover`})}),a(`span`,{className:`w-24 text-[11px] leading-tight text-foreground-subtle md:w-auto`,children:o(`detectionIntelligence.similarGroupsModal.clusterMeta`,{count:t.size,percent:Math.round(t.cohesion*100)})})]})}function Mr({face:t,cameraName:n,nowMs:r,excluded:i,onToggleExclude:o,onDelete:s,deletePending:c}){let{t:l}=Z(),u=er(t);return e(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden transition-opacity ${i?`border-border opacity-40 grayscale`:`border-border`}`,children:[e(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[u===null?e(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,children:[a(K,{className:`h-7 w-7 text-warning/70`}),a(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:l(`detectionIntelligence.similarGroupsModal.noCrop`,`No crop`)})]}):a(pr,{src:u,alt:l(`detectionIntelligence.similarGroupsModal.faceFrom`,`Face from {{cameraName}}`,{cameraName:n}),className:`h-full w-full`}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o()},className:`absolute right-1 top-1 z-10 rounded-full bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?l(`detectionIntelligence.similarGroupsModal.includeFace`,`Include face`):l(`detectionIntelligence.similarGroupsModal.excludeFace`,`Exclude face`),title:i?l(`detectionIntelligence.similarGroupsModal.include`,`Include`):l(`detectionIntelligence.similarGroupsModal.exclude`,`Exclude`),children:a(i?z:F,{className:`h-3.5 w-3.5`})})]}),e(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[a(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:n,children:n}),a(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:Jn(t.timestamp,r)})]}),a(`div`,{className:`mt-1 flex min-h-[2rem] items-center justify-end border-t border-border/60 px-1 py-0.5`,children:a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s()},disabled:c,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":l(`detectionIntelligence.similarGroupsModal.deleteFace`,`Delete face`),title:l(`detectionIntelligence.similarGroupsModal.deleteFace`,`Delete face`),children:c?a(G,{className:`h-4 w-4 animate-spin`}):a(b,{className:`h-4 w-4`})})})]})}function Nr({open:t,onClose:r,byId:i,cameraName:c,nowMs:l,identities:f,selectMany:p}){let{t:m}=Z(),h=u(),g=Pe(),_=nt(),[v,y]=s(Dr),[b,x]=s(Ar),[S,w]=s(null),[T,E]=s({}),[O,k]=s(null),{data:A,isFetching:j,refetch:M}=Ye({threshold:v,minClusterSize:b,limit:Cr},{enabled:t}),N=A??[];o(()=>{E({})},[v,b]),o(()=>{if(N.length===0){w(null);return}N.some(e=>e.representativeFaceId===S)||w(N[0]?.representativeFaceId??null)},[N]);let P=n(()=>N.find(e=>e.representativeFaceId===S)??null,[N,S]),F=P?T[P.representativeFaceId]??new Set:new Set,I=n(()=>P?xr(P,e=>i.has(e)):[],[P,i]),L=P?P.faceIds.length-I.length:0,R=P?br({...P,faceIds:I},F):[];function z(e){if(!P)return;let t=P.representativeFaceId;E(n=>({...n,[t]:yr(n[t]??new Set,e)}))}function B(){h.invalidateQueries({queryKey:Sr})}async function V(e){await g({title:m(`detectionIntelligence.similarGroupsModal.deleteFace`,`Delete face`),message:m(`detectionIntelligence.similarGroupsModal.permanentlyDeletesThisFaceCrop`,`Permanently deletes this face crop. This cannot be undone.`),confirmLabel:m(`common.delete`,`Delete`),variant:`danger`})&&_.mutate({faceId:e},{onSettled:B})}function H(){k(null),r()}function U(){R.length!==0&&(p(R),H())}return e(Je,{open:t,onOpenChange:e=>!e&&H(),children:[e(dt,{placement:`sheet-on-mobile`,width:`lg`,"aria-label":m(`detectionIntelligence.similarGroupsModal.lookAlikeGroups`,`Look-alike groups`),className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 md:max-w-4xl`,children:[e(`header`,{className:`flex shrink-0 flex-col gap-2 border-b border-border py-3 pl-4 pr-10`,children:[e(`div`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[a(D,{className:`h-4 w-4 text-primary`}),` `,m(`detectionIntelligence.similarGroupsModal.title`)]}),e(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[e(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[m(`detectionIntelligence.similarGroupsModal.threshold`,`Threshold`),a(`input`,{type:`range`,min:wr,max:Tr,step:Er,value:v,onChange:e=>y(Number(e.target.value)),className:`h-1.5 w-28 cursor-pointer accent-primary`}),a(`span`,{className:`w-8 shrink-0 text-right font-mono text-[11px] tabular-nums text-foreground`,children:v.toFixed(2)})]}),e(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[m(`detectionIntelligence.similarGroupsModal.minSize`,`Min size`),a(`input`,{type:`number`,min:Or,max:kr,step:1,value:b,onChange:e=>x(Math.min(kr,Math.max(Or,Number(e.target.value)||Or))),className:`w-12 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`})]}),e(Y,{variant:`secondary`,onClick:()=>{E({}),M()},disabled:j,children:[j?a(G,{className:`h-3.5 w-3.5 animate-spin`}):a(q,{className:`h-3.5 w-3.5`}),m(`detectionIntelligence.similarGroupsModal.reAnalyze`,`Re-analyze`)]})]})]}),a(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-hidden px-4 py-3 md:flex-row`,children:j&&N.length===0?e(`div`,{className:`flex flex-1 items-center justify-center gap-2 py-8 text-xs text-foreground-subtle`,children:[a(G,{className:`h-4 w-4 animate-spin`}),` `,m(`detectionIntelligence.similarGroupsModal.finding`)]}):N.length===0?a(`div`,{className:`flex flex-1 items-center justify-center py-8 text-xs text-foreground-subtle`,children:m(`detectionIntelligence.similarGroupsModal.noLookAlikeGroupsAt`,`No look-alike groups at this threshold.`)}):e(d,{children:[a(`div`,{className:`flex gap-2 overflow-x-auto pb-1 md:hidden`,children:N.map(e=>a(jr,{cluster:e,face:i.get(e.representativeFaceId),active:e.representativeFaceId===S,onSelect:()=>w(e.representativeFaceId)},e.representativeFaceId))}),a(`div`,{className:`hidden shrink-0 flex-col gap-2 overflow-y-auto md:flex md:w-56`,children:N.map(e=>a(jr,{cluster:e,face:i.get(e.representativeFaceId),active:e.representativeFaceId===S,onSelect:()=>w(e.representativeFaceId)},e.representativeFaceId))}),a(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:P&&e(d,{children:[L>0&&a(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:m(`detectionIntelligence.similarGroupsModal.hiddenCount`,{count:L})}),a(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(13rem,13rem))] justify-start gap-2`,children:I.map(e=>{let t=i.get(e);return t?a(Mr,{face:t,cameraName:c(t.deviceId),nowMs:l,excluded:F.has(e),onToggleExclude:()=>z(e),onDelete:()=>void V(e),deletePending:_.isPending&&_.variables?.faceId===e},e):null})})]})})]})}),e(`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:[a(Y,{variant:`secondary`,onClick:U,disabled:R.length===0,children:m(`detectionIntelligence.similarGroupsModal.selectInGallery`,`Select in gallery`)}),e(Y,{variant:`primary`,onClick:()=>k(R),disabled:R.length===0,children:[a(C,{className:`h-3.5 w-3.5`}),` `,m(`detectionIntelligence.similarGroupsModal.adopt`,{count:R.length})]})]})]}),a(or,{faceIds:O,identities:f,onDone:()=>k(null)})]})}l();var Pr=[[`faceGallery`]],Fr=500,Ir=120;function Lr({face:t,cameraName:n,nowMs:r,selected:i,onToggleSelect:o,onAssign:s,onOpenDetail:c}){let{t:l}=Z(),d=u(),f=vt(),p=nt(),m=()=>{d.invalidateQueries({queryKey:Pr})},h=()=>c(t.faceId),g=er(t);return e(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[e(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[g===null?e(`button`,{type:`button`,onClick:h,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:l(`detectionIntelligence.unassignedFaces.noCropImageTheFace`,`No crop image — the face's crop media is missing (a pre-fix orphan). Safe to delete.`),children:[a(K,{className:`h-7 w-7 text-warning/70`}),a(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:l(`detectionIntelligence.unassignedFaces.noCrop`,`No crop`)})]}):a(`img`,{src:g,alt:l(`detectionIntelligence.unassignedFaces.faceFrom`,`Face from {{cameraName}}`,{cameraName:n}),onClick:h,loading:`lazy`,decoding:`async`,className:`h-full w-full cursor-zoom-in object-cover`}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(t.faceId)},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":i?l(`detectionIntelligence.unassignedFaces.deselect`,`Deselect`):l(`detectionIntelligence.unassignedFaces.select`,`Select`),children:i?a(de,{className:`h-4 w-4 text-primary`}):a(k,{className:`h-4 w-4`})})]}),e(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[a(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:n,children:n}),a(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:Jn(t.timestamp,r)}),a(`p`,{className:`min-h-[0.875rem] truncate text-[10px] font-medium leading-tight ${t.identityName?`text-primary`:`invisible`}`,title:t.identityName,children:t.identityName??`\xA0`})]}),e(`div`,{className:`mt-1 flex min-h-[2rem] items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[t.assigned?a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),f.mutate({faceId:t.faceId},{onSettled:m})},disabled:f.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":l(`detectionIntelligence.unassignedFaces.detachFace`,`Detach face`),title:l(`detectionIntelligence.unassignedFaces.detach`,`Detach`),children:f.isPending?a(G,{className:`h-4 w-4 animate-spin`}):a(pe,{className:`h-4 w-4`})}):a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s(t.faceId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":l(`detectionIntelligence.unassignedFaces.assignFaceToPerson`,`Assign face to person`),title:l(`detectionIntelligence.unassignedFaces.assignToPerson`,`Assign to person`),children:a(C,{className:`h-4 w-4`})}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),p.mutate({faceId:t.faceId},{onSettled:m})},disabled:p.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":l(`detectionIntelligence.unassignedFaces.deleteFace`,`Delete face`),title:l(`detectionIntelligence.unassignedFaces.deleteFace`,`Delete face`),children:p.isPending?a(G,{className:`h-4 w-4 animate-spin`}):a(b,{className:`h-4 w-4`})})]})]})}var Rr=[{labelKey:`common.all`,value:`all`},{labelKey:`detectionIntelligence.unassignedFaces.filterUnassigned`,value:`unassigned`},{labelKey:`detectionIntelligence.unassignedFaces.filterRecognized`,value:`recognized`}];function zr(){let{t}=Z(),r=u(),[i,o]=s(`all`),[c,l]=s(Rn),[f,p]=s(new Set),[m,h]=s(new Set),[g,_]=s(null),[v,y]=s(!1),[x,S]=s(null),{data:w,isLoading:T}=lt({limit:Fr,filter:i,includeCrops:!1},{refetchInterval:3e4}),{data:E=[]}=St(),{data:O}=Ie({isCamera:!0,projection:`slim`}),k=mt(),A=vt(),j=ft(),M=nt(),N=Date.now(),P=w??[],I=n(()=>{let e=new Map;for(let t of O??[])e.set(t.id,t.name);return e},[O]),L=e=>I.get(e)??t(`detectionIntelligence.cameraFallback`,{id:String(e)}),R=n(()=>Gn(P).map(e=>({id:e,name:L(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[P,I]),z=n(()=>Wn(Un(P,c),f),[P,c,f]),B=tr(z,Ir,n(()=>JSON.stringify([i,c.fromMs,c.toMs,[...f].sort((e,t)=>e-t)]),[i,c.fromMs,c.toMs,f])),V=n(()=>new Map(P.map(e=>[e.faceId,e])),[P]),H=n(()=>$n(z),[z]),U=x===null?null:V.get(x)??null,W=()=>{r.invalidateQueries({queryKey:Pr})},ee=()=>h(new Set);function te(e){h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function q(e){h(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function ne(){q(Qn(z))}let re=[...m],J=k.isPending||j.isPending||M.isPending,ie=A.isPending||M.isPending;function ae(){re.length!==0&&j.mutate({faceIds:re},{onSettled:()=>{W(),ee()}})}function oe(){re.length!==0&&Promise.allSettled(re.map(e=>M.mutateAsync({faceId:e}))).then(()=>{W(),ee()})}function se(e){S(null),_([e])}function ce(e){A.mutate({faceId:e},{onSettled:W}),S(null)}function le(e){M.mutate({faceId:e},{onSettled:W}),S(null)}let ue=z.length!==P.length;return e(`div`,{className:`relative space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[a(`div`,{className:`flex items-center gap-1`,children:Rr.map(e=>a(`button`,{type:`button`,onClick:()=>o(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${i===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:t(e.labelKey)},e.value))}),a(lr,{onChange:l}),a(sr,{cameras:R,selected:f,onChange:p}),e(`button`,{type:`button`,onClick:()=>y(!0),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${v?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(D,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.similarGroups`)]}),!T&&H>0&&e(`button`,{type:`button`,onClick:ne,className:`ml-auto flex items-center gap-1 rounded-md px-2.5 py-1 text-xs text-warning/90 transition-colors hover:bg-warning/10`,title:t(`detectionIntelligence.unassignedFaces.selectEveryVisibleFaceWhose`,`Select every visible face whose crop image is missing so you can delete the orphans in one pass`),children:[a(K,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.selectCropless`,{count:H})]}),!T&&a(`span`,{className:`text-[10px] text-foreground-subtle ${H>0?`ml-2`:`ml-auto`}`,children:ue?t(`detectionIntelligence.unassignedFaces.ofFaces`,`{{value1}} of {{value2}} faces`,{value1:String(z.length),value2:String(P.length)}):t(`detectionIntelligence.unassignedFaces.faceCount`,{count:z.length})})]}),m.size>0&&e(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[a(`span`,{className:`text-xs font-medium text-foreground`,children:t(`common.selectedCount`,{count:m.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[e(Y,{variant:`primary`,onClick:()=>_(re),disabled:J,children:[a(C,{className:`h-3.5 w-3.5`}),` `,t(`common.assign`)]}),e(Y,{variant:`secondary`,onClick:ae,disabled:J,children:[j.isPending?a(G,{className:`h-3.5 w-3.5 animate-spin`}):a(pe,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.detach`,`Detach`)]}),e(Y,{variant:`secondary`,onClick:oe,disabled:J,children:[a(b,{className:`h-3.5 w-3.5`}),` `,t(`common.delete`)]}),a(Y,{variant:`ghost`,onClick:ee,disabled:J,children:a(F,{className:`h-3.5 w-3.5`})})]})]}),T?a(Xe,{status:`pending`,pendingMessage:`Loading faces…`,testId:`faces-grid`}):z.length===0?a(Te,{icon:K,title:P.length>0?t(`detectionIntelligence.unassignedFaces.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.unassignedFaces.noFacesFoundForThis`,`No faces found for this filter`),description:P.length>0?t(`detectionIntelligence.unassignedFaces.widenTheDateRangeOr`,`Widen the date range or clear the camera filter.`):t(`detectionIntelligence.unassignedFaces.faceCropsAppearHereWhen`,`Face crops appear here when the detection pipeline captures them.`)}):e(d,{children:[a(Xe,{status:`ready`,testId:`faces-grid`,className:`grid-cols-[repeat(auto-fill,minmax(6.5rem,6.5rem))] justify-start`,children:B.pageItems.map(e=>a(Lr,{face:e,cameraName:L(e.deviceId),nowMs:N,selected:m.has(e.faceId),onToggleSelect:te,onAssign:e=>_([e]),onOpenDetail:S},e.faceId))}),a(ir,{currentPage:B.page,totalItems:B.totalItems,pageSize:B.pageSize,onPageChange:B.setPage,itemNoun:`faces`})]}),a(vr,{face:U,cameraName:U?L(U.deviceId):``,onClose:()=>S(null),onAssign:se,onUnassign:ce,onDelete:le,actionsPending:ie}),a(or,{faceIds:g,identities:E,onDone:()=>{_(null),ee()}}),a(Nr,{open:v,onClose:()=>y(!1),byId:V,cameraName:L,nowMs:N,identities:E,selectMany:q})]})}function Br(e){let{delayMs:t,invalidate:n,setTimeoutFn:r=setTimeout,clearTimeoutFn:i=clearTimeout}=e,a;function o(){a===void 0&&(a=r(()=>{a=void 0,n()},t))}function s(){a!==void 0&&(i(a),a=void 0)}return{trigger:o,cancel:s}}l();var Vr=[[`faceGallery`]],Hr=2e3;function Ur(){let e=u(),n=t(e);n.current=e;let r=t(void 0);r.current||=Br({delayMs:Hr,invalidate:()=>{n.current.invalidateQueries({queryKey:Vr})}}),o(()=>()=>r.current?.cancel(),[]),ot(J.PipelineAnalyticsFaceGalleryChanged,()=>{r.current?.trigger()})}function Wr(){let{t}=Z();return Ur(),e(`div`,{className:`space-y-3`,children:[a(jt,{headingId:`library-people`,title:t(`detectionIntelligence.people`,`People`),icon:ge,testId:`library-section-people`,children:e(`div`,{className:`${m} space-y-3`,children:[a(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`detectionIntelligence.enrolledIdentitiesUsedForFace`,`Enrolled identities used for face recognition. Open a person to rename them or remove training samples.`)}),a(Ln,{})]})}),a(jt,{headingId:`library-recent-faces`,title:t(`detectionIntelligence.recentDetectedFaces`,`Recent detected faces`),icon:oe,testId:`library-section-recent-faces`,children:e(`div`,{className:`${m} space-y-3`,children:[a(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`detectionIntelligence.faceCropsCapturedByThe`,`Face crops captured by the detection pipeline. Assign them to a person to build recognition training data.`)}),a(zr,{})]})})]})}function Gr(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 Kr=720*60*60*1e3;function qr(e){let t=[];for(let n of e)t.push(...n);return t}function Jr(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function Yr(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 Xr(e,t){return`${String(e)}:${t}`}function Zr(e,t){let n=new Map,r=new Set;for(let i of e){let e=Xr(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 Qr(e,t){return{since:e.fromMs??t-Kr,until:e.toMs??t}}var $r=[`native`,`raster`,`standin`];function ei(e){return $r.some(t=>t===e)}function ti(e){return e===`standin`?{label:X.t(`helpers.mediaProvenance.standin.label`),title:X.t(`helpers.mediaProvenance.standin.title`),tone:`warning`}:{label:X.t(`helpers.mediaProvenance.raster.label`),title:X.t(`helpers.mediaProvenance.raster.title`),tone:`info`}}function ni(e){return e===`standin`?ti(`standin`):e===`raster`?ti(`raster`):null}var ri={"no-key-frame":`helpers.mediaProvenance.miss.noKeyFrame`,"no-best-seen-bbox":`helpers.mediaProvenance.miss.noBestSeenBbox`,"derive-returned-null":`helpers.mediaProvenance.miss.deriveReturnedNull`,"derive-threw":`helpers.mediaProvenance.miss.deriveThrew`,"derive-not-wired":`helpers.mediaProvenance.miss.deriveNotWired`,"no-media-store":`helpers.mediaProvenance.miss.noMediaStore`,"no-thumbnail":`helpers.mediaProvenance.miss.noThumbnail`,"standin-tile":`helpers.mediaProvenance.miss.standinTile`,"raster-tile":`helpers.mediaProvenance.miss.rasterTile`,"native-tile":`helpers.mediaProvenance.miss.nativeTile`};function ii(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)})}let a=ri[r];return{sentence:a===void 0?r:X.t(a),detail:i,raw:t}}function ai(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 oi({row:t,cameraName:n,nowMs:r,onOpenDetail:i,selected:o=!1,onToggleSelect:s,score:c,provenance:l,footer:u}){let{t:d}=Z(),f=Vt(t.mediaId===void 0?Ht(`track`,t.trackId):Wt(t.mediaId)),m=Math.round(t.importance*100),h=c===void 0?void 0:Math.round(c*100),g=ai(t.windowMs),_=()=>i(t),v=ni(l);return e(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${o?`border-primary ring-1 ring-primary`:`border-border`}`,children:[e(`div`,{className:`aspect-video relative overflow-hidden bg-surface-hover`,children:[f.src?a(`img`,{src:f.src,alt:d(`detectionIntelligence.eventCard.eventFrom`,`Event from {{cameraName}}`,{cameraName:n}),onClick:_,className:`h-full w-full cursor-zoom-in object-cover`}):a(`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:f.failed?d(`detectionIntelligence.eventCard.keyEventMediaUnavailable`,`Key-event media unavailable`):d(`detectionIntelligence.eventCard.noKeyEventMedia`,`No key-event media`),children:a(K,{className:`h-6 w-6 opacity-60`})}),s&&a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s(Xr(t.deviceId,t.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":o?d(`detectionIntelligence.eventCard.deselect`,`Deselect`):d(`detectionIntelligence.eventCard.select`,`Select`),children:o?a(de,{className:`h-4 w-4 text-primary`}):a(k,{className:`h-4 w-4`})}),h!==void 0&&e(`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:d(`detectionIntelligence.eventCard.clipSemanticMatchScore`,`CLIP semantic-match score`),children:[String(h),`%`]}),m>0&&a(`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(m)}),v!==null&&a(`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}),(t.markForTrain===!0||t.retrainStatus===`trained`||t.debug===!0||t.favourited===!0)&&e(`span`,{className:`absolute bottom-1 left-1 z-10 flex gap-1`,children:[t.markForTrain===!0&&a(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:d(`detectionIntelligence.eventCard.markedForTraining`,`Marked for training`),"aria-label":d(`detectionIntelligence.eventCard.markedForTraining`,`Marked for training`),children:a(S,{className:`h-3 w-3`})}),t.retrainStatus===`trained`&&t.markForTrain!==!0&&a(`span`,{className:`rounded bg-success/85 p-0.5 text-white`,title:d(`detectionIntelligence.eventCard.trainingComplete`,`Training complete`),"aria-label":d(`detectionIntelligence.eventCard.trainingComplete`,`Training complete`),"data-testid":`retrain-status-trained`,children:a(p,{className:`h-3 w-3`})}),t.debug===!0&&a(`span`,{className:`rounded bg-black/70 p-0.5 text-white`,title:d(`detectionIntelligence.eventCard.flaggedForDebug`,`Flagged for debug`),"aria-label":d(`detectionIntelligence.eventCard.flaggedForDebug`,`Flagged for debug`),children:a(R,{className:`h-3 w-3`})}),t.favourited===!0&&a(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:d(`detectionIntelligence.eventCard.favourited`,`Favourited`),"aria-label":d(`detectionIntelligence.eventCard.favourited`,`Favourited`),children:a(A,{className:`h-3 w-3`})})]})]}),e(`button`,{type:`button`,onClick:_,className:`min-w-0 px-2 py-1.5 text-left space-y-0.5`,children:[e(`p`,{className:`text-[11px] font-medium text-foreground truncate`,title:t.className,children:[t.className,Gr(t)?e(`span`,{className:`text-foreground-subtle`,children:[` · `,Gr(t)]}):null]}),a(`p`,{className:`text-[10px] text-foreground-subtle truncate`,title:n,children:n}),e(`div`,{className:`flex items-center justify-between gap-2`,children:[a(`span`,{className:`text-[10px] text-foreground-subtle truncate`,children:Jn(t.timestamp,r)}),g&&a(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:g})]})]}),u!==void 0&&a(`div`,{className:`px-2 pb-1.5`,children:u})]})}l();var si=1400,ci=`Admin-gated URL — opens only inside an authenticated session`;function li({label:t,value:n,title:r}){let{t:c}=Z(),[l,u]=s(!1),d=ve();return o(()=>{if(!l)return;let e=setTimeout(()=>u(!1),si);return()=>clearTimeout(e)},[l]),e(`button`,{type:`button`,onClick:i(()=>{(async()=>{try{await navigator.clipboard.writeText(n),u(!0)}catch{await d({title:c(`detectionIntelligence.copyUrlChips.copyTheMediaUrl`,`Copy the media URL`),message:c(`detectionIntelligence.copyUrlChips.clipboardAccessWasRefusedSelect`,`Clipboard access was refused. Select the URL below and copy it manually.`),label:c(`detectionIntelligence.copyUrlChips.url`,`{{label}} URL`,{label:t}),defaultValue:n,readOnly:!0,cancelLabel:c(`common.close`,`Close`)})}})()},[n,t,d,c]),title:r,"aria-label":c(`detectionIntelligence.copyUrlChips.copyUrl`,`Copy {{label}} URL`,{label:t}),className:`flex min-w-0 items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${l?`border-success/40 bg-success/10 text-success`:`border-border text-foreground-subtle hover:border-primary hover:text-foreground`}`,children:[a(l?p:E,{className:`h-2.5 w-2.5 shrink-0`}),a(`span`,{className:`truncate`,children:l?c(`detectionIntelligence.copyUrlChips.copied`,`Copied`):t})]})}function ui({localUrl:t,publicUrl:n}){let{t:r}=Z();return e(`div`,{className:`flex flex-wrap gap-1`,children:[a(li,{label:r(`detectionIntelligence.copyUrlChips.local`,`Local`),value:t,title:r(`detectionIntelligence.copyUrlChips.copyLanUrl`,`Copy LAN URL — {{AUTH_HINT}}`,{AUTH_HINT:ci})}),n&&a(li,{label:r(`detectionIntelligence.copyUrlChips.public`,`Public`),value:n,title:r(`detectionIntelligence.copyUrlChips.copyPublicUrl`,`Copy public URL — {{AUTH_HINT}}`,{AUTH_HINT:ci})})]})}var di={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 fi(e){return e in di}function pi(e){return fi(e)?di[e]:e}function mi(e,t){return`${e}${t}`}l();var hi=3e4;function gi(e){let[t,n]=s(null),r=i(e=>{n(t=>t??e)},[]);return o(()=>{e||n(null)},[e]),{publicOrigin:t,probes:e?a(_i,{onOrigin:r}):null}}function _i({onOrigin:e}){let{data:t}=rt({capName:`network-access`});return a(d,{children:(t??[]).map(t=>a(vi,{addonId:t.addonId,onOrigin:e},t.addonId))})}function vi({addonId:e,onOrigin:t}){let{data:n}=Ve({addonId:e},{refetchInterval:hi,retry:!1});return o(()=>{let e=n?ie.safeParse(n):null,r=e?.success?e.data.endpoint?.url:void 0;if(r)try{t(new URL(r).origin)}catch{}},[n,t]),null}var yi=typeof ye==`function`,bi=`Track flags arrive with the next server update`;function xi(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var Si=yi?ye:xi;function Ci(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}}l();function wi({label:t,hint:n,checked:r,disabled:i,title:o,icon:s,onToggle:c}){return e(`button`,{type:`button`,role:`switch`,"aria-checked":r,"aria-label":t,disabled:i,title:o,onClick:c,className:`flex w-full items-center gap-2 rounded-md border px-2 py-1.5 text-left transition-colors disabled:opacity-50 ${r?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[a(`span`,{className:r?`text-primary`:`text-foreground-subtle`,children:s}),e(`span`,{className:`min-w-0 flex-1`,children:[a(`span`,{className:`block text-[11px] font-medium text-foreground`,children:t}),a(`span`,{className:`block text-[10px] text-foreground-subtle`,children:n})]}),a(`span`,{"aria-hidden":`true`,className:`h-4 w-7 shrink-0 rounded-full p-0.5 transition-colors ${r?`bg-primary`:`bg-border`}`,children:a(`span`,{className:`block h-3 w-3 rounded-full bg-white transition-transform ${r?`translate-x-3`:``}`})})]})}function Ti({deviceId:t,trackId:n,markForTrain:r,debug:i,favourited:o,onChange:c}){let{t:l}=Z(),u=Si(),d=ze(),[f,p]=s(null),m=f?.markForTrain??r===!0,h=f?.debug??i===!0,g=f?.favourited??o===!0,_=!yi||u.isPending,v=yi?void 0:bi,y=e=>{_||(async()=>{try{let r=Ci(await u.mutateAsync({deviceId:t,trackId:n,flags:e}));if(!r)return;p(r),c?.(r)}catch(e){let t=e instanceof Error?e.message:``;await d({title:l(`detectionIntelligence.trackFlagToggles.couldNotUpdateThisTrack`,`Could not update this track`),message:t===``?l(`detectionIntelligence.trackFlagToggles.couldNotUpdateThisTrack2`,`Could not update this track. Check the server logs.`):t,variant:`danger`})}})()};return e(`div`,{className:`grid gap-1.5 sm:grid-cols-2`,children:[a(wi,{label:l(`detectionIntelligence.trackFlagToggles.markForTraining`,`Mark for training`),hint:l(`detectionIntelligence.trackFlagToggles.keepsThisTrackAndIts`,`Keeps this track and its media past retention`),checked:m,disabled:_,...v===void 0?{}:{title:v},icon:a(S,{className:`h-4 w-4`}),onToggle:()=>y({markForTrain:!m})}),a(wi,{label:l(`detectionIntelligence.trackFlagToggles.debug`,`Debug`),hint:l(`detectionIntelligence.trackFlagToggles.flagThisTrackForDiagnostic`,`Flag this track for diagnostic attention`),checked:h,disabled:_,...v===void 0?{}:{title:v},icon:a(R,{className:`h-4 w-4`}),onToggle:()=>y({debug:!h})}),a(wi,{label:l(`detectionIntelligence.trackFlagToggles.favourited`,`Favourited`),hint:l(`detectionIntelligence.trackFlagToggles.keepsThisTrackAndIts`,`Keeps this track and its media past retention`),checked:g,disabled:_,...v===void 0?{}:{title:v},icon:a(A,{className:`h-4 w-4`}),onToggle:()=>y({favourited:!g})})]})}function Ei(e){let t=e.deviceKey===void 0?e.nodeId:`${e.nodeId} · ${e.deviceKey}`;return e.modelId===void 0?t:`${t} (${e.modelId})`}function Di(e){let t=e?.openedPlacement,n=e?.closedPlacement;if(t!==void 0&&n!==void 0){let e=Ei(t),r=Ei(n);return e===r?[{kind:`detected`,value:e}]:[{kind:`opened`,value:e},{kind:`closed`,value:r}]}return t===void 0?n===void 0?[]:[{kind:`closed`,value:Ei(n)}]:[{kind:`opened`,value:Ei(t)}]}var Oi=100,ki={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Ai=e=>e<0?0:e>1?1:e,ji=e=>Math.round(e*100)/100;function Mi(e,t,n){if(e.length===0||t===null)return ki;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return ki;let a=ae(e.map(e=>({x:e.x/r,y:e.y/i,w:e.bbox.w/r,h:e.bbox.h/i})),n?.maxPoints===void 0?void 0:{maxPoints:n.maxPoints}).nodes.map(e=>({x:ji(e.x*Oi),y:ji(e.y*Oi)})),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:ji(Ai(e.x/r)*Oi),y:ji(Ai(e.y/i)*Oi),mediaId:e.mediaId})),u=null,d=-1;for(let t of e){let e=Ai(t.bbox.w/r)*Ai(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:ji(Ai(u.bbox.x/r)*Oi),y:ji(Ai(u.bbox.y/i)*Oi),w:ji(Ai(u.bbox.w/r)*Oi),h:ji(Ai(u.bbox.h/i)*Oi)}:null}}var Ni=typeof At==`function`,Pi=`Track deletion arrives with the next server update`;function Fi(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var Ii=Ni?At:Fi;l();var Li=15e3,Ri=j();function zi({url:e,label:t}){let{src:n,failed:r}=Vt(e);return n===null?a(`div`,{className:`flex h-full w-full items-center justify-center bg-surface-hover`,children:r?a(K,{className:`h-4 w-4 text-foreground-subtle opacity-60`}):a(G,{className:`h-4 w-4 animate-spin text-foreground-subtle opacity-70`})}):a(`img`,{src:n,alt:t,className:`h-full w-full object-cover`})}var Bi=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),Vi=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`,`sceneFrame`,`lastSceneFrame`]);function Hi(e){let[t,n]=s(null);return o(()=>{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 Ui({overlay:t,onPickSnapshot:n}){let{t:r}=Z();return!t.polyline&&!t.peakBox&&t.snapshots.length===0?null:e(`svg`,{viewBox:`0 0 100 100`,preserveAspectRatio:`none`,className:`pointer-events-none absolute inset-0 h-full w-full`,children:[t.peakBox&&a(`rect`,{x:t.peakBox.x,y:t.peakBox.y,width:t.peakBox.w,height:t.peakBox.h,fill:`none`,stroke:`var(--color-warning)`,strokeWidth:2,vectorEffect:`non-scaling-stroke`,rx:1}),t.polyline&&a(`polyline`,{points:t.polyline,fill:`none`,stroke:`var(--color-info)`,strokeWidth:2,strokeLinejoin:`round`,strokeLinecap:`round`,strokeOpacity:.85,vectorEffect:`non-scaling-stroke`}),t.points.map((e,t)=>a(`circle`,{cx:e.x,cy:e.y,r:1,fill:`var(--color-info)`,fillOpacity:.6,vectorEffect:`non-scaling-stroke`},`${String(e.x)}-${String(e.y)}-${String(t)}`)),t.snapshots.map((e,t)=>a(`circle`,{cx:e.x,cy:e.y,r:1.9,fill:`var(--color-info)`,fillOpacity:.95,stroke:`var(--color-background)`,strokeWidth:.7,vectorEffect:`non-scaling-stroke`,className:n?`pointer-events-auto cursor-pointer`:void 0,onClick:n?t=>{t.stopPropagation(),n(e.mediaId)}:void 0,children:a(`title`,{children:r(`detectionIntelligence.eventDetailPanel.snapshotCheckpointClickToView`,`Snapshot checkpoint — click to view this frame`)})},`snap-${String(e.mediaId)}-${String(t)}`)),t.start&&a(`circle`,{cx:t.start.x,cy:t.start.y,r:2.4,fill:`var(--color-success)`,stroke:`var(--color-background)`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`}),t.end&&a(`circle`,{cx:t.end.x,cy:t.end.y,r:2.4,fill:`var(--color-danger)`,stroke:`var(--color-background)`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`})]})}function Wi({label:t,value:n,mono:r,wrap:i}){return e(`div`,{className:`flex items-baseline justify-between gap-3 border-b border-border/60 py-1.5 last:border-0`,children:[a(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:t}),a(`span`,{className:`min-w-0 ${i?`break-words`:`truncate`} text-right text-xs font-medium text-foreground ${r?`font-mono text-[11px]`:``}`,title:n,children:n})]})}function Gi({row:t,cameraName:r,deleteAvailable:c,onClose:l,onDeleted:u,onFlagsChanged:f}){let{t:p}=Z(),m=U(),h=ze(),g=Pe(),_=Ii(),v=t!==null,x=t?.deviceId??0,S=t?.trackId??``,C=t?.timestamp??0,w=t?.windowMs??0,{data:T}=xe({deviceId:x,trackId:S},{enabled:v}),{data:E}=Ce({trackId:S,deviceId:x},{enabled:v}),D=T?.bestEventId===void 0?void 0:Number(T.bestEventId),{data:O}=Re({ownerType:`object`,eventId:D??0,deviceId:x},{enabled:v&&D!==void 0&&Number.isFinite(D)}),{data:k}=wt({deviceId:x},{enabled:v}),A=(k??[]).find(e=>e.addonId!==void 0)?.addonId,{data:j}=qe({deviceId:x,since:C-Li,until:C+w+Li,provider:A??``},{enabled:v&&A!==void 0}),[M,N]=s(null),[P,F]=s(!1),{publicOrigin:I,probes:L}=gi(v);o(()=>{N(null)},[x,S]);let R=n(()=>{let e=E??[],t=O??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[E,O]),z=M??R,B=Vt(z?z.url:void 0),V=n(()=>{let e=new Set,t=[];for(let n of[...O??[],...E??[]])e.has(n.mediaId)||(e.add(n.mediaId),t.push(n));return t},[O,E]),H=n(()=>V.find(e=>Bi.has(e.kind))??null,[V]),W=Hi(Vt(H?H.url:void 0).src),ee=n(()=>Mi(T?.positions??[],W,{snapshots:(T?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaId:e.mediaId}))}),[T?.positions,T?.snapshots,W]),te=i(e=>{let t=V.find(t=>t.mediaId===e);t&&N(t)},[V]);if(t===null)return null;let q=B.src,ne=z?.kind,re=ne!==void 0&&Vi.has(ne)&&W!==null&&(T?.positions.length??0)>=2,J=j&&j.length>0?j[0]:null,ie=()=>{J&&(F(!0),(async()=>{try{let e=await m.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:J.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{h({title:p(`detectionIntelligence.eventDetailPanel.clipUnavailable`,`Clip unavailable`),message:p(`detectionIntelligence.eventDetailPanel.couldNotResolveClipPlayback`,`Could not resolve clip playback. Check the server logs.`),variant:`warning`})}finally{F(!1)}})())},ae=()=>{!c||_.isPending||(async()=>{if(await g({title:p(`detectionIntelligence.eventDetailPanel.deleteTrack`,`Delete track`),message:p(`detectionIntelligence.eventDetailPanel.deleteThisTrackAndEvery`,`Delete this track and every image and clip captured for it? This cannot be undone.`),confirmLabel:p(`common.delete`,`Delete`),variant:`danger`}))try{await _.mutateAsync({deviceId:t.deviceId,trackIds:[t.trackId]}),u()}catch{await h({title:p(`detectionIntelligence.eventDetailPanel.deleteFailed`,`Delete failed`),message:p(`detectionIntelligence.eventDetailPanel.failedToDeleteThisTrack`,`Failed to delete this track. Check the server logs.`),variant:`danger`})}})()},oe=Math.round(t.importance*100),se=T?.importanceReason?`${String(oe)}% · ${T.importanceReason}`:`${String(oe)}%`,ce=T?.zonesVisited&&T.zonesVisited.length>0?T.zonesVisited.join(`, `):`—`,le=T?.audioLabels&&T.audioLabels.length>0?T.audioLabels:t.audioLabels&&t.audioLabels.length>0?t.audioLabels:void 0,ue=le===void 0?`—`:le.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `),de=T?T.totalDistance.toFixed(2):`—`,fe=ii(T?.previewMissReason),pe=Xn(T?T.firstSeen:C),me=T?Xn(T.lastSeen):`—`,he=Di(T),ge={detected:p(`detectionIntelligence.eventDetailPanel.detectedOn`,`Detected on`),opened:p(`detectionIntelligence.eventDetailPanel.openedOn`,`Opened on`),closed:p(`detectionIntelligence.eventDetailPanel.closedOn`,`Closed on`)};return a(Je,{open:!0,onOpenChange:e=>!e&&l(),children:e(dt,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":p(`detectionIntelligence.eventDetailPanel.eventDetail`,`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:[a(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:e(`div`,{className:`min-w-0`,children:[e(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:[t.className,Gr(t)?e(`span`,{className:`text-foreground-subtle`,children:[` · `,Gr(t)]}):null]}),a(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:r})]})}),e(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[q?a(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:a(pr,{src:q,alt:p(`detectionIntelligence.eventDetailPanel.keyFrameFrom`,`Key frame from {{cameraName}}`,{cameraName:r}),fit:`natural`,className:`w-full`,overlay:re?a(Ui,{overlay:ee,onPickSnapshot:te}):void 0})}):a(`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:B.failed?e(d,{children:[a(K,{className:`h-8 w-8 opacity-60`}),a(`span`,{className:`text-[11px]`,children:p(`detectionIntelligence.eventDetailPanel.keyFrameMediaUnavailable`,`Key-frame media unavailable`)})]}):a(G,{className:`h-6 w-6 animate-spin opacity-70`})}),V.length>0&&a(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:V.map(t=>{let n=pi(t.kind),r=mi(Ri,t.url),i=I?mi(I,t.url):null;return e(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[a(`button`,{type:`button`,onClick:()=>N(t),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${n} · ${Xn(t.timestamp)}`,children:a(zi,{url:t.url,label:n})}),e(`figcaption`,{className:`min-w-0 px-0.5`,children:[a(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:n,children:n}),a(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:Xn(t.timestamp),children:Yn(t.timestamp)})]}),a(ui,{localUrl:r,publicUrl:i})]},t.mediaId)})}),L,J&&e(Y,{variant:`secondary`,onClick:ie,disabled:P,children:[P?a(G,{className:`h-3.5 w-3.5 animate-spin`}):a(y,{className:`h-3.5 w-3.5`}),` `,p(`detectionIntelligence.eventDetailPanel.viewClip`,`View clip`)]}),a(Ti,{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}),fe!==null&&e(`div`,{className:`rounded-lg border border-warning/40 bg-warning/8 px-3 py-2`,children:[a(`p`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:p(`detectionIntelligence.eventDetailPanel.bestShot`,`Best shot`)}),a(`p`,{className:`mt-0.5 text-xs text-foreground`,children:fe.sentence}),a(`code`,{className:`mt-1 block break-all font-mono text-[10px] text-foreground-subtle`,children:fe.raw})]}),e(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[a(Wi,{label:p(`detectionIntelligence.eventDetailPanel.camera`,`Camera`),value:r}),he.map(e=>a(Wi,{label:ge[e.kind],value:e.value,mono:!0,wrap:!0},e.kind)),a(Wi,{label:p(`detectionIntelligence.eventDetailPanel.class`,`Class`),value:t.className}),a(Wi,{label:p(`detectionIntelligence.eventDetailPanel.label`,`Label`),value:t.label??`—`}),a(Wi,{label:p(`detectionIntelligence.eventDetailPanel.subLabel`,`Sub-label`),value:t.subLabel??`—`}),a(Wi,{label:p(`detectionIntelligence.eventDetailPanel.importance`,`Importance`),value:se}),a(Wi,{label:p(`detectionIntelligence.eventDetailPanel.zonesVisited`,`Zones visited`),value:ce}),a(Wi,{label:p(`detectionIntelligence.eventDetailPanel.audioHeard`,`Audio heard`),value:ue}),a(Wi,{label:p(`detectionIntelligence.eventDetailPanel.totalDistance`,`Total distance`),value:de}),a(Wi,{label:p(`detectionIntelligence.eventDetailPanel.firstSeen`,`First seen`),value:pe}),a(Wi,{label:p(`detectionIntelligence.eventDetailPanel.lastSeen`,`Last seen`),value:me}),a(Wi,{label:p(`detectionIntelligence.eventDetailPanel.track`,`Track`),value:t.trackId,mono:!0})]})]}),a(`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:a(`span`,{title:c?void 0:Pi,children:e(Y,{variant:`secondary`,onClick:ae,disabled:!c||_.isPending,children:[_.isPending?a(G,{className:`h-3.5 w-3.5 animate-spin`}):a(b,{className:`h-3.5 w-3.5`}),` `,p(`detectionIntelligence.eventDetailPanel.deleteTrack`,`Delete track`)]})})})]})})}var Ki={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`},qi={setRelation:`debug.gt.setRelation`,setPurity:`debug.gt.setPurity`,list:`debug.gt.list`},Ji=T(`/addon/pipeline-analytics/tape-export`),Yi=10*6e4;function Xi(e){return`${Ji}?tapeId=${encodeURIComponent(e)}`}var Zi=`The server answered in a shape this build does not understand.`;function Qi(e){return e instanceof Error?e.message:X.t(`helpers.eventsDebugTapes.actionFailed`)}function $i(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 ea(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 ta(e,t){let n=e[t];return typeof n==`boolean`?n:null}function na(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 ra(e){return e===`off`||e===`recording`||e===`refused`||e===`failing`||e===`unknown`}function ia(e){if(!$i(e))return null;let t=Q(e,`deviceId`),n=e.state,r=Q(e,`gapsSinceArmed`),i=ea(e,`segmentsHeld`),a=ea(e,`bytesLastHour`),o=ea(e,`bytesHeld`);if(t===null||!ra(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 aa(e){return $i(e)?na(e.cameras,ia):null}function oa(e){if(!$i(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=ta(e,`reviewed`),f=ta(e,`released`),p=na(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 sa(e){return $i(e)?na(e.tapes,oa):null}function ca(e){if(!$i(e))return null;let t=$(e,`trackId`),n=Q(e,`firstT`),r=Q(e,`lastT`),i=Q(e,`boundFrames`),a=$(e,`cls`),o=ta(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 la(e){if(!$i(e))return null;let t=$(e,`tapeId`),n=Q(e,`deviceId`),r=Q(e,`fromMs`),i=Q(e,`toMs`),a=ta(e,`reviewed`),o=na(e.lanes,ca);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 ua(e){if(!$i(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 da(e){if(!$i(e))return null;let t=e.status;if(t===`released`){let n=Q(e,`unpinned`),r=ta(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 fa(e){if(!$i(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 pa(e){switch(e.status){case`released`:case`deleted`:return null;case`already-released`:return X.t(`helpers.eventsDebugTapes.alreadyReleased`);case`not-found`:return X.t(`helpers.eventsDebugTapes.notFound`);case`pins-owed`:return X.t(`helpers.eventsDebugTapes.pinsOwed`);case`unavailable`:return X.t(`helpers.eventsDebugTapes.unavailable`,{reason:e.reason})}}function ma(e){if(!$i(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 ha(e){if(!$i(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 ga(e){if(!$i(e))return null;let t=na(e.relations,ma),n=na(e.purities,ha),r=ta(e,`truncated`);return t===null||n===null||r===null?null:{relations:t,purities:n,truncated:r}}function _a(e){if(!e.truncated)return null;let t=e.relations.length+e.purities.length;return X.t(`helpers.eventsDebugTapes.truncatedMarks`,{count:t})}function va(e){return e.filter(e=>e.segmentsHeld===null||e.segmentsHeld>0).map(e=>({deviceId:e.deviceId,segmentsUnknown:e.segmentsHeld===null}))}function ya(e){return e.slice(1).map((t,n)=>({trackId:e[n]??t,otherTrackId:t}))}function ba(e){return e.flatMap((t,n)=>e.slice(n+1).map(e=>({trackId:t,otherTrackId:e})))}function xa(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 Sa(e){switch(e.state){case`off`:return X.t(`helpers.eventsDebugTapes.statusOff`);case`recording`:return X.t(`helpers.eventsDebugTapes.statusRecording`);case`refused`:return X.t(`helpers.eventsDebugTapes.statusRefused`,{reason:e.reason??X.t(`helpers.eventsDebugTapes.unknownReason`)});case`failing`:return X.t(`helpers.eventsDebugTapes.statusFailing`,{reason:e.reason??X.t(`helpers.eventsDebugTapes.unknownReason`)});case`unknown`:return X.t(`helpers.eventsDebugTapes.statusUnknown`,{reason:e.reason??X.t(`helpers.eventsDebugTapes.unknownReason`)})}}var Ca={"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 wa(e,t){let n=Ca[e]??`Refused (${e}).`;return t.length>0?`${n} ${t}`:n}function Ta(e){if(e.length===0)return null;let t=new Date(e).getTime();return Number.isFinite(t)?t:null}function Ea(e){return e<1024*1024?X.t(`helpers.eventsDebugTapes.sizeKb`,{value:(e/1024).toFixed(0)}):X.t(`helpers.eventsDebugTapes.sizeMb`,{value:(e/1024/1024).toFixed(1)})}function Da(e){return e===null?`unknown`:Ea(e)}function Oa(e){return e===null?`unknown`:String(e)}function ka(e,t){let n=t.trim();return e===404?X.t(`helpers.eventsDebugTapes.exportUnknown`):e===503?n.length>0?n:X.t(`helpers.eventsDebugTapes.tapesUnavailable`):e===500?n.length>0?n:X.t(`helpers.eventsDebugTapes.exportUnreadable`):X.t(`helpers.eventsDebugTapes.downloadFailed`,{status:e})}l();function Aa({cameras:t,call:n,onPromoted:r}){let{t:i}=Z(),[o,c]=s(``),[l,u]=s(``),[d,f]=s(``),[p,m]=s(``),[h,g]=s(``),[_,v]=s(`auto`),[y,b]=s(!1),[x,S]=s(null),C=async()=>{let e=Number.parseInt(o===``?t[0]?.value??``:o,10),i=Ta(l),a=Ta(d);if(!Number.isFinite(e)||i===null||a===null){S(`Pick a camera and both ends of the window.`);return}b(!0),S(null);try{let t=ua(await n(Ki.promote,{deviceId:e,fromMs:i,toMs:a,scenario:p,...h.trim().length>0?{note:h.trim()}:{},..._===`day`||_===`ir`?{lighting:_}:{}}));t===null?S(Zi):t.ok?(S(`Promoted ${t.tapeId}: ${String(t.frames)} frames, ${Ea(t.bytes)}, ${String(t.pinnedTracks)} tracks pinned`+(t.state===`incomplete`?` — incomplete (it has gaps) and cannot become a case.`:`.`)),r()):S(wa(t.reason,t.detail))}catch(e){S(Qi(e))}finally{b(!1)}};return e(`div`,{className:`flex flex-wrap items-end gap-2 rounded-md border border-border px-3 py-2`,children:[a(`div`,{className:`w-40`,children:a(tt,{value:o,options:[...t],onChange:e=>c(e.target.value),"aria-label":i(`eventsDebugTapesPromoteForm.camera`,`Camera`)})}),a(ct,{type:`datetime-local`,"aria-label":i(`eventsDebugTapesPromoteForm.from`,`From`),value:l,onChange:e=>u(e.target.value),className:`w-48`}),a(ct,{type:`datetime-local`,"aria-label":i(`eventsDebugTapesPromoteForm.to`,`To`),value:d,onChange:e=>f(e.target.value),className:`w-48`}),a(ct,{"aria-label":i(`eventsDebugTapesPromoteForm.scenario`,`Scenario`),placeholder:`101-door-groups`,value:p,onChange:e=>m(e.target.value),className:`w-44`}),a(ct,{"aria-label":i(`eventsDebugTapesPromoteForm.note`,`Note`),placeholder:i(`eventsDebugTapesPromoteForm.optionalNote`,`optional note`),value:h,onChange:e=>g(e.target.value),className:`w-52`}),a(`div`,{className:`w-28`,children:a(tt,{value:_,"aria-label":i(`eventsDebugTapesPromoteForm.lighting`,`Lighting`),options:[{value:`auto`,label:i(`eventsDebugTapesPromoteForm.lightingAuto`,`Lighting: auto`)},{value:`day`,label:i(`eventsDebugTapes.dayMode`)},{value:`ir`,label:`IR`}],onChange:e=>v(e.target.value)})}),e(Y,{onClick:()=>void C(),disabled:y||t.length===0,children:[y?a(G,{className:`h-3.5 w-3.5 animate-spin`}):null,` `,i(`eventsDebugTapes.promoteWindow`)]}),a(`p`,{className:`w-full text-xs text-foreground-subtle`,children:i(`eventsDebugTapesPromoteForm.aPromotedTapeMayBe`,`A promoted tape may be shared as a test case — keep the scenario slug and note free of names or other personal data.`)}),x!==null&&a(`p`,{className:`w-full text-xs text-foreground`,children:x})]})}var ja=`pipeline-analytics`,Ma=`debug.listTracks`,Na=`debug.analyze`,Pa=T(`/addon/pipeline-analytics/debug-export`);function Fa(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Ia(e,t){let n=e[t];return typeof n==`string`?n:null}function La(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Ra(e,t){let n=e[t];return typeof n==`boolean`?n:null}function za(e){return e===`error`||e===`warn`||e===`info`}function Ba(e){if(!Fa(e))return null;let t=Ia(e,`code`),n=Ia(e,`detail`),r=e.severity;return t===null||n===null||!za(r)?null:{code:t,severity:r,detail:n}}function Va(e){if(!Fa(e))return null;let t=Ia(e,`trackId`),n=La(e,`deviceId`),r=Ia(e,`className`),i=La(e,`firstSeen`),a=La(e,`lastSeen`),o=La(e,`durationMs`),s=Ra(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=Ia(e,`label`),l=Ia(e,`subLabel`),u=Ia(e,`previewMissReason`),d=Ra(e,`markForTrain`),f=Ra(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:La(e,`importance`)??0,bestEventId:Ia(e,`bestEventId`)??``,...d===null?{}:{markForTrain:d},...f===null?{}:{favourited:f},debug:!0,...u===null||u.length===0?{}:{previewMissReason:u}}}function Ha(e){let t=Va(e);if(t===null||!Fa(e))return null;let n=La(e,`mediaCount`),r=La(e,`eventCount`),i=La(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=Ba(e);t!==null&&c.push(t)}let l=e.thumbnailProvenance;return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c,...ei(l)?{thumbnailProvenance:l}:{}}}function Ua(e){if(!Fa(e))return null;let t=Ra(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=Va(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function Wa(e){if(!Fa(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=Ha(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var Ga={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 Ka(e){return Ga[e]??e}var qa={error:0,warn:1,info:2};function Ja(e){return e.toSorted((e,t)=>qa[e.severity]-qa[t.severity]||e.code.localeCompare(t.code))}function Ya(e){return e.length===0?Pa:`${Pa}?deviceIds=${e.join(`,`)}`}function Xa(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 Za(e,t){return`${String(e)}:${t}`}function Qa(e,t){let n=[],r=new Set;for(let i of e){let e=Za(i.deviceId,i.trackId);!t.has(e)||r.has(e)||(r.add(e),n.push({deviceId:i.deviceId,trackId:i.trackId}))}return n}l();function $a({tapeId:t,call:n,onClose:r,onChanged:i}){let{t:o}=Z(),l=c({queryKey:[`events-debug`,`tapes`,`tracks`,t],queryFn:async()=>la(await n(Ki.tracks,{tapeId:t}))}),u=l.data??null,d=c({queryKey:[`events-debug`,`tapes`,`marks`,t],enabled:u!==null,queryFn:async()=>u===null?null:ga(await n(qi.list,{deviceId:u.deviceId,since:u.fromMs-Yi,until:u.toMs+Yi,limit:5e3}))}),[f,p]=s([]),[m,h]=s(``),[g,_]=s(null),v=e=>p(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),y=async e=>{_(null);try{for(let[t,r]of e)await n(t,r);p([]),await d.refetch(),i()}catch(e){_(Qi(e))}};if(u===null)return l.isLoading?a(`p`,{className:`text-xs`,children:o(`eventsDebugTapesReview.loadingTheTape`,`Loading the tape…`)}):a(Ee,{message:Zi});let b=u.deviceId,x=(e,t)=>y(e.map(e=>[qi.setRelation,{deviceId:b,...e,relation:t}])),S=e=>{let t=Number.parseFloat(m),n=e===`mixed`&&Number.isFinite(t)?u.fromMs+t*1e3:void 0;return y(f.map(t=>[qi.setPurity,{deviceId:b,trackId:t,purity:e,...n===void 0?{}:{switchAtMs:Math.round(n)}}]))},C=d.data==null?null:_a(d.data);return e(`div`,{className:`space-y-2 rounded-md border border-primary/40 px-3 py-2`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[a(`span`,{className:`text-xs font-medium`,children:o(`eventsDebugTapes.reviewLanes`,{id:u.tapeId,count:u.lanes.length})}),a(Y,{disabled:f.length<2,onClick:()=>void x(ya(f),`same-subject`),children:o(`eventsDebugTapesReview.sameSubject`,`Same subject`)}),a(Y,{variant:`secondary`,disabled:f.length<2,onClick:()=>void x(ba(f),`different-subjects`),children:o(`eventsDebugTapesReview.differentSubjects`,`Different subjects`)}),a(ct,{"aria-label":o(`eventsDebugTapesReview.changedAtSFromTape`,`Changed at (s from tape start)`),placeholder:o(`eventsDebugTapesReview.changedAtS`,`changed at s`),value:m,onChange:e=>h(e.target.value),className:`w-28`}),a(Y,{variant:`secondary`,disabled:f.length!==1,onClick:()=>void S(`mixed`),children:o(`eventsDebugTapesReview.mixed`,`Mixed`)}),a(Y,{variant:`secondary`,disabled:f.length===0,onClick:()=>void S(`not-a-subject`),children:o(`eventsDebugTapesReview.notASubject`,`Not a subject`)}),a(Y,{variant:u.reviewed?`secondary`:`primary`,onClick:()=>void y([[Ki.review,{tapeId:u.tapeId,reviewed:!u.reviewed}]]).then(()=>l.refetch()),children:u.reviewed?o(`eventsDebugTapesReview.markNotReviewed`,`Mark not reviewed`):o(`eventsDebugTapesReview.markReviewed`,`Mark reviewed`)}),a(Y,{variant:`ghost`,onClick:r,children:o(`common.close`,`Close`)})]}),g!==null&&a(Ee,{message:g}),C!==null&&a(Ee,{variant:`warning`,message:C}),a(`ul`,{className:`space-y-1`,children:u.lanes.toSorted((e,t)=>e.firstT-t.firstT).map(e=>a(eo,{lane:e,marks:d.data===null||d.data===void 0?[]:xa(e.trackId,d.data),selected:f.includes(e.trackId),onToggle:()=>v(e.trackId)},e.trackId))})]})}function eo({lane:t,marks:n,selected:r,onToggle:i}){let{t:o}=Z(),{src:s}=Vt(t.stillStored?Ht(`track`,t.trackId):void 0);return e(`li`,{className:`flex items-center gap-2 text-xs`,children:[a(`input`,{type:`checkbox`,"aria-label":o(`eventsDebugTapesReview.select`,`select {{trackId}}`,{trackId:t.trackId}),checked:r,onChange:i}),s===null?a(`div`,{className:`h-10 w-10 rounded bg-surface-hover`}):a(`img`,{src:s,alt:t.trackId,className:`h-10 w-10 rounded object-cover`}),a(`span`,{className:`font-mono`,children:t.trackId}),a(`span`,{children:t.cls}),a(`span`,{className:`text-foreground-subtle`,children:o(`eventsDebugTapes.laneFrames`,{range:`${Xa(t.firstT)} → ${Xa(t.lastT)}`,count:t.boundFrames})}),!t.stillStored&&a(`span`,{className:`text-foreground-subtle`,children:o(`eventsDebugTapesReview.notStoredMarkedThroughThe`,`not stored — marked through the tape`)}),n.map(e=>a(xt,{variant:`info`,children:e},e))]})}l();var to=`camstack_admin_token`;function no(){let e=U();return(t,n)=>e.trpcClient.addons.custom.mutate({addonId:ja,action:t,input:n})}async function ro(e,t){let n=localStorage.getItem(to),r={};n!==null&&(r.Authorization=`Bearer ${n}`);let i=await fetch(Xi(e),{headers:r});if(!i.ok){let e=await i.text().catch(()=>``);throw Error(ka(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 io(){let{t:e}=Z(),[t,n]=s(!1);return a(_e,{expanded:t,onExpandedChange:n,header:a(`span`,{className:`text-sm font-medium text-foreground`,children:e(`eventsDebugTapes.trackingTapes`,`Tracking tapes`)}),children:a(ao,{})})}function ao(){let{t}=Z(),r=no(),i=Ie({isCamera:!0,projection:`slim`}),o=n(()=>{let e=new Map;for(let t of i.data??[])e.set(t.id,t.name);return n=>e.get(n)??t(`cameraLoad.deviceLabel`,{deviceId:n})},[i.data,t]),l=c({queryKey:[`events-debug`,`tapes`,`status`],queryFn:async()=>aa(await r(Ki.status,{}))}),u=c({queryKey:[`events-debug`,`tapes`,`list`],queryFn:async()=>sa(await r(Ki.list,{}))}),[d,f]=s(null),[p,m]=s(null),h=async e=>{m(null);try{await ro(e.id,`${e.scenario}.tape-bundle.json.gz`)}catch(e){m(Qi(e))}},_=async e=>{let t=da(await r(Ki.release,{tapeId:e.id}));if(t===null)throw Error(Zi);let n=pa(t);if(n!==null)throw Error(n);await u.refetch()},v=async e=>{let t=fa(await r(Ki.remove,{tapeId:e.id}));if(t===null)throw Error(Zi);let n=pa(t);if(n!==null)throw Error(n);await u.refetch()};return e(`div`,{className:`space-y-3`,children:[a(`p`,{className:`text-xs text-foreground-subtle`,children:a(Lt,{i18nKey:`eventsDebugTapes.intro`,components:{b:a(`strong`,{}),code:a(`code`,{})}})}),p!==null&&a(Ee,{message:p}),l.isLoading&&a(`p`,{className:`text-xs text-foreground-subtle`,children:t(`eventsDebugTapes.loadingCameraStatus`,`Loading camera status…`)}),l.data===null&&a(Ee,{message:`The server answered in a shape this build does not understand.`}),e(`table`,{className:`w-full text-xs`,children:[a(`thead`,{children:e(`tr`,{className:`text-left text-foreground-subtle`,children:[a(`th`,{children:t(`eventsDebugTapes.camera`,`Camera`)}),a(`th`,{children:t(`eventsDebugTapes.state`,`State`)}),a(`th`,{children:t(`eventsDebugTapes.framesMin`,`Frames/min`)}),a(`th`,{children:t(`eventsDebugTapes.lastHour`,`Last hour`)}),a(`th`,{children:t(`eventsDebugTapes.held`,`Held`)}),a(`th`,{children:t(`eventsDebugTapes.gaps`,`Gaps`)})]})}),a(`tbody`,{children:(l.data??[]).map(n=>e(`tr`,{children:[a(`td`,{children:o(n.deviceId)}),a(`td`,{children:a(xt,{variant:n.state===`recording`?`success`:n.state===`off`?`default`:n.state===`unknown`?`warning`:`danger`,children:Sa(n)})}),a(`td`,{children:n.framesPerMin===void 0?`—`:String(Math.round(n.framesPerMin))}),a(`td`,{title:n.shelfError,children:Da(n.bytesLastHour)}),a(`td`,{title:n.shelfError,children:t(`eventsDebugTapes.segsHeld`,{count:Oa(n.segmentsHeld),size:Da(n.bytesHeld)})}),a(`td`,{children:String(n.gapsSinceArmed)})]},n.deviceId))})]}),a(Aa,{cameras:va(l.data??[]).map(e=>({value:String(e.deviceId),label:e.segmentsUnknown?t(`eventsDebugTapes.segmentsUnknown`,`{{value1}} (segments unknown)`,{value1:o(e.deviceId)}):o(e.deviceId)})),call:r,onPromoted:()=>void u.refetch()}),u.isLoading&&a(`p`,{className:`text-xs text-foreground-subtle`,children:t(`eventsDebugTapes.loadingPromotedTapes`,`Loading promoted tapes…`)}),u.data===null&&a(Ee,{message:`The server answered in a shape this build does not understand.`}),e(`table`,{className:`w-full text-xs`,children:[a(`thead`,{children:e(`tr`,{className:`text-left text-foreground-subtle`,children:[a(`th`,{children:t(`eventsDebugTapes.scenario`,`Scenario`)}),a(`th`,{children:t(`eventsDebugTapes.camera`,`Camera`)}),a(`th`,{children:t(`eventsDebugTapes.window`,`Window`)}),a(`th`,{children:t(`eventsDebugTapes.state`,`State`)}),a(`th`,{children:t(`eventsDebugTapes.tracks`,`Tracks`)}),a(`th`,{})]})}),a(`tbody`,{children:(u.data??[]).map(n=>e(`tr`,{children:[a(`td`,{children:n.scenario}),a(`td`,{children:o(n.deviceId)}),e(`td`,{children:[new Date(n.fromMs).toLocaleString(),` · `,Xa(n.toMs-n.fromMs),` `,`· `,n.lighting]}),e(`td`,{children:[a(xt,{variant:n.state===`complete`?`success`:`warning`,children:n.state}),` `,n.reviewed&&a(xt,{variant:`info`,children:t(`eventsDebugTapes.reviewed`)}),` `,n.released&&a(xt,{children:t(`eventsDebugTapes.released`)})]}),a(`td`,{children:t(`eventsDebugTapes.storedOf`,{stored:String(n.tracksStillStored),total:String(n.tracks.length)})}),e(`td`,{className:`space-x-1 text-right`,children:[a(Y,{variant:`secondary`,"aria-label":t(`eventsDebugTapes.review`,`Review {{scenario}}`,{scenario:n.scenario}),onClick:()=>f(n.id),children:t(`eventsDebugTapes.review2`,`Review`)}),a(Y,{variant:`ghost`,"aria-label":t(`eventsDebugTapes.download`,`Download {{scenario}}`,{scenario:n.scenario}),onClick:()=>void h(n),children:a(g,{className:`h-3.5 w-3.5`})}),a(Ze,{label:t(`eventsDebugTapes.release`,`Release`),icon:M,title:t(`eventsDebugTapes.release2`,`Release {{scenario}}?`,{scenario:n.scenario}),description:t(`eventsDebugTapes.releasingReturnsThisTapeS`,`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:t(`eventsDebugTapes.release`,`Release`),triggerVariant:`ghost`,confirmVariant:`danger`,disabled:n.released,action:()=>_(n)}),a(Ze,{label:t(`common.delete`,`Delete`),icon:b,title:t(`eventsDebugTapes.delete`,`Delete {{scenario}}?`,{scenario:n.scenario}),description:t(`eventsDebugTapes.deletingRemovesThePromotedBundle`,`Deleting removes the promoted bundle and its index row for good. Its tracks' pins are released first — this cannot be undone.`),confirmLabel:t(`common.delete`,`Delete`),triggerVariant:`ghost`,confirmVariant:`danger`,action:()=>v(n)})]})]},n.id))})]}),d!==null&&a($a,{tapeId:d,call:r,onClose:()=>f(null),onChanged:()=>void u.refetch()})]})}l();var oo=`all`,so=`The server answered in a shape this build does not understand.`,co={error:`danger`,warn:`warning`,info:`info`};function lo({findings:e}){let{t}=Z();return e.length===0?a(xt,{variant:`success`,children:t(`eventsDebug.noAnomalyFound`,`no anomaly found`)}):a(`div`,{className:`flex flex-wrap gap-1`,children:Ja(e).map(e=>a(xt,{variant:co[e.severity],title:e.detail,children:Ka(e.code)},e.code))})}function uo({track:t,report:n,analyzing:r}){let{t:i}=Z(),o=ii(n?.previewMissReason??t.previewMissReason);return e(`div`,{className:`space-y-1 border-t border-border pt-1.5`,children:[n===void 0?a(`span`,{className:`text-[10px] text-foreground-subtle`,children:r?i(`eventsDebug.analysing`,`analysing…`):i(`eventsDebug.notAnalysed`,`not analysed`)}):e(d,{children:[a(lo,{findings:n.findings}),a(`p`,{className:`text-[10px] text-foreground-subtle`,title:n.mediaKinds.length>0?n.mediaKinds.join(`, `):i(`eventsDebug.noMediaOfAnyKind`,`no media of any kind`),children:i(`eventsDebug.reportCounts`,{media:String(n.mediaCount),events:String(n.eventCount),positions:String(n.positionCount)})})]}),o!==null&&a(`p`,{className:`text-[10px] text-foreground-subtle`,title:o.raw,children:o.sentence})]})}function fo(){let{t}=Z(),r=U(),[i,o]=s(oo),[l,u]=s(!1),[d,f]=s(null),[m,h]=s(new Set),[_,v]=s(null),[y,b]=s(null),[x,S]=s(null),[C,w]=s([]),T=Si(),E=Ie({isCamera:!0,projection:`slim`}),D=n(()=>[{value:oo,label:t(`eventsDebug.allCameras`,`All cameras`)},...(E.data??[]).map(e=>({value:String(e.id),label:e.name}))],[E.data,t]),O=n(()=>{let e=new Map;for(let t of E.data??[])e.set(t.id,t.name);return e},[E.data]),k=e=>O.get(e)??t(`eventsDebug.cameraFallback`,{deviceId:e}),j=n(()=>i===oo?[]:[Number.parseInt(i,10)],[i]),M=c({queryKey:[`events-debug`,`list`,j],queryFn:async()=>Ua(await r.trpcClient.addons.custom.mutate({addonId:ja,action:Ma,input:j.length===0?{}:{deviceIds:j}}))}),N=n(()=>(M.data?.tracks??[]).map(e=>e.trackId),[M.data]),P=c({queryKey:[`events-debug`,`analyze`,N],enabled:N.length>0,queryFn:async()=>Wa(await r.trpcClient.addons.custom.mutate({addonId:ja,action:Na,input:{trackIds:N}}))}),I=n(()=>{let e=new Map;for(let t of P.data?.reports??[])e.set(t.trackId,t);return e},[P.data]),L=M.data?.tracks??[],B=M.data===null||P.data===null,V=()=>{M.refetch(),P.refetch()},H=e=>{h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},W=()=>{h(new Set(L.map(e=>Za(e.deviceId,e.trackId))))},ee=()=>h(new Set),K=async(e,t)=>{let n=e===`analyzed`?{debug:!1}:{favourited:!0},r=0,i=[];for(let e of t)try{await T.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,flags:n}),r+=1}catch{i.push(e.trackId)}return{applied:r,refused:i}},te=e=>{if(!yi||y!==null)return;let t=Qa(L,m);t.length!==0&&(b(e),S(null),(async()=>{let n=await K(e,t);b(null);let r=new Set(n.refused);h(new Set(t.filter(e=>r.has(e.trackId)).map(e=>Za(e.deviceId,e.trackId)))),e===`analyzed`&&w(t.filter(e=>!r.has(e.trackId))),n.refused.length>0&&S(`${String(n.refused.length)} of ${String(t.length)} were refused by the server and are still selected. Check the hub log.`),M.refetch()})())},ne=()=>{let e=C;e.length===0||y!==null||(b(`analyzed`),S(null),(async()=>{for(let t of e)try{await T.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,flags:{debug:!0}})}catch{S(`Some tracks could not be re-marked. Refresh and try again.`)}b(null),w([]),M.refetch()})())},re=async()=>{u(!0),f(null);try{await Gt(Ya(j),`camstack-debug.zip`)}catch(e){f(e instanceof Error?e.message:`Export failed.`)}finally{u(!1)}},J=y!==null;return e(`section`,{className:`space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[a(`div`,{className:`w-44`,children:a(tt,{value:i,options:D,onChange:e=>o(e.target.value)})}),e(Y,{variant:`secondary`,onClick:V,disabled:M.isFetching,children:[M.isFetching?a(G,{className:`h-3.5 w-3.5 animate-spin`}):a(q,{className:`h-3.5 w-3.5`}),t(`common.refresh`,`Refresh`)]}),e(Y,{onClick:()=>void re(),disabled:l||L.length===0,children:[l?a(G,{className:`h-3.5 w-3.5 animate-spin`}):a(g,{className:`h-3.5 w-3.5`}),t(`eventsDebug.exportAll`,{count:String(L.length)})]}),L.length>0&&m.size<L.length&&a(Y,{variant:`ghost`,onClick:W,children:t(`eventsDebug.selectAll`,`Select all`)})]}),a(`p`,{className:`text-xs text-foreground-subtle`,children:a(Lt,{i18nKey:`eventsDebug.debugMarkNote`,components:{code:a(`code`,{}),strong:a(`strong`,{})}})}),a(io,{}),M.isError&&a(Ee,{message:t(`eventsDebug.couldNotLoadTheMarked`,`Could not load the marked tracks.`)}),B&&!M.isError&&a(Ee,{message:so}),d!==null&&a(Ee,{message:d}),x!==null&&a(Ee,{message:x}),M.data?.truncated===!0&&a(Ee,{message:t(`eventsDebug.aCameraFilledThePer`,`A camera filled the per-camera cap — some marked tracks are not listed. Un-mark a few, or filter to one camera.`)}),(P.data?.vanished.length??0)>0&&a(`p`,{className:`text-xs text-foreground-subtle`,children:t(`eventsDebug.vanished`,{count:String(P.data?.vanished.length)})}),m.size>0&&e(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[a(`span`,{className:`text-xs font-medium text-foreground`,children:t(`common.selectedCount`,{count:m.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[a(`span`,{title:yi?void 0:`Track flags arrive with the next server update`,children:e(Y,{variant:`secondary`,onClick:()=>te(`keep`),disabled:!yi||J,children:[y===`keep`?a(G,{className:`h-3.5 w-3.5 animate-spin`}):a(A,{className:`h-3.5 w-3.5`}),` `,t(`eventsDebug.keep`,`Keep`)]})}),a(`span`,{title:yi?void 0:`Track flags arrive with the next server update`,children:e(Y,{onClick:()=>te(`analyzed`),disabled:!yi||J,children:[y===`analyzed`?a(G,{className:`h-3.5 w-3.5 animate-spin`}):a(p,{className:`h-3.5 w-3.5`}),` `,t(`eventsDebug.analyzed`,`Analyzed`)]})}),a(Y,{variant:`ghost`,onClick:ee,disabled:J,children:a(F,{className:`h-3.5 w-3.5`})})]})]}),C.length>0&&e(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-border bg-surface px-3 py-2`,children:[a(`span`,{className:`text-xs text-foreground`,children:t(`eventsDebug.markedAnalyzed`,{count:String(C.length)})}),e(Y,{variant:`ghost`,onClick:ne,disabled:J,children:[a(z,{className:`h-3.5 w-3.5`}),` `,t(`eventsDebug.undo`)]}),a(Y,{variant:`ghost`,onClick:()=>w([]),disabled:J,children:a(F,{className:`h-3.5 w-3.5`})})]}),M.isLoading?a(Xe,{status:`pending`,pendingMessage:`Loading…`,testId:`debug-tracks-grid`}):L.length===0?a(Te,{icon:R,title:t(`eventsDebug.noTrackIsMarkedFor`,`No track is marked for debug`),description:t(`eventsDebug.markOneFromATrack`,`Mark one from a track's actions on the Feed to see it here.`)}):a(Xe,{status:`ready`,testId:`debug-tracks-grid`,children:L.map(e=>{let t=I.get(e.trackId);return a(oi,{row:e,cameraName:k(e.deviceId),nowMs:e.lastSeen,selected:m.has(Za(e.deviceId,e.trackId)),onToggleSelect:H,onOpenDetail:v,...t?.thumbnailProvenance===void 0?{}:{provenance:t.thumbnailProvenance},footer:a(uo,{track:e,report:t,analyzing:P.isFetching})},Za(e.deviceId,e.trackId))})}),_&&a(Gi,{row:_,cameraName:k(_.deviceId),deleteAvailable:Ni,onClose:()=>v(null),onDeleted:()=>{v(null),M.refetch()},onFlagsChanged:e=>{e.debug||(v(null),M.refetch())}})]})}var po=200,mo=3e4,ho=[];function go(e){let t=U(),n=e.deviceIds.length>0,r=[...e.deviceIds].sort((e,t)=>e-t),{data:i,isLoading:a}=c({queryKey:[`events-feed`,r,e.since,e.until,e.minImportance??null,e.classFilter??null],enabled:n,staleTime:mo,refetchInterval:mo,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEventsBatch.query({deviceIds:r,since:e.since,until:e.until,limit:po,...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:Jr(qr(i??ho),`importance`),isLoading:n&&a}}l();var _o=[`events-feed`],vo=2e3;function yo(e){let n=u(),r=e?.paused===!0,a=t(n);a.current=n;let c=t(r);c.current=r;let[l,d]=s(!1),f=i(()=>{a.current.invalidateQueries({queryKey:_o})},[]),p=t(void 0);p.current||=Br({delayMs:vo,invalidate:()=>{c.current?d(!0):f()}}),o(()=>()=>p.current?.cancel(),[]),o(()=>{r||!l||(d(!1),f())},[r,l,f]);let m=i(()=>{d(!1),f()},[f]);return ot(J.PipelineAnalyticsDetectionEvent,()=>{p.current?.trigger()}),ot(J.PipelineAnalyticsTrackEnded,()=>{p.current?.trigger()}),{pending:l,refreshNow:m}}l();function bo({groups:t,selected:r,onChange:i,loading:o=!1}){let{t:c}=Z(),l=Ge(),[u,d]=s(!1),[f,p]=s(``),[m,h]=s(new Set),g=f.trim().toLowerCase(),v=e=>g.length===0||He(e,c).toLowerCase().includes(g),y=n(()=>t.map(e=>({macro:e.macro,subs:e.subs.filter(t=>v(t)||v(e.macro))})).filter(e=>v(e.macro)||e.subs.length>0),[t,g]),b=e=>h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),x=e=>{let t=new Set(r),n=r.has(e.macro.kind)&&e.subs.every(e=>r.has(e.kind)),a=[e.macro.kind,...e.subs.map(e=>e.kind)];if(n)for(let e of a)t.delete(e);else for(let e of a)t.add(e);i(t)},S=e=>{let t=new Set(r);t.has(e)?t.delete(e):t.add(e),i(t)},C=()=>i(new Set),w=r.size;return e(`div`,{className:`relative`,children:[e(`button`,{type:`button`,onClick:()=>d(e=>!e),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${w>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(_,{className:`h-3.5 w-3.5`}),w>0?c(`detectionIntelligence.eventKindFilter.kinds`,`Kinds ({{value1}})`,{value1:String(w)}):c(`detectionIntelligence.eventKindFilter.kinds2`,`Kinds`),a(O,{className:`h-3 w-3`})]}),u&&e(`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:[e(`div`,{className:`mb-2 flex items-center gap-1 rounded border border-border px-1.5`,children:[a(W,{className:`h-3.5 w-3.5 text-foreground-subtle`}),a(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:c(`detectionIntelligence.eventKindFilter.searchKinds`,`Search kinds…`),className:`w-full bg-transparent py-1 text-xs outline-none`}),w>0&&a(`button`,{type:`button`,onClick:C,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:c(`detectionIntelligence.eventKindFilter.clear`,`Clear`)})]}),y.length===0&&a(`div`,{className:`px-1 py-2 text-[11px] text-foreground-subtle`,children:o?c(`detectionIntelligence.eventKindFilter.loadingKinds`,`Loading kinds…`):g.length>0?c(`detectionIntelligence.eventKindFilter.noKindMatchesThatSearch`,`No kind matches that search.`):c(`detectionIntelligence.eventKindFilter.theseCamerasAdvertiseNoEvent`,`These cameras advertise no event kinds.`)}),y.map(t=>{let n=ht(t.macro.iconId),i=m.has(t.macro.kind)||g.length>0,o=r.has(t.macro.kind);return e(`div`,{className:`mb-0.5`,children:[e(`div`,{className:`flex items-center gap-1`,children:[t.subs.length>0?a(`button`,{type:`button`,onClick:()=>b(t.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":c(`detectionIntelligence.eventKindFilter.expand`,`Expand`),children:a(i?O:N,{className:`h-3 w-3`})}):a(`span`,{className:`w-3`}),e(`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:[a(`input`,{type:`checkbox`,checked:o,onChange:()=>x(t),className:`accent-primary`}),a(n,{className:`h-3.5 w-3.5`,style:{color:l(t.macro.kind)}}),a(`span`,{className:`font-medium`,children:He(t.macro,c)})]})]}),i&&t.subs.map(t=>{let n=ht(t.iconId);return e(`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:[a(`input`,{type:`checkbox`,checked:r.has(t.kind),onChange:()=>S(t.kind),className:`accent-primary`}),a(n,{className:`h-3.5 w-3.5`,style:{color:l(t.kind)}}),a(`span`,{children:He(t,c)})]},t.kind)})]},t.macro.kind)})]})]})}function xo(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 So(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var Co=new Set([`detection`,`package`]);function wo(e,t){return[...xo(e,t).values()].filter(e=>e.parentKind===null&&Co.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function To(e,t){let n=xo(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,So(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))}l();function Eo(){let[e,n]=s(!1),r=t(null),[a,c]=s(0),l=i(e=>{r.current!==e&&(r.current=e,c(e=>e+1))},[]);return o(()=>{let e=r.current;if(!e||typeof IntersectionObserver>`u`){n(!1);return}let t=new IntersectionObserver(e=>{let t=e[e.length-1];t&&n(!t.isIntersecting)},{rootMargin:`64px 0px 0px 0px`,threshold:0});return t.observe(e),()=>t.disconnect()},[a]),{ref:l,scrolledPast:e}}l();var Do=[`events-feed`],Oo=60,ko=[{value:`importance`,labelKey:`detectionIntelligence.eventsSection.sortImportance`,icon:se},{value:`time`,labelKey:`detectionIntelligence.eventsSection.sortRecent`,icon:H}];function Ao(){let{t}=Z(),r=u(),i=ze(),c=Pe(),[l,f]=s(Rn),[p,m]=s(new Set),[h,g]=s(new Set),[_,v]=s(0),[y,x]=s(`time`),[S,C]=s(new Set),[w,T]=s(null),[E,D]=s(()=>Date.now());o(()=>{let e=setInterval(()=>D(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:O,until:k}=n(()=>Qr({fromMs:l.fromMs,toMs:l.toMs},E),[l.fromMs,l.toMs,E]),A=Eo(),{pending:j,refreshNow:M}=yo({paused:w!==null||S.size>0||A.scrolledPast}),{data:N=[]}=Ie({isCamera:!0,projection:`slim`}),P=n(()=>N.map(e=>e.id),[N]),{data:I,isLoading:L}=Ot({deviceIds:P},{enabled:P.length>0,staleTime:5*6e4}),R=n(()=>To(I??[],p),[I,p]),z=Ii(),B=z.isPending,{rows:H,isLoading:U}=go({deviceIds:P,since:O,until:k,minImportance:_>0?_:void 0,classFilter:h.size===1?[...h][0]:void 0}),W=n(()=>{let e=new Map;for(let t of N??[])e.set(t.id,t.name);return e},[N]),ee=e=>W.get(e)??t(`detectionIntelligence.cameraFallback`,{id:String(e)}),K=n(()=>Gn(H).map(e=>({id:e,name:ee(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[H,W]),te=n(()=>Jr(Yr(H,{cameras:p,classes:h,minImportance:_}),y),[H,p,h,_,y]),q=tr(te,Oo,n(()=>JSON.stringify([[...p].sort((e,t)=>e-t),[...h].sort(),_,y,O,k]),[p,h,_,y,O,k])),ne=()=>{r.invalidateQueries({queryKey:Do})},re=()=>C(new Set);function J(e){C(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function ie(){if(S.size===0||!Ni)return;let e=Zr(H,S),n=[...e.values()].reduce((e,t)=>e+t.length,0);n!==0&&(async()=>{await c({title:t(`detectionIntelligence.eventsSection.deleteTitle`,{count:n}),message:t(`detectionIntelligence.eventsSection.deleteMessage`,{count:n}),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&ae(e)})()}function ae(e){let n=[...e];Promise.allSettled(n.map(([e,t])=>z.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{ne();let r=[],a=new Set;if(e.forEach((e,t)=>{let i=n[t];if(!i)return;let[o,s]=i;if(e.status===`fulfilled`)for(let e of s)a.add(Xr(o,e));else r.push(o)}),C(e=>{let t=new Set(e);for(let e of a)t.delete(e);return t}),r.length>0){let e=r.map(e=>ee(e)).join(`, `);i({title:t(`detectionIntelligence.eventsSection.someTracksWereNotDeleted`,`Some tracks were not deleted`),message:t(`detectionIntelligence.eventsSection.failedToDeleteTracksOn`,`Failed to delete tracks on: {{names}}. They remain selected — retry, or check the server logs.`,{names:e}),variant:`danger`})}})}let oe=te.length!==H.length;return e(`div`,{className:`relative space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[a(lr,{onChange:f}),a(sr,{cameras:K,selected:p,onChange:m}),a(bo,{groups:R,selected:h,onChange:g,loading:L}),e(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[a(`span`,{children:t(`detectionIntelligence.eventsSection.minScore`,`Min score`)}),a(`input`,{type:`range`,min:0,max:1,step:.05,value:_,onChange:e=>v(Number(e.target.value)),className:`h-1 w-24 cursor-pointer accent-primary`,"aria-label":t(`detectionIntelligence.eventsSection.minimumImportance`,`Minimum importance`)}),a(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(_*100)})]}),a(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:ko.map(n=>{let r=n.icon;return e(`button`,{type:`button`,onClick:()=>x(n.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${y===n.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(r,{className:`h-3.5 w-3.5`}),` `,t(n.labelKey)]},n.value)})}),!U&&a(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:oe?t(`detectionIntelligence.eventsSection.ofEvents`,`{{value1}} of {{value2}} events`,{value1:String(te.length),value2:String(H.length)}):t(`detectionIntelligence.eventsSection.eventCount`,{count:te.length})})]}),S.size>0&&e(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[a(`span`,{className:`text-xs font-medium text-foreground`,children:t(`common.selectedCount`,{count:S.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[a(`span`,{title:Ni?void 0:`Track deletion arrives with the next server update`,children:e(Y,{variant:`secondary`,onClick:ie,disabled:!Ni||B,children:[B?a(G,{className:`h-3.5 w-3.5 animate-spin`}):a(b,{className:`h-3.5 w-3.5`}),` `,t(`common.delete`,`Delete`)]})}),a(Y,{variant:`ghost`,onClick:re,disabled:B,children:a(F,{className:`h-3.5 w-3.5`})})]})]}),j&&a(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:a(`button`,{type:`button`,onClick:M,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:t(`detectionIntelligence.eventsSection.newEventsRefresh`,`New events — refresh`)})}),U?a(Xe,{status:`pending`,pendingMessage:`Loading events…`,testId:`events-grid`}):te.length===0?a(Te,{icon:V,title:oe?t(`detectionIntelligence.eventsSection.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.eventsSection.noKeyEventsInThis`,`No key events in this window`),description:oe?t(`detectionIntelligence.eventsSection.widenTheDateRangeClear`,`Widen the date range, clear cameras or kinds, or lower the min score.`):t(`detectionIntelligence.eventsSection.capturedTracksAppearHereWhen`,`Captured tracks appear here when the pipeline scores a key event.`)}):e(d,{children:[a(`div`,{ref:A.ref,"aria-hidden":!0,className:`h-0`}),a(Xe,{status:`ready`,testId:`events-grid`,children:q.pageItems.map(e=>a(oi,{row:e,cameraName:ee(e.deviceId),nowMs:E,selected:S.has(Xr(e.deviceId,e.trackId)),onToggleSelect:J,onOpenDetail:T},Xr(e.deviceId,e.trackId)))}),a(ir,{currentPage:q.page,totalItems:q.totalItems,pageSize:q.pageSize,onPageChange:q.setPage,itemNoun:`events`})]}),w&&a(Gi,{row:w,cameraName:ee(w.deviceId),deleteAvailable:Ni,onClose:()=>T(null),onDeleted:()=>{ne(),T(null)},onFlagsChanged:e=>{T(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug,favourited:e.favourited}:t)}})]})}var jo=`/addon/training`;function Mo(){let{t}=Z(),n=Rt();return e(Mt,{className:`flex flex-col gap-3 border-border bg-surface p-3 sm:flex-row sm:items-center sm:gap-4`,"data-testid":`events-feed-retrain-cta`,children:[e(`div`,{className:`flex min-w-0 flex-1 items-start gap-2.5`,children:[a(S,{className:`mt-0.5 h-4 w-4 shrink-0 text-primary`,"aria-hidden":!0}),e(`div`,{className:`min-w-0 space-y-0.5`,children:[a(`p`,{className:`text-xs font-medium text-foreground`,children:t(`detectionIntelligence.retrainTabCallout.trainingFromThisFeed`,`Training from this feed`)}),a(`p`,{className:`${re} leading-relaxed`,children:t(`detectionIntelligence.retrainTabCallout.markATrackWithThe`,`Mark a track with the graduation-cap control on its card. On Training you correct frames, build collections, and start cloud fine-tunes.`)})]})]}),a(Y,{variant:`outline`,size:`sm`,className:`shrink-0 self-start sm:self-center`,onClick:()=>n(jo),children:t(`detectionIntelligence.retrainTabCallout.openTraining`,`Open Training`)})]})}l();var No=50,Po=350,Fo=[{value:`loose`,labelKey:`detectionIntelligence.semanticEventSearch.looseLabel`,titleKey:`detectionIntelligence.semanticEventSearch.looseTitle`},{value:`balanced`,labelKey:`detectionIntelligence.semanticEventSearch.balancedLabel`,titleKey:`detectionIntelligence.semanticEventSearch.balancedTitle`},{value:`strict`,labelKey:`detectionIntelligence.semanticEventSearch.strictLabel`,titleKey:`detectionIntelligence.semanticEventSearch.strictTitle`}];function Io(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 Lo({onActiveChange:t}){let{t:r}=Z(),[i,c]=s(``),[l,u]=s(`loose`),[d,f]=s(null),[p,m]=s(null),[h,g]=s(null),_=pt(i,Po).trim(),v=_.length>0;o(()=>{t(v)},[v,t]);let[y,b]=s(()=>Date.now());o(()=>{let e=setInterval(()=>b(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:x=[]}=Ie({isCamera:!0,projection:`slim`}),S=n(()=>{let e=new Map;for(let t of x)e.set(t.id,t.name);return e},[x]),C=e=>S.get(e)??r(`detectionIntelligence.cameraFallback`,{id:String(e)}),w=n(()=>x.map(e=>e.id),[x]),{data:T}=Ot({deviceIds:w},{enabled:w.length>0,staleTime:5*6e4}),E=n(()=>wo(T??[],new Set(p===null?[]:[p])),[T,p]);o(()=>{d!==null&&(E.some(e=>e.kind===d)||f(null))},[E,d]);let{data:D,isFetching:O,isError:k,error:A}=at({text:_,strictness:l,limit:No,classFilter:d??void 0,deviceId:p??void 0},{enabled:v}),j=n(()=>[...D??[]].sort((e,t)=>t.score-e.score).map(e=>({...Io(e),score:e.score})),[D]);function M(e){f(t=>t===e?null:e)}return e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(`div`,{className:`relative min-w-[16rem] flex-1`,children:[a(W,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),a(`input`,{type:`text`,value:i,onChange:e=>c(e.target.value),placeholder:r(`detectionIntelligence.semanticEventSearch.semanticSearchDescribeWhatYou`,`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":r(`detectionIntelligence.semanticEventSearch.semanticEventSearch`,`Semantic event search`)}),i&&a(`button`,{type:`button`,onClick:()=>c(``),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":r(`detectionIntelligence.semanticEventSearch.clearSearch`,`Clear search`),children:a(F,{className:`h-3.5 w-3.5`})})]}),O&&v&&a(G,{className:`h-4 w-4 shrink-0 animate-spin text-foreground-subtle`})]}),e(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[a(`div`,{className:`flex items-center gap-1`,children:E.map(e=>a(`button`,{type:`button`,onClick:()=>M(e.kind),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${d===e.kind?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:He(e)},e.kind))}),e(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[a(`span`,{children:r(`detectionIntelligence.semanticEventSearch.camera`,`Camera`)}),a(tt,{value:p===null?``:String(p),onChange:e=>m(e.target.value===``?null:Number(e.target.value)),className:`h-7 text-xs`,"aria-label":r(`detectionIntelligence.semanticEventSearch.filterByCamera`,`Filter by camera`),options:[{value:``,label:r(`detectionIntelligence.semanticEventSearch.all`,`All`)},...x.map(e=>({value:String(e.id),label:e.name}))]})]}),e(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[a(`span`,{children:r(`detectionIntelligence.semanticEventSearch.match`,`Match`)}),a(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Fo.map(e=>a(`button`,{type:`button`,onClick:()=>u(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${l===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:r(e.titleKey),children:r(e.labelKey)},e.value))})]}),v&&!O&&!k&&a(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:r(`common.matches`,{count:j.length})})]})]}),v&&e(`div`,{className:`space-y-3`,children:[k&&e(`p`,{className:`py-4 text-xs text-danger`,children:[r(`detectionIntelligence.semanticEventSearch.searchFailed`,`Search failed:`),` `,A instanceof Error?A.message:r(`detectionIntelligence.semanticEventSearch.unknownError`,`unknown error`),`. Check that the CLIP embedding step is enabled.`]}),!k&&O&&j.length===0&&a(Xe,{status:`pending`,pendingMessage:`Searching…`,testId:`semantic-events-grid`}),!k&&!O&&j.length===0&&a(Xe,{status:`empty`,emptyMessage:r(`detectionIntelligence.semanticEventSearch.noSemanticMatchesForTry`,`No semantic matches for “{{debounced}}”. Try a looser match threshold or a different phrasing.`,{debounced:_}),testId:`semantic-events-grid`}),!k&&j.length>0&&a(Xe,{status:`ready`,testId:`semantic-events-grid`,children:j.map(e=>a(oi,{row:e,cameraName:C(e.deviceId),nowMs:y,score:e.score,onOpenDetail:g},e.id))})]}),h&&a(Gi,{row:h,cameraName:C(h.deviceId),deleteAvailable:Ni,onClose:()=>g(null),onDeleted:()=>g(null)})]})}l();function Ro(e,t){let n=Math.max(0,Math.round((e-t)/6e4));if(n<1)return X.t(`helpers.relativeTime.justNow`);if(n<60)return`${String(n)}m`;let r=Math.floor(n/60);return`${String(r)}h ${String(n%60)}m`}function zo({row:t,cameraName:n,nowMs:r}){let{t:i}=Z(),o=Vt(t.keyFrameMediaId===void 0?void 0:Wt(t.keyFrameMediaId));return e(`div`,{className:`flex flex-col overflow-hidden rounded-md border border-border bg-surface`,children:[e(`div`,{className:`relative aspect-video overflow-hidden bg-surface-hover`,children:[o.src?a(`img`,{src:o.src,alt:i(`detectionIntelligence.stationarySection.parkedOn`,`Parked {{className}} on {{cameraName}}`,{className:t.className,cameraName:n}),className:`h-full w-full object-cover`}):a(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:a(le,{className:`h-6 w-6`})}),a(`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:t.label??t.className})]}),e(`div`,{className:`flex flex-col gap-0.5 p-1.5`,children:[a(`span`,{className:`truncate text-[11px] text-foreground`,children:n}),a(`span`,{className:`text-[10px] text-foreground-subtle`,children:i(`common.parkedSince`,{since:Ro(r,t.becameStationaryAt)})})]})]})}function Bo(){let{t}=Z(),[r,i]=s(!1),o=Date.now(),{data:c=[]}=Ie({isCamera:!0,projection:`slim`}),l=n(()=>c.map(e=>e.id),[c]),u=n(()=>{let e=new Map;for(let t of c)e.set(t.id,t.name);return e},[c]),{rows:d,unreadableCount:f}=Bt(l);return d.length===0&&f===0?null:e(`div`,{className:`rounded-md border border-border bg-surface/40`,children:[e(`button`,{type:`button`,onClick:()=>i(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,children:[a(r?O:N,{className:`h-4 w-4 text-foreground-subtle`}),a(le,{className:`h-4 w-4 text-foreground-subtle`}),a(`span`,{className:`text-sm font-semibold text-foreground`,children:t(`detectionIntelligence.stationarySection.stationary`,`Stationary`)}),a(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:d.length}),a(`span`,{className:`ml-2 text-[11px] text-foreground-subtle`,children:t(`detectionIntelligence.stationarySection.parkedObjectsKeptOutOf`,`Parked objects — kept out of the event feed`)}),f>0?a(`span`,{className:`ml-2 text-[11px] text-warning`,children:t(`detectionIntelligence.stationarySection.unreadable`,{count:f})}):null]}),r&&a(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:d.map(e=>a(zo,{row:e,cameraName:u.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:o},e.id))})]})}l();function Vo(){let[t,n]=s(!1);return e(`section`,{className:`space-y-3`,children:[a(Mo,{}),a(Lo,{onActiveChange:n}),!t&&a(Bo,{}),!t&&a(Ao,{})]})}function Ho(){let{t:e}=Z(),[t]=It();return t.get(`section`)===`retrain`?a(Ft,{to:`/addon/training`,replace:!0}):a(zt,{sectionsOnly:!0,paramName:`section`,defaultSection:`feed`,sectionsLabel:`Events sections`,sections:[{id:`feed`,label:e(`events.feed`,`Feed`),content:a(Vo,{})},{id:`debug`,label:e(`events.debug`,`Debug`),content:a(fo,{})}]})}function Uo(e){return e==null?null:e.cropUrl!==void 0&&e.cropUrl.length>0?e.cropUrl:e.base64!==void 0&&e.base64.length>0?`data:image/jpeg;base64,${e.base64}`:null}l();var Wo=[[`plateGallery`]];function Go({plateIds:t,vehicles:n,onDone:r}){let{t:i}=Z(),o=u(),c=we(),l=st(),[d,f]=s(``),[p,m]=s(!1),[h,g]=s(null),_=t!==null&&t.length>0,v=t?.length??0;function y(){m(!1),f(``),g(null)}function b(){y(),r()}function x(e){!t||t.length===0||c.mutate({plateIds:[...t],vehicleId:e},{onSettled:()=>{o.invalidateQueries({queryKey:Wo}),b()}})}function S(){!t||!d.trim()||l.mutate({name:d.trim()},{onSuccess:e=>{e?.id&&x(e.id)},onError:()=>{o.invalidateQueries({queryKey:Wo}),b()}})}let C=c.isPending||l.isPending;return a(Je,{open:_,onOpenChange:e=>!e&&b(),children:e(dt,{children:[e(Be,{children:[a(Dt,{children:v>1?i(`detectionIntelligence.assignPlateDialog.assignPlatesToVehicle`,`Assign {{value1}} plates to vehicle`,{value1:String(v)}):i(`detectionIntelligence.assignPlateDialog.assignPlateToVehicle`,`Assign plate to vehicle`)}),a($e,{children:i(`detectionIntelligence.assignPlateDialog.selectAnExistingVehicleOr`,`Select an existing vehicle or create a new one.`)})]}),a(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:n.map(t=>e(`button`,{type:`button`,onClick:()=>g(t.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${h===t.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[a(`span`,{className:`font-medium`,children:t.name}),a(`span`,{className:`ml-2 text-foreground-subtle`,children:i(`detectionIntelligence.assignPlateDialog.plates`,{count:t.sampleCount})})]},t.id))}),p?a(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:a(ct,{placeholder:i(`detectionIntelligence.assignPlateDialog.newVehicleName`,`New vehicle name…`),value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&S()},autoFocus:!0,className:`flex-1`})}):a(`button`,{type:`button`,onClick:()=>{g(null),m(!0)},className:`mt-2 w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle hover:border-primary hover:text-primary transition-colors`,children:i(`detectionIntelligence.assignPlateDialog.newVehicle`,`+ New vehicle…`)}),e(Qe,{children:[a(Y,{variant:`secondary`,onClick:b,disabled:C,children:i(`common.cancel`,`Cancel`)}),p?e(Y,{variant:`primary`,onClick:S,disabled:C||!d.trim(),children:[C&&a(G,{className:`h-3.5 w-3.5 animate-spin`}),i(`detectionIntelligence.assignPlateDialog.createAssign`,`Create & assign`)]}):e(Y,{variant:`primary`,onClick:()=>h&&x(h),disabled:C||!h,children:[C&&a(G,{className:`h-3.5 w-3.5 animate-spin`}),v>1?i(`detectionIntelligence.assignCount`,{count:v}):i(`common.assign`)]})]})]})})}l();var Ko=[[`plateGallery`]];function qo(e){let[t,n]=s(null),[r,i]=s(null),[a,c]=s(!1);return o(()=>{if(n(null),i(null),c(!1),e===void 0)return;let t=!1,r=null;return(async()=>{try{let i=await Ut(Wt(e));if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||c(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),o(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>c(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function Jo(e){let t=e.filter(e=>e.url.length>0);return t.length===0?null:t.find(e=>/crop|plate/i.test(e.kind))??t[0]}function Yo({label:t,value:n,mono:r}){return e(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[a(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:t}),a(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${r?`font-mono`:``}`,title:n,children:n})]})}function Xo({box:e}){let{t}=Z();return a(`div`,{className:`pointer-events-none absolute rounded-[3px] border-2 border-primary shadow-[0_0_0_9999px_rgba(0,0,0,0.28)]`,style:{left:`${String(e.x*100)}%`,top:`${String(e.y*100)}%`,width:`${String(e.width*100)}%`,height:`${String(e.height*100)}%`},children:a(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:t(`detectionIntelligence.plateDetailPanel.plate`,`Plate`)})})}function Zo({plate:t,cameraName:r,onClose:i,onAssign:c,onUnassign:l,onDelete:d,actionsPending:f}){let{t:m}=Z(),h=u(),{data:g,isFetching:_}=Ae({plateId:t?.plateId??``},{enabled:t!==null}),y=Me(),[x,S]=s(`frame`),[w,T]=s(!1),[E,D]=s(``),{frameSrc:O,naturalWidth:k,naturalHeight:A,failed:j}=qo(t?.keyFrameMediaId);o(()=>{T(!1),D(``),S(`frame`)},[t?.plateId]);let M=n(()=>{let e=Jo(g??[]);return e?e.url:Uo(t)},[g,t]),N=n(()=>!t?.plateBbox||k===null||A===null?null:dr(t.plateBbox,k,A),[t?.plateBbox,k,A]);if(t===null)return null;let P=t.keyFrameMediaId!==void 0&&!j,I=P&&x===`frame`,R=t.assigned?t.vehicleName??`Assigned`:t.recognizedVehicleId?`${t.vehicleName??`Recognized`} (suggested)`:`Unassigned`,z=`${String(Math.round(t.score*100))}%${t.corrected?` · corrected`:``}`;function B(){t&&(D(t.text),T(!0))}function V(){if(!t)return;let e=E.trim().toUpperCase();if(!e||e===t.text){T(!1);return}y.mutate({plateId:t.plateId,text:e},{onSettled:()=>{h.invalidateQueries({queryKey:Ko}),T(!1)}})}return a(Je,{open:!0,onOpenChange:e=>!e&&i(),children:e(dt,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":m(`detectionIntelligence.plateDetailPanel.plateDetail`,`Plate 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:[a(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:e(`div`,{className:`min-w-0`,children:[a(`div`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:t.text||m(`detectionIntelligence.plateDetailPanel.plateDetail`,`Plate detail`)}),a(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:r})]})}),e(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[P&&e(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[e(`button`,{type:`button`,onClick:()=>S(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${x===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(L,{className:`h-3.5 w-3.5`}),` `,m(`detectionIntelligence.detailPanel.fullFrame`)]}),e(`button`,{type:`button`,onClick:()=>S(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${x===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(he,{className:`h-3.5 w-3.5`}),` `,m(`detectionIntelligence.detailPanel.crop`)]})]}),I&&O?a(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:a(pr,{src:O,alt:m(`detectionIntelligence.plateDetailPanel.fullFrameWithDetectedPlate`,`Full frame with detected plate`),fit:`natural`,className:`w-full`,overlay:N?a(Xo,{box:N}):void 0})}):M?e(`div`,{className:`relative aspect-[2/1] w-full overflow-hidden rounded-lg border border-border bg-background`,children:[a(pr,{src:M,alt:m(`detectionIntelligence.plateDetailPanel.detectedPlate`,`Detected plate`),className:`h-full w-full`}),_&&a(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:a(G,{className:`h-3.5 w-3.5 animate-spin`})})]}):e(`div`,{className:`flex aspect-[2/1] w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[a(K,{className:`h-8 w-8 text-warning/70`}),a(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:m(`detectionIntelligence.plateDetailPanel.noImage`,`No image`)}),a(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:m(`detectionIntelligence.plateDetailPanel.theCropMediaForThis`,`The crop media for this plate could not be resolved. Safe to delete.`)})]}),a(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-2`,children:e(`div`,{className:`flex items-center justify-between gap-3`,children:[a(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:m(`detectionIntelligence.plateDetailPanel.plateText`,`Plate text`)}),w?e(`div`,{className:`flex min-w-0 flex-1 items-center justify-end gap-1.5`,children:[a(ct,{value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`&&V(),e.key===`Escape`&&T(!1)},className:`h-7 max-w-[10rem] text-right font-mono text-xs uppercase`,autoFocus:!0}),a(`button`,{type:`button`,onClick:V,disabled:y.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":m(`detectionIntelligence.plateDetailPanel.saveCorrectedText`,`Save corrected text`),children:y.isPending?a(G,{className:`h-3.5 w-3.5 animate-spin`}):a(p,{className:`h-3.5 w-3.5`})}),a(`button`,{type:`button`,onClick:()=>T(!1),className:`text-foreground-subtle hover:text-foreground`,"aria-label":m(`common.cancel`,`Cancel`),children:a(F,{className:`h-3.5 w-3.5`})})]}):e(`button`,{type:`button`,onClick:B,className:`group flex min-w-0 items-center gap-1.5`,title:m(`detectionIntelligence.plateDetailPanel.correctTheOcrReading`,`Correct the OCR reading`),children:[a(`span`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:t.text||`—`}),a(v,{className:`h-3 w-3 shrink-0 text-foreground-subtle group-hover:text-foreground`})]})]})}),e(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[a(Yo,{label:m(`detectionIntelligence.plateDetailPanel.camera`,`Camera`),value:r}),a(Yo,{label:m(`detectionIntelligence.plateDetailPanel.captured`,`Captured`),value:Xn(t.timestamp)}),a(Yo,{label:m(`detectionIntelligence.plateDetailPanel.confidence`,`Confidence`),value:z}),a(Yo,{label:m(`detectionIntelligence.plateDetailPanel.vehicle`,`Vehicle`),value:R}),a(Yo,{label:m(`detectionIntelligence.plateDetailPanel.track`,`Track`),value:t.trackId,mono:!0})]})]}),e(`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:[t.assigned?e(Y,{variant:`secondary`,onClick:()=>l(t.plateId),disabled:f,children:[a(pe,{className:`h-3.5 w-3.5`}),` `,m(`detectionIntelligence.detailPanel.detach`)]}):e(Y,{variant:`primary`,onClick:()=>c(t.plateId),disabled:f,children:[a(C,{className:`h-3.5 w-3.5`}),` `,m(`common.assign`)]}),e(Y,{variant:`secondary`,onClick:()=>d(t.plateId),disabled:f,children:[a(b,{className:`h-3.5 w-3.5`}),` `,m(`common.delete`)]})]})]})})}l();var Qo=[[`plateGallery`]],$o=500,es=120;function ts({plate:t,cameraName:n,nowMs:r,selected:i,onToggleSelect:o,onAssign:s,onOpenDetail:c}){let{t:l}=Z(),d=u(),f=Fe(),p=be(),m=()=>{d.invalidateQueries({queryKey:Qo})},h=()=>c(t.plateId),g=Uo(t);return e(`div`,{className:`relative flex flex-col overflow-hidden rounded-md border bg-surface ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[e(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[g===null?e(`button`,{type:`button`,onClick:h,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:l(`detectionIntelligence.recentPlates.noCropImageThePlate`,`No crop image — the plate's crop media is missing. Safe to delete.`),children:[a(K,{className:`h-7 w-7 text-warning/70`}),a(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:l(`detectionIntelligence.recentPlates.noCrop`,`No crop`)})]}):a(`img`,{src:g,alt:l(`detectionIntelligence.recentPlates.plateFrom`,`Plate {{text}} from {{cameraName}}`,{text:t.text,cameraName:n}),onClick:h,className:`h-full w-full cursor-zoom-in object-cover`}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(t.plateId)},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":i?l(`detectionIntelligence.recentPlates.deselect`,`Deselect`):l(`detectionIntelligence.recentPlates.select`,`Select`),children:i?a(de,{className:`h-4 w-4 text-primary`}):a(k,{className:`h-4 w-4`})}),t.corrected&&e(`span`,{className:`absolute right-0 top-0 z-10 flex items-center gap-0.5 rounded-bl-md bg-primary/80 px-1 py-0.5 text-[8px] font-semibold uppercase tracking-wide text-white`,title:l(`detectionIntelligence.recentPlates.manuallyCorrected`,`Manually corrected`),children:[a(fe,{className:`h-3 w-3`}),` `,l(`detectionIntelligence.recentPlates.fixed`)]})]}),e(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[a(`p`,{className:`truncate font-mono text-xs font-bold tracking-wide text-foreground`,title:t.text,children:t.text||`—`}),a(`p`,{className:`truncate text-[10px] text-foreground-subtle`,title:n,children:n}),a(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:Jn(t.timestamp,r)}),t.vehicleName&&a(`p`,{className:`truncate text-[10px] font-medium text-primary`,title:t.vehicleName,children:t.vehicleName})]}),e(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[t.assigned?a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),f.mutate({plateId:t.plateId},{onSettled:m})},disabled:f.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":l(`detectionIntelligence.recentPlates.detachPlate`,`Detach plate`),title:l(`detectionIntelligence.recentPlates.detach`,`Detach`),children:f.isPending?a(G,{className:`h-4 w-4 animate-spin`}):a(pe,{className:`h-4 w-4`})}):a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s(t.plateId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":l(`detectionIntelligence.recentPlates.assignPlateToVehicle`,`Assign plate to vehicle`),title:l(`detectionIntelligence.recentPlates.assignToVehicle`,`Assign to vehicle`),children:a(C,{className:`h-4 w-4`})}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),p.mutate({plateId:t.plateId},{onSettled:m})},disabled:p.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":l(`detectionIntelligence.recentPlates.deletePlate`,`Delete plate`),title:l(`detectionIntelligence.recentPlates.deletePlate`,`Delete plate`),children:p.isPending?a(G,{className:`h-4 w-4 animate-spin`}):a(b,{className:`h-4 w-4`})})]})]})}var ns=[{labelKey:`common.all`,value:`all`},{labelKey:`detectionIntelligence.recentPlates.filterUnassigned`,value:`unassigned`},{labelKey:`detectionIntelligence.recentPlates.filterAssigned`,value:`assigned`}];function rs(e,t){return t===`unassigned`?e.filter(e=>!e.assigned):t===`assigned`?e.filter(e=>e.assigned):e}function is(){let{t}=Z(),r=u(),[i,o]=s(`all`),[c,l]=s(Rn),[f,p]=s(new Set),[m,h]=s(new Set),[g,_]=s(null),[v,y]=s(null),{data:x,isLoading:S}=je({limit:$o,includeCrops:!1},{refetchInterval:3e4}),{data:w=[]}=De(),{data:T}=Ie({isCamera:!0,projection:`slim`}),E=Fe(),D=Nt(),O=be(),k=Date.now(),A=x??[],j=n(()=>{let e=new Map;for(let t of T??[])e.set(t.id,t.name);return e},[T]),M=e=>j.get(e)??t(`detectionIntelligence.cameraFallback`,{id:String(e)}),N=n(()=>Gn(A).map(e=>({id:e,name:M(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[A,j]),P=n(()=>Wn(Un(rs(A,i),c),f),[A,i,c,f]),I=tr(P,es,n(()=>JSON.stringify([i,c.fromMs,c.toMs,[...f].sort((e,t)=>e-t)]),[i,c.fromMs,c.toMs,f])),L=n(()=>new Map(A.map(e=>[e.plateId,e])),[A]),R=v===null?null:L.get(v)??null,z=()=>{r.invalidateQueries({queryKey:Qo})},B=()=>h(new Set);function V(e){h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}let H=[...m],U=D.isPending||O.isPending,W=E.isPending||O.isPending;function ee(){H.length!==0&&D.mutate({plateIds:H},{onSettled:()=>{z(),B()}})}function te(){H.length!==0&&Promise.allSettled(H.map(e=>O.mutateAsync({plateId:e}))).then(()=>{z(),B()})}function q(e){y(null),_([e])}function ne(e){E.mutate({plateId:e},{onSettled:z}),y(null)}function re(e){O.mutate({plateId:e},{onSettled:z}),y(null)}let J=P.length!==A.length;return e(`div`,{className:`relative space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[a(`div`,{className:`flex items-center gap-1`,children:ns.map(e=>a(`button`,{type:`button`,onClick:()=>o(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${i===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:t(e.labelKey)},e.value))}),a(lr,{onChange:l}),a(sr,{cameras:N,selected:f,onChange:p}),!S&&a(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:J?t(`detectionIntelligence.recentPlates.ofPlates`,`{{value1}} of {{value2}} plates`,{value1:String(P.length),value2:String(A.length)}):t(`detectionIntelligence.recentPlates.plateCount`,{count:P.length})})]}),m.size>0&&e(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[a(`span`,{className:`text-xs font-medium text-foreground`,children:t(`common.selectedCount`,{count:m.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[e(Y,{variant:`primary`,onClick:()=>_(H),disabled:U,children:[a(C,{className:`h-3.5 w-3.5`}),` `,t(`common.assign`)]}),e(Y,{variant:`secondary`,onClick:ee,disabled:U,children:[D.isPending?a(G,{className:`h-3.5 w-3.5 animate-spin`}):a(pe,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.recentPlates.detach`,`Detach`)]}),e(Y,{variant:`secondary`,onClick:te,disabled:U,children:[a(b,{className:`h-3.5 w-3.5`}),` `,t(`common.delete`)]}),a(Y,{variant:`ghost`,onClick:B,disabled:U,children:a(F,{className:`h-3.5 w-3.5`})})]})]}),S?a(Xe,{status:`pending`,pendingMessage:`Loading plates…`,testId:`plates-grid`}):P.length===0?a(Te,{icon:K,title:A.length>0?t(`detectionIntelligence.recentPlates.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.recentPlates.noPlatesRecognizedYet`,`No plates recognized yet`),description:A.length>0?t(`detectionIntelligence.recentPlates.widenTheDateRangeOr`,`Widen the date range or clear the camera filter.`):t(`detectionIntelligence.recentPlates.plateReadsAppearHereWhen`,`Plate reads appear here when the detection pipeline OCRs a vehicle.`)}):e(d,{children:[a(Xe,{status:`ready`,testId:`plates-grid`,children:I.pageItems.map(e=>a(ts,{plate:e,cameraName:M(e.deviceId),nowMs:k,selected:m.has(e.plateId),onToggleSelect:V,onAssign:e=>_([e]),onOpenDetail:y},e.plateId))}),a(ir,{currentPage:I.page,totalItems:I.totalItems,pageSize:I.pageSize,onPageChange:I.setPage,itemNoun:`plates`})]}),a(Zo,{plate:R,cameraName:R?M(R.deviceId):``,onClose:()=>y(null),onAssign:q,onUnassign:ne,onDelete:re,actionsPending:W}),a(Go,{plateIds:g,vehicles:w,onDone:()=>{_(null),B()}})]})}l();var as=[[`plateGallery`]];function os({vehicleId:t}){let{t:n}=Z(),r=u(),{data:i,isLoading:o}=Ne({vehicleId:t}),s=Oe();function c(e){s.mutate({vehicleId:t,sampleId:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:as})}})}return o?e(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[a(G,{className:`h-3.5 w-3.5 animate-spin`}),n(`detectionIntelligence.vehiclesList.loadingPlates`,`Loading plates…`)]}):!i||i.length===0?a(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:n(`detectionIntelligence.vehiclesList.noPlatesYet`,`No plates yet.`)}):a(`div`,{className:`mt-2 grid grid-cols-3 gap-2 sm:grid-cols-4 md:grid-cols-6`,children:i.map(t=>e(`div`,{className:`group relative overflow-hidden rounded-md border border-border bg-surface`,children:[e(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[t.base64?a(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:t.text,className:`h-full w-full object-cover`}):a(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:a(h,{className:`h-6 w-6`})}),a(`button`,{type:`button`,onClick:()=>c(t),disabled:s.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":n(`detectionIntelligence.vehiclesList.removePlateSample`,`Remove plate sample`),children:a(F,{className:`h-4 w-4 text-white`})})]}),a(`p`,{className:`truncate px-1.5 py-1 text-center font-mono text-[11px] font-semibold tracking-wide text-foreground`,title:t.text,children:t.text})]},t.id))})}function ss(t){return[{key:`vehicle`,header:X.t(`detectionIntelligence.vehiclesList.vehicle`,`Vehicle`),sortValue:e=>e.name,render:t=>e(`span`,{className:`flex min-w-0 items-center gap-2`,children:[a(`span`,{className:`h-8 w-12 shrink-0 overflow-hidden rounded border border-border bg-surface-hover`,children:a(qt,{mediaId:t.coverMediaId,base64:t.coverBase64,alt:t.name,className:`h-full w-full object-cover`,placeholder:a(`span`,{className:`flex h-full w-full items-center justify-center`,children:a(h,{className:`h-4 w-4 text-foreground-subtle`})})})}),a(`span`,{className:`truncate text-sm font-medium text-foreground`,children:t.name})]})},{key:`samples`,header:X.t(`detectionIntelligence.vehiclesList.plates`,`Plates`),align:`center`,nowrap:!0,sortValue:e=>e.sampleCount,render:e=>a(xt,{variant:`default`,className:`text-[10px]`,children:e.sampleCount})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:n=>e(`span`,{className:`flex items-center justify-end gap-1`,children:[a(Tt,{variant:`ghost`,size:`sm`,icon:v,"aria-label":X.t(`detectionIntelligence.vehiclesList.edit`,`Edit {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onEdit(n)}}),a(Tt,{variant:`ghost`,size:`sm`,icon:b,"aria-label":X.t(`detectionIntelligence.vehiclesList.delete`,`Delete {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onDelete(n)}})]})}]}function cs({mode:t,vehicle:n,onClose:r}){let{t:i}=Z(),c=u(),[l,d]=s(t===`edit`?n?.name??``:``),f=st(),p=ke();o(()=>{d(t===`edit`?n?.name??``:``)},[t,n?.id,n?.name]);let m=f.isPending||p.isPending,g=l.trim(),_=t===`edit`&&n!==null&&g===n.name,v=m||g.length===0||_;function y(){c.invalidateQueries({queryKey:as})}function b(){if(!v){if(t===`new`){f.mutate({name:g},{onSuccess:()=>{y(),r()}});return}if(n===null){r();return}p.mutate({id:n.id,name:g},{onSuccess:()=>{y(),r()}})}}return a(et,{open:!0,onClose:r,title:t===`new`?`Add vehicle`:`Edit ${n?.name??`vehicle`}`,icon:h,width:t===`edit`?`xl`:`lg`,testId:`vehicles-vehicle-form`,footer:e(Y,{variant:`primary`,size:`sm`,type:`button`,onClick:b,disabled:v,children:[m?a(G,{className:`h-3.5 w-3.5 animate-spin`}):null,t===`new`?i(`common.add`,`Add`):i(`common.save`,`Save`)]}),children:e(`div`,{className:`space-y-4`,children:[a(Le,{label:i(`detectionIntelligence.vehiclesList.name`,`Name`),required:!0,children:a(ct,{value:l,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b()},placeholder:i(`detectionIntelligence.vehiclesList.vehicleName`,`Vehicle name…`),autoFocus:!0})}),t===`edit`&&n!==null&&e(`div`,{children:[a(`p`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:i(`detectionIntelligence.vehiclesList.plateSamples`,`Plate samples`)}),a(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:i(`detectionIntelligence.vehiclesList.removeAPlateCropTo`,`Remove a plate crop to drop it from recognition for this vehicle. Assign new plates from Recent recognized plates.`)}),a(os,{vehicleId:n.id})]})]})})}function ls(){let{t}=Z(),r=u(),i=Pe(),{data:s,isLoading:c}=De(),l=it(),{state:d,openNew:p,openEdit:m,close:g}=yt(),_=s??[],v=_t(_,{searchText:e=>[e.name]}),y=d.mode===`edit`?_.find(e=>e.id===d.id)??null:null;o(()=>{d.mode===`edit`&&!c&&y===null&&g()},[d.mode,c,y,g]);let b=n(()=>ss({onEdit:e=>m(e.id),onDelete:e=>{(async()=>{await i({title:t(`detectionIntelligence.vehiclesList.deleteVehicle`,`Delete vehicle`),message:t(`detectionIntelligence.vehiclesList.deleteAndAllItsPlate`,`Delete {{name}} and all its plate samples? This cannot be undone.`,{name:e.name}),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&l.mutate({id:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:as}),d.mode===`edit`&&d.id===e.id&&g()}})})()}}),[i,g,l,d,m,r,t]);if(c)return e(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[a(G,{className:`h-4 w-4 animate-spin`}),t(`detectionIntelligence.vehiclesList.loadingVehicles`,`Loading vehicles…`)]});let x=d.mode===`new`||d.mode===`edit`&&y!==null;return e(`div`,{className:`space-y-2`,children:[a(`div`,{className:`flex flex-wrap items-center gap-2`,children:e(Y,{variant:`primary`,size:`sm`,type:`button`,onClick:p,children:[a(f,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.vehiclesList.addVehicle`,`Add vehicle`)]})}),(_.length>0||v.active)&&a(ut,{state:v.state,facets:v.facets,labels:{searchPlaceholder:`Search vehicles…`,searchLabel:`Search vehicles`,facetsLabel:`Filter`,clearLabel:`Clear`},onSearch:v.setSearch,onToggleFacet:v.toggleFacet,onClear:v.clear}),v.rows.length===0?a(Te,{icon:h,title:v.active?t(`detectionIntelligence.vehiclesList.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.vehiclesList.noVehiclesEnrolledYet`,`No vehicles enrolled yet`),description:v.active?t(`detectionIntelligence.vehiclesList.clearTheSearchOrTry`,`Clear the search or try another name.`):t(`detectionIntelligence.vehiclesList.addAVehicleThenAssign`,`Add a vehicle, then assign plate crops from Recent recognized plates.`)}):a(Se,{columns:b,rows:v.rows,rowKey:e=>e.id,maxBodyHeight:kt,emptyMessage:t(`detectionIntelligence.vehiclesList.noVehiclesEnrolledYet2`,`No vehicles enrolled yet.`),onRowClick:e=>m(e.id)}),x&&a(cs,{mode:d.mode===`new`?`new`:`edit`,vehicle:y,onClose:g})]})}l();var us=[[`plateGallery`]],ds=2e3;function fs(){let e=u(),n=t(e);n.current=e;let r=t(void 0);r.current||=Br({delayMs:ds,invalidate:()=>{n.current.invalidateQueries({queryKey:us})}}),o(()=>()=>r.current?.cancel(),[]),ot(J.PipelineAnalyticsPlateGalleryChanged,()=>{r.current?.trigger()})}function ps(){let{t}=Z();return fs(),e(`div`,{className:`space-y-3`,children:[a(jt,{headingId:`library-vehicles`,title:t(`plates.vehicles`,`Vehicles`),icon:h,testId:`library-section-vehicles`,children:e(`div`,{className:`${m} space-y-3`,children:[a(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`plates.enrolledVehicleIdentitiesUsedFor`,`Enrolled vehicle identities used for plate recognition. Open a vehicle to rename it or remove plate samples.`)}),a(ls,{})]})}),a(jt,{headingId:`library-recent-plates`,title:t(`plates.recentRecognizedPlates`,`Recent recognized plates`),icon:ce,testId:`library-section-recent-plates`,children:e(`div`,{className:`${m} space-y-3`,children:[a(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`plates.licensePlatesReadByThe`,`License plates read by the detection pipeline. Assign them to a vehicle, correct the OCR text, or delete.`)}),a(is,{})]})})]})}function ms(e){return e.states.length===0?3:e.latched?0:e.verdict===`diverged`?1:e.verdict===`unknown`?2:4}function hs(e){let t=[e.divergedAt,e.restoredAt].filter(e=>typeof e==`number`);return t.length===0?null:Math.max(...t)}function gs(e,t){let n=new Map(e.map(e=>[e.deviceId,e.deviceName])),r=[];for(let e of t)for(let t of e.monitors)r.push({deviceId:e.deviceId,deviceName:n.get(e.deviceId)??`Camera ${e.deviceId}`,monitor:t});return r.toSorted((e,t)=>{let n=ms(e.monitor)-ms(t.monitor);if(n!==0)return n;let r=hs(e.monitor)??-1,i=hs(t.monitor)??-1;if(r!==i)return i-r;let a=e.deviceName.localeCompare(t.deviceName);return a===0?e.monitor.label.localeCompare(t.monitor.label):a})}l();var _s={alarm:`danger`,ok:`success`,unknown:`default`},vs={alarm:`Alarm`,ok:`OK`,unknown:`Unknown`};function ys(e,t){let n=hs(e);return n===null?`—`:X.t(`scenes.transitionAgo`,{duration:ee(Math.max(0,t-n))})}function bs(e){return P(e.monitor).tone}function xs(e){let t=Number(e);return Number.isFinite(t)&&t>0?t:null}function Ss(){let{t}=Z(),i=Ie({isCamera:!0,projection:`slim`}),c=n(()=>(i.data??[]).map(e=>({deviceId:e.id,deviceName:e.name})).sort((e,t)=>e.deviceName.localeCompare(t.deviceName)),[i.data]),l=n(()=>c.map(e=>e.deviceId),[c]),u=Kt(l),d=n(()=>gs(c,u.results),[c,u.results]),p=_t(d,{searchText:e=>[e.monitor.label,e.deviceName],facetValue:bs}),{state:m,openNew:h,openEdit:g,close:_}=yt(),[v,y]=s(null);o(()=>{if(m.mode===`new`){y(e=>e??l[0]??null);return}y(null)},[m.mode,l]);let b=m.mode===`edit`?xs(m.id):null,S=b===null?``:c.find(e=>e.deviceId===b)?.deviceName??`#${b}`,C=Date.now(),w=[{key:`label`,header:t(`scenes.scene`,`Scene`),sortValue:e=>e.monitor.label,render:e=>a(`span`,{className:`font-medium`,children:e.monitor.label})},{key:`camera`,header:t(`scenes.camera`,`Camera`),nowrap:!0,sortValue:e=>e.deviceName,render:e=>e.deviceName},{key:`state`,header:t(`scenes.state`,`State`),nowrap:!0,sortValue:e=>bs(e),render:e=>{let t=P(e.monitor);return a(xt,{variant:_s[t.tone],children:t.text})}},{key:`status`,header:t(`scenes.whatItSays`,`What it says`),notSortableReason:`Status is a live sentence, not a comparable value`,render:e=>a(`span`,{className:`text-xs text-foreground-muted`,children:I(e.monitor,C)})},{key:`coverage`,header:t(`scenes.variants`,`Variants`),notSortableReason:`Coverage is a summary string`,render:e=>a(`span`,{className:`text-xs text-foreground-muted`,children:B(e.monitor)})},{key:`transition`,header:t(`scenes.lastChange`,`Last change`),align:`right`,nowrap:!0,sortValue:e=>hs(e.monitor)??0,render:e=>a(`span`,{className:`text-xs tabular-nums text-foreground-muted`,children:ys(e.monitor,C)})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:e=>a(Y,{variant:`ghost`,onClick:()=>g(String(e.deviceId)),children:t(`scenes.open`,`Open`)})}];return e(`section`,{className:`space-y-3`,children:[e(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between sm:gap-4`,children:[a(`p`,{className:`text-xs text-foreground-subtle`,children:t(`scenes.aSceneWatchesOneRegion`,`A scene watches one region of one camera and tells you when it stops looking like the picture you captured — a wheelie bin, a gate, a parking space.`)}),e(Y,{onClick:h,disabled:c.length===0,className:`shrink-0`,children:[a(f,{className:`mr-1 h-3.5 w-3.5`}),t(`scenes.newScene`,`New scene`)]})]}),u.unreachableCount>0?a(`p`,{className:`text-xs text-warning`,children:t(`scenes.unreachable`,{count:u.unreachableCount})}):null,(d.length>0||p.active)&&a(ut,{state:p.state,facets:p.facets,labels:{searchPlaceholder:`Search scenes…`,searchLabel:`Search scenes`,facetsLabel:`State`,clearLabel:`Clear`},facetLabel:e=>vs[e]??e,onSearch:p.setSearch,onToggleFacet:p.toggleFacet,onClear:p.clear}),a(Mt,{variant:`flat`,className:`p-0`,children:a(Se,{columns:w,rows:p.rows,rowKey:e=>`${e.deviceId}:${e.monitor.id}`,minWidthPx:880,bordered:!1,maxBodyHeight:kt,emptyMessage:u.isLoading?t(`scenes.loadingScenes`,`Loading scenes…`):p.active?t(`scenes.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`scenes.noScenesYetPressNew`,`No scenes yet. Press “New scene”, pick a camera, then draw a box around the thing you want watched.`)})}),m.mode===`new`?e(et,{open:!0,onClose:_,title:t(`scenes.whichCamera`,`Which camera?`),icon:x,width:`sm`,testId:`scenes-camera-picker`,footer:a(Y,{onClick:()=>{v!==null&&g(String(v))},disabled:v===null,children:t(`scenes.continue`,`Continue`)}),children:[a(`p`,{className:`mb-3 text-xs text-foreground-subtle`,children:t(`scenes.aSceneLivesOnOne`,`A scene lives on one camera. Pick the one that can see the thing.`)}),a(tt,{value:v===null?``:String(v),onChange:e=>y(Number(e.target.value)),"aria-label":t(`scenes.camera`,`Camera`),options:c.map(e=>({value:String(e.deviceId),label:e.deviceName}))})]}):null,b===null?null:e(et,{open:!0,onClose:_,title:t(`scenes.scenes`,`Scenes — {{editingName}}`,{editingName:S}),icon:x,width:`lg`,testId:`scenes-editor`,children:[a(`p`,{className:`mb-3 text-xs text-foreground-subtle`,children:t(`scenes.drawABoxNameIt`,`Draw a box, name it, then capture what “normal” looks like. Daylight is enough — the night reference is optional, and “Settings” on each scene tunes how fussy and how often it checks.`)}),a(r,{fallback:a(`p`,{className:`text-xs text-foreground-muted`,children:t(`scenes.loadingTheEditor`,`Loading the editor…`)}),children:a(Ct,{deviceId:b})})]})]})}function Cs(){let{t:e}=Z(),t=Pt(`/library`,{t:e,isAdmin:!0})??{icon:me,title:e(`nav.library`,`Library`)};return a(zt,{icon:t.icon,title:t.title,subtitle:e(`library.peopleVehiclesCapturedEventsAnd`,`People, vehicles, captured events and scenes — what detection has recognised.`),defaultSection:`people`,sectionsLabel:`${t.title} sections`,sections:[{id:`people`,label:e(`library.people`,`People`),content:a(Wr,{})},{id:`vehicles`,label:e(`library.vehicles`,`Vehicles`),content:a(ps,{})},{id:`events`,label:e(`library.events`,`Events`),content:a(Ho,{}),ownedParams:[`section`]},{id:`scenes`,label:e(`library.scenes`,`Scenes`),content:a(Ss,{})}]})}export{Cs as LibraryPage};
1
+ import{C as e,J as t,K as n,Q as r,R as i,S as a,V as o,Y as s,a as c,et as l,o as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{An as f,Ci as p,D as m,Di as h,Gr as g,Gt as _,In as v,Ir as y,Lt as b,Oi as x,Or as S,Ot as C,Pt as w,Q as T,Qr as E,Qt as D,Si as O,Xt as k,Yt as A,Z as j,ar as M,bi as N,c as P,dt as F,f as I,hn as L,ji as R,jt as z,l as B,na as V,oi as H,ot as U,pn as W,sr as G,u as ee,vr as K,xi as te,xn as q,yn as ne,z as re}from"./player-overlays-Cs6l33cj.js";import{Ar as J,Ga as ie,nt as ae}from"./client-Ct1F5MoE.js";import{a as oe,c as se,i as ce,n as le,o as ue,r as de,s as fe,t as pe}from"./user-x-COQ6vhb4.js";import{c as me}from"./video-Byw3ItoR.js";import{t as he}from"./crop-CS-td_0y.js";import{t as ge}from"./user-round-BJVl6LX9.js";import{$n as _e,$r as ve,Ac as ye,Al as be,Cc as xe,Cn as Se,Dc as Ce,Dl as we,Dr as Te,Er as Ee,Fl as De,Il as Oe,Ll as ke,Ml as Ae,Nl as je,Ol as Me,Pl as Ne,Qr as Pe,Rl as Fe,So as Ie,St as Le,Tc as Re,Zr as ze,_r as Be,ac as Ve,ai as He,as as Ue,cs as We,dn as Ge,ds as Ke,ed as qe,ei as Y,fr as Je,fs as Ye,ft as Xe,gn as Ze,gr as Qe,hr as $e,ht as et,id as tt,is as nt,ji as rt,jl as it,kc as at,kd as ot,kl as st,ld as ct,ls as lt,mn as ut,mr as dt,ms as ft,nn as pt,ns as mt,oi as ht,os as gt,pn as _t,ps as vt,pt as yt,rs as bt,si as xt,ss as St,t as Ct,td as wt,ud as Tt,us as Et,vr as Dt,wc as Ot,wn as kt,xc as At,xn as jt,xr as Mt,zl as Nt}from"./src-DFzrn-CX.js";import{t as X}from"./i18n-DJ4egBMY.js";import{t as Z}from"./useTranslation-BJr-n0es.js";import"./mount-P-UzQOB7.js";import{S as Pt,dr as Ft,hr as It,lr as Lt,pr as Rt}from"./index-hKEeWkm1.js";import{t as zt}from"./AdminSectionedPage-DYCbg6TR.js";import{t as Bt}from"./use-stationary-objects-D_R5OahX.js";import{a as Vt,i as Ht,n as Ut,r as Wt,t as Gt}from"./authed-media-B6hJJcft.js";import{t as Kt}from"./use-scenes-feed-CGDnep25.js";l();function qt({mediaId:e,base64:t,alt:n,className:r,placeholder:i}){let{src:o,failed:s}=Vt(e===void 0?void 0:Wt(e));return o===null?(e===void 0||s)&&t!==void 0&&t!==``?a(`img`,{src:`data:image/jpeg;base64,${t}`,alt:n,className:r}):i:a(`img`,{src:o,alt:n,className:r})}var Jt=`pipeline-analytics`,Yt=`photo.analyze`,Xt=`photo.enroll`,Zt=`photo.discard`,Qt=18*1024*1024;function $t(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function en(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function tn(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function nn(e,t){let n=e[t];return typeof n==`boolean`?n:null}function rn(e){if(!$t(e))return null;let t=tn(e,`x`),n=tn(e,`y`),r=tn(e,`width`),i=tn(e,`height`);return t===null||n===null||r===null||i===null?null:{x:t,y:n,width:r,height:i}}function an(e){if(!$t(e))return null;let t=tn(e,`detectionShortSidePx`),n=tn(e,`score`);if(t===null||n===null)return null;let r=tn(e,`magnitude`);return{detectionShortSidePx:t,score:n,...r===null?{}:{magnitude:r}}}function on(e){if(!$t(e))return null;let t=tn(e,`faceIndex`),n=tn(e,`score`),r=nn(e,`enrollable`),i=rn(e.bbox),a=an(e.quality);if(t===null||n===null||r===null||i===null||a===null)return null;let o=en(e,`refusedReason`),s=en(e,`alignedCropBase64`),c=en(e,`modelId`);return{faceIndex:t,bbox:i,score:n,enrollable:r,quality:a,...o===null?{}:{refusedReason:o},...s===null?{}:{alignedCropBase64:s},...c===null?{}:{modelId:c}}}function sn(e){if(!$t(e))return null;let t=en(e,`sessionId`),n=en(e,`ranOnNodeId`),r=e.faces;if(t===null||n===null||!Array.isArray(r))return null;let i=[];for(let e of r){let t=on(e);t!==null&&i.push(t)}return{sessionId:t,ranOnNodeId:n,faces:i}}function cn(e){if(!$t(e))return null;let t=en(e,`sampleId`),n=en(e,`identityId`),r=en(e,`modelId`);return t===null||n===null||r===null?null:{sampleId:t,identityId:n,modelId:r}}function ln(e,t,n){let r={...e};return n===null||n===``?delete r[t]:r[t]=n,r}function un(e,t){return e.filter(e=>e.enrollable&&t[e.faceIndex]!==void 0).length}function dn(e,t,n){let r=[];for(let i of t){if(!i.enrollable)continue;let t=n[i.faceIndex];t!==void 0&&r.push({sessionId:e,faceIndex:i.faceIndex,identityId:t})}return r}function fn(e){switch(e){case`no-embedding`:return X.t(`helpers.photoEnroll.refusal.noEmbedding`);case`no-model-id`:return X.t(`helpers.photoEnroll.refusal.noModelId`);case`no-aligned-crop`:return X.t(`helpers.photoEnroll.refusal.noAlignedCrop`);case`magnitude`:return X.t(`helpers.photoEnroll.refusal.magnitude`);default:return X.t(`helpers.photoEnroll.refusal.default`)}}function pn(e,t){let n=[],r=[];for(let i of e)i.size>t.maxBytes?n.push(i.name):r.push(i);return{accepted:r.slice(0,t.maxCount),oversize:n,overflow:r.slice(t.maxCount).map(e=>e.name)}}async function mn(e,t,n){let r=Array(e.length),i=e.map((e,t)=>({item:e,index:t})),a=0,o=async()=>{for(;;){let e=i[a];if(a+=1,e===void 0)return;r[e.index]=await n(e.item,e.index)}},s=Array.from({length:Math.max(1,Math.min(t,e.length))},()=>o());return await Promise.all(s),r}function hn(e,t,n){return e.map(e=>e.photoIndex===t?{...e,...n}:e)}function gn(e,t){return`${e}:${t}`}function _n(e,t,n,r){let i=ln(e[t]??{},n,r),a={...e};return Object.keys(i).length===0?delete a[t]:a[t]=i,a}function vn(e,t){let n=0;for(let r of e)r.analysis!==void 0&&(n+=un(r.analysis.faces,t[r.photoIndex]??{}));return n}var yn=`__new__`;function bn(e,t,n){let r=[];for(let i of e){if(i.analysis===void 0)continue;let e=t[i.photoIndex]??{};for(let t of i.analysis.faces){if(!t.enrollable||e[t.faceIndex]!==`__new__`)continue;let a=(n[gn(i.photoIndex,t.faceIndex)]??``).trim();if(a===``)return{kind:`error`,message:X.t(`helpers.photoEnrollBatch.newPersonNoName`,{filename:i.filename,face:t.faceIndex+1})};r.includes(a)||r.push(a)}}return{kind:`ok`,names:r}}function xn(e,t,n){let r={};for(let[i,a]of Object.entries(e)){let e=Number(i),o={};for(let[r,i]of Object.entries(a)){let a=Number(r);if(i!==`__new__`){o[a]=i;continue}let s=n[(t[gn(e,a)]??``).trim()];s!==void 0&&(o[a]=s)}r[e]=o}return r}function Sn(e,t){let n=[];for(let r of e){if(r.analysis===void 0)continue;let e=dn(r.analysis.sessionId,r.analysis.faces,t[r.photoIndex]??{});for(let t of e)n.push({photoIndex:r.photoIndex,request:t})}return n}function Cn(e){return/expired/i.test(e)}function wn(e){return e instanceof Error?e.message:String(e)}async function Tn(e,t,n){let r=new Map(e.map(e=>[e.photoIndex,e])),i={},a=[],o=0,s=null,c=(e,t)=>{let n=r.get(e)?.filename??X.t(`helpers.photoEnrollBatch.photoFallback`,{n:e+1});return X.t(`helpers.photoEnrollBatch.faceLabel`,{filename:n,face:t+1})};for(let l of Sn(e,t)){let e=i[l.photoIndex],t=e===void 0?l.request:{...l.request,sessionId:e.sessionId};try{let e=await n.enroll(t);o+=1,s=e.modelId}catch(t){let u=wn(t);if(!Cn(u)||e!==void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${u}`);continue}let d=r.get(l.photoIndex);if(d===void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${u}`);continue}let f;try{f=await n.reanalyze(d)}catch(e){a.push(`${c(l.photoIndex,l.request.faceIndex)}: the analysis expired and re-analysing failed (${wn(e)})`);continue}if(i[l.photoIndex]=f,f.faces.find(e=>e.faceIndex===l.request.faceIndex&&e.enrollable)===void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: the analysis expired, and re-analysing no longer finds this face — assign it again from the fresh result`);continue}try{let e=await n.enroll({...l.request,sessionId:f.sessionId});o+=1,s=e.modelId}catch(e){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${wn(e)}`)}}}return{enrolled:o,stampedModelId:s,failures:a,refreshedAnalyses:i}}var En=[[`faceGallery`]],Dn=``;function On(e){return new Promise((t,n)=>{let r=new FileReader;r.addEventListener(`error`,()=>n(Error(`the file could not be read`)),{once:!0}),r.addEventListener(`load`,()=>{let e=r.result;if(typeof e!=`string`){n(Error(`the file could not be read`));return}let i=e.indexOf(`,`);t(i>=0?e.slice(i+1):e)},{once:!0}),r.readAsDataURL(e)})}function kn(e){return e instanceof Error?e.message:String(e)}function An({face:t,identities:r,value:i,onChange:o,disabled:s}){let{t:c}=Z(),l=n(()=>[{value:Dn,label:c(`detectionIntelligence.photoEnrollDialog.ignoreThisFace`,`Ignore this face`)},...r.map(e=>({value:e.id,label:e.name})),{value:yn,label:c(`detectionIntelligence.photoEnrollDialog.newPerson`,`+ New person…`)}],[r,c]);return e(`div`,{className:`rounded-md border border-border bg-surface p-2`,children:[a(`div`,{className:`mb-2 aspect-square w-full overflow-hidden rounded border border-border bg-surface-hover`,children:t.alignedCropBase64?a(`img`,{src:`data:image/jpeg;base64,${t.alignedCropBase64}`,alt:c(`detectionIntelligence.photoEnrollDialog.face`,`Face {{value1}}`,{value1:t.faceIndex+1}),className:`h-full w-full object-cover`}):a(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:a(ge,{className:`h-8 w-8`})})}),a(`div`,{className:`min-h-[4.75rem]`,children:t.enrollable?e(d,{children:[a(tt,{options:l,value:i,disabled:s,onChange:e=>o(e.target.value),"aria-label":c(`detectionIntelligence.photoEnrollDialog.assignFace`,`Assign face {{value1}}`,{value1:t.faceIndex+1})}),e(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:[Math.round(t.quality.detectionShortSidePx),` px`,t.modelId?` · ${t.modelId}`:``]})]}):e(`div`,{className:`space-y-1`,children:[a(xt,{variant:`warning`,className:`text-[10px]`,children:c(`detectionIntelligence.photoEnrollDialog.notUsable`,`Not usable`)}),a(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:fn(t.refusedReason)})]})})]})}function jn({photo:t,identities:n,draft:r,newNames:i,disabled:o,onAssign:s,onNameChange:c,onRetry:l}){let{t:u}=Z(),d=t.analysis?.faces??[],f=r[t.photoIndex]??{};return e(`div`,{className:`space-y-2`,children:[e(`div`,{className:`flex items-center gap-2 border-b border-border pb-1`,children:[a(`span`,{className:`truncate text-xs font-medium text-foreground`,children:t.filename}),t.status===`analyzing`||t.status===`queued`?e(`span`,{className:`flex items-center gap-1 text-xs text-foreground-subtle`,children:[a(G,{className:`h-3 w-3 animate-spin`}),` `,u(`detectionIntelligence.photoEnrollDialog.analysing`)]}):null,t.status===`analyzed`&&t.analysis!==void 0&&a(`span`,{className:`text-xs text-foreground-subtle`,children:u(`detectionIntelligence.photoEnrollDialog.facesAnalysedOn`,{count:d.length,node:t.analysis.ranOnNodeId})}),t.status===`failed`&&e(Y,{variant:`secondary`,size:`sm`,disabled:o,onClick:l,children:[a(ne,{className:`h-3 w-3`}),` `,u(`common.retry`)]})]}),t.status===`failed`&&e(`div`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[a(w,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),e(`span`,{children:[u(`detectionIntelligence.photoEnrollDialog.thisPhotoCouldNotBe`,`This photo could not be analysed:`),` `,t.error??u(`detectionIntelligence.photoEnrollDialog.unknownError`,`unknown error`),`. The other photos are unaffected.`]})]}),t.status===`analyzed`&&d.length===0&&a(`p`,{className:`text-xs text-foreground-subtle`,children:u(`detectionIntelligence.photoEnrollDialog.noFacesWereFoundIn`,`No faces were found in this photo. A face has to be reasonably large and facing the camera for the detector to measure it.`)}),d.length>0&&a(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(7rem,7rem))] justify-start gap-3`,children:d.map(e=>a(An,{face:e,identities:n,value:f[e.faceIndex]??Dn,disabled:o,onChange:t=>s(e.faceIndex,t)},e.faceIndex))}),d.filter(e=>f[e.faceIndex]===yn).map(n=>e(`div`,{className:`flex items-center gap-2`,children:[a(`span`,{className:`w-28 shrink-0 truncate text-xs text-foreground-subtle`,children:u(`detectionIntelligence.photoEnrollDialog.faceN`,{n:n.faceIndex+1})}),a(`input`,{className:`h-7 flex-1 rounded-md border border-border bg-surface px-2.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,placeholder:u(`detectionIntelligence.photoEnrollDialog.newPersonNameTypeThe`,`New person name… (type the same name under another face to reuse it)`),value:i[gn(t.photoIndex,n.faceIndex)]??``,onChange:e=>c(n.faceIndex,e.target.value)})]},n.faceIndex))]})}function Mn({open:r,onOpenChange:o}){let{t:c}=Z(),l=U(),d=u(),f=t(null),{data:p}=St(),m=bt(),[h,g]=s([]),[_,v]=s(!1),[y,b]=s(null),[x,S]=s({}),[C,T]=s({}),[E,D]=s(null),O=n(()=>(p??[]).map(e=>({id:e.id,name:e.name})),[p]),k=h.some(e=>e.status===`queued`||e.status===`analyzing`),A=k||_,j=i(e=>{for(let t of e){let e=t.analysis?.sessionId;e!==void 0&&l.trpcClient.addons.custom.mutate({addonId:Jt,action:Zt,input:{sessionId:e}}).catch(()=>void 0)}},[l]),M=i(()=>{g([]),S({}),T({}),b(null),D(null),f.current&&(f.current.value=``)},[]),N=i(()=>{j(h),M(),o(!1)},[j,o,h,M]),P=i(async e=>{let t=sn(await l.trpcClient.addons.custom.mutate({addonId:Jt,action:Yt,input:{photoBase64:e.photoBase64,filename:e.filename}}));if(t===null)throw Error(`the server replied with something this page could not read`);return t},[l]),F=i(async e=>{g(t=>hn(t,e.photoIndex,{status:`analyzing`,error:void 0}));try{let t=await P(e);g(n=>hn(n,e.photoIndex,{status:`analyzed`,analysis:t}))}catch(t){g(n=>hn(n,e.photoIndex,{status:`failed`,error:kn(t)}))}},[P]),I=i(async e=>{if(e.length===0)return;j(h),M();let t=pn(e,{maxCount:12,maxBytes:Qt}),n=[];t.oversize.length>0&&n.push(`Over the ${Math.round(Qt/(1024*1024))} MB limit and skipped: ${t.oversize.join(`, `)}.`),t.overflow.length>0&&n.push(`A batch holds at most 12 photos — not analysed: ${t.overflow.join(`, `)}. Enrol them in a second round.`),n.length>0&&b(n.join(` `));let r;try{r=await Promise.all(t.accepted.map(async(e,t)=>({photoIndex:t,filename:e.name,photoBase64:await On(e),status:`queued`})))}catch(e){b(kn(e));return}g(r),await mn(r,2,e=>F(e))},[j,h,M,F]),L=vn(h,x),R=i(async()=>{v(!0),b(null),D(null);try{let e=bn(h,x,C);if(e.kind===`error`){b(e.message);return}let t={};for(let n of e.names)t[n]=(await m.mutateAsync({name:n})).id;let n=await Tn(h,xn(x,C,t),{enroll:async e=>{let t=cn(await l.trpcClient.addons.custom.mutate({addonId:Jt,action:Xt,input:e}));if(t===null)throw Error(`unreadable reply`);return t},reanalyze:e=>P(e)});Object.keys(n.refreshedAnalyses).length>0&&g(e=>e.map(e=>{let t=n.refreshedAnalyses[e.photoIndex];return t===void 0?e:{...e,status:`analyzed`,analysis:t}})),d.invalidateQueries({queryKey:En}),n.failures.length>0&&b(n.failures.join(` · `)),D(n.enrolled===0?`Nothing was enrolled.`:`Enrolled ${n.enrolled} sample${n.enrolled===1?``:`s`}${n.stampedModelId===null?``:` with ${n.stampedModelId}`}.`)}catch(e){b(kn(e))}finally{v(!1)}},[P,m,x,C,h,d,l]),z=h.filter(e=>e.status===`analyzed`).length;return a(Je,{open:r,onOpenChange:e=>e?o(!0):N(),children:e(dt,{className:`max-w-3xl`,children:[e(Be,{children:[a(Dt,{children:c(`detectionIntelligence.photoEnrollDialog.enrolFromPhotos`,`Enrol from photos`)}),a($e,{children:c(`detectionIntelligence.photoEnrollDialog.everyPhotoIsAnalysedWith`,`Every photo is analysed with the same face detector the cameras use, and all the faces found are reviewed below in one pass, grouped by photo. Assign each face to a person, or leave it ignored.`)})]}),a(`div`,{className:`rounded-md border border-border bg-surface-hover px-3 py-2 text-xs text-foreground-subtle`,children:a(Lt,{i18nKey:`detectionIntelligence.photoEnrollDialog.reliableRecognition`,components:{strong:a(`strong`,{})}})}),e(`div`,{className:`flex items-center gap-2`,children:[a(`input`,{ref:f,type:`file`,accept:`image/jpeg,image/png,image/webp`,multiple:!0,className:`hidden`,onChange:e=>void I(Array.from(e.target.files??[]))}),e(Y,{variant:`secondary`,size:`sm`,disabled:A,onClick:()=>f.current?.click(),children:[k?a(G,{className:`h-3.5 w-3.5 animate-spin`}):a(ue,{className:`h-3.5 w-3.5`}),c(`detectionIntelligence.photoEnrollDialog.choosePhotos`,`Choose photos`)]}),h.length>0&&a(`span`,{className:`text-xs text-foreground-subtle`,children:c(`detectionIntelligence.photoEnrollDialog.photosAnalysed`,{done:z,count:h.length})})]}),a(`div`,{className:`min-h-11`,"aria-live":`polite`,children:y===null?E===null?null:a(`div`,{className:`rounded-md border border-success/40 bg-success/10 px-3 py-2 text-xs text-success`,children:E}):e(`div`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[a(w,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),a(`span`,{children:y})]})}),h.length>0&&a(`div`,{className:`max-h-[50vh] space-y-4 overflow-y-auto pr-1`,children:h.map(e=>a(jn,{photo:e,identities:O,draft:x,newNames:C,disabled:A,onAssign:(t,n)=>S(r=>_n(r,e.photoIndex,t,n===Dn?null:n)),onNameChange:(t,n)=>T(r=>({...r,[gn(e.photoIndex,t)]:n})),onRetry:()=>void F(e)},e.photoIndex))}),e(Qe,{children:[a(Y,{variant:`secondary`,onClick:N,disabled:_,children:c(`common.close`,`Close`)}),e(Y,{variant:`primary`,onClick:()=>void R(),disabled:A||L===0,children:[_?a(G,{className:`h-3.5 w-3.5 animate-spin`}):null,c(`detectionIntelligence.photoEnrollDialog.enrolFaces`,{count:L})]})]})]})})}l();var Nn=[[`faceGallery`]];function Pn({identityId:t}){let{t:n}=Z(),r=u(),{data:i,isLoading:o}=We({identityId:t}),s=Et();function c(e){s.mutate({identityId:t,sampleId:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:Nn})}})}return o?e(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[a(G,{className:`h-3.5 w-3.5 animate-spin`}),n(`detectionIntelligence.peopleList.loadingSamples`,`Loading samples…`)]}):!i||i.length===0?a(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:n(`detectionIntelligence.peopleList.noSamplesYet`,`No samples yet.`)}):a(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:i.map(t=>e(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[t.base64?a(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:n(`detectionIntelligence.peopleList.sample`,`Sample`),className:`h-full w-full object-cover`}):a(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:a(ge,{className:`h-6 w-6`})}),t.source===`photo`&&a(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 p-0.5 text-white`,title:n(`detectionIntelligence.peopleList.enrolledFromAnUploadedPhoto`,`Enrolled from an uploaded photo`),children:a(ue,{className:`h-3 w-3`})}),a(`button`,{type:`button`,onClick:()=>c(t),disabled:s.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":n(`detectionIntelligence.peopleList.removeSample`,`Remove sample`),children:a(F,{className:`h-4 w-4 text-white`})})]},t.id))})}function Fn(t){return[{key:`person`,header:X.t(`detectionIntelligence.peopleList.person`,`Person`),sortValue:e=>e.name,render:t=>e(`span`,{className:`flex min-w-0 items-center gap-2`,children:[a(`span`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:a(qt,{mediaId:t.coverMediaId,base64:t.coverBase64,alt:t.name,className:`h-full w-full object-cover`,placeholder:a(`span`,{className:`flex h-full w-full items-center justify-center`,children:a(ge,{className:`h-4 w-4 text-foreground-subtle`})})})}),a(`span`,{className:`truncate text-sm font-medium text-foreground`,children:t.name})]})},{key:`samples`,header:X.t(`detectionIntelligence.peopleList.samples`,`Samples`),align:`center`,nowrap:!0,sortValue:e=>e.sampleCount,render:e=>a(xt,{variant:`default`,className:`text-[10px]`,children:e.sampleCount})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:n=>e(`span`,{className:`flex items-center justify-end gap-1`,children:[a(Tt,{variant:`ghost`,size:`sm`,icon:v,"aria-label":X.t(`detectionIntelligence.peopleList.edit`,`Edit {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onEdit(n)}}),a(Tt,{variant:`ghost`,size:`sm`,icon:b,"aria-label":X.t(`detectionIntelligence.peopleList.delete`,`Delete {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onDelete(n)}})]})}]}function In({mode:t,identity:n,onClose:r}){let{t:i}=Z(),c=u(),[l,d]=s(t===`edit`?n?.name??``:``),f=bt(),p=Ke();o(()=>{d(t===`edit`?n?.name??``:``)},[t,n?.id,n?.name]);let m=f.isPending||p.isPending,h=l.trim(),g=t===`edit`&&n!==null&&h===n.name,_=m||h.length===0||g;function v(){c.invalidateQueries({queryKey:Nn})}function y(){if(!_){if(t===`new`){f.mutate({name:h},{onSuccess:()=>{v(),r()}});return}if(n===null){r();return}p.mutate({id:n.id,name:h},{onSuccess:()=>{v(),r()}})}}return a(et,{open:!0,onClose:r,title:t===`new`?`Add person`:`Edit ${n?.name??`person`}`,icon:ge,width:t===`edit`?`xl`:`lg`,testId:`people-person-form`,footer:e(Y,{variant:`primary`,size:`sm`,type:`button`,onClick:y,disabled:_,children:[m?a(G,{className:`h-3.5 w-3.5 animate-spin`}):null,t===`new`?i(`common.add`,`Add`):i(`common.save`,`Save`)]}),children:e(`div`,{className:`space-y-4`,children:[a(Le,{label:i(`detectionIntelligence.peopleList.name`,`Name`),required:!0,children:a(ct,{value:l,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&y()},placeholder:i(`detectionIntelligence.peopleList.personName`,`Person name…`),autoFocus:!0})}),t===`edit`&&n!==null&&e(`div`,{children:[a(`p`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:i(`detectionIntelligence.peopleList.trainingSamples`,`Training samples`)}),a(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:i(`detectionIntelligence.peopleList.removeASampleToDrop`,`Remove a sample to drop it from recognition training for this person.`)}),a(Pn,{identityId:n.id})]})]})})}function Ln(){let{t}=Z(),r=u(),i=Pe(),{data:c,isLoading:l}=St(),d=Ue(),{state:p,openNew:m,openEdit:h,close:g}=yt(),[_,v]=s(!1),y=c??[],b=_t(y,{searchText:e=>[e.name]}),x=p.mode===`edit`?y.find(e=>e.id===p.id)??null:null;o(()=>{p.mode===`edit`&&!l&&x===null&&g()},[p.mode,l,x,g]);let S=n(()=>Fn({onEdit:e=>h(e.id),onDelete:e=>{(async()=>{await i({title:t(`detectionIntelligence.peopleList.deletePerson`,`Delete person`),message:t(`detectionIntelligence.peopleList.deleteAndAllTheirSamples`,`Delete {{name}} and all their samples? This cannot be undone.`,{name:e.name}),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&d.mutate({id:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:Nn}),p.mode===`edit`&&p.id===e.id&&g()}})})()}}),[i,g,d,p,h,r,t]);if(l)return e(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[a(G,{className:`h-4 w-4 animate-spin`}),t(`detectionIntelligence.peopleList.loadingPeople`,`Loading people…`)]});let C=p.mode===`new`||p.mode===`edit`&&x!==null;return e(`div`,{className:`space-y-2`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(Y,{variant:`primary`,size:`sm`,type:`button`,onClick:m,children:[a(f,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.peopleList.addPerson`,`Add person`)]}),e(Y,{variant:`secondary`,size:`sm`,type:`button`,onClick:()=>v(!0),children:[a(ue,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.peopleList.enrolFromAPhoto`,`Enrol from a photo`)]})]}),(y.length>0||b.active)&&a(ut,{state:b.state,facets:b.facets,labels:{searchPlaceholder:`Search people…`,searchLabel:`Search people`,facetsLabel:`Filter`,clearLabel:`Clear`},onSearch:b.setSearch,onToggleFacet:b.toggleFacet,onClear:b.clear}),b.rows.length===0?a(Te,{icon:ge,title:b.active?t(`detectionIntelligence.peopleList.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.peopleList.noPeopleEnrolledYet`,`No people enrolled yet`),description:b.active?t(`detectionIntelligence.peopleList.clearTheSearchOrTry`,`Clear the search or try another name.`):t(`detectionIntelligence.peopleList.addAPersonOrEnrol`,`Add a person, or enrol faces from a photo.`)}):a(Se,{columns:S,rows:b.rows,rowKey:e=>e.id,maxBodyHeight:kt,emptyMessage:t(`detectionIntelligence.peopleList.noPeopleEnrolledYet2`,`No people enrolled yet.`),onRowClick:e=>h(e.id)}),C&&a(In,{mode:p.mode===`new`?`new`:`edit`,identity:x,onClose:g}),a(Mn,{open:_,onOpenChange:v})]})}var Rn={fromMs:null,toMs:null},zn=36e5,Bn=24*zn;function Vn(e,t){switch(e){case`24h`:return{fromMs:t-Bn,toMs:null};case`7d`:return{fromMs:t-7*Bn,toMs:null};case`30d`:return{fromMs:t-30*Bn,toMs:null};case`all`:return Rn}}function Hn(e){return e.fromMs!==null||e.toMs!==null}function Un(e,t){return Hn(t)?e.filter(e=>!(t.fromMs!==null&&e.timestamp<t.fromMs||t.toMs!==null&&e.timestamp>t.toMs)):[...e]}function Wn(e,t){return t.size===0?[...e]:e.filter(e=>t.has(e.deviceId))}function Gn(e){let t=new Set,n=[];for(let r of e)t.has(r.deviceId)||(t.add(r.deviceId),n.push(r.deviceId));return n}function Kn(e){if(!e)return null;let t=Date.parse(`${e}T00:00:00`);return Number.isNaN(t)?null:t}function qn(e){if(!e)return null;let t=Date.parse(`${e}T23:59:59.999`);return Number.isNaN(t)?null:t}function Jn(e,t){if(!Number.isFinite(e)||e<=0)return`—`;let n=t-e;return n<6e4?X.t(`helpers.relativeTime.justNow`):n<zn?X.t(`helpers.relativeTime.minutesAgo`,{count:Math.floor(n/6e4)}):n<Bn?X.t(`helpers.relativeTime.hoursAgo`,{count:Math.floor(n/zn)}):n<7*Bn?X.t(`helpers.relativeTime.daysAgo`,{count:Math.floor(n/Bn)}):new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function Yn(e){return!Number.isFinite(e)||e<=0?`—`:new Date(e).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function Xn(e){return!Number.isFinite(e)||e<=0?`—`:new Date(e).toLocaleString(void 0,{year:`numeric`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function Zn(e){let t=e.cropUrl!==void 0&&e.cropUrl.length>0,n=e.base64!==void 0&&e.base64.length>0;return!t&&!n}function Qn(e){return e.filter(Zn).map(e=>e.faceId)}function $n(e){let t=0;for(let n of e)Zn(n)&&(t+=1);return t}function er(e){return e==null?null:e.cropUrl!==void 0&&e.cropUrl.length>0?e.cropUrl:e.base64!==void 0&&e.base64.length>0?`data:image/jpeg;base64,${e.base64}`:null}l();function tr(e,t,r){let[i,a]=s(1);o(()=>{a(1)},[r]);let c=e.length,l=Math.max(1,Math.ceil(c/t)),u=Math.min(i,l);return o(()=>{u!==i&&a(u)},[u,i]),{page:u,setPage:a,pageItems:n(()=>{let n=(u-1)*t;return e.slice(n,n+t)},[e,u,t]),totalPages:l,totalItems:c,pageSize:t}}var nr=2;function rr(e,t){if(t<=1)return[{kind:`page`,n:1}];if(t<=7){let e=[];for(let n=1;n<=t;n++)e.push({kind:`page`,n});return e}let n=[],r=Math.max(2,e-nr),i=Math.min(t-1,e+nr);n.push({kind:`page`,n:1}),r>2&&n.push({kind:`ellipsis`,side:`left`});for(let e=r;e<=i;e++)n.push({kind:`page`,n:e});return i<t-1&&n.push({kind:`ellipsis`,side:`right`}),n.push({kind:`page`,n:t}),n}function ir({currentPage:t,totalItems:n,pageSize:r,onPageChange:i,itemNoun:o=`items`}){let{t:s}=Z();if(n<=r)return null;let c=Math.ceil(n/r),l=(t-1)*r+1,u=Math.min(t*r,n),d=rr(t,c),f=`inline-flex h-7 min-w-7 items-center justify-center rounded-md px-2 text-[11px] transition-colors disabled:opacity-40`;return e(`div`,{className:`flex items-center justify-between gap-4 flex-wrap pt-2 text-[11px] text-foreground-subtle`,children:[a(`span`,{children:s(`galleryPager.showing`,{from:l,to:u,total:n,noun:o})}),e(`div`,{className:`flex items-center gap-1`,children:[a(`button`,{type:`button`,className:`${f} hover:bg-surface-hover`,onClick:()=>i(t-1),disabled:t<=1,"aria-label":s(`galleryPager.previousPage`,`Previous page`),children:a(te,{className:`h-3.5 w-3.5`})}),d.map(e=>e.kind===`ellipsis`?a(`span`,{className:`px-1 opacity-60`,children:`…`},`ellipsis-${e.side}`):a(`button`,{type:`button`,className:`${f} ${e.n===t?`bg-primary/12 text-primary font-medium`:`hover:bg-surface-hover hover:text-foreground`}`,onClick:()=>i(e.n),"aria-current":e.n===t?`page`:void 0,children:e.n},e.n)),a(`button`,{type:`button`,className:`${f} hover:bg-surface-hover`,onClick:()=>i(t+1),disabled:t>=c,"aria-label":s(`galleryPager.nextPage`,`Next page`),children:a(N,{className:`h-3.5 w-3.5`})})]})]})}l();var ar=[[`faceGallery`]];function or({faceIds:t,identities:n,onDone:r}){let{t:i}=Z(),o=u(),c=mt(),l=bt(),[d,f]=s(``),[p,m]=s(!1),[h,g]=s(null),_=t!==null&&t.length>0,v=t?.length??0;function y(){m(!1),f(``),g(null)}function b(){y(),r()}function x(e){!t||t.length===0||c.mutate({faceIds:[...t],identityId:e},{onSettled:()=>{o.invalidateQueries({queryKey:ar}),b()}})}function S(){!t||!d.trim()||l.mutate({name:d.trim()},{onSuccess:e=>{e?.id&&x(e.id)},onError:()=>{o.invalidateQueries({queryKey:ar}),b()}})}let C=c.isPending||l.isPending;return a(Je,{open:_,onOpenChange:e=>!e&&b(),children:e(dt,{children:[e(Be,{children:[a(Dt,{children:v>1?i(`detectionIntelligence.assignDialog.assignFacesToPerson`,`Assign {{value1}} faces to person`,{value1:String(v)}):i(`detectionIntelligence.assignDialog.assignFaceToPerson`,`Assign face to person`)}),a($e,{children:i(`detectionIntelligence.assignDialog.selectAnExistingPersonOr`,`Select an existing person or create a new one.`)})]}),a(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:n.map(t=>e(`button`,{type:`button`,onClick:()=>g(t.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${h===t.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[a(`span`,{className:`font-medium`,children:t.name}),a(`span`,{className:`ml-2 text-foreground-subtle`,children:i(`detectionIntelligence.assignDialog.samples`,{count:t.sampleCount})})]},t.id))}),a(`div`,{className:`min-h-[2.75rem] border-t border-border pt-2`,children:p?a(`div`,{className:`flex items-center gap-2`,children:a(ct,{placeholder:i(`detectionIntelligence.assignDialog.newPersonName`,`New person name…`),value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&S()},autoFocus:!0,className:`flex-1`})}):a(`button`,{type:`button`,onClick:()=>{g(null),m(!0)},className:`w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle transition-colors hover:border-primary hover:text-primary`,children:i(`detectionIntelligence.assignDialog.newPerson`,`+ New person…`)})}),e(Qe,{className:`min-h-[2.75rem]`,children:[a(Y,{variant:`secondary`,onClick:b,disabled:C,children:i(`common.cancel`,`Cancel`)}),p?e(Y,{variant:`primary`,onClick:S,disabled:C||!d.trim(),children:[C&&a(G,{className:`h-3.5 w-3.5 animate-spin`}),i(`detectionIntelligence.assignDialog.createAssign`,`Create & assign`)]}):e(Y,{variant:`primary`,onClick:()=>h&&x(h),disabled:C||!h,children:[C&&a(G,{className:`h-3.5 w-3.5 animate-spin`}),v>1?i(`detectionIntelligence.assignCount`,{count:v}):i(`common.assign`)]})]})]})})}l();function sr({cameras:n,selected:r,onChange:i}){let{t:c}=Z(),[l,u]=s(!1),d=t(null);o(()=>{if(!l)return;function e(e){d.current&&e.target instanceof Node&&!d.current.contains(e.target)&&u(!1)}function t(e){e.key===`Escape`&&u(!1)}return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[l]);function f(e){let t=new Set(r);t.has(e)?t.delete(e):t.add(e),i(t)}let m=r.size,h=m===0?`All cameras`:m===1?n.find(e=>r.has(e.id))?.name??`1 camera`:`${String(m)} cameras`;return e(`div`,{ref:d,className:`relative`,children:[e(`button`,{type:`button`,onClick:()=>u(e=>!e),disabled:n.length===0,className:`flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs transition-colors disabled:opacity-40 ${m>0?`border-primary/40 bg-primary/8 text-primary`:`border-border text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(x,{className:`h-3.5 w-3.5`}),a(`span`,{className:`max-w-[10rem] truncate`,children:h}),a(O,{className:`h-3 w-3 opacity-70`})]}),l&&e(`div`,{className:`absolute left-0 z-30 mt-1 max-h-64 w-[min(15rem,calc(100vw-1.5rem))] overflow-y-auto rounded-md border border-border bg-surface p-1 shadow-lg shadow-black/30`,children:[m>0&&a(`button`,{type:`button`,onClick:()=>i(new Set),className:`mb-1 w-full rounded px-2 py-1 text-left text-[11px] text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:c(`detectionIntelligence.cameraMultiSelect.clearSelection`,`Clear selection`)}),n.map(t=>{let n=r.has(t.id);return e(`button`,{type:`button`,onClick:()=>f(t.id),className:`flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-xs transition-colors ${n?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[a(`span`,{className:`flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded-sm border ${n?`border-primary bg-primary text-white`:`border-border`}`,children:n&&a(p,{className:`h-2.5 w-2.5`})}),a(`span`,{className:`truncate`,children:t.name})]},t.id)})]})]})}l();var cr=[{label:`24h`,value:`24h`},{label:`7d`,value:`7d`},{label:`30d`,value:`30d`},{labelKey:`common.all`,value:`all`}];function lr({onChange:t}){let{t:n}=Z(),[r,i]=s(`all`),[o,c]=s(``),[l,u]=s(``);function d(e){i(e),c(``),u(``),t(Vn(e,Date.now()))}function f(e,n){i(`custom`),c(e),u(n),t({fromMs:Kn(e),toMs:qn(n)})}let p=`rounded-md border border-border bg-surface px-2 py-1.5 text-[11px] text-foreground outline-none focus:border-primary [color-scheme:light] dark:[color-scheme:dark]`;return e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[a(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:cr.map(e=>a(`button`,{type:`button`,onClick:()=>d(e.value),className:`rounded px-2.5 py-1 text-[11px] transition-colors ${r===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.labelKey===void 0?e.label:n(e.labelKey)},e.value))}),e(`div`,{className:`flex items-center gap-1`,children:[a(`input`,{type:`date`,"aria-label":n(`detectionIntelligence.dateRangeFilter.fromDate`,`From date`),value:o,max:l||void 0,onChange:e=>f(e.target.value,l),className:`${p} ${r===`custom`&&o?`border-primary/50`:``}`}),a(`span`,{className:`text-[11px] text-foreground-subtle`,children:`→`}),a(`input`,{type:`date`,"aria-label":n(`detectionIntelligence.dateRangeFilter.toDate`,`To date`),value:l,min:o||void 0,onChange:e=>f(o,e.target.value),className:`${p} ${r===`custom`&&l?`border-primary/50`:``}`})]})]})}function ur(e){return e<0?0:e>1?1:e}function dr(e,t,n){if(!Number.isFinite(t)||!Number.isFinite(n)||t<=0||n<=0)return null;let r=ur(e.x/t),i=ur(e.y/n),a=ur((e.x+e.w)/t),o=ur((e.y+e.h)/n);return{x:r,y:i,width:Math.max(0,a-r),height:Math.max(0,o-i)}}l();var fr=2.6;function pr({src:t,alt:n,className:r,overlay:i,fit:c=`contain`}){let[l,u]=s(!1),[d,f]=s(`50% 50%`);o(()=>{u(!1),f(`50% 50%`)},[t]);function p(e){if(!l){let t=e.currentTarget.getBoundingClientRect(),n=(e.clientX-t.left)/t.width*100,r=(e.clientY-t.top)/t.height*100;f(`${String(n)}% ${String(r)}%`)}u(e=>!e)}let m=c===`natural`;return a(`div`,{className:`relative overflow-hidden bg-background ${r??``}`,onClick:p,children:e(`div`,{className:`relative select-none transition-transform duration-200 ease-out ${m?`w-full`:`h-full w-full`} ${l?`cursor-zoom-out`:`cursor-zoom-in`}`,style:{transformOrigin:d,transform:l?`scale(${String(fr)})`:`scale(1)`},children:[a(`img`,{src:t,alt:n,draggable:!1,className:m?`block h-auto w-full object-contain`:`h-full w-full object-contain`}),i]})})}l();function mr(e){let[t,n]=s(null),[r,i]=s(null),[a,c]=s(!1);return o(()=>{if(n(null),i(null),c(!1),e===void 0)return;let t=!1,r=null;return(async()=>{try{let i=await Ut(Wt(e));if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||c(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),o(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>c(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function hr(e){let t=e.filter(e=>e.url.length>0);return t.length===0?null:t.find(e=>/crop|face/i.test(e.kind))??t[0]}function gr({label:t,value:n}){return e(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[a(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:t}),a(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground`,children:n})]})}function _r({box:e}){let{t}=Z();return a(`div`,{className:`pointer-events-none absolute rounded-[3px] border-2 border-primary shadow-[0_0_0_9999px_rgba(0,0,0,0.28)]`,style:{left:`${String(e.x*100)}%`,top:`${String(e.y*100)}%`,width:`${String(e.width*100)}%`,height:`${String(e.height*100)}%`},children:a(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:t(`detectionIntelligence.faceDetailPanel.face`,`Face`)})})}function vr({face:t,cameraName:r,onClose:i,onAssign:o,onUnassign:c,onDelete:l,actionsPending:u}){let{t:d}=Z(),{data:f,isFetching:p}=gt({faceId:t?.faceId??``},{enabled:t!==null}),[m,h]=s(`frame`),{frameSrc:g,naturalWidth:_,naturalHeight:v,failed:y}=mr(t?.keyFrameMediaId),x=n(()=>{let e=hr(f??[]);return e?e.url:er(t)},[f,t]),S=n(()=>!t?.faceBbox||_===null||v===null?null:dr(t.faceBbox,_,v),[t?.faceBbox,_,v]);if(t===null)return null;let w=t.keyFrameMediaId!==void 0&&!y,T=w&&m===`frame`,E=t.assigned?t.identityName??`Assigned`:t.recognizedIdentityId?`${t.identityName??`Recognized`} (suggested)`:`Unassigned`;return a(Je,{open:!0,onOpenChange:e=>!e&&i(),children:e(dt,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":d(`detectionIntelligence.faceDetailPanel.faceDetail`,`Face detail`),className:`flex max-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: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:[a(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:e(`div`,{className:`min-w-0`,children:[a(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:d(`detectionIntelligence.faceDetailPanel.faceDetail`,`Face detail`)}),a(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:r})]})}),e(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[w&&e(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[e(`button`,{type:`button`,onClick:()=>h(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${m===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(L,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.fullFrame`)]}),e(`button`,{type:`button`,onClick:()=>h(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${m===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(he,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.crop`)]})]}),T&&g?a(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:a(pr,{src:g,alt:d(`detectionIntelligence.faceDetailPanel.fullFrameWithDetectedFace`,`Full frame with detected face`),fit:`natural`,className:`w-full`,overlay:S?a(_r,{box:S}):void 0})}):x?e(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[a(pr,{src:x,alt:d(`detectionIntelligence.faceDetailPanel.detectedFace`,`Detected face`),className:`h-full w-full`}),p&&a(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:a(G,{className:`h-3.5 w-3.5 animate-spin`})})]}):e(`div`,{className:`flex aspect-square w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[a(K,{className:`h-8 w-8 text-warning/70`}),a(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:d(`detectionIntelligence.faceDetailPanel.noImage`,`No image`)}),a(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:d(`detectionIntelligence.faceDetailPanel.theCropMediaForThis`,`The crop media for this face could not be resolved (a pre-fix orphan). Safe to delete.`)})]}),e(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[a(gr,{label:d(`detectionIntelligence.faceDetailPanel.camera`,`Camera`),value:r}),a(gr,{label:d(`detectionIntelligence.faceDetailPanel.captured`,`Captured`),value:Xn(t.timestamp)}),a(gr,{label:d(`detectionIntelligence.faceDetailPanel.track`,`Track`),value:t.trackId}),a(gr,{label:d(`detectionIntelligence.faceDetailPanel.identity`,`Identity`),value:E})]})]}),e(`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:[t.assigned?e(Y,{variant:`secondary`,onClick:()=>c(t.faceId),disabled:u,children:[a(pe,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.detach`)]}):e(Y,{variant:`primary`,onClick:()=>o(t.faceId),disabled:u,children:[a(C,{className:`h-3.5 w-3.5`}),` `,d(`common.assign`)]}),e(Y,{variant:`secondary`,onClick:()=>l(t.faceId),disabled:u,children:[a(b,{className:`h-3.5 w-3.5`}),` `,d(`common.delete`)]})]})]})})}function yr(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function br(e,t){return e.faceIds.filter(e=>!t.has(e))}function xr(e,t){return e.faceIds.filter(e=>t(e))}l();var Sr=[[`faceGallery`]],Cr=20,wr=.3,Tr=.9,Er=.05,Dr=.5,Or=2,kr=10,Ar=2;function jr({cluster:t,face:n,active:r,onSelect:i}){let{t:o}=Z(),s=er(n);return e(`button`,{type:`button`,onClick:i,className:`flex shrink-0 flex-col items-center gap-1.5 rounded-md border p-2 text-center transition-colors md:w-full md:flex-row md:gap-2.5 md:text-left ${r?`border-primary bg-primary/8`:`border-border bg-surface hover:bg-surface-hover`}`,children:[a(`div`,{className:`h-24 w-24 shrink-0 overflow-hidden rounded bg-surface-hover`,children:s===null?a(K,{className:`h-24 w-24 p-6 text-foreground-subtle`}):a(`img`,{src:s,alt:``,loading:`lazy`,decoding:`async`,className:`h-24 w-24 object-cover`})}),a(`span`,{className:`w-24 text-[11px] leading-tight text-foreground-subtle md:w-auto`,children:o(`detectionIntelligence.similarGroupsModal.clusterMeta`,{count:t.size,percent:Math.round(t.cohesion*100)})})]})}function Mr({face:t,cameraName:n,nowMs:r,excluded:i,onToggleExclude:o,onDelete:s,deletePending:c}){let{t:l}=Z(),u=er(t);return e(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden transition-opacity ${i?`border-border opacity-40 grayscale`:`border-border`}`,children:[e(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[u===null?e(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,children:[a(K,{className:`h-7 w-7 text-warning/70`}),a(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:l(`detectionIntelligence.similarGroupsModal.noCrop`,`No crop`)})]}):a(pr,{src:u,alt:l(`detectionIntelligence.similarGroupsModal.faceFrom`,`Face from {{cameraName}}`,{cameraName:n}),className:`h-full w-full`}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o()},className:`absolute right-1 top-1 z-10 rounded-full bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?l(`detectionIntelligence.similarGroupsModal.includeFace`,`Include face`):l(`detectionIntelligence.similarGroupsModal.excludeFace`,`Exclude face`),title:i?l(`detectionIntelligence.similarGroupsModal.include`,`Include`):l(`detectionIntelligence.similarGroupsModal.exclude`,`Exclude`),children:a(i?z:F,{className:`h-3.5 w-3.5`})})]}),e(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[a(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:n,children:n}),a(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:Jn(t.timestamp,r)})]}),a(`div`,{className:`mt-1 flex min-h-[2rem] items-center justify-end border-t border-border/60 px-1 py-0.5`,children:a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s()},disabled:c,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":l(`detectionIntelligence.similarGroupsModal.deleteFace`,`Delete face`),title:l(`detectionIntelligence.similarGroupsModal.deleteFace`,`Delete face`),children:c?a(G,{className:`h-4 w-4 animate-spin`}):a(b,{className:`h-4 w-4`})})})]})}function Nr({open:t,onClose:r,byId:i,cameraName:c,nowMs:l,identities:f,selectMany:p}){let{t:m}=Z(),h=u(),g=Pe(),_=nt(),[v,y]=s(Dr),[b,x]=s(Ar),[S,w]=s(null),[T,E]=s({}),[O,k]=s(null),{data:A,isFetching:j,refetch:M}=Ye({threshold:v,minClusterSize:b,limit:Cr},{enabled:t}),N=A??[];o(()=>{E({})},[v,b]),o(()=>{if(N.length===0){w(null);return}N.some(e=>e.representativeFaceId===S)||w(N[0]?.representativeFaceId??null)},[N]);let P=n(()=>N.find(e=>e.representativeFaceId===S)??null,[N,S]),F=P?T[P.representativeFaceId]??new Set:new Set,I=n(()=>P?xr(P,e=>i.has(e)):[],[P,i]),L=P?P.faceIds.length-I.length:0,R=P?br({...P,faceIds:I},F):[];function z(e){if(!P)return;let t=P.representativeFaceId;E(n=>({...n,[t]:yr(n[t]??new Set,e)}))}function B(){h.invalidateQueries({queryKey:Sr})}async function V(e){await g({title:m(`detectionIntelligence.similarGroupsModal.deleteFace`,`Delete face`),message:m(`detectionIntelligence.similarGroupsModal.permanentlyDeletesThisFaceCrop`,`Permanently deletes this face crop. This cannot be undone.`),confirmLabel:m(`common.delete`,`Delete`),variant:`danger`})&&_.mutate({faceId:e},{onSettled:B})}function H(){k(null),r()}function U(){R.length!==0&&(p(R),H())}return e(Je,{open:t,onOpenChange:e=>!e&&H(),children:[e(dt,{placement:`sheet-on-mobile`,width:`lg`,"aria-label":m(`detectionIntelligence.similarGroupsModal.lookAlikeGroups`,`Look-alike groups`),className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 md:max-w-4xl`,children:[e(`header`,{className:`flex shrink-0 flex-col gap-2 border-b border-border py-3 pl-4 pr-10`,children:[e(`div`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[a(D,{className:`h-4 w-4 text-primary`}),` `,m(`detectionIntelligence.similarGroupsModal.title`)]}),e(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[e(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[m(`detectionIntelligence.similarGroupsModal.threshold`,`Threshold`),a(`input`,{type:`range`,min:wr,max:Tr,step:Er,value:v,onChange:e=>y(Number(e.target.value)),className:`h-1.5 w-28 cursor-pointer accent-primary`}),a(`span`,{className:`w-8 shrink-0 text-right font-mono text-[11px] tabular-nums text-foreground`,children:v.toFixed(2)})]}),e(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[m(`detectionIntelligence.similarGroupsModal.minSize`,`Min size`),a(`input`,{type:`number`,min:Or,max:kr,step:1,value:b,onChange:e=>x(Math.min(kr,Math.max(Or,Number(e.target.value)||Or))),className:`w-12 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`})]}),e(Y,{variant:`secondary`,onClick:()=>{E({}),M()},disabled:j,children:[j?a(G,{className:`h-3.5 w-3.5 animate-spin`}):a(q,{className:`h-3.5 w-3.5`}),m(`detectionIntelligence.similarGroupsModal.reAnalyze`,`Re-analyze`)]})]})]}),a(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-hidden px-4 py-3 md:flex-row`,children:j&&N.length===0?e(`div`,{className:`flex flex-1 items-center justify-center gap-2 py-8 text-xs text-foreground-subtle`,children:[a(G,{className:`h-4 w-4 animate-spin`}),` `,m(`detectionIntelligence.similarGroupsModal.finding`)]}):N.length===0?a(`div`,{className:`flex flex-1 items-center justify-center py-8 text-xs text-foreground-subtle`,children:m(`detectionIntelligence.similarGroupsModal.noLookAlikeGroupsAt`,`No look-alike groups at this threshold.`)}):e(d,{children:[a(`div`,{className:`flex gap-2 overflow-x-auto pb-1 md:hidden`,children:N.map(e=>a(jr,{cluster:e,face:i.get(e.representativeFaceId),active:e.representativeFaceId===S,onSelect:()=>w(e.representativeFaceId)},e.representativeFaceId))}),a(`div`,{className:`hidden shrink-0 flex-col gap-2 overflow-y-auto md:flex md:w-56`,children:N.map(e=>a(jr,{cluster:e,face:i.get(e.representativeFaceId),active:e.representativeFaceId===S,onSelect:()=>w(e.representativeFaceId)},e.representativeFaceId))}),a(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:P&&e(d,{children:[L>0&&a(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:m(`detectionIntelligence.similarGroupsModal.hiddenCount`,{count:L})}),a(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(13rem,13rem))] justify-start gap-2`,children:I.map(e=>{let t=i.get(e);return t?a(Mr,{face:t,cameraName:c(t.deviceId),nowMs:l,excluded:F.has(e),onToggleExclude:()=>z(e),onDelete:()=>void V(e),deletePending:_.isPending&&_.variables?.faceId===e},e):null})})]})})]})}),e(`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:[a(Y,{variant:`secondary`,onClick:U,disabled:R.length===0,children:m(`detectionIntelligence.similarGroupsModal.selectInGallery`,`Select in gallery`)}),e(Y,{variant:`primary`,onClick:()=>k(R),disabled:R.length===0,children:[a(C,{className:`h-3.5 w-3.5`}),` `,m(`detectionIntelligence.similarGroupsModal.adopt`,{count:R.length})]})]})]}),a(or,{faceIds:O,identities:f,onDone:()=>k(null)})]})}l();var Pr=[[`faceGallery`]],Fr=500,Ir=120;function Lr({face:t,cameraName:n,nowMs:r,selected:i,onToggleSelect:o,onAssign:s,onOpenDetail:c}){let{t:l}=Z(),d=u(),f=vt(),p=nt(),m=()=>{d.invalidateQueries({queryKey:Pr})},h=()=>c(t.faceId),g=er(t);return e(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[e(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[g===null?e(`button`,{type:`button`,onClick:h,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:l(`detectionIntelligence.unassignedFaces.noCropImageTheFace`,`No crop image — the face's crop media is missing (a pre-fix orphan). Safe to delete.`),children:[a(K,{className:`h-7 w-7 text-warning/70`}),a(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:l(`detectionIntelligence.unassignedFaces.noCrop`,`No crop`)})]}):a(`img`,{src:g,alt:l(`detectionIntelligence.unassignedFaces.faceFrom`,`Face from {{cameraName}}`,{cameraName:n}),onClick:h,loading:`lazy`,decoding:`async`,className:`h-full w-full cursor-zoom-in object-cover`}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(t.faceId)},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":i?l(`detectionIntelligence.unassignedFaces.deselect`,`Deselect`):l(`detectionIntelligence.unassignedFaces.select`,`Select`),children:i?a(de,{className:`h-4 w-4 text-primary`}):a(k,{className:`h-4 w-4`})})]}),e(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[a(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:n,children:n}),a(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:Jn(t.timestamp,r)}),a(`p`,{className:`min-h-[0.875rem] truncate text-[10px] font-medium leading-tight ${t.identityName?`text-primary`:`invisible`}`,title:t.identityName,children:t.identityName??`\xA0`})]}),e(`div`,{className:`mt-1 flex min-h-[2rem] items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[t.assigned?a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),f.mutate({faceId:t.faceId},{onSettled:m})},disabled:f.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":l(`detectionIntelligence.unassignedFaces.detachFace`,`Detach face`),title:l(`detectionIntelligence.unassignedFaces.detach`,`Detach`),children:f.isPending?a(G,{className:`h-4 w-4 animate-spin`}):a(pe,{className:`h-4 w-4`})}):a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s(t.faceId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":l(`detectionIntelligence.unassignedFaces.assignFaceToPerson`,`Assign face to person`),title:l(`detectionIntelligence.unassignedFaces.assignToPerson`,`Assign to person`),children:a(C,{className:`h-4 w-4`})}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),p.mutate({faceId:t.faceId},{onSettled:m})},disabled:p.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":l(`detectionIntelligence.unassignedFaces.deleteFace`,`Delete face`),title:l(`detectionIntelligence.unassignedFaces.deleteFace`,`Delete face`),children:p.isPending?a(G,{className:`h-4 w-4 animate-spin`}):a(b,{className:`h-4 w-4`})})]})]})}var Rr=[{labelKey:`common.all`,value:`all`},{labelKey:`detectionIntelligence.unassignedFaces.filterUnassigned`,value:`unassigned`},{labelKey:`detectionIntelligence.unassignedFaces.filterRecognized`,value:`recognized`}];function zr(){let{t}=Z(),r=u(),[i,o]=s(`all`),[c,l]=s(Rn),[f,p]=s(new Set),[m,h]=s(new Set),[g,_]=s(null),[v,y]=s(!1),[x,S]=s(null),{data:w,isLoading:T}=lt({limit:Fr,filter:i,includeCrops:!1},{refetchInterval:3e4}),{data:E=[]}=St(),{data:O}=Ie({isCamera:!0,projection:`slim`}),k=mt(),A=vt(),j=ft(),M=nt(),N=Date.now(),P=w??[],I=n(()=>{let e=new Map;for(let t of O??[])e.set(t.id,t.name);return e},[O]),L=e=>I.get(e)??t(`detectionIntelligence.cameraFallback`,{id:String(e)}),R=n(()=>Gn(P).map(e=>({id:e,name:L(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[P,I]),z=n(()=>Wn(Un(P,c),f),[P,c,f]),B=tr(z,Ir,n(()=>JSON.stringify([i,c.fromMs,c.toMs,[...f].sort((e,t)=>e-t)]),[i,c.fromMs,c.toMs,f])),V=n(()=>new Map(P.map(e=>[e.faceId,e])),[P]),H=n(()=>$n(z),[z]),U=x===null?null:V.get(x)??null,W=()=>{r.invalidateQueries({queryKey:Pr})},ee=()=>h(new Set);function te(e){h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function q(e){h(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function ne(){q(Qn(z))}let re=[...m],J=k.isPending||j.isPending||M.isPending,ie=A.isPending||M.isPending;function ae(){re.length!==0&&j.mutate({faceIds:re},{onSettled:()=>{W(),ee()}})}function oe(){re.length!==0&&Promise.allSettled(re.map(e=>M.mutateAsync({faceId:e}))).then(()=>{W(),ee()})}function se(e){S(null),_([e])}function ce(e){A.mutate({faceId:e},{onSettled:W}),S(null)}function le(e){M.mutate({faceId:e},{onSettled:W}),S(null)}let ue=z.length!==P.length;return e(`div`,{className:`relative space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[a(`div`,{className:`flex items-center gap-1`,children:Rr.map(e=>a(`button`,{type:`button`,onClick:()=>o(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${i===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:t(e.labelKey)},e.value))}),a(lr,{onChange:l}),a(sr,{cameras:R,selected:f,onChange:p}),e(`button`,{type:`button`,onClick:()=>y(!0),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${v?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(D,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.similarGroups`)]}),!T&&H>0&&e(`button`,{type:`button`,onClick:ne,className:`ml-auto flex items-center gap-1 rounded-md px-2.5 py-1 text-xs text-warning/90 transition-colors hover:bg-warning/10`,title:t(`detectionIntelligence.unassignedFaces.selectEveryVisibleFaceWhose`,`Select every visible face whose crop image is missing so you can delete the orphans in one pass`),children:[a(K,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.selectCropless`,{count:H})]}),!T&&a(`span`,{className:`text-[10px] text-foreground-subtle ${H>0?`ml-2`:`ml-auto`}`,children:ue?t(`detectionIntelligence.unassignedFaces.ofFaces`,`{{value1}} of {{value2}} faces`,{value1:String(z.length),value2:String(P.length)}):t(`detectionIntelligence.unassignedFaces.faceCount`,{count:z.length})})]}),m.size>0&&e(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[a(`span`,{className:`text-xs font-medium text-foreground`,children:t(`common.selectedCount`,{count:m.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[e(Y,{variant:`primary`,onClick:()=>_(re),disabled:J,children:[a(C,{className:`h-3.5 w-3.5`}),` `,t(`common.assign`)]}),e(Y,{variant:`secondary`,onClick:ae,disabled:J,children:[j.isPending?a(G,{className:`h-3.5 w-3.5 animate-spin`}):a(pe,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.detach`,`Detach`)]}),e(Y,{variant:`secondary`,onClick:oe,disabled:J,children:[a(b,{className:`h-3.5 w-3.5`}),` `,t(`common.delete`)]}),a(Y,{variant:`ghost`,onClick:ee,disabled:J,children:a(F,{className:`h-3.5 w-3.5`})})]})]}),T?a(Xe,{status:`pending`,pendingMessage:`Loading faces…`,testId:`faces-grid`}):z.length===0?a(Te,{icon:K,title:P.length>0?t(`detectionIntelligence.unassignedFaces.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.unassignedFaces.noFacesFoundForThis`,`No faces found for this filter`),description:P.length>0?t(`detectionIntelligence.unassignedFaces.widenTheDateRangeOr`,`Widen the date range or clear the camera filter.`):t(`detectionIntelligence.unassignedFaces.faceCropsAppearHereWhen`,`Face crops appear here when the detection pipeline captures them.`)}):e(d,{children:[a(Xe,{status:`ready`,testId:`faces-grid`,className:`grid-cols-[repeat(auto-fill,minmax(6.5rem,6.5rem))] justify-start`,children:B.pageItems.map(e=>a(Lr,{face:e,cameraName:L(e.deviceId),nowMs:N,selected:m.has(e.faceId),onToggleSelect:te,onAssign:e=>_([e]),onOpenDetail:S},e.faceId))}),a(ir,{currentPage:B.page,totalItems:B.totalItems,pageSize:B.pageSize,onPageChange:B.setPage,itemNoun:`faces`})]}),a(vr,{face:U,cameraName:U?L(U.deviceId):``,onClose:()=>S(null),onAssign:se,onUnassign:ce,onDelete:le,actionsPending:ie}),a(or,{faceIds:g,identities:E,onDone:()=>{_(null),ee()}}),a(Nr,{open:v,onClose:()=>y(!1),byId:V,cameraName:L,nowMs:N,identities:E,selectMany:q})]})}function Br(e){let{delayMs:t,invalidate:n,setTimeoutFn:r=setTimeout,clearTimeoutFn:i=clearTimeout}=e,a;function o(){a===void 0&&(a=r(()=>{a=void 0,n()},t))}function s(){a!==void 0&&(i(a),a=void 0)}return{trigger:o,cancel:s}}l();var Vr=[[`faceGallery`]],Hr=2e3;function Ur(){let e=u(),n=t(e);n.current=e;let r=t(void 0);r.current||=Br({delayMs:Hr,invalidate:()=>{n.current.invalidateQueries({queryKey:Vr})}}),o(()=>()=>r.current?.cancel(),[]),ot(ie.PipelineAnalyticsFaceGalleryChanged,()=>{r.current?.trigger()})}function Wr(){let{t}=Z();return Ur(),e(`div`,{className:`space-y-3`,children:[a(jt,{headingId:`library-people`,title:t(`detectionIntelligence.people`,`People`),icon:ge,testId:`library-section-people`,children:e(`div`,{className:`${m} space-y-3`,children:[a(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`detectionIntelligence.enrolledIdentitiesUsedForFace`,`Enrolled identities used for face recognition. Open a person to rename them or remove training samples.`)}),a(Ln,{})]})}),a(jt,{headingId:`library-recent-faces`,title:t(`detectionIntelligence.recentDetectedFaces`,`Recent detected faces`),icon:oe,testId:`library-section-recent-faces`,children:e(`div`,{className:`${m} space-y-3`,children:[a(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`detectionIntelligence.faceCropsCapturedByThe`,`Face crops captured by the detection pipeline. Assign them to a person to build recognition training data.`)}),a(zr,{})]})})]})}function Gr(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 Kr=720*60*60*1e3;function qr(e){let t=[];for(let n of e)t.push(...n);return t}function Jr(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function Yr(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 Xr(e,t){return`${String(e)}:${t}`}function Zr(e,t){let n=new Map,r=new Set;for(let i of e){let e=Xr(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 Qr(e,t){return{since:e.fromMs??t-Kr,until:e.toMs??t}}var $r=[`native`,`raster`,`standin`];function ei(e){return $r.some(t=>t===e)}function ti(e){return e===`standin`?{label:X.t(`helpers.mediaProvenance.standin.label`),title:X.t(`helpers.mediaProvenance.standin.title`),tone:`warning`}:{label:X.t(`helpers.mediaProvenance.raster.label`),title:X.t(`helpers.mediaProvenance.raster.title`),tone:`info`}}function ni(e){return e===`standin`?ti(`standin`):e===`raster`?ti(`raster`):null}var ri={"no-key-frame":`helpers.mediaProvenance.miss.noKeyFrame`,"no-best-seen-bbox":`helpers.mediaProvenance.miss.noBestSeenBbox`,"derive-returned-null":`helpers.mediaProvenance.miss.deriveReturnedNull`,"derive-threw":`helpers.mediaProvenance.miss.deriveThrew`,"derive-not-wired":`helpers.mediaProvenance.miss.deriveNotWired`,"no-media-store":`helpers.mediaProvenance.miss.noMediaStore`,"no-thumbnail":`helpers.mediaProvenance.miss.noThumbnail`,"standin-tile":`helpers.mediaProvenance.miss.standinTile`,"raster-tile":`helpers.mediaProvenance.miss.rasterTile`,"native-tile":`helpers.mediaProvenance.miss.nativeTile`};function ii(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)})}let a=ri[r];return{sentence:a===void 0?r:X.t(a),detail:i,raw:t}}function ai(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 oi({row:t,cameraName:n,nowMs:r,onOpenDetail:i,selected:o=!1,onToggleSelect:s,score:c,provenance:l,footer:u}){let{t:d}=Z(),f=Vt(t.mediaId===void 0?Ht(`track`,t.trackId):Wt(t.mediaId)),m=Math.round(t.importance*100),h=c===void 0?void 0:Math.round(c*100),g=ai(t.windowMs),_=()=>i(t),v=ni(l);return e(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${o?`border-primary ring-1 ring-primary`:`border-border`}`,children:[e(`div`,{className:`aspect-video relative overflow-hidden bg-surface-hover`,children:[f.src?a(`img`,{src:f.src,alt:d(`detectionIntelligence.eventCard.eventFrom`,`Event from {{cameraName}}`,{cameraName:n}),onClick:_,className:`h-full w-full cursor-zoom-in object-cover`}):a(`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:f.failed?d(`detectionIntelligence.eventCard.keyEventMediaUnavailable`,`Key-event media unavailable`):d(`detectionIntelligence.eventCard.noKeyEventMedia`,`No key-event media`),children:a(K,{className:`h-6 w-6 opacity-60`})}),s&&a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s(Xr(t.deviceId,t.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":o?d(`detectionIntelligence.eventCard.deselect`,`Deselect`):d(`detectionIntelligence.eventCard.select`,`Select`),children:o?a(de,{className:`h-4 w-4 text-primary`}):a(k,{className:`h-4 w-4`})}),h!==void 0&&e(`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:d(`detectionIntelligence.eventCard.clipSemanticMatchScore`,`CLIP semantic-match score`),children:[String(h),`%`]}),m>0&&a(`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(m)}),v!==null&&a(`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}),(t.markForTrain===!0||t.retrainStatus===`trained`||t.debug===!0||t.favourited===!0)&&e(`span`,{className:`absolute bottom-1 left-1 z-10 flex gap-1`,children:[t.markForTrain===!0&&a(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:d(`detectionIntelligence.eventCard.markedForTraining`,`Marked for training`),"aria-label":d(`detectionIntelligence.eventCard.markedForTraining`,`Marked for training`),children:a(S,{className:`h-3 w-3`})}),t.retrainStatus===`trained`&&t.markForTrain!==!0&&a(`span`,{className:`rounded bg-success/85 p-0.5 text-white`,title:d(`detectionIntelligence.eventCard.trainingComplete`,`Training complete`),"aria-label":d(`detectionIntelligence.eventCard.trainingComplete`,`Training complete`),"data-testid":`retrain-status-trained`,children:a(p,{className:`h-3 w-3`})}),t.debug===!0&&a(`span`,{className:`rounded bg-black/70 p-0.5 text-white`,title:d(`detectionIntelligence.eventCard.flaggedForDebug`,`Flagged for debug`),"aria-label":d(`detectionIntelligence.eventCard.flaggedForDebug`,`Flagged for debug`),children:a(R,{className:`h-3 w-3`})}),t.favourited===!0&&a(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:d(`detectionIntelligence.eventCard.favourited`,`Favourited`),"aria-label":d(`detectionIntelligence.eventCard.favourited`,`Favourited`),children:a(A,{className:`h-3 w-3`})})]})]}),e(`button`,{type:`button`,onClick:_,className:`min-w-0 px-2 py-1.5 text-left space-y-0.5`,children:[e(`p`,{className:`text-[11px] font-medium text-foreground truncate`,title:t.className,children:[t.className,Gr(t)?e(`span`,{className:`text-foreground-subtle`,children:[` · `,Gr(t)]}):null]}),a(`p`,{className:`text-[10px] text-foreground-subtle truncate`,title:n,children:n}),e(`div`,{className:`flex items-center justify-between gap-2`,children:[a(`span`,{className:`text-[10px] text-foreground-subtle truncate`,children:Jn(t.timestamp,r)}),g&&a(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:g})]})]}),u!==void 0&&a(`div`,{className:`px-2 pb-1.5`,children:u})]})}l();var si=1400,ci=`Admin-gated URL — opens only inside an authenticated session`;function li({label:t,value:n,title:r}){let{t:c}=Z(),[l,u]=s(!1),d=ve();return o(()=>{if(!l)return;let e=setTimeout(()=>u(!1),si);return()=>clearTimeout(e)},[l]),e(`button`,{type:`button`,onClick:i(()=>{(async()=>{try{await navigator.clipboard.writeText(n),u(!0)}catch{await d({title:c(`detectionIntelligence.copyUrlChips.copyTheMediaUrl`,`Copy the media URL`),message:c(`detectionIntelligence.copyUrlChips.clipboardAccessWasRefusedSelect`,`Clipboard access was refused. Select the URL below and copy it manually.`),label:c(`detectionIntelligence.copyUrlChips.url`,`{{label}} URL`,{label:t}),defaultValue:n,readOnly:!0,cancelLabel:c(`common.close`,`Close`)})}})()},[n,t,d,c]),title:r,"aria-label":c(`detectionIntelligence.copyUrlChips.copyUrl`,`Copy {{label}} URL`,{label:t}),className:`flex min-w-0 items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${l?`border-success/40 bg-success/10 text-success`:`border-border text-foreground-subtle hover:border-primary hover:text-foreground`}`,children:[a(l?p:E,{className:`h-2.5 w-2.5 shrink-0`}),a(`span`,{className:`truncate`,children:l?c(`detectionIntelligence.copyUrlChips.copied`,`Copied`):t})]})}function ui({localUrl:t,publicUrl:n}){let{t:r}=Z();return e(`div`,{className:`flex flex-wrap gap-1`,children:[a(li,{label:r(`detectionIntelligence.copyUrlChips.local`,`Local`),value:t,title:r(`detectionIntelligence.copyUrlChips.copyLanUrl`,`Copy LAN URL — {{AUTH_HINT}}`,{AUTH_HINT:ci})}),n&&a(li,{label:r(`detectionIntelligence.copyUrlChips.public`,`Public`),value:n,title:r(`detectionIntelligence.copyUrlChips.copyPublicUrl`,`Copy public URL — {{AUTH_HINT}}`,{AUTH_HINT:ci})})]})}var di={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 fi(e){return e in di}function pi(e){return fi(e)?di[e]:e}function mi(e,t){return`${e}${t}`}l();var hi=3e4;function gi(e){let[t,n]=s(null),r=i(e=>{n(t=>t??e)},[]);return o(()=>{e||n(null)},[e]),{publicOrigin:t,probes:e?a(_i,{onOrigin:r}):null}}function _i({onOrigin:e}){let{data:t}=rt({capName:`network-access`});return a(d,{children:(t??[]).map(t=>a(vi,{addonId:t.addonId,onOrigin:e},t.addonId))})}function vi({addonId:e,onOrigin:t}){let{data:n}=Ve({addonId:e},{refetchInterval:hi,retry:!1});return o(()=>{let e=n?J.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 yi=typeof ye==`function`,bi=`Track flags arrive with the next server update`;function xi(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var Si=yi?ye:xi;function Ci(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}}l();function wi({label:t,hint:n,checked:r,disabled:i,title:o,icon:s,onToggle:c}){return e(`button`,{type:`button`,role:`switch`,"aria-checked":r,"aria-label":t,disabled:i,title:o,onClick:c,className:`flex w-full items-center gap-2 rounded-md border px-2 py-1.5 text-left transition-colors disabled:opacity-50 ${r?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[a(`span`,{className:r?`text-primary`:`text-foreground-subtle`,children:s}),e(`span`,{className:`min-w-0 flex-1`,children:[a(`span`,{className:`block text-[11px] font-medium text-foreground`,children:t}),a(`span`,{className:`block text-[10px] text-foreground-subtle`,children:n})]}),a(`span`,{"aria-hidden":`true`,className:`h-4 w-7 shrink-0 rounded-full p-0.5 transition-colors ${r?`bg-primary`:`bg-border`}`,children:a(`span`,{className:`block h-3 w-3 rounded-full bg-white transition-transform ${r?`translate-x-3`:``}`})})]})}function Ti({deviceId:t,trackId:n,markForTrain:r,debug:i,favourited:o,onChange:c}){let{t:l}=Z(),u=Si(),d=ze(),[f,p]=s(null),m=f?.markForTrain??r===!0,h=f?.debug??i===!0,g=f?.favourited??o===!0,_=!yi||u.isPending,v=yi?void 0:bi,y=e=>{_||(async()=>{try{let r=Ci(await u.mutateAsync({deviceId:t,trackId:n,flags:e}));if(!r)return;p(r),c?.(r)}catch(e){let t=e instanceof Error?e.message:``;await d({title:l(`detectionIntelligence.trackFlagToggles.couldNotUpdateThisTrack`,`Could not update this track`),message:t===``?l(`detectionIntelligence.trackFlagToggles.couldNotUpdateThisTrack2`,`Could not update this track. Check the server logs.`):t,variant:`danger`})}})()};return e(`div`,{className:`grid gap-1.5 sm:grid-cols-2`,children:[a(wi,{label:l(`detectionIntelligence.trackFlagToggles.markForTraining`,`Mark for training`),hint:l(`detectionIntelligence.trackFlagToggles.keepsThisTrackAndIts`,`Keeps this track and its media past retention`),checked:m,disabled:_,...v===void 0?{}:{title:v},icon:a(S,{className:`h-4 w-4`}),onToggle:()=>y({markForTrain:!m})}),a(wi,{label:l(`detectionIntelligence.trackFlagToggles.debug`,`Debug`),hint:l(`detectionIntelligence.trackFlagToggles.flagThisTrackForDiagnostic`,`Flag this track for diagnostic attention`),checked:h,disabled:_,...v===void 0?{}:{title:v},icon:a(R,{className:`h-4 w-4`}),onToggle:()=>y({debug:!h})}),a(wi,{label:l(`detectionIntelligence.trackFlagToggles.favourited`,`Favourited`),hint:l(`detectionIntelligence.trackFlagToggles.keepsThisTrackAndIts`,`Keeps this track and its media past retention`),checked:g,disabled:_,...v===void 0?{}:{title:v},icon:a(A,{className:`h-4 w-4`}),onToggle:()=>y({favourited:!g})})]})}function Ei(e){let t=e.deviceKey===void 0?e.nodeId:`${e.nodeId} · ${e.deviceKey}`;return e.modelId===void 0?t:`${t} (${e.modelId})`}function Di(e){let t=e?.openedPlacement,n=e?.closedPlacement;if(t!==void 0&&n!==void 0){let e=Ei(t),r=Ei(n);return e===r?[{kind:`detected`,value:e}]:[{kind:`opened`,value:e},{kind:`closed`,value:r}]}return t===void 0?n===void 0?[]:[{kind:`closed`,value:Ei(n)}]:[{kind:`opened`,value:Ei(t)}]}var Oi=100,ki={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Ai=e=>e<0?0:e>1?1:e,ji=e=>Math.round(e*100)/100;function Mi(e,t,n){if(e.length===0||t===null)return ki;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return ki;let a=ae(e.map(e=>({x:e.x/r,y:e.y/i,w:e.bbox.w/r,h:e.bbox.h/i})),n?.maxPoints===void 0?void 0:{maxPoints:n.maxPoints}).nodes.map(e=>({x:ji(e.x*Oi),y:ji(e.y*Oi)})),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:ji(Ai(e.x/r)*Oi),y:ji(Ai(e.y/i)*Oi),mediaId:e.mediaId})),u=null,d=-1;for(let t of e){let e=Ai(t.bbox.w/r)*Ai(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:ji(Ai(u.bbox.x/r)*Oi),y:ji(Ai(u.bbox.y/i)*Oi),w:ji(Ai(u.bbox.w/r)*Oi),h:ji(Ai(u.bbox.h/i)*Oi)}:null}}var Ni=typeof At==`function`,Pi=`Track deletion arrives with the next server update`;function Fi(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var Ii=Ni?At:Fi;l();var Li=15e3,Ri=j();function zi({url:e,label:t}){let{src:n,failed:r}=Vt(e);return n===null?a(`div`,{className:`flex h-full w-full items-center justify-center bg-surface-hover`,children:r?a(K,{className:`h-4 w-4 text-foreground-subtle opacity-60`}):a(G,{className:`h-4 w-4 animate-spin text-foreground-subtle opacity-70`})}):a(`img`,{src:n,alt:t,className:`h-full w-full object-cover`})}var Bi=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),Vi=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`,`sceneFrame`,`lastSceneFrame`]);function Hi(e){let[t,n]=s(null);return o(()=>{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 Ui({overlay:t,onPickSnapshot:n}){let{t:r}=Z();return!t.polyline&&!t.peakBox&&t.snapshots.length===0?null:e(`svg`,{viewBox:`0 0 100 100`,preserveAspectRatio:`none`,className:`pointer-events-none absolute inset-0 h-full w-full`,children:[t.peakBox&&a(`rect`,{x:t.peakBox.x,y:t.peakBox.y,width:t.peakBox.w,height:t.peakBox.h,fill:`none`,stroke:`var(--color-warning)`,strokeWidth:2,vectorEffect:`non-scaling-stroke`,rx:1}),t.polyline&&a(`polyline`,{points:t.polyline,fill:`none`,stroke:`var(--color-info)`,strokeWidth:2,strokeLinejoin:`round`,strokeLinecap:`round`,strokeOpacity:.85,vectorEffect:`non-scaling-stroke`}),t.points.map((e,t)=>a(`circle`,{cx:e.x,cy:e.y,r:1,fill:`var(--color-info)`,fillOpacity:.6,vectorEffect:`non-scaling-stroke`},`${String(e.x)}-${String(e.y)}-${String(t)}`)),t.snapshots.map((e,t)=>a(`circle`,{cx:e.x,cy:e.y,r:1.9,fill:`var(--color-info)`,fillOpacity:.95,stroke:`var(--color-background)`,strokeWidth:.7,vectorEffect:`non-scaling-stroke`,className:n?`pointer-events-auto cursor-pointer`:void 0,onClick:n?t=>{t.stopPropagation(),n(e.mediaId)}:void 0,children:a(`title`,{children:r(`detectionIntelligence.eventDetailPanel.snapshotCheckpointClickToView`,`Snapshot checkpoint — click to view this frame`)})},`snap-${String(e.mediaId)}-${String(t)}`)),t.start&&a(`circle`,{cx:t.start.x,cy:t.start.y,r:2.4,fill:`var(--color-success)`,stroke:`var(--color-background)`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`}),t.end&&a(`circle`,{cx:t.end.x,cy:t.end.y,r:2.4,fill:`var(--color-danger)`,stroke:`var(--color-background)`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`})]})}function Wi({label:t,value:n,mono:r,wrap:i}){return e(`div`,{className:`flex items-baseline justify-between gap-3 border-b border-border/60 py-1.5 last:border-0`,children:[a(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:t}),a(`span`,{className:`min-w-0 ${i?`break-words`:`truncate`} text-right text-xs font-medium text-foreground ${r?`font-mono text-[11px]`:``}`,title:n,children:n})]})}function Gi({row:t,cameraName:r,deleteAvailable:c,onClose:l,onDeleted:u,onFlagsChanged:f}){let{t:p}=Z(),m=U(),h=ze(),g=Pe(),_=Ii(),v=t!==null,x=t?.deviceId??0,S=t?.trackId??``,C=t?.timestamp??0,w=t?.windowMs??0,{data:T}=xe({deviceId:x,trackId:S},{enabled:v}),{data:E}=Ce({trackId:S,deviceId:x},{enabled:v}),D=T?.bestEventId===void 0?void 0:Number(T.bestEventId),{data:O}=Re({ownerType:`object`,eventId:D??0,deviceId:x},{enabled:v&&D!==void 0&&Number.isFinite(D)}),{data:k}=wt({deviceId:x},{enabled:v}),A=(k??[]).find(e=>e.addonId!==void 0)?.addonId,{data:j}=qe({deviceId:x,since:C-Li,until:C+w+Li,provider:A??``},{enabled:v&&A!==void 0}),[M,N]=s(null),[P,F]=s(!1),{publicOrigin:I,probes:L}=gi(v);o(()=>{N(null)},[x,S]);let R=n(()=>{let e=E??[],t=O??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[E,O]),z=M??R,B=Vt(z?z.url:void 0),V=n(()=>{let e=new Set,t=[];for(let n of[...O??[],...E??[]])e.has(n.mediaId)||(e.add(n.mediaId),t.push(n));return t},[O,E]),H=n(()=>V.find(e=>Bi.has(e.kind))??null,[V]),W=Hi(Vt(H?H.url:void 0).src),ee=n(()=>Mi(T?.positions??[],W,{snapshots:(T?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaId:e.mediaId}))}),[T?.positions,T?.snapshots,W]),te=i(e=>{let t=V.find(t=>t.mediaId===e);t&&N(t)},[V]);if(t===null)return null;let q=B.src,ne=z?.kind,re=ne!==void 0&&Vi.has(ne)&&W!==null&&(T?.positions.length??0)>=2,J=j&&j.length>0?j[0]:null,ie=()=>{J&&(F(!0),(async()=>{try{let e=await m.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:J.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{h({title:p(`detectionIntelligence.eventDetailPanel.clipUnavailable`,`Clip unavailable`),message:p(`detectionIntelligence.eventDetailPanel.couldNotResolveClipPlayback`,`Could not resolve clip playback. Check the server logs.`),variant:`warning`})}finally{F(!1)}})())},ae=()=>{!c||_.isPending||(async()=>{if(await g({title:p(`detectionIntelligence.eventDetailPanel.deleteTrack`,`Delete track`),message:p(`detectionIntelligence.eventDetailPanel.deleteThisTrackAndEvery`,`Delete this track and every image and clip captured for it? This cannot be undone.`),confirmLabel:p(`common.delete`,`Delete`),variant:`danger`}))try{await _.mutateAsync({deviceId:t.deviceId,trackIds:[t.trackId]}),u()}catch{await h({title:p(`detectionIntelligence.eventDetailPanel.deleteFailed`,`Delete failed`),message:p(`detectionIntelligence.eventDetailPanel.failedToDeleteThisTrack`,`Failed to delete this track. Check the server logs.`),variant:`danger`})}})()},oe=Math.round(t.importance*100),se=T?.importanceReason?`${String(oe)}% · ${T.importanceReason}`:`${String(oe)}%`,ce=T?.zonesVisited&&T.zonesVisited.length>0?T.zonesVisited.join(`, `):`—`,le=T?.audioLabels&&T.audioLabels.length>0?T.audioLabels:t.audioLabels&&t.audioLabels.length>0?t.audioLabels:void 0,ue=le===void 0?`—`:le.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `),de=T?T.totalDistance.toFixed(2):`—`,fe=ii(T?.previewMissReason),pe=Xn(T?T.firstSeen:C),me=T?Xn(T.lastSeen):`—`,he=Di(T),ge={detected:p(`detectionIntelligence.eventDetailPanel.detectedOn`,`Detected on`),opened:p(`detectionIntelligence.eventDetailPanel.openedOn`,`Opened on`),closed:p(`detectionIntelligence.eventDetailPanel.closedOn`,`Closed on`)};return a(Je,{open:!0,onOpenChange:e=>!e&&l(),children:e(dt,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":p(`detectionIntelligence.eventDetailPanel.eventDetail`,`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:[a(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:e(`div`,{className:`min-w-0`,children:[e(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:[t.className,Gr(t)?e(`span`,{className:`text-foreground-subtle`,children:[` · `,Gr(t)]}):null]}),a(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:r})]})}),e(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[q?a(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:a(pr,{src:q,alt:p(`detectionIntelligence.eventDetailPanel.keyFrameFrom`,`Key frame from {{cameraName}}`,{cameraName:r}),fit:`natural`,className:`w-full`,overlay:re?a(Ui,{overlay:ee,onPickSnapshot:te}):void 0})}):a(`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:B.failed?e(d,{children:[a(K,{className:`h-8 w-8 opacity-60`}),a(`span`,{className:`text-[11px]`,children:p(`detectionIntelligence.eventDetailPanel.keyFrameMediaUnavailable`,`Key-frame media unavailable`)})]}):a(G,{className:`h-6 w-6 animate-spin opacity-70`})}),V.length>0&&a(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:V.map(t=>{let n=pi(t.kind),r=mi(Ri,t.url),i=I?mi(I,t.url):null;return e(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[a(`button`,{type:`button`,onClick:()=>N(t),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${n} · ${Xn(t.timestamp)}`,children:a(zi,{url:t.url,label:n})}),e(`figcaption`,{className:`min-w-0 px-0.5`,children:[a(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:n,children:n}),a(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:Xn(t.timestamp),children:Yn(t.timestamp)})]}),a(ui,{localUrl:r,publicUrl:i})]},t.mediaId)})}),L,J&&e(Y,{variant:`secondary`,onClick:ie,disabled:P,children:[P?a(G,{className:`h-3.5 w-3.5 animate-spin`}):a(y,{className:`h-3.5 w-3.5`}),` `,p(`detectionIntelligence.eventDetailPanel.viewClip`,`View clip`)]}),a(Ti,{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}),fe!==null&&e(`div`,{className:`rounded-lg border border-warning/40 bg-warning/8 px-3 py-2`,children:[a(`p`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:p(`detectionIntelligence.eventDetailPanel.bestShot`,`Best shot`)}),a(`p`,{className:`mt-0.5 text-xs text-foreground`,children:fe.sentence}),a(`code`,{className:`mt-1 block break-all font-mono text-[10px] text-foreground-subtle`,children:fe.raw})]}),e(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[a(Wi,{label:p(`detectionIntelligence.eventDetailPanel.camera`,`Camera`),value:r}),he.map(e=>a(Wi,{label:ge[e.kind],value:e.value,mono:!0,wrap:!0},e.kind)),a(Wi,{label:p(`detectionIntelligence.eventDetailPanel.class`,`Class`),value:t.className}),a(Wi,{label:p(`detectionIntelligence.eventDetailPanel.label`,`Label`),value:t.label??`—`}),a(Wi,{label:p(`detectionIntelligence.eventDetailPanel.subLabel`,`Sub-label`),value:t.subLabel??`—`}),a(Wi,{label:p(`detectionIntelligence.eventDetailPanel.importance`,`Importance`),value:se}),a(Wi,{label:p(`detectionIntelligence.eventDetailPanel.zonesVisited`,`Zones visited`),value:ce}),a(Wi,{label:p(`detectionIntelligence.eventDetailPanel.audioHeard`,`Audio heard`),value:ue}),a(Wi,{label:p(`detectionIntelligence.eventDetailPanel.totalDistance`,`Total distance`),value:de}),a(Wi,{label:p(`detectionIntelligence.eventDetailPanel.firstSeen`,`First seen`),value:pe}),a(Wi,{label:p(`detectionIntelligence.eventDetailPanel.lastSeen`,`Last seen`),value:me}),a(Wi,{label:p(`detectionIntelligence.eventDetailPanel.track`,`Track`),value:t.trackId,mono:!0})]})]}),a(`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:a(`span`,{title:c?void 0:Pi,children:e(Y,{variant:`secondary`,onClick:ae,disabled:!c||_.isPending,children:[_.isPending?a(G,{className:`h-3.5 w-3.5 animate-spin`}):a(b,{className:`h-3.5 w-3.5`}),` `,p(`detectionIntelligence.eventDetailPanel.deleteTrack`,`Delete track`)]})})})]})})}var Ki={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`},qi={setRelation:`debug.gt.setRelation`,setPurity:`debug.gt.setPurity`,list:`debug.gt.list`},Ji=T(`/addon/pipeline-analytics/tape-export`),Yi=10*6e4;function Xi(e){return`${Ji}?tapeId=${encodeURIComponent(e)}`}var Zi=`The server answered in a shape this build does not understand.`;function Qi(e){return e instanceof Error?e.message:X.t(`helpers.eventsDebugTapes.actionFailed`)}function $i(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 ea(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 ta(e,t){let n=e[t];return typeof n==`boolean`?n:null}function na(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 ra(e){return e===`off`||e===`recording`||e===`refused`||e===`failing`||e===`unknown`}function ia(e){if(!$i(e))return null;let t=Q(e,`deviceId`),n=e.state,r=Q(e,`gapsSinceArmed`),i=ea(e,`segmentsHeld`),a=ea(e,`bytesLastHour`),o=ea(e,`bytesHeld`);if(t===null||!ra(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 aa(e){return $i(e)?na(e.cameras,ia):null}function oa(e){if(!$i(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=ta(e,`reviewed`),f=ta(e,`released`),p=na(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 sa(e){return $i(e)?na(e.tapes,oa):null}function ca(e){if(!$i(e))return null;let t=$(e,`trackId`),n=Q(e,`firstT`),r=Q(e,`lastT`),i=Q(e,`boundFrames`),a=$(e,`cls`),o=ta(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 la(e){if(!$i(e))return null;let t=$(e,`tapeId`),n=Q(e,`deviceId`),r=Q(e,`fromMs`),i=Q(e,`toMs`),a=ta(e,`reviewed`),o=na(e.lanes,ca);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 ua(e){if(!$i(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 da(e){if(!$i(e))return null;let t=e.status;if(t===`released`){let n=Q(e,`unpinned`),r=ta(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 fa(e){if(!$i(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 pa(e){switch(e.status){case`released`:case`deleted`:return null;case`already-released`:return X.t(`helpers.eventsDebugTapes.alreadyReleased`);case`not-found`:return X.t(`helpers.eventsDebugTapes.notFound`);case`pins-owed`:return X.t(`helpers.eventsDebugTapes.pinsOwed`);case`unavailable`:return X.t(`helpers.eventsDebugTapes.unavailable`,{reason:e.reason})}}function ma(e){if(!$i(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 ha(e){if(!$i(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 ga(e){if(!$i(e))return null;let t=na(e.relations,ma),n=na(e.purities,ha),r=ta(e,`truncated`);return t===null||n===null||r===null?null:{relations:t,purities:n,truncated:r}}function _a(e){if(!e.truncated)return null;let t=e.relations.length+e.purities.length;return X.t(`helpers.eventsDebugTapes.truncatedMarks`,{count:t})}function va(e){return e.filter(e=>e.segmentsHeld===null||e.segmentsHeld>0).map(e=>({deviceId:e.deviceId,segmentsUnknown:e.segmentsHeld===null}))}function ya(e){return e.slice(1).map((t,n)=>({trackId:e[n]??t,otherTrackId:t}))}function ba(e){return e.flatMap((t,n)=>e.slice(n+1).map(e=>({trackId:t,otherTrackId:e})))}function xa(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 Sa(e){switch(e.state){case`off`:return X.t(`helpers.eventsDebugTapes.statusOff`);case`recording`:return X.t(`helpers.eventsDebugTapes.statusRecording`);case`refused`:return X.t(`helpers.eventsDebugTapes.statusRefused`,{reason:e.reason??X.t(`helpers.eventsDebugTapes.unknownReason`)});case`failing`:return X.t(`helpers.eventsDebugTapes.statusFailing`,{reason:e.reason??X.t(`helpers.eventsDebugTapes.unknownReason`)});case`unknown`:return X.t(`helpers.eventsDebugTapes.statusUnknown`,{reason:e.reason??X.t(`helpers.eventsDebugTapes.unknownReason`)})}}var Ca={"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 wa(e,t){let n=Ca[e]??`Refused (${e}).`;return t.length>0?`${n} ${t}`:n}function Ta(e){if(e.length===0)return null;let t=new Date(e).getTime();return Number.isFinite(t)?t:null}function Ea(e){return e<1024*1024?X.t(`helpers.eventsDebugTapes.sizeKb`,{value:(e/1024).toFixed(0)}):X.t(`helpers.eventsDebugTapes.sizeMb`,{value:(e/1024/1024).toFixed(1)})}function Da(e){return e===null?`unknown`:Ea(e)}function Oa(e){return e===null?`unknown`:String(e)}function ka(e,t){let n=t.trim();return e===404?X.t(`helpers.eventsDebugTapes.exportUnknown`):e===503?n.length>0?n:X.t(`helpers.eventsDebugTapes.tapesUnavailable`):e===500?n.length>0?n:X.t(`helpers.eventsDebugTapes.exportUnreadable`):X.t(`helpers.eventsDebugTapes.downloadFailed`,{status:e})}l();function Aa({cameras:t,call:n,onPromoted:r}){let{t:i}=Z(),[o,c]=s(``),[l,u]=s(``),[d,f]=s(``),[p,m]=s(``),[h,g]=s(``),[_,v]=s(`auto`),[y,b]=s(!1),[x,S]=s(null),C=async()=>{let e=Number.parseInt(o===``?t[0]?.value??``:o,10),i=Ta(l),a=Ta(d);if(!Number.isFinite(e)||i===null||a===null){S(`Pick a camera and both ends of the window.`);return}b(!0),S(null);try{let t=ua(await n(Ki.promote,{deviceId:e,fromMs:i,toMs:a,scenario:p,...h.trim().length>0?{note:h.trim()}:{},..._===`day`||_===`ir`?{lighting:_}:{}}));t===null?S(Zi):t.ok?(S(`Promoted ${t.tapeId}: ${String(t.frames)} frames, ${Ea(t.bytes)}, ${String(t.pinnedTracks)} tracks pinned`+(t.state===`incomplete`?` — incomplete (it has gaps) and cannot become a case.`:`.`)),r()):S(wa(t.reason,t.detail))}catch(e){S(Qi(e))}finally{b(!1)}};return e(`div`,{className:`flex flex-wrap items-end gap-2 rounded-md border border-border px-3 py-2`,children:[a(`div`,{className:`w-40`,children:a(tt,{value:o,options:[...t],onChange:e=>c(e.target.value),"aria-label":i(`eventsDebugTapesPromoteForm.camera`,`Camera`)})}),a(ct,{type:`datetime-local`,"aria-label":i(`eventsDebugTapesPromoteForm.from`,`From`),value:l,onChange:e=>u(e.target.value),className:`w-48`}),a(ct,{type:`datetime-local`,"aria-label":i(`eventsDebugTapesPromoteForm.to`,`To`),value:d,onChange:e=>f(e.target.value),className:`w-48`}),a(ct,{"aria-label":i(`eventsDebugTapesPromoteForm.scenario`,`Scenario`),placeholder:`101-door-groups`,value:p,onChange:e=>m(e.target.value),className:`w-44`}),a(ct,{"aria-label":i(`eventsDebugTapesPromoteForm.note`,`Note`),placeholder:i(`eventsDebugTapesPromoteForm.optionalNote`,`optional note`),value:h,onChange:e=>g(e.target.value),className:`w-52`}),a(`div`,{className:`w-28`,children:a(tt,{value:_,"aria-label":i(`eventsDebugTapesPromoteForm.lighting`,`Lighting`),options:[{value:`auto`,label:i(`eventsDebugTapesPromoteForm.lightingAuto`,`Lighting: auto`)},{value:`day`,label:i(`eventsDebugTapes.dayMode`)},{value:`ir`,label:`IR`}],onChange:e=>v(e.target.value)})}),e(Y,{onClick:()=>void C(),disabled:y||t.length===0,children:[y?a(G,{className:`h-3.5 w-3.5 animate-spin`}):null,` `,i(`eventsDebugTapes.promoteWindow`)]}),a(`p`,{className:`w-full text-xs text-foreground-subtle`,children:i(`eventsDebugTapesPromoteForm.aPromotedTapeMayBe`,`A promoted tape may be shared as a test case — keep the scenario slug and note free of names or other personal data.`)}),x!==null&&a(`p`,{className:`w-full text-xs text-foreground`,children:x})]})}var ja=`pipeline-analytics`,Ma=`debug.listTracks`,Na=`debug.analyze`,Pa=T(`/addon/pipeline-analytics/debug-export`);function Fa(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Ia(e,t){let n=e[t];return typeof n==`string`?n:null}function La(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Ra(e,t){let n=e[t];return typeof n==`boolean`?n:null}function za(e){return e===`error`||e===`warn`||e===`info`}function Ba(e){if(!Fa(e))return null;let t=Ia(e,`code`),n=Ia(e,`detail`),r=e.severity;return t===null||n===null||!za(r)?null:{code:t,severity:r,detail:n}}function Va(e){if(!Fa(e))return null;let t=Ia(e,`trackId`),n=La(e,`deviceId`),r=Ia(e,`className`),i=La(e,`firstSeen`),a=La(e,`lastSeen`),o=La(e,`durationMs`),s=Ra(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=Ia(e,`label`),l=Ia(e,`subLabel`),u=Ia(e,`previewMissReason`),d=Ra(e,`markForTrain`),f=Ra(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:La(e,`importance`)??0,bestEventId:Ia(e,`bestEventId`)??``,...d===null?{}:{markForTrain:d},...f===null?{}:{favourited:f},debug:!0,...u===null||u.length===0?{}:{previewMissReason:u}}}function Ha(e){let t=Va(e);if(t===null||!Fa(e))return null;let n=La(e,`mediaCount`),r=La(e,`eventCount`),i=La(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=Ba(e);t!==null&&c.push(t)}let l=e.thumbnailProvenance;return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c,...ei(l)?{thumbnailProvenance:l}:{}}}function Ua(e){if(!Fa(e))return null;let t=Ra(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=Va(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function Wa(e){if(!Fa(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=Ha(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var Ga={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 Ka(e){return Ga[e]??e}var qa={error:0,warn:1,info:2};function Ja(e){return e.toSorted((e,t)=>qa[e.severity]-qa[t.severity]||e.code.localeCompare(t.code))}function Ya(e){return e.length===0?Pa:`${Pa}?deviceIds=${e.join(`,`)}`}function Xa(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 Za(e,t){return`${String(e)}:${t}`}function Qa(e,t){let n=[],r=new Set;for(let i of e){let e=Za(i.deviceId,i.trackId);!t.has(e)||r.has(e)||(r.add(e),n.push({deviceId:i.deviceId,trackId:i.trackId}))}return n}l();function $a({tapeId:t,call:n,onClose:r,onChanged:i}){let{t:o}=Z(),l=c({queryKey:[`events-debug`,`tapes`,`tracks`,t],queryFn:async()=>la(await n(Ki.tracks,{tapeId:t}))}),u=l.data??null,d=c({queryKey:[`events-debug`,`tapes`,`marks`,t],enabled:u!==null,queryFn:async()=>u===null?null:ga(await n(qi.list,{deviceId:u.deviceId,since:u.fromMs-Yi,until:u.toMs+Yi,limit:5e3}))}),[f,p]=s([]),[m,h]=s(``),[g,_]=s(null),v=e=>p(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),y=async e=>{_(null);try{for(let[t,r]of e)await n(t,r);p([]),await d.refetch(),i()}catch(e){_(Qi(e))}};if(u===null)return l.isLoading?a(`p`,{className:`text-xs`,children:o(`eventsDebugTapesReview.loadingTheTape`,`Loading the tape…`)}):a(Ee,{message:Zi});let b=u.deviceId,x=(e,t)=>y(e.map(e=>[qi.setRelation,{deviceId:b,...e,relation:t}])),S=e=>{let t=Number.parseFloat(m),n=e===`mixed`&&Number.isFinite(t)?u.fromMs+t*1e3:void 0;return y(f.map(t=>[qi.setPurity,{deviceId:b,trackId:t,purity:e,...n===void 0?{}:{switchAtMs:Math.round(n)}}]))},C=d.data==null?null:_a(d.data);return e(`div`,{className:`space-y-2 rounded-md border border-primary/40 px-3 py-2`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[a(`span`,{className:`text-xs font-medium`,children:o(`eventsDebugTapes.reviewLanes`,{id:u.tapeId,count:u.lanes.length})}),a(Y,{disabled:f.length<2,onClick:()=>void x(ya(f),`same-subject`),children:o(`eventsDebugTapesReview.sameSubject`,`Same subject`)}),a(Y,{variant:`secondary`,disabled:f.length<2,onClick:()=>void x(ba(f),`different-subjects`),children:o(`eventsDebugTapesReview.differentSubjects`,`Different subjects`)}),a(ct,{"aria-label":o(`eventsDebugTapesReview.changedAtSFromTape`,`Changed at (s from tape start)`),placeholder:o(`eventsDebugTapesReview.changedAtS`,`changed at s`),value:m,onChange:e=>h(e.target.value),className:`w-28`}),a(Y,{variant:`secondary`,disabled:f.length!==1,onClick:()=>void S(`mixed`),children:o(`eventsDebugTapesReview.mixed`,`Mixed`)}),a(Y,{variant:`secondary`,disabled:f.length===0,onClick:()=>void S(`not-a-subject`),children:o(`eventsDebugTapesReview.notASubject`,`Not a subject`)}),a(Y,{variant:u.reviewed?`secondary`:`primary`,onClick:()=>void y([[Ki.review,{tapeId:u.tapeId,reviewed:!u.reviewed}]]).then(()=>l.refetch()),children:u.reviewed?o(`eventsDebugTapesReview.markNotReviewed`,`Mark not reviewed`):o(`eventsDebugTapesReview.markReviewed`,`Mark reviewed`)}),a(Y,{variant:`ghost`,onClick:r,children:o(`common.close`,`Close`)})]}),g!==null&&a(Ee,{message:g}),C!==null&&a(Ee,{variant:`warning`,message:C}),a(`ul`,{className:`space-y-1`,children:u.lanes.toSorted((e,t)=>e.firstT-t.firstT).map(e=>a(eo,{lane:e,marks:d.data===null||d.data===void 0?[]:xa(e.trackId,d.data),selected:f.includes(e.trackId),onToggle:()=>v(e.trackId)},e.trackId))})]})}function eo({lane:t,marks:n,selected:r,onToggle:i}){let{t:o}=Z(),{src:s}=Vt(t.stillStored?Ht(`track`,t.trackId):void 0);return e(`li`,{className:`flex items-center gap-2 text-xs`,children:[a(`input`,{type:`checkbox`,"aria-label":o(`eventsDebugTapesReview.select`,`select {{trackId}}`,{trackId:t.trackId}),checked:r,onChange:i}),s===null?a(`div`,{className:`h-10 w-10 rounded bg-surface-hover`}):a(`img`,{src:s,alt:t.trackId,className:`h-10 w-10 rounded object-cover`}),a(`span`,{className:`font-mono`,children:t.trackId}),a(`span`,{children:t.cls}),a(`span`,{className:`text-foreground-subtle`,children:o(`eventsDebugTapes.laneFrames`,{range:`${Xa(t.firstT)} → ${Xa(t.lastT)}`,count:t.boundFrames})}),!t.stillStored&&a(`span`,{className:`text-foreground-subtle`,children:o(`eventsDebugTapesReview.notStoredMarkedThroughThe`,`not stored — marked through the tape`)}),n.map(e=>a(xt,{variant:`info`,children:e},e))]})}l();var to=`camstack_admin_token`;function no(){let e=U();return(t,n)=>e.trpcClient.addons.custom.mutate({addonId:ja,action:t,input:n})}async function ro(e,t){let n=localStorage.getItem(to),r={};n!==null&&(r.Authorization=`Bearer ${n}`);let i=await fetch(Xi(e),{headers:r});if(!i.ok){let e=await i.text().catch(()=>``);throw Error(ka(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 io(){let{t:e}=Z(),[t,n]=s(!1);return a(_e,{expanded:t,onExpandedChange:n,header:a(`span`,{className:`text-sm font-medium text-foreground`,children:e(`eventsDebugTapes.trackingTapes`,`Tracking tapes`)}),children:a(ao,{})})}function ao(){let{t}=Z(),r=no(),i=Ie({isCamera:!0,projection:`slim`}),o=n(()=>{let e=new Map;for(let t of i.data??[])e.set(t.id,t.name);return n=>e.get(n)??t(`cameraLoad.deviceLabel`,{deviceId:n})},[i.data,t]),l=c({queryKey:[`events-debug`,`tapes`,`status`],queryFn:async()=>aa(await r(Ki.status,{}))}),u=c({queryKey:[`events-debug`,`tapes`,`list`],queryFn:async()=>sa(await r(Ki.list,{}))}),[d,f]=s(null),[p,m]=s(null),h=async e=>{m(null);try{await ro(e.id,`${e.scenario}.tape-bundle.json.gz`)}catch(e){m(Qi(e))}},_=async e=>{let t=da(await r(Ki.release,{tapeId:e.id}));if(t===null)throw Error(Zi);let n=pa(t);if(n!==null)throw Error(n);await u.refetch()},v=async e=>{let t=fa(await r(Ki.remove,{tapeId:e.id}));if(t===null)throw Error(Zi);let n=pa(t);if(n!==null)throw Error(n);await u.refetch()};return e(`div`,{className:`space-y-3`,children:[a(`p`,{className:`text-xs text-foreground-subtle`,children:a(Lt,{i18nKey:`eventsDebugTapes.intro`,components:{b:a(`strong`,{}),code:a(`code`,{})}})}),p!==null&&a(Ee,{message:p}),l.isLoading&&a(`p`,{className:`text-xs text-foreground-subtle`,children:t(`eventsDebugTapes.loadingCameraStatus`,`Loading camera status…`)}),l.data===null&&a(Ee,{message:`The server answered in a shape this build does not understand.`}),e(`table`,{className:`w-full text-xs`,children:[a(`thead`,{children:e(`tr`,{className:`text-left text-foreground-subtle`,children:[a(`th`,{children:t(`eventsDebugTapes.camera`,`Camera`)}),a(`th`,{children:t(`eventsDebugTapes.state`,`State`)}),a(`th`,{children:t(`eventsDebugTapes.framesMin`,`Frames/min`)}),a(`th`,{children:t(`eventsDebugTapes.lastHour`,`Last hour`)}),a(`th`,{children:t(`eventsDebugTapes.held`,`Held`)}),a(`th`,{children:t(`eventsDebugTapes.gaps`,`Gaps`)})]})}),a(`tbody`,{children:(l.data??[]).map(n=>e(`tr`,{children:[a(`td`,{children:o(n.deviceId)}),a(`td`,{children:a(xt,{variant:n.state===`recording`?`success`:n.state===`off`?`default`:n.state===`unknown`?`warning`:`danger`,children:Sa(n)})}),a(`td`,{children:n.framesPerMin===void 0?`—`:String(Math.round(n.framesPerMin))}),a(`td`,{title:n.shelfError,children:Da(n.bytesLastHour)}),a(`td`,{title:n.shelfError,children:t(`eventsDebugTapes.segsHeld`,{count:Oa(n.segmentsHeld),size:Da(n.bytesHeld)})}),a(`td`,{children:String(n.gapsSinceArmed)})]},n.deviceId))})]}),a(Aa,{cameras:va(l.data??[]).map(e=>({value:String(e.deviceId),label:e.segmentsUnknown?t(`eventsDebugTapes.segmentsUnknown`,`{{value1}} (segments unknown)`,{value1:o(e.deviceId)}):o(e.deviceId)})),call:r,onPromoted:()=>void u.refetch()}),u.isLoading&&a(`p`,{className:`text-xs text-foreground-subtle`,children:t(`eventsDebugTapes.loadingPromotedTapes`,`Loading promoted tapes…`)}),u.data===null&&a(Ee,{message:`The server answered in a shape this build does not understand.`}),e(`table`,{className:`w-full text-xs`,children:[a(`thead`,{children:e(`tr`,{className:`text-left text-foreground-subtle`,children:[a(`th`,{children:t(`eventsDebugTapes.scenario`,`Scenario`)}),a(`th`,{children:t(`eventsDebugTapes.camera`,`Camera`)}),a(`th`,{children:t(`eventsDebugTapes.window`,`Window`)}),a(`th`,{children:t(`eventsDebugTapes.state`,`State`)}),a(`th`,{children:t(`eventsDebugTapes.tracks`,`Tracks`)}),a(`th`,{})]})}),a(`tbody`,{children:(u.data??[]).map(n=>e(`tr`,{children:[a(`td`,{children:n.scenario}),a(`td`,{children:o(n.deviceId)}),e(`td`,{children:[new Date(n.fromMs).toLocaleString(),` · `,Xa(n.toMs-n.fromMs),` `,`· `,n.lighting]}),e(`td`,{children:[a(xt,{variant:n.state===`complete`?`success`:`warning`,children:n.state}),` `,n.reviewed&&a(xt,{variant:`info`,children:t(`eventsDebugTapes.reviewed`)}),` `,n.released&&a(xt,{children:t(`eventsDebugTapes.released`)})]}),a(`td`,{children:t(`eventsDebugTapes.storedOf`,{stored:String(n.tracksStillStored),total:String(n.tracks.length)})}),e(`td`,{className:`space-x-1 text-right`,children:[a(Y,{variant:`secondary`,"aria-label":t(`eventsDebugTapes.review`,`Review {{scenario}}`,{scenario:n.scenario}),onClick:()=>f(n.id),children:t(`eventsDebugTapes.review2`,`Review`)}),a(Y,{variant:`ghost`,"aria-label":t(`eventsDebugTapes.download`,`Download {{scenario}}`,{scenario:n.scenario}),onClick:()=>void h(n),children:a(g,{className:`h-3.5 w-3.5`})}),a(Ze,{label:t(`eventsDebugTapes.release`,`Release`),icon:M,title:t(`eventsDebugTapes.release2`,`Release {{scenario}}?`,{scenario:n.scenario}),description:t(`eventsDebugTapes.releasingReturnsThisTapeS`,`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:t(`eventsDebugTapes.release`,`Release`),triggerVariant:`ghost`,confirmVariant:`danger`,disabled:n.released,action:()=>_(n)}),a(Ze,{label:t(`common.delete`,`Delete`),icon:b,title:t(`eventsDebugTapes.delete`,`Delete {{scenario}}?`,{scenario:n.scenario}),description:t(`eventsDebugTapes.deletingRemovesThePromotedBundle`,`Deleting removes the promoted bundle and its index row for good. Its tracks' pins are released first — this cannot be undone.`),confirmLabel:t(`common.delete`,`Delete`),triggerVariant:`ghost`,confirmVariant:`danger`,action:()=>v(n)})]})]},n.id))})]}),d!==null&&a($a,{tapeId:d,call:r,onClose:()=>f(null),onChanged:()=>void u.refetch()})]})}l();var oo=`all`,so=`The server answered in a shape this build does not understand.`,co={error:`danger`,warn:`warning`,info:`info`};function lo({findings:e}){let{t}=Z();return e.length===0?a(xt,{variant:`success`,children:t(`eventsDebug.noAnomalyFound`,`no anomaly found`)}):a(`div`,{className:`flex flex-wrap gap-1`,children:Ja(e).map(e=>a(xt,{variant:co[e.severity],title:e.detail,children:Ka(e.code)},e.code))})}function uo({track:t,report:n,analyzing:r}){let{t:i}=Z(),o=ii(n?.previewMissReason??t.previewMissReason);return e(`div`,{className:`space-y-1 border-t border-border pt-1.5`,children:[n===void 0?a(`span`,{className:`text-[10px] text-foreground-subtle`,children:r?i(`eventsDebug.analysing`,`analysing…`):i(`eventsDebug.notAnalysed`,`not analysed`)}):e(d,{children:[a(lo,{findings:n.findings}),a(`p`,{className:`text-[10px] text-foreground-subtle`,title:n.mediaKinds.length>0?n.mediaKinds.join(`, `):i(`eventsDebug.noMediaOfAnyKind`,`no media of any kind`),children:i(`eventsDebug.reportCounts`,{media:String(n.mediaCount),events:String(n.eventCount),positions:String(n.positionCount)})})]}),o!==null&&a(`p`,{className:`text-[10px] text-foreground-subtle`,title:o.raw,children:o.sentence})]})}function fo(){let{t}=Z(),r=U(),[i,o]=s(oo),[l,u]=s(!1),[d,f]=s(null),[m,h]=s(new Set),[_,v]=s(null),[y,b]=s(null),[x,S]=s(null),[C,w]=s([]),T=Si(),E=Ie({isCamera:!0,projection:`slim`}),D=n(()=>[{value:oo,label:t(`eventsDebug.allCameras`,`All cameras`)},...(E.data??[]).map(e=>({value:String(e.id),label:e.name}))],[E.data,t]),O=n(()=>{let e=new Map;for(let t of E.data??[])e.set(t.id,t.name);return e},[E.data]),k=e=>O.get(e)??t(`eventsDebug.cameraFallback`,{deviceId:e}),j=n(()=>i===oo?[]:[Number.parseInt(i,10)],[i]),M=c({queryKey:[`events-debug`,`list`,j],queryFn:async()=>Ua(await r.trpcClient.addons.custom.mutate({addonId:ja,action:Ma,input:j.length===0?{}:{deviceIds:j}}))}),N=n(()=>(M.data?.tracks??[]).map(e=>e.trackId),[M.data]),P=c({queryKey:[`events-debug`,`analyze`,N],enabled:N.length>0,queryFn:async()=>Wa(await r.trpcClient.addons.custom.mutate({addonId:ja,action:Na,input:{trackIds:N}}))}),I=n(()=>{let e=new Map;for(let t of P.data?.reports??[])e.set(t.trackId,t);return e},[P.data]),L=M.data?.tracks??[],B=M.data===null||P.data===null,V=()=>{M.refetch(),P.refetch()},H=e=>{h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},W=()=>{h(new Set(L.map(e=>Za(e.deviceId,e.trackId))))},ee=()=>h(new Set),K=async(e,t)=>{let n=e===`analyzed`?{debug:!1}:{favourited:!0},r=0,i=[];for(let e of t)try{await T.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,flags:n}),r+=1}catch{i.push(e.trackId)}return{applied:r,refused:i}},te=e=>{if(!yi||y!==null)return;let t=Qa(L,m);t.length!==0&&(b(e),S(null),(async()=>{let n=await K(e,t);b(null);let r=new Set(n.refused);h(new Set(t.filter(e=>r.has(e.trackId)).map(e=>Za(e.deviceId,e.trackId)))),e===`analyzed`&&w(t.filter(e=>!r.has(e.trackId))),n.refused.length>0&&S(`${String(n.refused.length)} of ${String(t.length)} were refused by the server and are still selected. Check the hub log.`),M.refetch()})())},ne=()=>{let e=C;e.length===0||y!==null||(b(`analyzed`),S(null),(async()=>{for(let t of e)try{await T.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,flags:{debug:!0}})}catch{S(`Some tracks could not be re-marked. Refresh and try again.`)}b(null),w([]),M.refetch()})())},re=async()=>{u(!0),f(null);try{await Gt(Ya(j),`camstack-debug.zip`)}catch(e){f(e instanceof Error?e.message:`Export failed.`)}finally{u(!1)}},J=y!==null;return e(`section`,{className:`space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[a(`div`,{className:`w-44`,children:a(tt,{value:i,options:D,onChange:e=>o(e.target.value)})}),e(Y,{variant:`secondary`,onClick:V,disabled:M.isFetching,children:[M.isFetching?a(G,{className:`h-3.5 w-3.5 animate-spin`}):a(q,{className:`h-3.5 w-3.5`}),t(`common.refresh`,`Refresh`)]}),e(Y,{onClick:()=>void re(),disabled:l||L.length===0,children:[l?a(G,{className:`h-3.5 w-3.5 animate-spin`}):a(g,{className:`h-3.5 w-3.5`}),t(`eventsDebug.exportAll`,{count:String(L.length)})]}),L.length>0&&m.size<L.length&&a(Y,{variant:`ghost`,onClick:W,children:t(`eventsDebug.selectAll`,`Select all`)})]}),a(`p`,{className:`text-xs text-foreground-subtle`,children:a(Lt,{i18nKey:`eventsDebug.debugMarkNote`,components:{code:a(`code`,{}),strong:a(`strong`,{})}})}),a(io,{}),M.isError&&a(Ee,{message:t(`eventsDebug.couldNotLoadTheMarked`,`Could not load the marked tracks.`)}),B&&!M.isError&&a(Ee,{message:so}),d!==null&&a(Ee,{message:d}),x!==null&&a(Ee,{message:x}),M.data?.truncated===!0&&a(Ee,{message:t(`eventsDebug.aCameraFilledThePer`,`A camera filled the per-camera cap — some marked tracks are not listed. Un-mark a few, or filter to one camera.`)}),(P.data?.vanished.length??0)>0&&a(`p`,{className:`text-xs text-foreground-subtle`,children:t(`eventsDebug.vanished`,{count:String(P.data?.vanished.length)})}),m.size>0&&e(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[a(`span`,{className:`text-xs font-medium text-foreground`,children:t(`common.selectedCount`,{count:m.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[a(`span`,{title:yi?void 0:`Track flags arrive with the next server update`,children:e(Y,{variant:`secondary`,onClick:()=>te(`keep`),disabled:!yi||J,children:[y===`keep`?a(G,{className:`h-3.5 w-3.5 animate-spin`}):a(A,{className:`h-3.5 w-3.5`}),` `,t(`eventsDebug.keep`,`Keep`)]})}),a(`span`,{title:yi?void 0:`Track flags arrive with the next server update`,children:e(Y,{onClick:()=>te(`analyzed`),disabled:!yi||J,children:[y===`analyzed`?a(G,{className:`h-3.5 w-3.5 animate-spin`}):a(p,{className:`h-3.5 w-3.5`}),` `,t(`eventsDebug.analyzed`,`Analyzed`)]})}),a(Y,{variant:`ghost`,onClick:ee,disabled:J,children:a(F,{className:`h-3.5 w-3.5`})})]})]}),C.length>0&&e(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-border bg-surface px-3 py-2`,children:[a(`span`,{className:`text-xs text-foreground`,children:t(`eventsDebug.markedAnalyzed`,{count:String(C.length)})}),e(Y,{variant:`ghost`,onClick:ne,disabled:J,children:[a(z,{className:`h-3.5 w-3.5`}),` `,t(`eventsDebug.undo`)]}),a(Y,{variant:`ghost`,onClick:()=>w([]),disabled:J,children:a(F,{className:`h-3.5 w-3.5`})})]}),M.isLoading?a(Xe,{status:`pending`,pendingMessage:`Loading…`,testId:`debug-tracks-grid`}):L.length===0?a(Te,{icon:R,title:t(`eventsDebug.noTrackIsMarkedFor`,`No track is marked for debug`),description:t(`eventsDebug.markOneFromATrack`,`Mark one from a track's actions on the Feed to see it here.`)}):a(Xe,{status:`ready`,testId:`debug-tracks-grid`,children:L.map(e=>{let t=I.get(e.trackId);return a(oi,{row:e,cameraName:k(e.deviceId),nowMs:e.lastSeen,selected:m.has(Za(e.deviceId,e.trackId)),onToggleSelect:H,onOpenDetail:v,...t?.thumbnailProvenance===void 0?{}:{provenance:t.thumbnailProvenance},footer:a(uo,{track:e,report:t,analyzing:P.isFetching})},Za(e.deviceId,e.trackId))})}),_&&a(Gi,{row:_,cameraName:k(_.deviceId),deleteAvailable:Ni,onClose:()=>v(null),onDeleted:()=>{v(null),M.refetch()},onFlagsChanged:e=>{e.debug||(v(null),M.refetch())}})]})}var po=200,mo=3e4,ho=[];function go(e){let t=U(),n=e.deviceIds.length>0,r=[...e.deviceIds].sort((e,t)=>e-t),{data:i,isLoading:a}=c({queryKey:[`events-feed`,r,e.since,e.until,e.minImportance??null,e.classFilter??null],enabled:n,staleTime:mo,refetchInterval:mo,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEventsBatch.query({deviceIds:r,since:e.since,until:e.until,limit:po,...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:Jr(qr(i??ho),`importance`),isLoading:n&&a}}l();var _o=[`events-feed`],vo=2e3;function yo(e){let n=u(),r=e?.paused===!0,a=t(n);a.current=n;let c=t(r);c.current=r;let[l,d]=s(!1),f=i(()=>{a.current.invalidateQueries({queryKey:_o})},[]),p=t(void 0);p.current||=Br({delayMs:vo,invalidate:()=>{c.current?d(!0):f()}}),o(()=>()=>p.current?.cancel(),[]),o(()=>{r||!l||(d(!1),f())},[r,l,f]);let m=i(()=>{d(!1),f()},[f]);return ot(ie.PipelineAnalyticsDetectionEvent,()=>{p.current?.trigger()}),ot(ie.PipelineAnalyticsTrackEnded,()=>{p.current?.trigger()}),{pending:l,refreshNow:m}}l();function bo({groups:t,selected:r,onChange:i,loading:o=!1}){let{t:c}=Z(),l=Ge(),[u,d]=s(!1),[f,p]=s(``),[m,h]=s(new Set),g=f.trim().toLowerCase(),v=e=>g.length===0||He(e,c).toLowerCase().includes(g),y=n(()=>t.map(e=>({macro:e.macro,subs:e.subs.filter(t=>v(t)||v(e.macro))})).filter(e=>v(e.macro)||e.subs.length>0),[t,g]),b=e=>h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),x=e=>{let t=new Set(r),n=r.has(e.macro.kind)&&e.subs.every(e=>r.has(e.kind)),a=[e.macro.kind,...e.subs.map(e=>e.kind)];if(n)for(let e of a)t.delete(e);else for(let e of a)t.add(e);i(t)},S=e=>{let t=new Set(r);t.has(e)?t.delete(e):t.add(e),i(t)},C=()=>i(new Set),w=r.size;return e(`div`,{className:`relative`,children:[e(`button`,{type:`button`,onClick:()=>d(e=>!e),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${w>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(_,{className:`h-3.5 w-3.5`}),w>0?c(`detectionIntelligence.eventKindFilter.kinds`,`Kinds ({{value1}})`,{value1:String(w)}):c(`detectionIntelligence.eventKindFilter.kinds2`,`Kinds`),a(O,{className:`h-3 w-3`})]}),u&&e(`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:[e(`div`,{className:`mb-2 flex items-center gap-1 rounded border border-border px-1.5`,children:[a(W,{className:`h-3.5 w-3.5 text-foreground-subtle`}),a(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:c(`detectionIntelligence.eventKindFilter.searchKinds`,`Search kinds…`),className:`w-full bg-transparent py-1 text-xs outline-none`}),w>0&&a(`button`,{type:`button`,onClick:C,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:c(`detectionIntelligence.eventKindFilter.clear`,`Clear`)})]}),y.length===0&&a(`div`,{className:`px-1 py-2 text-[11px] text-foreground-subtle`,children:o?c(`detectionIntelligence.eventKindFilter.loadingKinds`,`Loading kinds…`):g.length>0?c(`detectionIntelligence.eventKindFilter.noKindMatchesThatSearch`,`No kind matches that search.`):c(`detectionIntelligence.eventKindFilter.theseCamerasAdvertiseNoEvent`,`These cameras advertise no event kinds.`)}),y.map(t=>{let n=ht(t.macro.iconId),i=m.has(t.macro.kind)||g.length>0,o=r.has(t.macro.kind);return e(`div`,{className:`mb-0.5`,children:[e(`div`,{className:`flex items-center gap-1`,children:[t.subs.length>0?a(`button`,{type:`button`,onClick:()=>b(t.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":c(`detectionIntelligence.eventKindFilter.expand`,`Expand`),children:a(i?O:N,{className:`h-3 w-3`})}):a(`span`,{className:`w-3`}),e(`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:[a(`input`,{type:`checkbox`,checked:o,onChange:()=>x(t),className:`accent-primary`}),a(n,{className:`h-3.5 w-3.5`,style:{color:l(t.macro.kind)}}),a(`span`,{className:`font-medium`,children:He(t.macro,c)})]})]}),i&&t.subs.map(t=>{let n=ht(t.iconId);return e(`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:[a(`input`,{type:`checkbox`,checked:r.has(t.kind),onChange:()=>S(t.kind),className:`accent-primary`}),a(n,{className:`h-3.5 w-3.5`,style:{color:l(t.kind)}}),a(`span`,{children:He(t,c)})]},t.kind)})]},t.macro.kind)})]})]})}function xo(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 So(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var Co=new Set([`detection`,`package`]);function wo(e,t){return[...xo(e,t).values()].filter(e=>e.parentKind===null&&Co.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function To(e,t){let n=xo(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,So(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))}l();function Eo(){let[e,n]=s(!1),r=t(null),[a,c]=s(0),l=i(e=>{r.current!==e&&(r.current=e,c(e=>e+1))},[]);return o(()=>{let e=r.current;if(!e||typeof IntersectionObserver>`u`){n(!1);return}let t=new IntersectionObserver(e=>{let t=e[e.length-1];t&&n(!t.isIntersecting)},{rootMargin:`64px 0px 0px 0px`,threshold:0});return t.observe(e),()=>t.disconnect()},[a]),{ref:l,scrolledPast:e}}l();var Do=[`events-feed`],Oo=60,ko=[{value:`importance`,labelKey:`detectionIntelligence.eventsSection.sortImportance`,icon:se},{value:`time`,labelKey:`detectionIntelligence.eventsSection.sortRecent`,icon:H}];function Ao(){let{t}=Z(),r=u(),i=ze(),c=Pe(),[l,f]=s(Rn),[p,m]=s(new Set),[h,g]=s(new Set),[_,v]=s(0),[y,x]=s(`time`),[S,C]=s(new Set),[w,T]=s(null),[E,D]=s(()=>Date.now());o(()=>{let e=setInterval(()=>D(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:O,until:k}=n(()=>Qr({fromMs:l.fromMs,toMs:l.toMs},E),[l.fromMs,l.toMs,E]),A=Eo(),{pending:j,refreshNow:M}=yo({paused:w!==null||S.size>0||A.scrolledPast}),{data:N=[]}=Ie({isCamera:!0,projection:`slim`}),P=n(()=>N.map(e=>e.id),[N]),{data:I,isLoading:L}=Ot({deviceIds:P},{enabled:P.length>0,staleTime:5*6e4}),R=n(()=>To(I??[],p),[I,p]),z=Ii(),B=z.isPending,{rows:H,isLoading:U}=go({deviceIds:P,since:O,until:k,minImportance:_>0?_:void 0,classFilter:h.size===1?[...h][0]:void 0}),W=n(()=>{let e=new Map;for(let t of N??[])e.set(t.id,t.name);return e},[N]),ee=e=>W.get(e)??t(`detectionIntelligence.cameraFallback`,{id:String(e)}),K=n(()=>Gn(H).map(e=>({id:e,name:ee(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[H,W]),te=n(()=>Jr(Yr(H,{cameras:p,classes:h,minImportance:_}),y),[H,p,h,_,y]),q=tr(te,Oo,n(()=>JSON.stringify([[...p].sort((e,t)=>e-t),[...h].sort(),_,y,O,k]),[p,h,_,y,O,k])),ne=()=>{r.invalidateQueries({queryKey:Do})},re=()=>C(new Set);function J(e){C(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function ie(){if(S.size===0||!Ni)return;let e=Zr(H,S),n=[...e.values()].reduce((e,t)=>e+t.length,0);n!==0&&(async()=>{await c({title:t(`detectionIntelligence.eventsSection.deleteTitle`,{count:n}),message:t(`detectionIntelligence.eventsSection.deleteMessage`,{count:n}),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&ae(e)})()}function ae(e){let n=[...e];Promise.allSettled(n.map(([e,t])=>z.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{ne();let r=[],a=new Set;if(e.forEach((e,t)=>{let i=n[t];if(!i)return;let[o,s]=i;if(e.status===`fulfilled`)for(let e of s)a.add(Xr(o,e));else r.push(o)}),C(e=>{let t=new Set(e);for(let e of a)t.delete(e);return t}),r.length>0){let e=r.map(e=>ee(e)).join(`, `);i({title:t(`detectionIntelligence.eventsSection.someTracksWereNotDeleted`,`Some tracks were not deleted`),message:t(`detectionIntelligence.eventsSection.failedToDeleteTracksOn`,`Failed to delete tracks on: {{names}}. They remain selected — retry, or check the server logs.`,{names:e}),variant:`danger`})}})}let oe=te.length!==H.length;return e(`div`,{className:`relative space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[a(lr,{onChange:f}),a(sr,{cameras:K,selected:p,onChange:m}),a(bo,{groups:R,selected:h,onChange:g,loading:L}),e(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[a(`span`,{children:t(`detectionIntelligence.eventsSection.minScore`,`Min score`)}),a(`input`,{type:`range`,min:0,max:1,step:.05,value:_,onChange:e=>v(Number(e.target.value)),className:`h-1 w-24 cursor-pointer accent-primary`,"aria-label":t(`detectionIntelligence.eventsSection.minimumImportance`,`Minimum importance`)}),a(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(_*100)})]}),a(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:ko.map(n=>{let r=n.icon;return e(`button`,{type:`button`,onClick:()=>x(n.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${y===n.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(r,{className:`h-3.5 w-3.5`}),` `,t(n.labelKey)]},n.value)})}),!U&&a(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:oe?t(`detectionIntelligence.eventsSection.ofEvents`,`{{value1}} of {{value2}} events`,{value1:String(te.length),value2:String(H.length)}):t(`detectionIntelligence.eventsSection.eventCount`,{count:te.length})})]}),S.size>0&&e(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[a(`span`,{className:`text-xs font-medium text-foreground`,children:t(`common.selectedCount`,{count:S.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[a(`span`,{title:Ni?void 0:`Track deletion arrives with the next server update`,children:e(Y,{variant:`secondary`,onClick:ie,disabled:!Ni||B,children:[B?a(G,{className:`h-3.5 w-3.5 animate-spin`}):a(b,{className:`h-3.5 w-3.5`}),` `,t(`common.delete`,`Delete`)]})}),a(Y,{variant:`ghost`,onClick:re,disabled:B,children:a(F,{className:`h-3.5 w-3.5`})})]})]}),j&&a(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:a(`button`,{type:`button`,onClick:M,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:t(`detectionIntelligence.eventsSection.newEventsRefresh`,`New events — refresh`)})}),U?a(Xe,{status:`pending`,pendingMessage:`Loading events…`,testId:`events-grid`}):te.length===0?a(Te,{icon:V,title:oe?t(`detectionIntelligence.eventsSection.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.eventsSection.noKeyEventsInThis`,`No key events in this window`),description:oe?t(`detectionIntelligence.eventsSection.widenTheDateRangeClear`,`Widen the date range, clear cameras or kinds, or lower the min score.`):t(`detectionIntelligence.eventsSection.capturedTracksAppearHereWhen`,`Captured tracks appear here when the pipeline scores a key event.`)}):e(d,{children:[a(`div`,{ref:A.ref,"aria-hidden":!0,className:`h-0`}),a(Xe,{status:`ready`,testId:`events-grid`,children:q.pageItems.map(e=>a(oi,{row:e,cameraName:ee(e.deviceId),nowMs:E,selected:S.has(Xr(e.deviceId,e.trackId)),onToggleSelect:J,onOpenDetail:T},Xr(e.deviceId,e.trackId)))}),a(ir,{currentPage:q.page,totalItems:q.totalItems,pageSize:q.pageSize,onPageChange:q.setPage,itemNoun:`events`})]}),w&&a(Gi,{row:w,cameraName:ee(w.deviceId),deleteAvailable:Ni,onClose:()=>T(null),onDeleted:()=>{ne(),T(null)},onFlagsChanged:e=>{T(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug,favourited:e.favourited}:t)}})]})}var jo=`/addon/training`;function Mo(){let{t}=Z(),n=Rt();return e(Mt,{className:`flex flex-col gap-3 border-border bg-surface p-3 sm:flex-row sm:items-center sm:gap-4`,"data-testid":`events-feed-retrain-cta`,children:[e(`div`,{className:`flex min-w-0 flex-1 items-start gap-2.5`,children:[a(S,{className:`mt-0.5 h-4 w-4 shrink-0 text-primary`,"aria-hidden":!0}),e(`div`,{className:`min-w-0 space-y-0.5`,children:[a(`p`,{className:`text-xs font-medium text-foreground`,children:t(`detectionIntelligence.retrainTabCallout.trainingFromThisFeed`,`Training from this feed`)}),a(`p`,{className:`${re} leading-relaxed`,children:t(`detectionIntelligence.retrainTabCallout.markATrackWithThe`,`Mark a track with the graduation-cap control on its card. On Training you correct frames, build collections, and start cloud fine-tunes.`)})]})]}),a(Y,{variant:`outline`,size:`sm`,className:`shrink-0 self-start sm:self-center`,onClick:()=>n(jo),children:t(`detectionIntelligence.retrainTabCallout.openTraining`,`Open Training`)})]})}l();var No=50,Po=350,Fo=[{value:`loose`,labelKey:`detectionIntelligence.semanticEventSearch.looseLabel`,titleKey:`detectionIntelligence.semanticEventSearch.looseTitle`},{value:`balanced`,labelKey:`detectionIntelligence.semanticEventSearch.balancedLabel`,titleKey:`detectionIntelligence.semanticEventSearch.balancedTitle`},{value:`strict`,labelKey:`detectionIntelligence.semanticEventSearch.strictLabel`,titleKey:`detectionIntelligence.semanticEventSearch.strictTitle`}];function Io(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 Lo({onActiveChange:t}){let{t:r}=Z(),[i,c]=s(``),[l,u]=s(`loose`),[d,f]=s(null),[p,m]=s(null),[h,g]=s(null),_=pt(i,Po).trim(),v=_.length>0;o(()=>{t(v)},[v,t]);let[y,b]=s(()=>Date.now());o(()=>{let e=setInterval(()=>b(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:x=[]}=Ie({isCamera:!0,projection:`slim`}),S=n(()=>{let e=new Map;for(let t of x)e.set(t.id,t.name);return e},[x]),C=e=>S.get(e)??r(`detectionIntelligence.cameraFallback`,{id:String(e)}),w=n(()=>x.map(e=>e.id),[x]),{data:T}=Ot({deviceIds:w},{enabled:w.length>0,staleTime:5*6e4}),E=n(()=>wo(T??[],new Set(p===null?[]:[p])),[T,p]);o(()=>{d!==null&&(E.some(e=>e.kind===d)||f(null))},[E,d]);let{data:D,isFetching:O,isError:k,error:A}=at({text:_,strictness:l,limit:No,classFilter:d??void 0,deviceId:p??void 0},{enabled:v}),j=n(()=>[...D??[]].sort((e,t)=>t.score-e.score).map(e=>({...Io(e),score:e.score})),[D]);function M(e){f(t=>t===e?null:e)}return e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(`div`,{className:`relative min-w-[16rem] flex-1`,children:[a(W,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),a(`input`,{type:`text`,value:i,onChange:e=>c(e.target.value),placeholder:r(`detectionIntelligence.semanticEventSearch.semanticSearchDescribeWhatYou`,`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":r(`detectionIntelligence.semanticEventSearch.semanticEventSearch`,`Semantic event search`)}),i&&a(`button`,{type:`button`,onClick:()=>c(``),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":r(`detectionIntelligence.semanticEventSearch.clearSearch`,`Clear search`),children:a(F,{className:`h-3.5 w-3.5`})})]}),O&&v&&a(G,{className:`h-4 w-4 shrink-0 animate-spin text-foreground-subtle`})]}),e(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[a(`div`,{className:`flex items-center gap-1`,children:E.map(e=>a(`button`,{type:`button`,onClick:()=>M(e.kind),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${d===e.kind?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:He(e)},e.kind))}),e(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[a(`span`,{children:r(`detectionIntelligence.semanticEventSearch.camera`,`Camera`)}),a(tt,{value:p===null?``:String(p),onChange:e=>m(e.target.value===``?null:Number(e.target.value)),className:`h-7 text-xs`,"aria-label":r(`detectionIntelligence.semanticEventSearch.filterByCamera`,`Filter by camera`),options:[{value:``,label:r(`detectionIntelligence.semanticEventSearch.all`,`All`)},...x.map(e=>({value:String(e.id),label:e.name}))]})]}),e(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[a(`span`,{children:r(`detectionIntelligence.semanticEventSearch.match`,`Match`)}),a(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Fo.map(e=>a(`button`,{type:`button`,onClick:()=>u(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${l===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:r(e.titleKey),children:r(e.labelKey)},e.value))})]}),v&&!O&&!k&&a(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:r(`common.matches`,{count:j.length})})]})]}),v&&e(`div`,{className:`space-y-3`,children:[k&&e(`p`,{className:`py-4 text-xs text-danger`,children:[r(`detectionIntelligence.semanticEventSearch.searchFailed`,`Search failed:`),` `,A instanceof Error?A.message:r(`detectionIntelligence.semanticEventSearch.unknownError`,`unknown error`),`. Check that the CLIP embedding step is enabled.`]}),!k&&O&&j.length===0&&a(Xe,{status:`pending`,pendingMessage:`Searching…`,testId:`semantic-events-grid`}),!k&&!O&&j.length===0&&a(Xe,{status:`empty`,emptyMessage:r(`detectionIntelligence.semanticEventSearch.noSemanticMatchesForTry`,`No semantic matches for “{{debounced}}”. Try a looser match threshold or a different phrasing.`,{debounced:_}),testId:`semantic-events-grid`}),!k&&j.length>0&&a(Xe,{status:`ready`,testId:`semantic-events-grid`,children:j.map(e=>a(oi,{row:e,cameraName:C(e.deviceId),nowMs:y,score:e.score,onOpenDetail:g},e.id))})]}),h&&a(Gi,{row:h,cameraName:C(h.deviceId),deleteAvailable:Ni,onClose:()=>g(null),onDeleted:()=>g(null)})]})}l();function Ro(e,t){let n=Math.max(0,Math.round((e-t)/6e4));if(n<1)return X.t(`helpers.relativeTime.justNow`);if(n<60)return`${String(n)}m`;let r=Math.floor(n/60);return`${String(r)}h ${String(n%60)}m`}function zo({row:t,cameraName:n,nowMs:r}){let{t:i}=Z(),o=Vt(t.keyFrameMediaId===void 0?void 0:Wt(t.keyFrameMediaId));return e(`div`,{className:`flex flex-col overflow-hidden rounded-md border border-border bg-surface`,children:[e(`div`,{className:`relative aspect-video overflow-hidden bg-surface-hover`,children:[o.src?a(`img`,{src:o.src,alt:i(`detectionIntelligence.stationarySection.parkedOn`,`Parked {{className}} on {{cameraName}}`,{className:t.className,cameraName:n}),className:`h-full w-full object-cover`}):a(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:a(le,{className:`h-6 w-6`})}),a(`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:t.label??t.className})]}),e(`div`,{className:`flex flex-col gap-0.5 p-1.5`,children:[a(`span`,{className:`truncate text-[11px] text-foreground`,children:n}),a(`span`,{className:`text-[10px] text-foreground-subtle`,children:i(`common.parkedSince`,{since:Ro(r,t.becameStationaryAt)})})]})]})}function Bo(){let{t}=Z(),[r,i]=s(!1),o=Date.now(),{data:c=[]}=Ie({isCamera:!0,projection:`slim`}),l=n(()=>c.map(e=>e.id),[c]),u=n(()=>{let e=new Map;for(let t of c)e.set(t.id,t.name);return e},[c]),{rows:d,unreadableCount:f}=Bt(l);return d.length===0&&f===0?null:e(`div`,{className:`rounded-md border border-border bg-surface/40`,children:[e(`button`,{type:`button`,onClick:()=>i(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,children:[a(r?O:N,{className:`h-4 w-4 text-foreground-subtle`}),a(le,{className:`h-4 w-4 text-foreground-subtle`}),a(`span`,{className:`text-sm font-semibold text-foreground`,children:t(`detectionIntelligence.stationarySection.stationary`,`Stationary`)}),a(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:d.length}),a(`span`,{className:`ml-2 text-[11px] text-foreground-subtle`,children:t(`detectionIntelligence.stationarySection.parkedObjectsKeptOutOf`,`Parked objects — kept out of the event feed`)}),f>0?a(`span`,{className:`ml-2 text-[11px] text-warning`,children:t(`detectionIntelligence.stationarySection.unreadable`,{count:f})}):null]}),r&&a(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:d.map(e=>a(zo,{row:e,cameraName:u.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:o},e.id))})]})}l();function Vo(){let[t,n]=s(!1);return e(`section`,{className:`space-y-3`,children:[a(Mo,{}),a(Lo,{onActiveChange:n}),!t&&a(Bo,{}),!t&&a(Ao,{})]})}function Ho(){let{t:e}=Z(),[t]=It();return t.get(`section`)===`retrain`?a(Ft,{to:`/addon/training`,replace:!0}):a(zt,{sectionsOnly:!0,paramName:`section`,defaultSection:`feed`,sectionsLabel:`Events sections`,sections:[{id:`feed`,label:e(`events.feed`,`Feed`),content:a(Vo,{})},{id:`debug`,label:e(`events.debug`,`Debug`),content:a(fo,{})}]})}function Uo(e){return e==null?null:e.cropUrl!==void 0&&e.cropUrl.length>0?e.cropUrl:e.base64!==void 0&&e.base64.length>0?`data:image/jpeg;base64,${e.base64}`:null}l();var Wo=[[`plateGallery`]];function Go({plateIds:t,vehicles:n,onDone:r}){let{t:i}=Z(),o=u(),c=we(),l=st(),[d,f]=s(``),[p,m]=s(!1),[h,g]=s(null),_=t!==null&&t.length>0,v=t?.length??0;function y(){m(!1),f(``),g(null)}function b(){y(),r()}function x(e){!t||t.length===0||c.mutate({plateIds:[...t],vehicleId:e},{onSettled:()=>{o.invalidateQueries({queryKey:Wo}),b()}})}function S(){!t||!d.trim()||l.mutate({name:d.trim()},{onSuccess:e=>{e?.id&&x(e.id)},onError:()=>{o.invalidateQueries({queryKey:Wo}),b()}})}let C=c.isPending||l.isPending;return a(Je,{open:_,onOpenChange:e=>!e&&b(),children:e(dt,{children:[e(Be,{children:[a(Dt,{children:v>1?i(`detectionIntelligence.assignPlateDialog.assignPlatesToVehicle`,`Assign {{value1}} plates to vehicle`,{value1:String(v)}):i(`detectionIntelligence.assignPlateDialog.assignPlateToVehicle`,`Assign plate to vehicle`)}),a($e,{children:i(`detectionIntelligence.assignPlateDialog.selectAnExistingVehicleOr`,`Select an existing vehicle or create a new one.`)})]}),a(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:n.map(t=>e(`button`,{type:`button`,onClick:()=>g(t.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${h===t.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[a(`span`,{className:`font-medium`,children:t.name}),a(`span`,{className:`ml-2 text-foreground-subtle`,children:i(`detectionIntelligence.assignPlateDialog.plates`,{count:t.sampleCount})})]},t.id))}),p?a(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:a(ct,{placeholder:i(`detectionIntelligence.assignPlateDialog.newVehicleName`,`New vehicle name…`),value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&S()},autoFocus:!0,className:`flex-1`})}):a(`button`,{type:`button`,onClick:()=>{g(null),m(!0)},className:`mt-2 w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle hover:border-primary hover:text-primary transition-colors`,children:i(`detectionIntelligence.assignPlateDialog.newVehicle`,`+ New vehicle…`)}),e(Qe,{children:[a(Y,{variant:`secondary`,onClick:b,disabled:C,children:i(`common.cancel`,`Cancel`)}),p?e(Y,{variant:`primary`,onClick:S,disabled:C||!d.trim(),children:[C&&a(G,{className:`h-3.5 w-3.5 animate-spin`}),i(`detectionIntelligence.assignPlateDialog.createAssign`,`Create & assign`)]}):e(Y,{variant:`primary`,onClick:()=>h&&x(h),disabled:C||!h,children:[C&&a(G,{className:`h-3.5 w-3.5 animate-spin`}),v>1?i(`detectionIntelligence.assignCount`,{count:v}):i(`common.assign`)]})]})]})})}l();var Ko=[[`plateGallery`]];function qo(e){let[t,n]=s(null),[r,i]=s(null),[a,c]=s(!1);return o(()=>{if(n(null),i(null),c(!1),e===void 0)return;let t=!1,r=null;return(async()=>{try{let i=await Ut(Wt(e));if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||c(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),o(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>c(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function Jo(e){let t=e.filter(e=>e.url.length>0);return t.length===0?null:t.find(e=>/crop|plate/i.test(e.kind))??t[0]}function Yo({label:t,value:n,mono:r}){return e(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[a(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:t}),a(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${r?`font-mono`:``}`,title:n,children:n})]})}function Xo({box:e}){let{t}=Z();return a(`div`,{className:`pointer-events-none absolute rounded-[3px] border-2 border-primary shadow-[0_0_0_9999px_rgba(0,0,0,0.28)]`,style:{left:`${String(e.x*100)}%`,top:`${String(e.y*100)}%`,width:`${String(e.width*100)}%`,height:`${String(e.height*100)}%`},children:a(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:t(`detectionIntelligence.plateDetailPanel.plate`,`Plate`)})})}function Zo({plate:t,cameraName:r,onClose:i,onAssign:c,onUnassign:l,onDelete:d,actionsPending:f}){let{t:m}=Z(),h=u(),{data:g,isFetching:_}=Ae({plateId:t?.plateId??``},{enabled:t!==null}),y=Me(),[x,S]=s(`frame`),[w,T]=s(!1),[E,D]=s(``),{frameSrc:O,naturalWidth:k,naturalHeight:A,failed:j}=qo(t?.keyFrameMediaId);o(()=>{T(!1),D(``),S(`frame`)},[t?.plateId]);let M=n(()=>{let e=Jo(g??[]);return e?e.url:Uo(t)},[g,t]),N=n(()=>!t?.plateBbox||k===null||A===null?null:dr(t.plateBbox,k,A),[t?.plateBbox,k,A]);if(t===null)return null;let P=t.keyFrameMediaId!==void 0&&!j,I=P&&x===`frame`,R=t.assigned?t.vehicleName??`Assigned`:t.recognizedVehicleId?`${t.vehicleName??`Recognized`} (suggested)`:`Unassigned`,z=`${String(Math.round(t.score*100))}%${t.corrected?` · corrected`:``}`;function B(){t&&(D(t.text),T(!0))}function V(){if(!t)return;let e=E.trim().toUpperCase();if(!e||e===t.text){T(!1);return}y.mutate({plateId:t.plateId,text:e},{onSettled:()=>{h.invalidateQueries({queryKey:Ko}),T(!1)}})}return a(Je,{open:!0,onOpenChange:e=>!e&&i(),children:e(dt,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":m(`detectionIntelligence.plateDetailPanel.plateDetail`,`Plate 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:[a(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:e(`div`,{className:`min-w-0`,children:[a(`div`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:t.text||m(`detectionIntelligence.plateDetailPanel.plateDetail`,`Plate detail`)}),a(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:r})]})}),e(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[P&&e(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[e(`button`,{type:`button`,onClick:()=>S(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${x===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(L,{className:`h-3.5 w-3.5`}),` `,m(`detectionIntelligence.detailPanel.fullFrame`)]}),e(`button`,{type:`button`,onClick:()=>S(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${x===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(he,{className:`h-3.5 w-3.5`}),` `,m(`detectionIntelligence.detailPanel.crop`)]})]}),I&&O?a(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:a(pr,{src:O,alt:m(`detectionIntelligence.plateDetailPanel.fullFrameWithDetectedPlate`,`Full frame with detected plate`),fit:`natural`,className:`w-full`,overlay:N?a(Xo,{box:N}):void 0})}):M?e(`div`,{className:`relative aspect-[2/1] w-full overflow-hidden rounded-lg border border-border bg-background`,children:[a(pr,{src:M,alt:m(`detectionIntelligence.plateDetailPanel.detectedPlate`,`Detected plate`),className:`h-full w-full`}),_&&a(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:a(G,{className:`h-3.5 w-3.5 animate-spin`})})]}):e(`div`,{className:`flex aspect-[2/1] w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[a(K,{className:`h-8 w-8 text-warning/70`}),a(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:m(`detectionIntelligence.plateDetailPanel.noImage`,`No image`)}),a(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:m(`detectionIntelligence.plateDetailPanel.theCropMediaForThis`,`The crop media for this plate could not be resolved. Safe to delete.`)})]}),a(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-2`,children:e(`div`,{className:`flex items-center justify-between gap-3`,children:[a(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:m(`detectionIntelligence.plateDetailPanel.plateText`,`Plate text`)}),w?e(`div`,{className:`flex min-w-0 flex-1 items-center justify-end gap-1.5`,children:[a(ct,{value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`&&V(),e.key===`Escape`&&T(!1)},className:`h-7 max-w-[10rem] text-right font-mono text-xs uppercase`,autoFocus:!0}),a(`button`,{type:`button`,onClick:V,disabled:y.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":m(`detectionIntelligence.plateDetailPanel.saveCorrectedText`,`Save corrected text`),children:y.isPending?a(G,{className:`h-3.5 w-3.5 animate-spin`}):a(p,{className:`h-3.5 w-3.5`})}),a(`button`,{type:`button`,onClick:()=>T(!1),className:`text-foreground-subtle hover:text-foreground`,"aria-label":m(`common.cancel`,`Cancel`),children:a(F,{className:`h-3.5 w-3.5`})})]}):e(`button`,{type:`button`,onClick:B,className:`group flex min-w-0 items-center gap-1.5`,title:m(`detectionIntelligence.plateDetailPanel.correctTheOcrReading`,`Correct the OCR reading`),children:[a(`span`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:t.text||`—`}),a(v,{className:`h-3 w-3 shrink-0 text-foreground-subtle group-hover:text-foreground`})]})]})}),e(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[a(Yo,{label:m(`detectionIntelligence.plateDetailPanel.camera`,`Camera`),value:r}),a(Yo,{label:m(`detectionIntelligence.plateDetailPanel.captured`,`Captured`),value:Xn(t.timestamp)}),a(Yo,{label:m(`detectionIntelligence.plateDetailPanel.confidence`,`Confidence`),value:z}),a(Yo,{label:m(`detectionIntelligence.plateDetailPanel.vehicle`,`Vehicle`),value:R}),a(Yo,{label:m(`detectionIntelligence.plateDetailPanel.track`,`Track`),value:t.trackId,mono:!0})]})]}),e(`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:[t.assigned?e(Y,{variant:`secondary`,onClick:()=>l(t.plateId),disabled:f,children:[a(pe,{className:`h-3.5 w-3.5`}),` `,m(`detectionIntelligence.detailPanel.detach`)]}):e(Y,{variant:`primary`,onClick:()=>c(t.plateId),disabled:f,children:[a(C,{className:`h-3.5 w-3.5`}),` `,m(`common.assign`)]}),e(Y,{variant:`secondary`,onClick:()=>d(t.plateId),disabled:f,children:[a(b,{className:`h-3.5 w-3.5`}),` `,m(`common.delete`)]})]})]})})}l();var Qo=[[`plateGallery`]],$o=500,es=120;function ts({plate:t,cameraName:n,nowMs:r,selected:i,onToggleSelect:o,onAssign:s,onOpenDetail:c}){let{t:l}=Z(),d=u(),f=Fe(),p=be(),m=()=>{d.invalidateQueries({queryKey:Qo})},h=()=>c(t.plateId),g=Uo(t);return e(`div`,{className:`relative flex flex-col overflow-hidden rounded-md border bg-surface ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[e(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[g===null?e(`button`,{type:`button`,onClick:h,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:l(`detectionIntelligence.recentPlates.noCropImageThePlate`,`No crop image — the plate's crop media is missing. Safe to delete.`),children:[a(K,{className:`h-7 w-7 text-warning/70`}),a(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:l(`detectionIntelligence.recentPlates.noCrop`,`No crop`)})]}):a(`img`,{src:g,alt:l(`detectionIntelligence.recentPlates.plateFrom`,`Plate {{text}} from {{cameraName}}`,{text:t.text,cameraName:n}),onClick:h,className:`h-full w-full cursor-zoom-in object-cover`}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(t.plateId)},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":i?l(`detectionIntelligence.recentPlates.deselect`,`Deselect`):l(`detectionIntelligence.recentPlates.select`,`Select`),children:i?a(de,{className:`h-4 w-4 text-primary`}):a(k,{className:`h-4 w-4`})}),t.corrected&&e(`span`,{className:`absolute right-0 top-0 z-10 flex items-center gap-0.5 rounded-bl-md bg-primary/80 px-1 py-0.5 text-[8px] font-semibold uppercase tracking-wide text-white`,title:l(`detectionIntelligence.recentPlates.manuallyCorrected`,`Manually corrected`),children:[a(fe,{className:`h-3 w-3`}),` `,l(`detectionIntelligence.recentPlates.fixed`)]})]}),e(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[a(`p`,{className:`truncate font-mono text-xs font-bold tracking-wide text-foreground`,title:t.text,children:t.text||`—`}),a(`p`,{className:`truncate text-[10px] text-foreground-subtle`,title:n,children:n}),a(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:Jn(t.timestamp,r)}),t.vehicleName&&a(`p`,{className:`truncate text-[10px] font-medium text-primary`,title:t.vehicleName,children:t.vehicleName})]}),e(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[t.assigned?a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),f.mutate({plateId:t.plateId},{onSettled:m})},disabled:f.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":l(`detectionIntelligence.recentPlates.detachPlate`,`Detach plate`),title:l(`detectionIntelligence.recentPlates.detach`,`Detach`),children:f.isPending?a(G,{className:`h-4 w-4 animate-spin`}):a(pe,{className:`h-4 w-4`})}):a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s(t.plateId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":l(`detectionIntelligence.recentPlates.assignPlateToVehicle`,`Assign plate to vehicle`),title:l(`detectionIntelligence.recentPlates.assignToVehicle`,`Assign to vehicle`),children:a(C,{className:`h-4 w-4`})}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),p.mutate({plateId:t.plateId},{onSettled:m})},disabled:p.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":l(`detectionIntelligence.recentPlates.deletePlate`,`Delete plate`),title:l(`detectionIntelligence.recentPlates.deletePlate`,`Delete plate`),children:p.isPending?a(G,{className:`h-4 w-4 animate-spin`}):a(b,{className:`h-4 w-4`})})]})]})}var ns=[{labelKey:`common.all`,value:`all`},{labelKey:`detectionIntelligence.recentPlates.filterUnassigned`,value:`unassigned`},{labelKey:`detectionIntelligence.recentPlates.filterAssigned`,value:`assigned`}];function rs(e,t){return t===`unassigned`?e.filter(e=>!e.assigned):t===`assigned`?e.filter(e=>e.assigned):e}function is(){let{t}=Z(),r=u(),[i,o]=s(`all`),[c,l]=s(Rn),[f,p]=s(new Set),[m,h]=s(new Set),[g,_]=s(null),[v,y]=s(null),{data:x,isLoading:S}=je({limit:$o,includeCrops:!1},{refetchInterval:3e4}),{data:w=[]}=De(),{data:T}=Ie({isCamera:!0,projection:`slim`}),E=Fe(),D=Nt(),O=be(),k=Date.now(),A=x??[],j=n(()=>{let e=new Map;for(let t of T??[])e.set(t.id,t.name);return e},[T]),M=e=>j.get(e)??t(`detectionIntelligence.cameraFallback`,{id:String(e)}),N=n(()=>Gn(A).map(e=>({id:e,name:M(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[A,j]),P=n(()=>Wn(Un(rs(A,i),c),f),[A,i,c,f]),I=tr(P,es,n(()=>JSON.stringify([i,c.fromMs,c.toMs,[...f].sort((e,t)=>e-t)]),[i,c.fromMs,c.toMs,f])),L=n(()=>new Map(A.map(e=>[e.plateId,e])),[A]),R=v===null?null:L.get(v)??null,z=()=>{r.invalidateQueries({queryKey:Qo})},B=()=>h(new Set);function V(e){h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}let H=[...m],U=D.isPending||O.isPending,W=E.isPending||O.isPending;function ee(){H.length!==0&&D.mutate({plateIds:H},{onSettled:()=>{z(),B()}})}function te(){H.length!==0&&Promise.allSettled(H.map(e=>O.mutateAsync({plateId:e}))).then(()=>{z(),B()})}function q(e){y(null),_([e])}function ne(e){E.mutate({plateId:e},{onSettled:z}),y(null)}function re(e){O.mutate({plateId:e},{onSettled:z}),y(null)}let J=P.length!==A.length;return e(`div`,{className:`relative space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[a(`div`,{className:`flex items-center gap-1`,children:ns.map(e=>a(`button`,{type:`button`,onClick:()=>o(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${i===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:t(e.labelKey)},e.value))}),a(lr,{onChange:l}),a(sr,{cameras:N,selected:f,onChange:p}),!S&&a(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:J?t(`detectionIntelligence.recentPlates.ofPlates`,`{{value1}} of {{value2}} plates`,{value1:String(P.length),value2:String(A.length)}):t(`detectionIntelligence.recentPlates.plateCount`,{count:P.length})})]}),m.size>0&&e(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[a(`span`,{className:`text-xs font-medium text-foreground`,children:t(`common.selectedCount`,{count:m.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[e(Y,{variant:`primary`,onClick:()=>_(H),disabled:U,children:[a(C,{className:`h-3.5 w-3.5`}),` `,t(`common.assign`)]}),e(Y,{variant:`secondary`,onClick:ee,disabled:U,children:[D.isPending?a(G,{className:`h-3.5 w-3.5 animate-spin`}):a(pe,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.recentPlates.detach`,`Detach`)]}),e(Y,{variant:`secondary`,onClick:te,disabled:U,children:[a(b,{className:`h-3.5 w-3.5`}),` `,t(`common.delete`)]}),a(Y,{variant:`ghost`,onClick:B,disabled:U,children:a(F,{className:`h-3.5 w-3.5`})})]})]}),S?a(Xe,{status:`pending`,pendingMessage:`Loading plates…`,testId:`plates-grid`}):P.length===0?a(Te,{icon:K,title:A.length>0?t(`detectionIntelligence.recentPlates.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.recentPlates.noPlatesRecognizedYet`,`No plates recognized yet`),description:A.length>0?t(`detectionIntelligence.recentPlates.widenTheDateRangeOr`,`Widen the date range or clear the camera filter.`):t(`detectionIntelligence.recentPlates.plateReadsAppearHereWhen`,`Plate reads appear here when the detection pipeline OCRs a vehicle.`)}):e(d,{children:[a(Xe,{status:`ready`,testId:`plates-grid`,children:I.pageItems.map(e=>a(ts,{plate:e,cameraName:M(e.deviceId),nowMs:k,selected:m.has(e.plateId),onToggleSelect:V,onAssign:e=>_([e]),onOpenDetail:y},e.plateId))}),a(ir,{currentPage:I.page,totalItems:I.totalItems,pageSize:I.pageSize,onPageChange:I.setPage,itemNoun:`plates`})]}),a(Zo,{plate:R,cameraName:R?M(R.deviceId):``,onClose:()=>y(null),onAssign:q,onUnassign:ne,onDelete:re,actionsPending:W}),a(Go,{plateIds:g,vehicles:w,onDone:()=>{_(null),B()}})]})}l();var as=[[`plateGallery`]];function os({vehicleId:t}){let{t:n}=Z(),r=u(),{data:i,isLoading:o}=Ne({vehicleId:t}),s=Oe();function c(e){s.mutate({vehicleId:t,sampleId:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:as})}})}return o?e(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[a(G,{className:`h-3.5 w-3.5 animate-spin`}),n(`detectionIntelligence.vehiclesList.loadingPlates`,`Loading plates…`)]}):!i||i.length===0?a(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:n(`detectionIntelligence.vehiclesList.noPlatesYet`,`No plates yet.`)}):a(`div`,{className:`mt-2 grid grid-cols-3 gap-2 sm:grid-cols-4 md:grid-cols-6`,children:i.map(t=>e(`div`,{className:`group relative overflow-hidden rounded-md border border-border bg-surface`,children:[e(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[t.base64?a(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:t.text,className:`h-full w-full object-cover`}):a(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:a(h,{className:`h-6 w-6`})}),a(`button`,{type:`button`,onClick:()=>c(t),disabled:s.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":n(`detectionIntelligence.vehiclesList.removePlateSample`,`Remove plate sample`),children:a(F,{className:`h-4 w-4 text-white`})})]}),a(`p`,{className:`truncate px-1.5 py-1 text-center font-mono text-[11px] font-semibold tracking-wide text-foreground`,title:t.text,children:t.text})]},t.id))})}function ss(t){return[{key:`vehicle`,header:X.t(`detectionIntelligence.vehiclesList.vehicle`,`Vehicle`),sortValue:e=>e.name,render:t=>e(`span`,{className:`flex min-w-0 items-center gap-2`,children:[a(`span`,{className:`h-8 w-12 shrink-0 overflow-hidden rounded border border-border bg-surface-hover`,children:a(qt,{mediaId:t.coverMediaId,base64:t.coverBase64,alt:t.name,className:`h-full w-full object-cover`,placeholder:a(`span`,{className:`flex h-full w-full items-center justify-center`,children:a(h,{className:`h-4 w-4 text-foreground-subtle`})})})}),a(`span`,{className:`truncate text-sm font-medium text-foreground`,children:t.name})]})},{key:`samples`,header:X.t(`detectionIntelligence.vehiclesList.plates`,`Plates`),align:`center`,nowrap:!0,sortValue:e=>e.sampleCount,render:e=>a(xt,{variant:`default`,className:`text-[10px]`,children:e.sampleCount})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:n=>e(`span`,{className:`flex items-center justify-end gap-1`,children:[a(Tt,{variant:`ghost`,size:`sm`,icon:v,"aria-label":X.t(`detectionIntelligence.vehiclesList.edit`,`Edit {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onEdit(n)}}),a(Tt,{variant:`ghost`,size:`sm`,icon:b,"aria-label":X.t(`detectionIntelligence.vehiclesList.delete`,`Delete {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onDelete(n)}})]})}]}function cs({mode:t,vehicle:n,onClose:r}){let{t:i}=Z(),c=u(),[l,d]=s(t===`edit`?n?.name??``:``),f=st(),p=ke();o(()=>{d(t===`edit`?n?.name??``:``)},[t,n?.id,n?.name]);let m=f.isPending||p.isPending,g=l.trim(),_=t===`edit`&&n!==null&&g===n.name,v=m||g.length===0||_;function y(){c.invalidateQueries({queryKey:as})}function b(){if(!v){if(t===`new`){f.mutate({name:g},{onSuccess:()=>{y(),r()}});return}if(n===null){r();return}p.mutate({id:n.id,name:g},{onSuccess:()=>{y(),r()}})}}return a(et,{open:!0,onClose:r,title:t===`new`?`Add vehicle`:`Edit ${n?.name??`vehicle`}`,icon:h,width:t===`edit`?`xl`:`lg`,testId:`vehicles-vehicle-form`,footer:e(Y,{variant:`primary`,size:`sm`,type:`button`,onClick:b,disabled:v,children:[m?a(G,{className:`h-3.5 w-3.5 animate-spin`}):null,t===`new`?i(`common.add`,`Add`):i(`common.save`,`Save`)]}),children:e(`div`,{className:`space-y-4`,children:[a(Le,{label:i(`detectionIntelligence.vehiclesList.name`,`Name`),required:!0,children:a(ct,{value:l,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b()},placeholder:i(`detectionIntelligence.vehiclesList.vehicleName`,`Vehicle name…`),autoFocus:!0})}),t===`edit`&&n!==null&&e(`div`,{children:[a(`p`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:i(`detectionIntelligence.vehiclesList.plateSamples`,`Plate samples`)}),a(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:i(`detectionIntelligence.vehiclesList.removeAPlateCropTo`,`Remove a plate crop to drop it from recognition for this vehicle. Assign new plates from Recent recognized plates.`)}),a(os,{vehicleId:n.id})]})]})})}function ls(){let{t}=Z(),r=u(),i=Pe(),{data:s,isLoading:c}=De(),l=it(),{state:d,openNew:p,openEdit:m,close:g}=yt(),_=s??[],v=_t(_,{searchText:e=>[e.name]}),y=d.mode===`edit`?_.find(e=>e.id===d.id)??null:null;o(()=>{d.mode===`edit`&&!c&&y===null&&g()},[d.mode,c,y,g]);let b=n(()=>ss({onEdit:e=>m(e.id),onDelete:e=>{(async()=>{await i({title:t(`detectionIntelligence.vehiclesList.deleteVehicle`,`Delete vehicle`),message:t(`detectionIntelligence.vehiclesList.deleteAndAllItsPlate`,`Delete {{name}} and all its plate samples? This cannot be undone.`,{name:e.name}),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&l.mutate({id:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:as}),d.mode===`edit`&&d.id===e.id&&g()}})})()}}),[i,g,l,d,m,r,t]);if(c)return e(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[a(G,{className:`h-4 w-4 animate-spin`}),t(`detectionIntelligence.vehiclesList.loadingVehicles`,`Loading vehicles…`)]});let x=d.mode===`new`||d.mode===`edit`&&y!==null;return e(`div`,{className:`space-y-2`,children:[a(`div`,{className:`flex flex-wrap items-center gap-2`,children:e(Y,{variant:`primary`,size:`sm`,type:`button`,onClick:p,children:[a(f,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.vehiclesList.addVehicle`,`Add vehicle`)]})}),(_.length>0||v.active)&&a(ut,{state:v.state,facets:v.facets,labels:{searchPlaceholder:`Search vehicles…`,searchLabel:`Search vehicles`,facetsLabel:`Filter`,clearLabel:`Clear`},onSearch:v.setSearch,onToggleFacet:v.toggleFacet,onClear:v.clear}),v.rows.length===0?a(Te,{icon:h,title:v.active?t(`detectionIntelligence.vehiclesList.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.vehiclesList.noVehiclesEnrolledYet`,`No vehicles enrolled yet`),description:v.active?t(`detectionIntelligence.vehiclesList.clearTheSearchOrTry`,`Clear the search or try another name.`):t(`detectionIntelligence.vehiclesList.addAVehicleThenAssign`,`Add a vehicle, then assign plate crops from Recent recognized plates.`)}):a(Se,{columns:b,rows:v.rows,rowKey:e=>e.id,maxBodyHeight:kt,emptyMessage:t(`detectionIntelligence.vehiclesList.noVehiclesEnrolledYet2`,`No vehicles enrolled yet.`),onRowClick:e=>m(e.id)}),x&&a(cs,{mode:d.mode===`new`?`new`:`edit`,vehicle:y,onClose:g})]})}l();var us=[[`plateGallery`]],ds=2e3;function fs(){let e=u(),n=t(e);n.current=e;let r=t(void 0);r.current||=Br({delayMs:ds,invalidate:()=>{n.current.invalidateQueries({queryKey:us})}}),o(()=>()=>r.current?.cancel(),[]),ot(ie.PipelineAnalyticsPlateGalleryChanged,()=>{r.current?.trigger()})}function ps(){let{t}=Z();return fs(),e(`div`,{className:`space-y-3`,children:[a(jt,{headingId:`library-vehicles`,title:t(`plates.vehicles`,`Vehicles`),icon:h,testId:`library-section-vehicles`,children:e(`div`,{className:`${m} space-y-3`,children:[a(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`plates.enrolledVehicleIdentitiesUsedFor`,`Enrolled vehicle identities used for plate recognition. Open a vehicle to rename it or remove plate samples.`)}),a(ls,{})]})}),a(jt,{headingId:`library-recent-plates`,title:t(`plates.recentRecognizedPlates`,`Recent recognized plates`),icon:ce,testId:`library-section-recent-plates`,children:e(`div`,{className:`${m} space-y-3`,children:[a(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`plates.licensePlatesReadByThe`,`License plates read by the detection pipeline. Assign them to a vehicle, correct the OCR text, or delete.`)}),a(is,{})]})})]})}function ms(e){return e.states.length===0?3:e.latched?0:e.verdict===`diverged`?1:e.verdict===`unknown`?2:4}function hs(e){let t=[e.divergedAt,e.restoredAt].filter(e=>typeof e==`number`);return t.length===0?null:Math.max(...t)}function gs(e,t){let n=new Map(e.map(e=>[e.deviceId,e.deviceName])),r=[];for(let e of t)for(let t of e.monitors)r.push({deviceId:e.deviceId,deviceName:n.get(e.deviceId)??`Camera ${e.deviceId}`,monitor:t});return r.toSorted((e,t)=>{let n=ms(e.monitor)-ms(t.monitor);if(n!==0)return n;let r=hs(e.monitor)??-1,i=hs(t.monitor)??-1;if(r!==i)return i-r;let a=e.deviceName.localeCompare(t.deviceName);return a===0?e.monitor.label.localeCompare(t.monitor.label):a})}l();var _s={alarm:`danger`,ok:`success`,unknown:`default`},vs={alarm:`Alarm`,ok:`OK`,unknown:`Unknown`};function ys(e,t){let n=hs(e);return n===null?`—`:X.t(`scenes.transitionAgo`,{duration:ee(Math.max(0,t-n))})}function bs(e){return P(e.monitor).tone}function xs(e){let t=Number(e);return Number.isFinite(t)&&t>0?t:null}function Ss(){let{t}=Z(),i=Ie({isCamera:!0,projection:`slim`}),c=n(()=>(i.data??[]).map(e=>({deviceId:e.id,deviceName:e.name})).sort((e,t)=>e.deviceName.localeCompare(t.deviceName)),[i.data]),l=n(()=>c.map(e=>e.deviceId),[c]),u=Kt(l),d=n(()=>gs(c,u.results),[c,u.results]),p=_t(d,{searchText:e=>[e.monitor.label,e.deviceName],facetValue:bs}),{state:m,openNew:h,openEdit:g,close:_}=yt(),[v,y]=s(null);o(()=>{if(m.mode===`new`){y(e=>e??l[0]??null);return}y(null)},[m.mode,l]);let b=m.mode===`edit`?xs(m.id):null,S=b===null?``:c.find(e=>e.deviceId===b)?.deviceName??`#${b}`,C=Date.now(),w=[{key:`label`,header:t(`scenes.scene`,`Scene`),sortValue:e=>e.monitor.label,render:e=>a(`span`,{className:`font-medium`,children:e.monitor.label})},{key:`camera`,header:t(`scenes.camera`,`Camera`),nowrap:!0,sortValue:e=>e.deviceName,render:e=>e.deviceName},{key:`state`,header:t(`scenes.state`,`State`),nowrap:!0,sortValue:e=>bs(e),render:e=>{let t=P(e.monitor);return a(xt,{variant:_s[t.tone],children:t.text})}},{key:`status`,header:t(`scenes.whatItSays`,`What it says`),notSortableReason:`Status is a live sentence, not a comparable value`,render:e=>a(`span`,{className:`text-xs text-foreground-muted`,children:I(e.monitor,C)})},{key:`coverage`,header:t(`scenes.variants`,`Variants`),notSortableReason:`Coverage is a summary string`,render:e=>a(`span`,{className:`text-xs text-foreground-muted`,children:B(e.monitor)})},{key:`transition`,header:t(`scenes.lastChange`,`Last change`),align:`right`,nowrap:!0,sortValue:e=>hs(e.monitor)??0,render:e=>a(`span`,{className:`text-xs tabular-nums text-foreground-muted`,children:ys(e.monitor,C)})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:e=>a(Y,{variant:`ghost`,onClick:()=>g(String(e.deviceId)),children:t(`scenes.open`,`Open`)})}];return e(`section`,{className:`space-y-3`,children:[e(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between sm:gap-4`,children:[a(`p`,{className:`text-xs text-foreground-subtle`,children:t(`scenes.aSceneWatchesOneRegion`,`A scene watches one region of one camera and tells you when it stops looking like the picture you captured — a wheelie bin, a gate, a parking space.`)}),e(Y,{onClick:h,disabled:c.length===0,className:`shrink-0`,children:[a(f,{className:`mr-1 h-3.5 w-3.5`}),t(`scenes.newScene`,`New scene`)]})]}),u.unreachableCount>0?a(`p`,{className:`text-xs text-warning`,children:t(`scenes.unreachable`,{count:u.unreachableCount})}):null,(d.length>0||p.active)&&a(ut,{state:p.state,facets:p.facets,labels:{searchPlaceholder:`Search scenes…`,searchLabel:`Search scenes`,facetsLabel:`State`,clearLabel:`Clear`},facetLabel:e=>vs[e]??e,onSearch:p.setSearch,onToggleFacet:p.toggleFacet,onClear:p.clear}),a(Mt,{variant:`flat`,className:`p-0`,children:a(Se,{columns:w,rows:p.rows,rowKey:e=>`${e.deviceId}:${e.monitor.id}`,minWidthPx:880,bordered:!1,maxBodyHeight:kt,emptyMessage:u.isLoading?t(`scenes.loadingScenes`,`Loading scenes…`):p.active?t(`scenes.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`scenes.noScenesYetPressNew`,`No scenes yet. Press “New scene”, pick a camera, then draw a box around the thing you want watched.`)})}),m.mode===`new`?e(et,{open:!0,onClose:_,title:t(`scenes.whichCamera`,`Which camera?`),icon:x,width:`sm`,testId:`scenes-camera-picker`,footer:a(Y,{onClick:()=>{v!==null&&g(String(v))},disabled:v===null,children:t(`scenes.continue`,`Continue`)}),children:[a(`p`,{className:`mb-3 text-xs text-foreground-subtle`,children:t(`scenes.aSceneLivesOnOne`,`A scene lives on one camera. Pick the one that can see the thing.`)}),a(tt,{value:v===null?``:String(v),onChange:e=>y(Number(e.target.value)),"aria-label":t(`scenes.camera`,`Camera`),options:c.map(e=>({value:String(e.deviceId),label:e.deviceName}))})]}):null,b===null?null:e(et,{open:!0,onClose:_,title:t(`scenes.scenes`,`Scenes — {{editingName}}`,{editingName:S}),icon:x,width:`lg`,testId:`scenes-editor`,children:[a(`p`,{className:`mb-3 text-xs text-foreground-subtle`,children:t(`scenes.drawABoxNameIt`,`Draw a box, name it, then capture what “normal” looks like. Daylight is enough — the night reference is optional, and “Settings” on each scene tunes how fussy and how often it checks.`)}),a(r,{fallback:a(`p`,{className:`text-xs text-foreground-muted`,children:t(`scenes.loadingTheEditor`,`Loading the editor…`)}),children:a(Ct,{deviceId:b})})]})]})}function Cs(){let{t:e}=Z(),t=Pt(`/library`,{t:e,isAdmin:!0})??{icon:me,title:e(`nav.library`,`Library`)};return a(zt,{icon:t.icon,title:t.title,subtitle:e(`library.peopleVehiclesCapturedEventsAnd`,`People, vehicles, captured events and scenes — what detection has recognised.`),defaultSection:`people`,sectionsLabel:`${t.title} sections`,sections:[{id:`people`,label:e(`library.people`,`People`),content:a(Wr,{})},{id:`vehicles`,label:e(`library.vehicles`,`Vehicles`),content:a(ps,{})},{id:`events`,label:e(`library.events`,`Events`),content:a(Ho,{}),ownedParams:[`section`]},{id:`scenes`,label:e(`library.scenes`,`Scenes`),content:a(Ss,{})}]})}export{Cs as LibraryPage};