@camstack/addon-admin-ui 1.2.435 → 1.2.437
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/dist/assets/{AddonAssetIcon-DwyvMm0j.js → AddonAssetIcon-C3Ltt0yX.js} +1 -1
- package/dist/assets/Addons-CkBmnKjV.js +4 -0
- package/dist/assets/{AdminPage-Dla2hgly.js → AdminPage-B7Z1OWO3.js} +1 -1
- package/dist/assets/{AdminSectionedPage-C6laWV2D.js → AdminSectionedPage-USP4OV_Y.js} +1 -1
- package/dist/assets/AiProfiles-QWD8PlMr.js +3 -0
- package/dist/assets/{BrokerForm-XPsm7VqN.js → BrokerForm-BxmxiIRw.js} +1 -1
- package/dist/assets/Build-CXn4HT3p.js +40 -0
- package/dist/assets/{Calendars-D9aQ6xfy.js → Calendars-DN9ln21d.js} +1 -1
- package/dist/assets/Cluster-tgWdVHND.js +1 -0
- package/dist/assets/ClusterStepModel-BizBdfIU.js +1 -0
- package/dist/assets/{CompositionEditor-Djw5jKF1.js → CompositionEditor-GiDCG4Aj.js} +1 -1
- package/dist/assets/CompositionEditorPage-wfYMLlvy.js +1 -0
- package/dist/assets/Data-CmT5GPx9.js +2 -0
- package/dist/assets/DeviceDetail-moNYFDGE.js +2 -0
- package/dist/assets/{DeviceDoActionFields-DLWA9-J9.js → DeviceDoActionFields-C1LG9nW0.js} +1 -1
- package/dist/assets/{Devices-C1k3PqRv.js → Devices-837Dt931.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-Dz0lVYTn.js → EmbedPlayerPage-Crrh_6YT.js} +1 -1
- package/dist/assets/Identity-CNNb8wrU.js +1 -0
- package/dist/assets/IntegrationDetail-BER_0Zaz.js +1 -0
- package/dist/assets/IntegrationHub-BEu0isNR.js +1 -0
- package/dist/assets/Integrations-CuZucOyR.js +1 -0
- package/dist/assets/Integrations-Sjh868gF.js +1 -0
- package/dist/assets/Library-B4Nw3n28.js +1 -0
- package/dist/assets/Locations-B7dC2DyF.js +3 -0
- package/dist/assets/{Logs-C5wdcV2o.js → Logs-4XWMmfpD.js} +1 -1
- package/dist/assets/{MaskShapeCanvas-WPSz6MvT.js → MaskShapeCanvas-Bwqusno0.js} +1 -1
- package/dist/assets/{MotionZonesSettings-CxZucl1G.js → MotionZonesSettings-CZbGV_dv.js} +1 -1
- package/dist/assets/MyAccess-TAG05L5N.js +2 -0
- package/dist/assets/Network-ReY1qUoQ.js +1 -0
- package/dist/assets/{NodeAddonsSettingsPanel-CSyREPja.js → NodeAddonsSettingsPanel-DIKEaj5p.js} +1 -1
- package/dist/assets/Notifications-CqTEfaZ_.js +1 -0
- package/dist/assets/{PrivacyMaskSettings-DQ7Xe8cq.js → PrivacyMaskSettings-CTKUYU5o.js} +1 -1
- package/dist/assets/Recordings-EMQC9iqz.js +1 -0
- package/dist/assets/ScanNetworkModal-DK98Sjd4.js +1 -0
- package/dist/assets/SceneMonitorEditor-CG4pADlP.js +1 -0
- package/dist/assets/SessionsList-B1Ni2lo_.js +2 -0
- package/dist/assets/{Showroom-DZRq9gks.js → Showroom-BKLoHB4Z.js} +1 -1
- package/dist/assets/System-DEOHPmr3.js +1 -0
- package/dist/assets/{Terminal-Dt_ribAu.js → Terminal-dVu7TTAE.js} +3 -3
- package/dist/assets/{Viewer-DbBh61dj.js → Viewer-B9mEIKqz.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CEvIRFB4.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BX43JXOX.js} +1 -1
- package/dist/assets/{addon-icons-context-r49093mC.js → addon-icons-context-BjcmJD_J.js} +1 -1
- package/dist/assets/{archive-CgDcyTmT.js → archive-Bcg0gLgY.js} +1 -1
- package/dist/assets/{authed-media-CN55sP4S.js → authed-media-Cf82_ejX.js} +1 -1
- package/dist/assets/{bell-off-CdHPL528.js → bell-off-BnByNJjy.js} +1 -1
- package/dist/assets/{board-model-DXmUHcnO.js → board-model-D8m2YmcS.js} +1 -1
- package/dist/assets/{boxes-DJvrVSZy.js → boxes-V2c7jrxe.js} +1 -1
- package/dist/assets/circle-slash-B_FzZotu.js +1 -0
- package/dist/assets/client-CUuI767h.js +358 -0
- package/dist/assets/{cloud-upload-BkTrXwKr.js → cloud-upload-aziKggfg.js} +1 -1
- package/dist/assets/crop-DzZyuK_f.js +1 -0
- package/dist/assets/{device-integration-icon-CViPS882.js → device-integration-icon-3UfBj_i6.js} +1 -1
- package/dist/assets/device-picker-model-DJj6igTj.js +1 -0
- package/dist/assets/dist-DsAwO6-i.js +358 -0
- package/dist/assets/{dist-0P_zMe7Y.js → dist-t-gGaOd0.js} +1 -1
- package/dist/assets/{eraser-BCiOGK5K.js → eraser-CsYhDDbY.js} +1 -1
- package/dist/assets/{hard-drive-download-Df-zlQQG.js → hard-drive-download-CWqd_JKb.js} +1 -1
- package/dist/assets/{history-CWpQe6k9.js → history-DOf9zSG-.js} +1 -1
- package/dist/assets/{hostInit-Cnw529bc.js → hostInit-BCqJwB4Y.js} +1 -1
- package/dist/assets/i18n-RHwbGLC0.js +1 -0
- package/dist/assets/icons-BrAHwVJD.js +1 -0
- package/dist/assets/index-CeO2wVZi.js +4 -0
- package/dist/assets/index-M0Q7O5pF.css +2 -0
- package/dist/assets/{key-CZcpRn4A.js → key-D0VHbthb.js} +1 -1
- package/dist/assets/{key-round-BBPO5HDK.js → key-round-CasJ848Z.js} +1 -1
- package/dist/assets/{layers-DLOgDOBH.js → layers-CFb4zoU6.js} +1 -1
- package/dist/assets/{linked-devices-model-f_SAvOZs.js → linked-devices-model-DbkbB7KM.js} +1 -1
- package/dist/assets/{list-ordered-BaNkdvWk.js → list-ordered-B14sQnH2.js} +1 -1
- package/dist/assets/{location-owned-usage-BFxIuzRL.js → location-owned-usage-C21QUrwl.js} +1 -1
- package/dist/assets/{log-in-CL3_o1dD.js → log-in-UZRiT8Rq.js} +1 -1
- package/dist/assets/{memory-stick-CHkvUw7C.js → memory-stick-l6hXPEuG.js} +1 -1
- package/dist/assets/{message-square-plus-CIeWtcNn.js → message-square-plus-C3grB9GT.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-657dd3ff.js → mf-entry-bootstrap-0-5e54ea5d.js} +2 -2
- package/dist/assets/{mic-off-DS8OGDQW.js → mic-off-wol-RBiS.js} +1 -1
- package/dist/assets/{monitor-off-DC9Xug5Z.js → monitor-off-BUehkWHc.js} +1 -1
- package/dist/assets/{monitor-smartphone-CS_5BZqr.js → monitor-smartphone-CCDiXDn-.js} +1 -1
- package/dist/assets/mount-DJj6igTj.js +1 -0
- package/dist/assets/{notification-schedule-field-aMkV5LtX.js → notification-schedule-field-DiZ-TJBp.js} +1 -1
- package/dist/assets/player-overlays-Db_o1Zm2.js +1 -0
- package/dist/assets/{recycle-wY_-o-u0.js → recycle-BVxTT0po.js} +1 -1
- package/dist/assets/remoteEntry-DSZ__m0a.js +1 -0
- package/dist/assets/{scan-eye-A6IBODIs.js → scan-eye-C5EKCLMY.js} +1 -1
- package/dist/assets/{scissors-BzZpfzIa.js → scissors-DjP6Unuk.js} +1 -1
- package/dist/assets/{search-x-DqjVJK7_.js → search-x-gjRI7PKB.js} +1 -1
- package/dist/assets/{send-BDCQEx8-.js → send-CV6GWVOX.js} +1 -1
- package/dist/assets/{settings-2-BBgeb4tF.js → settings-2--KyzHb5N.js} +1 -1
- package/dist/assets/{speaker-Bw_8wVkA.js → speaker-CnmwOCLp.js} +1 -1
- package/dist/assets/src-CL0G8g2V.js +67 -0
- package/dist/assets/{timer-reset-CNH944ar.js → timer-reset-nORqwwje.js} +1 -1
- package/dist/assets/{ungroup-D4fdKtA6.js → ungroup-BQTGGbbf.js} +1 -1
- package/dist/assets/{unlink-BKDNubwr.js → unlink-669jprEf.js} +1 -1
- package/dist/assets/{usb-CU5DhEWn.js → usb-BT4hzhxS.js} +1 -1
- package/dist/assets/{use-scenes-feed-Bk660KRI.js → use-scenes-feed-DCExYbbk.js} +1 -1
- package/dist/assets/{use-stationary-objects-BVxOU14q.js → use-stationary-objects-DPwgtmOw.js} +1 -1
- package/dist/assets/useEventInvalidation-DJj6igTj.js +1 -0
- package/dist/assets/{useNodeUrlSelection-Bg0rHiIl.js → useNodeUrlSelection-ibxCoFYh.js} +1 -1
- package/dist/assets/user-round-NWWWc7PC.js +1 -0
- package/dist/assets/{user-x-DRzptq94.js → user-x-Drhirj9Y.js} +1 -1
- package/dist/assets/{video-CEzO-5-D.js → video-Dzs93Xor.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DzDhE-1_.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DVRZb8h3.js} +2 -2
- package/dist/index.html +11 -11
- package/dist/server/addon.js +269 -28
- package/package.json +1 -1
- package/dist/assets/Addons-N1hcMjwi.js +0 -4
- package/dist/assets/AiProfiles-CW5cr9nz.js +0 -3
- package/dist/assets/Build-Dg7gaee7.js +0 -40
- package/dist/assets/Cluster-NV3ZrTk7.js +0 -1
- package/dist/assets/ClusterStepModel-BUROhnKA.js +0 -1
- package/dist/assets/CompositionEditorPage-BNAhOgDE.js +0 -1
- package/dist/assets/Data-Bkq3Cr_h.js +0 -2
- package/dist/assets/DeviceDetail-BR_FSl-i.js +0 -2
- package/dist/assets/Identity-CJN1MNrJ.js +0 -1
- package/dist/assets/IntegrationDetail-DomJ4oV8.js +0 -1
- package/dist/assets/IntegrationHub-BTJM3uSD.js +0 -1
- package/dist/assets/Integrations-B3EhTwi-.js +0 -1
- package/dist/assets/Integrations-w1Zb-AYc.js +0 -1
- package/dist/assets/Library-BLUxFISX.js +0 -1
- package/dist/assets/Locations-5WWzr64x.js +0 -3
- package/dist/assets/MyAccess-2bAujGDI.js +0 -2
- package/dist/assets/Network-DFt5Vib8.js +0 -1
- package/dist/assets/Notifications-KG9O3i8q.js +0 -1
- package/dist/assets/Recordings-BbQTlUaN.js +0 -1
- package/dist/assets/ScanNetworkModal-Dw7_YiJk.js +0 -1
- package/dist/assets/SceneMonitorEditor-CQtUJ-Cg.js +0 -1
- package/dist/assets/SessionsList-BuiRHWv-.js +0 -2
- package/dist/assets/System-n6EeqhH2.js +0 -1
- package/dist/assets/circle-slash-BvkFL8F1.js +0 -1
- package/dist/assets/client-CVIfL49c.js +0 -358
- package/dist/assets/crop-DUVdBcFC.js +0 -1
- package/dist/assets/device-picker-model-mxypQ5EF.js +0 -1
- package/dist/assets/dist-U5_IP253.js +0 -358
- package/dist/assets/i18n-CmGpgquB.js +0 -1
- package/dist/assets/icons-aI8aLvw4.js +0 -1
- package/dist/assets/index-DKqvG7BE.css +0 -2
- package/dist/assets/index-DkNBNJNl.js +0 -4
- package/dist/assets/mount-mxypQ5EF.js +0 -1
- package/dist/assets/octagon-alert-Cdtac8l_.js +0 -1
- package/dist/assets/player-overlays-CZXV2ES3.js +0 -1
- package/dist/assets/remoteEntry-BFNP-i5_.js +0 -1
- package/dist/assets/src-DOs8Kg5s.js +0 -67
- package/dist/assets/useEventInvalidation-mxypQ5EF.js +0 -1
- package/dist/assets/user-round-CYlbEszq.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{$ as e,B as t,G as n,J as r,L as i,S as a,Z as o,a as s,b as c,o as l,q 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-CEHpkaJP.js";import{At as f,Ci as p,D as m,Di as h,Dt as g,Hr as _,It as v,Jt as y,Nr as b,Nt as x,On as S,Pn as C,Q as w,Qi as T,Ut as E,Xt as D,Yr as O,Z as k,_i as A,_n as j,ar as M,bi as N,c as P,dn as F,dt as I,f as L,gr as R,l as z,ot as ee,pn as B,qt as V,ri as H,rr as U,u as W,vi as G,wi as te,wr as K,yi as q,yn as ne,z as re}from"./player-overlays-CZXV2ES3.js";import{a as J,c as ie,i as ae,n as oe,o as se,r as ce,s as le,t as ue}from"./user-x-DRzptq94.js";import{s as de}from"./video-CEzO-5-D.js";import{t as fe}from"./crop-DUVdBcFC.js";import{t as pe}from"./user-round-CYlbEszq.js";import{Ti as me,Un as he}from"./client-CVIfL49c.js";import{$a as ge,$l as _e,An as ve,Bn as Y,Cc as ye,Dn as be,Dr as xe,Ec as Se,G as Ce,Ga as we,Gl as Te,I as Ee,It as De,Ja as Oe,Jl as ke,Jo as Ae,Ka as je,L as Me,Ln as Ne,Nt as Pe,On as Fe,Pn as Ie,Pt as Le,Qa as Re,Qn as ze,Rn as Be,Sc as Ve,Tc as He,Tn as Ue,Ut as We,Vt as Ge,Wl as Ke,Wt as qe,Xa as Je,Xn as Ye,Ya as Xe,Za as Ze,Zn as Qe,_c as $e,ar as et,bc as tt,eo as nt,eu as rt,fn as it,fs as at,gc as ot,gs as st,ha as ct,hc as lt,ir as ut,jn as dt,kn as ft,mc as pt,ms as mt,no as ht,ps as gt,pt as _t,qa as vt,ro as yt,rr as bt,t as xt,to as St,us as Ct,vc as wt,vs as Tt,vu as Et,wc as Dt,xc as Ot,yc as kt,ys as At,z as jt}from"./src-DOs8Kg5s.js";import{t as X}from"./i18n-CmGpgquB.js";import{t as Z}from"./useTranslation-D3Is_4B6.js";import"./mount-mxypQ5EF.js";import{C as Mt,Q as Nt,Y as Pt,Z as Ft,et as It}from"./index-DkNBNJNl.js";import{t as Lt}from"./AdminSectionedPage-C6laWV2D.js";import{t as Rt}from"./use-stationary-objects-BVxOU14q.js";import{a as zt,i as Bt,n as Vt,r as Ht,t as Ut}from"./authed-media-CN55sP4S.js";import{t as Wt}from"./use-scenes-feed-Bk660KRI.js";e();function Gt({mediaId:e,base64:t,alt:n,className:r,placeholder:i}){let{src:a,failed:o}=zt(e===void 0?void 0:Ht(e));return a===null?(e===void 0||o)&&t!==void 0&&t!==``?d(`img`,{src:`data:image/jpeg;base64,${t}`,alt:n,className:r}):i:d(`img`,{src:a,alt:n,className:r})}var Kt=`pipeline-analytics`,qt=`photo.analyze`,Jt=`photo.enroll`,Yt=`photo.discard`,Xt=18*1024*1024;function Zt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Qt(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function $t(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function en(e,t){let n=e[t];return typeof n==`boolean`?n:null}function tn(e){if(!Zt(e))return null;let t=$t(e,`x`),n=$t(e,`y`),r=$t(e,`width`),i=$t(e,`height`);return t===null||n===null||r===null||i===null?null:{x:t,y:n,width:r,height:i}}function nn(e){if(!Zt(e))return null;let t=$t(e,`detectionShortSidePx`),n=$t(e,`score`);if(t===null||n===null)return null;let r=$t(e,`magnitude`);return{detectionShortSidePx:t,score:n,...r===null?{}:{magnitude:r}}}function rn(e){if(!Zt(e))return null;let t=$t(e,`faceIndex`),n=$t(e,`score`),r=en(e,`enrollable`),i=tn(e.bbox),a=nn(e.quality);if(t===null||n===null||r===null||i===null||a===null)return null;let o=Qt(e,`refusedReason`),s=Qt(e,`alignedCropBase64`),c=Qt(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 an(e){if(!Zt(e))return null;let t=Qt(e,`sessionId`),n=Qt(e,`ranOnNodeId`),r=e.faces;if(t===null||n===null||!Array.isArray(r))return null;let i=[];for(let e of r){let t=rn(e);t!==null&&i.push(t)}return{sessionId:t,ranOnNodeId:n,faces:i}}function on(e){if(!Zt(e))return null;let t=Qt(e,`sampleId`),n=Qt(e,`identityId`),r=Qt(e,`modelId`);return t===null||n===null||r===null?null:{sampleId:t,identityId:n,modelId:r}}function sn(e,t,n){let r={...e};return n===null||n===``?delete r[t]:r[t]=n,r}function cn(e,t){return e.filter(e=>e.enrollable&&t[e.faceIndex]!==void 0).length}function ln(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 un(e){switch(e){case`no-embedding`:return X.t(`helpers.photoEnroll.refusal.noEmbedding`);case`no-model-id`:return X.t(`helpers.photoEnroll.refusal.noModelId`);case`no-aligned-crop`:return X.t(`helpers.photoEnroll.refusal.noAlignedCrop`);case`magnitude`:return X.t(`helpers.photoEnroll.refusal.magnitude`);default:return X.t(`helpers.photoEnroll.refusal.default`)}}function dn(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 fn(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 pn(e,t,n){return e.map(e=>e.photoIndex===t?{...e,...n}:e)}function mn(e,t){return`${e}:${t}`}function hn(e,t,n,r){let i=sn(e[t]??{},n,r),a={...e};return Object.keys(i).length===0?delete a[t]:a[t]=i,a}function gn(e,t){let n=0;for(let r of e)r.analysis!==void 0&&(n+=cn(r.analysis.faces,t[r.photoIndex]??{}));return n}var _n=`__new__`;function vn(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[mn(i.photoIndex,t.faceIndex)]??``).trim();if(a===``)return{kind:`error`,message:X.t(`helpers.photoEnrollBatch.newPersonNoName`,{filename:i.filename,face:t.faceIndex+1})};r.includes(a)||r.push(a)}}return{kind:`ok`,names:r}}function yn(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[mn(e,a)]??``).trim()];s!==void 0&&(o[a]=s)}r[e]=o}return r}function bn(e,t){let n=[];for(let r of e){if(r.analysis===void 0)continue;let e=ln(r.analysis.sessionId,r.analysis.faces,t[r.photoIndex]??{});for(let t of e)n.push({photoIndex:r.photoIndex,request:t})}return n}function xn(e){return/expired/i.test(e)}function Sn(e){return e instanceof Error?e.message:String(e)}async function Cn(e,t,n){let r=new Map(e.map(e=>[e.photoIndex,e])),i={},a=[],o=0,s=null,c=(e,t)=>{let n=r.get(e)?.filename??X.t(`helpers.photoEnrollBatch.photoFallback`,{n:e+1});return X.t(`helpers.photoEnrollBatch.faceLabel`,{filename:n,face:t+1})};for(let l of bn(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=Sn(t);if(!xn(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 (${Sn(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)}: ${Sn(e)}`)}}}return{enrolled:o,stampedModelId:s,failures:a,refreshedAnalyses:i}}var wn=[[`faceGallery`]],Tn=``;function En(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 Dn(e){return e instanceof Error?e.message:String(e)}function On({face:e,identities:t,value:r,onChange:i,disabled:o}){let{t:s}=Z(),l=n(()=>[{value:Tn,label:s(`detectionIntelligence.photoEnrollDialog.ignoreThisFace`,`Ignore this face`)},...t.map(e=>({value:e.id,label:e.name})),{value:_n,label:s(`detectionIntelligence.photoEnrollDialog.newPerson`,`+ New person…`)}],[t,s]);return a(`div`,{className:`rounded-md border border-border bg-surface p-2`,children:[d(`div`,{className:`mb-2 aspect-square w-full overflow-hidden rounded border border-border bg-surface-hover`,children:e.alignedCropBase64?d(`img`,{src:`data:image/jpeg;base64,${e.alignedCropBase64}`,alt:s(`detectionIntelligence.photoEnrollDialog.face`,`Face {{value1}}`,{value1:e.faceIndex+1}),className:`h-full w-full object-cover`}):d(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:d(pe,{className:`h-8 w-8`})})}),d(`div`,{className:`min-h-[4.75rem]`,children:e.enrollable?a(c,{children:[d(ke,{options:l,value:r,disabled:o,onChange:e=>i(e.target.value),"aria-label":s(`detectionIntelligence.photoEnrollDialog.assignFace`,`Assign face {{value1}}`,{value1:e.faceIndex+1})}),a(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:[Math.round(e.quality.detectionShortSidePx),` px`,e.modelId?` · ${e.modelId}`:``]})]}):a(`div`,{className:`space-y-1`,children:[d(et,{variant:`warning`,className:`text-[10px]`,children:s(`detectionIntelligence.photoEnrollDialog.notUsable`,`Not usable`)}),d(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:un(e.refusedReason)})]})})]})}function kn({photo:e,identities:t,draft:n,newNames:r,disabled:i,onAssign:o,onNameChange:s,onRetry:c}){let{t:l}=Z(),u=e.analysis?.faces??[],f=n[e.photoIndex]??{};return a(`div`,{className:`space-y-2`,children:[a(`div`,{className:`flex items-center gap-2 border-b border-border pb-1`,children:[d(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.filename}),e.status===`analyzing`||e.status===`queued`?a(`span`,{className:`flex items-center gap-1 text-xs text-foreground-subtle`,children:[d(M,{className:`h-3 w-3 animate-spin`}),` `,l(`detectionIntelligence.photoEnrollDialog.analysing`)]}):null,e.status===`analyzed`&&e.analysis!==void 0&&d(`span`,{className:`text-xs text-foreground-subtle`,children:l(`detectionIntelligence.photoEnrollDialog.facesAnalysedOn`,{count:u.length,node:e.analysis.ranOnNodeId})}),e.status===`failed`&&a(Y,{variant:`secondary`,size:`sm`,disabled:i,onClick:c,children:[d(j,{className:`h-3 w-3`}),` `,l(`common.retry`)]})]}),e.status===`failed`&&a(`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:[d(x,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),a(`span`,{children:[l(`detectionIntelligence.photoEnrollDialog.thisPhotoCouldNotBe`,`This photo could not be analysed:`),` `,e.error??l(`detectionIntelligence.photoEnrollDialog.unknownError`,`unknown error`),`. The other photos are unaffected.`]})]}),e.status===`analyzed`&&u.length===0&&d(`p`,{className:`text-xs text-foreground-subtle`,children:l(`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.`)}),u.length>0&&d(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(7rem,7rem))] justify-start gap-3`,children:u.map(e=>d(On,{face:e,identities:t,value:f[e.faceIndex]??Tn,disabled:i,onChange:t=>o(e.faceIndex,t)},e.faceIndex))}),u.filter(e=>f[e.faceIndex]===_n).map(t=>a(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`w-28 shrink-0 truncate text-xs text-foreground-subtle`,children:l(`detectionIntelligence.photoEnrollDialog.faceN`,{n:t.faceIndex+1})}),d(`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:l(`detectionIntelligence.photoEnrollDialog.newPersonNameTypeThe`,`New person name… (type the same name under another face to reuse it)`),value:r[mn(e.photoIndex,t.faceIndex)]??``,onChange:e=>s(t.faceIndex,e.target.value)})]},t.faceIndex))]})}function An({open:e,onOpenChange:t}){let{t:o}=Z(),s=ee(),c=l(),f=u(null),{data:p}=Je(),m=je(),[h,g]=r([]),[_,v]=r(!1),[y,b]=r(null),[S,C]=r({}),[w,T]=r({}),[E,D]=r(null),O=n(()=>(p??[]).map(e=>({id:e.id,name:e.name})),[p]),k=h.some(e=>e.status===`queued`||e.status===`analyzing`),A=k||_,j=i(e=>{for(let t of e){let e=t.analysis?.sessionId;e!==void 0&&s.trpcClient.addons.custom.mutate({addonId:Kt,action:Yt,input:{sessionId:e}}).catch(()=>void 0)}},[s]),N=i(()=>{g([]),C({}),T({}),b(null),D(null),f.current&&(f.current.value=``)},[]),P=i(()=>{j(h),N(),t(!1)},[j,t,h,N]),F=i(async e=>{let t=an(await s.trpcClient.addons.custom.mutate({addonId:Kt,action:qt,input:{photoBase64:e.photoBase64,filename:e.filename}}));if(t===null)throw Error(`the server replied with something this page could not read`);return t},[s]),I=i(async e=>{g(t=>pn(t,e.photoIndex,{status:`analyzing`,error:void 0}));try{let t=await F(e);g(n=>pn(n,e.photoIndex,{status:`analyzed`,analysis:t}))}catch(t){g(n=>pn(n,e.photoIndex,{status:`failed`,error:Dn(t)}))}},[F]),L=i(async e=>{if(e.length===0)return;j(h),N();let t=dn(e,{maxCount:12,maxBytes:Xt}),n=[];t.oversize.length>0&&n.push(`Over the ${Math.round(Xt/(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 En(e),status:`queued`})))}catch(e){b(Dn(e));return}g(r),await fn(r,2,e=>I(e))},[j,h,N,I]),R=gn(h,S),z=i(async()=>{v(!0),b(null),D(null);try{let e=vn(h,S,w);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 Cn(h,yn(S,w,t),{enroll:async e=>{let t=on(await s.trpcClient.addons.custom.mutate({addonId:Kt,action:Jt,input:e}));if(t===null)throw Error(`unreadable reply`);return t},reanalyze:e=>F(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}})),c.invalidateQueries({queryKey:wn}),n.failures.length>0&&b(n.failures.join(` · `)),D(n.enrolled===0?`Nothing was enrolled.`:`Enrolled ${n.enrolled} sample${n.enrolled===1?``:`s`}${n.stampedModelId===null?``:` with ${n.stampedModelId}`}.`)}catch(e){b(Dn(e))}finally{v(!1)}},[F,m,S,w,h,c,s]),B=h.filter(e=>e.status===`analyzed`).length;return d(Ue,{open:e,onOpenChange:e=>e?t(!0):P(),children:a(be,{className:`max-w-3xl`,children:[a(ve,{children:[d(dt,{children:o(`detectionIntelligence.photoEnrollDialog.enrolFromPhotos`,`Enrol from photos`)}),d(Fe,{children:o(`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.`)})]}),d(`div`,{className:`rounded-md border border-border bg-surface-hover px-3 py-2 text-xs text-foreground-subtle`,children:d(Pt,{i18nKey:`detectionIntelligence.photoEnrollDialog.reliableRecognition`,components:{strong:d(`strong`,{})}})}),a(`div`,{className:`flex items-center gap-2`,children:[d(`input`,{ref:f,type:`file`,accept:`image/jpeg,image/png,image/webp`,multiple:!0,className:`hidden`,onChange:e=>void L(Array.from(e.target.files??[]))}),a(Y,{variant:`secondary`,size:`sm`,disabled:A,onClick:()=>f.current?.click(),children:[k?d(M,{className:`h-3.5 w-3.5 animate-spin`}):d(se,{className:`h-3.5 w-3.5`}),o(`detectionIntelligence.photoEnrollDialog.choosePhotos`,`Choose photos`)]}),h.length>0&&d(`span`,{className:`text-xs text-foreground-subtle`,children:o(`detectionIntelligence.photoEnrollDialog.photosAnalysed`,{done:B,count:h.length})})]}),d(`div`,{className:`min-h-11`,"aria-live":`polite`,children:y===null?E===null?null:d(`div`,{className:`rounded-md border border-success/40 bg-success/10 px-3 py-2 text-xs text-success`,children:E}):a(`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:[d(x,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),d(`span`,{children:y})]})}),h.length>0&&d(`div`,{className:`max-h-[50vh] space-y-4 overflow-y-auto pr-1`,children:h.map(e=>d(kn,{photo:e,identities:O,draft:S,newNames:w,disabled:A,onAssign:(t,n)=>C(r=>hn(r,e.photoIndex,t,n===Tn?null:n)),onNameChange:(t,n)=>T(r=>({...r,[mn(e.photoIndex,t)]:n})),onRetry:()=>void I(e)},e.photoIndex))}),a(ft,{children:[d(Y,{variant:`secondary`,onClick:P,disabled:_,children:o(`common.close`,`Close`)}),a(Y,{variant:`primary`,onClick:()=>void z(),disabled:A||R===0,children:[_?d(M,{className:`h-3.5 w-3.5 animate-spin`}):null,o(`detectionIntelligence.photoEnrollDialog.enrolFaces`,{count:R})]})]})]})})}e();var jn=[[`faceGallery`]];function Mn({identityId:e}){let{t}=Z(),n=l(),{data:r,isLoading:i}=Ze({identityId:e}),o=ge();function s(t){o.mutate({identityId:e,sampleId:t.id},{onSettled:()=>{n.invalidateQueries({queryKey:jn})}})}return i?a(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[d(M,{className:`h-3.5 w-3.5 animate-spin`}),t(`detectionIntelligence.peopleList.loadingSamples`,`Loading samples…`)]}):!r||r.length===0?d(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:t(`detectionIntelligence.peopleList.noSamplesYet`,`No samples yet.`)}):d(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:r.map(e=>a(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[e.base64?d(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:t(`detectionIntelligence.peopleList.sample`,`Sample`),className:`h-full w-full object-cover`}):d(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:d(pe,{className:`h-6 w-6`})}),e.source===`photo`&&d(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 p-0.5 text-white`,title:t(`detectionIntelligence.peopleList.enrolledFromAnUploadedPhoto`,`Enrolled from an uploaded photo`),children:d(se,{className:`h-3 w-3`})}),d(`button`,{type:`button`,onClick:()=>s(e),disabled:o.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":t(`detectionIntelligence.peopleList.removeSample`,`Remove sample`),children:d(I,{className:`h-4 w-4 text-white`})})]},e.id))})}function Nn(e){return[{key:`person`,header:X.t(`detectionIntelligence.peopleList.person`,`Person`),sortValue:e=>e.name,render:e=>a(`span`,{className:`flex min-w-0 items-center gap-2`,children:[d(`span`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:d(Gt,{mediaId:e.coverMediaId,base64:e.coverBase64,alt:e.name,className:`h-full w-full object-cover`,placeholder:d(`span`,{className:`flex h-full w-full items-center justify-center`,children:d(pe,{className:`h-4 w-4 text-foreground-subtle`})})})}),d(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})]})},{key:`samples`,header:X.t(`detectionIntelligence.peopleList.samples`,`Samples`),align:`center`,nowrap:!0,sortValue:e=>e.sampleCount,render:e=>d(et,{variant:`default`,className:`text-[10px]`,children:e.sampleCount})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:t=>a(`span`,{className:`flex items-center justify-end gap-1`,children:[d(rt,{variant:`ghost`,size:`sm`,icon:C,"aria-label":X.t(`detectionIntelligence.peopleList.edit`,`Edit {{name}}`,{name:t.name}),onClick:n=>{n.stopPropagation(),e.onEdit(t)}}),d(rt,{variant:`ghost`,size:`sm`,icon:v,"aria-label":X.t(`detectionIntelligence.peopleList.delete`,`Delete {{name}}`,{name:t.name}),onClick:n=>{n.stopPropagation(),e.onDelete(t)}})]})}]}function Pn({mode:e,identity:n,onClose:i}){let{t:o}=Z(),s=l(),[c,u]=r(e===`edit`?n?.name??``:``),f=je(),p=nt();t(()=>{u(e===`edit`?n?.name??``:``)},[e,n?.id,n?.name]);let m=f.isPending||p.isPending,h=c.trim(),g=e===`edit`&&n!==null&&h===n.name,_=m||h.length===0||g;function v(){s.invalidateQueries({queryKey:jn})}function y(){if(!_){if(e===`new`){f.mutate({name:h},{onSuccess:()=>{v(),i()}});return}if(n===null){i();return}p.mutate({id:n.id,name:h},{onSuccess:()=>{v(),i()}})}}return d(jt,{open:!0,onClose:i,title:e===`new`?`Add person`:`Edit ${n?.name??`person`}`,icon:pe,width:e===`edit`?`xl`:`lg`,testId:`people-person-form`,footer:a(Y,{variant:`primary`,size:`sm`,type:`button`,onClick:y,disabled:_,children:[m?d(M,{className:`h-3.5 w-3.5 animate-spin`}):null,e===`new`?o(`common.add`,`Add`):o(`common.save`,`Save`)]}),children:a(`div`,{className:`space-y-4`,children:[d(Ce,{label:o(`detectionIntelligence.peopleList.name`,`Name`),required:!0,children:d(_e,{value:c,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&y()},placeholder:o(`detectionIntelligence.peopleList.personName`,`Person name…`),autoFocus:!0})}),e===`edit`&&n!==null&&a(`div`,{children:[d(`p`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:o(`detectionIntelligence.peopleList.trainingSamples`,`Training samples`)}),d(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:o(`detectionIntelligence.peopleList.removeASampleToDrop`,`Remove a sample to drop it from recognition training for this person.`)}),d(Mn,{identityId:n.id})]})]})})}function Fn(){let{t:e}=Z(),i=l(),o=Qe(),{data:s,isLoading:c}=Je(),u=Oe(),{state:f,openNew:p,openEdit:m,close:h}=Me(),[g,_]=r(!1),v=s??[],y=Pe(v,{searchText:e=>[e.name]}),b=f.mode===`edit`?v.find(e=>e.id===f.id)??null:null;t(()=>{f.mode===`edit`&&!c&&b===null&&h()},[f.mode,c,b,h]);let x=n(()=>Nn({onEdit:e=>m(e.id),onDelete:t=>{(async()=>{await o({title:e(`detectionIntelligence.peopleList.deletePerson`,`Delete person`),message:e(`detectionIntelligence.peopleList.deleteAndAllTheirSamples`,`Delete {{name}} and all their samples? This cannot be undone.`,{name:t.name}),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&u.mutate({id:t.id},{onSettled:()=>{i.invalidateQueries({queryKey:jn}),f.mode===`edit`&&f.id===t.id&&h()}})})()}}),[o,h,u,f,m,i,e]);if(c)return a(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[d(M,{className:`h-4 w-4 animate-spin`}),e(`detectionIntelligence.peopleList.loadingPeople`,`Loading people…`)]});let C=f.mode===`new`||f.mode===`edit`&&b!==null;return a(`div`,{className:`space-y-2`,children:[a(`div`,{className:`flex flex-wrap items-center gap-2`,children:[a(Y,{variant:`primary`,size:`sm`,type:`button`,onClick:p,children:[d(S,{className:`h-3.5 w-3.5`}),e(`detectionIntelligence.peopleList.addPerson`,`Add person`)]}),a(Y,{variant:`secondary`,size:`sm`,type:`button`,onClick:()=>_(!0),children:[d(se,{className:`h-3.5 w-3.5`}),e(`detectionIntelligence.peopleList.enrolFromAPhoto`,`Enrol from a photo`)]})]}),(v.length>0||y.active)&&d(Le,{state:y.state,facets:y.facets,labels:{searchPlaceholder:`Search people…`,searchLabel:`Search people`,facetsLabel:`Filter`,clearLabel:`Clear`},onSearch:y.setSearch,onToggleFacet:y.toggleFacet,onClear:y.clear}),y.rows.length===0?d(Be,{icon:pe,title:y.active?e(`detectionIntelligence.peopleList.nothingMatchesTheFilter`,`Nothing matches the filter`):e(`detectionIntelligence.peopleList.noPeopleEnrolledYet`,`No people enrolled yet`),description:y.active?e(`detectionIntelligence.peopleList.clearTheSearchOrTry`,`Clear the search or try another name.`):e(`detectionIntelligence.peopleList.addAPersonOrEnrol`,`Add a person, or enrol faces from a photo.`)}):d(We,{columns:x,rows:y.rows,rowKey:e=>e.id,maxBodyHeight:qe,emptyMessage:e(`detectionIntelligence.peopleList.noPeopleEnrolledYet2`,`No people enrolled yet.`),onRowClick:e=>m(e.id)}),C&&d(Pn,{mode:f.mode===`new`?`new`:`edit`,identity:b,onClose:h}),d(An,{open:g,onOpenChange:_})]})}var In={fromMs:null,toMs:null},Ln=36e5,Rn=24*Ln;function zn(e,t){switch(e){case`24h`:return{fromMs:t-Rn,toMs:null};case`7d`:return{fromMs:t-7*Rn,toMs:null};case`30d`:return{fromMs:t-30*Rn,toMs:null};case`all`:return In}}function Bn(e){return e.fromMs!==null||e.toMs!==null}function Vn(e,t){return Bn(t)?e.filter(e=>!(t.fromMs!==null&&e.timestamp<t.fromMs||t.toMs!==null&&e.timestamp>t.toMs)):[...e]}function Hn(e,t){return t.size===0?[...e]:e.filter(e=>t.has(e.deviceId))}function Un(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 Wn(e){if(!e)return null;let t=Date.parse(`${e}T00:00:00`);return Number.isNaN(t)?null:t}function Gn(e){if(!e)return null;let t=Date.parse(`${e}T23:59:59.999`);return Number.isNaN(t)?null:t}function Kn(e,t){if(!Number.isFinite(e)||e<=0)return`—`;let n=t-e;return n<6e4?X.t(`helpers.relativeTime.justNow`):n<Ln?X.t(`helpers.relativeTime.minutesAgo`,{count:Math.floor(n/6e4)}):n<Rn?X.t(`helpers.relativeTime.hoursAgo`,{count:Math.floor(n/Ln)}):n<7*Rn?X.t(`helpers.relativeTime.daysAgo`,{count:Math.floor(n/Rn)}):new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function qn(e){return!Number.isFinite(e)||e<=0?`—`:new Date(e).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function Jn(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 Yn(e){let t=e.cropUrl!==void 0&&e.cropUrl.length>0,n=e.base64!==void 0&&e.base64.length>0;return!t&&!n}function Xn(e){return e.filter(Yn).map(e=>e.faceId)}function Zn(e){let t=0;for(let n of e)Yn(n)&&(t+=1);return t}function Qn(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}e();function $n(e,i,a){let[o,s]=r(1);t(()=>{s(1)},[a]);let c=e.length,l=Math.max(1,Math.ceil(c/i)),u=Math.min(o,l);return t(()=>{u!==o&&s(u)},[u,o]),{page:u,setPage:s,pageItems:n(()=>{let t=(u-1)*i;return e.slice(t,t+i)},[e,u,i]),totalPages:l,totalItems:c,pageSize:i}}var er=2;function tr(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-er),i=Math.min(t-1,e+er);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 nr({currentPage:e,totalItems:t,pageSize:n,onPageChange:r,itemNoun:i=`items`}){let{t:o}=Z();if(t<=n)return null;let s=Math.ceil(t/n),c=(e-1)*n+1,l=Math.min(e*n,t),u=tr(e,s),f=`inline-flex h-7 min-w-7 items-center justify-center rounded-md px-2 text-[11px] transition-colors disabled:opacity-40`;return a(`div`,{className:`flex items-center justify-between gap-4 flex-wrap pt-2 text-[11px] text-foreground-subtle`,children:[d(`span`,{children:o(`galleryPager.showing`,{from:c,to:l,total:t,noun:i})}),a(`div`,{className:`flex items-center gap-1`,children:[d(`button`,{type:`button`,className:`${f} hover:bg-surface-hover`,onClick:()=>r(e-1),disabled:e<=1,"aria-label":o(`galleryPager.previousPage`,`Previous page`),children:d(G,{className:`h-3.5 w-3.5`})}),u.map(t=>t.kind===`ellipsis`?d(`span`,{className:`px-1 opacity-60`,children:`…`},`ellipsis-${t.side}`):d(`button`,{type:`button`,className:`${f} ${t.n===e?`bg-primary/12 text-primary font-medium`:`hover:bg-surface-hover hover:text-foreground`}`,onClick:()=>r(t.n),"aria-current":t.n===e?`page`:void 0,children:t.n},t.n)),d(`button`,{type:`button`,className:`${f} hover:bg-surface-hover`,onClick:()=>r(e+1),disabled:e>=s,"aria-label":o(`galleryPager.nextPage`,`Next page`),children:d(A,{className:`h-3.5 w-3.5`})})]})]})}e();var rr=[[`faceGallery`]];function ir({faceIds:e,identities:t,onDone:n}){let{t:i}=Z(),o=l(),s=we(),c=je(),[u,f]=r(``),[p,m]=r(!1),[h,g]=r(null),_=e!==null&&e.length>0,v=e?.length??0;function y(){m(!1),f(``),g(null)}function b(){y(),n()}function x(t){!e||e.length===0||s.mutate({faceIds:[...e],identityId:t},{onSettled:()=>{o.invalidateQueries({queryKey:rr}),b()}})}function S(){!e||!u.trim()||c.mutate({name:u.trim()},{onSuccess:e=>{e?.id&&x(e.id)},onError:()=>{o.invalidateQueries({queryKey:rr}),b()}})}let C=s.isPending||c.isPending;return d(Ue,{open:_,onOpenChange:e=>!e&&b(),children:a(be,{children:[a(ve,{children:[d(dt,{children:v>1?i(`detectionIntelligence.assignDialog.assignFacesToPerson`,`Assign {{value1}} faces to person`,{value1:String(v)}):i(`detectionIntelligence.assignDialog.assignFaceToPerson`,`Assign face to person`)}),d(Fe,{children:i(`detectionIntelligence.assignDialog.selectAnExistingPersonOr`,`Select an existing person or create a new one.`)})]}),d(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:t.map(e=>a(`button`,{type:`button`,onClick:()=>g(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${h===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[d(`span`,{className:`font-medium`,children:e.name}),d(`span`,{className:`ml-2 text-foreground-subtle`,children:i(`detectionIntelligence.assignDialog.samples`,{count:e.sampleCount})})]},e.id))}),d(`div`,{className:`min-h-[2.75rem] border-t border-border pt-2`,children:p?d(`div`,{className:`flex items-center gap-2`,children:d(_e,{placeholder:i(`detectionIntelligence.assignDialog.newPersonName`,`New person name…`),value:u,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&S()},autoFocus:!0,className:`flex-1`})}):d(`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…`)})}),a(ft,{className:`min-h-[2.75rem]`,children:[d(Y,{variant:`secondary`,onClick:b,disabled:C,children:i(`common.cancel`,`Cancel`)}),p?a(Y,{variant:`primary`,onClick:S,disabled:C||!u.trim(),children:[C&&d(M,{className:`h-3.5 w-3.5 animate-spin`}),i(`detectionIntelligence.assignDialog.createAssign`,`Create & assign`)]}):a(Y,{variant:`primary`,onClick:()=>h&&x(h),disabled:C||!h,children:[C&&d(M,{className:`h-3.5 w-3.5 animate-spin`}),v>1?i(`detectionIntelligence.assignCount`,{count:v}):i(`common.assign`)]})]})]})})}e();function ar({cameras:e,selected:n,onChange:i}){let{t:o}=Z(),[s,c]=r(!1),l=u(null);t(()=>{if(!s)return;function e(e){l.current&&e.target instanceof Node&&!l.current.contains(e.target)&&c(!1)}function t(e){e.key===`Escape`&&c(!1)}return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[s]);function f(e){let t=new Set(n);t.has(e)?t.delete(e):t.add(e),i(t)}let p=n.size,m=p===0?`All cameras`:p===1?e.find(e=>n.has(e.id))?.name??`1 camera`:`${String(p)} cameras`;return a(`div`,{ref:l,className:`relative`,children:[a(`button`,{type:`button`,onClick:()=>c(e=>!e),disabled:e.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:[d(te,{className:`h-3.5 w-3.5`}),d(`span`,{className:`max-w-[10rem] truncate`,children:m}),d(q,{className:`h-3 w-3 opacity-70`})]}),s&&a(`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&&d(`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:o(`detectionIntelligence.cameraMultiSelect.clearSelection`,`Clear selection`)}),e.map(e=>{let t=n.has(e.id);return a(`button`,{type:`button`,onClick:()=>f(e.id),className:`flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-xs transition-colors ${t?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[d(`span`,{className:`flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded-sm border ${t?`border-primary bg-primary text-white`:`border-border`}`,children:t&&d(N,{className:`h-2.5 w-2.5`})}),d(`span`,{className:`truncate`,children:e.name})]},e.id)})]})]})}e();var or=[{label:`24h`,value:`24h`},{label:`7d`,value:`7d`},{label:`30d`,value:`30d`},{labelKey:`common.all`,value:`all`}];function sr({onChange:e}){let{t}=Z(),[n,i]=r(`all`),[o,s]=r(``),[c,l]=r(``);function u(t){i(t),s(``),l(``),e(zn(t,Date.now()))}function f(t,n){i(`custom`),s(t),l(n),e({fromMs:Wn(t),toMs:Gn(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 a(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:or.map(e=>d(`button`,{type:`button`,onClick:()=>u(e.value),className:`rounded px-2.5 py-1 text-[11px] transition-colors ${n===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:t(e.labelKey)},e.value))}),a(`div`,{className:`flex items-center gap-1`,children:[d(`input`,{type:`date`,"aria-label":t(`detectionIntelligence.dateRangeFilter.fromDate`,`From date`),value:o,max:c||void 0,onChange:e=>f(e.target.value,c),className:`${p} ${n===`custom`&&o?`border-primary/50`:``}`}),d(`span`,{className:`text-[11px] text-foreground-subtle`,children:`→`}),d(`input`,{type:`date`,"aria-label":t(`detectionIntelligence.dateRangeFilter.toDate`,`To date`),value:c,min:o||void 0,onChange:e=>f(o,e.target.value),className:`${p} ${n===`custom`&&c?`border-primary/50`:``}`})]})]})}function cr(e){return e<0?0:e>1?1:e}function lr(e,t,n){if(!Number.isFinite(t)||!Number.isFinite(n)||t<=0||n<=0)return null;let r=cr(e.x/t),i=cr(e.y/n),a=cr((e.x+e.w)/t),o=cr((e.y+e.h)/n);return{x:r,y:i,width:Math.max(0,a-r),height:Math.max(0,o-i)}}e();var ur=2.6;function dr({src:e,alt:n,className:i,overlay:o,fit:s=`contain`}){let[c,l]=r(!1),[u,f]=r(`50% 50%`);t(()=>{l(!1),f(`50% 50%`)},[e]);function p(e){if(!c){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)}%`)}l(e=>!e)}let m=s===`natural`;return d(`div`,{className:`relative overflow-hidden bg-background ${i??``}`,onClick:p,children:a(`div`,{className:`relative select-none transition-transform duration-200 ease-out ${m?`w-full`:`h-full w-full`} ${c?`cursor-zoom-out`:`cursor-zoom-in`}`,style:{transformOrigin:u,transform:c?`scale(${String(ur)})`:`scale(1)`},children:[d(`img`,{src:e,alt:n,draggable:!1,className:m?`block h-auto w-full object-contain`:`h-full w-full object-contain`}),o]})})}e();function fr(e){let[n,i]=r(null),[a,o]=r(null),[s,c]=r(!1);return t(()=>{if(i(null),o(null),c(!1),e===void 0)return;let t=!1,n=null;return(async()=>{try{let r=await Vt(Ht(e));if(t)return;n=URL.createObjectURL(r),i(n)}catch{t||c(!0)}})(),()=>{t=!0,n&&URL.revokeObjectURL(n)}},[e]),t(()=>{if(!n)return;let e=new Image;return e.onload=()=>o({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>c(!0),e.src=n,()=>{e.onload=null,e.onerror=null}},[n]),{frameSrc:n,naturalWidth:a?.width??null,naturalHeight:a?.height??null,failed:s}}function pr(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 mr({label:e,value:t}){return a(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[d(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),d(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground`,children:t})]})}function hr({box:e}){let{t}=Z();return d(`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:d(`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 gr({face:e,cameraName:t,onClose:i,onAssign:o,onUnassign:s,onDelete:c,actionsPending:l}){let{t:u}=Z(),{data:f,isFetching:p}=Xe({faceId:e?.faceId??``},{enabled:e!==null}),[m,h]=r(`frame`),{frameSrc:_,naturalWidth:y,naturalHeight:b,failed:x}=fr(e?.keyFrameMediaId),S=n(()=>{let t=pr(f??[]);return t?t.url:Qn(e)},[f,e]),C=n(()=>!e?.faceBbox||y===null||b===null?null:lr(e.faceBbox,y,b),[e?.faceBbox,y,b]);if(e===null)return null;let w=e.keyFrameMediaId!==void 0&&!x,T=w&&m===`frame`,E=e.assigned?e.identityName??`Assigned`:e.recognizedIdentityId?`${e.identityName??`Recognized`} (suggested)`:`Unassigned`;return d(Ue,{open:!0,onOpenChange:e=>!e&&i(),children:a(be,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":u(`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:[d(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:a(`div`,{className:`min-w-0`,children:[d(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:u(`detectionIntelligence.faceDetailPanel.faceDetail`,`Face detail`)}),d(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]})}),a(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[w&&a(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[a(`button`,{type:`button`,onClick:()=>h(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${m===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[d(B,{className:`h-3.5 w-3.5`}),` `,u(`detectionIntelligence.detailPanel.fullFrame`)]}),a(`button`,{type:`button`,onClick:()=>h(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${m===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[d(fe,{className:`h-3.5 w-3.5`}),` `,u(`detectionIntelligence.detailPanel.crop`)]})]}),T&&_?d(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:d(dr,{src:_,alt:u(`detectionIntelligence.faceDetailPanel.fullFrameWithDetectedFace`,`Full frame with detected face`),fit:`natural`,className:`w-full`,overlay:C?d(hr,{box:C}):void 0})}):S?a(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[d(dr,{src:S,alt:u(`detectionIntelligence.faceDetailPanel.detectedFace`,`Detected face`),className:`h-full w-full`}),p&&d(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:d(M,{className:`h-3.5 w-3.5 animate-spin`})})]}):a(`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:[d(R,{className:`h-8 w-8 text-warning/70`}),d(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:u(`detectionIntelligence.faceDetailPanel.noImage`,`No image`)}),d(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:u(`detectionIntelligence.faceDetailPanel.theCropMediaForThis`,`The crop media for this face could not be resolved (a pre-fix orphan). Safe to delete.`)})]}),a(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[d(mr,{label:u(`detectionIntelligence.faceDetailPanel.camera`,`Camera`),value:t}),d(mr,{label:u(`detectionIntelligence.faceDetailPanel.captured`,`Captured`),value:Jn(e.timestamp)}),d(mr,{label:u(`detectionIntelligence.faceDetailPanel.track`,`Track`),value:e.trackId}),d(mr,{label:u(`detectionIntelligence.faceDetailPanel.identity`,`Identity`),value:E})]})]}),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:[e.assigned?a(Y,{variant:`secondary`,onClick:()=>s(e.faceId),disabled:l,children:[d(ue,{className:`h-3.5 w-3.5`}),` `,u(`detectionIntelligence.detailPanel.detach`)]}):a(Y,{variant:`primary`,onClick:()=>o(e.faceId),disabled:l,children:[d(g,{className:`h-3.5 w-3.5`}),` `,u(`common.assign`)]}),a(Y,{variant:`secondary`,onClick:()=>c(e.faceId),disabled:l,children:[d(v,{className:`h-3.5 w-3.5`}),` `,u(`common.delete`)]})]})]})})}function _r(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function vr(e,t){return e.faceIds.filter(e=>!t.has(e))}function yr(e,t){return e.faceIds.filter(e=>t(e))}e();var br=[[`faceGallery`]],xr=20,Sr=.3,Cr=.9,wr=.05,Tr=.5,Er=2,Dr=10,Or=2;function kr({cluster:e,face:t,active:n,onSelect:r}){let{t:i}=Z(),o=Qn(t);return a(`button`,{type:`button`,onClick:r,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 ${n?`border-primary bg-primary/8`:`border-border bg-surface hover:bg-surface-hover`}`,children:[d(`div`,{className:`h-24 w-24 shrink-0 overflow-hidden rounded bg-surface-hover`,children:o===null?d(R,{className:`h-24 w-24 p-6 text-foreground-subtle`}):d(`img`,{src:o,alt:``,loading:`lazy`,decoding:`async`,className:`h-24 w-24 object-cover`})}),d(`span`,{className:`w-24 text-[11px] leading-tight text-foreground-subtle md:w-auto`,children:i(`detectionIntelligence.similarGroupsModal.clusterMeta`,{count:e.size,percent:Math.round(e.cohesion*100)})})]})}function Ar({face:e,cameraName:t,nowMs:n,excluded:r,onToggleExclude:i,onDelete:o,deletePending:s}){let{t:c}=Z(),l=Qn(e);return a(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden transition-opacity ${r?`border-border opacity-40 grayscale`:`border-border`}`,children:[a(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[l===null?a(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,children:[d(R,{className:`h-7 w-7 text-warning/70`}),d(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:c(`detectionIntelligence.similarGroupsModal.noCrop`,`No crop`)})]}):d(dr,{src:l,alt:c(`detectionIntelligence.similarGroupsModal.faceFrom`,`Face from {{cameraName}}`,{cameraName:t}),className:`h-full w-full`}),d(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i()},className:`absolute right-1 top-1 z-10 rounded-full bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":r?c(`detectionIntelligence.similarGroupsModal.includeFace`,`Include face`):c(`detectionIntelligence.similarGroupsModal.excludeFace`,`Exclude face`),title:r?c(`detectionIntelligence.similarGroupsModal.include`,`Include`):c(`detectionIntelligence.similarGroupsModal.exclude`,`Exclude`),children:d(r?f:I,{className:`h-3.5 w-3.5`})})]}),a(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[d(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),d(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:Kn(e.timestamp,n)})]}),d(`div`,{className:`mt-1 flex min-h-[2rem] items-center justify-end border-t border-border/60 px-1 py-0.5`,children:d(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o()},disabled:s,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":c(`detectionIntelligence.similarGroupsModal.deleteFace`,`Delete face`),title:c(`detectionIntelligence.similarGroupsModal.deleteFace`,`Delete face`),children:s?d(M,{className:`h-4 w-4 animate-spin`}):d(v,{className:`h-4 w-4`})})})]})}function jr({open:e,onClose:i,byId:o,cameraName:s,nowMs:u,identities:f,selectMany:p}){let{t:m}=Z(),h=l(),_=Qe(),v=vt(),[y,b]=r(Tr),[x,S]=r(Or),[C,w]=r(null),[T,E]=r({}),[O,k]=r(null),{data:A,isFetching:j,refetch:N}=St({threshold:y,minClusterSize:x,limit:xr},{enabled:e}),P=A??[];t(()=>{E({})},[y,x]),t(()=>{if(P.length===0){w(null);return}P.some(e=>e.representativeFaceId===C)||w(P[0]?.representativeFaceId??null)},[P]);let F=n(()=>P.find(e=>e.representativeFaceId===C)??null,[P,C]),I=F?T[F.representativeFaceId]??new Set:new Set,L=n(()=>F?yr(F,e=>o.has(e)):[],[F,o]),R=F?F.faceIds.length-L.length:0,z=F?vr({...F,faceIds:L},I):[];function ee(e){if(!F)return;let t=F.representativeFaceId;E(n=>({...n,[t]:_r(n[t]??new Set,e)}))}function B(){h.invalidateQueries({queryKey:br})}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),i()}function U(){z.length!==0&&(p(z),H())}return a(Ue,{open:e,onOpenChange:e=>!e&&H(),children:[a(be,{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:[a(`header`,{className:`flex shrink-0 flex-col gap-2 border-b border-border py-3 pl-4 pr-10`,children:[a(`div`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[d(D,{className:`h-4 w-4 text-primary`}),` `,m(`detectionIntelligence.similarGroupsModal.title`)]}),a(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[a(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[m(`detectionIntelligence.similarGroupsModal.threshold`,`Threshold`),d(`input`,{type:`range`,min:Sr,max:Cr,step:wr,value:y,onChange:e=>b(Number(e.target.value)),className:`h-1.5 w-28 cursor-pointer accent-primary`}),d(`span`,{className:`w-8 shrink-0 text-right font-mono text-[11px] tabular-nums text-foreground`,children:y.toFixed(2)})]}),a(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[m(`detectionIntelligence.similarGroupsModal.minSize`,`Min size`),d(`input`,{type:`number`,min:Er,max:Dr,step:1,value:x,onChange:e=>S(Math.min(Dr,Math.max(Er,Number(e.target.value)||Er))),className:`w-12 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`})]}),a(Y,{variant:`secondary`,onClick:()=>{E({}),N()},disabled:j,children:[j?d(M,{className:`h-3.5 w-3.5 animate-spin`}):d(ne,{className:`h-3.5 w-3.5`}),m(`detectionIntelligence.similarGroupsModal.reAnalyze`,`Re-analyze`)]})]})]}),d(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-hidden px-4 py-3 md:flex-row`,children:j&&P.length===0?a(`div`,{className:`flex flex-1 items-center justify-center gap-2 py-8 text-xs text-foreground-subtle`,children:[d(M,{className:`h-4 w-4 animate-spin`}),` `,m(`detectionIntelligence.similarGroupsModal.finding`)]}):P.length===0?d(`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.`)}):a(c,{children:[d(`div`,{className:`flex gap-2 overflow-x-auto pb-1 md:hidden`,children:P.map(e=>d(kr,{cluster:e,face:o.get(e.representativeFaceId),active:e.representativeFaceId===C,onSelect:()=>w(e.representativeFaceId)},e.representativeFaceId))}),d(`div`,{className:`hidden shrink-0 flex-col gap-2 overflow-y-auto md:flex md:w-56`,children:P.map(e=>d(kr,{cluster:e,face:o.get(e.representativeFaceId),active:e.representativeFaceId===C,onSelect:()=>w(e.representativeFaceId)},e.representativeFaceId))}),d(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:F&&a(c,{children:[R>0&&d(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:m(`detectionIntelligence.similarGroupsModal.hiddenCount`,{count:R})}),d(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(13rem,13rem))] justify-start gap-2`,children:L.map(e=>{let t=o.get(e);return t?d(Ar,{face:t,cameraName:s(t.deviceId),nowMs:u,excluded:I.has(e),onToggleExclude:()=>ee(e),onDelete:()=>void V(e),deletePending:v.isPending&&v.variables?.faceId===e},e):null})})]})})]})}),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:[d(Y,{variant:`secondary`,onClick:U,disabled:z.length===0,children:m(`detectionIntelligence.similarGroupsModal.selectInGallery`,`Select in gallery`)}),a(Y,{variant:`primary`,onClick:()=>k(z),disabled:z.length===0,children:[d(g,{className:`h-3.5 w-3.5`}),` `,m(`detectionIntelligence.similarGroupsModal.adopt`,{count:z.length})]})]})]}),d(ir,{faceIds:O,identities:f,onDone:()=>k(null)})]})}e();var Mr=[[`faceGallery`]],Nr=500,Pr=120;function Fr({face:e,cameraName:t,nowMs:n,selected:r,onToggleSelect:i,onAssign:o,onOpenDetail:s}){let{t:c}=Z(),u=l(),f=ht(),p=vt(),m=()=>{u.invalidateQueries({queryKey:Mr})},h=()=>s(e.faceId),_=Qn(e);return a(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${r?`border-primary ring-1 ring-primary`:`border-border`}`,children:[a(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[_===null?a(`button`,{type:`button`,onClick:h,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:c(`detectionIntelligence.unassignedFaces.noCropImageTheFace`,`No crop image — the face's crop media is missing (a pre-fix orphan). Safe to delete.`),children:[d(R,{className:`h-7 w-7 text-warning/70`}),d(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:c(`detectionIntelligence.unassignedFaces.noCrop`,`No crop`)})]}):d(`img`,{src:_,alt:c(`detectionIntelligence.unassignedFaces.faceFrom`,`Face from {{cameraName}}`,{cameraName:t}),onClick:h,loading:`lazy`,decoding:`async`,className:`h-full w-full cursor-zoom-in object-cover`}),d(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),i(e.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":r?c(`detectionIntelligence.unassignedFaces.deselect`,`Deselect`):c(`detectionIntelligence.unassignedFaces.select`,`Select`),children:r?d(ce,{className:`h-4 w-4 text-primary`}):d(y,{className:`h-4 w-4`})})]}),a(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[d(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),d(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:Kn(e.timestamp,n)}),d(`p`,{className:`min-h-[0.875rem] truncate text-[10px] font-medium leading-tight ${e.identityName?`text-primary`:`invisible`}`,title:e.identityName,children:e.identityName??`\xA0`})]}),a(`div`,{className:`mt-1 flex min-h-[2rem] items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[e.assigned?d(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),f.mutate({faceId:e.faceId},{onSettled:m})},disabled:f.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":c(`detectionIntelligence.unassignedFaces.detachFace`,`Detach face`),title:c(`detectionIntelligence.unassignedFaces.detach`,`Detach`),children:f.isPending?d(M,{className:`h-4 w-4 animate-spin`}):d(ue,{className:`h-4 w-4`})}):d(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(e.faceId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":c(`detectionIntelligence.unassignedFaces.assignFaceToPerson`,`Assign face to person`),title:c(`detectionIntelligence.unassignedFaces.assignToPerson`,`Assign to person`),children:d(g,{className:`h-4 w-4`})}),d(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),p.mutate({faceId:e.faceId},{onSettled:m})},disabled:p.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":c(`detectionIntelligence.unassignedFaces.deleteFace`,`Delete face`),title:c(`detectionIntelligence.unassignedFaces.deleteFace`,`Delete face`),children:p.isPending?d(M,{className:`h-4 w-4 animate-spin`}):d(v,{className:`h-4 w-4`})})]})]})}var Ir=[{labelKey:`common.all`,value:`all`},{labelKey:`detectionIntelligence.unassignedFaces.filterUnassigned`,value:`unassigned`},{labelKey:`detectionIntelligence.unassignedFaces.filterRecognized`,value:`recognized`}];function Lr(){let{t:e}=Z(),t=l(),[i,o]=r(`all`),[s,u]=r(In),[f,p]=r(new Set),[m,h]=r(new Set),[_,y]=r(null),[b,x]=r(!1),[S,C]=r(null),{data:w,isLoading:T}=Re({limit:Nr,filter:i,includeCrops:!1},{refetchInterval:3e4}),{data:E=[]}=Je(),{data:O}=ct({isCamera:!0,projection:`slim`}),k=we(),A=ht(),j=yt(),N=vt(),P=Date.now(),F=w??[],L=n(()=>{let e=new Map;for(let t of O??[])e.set(t.id,t.name);return e},[O]),z=t=>L.get(t)??e(`detectionIntelligence.cameraFallback`,{id:String(t)}),ee=n(()=>Un(F).map(e=>({id:e,name:z(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[F,L]),B=n(()=>Hn(Vn(F,s),f),[F,s,f]),V=$n(B,Pr,n(()=>JSON.stringify([i,s.fromMs,s.toMs,[...f].sort((e,t)=>e-t)]),[i,s.fromMs,s.toMs,f])),H=n(()=>new Map(F.map(e=>[e.faceId,e])),[F]),U=n(()=>Zn(B),[B]),W=S===null?null:H.get(S)??null,G=()=>{t.invalidateQueries({queryKey:Mr})},te=()=>h(new Set);function K(e){h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function q(e){h(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function ne(){q(Xn(B))}let re=[...m],J=k.isPending||j.isPending||N.isPending,ie=A.isPending||N.isPending;function ae(){re.length!==0&&j.mutate({faceIds:re},{onSettled:()=>{G(),te()}})}function oe(){re.length!==0&&Promise.allSettled(re.map(e=>N.mutateAsync({faceId:e}))).then(()=>{G(),te()})}function se(e){C(null),y([e])}function ce(e){A.mutate({faceId:e},{onSettled:G}),C(null)}function le(e){N.mutate({faceId:e},{onSettled:G}),C(null)}let de=B.length!==F.length;return a(`div`,{className:`relative space-y-3`,children:[a(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d(`div`,{className:`flex items-center gap-1`,children:Ir.map(t=>d(`button`,{type:`button`,onClick:()=>o(t.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${i===t.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e(t.labelKey)},t.value))}),d(sr,{onChange:u}),d(ar,{cameras:ee,selected:f,onChange:p}),a(`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:[d(D,{className:`h-3.5 w-3.5`}),` `,e(`detectionIntelligence.unassignedFaces.similarGroups`)]}),!T&&U>0&&a(`button`,{type:`button`,onClick:ne,className:`ml-auto flex items-center gap-1 rounded-md px-2.5 py-1 text-xs text-warning/90 transition-colors hover:bg-warning/10`,title:e(`detectionIntelligence.unassignedFaces.selectEveryVisibleFaceWhose`,`Select every visible face whose crop image is missing so you can delete the orphans in one pass`),children:[d(R,{className:`h-3.5 w-3.5`}),` `,e(`detectionIntelligence.unassignedFaces.selectCropless`,{count:U})]}),!T&&d(`span`,{className:`text-[10px] text-foreground-subtle ${U>0?`ml-2`:`ml-auto`}`,children:de?e(`detectionIntelligence.unassignedFaces.ofFaces`,`{{value1}} of {{value2}} faces`,{value1:String(B.length),value2:String(F.length)}):e(`detectionIntelligence.unassignedFaces.faceCount`,{count:B.length})})]}),m.size>0&&a(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[d(`span`,{className:`text-xs font-medium text-foreground`,children:e(`common.selectedCount`,{count:m.size})}),a(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[a(Y,{variant:`primary`,onClick:()=>y(re),disabled:J,children:[d(g,{className:`h-3.5 w-3.5`}),` `,e(`common.assign`)]}),a(Y,{variant:`secondary`,onClick:ae,disabled:J,children:[j.isPending?d(M,{className:`h-3.5 w-3.5 animate-spin`}):d(ue,{className:`h-3.5 w-3.5`}),` `,e(`detectionIntelligence.unassignedFaces.detach`,`Detach`)]}),a(Y,{variant:`secondary`,onClick:oe,disabled:J,children:[d(v,{className:`h-3.5 w-3.5`}),` `,e(`common.delete`)]}),d(Y,{variant:`ghost`,onClick:te,disabled:J,children:d(I,{className:`h-3.5 w-3.5`})})]})]}),T?d(Ee,{status:`pending`,pendingMessage:`Loading faces…`,testId:`faces-grid`}):B.length===0?d(Be,{icon:R,title:F.length>0?e(`detectionIntelligence.unassignedFaces.nothingMatchesTheFilter`,`Nothing matches the filter`):e(`detectionIntelligence.unassignedFaces.noFacesFoundForThis`,`No faces found for this filter`),description:F.length>0?e(`detectionIntelligence.unassignedFaces.widenTheDateRangeOr`,`Widen the date range or clear the camera filter.`):e(`detectionIntelligence.unassignedFaces.faceCropsAppearHereWhen`,`Face crops appear here when the detection pipeline captures them.`)}):a(c,{children:[d(Ee,{status:`ready`,testId:`faces-grid`,className:`grid-cols-[repeat(auto-fill,minmax(6.5rem,6.5rem))] justify-start`,children:V.pageItems.map(e=>d(Fr,{face:e,cameraName:z(e.deviceId),nowMs:P,selected:m.has(e.faceId),onToggleSelect:K,onAssign:e=>y([e]),onOpenDetail:C},e.faceId))}),d(nr,{currentPage:V.page,totalItems:V.totalItems,pageSize:V.pageSize,onPageChange:V.setPage,itemNoun:`faces`})]}),d(gr,{face:W,cameraName:W?z(W.deviceId):``,onClose:()=>C(null),onAssign:se,onUnassign:ce,onDelete:le,actionsPending:ie}),d(ir,{faceIds:_,identities:E,onDone:()=>{y(null),te()}}),d(jr,{open:b,onClose:()=>x(!1),byId:H,cameraName:z,nowMs:P,identities:E,selectMany:q})]})}function Rr(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}}e();var zr=[[`faceGallery`]],Br=2e3;function Vr(){let e=l(),n=u(e);n.current=e;let r=u(void 0);r.current||=Rr({delayMs:Br,invalidate:()=>{n.current.invalidateQueries({queryKey:zr})}}),t(()=>()=>r.current?.cancel(),[]),Et(me.PipelineAnalyticsFaceGalleryChanged,()=>{r.current?.trigger()})}function Hr(){let{t:e}=Z();return Vr(),a(`div`,{className:`space-y-3`,children:[d(Ge,{headingId:`library-people`,title:e(`detectionIntelligence.people`,`People`),icon:pe,testId:`library-section-people`,children:a(`div`,{className:`${m} space-y-3`,children:[d(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:e(`detectionIntelligence.enrolledIdentitiesUsedForFace`,`Enrolled identities used for face recognition. Open a person to rename them or remove training samples.`)}),d(Fn,{})]})}),d(Ge,{headingId:`library-recent-faces`,title:e(`detectionIntelligence.recentDetectedFaces`,`Recent detected faces`),icon:J,testId:`library-section-recent-faces`,children:a(`div`,{className:`${m} space-y-3`,children:[d(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:e(`detectionIntelligence.faceCropsCapturedByThe`,`Face crops captured by the detection pipeline. Assign them to a person to build recognition training data.`)}),d(Lr,{})]})})]})}function Ur(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 Wr=720*60*60*1e3;function Gr(e){let t=[];for(let n of e)t.push(...n);return t}function Kr(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function qr(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 Jr(e,t){return`${String(e)}:${t}`}function Yr(e,t){let n=new Map,r=new Set;for(let i of e){let e=Jr(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 Xr(e,t){return{since:e.fromMs??t-Wr,until:e.toMs??t}}var Zr=[`native`,`raster`,`standin`];function Qr(e){return Zr.some(t=>t===e)}function $r(e){return e===`standin`?{label:X.t(`helpers.mediaProvenance.standin.label`),title:X.t(`helpers.mediaProvenance.standin.title`),tone:`warning`}:{label:X.t(`helpers.mediaProvenance.raster.label`),title:X.t(`helpers.mediaProvenance.raster.title`),tone:`info`}}function ei(e){return e===`standin`?$r(`standin`):e===`raster`?$r(`raster`):null}var ti={"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 ni(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=ti[r];return{sentence:a===void 0?r:X.t(a),detail:i,raw:t}}function ri(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 ii({row:e,cameraName:t,nowMs:n,onOpenDetail:r,selected:i=!1,onToggleSelect:o,score:s,provenance:c,footer:l}){let{t:u}=Z(),f=zt(e.mediaId===void 0?Bt(`track`,e.trackId):Ht(e.mediaId)),p=Math.round(e.importance*100),m=s===void 0?void 0:Math.round(s*100),g=ri(e.windowMs),_=()=>r(e),v=ei(c);return a(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[a(`div`,{className:`aspect-video relative overflow-hidden bg-surface-hover`,children:[f.src?d(`img`,{src:f.src,alt:u(`detectionIntelligence.eventCard.eventFrom`,`Event from {{cameraName}}`,{cameraName:t}),onClick:_,className:`h-full w-full cursor-zoom-in object-cover`}):d(`button`,{type:`button`,onClick:_,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-surface-hover text-foreground-subtle`,title:f.failed?u(`detectionIntelligence.eventCard.keyEventMediaUnavailable`,`Key-event media unavailable`):u(`detectionIntelligence.eventCard.noKeyEventMedia`,`No key-event media`),children:d(R,{className:`h-6 w-6 opacity-60`})}),o&&d(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(Jr(e.deviceId,e.trackId))},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?u(`detectionIntelligence.eventCard.deselect`,`Deselect`):u(`detectionIntelligence.eventCard.select`,`Select`),children:i?d(ce,{className:`h-4 w-4 text-primary`}):d(y,{className:`h-4 w-4`})}),m!==void 0&&a(`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:u(`detectionIntelligence.eventCard.clipSemanticMatchScore`,`CLIP semantic-match score`),children:[String(m),`%`]}),p>0&&d(`span`,{className:`absolute right-1 top-1 z-10 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-semibold text-white`,children:String(p)}),v!==null&&d(`span`,{className:`absolute bottom-1 right-1 z-10 rounded px-1.5 py-0.5 text-[10px] font-semibold text-white ${v.tone===`warning`?`bg-warning/90`:`bg-black/70`}`,title:v.title,children:v.label}),(e.markForTrain===!0||e.retrainStatus===`trained`||e.debug===!0||e.favourited===!0)&&a(`span`,{className:`absolute bottom-1 left-1 z-10 flex gap-1`,children:[e.markForTrain===!0&&d(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:u(`detectionIntelligence.eventCard.markedForTraining`,`Marked for training`),"aria-label":u(`detectionIntelligence.eventCard.markedForTraining`,`Marked for training`),children:d(K,{className:`h-3 w-3`})}),e.retrainStatus===`trained`&&e.markForTrain!==!0&&d(`span`,{className:`rounded bg-success/85 p-0.5 text-white`,title:u(`detectionIntelligence.eventCard.trainingComplete`,`Training complete`),"aria-label":u(`detectionIntelligence.eventCard.trainingComplete`,`Training complete`),"data-testid":`retrain-status-trained`,children:d(N,{className:`h-3 w-3`})}),e.debug===!0&&d(`span`,{className:`rounded bg-black/70 p-0.5 text-white`,title:u(`detectionIntelligence.eventCard.flaggedForDebug`,`Flagged for debug`),"aria-label":u(`detectionIntelligence.eventCard.flaggedForDebug`,`Flagged for debug`),children:d(h,{className:`h-3 w-3`})}),e.favourited===!0&&d(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:u(`detectionIntelligence.eventCard.favourited`,`Favourited`),"aria-label":u(`detectionIntelligence.eventCard.favourited`,`Favourited`),children:d(V,{className:`h-3 w-3`})})]})]}),a(`button`,{type:`button`,onClick:_,className:`min-w-0 px-2 py-1.5 text-left space-y-0.5`,children:[a(`p`,{className:`text-[11px] font-medium text-foreground truncate`,title:e.className,children:[e.className,Ur(e)?a(`span`,{className:`text-foreground-subtle`,children:[` · `,Ur(e)]}):null]}),d(`p`,{className:`text-[10px] text-foreground-subtle truncate`,title:t,children:t}),a(`div`,{className:`flex items-center justify-between gap-2`,children:[d(`span`,{className:`text-[10px] text-foreground-subtle truncate`,children:Kn(e.timestamp,n)}),g&&d(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:g})]})]}),l!==void 0&&d(`div`,{className:`px-2 pb-1.5`,children:l})]})}e();var ai=1400,oi=`Admin-gated URL — opens only inside an authenticated session`;function si({label:e,value:n,title:o}){let{t:s}=Z(),[c,l]=r(!1),u=ze();return t(()=>{if(!c)return;let e=setTimeout(()=>l(!1),ai);return()=>clearTimeout(e)},[c]),a(`button`,{type:`button`,onClick:i(()=>{(async()=>{try{await navigator.clipboard.writeText(n),l(!0)}catch{await u({title:s(`detectionIntelligence.copyUrlChips.copyTheMediaUrl`,`Copy the media URL`),message:s(`detectionIntelligence.copyUrlChips.clipboardAccessWasRefusedSelect`,`Clipboard access was refused. Select the URL below and copy it manually.`),label:s(`detectionIntelligence.copyUrlChips.url`,`{{label}} URL`,{label:e}),defaultValue:n,readOnly:!0,cancelLabel:s(`common.close`,`Close`)})}})()},[n,e,u,s]),title:o,"aria-label":s(`detectionIntelligence.copyUrlChips.copyUrl`,`Copy {{label}} URL`,{label:e}),className:`flex min-w-0 items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${c?`border-success/40 bg-success/10 text-success`:`border-border text-foreground-subtle hover:border-primary hover:text-foreground`}`,children:[d(c?N:O,{className:`h-2.5 w-2.5 shrink-0`}),d(`span`,{className:`truncate`,children:c?s(`detectionIntelligence.copyUrlChips.copied`,`Copied`):e})]})}function ci({localUrl:e,publicUrl:t}){let{t:n}=Z();return a(`div`,{className:`flex flex-wrap gap-1`,children:[d(si,{label:n(`detectionIntelligence.copyUrlChips.local`,`Local`),value:e,title:n(`detectionIntelligence.copyUrlChips.copyLanUrl`,`Copy LAN URL — {{AUTH_HINT}}`,{AUTH_HINT:oi})}),t&&d(si,{label:n(`detectionIntelligence.copyUrlChips.public`,`Public`),value:t,title:n(`detectionIntelligence.copyUrlChips.copyPublicUrl`,`Copy public URL — {{AUTH_HINT}}`,{AUTH_HINT:oi})})]})}var li={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 ui(e){return e in li}function di(e){return ui(e)?li[e]:e}function fi(e,t){return`${e}${t}`}e();var pi=3e4;function mi(e){let[n,a]=r(null),o=i(e=>{a(t=>t??e)},[]);return t(()=>{e||a(null)},[e]),{publicOrigin:n,probes:e?d(hi,{onOrigin:o}):null}}function hi({onOrigin:e}){let{data:t}=xe({capName:`network-access`});return d(c,{children:(t??[]).map(t=>d(gi,{addonId:t.addonId,onOrigin:e},t.addonId))})}function gi({addonId:e,onOrigin:n}){let{data:r}=Ae({addonId:e},{refetchInterval:pi,retry:!1});return t(()=>{let e=r?he.safeParse(r):null,t=e?.success?e.data.endpoint?.url:void 0;if(t)try{n(new URL(t).origin)}catch{}},[r,n]),null}var _i=typeof At==`function`,vi=`Track flags arrive with the next server update`;function yi(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var bi=_i?At:yi;function xi(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}}e();function Si({label:e,hint:t,checked:n,disabled:r,title:i,icon:o,onToggle:s}){return a(`button`,{type:`button`,role:`switch`,"aria-checked":n,"aria-label":e,disabled:r,title:i,onClick:s,className:`flex w-full items-center gap-2 rounded-md border px-2 py-1.5 text-left transition-colors disabled:opacity-50 ${n?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[d(`span`,{className:n?`text-primary`:`text-foreground-subtle`,children:o}),a(`span`,{className:`min-w-0 flex-1`,children:[d(`span`,{className:`block text-[11px] font-medium text-foreground`,children:e}),d(`span`,{className:`block text-[10px] text-foreground-subtle`,children:t})]}),d(`span`,{"aria-hidden":`true`,className:`h-4 w-7 shrink-0 rounded-full p-0.5 transition-colors ${n?`bg-primary`:`bg-border`}`,children:d(`span`,{className:`block h-3 w-3 rounded-full bg-white transition-transform ${n?`translate-x-3`:``}`})})]})}function Ci({deviceId:e,trackId:t,markForTrain:n,debug:i,favourited:o,onChange:s}){let{t:c}=Z(),l=bi(),u=Ye(),[f,p]=r(null),m=f?.markForTrain??n===!0,g=f?.debug??i===!0,_=f?.favourited??o===!0,v=!_i||l.isPending,y=_i?void 0:vi,b=n=>{v||(async()=>{try{let r=xi(await l.mutateAsync({deviceId:e,trackId:t,flags:n}));if(!r)return;p(r),s?.(r)}catch(e){let t=e instanceof Error?e.message:``;await u({title:c(`detectionIntelligence.trackFlagToggles.couldNotUpdateThisTrack`,`Could not update this track`),message:t===``?c(`detectionIntelligence.trackFlagToggles.couldNotUpdateThisTrack2`,`Could not update this track. Check the server logs.`):t,variant:`danger`})}})()};return a(`div`,{className:`grid gap-1.5 sm:grid-cols-2`,children:[d(Si,{label:c(`detectionIntelligence.trackFlagToggles.markForTraining`,`Mark for training`),hint:c(`detectionIntelligence.trackFlagToggles.keepsThisTrackAndIts`,`Keeps this track and its media past retention`),checked:m,disabled:v,...y===void 0?{}:{title:y},icon:d(K,{className:`h-4 w-4`}),onToggle:()=>b({markForTrain:!m})}),d(Si,{label:c(`detectionIntelligence.trackFlagToggles.debug`,`Debug`),hint:c(`detectionIntelligence.trackFlagToggles.flagThisTrackForDiagnostic`,`Flag this track for diagnostic attention`),checked:g,disabled:v,...y===void 0?{}:{title:y},icon:d(h,{className:`h-4 w-4`}),onToggle:()=>b({debug:!g})}),d(Si,{label:c(`detectionIntelligence.trackFlagToggles.favourited`,`Favourited`),hint:c(`detectionIntelligence.trackFlagToggles.keepsThisTrackAndIts`,`Keeps this track and its media past retention`),checked:_,disabled:v,...y===void 0?{}:{title:y},icon:d(V,{className:`h-4 w-4`}),onToggle:()=>b({favourited:!_})})]})}var wi=100,Ti=120,Ei={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Di=e=>e<0?0:e>1?1:e,Oi=e=>Math.round(e*100)/100;function ki(e,t){if(e.length<=t)return[...e];let n=(e.length-1)/(t-1),r=[];for(let i=0;i<t;i++)r.push(e[Math.round(i*n)]);return r[r.length-1]=e[e.length-1],r}function Ai(e,t,n){if(e.length===0||t===null)return Ei;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return Ei;let a=ki(e,n?.maxPoints??Ti).map(e=>({x:Oi(Di(e.x/r)*wi),y:Oi(Di(e.y/i)*wi)})),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:Oi(Di(e.x/r)*wi),y:Oi(Di(e.y/i)*wi),mediaId:e.mediaId})),u=null,d=-1;for(let t of e){let e=Di(t.bbox.w/r)*Di(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:Oi(Di(u.bbox.x/r)*wi),y:Oi(Di(u.bbox.y/i)*wi),w:Oi(Di(u.bbox.w/r)*wi),h:Oi(Di(u.bbox.h/i)*wi)}:null}}var ji=typeof Ct==`function`,Mi=`Track deletion arrives with the next server update`;function Ni(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var Pi=ji?Ct:Ni;e();var Fi=15e3,Ii=k();function Li({url:e,label:t}){let{src:n,failed:r}=zt(e);return n===null?d(`div`,{className:`flex h-full w-full items-center justify-center bg-surface-hover`,children:r?d(R,{className:`h-4 w-4 text-foreground-subtle opacity-60`}):d(M,{className:`h-4 w-4 animate-spin text-foreground-subtle opacity-70`})}):d(`img`,{src:n,alt:t,className:`h-full w-full object-cover`})}var Ri=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),zi=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`,`sceneFrame`,`lastSceneFrame`]);function Bi(e){let[n,i]=r(null);return t(()=>{if(i(null),!e)return;let t=!1,n=new Image;return n.onload=()=>{t||i({width:n.naturalWidth,height:n.naturalHeight})},n.src=e,()=>{t=!0,n.onload=null}},[e]),n}function Vi({overlay:e,onPickSnapshot:t}){let{t:n}=Z();return!e.polyline&&!e.peakBox&&e.snapshots.length===0?null:a(`svg`,{viewBox:`0 0 100 100`,preserveAspectRatio:`none`,className:`pointer-events-none absolute inset-0 h-full w-full`,children:[e.peakBox&&d(`rect`,{x:e.peakBox.x,y:e.peakBox.y,width:e.peakBox.w,height:e.peakBox.h,fill:`none`,stroke:`var(--color-warning)`,strokeWidth:2,vectorEffect:`non-scaling-stroke`,rx:1}),e.polyline&&d(`polyline`,{points:e.polyline,fill:`none`,stroke:`var(--color-info)`,strokeWidth:2,strokeLinejoin:`round`,strokeLinecap:`round`,strokeOpacity:.85,vectorEffect:`non-scaling-stroke`}),e.points.map((e,t)=>d(`circle`,{cx:e.x,cy:e.y,r:1,fill:`var(--color-info)`,fillOpacity:.6,vectorEffect:`non-scaling-stroke`},`${String(e.x)}-${String(e.y)}-${String(t)}`)),e.snapshots.map((e,r)=>d(`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:t?`pointer-events-auto cursor-pointer`:void 0,onClick:t?n=>{n.stopPropagation(),t(e.mediaId)}:void 0,children:d(`title`,{children:n(`detectionIntelligence.eventDetailPanel.snapshotCheckpointClickToView`,`Snapshot checkpoint — click to view this frame`)})},`snap-${String(e.mediaId)}-${String(r)}`)),e.start&&d(`circle`,{cx:e.start.x,cy:e.start.y,r:2.4,fill:`var(--color-success)`,stroke:`var(--color-background)`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`}),e.end&&d(`circle`,{cx:e.end.x,cy:e.end.y,r:2.4,fill:`var(--color-danger)`,stroke:`var(--color-background)`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`})]})}function Hi({label:e,value:t,mono:n}){return a(`div`,{className:`flex items-baseline justify-between gap-3 border-b border-border/60 py-1.5 last:border-0`,children:[d(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),d(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono text-[11px]`:``}`,title:t,children:t})]})}function Ui({row:e,cameraName:o,deleteAvailable:s,onClose:l,onDeleted:u,onFlagsChanged:f}){let{t:p}=Z(),m=ee(),h=Ye(),g=Qe(),_=Pi(),y=e!==null,x=e?.deviceId??0,S=e?.trackId??``,C=e?.timestamp??0,w=e?.windowMs??0,{data:T}=at({deviceId:x,trackId:S},{enabled:y}),{data:E}=st({trackId:S,deviceId:x},{enabled:y}),D=T?.bestEventId===void 0?void 0:Number(T.bestEventId),{data:O}=mt({ownerType:`object`,eventId:D??0,deviceId:x},{enabled:y&&D!==void 0&&Number.isFinite(D)}),{data:k}=Te({deviceId:x},{enabled:y}),A=(k??[]).find(e=>e.addonId!==void 0)?.addonId,{data:j}=Ke({deviceId:x,since:C-Fi,until:C+w+Fi,provider:A??``},{enabled:y&&A!==void 0}),[N,P]=r(null),[F,I]=r(!1),{publicOrigin:L,probes:z}=mi(y);t(()=>{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,H=zt(V?V.url:void 0),U=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]),W=n(()=>U.find(e=>Ri.has(e.kind))??null,[U]),G=Bi(zt(W?W.url:void 0).src),te=n(()=>Ai(T?.positions??[],G,{snapshots:(T?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaId:e.mediaId}))}),[T?.positions,T?.snapshots,G]),K=i(e=>{let t=U.find(t=>t.mediaId===e);t&&P(t)},[U]);if(e===null)return null;let q=H.src,ne=V?.kind,re=ne!==void 0&&zi.has(ne)&&G!==null&&(T?.positions.length??0)>=2,J=j&&j.length>0?j[0]:null,ie=()=>{J&&(I(!0),(async()=>{try{let t=await m.trpcClient.videoclips.getClipPlayback.query({deviceId:e.deviceId,clipId:J.id});window.open(t.playbackUrl,`_blank`,`noopener`)}catch{h({title:p(`detectionIntelligence.eventDetailPanel.clipUnavailable`,`Clip unavailable`),message:p(`detectionIntelligence.eventDetailPanel.couldNotResolveClipPlayback`,`Could not resolve clip playback. Check the server logs.`),variant:`warning`})}finally{I(!1)}})())},ae=()=>{!s||_.isPending||(async()=>{if(await g({title:p(`detectionIntelligence.eventDetailPanel.deleteTrack`,`Delete track`),message:p(`detectionIntelligence.eventDetailPanel.deleteThisTrackAndEvery`,`Delete this track and every image and clip captured for it? This cannot be undone.`),confirmLabel:p(`common.delete`,`Delete`),variant:`danger`}))try{await _.mutateAsync({deviceId:e.deviceId,trackIds:[e.trackId]}),u()}catch{await h({title:p(`detectionIntelligence.eventDetailPanel.deleteFailed`,`Delete failed`),message:p(`detectionIntelligence.eventDetailPanel.failedToDeleteThisTrack`,`Failed to delete this track. Check the server logs.`),variant:`danger`})}})()},oe=Math.round(e.importance*100),se=T?.importanceReason?`${String(oe)}% · ${T.importanceReason}`:`${String(oe)}%`,ce=T?.zonesVisited&&T.zonesVisited.length>0?T.zonesVisited.join(`, `):`—`,le=T?.audioLabels&&T.audioLabels.length>0?T.audioLabels:e.audioLabels&&e.audioLabels.length>0?e.audioLabels:void 0,ue=le===void 0?`—`:le.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `),de=T?T.totalDistance.toFixed(2):`—`,fe=ni(T?.previewMissReason),pe=Jn(T?T.firstSeen:C),me=T?Jn(T.lastSeen):`—`;return d(Ue,{open:!0,onOpenChange:e=>!e&&l(),children:a(be,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":p(`detectionIntelligence.eventDetailPanel.eventDetail`,`Event detail`),className:`flex h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:h-auto md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[d(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:a(`div`,{className:`min-w-0`,children:[a(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:[e.className,Ur(e)?a(`span`,{className:`text-foreground-subtle`,children:[` · `,Ur(e)]}):null]}),d(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:o})]})}),a(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[q?d(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:d(dr,{src:q,alt:p(`detectionIntelligence.eventDetailPanel.keyFrameFrom`,`Key frame from {{cameraName}}`,{cameraName:o}),fit:`natural`,className:`w-full`,overlay:re?d(Vi,{overlay:te,onPickSnapshot:K}):void 0})}):d(`div`,{className:`flex aspect-video w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-surface-hover text-foreground-subtle`,children:H.failed?a(c,{children:[d(R,{className:`h-8 w-8 opacity-60`}),d(`span`,{className:`text-[11px]`,children:p(`detectionIntelligence.eventDetailPanel.keyFrameMediaUnavailable`,`Key-frame media unavailable`)})]}):d(M,{className:`h-6 w-6 animate-spin opacity-70`})}),U.length>0&&d(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:U.map(e=>{let t=di(e.kind),n=fi(Ii,e.url),r=L?fi(L,e.url):null;return a(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[d(`button`,{type:`button`,onClick:()=>P(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${t} · ${Jn(e.timestamp)}`,children:d(Li,{url:e.url,label:t})}),a(`figcaption`,{className:`min-w-0 px-0.5`,children:[d(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:t,children:t}),d(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:Jn(e.timestamp),children:qn(e.timestamp)})]}),d(ci,{localUrl:n,publicUrl:r})]},e.mediaId)})}),z,J&&a(Y,{variant:`secondary`,onClick:ie,disabled:F,children:[F?d(M,{className:`h-3.5 w-3.5 animate-spin`}):d(b,{className:`h-3.5 w-3.5`}),` `,p(`detectionIntelligence.eventDetailPanel.viewClip`,`View clip`)]}),d(Ci,{deviceId:e.deviceId,trackId:e.trackId,...(T?.markForTrain??e.markForTrain)===void 0?{}:{markForTrain:T?.markForTrain??e.markForTrain},...(T?.debug??e.debug)===void 0?{}:{debug:T?.debug??e.debug},...(T?.favourited??e.favourited)===void 0?{}:{favourited:T?.favourited??e.favourited},onChange:f}),fe!==null&&a(`div`,{className:`rounded-lg border border-warning/40 bg-warning/8 px-3 py-2`,children:[d(`p`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:p(`detectionIntelligence.eventDetailPanel.bestShot`,`Best shot`)}),d(`p`,{className:`mt-0.5 text-xs text-foreground`,children:fe.sentence}),d(`code`,{className:`mt-1 block break-all font-mono text-[10px] text-foreground-subtle`,children:fe.raw})]}),a(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[d(Hi,{label:p(`detectionIntelligence.eventDetailPanel.camera`,`Camera`),value:o}),d(Hi,{label:p(`detectionIntelligence.eventDetailPanel.class`,`Class`),value:e.className}),d(Hi,{label:p(`detectionIntelligence.eventDetailPanel.label`,`Label`),value:e.label??`—`}),d(Hi,{label:p(`detectionIntelligence.eventDetailPanel.subLabel`,`Sub-label`),value:e.subLabel??`—`}),d(Hi,{label:p(`detectionIntelligence.eventDetailPanel.importance`,`Importance`),value:se}),d(Hi,{label:p(`detectionIntelligence.eventDetailPanel.zonesVisited`,`Zones visited`),value:ce}),d(Hi,{label:p(`detectionIntelligence.eventDetailPanel.audioHeard`,`Audio heard`),value:ue}),d(Hi,{label:p(`detectionIntelligence.eventDetailPanel.totalDistance`,`Total distance`),value:de}),d(Hi,{label:p(`detectionIntelligence.eventDetailPanel.firstSeen`,`First seen`),value:pe}),d(Hi,{label:p(`detectionIntelligence.eventDetailPanel.lastSeen`,`Last seen`),value:me}),d(Hi,{label:p(`detectionIntelligence.eventDetailPanel.track`,`Track`),value:e.trackId,mono:!0})]})]}),d(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:d(`span`,{title:s?void 0:Mi,children:a(Y,{variant:`secondary`,onClick:ae,disabled:!s||_.isPending,children:[_.isPending?d(M,{className:`h-3.5 w-3.5 animate-spin`}):d(v,{className:`h-3.5 w-3.5`}),` `,p(`detectionIntelligence.eventDetailPanel.deleteTrack`,`Delete track`)]})})})]})})}var Wi={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`},Gi={setRelation:`debug.gt.setRelation`,setPurity:`debug.gt.setPurity`,list:`debug.gt.list`},Ki=w(`/addon/pipeline-analytics/tape-export`),qi=10*6e4;function Ji(e){return`${Ki}?tapeId=${encodeURIComponent(e)}`}var Yi=`The server answered in a shape this build does not understand.`;function Xi(e){return e instanceof Error?e.message:X.t(`helpers.eventsDebugTapes.actionFailed`)}function Zi(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 Qi(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 $i(e,t){let n=e[t];return typeof n==`boolean`?n:null}function ea(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 ta(e){return e===`off`||e===`recording`||e===`refused`||e===`failing`||e===`unknown`}function na(e){if(!Zi(e))return null;let t=Q(e,`deviceId`),n=e.state,r=Q(e,`gapsSinceArmed`),i=Qi(e,`segmentsHeld`),a=Qi(e,`bytesLastHour`),o=Qi(e,`bytesHeld`);if(t===null||!ta(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 ra(e){return Zi(e)?ea(e.cameras,na):null}function ia(e){if(!Zi(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=$i(e,`reviewed`),f=$i(e,`released`),p=ea(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 aa(e){return Zi(e)?ea(e.tapes,ia):null}function oa(e){if(!Zi(e))return null;let t=$(e,`trackId`),n=Q(e,`firstT`),r=Q(e,`lastT`),i=Q(e,`boundFrames`),a=$(e,`cls`),o=$i(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 sa(e){if(!Zi(e))return null;let t=$(e,`tapeId`),n=Q(e,`deviceId`),r=Q(e,`fromMs`),i=Q(e,`toMs`),a=$i(e,`reviewed`),o=ea(e.lanes,oa);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 ca(e){if(!Zi(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 la(e){if(!Zi(e))return null;let t=e.status;if(t===`released`){let n=Q(e,`unpinned`),r=$i(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 ua(e){if(!Zi(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 da(e){switch(e.status){case`released`:case`deleted`:return null;case`already-released`:return X.t(`helpers.eventsDebugTapes.alreadyReleased`);case`not-found`:return X.t(`helpers.eventsDebugTapes.notFound`);case`pins-owed`:return X.t(`helpers.eventsDebugTapes.pinsOwed`);case`unavailable`:return X.t(`helpers.eventsDebugTapes.unavailable`,{reason:e.reason})}}function fa(e){if(!Zi(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 pa(e){if(!Zi(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 ma(e){if(!Zi(e))return null;let t=ea(e.relations,fa),n=ea(e.purities,pa),r=$i(e,`truncated`);return t===null||n===null||r===null?null:{relations:t,purities:n,truncated:r}}function ha(e){if(!e.truncated)return null;let t=e.relations.length+e.purities.length;return X.t(`helpers.eventsDebugTapes.truncatedMarks`,{count:t})}function ga(e){return e.filter(e=>e.segmentsHeld===null||e.segmentsHeld>0).map(e=>({deviceId:e.deviceId,segmentsUnknown:e.segmentsHeld===null}))}function _a(e){return e.slice(1).map((t,n)=>({trackId:e[n]??t,otherTrackId:t}))}function va(e){return e.flatMap((t,n)=>e.slice(n+1).map(e=>({trackId:t,otherTrackId:e})))}function ya(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 ba(e){switch(e.state){case`off`:return X.t(`helpers.eventsDebugTapes.statusOff`);case`recording`:return X.t(`helpers.eventsDebugTapes.statusRecording`);case`refused`:return X.t(`helpers.eventsDebugTapes.statusRefused`,{reason:e.reason??X.t(`helpers.eventsDebugTapes.unknownReason`)});case`failing`:return X.t(`helpers.eventsDebugTapes.statusFailing`,{reason:e.reason??X.t(`helpers.eventsDebugTapes.unknownReason`)});case`unknown`:return X.t(`helpers.eventsDebugTapes.statusUnknown`,{reason:e.reason??X.t(`helpers.eventsDebugTapes.unknownReason`)})}}var xa={"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 Sa(e,t){let n=xa[e]??`Refused (${e}).`;return t.length>0?`${n} ${t}`:n}function Ca(e){if(e.length===0)return null;let t=new Date(e).getTime();return Number.isFinite(t)?t:null}function wa(e){return e<1024*1024?X.t(`helpers.eventsDebugTapes.sizeKb`,{value:(e/1024).toFixed(0)}):X.t(`helpers.eventsDebugTapes.sizeMb`,{value:(e/1024/1024).toFixed(1)})}function Ta(e){return e===null?`unknown`:wa(e)}function Ea(e){return e===null?`unknown`:String(e)}function Da(e,t){let n=t.trim();return e===404?X.t(`helpers.eventsDebugTapes.exportUnknown`):e===503?n.length>0?n:X.t(`helpers.eventsDebugTapes.tapesUnavailable`):e===500?n.length>0?n:X.t(`helpers.eventsDebugTapes.exportUnreadable`):X.t(`helpers.eventsDebugTapes.downloadFailed`,{status:e})}e();function Oa({cameras:e,call:t,onPromoted:n}){let{t:i}=Z(),[o,s]=r(``),[c,l]=r(``),[u,f]=r(``),[p,m]=r(``),[h,g]=r(``),[_,v]=r(`auto`),[y,b]=r(!1),[x,S]=r(null),C=async()=>{let r=Number.parseInt(o===``?e[0]?.value??``:o,10),i=Ca(c),a=Ca(u);if(!Number.isFinite(r)||i===null||a===null){S(`Pick a camera and both ends of the window.`);return}b(!0),S(null);try{let e=ca(await t(Wi.promote,{deviceId:r,fromMs:i,toMs:a,scenario:p,...h.trim().length>0?{note:h.trim()}:{},..._===`day`||_===`ir`?{lighting:_}:{}}));e===null?S(Yi):e.ok?(S(`Promoted ${e.tapeId}: ${String(e.frames)} frames, ${wa(e.bytes)}, ${String(e.pinnedTracks)} tracks pinned`+(e.state===`incomplete`?` — incomplete (it has gaps) and cannot become a case.`:`.`)),n()):S(Sa(e.reason,e.detail))}catch(e){S(Xi(e))}finally{b(!1)}};return a(`div`,{className:`flex flex-wrap items-end gap-2 rounded-md border border-border px-3 py-2`,children:[d(`div`,{className:`w-40`,children:d(ke,{value:o,options:[...e],onChange:e=>s(e.target.value),"aria-label":i(`eventsDebugTapesPromoteForm.camera`,`Camera`)})}),d(_e,{type:`datetime-local`,"aria-label":i(`eventsDebugTapesPromoteForm.from`,`From`),value:c,onChange:e=>l(e.target.value),className:`w-48`}),d(_e,{type:`datetime-local`,"aria-label":i(`eventsDebugTapesPromoteForm.to`,`To`),value:u,onChange:e=>f(e.target.value),className:`w-48`}),d(_e,{"aria-label":i(`eventsDebugTapesPromoteForm.scenario`,`Scenario`),placeholder:`615-door-groups`,value:p,onChange:e=>m(e.target.value),className:`w-44`}),d(_e,{"aria-label":i(`eventsDebugTapesPromoteForm.note`,`Note`),placeholder:i(`eventsDebugTapesPromoteForm.optionalNote`,`optional note`),value:h,onChange:e=>g(e.target.value),className:`w-52`}),d(`div`,{className:`w-28`,children:d(ke,{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)})}),a(Y,{onClick:()=>void C(),disabled:y||e.length===0,children:[y?d(M,{className:`h-3.5 w-3.5 animate-spin`}):null,` `,i(`eventsDebugTapes.promoteWindow`)]}),d(`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&&d(`p`,{className:`w-full text-xs text-foreground`,children:x})]})}var ka=`pipeline-analytics`,Aa=`debug.listTracks`,ja=`debug.analyze`,Ma=w(`/addon/pipeline-analytics/debug-export`);function Na(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Pa(e,t){let n=e[t];return typeof n==`string`?n:null}function Fa(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Ia(e,t){let n=e[t];return typeof n==`boolean`?n:null}function La(e){return e===`error`||e===`warn`||e===`info`}function Ra(e){if(!Na(e))return null;let t=Pa(e,`code`),n=Pa(e,`detail`),r=e.severity;return t===null||n===null||!La(r)?null:{code:t,severity:r,detail:n}}function za(e){if(!Na(e))return null;let t=Pa(e,`trackId`),n=Fa(e,`deviceId`),r=Pa(e,`className`),i=Fa(e,`firstSeen`),a=Fa(e,`lastSeen`),o=Fa(e,`durationMs`),s=Ia(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=Pa(e,`label`),l=Pa(e,`subLabel`),u=Pa(e,`previewMissReason`),d=Ia(e,`markForTrain`),f=Ia(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:Fa(e,`importance`)??0,bestEventId:Pa(e,`bestEventId`)??``,...d===null?{}:{markForTrain:d},...f===null?{}:{favourited:f},debug:!0,...u===null||u.length===0?{}:{previewMissReason:u}}}function Ba(e){let t=za(e);if(t===null||!Na(e))return null;let n=Fa(e,`mediaCount`),r=Fa(e,`eventCount`),i=Fa(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=Ra(e);t!==null&&c.push(t)}let l=e.thumbnailProvenance;return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c,...Qr(l)?{thumbnailProvenance:l}:{}}}function Va(e){if(!Na(e))return null;let t=Ia(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=za(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function Ha(e){if(!Na(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=Ba(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var Ua={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 Wa(e){return Ua[e]??e}var Ga={error:0,warn:1,info:2};function Ka(e){return e.toSorted((e,t)=>Ga[e.severity]-Ga[t.severity]||e.code.localeCompare(t.code))}function qa(e){return e.length===0?Ma:`${Ma}?deviceIds=${e.join(`,`)}`}function Ja(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 Ya(e,t){return`${String(e)}:${t}`}function Xa(e,t){let n=[],r=new Set;for(let i of e){let e=Ya(i.deviceId,i.trackId);!t.has(e)||r.has(e)||(r.add(e),n.push({deviceId:i.deviceId,trackId:i.trackId}))}return n}e();function Za({tapeId:e,call:t,onClose:n,onChanged:i}){let{t:o}=Z(),c=s({queryKey:[`events-debug`,`tapes`,`tracks`,e],queryFn:async()=>sa(await t(Wi.tracks,{tapeId:e}))}),l=c.data??null,u=s({queryKey:[`events-debug`,`tapes`,`marks`,e],enabled:l!==null,queryFn:async()=>l===null?null:ma(await t(Gi.list,{deviceId:l.deviceId,since:l.fromMs-qi,until:l.toMs+qi,limit:5e3}))}),[f,p]=r([]),[m,h]=r(``),[g,_]=r(null),v=e=>p(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),y=async e=>{_(null);try{for(let[n,r]of e)await t(n,r);p([]),await u.refetch(),i()}catch(e){_(Xi(e))}};if(l===null)return c.isLoading?d(`p`,{className:`text-xs`,children:o(`eventsDebugTapesReview.loadingTheTape`,`Loading the tape…`)}):d(Ne,{message:Yi});let b=l.deviceId,x=(e,t)=>y(e.map(e=>[Gi.setRelation,{deviceId:b,...e,relation:t}])),S=e=>{let t=Number.parseFloat(m),n=e===`mixed`&&Number.isFinite(t)?l.fromMs+t*1e3:void 0;return y(f.map(t=>[Gi.setPurity,{deviceId:b,trackId:t,purity:e,...n===void 0?{}:{switchAtMs:Math.round(n)}}]))},C=u.data==null?null:ha(u.data);return a(`div`,{className:`space-y-2 rounded-md border border-primary/40 px-3 py-2`,children:[a(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d(`span`,{className:`text-xs font-medium`,children:o(`eventsDebugTapes.reviewLanes`,{id:l.tapeId,count:l.lanes.length})}),d(Y,{disabled:f.length<2,onClick:()=>void x(_a(f),`same-subject`),children:o(`eventsDebugTapesReview.sameSubject`,`Same subject`)}),d(Y,{variant:`secondary`,disabled:f.length<2,onClick:()=>void x(va(f),`different-subjects`),children:o(`eventsDebugTapesReview.differentSubjects`,`Different subjects`)}),d(_e,{"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`}),d(Y,{variant:`secondary`,disabled:f.length!==1,onClick:()=>void S(`mixed`),children:o(`eventsDebugTapesReview.mixed`,`Mixed`)}),d(Y,{variant:`secondary`,disabled:f.length===0,onClick:()=>void S(`not-a-subject`),children:o(`eventsDebugTapesReview.notASubject`,`Not a subject`)}),d(Y,{variant:l.reviewed?`secondary`:`primary`,onClick:()=>void y([[Wi.review,{tapeId:l.tapeId,reviewed:!l.reviewed}]]).then(()=>c.refetch()),children:l.reviewed?o(`eventsDebugTapesReview.markNotReviewed`,`Mark not reviewed`):o(`eventsDebugTapesReview.markReviewed`,`Mark reviewed`)}),d(Y,{variant:`ghost`,onClick:n,children:o(`common.close`,`Close`)})]}),g!==null&&d(Ne,{message:g}),C!==null&&d(Ne,{variant:`warning`,message:C}),d(`ul`,{className:`space-y-1`,children:l.lanes.toSorted((e,t)=>e.firstT-t.firstT).map(e=>d(Qa,{lane:e,marks:u.data===null||u.data===void 0?[]:ya(e.trackId,u.data),selected:f.includes(e.trackId),onToggle:()=>v(e.trackId)},e.trackId))})]})}function Qa({lane:e,marks:t,selected:n,onToggle:r}){let{t:i}=Z(),{src:o}=zt(e.stillStored?Bt(`track`,e.trackId):void 0);return a(`li`,{className:`flex items-center gap-2 text-xs`,children:[d(`input`,{type:`checkbox`,"aria-label":i(`eventsDebugTapesReview.select`,`select {{trackId}}`,{trackId:e.trackId}),checked:n,onChange:r}),o===null?d(`div`,{className:`h-10 w-10 rounded bg-surface-hover`}):d(`img`,{src:o,alt:e.trackId,className:`h-10 w-10 rounded object-cover`}),d(`span`,{className:`font-mono`,children:e.trackId}),d(`span`,{children:e.cls}),d(`span`,{className:`text-foreground-subtle`,children:i(`eventsDebugTapes.laneFrames`,{range:`${Ja(e.firstT)} → ${Ja(e.lastT)}`,count:e.boundFrames})}),!e.stillStored&&d(`span`,{className:`text-foreground-subtle`,children:i(`eventsDebugTapesReview.notStoredMarkedThroughThe`,`not stored — marked through the tape`)}),t.map(e=>d(et,{variant:`info`,children:e},e))]})}e();var $a=`camstack_admin_token`;function eo(){let e=ee();return(t,n)=>e.trpcClient.addons.custom.mutate({addonId:ka,action:t,input:n})}async function to(e,t){let n=localStorage.getItem($a),r={};n!==null&&(r.Authorization=`Bearer ${n}`);let i=await fetch(Ji(e),{headers:r});if(!i.ok){let e=await i.text().catch(()=>``);throw Error(Da(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 no(){let{t:e}=Z(),[t,n]=r(!1);return d(it,{expanded:t,onExpandedChange:n,header:d(`span`,{className:`text-sm font-medium text-foreground`,children:e(`eventsDebugTapes.trackingTapes`,`Tracking tapes`)}),children:d(ro,{})})}function ro(){let{t:e}=Z(),t=eo(),i=ct({isCamera:!0,projection:`slim`}),o=n(()=>{let t=new Map;for(let e of i.data??[])t.set(e.id,e.name);return n=>t.get(n)??e(`cameraLoad.deviceLabel`,{deviceId:n})},[i.data,e]),c=s({queryKey:[`events-debug`,`tapes`,`status`],queryFn:async()=>ra(await t(Wi.status,{}))}),l=s({queryKey:[`events-debug`,`tapes`,`list`],queryFn:async()=>aa(await t(Wi.list,{}))}),[u,f]=r(null),[p,m]=r(null),h=async e=>{m(null);try{await to(e.id,`${e.scenario}.tape-bundle.json.gz`)}catch(e){m(Xi(e))}},g=async e=>{let n=la(await t(Wi.release,{tapeId:e.id}));if(n===null)throw Error(Yi);let r=da(n);if(r!==null)throw Error(r);await l.refetch()},y=async e=>{let n=ua(await t(Wi.remove,{tapeId:e.id}));if(n===null)throw Error(Yi);let r=da(n);if(r!==null)throw Error(r);await l.refetch()};return a(`div`,{className:`space-y-3`,children:[d(`p`,{className:`text-xs text-foreground-subtle`,children:d(Pt,{i18nKey:`eventsDebugTapes.intro`,components:{b:d(`strong`,{}),code:d(`code`,{})}})}),p!==null&&d(Ne,{message:p}),c.isLoading&&d(`p`,{className:`text-xs text-foreground-subtle`,children:e(`eventsDebugTapes.loadingCameraStatus`,`Loading camera status…`)}),c.data===null&&d(Ne,{message:`The server answered in a shape this build does not understand.`}),a(`table`,{className:`w-full text-xs`,children:[d(`thead`,{children:a(`tr`,{className:`text-left text-foreground-subtle`,children:[d(`th`,{children:e(`eventsDebugTapes.camera`,`Camera`)}),d(`th`,{children:e(`eventsDebugTapes.state`,`State`)}),d(`th`,{children:e(`eventsDebugTapes.framesMin`,`Frames/min`)}),d(`th`,{children:e(`eventsDebugTapes.lastHour`,`Last hour`)}),d(`th`,{children:e(`eventsDebugTapes.held`,`Held`)}),d(`th`,{children:e(`eventsDebugTapes.gaps`,`Gaps`)})]})}),d(`tbody`,{children:(c.data??[]).map(t=>a(`tr`,{children:[d(`td`,{children:o(t.deviceId)}),d(`td`,{children:d(et,{variant:t.state===`recording`?`success`:t.state===`off`?`default`:t.state===`unknown`?`warning`:`danger`,children:ba(t)})}),d(`td`,{children:t.framesPerMin===void 0?`—`:String(Math.round(t.framesPerMin))}),d(`td`,{title:t.shelfError,children:Ta(t.bytesLastHour)}),d(`td`,{title:t.shelfError,children:e(`eventsDebugTapes.segsHeld`,{count:Ea(t.segmentsHeld),size:Ta(t.bytesHeld)})}),d(`td`,{children:String(t.gapsSinceArmed)})]},t.deviceId))})]}),d(Oa,{cameras:ga(c.data??[]).map(t=>({value:String(t.deviceId),label:t.segmentsUnknown?e(`eventsDebugTapes.segmentsUnknown`,`{{value1}} (segments unknown)`,{value1:o(t.deviceId)}):o(t.deviceId)})),call:t,onPromoted:()=>void l.refetch()}),l.isLoading&&d(`p`,{className:`text-xs text-foreground-subtle`,children:e(`eventsDebugTapes.loadingPromotedTapes`,`Loading promoted tapes…`)}),l.data===null&&d(Ne,{message:`The server answered in a shape this build does not understand.`}),a(`table`,{className:`w-full text-xs`,children:[d(`thead`,{children:a(`tr`,{className:`text-left text-foreground-subtle`,children:[d(`th`,{children:e(`eventsDebugTapes.scenario`,`Scenario`)}),d(`th`,{children:e(`eventsDebugTapes.camera`,`Camera`)}),d(`th`,{children:e(`eventsDebugTapes.window`,`Window`)}),d(`th`,{children:e(`eventsDebugTapes.state`,`State`)}),d(`th`,{children:e(`eventsDebugTapes.tracks`,`Tracks`)}),d(`th`,{})]})}),d(`tbody`,{children:(l.data??[]).map(t=>a(`tr`,{children:[d(`td`,{children:t.scenario}),d(`td`,{children:o(t.deviceId)}),a(`td`,{children:[new Date(t.fromMs).toLocaleString(),` · `,Ja(t.toMs-t.fromMs),` `,`· `,t.lighting]}),a(`td`,{children:[d(et,{variant:t.state===`complete`?`success`:`warning`,children:t.state}),` `,t.reviewed&&d(et,{variant:`info`,children:e(`eventsDebugTapes.reviewed`)}),` `,t.released&&d(et,{children:e(`eventsDebugTapes.released`)})]}),d(`td`,{children:e(`eventsDebugTapes.storedOf`,{stored:String(t.tracksStillStored),total:String(t.tracks.length)})}),a(`td`,{className:`space-x-1 text-right`,children:[d(Y,{variant:`secondary`,"aria-label":e(`eventsDebugTapes.review`,`Review {{scenario}}`,{scenario:t.scenario}),onClick:()=>f(t.id),children:e(`eventsDebugTapes.review2`,`Review`)}),d(Y,{variant:`ghost`,"aria-label":e(`eventsDebugTapes.download`,`Download {{scenario}}`,{scenario:t.scenario}),onClick:()=>void h(t),children:d(_,{className:`h-3.5 w-3.5`})}),d(De,{label:e(`eventsDebugTapes.release`,`Release`),icon:U,title:e(`eventsDebugTapes.release2`,`Release {{scenario}}?`,{scenario:t.scenario}),description:e(`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:e(`eventsDebugTapes.release`,`Release`),triggerVariant:`ghost`,confirmVariant:`danger`,disabled:t.released,action:()=>g(t)}),d(De,{label:e(`common.delete`,`Delete`),icon:v,title:e(`eventsDebugTapes.delete`,`Delete {{scenario}}?`,{scenario:t.scenario}),description:e(`eventsDebugTapes.deletingRemovesThePromotedBundle`,`Deleting removes the promoted bundle and its index row for good. Its tracks' pins are released first — this cannot be undone.`),confirmLabel:e(`common.delete`,`Delete`),triggerVariant:`ghost`,confirmVariant:`danger`,action:()=>y(t)})]})]},t.id))})]}),u!==null&&d(Za,{tapeId:u,call:t,onClose:()=>f(null),onChanged:()=>void l.refetch()})]})}e();var io=`all`,ao=`The server answered in a shape this build does not understand.`,oo={error:`danger`,warn:`warning`,info:`info`};function so({findings:e}){let{t}=Z();return e.length===0?d(et,{variant:`success`,children:t(`eventsDebug.noAnomalyFound`,`no anomaly found`)}):d(`div`,{className:`flex flex-wrap gap-1`,children:Ka(e).map(e=>d(et,{variant:oo[e.severity],title:e.detail,children:Wa(e.code)},e.code))})}function co({track:e,report:t,analyzing:n}){let{t:r}=Z(),i=ni(t?.previewMissReason??e.previewMissReason);return a(`div`,{className:`space-y-1 border-t border-border pt-1.5`,children:[t===void 0?d(`span`,{className:`text-[10px] text-foreground-subtle`,children:n?r(`eventsDebug.analysing`,`analysing…`):r(`eventsDebug.notAnalysed`,`not analysed`)}):a(c,{children:[d(so,{findings:t.findings}),d(`p`,{className:`text-[10px] text-foreground-subtle`,title:t.mediaKinds.length>0?t.mediaKinds.join(`, `):r(`eventsDebug.noMediaOfAnyKind`,`no media of any kind`),children:r(`eventsDebug.reportCounts`,{media:String(t.mediaCount),events:String(t.eventCount),positions:String(t.positionCount)})})]}),i!==null&&d(`p`,{className:`text-[10px] text-foreground-subtle`,title:i.raw,children:i.sentence})]})}function lo(){let{t:e}=Z(),t=ee(),[i,o]=r(io),[c,l]=r(!1),[u,p]=r(null),[m,g]=r(new Set),[v,y]=r(null),[b,x]=r(null),[S,C]=r(null),[w,T]=r([]),E=bi(),D=ct({isCamera:!0,projection:`slim`}),O=n(()=>[{value:io,label:e(`eventsDebug.allCameras`,`All cameras`)},...(D.data??[]).map(e=>({value:String(e.id),label:e.name}))],[D.data,e]),k=n(()=>{let e=new Map;for(let t of D.data??[])e.set(t.id,t.name);return e},[D.data]),A=t=>k.get(t)??e(`eventsDebug.cameraFallback`,{deviceId:t}),j=n(()=>i===io?[]:[Number.parseInt(i,10)],[i]),P=s({queryKey:[`events-debug`,`list`,j],queryFn:async()=>Va(await t.trpcClient.addons.custom.mutate({addonId:ka,action:Aa,input:j.length===0?{}:{deviceIds:j}}))}),F=n(()=>(P.data?.tracks??[]).map(e=>e.trackId),[P.data]),L=s({queryKey:[`events-debug`,`analyze`,F],enabled:F.length>0,queryFn:async()=>Ha(await t.trpcClient.addons.custom.mutate({addonId:ka,action:ja,input:{trackIds:F}}))}),R=n(()=>{let e=new Map;for(let t of L.data?.reports??[])e.set(t.trackId,t);return e},[L.data]),z=P.data?.tracks??[],B=P.data===null||L.data===null,H=()=>{P.refetch(),L.refetch()},U=e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},W=()=>{g(new Set(z.map(e=>Ya(e.deviceId,e.trackId))))},G=()=>g(new Set),te=async(e,t)=>{let n=e===`analyzed`?{debug:!1}:{favourited:!0},r=0,i=[];for(let e of t)try{await E.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,flags:n}),r+=1}catch{i.push(e.trackId)}return{applied:r,refused:i}},K=e=>{if(!_i||b!==null)return;let t=Xa(z,m);t.length!==0&&(x(e),C(null),(async()=>{let n=await te(e,t);x(null);let r=new Set(n.refused);g(new Set(t.filter(e=>r.has(e.trackId)).map(e=>Ya(e.deviceId,e.trackId)))),e===`analyzed`&&T(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()})())},q=()=>{let e=w;e.length===0||b!==null||(x(`analyzed`),C(null),(async()=>{for(let t of e)try{await E.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),T([]),P.refetch()})())},re=async()=>{l(!0),p(null);try{await Ut(qa(j),`camstack-debug.zip`)}catch(e){p(e instanceof Error?e.message:`Export failed.`)}finally{l(!1)}},J=b!==null;return a(`section`,{className:`space-y-3`,children:[a(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`div`,{className:`w-44`,children:d(ke,{value:i,options:O,onChange:e=>o(e.target.value)})}),a(Y,{variant:`secondary`,onClick:H,disabled:P.isFetching,children:[P.isFetching?d(M,{className:`h-3.5 w-3.5 animate-spin`}):d(ne,{className:`h-3.5 w-3.5`}),e(`common.refresh`,`Refresh`)]}),a(Y,{onClick:()=>void re(),disabled:c||z.length===0,children:[c?d(M,{className:`h-3.5 w-3.5 animate-spin`}):d(_,{className:`h-3.5 w-3.5`}),e(`eventsDebug.exportAll`,{count:String(z.length)})]}),z.length>0&&m.size<z.length&&d(Y,{variant:`ghost`,onClick:W,children:e(`eventsDebug.selectAll`,`Select all`)})]}),d(`p`,{className:`text-xs text-foreground-subtle`,children:d(Pt,{i18nKey:`eventsDebug.debugMarkNote`,components:{code:d(`code`,{}),strong:d(`strong`,{})}})}),d(no,{}),P.isError&&d(Ne,{message:e(`eventsDebug.couldNotLoadTheMarked`,`Could not load the marked tracks.`)}),B&&!P.isError&&d(Ne,{message:ao}),u!==null&&d(Ne,{message:u}),S!==null&&d(Ne,{message:S}),P.data?.truncated===!0&&d(Ne,{message:e(`eventsDebug.aCameraFilledThePer`,`A camera filled the per-camera cap — some marked tracks are not listed. Un-mark a few, or filter to one camera.`)}),(L.data?.vanished.length??0)>0&&d(`p`,{className:`text-xs text-foreground-subtle`,children:e(`eventsDebug.vanished`,{count:String(L.data?.vanished.length)})}),m.size>0&&a(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[d(`span`,{className:`text-xs font-medium text-foreground`,children:e(`common.selectedCount`,{count:m.size})}),a(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[d(`span`,{title:_i?void 0:`Track flags arrive with the next server update`,children:a(Y,{variant:`secondary`,onClick:()=>K(`keep`),disabled:!_i||J,children:[b===`keep`?d(M,{className:`h-3.5 w-3.5 animate-spin`}):d(V,{className:`h-3.5 w-3.5`}),` `,e(`eventsDebug.keep`,`Keep`)]})}),d(`span`,{title:_i?void 0:`Track flags arrive with the next server update`,children:a(Y,{onClick:()=>K(`analyzed`),disabled:!_i||J,children:[b===`analyzed`?d(M,{className:`h-3.5 w-3.5 animate-spin`}):d(N,{className:`h-3.5 w-3.5`}),` `,e(`eventsDebug.analyzed`,`Analyzed`)]})}),d(Y,{variant:`ghost`,onClick:G,disabled:J,children:d(I,{className:`h-3.5 w-3.5`})})]})]}),w.length>0&&a(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-border bg-surface px-3 py-2`,children:[d(`span`,{className:`text-xs text-foreground`,children:e(`eventsDebug.markedAnalyzed`,{count:String(w.length)})}),a(Y,{variant:`ghost`,onClick:q,disabled:J,children:[d(f,{className:`h-3.5 w-3.5`}),` `,e(`eventsDebug.undo`)]}),d(Y,{variant:`ghost`,onClick:()=>T([]),disabled:J,children:d(I,{className:`h-3.5 w-3.5`})})]}),P.isLoading?d(Ee,{status:`pending`,pendingMessage:`Loading…`,testId:`debug-tracks-grid`}):z.length===0?d(Be,{icon:h,title:e(`eventsDebug.noTrackIsMarkedFor`,`No track is marked for debug`),description:e(`eventsDebug.markOneFromATrack`,`Mark one from a track's actions on the Feed to see it here.`)}):d(Ee,{status:`ready`,testId:`debug-tracks-grid`,children:z.map(e=>{let t=R.get(e.trackId);return d(ii,{row:e,cameraName:A(e.deviceId),nowMs:e.lastSeen,selected:m.has(Ya(e.deviceId,e.trackId)),onToggleSelect:U,onOpenDetail:y,...t?.thumbnailProvenance===void 0?{}:{provenance:t.thumbnailProvenance},footer:d(co,{track:e,report:t,analyzing:L.isFetching})},Ya(e.deviceId,e.trackId))})}),v&&d(Ui,{row:v,cameraName:A(v.deviceId),deleteAvailable:ji,onClose:()=>y(null),onDeleted:()=>{y(null),P.refetch()},onFlagsChanged:e=>{e.debug||(y(null),P.refetch())}})]})}var uo=200,fo=3e4,po=[];function mo(e){let t=ee(),n=e.deviceIds.length>0,r=[...e.deviceIds].sort((e,t)=>e-t),{data:i,isLoading:a}=s({queryKey:[`events-feed`,r,e.since,e.until,e.minImportance??null,e.classFilter??null],enabled:n,staleTime:fo,refetchInterval:fo,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEventsBatch.query({deviceIds:r,since:e.since,until:e.until,limit:uo,...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:Kr(Gr(i??po),`importance`),isLoading:n&&a}}e();var ho=[`events-feed`],go=2e3;function _o(e){let n=l(),a=e?.paused===!0,o=u(n);o.current=n;let s=u(a);s.current=a;let[c,d]=r(!1),f=i(()=>{o.current.invalidateQueries({queryKey:ho})},[]),p=u(void 0);p.current||=Rr({delayMs:go,invalidate:()=>{s.current?d(!0):f()}}),t(()=>()=>p.current?.cancel(),[]),t(()=>{a||!c||(d(!1),f())},[a,c,f]);let m=i(()=>{d(!1),f()},[f]);return Et(me.PipelineAnalyticsDetectionEvent,()=>{p.current?.trigger()}),Et(me.PipelineAnalyticsTrackEnded,()=>{p.current?.trigger()}),{pending:c,refreshNow:m}}e();function vo({groups:e,selected:t,onChange:i,loading:o=!1}){let{t:s}=Z(),[c,l]=r(!1),[u,f]=r(``),[p,m]=r(new Set),h=u.trim().toLowerCase(),g=e=>h.length===0||bt(e,s).toLowerCase().includes(h),_=n(()=>e.map(e=>({macro:e.macro,subs:e.subs.filter(t=>g(t)||g(e.macro))})).filter(e=>g(e.macro)||e.subs.length>0),[e,h]),v=e=>m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),y=e=>{let n=new Set(t),r=t.has(e.macro.kind)&&e.subs.every(e=>t.has(e.kind)),a=[e.macro.kind,...e.subs.map(e=>e.kind)];if(r)for(let e of a)n.delete(e);else for(let e of a)n.add(e);i(n)},b=e=>{let n=new Set(t);n.has(e)?n.delete(e):n.add(e),i(n)},x=()=>i(new Set),S=t.size;return a(`div`,{className:`relative`,children:[a(`button`,{type:`button`,onClick:()=>l(e=>!e),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${S>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[d(E,{className:`h-3.5 w-3.5`}),S>0?s(`detectionIntelligence.eventKindFilter.kinds`,`Kinds ({{value1}})`,{value1:String(S)}):s(`detectionIntelligence.eventKindFilter.kinds2`,`Kinds`),d(q,{className:`h-3 w-3`})]}),c&&a(`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:[a(`div`,{className:`mb-2 flex items-center gap-1 rounded border border-border px-1.5`,children:[d(F,{className:`h-3.5 w-3.5 text-foreground-subtle`}),d(`input`,{type:`text`,value:u,onChange:e=>f(e.target.value),placeholder:s(`detectionIntelligence.eventKindFilter.searchKinds`,`Search kinds…`),className:`w-full bg-transparent py-1 text-xs outline-none`}),S>0&&d(`button`,{type:`button`,onClick:x,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:s(`detectionIntelligence.eventKindFilter.clear`,`Clear`)})]}),_.length===0&&d(`div`,{className:`px-1 py-2 text-[11px] text-foreground-subtle`,children:o?s(`detectionIntelligence.eventKindFilter.loadingKinds`,`Loading kinds…`):h.length>0?s(`detectionIntelligence.eventKindFilter.noKindMatchesThatSearch`,`No kind matches that search.`):s(`detectionIntelligence.eventKindFilter.theseCamerasAdvertiseNoEvent`,`These cameras advertise no event kinds.`)}),_.map(e=>{let n=ut(e.macro.iconId),r=p.has(e.macro.kind)||h.length>0,i=t.has(e.macro.kind);return a(`div`,{className:`mb-0.5`,children:[a(`div`,{className:`flex items-center gap-1`,children:[e.subs.length>0?d(`button`,{type:`button`,onClick:()=>v(e.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":s(`detectionIntelligence.eventKindFilter.expand`,`Expand`),children:d(r?q:A,{className:`h-3 w-3`})}):d(`span`,{className:`w-3`}),a(`label`,{className:`flex flex-1 cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[d(`input`,{type:`checkbox`,checked:i,onChange:()=>y(e),className:`accent-primary`}),d(n,{className:`h-3.5 w-3.5`,style:{color:e.macro.color}}),d(`span`,{className:`font-medium`,children:bt(e.macro,s)})]})]}),r&&e.subs.map(e=>{let n=ut(e.iconId);return a(`label`,{className:`ml-5 flex cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[d(`input`,{type:`checkbox`,checked:t.has(e.kind),onChange:()=>b(e.kind),className:`accent-primary`}),d(n,{className:`h-3.5 w-3.5`,style:{color:e.color}}),d(`span`,{children:bt(e,s)})]},e.kind)})]},e.macro.kind)})]})]})}function yo(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 bo(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var xo=new Set([`detection`,`package`]);function So(e,t){return[...yo(e,t).values()].filter(e=>e.parentKind===null&&xo.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function Co(e,t){let n=yo(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,bo(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))}e();function wo(){let[e,n]=r(!1),a=u(null),[o,s]=r(0),c=i(e=>{a.current!==e&&(a.current=e,s(e=>e+1))},[]);return t(()=>{let e=a.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()},[o]),{ref:c,scrolledPast:e}}e();var To=[`events-feed`],Eo=60,Do=[{value:`importance`,labelKey:`detectionIntelligence.eventsSection.sortImportance`,icon:ie},{value:`time`,labelKey:`detectionIntelligence.eventsSection.sortRecent`,icon:H}];function Oo(){let{t:e}=Z(),i=l(),o=Ye(),s=Qe(),[u,f]=r(In),[p,m]=r(new Set),[h,g]=r(new Set),[_,y]=r(0),[b,x]=r(`time`),[S,C]=r(new Set),[w,E]=r(null),[D,O]=r(()=>Date.now());t(()=>{let e=setInterval(()=>O(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:k,until:A}=n(()=>Xr({fromMs:u.fromMs,toMs:u.toMs},D),[u.fromMs,u.toMs,D]),j=wo(),{pending:N,refreshNow:P}=_o({paused:w!==null||S.size>0||j.scrolledPast}),{data:F=[]}=ct({isCamera:!0,projection:`slim`}),L=n(()=>F.map(e=>e.id),[F]),{data:R,isLoading:z}=gt({deviceIds:L},{enabled:L.length>0,staleTime:5*6e4}),ee=n(()=>Co(R??[],p),[R,p]),B=Pi(),V=B.isPending,{rows:H,isLoading:U}=mo({deviceIds:L,since:k,until:A,minImportance:_>0?_:void 0,classFilter:h.size===1?[...h][0]:void 0}),W=n(()=>{let e=new Map;for(let t of F??[])e.set(t.id,t.name);return e},[F]),G=t=>W.get(t)??e(`detectionIntelligence.cameraFallback`,{id:String(t)}),te=n(()=>Un(H).map(e=>({id:e,name:G(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[H,W]),K=n(()=>Kr(qr(H,{cameras:p,classes:h,minImportance:_}),b),[H,p,h,_,b]),q=$n(K,Eo,n(()=>JSON.stringify([[...p].sort((e,t)=>e-t),[...h].sort(),_,b,k,A]),[p,h,_,b,k,A])),ne=()=>{i.invalidateQueries({queryKey:To})},re=()=>C(new Set);function J(e){C(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function ie(){if(S.size===0||!ji)return;let t=Yr(H,S),n=[...t.values()].reduce((e,t)=>e+t.length,0);n!==0&&(async()=>{await s({title:e(`detectionIntelligence.eventsSection.deleteTitle`,{count:n}),message:e(`detectionIntelligence.eventsSection.deleteMessage`,{count:n}),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&ae(t)})()}function ae(t){let n=[...t];Promise.allSettled(n.map(([e,t])=>B.mutateAsync({deviceId:e,trackIds:t}))).then(t=>{ne();let r=[],i=new Set;if(t.forEach((e,t)=>{let a=n[t];if(!a)return;let[o,s]=a;if(e.status===`fulfilled`)for(let e of s)i.add(Jr(o,e));else r.push(o)}),C(e=>{let t=new Set(e);for(let e of i)t.delete(e);return t}),r.length>0){let t=r.map(e=>G(e)).join(`, `);o({title:e(`detectionIntelligence.eventsSection.someTracksWereNotDeleted`,`Some tracks were not deleted`),message:e(`detectionIntelligence.eventsSection.failedToDeleteTracksOn`,`Failed to delete tracks on: {{names}}. They remain selected — retry, or check the server logs.`,{names:t}),variant:`danger`})}})}let oe=K.length!==H.length;return a(`div`,{className:`relative space-y-3`,children:[a(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d(sr,{onChange:f}),d(ar,{cameras:te,selected:p,onChange:m}),d(vo,{groups:ee,selected:h,onChange:g,loading:z}),a(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[d(`span`,{children:e(`detectionIntelligence.eventsSection.minScore`,`Min score`)}),d(`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":e(`detectionIntelligence.eventsSection.minimumImportance`,`Minimum importance`)}),d(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(_*100)})]}),d(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Do.map(t=>{let n=t.icon;return a(`button`,{type:`button`,onClick:()=>x(t.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${b===t.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[d(n,{className:`h-3.5 w-3.5`}),` `,e(t.labelKey)]},t.value)})}),!U&&d(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:oe?e(`detectionIntelligence.eventsSection.ofEvents`,`{{value1}} of {{value2}} events`,{value1:String(K.length),value2:String(H.length)}):e(`detectionIntelligence.eventsSection.eventCount`,{count:K.length})})]}),S.size>0&&a(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[d(`span`,{className:`text-xs font-medium text-foreground`,children:e(`common.selectedCount`,{count:S.size})}),a(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[d(`span`,{title:ji?void 0:`Track deletion arrives with the next server update`,children:a(Y,{variant:`secondary`,onClick:ie,disabled:!ji||V,children:[V?d(M,{className:`h-3.5 w-3.5 animate-spin`}):d(v,{className:`h-3.5 w-3.5`}),` `,e(`common.delete`,`Delete`)]})}),d(Y,{variant:`ghost`,onClick:re,disabled:V,children:d(I,{className:`h-3.5 w-3.5`})})]})]}),N&&d(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:d(`button`,{type:`button`,onClick:P,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:e(`detectionIntelligence.eventsSection.newEventsRefresh`,`New events — refresh`)})}),U?d(Ee,{status:`pending`,pendingMessage:`Loading events…`,testId:`events-grid`}):K.length===0?d(Be,{icon:T,title:oe?e(`detectionIntelligence.eventsSection.nothingMatchesTheFilter`,`Nothing matches the filter`):e(`detectionIntelligence.eventsSection.noKeyEventsInThis`,`No key events in this window`),description:oe?e(`detectionIntelligence.eventsSection.widenTheDateRangeClear`,`Widen the date range, clear cameras or kinds, or lower the min score.`):e(`detectionIntelligence.eventsSection.capturedTracksAppearHereWhen`,`Captured tracks appear here when the pipeline scores a key event.`)}):a(c,{children:[d(`div`,{ref:j.ref,"aria-hidden":!0,className:`h-0`}),d(Ee,{status:`ready`,testId:`events-grid`,children:q.pageItems.map(e=>d(ii,{row:e,cameraName:G(e.deviceId),nowMs:D,selected:S.has(Jr(e.deviceId,e.trackId)),onToggleSelect:J,onOpenDetail:E},Jr(e.deviceId,e.trackId)))}),d(nr,{currentPage:q.page,totalItems:q.totalItems,pageSize:q.pageSize,onPageChange:q.setPage,itemNoun:`events`})]}),w&&d(Ui,{row:w,cameraName:G(w.deviceId),deleteAvailable:ji,onClose:()=>E(null),onDeleted:()=>{ne(),E(null)},onFlagsChanged:e=>{E(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug,favourited:e.favourited}:t)}})]})}var ko=`/addon/training`;function Ao(){let{t:e}=Z(),t=Nt();return a(Ie,{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:[a(`div`,{className:`flex min-w-0 flex-1 items-start gap-2.5`,children:[d(K,{className:`mt-0.5 h-4 w-4 shrink-0 text-primary`,"aria-hidden":!0}),a(`div`,{className:`min-w-0 space-y-0.5`,children:[d(`p`,{className:`text-xs font-medium text-foreground`,children:e(`detectionIntelligence.retrainTabCallout.trainingFromThisFeed`,`Training from this feed`)}),d(`p`,{className:`${re} leading-relaxed`,children:e(`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.`)})]})]}),d(Y,{variant:`outline`,size:`sm`,className:`shrink-0 self-start sm:self-center`,onClick:()=>t(ko),children:e(`detectionIntelligence.retrainTabCallout.openTraining`,`Open Training`)})]})}e();var jo=50,Mo=350,No=[{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 Po(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 Fo({onActiveChange:e}){let{t:i}=Z(),[o,s]=r(``),[c,l]=r(`loose`),[u,f]=r(null),[p,m]=r(null),[h,g]=r(null),_=_t(o,Mo).trim(),v=_.length>0;t(()=>{e(v)},[v,e]);let[y,b]=r(()=>Date.now());t(()=>{let e=setInterval(()=>b(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:x=[]}=ct({isCamera:!0,projection:`slim`}),S=n(()=>{let e=new Map;for(let t of x)e.set(t.id,t.name);return e},[x]),C=e=>S.get(e)??i(`detectionIntelligence.cameraFallback`,{id:String(e)}),w=n(()=>x.map(e=>e.id),[x]),{data:T}=gt({deviceIds:w},{enabled:w.length>0,staleTime:5*6e4}),E=n(()=>So(T??[],new Set(p===null?[]:[p])),[T,p]);t(()=>{u!==null&&(E.some(e=>e.kind===u)||f(null))},[E,u]);let{data:D,isFetching:O,isError:k,error:A}=Tt({text:_,strictness:c,limit:jo,classFilter:u??void 0,deviceId:p??void 0},{enabled:v}),j=n(()=>[...D??[]].sort((e,t)=>t.score-e.score).map(e=>({...Po(e),score:e.score})),[D]);function N(e){f(t=>t===e?null:e)}return a(`div`,{className:`space-y-3`,children:[a(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-3`,children:[a(`div`,{className:`flex flex-wrap items-center gap-2`,children:[a(`div`,{className:`relative min-w-[16rem] flex-1`,children:[d(F,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),d(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:i(`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":i(`detectionIntelligence.semanticEventSearch.semanticEventSearch`,`Semantic event search`)}),o&&d(`button`,{type:`button`,onClick:()=>s(``),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":i(`detectionIntelligence.semanticEventSearch.clearSearch`,`Clear search`),children:d(I,{className:`h-3.5 w-3.5`})})]}),O&&v&&d(M,{className:`h-4 w-4 shrink-0 animate-spin text-foreground-subtle`})]}),a(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[d(`div`,{className:`flex items-center gap-1`,children:E.map(e=>d(`button`,{type:`button`,onClick:()=>N(e.kind),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${u===e.kind?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:bt(e)},e.kind))}),a(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[d(`span`,{children:i(`detectionIntelligence.semanticEventSearch.camera`,`Camera`)}),d(ke,{value:p===null?``:String(p),onChange:e=>m(e.target.value===``?null:Number(e.target.value)),className:`h-7 text-xs`,"aria-label":i(`detectionIntelligence.semanticEventSearch.filterByCamera`,`Filter by camera`),options:[{value:``,label:i(`detectionIntelligence.semanticEventSearch.all`,`All`)},...x.map(e=>({value:String(e.id),label:e.name}))]})]}),a(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[d(`span`,{children:i(`detectionIntelligence.semanticEventSearch.match`,`Match`)}),d(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:No.map(e=>d(`button`,{type:`button`,onClick:()=>l(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${c===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:i(e.titleKey),children:i(e.labelKey)},e.value))})]}),v&&!O&&!k&&d(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:i(`common.matches`,{count:j.length})})]})]}),v&&a(`div`,{className:`space-y-3`,children:[k&&a(`p`,{className:`py-4 text-xs text-danger`,children:[i(`detectionIntelligence.semanticEventSearch.searchFailed`,`Search failed:`),` `,A instanceof Error?A.message:i(`detectionIntelligence.semanticEventSearch.unknownError`,`unknown error`),`. Check that the CLIP embedding step is enabled.`]}),!k&&O&&j.length===0&&d(Ee,{status:`pending`,pendingMessage:`Searching…`,testId:`semantic-events-grid`}),!k&&!O&&j.length===0&&d(Ee,{status:`empty`,emptyMessage:i(`detectionIntelligence.semanticEventSearch.noSemanticMatchesForTry`,`No semantic matches for “{{debounced}}”. Try a looser match threshold or a different phrasing.`,{debounced:_}),testId:`semantic-events-grid`}),!k&&j.length>0&&d(Ee,{status:`ready`,testId:`semantic-events-grid`,children:j.map(e=>d(ii,{row:e,cameraName:C(e.deviceId),nowMs:y,score:e.score,onOpenDetail:g},e.id))})]}),h&&d(Ui,{row:h,cameraName:C(h.deviceId),deleteAvailable:ji,onClose:()=>g(null),onDeleted:()=>g(null)})]})}e();function Io(e,t){let n=Math.max(0,Math.round((e-t)/6e4));if(n<1)return X.t(`helpers.relativeTime.justNow`);if(n<60)return`${String(n)}m`;let r=Math.floor(n/60);return`${String(r)}h ${String(n%60)}m`}function Lo({row:e,cameraName:t,nowMs:n}){let{t:r}=Z(),i=zt(e.keyFrameMediaId===void 0?void 0:Ht(e.keyFrameMediaId));return a(`div`,{className:`flex flex-col overflow-hidden rounded-md border border-border bg-surface`,children:[a(`div`,{className:`relative aspect-video overflow-hidden bg-surface-hover`,children:[i.src?d(`img`,{src:i.src,alt:r(`detectionIntelligence.stationarySection.parkedOn`,`Parked {{className}} on {{cameraName}}`,{className:e.className,cameraName:t}),className:`h-full w-full object-cover`}):d(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:d(oe,{className:`h-6 w-6`})}),d(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-medium capitalize text-white`,children:e.label??e.className})]}),a(`div`,{className:`flex flex-col gap-0.5 p-1.5`,children:[d(`span`,{className:`truncate text-[11px] text-foreground`,children:t}),d(`span`,{className:`text-[10px] text-foreground-subtle`,children:r(`common.parkedSince`,{since:Io(n,e.becameStationaryAt)})})]})]})}function Ro(){let{t:e}=Z(),[t,i]=r(!1),o=Date.now(),{data:s=[]}=ct({isCamera:!0,projection:`slim`}),c=n(()=>s.map(e=>e.id),[s]),l=n(()=>{let e=new Map;for(let t of s)e.set(t.id,t.name);return e},[s]),{rows:u,unreadableCount:f}=Rt(c);return u.length===0&&f===0?null:a(`div`,{className:`rounded-md border border-border bg-surface/40`,children:[a(`button`,{type:`button`,onClick:()=>i(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,children:[d(t?q:A,{className:`h-4 w-4 text-foreground-subtle`}),d(oe,{className:`h-4 w-4 text-foreground-subtle`}),d(`span`,{className:`text-sm font-semibold text-foreground`,children:e(`detectionIntelligence.stationarySection.stationary`,`Stationary`)}),d(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:u.length}),d(`span`,{className:`ml-2 text-[11px] text-foreground-subtle`,children:e(`detectionIntelligence.stationarySection.parkedObjectsKeptOutOf`,`Parked objects — kept out of the event feed`)}),f>0?d(`span`,{className:`ml-2 text-[11px] text-warning`,children:e(`detectionIntelligence.stationarySection.unreadable`,{count:f})}):null]}),t&&d(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:u.map(e=>d(Lo,{row:e,cameraName:l.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:o},e.id))})]})}e();function zo(){let[e,t]=r(!1);return a(`section`,{className:`space-y-3`,children:[d(Ao,{}),d(Fo,{onActiveChange:t}),!e&&d(Ro,{}),!e&&d(Oo,{})]})}function Bo(){let{t:e}=Z(),[t]=It();return t.get(`section`)===`retrain`?d(Ft,{to:`/addon/training`,replace:!0}):d(Lt,{sectionsOnly:!0,paramName:`section`,defaultSection:`feed`,sectionsLabel:`Events sections`,sections:[{id:`feed`,label:e(`events.feed`,`Feed`),content:d(zo,{})},{id:`debug`,label:e(`events.debug`,`Debug`),content:d(lo,{})}]})}function Vo(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}e();var Ho=[[`plateGallery`]];function Uo({plateIds:e,vehicles:t,onDone:n}){let{t:i}=Z(),o=l(),s=pt(),c=ot(),[u,f]=r(``),[p,m]=r(!1),[h,g]=r(null),_=e!==null&&e.length>0,v=e?.length??0;function y(){m(!1),f(``),g(null)}function b(){y(),n()}function x(t){!e||e.length===0||s.mutate({plateIds:[...e],vehicleId:t},{onSettled:()=>{o.invalidateQueries({queryKey:Ho}),b()}})}function S(){!e||!u.trim()||c.mutate({name:u.trim()},{onSuccess:e=>{e?.id&&x(e.id)},onError:()=>{o.invalidateQueries({queryKey:Ho}),b()}})}let C=s.isPending||c.isPending;return d(Ue,{open:_,onOpenChange:e=>!e&&b(),children:a(be,{children:[a(ve,{children:[d(dt,{children:v>1?i(`detectionIntelligence.assignPlateDialog.assignPlatesToVehicle`,`Assign {{value1}} plates to vehicle`,{value1:String(v)}):i(`detectionIntelligence.assignPlateDialog.assignPlateToVehicle`,`Assign plate to vehicle`)}),d(Fe,{children:i(`detectionIntelligence.assignPlateDialog.selectAnExistingVehicleOr`,`Select an existing vehicle or create a new one.`)})]}),d(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:t.map(e=>a(`button`,{type:`button`,onClick:()=>g(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${h===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[d(`span`,{className:`font-medium`,children:e.name}),d(`span`,{className:`ml-2 text-foreground-subtle`,children:i(`detectionIntelligence.assignPlateDialog.plates`,{count:e.sampleCount})})]},e.id))}),p?d(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:d(_e,{placeholder:i(`detectionIntelligence.assignPlateDialog.newVehicleName`,`New vehicle name…`),value:u,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&S()},autoFocus:!0,className:`flex-1`})}):d(`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…`)}),a(ft,{children:[d(Y,{variant:`secondary`,onClick:b,disabled:C,children:i(`common.cancel`,`Cancel`)}),p?a(Y,{variant:`primary`,onClick:S,disabled:C||!u.trim(),children:[C&&d(M,{className:`h-3.5 w-3.5 animate-spin`}),i(`detectionIntelligence.assignPlateDialog.createAssign`,`Create & assign`)]}):a(Y,{variant:`primary`,onClick:()=>h&&x(h),disabled:C||!h,children:[C&&d(M,{className:`h-3.5 w-3.5 animate-spin`}),v>1?i(`detectionIntelligence.assignCount`,{count:v}):i(`common.assign`)]})]})]})})}e();var Wo=[[`plateGallery`]];function Go(e){let[n,i]=r(null),[a,o]=r(null),[s,c]=r(!1);return t(()=>{if(i(null),o(null),c(!1),e===void 0)return;let t=!1,n=null;return(async()=>{try{let r=await Vt(Ht(e));if(t)return;n=URL.createObjectURL(r),i(n)}catch{t||c(!0)}})(),()=>{t=!0,n&&URL.revokeObjectURL(n)}},[e]),t(()=>{if(!n)return;let e=new Image;return e.onload=()=>o({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>c(!0),e.src=n,()=>{e.onload=null,e.onerror=null}},[n]),{frameSrc:n,naturalWidth:a?.width??null,naturalHeight:a?.height??null,failed:s}}function Ko(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 qo({label:e,value:t,mono:n}){return a(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[d(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),d(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono`:``}`,title:t,children:t})]})}function Jo({box:e}){let{t}=Z();return d(`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:d(`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 Yo({plate:e,cameraName:i,onClose:o,onAssign:s,onUnassign:c,onDelete:u,actionsPending:f}){let{t:p}=Z(),m=l(),{data:h,isFetching:_}=kt({plateId:e?.plateId??``},{enabled:e!==null}),y=lt(),[b,x]=r(`frame`),[S,w]=r(!1),[T,E]=r(``),{frameSrc:D,naturalWidth:O,naturalHeight:k,failed:A}=Go(e?.keyFrameMediaId);t(()=>{w(!1),E(``),x(`frame`)},[e?.plateId]);let j=n(()=>{let t=Ko(h??[]);return t?t.url:Vo(e)},[h,e]),P=n(()=>!e?.plateBbox||O===null||k===null?null:lr(e.plateBbox,O,k),[e?.plateBbox,O,k]);if(e===null)return null;let F=e.keyFrameMediaId!==void 0&&!A,L=F&&b===`frame`,z=e.assigned?e.vehicleName??`Assigned`:e.recognizedVehicleId?`${e.vehicleName??`Recognized`} (suggested)`:`Unassigned`,ee=`${String(Math.round(e.score*100))}%${e.corrected?` · corrected`:``}`;function V(){e&&(E(e.text),w(!0))}function H(){if(!e)return;let t=T.trim().toUpperCase();if(!t||t===e.text){w(!1);return}y.mutate({plateId:e.plateId,text:t},{onSettled:()=>{m.invalidateQueries({queryKey:Wo}),w(!1)}})}return d(Ue,{open:!0,onOpenChange:e=>!e&&o(),children:a(be,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":p(`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:[d(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:a(`div`,{className:`min-w-0`,children:[d(`div`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:e.text||p(`detectionIntelligence.plateDetailPanel.plateDetail`,`Plate detail`)}),d(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:i})]})}),a(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[F&&a(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[a(`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:[d(B,{className:`h-3.5 w-3.5`}),` `,p(`detectionIntelligence.detailPanel.fullFrame`)]}),a(`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:[d(fe,{className:`h-3.5 w-3.5`}),` `,p(`detectionIntelligence.detailPanel.crop`)]})]}),L&&D?d(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:d(dr,{src:D,alt:p(`detectionIntelligence.plateDetailPanel.fullFrameWithDetectedPlate`,`Full frame with detected plate`),fit:`natural`,className:`w-full`,overlay:P?d(Jo,{box:P}):void 0})}):j?a(`div`,{className:`relative aspect-[2/1] w-full overflow-hidden rounded-lg border border-border bg-background`,children:[d(dr,{src:j,alt:p(`detectionIntelligence.plateDetailPanel.detectedPlate`,`Detected plate`),className:`h-full w-full`}),_&&d(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:d(M,{className:`h-3.5 w-3.5 animate-spin`})})]}):a(`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:[d(R,{className:`h-8 w-8 text-warning/70`}),d(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:p(`detectionIntelligence.plateDetailPanel.noImage`,`No image`)}),d(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:p(`detectionIntelligence.plateDetailPanel.theCropMediaForThis`,`The crop media for this plate could not be resolved. Safe to delete.`)})]}),d(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-2`,children:a(`div`,{className:`flex items-center justify-between gap-3`,children:[d(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:p(`detectionIntelligence.plateDetailPanel.plateText`,`Plate text`)}),S?a(`div`,{className:`flex min-w-0 flex-1 items-center justify-end gap-1.5`,children:[d(_e,{value:T,onChange:e=>E(e.target.value),onKeyDown:e=>{e.key===`Enter`&&H(),e.key===`Escape`&&w(!1)},className:`h-7 max-w-[10rem] text-right font-mono text-xs uppercase`,autoFocus:!0}),d(`button`,{type:`button`,onClick:H,disabled:y.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":p(`detectionIntelligence.plateDetailPanel.saveCorrectedText`,`Save corrected text`),children:y.isPending?d(M,{className:`h-3.5 w-3.5 animate-spin`}):d(N,{className:`h-3.5 w-3.5`})}),d(`button`,{type:`button`,onClick:()=>w(!1),className:`text-foreground-subtle hover:text-foreground`,"aria-label":p(`common.cancel`,`Cancel`),children:d(I,{className:`h-3.5 w-3.5`})})]}):a(`button`,{type:`button`,onClick:V,className:`group flex min-w-0 items-center gap-1.5`,title:p(`detectionIntelligence.plateDetailPanel.correctTheOcrReading`,`Correct the OCR reading`),children:[d(`span`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:e.text||`—`}),d(C,{className:`h-3 w-3 shrink-0 text-foreground-subtle group-hover:text-foreground`})]})]})}),a(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[d(qo,{label:p(`detectionIntelligence.plateDetailPanel.camera`,`Camera`),value:i}),d(qo,{label:p(`detectionIntelligence.plateDetailPanel.captured`,`Captured`),value:Jn(e.timestamp)}),d(qo,{label:p(`detectionIntelligence.plateDetailPanel.confidence`,`Confidence`),value:ee}),d(qo,{label:p(`detectionIntelligence.plateDetailPanel.vehicle`,`Vehicle`),value:z}),d(qo,{label:p(`detectionIntelligence.plateDetailPanel.track`,`Track`),value:e.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:[e.assigned?a(Y,{variant:`secondary`,onClick:()=>c(e.plateId),disabled:f,children:[d(ue,{className:`h-3.5 w-3.5`}),` `,p(`detectionIntelligence.detailPanel.detach`)]}):a(Y,{variant:`primary`,onClick:()=>s(e.plateId),disabled:f,children:[d(g,{className:`h-3.5 w-3.5`}),` `,p(`common.assign`)]}),a(Y,{variant:`secondary`,onClick:()=>u(e.plateId),disabled:f,children:[d(v,{className:`h-3.5 w-3.5`}),` `,p(`common.delete`)]})]})]})})}e();var Xo=[[`plateGallery`]],Zo=500,Qo=120;function $o({plate:e,cameraName:t,nowMs:n,selected:r,onToggleSelect:i,onAssign:o,onOpenDetail:s}){let{t:c}=Z(),u=l(),f=He(),p=$e(),m=()=>{u.invalidateQueries({queryKey:Xo})},h=()=>s(e.plateId),_=Vo(e);return a(`div`,{className:`relative flex flex-col overflow-hidden rounded-md border bg-surface ${r?`border-primary ring-1 ring-primary`:`border-border`}`,children:[a(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[_===null?a(`button`,{type:`button`,onClick:h,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:c(`detectionIntelligence.recentPlates.noCropImageThePlate`,`No crop image — the plate's crop media is missing. Safe to delete.`),children:[d(R,{className:`h-7 w-7 text-warning/70`}),d(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:c(`detectionIntelligence.recentPlates.noCrop`,`No crop`)})]}):d(`img`,{src:_,alt:c(`detectionIntelligence.recentPlates.plateFrom`,`Plate {{text}} from {{cameraName}}`,{text:e.text,cameraName:t}),onClick:h,className:`h-full w-full cursor-zoom-in object-cover`}),d(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),i(e.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":r?c(`detectionIntelligence.recentPlates.deselect`,`Deselect`):c(`detectionIntelligence.recentPlates.select`,`Select`),children:r?d(ce,{className:`h-4 w-4 text-primary`}):d(y,{className:`h-4 w-4`})}),e.corrected&&a(`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:c(`detectionIntelligence.recentPlates.manuallyCorrected`,`Manually corrected`),children:[d(le,{className:`h-3 w-3`}),` `,c(`detectionIntelligence.recentPlates.fixed`)]})]}),a(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[d(`p`,{className:`truncate font-mono text-xs font-bold tracking-wide text-foreground`,title:e.text,children:e.text||`—`}),d(`p`,{className:`truncate text-[10px] text-foreground-subtle`,title:t,children:t}),d(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:Kn(e.timestamp,n)}),e.vehicleName&&d(`p`,{className:`truncate text-[10px] font-medium text-primary`,title:e.vehicleName,children:e.vehicleName})]}),a(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[e.assigned?d(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),f.mutate({plateId:e.plateId},{onSettled:m})},disabled:f.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":c(`detectionIntelligence.recentPlates.detachPlate`,`Detach plate`),title:c(`detectionIntelligence.recentPlates.detach`,`Detach`),children:f.isPending?d(M,{className:`h-4 w-4 animate-spin`}):d(ue,{className:`h-4 w-4`})}):d(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(e.plateId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":c(`detectionIntelligence.recentPlates.assignPlateToVehicle`,`Assign plate to vehicle`),title:c(`detectionIntelligence.recentPlates.assignToVehicle`,`Assign to vehicle`),children:d(g,{className:`h-4 w-4`})}),d(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),p.mutate({plateId:e.plateId},{onSettled:m})},disabled:p.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":c(`detectionIntelligence.recentPlates.deletePlate`,`Delete plate`),title:c(`detectionIntelligence.recentPlates.deletePlate`,`Delete plate`),children:p.isPending?d(M,{className:`h-4 w-4 animate-spin`}):d(v,{className:`h-4 w-4`})})]})]})}var es=[{labelKey:`common.all`,value:`all`},{labelKey:`detectionIntelligence.recentPlates.filterUnassigned`,value:`unassigned`},{labelKey:`detectionIntelligence.recentPlates.filterAssigned`,value:`assigned`}];function ts(e,t){return t===`unassigned`?e.filter(e=>!e.assigned):t===`assigned`?e.filter(e=>e.assigned):e}function ns(){let{t:e}=Z(),t=l(),[i,o]=r(`all`),[s,u]=r(In),[f,p]=r(new Set),[m,h]=r(new Set),[_,y]=r(null),[b,x]=r(null),{data:S,isLoading:C}=tt({limit:Zo,includeCrops:!1},{refetchInterval:3e4}),{data:w=[]}=Ve(),{data:T}=ct({isCamera:!0,projection:`slim`}),E=He(),D=Se(),O=$e(),k=Date.now(),A=S??[],j=n(()=>{let e=new Map;for(let t of T??[])e.set(t.id,t.name);return e},[T]),N=t=>j.get(t)??e(`detectionIntelligence.cameraFallback`,{id:String(t)}),P=n(()=>Un(A).map(e=>({id:e,name:N(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[A,j]),F=n(()=>Hn(Vn(ts(A,i),s),f),[A,i,s,f]),L=$n(F,Qo,n(()=>JSON.stringify([i,s.fromMs,s.toMs,[...f].sort((e,t)=>e-t)]),[i,s.fromMs,s.toMs,f])),z=n(()=>new Map(A.map(e=>[e.plateId,e])),[A]),ee=b===null?null:z.get(b)??null,B=()=>{t.invalidateQueries({queryKey:Xo})},V=()=>h(new Set);function H(e){h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}let U=[...m],W=D.isPending||O.isPending,G=E.isPending||O.isPending;function te(){U.length!==0&&D.mutate({plateIds:U},{onSettled:()=>{B(),V()}})}function K(){U.length!==0&&Promise.allSettled(U.map(e=>O.mutateAsync({plateId:e}))).then(()=>{B(),V()})}function q(e){x(null),y([e])}function ne(e){E.mutate({plateId:e},{onSettled:B}),x(null)}function re(e){O.mutate({plateId:e},{onSettled:B}),x(null)}let J=F.length!==A.length;return a(`div`,{className:`relative space-y-3`,children:[a(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d(`div`,{className:`flex items-center gap-1`,children:es.map(t=>d(`button`,{type:`button`,onClick:()=>o(t.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${i===t.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e(t.labelKey)},t.value))}),d(sr,{onChange:u}),d(ar,{cameras:P,selected:f,onChange:p}),!C&&d(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:J?e(`detectionIntelligence.recentPlates.ofPlates`,`{{value1}} of {{value2}} plates`,{value1:String(F.length),value2:String(A.length)}):e(`detectionIntelligence.recentPlates.plateCount`,{count:F.length})})]}),m.size>0&&a(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[d(`span`,{className:`text-xs font-medium text-foreground`,children:e(`common.selectedCount`,{count:m.size})}),a(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[a(Y,{variant:`primary`,onClick:()=>y(U),disabled:W,children:[d(g,{className:`h-3.5 w-3.5`}),` `,e(`common.assign`)]}),a(Y,{variant:`secondary`,onClick:te,disabled:W,children:[D.isPending?d(M,{className:`h-3.5 w-3.5 animate-spin`}):d(ue,{className:`h-3.5 w-3.5`}),` `,e(`detectionIntelligence.recentPlates.detach`,`Detach`)]}),a(Y,{variant:`secondary`,onClick:K,disabled:W,children:[d(v,{className:`h-3.5 w-3.5`}),` `,e(`common.delete`)]}),d(Y,{variant:`ghost`,onClick:V,disabled:W,children:d(I,{className:`h-3.5 w-3.5`})})]})]}),C?d(Ee,{status:`pending`,pendingMessage:`Loading plates…`,testId:`plates-grid`}):F.length===0?d(Be,{icon:R,title:A.length>0?e(`detectionIntelligence.recentPlates.nothingMatchesTheFilter`,`Nothing matches the filter`):e(`detectionIntelligence.recentPlates.noPlatesRecognizedYet`,`No plates recognized yet`),description:A.length>0?e(`detectionIntelligence.recentPlates.widenTheDateRangeOr`,`Widen the date range or clear the camera filter.`):e(`detectionIntelligence.recentPlates.plateReadsAppearHereWhen`,`Plate reads appear here when the detection pipeline OCRs a vehicle.`)}):a(c,{children:[d(Ee,{status:`ready`,testId:`plates-grid`,children:L.pageItems.map(e=>d($o,{plate:e,cameraName:N(e.deviceId),nowMs:k,selected:m.has(e.plateId),onToggleSelect:H,onAssign:e=>y([e]),onOpenDetail:x},e.plateId))}),d(nr,{currentPage:L.page,totalItems:L.totalItems,pageSize:L.pageSize,onPageChange:L.setPage,itemNoun:`plates`})]}),d(Yo,{plate:ee,cameraName:ee?N(ee.deviceId):``,onClose:()=>x(null),onAssign:q,onUnassign:ne,onDelete:re,actionsPending:G}),d(Uo,{plateIds:_,vehicles:w,onDone:()=>{y(null),V()}})]})}e();var rs=[[`plateGallery`]];function is({vehicleId:e}){let{t}=Z(),n=l(),{data:r,isLoading:i}=Ot({vehicleId:e}),o=ye();function s(t){o.mutate({vehicleId:e,sampleId:t.id},{onSettled:()=>{n.invalidateQueries({queryKey:rs})}})}return i?a(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[d(M,{className:`h-3.5 w-3.5 animate-spin`}),t(`detectionIntelligence.vehiclesList.loadingPlates`,`Loading plates…`)]}):!r||r.length===0?d(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:t(`detectionIntelligence.vehiclesList.noPlatesYet`,`No plates yet.`)}):d(`div`,{className:`mt-2 grid grid-cols-3 gap-2 sm:grid-cols-4 md:grid-cols-6`,children:r.map(e=>a(`div`,{className:`group relative overflow-hidden rounded-md border border-border bg-surface`,children:[a(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[e.base64?d(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:e.text,className:`h-full w-full object-cover`}):d(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:d(p,{className:`h-6 w-6`})}),d(`button`,{type:`button`,onClick:()=>s(e),disabled:o.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":t(`detectionIntelligence.vehiclesList.removePlateSample`,`Remove plate sample`),children:d(I,{className:`h-4 w-4 text-white`})})]}),d(`p`,{className:`truncate px-1.5 py-1 text-center font-mono text-[11px] font-semibold tracking-wide text-foreground`,title:e.text,children:e.text})]},e.id))})}function as(e){return[{key:`vehicle`,header:X.t(`detectionIntelligence.vehiclesList.vehicle`,`Vehicle`),sortValue:e=>e.name,render:e=>a(`span`,{className:`flex min-w-0 items-center gap-2`,children:[d(`span`,{className:`h-8 w-12 shrink-0 overflow-hidden rounded border border-border bg-surface-hover`,children:d(Gt,{mediaId:e.coverMediaId,base64:e.coverBase64,alt:e.name,className:`h-full w-full object-cover`,placeholder:d(`span`,{className:`flex h-full w-full items-center justify-center`,children:d(p,{className:`h-4 w-4 text-foreground-subtle`})})})}),d(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})]})},{key:`samples`,header:X.t(`detectionIntelligence.vehiclesList.plates`,`Plates`),align:`center`,nowrap:!0,sortValue:e=>e.sampleCount,render:e=>d(et,{variant:`default`,className:`text-[10px]`,children:e.sampleCount})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:t=>a(`span`,{className:`flex items-center justify-end gap-1`,children:[d(rt,{variant:`ghost`,size:`sm`,icon:C,"aria-label":X.t(`detectionIntelligence.vehiclesList.edit`,`Edit {{name}}`,{name:t.name}),onClick:n=>{n.stopPropagation(),e.onEdit(t)}}),d(rt,{variant:`ghost`,size:`sm`,icon:v,"aria-label":X.t(`detectionIntelligence.vehiclesList.delete`,`Delete {{name}}`,{name:t.name}),onClick:n=>{n.stopPropagation(),e.onDelete(t)}})]})}]}function os({mode:e,vehicle:n,onClose:i}){let{t:o}=Z(),s=l(),[c,u]=r(e===`edit`?n?.name??``:``),f=ot(),m=Dt();t(()=>{u(e===`edit`?n?.name??``:``)},[e,n?.id,n?.name]);let h=f.isPending||m.isPending,g=c.trim(),_=e===`edit`&&n!==null&&g===n.name,v=h||g.length===0||_;function y(){s.invalidateQueries({queryKey:rs})}function b(){if(!v){if(e===`new`){f.mutate({name:g},{onSuccess:()=>{y(),i()}});return}if(n===null){i();return}m.mutate({id:n.id,name:g},{onSuccess:()=>{y(),i()}})}}return d(jt,{open:!0,onClose:i,title:e===`new`?`Add vehicle`:`Edit ${n?.name??`vehicle`}`,icon:p,width:e===`edit`?`xl`:`lg`,testId:`vehicles-vehicle-form`,footer:a(Y,{variant:`primary`,size:`sm`,type:`button`,onClick:b,disabled:v,children:[h?d(M,{className:`h-3.5 w-3.5 animate-spin`}):null,e===`new`?o(`common.add`,`Add`):o(`common.save`,`Save`)]}),children:a(`div`,{className:`space-y-4`,children:[d(Ce,{label:o(`detectionIntelligence.vehiclesList.name`,`Name`),required:!0,children:d(_e,{value:c,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b()},placeholder:o(`detectionIntelligence.vehiclesList.vehicleName`,`Vehicle name…`),autoFocus:!0})}),e===`edit`&&n!==null&&a(`div`,{children:[d(`p`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:o(`detectionIntelligence.vehiclesList.plateSamples`,`Plate samples`)}),d(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:o(`detectionIntelligence.vehiclesList.removeAPlateCropTo`,`Remove a plate crop to drop it from recognition for this vehicle. Assign new plates from Recent recognized plates.`)}),d(is,{vehicleId:n.id})]})]})})}function ss(){let{t:e}=Z(),r=l(),i=Qe(),{data:o,isLoading:s}=Ve(),c=wt(),{state:u,openNew:f,openEdit:m,close:h}=Me(),g=o??[],_=Pe(g,{searchText:e=>[e.name]}),v=u.mode===`edit`?g.find(e=>e.id===u.id)??null:null;t(()=>{u.mode===`edit`&&!s&&v===null&&h()},[u.mode,s,v,h]);let y=n(()=>as({onEdit:e=>m(e.id),onDelete:t=>{(async()=>{await i({title:e(`detectionIntelligence.vehiclesList.deleteVehicle`,`Delete vehicle`),message:e(`detectionIntelligence.vehiclesList.deleteAndAllItsPlate`,`Delete {{name}} and all its plate samples? This cannot be undone.`,{name:t.name}),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&c.mutate({id:t.id},{onSettled:()=>{r.invalidateQueries({queryKey:rs}),u.mode===`edit`&&u.id===t.id&&h()}})})()}}),[i,h,c,u,m,r,e]);if(s)return a(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[d(M,{className:`h-4 w-4 animate-spin`}),e(`detectionIntelligence.vehiclesList.loadingVehicles`,`Loading vehicles…`)]});let b=u.mode===`new`||u.mode===`edit`&&v!==null;return a(`div`,{className:`space-y-2`,children:[d(`div`,{className:`flex flex-wrap items-center gap-2`,children:a(Y,{variant:`primary`,size:`sm`,type:`button`,onClick:f,children:[d(S,{className:`h-3.5 w-3.5`}),e(`detectionIntelligence.vehiclesList.addVehicle`,`Add vehicle`)]})}),(g.length>0||_.active)&&d(Le,{state:_.state,facets:_.facets,labels:{searchPlaceholder:`Search vehicles…`,searchLabel:`Search vehicles`,facetsLabel:`Filter`,clearLabel:`Clear`},onSearch:_.setSearch,onToggleFacet:_.toggleFacet,onClear:_.clear}),_.rows.length===0?d(Be,{icon:p,title:_.active?e(`detectionIntelligence.vehiclesList.nothingMatchesTheFilter`,`Nothing matches the filter`):e(`detectionIntelligence.vehiclesList.noVehiclesEnrolledYet`,`No vehicles enrolled yet`),description:_.active?e(`detectionIntelligence.vehiclesList.clearTheSearchOrTry`,`Clear the search or try another name.`):e(`detectionIntelligence.vehiclesList.addAVehicleThenAssign`,`Add a vehicle, then assign plate crops from Recent recognized plates.`)}):d(We,{columns:y,rows:_.rows,rowKey:e=>e.id,maxBodyHeight:qe,emptyMessage:e(`detectionIntelligence.vehiclesList.noVehiclesEnrolledYet2`,`No vehicles enrolled yet.`),onRowClick:e=>m(e.id)}),b&&d(os,{mode:u.mode===`new`?`new`:`edit`,vehicle:v,onClose:h})]})}e();var cs=[[`plateGallery`]],ls=2e3;function us(){let e=l(),n=u(e);n.current=e;let r=u(void 0);r.current||=Rr({delayMs:ls,invalidate:()=>{n.current.invalidateQueries({queryKey:cs})}}),t(()=>()=>r.current?.cancel(),[]),Et(me.PipelineAnalyticsPlateGalleryChanged,()=>{r.current?.trigger()})}function ds(){let{t:e}=Z();return us(),a(`div`,{className:`space-y-3`,children:[d(Ge,{headingId:`library-vehicles`,title:e(`plates.vehicles`,`Vehicles`),icon:p,testId:`library-section-vehicles`,children:a(`div`,{className:`${m} space-y-3`,children:[d(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:e(`plates.enrolledVehicleIdentitiesUsedFor`,`Enrolled vehicle identities used for plate recognition. Open a vehicle to rename it or remove plate samples.`)}),d(ss,{})]})}),d(Ge,{headingId:`library-recent-plates`,title:e(`plates.recentRecognizedPlates`,`Recent recognized plates`),icon:ae,testId:`library-section-recent-plates`,children:a(`div`,{className:`${m} space-y-3`,children:[d(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:e(`plates.licensePlatesReadByThe`,`License plates read by the detection pipeline. Assign them to a vehicle, correct the OCR text, or delete.`)}),d(ns,{})]})})]})}function fs(e){return e.states.length===0?3:e.latched?0:e.verdict===`diverged`?1:e.verdict===`unknown`?2:4}function ps(e){let t=[e.divergedAt,e.restoredAt].filter(e=>typeof e==`number`);return t.length===0?null:Math.max(...t)}function ms(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=fs(e.monitor)-fs(t.monitor);if(n!==0)return n;let r=ps(e.monitor)??-1,i=ps(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})}e();var hs={alarm:`danger`,ok:`success`,unknown:`default`},gs={alarm:`Alarm`,ok:`OK`,unknown:`Unknown`};function _s(e,t){let n=ps(e);return n===null?`—`:X.t(`scenes.transitionAgo`,{duration:W(Math.max(0,t-n))})}function vs(e){return P(e.monitor).tone}function ys(e){let t=Number(e);return Number.isFinite(t)&&t>0?t:null}function bs(){let{t:e}=Z(),i=ct({isCamera:!0,projection:`slim`}),s=n(()=>(i.data??[]).map(e=>({deviceId:e.id,deviceName:e.name})).sort((e,t)=>e.deviceName.localeCompare(t.deviceName)),[i.data]),c=n(()=>s.map(e=>e.deviceId),[s]),l=Wt(c),u=n(()=>ms(s,l.results),[s,l.results]),f=Pe(u,{searchText:e=>[e.monitor.label,e.deviceName],facetValue:vs}),{state:p,openNew:m,openEdit:h,close:g}=Me(),[_,v]=r(null);t(()=>{if(p.mode===`new`){v(e=>e??c[0]??null);return}v(null)},[p.mode,c]);let y=p.mode===`edit`?ys(p.id):null,b=y===null?``:s.find(e=>e.deviceId===y)?.deviceName??`#${y}`,x=Date.now(),C=[{key:`label`,header:e(`scenes.scene`,`Scene`),sortValue:e=>e.monitor.label,render:e=>d(`span`,{className:`font-medium`,children:e.monitor.label})},{key:`camera`,header:e(`scenes.camera`,`Camera`),nowrap:!0,sortValue:e=>e.deviceName,render:e=>e.deviceName},{key:`state`,header:e(`scenes.state`,`State`),nowrap:!0,sortValue:e=>vs(e),render:e=>{let t=P(e.monitor);return d(et,{variant:hs[t.tone],children:t.text})}},{key:`status`,header:e(`scenes.whatItSays`,`What it says`),notSortableReason:`Status is a live sentence, not a comparable value`,render:e=>d(`span`,{className:`text-xs text-foreground-muted`,children:L(e.monitor,x)})},{key:`coverage`,header:e(`scenes.variants`,`Variants`),notSortableReason:`Coverage is a summary string`,render:e=>d(`span`,{className:`text-xs text-foreground-muted`,children:z(e.monitor)})},{key:`transition`,header:e(`scenes.lastChange`,`Last change`),align:`right`,nowrap:!0,sortValue:e=>ps(e.monitor)??0,render:e=>d(`span`,{className:`text-xs tabular-nums text-foreground-muted`,children:_s(e.monitor,x)})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:t=>d(Y,{variant:`ghost`,onClick:()=>h(String(t.deviceId)),children:e(`scenes.open`,`Open`)})}];return a(`section`,{className:`space-y-3`,children:[a(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between sm:gap-4`,children:[d(`p`,{className:`text-xs text-foreground-subtle`,children:e(`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.`)}),a(Y,{onClick:m,disabled:s.length===0,className:`shrink-0`,children:[d(S,{className:`mr-1 h-3.5 w-3.5`}),e(`scenes.newScene`,`New scene`)]})]}),l.unreachableCount>0?d(`p`,{className:`text-xs text-warning`,children:e(`scenes.unreachable`,{count:l.unreachableCount})}):null,(u.length>0||f.active)&&d(Le,{state:f.state,facets:f.facets,labels:{searchPlaceholder:`Search scenes…`,searchLabel:`Search scenes`,facetsLabel:`State`,clearLabel:`Clear`},facetLabel:e=>gs[e]??e,onSearch:f.setSearch,onToggleFacet:f.toggleFacet,onClear:f.clear}),d(Ie,{variant:`flat`,className:`p-0`,children:d(We,{columns:C,rows:f.rows,rowKey:e=>`${e.deviceId}:${e.monitor.id}`,minWidthPx:880,bordered:!1,maxBodyHeight:qe,emptyMessage:l.isLoading?e(`scenes.loadingScenes`,`Loading scenes…`):f.active?e(`scenes.nothingMatchesTheFilter`,`Nothing matches the filter`):e(`scenes.noScenesYetPressNew`,`No scenes yet. Press “New scene”, pick a camera, then draw a box around the thing you want watched.`)})}),p.mode===`new`?a(jt,{open:!0,onClose:g,title:e(`scenes.whichCamera`,`Which camera?`),icon:te,width:`sm`,testId:`scenes-camera-picker`,footer:d(Y,{onClick:()=>{_!==null&&h(String(_))},disabled:_===null,children:e(`scenes.continue`,`Continue`)}),children:[d(`p`,{className:`mb-3 text-xs text-foreground-subtle`,children:e(`scenes.aSceneLivesOnOne`,`A scene lives on one camera. Pick the one that can see the thing.`)}),d(ke,{value:_===null?``:String(_),onChange:e=>v(Number(e.target.value)),"aria-label":e(`scenes.camera`,`Camera`),options:s.map(e=>({value:String(e.deviceId),label:e.deviceName}))})]}):null,y===null?null:a(jt,{open:!0,onClose:g,title:e(`scenes.scenes`,`Scenes — {{editingName}}`,{editingName:b}),icon:te,width:`lg`,testId:`scenes-editor`,children:[d(`p`,{className:`mb-3 text-xs text-foreground-subtle`,children:e(`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.`)}),d(o,{fallback:d(`p`,{className:`text-xs text-foreground-muted`,children:e(`scenes.loadingTheEditor`,`Loading the editor…`)}),children:d(xt,{deviceId:y})})]})]})}function xs(){let{t:e}=Z(),t=Mt(`/library`,{t:e,isAdmin:!0})??{icon:de,title:e(`nav.library`,`Library`)};return d(Lt,{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:d(Hr,{})},{id:`vehicles`,label:e(`library.vehicles`,`Vehicles`),content:d(ds,{})},{id:`events`,label:e(`library.events`,`Events`),content:d(Bo,{}),ownedParams:[`section`]},{id:`scenes`,label:e(`library.scenes`,`Scenes`),content:d(bs,{})}]})}export{xs as LibraryPage};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{$ as e,B as t,G as n,J as r,S as i,b as a,o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{$t as c,Br as l,Fi as u,Fr as d,Hi as f,It as p,Mr as m,O as h,On as g,Pn as _,Qi as v,Qr as y,Rt as b,V as x,Vr as S,Vt as C,Xi as w,Zi as T,_i as E,cr as D,dt as O,er as k,fn as A,hr as j,ji as ee,k as M,ki as N,lr as P,nn as F,nr as I,pt as L,sn as R,ui as te,ut as z,wi as ne,yi as re,yn as B,z as V,zt as ie}from"./player-overlays-CZXV2ES3.js";import{t as ae}from"./boxes-DJvrVSZy.js";import{n as oe,r as se,t as ce}from"./speaker-Bw_8wVkA.js";import{t as le}from"./user-round-CYlbEszq.js";import{Xt as ue,er as de,nr as H}from"./client-CVIfL49c.js";import{$l as U,An as fe,Bn as W,Da as pe,Dn as G,Ea as me,En as he,Gi as ge,Hi as _e,Jl as K,Ma as ve,Na as ye,Nt as be,Oa as xe,Pa as Se,Pt as Ce,Ta as we,Tn as Te,Ui as Ee,Ut as q,W as De,Wi as Oe,Zn as ke,_a as Ae,an as je,ar as Me,ba as Ne,d as Pe,eu as Fe,ha as Ie,ja as Le,jn as Re,kn as ze,on as Be,tr as Ve,tu as He,va as Ue,ya as We,za as Ge}from"./src-DOs8Kg5s.js";import{t as J}from"./i18n-CmGpgquB.js";import{t as Y}from"./useTranslation-D3Is_4B6.js";import{Q as Ke,X,et as qe,x as Je}from"./index-DkNBNJNl.js";import{t as Ye}from"./AdminSectionedPage-C6laWV2D.js";import{a as Xe,n as Ze,r as Qe}from"./linked-devices-model-f_SAvOZs.js";e();var $e={camera:ne,hub:oe,container:ae,light:P,siren:F,switch:ie,sensor:v,thermostat:C,climate:T,button:te,"event-emitter":z,update:se,notifier:u,script:A,automation:L,lock:I,cover:ee,valve:S,humidifier:l,"water-heater":m,fan:d,"media-player":ce,"alarm-panel":R,control:c,presence:le,weather:y,vacuum:N,"lawn-mower":b,image:j,smoke:w};function Z({type:e,className:t}){return s($e[e]??te,{"aria-hidden":`true`,className:t??`h-3.5 w-3.5 shrink-0 text-foreground-subtle`})}function et({online:e,deviceName:t}){return s(`span`,{className:e?`inline-block h-1.5 w-1.5 shrink-0 rounded-full bg-success`:`inline-block h-1.5 w-1.5 shrink-0 rounded-full border border-foreground-subtle`,role:`img`,"aria-label":J.t(`locations.deviceGlyphs.aria`,{name:t,state:e?J.t(`common.online`):J.t(`common.offline`)}),title:e?J.t(`common.online`):J.t(`common.offline`)})}function tt({open:e,title:n,items:a,listState:o,lockedIds:c,lockedNote:l,suggestions:u=null,busy:d=!1,onConfirm:f,onClose:p}){let{t:m}=Y(),[h,g]=r([]);t(()=>{e||g([])},[e]);let _=new Map(a.map(e=>[e.id,e.name])),v=(u?.ids??[]).filter(e=>_.has(e)&&!c.includes(e)),y=e=>g(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]);return s(Te,{open:e,onOpenChange:e=>e?void 0:p(),children:i(G,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":n,children:[s(fe,{children:s(Re,{children:n})}),i(he,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:[e&&u!==null&&v.length>0&&i(`section`,{"aria-label":u.heading,className:`flex flex-col gap-1`,children:[s(`h3`,{className:`text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:u.heading}),s(`div`,{className:`flex flex-wrap gap-1`,children:v.map(e=>s(`button`,{type:`button`,"aria-pressed":h.includes(e),className:`inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${h.includes(e)?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:bg-surface-hover`}`,onClick:()=>y(e),children:_.get(e)},e))})]}),e&&s(Pe,{devices:a,listState:o,value:h,onChange:e=>g(e),noun:`device`,emptyLabel:m(`locations.addDialog.nonePicked`),showAll:!0,lockedIds:c,lockedNote:l,testId:`quick-add-picker`})]}),i(ze,{children:[s(W,{variant:`ghost`,onClick:p,children:m(`locations.addDialog.cancel`)}),s(W,{disabled:h.length===0||d,onClick:()=>f(h),children:m(`locations.addDialog.confirm`,{count:h.length})})]})]})})}e();function nt({room:e,cameras:t,fleet:r}){let{t:i}=Y(),a=n(()=>new Map(r.map(e=>[e.id,e])),[r]);return e===null?s(`p`,{className:`text-xs text-foreground-subtle`,children:i(`locations.links.noRoom`)}):s(`div`,{className:`flex flex-col gap-3`,"data-testid":`camera-links-section`,children:t.length===0?s(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`camera-links-empty`,children:i(`locations.links.noCameras`,{room:e})}):t.map(e=>s(it,{camera:e,byId:a},e.id))})}function rt(e){return{id:e.deviceId,name:e.parentName===null?e.name:`${e.parentName} · ${e.name}`,type:e.type,location:e.location}}function it({camera:e,byId:t}){let{t:n}=Y(),a=o(),c=Ke(),[l,u]=r(!1),[d,f]=r(null),p=Ee({deviceId:e.id}),m=Qe({status:p.status,data:p.data,error:p.error===null||p.error===void 0?null:p.error}),g=Oe(),_=m.kind===`present`?m:null,v=_e({deviceId:e.id,slotRef:_?.slot.slotRef??``},{enabled:l&&_!==null}),y=_===null?[]:Ze(_.slot,_.value),b=y.map(e=>e.deviceId),x=(v.data?.candidates??[]).map(rt),S=new Set(x.map(e=>e.id)),C=b.filter(e=>!S.has(e)).map(e=>{let n=t.get(e);return{id:e,name:n?.name??`#${String(e)}`,...n===void 0?{}:{type:n.type,location:n.location}}}),w=[...x,...C],T=(v.data?.candidates??[]).filter(e=>e.suggested).map(e=>e.deviceId),E=async t=>{if(_!==null){f(null);try{await g.mutateAsync({deviceId:e.id,slotRef:_.slot.slotRef,value:Xe(_.value,t)}),await p.refetch(),await a.invalidateQueries({queryKey:[[`deviceManager`]]}),u(!1)}catch(e){f(e instanceof Error?e.message:String(e))}}},O=[{key:`device`,header:n(`locations.columns.device`),notSortableReason:n(`locations.columns.noSort`),render:e=>{let r=t.get(e.deviceId),a=e.name??r?.name??`#${String(e.deviceId)}`;return i(`span`,{className:`flex items-center gap-1.5`,children:[r!==void 0&&s(Z,{type:r.type}),s(X,{to:`/devices/${String(e.deviceId)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:a}),e.implied&&s(`span`,{className:`text-[10px] text-foreground-subtle`,children:n(`locations.links.implied`)})]})}},{key:`type`,header:n(`locations.columns.type`),notSortableReason:n(`locations.columns.noSort`),render:e=>s(`span`,{className:`text-xs text-foreground-muted`,children:t.get(e.deviceId)?.type??`—`})},{key:`status`,header:n(`locations.columns.status`),notSortableReason:n(`locations.columns.noSort`),render:e=>{let r=t.get(e.deviceId);return r===void 0?s(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):i(`span`,{className:`flex items-center gap-1.5`,children:[s(et,{online:r.online,deviceName:r.name}),s(`span`,{className:`text-xs text-foreground-muted`,children:r.online?n(`common.online`):n(`common.offline`)})]})}}];return i(`section`,{className:`min-w-0 ${h}`,"data-testid":`camera-links-${String(e.id)}`,children:[i(`header`,{className:`${M} flex min-h-9 items-center gap-1.5`,children:[s(Z,{type:e.type}),s(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:e.name}),i(W,{variant:`ghost`,size:`sm`,onClick:()=>c(Je(e.id)),children:[s(D,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),n(`locations.links.edit`)]}),s(W,{variant:`outline`,size:`sm`,disabled:_===null,onClick:()=>u(!0),"aria-label":n(`locations.links.addNamed`,{camera:e.name}),children:n(`locations.room.add`)})]}),m.kind===`pending`&&s(`p`,{role:`status`,className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:n(`locations.links.loading`)}),m.kind===`unknown`&&s(`p`,{role:`alert`,className:`px-3 py-3 text-xs text-warning sm:px-4`,children:n(`locations.links.unreadable`,{reason:m.reason})}),m.kind===`absent`&&s(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:n(`locations.links.unsupported`)}),d!==null&&s(`p`,{role:`alert`,className:`px-3 pt-2 text-xs text-danger break-words sm:px-4`,children:d}),_!==null&&(y.length===0?s(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:n(`locations.links.none`)}):s(q,{columns:O,rows:y,rowKey:e=>String(e.deviceId),bordered:!1,minWidthPx:360})),s(tt,{open:l,title:n(`locations.links.pickTitle`,{camera:e.name}),items:w,listState:v.status===`error`?`failed`:v.data===void 0?`pending`:`answered`,lockedIds:b,lockedNote:n(`locations.links.alreadyLinked`),suggestions:e.location===null?null:{heading:n(`locations.links.suggested`,{room:e.location}),ids:T},busy:g.isPending,onConfirm:e=>void E(e),onClose:()=>u(!1)})]})}e();function at({name:e,description:n,busy:a,onSave:o}){let{t:c}=Y(),[l,u]=r(n??``);return t(()=>{u(n??``)},[n]),i(`div`,{className:`border-t border-border px-3 py-2 sm:px-4`,children:[s(Be,{htmlFor:`location-description-${e}`,className:`block`,children:c(`locations.locationDescriptionField.whatIsThere`,`What is there`)}),s(`textarea`,{id:`location-description-${e}`,value:l,onChange:e=>u(e.target.value),onBlur:()=>{let e=l.trim();e!==(n??``)&&o(e.length===0?null:e)},disabled:a,rows:2,maxLength:400,placeholder:c(`locations.locationDescriptionField.surfacesBoundariesWhatIsNormally`,`Surfaces, boundaries, what is normally parked or stored here.`),className:`mt-1 w-full resize-y rounded-md border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-inset focus:ring-primary disabled:cursor-not-allowed disabled:opacity-50`}),s(`p`,{className:`mt-1 ${V}`,children:c(`locations.locationDescriptionField.givenToTheAiWith`,`Given to the AI with the pictures, so it knows what it is looking at. Describe the PLACE, not what happens in it — events change, the ground does not.`)})]})}function ot(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0||n.description.length===0?null:n.description}var Q=` none`;function st({name:e,zones:t,zoneKey:n,busy:r,onChange:a}){let{t:o}=Y();if(t.length===0)return null;let c=[{value:Q,label:o(`locations.locationZoneField.none`,`— none —`)},...t.map(e=>({value:e.zoneKey,label:e.label}))];return i(`div`,{className:`flex items-center gap-2 border-t border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:[s(Be,{htmlFor:`location-zone-${e}`,children:o(`locations.locationZoneField.zone`,`Zone`)}),s(K,{id:`location-zone-${e}`,value:n??Q,disabled:r,onChange:e=>{let n=e.target.value;if(n===Q){a(null);return}let r=t.find(e=>e.zoneKey===n);r!==void 0&&a(r.label)},options:c})]})}function ct(e,t){return e.find(e=>e.locationKeys.includes(t))?.zoneKey??null}function lt({name:e,icon:t,busy:n,onPick:r}){return s(He,{value:t,onPick:r,fallbackGlyph:k,clearGlyph:f,labels:{trigger:`Change the icon of ${e}`,panel:`Icon for ${e}`,searchPlaceholder:`Search icons`,clear:`No icon`,noMatches:`No icon matches that`},disabled:n})}function ut(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0?null:H(n.icon)??`map-pin`}function $(e){if(e==null)return null;let t=e.trim();return t.length===0?null:t.toLowerCase()}function dt(e,t){let n=$(t);return n===null?[]:e.filter(e=>$(e.location)===n)}function ft(e,t){let n=dt(e,t),r=new Set(n.map(e=>e.id));return n.filter(e=>e.parentDeviceId===null||!r.has(e.parentDeviceId))}function pt(e,t){let n=$(e.location);return n===null||new Set(t.map(e=>$(e))).has(n)?null:e.location?.trim()??null}function mt(e,t){let n=$(e.location);return n!==null&&t.has(n)}function ht(e,t){let n=new Set(t.map(e=>$(e))),r=new Set(e.filter(e=>mt(e,n)).map(e=>e.id));return e.filter(e=>!(mt(e,n)||e.parentDeviceId!==null&&r.has(e.parentDeviceId)))}function gt(e,t){return ht(e,t).filter(e=>e.parentDeviceId===null)}function _t(e,t){let n=new Map;for(let t of e){if(t.parentDeviceId===null)continue;let e=n.get(t.parentDeviceId);e?e.push(t):n.set(t.parentDeviceId,[t])}let r=[],i=new Set([t]),a=[t];for(;a.length>0;){let e=[];for(let t of a)for(let a of n.get(t)??[])i.has(a.id)||(i.add(a.id),r.push(a),e.push(a.id));a=e}return r}function vt(e,t){return _t(e,t).length}function yt(e,t){return e.filter(e=>!e.isCamera&&e.parentDeviceId===t)}function bt(e,t){return t.map(t=>({name:t,members:ft(e,t)}))}function xt(e){return`${e.kind}:${String(e.device.id)}`}function St(e,t,n){return e.flatMap(e=>{let r=yt(t,e.id),i=n.has(e.id),a={kind:`member`,device:e,accessories:r,open:i};return!i||r.length===0?[a]:[a,...r.map(t=>({kind:`accessory`,device:t,parent:e}))]})}e();function Ct({name:e,members:t,devices:o,busy:c,icon:l,description:u,onRename:d,onDelete:f,onRebuildLinks:m,onAddDevices:g,onPickIcon:v,onSaveDescription:y,zones:b,zoneKey:x,onChangeZone:S}){let{t:C}=Y(),[w,T]=r(!1),[E,D]=r(e),k=be(t,n(()=>({searchText:e=>[e.name,...yt(o,e.id).map(e=>e.name)],facetValue:e=>e.type}),[o])),[A,j]=r(()=>new Set),ee=e=>j(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),N=n(()=>St(k.rows,o,A),[k.rows,o,A]),P=[{key:`name`,header:C(`locations.columns.device`),notSortableReason:C(`locations.columns.noSort`),render:e=>e.kind===`member`?s(wt,{row:e,onToggle:()=>ee(e.device.id)}):s(Tt,{row:e})},{key:`type`,header:C(`locations.columns.type`),notSortableReason:C(`locations.columns.noSort`),render:e=>s(`span`,{className:`text-xs text-foreground-muted`,children:e.device.type})},{key:`status`,header:C(`locations.columns.status`),notSortableReason:C(`locations.columns.noSort`),render:e=>i(`span`,{className:`flex items-center gap-1.5`,children:[s(et,{online:e.device.online,deviceName:e.device.name}),s(`span`,{className:`text-xs text-foreground-muted`,children:e.device.online?C(`common.online`):C(`common.offline`)})]})}],F=()=>{D(e),T(!1)},I=async()=>{let t=E.trim();if(t.length===0||t===e){F();return}await d(t),T(!1)},L=[{id:`rename`,label:C(`locations.locationCard.rename`,`Rename`),icon:_,disabled:c,onClick:()=>{D(e),T(!0)}},{id:`rebuild-links`,label:C(`locations.locationCard.rebuildLinkedDevices`,`Rebuild linked devices`),icon:B,separatorBefore:!0,disabled:c,onClick:()=>void m()},{id:`delete`,label:C(`common.delete`,`Delete`),icon:p,danger:!0,separatorBefore:!0,disabled:c,onClick:()=>void f()}];return i(`section`,{className:`min-w-0 ${h}`,children:[i(`header`,{className:`${M} flex min-h-9 items-center gap-1.5`,children:[s(lt,{name:e,icon:l,busy:c,onPick:v}),w?i(a,{children:[s(U,{value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`&&I(),e.key===`Escape`&&F()},"aria-label":C(`locations.locationCard.rename2`,`Rename {{name}}`,{name:e}),className:`min-w-0 flex-1`,autoFocus:!0}),s(W,{type:`button`,size:`sm`,onClick:()=>void I(),children:C(`common.save`,`Save`)}),s(Fe,{type:`button`,variant:`ghost`,icon:O,onClick:F,"aria-label":C(`locations.locationCard.cancelRename`,`Cancel rename`)})]}):i(a,{children:[s(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:e}),s(W,{type:`button`,variant:`outline`,size:`sm`,disabled:c,onClick:g,"aria-label":C(`locations.room.addTo`,{room:e}),children:C(`locations.room.add`)}),s(De,{items:L,title:C(`locations.locationCard.actionsFor`,`Actions for {{name}}`,{name:e}),triggerClassName:`p-1`})]})]}),s(st,{name:e,zones:b,zoneKey:x,busy:c,onChange:S}),s(at,{name:e,description:u,busy:c,onSave:y}),t.length>0&&s(`div`,{className:`border-b border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:s(Ce,{state:k.state,facets:k.facets,labels:{searchPlaceholder:C(`locations.filter.searchPlaceholder`),searchLabel:C(`locations.room.searchLabel`,{room:e}),facetsLabel:C(`locations.filter.typesLabel`),clearLabel:C(`locations.filter.clear`)},onSearch:k.setSearch,onToggleFacet:k.toggleFacet,onClear:k.clear})}),t.length===0?s(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:C(`locations.locationCard.nothingHereYetAssignA`,`Nothing here yet — assign a device from the table below.`)}):s(q,{columns:P,rows:N,rowKey:xt,bordered:!1,minWidthPx:360,emptyMessage:C(`locations.filter.noMatch`)})]})}function wt({row:e,onToggle:t}){let{t:n}=Y(),{device:r,accessories:a,open:o}=e,c=o?re:E;return i(`span`,{className:`flex items-center gap-1.5`,children:[a.length>0?i(W,{type:`button`,variant:`ghost`,onClick:t,"aria-expanded":o,"aria-label":n(o?`locations.locationCard.collapseAccessories`:`locations.locationCard.expandAccessories`,{count:a.length,name:r.name}),className:`h-auto shrink-0 gap-0.5 p-0.5 text-foreground-subtle hover:text-foreground`,children:[s(c,{className:`h-3 w-3`}),s(`span`,{className:`text-[10px] tabular-nums`,children:a.length})]}):s(`span`,{"aria-hidden":`true`,className:`w-[1.35rem] shrink-0`}),s(Z,{type:r.type}),s(X,{to:`/devices/${String(r.id)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:r.name})]})}function Tt({row:e}){let{device:t}=e;return i(`span`,{className:`flex items-center gap-1.5 pl-6`,children:[s(`span`,{"aria-hidden":`true`,className:`text-[10px] text-foreground-subtle`,children:`└`}),s(Z,{type:t.type,className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(X,{to:`/devices/${String(t.id)}`,className:`min-w-0 truncate text-xs text-foreground-muted hover:underline`,children:t.name})]})}e();function Et({zones:e,busy:t,onRename:n,onDelete:i,onPickIcon:a}){let{t:o}=Y(),[c,l]=r(null),[u,d]=r(``),f=async e=>{let t=u.trim();l(null),!(t.length===0||t===e)&&await n(e,t)};return s(q,{columns:[{key:`icon`,header:o(`locations.siteZonesPanel.icon`,`Icon`),width:`w-12`,notSortableReason:`An icon has no order`,render:e=>s(lt,{name:e.label,icon:e.icon,busy:t,onPick:t=>a(e.label,t)})},{key:`name`,header:o(`locations.siteZonesPanel.zone`,`Zone`),sortValue:e=>e.label.toLowerCase(),render:e=>c===e.label?s(U,{value:u,onChange:e=>d(e.target.value),onKeyDown:t=>{t.key===`Enter`&&f(e.label),t.key===`Escape`&&l(null)},onBlur:()=>void f(e.label),"aria-label":o(`locations.siteZonesPanel.rename`,`Rename {{label}}`,{label:e.label}),autoFocus:!0}):s(W,{type:`button`,variant:`ghost`,size:`sm`,className:`px-0`,onClick:()=>{d(e.label),l(e.label)},disabled:t,title:o(`locations.siteZonesPanel.renameTheZone`,`Rename the zone`),children:e.label})},{key:`rooms`,header:o(`locations.siteZonesPanel.rooms`,`Rooms`),align:`right`,sortValue:e=>e.locationKeys.length,render:e=>s(`span`,{className:`tabular-nums text-foreground-subtle`,children:e.locationKeys.length===0?o(`common.empty`):o(`common.rooms`,{count:e.locationKeys.length})})},{key:`actions`,header:o(`locations.siteZonesPanel.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order`,render:e=>s(W,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void i(e.label),disabled:t,"aria-label":o(`locations.siteZonesPanel.delete`,`Delete {{label}}`,{label:e.label}),title:o(`locations.siteZonesPanel.deleteTheZoneTheRooms`,`Delete the zone — the rooms in it are kept`),children:s(p,{className:`h-3.5 w-3.5`})})}],rows:e,rowKey:e=>e.zoneKey,emptyMessage:o(`locations.siteZonesPanel.noZonesYetAZone`,`No zones yet. A zone groups rooms — “Zona notte” for the bedrooms — and shows up before them in the app’s camera filter.`)})}e();function Dt({busy:e,onCreate:t}){let{t:n}=Y(),[a,o]=r(!1),[c,l]=r(``),u=()=>{l(``),o(!1)},d=async()=>{let e=c.trim();e.length!==0&&(await t(e),u())};return a?i(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),d()},children:[s(U,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&u()},placeholder:n(`locations.newLocationButton.ingressoSaloneCucina`,`Ingresso, Salone, Cucina…`),"aria-label":n(`locations.newLocationButton.newLocationName`,`New location name`),className:`min-w-[12rem] flex-1`,autoFocus:!0}),i(W,{size:`sm`,type:`submit`,disabled:c.trim().length===0||e,children:[s(g,{className:`h-3.5 w-3.5`}),n(`common.add`,`Add`)]}),s(W,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":n(`locations.newLocationButton.cancelNewLocation`,`Cancel new location`),children:s(O,{className:`h-3.5 w-3.5`})})]}):i(W,{size:`sm`,type:`button`,onClick:()=>o(!0),"data-testid":`new-location-button`,children:[s(g,{className:`h-3.5 w-3.5`}),n(`locations.newLocationButton.newLocation`,`New location`)]})}e();function Ot({busy:e,onCreate:t}){let{t:n}=Y(),[a,o]=r(!1),[c,l]=r(``),u=()=>{l(``),o(!1)},d=async()=>{let e=c.trim();e.length!==0&&(await t(e),u())};return a?i(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),d()},children:[s(U,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&u()},placeholder:n(`locations.newZoneButton.zonaGiornoZonaNotte`,`Zona giorno, Zona notte…`),"aria-label":n(`locations.newZoneButton.newZoneName`,`New zone name`),className:`min-w-[12rem] flex-1`,autoFocus:!0}),i(W,{size:`sm`,type:`submit`,disabled:c.trim().length===0||e,children:[s(g,{className:`h-3.5 w-3.5`}),n(`common.add`,`Add`)]}),s(W,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":n(`locations.newZoneButton.cancelNewZone`,`Cancel new zone`),children:s(O,{className:`h-3.5 w-3.5`})})]}):i(W,{size:`sm`,type:`button`,onClick:()=>o(!0),"data-testid":`new-zone-button`,children:[s(g,{className:`h-3.5 w-3.5`}),n(`locations.newZoneButton.newZone`,`New zone`)]})}e();function kt(e,t,n,r){let i=e.map(e=>({value:e.name,label:`${e.name} · ${String(e.count)}`}));return t===void 0?i:[...i,{value:n,label:`${r} · ${String(t)}`}]}function At({rooms:e,unassignedCount:t,value:r,unassignedValue:i,onChange:a}){let{t:o}=Y(),c=n(()=>kt(e,t,i,o(`locations.roomPicker.unassigned`)),[e,t,i,o]);return s(`div`,{className:`max-w-sm`,"data-testid":`room-select`,children:s(Ve,{mode:`single`,singleDisplay:`field`,label:o(`locations.roomPicker.label`),placeholder:o(`locations.roomPicker.placeholder`),options:c,value:r,onChange:a,searchable:!0,testId:`room-select-control`,optionTestIdPrefix:`room-option`})})}e();var jt={searchText:e=>[e.name],facetValue:e=>e.type};function Mt({rows:e,fleet:t,locations:a,busy:o,emptyMessage:c,onAssign:l}){let{t:u}=Y(),[d,f]=r([]),[p,m]=r(``),h=be(e,jt),g=h.rows,_=n(()=>g.map(e=>e.id),[g]),v=n(()=>d.filter(e=>_.includes(e)),[d,_]),y=g.length>0&&v.length===g.length,b=n(()=>{let n=new Map;for(let r of e)n.set(r.id,vt(t,r.id));return n},[e,t]),S=v.reduce((e,t)=>e+(b.get(t)??0),0),C=e=>f(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),w=()=>f(y?[]:_),T=()=>{p.length===0||v.length===0||(l(v,p),f([]),m(``))},E=a.map(e=>({value:e,label:e})),D=[{key:`select`,width:`w-8`,headerRender:()=>s(je,{checked:y,onChange:w,"aria-label":y?u(`locations.unassignedTable.clearSelection`,`Clear selection`):u(`locations.unassignedTable.selectAllUnassignedDevices`,`Select all unassigned devices`)}),render:e=>s(je,{checked:v.includes(e.id),onChange:()=>C(e.id),"aria-label":u(`locations.unassignedTable.select`,`Select {{name}}`,{name:e.name})})},{key:`name`,header:u(`locations.unassignedTable.device`,`Device`),sortValue:e=>e.name.toLowerCase(),render:e=>{let t=pt(e,a);return i(`span`,{className:`flex items-center gap-1.5`,children:[s(Z,{type:e.type}),s(X,{to:`/devices/${String(e.id)}`,className:`truncate text-xs text-foreground hover:underline`,children:e.name}),t!==null&&s(Me,{variant:`warning`,children:u(`locations.unassignedTable.unknownRoom`,{room:t})})]})}},{key:`type`,header:u(`locations.unassignedTable.type`,`Type`),sortValue:e=>e.type,render:e=>s(`span`,{className:`text-xs text-foreground-muted`,children:e.type})},{key:`status`,header:u(`locations.unassignedTable.status`,`Status`),sortValue:e=>+!!e.online,render:e=>i(`span`,{className:`flex items-center gap-1.5`,children:[s(et,{online:e.online,deviceName:e.name}),s(`span`,{className:`text-xs text-foreground-muted`,children:e.online?u(`common.online`):u(`common.offline`)})]})},{key:`followers`,header:u(`locations.unassignedTable.accessoriesInTowCount`,`Accessories in tow`),align:`right`,sortValue:e=>b.get(e.id)??0,render:e=>s(`span`,{className:`tabular-nums text-xs text-foreground-muted`,children:b.get(e.id)??0})},{key:`assign`,header:u(`locations.unassignedTable.assignTo`,`Assign to`),align:`right`,notSortableReason:`This column is a control, not a value.`,render:e=>s(K,{"aria-label":u(`locations.unassignedTable.locationFor`,`Location for {{name}}`,{name:e.name}),value:``,disabled:o||a.length===0,onChange:t=>{let n=t.target.value;n.length!==0&&l([e.id],n)},className:`max-w-[11rem]`,options:[{value:``,label:`—`},...E]})}];return i(`section`,{className:`space-y-2`,children:[i(`header`,{className:`flex flex-wrap items-baseline gap-2`,children:[s(`h2`,{className:x,children:u(`locations.unassignedTable.notInARoom`,`Not in a room`)}),s(`p`,{className:V,children:u(`locations.unassignedTable.topLevelDevicesOnlyAccessories`,`Top-level devices only — accessories move with their parent.`)})]}),e.length>0&&s(Ce,{state:h.state,facets:h.facets,labels:{searchPlaceholder:u(`locations.filter.searchPlaceholder`),searchLabel:u(`locations.unassigned.searchLabel`),facetsLabel:u(`locations.filter.typesLabel`),clearLabel:u(`locations.filter.clear`)},onSearch:h.setSearch,onToggleFacet:h.toggleFacet,onClear:h.clear}),v.length>0&&i(`div`,{role:`group`,"aria-label":u(`locations.unassignedTable.bulkAssignment`,`Bulk assignment`),className:`flex flex-wrap items-center gap-2 rounded border border-primary/40 bg-primary/5 px-2 py-1.5`,children:[i(`span`,{className:`text-xs text-foreground`,children:[u(`locations.unassignedTable.selected`,{count:v.length}),S>0&&` · ${u(`locations.unassignedTable.accessoriesInTowCount`,{count:S})}`]}),s(K,{"aria-label":u(`locations.unassignedTable.assignSelectedDevicesTo`,`Assign selected devices to`),value:p,onChange:e=>m(e.target.value),className:`w-auto min-w-[10rem]`,options:[{value:``,label:u(`locations.unassignedTable.assignTo2`,`Assign to…`)},...E]}),s(W,{type:`button`,size:`sm`,onClick:T,disabled:o||p.length===0,children:u(`locations.unassignedTable.assign`,`Assign`)}),s(W,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>f([]),children:u(`locations.unassignedTable.clear`,`Clear`)})]}),s(q,{columns:D,rows:g,rowKey:e=>e.id,minWidthPx:720,emptyMessage:h.active?u(`locations.filter.noMatch`):c})]})}function Nt(e){return{id:e.id,parentDeviceId:e.parentDeviceId,location:e.location,type:e.type,stableId:e.stableId??``,...e.primaryChildEntityId===void 0?{}:{primaryChildEntityId:e.primaryChildEntityId},...e.role!==void 0&&e.role!==null?{role:e.role}:{},name:e.name}}function Pt(e,t){let n=t.map(Nt),r=[];for(let i of t)i.isCamera&&i.location===e&&r.push({deviceId:i.id,name:i.name,ids:ue({selfId:i.id,selfLocation:i.location,candidates:n})});return{entries:r}}var Ft=`device-manager:linked-devices`;function It(e){return{deviceId:e.deviceId,slotRef:Ft,value:{slot:`linked-devices`,deviceIds:[...e.ids]}}}e();var Lt=`__unassigned__`;function Rt(){let{t:e}=Y(),t=o(),a=ke(),{data:c,isLoading:l}=We(),{data:u}=Ue(),{data:d}=Ae(),{data:f}=Ne(),{data:p,isLoading:m}=Ie({projection:`slim`}),h=()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]}),t.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),t.invalidateQueries({queryKey:[[`deviceManager`,`listLocationIcons`]]}),t.invalidateQueries({queryKey:[[`deviceManager`,`listLocationDescriptions`]]}),t.invalidateQueries({queryKey:[[`deviceManager`,`listSiteZones`]]})},g=ge({onSuccess:h}),_=we({onSuccess:h}),v=Le({onSuccess:h}),y=pe({onSuccess:h}),b=ye({onSuccess:h}),x=ve({onSuccess:h}),S=Ge({onSuccess:h}),C=me({onSuccess:h}),w=xe({onSuccess:h}),T=Se({onSuccess:h}),E=Oe(),D=n(()=>(p??[]).map(e=>({id:e.id,name:e.name,location:e.location??null,type:String(e.type),isCamera:e.isCamera,parentDeviceId:e.parentDeviceId,online:e.online,role:e.role??null,stableId:e.stableId,primaryChildEntityId:e.primaryChildEntityId??null})),[p]),O=c??[],A=n(()=>bt(D,O),[D,O]),[j,ee]=qe(),M=j.get(`tab`),N=M===`zones`||M===`camera-links`?M:`locations`,P=j.get(`room`),F=n(()=>gt(D,O),[D,O]),I=P===Lt,L=I?null:P!==null&&A.some(e=>e.name===P)?P:A[0]?.name??null,R=L===null?null:A.find(e=>e.name===L)??null,te=I?Lt:L??`__unassigned__`,z=L??A[0]?.name??null,ne=n(()=>A.map(e=>({name:e.name,count:e.members.length})),[A]),re=e=>{ee(t=>{let n=new URLSearchParams(t);return n.set(`room`,e),n},{replace:!0})},B=l||m,V=v.isPending||_.isPending||g.isPending||b.isPending,ie=async e=>{await g.mutateAsync({name:e})},ae=async(e,t)=>{let n=t.trim();n.length===0||n===e||await y.mutateAsync({from:e,to:n})},oe=async t=>{let n=Pt(t,D);if(n.entries.length===0){await a({title:e(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:e(`locations.noCameraIsAssignedTo`,`No camera is assigned to “{{room}}”.`,{room:t}),confirmLabel:`OK`});return}let r=n.entries.map(t=>e(`locations.rebuildEntry`,{name:t.name,count:t.ids.length})).join(`
|
|
2
|
-
`);if(!await a({title:e(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:e(`locations.replaceTheLinkedDeviceList`,`Replace the linked-device list of every camera in “{{room}}” with what the room contains? {{lines}} Anything linked by hand that is not in this room is lost.`,{room:t,lines:r}),confirmLabel:e(`locations.rebuild`,`Rebuild`),variant:`danger`}))return;let i=[];for(let e of n.entries)try{await E.mutateAsync(It(e))}catch(t){i.push(`• ${e.name}: ${t instanceof Error?t.message:String(t)}`)}h(),i.length>0&&await a({title:e(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:e(`locations.notRebuilt`,`Not rebuilt: {{value1}}`,{value1:i.join(`
|
|
3
|
-
`)}),confirmLabel:`OK`})},se=async(t,n)=>{let r=n>0?` ${String(n)} device(s) will become unassigned.`:``;await a({title:e(`locations.deleteLocation`,`Delete location`),message:e(`locations.deleteTheLocation`,`Delete the location “{{name}}”?{{extra}}`,{name:t,extra:r}),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&await _.mutateAsync({name:t,cascade:!0})},ce=async t=>{await a({title:e(`locations.deleteZone`,`Delete zone`),message:e(`locations.deleteTheZoneTheRooms`,`Delete the zone “{{name}}”? The rooms in it are kept.`,{name:t}),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&await C.mutateAsync({name:t})},le=async(e,t)=>{await b.mutateAsync({location:e,icon:t})},ue=async(e,t)=>{await x.mutateAsync({location:e,description:t})},H=f??[],U=async(e,t)=>{await T.mutateAsync({location:e,zone:t})},fe=(e,t)=>{for(let n of e)v.mutate({deviceId:n,location:t})},[W,G]=r(null),he=n(()=>D.filter(e=>e.parentDeviceId===null).map(e=>({id:e.id,name:e.name,type:e.type,location:e.location})),[D]),_e=s(At,{rooms:ne,...N===`locations`?{unassignedCount:F.length}:{},value:N===`locations`?te:z??``,unassignedValue:Lt,onChange:re}),K=i(`div`,{className:`flex flex-col gap-3`,"data-testid":`locations-section`,children:[B&&s(`p`,{className:`text-xs text-foreground-subtle`,children:e(`locations.loadingLocationsAndDevices`,`Loading locations and devices…`)}),_e,I||R===null?s(Mt,{rows:F,fleet:D,locations:O,busy:V,emptyMessage:B?e(`common.loading`,`Loading…`):e(`locations.everyTopLevelDeviceHas`,`Every top-level device has a room.`),onAssign:fe}):s(Ct,{name:R.name,members:R.members,devices:D,busy:V,icon:ut(u,de(R.name)),onPickIcon:e=>le(R.name,e),description:ot(d,de(R.name)),onSaveDescription:e=>ue(R.name,e),zones:H,zoneKey:ct(H,de(R.name)),onChangeZone:e=>U(R.name,e),onRename:e=>ae(R.name,e),onDelete:()=>se(R.name,dt(D,R.name).length),onRebuildLinks:()=>oe(R.name),onAddDevices:()=>G(R.name)},R.name),O.length===0&&!B&&s(`p`,{className:`text-xs text-foreground-subtle`,children:e(`locations.noLocationsYetAddIngresso`,`No locations yet. Add Ingresso, Salone, Cucina…`)}),s(tt,{open:W!==null,title:e(`locations.room.addDialogTitle`,{room:W??``}),items:he,listState:m?`pending`:`answered`,lockedIds:W===null?[]:(A.find(e=>e.name===W)?.members??[]).map(e=>e.id),lockedNote:e(`locations.room.alreadyHere`),suggestions:{heading:e(`locations.room.suggestedUnassigned`),ids:F.map(e=>e.id)},busy:v.isPending,onConfirm:e=>{W!==null&&fe(e,W),G(null)},onClose:()=>G(null)})]}),be=i(`div`,{className:`flex flex-col gap-3`,"data-testid":`camera-links-tab`,children:[_e,s(nt,{room:z,cameras:z===null?[]:dt(D,z).filter(e=>e.isCamera),fleet:D})]});return s(Ye,{icon:k,title:e(`locations.locations`,`Locations`),subtitle:e(`locations.roomsAndAreasOfThe`,`Rooms and areas of the site. Assign any device here — storage disks are under Data → Storage.`),defaultSection:`locations`,sectionsLabel:`Locations sections`,actions:N===`zones`?s(Ot,{busy:S.isPending,onCreate:e=>S.mutateAsync({name:e})}):s(Dt,{busy:g.isPending,onCreate:ie}),sections:[{id:`locations`,label:e(`locations.locations`,`Locations`),content:K},{id:`camera-links`,label:e(`locations.cameraLinks`,`Camera links`),content:be},{id:`zones`,label:e(`locations.zones`,`Zones`),content:s(Et,{zones:H,busy:V,onRename:(e,t)=>w.mutateAsync({from:e,to:t}),onDelete:ce,onPickIcon:(e,t)=>S.mutateAsync({name:e,icon:t})})}]})}export{Rt as LocationsPage};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./browser-BHo8W_uH.js","./rolldown-runtime-Cyuzqnbw.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{t}from"./vite-preload-helper-kNaey6uv.js";import{$ as n,B as r,G as i,J as a,S as o,a as s,b as c,q as l,t 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-CEHpkaJP.js";import{Hi as f,Ir as p,It as m,Nt as h,Pn as g,Q as _,Qt as v,Yr as y,ar as b,cr as x,fi as S,ia as C,nr as w,ot as T,pi as E,pr as D}from"./player-overlays-CZXV2ES3.js";import{o as O}from"./video-CEzO-5-D.js";import{t as k}from"./key-round-BBPO5HDK.js";import{t as A}from"./monitor-smartphone-CS_5BZqr.js";import{t as j}from"./unlink-BKDNubwr.js";import{Jn as M,Yn as ee}from"./client-CVIfL49c.js";import{Ao as te,Bn as ne,Cn as re,Ft as ie,Jl as ae,Oo as N,Wn as oe,Z as P,Zn as F,wn as se,yu as I}from"./src-DOs8Kg5s.js";import{t as ce}from"./i18n-CmGpgquB.js";import{t as L}from"./useTranslation-D3Is_4B6.js";import"./mount-mxypQ5EF.js";import{Y as R,i as z,n as B,r as V,t as H,z as U}from"./index-DkNBNJNl.js";import{t as W}from"./AdminPage-Dla2hgly.js";import{N as G,P as le,_ as K,a as ue,g as de,k as fe,r as pe,t as q,v as me}from"./SessionsList-BuiRHWv-.js";n();function he({value:n,size:i=192}){let{t:s}=L(),[c,l]=a(null),[u,f]=a(null);if(r(()=>{let r=!1;return t(()=>import(`./browser-BHo8W_uH.js`).then(t=>e(t.default,1)).then(async e=>{if(r)return;let t=e.create;if(typeof t!=`function`){f(`qrcode.create() unavailable in installed version`);return}try{let e=t(n,{errorCorrectionLevel:`M`});r||l(e)}catch(e){r||f(e instanceof Error?e.message:`QR generation failed`)}}),__vite__mapDeps([0,1]),import.meta.url).catch(()=>{r||f(`qrcode library not installed`)}),()=>{r=!0}},[n]),u)return d(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle text-center p-4`,style:{width:i,height:i},children:s(`users.totpQrCode.qrRenderingUnavailableUseThe`,`QR rendering unavailable — use the secret below.`)});if(!c)return d(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle animate-pulse`,style:{width:i,height:i},children:s(`users.totpQrCode.generating`,`Generating…`)});let p=c.modules.size,m=i/p,h=[];for(let e=0;e<p;e++)for(let t=0;t<p;t++)c.modules.data[e*p+t]&&h.push(d(`rect`,{x:t*m,y:e*m,width:m,height:m,fill:`currentColor`},`${t}-${e}`));return o(`svg`,{width:i,height:i,viewBox:`0 0 ${i} ${i}`,className:`text-black`,children:[d(`rect`,{x:0,y:0,width:i,height:i,fill:`white`}),h]})}var ge=`${M}/connect`,J={public:0,mesh:1,lan:2,"lan-ipv6":3};function _e(e){switch(e.kind){case`public`:return e.interfaceKind===`vpn`?`mesh`:`public`;case`lan-ipv4`:return`lan`;case`lan-ipv6`:return`lan-ipv6`;case`custom`:return`public`;case`loopback`:case`app-link`:return null}}function Y(e){return ee(e)}function ve(e){return e.startsWith(`https://`)}function ye(e){let t=e.flatMap(e=>{let t=_e(e),n=Y(e.baseUrl);return t===null||n===null?[]:[{endpoint:e,tier:t,origin:n}]}).toSorted((e,t)=>J[e.tier]-J[t.tier]||Number(t.endpoint.plausible)-Number(e.endpoint.plausible)||e.endpoint.priority-t.endpoint.priority),n=new Set;return t.flatMap(({endpoint:e,tier:t,origin:r})=>n.has(r)?[]:(n.add(r),[{origin:r,label:e.label,tier:t,secure:ve(r),plausible:e.plausible}]))}function be(e,t,n=null){for(let r of[t,n]){if(r===null)continue;let t=Y(r),n=e.find(e=>e.origin===t);if(n!==void 0)return n}return e[0]??null}function xe(e){let t=new URL(ge);return t.searchParams.set(`hub`,e),t.toString()}n();var Se=176,X={scheme:`https`};function Ce(){let{t:e}=L(),t=te(X),n=N(X).data?.roles.publicEndpoint.resolved??null;return o(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[o(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[d(v,{className:`h-3.5 w-3.5 text-foreground-subtle`}),d(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`connectPhone.title`)})]}),o(`div`,{className:`p-4 space-y-3`,children:[d(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`connectPhone.description`)}),t.isPending?o(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[d(b,{className:`h-3.5 w-3.5 animate-spin`}),e(`connectPhone.loading`)]}):t.isError?o(`div`,{className:`flex items-start gap-2 text-[11px] text-danger`,children:[d(h,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),o(`div`,{className:`flex-1 min-w-0 space-y-1.5`,children:[d(`div`,{className:`break-words`,children:e(`connectPhone.error`,{message:t.error.message})}),d(ne,{size:`sm`,variant:`ghost`,onClick:()=>void t.refetch(),children:e(`connectPhone.retry`)})]})]}):d(we,{candidates:ye(t.data.endpoints),preferredOrigin:n})]})]})}function we({candidates:e,preferredOrigin:t}){let{t:n}=L(),[r,s]=a(null),c=be(e,r,t),l=i(()=>c?xe(c.origin):null,[c]);if(c===null||l===null)return d(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`connectPhone.empty`)});let u=e=>n(`connectPhone.tier.${e}`),f=e.map(e=>({value:e.origin,label:`${u(e.tier)} — ${e.origin}`}));return o(`div`,{className:`flex flex-col sm:flex-row gap-4`,children:[d(re,{value:l,size:Se,alt:n(`connectPhone.qrAlt`),className:`self-start`}),o(`div`,{className:`flex-1 min-w-0 space-y-3`,children:[o(`label`,{className:`block space-y-1`,children:[d(`span`,{className:`text-[11px] font-medium text-foreground`,children:n(`connectPhone.addressLabel`)}),d(ae,{value:c.origin,options:f,onChange:e=>s(e.target.value)}),o(`span`,{className:`block text-[10px] text-foreground-subtle`,children:[u(c.tier),` · `,c.label]})]}),!c.secure&&d(Z,{text:n(`connectPhone.insecure`)}),!c.plausible&&d(Z,{text:n(`connectPhone.implausible`)}),o(`div`,{className:`space-y-1`,children:[d(`span`,{className:`text-[11px] font-medium text-foreground`,children:n(`connectPhone.linkLabel`)}),o(`div`,{className:`flex items-center gap-1 rounded-md border border-border bg-background px-2 py-1`,children:[d(`code`,{className:`flex-1 min-w-0 font-mono text-[11px] text-foreground break-all select-all`,children:l}),d(ie,{value:l,srLabel:n(`connectPhone.linkLabel`)})]})]}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`connectPhone.signInHint`)})]})]})}function Z({text:e}){return o(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-2.5 py-1.5 text-[11px] text-foreground`,children:[d(h,{className:`h-3.5 w-3.5 text-warning mt-0.5 shrink-0`}),d(`span`,{children:e})]})}n();function Te(e){return new Date(e).toLocaleDateString()}function Ee(){let{t:e}=L(),t=F(),n=I.useUtils(),i=I.auth.listLinkableProviders.useQuery(),s=I.auth.listOwnExternalIdentities.useQuery(),[c,u]=a(null),[f,p]=a(()=>z(window.location.search)),m=l(null),h=K(`Linking a sign-in account`),g=l(null);r(()=>()=>g.current?.(),[]);let[v,y]=a(null);r(()=>{if(f===null)return;let e=new URL(window.location.href);e.searchParams.delete(`linked`),e.searchParams.delete(`linkError`),window.history.replaceState({},``,e.pathname+e.search+e.hash)},[f]);let C=I.auth.beginExternalLink.useMutation({onSuccess:({url:e})=>{let t=m.current;if(m.current=null,t===null||t.closed){window.location.assign(e);return}let r=e=>{y(null),p(z(`?${e}`)),n.auth.listOwnExternalIdentities.invalidate()};g.current?.(),g.current=B(t,{onReturn:e=>{e.target===`profile`&&r(e.query)},onDone:e=>{e.target===`profile`&&r(e.query)},onClosed:()=>{g.current?.(),g.current=null,n.auth.listOwnExternalIdentities.invalidate()}}),t.location.href=_(V(e))},onError:e=>{m.current?.close(),m.current=null,y(null),u(e.message)}}),w=I.auth.unlinkOwnExternalIdentity.useMutation({onSuccess:()=>void n.auth.listOwnExternalIdentities.invalidate(),onError:e=>u(e.message)}),T=i.data??[],D=s.data??[],O=v!==null&&D.some(e=>e.provider===v);if(r(()=>{!O||v===null||(y(null),p({kind:`linked`,provider:v}))},[O,v]),T.length===0&&D.length===0)return null;let k=new Set(D.map(e=>e.provider)),A=e=>T.find(t=>t.provider===e)?.label??e,M=async(n,r)=>{await t({title:e(`users.linkedSignInsSection.unlinkSignInAccount`,`Unlink sign-in account`),message:e(`users.linkedSignInsSection.stopSigningInWithThis`,`Stop signing in with this {{label}} account?`,{label:r}),confirmLabel:e(`users.linkedSignInsSection.unlink`,`Unlink`),variant:`danger`})&&(u(null),w.mutate({provider:n.provider,subject:n.subject}))};return o(`div`,{"data-testid":`linked-sign-ins`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[h.dialog,o(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[d(x,{className:`h-3.5 w-3.5 text-foreground-subtle`}),d(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`users.linkedSignInsSection.linkedSignInAccounts`,`Linked sign-in accounts`)})]}),o(`div`,{className:`p-4 space-y-3`,children:[d(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`users.linkedSignInsSection.signInWithAnExternal`,`Sign in with an external account instead of your password. Only accounts you link here can sign you in; your two-factor authentication still applies.`)}),f?.kind===`linked`&&o(`div`,{className:`flex items-center gap-2 rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2 text-xs text-foreground`,children:[d(S,{className:`h-3.5 w-3.5 text-emerald-500 shrink-0`}),e(`users.linkedSignIns.linkedNotice`,{provider:A(f.provider)})]}),(f?.kind===`error`||c)&&o(`div`,{className:`flex items-center gap-2 rounded-md border border-danger/20 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[d(E,{className:`h-3.5 w-3.5 shrink-0`}),c??(f?.kind===`error`?f.message:``)]}),D.length>0&&d(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:D.map(t=>{let n=t.providerLabel??t.provider;return o(`li`,{className:`flex items-center gap-3 px-3 py-2 text-xs`,children:[o(`div`,{className:`flex-1 min-w-0`,children:[o(`div`,{className:`font-medium text-foreground truncate`,children:[n,!t.available&&d(`span`,{className:`ml-2 rounded bg-foreground-subtle/15 px-1.5 py-0.5 text-[10px] font-normal text-foreground-subtle`,children:e(`users.linkedSignInsSection.providerUnavailable`,`provider unavailable`)})]}),d(`div`,{className:`text-[11px] text-foreground-subtle truncate`,children:e(`users.linkedSignIns.linkedOn`,{label:t.label??t.subject,date:Te(t.linkedAt)})})]}),o(`button`,{onClick:()=>void M(t,n),disabled:w.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[d(j,{className:`h-3 w-3`}),e(`users.linkedSignInsSection.unlink`,`Unlink`)]})]},`${t.provider}|${t.subject}`)})}),d(`div`,{className:`flex flex-wrap gap-2`,children:T.filter(e=>!k.has(e.provider)).map(t=>o(`button`,{onClick:()=>{u(null),p(null),h.requestProof().then(e=>{e!==null&&(m.current=H(null),y(m.current===null?null:t.provider),C.mutate({provider:t.provider,reauthToken:e}))})},disabled:C.isPending,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1 text-[11px] font-medium text-foreground hover:bg-surface-hover disabled:opacity-50`,children:[C.isPending&&C.variables?.provider===t.provider?d(b,{className:`h-3 w-3 animate-spin`}):d(x,{className:`h-3 w-3`}),e(`users.linkedSignIns.link`,{provider:t.label})]},t.provider))})]})]})}n();function Q(e){return e.message.length>0?e.message:ce.t(`auth.authAuditSection.requestFailed`)}function De(){let{t:e}=L(),{logout:t}=U(),n=F(),r=I.useUtils(),i=I.auth.listOwnSessions.useQuery(),[s,c]=a(null),l=I.auth.revokeOwnSession.useMutation({onSuccess:()=>void r.auth.listOwnSessions.invalidate(),onError:e=>c(`Sign out failed: ${Q(e)}`)}),u=I.auth.logout.useMutation({onSuccess:()=>t(),onError:e=>c(`Sign out failed: ${Q(e)}`)}),f=async t=>{await n({title:e(`auth.mySessionsSection.signOutThisSession`,`Sign out this session`),message:e(`auth.mySessionsSection.willHaveToSignIn`,`{{label}} will have to sign in again.`,{label:me(t.client).label}),confirmLabel:e(`auth.mySessionsSection.signOut`,`Sign out`),variant:`danger`})&&(c(null),l.mutate({id:t.id}))},p=async()=>{await n({title:e(`auth.mySessionsSection.signOutEverywhere`,`Sign out everywhere`),message:e(`auth.mySessionsSection.everySessionOfYourAccount`,`Every session of your account ends, this browser included: you will be signed out here too and every device has to sign in again.`),confirmLabel:e(`auth.mySessionsSection.signOutEverywhere`,`Sign out everywhere`),variant:`danger`})&&(c(null),u.mutate({everywhere:!0}))};return o(`div`,{"data-testid":`my-sessions`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[o(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[d(A,{className:`h-3.5 w-3.5 text-foreground-subtle`}),d(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`auth.mySessionsSection.activeSessions`,`Active sessions`)})]}),o(`div`,{className:`p-4 space-y-3`,children:[d(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`auth.mySessionsSection.theBrowsersAndAppsSigned`,`The browsers and apps signed in to your account. Signing one out ends it at once.`)}),s!==null&&d(`div`,{className:`text-[11px] text-danger`,children:s}),d(q,{sessions:i.data??[],isLoading:i.isLoading,loadError:i.isError?i.error?.message??e(`auth.authAuditSection.requestFailed`):null,emptyText:`No active sessions.`,onRevoke:e=>void f(e),revokingId:l.isPending?l.variables?.id??null:null}),d(`div`,{className:`flex justify-end`,children:o(`button`,{onClick:()=>void p(),disabled:u.isPending,className:`inline-flex items-center gap-1.5 rounded border border-danger/40 px-2.5 py-1 text-[11px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,children:[u.isPending?d(b,{className:`h-3 w-3 animate-spin`}):d(O,{className:`h-3 w-3`}),e(`auth.mySessionsSection.signOutEverywhere`,`Sign out everywhere`)]})})]})]})}n();var Oe=`You`;function ke(){let{t:e}=L(),t=F(),n=I.useUtils(),r=I.auth.listOwnDeviceCredentials.useQuery(),[o,s]=a(null),c=I.auth.revokeOwnDeviceCredential.useMutation({onSuccess:e=>{e.revoked||s(`That device could not be revoked - it may already be gone.`),n.auth.listOwnDeviceCredentials.invalidate()},onError:e=>s(`Revoke failed: ${e.message}`)}),l=i(()=>(r.data??[]).map(e=>pe(e,Oe)),[r.data]),u=async n=>{await t({title:e(`certificates.myDevicesSection.revoke`,`Revoke "{{name}}"?`,{name:n.name}),message:e(`certificates.myDevicesSection.theDeviceStopsSigningIn`,`The device stops signing in at once and its open sessions end. To use it again you have to pair it anew. This cannot be undone.`),confirmLabel:e(`certificates.myDevicesSection.revoke2`,`Revoke`),variant:`danger`})&&(s(null),c.mutate({id:n.id}))},p={label:e(`certificates.myDevicesSection.revoke2`,`Revoke`),icon:f,isAvailable:ue,onRun:e=>void u(e),busyId:c.isPending?c.variables?.id??null:null,disabled:c.isPending};return d(G,{id:`my-devices`,title:e(`certificates.myDevicesSection.myDevices`,`My devices`),icon:v,description:e(`certificates.myDevicesSection.phonesThatStaySignedIn`,`Phones that stay signed in to your account with a certificate. If one is lost, revoke it here and it is signed out at once.`),notice:le(o),onDismissNotice:()=>s(null),children:d(fe,{rows:l,label:e(`certificates.devicesCard.label`),isLoading:r.isPending,loadError:r.error===null?null:r.error.message||`Request failed`,emptyText:`No devices are signed in with a certificate.`,hideOwner:!0,expiresNone:`—`,action:p})})}n();var Ae={view:{icon:p,cls:`bg-foreground-subtle/15 text-foreground-subtle`},create:{icon:g,cls:`bg-primary/15 text-primary`},delete:{icon:m,cls:`bg-danger/15 text-danger`}};function je(){let{t:e}=L(),t=C(),{user:n,logout:r}=U();if(!n)return d(W,{children:d(`div`,{className:`text-xs text-foreground-subtle`,children:e(`systemPage.myAccess.notSignedIn`,`Not signed in.`)})});let i=n.isAdmin,a=n.scopes??[];return o(W,{children:[o(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3 flex items-center gap-3`,children:[d(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-full bg-primary/10 text-primary font-semibold text-base`,children:n.username.slice(0,1).toUpperCase()}),o(`div`,{className:`flex-1 min-w-0`,children:[d(`div`,{className:`text-sm font-semibold text-foreground truncate`,children:n.username}),o(`div`,{className:`text-[11px] text-foreground-subtle`,children:[i?e(`systemPage.myAccess.administrator`,`Administrator`):e(`systemPage.myAccess.user`,`User`),` `,d(R,{i18nKey:`systemPage.myAccess.sessionId`,values:{id:n.id.slice(0,8)},components:{mono:d(`span`,{className:`font-mono`})}})]})]})]}),i&&o(`div`,{className:`rounded-lg border border-primary/30 bg-primary/5 px-4 py-3 text-xs text-foreground flex items-start gap-2.5`,children:[d(D,{className:`h-4 w-4 text-primary mt-0.5 shrink-0`}),o(`div`,{children:[d(`div`,{className:`font-semibold text-foreground`,children:e(`systemPage.myAccess.unrestrictedAccess`,`Unrestricted access`)}),d(`p`,{className:`text-foreground-subtle mt-0.5`,children:e(`systemPage.myAccess.adminSessionsBypassThePer`,`Admin sessions bypass the per-call scope check. Every protected endpoint is reachable regardless of the list below.`)})]})]}),d(Me,{}),d(Ne,{username:n.username}),d(Pe,{}),d(Ee,{}),d(de,{}),d(De,{}),d(ke,{}),d(Ce,{}),a.length>0&&o(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[o(`div`,{className:`px-4 py-2 border-b border-border`,children:[d(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`systemPage.myAccess.grantedScopes`,`Granted scopes`)}),d(`div`,{className:`text-[10px] text-foreground-subtle`,children:e(`systemPage.myAccess.bakedIntoYourSessionToken`,`Baked into your session token at login; sign out + back in to refresh after changes.`)})]}),o(`div`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[d(`div`,{children:e(`systemPage.myAccess.type`,`Type`)}),d(`div`,{children:e(`systemPage.myAccess.target`,`Target`)}),d(`div`,{children:e(`systemPage.myAccess.access`,`Access`)})]}),d(`ul`,{className:`divide-y divide-border`,children:a.map((n,r)=>o(`li`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2.5 items-center text-xs`,children:[d(`span`,{className:`font-mono text-foreground-subtle`,children:n.type}),d(`span`,{className:`font-mono text-foreground`,children:n.type===`device`?P(n.selector,t):n.target}),d(`div`,{className:`flex items-center gap-1`,children:[`view`,`create`,`delete`].map(t=>{let r=n.access.includes(t),{icon:i,cls:a}=Ae[t];return o(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${r?a:`bg-transparent text-foreground-subtle/40 line-through`}`,title:r?e(`systemPage.myAccess.can`,`Can {{a}}`,{a:t}):e(`systemPage.myAccess.cannot`,`Cannot {{a}}`,{a:t}),children:[d(i,{className:`h-3 w-3`}),t]},t)})})]},r))})]}),d(`div`,{className:`flex justify-end`,children:o(`button`,{onClick:r,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground transition-colors`,children:[d(O,{className:`h-3 w-3`}),e(`systemPage.myAccess.signOut`,`Sign out`)]})})]})}function Me(){let{t:e}=L(),t=T(),[n,r]=a(``),[i,s]=a(``),[c,l]=a(``),[f,p]=a(null),m=u({mutationFn:e=>t.changeOwnPassword(e),onSuccess:()=>{p({kind:`success`,msg:`Password updated.`}),r(``),s(``),l(``)},onError:e=>{p({kind:`error`,msg:e instanceof Error?e.message:`Update failed`})}}),h=i.length>0&&c.length>0&&i!==c,g=i.length>0&&i.length<8,_=n.length>=1&&i.length>=8&&i===c;return o(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[o(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[d(k,{className:`h-3.5 w-3.5 text-foreground-subtle`}),d(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`systemPage.myAccess.changePassword`,`Change password`)})]}),o(`div`,{className:`p-4 space-y-3`,children:[d($,{label:e(`systemPage.myAccess.currentPassword`,`Current password`),value:n,onChange:r,autoComplete:`current-password`}),d($,{label:e(`systemPage.myAccess.newPassword`,`New password`),value:i,onChange:s,autoComplete:`new-password`,hint:e(`systemPage.myAccess.atLeast8Characters`,`At least 8 characters.`)}),d($,{label:e(`systemPage.myAccess.confirmNewPassword`,`Confirm new password`),value:c,onChange:l,autoComplete:`new-password`}),(h||g)&&d(`div`,{className:`text-[11px] text-danger`,children:h?e(`systemPage.myAccess.passwordsDoNotMatch`,`Passwords do not match.`):e(`systemPage.myAccess.newPasswordMustBeAt`,`New password must be at least 8 characters.`)}),f&&o(`div`,{className:`text-[11px] flex items-center gap-1 ${f.kind===`success`?`text-emerald-500`:`text-danger`}`,children:[f.kind===`success`?d(S,{className:`h-3 w-3`}):d(E,{className:`h-3 w-3`}),f.msg]}),d(`div`,{className:`flex justify-end`,children:o(`button`,{onClick:()=>{p(null),m.mutate({currentPassword:n,newPassword:i})},disabled:!_||m.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[m.isPending?d(b,{className:`h-3 w-3 animate-spin`}):d(w,{className:`h-3 w-3`}),e(`systemPage.myAccess.updatePassword`,`Update password`)]})})]})]})}function $({label:e,value:t,onChange:n,autoComplete:r,hint:i}){return o(`div`,{className:`space-y-1`,children:[d(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e}),d(`input`,{type:`password`,value:t,onChange:e=>n(e.target.value),autoComplete:r,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),i&&d(`div`,{className:`text-[10px] text-foreground-subtle`,children:i})]})}function Ne({username:e}){let{t}=L(),n=T(),l=s({queryKey:[`auth`,`getOwnTotpStatus`],queryFn:()=>n.getOwnTotpStatus()}),f=l.data,[p,m]=a(null),[h,g]=a(``),[_,x]=a(null),[C,w]=a(!1),D=u({mutationFn:()=>n.setupOwnTotp(),onSuccess:e=>{m({secret:e.secret,otpauthUrl:e.otpauthUrl}),g(``),x(null)},onError:e=>x(e instanceof Error?e.message:`Setup failed`)}),O=u({mutationFn:e=>n.confirmOwnTotp(e),onSuccess:()=>{m(null),g(``),x(null),l.refetch()},onError:e=>x(e instanceof Error?e.message:`Confirmation failed — code did not match`)}),k=K(`Turning off two-factor authentication`),A=u({mutationFn:async()=>{let e=await k.requestProof();return e===null?null:n.disableOwnTotp({reauthToken:e})},onSuccess:()=>{x(null),l.refetch()},onError:e=>x(e instanceof Error?e.message:`Disable failed`)});r(()=>{if(!C)return;let e=setTimeout(()=>w(!1),1500);return()=>clearTimeout(e)},[C]);let j=i(()=>l.isLoading?`loading`:p?`setup_in_progress`:f?.enabled?`enrolled`:`not_enrolled`,[l.isLoading,f?.enabled,p]);return o(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[k.dialog,o(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[d(v,{className:`h-3.5 w-3.5 text-foreground-subtle`}),d(`div`,{className:`text-xs font-semibold text-foreground`,children:t(`systemPage.myAccess.twoFactorAuthentication`,`Two-factor authentication`)})]}),o(`div`,{className:`p-4 space-y-3`,children:[j===`loading`&&o(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(b,{className:`h-3.5 w-3.5 animate-spin`}),t(`systemPage.myAccess.checkingStatus`,`Checking status…`)]}),j===`not_enrolled`&&o(c,{children:[d(`div`,{className:`text-xs text-foreground-subtle`,children:t(`systemPage.myAccess.2faIsnTActiveOn`,`2FA isn't active on your account. Enable it to require a 6-digit code from your authenticator app at every login.`)}),d(`div`,{className:`flex justify-end`,children:o(`button`,{onClick:()=>{x(null),D.mutate()},disabled:D.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[D.isPending?d(b,{className:`h-3 w-3 animate-spin`}):d(v,{className:`h-3 w-3`}),t(`systemPage.myAccess.enable2fa`,`Enable 2FA`)]})})]}),j===`setup_in_progress`&&p&&o(c,{children:[d(`div`,{className:`text-[11px] text-foreground-subtle`,children:d(R,{i18nKey:`systemPage.myAccess.scanQr`,values:{username:e},components:{mono:d(`span`,{className:`font-mono`})}})}),o(`div`,{className:`flex flex-col items-center gap-3`,children:[d(`div`,{className:`rounded-lg border border-border bg-white p-3`,children:d(he,{value:p.otpauthUrl,size:180})}),o(`div`,{className:`w-full`,children:[d(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle mb-1`,children:t(`systemPage.myAccess.secretManualEntry`,`Secret (manual entry)`)}),o(`div`,{className:`flex items-center gap-2 rounded border border-border bg-surface-hover/30 px-2 py-1.5`,children:[d(`code`,{className:`text-[11px] font-mono text-foreground break-all flex-1`,children:p.secret}),o(`button`,{onClick:()=>{p&&navigator.clipboard.writeText(p.secret).then(()=>w(!0))},className:`inline-flex items-center gap-1 text-[10px] text-foreground-subtle hover:text-foreground`,children:[C?d(S,{className:`h-3 w-3 text-emerald-500`}):d(y,{className:`h-3 w-3`}),C?t(`systemPage.myAccess.copied`,`Copied`):t(`common.copy`,`Copy`)]})]})]})]}),o(`div`,{className:`space-y-1`,children:[d(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`6-digit code`}),d(`input`,{type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,placeholder:`123456`,value:h,onChange:e=>g(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full rounded-md border border-border bg-surface px-3 py-2 text-center text-lg font-mono tracking-widest text-foreground focus:outline-none focus:ring-2 focus:ring-primary`})]}),_&&o(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[d(E,{className:`h-3 w-3`}),_]}),o(`div`,{className:`flex justify-end gap-2`,children:[d(`button`,{onClick:()=>{m(null),x(null),g(``)},className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:t(`common.cancel`,`Cancel`)}),o(`button`,{onClick:()=>{x(null),O.mutate({code:h})},disabled:O.isPending||h.length!==6,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[O.isPending?d(b,{className:`h-3 w-3 animate-spin`}):d(S,{className:`h-3 w-3`}),t(`common.confirm`,`Confirm`)]})]})]}),j===`enrolled`&&f&&o(c,{children:[o(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[d(S,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),o(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[d(`div`,{className:`font-medium`,children:t(`systemPage.myAccess.2faIsActive`,`2FA is active`)}),d(`div`,{className:`text-foreground-subtle`,children:t(`common.enrolledOn`,{when:f.confirmedAt?new Date(f.confirmedAt).toLocaleString():`—`})})]})]}),_&&o(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[d(E,{className:`h-3 w-3`}),_]}),d(`div`,{className:`flex justify-end`,children:o(`button`,{onClick:()=>{x(null),A.mutate()},disabled:A.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[A.isPending?d(b,{className:`h-3 w-3 animate-spin`}):d(v,{className:`h-3 w-3`}),t(`systemPage.myAccess.disable2fa`,`Disable 2FA`)]})})]})]})]})}function Pe(){return oe(`auth-webauthn/passkey-enrollment`)?d(se,{widgetId:`auth-webauthn/passkey-enrollment`,host:`dashboard`}):null}export{je as MyAccessPage};
|