@camstack/addon-admin-ui 1.2.509 → 1.2.510
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/assets/{AddonAssetIcon-BI2lRuoS.js → AddonAssetIcon-C9hAoKXu.js} +1 -1
- package/dist/assets/{Addons-aixytO1O.js → Addons-RWj1BxGY.js} +1 -1
- package/dist/assets/{AdminPage-CoK_jJGS.js → AdminPage-DlYf-2bp.js} +1 -1
- package/dist/assets/{AdminSectionedPage-DhFW0QuY.js → AdminSectionedPage-BZCKp3Ch.js} +1 -1
- package/dist/assets/{AiProfiles-Hta21yBZ.js → AiProfiles-JSlQDV72.js} +1 -1
- package/dist/assets/{BrokerEditorDialog-gOoxFZhc.js → BrokerEditorDialog-Bd04efEw.js} +1 -1
- package/dist/assets/{Build-DeHUkf81.js → Build-BZi_niS-.js} +1 -1
- package/dist/assets/{Calendars-Bc2nNcs2.js → Calendars-DP9Bg77f.js} +1 -1
- package/dist/assets/{Cluster-VtNbtY9D.js → Cluster-Dd_vu_bM.js} +1 -1
- package/dist/assets/{CompositionBlockEditor-ClF4WE8b.js → CompositionBlockEditor-CH-GMXbq.js} +1 -1
- package/dist/assets/{CompositionEditorPage-BbTxuNsy.js → CompositionEditorPage-Csnltw_A.js} +1 -1
- package/dist/assets/{Data-jsug18s-.js → Data-uCQZVzY1.js} +1 -1
- package/dist/assets/{DeviceDetail-joS1oAlZ.js → DeviceDetail-BxIy7-Dm.js} +1 -1
- package/dist/assets/{DeviceDoActionFields-HDaDny9u.js → DeviceDoActionFields-CK01sDyF.js} +1 -1
- package/dist/assets/{Devices-auu9DUkM.js → Devices-CVsltbg0.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-CIhSpElZ.js → EmbedPlayerPage-C5TPel_z.js} +1 -1
- package/dist/assets/{HelperWizard-BgJngxXm.js → HelperWizard-BPhC2XoW.js} +1 -1
- package/dist/assets/{History-6YEHunH9.js → History-B20ge-W7.js} +1 -1
- package/dist/assets/{Identity-Dv-KAkrQ.js → Identity-DPilvdr-.js} +1 -1
- package/dist/assets/{IntegrationDetail-9gEegPuj.js → IntegrationDetail-QFz0_FYR.js} +1 -1
- package/dist/assets/{IntegrationHub-CMzk8_M7.js → IntegrationHub-B1kSbU1F.js} +1 -1
- package/dist/assets/{Integrations-BmMpmuUr.js → Integrations-DL3TkBVs.js} +1 -1
- package/dist/assets/{Integrations-4H8b5m-o.js → Integrations-DZSqPZJX.js} +1 -1
- package/dist/assets/{Library-DCJLo-8C.js → Library-lJCalEoT.js} +1 -1
- package/dist/assets/{Locations-DcE-odlA.js → Locations-B0jWaHF6.js} +1 -1
- package/dist/assets/{Logs-CPkwmk1L.js → Logs-DQLPAUyF.js} +1 -1
- package/dist/assets/{MaskShapeCanvas-Bc_okYTu.js → MaskShapeCanvas-CFljj6Sk.js} +1 -1
- package/dist/assets/{MotionZonesSettings-C-3oW42G.js → MotionZonesSettings-B8TBt4dC.js} +1 -1
- package/dist/assets/{MyAccess-aKBp7TFc.js → MyAccess-CZG0q7Mt.js} +1 -1
- package/dist/assets/{Network-BZRPnSCn.js → Network-BBrgIFOt.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-D2vtVm6t.js → NodeAddonsSettingsPanel-CeHG4O24.js} +1 -1
- package/dist/assets/{Notifications-DRe4l7tP.js → Notifications-3RTWnoyO.js} +1 -1
- package/dist/assets/{Pipeline-CciPr0pg.js → Pipeline-CGdO9F0O.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-BOI5MbOP.js → PrivacyMaskSettings-BJlCR0a3.js} +1 -1
- package/dist/assets/{Recordings-BzsdLv6y.js → Recordings-CURYqqF0.js} +1 -1
- package/dist/assets/{ScanNetworkModal-DvfjnJfb.js → ScanNetworkModal-ojXdkkOk.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-BP10OuX_.js → SceneMonitorEditor-CNgXiExG.js} +1 -1
- package/dist/assets/{SessionsList-CPeF55_J.js → SessionsList-Bd4yBLfB.js} +1 -1
- package/dist/assets/{Showroom-otBl581k.js → Showroom-Df0D9oOc.js} +1 -1
- package/dist/assets/{System-CSJNNYl2.js → System-DQkvS75J.js} +1 -1
- package/dist/assets/{Terminal-CjxtMAdp.js → Terminal-BhUVowlr.js} +1 -1
- package/dist/assets/{Viewer-CDe6m77J.js → Viewer-B4P4Bkxo.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DmDesblz.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Cze0rRAV.js} +1 -1
- package/dist/assets/{addon-icons-context-C1MOrZ0k.js → addon-icons-context-fZFRR8Jh.js} +1 -1
- package/dist/assets/{archive-DfRpKbmd.js → archive-B0Gb92Md.js} +1 -1
- package/dist/assets/{assignment-candidates-CZXvnTmb.js → assignment-candidates-CLAnrBak.js} +1 -1
- package/dist/assets/{authed-media-acRzkBVq.js → authed-media-BZXVXyjI.js} +1 -1
- package/dist/assets/{bell-off-BDtTHYf7.js → bell-off-BFI_PtFI.js} +1 -1
- package/dist/assets/{board-model-DmsaBGD6.js → board-model-Cb9TF016.js} +1 -1
- package/dist/assets/{boxes-Dg0SsuKi.js → boxes-C9rq6GsW.js} +1 -1
- package/dist/assets/circle-slash-CrgSHCu9.js +1 -0
- package/dist/assets/client-CwJGlpR9.js +674 -0
- package/dist/assets/{cloud-upload-D5gzNxtI.js → cloud-upload-kAMSz6c0.js} +1 -1
- package/dist/assets/crop-DKZuvuZ0.js +1 -0
- package/dist/assets/{device-integration-icon-DYxz_sNP.js → device-integration-icon-a0pkysxV.js} +1 -1
- package/dist/assets/device-picker-model-BTGIE40h.js +1 -0
- package/dist/assets/{dist-DU6BvfF_.js → dist-CG2a7mCH.js} +1 -1
- package/dist/assets/dist-D4krkzk0.js +674 -0
- package/dist/assets/{eraser-DatAKBqr.js → eraser-De_DOv3l.js} +1 -1
- package/dist/assets/{format-BXqfrshG.js → format-7HUlrbym.js} +1 -1
- package/dist/assets/{hard-drive-download-BMn4pcLF.js → hard-drive-download-DKm5p-Le.js} +1 -1
- package/dist/assets/{hostInit-SgUIaQcR.js → hostInit-Ct3ew837.js} +1 -1
- package/dist/assets/i18n-9jE1YKjd.js +1 -0
- package/dist/assets/{icons-CfQXaR2o.js → icons-3VtN4bSW.js} +1 -1
- package/dist/assets/{index-B6a27fav.js → index-DG07MiZm.js} +3 -3
- package/dist/assets/{key-0qodB2RW.js → key-VHIrojXx.js} +1 -1
- package/dist/assets/{key-round-EDiKxWDb.js → key-round-Bfq08tmQ.js} +1 -1
- package/dist/assets/{layers-BuqS0QUs.js → layers-C2a0eh6-.js} +1 -1
- package/dist/assets/{linked-devices-model-fUmE1zN_.js → linked-devices-model-D3jOXb7G.js} +1 -1
- package/dist/assets/{list-ordered-5xX0c-4M.js → list-ordered-Da2mHuCu.js} +1 -1
- package/dist/assets/{location-owned-usage-C90h2IYf.js → location-owned-usage-DqvEUneY.js} +1 -1
- package/dist/assets/{log-in-DfGAqbts.js → log-in-eLGFJBOn.js} +1 -1
- package/dist/assets/{memory-stick-Cw-HmXQN.js → memory-stick-DnKI7rwN.js} +1 -1
- package/dist/assets/{message-square-plus-Cimd4hIM.js → message-square-plus-C6KwcZuQ.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-6f836b4a.js → mf-entry-bootstrap-0-98f2c3e4.js} +2 -2
- package/dist/assets/{mic-off-BaeJlMpU.js → mic-off-D983qPJH.js} +1 -1
- package/dist/assets/{monitor-off-B5ZegpCN.js → monitor-off-BxsFOOUC.js} +1 -1
- package/dist/assets/{monitor-smartphone-GrRvroYr.js → monitor-smartphone-CVLLvvgV.js} +1 -1
- package/dist/assets/mount-BTGIE40h.js +1 -0
- package/dist/assets/{player-overlays-CzZYPO2s.js → player-overlays-g9d3qYrr.js} +1 -1
- package/dist/assets/{recycle-C0Za7XIk.js → recycle-DO_1Mgmd.js} +1 -1
- package/dist/assets/remoteEntry-CpKU5IE2.js +1 -0
- package/dist/assets/{scan-eye-DBcVKkv9.js → scan-eye-CyJ3ozW9.js} +1 -1
- package/dist/assets/{scissors-ClBtIo8F.js → scissors-BNMtq6Ob.js} +1 -1
- package/dist/assets/{search-x-vzCWLMzU.js → search-x-DDY8MfL6.js} +1 -1
- package/dist/assets/{send-C2xLiGxd.js → send-Ch2Il08w.js} +1 -1
- package/dist/assets/{settings-2-CE18osa2.js → settings-2-DuqbBWmE.js} +1 -1
- package/dist/assets/{sigma-BzZ_sr1s.js → sigma-C3PEOK_Y.js} +1 -1
- package/dist/assets/{speaker-DPhQgEkP.js → speaker-DkdRIL1K.js} +1 -1
- package/dist/assets/{src-DytYtgEw.js → src-DwNoxp86.js} +3 -3
- package/dist/assets/{step-inspector-model-BpPknRH5.js → step-inspector-model-DQUr_7uJ.js} +1 -1
- package/dist/assets/{table-2-Ca1maW_p.js → table-2-DoxvwhSo.js} +1 -1
- package/dist/assets/{timer-reset-DLwEAlTU.js → timer-reset-DVNN3Abc.js} +1 -1
- package/dist/assets/{unlink-Bdb8-xwF.js → unlink-C-2ouMww.js} +1 -1
- package/dist/assets/{usb-DxqbvFPc.js → usb-PSQjoR7w.js} +1 -1
- package/dist/assets/{use-scenes-feed-YVkY4_qr.js → use-scenes-feed-B_j7CFbm.js} +1 -1
- package/dist/assets/{use-stationary-objects-FD4-OqJN.js → use-stationary-objects-Drf9XXJR.js} +1 -1
- package/dist/assets/useEventInvalidation-BTGIE40h.js +1 -0
- package/dist/assets/{useNodeUrlSelection-Kb4BvUIw.js → useNodeUrlSelection-Cg0TPdbH.js} +1 -1
- package/dist/assets/user-round-Z0QH_kjR.js +1 -0
- package/dist/assets/{user-x-BQ6msuOU.js → user-x-BRStn-V-.js} +1 -1
- package/dist/assets/{variable-mkIJuabT.js → variable-vFOxYqY7.js} +1 -1
- package/dist/assets/{video-O02NyJP7.js → video-BFmrpvc7.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CVBjsL5d.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-JzLE6zuc.js} +2 -2
- package/dist/index.html +9 -9
- package/dist/server/addon.js +13 -1
- package/package.json +1 -1
- package/dist/assets/circle-slash-vr6zT4n3.js +0 -1
- package/dist/assets/client-BRyxs6lT.js +0 -674
- package/dist/assets/crop-CGtgnf44.js +0 -1
- package/dist/assets/device-picker-model-D0GfTZgv.js +0 -1
- package/dist/assets/dist-CPWJTJFO.js +0 -674
- package/dist/assets/i18n-CNMsurg3.js +0 -1
- package/dist/assets/mount-D0GfTZgv.js +0 -1
- package/dist/assets/remoteEntry-BNJLevTL.js +0 -1
- package/dist/assets/useEventInvalidation-D0GfTZgv.js +0 -1
- package/dist/assets/user-round-D5DJkFym.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{Cr as f,D as p,Di as m,Ei as h,En as g,Fn as _,Ht as v,Ii as y,It as b,Mi as x,Ni as S,Nr as C,Nt as w,Oi as T,Q as E,Ti as D,Vn as O,Vr as k,Xr as A,Xt as j,Z as M,bn as N,c as P,ct as F,di as I,dt as ee,en as L,f as R,fr as z,gt as B,l as V,ot as H,ri as U,rn as W,sa as te,st as ne,tn as G,u as re,ur as ie,vn as K,wn as q,z as ae,zt as oe}from"./player-overlays-CzZYPO2s.js";import{Br as se,nt as ce,so as le}from"./client-BRyxs6lT.js";import{a as ue,c as de,i as fe,n as pe,o as me,r as he,s as ge,t as _e}from"./user-x-BQ6msuOU.js";import{c as ve}from"./video-O02NyJP7.js";import{t as ye}from"./crop-CGtgnf44.js";import{t as be}from"./user-round-D5DJkFym.js";import{Ac as xe,Bl as Se,Cn as Ce,Do as we,Er as Te,Fi as Ee,Fl as De,Gl as Oe,Hl as ke,Ic as Ae,Il as je,Kl as Me,Lc as Ne,Ll as Pe,Mc as Fe,Oc as Ie,Pc as Le,Pl as Re,Qn as ze,Rl as Be,Sn as Ve,Td as He,Tr as Ue,Ul as We,Vl as Ge,Wl as Ke,Yr as J,_d as qe,_r as Je,_s as Ye,bn as Xe,br as Ze,cs as Qe,dd as $e,dr as et,ds as tt,dt as nt,fc as rt,fn as it,fs as at,ft as ot,gd as st,gr as ct,gs as lt,hn as ut,hr as dt,hs as ft,jc as pt,ls as mt,mr as ht,ms as gt,mt as _t,ni as vt,od as yt,pn as bt,pr as xt,ps as St,ri as Ct,sd as wt,ss as Tt,t as Et,ti as Dt,tn as Ot,un as kt,us as At,vs as jt,xt as Mt,ys as Nt,zd as Pt,zl as Ft}from"./src-DytYtgEw.js";import{t as Y}from"./i18n-CNMsurg3.js";import{t as X}from"./useTranslation-BJr-n0es.js";import"./mount-D0GfTZgv.js";import{T as It,_r as Lt,hr as Rt,pr as zt,yr as Bt}from"./index-B6a27fav.js";import{t as Vt}from"./AdminSectionedPage-DhFW0QuY.js";import{t as Ht}from"./use-stationary-objects-FD4-OqJN.js";import{a as Ut,i as Wt,n as Gt,r as Kt,t as qt}from"./authed-media-acRzkBVq.js";import{t as Jt}from"./use-scenes-feed-YVkY4_qr.js";l();function Yt({mediaId:e,base64:t,alt:n,className:r,placeholder:i}){let{src:o,failed:s}=Ut(e===void 0?void 0:Kt(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 Xt=`pipeline-analytics`,Zt=`photo.analyze`,Qt=`photo.enroll`,$t=`photo.discard`,en=18*1024*1024;function tn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function nn(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function rn(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function an(e,t){let n=e[t];return typeof n==`boolean`?n:null}function on(e){if(!tn(e))return null;let t=rn(e,`x`),n=rn(e,`y`),r=rn(e,`width`),i=rn(e,`height`);return t===null||n===null||r===null||i===null?null:{x:t,y:n,width:r,height:i}}function sn(e){if(!tn(e))return null;let t=rn(e,`detectionShortSidePx`),n=rn(e,`score`);if(t===null||n===null)return null;let r=rn(e,`magnitude`);return{detectionShortSidePx:t,score:n,...r===null?{}:{magnitude:r}}}function cn(e){if(!tn(e))return null;let t=rn(e,`faceIndex`),n=rn(e,`score`),r=an(e,`enrollable`),i=on(e.bbox),a=sn(e.quality);if(t===null||n===null||r===null||i===null||a===null)return null;let o=nn(e,`refusedReason`),s=nn(e,`alignedCropBase64`),c=nn(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 ln(e){if(!tn(e))return null;let t=nn(e,`sessionId`),n=nn(e,`ranOnNodeId`),r=e.faces;if(t===null||n===null||!Array.isArray(r))return null;let i=[];for(let e of r){let t=cn(e);t!==null&&i.push(t)}return{sessionId:t,ranOnNodeId:n,faces:i}}function un(e){if(!tn(e))return null;let t=nn(e,`sampleId`),n=nn(e,`identityId`),r=nn(e,`modelId`);return t===null||n===null||r===null?null:{sampleId:t,identityId:n,modelId:r}}function dn(e,t,n){let r={...e};return n===null||n===``?delete r[t]:r[t]=n,r}function fn(e,t){return e.filter(e=>e.enrollable&&t[e.faceIndex]!==void 0).length}function pn(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 mn(e){switch(e){case`no-embedding`:return Y.t(`helpers.photoEnroll.refusal.noEmbedding`);case`no-model-id`:return Y.t(`helpers.photoEnroll.refusal.noModelId`);case`no-aligned-crop`:return Y.t(`helpers.photoEnroll.refusal.noAlignedCrop`);case`magnitude`:return Y.t(`helpers.photoEnroll.refusal.magnitude`);default:return Y.t(`helpers.photoEnroll.refusal.default`)}}function hn(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 gn(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 _n(e,t,n){return e.map(e=>e.photoIndex===t?{...e,...n}:e)}function vn(e,t){return`${e}:${t}`}function yn(e,t,n,r){let i=dn(e[t]??{},n,r),a={...e};return Object.keys(i).length===0?delete a[t]:a[t]=i,a}function bn(e,t){let n=0;for(let r of e)r.analysis!==void 0&&(n+=fn(r.analysis.faces,t[r.photoIndex]??{}));return n}var xn=`__new__`;function Sn(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[vn(i.photoIndex,t.faceIndex)]??``).trim();if(a===``)return{kind:`error`,message:Y.t(`helpers.photoEnrollBatch.newPersonNoName`,{filename:i.filename,face:t.faceIndex+1})};r.includes(a)||r.push(a)}}return{kind:`ok`,names:r}}function Cn(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[vn(e,a)]??``).trim()];s!==void 0&&(o[a]=s)}r[e]=o}return r}function wn(e,t){let n=[];for(let r of e){if(r.analysis===void 0)continue;let e=pn(r.analysis.sessionId,r.analysis.faces,t[r.photoIndex]??{});for(let t of e)n.push({photoIndex:r.photoIndex,request:t})}return n}function Tn(e){return/expired/i.test(e)}function En(e){return e instanceof Error?e.message:String(e)}async function Dn(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??Y.t(`helpers.photoEnrollBatch.photoFallback`,{n:e+1});return Y.t(`helpers.photoEnrollBatch.faceLabel`,{filename:n,face:t+1})};for(let l of wn(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=En(t);if(!Tn(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 (${En(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)}: ${En(e)}`)}}}return{enrolled:o,stampedModelId:s,failures:a,refreshedAnalyses:i}}var On=[[`faceGallery`]],kn=``;function An(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 jn(e){return e instanceof Error?e.message:String(e)}function Mn({face:t,identities:r,value:i,onChange:o,disabled:s}){let{t:c}=X(),l=n(()=>[{value:kn,label:c(`detectionIntelligence.photoEnrollDialog.ignoreThisFace`,`Ignore this face`)},...r.map(e=>({value:e.id,label:e.name})),{value:xn,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(be,{className:`h-8 w-8`})})}),a(`div`,{className:`min-h-[4.75rem]`,children:t.enrollable?e(d,{children:[a($e,{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(Ct,{variant:`warning`,className:`text-[10px]`,children:c(`detectionIntelligence.photoEnrollDialog.notUsable`,`Not usable`)}),a(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:mn(t.refusedReason)})]})})]})}function Nn({photo:t,identities:n,draft:r,newNames:i,disabled:o,onAssign:s,onNameChange:c,onRetry:l}){let{t:u}=X(),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(z,{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(J,{variant:`secondary`,size:`sm`,disabled:o,onClick:l,children:[a(q,{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(oe,{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(Mn,{face:e,identities:n,value:f[e.faceIndex]??kn,disabled:o,onChange:t=>s(e.faceIndex,t)},e.faceIndex))}),d.filter(e=>f[e.faceIndex]===xn).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[vn(t.photoIndex,n.faceIndex)]??``,onChange:e=>c(n.faceIndex,e.target.value)})]},n.faceIndex))]})}function Pn({open:r,onOpenChange:o}){let{t:c}=X(),l=ee(),d=u(),f=t(null),{data:p}=at(),m=Qe(),[h,g]=s([]),[_,v]=s(!1),[y,b]=s(null),[x,S]=s({}),[C,w]=s({}),[T,E]=s(null),D=n(()=>(p??[]).map(e=>({id:e.id,name:e.name})),[p]),O=h.some(e=>e.status===`queued`||e.status===`analyzing`),k=O||_,A=i(e=>{for(let t of e){let e=t.analysis?.sessionId;e!==void 0&&l.trpcClient.addons.custom.mutate({addonId:Xt,action:$t,input:{sessionId:e}}).catch(()=>void 0)}},[l]),j=i(()=>{g([]),S({}),w({}),b(null),E(null),f.current&&(f.current.value=``)},[]),M=i(()=>{A(h),j(),o(!1)},[A,o,h,j]),N=i(async e=>{let t=ln(await l.trpcClient.addons.custom.mutate({addonId:Xt,action:Zt,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]),P=i(async e=>{g(t=>_n(t,e.photoIndex,{status:`analyzing`,error:void 0}));try{let t=await N(e);g(n=>_n(n,e.photoIndex,{status:`analyzed`,analysis:t}))}catch(t){g(n=>_n(n,e.photoIndex,{status:`failed`,error:jn(t)}))}},[N]),F=i(async e=>{if(e.length===0)return;A(h),j();let t=hn(e,{maxCount:12,maxBytes:en}),n=[];t.oversize.length>0&&n.push(`Over the ${Math.round(en/(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 An(e),status:`queued`})))}catch(e){b(jn(e));return}g(r),await gn(r,2,e=>P(e))},[A,h,j,P]),I=bn(h,x),L=i(async()=>{v(!0),b(null),E(null);try{let e=Sn(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 Dn(h,Cn(x,C,t),{enroll:async e=>{let t=un(await l.trpcClient.addons.custom.mutate({addonId:Xt,action:Qt,input:e}));if(t===null)throw Error(`unreadable reply`);return t},reanalyze:e=>N(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:On}),n.failures.length>0&&b(n.failures.join(` · `)),E(n.enrolled===0?`Nothing was enrolled.`:`Enrolled ${n.enrolled} sample${n.enrolled===1?``:`s`}${n.stampedModelId===null?``:` with ${n.stampedModelId}`}.`)}catch(e){b(jn(e))}finally{v(!1)}},[N,m,x,C,h,d,l]),R=h.filter(e=>e.status===`analyzed`).length;return a(et,{open:r,onOpenChange:e=>e?o(!0):M(),children:e(xt,{className:`max-w-3xl`,children:[e(ct,{children:[a(Je,{children:c(`detectionIntelligence.photoEnrollDialog.enrolFromPhotos`,`Enrol from photos`)}),a(ht,{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(zt,{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 F(Array.from(e.target.files??[]))}),e(J,{variant:`secondary`,size:`sm`,disabled:k,onClick:()=>f.current?.click(),children:[O?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(me,{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:R,count:h.length})})]}),a(`div`,{className:`min-h-11`,"aria-live":`polite`,children:y===null?T===null?null:a(`div`,{className:`rounded-md border border-success/40 bg-success/10 px-3 py-2 text-xs text-success`,children:T}):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(oe,{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(Nn,{photo:e,identities:D,draft:x,newNames:C,disabled:k,onAssign:(t,n)=>S(r=>yn(r,e.photoIndex,t,n===kn?null:n)),onNameChange:(t,n)=>w(r=>({...r,[vn(e.photoIndex,t)]:n})),onRetry:()=>void P(e)},e.photoIndex))}),e(dt,{children:[a(J,{variant:`secondary`,onClick:M,disabled:_,children:c(`common.close`,`Close`)}),e(J,{variant:`primary`,onClick:()=>void L(),disabled:k||I===0,children:[_?a(z,{className:`h-3.5 w-3.5 animate-spin`}):null,c(`detectionIntelligence.photoEnrollDialog.enrolFaces`,{count:I})]})]})]})})}l();var Fn=[[`faceGallery`]];function In({identityId:t}){let{t:n}=X(),r=u(),{data:i,isLoading:o}=St({identityId:t}),s=ft();function c(e){s.mutate({identityId:t,sampleId:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:Fn})}})}return o?e(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[a(z,{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(be,{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(me,{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(B,{className:`h-4 w-4 text-white`})})]},t.id))})}function Ln(t){return[{key:`person`,header:Y.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(Yt,{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(be,{className:`h-4 w-4 text-foreground-subtle`})})})}),a(`span`,{className:`truncate text-sm font-medium text-foreground`,children:t.name})]})},{key:`samples`,header:Y.t(`detectionIntelligence.peopleList.samples`,`Samples`),align:`center`,nowrap:!0,sortValue:e=>e.sampleCount,render:e=>a(Ct,{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(qe,{variant:`ghost`,size:`sm`,icon:O,"aria-label":Y.t(`detectionIntelligence.peopleList.edit`,`Edit {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onEdit(n)}}),a(qe,{variant:`ghost`,size:`sm`,icon:v,"aria-label":Y.t(`detectionIntelligence.peopleList.delete`,`Delete {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onDelete(n)}})]})}]}function Rn({mode:t,identity:n,onClose:r}){let{t:i}=X(),c=u(),[l,d]=s(t===`edit`?n?.name??``:``),f=Qe(),p=lt();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:Fn})}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(_t,{open:!0,onClose:r,title:t===`new`?`Add person`:`Edit ${n?.name??`person`}`,icon:be,width:t===`edit`?`xl`:`lg`,testId:`people-person-form`,footer:e(J,{variant:`primary`,size:`sm`,type:`button`,onClick:y,disabled:_,children:[m?a(z,{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(Mt,{label:i(`detectionIntelligence.peopleList.name`,`Name`),required:!0,children:a(st,{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(In,{identityId:n.id})]})]})})}function zn(){let{t}=X(),r=u(),i=ne(),{data:c,isLoading:l}=at(),d=At(),{state:f,openNew:p,openEdit:m,close:h}=ot(),[g,v]=s(!1),y=c??[],b=it(y,{searchText:e=>[e.name]}),x=f.mode===`edit`?y.find(e=>e.id===f.id)??null:null;o(()=>{f.mode===`edit`&&!l&&x===null&&h()},[f.mode,l,x,h]);let S=n(()=>Ln({onEdit:e=>m(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:Fn}),f.mode===`edit`&&f.id===e.id&&h()}})})()}}),[i,h,d,f,m,r,t]);if(l)return e(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[a(z,{className:`h-4 w-4 animate-spin`}),t(`detectionIntelligence.peopleList.loadingPeople`,`Loading people…`)]});let C=f.mode===`new`||f.mode===`edit`&&x!==null;return e(`div`,{className:`space-y-2`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(J,{variant:`primary`,size:`sm`,type:`button`,onClick:p,children:[a(_,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.peopleList.addPerson`,`Add person`)]}),e(J,{variant:`secondary`,size:`sm`,type:`button`,onClick:()=>v(!0),children:[a(me,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.peopleList.enrolFromAPhoto`,`Enrol from a photo`)]})]}),(y.length>0||b.active)&&a(bt,{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:be,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(Ve,{columns:S,rows:b.rows,rowKey:e=>e.id,maxBodyHeight:Ce,emptyMessage:t(`detectionIntelligence.peopleList.noPeopleEnrolledYet2`,`No people enrolled yet.`),onRowClick:e=>m(e.id)}),C&&a(Rn,{mode:f.mode===`new`?`new`:`edit`,identity:x,onClose:h}),a(Pn,{open:g,onOpenChange:v})]})}var Bn={fromMs:null,toMs:null},Vn=36e5,Hn=24*Vn;function Un(e,t){switch(e){case`24h`:return{fromMs:t-Hn,toMs:null};case`7d`:return{fromMs:t-7*Hn,toMs:null};case`30d`:return{fromMs:t-30*Hn,toMs:null};case`all`:return Bn}}function Wn(e){return e.fromMs!==null||e.toMs!==null}function Gn(e,t){return Wn(t)?e.filter(e=>!(t.fromMs!==null&&e.timestamp<t.fromMs||t.toMs!==null&&e.timestamp>t.toMs)):[...e]}function Kn(e,t){return t.size===0?[...e]:e.filter(e=>t.has(e.deviceId))}function qn(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 Jn(e){if(!e)return null;let t=Date.parse(`${e}T00:00:00`);return Number.isNaN(t)?null:t}function Yn(e){if(!e)return null;let t=Date.parse(`${e}T23:59:59.999`);return Number.isNaN(t)?null:t}function Xn(e,t){if(!Number.isFinite(e)||e<=0)return`—`;let n=t-e;return n<6e4?Y.t(`helpers.relativeTime.justNow`):n<Vn?Y.t(`helpers.relativeTime.minutesAgo`,{count:Math.floor(n/6e4)}):n<Hn?Y.t(`helpers.relativeTime.hoursAgo`,{count:Math.floor(n/Vn)}):n<7*Hn?Y.t(`helpers.relativeTime.daysAgo`,{count:Math.floor(n/Hn)}):new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function Zn(e){return!Number.isFinite(e)||e<=0?`—`:new Date(e).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function Qn(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 $n(e){let t=e.cropUrl!==void 0&&e.cropUrl.length>0,n=e.base64!==void 0&&e.base64.length>0;return!t&&!n}function er(e){return e.filter($n).map(e=>e.faceId)}function tr(e){let t=0;for(let n of e)$n(n)&&(t+=1);return t}function nr(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 rr(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 ir=2;function ar(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-ir),i=Math.min(t-1,e+ir);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 or({currentPage:t,totalItems:n,pageSize:r,onPageChange:i,itemNoun:o=`items`}){let{t:s}=X();if(n<=r)return null;let c=Math.ceil(n/r),l=(t-1)*r+1,u=Math.min(t*r,n),d=ar(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(h,{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(D,{className:`h-3.5 w-3.5`})})]})]})}l();var sr=[[`faceGallery`]];function cr({faceIds:t,identities:n,onDone:r}){let{t:i}=X(),o=u(),c=Tt(),l=Qe(),[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:sr}),b()}})}function S(){!t||!d.trim()||l.mutate({name:d.trim()},{onSuccess:e=>{e?.id&&x(e.id)},onError:()=>{o.invalidateQueries({queryKey:sr}),b()}})}let C=c.isPending||l.isPending;return a(et,{open:_,onOpenChange:e=>!e&&b(),children:e(xt,{children:[e(ct,{children:[a(Je,{children:v>1?i(`detectionIntelligence.assignDialog.assignFacesToPerson`,`Assign {{value1}} faces to person`,{value1:String(v)}):i(`detectionIntelligence.assignDialog.assignFaceToPerson`,`Assign face to person`)}),a(ht,{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(st,{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(dt,{className:`min-h-[2.75rem]`,children:[a(J,{variant:`secondary`,onClick:b,disabled:C,children:i(`common.cancel`,`Cancel`)}),p?e(J,{variant:`primary`,onClick:S,disabled:C||!d.trim(),children:[C&&a(z,{className:`h-3.5 w-3.5 animate-spin`}),i(`detectionIntelligence.assignDialog.createAssign`,`Create & assign`)]}):e(J,{variant:`primary`,onClick:()=>h&&x(h),disabled:C||!h,children:[C&&a(z,{className:`h-3.5 w-3.5 animate-spin`}),v>1?i(`detectionIntelligence.assignCount`,{count:v}):i(`common.assign`)]})]})]})})}l();function lr({cameras:n,selected:r,onChange:i}){let{t:c}=X(),[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 p=r.size,h=p===0?`All cameras`:p===1?n.find(e=>r.has(e.id))?.name??`1 camera`:`${String(p)} 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 ${p>0?`border-primary/40 bg-primary/8 text-primary`:`border-border text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(S,{className:`h-3.5 w-3.5`}),a(`span`,{className:`max-w-[10rem] truncate`,children:h}),a(m,{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:[p>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(T,{className:`h-2.5 w-2.5`})}),a(`span`,{className:`truncate`,children:t.name})]},t.id)})]})]})}l();var ur=[{label:`24h`,value:`24h`},{label:`7d`,value:`7d`},{label:`30d`,value:`30d`},{labelKey:`common.all`,value:`all`}];function dr({onChange:t}){let{t:n}=X(),[r,i]=s(`all`),[o,c]=s(``),[l,u]=s(``);function d(e){i(e),c(``),u(``),t(Un(e,Date.now()))}function f(e,n){i(`custom`),c(e),u(n),t({fromMs:Jn(e),toMs:Yn(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:ur.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 fr(e){return e<0?0:e>1?1:e}function pr(e,t,n){if(!Number.isFinite(t)||!Number.isFinite(n)||t<=0||n<=0)return null;let r=fr(e.x/t),i=fr(e.y/n),a=fr((e.x+e.w)/t),o=fr((e.y+e.h)/n);return{x:r,y:i,width:Math.max(0,a-r),height:Math.max(0,o-i)}}l();var mr=2.6;function hr({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(mr)})`:`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 gr(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 Gt(Kt(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 _r(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 vr({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 yr({box:e}){let{t}=X();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 br({face:t,cameraName:r,onClose:i,onAssign:o,onUnassign:c,onDelete:l,actionsPending:u}){let{t:d}=X(),{data:p,isFetching:m}=tt({faceId:t?.faceId??``},{enabled:t!==null}),[h,g]=s(`frame`),{frameSrc:_,naturalWidth:y,naturalHeight:b,failed:x}=gr(t?.keyFrameMediaId),S=n(()=>{let e=_r(p??[]);return e?e.url:nr(t)},[p,t]),C=n(()=>!t?.faceBbox||y===null||b===null?null:pr(t.faceBbox,y,b),[t?.faceBbox,y,b]);if(t===null)return null;let T=t.keyFrameMediaId!==void 0&&!x,E=T&&h===`frame`,D=t.assigned?t.identityName??`Assigned`:t.recognizedIdentityId?`${t.identityName??`Recognized`} (suggested)`:`Unassigned`;return a(et,{open:!0,onOpenChange:e=>!e&&i(),children:e(xt,{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:[T&&e(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[e(`button`,{type:`button`,onClick:()=>g(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${h===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(N,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.fullFrame`)]}),e(`button`,{type:`button`,onClick:()=>g(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${h===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(ye,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.crop`)]})]}),E&&_?a(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:a(hr,{src:_,alt:d(`detectionIntelligence.faceDetailPanel.fullFrameWithDetectedFace`,`Full frame with detected face`),fit:`natural`,className:`w-full`,overlay:C?a(yr,{box:C}):void 0})}):S?e(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[a(hr,{src:S,alt:d(`detectionIntelligence.faceDetailPanel.detectedFace`,`Detected face`),className:`h-full w-full`}),m&&a(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:a(z,{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(f,{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(vr,{label:d(`detectionIntelligence.faceDetailPanel.camera`,`Camera`),value:r}),a(vr,{label:d(`detectionIntelligence.faceDetailPanel.captured`,`Captured`),value:Qn(t.timestamp)}),a(vr,{label:d(`detectionIntelligence.faceDetailPanel.track`,`Track`),value:t.trackId}),a(vr,{label:d(`detectionIntelligence.faceDetailPanel.identity`,`Identity`),value:D})]})]}),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(J,{variant:`secondary`,onClick:()=>c(t.faceId),disabled:u,children:[a(_e,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.detach`)]}):e(J,{variant:`primary`,onClick:()=>o(t.faceId),disabled:u,children:[a(w,{className:`h-3.5 w-3.5`}),` `,d(`common.assign`)]}),e(J,{variant:`secondary`,onClick:()=>l(t.faceId),disabled:u,children:[a(v,{className:`h-3.5 w-3.5`}),` `,d(`common.delete`)]})]})]})})}function xr(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function Sr(e,t){return e.faceIds.filter(e=>!t.has(e))}function Cr(e,t){return e.faceIds.filter(e=>t(e))}l();var wr=[[`faceGallery`]],Tr=20,Er=.3,Dr=.9,Or=.05,kr=.5,Ar=2,jr=10,Mr=2;function Nr({cluster:t,face:n,active:r,onSelect:i}){let{t:o}=X(),s=nr(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(f,{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 Pr({face:t,cameraName:n,nowMs:r,excluded:i,onToggleExclude:o,onDelete:s,deletePending:c}){let{t:l}=X(),u=nr(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(f,{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(hr,{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?b:B,{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:Xn(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(z,{className:`h-4 w-4 animate-spin`}):a(v,{className:`h-4 w-4`})})})]})}function Fr({open:t,onClose:r,byId:i,cameraName:c,nowMs:l,identities:f,selectMany:p}){let{t:m}=X(),h=u(),_=ne(),v=mt(),[y,b]=s(kr),[x,S]=s(Mr),[C,T]=s(null),[E,D]=s({}),[O,k]=s(null),{data:A,isFetching:j,refetch:M}=Ye({threshold:y,minClusterSize:x,limit:Tr},{enabled:t}),N=A??[];o(()=>{D({})},[y,x]),o(()=>{if(N.length===0){T(null);return}N.some(e=>e.representativeFaceId===C)||T(N[0]?.representativeFaceId??null)},[N]);let P=n(()=>N.find(e=>e.representativeFaceId===C)??null,[N,C]),F=P?E[P.representativeFaceId]??new Set:new Set,I=n(()=>P?Cr(P,e=>i.has(e)):[],[P,i]),ee=P?P.faceIds.length-I.length:0,L=P?Sr({...P,faceIds:I},F):[];function R(e){if(!P)return;let t=P.representativeFaceId;D(n=>({...n,[t]:xr(n[t]??new Set,e)}))}function B(){h.invalidateQueries({queryKey:wr})}async function V(e){await _({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`})&&v.mutate({faceId:e},{onSettled:B})}function H(){k(null),r()}function U(){L.length!==0&&(p(L),H())}return e(et,{open:t,onOpenChange:e=>!e&&H(),children:[e(xt,{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(W,{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:Er,max:Dr,step:Or,value:y,onChange:e=>b(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:y.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:Ar,max:jr,step:1,value:x,onChange:e=>S(Math.min(jr,Math.max(Ar,Number(e.target.value)||Ar))),className:`w-12 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`})]}),e(J,{variant:`secondary`,onClick:()=>{D({}),M()},disabled:j,children:[j?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(g,{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(z,{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(Nr,{cluster:e,face:i.get(e.representativeFaceId),active:e.representativeFaceId===C,onSelect:()=>T(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(Nr,{cluster:e,face:i.get(e.representativeFaceId),active:e.representativeFaceId===C,onSelect:()=>T(e.representativeFaceId)},e.representativeFaceId))}),a(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:P&&e(d,{children:[ee>0&&a(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:m(`detectionIntelligence.similarGroupsModal.hiddenCount`,{count:ee})}),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(Pr,{face:t,cameraName:c(t.deviceId),nowMs:l,excluded:F.has(e),onToggleExclude:()=>R(e),onDelete:()=>void V(e),deletePending:v.isPending&&v.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(J,{variant:`secondary`,onClick:U,disabled:L.length===0,children:m(`detectionIntelligence.similarGroupsModal.selectInGallery`,`Select in gallery`)}),e(J,{variant:`primary`,onClick:()=>k(L),disabled:L.length===0,children:[a(w,{className:`h-3.5 w-3.5`}),` `,m(`detectionIntelligence.similarGroupsModal.adopt`,{count:L.length})]})]})]}),a(cr,{faceIds:O,identities:f,onDone:()=>k(null)})]})}l();var Ir=[[`faceGallery`]],Lr=500,Rr=120;function zr({face:t,cameraName:n,nowMs:r,selected:i,onToggleSelect:o,onAssign:s,onOpenDetail:c}){let{t:l}=X(),d=u(),p=jt(),m=mt(),h=()=>{d.invalidateQueries({queryKey:Ir})},g=()=>c(t.faceId),_=nr(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:[_===null?e(`button`,{type:`button`,onClick:g,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(f,{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:_,alt:l(`detectionIntelligence.unassignedFaces.faceFrom`,`Face from {{cameraName}}`,{cameraName:n}),onClick:g,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(he,{className:`h-4 w-4 text-primary`}):a(G,{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:Xn(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(),p.mutate({faceId:t.faceId},{onSettled:h})},disabled:p.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:p.isPending?a(z,{className:`h-4 w-4 animate-spin`}):a(_e,{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(w,{className:`h-4 w-4`})}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),m.mutate({faceId:t.faceId},{onSettled:h})},disabled:m.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:m.isPending?a(z,{className:`h-4 w-4 animate-spin`}):a(v,{className:`h-4 w-4`})})]})]})}var Br=[{labelKey:`common.all`,value:`all`},{labelKey:`detectionIntelligence.unassignedFaces.filterUnassigned`,value:`unassigned`},{labelKey:`detectionIntelligence.unassignedFaces.filterRecognized`,value:`recognized`}];function Vr(){let{t}=X(),r=u(),[i,o]=s(`all`),[c,l]=s(Bn),[p,m]=s(new Set),[h,g]=s(new Set),[_,y]=s(null),[b,x]=s(!1),[S,C]=s(null),{data:T,isLoading:E}=gt({limit:Lr,filter:i,includeCrops:!1},{refetchInterval:3e4}),{data:D=[]}=at(),{data:O}=we({isCamera:!0,projection:`slim`}),k=Tt(),A=jt(),j=Nt(),M=mt(),N=Date.now(),P=T??[],F=n(()=>{let e=new Map;for(let t of O??[])e.set(t.id,t.name);return e},[O]),I=e=>F.get(e)??t(`detectionIntelligence.cameraFallback`,{id:String(e)}),ee=n(()=>qn(P).map(e=>({id:e,name:I(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[P,F]),L=n(()=>Kn(Gn(P,c),p),[P,c,p]),R=rr(L,Rr,n(()=>JSON.stringify([i,c.fromMs,c.toMs,[...p].sort((e,t)=>e-t)]),[i,c.fromMs,c.toMs,p])),V=n(()=>new Map(P.map(e=>[e.faceId,e])),[P]),H=n(()=>tr(L),[L]),U=S===null?null:V.get(S)??null,te=()=>{r.invalidateQueries({queryKey:Ir})},ne=()=>g(new Set);function G(e){g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function re(e){g(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function ie(){re(er(L))}let K=[...h],q=k.isPending||j.isPending||M.isPending,ae=A.isPending||M.isPending;function oe(){K.length!==0&&j.mutate({faceIds:K},{onSettled:()=>{te(),ne()}})}function se(){K.length!==0&&Promise.allSettled(K.map(e=>M.mutateAsync({faceId:e}))).then(()=>{te(),ne()})}function ce(e){C(null),y([e])}function le(e){A.mutate({faceId:e},{onSettled:te}),C(null)}function ue(e){M.mutate({faceId:e},{onSettled:te}),C(null)}let de=L.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:Br.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(dr,{onChange:l}),a(lr,{cameras:ee,selected:p,onChange:m}),e(`button`,{type:`button`,onClick:()=>x(!0),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${b?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(W,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.similarGroups`)]}),!E&&H>0&&e(`button`,{type:`button`,onClick:ie,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(f,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.selectCropless`,{count:H})]}),!E&&a(`span`,{className:`text-[10px] text-foreground-subtle ${H>0?`ml-2`:`ml-auto`}`,children:de?t(`detectionIntelligence.unassignedFaces.ofFaces`,`{{value1}} of {{value2}} faces`,{value1:String(L.length),value2:String(P.length)}):t(`detectionIntelligence.unassignedFaces.faceCount`,{count:L.length})})]}),h.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:h.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[e(J,{variant:`primary`,onClick:()=>y(K),disabled:q,children:[a(w,{className:`h-3.5 w-3.5`}),` `,t(`common.assign`)]}),e(J,{variant:`secondary`,onClick:oe,disabled:q,children:[j.isPending?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(_e,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.detach`,`Detach`)]}),e(J,{variant:`secondary`,onClick:se,disabled:q,children:[a(v,{className:`h-3.5 w-3.5`}),` `,t(`common.delete`)]}),a(J,{variant:`ghost`,onClick:ne,disabled:q,children:a(B,{className:`h-3.5 w-3.5`})})]})]}),E?a(nt,{status:`pending`,pendingMessage:`Loading faces…`,testId:`faces-grid`}):L.length===0?a(Te,{icon:f,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(nt,{status:`ready`,testId:`faces-grid`,className:`grid-cols-[repeat(auto-fill,minmax(6.5rem,6.5rem))] justify-start`,children:R.pageItems.map(e=>a(zr,{face:e,cameraName:I(e.deviceId),nowMs:N,selected:h.has(e.faceId),onToggleSelect:G,onAssign:e=>y([e]),onOpenDetail:C},e.faceId))}),a(or,{currentPage:R.page,totalItems:R.totalItems,pageSize:R.pageSize,onPageChange:R.setPage,itemNoun:`faces`})]}),a(br,{face:U,cameraName:U?I(U.deviceId):``,onClose:()=>C(null),onAssign:ce,onUnassign:le,onDelete:ue,actionsPending:ae}),a(cr,{faceIds:_,identities:D,onDone:()=>{y(null),ne()}}),a(Fr,{open:b,onClose:()=>x(!1),byId:V,cameraName:I,nowMs:N,identities:D,selectMany:re})]})}function Hr(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 Ur=[[`faceGallery`]],Wr=2e3;function Gr(){let e=u(),n=t(e);n.current=e;let r=t(void 0);r.current||=Hr({delayMs:Wr,invalidate:()=>{n.current.invalidateQueries({queryKey:Ur})}}),o(()=>()=>r.current?.cancel(),[]),Pt(le.PipelineAnalyticsFaceGalleryChanged,()=>{r.current?.trigger()})}function Kr(){let{t}=X();return Gr(),e(`div`,{className:`space-y-3`,children:[a(Xe,{headingId:`library-people`,title:t(`detectionIntelligence.people`,`People`),icon:be,testId:`library-section-people`,children:e(`div`,{className:`${p} 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(zn,{})]})}),a(Xe,{headingId:`library-recent-faces`,title:t(`detectionIntelligence.recentDetectedFaces`,`Recent detected faces`),icon:ue,testId:`library-section-recent-faces`,children:e(`div`,{className:`${p} 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(Vr,{})]})})]})}function qr(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 Jr=720*60*60*1e3;function Yr(e){let t=[];for(let n of e)t.push(...n);return t}function Xr(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function Zr(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 Qr(e,t){return`${String(e)}:${t}`}function $r(e,t){let n=new Map,r=new Set;for(let i of e){let e=Qr(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 ei(e,t){return{since:e.fromMs??t-Jr,until:e.toMs??t}}var ti=[`native`,`raster`,`standin`];function ni(e){return ti.some(t=>t===e)}function ri(e){return e===`standin`?{label:Y.t(`helpers.mediaProvenance.standin.label`),title:Y.t(`helpers.mediaProvenance.standin.title`),tone:`warning`}:{label:Y.t(`helpers.mediaProvenance.raster.label`),title:Y.t(`helpers.mediaProvenance.raster.title`),tone:`info`}}function ii(e){return e===`standin`?ri(`standin`):e===`raster`?ri(`raster`):null}var ai={"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 oi(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=ai[r];return{sentence:a===void 0?r:Y.t(a),detail:i,raw:t}}function si(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 ci({row:t,cameraName:n,nowMs:r,onOpenDetail:i,selected:o=!1,onToggleSelect:s,score:c,provenance:l,footer:u}){let{t:d}=X(),p=Ut(t.mediaId===void 0?Wt(`track`,t.trackId):Kt(t.mediaId)),m=Math.round(t.importance*100),h=c===void 0?void 0:Math.round(c*100),g=si(t.windowMs),_=()=>i(t),v=ii(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:[p.src?a(`img`,{src:p.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:p.failed?d(`detectionIntelligence.eventCard.keyEventMediaUnavailable`,`Key-event media unavailable`):d(`detectionIntelligence.eventCard.noKeyEventMedia`,`No key-event media`),children:a(f,{className:`h-6 w-6 opacity-60`})}),s&&a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s(Qr(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(he,{className:`h-4 w-4 text-primary`}):a(G,{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(C,{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(T,{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(y,{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(L,{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,qr(t)?e(`span`,{className:`text-foreground-subtle`,children:[` · `,qr(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:Xn(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 li=1400,ui=`Admin-gated URL — opens only inside an authenticated session`;function di({label:t,value:n,title:r}){let{t:c}=X(),[l,u]=s(!1),d=F();return o(()=>{if(!l)return;let e=setTimeout(()=>u(!1),li);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?T:U,{className:`h-2.5 w-2.5 shrink-0`}),a(`span`,{className:`truncate`,children:l?c(`detectionIntelligence.copyUrlChips.copied`,`Copied`):t})]})}function fi({localUrl:t,publicUrl:n}){let{t:r}=X();return e(`div`,{className:`flex flex-wrap gap-1`,children:[a(di,{label:r(`detectionIntelligence.copyUrlChips.local`,`Local`),value:t,title:r(`detectionIntelligence.copyUrlChips.copyLanUrl`,`Copy LAN URL — {{AUTH_HINT}}`,{AUTH_HINT:ui})}),n&&a(di,{label:r(`detectionIntelligence.copyUrlChips.public`,`Public`),value:n,title:r(`detectionIntelligence.copyUrlChips.copyPublicUrl`,`Copy public URL — {{AUTH_HINT}}`,{AUTH_HINT:ui})})]})}var pi={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 mi(e){return e in pi}function hi(e){return mi(e)?pi[e]:e}function gi(e,t){return`${e}${t}`}l();var _i=3e4;function vi(e){let[t,n]=s(null),r=i(e=>{n(t=>t??e)},[]);return o(()=>{e||n(null)},[e]),{publicOrigin:t,probes:e?a(yi,{onOrigin:r}):null}}function yi({onOrigin:e}){let{data:t}=Ee({capName:`network-access`});return a(d,{children:(t??[]).map(t=>a(bi,{addonId:t.addonId,onOrigin:e},t.addonId))})}function bi({addonId:e,onOrigin:t}){let{data:n}=rt({addonId:e},{refetchInterval:_i,retry:!1});return o(()=>{let e=n?se.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 xi=typeof Ne==`function`,Si=`Track flags arrive with the next server update`;function Ci(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var wi=xi?Ne:Ci;function Ti(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 Ei({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 Di({deviceId:t,trackId:n,markForTrain:r,debug:i,favourited:o,onChange:c}){let{t:l}=X(),u=wi(),d=H(),[f,p]=s(null),m=f?.markForTrain??r===!0,h=f?.debug??i===!0,g=f?.favourited??o===!0,_=!xi||u.isPending,v=xi?void 0:Si,b=e=>{_||(async()=>{try{let r=Ti(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(Ei,{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(C,{className:`h-4 w-4`}),onToggle:()=>b({markForTrain:!m})}),a(Ei,{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(y,{className:`h-4 w-4`}),onToggle:()=>b({debug:!h})}),a(Ei,{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(L,{className:`h-4 w-4`}),onToggle:()=>b({favourited:!g})})]})}function Oi(e){let t=e.deviceKey===void 0?e.nodeId:`${e.nodeId} · ${e.deviceKey}`;return e.modelId===void 0?t:`${t} (${e.modelId})`}function ki(e){let t=e?.openedPlacement,n=e?.closedPlacement;if(t!==void 0&&n!==void 0){let e=Oi(t),r=Oi(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:Oi(n)}]:[{kind:`opened`,value:Oi(t)}]}var Ai=100,ji={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Mi=e=>e<0?0:e>1?1:e,Ni=e=>Math.round(e*100)/100;function Pi(e,t,n){if(e.length===0||t===null)return ji;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return ji;let a=ce(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:Ni(e.x*Ai),y:Ni(e.y*Ai)})),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:Ni(Mi(e.x/r)*Ai),y:Ni(Mi(e.y/i)*Ai),mediaId:e.mediaId})),u=null,d=-1;for(let t of e){let e=Mi(t.bbox.w/r)*Mi(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:Ni(Mi(u.bbox.x/r)*Ai),y:Ni(Mi(u.bbox.y/i)*Ai),w:Ni(Mi(u.bbox.w/r)*Ai),h:Ni(Mi(u.bbox.h/i)*Ai)}:null}}var Fi=typeof Ie==`function`,Ii=`Track deletion arrives with the next server update`;function Li(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var Ri=Fi?Ie:Li;l();var zi=15e3,Bi=M();function Vi({url:e,label:t}){let{src:n,failed:r}=Ut(e);return n===null?a(`div`,{className:`flex h-full w-full items-center justify-center bg-surface-hover`,children:r?a(f,{className:`h-4 w-4 text-foreground-subtle opacity-60`}):a(z,{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 Hi=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),Ui=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`,`sceneFrame`,`lastSceneFrame`]);function Wi(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 Gi({overlay:t,onPickSnapshot:n}){let{t:r}=X();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 Z({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 Ki({row:t,cameraName:r,deleteAvailable:c,onClose:l,onDeleted:u,onFlagsChanged:p}){let{t:m}=X(),h=ee(),g=H(),_=ne(),y=Ri(),b=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:b}),{data:E}=Le({trackId:S,deviceId:x},{enabled:b}),D=T?.bestEventId===void 0?void 0:Number(T.bestEventId),{data:O}=Fe({ownerType:`object`,eventId:D??0,deviceId:x},{enabled:b&&D!==void 0&&Number.isFinite(D)}),{data:A}=wt({deviceId:x},{enabled:b}),j=(A??[]).find(e=>e.addonId!==void 0)?.addonId,{data:M}=yt({deviceId:x,since:C-zi,until:C+w+zi,provider:j??``},{enabled:b&&j!==void 0}),[N,P]=s(null),[F,I]=s(!1),{publicOrigin:L,probes:R}=vi(b);o(()=>{P(null)},[x,S]);let B=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]),V=N??B,U=Ut(V?V.url:void 0),W=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]),te=n(()=>W.find(e=>Hi.has(e.kind))??null,[W]),G=Wi(Ut(te?te.url:void 0).src),re=n(()=>Pi(T?.positions??[],G,{snapshots:(T?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaId:e.mediaId}))}),[T?.positions,T?.snapshots,G]),ie=i(e=>{let t=W.find(t=>t.mediaId===e);t&&P(t)},[W]);if(t===null)return null;let K=U.src,q=V?.kind,ae=q!==void 0&&Ui.has(q)&&G!==null&&(T?.positions.length??0)>=2,oe=M&&M.length>0?M[0]:null,se=()=>{oe&&(I(!0),(async()=>{try{let e=await h.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:oe.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{g({title:m(`detectionIntelligence.eventDetailPanel.clipUnavailable`,`Clip unavailable`),message:m(`detectionIntelligence.eventDetailPanel.couldNotResolveClipPlayback`,`Could not resolve clip playback. Check the server logs.`),variant:`warning`})}finally{I(!1)}})())},ce=()=>{!c||y.isPending||(async()=>{if(await _({title:m(`detectionIntelligence.eventDetailPanel.deleteTrack`,`Delete track`),message:m(`detectionIntelligence.eventDetailPanel.deleteThisTrackAndEvery`,`Delete this track and every image and clip captured for it? This cannot be undone.`),confirmLabel:m(`common.delete`,`Delete`),variant:`danger`}))try{await y.mutateAsync({deviceId:t.deviceId,trackIds:[t.trackId]}),u()}catch{await g({title:m(`detectionIntelligence.eventDetailPanel.deleteFailed`,`Delete failed`),message:m(`detectionIntelligence.eventDetailPanel.failedToDeleteThisTrack`,`Failed to delete this track. Check the server logs.`),variant:`danger`})}})()},le=Math.round(t.importance*100),ue=T?.importanceReason?`${String(le)}% · ${T.importanceReason}`:`${String(le)}%`,de=T?.zonesVisited&&T.zonesVisited.length>0?T.zonesVisited.join(`, `):`—`,fe=T?.audioLabels&&T.audioLabels.length>0?T.audioLabels:t.audioLabels&&t.audioLabels.length>0?t.audioLabels:void 0,pe=fe===void 0?`—`:fe.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `),me=T?T.totalDistance.toFixed(2):`—`,he=oi(T?.previewMissReason),ge=Qn(T?T.firstSeen:C),_e=T?Qn(T.lastSeen):`—`,ve=ki(T),ye={detected:m(`detectionIntelligence.eventDetailPanel.detectedOn`,`Detected on`),opened:m(`detectionIntelligence.eventDetailPanel.openedOn`,`Opened on`),closed:m(`detectionIntelligence.eventDetailPanel.closedOn`,`Closed on`)};return a(et,{open:!0,onOpenChange:e=>!e&&l(),children:e(xt,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":m(`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,qr(t)?e(`span`,{className:`text-foreground-subtle`,children:[` · `,qr(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:[K?a(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:a(hr,{src:K,alt:m(`detectionIntelligence.eventDetailPanel.keyFrameFrom`,`Key frame from {{cameraName}}`,{cameraName:r}),fit:`natural`,className:`w-full`,overlay:ae?a(Gi,{overlay:re,onPickSnapshot:ie}):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:U.failed?e(d,{children:[a(f,{className:`h-8 w-8 opacity-60`}),a(`span`,{className:`text-[11px]`,children:m(`detectionIntelligence.eventDetailPanel.keyFrameMediaUnavailable`,`Key-frame media unavailable`)})]}):a(z,{className:`h-6 w-6 animate-spin opacity-70`})}),W.length>0&&a(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:W.map(t=>{let n=hi(t.kind),r=gi(Bi,t.url),i=L?gi(L,t.url):null;return e(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[a(`button`,{type:`button`,onClick:()=>P(t),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${n} · ${Qn(t.timestamp)}`,children:a(Vi,{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:Qn(t.timestamp),children:Zn(t.timestamp)})]}),a(fi,{localUrl:r,publicUrl:i})]},t.mediaId)})}),R,oe&&e(J,{variant:`secondary`,onClick:se,disabled:F,children:[F?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(k,{className:`h-3.5 w-3.5`}),` `,m(`detectionIntelligence.eventDetailPanel.viewClip`,`View clip`)]}),a(Di,{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:p}),he!==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:m(`detectionIntelligence.eventDetailPanel.bestShot`,`Best shot`)}),a(`p`,{className:`mt-0.5 text-xs text-foreground`,children:he.sentence}),a(`code`,{className:`mt-1 block break-all font-mono text-[10px] text-foreground-subtle`,children:he.raw})]}),e(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[a(Z,{label:m(`detectionIntelligence.eventDetailPanel.camera`,`Camera`),value:r}),ve.map(e=>a(Z,{label:ye[e.kind],value:e.value,mono:!0,wrap:!0},e.kind)),a(Z,{label:m(`detectionIntelligence.eventDetailPanel.class`,`Class`),value:t.className}),a(Z,{label:m(`detectionIntelligence.eventDetailPanel.label`,`Label`),value:t.label??`—`}),a(Z,{label:m(`detectionIntelligence.eventDetailPanel.subLabel`,`Sub-label`),value:t.subLabel??`—`}),a(Z,{label:m(`detectionIntelligence.eventDetailPanel.importance`,`Importance`),value:ue}),a(Z,{label:m(`detectionIntelligence.eventDetailPanel.zonesVisited`,`Zones visited`),value:de}),a(Z,{label:m(`detectionIntelligence.eventDetailPanel.audioHeard`,`Audio heard`),value:pe}),a(Z,{label:m(`detectionIntelligence.eventDetailPanel.totalDistance`,`Total distance`),value:me}),a(Z,{label:m(`detectionIntelligence.eventDetailPanel.firstSeen`,`First seen`),value:ge}),a(Z,{label:m(`detectionIntelligence.eventDetailPanel.lastSeen`,`Last seen`),value:_e}),a(Z,{label:m(`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:Ii,children:e(J,{variant:`secondary`,onClick:ce,disabled:!c||y.isPending,children:[y.isPending?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(v,{className:`h-3.5 w-3.5`}),` `,m(`detectionIntelligence.eventDetailPanel.deleteTrack`,`Delete track`)]})})})]})})}var qi={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`},Ji={setRelation:`debug.gt.setRelation`,setPurity:`debug.gt.setPurity`,list:`debug.gt.list`},Yi=E(`/addon/pipeline-analytics/tape-export`),Xi=10*6e4;function Zi(e){return`${Yi}?tapeId=${encodeURIComponent(e)}`}var Qi=`The server answered in a shape this build does not understand.`;function $i(e){return e instanceof Error?e.message:Y.t(`helpers.eventsDebugTapes.actionFailed`)}function ea(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 ta(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 na(e,t){let n=e[t];return typeof n==`boolean`?n:null}function ra(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 ia(e){return e===`off`||e===`recording`||e===`refused`||e===`failing`||e===`unknown`}function aa(e){if(!ea(e))return null;let t=Q(e,`deviceId`),n=e.state,r=Q(e,`gapsSinceArmed`),i=ta(e,`segmentsHeld`),a=ta(e,`bytesLastHour`),o=ta(e,`bytesHeld`);if(t===null||!ia(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 oa(e){return ea(e)?ra(e.cameras,aa):null}function sa(e){if(!ea(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=na(e,`reviewed`),f=na(e,`released`),p=ra(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 ca(e){return ea(e)?ra(e.tapes,sa):null}function la(e){if(!ea(e))return null;let t=$(e,`trackId`),n=Q(e,`firstT`),r=Q(e,`lastT`),i=Q(e,`boundFrames`),a=$(e,`cls`),o=na(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 ua(e){if(!ea(e))return null;let t=$(e,`tapeId`),n=Q(e,`deviceId`),r=Q(e,`fromMs`),i=Q(e,`toMs`),a=na(e,`reviewed`),o=ra(e.lanes,la);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 da(e){if(!ea(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 fa(e){if(!ea(e))return null;let t=e.status;if(t===`released`){let n=Q(e,`unpinned`),r=na(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 pa(e){if(!ea(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 ma(e){switch(e.status){case`released`:case`deleted`:return null;case`already-released`:return Y.t(`helpers.eventsDebugTapes.alreadyReleased`);case`not-found`:return Y.t(`helpers.eventsDebugTapes.notFound`);case`pins-owed`:return Y.t(`helpers.eventsDebugTapes.pinsOwed`);case`unavailable`:return Y.t(`helpers.eventsDebugTapes.unavailable`,{reason:e.reason})}}function ha(e){if(!ea(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 ga(e){if(!ea(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 _a(e){if(!ea(e))return null;let t=ra(e.relations,ha),n=ra(e.purities,ga),r=na(e,`truncated`);return t===null||n===null||r===null?null:{relations:t,purities:n,truncated:r}}function va(e){if(!e.truncated)return null;let t=e.relations.length+e.purities.length;return Y.t(`helpers.eventsDebugTapes.truncatedMarks`,{count:t})}function ya(e){return e.filter(e=>e.segmentsHeld===null||e.segmentsHeld>0).map(e=>({deviceId:e.deviceId,segmentsUnknown:e.segmentsHeld===null}))}function ba(e){return e.slice(1).map((t,n)=>({trackId:e[n]??t,otherTrackId:t}))}function xa(e){return e.flatMap((t,n)=>e.slice(n+1).map(e=>({trackId:t,otherTrackId:e})))}function Sa(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 Ca(e){switch(e.state){case`off`:return Y.t(`helpers.eventsDebugTapes.statusOff`);case`recording`:return Y.t(`helpers.eventsDebugTapes.statusRecording`);case`refused`:return Y.t(`helpers.eventsDebugTapes.statusRefused`,{reason:e.reason??Y.t(`helpers.eventsDebugTapes.unknownReason`)});case`failing`:return Y.t(`helpers.eventsDebugTapes.statusFailing`,{reason:e.reason??Y.t(`helpers.eventsDebugTapes.unknownReason`)});case`unknown`:return Y.t(`helpers.eventsDebugTapes.statusUnknown`,{reason:e.reason??Y.t(`helpers.eventsDebugTapes.unknownReason`)})}}var wa={"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 Ta(e,t){let n=wa[e]??`Refused (${e}).`;return t.length>0?`${n} ${t}`:n}function Ea(e){if(e.length===0)return null;let t=new Date(e).getTime();return Number.isFinite(t)?t:null}function Da(e){return e<1024*1024?Y.t(`helpers.eventsDebugTapes.sizeKb`,{value:(e/1024).toFixed(0)}):Y.t(`helpers.eventsDebugTapes.sizeMb`,{value:(e/1024/1024).toFixed(1)})}function Oa(e){return e===null?`unknown`:Da(e)}function ka(e){return e===null?`unknown`:String(e)}function Aa(e,t){let n=t.trim();return e===404?Y.t(`helpers.eventsDebugTapes.exportUnknown`):e===503?n.length>0?n:Y.t(`helpers.eventsDebugTapes.tapesUnavailable`):e===500?n.length>0?n:Y.t(`helpers.eventsDebugTapes.exportUnreadable`):Y.t(`helpers.eventsDebugTapes.downloadFailed`,{status:e})}l();function ja({cameras:t,call:n,onPromoted:r}){let{t:i}=X(),[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=Ea(l),a=Ea(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=da(await n(qi.promote,{deviceId:e,fromMs:i,toMs:a,scenario:p,...h.trim().length>0?{note:h.trim()}:{},..._===`day`||_===`ir`?{lighting:_}:{}}));t===null?S(Qi):t.ok?(S(`Promoted ${t.tapeId}: ${String(t.frames)} frames, ${Da(t.bytes)}, ${String(t.pinnedTracks)} tracks pinned`+(t.state===`incomplete`?` — incomplete (it has gaps) and cannot become a case.`:`.`)),r()):S(Ta(t.reason,t.detail))}catch(e){S($i(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($e,{value:o,options:[...t],onChange:e=>c(e.target.value),"aria-label":i(`eventsDebugTapesPromoteForm.camera`,`Camera`)})}),a(st,{type:`datetime-local`,"aria-label":i(`eventsDebugTapesPromoteForm.from`,`From`),value:l,onChange:e=>u(e.target.value),className:`w-48`}),a(st,{type:`datetime-local`,"aria-label":i(`eventsDebugTapesPromoteForm.to`,`To`),value:d,onChange:e=>f(e.target.value),className:`w-48`}),a(st,{"aria-label":i(`eventsDebugTapesPromoteForm.scenario`,`Scenario`),placeholder:`101-door-groups`,value:p,onChange:e=>m(e.target.value),className:`w-44`}),a(st,{"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($e,{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(J,{onClick:()=>void C(),disabled:y||t.length===0,children:[y?a(z,{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 Ma=`pipeline-analytics`,Na=`debug.listTracks`,Pa=`debug.analyze`,Fa=E(`/addon/pipeline-analytics/debug-export`);function Ia(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function La(e,t){let n=e[t];return typeof n==`string`?n:null}function Ra(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function za(e,t){let n=e[t];return typeof n==`boolean`?n:null}function Ba(e){return e===`error`||e===`warn`||e===`info`}function Va(e){if(!Ia(e))return null;let t=La(e,`code`),n=La(e,`detail`),r=e.severity;return t===null||n===null||!Ba(r)?null:{code:t,severity:r,detail:n}}function Ha(e){if(!Ia(e))return null;let t=La(e,`trackId`),n=Ra(e,`deviceId`),r=La(e,`className`),i=Ra(e,`firstSeen`),a=Ra(e,`lastSeen`),o=Ra(e,`durationMs`),s=za(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=La(e,`label`),l=La(e,`subLabel`),u=La(e,`previewMissReason`),d=za(e,`markForTrain`),f=za(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:Ra(e,`importance`)??0,bestEventId:La(e,`bestEventId`)??``,...d===null?{}:{markForTrain:d},...f===null?{}:{favourited:f},debug:!0,...u===null||u.length===0?{}:{previewMissReason:u}}}function Ua(e){let t=Ha(e);if(t===null||!Ia(e))return null;let n=Ra(e,`mediaCount`),r=Ra(e,`eventCount`),i=Ra(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=Va(e);t!==null&&c.push(t)}let l=e.thumbnailProvenance;return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c,...ni(l)?{thumbnailProvenance:l}:{}}}function Wa(e){if(!Ia(e))return null;let t=za(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=Ha(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function Ga(e){if(!Ia(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=Ua(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var Ka={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 qa(e){return Ka[e]??e}var Ja={error:0,warn:1,info:2};function Ya(e){return e.toSorted((e,t)=>Ja[e.severity]-Ja[t.severity]||e.code.localeCompare(t.code))}function Xa(e){return e.length===0?Fa:`${Fa}?deviceIds=${e.join(`,`)}`}function Za(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 Qa(e,t){return`${String(e)}:${t}`}function $a(e,t){let n=[],r=new Set;for(let i of e){let e=Qa(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 eo({tapeId:t,call:n,onClose:r,onChanged:i}){let{t:o}=X(),l=c({queryKey:[`events-debug`,`tapes`,`tracks`,t],queryFn:async()=>ua(await n(qi.tracks,{tapeId:t}))}),u=l.data??null,d=c({queryKey:[`events-debug`,`tapes`,`marks`,t],enabled:u!==null,queryFn:async()=>u===null?null:_a(await n(Ji.list,{deviceId:u.deviceId,since:u.fromMs-Xi,until:u.toMs+Xi,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){_($i(e))}};if(u===null)return l.isLoading?a(`p`,{className:`text-xs`,children:o(`eventsDebugTapesReview.loadingTheTape`,`Loading the tape…`)}):a(Ue,{message:Qi});let b=u.deviceId,x=(e,t)=>y(e.map(e=>[Ji.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=>[Ji.setPurity,{deviceId:b,trackId:t,purity:e,...n===void 0?{}:{switchAtMs:Math.round(n)}}]))},C=d.data==null?null:va(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(J,{disabled:f.length<2,onClick:()=>void x(ba(f),`same-subject`),children:o(`eventsDebugTapesReview.sameSubject`,`Same subject`)}),a(J,{variant:`secondary`,disabled:f.length<2,onClick:()=>void x(xa(f),`different-subjects`),children:o(`eventsDebugTapesReview.differentSubjects`,`Different subjects`)}),a(st,{"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(J,{variant:`secondary`,disabled:f.length!==1,onClick:()=>void S(`mixed`),children:o(`eventsDebugTapesReview.mixed`,`Mixed`)}),a(J,{variant:`secondary`,disabled:f.length===0,onClick:()=>void S(`not-a-subject`),children:o(`eventsDebugTapesReview.notASubject`,`Not a subject`)}),a(J,{variant:u.reviewed?`secondary`:`primary`,onClick:()=>void y([[qi.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(J,{variant:`ghost`,onClick:r,children:o(`common.close`,`Close`)})]}),g!==null&&a(Ue,{message:g}),C!==null&&a(Ue,{variant:`warning`,message:C}),a(`ul`,{className:`space-y-1`,children:u.lanes.toSorted((e,t)=>e.firstT-t.firstT).map(e=>a(to,{lane:e,marks:d.data===null||d.data===void 0?[]:Sa(e.trackId,d.data),selected:f.includes(e.trackId),onToggle:()=>v(e.trackId)},e.trackId))})]})}function to({lane:t,marks:n,selected:r,onToggle:i}){let{t:o}=X(),{src:s}=Ut(t.stillStored?Wt(`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:`${Za(t.firstT)} → ${Za(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(Ct,{variant:`info`,children:e},e))]})}l();var no=`camstack_admin_token`;function ro(){let e=ee();return(t,n)=>e.trpcClient.addons.custom.mutate({addonId:Ma,action:t,input:n})}async function io(e,t){let n=localStorage.getItem(no),r={};n!==null&&(r.Authorization=`Bearer ${n}`);let i=await fetch(Zi(e),{headers:r});if(!i.ok){let e=await i.text().catch(()=>``);throw Error(Aa(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 ao(){let{t:e}=X(),[t,n]=s(!1);return a(ze,{expanded:t,onExpandedChange:n,header:a(`span`,{className:`text-sm font-medium text-foreground`,children:e(`eventsDebugTapes.trackingTapes`,`Tracking tapes`)}),children:a(oo,{})})}function oo(){let{t}=X(),r=ro(),i=we({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()=>oa(await r(qi.status,{}))}),u=c({queryKey:[`events-debug`,`tapes`,`list`],queryFn:async()=>ca(await r(qi.list,{}))}),[d,f]=s(null),[p,m]=s(null),h=async e=>{m(null);try{await io(e.id,`${e.scenario}.tape-bundle.json.gz`)}catch(e){m($i(e))}},g=async e=>{let t=fa(await r(qi.release,{tapeId:e.id}));if(t===null)throw Error(Qi);let n=ma(t);if(n!==null)throw Error(n);await u.refetch()},_=async e=>{let t=pa(await r(qi.remove,{tapeId:e.id}));if(t===null)throw Error(Qi);let n=ma(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(zt,{i18nKey:`eventsDebugTapes.intro`,components:{b:a(`strong`,{}),code:a(`code`,{})}})}),p!==null&&a(Ue,{message:p}),l.isLoading&&a(`p`,{className:`text-xs text-foreground-subtle`,children:t(`eventsDebugTapes.loadingCameraStatus`,`Loading camera status…`)}),l.data===null&&a(Ue,{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(Ct,{variant:n.state===`recording`?`success`:n.state===`off`?`default`:n.state===`unknown`?`warning`:`danger`,children:Ca(n)})}),a(`td`,{children:n.framesPerMin===void 0?`—`:String(Math.round(n.framesPerMin))}),a(`td`,{title:n.shelfError,children:Oa(n.bytesLastHour)}),a(`td`,{title:n.shelfError,children:t(`eventsDebugTapes.segsHeld`,{count:ka(n.segmentsHeld),size:Oa(n.bytesHeld)})}),a(`td`,{children:String(n.gapsSinceArmed)})]},n.deviceId))})]}),a(ja,{cameras:ya(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(Ue,{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(),` · `,Za(n.toMs-n.fromMs),` `,`· `,n.lighting]}),e(`td`,{children:[a(Ct,{variant:n.state===`complete`?`success`:`warning`,children:n.state}),` `,n.reviewed&&a(Ct,{variant:`info`,children:t(`eventsDebugTapes.reviewed`)}),` `,n.released&&a(Ct,{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(J,{variant:`secondary`,"aria-label":t(`eventsDebugTapes.review`,`Review {{scenario}}`,{scenario:n.scenario}),onClick:()=>f(n.id),children:t(`eventsDebugTapes.review2`,`Review`)}),a(J,{variant:`ghost`,"aria-label":t(`eventsDebugTapes.download`,`Download {{scenario}}`,{scenario:n.scenario}),onClick:()=>void h(n),children:a(A,{className:`h-3.5 w-3.5`})}),a(ut,{label:t(`eventsDebugTapes.release`,`Release`),icon:ie,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:()=>g(n)}),a(ut,{label:t(`common.delete`,`Delete`),icon:v,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:()=>_(n)})]})]},n.id))})]}),d!==null&&a(eo,{tapeId:d,call:r,onClose:()=>f(null),onChanged:()=>void u.refetch()})]})}l();var so=`all`,co=`The server answered in a shape this build does not understand.`,lo={error:`danger`,warn:`warning`,info:`info`};function uo({findings:e}){let{t}=X();return e.length===0?a(Ct,{variant:`success`,children:t(`eventsDebug.noAnomalyFound`,`no anomaly found`)}):a(`div`,{className:`flex flex-wrap gap-1`,children:Ya(e).map(e=>a(Ct,{variant:lo[e.severity],title:e.detail,children:qa(e.code)},e.code))})}function fo({track:t,report:n,analyzing:r}){let{t:i}=X(),o=oi(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(uo,{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 po(){let{t}=X(),r=ee(),[i,o]=s(so),[l,u]=s(!1),[d,f]=s(null),[p,m]=s(new Set),[h,_]=s(null),[v,x]=s(null),[S,C]=s(null),[w,E]=s([]),D=wi(),O=we({isCamera:!0,projection:`slim`}),k=n(()=>[{value:so,label:t(`eventsDebug.allCameras`,`All cameras`)},...(O.data??[]).map(e=>({value:String(e.id),label:e.name}))],[O.data,t]),j=n(()=>{let e=new Map;for(let t of O.data??[])e.set(t.id,t.name);return e},[O.data]),M=e=>j.get(e)??t(`eventsDebug.cameraFallback`,{deviceId:e}),N=n(()=>i===so?[]:[Number.parseInt(i,10)],[i]),P=c({queryKey:[`events-debug`,`list`,N],queryFn:async()=>Wa(await r.trpcClient.addons.custom.mutate({addonId:Ma,action:Na,input:N.length===0?{}:{deviceIds:N}}))}),F=n(()=>(P.data?.tracks??[]).map(e=>e.trackId),[P.data]),I=c({queryKey:[`events-debug`,`analyze`,F],enabled:F.length>0,queryFn:async()=>Ga(await r.trpcClient.addons.custom.mutate({addonId:Ma,action:Pa,input:{trackIds:F}}))}),R=n(()=>{let e=new Map;for(let t of I.data?.reports??[])e.set(t.trackId,t);return e},[I.data]),V=P.data?.tracks??[],H=P.data===null||I.data===null,U=()=>{P.refetch(),I.refetch()},W=e=>{m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},te=()=>{m(new Set(V.map(e=>Qa(e.deviceId,e.trackId))))},ne=()=>m(new Set),G=async(e,t)=>{let n=e===`analyzed`?{debug:!1}:{favourited:!0},r=0,i=[];for(let e of t)try{await D.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,flags:n}),r+=1}catch{i.push(e.trackId)}return{applied:r,refused:i}},re=e=>{if(!xi||v!==null)return;let t=$a(V,p);t.length!==0&&(x(e),C(null),(async()=>{let n=await G(e,t);x(null);let r=new Set(n.refused);m(new Set(t.filter(e=>r.has(e.trackId)).map(e=>Qa(e.deviceId,e.trackId)))),e===`analyzed`&&E(t.filter(e=>!r.has(e.trackId))),n.refused.length>0&&C(`${String(n.refused.length)} of ${String(t.length)} were refused by the server and are still selected. Check the hub log.`),P.refetch()})())},ie=()=>{let e=w;e.length===0||v!==null||(x(`analyzed`),C(null),(async()=>{for(let t of e)try{await D.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,flags:{debug:!0}})}catch{C(`Some tracks could not be re-marked. Refresh and try again.`)}x(null),E([]),P.refetch()})())},K=async()=>{u(!0),f(null);try{await qt(Xa(N),`camstack-debug.zip`)}catch(e){f(e instanceof Error?e.message:`Export failed.`)}finally{u(!1)}},q=v!==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($e,{value:i,options:k,onChange:e=>o(e.target.value)})}),e(J,{variant:`secondary`,onClick:U,disabled:P.isFetching,children:[P.isFetching?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(g,{className:`h-3.5 w-3.5`}),t(`common.refresh`,`Refresh`)]}),e(J,{onClick:()=>void K(),disabled:l||V.length===0,children:[l?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(A,{className:`h-3.5 w-3.5`}),t(`eventsDebug.exportAll`,{count:String(V.length)})]}),V.length>0&&p.size<V.length&&a(J,{variant:`ghost`,onClick:te,children:t(`eventsDebug.selectAll`,`Select all`)})]}),a(`p`,{className:`text-xs text-foreground-subtle`,children:a(zt,{i18nKey:`eventsDebug.debugMarkNote`,components:{code:a(`code`,{}),strong:a(`strong`,{})}})}),a(ao,{}),P.isError&&a(Ue,{message:t(`eventsDebug.couldNotLoadTheMarked`,`Could not load the marked tracks.`)}),H&&!P.isError&&a(Ue,{message:co}),d!==null&&a(Ue,{message:d}),S!==null&&a(Ue,{message:S}),P.data?.truncated===!0&&a(Ue,{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.`)}),(I.data?.vanished.length??0)>0&&a(`p`,{className:`text-xs text-foreground-subtle`,children:t(`eventsDebug.vanished`,{count:String(I.data?.vanished.length)})}),p.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:p.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[a(`span`,{title:xi?void 0:`Track flags arrive with the next server update`,children:e(J,{variant:`secondary`,onClick:()=>re(`keep`),disabled:!xi||q,children:[v===`keep`?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(L,{className:`h-3.5 w-3.5`}),` `,t(`eventsDebug.keep`,`Keep`)]})}),a(`span`,{title:xi?void 0:`Track flags arrive with the next server update`,children:e(J,{onClick:()=>re(`analyzed`),disabled:!xi||q,children:[v===`analyzed`?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(T,{className:`h-3.5 w-3.5`}),` `,t(`eventsDebug.analyzed`,`Analyzed`)]})}),a(J,{variant:`ghost`,onClick:ne,disabled:q,children:a(B,{className:`h-3.5 w-3.5`})})]})]}),w.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(w.length)})}),e(J,{variant:`ghost`,onClick:ie,disabled:q,children:[a(b,{className:`h-3.5 w-3.5`}),` `,t(`eventsDebug.undo`)]}),a(J,{variant:`ghost`,onClick:()=>E([]),disabled:q,children:a(B,{className:`h-3.5 w-3.5`})})]}),P.isLoading?a(nt,{status:`pending`,pendingMessage:`Loading…`,testId:`debug-tracks-grid`}):V.length===0?a(Te,{icon:y,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(nt,{status:`ready`,testId:`debug-tracks-grid`,children:V.map(e=>{let t=R.get(e.trackId);return a(ci,{row:e,cameraName:M(e.deviceId),nowMs:e.lastSeen,selected:p.has(Qa(e.deviceId,e.trackId)),onToggleSelect:W,onOpenDetail:_,...t?.thumbnailProvenance===void 0?{}:{provenance:t.thumbnailProvenance},footer:a(fo,{track:e,report:t,analyzing:I.isFetching})},Qa(e.deviceId,e.trackId))})}),h&&a(Ki,{row:h,cameraName:M(h.deviceId),deleteAvailable:Fi,onClose:()=>_(null),onDeleted:()=>{_(null),P.refetch()},onFlagsChanged:e=>{e.debug||(_(null),P.refetch())}})]})}var mo=200,ho=3e4,go=[];function _o(e){let t=ee(),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:ho,refetchInterval:ho,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEventsBatch.query({deviceIds:r,since:e.since,until:e.until,limit:mo,...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:Xr(Yr(i??go),`importance`),isLoading:n&&a}}l();var vo=[`events-feed`],yo=2e3;function bo(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:vo})},[]),p=t(void 0);p.current||=Hr({delayMs:yo,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 Pt(le.PipelineAnalyticsDetectionEvent,()=>{p.current?.trigger()}),Pt(le.PipelineAnalyticsTrackEnded,()=>{p.current?.trigger()}),{pending:l,refreshNow:m}}l();function xo({groups:t,selected:r,onChange:i,loading:o=!1}){let{t:c}=X(),l=kt(),[u,d]=s(!1),[f,p]=s(``),[h,g]=s(new Set),_=f.trim().toLowerCase(),v=e=>_.length===0||Dt(e,c).toLowerCase().includes(_),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,_]),b=e=>g(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(j,{className:`h-3.5 w-3.5`}),w>0?c(`detectionIntelligence.eventKindFilter.kinds`,`Kinds ({{value1}})`,{value1:String(w)}):c(`detectionIntelligence.eventKindFilter.kinds2`,`Kinds`),a(m,{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(K,{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…`):_.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=vt(t.macro.iconId),i=h.has(t.macro.kind)||_.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?m:D,{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:Dt(t.macro,c)})]})]}),i&&t.subs.map(t=>{let n=vt(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:Dt(t,c)})]},t.kind)})]},t.macro.kind)})]})]})}function So(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 Co(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var wo=new Set([`detection`,`package`]);function To(e,t){return[...So(e,t).values()].filter(e=>e.parentKind===null&&wo.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function Eo(e,t){let n=So(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,Co(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 Do(){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 Oo=[`events-feed`],ko=60,Ao=[{value:`importance`,labelKey:`detectionIntelligence.eventsSection.sortImportance`,icon:de},{value:`time`,labelKey:`detectionIntelligence.eventsSection.sortRecent`,icon:I}];function jo(){let{t}=X(),r=u(),i=H(),c=ne(),[l,f]=s(Bn),[p,m]=s(new Set),[h,g]=s(new Set),[_,y]=s(0),[b,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(()=>ei({fromMs:l.fromMs,toMs:l.toMs},E),[l.fromMs,l.toMs,E]),A=Do(),{pending:j,refreshNow:M}=bo({paused:w!==null||S.size>0||A.scrolledPast}),{data:N=[]}=we({isCamera:!0,projection:`slim`}),P=n(()=>N.map(e=>e.id),[N]),{data:F,isLoading:I}=pt({deviceIds:P},{enabled:P.length>0,staleTime:5*6e4}),ee=n(()=>Eo(F??[],p),[F,p]),L=Ri(),R=L.isPending,{rows:V,isLoading:U}=_o({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]),G=e=>W.get(e)??t(`detectionIntelligence.cameraFallback`,{id:String(e)}),re=n(()=>qn(V).map(e=>({id:e,name:G(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[V,W]),ie=n(()=>Xr(Zr(V,{cameras:p,classes:h,minImportance:_}),b),[V,p,h,_,b]),K=rr(ie,ko,n(()=>JSON.stringify([[...p].sort((e,t)=>e-t),[...h].sort(),_,b,O,k]),[p,h,_,b,O,k])),q=()=>{r.invalidateQueries({queryKey:Oo})},ae=()=>C(new Set);function oe(e){C(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function se(){if(S.size===0||!Fi)return;let e=$r(V,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`})&&ce(e)})()}function ce(e){let n=[...e];Promise.allSettled(n.map(([e,t])=>L.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{q();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(Qr(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=>G(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 le=ie.length!==V.length;return e(`div`,{className:`relative space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[a(dr,{onChange:f}),a(lr,{cameras:re,selected:p,onChange:m}),a(xo,{groups:ee,selected:h,onChange:g,loading:I}),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=>y(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:Ao.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 ${b===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:le?t(`detectionIntelligence.eventsSection.ofEvents`,`{{value1}} of {{value2}} events`,{value1:String(ie.length),value2:String(V.length)}):t(`detectionIntelligence.eventsSection.eventCount`,{count:ie.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:Fi?void 0:`Track deletion arrives with the next server update`,children:e(J,{variant:`secondary`,onClick:se,disabled:!Fi||R,children:[R?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(v,{className:`h-3.5 w-3.5`}),` `,t(`common.delete`,`Delete`)]})}),a(J,{variant:`ghost`,onClick:ae,disabled:R,children:a(B,{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(nt,{status:`pending`,pendingMessage:`Loading events…`,testId:`events-grid`}):ie.length===0?a(Te,{icon:te,title:le?t(`detectionIntelligence.eventsSection.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.eventsSection.noKeyEventsInThis`,`No key events in this window`),description:le?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(nt,{status:`ready`,testId:`events-grid`,children:K.pageItems.map(e=>a(ci,{row:e,cameraName:G(e.deviceId),nowMs:E,selected:S.has(Qr(e.deviceId,e.trackId)),onToggleSelect:oe,onOpenDetail:T},Qr(e.deviceId,e.trackId)))}),a(or,{currentPage:K.page,totalItems:K.totalItems,pageSize:K.pageSize,onPageChange:K.setPage,itemNoun:`events`})]}),w&&a(Ki,{row:w,cameraName:G(w.deviceId),deleteAvailable:Fi,onClose:()=>T(null),onDeleted:()=>{q(),T(null)},onFlagsChanged:e=>{T(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug,favourited:e.favourited}:t)}})]})}var Mo=`/addon/training`;function No(){let{t}=X(),n=Lt();return e(Ze,{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(C,{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:`${ae} 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(J,{variant:`outline`,size:`sm`,className:`shrink-0 self-start sm:self-center`,onClick:()=>n(Mo),children:t(`detectionIntelligence.retrainTabCallout.openTraining`,`Open Training`)})]})}l();var Po=50,Fo=350,Io=[{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 Lo(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 Ro({onActiveChange:r}){let i=t(null);He(i);let{t:c}=X(),[l,u]=s(``),[d,f]=s(`loose`),[p,m]=s(null),[h,g]=s(null),[_,v]=s(null),y=Ot(l,Fo).trim(),b=y.length>0;o(()=>{r(b)},[b,r]);let[x,S]=s(()=>Date.now());o(()=>{let e=setInterval(()=>S(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:C=[]}=we({isCamera:!0,projection:`slim`}),w=n(()=>{let e=new Map;for(let t of C)e.set(t.id,t.name);return e},[C]),T=e=>w.get(e)??c(`detectionIntelligence.cameraFallback`,{id:String(e)}),E=n(()=>C.map(e=>e.id),[C]),{data:D}=pt({deviceIds:E},{enabled:E.length>0,staleTime:5*6e4}),O=n(()=>To(D??[],new Set(h===null?[]:[h])),[D,h]);o(()=>{p!==null&&(O.some(e=>e.kind===p)||m(null))},[O,p]);let{data:k,isFetching:A,isError:j,error:M}=Ae({text:y,strictness:d,limit:Po,classFilter:p??void 0,deviceId:h??void 0},{enabled:b}),N=n(()=>[...k??[]].sort((e,t)=>t.score-e.score).map(e=>({...Lo(e),score:e.score})),[k]);function P(e){m(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(K,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),a(`input`,{ref:i,type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:c(`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":c(`detectionIntelligence.semanticEventSearch.semanticEventSearch`,`Semantic event search`)}),l&&a(`button`,{type:`button`,onClick:()=>u(``),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":c(`detectionIntelligence.semanticEventSearch.clearSearch`,`Clear search`),children:a(B,{className:`h-3.5 w-3.5`})})]}),A&&b&&a(z,{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:O.map(e=>a(`button`,{type:`button`,onClick:()=>P(e.kind),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${p===e.kind?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:Dt(e)},e.kind))}),e(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[a(`span`,{children:c(`detectionIntelligence.semanticEventSearch.camera`,`Camera`)}),a($e,{value:h===null?``:String(h),onChange:e=>g(e.target.value===``?null:Number(e.target.value)),className:`h-7 text-xs`,"aria-label":c(`detectionIntelligence.semanticEventSearch.filterByCamera`,`Filter by camera`),options:[{value:``,label:c(`detectionIntelligence.semanticEventSearch.all`,`All`)},...C.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:c(`detectionIntelligence.semanticEventSearch.match`,`Match`)}),a(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Io.map(e=>a(`button`,{type:`button`,onClick:()=>f(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${d===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:c(e.titleKey),children:c(e.labelKey)},e.value))})]}),b&&!A&&!j&&a(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:c(`common.matches`,{count:N.length})})]})]}),b&&e(`div`,{className:`space-y-3`,children:[j&&e(`p`,{className:`py-4 text-xs text-danger`,children:[c(`detectionIntelligence.semanticEventSearch.searchFailed`,`Search failed:`),` `,M instanceof Error?M.message:c(`detectionIntelligence.semanticEventSearch.unknownError`,`unknown error`),`. Check that the CLIP embedding step is enabled.`]}),!j&&A&&N.length===0&&a(nt,{status:`pending`,pendingMessage:`Searching…`,testId:`semantic-events-grid`}),!j&&!A&&N.length===0&&a(nt,{status:`empty`,emptyMessage:c(`detectionIntelligence.semanticEventSearch.noSemanticMatchesForTry`,`No semantic matches for “{{debounced}}”. Try a looser match threshold or a different phrasing.`,{debounced:y}),testId:`semantic-events-grid`}),!j&&N.length>0&&a(nt,{status:`ready`,testId:`semantic-events-grid`,children:N.map(e=>a(ci,{row:e,cameraName:T(e.deviceId),nowMs:x,score:e.score,onOpenDetail:v},e.id))})]}),_&&a(Ki,{row:_,cameraName:T(_.deviceId),deleteAvailable:Fi,onClose:()=>v(null),onDeleted:()=>v(null)})]})}l();function zo(e,t){let n=Math.max(0,Math.round((e-t)/6e4));if(n<1)return Y.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 Bo({row:t,cameraName:n,nowMs:r}){let{t:i}=X(),o=Ut(t.keyFrameMediaId===void 0?void 0:Kt(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(pe,{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:zo(r,t.becameStationaryAt)})})]})]})}function Vo(){let{t}=X(),[r,i]=s(!1),o=Date.now(),{data:c=[]}=we({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}=Ht(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?m:D,{className:`h-4 w-4 text-foreground-subtle`}),a(pe,{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(Bo,{row:e,cameraName:u.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:o},e.id))})]})}l();function Ho(){let[t,n]=s(!1);return e(`section`,{className:`space-y-3`,children:[a(No,{}),a(Ro,{onActiveChange:n}),!t&&a(Vo,{}),!t&&a(jo,{})]})}function Uo(){let{t:e}=X(),[t]=Bt();return t.get(`section`)===`retrain`?a(Rt,{to:`/addon/training`,replace:!0}):a(Vt,{sectionsOnly:!0,paramName:`section`,defaultSection:`feed`,sectionsLabel:`Events sections`,sections:[{id:`feed`,label:e(`events.feed`,`Feed`),content:a(Ho,{})},{id:`debug`,label:e(`events.debug`,`Debug`),content:a(po,{})}]})}function Wo(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 Go=[[`plateGallery`]];function Ko({plateIds:t,vehicles:n,onDone:r}){let{t:i}=X(),o=u(),c=Re(),l=je(),[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:Go}),b()}})}function S(){!t||!d.trim()||l.mutate({name:d.trim()},{onSuccess:e=>{e?.id&&x(e.id)},onError:()=>{o.invalidateQueries({queryKey:Go}),b()}})}let C=c.isPending||l.isPending;return a(et,{open:_,onOpenChange:e=>!e&&b(),children:e(xt,{children:[e(ct,{children:[a(Je,{children:v>1?i(`detectionIntelligence.assignPlateDialog.assignPlatesToVehicle`,`Assign {{value1}} plates to vehicle`,{value1:String(v)}):i(`detectionIntelligence.assignPlateDialog.assignPlateToVehicle`,`Assign plate to vehicle`)}),a(ht,{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(st,{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(dt,{children:[a(J,{variant:`secondary`,onClick:b,disabled:C,children:i(`common.cancel`,`Cancel`)}),p?e(J,{variant:`primary`,onClick:S,disabled:C||!d.trim(),children:[C&&a(z,{className:`h-3.5 w-3.5 animate-spin`}),i(`detectionIntelligence.assignPlateDialog.createAssign`,`Create & assign`)]}):e(J,{variant:`primary`,onClick:()=>h&&x(h),disabled:C||!h,children:[C&&a(z,{className:`h-3.5 w-3.5 animate-spin`}),v>1?i(`detectionIntelligence.assignCount`,{count:v}):i(`common.assign`)]})]})]})})}l();var qo=[[`plateGallery`]];function Jo(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 Gt(Kt(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 Yo(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 Xo({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 Zo({box:e}){let{t}=X();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 Qo({plate:t,cameraName:r,onClose:i,onAssign:c,onUnassign:l,onDelete:d,actionsPending:p}){let{t:m}=X(),h=u(),{data:g,isFetching:_}=Ft({plateId:t?.plateId??``},{enabled:t!==null}),y=De(),[b,x]=s(`frame`),[S,C]=s(!1),[E,D]=s(``),{frameSrc:k,naturalWidth:A,naturalHeight:j,failed:M}=Jo(t?.keyFrameMediaId);o(()=>{C(!1),D(``),x(`frame`)},[t?.plateId]);let P=n(()=>{let e=Yo(g??[]);return e?e.url:Wo(t)},[g,t]),F=n(()=>!t?.plateBbox||A===null||j===null?null:pr(t.plateBbox,A,j),[t?.plateBbox,A,j]);if(t===null)return null;let I=t.keyFrameMediaId!==void 0&&!M,ee=I&&b===`frame`,L=t.assigned?t.vehicleName??`Assigned`:t.recognizedVehicleId?`${t.vehicleName??`Recognized`} (suggested)`:`Unassigned`,R=`${String(Math.round(t.score*100))}%${t.corrected?` · corrected`:``}`;function V(){t&&(D(t.text),C(!0))}function H(){if(!t)return;let e=E.trim().toUpperCase();if(!e||e===t.text){C(!1);return}y.mutate({plateId:t.plateId,text:e},{onSettled:()=>{h.invalidateQueries({queryKey:qo}),C(!1)}})}return a(et,{open:!0,onOpenChange:e=>!e&&i(),children:e(xt,{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:[I&&e(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[e(`button`,{type:`button`,onClick:()=>x(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${b===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(N,{className:`h-3.5 w-3.5`}),` `,m(`detectionIntelligence.detailPanel.fullFrame`)]}),e(`button`,{type:`button`,onClick:()=>x(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${b===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(ye,{className:`h-3.5 w-3.5`}),` `,m(`detectionIntelligence.detailPanel.crop`)]})]}),ee&&k?a(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:a(hr,{src:k,alt:m(`detectionIntelligence.plateDetailPanel.fullFrameWithDetectedPlate`,`Full frame with detected plate`),fit:`natural`,className:`w-full`,overlay:F?a(Zo,{box:F}):void 0})}):P?e(`div`,{className:`relative aspect-[2/1] w-full overflow-hidden rounded-lg border border-border bg-background`,children:[a(hr,{src:P,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(z,{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(f,{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`)}),S?e(`div`,{className:`flex min-w-0 flex-1 items-center justify-end gap-1.5`,children:[a(st,{value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`&&H(),e.key===`Escape`&&C(!1)},className:`h-7 max-w-[10rem] text-right font-mono text-xs uppercase`,autoFocus:!0}),a(`button`,{type:`button`,onClick:H,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(z,{className:`h-3.5 w-3.5 animate-spin`}):a(T,{className:`h-3.5 w-3.5`})}),a(`button`,{type:`button`,onClick:()=>C(!1),className:`text-foreground-subtle hover:text-foreground`,"aria-label":m(`common.cancel`,`Cancel`),children:a(B,{className:`h-3.5 w-3.5`})})]}):e(`button`,{type:`button`,onClick:V,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(O,{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(Xo,{label:m(`detectionIntelligence.plateDetailPanel.camera`,`Camera`),value:r}),a(Xo,{label:m(`detectionIntelligence.plateDetailPanel.captured`,`Captured`),value:Qn(t.timestamp)}),a(Xo,{label:m(`detectionIntelligence.plateDetailPanel.confidence`,`Confidence`),value:R}),a(Xo,{label:m(`detectionIntelligence.plateDetailPanel.vehicle`,`Vehicle`),value:L}),a(Xo,{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(J,{variant:`secondary`,onClick:()=>l(t.plateId),disabled:p,children:[a(_e,{className:`h-3.5 w-3.5`}),` `,m(`detectionIntelligence.detailPanel.detach`)]}):e(J,{variant:`primary`,onClick:()=>c(t.plateId),disabled:p,children:[a(w,{className:`h-3.5 w-3.5`}),` `,m(`common.assign`)]}),e(J,{variant:`secondary`,onClick:()=>d(t.plateId),disabled:p,children:[a(v,{className:`h-3.5 w-3.5`}),` `,m(`common.delete`)]})]})]})})}l();var $o=[[`plateGallery`]],es=500,ts=120;function ns({plate:t,cameraName:n,nowMs:r,selected:i,onToggleSelect:o,onAssign:s,onOpenDetail:c}){let{t:l}=X(),d=u(),p=Oe(),m=Pe(),h=()=>{d.invalidateQueries({queryKey:$o})},g=()=>c(t.plateId),_=Wo(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:[_===null?e(`button`,{type:`button`,onClick:g,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(f,{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:_,alt:l(`detectionIntelligence.recentPlates.plateFrom`,`Plate {{text}} from {{cameraName}}`,{text:t.text,cameraName:n}),onClick:g,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(he,{className:`h-4 w-4 text-primary`}):a(G,{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(ge,{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:Xn(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(),p.mutate({plateId:t.plateId},{onSettled:h})},disabled:p.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:p.isPending?a(z,{className:`h-4 w-4 animate-spin`}):a(_e,{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(w,{className:`h-4 w-4`})}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),m.mutate({plateId:t.plateId},{onSettled:h})},disabled:m.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:m.isPending?a(z,{className:`h-4 w-4 animate-spin`}):a(v,{className:`h-4 w-4`})})]})]})}var rs=[{labelKey:`common.all`,value:`all`},{labelKey:`detectionIntelligence.recentPlates.filterUnassigned`,value:`unassigned`},{labelKey:`detectionIntelligence.recentPlates.filterAssigned`,value:`assigned`}];function is(e,t){return t===`unassigned`?e.filter(e=>!e.assigned):t===`assigned`?e.filter(e=>e.assigned):e}function as(){let{t}=X(),r=u(),[i,o]=s(`all`),[c,l]=s(Bn),[p,m]=s(new Set),[h,g]=s(new Set),[_,y]=s(null),[b,x]=s(null),{data:S,isLoading:C}=Se({limit:es,includeCrops:!1},{refetchInterval:3e4}),{data:T=[]}=ke(),{data:E}=we({isCamera:!0,projection:`slim`}),D=Oe(),O=Me(),k=Pe(),A=Date.now(),j=S??[],M=n(()=>{let e=new Map;for(let t of E??[])e.set(t.id,t.name);return e},[E]),N=e=>M.get(e)??t(`detectionIntelligence.cameraFallback`,{id:String(e)}),P=n(()=>qn(j).map(e=>({id:e,name:N(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[j,M]),F=n(()=>Kn(Gn(is(j,i),c),p),[j,i,c,p]),I=rr(F,ts,n(()=>JSON.stringify([i,c.fromMs,c.toMs,[...p].sort((e,t)=>e-t)]),[i,c.fromMs,c.toMs,p])),ee=n(()=>new Map(j.map(e=>[e.plateId,e])),[j]),L=b===null?null:ee.get(b)??null,R=()=>{r.invalidateQueries({queryKey:$o})},V=()=>g(new Set);function H(e){g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}let U=[...h],W=O.isPending||k.isPending,te=D.isPending||k.isPending;function ne(){U.length!==0&&O.mutate({plateIds:U},{onSettled:()=>{R(),V()}})}function G(){U.length!==0&&Promise.allSettled(U.map(e=>k.mutateAsync({plateId:e}))).then(()=>{R(),V()})}function re(e){x(null),y([e])}function ie(e){D.mutate({plateId:e},{onSettled:R}),x(null)}function K(e){k.mutate({plateId:e},{onSettled:R}),x(null)}let q=F.length!==j.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:rs.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(dr,{onChange:l}),a(lr,{cameras:P,selected:p,onChange:m}),!C&&a(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:q?t(`detectionIntelligence.recentPlates.ofPlates`,`{{value1}} of {{value2}} plates`,{value1:String(F.length),value2:String(j.length)}):t(`detectionIntelligence.recentPlates.plateCount`,{count:F.length})})]}),h.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:h.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[e(J,{variant:`primary`,onClick:()=>y(U),disabled:W,children:[a(w,{className:`h-3.5 w-3.5`}),` `,t(`common.assign`)]}),e(J,{variant:`secondary`,onClick:ne,disabled:W,children:[O.isPending?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(_e,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.recentPlates.detach`,`Detach`)]}),e(J,{variant:`secondary`,onClick:G,disabled:W,children:[a(v,{className:`h-3.5 w-3.5`}),` `,t(`common.delete`)]}),a(J,{variant:`ghost`,onClick:V,disabled:W,children:a(B,{className:`h-3.5 w-3.5`})})]})]}),C?a(nt,{status:`pending`,pendingMessage:`Loading plates…`,testId:`plates-grid`}):F.length===0?a(Te,{icon:f,title:j.length>0?t(`detectionIntelligence.recentPlates.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.recentPlates.noPlatesRecognizedYet`,`No plates recognized yet`),description:j.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(nt,{status:`ready`,testId:`plates-grid`,children:I.pageItems.map(e=>a(ns,{plate:e,cameraName:N(e.deviceId),nowMs:A,selected:h.has(e.plateId),onToggleSelect:H,onAssign:e=>y([e]),onOpenDetail:x},e.plateId))}),a(or,{currentPage:I.page,totalItems:I.totalItems,pageSize:I.pageSize,onPageChange:I.setPage,itemNoun:`plates`})]}),a(Qo,{plate:L,cameraName:L?N(L.deviceId):``,onClose:()=>x(null),onAssign:re,onUnassign:ie,onDelete:K,actionsPending:te}),a(Ko,{plateIds:_,vehicles:T,onDone:()=>{y(null),V()}})]})}l();var os=[[`plateGallery`]];function ss({vehicleId:t}){let{t:n}=X(),r=u(),{data:i,isLoading:o}=Ge({vehicleId:t}),s=We();function c(e){s.mutate({vehicleId:t,sampleId:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:os})}})}return o?e(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[a(z,{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(x,{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(B,{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 cs(t){return[{key:`vehicle`,header:Y.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(Yt,{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(x,{className:`h-4 w-4 text-foreground-subtle`})})})}),a(`span`,{className:`truncate text-sm font-medium text-foreground`,children:t.name})]})},{key:`samples`,header:Y.t(`detectionIntelligence.vehiclesList.plates`,`Plates`),align:`center`,nowrap:!0,sortValue:e=>e.sampleCount,render:e=>a(Ct,{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(qe,{variant:`ghost`,size:`sm`,icon:O,"aria-label":Y.t(`detectionIntelligence.vehiclesList.edit`,`Edit {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onEdit(n)}}),a(qe,{variant:`ghost`,size:`sm`,icon:v,"aria-label":Y.t(`detectionIntelligence.vehiclesList.delete`,`Delete {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onDelete(n)}})]})}]}function ls({mode:t,vehicle:n,onClose:r}){let{t:i}=X(),c=u(),[l,d]=s(t===`edit`?n?.name??``:``),f=je(),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:os})}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(_t,{open:!0,onClose:r,title:t===`new`?`Add vehicle`:`Edit ${n?.name??`vehicle`}`,icon:x,width:t===`edit`?`xl`:`lg`,testId:`vehicles-vehicle-form`,footer:e(J,{variant:`primary`,size:`sm`,type:`button`,onClick:y,disabled:_,children:[m?a(z,{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(Mt,{label:i(`detectionIntelligence.vehiclesList.name`,`Name`),required:!0,children:a(st,{value:l,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&y()},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(ss,{vehicleId:n.id})]})]})})}function us(){let{t}=X(),r=u(),i=ne(),{data:s,isLoading:c}=ke(),l=Be(),{state:d,openNew:f,openEdit:p,close:m}=ot(),h=s??[],g=it(h,{searchText:e=>[e.name]}),v=d.mode===`edit`?h.find(e=>e.id===d.id)??null:null;o(()=>{d.mode===`edit`&&!c&&v===null&&m()},[d.mode,c,v,m]);let y=n(()=>cs({onEdit:e=>p(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:os}),d.mode===`edit`&&d.id===e.id&&m()}})})()}}),[i,m,l,d,p,r,t]);if(c)return e(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[a(z,{className:`h-4 w-4 animate-spin`}),t(`detectionIntelligence.vehiclesList.loadingVehicles`,`Loading vehicles…`)]});let b=d.mode===`new`||d.mode===`edit`&&v!==null;return e(`div`,{className:`space-y-2`,children:[a(`div`,{className:`flex flex-wrap items-center gap-2`,children:e(J,{variant:`primary`,size:`sm`,type:`button`,onClick:f,children:[a(_,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.vehiclesList.addVehicle`,`Add vehicle`)]})}),(h.length>0||g.active)&&a(bt,{state:g.state,facets:g.facets,labels:{searchPlaceholder:`Search vehicles…`,searchLabel:`Search vehicles`,facetsLabel:`Filter`,clearLabel:`Clear`},onSearch:g.setSearch,onToggleFacet:g.toggleFacet,onClear:g.clear}),g.rows.length===0?a(Te,{icon:x,title:g.active?t(`detectionIntelligence.vehiclesList.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.vehiclesList.noVehiclesEnrolledYet`,`No vehicles enrolled yet`),description:g.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(Ve,{columns:y,rows:g.rows,rowKey:e=>e.id,maxBodyHeight:Ce,emptyMessage:t(`detectionIntelligence.vehiclesList.noVehiclesEnrolledYet2`,`No vehicles enrolled yet.`),onRowClick:e=>p(e.id)}),b&&a(ls,{mode:d.mode===`new`?`new`:`edit`,vehicle:v,onClose:m})]})}l();var ds=[[`plateGallery`]],fs=2e3;function ps(){let e=u(),n=t(e);n.current=e;let r=t(void 0);r.current||=Hr({delayMs:fs,invalidate:()=>{n.current.invalidateQueries({queryKey:ds})}}),o(()=>()=>r.current?.cancel(),[]),Pt(le.PipelineAnalyticsPlateGalleryChanged,()=>{r.current?.trigger()})}function ms(){let{t}=X();return ps(),e(`div`,{className:`space-y-3`,children:[a(Xe,{headingId:`library-vehicles`,title:t(`plates.vehicles`,`Vehicles`),icon:x,testId:`library-section-vehicles`,children:e(`div`,{className:`${p} 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(us,{})]})}),a(Xe,{headingId:`library-recent-plates`,title:t(`plates.recentRecognizedPlates`,`Recent recognized plates`),icon:fe,testId:`library-section-recent-plates`,children:e(`div`,{className:`${p} 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(as,{})]})})]})}function hs(e){return e.states.length===0?3:e.latched?0:e.verdict===`diverged`?1:e.verdict===`unknown`?2:4}function gs(e){let t=[e.divergedAt,e.restoredAt].filter(e=>typeof e==`number`);return t.length===0?null:Math.max(...t)}function _s(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=hs(e.monitor)-hs(t.monitor);if(n!==0)return n;let r=gs(e.monitor)??-1,i=gs(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 vs={alarm:`danger`,ok:`success`,unknown:`default`},ys={alarm:`Alarm`,ok:`OK`,unknown:`Unknown`};function bs(e,t){let n=gs(e);return n===null?`—`:Y.t(`scenes.transitionAgo`,{duration:re(Math.max(0,t-n))})}function xs(e){return P(e.monitor).tone}function Ss(e){let t=Number(e);return Number.isFinite(t)&&t>0?t:null}function Cs(){let{t}=X(),i=we({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=Jt(l),d=n(()=>_s(c,u.results),[c,u.results]),f=it(d,{searchText:e=>[e.monitor.label,e.deviceName],facetValue:xs}),{state:p,openNew:m,openEdit:h,close:g}=ot(),[v,y]=s(null);o(()=>{if(p.mode===`new`){y(e=>e??l[0]??null);return}y(null)},[p.mode,l]);let b=p.mode===`edit`?Ss(p.id):null,x=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=>xs(e),render:e=>{let t=P(e.monitor);return a(Ct,{variant:vs[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:R(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:V(e.monitor)})},{key:`transition`,header:t(`scenes.lastChange`,`Last change`),align:`right`,nowrap:!0,sortValue:e=>gs(e.monitor)??0,render:e=>a(`span`,{className:`text-xs tabular-nums text-foreground-muted`,children:bs(e.monitor,C)})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:e=>a(J,{variant:`ghost`,onClick:()=>h(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(J,{onClick:m,disabled:c.length===0,className:`shrink-0`,children:[a(_,{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||f.active)&&a(bt,{state:f.state,facets:f.facets,labels:{searchPlaceholder:`Search scenes…`,searchLabel:`Search scenes`,facetsLabel:`State`,clearLabel:`Clear`},facetLabel:e=>ys[e]??e,onSearch:f.setSearch,onToggleFacet:f.toggleFacet,onClear:f.clear}),a(Ze,{variant:`flat`,className:`p-0`,children:a(Ve,{columns:w,rows:f.rows,rowKey:e=>`${e.deviceId}:${e.monitor.id}`,minWidthPx:880,bordered:!1,maxBodyHeight:Ce,emptyMessage:u.isLoading?t(`scenes.loadingScenes`,`Loading scenes…`):f.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.`)})}),p.mode===`new`?e(_t,{open:!0,onClose:g,title:t(`scenes.whichCamera`,`Which camera?`),icon:S,width:`sm`,testId:`scenes-camera-picker`,footer:a(J,{onClick:()=>{v!==null&&h(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($e,{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(_t,{open:!0,onClose:g,title:t(`scenes.scenes`,`Scenes — {{editingName}}`,{editingName:x}),icon:S,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(Et,{deviceId:b})})]})]})}function ws(){let{t:e}=X(),t=It(`/library`,{t:e,isAdmin:!0})??{icon:ve,title:e(`nav.library`,`Library`)};return a(Vt,{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(Kr,{})},{id:`vehicles`,label:e(`library.vehicles`,`Vehicles`),content:a(ms,{})},{id:`events`,label:e(`library.events`,`Events`),content:a(Uo,{}),ownedParams:[`section`]},{id:`scenes`,label:e(`library.scenes`,`Scenes`),content:a(Cs,{})}]})}export{ws 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{Cr as f,D as p,Di as m,Ei as h,En as g,Fn as _,Ht as v,Ii as y,It as b,Mi as x,Ni as S,Nr as C,Nt as w,Oi as T,Q as E,Ti as D,Vn as O,Vr as k,Xr as A,Xt as j,Z as M,bn as N,c as P,ct as F,di as I,dt as ee,en as L,f as R,fr as z,gt as B,l as V,ot as H,ri as U,rn as W,sa as te,st as ne,tn as G,u as re,ur as ie,vn as K,wn as q,z as ae,zt as oe}from"./player-overlays-g9d3qYrr.js";import{Br as se,nt as ce,so as le}from"./client-CwJGlpR9.js";import{a as ue,c as de,i as fe,n as pe,o as me,r as he,s as ge,t as _e}from"./user-x-BRStn-V-.js";import{c as ve}from"./video-BFmrpvc7.js";import{t as ye}from"./crop-DKZuvuZ0.js";import{t as be}from"./user-round-Z0QH_kjR.js";import{Ac as xe,Bl as Se,Cn as Ce,Do as we,Er as Te,Fi as Ee,Fl as De,Gl as Oe,Hl as ke,Ic as Ae,Il as je,Kl as Me,Lc as Ne,Ll as Pe,Mc as Fe,Oc as Ie,Pc as Le,Pl as Re,Qn as ze,Rl as Be,Sn as Ve,Td as He,Tr as Ue,Ul as We,Vl as Ge,Wl as Ke,Yr as J,_d as qe,_r as Je,_s as Ye,bn as Xe,br as Ze,cs as Qe,dd as $e,dr as et,ds as tt,dt as nt,fc as rt,fn as it,fs as at,ft as ot,gd as st,gr as ct,gs as lt,hn as ut,hr as dt,hs as ft,jc as pt,ls as mt,mr as ht,ms as gt,mt as _t,ni as vt,od as yt,pn as bt,pr as xt,ps as St,ri as Ct,sd as wt,ss as Tt,t as Et,ti as Dt,tn as Ot,un as kt,us as At,vs as jt,xt as Mt,ys as Nt,zd as Pt,zl as Ft}from"./src-DwNoxp86.js";import{t as Y}from"./i18n-9jE1YKjd.js";import{t as X}from"./useTranslation-BJr-n0es.js";import"./mount-BTGIE40h.js";import{T as It,_r as Lt,hr as Rt,pr as zt,yr as Bt}from"./index-DG07MiZm.js";import{t as Vt}from"./AdminSectionedPage-BZCKp3Ch.js";import{t as Ht}from"./use-stationary-objects-Drf9XXJR.js";import{a as Ut,i as Wt,n as Gt,r as Kt,t as qt}from"./authed-media-BZXVXyjI.js";import{t as Jt}from"./use-scenes-feed-B_j7CFbm.js";l();function Yt({mediaId:e,base64:t,alt:n,className:r,placeholder:i}){let{src:o,failed:s}=Ut(e===void 0?void 0:Kt(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 Xt=`pipeline-analytics`,Zt=`photo.analyze`,Qt=`photo.enroll`,$t=`photo.discard`,en=18*1024*1024;function tn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function nn(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function rn(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function an(e,t){let n=e[t];return typeof n==`boolean`?n:null}function on(e){if(!tn(e))return null;let t=rn(e,`x`),n=rn(e,`y`),r=rn(e,`width`),i=rn(e,`height`);return t===null||n===null||r===null||i===null?null:{x:t,y:n,width:r,height:i}}function sn(e){if(!tn(e))return null;let t=rn(e,`detectionShortSidePx`),n=rn(e,`score`);if(t===null||n===null)return null;let r=rn(e,`magnitude`);return{detectionShortSidePx:t,score:n,...r===null?{}:{magnitude:r}}}function cn(e){if(!tn(e))return null;let t=rn(e,`faceIndex`),n=rn(e,`score`),r=an(e,`enrollable`),i=on(e.bbox),a=sn(e.quality);if(t===null||n===null||r===null||i===null||a===null)return null;let o=nn(e,`refusedReason`),s=nn(e,`alignedCropBase64`),c=nn(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 ln(e){if(!tn(e))return null;let t=nn(e,`sessionId`),n=nn(e,`ranOnNodeId`),r=e.faces;if(t===null||n===null||!Array.isArray(r))return null;let i=[];for(let e of r){let t=cn(e);t!==null&&i.push(t)}return{sessionId:t,ranOnNodeId:n,faces:i}}function un(e){if(!tn(e))return null;let t=nn(e,`sampleId`),n=nn(e,`identityId`),r=nn(e,`modelId`);return t===null||n===null||r===null?null:{sampleId:t,identityId:n,modelId:r}}function dn(e,t,n){let r={...e};return n===null||n===``?delete r[t]:r[t]=n,r}function fn(e,t){return e.filter(e=>e.enrollable&&t[e.faceIndex]!==void 0).length}function pn(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 mn(e){switch(e){case`no-embedding`:return Y.t(`helpers.photoEnroll.refusal.noEmbedding`);case`no-model-id`:return Y.t(`helpers.photoEnroll.refusal.noModelId`);case`no-aligned-crop`:return Y.t(`helpers.photoEnroll.refusal.noAlignedCrop`);case`magnitude`:return Y.t(`helpers.photoEnroll.refusal.magnitude`);default:return Y.t(`helpers.photoEnroll.refusal.default`)}}function hn(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 gn(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 _n(e,t,n){return e.map(e=>e.photoIndex===t?{...e,...n}:e)}function vn(e,t){return`${e}:${t}`}function yn(e,t,n,r){let i=dn(e[t]??{},n,r),a={...e};return Object.keys(i).length===0?delete a[t]:a[t]=i,a}function bn(e,t){let n=0;for(let r of e)r.analysis!==void 0&&(n+=fn(r.analysis.faces,t[r.photoIndex]??{}));return n}var xn=`__new__`;function Sn(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[vn(i.photoIndex,t.faceIndex)]??``).trim();if(a===``)return{kind:`error`,message:Y.t(`helpers.photoEnrollBatch.newPersonNoName`,{filename:i.filename,face:t.faceIndex+1})};r.includes(a)||r.push(a)}}return{kind:`ok`,names:r}}function Cn(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[vn(e,a)]??``).trim()];s!==void 0&&(o[a]=s)}r[e]=o}return r}function wn(e,t){let n=[];for(let r of e){if(r.analysis===void 0)continue;let e=pn(r.analysis.sessionId,r.analysis.faces,t[r.photoIndex]??{});for(let t of e)n.push({photoIndex:r.photoIndex,request:t})}return n}function Tn(e){return/expired/i.test(e)}function En(e){return e instanceof Error?e.message:String(e)}async function Dn(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??Y.t(`helpers.photoEnrollBatch.photoFallback`,{n:e+1});return Y.t(`helpers.photoEnrollBatch.faceLabel`,{filename:n,face:t+1})};for(let l of wn(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=En(t);if(!Tn(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 (${En(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)}: ${En(e)}`)}}}return{enrolled:o,stampedModelId:s,failures:a,refreshedAnalyses:i}}var On=[[`faceGallery`]],kn=``;function An(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 jn(e){return e instanceof Error?e.message:String(e)}function Mn({face:t,identities:r,value:i,onChange:o,disabled:s}){let{t:c}=X(),l=n(()=>[{value:kn,label:c(`detectionIntelligence.photoEnrollDialog.ignoreThisFace`,`Ignore this face`)},...r.map(e=>({value:e.id,label:e.name})),{value:xn,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(be,{className:`h-8 w-8`})})}),a(`div`,{className:`min-h-[4.75rem]`,children:t.enrollable?e(d,{children:[a($e,{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(Ct,{variant:`warning`,className:`text-[10px]`,children:c(`detectionIntelligence.photoEnrollDialog.notUsable`,`Not usable`)}),a(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:mn(t.refusedReason)})]})})]})}function Nn({photo:t,identities:n,draft:r,newNames:i,disabled:o,onAssign:s,onNameChange:c,onRetry:l}){let{t:u}=X(),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(z,{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(J,{variant:`secondary`,size:`sm`,disabled:o,onClick:l,children:[a(q,{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(oe,{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(Mn,{face:e,identities:n,value:f[e.faceIndex]??kn,disabled:o,onChange:t=>s(e.faceIndex,t)},e.faceIndex))}),d.filter(e=>f[e.faceIndex]===xn).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[vn(t.photoIndex,n.faceIndex)]??``,onChange:e=>c(n.faceIndex,e.target.value)})]},n.faceIndex))]})}function Pn({open:r,onOpenChange:o}){let{t:c}=X(),l=ee(),d=u(),f=t(null),{data:p}=at(),m=Qe(),[h,g]=s([]),[_,v]=s(!1),[y,b]=s(null),[x,S]=s({}),[C,w]=s({}),[T,E]=s(null),D=n(()=>(p??[]).map(e=>({id:e.id,name:e.name})),[p]),O=h.some(e=>e.status===`queued`||e.status===`analyzing`),k=O||_,A=i(e=>{for(let t of e){let e=t.analysis?.sessionId;e!==void 0&&l.trpcClient.addons.custom.mutate({addonId:Xt,action:$t,input:{sessionId:e}}).catch(()=>void 0)}},[l]),j=i(()=>{g([]),S({}),w({}),b(null),E(null),f.current&&(f.current.value=``)},[]),M=i(()=>{A(h),j(),o(!1)},[A,o,h,j]),N=i(async e=>{let t=ln(await l.trpcClient.addons.custom.mutate({addonId:Xt,action:Zt,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]),P=i(async e=>{g(t=>_n(t,e.photoIndex,{status:`analyzing`,error:void 0}));try{let t=await N(e);g(n=>_n(n,e.photoIndex,{status:`analyzed`,analysis:t}))}catch(t){g(n=>_n(n,e.photoIndex,{status:`failed`,error:jn(t)}))}},[N]),F=i(async e=>{if(e.length===0)return;A(h),j();let t=hn(e,{maxCount:12,maxBytes:en}),n=[];t.oversize.length>0&&n.push(`Over the ${Math.round(en/(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 An(e),status:`queued`})))}catch(e){b(jn(e));return}g(r),await gn(r,2,e=>P(e))},[A,h,j,P]),I=bn(h,x),L=i(async()=>{v(!0),b(null),E(null);try{let e=Sn(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 Dn(h,Cn(x,C,t),{enroll:async e=>{let t=un(await l.trpcClient.addons.custom.mutate({addonId:Xt,action:Qt,input:e}));if(t===null)throw Error(`unreadable reply`);return t},reanalyze:e=>N(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:On}),n.failures.length>0&&b(n.failures.join(` · `)),E(n.enrolled===0?`Nothing was enrolled.`:`Enrolled ${n.enrolled} sample${n.enrolled===1?``:`s`}${n.stampedModelId===null?``:` with ${n.stampedModelId}`}.`)}catch(e){b(jn(e))}finally{v(!1)}},[N,m,x,C,h,d,l]),R=h.filter(e=>e.status===`analyzed`).length;return a(et,{open:r,onOpenChange:e=>e?o(!0):M(),children:e(xt,{className:`max-w-3xl`,children:[e(ct,{children:[a(Je,{children:c(`detectionIntelligence.photoEnrollDialog.enrolFromPhotos`,`Enrol from photos`)}),a(ht,{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(zt,{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 F(Array.from(e.target.files??[]))}),e(J,{variant:`secondary`,size:`sm`,disabled:k,onClick:()=>f.current?.click(),children:[O?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(me,{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:R,count:h.length})})]}),a(`div`,{className:`min-h-11`,"aria-live":`polite`,children:y===null?T===null?null:a(`div`,{className:`rounded-md border border-success/40 bg-success/10 px-3 py-2 text-xs text-success`,children:T}):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(oe,{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(Nn,{photo:e,identities:D,draft:x,newNames:C,disabled:k,onAssign:(t,n)=>S(r=>yn(r,e.photoIndex,t,n===kn?null:n)),onNameChange:(t,n)=>w(r=>({...r,[vn(e.photoIndex,t)]:n})),onRetry:()=>void P(e)},e.photoIndex))}),e(dt,{children:[a(J,{variant:`secondary`,onClick:M,disabled:_,children:c(`common.close`,`Close`)}),e(J,{variant:`primary`,onClick:()=>void L(),disabled:k||I===0,children:[_?a(z,{className:`h-3.5 w-3.5 animate-spin`}):null,c(`detectionIntelligence.photoEnrollDialog.enrolFaces`,{count:I})]})]})]})})}l();var Fn=[[`faceGallery`]];function In({identityId:t}){let{t:n}=X(),r=u(),{data:i,isLoading:o}=St({identityId:t}),s=ft();function c(e){s.mutate({identityId:t,sampleId:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:Fn})}})}return o?e(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[a(z,{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(be,{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(me,{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(B,{className:`h-4 w-4 text-white`})})]},t.id))})}function Ln(t){return[{key:`person`,header:Y.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(Yt,{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(be,{className:`h-4 w-4 text-foreground-subtle`})})})}),a(`span`,{className:`truncate text-sm font-medium text-foreground`,children:t.name})]})},{key:`samples`,header:Y.t(`detectionIntelligence.peopleList.samples`,`Samples`),align:`center`,nowrap:!0,sortValue:e=>e.sampleCount,render:e=>a(Ct,{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(qe,{variant:`ghost`,size:`sm`,icon:O,"aria-label":Y.t(`detectionIntelligence.peopleList.edit`,`Edit {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onEdit(n)}}),a(qe,{variant:`ghost`,size:`sm`,icon:v,"aria-label":Y.t(`detectionIntelligence.peopleList.delete`,`Delete {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onDelete(n)}})]})}]}function Rn({mode:t,identity:n,onClose:r}){let{t:i}=X(),c=u(),[l,d]=s(t===`edit`?n?.name??``:``),f=Qe(),p=lt();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:Fn})}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(_t,{open:!0,onClose:r,title:t===`new`?`Add person`:`Edit ${n?.name??`person`}`,icon:be,width:t===`edit`?`xl`:`lg`,testId:`people-person-form`,footer:e(J,{variant:`primary`,size:`sm`,type:`button`,onClick:y,disabled:_,children:[m?a(z,{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(Mt,{label:i(`detectionIntelligence.peopleList.name`,`Name`),required:!0,children:a(st,{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(In,{identityId:n.id})]})]})})}function zn(){let{t}=X(),r=u(),i=ne(),{data:c,isLoading:l}=at(),d=At(),{state:f,openNew:p,openEdit:m,close:h}=ot(),[g,v]=s(!1),y=c??[],b=it(y,{searchText:e=>[e.name]}),x=f.mode===`edit`?y.find(e=>e.id===f.id)??null:null;o(()=>{f.mode===`edit`&&!l&&x===null&&h()},[f.mode,l,x,h]);let S=n(()=>Ln({onEdit:e=>m(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:Fn}),f.mode===`edit`&&f.id===e.id&&h()}})})()}}),[i,h,d,f,m,r,t]);if(l)return e(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[a(z,{className:`h-4 w-4 animate-spin`}),t(`detectionIntelligence.peopleList.loadingPeople`,`Loading people…`)]});let C=f.mode===`new`||f.mode===`edit`&&x!==null;return e(`div`,{className:`space-y-2`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(J,{variant:`primary`,size:`sm`,type:`button`,onClick:p,children:[a(_,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.peopleList.addPerson`,`Add person`)]}),e(J,{variant:`secondary`,size:`sm`,type:`button`,onClick:()=>v(!0),children:[a(me,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.peopleList.enrolFromAPhoto`,`Enrol from a photo`)]})]}),(y.length>0||b.active)&&a(bt,{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:be,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(Ve,{columns:S,rows:b.rows,rowKey:e=>e.id,maxBodyHeight:Ce,emptyMessage:t(`detectionIntelligence.peopleList.noPeopleEnrolledYet2`,`No people enrolled yet.`),onRowClick:e=>m(e.id)}),C&&a(Rn,{mode:f.mode===`new`?`new`:`edit`,identity:x,onClose:h}),a(Pn,{open:g,onOpenChange:v})]})}var Bn={fromMs:null,toMs:null},Vn=36e5,Hn=24*Vn;function Un(e,t){switch(e){case`24h`:return{fromMs:t-Hn,toMs:null};case`7d`:return{fromMs:t-7*Hn,toMs:null};case`30d`:return{fromMs:t-30*Hn,toMs:null};case`all`:return Bn}}function Wn(e){return e.fromMs!==null||e.toMs!==null}function Gn(e,t){return Wn(t)?e.filter(e=>!(t.fromMs!==null&&e.timestamp<t.fromMs||t.toMs!==null&&e.timestamp>t.toMs)):[...e]}function Kn(e,t){return t.size===0?[...e]:e.filter(e=>t.has(e.deviceId))}function qn(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 Jn(e){if(!e)return null;let t=Date.parse(`${e}T00:00:00`);return Number.isNaN(t)?null:t}function Yn(e){if(!e)return null;let t=Date.parse(`${e}T23:59:59.999`);return Number.isNaN(t)?null:t}function Xn(e,t){if(!Number.isFinite(e)||e<=0)return`—`;let n=t-e;return n<6e4?Y.t(`helpers.relativeTime.justNow`):n<Vn?Y.t(`helpers.relativeTime.minutesAgo`,{count:Math.floor(n/6e4)}):n<Hn?Y.t(`helpers.relativeTime.hoursAgo`,{count:Math.floor(n/Vn)}):n<7*Hn?Y.t(`helpers.relativeTime.daysAgo`,{count:Math.floor(n/Hn)}):new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function Zn(e){return!Number.isFinite(e)||e<=0?`—`:new Date(e).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function Qn(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 $n(e){let t=e.cropUrl!==void 0&&e.cropUrl.length>0,n=e.base64!==void 0&&e.base64.length>0;return!t&&!n}function er(e){return e.filter($n).map(e=>e.faceId)}function tr(e){let t=0;for(let n of e)$n(n)&&(t+=1);return t}function nr(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 rr(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 ir=2;function ar(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-ir),i=Math.min(t-1,e+ir);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 or({currentPage:t,totalItems:n,pageSize:r,onPageChange:i,itemNoun:o=`items`}){let{t:s}=X();if(n<=r)return null;let c=Math.ceil(n/r),l=(t-1)*r+1,u=Math.min(t*r,n),d=ar(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(h,{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(D,{className:`h-3.5 w-3.5`})})]})]})}l();var sr=[[`faceGallery`]];function cr({faceIds:t,identities:n,onDone:r}){let{t:i}=X(),o=u(),c=Tt(),l=Qe(),[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:sr}),b()}})}function S(){!t||!d.trim()||l.mutate({name:d.trim()},{onSuccess:e=>{e?.id&&x(e.id)},onError:()=>{o.invalidateQueries({queryKey:sr}),b()}})}let C=c.isPending||l.isPending;return a(et,{open:_,onOpenChange:e=>!e&&b(),children:e(xt,{children:[e(ct,{children:[a(Je,{children:v>1?i(`detectionIntelligence.assignDialog.assignFacesToPerson`,`Assign {{value1}} faces to person`,{value1:String(v)}):i(`detectionIntelligence.assignDialog.assignFaceToPerson`,`Assign face to person`)}),a(ht,{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(st,{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(dt,{className:`min-h-[2.75rem]`,children:[a(J,{variant:`secondary`,onClick:b,disabled:C,children:i(`common.cancel`,`Cancel`)}),p?e(J,{variant:`primary`,onClick:S,disabled:C||!d.trim(),children:[C&&a(z,{className:`h-3.5 w-3.5 animate-spin`}),i(`detectionIntelligence.assignDialog.createAssign`,`Create & assign`)]}):e(J,{variant:`primary`,onClick:()=>h&&x(h),disabled:C||!h,children:[C&&a(z,{className:`h-3.5 w-3.5 animate-spin`}),v>1?i(`detectionIntelligence.assignCount`,{count:v}):i(`common.assign`)]})]})]})})}l();function lr({cameras:n,selected:r,onChange:i}){let{t:c}=X(),[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 p=r.size,h=p===0?`All cameras`:p===1?n.find(e=>r.has(e.id))?.name??`1 camera`:`${String(p)} 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 ${p>0?`border-primary/40 bg-primary/8 text-primary`:`border-border text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(S,{className:`h-3.5 w-3.5`}),a(`span`,{className:`max-w-[10rem] truncate`,children:h}),a(m,{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:[p>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(T,{className:`h-2.5 w-2.5`})}),a(`span`,{className:`truncate`,children:t.name})]},t.id)})]})]})}l();var ur=[{label:`24h`,value:`24h`},{label:`7d`,value:`7d`},{label:`30d`,value:`30d`},{labelKey:`common.all`,value:`all`}];function dr({onChange:t}){let{t:n}=X(),[r,i]=s(`all`),[o,c]=s(``),[l,u]=s(``);function d(e){i(e),c(``),u(``),t(Un(e,Date.now()))}function f(e,n){i(`custom`),c(e),u(n),t({fromMs:Jn(e),toMs:Yn(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:ur.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 fr(e){return e<0?0:e>1?1:e}function pr(e,t,n){if(!Number.isFinite(t)||!Number.isFinite(n)||t<=0||n<=0)return null;let r=fr(e.x/t),i=fr(e.y/n),a=fr((e.x+e.w)/t),o=fr((e.y+e.h)/n);return{x:r,y:i,width:Math.max(0,a-r),height:Math.max(0,o-i)}}l();var mr=2.6;function hr({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(mr)})`:`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 gr(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 Gt(Kt(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 _r(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 vr({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 yr({box:e}){let{t}=X();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 br({face:t,cameraName:r,onClose:i,onAssign:o,onUnassign:c,onDelete:l,actionsPending:u}){let{t:d}=X(),{data:p,isFetching:m}=tt({faceId:t?.faceId??``},{enabled:t!==null}),[h,g]=s(`frame`),{frameSrc:_,naturalWidth:y,naturalHeight:b,failed:x}=gr(t?.keyFrameMediaId),S=n(()=>{let e=_r(p??[]);return e?e.url:nr(t)},[p,t]),C=n(()=>!t?.faceBbox||y===null||b===null?null:pr(t.faceBbox,y,b),[t?.faceBbox,y,b]);if(t===null)return null;let T=t.keyFrameMediaId!==void 0&&!x,E=T&&h===`frame`,D=t.assigned?t.identityName??`Assigned`:t.recognizedIdentityId?`${t.identityName??`Recognized`} (suggested)`:`Unassigned`;return a(et,{open:!0,onOpenChange:e=>!e&&i(),children:e(xt,{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:[T&&e(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[e(`button`,{type:`button`,onClick:()=>g(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${h===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(N,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.fullFrame`)]}),e(`button`,{type:`button`,onClick:()=>g(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${h===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(ye,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.crop`)]})]}),E&&_?a(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:a(hr,{src:_,alt:d(`detectionIntelligence.faceDetailPanel.fullFrameWithDetectedFace`,`Full frame with detected face`),fit:`natural`,className:`w-full`,overlay:C?a(yr,{box:C}):void 0})}):S?e(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[a(hr,{src:S,alt:d(`detectionIntelligence.faceDetailPanel.detectedFace`,`Detected face`),className:`h-full w-full`}),m&&a(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:a(z,{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(f,{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(vr,{label:d(`detectionIntelligence.faceDetailPanel.camera`,`Camera`),value:r}),a(vr,{label:d(`detectionIntelligence.faceDetailPanel.captured`,`Captured`),value:Qn(t.timestamp)}),a(vr,{label:d(`detectionIntelligence.faceDetailPanel.track`,`Track`),value:t.trackId}),a(vr,{label:d(`detectionIntelligence.faceDetailPanel.identity`,`Identity`),value:D})]})]}),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(J,{variant:`secondary`,onClick:()=>c(t.faceId),disabled:u,children:[a(_e,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.detach`)]}):e(J,{variant:`primary`,onClick:()=>o(t.faceId),disabled:u,children:[a(w,{className:`h-3.5 w-3.5`}),` `,d(`common.assign`)]}),e(J,{variant:`secondary`,onClick:()=>l(t.faceId),disabled:u,children:[a(v,{className:`h-3.5 w-3.5`}),` `,d(`common.delete`)]})]})]})})}function xr(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function Sr(e,t){return e.faceIds.filter(e=>!t.has(e))}function Cr(e,t){return e.faceIds.filter(e=>t(e))}l();var wr=[[`faceGallery`]],Tr=20,Er=.3,Dr=.9,Or=.05,kr=.5,Ar=2,jr=10,Mr=2;function Nr({cluster:t,face:n,active:r,onSelect:i}){let{t:o}=X(),s=nr(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(f,{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 Pr({face:t,cameraName:n,nowMs:r,excluded:i,onToggleExclude:o,onDelete:s,deletePending:c}){let{t:l}=X(),u=nr(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(f,{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(hr,{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?b:B,{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:Xn(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(z,{className:`h-4 w-4 animate-spin`}):a(v,{className:`h-4 w-4`})})})]})}function Fr({open:t,onClose:r,byId:i,cameraName:c,nowMs:l,identities:f,selectMany:p}){let{t:m}=X(),h=u(),_=ne(),v=mt(),[y,b]=s(kr),[x,S]=s(Mr),[C,T]=s(null),[E,D]=s({}),[O,k]=s(null),{data:A,isFetching:j,refetch:M}=Ye({threshold:y,minClusterSize:x,limit:Tr},{enabled:t}),N=A??[];o(()=>{D({})},[y,x]),o(()=>{if(N.length===0){T(null);return}N.some(e=>e.representativeFaceId===C)||T(N[0]?.representativeFaceId??null)},[N]);let P=n(()=>N.find(e=>e.representativeFaceId===C)??null,[N,C]),F=P?E[P.representativeFaceId]??new Set:new Set,I=n(()=>P?Cr(P,e=>i.has(e)):[],[P,i]),ee=P?P.faceIds.length-I.length:0,L=P?Sr({...P,faceIds:I},F):[];function R(e){if(!P)return;let t=P.representativeFaceId;D(n=>({...n,[t]:xr(n[t]??new Set,e)}))}function B(){h.invalidateQueries({queryKey:wr})}async function V(e){await _({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`})&&v.mutate({faceId:e},{onSettled:B})}function H(){k(null),r()}function U(){L.length!==0&&(p(L),H())}return e(et,{open:t,onOpenChange:e=>!e&&H(),children:[e(xt,{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(W,{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:Er,max:Dr,step:Or,value:y,onChange:e=>b(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:y.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:Ar,max:jr,step:1,value:x,onChange:e=>S(Math.min(jr,Math.max(Ar,Number(e.target.value)||Ar))),className:`w-12 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`})]}),e(J,{variant:`secondary`,onClick:()=>{D({}),M()},disabled:j,children:[j?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(g,{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(z,{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(Nr,{cluster:e,face:i.get(e.representativeFaceId),active:e.representativeFaceId===C,onSelect:()=>T(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(Nr,{cluster:e,face:i.get(e.representativeFaceId),active:e.representativeFaceId===C,onSelect:()=>T(e.representativeFaceId)},e.representativeFaceId))}),a(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:P&&e(d,{children:[ee>0&&a(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:m(`detectionIntelligence.similarGroupsModal.hiddenCount`,{count:ee})}),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(Pr,{face:t,cameraName:c(t.deviceId),nowMs:l,excluded:F.has(e),onToggleExclude:()=>R(e),onDelete:()=>void V(e),deletePending:v.isPending&&v.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(J,{variant:`secondary`,onClick:U,disabled:L.length===0,children:m(`detectionIntelligence.similarGroupsModal.selectInGallery`,`Select in gallery`)}),e(J,{variant:`primary`,onClick:()=>k(L),disabled:L.length===0,children:[a(w,{className:`h-3.5 w-3.5`}),` `,m(`detectionIntelligence.similarGroupsModal.adopt`,{count:L.length})]})]})]}),a(cr,{faceIds:O,identities:f,onDone:()=>k(null)})]})}l();var Ir=[[`faceGallery`]],Lr=500,Rr=120;function zr({face:t,cameraName:n,nowMs:r,selected:i,onToggleSelect:o,onAssign:s,onOpenDetail:c}){let{t:l}=X(),d=u(),p=jt(),m=mt(),h=()=>{d.invalidateQueries({queryKey:Ir})},g=()=>c(t.faceId),_=nr(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:[_===null?e(`button`,{type:`button`,onClick:g,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(f,{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:_,alt:l(`detectionIntelligence.unassignedFaces.faceFrom`,`Face from {{cameraName}}`,{cameraName:n}),onClick:g,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(he,{className:`h-4 w-4 text-primary`}):a(G,{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:Xn(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(),p.mutate({faceId:t.faceId},{onSettled:h})},disabled:p.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:p.isPending?a(z,{className:`h-4 w-4 animate-spin`}):a(_e,{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(w,{className:`h-4 w-4`})}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),m.mutate({faceId:t.faceId},{onSettled:h})},disabled:m.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:m.isPending?a(z,{className:`h-4 w-4 animate-spin`}):a(v,{className:`h-4 w-4`})})]})]})}var Br=[{labelKey:`common.all`,value:`all`},{labelKey:`detectionIntelligence.unassignedFaces.filterUnassigned`,value:`unassigned`},{labelKey:`detectionIntelligence.unassignedFaces.filterRecognized`,value:`recognized`}];function Vr(){let{t}=X(),r=u(),[i,o]=s(`all`),[c,l]=s(Bn),[p,m]=s(new Set),[h,g]=s(new Set),[_,y]=s(null),[b,x]=s(!1),[S,C]=s(null),{data:T,isLoading:E}=gt({limit:Lr,filter:i,includeCrops:!1},{refetchInterval:3e4}),{data:D=[]}=at(),{data:O}=we({isCamera:!0,projection:`slim`}),k=Tt(),A=jt(),j=Nt(),M=mt(),N=Date.now(),P=T??[],F=n(()=>{let e=new Map;for(let t of O??[])e.set(t.id,t.name);return e},[O]),I=e=>F.get(e)??t(`detectionIntelligence.cameraFallback`,{id:String(e)}),ee=n(()=>qn(P).map(e=>({id:e,name:I(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[P,F]),L=n(()=>Kn(Gn(P,c),p),[P,c,p]),R=rr(L,Rr,n(()=>JSON.stringify([i,c.fromMs,c.toMs,[...p].sort((e,t)=>e-t)]),[i,c.fromMs,c.toMs,p])),V=n(()=>new Map(P.map(e=>[e.faceId,e])),[P]),H=n(()=>tr(L),[L]),U=S===null?null:V.get(S)??null,te=()=>{r.invalidateQueries({queryKey:Ir})},ne=()=>g(new Set);function G(e){g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function re(e){g(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function ie(){re(er(L))}let K=[...h],q=k.isPending||j.isPending||M.isPending,ae=A.isPending||M.isPending;function oe(){K.length!==0&&j.mutate({faceIds:K},{onSettled:()=>{te(),ne()}})}function se(){K.length!==0&&Promise.allSettled(K.map(e=>M.mutateAsync({faceId:e}))).then(()=>{te(),ne()})}function ce(e){C(null),y([e])}function le(e){A.mutate({faceId:e},{onSettled:te}),C(null)}function ue(e){M.mutate({faceId:e},{onSettled:te}),C(null)}let de=L.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:Br.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(dr,{onChange:l}),a(lr,{cameras:ee,selected:p,onChange:m}),e(`button`,{type:`button`,onClick:()=>x(!0),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${b?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(W,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.similarGroups`)]}),!E&&H>0&&e(`button`,{type:`button`,onClick:ie,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(f,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.selectCropless`,{count:H})]}),!E&&a(`span`,{className:`text-[10px] text-foreground-subtle ${H>0?`ml-2`:`ml-auto`}`,children:de?t(`detectionIntelligence.unassignedFaces.ofFaces`,`{{value1}} of {{value2}} faces`,{value1:String(L.length),value2:String(P.length)}):t(`detectionIntelligence.unassignedFaces.faceCount`,{count:L.length})})]}),h.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:h.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[e(J,{variant:`primary`,onClick:()=>y(K),disabled:q,children:[a(w,{className:`h-3.5 w-3.5`}),` `,t(`common.assign`)]}),e(J,{variant:`secondary`,onClick:oe,disabled:q,children:[j.isPending?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(_e,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.detach`,`Detach`)]}),e(J,{variant:`secondary`,onClick:se,disabled:q,children:[a(v,{className:`h-3.5 w-3.5`}),` `,t(`common.delete`)]}),a(J,{variant:`ghost`,onClick:ne,disabled:q,children:a(B,{className:`h-3.5 w-3.5`})})]})]}),E?a(nt,{status:`pending`,pendingMessage:`Loading faces…`,testId:`faces-grid`}):L.length===0?a(Te,{icon:f,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(nt,{status:`ready`,testId:`faces-grid`,className:`grid-cols-[repeat(auto-fill,minmax(6.5rem,6.5rem))] justify-start`,children:R.pageItems.map(e=>a(zr,{face:e,cameraName:I(e.deviceId),nowMs:N,selected:h.has(e.faceId),onToggleSelect:G,onAssign:e=>y([e]),onOpenDetail:C},e.faceId))}),a(or,{currentPage:R.page,totalItems:R.totalItems,pageSize:R.pageSize,onPageChange:R.setPage,itemNoun:`faces`})]}),a(br,{face:U,cameraName:U?I(U.deviceId):``,onClose:()=>C(null),onAssign:ce,onUnassign:le,onDelete:ue,actionsPending:ae}),a(cr,{faceIds:_,identities:D,onDone:()=>{y(null),ne()}}),a(Fr,{open:b,onClose:()=>x(!1),byId:V,cameraName:I,nowMs:N,identities:D,selectMany:re})]})}function Hr(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 Ur=[[`faceGallery`]],Wr=2e3;function Gr(){let e=u(),n=t(e);n.current=e;let r=t(void 0);r.current||=Hr({delayMs:Wr,invalidate:()=>{n.current.invalidateQueries({queryKey:Ur})}}),o(()=>()=>r.current?.cancel(),[]),Pt(le.PipelineAnalyticsFaceGalleryChanged,()=>{r.current?.trigger()})}function Kr(){let{t}=X();return Gr(),e(`div`,{className:`space-y-3`,children:[a(Xe,{headingId:`library-people`,title:t(`detectionIntelligence.people`,`People`),icon:be,testId:`library-section-people`,children:e(`div`,{className:`${p} 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(zn,{})]})}),a(Xe,{headingId:`library-recent-faces`,title:t(`detectionIntelligence.recentDetectedFaces`,`Recent detected faces`),icon:ue,testId:`library-section-recent-faces`,children:e(`div`,{className:`${p} 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(Vr,{})]})})]})}function qr(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 Jr=720*60*60*1e3;function Yr(e){let t=[];for(let n of e)t.push(...n);return t}function Xr(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function Zr(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 Qr(e,t){return`${String(e)}:${t}`}function $r(e,t){let n=new Map,r=new Set;for(let i of e){let e=Qr(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 ei(e,t){return{since:e.fromMs??t-Jr,until:e.toMs??t}}var ti=[`native`,`raster`,`standin`];function ni(e){return ti.some(t=>t===e)}function ri(e){return e===`standin`?{label:Y.t(`helpers.mediaProvenance.standin.label`),title:Y.t(`helpers.mediaProvenance.standin.title`),tone:`warning`}:{label:Y.t(`helpers.mediaProvenance.raster.label`),title:Y.t(`helpers.mediaProvenance.raster.title`),tone:`info`}}function ii(e){return e===`standin`?ri(`standin`):e===`raster`?ri(`raster`):null}var ai={"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 oi(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=ai[r];return{sentence:a===void 0?r:Y.t(a),detail:i,raw:t}}function si(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 ci({row:t,cameraName:n,nowMs:r,onOpenDetail:i,selected:o=!1,onToggleSelect:s,score:c,provenance:l,footer:u}){let{t:d}=X(),p=Ut(t.mediaId===void 0?Wt(`track`,t.trackId):Kt(t.mediaId)),m=Math.round(t.importance*100),h=c===void 0?void 0:Math.round(c*100),g=si(t.windowMs),_=()=>i(t),v=ii(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:[p.src?a(`img`,{src:p.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:p.failed?d(`detectionIntelligence.eventCard.keyEventMediaUnavailable`,`Key-event media unavailable`):d(`detectionIntelligence.eventCard.noKeyEventMedia`,`No key-event media`),children:a(f,{className:`h-6 w-6 opacity-60`})}),s&&a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s(Qr(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(he,{className:`h-4 w-4 text-primary`}):a(G,{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(C,{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(T,{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(y,{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(L,{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,qr(t)?e(`span`,{className:`text-foreground-subtle`,children:[` · `,qr(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:Xn(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 li=1400,ui=`Admin-gated URL — opens only inside an authenticated session`;function di({label:t,value:n,title:r}){let{t:c}=X(),[l,u]=s(!1),d=F();return o(()=>{if(!l)return;let e=setTimeout(()=>u(!1),li);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?T:U,{className:`h-2.5 w-2.5 shrink-0`}),a(`span`,{className:`truncate`,children:l?c(`detectionIntelligence.copyUrlChips.copied`,`Copied`):t})]})}function fi({localUrl:t,publicUrl:n}){let{t:r}=X();return e(`div`,{className:`flex flex-wrap gap-1`,children:[a(di,{label:r(`detectionIntelligence.copyUrlChips.local`,`Local`),value:t,title:r(`detectionIntelligence.copyUrlChips.copyLanUrl`,`Copy LAN URL — {{AUTH_HINT}}`,{AUTH_HINT:ui})}),n&&a(di,{label:r(`detectionIntelligence.copyUrlChips.public`,`Public`),value:n,title:r(`detectionIntelligence.copyUrlChips.copyPublicUrl`,`Copy public URL — {{AUTH_HINT}}`,{AUTH_HINT:ui})})]})}var pi={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 mi(e){return e in pi}function hi(e){return mi(e)?pi[e]:e}function gi(e,t){return`${e}${t}`}l();var _i=3e4;function vi(e){let[t,n]=s(null),r=i(e=>{n(t=>t??e)},[]);return o(()=>{e||n(null)},[e]),{publicOrigin:t,probes:e?a(yi,{onOrigin:r}):null}}function yi({onOrigin:e}){let{data:t}=Ee({capName:`network-access`});return a(d,{children:(t??[]).map(t=>a(bi,{addonId:t.addonId,onOrigin:e},t.addonId))})}function bi({addonId:e,onOrigin:t}){let{data:n}=rt({addonId:e},{refetchInterval:_i,retry:!1});return o(()=>{let e=n?se.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 xi=typeof Ne==`function`,Si=`Track flags arrive with the next server update`;function Ci(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var wi=xi?Ne:Ci;function Ti(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 Ei({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 Di({deviceId:t,trackId:n,markForTrain:r,debug:i,favourited:o,onChange:c}){let{t:l}=X(),u=wi(),d=H(),[f,p]=s(null),m=f?.markForTrain??r===!0,h=f?.debug??i===!0,g=f?.favourited??o===!0,_=!xi||u.isPending,v=xi?void 0:Si,b=e=>{_||(async()=>{try{let r=Ti(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(Ei,{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(C,{className:`h-4 w-4`}),onToggle:()=>b({markForTrain:!m})}),a(Ei,{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(y,{className:`h-4 w-4`}),onToggle:()=>b({debug:!h})}),a(Ei,{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(L,{className:`h-4 w-4`}),onToggle:()=>b({favourited:!g})})]})}function Oi(e){let t=e.deviceKey===void 0?e.nodeId:`${e.nodeId} · ${e.deviceKey}`;return e.modelId===void 0?t:`${t} (${e.modelId})`}function ki(e){let t=e?.openedPlacement,n=e?.closedPlacement;if(t!==void 0&&n!==void 0){let e=Oi(t),r=Oi(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:Oi(n)}]:[{kind:`opened`,value:Oi(t)}]}var Ai=100,ji={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Mi=e=>e<0?0:e>1?1:e,Ni=e=>Math.round(e*100)/100;function Pi(e,t,n){if(e.length===0||t===null)return ji;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return ji;let a=ce(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:Ni(e.x*Ai),y:Ni(e.y*Ai)})),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:Ni(Mi(e.x/r)*Ai),y:Ni(Mi(e.y/i)*Ai),mediaId:e.mediaId})),u=null,d=-1;for(let t of e){let e=Mi(t.bbox.w/r)*Mi(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:Ni(Mi(u.bbox.x/r)*Ai),y:Ni(Mi(u.bbox.y/i)*Ai),w:Ni(Mi(u.bbox.w/r)*Ai),h:Ni(Mi(u.bbox.h/i)*Ai)}:null}}var Fi=typeof Ie==`function`,Ii=`Track deletion arrives with the next server update`;function Li(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var Ri=Fi?Ie:Li;l();var zi=15e3,Bi=M();function Vi({url:e,label:t}){let{src:n,failed:r}=Ut(e);return n===null?a(`div`,{className:`flex h-full w-full items-center justify-center bg-surface-hover`,children:r?a(f,{className:`h-4 w-4 text-foreground-subtle opacity-60`}):a(z,{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 Hi=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),Ui=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`,`sceneFrame`,`lastSceneFrame`]);function Wi(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 Gi({overlay:t,onPickSnapshot:n}){let{t:r}=X();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 Z({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 Ki({row:t,cameraName:r,deleteAvailable:c,onClose:l,onDeleted:u,onFlagsChanged:p}){let{t:m}=X(),h=ee(),g=H(),_=ne(),y=Ri(),b=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:b}),{data:E}=Le({trackId:S,deviceId:x},{enabled:b}),D=T?.bestEventId===void 0?void 0:Number(T.bestEventId),{data:O}=Fe({ownerType:`object`,eventId:D??0,deviceId:x},{enabled:b&&D!==void 0&&Number.isFinite(D)}),{data:A}=wt({deviceId:x},{enabled:b}),j=(A??[]).find(e=>e.addonId!==void 0)?.addonId,{data:M}=yt({deviceId:x,since:C-zi,until:C+w+zi,provider:j??``},{enabled:b&&j!==void 0}),[N,P]=s(null),[F,I]=s(!1),{publicOrigin:L,probes:R}=vi(b);o(()=>{P(null)},[x,S]);let B=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]),V=N??B,U=Ut(V?V.url:void 0),W=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]),te=n(()=>W.find(e=>Hi.has(e.kind))??null,[W]),G=Wi(Ut(te?te.url:void 0).src),re=n(()=>Pi(T?.positions??[],G,{snapshots:(T?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaId:e.mediaId}))}),[T?.positions,T?.snapshots,G]),ie=i(e=>{let t=W.find(t=>t.mediaId===e);t&&P(t)},[W]);if(t===null)return null;let K=U.src,q=V?.kind,ae=q!==void 0&&Ui.has(q)&&G!==null&&(T?.positions.length??0)>=2,oe=M&&M.length>0?M[0]:null,se=()=>{oe&&(I(!0),(async()=>{try{let e=await h.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:oe.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{g({title:m(`detectionIntelligence.eventDetailPanel.clipUnavailable`,`Clip unavailable`),message:m(`detectionIntelligence.eventDetailPanel.couldNotResolveClipPlayback`,`Could not resolve clip playback. Check the server logs.`),variant:`warning`})}finally{I(!1)}})())},ce=()=>{!c||y.isPending||(async()=>{if(await _({title:m(`detectionIntelligence.eventDetailPanel.deleteTrack`,`Delete track`),message:m(`detectionIntelligence.eventDetailPanel.deleteThisTrackAndEvery`,`Delete this track and every image and clip captured for it? This cannot be undone.`),confirmLabel:m(`common.delete`,`Delete`),variant:`danger`}))try{await y.mutateAsync({deviceId:t.deviceId,trackIds:[t.trackId]}),u()}catch{await g({title:m(`detectionIntelligence.eventDetailPanel.deleteFailed`,`Delete failed`),message:m(`detectionIntelligence.eventDetailPanel.failedToDeleteThisTrack`,`Failed to delete this track. Check the server logs.`),variant:`danger`})}})()},le=Math.round(t.importance*100),ue=T?.importanceReason?`${String(le)}% · ${T.importanceReason}`:`${String(le)}%`,de=T?.zonesVisited&&T.zonesVisited.length>0?T.zonesVisited.join(`, `):`—`,fe=T?.audioLabels&&T.audioLabels.length>0?T.audioLabels:t.audioLabels&&t.audioLabels.length>0?t.audioLabels:void 0,pe=fe===void 0?`—`:fe.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `),me=T?T.totalDistance.toFixed(2):`—`,he=oi(T?.previewMissReason),ge=Qn(T?T.firstSeen:C),_e=T?Qn(T.lastSeen):`—`,ve=ki(T),ye={detected:m(`detectionIntelligence.eventDetailPanel.detectedOn`,`Detected on`),opened:m(`detectionIntelligence.eventDetailPanel.openedOn`,`Opened on`),closed:m(`detectionIntelligence.eventDetailPanel.closedOn`,`Closed on`)};return a(et,{open:!0,onOpenChange:e=>!e&&l(),children:e(xt,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":m(`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,qr(t)?e(`span`,{className:`text-foreground-subtle`,children:[` · `,qr(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:[K?a(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:a(hr,{src:K,alt:m(`detectionIntelligence.eventDetailPanel.keyFrameFrom`,`Key frame from {{cameraName}}`,{cameraName:r}),fit:`natural`,className:`w-full`,overlay:ae?a(Gi,{overlay:re,onPickSnapshot:ie}):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:U.failed?e(d,{children:[a(f,{className:`h-8 w-8 opacity-60`}),a(`span`,{className:`text-[11px]`,children:m(`detectionIntelligence.eventDetailPanel.keyFrameMediaUnavailable`,`Key-frame media unavailable`)})]}):a(z,{className:`h-6 w-6 animate-spin opacity-70`})}),W.length>0&&a(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:W.map(t=>{let n=hi(t.kind),r=gi(Bi,t.url),i=L?gi(L,t.url):null;return e(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[a(`button`,{type:`button`,onClick:()=>P(t),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${n} · ${Qn(t.timestamp)}`,children:a(Vi,{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:Qn(t.timestamp),children:Zn(t.timestamp)})]}),a(fi,{localUrl:r,publicUrl:i})]},t.mediaId)})}),R,oe&&e(J,{variant:`secondary`,onClick:se,disabled:F,children:[F?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(k,{className:`h-3.5 w-3.5`}),` `,m(`detectionIntelligence.eventDetailPanel.viewClip`,`View clip`)]}),a(Di,{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:p}),he!==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:m(`detectionIntelligence.eventDetailPanel.bestShot`,`Best shot`)}),a(`p`,{className:`mt-0.5 text-xs text-foreground`,children:he.sentence}),a(`code`,{className:`mt-1 block break-all font-mono text-[10px] text-foreground-subtle`,children:he.raw})]}),e(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[a(Z,{label:m(`detectionIntelligence.eventDetailPanel.camera`,`Camera`),value:r}),ve.map(e=>a(Z,{label:ye[e.kind],value:e.value,mono:!0,wrap:!0},e.kind)),a(Z,{label:m(`detectionIntelligence.eventDetailPanel.class`,`Class`),value:t.className}),a(Z,{label:m(`detectionIntelligence.eventDetailPanel.label`,`Label`),value:t.label??`—`}),a(Z,{label:m(`detectionIntelligence.eventDetailPanel.subLabel`,`Sub-label`),value:t.subLabel??`—`}),a(Z,{label:m(`detectionIntelligence.eventDetailPanel.importance`,`Importance`),value:ue}),a(Z,{label:m(`detectionIntelligence.eventDetailPanel.zonesVisited`,`Zones visited`),value:de}),a(Z,{label:m(`detectionIntelligence.eventDetailPanel.audioHeard`,`Audio heard`),value:pe}),a(Z,{label:m(`detectionIntelligence.eventDetailPanel.totalDistance`,`Total distance`),value:me}),a(Z,{label:m(`detectionIntelligence.eventDetailPanel.firstSeen`,`First seen`),value:ge}),a(Z,{label:m(`detectionIntelligence.eventDetailPanel.lastSeen`,`Last seen`),value:_e}),a(Z,{label:m(`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:Ii,children:e(J,{variant:`secondary`,onClick:ce,disabled:!c||y.isPending,children:[y.isPending?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(v,{className:`h-3.5 w-3.5`}),` `,m(`detectionIntelligence.eventDetailPanel.deleteTrack`,`Delete track`)]})})})]})})}var qi={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`},Ji={setRelation:`debug.gt.setRelation`,setPurity:`debug.gt.setPurity`,list:`debug.gt.list`},Yi=E(`/addon/pipeline-analytics/tape-export`),Xi=10*6e4;function Zi(e){return`${Yi}?tapeId=${encodeURIComponent(e)}`}var Qi=`The server answered in a shape this build does not understand.`;function $i(e){return e instanceof Error?e.message:Y.t(`helpers.eventsDebugTapes.actionFailed`)}function ea(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 ta(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 na(e,t){let n=e[t];return typeof n==`boolean`?n:null}function ra(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 ia(e){return e===`off`||e===`recording`||e===`refused`||e===`failing`||e===`unknown`}function aa(e){if(!ea(e))return null;let t=Q(e,`deviceId`),n=e.state,r=Q(e,`gapsSinceArmed`),i=ta(e,`segmentsHeld`),a=ta(e,`bytesLastHour`),o=ta(e,`bytesHeld`);if(t===null||!ia(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 oa(e){return ea(e)?ra(e.cameras,aa):null}function sa(e){if(!ea(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=na(e,`reviewed`),f=na(e,`released`),p=ra(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 ca(e){return ea(e)?ra(e.tapes,sa):null}function la(e){if(!ea(e))return null;let t=$(e,`trackId`),n=Q(e,`firstT`),r=Q(e,`lastT`),i=Q(e,`boundFrames`),a=$(e,`cls`),o=na(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 ua(e){if(!ea(e))return null;let t=$(e,`tapeId`),n=Q(e,`deviceId`),r=Q(e,`fromMs`),i=Q(e,`toMs`),a=na(e,`reviewed`),o=ra(e.lanes,la);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 da(e){if(!ea(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 fa(e){if(!ea(e))return null;let t=e.status;if(t===`released`){let n=Q(e,`unpinned`),r=na(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 pa(e){if(!ea(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 ma(e){switch(e.status){case`released`:case`deleted`:return null;case`already-released`:return Y.t(`helpers.eventsDebugTapes.alreadyReleased`);case`not-found`:return Y.t(`helpers.eventsDebugTapes.notFound`);case`pins-owed`:return Y.t(`helpers.eventsDebugTapes.pinsOwed`);case`unavailable`:return Y.t(`helpers.eventsDebugTapes.unavailable`,{reason:e.reason})}}function ha(e){if(!ea(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 ga(e){if(!ea(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 _a(e){if(!ea(e))return null;let t=ra(e.relations,ha),n=ra(e.purities,ga),r=na(e,`truncated`);return t===null||n===null||r===null?null:{relations:t,purities:n,truncated:r}}function va(e){if(!e.truncated)return null;let t=e.relations.length+e.purities.length;return Y.t(`helpers.eventsDebugTapes.truncatedMarks`,{count:t})}function ya(e){return e.filter(e=>e.segmentsHeld===null||e.segmentsHeld>0).map(e=>({deviceId:e.deviceId,segmentsUnknown:e.segmentsHeld===null}))}function ba(e){return e.slice(1).map((t,n)=>({trackId:e[n]??t,otherTrackId:t}))}function xa(e){return e.flatMap((t,n)=>e.slice(n+1).map(e=>({trackId:t,otherTrackId:e})))}function Sa(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 Ca(e){switch(e.state){case`off`:return Y.t(`helpers.eventsDebugTapes.statusOff`);case`recording`:return Y.t(`helpers.eventsDebugTapes.statusRecording`);case`refused`:return Y.t(`helpers.eventsDebugTapes.statusRefused`,{reason:e.reason??Y.t(`helpers.eventsDebugTapes.unknownReason`)});case`failing`:return Y.t(`helpers.eventsDebugTapes.statusFailing`,{reason:e.reason??Y.t(`helpers.eventsDebugTapes.unknownReason`)});case`unknown`:return Y.t(`helpers.eventsDebugTapes.statusUnknown`,{reason:e.reason??Y.t(`helpers.eventsDebugTapes.unknownReason`)})}}var wa={"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 Ta(e,t){let n=wa[e]??`Refused (${e}).`;return t.length>0?`${n} ${t}`:n}function Ea(e){if(e.length===0)return null;let t=new Date(e).getTime();return Number.isFinite(t)?t:null}function Da(e){return e<1024*1024?Y.t(`helpers.eventsDebugTapes.sizeKb`,{value:(e/1024).toFixed(0)}):Y.t(`helpers.eventsDebugTapes.sizeMb`,{value:(e/1024/1024).toFixed(1)})}function Oa(e){return e===null?`unknown`:Da(e)}function ka(e){return e===null?`unknown`:String(e)}function Aa(e,t){let n=t.trim();return e===404?Y.t(`helpers.eventsDebugTapes.exportUnknown`):e===503?n.length>0?n:Y.t(`helpers.eventsDebugTapes.tapesUnavailable`):e===500?n.length>0?n:Y.t(`helpers.eventsDebugTapes.exportUnreadable`):Y.t(`helpers.eventsDebugTapes.downloadFailed`,{status:e})}l();function ja({cameras:t,call:n,onPromoted:r}){let{t:i}=X(),[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=Ea(l),a=Ea(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=da(await n(qi.promote,{deviceId:e,fromMs:i,toMs:a,scenario:p,...h.trim().length>0?{note:h.trim()}:{},..._===`day`||_===`ir`?{lighting:_}:{}}));t===null?S(Qi):t.ok?(S(`Promoted ${t.tapeId}: ${String(t.frames)} frames, ${Da(t.bytes)}, ${String(t.pinnedTracks)} tracks pinned`+(t.state===`incomplete`?` — incomplete (it has gaps) and cannot become a case.`:`.`)),r()):S(Ta(t.reason,t.detail))}catch(e){S($i(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($e,{value:o,options:[...t],onChange:e=>c(e.target.value),"aria-label":i(`eventsDebugTapesPromoteForm.camera`,`Camera`)})}),a(st,{type:`datetime-local`,"aria-label":i(`eventsDebugTapesPromoteForm.from`,`From`),value:l,onChange:e=>u(e.target.value),className:`w-48`}),a(st,{type:`datetime-local`,"aria-label":i(`eventsDebugTapesPromoteForm.to`,`To`),value:d,onChange:e=>f(e.target.value),className:`w-48`}),a(st,{"aria-label":i(`eventsDebugTapesPromoteForm.scenario`,`Scenario`),placeholder:`101-door-groups`,value:p,onChange:e=>m(e.target.value),className:`w-44`}),a(st,{"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($e,{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(J,{onClick:()=>void C(),disabled:y||t.length===0,children:[y?a(z,{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 Ma=`pipeline-analytics`,Na=`debug.listTracks`,Pa=`debug.analyze`,Fa=E(`/addon/pipeline-analytics/debug-export`);function Ia(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function La(e,t){let n=e[t];return typeof n==`string`?n:null}function Ra(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function za(e,t){let n=e[t];return typeof n==`boolean`?n:null}function Ba(e){return e===`error`||e===`warn`||e===`info`}function Va(e){if(!Ia(e))return null;let t=La(e,`code`),n=La(e,`detail`),r=e.severity;return t===null||n===null||!Ba(r)?null:{code:t,severity:r,detail:n}}function Ha(e){if(!Ia(e))return null;let t=La(e,`trackId`),n=Ra(e,`deviceId`),r=La(e,`className`),i=Ra(e,`firstSeen`),a=Ra(e,`lastSeen`),o=Ra(e,`durationMs`),s=za(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=La(e,`label`),l=La(e,`subLabel`),u=La(e,`previewMissReason`),d=za(e,`markForTrain`),f=za(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:Ra(e,`importance`)??0,bestEventId:La(e,`bestEventId`)??``,...d===null?{}:{markForTrain:d},...f===null?{}:{favourited:f},debug:!0,...u===null||u.length===0?{}:{previewMissReason:u}}}function Ua(e){let t=Ha(e);if(t===null||!Ia(e))return null;let n=Ra(e,`mediaCount`),r=Ra(e,`eventCount`),i=Ra(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=Va(e);t!==null&&c.push(t)}let l=e.thumbnailProvenance;return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c,...ni(l)?{thumbnailProvenance:l}:{}}}function Wa(e){if(!Ia(e))return null;let t=za(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=Ha(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function Ga(e){if(!Ia(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=Ua(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var Ka={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 qa(e){return Ka[e]??e}var Ja={error:0,warn:1,info:2};function Ya(e){return e.toSorted((e,t)=>Ja[e.severity]-Ja[t.severity]||e.code.localeCompare(t.code))}function Xa(e){return e.length===0?Fa:`${Fa}?deviceIds=${e.join(`,`)}`}function Za(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 Qa(e,t){return`${String(e)}:${t}`}function $a(e,t){let n=[],r=new Set;for(let i of e){let e=Qa(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 eo({tapeId:t,call:n,onClose:r,onChanged:i}){let{t:o}=X(),l=c({queryKey:[`events-debug`,`tapes`,`tracks`,t],queryFn:async()=>ua(await n(qi.tracks,{tapeId:t}))}),u=l.data??null,d=c({queryKey:[`events-debug`,`tapes`,`marks`,t],enabled:u!==null,queryFn:async()=>u===null?null:_a(await n(Ji.list,{deviceId:u.deviceId,since:u.fromMs-Xi,until:u.toMs+Xi,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){_($i(e))}};if(u===null)return l.isLoading?a(`p`,{className:`text-xs`,children:o(`eventsDebugTapesReview.loadingTheTape`,`Loading the tape…`)}):a(Ue,{message:Qi});let b=u.deviceId,x=(e,t)=>y(e.map(e=>[Ji.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=>[Ji.setPurity,{deviceId:b,trackId:t,purity:e,...n===void 0?{}:{switchAtMs:Math.round(n)}}]))},C=d.data==null?null:va(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(J,{disabled:f.length<2,onClick:()=>void x(ba(f),`same-subject`),children:o(`eventsDebugTapesReview.sameSubject`,`Same subject`)}),a(J,{variant:`secondary`,disabled:f.length<2,onClick:()=>void x(xa(f),`different-subjects`),children:o(`eventsDebugTapesReview.differentSubjects`,`Different subjects`)}),a(st,{"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(J,{variant:`secondary`,disabled:f.length!==1,onClick:()=>void S(`mixed`),children:o(`eventsDebugTapesReview.mixed`,`Mixed`)}),a(J,{variant:`secondary`,disabled:f.length===0,onClick:()=>void S(`not-a-subject`),children:o(`eventsDebugTapesReview.notASubject`,`Not a subject`)}),a(J,{variant:u.reviewed?`secondary`:`primary`,onClick:()=>void y([[qi.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(J,{variant:`ghost`,onClick:r,children:o(`common.close`,`Close`)})]}),g!==null&&a(Ue,{message:g}),C!==null&&a(Ue,{variant:`warning`,message:C}),a(`ul`,{className:`space-y-1`,children:u.lanes.toSorted((e,t)=>e.firstT-t.firstT).map(e=>a(to,{lane:e,marks:d.data===null||d.data===void 0?[]:Sa(e.trackId,d.data),selected:f.includes(e.trackId),onToggle:()=>v(e.trackId)},e.trackId))})]})}function to({lane:t,marks:n,selected:r,onToggle:i}){let{t:o}=X(),{src:s}=Ut(t.stillStored?Wt(`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:`${Za(t.firstT)} → ${Za(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(Ct,{variant:`info`,children:e},e))]})}l();var no=`camstack_admin_token`;function ro(){let e=ee();return(t,n)=>e.trpcClient.addons.custom.mutate({addonId:Ma,action:t,input:n})}async function io(e,t){let n=localStorage.getItem(no),r={};n!==null&&(r.Authorization=`Bearer ${n}`);let i=await fetch(Zi(e),{headers:r});if(!i.ok){let e=await i.text().catch(()=>``);throw Error(Aa(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 ao(){let{t:e}=X(),[t,n]=s(!1);return a(ze,{expanded:t,onExpandedChange:n,header:a(`span`,{className:`text-sm font-medium text-foreground`,children:e(`eventsDebugTapes.trackingTapes`,`Tracking tapes`)}),children:a(oo,{})})}function oo(){let{t}=X(),r=ro(),i=we({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()=>oa(await r(qi.status,{}))}),u=c({queryKey:[`events-debug`,`tapes`,`list`],queryFn:async()=>ca(await r(qi.list,{}))}),[d,f]=s(null),[p,m]=s(null),h=async e=>{m(null);try{await io(e.id,`${e.scenario}.tape-bundle.json.gz`)}catch(e){m($i(e))}},g=async e=>{let t=fa(await r(qi.release,{tapeId:e.id}));if(t===null)throw Error(Qi);let n=ma(t);if(n!==null)throw Error(n);await u.refetch()},_=async e=>{let t=pa(await r(qi.remove,{tapeId:e.id}));if(t===null)throw Error(Qi);let n=ma(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(zt,{i18nKey:`eventsDebugTapes.intro`,components:{b:a(`strong`,{}),code:a(`code`,{})}})}),p!==null&&a(Ue,{message:p}),l.isLoading&&a(`p`,{className:`text-xs text-foreground-subtle`,children:t(`eventsDebugTapes.loadingCameraStatus`,`Loading camera status…`)}),l.data===null&&a(Ue,{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(Ct,{variant:n.state===`recording`?`success`:n.state===`off`?`default`:n.state===`unknown`?`warning`:`danger`,children:Ca(n)})}),a(`td`,{children:n.framesPerMin===void 0?`—`:String(Math.round(n.framesPerMin))}),a(`td`,{title:n.shelfError,children:Oa(n.bytesLastHour)}),a(`td`,{title:n.shelfError,children:t(`eventsDebugTapes.segsHeld`,{count:ka(n.segmentsHeld),size:Oa(n.bytesHeld)})}),a(`td`,{children:String(n.gapsSinceArmed)})]},n.deviceId))})]}),a(ja,{cameras:ya(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(Ue,{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(),` · `,Za(n.toMs-n.fromMs),` `,`· `,n.lighting]}),e(`td`,{children:[a(Ct,{variant:n.state===`complete`?`success`:`warning`,children:n.state}),` `,n.reviewed&&a(Ct,{variant:`info`,children:t(`eventsDebugTapes.reviewed`)}),` `,n.released&&a(Ct,{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(J,{variant:`secondary`,"aria-label":t(`eventsDebugTapes.review`,`Review {{scenario}}`,{scenario:n.scenario}),onClick:()=>f(n.id),children:t(`eventsDebugTapes.review2`,`Review`)}),a(J,{variant:`ghost`,"aria-label":t(`eventsDebugTapes.download`,`Download {{scenario}}`,{scenario:n.scenario}),onClick:()=>void h(n),children:a(A,{className:`h-3.5 w-3.5`})}),a(ut,{label:t(`eventsDebugTapes.release`,`Release`),icon:ie,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:()=>g(n)}),a(ut,{label:t(`common.delete`,`Delete`),icon:v,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:()=>_(n)})]})]},n.id))})]}),d!==null&&a(eo,{tapeId:d,call:r,onClose:()=>f(null),onChanged:()=>void u.refetch()})]})}l();var so=`all`,co=`The server answered in a shape this build does not understand.`,lo={error:`danger`,warn:`warning`,info:`info`};function uo({findings:e}){let{t}=X();return e.length===0?a(Ct,{variant:`success`,children:t(`eventsDebug.noAnomalyFound`,`no anomaly found`)}):a(`div`,{className:`flex flex-wrap gap-1`,children:Ya(e).map(e=>a(Ct,{variant:lo[e.severity],title:e.detail,children:qa(e.code)},e.code))})}function fo({track:t,report:n,analyzing:r}){let{t:i}=X(),o=oi(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(uo,{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 po(){let{t}=X(),r=ee(),[i,o]=s(so),[l,u]=s(!1),[d,f]=s(null),[p,m]=s(new Set),[h,_]=s(null),[v,x]=s(null),[S,C]=s(null),[w,E]=s([]),D=wi(),O=we({isCamera:!0,projection:`slim`}),k=n(()=>[{value:so,label:t(`eventsDebug.allCameras`,`All cameras`)},...(O.data??[]).map(e=>({value:String(e.id),label:e.name}))],[O.data,t]),j=n(()=>{let e=new Map;for(let t of O.data??[])e.set(t.id,t.name);return e},[O.data]),M=e=>j.get(e)??t(`eventsDebug.cameraFallback`,{deviceId:e}),N=n(()=>i===so?[]:[Number.parseInt(i,10)],[i]),P=c({queryKey:[`events-debug`,`list`,N],queryFn:async()=>Wa(await r.trpcClient.addons.custom.mutate({addonId:Ma,action:Na,input:N.length===0?{}:{deviceIds:N}}))}),F=n(()=>(P.data?.tracks??[]).map(e=>e.trackId),[P.data]),I=c({queryKey:[`events-debug`,`analyze`,F],enabled:F.length>0,queryFn:async()=>Ga(await r.trpcClient.addons.custom.mutate({addonId:Ma,action:Pa,input:{trackIds:F}}))}),R=n(()=>{let e=new Map;for(let t of I.data?.reports??[])e.set(t.trackId,t);return e},[I.data]),V=P.data?.tracks??[],H=P.data===null||I.data===null,U=()=>{P.refetch(),I.refetch()},W=e=>{m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},te=()=>{m(new Set(V.map(e=>Qa(e.deviceId,e.trackId))))},ne=()=>m(new Set),G=async(e,t)=>{let n=e===`analyzed`?{debug:!1}:{favourited:!0},r=0,i=[];for(let e of t)try{await D.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,flags:n}),r+=1}catch{i.push(e.trackId)}return{applied:r,refused:i}},re=e=>{if(!xi||v!==null)return;let t=$a(V,p);t.length!==0&&(x(e),C(null),(async()=>{let n=await G(e,t);x(null);let r=new Set(n.refused);m(new Set(t.filter(e=>r.has(e.trackId)).map(e=>Qa(e.deviceId,e.trackId)))),e===`analyzed`&&E(t.filter(e=>!r.has(e.trackId))),n.refused.length>0&&C(`${String(n.refused.length)} of ${String(t.length)} were refused by the server and are still selected. Check the hub log.`),P.refetch()})())},ie=()=>{let e=w;e.length===0||v!==null||(x(`analyzed`),C(null),(async()=>{for(let t of e)try{await D.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,flags:{debug:!0}})}catch{C(`Some tracks could not be re-marked. Refresh and try again.`)}x(null),E([]),P.refetch()})())},K=async()=>{u(!0),f(null);try{await qt(Xa(N),`camstack-debug.zip`)}catch(e){f(e instanceof Error?e.message:`Export failed.`)}finally{u(!1)}},q=v!==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($e,{value:i,options:k,onChange:e=>o(e.target.value)})}),e(J,{variant:`secondary`,onClick:U,disabled:P.isFetching,children:[P.isFetching?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(g,{className:`h-3.5 w-3.5`}),t(`common.refresh`,`Refresh`)]}),e(J,{onClick:()=>void K(),disabled:l||V.length===0,children:[l?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(A,{className:`h-3.5 w-3.5`}),t(`eventsDebug.exportAll`,{count:String(V.length)})]}),V.length>0&&p.size<V.length&&a(J,{variant:`ghost`,onClick:te,children:t(`eventsDebug.selectAll`,`Select all`)})]}),a(`p`,{className:`text-xs text-foreground-subtle`,children:a(zt,{i18nKey:`eventsDebug.debugMarkNote`,components:{code:a(`code`,{}),strong:a(`strong`,{})}})}),a(ao,{}),P.isError&&a(Ue,{message:t(`eventsDebug.couldNotLoadTheMarked`,`Could not load the marked tracks.`)}),H&&!P.isError&&a(Ue,{message:co}),d!==null&&a(Ue,{message:d}),S!==null&&a(Ue,{message:S}),P.data?.truncated===!0&&a(Ue,{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.`)}),(I.data?.vanished.length??0)>0&&a(`p`,{className:`text-xs text-foreground-subtle`,children:t(`eventsDebug.vanished`,{count:String(I.data?.vanished.length)})}),p.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:p.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[a(`span`,{title:xi?void 0:`Track flags arrive with the next server update`,children:e(J,{variant:`secondary`,onClick:()=>re(`keep`),disabled:!xi||q,children:[v===`keep`?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(L,{className:`h-3.5 w-3.5`}),` `,t(`eventsDebug.keep`,`Keep`)]})}),a(`span`,{title:xi?void 0:`Track flags arrive with the next server update`,children:e(J,{onClick:()=>re(`analyzed`),disabled:!xi||q,children:[v===`analyzed`?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(T,{className:`h-3.5 w-3.5`}),` `,t(`eventsDebug.analyzed`,`Analyzed`)]})}),a(J,{variant:`ghost`,onClick:ne,disabled:q,children:a(B,{className:`h-3.5 w-3.5`})})]})]}),w.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(w.length)})}),e(J,{variant:`ghost`,onClick:ie,disabled:q,children:[a(b,{className:`h-3.5 w-3.5`}),` `,t(`eventsDebug.undo`)]}),a(J,{variant:`ghost`,onClick:()=>E([]),disabled:q,children:a(B,{className:`h-3.5 w-3.5`})})]}),P.isLoading?a(nt,{status:`pending`,pendingMessage:`Loading…`,testId:`debug-tracks-grid`}):V.length===0?a(Te,{icon:y,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(nt,{status:`ready`,testId:`debug-tracks-grid`,children:V.map(e=>{let t=R.get(e.trackId);return a(ci,{row:e,cameraName:M(e.deviceId),nowMs:e.lastSeen,selected:p.has(Qa(e.deviceId,e.trackId)),onToggleSelect:W,onOpenDetail:_,...t?.thumbnailProvenance===void 0?{}:{provenance:t.thumbnailProvenance},footer:a(fo,{track:e,report:t,analyzing:I.isFetching})},Qa(e.deviceId,e.trackId))})}),h&&a(Ki,{row:h,cameraName:M(h.deviceId),deleteAvailable:Fi,onClose:()=>_(null),onDeleted:()=>{_(null),P.refetch()},onFlagsChanged:e=>{e.debug||(_(null),P.refetch())}})]})}var mo=200,ho=3e4,go=[];function _o(e){let t=ee(),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:ho,refetchInterval:ho,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEventsBatch.query({deviceIds:r,since:e.since,until:e.until,limit:mo,...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:Xr(Yr(i??go),`importance`),isLoading:n&&a}}l();var vo=[`events-feed`],yo=2e3;function bo(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:vo})},[]),p=t(void 0);p.current||=Hr({delayMs:yo,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 Pt(le.PipelineAnalyticsDetectionEvent,()=>{p.current?.trigger()}),Pt(le.PipelineAnalyticsTrackEnded,()=>{p.current?.trigger()}),{pending:l,refreshNow:m}}l();function xo({groups:t,selected:r,onChange:i,loading:o=!1}){let{t:c}=X(),l=kt(),[u,d]=s(!1),[f,p]=s(``),[h,g]=s(new Set),_=f.trim().toLowerCase(),v=e=>_.length===0||Dt(e,c).toLowerCase().includes(_),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,_]),b=e=>g(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(j,{className:`h-3.5 w-3.5`}),w>0?c(`detectionIntelligence.eventKindFilter.kinds`,`Kinds ({{value1}})`,{value1:String(w)}):c(`detectionIntelligence.eventKindFilter.kinds2`,`Kinds`),a(m,{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(K,{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…`):_.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=vt(t.macro.iconId),i=h.has(t.macro.kind)||_.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?m:D,{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:Dt(t.macro,c)})]})]}),i&&t.subs.map(t=>{let n=vt(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:Dt(t,c)})]},t.kind)})]},t.macro.kind)})]})]})}function So(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 Co(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var wo=new Set([`detection`,`package`]);function To(e,t){return[...So(e,t).values()].filter(e=>e.parentKind===null&&wo.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function Eo(e,t){let n=So(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,Co(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 Do(){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 Oo=[`events-feed`],ko=60,Ao=[{value:`importance`,labelKey:`detectionIntelligence.eventsSection.sortImportance`,icon:de},{value:`time`,labelKey:`detectionIntelligence.eventsSection.sortRecent`,icon:I}];function jo(){let{t}=X(),r=u(),i=H(),c=ne(),[l,f]=s(Bn),[p,m]=s(new Set),[h,g]=s(new Set),[_,y]=s(0),[b,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(()=>ei({fromMs:l.fromMs,toMs:l.toMs},E),[l.fromMs,l.toMs,E]),A=Do(),{pending:j,refreshNow:M}=bo({paused:w!==null||S.size>0||A.scrolledPast}),{data:N=[]}=we({isCamera:!0,projection:`slim`}),P=n(()=>N.map(e=>e.id),[N]),{data:F,isLoading:I}=pt({deviceIds:P},{enabled:P.length>0,staleTime:5*6e4}),ee=n(()=>Eo(F??[],p),[F,p]),L=Ri(),R=L.isPending,{rows:V,isLoading:U}=_o({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]),G=e=>W.get(e)??t(`detectionIntelligence.cameraFallback`,{id:String(e)}),re=n(()=>qn(V).map(e=>({id:e,name:G(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[V,W]),ie=n(()=>Xr(Zr(V,{cameras:p,classes:h,minImportance:_}),b),[V,p,h,_,b]),K=rr(ie,ko,n(()=>JSON.stringify([[...p].sort((e,t)=>e-t),[...h].sort(),_,b,O,k]),[p,h,_,b,O,k])),q=()=>{r.invalidateQueries({queryKey:Oo})},ae=()=>C(new Set);function oe(e){C(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function se(){if(S.size===0||!Fi)return;let e=$r(V,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`})&&ce(e)})()}function ce(e){let n=[...e];Promise.allSettled(n.map(([e,t])=>L.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{q();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(Qr(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=>G(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 le=ie.length!==V.length;return e(`div`,{className:`relative space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[a(dr,{onChange:f}),a(lr,{cameras:re,selected:p,onChange:m}),a(xo,{groups:ee,selected:h,onChange:g,loading:I}),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=>y(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:Ao.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 ${b===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:le?t(`detectionIntelligence.eventsSection.ofEvents`,`{{value1}} of {{value2}} events`,{value1:String(ie.length),value2:String(V.length)}):t(`detectionIntelligence.eventsSection.eventCount`,{count:ie.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:Fi?void 0:`Track deletion arrives with the next server update`,children:e(J,{variant:`secondary`,onClick:se,disabled:!Fi||R,children:[R?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(v,{className:`h-3.5 w-3.5`}),` `,t(`common.delete`,`Delete`)]})}),a(J,{variant:`ghost`,onClick:ae,disabled:R,children:a(B,{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(nt,{status:`pending`,pendingMessage:`Loading events…`,testId:`events-grid`}):ie.length===0?a(Te,{icon:te,title:le?t(`detectionIntelligence.eventsSection.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.eventsSection.noKeyEventsInThis`,`No key events in this window`),description:le?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(nt,{status:`ready`,testId:`events-grid`,children:K.pageItems.map(e=>a(ci,{row:e,cameraName:G(e.deviceId),nowMs:E,selected:S.has(Qr(e.deviceId,e.trackId)),onToggleSelect:oe,onOpenDetail:T},Qr(e.deviceId,e.trackId)))}),a(or,{currentPage:K.page,totalItems:K.totalItems,pageSize:K.pageSize,onPageChange:K.setPage,itemNoun:`events`})]}),w&&a(Ki,{row:w,cameraName:G(w.deviceId),deleteAvailable:Fi,onClose:()=>T(null),onDeleted:()=>{q(),T(null)},onFlagsChanged:e=>{T(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug,favourited:e.favourited}:t)}})]})}var Mo=`/addon/training`;function No(){let{t}=X(),n=Lt();return e(Ze,{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(C,{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:`${ae} 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(J,{variant:`outline`,size:`sm`,className:`shrink-0 self-start sm:self-center`,onClick:()=>n(Mo),children:t(`detectionIntelligence.retrainTabCallout.openTraining`,`Open Training`)})]})}l();var Po=50,Fo=350,Io=[{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 Lo(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 Ro({onActiveChange:r}){let i=t(null);He(i);let{t:c}=X(),[l,u]=s(``),[d,f]=s(`loose`),[p,m]=s(null),[h,g]=s(null),[_,v]=s(null),y=Ot(l,Fo).trim(),b=y.length>0;o(()=>{r(b)},[b,r]);let[x,S]=s(()=>Date.now());o(()=>{let e=setInterval(()=>S(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:C=[]}=we({isCamera:!0,projection:`slim`}),w=n(()=>{let e=new Map;for(let t of C)e.set(t.id,t.name);return e},[C]),T=e=>w.get(e)??c(`detectionIntelligence.cameraFallback`,{id:String(e)}),E=n(()=>C.map(e=>e.id),[C]),{data:D}=pt({deviceIds:E},{enabled:E.length>0,staleTime:5*6e4}),O=n(()=>To(D??[],new Set(h===null?[]:[h])),[D,h]);o(()=>{p!==null&&(O.some(e=>e.kind===p)||m(null))},[O,p]);let{data:k,isFetching:A,isError:j,error:M}=Ae({text:y,strictness:d,limit:Po,classFilter:p??void 0,deviceId:h??void 0},{enabled:b}),N=n(()=>[...k??[]].sort((e,t)=>t.score-e.score).map(e=>({...Lo(e),score:e.score})),[k]);function P(e){m(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(K,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),a(`input`,{ref:i,type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:c(`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":c(`detectionIntelligence.semanticEventSearch.semanticEventSearch`,`Semantic event search`)}),l&&a(`button`,{type:`button`,onClick:()=>u(``),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":c(`detectionIntelligence.semanticEventSearch.clearSearch`,`Clear search`),children:a(B,{className:`h-3.5 w-3.5`})})]}),A&&b&&a(z,{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:O.map(e=>a(`button`,{type:`button`,onClick:()=>P(e.kind),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${p===e.kind?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:Dt(e)},e.kind))}),e(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[a(`span`,{children:c(`detectionIntelligence.semanticEventSearch.camera`,`Camera`)}),a($e,{value:h===null?``:String(h),onChange:e=>g(e.target.value===``?null:Number(e.target.value)),className:`h-7 text-xs`,"aria-label":c(`detectionIntelligence.semanticEventSearch.filterByCamera`,`Filter by camera`),options:[{value:``,label:c(`detectionIntelligence.semanticEventSearch.all`,`All`)},...C.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:c(`detectionIntelligence.semanticEventSearch.match`,`Match`)}),a(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Io.map(e=>a(`button`,{type:`button`,onClick:()=>f(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${d===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:c(e.titleKey),children:c(e.labelKey)},e.value))})]}),b&&!A&&!j&&a(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:c(`common.matches`,{count:N.length})})]})]}),b&&e(`div`,{className:`space-y-3`,children:[j&&e(`p`,{className:`py-4 text-xs text-danger`,children:[c(`detectionIntelligence.semanticEventSearch.searchFailed`,`Search failed:`),` `,M instanceof Error?M.message:c(`detectionIntelligence.semanticEventSearch.unknownError`,`unknown error`),`. Check that the CLIP embedding step is enabled.`]}),!j&&A&&N.length===0&&a(nt,{status:`pending`,pendingMessage:`Searching…`,testId:`semantic-events-grid`}),!j&&!A&&N.length===0&&a(nt,{status:`empty`,emptyMessage:c(`detectionIntelligence.semanticEventSearch.noSemanticMatchesForTry`,`No semantic matches for “{{debounced}}”. Try a looser match threshold or a different phrasing.`,{debounced:y}),testId:`semantic-events-grid`}),!j&&N.length>0&&a(nt,{status:`ready`,testId:`semantic-events-grid`,children:N.map(e=>a(ci,{row:e,cameraName:T(e.deviceId),nowMs:x,score:e.score,onOpenDetail:v},e.id))})]}),_&&a(Ki,{row:_,cameraName:T(_.deviceId),deleteAvailable:Fi,onClose:()=>v(null),onDeleted:()=>v(null)})]})}l();function zo(e,t){let n=Math.max(0,Math.round((e-t)/6e4));if(n<1)return Y.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 Bo({row:t,cameraName:n,nowMs:r}){let{t:i}=X(),o=Ut(t.keyFrameMediaId===void 0?void 0:Kt(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(pe,{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:zo(r,t.becameStationaryAt)})})]})]})}function Vo(){let{t}=X(),[r,i]=s(!1),o=Date.now(),{data:c=[]}=we({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}=Ht(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?m:D,{className:`h-4 w-4 text-foreground-subtle`}),a(pe,{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(Bo,{row:e,cameraName:u.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:o},e.id))})]})}l();function Ho(){let[t,n]=s(!1);return e(`section`,{className:`space-y-3`,children:[a(No,{}),a(Ro,{onActiveChange:n}),!t&&a(Vo,{}),!t&&a(jo,{})]})}function Uo(){let{t:e}=X(),[t]=Bt();return t.get(`section`)===`retrain`?a(Rt,{to:`/addon/training`,replace:!0}):a(Vt,{sectionsOnly:!0,paramName:`section`,defaultSection:`feed`,sectionsLabel:`Events sections`,sections:[{id:`feed`,label:e(`events.feed`,`Feed`),content:a(Ho,{})},{id:`debug`,label:e(`events.debug`,`Debug`),content:a(po,{})}]})}function Wo(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 Go=[[`plateGallery`]];function Ko({plateIds:t,vehicles:n,onDone:r}){let{t:i}=X(),o=u(),c=Re(),l=je(),[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:Go}),b()}})}function S(){!t||!d.trim()||l.mutate({name:d.trim()},{onSuccess:e=>{e?.id&&x(e.id)},onError:()=>{o.invalidateQueries({queryKey:Go}),b()}})}let C=c.isPending||l.isPending;return a(et,{open:_,onOpenChange:e=>!e&&b(),children:e(xt,{children:[e(ct,{children:[a(Je,{children:v>1?i(`detectionIntelligence.assignPlateDialog.assignPlatesToVehicle`,`Assign {{value1}} plates to vehicle`,{value1:String(v)}):i(`detectionIntelligence.assignPlateDialog.assignPlateToVehicle`,`Assign plate to vehicle`)}),a(ht,{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(st,{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(dt,{children:[a(J,{variant:`secondary`,onClick:b,disabled:C,children:i(`common.cancel`,`Cancel`)}),p?e(J,{variant:`primary`,onClick:S,disabled:C||!d.trim(),children:[C&&a(z,{className:`h-3.5 w-3.5 animate-spin`}),i(`detectionIntelligence.assignPlateDialog.createAssign`,`Create & assign`)]}):e(J,{variant:`primary`,onClick:()=>h&&x(h),disabled:C||!h,children:[C&&a(z,{className:`h-3.5 w-3.5 animate-spin`}),v>1?i(`detectionIntelligence.assignCount`,{count:v}):i(`common.assign`)]})]})]})})}l();var qo=[[`plateGallery`]];function Jo(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 Gt(Kt(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 Yo(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 Xo({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 Zo({box:e}){let{t}=X();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 Qo({plate:t,cameraName:r,onClose:i,onAssign:c,onUnassign:l,onDelete:d,actionsPending:p}){let{t:m}=X(),h=u(),{data:g,isFetching:_}=Ft({plateId:t?.plateId??``},{enabled:t!==null}),y=De(),[b,x]=s(`frame`),[S,C]=s(!1),[E,D]=s(``),{frameSrc:k,naturalWidth:A,naturalHeight:j,failed:M}=Jo(t?.keyFrameMediaId);o(()=>{C(!1),D(``),x(`frame`)},[t?.plateId]);let P=n(()=>{let e=Yo(g??[]);return e?e.url:Wo(t)},[g,t]),F=n(()=>!t?.plateBbox||A===null||j===null?null:pr(t.plateBbox,A,j),[t?.plateBbox,A,j]);if(t===null)return null;let I=t.keyFrameMediaId!==void 0&&!M,ee=I&&b===`frame`,L=t.assigned?t.vehicleName??`Assigned`:t.recognizedVehicleId?`${t.vehicleName??`Recognized`} (suggested)`:`Unassigned`,R=`${String(Math.round(t.score*100))}%${t.corrected?` · corrected`:``}`;function V(){t&&(D(t.text),C(!0))}function H(){if(!t)return;let e=E.trim().toUpperCase();if(!e||e===t.text){C(!1);return}y.mutate({plateId:t.plateId,text:e},{onSettled:()=>{h.invalidateQueries({queryKey:qo}),C(!1)}})}return a(et,{open:!0,onOpenChange:e=>!e&&i(),children:e(xt,{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:[I&&e(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[e(`button`,{type:`button`,onClick:()=>x(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${b===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(N,{className:`h-3.5 w-3.5`}),` `,m(`detectionIntelligence.detailPanel.fullFrame`)]}),e(`button`,{type:`button`,onClick:()=>x(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${b===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(ye,{className:`h-3.5 w-3.5`}),` `,m(`detectionIntelligence.detailPanel.crop`)]})]}),ee&&k?a(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:a(hr,{src:k,alt:m(`detectionIntelligence.plateDetailPanel.fullFrameWithDetectedPlate`,`Full frame with detected plate`),fit:`natural`,className:`w-full`,overlay:F?a(Zo,{box:F}):void 0})}):P?e(`div`,{className:`relative aspect-[2/1] w-full overflow-hidden rounded-lg border border-border bg-background`,children:[a(hr,{src:P,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(z,{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(f,{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`)}),S?e(`div`,{className:`flex min-w-0 flex-1 items-center justify-end gap-1.5`,children:[a(st,{value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`&&H(),e.key===`Escape`&&C(!1)},className:`h-7 max-w-[10rem] text-right font-mono text-xs uppercase`,autoFocus:!0}),a(`button`,{type:`button`,onClick:H,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(z,{className:`h-3.5 w-3.5 animate-spin`}):a(T,{className:`h-3.5 w-3.5`})}),a(`button`,{type:`button`,onClick:()=>C(!1),className:`text-foreground-subtle hover:text-foreground`,"aria-label":m(`common.cancel`,`Cancel`),children:a(B,{className:`h-3.5 w-3.5`})})]}):e(`button`,{type:`button`,onClick:V,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(O,{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(Xo,{label:m(`detectionIntelligence.plateDetailPanel.camera`,`Camera`),value:r}),a(Xo,{label:m(`detectionIntelligence.plateDetailPanel.captured`,`Captured`),value:Qn(t.timestamp)}),a(Xo,{label:m(`detectionIntelligence.plateDetailPanel.confidence`,`Confidence`),value:R}),a(Xo,{label:m(`detectionIntelligence.plateDetailPanel.vehicle`,`Vehicle`),value:L}),a(Xo,{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(J,{variant:`secondary`,onClick:()=>l(t.plateId),disabled:p,children:[a(_e,{className:`h-3.5 w-3.5`}),` `,m(`detectionIntelligence.detailPanel.detach`)]}):e(J,{variant:`primary`,onClick:()=>c(t.plateId),disabled:p,children:[a(w,{className:`h-3.5 w-3.5`}),` `,m(`common.assign`)]}),e(J,{variant:`secondary`,onClick:()=>d(t.plateId),disabled:p,children:[a(v,{className:`h-3.5 w-3.5`}),` `,m(`common.delete`)]})]})]})})}l();var $o=[[`plateGallery`]],es=500,ts=120;function ns({plate:t,cameraName:n,nowMs:r,selected:i,onToggleSelect:o,onAssign:s,onOpenDetail:c}){let{t:l}=X(),d=u(),p=Oe(),m=Pe(),h=()=>{d.invalidateQueries({queryKey:$o})},g=()=>c(t.plateId),_=Wo(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:[_===null?e(`button`,{type:`button`,onClick:g,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(f,{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:_,alt:l(`detectionIntelligence.recentPlates.plateFrom`,`Plate {{text}} from {{cameraName}}`,{text:t.text,cameraName:n}),onClick:g,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(he,{className:`h-4 w-4 text-primary`}):a(G,{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(ge,{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:Xn(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(),p.mutate({plateId:t.plateId},{onSettled:h})},disabled:p.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:p.isPending?a(z,{className:`h-4 w-4 animate-spin`}):a(_e,{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(w,{className:`h-4 w-4`})}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),m.mutate({plateId:t.plateId},{onSettled:h})},disabled:m.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:m.isPending?a(z,{className:`h-4 w-4 animate-spin`}):a(v,{className:`h-4 w-4`})})]})]})}var rs=[{labelKey:`common.all`,value:`all`},{labelKey:`detectionIntelligence.recentPlates.filterUnassigned`,value:`unassigned`},{labelKey:`detectionIntelligence.recentPlates.filterAssigned`,value:`assigned`}];function is(e,t){return t===`unassigned`?e.filter(e=>!e.assigned):t===`assigned`?e.filter(e=>e.assigned):e}function as(){let{t}=X(),r=u(),[i,o]=s(`all`),[c,l]=s(Bn),[p,m]=s(new Set),[h,g]=s(new Set),[_,y]=s(null),[b,x]=s(null),{data:S,isLoading:C}=Se({limit:es,includeCrops:!1},{refetchInterval:3e4}),{data:T=[]}=ke(),{data:E}=we({isCamera:!0,projection:`slim`}),D=Oe(),O=Me(),k=Pe(),A=Date.now(),j=S??[],M=n(()=>{let e=new Map;for(let t of E??[])e.set(t.id,t.name);return e},[E]),N=e=>M.get(e)??t(`detectionIntelligence.cameraFallback`,{id:String(e)}),P=n(()=>qn(j).map(e=>({id:e,name:N(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[j,M]),F=n(()=>Kn(Gn(is(j,i),c),p),[j,i,c,p]),I=rr(F,ts,n(()=>JSON.stringify([i,c.fromMs,c.toMs,[...p].sort((e,t)=>e-t)]),[i,c.fromMs,c.toMs,p])),ee=n(()=>new Map(j.map(e=>[e.plateId,e])),[j]),L=b===null?null:ee.get(b)??null,R=()=>{r.invalidateQueries({queryKey:$o})},V=()=>g(new Set);function H(e){g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}let U=[...h],W=O.isPending||k.isPending,te=D.isPending||k.isPending;function ne(){U.length!==0&&O.mutate({plateIds:U},{onSettled:()=>{R(),V()}})}function G(){U.length!==0&&Promise.allSettled(U.map(e=>k.mutateAsync({plateId:e}))).then(()=>{R(),V()})}function re(e){x(null),y([e])}function ie(e){D.mutate({plateId:e},{onSettled:R}),x(null)}function K(e){k.mutate({plateId:e},{onSettled:R}),x(null)}let q=F.length!==j.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:rs.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(dr,{onChange:l}),a(lr,{cameras:P,selected:p,onChange:m}),!C&&a(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:q?t(`detectionIntelligence.recentPlates.ofPlates`,`{{value1}} of {{value2}} plates`,{value1:String(F.length),value2:String(j.length)}):t(`detectionIntelligence.recentPlates.plateCount`,{count:F.length})})]}),h.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:h.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[e(J,{variant:`primary`,onClick:()=>y(U),disabled:W,children:[a(w,{className:`h-3.5 w-3.5`}),` `,t(`common.assign`)]}),e(J,{variant:`secondary`,onClick:ne,disabled:W,children:[O.isPending?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(_e,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.recentPlates.detach`,`Detach`)]}),e(J,{variant:`secondary`,onClick:G,disabled:W,children:[a(v,{className:`h-3.5 w-3.5`}),` `,t(`common.delete`)]}),a(J,{variant:`ghost`,onClick:V,disabled:W,children:a(B,{className:`h-3.5 w-3.5`})})]})]}),C?a(nt,{status:`pending`,pendingMessage:`Loading plates…`,testId:`plates-grid`}):F.length===0?a(Te,{icon:f,title:j.length>0?t(`detectionIntelligence.recentPlates.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.recentPlates.noPlatesRecognizedYet`,`No plates recognized yet`),description:j.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(nt,{status:`ready`,testId:`plates-grid`,children:I.pageItems.map(e=>a(ns,{plate:e,cameraName:N(e.deviceId),nowMs:A,selected:h.has(e.plateId),onToggleSelect:H,onAssign:e=>y([e]),onOpenDetail:x},e.plateId))}),a(or,{currentPage:I.page,totalItems:I.totalItems,pageSize:I.pageSize,onPageChange:I.setPage,itemNoun:`plates`})]}),a(Qo,{plate:L,cameraName:L?N(L.deviceId):``,onClose:()=>x(null),onAssign:re,onUnassign:ie,onDelete:K,actionsPending:te}),a(Ko,{plateIds:_,vehicles:T,onDone:()=>{y(null),V()}})]})}l();var os=[[`plateGallery`]];function ss({vehicleId:t}){let{t:n}=X(),r=u(),{data:i,isLoading:o}=Ge({vehicleId:t}),s=We();function c(e){s.mutate({vehicleId:t,sampleId:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:os})}})}return o?e(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[a(z,{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(x,{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(B,{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 cs(t){return[{key:`vehicle`,header:Y.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(Yt,{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(x,{className:`h-4 w-4 text-foreground-subtle`})})})}),a(`span`,{className:`truncate text-sm font-medium text-foreground`,children:t.name})]})},{key:`samples`,header:Y.t(`detectionIntelligence.vehiclesList.plates`,`Plates`),align:`center`,nowrap:!0,sortValue:e=>e.sampleCount,render:e=>a(Ct,{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(qe,{variant:`ghost`,size:`sm`,icon:O,"aria-label":Y.t(`detectionIntelligence.vehiclesList.edit`,`Edit {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onEdit(n)}}),a(qe,{variant:`ghost`,size:`sm`,icon:v,"aria-label":Y.t(`detectionIntelligence.vehiclesList.delete`,`Delete {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onDelete(n)}})]})}]}function ls({mode:t,vehicle:n,onClose:r}){let{t:i}=X(),c=u(),[l,d]=s(t===`edit`?n?.name??``:``),f=je(),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:os})}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(_t,{open:!0,onClose:r,title:t===`new`?`Add vehicle`:`Edit ${n?.name??`vehicle`}`,icon:x,width:t===`edit`?`xl`:`lg`,testId:`vehicles-vehicle-form`,footer:e(J,{variant:`primary`,size:`sm`,type:`button`,onClick:y,disabled:_,children:[m?a(z,{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(Mt,{label:i(`detectionIntelligence.vehiclesList.name`,`Name`),required:!0,children:a(st,{value:l,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&y()},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(ss,{vehicleId:n.id})]})]})})}function us(){let{t}=X(),r=u(),i=ne(),{data:s,isLoading:c}=ke(),l=Be(),{state:d,openNew:f,openEdit:p,close:m}=ot(),h=s??[],g=it(h,{searchText:e=>[e.name]}),v=d.mode===`edit`?h.find(e=>e.id===d.id)??null:null;o(()=>{d.mode===`edit`&&!c&&v===null&&m()},[d.mode,c,v,m]);let y=n(()=>cs({onEdit:e=>p(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:os}),d.mode===`edit`&&d.id===e.id&&m()}})})()}}),[i,m,l,d,p,r,t]);if(c)return e(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[a(z,{className:`h-4 w-4 animate-spin`}),t(`detectionIntelligence.vehiclesList.loadingVehicles`,`Loading vehicles…`)]});let b=d.mode===`new`||d.mode===`edit`&&v!==null;return e(`div`,{className:`space-y-2`,children:[a(`div`,{className:`flex flex-wrap items-center gap-2`,children:e(J,{variant:`primary`,size:`sm`,type:`button`,onClick:f,children:[a(_,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.vehiclesList.addVehicle`,`Add vehicle`)]})}),(h.length>0||g.active)&&a(bt,{state:g.state,facets:g.facets,labels:{searchPlaceholder:`Search vehicles…`,searchLabel:`Search vehicles`,facetsLabel:`Filter`,clearLabel:`Clear`},onSearch:g.setSearch,onToggleFacet:g.toggleFacet,onClear:g.clear}),g.rows.length===0?a(Te,{icon:x,title:g.active?t(`detectionIntelligence.vehiclesList.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.vehiclesList.noVehiclesEnrolledYet`,`No vehicles enrolled yet`),description:g.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(Ve,{columns:y,rows:g.rows,rowKey:e=>e.id,maxBodyHeight:Ce,emptyMessage:t(`detectionIntelligence.vehiclesList.noVehiclesEnrolledYet2`,`No vehicles enrolled yet.`),onRowClick:e=>p(e.id)}),b&&a(ls,{mode:d.mode===`new`?`new`:`edit`,vehicle:v,onClose:m})]})}l();var ds=[[`plateGallery`]],fs=2e3;function ps(){let e=u(),n=t(e);n.current=e;let r=t(void 0);r.current||=Hr({delayMs:fs,invalidate:()=>{n.current.invalidateQueries({queryKey:ds})}}),o(()=>()=>r.current?.cancel(),[]),Pt(le.PipelineAnalyticsPlateGalleryChanged,()=>{r.current?.trigger()})}function ms(){let{t}=X();return ps(),e(`div`,{className:`space-y-3`,children:[a(Xe,{headingId:`library-vehicles`,title:t(`plates.vehicles`,`Vehicles`),icon:x,testId:`library-section-vehicles`,children:e(`div`,{className:`${p} 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(us,{})]})}),a(Xe,{headingId:`library-recent-plates`,title:t(`plates.recentRecognizedPlates`,`Recent recognized plates`),icon:fe,testId:`library-section-recent-plates`,children:e(`div`,{className:`${p} 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(as,{})]})})]})}function hs(e){return e.states.length===0?3:e.latched?0:e.verdict===`diverged`?1:e.verdict===`unknown`?2:4}function gs(e){let t=[e.divergedAt,e.restoredAt].filter(e=>typeof e==`number`);return t.length===0?null:Math.max(...t)}function _s(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=hs(e.monitor)-hs(t.monitor);if(n!==0)return n;let r=gs(e.monitor)??-1,i=gs(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 vs={alarm:`danger`,ok:`success`,unknown:`default`},ys={alarm:`Alarm`,ok:`OK`,unknown:`Unknown`};function bs(e,t){let n=gs(e);return n===null?`—`:Y.t(`scenes.transitionAgo`,{duration:re(Math.max(0,t-n))})}function xs(e){return P(e.monitor).tone}function Ss(e){let t=Number(e);return Number.isFinite(t)&&t>0?t:null}function Cs(){let{t}=X(),i=we({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=Jt(l),d=n(()=>_s(c,u.results),[c,u.results]),f=it(d,{searchText:e=>[e.monitor.label,e.deviceName],facetValue:xs}),{state:p,openNew:m,openEdit:h,close:g}=ot(),[v,y]=s(null);o(()=>{if(p.mode===`new`){y(e=>e??l[0]??null);return}y(null)},[p.mode,l]);let b=p.mode===`edit`?Ss(p.id):null,x=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=>xs(e),render:e=>{let t=P(e.monitor);return a(Ct,{variant:vs[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:R(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:V(e.monitor)})},{key:`transition`,header:t(`scenes.lastChange`,`Last change`),align:`right`,nowrap:!0,sortValue:e=>gs(e.monitor)??0,render:e=>a(`span`,{className:`text-xs tabular-nums text-foreground-muted`,children:bs(e.monitor,C)})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:e=>a(J,{variant:`ghost`,onClick:()=>h(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(J,{onClick:m,disabled:c.length===0,className:`shrink-0`,children:[a(_,{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||f.active)&&a(bt,{state:f.state,facets:f.facets,labels:{searchPlaceholder:`Search scenes…`,searchLabel:`Search scenes`,facetsLabel:`State`,clearLabel:`Clear`},facetLabel:e=>ys[e]??e,onSearch:f.setSearch,onToggleFacet:f.toggleFacet,onClear:f.clear}),a(Ze,{variant:`flat`,className:`p-0`,children:a(Ve,{columns:w,rows:f.rows,rowKey:e=>`${e.deviceId}:${e.monitor.id}`,minWidthPx:880,bordered:!1,maxBodyHeight:Ce,emptyMessage:u.isLoading?t(`scenes.loadingScenes`,`Loading scenes…`):f.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.`)})}),p.mode===`new`?e(_t,{open:!0,onClose:g,title:t(`scenes.whichCamera`,`Which camera?`),icon:S,width:`sm`,testId:`scenes-camera-picker`,footer:a(J,{onClick:()=>{v!==null&&h(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($e,{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(_t,{open:!0,onClose:g,title:t(`scenes.scenes`,`Scenes — {{editingName}}`,{editingName:x}),icon:S,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(Et,{deviceId:b})})]})]})}function ws(){let{t:e}=X(),t=It(`/library`,{t:e,isAdmin:!0})??{icon:ve,title:e(`nav.library`,`Library`)};return a(Vt,{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(Kr,{})},{id:`vehicles`,label:e(`library.vehicles`,`Vehicles`),content:a(ms,{})},{id:`events`,label:e(`library.events`,`Events`),content:a(Uo,{}),ownedParams:[`section`]},{id:`scenes`,label:e(`library.scenes`,`Scenes`),content:a(Cs,{})}]})}export{ws as LibraryPage};
|