@camstack/addon-admin-ui 1.2.459 → 1.2.460

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 (148) hide show
  1. package/dist/assets/{AddonAssetIcon-BJEJ1k08.js → AddonAssetIcon-D34ETuUY.js} +1 -1
  2. package/dist/assets/Addons-CgBqBge8.js +4 -0
  3. package/dist/assets/{AdminPage-COkr2pSl.js → AdminPage-DR77_HbX.js} +1 -1
  4. package/dist/assets/{AdminSectionedPage-DacqZ038.js → AdminSectionedPage-CjqX3s11.js} +1 -1
  5. package/dist/assets/AiProfiles-BCwpORLm.js +3 -0
  6. package/dist/assets/BrokerForm-BRqn1YkQ.js +1 -0
  7. package/dist/assets/{Build-C-5lgbq3.js → Build-ClOzVQfs.js} +5 -5
  8. package/dist/assets/Calendars-CBoSQYDb.js +1 -0
  9. package/dist/assets/{Cluster-9x8btsN4.js → Cluster-DRNVLj1k.js} +1 -1
  10. package/dist/assets/CompositionEditor-DMf4BAe3.js +1 -0
  11. package/dist/assets/CompositionEditorPage-CzNZMblE.js +1 -0
  12. package/dist/assets/Data-H0iqkofK.js +2 -0
  13. package/dist/assets/DeviceDetail-DxOdxrh3.js +2 -0
  14. package/dist/assets/DeviceDoActionFields-DzCHBj65.js +1 -0
  15. package/dist/assets/Devices-DKbjdxcr.js +1 -0
  16. package/dist/assets/{EmbedPlayerPage-yV8Ghwca.js → EmbedPlayerPage-Cy-nFopg.js} +1 -1
  17. package/dist/assets/History-C87WOkmh.js +1 -0
  18. package/dist/assets/Identity-Cvu5d-Dp.js +1 -0
  19. package/dist/assets/IntegrationDetail-BP5Tp1Xv.js +1 -0
  20. package/dist/assets/IntegrationHub-fFIljDH3.js +1 -0
  21. package/dist/assets/Integrations-Bxk1Pm6v.js +1 -0
  22. package/dist/assets/Integrations-a8KDlcvK.js +1 -0
  23. package/dist/assets/Library-Bn3TiJ8y.js +1 -0
  24. package/dist/assets/Locations-kMreeWCo.js +3 -0
  25. package/dist/assets/{Logs--6yOXDdG.js → Logs-BINANLCk.js} +1 -1
  26. package/dist/assets/{MaskShapeCanvas-BFRANocL.js → MaskShapeCanvas-BIzAwkst.js} +1 -1
  27. package/dist/assets/{MotionZonesSettings-DAR1lGRc.js → MotionZonesSettings-DnZRB_4R.js} +1 -1
  28. package/dist/assets/MyAccess-C4nalat5.js +2 -0
  29. package/dist/assets/Network-oFeEwPiX.js +1 -0
  30. package/dist/assets/NodeAddonsSettingsPanel-BGv4byJ3.js +1 -0
  31. package/dist/assets/Notifications-DL5HsEPP.js +1 -0
  32. package/dist/assets/Pipeline-CCYyFQs2.js +1 -0
  33. package/dist/assets/{PrivacyMaskSettings-CFjaiNPa.js → PrivacyMaskSettings-B1S3oQXv.js} +1 -1
  34. package/dist/assets/Recordings-CVFFAgP5.js +1 -0
  35. package/dist/assets/ScanNetworkModal-DiohLY4p.js +1 -0
  36. package/dist/assets/{SceneMonitorEditor-CtObZ92A.js → SceneMonitorEditor-BOBxjly7.js} +1 -1
  37. package/dist/assets/SessionsList-BHz78Zw6.js +2 -0
  38. package/dist/assets/Showroom-ndNDu6AF.js +1 -0
  39. package/dist/assets/System-BxeSBDfd.js +1 -0
  40. package/dist/assets/{Terminal-CfhgVSfX.js → Terminal-JlLeryPw.js} +3 -3
  41. package/dist/assets/{Viewer-DOy7SpD5.js → Viewer-CUYAjAr2.js} +1 -1
  42. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-FGBBI8DM.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DO_2_4ZT.js} +1 -1
  43. package/dist/assets/{addon-icons-context-zSgVMYOT.js → addon-icons-context-BR7L-Tl4.js} +1 -1
  44. package/dist/assets/{archive-CCdQLR92.js → archive-C91oVgt5.js} +1 -1
  45. package/dist/assets/{authed-media-BnRlGkoA.js → authed-media-BLAkkFbc.js} +1 -1
  46. package/dist/assets/{bell-off-CqtliYfE.js → bell-off-CwDLJ3dr.js} +1 -1
  47. package/dist/assets/{board-model-DcXa88Au.js → board-model-D0uZ4Hi-.js} +1 -1
  48. package/dist/assets/{boxes-DQn7OALq.js → boxes-BqbPUbNG.js} +1 -1
  49. package/dist/assets/circle-slash-mKgId_-0.js +1 -0
  50. package/dist/assets/client-Bk3bp5F2.js +358 -0
  51. package/dist/assets/{cloud-upload-Ds0DBFF4.js → cloud-upload-mL-8gqPE.js} +1 -1
  52. package/dist/assets/crop-o9eS9Vg7.js +1 -0
  53. package/dist/assets/device-integration-icon-6CS7KQYP.js +1 -0
  54. package/dist/assets/device-picker-model--DJ7vWrZ.js +1 -0
  55. package/dist/assets/dist-DEi6Qrdg.js +358 -0
  56. package/dist/assets/{dist-DGtsAF0e.js → dist-q6ZbxCLt.js} +1 -1
  57. package/dist/assets/{eraser-CBhjXP5B.js → eraser-TGxNpy2a.js} +1 -1
  58. package/dist/assets/{hard-drive-download-Bbqt0BU7.js → hard-drive-download-D9Rkcg5b.js} +1 -1
  59. package/dist/assets/{hostInit-DYH0aGPp.js → hostInit-DpIklA1C.js} +1 -1
  60. package/dist/assets/i18n-CWIrO_Qb.js +1 -0
  61. package/dist/assets/{icons-CIAj8beD.js → icons-Dr-Mg6Rp.js} +1 -1
  62. package/dist/assets/index-CfyMTyLK.css +2 -0
  63. package/dist/assets/index-D3LY1t1A.js +4 -0
  64. package/dist/assets/{key-BrmsyfQ2.js → key-YOvsTqKG.js} +1 -1
  65. package/dist/assets/{key-round-DupHhW0i.js → key-round-BZ4X-rUb.js} +1 -1
  66. package/dist/assets/{layers-jV4_DPMS.js → layers-Dof6dMwp.js} +1 -1
  67. package/dist/assets/{linked-devices-model-Wflvd004.js → linked-devices-model-CMebF7aU.js} +1 -1
  68. package/dist/assets/{list-ordered-DOEvj-y0.js → list-ordered-Co9pKx8m.js} +1 -1
  69. package/dist/assets/location-owned-usage-CsAzpjY3.js +1 -0
  70. package/dist/assets/{log-in-CcPfrqgr.js → log-in-CHySLCGD.js} +1 -1
  71. package/dist/assets/{memory-stick-q_w6rp-t.js → memory-stick-0Z6zphbD.js} +1 -1
  72. package/dist/assets/{message-square-plus-9n6eNHhb.js → message-square-plus-DlQEXnei.js} +1 -1
  73. package/dist/assets/{mf-entry-bootstrap-0-44ebd2c3.js → mf-entry-bootstrap-0-4cca1fc4.js} +2 -2
  74. package/dist/assets/{mic-off-D8Z3zvJC.js → mic-off-B-AwHbuE.js} +1 -1
  75. package/dist/assets/{monitor-off-ChiwdYm2.js → monitor-off-BXvpLLls.js} +1 -1
  76. package/dist/assets/{monitor-smartphone-5A2YPeJg.js → monitor-smartphone-B0_0dH0j.js} +1 -1
  77. package/dist/assets/mount--DJ7vWrZ.js +1 -0
  78. package/dist/assets/{player-overlays-B2uKzPiF.js → player-overlays-Dx9MsPRB.js} +1 -1
  79. package/dist/assets/{recycle-lkNup4GK.js → recycle-hQF3Eedf.js} +1 -1
  80. package/dist/assets/remoteEntry-fmZ04jeg.js +1 -0
  81. package/dist/assets/{scan-eye-CJpdZenM.js → scan-eye-CaBHblK8.js} +1 -1
  82. package/dist/assets/{scissors-v8FUfmH0.js → scissors-Cn0y5BDd.js} +1 -1
  83. package/dist/assets/{search-x-CJx173bU.js → search-x-BFUKepJY.js} +1 -1
  84. package/dist/assets/{send-XYAWcADm.js → send-DnFrAxG7.js} +1 -1
  85. package/dist/assets/{settings-2-Bgu4fxha.js → settings-2-TvLz8e2t.js} +1 -1
  86. package/dist/assets/{speaker-ofUzLdUT.js → speaker-5LjbBCEM.js} +1 -1
  87. package/dist/assets/src-D293nH2g.js +67 -0
  88. package/dist/assets/{step-inspector-model-C7JCmVfz.js → step-inspector-model-PJaQfiIl.js} +1 -1
  89. package/dist/assets/{timer-reset-D-5iU9l-.js → timer-reset-DHDxq-YS.js} +1 -1
  90. package/dist/assets/{ungroup-DD3pb37b.js → ungroup-B3qoTqBs.js} +1 -1
  91. package/dist/assets/{unlink-xgj0DHXA.js → unlink-pSJVFfzP.js} +1 -1
  92. package/dist/assets/{usb-COQJ7FVk.js → usb-8iIkiKi4.js} +1 -1
  93. package/dist/assets/{use-scenes-feed-Cr8WJGCC.js → use-scenes-feed-xDDedfcQ.js} +1 -1
  94. package/dist/assets/{use-stationary-objects-kiH5Q2gT.js → use-stationary-objects-D0sT-_dl.js} +1 -1
  95. package/dist/assets/useEventInvalidation--DJ7vWrZ.js +1 -0
  96. package/dist/assets/useNodeUrlSelection-Ci3kxs0x.js +1 -0
  97. package/dist/assets/user-round-lV0LR5iu.js +1 -0
  98. package/dist/assets/{user-x-CBuwxTd8.js → user-x-Be8HX8C7.js} +1 -1
  99. package/dist/assets/{video-CCbgIO_h.js → video-BiU6h1kt.js} +1 -1
  100. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CxTajz7L.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CgcmxUPa.js} +2 -2
  101. package/dist/index.html +10 -11
  102. package/dist/server/addon.js +92 -89
  103. package/package.json +1 -1
  104. package/dist/assets/Addons-DHanUVT2.js +0 -4
  105. package/dist/assets/AiProfiles-00eup-gf.js +0 -3
  106. package/dist/assets/BrokerForm-BZXEvLK0.js +0 -1
  107. package/dist/assets/Calendars-BkpP1D2U.js +0 -1
  108. package/dist/assets/CompositionEditor-r0DF2l8O.js +0 -1
  109. package/dist/assets/CompositionEditorPage-ZgZUzIco.js +0 -1
  110. package/dist/assets/Data-CRUK3PE2.js +0 -2
  111. package/dist/assets/DeviceDetail-B-WDYuF4.js +0 -2
  112. package/dist/assets/DeviceDoActionFields-B6h8uYuA.js +0 -1
  113. package/dist/assets/Devices--JO66DyO.js +0 -1
  114. package/dist/assets/History-BwlSzH55.js +0 -1
  115. package/dist/assets/Identity-BWhaEMdv.js +0 -1
  116. package/dist/assets/IntegrationDetail-CQTl55bJ.js +0 -1
  117. package/dist/assets/IntegrationHub-1t9XtENg.js +0 -1
  118. package/dist/assets/Integrations-BsHioywX.js +0 -1
  119. package/dist/assets/Integrations-DAZG8yCP.js +0 -1
  120. package/dist/assets/Library-I8I-H4B0.js +0 -1
  121. package/dist/assets/Locations-DpID1z6R.js +0 -3
  122. package/dist/assets/MyAccess-BlPaAQNJ.js +0 -2
  123. package/dist/assets/Network-68PrEWb3.js +0 -1
  124. package/dist/assets/NodeAddonsSettingsPanel-BU9D0unj.js +0 -1
  125. package/dist/assets/Notifications-BHMdjbhb.js +0 -1
  126. package/dist/assets/Pipeline-BntRM_Gg.js +0 -1
  127. package/dist/assets/Recordings-B0PFCiE6.js +0 -1
  128. package/dist/assets/ScanNetworkModal-KVlo34E_.js +0 -1
  129. package/dist/assets/SessionsList-BqQzJQzH.js +0 -2
  130. package/dist/assets/Showroom-BpbWCBms.js +0 -1
  131. package/dist/assets/System-Bi2UJjp7.js +0 -1
  132. package/dist/assets/circle-slash-BqXxDfpK.js +0 -1
  133. package/dist/assets/client-DUabg_ow.js +0 -358
  134. package/dist/assets/crop-Cfvx74Ee.js +0 -1
  135. package/dist/assets/device-integration-icon-Bb8AOXEF.js +0 -1
  136. package/dist/assets/device-picker-model-BtgtDdnV.js +0 -1
  137. package/dist/assets/dist-BgJn1_Ws.js +0 -358
  138. package/dist/assets/i18n-aZ2iCAl5.js +0 -1
  139. package/dist/assets/index-DKfAHLRf.js +0 -4
  140. package/dist/assets/index-I9On1g0c.css +0 -2
  141. package/dist/assets/location-owned-usage-D3Zl9d5o.js +0 -1
  142. package/dist/assets/mount-BtgtDdnV.js +0 -1
  143. package/dist/assets/notification-schedule-field-BGziM8ff.js +0 -1
  144. package/dist/assets/remoteEntry-DwoMnkvg.js +0 -1
  145. package/dist/assets/src-N0x0aMoc.js +0 -67
  146. package/dist/assets/useEventInvalidation-BtgtDdnV.js +0 -1
  147. package/dist/assets/useNodeUrlSelection-DpqDFKVD.js +0 -1
  148. package/dist/assets/user-round-Dy1LJO0f.js +0 -1
