@camstack/addon-admin-ui 1.2.97 → 1.2.99

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/dist/assets/{AddLocationWizard-BINhXZS7.js → AddLocationWizard-BoMdcUqK.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-DklRWpsf.js → AddonCollectionPage-BeuyrbPU.js} +1 -1
  3. package/dist/assets/{Addons-BlK4aHPk.js → Addons-BHwAi_Ds.js} +1 -1
  4. package/dist/assets/{AdminTabs-m0mv8roB.js → AdminTabs-CX9dEC2O.js} +1 -1
  5. package/dist/assets/{AiProfiles-Bf0vUYhe.js → AiProfiles-DlwniNcN.js} +1 -1
  6. package/dist/assets/{BrokerForm-DQuIRxne.js → BrokerForm-B7hzX8rb.js} +1 -1
  7. package/dist/assets/{Build-C6iddP-q.js → Build-tE4EhSaT.js} +1 -1
  8. package/dist/assets/{Capabilities-SGgMXEp2.js → Capabilities-DxVvgAzD.js} +1 -1
  9. package/dist/assets/{CapabilityBadges-E_nzwUDR.js → CapabilityBadges-emVPX4I2.js} +1 -1
  10. package/dist/assets/{Cluster-BH1MR0mW.js → Cluster-JUwg2dkP.js} +1 -1
  11. package/dist/assets/{Data-CsMYu6hZ.js → Data-Cxg1mPBE.js} +1 -1
  12. package/dist/assets/DetectionIntelligence-CbKPyUop.js +1 -0
  13. package/dist/assets/{DeviceAggregateSection-C4L267mZ.js → DeviceAggregateSection-waoppD0W.js} +1 -1
  14. package/dist/assets/{DeviceDetail-CBKhvUx6.js → DeviceDetail-Dci5cbpv.js} +1 -1
  15. package/dist/assets/{Devices-CwNvvhuP.js → Devices-D9II1LJb.js} +1 -1
  16. package/dist/assets/{EmbedPlayerPage-D8PVPO9q.js → EmbedPlayerPage-BttmGIA6.js} +1 -1
  17. package/dist/assets/Events-BjaKZpZf.js +1 -0
  18. package/dist/assets/{FormBuilder-CWNgxAJd.js → FormBuilder-1r_2pkuu.js} +1 -1
  19. package/dist/assets/{Identity-waMHP2rf.js → Identity-BdTuPuKv.js} +1 -1
  20. package/dist/assets/{IntegrationDetail-Dg77zA0m.js → IntegrationDetail-CvxZbTm2.js} +1 -1
  21. package/dist/assets/{Integrations-BjikDhW2.js → Integrations-B5uZQ_hG.js} +1 -1
  22. package/dist/assets/{Integrations-DdYmyIDh.js → Integrations-Dm_ug2n_.js} +1 -1
  23. package/dist/assets/{Logs-DeO7vj6U.js → Logs-ClnZCjgz.js} +1 -1
  24. package/dist/assets/{MotionZonesSettings-_FWLaOPm.js → MotionZonesSettings-BcBzi-j4.js} +1 -1
  25. package/dist/assets/{MyAccess-DpJbIn4L.js → MyAccess-D27HsjNA.js} +1 -1
  26. package/dist/assets/{Network-BEqrSSjr.js → Network-BpaCiAzG.js} +1 -1
  27. package/dist/assets/{NodeAddonsSettingsPanel-CeP5jKWa.js → NodeAddonsSettingsPanel-ptvTM4Ri.js} +1 -1
  28. package/dist/assets/{NodeInferenceDevices-mTYwAPzU.js → NodeInferenceDevices-BOyHlH5j.js} +1 -1
  29. package/dist/assets/{Notifications-D3ABHNFb.js → Notifications-BNZyRpU4.js} +1 -1
  30. package/dist/assets/{Pipeline-u0YUqykM.js → Pipeline-tifFVNvD.js} +1 -1
  31. package/dist/assets/Plates-DS0aJWI5.js +1 -0
  32. package/dist/assets/{PrivacyMaskSettings-jeErpimI.js → PrivacyMaskSettings-CWQfl1TC.js} +1 -1
  33. package/dist/assets/{ProviderIcon-D1f90gAc.js → ProviderIcon-BYY3__KP.js} +1 -1
  34. package/dist/assets/Recordings-DZSmzuAc.js +1 -0
  35. package/dist/assets/{ScanNetworkModal-CJGTvhir.js → ScanNetworkModal-B8lG3NsX.js} +1 -1
  36. package/dist/assets/{SceneMonitorEditor-BnW4ISH0.js → SceneMonitorEditor-Bqwf_0qV.js} +1 -1
  37. package/dist/assets/{Scenes-DgDZ2ncX.js → Scenes-Cwmh_GbN.js} +1 -1
  38. package/dist/assets/{Settings-unTatcd_.js → Settings-D_2-xI9-.js} +1 -1
  39. package/dist/assets/{Showroom-C0ifRVPW.js → Showroom-Cl7eIhbG.js} +1 -1
  40. package/dist/assets/{Terminal-CE3rs2os.js → Terminal-CFwukkqI.js} +1 -1
  41. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-C9yqrnn_.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CI4I2cYP.js} +1 -1
  42. package/dist/assets/{bell-ring-ySHjfKbj.js → bell-ring-CsQYceF5.js} +1 -1
  43. package/dist/assets/{boxes-3rK9DhRd.js → boxes-6foKhsHw.js} +1 -1
  44. package/dist/assets/{build-cluster-graph-CGpouoQb.js → build-cluster-graph-Ccj9w__U.js} +1 -1
  45. package/dist/assets/circle-check-big-B8rnDG8h.js +1 -0
  46. package/dist/assets/{circle-x-CCD4C3g3.js → circle-x-Bf5Kcelv.js} +1 -1
  47. package/dist/assets/clock-DnzOV8EI.js +1 -0
  48. package/dist/assets/{copy-iQELk1hh.js → copy-B4N78LE2.js} +1 -1
  49. package/dist/assets/{debounced-invalidate-DuIdhnb0.js → debounced-invalidate-BvcuJvDz.js} +1 -1
  50. package/dist/assets/dist-CXnx4jTF.js +349 -0
  51. package/dist/assets/{dist-DrcsVsFK.js → dist-D-Jc8U0i.js} +1 -1
  52. package/dist/assets/{download-gb-TEWAX.js → download-BsBZ8S8R.js} +1 -1
  53. package/dist/assets/face-bbox-CG7h6fE-.js +1 -0
  54. package/dist/assets/{hostInit-4OS6KPom.js → hostInit-D01Z23QG.js} +1 -1
  55. package/dist/assets/{index-DkufJo5r.js → index-CUen2nrR.js} +3 -3
  56. package/dist/assets/{key-round-1PZwTEUy.js → key-round-B46YLw7m.js} +1 -1
  57. package/dist/assets/{mf-entry-bootstrap-0-1c1f91b8.js → mf-entry-bootstrap-0-063874c6.js} +2 -2
  58. package/dist/assets/{pencil-CLA68sNA.js → pencil-BQJAwzya.js} +1 -1
  59. package/dist/assets/play-DoOoBM0P.js +1 -0
  60. package/dist/assets/{player-overlays-C6s8h_4Y.js → player-overlays-BDZbxeCH.js} +1 -1
  61. package/dist/assets/plus-DDGOU54V.js +1 -0
  62. package/dist/assets/power-DmlMC-7S.js +1 -0
  63. package/dist/assets/{radio-T1V7hUcz.js → radio-DpeKwLzo.js} +1 -1
  64. package/dist/assets/{refresh-cw-CUau8U5z.js → refresh-cw-DLQxYBTF.js} +1 -1
  65. package/dist/assets/remoteEntry-Dm-Wta47.js +1 -0
  66. package/dist/assets/rotate-ccw-wXYD6bC7.js +1 -0
  67. package/dist/assets/rotate-cw-ClC0Tfzf.js +1 -0
  68. package/dist/assets/search-C1UMvnoJ.js +1 -0
  69. package/dist/assets/{send-zhtZvSfs.js → send-SvrrXT_D.js} +1 -1
  70. package/dist/assets/{server-CXynRDpL.js → server-ZhEvwONi.js} +1 -1
  71. package/dist/assets/{shield-D7sORCj4.js → shield-4rMaNiMB.js} +1 -1
  72. package/dist/assets/{square-check-big-B4Eh45MV.js → square-check-big-B3-8gxk1.js} +1 -1
  73. package/dist/assets/square-ookqWTBx.js +1 -0
  74. package/dist/assets/{src-BJefDdNe.js → src-BO2615nJ.js} +3 -3
  75. package/dist/assets/src-BgxUlUk-.js +349 -0
  76. package/dist/assets/{star-lyXpX0iL.js → star-BwlNFxIs.js} +1 -1
  77. package/dist/assets/{undo-2-cT7lldww.js → undo-2-DqcWKrwk.js} +1 -1
  78. package/dist/assets/{upload-DFkrbZ-3.js → upload-C7vU_A2m.js} +1 -1
  79. package/dist/assets/{use-scenes-feed-BOHFSxkZ.js → use-scenes-feed-8dvuhS6R.js} +1 -1
  80. package/dist/assets/useEventInvalidation-BEgRNMRl.js +1 -0
  81. package/dist/assets/{video-B4oO-6iS.js → video-CWHO5MEy.js} +1 -1
  82. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BIJq0x6k.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CBSniS6c.js} +2 -2
  83. package/dist/assets/{wifi-DRVqWiT8.js → wifi-BUxK1DpB.js} +1 -1
  84. package/dist/assets/{zap-D1BDB0by.js → zap-C6IN4srQ.js} +1 -1
  85. package/dist/index.html +5 -5
  86. package/dist/server/addon.js +74 -36
  87. package/package.json +1 -1
  88. package/dist/assets/DetectionIntelligence-BLDn9h8b.js +0 -1
  89. package/dist/assets/Events-CX36Hzz7.js +0 -1
  90. package/dist/assets/Plates-h2kbFnWA.js +0 -1
  91. package/dist/assets/Recordings-Bupa-J0S.js +0 -1
  92. package/dist/assets/circle-check-big-DZ6kfKbc.js +0 -1
  93. package/dist/assets/clock-C8y1RuCX.js +0 -1
  94. package/dist/assets/dist-B30oVI05.js +0 -349
  95. package/dist/assets/face-bbox-BXEzHS8o.js +0 -1
  96. package/dist/assets/play-zgy3rVP8.js +0 -1
  97. package/dist/assets/plus-BuuQxDX-.js +0 -1
  98. package/dist/assets/power-ClWwa12v.js +0 -1
  99. package/dist/assets/remoteEntry-BK9_KzZc.js +0 -1
  100. package/dist/assets/rotate-ccw-DU9po2go.js +0 -1
  101. package/dist/assets/rotate-cw-CF87z69a.js +0 -1
  102. package/dist/assets/search-BrDukCgH.js +0 -1
  103. package/dist/assets/square-D0Tv7x37.js +0 -1
  104. package/dist/assets/src-izCXHk1w.js +0 -349
  105. package/dist/assets/useEventInvalidation-hJIywZi2.js +0 -1
