@camstack/addon-admin-ui 1.2.700 → 1.2.701
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/assets/{AccessSection-DuhBff2I.js → AccessSection-CmGUVN2c.js} +1 -1
- package/dist/assets/{Addons-DkWR3gkq.js → Addons-CgCQDQsS.js} +1 -1
- package/dist/assets/{AdminPage-CyMuobXy.js → AdminPage-Dvziohv2.js} +1 -1
- package/dist/assets/{AdminSectionedPage-DiyrPcy9.js → AdminSectionedPage-3F0XiS4h.js} +1 -1
- package/dist/assets/{AiProfiles-DUZci2sf.js → AiProfiles-BAdfHll3.js} +1 -1
- package/dist/assets/{Archive-BumU9DOS.js → Archive-tBDnGn2J.js} +1 -1
- package/dist/assets/{BootstrapSettingsForm-CEkpZiEK.js → BootstrapSettingsForm-D5_YCsD2.js} +1 -1
- package/dist/assets/{Build-B0Su_s2L.js → Build-DgzW58SZ.js} +1 -1
- package/dist/assets/{Calendars-DsRFyTPC.js → Calendars-BzFF94EV.js} +1 -1
- package/dist/assets/{Cluster-D2qSEqhz.js → Cluster-Chna0Sjs.js} +1 -1
- package/dist/assets/{CompositionBlockEditor-BKG-rKjJ.js → CompositionBlockEditor-BUQTd-UR.js} +1 -1
- package/dist/assets/{CompositionEditorPage-8y0k5Nhe.js → CompositionEditorPage-BTvOMFXc.js} +1 -1
- package/dist/assets/{Data-D9LaQOXD.js → Data-Ge58RjOD.js} +1 -1
- package/dist/assets/{DeviceDetail-BxDpw3WU.js → DeviceDetail-C09lWDie.js} +1 -1
- package/dist/assets/{Devices-CDjecVeO.js → Devices-DsS5GkXt.js} +1 -1
- package/dist/assets/{EmbedDevicePage-BD6_HvMe.js → EmbedDevicePage-BkW36-q-.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-Bf0oo9Q3.js → EmbedPlayerPage-BD43fNk-.js} +1 -1
- package/dist/assets/{History-CRvVI3U1.js → History-D-ERNFKB.js} +1 -1
- package/dist/assets/{Identity-CgqjNQVX.js → Identity-DXfvzQIG.js} +1 -1
- package/dist/assets/{InstancesTable-DcwQ5Z2U.js → InstancesTable-BzPfQPuA.js} +1 -1
- package/dist/assets/{IntegrationDetail-CTL_BNd5.js → IntegrationDetail-CEcOLviw.js} +1 -1
- package/dist/assets/{Integrations-DjE3kD95.js → Integrations-BOc2LGfc.js} +1 -1
- package/dist/assets/{Integrations-BWIZL8DT.js → Integrations-BgRTT3i6.js} +1 -1
- package/dist/assets/{Library-CnuFtxG7.js → Library-DUI94NI6.js} +1 -1
- package/dist/assets/{Locations-C5O5CcZV.js → Locations-DkcchiHh.js} +1 -1
- package/dist/assets/{Logs-BPEaFkcQ.js → Logs-DS49QhkO.js} +1 -1
- package/dist/assets/{MyAccess-DenZQPxt.js → MyAccess-TXMLevZM.js} +1 -1
- package/dist/assets/{Network-DWGrdbU2.js → Network-Dxm48n1Y.js} +1 -1
- package/dist/assets/{NewExportModal-Dn5qIfYF.js → NewExportModal-DQLl3C3Q.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-C1h8YgnE.js → NodeAddonsSettingsPanel-H8ruMWFP.js} +1 -1
- package/dist/assets/{Notifications-RetD-vo3.js → Notifications-B44Sd1jg.js} +1 -1
- package/dist/assets/{PanelContent-CWdEuPnB.js → PanelContent-DnT2f8Cc.js} +1 -1
- package/dist/assets/{Pipeline-g9OrBU5t.js → Pipeline-XpW32I39.js} +1 -1
- package/dist/assets/{SessionsList-PpGdvCRu.js → SessionsList-D0tv-91a.js} +1 -1
- package/dist/assets/{Showroom-DSutXWcf.js → Showroom-BlMk46Us.js} +1 -1
- package/dist/assets/{StorageLocationsTable-eT6j45e1.js → StorageLocationsTable-13scCxNp.js} +1 -1
- package/dist/assets/{System-BbVT7aZV.js → System-CkjsA5xm.js} +1 -1
- package/dist/assets/{TemplateEditorDialog-CkVm64ab.js → TemplateEditorDialog-fJjZNx16.js} +1 -1
- package/dist/assets/{Terminal-jh3VZwwP.js → Terminal-BwEVkhLM.js} +1 -1
- package/dist/assets/{TrainingProviders-B0MPb6es.js → TrainingProviders-CPc4S7AF.js} +1 -1
- package/dist/assets/{Viewer-Fo86cc0-.js → Viewer-B4D9Uq2-.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-rBseLAXs.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-D6FI5YpS.js} +1 -1
- package/dist/assets/{assignment-candidates-tNcnUZOo.js → assignment-candidates-BfJhT0tz.js} +1 -1
- package/dist/assets/{authed-media-Dmn6VKYc.js → authed-media-ChKbSmi3.js} +1 -1
- package/dist/assets/{device-detail-CRi_SiN0.js → device-detail-CFJoqbEo.js} +1 -1
- package/dist/assets/{device-integration-icon-DigkwuPa.js → device-integration-icon-BwgC8WB_.js} +1 -1
- package/dist/assets/device-picker-model-CVOfqhXA.js +1 -0
- package/dist/assets/{hostInit-DKsMmBUL.js → hostInit-DO8vSCT5.js} +1 -1
- package/dist/assets/{index-BtSb3e7u.js → index-BN2PojUq.js} +3 -3
- package/dist/assets/{linked-devices-model-DfectUL6.js → linked-devices-model-bymuMeaF.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-3133e5cd.js → mf-entry-bootstrap-0-dc995488.js} +2 -2
- package/dist/assets/mount-CVOfqhXA.js +1 -0
- package/dist/assets/remoteEntry-CeXhbAxp.js +1 -0
- package/dist/assets/{src-CFKmxwYU.js → src-C9_yKHH3.js} +1 -1
- package/dist/assets/{step-inspector-model-BTxke2pR.js → step-inspector-model-B_OOCp6Z.js} +1 -1
- package/dist/assets/{use-scenes-feed-BO3ulLXX.js → use-scenes-feed-D9kXSeA2.js} +1 -1
- package/dist/assets/{useAdminDeviceRemoval-DnSeZ4C8.js → useAdminDeviceRemoval-CF8lG06z.js} +1 -1
- package/dist/assets/useEventInvalidation-CVOfqhXA.js +1 -0
- package/dist/assets/{useNodeUrlSelection-B7z0eVw2.js → useNodeUrlSelection-ju70FIba.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-COrdYohN.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BSgZU_Z3.js} +2 -2
- package/dist/index.html +4 -4
- package/dist/server/addon.js +1 -1
- package/package.json +2 -2
- package/dist/assets/device-picker-model-Ct4hIz-N.js +0 -1
- package/dist/assets/mount-Ct4hIz-N.js +0 -1
- package/dist/assets/remoteEntry-dUdMqzVb.js +0 -1
- package/dist/assets/useEventInvalidation-Ct4hIz-N.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as e,J as t,K as n,Q as r,R as i,S as a,V as o,Y as s,et as c,o as l,x as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$a as d,D as f,Hn as p,Tt as m,Wi as h,Wt as g,Xr as _,Yn as v,Zt as y,c as b,ct as x,da as S,f as C,fa as w,ft as T,hi as E,ir as D,l as O,mn as k,qn as A,qt as j,sa as M,tn as N,u as P,ur as F,wi as I,yn as L,yt as R,zr as z}from"./player-overlays-D546iNTv.js";import{ll as B}from"./client-DQzHwaNb.js";import{s as V}from"./terminal-DZ5OZpgC.js";import{a as H,i as U,n as W,o as G,r as K,t as q}from"./user-x-DkWcmF99.js";import{t as J}from"./crop-B-t0rzRY.js";import{t as ee}from"./square-check-big-DAcFGNUN.js";import{Bc as te,Br as ne,Cd as re,Dd as ie,Dr as ae,Ed as oe,Gc as se,Gi as ce,Hc as le,Hd as ue,Ic as de,Ir as fe,Jc as pe,Ji as me,Kc as he,Ki as ge,Lc as _e,Od as ve,Rc as ye,Sd as be,Sp as xe,Td as Se,Tr as Ce,Uc as we,Ui as Te,Vc as Ee,Vd as De,Wc as Oe,Xp as ke,Yi as Ae,Yp as je,Zs as Me,_d as Ne,bd as Pe,ia as Fe,ka as Ie,kd as Le,la as Re,mi as ze,nt as Be,pp as Y,qc as Ve,qi as He,rt as Ue,t as We,tt as Ge,ut as Ke,vd as qe,wd as Je,xd as Ye,xp as Xe,yd as Ze,zc as Qe,zd as $e,zr as et}from"./src-CFKmxwYU.js";import{t as X}from"./i18n-HSlX-YO0.js";import{t as Z}from"./useTranslation-BJr-n0es.js";import{Ai as tt,Mi as nt,Ni as rt,b as it,ji as at,vi as ot,wi as st}from"./index-BtSb3e7u.js";import{t as ct}from"./AdminSectionedPage-DiyrPcy9.js";import{a as lt,c as ut,d as dt,f as ft,i as pt,l as mt,m as ht,n as gt,o as _t,p as vt,r as yt,s as bt,t as xt}from"./NewExportModal-Dn5qIfYF.js";import{a as St,n as Ct,r as wt}from"./authed-media-Dmn6VKYc.js";import{t as Tt}from"./format-size-DIxKXxtj.js";import{t as Et}from"./use-scenes-feed-BO3ulLXX.js";c();function Dt(e){let t=[];return e.timelapse?t.push(`timelapse ${String(e.timelapse.everyMs/1e3)}s`):(t.push(`${String(e.speed??1)}×`),e.includeAudio&&t.push(`+ audio`)),t.join(` `)}function Ot(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}function kt(e,t){let n=Math.max(0,Math.round((t-e)/1e3)),r=Math.floor(n/3600),i=Math.floor(n%3600/60),a=n%60,o=r>0?`${String(r)}:${String(i).padStart(2,`0`)}:${String(a).padStart(2,`0`)}`:`${String(i)}:${String(a).padStart(2,`0`)}`;return`${Ot(e)} · ${o}`}function At(e,t){let n=e-t;if(n<=0)return X.t(`helpers.exportFormat.expired`);let r=Math.floor(n/6e4);if(r<60)return X.t(`helpers.exportFormat.inMinutes`,{n:String(r)});let i=Math.floor(r/60);return i<24?X.t(`helpers.exportFormat.inHours`,{n:String(i)}):X.t(`helpers.exportFormat.inDays`,{n:String(Math.floor(i/24))})}function jt(e,t,n,r){return e.map(e=>{if(e.state===`expired`||e.state===`deleted`)return e;let i=r.get(e.id);if(i)return{...e,state:`failed`,error:i.error,progressPct:null};let a=n.get(e.id);if(a)return{...e,state:`ready`,fileBytes:a.fileBytes,progressPct:100};let o=t.get(e.id);return o&&(e.state===`queued`||e.state===`rendering`)?{...e,state:`rendering`,progressPct:o.progressPct}:e})}var Mt=[[`recordingExport`]],Nt={queued:{cls:`bg-surface-hover text-foreground-subtle`,labelKey:`recordings.exportsSection.queued`},rendering:{cls:`bg-primary/10 text-primary`,labelKey:`recordings.exportsSection.rendering`,spin:!0},ready:{cls:`bg-success/10 text-success`,labelKey:`recordings.exportsSection.ready`},failed:{cls:`bg-danger/10 text-danger`,labelKey:`recordings.exportsSection.failed`},expired:{cls:`bg-surface-hover text-foreground-subtle`,labelKey:`recordings.exportsSection.expired`},deleted:{cls:`bg-surface-hover text-foreground-subtle`,labelKey:`recordings.exportsSection.deleted`}};function Pt(){let{data:e,isLoading:t}=ue({},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`queued`||e.state===`rendering`)?3e3:!1}),{map:r}=je(B.RecordingExportProgress,e=>e.exportId),{map:i}=je(B.RecordingExportCompleted,e=>e.exportId),{map:a}=je(B.RecordingExportFailed,e=>e.exportId);return{rows:n(()=>jt(e??[],r,i,a),[e,r,i,a]),isLoading:t}}function Ft(e){let[t,n]=s(()=>Date.now());return o(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}function It(){let{t}=Z(),r=l(),[o,c]=s(!1),u=()=>{r.invalidateQueries({queryKey:[[`recordingExport`,`listExports`]]})},d=x(),f=R().trpcClient,p=Ft(6e4),{rows:m,isLoading:g}=Pt(),[_,v]=st(),y=rt(_.get(tt)),b=n(()=>nt(m,y),[m,y]),S=n(()=>at(m,y),[m,y]),C=e=>{v(t=>{let n=new URLSearchParams(t);return e===``?n.delete(tt):n.set(tt,e),n},{replace:!0})},{data:w}=Me({isCamera:!0,projection:`slim`}),D=n(()=>{let e=new Map;for(let t of w??[])e.set(t.id,t.name);return e},[w]),O=i(()=>{r.invalidateQueries({queryKey:Mt})},[r]),k=$e({onSuccess:O}),A=De({onSuccess:O}),[j,M]=s(null),P=i(async e=>{M(e.id);try{let{url:t}=await f.recordingExport.getDownloadUrl.query({exportId:e.id}),n=await Ct(t),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.options.title??e.id}.mp4`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r),O()}finally{M(null)}},[f,O]),F=i(async e=>{await d({title:t(`recordings.exportsSection.cancelThisExport`,`Cancel this export?`),message:t(`recordings.exportsSection.stopsTheRenderThePartial`,`Stops the render. The partial file is discarded.`),confirmLabel:t(`recordings.exportsSection.cancelExport`,`Cancel export`),variant:`danger`})&&k.mutate({exportId:e.id})},[d,k,t]),L=i(async e=>{await d({title:t(`recordings.exportsSection.deleteThisExport`,`Delete this export?`),message:t(`recordings.exportsSection.permanentlyRemovesTheRenderedFile`,`Permanently removes the rendered file and its history row.`),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&A.mutate({exportId:e.id})},[d,A,t]),B=n(()=>[{key:`camera`,header:t(`recordings.exportsSection.camera`,`Camera`),render:e=>a(`span`,{className:`text-foreground`,children:D.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`created`,header:t(`recordings.exportsSection.created`,`Created`),nowrap:!0,sortValue:e=>e.createdAt,render:n=>e(`span`,{className:`text-foreground-subtle tabular-nums`,children:[new Date(n.createdAt).toLocaleString(),a(`span`,{className:`ml-1`,children:t(`recordings.exportsSection.by`,`by {{who}}`,{who:n.createdBy})})]})},{key:`title`,header:t(`recordings.exportsSection.title`,`Title`),render:e=>a(`span`,{className:`text-foreground`,children:e.options.title??`—`})},{key:`range`,header:t(`recordings.exportsSection.range`,`Range`),nowrap:!0,render:e=>a(`span`,{className:`tabular-nums`,children:kt(e.fromMs,e.toMs)})},{key:`variant`,header:t(`recordings.exportsSection.variant`,`Variant`),render:e=>a(`span`,{className:`text-foreground-subtle`,children:Dt(e.options)})},{key:`state`,header:t(`recordings.exportsSection.state`,`State`),render:n=>{let r=Nt[n.state];return e(`div`,{className:`flex flex-col gap-0.5`,children:[e(`span`,{className:`inline-flex w-fit items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${r.cls}`,children:[r.spin&&a(z,{className:`h-2.5 w-2.5 animate-spin`}),t(r.labelKey),n.state===`rendering`&&n.progressPct!==null&&e(`span`,{className:`tabular-nums`,children:[n.progressPct,`%`]})]}),n.error!==null&&a(`span`,{className:`text-[10px] text-danger`,children:n.error})]})}},{key:`expiry`,header:t(`recordings.exportsSection.expires`,`Expires`),nowrap:!0,render:e=>e.state===`deleted`?a(`span`,{className:`text-foreground-subtle`,children:`—`}):a(`span`,{className:`text-foreground-subtle tabular-nums`,children:At(e.expiresAt,p)})},{key:`downloaded`,header:t(`recordings.exportsSection.downloaded`,`Downloaded`),nowrap:!0,render:e=>a(`span`,{className:`text-foreground-subtle tabular-nums`,children:e.downloadedAt===null?`—`:new Date(e.downloadedAt).toLocaleString()})},{key:`size`,header:t(`recordings.exportsSection.size`,`Size`),align:`right`,nowrap:!0,render:e=>a(`span`,{className:`tabular-nums`,children:e.fileBytes===null?`—`:Tt(e.fileBytes)})},{key:`actions`,header:``,align:`right`,render:n=>{let r=n.state===`ready`,i=n.state===`queued`||n.state===`rendering`,o=n.state!==`deleted`;return e(`div`,{className:`flex items-center justify-end gap-1`,children:[r&&e(Y,{variant:`unstyled`,onClick:()=>{P(n)},disabled:j===n.id,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-primary/10 hover:text-foreground disabled:opacity-50`,title:t(`recordings.exportsSection.downloadMp4`,`Download MP4`),children:[j===n.id?a(z,{className:`h-3 w-3 animate-spin`}):a(I,{className:`h-3 w-3`}),t(`recordings.exportsSection.download`,`Download`)]}),i&&e(Y,{variant:`unstyled`,onClick:()=>{F(n)},disabled:k.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-warning/10 hover:text-warning disabled:opacity-50`,title:t(`recordings.exportsSection.cancelRender`,`Cancel render`),children:[a(h,{className:`h-3 w-3`}),t(`common.cancel`,`Cancel`)]}),o&&a(Y,{variant:`unstyled`,onClick:()=>{L(n)},disabled:A.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:t(`recordings.exportsSection.deleteExport`,`Delete export`),children:a(N,{className:`h-3 w-3`})})]})}}],[D,p,j,k.isPending,A.isPending,P,F,L,t]);return g&&b.length===0?e(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[a(z,{className:`h-4 w-4 animate-spin`}),t(`recordings.exportsSection.loadingExports`,`Loading exports…`)]}):e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[S.length>1||y!==null?e(T,{wrapperClassName:`mr-auto inline-block w-auto`,"aria-label":t(`recordings.exportsSection.camera`,`Camera`),value:y===null?``:String(y),onChange:e=>C(e.target.value),children:[a(`option`,{value:``,children:t(`recordings.exportsSection.allCameras`,`All cameras`)}),S.map(e=>a(`option`,{value:String(e),children:D.get(e)??`#${String(e)}`},e))]}):null,e(Y,{variant:`unstyled`,onClick:()=>c(!0),className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground`,children:[a(E,{className:`h-3.5 w-3.5`}),t(`recordings.exportsSection.newExport`,`New export`)]})]}),b.length===0&&m.length>0?a(Re,{icon:E,title:t(`recordings.exportsSection.noExportsForCamera`,`No exports for this camera`),description:t(`recordings.exportsSection.noExportsForCameraHint`,`Pick All cameras to see every export, or create one with New export.`)}):b.length===0?a(Re,{icon:E,title:t(`recordings.exportsSection.noExportsYet`,`No exports yet`),description:t(`recordings.exportsSection.createOneHereNewExport`,`Create one here (New export) or from a camera's timeline in the viewer. Rendered clips show up here to download or manage.`)}):a(et,{columns:B,rows:b,rowKey:e=>e.id,minWidthPx:720}),o&&a(xt,{onClose:()=>c(!1),onCreated:u,...y===null?{}:{initialDeviceId:y}})]})}function Lt({mediaId:e,base64:t,alt:n,className:r,placeholder:i}){let{src:o,failed:s}=St(e===void 0?void 0:wt(e));return o===null?(e===void 0||s)&&t!==void 0&&t!==``?a(`img`,{src:`data:image/jpeg;base64,${t}`,alt:n,className:r}):i:a(`img`,{src:o,alt:n,className:r})}var Rt=`pipeline-analytics`,zt=`photo.analyze`,Bt=`photo.enroll`,Vt=`photo.discard`,Ht=18*1024*1024;function Ut(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Q(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function $(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Wt(e,t){let n=e[t];return typeof n==`boolean`?n:null}function Gt(e){if(!Ut(e))return null;let t=$(e,`x`),n=$(e,`y`),r=$(e,`width`),i=$(e,`height`);return t===null||n===null||r===null||i===null?null:{x:t,y:n,width:r,height:i}}function Kt(e){if(!Ut(e))return null;let t=$(e,`detectionShortSidePx`),n=$(e,`score`);if(t===null||n===null)return null;let r=$(e,`magnitude`);return{detectionShortSidePx:t,score:n,...r===null?{}:{magnitude:r}}}function qt(e){if(!Ut(e))return null;let t=$(e,`faceIndex`),n=$(e,`score`),r=Wt(e,`enrollable`),i=Gt(e.bbox),a=Kt(e.quality);if(t===null||n===null||r===null||i===null||a===null)return null;let o=Q(e,`refusedReason`),s=Q(e,`alignedCropBase64`),c=Q(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 Jt(e){if(!Ut(e))return null;let t=Q(e,`sessionId`),n=Q(e,`ranOnNodeId`),r=e.faces;if(t===null||n===null||!Array.isArray(r))return null;let i=[];for(let e of r){let t=qt(e);t!==null&&i.push(t)}return{sessionId:t,ranOnNodeId:n,faces:i}}function Yt(e){if(!Ut(e))return null;let t=Q(e,`sampleId`),n=Q(e,`identityId`),r=Q(e,`modelId`);return t===null||n===null||r===null?null:{sampleId:t,identityId:n,modelId:r}}function Xt(e,t,n){let r={...e};return n===null||n===``?delete r[t]:r[t]=n,r}function Zt(e,t){return e.filter(e=>e.enrollable&&t[e.faceIndex]!==void 0).length}function Qt(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 $t(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 en(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 tn(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 nn(e,t,n){return e.map(e=>e.photoIndex===t?{...e,...n}:e)}function rn(e,t){return`${e}:${t}`}function an(e,t,n,r){let i=Xt(e[t]??{},n,r),a={...e};return Object.keys(i).length===0?delete a[t]:a[t]=i,a}function on(e,t){let n=0;for(let r of e)r.analysis!==void 0&&(n+=Zt(r.analysis.faces,t[r.photoIndex]??{}));return n}var sn=`__new__`;function cn(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[rn(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 ln(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[rn(e,a)]??``).trim()];s!==void 0&&(o[a]=s)}r[e]=o}return r}function un(e,t){let n=[];for(let r of e){if(r.analysis===void 0)continue;let e=Qt(r.analysis.sessionId,r.analysis.faces,t[r.photoIndex]??{});for(let t of e)n.push({photoIndex:r.photoIndex,request:t})}return n}function dn(e){return/expired/i.test(e)}function fn(e){return e instanceof Error?e.message:String(e)}async function pn(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 un(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=fn(t);if(!dn(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 (${fn(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)}: ${fn(e)}`)}}}return{enrolled:o,stampedModelId:s,failures:a,refreshedAnalyses:i}}c();var mn=[[`faceGallery`]],hn=``;function gn(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 _n(e){return e instanceof Error?e.message:String(e)}function vn({face:t,identities:r,value:i,onChange:o,disabled:s}){let{t:c}=Z(),l=n(()=>[{value:hn,label:c(`detectionIntelligence.photoEnrollDialog.ignoreThisFace`,`Ignore this face`)},...r.map(e=>({value:e.id,label:e.name})),{value:sn,label:c(`detectionIntelligence.photoEnrollDialog.newPerson`,`+ New person…`)}],[r,c]);return e(`div`,{className:`rounded-md border border-border bg-surface p-2`,children:[a(`div`,{className:`mb-2 aspect-square w-full overflow-hidden rounded border border-border bg-surface-hover`,children:t.alignedCropBase64?a(`img`,{src:`data:image/jpeg;base64,${t.alignedCropBase64}`,alt:c(`detectionIntelligence.photoEnrollDialog.face`,`Face {{value1}}`,{value1:t.faceIndex+1}),className:`h-full w-full object-cover`}):a(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:a(W,{className:`h-8 w-8`})})}),a(`div`,{className:`min-h-[4.75rem]`,children:t.enrollable?e(u,{children:[a(T,{options:l,value:i,disabled:s,onChange:e=>o(e.target.value),"aria-label":c(`detectionIntelligence.photoEnrollDialog.assignFace`,`Assign face {{value1}}`,{value1:t.faceIndex+1})}),e(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:[Math.round(t.quality.detectionShortSidePx),` px`,t.modelId?` · ${t.modelId}`:``]})]}):e(`div`,{className:`space-y-1`,children:[a(Ie,{variant:`warning`,className:`text-[10px]`,children:c(`detectionIntelligence.photoEnrollDialog.notUsable`,`Not usable`)}),a(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:$t(t.refusedReason)})]})})]})}function yn({photo:t,identities:n,draft:r,newNames:i,disabled:o,onAssign:s,onNameChange:c,onRetry:l}){let{t:u}=Z(),d=t.analysis?.faces??[],f=r[t.photoIndex]??{};return e(`div`,{className:`space-y-2`,children:[e(`div`,{className:`flex items-center gap-2 border-b border-border pb-1`,children:[a(`span`,{className:`truncate text-xs font-medium text-foreground`,children:t.filename}),t.status===`analyzing`||t.status===`queued`?e(`span`,{className:`flex items-center gap-1 text-xs text-foreground-subtle`,children:[a(z,{className:`h-3 w-3 animate-spin`}),` `,u(`detectionIntelligence.photoEnrollDialog.analysing`)]}):null,t.status===`analyzed`&&t.analysis!==void 0&&a(`span`,{className:`text-xs text-foreground-subtle`,children:u(`detectionIntelligence.photoEnrollDialog.facesAnalysedOn`,{count:d.length,node:t.analysis.ranOnNodeId})}),t.status===`failed`&&e(Y,{variant:`secondary`,size:`sm`,disabled:o,onClick:l,children:[a(A,{className:`h-3 w-3`}),` `,u(`common.retry`)]})]}),t.status===`failed`&&e(`div`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[a(y,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),e(`span`,{children:[u(`detectionIntelligence.photoEnrollDialog.thisPhotoCouldNotBe`,`This photo could not be analysed:`),` `,t.error??u(`detectionIntelligence.photoEnrollDialog.unknownError`,`unknown error`),`. The other photos are unaffected.`]})]}),t.status===`analyzed`&&d.length===0&&a(`p`,{className:`text-xs text-foreground-subtle`,children:u(`detectionIntelligence.photoEnrollDialog.noFacesWereFoundIn`,`No faces were found in this photo. A face has to be reasonably large and facing the camera for the detector to measure it.`)}),d.length>0&&a(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(7rem,7rem))] justify-start gap-3`,children:d.map(e=>a(vn,{face:e,identities:n,value:f[e.faceIndex]??hn,disabled:o,onChange:t=>s(e.faceIndex,t)},e.faceIndex))}),d.filter(e=>f[e.faceIndex]===sn).map(n=>e(`div`,{className:`flex items-center gap-2`,children:[a(`span`,{className:`w-28 shrink-0 truncate text-xs text-foreground-subtle`,children:u(`detectionIntelligence.photoEnrollDialog.faceN`,{n:n.faceIndex+1})}),a(Xe,{className:`h-7 flex-1 rounded-md border border-border bg-surface px-2.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,placeholder:u(`detectionIntelligence.photoEnrollDialog.newPersonNameTypeThe`,`New person name… (type the same name under another face to reuse it)`),value:i[rn(t.photoIndex,n.faceIndex)]??``,onChange:e=>c(n.faceIndex,e.target.value)})]},n.faceIndex))]})}function bn({open:r,onOpenChange:o}){let{t:c}=Z(),u=R(),d=l(),f=t(null),{data:p}=Ee(),m=_e(),[h,g]=s([]),[_,v]=s(!1),[b,x]=s(null),[S,C]=s({}),[w,T]=s({}),[E,D]=s(null),O=n(()=>(p??[]).map(e=>({id:e.id,name:e.name})),[p]),k=h.some(e=>e.status===`queued`||e.status===`analyzing`),A=k||_,j=i(e=>{for(let t of e){let e=t.analysis?.sessionId;e!==void 0&&u.trpcClient.addons.custom.mutate({addonId:Rt,action:Vt,input:{sessionId:e}}).catch(()=>void 0)}},[u]),M=i(()=>{g([]),C({}),T({}),x(null),D(null),f.current&&(f.current.value=``)},[]),N=i(()=>{j(h),M(),o(!1)},[j,o,h,M]),P=i(async e=>{let t=Jt(await u.trpcClient.addons.custom.mutate({addonId:Rt,action:zt,input:{photoBase64:e.photoBase64,filename:e.filename}}));if(t===null)throw Error(`the server replied with something this page could not read`);return t},[u]),F=i(async e=>{g(t=>nn(t,e.photoIndex,{status:`analyzing`,error:void 0}));try{let t=await P(e);g(n=>nn(n,e.photoIndex,{status:`analyzed`,analysis:t}))}catch(t){g(n=>nn(n,e.photoIndex,{status:`failed`,error:_n(t)}))}},[P]),I=i(async e=>{if(e.length===0)return;j(h),M();let t=en(e,{maxCount:12,maxBytes:Ht}),n=[];t.oversize.length>0&&n.push(`Over the ${Math.round(Ht/(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&&x(n.join(` `));let r;try{r=await Promise.all(t.accepted.map(async(e,t)=>({photoIndex:t,filename:e.name,photoBase64:await gn(e),status:`queued`})))}catch(e){x(_n(e));return}g(r),await tn(r,2,e=>F(e))},[j,h,M,F]),L=on(h,S),B=i(async()=>{v(!0),x(null),D(null);try{let e=cn(h,S,w);if(e.kind===`error`){x(e.message);return}let t={};for(let n of e.names)t[n]=(await m.mutateAsync({name:n})).id;let n=await pn(h,ln(S,w,t),{enroll:async e=>{let t=Yt(await u.trpcClient.addons.custom.mutate({addonId:Rt,action:Bt,input:e}));if(t===null)throw Error(`unreadable reply`);return t},reanalyze:e=>P(e)});Object.keys(n.refreshedAnalyses).length>0&&g(e=>e.map(e=>{let t=n.refreshedAnalyses[e.photoIndex];return t===void 0?e:{...e,status:`analyzed`,analysis:t}})),d.invalidateQueries({queryKey:mn}),n.failures.length>0&&x(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){x(_n(e))}finally{v(!1)}},[P,m,S,w,h,d,u]),V=h.filter(e=>e.status===`analyzed`).length;return a(Te,{open:r,onOpenChange:e=>e?o(!0):N(),children:e(ce,{className:`max-w-3xl`,children:[e(me,{children:[a(Ae,{children:c(`detectionIntelligence.photoEnrollDialog.enrolFromPhotos`,`Enrol from photos`)}),a(ge,{children:c(`detectionIntelligence.photoEnrollDialog.everyPhotoIsAnalysedWith`,`Every photo is analysed with the same face detector the cameras use, and all the faces found are reviewed below in one pass, grouped by photo. Assign each face to a person, or leave it ignored.`)})]}),a(`div`,{className:`rounded-md border border-border bg-surface-hover px-3 py-2 text-xs text-foreground-subtle`,children:a(ot,{i18nKey:`detectionIntelligence.photoEnrollDialog.reliableRecognition`,components:{strong:a(`strong`,{})}})}),e(`div`,{className:`flex items-center gap-2`,children:[a(ze,{ref:f,accept:`image/jpeg,image/png,image/webp`,multiple:!0,className:`hidden`,onChange:e=>void I(Array.from(e.target.files??[]))}),e(Y,{variant:`secondary`,size:`sm`,disabled:A,onClick:()=>f.current?.click(),children:[k?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(H,{className:`h-3.5 w-3.5`}),c(`detectionIntelligence.photoEnrollDialog.choosePhotos`,`Choose photos`)]}),h.length>0&&a(`span`,{className:`text-xs text-foreground-subtle`,children:c(`detectionIntelligence.photoEnrollDialog.photosAnalysed`,{done:V,count:h.length})})]}),a(`div`,{className:`min-h-11`,"aria-live":`polite`,children:b===null?E===null?null:a(`div`,{className:`rounded-md border border-success/40 bg-success/10 px-3 py-2 text-xs text-success`,children:E}):e(`div`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[a(y,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),a(`span`,{children:b})]})}),h.length>0&&a(`div`,{className:`max-h-[50vh] space-y-4 overflow-y-auto pr-1`,children:h.map(e=>a(yn,{photo:e,identities:O,draft:S,newNames:w,disabled:A,onAssign:(t,n)=>C(r=>an(r,e.photoIndex,t,n===hn?null:n)),onNameChange:(t,n)=>T(r=>({...r,[rn(e.photoIndex,t)]:n})),onRetry:()=>void F(e)},e.photoIndex))}),e(He,{children:[a(Y,{variant:`secondary`,onClick:N,disabled:_,children:c(`common.close`,`Close`)}),e(Y,{variant:`primary`,onClick:()=>void B(),disabled:A||L===0,children:[_?a(z,{className:`h-3.5 w-3.5 animate-spin`}):null,c(`detectionIntelligence.photoEnrollDialog.enrolFaces`,{count:L})]})]})]})})}c();var xn=[[`faceGallery`]];function Sn({identityId:t}){let{t:n}=Z(),r=l(),{data:i,isLoading:o}=le({identityId:t}),s=Oe();function c(e){s.mutate({identityId:t,sampleId:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:xn})}})}return o?e(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[a(z,{className:`h-3.5 w-3.5 animate-spin`}),n(`detectionIntelligence.peopleList.loadingSamples`,`Loading samples…`)]}):!i||i.length===0?a(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:n(`detectionIntelligence.peopleList.noSamplesYet`,`No samples yet.`)}):a(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:i.map(t=>e(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[t.base64?a(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:n(`detectionIntelligence.peopleList.sample`,`Sample`),className:`h-full w-full object-cover`}):a(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:a(W,{className:`h-6 w-6`})}),t.source===`photo`&&a(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 p-0.5 text-white`,title:n(`detectionIntelligence.peopleList.enrolledFromAnUploadedPhoto`,`Enrolled from an uploaded photo`),children:a(H,{className:`h-3 w-3`})}),a(`button`,{type:`button`,onClick:()=>c(t),disabled:s.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":n(`detectionIntelligence.peopleList.removeSample`,`Remove sample`),children:a(m,{className:`h-4 w-4 text-white`})})]},t.id))})}function Cn(t){return[{key:`person`,header:X.t(`detectionIntelligence.peopleList.person`,`Person`),sortValue:e=>e.name,render:t=>e(`span`,{className:`flex min-w-0 items-center gap-2`,children:[a(`span`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:a(Lt,{mediaId:t.coverMediaId,base64:t.coverBase64,alt:t.name,className:`h-full w-full object-cover`,placeholder:a(`span`,{className:`flex h-full w-full items-center justify-center`,children:a(W,{className:`h-4 w-4 text-foreground-subtle`})})})}),a(`span`,{className:`truncate text-sm font-medium text-foreground`,children:t.name})]})},{key:`samples`,header:X.t(`detectionIntelligence.peopleList.samples`,`Samples`),align:`center`,nowrap:!0,sortValue:e=>e.sampleCount,render:e=>a(Ie,{variant:`default`,className:`text-[10px]`,children:e.sampleCount})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:n=>e(`span`,{className:`flex items-center justify-end gap-1`,children:[a(xe,{variant:`ghost`,size:`sm`,icon:F,"aria-label":X.t(`detectionIntelligence.peopleList.edit`,`Edit {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onEdit(n)}}),a(xe,{variant:`ghost`,size:`sm`,icon:N,"aria-label":X.t(`detectionIntelligence.peopleList.delete`,`Delete {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onDelete(n)}})]})}]}function wn({mode:t,identity:n,onClose:r}){let{t:i}=Z(),c=l(),[u,d]=s(t===`edit`?n?.name??``:``),f=_e(),p=se();o(()=>{d(t===`edit`?n?.name??``:``)},[t,n?.id,n?.name]);let m=f.isPending||p.isPending,h=u.trim(),g=t===`edit`&&n!==null&&h===n.name,_=m||h.length===0||g;function v(){c.invalidateQueries({queryKey:xn})}function y(){if(!_){if(t===`new`){f.mutate({name:h},{onSuccess:()=>{v(),r()}});return}if(n===null){r();return}p.mutate({id:n.id,name:h},{onSuccess:()=>{v(),r()}})}}return a(Ue,{open:!0,onClose:r,title:t===`new`?`Add person`:`Edit ${n?.name??`person`}`,icon:W,width:t===`edit`?`xl`:`lg`,testId:`people-person-form`,footer:e(Y,{variant:`primary`,size:`sm`,type:`button`,onClick:y,disabled:_,children:[m?a(z,{className:`h-3.5 w-3.5 animate-spin`}):null,t===`new`?i(`common.add`,`Add`):i(`common.save`,`Save`)]}),children:e(`div`,{className:`space-y-4`,children:[a(Ke,{label:i(`detectionIntelligence.peopleList.name`,`Name`),required:!0,children:a(Xe,{value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&y()},placeholder:i(`detectionIntelligence.peopleList.personName`,`Person name…`),autoFocus:!0})}),t===`edit`&&n!==null&&e(`div`,{children:[a(`p`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:i(`detectionIntelligence.peopleList.trainingSamples`,`Training samples`)}),a(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:i(`detectionIntelligence.peopleList.removeASampleToDrop`,`Remove a sample to drop it from recognition training for this person.`)}),a(Sn,{identityId:n.id})]})]})})}function Tn(){let{t}=Z(),r=l(),i=x(),{data:c,isLoading:u}=Ee(),d=Qe(),{state:f,openNew:p,openEdit:m,close:h}=Be(),[g,_]=s(!1),v=c??[],y=Ce(v,{searchText:e=>[e.name]}),b=f.mode===`edit`?v.find(e=>e.id===f.id)??null:null;o(()=>{f.mode===`edit`&&!u&&b===null&&h()},[f.mode,u,b,h]);let S=n(()=>Cn({onEdit:e=>m(e.id),onDelete:e=>{(async()=>{await i({title:t(`detectionIntelligence.peopleList.deletePerson`,`Delete person`),message:t(`detectionIntelligence.peopleList.deleteAndAllTheirSamples`,`Delete {{name}} and all their samples? This cannot be undone.`,{name:e.name}),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&d.mutate({id:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:xn}),f.mode===`edit`&&f.id===e.id&&h()}})})()}}),[i,h,d,f,m,r,t]);if(u)return e(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[a(z,{className:`h-4 w-4 animate-spin`}),t(`detectionIntelligence.peopleList.loadingPeople`,`Loading people…`)]});let C=f.mode===`new`||f.mode===`edit`&&b!==null;return e(`div`,{className:`space-y-2`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(Y,{variant:`primary`,size:`sm`,type:`button`,onClick:p,children:[a(D,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.peopleList.addPerson`,`Add person`)]}),e(Y,{variant:`secondary`,size:`sm`,type:`button`,onClick:()=>_(!0),children:[a(H,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.peopleList.enrolFromAPhoto`,`Enrol from a photo`)]})]}),(v.length>0||y.active)&&a(ae,{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?a(Re,{icon:W,title:y.active?t(`detectionIntelligence.peopleList.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.peopleList.noPeopleEnrolledYet`,`No people enrolled yet`),description:y.active?t(`detectionIntelligence.peopleList.clearTheSearchOrTry`,`Clear the search or try another name.`):t(`detectionIntelligence.peopleList.addAPersonOrEnrol`,`Add a person, or enrol faces from a photo.`)}):a(et,{columns:S,rows:y.rows,rowKey:e=>e.id,maxBodyHeight:ne,emptyMessage:t(`detectionIntelligence.peopleList.noPeopleEnrolledYet2`,`No people enrolled yet.`),onRowClick:e=>m(e.id)}),C&&a(wn,{mode:f.mode===`new`?`new`:`edit`,identity:b,onClose:h}),a(bn,{open:g,onOpenChange:_})]})}function En(e){let t=e.cropUrl!==void 0&&e.cropUrl.length>0,n=e.base64!==void 0&&e.base64.length>0;return!t&&!n}function Dn(e){return e.filter(En).map(e=>e.faceId)}function On(e){let t=0;for(let n of e)En(n)&&(t+=1);return t}function kn(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}c();var An=[[`faceGallery`]];function jn({faceIds:t,identities:n,onDone:r}){let{t:i}=Z(),o=l(),c=de(),u=_e(),[d,f]=s(``),[p,m]=s(!1),[h,g]=s(null),_=t!==null&&t.length>0,v=t?.length??0;function y(){m(!1),f(``),g(null)}function b(){y(),r()}function x(e){!t||t.length===0||c.mutate({faceIds:[...t],identityId:e},{onSettled:()=>{o.invalidateQueries({queryKey:An}),b()}})}function S(){!t||!d.trim()||u.mutate({name:d.trim()},{onSuccess:e=>{e?.id&&x(e.id)},onError:()=>{o.invalidateQueries({queryKey:An}),b()}})}let C=c.isPending||u.isPending;return a(Te,{open:_,onOpenChange:e=>!e&&b(),children:e(ce,{children:[e(me,{children:[a(Ae,{children:v>1?i(`detectionIntelligence.assignDialog.assignFacesToPerson`,`Assign {{value1}} faces to person`,{value1:String(v)}):i(`detectionIntelligence.assignDialog.assignFaceToPerson`,`Assign face to person`)}),a(ge,{children:i(`detectionIntelligence.assignDialog.selectAnExistingPersonOr`,`Select an existing person or create a new one.`)})]}),a(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:n.map(t=>e(Y,{variant:`unstyled`,type:`button`,onClick:()=>g(t.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${h===t.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[a(`span`,{className:`font-medium`,children:t.name}),a(`span`,{className:`ml-2 text-foreground-subtle`,children:i(`detectionIntelligence.assignDialog.samples`,{count:t.sampleCount})})]},t.id))}),a(`div`,{className:`min-h-[2.75rem] border-t border-border pt-2`,children:p?a(`div`,{className:`flex items-center gap-2`,children:a(Xe,{placeholder:i(`detectionIntelligence.assignDialog.newPersonName`,`New person name…`),value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&S()},autoFocus:!0,className:`flex-1`})}):a(Y,{variant:`unstyled`,type:`button`,onClick:()=>{g(null),m(!0)},className:`w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle transition-colors hover:border-primary hover:text-primary`,children:i(`detectionIntelligence.assignDialog.newPerson`,`+ New person…`)})}),e(He,{className:`min-h-[2.75rem]`,children:[a(Y,{variant:`secondary`,onClick:b,disabled:C,children:i(`common.cancel`,`Cancel`)}),p?e(Y,{variant:`primary`,onClick:S,disabled:C||!d.trim(),children:[C&&a(z,{className:`h-3.5 w-3.5 animate-spin`}),i(`detectionIntelligence.assignDialog.createAssign`,`Create & assign`)]}):e(Y,{variant:`primary`,onClick:()=>h&&x(h),disabled:C||!h,children:[C&&a(z,{className:`h-3.5 w-3.5 animate-spin`}),v>1?i(`detectionIntelligence.assignCount`,{count:v}):i(`common.assign`)]})]})]})})}function Mn(e){return e<0?0:e>1?1:e}function Nn(e,t,n){if(!Number.isFinite(t)||!Number.isFinite(n)||t<=0||n<=0)return null;let r=Mn(e.x/t),i=Mn(e.y/n),a=Mn((e.x+e.w)/t),o=Mn((e.y+e.h)/n);return{x:r,y:i,width:Math.max(0,a-r),height:Math.max(0,o-i)}}c();function Pn(e){let[t,n]=s(null),[r,i]=s(null),[a,c]=s(!1);return o(()=>{if(n(null),i(null),c(!1),e===void 0)return;let t=!1,r=null;return(async()=>{try{let i=await Ct(wt(e));if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||c(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),o(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>c(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function Fn(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 In({label:t,value:n}){return e(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[a(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:t}),a(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground`,children:n})]})}function Ln({box:e}){let{t}=Z();return a(`div`,{className:`pointer-events-none absolute rounded-[3px] border-2 border-primary shadow-[0_0_0_9999px_rgba(0,0,0,0.28)]`,style:{left:`${String(e.x*100)}%`,top:`${String(e.y*100)}%`,width:`${String(e.width*100)}%`,height:`${String(e.height*100)}%`},children:a(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:t(`detectionIntelligence.faceDetailPanel.face`,`Face`)})})}function Rn({face:t,cameraName:r,onClose:i,onAssign:o,onUnassign:c,onDelete:l,actionsPending:u}){let{t:d}=Z(),{data:f,isFetching:m}=te({faceId:t?.faceId??``},{enabled:t!==null}),[h,v]=s(`frame`),{frameSrc:y,naturalWidth:b,naturalHeight:x,failed:S}=Pn(t?.keyFrameMediaId),C=n(()=>{let e=Fn(f??[]);return e?e.url:kn(t)},[f,t]),w=n(()=>!t?.faceBbox||b===null||x===null?null:Nn(t.faceBbox,b,x),[t?.faceBbox,b,x]);if(t===null)return null;let T=t.keyFrameMediaId!==void 0&&!S,E=T&&h===`frame`,D=t.assigned?t.identityName??`Assigned`:t.recognizedIdentityId?`${t.identityName??`Recognized`} (suggested)`:`Unassigned`;return a(Te,{open:!0,onOpenChange:e=>!e&&i(),children:e(ce,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":d(`detectionIntelligence.faceDetailPanel.faceDetail`,`Face detail`),className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[a(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:e(`div`,{className:`min-w-0`,children:[a(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:d(`detectionIntelligence.faceDetailPanel.faceDetail`,`Face detail`)}),a(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:r})]})}),e(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[T&&e(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[e(Y,{variant:`unstyled`,type:`button`,onClick:()=>v(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${h===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(p,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.fullFrame`)]}),e(Y,{variant:`unstyled`,type:`button`,onClick:()=>v(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${h===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(J,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.crop`)]})]}),E&&y?a(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:a(pt,{src:y,alt:d(`detectionIntelligence.faceDetailPanel.fullFrameWithDetectedFace`,`Full frame with detected face`),fit:`natural`,className:`w-full`,overlay:w?a(Ln,{box:w}):void 0})}):C?e(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[a(pt,{src:C,alt:d(`detectionIntelligence.faceDetailPanel.detectedFace`,`Detected face`),className:`h-full w-full`}),m&&a(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:a(z,{className:`h-3.5 w-3.5 animate-spin`})})]}):e(`div`,{className:`flex aspect-square w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[a(_,{className:`h-8 w-8 text-warning/70`}),a(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:d(`detectionIntelligence.faceDetailPanel.noImage`,`No image`)}),a(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:d(`detectionIntelligence.faceDetailPanel.theCropMediaForThis`,`The crop media for this face could not be resolved (a pre-fix orphan). Safe to delete.`)})]}),e(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[a(In,{label:d(`detectionIntelligence.faceDetailPanel.camera`,`Camera`),value:r}),a(In,{label:d(`detectionIntelligence.faceDetailPanel.captured`,`Captured`),value:ft(t.timestamp)}),a(In,{label:d(`detectionIntelligence.faceDetailPanel.track`,`Track`),value:t.trackId}),a(In,{label:d(`detectionIntelligence.faceDetailPanel.identity`,`Identity`),value:D})]})]}),e(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[t.assigned?e(Y,{variant:`secondary`,onClick:()=>c(t.faceId),disabled:u,children:[a(q,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.detach`)]}):e(Y,{variant:`primary`,onClick:()=>o(t.faceId),disabled:u,children:[a(g,{className:`h-3.5 w-3.5`}),` `,d(`common.assign`)]}),e(Y,{variant:`secondary`,onClick:()=>l(t.faceId),disabled:u,children:[a(N,{className:`h-3.5 w-3.5`}),` `,d(`common.delete`)]})]})]})})}function zn(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function Bn(e,t){return e.faceIds.filter(e=>!t.has(e))}function Vn(e,t){return e.faceIds.filter(e=>t(e))}c();var Hn=[[`faceGallery`]],Un=20,Wn=.3,Gn=.9,Kn=.05,qn=.5,Jn=2,Yn=10,Xn=2;function Zn({cluster:t,face:n,active:r,onSelect:i}){let{t:o}=Z(),s=kn(n);return e(Y,{variant:`unstyled`,type:`button`,onClick:i,className:`flex shrink-0 flex-col items-center gap-1.5 rounded-md border p-2 text-center transition-colors md:w-full md:flex-row md:gap-2.5 md:text-left ${r?`border-primary bg-primary/8`:`border-border bg-surface hover:bg-surface-hover`}`,children:[a(`div`,{className:`h-24 w-24 shrink-0 overflow-hidden rounded bg-surface-hover`,children:s===null?a(_,{className:`h-24 w-24 p-6 text-foreground-subtle`}):a(`img`,{src:s,alt:``,loading:`lazy`,decoding:`async`,className:`h-24 w-24 object-cover`})}),a(`span`,{className:`w-24 text-[11px] leading-tight text-foreground-subtle md:w-auto`,children:o(`detectionIntelligence.similarGroupsModal.clusterMeta`,{count:t.size,percent:Math.round(t.cohesion*100)})})]})}function Qn({face:t,cameraName:n,nowMs:r,excluded:i,onToggleExclude:o,onDelete:s,deletePending:c}){let{t:l}=Z(),u=kn(t);return e(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden transition-opacity ${i?`border-border opacity-40 grayscale`:`border-border`}`,children:[e(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[u===null?e(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,children:[a(_,{className:`h-7 w-7 text-warning/70`}),a(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:l(`detectionIntelligence.similarGroupsModal.noCrop`,`No crop`)})]}):a(pt,{src:u,alt:l(`detectionIntelligence.similarGroupsModal.faceFrom`,`Face from {{cameraName}}`,{cameraName:n}),className:`h-full w-full`}),a(Y,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),o()},className:`absolute right-1 top-1 z-10 rounded-full bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?l(`detectionIntelligence.similarGroupsModal.includeFace`,`Include face`):l(`detectionIntelligence.similarGroupsModal.excludeFace`,`Exclude face`),title:i?l(`detectionIntelligence.similarGroupsModal.include`,`Include`):l(`detectionIntelligence.similarGroupsModal.exclude`,`Exclude`),children:a(i?j:m,{className:`h-3.5 w-3.5`})})]}),e(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[a(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:n,children:n}),a(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:dt(t.timestamp,r)})]}),a(`div`,{className:`mt-1 flex min-h-[2rem] items-center justify-end border-t border-border/60 px-1 py-0.5`,children:a(Y,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),s()},disabled:c,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":l(`detectionIntelligence.similarGroupsModal.deleteFace`,`Delete face`),title:l(`detectionIntelligence.similarGroupsModal.deleteFace`,`Delete face`),children:c?a(z,{className:`h-4 w-4 animate-spin`}):a(N,{className:`h-4 w-4`})})})]})}function $n({open:t,onClose:r,byId:i,cameraName:c,nowMs:f,identities:p,selectMany:m}){let{t:h}=Z(),_=l(),y=x(),b=ye(),[S,C]=s(qn),[w,T]=s(Xn),[E,D]=s(null),[O,k]=s({}),[A,j]=s(null),{data:M,isFetching:N,refetch:P}=he({threshold:S,minClusterSize:w,limit:Un},{enabled:t}),F=M??[];o(()=>{k({})},[S,w]),o(()=>{if(F.length===0){D(null);return}F.some(e=>e.representativeFaceId===E)||D(F[0]?.representativeFaceId??null)},[F]);let I=n(()=>F.find(e=>e.representativeFaceId===E)??null,[F,E]),R=I?O[I.representativeFaceId]??new Set:new Set,B=n(()=>I?Vn(I,e=>i.has(e)):[],[I,i]),V=I?I.faceIds.length-B.length:0,H=I?Bn({...I,faceIds:B},R):[];function U(e){if(!I)return;let t=I.representativeFaceId;k(n=>({...n,[t]:zn(n[t]??new Set,e)}))}function W(){_.invalidateQueries({queryKey:Hn})}async function G(e){await y({title:h(`detectionIntelligence.similarGroupsModal.deleteFace`,`Delete face`),message:h(`detectionIntelligence.similarGroupsModal.permanentlyDeletesThisFaceCrop`,`Permanently deletes this face crop. This cannot be undone.`),confirmLabel:h(`common.delete`,`Delete`),variant:`danger`})&&b.mutate({faceId:e},{onSettled:W})}function K(){j(null),r()}function q(){H.length!==0&&(m(H),K())}return e(Te,{open:t,onOpenChange:e=>!e&&K(),children:[e(ce,{placement:`sheet-on-mobile`,width:`lg`,"aria-label":h(`detectionIntelligence.similarGroupsModal.lookAlikeGroups`,`Look-alike groups`),className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 md:max-w-4xl`,children:[e(`header`,{className:`flex shrink-0 flex-col gap-2 border-b border-border py-3 pl-4 pr-10`,children:[e(`div`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[a(L,{className:`h-4 w-4 text-primary`}),` `,h(`detectionIntelligence.similarGroupsModal.title`)]}),e(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[e(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[h(`detectionIntelligence.similarGroupsModal.threshold`,`Threshold`),a(d,{min:Wn,max:Gn,step:Kn,value:S,onChange:e=>C(Number(e.target.value)),className:`h-1.5 w-28 cursor-pointer accent-primary`}),a(`span`,{className:`w-8 shrink-0 text-right font-mono text-[11px] tabular-nums text-foreground`,children:S.toFixed(2)})]}),e(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[h(`detectionIntelligence.similarGroupsModal.minSize`,`Min size`),a(Xe,{type:`number`,min:Jn,max:Yn,step:1,value:w,onChange:e=>T(Math.min(Yn,Math.max(Jn,Number(e.target.value)||Jn))),className:`w-12 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`})]}),e(Y,{variant:`secondary`,onClick:()=>{k({}),P()},disabled:N,children:[N?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(v,{className:`h-3.5 w-3.5`}),h(`detectionIntelligence.similarGroupsModal.reAnalyze`,`Re-analyze`)]})]})]}),a(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-hidden px-4 py-3 md:flex-row`,children:N&&F.length===0?e(`div`,{className:`flex flex-1 items-center justify-center gap-2 py-8 text-xs text-foreground-subtle`,children:[a(z,{className:`h-4 w-4 animate-spin`}),` `,h(`detectionIntelligence.similarGroupsModal.finding`)]}):F.length===0?a(`div`,{className:`flex flex-1 items-center justify-center py-8 text-xs text-foreground-subtle`,children:h(`detectionIntelligence.similarGroupsModal.noLookAlikeGroupsAt`,`No look-alike groups at this threshold.`)}):e(u,{children:[a(`div`,{className:`flex gap-2 overflow-x-auto pb-1 md:hidden`,children:F.map(e=>a(Zn,{cluster:e,face:i.get(e.representativeFaceId),active:e.representativeFaceId===E,onSelect:()=>D(e.representativeFaceId)},e.representativeFaceId))}),a(`div`,{className:`hidden shrink-0 flex-col gap-2 overflow-y-auto md:flex md:w-56`,children:F.map(e=>a(Zn,{cluster:e,face:i.get(e.representativeFaceId),active:e.representativeFaceId===E,onSelect:()=>D(e.representativeFaceId)},e.representativeFaceId))}),a(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:I&&e(u,{children:[V>0&&a(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:h(`detectionIntelligence.similarGroupsModal.hiddenCount`,{count:V})}),a(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(13rem,13rem))] justify-start gap-2`,children:B.map(e=>{let t=i.get(e);return t?a(Qn,{face:t,cameraName:c(t.deviceId),nowMs:f,excluded:R.has(e),onToggleExclude:()=>U(e),onDelete:()=>void G(e),deletePending:b.isPending&&b.variables?.faceId===e},e):null})})]})})]})}),e(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[a(Y,{variant:`secondary`,onClick:q,disabled:H.length===0,children:h(`detectionIntelligence.similarGroupsModal.selectInGallery`,`Select in gallery`)}),e(Y,{variant:`primary`,onClick:()=>j(H),disabled:H.length===0,children:[a(g,{className:`h-3.5 w-3.5`}),` `,h(`detectionIntelligence.similarGroupsModal.adopt`,{count:H.length})]})]})]}),a(jn,{faceIds:A,identities:p,onDone:()=>j(null)})]})}c();var er=[[`faceGallery`]],tr=500,nr=120;function rr({face:t,cameraName:n,nowMs:r,selected:i,onToggleSelect:o,onAssign:s,onOpenDetail:c}){let{t:u}=Z(),d=l(),f=Ve(),p=ye(),m=()=>{d.invalidateQueries({queryKey:er})},h=()=>c(t.faceId),v=kn(t);return e(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[e(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[v===null?e(`button`,{type:`button`,onClick:h,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:u(`detectionIntelligence.unassignedFaces.noCropImageTheFace`,`No crop image — the face's crop media is missing (a pre-fix orphan). Safe to delete.`),children:[a(_,{className:`h-7 w-7 text-warning/70`}),a(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:u(`detectionIntelligence.unassignedFaces.noCrop`,`No crop`)})]}):a(`img`,{src:v,alt:u(`detectionIntelligence.unassignedFaces.faceFrom`,`Face from {{cameraName}}`,{cameraName:n}),onClick:h,loading:`lazy`,decoding:`async`,className:`h-full w-full cursor-zoom-in object-cover`}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(t.faceId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?u(`detectionIntelligence.unassignedFaces.deselect`,`Deselect`):u(`detectionIntelligence.unassignedFaces.select`,`Select`),children:i?a(ee,{className:`h-4 w-4 text-primary`}):a(k,{className:`h-4 w-4`})})]}),e(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[a(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:n,children:n}),a(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:dt(t.timestamp,r)}),a(`p`,{className:`min-h-[0.875rem] truncate text-[10px] font-medium leading-tight ${t.identityName?`text-primary`:`invisible`}`,title:t.identityName,children:t.identityName??`\xA0`})]}),e(`div`,{className:`mt-1 flex min-h-[2rem] items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[t.assigned?a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),f.mutate({faceId:t.faceId},{onSettled:m})},disabled:f.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":u(`detectionIntelligence.unassignedFaces.detachFace`,`Detach face`),title:u(`detectionIntelligence.unassignedFaces.detach`,`Detach`),children:f.isPending?a(z,{className:`h-4 w-4 animate-spin`}):a(q,{className:`h-4 w-4`})}):a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s(t.faceId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":u(`detectionIntelligence.unassignedFaces.assignFaceToPerson`,`Assign face to person`),title:u(`detectionIntelligence.unassignedFaces.assignToPerson`,`Assign to person`),children:a(g,{className:`h-4 w-4`})}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),p.mutate({faceId:t.faceId},{onSettled:m})},disabled:p.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":u(`detectionIntelligence.unassignedFaces.deleteFace`,`Delete face`),title:u(`detectionIntelligence.unassignedFaces.deleteFace`,`Delete face`),children:p.isPending?a(z,{className:`h-4 w-4 animate-spin`}):a(N,{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 ar(){let{t}=Z(),r=l(),[i,o]=s(`all`),[c,d]=s(_t),[f,p]=s(new Set),[h,v]=s(new Set),[y,b]=s(null),[x,S]=s(!1),[C,w]=s(null),{data:T,isLoading:E}=we({limit:tr,filter:i,includeCrops:!1},{refetchInterval:3e4}),{data:D=[]}=Ee(),{data:O}=Me({isCamera:!0,projection:`slim`}),k=de(),A=Ve(),j=pe(),M=ye(),P=Date.now(),F=T??[],I=n(()=>{let e=new Map;for(let t of O??[])e.set(t.id,t.name);return e},[O]),R=e=>I.get(e)??t(`detectionIntelligence.cameraFallback`,{id:String(e)}),B=n(()=>bt(F).map(e=>({id:e,name:R(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[F,I]),V=n(()=>ut(mt(F,c),f),[F,c,f]),H=gt(V,nr,n(()=>JSON.stringify([i,c.fromMs,c.toMs,[...f].sort((e,t)=>e-t)]),[i,c.fromMs,c.toMs,f])),U=n(()=>new Map(F.map(e=>[e.faceId,e])),[F]),W=n(()=>On(V),[V]),G=C===null?null:U.get(C)??null,K=()=>{r.invalidateQueries({queryKey:er})},J=()=>v(new Set);function ee(e){v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function te(e){v(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function ne(){te(Dn(V))}let re=[...h],ie=k.isPending||j.isPending||M.isPending,ae=A.isPending||M.isPending;function oe(){re.length!==0&&j.mutate({faceIds:re},{onSettled:()=>{K(),J()}})}function se(){re.length!==0&&Promise.allSettled(re.map(e=>M.mutateAsync({faceId:e}))).then(()=>{K(),J()})}function ce(e){w(null),b([e])}function le(e){A.mutate({faceId:e},{onSettled:K}),w(null)}function ue(e){M.mutate({faceId:e},{onSettled:K}),w(null)}let fe=V.length!==F.length;return e(`div`,{className:`relative space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[a(`div`,{className:`flex items-center gap-1`,children:ir.map(e=>a(`button`,{type:`button`,onClick:()=>o(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${i===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:t(e.labelKey)},e.value))}),a(lt,{onChange:d}),a(vt,{cameras:B,selected:f,onChange:p}),e(`button`,{type:`button`,onClick:()=>S(!0),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${x?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(L,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.similarGroups`)]}),!E&&W>0&&e(`button`,{type:`button`,onClick:ne,className:`ml-auto flex items-center gap-1 rounded-md px-2.5 py-1 text-xs text-warning/90 transition-colors hover:bg-warning/10`,title:t(`detectionIntelligence.unassignedFaces.selectEveryVisibleFaceWhose`,`Select every visible face whose crop image is missing so you can delete the orphans in one pass`),children:[a(_,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.selectCropless`,{count:W})]}),!E&&a(`span`,{className:`text-[10px] text-foreground-subtle ${W>0?`ml-2`:`ml-auto`}`,children:fe?t(`detectionIntelligence.unassignedFaces.ofFaces`,`{{value1}} of {{value2}} faces`,{value1:String(V.length),value2:String(F.length)}):t(`detectionIntelligence.unassignedFaces.faceCount`,{count:V.length})})]}),h.size>0&&e(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[a(`span`,{className:`text-xs font-medium text-foreground`,children:t(`common.selectedCount`,{count:h.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[e(Y,{variant:`primary`,onClick:()=>b(re),disabled:ie,children:[a(g,{className:`h-3.5 w-3.5`}),` `,t(`common.assign`)]}),e(Y,{variant:`secondary`,onClick:oe,disabled:ie,children:[j.isPending?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(q,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.detach`,`Detach`)]}),e(Y,{variant:`secondary`,onClick:se,disabled:ie,children:[a(N,{className:`h-3.5 w-3.5`}),` `,t(`common.delete`)]}),a(Y,{variant:`ghost`,onClick:J,disabled:ie,children:a(m,{className:`h-3.5 w-3.5`})})]})]}),E?a(Ge,{status:`pending`,pendingMessage:`Loading faces…`,testId:`faces-grid`}):V.length===0?a(Re,{icon:_,title:F.length>0?t(`detectionIntelligence.unassignedFaces.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.unassignedFaces.noFacesFoundForThis`,`No faces found for this filter`),description:F.length>0?t(`detectionIntelligence.unassignedFaces.widenTheDateRangeOr`,`Widen the date range or clear the camera filter.`):t(`detectionIntelligence.unassignedFaces.faceCropsAppearHereWhen`,`Face crops appear here when the detection pipeline captures them.`)}):e(u,{children:[a(Ge,{status:`ready`,testId:`faces-grid`,className:`grid-cols-[repeat(auto-fill,minmax(6.5rem,6.5rem))] justify-start`,children:H.pageItems.map(e=>a(rr,{face:e,cameraName:R(e.deviceId),nowMs:P,selected:h.has(e.faceId),onToggleSelect:ee,onAssign:e=>b([e]),onOpenDetail:w},e.faceId))}),a(yt,{currentPage:H.page,totalItems:H.totalItems,pageSize:H.pageSize,onPageChange:H.setPage,itemNoun:`faces`})]}),a(Rn,{face:G,cameraName:G?R(G.deviceId):``,onClose:()=>w(null),onAssign:ce,onUnassign:le,onDelete:ue,actionsPending:ae}),a(jn,{faceIds:y,identities:D,onDone:()=>{b(null),J()}}),a($n,{open:x,onClose:()=>S(!1),byId:U,cameraName:R,nowMs:P,identities:D,selectMany:te})]})}c();var or=[[`faceGallery`]],sr=2e3;function cr(){let e=l(),n=t(e);n.current=e;let r=t(void 0);r.current||=ht({delayMs:sr,invalidate:()=>{n.current.invalidateQueries({queryKey:or})}}),o(()=>()=>r.current?.cancel(),[]),ke(B.PipelineAnalyticsFaceGalleryChanged,()=>{r.current?.trigger()})}function lr(){let{t}=Z();return cr(),e(`div`,{className:`space-y-3`,children:[a(fe,{headingId:`library-people`,title:t(`detectionIntelligence.people`,`People`),icon:W,testId:`library-section-people`,children:e(`div`,{className:`${f} space-y-3`,children:[a(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`detectionIntelligence.enrolledIdentitiesUsedForFace`,`Enrolled identities used for face recognition. Open a person to rename them or remove training samples.`)}),a(Tn,{})]})}),a(fe,{headingId:`library-recent-faces`,title:t(`detectionIntelligence.recentDetectedFaces`,`Recent detected faces`),icon:U,testId:`library-section-recent-faces`,children:e(`div`,{className:`${f} space-y-3`,children:[a(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`detectionIntelligence.faceCropsCapturedByThe`,`Face crops captured by the detection pipeline. Assign them to a person to build recognition training data.`)}),a(ar,{})]})})]})}function ur(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}c();var dr=[[`plateGallery`]];function fr({plateIds:t,vehicles:n,onDone:r}){let{t:i}=Z(),o=l(),c=Ne(),u=Ze(),[d,f]=s(``),[p,m]=s(!1),[h,g]=s(null),_=t!==null&&t.length>0,v=t?.length??0;function y(){m(!1),f(``),g(null)}function b(){y(),r()}function x(e){!t||t.length===0||c.mutate({plateIds:[...t],vehicleId:e},{onSettled:()=>{o.invalidateQueries({queryKey:dr}),b()}})}function S(){!t||!d.trim()||u.mutate({name:d.trim()},{onSuccess:e=>{e?.id&&x(e.id)},onError:()=>{o.invalidateQueries({queryKey:dr}),b()}})}let C=c.isPending||u.isPending;return a(Te,{open:_,onOpenChange:e=>!e&&b(),children:e(ce,{children:[e(me,{children:[a(Ae,{children:v>1?i(`detectionIntelligence.assignPlateDialog.assignPlatesToVehicle`,`Assign {{value1}} plates to vehicle`,{value1:String(v)}):i(`detectionIntelligence.assignPlateDialog.assignPlateToVehicle`,`Assign plate to vehicle`)}),a(ge,{children:i(`detectionIntelligence.assignPlateDialog.selectAnExistingVehicleOr`,`Select an existing vehicle or create a new one.`)})]}),a(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:n.map(t=>e(Y,{variant:`unstyled`,type:`button`,onClick:()=>g(t.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${h===t.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[a(`span`,{className:`font-medium`,children:t.name}),a(`span`,{className:`ml-2 text-foreground-subtle`,children:i(`detectionIntelligence.assignPlateDialog.plates`,{count:t.sampleCount})})]},t.id))}),p?a(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:a(Xe,{placeholder:i(`detectionIntelligence.assignPlateDialog.newVehicleName`,`New vehicle name…`),value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&S()},autoFocus:!0,className:`flex-1`})}):a(Y,{variant:`unstyled`,type:`button`,onClick:()=>{g(null),m(!0)},className:`mt-2 w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle hover:border-primary hover:text-primary transition-colors`,children:i(`detectionIntelligence.assignPlateDialog.newVehicle`,`+ New vehicle…`)}),e(He,{children:[a(Y,{variant:`secondary`,onClick:b,disabled:C,children:i(`common.cancel`,`Cancel`)}),p?e(Y,{variant:`primary`,onClick:S,disabled:C||!d.trim(),children:[C&&a(z,{className:`h-3.5 w-3.5 animate-spin`}),i(`detectionIntelligence.assignPlateDialog.createAssign`,`Create & assign`)]}):e(Y,{variant:`primary`,onClick:()=>h&&x(h),disabled:C||!h,children:[C&&a(z,{className:`h-3.5 w-3.5 animate-spin`}),v>1?i(`detectionIntelligence.assignCount`,{count:v}):i(`common.assign`)]})]})]})})}c();var pr=[[`plateGallery`]];function mr(e){let[t,n]=s(null),[r,i]=s(null),[a,c]=s(!1);return o(()=>{if(n(null),i(null),c(!1),e===void 0)return;let t=!1,r=null;return(async()=>{try{let i=await Ct(wt(e));if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||c(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),o(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>c(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function hr(e){let t=e.filter(e=>e.url.length>0);return t.length===0?null:t.find(e=>/crop|plate/i.test(e.kind))??t[0]}function gr({label:t,value:n,mono:r}){return e(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[a(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:t}),a(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${r?`font-mono`:``}`,title:n,children:n})]})}function _r({box:e}){let{t}=Z();return a(`div`,{className:`pointer-events-none absolute rounded-[3px] border-2 border-primary shadow-[0_0_0_9999px_rgba(0,0,0,0.28)]`,style:{left:`${String(e.x*100)}%`,top:`${String(e.y*100)}%`,width:`${String(e.width*100)}%`,height:`${String(e.height*100)}%`},children:a(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:t(`detectionIntelligence.plateDetailPanel.plate`,`Plate`)})})}function vr({plate:t,cameraName:r,onClose:i,onAssign:c,onUnassign:u,onDelete:d,actionsPending:f}){let{t:h}=Z(),v=l(),{data:y,isFetching:b}=be({plateId:t?.plateId??``},{enabled:t!==null}),x=qe(),[S,C]=s(`frame`),[w,T]=s(!1),[E,D]=s(``),{frameSrc:O,naturalWidth:k,naturalHeight:A,failed:j}=mr(t?.keyFrameMediaId);o(()=>{T(!1),D(``),C(`frame`)},[t?.plateId]);let P=n(()=>{let e=hr(y??[]);return e?e.url:ur(t)},[y,t]),I=n(()=>!t?.plateBbox||k===null||A===null?null:Nn(t.plateBbox,k,A),[t?.plateBbox,k,A]);if(t===null)return null;let L=t.keyFrameMediaId!==void 0&&!j,R=L&&S===`frame`,B=t.assigned?t.vehicleName??`Assigned`:t.recognizedVehicleId?`${t.vehicleName??`Recognized`} (suggested)`:`Unassigned`,V=`${String(Math.round(t.score*100))}%${t.corrected?` · corrected`:``}`;function H(){t&&(D(t.text),T(!0))}function U(){if(!t)return;let e=E.trim().toUpperCase();if(!e||e===t.text){T(!1);return}x.mutate({plateId:t.plateId,text:e},{onSettled:()=>{v.invalidateQueries({queryKey:pr}),T(!1)}})}return a(Te,{open:!0,onOpenChange:e=>!e&&i(),children:e(ce,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":h(`detectionIntelligence.plateDetailPanel.plateDetail`,`Plate detail`),className:`flex h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:h-auto md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[a(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:e(`div`,{className:`min-w-0`,children:[a(`div`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:t.text||h(`detectionIntelligence.plateDetailPanel.plateDetail`,`Plate detail`)}),a(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:r})]})}),e(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[L&&e(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[e(Y,{variant:`unstyled`,type:`button`,onClick:()=>C(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${S===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(p,{className:`h-3.5 w-3.5`}),` `,h(`detectionIntelligence.detailPanel.fullFrame`)]}),e(Y,{variant:`unstyled`,type:`button`,onClick:()=>C(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${S===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(J,{className:`h-3.5 w-3.5`}),` `,h(`detectionIntelligence.detailPanel.crop`)]})]}),R&&O?a(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:a(pt,{src:O,alt:h(`detectionIntelligence.plateDetailPanel.fullFrameWithDetectedPlate`,`Full frame with detected plate`),fit:`natural`,className:`w-full`,overlay:I?a(_r,{box:I}):void 0})}):P?e(`div`,{className:`relative aspect-[2/1] w-full overflow-hidden rounded-lg border border-border bg-background`,children:[a(pt,{src:P,alt:h(`detectionIntelligence.plateDetailPanel.detectedPlate`,`Detected plate`),className:`h-full w-full`}),b&&a(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:a(z,{className:`h-3.5 w-3.5 animate-spin`})})]}):e(`div`,{className:`flex aspect-[2/1] w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[a(_,{className:`h-8 w-8 text-warning/70`}),a(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:h(`detectionIntelligence.plateDetailPanel.noImage`,`No image`)}),a(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:h(`detectionIntelligence.plateDetailPanel.theCropMediaForThis`,`The crop media for this plate could not be resolved. Safe to delete.`)})]}),a(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-2`,children:e(`div`,{className:`flex items-center justify-between gap-3`,children:[a(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:h(`detectionIntelligence.plateDetailPanel.plateText`,`Plate text`)}),w?e(`div`,{className:`flex min-w-0 flex-1 items-center justify-end gap-1.5`,children:[a(Xe,{value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`&&U(),e.key===`Escape`&&T(!1)},className:`h-7 max-w-[10rem] text-right font-mono text-xs uppercase`,autoFocus:!0}),a(Y,{variant:`unstyled`,type:`button`,onClick:U,disabled:x.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":h(`detectionIntelligence.plateDetailPanel.saveCorrectedText`,`Save corrected text`),children:x.isPending?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(M,{className:`h-3.5 w-3.5`})}),a(Y,{variant:`unstyled`,type:`button`,onClick:()=>T(!1),className:`text-foreground-subtle hover:text-foreground`,"aria-label":h(`common.cancel`,`Cancel`),children:a(m,{className:`h-3.5 w-3.5`})})]}):e(Y,{variant:`unstyled`,type:`button`,onClick:H,className:`group flex min-w-0 items-center gap-1.5`,title:h(`detectionIntelligence.plateDetailPanel.correctTheOcrReading`,`Correct the OCR reading`),children:[a(`span`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:t.text||`—`}),a(F,{className:`h-3 w-3 shrink-0 text-foreground-subtle group-hover:text-foreground`})]})]})}),e(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[a(gr,{label:h(`detectionIntelligence.plateDetailPanel.camera`,`Camera`),value:r}),a(gr,{label:h(`detectionIntelligence.plateDetailPanel.captured`,`Captured`),value:ft(t.timestamp)}),a(gr,{label:h(`detectionIntelligence.plateDetailPanel.confidence`,`Confidence`),value:V}),a(gr,{label:h(`detectionIntelligence.plateDetailPanel.vehicle`,`Vehicle`),value:B}),a(gr,{label:h(`detectionIntelligence.plateDetailPanel.track`,`Track`),value:t.trackId,mono:!0})]})]}),e(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[t.assigned?e(Y,{variant:`secondary`,onClick:()=>u(t.plateId),disabled:f,children:[a(q,{className:`h-3.5 w-3.5`}),` `,h(`detectionIntelligence.detailPanel.detach`)]}):e(Y,{variant:`primary`,onClick:()=>c(t.plateId),disabled:f,children:[a(g,{className:`h-3.5 w-3.5`}),` `,h(`common.assign`)]}),e(Y,{variant:`secondary`,onClick:()=>d(t.plateId),disabled:f,children:[a(N,{className:`h-3.5 w-3.5`}),` `,h(`common.delete`)]})]})]})})}c();var yr=[[`plateGallery`]],br=500,xr=120;function Sr({plate:t,cameraName:n,nowMs:r,selected:i,onToggleSelect:o,onAssign:s,onOpenDetail:c}){let{t:u}=Z(),d=l(),f=ve(),p=Pe(),m=()=>{d.invalidateQueries({queryKey:yr})},h=()=>c(t.plateId),v=ur(t);return e(`div`,{className:`relative flex flex-col overflow-hidden rounded-md border bg-surface ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[e(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[v===null?e(`button`,{type:`button`,onClick:h,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:u(`detectionIntelligence.recentPlates.noCropImageThePlate`,`No crop image — the plate's crop media is missing. Safe to delete.`),children:[a(_,{className:`h-7 w-7 text-warning/70`}),a(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:u(`detectionIntelligence.recentPlates.noCrop`,`No crop`)})]}):a(`img`,{src:v,alt:u(`detectionIntelligence.recentPlates.plateFrom`,`Plate {{text}} from {{cameraName}}`,{text:t.text,cameraName:n}),onClick:h,className:`h-full w-full cursor-zoom-in object-cover`}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(t.plateId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?u(`detectionIntelligence.recentPlates.deselect`,`Deselect`):u(`detectionIntelligence.recentPlates.select`,`Select`),children:i?a(ee,{className:`h-4 w-4 text-primary`}):a(k,{className:`h-4 w-4`})}),t.corrected&&e(`span`,{className:`absolute right-0 top-0 z-10 flex items-center gap-0.5 rounded-bl-md bg-primary/80 px-1 py-0.5 text-[8px] font-semibold uppercase tracking-wide text-white`,title:u(`detectionIntelligence.recentPlates.manuallyCorrected`,`Manually corrected`),children:[a(G,{className:`h-3 w-3`}),` `,u(`detectionIntelligence.recentPlates.fixed`)]})]}),e(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[a(`p`,{className:`truncate font-mono text-xs font-bold tracking-wide text-foreground`,title:t.text,children:t.text||`—`}),a(`p`,{className:`truncate text-[10px] text-foreground-subtle`,title:n,children:n}),a(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:dt(t.timestamp,r)}),t.vehicleName&&a(`p`,{className:`truncate text-[10px] font-medium text-primary`,title:t.vehicleName,children:t.vehicleName})]}),e(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[t.assigned?a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),f.mutate({plateId:t.plateId},{onSettled:m})},disabled:f.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":u(`detectionIntelligence.recentPlates.detachPlate`,`Detach plate`),title:u(`detectionIntelligence.recentPlates.detach`,`Detach`),children:f.isPending?a(z,{className:`h-4 w-4 animate-spin`}):a(q,{className:`h-4 w-4`})}):a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s(t.plateId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":u(`detectionIntelligence.recentPlates.assignPlateToVehicle`,`Assign plate to vehicle`),title:u(`detectionIntelligence.recentPlates.assignToVehicle`,`Assign to vehicle`),children:a(g,{className:`h-4 w-4`})}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),p.mutate({plateId:t.plateId},{onSettled:m})},disabled:p.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":u(`detectionIntelligence.recentPlates.deletePlate`,`Delete plate`),title:u(`detectionIntelligence.recentPlates.deletePlate`,`Delete plate`),children:p.isPending?a(z,{className:`h-4 w-4 animate-spin`}):a(N,{className:`h-4 w-4`})})]})]})}var Cr=[{labelKey:`common.all`,value:`all`},{labelKey:`detectionIntelligence.recentPlates.filterUnassigned`,value:`unassigned`},{labelKey:`detectionIntelligence.recentPlates.filterAssigned`,value:`assigned`}];function wr(e,t){return t===`unassigned`?e.filter(e=>!e.assigned):t===`assigned`?e.filter(e=>e.assigned):e}function Tr(){let{t}=Z(),r=l(),[i,o]=s(`all`),[c,d]=s(_t),[f,p]=s(new Set),[h,v]=s(new Set),[y,b]=s(null),[x,S]=s(null),{data:C,isLoading:w}=re({limit:br,includeCrops:!1},{refetchInterval:3e4}),{data:T=[]}=Se(),{data:E}=Me({isCamera:!0,projection:`slim`}),D=ve(),O=Le(),k=Pe(),A=Date.now(),j=C??[],M=n(()=>{let e=new Map;for(let t of E??[])e.set(t.id,t.name);return e},[E]),P=e=>M.get(e)??t(`detectionIntelligence.cameraFallback`,{id:String(e)}),F=n(()=>bt(j).map(e=>({id:e,name:P(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[j,M]),I=n(()=>ut(mt(wr(j,i),c),f),[j,i,c,f]),L=gt(I,xr,n(()=>JSON.stringify([i,c.fromMs,c.toMs,[...f].sort((e,t)=>e-t)]),[i,c.fromMs,c.toMs,f])),R=n(()=>new Map(j.map(e=>[e.plateId,e])),[j]),B=x===null?null:R.get(x)??null,V=()=>{r.invalidateQueries({queryKey:yr})},H=()=>v(new Set);function U(e){v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}let W=[...h],G=O.isPending||k.isPending,K=D.isPending||k.isPending;function J(){W.length!==0&&O.mutate({plateIds:W},{onSettled:()=>{V(),H()}})}function ee(){W.length!==0&&Promise.allSettled(W.map(e=>k.mutateAsync({plateId:e}))).then(()=>{V(),H()})}function te(e){S(null),b([e])}function ne(e){D.mutate({plateId:e},{onSettled:V}),S(null)}function ie(e){k.mutate({plateId:e},{onSettled:V}),S(null)}let ae=I.length!==j.length;return e(`div`,{className:`relative space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[a(`div`,{className:`flex items-center gap-1`,children:Cr.map(e=>a(`button`,{type:`button`,onClick:()=>o(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${i===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:t(e.labelKey)},e.value))}),a(lt,{onChange:d}),a(vt,{cameras:F,selected:f,onChange:p}),!w&&a(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:ae?t(`detectionIntelligence.recentPlates.ofPlates`,`{{value1}} of {{value2}} plates`,{value1:String(I.length),value2:String(j.length)}):t(`detectionIntelligence.recentPlates.plateCount`,{count:I.length})})]}),h.size>0&&e(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[a(`span`,{className:`text-xs font-medium text-foreground`,children:t(`common.selectedCount`,{count:h.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[e(Y,{variant:`primary`,onClick:()=>b(W),disabled:G,children:[a(g,{className:`h-3.5 w-3.5`}),` `,t(`common.assign`)]}),e(Y,{variant:`secondary`,onClick:J,disabled:G,children:[O.isPending?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(q,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.recentPlates.detach`,`Detach`)]}),e(Y,{variant:`secondary`,onClick:ee,disabled:G,children:[a(N,{className:`h-3.5 w-3.5`}),` `,t(`common.delete`)]}),a(Y,{variant:`ghost`,onClick:H,disabled:G,children:a(m,{className:`h-3.5 w-3.5`})})]})]}),w?a(Ge,{status:`pending`,pendingMessage:`Loading plates…`,testId:`plates-grid`}):I.length===0?a(Re,{icon:_,title:j.length>0?t(`detectionIntelligence.recentPlates.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.recentPlates.noPlatesRecognizedYet`,`No plates recognized yet`),description:j.length>0?t(`detectionIntelligence.recentPlates.widenTheDateRangeOr`,`Widen the date range or clear the camera filter.`):t(`detectionIntelligence.recentPlates.plateReadsAppearHereWhen`,`Plate reads appear here when the detection pipeline OCRs a vehicle.`)}):e(u,{children:[a(Ge,{status:`ready`,testId:`plates-grid`,children:L.pageItems.map(e=>a(Sr,{plate:e,cameraName:P(e.deviceId),nowMs:A,selected:h.has(e.plateId),onToggleSelect:U,onAssign:e=>b([e]),onOpenDetail:S},e.plateId))}),a(yt,{currentPage:L.page,totalItems:L.totalItems,pageSize:L.pageSize,onPageChange:L.setPage,itemNoun:`plates`})]}),a(vr,{plate:B,cameraName:B?P(B.deviceId):``,onClose:()=>S(null),onAssign:te,onUnassign:ne,onDelete:ie,actionsPending:K}),a(fr,{plateIds:y,vehicles:T,onDone:()=>{b(null),H()}})]})}c();var Er=[[`plateGallery`]];function Dr({vehicleId:t}){let{t:n}=Z(),r=l(),{data:i,isLoading:o}=Je({vehicleId:t}),s=oe();function c(e){s.mutate({vehicleId:t,sampleId:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:Er})}})}return o?e(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[a(z,{className:`h-3.5 w-3.5 animate-spin`}),n(`detectionIntelligence.vehiclesList.loadingPlates`,`Loading plates…`)]}):!i||i.length===0?a(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:n(`detectionIntelligence.vehiclesList.noPlatesYet`,`No plates yet.`)}):a(`div`,{className:`mt-2 grid grid-cols-3 gap-2 sm:grid-cols-4 md:grid-cols-6`,children:i.map(t=>e(`div`,{className:`group relative overflow-hidden rounded-md border border-border bg-surface`,children:[e(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[t.base64?a(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:t.text,className:`h-full w-full object-cover`}):a(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:a(S,{className:`h-6 w-6`})}),a(`button`,{type:`button`,onClick:()=>c(t),disabled:s.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":n(`detectionIntelligence.vehiclesList.removePlateSample`,`Remove plate sample`),children:a(m,{className:`h-4 w-4 text-white`})})]}),a(`p`,{className:`truncate px-1.5 py-1 text-center font-mono text-[11px] font-semibold tracking-wide text-foreground`,title:t.text,children:t.text})]},t.id))})}function Or(t){return[{key:`vehicle`,header:X.t(`detectionIntelligence.vehiclesList.vehicle`,`Vehicle`),sortValue:e=>e.name,render:t=>e(`span`,{className:`flex min-w-0 items-center gap-2`,children:[a(`span`,{className:`h-8 w-12 shrink-0 overflow-hidden rounded border border-border bg-surface-hover`,children:a(Lt,{mediaId:t.coverMediaId,base64:t.coverBase64,alt:t.name,className:`h-full w-full object-cover`,placeholder:a(`span`,{className:`flex h-full w-full items-center justify-center`,children:a(S,{className:`h-4 w-4 text-foreground-subtle`})})})}),a(`span`,{className:`truncate text-sm font-medium text-foreground`,children:t.name})]})},{key:`samples`,header:X.t(`detectionIntelligence.vehiclesList.plates`,`Plates`),align:`center`,nowrap:!0,sortValue:e=>e.sampleCount,render:e=>a(Ie,{variant:`default`,className:`text-[10px]`,children:e.sampleCount})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:n=>e(`span`,{className:`flex items-center justify-end gap-1`,children:[a(xe,{variant:`ghost`,size:`sm`,icon:F,"aria-label":X.t(`detectionIntelligence.vehiclesList.edit`,`Edit {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onEdit(n)}}),a(xe,{variant:`ghost`,size:`sm`,icon:N,"aria-label":X.t(`detectionIntelligence.vehiclesList.delete`,`Delete {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onDelete(n)}})]})}]}function kr({mode:t,vehicle:n,onClose:r}){let{t:i}=Z(),c=l(),[u,d]=s(t===`edit`?n?.name??``:``),f=Ze(),p=ie();o(()=>{d(t===`edit`?n?.name??``:``)},[t,n?.id,n?.name]);let m=f.isPending||p.isPending,h=u.trim(),g=t===`edit`&&n!==null&&h===n.name,_=m||h.length===0||g;function v(){c.invalidateQueries({queryKey:Er})}function y(){if(!_){if(t===`new`){f.mutate({name:h},{onSuccess:()=>{v(),r()}});return}if(n===null){r();return}p.mutate({id:n.id,name:h},{onSuccess:()=>{v(),r()}})}}return a(Ue,{open:!0,onClose:r,title:t===`new`?`Add vehicle`:`Edit ${n?.name??`vehicle`}`,icon:S,width:t===`edit`?`xl`:`lg`,testId:`vehicles-vehicle-form`,footer:e(Y,{variant:`primary`,size:`sm`,type:`button`,onClick:y,disabled:_,children:[m?a(z,{className:`h-3.5 w-3.5 animate-spin`}):null,t===`new`?i(`common.add`,`Add`):i(`common.save`,`Save`)]}),children:e(`div`,{className:`space-y-4`,children:[a(Ke,{label:i(`detectionIntelligence.vehiclesList.name`,`Name`),required:!0,children:a(Xe,{value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&y()},placeholder:i(`detectionIntelligence.vehiclesList.vehicleName`,`Vehicle name…`),autoFocus:!0})}),t===`edit`&&n!==null&&e(`div`,{children:[a(`p`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:i(`detectionIntelligence.vehiclesList.plateSamples`,`Plate samples`)}),a(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:i(`detectionIntelligence.vehiclesList.removeAPlateCropTo`,`Remove a plate crop to drop it from recognition for this vehicle. Assign new plates from Recent recognized plates.`)}),a(Dr,{vehicleId:n.id})]})]})})}function Ar(){let{t}=Z(),r=l(),i=x(),{data:s,isLoading:c}=Se(),u=Ye(),{state:d,openNew:f,openEdit:p,close:m}=Be(),h=s??[],g=Ce(h,{searchText:e=>[e.name]}),_=d.mode===`edit`?h.find(e=>e.id===d.id)??null:null;o(()=>{d.mode===`edit`&&!c&&_===null&&m()},[d.mode,c,_,m]);let v=n(()=>Or({onEdit:e=>p(e.id),onDelete:e=>{(async()=>{await i({title:t(`detectionIntelligence.vehiclesList.deleteVehicle`,`Delete vehicle`),message:t(`detectionIntelligence.vehiclesList.deleteAndAllItsPlate`,`Delete {{name}} and all its plate samples? This cannot be undone.`,{name:e.name}),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&u.mutate({id:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:Er}),d.mode===`edit`&&d.id===e.id&&m()}})})()}}),[i,m,u,d,p,r,t]);if(c)return e(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[a(z,{className:`h-4 w-4 animate-spin`}),t(`detectionIntelligence.vehiclesList.loadingVehicles`,`Loading vehicles…`)]});let y=d.mode===`new`||d.mode===`edit`&&_!==null;return e(`div`,{className:`space-y-2`,children:[a(`div`,{className:`flex flex-wrap items-center gap-2`,children:e(Y,{variant:`primary`,size:`sm`,type:`button`,onClick:f,children:[a(D,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.vehiclesList.addVehicle`,`Add vehicle`)]})}),(h.length>0||g.active)&&a(ae,{state:g.state,facets:g.facets,labels:{searchPlaceholder:`Search vehicles…`,searchLabel:`Search vehicles`,facetsLabel:`Filter`,clearLabel:`Clear`},onSearch:g.setSearch,onToggleFacet:g.toggleFacet,onClear:g.clear}),g.rows.length===0?a(Re,{icon:S,title:g.active?t(`detectionIntelligence.vehiclesList.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.vehiclesList.noVehiclesEnrolledYet`,`No vehicles enrolled yet`),description:g.active?t(`detectionIntelligence.vehiclesList.clearTheSearchOrTry`,`Clear the search or try another name.`):t(`detectionIntelligence.vehiclesList.addAVehicleThenAssign`,`Add a vehicle, then assign plate crops from Recent recognized plates.`)}):a(et,{columns:v,rows:g.rows,rowKey:e=>e.id,maxBodyHeight:ne,emptyMessage:t(`detectionIntelligence.vehiclesList.noVehiclesEnrolledYet2`,`No vehicles enrolled yet.`),onRowClick:e=>p(e.id)}),y&&a(kr,{mode:d.mode===`new`?`new`:`edit`,vehicle:_,onClose:m})]})}c();var jr=[[`plateGallery`]],Mr=2e3;function Nr(){let e=l(),n=t(e);n.current=e;let r=t(void 0);r.current||=ht({delayMs:Mr,invalidate:()=>{n.current.invalidateQueries({queryKey:jr})}}),o(()=>()=>r.current?.cancel(),[]),ke(B.PipelineAnalyticsPlateGalleryChanged,()=>{r.current?.trigger()})}function Pr(){let{t}=Z();return Nr(),e(`div`,{className:`space-y-3`,children:[a(fe,{headingId:`library-vehicles`,title:t(`plates.vehicles`,`Vehicles`),icon:S,testId:`library-section-vehicles`,children:e(`div`,{className:`${f} space-y-3`,children:[a(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`plates.enrolledVehicleIdentitiesUsedFor`,`Enrolled vehicle identities used for plate recognition. Open a vehicle to rename it or remove plate samples.`)}),a(Ar,{})]})}),a(fe,{headingId:`library-recent-plates`,title:t(`plates.recentRecognizedPlates`,`Recent recognized plates`),icon:K,testId:`library-section-recent-plates`,children:e(`div`,{className:`${f} space-y-3`,children:[a(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`plates.licensePlatesReadByThe`,`License plates read by the detection pipeline. Assign them to a vehicle, correct the OCR text, or delete.`)}),a(Tr,{})]})})]})}function Fr(e){return e.states.length===0?3:e.latched?0:e.verdict===`diverged`?1:e.verdict===`unknown`?2:4}function Ir(e){let t=[e.divergedAt,e.restoredAt].filter(e=>typeof e==`number`);return t.length===0?null:Math.max(...t)}function Lr(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=Fr(e.monitor)-Fr(t.monitor);if(n!==0)return n;let r=Ir(e.monitor)??-1,i=Ir(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})}c();var Rr={alarm:`danger`,ok:`success`,unknown:`default`},zr={alarm:`Alarm`,ok:`OK`,unknown:`Unknown`};function Br(e,t){let n=Ir(e);return n===null?`—`:X.t(`scenes.transitionAgo`,{duration:P(Math.max(0,t-n))})}function Vr(e){return b(e.monitor).tone}function Hr(e){let t=Number(e);return Number.isFinite(t)&&t>0?t:null}function Ur(){let{t}=Z(),i=Me({isCamera:!0,projection:`slim`}),c=n(()=>(i.data??[]).map(e=>({deviceId:e.id,deviceName:e.name})).sort((e,t)=>e.deviceName.localeCompare(t.deviceName)),[i.data]),l=n(()=>c.map(e=>e.deviceId),[c]),u=Et(l),d=n(()=>Lr(c,u.results),[c,u.results]),f=Ce(d,{searchText:e=>[e.monitor.label,e.deviceName],facetValue:Vr}),{state:p,openNew:m,openEdit:h,close:g}=Be(),[_,v]=s(null);o(()=>{if(p.mode===`new`){v(e=>e??l[0]??null);return}v(null)},[p.mode,l]);let y=p.mode===`edit`?Hr(p.id):null,x=y===null?``:c.find(e=>e.deviceId===y)?.deviceName??`#${y}`,S=Date.now(),E=[{key:`label`,header:t(`scenes.scene`,`Scene`),sortValue:e=>e.monitor.label,render:e=>a(`span`,{className:`font-medium`,children:e.monitor.label})},{key:`camera`,header:t(`scenes.camera`,`Camera`),nowrap:!0,sortValue:e=>e.deviceName,render:e=>e.deviceName},{key:`state`,header:t(`scenes.state`,`State`),nowrap:!0,sortValue:e=>Vr(e),render:e=>{let t=b(e.monitor);return a(Ie,{variant:Rr[t.tone],children:t.text})}},{key:`status`,header:t(`scenes.whatItSays`,`What it says`),notSortableReason:`Status is a live sentence, not a comparable value`,render:e=>a(`span`,{className:`text-xs text-foreground-muted`,children:C(e.monitor,S)})},{key:`coverage`,header:t(`scenes.variants`,`Variants`),notSortableReason:`Coverage is a summary string`,render:e=>a(`span`,{className:`text-xs text-foreground-muted`,children:O(e.monitor)})},{key:`transition`,header:t(`scenes.lastChange`,`Last change`),align:`right`,nowrap:!0,sortValue:e=>Ir(e.monitor)??0,render:e=>a(`span`,{className:`text-xs tabular-nums text-foreground-muted`,children:Br(e.monitor,S)})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:e=>a(Y,{variant:`ghost`,onClick:()=>h(String(e.deviceId)),children:t(`scenes.open`,`Open`)})}];return e(`section`,{className:`space-y-3`,children:[e(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between sm:gap-4`,children:[a(`p`,{className:`text-xs text-foreground-subtle`,children:t(`scenes.aSceneWatchesOneRegion`,`A scene watches one region of one camera and tells you when it stops looking like the picture you captured — a wheelie bin, a gate, a parking space.`)}),e(Y,{onClick:m,disabled:c.length===0,className:`shrink-0`,children:[a(D,{className:`mr-1 h-3.5 w-3.5`}),t(`scenes.newScene`,`New scene`)]})]}),u.unreachableCount>0?a(`p`,{className:`text-xs text-warning`,children:t(`scenes.unreachable`,{count:u.unreachableCount})}):null,(d.length>0||f.active)&&a(ae,{state:f.state,facets:f.facets,labels:{searchPlaceholder:`Search scenes…`,searchLabel:`Search scenes`,facetsLabel:`State`,clearLabel:`Clear`},facetLabel:e=>zr[e]??e,onSearch:f.setSearch,onToggleFacet:f.toggleFacet,onClear:f.clear}),a(Fe,{variant:`flat`,className:`p-0`,children:a(et,{columns:E,rows:f.rows,rowKey:e=>`${e.deviceId}:${e.monitor.id}`,minWidthPx:880,bordered:!1,maxBodyHeight:ne,emptyMessage:u.isLoading?t(`scenes.loadingScenes`,`Loading scenes…`):f.active?t(`scenes.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`scenes.noScenesYetPressNew`,`No scenes yet. Press “New scene”, pick a camera, then draw a box around the thing you want watched.`)})}),p.mode===`new`?e(Ue,{open:!0,onClose:g,title:t(`scenes.whichCamera`,`Which camera?`),icon:w,width:`sm`,testId:`scenes-camera-picker`,footer:a(Y,{onClick:()=>{_!==null&&h(String(_))},disabled:_===null,children:t(`scenes.continue`,`Continue`)}),children:[a(`p`,{className:`mb-3 text-xs text-foreground-subtle`,children:t(`scenes.aSceneLivesOnOne`,`A scene lives on one camera. Pick the one that can see the thing.`)}),a(T,{value:_===null?``:String(_),onChange:e=>v(Number(e.target.value)),"aria-label":t(`scenes.camera`,`Camera`),options:c.map(e=>({value:String(e.deviceId),label:e.deviceName}))})]}):null,y===null?null:e(Ue,{open:!0,onClose:g,title:t(`scenes.scenes`,`Scenes — {{editingName}}`,{editingName:x}),icon:w,width:`lg`,testId:`scenes-editor`,children:[a(`p`,{className:`mb-3 text-xs text-foreground-subtle`,children:t(`scenes.drawABoxNameIt`,`Draw a box, name it, then capture what “normal” looks like. Daylight is enough — the night reference is optional, and “Settings” on each scene tunes how fussy and how often it checks.`)}),a(r,{fallback:a(`p`,{className:`text-xs text-foreground-muted`,children:t(`scenes.loadingTheEditor`,`Loading the editor…`)}),children:a(We,{deviceId:y})})]})]})}function Wr(){let{t:e}=Z(),t=it(`/library`,{t:e,isAdmin:!0})??{icon:V,title:e(`nav.library`,`Library`)};return a(ct,{icon:t.icon,title:t.title,subtitle:e(`library.subtitleWithExports`,`People, vehicles, scenes and exports — what detection has recognised, and the clips you rendered.`),defaultSection:`people`,sectionsLabel:`${t.title} sections`,sections:[{id:`people`,label:e(`library.people`,`People`),content:a(lr,{})},{id:`vehicles`,label:e(`library.vehicles`,`Vehicles`),content:a(Pr,{})},{id:`scenes`,label:e(`library.scenes`,`Scenes`),content:a(Ur,{})},{id:`exports`,label:e(`library.exports`,`Exports`),content:a(It,{}),ownedParams:[tt]}]})}export{Wr as LibraryPage};
|
|
1
|
+
import{C as e,J as t,K as n,Q as r,R as i,S as a,V as o,Y as s,et as c,o as l,x as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$a as d,D as f,Hn as p,Tt as m,Wi as h,Wt as g,Xr as _,Yn as v,Zt as y,c as b,ct as x,da as S,f as C,fa as w,ft as T,hi as E,ir as D,l as O,mn as k,qn as A,qt as j,sa as M,tn as N,u as P,ur as F,wi as I,yn as L,yt as R,zr as z}from"./player-overlays-D546iNTv.js";import{ll as B}from"./client-DQzHwaNb.js";import{s as V}from"./terminal-DZ5OZpgC.js";import{a as H,i as U,n as W,o as G,r as K,t as q}from"./user-x-DkWcmF99.js";import{t as J}from"./crop-B-t0rzRY.js";import{t as ee}from"./square-check-big-DAcFGNUN.js";import{Bc as te,Br as ne,Cd as re,Dd as ie,Dr as ae,Ed as oe,Gc as se,Gi as ce,Hc as le,Hd as ue,Ic as de,Ir as fe,Jc as pe,Ji as me,Kc as he,Ki as ge,Lc as _e,Od as ve,Rc as ye,Sd as be,Sp as xe,Td as Se,Tr as Ce,Uc as we,Ui as Te,Vc as Ee,Vd as De,Wc as Oe,Xp as ke,Yi as Ae,Yp as je,Zs as Me,_d as Ne,bd as Pe,ia as Fe,ka as Ie,kd as Le,la as Re,mi as ze,nt as Be,pp as Y,qc as Ve,qi as He,rt as Ue,t as We,tt as Ge,ut as Ke,vd as qe,wd as Je,xd as Ye,xp as Xe,yd as Ze,zc as Qe,zd as $e,zr as et}from"./src-C9_yKHH3.js";import{t as X}from"./i18n-HSlX-YO0.js";import{t as Z}from"./useTranslation-BJr-n0es.js";import{Ai as tt,Mi as nt,Ni as rt,b as it,ji as at,vi as ot,wi as st}from"./index-BN2PojUq.js";import{t as ct}from"./AdminSectionedPage-3F0XiS4h.js";import{a as lt,c as ut,d as dt,f as ft,i as pt,l as mt,m as ht,n as gt,o as _t,p as vt,r as yt,s as bt,t as xt}from"./NewExportModal-DQLl3C3Q.js";import{a as St,n as Ct,r as wt}from"./authed-media-ChKbSmi3.js";import{t as Tt}from"./format-size-DIxKXxtj.js";import{t as Et}from"./use-scenes-feed-D9kXSeA2.js";c();function Dt(e){let t=[];return e.timelapse?t.push(`timelapse ${String(e.timelapse.everyMs/1e3)}s`):(t.push(`${String(e.speed??1)}×`),e.includeAudio&&t.push(`+ audio`)),t.join(` `)}function Ot(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}function kt(e,t){let n=Math.max(0,Math.round((t-e)/1e3)),r=Math.floor(n/3600),i=Math.floor(n%3600/60),a=n%60,o=r>0?`${String(r)}:${String(i).padStart(2,`0`)}:${String(a).padStart(2,`0`)}`:`${String(i)}:${String(a).padStart(2,`0`)}`;return`${Ot(e)} · ${o}`}function At(e,t){let n=e-t;if(n<=0)return X.t(`helpers.exportFormat.expired`);let r=Math.floor(n/6e4);if(r<60)return X.t(`helpers.exportFormat.inMinutes`,{n:String(r)});let i=Math.floor(r/60);return i<24?X.t(`helpers.exportFormat.inHours`,{n:String(i)}):X.t(`helpers.exportFormat.inDays`,{n:String(Math.floor(i/24))})}function jt(e,t,n,r){return e.map(e=>{if(e.state===`expired`||e.state===`deleted`)return e;let i=r.get(e.id);if(i)return{...e,state:`failed`,error:i.error,progressPct:null};let a=n.get(e.id);if(a)return{...e,state:`ready`,fileBytes:a.fileBytes,progressPct:100};let o=t.get(e.id);return o&&(e.state===`queued`||e.state===`rendering`)?{...e,state:`rendering`,progressPct:o.progressPct}:e})}var Mt=[[`recordingExport`]],Nt={queued:{cls:`bg-surface-hover text-foreground-subtle`,labelKey:`recordings.exportsSection.queued`},rendering:{cls:`bg-primary/10 text-primary`,labelKey:`recordings.exportsSection.rendering`,spin:!0},ready:{cls:`bg-success/10 text-success`,labelKey:`recordings.exportsSection.ready`},failed:{cls:`bg-danger/10 text-danger`,labelKey:`recordings.exportsSection.failed`},expired:{cls:`bg-surface-hover text-foreground-subtle`,labelKey:`recordings.exportsSection.expired`},deleted:{cls:`bg-surface-hover text-foreground-subtle`,labelKey:`recordings.exportsSection.deleted`}};function Pt(){let{data:e,isLoading:t}=ue({},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`queued`||e.state===`rendering`)?3e3:!1}),{map:r}=je(B.RecordingExportProgress,e=>e.exportId),{map:i}=je(B.RecordingExportCompleted,e=>e.exportId),{map:a}=je(B.RecordingExportFailed,e=>e.exportId);return{rows:n(()=>jt(e??[],r,i,a),[e,r,i,a]),isLoading:t}}function Ft(e){let[t,n]=s(()=>Date.now());return o(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}function It(){let{t}=Z(),r=l(),[o,c]=s(!1),u=()=>{r.invalidateQueries({queryKey:[[`recordingExport`,`listExports`]]})},d=x(),f=R().trpcClient,p=Ft(6e4),{rows:m,isLoading:g}=Pt(),[_,v]=st(),y=rt(_.get(tt)),b=n(()=>nt(m,y),[m,y]),S=n(()=>at(m,y),[m,y]),C=e=>{v(t=>{let n=new URLSearchParams(t);return e===``?n.delete(tt):n.set(tt,e),n},{replace:!0})},{data:w}=Me({isCamera:!0,projection:`slim`}),D=n(()=>{let e=new Map;for(let t of w??[])e.set(t.id,t.name);return e},[w]),O=i(()=>{r.invalidateQueries({queryKey:Mt})},[r]),k=$e({onSuccess:O}),A=De({onSuccess:O}),[j,M]=s(null),P=i(async e=>{M(e.id);try{let{url:t}=await f.recordingExport.getDownloadUrl.query({exportId:e.id}),n=await Ct(t),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.options.title??e.id}.mp4`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r),O()}finally{M(null)}},[f,O]),F=i(async e=>{await d({title:t(`recordings.exportsSection.cancelThisExport`,`Cancel this export?`),message:t(`recordings.exportsSection.stopsTheRenderThePartial`,`Stops the render. The partial file is discarded.`),confirmLabel:t(`recordings.exportsSection.cancelExport`,`Cancel export`),variant:`danger`})&&k.mutate({exportId:e.id})},[d,k,t]),L=i(async e=>{await d({title:t(`recordings.exportsSection.deleteThisExport`,`Delete this export?`),message:t(`recordings.exportsSection.permanentlyRemovesTheRenderedFile`,`Permanently removes the rendered file and its history row.`),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&A.mutate({exportId:e.id})},[d,A,t]),B=n(()=>[{key:`camera`,header:t(`recordings.exportsSection.camera`,`Camera`),render:e=>a(`span`,{className:`text-foreground`,children:D.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`created`,header:t(`recordings.exportsSection.created`,`Created`),nowrap:!0,sortValue:e=>e.createdAt,render:n=>e(`span`,{className:`text-foreground-subtle tabular-nums`,children:[new Date(n.createdAt).toLocaleString(),a(`span`,{className:`ml-1`,children:t(`recordings.exportsSection.by`,`by {{who}}`,{who:n.createdBy})})]})},{key:`title`,header:t(`recordings.exportsSection.title`,`Title`),render:e=>a(`span`,{className:`text-foreground`,children:e.options.title??`—`})},{key:`range`,header:t(`recordings.exportsSection.range`,`Range`),nowrap:!0,render:e=>a(`span`,{className:`tabular-nums`,children:kt(e.fromMs,e.toMs)})},{key:`variant`,header:t(`recordings.exportsSection.variant`,`Variant`),render:e=>a(`span`,{className:`text-foreground-subtle`,children:Dt(e.options)})},{key:`state`,header:t(`recordings.exportsSection.state`,`State`),render:n=>{let r=Nt[n.state];return e(`div`,{className:`flex flex-col gap-0.5`,children:[e(`span`,{className:`inline-flex w-fit items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${r.cls}`,children:[r.spin&&a(z,{className:`h-2.5 w-2.5 animate-spin`}),t(r.labelKey),n.state===`rendering`&&n.progressPct!==null&&e(`span`,{className:`tabular-nums`,children:[n.progressPct,`%`]})]}),n.error!==null&&a(`span`,{className:`text-[10px] text-danger`,children:n.error})]})}},{key:`expiry`,header:t(`recordings.exportsSection.expires`,`Expires`),nowrap:!0,render:e=>e.state===`deleted`?a(`span`,{className:`text-foreground-subtle`,children:`—`}):a(`span`,{className:`text-foreground-subtle tabular-nums`,children:At(e.expiresAt,p)})},{key:`downloaded`,header:t(`recordings.exportsSection.downloaded`,`Downloaded`),nowrap:!0,render:e=>a(`span`,{className:`text-foreground-subtle tabular-nums`,children:e.downloadedAt===null?`—`:new Date(e.downloadedAt).toLocaleString()})},{key:`size`,header:t(`recordings.exportsSection.size`,`Size`),align:`right`,nowrap:!0,render:e=>a(`span`,{className:`tabular-nums`,children:e.fileBytes===null?`—`:Tt(e.fileBytes)})},{key:`actions`,header:``,align:`right`,render:n=>{let r=n.state===`ready`,i=n.state===`queued`||n.state===`rendering`,o=n.state!==`deleted`;return e(`div`,{className:`flex items-center justify-end gap-1`,children:[r&&e(Y,{variant:`unstyled`,onClick:()=>{P(n)},disabled:j===n.id,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-primary/10 hover:text-foreground disabled:opacity-50`,title:t(`recordings.exportsSection.downloadMp4`,`Download MP4`),children:[j===n.id?a(z,{className:`h-3 w-3 animate-spin`}):a(I,{className:`h-3 w-3`}),t(`recordings.exportsSection.download`,`Download`)]}),i&&e(Y,{variant:`unstyled`,onClick:()=>{F(n)},disabled:k.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-warning/10 hover:text-warning disabled:opacity-50`,title:t(`recordings.exportsSection.cancelRender`,`Cancel render`),children:[a(h,{className:`h-3 w-3`}),t(`common.cancel`,`Cancel`)]}),o&&a(Y,{variant:`unstyled`,onClick:()=>{L(n)},disabled:A.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:t(`recordings.exportsSection.deleteExport`,`Delete export`),children:a(N,{className:`h-3 w-3`})})]})}}],[D,p,j,k.isPending,A.isPending,P,F,L,t]);return g&&b.length===0?e(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[a(z,{className:`h-4 w-4 animate-spin`}),t(`recordings.exportsSection.loadingExports`,`Loading exports…`)]}):e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[S.length>1||y!==null?e(T,{wrapperClassName:`mr-auto inline-block w-auto`,"aria-label":t(`recordings.exportsSection.camera`,`Camera`),value:y===null?``:String(y),onChange:e=>C(e.target.value),children:[a(`option`,{value:``,children:t(`recordings.exportsSection.allCameras`,`All cameras`)}),S.map(e=>a(`option`,{value:String(e),children:D.get(e)??`#${String(e)}`},e))]}):null,e(Y,{variant:`unstyled`,onClick:()=>c(!0),className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground`,children:[a(E,{className:`h-3.5 w-3.5`}),t(`recordings.exportsSection.newExport`,`New export`)]})]}),b.length===0&&m.length>0?a(Re,{icon:E,title:t(`recordings.exportsSection.noExportsForCamera`,`No exports for this camera`),description:t(`recordings.exportsSection.noExportsForCameraHint`,`Pick All cameras to see every export, or create one with New export.`)}):b.length===0?a(Re,{icon:E,title:t(`recordings.exportsSection.noExportsYet`,`No exports yet`),description:t(`recordings.exportsSection.createOneHereNewExport`,`Create one here (New export) or from a camera's timeline in the viewer. Rendered clips show up here to download or manage.`)}):a(et,{columns:B,rows:b,rowKey:e=>e.id,minWidthPx:720}),o&&a(xt,{onClose:()=>c(!1),onCreated:u,...y===null?{}:{initialDeviceId:y}})]})}function Lt({mediaId:e,base64:t,alt:n,className:r,placeholder:i}){let{src:o,failed:s}=St(e===void 0?void 0:wt(e));return o===null?(e===void 0||s)&&t!==void 0&&t!==``?a(`img`,{src:`data:image/jpeg;base64,${t}`,alt:n,className:r}):i:a(`img`,{src:o,alt:n,className:r})}var Rt=`pipeline-analytics`,zt=`photo.analyze`,Bt=`photo.enroll`,Vt=`photo.discard`,Ht=18*1024*1024;function Ut(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Q(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function $(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Wt(e,t){let n=e[t];return typeof n==`boolean`?n:null}function Gt(e){if(!Ut(e))return null;let t=$(e,`x`),n=$(e,`y`),r=$(e,`width`),i=$(e,`height`);return t===null||n===null||r===null||i===null?null:{x:t,y:n,width:r,height:i}}function Kt(e){if(!Ut(e))return null;let t=$(e,`detectionShortSidePx`),n=$(e,`score`);if(t===null||n===null)return null;let r=$(e,`magnitude`);return{detectionShortSidePx:t,score:n,...r===null?{}:{magnitude:r}}}function qt(e){if(!Ut(e))return null;let t=$(e,`faceIndex`),n=$(e,`score`),r=Wt(e,`enrollable`),i=Gt(e.bbox),a=Kt(e.quality);if(t===null||n===null||r===null||i===null||a===null)return null;let o=Q(e,`refusedReason`),s=Q(e,`alignedCropBase64`),c=Q(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 Jt(e){if(!Ut(e))return null;let t=Q(e,`sessionId`),n=Q(e,`ranOnNodeId`),r=e.faces;if(t===null||n===null||!Array.isArray(r))return null;let i=[];for(let e of r){let t=qt(e);t!==null&&i.push(t)}return{sessionId:t,ranOnNodeId:n,faces:i}}function Yt(e){if(!Ut(e))return null;let t=Q(e,`sampleId`),n=Q(e,`identityId`),r=Q(e,`modelId`);return t===null||n===null||r===null?null:{sampleId:t,identityId:n,modelId:r}}function Xt(e,t,n){let r={...e};return n===null||n===``?delete r[t]:r[t]=n,r}function Zt(e,t){return e.filter(e=>e.enrollable&&t[e.faceIndex]!==void 0).length}function Qt(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 $t(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 en(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 tn(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 nn(e,t,n){return e.map(e=>e.photoIndex===t?{...e,...n}:e)}function rn(e,t){return`${e}:${t}`}function an(e,t,n,r){let i=Xt(e[t]??{},n,r),a={...e};return Object.keys(i).length===0?delete a[t]:a[t]=i,a}function on(e,t){let n=0;for(let r of e)r.analysis!==void 0&&(n+=Zt(r.analysis.faces,t[r.photoIndex]??{}));return n}var sn=`__new__`;function cn(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[rn(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 ln(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[rn(e,a)]??``).trim()];s!==void 0&&(o[a]=s)}r[e]=o}return r}function un(e,t){let n=[];for(let r of e){if(r.analysis===void 0)continue;let e=Qt(r.analysis.sessionId,r.analysis.faces,t[r.photoIndex]??{});for(let t of e)n.push({photoIndex:r.photoIndex,request:t})}return n}function dn(e){return/expired/i.test(e)}function fn(e){return e instanceof Error?e.message:String(e)}async function pn(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 un(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=fn(t);if(!dn(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 (${fn(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)}: ${fn(e)}`)}}}return{enrolled:o,stampedModelId:s,failures:a,refreshedAnalyses:i}}c();var mn=[[`faceGallery`]],hn=``;function gn(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 _n(e){return e instanceof Error?e.message:String(e)}function vn({face:t,identities:r,value:i,onChange:o,disabled:s}){let{t:c}=Z(),l=n(()=>[{value:hn,label:c(`detectionIntelligence.photoEnrollDialog.ignoreThisFace`,`Ignore this face`)},...r.map(e=>({value:e.id,label:e.name})),{value:sn,label:c(`detectionIntelligence.photoEnrollDialog.newPerson`,`+ New person…`)}],[r,c]);return e(`div`,{className:`rounded-md border border-border bg-surface p-2`,children:[a(`div`,{className:`mb-2 aspect-square w-full overflow-hidden rounded border border-border bg-surface-hover`,children:t.alignedCropBase64?a(`img`,{src:`data:image/jpeg;base64,${t.alignedCropBase64}`,alt:c(`detectionIntelligence.photoEnrollDialog.face`,`Face {{value1}}`,{value1:t.faceIndex+1}),className:`h-full w-full object-cover`}):a(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:a(W,{className:`h-8 w-8`})})}),a(`div`,{className:`min-h-[4.75rem]`,children:t.enrollable?e(u,{children:[a(T,{options:l,value:i,disabled:s,onChange:e=>o(e.target.value),"aria-label":c(`detectionIntelligence.photoEnrollDialog.assignFace`,`Assign face {{value1}}`,{value1:t.faceIndex+1})}),e(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:[Math.round(t.quality.detectionShortSidePx),` px`,t.modelId?` · ${t.modelId}`:``]})]}):e(`div`,{className:`space-y-1`,children:[a(Ie,{variant:`warning`,className:`text-[10px]`,children:c(`detectionIntelligence.photoEnrollDialog.notUsable`,`Not usable`)}),a(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:$t(t.refusedReason)})]})})]})}function yn({photo:t,identities:n,draft:r,newNames:i,disabled:o,onAssign:s,onNameChange:c,onRetry:l}){let{t:u}=Z(),d=t.analysis?.faces??[],f=r[t.photoIndex]??{};return e(`div`,{className:`space-y-2`,children:[e(`div`,{className:`flex items-center gap-2 border-b border-border pb-1`,children:[a(`span`,{className:`truncate text-xs font-medium text-foreground`,children:t.filename}),t.status===`analyzing`||t.status===`queued`?e(`span`,{className:`flex items-center gap-1 text-xs text-foreground-subtle`,children:[a(z,{className:`h-3 w-3 animate-spin`}),` `,u(`detectionIntelligence.photoEnrollDialog.analysing`)]}):null,t.status===`analyzed`&&t.analysis!==void 0&&a(`span`,{className:`text-xs text-foreground-subtle`,children:u(`detectionIntelligence.photoEnrollDialog.facesAnalysedOn`,{count:d.length,node:t.analysis.ranOnNodeId})}),t.status===`failed`&&e(Y,{variant:`secondary`,size:`sm`,disabled:o,onClick:l,children:[a(A,{className:`h-3 w-3`}),` `,u(`common.retry`)]})]}),t.status===`failed`&&e(`div`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[a(y,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),e(`span`,{children:[u(`detectionIntelligence.photoEnrollDialog.thisPhotoCouldNotBe`,`This photo could not be analysed:`),` `,t.error??u(`detectionIntelligence.photoEnrollDialog.unknownError`,`unknown error`),`. The other photos are unaffected.`]})]}),t.status===`analyzed`&&d.length===0&&a(`p`,{className:`text-xs text-foreground-subtle`,children:u(`detectionIntelligence.photoEnrollDialog.noFacesWereFoundIn`,`No faces were found in this photo. A face has to be reasonably large and facing the camera for the detector to measure it.`)}),d.length>0&&a(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(7rem,7rem))] justify-start gap-3`,children:d.map(e=>a(vn,{face:e,identities:n,value:f[e.faceIndex]??hn,disabled:o,onChange:t=>s(e.faceIndex,t)},e.faceIndex))}),d.filter(e=>f[e.faceIndex]===sn).map(n=>e(`div`,{className:`flex items-center gap-2`,children:[a(`span`,{className:`w-28 shrink-0 truncate text-xs text-foreground-subtle`,children:u(`detectionIntelligence.photoEnrollDialog.faceN`,{n:n.faceIndex+1})}),a(Xe,{className:`h-7 flex-1 rounded-md border border-border bg-surface px-2.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,placeholder:u(`detectionIntelligence.photoEnrollDialog.newPersonNameTypeThe`,`New person name… (type the same name under another face to reuse it)`),value:i[rn(t.photoIndex,n.faceIndex)]??``,onChange:e=>c(n.faceIndex,e.target.value)})]},n.faceIndex))]})}function bn({open:r,onOpenChange:o}){let{t:c}=Z(),u=R(),d=l(),f=t(null),{data:p}=Ee(),m=_e(),[h,g]=s([]),[_,v]=s(!1),[b,x]=s(null),[S,C]=s({}),[w,T]=s({}),[E,D]=s(null),O=n(()=>(p??[]).map(e=>({id:e.id,name:e.name})),[p]),k=h.some(e=>e.status===`queued`||e.status===`analyzing`),A=k||_,j=i(e=>{for(let t of e){let e=t.analysis?.sessionId;e!==void 0&&u.trpcClient.addons.custom.mutate({addonId:Rt,action:Vt,input:{sessionId:e}}).catch(()=>void 0)}},[u]),M=i(()=>{g([]),C({}),T({}),x(null),D(null),f.current&&(f.current.value=``)},[]),N=i(()=>{j(h),M(),o(!1)},[j,o,h,M]),P=i(async e=>{let t=Jt(await u.trpcClient.addons.custom.mutate({addonId:Rt,action:zt,input:{photoBase64:e.photoBase64,filename:e.filename}}));if(t===null)throw Error(`the server replied with something this page could not read`);return t},[u]),F=i(async e=>{g(t=>nn(t,e.photoIndex,{status:`analyzing`,error:void 0}));try{let t=await P(e);g(n=>nn(n,e.photoIndex,{status:`analyzed`,analysis:t}))}catch(t){g(n=>nn(n,e.photoIndex,{status:`failed`,error:_n(t)}))}},[P]),I=i(async e=>{if(e.length===0)return;j(h),M();let t=en(e,{maxCount:12,maxBytes:Ht}),n=[];t.oversize.length>0&&n.push(`Over the ${Math.round(Ht/(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&&x(n.join(` `));let r;try{r=await Promise.all(t.accepted.map(async(e,t)=>({photoIndex:t,filename:e.name,photoBase64:await gn(e),status:`queued`})))}catch(e){x(_n(e));return}g(r),await tn(r,2,e=>F(e))},[j,h,M,F]),L=on(h,S),B=i(async()=>{v(!0),x(null),D(null);try{let e=cn(h,S,w);if(e.kind===`error`){x(e.message);return}let t={};for(let n of e.names)t[n]=(await m.mutateAsync({name:n})).id;let n=await pn(h,ln(S,w,t),{enroll:async e=>{let t=Yt(await u.trpcClient.addons.custom.mutate({addonId:Rt,action:Bt,input:e}));if(t===null)throw Error(`unreadable reply`);return t},reanalyze:e=>P(e)});Object.keys(n.refreshedAnalyses).length>0&&g(e=>e.map(e=>{let t=n.refreshedAnalyses[e.photoIndex];return t===void 0?e:{...e,status:`analyzed`,analysis:t}})),d.invalidateQueries({queryKey:mn}),n.failures.length>0&&x(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){x(_n(e))}finally{v(!1)}},[P,m,S,w,h,d,u]),V=h.filter(e=>e.status===`analyzed`).length;return a(Te,{open:r,onOpenChange:e=>e?o(!0):N(),children:e(ce,{className:`max-w-3xl`,children:[e(me,{children:[a(Ae,{children:c(`detectionIntelligence.photoEnrollDialog.enrolFromPhotos`,`Enrol from photos`)}),a(ge,{children:c(`detectionIntelligence.photoEnrollDialog.everyPhotoIsAnalysedWith`,`Every photo is analysed with the same face detector the cameras use, and all the faces found are reviewed below in one pass, grouped by photo. Assign each face to a person, or leave it ignored.`)})]}),a(`div`,{className:`rounded-md border border-border bg-surface-hover px-3 py-2 text-xs text-foreground-subtle`,children:a(ot,{i18nKey:`detectionIntelligence.photoEnrollDialog.reliableRecognition`,components:{strong:a(`strong`,{})}})}),e(`div`,{className:`flex items-center gap-2`,children:[a(ze,{ref:f,accept:`image/jpeg,image/png,image/webp`,multiple:!0,className:`hidden`,onChange:e=>void I(Array.from(e.target.files??[]))}),e(Y,{variant:`secondary`,size:`sm`,disabled:A,onClick:()=>f.current?.click(),children:[k?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(H,{className:`h-3.5 w-3.5`}),c(`detectionIntelligence.photoEnrollDialog.choosePhotos`,`Choose photos`)]}),h.length>0&&a(`span`,{className:`text-xs text-foreground-subtle`,children:c(`detectionIntelligence.photoEnrollDialog.photosAnalysed`,{done:V,count:h.length})})]}),a(`div`,{className:`min-h-11`,"aria-live":`polite`,children:b===null?E===null?null:a(`div`,{className:`rounded-md border border-success/40 bg-success/10 px-3 py-2 text-xs text-success`,children:E}):e(`div`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[a(y,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),a(`span`,{children:b})]})}),h.length>0&&a(`div`,{className:`max-h-[50vh] space-y-4 overflow-y-auto pr-1`,children:h.map(e=>a(yn,{photo:e,identities:O,draft:S,newNames:w,disabled:A,onAssign:(t,n)=>C(r=>an(r,e.photoIndex,t,n===hn?null:n)),onNameChange:(t,n)=>T(r=>({...r,[rn(e.photoIndex,t)]:n})),onRetry:()=>void F(e)},e.photoIndex))}),e(He,{children:[a(Y,{variant:`secondary`,onClick:N,disabled:_,children:c(`common.close`,`Close`)}),e(Y,{variant:`primary`,onClick:()=>void B(),disabled:A||L===0,children:[_?a(z,{className:`h-3.5 w-3.5 animate-spin`}):null,c(`detectionIntelligence.photoEnrollDialog.enrolFaces`,{count:L})]})]})]})})}c();var xn=[[`faceGallery`]];function Sn({identityId:t}){let{t:n}=Z(),r=l(),{data:i,isLoading:o}=le({identityId:t}),s=Oe();function c(e){s.mutate({identityId:t,sampleId:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:xn})}})}return o?e(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[a(z,{className:`h-3.5 w-3.5 animate-spin`}),n(`detectionIntelligence.peopleList.loadingSamples`,`Loading samples…`)]}):!i||i.length===0?a(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:n(`detectionIntelligence.peopleList.noSamplesYet`,`No samples yet.`)}):a(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:i.map(t=>e(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[t.base64?a(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:n(`detectionIntelligence.peopleList.sample`,`Sample`),className:`h-full w-full object-cover`}):a(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:a(W,{className:`h-6 w-6`})}),t.source===`photo`&&a(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 p-0.5 text-white`,title:n(`detectionIntelligence.peopleList.enrolledFromAnUploadedPhoto`,`Enrolled from an uploaded photo`),children:a(H,{className:`h-3 w-3`})}),a(`button`,{type:`button`,onClick:()=>c(t),disabled:s.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":n(`detectionIntelligence.peopleList.removeSample`,`Remove sample`),children:a(m,{className:`h-4 w-4 text-white`})})]},t.id))})}function Cn(t){return[{key:`person`,header:X.t(`detectionIntelligence.peopleList.person`,`Person`),sortValue:e=>e.name,render:t=>e(`span`,{className:`flex min-w-0 items-center gap-2`,children:[a(`span`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:a(Lt,{mediaId:t.coverMediaId,base64:t.coverBase64,alt:t.name,className:`h-full w-full object-cover`,placeholder:a(`span`,{className:`flex h-full w-full items-center justify-center`,children:a(W,{className:`h-4 w-4 text-foreground-subtle`})})})}),a(`span`,{className:`truncate text-sm font-medium text-foreground`,children:t.name})]})},{key:`samples`,header:X.t(`detectionIntelligence.peopleList.samples`,`Samples`),align:`center`,nowrap:!0,sortValue:e=>e.sampleCount,render:e=>a(Ie,{variant:`default`,className:`text-[10px]`,children:e.sampleCount})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:n=>e(`span`,{className:`flex items-center justify-end gap-1`,children:[a(xe,{variant:`ghost`,size:`sm`,icon:F,"aria-label":X.t(`detectionIntelligence.peopleList.edit`,`Edit {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onEdit(n)}}),a(xe,{variant:`ghost`,size:`sm`,icon:N,"aria-label":X.t(`detectionIntelligence.peopleList.delete`,`Delete {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onDelete(n)}})]})}]}function wn({mode:t,identity:n,onClose:r}){let{t:i}=Z(),c=l(),[u,d]=s(t===`edit`?n?.name??``:``),f=_e(),p=se();o(()=>{d(t===`edit`?n?.name??``:``)},[t,n?.id,n?.name]);let m=f.isPending||p.isPending,h=u.trim(),g=t===`edit`&&n!==null&&h===n.name,_=m||h.length===0||g;function v(){c.invalidateQueries({queryKey:xn})}function y(){if(!_){if(t===`new`){f.mutate({name:h},{onSuccess:()=>{v(),r()}});return}if(n===null){r();return}p.mutate({id:n.id,name:h},{onSuccess:()=>{v(),r()}})}}return a(Ue,{open:!0,onClose:r,title:t===`new`?`Add person`:`Edit ${n?.name??`person`}`,icon:W,width:t===`edit`?`xl`:`lg`,testId:`people-person-form`,footer:e(Y,{variant:`primary`,size:`sm`,type:`button`,onClick:y,disabled:_,children:[m?a(z,{className:`h-3.5 w-3.5 animate-spin`}):null,t===`new`?i(`common.add`,`Add`):i(`common.save`,`Save`)]}),children:e(`div`,{className:`space-y-4`,children:[a(Ke,{label:i(`detectionIntelligence.peopleList.name`,`Name`),required:!0,children:a(Xe,{value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&y()},placeholder:i(`detectionIntelligence.peopleList.personName`,`Person name…`),autoFocus:!0})}),t===`edit`&&n!==null&&e(`div`,{children:[a(`p`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:i(`detectionIntelligence.peopleList.trainingSamples`,`Training samples`)}),a(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:i(`detectionIntelligence.peopleList.removeASampleToDrop`,`Remove a sample to drop it from recognition training for this person.`)}),a(Sn,{identityId:n.id})]})]})})}function Tn(){let{t}=Z(),r=l(),i=x(),{data:c,isLoading:u}=Ee(),d=Qe(),{state:f,openNew:p,openEdit:m,close:h}=Be(),[g,_]=s(!1),v=c??[],y=Ce(v,{searchText:e=>[e.name]}),b=f.mode===`edit`?v.find(e=>e.id===f.id)??null:null;o(()=>{f.mode===`edit`&&!u&&b===null&&h()},[f.mode,u,b,h]);let S=n(()=>Cn({onEdit:e=>m(e.id),onDelete:e=>{(async()=>{await i({title:t(`detectionIntelligence.peopleList.deletePerson`,`Delete person`),message:t(`detectionIntelligence.peopleList.deleteAndAllTheirSamples`,`Delete {{name}} and all their samples? This cannot be undone.`,{name:e.name}),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&d.mutate({id:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:xn}),f.mode===`edit`&&f.id===e.id&&h()}})})()}}),[i,h,d,f,m,r,t]);if(u)return e(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[a(z,{className:`h-4 w-4 animate-spin`}),t(`detectionIntelligence.peopleList.loadingPeople`,`Loading people…`)]});let C=f.mode===`new`||f.mode===`edit`&&b!==null;return e(`div`,{className:`space-y-2`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(Y,{variant:`primary`,size:`sm`,type:`button`,onClick:p,children:[a(D,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.peopleList.addPerson`,`Add person`)]}),e(Y,{variant:`secondary`,size:`sm`,type:`button`,onClick:()=>_(!0),children:[a(H,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.peopleList.enrolFromAPhoto`,`Enrol from a photo`)]})]}),(v.length>0||y.active)&&a(ae,{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?a(Re,{icon:W,title:y.active?t(`detectionIntelligence.peopleList.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.peopleList.noPeopleEnrolledYet`,`No people enrolled yet`),description:y.active?t(`detectionIntelligence.peopleList.clearTheSearchOrTry`,`Clear the search or try another name.`):t(`detectionIntelligence.peopleList.addAPersonOrEnrol`,`Add a person, or enrol faces from a photo.`)}):a(et,{columns:S,rows:y.rows,rowKey:e=>e.id,maxBodyHeight:ne,emptyMessage:t(`detectionIntelligence.peopleList.noPeopleEnrolledYet2`,`No people enrolled yet.`),onRowClick:e=>m(e.id)}),C&&a(wn,{mode:f.mode===`new`?`new`:`edit`,identity:b,onClose:h}),a(bn,{open:g,onOpenChange:_})]})}function En(e){let t=e.cropUrl!==void 0&&e.cropUrl.length>0,n=e.base64!==void 0&&e.base64.length>0;return!t&&!n}function Dn(e){return e.filter(En).map(e=>e.faceId)}function On(e){let t=0;for(let n of e)En(n)&&(t+=1);return t}function kn(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}c();var An=[[`faceGallery`]];function jn({faceIds:t,identities:n,onDone:r}){let{t:i}=Z(),o=l(),c=de(),u=_e(),[d,f]=s(``),[p,m]=s(!1),[h,g]=s(null),_=t!==null&&t.length>0,v=t?.length??0;function y(){m(!1),f(``),g(null)}function b(){y(),r()}function x(e){!t||t.length===0||c.mutate({faceIds:[...t],identityId:e},{onSettled:()=>{o.invalidateQueries({queryKey:An}),b()}})}function S(){!t||!d.trim()||u.mutate({name:d.trim()},{onSuccess:e=>{e?.id&&x(e.id)},onError:()=>{o.invalidateQueries({queryKey:An}),b()}})}let C=c.isPending||u.isPending;return a(Te,{open:_,onOpenChange:e=>!e&&b(),children:e(ce,{children:[e(me,{children:[a(Ae,{children:v>1?i(`detectionIntelligence.assignDialog.assignFacesToPerson`,`Assign {{value1}} faces to person`,{value1:String(v)}):i(`detectionIntelligence.assignDialog.assignFaceToPerson`,`Assign face to person`)}),a(ge,{children:i(`detectionIntelligence.assignDialog.selectAnExistingPersonOr`,`Select an existing person or create a new one.`)})]}),a(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:n.map(t=>e(Y,{variant:`unstyled`,type:`button`,onClick:()=>g(t.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${h===t.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[a(`span`,{className:`font-medium`,children:t.name}),a(`span`,{className:`ml-2 text-foreground-subtle`,children:i(`detectionIntelligence.assignDialog.samples`,{count:t.sampleCount})})]},t.id))}),a(`div`,{className:`min-h-[2.75rem] border-t border-border pt-2`,children:p?a(`div`,{className:`flex items-center gap-2`,children:a(Xe,{placeholder:i(`detectionIntelligence.assignDialog.newPersonName`,`New person name…`),value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&S()},autoFocus:!0,className:`flex-1`})}):a(Y,{variant:`unstyled`,type:`button`,onClick:()=>{g(null),m(!0)},className:`w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle transition-colors hover:border-primary hover:text-primary`,children:i(`detectionIntelligence.assignDialog.newPerson`,`+ New person…`)})}),e(He,{className:`min-h-[2.75rem]`,children:[a(Y,{variant:`secondary`,onClick:b,disabled:C,children:i(`common.cancel`,`Cancel`)}),p?e(Y,{variant:`primary`,onClick:S,disabled:C||!d.trim(),children:[C&&a(z,{className:`h-3.5 w-3.5 animate-spin`}),i(`detectionIntelligence.assignDialog.createAssign`,`Create & assign`)]}):e(Y,{variant:`primary`,onClick:()=>h&&x(h),disabled:C||!h,children:[C&&a(z,{className:`h-3.5 w-3.5 animate-spin`}),v>1?i(`detectionIntelligence.assignCount`,{count:v}):i(`common.assign`)]})]})]})})}function Mn(e){return e<0?0:e>1?1:e}function Nn(e,t,n){if(!Number.isFinite(t)||!Number.isFinite(n)||t<=0||n<=0)return null;let r=Mn(e.x/t),i=Mn(e.y/n),a=Mn((e.x+e.w)/t),o=Mn((e.y+e.h)/n);return{x:r,y:i,width:Math.max(0,a-r),height:Math.max(0,o-i)}}c();function Pn(e){let[t,n]=s(null),[r,i]=s(null),[a,c]=s(!1);return o(()=>{if(n(null),i(null),c(!1),e===void 0)return;let t=!1,r=null;return(async()=>{try{let i=await Ct(wt(e));if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||c(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),o(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>c(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function Fn(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 In({label:t,value:n}){return e(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[a(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:t}),a(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground`,children:n})]})}function Ln({box:e}){let{t}=Z();return a(`div`,{className:`pointer-events-none absolute rounded-[3px] border-2 border-primary shadow-[0_0_0_9999px_rgba(0,0,0,0.28)]`,style:{left:`${String(e.x*100)}%`,top:`${String(e.y*100)}%`,width:`${String(e.width*100)}%`,height:`${String(e.height*100)}%`},children:a(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:t(`detectionIntelligence.faceDetailPanel.face`,`Face`)})})}function Rn({face:t,cameraName:r,onClose:i,onAssign:o,onUnassign:c,onDelete:l,actionsPending:u}){let{t:d}=Z(),{data:f,isFetching:m}=te({faceId:t?.faceId??``},{enabled:t!==null}),[h,v]=s(`frame`),{frameSrc:y,naturalWidth:b,naturalHeight:x,failed:S}=Pn(t?.keyFrameMediaId),C=n(()=>{let e=Fn(f??[]);return e?e.url:kn(t)},[f,t]),w=n(()=>!t?.faceBbox||b===null||x===null?null:Nn(t.faceBbox,b,x),[t?.faceBbox,b,x]);if(t===null)return null;let T=t.keyFrameMediaId!==void 0&&!S,E=T&&h===`frame`,D=t.assigned?t.identityName??`Assigned`:t.recognizedIdentityId?`${t.identityName??`Recognized`} (suggested)`:`Unassigned`;return a(Te,{open:!0,onOpenChange:e=>!e&&i(),children:e(ce,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":d(`detectionIntelligence.faceDetailPanel.faceDetail`,`Face detail`),className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[a(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:e(`div`,{className:`min-w-0`,children:[a(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:d(`detectionIntelligence.faceDetailPanel.faceDetail`,`Face detail`)}),a(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:r})]})}),e(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[T&&e(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[e(Y,{variant:`unstyled`,type:`button`,onClick:()=>v(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${h===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(p,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.fullFrame`)]}),e(Y,{variant:`unstyled`,type:`button`,onClick:()=>v(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${h===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(J,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.crop`)]})]}),E&&y?a(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:a(pt,{src:y,alt:d(`detectionIntelligence.faceDetailPanel.fullFrameWithDetectedFace`,`Full frame with detected face`),fit:`natural`,className:`w-full`,overlay:w?a(Ln,{box:w}):void 0})}):C?e(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[a(pt,{src:C,alt:d(`detectionIntelligence.faceDetailPanel.detectedFace`,`Detected face`),className:`h-full w-full`}),m&&a(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:a(z,{className:`h-3.5 w-3.5 animate-spin`})})]}):e(`div`,{className:`flex aspect-square w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[a(_,{className:`h-8 w-8 text-warning/70`}),a(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:d(`detectionIntelligence.faceDetailPanel.noImage`,`No image`)}),a(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:d(`detectionIntelligence.faceDetailPanel.theCropMediaForThis`,`The crop media for this face could not be resolved (a pre-fix orphan). Safe to delete.`)})]}),e(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[a(In,{label:d(`detectionIntelligence.faceDetailPanel.camera`,`Camera`),value:r}),a(In,{label:d(`detectionIntelligence.faceDetailPanel.captured`,`Captured`),value:ft(t.timestamp)}),a(In,{label:d(`detectionIntelligence.faceDetailPanel.track`,`Track`),value:t.trackId}),a(In,{label:d(`detectionIntelligence.faceDetailPanel.identity`,`Identity`),value:D})]})]}),e(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[t.assigned?e(Y,{variant:`secondary`,onClick:()=>c(t.faceId),disabled:u,children:[a(q,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.detach`)]}):e(Y,{variant:`primary`,onClick:()=>o(t.faceId),disabled:u,children:[a(g,{className:`h-3.5 w-3.5`}),` `,d(`common.assign`)]}),e(Y,{variant:`secondary`,onClick:()=>l(t.faceId),disabled:u,children:[a(N,{className:`h-3.5 w-3.5`}),` `,d(`common.delete`)]})]})]})})}function zn(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function Bn(e,t){return e.faceIds.filter(e=>!t.has(e))}function Vn(e,t){return e.faceIds.filter(e=>t(e))}c();var Hn=[[`faceGallery`]],Un=20,Wn=.3,Gn=.9,Kn=.05,qn=.5,Jn=2,Yn=10,Xn=2;function Zn({cluster:t,face:n,active:r,onSelect:i}){let{t:o}=Z(),s=kn(n);return e(Y,{variant:`unstyled`,type:`button`,onClick:i,className:`flex shrink-0 flex-col items-center gap-1.5 rounded-md border p-2 text-center transition-colors md:w-full md:flex-row md:gap-2.5 md:text-left ${r?`border-primary bg-primary/8`:`border-border bg-surface hover:bg-surface-hover`}`,children:[a(`div`,{className:`h-24 w-24 shrink-0 overflow-hidden rounded bg-surface-hover`,children:s===null?a(_,{className:`h-24 w-24 p-6 text-foreground-subtle`}):a(`img`,{src:s,alt:``,loading:`lazy`,decoding:`async`,className:`h-24 w-24 object-cover`})}),a(`span`,{className:`w-24 text-[11px] leading-tight text-foreground-subtle md:w-auto`,children:o(`detectionIntelligence.similarGroupsModal.clusterMeta`,{count:t.size,percent:Math.round(t.cohesion*100)})})]})}function Qn({face:t,cameraName:n,nowMs:r,excluded:i,onToggleExclude:o,onDelete:s,deletePending:c}){let{t:l}=Z(),u=kn(t);return e(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden transition-opacity ${i?`border-border opacity-40 grayscale`:`border-border`}`,children:[e(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[u===null?e(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,children:[a(_,{className:`h-7 w-7 text-warning/70`}),a(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:l(`detectionIntelligence.similarGroupsModal.noCrop`,`No crop`)})]}):a(pt,{src:u,alt:l(`detectionIntelligence.similarGroupsModal.faceFrom`,`Face from {{cameraName}}`,{cameraName:n}),className:`h-full w-full`}),a(Y,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),o()},className:`absolute right-1 top-1 z-10 rounded-full bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?l(`detectionIntelligence.similarGroupsModal.includeFace`,`Include face`):l(`detectionIntelligence.similarGroupsModal.excludeFace`,`Exclude face`),title:i?l(`detectionIntelligence.similarGroupsModal.include`,`Include`):l(`detectionIntelligence.similarGroupsModal.exclude`,`Exclude`),children:a(i?j:m,{className:`h-3.5 w-3.5`})})]}),e(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[a(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:n,children:n}),a(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:dt(t.timestamp,r)})]}),a(`div`,{className:`mt-1 flex min-h-[2rem] items-center justify-end border-t border-border/60 px-1 py-0.5`,children:a(Y,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),s()},disabled:c,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":l(`detectionIntelligence.similarGroupsModal.deleteFace`,`Delete face`),title:l(`detectionIntelligence.similarGroupsModal.deleteFace`,`Delete face`),children:c?a(z,{className:`h-4 w-4 animate-spin`}):a(N,{className:`h-4 w-4`})})})]})}function $n({open:t,onClose:r,byId:i,cameraName:c,nowMs:f,identities:p,selectMany:m}){let{t:h}=Z(),_=l(),y=x(),b=ye(),[S,C]=s(qn),[w,T]=s(Xn),[E,D]=s(null),[O,k]=s({}),[A,j]=s(null),{data:M,isFetching:N,refetch:P}=he({threshold:S,minClusterSize:w,limit:Un},{enabled:t}),F=M??[];o(()=>{k({})},[S,w]),o(()=>{if(F.length===0){D(null);return}F.some(e=>e.representativeFaceId===E)||D(F[0]?.representativeFaceId??null)},[F]);let I=n(()=>F.find(e=>e.representativeFaceId===E)??null,[F,E]),R=I?O[I.representativeFaceId]??new Set:new Set,B=n(()=>I?Vn(I,e=>i.has(e)):[],[I,i]),V=I?I.faceIds.length-B.length:0,H=I?Bn({...I,faceIds:B},R):[];function U(e){if(!I)return;let t=I.representativeFaceId;k(n=>({...n,[t]:zn(n[t]??new Set,e)}))}function W(){_.invalidateQueries({queryKey:Hn})}async function G(e){await y({title:h(`detectionIntelligence.similarGroupsModal.deleteFace`,`Delete face`),message:h(`detectionIntelligence.similarGroupsModal.permanentlyDeletesThisFaceCrop`,`Permanently deletes this face crop. This cannot be undone.`),confirmLabel:h(`common.delete`,`Delete`),variant:`danger`})&&b.mutate({faceId:e},{onSettled:W})}function K(){j(null),r()}function q(){H.length!==0&&(m(H),K())}return e(Te,{open:t,onOpenChange:e=>!e&&K(),children:[e(ce,{placement:`sheet-on-mobile`,width:`lg`,"aria-label":h(`detectionIntelligence.similarGroupsModal.lookAlikeGroups`,`Look-alike groups`),className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 md:max-w-4xl`,children:[e(`header`,{className:`flex shrink-0 flex-col gap-2 border-b border-border py-3 pl-4 pr-10`,children:[e(`div`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[a(L,{className:`h-4 w-4 text-primary`}),` `,h(`detectionIntelligence.similarGroupsModal.title`)]}),e(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[e(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[h(`detectionIntelligence.similarGroupsModal.threshold`,`Threshold`),a(d,{min:Wn,max:Gn,step:Kn,value:S,onChange:e=>C(Number(e.target.value)),className:`h-1.5 w-28 cursor-pointer accent-primary`}),a(`span`,{className:`w-8 shrink-0 text-right font-mono text-[11px] tabular-nums text-foreground`,children:S.toFixed(2)})]}),e(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[h(`detectionIntelligence.similarGroupsModal.minSize`,`Min size`),a(Xe,{type:`number`,min:Jn,max:Yn,step:1,value:w,onChange:e=>T(Math.min(Yn,Math.max(Jn,Number(e.target.value)||Jn))),className:`w-12 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`})]}),e(Y,{variant:`secondary`,onClick:()=>{k({}),P()},disabled:N,children:[N?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(v,{className:`h-3.5 w-3.5`}),h(`detectionIntelligence.similarGroupsModal.reAnalyze`,`Re-analyze`)]})]})]}),a(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-hidden px-4 py-3 md:flex-row`,children:N&&F.length===0?e(`div`,{className:`flex flex-1 items-center justify-center gap-2 py-8 text-xs text-foreground-subtle`,children:[a(z,{className:`h-4 w-4 animate-spin`}),` `,h(`detectionIntelligence.similarGroupsModal.finding`)]}):F.length===0?a(`div`,{className:`flex flex-1 items-center justify-center py-8 text-xs text-foreground-subtle`,children:h(`detectionIntelligence.similarGroupsModal.noLookAlikeGroupsAt`,`No look-alike groups at this threshold.`)}):e(u,{children:[a(`div`,{className:`flex gap-2 overflow-x-auto pb-1 md:hidden`,children:F.map(e=>a(Zn,{cluster:e,face:i.get(e.representativeFaceId),active:e.representativeFaceId===E,onSelect:()=>D(e.representativeFaceId)},e.representativeFaceId))}),a(`div`,{className:`hidden shrink-0 flex-col gap-2 overflow-y-auto md:flex md:w-56`,children:F.map(e=>a(Zn,{cluster:e,face:i.get(e.representativeFaceId),active:e.representativeFaceId===E,onSelect:()=>D(e.representativeFaceId)},e.representativeFaceId))}),a(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:I&&e(u,{children:[V>0&&a(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:h(`detectionIntelligence.similarGroupsModal.hiddenCount`,{count:V})}),a(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(13rem,13rem))] justify-start gap-2`,children:B.map(e=>{let t=i.get(e);return t?a(Qn,{face:t,cameraName:c(t.deviceId),nowMs:f,excluded:R.has(e),onToggleExclude:()=>U(e),onDelete:()=>void G(e),deletePending:b.isPending&&b.variables?.faceId===e},e):null})})]})})]})}),e(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[a(Y,{variant:`secondary`,onClick:q,disabled:H.length===0,children:h(`detectionIntelligence.similarGroupsModal.selectInGallery`,`Select in gallery`)}),e(Y,{variant:`primary`,onClick:()=>j(H),disabled:H.length===0,children:[a(g,{className:`h-3.5 w-3.5`}),` `,h(`detectionIntelligence.similarGroupsModal.adopt`,{count:H.length})]})]})]}),a(jn,{faceIds:A,identities:p,onDone:()=>j(null)})]})}c();var er=[[`faceGallery`]],tr=500,nr=120;function rr({face:t,cameraName:n,nowMs:r,selected:i,onToggleSelect:o,onAssign:s,onOpenDetail:c}){let{t:u}=Z(),d=l(),f=Ve(),p=ye(),m=()=>{d.invalidateQueries({queryKey:er})},h=()=>c(t.faceId),v=kn(t);return e(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[e(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[v===null?e(`button`,{type:`button`,onClick:h,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:u(`detectionIntelligence.unassignedFaces.noCropImageTheFace`,`No crop image — the face's crop media is missing (a pre-fix orphan). Safe to delete.`),children:[a(_,{className:`h-7 w-7 text-warning/70`}),a(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:u(`detectionIntelligence.unassignedFaces.noCrop`,`No crop`)})]}):a(`img`,{src:v,alt:u(`detectionIntelligence.unassignedFaces.faceFrom`,`Face from {{cameraName}}`,{cameraName:n}),onClick:h,loading:`lazy`,decoding:`async`,className:`h-full w-full cursor-zoom-in object-cover`}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(t.faceId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?u(`detectionIntelligence.unassignedFaces.deselect`,`Deselect`):u(`detectionIntelligence.unassignedFaces.select`,`Select`),children:i?a(ee,{className:`h-4 w-4 text-primary`}):a(k,{className:`h-4 w-4`})})]}),e(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[a(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:n,children:n}),a(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:dt(t.timestamp,r)}),a(`p`,{className:`min-h-[0.875rem] truncate text-[10px] font-medium leading-tight ${t.identityName?`text-primary`:`invisible`}`,title:t.identityName,children:t.identityName??`\xA0`})]}),e(`div`,{className:`mt-1 flex min-h-[2rem] items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[t.assigned?a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),f.mutate({faceId:t.faceId},{onSettled:m})},disabled:f.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":u(`detectionIntelligence.unassignedFaces.detachFace`,`Detach face`),title:u(`detectionIntelligence.unassignedFaces.detach`,`Detach`),children:f.isPending?a(z,{className:`h-4 w-4 animate-spin`}):a(q,{className:`h-4 w-4`})}):a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s(t.faceId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":u(`detectionIntelligence.unassignedFaces.assignFaceToPerson`,`Assign face to person`),title:u(`detectionIntelligence.unassignedFaces.assignToPerson`,`Assign to person`),children:a(g,{className:`h-4 w-4`})}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),p.mutate({faceId:t.faceId},{onSettled:m})},disabled:p.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":u(`detectionIntelligence.unassignedFaces.deleteFace`,`Delete face`),title:u(`detectionIntelligence.unassignedFaces.deleteFace`,`Delete face`),children:p.isPending?a(z,{className:`h-4 w-4 animate-spin`}):a(N,{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 ar(){let{t}=Z(),r=l(),[i,o]=s(`all`),[c,d]=s(_t),[f,p]=s(new Set),[h,v]=s(new Set),[y,b]=s(null),[x,S]=s(!1),[C,w]=s(null),{data:T,isLoading:E}=we({limit:tr,filter:i,includeCrops:!1},{refetchInterval:3e4}),{data:D=[]}=Ee(),{data:O}=Me({isCamera:!0,projection:`slim`}),k=de(),A=Ve(),j=pe(),M=ye(),P=Date.now(),F=T??[],I=n(()=>{let e=new Map;for(let t of O??[])e.set(t.id,t.name);return e},[O]),R=e=>I.get(e)??t(`detectionIntelligence.cameraFallback`,{id:String(e)}),B=n(()=>bt(F).map(e=>({id:e,name:R(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[F,I]),V=n(()=>ut(mt(F,c),f),[F,c,f]),H=gt(V,nr,n(()=>JSON.stringify([i,c.fromMs,c.toMs,[...f].sort((e,t)=>e-t)]),[i,c.fromMs,c.toMs,f])),U=n(()=>new Map(F.map(e=>[e.faceId,e])),[F]),W=n(()=>On(V),[V]),G=C===null?null:U.get(C)??null,K=()=>{r.invalidateQueries({queryKey:er})},J=()=>v(new Set);function ee(e){v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function te(e){v(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function ne(){te(Dn(V))}let re=[...h],ie=k.isPending||j.isPending||M.isPending,ae=A.isPending||M.isPending;function oe(){re.length!==0&&j.mutate({faceIds:re},{onSettled:()=>{K(),J()}})}function se(){re.length!==0&&Promise.allSettled(re.map(e=>M.mutateAsync({faceId:e}))).then(()=>{K(),J()})}function ce(e){w(null),b([e])}function le(e){A.mutate({faceId:e},{onSettled:K}),w(null)}function ue(e){M.mutate({faceId:e},{onSettled:K}),w(null)}let fe=V.length!==F.length;return e(`div`,{className:`relative space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[a(`div`,{className:`flex items-center gap-1`,children:ir.map(e=>a(`button`,{type:`button`,onClick:()=>o(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${i===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:t(e.labelKey)},e.value))}),a(lt,{onChange:d}),a(vt,{cameras:B,selected:f,onChange:p}),e(`button`,{type:`button`,onClick:()=>S(!0),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${x?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(L,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.similarGroups`)]}),!E&&W>0&&e(`button`,{type:`button`,onClick:ne,className:`ml-auto flex items-center gap-1 rounded-md px-2.5 py-1 text-xs text-warning/90 transition-colors hover:bg-warning/10`,title:t(`detectionIntelligence.unassignedFaces.selectEveryVisibleFaceWhose`,`Select every visible face whose crop image is missing so you can delete the orphans in one pass`),children:[a(_,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.selectCropless`,{count:W})]}),!E&&a(`span`,{className:`text-[10px] text-foreground-subtle ${W>0?`ml-2`:`ml-auto`}`,children:fe?t(`detectionIntelligence.unassignedFaces.ofFaces`,`{{value1}} of {{value2}} faces`,{value1:String(V.length),value2:String(F.length)}):t(`detectionIntelligence.unassignedFaces.faceCount`,{count:V.length})})]}),h.size>0&&e(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[a(`span`,{className:`text-xs font-medium text-foreground`,children:t(`common.selectedCount`,{count:h.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[e(Y,{variant:`primary`,onClick:()=>b(re),disabled:ie,children:[a(g,{className:`h-3.5 w-3.5`}),` `,t(`common.assign`)]}),e(Y,{variant:`secondary`,onClick:oe,disabled:ie,children:[j.isPending?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(q,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.detach`,`Detach`)]}),e(Y,{variant:`secondary`,onClick:se,disabled:ie,children:[a(N,{className:`h-3.5 w-3.5`}),` `,t(`common.delete`)]}),a(Y,{variant:`ghost`,onClick:J,disabled:ie,children:a(m,{className:`h-3.5 w-3.5`})})]})]}),E?a(Ge,{status:`pending`,pendingMessage:`Loading faces…`,testId:`faces-grid`}):V.length===0?a(Re,{icon:_,title:F.length>0?t(`detectionIntelligence.unassignedFaces.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.unassignedFaces.noFacesFoundForThis`,`No faces found for this filter`),description:F.length>0?t(`detectionIntelligence.unassignedFaces.widenTheDateRangeOr`,`Widen the date range or clear the camera filter.`):t(`detectionIntelligence.unassignedFaces.faceCropsAppearHereWhen`,`Face crops appear here when the detection pipeline captures them.`)}):e(u,{children:[a(Ge,{status:`ready`,testId:`faces-grid`,className:`grid-cols-[repeat(auto-fill,minmax(6.5rem,6.5rem))] justify-start`,children:H.pageItems.map(e=>a(rr,{face:e,cameraName:R(e.deviceId),nowMs:P,selected:h.has(e.faceId),onToggleSelect:ee,onAssign:e=>b([e]),onOpenDetail:w},e.faceId))}),a(yt,{currentPage:H.page,totalItems:H.totalItems,pageSize:H.pageSize,onPageChange:H.setPage,itemNoun:`faces`})]}),a(Rn,{face:G,cameraName:G?R(G.deviceId):``,onClose:()=>w(null),onAssign:ce,onUnassign:le,onDelete:ue,actionsPending:ae}),a(jn,{faceIds:y,identities:D,onDone:()=>{b(null),J()}}),a($n,{open:x,onClose:()=>S(!1),byId:U,cameraName:R,nowMs:P,identities:D,selectMany:te})]})}c();var or=[[`faceGallery`]],sr=2e3;function cr(){let e=l(),n=t(e);n.current=e;let r=t(void 0);r.current||=ht({delayMs:sr,invalidate:()=>{n.current.invalidateQueries({queryKey:or})}}),o(()=>()=>r.current?.cancel(),[]),ke(B.PipelineAnalyticsFaceGalleryChanged,()=>{r.current?.trigger()})}function lr(){let{t}=Z();return cr(),e(`div`,{className:`space-y-3`,children:[a(fe,{headingId:`library-people`,title:t(`detectionIntelligence.people`,`People`),icon:W,testId:`library-section-people`,children:e(`div`,{className:`${f} space-y-3`,children:[a(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`detectionIntelligence.enrolledIdentitiesUsedForFace`,`Enrolled identities used for face recognition. Open a person to rename them or remove training samples.`)}),a(Tn,{})]})}),a(fe,{headingId:`library-recent-faces`,title:t(`detectionIntelligence.recentDetectedFaces`,`Recent detected faces`),icon:U,testId:`library-section-recent-faces`,children:e(`div`,{className:`${f} space-y-3`,children:[a(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`detectionIntelligence.faceCropsCapturedByThe`,`Face crops captured by the detection pipeline. Assign them to a person to build recognition training data.`)}),a(ar,{})]})})]})}function ur(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}c();var dr=[[`plateGallery`]];function fr({plateIds:t,vehicles:n,onDone:r}){let{t:i}=Z(),o=l(),c=Ne(),u=Ze(),[d,f]=s(``),[p,m]=s(!1),[h,g]=s(null),_=t!==null&&t.length>0,v=t?.length??0;function y(){m(!1),f(``),g(null)}function b(){y(),r()}function x(e){!t||t.length===0||c.mutate({plateIds:[...t],vehicleId:e},{onSettled:()=>{o.invalidateQueries({queryKey:dr}),b()}})}function S(){!t||!d.trim()||u.mutate({name:d.trim()},{onSuccess:e=>{e?.id&&x(e.id)},onError:()=>{o.invalidateQueries({queryKey:dr}),b()}})}let C=c.isPending||u.isPending;return a(Te,{open:_,onOpenChange:e=>!e&&b(),children:e(ce,{children:[e(me,{children:[a(Ae,{children:v>1?i(`detectionIntelligence.assignPlateDialog.assignPlatesToVehicle`,`Assign {{value1}} plates to vehicle`,{value1:String(v)}):i(`detectionIntelligence.assignPlateDialog.assignPlateToVehicle`,`Assign plate to vehicle`)}),a(ge,{children:i(`detectionIntelligence.assignPlateDialog.selectAnExistingVehicleOr`,`Select an existing vehicle or create a new one.`)})]}),a(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:n.map(t=>e(Y,{variant:`unstyled`,type:`button`,onClick:()=>g(t.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${h===t.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[a(`span`,{className:`font-medium`,children:t.name}),a(`span`,{className:`ml-2 text-foreground-subtle`,children:i(`detectionIntelligence.assignPlateDialog.plates`,{count:t.sampleCount})})]},t.id))}),p?a(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:a(Xe,{placeholder:i(`detectionIntelligence.assignPlateDialog.newVehicleName`,`New vehicle name…`),value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&S()},autoFocus:!0,className:`flex-1`})}):a(Y,{variant:`unstyled`,type:`button`,onClick:()=>{g(null),m(!0)},className:`mt-2 w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle hover:border-primary hover:text-primary transition-colors`,children:i(`detectionIntelligence.assignPlateDialog.newVehicle`,`+ New vehicle…`)}),e(He,{children:[a(Y,{variant:`secondary`,onClick:b,disabled:C,children:i(`common.cancel`,`Cancel`)}),p?e(Y,{variant:`primary`,onClick:S,disabled:C||!d.trim(),children:[C&&a(z,{className:`h-3.5 w-3.5 animate-spin`}),i(`detectionIntelligence.assignPlateDialog.createAssign`,`Create & assign`)]}):e(Y,{variant:`primary`,onClick:()=>h&&x(h),disabled:C||!h,children:[C&&a(z,{className:`h-3.5 w-3.5 animate-spin`}),v>1?i(`detectionIntelligence.assignCount`,{count:v}):i(`common.assign`)]})]})]})})}c();var pr=[[`plateGallery`]];function mr(e){let[t,n]=s(null),[r,i]=s(null),[a,c]=s(!1);return o(()=>{if(n(null),i(null),c(!1),e===void 0)return;let t=!1,r=null;return(async()=>{try{let i=await Ct(wt(e));if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||c(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),o(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>c(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function hr(e){let t=e.filter(e=>e.url.length>0);return t.length===0?null:t.find(e=>/crop|plate/i.test(e.kind))??t[0]}function gr({label:t,value:n,mono:r}){return e(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[a(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:t}),a(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${r?`font-mono`:``}`,title:n,children:n})]})}function _r({box:e}){let{t}=Z();return a(`div`,{className:`pointer-events-none absolute rounded-[3px] border-2 border-primary shadow-[0_0_0_9999px_rgba(0,0,0,0.28)]`,style:{left:`${String(e.x*100)}%`,top:`${String(e.y*100)}%`,width:`${String(e.width*100)}%`,height:`${String(e.height*100)}%`},children:a(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:t(`detectionIntelligence.plateDetailPanel.plate`,`Plate`)})})}function vr({plate:t,cameraName:r,onClose:i,onAssign:c,onUnassign:u,onDelete:d,actionsPending:f}){let{t:h}=Z(),v=l(),{data:y,isFetching:b}=be({plateId:t?.plateId??``},{enabled:t!==null}),x=qe(),[S,C]=s(`frame`),[w,T]=s(!1),[E,D]=s(``),{frameSrc:O,naturalWidth:k,naturalHeight:A,failed:j}=mr(t?.keyFrameMediaId);o(()=>{T(!1),D(``),C(`frame`)},[t?.plateId]);let P=n(()=>{let e=hr(y??[]);return e?e.url:ur(t)},[y,t]),I=n(()=>!t?.plateBbox||k===null||A===null?null:Nn(t.plateBbox,k,A),[t?.plateBbox,k,A]);if(t===null)return null;let L=t.keyFrameMediaId!==void 0&&!j,R=L&&S===`frame`,B=t.assigned?t.vehicleName??`Assigned`:t.recognizedVehicleId?`${t.vehicleName??`Recognized`} (suggested)`:`Unassigned`,V=`${String(Math.round(t.score*100))}%${t.corrected?` · corrected`:``}`;function H(){t&&(D(t.text),T(!0))}function U(){if(!t)return;let e=E.trim().toUpperCase();if(!e||e===t.text){T(!1);return}x.mutate({plateId:t.plateId,text:e},{onSettled:()=>{v.invalidateQueries({queryKey:pr}),T(!1)}})}return a(Te,{open:!0,onOpenChange:e=>!e&&i(),children:e(ce,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":h(`detectionIntelligence.plateDetailPanel.plateDetail`,`Plate detail`),className:`flex h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:h-auto md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[a(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:e(`div`,{className:`min-w-0`,children:[a(`div`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:t.text||h(`detectionIntelligence.plateDetailPanel.plateDetail`,`Plate detail`)}),a(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:r})]})}),e(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[L&&e(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[e(Y,{variant:`unstyled`,type:`button`,onClick:()=>C(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${S===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(p,{className:`h-3.5 w-3.5`}),` `,h(`detectionIntelligence.detailPanel.fullFrame`)]}),e(Y,{variant:`unstyled`,type:`button`,onClick:()=>C(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${S===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(J,{className:`h-3.5 w-3.5`}),` `,h(`detectionIntelligence.detailPanel.crop`)]})]}),R&&O?a(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:a(pt,{src:O,alt:h(`detectionIntelligence.plateDetailPanel.fullFrameWithDetectedPlate`,`Full frame with detected plate`),fit:`natural`,className:`w-full`,overlay:I?a(_r,{box:I}):void 0})}):P?e(`div`,{className:`relative aspect-[2/1] w-full overflow-hidden rounded-lg border border-border bg-background`,children:[a(pt,{src:P,alt:h(`detectionIntelligence.plateDetailPanel.detectedPlate`,`Detected plate`),className:`h-full w-full`}),b&&a(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:a(z,{className:`h-3.5 w-3.5 animate-spin`})})]}):e(`div`,{className:`flex aspect-[2/1] w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[a(_,{className:`h-8 w-8 text-warning/70`}),a(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:h(`detectionIntelligence.plateDetailPanel.noImage`,`No image`)}),a(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:h(`detectionIntelligence.plateDetailPanel.theCropMediaForThis`,`The crop media for this plate could not be resolved. Safe to delete.`)})]}),a(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-2`,children:e(`div`,{className:`flex items-center justify-between gap-3`,children:[a(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:h(`detectionIntelligence.plateDetailPanel.plateText`,`Plate text`)}),w?e(`div`,{className:`flex min-w-0 flex-1 items-center justify-end gap-1.5`,children:[a(Xe,{value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`&&U(),e.key===`Escape`&&T(!1)},className:`h-7 max-w-[10rem] text-right font-mono text-xs uppercase`,autoFocus:!0}),a(Y,{variant:`unstyled`,type:`button`,onClick:U,disabled:x.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":h(`detectionIntelligence.plateDetailPanel.saveCorrectedText`,`Save corrected text`),children:x.isPending?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(M,{className:`h-3.5 w-3.5`})}),a(Y,{variant:`unstyled`,type:`button`,onClick:()=>T(!1),className:`text-foreground-subtle hover:text-foreground`,"aria-label":h(`common.cancel`,`Cancel`),children:a(m,{className:`h-3.5 w-3.5`})})]}):e(Y,{variant:`unstyled`,type:`button`,onClick:H,className:`group flex min-w-0 items-center gap-1.5`,title:h(`detectionIntelligence.plateDetailPanel.correctTheOcrReading`,`Correct the OCR reading`),children:[a(`span`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:t.text||`—`}),a(F,{className:`h-3 w-3 shrink-0 text-foreground-subtle group-hover:text-foreground`})]})]})}),e(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[a(gr,{label:h(`detectionIntelligence.plateDetailPanel.camera`,`Camera`),value:r}),a(gr,{label:h(`detectionIntelligence.plateDetailPanel.captured`,`Captured`),value:ft(t.timestamp)}),a(gr,{label:h(`detectionIntelligence.plateDetailPanel.confidence`,`Confidence`),value:V}),a(gr,{label:h(`detectionIntelligence.plateDetailPanel.vehicle`,`Vehicle`),value:B}),a(gr,{label:h(`detectionIntelligence.plateDetailPanel.track`,`Track`),value:t.trackId,mono:!0})]})]}),e(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[t.assigned?e(Y,{variant:`secondary`,onClick:()=>u(t.plateId),disabled:f,children:[a(q,{className:`h-3.5 w-3.5`}),` `,h(`detectionIntelligence.detailPanel.detach`)]}):e(Y,{variant:`primary`,onClick:()=>c(t.plateId),disabled:f,children:[a(g,{className:`h-3.5 w-3.5`}),` `,h(`common.assign`)]}),e(Y,{variant:`secondary`,onClick:()=>d(t.plateId),disabled:f,children:[a(N,{className:`h-3.5 w-3.5`}),` `,h(`common.delete`)]})]})]})})}c();var yr=[[`plateGallery`]],br=500,xr=120;function Sr({plate:t,cameraName:n,nowMs:r,selected:i,onToggleSelect:o,onAssign:s,onOpenDetail:c}){let{t:u}=Z(),d=l(),f=ve(),p=Pe(),m=()=>{d.invalidateQueries({queryKey:yr})},h=()=>c(t.plateId),v=ur(t);return e(`div`,{className:`relative flex flex-col overflow-hidden rounded-md border bg-surface ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[e(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[v===null?e(`button`,{type:`button`,onClick:h,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:u(`detectionIntelligence.recentPlates.noCropImageThePlate`,`No crop image — the plate's crop media is missing. Safe to delete.`),children:[a(_,{className:`h-7 w-7 text-warning/70`}),a(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:u(`detectionIntelligence.recentPlates.noCrop`,`No crop`)})]}):a(`img`,{src:v,alt:u(`detectionIntelligence.recentPlates.plateFrom`,`Plate {{text}} from {{cameraName}}`,{text:t.text,cameraName:n}),onClick:h,className:`h-full w-full cursor-zoom-in object-cover`}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(t.plateId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?u(`detectionIntelligence.recentPlates.deselect`,`Deselect`):u(`detectionIntelligence.recentPlates.select`,`Select`),children:i?a(ee,{className:`h-4 w-4 text-primary`}):a(k,{className:`h-4 w-4`})}),t.corrected&&e(`span`,{className:`absolute right-0 top-0 z-10 flex items-center gap-0.5 rounded-bl-md bg-primary/80 px-1 py-0.5 text-[8px] font-semibold uppercase tracking-wide text-white`,title:u(`detectionIntelligence.recentPlates.manuallyCorrected`,`Manually corrected`),children:[a(G,{className:`h-3 w-3`}),` `,u(`detectionIntelligence.recentPlates.fixed`)]})]}),e(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[a(`p`,{className:`truncate font-mono text-xs font-bold tracking-wide text-foreground`,title:t.text,children:t.text||`—`}),a(`p`,{className:`truncate text-[10px] text-foreground-subtle`,title:n,children:n}),a(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:dt(t.timestamp,r)}),t.vehicleName&&a(`p`,{className:`truncate text-[10px] font-medium text-primary`,title:t.vehicleName,children:t.vehicleName})]}),e(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[t.assigned?a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),f.mutate({plateId:t.plateId},{onSettled:m})},disabled:f.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":u(`detectionIntelligence.recentPlates.detachPlate`,`Detach plate`),title:u(`detectionIntelligence.recentPlates.detach`,`Detach`),children:f.isPending?a(z,{className:`h-4 w-4 animate-spin`}):a(q,{className:`h-4 w-4`})}):a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s(t.plateId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":u(`detectionIntelligence.recentPlates.assignPlateToVehicle`,`Assign plate to vehicle`),title:u(`detectionIntelligence.recentPlates.assignToVehicle`,`Assign to vehicle`),children:a(g,{className:`h-4 w-4`})}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),p.mutate({plateId:t.plateId},{onSettled:m})},disabled:p.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":u(`detectionIntelligence.recentPlates.deletePlate`,`Delete plate`),title:u(`detectionIntelligence.recentPlates.deletePlate`,`Delete plate`),children:p.isPending?a(z,{className:`h-4 w-4 animate-spin`}):a(N,{className:`h-4 w-4`})})]})]})}var Cr=[{labelKey:`common.all`,value:`all`},{labelKey:`detectionIntelligence.recentPlates.filterUnassigned`,value:`unassigned`},{labelKey:`detectionIntelligence.recentPlates.filterAssigned`,value:`assigned`}];function wr(e,t){return t===`unassigned`?e.filter(e=>!e.assigned):t===`assigned`?e.filter(e=>e.assigned):e}function Tr(){let{t}=Z(),r=l(),[i,o]=s(`all`),[c,d]=s(_t),[f,p]=s(new Set),[h,v]=s(new Set),[y,b]=s(null),[x,S]=s(null),{data:C,isLoading:w}=re({limit:br,includeCrops:!1},{refetchInterval:3e4}),{data:T=[]}=Se(),{data:E}=Me({isCamera:!0,projection:`slim`}),D=ve(),O=Le(),k=Pe(),A=Date.now(),j=C??[],M=n(()=>{let e=new Map;for(let t of E??[])e.set(t.id,t.name);return e},[E]),P=e=>M.get(e)??t(`detectionIntelligence.cameraFallback`,{id:String(e)}),F=n(()=>bt(j).map(e=>({id:e,name:P(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[j,M]),I=n(()=>ut(mt(wr(j,i),c),f),[j,i,c,f]),L=gt(I,xr,n(()=>JSON.stringify([i,c.fromMs,c.toMs,[...f].sort((e,t)=>e-t)]),[i,c.fromMs,c.toMs,f])),R=n(()=>new Map(j.map(e=>[e.plateId,e])),[j]),B=x===null?null:R.get(x)??null,V=()=>{r.invalidateQueries({queryKey:yr})},H=()=>v(new Set);function U(e){v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}let W=[...h],G=O.isPending||k.isPending,K=D.isPending||k.isPending;function J(){W.length!==0&&O.mutate({plateIds:W},{onSettled:()=>{V(),H()}})}function ee(){W.length!==0&&Promise.allSettled(W.map(e=>k.mutateAsync({plateId:e}))).then(()=>{V(),H()})}function te(e){S(null),b([e])}function ne(e){D.mutate({plateId:e},{onSettled:V}),S(null)}function ie(e){k.mutate({plateId:e},{onSettled:V}),S(null)}let ae=I.length!==j.length;return e(`div`,{className:`relative space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[a(`div`,{className:`flex items-center gap-1`,children:Cr.map(e=>a(`button`,{type:`button`,onClick:()=>o(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${i===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:t(e.labelKey)},e.value))}),a(lt,{onChange:d}),a(vt,{cameras:F,selected:f,onChange:p}),!w&&a(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:ae?t(`detectionIntelligence.recentPlates.ofPlates`,`{{value1}} of {{value2}} plates`,{value1:String(I.length),value2:String(j.length)}):t(`detectionIntelligence.recentPlates.plateCount`,{count:I.length})})]}),h.size>0&&e(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[a(`span`,{className:`text-xs font-medium text-foreground`,children:t(`common.selectedCount`,{count:h.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[e(Y,{variant:`primary`,onClick:()=>b(W),disabled:G,children:[a(g,{className:`h-3.5 w-3.5`}),` `,t(`common.assign`)]}),e(Y,{variant:`secondary`,onClick:J,disabled:G,children:[O.isPending?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(q,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.recentPlates.detach`,`Detach`)]}),e(Y,{variant:`secondary`,onClick:ee,disabled:G,children:[a(N,{className:`h-3.5 w-3.5`}),` `,t(`common.delete`)]}),a(Y,{variant:`ghost`,onClick:H,disabled:G,children:a(m,{className:`h-3.5 w-3.5`})})]})]}),w?a(Ge,{status:`pending`,pendingMessage:`Loading plates…`,testId:`plates-grid`}):I.length===0?a(Re,{icon:_,title:j.length>0?t(`detectionIntelligence.recentPlates.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.recentPlates.noPlatesRecognizedYet`,`No plates recognized yet`),description:j.length>0?t(`detectionIntelligence.recentPlates.widenTheDateRangeOr`,`Widen the date range or clear the camera filter.`):t(`detectionIntelligence.recentPlates.plateReadsAppearHereWhen`,`Plate reads appear here when the detection pipeline OCRs a vehicle.`)}):e(u,{children:[a(Ge,{status:`ready`,testId:`plates-grid`,children:L.pageItems.map(e=>a(Sr,{plate:e,cameraName:P(e.deviceId),nowMs:A,selected:h.has(e.plateId),onToggleSelect:U,onAssign:e=>b([e]),onOpenDetail:S},e.plateId))}),a(yt,{currentPage:L.page,totalItems:L.totalItems,pageSize:L.pageSize,onPageChange:L.setPage,itemNoun:`plates`})]}),a(vr,{plate:B,cameraName:B?P(B.deviceId):``,onClose:()=>S(null),onAssign:te,onUnassign:ne,onDelete:ie,actionsPending:K}),a(fr,{plateIds:y,vehicles:T,onDone:()=>{b(null),H()}})]})}c();var Er=[[`plateGallery`]];function Dr({vehicleId:t}){let{t:n}=Z(),r=l(),{data:i,isLoading:o}=Je({vehicleId:t}),s=oe();function c(e){s.mutate({vehicleId:t,sampleId:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:Er})}})}return o?e(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[a(z,{className:`h-3.5 w-3.5 animate-spin`}),n(`detectionIntelligence.vehiclesList.loadingPlates`,`Loading plates…`)]}):!i||i.length===0?a(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:n(`detectionIntelligence.vehiclesList.noPlatesYet`,`No plates yet.`)}):a(`div`,{className:`mt-2 grid grid-cols-3 gap-2 sm:grid-cols-4 md:grid-cols-6`,children:i.map(t=>e(`div`,{className:`group relative overflow-hidden rounded-md border border-border bg-surface`,children:[e(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[t.base64?a(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:t.text,className:`h-full w-full object-cover`}):a(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:a(S,{className:`h-6 w-6`})}),a(`button`,{type:`button`,onClick:()=>c(t),disabled:s.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":n(`detectionIntelligence.vehiclesList.removePlateSample`,`Remove plate sample`),children:a(m,{className:`h-4 w-4 text-white`})})]}),a(`p`,{className:`truncate px-1.5 py-1 text-center font-mono text-[11px] font-semibold tracking-wide text-foreground`,title:t.text,children:t.text})]},t.id))})}function Or(t){return[{key:`vehicle`,header:X.t(`detectionIntelligence.vehiclesList.vehicle`,`Vehicle`),sortValue:e=>e.name,render:t=>e(`span`,{className:`flex min-w-0 items-center gap-2`,children:[a(`span`,{className:`h-8 w-12 shrink-0 overflow-hidden rounded border border-border bg-surface-hover`,children:a(Lt,{mediaId:t.coverMediaId,base64:t.coverBase64,alt:t.name,className:`h-full w-full object-cover`,placeholder:a(`span`,{className:`flex h-full w-full items-center justify-center`,children:a(S,{className:`h-4 w-4 text-foreground-subtle`})})})}),a(`span`,{className:`truncate text-sm font-medium text-foreground`,children:t.name})]})},{key:`samples`,header:X.t(`detectionIntelligence.vehiclesList.plates`,`Plates`),align:`center`,nowrap:!0,sortValue:e=>e.sampleCount,render:e=>a(Ie,{variant:`default`,className:`text-[10px]`,children:e.sampleCount})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:n=>e(`span`,{className:`flex items-center justify-end gap-1`,children:[a(xe,{variant:`ghost`,size:`sm`,icon:F,"aria-label":X.t(`detectionIntelligence.vehiclesList.edit`,`Edit {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onEdit(n)}}),a(xe,{variant:`ghost`,size:`sm`,icon:N,"aria-label":X.t(`detectionIntelligence.vehiclesList.delete`,`Delete {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onDelete(n)}})]})}]}function kr({mode:t,vehicle:n,onClose:r}){let{t:i}=Z(),c=l(),[u,d]=s(t===`edit`?n?.name??``:``),f=Ze(),p=ie();o(()=>{d(t===`edit`?n?.name??``:``)},[t,n?.id,n?.name]);let m=f.isPending||p.isPending,h=u.trim(),g=t===`edit`&&n!==null&&h===n.name,_=m||h.length===0||g;function v(){c.invalidateQueries({queryKey:Er})}function y(){if(!_){if(t===`new`){f.mutate({name:h},{onSuccess:()=>{v(),r()}});return}if(n===null){r();return}p.mutate({id:n.id,name:h},{onSuccess:()=>{v(),r()}})}}return a(Ue,{open:!0,onClose:r,title:t===`new`?`Add vehicle`:`Edit ${n?.name??`vehicle`}`,icon:S,width:t===`edit`?`xl`:`lg`,testId:`vehicles-vehicle-form`,footer:e(Y,{variant:`primary`,size:`sm`,type:`button`,onClick:y,disabled:_,children:[m?a(z,{className:`h-3.5 w-3.5 animate-spin`}):null,t===`new`?i(`common.add`,`Add`):i(`common.save`,`Save`)]}),children:e(`div`,{className:`space-y-4`,children:[a(Ke,{label:i(`detectionIntelligence.vehiclesList.name`,`Name`),required:!0,children:a(Xe,{value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&y()},placeholder:i(`detectionIntelligence.vehiclesList.vehicleName`,`Vehicle name…`),autoFocus:!0})}),t===`edit`&&n!==null&&e(`div`,{children:[a(`p`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:i(`detectionIntelligence.vehiclesList.plateSamples`,`Plate samples`)}),a(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:i(`detectionIntelligence.vehiclesList.removeAPlateCropTo`,`Remove a plate crop to drop it from recognition for this vehicle. Assign new plates from Recent recognized plates.`)}),a(Dr,{vehicleId:n.id})]})]})})}function Ar(){let{t}=Z(),r=l(),i=x(),{data:s,isLoading:c}=Se(),u=Ye(),{state:d,openNew:f,openEdit:p,close:m}=Be(),h=s??[],g=Ce(h,{searchText:e=>[e.name]}),_=d.mode===`edit`?h.find(e=>e.id===d.id)??null:null;o(()=>{d.mode===`edit`&&!c&&_===null&&m()},[d.mode,c,_,m]);let v=n(()=>Or({onEdit:e=>p(e.id),onDelete:e=>{(async()=>{await i({title:t(`detectionIntelligence.vehiclesList.deleteVehicle`,`Delete vehicle`),message:t(`detectionIntelligence.vehiclesList.deleteAndAllItsPlate`,`Delete {{name}} and all its plate samples? This cannot be undone.`,{name:e.name}),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&u.mutate({id:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:Er}),d.mode===`edit`&&d.id===e.id&&m()}})})()}}),[i,m,u,d,p,r,t]);if(c)return e(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[a(z,{className:`h-4 w-4 animate-spin`}),t(`detectionIntelligence.vehiclesList.loadingVehicles`,`Loading vehicles…`)]});let y=d.mode===`new`||d.mode===`edit`&&_!==null;return e(`div`,{className:`space-y-2`,children:[a(`div`,{className:`flex flex-wrap items-center gap-2`,children:e(Y,{variant:`primary`,size:`sm`,type:`button`,onClick:f,children:[a(D,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.vehiclesList.addVehicle`,`Add vehicle`)]})}),(h.length>0||g.active)&&a(ae,{state:g.state,facets:g.facets,labels:{searchPlaceholder:`Search vehicles…`,searchLabel:`Search vehicles`,facetsLabel:`Filter`,clearLabel:`Clear`},onSearch:g.setSearch,onToggleFacet:g.toggleFacet,onClear:g.clear}),g.rows.length===0?a(Re,{icon:S,title:g.active?t(`detectionIntelligence.vehiclesList.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.vehiclesList.noVehiclesEnrolledYet`,`No vehicles enrolled yet`),description:g.active?t(`detectionIntelligence.vehiclesList.clearTheSearchOrTry`,`Clear the search or try another name.`):t(`detectionIntelligence.vehiclesList.addAVehicleThenAssign`,`Add a vehicle, then assign plate crops from Recent recognized plates.`)}):a(et,{columns:v,rows:g.rows,rowKey:e=>e.id,maxBodyHeight:ne,emptyMessage:t(`detectionIntelligence.vehiclesList.noVehiclesEnrolledYet2`,`No vehicles enrolled yet.`),onRowClick:e=>p(e.id)}),y&&a(kr,{mode:d.mode===`new`?`new`:`edit`,vehicle:_,onClose:m})]})}c();var jr=[[`plateGallery`]],Mr=2e3;function Nr(){let e=l(),n=t(e);n.current=e;let r=t(void 0);r.current||=ht({delayMs:Mr,invalidate:()=>{n.current.invalidateQueries({queryKey:jr})}}),o(()=>()=>r.current?.cancel(),[]),ke(B.PipelineAnalyticsPlateGalleryChanged,()=>{r.current?.trigger()})}function Pr(){let{t}=Z();return Nr(),e(`div`,{className:`space-y-3`,children:[a(fe,{headingId:`library-vehicles`,title:t(`plates.vehicles`,`Vehicles`),icon:S,testId:`library-section-vehicles`,children:e(`div`,{className:`${f} space-y-3`,children:[a(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`plates.enrolledVehicleIdentitiesUsedFor`,`Enrolled vehicle identities used for plate recognition. Open a vehicle to rename it or remove plate samples.`)}),a(Ar,{})]})}),a(fe,{headingId:`library-recent-plates`,title:t(`plates.recentRecognizedPlates`,`Recent recognized plates`),icon:K,testId:`library-section-recent-plates`,children:e(`div`,{className:`${f} space-y-3`,children:[a(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`plates.licensePlatesReadByThe`,`License plates read by the detection pipeline. Assign them to a vehicle, correct the OCR text, or delete.`)}),a(Tr,{})]})})]})}function Fr(e){return e.states.length===0?3:e.latched?0:e.verdict===`diverged`?1:e.verdict===`unknown`?2:4}function Ir(e){let t=[e.divergedAt,e.restoredAt].filter(e=>typeof e==`number`);return t.length===0?null:Math.max(...t)}function Lr(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=Fr(e.monitor)-Fr(t.monitor);if(n!==0)return n;let r=Ir(e.monitor)??-1,i=Ir(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})}c();var Rr={alarm:`danger`,ok:`success`,unknown:`default`},zr={alarm:`Alarm`,ok:`OK`,unknown:`Unknown`};function Br(e,t){let n=Ir(e);return n===null?`—`:X.t(`scenes.transitionAgo`,{duration:P(Math.max(0,t-n))})}function Vr(e){return b(e.monitor).tone}function Hr(e){let t=Number(e);return Number.isFinite(t)&&t>0?t:null}function Ur(){let{t}=Z(),i=Me({isCamera:!0,projection:`slim`}),c=n(()=>(i.data??[]).map(e=>({deviceId:e.id,deviceName:e.name})).sort((e,t)=>e.deviceName.localeCompare(t.deviceName)),[i.data]),l=n(()=>c.map(e=>e.deviceId),[c]),u=Et(l),d=n(()=>Lr(c,u.results),[c,u.results]),f=Ce(d,{searchText:e=>[e.monitor.label,e.deviceName],facetValue:Vr}),{state:p,openNew:m,openEdit:h,close:g}=Be(),[_,v]=s(null);o(()=>{if(p.mode===`new`){v(e=>e??l[0]??null);return}v(null)},[p.mode,l]);let y=p.mode===`edit`?Hr(p.id):null,x=y===null?``:c.find(e=>e.deviceId===y)?.deviceName??`#${y}`,S=Date.now(),E=[{key:`label`,header:t(`scenes.scene`,`Scene`),sortValue:e=>e.monitor.label,render:e=>a(`span`,{className:`font-medium`,children:e.monitor.label})},{key:`camera`,header:t(`scenes.camera`,`Camera`),nowrap:!0,sortValue:e=>e.deviceName,render:e=>e.deviceName},{key:`state`,header:t(`scenes.state`,`State`),nowrap:!0,sortValue:e=>Vr(e),render:e=>{let t=b(e.monitor);return a(Ie,{variant:Rr[t.tone],children:t.text})}},{key:`status`,header:t(`scenes.whatItSays`,`What it says`),notSortableReason:`Status is a live sentence, not a comparable value`,render:e=>a(`span`,{className:`text-xs text-foreground-muted`,children:C(e.monitor,S)})},{key:`coverage`,header:t(`scenes.variants`,`Variants`),notSortableReason:`Coverage is a summary string`,render:e=>a(`span`,{className:`text-xs text-foreground-muted`,children:O(e.monitor)})},{key:`transition`,header:t(`scenes.lastChange`,`Last change`),align:`right`,nowrap:!0,sortValue:e=>Ir(e.monitor)??0,render:e=>a(`span`,{className:`text-xs tabular-nums text-foreground-muted`,children:Br(e.monitor,S)})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:e=>a(Y,{variant:`ghost`,onClick:()=>h(String(e.deviceId)),children:t(`scenes.open`,`Open`)})}];return e(`section`,{className:`space-y-3`,children:[e(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between sm:gap-4`,children:[a(`p`,{className:`text-xs text-foreground-subtle`,children:t(`scenes.aSceneWatchesOneRegion`,`A scene watches one region of one camera and tells you when it stops looking like the picture you captured — a wheelie bin, a gate, a parking space.`)}),e(Y,{onClick:m,disabled:c.length===0,className:`shrink-0`,children:[a(D,{className:`mr-1 h-3.5 w-3.5`}),t(`scenes.newScene`,`New scene`)]})]}),u.unreachableCount>0?a(`p`,{className:`text-xs text-warning`,children:t(`scenes.unreachable`,{count:u.unreachableCount})}):null,(d.length>0||f.active)&&a(ae,{state:f.state,facets:f.facets,labels:{searchPlaceholder:`Search scenes…`,searchLabel:`Search scenes`,facetsLabel:`State`,clearLabel:`Clear`},facetLabel:e=>zr[e]??e,onSearch:f.setSearch,onToggleFacet:f.toggleFacet,onClear:f.clear}),a(Fe,{variant:`flat`,className:`p-0`,children:a(et,{columns:E,rows:f.rows,rowKey:e=>`${e.deviceId}:${e.monitor.id}`,minWidthPx:880,bordered:!1,maxBodyHeight:ne,emptyMessage:u.isLoading?t(`scenes.loadingScenes`,`Loading scenes…`):f.active?t(`scenes.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`scenes.noScenesYetPressNew`,`No scenes yet. Press “New scene”, pick a camera, then draw a box around the thing you want watched.`)})}),p.mode===`new`?e(Ue,{open:!0,onClose:g,title:t(`scenes.whichCamera`,`Which camera?`),icon:w,width:`sm`,testId:`scenes-camera-picker`,footer:a(Y,{onClick:()=>{_!==null&&h(String(_))},disabled:_===null,children:t(`scenes.continue`,`Continue`)}),children:[a(`p`,{className:`mb-3 text-xs text-foreground-subtle`,children:t(`scenes.aSceneLivesOnOne`,`A scene lives on one camera. Pick the one that can see the thing.`)}),a(T,{value:_===null?``:String(_),onChange:e=>v(Number(e.target.value)),"aria-label":t(`scenes.camera`,`Camera`),options:c.map(e=>({value:String(e.deviceId),label:e.deviceName}))})]}):null,y===null?null:e(Ue,{open:!0,onClose:g,title:t(`scenes.scenes`,`Scenes — {{editingName}}`,{editingName:x}),icon:w,width:`lg`,testId:`scenes-editor`,children:[a(`p`,{className:`mb-3 text-xs text-foreground-subtle`,children:t(`scenes.drawABoxNameIt`,`Draw a box, name it, then capture what “normal” looks like. Daylight is enough — the night reference is optional, and “Settings” on each scene tunes how fussy and how often it checks.`)}),a(r,{fallback:a(`p`,{className:`text-xs text-foreground-muted`,children:t(`scenes.loadingTheEditor`,`Loading the editor…`)}),children:a(We,{deviceId:y})})]})]})}function Wr(){let{t:e}=Z(),t=it(`/library`,{t:e,isAdmin:!0})??{icon:V,title:e(`nav.library`,`Library`)};return a(ct,{icon:t.icon,title:t.title,subtitle:e(`library.subtitleWithExports`,`People, vehicles, scenes and exports — what detection has recognised, and the clips you rendered.`),defaultSection:`people`,sectionsLabel:`${t.title} sections`,sections:[{id:`people`,label:e(`library.people`,`People`),content:a(lr,{})},{id:`vehicles`,label:e(`library.vehicles`,`Vehicles`),content:a(Pr,{})},{id:`scenes`,label:e(`library.scenes`,`Scenes`),content:a(Ur,{})},{id:`exports`,label:e(`library.exports`,`Exports`),content:a(It,{}),ownedParams:[tt]}]})}export{Wr as LibraryPage};
|