@camstack/addon-admin-ui 1.2.428 → 1.2.429

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 (167) hide show
  1. package/dist/assets/{AddonAssetIcon-Cs_blBpK.js → AddonAssetIcon-DR35yt0E.js} +1 -1
  2. package/dist/assets/Addons-gkGgGpTC.js +4 -0
  3. package/dist/assets/{AdminPage-DuuyDIsY.js → AdminPage-DAO24U0w.js} +1 -1
  4. package/dist/assets/AdminSectionedPage-B-qoE6ra.js +1 -0
  5. package/dist/assets/AiProfiles-BXcreqZP.js +3 -0
  6. package/dist/assets/BrokerForm-B3xs9aBj.js +1 -0
  7. package/dist/assets/Build-DeMAJfjN.js +40 -0
  8. package/dist/assets/Calendars-VPH-vy-o.js +1 -0
  9. package/dist/assets/Cluster-B-k0M79z.js +1 -0
  10. package/dist/assets/ClusterStepModel-DaAc_6nI.js +1 -0
  11. package/dist/assets/CompositionEditor-BrtLjoSu.js +1 -0
  12. package/dist/assets/{CompositionEditorPage-Acq7iapA.js → CompositionEditorPage-D51jS9td.js} +1 -1
  13. package/dist/assets/Data-IfJuKcwc.js +2 -0
  14. package/dist/assets/DeviceDetail-D1qU_p1k.js +2 -0
  15. package/dist/assets/DeviceDoActionFields-B62Nv4K7.js +1 -0
  16. package/dist/assets/Devices-Cf5Exjsk.js +1 -0
  17. package/dist/assets/{EmbedPlayerPage-RXOmf2F3.js → EmbedPlayerPage-CnEcSJ8D.js} +1 -1
  18. package/dist/assets/Identity-DNE80jdX.js +1 -0
  19. package/dist/assets/IntegrationDetail-LKbiJFU3.js +1 -0
  20. package/dist/assets/IntegrationHub-DdjWEObX.js +1 -0
  21. package/dist/assets/Integrations-CU7Ll9U_.js +1 -0
  22. package/dist/assets/Integrations-uZB2ozhn.js +1 -0
  23. package/dist/assets/Library-DSuCaXt6.js +1 -0
  24. package/dist/assets/Locations-BeaznsZS.js +3 -0
  25. package/dist/assets/{Logs-DIeXeCqI.js → Logs-cm-1R2Z4.js} +1 -1
  26. package/dist/assets/MaskShapeCanvas-CM9D4FOf.js +1 -0
  27. package/dist/assets/MotionZonesSettings-DqS8ndiK.js +1 -0
  28. package/dist/assets/MyAccess-Dxb11B6h.js +2 -0
  29. package/dist/assets/Network-BCDUHSB0.js +1 -0
  30. package/dist/assets/NodeAddonsSettingsPanel-BMat4ckt.js +1 -0
  31. package/dist/assets/Notifications-EPQiEZ1t.js +1 -0
  32. package/dist/assets/PrivacyMaskSettings-Bis0PO01.js +1 -0
  33. package/dist/assets/Recordings-BCeoXxL4.js +1 -0
  34. package/dist/assets/ScanNetworkModal-dHWFmbFe.js +1 -0
  35. package/dist/assets/SceneMonitorEditor-SFMMIopn.js +1 -0
  36. package/dist/assets/SessionsList-BRTwG3uv.js +2 -0
  37. package/dist/assets/{Showroom-W2yJvb8s.js → Showroom-Er-hes9K.js} +1 -1
  38. package/dist/assets/System-BDXxfgsq.js +1 -0
  39. package/dist/assets/{Terminal-CrFum1tE.js → Terminal-B70jnm8e.js} +4 -4
  40. package/dist/assets/{Viewer-YBzeS3RA.js → Viewer-BsGL5Dfa.js} +1 -1
  41. package/dist/assets/_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-C7iEnSHU.js +1 -0
  42. package/dist/assets/_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js +1 -0
  43. package/dist/assets/_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DdJYWyu3.js +1 -0
  44. package/dist/assets/{_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.js-BsvPG3BX.js → _virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.js-DPkvGqVU.js} +1 -1
  45. package/dist/assets/{_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-DtoGixA1.js → _virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-Cb2QlpvS.js} +1 -1
  46. package/dist/assets/{_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_konva__loadShare__.js-PmiLsYEK.js → _virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_konva__loadShare__.js-Cyj0Xie_.js} +4 -4
  47. package/dist/assets/{addon-icons-context-D6glxUQF.js → addon-icons-context--6Hi3qRW.js} +1 -1
  48. package/dist/assets/{archive-kvflMCgL.js → archive-DtcjevJM.js} +1 -1
  49. package/dist/assets/{authed-media-CSlndmzS.js → authed-media-LCmlAEZ5.js} +1 -1
  50. package/dist/assets/{bell-off-BYnwGeiH.js → bell-off-eQBpwamg.js} +1 -1
  51. package/dist/assets/board-model-wzCmdEKJ.js +1 -0
  52. package/dist/assets/{boxes-Dx4USyB3.js → boxes-DikDfAoo.js} +1 -1
  53. package/dist/assets/circle-slash-YVgGJTpJ.js +1 -0
  54. package/dist/assets/client-DYbvGOid.js +358 -0
  55. package/dist/assets/{cloud-upload-82x5w5u8.js → cloud-upload-DI9XunFf.js} +1 -1
  56. package/dist/assets/crop-CxZbpOyK.js +1 -0
  57. package/dist/assets/{device-integration-icon-bTnWrYe0.js → device-integration-icon-D2lWVDM2.js} +1 -1
  58. package/dist/assets/device-picker-model-C4w1vbly.js +1 -0
  59. package/dist/assets/dist-CPO0KWoy.js +358 -0
  60. package/dist/assets/dist-ChQzskeX.js +1 -0
  61. package/dist/assets/{eraser-B8Awx5Sj.js → eraser-Dl5ROV0l.js} +1 -1
  62. package/dist/assets/{file-up-LqDVgVVa.js → file-up-WS3s_T9x.js} +1 -1
  63. package/dist/assets/{hard-drive-download-C24D80x2.js → hard-drive-download-B1ard6ym.js} +1 -1
  64. package/dist/assets/{history-DZsORyBG.js → history-BMhP0SFG.js} +1 -1
  65. package/dist/assets/{hostInit-D2EmEDvv.js → hostInit-FCvre9AW.js} +1 -1
  66. package/dist/assets/i18n-Vb3uBp7P.js +1 -0
  67. package/dist/assets/{icons-D5RaCH1q.js → icons-DocdgFuy.js} +1 -1
  68. package/dist/assets/index-DKqvG7BE.css +2 -0
  69. package/dist/assets/index-DvOECbab.js +4 -0
  70. package/dist/assets/{key-DLwSBrPM.js → key-B1M6i1mf.js} +1 -1
  71. package/dist/assets/{key-round-CYflkUyd.js → key-round-yCDTbIQb.js} +1 -1
  72. package/dist/assets/{layers-C1wzFfr1.js → layers-c960YTPf.js} +1 -1
  73. package/dist/assets/linked-devices-model-CB7qgVjI.js +1 -0
  74. package/dist/assets/{list-ordered-CFeS9o_w.js → list-ordered-C7hEwAd1.js} +1 -1
  75. package/dist/assets/location-owned-usage-D28vwYJT.js +1 -0
  76. package/dist/assets/{log-in-Be_RcxDr.js → log-in-DFfxcqYz.js} +1 -1
  77. package/dist/assets/{memory-stick-4BwYEagi.js → memory-stick-BBfIGrWx.js} +1 -1
  78. package/dist/assets/{message-square-plus-D7BNG3h7.js → message-square-plus-D8ZUT6rz.js} +1 -1
  79. package/dist/assets/{mf-entry-bootstrap-0-9df0d08c.js → mf-entry-bootstrap-0-3035e647.js} +2 -2
  80. package/dist/assets/{mic-off-e162Bcfu.js → mic-off-w2mFOBi3.js} +1 -1
  81. package/dist/assets/{monitor-off-CARYfHC4.js → monitor-off-DPi_gm_c.js} +1 -1
  82. package/dist/assets/{monitor-smartphone-lsNgnRRZ.js → monitor-smartphone-9Ife1Trw.js} +1 -1
  83. package/dist/assets/mount-C4w1vbly.js +1 -0
  84. package/dist/assets/notification-schedule-field-BuLfSYLZ.js +1 -0
  85. package/dist/assets/{octagon-alert-h80nyWRM.js → octagon-alert-C-jH7VH_.js} +1 -1
  86. package/dist/assets/player-overlays-D0U2dNvn.js +1 -0
  87. package/dist/assets/{recycle-0MLWppmT.js → recycle-Bbki65G2.js} +1 -1
  88. package/dist/assets/remoteEntry-DYVoozgD.js +1 -0
  89. package/dist/assets/{scan-eye-DVK8MF3K.js → scan-eye-AfIM_Dlr.js} +1 -1
  90. package/dist/assets/{scissors-Cz3GoeOd.js → scissors-CnL6g0BO.js} +1 -1
  91. package/dist/assets/{search-x-i_A-Upbe.js → search-x-eqJd3G8u.js} +1 -1
  92. package/dist/assets/{send-B5VKcNUH.js → send-B72RQ9UL.js} +1 -1
  93. package/dist/assets/{settings-2-ZQsYJ0Zb.js → settings-2-CXZ6DVRg.js} +1 -1
  94. package/dist/assets/{speaker-Cl8DZGk_.js → speaker-CcCWWecW.js} +1 -1
  95. package/dist/assets/src-CGxdJN_f.js +67 -0
  96. package/dist/assets/{timer-reset-A5ofAkBW.js → timer-reset-B9Lihcw9.js} +1 -1
  97. package/dist/assets/{ungroup-t0yDnzVf.js → ungroup-D753owNE.js} +1 -1
  98. package/dist/assets/{unlink-C1ZpCxl3.js → unlink-DzoLNfsq.js} +1 -1
  99. package/dist/assets/{usb-DmUPajSy.js → usb-CuSU-_EY.js} +1 -1
  100. package/dist/assets/{use-scenes-feed-BQlYhRMq.js → use-scenes-feed-CZjJNxfD.js} +1 -1
  101. package/dist/assets/{use-stationary-objects-BWM4vE0E.js → use-stationary-objects-BoGqWyLV.js} +1 -1
  102. package/dist/assets/useEventInvalidation-C4w1vbly.js +1 -0
  103. package/dist/assets/useNodeUrlSelection-BA6CgjTU.js +1 -0
  104. package/dist/assets/useTranslation-D3Is_4B6.js +1 -0
  105. package/dist/assets/user-round-CMg3Ndlt.js +1 -0
  106. package/dist/assets/{user-x-DRcPeM9C.js → user-x-PK8sSsso.js} +1 -1
  107. package/dist/assets/{video-tLHyNE3q.js → video-BBtESt54.js} +1 -1
  108. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DOOXjnRq.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BKfTL-9e.js} +2 -2
  109. package/dist/index.html +12 -12
  110. package/dist/server/addon.js +174 -5
  111. package/package.json +1 -1
  112. package/dist/assets/Addons-2xWF73cR.js +0 -4
  113. package/dist/assets/AdminSectionedPage-C3VHg80L.js +0 -1
  114. package/dist/assets/AiProfiles-DmHcVlS2.js +0 -3
  115. package/dist/assets/BrokerForm-Dqhjsi3Y.js +0 -1
  116. package/dist/assets/Build-CBYP1fT5.js +0 -40
  117. package/dist/assets/Calendars-C926x7b_.js +0 -1
  118. package/dist/assets/Cluster-OZlA14uV.js +0 -1
  119. package/dist/assets/ClusterStepModel-DHbwIGAW.js +0 -1
  120. package/dist/assets/CompositionEditor-vP3JcV2R.js +0 -1
  121. package/dist/assets/Data-7BoejvKA.js +0 -1
  122. package/dist/assets/DeviceDetail-ByM0856T.js +0 -2
  123. package/dist/assets/DeviceDoActionFields-BDJsvRNX.js +0 -1
  124. package/dist/assets/Devices-PIrWjfhq.js +0 -1
  125. package/dist/assets/Identity-C-tztwfa.js +0 -1
  126. package/dist/assets/IntegrationDetail-DugB7cv6.js +0 -1
  127. package/dist/assets/IntegrationHub-BePMbmC5.js +0 -1
  128. package/dist/assets/Integrations-Dj3nT9ZT.js +0 -1
  129. package/dist/assets/Integrations-OH5z-t03.js +0 -1
  130. package/dist/assets/Library-DDNti2te.js +0 -1
  131. package/dist/assets/Locations-OL9_NoSi.js +0 -3
  132. package/dist/assets/MaskShapeCanvas-Dcpby34M.js +0 -1
  133. package/dist/assets/MotionZonesSettings-CfTOerul.js +0 -1
  134. package/dist/assets/MyAccess-iJP3JQIS.js +0 -2
  135. package/dist/assets/Network-DYssxNiN.js +0 -1
  136. package/dist/assets/NodeAddonsSettingsPanel-mmtEgDbu.js +0 -1
  137. package/dist/assets/Notifications-DEcxFWp3.js +0 -1
  138. package/dist/assets/PrivacyMaskSettings-CJUKFEIs.js +0 -1
  139. package/dist/assets/Recordings-lygSYEJj.js +0 -1
  140. package/dist/assets/ScanNetworkModal-C2oJlLfj.js +0 -1
  141. package/dist/assets/SceneMonitorEditor-D1S-D2V9.js +0 -1
  142. package/dist/assets/SessionsList-CIN4GdSm.js +0 -2
  143. package/dist/assets/System-ChWpOOqN.js +0 -1
  144. package/dist/assets/_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CE2IIKhe.js +0 -1
  145. package/dist/assets/_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js +0 -1
  146. package/dist/assets/_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DX7sYWrs.js +0 -1
  147. package/dist/assets/board-model-Bmts6hrg.js +0 -1
  148. package/dist/assets/circle-slash-D5mo-8G0.js +0 -1
  149. package/dist/assets/client-CMlUvfoK.js +0 -358
  150. package/dist/assets/crop-Dev61hIh.js +0 -1
  151. package/dist/assets/device-picker-model-DlnG_8P7.js +0 -1
  152. package/dist/assets/dist--5X8Gy0U.js +0 -1
  153. package/dist/assets/dist-Dod19ois.js +0 -358
  154. package/dist/assets/i18n-vggiB6gm.js +0 -1
  155. package/dist/assets/index-BgQGn3LX.js +0 -4
  156. package/dist/assets/index-BndCgmxf.css +0 -2
  157. package/dist/assets/linked-devices-model-CCTQ_gka.js +0 -1
  158. package/dist/assets/location-owned-usage-DSLiI6RY.js +0 -1
  159. package/dist/assets/mount-DlnG_8P7.js +0 -1
  160. package/dist/assets/notification-schedule-field-DWpT_5Vh.js +0 -1
  161. package/dist/assets/player-overlays-Cda8wso6.js +0 -1
  162. package/dist/assets/remoteEntry-V_83-NrI.js +0 -1
  163. package/dist/assets/src-eoSUZcV-.js +0 -67
  164. package/dist/assets/useEventInvalidation-DlnG_8P7.js +0 -1
  165. package/dist/assets/useNodeUrlSelection-CTxv9Em7.js +0 -1
  166. package/dist/assets/useTranslation-Bc5yH9V9.js +0 -1
  167. package/dist/assets/user-round-BTaID248.js +0 -1