@@ -1 +0,0 @@
1
- import{I as e,K as t,Q as n,S as r,W as i,b as a,o,q as s,x as c,z as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as u}from"./player-overlays-C6s8h_4Y.js";import{At as d,Br as f,Dt as p,Et as m,Fs as h,It as g,Lt as _,Nt as v,Ot as y,Pt as b,ai as x,ci as S,di as C,fi as w,ii as T,kt as E,li as D,ln as O,ni as k,oi as A,pi as j,ri as M,si as N,ti as P,ui as F,wt as I}from"./src-BJefDdNe.js";import{Rt as L}from"./src-izCXHk1w.js";import{a as R,i as z,n as B,r as V,t as H}from"./face-bbox-BXEzHS8o.js";import{a as U,c as ee,f as W,i as G,l as te,m as ne,n as K,o as re,p as q,r as ie,s as ae,t as oe,u as se}from"./debounced-invalidate-DuIdhnb0.js";import{t as ce}from"./pencil-CLA68sNA.js";import{t as le}from"./plus-BuuQxDX-.js";import{t as ue}from"./refresh-cw-CUau8U5z.js";import{t as de}from"./rotate-cw-CF87z69a.js";import{t as fe}from"./square-check-big-B4Eh45MV.js";import{t as pe}from"./square-D0Tv7x37.js";import{t as me}from"./undo-2-cT7lldww.js";import{C as J,I as Y,K as X,R as he,h as ge,i as Z,l as _e,o as ve,s as ye,z as be}from"./index-DkufJo5r.js";import{t as xe}from"./AdminPage-CCD07UMs.js";import{r as Se,t as Ce}from"./authed-media-BPd_L9jr.js";var we=X(`image-plus`,[[`path`,{d:`M16 5h6`,key:`1vod17`}],[`path`,{d:`M19 2v6`,key:`4bpg5p`}],[`path`,{d:`M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5`,key:`1ue2ih`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}]]),Te=X(`user-round`,[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]]);n();var Ee=`pipeline-analytics`,De=`photo.analyze`,Oe=`photo.enroll`,ke=`photo.discard`,Ae=18*1024*1024;function je(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 Me(e,t){let n=e[t];return typeof n==`boolean`?n:null}function Ne(e){if(!je(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 Pe(e){if(!je(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 Fe(e){if(!je(e))return null;let t=$(e,`faceIndex`),n=$(e,`score`),r=Me(e,`enrollable`),i=Ne(e.bbox),a=Pe(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 Ie(e){if(!je(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=Fe(e);t!==null&&i.push(t)}return{sessionId:t,ranOnNodeId:n,faces:i}}function Le(e){if(!je(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 Re(e,t,n){let r={...e};return n===null||n===``?delete r[t]:r[t]=n,r}function ze(e,t){return e.filter(e=>e.enrollable&&t[e.faceIndex]!==void 0).length}function Be(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 Ve(e){switch(e){case`no-embedding`:return`Too small or too indistinct for the recognizer to measure — try a photo where this face is larger.`;case`no-model-id`:return`The recognizer did not report which model it used, so this face cannot be enrolled safely.`;case`no-aligned-crop`:return`The recognizer produced no aligned crop for this face, so there is nothing to store.`;case`magnitude`:return`Refused by the quality gate: the features look degenerate, and a sample like this matches everybody.`;default:return`This face is not usable as a sample.`}}function He(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 Ue(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 We(e,t,n){return e.map(e=>e.photoIndex===t?{...e,...n}:e)}function Ge(e,t){return`${e}:${t}`}function Ke(e,t,n,r){let i=Re(e[t]??{},n,r),a={...e};return Object.keys(i).length===0?delete a[t]:a[t]=i,a}function qe(e,t){let n=0;for(let r of e)r.analysis!==void 0&&(n+=ze(r.analysis.faces,t[r.photoIndex]??{}));return n}var Je=`__new__`;function Ye(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[Ge(i.photoIndex,t.faceIndex)]??``).trim();if(a===``)return{kind:`error`,message:`${i.filename}: face ${t.faceIndex+1} is set to a new person but has no name.`};r.includes(a)||r.push(a)}}return{kind:`ok`,names:r}}function Xe(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[Ge(e,a)]??``).trim()];s!==void 0&&(o[a]=s)}r[e]=o}return r}function Ze(e,t){let n=[];for(let r of e){if(r.analysis===void 0)continue;let e=Be(r.analysis.sessionId,r.analysis.faces,t[r.photoIndex]??{});for(let t of e)n.push({photoIndex:r.photoIndex,request:t})}return n}function Qe(e){return/expired/i.test(e)}function $e(e){return e instanceof Error?e.message:String(e)}async function et(e,t,n){let r=new Map(e.map(e=>[e.photoIndex,e])),i={},a=[],o=0,s=null,c=(e,t)=>`${r.get(e)?.filename??`photo ${e+1}`}, face ${t+1}`;for(let l of Ze(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=$e(t);if(!Qe(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 (${$e(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)}: ${$e(e)}`)}}}return{enrolled:o,stampedModelId:s,failures:a,refreshedAnalyses:i}}var tt=[[`faceGallery`]],nt=``;function rt(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 it(e){return e instanceof Error?e.message:String(e)}function at({face:e,identities:t,value:n,onChange:o,disabled:s}){let l=i(()=>[{value:nt,label:`Ignore this face`},...t.map(e=>({value:e.id,label:e.name})),{value:Je,label:`+ New person…`}],[t]);return r(`div`,{className:`rounded-md border border-border bg-surface p-2`,children:[c(`div`,{className:`mb-2 aspect-square w-full overflow-hidden rounded border border-border bg-surface-hover`,children:e.alignedCropBase64?c(`img`,{src:`data:image/jpeg;base64,${e.alignedCropBase64}`,alt:`Face ${e.faceIndex+1}`,className:`h-full w-full object-cover`}):c(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:c(Te,{className:`h-8 w-8`})})}),e.enrollable?r(a,{children:[c(v,{options:l,value:n,disabled:s,onChange:e=>o(e.target.value),"aria-label":`Assign face ${e.faceIndex+1}`}),r(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:[Math.round(e.quality.detectionShortSidePx),` px`,e.modelId?` · ${e.modelId}`:``]})]}):r(`div`,{className:`space-y-1`,children:[c(g,{variant:`warning`,className:`text-[10px]`,children:`Not usable`}),c(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:Ve(e.refusedReason)})]})]})}function ot({photo:e,identities:t,draft:n,newNames:i,disabled:a,onAssign:o,onNameChange:s,onRetry:l}){let u=e.analysis?.faces??[],d=n[e.photoIndex]??{};return r(`div`,{className:`space-y-2`,children:[r(`div`,{className:`flex items-center gap-2 border-b border-border pb-1`,children:[c(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.filename}),e.status===`analyzing`||e.status===`queued`?r(`span`,{className:`flex items-center gap-1 text-xs text-foreground-subtle`,children:[c(J,{className:`h-3 w-3 animate-spin`}),` analysing…`]}):null,e.status===`analyzed`&&e.analysis!==void 0&&r(`span`,{className:`text-xs text-foreground-subtle`,children:[u.length,` face`,u.length===1?``:`s`,` · analysed on`,` `,e.analysis.ranOnNodeId]}),e.status===`failed`&&r(_,{variant:`secondary`,size:`sm`,disabled:a,onClick:l,children:[c(de,{className:`h-3 w-3`}),` Retry`]})]}),e.status===`failed`&&r(`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:[c(ve,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),r(`span`,{children:[`This photo could not be analysed: `,e.error??`unknown error`,`. The other photos are unaffected.`]})]}),e.status===`analyzed`&&u.length===0&&c(`p`,{className:`text-xs text-foreground-subtle`,children:`No faces were found in this photo. A face has to be reasonably large and facing the camera for the detector to measure it.`}),u.length>0&&c(`div`,{className:`grid grid-cols-3 gap-3 sm:grid-cols-4 md:grid-cols-5`,children:u.map(e=>c(at,{face:e,identities:t,value:d[e.faceIndex]??nt,disabled:a,onChange:t=>o(e.faceIndex,t)},e.faceIndex))}),u.filter(e=>d[e.faceIndex]===Je).map(t=>r(`div`,{className:`flex items-center gap-2`,children:[r(`span`,{className:`w-28 shrink-0 truncate text-xs text-foreground-subtle`,children:[`Face `,t.faceIndex+1]}),c(`input`,{className:`h-7 flex-1 rounded-md border border-border bg-surface px-2.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,placeholder:`New person name… (type the same name under another face to reuse it)`,value:i[Ge(e.photoIndex,t.faceIndex)]??``,onChange:e=>s(t.faceIndex,e.target.value)})]},t.faceIndex))]})}function st({open:n,onOpenChange:a}){let l=u(),f=o(),h=t(null),{data:g}=A(),v=k(),[b,x]=s([]),[S,C]=s(!1),[w,T]=s(null),[D,O]=s({}),[j,M]=s({}),[N,P]=s(null),F=i(()=>(g??[]).map(e=>({id:e.id,name:e.name})),[g]),L=b.some(e=>e.status===`queued`||e.status===`analyzing`),R=L||S,z=e(e=>{for(let t of e){let e=t.analysis?.sessionId;e!==void 0&&l.trpcClient.addons.custom.mutate({addonId:Ee,action:ke,input:{sessionId:e}}).catch(()=>void 0)}},[l]),B=e(()=>{x([]),O({}),M({}),T(null),P(null),h.current&&(h.current.value=``)},[]),V=e(()=>{z(b),B(),a(!1)},[z,a,b,B]),H=e(async e=>{let t=Ie(await l.trpcClient.addons.custom.mutate({addonId:Ee,action:De,input:{photoBase64:e.photoBase64,filename:e.filename}}));if(t===null)throw Error(`the server replied with something this page could not read`);return t},[l]),U=e(async e=>{x(t=>We(t,e.photoIndex,{status:`analyzing`,error:void 0}));try{let t=await H(e);x(n=>We(n,e.photoIndex,{status:`analyzed`,analysis:t}))}catch(t){x(n=>We(n,e.photoIndex,{status:`failed`,error:it(t)}))}},[H]),ee=e(async e=>{if(e.length===0)return;z(b),B();let t=He(e,{maxCount:12,maxBytes:Ae}),n=[];t.oversize.length>0&&n.push(`Over the ${Math.round(Ae/(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&&T(n.join(` `));let r;try{r=await Promise.all(t.accepted.map(async(e,t)=>({photoIndex:t,filename:e.name,photoBase64:await rt(e),status:`queued`})))}catch(e){T(it(e));return}x(r),await Ue(r,2,e=>U(e))},[z,b,B,U]),W=qe(b,D),G=e(async()=>{C(!0),T(null),P(null);try{let e=Ye(b,D,j);if(e.kind===`error`){T(e.message);return}let t={};for(let n of e.names)t[n]=(await v.mutateAsync({name:n})).id;let n=await et(b,Xe(D,j,t),{enroll:async e=>{let t=Le(await l.trpcClient.addons.custom.mutate({addonId:Ee,action:Oe,input:e}));if(t===null)throw Error(`unreadable reply`);return t},reanalyze:e=>H(e)});Object.keys(n.refreshedAnalyses).length>0&&x(e=>e.map(e=>{let t=n.refreshedAnalyses[e.photoIndex];return t===void 0?e:{...e,status:`analyzed`,analysis:t}})),f.invalidateQueries({queryKey:tt}),n.failures.length>0&&T(n.failures.join(` · `)),P(n.enrolled===0?`Nothing was enrolled.`:`Enrolled ${n.enrolled} sample${n.enrolled===1?``:`s`}${n.stampedModelId===null?``:` with ${n.stampedModelId}`}.`)}catch(e){T(it(e))}finally{C(!1)}},[H,v,D,j,b,f,l]),te=b.filter(e=>e.status===`analyzed`).length;return c(I,{open:n,onOpenChange:e=>e?a(!0):V(),children:r(m,{className:`max-w-3xl`,children:[r(E,{children:[c(d,{children:`Enrol from photos`}),c(p,{children:`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.`})]}),r(`div`,{className:`rounded-md border border-border bg-surface-hover px-3 py-2 text-xs text-foreground-subtle`,children:[`For reliable recognition use `,c(`strong`,{children:`at least 3 photos per person`}),`, taken at different times, with different poses and lighting — you can select them all at once. Several frames from the same moment count as one — they do not add information.`]}),r(`div`,{className:`flex items-center gap-2`,children:[c(`input`,{ref:h,type:`file`,accept:`image/jpeg,image/png,image/webp`,multiple:!0,className:`hidden`,onChange:e=>void ee(Array.from(e.target.files??[]))}),r(_,{variant:`secondary`,size:`sm`,disabled:R,onClick:()=>h.current?.click(),children:[L?c(J,{className:`h-3.5 w-3.5 animate-spin`}):c(we,{className:`h-3.5 w-3.5`}),`Choose photos`]}),b.length>0&&r(`span`,{className:`text-xs text-foreground-subtle`,children:[te,`/`,b.length,` photo`,b.length===1?``:`s`,` analysed`]})]}),w!==null&&r(`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:[c(ve,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),c(`span`,{children:w})]}),N!==null&&c(`div`,{className:`rounded-md border border-success/40 bg-success/10 px-3 py-2 text-xs text-success`,children:N}),b.length>0&&c(`div`,{className:`max-h-[50vh] space-y-4 overflow-y-auto pr-1`,children:b.map(e=>c(ot,{photo:e,identities:F,draft:D,newNames:j,disabled:R,onAssign:(t,n)=>O(r=>Ke(r,e.photoIndex,t,n===nt?null:n)),onNameChange:(t,n)=>M(r=>({...r,[Ge(e.photoIndex,t)]:n})),onRetry:()=>void U(e)},e.photoIndex))}),r(y,{children:[c(_,{variant:`secondary`,onClick:V,disabled:S,children:`Close`}),r(_,{variant:`primary`,onClick:()=>void G(),disabled:R||W===0,children:[S?c(J,{className:`h-3.5 w-3.5 animate-spin`}):null,`Enrol `,W,` face`,W===1?``:`s`]})]})]})})}n();var ct=[[`faceGallery`]];function lt({identityId:e}){let t=o(),{data:n,isLoading:i}=N({identityId:e}),a=D();function s(n){a.mutate({identityId:e,sampleId:n.id},{onSettled:()=>{t.invalidateQueries({queryKey:ct})}})}return i?r(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[c(J,{className:`h-3.5 w-3.5 animate-spin`}),`Loading samples…`]}):!n||n.length===0?c(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No samples yet.`}):c(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:n.map(e=>r(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[e.base64?c(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Sample`,className:`h-full w-full object-cover`}):c(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:c(Te,{className:`h-6 w-6`})}),e.source===`photo`&&c(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 p-0.5 text-white`,title:`Enrolled from an uploaded photo`,children:c(we,{className:`h-3 w-3`})}),c(`button`,{type:`button`,onClick:()=>s(e),disabled:a.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":`Remove sample`,children:c(Z,{className:`h-4 w-4 text-white`})})]},e.id))})}function ut({identity:e,expanded:t,onToggle:n}){let i=o(),[l,u]=s(``),[f,h]=s(!1),[v,x]=s(!1),S=F(),C=T();function w(){u(e.name),h(!0)}function D(){h(!1),u(``)}function O(){let t=l.trim();if(!t||t===e.name){D();return}S.mutate({id:e.id,name:t},{onSettled:()=>{i.invalidateQueries({queryKey:ct}),D()}})}function k(){C.mutate({id:e.id},{onSettled:()=>{i.invalidateQueries({queryKey:ct}),x(!1)}})}return r(`div`,{className:`rounded-md border border-border bg-surface`,children:[r(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[c(`div`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:e.coverBase64?c(`img`,{src:`data:image/jpeg;base64,${e.coverBase64}`,alt:e.name,className:`h-full w-full object-cover`}):c(`div`,{className:`flex h-full w-full items-center justify-center`,children:c(Te,{className:`h-4 w-4 text-foreground-subtle`})})}),c(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:f?r(a,{children:[c(b,{value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&O(),e.key===`Escape`&&D()},className:`h-6 text-xs`,autoFocus:!0}),c(`button`,{type:`button`,onClick:O,disabled:S.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:c(be,{className:`h-3.5 w-3.5`})}),c(`button`,{type:`button`,onClick:D,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:c(Z,{className:`h-3.5 w-3.5`})})]}):c(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),c(g,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!f&&r(`div`,{className:`flex items-center gap-1`,children:[c(`button`,{type:`button`,onClick:w,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:c(ce,{className:`h-3.5 w-3.5`})}),c(`button`,{type:`button`,onClick:()=>x(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:c(ye,{className:`h-3.5 w-3.5`})})]}),c(`button`,{type:`button`,onClick:n,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":t?`Collapse`:`Expand`,children:c(t?he:Y,{className:`h-3.5 w-3.5`})})]}),t&&c(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:c(lt,{identityId:e.id})}),c(I,{open:v,onOpenChange:e=>!e&&x(!1),children:r(m,{children:[r(E,{children:[c(d,{children:`Delete person`}),r(p,{children:[`Delete `,c(`strong`,{children:e.name}),` and all their samples? This cannot be undone.`]})]}),r(y,{children:[c(_,{variant:`secondary`,onClick:()=>x(!1),children:`Cancel`}),r(_,{variant:`danger`,onClick:k,disabled:C.isPending,children:[C.isPending?c(J,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function dt(){let e=o(),[t,n]=s(``),i=k();function a(){let r=t.trim();r&&i.mutate({name:r},{onSettled:()=>{e.invalidateQueries({queryKey:ct}),n(``)}})}return r(`div`,{className:`flex items-center gap-2 pt-2`,children:[c(b,{placeholder:`New person name…`,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&a()},className:`h-7 text-xs flex-1`}),r(_,{variant:`primary`,size:`sm`,onClick:a,disabled:i.isPending||!t.trim(),children:[i.isPending?c(J,{className:`h-3.5 w-3.5 animate-spin`}):c(le,{className:`h-3.5 w-3.5`}),`Add`]})]})}function ft(){let{data:e,isLoading:t}=A(),[n,i]=s(null),[a,o]=s(!1);function l(e){i(t=>t===e?null:e)}return t?r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[c(J,{className:`h-4 w-4 animate-spin`}),`Loading people…`]}):r(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&c(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No people enrolled yet. Add one below.`}),e?.map(e=>c(ut,{identity:e,expanded:n===e.id,onToggle:()=>l(e.id)},e.id)),c(dt,{}),c(`div`,{className:`pt-1`,children:r(_,{variant:`secondary`,size:`sm`,onClick:()=>o(!0),children:[c(we,{className:`h-3.5 w-3.5`}),`Enrol from a photo`]})}),c(st,{open:a,onOpenChange:o})]})}function pt(e){let t=e.cropUrl!==void 0&&e.cropUrl.length>0,n=e.base64!==void 0&&e.base64.length>0;return!t&&!n}function mt(e){return e.filter(pt).map(e=>e.faceId)}function ht(e){let t=0;for(let n of e)pt(n)&&(t+=1);return t}function gt(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}n();var _t=[[`faceGallery`]];function vt({faceIds:e,identities:t,onDone:n}){let i=o(),a=P(),l=k(),[u,f]=s(``),[h,g]=s(!1),[v,x]=s(null),S=e!==null&&e.length>0,C=e?.length??0;function w(){g(!1),f(``),x(null)}function T(){w(),n()}function D(t){!e||e.length===0||a.mutate({faceIds:[...e],identityId:t},{onSettled:()=>{i.invalidateQueries({queryKey:_t}),T()}})}function O(){!e||!u.trim()||l.mutate({name:u.trim()},{onSuccess:e=>{e?.id&&D(e.id)},onError:()=>{i.invalidateQueries({queryKey:_t}),T()}})}let A=a.isPending||l.isPending;return c(I,{open:S,onOpenChange:e=>!e&&T(),children:r(m,{children:[r(E,{children:[c(d,{children:C>1?`Assign ${String(C)} faces to person`:`Assign face to person`}),c(p,{children:`Select an existing person or create a new one.`})]}),c(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:t.map(e=>r(`button`,{type:`button`,onClick:()=>x(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${v===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[c(`span`,{className:`font-medium`,children:e.name}),r(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` samples`]})]},e.id))}),h?c(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:c(b,{placeholder:`New person name…`,value:u,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&O()},autoFocus:!0,className:`flex-1`})}):c(`button`,{type:`button`,onClick:()=>{x(null),g(!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:`+ New person…`}),r(y,{children:[c(_,{variant:`secondary`,onClick:T,disabled:A,children:`Cancel`}),h?r(_,{variant:`primary`,onClick:O,disabled:A||!u.trim(),children:[A&&c(J,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):r(_,{variant:`primary`,onClick:()=>v&&D(v),disabled:A||!v,children:[A&&c(J,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,C>1?` ${String(C)}`:``]})]})]})})}n();function yt(e){let[t,n]=s(null),[r,i]=s(null),[a,o]=s(!1);return l(()=>{if(n(null),i(null),o(!1),!e)return;let t=!1,r=null;return(async()=>{try{let i=await Se(`${Ce}/${encodeURIComponent(e)}`);if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||o(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),l(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>o(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function bt(e){let t=e.filter(e=>e.base64.length>0);return t.length===0?null:t.find(e=>/crop|face/i.test(e.kind))??t[0]}function xt({label:e,value:t}){return r(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[c(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),c(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground`,children:t})]})}function St({box:e}){return c(`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:c(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:`Face`})})}function Ct({face:e,cameraName:t,onClose:n,onAssign:a,onUnassign:o,onDelete:l,actionsPending:u}){let{data:d,isFetching:f}=x({faceId:e?.faceId??``},{enabled:e!==null}),[p,h]=s(`frame`),{frameSrc:g,naturalWidth:v,naturalHeight:y,failed:b}=yt(e?.keyFrameMediaKey),S=i(()=>{let t=bt(d??[]);return t?`data:image/jpeg;base64,${t.base64}`:gt(e)},[d,e]),C=i(()=>!e?.faceBbox||v===null||y===null?null:H(e.faceBbox,v,y),[e?.faceBbox,v,y]);if(e===null)return null;let w=typeof e.keyFrameMediaKey==`string`&&e.keyFrameMediaKey.length>0&&!b,T=w&&p===`frame`,E=e.assigned?e.identityName??`Assigned`:e.recognizedIdentityId?`${e.identityName??`Recognized`} (suggested)`:`Unassigned`;return c(I,{open:!0,onOpenChange:e=>!e&&n(),children:r(m,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`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:[r(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[r(`div`,{className:`min-w-0`,children:[c(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:`Face detail`}),c(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]}),c(`button`,{type:`button`,onClick:n,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:c(Z,{className:`h-4 w-4`})})]}),r(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[w&&r(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[r(`button`,{type:`button`,onClick:()=>h(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${p===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[c(z,{className:`h-3.5 w-3.5`}),` Full frame`]}),r(`button`,{type:`button`,onClick:()=>h(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${p===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[c(R,{className:`h-3.5 w-3.5`}),` Crop`]})]}),T&&g?c(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:c(K,{src:g,alt:`Full frame with detected face`,fit:`natural`,className:`w-full`,overlay:C?c(St,{box:C}):void 0})}):S?r(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[c(K,{src:S,alt:`Detected face`,className:`h-full w-full`}),f&&c(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:c(J,{className:`h-3.5 w-3.5 animate-spin`})})]}):r(`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:[c(ne,{className:`h-8 w-8 text-warning/70`}),c(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:`No image`}),c(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:`The crop media for this face could not be resolved (a pre-fix orphan). Safe to delete.`})]}),r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[c(xt,{label:`Camera`,value:t}),c(xt,{label:`Captured`,value:q(e.timestamp)}),c(xt,{label:`Track`,value:e.trackId}),c(xt,{label:`Identity`,value:E})]})]}),r(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[e.assigned?r(_,{variant:`secondary`,onClick:()=>o(e.faceId),disabled:u,children:[c(B,{className:`h-3.5 w-3.5`}),` Detach`]}):r(_,{variant:`primary`,onClick:()=>a(e.faceId),disabled:u,children:[c(V,{className:`h-3.5 w-3.5`}),` Assign`]}),r(_,{variant:`secondary`,onClick:()=>l(e.faceId),disabled:u,children:[c(ye,{className:`h-3.5 w-3.5`}),` Delete`]})]})]})})}function wt(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function Tt(e,t){return e.faceIds.filter(e=>!t.has(e))}function Et(e,t){return e.faceIds.filter(e=>t(e))}n();var Dt=[[`faceGallery`]],Ot=20,kt=.3,At=.9,jt=.05,Mt=.5,Nt=2,Pt=10,Ft=2;function It({cluster:e,face:t,active:n,onSelect:i}){let a=gt(t);return r(`button`,{type:`button`,onClick:i,className:`flex shrink-0 flex-col items-center gap-1.5 rounded-md border p-2 text-center transition-colors md:w-full md:flex-row md:gap-2.5 md:text-left ${n?`border-primary bg-primary/8`:`border-border bg-surface hover:bg-surface-hover`}`,children:[c(`div`,{className:`h-24 w-24 shrink-0 overflow-hidden rounded bg-surface-hover`,children:a===null?c(ne,{className:`h-24 w-24 p-6 text-foreground-subtle`}):c(`img`,{src:a,alt:``,loading:`lazy`,decoding:`async`,className:`h-24 w-24 object-cover`})}),r(`span`,{className:`w-24 text-[11px] leading-tight text-foreground-subtle md:w-auto`,children:[e.size,` faces · `,Math.round(e.cohesion*100),`% alike`]})]})}function Lt({face:e,cameraName:t,nowMs:n,excluded:i,onToggleExclude:a,onDelete:o,deletePending:s}){let l=gt(e);return r(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden transition-opacity ${i?`border-border opacity-40 grayscale`:`border-border`}`,children:[r(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[l===null?r(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,children:[c(ne,{className:`h-7 w-7 text-warning/70`}),c(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}):c(K,{src:l,alt:`Face from ${t}`,className:`h-full w-full`}),c(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a()},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?`Include face`:`Exclude face`,title:i?`Include`:`Exclude`,children:c(i?me:Z,{className:`h-3.5 w-3.5`})})]}),r(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[c(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),c(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:W(e.timestamp,n)})]}),c(`div`,{className:`mt-1 flex items-center justify-end border-t border-border/60 px-1 py-0.5`,children:c(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o()},disabled:s,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":`Delete face`,title:`Delete face`,children:s?c(J,{className:`h-4 w-4 animate-spin`}):c(ye,{className:`h-4 w-4`})})})]})}function Rt({open:e,onClose:t,byId:n,cameraName:u,nowMs:d,identities:f,selectMany:p}){let h=o(),g=O(),v=M(),[y,b]=s(Mt),[x,S]=s(Ft),[w,T]=s(null),[E,D]=s({}),[k,A]=s(null),{data:j,isFetching:N,refetch:P}=C({threshold:y,minClusterSize:x,limit:Ot},{enabled:e}),F=j??[];l(()=>{D({})},[y,x]),l(()=>{if(F.length===0){T(null);return}F.some(e=>e.representativeFaceId===w)||T(F[0]?.representativeFaceId??null)},[F]);let L=i(()=>F.find(e=>e.representativeFaceId===w)??null,[F,w]),R=L?E[L.representativeFaceId]??new Set:new Set,z=i(()=>L?Et(L,e=>n.has(e)):[],[L,n]),B=L?L.faceIds.length-z.length:0,H=L?Tt({...L,faceIds:z},R):[];function U(e){if(!L)return;let t=L.representativeFaceId;D(n=>({...n,[t]:wt(n[t]??new Set,e)}))}function ee(){h.invalidateQueries({queryKey:Dt})}async function W(e){await g({title:`Delete face`,message:`Permanently deletes this face crop. This cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&v.mutate({faceId:e},{onSettled:ee})}function G(){A(null),t()}function te(){H.length!==0&&(p(H),G())}return r(I,{open:e,onOpenChange:e=>!e&&G(),children:[r(m,{placement:`sheet-on-mobile`,width:`lg`,"aria-label":`Look-alike groups`,className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 md:max-w-4xl`,children:[r(`header`,{className:`flex shrink-0 flex-col gap-2 border-b border-border px-4 py-3`,children:[r(`div`,{className:`flex items-center justify-between gap-2`,children:[r(`div`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[c(_e,{className:`h-4 w-4 text-primary`}),` Look-alike groups`]}),c(`button`,{type:`button`,onClick:G,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:c(Z,{className:`h-4 w-4`})})]}),r(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[r(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Threshold`,c(`input`,{type:`range`,min:kt,max:At,step:jt,value:y,onChange:e=>b(Number(e.target.value)),className:`h-1.5 w-28 cursor-pointer accent-primary`}),c(`span`,{className:`w-8 shrink-0 text-right font-mono text-[11px] tabular-nums text-foreground`,children:y.toFixed(2)})]}),r(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Min size`,c(`input`,{type:`number`,min:Nt,max:Pt,step:1,value:x,onChange:e=>S(Math.min(Pt,Math.max(Nt,Number(e.target.value)||Nt))),className:`w-12 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`})]}),r(_,{variant:`secondary`,onClick:()=>{D({}),P()},disabled:N,children:[N?c(J,{className:`h-3.5 w-3.5 animate-spin`}):c(ue,{className:`h-3.5 w-3.5`}),`Re-analyze`]})]})]}),c(`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?r(`div`,{className:`flex flex-1 items-center justify-center gap-2 py-8 text-xs text-foreground-subtle`,children:[c(J,{className:`h-4 w-4 animate-spin`}),` Finding similar faces…`]}):F.length===0?c(`div`,{className:`flex flex-1 items-center justify-center py-8 text-xs text-foreground-subtle`,children:`No look-alike groups at this threshold.`}):r(a,{children:[c(`div`,{className:`flex gap-2 overflow-x-auto pb-1 md:hidden`,children:F.map(e=>c(It,{cluster:e,face:n.get(e.representativeFaceId),active:e.representativeFaceId===w,onSelect:()=>T(e.representativeFaceId)},e.representativeFaceId))}),c(`div`,{className:`hidden shrink-0 flex-col gap-2 overflow-y-auto md:flex md:w-56`,children:F.map(e=>c(It,{cluster:e,face:n.get(e.representativeFaceId),active:e.representativeFaceId===w,onSelect:()=>T(e.representativeFaceId)},e.representativeFaceId))}),c(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:L&&r(a,{children:[B>0&&r(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:[B,` not loaded — excluded from actions`]}),c(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(13rem,1fr))] gap-2`,children:z.map(e=>{let t=n.get(e);return t?c(Lt,{face:t,cameraName:u(t.deviceId),nowMs:d,excluded:R.has(e),onToggleExclude:()=>U(e),onDelete:()=>void W(e),deletePending:v.isPending&&v.variables?.faceId===e},e):null})})]})})]})}),r(`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:[c(_,{variant:`secondary`,onClick:te,disabled:H.length===0,children:`Select in gallery`}),r(_,{variant:`primary`,onClick:()=>A(H),disabled:H.length===0,children:[c(V,{className:`h-3.5 w-3.5`}),` Adopt (`,H.length,`)`]})]})]}),c(vt,{faceIds:k,identities:f,onDone:()=>A(null)})]})}n();var zt=[[`faceGallery`]],Bt=500,Vt=120;function Ht({face:e,cameraName:t,nowMs:n,selected:i,onToggleSelect:a,onAssign:s,onOpenDetail:l}){let u=o(),d=w(),f=M(),p=()=>{u.invalidateQueries({queryKey:zt})},m=()=>l(e.faceId),h=gt(e);return r(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[r(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[h===null?r(`button`,{type:`button`,onClick:m,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:`No crop image — the face's crop media is missing (a pre-fix orphan). Safe to delete.`,children:[c(ne,{className:`h-7 w-7 text-warning/70`}),c(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}):c(`img`,{src:h,alt:`Face from ${t}`,onClick:m,loading:`lazy`,decoding:`async`,className:`h-full w-full cursor-zoom-in object-cover`}),c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),a(e.faceId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?`Deselect`:`Select`,children:i?c(fe,{className:`h-4 w-4 text-primary`}):c(pe,{className:`h-4 w-4`})})]}),r(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[c(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),c(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:W(e.timestamp,n)}),e.identityName&&c(`p`,{className:`text-[10px] font-medium text-primary truncate`,title:e.identityName,children:e.identityName})]}),r(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[e.assigned?c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),d.mutate({faceId:e.faceId},{onSettled:p})},disabled:d.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":`Detach face`,title:`Detach`,children:d.isPending?c(J,{className:`h-4 w-4 animate-spin`}):c(B,{className:`h-4 w-4`})}):c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e.faceId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":`Assign face to person`,title:`Assign to person`,children:c(V,{className:`h-4 w-4`})}),c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),f.mutate({faceId:e.faceId},{onSettled:p})},disabled:f.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":`Delete face`,title:`Delete face`,children:f.isPending?c(J,{className:`h-4 w-4 animate-spin`}):c(ye,{className:`h-4 w-4`})})]})]})}var Ut=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Recognized`,value:`recognized`}];function Wt(){let e=o(),[t,n]=s(`all`),[l,u]=s(ae),[d,p]=s(new Set),[m,h]=s(new Set),[g,v]=s(null),[y,b]=s(!1),[x,C]=s(null),{data:T,isLoading:E}=S({limit:Bt,filter:t,includeCrops:!1},{refetchInterval:3e4}),{data:D=[]}=A(),{data:O}=f({}),k=P(),N=w(),F=j(),I=M(),L=Date.now(),R=T??[],z=i(()=>{let e=new Map;for(let t of O??[])e.set(t.id,t.name);return e},[O]),H=e=>z.get(e)??`Camera #${String(e)}`,W=i(()=>ee(R).map(e=>({id:e,name:H(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[R,z]),K=i(()=>te(se(R,l),d),[R,l,d]),q=re(K,Vt,i(()=>JSON.stringify([t,l.fromMs,l.toMs,[...d].sort((e,t)=>e-t)]),[t,l.fromMs,l.toMs,d])),oe=i(()=>new Map(R.map(e=>[e.faceId,e])),[R]),ce=i(()=>ht(K),[K]),le=x===null?null:oe.get(x)??null,ue=()=>{e.invalidateQueries({queryKey:zt})},de=()=>h(new Set);function fe(e){h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function pe(e){h(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function me(){pe(mt(K))}let Y=[...m],X=k.isPending||F.isPending||I.isPending,he=N.isPending||I.isPending;function ge(){Y.length!==0&&F.mutate({faceIds:Y},{onSettled:()=>{ue(),de()}})}function ve(){Y.length!==0&&Promise.allSettled(Y.map(e=>I.mutateAsync({faceId:e}))).then(()=>{ue(),de()})}function be(e){C(null),v([e])}function xe(e){N.mutate({faceId:e},{onSettled:ue}),C(null)}function Se(e){I.mutate({faceId:e},{onSettled:ue}),C(null)}let Ce=K.length!==R.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[c(`div`,{className:`flex items-center gap-1`,children:Ut.map(e=>c(`button`,{type:`button`,onClick:()=>n(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${t===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.label},e.value))}),c(ie,{onChange:u}),c(G,{cameras:W,selected:d,onChange:p}),r(`button`,{type:`button`,onClick:()=>b(!0),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${y?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[c(_e,{className:`h-3.5 w-3.5`}),` Similar groups`]}),!E&&ce>0&&r(`button`,{type:`button`,onClick:me,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:`Select every visible face whose crop image is missing so you can delete the orphans in one pass`,children:[c(ne,{className:`h-3.5 w-3.5`}),` Select `,ce,` crop-less`]}),!E&&c(`span`,{className:`text-[10px] text-foreground-subtle ${ce>0?`ml-2`:`ml-auto`}`,children:Ce?`${String(K.length)} of ${String(R.length)} faces`:`${String(K.length)} face${K.length===1?``:`s`}`})]}),m.size>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[r(`span`,{className:`text-xs font-medium text-foreground`,children:[m.size,` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[r(_,{variant:`primary`,onClick:()=>v(Y),disabled:X,children:[c(V,{className:`h-3.5 w-3.5`}),` Assign`]}),r(_,{variant:`secondary`,onClick:ge,disabled:X,children:[F.isPending?c(J,{className:`h-3.5 w-3.5 animate-spin`}):c(B,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),r(_,{variant:`secondary`,onClick:ve,disabled:X,children:[c(ye,{className:`h-3.5 w-3.5`}),` Delete`]}),c(_,{variant:`ghost`,onClick:de,disabled:X,children:c(Z,{className:`h-3.5 w-3.5`})})]})]}),E&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[c(J,{className:`h-4 w-4 animate-spin`}),` Loading faces…`]}),!E&&K.length===0&&c(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:R.length>0?`No faces match the current date / camera filters.`:`No faces found for this filter.`}),!E&&K.length>0&&r(a,{children:[c(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(6.5rem,1fr))] gap-2`,children:q.pageItems.map(e=>c(Ht,{face:e,cameraName:H(e.deviceId),nowMs:L,selected:m.has(e.faceId),onToggleSelect:fe,onAssign:e=>v([e]),onOpenDetail:C},e.faceId))}),c(U,{currentPage:q.page,totalItems:q.totalItems,pageSize:q.pageSize,onPageChange:q.setPage,itemNoun:`faces`})]}),c(Ct,{face:le,cameraName:le?H(le.deviceId):``,onClose:()=>C(null),onAssign:be,onUnassign:xe,onDelete:Se,actionsPending:he}),c(vt,{faceIds:g,identities:D,onDone:()=>{v(null),de()}}),c(Rt,{open:y,onClose:()=>b(!1),byId:oe,cameraName:H,nowMs:L,identities:D,selectMany:pe})]})}n();var Gt=[[`faceGallery`]],Kt=2e3;function qt(){let e=o(),n=t(e);n.current=e;let r=t(void 0);r.current||=oe({delayMs:Kt,invalidate:()=>{n.current.invalidateQueries({queryKey:Gt})}}),l(()=>()=>r.current?.cancel(),[]),h(L.PipelineAnalyticsFaceGalleryChanged,()=>{r.current?.trigger()})}function Jt(){return qt(),c(xe,{icon:ge,title:`Faces`,subtitle:`Manage enrolled identities and assign detected face crops to people.`,children:r(`section`,{className:`space-y-3`,children:[r(`div`,{children:[c(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`People`}),c(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Enrolled identities used for face recognition. Expand a row to view or remove training samples.`}),c(ft,{})]}),r(`div`,{className:`pt-4 border-t border-border`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent detected faces`}),c(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Face crops captured by the detection pipeline. Assign them to a person to build recognition training data.`}),c(Wt,{})]})]})})}export{Jt as DetectionIntelligencePage};
@@ -1 +0,0 @@
1
- import{I as e,K as t,Q as n,S as r,U as i,W as a,a as o,b as s,i as c,o as l,q as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as p}from"./player-overlays-C6s8h_4Y.js";import{Br as m,Ca as h,Da as g,Dn as _,Ea as v,Et as y,Fs as b,Ft as x,It as S,Lt as C,Nt as w,Pt as T,Ta as E,Yt as D,ba as O,da as k,dn as A,fn as j,ga as M,ha as N,j as P,js as F,la as I,ma as ee,pa as te,qi as L,sa as R,ua as z,va as B,wa as ne,wt as re,xa as V,ya as H}from"./src-BJefDdNe.js";import{Rt as U,at as ie,mt as W}from"./src-izCXHk1w.js";import{t as ae}from"./clock-C8y1RuCX.js";import{t as oe}from"./copy-iQELk1hh.js";import{t as se}from"./download-gb-TEWAX.js";import{a as ce,c as G,d as le,f as ue,i as de,m as fe,n as pe,o as me,p as he,r as ge,s as _e,t as ve}from"./debounced-invalidate-DuIdhnb0.js";import{t as ye}from"./refresh-cw-CUau8U5z.js";import{t as be}from"./search-BrDukCgH.js";import{t as xe}from"./square-check-big-B4Eh45MV.js";import{t as Se}from"./square-D0Tv7x37.js";import{t as Ce}from"./star-lyXpX0iL.js";import{t as we}from"./undo-2-cT7lldww.js";import{C as K,G as Te,I as Ee,K as q,O as De,P as Oe,R as ke,i as Ae,l as je,s as Me,t as Ne,z as Pe}from"./index-DkufJo5r.js";import{t as Fe}from"./AdminPage-CCD07UMs.js";import{i as Ie,n as Le,t as Re}from"./authed-media-BPd_L9jr.js";import{t as ze}from"./AdminTabs-m0mv8roB.js";var Be=q(`arrow-down-wide-narrow`,[[`path`,{d:`m3 16 4 4 4-4`,key:`1co6wj`}],[`path`,{d:`M7 20V4`,key:`1yoxec`}],[`path`,{d:`M11 4h10`,key:`1w87gc`}],[`path`,{d:`M11 8h7`,key:`djye34`}],[`path`,{d:`M11 12h4`,key:`q8tih4`}]]),Ve=q(`bug`,[[`path`,{d:`m8 2 1.88 1.88`,key:`fmnt4t`}],[`path`,{d:`M14.12 3.88 16 2`,key:`qol33r`}],[`path`,{d:`M9 7.13v-1a3.003 3.003 0 1 1 6 0v1`,key:`d7y7pr`}],[`path`,{d:`M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6`,key:`xs1cw7`}],[`path`,{d:`M12 20v-9`,key:`1qisl0`}],[`path`,{d:`M6.53 9C4.6 8.8 3 7.1 3 5`,key:`32zzws`}],[`path`,{d:`M6 13H2`,key:`82j7cp`}],[`path`,{d:`M3 21c0-2.1 1.7-3.9 3.8-4`,key:`4p0ekp`}],[`path`,{d:`M20.97 5c0 2.1-1.6 3.8-3.5 4`,key:`18gb23`}],[`path`,{d:`M22 13h-4`,key:`1jl80f`}],[`path`,{d:`M17.2 17c2.1.1 3.8 1.9 3.8 4`,key:`k3fwyw`}]]),He=q(`circle-dashed`,[[`path`,{d:`M10.1 2.182a10 10 0 0 1 3.8 0`,key:`5ilxe3`}],[`path`,{d:`M13.9 21.818a10 10 0 0 1-3.8 0`,key:`11zvb9`}],[`path`,{d:`M17.609 3.721a10 10 0 0 1 2.69 2.7`,key:`1iw5b2`}],[`path`,{d:`M2.182 13.9a10 10 0 0 1 0-3.8`,key:`c0bmvh`}],[`path`,{d:`M20.279 17.609a10 10 0 0 1-2.7 2.69`,key:`1ruxm7`}],[`path`,{d:`M21.818 10.1a10 10 0 0 1 0 3.8`,key:`qkgqxc`}],[`path`,{d:`M3.721 6.391a10 10 0 0 1 2.7-2.69`,key:`1mcia2`}],[`path`,{d:`M6.391 20.279a10 10 0 0 1-2.69-2.7`,key:`1fvljs`}]]),Ue=q(`circle`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),We=q(`copy-plus`,[[`line`,{x1:`15`,x2:`15`,y1:`12`,y2:`18`,key:`1p7wdc`}],[`line`,{x1:`12`,x2:`18`,y1:`15`,y2:`15`,key:`1nscbv`}],[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]),Ge=q(`graduation-cap`,[[`path`,{d:`M21.42 10.922a1 1 0 0 0-.019-1.838L12.83 5.18a2 2 0 0 0-1.66 0L2.6 9.08a1 1 0 0 0 0 1.832l8.57 3.908a2 2 0 0 0 1.66 0z`,key:`j76jl0`}],[`path`,{d:`M22 10v6`,key:`1lu8f3`}],[`path`,{d:`M6 12.5V16a6 3 0 0 0 12 0v-3.5`,key:`1r8lef`}]]),Ke=q(`square-parking`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 17V7h4a3 3 0 0 1 0 6H9`,key:`1dfk2c`}]]),qe=q(`tag`,[[`path`,{d:`M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z`,key:`vktsd0`}],[`circle`,{cx:`7.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`kqv944`}]]);n();var Je=`pipeline-analytics`,Ye=`debug.listTracks`,Xe=`debug.analyze`,Ze=`/addon/pipeline-analytics/debug-export`;function Qe(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function $e(e,t){let n=e[t];return typeof n==`string`?n:null}function J(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function et(e,t){let n=e[t];return typeof n==`boolean`?n:null}function tt(e){return e===`error`||e===`warn`||e===`info`}function nt(e){if(!Qe(e))return null;let t=$e(e,`code`),n=$e(e,`detail`),r=e.severity;return t===null||n===null||!tt(r)?null:{code:t,severity:r,detail:n}}function rt(e){if(!Qe(e))return null;let t=$e(e,`trackId`),n=J(e,`deviceId`),r=$e(e,`className`),i=J(e,`firstSeen`),a=J(e,`lastSeen`),o=J(e,`durationMs`),s=et(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=$e(e,`label`);return{trackId:t,deviceId:n,className:r,...c===null?{}:{label:c},firstSeen:i,lastSeen:a,durationMs:o,active:s}}function it(e){let t=rt(e);if(t===null||!Qe(e))return null;let n=J(e,`mediaCount`),r=J(e,`eventCount`),i=J(e,`positionCount`);if(n===null||r===null||i===null)return null;let a=e.mediaKinds,o=e.findings;if(!Array.isArray(a)||!Array.isArray(o))return null;let s=a.filter(e=>typeof e==`string`),c=[];for(let e of o){let t=nt(e);t!==null&&c.push(t)}return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c}}function at(e){if(!Qe(e))return null;let t=et(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=rt(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function ot(e){if(!Qe(e))return null;let t=e.reports,n=e.vanished;if(!Array.isArray(t)||!Array.isArray(n))return null;let r=[];for(let e of t){let t=it(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var st={MEDIA_EVICTED_OR_NEVER:`no media`,MISSING_KEYFRAME:`no keyframe`,MISSING_FIRSTFRAME:`no first frame`,MISSING_LASTFRAME:`no last frame`,MISSING_THUMBNAIL:`no thumbnail`,MISSING_BEST_CROP:`no crop`,SHORT_TRACK:`very short`,ZERO_EVENTS:`no events`,ZERO_POSITIONS:`no trajectory`,NO_PERIODIC_SNAPSHOTS:`no snapshots`,LASTFRAME_STALE:`stale last frame`,MEDIA_STOPPED_EARLY:`media stopped early`,NO_BEST_EVENT:`no best event`,LOW_BEST_SCORE:`low score`};function ct(e){return st[e]??e}var lt={error:0,warn:1,info:2};function ut(e){return e.toSorted((e,t)=>lt[e.severity]-lt[t.severity]||e.code.localeCompare(t.code))}function dt(e){return e.length===0?Ze:`${Ze}?deviceIds=${e.join(`,`)}`}function ft(e){if(e<1e4)return`${(e/1e3).toFixed(1)}s`;let t=Math.round(e/1e3);if(t<60)return`${String(t)}s`;let n=Math.floor(t/60);return`${String(n)}m ${String(t%60).padStart(2,`0`)}s`}var pt=`all`,mt=`The server answered in a shape this build does not understand.`,ht={error:`danger`,warn:`warning`,info:`info`};function gt({findings:e}){return e.length===0?d(S,{variant:`success`,children:`no anomaly found`}):d(`div`,{className:`flex flex-wrap gap-1`,children:ut(e).map(e=>d(S,{variant:ht[e.severity],title:e.detail,children:ct(e.code)},e.code))})}function _t({track:e,report:t,cameraName:n,analyzing:i}){return r(`div`,{className:`flex flex-col gap-1.5 border-b border-border px-3 py-2.5 last:border-b-0`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[d(`span`,{className:`font-medium text-foreground`,children:n}),d(`span`,{className:`text-foreground-subtle`,children:e.label??e.className}),r(`span`,{className:`text-foreground-subtle`,children:[new Date(e.lastSeen).toLocaleString(),` · `,ft(e.durationMs)]}),e.active&&d(S,{variant:`default`,children:`still open`}),t!==void 0&&r(`span`,{className:`text-foreground-subtle`,children:[String(t.mediaCount),` media · `,String(t.eventCount),` events ·`,` `,String(t.positionCount),` positions`]})]}),d(`div`,{className:`flex items-center gap-2`,children:t===void 0?d(`span`,{className:`text-xs text-foreground-subtle`,children:i?`analysing…`:`not analysed`}):d(gt,{findings:t.findings})}),d(`code`,{className:`text-[10px] text-foreground-subtle`,children:e.trackId})]})}function vt(){let e=p(),[t,n]=u(pt),[i,s]=u(!1),[c,l]=u(null),f=m({}),h=a(()=>[{value:pt,label:`All cameras`},...(f.data??[]).map(e=>({value:String(e.id),label:e.name}))],[f.data]),g=a(()=>{let e=new Map;for(let t of f.data??[])e.set(t.id,t.name);return e},[f.data]),_=a(()=>t===pt?[]:[Number.parseInt(t,10)],[t]),v=o({queryKey:[`events-debug`,`list`,_],queryFn:async()=>at(await e.trpcClient.addons.custom.mutate({addonId:Je,action:Ye,input:_.length===0?{}:{deviceIds:_}}))}),y=a(()=>(v.data?.tracks??[]).map(e=>e.trackId),[v.data]),b=o({queryKey:[`events-debug`,`analyze`,y],enabled:y.length>0,queryFn:async()=>ot(await e.trpcClient.addons.custom.mutate({addonId:Je,action:Xe,input:{trackIds:y}}))}),S=a(()=>{let e=new Map;for(let t of b.data?.reports??[])e.set(t.trackId,t);return e},[b.data]),T=()=>{v.refetch(),b.refetch()},E=async()=>{s(!0),l(null);try{await Le(dt(_),`camstack-debug.zip`)}catch(e){l(e instanceof Error?e.message:`Export failed.`)}finally{s(!1)}},O=v.data?.tracks??[],k=v.data===null||b.data===null;return d(Fe,{children:r(`section`,{className:`space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`div`,{className:`w-44`,children:d(w,{value:t,options:h,onChange:e=>n(e.target.value)})}),r(C,{variant:`secondary`,onClick:T,disabled:v.isFetching,children:[v.isFetching?d(K,{className:`h-3.5 w-3.5 animate-spin`}):d(ye,{className:`h-3.5 w-3.5`}),`Refresh`]}),r(C,{onClick:()=>void E(),disabled:i||O.length===0,children:[i?d(K,{className:`h-3.5 w-3.5 animate-spin`}):d(se,{className:`h-3.5 w-3.5`}),`Export all (`,String(O.length),`)`]})]}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`A `,d(`code`,{children:`debug`}),` mark does not pin retention — this lists the marked tracks that still exist. A track whose media was evicted shows as missing media.`]}),v.isError&&d(D,{message:`Could not load the marked tracks.`}),k&&!v.isError&&d(D,{message:mt}),c!==null&&d(D,{message:c}),v.data?.truncated===!0&&d(D,{message:`A camera filled the per-camera cap — some marked tracks are not listed. Un-mark a few, or filter to one camera.`}),(b.data?.vanished.length??0)>0&&r(`p`,{className:`text-xs text-foreground-subtle`,children:[String(b.data?.vanished.length),` marked track(s) were evicted between the list and the analysis.`]}),d(x,{children:v.isLoading?d(`div`,{className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`Loading…`}):O.length===0?r(`div`,{className:`flex flex-col items-center gap-2 px-3 py-8 text-center`,children:[d(Ve,{className:`h-5 w-5 text-foreground-subtle`}),d(`p`,{className:`text-xs text-foreground-subtle`,children:`No track is marked for debug. Mark one from a track's actions to see it here.`})]}):O.map(e=>d(_t,{track:e,report:S.get(e.trackId),cameraName:g.get(e.deviceId)??`Camera ${String(e.deviceId)}`,analyzing:b.isFetching},e.trackId))})]})})}function yt(e){return e.subLabel??e.label}var bt=720*60*60*1e3;function xt(e){let t=[];for(let n of e)t.push(...n);return t}function St(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function Ct(e,t){return e.filter(e=>!(e.importance<t.minImportance||t.cameras.size>0&&!t.cameras.has(e.deviceId)||t.classes.size>0&&!t.classes.has(e.className)))}function wt(e,t){return`${String(e)}:${t}`}function Tt(e,t){let n=new Map,r=new Set;for(let i of e){let e=wt(i.deviceId,i.trackId);if(!t.has(e)||r.has(e))continue;r.add(e);let a=n.get(i.deviceId);a?a.push(i.trackId):n.set(i.deviceId,[i.trackId])}return n}function Et(e,t){return{since:e.fromMs??t-bt,until:e.toMs??t}}var Y=typeof I==`function`,Dt=`Track deletion arrives with the next server update`;function Ot(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var kt=Y?I:Ot,At=200,jt=3e4;function Mt(e){let t=p(),n=c({queries:e.deviceIds.map(n=>({queryKey:[`events-feed`,n,e.since,e.until,e.minImportance??null,e.classFilter??null],staleTime:jt,refetchInterval:jt,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEvents.query({deviceId:n,since:e.since,until:e.until,limit:At,...e.minImportance===void 0?{}:{minImportance:e.minImportance},...e.classFilter===void 0?{}:{classFilter:e.classFilter}})).map(e=>({...e,deviceId:n}))}))});return{rows:St(xt(n.map(e=>e.data??[])),`importance`),isLoading:n.some(e=>e.isLoading)}}n();var Nt=[`events-feed`],Pt=2e3;function Ft(n){let r=l(),i=n?.paused===!0,a=t(r);a.current=r;let o=t(i);o.current=i;let[s,c]=u(!1),d=e(()=>{a.current.invalidateQueries({queryKey:Nt})},[]),p=t(void 0);p.current||=ve({delayMs:Pt,invalidate:()=>{o.current?c(!0):d()}}),f(()=>()=>p.current?.cancel(),[]),f(()=>{i||!s||(c(!1),d())},[i,s,d]);let m=e(()=>{c(!1),d()},[d]);return b(U.PipelineAnalyticsDetectionEvent,()=>{p.current?.trigger()}),b(U.PipelineAnalyticsTrackEnded,()=>{p.current?.trigger()}),{pending:s,refreshNow:m}}n();function It({groups:e,selected:t,onChange:n,loading:i=!1}){let{t:o}=Ne(),[s,c]=u(!1),[l,f]=u(``),[p,m]=u(new Set),h=l.trim().toLowerCase(),g=e=>h.length===0||A(e,o).toLowerCase().includes(h),_=a(()=>e.map(e=>({macro:e.macro,subs:e.subs.filter(t=>g(t)||g(e.macro))})).filter(e=>g(e.macro)||e.subs.length>0),[e,h]),v=e=>m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),y=e=>{let r=new Set(t),i=t.has(e.macro.kind)&&e.subs.every(e=>t.has(e.kind)),a=[e.macro.kind,...e.subs.map(e=>e.kind)];if(i)for(let e of a)r.delete(e);else for(let e of a)r.add(e);n(r)},b=e=>{let r=new Set(t);r.has(e)?r.delete(e):r.add(e),n(r)},x=()=>n(new Set),S=t.size;return r(`div`,{className:`relative`,children:[r(`button`,{type:`button`,onClick:()=>c(e=>!e),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${S>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[d(qe,{className:`h-3.5 w-3.5`}),S>0?`Kinds (${String(S)})`:`Kinds`,d(ke,{className:`h-3 w-3`})]}),s&&r(`div`,{className:`absolute z-20 mt-1 max-h-80 w-64 overflow-auto rounded-md border border-border bg-surface p-2 shadow-lg`,children:[r(`div`,{className:`mb-2 flex items-center gap-1 rounded border border-border px-1.5`,children:[d(be,{className:`h-3.5 w-3.5 text-foreground-subtle`}),d(`input`,{type:`text`,value:l,onChange:e=>f(e.target.value),placeholder:`Search kinds…`,className:`w-full bg-transparent py-1 text-xs outline-none`}),S>0&&d(`button`,{type:`button`,onClick:x,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),_.length===0&&d(`div`,{className:`px-1 py-2 text-[11px] text-foreground-subtle`,children:i?`Loading kinds…`:h.length>0?`No kind matches that search.`:`These cameras advertise no event kinds.`}),_.map(e=>{let n=j(e.macro.iconId),i=p.has(e.macro.kind)||h.length>0,a=t.has(e.macro.kind);return r(`div`,{className:`mb-0.5`,children:[r(`div`,{className:`flex items-center gap-1`,children:[e.subs.length>0?d(`button`,{type:`button`,onClick:()=>v(e.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Expand`,children:d(i?ke:Ee,{className:`h-3 w-3`})}):d(`span`,{className:`w-3`}),r(`label`,{className:`flex flex-1 cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[d(`input`,{type:`checkbox`,checked:a,onChange:()=>y(e),className:`accent-primary`}),d(n,{className:`h-3.5 w-3.5`,style:{color:e.macro.color}}),d(`span`,{className:`font-medium`,children:A(e.macro,o)})]})]}),i&&e.subs.map(e=>{let n=j(e.iconId);return r(`label`,{className:`ml-5 flex cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[d(`input`,{type:`checkbox`,checked:t.has(e.kind),onChange:()=>b(e.kind),className:`accent-primary`}),d(n,{className:`h-3.5 w-3.5`,style:{color:e.color}}),d(`span`,{children:A(e,o)})]},e.kind)})]},e.macro.kind)})]})]})}function Lt(e,t){let n=new Map;for(let r of e)if(!(t.size>0&&!t.has(r.deviceId)))for(let e of r.kinds)n.has(e.kind)||n.set(e.kind,e);return n}function Rt(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var zt=new Set([`detection`,`package`]);function Bt(e,t){return[...Lt(e,t).values()].filter(e=>e.parentKind===null&&zt.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function Vt(e,t){let n=Lt(e,t),r=new Map,i=new Map;for(let e of n.values()){if(e.parentKind===null){i.set(e.kind,e);continue}let t=r.get(e.parentKind);t===void 0?r.set(e.parentKind,[e]):t.push(e)}for(let[e,t]of r){if(i.has(e))continue;let n=t[0];n!==void 0&&i.set(e,Rt(e,n))}return[...i.values()].map(e=>({macro:e,subs:[...r.get(e.kind)??[]].sort((e,t)=>e.label.localeCompare(t.label))})).sort((e,t)=>e.macro.label.localeCompare(t.macro.label))}n();var Ht=1400,Ut=`Admin-gated URL — opens only inside an authenticated session`;function Wt({label:t,value:n,title:i}){let[a,o]=u(!1);return f(()=>{if(!a)return;let e=setTimeout(()=>o(!1),Ht);return()=>clearTimeout(e)},[a]),r(`button`,{type:`button`,onClick:e(()=>{(async()=>{try{await navigator.clipboard.writeText(n),o(!0)}catch{window.prompt(`Copy the media URL:`,n)}})()},[n]),title:i,"aria-label":`Copy ${t} URL`,className:`flex min-w-0 items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${a?`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:`border-border text-foreground-subtle hover:border-primary hover:text-foreground`}`,children:[d(a?Pe:oe,{className:`h-2.5 w-2.5 shrink-0`}),d(`span`,{className:`truncate`,children:a?`Copied`:t})]})}function Gt({localUrl:e,publicUrl:t}){return r(`div`,{className:`flex flex-wrap gap-1`,children:[d(Wt,{label:`Local`,value:e,title:`Copy LAN URL — ${Ut}`}),t&&d(Wt,{label:`Public`,value:t,title:`Copy public URL — ${Ut}`})]})}var Kt={firstFrame:`First frame (track start)`,lastFrame:`Last frame (track end)`,thumbnail:`Best detection`,thumbnailSmall:`Best detection (480)`,snapshot:`Snapshot`,keyFrame:`Key frame (native-res)`,keyFrameSmall:`Key frame (960)`,crop:`Object crop`,fullFrame:`Full frame`,fullFrameBoxed:`Full frame (boxed)`,faceCrop:`Face crop`,plateCrop:`Plate crop`};function qt(e){return e in Kt}function Jt(e){return qt(e)?Kt[e]:e}function Yt(e,t){return`${e}${Re}/${encodeURIComponent(t)}`}n();var Xt=3e4;function Zt(t){let[n,r]=u(null),i=e(e=>{r(t=>t??e)},[]);return f(()=>{t||r(null)},[t]),{publicOrigin:n,probes:t?d(Qt,{onOrigin:i}):null}}function Qt({onOrigin:e}){let{data:t}=_({capName:`network-access`});return d(s,{children:(t??[]).map(t=>d($t,{addonId:t.addonId,onOrigin:e},t.addonId))})}function $t({addonId:e,onOrigin:t}){let{data:n}=L({addonId:e},{refetchInterval:Xt,retry:!1});return f(()=>{let e=n?ie.safeParse(n):null,r=e?.success?e.data.endpoint?.url:void 0;if(r)try{t(new URL(r).origin)}catch{}},[n,t]),null}var en=typeof g==`function`,tn=`Track flags arrive with the next server update`;function nn(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var rn=en?g:nn;function an(e){if(typeof e!=`object`||!e||!(`trackId`in e)||!(`markForTrain`in e)||!(`debug`in e)||!(`favourited`in e))return null;let{trackId:t,markForTrain:n,debug:r,favourited:i}=e;return typeof t!=`string`||typeof n!=`boolean`||typeof r!=`boolean`||typeof i!=`boolean`?null:{trackId:t,markForTrain:n,debug:r,favourited:i}}n();function on({label:e,hint:t,checked:n,disabled:i,title:a,icon:o,onToggle:s}){return r(`button`,{type:`button`,role:`switch`,"aria-checked":n,"aria-label":e,disabled:i,title:a,onClick:s,className:`flex w-full items-center gap-2 rounded-md border px-2 py-1.5 text-left transition-colors disabled:opacity-50 ${n?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[d(`span`,{className:n?`text-primary`:`text-foreground-subtle`,children:o}),r(`span`,{className:`min-w-0 flex-1`,children:[d(`span`,{className:`block text-[11px] font-medium text-foreground`,children:e}),d(`span`,{className:`block text-[10px] text-foreground-subtle`,children:t})]}),d(`span`,{"aria-hidden":`true`,className:`h-4 w-7 shrink-0 rounded-full p-0.5 transition-colors ${n?`bg-primary`:`bg-border`}`,children:d(`span`,{className:`block h-3 w-3 rounded-full bg-white transition-transform ${n?`translate-x-3`:``}`})})]})}function sn({deviceId:e,trackId:t,markForTrain:n,debug:i,favourited:a,onChange:o}){let s=rn(),[c,l]=u(null),f=c?.markForTrain??n===!0,p=c?.debug??i===!0,m=c?.favourited??a===!0,h=!en||s.isPending,g=en?void 0:tn,_=n=>{h||(async()=>{try{let r=an(await s.mutateAsync({deviceId:e,trackId:t,flags:n}));if(!r)return;l(r),o?.(r)}catch(e){let t=e instanceof Error?e.message:``;window.alert(t===``?`Could not update this track. Check the server logs.`:`Could not update this track — ${t}`)}})()};return r(`div`,{className:`grid gap-1.5 sm:grid-cols-2`,children:[d(on,{label:`Mark for training`,hint:`Keeps this track and its media past retention`,checked:f,disabled:h,...g===void 0?{}:{title:g},icon:d(Ge,{className:`h-4 w-4`}),onToggle:()=>_({markForTrain:!f})}),d(on,{label:`Debug`,hint:`Flag this track for diagnostic attention`,checked:p,disabled:h,...g===void 0?{}:{title:g},icon:d(Ve,{className:`h-4 w-4`}),onToggle:()=>_({debug:!p})}),d(on,{label:`Favourited`,hint:`Keeps this track and its media past retention`,checked:m,disabled:h,...g===void 0?{}:{title:g},icon:d(Ce,{className:`h-4 w-4`}),onToggle:()=>_({favourited:!m})})]})}var X=100,cn=120,ln={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Z=e=>e<0?0:e>1?1:e,Q=e=>Math.round(e*100)/100;function un(e,t){if(e.length<=t)return[...e];let n=(e.length-1)/(t-1),r=[];for(let i=0;i<t;i++)r.push(e[Math.round(i*n)]);return r[r.length-1]=e[e.length-1],r}function dn(e,t,n){if(e.length===0||t===null)return ln;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return ln;let a=un(e,n?.maxPoints??cn).map(e=>({x:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X)})),o=a[0]??null,s=a[a.length-1]??null,c=a.length>=2?a.map(e=>`${e.x},${e.y}`).join(` `):``,l=(n?.snapshots??[]).map(e=>({x:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X),mediaKey:e.mediaKey})),u=null,d=-1;for(let t of e){let e=Z(t.bbox.w/r)*Z(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:Q(Z(u.bbox.x/r)*X),y:Q(Z(u.bbox.y/i)*X),w:Q(Z(u.bbox.w/r)*X),h:Q(Z(u.bbox.h/i)*X)}:null}}n();var fn=15e3,pn=window.location.origin,mn=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),hn=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]);function gn(e){let[t,n]=u(null);return f(()=>{if(n(null),!e)return;let t=!1,r=new Image;return r.onload=()=>{t||n({width:r.naturalWidth,height:r.naturalHeight})},r.src=e,()=>{t=!0,r.onload=null}},[e]),t}function _n({overlay:e,onPickSnapshot:t}){return!e.polyline&&!e.peakBox&&e.snapshots.length===0?null:r(`svg`,{viewBox:`0 0 100 100`,preserveAspectRatio:`none`,className:`pointer-events-none absolute inset-0 h-full w-full`,children:[e.peakBox&&d(`rect`,{x:e.peakBox.x,y:e.peakBox.y,width:e.peakBox.w,height:e.peakBox.h,fill:`none`,stroke:`#f59e0b`,strokeWidth:2,vectorEffect:`non-scaling-stroke`,rx:1}),e.polyline&&d(`polyline`,{points:e.polyline,fill:`none`,stroke:`#38bdf8`,strokeWidth:2,strokeLinejoin:`round`,strokeLinecap:`round`,strokeOpacity:.85,vectorEffect:`non-scaling-stroke`}),e.points.map((e,t)=>d(`circle`,{cx:e.x,cy:e.y,r:1,fill:`#38bdf8`,fillOpacity:.6,vectorEffect:`non-scaling-stroke`},`${String(e.x)}-${String(e.y)}-${String(t)}`)),e.snapshots.map((e,n)=>d(`circle`,{cx:e.x,cy:e.y,r:1.9,fill:`#0ea5e9`,fillOpacity:.95,stroke:`#082f49`,strokeWidth:.7,vectorEffect:`non-scaling-stroke`,className:t?`pointer-events-auto cursor-pointer`:void 0,onClick:t?n=>{n.stopPropagation(),t(e.mediaKey)}:void 0,children:d(`title`,{children:`Snapshot checkpoint — click to view this frame`})},`snap-${e.mediaKey}-${String(n)}`)),e.start&&d(`circle`,{cx:e.start.x,cy:e.start.y,r:2.4,fill:`#22c55e`,stroke:`#052e16`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`}),e.end&&d(`circle`,{cx:e.end.x,cy:e.end.y,r:2.4,fill:`#ef4444`,stroke:`#450a0a`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`})]})}function $({label:e,value:t,mono:n}){return r(`div`,{className:`flex items-baseline justify-between gap-3 border-b border-border/60 py-1.5 last:border-0`,children:[d(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),d(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono text-[11px]`:``}`,title:t,children:t})]})}function vn({row:t,cameraName:n,deleteAvailable:i,onClose:o,onDeleted:c,onFlagsChanged:l}){let m=p(),h=kt(),g=t!==null,_=t?.deviceId??0,v=t?.trackId??``,b=t?.bestEventId??``,x=t?.timestamp??0,S=t?.windowMs??0,{data:w}=ee({deviceId:_,trackId:v},{enabled:g}),{data:T}=N({trackId:v,deviceId:_},{enabled:g}),{data:E}=k({eventId:b,deviceId:_},{enabled:g&&b!==``}),{data:D}=F({deviceId:_,since:x-fn,until:x+S+fn},{enabled:g}),[O,A]=u(null),[j,M]=u(!1),{publicOrigin:P,probes:I}=Zt(g);f(()=>{A(null)},[_,v]);let te=a(()=>{let e=T??[],t=E??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[T,E]),L=Ie(te?`${Re}/${encodeURIComponent(te.key)}`:void 0),R=a(()=>{let e=new Set,t=[];for(let n of[...E??[],...T??[]])!n.base64||e.has(n.key)||(e.add(n.key),t.push(n));return t},[E,T]),z=a(()=>R.find(e=>mn.has(e.kind))??null,[R]),B=gn(z?`data:image/jpeg;base64,${z.base64}`:null),ne=a(()=>dn(w?.positions??[],B,{snapshots:(w?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaKey:e.mediaKey}))}),[w?.positions,w?.snapshots,B]),V=e(e=>{let t=R.find(t=>t.key===e);t&&A(t)},[R]);if(t===null)return null;let H=O?`data:image/jpeg;base64,${O.base64}`:L.src,U=O?.kind??te?.kind,ie=U!==void 0&&hn.has(U)&&B!==null&&(w?.positions.length??0)>=2,W=D&&D.length>0?D[0]:null,ae=()=>{W&&(M(!0),(async()=>{try{let e=await m.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:W.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{window.alert(`Could not resolve clip playback. Check the server logs.`)}finally{M(!1)}})())},oe=()=>{!i||h.isPending||window.confirm(`Delete this track and all its media? This cannot be undone.`)&&(async()=>{try{await h.mutateAsync({deviceId:t.deviceId,trackIds:[t.trackId]}),c()}catch{window.alert(`Failed to delete this track. Check the server logs.`)}})()},se=Math.round(t.importance*100),ce=w?.importanceReason?`${String(se)}% · ${w.importanceReason}`:`${String(se)}%`,G=w?.zonesVisited&&w.zonesVisited.length>0?w.zonesVisited.join(`, `):`—`,ue=w?.audioLabels&&w.audioLabels.length>0?w.audioLabels.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `):`—`,de=w?w.totalDistance.toFixed(2):`—`,me=he(w?w.firstSeen:x),ge=w?he(w.lastSeen):`—`;return d(re,{open:!0,onOpenChange:e=>!e&&o(),children:r(y,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Event detail`,className:`flex h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:h-auto md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[r(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[r(`div`,{className:`min-w-0`,children:[r(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:[t.className,yt(t)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,yt(t)]}):null]}),d(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:n})]}),d(`button`,{type:`button`,onClick:o,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:d(Ae,{className:`h-4 w-4`})})]}),r(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[H?d(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:d(pe,{src:H,alt:`Key frame from ${n}`,fit:`natural`,className:`w-full`,overlay:ie?d(_n,{overlay:ne,onPickSnapshot:V}):void 0})}):d(`div`,{className:`flex aspect-video w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-surface-hover text-foreground-subtle`,children:L.failed?r(s,{children:[d(fe,{className:`h-8 w-8 opacity-60`}),d(`span`,{className:`text-[11px]`,children:`Key-frame media unavailable`})]}):d(K,{className:`h-6 w-6 animate-spin opacity-70`})}),R.length>0&&d(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:R.map(e=>{let t=`data:image/jpeg;base64,${e.base64}`,n=Jt(e.kind),i=Yt(pn,e.key),a=P?Yt(P,e.key):null;return r(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[d(`button`,{type:`button`,onClick:()=>A(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${n} · ${he(e.timestamp)}`,children:d(`img`,{src:t,alt:n,className:`h-full w-full object-cover`})}),r(`figcaption`,{className:`min-w-0 px-0.5`,children:[d(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:n,children:n}),d(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:he(e.timestamp),children:le(e.timestamp)})]}),d(Gt,{localUrl:i,publicUrl:a})]},e.key)})}),I,W&&r(C,{variant:`secondary`,onClick:ae,disabled:j,children:[j?d(K,{className:`h-3.5 w-3.5 animate-spin`}):d(De,{className:`h-3.5 w-3.5`}),` `,`View clip`]}),d(sn,{deviceId:t.deviceId,trackId:t.trackId,...(w?.markForTrain??t.markForTrain)===void 0?{}:{markForTrain:w?.markForTrain??t.markForTrain},...(w?.debug??t.debug)===void 0?{}:{debug:w?.debug??t.debug},...(w?.favourited??t.favourited)===void 0?{}:{favourited:w?.favourited??t.favourited},onChange:l}),r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[d($,{label:`Camera`,value:n}),d($,{label:`Class`,value:t.className}),d($,{label:`Label`,value:t.label??`—`}),d($,{label:`Sub-label`,value:t.subLabel??`—`}),d($,{label:`Importance`,value:ce}),d($,{label:`Zones visited`,value:G}),d($,{label:`Audio heard`,value:ue}),d($,{label:`Total distance`,value:de}),d($,{label:`First seen`,value:me}),d($,{label:`Last seen`,value:ge}),d($,{label:`Track`,value:t.trackId,mono:!0})]})]}),d(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:d(`span`,{title:i?void 0:Dt,children:r(C,{variant:`secondary`,onClick:oe,disabled:!i||h.isPending,children:[h.isPending?d(K,{className:`h-3.5 w-3.5 animate-spin`}):d(Me,{className:`h-3.5 w-3.5`}),` `,`Delete track`]})})})]})})}function yn(e){if(e===void 0||!Number.isFinite(e)||e<=0)return``;let t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return`${String(n)}m ${String(r).padStart(2,`0`)}s`}function bn({row:e,cameraName:t,nowMs:n,onOpenDetail:i,selected:a=!1,onToggleSelect:o,score:s}){let c=Ie(e.bestEventId?`${Re}/${e.bestEventId}`:void 0),l=Math.round(e.importance*100),u=s===void 0?void 0:Math.round(s*100),f=yn(e.windowMs),p=()=>i(e);return r(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${a?`border-primary ring-1 ring-primary`:`border-border`}`,children:[r(`div`,{className:`aspect-video relative overflow-hidden bg-surface-hover`,children:[c.src?d(`img`,{src:c.src,alt:`Event from ${t}`,onClick:p,className:`h-full w-full cursor-zoom-in object-cover`}):d(`button`,{type:`button`,onClick:p,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-surface-hover text-foreground-subtle`,title:c.failed?`Key-event media unavailable`:`No key-event media`,children:d(fe,{className:`h-6 w-6 opacity-60`})}),o&&d(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(wt(e.deviceId,e.trackId))},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":a?`Deselect`:`Select`,children:a?d(xe,{className:`h-4 w-4 text-primary`}):d(Se,{className:`h-4 w-4`})}),u!==void 0&&r(`span`,{className:`absolute left-1 top-1 z-10 rounded bg-primary/85 px-1.5 py-0.5 text-[10px] font-semibold text-white tabular-nums`,title:`CLIP semantic-match score`,children:[String(u),`%`]}),l>0&&d(`span`,{className:`absolute right-1 top-1 z-10 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-semibold text-white`,children:String(l)}),(e.markForTrain===!0||e.debug===!0||e.favourited===!0)&&r(`span`,{className:`absolute bottom-1 left-1 z-10 flex gap-1`,children:[e.markForTrain===!0&&d(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:`Marked for training`,"aria-label":`Marked for training`,children:d(Ge,{className:`h-3 w-3`})}),e.debug===!0&&d(`span`,{className:`rounded bg-black/70 p-0.5 text-white`,title:`Flagged for debug`,"aria-label":`Flagged for debug`,children:d(Ve,{className:`h-3 w-3`})}),e.favourited===!0&&d(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:`Favourited`,"aria-label":`Favourited`,children:d(Ce,{className:`h-3 w-3`})})]})]}),r(`button`,{type:`button`,onClick:p,className:`min-w-0 px-2 py-1.5 text-left space-y-0.5`,children:[r(`p`,{className:`text-[11px] font-medium text-foreground truncate`,title:e.className,children:[e.className,yt(e)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,yt(e)]}):null]}),d(`p`,{className:`text-[10px] text-foreground-subtle truncate`,title:t,children:t}),r(`div`,{className:`flex items-center justify-between gap-2`,children:[d(`span`,{className:`text-[10px] text-foreground-subtle truncate`,children:ue(e.timestamp,n)}),f&&d(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:f})]})]})]})}n();function xn(){let[n,r]=u(!1),i=t(null),[a,o]=u(0),s=e(e=>{i.current!==e&&(i.current=e,o(e=>e+1))},[]);return f(()=>{let e=i.current;if(!e||typeof IntersectionObserver>`u`){r(!1);return}let t=new IntersectionObserver(e=>{let t=e[e.length-1];t&&r(!t.isIntersecting)},{rootMargin:`64px 0px 0px 0px`,threshold:0});return t.observe(e),()=>t.disconnect()},[a]),{ref:s,scrolledPast:n}}n();var Sn=[`events-feed`],Cn=60,wn=[{value:`importance`,label:`Importance`,icon:Be},{value:`time`,label:`Recent`,icon:ae}];function Tn(){let e=l(),[t,n]=u(_e),[i,o]=u(new Set),[c,p]=u(new Set),[h,g]=u(0),[_,v]=u(`time`),[y,b]=u(new Set),[x,S]=u(null),[w,T]=u(()=>Date.now());f(()=>{let e=setInterval(()=>T(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:E,until:D}=a(()=>Et({fromMs:t.fromMs,toMs:t.toMs},w),[t.fromMs,t.toMs,w]),O=xn(),{pending:k,refreshNow:A}=Ft({paused:x!==null||y.size>0||O.scrolledPast}),{data:j}=m({}),N=a(()=>(j??[]).filter(e=>e.type===W.Camera),[j]),P=a(()=>N.map(e=>e.id),[N]),{data:F,isLoading:I}=M({deviceIds:P},{enabled:P.length>0,staleTime:5*6e4}),ee=a(()=>Vt(F??[],i),[F,i]),te=kt(),L=te.isPending,{rows:R,isLoading:z}=Mt({deviceIds:P,since:E,until:D,minImportance:h>0?h:void 0,classFilter:c.size===1?[...c][0]:void 0}),B=a(()=>{let e=new Map;for(let t of N??[])e.set(t.id,t.name);return e},[N]),ne=e=>B.get(e)??`Camera #${String(e)}`,re=a(()=>G(R).map(e=>({id:e,name:ne(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[R,B]),V=a(()=>St(Ct(R,{cameras:i,classes:c,minImportance:h}),_),[R,i,c,h,_]),H=me(V,Cn,a(()=>JSON.stringify([[...i].sort((e,t)=>e-t),[...c].sort(),h,_,E,D]),[i,c,h,_,E,D])),U=()=>{e.invalidateQueries({queryKey:Sn})},ie=()=>b(new Set);function ae(e){b(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function oe(){if(y.size===0||!Y)return;let e=Tt(R,y),t=[...e.values()].reduce((e,t)=>e+t.length,0);if(t===0||!window.confirm(`Delete ${String(t)} track${t===1?``:`s`} and all their media? This cannot be undone.`))return;let n=[...e];Promise.allSettled(n.map(([e,t])=>te.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{U();let t=[],r=new Set;if(e.forEach((e,i)=>{let a=n[i];if(!a)return;let[o,s]=a;if(e.status===`fulfilled`)for(let e of s)r.add(wt(o,e));else t.push(o)}),b(e=>{let t=new Set(e);for(let e of r)t.delete(e);return t}),t.length>0){let e=t.map(e=>ne(e)).join(`, `);window.alert(`Failed to delete tracks on: ${e}. They remain selected — retry, or check the server logs.`)}})}let se=V.length!==R.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d(ge,{onChange:n}),d(de,{cameras:re,selected:i,onChange:o}),d(It,{groups:ee,selected:c,onChange:p,loading:I}),r(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[d(`span`,{children:`Min score`}),d(`input`,{type:`range`,min:0,max:1,step:.05,value:h,onChange:e=>g(Number(e.target.value)),className:`h-1 w-24 cursor-pointer accent-primary`,"aria-label":`Minimum importance`}),d(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(h*100)})]}),d(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:wn.map(e=>{let t=e.icon;return r(`button`,{type:`button`,onClick:()=>v(e.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${_===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[d(t,{className:`h-3.5 w-3.5`}),` `,e.label]},e.value)})}),!z&&d(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:se?`${String(V.length)} of ${String(R.length)} events`:`${String(V.length)} event${V.length===1?``:`s`}`})]}),y.size>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[r(`span`,{className:`text-xs font-medium text-foreground`,children:[y.size,` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[d(`span`,{title:Y?void 0:`Track deletion arrives with the next server update`,children:r(C,{variant:`secondary`,onClick:oe,disabled:!Y||L,children:[L?d(K,{className:`h-3.5 w-3.5 animate-spin`}):d(Me,{className:`h-3.5 w-3.5`}),` `,`Delete`]})}),d(C,{variant:`ghost`,onClick:ie,disabled:L,children:d(Ae,{className:`h-3.5 w-3.5`})})]})]}),z&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[d(K,{className:`h-4 w-4 animate-spin`}),` Loading events…`]}),!z&&V.length===0&&d(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No key events in this window.`}),k&&d(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:d(`button`,{type:`button`,onClick:A,className:`rounded-full border border-primary/40 bg-surface px-3 py-1 text-[11px] font-medium text-primary shadow-sm hover:bg-primary/10`,children:`New events — refresh`})}),!z&&V.length>0&&r(s,{children:[d(`div`,{ref:O.ref,"aria-hidden":!0,className:`h-0`}),d(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:H.pageItems.map(e=>d(bn,{row:e,cameraName:ne(e.deviceId),nowMs:w,selected:y.has(wt(e.deviceId,e.trackId)),onToggleSelect:ae,onOpenDetail:S},wt(e.deviceId,e.trackId)))}),d(ce,{currentPage:H.page,totalItems:H.totalItems,pageSize:H.pageSize,onPageChange:H.setPage,itemNoun:`events`})]}),x&&d(vn,{row:x,cameraName:ne(x.deviceId),deleteAvailable:Y,onClose:()=>S(null),onDeleted:()=>{U(),S(null)},onFlagsChanged:e=>{S(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug,favourited:e.favourited}:t)}})]})}n();var En=50,Dn=350,On=[{value:.2,label:`Loose`},{value:.25,label:`Balanced`},{value:.3,label:`Strict`}];function kn(e){return{id:e.id,trackId:e.trackId??e.id,deviceId:e.deviceId,timestamp:e.timestamp,className:e.className,label:e.label,subLabel:e.subLabel,importance:e.importance??0,bestEventId:e.mediaKey??e.trackId??e.id,windowMs:void 0}}function An({onActiveChange:e}){let[t,n]=u(``),[i,o]=u(.2),[s,c]=u(null),[l,p]=u(null),[h,g]=u(null),_=P(t,Dn).trim(),v=_.length>0;f(()=>{e(v)},[v,e]);let[y,b]=u(()=>Date.now());f(()=>{let e=setInterval(()=>b(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:x}=m({}),S=a(()=>(x??[]).filter(e=>e.type===W.Camera),[x]),C=a(()=>{let e=new Map;for(let t of x??[])e.set(t.id,t.name);return e},[x]),w=e=>C.get(e)??`Camera #${String(e)}`,T=a(()=>S.map(e=>e.id),[S]),{data:D}=M({deviceIds:T},{enabled:T.length>0,staleTime:5*6e4}),O=a(()=>Bt(D??[],new Set(l===null?[]:[l])),[D,l]);f(()=>{s!==null&&(O.some(e=>e.kind===s)||c(null))},[O,s]);let{data:k,isFetching:j,isError:N,error:F}=E({text:_,minScore:i,limit:En,classFilter:s??void 0,deviceId:l??void 0},{enabled:v}),I=a(()=>[...k??[]].sort((e,t)=>t.score-e.score).map(e=>({...kn(e),score:e.score})),[k]);function ee(e){c(t=>t===e?null:e)}return r(`div`,{className:`space-y-3`,children:[r(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(`div`,{className:`relative min-w-[16rem] flex-1`,children:[d(be,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),d(`input`,{type:`text`,value:t,onChange:e=>n(e.target.value),placeholder:`Semantic search — describe what you're looking for…`,className:`h-9 w-full rounded-md border border-border bg-background pl-8 pr-8 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary`,"aria-label":`Semantic event search`}),t&&d(`button`,{type:`button`,onClick:()=>n(``),className:`absolute right-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Clear search`,children:d(Ae,{className:`h-3.5 w-3.5`})})]}),j&&v&&d(K,{className:`h-4 w-4 shrink-0 animate-spin text-foreground-subtle`})]}),r(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[d(`div`,{className:`flex items-center gap-1`,children:O.map(e=>d(`button`,{type:`button`,onClick:()=>ee(e.kind),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${s===e.kind?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:A(e)},e.kind))}),r(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[d(`span`,{children:`Camera`}),r(`select`,{value:l===null?``:String(l),onChange:e=>p(e.target.value===``?null:Number(e.target.value)),className:`h-7 rounded-md border border-border bg-background px-1.5 text-xs text-foreground focus:border-primary focus:outline-none`,"aria-label":`Filter by camera`,children:[d(`option`,{value:``,children:`All`}),S.map(e=>d(`option`,{value:String(e.id),children:e.name},e.id))]})]}),r(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[d(`span`,{children:`Match`}),d(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:On.map(e=>d(`button`,{type:`button`,onClick:()=>o(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${i===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:`Minimum CLIP score ${e.value.toFixed(2)}`,children:e.label},e.value))})]}),v&&!j&&!N&&r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[I.length,` match`,I.length===1?``:`es`]})]})]}),v&&r(`div`,{className:`space-y-3`,children:[N&&r(`p`,{className:`py-4 text-xs text-danger`,children:[`Search failed: `,F instanceof Error?F.message:`unknown error`,`. Check that the CLIP embedding step is enabled.`]}),!N&&j&&I.length===0&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[d(K,{className:`h-4 w-4 animate-spin`}),` Searching…`]}),!N&&!j&&I.length===0&&r(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:[`No semantic matches for “`,_,`”. Try a looser match threshold or a different phrasing.`]}),!N&&I.length>0&&d(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:I.map(e=>d(bn,{row:e,cameraName:w(e.deviceId),nowMs:y,score:e.score,onOpenDetail:g},e.id))})]}),h&&d(vn,{row:h,cameraName:w(h.deviceId),deleteAvailable:Y,onClose:()=>g(null),onDeleted:()=>g(null)})]})}var jn=15e3;function Mn(e){let t=p(),n=c({queries:e.map(e=>({queryKey:[`stationary-objects`,e],staleTime:jn,refetchInterval:jn,queryFn:async()=>((await t.trpcClient.zoneAnalytics.getCurrentSnapshot.query({deviceId:e}))?.stationaryObjects??[]).map(t=>({...t,deviceId:e}))}))});return{rows:n.flatMap(e=>e.data??[]).toSorted((e,t)=>t.becameStationaryAt-e.becameStationaryAt),isLoading:n.some(e=>e.isLoading)}}n();function Nn(e,t){let n=Math.max(0,Math.round((e-t)/6e4));if(n<1)return`just now`;if(n<60)return`${String(n)}m`;let r=Math.floor(n/60);return`${String(r)}h ${String(n%60)}m`}function Pn({row:e,cameraName:t,nowMs:n}){let i=e.keyFrameMediaKey?.startsWith(`track:`)?e.keyFrameMediaKey.split(`:`)[1]:e.keyFrameMediaKey,a=Ie(i?`${Re}/${i}`:void 0);return r(`div`,{className:`flex flex-col overflow-hidden rounded-md border border-border bg-surface`,children:[r(`div`,{className:`relative aspect-video overflow-hidden bg-surface-hover`,children:[a.src?d(`img`,{src:a.src,alt:`Parked ${e.className} on ${t}`,className:`h-full w-full object-cover`}):d(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:d(Ke,{className:`h-6 w-6`})}),d(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-medium capitalize text-white`,children:e.label??e.className})]}),r(`div`,{className:`flex flex-col gap-0.5 p-1.5`,children:[d(`span`,{className:`truncate text-[11px] text-foreground`,children:t}),r(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`parked `,Nn(n,e.becameStationaryAt)]})]})]})}function Fn(){let[e,t]=u(!1),n=Date.now(),{data:i}=m({}),o=a(()=>(i??[]).filter(e=>e.type===W.Camera),[i]),s=a(()=>o.map(e=>e.id),[o]),c=a(()=>{let e=new Map;for(let t of o)e.set(t.id,t.name);return e},[o]),{rows:l}=Mn(s);return l.length===0?null:r(`div`,{className:`rounded-md border border-border bg-surface/40`,children:[r(`button`,{type:`button`,onClick:()=>t(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,children:[d(e?ke:Ee,{className:`h-4 w-4 text-foreground-subtle`}),d(Ke,{className:`h-4 w-4 text-foreground-subtle`}),d(`span`,{className:`text-sm font-semibold text-foreground`,children:`Stationary`}),d(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:l.length}),d(`span`,{className:`ml-2 text-[11px] text-foreground-subtle`,children:`Parked objects — kept out of the event feed`})]}),e&&d(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:l.map(e=>d(Pn,{row:e,cameraName:c.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:n},e.id))})]})}n();function In(){let[e,t]=u(!1);return d(Fe,{children:r(`section`,{className:`space-y-3`,children:[d(An,{onActiveChange:t}),!e&&d(Fn,{}),!e&&d(Tn,{})]})})}var Ln=[`person`,`vehicle`,`animal`,`package`,`face`,`plate`],Rn=new Set(Ln);function zn(e){let t=e?.trim().toLowerCase();return t===void 0||t===``?null:Rn.has(t)?`"${t}" is a macro class, not a label — person / postman / Marco are three different tiers`:null}function Bn({annotations:e,selectedIndex:t,onSelect:n,onChange:i,onDelete:a}){return e.length===0?r(`p`,{className:`text-[11px] text-foreground-subtle p-3`,children:[`No subject on this frame yet. Drag on the image to draw one, or ask the pipeline for a proposal. Annotate `,d(`strong`,{children:`every`}),` subject — a frame with one box and three unlabelled people teaches the model that two thirds of the people in it are background.`]}):d(`ul`,{className:`divide-y divide-border`,children:e.map((e,o)=>{let s=o===t,c=zn(e.label),l=zn(e.subLabel);return r(`li`,{className:`p-2.5 space-y-1.5 ${s?`bg-surface-hover`:``}`,onFocus:()=>{n(o)},children:[r(`div`,{className:`flex items-center gap-2`,children:[d(w,{className:`w-28`,value:e.macroClass,options:Ln.map(e=>({value:e,label:e})),onChange:e=>{let t=Ln.find(t=>t===e.target.value);t!==void 0&&i(o,{macroClass:t})}}),d(w,{className:`w-32`,value:e.kind,options:[{value:`subject`,label:`subject`},{value:`model_error`,label:`model error`}],onChange:e=>{i(o,{kind:e.target.value===`model_error`?`model_error`:`subject`})}}),e.source===`assist`&&r(S,{variant:`info`,children:[e.assistModelId??`assist`,e.assistScore===void 0?``:` ${e.assistScore.toFixed(2)}`]}),d(C,{variant:`ghost`,size:`sm`,"aria-label":`Delete this subject`,onClick:()=>{a(o)},children:d(Me,{className:`h-3 w-3`})})]}),r(`div`,{className:`flex items-center gap-2`,children:[d(T,{className:`flex-1`,placeholder:`label (postman, van, cat…)`,value:e.label??``,onChange:e=>{i(o,{label:e.target.value})}}),d(T,{className:`flex-1`,placeholder:`sub-label (a name, a plate…)`,value:e.subLabel??``,onChange:e=>{i(o,{subLabel:e.target.value})}})]}),c!==null&&d(`p`,{className:`text-[11px] text-danger`,children:c}),l!==null&&d(`p`,{className:`text-[11px] text-danger`,children:l})]},`${String(o)}-${String(e.bbox.x)}`)})})}function Vn(e){return e.every(e=>zn(e.label)===null&&zn(e.subLabel)===null&&Rn.has(e.macroClass))}function Hn(e){return e<0?0:e>1?1:e}function Un(e,t,n,r){if(!(e>0)||!(t>0)||!(n>0)||!(r>0))return null;let i=Math.min(e/n,t/r),a=n*i,o=r*i;return{left:(e-a)/2,top:(t-o)/2,width:a,height:o}}function Wn(e,t,n){return{x:Hn((e-n.left)/n.width),y:Hn((t-n.top)/n.height)}}function Gn(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),w:Math.abs(t.x-e.x),h:Math.abs(t.y-e.y)}}function Kn(e){return e.w>=.01&&e.h>=.01}function qn(e,t){return{left:t.left+e.x*t.width,top:t.top+e.y*t.height,width:e.w*t.width,height:e.h*t.height}}function Jn(e,t){let n=-1,r=1/0;return e.forEach((e,i)=>{if(!(t.x>=e.x&&t.x<=e.x+e.w&&t.y>=e.y&&t.y<=e.y+e.h))return;let a=e.w*e.h;a<r&&(n=i,r=a)}),n}n();function Yn({imageSrc:n,imageWidth:a,imageHeight:o,boxes:s,selectedIndex:c,onSelect:l,onDraw:f}){let p=t(null),[m,h]=u({w:0,h:0}),[g,_]=u(null);i(()=>{let e=p.current;if(e===null)return;let t=new ResizeObserver(()=>{h({w:e.clientWidth,h:e.clientHeight})});return t.observe(e),h({w:e.clientWidth,h:e.clientHeight}),()=>{t.disconnect()}},[]);let v=Un(m.w,m.h,a,o),y=e(e=>{let t=p.current;if(t===null||v===null)return null;let n=t.getBoundingClientRect();return Wn(e.clientX-n.left,e.clientY-n.top,v)},[v]);return r(`div`,{ref:p,className:`relative w-full h-full min-h-[280px] bg-surface-sunken select-none touch-none`,onPointerDown:e=>{let t=y(e);t!==null&&(e.currentTarget.setPointerCapture(e.pointerId),_({start:t,current:Gn(t,t)}))},onPointerMove:e=>{if(g===null)return;let t=y(e);t!==null&&_({start:g.start,current:Gn(g.start,t)})},onPointerUp:()=>{if(g===null)return;let e=g.current;_(null),Kn(e)?f(e):l(Jn(s.map(e=>e.bbox),g.start))},children:[d(`img`,{src:n,alt:`Frame being annotated`,className:`absolute inset-0 w-full h-full object-contain pointer-events-none`}),v!==null&&s.map((e,t)=>{let n=qn(e.bbox,v),i=e.kind===`model_error`,a=t===c,o=i?`#ef4444`:a?`#22c55e`:`#3b82f6`;return d(`div`,{className:`absolute pointer-events-none`,style:{left:n.left,top:n.top,width:n.width,height:n.height,border:`${a?`2px`:`1px`} ${i?`dashed`:`solid`} ${o}`,opacity:e.source===`assist`&&!a?.65:1},children:r(`span`,{className:`absolute -top-4 left-0 text-[10px] px-1 rounded`,style:{background:o,color:`#08121f`},children:[e.label??e.macroClass,i?` ✕`:``]})},`${String(t)}-${String(e.bbox.x)}-${String(e.bbox.y)}`)}),g!==null&&v!==null&&d(`div`,{className:`absolute border border-dashed border-primary pointer-events-none`,style:qn(g.current,v)})]})}function Xn(e){return e>=1e6?`${(e/1e6).toFixed(1)} MB`:`${Math.round(e/1e3)} KB`}function Zn({candidates:e,copies:t,activeFrameId:n,refusals:i,isSelecting:a,onSelectCandidate:o,onOpenCopy:s,onRemoveCopy:c}){let l=new Set(t.map(e=>e.sourceMediaKey)),u=e.filter(e=>!l.has(e.mediaKey));return r(`div`,{className:`space-y-3`,children:[r(`section`,{children:[r(`h3`,{className:`text-xs font-semibold text-foreground mb-1.5`,children:[`In the dataset (`,t.length,`)`]}),t.length===0?d(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No frame copied yet. Selecting a frame copies it into retrain storage immediately — the dataset stops depending on the track's own media from that moment.`}):d(`ul`,{className:`flex flex-wrap gap-2`,children:t.map(e=>d(`li`,{children:r(`div`,{className:`rounded-md border px-2 py-1.5 text-[11px] ${e.frameId===n?`border-primary bg-surface-hover`:`border-border`}`,children:[r(`button`,{type:`button`,className:`flex items-center gap-1.5 text-left`,onClick:()=>{s(e.frameId)},children:[d(Pe,{className:`h-3 w-3 text-success`}),d(`span`,{className:`font-medium text-foreground`,children:e.sourceKind}),r(`span`,{className:`text-foreground-subtle`,children:[e.width,`×`,e.height,` · `,Xn(e.sizeBytes)]})]}),r(`button`,{type:`button`,"aria-label":`Remove this frame from the dataset`,className:`mt-1 flex items-center gap-1 text-foreground-muted hover:text-danger`,onClick:()=>{c(e.frameId)},children:[d(Me,{className:`h-3 w-3`}),`remove`]})]})},e.frameId))})]}),r(`section`,{children:[r(`h3`,{className:`text-xs font-semibold text-foreground mb-1.5`,children:[`Available frames (`,u.length,`)`]}),u.length===0?d(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.length===0?`This track has no whole, unannotated frame left — its media aged out before it was marked. Anything already copied above is still usable.`:`Every available frame is already in the dataset.`}):d(`ul`,{className:`flex flex-wrap gap-2`,children:u.map(e=>{let t=i.get(e.mediaKey);return r(`li`,{children:[r(C,{variant:`secondary`,size:`sm`,disabled:a||t!==void 0,onClick:()=>{o(e.mediaKey)},children:[a?d(K,{className:`h-3 w-3 animate-spin`}):d(t===void 0?We:fe,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:e.kind}),d(`span`,{className:`ml-1 text-foreground-subtle`,children:Xn(e.sizeBytes)})]}),t!==void 0&&d(S,{variant:`danger`,className:`ml-1`,children:t})]},e.mediaKey)})})]})]})}function Qn(e){return e.frameCount===0?`untouched`:e.annotationCount===0?`started`:`ready`}var $n={untouched:{icon:Ue,label:`to do`,variant:`default`},started:{icon:He,label:`frames only`,variant:`info`},ready:{icon:Oe,label:`annotated`,variant:`success`}};function er(e){return new Date(e).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function tr({tracks:e,isLoading:t,selectedTrackId:n,deviceNames:i,onSelect:a}){return t?r(`div`,{className:`flex items-center gap-2 p-4 text-xs text-foreground-subtle`,children:[d(K,{className:`h-3.5 w-3.5 animate-spin`}),`Loading staging tracks…`]}):e.length===0?d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`Nothing in staging. Mark a track for training from the viewer or the Events grid and it appears here.`}):d(`ul`,{className:`divide-y divide-border`,children:e.map(e=>{let t=$n[Qn(e)],o=t.icon;return d(`li`,{children:r(`button`,{type:`button`,onClick:()=>{a(e)},className:`w-full text-left px-3 py-2 flex items-start gap-2 hover:bg-surface-hover ${e.trackId===n?`bg-surface-hover`:``}`,children:[d(o,{className:`h-3.5 w-3.5 mt-0.5 shrink-0 text-foreground-subtle`}),r(`span`,{className:`min-w-0 flex-1`,children:[r(`span`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs font-medium text-foreground truncate`,children:e.label??e.className}),d(S,{variant:t.variant,children:t.label})]}),r(`span`,{className:`block text-[11px] text-foreground-subtle truncate`,children:[i.get(e.deviceId)??`Camera ${String(e.deviceId)}`,` ·`,` `,er(e.lastSeen)]}),r(`span`,{className:`block text-[11px] text-foreground-muted`,children:[e.frameCount,` frame`,e.frameCount===1?``:`s`,` ·`,` `,e.annotationCount,` subject`,e.annotationCount===1?``:`s`]})]})]})},e.trackId)})})}n();var nr=`person`;function rr(){let[t,n]=u(null),[i,o]=u(null),[c,l]=u([]),[p,g]=u(-1),[_,y]=u(new Map),[b,x]=u(null),w=m({projection:`slim`,isCamera:!0}),T=a(()=>{let e=new Map;for(let t of w.data??[])e.set(t.id,t.name);return e},[w.data]),E=O({}),D=H({trackId:t?.trackId??``},{enabled:t!==null}),k=B({trackId:t?.trackId??``},{enabled:t!==null}),A=te({frameId:i??``},{enabled:i!==null}),j=v(),M=z(),N=V(),P=ne(),F=R(),I=h();f(()=>{if(i===null){l([]);return}l((k.data??[]).filter(e=>e.mediaKey===i).map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},...e.subLabel===void 0?{}:{subLabel:e.subLabel},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))),g(-1)},[i,k.data]),f(()=>{let e=D.data?.copies??[];i===null&&e.length>0&&o(e[0].frameId)},[D.data,i]);let ee=e(e=>{n(e),o(null),l([]),y(new Map),x(null)},[]),L=e(async e=>{if(t===null)return;let n=await j.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,mediaKeys:[e]});if(n.refused.length>0){let e=new Map(_);for(let t of n.refused)e.set(t.sourceMediaKey,t.reason);y(e)}n.copied.length>0&&o(n.copied[0].frameId),await D.refetch(),await E.refetch()},[t,j,_,D,E]),re=e(async e=>{t!==null&&(await M.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:e}),i===e&&o(null),await D.refetch(),await k.refetch(),await E.refetch())},[t,M,i,D,k,E]),U=e(async e=>{if(t===null||i===null)return;x(null);let n=await N.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:i,subject:e===`package`?{kind:`package`}:{kind:`objects`,modelId:`yolo26n`,minScore:.3}});if(n.kind===`refused`){x(n.reason===`no-zone`?`A package proposal runs on the zone crop only — this camera has no zone, and running the detector on the whole frame at 0.35 proposes furniture.`:`The pipeline refused: ${n.reason}${n.detail===void 0?``:` — ${n.detail}`}`);return}l(e=>[...e,...n.proposals.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))]),x(`${n.proposals.length} proposal${n.proposals.length===1?``:`s`} from ${n.modelId}`+(n.belowThreshold>0?` — ${n.belowThreshold} more were below ${n.minScore.toFixed(2)}`:``))},[t,i,N]),ie=e(e=>{l(t=>[...t,{bbox:e,macroClass:nr,kind:`subject`,source:`operator`}]),g(c.length)},[c.length]),W=e((e,t)=>{l(n=>n.map((n,r)=>r===e?{...n,...t}:n))},[]),ae=e(e=>{l(t=>t.filter((t,n)=>n!==e)),g(-1)},[]),oe=e(async()=>{t===null||i===null||(await P.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:i,annotations:c.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label!==void 0&&e.label!==``?{label:e.label}:{},...e.subLabel!==void 0&&e.subLabel!==``?{subLabel:e.subLabel}:{},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))}),await k.refetch(),await E.refetch(),x(`Annotations saved.`))},[t,i,c,P,k,E]),se=e(async()=>{if(t===null)return;let e=await F.mutateAsync({deviceId:t.deviceId,trackId:t.trackId});x(e.changed?`Track completed — it is now trained, and its own media is evictable again.`:e.reason===`no-frames-copied`?`Refused: no frame was ever copied into the dataset. Completing would let retention delete material nothing was extracted from.`:`Refused: ${e.reason??`unknown`}`),await E.refetch(),e.changed&&n(null)},[t,F,E]),ce=e(async()=>{if(t===null)return;let e=await I.mutateAsync({deviceId:t.deviceId,trackId:t.trackId});x(e.changed?`Track returned to staging. Its copies and annotations were left alone.`:`Refused: ${e.reason??`unknown`}`),await E.refetch()},[t,I,E]),G=A.data,le=Vn(c)&&i!==null;return r(Fe,{subtitle:`Turn the tracks you marked for training into an annotated dataset. Selecting a frame copies it — the dataset never depends on media that can be swept.`,actions:t===null?null:r(`div`,{className:`flex items-center gap-2`,children:[r(C,{variant:`secondary`,size:`sm`,onClick:()=>void ce(),children:[d(we,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:`Back to staging`})]}),r(C,{size:`sm`,onClick:()=>void se(),children:[d(Ge,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:`Complete track`})]})]}),children:[b!==null&&d(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-xs text-foreground`,children:b}),r(`div`,{className:`grid grid-cols-1 lg:grid-cols-[minmax(0,260px)_minmax(0,1fr)] gap-4`,children:[r(`aside`,{className:`rounded-md border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-3 py-2 border-b border-border flex items-center justify-between`,children:[d(`h2`,{className:`text-xs font-semibold text-foreground`,children:`Staging`}),d(S,{children:E.data?.length??0})]}),d(tr,{tracks:E.data??[],isLoading:E.isLoading,selectedTrackId:t?.trackId??null,deviceNames:T,onSelect:ee})]}),d(`section`,{className:`space-y-3 min-w-0`,children:t===null?d(`p`,{className:`text-xs text-foreground-subtle`,children:`Pick a track from the staging list to start annotating it.`}):r(s,{children:[d(`div`,{className:`rounded-md border border-border bg-surface p-3`,children:d(Zn,{candidates:D.data?.candidates??[],copies:D.data?.copies??[],activeFrameId:i,refusals:_,isSelecting:j.isPending,onSelectCandidate:e=>void L(e),onOpenCopy:o,onRemoveCopy:e=>void re(e)})}),i!==null&&r(`div`,{className:`grid grid-cols-1 xl:grid-cols-[minmax(0,1fr)_minmax(0,380px)] gap-3`,children:[d(`div`,{className:`rounded-md border border-border overflow-hidden`,children:G===void 0?r(`div`,{className:`flex items-center gap-2 p-6 text-xs text-foreground-subtle`,children:[d(K,{className:`h-3.5 w-3.5 animate-spin`}),`Loading the frame…`]}):d(Yn,{imageSrc:`data:image/jpeg;base64,${G.base64}`,imageWidth:G.width,imageHeight:G.height,boxes:c,selectedIndex:p,onSelect:g,onDraw:ie})}),r(`div`,{className:`rounded-md border border-border bg-surface flex flex-col min-h-0`,children:[r(`div`,{className:`px-3 py-2 border-b border-border flex items-center gap-2`,children:[d(`h2`,{className:`text-xs font-semibold text-foreground flex-1`,children:`Subjects`}),r(C,{variant:`secondary`,size:`sm`,disabled:N.isPending,onClick:()=>void U(`objects`),children:[d(je,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:`Propose`})]}),r(C,{variant:`secondary`,size:`sm`,disabled:N.isPending,onClick:()=>void U(`package`),children:[d(je,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:`Packages`})]})]}),d(`div`,{className:`flex-1 overflow-y-auto`,children:d(Bn,{annotations:c,selectedIndex:p,onSelect:g,onChange:W,onDelete:ae})}),r(`div`,{className:`px-3 py-2 border-t border-border flex items-center justify-between`,children:[r(`span`,{className:`text-[11px] text-foreground-subtle`,children:[c.filter(e=>e.kind===`model_error`).length,` marked as model errors`]}),d(C,{size:`sm`,disabled:!le||P.isPending,onClick:()=>void oe(),children:`Save frame`})]})]})]})]})})]})]})}function ir(){return d(`div`,{className:`flex flex-col p-4`,children:d(ze,{tabs:[{id:`feed`,label:`Feed`,icon:Te,content:d(In,{})},{id:`retrain`,label:`Retrain`,icon:Ge,content:d(rr,{})},{id:`debug`,label:`Debug`,icon:Ve,content:d(vt,{})}]})})}export{ir as EventsPage};
@@ -1 +0,0 @@
1
- import{K as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{At as l,Br as u,Co as d,Dt as f,Et as p,Fs as m,It as h,Lt as g,Ot as _,Pt as v,So as y,_o as b,bo as x,fo as S,go as C,ho as w,kt as T,mo as E,po as D,vo as O,wo as k,wt as A,xo as j,yo as M}from"./src-BJefDdNe.js";import{Rt as N}from"./src-izCXHk1w.js";import{a as P,i as ee,n as F,r as I,t as L}from"./face-bbox-BXEzHS8o.js";import{a as R,c as z,f as B,i as te,l as ne,m as V,n as H,o as re,p as ie,r as U,s as ae,t as W,u as oe}from"./debounced-invalidate-DuIdhnb0.js";import{t as G}from"./pencil-CLA68sNA.js";import{t as K}from"./plus-BuuQxDX-.js";import{t as se}from"./square-check-big-B4Eh45MV.js";import{t as q}from"./square-D0Tv7x37.js";import{B as J,C as Y,I as ce,K as le,R as ue,i as X,s as Z,z as de}from"./index-DkufJo5r.js";import{t as fe}from"./AdminPage-CCD07UMs.js";import{r as pe,t as me}from"./authed-media-BPd_L9jr.js";var he=le(`badge-check`,[[`path`,{d:`M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z`,key:`3c2336`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]);t();var Q=[[`plateGallery`]];function ge({vehicleId:e}){let t=a(),{data:r,isLoading:i}=M({vehicleId:e}),o=j();function c(n){o.mutate({vehicleId:e,sampleId:n.id},{onSettled:()=>{t.invalidateQueries({queryKey:Q})}})}return i?n(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[s(Y,{className:`h-3.5 w-3.5 animate-spin`}),`Loading plates…`]}):!r||r.length===0?s(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No plates yet.`}):s(`div`,{className:`mt-2 grid grid-cols-3 gap-2 sm:grid-cols-4 md:grid-cols-6`,children:r.map(e=>n(`div`,{className:`group relative overflow-hidden rounded-md border border-border bg-surface`,children:[n(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[e.base64?s(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:e.text,className:`h-full w-full object-cover`}):s(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:s(J,{className:`h-6 w-6`})}),s(`button`,{type:`button`,onClick:()=>c(e),disabled:o.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":`Remove plate sample`,children:s(X,{className:`h-4 w-4 text-white`})})]}),s(`p`,{className:`truncate px-1.5 py-1 text-center font-mono text-[11px] font-semibold tracking-wide text-foreground`,title:e.text,children:e.text})]},e.id))})}function _e({vehicle:e,expanded:t,onToggle:r}){let c=a(),[u,d]=o(``),[m,b]=o(!1),[x,S]=o(!1),w=y(),E=C();function D(){d(e.name),b(!0)}function O(){b(!1),d(``)}function k(){let t=u.trim();if(!t||t===e.name){O();return}w.mutate({id:e.id,name:t},{onSettled:()=>{c.invalidateQueries({queryKey:Q}),O()}})}function j(){E.mutate({id:e.id},{onSettled:()=>{c.invalidateQueries({queryKey:Q}),S(!1)}})}return n(`div`,{className:`rounded-md border border-border bg-surface`,children:[n(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[s(`div`,{className:`h-8 w-12 shrink-0 overflow-hidden rounded border border-border bg-surface-hover`,children:e.coverBase64?s(`img`,{src:`data:image/jpeg;base64,${e.coverBase64}`,alt:e.name,className:`h-full w-full object-cover`}):s(`div`,{className:`flex h-full w-full items-center justify-center`,children:s(J,{className:`h-4 w-4 text-foreground-subtle`})})}),s(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:m?n(i,{children:[s(v,{value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&k(),e.key===`Escape`&&O()},className:`h-6 text-xs`,autoFocus:!0}),s(`button`,{type:`button`,onClick:k,disabled:w.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:s(de,{className:`h-3.5 w-3.5`})}),s(`button`,{type:`button`,onClick:O,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:s(X,{className:`h-3.5 w-3.5`})})]}):s(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),s(h,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!m&&n(`div`,{className:`flex items-center gap-1`,children:[s(`button`,{type:`button`,onClick:D,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:s(G,{className:`h-3.5 w-3.5`})}),s(`button`,{type:`button`,onClick:()=>S(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:s(Z,{className:`h-3.5 w-3.5`})})]}),s(`button`,{type:`button`,onClick:r,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":t?`Collapse`:`Expand`,children:s(t?ue:ce,{className:`h-3.5 w-3.5`})})]}),t&&s(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:s(ge,{vehicleId:e.id})}),s(A,{open:x,onOpenChange:e=>!e&&S(!1),children:n(p,{children:[n(T,{children:[s(l,{children:`Delete vehicle`}),n(f,{children:[`Delete `,s(`strong`,{children:e.name}),` and all its plate samples? This cannot be undone.`]})]}),n(_,{children:[s(g,{variant:`secondary`,onClick:()=>S(!1),children:`Cancel`}),n(g,{variant:`danger`,onClick:j,disabled:E.isPending,children:[E.isPending?s(Y,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function ve(){let e=a(),[t,r]=o(``),i=E();function c(){let n=t.trim();n&&i.mutate({name:n},{onSettled:()=>{e.invalidateQueries({queryKey:Q}),r(``)}})}return n(`div`,{className:`flex items-center gap-2 pt-2`,children:[s(v,{placeholder:`New vehicle name…`,value:t,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`&&c()},className:`h-7 text-xs flex-1`}),n(g,{variant:`primary`,size:`sm`,onClick:c,disabled:i.isPending||!t.trim(),children:[i.isPending?s(Y,{className:`h-3.5 w-3.5 animate-spin`}):s(K,{className:`h-3.5 w-3.5`}),`Add`]})]})}function ye(){let{data:e,isLoading:t}=x(),[r,i]=o(null);function a(e){i(t=>t===e?null:e)}return t?n(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[s(Y,{className:`h-4 w-4 animate-spin`}),`Loading vehicles…`]}):n(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&s(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No vehicles enrolled yet. Add one below.`}),e?.map(e=>s(_e,{vehicle:e,expanded:r===e.id,onToggle:()=>a(e.id)},e.id)),s(ve,{})]})}t();var be=[[`plateGallery`]];function xe(e){let[t,n]=o(null),[r,i]=o(null),[a,s]=o(!1);return c(()=>{if(n(null),i(null),s(!1),!e)return;let t=!1,r=null;return(async()=>{try{let i=await pe(`${me}/${encodeURIComponent(e)}`);if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||s(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),c(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>s(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function Se(e){let t=e.filter(e=>e.base64.length>0);return t.length===0?null:t.find(e=>/crop|plate/i.test(e.kind))??t[0]}function $({label:e,value:t,mono:r}){return n(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[s(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),s(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${r?`font-mono`:``}`,title:t,children:t})]})}function Ce({box:e}){return s(`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:s(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:`Plate`})})}function we({plate:e,cameraName:t,onClose:i,onAssign:l,onUnassign:u,onDelete:d,actionsPending:f}){let m=a(),{data:h,isFetching:_}=b({plateId:e?.plateId??``},{enabled:e!==null}),y=D(),[x,S]=o(`frame`),[C,w]=o(!1),[T,E]=o(``),{frameSrc:O,naturalWidth:k,naturalHeight:j,failed:M}=xe(e?.keyFrameMediaKey);c(()=>{w(!1),E(``),S(`frame`)},[e?.plateId]);let N=r(()=>{let t=Se(h??[]);return t?`data:image/jpeg;base64,${t.base64}`:e?.base64?`data:image/jpeg;base64,${e.base64}`:null},[h,e]),R=r(()=>!e?.plateBbox||k===null||j===null?null:L(e.plateBbox,k,j),[e?.plateBbox,k,j]);if(e===null)return null;let z=typeof e.keyFrameMediaKey==`string`&&e.keyFrameMediaKey.length>0&&!M,B=z&&x===`frame`,te=e.assigned?e.vehicleName??`Assigned`:e.recognizedVehicleId?`${e.vehicleName??`Recognized`} (suggested)`:`Unassigned`,ne=`${String(Math.round(e.score*100))}%${e.corrected?` · corrected`:``}`;function re(){e&&(E(e.text),w(!0))}function U(){if(!e)return;let t=T.trim().toUpperCase();if(!t||t===e.text){w(!1);return}y.mutate({plateId:e.plateId,text:t},{onSettled:()=>{m.invalidateQueries({queryKey:be}),w(!1)}})}return s(A,{open:!0,onOpenChange:e=>!e&&i(),children:n(p,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`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:[n(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[n(`div`,{className:`min-w-0`,children:[s(`div`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:e.text||`Plate detail`}),s(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]}),s(`button`,{type:`button`,onClick:i,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:s(X,{className:`h-4 w-4`})})]}),n(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[z&&n(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[n(`button`,{type:`button`,onClick:()=>S(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${x===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[s(ee,{className:`h-3.5 w-3.5`}),` Full frame`]}),n(`button`,{type:`button`,onClick:()=>S(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${x===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[s(P,{className:`h-3.5 w-3.5`}),` Crop`]})]}),B&&O?s(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:s(H,{src:O,alt:`Full frame with detected plate`,fit:`natural`,className:`w-full`,overlay:R?s(Ce,{box:R}):void 0})}):N?n(`div`,{className:`relative aspect-[2/1] w-full overflow-hidden rounded-lg border border-border bg-background`,children:[s(H,{src:N,alt:`Detected plate`,className:`h-full w-full`}),_&&s(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:s(Y,{className:`h-3.5 w-3.5 animate-spin`})})]}):n(`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:[s(V,{className:`h-8 w-8 text-warning/70`}),s(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:`No image`}),s(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:`The crop media for this plate could not be resolved. Safe to delete.`})]}),s(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-2`,children:n(`div`,{className:`flex items-center justify-between gap-3`,children:[s(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:`Plate text`}),C?n(`div`,{className:`flex min-w-0 flex-1 items-center justify-end gap-1.5`,children:[s(v,{value:T,onChange:e=>E(e.target.value),onKeyDown:e=>{e.key===`Enter`&&U(),e.key===`Escape`&&w(!1)},className:`h-7 max-w-[10rem] text-right font-mono text-xs uppercase`,autoFocus:!0}),s(`button`,{type:`button`,onClick:U,disabled:y.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Save corrected text`,children:y.isPending?s(Y,{className:`h-3.5 w-3.5 animate-spin`}):s(de,{className:`h-3.5 w-3.5`})}),s(`button`,{type:`button`,onClick:()=>w(!1),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel`,children:s(X,{className:`h-3.5 w-3.5`})})]}):n(`button`,{type:`button`,onClick:re,className:`group flex min-w-0 items-center gap-1.5`,title:`Correct the OCR reading`,children:[s(`span`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:e.text||`—`}),s(G,{className:`h-3 w-3 shrink-0 text-foreground-subtle group-hover:text-foreground`})]})]})}),n(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[s($,{label:`Camera`,value:t}),s($,{label:`Captured`,value:ie(e.timestamp)}),s($,{label:`Confidence`,value:ne}),s($,{label:`Vehicle`,value:te}),s($,{label:`Track`,value:e.trackId,mono:!0})]})]}),n(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[e.assigned?n(g,{variant:`secondary`,onClick:()=>u(e.plateId),disabled:f,children:[s(F,{className:`h-3.5 w-3.5`}),` Detach`]}):n(g,{variant:`primary`,onClick:()=>l(e.plateId),disabled:f,children:[s(I,{className:`h-3.5 w-3.5`}),` Assign`]}),n(g,{variant:`secondary`,onClick:()=>d(e.plateId),disabled:f,children:[s(Z,{className:`h-3.5 w-3.5`}),` Delete`]})]})]})})}t();var Te=[[`plateGallery`]];function Ee({plateIds:e,vehicles:t,onDone:r}){let i=a(),c=S(),u=E(),[d,m]=o(``),[h,y]=o(!1),[b,x]=o(null),C=e!==null&&e.length>0,w=e?.length??0;function D(){y(!1),m(``),x(null)}function O(){D(),r()}function k(t){!e||e.length===0||c.mutate({plateIds:[...e],vehicleId:t},{onSettled:()=>{i.invalidateQueries({queryKey:Te}),O()}})}function j(){!e||!d.trim()||u.mutate({name:d.trim()},{onSuccess:e=>{e?.id&&k(e.id)},onError:()=>{i.invalidateQueries({queryKey:Te}),O()}})}let M=c.isPending||u.isPending;return s(A,{open:C,onOpenChange:e=>!e&&O(),children:n(p,{children:[n(T,{children:[s(l,{children:w>1?`Assign ${String(w)} plates to vehicle`:`Assign plate to vehicle`}),s(f,{children:`Select an existing vehicle or create a new one.`})]}),s(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:t.map(e=>n(`button`,{type:`button`,onClick:()=>x(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${b===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[s(`span`,{className:`font-medium`,children:e.name}),n(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` plates`]})]},e.id))}),h?s(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:s(v,{placeholder:`New vehicle name…`,value:d,onChange:e=>m(e.target.value),onKeyDown:e=>{e.key===`Enter`&&j()},autoFocus:!0,className:`flex-1`})}):s(`button`,{type:`button`,onClick:()=>{x(null),y(!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:`+ New vehicle…`}),n(_,{children:[s(g,{variant:`secondary`,onClick:O,disabled:M,children:`Cancel`}),h?n(g,{variant:`primary`,onClick:j,disabled:M||!d.trim(),children:[M&&s(Y,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):n(g,{variant:`primary`,onClick:()=>b&&k(b),disabled:M||!b,children:[M&&s(Y,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,w>1?` ${String(w)}`:``]})]})]})})}t();var De=[[`plateGallery`]],Oe=500,ke=120;function Ae({plate:e,cameraName:t,nowMs:r,selected:i,onToggleSelect:o,onAssign:c,onOpenDetail:l}){let u=a(),f=d(),p=w(),m=()=>{u.invalidateQueries({queryKey:De})},h=()=>l(e.plateId);return n(`div`,{className:`relative flex flex-col overflow-hidden rounded-md border bg-surface ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[n(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[e.base64?s(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Plate ${e.text} from ${t}`,onClick:h,className:`h-full w-full cursor-zoom-in object-cover`}):n(`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:`No crop image — the plate's crop media is missing. Safe to delete.`,children:[s(V,{className:`h-7 w-7 text-warning/70`}),s(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}),s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(e.plateId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?`Deselect`:`Select`,children:i?s(se,{className:`h-4 w-4 text-primary`}):s(q,{className:`h-4 w-4`})}),e.corrected&&n(`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:`Manually corrected`,children:[s(he,{className:`h-3 w-3`}),` Fixed`]})]}),n(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[s(`p`,{className:`truncate font-mono text-xs font-bold tracking-wide text-foreground`,title:e.text,children:e.text||`—`}),s(`p`,{className:`truncate text-[10px] text-foreground-subtle`,title:t,children:t}),s(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:B(e.timestamp,r)}),e.vehicleName&&s(`p`,{className:`truncate text-[10px] font-medium text-primary`,title:e.vehicleName,children:e.vehicleName})]}),n(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[e.assigned?s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),f.mutate({plateId:e.plateId},{onSettled:m})},disabled:f.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":`Detach plate`,title:`Detach`,children:f.isPending?s(Y,{className:`h-4 w-4 animate-spin`}):s(F,{className:`h-4 w-4`})}):s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),c(e.plateId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":`Assign plate to vehicle`,title:`Assign to vehicle`,children:s(I,{className:`h-4 w-4`})}),s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),p.mutate({plateId:e.plateId},{onSettled:m})},disabled:p.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":`Delete plate`,title:`Delete plate`,children:p.isPending?s(Y,{className:`h-4 w-4 animate-spin`}):s(Z,{className:`h-4 w-4`})})]})]})}var je=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Assigned`,value:`assigned`}];function Me(e,t){return t===`unassigned`?e.filter(e=>!e.assigned):t===`assigned`?e.filter(e=>e.assigned):e}function Ne(){let e=a(),[t,c]=o(`all`),[l,f]=o(ae),[p,m]=o(new Set),[h,_]=o(new Set),[v,y]=o(null),[b,S]=o(null),{data:C,isLoading:T}=O({limit:Oe},{refetchInterval:3e4}),{data:E=[]}=x(),{data:D}=u({}),A=d(),j=k(),M=w(),N=Date.now(),P=C??[],ee=r(()=>{let e=new Map;for(let t of D??[])e.set(t.id,t.name);return e},[D]),L=e=>ee.get(e)??`Camera #${String(e)}`,B=r(()=>z(P).map(e=>({id:e,name:L(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[P,ee]),V=r(()=>ne(oe(Me(P,t),l),p),[P,t,l,p]),H=re(V,ke,r(()=>JSON.stringify([t,l.fromMs,l.toMs,[...p].sort((e,t)=>e-t)]),[t,l.fromMs,l.toMs,p])),ie=r(()=>new Map(P.map(e=>[e.plateId,e])),[P]),W=b===null?null:ie.get(b)??null,G=()=>{e.invalidateQueries({queryKey:De})},K=()=>_(new Set);function se(e){_(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}let q=[...h],J=j.isPending||M.isPending,ce=A.isPending||M.isPending;function le(){q.length!==0&&j.mutate({plateIds:q},{onSettled:()=>{G(),K()}})}function ue(){q.length!==0&&Promise.allSettled(q.map(e=>M.mutateAsync({plateId:e}))).then(()=>{G(),K()})}function de(e){S(null),y([e])}function fe(e){A.mutate({plateId:e},{onSettled:G}),S(null)}function pe(e){M.mutate({plateId:e},{onSettled:G}),S(null)}let me=V.length!==P.length;return n(`div`,{className:`relative space-y-3`,children:[n(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[s(`div`,{className:`flex items-center gap-1`,children:je.map(e=>s(`button`,{type:`button`,onClick:()=>c(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${t===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.label},e.value))}),s(U,{onChange:f}),s(te,{cameras:B,selected:p,onChange:m}),!T&&s(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:me?`${String(V.length)} of ${String(P.length)} plates`:`${String(V.length)} plate${V.length===1?``:`s`}`})]}),h.size>0&&n(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[n(`span`,{className:`text-xs font-medium text-foreground`,children:[h.size,` selected`]}),n(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[n(g,{variant:`primary`,onClick:()=>y(q),disabled:J,children:[s(I,{className:`h-3.5 w-3.5`}),` Assign`]}),n(g,{variant:`secondary`,onClick:le,disabled:J,children:[j.isPending?s(Y,{className:`h-3.5 w-3.5 animate-spin`}):s(F,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),n(g,{variant:`secondary`,onClick:ue,disabled:J,children:[s(Z,{className:`h-3.5 w-3.5`}),` Delete`]}),s(g,{variant:`ghost`,onClick:K,disabled:J,children:s(X,{className:`h-3.5 w-3.5`})})]})]}),T&&n(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[s(Y,{className:`h-4 w-4 animate-spin`}),` Loading plates…`]}),!T&&V.length===0&&s(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:P.length>0?`No plates match the current filters.`:`No plates recognized yet.`}),!T&&V.length>0&&n(i,{children:[s(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2`,children:H.pageItems.map(e=>s(Ae,{plate:e,cameraName:L(e.deviceId),nowMs:N,selected:h.has(e.plateId),onToggleSelect:se,onAssign:e=>y([e]),onOpenDetail:S},e.plateId))}),s(R,{currentPage:H.page,totalItems:H.totalItems,pageSize:H.pageSize,onPageChange:H.setPage,itemNoun:`plates`})]}),s(we,{plate:W,cameraName:W?L(W.deviceId):``,onClose:()=>S(null),onAssign:de,onUnassign:fe,onDelete:pe,actionsPending:ce}),s(Ee,{plateIds:v,vehicles:E,onDone:()=>{y(null),K()}})]})}t();var Pe=[[`plateGallery`]],Fe=2e3;function Ie(){let t=a(),n=e(t);n.current=t;let r=e(void 0);r.current||=W({delayMs:Fe,invalidate:()=>{n.current.invalidateQueries({queryKey:Pe})}}),c(()=>()=>r.current?.cancel(),[]),m(N.PipelineAnalyticsPlateGalleryChanged,()=>{r.current?.trigger()})}function Le(){return Ie(),s(fe,{icon:J,title:`Plates`,subtitle:`Manage enrolled vehicles and assign recognized license plates to them.`,children:n(`section`,{className:`space-y-3`,children:[n(`div`,{children:[s(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Vehicles`}),s(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Enrolled vehicle identities used for plate recognition. Expand a row to view or remove plate samples.`}),s(ye,{})]}),n(`div`,{className:`pt-4 border-t border-border`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent recognized plates`}),s(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`License plates read by the detection pipeline. Assign them to a vehicle, correct the OCR text, or delete.`}),s(Ne,{})]})]})})}export{Le as PlatesPage};
@@ -1 +0,0 @@
1
- import{I as e,Q as t,S as n,W as r,o as i,q as a,x as o,z as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as c,q as l}from"./player-overlays-C6s8h_4Y.js";import{Ao as u,Bo as d,Br as f,Do as p,Eo as m,Ga as h,Go as g,Ho as _,Jo as v,Ko as y,Mo as b,No as x,Oo as S,Po as C,Ps as w,Sa as T,Vo as E,Wo as D,Xt as O,Ya as k,_a as A,an as j,ca as M,et as N,fa as P,gn as F,ko as ee,ln as I,qo as te,ra as L,vn as R}from"./src-BJefDdNe.js";import{Rt as z,mt as B}from"./src-izCXHk1w.js";import{t as ne}from"./circle-x-CCD4C3g3.js";import{t as re}from"./download-gb-TEWAX.js";import{a as V,i as H,n as ie,r as ae,t as oe}from"./AddLocationWizard-BINhXZS7.js";import{C as U,G as W,K as G,M as K,O as q,V as J,i as Y,s as X}from"./index-DkufJo5r.js";import{t as se}from"./AdminPage-CCD07UMs.js";import{r as ce}from"./authed-media-BPd_L9jr.js";import{t as le}from"./DeviceAggregateSection-C4L267mZ.js";import{t as ue}from"./AdminTabs-m0mv8roB.js";import{t as Z}from"./format-size-DIxKXxtj.js";var Q=G(`arrow-right-left`,[[`path`,{d:`m16 3 4 4-4 4`,key:`1x1c3m`}],[`path`,{d:`M20 7H4`,key:`zbl0bi`}],[`path`,{d:`m8 21-4-4 4-4`,key:`h9nckh`}],[`path`,{d:`M4 17h16`,key:`g4d7ey`}]]),de=G(`scissors`,[[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M8.12 8.12 12 12`,key:`1alkpv`}],[`path`,{d:`M20 4 8.12 15.88`,key:`xgtan2`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`path`,{d:`M14.8 14.8 20 20`,key:`ptml3r`}]]),fe=G(`settings-2`,[[`path`,{d:`M20 7h-9`,key:`3s1dr2`}],[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]);t();function pe(){let e=f({}),t=r(()=>(e.data??[]).filter(e=>e.type===B.Camera).sort((e,t)=>e.name.localeCompare(t.name)),[e.data]),[i,s]=a(null),c=i??t[0]?.id??null;return!e.isLoading&&t.length===0?o(O,{icon:J,title:`No cameras`,description:`Add a camera first.`}):n(`div`,{className:`space-y-3`,children:[n(`div`,{className:`flex items-center gap-2`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Camera`}),o(`select`,{value:c??``,onChange:e=>s(Number(e.target.value)),className:`rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,children:t.map(e=>o(`option`,{value:e.id,children:e.name},e.id))})]}),c!==null&&o(j,{deviceId:c,children:o(le,{deviceId:c,sectionFilter:e=>e.location===`top-tab`&&e.tab===`recording`})},c)]})}t();var me=[`high`,`mid`,`low`],he=[{value:1,label:`Real time (1×)`},{value:2,label:`2×`},{value:4,label:`4×`},{value:8,label:`8×`},{value:16,label:`16×`}],ge=10080*60*1e3;function _e(e){let t=new Date(Date.now()-e*6e4),n=e=>String(e).padStart(2,`0`);return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}T${n(t.getHours())}:${n(t.getMinutes())}`}function ve({onClose:e,onCreated:t}){let i=f({}),s=r(()=>(i.data??[]).filter(e=>e.type===B.Camera).sort((e,t)=>e.name.localeCompare(t.name)),[i.data]),[c,l]=a(``),[u,d]=a(`high`),[p,m]=a(_e(60)),[h,g]=a(_e(0)),[_,v]=a(1),[y,b]=a(!0),[x,C]=a(``),[w,T]=a(null),E=c===``?s[0]?.id??null:c,D=new Date(p).getTime(),O=new Date(h).getTime(),k=Number.isFinite(D)&&Number.isFinite(O)&&D<O,A=S({onSuccess:()=>{t(),e()},onError:e=>T(e instanceof Error?e.message:String(e))});return o(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:e,children:n(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[n(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[n(`h2`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[o(q,{className:`h-3.5 w-3.5`}),`New export`]}),o(`button`,{onClick:e,className:`text-foreground-subtle hover:text-foreground`,children:o(Y,{className:`h-4 w-4`})})]}),n(`div`,{className:`p-4 space-y-3`,children:[n(`div`,{className:`grid grid-cols-2 gap-3`,children:[n(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Camera`}),o(`select`,{value:E??``,onChange:e=>l(Number(e.target.value)),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,children:s.map(e=>o(`option`,{value:e.id,children:e.name},e.id))})]}),n(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Profile`}),o(`select`,{value:u,onChange:e=>d(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,children:me.map(e=>o(`option`,{value:e,children:e},e))})]})]}),n(`div`,{className:`grid grid-cols-2 gap-3`,children:[n(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`From`}),o(`input`,{type:`datetime-local`,value:p,onChange:e=>m(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`})]}),n(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`To`}),o(`input`,{type:`datetime-local`,value:h,onChange:e=>g(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`})]})]}),n(`div`,{className:`grid grid-cols-2 gap-3`,children:[n(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Speed`}),o(`select`,{value:_,onChange:e=>v(Number(e.target.value)),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,children:he.map(e=>o(`option`,{value:e.value,children:e.label},e.value))})]}),n(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Title (optional)`}),o(`input`,{type:`text`,value:x,onChange:e=>C(e.target.value),placeholder:`e.g. courier at the gate`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle`})]})]}),n(`label`,{className:`flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[o(`input`,{type:`checkbox`,checked:y,disabled:_!==1,onChange:e=>b(e.target.checked),className:`accent-primary`}),`Include audio`,_===1?``:` (real-time only)`]}),!k&&o(`p`,{className:`text-[11px] text-danger`,children:`"From" must be before "To".`}),w&&o(`p`,{className:`text-[11px] text-danger`,children:w})]}),n(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[o(`button`,{onClick:e,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground`,children:`Cancel`}),o(`button`,{onClick:()=>{if(E===null||!k)return;T(null);let e=x.trim();A.mutate({deviceId:E,profile:u,fromMs:D,toMs:O,options:{includeAudio:y,maxLifeMs:ge,deleteAfterDownload:!1,..._===1?{}:{speed:_},...e.length>0?{title:e}:{}}})},disabled:E===null||!k||A.isPending,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground disabled:opacity-50`,children:A.isPending?`Queuing…`:`Create export`})]})]})})}function ye(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 be(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}function xe(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`${be(e)} · ${o}`}function Se(e,t){let n=e-t;if(n<=0)return`expired`;let r=Math.floor(n/6e4);if(r<60)return`in ${String(r)}m`;let i=Math.floor(r/60);return i<24?`in ${String(i)}h`:`in ${String(Math.floor(i/24))}d`}function Ce(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})}t();var we=[[`recordingExport`]],Te={queued:{cls:`bg-muted text-foreground-subtle`,label:`queued`},rendering:{cls:`bg-primary/10 text-primary`,label:`rendering`,spin:!0},ready:{cls:`bg-success/10 text-success`,label:`ready`},failed:{cls:`bg-danger/10 text-danger`,label:`failed`},expired:{cls:`bg-muted text-foreground-subtle`,label:`expired`},deleted:{cls:`bg-muted text-foreground-subtle`,label:`deleted`}};function Ee(){let{data:e,isLoading:t}=u({},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`queued`||e.state===`rendering`)?3e3:!1}),{map:n}=w(z.RecordingExportProgress,e=>e.exportId),{map:i}=w(z.RecordingExportCompleted,e=>e.exportId),{map:a}=w(z.RecordingExportFailed,e=>e.exportId);return{rows:r(()=>Ce(e??[],n,i,a),[e,n,i,a]),isLoading:t}}function De(e){let[t,n]=a(()=>Date.now());return s(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}function Oe(){let t=i(),[s,l]=a(!1),u=()=>{t.invalidateQueries({queryKey:[[`recordingExport`,`listExports`]]})},d=I(),m=c().trpcClient,h=De(6e4),{rows:g,isLoading:_}=Ee(),{data:v}=f({}),y=r(()=>{let e=new Map;for(let t of v??[])e.set(t.id,t.name);return e},[v]),b=e(()=>{t.invalidateQueries({queryKey:we})},[t]),x=p({onSuccess:b}),S=ee({onSuccess:b}),[C,w]=a(null),T=e(async e=>{w(e.id);try{let{url:t}=await m.recordingExport.getDownloadUrl.query({exportId:e.id}),n=await ce(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),b()}finally{w(null)}},[m,b]),E=e(async e=>{await d({title:`Cancel this export?`,message:`Stops the render. The partial file is discarded.`,confirmLabel:`Cancel export`,variant:`danger`})&&x.mutate({exportId:e.id})},[d,x]),D=e(async e=>{await d({title:`Delete this export?`,message:`Permanently removes the rendered file and its history row.`,confirmLabel:`Delete`,variant:`danger`})&&S.mutate({exportId:e.id})},[d,S]),k=r(()=>[{key:`camera`,header:`Camera`,render:e=>o(`span`,{className:`text-foreground`,children:y.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`range`,header:`Range`,nowrap:!0,render:e=>o(`span`,{className:`tabular-nums`,children:xe(e.fromMs,e.toMs)})},{key:`variant`,header:`Variant`,render:e=>o(`span`,{className:`text-foreground-subtle`,children:ye(e.options)})},{key:`state`,header:`State`,render:e=>{let t=Te[e.state];return n(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${t.cls}`,children:[t.spin&&o(U,{className:`h-2.5 w-2.5 animate-spin`}),t.label,e.state===`rendering`&&e.progressPct!==null&&n(`span`,{className:`tabular-nums`,children:[e.progressPct,`%`]})]})}},{key:`expiry`,header:`Expires`,nowrap:!0,render:e=>e.state===`deleted`?o(`span`,{className:`text-foreground-subtle`,children:`—`}):o(`span`,{className:`text-foreground-subtle tabular-nums`,children:Se(e.expiresAt,h)})},{key:`size`,header:`Size`,align:`right`,nowrap:!0,render:e=>o(`span`,{className:`tabular-nums`,children:e.fileBytes===null?`—`:Z(e.fileBytes)})},{key:`actions`,header:``,align:`right`,render:e=>{let t=e.state===`ready`,r=e.state===`queued`||e.state===`rendering`,i=e.state!==`deleted`;return n(`div`,{className:`flex items-center justify-end gap-1`,children:[t&&n(`button`,{onClick:()=>{T(e)},disabled:C===e.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:`Download MP4`,children:[C===e.id?o(U,{className:`h-3 w-3 animate-spin`}):o(re,{className:`h-3 w-3`}),`Download`]}),r&&n(`button`,{onClick:()=>{E(e)},disabled:x.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-amber-500/10 hover:text-amber-500 disabled:opacity-50`,title:`Cancel render`,children:[o(ne,{className:`h-3 w-3`}),`Cancel`]}),i&&o(`button`,{onClick:()=>{D(e)},disabled:S.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:`Delete export`,children:o(X,{className:`h-3 w-3`})})]})}}],[y,h,C,x.isPending,S.isPending,T,E,D]);return _&&g.length===0?n(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[o(U,{className:`h-4 w-4 animate-spin`}),`Loading exports…`]}):n(`div`,{className:`space-y-3`,children:[o(`div`,{className:`flex justify-end`,children:n(`button`,{onClick:()=>l(!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:[o(q,{className:`h-3.5 w-3.5`}),`New export`]})}),g.length===0?o(O,{icon:q,title:`No exports yet`,description:`Create one here (New export) or from a camera's timeline in the viewer. Rendered clips show up here to download or manage.`}):o(N,{columns:k,rows:g,rowKey:e=>e.id,minWidthPx:720}),s&&o(ve,{onClose:()=>l(!1),onCreated:u})]})}function ke(e){return e.locationIds!==void 0&&e.locationIds.length>0?e.locationIds:e.locationId===null?[]:[e.locationId]}function Ae(e,t){let n=ke(e);return n.length===0?`default root`:n.map(e=>t.get(e)??e).join(` + `)}function je(e,t,n){if(e.length===0)return null;let r=e[0];if(e.length===1&&r!==void 0)return{label:Ae(r,t),exact:!0};if(n===null)return null;let i=e.find(e=>ke(e).includes(n));return i===void 0?null:{label:Ae(i,t),exact:!1}}var Me=[`ok`,`warn`,`critical`];function Ne(e){return e>=.95?`critical`:e>=.85?`warn`:`ok`}function Pe(e){return Math.min(1,Math.max(0,e))}function Fe(e){let{availableBytes:t,totalBytes:n}=e;if(n===null||n<=0||t===null)return null;let r=Pe((n-t)/n);return{fraction:r,severity:Ne(r),recordingsFraction:Pe(e.usedBytes/n),freeBytes:t,totalBytes:n}}function Ie(e){if(e.length===0)return null;let t=0,n=0,r=0,i=0,a=null;for(let o of e){let e=Fe(o);if(e===null){n+=1;continue}t+=1,r+=e.totalBytes,i+=e.freeBytes,(a===null||Me.indexOf(e.severity)>Me.indexOf(a))&&(a=e.severity)}return{knownVolumes:t,unknownVolumes:n,totalBytes:r,freeBytes:i,severity:a}}t();var Le=[[`recording`]],Re=[{value:`retention`,label:`Retention policy`},{value:`quota`,label:`Quota / disk pressure`},{value:`operator`,label:`Operator`}],ze={ok:`bg-primary`,warn:`bg-amber-500`,critical:`bg-danger`},Be={ok:`text-foreground-subtle`,warn:`text-amber-500`,critical:`text-danger`};function $(e){return`${String(Math.round(e*100))}%`}function Ve(e,t){let n=e.locationIds??(e.locationId===null?[]:[e.locationId]),r=n.map(e=>t.get(e)).filter(e=>e!==void 0);return r.length>0?r.join(` + `):e.root===void 0?n.length>0?n.join(` + `):`default root`:e.root}function He(){let t=i(),s=I(),[c,u]=a(`retention`),{data:d,isLoading:p}=b({},{refetchOnWindowFocus:!1}),{data:h}=f({}),{data:g}=_({}),v=r(()=>{let e=new Map;for(let t of h??[])e.set(t.id,t.name);return e},[h]),y=r(()=>{let e=new Map;for(let t of g??[])e.set(t.id,t.displayName);return e},[g]),x=r(()=>(g??[]).find(e=>e.type===`recordings`&&e.isDefault)?.id??null,[g]),S=r(()=>d?.locations??[],[d?.locations]),w=r(()=>je(S,y,x),[S,y,x]),T=r(()=>Ie(S),[S]),E=e(()=>{t.invalidateQueries({queryKey:Le})},[t]),D=C({onSuccess:E}),k=m({onSuccess:E}),A=e(async e=>{await s({title:`Prune ${v.get(e.deviceId)??`#${String(e.deviceId)}`}?`,message:`Applies the retention policy now (reason: ${c}). Footage beyond the policy is permanently deleted.`,confirmLabel:`Prune now`,variant:`danger`})&&D.mutate({deviceId:e.deviceId,reason:c})},[s,D,c,v]),j=e(async e=>{await s({title:`Delete all footage for ${v.get(e.deviceId)??`#${String(e.deviceId)}`}?`,message:`Permanently deletes ${Z(e.usedBytes)} of recorded footage for this camera. This cannot be undone.`,confirmLabel:`Delete ${Z(e.usedBytes)}`,variant:`danger`})&&k.mutate({deviceId:e.deviceId})},[s,k,v]),M=r(()=>[{key:`camera`,header:`Camera`,render:e=>o(`span`,{className:`text-foreground`,children:v.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`disk`,header:`Disk`,nowrap:!0,render:()=>w===null?o(`span`,{className:`text-foreground-subtle`,children:`—`}):n(`span`,{className:w.exact?`text-foreground`:`text-foreground-subtle`,title:w.exact?`The only recordings volume on this node — this camera can only be here.`:`The recordings DEFAULT. This node has several recordings volumes and the per-camera placement is not reported by recording.getStorageUsage, so this is where footage lands by default rather than a per-camera fact.`,children:[w.label,!w.exact&&o(`span`,{className:`ml-1 text-foreground-subtle`,children:`(default)`})]})},{key:`used`,header:`Used`,align:`right`,nowrap:!0,render:e=>o(`span`,{className:`tabular-nums`,children:Z(e.usedBytes)})},{key:`actions`,header:``,align:`right`,render:e=>n(`div`,{className:`flex items-center justify-end gap-1`,children:[n(`button`,{onClick:()=>{A(e)},disabled:D.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-amber-500/10 hover:text-amber-500 disabled:opacity-50`,title:`Apply retention policy now`,children:[o(de,{className:`h-3 w-3`}),`Prune`]}),n(`button`,{onClick:()=>{j(e)},disabled:k.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:`Delete all footage`,children:[o(X,{className:`h-3 w-3`}),`Delete`]})]})}],[v,w,A,j,D.isPending,k.isPending]);if(p&&!d)return n(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[o(U,{className:`h-4 w-4 animate-spin`}),`Loading storage usage…`]});if(!d)return o(O,{icon:V,title:`No storage data`,description:`The recording node has not reported any storage usage yet.`});let P=d.devices.length;return n(`div`,{className:`flex flex-col gap-6`,children:[n(`section`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:[o(l,{label:`Total used`,icon:o(V,{className:`h-3 w-3`}),footer:`${String(P)} camera${P===1?``:`s`} on ${d.nodeId}`,children:Z(d.totalUsedBytes)}),T!==null&&T.severity!==null&&o(l,{label:`Free on recordings volumes`,icon:o(V,{className:`h-3 w-3`}),footer:`across ${String(T.knownVolumes)} volume${T.knownVolumes===1?``:`s`} of ${Z(T.totalBytes)}`+(T.unknownVolumes>0?` · ${String(T.unknownVolumes)} did not report capacity`:``),children:o(`span`,{className:`tabular-nums ${Be[T.severity]}`,children:Z(T.freeBytes)})}),S.map(e=>{let t=Fe(e),r=e.locationId??e.root??`default`;return o(l,{label:`Disk: ${Ve(e,y)}`,footer:t===null?`${Z(e.usedBytes)} of recordings · volume capacity unknown`:`${Z(t.freeBytes)} free of ${Z(t.totalBytes)} · ${Z(e.usedBytes)} recordings (${$(t.recordingsFraction)})`,children:t===null?o(`span`,{className:`tabular-nums`,children:Z(e.usedBytes)}):n(`div`,{className:`flex items-center gap-2`,title:`Volume fill — everything on the disk, not only recordings. Warn at 85%, critical at 95%.`,children:[o(`div`,{className:`h-2 flex-1 overflow-hidden rounded bg-muted`,children:o(`div`,{className:`h-full rounded ${ze[t.severity]}`,style:{width:$(t.fraction)}})}),o(`span`,{className:`tabular-nums text-xs ${Be[t.severity]}`,children:$(t.fraction)})]})},r)})]}),n(`section`,{className:`flex items-center gap-2 text-xs`,children:[o(`label`,{htmlFor:`prune-reason`,className:`text-foreground-subtle`,children:`Prune reason`}),o(`select`,{id:`prune-reason`,value:c,onChange:e=>{let t=Re.find(t=>t.value===e.target.value);t&&u(t.value)},className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:Re.map(e=>o(`option`,{value:e.value,children:e.label},e.value))})]}),P===0?o(O,{icon:V,title:`No recorded footage`,description:`No camera has recorded footage on this node yet.`}):o(N,{columns:M,rows:[...d.devices],rowKey:e=>e.deviceId,minWidthPx:480})]})}t();var Ue=[{value:`all`,label:`All`},{value:`recording`,label:`Recordings`},{value:`events`,label:`Events`}],We={recording:`bg-primary/10 text-primary`,events:`bg-violet-500/10 text-violet-400`};function Ge(e){return new Date(e).toLocaleString()}function Ke(){let[e,t]=a(`all`),{data:i,isLoading:s}=x({},{refetchOnWindowFocus:!1}),{data:c,isLoading:l}=A({},{refetchOnWindowFocus:!1}),{data:u}=f({}),d=r(()=>{let e=new Map;for(let t of u??[])e.set(t.id,t.name);return e},[u]),p=r(()=>{let t=[...i??[],...c??[]];return(e===`all`?t:t.filter(t=>t.domain===e)).toSorted((e,t)=>t.at-e.at)},[i,c,e]),m=r(()=>[{key:`at`,header:`When`,nowrap:!0,render:e=>o(`span`,{className:`text-foreground-subtle tabular-nums`,children:Ge(e.at)})},{key:`domain`,header:`Domain`,render:e=>o(`span`,{className:`inline-flex rounded px-1.5 py-0.5 text-[10px] font-medium ${We[e.domain]}`,children:e.domain})},{key:`op`,header:`Operation`,render:e=>o(`span`,{className:`text-foreground`,children:e.op})},{key:`reason`,header:`Reason`,render:e=>o(`span`,{className:`text-foreground-subtle`,children:e.reason})},{key:`device`,header:`Camera`,render:e=>e.deviceId===null?o(`span`,{className:`text-foreground-subtle`,children:`cluster`}):o(`span`,{className:`text-foreground`,children:d.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`items`,header:`Items`,align:`right`,nowrap:!0,render:e=>o(`span`,{className:`tabular-nums`,children:e.itemsAffected.toLocaleString()})},{key:`bytes`,header:`Reclaimed`,align:`right`,nowrap:!0,render:e=>o(`span`,{className:`tabular-nums`,children:e.bytesReclaimed>0?Z(e.bytesReclaimed):`—`})}],[d]),h=s||l;return n(`div`,{className:`flex flex-col gap-4`,children:[o(`div`,{className:`flex items-center gap-1`,children:Ue.map(n=>o(`button`,{onClick:()=>t(n.value),className:`rounded px-2 py-1 text-xs font-medium ${e===n.value?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-muted`}`,children:n.label},n.value))}),h&&p.length===0?n(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[o(U,{className:`h-4 w-4 animate-spin`}),`Loading activity…`]}):p.length===0?o(O,{icon:W,title:`No activity yet`,description:`Prune, delete and rescan operations across recordings and events show up here.`}):o(N,{columns:m,rows:p,rowKey:e=>e.id,minWidthPx:720})]})}t();function qe({types:e}){let t=i(),s=I(),{data:c}=_({}),l=E(),u=r(()=>l.data??[],[l.data]),[f,p]=a(null),[m,h]=a(null),g=()=>{t.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})},y=v({onSuccess:g}),b=d({onSuccess:g}),x=r(()=>{let e=new Map;for(let t of c??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[c]),S=e=>{e.isDefault||y.mutate(H(e,{isDefault:!0}))},C=(e,t)=>{y.mutate(H(e,{enabled:t}))},w=async e=>{if(e.isDefault){await s({title:`Cannot delete default location`,message:`"${e.displayName}" is the default for type "${e.type}". Mark another as default first.`,confirmLabel:`OK`,variant:`warning`});return}await s({title:`Delete location "${e.displayName}"?`,message:`Removes the record; files on disk are untouched.`,confirmLabel:`Delete`,variant:`danger`})&&b.mutate({id:e.id})},T=e.map(e=>u.find(t=>t.id===e)).filter(e=>e!==void 0);return n(`div`,{className:`space-y-3`,children:[T.length===0?o(`p`,{className:`text-[11px] text-foreground-subtle italic`,children:`No storage locations declared for this purpose.`}):T.map(e=>o(ae,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:x.get(e.id)??[],onAdd:e=>p(e),onEdit:e=>h(e),onDelete:e=>{w(e)},onSetDefault:e=>S(e),onToggleEnabled:(e,t)=>C(e,t)},e.id)),f!==null&&o(oe,{initialType:f,onClose:()=>p(null),onCreated:()=>{g(),p(null)}}),m!==null&&o(ie,{location:m,onClose:()=>h(null),onSaved:()=>{g(),h(null)}})]})}t();var Je=`pipeline-analytics`;function Ye(e){for(let t of e?.sections??[])for(let e of t.fields??[])if(e.key===`postProcessingNodeId`&&typeof e.value==`string`)return e.value;return`hub`}function Xe(){let e=i(),{data:t}=L(void 0),{data:a,isLoading:s}=F({addonId:Je}),c=Ye(a),l=R({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),u=r(()=>{let e=(t??[]).filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,c,...e])].filter(Boolean)},[t,c]);return n(`div`,{className:`flex flex-col gap-6`,children:[n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[o(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Post-processing node`}),o(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that runs detection post-processing (events, media, audio & motion). Every other node stays inert — no multi-node balancing. Takes effect on addon restart.`}),n(`div`,{className:`mt-3 flex items-center gap-2`,children:[s?o(U,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):o(`select`,{value:c,onChange:e=>{e.target.value!==c&&l.mutate({addonId:Je,patch:{postProcessingNodeId:e.target.value}})},disabled:l.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:u.map(e=>o(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),l.isPending&&o(U,{className:`h-4 w-4 animate-spin text-primary`})]})]}),n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[o(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Events folder`}),o(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where event crops / full frames are stored. A single folder — no collection / equal-splitting.`}),o(qe,{types:[`eventMedia`]})]})]})}t();var Ze=`recorder`;function Qe(e,t,n){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t&&typeof e.value==`string`)return e.value;return n}function $e(){let e=i(),{data:t}=L(void 0),{data:a,isLoading:s}=F({addonId:Ze}),c=Qe(a,`recordingNodeId`,`hub`),l=R({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),u=r(()=>{let e=(t??[]).filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,c,...e])].filter(Boolean)},[t,c]);return n(`div`,{className:`flex flex-col gap-6`,children:[n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[o(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Recording node`}),o(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that records (continuous & events) and serves playback. Every other node stays inert — no multi-node balancing. Takes effect on addon restart.`}),n(`div`,{className:`mt-3 flex items-center gap-2`,children:[s?o(U,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):o(`select`,{value:c,onChange:e=>{e.target.value!==c&&l.mutate({addonId:Ze,patch:{recordingNodeId:e.target.value}})},disabled:l.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:u.map(e=>o(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),l.isPending&&o(U,{className:`h-4 w-4 animate-spin text-primary`})]}),c!==`hub`&&n(`p`,{className:`mt-2 text-[11px] text-amber-500`,children:[`The stream-broker is hub-only — an agent recorder pulls streams from the hub over the network. The hub's RTSP restream port must be reachable from`,` `,o(`span`,{className:`font-medium`,children:c}),`. If the auto-derived host doesn't work, set the recorder's`,o(`span`,{className:`font-medium`,children:` recordingHubHostname`}),` global setting.`]})]}),n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[o(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Recordings folders`}),o(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where recordings are stored. Multi-location collections — segments are split across the locations of a type. Add a location to grow capacity; mark one default per type.`}),o(qe,{types:[`recordings`,`recordingsLow`]})]})]})}t();var et=2e3;function tt(){let e=I(),t=i(),r=k(),a=h(void 0,{refetchInterval:e=>e.state.data?.state===`running`?et:!1}),c=a.data,l=c?.state===`running`,u=l||r.isPending;s(()=>{c?.state!==`done`||c.finishedAtMs===null||(t.invalidateQueries({queryKey:[[`recording`]]}),t.invalidateQueries({queryKey:[[`pipelineAnalytics`]]}))},[c?.state,c?.finishedAtMs,t]);let d=async()=>{await e({title:`Reconcile storage from disk?`,message:`Makes the database match the filesystem: recordings index, tracks, events and media whose files are gone. Favourited tracks without files are deleted. Snapshot-less motion/audio events are deleted. Enrolled identities stay. This cannot be undone.`,confirmLabel:`Reconcile`,variant:`warning`})&&(await r.mutateAsync(),await a.refetch())},f=l?c.total>0?`Reconciling ${String(c.completed)}/${String(c.total)}…`:`Reconciling…`:r.isPending?`Reconciling…`:`Reconcile from disk`;return n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[o(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Disk reconcile`}),o(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`Makes the database match the filesystem for recordings, tracks, events and media. Rows whose files are gone are deleted, including snapshot-less motion events. Enrolled identities stay. The walk runs on the hub; you can leave this page.`}),n(`div`,{className:`mt-3 flex flex-col gap-2`,children:[n(`button`,{type:`button`,onClick:()=>void d(),disabled:u,className:`inline-flex w-fit items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[u?o(U,{className:`h-3.5 w-3.5 animate-spin`}):o(V,{className:`h-3.5 w-3.5`}),f]}),c?.state===`done`?n(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Last run: `,String(c.completed),` camera(s) — dropped `,String(c.tracks),` tracks,`,` `,String(c.events),` events, `,String(c.mediaDropped),` media`,c.failed.length>0?`, ${String(c.failed.length)} failed (${c.failed.join(`, `)})`:``,`.`]}):null,c?.state===`error`&&c.error!==null?n(`p`,{className:`text-[11px] text-destructive`,children:[`Reconcile failed: `,c.error]}):null]})]})}t();var nt=[[`pipelineAnalytics`]],rt=1440*60*1e3,it=[{days:1,label:`1 day`},{days:7,label:`7 days`},{days:30,label:`30 days`},{days:90,label:`90 days`}];function at(){let t=i(),s=I(),[c,u]=a(30),{data:d,isLoading:p}=P({},{refetchOnWindowFocus:!1}),{data:m}=f({}),h=r(()=>{let e=new Map;for(let t of m??[])e.set(t.id,t.name);return e},[m]),g=e(()=>{t.invalidateQueries({queryKey:nt})},[t]),_=T({onSuccess:g}),v=M({onSuccess:g}),y=e(async()=>{await s({title:`Prune events older than ${String(c)} day${c===1?``:`s`}?`,message:`Permanently deletes every event (motion / object / audio) older than the cutoff across all cameras, and their media. This cannot be undone.`,confirmLabel:`Prune events`,variant:`danger`})&&_.mutate({olderThanMs:Date.now()-c*rt,reason:`retention`})},[s,_,c]),b=e(async e=>{await s({title:`Delete all events for ${h.get(e.deviceId)??`#${String(e.deviceId)}`}?`,message:`Permanently deletes ${String(e.rows)} event${e.rows===1?``:`s`} (${Z(e.bytes)} of media) for this camera. This cannot be undone.`,confirmLabel:`Delete events`,variant:`danger`})&&v.mutate({deviceId:e.deviceId})},[s,v,h]),x=r(()=>[{key:`camera`,header:`Camera`,render:e=>o(`span`,{className:`text-foreground`,children:h.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`rows`,header:`Events`,align:`right`,nowrap:!0,render:e=>o(`span`,{className:`tabular-nums`,children:e.rows.toLocaleString()})},{key:`bytes`,header:`Media`,align:`right`,nowrap:!0,render:e=>o(`span`,{className:`tabular-nums`,children:Z(e.bytes)})},{key:`actions`,header:``,align:`right`,render:e=>n(`button`,{onClick:()=>{b(e)},disabled:v.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:`Delete all events for this camera`,children:[o(X,{className:`h-3 w-3`}),`Delete`]})}],[h,b,v.isPending]);return p&&!d?n(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[o(U,{className:`h-4 w-4 animate-spin`}),`Loading event-store footprint…`]}):d?n(`div`,{className:`flex flex-col gap-6`,children:[n(`section`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[o(l,{label:`Total events`,icon:o(K,{className:`h-3 w-3`}),footer:`across ${String(d.devices.length)} camera${d.devices.length===1?``:`s`}`,children:d.totalRows.toLocaleString()}),o(l,{label:`Event media on disk`,children:Z(d.totalBytes)})]}),n(`section`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[o(`span`,{className:`text-foreground-subtle`,children:`Prune events older than`}),o(`select`,{value:c,onChange:e=>u(Number(e.target.value)),className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:it.map(e=>o(`option`,{value:e.days,children:e.label},e.days))}),n(`button`,{onClick:()=>{y()},disabled:_.isPending,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-xs font-medium text-foreground-subtle hover:bg-amber-500/10 hover:text-amber-500 disabled:opacity-50`,children:[_.isPending?o(U,{className:`h-3 w-3 animate-spin`}):o(de,{className:`h-3 w-3`}),`Prune now`]})]}),d.devices.length===0?o(O,{icon:K,title:`No stored events`,description:`No camera has persisted events yet.`}):o(N,{columns:x,rows:[...d.devices],rowKey:e=>e.deviceId,minWidthPx:480})]}):o(O,{icon:K,title:`No event data`,description:`Pipeline analytics has not reported any event-store footprint yet.`})}t();var ot=`storage-migration`;function st(){let{data:e}=L(void 0);return(e??[]).some(e=>e.addons.some(e=>e.capabilities.includes(ot)))}var ct=[{id:`recordings`,label:`Recordings`,locationType:`recordings`},{id:`recordingsLow`,label:`Low-res recordings`,locationType:`recordingsLow`},{id:`eventMedia`,label:`Event media`,locationType:`eventMedia`}],lt=new Set([`planning`,`pausing`,`moving`,`verifying`,`repointing`,`refreshing`,`resuming`]);function ut(){return st()?o(dt,{}):o(O,{icon:Q,title:`Storage migration not installed`,description:`This system doesn't advertise the storage-migration capability yet. Once it's deployed, this panel moves recordings, low-res recordings and event media to new storage locations in one coordinated, verified operation.`})}function dt(){let e=I(),{data:t}=_({}),[i,s]=a({}),[c,l]=a(null),[u,d]=a(null),f=r(()=>{let e=new Map;for(let n of t??[]){let t=e.get(n.type);t?t.push(n):e.set(n.type,[n])}return e},[t]),p=te({},{refetchInterval:2e3}),m=p.data??null,h=m!==null&&lt.has(m.phase),v=r(()=>{let e={};for(let t of ct){let n=i[t.id];n&&(e[t.id]=n)}return Object.keys(e).length>0?e:void 0},[i]),b=g({destinations:v??{}},{enabled:!1,retry:!1}),x=y(),S=D(),C=async()=>{if(!v)return;d(null);let e=await b.refetch();if(e.error){d(e.error instanceof Error?e.error.message:String(e.error));return}l(e.data??null)},w=async()=>{if(v&&await e({title:`Start storage migration?`,message:`Pauses the affected writers, copies the data to the new locations, verifies it, then repoints the defaults. Safe to re-run if interrupted.`,confirmLabel:`Start migration`,variant:`danger`})){d(null);try{await x.mutateAsync({destinations:v}),l(null),await p.refetch()}catch(e){d(e instanceof Error?e.message:String(e))}}},T=async()=>{if(m&&await e({title:`Cancel migration?`,message:`Stops the in-progress migration. Data already moved and verified stays at the destination; anything already repointed is not reverted.`,confirmLabel:`Cancel migration`,variant:`danger`}))try{await S.mutateAsync({jobId:m.jobId}),await p.refetch()}catch{}};return n(`div`,{className:`flex flex-col gap-6`,children:[n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[n(`h3`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[o(Q,{className:`h-3.5 w-3.5`}),`Storage migration`]}),o(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`Move recordings, low-res recordings and/or event media to new storage locations in one coordinated operation: pauses the writers, copies via the recorder / pipeline-analytics movers, verifies, then repoints the defaults. Always applies to every camera — destinations are global defaults per storage class, so migration can't be scoped to a subset of cameras. This is the only supported way to move a storage location's data — the Storage tab no longer offers a per-location "Relocate" action.`}),o(`div`,{className:`mt-3 grid grid-cols-1 gap-3 sm:grid-cols-3`,children:ct.map(e=>{let t=f.get(e.locationType)??[];return n(`div`,{className:`space-y-1`,children:[o(`label`,{htmlFor:`migration-dest-${e.id}`,className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e.label}),n(`select`,{id:`migration-dest-${e.id}`,value:i[e.id]??``,onChange:t=>{let n=t.target.value;s(t=>({...t,[e.id]:n}))},disabled:h,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground disabled:opacity-50`,children:[o(`option`,{value:``,children:`— unchanged —`}),t.map(e=>o(`option`,{value:e.id,children:e.displayName},e.id))]})]},e.id)})}),u&&o(`p`,{className:`mt-2 text-[11px] text-danger`,children:u}),n(`div`,{className:`mt-3 flex items-center gap-2`,children:[n(`button`,{type:`button`,onClick:()=>{C()},disabled:!v||b.isFetching||h,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover disabled:opacity-50`,children:[b.isFetching&&o(U,{className:`h-3 w-3 animate-spin`}),`Plan`]}),n(`button`,{type:`button`,onClick:()=>{w()},disabled:!v||x.isPending||h,className:`inline-flex items-center gap-1.5 rounded bg-primary px-2.5 py-1.5 text-xs font-medium text-primary-foreground disabled:opacity-50`,children:[x.isPending&&o(U,{className:`h-3 w-3 animate-spin`}),`Start migration`]})]}),c&&o(`div`,{className:`mt-3 divide-y divide-border rounded-md border border-border`,children:c.moves.length===0?o(`p`,{className:`px-2.5 py-1.5 text-[11px] text-foreground-subtle`,children:`Nothing to move — selected destinations match the current defaults.`}):c.moves.map(e=>n(`div`,{className:`px-2.5 py-1.5 text-[11px] text-foreground`,children:[e.storageClass,`: `,e.fromLocationId,` → `,e.toLocationId]},`${e.storageClass}-${e.toLocationId}`))})]}),m&&n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[n(`div`,{className:`flex items-center justify-between`,children:[o(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Migration status`}),h&&n(`button`,{type:`button`,onClick:()=>{T()},className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10`,children:[o(Y,{className:`h-3 w-3`}),`Cancel`]})]}),n(`p`,{className:`mt-1 text-xs text-foreground`,children:[`Phase: `,o(`span`,{className:`font-medium`,children:m.phase}),h&&o(U,{className:`ml-2 inline h-3 w-3 animate-spin text-primary`})]}),m.error&&o(`p`,{className:`mt-1 text-[11px] text-danger`,children:m.error}),m.pausedParticipants.length>0&&n(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:[`Paused: `,m.pausedParticipants.join(`, `)]}),o(`div`,{className:`mt-2 divide-y divide-border rounded-md border border-border`,children:m.moves.map(e=>n(`div`,{className:`flex items-center justify-between px-2.5 py-1.5 text-[11px]`,children:[n(`span`,{className:`text-foreground`,children:[e.storageClass,`: `,e.fromLocationId,` → `,e.toLocationId]}),n(`span`,{className:`text-foreground-subtle`,children:[e.state??`pending`,e.error?` (${e.error})`:``]})]},e.storageClass))})]})]})}function ft(){return n(`div`,{className:`flex flex-col gap-8`,children:[n(`div`,{children:[o(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Recording`}),o(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The cluster recording node and recordings folders.`}),n(`div`,{className:`mt-3 flex flex-col gap-6`,children:[o($e,{}),o(tt,{})]})]}),n(`div`,{children:[o(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Events`}),o(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The cluster post-processing node, the events folder, and the durable event-store footprint with retention and per-camera deletion.`}),n(`div`,{className:`mt-3 flex flex-col gap-6`,children:[o(Xe,{}),o(at,{})]})]}),n(`div`,{children:[o(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Migration`}),o(`div`,{className:`mt-3`,children:o(ut,{})})]})]})}function pt(){return o(se,{icon:q,title:`Recordings`,subtitle:`Recording node & storage, event-store management, exported clips, and an activity log.`,children:o(ue,{tabs:[{id:`storage`,label:`Storage`,icon:V,content:o(He,{})},{id:`cameras`,label:`Cameras`,icon:J,content:o(pe,{})},{id:`exports`,label:`Export`,icon:q,content:o(Oe,{})},{id:`activity`,label:`Activity`,icon:W,content:o(Ke,{})},{id:`management`,label:`Management`,icon:fe,content:o(ft,{})}]})})}export{pt as RecordingsPage};
@@ -1 +0,0 @@
1
- import{K as e}from"./index-DkufJo5r.js";var t=e(`circle-check-big`,[[`path`,{d:`M21.801 10A10 10 0 1 1 17 3.335`,key:`yps3ct`}],[`path`,{d:`m9 11 3 3L22 4`,key:`1pflzl`}]]);export{t};
@@ -1 +0,0 @@
1
- import{K as e}from"./index-DkufJo5r.js";var t=e(`clock`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`polyline`,{points:`12 6 12 12 16 14`,key:`68esgv`}]]);export{t};