@@ -0,0 +1 @@
1
+ import{$ as e,B as t,G as n,J as r,L as i,S as a,Z as o,a as s,b as c,o as l,q as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Ai as f,At as p,D as m,Di as h,Dr as g,Dt as _,Ei as v,Fn as y,Fr as b,It as x,Jt as S,Nt as C,Q as w,Si as T,Wr as E,Wt as D,Yt as O,Z as k,Zr as A,Zt as j,_r as M,ai as N,bi as P,bn as F,c as I,dt as L,f as R,fn as z,ir as B,kn as V,l as H,mn as U,or as W,ot as G,ta as ee,u as te,vn as ne,xi as K,yi as re,z as ie}from"./player-overlays-Dx9MsPRB.js";import{lr as q,ta as ae,tt as oe}from"./client-Bk3bp5F2.js";import{a as se,c as ce,i as le,n as ue,o as de,r as fe,s as pe,t as me}from"./user-x-Be8HX8C7.js";import{c as he}from"./video-BiU6h1kt.js";import{t as ge}from"./crop-o9eS9Vg7.js";import{t as _e}from"./user-round-lV0LR5iu.js";import{$s as ve,Bo as ye,Br as be,Fo as xe,Fr as J,Ho as Se,Hr as Ce,Io as we,Lo as Te,Lu as Ee,Mo as De,Mr as Oe,Mu as ke,No as Ae,Nr as je,Ou as Me,Po as Ne,Pr as Pe,Ps as Fe,Qs as Ie,Qt as Le,Ro as Re,Ru as ze,Un as Be,Uo as Ve,Vo as He,Vr as Ue,Xs as We,_n as Ge,_r as Ke,ac as qe,al as Je,ar as Ye,cl as Xe,cr as Ze,di as Qe,dl as $e,dr as et,ec as tt,fl as nt,ft as rt,gn as it,gr as at,ic as ot,il as st,ir as ct,jo as lt,ku as ut,ll as dt,ln as ft,lt as pt,mn as mt,nc as ht,nd as gt,nl as _t,nr as vt,ol as yt,on as bt,or as xt,pl as St,rl as Ct,sl as wt,sn as Tt,sr as Et,t as Dt,tl as Ot,to as kt,ul as At,ut as jt,yt as Mt,zo as Nt}from"./src-D293nH2g.js";import{t as Y}from"./i18n-CWIrO_Qb.js";import{t as X}from"./useTranslation-D3Is_4B6.js";import"./mount--DJ7vWrZ.js";import{T as Pt,_r as Ft,gr as It,mr as Lt,yr as Rt}from"./index-D3LY1t1A.js";import{t as zt}from"./AdminSectionedPage-CjqX3s11.js";import{t as Bt}from"./use-stationary-objects-D0sT-_dl.js";import{a as Vt,i as Ht,n as Ut,r as Wt,t as Gt}from"./authed-media-BLAkkFbc.js";import{t as Kt}from"./use-scenes-feed-xDDedfcQ.js";e();function qt({mediaId:e,base64:t,alt:n,className:r,placeholder:i}){let{src:a,failed:o}=Vt(e===void 0?void 0:Wt(e));return a===null?(e===void 0||o)&&t!==void 0&&t!==``?d(`img`,{src:`data:image/jpeg;base64,${t}`,alt:n,className:r}):i:d(`img`,{src:a,alt:n,className:r})}var Jt=`pipeline-analytics`,Yt=`photo.analyze`,Xt=`photo.enroll`,Zt=`photo.discard`,Qt=18*1024*1024;function $t(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function en(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function tn(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function nn(e,t){let n=e[t];return typeof n==`boolean`?n:null}function rn(e){if(!$t(e))return null;let t=tn(e,`x`),n=tn(e,`y`),r=tn(e,`width`),i=tn(e,`height`);return t===null||n===null||r===null||i===null?null:{x:t,y:n,width:r,height:i}}function an(e){if(!$t(e))return null;let t=tn(e,`detectionShortSidePx`),n=tn(e,`score`);if(t===null||n===null)return null;let r=tn(e,`magnitude`);return{detectionShortSidePx:t,score:n,...r===null?{}:{magnitude:r}}}function on(e){if(!$t(e))return null;let t=tn(e,`faceIndex`),n=tn(e,`score`),r=nn(e,`enrollable`),i=rn(e.bbox),a=an(e.quality);if(t===null||n===null||r===null||i===null||a===null)return null;let o=en(e,`refusedReason`),s=en(e,`alignedCropBase64`),c=en(e,`modelId`);return{faceIndex:t,bbox:i,score:n,enrollable:r,quality:a,...o===null?{}:{refusedReason:o},...s===null?{}:{alignedCropBase64:s},...c===null?{}:{modelId:c}}}function sn(e){if(!$t(e))return null;let t=en(e,`sessionId`),n=en(e,`ranOnNodeId`),r=e.faces;if(t===null||n===null||!Array.isArray(r))return null;let i=[];for(let e of r){let t=on(e);t!==null&&i.push(t)}return{sessionId:t,ranOnNodeId:n,faces:i}}function cn(e){if(!$t(e))return null;let t=en(e,`sampleId`),n=en(e,`identityId`),r=en(e,`modelId`);return t===null||n===null||r===null?null:{sampleId:t,identityId:n,modelId:r}}function ln(e,t,n){let r={...e};return n===null||n===``?delete r[t]:r[t]=n,r}function un(e,t){return e.filter(e=>e.enrollable&&t[e.faceIndex]!==void 0).length}function dn(e,t,n){let r=[];for(let i of t){if(!i.enrollable)continue;let t=n[i.faceIndex];t!==void 0&&r.push({sessionId:e,faceIndex:i.faceIndex,identityId:t})}return r}function fn(e){switch(e){case`no-embedding`:return Y.t(`helpers.photoEnroll.refusal.noEmbedding`);case`no-model-id`:return Y.t(`helpers.photoEnroll.refusal.noModelId`);case`no-aligned-crop`:return Y.t(`helpers.photoEnroll.refusal.noAlignedCrop`);case`magnitude`:return Y.t(`helpers.photoEnroll.refusal.magnitude`);default:return Y.t(`helpers.photoEnroll.refusal.default`)}}function pn(e,t){let n=[],r=[];for(let i of e)i.size>t.maxBytes?n.push(i.name):r.push(i);return{accepted:r.slice(0,t.maxCount),oversize:n,overflow:r.slice(t.maxCount).map(e=>e.name)}}async function mn(e,t,n){let r=Array(e.length),i=e.map((e,t)=>({item:e,index:t})),a=0,o=async()=>{for(;;){let e=i[a];if(a+=1,e===void 0)return;r[e.index]=await n(e.item,e.index)}},s=Array.from({length:Math.max(1,Math.min(t,e.length))},()=>o());return await Promise.all(s),r}function hn(e,t,n){return e.map(e=>e.photoIndex===t?{...e,...n}:e)}function gn(e,t){return`${e}:${t}`}function _n(e,t,n,r){let i=ln(e[t]??{},n,r),a={...e};return Object.keys(i).length===0?delete a[t]:a[t]=i,a}function vn(e,t){let n=0;for(let r of e)r.analysis!==void 0&&(n+=un(r.analysis.faces,t[r.photoIndex]??{}));return n}var yn=`__new__`;function bn(e,t,n){let r=[];for(let i of e){if(i.analysis===void 0)continue;let e=t[i.photoIndex]??{};for(let t of i.analysis.faces){if(!t.enrollable||e[t.faceIndex]!==`__new__`)continue;let a=(n[gn(i.photoIndex,t.faceIndex)]??``).trim();if(a===``)return{kind:`error`,message:Y.t(`helpers.photoEnrollBatch.newPersonNoName`,{filename:i.filename,face:t.faceIndex+1})};r.includes(a)||r.push(a)}}return{kind:`ok`,names:r}}function xn(e,t,n){let r={};for(let[i,a]of Object.entries(e)){let e=Number(i),o={};for(let[r,i]of Object.entries(a)){let a=Number(r);if(i!==`__new__`){o[a]=i;continue}let s=n[(t[gn(e,a)]??``).trim()];s!==void 0&&(o[a]=s)}r[e]=o}return r}function Sn(e,t){let n=[];for(let r of e){if(r.analysis===void 0)continue;let e=dn(r.analysis.sessionId,r.analysis.faces,t[r.photoIndex]??{});for(let t of e)n.push({photoIndex:r.photoIndex,request:t})}return n}function Cn(e){return/expired/i.test(e)}function wn(e){return e instanceof Error?e.message:String(e)}async function Tn(e,t,n){let r=new Map(e.map(e=>[e.photoIndex,e])),i={},a=[],o=0,s=null,c=(e,t)=>{let n=r.get(e)?.filename??Y.t(`helpers.photoEnrollBatch.photoFallback`,{n:e+1});return Y.t(`helpers.photoEnrollBatch.faceLabel`,{filename:n,face:t+1})};for(let l of Sn(e,t)){let e=i[l.photoIndex],t=e===void 0?l.request:{...l.request,sessionId:e.sessionId};try{let e=await n.enroll(t);o+=1,s=e.modelId}catch(t){let u=wn(t);if(!Cn(u)||e!==void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${u}`);continue}let d=r.get(l.photoIndex);if(d===void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${u}`);continue}let f;try{f=await n.reanalyze(d)}catch(e){a.push(`${c(l.photoIndex,l.request.faceIndex)}: the analysis expired and re-analysing failed (${wn(e)})`);continue}if(i[l.photoIndex]=f,f.faces.find(e=>e.faceIndex===l.request.faceIndex&&e.enrollable)===void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: the analysis expired, and re-analysing no longer finds this face — assign it again from the fresh result`);continue}try{let e=await n.enroll({...l.request,sessionId:f.sessionId});o+=1,s=e.modelId}catch(e){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${wn(e)}`)}}}return{enrolled:o,stampedModelId:s,failures:a,refreshedAnalyses:i}}var En=[[`faceGallery`]],Dn=``;function On(e){return new Promise((t,n)=>{let r=new FileReader;r.addEventListener(`error`,()=>n(Error(`the file could not be read`)),{once:!0}),r.addEventListener(`load`,()=>{let e=r.result;if(typeof e!=`string`){n(Error(`the file could not be read`));return}let i=e.indexOf(`,`);t(i>=0?e.slice(i+1):e)},{once:!0}),r.readAsDataURL(e)})}function kn(e){return e instanceof Error?e.message:String(e)}function An({face:e,identities:t,value:r,onChange:i,disabled:o}){let{t:s}=X(),l=n(()=>[{value:Dn,label:s(`detectionIntelligence.photoEnrollDialog.ignoreThisFace`,`Ignore this face`)},...t.map(e=>({value:e.id,label:e.name})),{value:yn,label:s(`detectionIntelligence.photoEnrollDialog.newPerson`,`+ New person…`)}],[t,s]);return a(`div`,{className:`rounded-md border border-border bg-surface p-2`,children:[d(`div`,{className:`mb-2 aspect-square w-full overflow-hidden rounded border border-border bg-surface-hover`,children:e.alignedCropBase64?d(`img`,{src:`data:image/jpeg;base64,${e.alignedCropBase64}`,alt:s(`detectionIntelligence.photoEnrollDialog.face`,`Face {{value1}}`,{value1:e.faceIndex+1}),className:`h-full w-full object-cover`}):d(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:d(_e,{className:`h-8 w-8`})})}),d(`div`,{className:`min-h-[4.75rem]`,children:e.enrollable?a(c,{children:[d(ke,{options:l,value:r,disabled:o,onChange:e=>i(e.target.value),"aria-label":s(`detectionIntelligence.photoEnrollDialog.assignFace`,`Assign face {{value1}}`,{value1:e.faceIndex+1})}),a(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:[Math.round(e.quality.detectionShortSidePx),` px`,e.modelId?` · ${e.modelId}`:``]})]}):a(`div`,{className:`space-y-1`,children:[d(Ce,{variant:`warning`,className:`text-[10px]`,children:s(`detectionIntelligence.photoEnrollDialog.notUsable`,`Not usable`)}),d(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:fn(e.refusedReason)})]})})]})}function jn({photo:e,identities:t,draft:n,newNames:r,disabled:i,onAssign:o,onNameChange:s,onRetry:c}){let{t:l}=X(),u=e.analysis?.faces??[],f=n[e.photoIndex]??{};return a(`div`,{className:`space-y-2`,children:[a(`div`,{className:`flex items-center gap-2 border-b border-border pb-1`,children:[d(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.filename}),e.status===`analyzing`||e.status===`queued`?a(`span`,{className:`flex items-center gap-1 text-xs text-foreground-subtle`,children:[d(W,{className:`h-3 w-3 animate-spin`}),` `,l(`detectionIntelligence.photoEnrollDialog.analysing`)]}):null,e.status===`analyzed`&&e.analysis!==void 0&&d(`span`,{className:`text-xs text-foreground-subtle`,children:l(`detectionIntelligence.photoEnrollDialog.facesAnalysedOn`,{count:u.length,node:e.analysis.ranOnNodeId})}),e.status===`failed`&&a(J,{variant:`secondary`,size:`sm`,disabled:i,onClick:c,children:[d(ne,{className:`h-3 w-3`}),` `,l(`common.retry`)]})]}),e.status===`failed`&&a(`div`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[d(C,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),a(`span`,{children:[l(`detectionIntelligence.photoEnrollDialog.thisPhotoCouldNotBe`,`This photo could not be analysed:`),` `,e.error??l(`detectionIntelligence.photoEnrollDialog.unknownError`,`unknown error`),`. The other photos are unaffected.`]})]}),e.status===`analyzed`&&u.length===0&&d(`p`,{className:`text-xs text-foreground-subtle`,children:l(`detectionIntelligence.photoEnrollDialog.noFacesWereFoundIn`,`No faces were found in this photo. A face has to be reasonably large and facing the camera for the detector to measure it.`)}),u.length>0&&d(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(7rem,7rem))] justify-start gap-3`,children:u.map(e=>d(An,{face:e,identities:t,value:f[e.faceIndex]??Dn,disabled:i,onChange:t=>o(e.faceIndex,t)},e.faceIndex))}),u.filter(e=>f[e.faceIndex]===yn).map(t=>a(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`w-28 shrink-0 truncate text-xs text-foreground-subtle`,children:l(`detectionIntelligence.photoEnrollDialog.faceN`,{n:t.faceIndex+1})}),d(`input`,{className:`h-7 flex-1 rounded-md border border-border bg-surface px-2.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,placeholder:l(`detectionIntelligence.photoEnrollDialog.newPersonNameTypeThe`,`New person name… (type the same name under another face to reuse it)`),value:r[gn(e.photoIndex,t.faceIndex)]??``,onChange:e=>s(t.faceIndex,e.target.value)})]},t.faceIndex))]})}function Mn({open:e,onOpenChange:t}){let{t:o}=X(),s=G(),c=l(),f=u(null),{data:p}=we(),m=De(),[h,g]=r([]),[_,v]=r(!1),[y,b]=r(null),[x,S]=r({}),[w,T]=r({}),[E,D]=r(null),O=n(()=>(p??[]).map(e=>({id:e.id,name:e.name})),[p]),k=h.some(e=>e.status===`queued`||e.status===`analyzing`),A=k||_,j=i(e=>{for(let t of e){let e=t.analysis?.sessionId;e!==void 0&&s.trpcClient.addons.custom.mutate({addonId:Jt,action:Zt,input:{sessionId:e}}).catch(()=>void 0)}},[s]),M=i(()=>{g([]),S({}),T({}),b(null),D(null),f.current&&(f.current.value=``)},[]),N=i(()=>{j(h),M(),t(!1)},[j,t,h,M]),P=i(async e=>{let t=sn(await s.trpcClient.addons.custom.mutate({addonId:Jt,action:Yt,input:{photoBase64:e.photoBase64,filename:e.filename}}));if(t===null)throw Error(`the server replied with something this page could not read`);return t},[s]),F=i(async e=>{g(t=>hn(t,e.photoIndex,{status:`analyzing`,error:void 0}));try{let t=await P(e);g(n=>hn(n,e.photoIndex,{status:`analyzed`,analysis:t}))}catch(t){g(n=>hn(n,e.photoIndex,{status:`failed`,error:kn(t)}))}},[P]),I=i(async e=>{if(e.length===0)return;j(h),M();let t=pn(e,{maxCount:12,maxBytes:Qt}),n=[];t.oversize.length>0&&n.push(`Over the ${Math.round(Qt/(1024*1024))} MB limit and skipped: ${t.oversize.join(`, `)}.`),t.overflow.length>0&&n.push(`A batch holds at most 12 photos — not analysed: ${t.overflow.join(`, `)}. Enrol them in a second round.`),n.length>0&&b(n.join(` `));let r;try{r=await Promise.all(t.accepted.map(async(e,t)=>({photoIndex:t,filename:e.name,photoBase64:await On(e),status:`queued`})))}catch(e){b(kn(e));return}g(r),await mn(r,2,e=>F(e))},[j,h,M,F]),L=vn(h,x),R=i(async()=>{v(!0),b(null),D(null);try{let e=bn(h,x,w);if(e.kind===`error`){b(e.message);return}let t={};for(let n of e.names)t[n]=(await m.mutateAsync({name:n})).id;let n=await Tn(h,xn(x,w,t),{enroll:async e=>{let t=cn(await s.trpcClient.addons.custom.mutate({addonId:Jt,action:Xt,input:e}));if(t===null)throw Error(`unreadable reply`);return t},reanalyze:e=>P(e)});Object.keys(n.refreshedAnalyses).length>0&&g(e=>e.map(e=>{let t=n.refreshedAnalyses[e.photoIndex];return t===void 0?e:{...e,status:`analyzed`,analysis:t}})),c.invalidateQueries({queryKey:En}),n.failures.length>0&&b(n.failures.join(` · `)),D(n.enrolled===0?`Nothing was enrolled.`:`Enrolled ${n.enrolled} sample${n.enrolled===1?``:`s`}${n.stampedModelId===null?``:` with ${n.stampedModelId}`}.`)}catch(e){b(kn(e))}finally{v(!1)}},[P,m,x,w,h,c,s]),z=h.filter(e=>e.status===`analyzed`).length;return d(vt,{open:e,onOpenChange:e=>e?t(!0):N(),children:a(ct,{className:`max-w-3xl`,children:[a(Et,{children:[d(Ze,{children:o(`detectionIntelligence.photoEnrollDialog.enrolFromPhotos`,`Enrol from photos`)}),d(Ye,{children:o(`detectionIntelligence.photoEnrollDialog.everyPhotoIsAnalysedWith`,`Every photo is analysed with the same face detector the cameras use, and all the faces found are reviewed below in one pass, grouped by photo. Assign each face to a person, or leave it ignored.`)})]}),d(`div`,{className:`rounded-md border border-border bg-surface-hover px-3 py-2 text-xs text-foreground-subtle`,children:d(Lt,{i18nKey:`detectionIntelligence.photoEnrollDialog.reliableRecognition`,components:{strong:d(`strong`,{})}})}),a(`div`,{className:`flex items-center gap-2`,children:[d(`input`,{ref:f,type:`file`,accept:`image/jpeg,image/png,image/webp`,multiple:!0,className:`hidden`,onChange:e=>void I(Array.from(e.target.files??[]))}),a(J,{variant:`secondary`,size:`sm`,disabled:A,onClick:()=>f.current?.click(),children:[k?d(W,{className:`h-3.5 w-3.5 animate-spin`}):d(de,{className:`h-3.5 w-3.5`}),o(`detectionIntelligence.photoEnrollDialog.choosePhotos`,`Choose photos`)]}),h.length>0&&d(`span`,{className:`text-xs text-foreground-subtle`,children:o(`detectionIntelligence.photoEnrollDialog.photosAnalysed`,{done:z,count:h.length})})]}),d(`div`,{className:`min-h-11`,"aria-live":`polite`,children:y===null?E===null?null:d(`div`,{className:`rounded-md border border-success/40 bg-success/10 px-3 py-2 text-xs text-success`,children:E}):a(`div`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[d(C,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),d(`span`,{children:y})]})}),h.length>0&&d(`div`,{className:`max-h-[50vh] space-y-4 overflow-y-auto pr-1`,children:h.map(e=>d(jn,{photo:e,identities:O,draft:x,newNames:w,disabled:A,onAssign:(t,n)=>S(r=>_n(r,e.photoIndex,t,n===Dn?null:n)),onNameChange:(t,n)=>T(r=>({...r,[gn(e.photoIndex,t)]:n})),onRetry:()=>void F(e)},e.photoIndex))}),a(xt,{children:[d(J,{variant:`secondary`,onClick:N,disabled:_,children:o(`common.close`,`Close`)}),a(J,{variant:`primary`,onClick:()=>void R(),disabled:A||L===0,children:[_?d(W,{className:`h-3.5 w-3.5 animate-spin`}):null,o(`detectionIntelligence.photoEnrollDialog.enrolFaces`,{count:L})]})]})]})})}e();var Nn=[[`faceGallery`]];function Pn({identityId:e}){let{t}=X(),n=l(),{data:r,isLoading:i}=Te({identityId:e}),o=Nt();function s(t){o.mutate({identityId:e,sampleId:t.id},{onSettled:()=>{n.invalidateQueries({queryKey:Nn})}})}return i?a(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[d(W,{className:`h-3.5 w-3.5 animate-spin`}),t(`detectionIntelligence.peopleList.loadingSamples`,`Loading samples…`)]}):!r||r.length===0?d(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:t(`detectionIntelligence.peopleList.noSamplesYet`,`No samples yet.`)}):d(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:r.map(e=>a(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[e.base64?d(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:t(`detectionIntelligence.peopleList.sample`,`Sample`),className:`h-full w-full object-cover`}):d(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:d(_e,{className:`h-6 w-6`})}),e.source===`photo`&&d(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 p-0.5 text-white`,title:t(`detectionIntelligence.peopleList.enrolledFromAnUploadedPhoto`,`Enrolled from an uploaded photo`),children:d(de,{className:`h-3 w-3`})}),d(`button`,{type:`button`,onClick:()=>s(e),disabled:o.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":t(`detectionIntelligence.peopleList.removeSample`,`Remove sample`),children:d(L,{className:`h-4 w-4 text-white`})})]},e.id))})}function Fn(e){return[{key:`person`,header:Y.t(`detectionIntelligence.peopleList.person`,`Person`),sortValue:e=>e.name,render:e=>a(`span`,{className:`flex min-w-0 items-center gap-2`,children:[d(`span`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:d(qt,{mediaId:e.coverMediaId,base64:e.coverBase64,alt:e.name,className:`h-full w-full object-cover`,placeholder:d(`span`,{className:`flex h-full w-full items-center justify-center`,children:d(_e,{className:`h-4 w-4 text-foreground-subtle`})})})}),d(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})]})},{key:`samples`,header:Y.t(`detectionIntelligence.peopleList.samples`,`Samples`),align:`center`,nowrap:!0,sortValue:e=>e.sampleCount,render:e=>d(Ce,{variant:`default`,className:`text-[10px]`,children:e.sampleCount})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:t=>a(`span`,{className:`flex items-center justify-end gap-1`,children:[d(ze,{variant:`ghost`,size:`sm`,icon:y,"aria-label":Y.t(`detectionIntelligence.peopleList.edit`,`Edit {{name}}`,{name:t.name}),onClick:n=>{n.stopPropagation(),e.onEdit(t)}}),d(ze,{variant:`ghost`,size:`sm`,icon:x,"aria-label":Y.t(`detectionIntelligence.peopleList.delete`,`Delete {{name}}`,{name:t.name}),onClick:n=>{n.stopPropagation(),e.onDelete(t)}})]})}]}function In({mode:e,identity:n,onClose:i}){let{t:o}=X(),s=l(),[c,u]=r(e===`edit`?n?.name??``:``),f=De(),p=ye();t(()=>{u(e===`edit`?n?.name??``:``)},[e,n?.id,n?.name]);let m=f.isPending||p.isPending,h=c.trim(),g=e===`edit`&&n!==null&&h===n.name,_=m||h.length===0||g;function v(){s.invalidateQueries({queryKey:Nn})}function y(){if(!_){if(e===`new`){f.mutate({name:h},{onSuccess:()=>{v(),i()}});return}if(n===null){i();return}p.mutate({id:n.id,name:h},{onSuccess:()=>{v(),i()}})}}return d(rt,{open:!0,onClose:i,title:e===`new`?`Add person`:`Edit ${n?.name??`person`}`,icon:_e,width:e===`edit`?`xl`:`lg`,testId:`people-person-form`,footer:a(J,{variant:`primary`,size:`sm`,type:`button`,onClick:y,disabled:_,children:[m?d(W,{className:`h-3.5 w-3.5 animate-spin`}):null,e===`new`?o(`common.add`,`Add`):o(`common.save`,`Save`)]}),children:a(`div`,{className:`space-y-4`,children:[d(Mt,{label:o(`detectionIntelligence.peopleList.name`,`Name`),required:!0,children:d(Ee,{value:c,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&y()},placeholder:o(`detectionIntelligence.peopleList.personName`,`Person name…`),autoFocus:!0})}),e===`edit`&&n!==null&&a(`div`,{children:[d(`p`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:o(`detectionIntelligence.peopleList.trainingSamples`,`Training samples`)}),d(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:o(`detectionIntelligence.peopleList.removeASampleToDrop`,`Remove a sample to drop it from recognition training for this person.`)}),d(Pn,{identityId:n.id})]})]})})}function Ln(){let{t:e}=X(),i=l(),o=je(),{data:s,isLoading:c}=we(),u=Ne(),{state:f,openNew:p,openEdit:m,close:h}=jt(),[g,_]=r(!1),v=s??[],y=bt(v,{searchText:e=>[e.name]}),b=f.mode===`edit`?v.find(e=>e.id===f.id)??null:null;t(()=>{f.mode===`edit`&&!c&&b===null&&h()},[f.mode,c,b,h]);let x=n(()=>Fn({onEdit:e=>m(e.id),onDelete:t=>{(async()=>{await o({title:e(`detectionIntelligence.peopleList.deletePerson`,`Delete person`),message:e(`detectionIntelligence.peopleList.deleteAndAllTheirSamples`,`Delete {{name}} and all their samples? This cannot be undone.`,{name:t.name}),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&u.mutate({id:t.id},{onSettled:()=>{i.invalidateQueries({queryKey:Nn}),f.mode===`edit`&&f.id===t.id&&h()}})})()}}),[o,h,u,f,m,i,e]);if(c)return a(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[d(W,{className:`h-4 w-4 animate-spin`}),e(`detectionIntelligence.peopleList.loadingPeople`,`Loading people…`)]});let S=f.mode===`new`||f.mode===`edit`&&b!==null;return a(`div`,{className:`space-y-2`,children:[a(`div`,{className:`flex flex-wrap items-center gap-2`,children:[a(J,{variant:`primary`,size:`sm`,type:`button`,onClick:p,children:[d(V,{className:`h-3.5 w-3.5`}),e(`detectionIntelligence.peopleList.addPerson`,`Add person`)]}),a(J,{variant:`secondary`,size:`sm`,type:`button`,onClick:()=>_(!0),children:[d(de,{className:`h-3.5 w-3.5`}),e(`detectionIntelligence.peopleList.enrolFromAPhoto`,`Enrol from a photo`)]})]}),(v.length>0||y.active)&&d(Tt,{state:y.state,facets:y.facets,labels:{searchPlaceholder:`Search people…`,searchLabel:`Search people`,facetsLabel:`Filter`,clearLabel:`Clear`},onSearch:y.setSearch,onToggleFacet:y.toggleFacet,onClear:y.clear}),y.rows.length===0?d(Ke,{icon:_e,title:y.active?e(`detectionIntelligence.peopleList.nothingMatchesTheFilter`,`Nothing matches the filter`):e(`detectionIntelligence.peopleList.noPeopleEnrolledYet`,`No people enrolled yet`),description:y.active?e(`detectionIntelligence.peopleList.clearTheSearchOrTry`,`Clear the search or try another name.`):e(`detectionIntelligence.peopleList.addAPersonOrEnrol`,`Add a person, or enrol faces from a photo.`)}):d(it,{columns:x,rows:y.rows,rowKey:e=>e.id,maxBodyHeight:Ge,emptyMessage:e(`detectionIntelligence.peopleList.noPeopleEnrolledYet2`,`No people enrolled yet.`),onRowClick:e=>m(e.id)}),S&&d(In,{mode:f.mode===`new`?`new`:`edit`,identity:b,onClose:h}),d(Mn,{open:g,onOpenChange:_})]})}var Rn={fromMs:null,toMs:null},zn=36e5,Bn=24*zn;function Vn(e,t){switch(e){case`24h`:return{fromMs:t-Bn,toMs:null};case`7d`:return{fromMs:t-7*Bn,toMs:null};case`30d`:return{fromMs:t-30*Bn,toMs:null};case`all`:return Rn}}function Hn(e){return e.fromMs!==null||e.toMs!==null}function Un(e,t){return Hn(t)?e.filter(e=>!(t.fromMs!==null&&e.timestamp<t.fromMs||t.toMs!==null&&e.timestamp>t.toMs)):[...e]}function Wn(e,t){return t.size===0?[...e]:e.filter(e=>t.has(e.deviceId))}function Gn(e){let t=new Set,n=[];for(let r of e)t.has(r.deviceId)||(t.add(r.deviceId),n.push(r.deviceId));return n}function Kn(e){if(!e)return null;let t=Date.parse(`${e}T00:00:00`);return Number.isNaN(t)?null:t}function qn(e){if(!e)return null;let t=Date.parse(`${e}T23:59:59.999`);return Number.isNaN(t)?null:t}function Jn(e,t){if(!Number.isFinite(e)||e<=0)return`—`;let n=t-e;return n<6e4?Y.t(`helpers.relativeTime.justNow`):n<zn?Y.t(`helpers.relativeTime.minutesAgo`,{count:Math.floor(n/6e4)}):n<Bn?Y.t(`helpers.relativeTime.hoursAgo`,{count:Math.floor(n/zn)}):n<7*Bn?Y.t(`helpers.relativeTime.daysAgo`,{count:Math.floor(n/Bn)}):new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function Yn(e){return!Number.isFinite(e)||e<=0?`—`:new Date(e).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function Xn(e){return!Number.isFinite(e)||e<=0?`—`:new Date(e).toLocaleString(void 0,{year:`numeric`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function Zn(e){let t=e.cropUrl!==void 0&&e.cropUrl.length>0,n=e.base64!==void 0&&e.base64.length>0;return!t&&!n}function Qn(e){return e.filter(Zn).map(e=>e.faceId)}function $n(e){let t=0;for(let n of e)Zn(n)&&(t+=1);return t}function er(e){return e==null?null:e.cropUrl!==void 0&&e.cropUrl.length>0?e.cropUrl:e.base64!==void 0&&e.base64.length>0?`data:image/jpeg;base64,${e.base64}`:null}e();function tr(e,i,a){let[o,s]=r(1);t(()=>{s(1)},[a]);let c=e.length,l=Math.max(1,Math.ceil(c/i)),u=Math.min(o,l);return t(()=>{u!==o&&s(u)},[u,o]),{page:u,setPage:s,pageItems:n(()=>{let t=(u-1)*i;return e.slice(t,t+i)},[e,u,i]),totalPages:l,totalItems:c,pageSize:i}}var nr=2;function rr(e,t){if(t<=1)return[{kind:`page`,n:1}];if(t<=7){let e=[];for(let n=1;n<=t;n++)e.push({kind:`page`,n});return e}let n=[],r=Math.max(2,e-nr),i=Math.min(t-1,e+nr);n.push({kind:`page`,n:1}),r>2&&n.push({kind:`ellipsis`,side:`left`});for(let e=r;e<=i;e++)n.push({kind:`page`,n:e});return i<t-1&&n.push({kind:`ellipsis`,side:`right`}),n.push({kind:`page`,n:t}),n}function ir({currentPage:e,totalItems:t,pageSize:n,onPageChange:r,itemNoun:i=`items`}){let{t:o}=X();if(t<=n)return null;let s=Math.ceil(t/n),c=(e-1)*n+1,l=Math.min(e*n,t),u=rr(e,s),f=`inline-flex h-7 min-w-7 items-center justify-center rounded-md px-2 text-[11px] transition-colors disabled:opacity-40`;return a(`div`,{className:`flex items-center justify-between gap-4 flex-wrap pt-2 text-[11px] text-foreground-subtle`,children:[d(`span`,{children:o(`galleryPager.showing`,{from:c,to:l,total:t,noun:i})}),a(`div`,{className:`flex items-center gap-1`,children:[d(`button`,{type:`button`,className:`${f} hover:bg-surface-hover`,onClick:()=>r(e-1),disabled:e<=1,"aria-label":o(`galleryPager.previousPage`,`Previous page`),children:d(P,{className:`h-3.5 w-3.5`})}),u.map(t=>t.kind===`ellipsis`?d(`span`,{className:`px-1 opacity-60`,children:`…`},`ellipsis-${t.side}`):d(`button`,{type:`button`,className:`${f} ${t.n===e?`bg-primary/12 text-primary font-medium`:`hover:bg-surface-hover hover:text-foreground`}`,onClick:()=>r(t.n),"aria-current":t.n===e?`page`:void 0,children:t.n},t.n)),d(`button`,{type:`button`,className:`${f} hover:bg-surface-hover`,onClick:()=>r(e+1),disabled:e>=s,"aria-label":o(`galleryPager.nextPage`,`Next page`),children:d(re,{className:`h-3.5 w-3.5`})})]})]})}e();var ar=[[`faceGallery`]];function or({faceIds:e,identities:t,onDone:n}){let{t:i}=X(),o=l(),s=lt(),c=De(),[u,f]=r(``),[p,m]=r(!1),[h,g]=r(null),_=e!==null&&e.length>0,v=e?.length??0;function y(){m(!1),f(``),g(null)}function b(){y(),n()}function x(t){!e||e.length===0||s.mutate({faceIds:[...e],identityId:t},{onSettled:()=>{o.invalidateQueries({queryKey:ar}),b()}})}function S(){!e||!u.trim()||c.mutate({name:u.trim()},{onSuccess:e=>{e?.id&&x(e.id)},onError:()=>{o.invalidateQueries({queryKey:ar}),b()}})}let C=s.isPending||c.isPending;return d(vt,{open:_,onOpenChange:e=>!e&&b(),children:a(ct,{children:[a(Et,{children:[d(Ze,{children:v>1?i(`detectionIntelligence.assignDialog.assignFacesToPerson`,`Assign {{value1}} faces to person`,{value1:String(v)}):i(`detectionIntelligence.assignDialog.assignFaceToPerson`,`Assign face to person`)}),d(Ye,{children:i(`detectionIntelligence.assignDialog.selectAnExistingPersonOr`,`Select an existing person or create a new one.`)})]}),d(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:t.map(e=>a(`button`,{type:`button`,onClick:()=>g(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${h===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[d(`span`,{className:`font-medium`,children:e.name}),d(`span`,{className:`ml-2 text-foreground-subtle`,children:i(`detectionIntelligence.assignDialog.samples`,{count:e.sampleCount})})]},e.id))}),d(`div`,{className:`min-h-[2.75rem] border-t border-border pt-2`,children:p?d(`div`,{className:`flex items-center gap-2`,children:d(Ee,{placeholder:i(`detectionIntelligence.assignDialog.newPersonName`,`New person name…`),value:u,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&S()},autoFocus:!0,className:`flex-1`})}):d(`button`,{type:`button`,onClick:()=>{g(null),m(!0)},className:`w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle transition-colors hover:border-primary hover:text-primary`,children:i(`detectionIntelligence.assignDialog.newPerson`,`+ New person…`)})}),a(xt,{className:`min-h-[2.75rem]`,children:[d(J,{variant:`secondary`,onClick:b,disabled:C,children:i(`common.cancel`,`Cancel`)}),p?a(J,{variant:`primary`,onClick:S,disabled:C||!u.trim(),children:[C&&d(W,{className:`h-3.5 w-3.5 animate-spin`}),i(`detectionIntelligence.assignDialog.createAssign`,`Create & assign`)]}):a(J,{variant:`primary`,onClick:()=>h&&x(h),disabled:C||!h,children:[C&&d(W,{className:`h-3.5 w-3.5 animate-spin`}),v>1?i(`detectionIntelligence.assignCount`,{count:v}):i(`common.assign`)]})]})]})})}e();function sr({cameras:e,selected:n,onChange:i}){let{t:o}=X(),[s,c]=r(!1),l=u(null);t(()=>{if(!s)return;function e(e){l.current&&e.target instanceof Node&&!l.current.contains(e.target)&&c(!1)}function t(e){e.key===`Escape`&&c(!1)}return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[s]);function f(e){let t=new Set(n);t.has(e)?t.delete(e):t.add(e),i(t)}let p=n.size,m=p===0?`All cameras`:p===1?e.find(e=>n.has(e.id))?.name??`1 camera`:`${String(p)} cameras`;return a(`div`,{ref:l,className:`relative`,children:[a(`button`,{type:`button`,onClick:()=>c(e=>!e),disabled:e.length===0,className:`flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs transition-colors disabled:opacity-40 ${p>0?`border-primary/40 bg-primary/8 text-primary`:`border-border text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[d(h,{className:`h-3.5 w-3.5`}),d(`span`,{className:`max-w-[10rem] truncate`,children:m}),d(K,{className:`h-3 w-3 opacity-70`})]}),s&&a(`div`,{className:`absolute left-0 z-30 mt-1 max-h-64 w-[min(15rem,calc(100vw-1.5rem))] overflow-y-auto rounded-md border border-border bg-surface p-1 shadow-lg shadow-black/30`,children:[p>0&&d(`button`,{type:`button`,onClick:()=>i(new Set),className:`mb-1 w-full rounded px-2 py-1 text-left text-[11px] text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:o(`detectionIntelligence.cameraMultiSelect.clearSelection`,`Clear selection`)}),e.map(e=>{let t=n.has(e.id);return a(`button`,{type:`button`,onClick:()=>f(e.id),className:`flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-xs transition-colors ${t?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[d(`span`,{className:`flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded-sm border ${t?`border-primary bg-primary text-white`:`border-border`}`,children:t&&d(T,{className:`h-2.5 w-2.5`})}),d(`span`,{className:`truncate`,children:e.name})]},e.id)})]})]})}e();var cr=[{label:`24h`,value:`24h`},{label:`7d`,value:`7d`},{label:`30d`,value:`30d`},{labelKey:`common.all`,value:`all`}];function lr({onChange:e}){let{t}=X(),[n,i]=r(`all`),[o,s]=r(``),[c,l]=r(``);function u(t){i(t),s(``),l(``),e(Vn(t,Date.now()))}function f(t,n){i(`custom`),s(t),l(n),e({fromMs:Kn(t),toMs:qn(n)})}let p=`rounded-md border border-border bg-surface px-2 py-1.5 text-[11px] text-foreground outline-none focus:border-primary [color-scheme:light] dark:[color-scheme:dark]`;return a(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:cr.map(e=>d(`button`,{type:`button`,onClick:()=>u(e.value),className:`rounded px-2.5 py-1 text-[11px] transition-colors ${n===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.labelKey===void 0?e.label:t(e.labelKey)},e.value))}),a(`div`,{className:`flex items-center gap-1`,children:[d(`input`,{type:`date`,"aria-label":t(`detectionIntelligence.dateRangeFilter.fromDate`,`From date`),value:o,max:c||void 0,onChange:e=>f(e.target.value,c),className:`${p} ${n===`custom`&&o?`border-primary/50`:``}`}),d(`span`,{className:`text-[11px] text-foreground-subtle`,children:`→`}),d(`input`,{type:`date`,"aria-label":t(`detectionIntelligence.dateRangeFilter.toDate`,`To date`),value:c,min:o||void 0,onChange:e=>f(o,e.target.value),className:`${p} ${n===`custom`&&c?`border-primary/50`:``}`})]})]})}function ur(e){return e<0?0:e>1?1:e}function dr(e,t,n){if(!Number.isFinite(t)||!Number.isFinite(n)||t<=0||n<=0)return null;let r=ur(e.x/t),i=ur(e.y/n),a=ur((e.x+e.w)/t),o=ur((e.y+e.h)/n);return{x:r,y:i,width:Math.max(0,a-r),height:Math.max(0,o-i)}}e();var fr=2.6;function pr({src:e,alt:n,className:i,overlay:o,fit:s=`contain`}){let[c,l]=r(!1),[u,f]=r(`50% 50%`);t(()=>{l(!1),f(`50% 50%`)},[e]);function p(e){if(!c){let t=e.currentTarget.getBoundingClientRect(),n=(e.clientX-t.left)/t.width*100,r=(e.clientY-t.top)/t.height*100;f(`${String(n)}% ${String(r)}%`)}l(e=>!e)}let m=s===`natural`;return d(`div`,{className:`relative overflow-hidden bg-background ${i??``}`,onClick:p,children:a(`div`,{className:`relative select-none transition-transform duration-200 ease-out ${m?`w-full`:`h-full w-full`} ${c?`cursor-zoom-out`:`cursor-zoom-in`}`,style:{transformOrigin:u,transform:c?`scale(${String(fr)})`:`scale(1)`},children:[d(`img`,{src:e,alt:n,draggable:!1,className:m?`block h-auto w-full object-contain`:`h-full w-full object-contain`}),o]})})}e();function mr(e){let[n,i]=r(null),[a,o]=r(null),[s,c]=r(!1);return t(()=>{if(i(null),o(null),c(!1),e===void 0)return;let t=!1,n=null;return(async()=>{try{let r=await Ut(Wt(e));if(t)return;n=URL.createObjectURL(r),i(n)}catch{t||c(!0)}})(),()=>{t=!0,n&&URL.revokeObjectURL(n)}},[e]),t(()=>{if(!n)return;let e=new Image;return e.onload=()=>o({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>c(!0),e.src=n,()=>{e.onload=null,e.onerror=null}},[n]),{frameSrc:n,naturalWidth:a?.width??null,naturalHeight:a?.height??null,failed:s}}function hr(e){let t=e.filter(e=>e.url.length>0);return t.length===0?null:t.find(e=>/crop|face/i.test(e.kind))??t[0]}function gr({label:e,value:t}){return a(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[d(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),d(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground`,children:t})]})}function _r({box:e}){let{t}=X();return d(`div`,{className:`pointer-events-none absolute rounded-[3px] border-2 border-primary shadow-[0_0_0_9999px_rgba(0,0,0,0.28)]`,style:{left:`${String(e.x*100)}%`,top:`${String(e.y*100)}%`,width:`${String(e.width*100)}%`,height:`${String(e.height*100)}%`},children:d(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:t(`detectionIntelligence.faceDetailPanel.face`,`Face`)})})}function vr({face:e,cameraName:t,onClose:i,onAssign:o,onUnassign:s,onDelete:c,actionsPending:l}){let{t:u}=X(),{data:f,isFetching:p}=xe({faceId:e?.faceId??``},{enabled:e!==null}),[m,h]=r(`frame`),{frameSrc:g,naturalWidth:v,naturalHeight:y,failed:b}=mr(e?.keyFrameMediaId),S=n(()=>{let t=hr(f??[]);return t?t.url:er(e)},[f,e]),C=n(()=>!e?.faceBbox||v===null||y===null?null:dr(e.faceBbox,v,y),[e?.faceBbox,v,y]);if(e===null)return null;let w=e.keyFrameMediaId!==void 0&&!b,T=w&&m===`frame`,E=e.assigned?e.identityName??`Assigned`:e.recognizedIdentityId?`${e.identityName??`Recognized`} (suggested)`:`Unassigned`;return d(vt,{open:!0,onOpenChange:e=>!e&&i(),children:a(ct,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":u(`detectionIntelligence.faceDetailPanel.faceDetail`,`Face detail`),className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[d(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:a(`div`,{className:`min-w-0`,children:[d(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:u(`detectionIntelligence.faceDetailPanel.faceDetail`,`Face detail`)}),d(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]})}),a(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[w&&a(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[a(`button`,{type:`button`,onClick:()=>h(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${m===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[d(U,{className:`h-3.5 w-3.5`}),` `,u(`detectionIntelligence.detailPanel.fullFrame`)]}),a(`button`,{type:`button`,onClick:()=>h(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${m===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[d(ge,{className:`h-3.5 w-3.5`}),` `,u(`detectionIntelligence.detailPanel.crop`)]})]}),T&&g?d(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:d(pr,{src:g,alt:u(`detectionIntelligence.faceDetailPanel.fullFrameWithDetectedFace`,`Full frame with detected face`),fit:`natural`,className:`w-full`,overlay:C?d(_r,{box:C}):void 0})}):S?a(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[d(pr,{src:S,alt:u(`detectionIntelligence.faceDetailPanel.detectedFace`,`Detected face`),className:`h-full w-full`}),p&&d(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:d(W,{className:`h-3.5 w-3.5 animate-spin`})})]}):a(`div`,{className:`flex aspect-square w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[d(M,{className:`h-8 w-8 text-warning/70`}),d(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:u(`detectionIntelligence.faceDetailPanel.noImage`,`No image`)}),d(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:u(`detectionIntelligence.faceDetailPanel.theCropMediaForThis`,`The crop media for this face could not be resolved (a pre-fix orphan). Safe to delete.`)})]}),a(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[d(gr,{label:u(`detectionIntelligence.faceDetailPanel.camera`,`Camera`),value:t}),d(gr,{label:u(`detectionIntelligence.faceDetailPanel.captured`,`Captured`),value:Xn(e.timestamp)}),d(gr,{label:u(`detectionIntelligence.faceDetailPanel.track`,`Track`),value:e.trackId}),d(gr,{label:u(`detectionIntelligence.faceDetailPanel.identity`,`Identity`),value:E})]})]}),a(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[e.assigned?a(J,{variant:`secondary`,onClick:()=>s(e.faceId),disabled:l,children:[d(me,{className:`h-3.5 w-3.5`}),` `,u(`detectionIntelligence.detailPanel.detach`)]}):a(J,{variant:`primary`,onClick:()=>o(e.faceId),disabled:l,children:[d(_,{className:`h-3.5 w-3.5`}),` `,u(`common.assign`)]}),a(J,{variant:`secondary`,onClick:()=>c(e.faceId),disabled:l,children:[d(x,{className:`h-3.5 w-3.5`}),` `,u(`common.delete`)]})]})]})})}function yr(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function br(e,t){return e.faceIds.filter(e=>!t.has(e))}function xr(e,t){return e.faceIds.filter(e=>t(e))}e();var Sr=[[`faceGallery`]],Cr=20,wr=.3,Tr=.9,Er=.05,Dr=.5,Or=2,kr=10,Ar=2;function jr({cluster:e,face:t,active:n,onSelect:r}){let{t:i}=X(),o=er(t);return a(`button`,{type:`button`,onClick:r,className:`flex shrink-0 flex-col items-center gap-1.5 rounded-md border p-2 text-center transition-colors md:w-full md:flex-row md:gap-2.5 md:text-left ${n?`border-primary bg-primary/8`:`border-border bg-surface hover:bg-surface-hover`}`,children:[d(`div`,{className:`h-24 w-24 shrink-0 overflow-hidden rounded bg-surface-hover`,children:o===null?d(M,{className:`h-24 w-24 p-6 text-foreground-subtle`}):d(`img`,{src:o,alt:``,loading:`lazy`,decoding:`async`,className:`h-24 w-24 object-cover`})}),d(`span`,{className:`w-24 text-[11px] leading-tight text-foreground-subtle md:w-auto`,children:i(`detectionIntelligence.similarGroupsModal.clusterMeta`,{count:e.size,percent:Math.round(e.cohesion*100)})})]})}function Mr({face:e,cameraName:t,nowMs:n,excluded:r,onToggleExclude:i,onDelete:o,deletePending:s}){let{t:c}=X(),l=er(e);return a(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden transition-opacity ${r?`border-border opacity-40 grayscale`:`border-border`}`,children:[a(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[l===null?a(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,children:[d(M,{className:`h-7 w-7 text-warning/70`}),d(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:c(`detectionIntelligence.similarGroupsModal.noCrop`,`No crop`)})]}):d(pr,{src:l,alt:c(`detectionIntelligence.similarGroupsModal.faceFrom`,`Face from {{cameraName}}`,{cameraName:t}),className:`h-full w-full`}),d(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i()},className:`absolute right-1 top-1 z-10 rounded-full bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":r?c(`detectionIntelligence.similarGroupsModal.includeFace`,`Include face`):c(`detectionIntelligence.similarGroupsModal.excludeFace`,`Exclude face`),title:r?c(`detectionIntelligence.similarGroupsModal.include`,`Include`):c(`detectionIntelligence.similarGroupsModal.exclude`,`Exclude`),children:d(r?p:L,{className:`h-3.5 w-3.5`})})]}),a(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[d(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),d(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:Jn(e.timestamp,n)})]}),d(`div`,{className:`mt-1 flex min-h-[2rem] items-center justify-end border-t border-border/60 px-1 py-0.5`,children:d(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o()},disabled:s,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":c(`detectionIntelligence.similarGroupsModal.deleteFace`,`Delete face`),title:c(`detectionIntelligence.similarGroupsModal.deleteFace`,`Delete face`),children:s?d(W,{className:`h-4 w-4 animate-spin`}):d(x,{className:`h-4 w-4`})})})]})}function Nr({open:e,onClose:i,byId:o,cameraName:s,nowMs:u,identities:f,selectMany:p}){let{t:m}=X(),h=l(),g=je(),v=Ae(),[y,b]=r(Dr),[x,S]=r(Ar),[C,w]=r(null),[T,E]=r({}),[D,O]=r(null),{data:k,isFetching:A,refetch:M}=He({threshold:y,minClusterSize:x,limit:Cr},{enabled:e}),N=k??[];t(()=>{E({})},[y,x]),t(()=>{if(N.length===0){w(null);return}N.some(e=>e.representativeFaceId===C)||w(N[0]?.representativeFaceId??null)},[N]);let P=n(()=>N.find(e=>e.representativeFaceId===C)??null,[N,C]),I=P?T[P.representativeFaceId]??new Set:new Set,L=n(()=>P?xr(P,e=>o.has(e)):[],[P,o]),R=P?P.faceIds.length-L.length:0,z=P?br({...P,faceIds:L},I):[];function B(e){if(!P)return;let t=P.representativeFaceId;E(n=>({...n,[t]:yr(n[t]??new Set,e)}))}function V(){h.invalidateQueries({queryKey:Sr})}async function H(e){await g({title:m(`detectionIntelligence.similarGroupsModal.deleteFace`,`Delete face`),message:m(`detectionIntelligence.similarGroupsModal.permanentlyDeletesThisFaceCrop`,`Permanently deletes this face crop. This cannot be undone.`),confirmLabel:m(`common.delete`,`Delete`),variant:`danger`})&&v.mutate({faceId:e},{onSettled:V})}function U(){O(null),i()}function G(){z.length!==0&&(p(z),U())}return a(vt,{open:e,onOpenChange:e=>!e&&U(),children:[a(ct,{placement:`sheet-on-mobile`,width:`lg`,"aria-label":m(`detectionIntelligence.similarGroupsModal.lookAlikeGroups`,`Look-alike groups`),className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 md:max-w-4xl`,children:[a(`header`,{className:`flex shrink-0 flex-col gap-2 border-b border-border py-3 pl-4 pr-10`,children:[a(`div`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[d(j,{className:`h-4 w-4 text-primary`}),` `,m(`detectionIntelligence.similarGroupsModal.title`)]}),a(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[a(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[m(`detectionIntelligence.similarGroupsModal.threshold`,`Threshold`),d(`input`,{type:`range`,min:wr,max:Tr,step:Er,value:y,onChange:e=>b(Number(e.target.value)),className:`h-1.5 w-28 cursor-pointer accent-primary`}),d(`span`,{className:`w-8 shrink-0 text-right font-mono text-[11px] tabular-nums text-foreground`,children:y.toFixed(2)})]}),a(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[m(`detectionIntelligence.similarGroupsModal.minSize`,`Min size`),d(`input`,{type:`number`,min:Or,max:kr,step:1,value:x,onChange:e=>S(Math.min(kr,Math.max(Or,Number(e.target.value)||Or))),className:`w-12 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`})]}),a(J,{variant:`secondary`,onClick:()=>{E({}),M()},disabled:A,children:[A?d(W,{className:`h-3.5 w-3.5 animate-spin`}):d(F,{className:`h-3.5 w-3.5`}),m(`detectionIntelligence.similarGroupsModal.reAnalyze`,`Re-analyze`)]})]})]}),d(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-hidden px-4 py-3 md:flex-row`,children:A&&N.length===0?a(`div`,{className:`flex flex-1 items-center justify-center gap-2 py-8 text-xs text-foreground-subtle`,children:[d(W,{className:`h-4 w-4 animate-spin`}),` `,m(`detectionIntelligence.similarGroupsModal.finding`)]}):N.length===0?d(`div`,{className:`flex flex-1 items-center justify-center py-8 text-xs text-foreground-subtle`,children:m(`detectionIntelligence.similarGroupsModal.noLookAlikeGroupsAt`,`No look-alike groups at this threshold.`)}):a(c,{children:[d(`div`,{className:`flex gap-2 overflow-x-auto pb-1 md:hidden`,children:N.map(e=>d(jr,{cluster:e,face:o.get(e.representativeFaceId),active:e.representativeFaceId===C,onSelect:()=>w(e.representativeFaceId)},e.representativeFaceId))}),d(`div`,{className:`hidden shrink-0 flex-col gap-2 overflow-y-auto md:flex md:w-56`,children:N.map(e=>d(jr,{cluster:e,face:o.get(e.representativeFaceId),active:e.representativeFaceId===C,onSelect:()=>w(e.representativeFaceId)},e.representativeFaceId))}),d(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:P&&a(c,{children:[R>0&&d(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:m(`detectionIntelligence.similarGroupsModal.hiddenCount`,{count:R})}),d(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(13rem,13rem))] justify-start gap-2`,children:L.map(e=>{let t=o.get(e);return t?d(Mr,{face:t,cameraName:s(t.deviceId),nowMs:u,excluded:I.has(e),onToggleExclude:()=>B(e),onDelete:()=>void H(e),deletePending:v.isPending&&v.variables?.faceId===e},e):null})})]})})]})}),a(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[d(J,{variant:`secondary`,onClick:G,disabled:z.length===0,children:m(`detectionIntelligence.similarGroupsModal.selectInGallery`,`Select in gallery`)}),a(J,{variant:`primary`,onClick:()=>O(z),disabled:z.length===0,children:[d(_,{className:`h-3.5 w-3.5`}),` `,m(`detectionIntelligence.similarGroupsModal.adopt`,{count:z.length})]})]})]}),d(or,{faceIds:D,identities:f,onDone:()=>O(null)})]})}e();var Pr=[[`faceGallery`]],Fr=500,Ir=120;function Lr({face:e,cameraName:t,nowMs:n,selected:r,onToggleSelect:i,onAssign:o,onOpenDetail:s}){let{t:c}=X(),u=l(),f=Se(),p=Ae(),m=()=>{u.invalidateQueries({queryKey:Pr})},h=()=>s(e.faceId),g=er(e);return a(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${r?`border-primary ring-1 ring-primary`:`border-border`}`,children:[a(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[g===null?a(`button`,{type:`button`,onClick:h,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:c(`detectionIntelligence.unassignedFaces.noCropImageTheFace`,`No crop image — the face's crop media is missing (a pre-fix orphan). Safe to delete.`),children:[d(M,{className:`h-7 w-7 text-warning/70`}),d(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:c(`detectionIntelligence.unassignedFaces.noCrop`,`No crop`)})]}):d(`img`,{src:g,alt:c(`detectionIntelligence.unassignedFaces.faceFrom`,`Face from {{cameraName}}`,{cameraName:t}),onClick:h,loading:`lazy`,decoding:`async`,className:`h-full w-full cursor-zoom-in object-cover`}),d(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),i(e.faceId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":r?c(`detectionIntelligence.unassignedFaces.deselect`,`Deselect`):c(`detectionIntelligence.unassignedFaces.select`,`Select`),children:r?d(fe,{className:`h-4 w-4 text-primary`}):d(O,{className:`h-4 w-4`})})]}),a(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[d(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),d(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:Jn(e.timestamp,n)}),d(`p`,{className:`min-h-[0.875rem] truncate text-[10px] font-medium leading-tight ${e.identityName?`text-primary`:`invisible`}`,title:e.identityName,children:e.identityName??`\xA0`})]}),a(`div`,{className:`mt-1 flex min-h-[2rem] items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[e.assigned?d(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),f.mutate({faceId:e.faceId},{onSettled:m})},disabled:f.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":c(`detectionIntelligence.unassignedFaces.detachFace`,`Detach face`),title:c(`detectionIntelligence.unassignedFaces.detach`,`Detach`),children:f.isPending?d(W,{className:`h-4 w-4 animate-spin`}):d(me,{className:`h-4 w-4`})}):d(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(e.faceId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":c(`detectionIntelligence.unassignedFaces.assignFaceToPerson`,`Assign face to person`),title:c(`detectionIntelligence.unassignedFaces.assignToPerson`,`Assign to person`),children:d(_,{className:`h-4 w-4`})}),d(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),p.mutate({faceId:e.faceId},{onSettled:m})},disabled:p.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":c(`detectionIntelligence.unassignedFaces.deleteFace`,`Delete face`),title:c(`detectionIntelligence.unassignedFaces.deleteFace`,`Delete face`),children:p.isPending?d(W,{className:`h-4 w-4 animate-spin`}):d(x,{className:`h-4 w-4`})})]})]})}var Rr=[{labelKey:`common.all`,value:`all`},{labelKey:`detectionIntelligence.unassignedFaces.filterUnassigned`,value:`unassigned`},{labelKey:`detectionIntelligence.unassignedFaces.filterRecognized`,value:`recognized`}];function zr(){let{t:e}=X(),t=l(),[i,o]=r(`all`),[s,u]=r(Rn),[f,p]=r(new Set),[m,h]=r(new Set),[g,v]=r(null),[y,b]=r(!1),[S,C]=r(null),{data:w,isLoading:T}=Re({limit:Fr,filter:i,includeCrops:!1},{refetchInterval:3e4}),{data:E=[]}=we(),{data:D}=kt({isCamera:!0,projection:`slim`}),O=lt(),k=Se(),A=Ve(),N=Ae(),P=Date.now(),F=w??[],I=n(()=>{let e=new Map;for(let t of D??[])e.set(t.id,t.name);return e},[D]),R=t=>I.get(t)??e(`detectionIntelligence.cameraFallback`,{id:String(t)}),z=n(()=>Gn(F).map(e=>({id:e,name:R(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[F,I]),B=n(()=>Wn(Un(F,s),f),[F,s,f]),V=tr(B,Ir,n(()=>JSON.stringify([i,s.fromMs,s.toMs,[...f].sort((e,t)=>e-t)]),[i,s.fromMs,s.toMs,f])),H=n(()=>new Map(F.map(e=>[e.faceId,e])),[F]),U=n(()=>$n(B),[B]),G=S===null?null:H.get(S)??null,ee=()=>{t.invalidateQueries({queryKey:Pr})},te=()=>h(new Set);function ne(e){h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function K(e){h(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function re(){K(Qn(B))}let ie=[...m],q=O.isPending||A.isPending||N.isPending,ae=k.isPending||N.isPending;function oe(){ie.length!==0&&A.mutate({faceIds:ie},{onSettled:()=>{ee(),te()}})}function se(){ie.length!==0&&Promise.allSettled(ie.map(e=>N.mutateAsync({faceId:e}))).then(()=>{ee(),te()})}function ce(e){C(null),v([e])}function le(e){k.mutate({faceId:e},{onSettled:ee}),C(null)}function ue(e){N.mutate({faceId:e},{onSettled:ee}),C(null)}let de=B.length!==F.length;return a(`div`,{className:`relative space-y-3`,children:[a(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d(`div`,{className:`flex items-center gap-1`,children:Rr.map(t=>d(`button`,{type:`button`,onClick:()=>o(t.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${i===t.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e(t.labelKey)},t.value))}),d(lr,{onChange:u}),d(sr,{cameras:z,selected:f,onChange:p}),a(`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:[d(j,{className:`h-3.5 w-3.5`}),` `,e(`detectionIntelligence.unassignedFaces.similarGroups`)]}),!T&&U>0&&a(`button`,{type:`button`,onClick:re,className:`ml-auto flex items-center gap-1 rounded-md px-2.5 py-1 text-xs text-warning/90 transition-colors hover:bg-warning/10`,title:e(`detectionIntelligence.unassignedFaces.selectEveryVisibleFaceWhose`,`Select every visible face whose crop image is missing so you can delete the orphans in one pass`),children:[d(M,{className:`h-3.5 w-3.5`}),` `,e(`detectionIntelligence.unassignedFaces.selectCropless`,{count:U})]}),!T&&d(`span`,{className:`text-[10px] text-foreground-subtle ${U>0?`ml-2`:`ml-auto`}`,children:de?e(`detectionIntelligence.unassignedFaces.ofFaces`,`{{value1}} of {{value2}} faces`,{value1:String(B.length),value2:String(F.length)}):e(`detectionIntelligence.unassignedFaces.faceCount`,{count:B.length})})]}),m.size>0&&a(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[d(`span`,{className:`text-xs font-medium text-foreground`,children:e(`common.selectedCount`,{count:m.size})}),a(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[a(J,{variant:`primary`,onClick:()=>v(ie),disabled:q,children:[d(_,{className:`h-3.5 w-3.5`}),` `,e(`common.assign`)]}),a(J,{variant:`secondary`,onClick:oe,disabled:q,children:[A.isPending?d(W,{className:`h-3.5 w-3.5 animate-spin`}):d(me,{className:`h-3.5 w-3.5`}),` `,e(`detectionIntelligence.unassignedFaces.detach`,`Detach`)]}),a(J,{variant:`secondary`,onClick:se,disabled:q,children:[d(x,{className:`h-3.5 w-3.5`}),` `,e(`common.delete`)]}),d(J,{variant:`ghost`,onClick:te,disabled:q,children:d(L,{className:`h-3.5 w-3.5`})})]})]}),T?d(pt,{status:`pending`,pendingMessage:`Loading faces…`,testId:`faces-grid`}):B.length===0?d(Ke,{icon:M,title:F.length>0?e(`detectionIntelligence.unassignedFaces.nothingMatchesTheFilter`,`Nothing matches the filter`):e(`detectionIntelligence.unassignedFaces.noFacesFoundForThis`,`No faces found for this filter`),description:F.length>0?e(`detectionIntelligence.unassignedFaces.widenTheDateRangeOr`,`Widen the date range or clear the camera filter.`):e(`detectionIntelligence.unassignedFaces.faceCropsAppearHereWhen`,`Face crops appear here when the detection pipeline captures them.`)}):a(c,{children:[d(pt,{status:`ready`,testId:`faces-grid`,className:`grid-cols-[repeat(auto-fill,minmax(6.5rem,6.5rem))] justify-start`,children:V.pageItems.map(e=>d(Lr,{face:e,cameraName:R(e.deviceId),nowMs:P,selected:m.has(e.faceId),onToggleSelect:ne,onAssign:e=>v([e]),onOpenDetail:C},e.faceId))}),d(ir,{currentPage:V.page,totalItems:V.totalItems,pageSize:V.pageSize,onPageChange:V.setPage,itemNoun:`faces`})]}),d(vr,{face:G,cameraName:G?R(G.deviceId):``,onClose:()=>C(null),onAssign:ce,onUnassign:le,onDelete:ue,actionsPending:ae}),d(or,{faceIds:g,identities:E,onDone:()=>{v(null),te()}}),d(Nr,{open:y,onClose:()=>b(!1),byId:H,cameraName:R,nowMs:P,identities:E,selectMany:K})]})}function Br(e){let{delayMs:t,invalidate:n,setTimeoutFn:r=setTimeout,clearTimeoutFn:i=clearTimeout}=e,a;function o(){a===void 0&&(a=r(()=>{a=void 0,n()},t))}function s(){a!==void 0&&(i(a),a=void 0)}return{trigger:o,cancel:s}}e();var Vr=[[`faceGallery`]],Hr=2e3;function Ur(){let e=l(),n=u(e);n.current=e;let r=u(void 0);r.current||=Br({delayMs:Hr,invalidate:()=>{n.current.invalidateQueries({queryKey:Vr})}}),t(()=>()=>r.current?.cancel(),[]),gt(ae.PipelineAnalyticsFaceGalleryChanged,()=>{r.current?.trigger()})}function Wr(){let{t:e}=X();return Ur(),a(`div`,{className:`space-y-3`,children:[d(mt,{headingId:`library-people`,title:e(`detectionIntelligence.people`,`People`),icon:_e,testId:`library-section-people`,children:a(`div`,{className:`${m} space-y-3`,children:[d(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:e(`detectionIntelligence.enrolledIdentitiesUsedForFace`,`Enrolled identities used for face recognition. Open a person to rename them or remove training samples.`)}),d(Ln,{})]})}),d(mt,{headingId:`library-recent-faces`,title:e(`detectionIntelligence.recentDetectedFaces`,`Recent detected faces`),icon:se,testId:`library-section-recent-faces`,children:a(`div`,{className:`${m} space-y-3`,children:[d(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:e(`detectionIntelligence.faceCropsCapturedByThe`,`Face crops captured by the detection pipeline. Assign them to a person to build recognition training data.`)}),d(zr,{})]})})]})}function Gr(e){let t=e.subLabel??e.label;if(t!==void 0)return t;let n=e.audioLabels?.[0]?.label;return n!==void 0&&n.length>0?n:void 0}var Kr=720*60*60*1e3;function qr(e){let t=[];for(let n of e)t.push(...n);return t}function Jr(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function Yr(e,t){return e.filter(e=>!(e.importance<t.minImportance||t.cameras.size>0&&!t.cameras.has(e.deviceId)||t.classes.size>0&&!t.classes.has(e.className)))}function Xr(e,t){return`${String(e)}:${t}`}function Zr(e,t){let n=new Map,r=new Set;for(let i of e){let e=Xr(i.deviceId,i.trackId);if(!t.has(e)||r.has(e))continue;r.add(e);let a=n.get(i.deviceId);a?a.push(i.trackId):n.set(i.deviceId,[i.trackId])}return n}function Qr(e,t){return{since:e.fromMs??t-Kr,until:e.toMs??t}}var $r=[`native`,`raster`,`standin`];function ei(e){return $r.some(t=>t===e)}function ti(e){return e===`standin`?{label:Y.t(`helpers.mediaProvenance.standin.label`),title:Y.t(`helpers.mediaProvenance.standin.title`),tone:`warning`}:{label:Y.t(`helpers.mediaProvenance.raster.label`),title:Y.t(`helpers.mediaProvenance.raster.title`),tone:`info`}}function ni(e){return e===`standin`?ti(`standin`):e===`raster`?ti(`raster`):null}var ri={"no-key-frame":`helpers.mediaProvenance.miss.noKeyFrame`,"no-best-seen-bbox":`helpers.mediaProvenance.miss.noBestSeenBbox`,"derive-returned-null":`helpers.mediaProvenance.miss.deriveReturnedNull`,"derive-threw":`helpers.mediaProvenance.miss.deriveThrew`,"derive-not-wired":`helpers.mediaProvenance.miss.deriveNotWired`,"no-media-store":`helpers.mediaProvenance.miss.noMediaStore`,"no-thumbnail":`helpers.mediaProvenance.miss.noThumbnail`,"standin-tile":`helpers.mediaProvenance.miss.standinTile`,"raster-tile":`helpers.mediaProvenance.miss.rasterTile`,"native-tile":`helpers.mediaProvenance.miss.nativeTile`};function ii(e){if(e===void 0)return null;let t=e.trim();if(t.length===0)return null;let n=t.split(/\s+/),r=n[0]??t,i=[];for(let e of n.slice(1)){let t=e.indexOf(`=`);t===-1?i.push({key:e,value:null}):i.push({key:e.slice(0,t),value:e.slice(t+1)})}let a=ri[r];return{sentence:a===void 0?r:Y.t(a),detail:i,raw:t}}function ai(e){if(e===void 0||!Number.isFinite(e)||e<=0)return``;let t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return`${String(n)}m ${String(r).padStart(2,`0`)}s`}function oi({row:e,cameraName:t,nowMs:n,onOpenDetail:r,selected:i=!1,onToggleSelect:o,score:s,provenance:c,footer:l}){let{t:u}=X(),p=Vt(e.mediaId===void 0?Ht(`track`,e.trackId):Wt(e.mediaId)),m=Math.round(e.importance*100),h=s===void 0?void 0:Math.round(s*100),_=ai(e.windowMs),v=()=>r(e),y=ni(c);return a(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[a(`div`,{className:`aspect-video relative overflow-hidden bg-surface-hover`,children:[p.src?d(`img`,{src:p.src,alt:u(`detectionIntelligence.eventCard.eventFrom`,`Event from {{cameraName}}`,{cameraName:t}),onClick:v,className:`h-full w-full cursor-zoom-in object-cover`}):d(`button`,{type:`button`,onClick:v,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-surface-hover text-foreground-subtle`,title:p.failed?u(`detectionIntelligence.eventCard.keyEventMediaUnavailable`,`Key-event media unavailable`):u(`detectionIntelligence.eventCard.noKeyEventMedia`,`No key-event media`),children:d(M,{className:`h-6 w-6 opacity-60`})}),o&&d(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(Xr(e.deviceId,e.trackId))},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?u(`detectionIntelligence.eventCard.deselect`,`Deselect`):u(`detectionIntelligence.eventCard.select`,`Select`),children:i?d(fe,{className:`h-4 w-4 text-primary`}):d(O,{className:`h-4 w-4`})}),h!==void 0&&a(`span`,{className:`absolute left-1 top-1 z-10 rounded bg-primary/85 px-1.5 py-0.5 text-[10px] font-semibold text-white tabular-nums`,title:u(`detectionIntelligence.eventCard.clipSemanticMatchScore`,`CLIP semantic-match score`),children:[String(h),`%`]}),m>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(m)}),y!==null&&d(`span`,{className:`absolute bottom-1 right-1 z-10 rounded px-1.5 py-0.5 text-[10px] font-semibold text-white ${y.tone===`warning`?`bg-warning/90`:`bg-black/70`}`,title:y.title,children:y.label}),(e.markForTrain===!0||e.retrainStatus===`trained`||e.debug===!0||e.favourited===!0)&&a(`span`,{className:`absolute bottom-1 left-1 z-10 flex gap-1`,children:[e.markForTrain===!0&&d(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:u(`detectionIntelligence.eventCard.markedForTraining`,`Marked for training`),"aria-label":u(`detectionIntelligence.eventCard.markedForTraining`,`Marked for training`),children:d(g,{className:`h-3 w-3`})}),e.retrainStatus===`trained`&&e.markForTrain!==!0&&d(`span`,{className:`rounded bg-success/85 p-0.5 text-white`,title:u(`detectionIntelligence.eventCard.trainingComplete`,`Training complete`),"aria-label":u(`detectionIntelligence.eventCard.trainingComplete`,`Training complete`),"data-testid":`retrain-status-trained`,children:d(T,{className:`h-3 w-3`})}),e.debug===!0&&d(`span`,{className:`rounded bg-black/70 p-0.5 text-white`,title:u(`detectionIntelligence.eventCard.flaggedForDebug`,`Flagged for debug`),"aria-label":u(`detectionIntelligence.eventCard.flaggedForDebug`,`Flagged for debug`),children:d(f,{className:`h-3 w-3`})}),e.favourited===!0&&d(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:u(`detectionIntelligence.eventCard.favourited`,`Favourited`),"aria-label":u(`detectionIntelligence.eventCard.favourited`,`Favourited`),children:d(S,{className:`h-3 w-3`})})]})]}),a(`button`,{type:`button`,onClick:v,className:`min-w-0 px-2 py-1.5 text-left space-y-0.5`,children:[a(`p`,{className:`text-[11px] font-medium text-foreground truncate`,title:e.className,children:[e.className,Gr(e)?a(`span`,{className:`text-foreground-subtle`,children:[` · `,Gr(e)]}):null]}),d(`p`,{className:`text-[10px] text-foreground-subtle truncate`,title:t,children:t}),a(`div`,{className:`flex items-center justify-between gap-2`,children:[d(`span`,{className:`text-[10px] text-foreground-subtle truncate`,children:Jn(e.timestamp,n)}),_&&d(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:_})]})]}),l!==void 0&&d(`div`,{className:`px-2 pb-1.5`,children:l})]})}e();var si=1400,ci=`Admin-gated URL — opens only inside an authenticated session`;function li({label:e,value:n,title:o}){let{t:s}=X(),[c,l]=r(!1),u=Pe();return t(()=>{if(!c)return;let e=setTimeout(()=>l(!1),si);return()=>clearTimeout(e)},[c]),a(`button`,{type:`button`,onClick:i(()=>{(async()=>{try{await navigator.clipboard.writeText(n),l(!0)}catch{await u({title:s(`detectionIntelligence.copyUrlChips.copyTheMediaUrl`,`Copy the media URL`),message:s(`detectionIntelligence.copyUrlChips.clipboardAccessWasRefusedSelect`,`Clipboard access was refused. Select the URL below and copy it manually.`),label:s(`detectionIntelligence.copyUrlChips.url`,`{{label}} URL`,{label:e}),defaultValue:n,readOnly:!0,cancelLabel:s(`common.close`,`Close`)})}})()},[n,e,u,s]),title:o,"aria-label":s(`detectionIntelligence.copyUrlChips.copyUrl`,`Copy {{label}} URL`,{label:e}),className:`flex min-w-0 items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${c?`border-success/40 bg-success/10 text-success`:`border-border text-foreground-subtle hover:border-primary hover:text-foreground`}`,children:[d(c?T:A,{className:`h-2.5 w-2.5 shrink-0`}),d(`span`,{className:`truncate`,children:c?s(`detectionIntelligence.copyUrlChips.copied`,`Copied`):e})]})}function ui({localUrl:e,publicUrl:t}){let{t:n}=X();return a(`div`,{className:`flex flex-wrap gap-1`,children:[d(li,{label:n(`detectionIntelligence.copyUrlChips.local`,`Local`),value:e,title:n(`detectionIntelligence.copyUrlChips.copyLanUrl`,`Copy LAN URL — {{AUTH_HINT}}`,{AUTH_HINT:ci})}),t&&d(li,{label:n(`detectionIntelligence.copyUrlChips.public`,`Public`),value:t,title:n(`detectionIntelligence.copyUrlChips.copyPublicUrl`,`Copy public URL — {{AUTH_HINT}}`,{AUTH_HINT:ci})})]})}var di={firstFrame:`First frame (track start)`,lastFrame:`Last frame (track end)`,thumbnail:`Best detection`,thumbnailSmall:`Best detection (480)`,snapshot:`Snapshot`,keyFrame:`Key frame (native-res)`,keyFrameSmall:`Key frame (960)`,crop:`Object crop`,fullFrame:`Full frame`,fullFrameBoxed:`Full frame (boxed)`,faceCrop:`Face crop`,plateCrop:`Plate crop`,confirmationCrop:`Confirmation crop (what the gate saw)`,debugCrop:`Debug crop (why this decision)`,sceneFrame:`Scene frame (clean)`,lastSceneFrame:`Last frame (clean)`};function fi(e){return e in di}function pi(e){return fi(e)?di[e]:e}function mi(e,t){return`${e}${t}`}e();var hi=3e4;function gi(e){let[n,a]=r(null),o=i(e=>{a(t=>t??e)},[]);return t(()=>{e||a(null)},[e]),{publicOrigin:n,probes:e?d(_i,{onOrigin:o}):null}}function _i({onOrigin:e}){let{data:t}=Qe({capName:`network-access`});return d(c,{children:(t??[]).map(t=>d(vi,{addonId:t.addonId,onOrigin:e},t.addonId))})}function vi({addonId:e,onOrigin:n}){let{data:r}=Fe({addonId:e},{refetchInterval:hi,retry:!1});return t(()=>{let e=r?q.safeParse(r):null,t=e?.success?e.data.endpoint?.url:void 0;if(t)try{n(new URL(t).origin)}catch{}},[r,n]),null}var yi=typeof qe==`function`,bi=`Track flags arrive with the next server update`;function xi(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var Si=yi?qe:xi;function Ci(e){if(typeof e!=`object`||!e||!(`trackId`in e)||!(`markForTrain`in e)||!(`debug`in e)||!(`favourited`in e))return null;let{trackId:t,markForTrain:n,debug:r,favourited:i}=e;return typeof t!=`string`||typeof n!=`boolean`||typeof r!=`boolean`||typeof i!=`boolean`?null:{trackId:t,markForTrain:n,debug:r,favourited:i}}e();function wi({label:e,hint:t,checked:n,disabled:r,title:i,icon:o,onToggle:s}){return a(`button`,{type:`button`,role:`switch`,"aria-checked":n,"aria-label":e,disabled:r,title:i,onClick:s,className:`flex w-full items-center gap-2 rounded-md border px-2 py-1.5 text-left transition-colors disabled:opacity-50 ${n?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[d(`span`,{className:n?`text-primary`:`text-foreground-subtle`,children:o}),a(`span`,{className:`min-w-0 flex-1`,children:[d(`span`,{className:`block text-[11px] font-medium text-foreground`,children:e}),d(`span`,{className:`block text-[10px] text-foreground-subtle`,children:t})]}),d(`span`,{"aria-hidden":`true`,className:`h-4 w-7 shrink-0 rounded-full p-0.5 transition-colors ${n?`bg-primary`:`bg-border`}`,children:d(`span`,{className:`block h-3 w-3 rounded-full bg-white transition-transform ${n?`translate-x-3`:``}`})})]})}function Ti({deviceId:e,trackId:t,markForTrain:n,debug:i,favourited:o,onChange:s}){let{t:c}=X(),l=Si(),u=Oe(),[p,m]=r(null),h=p?.markForTrain??n===!0,_=p?.debug??i===!0,v=p?.favourited??o===!0,y=!yi||l.isPending,b=yi?void 0:bi,x=n=>{y||(async()=>{try{let r=Ci(await l.mutateAsync({deviceId:e,trackId:t,flags:n}));if(!r)return;m(r),s?.(r)}catch(e){let t=e instanceof Error?e.message:``;await u({title:c(`detectionIntelligence.trackFlagToggles.couldNotUpdateThisTrack`,`Could not update this track`),message:t===``?c(`detectionIntelligence.trackFlagToggles.couldNotUpdateThisTrack2`,`Could not update this track. Check the server logs.`):t,variant:`danger`})}})()};return a(`div`,{className:`grid gap-1.5 sm:grid-cols-2`,children:[d(wi,{label:c(`detectionIntelligence.trackFlagToggles.markForTraining`,`Mark for training`),hint:c(`detectionIntelligence.trackFlagToggles.keepsThisTrackAndIts`,`Keeps this track and its media past retention`),checked:h,disabled:y,...b===void 0?{}:{title:b},icon:d(g,{className:`h-4 w-4`}),onToggle:()=>x({markForTrain:!h})}),d(wi,{label:c(`detectionIntelligence.trackFlagToggles.debug`,`Debug`),hint:c(`detectionIntelligence.trackFlagToggles.flagThisTrackForDiagnostic`,`Flag this track for diagnostic attention`),checked:_,disabled:y,...b===void 0?{}:{title:b},icon:d(f,{className:`h-4 w-4`}),onToggle:()=>x({debug:!_})}),d(wi,{label:c(`detectionIntelligence.trackFlagToggles.favourited`,`Favourited`),hint:c(`detectionIntelligence.trackFlagToggles.keepsThisTrackAndIts`,`Keeps this track and its media past retention`),checked:v,disabled:y,...b===void 0?{}:{title:b},icon:d(S,{className:`h-4 w-4`}),onToggle:()=>x({favourited:!v})})]})}function Ei(e){let t=e.deviceKey===void 0?e.nodeId:`${e.nodeId} · ${e.deviceKey}`;return e.modelId===void 0?t:`${t} (${e.modelId})`}function Di(e){let t=e?.openedPlacement,n=e?.closedPlacement;if(t!==void 0&&n!==void 0){let e=Ei(t),r=Ei(n);return e===r?[{kind:`detected`,value:e}]:[{kind:`opened`,value:e},{kind:`closed`,value:r}]}return t===void 0?n===void 0?[]:[{kind:`closed`,value:Ei(n)}]:[{kind:`opened`,value:Ei(t)}]}var Oi=100,ki={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Ai=e=>e<0?0:e>1?1:e,ji=e=>Math.round(e*100)/100;function Mi(e,t,n){if(e.length===0||t===null)return ki;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return ki;let a=oe(e.map(e=>({x:e.x/r,y:e.y/i,w:e.bbox.w/r,h:e.bbox.h/i})),n?.maxPoints===void 0?void 0:{maxPoints:n.maxPoints}).nodes.map(e=>({x:ji(e.x*Oi),y:ji(e.y*Oi)})),o=a[0]??null,s=a[a.length-1]??null,c=a.length>=2?a.map(e=>`${e.x},${e.y}`).join(` `):``,l=(n?.snapshots??[]).map(e=>({x:ji(Ai(e.x/r)*Oi),y:ji(Ai(e.y/i)*Oi),mediaId:e.mediaId})),u=null,d=-1;for(let t of e){let e=Ai(t.bbox.w/r)*Ai(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:ji(Ai(u.bbox.x/r)*Oi),y:ji(Ai(u.bbox.y/i)*Oi),w:ji(Ai(u.bbox.w/r)*Oi),h:ji(Ai(u.bbox.h/i)*Oi)}:null}}var Ni=typeof We==`function`,Pi=`Track deletion arrives with the next server update`;function Fi(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var Ii=Ni?We:Fi;e();var Li=15e3,Ri=k();function zi({url:e,label:t}){let{src:n,failed:r}=Vt(e);return n===null?d(`div`,{className:`flex h-full w-full items-center justify-center bg-surface-hover`,children:r?d(M,{className:`h-4 w-4 text-foreground-subtle opacity-60`}):d(W,{className:`h-4 w-4 animate-spin text-foreground-subtle opacity-70`})}):d(`img`,{src:n,alt:t,className:`h-full w-full object-cover`})}var Bi=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),Vi=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`,`sceneFrame`,`lastSceneFrame`]);function Hi(e){let[n,i]=r(null);return t(()=>{if(i(null),!e)return;let t=!1,n=new Image;return n.onload=()=>{t||i({width:n.naturalWidth,height:n.naturalHeight})},n.src=e,()=>{t=!0,n.onload=null}},[e]),n}function Ui({overlay:e,onPickSnapshot:t}){let{t:n}=X();return!e.polyline&&!e.peakBox&&e.snapshots.length===0?null:a(`svg`,{viewBox:`0 0 100 100`,preserveAspectRatio:`none`,className:`pointer-events-none absolute inset-0 h-full w-full`,children:[e.peakBox&&d(`rect`,{x:e.peakBox.x,y:e.peakBox.y,width:e.peakBox.w,height:e.peakBox.h,fill:`none`,stroke:`var(--color-warning)`,strokeWidth:2,vectorEffect:`non-scaling-stroke`,rx:1}),e.polyline&&d(`polyline`,{points:e.polyline,fill:`none`,stroke:`var(--color-info)`,strokeWidth:2,strokeLinejoin:`round`,strokeLinecap:`round`,strokeOpacity:.85,vectorEffect:`non-scaling-stroke`}),e.points.map((e,t)=>d(`circle`,{cx:e.x,cy:e.y,r:1,fill:`var(--color-info)`,fillOpacity:.6,vectorEffect:`non-scaling-stroke`},`${String(e.x)}-${String(e.y)}-${String(t)}`)),e.snapshots.map((e,r)=>d(`circle`,{cx:e.x,cy:e.y,r:1.9,fill:`var(--color-info)`,fillOpacity:.95,stroke:`var(--color-background)`,strokeWidth:.7,vectorEffect:`non-scaling-stroke`,className:t?`pointer-events-auto cursor-pointer`:void 0,onClick:t?n=>{n.stopPropagation(),t(e.mediaId)}:void 0,children:d(`title`,{children:n(`detectionIntelligence.eventDetailPanel.snapshotCheckpointClickToView`,`Snapshot checkpoint — click to view this frame`)})},`snap-${String(e.mediaId)}-${String(r)}`)),e.start&&d(`circle`,{cx:e.start.x,cy:e.start.y,r:2.4,fill:`var(--color-success)`,stroke:`var(--color-background)`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`}),e.end&&d(`circle`,{cx:e.end.x,cy:e.end.y,r:2.4,fill:`var(--color-danger)`,stroke:`var(--color-background)`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`})]})}function Z({label:e,value:t,mono:n,wrap:r}){return a(`div`,{className:`flex items-baseline justify-between gap-3 border-b border-border/60 py-1.5 last:border-0`,children:[d(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),d(`span`,{className:`min-w-0 ${r?`break-words`:`truncate`} text-right text-xs font-medium text-foreground ${n?`font-mono text-[11px]`:``}`,title:t,children:t})]})}function Wi({row:e,cameraName:o,deleteAvailable:s,onClose:l,onDeleted:u,onFlagsChanged:f}){let{t:p}=X(),m=G(),h=Oe(),g=je(),_=Ii(),v=e!==null,y=e?.deviceId??0,S=e?.trackId??``,C=e?.timestamp??0,w=e?.windowMs??0,{data:T}=Ie({deviceId:y,trackId:S},{enabled:v}),{data:E}=ht({trackId:S,deviceId:y},{enabled:v}),D=T?.bestEventId===void 0?void 0:Number(T.bestEventId),{data:O}=tt({ownerType:`object`,eventId:D??0,deviceId:y},{enabled:v&&D!==void 0&&Number.isFinite(D)}),{data:k}=ut({deviceId:y},{enabled:v}),A=(k??[]).find(e=>e.addonId!==void 0)?.addonId,{data:j}=Me({deviceId:y,since:C-Li,until:C+w+Li,provider:A??``},{enabled:v&&A!==void 0}),[N,P]=r(null),[F,I]=r(!1),{publicOrigin:L,probes:R}=gi(v);t(()=>{P(null)},[y,S]);let z=n(()=>{let e=E??[],t=O??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[E,O]),B=N??z,V=Vt(B?B.url:void 0),H=n(()=>{let e=new Set,t=[];for(let n of[...O??[],...E??[]])e.has(n.mediaId)||(e.add(n.mediaId),t.push(n));return t},[O,E]),U=n(()=>H.find(e=>Bi.has(e.kind))??null,[H]),ee=Hi(Vt(U?U.url:void 0).src),te=n(()=>Mi(T?.positions??[],ee,{snapshots:(T?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaId:e.mediaId}))}),[T?.positions,T?.snapshots,ee]),ne=i(e=>{let t=H.find(t=>t.mediaId===e);t&&P(t)},[H]);if(e===null)return null;let K=V.src,re=B?.kind,ie=re!==void 0&&Vi.has(re)&&ee!==null&&(T?.positions.length??0)>=2,q=j&&j.length>0?j[0]:null,ae=()=>{q&&(I(!0),(async()=>{try{let t=await m.trpcClient.videoclips.getClipPlayback.query({deviceId:e.deviceId,clipId:q.id});window.open(t.playbackUrl,`_blank`,`noopener`)}catch{h({title:p(`detectionIntelligence.eventDetailPanel.clipUnavailable`,`Clip unavailable`),message:p(`detectionIntelligence.eventDetailPanel.couldNotResolveClipPlayback`,`Could not resolve clip playback. Check the server logs.`),variant:`warning`})}finally{I(!1)}})())},oe=()=>{!s||_.isPending||(async()=>{if(await g({title:p(`detectionIntelligence.eventDetailPanel.deleteTrack`,`Delete track`),message:p(`detectionIntelligence.eventDetailPanel.deleteThisTrackAndEvery`,`Delete this track and every image and clip captured for it? This cannot be undone.`),confirmLabel:p(`common.delete`,`Delete`),variant:`danger`}))try{await _.mutateAsync({deviceId:e.deviceId,trackIds:[e.trackId]}),u()}catch{await h({title:p(`detectionIntelligence.eventDetailPanel.deleteFailed`,`Delete failed`),message:p(`detectionIntelligence.eventDetailPanel.failedToDeleteThisTrack`,`Failed to delete this track. Check the server logs.`),variant:`danger`})}})()},se=Math.round(e.importance*100),ce=T?.importanceReason?`${String(se)}% · ${T.importanceReason}`:`${String(se)}%`,le=T?.zonesVisited&&T.zonesVisited.length>0?T.zonesVisited.join(`, `):`—`,ue=T?.audioLabels&&T.audioLabels.length>0?T.audioLabels:e.audioLabels&&e.audioLabels.length>0?e.audioLabels:void 0,de=ue===void 0?`—`:ue.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `),fe=T?T.totalDistance.toFixed(2):`—`,pe=ii(T?.previewMissReason),me=Xn(T?T.firstSeen:C),he=T?Xn(T.lastSeen):`—`,ge=Di(T),_e={detected:p(`detectionIntelligence.eventDetailPanel.detectedOn`,`Detected on`),opened:p(`detectionIntelligence.eventDetailPanel.openedOn`,`Opened on`),closed:p(`detectionIntelligence.eventDetailPanel.closedOn`,`Closed on`)};return d(vt,{open:!0,onOpenChange:e=>!e&&l(),children:a(ct,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":p(`detectionIntelligence.eventDetailPanel.eventDetail`,`Event detail`),className:`flex h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:h-auto md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[d(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:a(`div`,{className:`min-w-0`,children:[a(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:[e.className,Gr(e)?a(`span`,{className:`text-foreground-subtle`,children:[` · `,Gr(e)]}):null]}),d(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:o})]})}),a(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[K?d(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:d(pr,{src:K,alt:p(`detectionIntelligence.eventDetailPanel.keyFrameFrom`,`Key frame from {{cameraName}}`,{cameraName:o}),fit:`natural`,className:`w-full`,overlay:ie?d(Ui,{overlay:te,onPickSnapshot:ne}):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:V.failed?a(c,{children:[d(M,{className:`h-8 w-8 opacity-60`}),d(`span`,{className:`text-[11px]`,children:p(`detectionIntelligence.eventDetailPanel.keyFrameMediaUnavailable`,`Key-frame media unavailable`)})]}):d(W,{className:`h-6 w-6 animate-spin opacity-70`})}),H.length>0&&d(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:H.map(e=>{let t=pi(e.kind),n=mi(Ri,e.url),r=L?mi(L,e.url):null;return a(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[d(`button`,{type:`button`,onClick:()=>P(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${t} · ${Xn(e.timestamp)}`,children:d(zi,{url:e.url,label:t})}),a(`figcaption`,{className:`min-w-0 px-0.5`,children:[d(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:t,children:t}),d(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:Xn(e.timestamp),children:Yn(e.timestamp)})]}),d(ui,{localUrl:n,publicUrl:r})]},e.mediaId)})}),R,q&&a(J,{variant:`secondary`,onClick:ae,disabled:F,children:[F?d(W,{className:`h-3.5 w-3.5 animate-spin`}):d(b,{className:`h-3.5 w-3.5`}),` `,p(`detectionIntelligence.eventDetailPanel.viewClip`,`View clip`)]}),d(Ti,{deviceId:e.deviceId,trackId:e.trackId,...(T?.markForTrain??e.markForTrain)===void 0?{}:{markForTrain:T?.markForTrain??e.markForTrain},...(T?.debug??e.debug)===void 0?{}:{debug:T?.debug??e.debug},...(T?.favourited??e.favourited)===void 0?{}:{favourited:T?.favourited??e.favourited},onChange:f}),pe!==null&&a(`div`,{className:`rounded-lg border border-warning/40 bg-warning/8 px-3 py-2`,children:[d(`p`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:p(`detectionIntelligence.eventDetailPanel.bestShot`,`Best shot`)}),d(`p`,{className:`mt-0.5 text-xs text-foreground`,children:pe.sentence}),d(`code`,{className:`mt-1 block break-all font-mono text-[10px] text-foreground-subtle`,children:pe.raw})]}),a(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[d(Z,{label:p(`detectionIntelligence.eventDetailPanel.camera`,`Camera`),value:o}),ge.map(e=>d(Z,{label:_e[e.kind],value:e.value,mono:!0,wrap:!0},e.kind)),d(Z,{label:p(`detectionIntelligence.eventDetailPanel.class`,`Class`),value:e.className}),d(Z,{label:p(`detectionIntelligence.eventDetailPanel.label`,`Label`),value:e.label??`—`}),d(Z,{label:p(`detectionIntelligence.eventDetailPanel.subLabel`,`Sub-label`),value:e.subLabel??`—`}),d(Z,{label:p(`detectionIntelligence.eventDetailPanel.importance`,`Importance`),value:ce}),d(Z,{label:p(`detectionIntelligence.eventDetailPanel.zonesVisited`,`Zones visited`),value:le}),d(Z,{label:p(`detectionIntelligence.eventDetailPanel.audioHeard`,`Audio heard`),value:de}),d(Z,{label:p(`detectionIntelligence.eventDetailPanel.totalDistance`,`Total distance`),value:fe}),d(Z,{label:p(`detectionIntelligence.eventDetailPanel.firstSeen`,`First seen`),value:me}),d(Z,{label:p(`detectionIntelligence.eventDetailPanel.lastSeen`,`Last seen`),value:he}),d(Z,{label:p(`detectionIntelligence.eventDetailPanel.track`,`Track`),value:e.trackId,mono:!0})]})]}),d(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:d(`span`,{title:s?void 0:Pi,children:a(J,{variant:`secondary`,onClick:oe,disabled:!s||_.isPending,children:[_.isPending?d(W,{className:`h-3.5 w-3.5 animate-spin`}):d(x,{className:`h-3.5 w-3.5`}),` `,p(`detectionIntelligence.eventDetailPanel.deleteTrack`,`Delete track`)]})})})]})})}var Gi={status:`debug.tape.status`,promote:`debug.tape.promote`,list:`debug.tape.list`,tracks:`debug.tape.tracks`,review:`debug.tape.review`,release:`debug.tape.release`,remove:`debug.tape.delete`},Ki={setRelation:`debug.gt.setRelation`,setPurity:`debug.gt.setPurity`,list:`debug.gt.list`},qi=w(`/addon/pipeline-analytics/tape-export`),Ji=10*6e4;function Yi(e){return`${qi}?tapeId=${encodeURIComponent(e)}`}var Xi=`The server answered in a shape this build does not understand.`;function Zi(e){return e instanceof Error?e.message:Y.t(`helpers.eventsDebugTapes.actionFailed`)}function Qi(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Q(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function $i(e,t){if(!(t in e))return;let n=e[t];return n===null?null:typeof n==`number`&&Number.isFinite(n)?n:void 0}function $(e,t){let n=e[t];return typeof n==`string`?n:null}function ea(e,t){let n=e[t];return typeof n==`boolean`?n:null}function ta(e,t){if(!Array.isArray(e))return null;let n=[];for(let r of e){let e=t(r);if(e===null)return null;n.push(e)}return n}function na(e){return e===`off`||e===`recording`||e===`refused`||e===`failing`||e===`unknown`}function ra(e){if(!Qi(e))return null;let t=Q(e,`deviceId`),n=e.state,r=Q(e,`gapsSinceArmed`),i=$i(e,`segmentsHeld`),a=$i(e,`bytesLastHour`),o=$i(e,`bytesHeld`);if(t===null||!na(n)||r===null||i===void 0||a===void 0||o===void 0)return null;let s=$(e,`reason`),c=Q(e,`segmentOriginMs`),l=Q(e,`framesPerMin`),u=Q(e,`heldFromMs`),d=Q(e,`heldToMs`),f=$(e,`shelfError`);return{deviceId:t,state:n,gapsSinceArmed:r,segmentsHeld:i,bytesLastHour:a,bytesHeld:o,...s===null?{}:{reason:s},...c===null?{}:{segmentOriginMs:c},...l===null?{}:{framesPerMin:l},...u===null?{}:{heldFromMs:u},...d===null?{}:{heldToMs:d},...f===null?{}:{shelfError:f}}}function ia(e){return Qi(e)?ta(e.cameras,ra):null}function aa(e){if(!Qi(e))return null;let t=$(e,`id`),n=Q(e,`deviceId`),r=$(e,`scenario`),i=e.lighting,a=Q(e,`fromMs`),o=Q(e,`toMs`),s=e.state,c=Q(e,`frames`),l=Q(e,`gaps`),u=Q(e,`bytes`),d=ea(e,`reviewed`),f=ea(e,`released`),p=ta(e.tracks,e=>typeof e==`string`?e:null),m=Q(e,`tracksStillStored`);return t===null||n===null||r===null||i!==`day`&&i!==`ir`||a===null||o===null||s!==`complete`&&s!==`incomplete`||c===null||l===null||u===null||d===null||f===null||p===null||m===null?null:{id:t,deviceId:n,scenario:r,note:$(e,`note`),lighting:i,fromMs:a,toMs:o,state:s,frames:c,gaps:l,bytes:u,reviewed:d,released:f,tracks:p,tracksStillStored:m}}function oa(e){return Qi(e)?ta(e.tapes,aa):null}function sa(e){if(!Qi(e))return null;let t=$(e,`trackId`),n=Q(e,`firstT`),r=Q(e,`lastT`),i=Q(e,`boundFrames`),a=$(e,`cls`),o=ea(e,`stillStored`);return t===null||n===null||r===null||i===null||a===null||o===null?null:{trackId:t,firstT:n,lastT:r,boundFrames:i,cls:a,stillStored:o}}function ca(e){if(!Qi(e))return null;let t=$(e,`tapeId`),n=Q(e,`deviceId`),r=Q(e,`fromMs`),i=Q(e,`toMs`),a=ea(e,`reviewed`),o=ta(e.lanes,sa);return t===null||n===null||r===null||i===null||a===null||o===null?null:{tapeId:t,deviceId:n,fromMs:r,toMs:i,reviewed:a,lanes:o}}function la(e){if(!Qi(e))return null;if(e.ok===!1){let t=$(e,`reason`),n=$(e,`detail`);return t===null||n===null?null:{ok:!1,reason:t,detail:n}}if(e.ok!==!0)return null;let t=$(e,`tapeId`),n=e.state,r=Q(e,`frames`),i=Q(e,`gaps`),a=Q(e,`pinnedTracks`),o=Q(e,`bytes`);return t===null||n!==`complete`&&n!==`incomplete`||r===null||i===null||a===null||o===null?null:{ok:!0,tapeId:t,state:n,frames:r,gaps:i,pinnedTracks:a,bytes:o}}function ua(e){if(!Qi(e))return null;let t=e.status;if(t===`released`){let n=Q(e,`unpinned`),r=ea(e,`pinsSettled`);return n===null||r===null?null:{status:t,unpinned:n,pinsSettled:r}}if(t===`already-released`||t===`not-found`)return{status:t};if(t===`unavailable`){let n=$(e,`reason`);return n===null?null:{status:t,reason:n}}return null}function da(e){if(!Qi(e))return null;let t=e.status;if(t===`deleted`||t===`pins-owed`||t===`not-found`)return{status:t};if(t===`unavailable`){let n=$(e,`reason`);return n===null?null:{status:t,reason:n}}return null}function fa(e){switch(e.status){case`released`:case`deleted`:return null;case`already-released`:return Y.t(`helpers.eventsDebugTapes.alreadyReleased`);case`not-found`:return Y.t(`helpers.eventsDebugTapes.notFound`);case`pins-owed`:return Y.t(`helpers.eventsDebugTapes.pinsOwed`);case`unavailable`:return Y.t(`helpers.eventsDebugTapes.unavailable`,{reason:e.reason})}}function pa(e){if(!Qi(e))return null;let t=$(e,`leftTrackId`),n=$(e,`rightTrackId`),r=e.relation,i=e.presence;return t===null||n===null||r!==`same-subject`&&r!==`different-subjects`?null:{leftTrackId:t,rightTrackId:n,relation:r,presence:i===`continuous`?`continuous`:null}}function ma(e){if(!Qi(e))return null;let t=$(e,`sourceTrackId`),n=e.purity;return t===null||n!==`mixed`&&n!==`not-a-subject`?null:{sourceTrackId:t,purity:n,switchAtMs:Q(e,`switchAtMs`)}}function ha(e){if(!Qi(e))return null;let t=ta(e.relations,pa),n=ta(e.purities,ma),r=ea(e,`truncated`);return t===null||n===null||r===null?null:{relations:t,purities:n,truncated:r}}function ga(e){if(!e.truncated)return null;let t=e.relations.length+e.purities.length;return Y.t(`helpers.eventsDebugTapes.truncatedMarks`,{count:t})}function _a(e){return e.filter(e=>e.segmentsHeld===null||e.segmentsHeld>0).map(e=>({deviceId:e.deviceId,segmentsUnknown:e.segmentsHeld===null}))}function va(e){return e.slice(1).map((t,n)=>({trackId:e[n]??t,otherTrackId:t}))}function ya(e){return e.flatMap((t,n)=>e.slice(n+1).map(e=>({trackId:t,otherTrackId:e})))}function ba(e,t){let n=[];for(let r of t.relations){let t=r.leftTrackId===e?r.rightTrackId:r.rightTrackId===e?r.leftTrackId:null;if(t===null)continue;let i=r.relation===`same-subject`?`same as`:`different from`;n.push(`${i} ${t}${r.presence===`continuous`?` (continuous)`:``}`)}for(let r of t.purities)r.sourceTrackId===e&&n.push(r.purity===`not-a-subject`?`not a subject`:r.switchAtMs===null?`mixed`:`mixed at switch`);return n}function xa(e){switch(e.state){case`off`:return Y.t(`helpers.eventsDebugTapes.statusOff`);case`recording`:return Y.t(`helpers.eventsDebugTapes.statusRecording`);case`refused`:return Y.t(`helpers.eventsDebugTapes.statusRefused`,{reason:e.reason??Y.t(`helpers.eventsDebugTapes.unknownReason`)});case`failing`:return Y.t(`helpers.eventsDebugTapes.statusFailing`,{reason:e.reason??Y.t(`helpers.eventsDebugTapes.unknownReason`)});case`unknown`:return Y.t(`helpers.eventsDebugTapes.statusUnknown`,{reason:e.reason??Y.t(`helpers.eventsDebugTapes.unknownReason`)})}}var Sa={"window-too-long":`A promoted window is at most 30 minutes.`,"window-in-future":`The window ends in the future.`,"window-not-recorded":`No segment covers that window — the camera was not recording then, or it is older than 24 h.`,"invalid-scenario":`The scenario must be a slug: lowercase letters, digits and dashes, 3–64 characters.`,"promotion-budget":`A promotion budget is full (60 tapes, 1 GiB, 3 000 pinned tracks). Release or delete a tape already committed as a case first.`,"empty-window":`No frame was recorded in that window.`,"shelf-unreadable":`The camera's recorded segments could not be listed, so the window cannot be proven whole.`,"not-post-processing-node":`This node does not post-process frames, so it records no tracking tapes.`,"artifacts-elsewhere":`The artifacts storage location is on another node; tapes are recorded only where it lives.`,"tapes-not-started":`The tape recorder has not started on this node (or failed to).`};function Ca(e,t){let n=Sa[e]??`Refused (${e}).`;return t.length>0?`${n} ${t}`:n}function wa(e){if(e.length===0)return null;let t=new Date(e).getTime();return Number.isFinite(t)?t:null}function Ta(e){return e<1024*1024?Y.t(`helpers.eventsDebugTapes.sizeKb`,{value:(e/1024).toFixed(0)}):Y.t(`helpers.eventsDebugTapes.sizeMb`,{value:(e/1024/1024).toFixed(1)})}function Ea(e){return e===null?`unknown`:Ta(e)}function Da(e){return e===null?`unknown`:String(e)}function Oa(e,t){let n=t.trim();return e===404?Y.t(`helpers.eventsDebugTapes.exportUnknown`):e===503?n.length>0?n:Y.t(`helpers.eventsDebugTapes.tapesUnavailable`):e===500?n.length>0?n:Y.t(`helpers.eventsDebugTapes.exportUnreadable`):Y.t(`helpers.eventsDebugTapes.downloadFailed`,{status:e})}e();function ka({cameras:e,call:t,onPromoted:n}){let{t:i}=X(),[o,s]=r(``),[c,l]=r(``),[u,f]=r(``),[p,m]=r(``),[h,g]=r(``),[_,v]=r(`auto`),[y,b]=r(!1),[x,S]=r(null),C=async()=>{let r=Number.parseInt(o===``?e[0]?.value??``:o,10),i=wa(c),a=wa(u);if(!Number.isFinite(r)||i===null||a===null){S(`Pick a camera and both ends of the window.`);return}b(!0),S(null);try{let e=la(await t(Gi.promote,{deviceId:r,fromMs:i,toMs:a,scenario:p,...h.trim().length>0?{note:h.trim()}:{},..._===`day`||_===`ir`?{lighting:_}:{}}));e===null?S(Xi):e.ok?(S(`Promoted ${e.tapeId}: ${String(e.frames)} frames, ${Ta(e.bytes)}, ${String(e.pinnedTracks)} tracks pinned`+(e.state===`incomplete`?` — incomplete (it has gaps) and cannot become a case.`:`.`)),n()):S(Ca(e.reason,e.detail))}catch(e){S(Zi(e))}finally{b(!1)}};return a(`div`,{className:`flex flex-wrap items-end gap-2 rounded-md border border-border px-3 py-2`,children:[d(`div`,{className:`w-40`,children:d(ke,{value:o,options:[...e],onChange:e=>s(e.target.value),"aria-label":i(`eventsDebugTapesPromoteForm.camera`,`Camera`)})}),d(Ee,{type:`datetime-local`,"aria-label":i(`eventsDebugTapesPromoteForm.from`,`From`),value:c,onChange:e=>l(e.target.value),className:`w-48`}),d(Ee,{type:`datetime-local`,"aria-label":i(`eventsDebugTapesPromoteForm.to`,`To`),value:u,onChange:e=>f(e.target.value),className:`w-48`}),d(Ee,{"aria-label":i(`eventsDebugTapesPromoteForm.scenario`,`Scenario`),placeholder:`615-door-groups`,value:p,onChange:e=>m(e.target.value),className:`w-44`}),d(Ee,{"aria-label":i(`eventsDebugTapesPromoteForm.note`,`Note`),placeholder:i(`eventsDebugTapesPromoteForm.optionalNote`,`optional note`),value:h,onChange:e=>g(e.target.value),className:`w-52`}),d(`div`,{className:`w-28`,children:d(ke,{value:_,"aria-label":i(`eventsDebugTapesPromoteForm.lighting`,`Lighting`),options:[{value:`auto`,label:i(`eventsDebugTapesPromoteForm.lightingAuto`,`Lighting: auto`)},{value:`day`,label:i(`eventsDebugTapes.dayMode`)},{value:`ir`,label:`IR`}],onChange:e=>v(e.target.value)})}),a(J,{onClick:()=>void C(),disabled:y||e.length===0,children:[y?d(W,{className:`h-3.5 w-3.5 animate-spin`}):null,` `,i(`eventsDebugTapes.promoteWindow`)]}),d(`p`,{className:`w-full text-xs text-foreground-subtle`,children:i(`eventsDebugTapesPromoteForm.aPromotedTapeMayBe`,`A promoted tape may be shared as a test case — keep the scenario slug and note free of names or other personal data.`)}),x!==null&&d(`p`,{className:`w-full text-xs text-foreground`,children:x})]})}var Aa=`pipeline-analytics`,ja=`debug.listTracks`,Ma=`debug.analyze`,Na=w(`/addon/pipeline-analytics/debug-export`);function Pa(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Fa(e,t){let n=e[t];return typeof n==`string`?n:null}function Ia(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function La(e,t){let n=e[t];return typeof n==`boolean`?n:null}function Ra(e){return e===`error`||e===`warn`||e===`info`}function za(e){if(!Pa(e))return null;let t=Fa(e,`code`),n=Fa(e,`detail`),r=e.severity;return t===null||n===null||!Ra(r)?null:{code:t,severity:r,detail:n}}function Ba(e){if(!Pa(e))return null;let t=Fa(e,`trackId`),n=Ia(e,`deviceId`),r=Fa(e,`className`),i=Ia(e,`firstSeen`),a=Ia(e,`lastSeen`),o=Ia(e,`durationMs`),s=La(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=Fa(e,`label`),l=Fa(e,`subLabel`),u=Fa(e,`previewMissReason`),d=La(e,`markForTrain`),f=La(e,`favourited`);return{trackId:t,deviceId:n,className:r,...c===null?{}:{label:c},...l===null?{}:{subLabel:l},firstSeen:i,lastSeen:a,durationMs:o,active:s,timestamp:i,windowMs:o,importance:Ia(e,`importance`)??0,bestEventId:Fa(e,`bestEventId`)??``,...d===null?{}:{markForTrain:d},...f===null?{}:{favourited:f},debug:!0,...u===null||u.length===0?{}:{previewMissReason:u}}}function Va(e){let t=Ba(e);if(t===null||!Pa(e))return null;let n=Ia(e,`mediaCount`),r=Ia(e,`eventCount`),i=Ia(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=za(e);t!==null&&c.push(t)}let l=e.thumbnailProvenance;return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c,...ei(l)?{thumbnailProvenance:l}:{}}}function Ha(e){if(!Pa(e))return null;let t=La(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=Ba(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function Ua(e){if(!Pa(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=Va(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var Wa={MEDIA_EVICTED_OR_NEVER:`no media`,MISSING_KEYFRAME:`no keyframe`,MISSING_FIRSTFRAME:`no first frame`,MISSING_LASTFRAME:`no last frame`,MISSING_THUMBNAIL:`no thumbnail`,MISSING_BEST_CROP:`no crop`,SHORT_TRACK:`very short`,ZERO_EVENTS:`no events`,ZERO_POSITIONS:`no trajectory`,NO_PERIODIC_SNAPSHOTS:`no snapshots`,LASTFRAME_STALE:`stale last frame`,MEDIA_STOPPED_EARLY:`media stopped early`,NO_BEST_EVENT:`no best event`,LOW_BEST_SCORE:`low score`,UNSCORED_LABEL:`unscored label`,BEST_SHOT_STANDIN:`stand-in best shot`,BEST_SHOT_RASTER:`low-res best shot`};function Ga(e){return Wa[e]??e}var Ka={error:0,warn:1,info:2};function qa(e){return e.toSorted((e,t)=>Ka[e.severity]-Ka[t.severity]||e.code.localeCompare(t.code))}function Ja(e){return e.length===0?Na:`${Na}?deviceIds=${e.join(`,`)}`}function Ya(e){if(e<1e4)return`${(e/1e3).toFixed(1)}s`;let t=Math.round(e/1e3);if(t<60)return`${String(t)}s`;let n=Math.floor(t/60);return`${String(n)}m ${String(t%60).padStart(2,`0`)}s`}function Xa(e,t){return`${String(e)}:${t}`}function Za(e,t){let n=[],r=new Set;for(let i of e){let e=Xa(i.deviceId,i.trackId);!t.has(e)||r.has(e)||(r.add(e),n.push({deviceId:i.deviceId,trackId:i.trackId}))}return n}e();function Qa({tapeId:e,call:t,onClose:n,onChanged:i}){let{t:o}=X(),c=s({queryKey:[`events-debug`,`tapes`,`tracks`,e],queryFn:async()=>ca(await t(Gi.tracks,{tapeId:e}))}),l=c.data??null,u=s({queryKey:[`events-debug`,`tapes`,`marks`,e],enabled:l!==null,queryFn:async()=>l===null?null:ha(await t(Ki.list,{deviceId:l.deviceId,since:l.fromMs-Ji,until:l.toMs+Ji,limit:5e3}))}),[f,p]=r([]),[m,h]=r(``),[g,_]=r(null),v=e=>p(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),y=async e=>{_(null);try{for(let[n,r]of e)await t(n,r);p([]),await u.refetch(),i()}catch(e){_(Zi(e))}};if(l===null)return c.isLoading?d(`p`,{className:`text-xs`,children:o(`eventsDebugTapesReview.loadingTheTape`,`Loading the tape…`)}):d(at,{message:Xi});let b=l.deviceId,x=(e,t)=>y(e.map(e=>[Ki.setRelation,{deviceId:b,...e,relation:t}])),S=e=>{let t=Number.parseFloat(m),n=e===`mixed`&&Number.isFinite(t)?l.fromMs+t*1e3:void 0;return y(f.map(t=>[Ki.setPurity,{deviceId:b,trackId:t,purity:e,...n===void 0?{}:{switchAtMs:Math.round(n)}}]))},C=u.data==null?null:ga(u.data);return a(`div`,{className:`space-y-2 rounded-md border border-primary/40 px-3 py-2`,children:[a(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d(`span`,{className:`text-xs font-medium`,children:o(`eventsDebugTapes.reviewLanes`,{id:l.tapeId,count:l.lanes.length})}),d(J,{disabled:f.length<2,onClick:()=>void x(va(f),`same-subject`),children:o(`eventsDebugTapesReview.sameSubject`,`Same subject`)}),d(J,{variant:`secondary`,disabled:f.length<2,onClick:()=>void x(ya(f),`different-subjects`),children:o(`eventsDebugTapesReview.differentSubjects`,`Different subjects`)}),d(Ee,{"aria-label":o(`eventsDebugTapesReview.changedAtSFromTape`,`Changed at (s from tape start)`),placeholder:o(`eventsDebugTapesReview.changedAtS`,`changed at s`),value:m,onChange:e=>h(e.target.value),className:`w-28`}),d(J,{variant:`secondary`,disabled:f.length!==1,onClick:()=>void S(`mixed`),children:o(`eventsDebugTapesReview.mixed`,`Mixed`)}),d(J,{variant:`secondary`,disabled:f.length===0,onClick:()=>void S(`not-a-subject`),children:o(`eventsDebugTapesReview.notASubject`,`Not a subject`)}),d(J,{variant:l.reviewed?`secondary`:`primary`,onClick:()=>void y([[Gi.review,{tapeId:l.tapeId,reviewed:!l.reviewed}]]).then(()=>c.refetch()),children:l.reviewed?o(`eventsDebugTapesReview.markNotReviewed`,`Mark not reviewed`):o(`eventsDebugTapesReview.markReviewed`,`Mark reviewed`)}),d(J,{variant:`ghost`,onClick:n,children:o(`common.close`,`Close`)})]}),g!==null&&d(at,{message:g}),C!==null&&d(at,{variant:`warning`,message:C}),d(`ul`,{className:`space-y-1`,children:l.lanes.toSorted((e,t)=>e.firstT-t.firstT).map(e=>d($a,{lane:e,marks:u.data===null||u.data===void 0?[]:ba(e.trackId,u.data),selected:f.includes(e.trackId),onToggle:()=>v(e.trackId)},e.trackId))})]})}function $a({lane:e,marks:t,selected:n,onToggle:r}){let{t:i}=X(),{src:o}=Vt(e.stillStored?Ht(`track`,e.trackId):void 0);return a(`li`,{className:`flex items-center gap-2 text-xs`,children:[d(`input`,{type:`checkbox`,"aria-label":i(`eventsDebugTapesReview.select`,`select {{trackId}}`,{trackId:e.trackId}),checked:n,onChange:r}),o===null?d(`div`,{className:`h-10 w-10 rounded bg-surface-hover`}):d(`img`,{src:o,alt:e.trackId,className:`h-10 w-10 rounded object-cover`}),d(`span`,{className:`font-mono`,children:e.trackId}),d(`span`,{children:e.cls}),d(`span`,{className:`text-foreground-subtle`,children:i(`eventsDebugTapes.laneFrames`,{range:`${Ya(e.firstT)} → ${Ya(e.lastT)}`,count:e.boundFrames})}),!e.stillStored&&d(`span`,{className:`text-foreground-subtle`,children:i(`eventsDebugTapesReview.notStoredMarkedThroughThe`,`not stored — marked through the tape`)}),t.map(e=>d(Ce,{variant:`info`,children:e},e))]})}e();var eo=`camstack_admin_token`;function to(){let e=G();return(t,n)=>e.trpcClient.addons.custom.mutate({addonId:Aa,action:t,input:n})}async function no(e,t){let n=localStorage.getItem(eo),r={};n!==null&&(r.Authorization=`Bearer ${n}`);let i=await fetch(Yi(e),{headers:r});if(!i.ok){let e=await i.text().catch(()=>``);throw Error(Oa(i.status,e))}let a=await i.blob(),o=i.headers.get(`content-disposition`),s=(o===null?null:/filename="?([^";]+)"?/i.exec(o))?.[1]?.trim()??t,c=URL.createObjectURL(a),l=document.createElement(`a`);l.href=c,l.download=s,l.click(),setTimeout(()=>URL.revokeObjectURL(c),6e4)}function ro(){let{t:e}=X(),[t,n]=r(!1);return d(Be,{expanded:t,onExpandedChange:n,header:d(`span`,{className:`text-sm font-medium text-foreground`,children:e(`eventsDebugTapes.trackingTapes`,`Tracking tapes`)}),children:d(io,{})})}function io(){let{t:e}=X(),t=to(),i=kt({isCamera:!0,projection:`slim`}),o=n(()=>{let t=new Map;for(let e of i.data??[])t.set(e.id,e.name);return n=>t.get(n)??e(`cameraLoad.deviceLabel`,{deviceId:n})},[i.data,e]),c=s({queryKey:[`events-debug`,`tapes`,`status`],queryFn:async()=>ia(await t(Gi.status,{}))}),l=s({queryKey:[`events-debug`,`tapes`,`list`],queryFn:async()=>oa(await t(Gi.list,{}))}),[u,f]=r(null),[p,m]=r(null),h=async e=>{m(null);try{await no(e.id,`${e.scenario}.tape-bundle.json.gz`)}catch(e){m(Zi(e))}},g=async e=>{let n=ua(await t(Gi.release,{tapeId:e.id}));if(n===null)throw Error(Xi);let r=fa(n);if(r!==null)throw Error(r);await l.refetch()},_=async e=>{let n=da(await t(Gi.remove,{tapeId:e.id}));if(n===null)throw Error(Xi);let r=fa(n);if(r!==null)throw Error(r);await l.refetch()};return a(`div`,{className:`space-y-3`,children:[d(`p`,{className:`text-xs text-foreground-subtle`,children:d(Lt,{i18nKey:`eventsDebugTapes.intro`,components:{b:d(`strong`,{}),code:d(`code`,{})}})}),p!==null&&d(at,{message:p}),c.isLoading&&d(`p`,{className:`text-xs text-foreground-subtle`,children:e(`eventsDebugTapes.loadingCameraStatus`,`Loading camera status…`)}),c.data===null&&d(at,{message:`The server answered in a shape this build does not understand.`}),a(`table`,{className:`w-full text-xs`,children:[d(`thead`,{children:a(`tr`,{className:`text-left text-foreground-subtle`,children:[d(`th`,{children:e(`eventsDebugTapes.camera`,`Camera`)}),d(`th`,{children:e(`eventsDebugTapes.state`,`State`)}),d(`th`,{children:e(`eventsDebugTapes.framesMin`,`Frames/min`)}),d(`th`,{children:e(`eventsDebugTapes.lastHour`,`Last hour`)}),d(`th`,{children:e(`eventsDebugTapes.held`,`Held`)}),d(`th`,{children:e(`eventsDebugTapes.gaps`,`Gaps`)})]})}),d(`tbody`,{children:(c.data??[]).map(t=>a(`tr`,{children:[d(`td`,{children:o(t.deviceId)}),d(`td`,{children:d(Ce,{variant:t.state===`recording`?`success`:t.state===`off`?`default`:t.state===`unknown`?`warning`:`danger`,children:xa(t)})}),d(`td`,{children:t.framesPerMin===void 0?`—`:String(Math.round(t.framesPerMin))}),d(`td`,{title:t.shelfError,children:Ea(t.bytesLastHour)}),d(`td`,{title:t.shelfError,children:e(`eventsDebugTapes.segsHeld`,{count:Da(t.segmentsHeld),size:Ea(t.bytesHeld)})}),d(`td`,{children:String(t.gapsSinceArmed)})]},t.deviceId))})]}),d(ka,{cameras:_a(c.data??[]).map(t=>({value:String(t.deviceId),label:t.segmentsUnknown?e(`eventsDebugTapes.segmentsUnknown`,`{{value1}} (segments unknown)`,{value1:o(t.deviceId)}):o(t.deviceId)})),call:t,onPromoted:()=>void l.refetch()}),l.isLoading&&d(`p`,{className:`text-xs text-foreground-subtle`,children:e(`eventsDebugTapes.loadingPromotedTapes`,`Loading promoted tapes…`)}),l.data===null&&d(at,{message:`The server answered in a shape this build does not understand.`}),a(`table`,{className:`w-full text-xs`,children:[d(`thead`,{children:a(`tr`,{className:`text-left text-foreground-subtle`,children:[d(`th`,{children:e(`eventsDebugTapes.scenario`,`Scenario`)}),d(`th`,{children:e(`eventsDebugTapes.camera`,`Camera`)}),d(`th`,{children:e(`eventsDebugTapes.window`,`Window`)}),d(`th`,{children:e(`eventsDebugTapes.state`,`State`)}),d(`th`,{children:e(`eventsDebugTapes.tracks`,`Tracks`)}),d(`th`,{})]})}),d(`tbody`,{children:(l.data??[]).map(t=>a(`tr`,{children:[d(`td`,{children:t.scenario}),d(`td`,{children:o(t.deviceId)}),a(`td`,{children:[new Date(t.fromMs).toLocaleString(),` · `,Ya(t.toMs-t.fromMs),` `,`· `,t.lighting]}),a(`td`,{children:[d(Ce,{variant:t.state===`complete`?`success`:`warning`,children:t.state}),` `,t.reviewed&&d(Ce,{variant:`info`,children:e(`eventsDebugTapes.reviewed`)}),` `,t.released&&d(Ce,{children:e(`eventsDebugTapes.released`)})]}),d(`td`,{children:e(`eventsDebugTapes.storedOf`,{stored:String(t.tracksStillStored),total:String(t.tracks.length)})}),a(`td`,{className:`space-x-1 text-right`,children:[d(J,{variant:`secondary`,"aria-label":e(`eventsDebugTapes.review`,`Review {{scenario}}`,{scenario:t.scenario}),onClick:()=>f(t.id),children:e(`eventsDebugTapes.review2`,`Review`)}),d(J,{variant:`ghost`,"aria-label":e(`eventsDebugTapes.download`,`Download {{scenario}}`,{scenario:t.scenario}),onClick:()=>void h(t),children:d(E,{className:`h-3.5 w-3.5`})}),d(ft,{label:e(`eventsDebugTapes.release`,`Release`),icon:B,title:e(`eventsDebugTapes.release2`,`Release {{scenario}}?`,{scenario:t.scenario}),description:e(`eventsDebugTapes.releasingReturnsThisTapeS`,`Releasing returns this tape's pinned tracks to ordinary retention — they can be pruned from then on. The promoted bundle itself is kept until deleted.`),confirmLabel:e(`eventsDebugTapes.release`,`Release`),triggerVariant:`ghost`,confirmVariant:`danger`,disabled:t.released,action:()=>g(t)}),d(ft,{label:e(`common.delete`,`Delete`),icon:x,title:e(`eventsDebugTapes.delete`,`Delete {{scenario}}?`,{scenario:t.scenario}),description:e(`eventsDebugTapes.deletingRemovesThePromotedBundle`,`Deleting removes the promoted bundle and its index row for good. Its tracks' pins are released first — this cannot be undone.`),confirmLabel:e(`common.delete`,`Delete`),triggerVariant:`ghost`,confirmVariant:`danger`,action:()=>_(t)})]})]},t.id))})]}),u!==null&&d(Qa,{tapeId:u,call:t,onClose:()=>f(null),onChanged:()=>void l.refetch()})]})}e();var ao=`all`,oo=`The server answered in a shape this build does not understand.`,so={error:`danger`,warn:`warning`,info:`info`};function co({findings:e}){let{t}=X();return e.length===0?d(Ce,{variant:`success`,children:t(`eventsDebug.noAnomalyFound`,`no anomaly found`)}):d(`div`,{className:`flex flex-wrap gap-1`,children:qa(e).map(e=>d(Ce,{variant:so[e.severity],title:e.detail,children:Ga(e.code)},e.code))})}function lo({track:e,report:t,analyzing:n}){let{t:r}=X(),i=ii(t?.previewMissReason??e.previewMissReason);return a(`div`,{className:`space-y-1 border-t border-border pt-1.5`,children:[t===void 0?d(`span`,{className:`text-[10px] text-foreground-subtle`,children:n?r(`eventsDebug.analysing`,`analysing…`):r(`eventsDebug.notAnalysed`,`not analysed`)}):a(c,{children:[d(co,{findings:t.findings}),d(`p`,{className:`text-[10px] text-foreground-subtle`,title:t.mediaKinds.length>0?t.mediaKinds.join(`, `):r(`eventsDebug.noMediaOfAnyKind`,`no media of any kind`),children:r(`eventsDebug.reportCounts`,{media:String(t.mediaCount),events:String(t.eventCount),positions:String(t.positionCount)})})]}),i!==null&&d(`p`,{className:`text-[10px] text-foreground-subtle`,title:i.raw,children:i.sentence})]})}function uo(){let{t:e}=X(),t=G(),[i,o]=r(ao),[c,l]=r(!1),[u,m]=r(null),[h,g]=r(new Set),[_,v]=r(null),[y,b]=r(null),[x,C]=r(null),[w,D]=r([]),O=Si(),k=kt({isCamera:!0,projection:`slim`}),A=n(()=>[{value:ao,label:e(`eventsDebug.allCameras`,`All cameras`)},...(k.data??[]).map(e=>({value:String(e.id),label:e.name}))],[k.data,e]),j=n(()=>{let e=new Map;for(let t of k.data??[])e.set(t.id,t.name);return e},[k.data]),M=t=>j.get(t)??e(`eventsDebug.cameraFallback`,{deviceId:t}),N=n(()=>i===ao?[]:[Number.parseInt(i,10)],[i]),P=s({queryKey:[`events-debug`,`list`,N],queryFn:async()=>Ha(await t.trpcClient.addons.custom.mutate({addonId:Aa,action:ja,input:N.length===0?{}:{deviceIds:N}}))}),I=n(()=>(P.data?.tracks??[]).map(e=>e.trackId),[P.data]),R=s({queryKey:[`events-debug`,`analyze`,I],enabled:I.length>0,queryFn:async()=>Ua(await t.trpcClient.addons.custom.mutate({addonId:Aa,action:Ma,input:{trackIds:I}}))}),z=n(()=>{let e=new Map;for(let t of R.data?.reports??[])e.set(t.trackId,t);return e},[R.data]),B=P.data?.tracks??[],V=P.data===null||R.data===null,H=()=>{P.refetch(),R.refetch()},U=e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},ee=()=>{g(new Set(B.map(e=>Xa(e.deviceId,e.trackId))))},te=()=>g(new Set),ne=async(e,t)=>{let n=e===`analyzed`?{debug:!1}:{favourited:!0},r=0,i=[];for(let e of t)try{await O.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,flags:n}),r+=1}catch{i.push(e.trackId)}return{applied:r,refused:i}},K=e=>{if(!yi||y!==null)return;let t=Za(B,h);t.length!==0&&(b(e),C(null),(async()=>{let n=await ne(e,t);b(null);let r=new Set(n.refused);g(new Set(t.filter(e=>r.has(e.trackId)).map(e=>Xa(e.deviceId,e.trackId)))),e===`analyzed`&&D(t.filter(e=>!r.has(e.trackId))),n.refused.length>0&&C(`${String(n.refused.length)} of ${String(t.length)} were refused by the server and are still selected. Check the hub log.`),P.refetch()})())},re=()=>{let e=w;e.length===0||y!==null||(b(`analyzed`),C(null),(async()=>{for(let t of e)try{await O.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,flags:{debug:!0}})}catch{C(`Some tracks could not be re-marked. Refresh and try again.`)}b(null),D([]),P.refetch()})())},ie=async()=>{l(!0),m(null);try{await Gt(Ja(N),`camstack-debug.zip`)}catch(e){m(e instanceof Error?e.message:`Export failed.`)}finally{l(!1)}},q=y!==null;return a(`section`,{className:`space-y-3`,children:[a(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`div`,{className:`w-44`,children:d(ke,{value:i,options:A,onChange:e=>o(e.target.value)})}),a(J,{variant:`secondary`,onClick:H,disabled:P.isFetching,children:[P.isFetching?d(W,{className:`h-3.5 w-3.5 animate-spin`}):d(F,{className:`h-3.5 w-3.5`}),e(`common.refresh`,`Refresh`)]}),a(J,{onClick:()=>void ie(),disabled:c||B.length===0,children:[c?d(W,{className:`h-3.5 w-3.5 animate-spin`}):d(E,{className:`h-3.5 w-3.5`}),e(`eventsDebug.exportAll`,{count:String(B.length)})]}),B.length>0&&h.size<B.length&&d(J,{variant:`ghost`,onClick:ee,children:e(`eventsDebug.selectAll`,`Select all`)})]}),d(`p`,{className:`text-xs text-foreground-subtle`,children:d(Lt,{i18nKey:`eventsDebug.debugMarkNote`,components:{code:d(`code`,{}),strong:d(`strong`,{})}})}),d(ro,{}),P.isError&&d(at,{message:e(`eventsDebug.couldNotLoadTheMarked`,`Could not load the marked tracks.`)}),V&&!P.isError&&d(at,{message:oo}),u!==null&&d(at,{message:u}),x!==null&&d(at,{message:x}),P.data?.truncated===!0&&d(at,{message:e(`eventsDebug.aCameraFilledThePer`,`A camera filled the per-camera cap — some marked tracks are not listed. Un-mark a few, or filter to one camera.`)}),(R.data?.vanished.length??0)>0&&d(`p`,{className:`text-xs text-foreground-subtle`,children:e(`eventsDebug.vanished`,{count:String(R.data?.vanished.length)})}),h.size>0&&a(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[d(`span`,{className:`text-xs font-medium text-foreground`,children:e(`common.selectedCount`,{count:h.size})}),a(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[d(`span`,{title:yi?void 0:`Track flags arrive with the next server update`,children:a(J,{variant:`secondary`,onClick:()=>K(`keep`),disabled:!yi||q,children:[y===`keep`?d(W,{className:`h-3.5 w-3.5 animate-spin`}):d(S,{className:`h-3.5 w-3.5`}),` `,e(`eventsDebug.keep`,`Keep`)]})}),d(`span`,{title:yi?void 0:`Track flags arrive with the next server update`,children:a(J,{onClick:()=>K(`analyzed`),disabled:!yi||q,children:[y===`analyzed`?d(W,{className:`h-3.5 w-3.5 animate-spin`}):d(T,{className:`h-3.5 w-3.5`}),` `,e(`eventsDebug.analyzed`,`Analyzed`)]})}),d(J,{variant:`ghost`,onClick:te,disabled:q,children:d(L,{className:`h-3.5 w-3.5`})})]})]}),w.length>0&&a(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-border bg-surface px-3 py-2`,children:[d(`span`,{className:`text-xs text-foreground`,children:e(`eventsDebug.markedAnalyzed`,{count:String(w.length)})}),a(J,{variant:`ghost`,onClick:re,disabled:q,children:[d(p,{className:`h-3.5 w-3.5`}),` `,e(`eventsDebug.undo`)]}),d(J,{variant:`ghost`,onClick:()=>D([]),disabled:q,children:d(L,{className:`h-3.5 w-3.5`})})]}),P.isLoading?d(pt,{status:`pending`,pendingMessage:`Loading…`,testId:`debug-tracks-grid`}):B.length===0?d(Ke,{icon:f,title:e(`eventsDebug.noTrackIsMarkedFor`,`No track is marked for debug`),description:e(`eventsDebug.markOneFromATrack`,`Mark one from a track's actions on the Feed to see it here.`)}):d(pt,{status:`ready`,testId:`debug-tracks-grid`,children:B.map(e=>{let t=z.get(e.trackId);return d(oi,{row:e,cameraName:M(e.deviceId),nowMs:e.lastSeen,selected:h.has(Xa(e.deviceId,e.trackId)),onToggleSelect:U,onOpenDetail:v,...t?.thumbnailProvenance===void 0?{}:{provenance:t.thumbnailProvenance},footer:d(lo,{track:e,report:t,analyzing:R.isFetching})},Xa(e.deviceId,e.trackId))})}),_&&d(Wi,{row:_,cameraName:M(_.deviceId),deleteAvailable:Ni,onClose:()=>v(null),onDeleted:()=>{v(null),P.refetch()},onFlagsChanged:e=>{e.debug||(v(null),P.refetch())}})]})}var fo=200,po=3e4,mo=[];function ho(e){let t=G(),n=e.deviceIds.length>0,r=[...e.deviceIds].sort((e,t)=>e-t),{data:i,isLoading:a}=s({queryKey:[`events-feed`,r,e.since,e.until,e.minImportance??null,e.classFilter??null],enabled:n,staleTime:po,refetchInterval:po,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEventsBatch.query({deviceIds:r,since:e.since,until:e.until,limit:fo,...e.minImportance===void 0?{}:{minImportance:e.minImportance},...e.classFilter===void 0?{}:{classFilter:e.classFilter}})).map(e=>e.events.map(t=>({...t,deviceId:e.deviceId})))});return{rows:Jr(qr(i??mo),`importance`),isLoading:n&&a}}e();var go=[`events-feed`],_o=2e3;function vo(e){let n=l(),a=e?.paused===!0,o=u(n);o.current=n;let s=u(a);s.current=a;let[c,d]=r(!1),f=i(()=>{o.current.invalidateQueries({queryKey:go})},[]),p=u(void 0);p.current||=Br({delayMs:_o,invalidate:()=>{s.current?d(!0):f()}}),t(()=>()=>p.current?.cancel(),[]),t(()=>{a||!c||(d(!1),f())},[a,c,f]);let m=i(()=>{d(!1),f()},[f]);return gt(ae.PipelineAnalyticsDetectionEvent,()=>{p.current?.trigger()}),gt(ae.PipelineAnalyticsTrackEnded,()=>{p.current?.trigger()}),{pending:c,refreshNow:m}}e();function yo({groups:e,selected:t,onChange:i,loading:o=!1}){let{t:s}=X(),[c,l]=r(!1),[u,f]=r(``),[p,m]=r(new Set),h=u.trim().toLowerCase(),g=e=>h.length===0||be(e,s).toLowerCase().includes(h),_=n(()=>e.map(e=>({macro:e.macro,subs:e.subs.filter(t=>g(t)||g(e.macro))})).filter(e=>g(e.macro)||e.subs.length>0),[e,h]),v=e=>m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),y=e=>{let n=new Set(t),r=t.has(e.macro.kind)&&e.subs.every(e=>t.has(e.kind)),a=[e.macro.kind,...e.subs.map(e=>e.kind)];if(r)for(let e of a)n.delete(e);else for(let e of a)n.add(e);i(n)},b=e=>{let n=new Set(t);n.has(e)?n.delete(e):n.add(e),i(n)},x=()=>i(new Set),S=t.size;return a(`div`,{className:`relative`,children:[a(`button`,{type:`button`,onClick:()=>l(e=>!e),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${S>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[d(D,{className:`h-3.5 w-3.5`}),S>0?s(`detectionIntelligence.eventKindFilter.kinds`,`Kinds ({{value1}})`,{value1:String(S)}):s(`detectionIntelligence.eventKindFilter.kinds2`,`Kinds`),d(K,{className:`h-3 w-3`})]}),c&&a(`div`,{className:`absolute z-20 mt-1 max-h-80 w-64 overflow-auto rounded-md border border-border bg-surface p-2 shadow-lg`,children:[a(`div`,{className:`mb-2 flex items-center gap-1 rounded border border-border px-1.5`,children:[d(z,{className:`h-3.5 w-3.5 text-foreground-subtle`}),d(`input`,{type:`text`,value:u,onChange:e=>f(e.target.value),placeholder:s(`detectionIntelligence.eventKindFilter.searchKinds`,`Search kinds…`),className:`w-full bg-transparent py-1 text-xs outline-none`}),S>0&&d(`button`,{type:`button`,onClick:x,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:s(`detectionIntelligence.eventKindFilter.clear`,`Clear`)})]}),_.length===0&&d(`div`,{className:`px-1 py-2 text-[11px] text-foreground-subtle`,children:o?s(`detectionIntelligence.eventKindFilter.loadingKinds`,`Loading kinds…`):h.length>0?s(`detectionIntelligence.eventKindFilter.noKindMatchesThatSearch`,`No kind matches that search.`):s(`detectionIntelligence.eventKindFilter.theseCamerasAdvertiseNoEvent`,`These cameras advertise no event kinds.`)}),_.map(e=>{let n=Ue(e.macro.iconId),r=p.has(e.macro.kind)||h.length>0,i=t.has(e.macro.kind);return a(`div`,{className:`mb-0.5`,children:[a(`div`,{className:`flex items-center gap-1`,children:[e.subs.length>0?d(`button`,{type:`button`,onClick:()=>v(e.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":s(`detectionIntelligence.eventKindFilter.expand`,`Expand`),children:d(r?K:re,{className:`h-3 w-3`})}):d(`span`,{className:`w-3`}),a(`label`,{className:`flex flex-1 cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[d(`input`,{type:`checkbox`,checked:i,onChange:()=>y(e),className:`accent-primary`}),d(n,{className:`h-3.5 w-3.5`,style:{color:e.macro.color}}),d(`span`,{className:`font-medium`,children:be(e.macro,s)})]})]}),r&&e.subs.map(e=>{let n=Ue(e.iconId);return a(`label`,{className:`ml-5 flex cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[d(`input`,{type:`checkbox`,checked:t.has(e.kind),onChange:()=>b(e.kind),className:`accent-primary`}),d(n,{className:`h-3.5 w-3.5`,style:{color:e.color}}),d(`span`,{children:be(e,s)})]},e.kind)})]},e.macro.kind)})]})]})}function bo(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 xo(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var So=new Set([`detection`,`package`]);function Co(e,t){return[...bo(e,t).values()].filter(e=>e.parentKind===null&&So.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function wo(e,t){let n=bo(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,xo(e,n))}return[...i.values()].map(e=>({macro:e,subs:[...r.get(e.kind)??[]].sort((e,t)=>e.label.localeCompare(t.label))})).sort((e,t)=>e.macro.label.localeCompare(t.macro.label))}e();function To(){let[e,n]=r(!1),a=u(null),[o,s]=r(0),c=i(e=>{a.current!==e&&(a.current=e,s(e=>e+1))},[]);return t(()=>{let e=a.current;if(!e||typeof IntersectionObserver>`u`){n(!1);return}let t=new IntersectionObserver(e=>{let t=e[e.length-1];t&&n(!t.isIntersecting)},{rootMargin:`64px 0px 0px 0px`,threshold:0});return t.observe(e),()=>t.disconnect()},[o]),{ref:c,scrolledPast:e}}e();var Eo=[`events-feed`],Do=60,Oo=[{value:`importance`,labelKey:`detectionIntelligence.eventsSection.sortImportance`,icon:ce},{value:`time`,labelKey:`detectionIntelligence.eventsSection.sortRecent`,icon:N}];function ko(){let{t:e}=X(),i=l(),o=Oe(),s=je(),[u,f]=r(Rn),[p,m]=r(new Set),[h,g]=r(new Set),[_,v]=r(0),[y,b]=r(`time`),[S,C]=r(new Set),[w,T]=r(null),[E,D]=r(()=>Date.now());t(()=>{let e=setInterval(()=>D(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:O,until:k}=n(()=>Qr({fromMs:u.fromMs,toMs:u.toMs},E),[u.fromMs,u.toMs,E]),A=To(),{pending:j,refreshNow:M}=vo({paused:w!==null||S.size>0||A.scrolledPast}),{data:N=[]}=kt({isCamera:!0,projection:`slim`}),P=n(()=>N.map(e=>e.id),[N]),{data:F,isLoading:I}=ve({deviceIds:P},{enabled:P.length>0,staleTime:5*6e4}),R=n(()=>wo(F??[],p),[F,p]),z=Ii(),B=z.isPending,{rows:V,isLoading:H}=ho({deviceIds:P,since:O,until:k,minImportance:_>0?_:void 0,classFilter:h.size===1?[...h][0]:void 0}),U=n(()=>{let e=new Map;for(let t of N??[])e.set(t.id,t.name);return e},[N]),G=t=>U.get(t)??e(`detectionIntelligence.cameraFallback`,{id:String(t)}),te=n(()=>Gn(V).map(e=>({id:e,name:G(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[V,U]),ne=n(()=>Jr(Yr(V,{cameras:p,classes:h,minImportance:_}),y),[V,p,h,_,y]),K=tr(ne,Do,n(()=>JSON.stringify([[...p].sort((e,t)=>e-t),[...h].sort(),_,y,O,k]),[p,h,_,y,O,k])),re=()=>{i.invalidateQueries({queryKey:Eo})},ie=()=>C(new Set);function q(e){C(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function ae(){if(S.size===0||!Ni)return;let t=Zr(V,S),n=[...t.values()].reduce((e,t)=>e+t.length,0);n!==0&&(async()=>{await s({title:e(`detectionIntelligence.eventsSection.deleteTitle`,{count:n}),message:e(`detectionIntelligence.eventsSection.deleteMessage`,{count:n}),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&oe(t)})()}function oe(t){let n=[...t];Promise.allSettled(n.map(([e,t])=>z.mutateAsync({deviceId:e,trackIds:t}))).then(t=>{re();let r=[],i=new Set;if(t.forEach((e,t)=>{let a=n[t];if(!a)return;let[o,s]=a;if(e.status===`fulfilled`)for(let e of s)i.add(Xr(o,e));else r.push(o)}),C(e=>{let t=new Set(e);for(let e of i)t.delete(e);return t}),r.length>0){let t=r.map(e=>G(e)).join(`, `);o({title:e(`detectionIntelligence.eventsSection.someTracksWereNotDeleted`,`Some tracks were not deleted`),message:e(`detectionIntelligence.eventsSection.failedToDeleteTracksOn`,`Failed to delete tracks on: {{names}}. They remain selected — retry, or check the server logs.`,{names:t}),variant:`danger`})}})}let se=ne.length!==V.length;return a(`div`,{className:`relative space-y-3`,children:[a(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d(lr,{onChange:f}),d(sr,{cameras:te,selected:p,onChange:m}),d(yo,{groups:R,selected:h,onChange:g,loading:I}),a(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[d(`span`,{children:e(`detectionIntelligence.eventsSection.minScore`,`Min score`)}),d(`input`,{type:`range`,min:0,max:1,step:.05,value:_,onChange:e=>v(Number(e.target.value)),className:`h-1 w-24 cursor-pointer accent-primary`,"aria-label":e(`detectionIntelligence.eventsSection.minimumImportance`,`Minimum importance`)}),d(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(_*100)})]}),d(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Oo.map(t=>{let n=t.icon;return a(`button`,{type:`button`,onClick:()=>b(t.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${y===t.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[d(n,{className:`h-3.5 w-3.5`}),` `,e(t.labelKey)]},t.value)})}),!H&&d(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:se?e(`detectionIntelligence.eventsSection.ofEvents`,`{{value1}} of {{value2}} events`,{value1:String(ne.length),value2:String(V.length)}):e(`detectionIntelligence.eventsSection.eventCount`,{count:ne.length})})]}),S.size>0&&a(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[d(`span`,{className:`text-xs font-medium text-foreground`,children:e(`common.selectedCount`,{count:S.size})}),a(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[d(`span`,{title:Ni?void 0:`Track deletion arrives with the next server update`,children:a(J,{variant:`secondary`,onClick:ae,disabled:!Ni||B,children:[B?d(W,{className:`h-3.5 w-3.5 animate-spin`}):d(x,{className:`h-3.5 w-3.5`}),` `,e(`common.delete`,`Delete`)]})}),d(J,{variant:`ghost`,onClick:ie,disabled:B,children:d(L,{className:`h-3.5 w-3.5`})})]})]}),j&&d(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:d(`button`,{type:`button`,onClick:M,className:`rounded-full border border-primary/40 bg-surface px-3 py-1 text-[11px] font-medium text-primary shadow-sm hover:bg-primary/10`,children:e(`detectionIntelligence.eventsSection.newEventsRefresh`,`New events — refresh`)})}),H?d(pt,{status:`pending`,pendingMessage:`Loading events…`,testId:`events-grid`}):ne.length===0?d(Ke,{icon:ee,title:se?e(`detectionIntelligence.eventsSection.nothingMatchesTheFilter`,`Nothing matches the filter`):e(`detectionIntelligence.eventsSection.noKeyEventsInThis`,`No key events in this window`),description:se?e(`detectionIntelligence.eventsSection.widenTheDateRangeClear`,`Widen the date range, clear cameras or kinds, or lower the min score.`):e(`detectionIntelligence.eventsSection.capturedTracksAppearHereWhen`,`Captured tracks appear here when the pipeline scores a key event.`)}):a(c,{children:[d(`div`,{ref:A.ref,"aria-hidden":!0,className:`h-0`}),d(pt,{status:`ready`,testId:`events-grid`,children:K.pageItems.map(e=>d(oi,{row:e,cameraName:G(e.deviceId),nowMs:E,selected:S.has(Xr(e.deviceId,e.trackId)),onToggleSelect:q,onOpenDetail:T},Xr(e.deviceId,e.trackId)))}),d(ir,{currentPage:K.page,totalItems:K.totalItems,pageSize:K.pageSize,onPageChange:K.setPage,itemNoun:`events`})]}),w&&d(Wi,{row:w,cameraName:G(w.deviceId),deleteAvailable:Ni,onClose:()=>T(null),onDeleted:()=>{re(),T(null)},onFlagsChanged:e=>{T(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug,favourited:e.favourited}:t)}})]})}var Ao=`/addon/training`;function jo(){let{t:e}=X(),t=Ft();return a(et,{className:`flex flex-col gap-3 border-border bg-surface p-3 sm:flex-row sm:items-center sm:gap-4`,"data-testid":`events-feed-retrain-cta`,children:[a(`div`,{className:`flex min-w-0 flex-1 items-start gap-2.5`,children:[d(g,{className:`mt-0.5 h-4 w-4 shrink-0 text-primary`,"aria-hidden":!0}),a(`div`,{className:`min-w-0 space-y-0.5`,children:[d(`p`,{className:`text-xs font-medium text-foreground`,children:e(`detectionIntelligence.retrainTabCallout.trainingFromThisFeed`,`Training from this feed`)}),d(`p`,{className:`${ie} leading-relaxed`,children:e(`detectionIntelligence.retrainTabCallout.markATrackWithThe`,`Mark a track with the graduation-cap control on its card. On Training you correct frames, build collections, and start cloud fine-tunes.`)})]})]}),d(J,{variant:`outline`,size:`sm`,className:`shrink-0 self-start sm:self-center`,onClick:()=>t(Ao),children:e(`detectionIntelligence.retrainTabCallout.openTraining`,`Open Training`)})]})}e();var Mo=50,No=350,Po=[{value:`loose`,labelKey:`detectionIntelligence.semanticEventSearch.looseLabel`,titleKey:`detectionIntelligence.semanticEventSearch.looseTitle`},{value:`balanced`,labelKey:`detectionIntelligence.semanticEventSearch.balancedLabel`,titleKey:`detectionIntelligence.semanticEventSearch.balancedTitle`},{value:`strict`,labelKey:`detectionIntelligence.semanticEventSearch.strictLabel`,titleKey:`detectionIntelligence.semanticEventSearch.strictTitle`}];function Fo(e){let t=String(e.id);return{id:t,trackId:e.trackId??t,deviceId:e.deviceId,timestamp:e.timestamp,className:e.className,label:e.label,subLabel:e.subLabel,importance:e.importance??0,bestEventId:t,mediaId:e.keyFrameMediaId??e.mediaId,windowMs:void 0}}function Io({onActiveChange:e}){let{t:i}=X(),[o,s]=r(``),[c,l]=r(`loose`),[u,f]=r(null),[p,m]=r(null),[h,g]=r(null),_=Le(o,No).trim(),v=_.length>0;t(()=>{e(v)},[v,e]);let[y,b]=r(()=>Date.now());t(()=>{let e=setInterval(()=>b(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:x=[]}=kt({isCamera:!0,projection:`slim`}),S=n(()=>{let e=new Map;for(let t of x)e.set(t.id,t.name);return e},[x]),C=e=>S.get(e)??i(`detectionIntelligence.cameraFallback`,{id:String(e)}),w=n(()=>x.map(e=>e.id),[x]),{data:T}=ve({deviceIds:w},{enabled:w.length>0,staleTime:5*6e4}),E=n(()=>Co(T??[],new Set(p===null?[]:[p])),[T,p]);t(()=>{u!==null&&(E.some(e=>e.kind===u)||f(null))},[E,u]);let{data:D,isFetching:O,isError:k,error:A}=ot({text:_,strictness:c,limit:Mo,classFilter:u??void 0,deviceId:p??void 0},{enabled:v}),j=n(()=>[...D??[]].sort((e,t)=>t.score-e.score).map(e=>({...Fo(e),score:e.score})),[D]);function M(e){f(t=>t===e?null:e)}return a(`div`,{className:`space-y-3`,children:[a(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-3`,children:[a(`div`,{className:`flex flex-wrap items-center gap-2`,children:[a(`div`,{className:`relative min-w-[16rem] flex-1`,children:[d(z,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),d(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:i(`detectionIntelligence.semanticEventSearch.semanticSearchDescribeWhatYou`,`Semantic search — describe what you're looking for…`),className:`h-9 w-full rounded-md border border-border bg-background pl-8 pr-8 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary`,"aria-label":i(`detectionIntelligence.semanticEventSearch.semanticEventSearch`,`Semantic event search`)}),o&&d(`button`,{type:`button`,onClick:()=>s(``),className:`absolute right-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":i(`detectionIntelligence.semanticEventSearch.clearSearch`,`Clear search`),children:d(L,{className:`h-3.5 w-3.5`})})]}),O&&v&&d(W,{className:`h-4 w-4 shrink-0 animate-spin text-foreground-subtle`})]}),a(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[d(`div`,{className:`flex items-center gap-1`,children:E.map(e=>d(`button`,{type:`button`,onClick:()=>M(e.kind),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${u===e.kind?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:be(e)},e.kind))}),a(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[d(`span`,{children:i(`detectionIntelligence.semanticEventSearch.camera`,`Camera`)}),d(ke,{value:p===null?``:String(p),onChange:e=>m(e.target.value===``?null:Number(e.target.value)),className:`h-7 text-xs`,"aria-label":i(`detectionIntelligence.semanticEventSearch.filterByCamera`,`Filter by camera`),options:[{value:``,label:i(`detectionIntelligence.semanticEventSearch.all`,`All`)},...x.map(e=>({value:String(e.id),label:e.name}))]})]}),a(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[d(`span`,{children:i(`detectionIntelligence.semanticEventSearch.match`,`Match`)}),d(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Po.map(e=>d(`button`,{type:`button`,onClick:()=>l(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${c===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:i(e.titleKey),children:i(e.labelKey)},e.value))})]}),v&&!O&&!k&&d(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:i(`common.matches`,{count:j.length})})]})]}),v&&a(`div`,{className:`space-y-3`,children:[k&&a(`p`,{className:`py-4 text-xs text-danger`,children:[i(`detectionIntelligence.semanticEventSearch.searchFailed`,`Search failed:`),` `,A instanceof Error?A.message:i(`detectionIntelligence.semanticEventSearch.unknownError`,`unknown error`),`. Check that the CLIP embedding step is enabled.`]}),!k&&O&&j.length===0&&d(pt,{status:`pending`,pendingMessage:`Searching…`,testId:`semantic-events-grid`}),!k&&!O&&j.length===0&&d(pt,{status:`empty`,emptyMessage:i(`detectionIntelligence.semanticEventSearch.noSemanticMatchesForTry`,`No semantic matches for “{{debounced}}”. Try a looser match threshold or a different phrasing.`,{debounced:_}),testId:`semantic-events-grid`}),!k&&j.length>0&&d(pt,{status:`ready`,testId:`semantic-events-grid`,children:j.map(e=>d(oi,{row:e,cameraName:C(e.deviceId),nowMs:y,score:e.score,onOpenDetail:g},e.id))})]}),h&&d(Wi,{row:h,cameraName:C(h.deviceId),deleteAvailable:Ni,onClose:()=>g(null),onDeleted:()=>g(null)})]})}e();function Lo(e,t){let n=Math.max(0,Math.round((e-t)/6e4));if(n<1)return Y.t(`helpers.relativeTime.justNow`);if(n<60)return`${String(n)}m`;let r=Math.floor(n/60);return`${String(r)}h ${String(n%60)}m`}function Ro({row:e,cameraName:t,nowMs:n}){let{t:r}=X(),i=Vt(e.keyFrameMediaId===void 0?void 0:Wt(e.keyFrameMediaId));return a(`div`,{className:`flex flex-col overflow-hidden rounded-md border border-border bg-surface`,children:[a(`div`,{className:`relative aspect-video overflow-hidden bg-surface-hover`,children:[i.src?d(`img`,{src:i.src,alt:r(`detectionIntelligence.stationarySection.parkedOn`,`Parked {{className}} on {{cameraName}}`,{className:e.className,cameraName:t}),className:`h-full w-full object-cover`}):d(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:d(ue,{className:`h-6 w-6`})}),d(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-medium capitalize text-white`,children:e.label??e.className})]}),a(`div`,{className:`flex flex-col gap-0.5 p-1.5`,children:[d(`span`,{className:`truncate text-[11px] text-foreground`,children:t}),d(`span`,{className:`text-[10px] text-foreground-subtle`,children:r(`common.parkedSince`,{since:Lo(n,e.becameStationaryAt)})})]})]})}function zo(){let{t:e}=X(),[t,i]=r(!1),o=Date.now(),{data:s=[]}=kt({isCamera:!0,projection:`slim`}),c=n(()=>s.map(e=>e.id),[s]),l=n(()=>{let e=new Map;for(let t of s)e.set(t.id,t.name);return e},[s]),{rows:u,unreadableCount:f}=Bt(c);return u.length===0&&f===0?null:a(`div`,{className:`rounded-md border border-border bg-surface/40`,children:[a(`button`,{type:`button`,onClick:()=>i(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,children:[d(t?K:re,{className:`h-4 w-4 text-foreground-subtle`}),d(ue,{className:`h-4 w-4 text-foreground-subtle`}),d(`span`,{className:`text-sm font-semibold text-foreground`,children:e(`detectionIntelligence.stationarySection.stationary`,`Stationary`)}),d(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:u.length}),d(`span`,{className:`ml-2 text-[11px] text-foreground-subtle`,children:e(`detectionIntelligence.stationarySection.parkedObjectsKeptOutOf`,`Parked objects — kept out of the event feed`)}),f>0?d(`span`,{className:`ml-2 text-[11px] text-warning`,children:e(`detectionIntelligence.stationarySection.unreadable`,{count:f})}):null]}),t&&d(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:u.map(e=>d(Ro,{row:e,cameraName:l.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:o},e.id))})]})}e();function Bo(){let[e,t]=r(!1);return a(`section`,{className:`space-y-3`,children:[d(jo,{}),d(Io,{onActiveChange:t}),!e&&d(zo,{}),!e&&d(ko,{})]})}function Vo(){let{t:e}=X(),[t]=Rt();return t.get(`section`)===`retrain`?d(It,{to:`/addon/training`,replace:!0}):d(zt,{sectionsOnly:!0,paramName:`section`,defaultSection:`feed`,sectionsLabel:`Events sections`,sections:[{id:`feed`,label:e(`events.feed`,`Feed`),content:d(Bo,{})},{id:`debug`,label:e(`events.debug`,`Debug`),content:d(uo,{})}]})}function Ho(e){return e==null?null:e.cropUrl!==void 0&&e.cropUrl.length>0?e.cropUrl:e.base64!==void 0&&e.base64.length>0?`data:image/jpeg;base64,${e.base64}`:null}e();var Uo=[[`plateGallery`]];function Wo({plateIds:e,vehicles:t,onDone:n}){let{t:i}=X(),o=l(),s=Ot(),c=Ct(),[u,f]=r(``),[p,m]=r(!1),[h,g]=r(null),_=e!==null&&e.length>0,v=e?.length??0;function y(){m(!1),f(``),g(null)}function b(){y(),n()}function x(t){!e||e.length===0||s.mutate({plateIds:[...e],vehicleId:t},{onSettled:()=>{o.invalidateQueries({queryKey:Uo}),b()}})}function S(){!e||!u.trim()||c.mutate({name:u.trim()},{onSuccess:e=>{e?.id&&x(e.id)},onError:()=>{o.invalidateQueries({queryKey:Uo}),b()}})}let C=s.isPending||c.isPending;return d(vt,{open:_,onOpenChange:e=>!e&&b(),children:a(ct,{children:[a(Et,{children:[d(Ze,{children:v>1?i(`detectionIntelligence.assignPlateDialog.assignPlatesToVehicle`,`Assign {{value1}} plates to vehicle`,{value1:String(v)}):i(`detectionIntelligence.assignPlateDialog.assignPlateToVehicle`,`Assign plate to vehicle`)}),d(Ye,{children:i(`detectionIntelligence.assignPlateDialog.selectAnExistingVehicleOr`,`Select an existing vehicle or create a new one.`)})]}),d(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:t.map(e=>a(`button`,{type:`button`,onClick:()=>g(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${h===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[d(`span`,{className:`font-medium`,children:e.name}),d(`span`,{className:`ml-2 text-foreground-subtle`,children:i(`detectionIntelligence.assignPlateDialog.plates`,{count:e.sampleCount})})]},e.id))}),p?d(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:d(Ee,{placeholder:i(`detectionIntelligence.assignPlateDialog.newVehicleName`,`New vehicle name…`),value:u,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&S()},autoFocus:!0,className:`flex-1`})}):d(`button`,{type:`button`,onClick:()=>{g(null),m(!0)},className:`mt-2 w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle hover:border-primary hover:text-primary transition-colors`,children:i(`detectionIntelligence.assignPlateDialog.newVehicle`,`+ New vehicle…`)}),a(xt,{children:[d(J,{variant:`secondary`,onClick:b,disabled:C,children:i(`common.cancel`,`Cancel`)}),p?a(J,{variant:`primary`,onClick:S,disabled:C||!u.trim(),children:[C&&d(W,{className:`h-3.5 w-3.5 animate-spin`}),i(`detectionIntelligence.assignPlateDialog.createAssign`,`Create & assign`)]}):a(J,{variant:`primary`,onClick:()=>h&&x(h),disabled:C||!h,children:[C&&d(W,{className:`h-3.5 w-3.5 animate-spin`}),v>1?i(`detectionIntelligence.assignCount`,{count:v}):i(`common.assign`)]})]})]})})}e();var Go=[[`plateGallery`]];function Ko(e){let[n,i]=r(null),[a,o]=r(null),[s,c]=r(!1);return t(()=>{if(i(null),o(null),c(!1),e===void 0)return;let t=!1,n=null;return(async()=>{try{let r=await Ut(Wt(e));if(t)return;n=URL.createObjectURL(r),i(n)}catch{t||c(!0)}})(),()=>{t=!0,n&&URL.revokeObjectURL(n)}},[e]),t(()=>{if(!n)return;let e=new Image;return e.onload=()=>o({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>c(!0),e.src=n,()=>{e.onload=null,e.onerror=null}},[n]),{frameSrc:n,naturalWidth:a?.width??null,naturalHeight:a?.height??null,failed:s}}function qo(e){let t=e.filter(e=>e.url.length>0);return t.length===0?null:t.find(e=>/crop|plate/i.test(e.kind))??t[0]}function Jo({label:e,value:t,mono:n}){return a(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[d(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),d(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono`:``}`,title:t,children:t})]})}function Yo({box:e}){let{t}=X();return d(`div`,{className:`pointer-events-none absolute rounded-[3px] border-2 border-primary shadow-[0_0_0_9999px_rgba(0,0,0,0.28)]`,style:{left:`${String(e.x*100)}%`,top:`${String(e.y*100)}%`,width:`${String(e.width*100)}%`,height:`${String(e.height*100)}%`},children:d(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:t(`detectionIntelligence.plateDetailPanel.plate`,`Plate`)})})}function Xo({plate:e,cameraName:i,onClose:o,onAssign:s,onUnassign:c,onDelete:u,actionsPending:f}){let{t:p}=X(),m=l(),{data:h,isFetching:g}=yt({plateId:e?.plateId??``},{enabled:e!==null}),v=_t(),[b,S]=r(`frame`),[C,w]=r(!1),[E,D]=r(``),{frameSrc:O,naturalWidth:k,naturalHeight:A,failed:j}=Ko(e?.keyFrameMediaId);t(()=>{w(!1),D(``),S(`frame`)},[e?.plateId]);let N=n(()=>{let t=qo(h??[]);return t?t.url:Ho(e)},[h,e]),P=n(()=>!e?.plateBbox||k===null||A===null?null:dr(e.plateBbox,k,A),[e?.plateBbox,k,A]);if(e===null)return null;let F=e.keyFrameMediaId!==void 0&&!j,I=F&&b===`frame`,R=e.assigned?e.vehicleName??`Assigned`:e.recognizedVehicleId?`${e.vehicleName??`Recognized`} (suggested)`:`Unassigned`,z=`${String(Math.round(e.score*100))}%${e.corrected?` · corrected`:``}`;function B(){e&&(D(e.text),w(!0))}function V(){if(!e)return;let t=E.trim().toUpperCase();if(!t||t===e.text){w(!1);return}v.mutate({plateId:e.plateId,text:t},{onSettled:()=>{m.invalidateQueries({queryKey:Go}),w(!1)}})}return d(vt,{open:!0,onOpenChange:e=>!e&&o(),children:a(ct,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":p(`detectionIntelligence.plateDetailPanel.plateDetail`,`Plate detail`),className:`flex h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:h-auto md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[d(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:a(`div`,{className:`min-w-0`,children:[d(`div`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:e.text||p(`detectionIntelligence.plateDetailPanel.plateDetail`,`Plate detail`)}),d(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:i})]})}),a(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[F&&a(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[a(`button`,{type:`button`,onClick:()=>S(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${b===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[d(U,{className:`h-3.5 w-3.5`}),` `,p(`detectionIntelligence.detailPanel.fullFrame`)]}),a(`button`,{type:`button`,onClick:()=>S(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${b===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[d(ge,{className:`h-3.5 w-3.5`}),` `,p(`detectionIntelligence.detailPanel.crop`)]})]}),I&&O?d(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:d(pr,{src:O,alt:p(`detectionIntelligence.plateDetailPanel.fullFrameWithDetectedPlate`,`Full frame with detected plate`),fit:`natural`,className:`w-full`,overlay:P?d(Yo,{box:P}):void 0})}):N?a(`div`,{className:`relative aspect-[2/1] w-full overflow-hidden rounded-lg border border-border bg-background`,children:[d(pr,{src:N,alt:p(`detectionIntelligence.plateDetailPanel.detectedPlate`,`Detected plate`),className:`h-full w-full`}),g&&d(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:d(W,{className:`h-3.5 w-3.5 animate-spin`})})]}):a(`div`,{className:`flex aspect-[2/1] w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[d(M,{className:`h-8 w-8 text-warning/70`}),d(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:p(`detectionIntelligence.plateDetailPanel.noImage`,`No image`)}),d(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:p(`detectionIntelligence.plateDetailPanel.theCropMediaForThis`,`The crop media for this plate could not be resolved. Safe to delete.`)})]}),d(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-2`,children:a(`div`,{className:`flex items-center justify-between gap-3`,children:[d(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:p(`detectionIntelligence.plateDetailPanel.plateText`,`Plate text`)}),C?a(`div`,{className:`flex min-w-0 flex-1 items-center justify-end gap-1.5`,children:[d(Ee,{value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`&&V(),e.key===`Escape`&&w(!1)},className:`h-7 max-w-[10rem] text-right font-mono text-xs uppercase`,autoFocus:!0}),d(`button`,{type:`button`,onClick:V,disabled:v.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":p(`detectionIntelligence.plateDetailPanel.saveCorrectedText`,`Save corrected text`),children:v.isPending?d(W,{className:`h-3.5 w-3.5 animate-spin`}):d(T,{className:`h-3.5 w-3.5`})}),d(`button`,{type:`button`,onClick:()=>w(!1),className:`text-foreground-subtle hover:text-foreground`,"aria-label":p(`common.cancel`,`Cancel`),children:d(L,{className:`h-3.5 w-3.5`})})]}):a(`button`,{type:`button`,onClick:B,className:`group flex min-w-0 items-center gap-1.5`,title:p(`detectionIntelligence.plateDetailPanel.correctTheOcrReading`,`Correct the OCR reading`),children:[d(`span`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:e.text||`—`}),d(y,{className:`h-3 w-3 shrink-0 text-foreground-subtle group-hover:text-foreground`})]})]})}),a(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[d(Jo,{label:p(`detectionIntelligence.plateDetailPanel.camera`,`Camera`),value:i}),d(Jo,{label:p(`detectionIntelligence.plateDetailPanel.captured`,`Captured`),value:Xn(e.timestamp)}),d(Jo,{label:p(`detectionIntelligence.plateDetailPanel.confidence`,`Confidence`),value:z}),d(Jo,{label:p(`detectionIntelligence.plateDetailPanel.vehicle`,`Vehicle`),value:R}),d(Jo,{label:p(`detectionIntelligence.plateDetailPanel.track`,`Track`),value:e.trackId,mono:!0})]})]}),a(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[e.assigned?a(J,{variant:`secondary`,onClick:()=>c(e.plateId),disabled:f,children:[d(me,{className:`h-3.5 w-3.5`}),` `,p(`detectionIntelligence.detailPanel.detach`)]}):a(J,{variant:`primary`,onClick:()=>s(e.plateId),disabled:f,children:[d(_,{className:`h-3.5 w-3.5`}),` `,p(`common.assign`)]}),a(J,{variant:`secondary`,onClick:()=>u(e.plateId),disabled:f,children:[d(x,{className:`h-3.5 w-3.5`}),` `,p(`common.delete`)]})]})]})})}e();var Zo=[[`plateGallery`]],Qo=500,$o=120;function es({plate:e,cameraName:t,nowMs:n,selected:r,onToggleSelect:i,onAssign:o,onOpenDetail:s}){let{t:c}=X(),u=l(),f=nt(),p=st(),m=()=>{u.invalidateQueries({queryKey:Zo})},h=()=>s(e.plateId),g=Ho(e);return a(`div`,{className:`relative flex flex-col overflow-hidden rounded-md border bg-surface ${r?`border-primary ring-1 ring-primary`:`border-border`}`,children:[a(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[g===null?a(`button`,{type:`button`,onClick:h,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:c(`detectionIntelligence.recentPlates.noCropImageThePlate`,`No crop image — the plate's crop media is missing. Safe to delete.`),children:[d(M,{className:`h-7 w-7 text-warning/70`}),d(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:c(`detectionIntelligence.recentPlates.noCrop`,`No crop`)})]}):d(`img`,{src:g,alt:c(`detectionIntelligence.recentPlates.plateFrom`,`Plate {{text}} from {{cameraName}}`,{text:e.text,cameraName:t}),onClick:h,className:`h-full w-full cursor-zoom-in object-cover`}),d(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),i(e.plateId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":r?c(`detectionIntelligence.recentPlates.deselect`,`Deselect`):c(`detectionIntelligence.recentPlates.select`,`Select`),children:r?d(fe,{className:`h-4 w-4 text-primary`}):d(O,{className:`h-4 w-4`})}),e.corrected&&a(`span`,{className:`absolute right-0 top-0 z-10 flex items-center gap-0.5 rounded-bl-md bg-primary/80 px-1 py-0.5 text-[8px] font-semibold uppercase tracking-wide text-white`,title:c(`detectionIntelligence.recentPlates.manuallyCorrected`,`Manually corrected`),children:[d(pe,{className:`h-3 w-3`}),` `,c(`detectionIntelligence.recentPlates.fixed`)]})]}),a(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[d(`p`,{className:`truncate font-mono text-xs font-bold tracking-wide text-foreground`,title:e.text,children:e.text||`—`}),d(`p`,{className:`truncate text-[10px] text-foreground-subtle`,title:t,children:t}),d(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:Jn(e.timestamp,n)}),e.vehicleName&&d(`p`,{className:`truncate text-[10px] font-medium text-primary`,title:e.vehicleName,children:e.vehicleName})]}),a(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[e.assigned?d(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),f.mutate({plateId:e.plateId},{onSettled:m})},disabled:f.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":c(`detectionIntelligence.recentPlates.detachPlate`,`Detach plate`),title:c(`detectionIntelligence.recentPlates.detach`,`Detach`),children:f.isPending?d(W,{className:`h-4 w-4 animate-spin`}):d(me,{className:`h-4 w-4`})}):d(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(e.plateId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":c(`detectionIntelligence.recentPlates.assignPlateToVehicle`,`Assign plate to vehicle`),title:c(`detectionIntelligence.recentPlates.assignToVehicle`,`Assign to vehicle`),children:d(_,{className:`h-4 w-4`})}),d(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),p.mutate({plateId:e.plateId},{onSettled:m})},disabled:p.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":c(`detectionIntelligence.recentPlates.deletePlate`,`Delete plate`),title:c(`detectionIntelligence.recentPlates.deletePlate`,`Delete plate`),children:p.isPending?d(W,{className:`h-4 w-4 animate-spin`}):d(x,{className:`h-4 w-4`})})]})]})}var ts=[{labelKey:`common.all`,value:`all`},{labelKey:`detectionIntelligence.recentPlates.filterUnassigned`,value:`unassigned`},{labelKey:`detectionIntelligence.recentPlates.filterAssigned`,value:`assigned`}];function ns(e,t){return t===`unassigned`?e.filter(e=>!e.assigned):t===`assigned`?e.filter(e=>e.assigned):e}function rs(){let{t:e}=X(),t=l(),[i,o]=r(`all`),[s,u]=r(Rn),[f,p]=r(new Set),[m,h]=r(new Set),[g,v]=r(null),[y,b]=r(null),{data:S,isLoading:C}=wt({limit:Qo,includeCrops:!1},{refetchInterval:3e4}),{data:w=[]}=dt(),{data:T}=kt({isCamera:!0,projection:`slim`}),E=nt(),D=St(),O=st(),k=Date.now(),A=S??[],j=n(()=>{let e=new Map;for(let t of T??[])e.set(t.id,t.name);return e},[T]),N=t=>j.get(t)??e(`detectionIntelligence.cameraFallback`,{id:String(t)}),P=n(()=>Gn(A).map(e=>({id:e,name:N(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[A,j]),F=n(()=>Wn(Un(ns(A,i),s),f),[A,i,s,f]),I=tr(F,$o,n(()=>JSON.stringify([i,s.fromMs,s.toMs,[...f].sort((e,t)=>e-t)]),[i,s.fromMs,s.toMs,f])),R=n(()=>new Map(A.map(e=>[e.plateId,e])),[A]),z=y===null?null:R.get(y)??null,B=()=>{t.invalidateQueries({queryKey:Zo})},V=()=>h(new Set);function H(e){h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}let U=[...m],G=D.isPending||O.isPending,ee=E.isPending||O.isPending;function te(){U.length!==0&&D.mutate({plateIds:U},{onSettled:()=>{B(),V()}})}function ne(){U.length!==0&&Promise.allSettled(U.map(e=>O.mutateAsync({plateId:e}))).then(()=>{B(),V()})}function K(e){b(null),v([e])}function re(e){E.mutate({plateId:e},{onSettled:B}),b(null)}function ie(e){O.mutate({plateId:e},{onSettled:B}),b(null)}let q=F.length!==A.length;return a(`div`,{className:`relative space-y-3`,children:[a(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d(`div`,{className:`flex items-center gap-1`,children:ts.map(t=>d(`button`,{type:`button`,onClick:()=>o(t.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${i===t.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e(t.labelKey)},t.value))}),d(lr,{onChange:u}),d(sr,{cameras:P,selected:f,onChange:p}),!C&&d(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:q?e(`detectionIntelligence.recentPlates.ofPlates`,`{{value1}} of {{value2}} plates`,{value1:String(F.length),value2:String(A.length)}):e(`detectionIntelligence.recentPlates.plateCount`,{count:F.length})})]}),m.size>0&&a(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[d(`span`,{className:`text-xs font-medium text-foreground`,children:e(`common.selectedCount`,{count:m.size})}),a(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[a(J,{variant:`primary`,onClick:()=>v(U),disabled:G,children:[d(_,{className:`h-3.5 w-3.5`}),` `,e(`common.assign`)]}),a(J,{variant:`secondary`,onClick:te,disabled:G,children:[D.isPending?d(W,{className:`h-3.5 w-3.5 animate-spin`}):d(me,{className:`h-3.5 w-3.5`}),` `,e(`detectionIntelligence.recentPlates.detach`,`Detach`)]}),a(J,{variant:`secondary`,onClick:ne,disabled:G,children:[d(x,{className:`h-3.5 w-3.5`}),` `,e(`common.delete`)]}),d(J,{variant:`ghost`,onClick:V,disabled:G,children:d(L,{className:`h-3.5 w-3.5`})})]})]}),C?d(pt,{status:`pending`,pendingMessage:`Loading plates…`,testId:`plates-grid`}):F.length===0?d(Ke,{icon:M,title:A.length>0?e(`detectionIntelligence.recentPlates.nothingMatchesTheFilter`,`Nothing matches the filter`):e(`detectionIntelligence.recentPlates.noPlatesRecognizedYet`,`No plates recognized yet`),description:A.length>0?e(`detectionIntelligence.recentPlates.widenTheDateRangeOr`,`Widen the date range or clear the camera filter.`):e(`detectionIntelligence.recentPlates.plateReadsAppearHereWhen`,`Plate reads appear here when the detection pipeline OCRs a vehicle.`)}):a(c,{children:[d(pt,{status:`ready`,testId:`plates-grid`,children:I.pageItems.map(e=>d(es,{plate:e,cameraName:N(e.deviceId),nowMs:k,selected:m.has(e.plateId),onToggleSelect:H,onAssign:e=>v([e]),onOpenDetail:b},e.plateId))}),d(ir,{currentPage:I.page,totalItems:I.totalItems,pageSize:I.pageSize,onPageChange:I.setPage,itemNoun:`plates`})]}),d(Xo,{plate:z,cameraName:z?N(z.deviceId):``,onClose:()=>b(null),onAssign:K,onUnassign:re,onDelete:ie,actionsPending:ee}),d(Wo,{plateIds:g,vehicles:w,onDone:()=>{v(null),V()}})]})}e();var is=[[`plateGallery`]];function as({vehicleId:e}){let{t}=X(),n=l(),{data:r,isLoading:i}=Xe({vehicleId:e}),o=At();function s(t){o.mutate({vehicleId:e,sampleId:t.id},{onSettled:()=>{n.invalidateQueries({queryKey:is})}})}return i?a(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[d(W,{className:`h-3.5 w-3.5 animate-spin`}),t(`detectionIntelligence.vehiclesList.loadingPlates`,`Loading plates…`)]}):!r||r.length===0?d(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:t(`detectionIntelligence.vehiclesList.noPlatesYet`,`No plates yet.`)}):d(`div`,{className:`mt-2 grid grid-cols-3 gap-2 sm:grid-cols-4 md:grid-cols-6`,children:r.map(e=>a(`div`,{className:`group relative overflow-hidden rounded-md border border-border bg-surface`,children:[a(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[e.base64?d(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:e.text,className:`h-full w-full object-cover`}):d(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:d(v,{className:`h-6 w-6`})}),d(`button`,{type:`button`,onClick:()=>s(e),disabled:o.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":t(`detectionIntelligence.vehiclesList.removePlateSample`,`Remove plate sample`),children:d(L,{className:`h-4 w-4 text-white`})})]}),d(`p`,{className:`truncate px-1.5 py-1 text-center font-mono text-[11px] font-semibold tracking-wide text-foreground`,title:e.text,children:e.text})]},e.id))})}function os(e){return[{key:`vehicle`,header:Y.t(`detectionIntelligence.vehiclesList.vehicle`,`Vehicle`),sortValue:e=>e.name,render:e=>a(`span`,{className:`flex min-w-0 items-center gap-2`,children:[d(`span`,{className:`h-8 w-12 shrink-0 overflow-hidden rounded border border-border bg-surface-hover`,children:d(qt,{mediaId:e.coverMediaId,base64:e.coverBase64,alt:e.name,className:`h-full w-full object-cover`,placeholder:d(`span`,{className:`flex h-full w-full items-center justify-center`,children:d(v,{className:`h-4 w-4 text-foreground-subtle`})})})}),d(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})]})},{key:`samples`,header:Y.t(`detectionIntelligence.vehiclesList.plates`,`Plates`),align:`center`,nowrap:!0,sortValue:e=>e.sampleCount,render:e=>d(Ce,{variant:`default`,className:`text-[10px]`,children:e.sampleCount})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:t=>a(`span`,{className:`flex items-center justify-end gap-1`,children:[d(ze,{variant:`ghost`,size:`sm`,icon:y,"aria-label":Y.t(`detectionIntelligence.vehiclesList.edit`,`Edit {{name}}`,{name:t.name}),onClick:n=>{n.stopPropagation(),e.onEdit(t)}}),d(ze,{variant:`ghost`,size:`sm`,icon:x,"aria-label":Y.t(`detectionIntelligence.vehiclesList.delete`,`Delete {{name}}`,{name:t.name}),onClick:n=>{n.stopPropagation(),e.onDelete(t)}})]})}]}function ss({mode:e,vehicle:n,onClose:i}){let{t:o}=X(),s=l(),[c,u]=r(e===`edit`?n?.name??``:``),f=Ct(),p=$e();t(()=>{u(e===`edit`?n?.name??``:``)},[e,n?.id,n?.name]);let m=f.isPending||p.isPending,h=c.trim(),g=e===`edit`&&n!==null&&h===n.name,_=m||h.length===0||g;function y(){s.invalidateQueries({queryKey:is})}function b(){if(!_){if(e===`new`){f.mutate({name:h},{onSuccess:()=>{y(),i()}});return}if(n===null){i();return}p.mutate({id:n.id,name:h},{onSuccess:()=>{y(),i()}})}}return d(rt,{open:!0,onClose:i,title:e===`new`?`Add vehicle`:`Edit ${n?.name??`vehicle`}`,icon:v,width:e===`edit`?`xl`:`lg`,testId:`vehicles-vehicle-form`,footer:a(J,{variant:`primary`,size:`sm`,type:`button`,onClick:b,disabled:_,children:[m?d(W,{className:`h-3.5 w-3.5 animate-spin`}):null,e===`new`?o(`common.add`,`Add`):o(`common.save`,`Save`)]}),children:a(`div`,{className:`space-y-4`,children:[d(Mt,{label:o(`detectionIntelligence.vehiclesList.name`,`Name`),required:!0,children:d(Ee,{value:c,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b()},placeholder:o(`detectionIntelligence.vehiclesList.vehicleName`,`Vehicle name…`),autoFocus:!0})}),e===`edit`&&n!==null&&a(`div`,{children:[d(`p`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:o(`detectionIntelligence.vehiclesList.plateSamples`,`Plate samples`)}),d(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:o(`detectionIntelligence.vehiclesList.removeAPlateCropTo`,`Remove a plate crop to drop it from recognition for this vehicle. Assign new plates from Recent recognized plates.`)}),d(as,{vehicleId:n.id})]})]})})}function cs(){let{t:e}=X(),r=l(),i=je(),{data:o,isLoading:s}=dt(),c=Je(),{state:u,openNew:f,openEdit:p,close:m}=jt(),h=o??[],g=bt(h,{searchText:e=>[e.name]}),_=u.mode===`edit`?h.find(e=>e.id===u.id)??null:null;t(()=>{u.mode===`edit`&&!s&&_===null&&m()},[u.mode,s,_,m]);let y=n(()=>os({onEdit:e=>p(e.id),onDelete:t=>{(async()=>{await i({title:e(`detectionIntelligence.vehiclesList.deleteVehicle`,`Delete vehicle`),message:e(`detectionIntelligence.vehiclesList.deleteAndAllItsPlate`,`Delete {{name}} and all its plate samples? This cannot be undone.`,{name:t.name}),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&c.mutate({id:t.id},{onSettled:()=>{r.invalidateQueries({queryKey:is}),u.mode===`edit`&&u.id===t.id&&m()}})})()}}),[i,m,c,u,p,r,e]);if(s)return a(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[d(W,{className:`h-4 w-4 animate-spin`}),e(`detectionIntelligence.vehiclesList.loadingVehicles`,`Loading vehicles…`)]});let b=u.mode===`new`||u.mode===`edit`&&_!==null;return a(`div`,{className:`space-y-2`,children:[d(`div`,{className:`flex flex-wrap items-center gap-2`,children:a(J,{variant:`primary`,size:`sm`,type:`button`,onClick:f,children:[d(V,{className:`h-3.5 w-3.5`}),e(`detectionIntelligence.vehiclesList.addVehicle`,`Add vehicle`)]})}),(h.length>0||g.active)&&d(Tt,{state:g.state,facets:g.facets,labels:{searchPlaceholder:`Search vehicles…`,searchLabel:`Search vehicles`,facetsLabel:`Filter`,clearLabel:`Clear`},onSearch:g.setSearch,onToggleFacet:g.toggleFacet,onClear:g.clear}),g.rows.length===0?d(Ke,{icon:v,title:g.active?e(`detectionIntelligence.vehiclesList.nothingMatchesTheFilter`,`Nothing matches the filter`):e(`detectionIntelligence.vehiclesList.noVehiclesEnrolledYet`,`No vehicles enrolled yet`),description:g.active?e(`detectionIntelligence.vehiclesList.clearTheSearchOrTry`,`Clear the search or try another name.`):e(`detectionIntelligence.vehiclesList.addAVehicleThenAssign`,`Add a vehicle, then assign plate crops from Recent recognized plates.`)}):d(it,{columns:y,rows:g.rows,rowKey:e=>e.id,maxBodyHeight:Ge,emptyMessage:e(`detectionIntelligence.vehiclesList.noVehiclesEnrolledYet2`,`No vehicles enrolled yet.`),onRowClick:e=>p(e.id)}),b&&d(ss,{mode:u.mode===`new`?`new`:`edit`,vehicle:_,onClose:m})]})}e();var ls=[[`plateGallery`]],us=2e3;function ds(){let e=l(),n=u(e);n.current=e;let r=u(void 0);r.current||=Br({delayMs:us,invalidate:()=>{n.current.invalidateQueries({queryKey:ls})}}),t(()=>()=>r.current?.cancel(),[]),gt(ae.PipelineAnalyticsPlateGalleryChanged,()=>{r.current?.trigger()})}function fs(){let{t:e}=X();return ds(),a(`div`,{className:`space-y-3`,children:[d(mt,{headingId:`library-vehicles`,title:e(`plates.vehicles`,`Vehicles`),icon:v,testId:`library-section-vehicles`,children:a(`div`,{className:`${m} space-y-3`,children:[d(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:e(`plates.enrolledVehicleIdentitiesUsedFor`,`Enrolled vehicle identities used for plate recognition. Open a vehicle to rename it or remove plate samples.`)}),d(cs,{})]})}),d(mt,{headingId:`library-recent-plates`,title:e(`plates.recentRecognizedPlates`,`Recent recognized plates`),icon:le,testId:`library-section-recent-plates`,children:a(`div`,{className:`${m} space-y-3`,children:[d(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:e(`plates.licensePlatesReadByThe`,`License plates read by the detection pipeline. Assign them to a vehicle, correct the OCR text, or delete.`)}),d(rs,{})]})})]})}function ps(e){return e.states.length===0?3:e.latched?0:e.verdict===`diverged`?1:e.verdict===`unknown`?2:4}function ms(e){let t=[e.divergedAt,e.restoredAt].filter(e=>typeof e==`number`);return t.length===0?null:Math.max(...t)}function hs(e,t){let n=new Map(e.map(e=>[e.deviceId,e.deviceName])),r=[];for(let e of t)for(let t of e.monitors)r.push({deviceId:e.deviceId,deviceName:n.get(e.deviceId)??`Camera ${e.deviceId}`,monitor:t});return r.toSorted((e,t)=>{let n=ps(e.monitor)-ps(t.monitor);if(n!==0)return n;let r=ms(e.monitor)??-1,i=ms(t.monitor)??-1;if(r!==i)return i-r;let a=e.deviceName.localeCompare(t.deviceName);return a===0?e.monitor.label.localeCompare(t.monitor.label):a})}e();var gs={alarm:`danger`,ok:`success`,unknown:`default`},_s={alarm:`Alarm`,ok:`OK`,unknown:`Unknown`};function vs(e,t){let n=ms(e);return n===null?`—`:Y.t(`scenes.transitionAgo`,{duration:te(Math.max(0,t-n))})}function ys(e){return I(e.monitor).tone}function bs(e){let t=Number(e);return Number.isFinite(t)&&t>0?t:null}function xs(){let{t:e}=X(),i=kt({isCamera:!0,projection:`slim`}),s=n(()=>(i.data??[]).map(e=>({deviceId:e.id,deviceName:e.name})).sort((e,t)=>e.deviceName.localeCompare(t.deviceName)),[i.data]),c=n(()=>s.map(e=>e.deviceId),[s]),l=Kt(c),u=n(()=>hs(s,l.results),[s,l.results]),f=bt(u,{searchText:e=>[e.monitor.label,e.deviceName],facetValue:ys}),{state:p,openNew:m,openEdit:g,close:_}=jt(),[v,y]=r(null);t(()=>{if(p.mode===`new`){y(e=>e??c[0]??null);return}y(null)},[p.mode,c]);let b=p.mode===`edit`?bs(p.id):null,x=b===null?``:s.find(e=>e.deviceId===b)?.deviceName??`#${b}`,S=Date.now(),C=[{key:`label`,header:e(`scenes.scene`,`Scene`),sortValue:e=>e.monitor.label,render:e=>d(`span`,{className:`font-medium`,children:e.monitor.label})},{key:`camera`,header:e(`scenes.camera`,`Camera`),nowrap:!0,sortValue:e=>e.deviceName,render:e=>e.deviceName},{key:`state`,header:e(`scenes.state`,`State`),nowrap:!0,sortValue:e=>ys(e),render:e=>{let t=I(e.monitor);return d(Ce,{variant:gs[t.tone],children:t.text})}},{key:`status`,header:e(`scenes.whatItSays`,`What it says`),notSortableReason:`Status is a live sentence, not a comparable value`,render:e=>d(`span`,{className:`text-xs text-foreground-muted`,children:R(e.monitor,S)})},{key:`coverage`,header:e(`scenes.variants`,`Variants`),notSortableReason:`Coverage is a summary string`,render:e=>d(`span`,{className:`text-xs text-foreground-muted`,children:H(e.monitor)})},{key:`transition`,header:e(`scenes.lastChange`,`Last change`),align:`right`,nowrap:!0,sortValue:e=>ms(e.monitor)??0,render:e=>d(`span`,{className:`text-xs tabular-nums text-foreground-muted`,children:vs(e.monitor,S)})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:t=>d(J,{variant:`ghost`,onClick:()=>g(String(t.deviceId)),children:e(`scenes.open`,`Open`)})}];return a(`section`,{className:`space-y-3`,children:[a(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between sm:gap-4`,children:[d(`p`,{className:`text-xs text-foreground-subtle`,children:e(`scenes.aSceneWatchesOneRegion`,`A scene watches one region of one camera and tells you when it stops looking like the picture you captured — a wheelie bin, a gate, a parking space.`)}),a(J,{onClick:m,disabled:s.length===0,className:`shrink-0`,children:[d(V,{className:`mr-1 h-3.5 w-3.5`}),e(`scenes.newScene`,`New scene`)]})]}),l.unreachableCount>0?d(`p`,{className:`text-xs text-warning`,children:e(`scenes.unreachable`,{count:l.unreachableCount})}):null,(u.length>0||f.active)&&d(Tt,{state:f.state,facets:f.facets,labels:{searchPlaceholder:`Search scenes…`,searchLabel:`Search scenes`,facetsLabel:`State`,clearLabel:`Clear`},facetLabel:e=>_s[e]??e,onSearch:f.setSearch,onToggleFacet:f.toggleFacet,onClear:f.clear}),d(et,{variant:`flat`,className:`p-0`,children:d(it,{columns:C,rows:f.rows,rowKey:e=>`${e.deviceId}:${e.monitor.id}`,minWidthPx:880,bordered:!1,maxBodyHeight:Ge,emptyMessage:l.isLoading?e(`scenes.loadingScenes`,`Loading scenes…`):f.active?e(`scenes.nothingMatchesTheFilter`,`Nothing matches the filter`):e(`scenes.noScenesYetPressNew`,`No scenes yet. Press “New scene”, pick a camera, then draw a box around the thing you want watched.`)})}),p.mode===`new`?a(rt,{open:!0,onClose:_,title:e(`scenes.whichCamera`,`Which camera?`),icon:h,width:`sm`,testId:`scenes-camera-picker`,footer:d(J,{onClick:()=>{v!==null&&g(String(v))},disabled:v===null,children:e(`scenes.continue`,`Continue`)}),children:[d(`p`,{className:`mb-3 text-xs text-foreground-subtle`,children:e(`scenes.aSceneLivesOnOne`,`A scene lives on one camera. Pick the one that can see the thing.`)}),d(ke,{value:v===null?``:String(v),onChange:e=>y(Number(e.target.value)),"aria-label":e(`scenes.camera`,`Camera`),options:s.map(e=>({value:String(e.deviceId),label:e.deviceName}))})]}):null,b===null?null:a(rt,{open:!0,onClose:_,title:e(`scenes.scenes`,`Scenes — {{editingName}}`,{editingName:x}),icon:h,width:`lg`,testId:`scenes-editor`,children:[d(`p`,{className:`mb-3 text-xs text-foreground-subtle`,children:e(`scenes.drawABoxNameIt`,`Draw a box, name it, then capture what “normal” looks like. Daylight is enough — the night reference is optional, and “Settings” on each scene tunes how fussy and how often it checks.`)}),d(o,{fallback:d(`p`,{className:`text-xs text-foreground-muted`,children:e(`scenes.loadingTheEditor`,`Loading the editor…`)}),children:d(Dt,{deviceId:b})})]})]})}function Ss(){let{t:e}=X(),t=Pt(`/library`,{t:e,isAdmin:!0})??{icon:he,title:e(`nav.library`,`Library`)};return d(zt,{icon:t.icon,title:t.title,subtitle:e(`library.peopleVehiclesCapturedEventsAnd`,`People, vehicles, captured events and scenes — what detection has recognised.`),defaultSection:`people`,sectionsLabel:`${t.title} sections`,sections:[{id:`people`,label:e(`library.people`,`People`),content:d(Wr,{})},{id:`vehicles`,label:e(`library.vehicles`,`Vehicles`),content:d(fs,{})},{id:`events`,label:e(`library.events`,`Events`),content:d(Vo,{}),ownedParams:[`section`]},{id:`scenes`,label:e(`library.scenes`,`Scenes`),content:d(xs,{})}]})}export{Ss as LibraryPage};
@@ -0,0 +1,3 @@
1
+ import{$ as e,B as t,G as n,J as r,S as i,b as a,o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{$i as c,Di as l,Fn as u,Gi as d,Hr as f,Ht as p,It as m,Lr as h,Mi as g,O as _,Pi as v,Pr as y,Ri as b,Rt as x,Ur as S,V as C,bn as w,cn as T,dt as E,ea as D,ei as O,en as k,fi as A,gr as j,k as M,kn as N,lr as P,pn as F,pt as I,rn as L,rr as R,ta as z,tr as ee,ur as B,ut as te,xi as ne,yi as V,z as H,zt as re}from"./player-overlays-Dx9MsPRB.js";import{Cr as ie,sn as ae,xr as oe}from"./client-Bk3bp5F2.js";import{t as se}from"./boxes-BqbPUbNG.js";import{n as ce,r as le,t as ue}from"./speaker-5LjbBCEM.js";import{t as U}from"./user-round-lV0LR5iu.js";import{Da as de,Ea as fe,Fn as W,Fr as G,Hr as pe,L as me,Lu as K,Mu as q,Nr as he,Oa as ge,Pn as _e,Rr as ve,Ru as ye,To as be,_o as xe,_t as Se,ao as Ce,bo as we,cr as Te,do as Ee,fo as De,gn as J,io as Oe,ir as ke,ja as Ae,mo as je,nr as Me,on as Ne,oo as Pe,or as Fe,po as Ie,ro as Le,rr as Re,sn as ze,sr as Be,to as Ve,vo as He,yo as Ue,zu as We}from"./src-D293nH2g.js";import{t as Y}from"./i18n-CWIrO_Qb.js";import{t as X}from"./useTranslation-D3Is_4B6.js";import{_r as Ge,hr as Z,v as Ke,yr as qe}from"./index-D3LY1t1A.js";import{t as Je}from"./AdminSectionedPage-CjqX3s11.js";import{a as Ye,n as Xe,r as Ze}from"./linked-devices-model-CMebF7aU.js";e();var Qe={camera:l,hub:ce,container:se,light:B,siren:L,switch:re,sensor:z,thermostat:p,climate:D,button:A,"event-emitter":te,update:le,notifier:b,script:F,automation:I,lock:R,cover:v,valve:S,humidifier:f,"water-heater":y,fan:h,"media-player":ue,"alarm-panel":T,control:k,presence:U,weather:O,vacuum:g,"lawn-mower":x,image:j,smoke:c};function Q({type:e,className:t}){return s(Qe[e]??A,{"aria-hidden":`true`,className:t??`h-3.5 w-3.5 shrink-0 text-foreground-subtle`})}function $e({online:e,deviceName:t}){return s(`span`,{className:e?`inline-block h-1.5 w-1.5 shrink-0 rounded-full bg-success`:`inline-block h-1.5 w-1.5 shrink-0 rounded-full border border-foreground-subtle`,role:`img`,"aria-label":Y.t(`locations.deviceGlyphs.aria`,{name:t,state:e?Y.t(`common.online`):Y.t(`common.offline`)}),title:e?Y.t(`common.online`):Y.t(`common.offline`)})}function et({open:e,title:n,items:a,listState:o,lockedIds:c,lockedNote:l,suggestions:u=null,busy:d=!1,onConfirm:f,onClose:p}){let{t:m}=X(),[h,g]=r([]);t(()=>{e||g([])},[e]);let _=new Map(a.map(e=>[e.id,e.name])),v=(u?.ids??[]).filter(e=>_.has(e)&&!c.includes(e)),y=e=>g(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]);return s(Me,{open:e,onOpenChange:e=>e?void 0:p(),children:i(ke,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":n,children:[s(Be,{children:s(Te,{children:n})}),i(Re,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:[e&&u!==null&&v.length>0&&i(`section`,{"aria-label":u.heading,className:`flex flex-col gap-1`,children:[s(`h3`,{className:`text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:u.heading}),s(`div`,{className:`flex flex-wrap gap-1`,children:v.map(e=>s(`button`,{type:`button`,"aria-pressed":h.includes(e),className:`inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${h.includes(e)?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:bg-surface-hover`}`,onClick:()=>y(e),children:_.get(e)},e))})]}),e&&s(me,{devices:a,listState:o,value:h,onChange:e=>g(e),noun:`device`,emptyLabel:m(`locations.addDialog.nonePicked`),showAll:!0,lockedIds:c,lockedNote:l,testId:`quick-add-picker`})]}),i(Fe,{children:[s(G,{variant:`ghost`,onClick:p,children:m(`locations.addDialog.cancel`)}),s(G,{disabled:h.length===0||d,onClick:()=>f(h),children:m(`locations.addDialog.confirm`,{count:h.length})})]})]})})}e();function tt({room:e,cameras:t,fleet:r}){let{t:i}=X(),a=n(()=>new Map(r.map(e=>[e.id,e])),[r]);return e===null?s(`p`,{className:`text-xs text-foreground-subtle`,children:i(`locations.links.noRoom`)}):s(`div`,{className:`flex flex-col gap-3`,"data-testid":`camera-links-section`,children:t.length===0?s(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`camera-links-empty`,children:i(`locations.links.noCameras`,{room:e})}):t.map(e=>s(rt,{camera:e,byId:a},e.id))})}function nt(e){return{id:e.deviceId,name:e.parentName===null?e.name:`${e.parentName} · ${e.name}`,type:e.type,location:e.location}}function rt({camera:e,byId:t}){let{t:n}=X(),a=o(),c=Ge(),[l,u]=r(!1),[d,f]=r(null),p=de({deviceId:e.id}),m=Ze({status:p.status,data:p.data,error:p.error===null||p.error===void 0?null:p.error}),h=ge(),g=m.kind===`present`?m:null,v=fe({deviceId:e.id,slotRef:g?.slot.slotRef??``},{enabled:l&&g!==null}),y=g===null?[]:Xe(g.slot,g.value),b=y.map(e=>e.deviceId),x=(v.data?.candidates??[]).map(nt),S=new Set(x.map(e=>e.id)),C=b.filter(e=>!S.has(e)).map(e=>{let n=t.get(e);return{id:e,name:n?.name??`#${String(e)}`,...n===void 0?{}:{type:n.type,location:n.location}}}),w=[...x,...C],T=(v.data?.candidates??[]).filter(e=>e.suggested).map(e=>e.deviceId),E=async t=>{if(g!==null){f(null);try{await h.mutateAsync({deviceId:e.id,slotRef:g.slot.slotRef,value:Ye(g.value,t)}),await p.refetch(),await a.invalidateQueries({queryKey:[[`deviceManager`]]}),u(!1)}catch(e){f(e instanceof Error?e.message:String(e))}}},D=[{key:`device`,header:n(`locations.columns.device`),notSortableReason:n(`locations.columns.noSort`),render:e=>{let r=t.get(e.deviceId),a=e.name??r?.name??`#${String(e.deviceId)}`;return i(`span`,{className:`flex items-center gap-1.5`,children:[r!==void 0&&s(Q,{type:r.type}),s(Z,{to:`/devices/${String(e.deviceId)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:a}),e.implied&&s(`span`,{className:`text-[10px] text-foreground-subtle`,children:n(`locations.links.implied`)})]})}},{key:`type`,header:n(`locations.columns.type`),notSortableReason:n(`locations.columns.noSort`),render:e=>s(`span`,{className:`text-xs text-foreground-muted`,children:t.get(e.deviceId)?.type??`—`})},{key:`status`,header:n(`locations.columns.status`),notSortableReason:n(`locations.columns.noSort`),render:e=>{let r=t.get(e.deviceId);return r===void 0?s(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):i(`span`,{className:`flex items-center gap-1.5`,children:[s($e,{online:r.online,deviceName:r.name}),s(`span`,{className:`text-xs text-foreground-muted`,children:r.online?n(`common.online`):n(`common.offline`)})]})}}];return i(`section`,{className:`min-w-0 ${_}`,"data-testid":`camera-links-${String(e.id)}`,children:[i(`header`,{className:`${M} flex min-h-9 items-center gap-1.5`,children:[s(Q,{type:e.type}),s(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:e.name}),i(G,{variant:`ghost`,size:`sm`,onClick:()=>c(Ke(e.id)),children:[s(P,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),n(`locations.links.edit`)]}),s(G,{variant:`outline`,size:`sm`,disabled:g===null,onClick:()=>u(!0),"aria-label":n(`locations.links.addNamed`,{camera:e.name}),children:n(`locations.room.add`)})]}),m.kind===`pending`&&s(`p`,{role:`status`,className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:n(`locations.links.loading`)}),m.kind===`unknown`&&s(`p`,{role:`alert`,className:`px-3 py-3 text-xs text-warning sm:px-4`,children:n(`locations.links.unreadable`,{reason:m.reason})}),m.kind===`absent`&&s(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:n(`locations.links.unsupported`)}),d!==null&&s(`p`,{role:`alert`,className:`px-3 pt-2 text-xs text-danger break-words sm:px-4`,children:d}),g!==null&&(y.length===0?s(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:n(`locations.links.none`)}):s(J,{columns:D,rows:y,rowKey:e=>String(e.deviceId),bordered:!1,minWidthPx:360})),s(et,{open:l,title:n(`locations.links.pickTitle`,{camera:e.name}),items:w,listState:v.status===`error`?`failed`:v.data===void 0?`pending`:`answered`,lockedIds:b,lockedNote:n(`locations.links.alreadyLinked`),suggestions:e.location===null?null:{heading:n(`locations.links.suggested`,{room:e.location}),ids:T},busy:h.isPending,onConfirm:e=>void E(e),onClose:()=>u(!1)})]})}e();function it({name:e,description:n,busy:a,onSave:o}){let{t:c}=X(),[l,u]=r(n??``);return t(()=>{u(n??``)},[n]),i(`div`,{className:`border-t border-border px-3 py-2 sm:px-4`,children:[s(W,{htmlFor:`location-description-${e}`,className:`block`,children:c(`locations.locationDescriptionField.whatIsThere`,`What is there`)}),s(`textarea`,{id:`location-description-${e}`,value:l,onChange:e=>u(e.target.value),onBlur:()=>{let e=l.trim();e!==(n??``)&&o(e.length===0?null:e)},disabled:a,rows:2,maxLength:400,placeholder:c(`locations.locationDescriptionField.surfacesBoundariesWhatIsNormally`,`Surfaces, boundaries, what is normally parked or stored here.`),className:`mt-1 w-full resize-y rounded-md border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-inset focus:ring-primary disabled:cursor-not-allowed disabled:opacity-50`}),s(`p`,{className:`mt-1 ${H}`,children:c(`locations.locationDescriptionField.givenToTheAiWith`,`Given to the AI with the pictures, so it knows what it is looking at. Describe the PLACE, not what happens in it — events change, the ground does not.`)})]})}function at(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0||n.description.length===0?null:n.description}var ot=` none`;function st({name:e,zones:t,zoneKey:n,busy:r,onChange:a}){let{t:o}=X();if(t.length===0)return null;let c=[{value:ot,label:o(`locations.locationZoneField.none`,`— none —`)},...t.map(e=>({value:e.zoneKey,label:e.label}))];return i(`div`,{className:`flex items-center gap-2 border-t border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:[s(W,{htmlFor:`location-zone-${e}`,children:o(`locations.locationZoneField.zone`,`Zone`)}),s(q,{id:`location-zone-${e}`,value:n??ot,disabled:r,onChange:e=>{let n=e.target.value;if(n===ot){a(null);return}let r=t.find(e=>e.zoneKey===n);r!==void 0&&a(r.label)},options:c})]})}function ct(e,t){return e.find(e=>e.locationKeys.includes(t))?.zoneKey??null}function lt({name:e,icon:t,busy:n,onPick:r}){return s(We,{value:t,onPick:r,fallbackGlyph:ee,clearGlyph:d,labels:{trigger:`Change the icon of ${e}`,panel:`Icon for ${e}`,searchPlaceholder:`Search icons`,clear:`No icon`,noMatches:`No icon matches that`},disabled:n})}function ut(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0?null:ie(n.icon)??`map-pin`}function $(e){if(e==null)return null;let t=e.trim();return t.length===0?null:t.toLowerCase()}function dt(e,t){let n=$(t);return n===null?[]:e.filter(e=>$(e.location)===n)}function ft(e,t){let n=dt(e,t),r=new Set(n.map(e=>e.id));return n.filter(e=>e.parentDeviceId===null||!r.has(e.parentDeviceId))}function pt(e,t){let n=$(e.location);return n===null||new Set(t.map(e=>$(e))).has(n)?null:e.location?.trim()??null}function mt(e,t){let n=$(e.location);return n!==null&&t.has(n)}function ht(e,t){let n=new Set(t.map(e=>$(e))),r=new Set(e.filter(e=>mt(e,n)).map(e=>e.id));return e.filter(e=>!(mt(e,n)||e.parentDeviceId!==null&&r.has(e.parentDeviceId)))}function gt(e,t){return ht(e,t).filter(e=>e.parentDeviceId===null)}function _t(e,t){let n=new Map;for(let t of e){if(t.parentDeviceId===null)continue;let e=n.get(t.parentDeviceId);e?e.push(t):n.set(t.parentDeviceId,[t])}let r=[],i=new Set([t]),a=[t];for(;a.length>0;){let e=[];for(let t of a)for(let a of n.get(t)??[])i.has(a.id)||(i.add(a.id),r.push(a),e.push(a.id));a=e}return r}function vt(e,t){return _t(e,t).length}function yt(e,t){return e.filter(e=>!e.isCamera&&e.parentDeviceId===t)}function bt(e,t){return t.map(t=>({name:t,members:ft(e,t)}))}function xt(e){return`${e.kind}:${String(e.device.id)}`}function St(e,t,n){return e.flatMap(e=>{let r=yt(t,e.id),i=n.has(e.id),a={kind:`member`,device:e,accessories:r,open:i};return!i||r.length===0?[a]:[a,...r.map(t=>({kind:`accessory`,device:t,parent:e}))]})}e();function Ct({name:e,members:t,devices:o,busy:c,icon:l,description:d,onRename:f,onDelete:p,onRebuildLinks:h,onAddDevices:g,onPickIcon:v,onSaveDescription:y,zones:b,zoneKey:x,onChangeZone:S}){let{t:C}=X(),[T,D]=r(!1),[O,k]=r(e),A=Ne(t,n(()=>({searchText:e=>[e.name,...yt(o,e.id).map(e=>e.name)],facetValue:e=>e.type}),[o])),[j,N]=r(()=>new Set),P=e=>N(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),F=n(()=>St(A.rows,o,j),[A.rows,o,j]),I=[{key:`name`,header:C(`locations.columns.device`),notSortableReason:C(`locations.columns.noSort`),render:e=>e.kind===`member`?s(wt,{row:e,onToggle:()=>P(e.device.id)}):s(Tt,{row:e})},{key:`type`,header:C(`locations.columns.type`),notSortableReason:C(`locations.columns.noSort`),render:e=>s(`span`,{className:`text-xs text-foreground-muted`,children:e.device.type})},{key:`status`,header:C(`locations.columns.status`),notSortableReason:C(`locations.columns.noSort`),render:e=>i(`span`,{className:`flex items-center gap-1.5`,children:[s($e,{online:e.device.online,deviceName:e.device.name}),s(`span`,{className:`text-xs text-foreground-muted`,children:e.device.online?C(`common.online`):C(`common.offline`)})]})}],L=()=>{k(e),D(!1)},R=async()=>{let t=O.trim();if(t.length===0||t===e){L();return}await f(t),D(!1)},z=[{id:`rename`,label:C(`locations.locationCard.rename`,`Rename`),icon:u,disabled:c,onClick:()=>{k(e),D(!0)}},{id:`rebuild-links`,label:C(`locations.locationCard.rebuildLinkedDevices`,`Rebuild linked devices`),icon:w,separatorBefore:!0,disabled:c,onClick:()=>void h()},{id:`delete`,label:C(`common.delete`,`Delete`),icon:m,danger:!0,separatorBefore:!0,disabled:c,onClick:()=>void p()}];return i(`section`,{className:`min-w-0 ${_}`,children:[i(`header`,{className:`${M} flex min-h-9 items-center gap-1.5`,children:[s(lt,{name:e,icon:l,busy:c,onPick:v}),T?i(a,{children:[s(K,{value:O,onChange:e=>k(e.target.value),onKeyDown:e=>{e.key===`Enter`&&R(),e.key===`Escape`&&L()},"aria-label":C(`locations.locationCard.rename2`,`Rename {{name}}`,{name:e}),className:`min-w-0 flex-1`,autoFocus:!0}),s(G,{type:`button`,size:`sm`,onClick:()=>void R(),children:C(`common.save`,`Save`)}),s(ye,{type:`button`,variant:`ghost`,icon:E,onClick:L,"aria-label":C(`locations.locationCard.cancelRename`,`Cancel rename`)})]}):i(a,{children:[s(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:e}),s(G,{type:`button`,variant:`outline`,size:`sm`,disabled:c,onClick:g,"aria-label":C(`locations.room.addTo`,{room:e}),children:C(`locations.room.add`)}),s(Se,{items:z,title:C(`locations.locationCard.actionsFor`,`Actions for {{name}}`,{name:e}),triggerClassName:`p-1`})]})]}),s(st,{name:e,zones:b,zoneKey:x,busy:c,onChange:S}),s(it,{name:e,description:d,busy:c,onSave:y}),t.length>0&&s(`div`,{className:`border-b border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:s(ze,{state:A.state,facets:A.facets,labels:{searchPlaceholder:C(`locations.filter.searchPlaceholder`),searchLabel:C(`locations.room.searchLabel`,{room:e}),facetsLabel:C(`locations.filter.typesLabel`),clearLabel:C(`locations.filter.clear`)},onSearch:A.setSearch,onToggleFacet:A.toggleFacet,onClear:A.clear})}),t.length===0?s(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:C(`locations.locationCard.nothingHereYetAssignA`,`Nothing here yet — assign a device from the table below.`)}):s(J,{columns:I,rows:F,rowKey:xt,bordered:!1,minWidthPx:360,emptyMessage:C(`locations.filter.noMatch`)})]})}function wt({row:e,onToggle:t}){let{t:n}=X(),{device:r,accessories:a,open:o}=e,c=o?ne:V;return i(`span`,{className:`flex items-center gap-1.5`,children:[a.length>0?i(G,{type:`button`,variant:`ghost`,onClick:t,"aria-expanded":o,"aria-label":n(o?`locations.locationCard.collapseAccessories`:`locations.locationCard.expandAccessories`,{count:a.length,name:r.name}),className:`h-auto shrink-0 gap-0.5 p-0.5 text-foreground-subtle hover:text-foreground`,children:[s(c,{className:`h-3 w-3`}),s(`span`,{className:`text-[10px] tabular-nums`,children:a.length})]}):s(`span`,{"aria-hidden":`true`,className:`w-[1.35rem] shrink-0`}),s(Q,{type:r.type}),s(Z,{to:`/devices/${String(r.id)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:r.name})]})}function Tt({row:e}){let{device:t}=e;return i(`span`,{className:`flex items-center gap-1.5 pl-6`,children:[s(`span`,{"aria-hidden":`true`,className:`text-[10px] text-foreground-subtle`,children:`└`}),s(Q,{type:t.type,className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(Z,{to:`/devices/${String(t.id)}`,className:`min-w-0 truncate text-xs text-foreground-muted hover:underline`,children:t.name})]})}e();function Et({zones:e,busy:t,onRename:n,onDelete:i,onPickIcon:a}){let{t:o}=X(),[c,l]=r(null),[u,d]=r(``),f=async e=>{let t=u.trim();l(null),!(t.length===0||t===e)&&await n(e,t)};return s(J,{columns:[{key:`icon`,header:o(`locations.siteZonesPanel.icon`,`Icon`),width:`w-12`,notSortableReason:`An icon has no order`,render:e=>s(lt,{name:e.label,icon:e.icon,busy:t,onPick:t=>a(e.label,t)})},{key:`name`,header:o(`locations.siteZonesPanel.zone`,`Zone`),sortValue:e=>e.label.toLowerCase(),render:e=>c===e.label?s(K,{value:u,onChange:e=>d(e.target.value),onKeyDown:t=>{t.key===`Enter`&&f(e.label),t.key===`Escape`&&l(null)},onBlur:()=>void f(e.label),"aria-label":o(`locations.siteZonesPanel.rename`,`Rename {{label}}`,{label:e.label}),autoFocus:!0}):s(G,{type:`button`,variant:`ghost`,size:`sm`,className:`px-0`,onClick:()=>{d(e.label),l(e.label)},disabled:t,title:o(`locations.siteZonesPanel.renameTheZone`,`Rename the zone`),children:e.label})},{key:`rooms`,header:o(`locations.siteZonesPanel.rooms`,`Rooms`),align:`right`,sortValue:e=>e.locationKeys.length,render:e=>s(`span`,{className:`tabular-nums text-foreground-subtle`,children:e.locationKeys.length===0?o(`common.empty`):o(`common.rooms`,{count:e.locationKeys.length})})},{key:`actions`,header:o(`locations.siteZonesPanel.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order`,render:e=>s(G,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void i(e.label),disabled:t,"aria-label":o(`locations.siteZonesPanel.delete`,`Delete {{label}}`,{label:e.label}),title:o(`locations.siteZonesPanel.deleteTheZoneTheRooms`,`Delete the zone — the rooms in it are kept`),children:s(m,{className:`h-3.5 w-3.5`})})}],rows:e,rowKey:e=>e.zoneKey,emptyMessage:o(`locations.siteZonesPanel.noZonesYetAZone`,`No zones yet. A zone groups rooms — “Zona notte” for the bedrooms — and shows up before them in the app’s camera filter.`)})}e();function Dt({busy:e,onCreate:t}){let{t:n}=X(),[a,o]=r(!1),[c,l]=r(``),u=()=>{l(``),o(!1)},d=async()=>{let e=c.trim();e.length!==0&&(await t(e),u())};return a?i(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),d()},children:[s(K,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&u()},placeholder:n(`locations.newLocationButton.ingressoSaloneCucina`,`Ingresso, Salone, Cucina…`),"aria-label":n(`locations.newLocationButton.newLocationName`,`New location name`),className:`min-w-[12rem] flex-1`,autoFocus:!0}),i(G,{size:`sm`,type:`submit`,disabled:c.trim().length===0||e,children:[s(N,{className:`h-3.5 w-3.5`}),n(`common.add`,`Add`)]}),s(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":n(`locations.newLocationButton.cancelNewLocation`,`Cancel new location`),children:s(E,{className:`h-3.5 w-3.5`})})]}):i(G,{size:`sm`,type:`button`,onClick:()=>o(!0),"data-testid":`new-location-button`,children:[s(N,{className:`h-3.5 w-3.5`}),n(`locations.newLocationButton.newLocation`,`New location`)]})}e();function Ot({busy:e,onCreate:t}){let{t:n}=X(),[a,o]=r(!1),[c,l]=r(``),u=()=>{l(``),o(!1)},d=async()=>{let e=c.trim();e.length!==0&&(await t(e),u())};return a?i(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),d()},children:[s(K,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&u()},placeholder:n(`locations.newZoneButton.zonaGiornoZonaNotte`,`Zona giorno, Zona notte…`),"aria-label":n(`locations.newZoneButton.newZoneName`,`New zone name`),className:`min-w-[12rem] flex-1`,autoFocus:!0}),i(G,{size:`sm`,type:`submit`,disabled:c.trim().length===0||e,children:[s(N,{className:`h-3.5 w-3.5`}),n(`common.add`,`Add`)]}),s(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":n(`locations.newZoneButton.cancelNewZone`,`Cancel new zone`),children:s(E,{className:`h-3.5 w-3.5`})})]}):i(G,{size:`sm`,type:`button`,onClick:()=>o(!0),"data-testid":`new-zone-button`,children:[s(N,{className:`h-3.5 w-3.5`}),n(`locations.newZoneButton.newZone`,`New zone`)]})}e();function kt(e,t,n,r){let i=e.map(e=>({value:e.name,label:`${e.name} · ${String(e.count)}`}));return t===void 0?i:[...i,{value:n,label:`${r} · ${String(t)}`}]}function At({rooms:e,unassignedCount:t,value:r,unassignedValue:i,onChange:a}){let{t:o}=X(),c=n(()=>kt(e,t,i,o(`locations.roomPicker.unassigned`)),[e,t,i,o]);return s(`div`,{className:`max-w-sm`,"data-testid":`room-select`,children:s(ve,{mode:`single`,singleDisplay:`field`,label:o(`locations.roomPicker.label`),placeholder:o(`locations.roomPicker.placeholder`),options:c,value:r,onChange:a,searchable:!0,testId:`room-select-control`,optionTestIdPrefix:`room-option`})})}e();var jt={searchText:e=>[e.name],facetValue:e=>e.type};function Mt({rows:e,fleet:t,locations:a,busy:o,emptyMessage:c,onAssign:l}){let{t:u}=X(),[d,f]=r([]),[p,m]=r(``),h=Ne(e,jt),g=h.rows,_=n(()=>g.map(e=>e.id),[g]),v=n(()=>d.filter(e=>_.includes(e)),[d,_]),y=g.length>0&&v.length===g.length,b=n(()=>{let n=new Map;for(let r of e)n.set(r.id,vt(t,r.id));return n},[e,t]),x=v.reduce((e,t)=>e+(b.get(t)??0),0),S=e=>f(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),w=()=>f(y?[]:_),T=()=>{p.length===0||v.length===0||(l(v,p),f([]),m(``))},E=a.map(e=>({value:e,label:e})),D=[{key:`select`,width:`w-8`,headerRender:()=>s(_e,{checked:y,onChange:w,"aria-label":y?u(`locations.unassignedTable.clearSelection`,`Clear selection`):u(`locations.unassignedTable.selectAllUnassignedDevices`,`Select all unassigned devices`)}),render:e=>s(_e,{checked:v.includes(e.id),onChange:()=>S(e.id),"aria-label":u(`locations.unassignedTable.select`,`Select {{name}}`,{name:e.name})})},{key:`name`,header:u(`locations.unassignedTable.device`,`Device`),sortValue:e=>e.name.toLowerCase(),render:e=>{let t=pt(e,a);return i(`span`,{className:`flex items-center gap-1.5`,children:[s(Q,{type:e.type}),s(Z,{to:`/devices/${String(e.id)}`,className:`truncate text-xs text-foreground hover:underline`,children:e.name}),t!==null&&s(pe,{variant:`warning`,children:u(`locations.unassignedTable.unknownRoom`,{room:t})})]})}},{key:`type`,header:u(`locations.unassignedTable.type`,`Type`),sortValue:e=>e.type,render:e=>s(`span`,{className:`text-xs text-foreground-muted`,children:e.type})},{key:`status`,header:u(`locations.unassignedTable.status`,`Status`),sortValue:e=>+!!e.online,render:e=>i(`span`,{className:`flex items-center gap-1.5`,children:[s($e,{online:e.online,deviceName:e.name}),s(`span`,{className:`text-xs text-foreground-muted`,children:e.online?u(`common.online`):u(`common.offline`)})]})},{key:`followers`,header:u(`locations.unassignedTable.accessoriesInTowCount`,`Accessories in tow`),align:`right`,sortValue:e=>b.get(e.id)??0,render:e=>s(`span`,{className:`tabular-nums text-xs text-foreground-muted`,children:b.get(e.id)??0})},{key:`assign`,header:u(`locations.unassignedTable.assignTo`,`Assign to`),align:`right`,notSortableReason:`This column is a control, not a value.`,render:e=>s(q,{"aria-label":u(`locations.unassignedTable.locationFor`,`Location for {{name}}`,{name:e.name}),value:``,disabled:o||a.length===0,onChange:t=>{let n=t.target.value;n.length!==0&&l([e.id],n)},className:`max-w-[11rem]`,options:[{value:``,label:`—`},...E]})}];return i(`section`,{className:`space-y-2`,children:[i(`header`,{className:`flex flex-wrap items-baseline gap-2`,children:[s(`h2`,{className:C,children:u(`locations.unassignedTable.notInARoom`,`Not in a room`)}),s(`p`,{className:H,children:u(`locations.unassignedTable.topLevelDevicesOnlyAccessories`,`Top-level devices only — accessories move with their parent.`)})]}),e.length>0&&s(ze,{state:h.state,facets:h.facets,labels:{searchPlaceholder:u(`locations.filter.searchPlaceholder`),searchLabel:u(`locations.unassigned.searchLabel`),facetsLabel:u(`locations.filter.typesLabel`),clearLabel:u(`locations.filter.clear`)},onSearch:h.setSearch,onToggleFacet:h.toggleFacet,onClear:h.clear}),v.length>0&&i(`div`,{role:`group`,"aria-label":u(`locations.unassignedTable.bulkAssignment`,`Bulk assignment`),className:`flex flex-wrap items-center gap-2 rounded border border-primary/40 bg-primary/5 px-2 py-1.5`,children:[i(`span`,{className:`text-xs text-foreground`,children:[u(`locations.unassignedTable.selected`,{count:v.length}),x>0&&` · ${u(`locations.unassignedTable.accessoriesInTowCount`,{count:x})}`]}),s(q,{"aria-label":u(`locations.unassignedTable.assignSelectedDevicesTo`,`Assign selected devices to`),value:p,onChange:e=>m(e.target.value),className:`w-auto min-w-[10rem]`,options:[{value:``,label:u(`locations.unassignedTable.assignTo2`,`Assign to…`)},...E]}),s(G,{type:`button`,size:`sm`,onClick:T,disabled:o||p.length===0,children:u(`locations.unassignedTable.assign`,`Assign`)}),s(G,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>f([]),children:u(`locations.unassignedTable.clear`,`Clear`)})]}),s(J,{columns:D,rows:g,rowKey:e=>e.id,minWidthPx:720,emptyMessage:h.active?u(`locations.filter.noMatch`):c})]})}function Nt(e){return{id:e.id,parentDeviceId:e.parentDeviceId,location:e.location,type:e.type,stableId:e.stableId??``,...e.primaryChildEntityId===void 0?{}:{primaryChildEntityId:e.primaryChildEntityId},...e.role!==void 0&&e.role!==null?{role:e.role}:{},name:e.name}}function Pt(e,t){let n=t.map(Nt),r=[];for(let i of t)i.isCamera&&i.location===e&&r.push({deviceId:i.id,name:i.name,ids:ae({selfId:i.id,selfLocation:i.location,candidates:n})});return{entries:r}}var Ft=`device-manager:linked-devices`;function It(e){return{deviceId:e.deviceId,slotRef:Ft,value:{slot:`linked-devices`,deviceIds:[...e.ids]}}}e();var Lt=`__unassigned__`;function Rt(){let{t:e}=X(),t=o(),a=he(),{data:c,isLoading:l}=Ce(),{data:u}=Oe(),{data:d}=Le(),{data:f}=Pe(),{data:p,isLoading:m}=Ve({projection:`slim`}),h=()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]}),t.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),t.invalidateQueries({queryKey:[[`deviceManager`,`listLocationIcons`]]}),t.invalidateQueries({queryKey:[[`deviceManager`,`listLocationDescriptions`]]}),t.invalidateQueries({queryKey:[[`deviceManager`,`listSiteZones`]]})},g=Ae({onSuccess:h}),_=Ee({onSuccess:h}),v=xe({onSuccess:h}),y=Ie({onSuccess:h}),b=Ue({onSuccess:h}),x=He({onSuccess:h}),S=be({onSuccess:h}),C=De({onSuccess:h}),w=je({onSuccess:h}),T=we({onSuccess:h}),E=ge(),D=n(()=>(p??[]).map(e=>({id:e.id,name:e.name,location:e.location??null,type:String(e.type),isCamera:e.isCamera,parentDeviceId:e.parentDeviceId,online:e.online,role:e.role??null,stableId:e.stableId,primaryChildEntityId:e.primaryChildEntityId??null})),[p]),O=c??[],k=n(()=>bt(D,O),[D,O]),[A,j]=qe(),M=A.get(`tab`),N=M===`zones`||M===`camera-links`?M:`locations`,P=A.get(`room`),F=n(()=>gt(D,O),[D,O]),I=P===Lt,L=I?null:P!==null&&k.some(e=>e.name===P)?P:k[0]?.name??null,R=L===null?null:k.find(e=>e.name===L)??null,z=I?Lt:L??`__unassigned__`,B=L??k[0]?.name??null,te=n(()=>k.map(e=>({name:e.name,count:e.members.length})),[k]),ne=e=>{j(t=>{let n=new URLSearchParams(t);return n.set(`room`,e),n},{replace:!0})},V=l||m,H=v.isPending||_.isPending||g.isPending||b.isPending,re=async e=>{await g.mutateAsync({name:e})},ie=async(e,t)=>{let n=t.trim();n.length===0||n===e||await y.mutateAsync({from:e,to:n})},ae=async t=>{let n=Pt(t,D);if(n.entries.length===0){await a({title:e(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:e(`locations.noCameraIsAssignedTo`,`No camera is assigned to “{{room}}”.`,{room:t}),confirmLabel:`OK`});return}let r=n.entries.map(t=>e(`locations.rebuildEntry`,{name:t.name,count:t.ids.length})).join(`
2
+ `);if(!await a({title:e(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:e(`locations.replaceTheLinkedDeviceList`,`Replace the linked-device list of every camera in “{{room}}” with what the room contains? {{lines}} Anything linked by hand that is not in this room is lost.`,{room:t,lines:r}),confirmLabel:e(`locations.rebuild`,`Rebuild`),variant:`danger`}))return;let i=[];for(let e of n.entries)try{await E.mutateAsync(It(e))}catch(t){i.push(`• ${e.name}: ${t instanceof Error?t.message:String(t)}`)}h(),i.length>0&&await a({title:e(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:e(`locations.notRebuilt`,`Not rebuilt: {{value1}}`,{value1:i.join(`
3
+ `)}),confirmLabel:`OK`})},se=async(t,n)=>{let r=n>0?` ${String(n)} device(s) will become unassigned.`:``;await a({title:e(`locations.deleteLocation`,`Delete location`),message:e(`locations.deleteTheLocation`,`Delete the location “{{name}}”?{{extra}}`,{name:t,extra:r}),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&await _.mutateAsync({name:t,cascade:!0})},ce=async t=>{await a({title:e(`locations.deleteZone`,`Delete zone`),message:e(`locations.deleteTheZoneTheRooms`,`Delete the zone “{{name}}”? The rooms in it are kept.`,{name:t}),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&await C.mutateAsync({name:t})},le=async(e,t)=>{await b.mutateAsync({location:e,icon:t})},ue=async(e,t)=>{await x.mutateAsync({location:e,description:t})},U=f??[],de=async(e,t)=>{await T.mutateAsync({location:e,zone:t})},fe=(e,t)=>{for(let n of e)v.mutate({deviceId:n,location:t})},[W,G]=r(null),pe=n(()=>D.filter(e=>e.parentDeviceId===null).map(e=>({id:e.id,name:e.name,type:e.type,location:e.location})),[D]),me=s(At,{rooms:te,...N===`locations`?{unassignedCount:F.length}:{},value:N===`locations`?z:B??``,unassignedValue:Lt,onChange:ne}),K=i(`div`,{className:`flex flex-col gap-3`,"data-testid":`locations-section`,children:[V&&s(`p`,{className:`text-xs text-foreground-subtle`,children:e(`locations.loadingLocationsAndDevices`,`Loading locations and devices…`)}),me,I||R===null?s(Mt,{rows:F,fleet:D,locations:O,busy:H,emptyMessage:V?e(`common.loading`,`Loading…`):e(`locations.everyTopLevelDeviceHas`,`Every top-level device has a room.`),onAssign:fe}):s(Ct,{name:R.name,members:R.members,devices:D,busy:H,icon:ut(u,oe(R.name)),onPickIcon:e=>le(R.name,e),description:at(d,oe(R.name)),onSaveDescription:e=>ue(R.name,e),zones:U,zoneKey:ct(U,oe(R.name)),onChangeZone:e=>de(R.name,e),onRename:e=>ie(R.name,e),onDelete:()=>se(R.name,dt(D,R.name).length),onRebuildLinks:()=>ae(R.name),onAddDevices:()=>G(R.name)},R.name),O.length===0&&!V&&s(`p`,{className:`text-xs text-foreground-subtle`,children:e(`locations.noLocationsYetAddIngresso`,`No locations yet. Add Ingresso, Salone, Cucina…`)}),s(et,{open:W!==null,title:e(`locations.room.addDialogTitle`,{room:W??``}),items:pe,listState:m?`pending`:`answered`,lockedIds:W===null?[]:(k.find(e=>e.name===W)?.members??[]).map(e=>e.id),lockedNote:e(`locations.room.alreadyHere`),suggestions:{heading:e(`locations.room.suggestedUnassigned`),ids:F.map(e=>e.id)},busy:v.isPending,onConfirm:e=>{W!==null&&fe(e,W),G(null)},onClose:()=>G(null)})]}),q=i(`div`,{className:`flex flex-col gap-3`,"data-testid":`camera-links-tab`,children:[me,s(tt,{room:B,cameras:B===null?[]:dt(D,B).filter(e=>e.isCamera),fleet:D})]});return s(Je,{icon:ee,title:e(`locations.locations`,`Locations`),subtitle:e(`locations.roomsAndAreasOfThe`,`Rooms and areas of the site. Assign any device here — storage disks are under Data → Storage.`),defaultSection:`locations`,sectionsLabel:`Locations sections`,actions:N===`zones`?s(Ot,{busy:S.isPending,onCreate:e=>S.mutateAsync({name:e})}):s(Dt,{busy:g.isPending,onCreate:re}),sections:[{id:`locations`,label:e(`locations.locations`,`Locations`),content:K},{id:`camera-links`,label:e(`locations.cameraLinks`,`Camera links`),content:q},{id:`zones`,label:e(`locations.zones`,`Zones`),content:s(Et,{zones:U,busy:H,onRename:(e,t)=>w.mutateAsync({from:e,to:t}),onDelete:ce,onPickIcon:(e,t)=>S.mutateAsync({name:e,icon:t})})}]})}export{Rt as LocationsPage};
@@ -1 +1 @@
1
- import{$ as e,G as t,J as n,S as r,x as i}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Di as a,Si as o,or as s,pn as c,ta as l}from"./player-overlays-B2uKzPiF.js";import{n as u,t as d}from"./timer-reset-D-5iU9l-.js";import{t as f}from"./layers-jV4_DPMS.js";import{Gl as p,Jl as m,Ju as h,Yt as g,oi as _,si as v}from"./src-N0x0aMoc.js";import{t as y}from"./useTranslation-D3Is_4B6.js";import{T as b,a as x,i as S}from"./index-DKfAHLRf.js";import{t as C}from"./AdminSectionedPage-DacqZ038.js";import{t as w}from"./AdminPage-COkr2pSl.js";import{n as T,t as E}from"./IntegrationHub-1t9XtENg.js";import{n as D,t as O}from"./addon-display-names-BkwMrExv.js";e();var k=5e3,A=`log-destination`,j={"winston-logging":`Rotated log files on this node’s disk.`,"console-logging":`stdout / stderr of the node process.`,"loki-logging":`Pushes to a Grafana Loki instance. Off until enabled with a URL.`,"hub-forwarder":`Agent-only — forwards this node’s entries to the hub.`};function M(){let{t:e}=y(),n=v({capName:`log-destination`},{refetchInterval:k}),r=_(void 0,{refetchInterval:k}),a=t(()=>O(r.data??[]),[r.data]),o=t(()=>{let e=new Map;for(let t of r.data??[]){let n=t.description,r=t.id;typeof r==`string`&&typeof n==`string`&&n.length>0&&e.set(r,n)}return e},[r.data]),s=t(()=>(n.data??[]).map(e=>({addonId:e.addonId,displayName:a.get(e.addonId)??e.addonId,isActive:e.isActive,caption:o.get(e.addonId)??j[e.addonId]??``})),[n.data,a,o]),l=[{id:A,label:e(`system.logging.logDestinations`,`Log destinations`),entries:s.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:u,...D(e.isActive),render:()=>i(T,{addonId:e.addonId,displayName:e.displayName,capName:A,isActive:e.isActive,badges:e.caption.length>0?i(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.caption}):null})}))}];return i(E,{embedded:!0,icon:c,title:e(`system.logging.destinations`,`Destinations`),subtitle:e(`system.logging.everyRegisteredLogDestinationEntries`,`Every registered log destination. Entries are fanned to all enabled destinations at once — enabling one does not disable another.`),groups:l,isLoading:n.isLoading,emptyTitle:e(`system.logging.noLogDestinationsRegistered`,`No log destinations registered`),emptyDescription:e(`system.logging.thisShouldNotHappenThe`,`This should not happen — the console and rotated-file destinations are builtins. If the list is empty, the node is still booting.`)})}e();var N=[12e4,3e5,6e5,18e5],P={"request-census":`Counts every tRPC call by TRANSPORT PLANE — http, ws, mesh — and by procedure, caller, address and user-agent. Subscriptions are counted apart from calls, so a long-lived stream cannot pass for a storm. Arm it, then restart: the deadline is persisted, so the window is still running when clients reconnect.`};function F(){let{t:e}=y(),t=p({},{refetchInterval:5e3}),a=m(),[o,c]=n(null),u=(e,n)=>{c(e),a.mutate({patch:{diagnostics:[{id:e,armMs:n}]}},{onSettled:()=>{c(null),t.refetch()}})},d=t.data?.activeWindows??[],f=t.data?.channels??[],h=t.data?.activeChannels??[],g=(e,n,r)=>{c(e),a.mutate({patch:{channels:[{channel:e,armMs:n,deviceIds:r}]}},{onSettled:()=>{c(null),t.refetch()}})};return r(w,{embedded:!0,icon:l,title:e(`logging.diagnostics.title`,`Diagnostics`),subtitle:e(`logging.diagnostics.subtitle`,`Diagnostics are armed for a window, never switched on. Each carries a deadline and expires by itself — one left running is an incident of its own.`),children:[t.isLoading?r(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(s,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}):i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:d.map(e=>i(L,{window:e,busy:o===e.id,onArm:t=>u(e.id,t)},e.id))}),i(`h3`,{className:`mt-6 text-sm font-medium text-foreground`,children:e(`logging.diagnostics.channels`,`Component channels`)}),i(`p`,{className:`mb-2 max-w-3xl text-[11px] text-foreground-subtle`,children:e(`logging.diagnostics.channelsSubtitle`,`Declared by the addons that own them — this list is not maintained by hand. Arming a channel opens a window with a deadline; it closes by itself.`)}),f.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`logging.diagnostics.noChannels`,`No addon on this cluster declares a log channel, or none could be reached right now.`)}):i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:f.map(e=>i(I,{channel:e,state:h.find(t=>t.channel===e.name),busy:o===e.name,onArm:(t,n)=>g(e.name,t,n)},e.name))})]})}function I({channel:e,state:t,busy:o,onArm:s}){let{t:c}=y(),[l,u]=n(``),f=t?.armed===!0,p=()=>{let e=l.split(/[\s,+]+/).filter(e=>/^\d+$/.test(e)).map(e=>Number(e));return e.length>0?e:null};return r(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[r(`div`,{className:`min-w-0`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.name}),f?r(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[i(d,{className:`h-3 w-3`}),c(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:R(t?.remainingMs??0)})]}):i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:c(`logging.diagnostics.disarmed`,`disarmed`)}),f&&t?.deviceIds!==null&&t?.deviceIds!==void 0&&r(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[i(a,{className:`h-3 w-3`}),t.deviceIds.join(`, `)]}),!e.perDevice&&i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:c(`logging.diagnostics.notPerCamera`,`not filterable per camera`)})]}),i(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:e.description})]}),r(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[e.perDevice&&i(`input`,{type:`text`,inputMode:`numeric`,value:l,disabled:o,onChange:e=>u(e.target.value),placeholder:c(`logging.diagnostics.camerasPlaceholder`,`all cameras`),className:`w-28 rounded border border-border bg-surface px-2 py-1 text-[11px] text-foreground`}),N.map(e=>i(`button`,{type:`button`,disabled:o,onClick:()=>s(e,p()),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:R(e)},e)),i(`button`,{type:`button`,disabled:o||!f,onClick:()=>s(0,null),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:c(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function L({window:e,busy:t,onArm:n}){let{t:a}=y();return r(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[r(`div`,{className:`min-w-0`,children:[r(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.id}),e.armed?r(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[i(d,{className:`h-3 w-3`}),a(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:R(e.remainingMs)})]}):i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:a(`logging.diagnostics.disarmed`,`disarmed`)}),e.armed&&!e.persisted&&i(`span`,{className:`text-[10px] text-warning`,children:a(`logging.diagnostics.notPersisted`,`not persisted — will not survive a restart`)})]}),i(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:P[e.id]??``})]}),r(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[N.map(e=>i(`button`,{type:`button`,disabled:t,onClick:()=>n(e),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:R(e)},e)),i(`button`,{type:`button`,disabled:t||!e.armed,onClick:()=>n(0),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:a(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function R(e){let t=Math.max(0,Math.round(e/1e3)),n=Math.floor(t/60),r=t%60;return n===0?`${r}s`:r===0?`${n}m`:`${n}m ${r}s`}e();var z=[`debug`,`info`,`warn`,`error`],B=``,V=``;function H(){let{t:e}=y(),[a,o]=n(B),[c,l]=n(V),{nodes:u}=h(),d=t(()=>u.map(e=>({id:e.id,label:e.name||e.id})),[u]),g=p({...a===B?{}:{scopeNodeId:a},...c===V?{}:{scopeComponent:c}},{refetchInterval:15e3}),_=m(),v=g.data,b=_.isPending||g.isFetching,x=v?.channels??[],S=(e,t)=>{_.mutate({...e.nodeId===null?{}:{scopeNodeId:e.nodeId},...e.component===null?{}:{scopeComponent:e.component},patch:{level:t}},{onSuccess:()=>void g.refetch()})};return i(w,{embedded:!0,icon:f,title:e(`logging.levels.title`,`Levels`),subtitle:e(`logging.levels.subtitle`,`Cluster → node, most specific wins. The floor gates what reaches the log destinations; the in-memory viewer keeps every line either way.`),actions:r(`div`,{className:`flex flex-wrap items-center gap-3`,children:[r(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[e(`logging.levels.scope`,`Scope`),r(`select`,{className:`rounded border border-border bg-surface px-2 py-1 text-xs text-foreground disabled:opacity-50`,value:a,disabled:c!==V,onChange:e=>o(e.target.value),children:[i(`option`,{value:B,children:e(`logging.levels.cluster`,`Cluster`)}),d.map(e=>i(`option`,{value:e.id,children:e.label},e.id))]})]}),r(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[e(`logging.levels.component`,`Component`),r(`select`,{className:`rounded border border-border bg-surface px-2 py-1 text-xs text-foreground`,value:c,onChange:e=>l(e.target.value),children:[i(`option`,{value:V,children:e(`logging.levels.noComponent`,`None`)}),x.map(e=>i(`option`,{value:e.name,children:e.name},e.name))]})]})]}),children:g.isLoading||v===void 0?r(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(s,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}):r(`div`,{className:`space-y-3`,children:[i(W,{level:v.effective.level,source:v.effective.levelSource,persisted:v.persisted}),i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:v.explicit.layers.map(e=>i(G,{layer:e,inForce:e.scope===v.effective.levelSource,busy:b,onSet:t=>S(e,t),onClear:()=>S(e,null)},`${e.scope}:${e.nodeId??e.component??`cluster`}`))}),c!==V&&i(`p`,{className:`text-[11px] text-foreground-subtle`,children:x.find(e=>e.name===c)?.description??``}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`logging.levels.componentNote`,`A component is a log channel an addon declared. Its level is cluster-wide and beats both the node and the cluster layer.`)}),i(U,{days:v.opsLogRetentionDays,busy:b,onSet:e=>_.mutate({patch:{opsLogRetentionDays:e}},{onSuccess:()=>void g.refetch()})})]})})}function U({days:e,busy:t,onSet:n}){let{t:a}=y();return r(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-1`,children:[r(`label`,{className:`flex items-center justify-between gap-3`,children:[i(`span`,{className:`text-xs font-medium`,children:a(`logging.levels.opsLogRetention`,`Retention audit trail`)}),r(`span`,{className:`flex items-center gap-1.5`,children:[i(`input`,{type:`number`,min:0,max:3650,step:1,defaultValue:e,disabled:t,onBlur:t=>{let r=Number.parseInt(t.target.value,10);Number.isFinite(r)&&r!==e&&n(r)},className:`w-20 rounded border border-border bg-surface px-2 py-1 text-xs`}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:a(`common.days`,`days`)})]})]}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`logging.levels.opsLogRetentionNote`,`How long the record of what retention deleted is kept. Cluster-wide, and deliberately longer than any camera window — it is the history of the sweep, not of the camera, and it is what makes a storage leak explainable after the fact. 0 keeps it forever.`)})]})}function W({level:e,source:t,persisted:n}){let{t:a}=y();return r(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[r(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-xs text-foreground-subtle`,children:a(`logging.levels.effective`,`In force here`)}),i(`span`,{className:`rounded bg-primary/10 px-2 py-0.5 text-xs font-semibold text-primary`,children:e}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:t==="default"?a(`logging.levels.fromDefault`,`nothing is set anywhere — this is the default`):a(`logging.levels.fromLayer`,`decided by the {{source}} layer`,{source:t})})]}),!n&&i(`p`,{className:`mt-1 text-[11px] text-warning`,children:a(`logging.levels.notPersisted`,`The settings store could not be read or written — what you see is live, but it would not survive a restart.`)})]})}function G({layer:e,inForce:t,busy:n,onSet:a,onClear:s}){let{t:c}=y();return r(`div`,{className:`flex flex-col gap-2 p-3 sm:flex-row sm:items-center sm:justify-between`,children:[r(`div`,{className:`min-w-0`,children:[r(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.scope===`cluster`?c(`logging.levels.cluster`,`Cluster`):e.scope===`component`?e.component??``:e.nodeId??``}),t&&r(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[i(o,{className:`h-3 w-3`}),c(`logging.levels.inForce`,`in force`)]})]}),i(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:e.level===null?c(`logging.levels.inherits`,`inherits — nothing set at this layer`):c(`logging.levels.setHere`,`set here: {{level}}`,{level:e.level})})]}),r(`div`,{className:`flex shrink-0 items-center gap-1`,children:[z.map(t=>i(`button`,{type:`button`,disabled:n,onClick:()=>a(t),className:`rounded px-2 py-1 text-[11px] font-medium transition-colors disabled:opacity-50 ${e.level===t?`bg-primary text-primary-foreground`:`border border-border text-foreground-subtle hover:text-foreground`}`,children:t},t)),i(`button`,{type:`button`,disabled:n||e.level===null,onClick:s,className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-40`,children:c(`logging.levels.clear`,`Clear`)})]})]})}function K(){return i(w,{embedded:!0,children:i(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:i(g,{limit:500,maxHeight:`max-h-[calc(100vh-310px)]`,showScope:!0,showFilters:!0})})})}function q(){let{t:e}=y(),t=b(`/system/logs`,{t:e,isAdmin:!0})??{icon:c,title:e(`system.logs`,`Logs`)};return i(C,{icon:t.icon,title:t.title,defaultSection:`viewer`,sectionsLabel:`${t.title} sections`,sections:[{id:`viewer`,label:e(`admin.system.logs.viewer`,`Viewer`),content:i(K,{})},{id:x.logging.tab,label:e(`admin.system.logs.destinations`,`Destinations`),content:i(M,{}),ownedParams:S},{id:`levels`,label:e(`admin.system.logs.levels`,`Levels`),content:i(H,{})},{id:`diagnostics`,label:e(`admin.system.logs.diagnostics`,`Diagnostics`),content:i(F,{})}]})}export{q as LogsPage};
1
+ import{$ as e,G as t,J as n,S as r,x as i}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Di as a,Si as o,or as s,pn as c,ta as l}from"./player-overlays-Dx9MsPRB.js";import{n as u,t as d}from"./timer-reset-DHDxq-YS.js";import{t as f}from"./layers-Dof6dMwp.js";import{Ql as p,Qu as m,Yl as h,Zt as g,di as _,ui as v}from"./src-D293nH2g.js";import{t as y}from"./useTranslation-D3Is_4B6.js";import{T as b,a as x,i as S}from"./index-D3LY1t1A.js";import{t as C}from"./AdminSectionedPage-CjqX3s11.js";import{t as w}from"./AdminPage-DR77_HbX.js";import{n as T,t as E}from"./IntegrationHub-fFIljDH3.js";import{n as D,t as O}from"./addon-display-names-BkwMrExv.js";e();var k=5e3,A=`log-destination`,j={"winston-logging":`Rotated log files on this node’s disk.`,"console-logging":`stdout / stderr of the node process.`,"loki-logging":`Pushes to a Grafana Loki instance. Off until enabled with a URL.`,"hub-forwarder":`Agent-only — forwards this node’s entries to the hub.`};function M(){let{t:e}=y(),n=_({capName:`log-destination`},{refetchInterval:k}),r=v(void 0,{refetchInterval:k}),a=t(()=>O(r.data??[]),[r.data]),o=t(()=>{let e=new Map;for(let t of r.data??[]){let n=t.description,r=t.id;typeof r==`string`&&typeof n==`string`&&n.length>0&&e.set(r,n)}return e},[r.data]),s=t(()=>(n.data??[]).map(e=>({addonId:e.addonId,displayName:a.get(e.addonId)??e.addonId,isActive:e.isActive,caption:o.get(e.addonId)??j[e.addonId]??``})),[n.data,a,o]),l=[{id:A,label:e(`system.logging.logDestinations`,`Log destinations`),entries:s.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:u,...D(e.isActive),render:()=>i(T,{addonId:e.addonId,displayName:e.displayName,capName:A,isActive:e.isActive,badges:e.caption.length>0?i(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.caption}):null})}))}];return i(E,{embedded:!0,icon:c,title:e(`system.logging.destinations`,`Destinations`),subtitle:e(`system.logging.everyRegisteredLogDestinationEntries`,`Every registered log destination. Entries are fanned to all enabled destinations at once — enabling one does not disable another.`),groups:l,isLoading:n.isLoading,emptyTitle:e(`system.logging.noLogDestinationsRegistered`,`No log destinations registered`),emptyDescription:e(`system.logging.thisShouldNotHappenThe`,`This should not happen — the console and rotated-file destinations are builtins. If the list is empty, the node is still booting.`)})}e();var N=[12e4,3e5,6e5,18e5],P={"request-census":`Counts every tRPC call by TRANSPORT PLANE — http, ws, mesh — and by procedure, caller, address and user-agent. Subscriptions are counted apart from calls, so a long-lived stream cannot pass for a storm. Arm it, then restart: the deadline is persisted, so the window is still running when clients reconnect.`};function F(){let{t:e}=y(),t=h({},{refetchInterval:5e3}),a=p(),[o,c]=n(null),u=(e,n)=>{c(e),a.mutate({patch:{diagnostics:[{id:e,armMs:n}]}},{onSettled:()=>{c(null),t.refetch()}})},d=t.data?.activeWindows??[],f=t.data?.channels??[],m=t.data?.activeChannels??[],g=(e,n,r)=>{c(e),a.mutate({patch:{channels:[{channel:e,armMs:n,deviceIds:r}]}},{onSettled:()=>{c(null),t.refetch()}})};return r(w,{embedded:!0,icon:l,title:e(`logging.diagnostics.title`,`Diagnostics`),subtitle:e(`logging.diagnostics.subtitle`,`Diagnostics are armed for a window, never switched on. Each carries a deadline and expires by itself — one left running is an incident of its own.`),children:[t.isLoading?r(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(s,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}):i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:d.map(e=>i(L,{window:e,busy:o===e.id,onArm:t=>u(e.id,t)},e.id))}),i(`h3`,{className:`mt-6 text-sm font-medium text-foreground`,children:e(`logging.diagnostics.channels`,`Component channels`)}),i(`p`,{className:`mb-2 max-w-3xl text-[11px] text-foreground-subtle`,children:e(`logging.diagnostics.channelsSubtitle`,`Declared by the addons that own them — this list is not maintained by hand. Arming a channel opens a window with a deadline; it closes by itself.`)}),f.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`logging.diagnostics.noChannels`,`No addon on this cluster declares a log channel, or none could be reached right now.`)}):i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:f.map(e=>i(I,{channel:e,state:m.find(t=>t.channel===e.name),busy:o===e.name,onArm:(t,n)=>g(e.name,t,n)},e.name))})]})}function I({channel:e,state:t,busy:o,onArm:s}){let{t:c}=y(),[l,u]=n(``),f=t?.armed===!0,p=()=>{let e=l.split(/[\s,+]+/).filter(e=>/^\d+$/.test(e)).map(e=>Number(e));return e.length>0?e:null};return r(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[r(`div`,{className:`min-w-0`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.name}),f?r(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[i(d,{className:`h-3 w-3`}),c(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:R(t?.remainingMs??0)})]}):i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:c(`logging.diagnostics.disarmed`,`disarmed`)}),f&&t?.deviceIds!==null&&t?.deviceIds!==void 0&&r(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[i(a,{className:`h-3 w-3`}),t.deviceIds.join(`, `)]}),!e.perDevice&&i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:c(`logging.diagnostics.notPerCamera`,`not filterable per camera`)})]}),i(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:e.description})]}),r(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[e.perDevice&&i(`input`,{type:`text`,inputMode:`numeric`,value:l,disabled:o,onChange:e=>u(e.target.value),placeholder:c(`logging.diagnostics.camerasPlaceholder`,`all cameras`),className:`w-28 rounded border border-border bg-surface px-2 py-1 text-[11px] text-foreground`}),N.map(e=>i(`button`,{type:`button`,disabled:o,onClick:()=>s(e,p()),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:R(e)},e)),i(`button`,{type:`button`,disabled:o||!f,onClick:()=>s(0,null),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:c(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function L({window:e,busy:t,onArm:n}){let{t:a}=y();return r(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[r(`div`,{className:`min-w-0`,children:[r(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.id}),e.armed?r(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[i(d,{className:`h-3 w-3`}),a(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:R(e.remainingMs)})]}):i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:a(`logging.diagnostics.disarmed`,`disarmed`)}),e.armed&&!e.persisted&&i(`span`,{className:`text-[10px] text-warning`,children:a(`logging.diagnostics.notPersisted`,`not persisted — will not survive a restart`)})]}),i(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:P[e.id]??``})]}),r(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[N.map(e=>i(`button`,{type:`button`,disabled:t,onClick:()=>n(e),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:R(e)},e)),i(`button`,{type:`button`,disabled:t||!e.armed,onClick:()=>n(0),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:a(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function R(e){let t=Math.max(0,Math.round(e/1e3)),n=Math.floor(t/60),r=t%60;return n===0?`${r}s`:r===0?`${n}m`:`${n}m ${r}s`}e();var z=[`debug`,`info`,`warn`,`error`],B=``,V=``;function H(){let{t:e}=y(),[a,o]=n(B),[c,l]=n(V),{nodes:u}=m(),d=t(()=>u.map(e=>({id:e.id,label:e.name||e.id})),[u]),g=h({...a===B?{}:{scopeNodeId:a},...c===V?{}:{scopeComponent:c}},{refetchInterval:15e3}),_=p(),v=g.data,b=_.isPending||g.isFetching,x=v?.channels??[],S=(e,t)=>{_.mutate({...e.nodeId===null?{}:{scopeNodeId:e.nodeId},...e.component===null?{}:{scopeComponent:e.component},patch:{level:t}},{onSuccess:()=>void g.refetch()})};return i(w,{embedded:!0,icon:f,title:e(`logging.levels.title`,`Levels`),subtitle:e(`logging.levels.subtitle`,`Cluster → node, most specific wins. The floor gates what reaches the log destinations; the in-memory viewer keeps every line either way.`),actions:r(`div`,{className:`flex flex-wrap items-center gap-3`,children:[r(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[e(`logging.levels.scope`,`Scope`),r(`select`,{className:`rounded border border-border bg-surface px-2 py-1 text-xs text-foreground disabled:opacity-50`,value:a,disabled:c!==V,onChange:e=>o(e.target.value),children:[i(`option`,{value:B,children:e(`logging.levels.cluster`,`Cluster`)}),d.map(e=>i(`option`,{value:e.id,children:e.label},e.id))]})]}),r(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[e(`logging.levels.component`,`Component`),r(`select`,{className:`rounded border border-border bg-surface px-2 py-1 text-xs text-foreground`,value:c,onChange:e=>l(e.target.value),children:[i(`option`,{value:V,children:e(`logging.levels.noComponent`,`None`)}),x.map(e=>i(`option`,{value:e.name,children:e.name},e.name))]})]})]}),children:g.isLoading||v===void 0?r(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(s,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}):r(`div`,{className:`space-y-3`,children:[i(W,{level:v.effective.level,source:v.effective.levelSource,persisted:v.persisted}),i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:v.explicit.layers.map(e=>i(G,{layer:e,inForce:e.scope===v.effective.levelSource,busy:b,onSet:t=>S(e,t),onClear:()=>S(e,null)},`${e.scope}:${e.nodeId??e.component??`cluster`}`))}),c!==V&&i(`p`,{className:`text-[11px] text-foreground-subtle`,children:x.find(e=>e.name===c)?.description??``}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`logging.levels.componentNote`,`A component is a log channel an addon declared. Its level is cluster-wide and beats both the node and the cluster layer.`)}),i(U,{days:v.opsLogRetentionDays,busy:b,onSet:e=>_.mutate({patch:{opsLogRetentionDays:e}},{onSuccess:()=>void g.refetch()})})]})})}function U({days:e,busy:t,onSet:n}){let{t:a}=y();return r(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-1`,children:[r(`label`,{className:`flex items-center justify-between gap-3`,children:[i(`span`,{className:`text-xs font-medium`,children:a(`logging.levels.opsLogRetention`,`Retention audit trail`)}),r(`span`,{className:`flex items-center gap-1.5`,children:[i(`input`,{type:`number`,min:0,max:3650,step:1,defaultValue:e,disabled:t,onBlur:t=>{let r=Number.parseInt(t.target.value,10);Number.isFinite(r)&&r!==e&&n(r)},className:`w-20 rounded border border-border bg-surface px-2 py-1 text-xs`}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:a(`common.days`,`days`)})]})]}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`logging.levels.opsLogRetentionNote`,`How long the record of what retention deleted is kept. Cluster-wide, and deliberately longer than any camera window — it is the history of the sweep, not of the camera, and it is what makes a storage leak explainable after the fact. 0 keeps it forever.`)})]})}function W({level:e,source:t,persisted:n}){let{t:a}=y();return r(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[r(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-xs text-foreground-subtle`,children:a(`logging.levels.effective`,`In force here`)}),i(`span`,{className:`rounded bg-primary/10 px-2 py-0.5 text-xs font-semibold text-primary`,children:e}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:t==="default"?a(`logging.levels.fromDefault`,`nothing is set anywhere — this is the default`):a(`logging.levels.fromLayer`,`decided by the {{source}} layer`,{source:t})})]}),!n&&i(`p`,{className:`mt-1 text-[11px] text-warning`,children:a(`logging.levels.notPersisted`,`The settings store could not be read or written — what you see is live, but it would not survive a restart.`)})]})}function G({layer:e,inForce:t,busy:n,onSet:a,onClear:s}){let{t:c}=y();return r(`div`,{className:`flex flex-col gap-2 p-3 sm:flex-row sm:items-center sm:justify-between`,children:[r(`div`,{className:`min-w-0`,children:[r(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.scope===`cluster`?c(`logging.levels.cluster`,`Cluster`):e.scope===`component`?e.component??``:e.nodeId??``}),t&&r(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[i(o,{className:`h-3 w-3`}),c(`logging.levels.inForce`,`in force`)]})]}),i(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:e.level===null?c(`logging.levels.inherits`,`inherits — nothing set at this layer`):c(`logging.levels.setHere`,`set here: {{level}}`,{level:e.level})})]}),r(`div`,{className:`flex shrink-0 items-center gap-1`,children:[z.map(t=>i(`button`,{type:`button`,disabled:n,onClick:()=>a(t),className:`rounded px-2 py-1 text-[11px] font-medium transition-colors disabled:opacity-50 ${e.level===t?`bg-primary text-primary-foreground`:`border border-border text-foreground-subtle hover:text-foreground`}`,children:t},t)),i(`button`,{type:`button`,disabled:n||e.level===null,onClick:s,className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-40`,children:c(`logging.levels.clear`,`Clear`)})]})]})}function K(){return i(w,{embedded:!0,children:i(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:i(g,{limit:500,maxHeight:`max-h-[calc(100vh-310px)]`,showScope:!0,showFilters:!0})})})}function q(){let{t:e}=y(),t=b(`/system/logs`,{t:e,isAdmin:!0})??{icon:c,title:e(`system.logs`,`Logs`)};return i(C,{icon:t.icon,title:t.title,defaultSection:`viewer`,sectionsLabel:`${t.title} sections`,sections:[{id:`viewer`,label:e(`admin.system.logs.viewer`,`Viewer`),content:i(K,{})},{id:x.logging.tab,label:e(`admin.system.logs.destinations`,`Destinations`),content:i(M,{}),ownedParams:S},{id:`levels`,label:e(`admin.system.logs.levels`,`Levels`),content:i(H,{})},{id:`diagnostics`,label:e(`admin.system.logs.diagnostics`,`Diagnostics`),content:i(F,{})}]})}export{q as LogsPage};