@@ -1 +0,0 @@
1
- import{I as e,K as t,Q as n,S as r,W as i,X as a,a as o,b as s,o as c,q as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{At as f,Ci as p,D as m,Di as h,Dt as g,Hr as _,It as v,Jt as y,Nr as b,Nt as x,On as S,Pn as C,Q as w,Qi as T,Ut as E,Xt as D,Yr as O,Z as k,_i as A,_n as j,ar as M,bi as N,c as P,dn as F,dt as I,f as L,gr as R,l as z,ot as ee,pn as B,qt as V,ri as H,rr as U,u as W,vi as G,wi as te,wr as K,yi as q,yn as ne,z as re}from"./player-overlays-Cda8wso6.js";import{a as J,c as ie,i as ae,n as oe,o as se,r as ce,s as le,t as ue}from"./user-x-DRcPeM9C.js";import{s as de}from"./video-tLHyNE3q.js";import{t as fe}from"./crop-Dev61hIh.js";import{t as pe}from"./user-round-BTaID248.js";import{Ti as me,Un as he}from"./client-CMlUvfoK.js";import{$a as ge,An as _e,Bn as Y,Cc as ve,Dn as ye,Dr as be,G as xe,Ga as Se,Hl as Ce,Ht as we,I as Te,It as Ee,Ja as De,Ka as Oe,Kl as ke,Ko as Ae,L as je,Ln as Me,Nt as Ne,On as Pe,Pn as Fe,Pt as Ie,Qa as Le,Ql as Re,Qn as ze,Rn as Be,Sc as Ve,Tn as He,Ul as Ue,Ut as We,Vt as Ge,Wa as Ke,Xa as qe,Xn as Je,Ya as Ye,Za as Xe,Zl as Ze,Zn as Qe,_c as $e,_s as et,ar as tt,bc as nt,cs as rt,ds as it,eo as at,fc as ot,fn as st,fs as ct,gc as lt,gs as ut,gu as dt,hc as ft,ir as pt,jn as mt,kn as ht,ma as gt,mc as _t,ms as vt,no as yt,pc as bt,pt as xt,qa as St,rr as Ct,t as wt,to as Tt,us as Et,vc as Dt,wc as Ot,xc as kt,yc as At,z as jt}from"./src-eoSUZcV-.js";import{t as Mt}from"./i18n-vggiB6gm.js";import{t as X}from"./useTranslation-Bc5yH9V9.js";import"./mount-DlnG_8P7.js";import{C as Nt,Q as Pt,X as Ft,Y as It}from"./index-BgQGn3LX.js";import{t as Lt}from"./AdminSectionedPage-C3VHg80L.js";import{t as Rt}from"./use-stationary-objects-BWM4vE0E.js";import{a as zt,i as Bt,n as Vt,r as Ht,t as Ut}from"./authed-media-CSlndmzS.js";import{t as Wt}from"./use-scenes-feed-BQlYhRMq.js";n();function Gt({mediaId:e,base64:t,alt:n,className:r,placeholder:i}){let{src:a,failed:o}=zt(e===void 0?void 0:Ht(e));return a===null?(e===void 0||o)&&t!==void 0&&t!==``?u(`img`,{src:`data:image/jpeg;base64,${t}`,alt:n,className:r}):i:u(`img`,{src:a,alt:n,className:r})}var Kt=`pipeline-analytics`,qt=`photo.analyze`,Jt=`photo.enroll`,Yt=`photo.discard`,Xt=18*1024*1024;function Zt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Qt(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function $t(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function en(e,t){let n=e[t];return typeof n==`boolean`?n:null}function tn(e){if(!Zt(e))return null;let t=$t(e,`x`),n=$t(e,`y`),r=$t(e,`width`),i=$t(e,`height`);return t===null||n===null||r===null||i===null?null:{x:t,y:n,width:r,height:i}}function nn(e){if(!Zt(e))return null;let t=$t(e,`detectionShortSidePx`),n=$t(e,`score`);if(t===null||n===null)return null;let r=$t(e,`magnitude`);return{detectionShortSidePx:t,score:n,...r===null?{}:{magnitude:r}}}function rn(e){if(!Zt(e))return null;let t=$t(e,`faceIndex`),n=$t(e,`score`),r=en(e,`enrollable`),i=tn(e.bbox),a=nn(e.quality);if(t===null||n===null||r===null||i===null||a===null)return null;let o=Qt(e,`refusedReason`),s=Qt(e,`alignedCropBase64`),c=Qt(e,`modelId`);return{faceIndex:t,bbox:i,score:n,enrollable:r,quality:a,...o===null?{}:{refusedReason:o},...s===null?{}:{alignedCropBase64:s},...c===null?{}:{modelId:c}}}function an(e){if(!Zt(e))return null;let t=Qt(e,`sessionId`),n=Qt(e,`ranOnNodeId`),r=e.faces;if(t===null||n===null||!Array.isArray(r))return null;let i=[];for(let e of r){let t=rn(e);t!==null&&i.push(t)}return{sessionId:t,ranOnNodeId:n,faces:i}}function on(e){if(!Zt(e))return null;let t=Qt(e,`sampleId`),n=Qt(e,`identityId`),r=Qt(e,`modelId`);return t===null||n===null||r===null?null:{sampleId:t,identityId:n,modelId:r}}function sn(e,t,n){let r={...e};return n===null||n===``?delete r[t]:r[t]=n,r}function cn(e,t){return e.filter(e=>e.enrollable&&t[e.faceIndex]!==void 0).length}function ln(e,t,n){let r=[];for(let i of t){if(!i.enrollable)continue;let t=n[i.faceIndex];t!==void 0&&r.push({sessionId:e,faceIndex:i.faceIndex,identityId:t})}return r}function un(e){switch(e){case`no-embedding`:return`Too small or too indistinct for the recognizer to measure — try a photo where this face is larger.`;case`no-model-id`:return`The recognizer did not report which model it used, so this face cannot be enrolled safely.`;case`no-aligned-crop`:return`The recognizer produced no aligned crop for this face, so there is nothing to store.`;case`magnitude`:return`Refused by the quality gate: the features look degenerate, and a sample like this matches everybody.`;default:return`This face is not usable as a sample.`}}function dn(e,t){let n=[],r=[];for(let i of e)i.size>t.maxBytes?n.push(i.name):r.push(i);return{accepted:r.slice(0,t.maxCount),oversize:n,overflow:r.slice(t.maxCount).map(e=>e.name)}}async function fn(e,t,n){let r=Array(e.length),i=e.map((e,t)=>({item:e,index:t})),a=0,o=async()=>{for(;;){let e=i[a];if(a+=1,e===void 0)return;r[e.index]=await n(e.item,e.index)}},s=Array.from({length:Math.max(1,Math.min(t,e.length))},()=>o());return await Promise.all(s),r}function pn(e,t,n){return e.map(e=>e.photoIndex===t?{...e,...n}:e)}function mn(e,t){return`${e}:${t}`}function hn(e,t,n,r){let i=sn(e[t]??{},n,r),a={...e};return Object.keys(i).length===0?delete a[t]:a[t]=i,a}function gn(e,t){let n=0;for(let r of e)r.analysis!==void 0&&(n+=cn(r.analysis.faces,t[r.photoIndex]??{}));return n}var _n=`__new__`;function vn(e,t,n){let r=[];for(let i of e){if(i.analysis===void 0)continue;let e=t[i.photoIndex]??{};for(let t of i.analysis.faces){if(!t.enrollable||e[t.faceIndex]!==`__new__`)continue;let a=(n[mn(i.photoIndex,t.faceIndex)]??``).trim();if(a===``)return{kind:`error`,message:`${i.filename}: face ${t.faceIndex+1} is set to a new person but has no name.`};r.includes(a)||r.push(a)}}return{kind:`ok`,names:r}}function yn(e,t,n){let r={};for(let[i,a]of Object.entries(e)){let e=Number(i),o={};for(let[r,i]of Object.entries(a)){let a=Number(r);if(i!==`__new__`){o[a]=i;continue}let s=n[(t[mn(e,a)]??``).trim()];s!==void 0&&(o[a]=s)}r[e]=o}return r}function bn(e,t){let n=[];for(let r of e){if(r.analysis===void 0)continue;let e=ln(r.analysis.sessionId,r.analysis.faces,t[r.photoIndex]??{});for(let t of e)n.push({photoIndex:r.photoIndex,request:t})}return n}function xn(e){return/expired/i.test(e)}function Sn(e){return e instanceof Error?e.message:String(e)}async function Cn(e,t,n){let r=new Map(e.map(e=>[e.photoIndex,e])),i={},a=[],o=0,s=null,c=(e,t)=>`${r.get(e)?.filename??`photo ${e+1}`}, face ${t+1}`;for(let l of bn(e,t)){let e=i[l.photoIndex],t=e===void 0?l.request:{...l.request,sessionId:e.sessionId};try{let e=await n.enroll(t);o+=1,s=e.modelId}catch(t){let u=Sn(t);if(!xn(u)||e!==void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${u}`);continue}let d=r.get(l.photoIndex);if(d===void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${u}`);continue}let f;try{f=await n.reanalyze(d)}catch(e){a.push(`${c(l.photoIndex,l.request.faceIndex)}: the analysis expired and re-analysing failed (${Sn(e)})`);continue}if(i[l.photoIndex]=f,f.faces.find(e=>e.faceIndex===l.request.faceIndex&&e.enrollable)===void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: the analysis expired, and re-analysing no longer finds this face — assign it again from the fresh result`);continue}try{let e=await n.enroll({...l.request,sessionId:f.sessionId});o+=1,s=e.modelId}catch(e){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${Sn(e)}`)}}}return{enrolled:o,stampedModelId:s,failures:a,refreshedAnalyses:i}}var wn=[[`faceGallery`]],Tn=``;function En(e){return new Promise((t,n)=>{let r=new FileReader;r.addEventListener(`error`,()=>n(Error(`the file could not be read`)),{once:!0}),r.addEventListener(`load`,()=>{let e=r.result;if(typeof e!=`string`){n(Error(`the file could not be read`));return}let i=e.indexOf(`,`);t(i>=0?e.slice(i+1):e)},{once:!0}),r.readAsDataURL(e)})}function Dn(e){return e instanceof Error?e.message:String(e)}function On({face:e,identities:t,value:n,onChange:a,disabled:o}){let{t:c}=X(),l=i(()=>[{value:Tn,label:c(`detectionIntelligence.photoEnrollDialog.ignoreThisFace`,`Ignore this face`)},...t.map(e=>({value:e.id,label:e.name})),{value:_n,label:c(`detectionIntelligence.photoEnrollDialog.newPerson`,`+ New person…`)}],[t,c]);return r(`div`,{className:`rounded-md border border-border bg-surface p-2`,children:[u(`div`,{className:`mb-2 aspect-square w-full overflow-hidden rounded border border-border bg-surface-hover`,children:e.alignedCropBase64?u(`img`,{src:`data:image/jpeg;base64,${e.alignedCropBase64}`,alt:c(`detectionIntelligence.photoEnrollDialog.face`,`Face {{value1}}`,{value1:e.faceIndex+1}),className:`h-full w-full object-cover`}):u(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:u(pe,{className:`h-8 w-8`})})}),u(`div`,{className:`min-h-[4.75rem]`,children:e.enrollable?r(s,{children:[u(ke,{options:l,value:n,disabled:o,onChange:e=>a(e.target.value),"aria-label":c(`detectionIntelligence.photoEnrollDialog.assignFace`,`Assign face {{value1}}`,{value1:e.faceIndex+1})}),r(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:[Math.round(e.quality.detectionShortSidePx),` px`,e.modelId?` · ${e.modelId}`:``]})]}):r(`div`,{className:`space-y-1`,children:[u(tt,{variant:`warning`,className:`text-[10px]`,children:c(`detectionIntelligence.photoEnrollDialog.notUsable`,`Not usable`)}),u(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:un(e.refusedReason)})]})})]})}function kn({photo:e,identities:t,draft:n,newNames:i,disabled:a,onAssign:o,onNameChange:s,onRetry:c}){let{t:l}=X(),d=e.analysis?.faces??[],f=n[e.photoIndex]??{};return r(`div`,{className:`space-y-2`,children:[r(`div`,{className:`flex items-center gap-2 border-b border-border pb-1`,children:[u(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.filename}),e.status===`analyzing`||e.status===`queued`?r(`span`,{className:`flex items-center gap-1 text-xs text-foreground-subtle`,children:[u(M,{className:`h-3 w-3 animate-spin`}),` analysing…`]}):null,e.status===`analyzed`&&e.analysis!==void 0&&r(`span`,{className:`text-xs text-foreground-subtle`,children:[d.length,` face`,d.length===1?``:`s`,` · analysed on`,` `,e.analysis.ranOnNodeId]}),e.status===`failed`&&r(Y,{variant:`secondary`,size:`sm`,disabled:a,onClick:c,children:[u(j,{className:`h-3 w-3`}),` Retry`]})]}),e.status===`failed`&&r(`div`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[u(x,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),r(`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`&&d.length===0&&u(`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.`)}),d.length>0&&u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(7rem,7rem))] justify-start gap-3`,children:d.map(e=>u(On,{face:e,identities:t,value:f[e.faceIndex]??Tn,disabled:a,onChange:t=>o(e.faceIndex,t)},e.faceIndex))}),d.filter(e=>f[e.faceIndex]===_n).map(t=>r(`div`,{className:`flex items-center gap-2`,children:[r(`span`,{className:`w-28 shrink-0 truncate text-xs text-foreground-subtle`,children:[`Face `,t.faceIndex+1]}),u(`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:i[mn(e.photoIndex,t.faceIndex)]??``,onChange:e=>s(t.faceIndex,e.target.value)})]},t.faceIndex))]})}function An({open:n,onOpenChange:a}){let{t:o}=X(),s=ee(),d=c(),f=t(null),{data:p}=Ye(),m=Se(),[h,g]=l([]),[_,v]=l(!1),[y,b]=l(null),[S,C]=l({}),[w,T]=l({}),[E,D]=l(null),O=i(()=>(p??[]).map(e=>({id:e.id,name:e.name})),[p]),k=h.some(e=>e.status===`queued`||e.status===`analyzing`),A=k||_,j=e(e=>{for(let t of e){let e=t.analysis?.sessionId;e!==void 0&&s.trpcClient.addons.custom.mutate({addonId:Kt,action:Yt,input:{sessionId:e}}).catch(()=>void 0)}},[s]),N=e(()=>{g([]),C({}),T({}),b(null),D(null),f.current&&(f.current.value=``)},[]),P=e(()=>{j(h),N(),a(!1)},[j,a,h,N]),F=e(async e=>{let t=an(await s.trpcClient.addons.custom.mutate({addonId:Kt,action:qt,input:{photoBase64:e.photoBase64,filename:e.filename}}));if(t===null)throw Error(`the server replied with something this page could not read`);return t},[s]),I=e(async e=>{g(t=>pn(t,e.photoIndex,{status:`analyzing`,error:void 0}));try{let t=await F(e);g(n=>pn(n,e.photoIndex,{status:`analyzed`,analysis:t}))}catch(t){g(n=>pn(n,e.photoIndex,{status:`failed`,error:Dn(t)}))}},[F]),L=e(async e=>{if(e.length===0)return;j(h),N();let t=dn(e,{maxCount:12,maxBytes:Xt}),n=[];t.oversize.length>0&&n.push(`Over the ${Math.round(Xt/(1024*1024))} MB limit and skipped: ${t.oversize.join(`, `)}.`),t.overflow.length>0&&n.push(`A batch holds at most 12 photos — not analysed: ${t.overflow.join(`, `)}. Enrol them in a second round.`),n.length>0&&b(n.join(` `));let r;try{r=await Promise.all(t.accepted.map(async(e,t)=>({photoIndex:t,filename:e.name,photoBase64:await En(e),status:`queued`})))}catch(e){b(Dn(e));return}g(r),await fn(r,2,e=>I(e))},[j,h,N,I]),R=gn(h,S),z=e(async()=>{v(!0),b(null),D(null);try{let e=vn(h,S,w);if(e.kind===`error`){b(e.message);return}let t={};for(let n of e.names)t[n]=(await m.mutateAsync({name:n})).id;let n=await Cn(h,yn(S,w,t),{enroll:async e=>{let t=on(await s.trpcClient.addons.custom.mutate({addonId:Kt,action:Jt,input:e}));if(t===null)throw Error(`unreadable reply`);return t},reanalyze:e=>F(e)});Object.keys(n.refreshedAnalyses).length>0&&g(e=>e.map(e=>{let t=n.refreshedAnalyses[e.photoIndex];return t===void 0?e:{...e,status:`analyzed`,analysis:t}})),d.invalidateQueries({queryKey:wn}),n.failures.length>0&&b(n.failures.join(` · `)),D(n.enrolled===0?`Nothing was enrolled.`:`Enrolled ${n.enrolled} sample${n.enrolled===1?``:`s`}${n.stampedModelId===null?``:` with ${n.stampedModelId}`}.`)}catch(e){b(Dn(e))}finally{v(!1)}},[F,m,S,w,h,d,s]),B=h.filter(e=>e.status===`analyzed`).length;return u(He,{open:n,onOpenChange:e=>e?a(!0):P(),children:r(ye,{className:`max-w-3xl`,children:[r(_e,{children:[u(mt,{children:o(`detectionIntelligence.photoEnrollDialog.enrolFromPhotos`,`Enrol from photos`)}),u(Pe,{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.`)})]}),r(`div`,{className:`rounded-md border border-border bg-surface-hover px-3 py-2 text-xs text-foreground-subtle`,children:[`For reliable recognition use`,` `,u(`strong`,{children:o(`detectionIntelligence.photoEnrollDialog.atLeast3PhotosPer`,`at least 3 photos per person`)}),`, taken at different times, with different poses and lighting — you can select them all at once. Several frames from the same moment count as one — they do not add information.`]}),r(`div`,{className:`flex items-center gap-2`,children:[u(`input`,{ref:f,type:`file`,accept:`image/jpeg,image/png,image/webp`,multiple:!0,className:`hidden`,onChange:e=>void L(Array.from(e.target.files??[]))}),r(Y,{variant:`secondary`,size:`sm`,disabled:A,onClick:()=>f.current?.click(),children:[k?u(M,{className:`h-3.5 w-3.5 animate-spin`}):u(se,{className:`h-3.5 w-3.5`}),o(`detectionIntelligence.photoEnrollDialog.choosePhotos`,`Choose photos`)]}),h.length>0&&r(`span`,{className:`text-xs text-foreground-subtle`,children:[B,`/`,h.length,` photo`,h.length===1?``:`s`,` analysed`]})]}),u(`div`,{className:`min-h-11`,"aria-live":`polite`,children:y===null?E===null?null:u(`div`,{className:`rounded-md border border-success/40 bg-success/10 px-3 py-2 text-xs text-success`,children:E}):r(`div`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[u(x,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),u(`span`,{children:y})]})}),h.length>0&&u(`div`,{className:`max-h-[50vh] space-y-4 overflow-y-auto pr-1`,children:h.map(e=>u(kn,{photo:e,identities:O,draft:S,newNames:w,disabled:A,onAssign:(t,n)=>C(r=>hn(r,e.photoIndex,t,n===Tn?null:n)),onNameChange:(t,n)=>T(r=>({...r,[mn(e.photoIndex,t)]:n})),onRetry:()=>void I(e)},e.photoIndex))}),r(ht,{children:[u(Y,{variant:`secondary`,onClick:P,disabled:_,children:o(`common.close`,`Close`)}),r(Y,{variant:`primary`,onClick:()=>void z(),disabled:A||R===0,children:[_?u(M,{className:`h-3.5 w-3.5 animate-spin`}):null,`Enrol `,R,` face`,R===1?``:`s`]})]})]})})}n();var jn=[[`faceGallery`]];function Mn({identityId:e}){let{t}=X(),n=c(),{data:i,isLoading:a}=qe({identityId:e}),o=Le();function s(t){o.mutate({identityId:e,sampleId:t.id},{onSettled:()=>{n.invalidateQueries({queryKey:jn})}})}return a?r(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[u(M,{className:`h-3.5 w-3.5 animate-spin`}),t(`detectionIntelligence.peopleList.loadingSamples`,`Loading samples…`)]}):!i||i.length===0?u(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:t(`detectionIntelligence.peopleList.noSamplesYet`,`No samples yet.`)}):u(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:i.map(e=>r(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[e.base64?u(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:t(`detectionIntelligence.peopleList.sample`,`Sample`),className:`h-full w-full object-cover`}):u(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:u(pe,{className:`h-6 w-6`})}),e.source===`photo`&&u(`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:u(se,{className:`h-3 w-3`})}),u(`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:u(I,{className:`h-4 w-4 text-white`})})]},e.id))})}function Nn(e){return[{key:`person`,header:Mt.t(`detectionIntelligence.peopleList.person`,`Person`),sortValue:e=>e.name,render:e=>r(`span`,{className:`flex min-w-0 items-center gap-2`,children:[u(`span`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:u(Gt,{mediaId:e.coverMediaId,base64:e.coverBase64,alt:e.name,className:`h-full w-full object-cover`,placeholder:u(`span`,{className:`flex h-full w-full items-center justify-center`,children:u(pe,{className:`h-4 w-4 text-foreground-subtle`})})})}),u(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})]})},{key:`samples`,header:Mt.t(`detectionIntelligence.peopleList.samples`,`Samples`),align:`center`,nowrap:!0,sortValue:e=>e.sampleCount,render:e=>u(tt,{variant:`default`,className:`text-[10px]`,children:e.sampleCount})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:t=>r(`span`,{className:`flex items-center justify-end gap-1`,children:[u(Re,{variant:`ghost`,size:`sm`,icon:C,"aria-label":Mt.t(`detectionIntelligence.peopleList.edit`,`Edit {{name}}`,{name:t.name}),onClick:n=>{n.stopPropagation(),e.onEdit(t)}}),u(Re,{variant:`ghost`,size:`sm`,icon:v,"aria-label":Mt.t(`detectionIntelligence.peopleList.delete`,`Delete {{name}}`,{name:t.name}),onClick:n=>{n.stopPropagation(),e.onDelete(t)}})]})}]}function Pn({mode:e,identity:t,onClose:n}){let{t:i}=X(),a=c(),[o,s]=l(e===`edit`?t?.name??``:``),f=Se(),p=ge();d(()=>{s(e===`edit`?t?.name??``:``)},[e,t?.id,t?.name]);let m=f.isPending||p.isPending,h=o.trim(),g=e===`edit`&&t!==null&&h===t.name,_=m||h.length===0||g;function v(){a.invalidateQueries({queryKey:jn})}function y(){if(!_){if(e===`new`){f.mutate({name:h},{onSuccess:()=>{v(),n()}});return}if(t===null){n();return}p.mutate({id:t.id,name:h},{onSuccess:()=>{v(),n()}})}}return u(jt,{open:!0,onClose:n,title:e===`new`?`Add person`:`Edit ${t?.name??`person`}`,icon:pe,width:e===`edit`?`xl`:`lg`,testId:`people-person-form`,footer:r(Y,{variant:`primary`,size:`sm`,type:`button`,onClick:y,disabled:_,children:[m?u(M,{className:`h-3.5 w-3.5 animate-spin`}):null,e===`new`?i(`common.add`,`Add`):i(`common.save`,`Save`)]}),children:r(`div`,{className:`space-y-4`,children:[u(xe,{label:i(`detectionIntelligence.peopleList.name`,`Name`),required:!0,children:u(Ze,{value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&y()},placeholder:i(`detectionIntelligence.peopleList.personName`,`Person name…`),autoFocus:!0})}),e===`edit`&&t!==null&&r(`div`,{children:[u(`p`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:i(`detectionIntelligence.peopleList.trainingSamples`,`Training samples`)}),u(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:i(`detectionIntelligence.peopleList.removeASampleToDrop`,`Remove a sample to drop it from recognition training for this person.`)}),u(Mn,{identityId:t.id})]})]})})}function Fn(){let{t:e}=X(),t=c(),n=Qe(),{data:a,isLoading:o}=Ye(),s=St(),{state:f,openNew:p,openEdit:m,close:h}=je(),[g,_]=l(!1),v=a??[],y=Ne(v,{searchText:e=>[e.name]}),b=f.mode===`edit`?v.find(e=>e.id===f.id)??null:null;d(()=>{f.mode===`edit`&&!o&&b===null&&h()},[f.mode,o,b,h]);let x=i(()=>Nn({onEdit:e=>m(e.id),onDelete:r=>{(async()=>{await n({title:e(`detectionIntelligence.peopleList.deletePerson`,`Delete person`),message:e(`detectionIntelligence.peopleList.deleteAndAllTheirSamples`,`Delete {{name}} and all their samples? This cannot be undone.`,{name:r.name}),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&s.mutate({id:r.id},{onSettled:()=>{t.invalidateQueries({queryKey:jn}),f.mode===`edit`&&f.id===r.id&&h()}})})()}}),[n,h,s,f,m,t,e]);if(o)return r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[u(M,{className:`h-4 w-4 animate-spin`}),e(`detectionIntelligence.peopleList.loadingPeople`,`Loading people…`)]});let C=f.mode===`new`||f.mode===`edit`&&b!==null;return r(`div`,{className:`space-y-2`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(Y,{variant:`primary`,size:`sm`,type:`button`,onClick:p,children:[u(S,{className:`h-3.5 w-3.5`}),e(`detectionIntelligence.peopleList.addPerson`,`Add person`)]}),r(Y,{variant:`secondary`,size:`sm`,type:`button`,onClick:()=>_(!0),children:[u(se,{className:`h-3.5 w-3.5`}),e(`detectionIntelligence.peopleList.enrolFromAPhoto`,`Enrol from a photo`)]})]}),(v.length>0||y.active)&&u(Ie,{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?u(Be,{icon:pe,title:y.active?e(`detectionIntelligence.peopleList.nothingMatchesTheFilter`,`Nothing matches the filter`):e(`detectionIntelligence.peopleList.noPeopleEnrolledYet`,`No people enrolled yet`),description:y.active?e(`detectionIntelligence.peopleList.clearTheSearchOrTry`,`Clear the search or try another name.`):e(`detectionIntelligence.peopleList.addAPersonOrEnrol`,`Add a person, or enrol faces from a photo.`)}):u(we,{columns:x,rows:y.rows,rowKey:e=>e.id,maxBodyHeight:We,mobileMode:`scroll`,emptyMessage:e(`detectionIntelligence.peopleList.noPeopleEnrolledYet2`,`No people enrolled yet.`),onRowClick:e=>m(e.id)}),C&&u(Pn,{mode:f.mode===`new`?`new`:`edit`,identity:b,onClose:h}),u(An,{open:g,onOpenChange:_})]})}var In={fromMs:null,toMs:null},Ln=36e5,Rn=24*Ln;function zn(e,t){switch(e){case`24h`:return{fromMs:t-Rn,toMs:null};case`7d`:return{fromMs:t-7*Rn,toMs:null};case`30d`:return{fromMs:t-30*Rn,toMs:null};case`all`:return In}}function Bn(e){return e.fromMs!==null||e.toMs!==null}function Vn(e,t){return Bn(t)?e.filter(e=>!(t.fromMs!==null&&e.timestamp<t.fromMs||t.toMs!==null&&e.timestamp>t.toMs)):[...e]}function Hn(e,t){return t.size===0?[...e]:e.filter(e=>t.has(e.deviceId))}function Un(e){let t=new Set,n=[];for(let r of e)t.has(r.deviceId)||(t.add(r.deviceId),n.push(r.deviceId));return n}function Wn(e){if(!e)return null;let t=Date.parse(`${e}T00:00:00`);return Number.isNaN(t)?null:t}function Gn(e){if(!e)return null;let t=Date.parse(`${e}T23:59:59.999`);return Number.isNaN(t)?null:t}function Kn(e,t){if(!Number.isFinite(e)||e<=0)return`—`;let n=t-e;return n<6e4?`just now`:n<Ln?`${String(Math.floor(n/6e4))}m ago`:n<Rn?`${String(Math.floor(n/Ln))}h ago`:n<7*Rn?`${String(Math.floor(n/Rn))}d ago`:new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function qn(e){return!Number.isFinite(e)||e<=0?`—`:new Date(e).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function Jn(e){return!Number.isFinite(e)||e<=0?`—`:new Date(e).toLocaleString(void 0,{year:`numeric`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function Yn(e){let t=e.cropUrl!==void 0&&e.cropUrl.length>0,n=e.base64!==void 0&&e.base64.length>0;return!t&&!n}function Xn(e){return e.filter(Yn).map(e=>e.faceId)}function Zn(e){let t=0;for(let n of e)Yn(n)&&(t+=1);return t}function Qn(e){return e==null?null:e.cropUrl!==void 0&&e.cropUrl.length>0?e.cropUrl:e.base64!==void 0&&e.base64.length>0?`data:image/jpeg;base64,${e.base64}`:null}n();function $n(e,t,n){let[r,a]=l(1);d(()=>{a(1)},[n]);let o=e.length,s=Math.max(1,Math.ceil(o/t)),c=Math.min(r,s);return d(()=>{c!==r&&a(c)},[c,r]),{page:c,setPage:a,pageItems:i(()=>{let n=(c-1)*t;return e.slice(n,n+t)},[e,c,t]),totalPages:s,totalItems:o,pageSize:t}}var er=2;function tr(e,t){if(t<=1)return[{kind:`page`,n:1}];if(t<=7){let e=[];for(let n=1;n<=t;n++)e.push({kind:`page`,n});return e}let n=[],r=Math.max(2,e-er),i=Math.min(t-1,e+er);n.push({kind:`page`,n:1}),r>2&&n.push({kind:`ellipsis`,side:`left`});for(let e=r;e<=i;e++)n.push({kind:`page`,n:e});return i<t-1&&n.push({kind:`ellipsis`,side:`right`}),n.push({kind:`page`,n:t}),n}function nr({currentPage:e,totalItems:t,pageSize:n,onPageChange:i,itemNoun:a=`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),d=tr(e,s),f=`inline-flex h-7 min-w-7 items-center justify-center rounded-md px-2 text-[11px] transition-colors disabled:opacity-40`;return r(`div`,{className:`flex items-center justify-between gap-4 flex-wrap pt-2 text-[11px] text-foreground-subtle`,children:[r(`span`,{children:[`Showing `,c,`–`,l,` of `,t,` `,a]}),r(`div`,{className:`flex items-center gap-1`,children:[u(`button`,{type:`button`,className:`${f} hover:bg-surface-hover`,onClick:()=>i(e-1),disabled:e<=1,"aria-label":o(`galleryPager.previousPage`,`Previous page`),children:u(G,{className:`h-3.5 w-3.5`})}),d.map(t=>t.kind===`ellipsis`?u(`span`,{className:`px-1 opacity-60`,children:`…`},`ellipsis-${t.side}`):u(`button`,{type:`button`,className:`${f} ${t.n===e?`bg-primary/12 text-primary font-medium`:`hover:bg-surface-hover hover:text-foreground`}`,onClick:()=>i(t.n),"aria-current":t.n===e?`page`:void 0,children:t.n},t.n)),u(`button`,{type:`button`,className:`${f} hover:bg-surface-hover`,onClick:()=>i(e+1),disabled:e>=s,"aria-label":o(`galleryPager.nextPage`,`Next page`),children:u(A,{className:`h-3.5 w-3.5`})})]})]})}n();var rr=[[`faceGallery`]];function ir({faceIds:e,identities:t,onDone:n}){let{t:i}=X(),a=c(),o=Ke(),s=Se(),[d,f]=l(``),[p,m]=l(!1),[h,g]=l(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||o.mutate({faceIds:[...e],identityId:t},{onSettled:()=>{a.invalidateQueries({queryKey:rr}),b()}})}function S(){!e||!d.trim()||s.mutate({name:d.trim()},{onSuccess:e=>{e?.id&&x(e.id)},onError:()=>{a.invalidateQueries({queryKey:rr}),b()}})}let C=o.isPending||s.isPending;return u(He,{open:_,onOpenChange:e=>!e&&b(),children:r(ye,{children:[r(_e,{children:[u(mt,{children:v>1?i(`detectionIntelligence.assignDialog.assignFacesToPerson`,`Assign {{value1}} faces to person`,{value1:String(v)}):i(`detectionIntelligence.assignDialog.assignFaceToPerson`,`Assign face to person`)}),u(Pe,{children:i(`detectionIntelligence.assignDialog.selectAnExistingPersonOr`,`Select an existing person or create a new one.`)})]}),u(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:t.map(e=>r(`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:[u(`span`,{className:`font-medium`,children:e.name}),r(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` samples`]})]},e.id))}),u(`div`,{className:`min-h-[2.75rem] border-t border-border pt-2`,children:p?u(`div`,{className:`flex items-center gap-2`,children:u(Ze,{placeholder:i(`detectionIntelligence.assignDialog.newPersonName`,`New person name…`),value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&S()},autoFocus:!0,className:`flex-1`})}):u(`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…`)})}),r(ht,{className:`min-h-[2.75rem]`,children:[u(Y,{variant:`secondary`,onClick:b,disabled:C,children:i(`common.cancel`,`Cancel`)}),p?r(Y,{variant:`primary`,onClick:S,disabled:C||!d.trim(),children:[C&&u(M,{className:`h-3.5 w-3.5 animate-spin`}),i(`detectionIntelligence.assignDialog.createAssign`,`Create & assign`)]}):r(Y,{variant:`primary`,onClick:()=>h&&x(h),disabled:C||!h,children:[C&&u(M,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,v>1?` ${String(v)}`:``]})]})]})})}n();function ar({cameras:e,selected:n,onChange:i}){let{t:a}=X(),[o,s]=l(!1),c=t(null);d(()=>{if(!o)return;function e(e){c.current&&e.target instanceof Node&&!c.current.contains(e.target)&&s(!1)}function t(e){e.key===`Escape`&&s(!1)}return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[o]);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 r(`div`,{ref:c,className:`relative`,children:[r(`button`,{type:`button`,onClick:()=>s(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:[u(te,{className:`h-3.5 w-3.5`}),u(`span`,{className:`max-w-[10rem] truncate`,children:m}),u(q,{className:`h-3 w-3 opacity-70`})]}),o&&r(`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&&u(`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:a(`detectionIntelligence.cameraMultiSelect.clearSelection`,`Clear selection`)}),e.map(e=>{let t=n.has(e.id);return r(`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:[u(`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&&u(N,{className:`h-2.5 w-2.5`})}),u(`span`,{className:`truncate`,children:e.name})]},e.id)})]})]})}n();var or=[{label:`24h`,value:`24h`},{label:`7d`,value:`7d`},{label:`30d`,value:`30d`},{label:`All`,value:`all`}];function sr({onChange:e}){let{t}=X(),[n,i]=l(`all`),[a,o]=l(``),[s,c]=l(``);function d(t){i(t),o(``),c(``),e(zn(t,Date.now()))}function f(t,n){i(`custom`),o(t),c(n),e({fromMs:Wn(t),toMs:Gn(n)})}let p=`rounded-md border border-border bg-surface px-2 py-1.5 text-[11px] text-foreground outline-none focus:border-primary [color-scheme:light] dark:[color-scheme:dark]`;return r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[u(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:or.map(e=>u(`button`,{type:`button`,onClick:()=>d(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.label},e.value))}),r(`div`,{className:`flex items-center gap-1`,children:[u(`input`,{type:`date`,"aria-label":t(`detectionIntelligence.dateRangeFilter.fromDate`,`From date`),value:a,max:s||void 0,onChange:e=>f(e.target.value,s),className:`${p} ${n===`custom`&&a?`border-primary/50`:``}`}),u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`→`}),u(`input`,{type:`date`,"aria-label":t(`detectionIntelligence.dateRangeFilter.toDate`,`To date`),value:s,min:a||void 0,onChange:e=>f(a,e.target.value),className:`${p} ${n===`custom`&&s?`border-primary/50`:``}`})]})]})}function cr(e){return e<0?0:e>1?1:e}function lr(e,t,n){if(!Number.isFinite(t)||!Number.isFinite(n)||t<=0||n<=0)return null;let r=cr(e.x/t),i=cr(e.y/n),a=cr((e.x+e.w)/t),o=cr((e.y+e.h)/n);return{x:r,y:i,width:Math.max(0,a-r),height:Math.max(0,o-i)}}n();var ur=2.6;function dr({src:e,alt:t,className:n,overlay:i,fit:a=`contain`}){let[o,s]=l(!1),[c,f]=l(`50% 50%`);d(()=>{s(!1),f(`50% 50%`)},[e]);function p(e){if(!o){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)}%`)}s(e=>!e)}let m=a===`natural`;return u(`div`,{className:`relative overflow-hidden bg-background ${n??``}`,onClick:p,children:r(`div`,{className:`relative select-none transition-transform duration-200 ease-out ${m?`w-full`:`h-full w-full`} ${o?`cursor-zoom-out`:`cursor-zoom-in`}`,style:{transformOrigin:c,transform:o?`scale(${String(ur)})`:`scale(1)`},children:[u(`img`,{src:e,alt:t,draggable:!1,className:m?`block h-auto w-full object-contain`:`h-full w-full object-contain`}),i]})})}n();function fr(e){let[t,n]=l(null),[r,i]=l(null),[a,o]=l(!1);return d(()=>{if(n(null),i(null),o(!1),e===void 0)return;let t=!1,r=null;return(async()=>{try{let i=await Vt(Ht(e));if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||o(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),d(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>o(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function pr(e){let t=e.filter(e=>e.url.length>0);return t.length===0?null:t.find(e=>/crop|face/i.test(e.kind))??t[0]}function mr({label:e,value:t}){return r(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[u(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),u(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground`,children:t})]})}function hr({box:e}){let{t}=X();return u(`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:u(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:t(`detectionIntelligence.faceDetailPanel.face`,`Face`)})})}function gr({face:e,cameraName:t,onClose:n,onAssign:a,onUnassign:o,onDelete:s,actionsPending:c}){let{t:d}=X(),{data:f,isFetching:p}=De({faceId:e?.faceId??``},{enabled:e!==null}),[m,h]=l(`frame`),{frameSrc:_,naturalWidth:y,naturalHeight:b,failed:x}=fr(e?.keyFrameMediaId),S=i(()=>{let t=pr(f??[]);return t?t.url:Qn(e)},[f,e]),C=i(()=>!e?.faceBbox||y===null||b===null?null:lr(e.faceBbox,y,b),[e?.faceBbox,y,b]);if(e===null)return null;let w=e.keyFrameMediaId!==void 0&&!x,T=w&&m===`frame`,E=e.assigned?e.identityName??`Assigned`:e.recognizedIdentityId?`${e.identityName??`Recognized`} (suggested)`:`Unassigned`;return u(He,{open:!0,onOpenChange:e=>!e&&n(),children:r(ye,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":d(`detectionIntelligence.faceDetailPanel.faceDetail`,`Face detail`),className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[u(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:r(`div`,{className:`min-w-0`,children:[u(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:d(`detectionIntelligence.faceDetailPanel.faceDetail`,`Face detail`)}),u(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]})}),r(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[w&&r(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[r(`button`,{type:`button`,onClick:()=>h(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${m===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[u(B,{className:`h-3.5 w-3.5`}),` Full frame`]}),r(`button`,{type:`button`,onClick:()=>h(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${m===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[u(fe,{className:`h-3.5 w-3.5`}),` Crop`]})]}),T&&_?u(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:u(dr,{src:_,alt:d(`detectionIntelligence.faceDetailPanel.fullFrameWithDetectedFace`,`Full frame with detected face`),fit:`natural`,className:`w-full`,overlay:C?u(hr,{box:C}):void 0})}):S?r(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[u(dr,{src:S,alt:d(`detectionIntelligence.faceDetailPanel.detectedFace`,`Detected face`),className:`h-full w-full`}),p&&u(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:u(M,{className:`h-3.5 w-3.5 animate-spin`})})]}):r(`div`,{className:`flex aspect-square w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[u(R,{className:`h-8 w-8 text-warning/70`}),u(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:d(`detectionIntelligence.faceDetailPanel.noImage`,`No image`)}),u(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:d(`detectionIntelligence.faceDetailPanel.theCropMediaForThis`,`The crop media for this face could not be resolved (a pre-fix orphan). Safe to delete.`)})]}),r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[u(mr,{label:d(`detectionIntelligence.faceDetailPanel.camera`,`Camera`),value:t}),u(mr,{label:d(`detectionIntelligence.faceDetailPanel.captured`,`Captured`),value:Jn(e.timestamp)}),u(mr,{label:d(`detectionIntelligence.faceDetailPanel.track`,`Track`),value:e.trackId}),u(mr,{label:d(`detectionIntelligence.faceDetailPanel.identity`,`Identity`),value:E})]})]}),r(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[e.assigned?r(Y,{variant:`secondary`,onClick:()=>o(e.faceId),disabled:c,children:[u(ue,{className:`h-3.5 w-3.5`}),` Detach`]}):r(Y,{variant:`primary`,onClick:()=>a(e.faceId),disabled:c,children:[u(g,{className:`h-3.5 w-3.5`}),` Assign`]}),r(Y,{variant:`secondary`,onClick:()=>s(e.faceId),disabled:c,children:[u(v,{className:`h-3.5 w-3.5`}),` Delete`]})]})]})})}function _r(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function vr(e,t){return e.faceIds.filter(e=>!t.has(e))}function yr(e,t){return e.faceIds.filter(e=>t(e))}n();var br=[[`faceGallery`]],xr=20,Sr=.3,Cr=.9,wr=.05,Tr=.5,Er=2,Dr=10,Or=2;function kr({cluster:e,face:t,active:n,onSelect:i}){let a=Qn(t);return r(`button`,{type:`button`,onClick:i,className:`flex shrink-0 flex-col items-center gap-1.5 rounded-md border p-2 text-center transition-colors md:w-full md:flex-row md:gap-2.5 md:text-left ${n?`border-primary bg-primary/8`:`border-border bg-surface hover:bg-surface-hover`}`,children:[u(`div`,{className:`h-24 w-24 shrink-0 overflow-hidden rounded bg-surface-hover`,children:a===null?u(R,{className:`h-24 w-24 p-6 text-foreground-subtle`}):u(`img`,{src:a,alt:``,loading:`lazy`,decoding:`async`,className:`h-24 w-24 object-cover`})}),r(`span`,{className:`w-24 text-[11px] leading-tight text-foreground-subtle md:w-auto`,children:[e.size,` faces · `,Math.round(e.cohesion*100),`% alike`]})]})}function Ar({face:e,cameraName:t,nowMs:n,excluded:i,onToggleExclude:a,onDelete:o,deletePending:s}){let{t:c}=X(),l=Qn(e);return r(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden transition-opacity ${i?`border-border opacity-40 grayscale`:`border-border`}`,children:[r(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[l===null?r(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,children:[u(R,{className:`h-7 w-7 text-warning/70`}),u(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:c(`detectionIntelligence.similarGroupsModal.noCrop`,`No crop`)})]}):u(dr,{src:l,alt:c(`detectionIntelligence.similarGroupsModal.faceFrom`,`Face from {{cameraName}}`,{cameraName:t}),className:`h-full w-full`}),u(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a()},className:`absolute right-1 top-1 z-10 rounded-full bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?c(`detectionIntelligence.similarGroupsModal.includeFace`,`Include face`):c(`detectionIntelligence.similarGroupsModal.excludeFace`,`Exclude face`),title:i?c(`detectionIntelligence.similarGroupsModal.include`,`Include`):c(`detectionIntelligence.similarGroupsModal.exclude`,`Exclude`),children:u(i?f:I,{className:`h-3.5 w-3.5`})})]}),r(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[u(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),u(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:Kn(e.timestamp,n)})]}),u(`div`,{className:`mt-1 flex min-h-[2rem] items-center justify-end border-t border-border/60 px-1 py-0.5`,children:u(`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?u(M,{className:`h-4 w-4 animate-spin`}):u(v,{className:`h-4 w-4`})})})]})}function jr({open:e,onClose:t,byId:n,cameraName:a,nowMs:o,identities:f,selectMany:p}){let{t:m}=X(),h=c(),_=Qe(),v=Oe(),[y,b]=l(Tr),[x,S]=l(Or),[C,w]=l(null),[T,E]=l({}),[O,k]=l(null),{data:A,isFetching:j,refetch:N}=at({threshold:y,minClusterSize:x,limit:xr},{enabled:e}),P=A??[];d(()=>{E({})},[y,x]),d(()=>{if(P.length===0){w(null);return}P.some(e=>e.representativeFaceId===C)||w(P[0]?.representativeFaceId??null)},[P]);let F=i(()=>P.find(e=>e.representativeFaceId===C)??null,[P,C]),I=F?T[F.representativeFaceId]??new Set:new Set,L=i(()=>F?yr(F,e=>n.has(e)):[],[F,n]),R=F?F.faceIds.length-L.length:0,z=F?vr({...F,faceIds:L},I):[];function ee(e){if(!F)return;let t=F.representativeFaceId;E(n=>({...n,[t]:_r(n[t]??new Set,e)}))}function B(){h.invalidateQueries({queryKey:br})}async function V(e){await _({title:m(`detectionIntelligence.similarGroupsModal.deleteFace`,`Delete face`),message:m(`detectionIntelligence.similarGroupsModal.permanentlyDeletesThisFaceCrop`,`Permanently deletes this face crop. This cannot be undone.`),confirmLabel:m(`common.delete`,`Delete`),variant:`danger`})&&v.mutate({faceId:e},{onSettled:B})}function H(){k(null),t()}function U(){z.length!==0&&(p(z),H())}return r(He,{open:e,onOpenChange:e=>!e&&H(),children:[r(ye,{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:[r(`header`,{className:`flex shrink-0 flex-col gap-2 border-b border-border py-3 pl-4 pr-10`,children:[r(`div`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[u(D,{className:`h-4 w-4 text-primary`}),` Look-alike groups`]}),r(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[r(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[m(`detectionIntelligence.similarGroupsModal.threshold`,`Threshold`),u(`input`,{type:`range`,min:Sr,max:Cr,step:wr,value:y,onChange:e=>b(Number(e.target.value)),className:`h-1.5 w-28 cursor-pointer accent-primary`}),u(`span`,{className:`w-8 shrink-0 text-right font-mono text-[11px] tabular-nums text-foreground`,children:y.toFixed(2)})]}),r(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[m(`detectionIntelligence.similarGroupsModal.minSize`,`Min size`),u(`input`,{type:`number`,min:Er,max:Dr,step:1,value:x,onChange:e=>S(Math.min(Dr,Math.max(Er,Number(e.target.value)||Er))),className:`w-12 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`})]}),r(Y,{variant:`secondary`,onClick:()=>{E({}),N()},disabled:j,children:[j?u(M,{className:`h-3.5 w-3.5 animate-spin`}):u(ne,{className:`h-3.5 w-3.5`}),m(`detectionIntelligence.similarGroupsModal.reAnalyze`,`Re-analyze`)]})]})]}),u(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-hidden px-4 py-3 md:flex-row`,children:j&&P.length===0?r(`div`,{className:`flex flex-1 items-center justify-center gap-2 py-8 text-xs text-foreground-subtle`,children:[u(M,{className:`h-4 w-4 animate-spin`}),` Finding similar faces…`]}):P.length===0?u(`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.`)}):r(s,{children:[u(`div`,{className:`flex gap-2 overflow-x-auto pb-1 md:hidden`,children:P.map(e=>u(kr,{cluster:e,face:n.get(e.representativeFaceId),active:e.representativeFaceId===C,onSelect:()=>w(e.representativeFaceId)},e.representativeFaceId))}),u(`div`,{className:`hidden shrink-0 flex-col gap-2 overflow-y-auto md:flex md:w-56`,children:P.map(e=>u(kr,{cluster:e,face:n.get(e.representativeFaceId),active:e.representativeFaceId===C,onSelect:()=>w(e.representativeFaceId)},e.representativeFaceId))}),u(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:F&&r(s,{children:[R>0&&r(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:[R,` not loaded — excluded from actions`]}),u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(13rem,13rem))] justify-start gap-2`,children:L.map(e=>{let t=n.get(e);return t?u(Ar,{face:t,cameraName:a(t.deviceId),nowMs:o,excluded:I.has(e),onToggleExclude:()=>ee(e),onDelete:()=>void V(e),deletePending:v.isPending&&v.variables?.faceId===e},e):null})})]})})]})}),r(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[u(Y,{variant:`secondary`,onClick:U,disabled:z.length===0,children:m(`detectionIntelligence.similarGroupsModal.selectInGallery`,`Select in gallery`)}),r(Y,{variant:`primary`,onClick:()=>k(z),disabled:z.length===0,children:[u(g,{className:`h-3.5 w-3.5`}),` Adopt (`,z.length,`)`]})]})]}),u(ir,{faceIds:O,identities:f,onDone:()=>k(null)})]})}n();var Mr=[[`faceGallery`]],Nr=500,Pr=120;function Fr({face:e,cameraName:t,nowMs:n,selected:i,onToggleSelect:a,onAssign:o,onOpenDetail:s}){let{t:l}=X(),d=c(),f=Tt(),p=Oe(),m=()=>{d.invalidateQueries({queryKey:Mr})},h=()=>s(e.faceId),_=Qn(e);return r(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[r(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[_===null?r(`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:l(`detectionIntelligence.unassignedFaces.noCropImageTheFace`,`No crop image — the face's crop media is missing (a pre-fix orphan). Safe to delete.`),children:[u(R,{className:`h-7 w-7 text-warning/70`}),u(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:l(`detectionIntelligence.unassignedFaces.noCrop`,`No crop`)})]}):u(`img`,{src:_,alt:l(`detectionIntelligence.unassignedFaces.faceFrom`,`Face from {{cameraName}}`,{cameraName:t}),onClick:h,loading:`lazy`,decoding:`async`,className:`h-full w-full cursor-zoom-in object-cover`}),u(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),a(e.faceId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?l(`detectionIntelligence.unassignedFaces.deselect`,`Deselect`):l(`detectionIntelligence.unassignedFaces.select`,`Select`),children:i?u(ce,{className:`h-4 w-4 text-primary`}):u(y,{className:`h-4 w-4`})})]}),r(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[u(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),u(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:Kn(e.timestamp,n)}),u(`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`})]}),r(`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?u(`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":l(`detectionIntelligence.unassignedFaces.detachFace`,`Detach face`),title:l(`detectionIntelligence.unassignedFaces.detach`,`Detach`),children:f.isPending?u(M,{className:`h-4 w-4 animate-spin`}):u(ue,{className:`h-4 w-4`})}):u(`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":l(`detectionIntelligence.unassignedFaces.assignFaceToPerson`,`Assign face to person`),title:l(`detectionIntelligence.unassignedFaces.assignToPerson`,`Assign to person`),children:u(g,{className:`h-4 w-4`})}),u(`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":l(`detectionIntelligence.unassignedFaces.deleteFace`,`Delete face`),title:l(`detectionIntelligence.unassignedFaces.deleteFace`,`Delete face`),children:p.isPending?u(M,{className:`h-4 w-4 animate-spin`}):u(v,{className:`h-4 w-4`})})]})]})}var Ir=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Recognized`,value:`recognized`}];function Lr(){let{t:e}=X(),t=c(),[n,a]=l(`all`),[o,d]=l(In),[f,p]=l(new Set),[m,h]=l(new Set),[_,y]=l(null),[b,x]=l(!1),[S,C]=l(null),{data:w,isLoading:T}=Xe({limit:Nr,filter:n,includeCrops:!1},{refetchInterval:3e4}),{data:E=[]}=Ye(),{data:O}=gt({isCamera:!0,projection:`slim`}),k=Ke(),A=Tt(),j=yt(),N=Oe(),P=Date.now(),F=w??[],L=i(()=>{let e=new Map;for(let t of O??[])e.set(t.id,t.name);return e},[O]),z=e=>L.get(e)??`Camera #${String(e)}`,ee=i(()=>Un(F).map(e=>({id:e,name:z(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[F,L]),B=i(()=>Hn(Vn(F,o),f),[F,o,f]),V=$n(B,Pr,i(()=>JSON.stringify([n,o.fromMs,o.toMs,[...f].sort((e,t)=>e-t)]),[n,o.fromMs,o.toMs,f])),H=i(()=>new Map(F.map(e=>[e.faceId,e])),[F]),U=i(()=>Zn(B),[B]),W=S===null?null:H.get(S)??null,G=()=>{t.invalidateQueries({queryKey:Mr})},te=()=>h(new Set);function K(e){h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function q(e){h(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function ne(){q(Xn(B))}let re=[...m],J=k.isPending||j.isPending||N.isPending,ie=A.isPending||N.isPending;function ae(){re.length!==0&&j.mutate({faceIds:re},{onSettled:()=>{G(),te()}})}function oe(){re.length!==0&&Promise.allSettled(re.map(e=>N.mutateAsync({faceId:e}))).then(()=>{G(),te()})}function se(e){C(null),y([e])}function ce(e){A.mutate({faceId:e},{onSettled:G}),C(null)}function le(e){N.mutate({faceId:e},{onSettled:G}),C(null)}let de=B.length!==F.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[u(`div`,{className:`flex items-center gap-1`,children:Ir.map(e=>u(`button`,{type:`button`,onClick:()=>a(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${n===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.label},e.value))}),u(sr,{onChange:d}),u(ar,{cameras:ee,selected:f,onChange:p}),r(`button`,{type:`button`,onClick:()=>x(!0),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${b?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[u(D,{className:`h-3.5 w-3.5`}),` Similar groups`]}),!T&&U>0&&r(`button`,{type:`button`,onClick:ne,className:`ml-auto flex items-center gap-1 rounded-md px-2.5 py-1 text-xs text-warning/90 transition-colors hover:bg-warning/10`,title:e(`detectionIntelligence.unassignedFaces.selectEveryVisibleFaceWhose`,`Select every visible face whose crop image is missing so you can delete the orphans in one pass`),children:[u(R,{className:`h-3.5 w-3.5`}),` Select `,U,` crop-less`]}),!T&&u(`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)}):`${String(B.length)} face${B.length===1?``:`s`}`})]}),m.size>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[r(`span`,{className:`text-xs font-medium text-foreground`,children:[m.size,` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[r(Y,{variant:`primary`,onClick:()=>y(re),disabled:J,children:[u(g,{className:`h-3.5 w-3.5`}),` Assign`]}),r(Y,{variant:`secondary`,onClick:ae,disabled:J,children:[j.isPending?u(M,{className:`h-3.5 w-3.5 animate-spin`}):u(ue,{className:`h-3.5 w-3.5`}),` `,e(`detectionIntelligence.unassignedFaces.detach`,`Detach`)]}),r(Y,{variant:`secondary`,onClick:oe,disabled:J,children:[u(v,{className:`h-3.5 w-3.5`}),` Delete`]}),u(Y,{variant:`ghost`,onClick:te,disabled:J,children:u(I,{className:`h-3.5 w-3.5`})})]})]}),T?u(Te,{status:`pending`,pendingMessage:`Loading faces…`,testId:`faces-grid`}):B.length===0?u(Be,{icon:R,title:F.length>0?e(`detectionIntelligence.unassignedFaces.nothingMatchesTheFilter`,`Nothing matches the filter`):e(`detectionIntelligence.unassignedFaces.noFacesFoundForThis`,`No faces found for this filter`),description:F.length>0?e(`detectionIntelligence.unassignedFaces.widenTheDateRangeOr`,`Widen the date range or clear the camera filter.`):e(`detectionIntelligence.unassignedFaces.faceCropsAppearHereWhen`,`Face crops appear here when the detection pipeline captures them.`)}):r(s,{children:[u(Te,{status:`ready`,testId:`faces-grid`,className:`grid-cols-[repeat(auto-fill,minmax(6.5rem,6.5rem))] justify-start`,children:V.pageItems.map(e=>u(Fr,{face:e,cameraName:z(e.deviceId),nowMs:P,selected:m.has(e.faceId),onToggleSelect:K,onAssign:e=>y([e]),onOpenDetail:C},e.faceId))}),u(nr,{currentPage:V.page,totalItems:V.totalItems,pageSize:V.pageSize,onPageChange:V.setPage,itemNoun:`faces`})]}),u(gr,{face:W,cameraName:W?z(W.deviceId):``,onClose:()=>C(null),onAssign:se,onUnassign:ce,onDelete:le,actionsPending:ie}),u(ir,{faceIds:_,identities:E,onDone:()=>{y(null),te()}}),u(jr,{open:b,onClose:()=>x(!1),byId:H,cameraName:z,nowMs:P,identities:E,selectMany:q})]})}function Rr(e){let{delayMs:t,invalidate:n,setTimeoutFn:r=setTimeout,clearTimeoutFn:i=clearTimeout}=e,a;function o(){a===void 0&&(a=r(()=>{a=void 0,n()},t))}function s(){a!==void 0&&(i(a),a=void 0)}return{trigger:o,cancel:s}}n();var zr=[[`faceGallery`]],Br=2e3;function Vr(){let e=c(),n=t(e);n.current=e;let r=t(void 0);r.current||=Rr({delayMs:Br,invalidate:()=>{n.current.invalidateQueries({queryKey:zr})}}),d(()=>()=>r.current?.cancel(),[]),dt(me.PipelineAnalyticsFaceGalleryChanged,()=>{r.current?.trigger()})}function Hr(){let{t:e}=X();return Vr(),r(`div`,{className:`space-y-3`,children:[u(Ge,{headingId:`library-people`,title:e(`detectionIntelligence.people`,`People`),icon:pe,testId:`library-section-people`,children:r(`div`,{className:`${m} space-y-3`,children:[u(`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.`)}),u(Fn,{})]})}),u(Ge,{headingId:`library-recent-faces`,title:e(`detectionIntelligence.recentDetectedFaces`,`Recent detected faces`),icon:J,testId:`library-section-recent-faces`,children:r(`div`,{className:`${m} space-y-3`,children:[u(`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.`)}),u(Lr,{})]})})]})}function Ur(e){let t=e.subLabel??e.label;if(t!==void 0)return t;let n=e.audioLabels?.[0]?.label;return n!==void 0&&n.length>0?n:void 0}var Wr=720*60*60*1e3;function Gr(e){let t=[];for(let n of e)t.push(...n);return t}function Kr(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function qr(e,t){return e.filter(e=>!(e.importance<t.minImportance||t.cameras.size>0&&!t.cameras.has(e.deviceId)||t.classes.size>0&&!t.classes.has(e.className)))}function Jr(e,t){return`${String(e)}:${t}`}function Yr(e,t){let n=new Map,r=new Set;for(let i of e){let e=Jr(i.deviceId,i.trackId);if(!t.has(e)||r.has(e))continue;r.add(e);let a=n.get(i.deviceId);a?a.push(i.trackId):n.set(i.deviceId,[i.trackId])}return n}function Xr(e,t){return{since:e.fromMs??t-Wr,until:e.toMs??t}}var Zr=[`native`,`raster`,`standin`];function Qr(e){return Zr.some(t=>t===e)}var $r={standin:{label:`stand-in`,title:`Stand-in: this tile is a face or plate detail crop copied in because no frame of the subject was captured. It is not a best shot.`,tone:`warning`},raster:{label:`low-res`,title:`Raster crop: a sub-native cut of the subject, not a native capture. Honest, but lower resolution than a best shot.`,tone:`info`}};function ei(e){return e===`standin`?$r.standin:e===`raster`?$r.raster:null}var ti={"no-key-frame":`No key frame existed at close, so no native tile could be cut.`,"no-best-seen-bbox":`No subject box was ever recorded, so there was nothing to cut around.`,"derive-returned-null":`The close-time crop was attempted and produced nothing.`,"derive-threw":`The close-time crop failed with an error.`,"derive-not-wired":`No close-time crop was wired on this node.`,"no-media-store":`The node was shutting down mid-close.`,"no-thumbnail":`The track closed with no tile of any kind.`,"standin-tile":`The track closed with a detail crop standing in for the subject.`,"raster-tile":`The track closed with a sub-native raster crop of the subject.`,"native-tile":`The track closed with a native tile.`};function ni(e){if(e===void 0)return null;let t=e.trim();if(t.length===0)return null;let n=t.split(/\s+/),r=n[0]??t,i=[];for(let e of n.slice(1)){let t=e.indexOf(`=`);t===-1?i.push({key:e,value:null}):i.push({key:e.slice(0,t),value:e.slice(t+1)})}return{sentence:ti[r]??r,detail:i,raw:t}}function ri(e){if(e===void 0||!Number.isFinite(e)||e<=0)return``;let t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return`${String(n)}m ${String(r).padStart(2,`0`)}s`}function ii({row:e,cameraName:t,nowMs:n,onOpenDetail:i,selected:a=!1,onToggleSelect:o,score:s,provenance:c,footer:l}){let{t:d}=X(),f=zt(e.mediaId===void 0?Bt(`track`,e.trackId):Ht(e.mediaId)),p=Math.round(e.importance*100),m=s===void 0?void 0:Math.round(s*100),g=ri(e.windowMs),_=()=>i(e),v=ei(c);return r(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${a?`border-primary ring-1 ring-primary`:`border-border`}`,children:[r(`div`,{className:`aspect-video relative overflow-hidden bg-surface-hover`,children:[f.src?u(`img`,{src:f.src,alt:d(`detectionIntelligence.eventCard.eventFrom`,`Event from {{cameraName}}`,{cameraName:t}),onClick:_,className:`h-full w-full cursor-zoom-in object-cover`}):u(`button`,{type:`button`,onClick:_,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-surface-hover text-foreground-subtle`,title:f.failed?d(`detectionIntelligence.eventCard.keyEventMediaUnavailable`,`Key-event media unavailable`):d(`detectionIntelligence.eventCard.noKeyEventMedia`,`No key-event media`),children:u(R,{className:`h-6 w-6 opacity-60`})}),o&&u(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(Jr(e.deviceId,e.trackId))},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":a?d(`detectionIntelligence.eventCard.deselect`,`Deselect`):d(`detectionIntelligence.eventCard.select`,`Select`),children:a?u(ce,{className:`h-4 w-4 text-primary`}):u(y,{className:`h-4 w-4`})}),m!==void 0&&r(`span`,{className:`absolute left-1 top-1 z-10 rounded bg-primary/85 px-1.5 py-0.5 text-[10px] font-semibold text-white tabular-nums`,title:d(`detectionIntelligence.eventCard.clipSemanticMatchScore`,`CLIP semantic-match score`),children:[String(m),`%`]}),p>0&&u(`span`,{className:`absolute right-1 top-1 z-10 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-semibold text-white`,children:String(p)}),v!==null&&u(`span`,{className:`absolute bottom-1 right-1 z-10 rounded px-1.5 py-0.5 text-[10px] font-semibold text-white ${v.tone===`warning`?`bg-warning/90`:`bg-black/70`}`,title:v.title,children:v.label}),(e.markForTrain===!0||e.retrainStatus===`trained`||e.debug===!0||e.favourited===!0)&&r(`span`,{className:`absolute bottom-1 left-1 z-10 flex gap-1`,children:[e.markForTrain===!0&&u(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:d(`detectionIntelligence.eventCard.markedForTraining`,`Marked for training`),"aria-label":d(`detectionIntelligence.eventCard.markedForTraining`,`Marked for training`),children:u(K,{className:`h-3 w-3`})}),e.retrainStatus===`trained`&&e.markForTrain!==!0&&u(`span`,{className:`rounded bg-success/85 p-0.5 text-white`,title:d(`detectionIntelligence.eventCard.trainingComplete`,`Training complete`),"aria-label":d(`detectionIntelligence.eventCard.trainingComplete`,`Training complete`),"data-testid":`retrain-status-trained`,children:u(N,{className:`h-3 w-3`})}),e.debug===!0&&u(`span`,{className:`rounded bg-black/70 p-0.5 text-white`,title:d(`detectionIntelligence.eventCard.flaggedForDebug`,`Flagged for debug`),"aria-label":d(`detectionIntelligence.eventCard.flaggedForDebug`,`Flagged for debug`),children:u(h,{className:`h-3 w-3`})}),e.favourited===!0&&u(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:d(`detectionIntelligence.eventCard.favourited`,`Favourited`),"aria-label":d(`detectionIntelligence.eventCard.favourited`,`Favourited`),children:u(V,{className:`h-3 w-3`})})]})]}),r(`button`,{type:`button`,onClick:_,className:`min-w-0 px-2 py-1.5 text-left space-y-0.5`,children:[r(`p`,{className:`text-[11px] font-medium text-foreground truncate`,title:e.className,children:[e.className,Ur(e)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,Ur(e)]}):null]}),u(`p`,{className:`text-[10px] text-foreground-subtle truncate`,title:t,children:t}),r(`div`,{className:`flex items-center justify-between gap-2`,children:[u(`span`,{className:`text-[10px] text-foreground-subtle truncate`,children:Kn(e.timestamp,n)}),g&&u(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:g})]})]}),l!==void 0&&u(`div`,{className:`px-2 pb-1.5`,children:l})]})}n();var ai=1400,oi=`Admin-gated URL — opens only inside an authenticated session`;function si({label:t,value:n,title:i}){let{t:a}=X(),[o,s]=l(!1),c=ze();return d(()=>{if(!o)return;let e=setTimeout(()=>s(!1),ai);return()=>clearTimeout(e)},[o]),r(`button`,{type:`button`,onClick:e(()=>{(async()=>{try{await navigator.clipboard.writeText(n),s(!0)}catch{await c({title:a(`detectionIntelligence.copyUrlChips.copyTheMediaUrl`,`Copy the media URL`),message:a(`detectionIntelligence.copyUrlChips.clipboardAccessWasRefusedSelect`,`Clipboard access was refused. Select the URL below and copy it manually.`),label:a(`detectionIntelligence.copyUrlChips.url`,`{{label}} URL`,{label:t}),defaultValue:n,readOnly:!0,cancelLabel:a(`common.close`,`Close`)})}})()},[n,t,c,a]),title:i,"aria-label":a(`detectionIntelligence.copyUrlChips.copyUrl`,`Copy {{label}} URL`,{label:t}),className:`flex min-w-0 items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${o?`border-success/40 bg-success/10 text-success`:`border-border text-foreground-subtle hover:border-primary hover:text-foreground`}`,children:[u(o?N:O,{className:`h-2.5 w-2.5 shrink-0`}),u(`span`,{className:`truncate`,children:o?a(`detectionIntelligence.copyUrlChips.copied`,`Copied`):t})]})}function ci({localUrl:e,publicUrl:t}){let{t:n}=X();return r(`div`,{className:`flex flex-wrap gap-1`,children:[u(si,{label:n(`detectionIntelligence.copyUrlChips.local`,`Local`),value:e,title:n(`detectionIntelligence.copyUrlChips.copyLanUrl`,`Copy LAN URL — {{AUTH_HINT}}`,{AUTH_HINT:oi})}),t&&u(si,{label:n(`detectionIntelligence.copyUrlChips.public`,`Public`),value:t,title:n(`detectionIntelligence.copyUrlChips.copyPublicUrl`,`Copy public URL — {{AUTH_HINT}}`,{AUTH_HINT:oi})})]})}var li={firstFrame:`First frame (track start)`,lastFrame:`Last frame (track end)`,thumbnail:`Best detection`,thumbnailSmall:`Best detection (480)`,snapshot:`Snapshot`,keyFrame:`Key frame (native-res)`,keyFrameSmall:`Key frame (960)`,crop:`Object crop`,fullFrame:`Full frame`,fullFrameBoxed:`Full frame (boxed)`,faceCrop:`Face crop`,plateCrop:`Plate crop`,confirmationCrop:`Confirmation crop (what the gate saw)`,debugCrop:`Debug crop (why this decision)`,sceneFrame:`Scene frame (clean)`,lastSceneFrame:`Last frame (clean)`};function ui(e){return e in li}function di(e){return ui(e)?li[e]:e}function fi(e,t){return`${e}${t}`}n();var pi=3e4;function mi(t){let[n,r]=l(null),i=e(e=>{r(t=>t??e)},[]);return d(()=>{t||r(null)},[t]),{publicOrigin:n,probes:t?u(hi,{onOrigin:i}):null}}function hi({onOrigin:e}){let{data:t}=be({capName:`network-access`});return u(s,{children:(t??[]).map(t=>u(gi,{addonId:t.addonId,onOrigin:e},t.addonId))})}function gi({addonId:e,onOrigin:t}){let{data:n}=Ae({addonId:e},{refetchInterval:pi,retry:!1});return d(()=>{let e=n?he.safeParse(n):null,r=e?.success?e.data.endpoint?.url:void 0;if(r)try{t(new URL(r).origin)}catch{}},[n,t]),null}var _i=typeof et==`function`,vi=`Track flags arrive with the next server update`;function yi(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var bi=_i?et:yi;function xi(e){if(typeof e!=`object`||!e||!(`trackId`in e)||!(`markForTrain`in e)||!(`debug`in e)||!(`favourited`in e))return null;let{trackId:t,markForTrain:n,debug:r,favourited:i}=e;return typeof t!=`string`||typeof n!=`boolean`||typeof r!=`boolean`||typeof i!=`boolean`?null:{trackId:t,markForTrain:n,debug:r,favourited:i}}n();function Si({label:e,hint:t,checked:n,disabled:i,title:a,icon:o,onToggle:s}){return r(`button`,{type:`button`,role:`switch`,"aria-checked":n,"aria-label":e,disabled:i,title:a,onClick:s,className:`flex w-full items-center gap-2 rounded-md border px-2 py-1.5 text-left transition-colors disabled:opacity-50 ${n?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[u(`span`,{className:n?`text-primary`:`text-foreground-subtle`,children:o}),r(`span`,{className:`min-w-0 flex-1`,children:[u(`span`,{className:`block text-[11px] font-medium text-foreground`,children:e}),u(`span`,{className:`block text-[10px] text-foreground-subtle`,children:t})]}),u(`span`,{"aria-hidden":`true`,className:`h-4 w-7 shrink-0 rounded-full p-0.5 transition-colors ${n?`bg-primary`:`bg-border`}`,children:u(`span`,{className:`block h-3 w-3 rounded-full bg-white transition-transform ${n?`translate-x-3`:``}`})})]})}function Ci({deviceId:e,trackId:t,markForTrain:n,debug:i,favourited:a,onChange:o}){let{t:s}=X(),c=bi(),d=Je(),[f,p]=l(null),m=f?.markForTrain??n===!0,g=f?.debug??i===!0,_=f?.favourited??a===!0,v=!_i||c.isPending,y=_i?void 0:vi,b=n=>{v||(async()=>{try{let r=xi(await c.mutateAsync({deviceId:e,trackId:t,flags:n}));if(!r)return;p(r),o?.(r)}catch(e){let t=e instanceof Error?e.message:``;await d({title:s(`detectionIntelligence.trackFlagToggles.couldNotUpdateThisTrack`,`Could not update this track`),message:t===``?s(`detectionIntelligence.trackFlagToggles.couldNotUpdateThisTrack2`,`Could not update this track. Check the server logs.`):t,variant:`danger`})}})()};return r(`div`,{className:`grid gap-1.5 sm:grid-cols-2`,children:[u(Si,{label:s(`detectionIntelligence.trackFlagToggles.markForTraining`,`Mark for training`),hint:s(`detectionIntelligence.trackFlagToggles.keepsThisTrackAndIts`,`Keeps this track and its media past retention`),checked:m,disabled:v,...y===void 0?{}:{title:y},icon:u(K,{className:`h-4 w-4`}),onToggle:()=>b({markForTrain:!m})}),u(Si,{label:s(`detectionIntelligence.trackFlagToggles.debug`,`Debug`),hint:s(`detectionIntelligence.trackFlagToggles.flagThisTrackForDiagnostic`,`Flag this track for diagnostic attention`),checked:g,disabled:v,...y===void 0?{}:{title:y},icon:u(h,{className:`h-4 w-4`}),onToggle:()=>b({debug:!g})}),u(Si,{label:s(`detectionIntelligence.trackFlagToggles.favourited`,`Favourited`),hint:s(`detectionIntelligence.trackFlagToggles.keepsThisTrackAndIts`,`Keeps this track and its media past retention`),checked:_,disabled:v,...y===void 0?{}:{title:y},icon:u(V,{className:`h-4 w-4`}),onToggle:()=>b({favourited:!_})})]})}var wi=100,Ti=120,Ei={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Di=e=>e<0?0:e>1?1:e,Oi=e=>Math.round(e*100)/100;function ki(e,t){if(e.length<=t)return[...e];let n=(e.length-1)/(t-1),r=[];for(let i=0;i<t;i++)r.push(e[Math.round(i*n)]);return r[r.length-1]=e[e.length-1],r}function Ai(e,t,n){if(e.length===0||t===null)return Ei;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return Ei;let a=ki(e,n?.maxPoints??Ti).map(e=>({x:Oi(Di(e.x/r)*wi),y:Oi(Di(e.y/i)*wi)})),o=a[0]??null,s=a[a.length-1]??null,c=a.length>=2?a.map(e=>`${e.x},${e.y}`).join(` `):``,l=(n?.snapshots??[]).map(e=>({x:Oi(Di(e.x/r)*wi),y:Oi(Di(e.y/i)*wi),mediaId:e.mediaId})),u=null,d=-1;for(let t of e){let e=Di(t.bbox.w/r)*Di(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:Oi(Di(u.bbox.x/r)*wi),y:Oi(Di(u.bbox.y/i)*wi),w:Oi(Di(u.bbox.w/r)*wi),h:Oi(Di(u.bbox.h/i)*wi)}:null}}var ji=typeof rt==`function`,Mi=`Track deletion arrives with the next server update`;function Ni(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var Pi=ji?rt:Ni;n();var Fi=15e3,Ii=k();function Li({url:e,label:t}){let{src:n,failed:r}=zt(e);return n===null?u(`div`,{className:`flex h-full w-full items-center justify-center bg-surface-hover`,children:r?u(R,{className:`h-4 w-4 text-foreground-subtle opacity-60`}):u(M,{className:`h-4 w-4 animate-spin text-foreground-subtle opacity-70`})}):u(`img`,{src:n,alt:t,className:`h-full w-full object-cover`})}var Ri=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),zi=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`,`sceneFrame`,`lastSceneFrame`]);function Bi(e){let[t,n]=l(null);return d(()=>{if(n(null),!e)return;let t=!1,r=new Image;return r.onload=()=>{t||n({width:r.naturalWidth,height:r.naturalHeight})},r.src=e,()=>{t=!0,r.onload=null}},[e]),t}function Vi({overlay:e,onPickSnapshot:t}){let{t:n}=X();return!e.polyline&&!e.peakBox&&e.snapshots.length===0?null:r(`svg`,{viewBox:`0 0 100 100`,preserveAspectRatio:`none`,className:`pointer-events-none absolute inset-0 h-full w-full`,children:[e.peakBox&&u(`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&&u(`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)=>u(`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)=>u(`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:u(`title`,{children:n(`detectionIntelligence.eventDetailPanel.snapshotCheckpointClickToView`,`Snapshot checkpoint — click to view this frame`)})},`snap-${String(e.mediaId)}-${String(r)}`)),e.start&&u(`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&&u(`circle`,{cx:e.end.x,cy:e.end.y,r:2.4,fill:`var(--color-danger)`,stroke:`var(--color-background)`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`})]})}function Hi({label:e,value:t,mono:n}){return r(`div`,{className:`flex items-baseline justify-between gap-3 border-b border-border/60 py-1.5 last:border-0`,children:[u(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),u(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono text-[11px]`:``}`,title:t,children:t})]})}function Ui({row:t,cameraName:n,deleteAvailable:a,onClose:o,onDeleted:c,onFlagsChanged:f}){let{t:p}=X(),m=ee(),h=Je(),g=Qe(),_=Pi(),y=t!==null,x=t?.deviceId??0,S=t?.trackId??``,C=t?.timestamp??0,w=t?.windowMs??0,{data:T}=Et({deviceId:x,trackId:S},{enabled:y}),{data:E}=vt({trackId:S,deviceId:x},{enabled:y}),D=T?.bestEventId===void 0?void 0:Number(T.bestEventId),{data:O}=ct({ownerType:`object`,eventId:D??0,deviceId:x},{enabled:y&&D!==void 0&&Number.isFinite(D)}),{data:k}=Ue({deviceId:x},{enabled:y}),A=(k??[]).find(e=>e.addonId!==void 0)?.addonId,{data:j}=Ce({deviceId:x,since:C-Fi,until:C+w+Fi,provider:A??``},{enabled:y&&A!==void 0}),[N,P]=l(null),[F,I]=l(!1),{publicOrigin:L,probes:z}=mi(y);d(()=>{P(null)},[x,S]);let B=i(()=>{let e=E??[],t=O??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[E,O]),V=N??B,H=zt(V?V.url:void 0),U=i(()=>{let e=new Set,t=[];for(let n of[...O??[],...E??[]])e.has(n.mediaId)||(e.add(n.mediaId),t.push(n));return t},[O,E]),W=i(()=>U.find(e=>Ri.has(e.kind))??null,[U]),G=Bi(zt(W?W.url:void 0).src),te=i(()=>Ai(T?.positions??[],G,{snapshots:(T?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaId:e.mediaId}))}),[T?.positions,T?.snapshots,G]),K=e(e=>{let t=U.find(t=>t.mediaId===e);t&&P(t)},[U]);if(t===null)return null;let q=H.src,ne=V?.kind,re=ne!==void 0&&zi.has(ne)&&G!==null&&(T?.positions.length??0)>=2,J=j&&j.length>0?j[0]:null,ie=()=>{J&&(I(!0),(async()=>{try{let e=await m.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:J.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{h({title:p(`detectionIntelligence.eventDetailPanel.clipUnavailable`,`Clip unavailable`),message:p(`detectionIntelligence.eventDetailPanel.couldNotResolveClipPlayback`,`Could not resolve clip playback. Check the server logs.`),variant:`warning`})}finally{I(!1)}})())},ae=()=>{!a||_.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:t.deviceId,trackIds:[t.trackId]}),c()}catch{await h({title:p(`detectionIntelligence.eventDetailPanel.deleteFailed`,`Delete failed`),message:p(`detectionIntelligence.eventDetailPanel.failedToDeleteThisTrack`,`Failed to delete this track. Check the server logs.`),variant:`danger`})}})()},oe=Math.round(t.importance*100),se=T?.importanceReason?`${String(oe)}% · ${T.importanceReason}`:`${String(oe)}%`,ce=T?.zonesVisited&&T.zonesVisited.length>0?T.zonesVisited.join(`, `):`—`,le=T?.audioLabels&&T.audioLabels.length>0?T.audioLabels:t.audioLabels&&t.audioLabels.length>0?t.audioLabels:void 0,ue=le===void 0?`—`:le.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `),de=T?T.totalDistance.toFixed(2):`—`,fe=ni(T?.previewMissReason),pe=Jn(T?T.firstSeen:C),me=T?Jn(T.lastSeen):`—`;return u(He,{open:!0,onOpenChange:e=>!e&&o(),children:r(ye,{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:[u(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:r(`div`,{className:`min-w-0`,children:[r(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:[t.className,Ur(t)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,Ur(t)]}):null]}),u(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:n})]})}),r(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[q?u(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:u(dr,{src:q,alt:p(`detectionIntelligence.eventDetailPanel.keyFrameFrom`,`Key frame from {{cameraName}}`,{cameraName:n}),fit:`natural`,className:`w-full`,overlay:re?u(Vi,{overlay:te,onPickSnapshot:K}):void 0})}):u(`div`,{className:`flex aspect-video w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-surface-hover text-foreground-subtle`,children:H.failed?r(s,{children:[u(R,{className:`h-8 w-8 opacity-60`}),u(`span`,{className:`text-[11px]`,children:p(`detectionIntelligence.eventDetailPanel.keyFrameMediaUnavailable`,`Key-frame media unavailable`)})]}):u(M,{className:`h-6 w-6 animate-spin opacity-70`})}),U.length>0&&u(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:U.map(e=>{let t=di(e.kind),n=fi(Ii,e.url),i=L?fi(L,e.url):null;return r(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[u(`button`,{type:`button`,onClick:()=>P(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${t} · ${Jn(e.timestamp)}`,children:u(Li,{url:e.url,label:t})}),r(`figcaption`,{className:`min-w-0 px-0.5`,children:[u(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:t,children:t}),u(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:Jn(e.timestamp),children:qn(e.timestamp)})]}),u(ci,{localUrl:n,publicUrl:i})]},e.mediaId)})}),z,J&&r(Y,{variant:`secondary`,onClick:ie,disabled:F,children:[F?u(M,{className:`h-3.5 w-3.5 animate-spin`}):u(b,{className:`h-3.5 w-3.5`}),` `,p(`detectionIntelligence.eventDetailPanel.viewClip`,`View clip`)]}),u(Ci,{deviceId:t.deviceId,trackId:t.trackId,...(T?.markForTrain??t.markForTrain)===void 0?{}:{markForTrain:T?.markForTrain??t.markForTrain},...(T?.debug??t.debug)===void 0?{}:{debug:T?.debug??t.debug},...(T?.favourited??t.favourited)===void 0?{}:{favourited:T?.favourited??t.favourited},onChange:f}),fe!==null&&r(`div`,{className:`rounded-lg border border-warning/40 bg-warning/8 px-3 py-2`,children:[u(`p`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:p(`detectionIntelligence.eventDetailPanel.bestShot`,`Best shot`)}),u(`p`,{className:`mt-0.5 text-xs text-foreground`,children:fe.sentence}),u(`code`,{className:`mt-1 block break-all font-mono text-[10px] text-foreground-subtle`,children:fe.raw})]}),r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[u(Hi,{label:p(`detectionIntelligence.eventDetailPanel.camera`,`Camera`),value:n}),u(Hi,{label:p(`detectionIntelligence.eventDetailPanel.class`,`Class`),value:t.className}),u(Hi,{label:p(`detectionIntelligence.eventDetailPanel.label`,`Label`),value:t.label??`—`}),u(Hi,{label:p(`detectionIntelligence.eventDetailPanel.subLabel`,`Sub-label`),value:t.subLabel??`—`}),u(Hi,{label:p(`detectionIntelligence.eventDetailPanel.importance`,`Importance`),value:se}),u(Hi,{label:p(`detectionIntelligence.eventDetailPanel.zonesVisited`,`Zones visited`),value:ce}),u(Hi,{label:p(`detectionIntelligence.eventDetailPanel.audioHeard`,`Audio heard`),value:ue}),u(Hi,{label:p(`detectionIntelligence.eventDetailPanel.totalDistance`,`Total distance`),value:de}),u(Hi,{label:p(`detectionIntelligence.eventDetailPanel.firstSeen`,`First seen`),value:pe}),u(Hi,{label:p(`detectionIntelligence.eventDetailPanel.lastSeen`,`Last seen`),value:me}),u(Hi,{label:p(`detectionIntelligence.eventDetailPanel.track`,`Track`),value:t.trackId,mono:!0})]})]}),u(`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:u(`span`,{title:a?void 0:Mi,children:r(Y,{variant:`secondary`,onClick:ae,disabled:!a||_.isPending,children:[_.isPending?u(M,{className:`h-3.5 w-3.5 animate-spin`}):u(v,{className:`h-3.5 w-3.5`}),` `,p(`detectionIntelligence.eventDetailPanel.deleteTrack`,`Delete track`)]})})})]})})}var Wi={status:`debug.tape.status`,promote:`debug.tape.promote`,list:`debug.tape.list`,tracks:`debug.tape.tracks`,review:`debug.tape.review`,release:`debug.tape.release`,remove:`debug.tape.delete`},Gi={setRelation:`debug.gt.setRelation`,setPurity:`debug.gt.setPurity`,list:`debug.gt.list`},Ki=w(`/addon/pipeline-analytics/tape-export`),qi=10*6e4;function Ji(e){return`${Ki}?tapeId=${encodeURIComponent(e)}`}var Yi=`The server answered in a shape this build does not understand.`;function Xi(e){return e instanceof Error?e.message:`The action failed.`}function Z(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 Zi(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 Qi(e,t){let n=e[t];return typeof n==`boolean`?n:null}function $i(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 ea(e){return e===`off`||e===`recording`||e===`refused`||e===`failing`||e===`unknown`}function ta(e){if(!Z(e))return null;let t=Q(e,`deviceId`),n=e.state,r=Q(e,`gapsSinceArmed`),i=Zi(e,`segmentsHeld`),a=Zi(e,`bytesLastHour`),o=Zi(e,`bytesHeld`);if(t===null||!ea(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 na(e){return Z(e)?$i(e.cameras,ta):null}function ra(e){if(!Z(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=Qi(e,`reviewed`),f=Qi(e,`released`),p=$i(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 ia(e){return Z(e)?$i(e.tapes,ra):null}function aa(e){if(!Z(e))return null;let t=$(e,`trackId`),n=Q(e,`firstT`),r=Q(e,`lastT`),i=Q(e,`boundFrames`),a=$(e,`cls`),o=Qi(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 oa(e){if(!Z(e))return null;let t=$(e,`tapeId`),n=Q(e,`deviceId`),r=Q(e,`fromMs`),i=Q(e,`toMs`),a=Qi(e,`reviewed`),o=$i(e.lanes,aa);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 sa(e){if(!Z(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 ca(e){if(!Z(e))return null;let t=e.status;if(t===`released`){let n=Q(e,`unpinned`),r=Qi(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 la(e){if(!Z(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 ua(e){switch(e.status){case`released`:case`deleted`:return null;case`already-released`:return`This tape was already released.`;case`not-found`:return`That tape no longer exists — it may have been released or deleted elsewhere.`;case`pins-owed`:return`Refused: this tape still names pins not yet taken back. Try again shortly — the ledger settles them automatically.`;case`unavailable`:return`Unavailable on this node: ${e.reason}`}}function da(e){if(!Z(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 fa(e){if(!Z(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 pa(e){if(!Z(e))return null;let t=$i(e.relations,da),n=$i(e.purities,fa),r=Qi(e,`truncated`);return t===null||n===null||r===null?null:{relations:t,purities:n,truncated:r}}function ma(e){if(!e.truncated)return null;let t=e.relations.length+e.purities.length;return`Showing the first ${String(t)} marks — more exist for this window.`}function ha(e){return e.filter(e=>e.segmentsHeld===null||e.segmentsHeld>0).map(e=>({deviceId:e.deviceId,segmentsUnknown:e.segmentsHeld===null}))}function ga(e){return e.slice(1).map((t,n)=>({trackId:e[n]??t,otherTrackId:t}))}function _a(e){return e.flatMap((t,n)=>e.slice(n+1).map(e=>({trackId:t,otherTrackId:e})))}function va(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 ya(e){switch(e.state){case`off`:return`Off`;case`recording`:return`Recording`;case`refused`:return`Refused: ${e.reason??`unknown reason`}`;case`failing`:return`Failing: ${e.reason??`unknown reason`}`;case`unknown`:return`Unknown: ${e.reason??`unknown reason`}`}}var ba={"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 xa(e,t){let n=ba[e]??`Refused (${e}).`;return t.length>0?`${n} ${t}`:n}function Sa(e){if(e.length===0)return null;let t=new Date(e).getTime();return Number.isFinite(t)?t:null}function Ca(e){return e<1024*1024?`${(e/1024).toFixed(0)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function wa(e){return e===null?`unknown`:Ca(e)}function Ta(e){return e===null?`unknown`:String(e)}function Ea(e,t){let n=t.trim();return e===404?`This tape no longer exists on this node (unknown tape).`:e===503?n.length>0?n:`Tapes are unavailable on this node.`:e===500?n.length>0?n:`The export could not be read (the tape may have just been released or deleted).`:`Download failed (${String(e)}).`}n();function Da({cameras:e,call:t,onPromoted:n}){let{t:i}=X(),[a,o]=l(``),[s,c]=l(``),[d,f]=l(``),[p,m]=l(``),[h,g]=l(``),[_,v]=l(`auto`),[y,b]=l(!1),[x,S]=l(null),C=async()=>{let r=Number.parseInt(a===``?e[0]?.value??``:a,10),i=Sa(s),o=Sa(d);if(!Number.isFinite(r)||i===null||o===null){S(`Pick a camera and both ends of the window.`);return}b(!0),S(null);try{let e=sa(await t(Wi.promote,{deviceId:r,fromMs:i,toMs:o,scenario:p,...h.trim().length>0?{note:h.trim()}:{},..._===`day`||_===`ir`?{lighting:_}:{}}));e===null?S(Yi):e.ok?(S(`Promoted ${e.tapeId}: ${String(e.frames)} frames, ${Ca(e.bytes)}, ${String(e.pinnedTracks)} tracks pinned`+(e.state===`incomplete`?` — incomplete (it has gaps) and cannot become a case.`:`.`)),n()):S(xa(e.reason,e.detail))}catch(e){S(Xi(e))}finally{b(!1)}};return r(`div`,{className:`flex flex-wrap items-end gap-2 rounded-md border border-border px-3 py-2`,children:[u(`div`,{className:`w-40`,children:u(ke,{value:a,options:[...e],onChange:e=>o(e.target.value),"aria-label":i(`eventsDebugTapesPromoteForm.camera`,`Camera`)})}),u(Ze,{type:`datetime-local`,"aria-label":i(`eventsDebugTapesPromoteForm.from`,`From`),value:s,onChange:e=>c(e.target.value),className:`w-48`}),u(Ze,{type:`datetime-local`,"aria-label":i(`eventsDebugTapesPromoteForm.to`,`To`),value:d,onChange:e=>f(e.target.value),className:`w-48`}),u(Ze,{"aria-label":i(`eventsDebugTapesPromoteForm.scenario`,`Scenario`),placeholder:`615-door-groups`,value:p,onChange:e=>m(e.target.value),className:`w-44`}),u(Ze,{"aria-label":i(`eventsDebugTapesPromoteForm.note`,`Note`),placeholder:i(`eventsDebugTapesPromoteForm.optionalNote`,`optional note`),value:h,onChange:e=>g(e.target.value),className:`w-52`}),u(`div`,{className:`w-28`,children:u(ke,{value:_,"aria-label":i(`eventsDebugTapesPromoteForm.lighting`,`Lighting`),options:[{value:`auto`,label:i(`eventsDebugTapesPromoteForm.lightingAuto`,`Lighting: auto`)},{value:`day`,label:`day`},{value:`ir`,label:`ir`}],onChange:e=>v(e.target.value)})}),r(Y,{onClick:()=>void C(),disabled:y||e.length===0,children:[y?u(M,{className:`h-3.5 w-3.5 animate-spin`}):null,` Promote window`]}),u(`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&&u(`p`,{className:`w-full text-xs text-foreground`,children:x})]})}var Oa=`pipeline-analytics`,ka=`debug.listTracks`,Aa=`debug.analyze`,ja=w(`/addon/pipeline-analytics/debug-export`);function Ma(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Na(e,t){let n=e[t];return typeof n==`string`?n:null}function Pa(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Fa(e,t){let n=e[t];return typeof n==`boolean`?n:null}function Ia(e){return e===`error`||e===`warn`||e===`info`}function La(e){if(!Ma(e))return null;let t=Na(e,`code`),n=Na(e,`detail`),r=e.severity;return t===null||n===null||!Ia(r)?null:{code:t,severity:r,detail:n}}function Ra(e){if(!Ma(e))return null;let t=Na(e,`trackId`),n=Pa(e,`deviceId`),r=Na(e,`className`),i=Pa(e,`firstSeen`),a=Pa(e,`lastSeen`),o=Pa(e,`durationMs`),s=Fa(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=Na(e,`label`),l=Na(e,`subLabel`),u=Na(e,`previewMissReason`),d=Fa(e,`markForTrain`),f=Fa(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:Pa(e,`importance`)??0,bestEventId:Na(e,`bestEventId`)??``,...d===null?{}:{markForTrain:d},...f===null?{}:{favourited:f},debug:!0,...u===null||u.length===0?{}:{previewMissReason:u}}}function za(e){let t=Ra(e);if(t===null||!Ma(e))return null;let n=Pa(e,`mediaCount`),r=Pa(e,`eventCount`),i=Pa(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=La(e);t!==null&&c.push(t)}let l=e.thumbnailProvenance;return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c,...Qr(l)?{thumbnailProvenance:l}:{}}}function Ba(e){if(!Ma(e))return null;let t=Fa(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=Ra(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function Va(e){if(!Ma(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=za(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var Ha={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 Ua(e){return Ha[e]??e}var Wa={error:0,warn:1,info:2};function Ga(e){return e.toSorted((e,t)=>Wa[e.severity]-Wa[t.severity]||e.code.localeCompare(t.code))}function Ka(e){return e.length===0?ja:`${ja}?deviceIds=${e.join(`,`)}`}function qa(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 Ja(e,t){return`${String(e)}:${t}`}function Ya(e,t){let n=[],r=new Set;for(let i of e){let e=Ja(i.deviceId,i.trackId);!t.has(e)||r.has(e)||(r.add(e),n.push({deviceId:i.deviceId,trackId:i.trackId}))}return n}n();function Xa({tapeId:e,call:t,onClose:n,onChanged:i}){let{t:a}=X(),s=o({queryKey:[`events-debug`,`tapes`,`tracks`,e],queryFn:async()=>oa(await t(Wi.tracks,{tapeId:e}))}),c=s.data??null,d=o({queryKey:[`events-debug`,`tapes`,`marks`,e],enabled:c!==null,queryFn:async()=>c===null?null:pa(await t(Gi.list,{deviceId:c.deviceId,since:c.fromMs-qi,until:c.toMs+qi,limit:5e3}))}),[f,p]=l([]),[m,h]=l(``),[g,_]=l(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 d.refetch(),i()}catch(e){_(Xi(e))}};if(c===null)return s.isLoading?u(`p`,{className:`text-xs`,children:a(`eventsDebugTapesReview.loadingTheTape`,`Loading the tape…`)}):u(Me,{message:Yi});let b=c.deviceId,x=(e,t)=>y(e.map(e=>[Gi.setRelation,{deviceId:b,...e,relation:t}])),S=e=>{let t=Number.parseFloat(m),n=e===`mixed`&&Number.isFinite(t)?c.fromMs+t*1e3:void 0;return y(f.map(t=>[Gi.setPurity,{deviceId:b,trackId:t,purity:e,...n===void 0?{}:{switchAtMs:Math.round(n)}}]))},C=d.data==null?null:ma(d.data);return r(`div`,{className:`space-y-2 rounded-md border border-primary/40 px-3 py-2`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[r(`span`,{className:`text-xs font-medium`,children:[c.tapeId,` — `,String(c.lanes.length),` tracks`]}),u(Y,{disabled:f.length<2,onClick:()=>void x(ga(f),`same-subject`),children:a(`eventsDebugTapesReview.sameSubject`,`Same subject`)}),u(Y,{variant:`secondary`,disabled:f.length<2,onClick:()=>void x(_a(f),`different-subjects`),children:a(`eventsDebugTapesReview.differentSubjects`,`Different subjects`)}),u(Ze,{"aria-label":a(`eventsDebugTapesReview.changedAtSFromTape`,`Changed at (s from tape start)`),placeholder:a(`eventsDebugTapesReview.changedAtS`,`changed at s`),value:m,onChange:e=>h(e.target.value),className:`w-28`}),u(Y,{variant:`secondary`,disabled:f.length!==1,onClick:()=>void S(`mixed`),children:a(`eventsDebugTapesReview.mixed`,`Mixed`)}),u(Y,{variant:`secondary`,disabled:f.length===0,onClick:()=>void S(`not-a-subject`),children:a(`eventsDebugTapesReview.notASubject`,`Not a subject`)}),u(Y,{variant:c.reviewed?`secondary`:`primary`,onClick:()=>void y([[Wi.review,{tapeId:c.tapeId,reviewed:!c.reviewed}]]).then(()=>s.refetch()),children:c.reviewed?a(`eventsDebugTapesReview.markNotReviewed`,`Mark not reviewed`):a(`eventsDebugTapesReview.markReviewed`,`Mark reviewed`)}),u(Y,{variant:`ghost`,onClick:n,children:a(`common.close`,`Close`)})]}),g!==null&&u(Me,{message:g}),C!==null&&u(Me,{variant:`warning`,message:C}),u(`ul`,{className:`space-y-1`,children:c.lanes.toSorted((e,t)=>e.firstT-t.firstT).map(e=>u(Za,{lane:e,marks:d.data===null||d.data===void 0?[]:va(e.trackId,d.data),selected:f.includes(e.trackId),onToggle:()=>v(e.trackId)},e.trackId))})]})}function Za({lane:e,marks:t,selected:n,onToggle:i}){let{t:a}=X(),{src:o}=zt(e.stillStored?Bt(`track`,e.trackId):void 0);return r(`li`,{className:`flex items-center gap-2 text-xs`,children:[u(`input`,{type:`checkbox`,"aria-label":a(`eventsDebugTapesReview.select`,`select {{trackId}}`,{trackId:e.trackId}),checked:n,onChange:i}),o===null?u(`div`,{className:`h-10 w-10 rounded bg-surface-hover`}):u(`img`,{src:o,alt:e.trackId,className:`h-10 w-10 rounded object-cover`}),u(`span`,{className:`font-mono`,children:e.trackId}),u(`span`,{children:e.cls}),r(`span`,{className:`text-foreground-subtle`,children:[qa(e.firstT),` → `,qa(e.lastT),` · `,String(e.boundFrames),` `,`frames`]}),!e.stillStored&&u(`span`,{className:`text-foreground-subtle`,children:a(`eventsDebugTapesReview.notStoredMarkedThroughThe`,`not stored — marked through the tape`)}),t.map(e=>u(tt,{variant:`info`,children:e},e))]})}n();var Qa=`camstack_admin_token`;function $a(){let e=ee();return(t,n)=>e.trpcClient.addons.custom.mutate({addonId:Oa,action:t,input:n})}async function eo(e,t){let n=localStorage.getItem(Qa),r={};n!==null&&(r.Authorization=`Bearer ${n}`);let i=await fetch(Ji(e),{headers:r});if(!i.ok){let e=await i.text().catch(()=>``);throw Error(Ea(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 to(){let{t:e}=X(),[t,n]=l(!1);return u(st,{expanded:t,onExpandedChange:n,header:u(`span`,{className:`text-sm font-medium text-foreground`,children:e(`eventsDebugTapes.trackingTapes`,`Tracking tapes`)}),children:u(no,{})})}function no(){let{t:e}=X(),t=$a(),n=gt({isCamera:!0,projection:`slim`}),a=i(()=>{let e=new Map;for(let t of n.data??[])e.set(t.id,t.name);return t=>e.get(t)??`Camera ${String(t)}`},[n.data]),s=o({queryKey:[`events-debug`,`tapes`,`status`],queryFn:async()=>na(await t(Wi.status,{}))}),c=o({queryKey:[`events-debug`,`tapes`,`list`],queryFn:async()=>ia(await t(Wi.list,{}))}),[d,f]=l(null),[p,m]=l(null),h=async e=>{m(null);try{await eo(e.id,`${e.scenario}.tape-bundle.json.gz`)}catch(e){m(Xi(e))}},g=async e=>{let n=ca(await t(Wi.release,{tapeId:e.id}));if(n===null)throw Error(Yi);let r=ua(n);if(r!==null)throw Error(r);await c.refetch()},y=async e=>{let n=la(await t(Wi.remove,{tapeId:e.id}));if(n===null)throw Error(Yi);let r=ua(n);if(r!==null)throw Error(r);await c.refetch()};return r(`div`,{className:`space-y-3`,children:[r(`p`,{className:`text-xs text-foreground-subtle`,children:[`A camera records while its`,` `,u(`strong`,{children:e(`eventsDebugTapes.recordTheTrackHistory`,`Record the track history`)}),` `,`switch (camera settings → Tracking) is on; segments are kept 24 h. Promote a window worth keeping, label it in the review, mark it reviewed, download it and turn it into a test case with `,u(`code`,{children:`npm run tracking-bench -- case`}),`.`]}),p!==null&&u(Me,{message:p}),s.isLoading&&u(`p`,{className:`text-xs text-foreground-subtle`,children:e(`eventsDebugTapes.loadingCameraStatus`,`Loading camera status…`)}),s.data===null&&u(Me,{message:`The server answered in a shape this build does not understand.`}),r(`table`,{className:`w-full text-xs`,children:[u(`thead`,{children:r(`tr`,{className:`text-left text-foreground-subtle`,children:[u(`th`,{children:e(`eventsDebugTapes.camera`,`Camera`)}),u(`th`,{children:e(`eventsDebugTapes.state`,`State`)}),u(`th`,{children:e(`eventsDebugTapes.framesMin`,`Frames/min`)}),u(`th`,{children:e(`eventsDebugTapes.lastHour`,`Last hour`)}),u(`th`,{children:e(`eventsDebugTapes.held`,`Held`)}),u(`th`,{children:e(`eventsDebugTapes.gaps`,`Gaps`)})]})}),u(`tbody`,{children:(s.data??[]).map(e=>r(`tr`,{children:[u(`td`,{children:a(e.deviceId)}),u(`td`,{children:u(tt,{variant:e.state===`recording`?`success`:e.state===`off`?`default`:e.state===`unknown`?`warning`:`danger`,children:ya(e)})}),u(`td`,{children:e.framesPerMin===void 0?`—`:String(Math.round(e.framesPerMin))}),u(`td`,{title:e.shelfError,children:wa(e.bytesLastHour)}),r(`td`,{title:e.shelfError,children:[Ta(e.segmentsHeld),` seg · `,wa(e.bytesHeld)]}),u(`td`,{children:String(e.gapsSinceArmed)})]},e.deviceId))})]}),u(Da,{cameras:ha(s.data??[]).map(t=>({value:String(t.deviceId),label:t.segmentsUnknown?e(`eventsDebugTapes.segmentsUnknown`,`{{value1}} (segments unknown)`,{value1:a(t.deviceId)}):a(t.deviceId)})),call:t,onPromoted:()=>void c.refetch()}),c.isLoading&&u(`p`,{className:`text-xs text-foreground-subtle`,children:e(`eventsDebugTapes.loadingPromotedTapes`,`Loading promoted tapes…`)}),c.data===null&&u(Me,{message:`The server answered in a shape this build does not understand.`}),r(`table`,{className:`w-full text-xs`,children:[u(`thead`,{children:r(`tr`,{className:`text-left text-foreground-subtle`,children:[u(`th`,{children:e(`eventsDebugTapes.scenario`,`Scenario`)}),u(`th`,{children:e(`eventsDebugTapes.camera`,`Camera`)}),u(`th`,{children:e(`eventsDebugTapes.window`,`Window`)}),u(`th`,{children:e(`eventsDebugTapes.state`,`State`)}),u(`th`,{children:e(`eventsDebugTapes.tracks`,`Tracks`)}),u(`th`,{})]})}),u(`tbody`,{children:(c.data??[]).map(t=>r(`tr`,{children:[u(`td`,{children:t.scenario}),u(`td`,{children:a(t.deviceId)}),r(`td`,{children:[new Date(t.fromMs).toLocaleString(),` · `,qa(t.toMs-t.fromMs),` `,`· `,t.lighting]}),r(`td`,{children:[u(tt,{variant:t.state===`complete`?`success`:`warning`,children:t.state}),` `,t.reviewed&&u(tt,{variant:`info`,children:`reviewed`}),` `,t.released&&u(tt,{children:`released`})]}),r(`td`,{children:[String(t.tracksStillStored),`/`,String(t.tracks.length),` stored`]}),r(`td`,{className:`space-x-1 text-right`,children:[u(Y,{variant:`secondary`,"aria-label":e(`eventsDebugTapes.review`,`Review {{scenario}}`,{scenario:t.scenario}),onClick:()=>f(t.id),children:e(`eventsDebugTapes.review2`,`Review`)}),u(Y,{variant:`ghost`,"aria-label":e(`eventsDebugTapes.download`,`Download {{scenario}}`,{scenario:t.scenario}),onClick:()=>void h(t),children:u(_,{className:`h-3.5 w-3.5`})}),u(Ee,{label:e(`eventsDebugTapes.release`,`Release`),icon:U,title:e(`eventsDebugTapes.release2`,`Release {{scenario}}?`,{scenario:t.scenario}),description:e(`eventsDebugTapes.releasingReturnsThisTapeS`,`Releasing returns this tape's pinned tracks to ordinary retention — they can be pruned from then on. The promoted bundle itself is kept until deleted.`),confirmLabel:e(`eventsDebugTapes.release`,`Release`),triggerVariant:`ghost`,confirmVariant:`danger`,disabled:t.released,action:()=>g(t)}),u(Ee,{label:e(`common.delete`,`Delete`),icon:v,title:e(`eventsDebugTapes.delete`,`Delete {{scenario}}?`,{scenario:t.scenario}),description:e(`eventsDebugTapes.deletingRemovesThePromotedBundle`,`Deleting removes the promoted bundle and its index row for good. Its tracks' pins are released first — this cannot be undone.`),confirmLabel:e(`common.delete`,`Delete`),triggerVariant:`ghost`,confirmVariant:`danger`,action:()=>y(t)})]})]},t.id))})]}),d!==null&&u(Xa,{tapeId:d,call:t,onClose:()=>f(null),onChanged:()=>void c.refetch()})]})}n();var ro=`all`,io=`The server answered in a shape this build does not understand.`,ao={error:`danger`,warn:`warning`,info:`info`};function oo({findings:e}){let{t}=X();return e.length===0?u(tt,{variant:`success`,children:t(`eventsDebug.noAnomalyFound`,`no anomaly found`)}):u(`div`,{className:`flex flex-wrap gap-1`,children:Ga(e).map(e=>u(tt,{variant:ao[e.severity],title:e.detail,children:Ua(e.code)},e.code))})}function so({track:e,report:t,analyzing:n}){let{t:i}=X(),a=ni(t?.previewMissReason??e.previewMissReason);return r(`div`,{className:`space-y-1 border-t border-border pt-1.5`,children:[t===void 0?u(`span`,{className:`text-[10px] text-foreground-subtle`,children:n?i(`eventsDebug.analysing`,`analysing…`):i(`eventsDebug.notAnalysed`,`not analysed`)}):r(s,{children:[u(oo,{findings:t.findings}),r(`p`,{className:`text-[10px] text-foreground-subtle`,title:t.mediaKinds.length>0?t.mediaKinds.join(`, `):i(`eventsDebug.noMediaOfAnyKind`,`no media of any kind`),children:[String(t.mediaCount),` media · `,String(t.eventCount),` events ·`,` `,String(t.positionCount),` positions`]})]}),a!==null&&u(`p`,{className:`text-[10px] text-foreground-subtle`,title:a.raw,children:a.sentence})]})}function co(){let{t:e}=X(),t=ee(),[n,a]=l(ro),[s,c]=l(!1),[d,p]=l(null),[m,g]=l(new Set),[v,y]=l(null),[b,x]=l(null),[S,C]=l(null),[w,T]=l([]),E=bi(),D=gt({isCamera:!0,projection:`slim`}),O=i(()=>[{value:ro,label:e(`eventsDebug.allCameras`,`All cameras`)},...(D.data??[]).map(e=>({value:String(e.id),label:e.name}))],[D.data,e]),k=i(()=>{let e=new Map;for(let t of D.data??[])e.set(t.id,t.name);return e},[D.data]),A=e=>k.get(e)??`Camera ${String(e)}`,j=i(()=>n===ro?[]:[Number.parseInt(n,10)],[n]),P=o({queryKey:[`events-debug`,`list`,j],queryFn:async()=>Ba(await t.trpcClient.addons.custom.mutate({addonId:Oa,action:ka,input:j.length===0?{}:{deviceIds:j}}))}),F=i(()=>(P.data?.tracks??[]).map(e=>e.trackId),[P.data]),L=o({queryKey:[`events-debug`,`analyze`,F],enabled:F.length>0,queryFn:async()=>Va(await t.trpcClient.addons.custom.mutate({addonId:Oa,action:Aa,input:{trackIds:F}}))}),R=i(()=>{let e=new Map;for(let t of L.data?.reports??[])e.set(t.trackId,t);return e},[L.data]),z=P.data?.tracks??[],B=P.data===null||L.data===null,H=()=>{P.refetch(),L.refetch()},U=e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},W=()=>{g(new Set(z.map(e=>Ja(e.deviceId,e.trackId))))},G=()=>g(new Set),te=async(e,t)=>{let n=e===`analyzed`?{debug:!1}:{favourited:!0},r=0,i=[];for(let e of t)try{await E.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,flags:n}),r+=1}catch{i.push(e.trackId)}return{applied:r,refused:i}},K=e=>{if(!_i||b!==null)return;let t=Ya(z,m);t.length!==0&&(x(e),C(null),(async()=>{let n=await te(e,t);x(null);let r=new Set(n.refused);g(new Set(t.filter(e=>r.has(e.trackId)).map(e=>Ja(e.deviceId,e.trackId)))),e===`analyzed`&&T(t.filter(e=>!r.has(e.trackId))),n.refused.length>0&&C(`${String(n.refused.length)} of ${String(t.length)} were refused by the server and are still selected. Check the hub log.`),P.refetch()})())},q=()=>{let e=w;e.length===0||b!==null||(x(`analyzed`),C(null),(async()=>{for(let t of e)try{await E.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,flags:{debug:!0}})}catch{C(`Some tracks could not be re-marked. Refresh and try again.`)}x(null),T([]),P.refetch()})())},re=async()=>{c(!0),p(null);try{await Ut(Ka(j),`camstack-debug.zip`)}catch(e){p(e instanceof Error?e.message:`Export failed.`)}finally{c(!1)}},J=b!==null;return r(`section`,{className:`space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[u(`div`,{className:`w-44`,children:u(ke,{value:n,options:O,onChange:e=>a(e.target.value)})}),r(Y,{variant:`secondary`,onClick:H,disabled:P.isFetching,children:[P.isFetching?u(M,{className:`h-3.5 w-3.5 animate-spin`}):u(ne,{className:`h-3.5 w-3.5`}),e(`common.refresh`,`Refresh`)]}),r(Y,{onClick:()=>void re(),disabled:s||z.length===0,children:[s?u(M,{className:`h-3.5 w-3.5 animate-spin`}):u(_,{className:`h-3.5 w-3.5`}),`Export all (`,String(z.length),`)`]}),z.length>0&&m.size<z.length&&u(Y,{variant:`ghost`,onClick:W,children:e(`eventsDebug.selectAll`,`Select all`)})]}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`A `,u(`code`,{children:`debug`}),` mark does not pin retention — this lists the marked tracks that still exist. A track whose media was evicted shows as missing media. Use`,` `,u(`strong`,{children:e(`eventsDebug.keep`,`Keep`)}),` to hold a selection against pruning while you investigate, and `,u(`strong`,{children:e(`eventsDebug.analyzed`,`Analyzed`)}),` to un-mark the ones you are finished with.`]}),u(to,{}),P.isError&&u(Me,{message:e(`eventsDebug.couldNotLoadTheMarked`,`Could not load the marked tracks.`)}),B&&!P.isError&&u(Me,{message:io}),d!==null&&u(Me,{message:d}),S!==null&&u(Me,{message:S}),P.data?.truncated===!0&&u(Me,{message:e(`eventsDebug.aCameraFilledThePer`,`A camera filled the per-camera cap — some marked tracks are not listed. Un-mark a few, or filter to one camera.`)}),(L.data?.vanished.length??0)>0&&r(`p`,{className:`text-xs text-foreground-subtle`,children:[String(L.data?.vanished.length),` marked track(s) were evicted between the list and the analysis.`]}),m.size>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[r(`span`,{className:`text-xs font-medium text-foreground`,children:[String(m.size),` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[u(`span`,{title:_i?void 0:`Track flags arrive with the next server update`,children:r(Y,{variant:`secondary`,onClick:()=>K(`keep`),disabled:!_i||J,children:[b===`keep`?u(M,{className:`h-3.5 w-3.5 animate-spin`}):u(V,{className:`h-3.5 w-3.5`}),` `,e(`eventsDebug.keep`,`Keep`)]})}),u(`span`,{title:_i?void 0:`Track flags arrive with the next server update`,children:r(Y,{onClick:()=>K(`analyzed`),disabled:!_i||J,children:[b===`analyzed`?u(M,{className:`h-3.5 w-3.5 animate-spin`}):u(N,{className:`h-3.5 w-3.5`}),` `,e(`eventsDebug.analyzed`,`Analyzed`)]})}),u(Y,{variant:`ghost`,onClick:G,disabled:J,children:u(I,{className:`h-3.5 w-3.5`})})]})]}),w.length>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-border bg-surface px-3 py-2`,children:[r(`span`,{className:`text-xs text-foreground`,children:[String(w.length),` track(s) marked analyzed and removed from this list.`]}),r(Y,{variant:`ghost`,onClick:q,disabled:J,children:[u(f,{className:`h-3.5 w-3.5`}),` Undo`]}),u(Y,{variant:`ghost`,onClick:()=>T([]),disabled:J,children:u(I,{className:`h-3.5 w-3.5`})})]}),P.isLoading?u(Te,{status:`pending`,pendingMessage:`Loading…`,testId:`debug-tracks-grid`}):z.length===0?u(Be,{icon:h,title:e(`eventsDebug.noTrackIsMarkedFor`,`No track is marked for debug`),description:e(`eventsDebug.markOneFromATrack`,`Mark one from a track's actions on the Feed to see it here.`)}):u(Te,{status:`ready`,testId:`debug-tracks-grid`,children:z.map(e=>{let t=R.get(e.trackId);return u(ii,{row:e,cameraName:A(e.deviceId),nowMs:e.lastSeen,selected:m.has(Ja(e.deviceId,e.trackId)),onToggleSelect:U,onOpenDetail:y,...t?.thumbnailProvenance===void 0?{}:{provenance:t.thumbnailProvenance},footer:u(so,{track:e,report:t,analyzing:L.isFetching})},Ja(e.deviceId,e.trackId))})}),v&&u(Ui,{row:v,cameraName:A(v.deviceId),deleteAvailable:ji,onClose:()=>y(null),onDeleted:()=>{y(null),P.refetch()},onFlagsChanged:e=>{e.debug||(y(null),P.refetch())}})]})}var lo=200,uo=3e4,fo=[];function po(e){let t=ee(),n=e.deviceIds.length>0,r=[...e.deviceIds].sort((e,t)=>e-t),{data:i,isLoading:a}=o({queryKey:[`events-feed`,r,e.since,e.until,e.minImportance??null,e.classFilter??null],enabled:n,staleTime:uo,refetchInterval:uo,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEventsBatch.query({deviceIds:r,since:e.since,until:e.until,limit:lo,...e.minImportance===void 0?{}:{minImportance:e.minImportance},...e.classFilter===void 0?{}:{classFilter:e.classFilter}})).map(e=>e.events.map(t=>({...t,deviceId:e.deviceId})))});return{rows:Kr(Gr(i??fo),`importance`),isLoading:n&&a}}n();var mo=[`events-feed`],ho=2e3;function go(n){let r=c(),i=n?.paused===!0,a=t(r);a.current=r;let o=t(i);o.current=i;let[s,u]=l(!1),f=e(()=>{a.current.invalidateQueries({queryKey:mo})},[]),p=t(void 0);p.current||=Rr({delayMs:ho,invalidate:()=>{o.current?u(!0):f()}}),d(()=>()=>p.current?.cancel(),[]),d(()=>{i||!s||(u(!1),f())},[i,s,f]);let m=e(()=>{u(!1),f()},[f]);return dt(me.PipelineAnalyticsDetectionEvent,()=>{p.current?.trigger()}),dt(me.PipelineAnalyticsTrackEnded,()=>{p.current?.trigger()}),{pending:s,refreshNow:m}}n();function _o({groups:e,selected:t,onChange:n,loading:a=!1}){let{t:o}=X(),[s,c]=l(!1),[d,f]=l(``),[p,m]=l(new Set),h=d.trim().toLowerCase(),g=e=>h.length===0||Ct(e,o).toLowerCase().includes(h),_=i(()=>e.map(e=>({macro:e.macro,subs:e.subs.filter(t=>g(t)||g(e.macro))})).filter(e=>g(e.macro)||e.subs.length>0),[e,h]),v=e=>m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),y=e=>{let r=new Set(t),i=t.has(e.macro.kind)&&e.subs.every(e=>t.has(e.kind)),a=[e.macro.kind,...e.subs.map(e=>e.kind)];if(i)for(let e of a)r.delete(e);else for(let e of a)r.add(e);n(r)},b=e=>{let r=new Set(t);r.has(e)?r.delete(e):r.add(e),n(r)},x=()=>n(new Set),S=t.size;return r(`div`,{className:`relative`,children:[r(`button`,{type:`button`,onClick:()=>c(e=>!e),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${S>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[u(E,{className:`h-3.5 w-3.5`}),S>0?o(`detectionIntelligence.eventKindFilter.kinds`,`Kinds ({{value1}})`,{value1:String(S)}):o(`detectionIntelligence.eventKindFilter.kinds2`,`Kinds`),u(q,{className:`h-3 w-3`})]}),s&&r(`div`,{className:`absolute z-20 mt-1 max-h-80 w-64 overflow-auto rounded-md border border-border bg-surface p-2 shadow-lg`,children:[r(`div`,{className:`mb-2 flex items-center gap-1 rounded border border-border px-1.5`,children:[u(F,{className:`h-3.5 w-3.5 text-foreground-subtle`}),u(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:o(`detectionIntelligence.eventKindFilter.searchKinds`,`Search kinds…`),className:`w-full bg-transparent py-1 text-xs outline-none`}),S>0&&u(`button`,{type:`button`,onClick:x,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:o(`detectionIntelligence.eventKindFilter.clear`,`Clear`)})]}),_.length===0&&u(`div`,{className:`px-1 py-2 text-[11px] text-foreground-subtle`,children:a?o(`detectionIntelligence.eventKindFilter.loadingKinds`,`Loading kinds…`):h.length>0?o(`detectionIntelligence.eventKindFilter.noKindMatchesThatSearch`,`No kind matches that search.`):o(`detectionIntelligence.eventKindFilter.theseCamerasAdvertiseNoEvent`,`These cameras advertise no event kinds.`)}),_.map(e=>{let n=pt(e.macro.iconId),i=p.has(e.macro.kind)||h.length>0,a=t.has(e.macro.kind);return r(`div`,{className:`mb-0.5`,children:[r(`div`,{className:`flex items-center gap-1`,children:[e.subs.length>0?u(`button`,{type:`button`,onClick:()=>v(e.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":o(`detectionIntelligence.eventKindFilter.expand`,`Expand`),children:u(i?q:A,{className:`h-3 w-3`})}):u(`span`,{className:`w-3`}),r(`label`,{className:`flex flex-1 cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[u(`input`,{type:`checkbox`,checked:a,onChange:()=>y(e),className:`accent-primary`}),u(n,{className:`h-3.5 w-3.5`,style:{color:e.macro.color}}),u(`span`,{className:`font-medium`,children:Ct(e.macro,o)})]})]}),i&&e.subs.map(e=>{let n=pt(e.iconId);return r(`label`,{className:`ml-5 flex cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[u(`input`,{type:`checkbox`,checked:t.has(e.kind),onChange:()=>b(e.kind),className:`accent-primary`}),u(n,{className:`h-3.5 w-3.5`,style:{color:e.color}}),u(`span`,{children:Ct(e,o)})]},e.kind)})]},e.macro.kind)})]})]})}function vo(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 yo(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var bo=new Set([`detection`,`package`]);function xo(e,t){return[...vo(e,t).values()].filter(e=>e.parentKind===null&&bo.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function So(e,t){let n=vo(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,yo(e,n))}return[...i.values()].map(e=>({macro:e,subs:[...r.get(e.kind)??[]].sort((e,t)=>e.label.localeCompare(t.label))})).sort((e,t)=>e.macro.label.localeCompare(t.macro.label))}n();function Co(){let[n,r]=l(!1),i=t(null),[a,o]=l(0),s=e(e=>{i.current!==e&&(i.current=e,o(e=>e+1))},[]);return d(()=>{let e=i.current;if(!e||typeof IntersectionObserver>`u`){r(!1);return}let t=new IntersectionObserver(e=>{let t=e[e.length-1];t&&r(!t.isIntersecting)},{rootMargin:`64px 0px 0px 0px`,threshold:0});return t.observe(e),()=>t.disconnect()},[a]),{ref:s,scrolledPast:n}}n();var wo=[`events-feed`],To=60,Eo=[{value:`importance`,label:`Importance`,icon:ie},{value:`time`,label:`Recent`,icon:H}];function Do(){let{t:e}=X(),t=c(),n=Je(),a=Qe(),[o,f]=l(In),[p,m]=l(new Set),[h,g]=l(new Set),[_,y]=l(0),[b,x]=l(`time`),[S,C]=l(new Set),[w,E]=l(null),[D,O]=l(()=>Date.now());d(()=>{let e=setInterval(()=>O(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:k,until:A}=i(()=>Xr({fromMs:o.fromMs,toMs:o.toMs},D),[o.fromMs,o.toMs,D]),j=Co(),{pending:N,refreshNow:P}=go({paused:w!==null||S.size>0||j.scrolledPast}),{data:F=[]}=gt({isCamera:!0,projection:`slim`}),L=i(()=>F.map(e=>e.id),[F]),{data:R,isLoading:z}=it({deviceIds:L},{enabled:L.length>0,staleTime:5*6e4}),ee=i(()=>So(R??[],p),[R,p]),B=Pi(),V=B.isPending,{rows:H,isLoading:U}=po({deviceIds:L,since:k,until:A,minImportance:_>0?_:void 0,classFilter:h.size===1?[...h][0]:void 0}),W=i(()=>{let e=new Map;for(let t of F??[])e.set(t.id,t.name);return e},[F]),G=e=>W.get(e)??`Camera #${String(e)}`,te=i(()=>Un(H).map(e=>({id:e,name:G(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[H,W]),K=i(()=>Kr(qr(H,{cameras:p,classes:h,minImportance:_}),b),[H,p,h,_,b]),q=$n(K,To,i(()=>JSON.stringify([[...p].sort((e,t)=>e-t),[...h].sort(),_,b,k,A]),[p,h,_,b,k,A])),ne=()=>{t.invalidateQueries({queryKey:wo})},re=()=>C(new Set);function J(e){C(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function ie(){if(S.size===0||!ji)return;let t=Yr(H,S),n=[...t.values()].reduce((e,t)=>e+t.length,0);n!==0&&(async()=>{await a({title:`Delete ${String(n)} track${n===1?``:`s`}`,message:`Delete ${String(n)} track${n===1?``:`s`} and every image and clip captured for ${n===1?`it`:`them`}? This cannot be undone.`,confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&ae(t)})()}function ae(t){let r=[...t];Promise.allSettled(r.map(([e,t])=>B.mutateAsync({deviceId:e,trackIds:t}))).then(t=>{ne();let i=[],a=new Set;if(t.forEach((e,t)=>{let n=r[t];if(!n)return;let[o,s]=n;if(e.status===`fulfilled`)for(let e of s)a.add(Jr(o,e));else i.push(o)}),C(e=>{let t=new Set(e);for(let e of a)t.delete(e);return t}),i.length>0){let t=i.map(e=>G(e)).join(`, `);n({title:e(`detectionIntelligence.eventsSection.someTracksWereNotDeleted`,`Some tracks were not deleted`),message:e(`detectionIntelligence.eventsSection.failedToDeleteTracksOn`,`Failed to delete tracks on: {{names}}. They remain selected — retry, or check the server logs.`,{names:t}),variant:`danger`})}})}let oe=K.length!==H.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[u(sr,{onChange:f}),u(ar,{cameras:te,selected:p,onChange:m}),u(_o,{groups:ee,selected:h,onChange:g,loading:z}),r(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[u(`span`,{children:e(`detectionIntelligence.eventsSection.minScore`,`Min score`)}),u(`input`,{type:`range`,min:0,max:1,step:.05,value:_,onChange:e=>y(Number(e.target.value)),className:`h-1 w-24 cursor-pointer accent-primary`,"aria-label":e(`detectionIntelligence.eventsSection.minimumImportance`,`Minimum importance`)}),u(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(_*100)})]}),u(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Eo.map(e=>{let t=e.icon;return r(`button`,{type:`button`,onClick:()=>x(e.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${b===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[u(t,{className:`h-3.5 w-3.5`}),` `,e.label]},e.value)})}),!U&&u(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:oe?e(`detectionIntelligence.eventsSection.ofEvents`,`{{value1}} of {{value2}} events`,{value1:String(K.length),value2:String(H.length)}):`${String(K.length)} event${K.length===1?``:`s`}`})]}),S.size>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[r(`span`,{className:`text-xs font-medium text-foreground`,children:[S.size,` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[u(`span`,{title:ji?void 0:`Track deletion arrives with the next server update`,children:r(Y,{variant:`secondary`,onClick:ie,disabled:!ji||V,children:[V?u(M,{className:`h-3.5 w-3.5 animate-spin`}):u(v,{className:`h-3.5 w-3.5`}),` `,e(`common.delete`,`Delete`)]})}),u(Y,{variant:`ghost`,onClick:re,disabled:V,children:u(I,{className:`h-3.5 w-3.5`})})]})]}),N&&u(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:u(`button`,{type:`button`,onClick:P,className:`rounded-full border border-primary/40 bg-surface px-3 py-1 text-[11px] font-medium text-primary shadow-sm hover:bg-primary/10`,children:e(`detectionIntelligence.eventsSection.newEventsRefresh`,`New events — refresh`)})}),U?u(Te,{status:`pending`,pendingMessage:`Loading events…`,testId:`events-grid`}):K.length===0?u(Be,{icon:T,title:oe?e(`detectionIntelligence.eventsSection.nothingMatchesTheFilter`,`Nothing matches the filter`):e(`detectionIntelligence.eventsSection.noKeyEventsInThis`,`No key events in this window`),description:oe?e(`detectionIntelligence.eventsSection.widenTheDateRangeClear`,`Widen the date range, clear cameras or kinds, or lower the min score.`):e(`detectionIntelligence.eventsSection.capturedTracksAppearHereWhen`,`Captured tracks appear here when the pipeline scores a key event.`)}):r(s,{children:[u(`div`,{ref:j.ref,"aria-hidden":!0,className:`h-0`}),u(Te,{status:`ready`,testId:`events-grid`,children:q.pageItems.map(e=>u(ii,{row:e,cameraName:G(e.deviceId),nowMs:D,selected:S.has(Jr(e.deviceId,e.trackId)),onToggleSelect:J,onOpenDetail:E},Jr(e.deviceId,e.trackId)))}),u(nr,{currentPage:q.page,totalItems:q.totalItems,pageSize:q.pageSize,onPageChange:q.setPage,itemNoun:`events`})]}),w&&u(Ui,{row:w,cameraName:G(w.deviceId),deleteAvailable:ji,onClose:()=>E(null),onDeleted:()=>{ne(),E(null)},onFlagsChanged:e=>{E(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug,favourited:e.favourited}:t)}})]})}var Oo=`/addon/training`;function ko(){let{t:e}=X(),t=Ft();return r(Fe,{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:[r(`div`,{className:`flex min-w-0 flex-1 items-start gap-2.5`,children:[u(K,{className:`mt-0.5 h-4 w-4 shrink-0 text-primary`,"aria-hidden":!0}),r(`div`,{className:`min-w-0 space-y-0.5`,children:[u(`p`,{className:`text-xs font-medium text-foreground`,children:e(`detectionIntelligence.retrainTabCallout.trainingFromThisFeed`,`Training from this feed`)}),u(`p`,{className:`${re} leading-relaxed`,children:e(`detectionIntelligence.retrainTabCallout.markATrackWithThe`,`Mark a track with the graduation-cap control on its card. On Training you correct frames, build collections, and start cloud fine-tunes.`)})]})]}),u(Y,{variant:`outline`,size:`sm`,className:`shrink-0 self-start sm:self-center`,onClick:()=>t(Oo),children:e(`detectionIntelligence.retrainTabCallout.openTraining`,`Open Training`)})]})}n();var Ao=50,jo=350,Mo=[{value:`loose`,label:`Loose`,title:`The search model's own floor`},{value:`balanced`,label:`Balanced`,title:`1.25× the search model's floor`},{value:`strict`,label:`Strict`,title:`1.5× the search model's floor`}];function No(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 Po({onActiveChange:e}){let{t}=X(),[n,a]=l(``),[o,s]=l(`loose`),[c,f]=l(null),[p,m]=l(null),[h,g]=l(null),_=xt(n,jo).trim(),v=_.length>0;d(()=>{e(v)},[v,e]);let[y,b]=l(()=>Date.now());d(()=>{let e=setInterval(()=>b(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:x=[]}=gt({isCamera:!0,projection:`slim`}),S=i(()=>{let e=new Map;for(let t of x)e.set(t.id,t.name);return e},[x]),C=e=>S.get(e)??`Camera #${String(e)}`,w=i(()=>x.map(e=>e.id),[x]),{data:T}=it({deviceIds:w},{enabled:w.length>0,staleTime:5*6e4}),E=i(()=>xo(T??[],new Set(p===null?[]:[p])),[T,p]);d(()=>{c!==null&&(E.some(e=>e.kind===c)||f(null))},[E,c]);let{data:D,isFetching:O,isError:k,error:A}=ut({text:_,strictness:o,limit:Ao,classFilter:c??void 0,deviceId:p??void 0},{enabled:v}),j=i(()=>[...D??[]].sort((e,t)=>t.score-e.score).map(e=>({...No(e),score:e.score})),[D]);function N(e){f(t=>t===e?null:e)}return r(`div`,{className:`space-y-3`,children:[r(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(`div`,{className:`relative min-w-[16rem] flex-1`,children:[u(F,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),u(`input`,{type:`text`,value:n,onChange:e=>a(e.target.value),placeholder:t(`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":t(`detectionIntelligence.semanticEventSearch.semanticEventSearch`,`Semantic event search`)}),n&&u(`button`,{type:`button`,onClick:()=>a(``),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":t(`detectionIntelligence.semanticEventSearch.clearSearch`,`Clear search`),children:u(I,{className:`h-3.5 w-3.5`})})]}),O&&v&&u(M,{className:`h-4 w-4 shrink-0 animate-spin text-foreground-subtle`})]}),r(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[u(`div`,{className:`flex items-center gap-1`,children:E.map(e=>u(`button`,{type:`button`,onClick:()=>N(e.kind),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${c===e.kind?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:Ct(e)},e.kind))}),r(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[u(`span`,{children:t(`detectionIntelligence.semanticEventSearch.camera`,`Camera`)}),u(ke,{value:p===null?``:String(p),onChange:e=>m(e.target.value===``?null:Number(e.target.value)),className:`h-7 text-xs`,"aria-label":t(`detectionIntelligence.semanticEventSearch.filterByCamera`,`Filter by camera`),options:[{value:``,label:t(`detectionIntelligence.semanticEventSearch.all`,`All`)},...x.map(e=>({value:String(e.id),label:e.name}))]})]}),r(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[u(`span`,{children:t(`detectionIntelligence.semanticEventSearch.match`,`Match`)}),u(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Mo.map(e=>u(`button`,{type:`button`,onClick:()=>s(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${o===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:e.title,children:e.label},e.value))})]}),v&&!O&&!k&&r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[j.length,` match`,j.length===1?``:`es`]})]})]}),v&&r(`div`,{className:`space-y-3`,children:[k&&r(`p`,{className:`py-4 text-xs text-danger`,children:[t(`detectionIntelligence.semanticEventSearch.searchFailed`,`Search failed:`),` `,A instanceof Error?A.message:t(`detectionIntelligence.semanticEventSearch.unknownError`,`unknown error`),`. Check that the CLIP embedding step is enabled.`]}),!k&&O&&j.length===0&&u(Te,{status:`pending`,pendingMessage:`Searching…`,testId:`semantic-events-grid`}),!k&&!O&&j.length===0&&u(Te,{status:`empty`,emptyMessage:t(`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&&u(Te,{status:`ready`,testId:`semantic-events-grid`,children:j.map(e=>u(ii,{row:e,cameraName:C(e.deviceId),nowMs:y,score:e.score,onOpenDetail:g},e.id))})]}),h&&u(Ui,{row:h,cameraName:C(h.deviceId),deleteAvailable:ji,onClose:()=>g(null),onDeleted:()=>g(null)})]})}n();function Fo(e,t){let n=Math.max(0,Math.round((e-t)/6e4));if(n<1)return`just now`;if(n<60)return`${String(n)}m`;let r=Math.floor(n/60);return`${String(r)}h ${String(n%60)}m`}function Io({row:e,cameraName:t,nowMs:n}){let{t:i}=X(),a=zt(e.keyFrameMediaId===void 0?void 0:Ht(e.keyFrameMediaId));return r(`div`,{className:`flex flex-col overflow-hidden rounded-md border border-border bg-surface`,children:[r(`div`,{className:`relative aspect-video overflow-hidden bg-surface-hover`,children:[a.src?u(`img`,{src:a.src,alt:i(`detectionIntelligence.stationarySection.parkedOn`,`Parked {{className}} on {{cameraName}}`,{className:e.className,cameraName:t}),className:`h-full w-full object-cover`}):u(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:u(oe,{className:`h-6 w-6`})}),u(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-medium capitalize text-white`,children:e.label??e.className})]}),r(`div`,{className:`flex flex-col gap-0.5 p-1.5`,children:[u(`span`,{className:`truncate text-[11px] text-foreground`,children:t}),r(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`parked `,Fo(n,e.becameStationaryAt)]})]})]})}function Lo(){let{t:e}=X(),[t,n]=l(!1),a=Date.now(),{data:o=[]}=gt({isCamera:!0,projection:`slim`}),s=i(()=>o.map(e=>e.id),[o]),c=i(()=>{let e=new Map;for(let t of o)e.set(t.id,t.name);return e},[o]),{rows:d,unreadableCount:f}=Rt(s);return d.length===0&&f===0?null:r(`div`,{className:`rounded-md border border-border bg-surface/40`,children:[r(`button`,{type:`button`,onClick:()=>n(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,children:[u(t?q:A,{className:`h-4 w-4 text-foreground-subtle`}),u(oe,{className:`h-4 w-4 text-foreground-subtle`}),u(`span`,{className:`text-sm font-semibold text-foreground`,children:e(`detectionIntelligence.stationarySection.stationary`,`Stationary`)}),u(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:d.length}),u(`span`,{className:`ml-2 text-[11px] text-foreground-subtle`,children:e(`detectionIntelligence.stationarySection.parkedObjectsKeptOutOf`,`Parked objects — kept out of the event feed`)}),f>0?r(`span`,{className:`ml-2 text-[11px] text-warning`,children:[f,` camera`,f===1?``:`s`,` could not be read`]}):null]}),t&&u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:d.map(e=>u(Io,{row:e,cameraName:c.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:a},e.id))})]})}n();function Ro(){let[e,t]=l(!1);return r(`section`,{className:`space-y-3`,children:[u(ko,{}),u(Po,{onActiveChange:t}),!e&&u(Lo,{}),!e&&u(Do,{})]})}function zo(){let{t:e}=X(),[t]=Pt();return t.get(`section`)===`retrain`?u(It,{to:`/addon/training`,replace:!0}):u(Lt,{sectionsOnly:!0,paramName:`section`,defaultSection:`feed`,sectionsLabel:`Events sections`,sections:[{id:`feed`,label:e(`events.feed`,`Feed`),content:u(Ro,{})},{id:`debug`,label:e(`events.debug`,`Debug`),content:u(co,{})}]})}function Bo(e){return e==null?null:e.cropUrl!==void 0&&e.cropUrl.length>0?e.cropUrl:e.base64!==void 0&&e.base64.length>0?`data:image/jpeg;base64,${e.base64}`:null}n();var Vo=[[`plateGallery`]];function Ho({plateIds:e,vehicles:t,onDone:n}){let{t:i}=X(),a=c(),o=ot(),s=_t(),[d,f]=l(``),[p,m]=l(!1),[h,g]=l(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||o.mutate({plateIds:[...e],vehicleId:t},{onSettled:()=>{a.invalidateQueries({queryKey:Vo}),b()}})}function S(){!e||!d.trim()||s.mutate({name:d.trim()},{onSuccess:e=>{e?.id&&x(e.id)},onError:()=>{a.invalidateQueries({queryKey:Vo}),b()}})}let C=o.isPending||s.isPending;return u(He,{open:_,onOpenChange:e=>!e&&b(),children:r(ye,{children:[r(_e,{children:[u(mt,{children:v>1?i(`detectionIntelligence.assignPlateDialog.assignPlatesToVehicle`,`Assign {{value1}} plates to vehicle`,{value1:String(v)}):i(`detectionIntelligence.assignPlateDialog.assignPlateToVehicle`,`Assign plate to vehicle`)}),u(Pe,{children:i(`detectionIntelligence.assignPlateDialog.selectAnExistingVehicleOr`,`Select an existing vehicle or create a new one.`)})]}),u(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:t.map(e=>r(`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:[u(`span`,{className:`font-medium`,children:e.name}),r(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` plates`]})]},e.id))}),p?u(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:u(Ze,{placeholder:i(`detectionIntelligence.assignPlateDialog.newVehicleName`,`New vehicle name…`),value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&S()},autoFocus:!0,className:`flex-1`})}):u(`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…`)}),r(ht,{children:[u(Y,{variant:`secondary`,onClick:b,disabled:C,children:i(`common.cancel`,`Cancel`)}),p?r(Y,{variant:`primary`,onClick:S,disabled:C||!d.trim(),children:[C&&u(M,{className:`h-3.5 w-3.5 animate-spin`}),i(`detectionIntelligence.assignPlateDialog.createAssign`,`Create & assign`)]}):r(Y,{variant:`primary`,onClick:()=>h&&x(h),disabled:C||!h,children:[C&&u(M,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,v>1?` ${String(v)}`:``]})]})]})})}n();var Uo=[[`plateGallery`]];function Wo(e){let[t,n]=l(null),[r,i]=l(null),[a,o]=l(!1);return d(()=>{if(n(null),i(null),o(!1),e===void 0)return;let t=!1,r=null;return(async()=>{try{let i=await Vt(Ht(e));if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||o(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),d(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>o(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function Go(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 Ko({label:e,value:t,mono:n}){return r(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[u(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),u(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono`:``}`,title:t,children:t})]})}function qo({box:e}){let{t}=X();return u(`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:u(`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 Jo({plate:e,cameraName:t,onClose:n,onAssign:a,onUnassign:o,onDelete:s,actionsPending:f}){let{t:p}=X(),m=c(),{data:h,isFetching:_}=$e({plateId:e?.plateId??``},{enabled:e!==null}),y=bt(),[b,x]=l(`frame`),[S,w]=l(!1),[T,E]=l(``),{frameSrc:D,naturalWidth:O,naturalHeight:k,failed:A}=Wo(e?.keyFrameMediaId);d(()=>{w(!1),E(``),x(`frame`)},[e?.plateId]);let j=i(()=>{let t=Go(h??[]);return t?t.url:Bo(e)},[h,e]),P=i(()=>!e?.plateBbox||O===null||k===null?null:lr(e.plateBbox,O,k),[e?.plateBbox,O,k]);if(e===null)return null;let F=e.keyFrameMediaId!==void 0&&!A,L=F&&b===`frame`,z=e.assigned?e.vehicleName??`Assigned`:e.recognizedVehicleId?`${e.vehicleName??`Recognized`} (suggested)`:`Unassigned`,ee=`${String(Math.round(e.score*100))}%${e.corrected?` · corrected`:``}`;function V(){e&&(E(e.text),w(!0))}function H(){if(!e)return;let t=T.trim().toUpperCase();if(!t||t===e.text){w(!1);return}y.mutate({plateId:e.plateId,text:t},{onSettled:()=>{m.invalidateQueries({queryKey:Uo}),w(!1)}})}return u(He,{open:!0,onOpenChange:e=>!e&&n(),children:r(ye,{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:[u(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:r(`div`,{className:`min-w-0`,children:[u(`div`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:e.text||p(`detectionIntelligence.plateDetailPanel.plateDetail`,`Plate detail`)}),u(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]})}),r(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[F&&r(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[r(`button`,{type:`button`,onClick:()=>x(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${b===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[u(B,{className:`h-3.5 w-3.5`}),` Full frame`]}),r(`button`,{type:`button`,onClick:()=>x(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${b===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[u(fe,{className:`h-3.5 w-3.5`}),` Crop`]})]}),L&&D?u(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:u(dr,{src:D,alt:p(`detectionIntelligence.plateDetailPanel.fullFrameWithDetectedPlate`,`Full frame with detected plate`),fit:`natural`,className:`w-full`,overlay:P?u(qo,{box:P}):void 0})}):j?r(`div`,{className:`relative aspect-[2/1] w-full overflow-hidden rounded-lg border border-border bg-background`,children:[u(dr,{src:j,alt:p(`detectionIntelligence.plateDetailPanel.detectedPlate`,`Detected plate`),className:`h-full w-full`}),_&&u(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:u(M,{className:`h-3.5 w-3.5 animate-spin`})})]}):r(`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:[u(R,{className:`h-8 w-8 text-warning/70`}),u(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:p(`detectionIntelligence.plateDetailPanel.noImage`,`No image`)}),u(`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.`)})]}),u(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-2`,children:r(`div`,{className:`flex items-center justify-between gap-3`,children:[u(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:p(`detectionIntelligence.plateDetailPanel.plateText`,`Plate text`)}),S?r(`div`,{className:`flex min-w-0 flex-1 items-center justify-end gap-1.5`,children:[u(Ze,{value:T,onChange:e=>E(e.target.value),onKeyDown:e=>{e.key===`Enter`&&H(),e.key===`Escape`&&w(!1)},className:`h-7 max-w-[10rem] text-right font-mono text-xs uppercase`,autoFocus:!0}),u(`button`,{type:`button`,onClick:H,disabled:y.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":p(`detectionIntelligence.plateDetailPanel.saveCorrectedText`,`Save corrected text`),children:y.isPending?u(M,{className:`h-3.5 w-3.5 animate-spin`}):u(N,{className:`h-3.5 w-3.5`})}),u(`button`,{type:`button`,onClick:()=>w(!1),className:`text-foreground-subtle hover:text-foreground`,"aria-label":p(`common.cancel`,`Cancel`),children:u(I,{className:`h-3.5 w-3.5`})})]}):r(`button`,{type:`button`,onClick:V,className:`group flex min-w-0 items-center gap-1.5`,title:p(`detectionIntelligence.plateDetailPanel.correctTheOcrReading`,`Correct the OCR reading`),children:[u(`span`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:e.text||`—`}),u(C,{className:`h-3 w-3 shrink-0 text-foreground-subtle group-hover:text-foreground`})]})]})}),r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[u(Ko,{label:p(`detectionIntelligence.plateDetailPanel.camera`,`Camera`),value:t}),u(Ko,{label:p(`detectionIntelligence.plateDetailPanel.captured`,`Captured`),value:Jn(e.timestamp)}),u(Ko,{label:p(`detectionIntelligence.plateDetailPanel.confidence`,`Confidence`),value:ee}),u(Ko,{label:p(`detectionIntelligence.plateDetailPanel.vehicle`,`Vehicle`),value:z}),u(Ko,{label:p(`detectionIntelligence.plateDetailPanel.track`,`Track`),value:e.trackId,mono:!0})]})]}),r(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[e.assigned?r(Y,{variant:`secondary`,onClick:()=>o(e.plateId),disabled:f,children:[u(ue,{className:`h-3.5 w-3.5`}),` Detach`]}):r(Y,{variant:`primary`,onClick:()=>a(e.plateId),disabled:f,children:[u(g,{className:`h-3.5 w-3.5`}),` Assign`]}),r(Y,{variant:`secondary`,onClick:()=>s(e.plateId),disabled:f,children:[u(v,{className:`h-3.5 w-3.5`}),` Delete`]})]})]})})}n();var Yo=[[`plateGallery`]],Xo=500,Zo=120;function Qo({plate:e,cameraName:t,nowMs:n,selected:i,onToggleSelect:a,onAssign:o,onOpenDetail:s}){let{t:l}=X(),d=c(),f=ve(),p=ft(),m=()=>{d.invalidateQueries({queryKey:Yo})},h=()=>s(e.plateId),_=Bo(e);return r(`div`,{className:`relative flex flex-col overflow-hidden rounded-md border bg-surface ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[r(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[_===null?r(`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:l(`detectionIntelligence.recentPlates.noCropImageThePlate`,`No crop image — the plate's crop media is missing. Safe to delete.`),children:[u(R,{className:`h-7 w-7 text-warning/70`}),u(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:l(`detectionIntelligence.recentPlates.noCrop`,`No crop`)})]}):u(`img`,{src:_,alt:l(`detectionIntelligence.recentPlates.plateFrom`,`Plate {{text}} from {{cameraName}}`,{text:e.text,cameraName:t}),onClick:h,className:`h-full w-full cursor-zoom-in object-cover`}),u(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),a(e.plateId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?l(`detectionIntelligence.recentPlates.deselect`,`Deselect`):l(`detectionIntelligence.recentPlates.select`,`Select`),children:i?u(ce,{className:`h-4 w-4 text-primary`}):u(y,{className:`h-4 w-4`})}),e.corrected&&r(`span`,{className:`absolute right-0 top-0 z-10 flex items-center gap-0.5 rounded-bl-md bg-primary/80 px-1 py-0.5 text-[8px] font-semibold uppercase tracking-wide text-white`,title:l(`detectionIntelligence.recentPlates.manuallyCorrected`,`Manually corrected`),children:[u(le,{className:`h-3 w-3`}),` Fixed`]})]}),r(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[u(`p`,{className:`truncate font-mono text-xs font-bold tracking-wide text-foreground`,title:e.text,children:e.text||`—`}),u(`p`,{className:`truncate text-[10px] text-foreground-subtle`,title:t,children:t}),u(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:Kn(e.timestamp,n)}),e.vehicleName&&u(`p`,{className:`truncate text-[10px] font-medium text-primary`,title:e.vehicleName,children:e.vehicleName})]}),r(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[e.assigned?u(`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":l(`detectionIntelligence.recentPlates.detachPlate`,`Detach plate`),title:l(`detectionIntelligence.recentPlates.detach`,`Detach`),children:f.isPending?u(M,{className:`h-4 w-4 animate-spin`}):u(ue,{className:`h-4 w-4`})}):u(`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":l(`detectionIntelligence.recentPlates.assignPlateToVehicle`,`Assign plate to vehicle`),title:l(`detectionIntelligence.recentPlates.assignToVehicle`,`Assign to vehicle`),children:u(g,{className:`h-4 w-4`})}),u(`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":l(`detectionIntelligence.recentPlates.deletePlate`,`Delete plate`),title:l(`detectionIntelligence.recentPlates.deletePlate`,`Delete plate`),children:p.isPending?u(M,{className:`h-4 w-4 animate-spin`}):u(v,{className:`h-4 w-4`})})]})]})}var $o=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Assigned`,value:`assigned`}];function es(e,t){return t===`unassigned`?e.filter(e=>!e.assigned):t===`assigned`?e.filter(e=>e.assigned):e}function ts(){let{t:e}=X(),t=c(),[n,a]=l(`all`),[o,d]=l(In),[f,p]=l(new Set),[m,h]=l(new Set),[_,y]=l(null),[b,x]=l(null),{data:S,isLoading:C}=Dt({limit:Xo,includeCrops:!1},{refetchInterval:3e4}),{data:w=[]}=nt(),{data:T}=gt({isCamera:!0,projection:`slim`}),E=ve(),D=Ot(),O=ft(),k=Date.now(),A=S??[],j=i(()=>{let e=new Map;for(let t of T??[])e.set(t.id,t.name);return e},[T]),N=e=>j.get(e)??`Camera #${String(e)}`,P=i(()=>Un(A).map(e=>({id:e,name:N(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[A,j]),F=i(()=>Hn(Vn(es(A,n),o),f),[A,n,o,f]),L=$n(F,Zo,i(()=>JSON.stringify([n,o.fromMs,o.toMs,[...f].sort((e,t)=>e-t)]),[n,o.fromMs,o.toMs,f])),z=i(()=>new Map(A.map(e=>[e.plateId,e])),[A]),ee=b===null?null:z.get(b)??null,B=()=>{t.invalidateQueries({queryKey:Yo})},V=()=>h(new Set);function H(e){h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}let U=[...m],W=D.isPending||O.isPending,G=E.isPending||O.isPending;function te(){U.length!==0&&D.mutate({plateIds:U},{onSettled:()=>{B(),V()}})}function K(){U.length!==0&&Promise.allSettled(U.map(e=>O.mutateAsync({plateId:e}))).then(()=>{B(),V()})}function q(e){x(null),y([e])}function ne(e){E.mutate({plateId:e},{onSettled:B}),x(null)}function re(e){O.mutate({plateId:e},{onSettled:B}),x(null)}let J=F.length!==A.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[u(`div`,{className:`flex items-center gap-1`,children:$o.map(e=>u(`button`,{type:`button`,onClick:()=>a(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${n===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.label},e.value))}),u(sr,{onChange:d}),u(ar,{cameras:P,selected:f,onChange:p}),!C&&u(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:J?e(`detectionIntelligence.recentPlates.ofPlates`,`{{value1}} of {{value2}} plates`,{value1:String(F.length),value2:String(A.length)}):`${String(F.length)} plate${F.length===1?``:`s`}`})]}),m.size>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[r(`span`,{className:`text-xs font-medium text-foreground`,children:[m.size,` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[r(Y,{variant:`primary`,onClick:()=>y(U),disabled:W,children:[u(g,{className:`h-3.5 w-3.5`}),` Assign`]}),r(Y,{variant:`secondary`,onClick:te,disabled:W,children:[D.isPending?u(M,{className:`h-3.5 w-3.5 animate-spin`}):u(ue,{className:`h-3.5 w-3.5`}),` `,e(`detectionIntelligence.recentPlates.detach`,`Detach`)]}),r(Y,{variant:`secondary`,onClick:K,disabled:W,children:[u(v,{className:`h-3.5 w-3.5`}),` Delete`]}),u(Y,{variant:`ghost`,onClick:V,disabled:W,children:u(I,{className:`h-3.5 w-3.5`})})]})]}),C?u(Te,{status:`pending`,pendingMessage:`Loading plates…`,testId:`plates-grid`}):F.length===0?u(Be,{icon:R,title:A.length>0?e(`detectionIntelligence.recentPlates.nothingMatchesTheFilter`,`Nothing matches the filter`):e(`detectionIntelligence.recentPlates.noPlatesRecognizedYet`,`No plates recognized yet`),description:A.length>0?e(`detectionIntelligence.recentPlates.widenTheDateRangeOr`,`Widen the date range or clear the camera filter.`):e(`detectionIntelligence.recentPlates.plateReadsAppearHereWhen`,`Plate reads appear here when the detection pipeline OCRs a vehicle.`)}):r(s,{children:[u(Te,{status:`ready`,testId:`plates-grid`,children:L.pageItems.map(e=>u(Qo,{plate:e,cameraName:N(e.deviceId),nowMs:k,selected:m.has(e.plateId),onToggleSelect:H,onAssign:e=>y([e]),onOpenDetail:x},e.plateId))}),u(nr,{currentPage:L.page,totalItems:L.totalItems,pageSize:L.pageSize,onPageChange:L.setPage,itemNoun:`plates`})]}),u(Jo,{plate:ee,cameraName:ee?N(ee.deviceId):``,onClose:()=>x(null),onAssign:q,onUnassign:ne,onDelete:re,actionsPending:G}),u(Ho,{plateIds:_,vehicles:w,onDone:()=>{y(null),V()}})]})}n();var ns=[[`plateGallery`]];function rs({vehicleId:e}){let{t}=X(),n=c(),{data:i,isLoading:a}=At({vehicleId:e}),o=kt();function s(t){o.mutate({vehicleId:e,sampleId:t.id},{onSettled:()=>{n.invalidateQueries({queryKey:ns})}})}return a?r(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[u(M,{className:`h-3.5 w-3.5 animate-spin`}),t(`detectionIntelligence.vehiclesList.loadingPlates`,`Loading plates…`)]}):!i||i.length===0?u(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:t(`detectionIntelligence.vehiclesList.noPlatesYet`,`No plates yet.`)}):u(`div`,{className:`mt-2 grid grid-cols-3 gap-2 sm:grid-cols-4 md:grid-cols-6`,children:i.map(e=>r(`div`,{className:`group relative overflow-hidden rounded-md border border-border bg-surface`,children:[r(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[e.base64?u(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:e.text,className:`h-full w-full object-cover`}):u(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:u(p,{className:`h-6 w-6`})}),u(`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:u(I,{className:`h-4 w-4 text-white`})})]}),u(`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 is(e){return[{key:`vehicle`,header:Mt.t(`detectionIntelligence.vehiclesList.vehicle`,`Vehicle`),sortValue:e=>e.name,render:e=>r(`span`,{className:`flex min-w-0 items-center gap-2`,children:[u(`span`,{className:`h-8 w-12 shrink-0 overflow-hidden rounded border border-border bg-surface-hover`,children:u(Gt,{mediaId:e.coverMediaId,base64:e.coverBase64,alt:e.name,className:`h-full w-full object-cover`,placeholder:u(`span`,{className:`flex h-full w-full items-center justify-center`,children:u(p,{className:`h-4 w-4 text-foreground-subtle`})})})}),u(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})]})},{key:`samples`,header:Mt.t(`detectionIntelligence.vehiclesList.plates`,`Plates`),align:`center`,nowrap:!0,sortValue:e=>e.sampleCount,render:e=>u(tt,{variant:`default`,className:`text-[10px]`,children:e.sampleCount})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:t=>r(`span`,{className:`flex items-center justify-end gap-1`,children:[u(Re,{variant:`ghost`,size:`sm`,icon:C,"aria-label":Mt.t(`detectionIntelligence.vehiclesList.edit`,`Edit {{name}}`,{name:t.name}),onClick:n=>{n.stopPropagation(),e.onEdit(t)}}),u(Re,{variant:`ghost`,size:`sm`,icon:v,"aria-label":Mt.t(`detectionIntelligence.vehiclesList.delete`,`Delete {{name}}`,{name:t.name}),onClick:n=>{n.stopPropagation(),e.onDelete(t)}})]})}]}function as({mode:e,vehicle:t,onClose:n}){let{t:i}=X(),a=c(),[o,s]=l(e===`edit`?t?.name??``:``),f=_t(),m=Ve();d(()=>{s(e===`edit`?t?.name??``:``)},[e,t?.id,t?.name]);let h=f.isPending||m.isPending,g=o.trim(),_=e===`edit`&&t!==null&&g===t.name,v=h||g.length===0||_;function y(){a.invalidateQueries({queryKey:ns})}function b(){if(!v){if(e===`new`){f.mutate({name:g},{onSuccess:()=>{y(),n()}});return}if(t===null){n();return}m.mutate({id:t.id,name:g},{onSuccess:()=>{y(),n()}})}}return u(jt,{open:!0,onClose:n,title:e===`new`?`Add vehicle`:`Edit ${t?.name??`vehicle`}`,icon:p,width:e===`edit`?`xl`:`lg`,testId:`vehicles-vehicle-form`,footer:r(Y,{variant:`primary`,size:`sm`,type:`button`,onClick:b,disabled:v,children:[h?u(M,{className:`h-3.5 w-3.5 animate-spin`}):null,e===`new`?i(`common.add`,`Add`):i(`common.save`,`Save`)]}),children:r(`div`,{className:`space-y-4`,children:[u(xe,{label:i(`detectionIntelligence.vehiclesList.name`,`Name`),required:!0,children:u(Ze,{value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b()},placeholder:i(`detectionIntelligence.vehiclesList.vehicleName`,`Vehicle name…`),autoFocus:!0})}),e===`edit`&&t!==null&&r(`div`,{children:[u(`p`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:i(`detectionIntelligence.vehiclesList.plateSamples`,`Plate samples`)}),u(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:i(`detectionIntelligence.vehiclesList.removeAPlateCropTo`,`Remove a plate crop to drop it from recognition for this vehicle. Assign new plates from Recent recognized plates.`)}),u(rs,{vehicleId:t.id})]})]})})}function os(){let{t:e}=X(),t=c(),n=Qe(),{data:a,isLoading:o}=nt(),s=lt(),{state:l,openNew:f,openEdit:m,close:h}=je(),g=a??[],_=Ne(g,{searchText:e=>[e.name]}),v=l.mode===`edit`?g.find(e=>e.id===l.id)??null:null;d(()=>{l.mode===`edit`&&!o&&v===null&&h()},[l.mode,o,v,h]);let y=i(()=>is({onEdit:e=>m(e.id),onDelete:r=>{(async()=>{await n({title:e(`detectionIntelligence.vehiclesList.deleteVehicle`,`Delete vehicle`),message:e(`detectionIntelligence.vehiclesList.deleteAndAllItsPlate`,`Delete {{name}} and all its plate samples? This cannot be undone.`,{name:r.name}),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&s.mutate({id:r.id},{onSettled:()=>{t.invalidateQueries({queryKey:ns}),l.mode===`edit`&&l.id===r.id&&h()}})})()}}),[n,h,s,l,m,t,e]);if(o)return r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[u(M,{className:`h-4 w-4 animate-spin`}),e(`detectionIntelligence.vehiclesList.loadingVehicles`,`Loading vehicles…`)]});let b=l.mode===`new`||l.mode===`edit`&&v!==null;return r(`div`,{className:`space-y-2`,children:[u(`div`,{className:`flex flex-wrap items-center gap-2`,children:r(Y,{variant:`primary`,size:`sm`,type:`button`,onClick:f,children:[u(S,{className:`h-3.5 w-3.5`}),e(`detectionIntelligence.vehiclesList.addVehicle`,`Add vehicle`)]})}),(g.length>0||_.active)&&u(Ie,{state:_.state,facets:_.facets,labels:{searchPlaceholder:`Search vehicles…`,searchLabel:`Search vehicles`,facetsLabel:`Filter`,clearLabel:`Clear`},onSearch:_.setSearch,onToggleFacet:_.toggleFacet,onClear:_.clear}),_.rows.length===0?u(Be,{icon:p,title:_.active?e(`detectionIntelligence.vehiclesList.nothingMatchesTheFilter`,`Nothing matches the filter`):e(`detectionIntelligence.vehiclesList.noVehiclesEnrolledYet`,`No vehicles enrolled yet`),description:_.active?e(`detectionIntelligence.vehiclesList.clearTheSearchOrTry`,`Clear the search or try another name.`):e(`detectionIntelligence.vehiclesList.addAVehicleThenAssign`,`Add a vehicle, then assign plate crops from Recent recognized plates.`)}):u(we,{columns:y,rows:_.rows,rowKey:e=>e.id,maxBodyHeight:We,mobileMode:`scroll`,emptyMessage:e(`detectionIntelligence.vehiclesList.noVehiclesEnrolledYet2`,`No vehicles enrolled yet.`),onRowClick:e=>m(e.id)}),b&&u(as,{mode:l.mode===`new`?`new`:`edit`,vehicle:v,onClose:h})]})}n();var ss=[[`plateGallery`]],cs=2e3;function ls(){let e=c(),n=t(e);n.current=e;let r=t(void 0);r.current||=Rr({delayMs:cs,invalidate:()=>{n.current.invalidateQueries({queryKey:ss})}}),d(()=>()=>r.current?.cancel(),[]),dt(me.PipelineAnalyticsPlateGalleryChanged,()=>{r.current?.trigger()})}function us(){let{t:e}=X();return ls(),r(`div`,{className:`space-y-3`,children:[u(Ge,{headingId:`library-vehicles`,title:e(`plates.vehicles`,`Vehicles`),icon:p,testId:`library-section-vehicles`,children:r(`div`,{className:`${m} space-y-3`,children:[u(`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.`)}),u(os,{})]})}),u(Ge,{headingId:`library-recent-plates`,title:e(`plates.recentRecognizedPlates`,`Recent recognized plates`),icon:ae,testId:`library-section-recent-plates`,children:r(`div`,{className:`${m} space-y-3`,children:[u(`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.`)}),u(ts,{})]})})]})}function ds(e){return e.states.length===0?3:e.latched?0:e.verdict===`diverged`?1:e.verdict===`unknown`?2:4}function fs(e){let t=[e.divergedAt,e.restoredAt].filter(e=>typeof e==`number`);return t.length===0?null:Math.max(...t)}function ps(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=ds(e.monitor)-ds(t.monitor);if(n!==0)return n;let r=fs(e.monitor)??-1,i=fs(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})}n();var ms={alarm:`danger`,ok:`success`,unknown:`default`},hs={alarm:`Alarm`,ok:`OK`,unknown:`Unknown`};function gs(e,t){let n=fs(e);return n===null?`—`:`${W(Math.max(0,t-n))} ago`}function _s(e){return P(e.monitor).tone}function vs(e){let t=Number(e);return Number.isFinite(t)&&t>0?t:null}function ys(){let{t:e}=X(),t=gt({isCamera:!0,projection:`slim`}),n=i(()=>(t.data??[]).map(e=>({deviceId:e.id,deviceName:e.name})).sort((e,t)=>e.deviceName.localeCompare(t.deviceName)),[t.data]),o=i(()=>n.map(e=>e.deviceId),[n]),s=Wt(o),c=i(()=>ps(n,s.results),[n,s.results]),f=Ne(c,{searchText:e=>[e.monitor.label,e.deviceName],facetValue:_s}),{state:p,openNew:m,openEdit:h,close:g}=je(),[_,v]=l(null);d(()=>{if(p.mode===`new`){v(e=>e??o[0]??null);return}v(null)},[p.mode,o]);let y=p.mode===`edit`?vs(p.id):null,b=y===null?``:n.find(e=>e.deviceId===y)?.deviceName??`#${y}`,x=Date.now(),C=[{key:`label`,header:e(`scenes.scene`,`Scene`),sortValue:e=>e.monitor.label,render:e=>u(`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=>_s(e),render:e=>{let t=P(e.monitor);return u(tt,{variant:ms[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=>u(`span`,{className:`text-xs text-foreground-muted`,children:L(e.monitor,x)})},{key:`coverage`,header:e(`scenes.variants`,`Variants`),notSortableReason:`Coverage is a summary string`,render:e=>u(`span`,{className:`text-xs text-foreground-muted`,children:z(e.monitor)})},{key:`transition`,header:e(`scenes.lastChange`,`Last change`),align:`right`,nowrap:!0,sortValue:e=>fs(e.monitor)??0,render:e=>u(`span`,{className:`text-xs tabular-nums text-foreground-muted`,children:gs(e.monitor,x)})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:t=>u(Y,{variant:`ghost`,onClick:()=>h(String(t.deviceId)),children:e(`scenes.open`,`Open`)})}];return r(`section`,{className:`space-y-3`,children:[r(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between sm:gap-4`,children:[u(`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.`)}),r(Y,{onClick:m,disabled:n.length===0,className:`shrink-0`,children:[u(S,{className:`mr-1 h-3.5 w-3.5`}),e(`scenes.newScene`,`New scene`)]})]}),s.unreachableCount>0?r(`p`,{className:`text-xs text-warning`,children:[s.unreachableCount,` camera`,s.unreachableCount===1?``:`s`,` could not be asked about scenes. Those cameras are missing from this list — this is not the same as having no scenes.`]}):null,(c.length>0||f.active)&&u(Ie,{state:f.state,facets:f.facets,labels:{searchPlaceholder:`Search scenes…`,searchLabel:`Search scenes`,facetsLabel:`State`,clearLabel:`Clear`},facetLabel:e=>hs[e]??e,onSearch:f.setSearch,onToggleFacet:f.toggleFacet,onClear:f.clear}),u(Fe,{variant:`flat`,className:`p-0`,children:u(we,{columns:C,rows:f.rows,rowKey:e=>`${e.deviceId}:${e.monitor.id}`,minWidthPx:880,bordered:!1,mobileMode:`scroll`,maxBodyHeight:We,emptyMessage:s.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`?r(jt,{open:!0,onClose:g,title:e(`scenes.whichCamera`,`Which camera?`),icon:te,width:`sm`,testId:`scenes-camera-picker`,footer:u(Y,{onClick:()=>{_!==null&&h(String(_))},disabled:_===null,children:e(`scenes.continue`,`Continue`)}),children:[u(`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.`)}),u(ke,{value:_===null?``:String(_),onChange:e=>v(Number(e.target.value)),"aria-label":e(`scenes.camera`,`Camera`),options:n.map(e=>({value:String(e.deviceId),label:e.deviceName}))})]}):null,y===null?null:r(jt,{open:!0,onClose:g,title:e(`scenes.scenes`,`Scenes — {{editingName}}`,{editingName:b}),icon:te,width:`lg`,testId:`scenes-editor`,children:[u(`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.`)}),u(a,{fallback:u(`p`,{className:`text-xs text-foreground-muted`,children:e(`scenes.loadingTheEditor`,`Loading the editor…`)}),children:u(wt,{deviceId:y})})]})]})}function bs(){let{t:e}=X(),t=Nt(`/library`,{t:e,isAdmin:!0})??{icon:de,title:e(`nav.library`,`Library`)};return u(Lt,{icon:t.icon,title:t.title,subtitle:e(`library.peopleVehiclesCapturedEventsAnd`,`People, vehicles, captured events and scenes — what detection has recognised.`),defaultSection:`people`,sectionsLabel:`${t.title} sections`,sections:[{id:`people`,label:e(`library.people`,`People`),content:u(Hr,{})},{id:`vehicles`,label:e(`library.vehicles`,`Vehicles`),content:u(us,{})},{id:`events`,label:e(`library.events`,`Events`),content:u(zo,{}),ownedParams:[`section`]},{id:`scenes`,label:e(`library.scenes`,`Scenes`),content:u(ys,{})}]})}export{bs as LibraryPage};
@@ -1,3 +0,0 @@
1
- import{Q as e,S as t,W as n,b as r,o as i,q as a,x as o,z as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{$t as c,Br as l,Fi as u,Fr as d,Hi as f,It as p,Mr as m,O as h,On as g,Pn as _,Qi as v,Qr as y,Rt as b,V as x,Vr as S,Vt as C,Xi as w,Zi as T,_i as E,cr as D,dt as O,er as k,fn as A,hr as j,ji as ee,k as M,ki as N,lr as P,nn as F,nr as I,pt as L,sn as R,ui as z,ut as B,wi as te,yi as ne,yn as V,z as H,zt as re}from"./player-overlays-Cda8wso6.js";import{t as ie}from"./boxes-Dx4USyB3.js";import{n as ae,r as oe,t as se}from"./speaker-Cl8DZGk_.js";import{t as ce}from"./user-round-BTaID248.js";import{Xt as le,er as ue,nr as U}from"./client-CMlUvfoK.js";import{$l as de,Aa as fe,An as pe,Bn as W,Da as me,Dn as G,Ea as he,En as ge,Gi as _e,Hi as ve,Ht as K,Kl as q,Ma as ye,Na as be,Nt as xe,Pt as Se,Ql as Ce,Ra as we,Ta as Te,Tn as Ee,Ui as De,W as Oe,Wi as ke,Zl as J,Zn as Ae,_a as je,an as Me,ar as Ne,d as Pe,ga as Fe,ja as Ie,jn as Le,kn as Re,ma as ze,on as Be,tr as Ve,va as He,wa as Ue,ya as We}from"./src-eoSUZcV-.js";import{t as Y}from"./useTranslation-Bc5yH9V9.js";import{J as X,Q as Ge,X as Ke,x as qe}from"./index-BgQGn3LX.js";import{t as Je}from"./AdminSectionedPage-C3VHg80L.js";import{a as Ye,n as Xe,r as Ze}from"./linked-devices-model-CCTQ_gka.js";e();var Qe={camera:te,hub:ae,container:ie,light:P,siren:F,switch:re,sensor:v,thermostat:C,climate:T,button:z,"event-emitter":B,update:oe,notifier:u,script:A,automation:L,lock:I,cover:ee,valve:S,humidifier:l,"water-heater":m,fan:d,"media-player":se,"alarm-panel":R,control:c,presence:ce,weather:y,vacuum:N,"lawn-mower":b,image:j,smoke:w};function Z({type:e,className:t}){return o(Qe[e]??z,{"aria-hidden":`true`,className:t??`h-3.5 w-3.5 shrink-0 text-foreground-subtle`})}function $e({online:e,deviceName:t}){return o(`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":`${t}: ${e?`online`:`offline`}`,title:e?`online`:`offline`})}function et({open:e,title:n,items:r,listState:i,lockedIds:c,lockedNote:l,suggestions:u=null,busy:d=!1,onConfirm:f,onClose:p}){let{t:m}=Y(),[h,g]=a([]);s(()=>{e||g([])},[e]);let _=new Map(r.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 o(Ee,{open:e,onOpenChange:e=>e?void 0:p(),children:t(G,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":n,children:[o(pe,{children:o(Le,{children:n})}),t(ge,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:[e&&u!==null&&v.length>0&&t(`section`,{"aria-label":u.heading,className:`flex flex-col gap-1`,children:[o(`h3`,{className:`text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:u.heading}),o(`div`,{className:`flex flex-wrap gap-1`,children:v.map(e=>o(`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&&o(Pe,{devices:r,listState:i,value:h,onChange:e=>g(e),noun:`device`,emptyLabel:m(`locations.addDialog.nonePicked`),showAll:!0,lockedIds:c,lockedNote:l,testId:`quick-add-picker`})]}),t(Re,{children:[o(W,{variant:`ghost`,onClick:p,children:m(`locations.addDialog.cancel`)}),o(W,{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}=Y(),a=n(()=>new Map(r.map(e=>[e.id,e])),[r]);return e===null?o(`p`,{className:`text-xs text-foreground-subtle`,children:i(`locations.links.noRoom`)}):o(`div`,{className:`flex flex-col gap-3`,"data-testid":`camera-links-section`,children:t.length===0?o(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`camera-links-empty`,children:i(`locations.links.noCameras`,{room:e})}):t.map(e=>o(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:n}){let{t:r}=Y(),s=i(),c=Ke(),[l,u]=a(!1),[d,f]=a(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}),g=ke(),_=m.kind===`present`?m:null,v=ve({deviceId:e.id,slotRef:_?.slot.slotRef??``},{enabled:l&&_!==null}),y=_===null?[]:Xe(_.slot,_.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 t=n.get(e);return{id:e,name:t?.name??`#${String(e)}`,...t===void 0?{}:{type:t.type,location:t.location}}}),w=[...x,...C],T=(v.data?.candidates??[]).filter(e=>e.suggested).map(e=>e.deviceId),E=async t=>{if(_!==null){f(null);try{await g.mutateAsync({deviceId:e.id,slotRef:_.slot.slotRef,value:Ye(_.value,t)}),await p.refetch(),await s.invalidateQueries({queryKey:[[`deviceManager`]]}),u(!1)}catch(e){f(e instanceof Error?e.message:String(e))}}},O=[{key:`device`,header:r(`locations.columns.device`),notSortableReason:r(`locations.columns.noSort`),render:e=>{let i=n.get(e.deviceId),a=e.name??i?.name??`#${String(e.deviceId)}`;return t(`span`,{className:`flex items-center gap-1.5`,children:[i!==void 0&&o(Z,{type:i.type}),o(X,{to:`/devices/${String(e.deviceId)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:a}),e.implied&&o(`span`,{className:`text-[10px] text-foreground-subtle`,children:r(`locations.links.implied`)})]})}},{key:`type`,header:r(`locations.columns.type`),notSortableReason:r(`locations.columns.noSort`),render:e=>o(`span`,{className:`text-xs text-foreground-muted`,children:n.get(e.deviceId)?.type??`—`})},{key:`status`,header:r(`locations.columns.status`),notSortableReason:r(`locations.columns.noSort`),render:e=>{let r=n.get(e.deviceId);return r===void 0?o(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):t(`span`,{className:`flex items-center gap-1.5`,children:[o($e,{online:r.online,deviceName:r.name}),o(`span`,{className:`text-xs text-foreground-muted`,children:r.online?`online`:`offline`})]})}}];return t(`section`,{className:`min-w-0 ${h}`,"data-testid":`camera-links-${String(e.id)}`,children:[t(`header`,{className:`${M} flex min-h-9 items-center gap-1.5`,children:[o(Z,{type:e.type}),o(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:e.name}),t(W,{variant:`ghost`,size:`sm`,onClick:()=>c(qe(e.id)),children:[o(D,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),r(`locations.links.edit`)]}),o(W,{variant:`outline`,size:`sm`,disabled:_===null,onClick:()=>u(!0),"aria-label":r(`locations.links.addNamed`,{camera:e.name}),children:r(`locations.room.add`)})]}),m.kind===`pending`&&o(`p`,{role:`status`,className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:r(`locations.links.loading`)}),m.kind===`unknown`&&o(`p`,{role:`alert`,className:`px-3 py-3 text-xs text-warning sm:px-4`,children:r(`locations.links.unreadable`,{reason:m.reason})}),m.kind===`absent`&&o(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:r(`locations.links.unsupported`)}),d!==null&&o(`p`,{role:`alert`,className:`px-3 pt-2 text-xs text-danger break-words sm:px-4`,children:d}),_!==null&&(y.length===0?o(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:r(`locations.links.none`)}):o(K,{columns:O,rows:y,rowKey:e=>String(e.deviceId),bordered:!1,minWidthPx:360,mobileMode:`scroll`})),o(et,{open:l,title:r(`locations.links.pickTitle`,{camera:e.name}),items:w,listState:v.status===`error`?`failed`:v.data===void 0?`pending`:`answered`,lockedIds:b,lockedNote:r(`locations.links.alreadyLinked`),suggestions:e.location===null?null:{heading:r(`locations.links.suggested`,{room:e.location}),ids:T},busy:g.isPending,onConfirm:e=>void E(e),onClose:()=>u(!1)})]})}e();function it({name:e,description:n,busy:r,onSave:i}){let{t:c}=Y(),[l,u]=a(n??``);return s(()=>{u(n??``)},[n]),t(`div`,{className:`border-t border-border px-3 py-2 sm:px-4`,children:[o(Be,{htmlFor:`location-description-${e}`,className:`block`,children:c(`locations.locationDescriptionField.whatIsThere`,`What is there`)}),o(`textarea`,{id:`location-description-${e}`,value:l,onChange:e=>u(e.target.value),onBlur:()=>{let e=l.trim();e!==(n??``)&&i(e.length===0?null:e)},disabled:r,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`}),o(`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 Q=` none`;function ot({name:e,zones:n,zoneKey:r,busy:i,onChange:a}){let{t:s}=Y();if(n.length===0)return null;let c=[{value:Q,label:s(`locations.locationZoneField.none`,`— none —`)},...n.map(e=>({value:e.zoneKey,label:e.label}))];return t(`div`,{className:`flex items-center gap-2 border-t border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:[o(Be,{htmlFor:`location-zone-${e}`,children:s(`locations.locationZoneField.zone`,`Zone`)}),o(q,{id:`location-zone-${e}`,value:r??Q,disabled:i,onChange:e=>{let t=e.target.value;if(t===Q){a(null);return}let r=n.find(e=>e.zoneKey===t);r!==void 0&&a(r.label)},options:c})]})}function st(e,t){return e.find(e=>e.locationKeys.includes(t))?.zoneKey??null}function ct({name:e,icon:t,busy:n,onPick:r}){return o(de,{value:t,onPick:r,fallbackGlyph:k,clearGlyph:f,labels:{trigger:`Change the icon of ${e}`,panel:`Icon for ${e}`,searchPlaceholder:`Search icons`,clear:`No icon`,noMatches:`No icon matches that`},disabled:n})}function lt(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0?null:U(n.icon)??`map-pin`}function $(e){if(e==null)return null;let t=e.trim();return t.length===0?null:t.toLowerCase()}function ut(e,t){let n=$(t);return n===null?[]:e.filter(e=>$(e.location)===n)}function dt(e,t){let n=ut(e,t),r=new Set(n.map(e=>e.id));return n.filter(e=>e.parentDeviceId===null||!r.has(e.parentDeviceId))}function ft(e,t){let n=$(e.location);return n===null||new Set(t.map(e=>$(e))).has(n)?null:e.location?.trim()??null}function pt(e,t){let n=$(e.location);return n!==null&&t.has(n)}function mt(e,t){let n=new Set(t.map(e=>$(e))),r=new Set(e.filter(e=>pt(e,n)).map(e=>e.id));return e.filter(e=>!(pt(e,n)||e.parentDeviceId!==null&&r.has(e.parentDeviceId)))}function ht(e,t){return mt(e,t).filter(e=>e.parentDeviceId===null)}function gt(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 _t(e,t){return gt(e,t).length}function vt(e,t){return e.filter(e=>!e.isCamera&&e.parentDeviceId===t)}function yt(e,t){return t.map(t=>({name:t,members:dt(e,t)}))}function bt(e){return`${e.kind}:${String(e.device.id)}`}function xt(e,t,n){return e.flatMap(e=>{let r=vt(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 St({name:e,members:i,devices:s,busy:c,icon:l,description:u,onRename:d,onDelete:f,onRebuildLinks:m,onAddDevices:g,onPickIcon:v,onSaveDescription:y,zones:b,zoneKey:x,onChangeZone:S}){let{t:C}=Y(),[w,T]=a(!1),[E,D]=a(e),k=xe(i,n(()=>({searchText:e=>[e.name,...vt(s,e.id).map(e=>e.name)],facetValue:e=>e.type}),[s])),[A,j]=a(()=>new Set),ee=e=>j(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),N=n(()=>xt(k.rows,s,A),[k.rows,s,A]),P=[{key:`name`,header:C(`locations.columns.device`),notSortableReason:C(`locations.columns.noSort`),render:e=>e.kind===`member`?o(Ct,{row:e,onToggle:()=>ee(e.device.id)}):o(wt,{row:e})},{key:`type`,header:C(`locations.columns.type`),notSortableReason:C(`locations.columns.noSort`),render:e=>o(`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=>t(`span`,{className:`flex items-center gap-1.5`,children:[o($e,{online:e.device.online,deviceName:e.device.name}),o(`span`,{className:`text-xs text-foreground-muted`,children:e.device.online?`online`:`offline`})]})}],F=()=>{D(e),T(!1)},I=async()=>{let t=E.trim();if(t.length===0||t===e){F();return}await d(t),T(!1)},L=[{id:`rename`,label:C(`locations.locationCard.rename`,`Rename`),icon:_,disabled:c,onClick:()=>{D(e),T(!0)}},{id:`rebuild-links`,label:C(`locations.locationCard.rebuildLinkedDevices`,`Rebuild linked devices`),icon:V,separatorBefore:!0,disabled:c,onClick:()=>void m()},{id:`delete`,label:C(`common.delete`,`Delete`),icon:p,danger:!0,separatorBefore:!0,disabled:c,onClick:()=>void f()}];return t(`section`,{className:`min-w-0 ${h}`,children:[t(`header`,{className:`${M} flex min-h-9 items-center gap-1.5`,children:[o(ct,{name:e,icon:l,busy:c,onPick:v}),w?t(r,{children:[o(J,{value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`&&I(),e.key===`Escape`&&F()},"aria-label":C(`locations.locationCard.rename2`,`Rename {{name}}`,{name:e}),className:`min-w-0 flex-1`,autoFocus:!0}),o(W,{type:`button`,size:`sm`,onClick:()=>void I(),children:C(`common.save`,`Save`)}),o(Ce,{type:`button`,variant:`ghost`,icon:O,onClick:F,"aria-label":C(`locations.locationCard.cancelRename`,`Cancel rename`)})]}):t(r,{children:[o(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:e}),o(W,{type:`button`,variant:`outline`,size:`sm`,disabled:c,onClick:g,"aria-label":C(`locations.room.addTo`,{room:e}),children:C(`locations.room.add`)}),o(Oe,{items:L,title:C(`locations.locationCard.actionsFor`,`Actions for {{name}}`,{name:e}),triggerClassName:`p-1`})]})]}),o(ot,{name:e,zones:b,zoneKey:x,busy:c,onChange:S}),o(it,{name:e,description:u,busy:c,onSave:y}),i.length>0&&o(`div`,{className:`border-b border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:o(Se,{state:k.state,facets:k.facets,labels:{searchPlaceholder:C(`locations.filter.searchPlaceholder`),searchLabel:C(`locations.room.searchLabel`,{room:e}),facetsLabel:C(`locations.filter.typesLabel`),clearLabel:C(`locations.filter.clear`)},onSearch:k.setSearch,onToggleFacet:k.toggleFacet,onClear:k.clear})}),i.length===0?o(`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.`)}):o(K,{columns:P,rows:N,rowKey:bt,bordered:!1,minWidthPx:360,mobileMode:`scroll`,emptyMessage:C(`locations.filter.noMatch`)})]})}function Ct({row:e,onToggle:n}){let{device:r,accessories:i,open:a}=e,s=a?ne:E;return t(`span`,{className:`flex items-center gap-1.5`,children:[i.length>0?t(W,{type:`button`,variant:`ghost`,onClick:n,"aria-expanded":a,"aria-label":`${a?`Collapse`:`Expand`} ${String(i.length)} companion device(s) of ${r.name}`,className:`h-auto shrink-0 gap-0.5 p-0.5 text-foreground-subtle hover:text-foreground`,children:[o(s,{className:`h-3 w-3`}),o(`span`,{className:`text-[10px] tabular-nums`,children:i.length})]}):o(`span`,{"aria-hidden":`true`,className:`w-[1.35rem] shrink-0`}),o(Z,{type:r.type}),o(X,{to:`/devices/${String(r.id)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:r.name})]})}function wt({row:e}){let{device:n}=e;return t(`span`,{className:`flex items-center gap-1.5 pl-6`,children:[o(`span`,{"aria-hidden":`true`,className:`text-[10px] text-foreground-subtle`,children:`└`}),o(Z,{type:n.type,className:`h-3 w-3 shrink-0 text-foreground-subtle`}),o(X,{to:`/devices/${String(n.id)}`,className:`min-w-0 truncate text-xs text-foreground-muted hover:underline`,children:n.name})]})}e();function Tt({zones:e,busy:t,onRename:n,onDelete:r,onPickIcon:i}){let{t:s}=Y(),[c,l]=a(null),[u,d]=a(``),f=async e=>{let t=u.trim();l(null),!(t.length===0||t===e)&&await n(e,t)};return o(K,{columns:[{key:`icon`,header:s(`locations.siteZonesPanel.icon`,`Icon`),width:`w-12`,notSortableReason:`An icon has no order`,render:e=>o(ct,{name:e.label,icon:e.icon,busy:t,onPick:t=>i(e.label,t)})},{key:`name`,header:s(`locations.siteZonesPanel.zone`,`Zone`),sortValue:e=>e.label.toLowerCase(),render:e=>c===e.label?o(J,{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":s(`locations.siteZonesPanel.rename`,`Rename {{label}}`,{label:e.label}),autoFocus:!0}):o(W,{type:`button`,variant:`ghost`,size:`sm`,className:`px-0`,onClick:()=>{d(e.label),l(e.label)},disabled:t,title:s(`locations.siteZonesPanel.renameTheZone`,`Rename the zone`),children:e.label})},{key:`rooms`,header:s(`locations.siteZonesPanel.rooms`,`Rooms`),align:`right`,sortValue:e=>e.locationKeys.length,render:e=>o(`span`,{className:`tabular-nums text-foreground-subtle`,children:e.locationKeys.length===0?`empty`:`${String(e.locationKeys.length)} ${e.locationKeys.length===1?`room`:`rooms`}`})},{key:`actions`,header:s(`locations.siteZonesPanel.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order`,render:e=>o(W,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void r(e.label),disabled:t,"aria-label":s(`locations.siteZonesPanel.delete`,`Delete {{label}}`,{label:e.label}),title:s(`locations.siteZonesPanel.deleteTheZoneTheRooms`,`Delete the zone — the rooms in it are kept`),children:o(p,{className:`h-3.5 w-3.5`})})}],rows:e,rowKey:e=>e.zoneKey,mobileMode:`scroll`,emptyMessage:s(`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 Et({busy:e,onCreate:n}){let{t:r}=Y(),[i,s]=a(!1),[c,l]=a(``),u=()=>{l(``),s(!1)},d=async()=>{let e=c.trim();e.length!==0&&(await n(e),u())};return i?t(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),d()},children:[o(J,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&u()},placeholder:r(`locations.newLocationButton.ingressoSaloneCucina`,`Ingresso, Salone, Cucina…`),"aria-label":r(`locations.newLocationButton.newLocationName`,`New location name`),className:`min-w-[12rem] flex-1`,autoFocus:!0}),t(W,{size:`sm`,type:`submit`,disabled:c.trim().length===0||e,children:[o(g,{className:`h-3.5 w-3.5`}),r(`common.add`,`Add`)]}),o(W,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":r(`locations.newLocationButton.cancelNewLocation`,`Cancel new location`),children:o(O,{className:`h-3.5 w-3.5`})})]}):t(W,{size:`sm`,type:`button`,onClick:()=>s(!0),"data-testid":`new-location-button`,children:[o(g,{className:`h-3.5 w-3.5`}),r(`locations.newLocationButton.newLocation`,`New location`)]})}e();function Dt({busy:e,onCreate:n}){let{t:r}=Y(),[i,s]=a(!1),[c,l]=a(``),u=()=>{l(``),s(!1)},d=async()=>{let e=c.trim();e.length!==0&&(await n(e),u())};return i?t(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),d()},children:[o(J,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&u()},placeholder:r(`locations.newZoneButton.zonaGiornoZonaNotte`,`Zona giorno, Zona notte…`),"aria-label":r(`locations.newZoneButton.newZoneName`,`New zone name`),className:`min-w-[12rem] flex-1`,autoFocus:!0}),t(W,{size:`sm`,type:`submit`,disabled:c.trim().length===0||e,children:[o(g,{className:`h-3.5 w-3.5`}),r(`common.add`,`Add`)]}),o(W,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":r(`locations.newZoneButton.cancelNewZone`,`Cancel new zone`),children:o(O,{className:`h-3.5 w-3.5`})})]}):t(W,{size:`sm`,type:`button`,onClick:()=>s(!0),"data-testid":`new-zone-button`,children:[o(g,{className:`h-3.5 w-3.5`}),r(`locations.newZoneButton.newZone`,`New zone`)]})}e();function Ot(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 kt({rooms:e,unassignedCount:t,value:r,unassignedValue:i,onChange:a}){let{t:s}=Y(),c=n(()=>Ot(e,t,i,s(`locations.roomPicker.unassigned`)),[e,t,i,s]);return o(`div`,{className:`max-w-sm`,"data-testid":`room-select`,children:o(Ve,{mode:`single`,singleDisplay:`field`,label:s(`locations.roomPicker.label`),placeholder:s(`locations.roomPicker.placeholder`),options:c,value:r,onChange:a,searchable:!0,testId:`room-select-control`,optionTestIdPrefix:`room-option`})})}e();var At={searchText:e=>[e.name],facetValue:e=>e.type};function jt({rows:e,fleet:r,locations:i,busy:s,emptyMessage:c,onAssign:l}){let{t:u}=Y(),[d,f]=a([]),[p,m]=a(``),h=xe(e,At),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 t=new Map;for(let n of e)t.set(n.id,_t(r,n.id));return t},[e,r]),S=v.reduce((e,t)=>e+(b.get(t)??0),0),C=e=>f(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),w=()=>f(y?[]:_),T=()=>{p.length===0||v.length===0||(l(v,p),f([]),m(``))},E=i.map(e=>({value:e,label:e})),D=[{key:`select`,width:`w-8`,headerRender:()=>o(Me,{checked:y,onChange:w,"aria-label":y?u(`locations.unassignedTable.clearSelection`,`Clear selection`):u(`locations.unassignedTable.selectAllUnassignedDevices`,`Select all unassigned devices`)}),render:e=>o(Me,{checked:v.includes(e.id),onChange:()=>C(e.id),"aria-label":u(`locations.unassignedTable.select`,`Select {{name}}`,{name:e.name})})},{key:`name`,header:u(`locations.unassignedTable.device`,`Device`),sortValue:e=>e.name.toLowerCase(),render:e=>{let n=ft(e,i);return t(`span`,{className:`flex items-center gap-1.5`,children:[o(Z,{type:e.type}),o(X,{to:`/devices/${String(e.id)}`,className:`truncate text-xs text-foreground hover:underline`,children:e.name}),n!==null&&t(Ne,{variant:`warning`,children:[`unknown room “`,n,`”`]})]})}},{key:`type`,header:u(`locations.unassignedTable.type`,`Type`),sortValue:e=>e.type,render:e=>o(`span`,{className:`text-xs text-foreground-muted`,children:e.type})},{key:`status`,header:u(`locations.unassignedTable.status`,`Status`),sortValue:e=>+!!e.online,render:e=>t(`span`,{className:`flex items-center gap-1.5`,children:[o($e,{online:e.online,deviceName:e.name}),o(`span`,{className:`text-xs text-foreground-muted`,children:e.online?`online`:`offline`})]})},{key:`followers`,header:u(`locations.unassignedTable.accessoriesInTow`,`Accessories in tow`),align:`right`,sortValue:e=>b.get(e.id)??0,render:e=>o(`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=>o(q,{"aria-label":u(`locations.unassignedTable.locationFor`,`Location for {{name}}`,{name:e.name}),value:``,disabled:s||i.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 t(`section`,{className:`space-y-2`,children:[t(`header`,{className:`flex flex-wrap items-baseline gap-2`,children:[o(`h2`,{className:x,children:u(`locations.unassignedTable.notInARoom`,`Not in a room`)}),o(`p`,{className:H,children:u(`locations.unassignedTable.topLevelDevicesOnlyAccessories`,`Top-level devices only — accessories move with their parent.`)})]}),e.length>0&&o(Se,{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&&t(`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:[t(`span`,{className:`text-xs text-foreground`,children:[v.length,` selected`,S>0&&` · ${String(S)} accessories in tow`]}),o(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]}),o(W,{type:`button`,size:`sm`,onClick:T,disabled:s||p.length===0,children:u(`locations.unassignedTable.assign`,`Assign`)}),o(W,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>f([]),children:u(`locations.unassignedTable.clear`,`Clear`)})]}),o(K,{columns:D,rows:g,rowKey:e=>e.id,minWidthPx:720,mobileMode:`scroll`,emptyMessage:h.active?u(`locations.filter.noMatch`):c})]})}function Mt(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 Nt(e,t){let n=t.map(Mt),r=[];for(let i of t)i.isCamera&&i.location===e&&r.push({deviceId:i.id,name:i.name,ids:le({selfId:i.id,selfLocation:i.location,candidates:n})});return{entries:r}}var Pt=`device-manager:linked-devices`;function Ft(e){return{deviceId:e.deviceId,slotRef:Pt,value:{slot:`linked-devices`,deviceIds:[...e.ids]}}}e();var It=`__unassigned__`;function Lt(){let{t:e}=Y(),r=i(),s=Ae(),{data:c,isLoading:l}=He(),{data:u}=je(),{data:d}=Fe(),{data:f}=We(),{data:p,isLoading:m}=ze({projection:`slim`}),h=()=>{r.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]}),r.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),r.invalidateQueries({queryKey:[[`deviceManager`,`listLocationIcons`]]}),r.invalidateQueries({queryKey:[[`deviceManager`,`listLocationDescriptions`]]}),r.invalidateQueries({queryKey:[[`deviceManager`,`listSiteZones`]]})},g=_e({onSuccess:h}),_=Ue({onSuccess:h}),v=fe({onSuccess:h}),y=he({onSuccess:h}),b=ye({onSuccess:h}),x=Ie({onSuccess:h}),S=we({onSuccess:h}),C=Te({onSuccess:h}),w=me({onSuccess:h}),T=be({onSuccess:h}),E=ke(),D=n(()=>(p??[]).map(e=>({id:e.id,name:e.name,location:e.location??null,type:String(e.type),isCamera:e.isCamera,parentDeviceId:e.parentDeviceId,online:e.online,role:e.role??null,stableId:e.stableId,primaryChildEntityId:e.primaryChildEntityId??null})),[p]),O=c??[],A=n(()=>yt(D,O),[D,O]),[j,ee]=Ge(),M=j.get(`tab`),N=M===`zones`||M===`camera-links`?M:`locations`,P=j.get(`room`),F=n(()=>ht(D,O),[D,O]),I=P===It,L=I?null:P!==null&&A.some(e=>e.name===P)?P:A[0]?.name??null,R=L===null?null:A.find(e=>e.name===L)??null,z=I?It:L??`__unassigned__`,B=L??A[0]?.name??null,te=n(()=>A.map(e=>({name:e.name,count:e.members.length})),[A]),ne=e=>{ee(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=Nt(t,D);if(n.entries.length===0){await s({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(e=>`• ${e.name}: ${String(e.ids.length)} device(s)`).join(`
2
- `);if(!await s({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(Ft(e))}catch(t){i.push(`• ${e.name}: ${t instanceof Error?t.message:String(t)}`)}h(),i.length>0&&await s({title:e(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:e(`locations.notRebuilt`,`Not rebuilt: {{value1}}`,{value1:i.join(`
3
- `)}),confirmLabel:`OK`})},oe=async(t,n)=>{let r=n>0?` ${String(n)} device(s) will become unassigned.`:``;await s({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})},se=async t=>{await s({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})},ce=async(e,t)=>{await b.mutateAsync({location:e,icon:t})},le=async(e,t)=>{await x.mutateAsync({location:e,description:t})},U=f??[],de=async(e,t)=>{await T.mutateAsync({location:e,zone:t})},pe=(e,t)=>{for(let n of e)v.mutate({deviceId:n,location:t})},[W,G]=a(null),ge=n(()=>D.filter(e=>e.parentDeviceId===null).map(e=>({id:e.id,name:e.name,type:e.type,location:e.location})),[D]),ve=o(kt,{rooms:te,...N===`locations`?{unassignedCount:F.length}:{},value:N===`locations`?z:B??``,unassignedValue:It,onChange:ne}),K=t(`div`,{className:`flex flex-col gap-3`,"data-testid":`locations-section`,children:[V&&o(`p`,{className:`text-xs text-foreground-subtle`,children:e(`locations.loadingLocationsAndDevices`,`Loading locations and devices…`)}),ve,I||R===null?o(jt,{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:pe}):o(St,{name:R.name,members:R.members,devices:D,busy:H,icon:lt(u,ue(R.name)),onPickIcon:e=>ce(R.name,e),description:at(d,ue(R.name)),onSaveDescription:e=>le(R.name,e),zones:U,zoneKey:st(U,ue(R.name)),onChangeZone:e=>de(R.name,e),onRename:e=>ie(R.name,e),onDelete:()=>oe(R.name,ut(D,R.name).length),onRebuildLinks:()=>ae(R.name),onAddDevices:()=>G(R.name)},R.name),O.length===0&&!V&&o(`p`,{className:`text-xs text-foreground-subtle`,children:e(`locations.noLocationsYetAddIngresso`,`No locations yet. Add Ingresso, Salone, Cucina…`)}),o(et,{open:W!==null,title:e(`locations.room.addDialogTitle`,{room:W??``}),items:ge,listState:m?`pending`:`answered`,lockedIds:W===null?[]:(A.find(e=>e.name===W)?.members??[]).map(e=>e.id),lockedNote:e(`locations.room.alreadyHere`),suggestions:{heading:e(`locations.room.suggestedUnassigned`),ids:F.map(e=>e.id)},busy:v.isPending,onConfirm:e=>{W!==null&&pe(e,W),G(null)},onClose:()=>G(null)})]}),q=t(`div`,{className:`flex flex-col gap-3`,"data-testid":`camera-links-tab`,children:[ve,o(tt,{room:B,cameras:B===null?[]:ut(D,B).filter(e=>e.isCamera),fleet:D})]});return o(Je,{icon:k,title:e(`locations.locations`,`Locations`),subtitle:e(`locations.roomsAndAreasOfThe`,`Rooms and areas of the site. Assign any device here — storage disks are under Data → Storage.`),defaultSection:`locations`,sectionsLabel:`Locations sections`,actions:N===`zones`?o(Dt,{busy:S.isPending,onCreate:e=>S.mutateAsync({name:e})}):o(Et,{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:o(Tt,{zones:U,busy:H,onRename:(e,t)=>w.mutateAsync({from:e,to:t}),onDelete:se,onPickIcon:(e,t)=>S.mutateAsync({name:e,icon:t})})}]})}export{Lt as LocationsPage};
@@ -1 +0,0 @@
1
- import{I as e,K as t,M as n,Q as r,S as i,q as a,x as o,z as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{a as c,c as l,i as u,n as d,o as f,r as p,s as m,t as h}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_konva__loadShare__.js-PmiLsYEK.js";r();var g={rect:`#ef4444`,polygon:`#3b82f6`,grid:`#6366f1`,line:`#f59e0b`},_=`33`,v=`66`,y=`#6366f1`,b=3,x=2,S=12,C=16,w=9;function T(e,t,n){return{x:e.x*t,y:e.y*n}}function E(e,t,n){return{x:e.x/t,y:e.y/n}}function D(e,t,n){return e.flatMap(e=>[e.x*t,e.y*n])}function O(e){return!Number.isFinite(e)||e<0?0:e>1?1:e}function k(e){return e.color??g[e.shape.kind]}function A(e,t){let n=e[t],r=e[(t+1)%e.length];if(!n||!r)return[...e];let i={x:(n.x+r.x)/2,y:(n.y+r.y)/2};return[...e.slice(0,t+1),i,...e.slice(t+1)]}function j(e,t){return e.length===t.length?e.every((e,n)=>{let r=t[n];return Math.abs(e.x-r.x)<1e-6&&Math.abs(e.y-r.y)<1e-6}):!1}function M(e){return e.kind===`polygon`||e.kind===`line`}function N({items:n,selectedId:r,onSelect:d,onShapeChange:f,onDrawComplete:p,drawingKind:_,supportedShapes:v,transparent:A=!1,backdrop:N,polygonVertices:P,grid:F}){let z=t(null),[B,V]=a({w:800,h:450}),[H,U]=a([]),[W,G]=a(null),[ee,te]=a(null),[K,q]=a(null),J=_!==null&&v.includes(_);s(()=>{if(!K)return;let e=n.find(e=>e.id===K.itemId);if(!e||!M(e.shape)){q(null);return}j(e.shape.points,K.points)&&q(null)},[n,K]),s(()=>{let e=z.current;if(!e)return;let t=new ResizeObserver(e=>{let t=e[0];if(!t)return;let{width:n,height:r}=t.contentRect;V(A?{w:n,h:r}:{w:n,h:n*9/16})});return t.observe(e),()=>t.disconnect()},[A]),s(()=>{!J&&W!==null&&G(null)},[J,W]);let Y=e(e=>{p(e),U([])},[p]),X=e(e=>{if(!J||_===null){d(null);return}let t=e.target.getStage();if(!t)return;let n=t.getPointerPosition();if(!n)return;let r=E(n,B.w,B.h);if(_===`rect`){let e=O(r.x),t=O(r.y);Y({kind:`rect`,x:e,y:t,width:Math.min(.2,1-e),height:Math.min(.2,1-t)});return}if(_===`grid`){let e=F?.width??C,t=F?.height??w;Y({kind:`grid`,gridWidth:e,gridHeight:t,cells:Array.from({length:e*t},()=>!1)});return}if(_===`line`){if(H.length===0){U([r]);return}Y({kind:`line`,points:[...H,r]});return}if(_===`polygon`){if(H.length===0){U([r]);return}if(H.length>=b){let e=T(H[0],B.w,B.h);if(Math.hypot(n.x-e.x,n.y-e.y)<S){Y({kind:`polygon`,points:H});return}}U(e=>[...e,r])}},[J,_,H,B,F,Y,d]),ne=e(e=>{!J||_!==`polygon`||H.length<b||(e.cancelBubble=!0,Y({kind:`polygon`,points:H}))},[J,_,H,Y]),Z=t(null),Q=t(null);s(()=>()=>{Z.current!==null&&cancelAnimationFrame(Z.current)},[]);let re=e(e=>{if(!J)return;let t=e.target.getStage();t&&(Q.current=t.getPointerPosition()??null,Z.current===null&&(Z.current=requestAnimationFrame(()=>{Z.current=null,G(Q.current)})))},[J]),ie=t(!1),ae=t(!0),oe=t(new Set),se=e((e,t,n,r)=>{let i=t.gridWidth*t.gridHeight;if(n<0||n>=i||t.cells[n]===r)return;let a=[...t.cells];for(;a.length<i;)a.push(!1);a.length=i,a[n]=r,f(e,{...t,cells:a})},[f]),$=[];if(!A){for(let e=1;e<C;e++){let t=B.w/C*e;$.push(o(l,{points:[t,0,t,B.h],stroke:`#ffffff`,strokeWidth:.5,opacity:.08},`gv-${e}`))}for(let e=1;e<w;e++){let t=B.h/w*e;$.push(o(l,{points:[0,t,B.w,t],stroke:`#ffffff`,strokeWidth:.5,opacity:.08},`gh-${e}`))}}return i(`div`,{ref:z,className:A?`absolute inset-0`:`relative w-full bg-zinc-900 rounded-lg overflow-hidden`,style:{cursor:J?`crosshair`:`default`},children:[N&&!A?o(`div`,{className:`absolute inset-0 pointer-events-none [&>*]:w-full [&>*]:h-full [&>img]:object-cover [&>video]:object-cover`,style:{width:B.w,height:B.h},children:N}):null,i(c,{width:B.w,height:B.h,onClick:X,onDblClick:ne,onMouseMove:re,children:[i(h,{listening:!1,children:[o(l,{points:[0,0,B.w,0,B.w,B.h,0,B.h,0,0],stroke:`transparent`,strokeWidth:0}),$]}),o(h,{children:n.map(e=>{let t=e.id===r,n=e.enabled===!1,i=k(e),a=t&&!J&&!n;if(e.shape.kind===`rect`)return o(I,{item:e,shape:e.shape,color:i,selected:t,dimmed:n,editable:a,isDrawing:J,size:B,onSelect:d,onShapeChange:f},e.id);if(e.shape.kind===`grid`)return o(L,{item:e,shape:e.shape,color:i,dimmed:n,editable:a,size:B,onSelect:d,paintingRef:ie,paintValueRef:ae,paintedRef:oe,paintCell:se},e.id);let s=e.shape.kind===`line`,c=s?x:Math.max(b,P?.min??b),l=s?x:P?.max,u=K&&K.itemId===e.id?K.points:e.shape.points;return o(R,{item:e,shape:e.shape,color:i,selected:t,dimmed:n,editable:a,isLine:s,isDrawing:J,size:B,effectivePoints:u,minVertices:c,maxVertices:l,isDragging:ee===e.id,onSelect:d,onShapeChange:f,setDragOverride:q,setDraggingItemId:te},e.id)})}),o(h,{listening:!1,children:J&&H.length>0&&i(u,{children:[_===`polygon`&&H.length>=2&&o(l,{points:D(H,B.w,B.h),stroke:y,strokeWidth:1.5,dash:[6,3],opacity:.8}),_===`line`&&H.length===1&&W&&o(l,{points:[H[0].x*B.w,H[0].y*B.h,W.x,W.y],stroke:g.line,strokeWidth:1.5,dash:[6,3],opacity:.7}),_===`polygon`&&W&&H.length>=1&&o(l,{points:[H[H.length-1].x*B.w,H[H.length-1].y*B.h,W.x,W.y],stroke:y,strokeWidth:1,dash:[4,4],opacity:.5}),H.map((e,t)=>{let n=T(e,B.w,B.h),r=t===0&&_===`polygon`&&H.length>=b;return o(m,{x:n.x,y:n.y,radius:r?7:4,fill:r?y:`#ffffff`,stroke:y,strokeWidth:1.5,opacity:.9},t)})]})})]}),J?o(`div`,{className:`px-3 py-1.5 bg-zinc-800/80 text-[11px] text-zinc-400 border-t border-zinc-700`,children:_===`line`?`Click to set the start point, click again to complete the line`:_===`rect`?`Click to drop a rectangle, then drag the corner to resize`:_===`grid`?`Click to add the grid, then paint cells`:H.length<b?`Click to add points (min 3). Double-click or click the first point to close.`:`Continue adding points. Double-click or click the first point to close.`}):null]})}var P=.02;function F(e,t){return Math.abs(e.x-t.x)<1e-6&&Math.abs(e.y-t.y)<1e-6&&Math.abs(e.width-t.width)<1e-6&&Math.abs(e.height-t.height)<1e-6}function I({item:e,shape:t,color:n,selected:r,dimmed:c,editable:l,isDrawing:p,size:h,onSelect:g,onShapeChange:y}){let[b,x]=a(null),S={x:t.x,y:t.y,width:t.width,height:t.height};s(()=>{b&&F(S,b)&&x(null)},[t.x,t.y,t.width,t.height,b]);let C=b??S,w=C.x*h.w,T=C.y*h.h,E=C.width*h.w,D=C.height*h.h,k=c?.35:r?1:.85,A=t=>{x(t),y(e.id,{kind:`rect`,x:t.x,y:t.y,width:t.width,height:t.height})};return o(u,{onClick:t=>{t.cancelBubble=!0,p||g(e.id)},children:i(u,{draggable:l,dragBoundFunc:l?e=>({x:Math.max(-w,Math.min(h.w-(w+E),e.x)),y:Math.max(-T,Math.min(h.h-(T+D),e.y))}):void 0,onDragEnd:l?e=>{let t=e.target,n=t.x()/h.w,r=t.y()/h.h;if(t.position({x:0,y:0}),n===0&&r===0)return;let i=Math.min(Math.max(0,C.x+n),Math.max(0,1-C.width)),a=Math.min(Math.max(0,C.y+r),Math.max(0,1-C.height));A({...C,x:i,y:a})}:void 0,onMouseEnter:e=>{if(!l)return;let t=e.target.getStage();t&&(t.container().style.cursor=`move`)},onMouseLeave:e=>{if(!l)return;let t=e.target.getStage();t&&(t.container().style.cursor=p?`crosshair`:`default`)},children:[o(f,{x:w,y:T,width:E,height:D,fill:n+(r?v:_),stroke:n,strokeWidth:r?2.5:1.5,opacity:k}),e.label?o(d,{x:w,y:T-16,text:e.label,fontSize:12,fill:n,stroke:`#000000`,strokeWidth:3,fillAfterStrokeEnabled:!0,fontStyle:`bold`,listening:!1}):null,l?o(m,{x:w+E,y:T+D,radius:6,fill:n,stroke:`#ffffff`,strokeWidth:1.5,draggable:!0,dragBoundFunc:e=>({x:Math.min(h.w,Math.max(w,e.x)),y:Math.min(h.h,Math.max(T,e.y))}),onDragStart:e=>{e.cancelBubble=!0},onDragMove:e=>{let t=e.target,n=O(t.x()/h.w-C.x),r=O(t.y()/h.h-C.y);x({...C,width:Math.max(P,Math.min(n,1-C.x)),height:Math.max(P,Math.min(r,1-C.y))})},onDragEnd:e=>{let t=e.target,n=O(t.x()/h.w-C.x),r=O(t.y()/h.h-C.y);A({...C,width:Math.max(P,Math.min(n,1-C.x)),height:Math.max(P,Math.min(r,1-C.y))})},onMouseEnter:e=>{let t=e.target.getStage();t&&(t.container().style.cursor=`nwse-resize`)},onMouseLeave:e=>{let t=e.target.getStage();t&&(t.container().style.cursor=`default`)}}):null]})})}function L({item:e,shape:t,color:n,dimmed:r,editable:i,size:a,onSelect:s,paintingRef:c,paintValueRef:l,paintedRef:d,paintCell:p}){let{gridWidth:m,gridHeight:h,cells:g}=t,_=a.w/m,y=a.h/h,b=m*h,x=r?.3:1,S=n=>{if(!i){s(e.id);return}let r=g[n]!==!0;c.current=!0,l.current=r,d.current=new Set([n]),p(e.id,t,n,r)},C=n=>{!c.current||!i||d.current.has(n)||(d.current.add(n),p(e.id,t,n,l.current))},w=()=>{c.current&&(c.current=!1,d.current=new Set)};return o(u,{opacity:x,onMouseUp:w,onMouseLeave:w,children:Array.from({length:b},(e,t)=>{let r=t%m,i=Math.floor(t/m),a=g[t]===!0;return o(f,{x:r*_,y:i*y,width:_,height:y,fill:a?n+v:`#ffffff10`,stroke:a?n:`#ffffff40`,strokeWidth:.5,onMouseDown:e=>{e.cancelBubble=!0,S(t)},onMouseEnter:()=>C(t)},t)})})}function R({item:e,shape:t,color:n,selected:r,dimmed:a,editable:s,isLine:c,isDrawing:f,size:h,effectivePoints:g,minVertices:y,maxVertices:b,isDragging:x,onSelect:S,onShapeChange:C,setDragOverride:w,setDraggingItemId:O}){let k=D(g,h.w,h.h),j=a?.35:r?1:c?.8:.85,M=e=>c?{kind:`line`,points:[...e]}:{kind:`polygon`,points:[...e]},N=g.map(e=>e.x*h.w),P=g.map(e=>e.y*h.h),F=N.length>0?Math.min(...N):0,I=N.length>0?Math.max(...N):0,L=P.length>0?Math.min(...P):0,R=P.length>0?Math.max(...P):0,z=e=>({x:Math.max(-F,Math.min(h.w-I,e.x)),y:Math.max(-L,Math.min(h.h-R,e.y))}),B=n=>{let r=n.target,i=r.x()/h.w,a=r.y()/h.h;if(r.position({x:0,y:0}),O(null),i===0&&a===0)return;let o=t.points.map(e=>({x:e.x+i,y:e.y+a}));w({itemId:e.id,points:o}),C(e.id,M(o))},V=!c&&g.length>y,H=!c&&(b===void 0||g.length<b);return i(u,{onClick:t=>{t.cancelBubble=!0,f||S(e.id)},children:[i(u,{draggable:s,dragBoundFunc:s?z:void 0,onDragStart:s?()=>O(e.id):void 0,onDragEnd:s?B:void 0,onMouseEnter:e=>{if(!s)return;let t=e.target.getStage();t&&(t.container().style.cursor=`move`)},onMouseLeave:e=>{if(!s)return;let t=e.target.getStage();t&&(t.container().style.cursor=f?`crosshair`:`default`)},children:[c?o(p,{points:k,stroke:n,strokeWidth:r?3:2,fill:n,pointerLength:10,pointerWidth:8,opacity:j}):o(l,{points:k,closed:!0,fill:n+(r?v:_),stroke:n,strokeWidth:r?2.5:1.5,opacity:j}),e.label&&g.length>0?(()=>{let t=T({x:g.reduce((e,t)=>e+t.x,0)/g.length,y:g.reduce((e,t)=>e+t.y,0)/g.length},h.w,h.h),r=Math.max(40,e.label.length*11*.62);return o(d,{x:t.x-r/2,y:t.y-7,width:r,align:`center`,text:e.label,fontSize:12,fill:n,stroke:`#000000`,strokeWidth:3,fillAfterStrokeEnabled:!0,fontStyle:`bold`,listening:!1})})():null]}),s&&!x&&g.map((r,i)=>{let a=T(r,h.w,h.h);return o(m,{x:a.x,y:a.y,radius:5,fill:n,stroke:`#ffffff`,strokeWidth:1.5,draggable:!0,onDragMove:n=>{let r=E({x:n.target.x(),y:n.target.y()},h.w,h.h);w(n=>{let a=n&&n.itemId===e.id?n.points:t.points;return{itemId:e.id,points:a.map((e,t)=>t===i?r:e)}})},onDragEnd:n=>{let r=E({x:n.target.x(),y:n.target.y()},h.w,h.h),a=t.points.map((e,t)=>t===i?r:e);w({itemId:e.id,points:a}),C(e.id,M(a))},onContextMenu:n=>{n.evt.preventDefault(),n.cancelBubble=!0,V&&C(e.id,M(t.points.filter((e,t)=>t!==i)))}},`pt-${i}`)}),s&&!x&&H&&g.length>=2&&g.map((r,i)=>{let a=g[(i+1)%g.length],s=T({x:(r.x+a.x)/2,y:(r.y+a.y)/2},h.w,h.h);return o(m,{x:s.x,y:s.y,radius:4,fill:`#ffffff`,stroke:n,strokeWidth:1.5,opacity:.6,onMouseEnter:e=>{let t=e.target;t.to({radius:6,opacity:1,duration:.1});let n=t.getStage();n&&(n.container().style.cursor=`copy`)},onMouseLeave:e=>{let t=e.target;t.to({radius:4,opacity:.6,duration:.1});let n=t.getStage();n&&(n.container().style.cursor=f?`crosshair`:`default`)},onClick:n=>{n.cancelBubble=!0,C(e.id,M(A(t.points,i)))}},`mid-${i}`)})]})}var z=n(N);export{z as MaskShapeCanvas};
@@ -1 +0,0 @@
1
- import{I as e,K as t,Q as n,S as r,W as i,b as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Cr as ee,K as te,U as ne,X as l,n as u,ot as d,z as f}from"./player-overlays-Cda8wso6.js";import{MaskShapeCanvas as p}from"./MaskShapeCanvas-Dcpby34M.js";n();var m=110,h=`motion-zones`,g=0,_=[1,2,3],v=1,y=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,b=`rounded-md border border-primary/50 bg-primary/15 px-2.5 py-1 text-[11px] font-medium text-primary hover:bg-primary/25 disabled:opacity-40 transition-colors`;function x(e,t,n){let r=t*n,i=Array.from({length:r});for(let t=0;t<r;t+=1)i[t]=e[t]===!0;return i}function S(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return!1;return!0}function C(e,t){return Math.ceil(e/t)}function w(e,t,n){return Math.min(n-1,Math.floor((e+.5)/t*n))}function T(e,t,n,r){let i=C(t,r),a=C(n,r),o=Array.from({length:i*a},()=>!1);for(let r=0;r<n;r+=1){let s=w(r,n,a);for(let n=0;n<t;n+=1)e[r*t+n]===!0&&(o[s*i+w(n,t,i)]=!0)}return o}function E(e,t,n,r){let i=C(t,r),a=C(n,r),o=Array.from({length:t*n},()=>!1);for(let r=0;r<n;r+=1){let s=w(r,n,a);for(let n=0;n<t;n+=1)o[r*t+n]=e[s*i+w(n,t,i)]===!0}return o}function D({deviceId:n}){let w=te(d().trpcClient,n),[D,O]=o(null),[k,A]=o(!1),[j,M]=o(null),[N,P]=o(null),[F,I]=o(v),[L,R]=o(!1),[z,B]=o(!1),V=t(!1);c(()=>{if(!w)return;let e=!1;return V.current=!1,O(null),A(!1),M(null),P(null),I(v),B(!1),(async()=>{try{let t=await w.motionZones?.getOptions({});if(e)return;if(!t)throw Error(`device proxy not ready`);if(O(t),V.current)return;let n=await w.motionZones?.getStatus({});if(e)return;if(!n)throw Error(`device proxy not ready`);V.current=!0;let r=n.regions.find(e=>e.shape.kind===`grid`),i=x(r?r.shape.cells:[],t.grid.width,t.grid.height);P(i),M(T(i,t.grid.width,t.grid.height,v))}catch(t){if(e)return;ne(t)?A(!0):console.error(`Motion Zones load failed`,t)}})(),()=>{e=!0}},[w]);let H=D?D.grid.width:0,U=D?D.grid.height:0,W=C(H,F),G=C(U,F),K=i(()=>j&&D?E(j,H,U,F):null,[j,D,H,U,F]),q=i(()=>K!==null&&N!==null&&!S(K,N),[K,N]),J=i(()=>K?K.reduce((e,t)=>t?e+1:e,0):0,[K]),Y=H*U,X=W*G,Z=e(e=>{X>0&&M(Array.from({length:X},()=>e))},[X]),re=e(()=>{M(e=>e&&e.map(e=>!e))},[]),ie=e(()=>{N&&D&&M(T(N,H,U,F))},[N,D,H,U,F]),ae=e(e=>{e===F||!D||M(t=>{if(!t)return I(e),t;let n=T(E(t,H,U,F),H,U,e);return I(e),n})},[F,D,H,U]),Q=i(()=>D&&j?[{id:g,shape:{kind:`grid`,gridWidth:W,gridHeight:G,cells:[...j]}}]:[],[D,j,W,G]),$=e((e,t)=>{t.kind===`grid`&&M(t.cells)},[]),oe=e(async()=>{if(!(!w||!j||!D)){R(!0);try{let e=E(j,D.grid.width,D.grid.height,F),t={kind:`grid`,gridWidth:D.grid.width,gridHeight:D.grid.height,cells:e};await w.motionZones?.setZone({patch:{regions:[{id:g,enabled:!0,shape:t}]}});let n=await w.motionZones?.getStatus({});if(n){let e=n.regions.find(e=>e.shape.kind===`grid`),t=x(e?e.shape.cells:[],D.grid.width,D.grid.height);P(t),M(T(t,D.grid.width,D.grid.height,F))}}catch(e){console.error(`Motion Zones save failed`,e)}finally{R(!1)}}},[w,j,D,F]);return u(i(()=>z&&!k&&D&&j?{id:h,order:m,node:s(p,{transparent:!0,items:Q,supportedShapes:[`grid`],grid:{width:W,height:G},selectedId:g,onSelect:()=>{},onShapeChange:$,onDrawComplete:()=>{},drawingKind:null})}:null,[z,k,D,j,Q,$,W,G])),w?s(l,{title:`Motion Zones`,icon:s(ee,{className:`h-3.5 w-3.5 text-foreground-subtle`}),children:s(`div`,{className:`flex flex-col gap-3`,children:k?s(`p`,{className:`${f} leading-relaxed`,children:`This camera doesn't expose an on-board motion zones grid.`}):!k&&D!==null&&j!==null?r(a,{children:[r(`p`,{className:`${f} leading-relaxed`,children:[`Toggle `,s(`strong`,{className:`text-foreground`,children:`Edit grid`}),` to paint the region directly on the live frame, then `,s(`strong`,{className:`text-foreground`,children:`Save`}),` to push the mask to the camera. Pick a bigger`,` `,s(`strong`,{className:`text-foreground`,children:`Cell size`}),` for quicker, broad-stroke painting — it's resampled to the camera's native `,D.grid.width,`×`,D.grid.height,` grid on save (×1 is the finest).`]}),r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[s(`button`,{type:`button`,onClick:()=>B(e=>!e),disabled:L,"aria-pressed":z,className:z?b:y,children:z?`Done editing`:`Edit grid`}),s(`button`,{type:`button`,onClick:()=>Z(!0),disabled:L,className:y,children:`All on`}),s(`button`,{type:`button`,onClick:()=>Z(!1),disabled:L,className:y,children:`All off`}),s(`button`,{type:`button`,onClick:re,disabled:L,className:y,children:`Invert`}),r(`div`,{className:`flex items-center gap-1 ml-1`,role:`group`,"aria-label":`Cell size`,children:[s(`span`,{className:`${f} mr-0.5`,children:`Cell size`}),_.map(e=>r(`button`,{type:`button`,onClick:()=>ae(e),disabled:L,"aria-pressed":F===e,title:e===1?`Camera grid ${H}×${U} (finest)`:`${C(H,e)}×${C(U,e)} painting grid · cells ×${e} bigger`,className:F===e?b:y,children:[`×`,e]},e))]}),r(`span`,{className:`${f} ml-1 tabular-nums`,children:[J,` / `,Y,` cells · `,D.grid.width,`×`,D.grid.height,F===1?``:` · paint ${W}×${G}`]}),s(`span`,{className:`flex-1`}),s(`button`,{type:`button`,onClick:ie,disabled:L||!q,className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,children:`Revert`}),s(`button`,{type:`button`,onClick:()=>void oe(),disabled:L||!q,className:b,children:L?`Saving…`:`Save`})]})]}):s(`p`,{className:`${f} leading-relaxed`,children:`Loading the camera's grid…`})})}):null}export{D as MotionZonesSettings};