@camstack/addon-admin-ui 1.2.474 → 1.2.475

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 (174) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +19 -0
  3. package/dist/assets/AddonAssetIcon-BNfqkJPr.js +1 -0
  4. package/dist/assets/Addons-BQclhgQv.js +5 -0
  5. package/dist/assets/AdminPage-UX2_-EVb.js +1 -0
  6. package/dist/assets/AdminSectionedPage-CJhCo7eS.js +1 -0
  7. package/dist/assets/AiProfiles-zhlwR2_B.js +3 -0
  8. package/dist/assets/BrokerForm-B1b0ZQq_.js +1 -0
  9. package/dist/assets/Build-DMVYWc57.js +40 -0
  10. package/dist/assets/Calendars-CPP5G4iE.js +1 -0
  11. package/dist/assets/Cluster-DxeRVsUO.js +1 -0
  12. package/dist/assets/CompositionCreateForm-ZntjBNdS.js +1 -0
  13. package/dist/assets/{CompositionEditorPage-syg6YTJF.js → CompositionEditorPage-CpvZY109.js} +1 -1
  14. package/dist/assets/Data-NzOvsB8O.js +2 -0
  15. package/dist/assets/DeviceDetail-DKGhhLVK.js +2 -0
  16. package/dist/assets/DeviceDoActionFields-CVBUVXjq.js +1 -0
  17. package/dist/assets/Devices-D9OmxxCE.js +1 -0
  18. package/dist/assets/EmbedPlayerPage-u5jZuoCz.js +1 -0
  19. package/dist/assets/HelperWizard-Dape3GuD.js +2 -0
  20. package/dist/assets/History-D-T-XA80.js +1 -0
  21. package/dist/assets/Identity-DmBhBZsL.js +1 -0
  22. package/dist/assets/IntegrationDetail-0C2a7iSq.js +1 -0
  23. package/dist/assets/IntegrationHub-DdxMGRIt.js +1 -0
  24. package/dist/assets/Integrations-aOO9hE39.js +1 -0
  25. package/dist/assets/Integrations-eKDwugCV.js +1 -0
  26. package/dist/assets/Library-DUWYOPjU.js +1 -0
  27. package/dist/assets/Locations-D4YphIdu.js +3 -0
  28. package/dist/assets/Logs-CPgxOarw.js +1 -0
  29. package/dist/assets/MaskShapeCanvas-Cmq6IidK.js +1 -0
  30. package/dist/assets/MotionZonesSettings-CnZg9FTF.js +1 -0
  31. package/dist/assets/MyAccess-BKLOlMok.js +2 -0
  32. package/dist/assets/Network-BT4UeK8H.js +1 -0
  33. package/dist/assets/NodeAddonsSettingsPanel-75hJ0AJM.js +1 -0
  34. package/dist/assets/Notifications-B7JOfwPI.js +1 -0
  35. package/dist/assets/Pipeline-DKfkLPEM.js +1 -0
  36. package/dist/assets/PrivacyMaskSettings-BFWSAVsy.js +1 -0
  37. package/dist/assets/Recordings-OmewxCzq.js +1 -0
  38. package/dist/assets/ScanNetworkModal-hCwvBDMd.js +1 -0
  39. package/dist/assets/SceneMonitorEditor-BVdAyhJk.js +1 -0
  40. package/dist/assets/SessionsList-CTsz8qck.js +2 -0
  41. package/dist/assets/Showroom-DlUMfmmX.js +1 -0
  42. package/dist/assets/System-xDNpG66Z.js +1 -0
  43. package/dist/assets/{Terminal-COEKXIAj.js → Terminal-BKTT8qvq.js} +3 -3
  44. package/dist/assets/{Viewer-BW9JCbu_.js → Viewer-Cu8oX6VE.js} +1 -1
  45. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-B4AOEb1R.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-20B8V9NZ.js} +1 -1
  46. package/dist/assets/{_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js → _virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js} +1 -1
  47. package/dist/assets/_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DzoL8nR8.js +1 -0
  48. package/dist/assets/_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.js-BPba2g2p.js +1 -0
  49. package/dist/assets/{_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-Cb2QlpvS.js → _virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-ZBKFTPET.js} +1 -1
  50. package/dist/assets/{_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_konva__loadShare__.js-Cyj0Xie_.js → _virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_konva__loadShare__.js-BjdR__nc.js} +3 -3
  51. package/dist/assets/addon-icons-context-BuuVE9Wr.js +1 -0
  52. package/dist/assets/{archive-BTmhmQQp.js → archive-CfJx72Ya.js} +1 -1
  53. package/dist/assets/{assignment-candidates-C4DL_rSh.js → assignment-candidates-B51c4fCG.js} +1 -1
  54. package/dist/assets/authed-media-iyqNF0CO.js +1 -0
  55. package/dist/assets/{bell-off-DsAerV0u.js → bell-off-D1QNHdBJ.js} +1 -1
  56. package/dist/assets/{board-model-CnpzmN9f.js → board-model-4EY3kgfH.js} +1 -1
  57. package/dist/assets/{boxes-DT6bkxUA.js → boxes-DomeSuUE.js} +1 -1
  58. package/dist/assets/circle-slash-CPzLe6ak.js +1 -0
  59. package/dist/assets/client-fa7ANI4X.js +358 -0
  60. package/dist/assets/{cloud-upload-iGrXLaxX.js → cloud-upload-J0OXIjbZ.js} +1 -1
  61. package/dist/assets/crop-4oyysRxn.js +1 -0
  62. package/dist/assets/{device-integration-icon-XVdZ9pIS.js → device-integration-icon-BQEjbsKG.js} +1 -1
  63. package/dist/assets/device-picker-model-CsITnnp7.js +1 -0
  64. package/dist/assets/dist-Cwk0eIEi.js +358 -0
  65. package/dist/assets/{dist-Bd_kB5yG.js → dist-DcarhQ77.js} +1 -1
  66. package/dist/assets/{eraser-L4lKjV-e.js → eraser-DdaeWuQ6.js} +1 -1
  67. package/dist/assets/{format-BTMQLjGl.js → format-Bq6kzos8.js} +1 -1
  68. package/dist/assets/{hard-drive-download-cfcxCkzE.js → hard-drive-download-YerwrGPA.js} +1 -1
  69. package/dist/assets/{hostInit-BBq0iCeL.js → hostInit-B6UQXYd9.js} +1 -1
  70. package/dist/assets/i18n-l_m6iBJW.js +1 -0
  71. package/dist/assets/{icons-Cv_Dcjty.js → icons-BBOyPCCy.js} +1 -1
  72. package/dist/assets/{index-BvsP28fN.css → index-B4dcSKZt.css} +1 -1
  73. package/dist/assets/index-Ctkts88E.js +4 -0
  74. package/dist/assets/{key-e3_N15fG.js → key-CunS-V0Z.js} +1 -1
  75. package/dist/assets/{key-round-x0Ig1rd2.js → key-round-DcVl91E5.js} +1 -1
  76. package/dist/assets/{layers-T4HoHbdn.js → layers-BC3a28BZ.js} +1 -1
  77. package/dist/assets/{linked-devices-model-CObOrxIk.js → linked-devices-model-CWqnVKj5.js} +1 -1
  78. package/dist/assets/{list-ordered-I4dBVzRf.js → list-ordered-B_2hLh_-.js} +1 -1
  79. package/dist/assets/location-owned-usage-C3ukxAgd.js +1 -0
  80. package/dist/assets/{log-in-B1D0wNrs.js → log-in-IPEzbjqk.js} +1 -1
  81. package/dist/assets/{memory-stick-DYS3v1CU.js → memory-stick-CUBeuzQu.js} +1 -1
  82. package/dist/assets/{message-square-plus-D64e2l9L.js → message-square-plus-DHiayOOs.js} +1 -1
  83. package/dist/assets/{mf-entry-bootstrap-0-c6a36508.js → mf-entry-bootstrap-0-976d3c1a.js} +2 -2
  84. package/dist/assets/{mic-off-hTqpFTxe.js → mic-off-DX_Buyxi.js} +1 -1
  85. package/dist/assets/{monitor-off-Bj-JQM7b.js → monitor-off-Czk3uiUL.js} +1 -1
  86. package/dist/assets/{monitor-smartphone-CyTSF3mW.js → monitor-smartphone-DhnI06Vd.js} +1 -1
  87. package/dist/assets/mount-CsITnnp7.js +1 -0
  88. package/dist/assets/player-overlays-DfIXPXfC.js +1 -0
  89. package/dist/assets/{recycle-BLx8Nd-6.js → recycle-CIxCuRlw.js} +1 -1
  90. package/dist/assets/remoteEntry-isS_YRZd.js +1 -0
  91. package/dist/assets/{scan-eye-CrOhuNWQ.js → scan-eye-CNch-kOQ.js} +1 -1
  92. package/dist/assets/{scissors-C6HYvaxr.js → scissors-DAqmNijF.js} +1 -1
  93. package/dist/assets/{search-x-C8eiZDQW.js → search-x-Bam8bduF.js} +1 -1
  94. package/dist/assets/{send-CNzJmniJ.js → send-DTxEr1U2.js} +1 -1
  95. package/dist/assets/{settings-2-Ccb0AMXU.js → settings-2-Gykf_Jj2.js} +1 -1
  96. package/dist/assets/{speaker-BsE4hqmg.js → speaker-vU_58Q4N.js} +1 -1
  97. package/dist/assets/src-Cy_bal4g.js +67 -0
  98. package/dist/assets/step-inspector-model-COSP18Eo.js +1 -0
  99. package/dist/assets/{timer-reset-Tun-zcxs.js → timer-reset-BfVqeFHK.js} +1 -1
  100. package/dist/assets/{ungroup-BdxY8QDj.js → ungroup-BzhYEwYi.js} +1 -1
  101. package/dist/assets/{unlink-BVODHZoC.js → unlink-DcrSLSGi.js} +1 -1
  102. package/dist/assets/{usb-i2JzfEjl.js → usb-CCxf9eVL.js} +1 -1
  103. package/dist/assets/{use-scenes-feed-CUQxwk-v.js → use-scenes-feed-CCy-Tx5-.js} +1 -1
  104. package/dist/assets/{use-stationary-objects-Cqmb4Ymg.js → use-stationary-objects-rfvEUY5Q.js} +1 -1
  105. package/dist/assets/useEventInvalidation-CsITnnp7.js +1 -0
  106. package/dist/assets/useNodeUrlSelection-BDqOR0oD.js +1 -0
  107. package/dist/assets/useTranslation-BJr-n0es.js +1 -0
  108. package/dist/assets/user-round-D6lnAuWE.js +1 -0
  109. package/dist/assets/{user-x-CIq05NC_.js → user-x-DNQnP84p.js} +1 -1
  110. package/dist/assets/{video-CJw8Jnle.js → video-FHJCba2c.js} +1 -1
  111. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BWKP-Fxc.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BBtNcF2c.js} +2 -2
  112. package/dist/index.html +11 -11
  113. package/dist/server/addon.js +145 -8
  114. package/package.json +4 -2
  115. package/dist/assets/AddonAssetIcon-DNTjc2uq.js +0 -1
  116. package/dist/assets/Addons-CPaW6tLw.js +0 -4
  117. package/dist/assets/AdminPage-B4QlIiKh.js +0 -1
  118. package/dist/assets/AdminSectionedPage-BIoU14zn.js +0 -1
  119. package/dist/assets/AiProfiles-FpbSg3kP.js +0 -3
  120. package/dist/assets/BrokerForm-CU4X3nL7.js +0 -1
  121. package/dist/assets/Build-C2qKCizt.js +0 -40
  122. package/dist/assets/Calendars-BRTmlFIt.js +0 -1
  123. package/dist/assets/Cluster-BvxOiIZ7.js +0 -1
  124. package/dist/assets/CompositionCreateForm-DCUy3waQ.js +0 -1
  125. package/dist/assets/Data-VG64mGmK.js +0 -2
  126. package/dist/assets/DeviceDetail-tZevLHDV.js +0 -2
  127. package/dist/assets/DeviceDoActionFields-BmEM1vFn.js +0 -1
  128. package/dist/assets/Devices-B-b5cUYn.js +0 -1
  129. package/dist/assets/EmbedPlayerPage-CI3OOtRg.js +0 -1
  130. package/dist/assets/HelperWizard-4637ctxc.js +0 -2
  131. package/dist/assets/History-BJcol9mz.js +0 -1
  132. package/dist/assets/Identity-CjEfAbi1.js +0 -1
  133. package/dist/assets/IntegrationDetail-DLncDXox.js +0 -1
  134. package/dist/assets/IntegrationHub-B1soAFk9.js +0 -1
  135. package/dist/assets/Integrations-DtQc1eDp.js +0 -1
  136. package/dist/assets/Integrations-xxkUIJ67.js +0 -1
  137. package/dist/assets/Library-DbHcY62a.js +0 -1
  138. package/dist/assets/Locations-CfYQkG2R.js +0 -3
  139. package/dist/assets/Logs-CMYLVX21.js +0 -1
  140. package/dist/assets/MaskShapeCanvas-BnMDm4ev.js +0 -1
  141. package/dist/assets/MotionZonesSettings-DKqDt4OB.js +0 -1
  142. package/dist/assets/MyAccess-CjUd-G8J.js +0 -2
  143. package/dist/assets/Network-Dudx2Fcg.js +0 -1
  144. package/dist/assets/NodeAddonsSettingsPanel-9_q0f4bE.js +0 -1
  145. package/dist/assets/Notifications-DE5Wtais.js +0 -1
  146. package/dist/assets/Pipeline-r8TFI-Fa.js +0 -1
  147. package/dist/assets/PrivacyMaskSettings-DZ2mewnu.js +0 -1
  148. package/dist/assets/Recordings-BrpMcrZw.js +0 -1
  149. package/dist/assets/ScanNetworkModal-DhahS87x.js +0 -1
  150. package/dist/assets/SceneMonitorEditor-CH7F9rZo.js +0 -1
  151. package/dist/assets/SessionsList-BbD9LSdf.js +0 -2
  152. package/dist/assets/Showroom-BX1LrKmF.js +0 -1
  153. package/dist/assets/System-CvErxLx3.js +0 -1
  154. package/dist/assets/_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DdJYWyu3.js +0 -1
  155. package/dist/assets/_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.js-DPkvGqVU.js +0 -1
  156. package/dist/assets/addon-icons-context-Bus8wGvh.js +0 -1
  157. package/dist/assets/authed-media-C8FW8mvx.js +0 -1
  158. package/dist/assets/circle-slash-BFwh1Zbg.js +0 -1
  159. package/dist/assets/client-BbPYrWg7.js +0 -358
  160. package/dist/assets/crop-FX76GBoF.js +0 -1
  161. package/dist/assets/device-picker-model-B5MjkWnS.js +0 -1
  162. package/dist/assets/dist-D6Fj77pb.js +0 -358
  163. package/dist/assets/i18n-BO6gCPcC.js +0 -1
  164. package/dist/assets/index-C8XwyZGE.js +0 -4
  165. package/dist/assets/location-owned-usage-D17U3uzz.js +0 -1
  166. package/dist/assets/mount-B5MjkWnS.js +0 -1
  167. package/dist/assets/player-overlays-CvKnZb5M.js +0 -1
  168. package/dist/assets/remoteEntry-DBUvkI6n.js +0 -1
  169. package/dist/assets/src-DKc14e9G.js +0 -67
  170. package/dist/assets/step-inspector-model-BeIQx3rW.js +0 -1
  171. package/dist/assets/useEventInvalidation-B5MjkWnS.js +0 -1
  172. package/dist/assets/useNodeUrlSelection-rnUQLTfb.js +0 -1
  173. package/dist/assets/useTranslation-D3Is_4B6.js +0 -1
  174. package/dist/assets/user-round-BkFCDGbj.js +0 -1
@@ -0,0 +1 @@
1
+ import{C as e,J as t,K as n,Q as r,R as i,S as a,V as o,Y as s,a as c,et as l,o as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Ai as f,At as p,D as m,Di as h,Dr as g,Dt as _,Ei as v,Fn as y,Fr as b,It as x,Jt as S,Nt as C,Q as w,Si as T,Wr as E,Wt as D,Yt as O,Z as k,Zr as A,Zt as j,_r as M,ai as N,bi as P,bn as F,c as I,dt as L,f as R,fn as z,ir as B,kn as V,l as H,mn as U,or as W,ot as G,ta as ee,u as te,vn as ne,xi as K,yi as re,z as ie}from"./player-overlays-DfIXPXfC.js";import{Ma as q,kr as ae,nt as oe}from"./client-fa7ANI4X.js";import{a as se,c as ce,i as le,n as ue,o as de,r as fe,s as pe,t as me}from"./user-x-DNQnP84p.js";import{c as he}from"./video-FHJCba2c.js";import{t as ge}from"./crop-4oyysRxn.js";import{t as _e}from"./user-round-D6lnAuWE.js";import{$n as ve,$o as ye,$u as be,Cl as xe,Cn as Se,Dl as Ce,Dr as we,El as Te,Er as Ee,Go as De,Gr as J,Hr as Oe,Jo as ke,Js as Ae,Ko as je,Ol as Me,Qo as Ne,Qr as Pe,Qu as Fe,Si as Ie,Sl as Le,St as Re,Tl as ze,Ur as Be,Uu as Ve,Wr as He,Wu as Ue,Xo as We,Xr as Ge,Yo as Ke,Zo as qe,Zr as Je,_d as Ye,_l as Xe,_r as Ze,bl as Qe,dn as $e,do as et,es as tt,fc as nt,fr as rt,ft as it,gc as at,gl as ot,gn as st,gr as ct,hr as lt,ht as ut,mc as dt,mn as ft,mr as pt,nn as mt,ns as ht,pc as gt,pn as _t,pt as vt,qo as yt,qu as bt,rs as xt,t as St,ts as Ct,uc as wt,vc as Tt,vl as Et,vr as Dt,wl as Ot,wn as kt,xl as At,xn as jt,xr as Mt,yc as Nt,yl as Pt}from"./src-Cy_bal4g.js";import{t as Y}from"./i18n-l_m6iBJW.js";import{t as X}from"./useTranslation-BJr-n0es.js";import"./mount-CsITnnp7.js";import{dr as Ft,fr as It,lr as Lt,mr as Rt,x as zt}from"./index-Ctkts88E.js";import{t as Bt}from"./AdminSectionedPage-CJhCo7eS.js";import{t as Vt}from"./use-stationary-objects-rfvEUY5Q.js";import{a as Ht,i as Ut,n as Wt,r as Gt,t as Kt}from"./authed-media-iyqNF0CO.js";import{t as qt}from"./use-scenes-feed-CCy-Tx5-.js";l();function Jt({mediaId:e,base64:t,alt:n,className:r,placeholder:i}){let{src:o,failed:s}=Ht(e===void 0?void 0:Gt(e));return o===null?(e===void 0||s)&&t!==void 0&&t!==``?a(`img`,{src:`data:image/jpeg;base64,${t}`,alt:n,className:r}):i:a(`img`,{src:o,alt:n,className:r})}var Yt=`pipeline-analytics`,Xt=`photo.analyze`,Zt=`photo.enroll`,Qt=`photo.discard`,$t=18*1024*1024;function en(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function tn(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function nn(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function rn(e,t){let n=e[t];return typeof n==`boolean`?n:null}function an(e){if(!en(e))return null;let t=nn(e,`x`),n=nn(e,`y`),r=nn(e,`width`),i=nn(e,`height`);return t===null||n===null||r===null||i===null?null:{x:t,y:n,width:r,height:i}}function on(e){if(!en(e))return null;let t=nn(e,`detectionShortSidePx`),n=nn(e,`score`);if(t===null||n===null)return null;let r=nn(e,`magnitude`);return{detectionShortSidePx:t,score:n,...r===null?{}:{magnitude:r}}}function sn(e){if(!en(e))return null;let t=nn(e,`faceIndex`),n=nn(e,`score`),r=rn(e,`enrollable`),i=an(e.bbox),a=on(e.quality);if(t===null||n===null||r===null||i===null||a===null)return null;let o=tn(e,`refusedReason`),s=tn(e,`alignedCropBase64`),c=tn(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 cn(e){if(!en(e))return null;let t=tn(e,`sessionId`),n=tn(e,`ranOnNodeId`),r=e.faces;if(t===null||n===null||!Array.isArray(r))return null;let i=[];for(let e of r){let t=sn(e);t!==null&&i.push(t)}return{sessionId:t,ranOnNodeId:n,faces:i}}function ln(e){if(!en(e))return null;let t=tn(e,`sampleId`),n=tn(e,`identityId`),r=tn(e,`modelId`);return t===null||n===null||r===null?null:{sampleId:t,identityId:n,modelId:r}}function un(e,t,n){let r={...e};return n===null||n===``?delete r[t]:r[t]=n,r}function dn(e,t){return e.filter(e=>e.enrollable&&t[e.faceIndex]!==void 0).length}function fn(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 pn(e){switch(e){case`no-embedding`:return Y.t(`helpers.photoEnroll.refusal.noEmbedding`);case`no-model-id`:return Y.t(`helpers.photoEnroll.refusal.noModelId`);case`no-aligned-crop`:return Y.t(`helpers.photoEnroll.refusal.noAlignedCrop`);case`magnitude`:return Y.t(`helpers.photoEnroll.refusal.magnitude`);default:return Y.t(`helpers.photoEnroll.refusal.default`)}}function mn(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 hn(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 gn(e,t,n){return e.map(e=>e.photoIndex===t?{...e,...n}:e)}function _n(e,t){return`${e}:${t}`}function vn(e,t,n,r){let i=un(e[t]??{},n,r),a={...e};return Object.keys(i).length===0?delete a[t]:a[t]=i,a}function yn(e,t){let n=0;for(let r of e)r.analysis!==void 0&&(n+=dn(r.analysis.faces,t[r.photoIndex]??{}));return n}var bn=`__new__`;function xn(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[_n(i.photoIndex,t.faceIndex)]??``).trim();if(a===``)return{kind:`error`,message:Y.t(`helpers.photoEnrollBatch.newPersonNoName`,{filename:i.filename,face:t.faceIndex+1})};r.includes(a)||r.push(a)}}return{kind:`ok`,names:r}}function Sn(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[_n(e,a)]??``).trim()];s!==void 0&&(o[a]=s)}r[e]=o}return r}function Cn(e,t){let n=[];for(let r of e){if(r.analysis===void 0)continue;let e=fn(r.analysis.sessionId,r.analysis.faces,t[r.photoIndex]??{});for(let t of e)n.push({photoIndex:r.photoIndex,request:t})}return n}function wn(e){return/expired/i.test(e)}function Tn(e){return e instanceof Error?e.message:String(e)}async function En(e,t,n){let r=new Map(e.map(e=>[e.photoIndex,e])),i={},a=[],o=0,s=null,c=(e,t)=>{let n=r.get(e)?.filename??Y.t(`helpers.photoEnrollBatch.photoFallback`,{n:e+1});return Y.t(`helpers.photoEnrollBatch.faceLabel`,{filename:n,face:t+1})};for(let l of Cn(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=Tn(t);if(!wn(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 (${Tn(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)}: ${Tn(e)}`)}}}return{enrolled:o,stampedModelId:s,failures:a,refreshedAnalyses:i}}var Dn=[[`faceGallery`]],On=``;function kn(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 An(e){return e instanceof Error?e.message:String(e)}function jn({face:t,identities:r,value:i,onChange:o,disabled:s}){let{t:c}=X(),l=n(()=>[{value:On,label:c(`detectionIntelligence.photoEnrollDialog.ignoreThisFace`,`Ignore this face`)},...r.map(e=>({value:e.id,label:e.name})),{value:bn,label:c(`detectionIntelligence.photoEnrollDialog.newPerson`,`+ New person…`)}],[r,c]);return e(`div`,{className:`rounded-md border border-border bg-surface p-2`,children:[a(`div`,{className:`mb-2 aspect-square w-full overflow-hidden rounded border border-border bg-surface-hover`,children:t.alignedCropBase64?a(`img`,{src:`data:image/jpeg;base64,${t.alignedCropBase64}`,alt:c(`detectionIntelligence.photoEnrollDialog.face`,`Face {{value1}}`,{value1:t.faceIndex+1}),className:`h-full w-full object-cover`}):a(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:a(_e,{className:`h-8 w-8`})})}),a(`div`,{className:`min-h-[4.75rem]`,children:t.enrollable?e(d,{children:[a(bt,{options:l,value:i,disabled:s,onChange:e=>o(e.target.value),"aria-label":c(`detectionIntelligence.photoEnrollDialog.assignFace`,`Assign face {{value1}}`,{value1:t.faceIndex+1})}),e(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:[Math.round(t.quality.detectionShortSidePx),` px`,t.modelId?` · ${t.modelId}`:``]})]}):e(`div`,{className:`space-y-1`,children:[a(Pe,{variant:`warning`,className:`text-[10px]`,children:c(`detectionIntelligence.photoEnrollDialog.notUsable`,`Not usable`)}),a(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:pn(t.refusedReason)})]})})]})}function Mn({photo:t,identities:n,draft:r,newNames:i,disabled:o,onAssign:s,onNameChange:c,onRetry:l}){let{t:u}=X(),d=t.analysis?.faces??[],f=r[t.photoIndex]??{};return e(`div`,{className:`space-y-2`,children:[e(`div`,{className:`flex items-center gap-2 border-b border-border pb-1`,children:[a(`span`,{className:`truncate text-xs font-medium text-foreground`,children:t.filename}),t.status===`analyzing`||t.status===`queued`?e(`span`,{className:`flex items-center gap-1 text-xs text-foreground-subtle`,children:[a(W,{className:`h-3 w-3 animate-spin`}),` `,u(`detectionIntelligence.photoEnrollDialog.analysing`)]}):null,t.status===`analyzed`&&t.analysis!==void 0&&a(`span`,{className:`text-xs text-foreground-subtle`,children:u(`detectionIntelligence.photoEnrollDialog.facesAnalysedOn`,{count:d.length,node:t.analysis.ranOnNodeId})}),t.status===`failed`&&e(J,{variant:`secondary`,size:`sm`,disabled:o,onClick:l,children:[a(ne,{className:`h-3 w-3`}),` `,u(`common.retry`)]})]}),t.status===`failed`&&e(`div`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[a(C,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),e(`span`,{children:[u(`detectionIntelligence.photoEnrollDialog.thisPhotoCouldNotBe`,`This photo could not be analysed:`),` `,t.error??u(`detectionIntelligence.photoEnrollDialog.unknownError`,`unknown error`),`. The other photos are unaffected.`]})]}),t.status===`analyzed`&&d.length===0&&a(`p`,{className:`text-xs text-foreground-subtle`,children:u(`detectionIntelligence.photoEnrollDialog.noFacesWereFoundIn`,`No faces were found in this photo. A face has to be reasonably large and facing the camera for the detector to measure it.`)}),d.length>0&&a(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(7rem,7rem))] justify-start gap-3`,children:d.map(e=>a(jn,{face:e,identities:n,value:f[e.faceIndex]??On,disabled:o,onChange:t=>s(e.faceIndex,t)},e.faceIndex))}),d.filter(e=>f[e.faceIndex]===bn).map(n=>e(`div`,{className:`flex items-center gap-2`,children:[a(`span`,{className:`w-28 shrink-0 truncate text-xs text-foreground-subtle`,children:u(`detectionIntelligence.photoEnrollDialog.faceN`,{n:n.faceIndex+1})}),a(`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:u(`detectionIntelligence.photoEnrollDialog.newPersonNameTypeThe`,`New person name… (type the same name under another face to reuse it)`),value:i[_n(t.photoIndex,n.faceIndex)]??``,onChange:e=>c(n.faceIndex,e.target.value)})]},n.faceIndex))]})}function Nn({open:r,onOpenChange:o}){let{t:c}=X(),l=G(),d=u(),f=t(null),{data:p}=We(),m=je(),[h,g]=s([]),[_,v]=s(!1),[y,b]=s(null),[x,S]=s({}),[w,T]=s({}),[E,D]=s(null),O=n(()=>(p??[]).map(e=>({id:e.id,name:e.name})),[p]),k=h.some(e=>e.status===`queued`||e.status===`analyzing`),A=k||_,j=i(e=>{for(let t of e){let e=t.analysis?.sessionId;e!==void 0&&l.trpcClient.addons.custom.mutate({addonId:Yt,action:Qt,input:{sessionId:e}}).catch(()=>void 0)}},[l]),M=i(()=>{g([]),S({}),T({}),b(null),D(null),f.current&&(f.current.value=``)},[]),N=i(()=>{j(h),M(),o(!1)},[j,o,h,M]),P=i(async e=>{let t=cn(await l.trpcClient.addons.custom.mutate({addonId:Yt,action:Xt,input:{photoBase64:e.photoBase64,filename:e.filename}}));if(t===null)throw Error(`the server replied with something this page could not read`);return t},[l]),F=i(async e=>{g(t=>gn(t,e.photoIndex,{status:`analyzing`,error:void 0}));try{let t=await P(e);g(n=>gn(n,e.photoIndex,{status:`analyzed`,analysis:t}))}catch(t){g(n=>gn(n,e.photoIndex,{status:`failed`,error:An(t)}))}},[P]),I=i(async e=>{if(e.length===0)return;j(h),M();let t=mn(e,{maxCount:12,maxBytes:$t}),n=[];t.oversize.length>0&&n.push(`Over the ${Math.round($t/(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 kn(e),status:`queued`})))}catch(e){b(An(e));return}g(r),await hn(r,2,e=>F(e))},[j,h,M,F]),L=yn(h,x),R=i(async()=>{v(!0),b(null),D(null);try{let e=xn(h,x,w);if(e.kind===`error`){b(e.message);return}let t={};for(let n of e.names)t[n]=(await m.mutateAsync({name:n})).id;let n=await En(h,Sn(x,w,t),{enroll:async e=>{let t=ln(await l.trpcClient.addons.custom.mutate({addonId:Yt,action:Zt,input:e}));if(t===null)throw Error(`unreadable reply`);return t},reanalyze:e=>P(e)});Object.keys(n.refreshedAnalyses).length>0&&g(e=>e.map(e=>{let t=n.refreshedAnalyses[e.photoIndex];return t===void 0?e:{...e,status:`analyzed`,analysis:t}})),d.invalidateQueries({queryKey:Dn}),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(An(e))}finally{v(!1)}},[P,m,x,w,h,d,l]),z=h.filter(e=>e.status===`analyzed`).length;return a(rt,{open:r,onOpenChange:e=>e?o(!0):N(),children:e(pt,{className:`max-w-3xl`,children:[e(Ze,{children:[a(Dt,{children:c(`detectionIntelligence.photoEnrollDialog.enrolFromPhotos`,`Enrol from photos`)}),a(lt,{children:c(`detectionIntelligence.photoEnrollDialog.everyPhotoIsAnalysedWith`,`Every photo is analysed with the same face detector the cameras use, and all the faces found are reviewed below in one pass, grouped by photo. Assign each face to a person, or leave it ignored.`)})]}),a(`div`,{className:`rounded-md border border-border bg-surface-hover px-3 py-2 text-xs text-foreground-subtle`,children:a(Lt,{i18nKey:`detectionIntelligence.photoEnrollDialog.reliableRecognition`,components:{strong:a(`strong`,{})}})}),e(`div`,{className:`flex items-center gap-2`,children:[a(`input`,{ref:f,type:`file`,accept:`image/jpeg,image/png,image/webp`,multiple:!0,className:`hidden`,onChange:e=>void I(Array.from(e.target.files??[]))}),e(J,{variant:`secondary`,size:`sm`,disabled:A,onClick:()=>f.current?.click(),children:[k?a(W,{className:`h-3.5 w-3.5 animate-spin`}):a(de,{className:`h-3.5 w-3.5`}),c(`detectionIntelligence.photoEnrollDialog.choosePhotos`,`Choose photos`)]}),h.length>0&&a(`span`,{className:`text-xs text-foreground-subtle`,children:c(`detectionIntelligence.photoEnrollDialog.photosAnalysed`,{done:z,count:h.length})})]}),a(`div`,{className:`min-h-11`,"aria-live":`polite`,children:y===null?E===null?null:a(`div`,{className:`rounded-md border border-success/40 bg-success/10 px-3 py-2 text-xs text-success`,children:E}):e(`div`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[a(C,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),a(`span`,{children:y})]})}),h.length>0&&a(`div`,{className:`max-h-[50vh] space-y-4 overflow-y-auto pr-1`,children:h.map(e=>a(Mn,{photo:e,identities:O,draft:x,newNames:w,disabled:A,onAssign:(t,n)=>S(r=>vn(r,e.photoIndex,t,n===On?null:n)),onNameChange:(t,n)=>T(r=>({...r,[_n(e.photoIndex,t)]:n})),onRetry:()=>void F(e)},e.photoIndex))}),e(ct,{children:[a(J,{variant:`secondary`,onClick:N,disabled:_,children:c(`common.close`,`Close`)}),e(J,{variant:`primary`,onClick:()=>void R(),disabled:A||L===0,children:[_?a(W,{className:`h-3.5 w-3.5 animate-spin`}):null,c(`detectionIntelligence.photoEnrollDialog.enrolFaces`,{count:L})]})]})]})})}l();var Pn=[[`faceGallery`]];function Fn({identityId:t}){let{t:n}=X(),r=u(),{data:i,isLoading:o}=qe({identityId:t}),s=ye();function c(e){s.mutate({identityId:t,sampleId:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:Pn})}})}return o?e(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[a(W,{className:`h-3.5 w-3.5 animate-spin`}),n(`detectionIntelligence.peopleList.loadingSamples`,`Loading samples…`)]}):!i||i.length===0?a(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:n(`detectionIntelligence.peopleList.noSamplesYet`,`No samples yet.`)}):a(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:i.map(t=>e(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[t.base64?a(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:n(`detectionIntelligence.peopleList.sample`,`Sample`),className:`h-full w-full object-cover`}):a(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:a(_e,{className:`h-6 w-6`})}),t.source===`photo`&&a(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 p-0.5 text-white`,title:n(`detectionIntelligence.peopleList.enrolledFromAnUploadedPhoto`,`Enrolled from an uploaded photo`),children:a(de,{className:`h-3 w-3`})}),a(`button`,{type:`button`,onClick:()=>c(t),disabled:s.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":n(`detectionIntelligence.peopleList.removeSample`,`Remove sample`),children:a(L,{className:`h-4 w-4 text-white`})})]},t.id))})}function In(t){return[{key:`person`,header:Y.t(`detectionIntelligence.peopleList.person`,`Person`),sortValue:e=>e.name,render:t=>e(`span`,{className:`flex min-w-0 items-center gap-2`,children:[a(`span`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:a(Jt,{mediaId:t.coverMediaId,base64:t.coverBase64,alt:t.name,className:`h-full w-full object-cover`,placeholder:a(`span`,{className:`flex h-full w-full items-center justify-center`,children:a(_e,{className:`h-4 w-4 text-foreground-subtle`})})})}),a(`span`,{className:`truncate text-sm font-medium text-foreground`,children:t.name})]})},{key:`samples`,header:Y.t(`detectionIntelligence.peopleList.samples`,`Samples`),align:`center`,nowrap:!0,sortValue:e=>e.sampleCount,render:e=>a(Pe,{variant:`default`,className:`text-[10px]`,children:e.sampleCount})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:n=>e(`span`,{className:`flex items-center justify-end gap-1`,children:[a(be,{variant:`ghost`,size:`sm`,icon:y,"aria-label":Y.t(`detectionIntelligence.peopleList.edit`,`Edit {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onEdit(n)}}),a(be,{variant:`ghost`,size:`sm`,icon:x,"aria-label":Y.t(`detectionIntelligence.peopleList.delete`,`Delete {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onDelete(n)}})]})}]}function Ln({mode:t,identity:n,onClose:r}){let{t:i}=X(),c=u(),[l,d]=s(t===`edit`?n?.name??``:``),f=je(),p=tt();o(()=>{d(t===`edit`?n?.name??``:``)},[t,n?.id,n?.name]);let m=f.isPending||p.isPending,h=l.trim(),g=t===`edit`&&n!==null&&h===n.name,_=m||h.length===0||g;function v(){c.invalidateQueries({queryKey:Pn})}function y(){if(!_){if(t===`new`){f.mutate({name:h},{onSuccess:()=>{v(),r()}});return}if(n===null){r();return}p.mutate({id:n.id,name:h},{onSuccess:()=>{v(),r()}})}}return a(ut,{open:!0,onClose:r,title:t===`new`?`Add person`:`Edit ${n?.name??`person`}`,icon:_e,width:t===`edit`?`xl`:`lg`,testId:`people-person-form`,footer:e(J,{variant:`primary`,size:`sm`,type:`button`,onClick:y,disabled:_,children:[m?a(W,{className:`h-3.5 w-3.5 animate-spin`}):null,t===`new`?i(`common.add`,`Add`):i(`common.save`,`Save`)]}),children:e(`div`,{className:`space-y-4`,children:[a(Re,{label:i(`detectionIntelligence.peopleList.name`,`Name`),required:!0,children:a(Fe,{value:l,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&y()},placeholder:i(`detectionIntelligence.peopleList.personName`,`Person name…`),autoFocus:!0})}),t===`edit`&&n!==null&&e(`div`,{children:[a(`p`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:i(`detectionIntelligence.peopleList.trainingSamples`,`Training samples`)}),a(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:i(`detectionIntelligence.peopleList.removeASampleToDrop`,`Remove a sample to drop it from recognition training for this person.`)}),a(Fn,{identityId:n.id})]})]})})}function Rn(){let{t}=X(),r=u(),i=Be(),{data:c,isLoading:l}=We(),d=ke(),{state:f,openNew:p,openEdit:m,close:h}=vt(),[g,_]=s(!1),v=c??[],y=_t(v,{searchText:e=>[e.name]}),b=f.mode===`edit`?v.find(e=>e.id===f.id)??null:null;o(()=>{f.mode===`edit`&&!l&&b===null&&h()},[f.mode,l,b,h]);let x=n(()=>In({onEdit:e=>m(e.id),onDelete:e=>{(async()=>{await i({title:t(`detectionIntelligence.peopleList.deletePerson`,`Delete person`),message:t(`detectionIntelligence.peopleList.deleteAndAllTheirSamples`,`Delete {{name}} and all their samples? This cannot be undone.`,{name:e.name}),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&d.mutate({id:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:Pn}),f.mode===`edit`&&f.id===e.id&&h()}})})()}}),[i,h,d,f,m,r,t]);if(l)return e(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[a(W,{className:`h-4 w-4 animate-spin`}),t(`detectionIntelligence.peopleList.loadingPeople`,`Loading people…`)]});let S=f.mode===`new`||f.mode===`edit`&&b!==null;return e(`div`,{className:`space-y-2`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(J,{variant:`primary`,size:`sm`,type:`button`,onClick:p,children:[a(V,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.peopleList.addPerson`,`Add person`)]}),e(J,{variant:`secondary`,size:`sm`,type:`button`,onClick:()=>_(!0),children:[a(de,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.peopleList.enrolFromAPhoto`,`Enrol from a photo`)]})]}),(v.length>0||y.active)&&a(ft,{state:y.state,facets:y.facets,labels:{searchPlaceholder:`Search people…`,searchLabel:`Search people`,facetsLabel:`Filter`,clearLabel:`Clear`},onSearch:y.setSearch,onToggleFacet:y.toggleFacet,onClear:y.clear}),y.rows.length===0?a(we,{icon:_e,title:y.active?t(`detectionIntelligence.peopleList.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.peopleList.noPeopleEnrolledYet`,`No people enrolled yet`),description:y.active?t(`detectionIntelligence.peopleList.clearTheSearchOrTry`,`Clear the search or try another name.`):t(`detectionIntelligence.peopleList.addAPersonOrEnrol`,`Add a person, or enrol faces from a photo.`)}):a(Se,{columns:x,rows:y.rows,rowKey:e=>e.id,maxBodyHeight:kt,emptyMessage:t(`detectionIntelligence.peopleList.noPeopleEnrolledYet2`,`No people enrolled yet.`),onRowClick:e=>m(e.id)}),S&&a(Ln,{mode:f.mode===`new`?`new`:`edit`,identity:b,onClose:h}),a(Nn,{open:g,onOpenChange:_})]})}var zn={fromMs:null,toMs:null},Bn=36e5,Vn=24*Bn;function Hn(e,t){switch(e){case`24h`:return{fromMs:t-Vn,toMs:null};case`7d`:return{fromMs:t-7*Vn,toMs:null};case`30d`:return{fromMs:t-30*Vn,toMs:null};case`all`:return zn}}function Un(e){return e.fromMs!==null||e.toMs!==null}function Wn(e,t){return Un(t)?e.filter(e=>!(t.fromMs!==null&&e.timestamp<t.fromMs||t.toMs!==null&&e.timestamp>t.toMs)):[...e]}function Gn(e,t){return t.size===0?[...e]:e.filter(e=>t.has(e.deviceId))}function Kn(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 qn(e){if(!e)return null;let t=Date.parse(`${e}T00:00:00`);return Number.isNaN(t)?null:t}function Jn(e){if(!e)return null;let t=Date.parse(`${e}T23:59:59.999`);return Number.isNaN(t)?null:t}function Yn(e,t){if(!Number.isFinite(e)||e<=0)return`—`;let n=t-e;return n<6e4?Y.t(`helpers.relativeTime.justNow`):n<Bn?Y.t(`helpers.relativeTime.minutesAgo`,{count:Math.floor(n/6e4)}):n<Vn?Y.t(`helpers.relativeTime.hoursAgo`,{count:Math.floor(n/Bn)}):n<7*Vn?Y.t(`helpers.relativeTime.daysAgo`,{count:Math.floor(n/Vn)}):new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function Xn(e){return!Number.isFinite(e)||e<=0?`—`:new Date(e).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function Zn(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 Qn(e){let t=e.cropUrl!==void 0&&e.cropUrl.length>0,n=e.base64!==void 0&&e.base64.length>0;return!t&&!n}function $n(e){return e.filter(Qn).map(e=>e.faceId)}function er(e){let t=0;for(let n of e)Qn(n)&&(t+=1);return t}function tr(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}l();function nr(e,t,r){let[i,a]=s(1);o(()=>{a(1)},[r]);let c=e.length,l=Math.max(1,Math.ceil(c/t)),u=Math.min(i,l);return o(()=>{u!==i&&a(u)},[u,i]),{page:u,setPage:a,pageItems:n(()=>{let n=(u-1)*t;return e.slice(n,n+t)},[e,u,t]),totalPages:l,totalItems:c,pageSize:t}}var rr=2;function ir(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-rr),i=Math.min(t-1,e+rr);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 ar({currentPage:t,totalItems:n,pageSize:r,onPageChange:i,itemNoun:o=`items`}){let{t:s}=X();if(n<=r)return null;let c=Math.ceil(n/r),l=(t-1)*r+1,u=Math.min(t*r,n),d=ir(t,c),f=`inline-flex h-7 min-w-7 items-center justify-center rounded-md px-2 text-[11px] transition-colors disabled:opacity-40`;return e(`div`,{className:`flex items-center justify-between gap-4 flex-wrap pt-2 text-[11px] text-foreground-subtle`,children:[a(`span`,{children:s(`galleryPager.showing`,{from:l,to:u,total:n,noun:o})}),e(`div`,{className:`flex items-center gap-1`,children:[a(`button`,{type:`button`,className:`${f} hover:bg-surface-hover`,onClick:()=>i(t-1),disabled:t<=1,"aria-label":s(`galleryPager.previousPage`,`Previous page`),children:a(P,{className:`h-3.5 w-3.5`})}),d.map(e=>e.kind===`ellipsis`?a(`span`,{className:`px-1 opacity-60`,children:`…`},`ellipsis-${e.side}`):a(`button`,{type:`button`,className:`${f} ${e.n===t?`bg-primary/12 text-primary font-medium`:`hover:bg-surface-hover hover:text-foreground`}`,onClick:()=>i(e.n),"aria-current":e.n===t?`page`:void 0,children:e.n},e.n)),a(`button`,{type:`button`,className:`${f} hover:bg-surface-hover`,onClick:()=>i(t+1),disabled:t>=c,"aria-label":s(`galleryPager.nextPage`,`Next page`),children:a(re,{className:`h-3.5 w-3.5`})})]})]})}l();var or=[[`faceGallery`]];function sr({faceIds:t,identities:n,onDone:r}){let{t:i}=X(),o=u(),c=De(),l=je(),[d,f]=s(``),[p,m]=s(!1),[h,g]=s(null),_=t!==null&&t.length>0,v=t?.length??0;function y(){m(!1),f(``),g(null)}function b(){y(),r()}function x(e){!t||t.length===0||c.mutate({faceIds:[...t],identityId:e},{onSettled:()=>{o.invalidateQueries({queryKey:or}),b()}})}function S(){!t||!d.trim()||l.mutate({name:d.trim()},{onSuccess:e=>{e?.id&&x(e.id)},onError:()=>{o.invalidateQueries({queryKey:or}),b()}})}let C=c.isPending||l.isPending;return a(rt,{open:_,onOpenChange:e=>!e&&b(),children:e(pt,{children:[e(Ze,{children:[a(Dt,{children:v>1?i(`detectionIntelligence.assignDialog.assignFacesToPerson`,`Assign {{value1}} faces to person`,{value1:String(v)}):i(`detectionIntelligence.assignDialog.assignFaceToPerson`,`Assign face to person`)}),a(lt,{children:i(`detectionIntelligence.assignDialog.selectAnExistingPersonOr`,`Select an existing person or create a new one.`)})]}),a(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:n.map(t=>e(`button`,{type:`button`,onClick:()=>g(t.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${h===t.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[a(`span`,{className:`font-medium`,children:t.name}),a(`span`,{className:`ml-2 text-foreground-subtle`,children:i(`detectionIntelligence.assignDialog.samples`,{count:t.sampleCount})})]},t.id))}),a(`div`,{className:`min-h-[2.75rem] border-t border-border pt-2`,children:p?a(`div`,{className:`flex items-center gap-2`,children:a(Fe,{placeholder:i(`detectionIntelligence.assignDialog.newPersonName`,`New person name…`),value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&S()},autoFocus:!0,className:`flex-1`})}):a(`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…`)})}),e(ct,{className:`min-h-[2.75rem]`,children:[a(J,{variant:`secondary`,onClick:b,disabled:C,children:i(`common.cancel`,`Cancel`)}),p?e(J,{variant:`primary`,onClick:S,disabled:C||!d.trim(),children:[C&&a(W,{className:`h-3.5 w-3.5 animate-spin`}),i(`detectionIntelligence.assignDialog.createAssign`,`Create & assign`)]}):e(J,{variant:`primary`,onClick:()=>h&&x(h),disabled:C||!h,children:[C&&a(W,{className:`h-3.5 w-3.5 animate-spin`}),v>1?i(`detectionIntelligence.assignCount`,{count:v}):i(`common.assign`)]})]})]})})}l();function cr({cameras:n,selected:r,onChange:i}){let{t:c}=X(),[l,u]=s(!1),d=t(null);o(()=>{if(!l)return;function e(e){d.current&&e.target instanceof Node&&!d.current.contains(e.target)&&u(!1)}function t(e){e.key===`Escape`&&u(!1)}return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[l]);function f(e){let t=new Set(r);t.has(e)?t.delete(e):t.add(e),i(t)}let p=r.size,m=p===0?`All cameras`:p===1?n.find(e=>r.has(e.id))?.name??`1 camera`:`${String(p)} cameras`;return e(`div`,{ref:d,className:`relative`,children:[e(`button`,{type:`button`,onClick:()=>u(e=>!e),disabled:n.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:[a(h,{className:`h-3.5 w-3.5`}),a(`span`,{className:`max-w-[10rem] truncate`,children:m}),a(K,{className:`h-3 w-3 opacity-70`})]}),l&&e(`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&&a(`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:c(`detectionIntelligence.cameraMultiSelect.clearSelection`,`Clear selection`)}),n.map(t=>{let n=r.has(t.id);return e(`button`,{type:`button`,onClick:()=>f(t.id),className:`flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-xs transition-colors ${n?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[a(`span`,{className:`flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded-sm border ${n?`border-primary bg-primary text-white`:`border-border`}`,children:n&&a(T,{className:`h-2.5 w-2.5`})}),a(`span`,{className:`truncate`,children:t.name})]},t.id)})]})]})}l();var lr=[{label:`24h`,value:`24h`},{label:`7d`,value:`7d`},{label:`30d`,value:`30d`},{labelKey:`common.all`,value:`all`}];function ur({onChange:t}){let{t:n}=X(),[r,i]=s(`all`),[o,c]=s(``),[l,u]=s(``);function d(e){i(e),c(``),u(``),t(Hn(e,Date.now()))}function f(e,n){i(`custom`),c(e),u(n),t({fromMs:qn(e),toMs:Jn(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 e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[a(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:lr.map(e=>a(`button`,{type:`button`,onClick:()=>d(e.value),className:`rounded px-2.5 py-1 text-[11px] transition-colors ${r===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.labelKey===void 0?e.label:n(e.labelKey)},e.value))}),e(`div`,{className:`flex items-center gap-1`,children:[a(`input`,{type:`date`,"aria-label":n(`detectionIntelligence.dateRangeFilter.fromDate`,`From date`),value:o,max:l||void 0,onChange:e=>f(e.target.value,l),className:`${p} ${r===`custom`&&o?`border-primary/50`:``}`}),a(`span`,{className:`text-[11px] text-foreground-subtle`,children:`→`}),a(`input`,{type:`date`,"aria-label":n(`detectionIntelligence.dateRangeFilter.toDate`,`To date`),value:l,min:o||void 0,onChange:e=>f(o,e.target.value),className:`${p} ${r===`custom`&&l?`border-primary/50`:``}`})]})]})}function dr(e){return e<0?0:e>1?1:e}function fr(e,t,n){if(!Number.isFinite(t)||!Number.isFinite(n)||t<=0||n<=0)return null;let r=dr(e.x/t),i=dr(e.y/n),a=dr((e.x+e.w)/t),o=dr((e.y+e.h)/n);return{x:r,y:i,width:Math.max(0,a-r),height:Math.max(0,o-i)}}l();var pr=2.6;function mr({src:t,alt:n,className:r,overlay:i,fit:c=`contain`}){let[l,u]=s(!1),[d,f]=s(`50% 50%`);o(()=>{u(!1),f(`50% 50%`)},[t]);function p(e){if(!l){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)}%`)}u(e=>!e)}let m=c===`natural`;return a(`div`,{className:`relative overflow-hidden bg-background ${r??``}`,onClick:p,children:e(`div`,{className:`relative select-none transition-transform duration-200 ease-out ${m?`w-full`:`h-full w-full`} ${l?`cursor-zoom-out`:`cursor-zoom-in`}`,style:{transformOrigin:d,transform:l?`scale(${String(pr)})`:`scale(1)`},children:[a(`img`,{src:t,alt:n,draggable:!1,className:m?`block h-auto w-full object-contain`:`h-full w-full object-contain`}),i]})})}l();function hr(e){let[t,n]=s(null),[r,i]=s(null),[a,c]=s(!1);return o(()=>{if(n(null),i(null),c(!1),e===void 0)return;let t=!1,r=null;return(async()=>{try{let i=await Wt(Gt(e));if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||c(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),o(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>c(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function gr(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 _r({label:t,value:n}){return e(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[a(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:t}),a(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground`,children:n})]})}function vr({box:e}){let{t}=X();return a(`div`,{className:`pointer-events-none absolute rounded-[3px] border-2 border-primary shadow-[0_0_0_9999px_rgba(0,0,0,0.28)]`,style:{left:`${String(e.x*100)}%`,top:`${String(e.y*100)}%`,width:`${String(e.width*100)}%`,height:`${String(e.height*100)}%`},children:a(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:t(`detectionIntelligence.faceDetailPanel.face`,`Face`)})})}function yr({face:t,cameraName:r,onClose:i,onAssign:o,onUnassign:c,onDelete:l,actionsPending:u}){let{t:d}=X(),{data:f,isFetching:p}=Ke({faceId:t?.faceId??``},{enabled:t!==null}),[m,h]=s(`frame`),{frameSrc:g,naturalWidth:v,naturalHeight:y,failed:b}=hr(t?.keyFrameMediaId),S=n(()=>{let e=gr(f??[]);return e?e.url:tr(t)},[f,t]),C=n(()=>!t?.faceBbox||v===null||y===null?null:fr(t.faceBbox,v,y),[t?.faceBbox,v,y]);if(t===null)return null;let w=t.keyFrameMediaId!==void 0&&!b,T=w&&m===`frame`,E=t.assigned?t.identityName??`Assigned`:t.recognizedIdentityId?`${t.identityName??`Recognized`} (suggested)`:`Unassigned`;return a(rt,{open:!0,onOpenChange:e=>!e&&i(),children:e(pt,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":d(`detectionIntelligence.faceDetailPanel.faceDetail`,`Face detail`),className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[a(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:e(`div`,{className:`min-w-0`,children:[a(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:d(`detectionIntelligence.faceDetailPanel.faceDetail`,`Face detail`)}),a(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:r})]})}),e(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[w&&e(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[e(`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:[a(U,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.fullFrame`)]}),e(`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:[a(ge,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.crop`)]})]}),T&&g?a(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:a(mr,{src:g,alt:d(`detectionIntelligence.faceDetailPanel.fullFrameWithDetectedFace`,`Full frame with detected face`),fit:`natural`,className:`w-full`,overlay:C?a(vr,{box:C}):void 0})}):S?e(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[a(mr,{src:S,alt:d(`detectionIntelligence.faceDetailPanel.detectedFace`,`Detected face`),className:`h-full w-full`}),p&&a(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:a(W,{className:`h-3.5 w-3.5 animate-spin`})})]}):e(`div`,{className:`flex aspect-square w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[a(M,{className:`h-8 w-8 text-warning/70`}),a(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:d(`detectionIntelligence.faceDetailPanel.noImage`,`No image`)}),a(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:d(`detectionIntelligence.faceDetailPanel.theCropMediaForThis`,`The crop media for this face could not be resolved (a pre-fix orphan). Safe to delete.`)})]}),e(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[a(_r,{label:d(`detectionIntelligence.faceDetailPanel.camera`,`Camera`),value:r}),a(_r,{label:d(`detectionIntelligence.faceDetailPanel.captured`,`Captured`),value:Zn(t.timestamp)}),a(_r,{label:d(`detectionIntelligence.faceDetailPanel.track`,`Track`),value:t.trackId}),a(_r,{label:d(`detectionIntelligence.faceDetailPanel.identity`,`Identity`),value:E})]})]}),e(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[t.assigned?e(J,{variant:`secondary`,onClick:()=>c(t.faceId),disabled:u,children:[a(me,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.detach`)]}):e(J,{variant:`primary`,onClick:()=>o(t.faceId),disabled:u,children:[a(_,{className:`h-3.5 w-3.5`}),` `,d(`common.assign`)]}),e(J,{variant:`secondary`,onClick:()=>l(t.faceId),disabled:u,children:[a(x,{className:`h-3.5 w-3.5`}),` `,d(`common.delete`)]})]})]})})}function br(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function xr(e,t){return e.faceIds.filter(e=>!t.has(e))}function Sr(e,t){return e.faceIds.filter(e=>t(e))}l();var Cr=[[`faceGallery`]],wr=20,Tr=.3,Er=.9,Dr=.05,Or=.5,kr=2,Ar=10,jr=2;function Mr({cluster:t,face:n,active:r,onSelect:i}){let{t:o}=X(),s=tr(n);return e(`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 ${r?`border-primary bg-primary/8`:`border-border bg-surface hover:bg-surface-hover`}`,children:[a(`div`,{className:`h-24 w-24 shrink-0 overflow-hidden rounded bg-surface-hover`,children:s===null?a(M,{className:`h-24 w-24 p-6 text-foreground-subtle`}):a(`img`,{src:s,alt:``,loading:`lazy`,decoding:`async`,className:`h-24 w-24 object-cover`})}),a(`span`,{className:`w-24 text-[11px] leading-tight text-foreground-subtle md:w-auto`,children:o(`detectionIntelligence.similarGroupsModal.clusterMeta`,{count:t.size,percent:Math.round(t.cohesion*100)})})]})}function Nr({face:t,cameraName:n,nowMs:r,excluded:i,onToggleExclude:o,onDelete:s,deletePending:c}){let{t:l}=X(),u=tr(t);return e(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden transition-opacity ${i?`border-border opacity-40 grayscale`:`border-border`}`,children:[e(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[u===null?e(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,children:[a(M,{className:`h-7 w-7 text-warning/70`}),a(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:l(`detectionIntelligence.similarGroupsModal.noCrop`,`No crop`)})]}):a(mr,{src:u,alt:l(`detectionIntelligence.similarGroupsModal.faceFrom`,`Face from {{cameraName}}`,{cameraName:n}),className:`h-full w-full`}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o()},className:`absolute right-1 top-1 z-10 rounded-full bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?l(`detectionIntelligence.similarGroupsModal.includeFace`,`Include face`):l(`detectionIntelligence.similarGroupsModal.excludeFace`,`Exclude face`),title:i?l(`detectionIntelligence.similarGroupsModal.include`,`Include`):l(`detectionIntelligence.similarGroupsModal.exclude`,`Exclude`),children:a(i?p:L,{className:`h-3.5 w-3.5`})})]}),e(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[a(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:n,children:n}),a(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:Yn(t.timestamp,r)})]}),a(`div`,{className:`mt-1 flex min-h-[2rem] items-center justify-end border-t border-border/60 px-1 py-0.5`,children:a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s()},disabled:c,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":l(`detectionIntelligence.similarGroupsModal.deleteFace`,`Delete face`),title:l(`detectionIntelligence.similarGroupsModal.deleteFace`,`Delete face`),children:c?a(W,{className:`h-4 w-4 animate-spin`}):a(x,{className:`h-4 w-4`})})})]})}function Pr({open:t,onClose:r,byId:i,cameraName:c,nowMs:l,identities:f,selectMany:p}){let{t:m}=X(),h=u(),g=Be(),v=yt(),[y,b]=s(Or),[x,S]=s(jr),[C,w]=s(null),[T,E]=s({}),[D,O]=s(null),{data:k,isFetching:A,refetch:M}=Ct({threshold:y,minClusterSize:x,limit:wr},{enabled:t}),N=k??[];o(()=>{E({})},[y,x]),o(()=>{if(N.length===0){w(null);return}N.some(e=>e.representativeFaceId===C)||w(N[0]?.representativeFaceId??null)},[N]);let P=n(()=>N.find(e=>e.representativeFaceId===C)??null,[N,C]),I=P?T[P.representativeFaceId]??new Set:new Set,L=n(()=>P?Sr(P,e=>i.has(e)):[],[P,i]),R=P?P.faceIds.length-L.length:0,z=P?xr({...P,faceIds:L},I):[];function B(e){if(!P)return;let t=P.representativeFaceId;E(n=>({...n,[t]:br(n[t]??new Set,e)}))}function V(){h.invalidateQueries({queryKey:Cr})}async function H(e){await g({title:m(`detectionIntelligence.similarGroupsModal.deleteFace`,`Delete face`),message:m(`detectionIntelligence.similarGroupsModal.permanentlyDeletesThisFaceCrop`,`Permanently deletes this face crop. This cannot be undone.`),confirmLabel:m(`common.delete`,`Delete`),variant:`danger`})&&v.mutate({faceId:e},{onSettled:V})}function U(){O(null),r()}function G(){z.length!==0&&(p(z),U())}return e(rt,{open:t,onOpenChange:e=>!e&&U(),children:[e(pt,{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:[e(`header`,{className:`flex shrink-0 flex-col gap-2 border-b border-border py-3 pl-4 pr-10`,children:[e(`div`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[a(j,{className:`h-4 w-4 text-primary`}),` `,m(`detectionIntelligence.similarGroupsModal.title`)]}),e(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[e(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[m(`detectionIntelligence.similarGroupsModal.threshold`,`Threshold`),a(`input`,{type:`range`,min:Tr,max:Er,step:Dr,value:y,onChange:e=>b(Number(e.target.value)),className:`h-1.5 w-28 cursor-pointer accent-primary`}),a(`span`,{className:`w-8 shrink-0 text-right font-mono text-[11px] tabular-nums text-foreground`,children:y.toFixed(2)})]}),e(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[m(`detectionIntelligence.similarGroupsModal.minSize`,`Min size`),a(`input`,{type:`number`,min:kr,max:Ar,step:1,value:x,onChange:e=>S(Math.min(Ar,Math.max(kr,Number(e.target.value)||kr))),className:`w-12 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`})]}),e(J,{variant:`secondary`,onClick:()=>{E({}),M()},disabled:A,children:[A?a(W,{className:`h-3.5 w-3.5 animate-spin`}):a(F,{className:`h-3.5 w-3.5`}),m(`detectionIntelligence.similarGroupsModal.reAnalyze`,`Re-analyze`)]})]})]}),a(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-hidden px-4 py-3 md:flex-row`,children:A&&N.length===0?e(`div`,{className:`flex flex-1 items-center justify-center gap-2 py-8 text-xs text-foreground-subtle`,children:[a(W,{className:`h-4 w-4 animate-spin`}),` `,m(`detectionIntelligence.similarGroupsModal.finding`)]}):N.length===0?a(`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.`)}):e(d,{children:[a(`div`,{className:`flex gap-2 overflow-x-auto pb-1 md:hidden`,children:N.map(e=>a(Mr,{cluster:e,face:i.get(e.representativeFaceId),active:e.representativeFaceId===C,onSelect:()=>w(e.representativeFaceId)},e.representativeFaceId))}),a(`div`,{className:`hidden shrink-0 flex-col gap-2 overflow-y-auto md:flex md:w-56`,children:N.map(e=>a(Mr,{cluster:e,face:i.get(e.representativeFaceId),active:e.representativeFaceId===C,onSelect:()=>w(e.representativeFaceId)},e.representativeFaceId))}),a(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:P&&e(d,{children:[R>0&&a(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:m(`detectionIntelligence.similarGroupsModal.hiddenCount`,{count:R})}),a(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(13rem,13rem))] justify-start gap-2`,children:L.map(e=>{let t=i.get(e);return t?a(Nr,{face:t,cameraName:c(t.deviceId),nowMs:l,excluded:I.has(e),onToggleExclude:()=>B(e),onDelete:()=>void H(e),deletePending:v.isPending&&v.variables?.faceId===e},e):null})})]})})]})}),e(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[a(J,{variant:`secondary`,onClick:G,disabled:z.length===0,children:m(`detectionIntelligence.similarGroupsModal.selectInGallery`,`Select in gallery`)}),e(J,{variant:`primary`,onClick:()=>O(z),disabled:z.length===0,children:[a(_,{className:`h-3.5 w-3.5`}),` `,m(`detectionIntelligence.similarGroupsModal.adopt`,{count:z.length})]})]})]}),a(sr,{faceIds:D,identities:f,onDone:()=>O(null)})]})}l();var Fr=[[`faceGallery`]],Ir=500,Lr=120;function Rr({face:t,cameraName:n,nowMs:r,selected:i,onToggleSelect:o,onAssign:s,onOpenDetail:c}){let{t:l}=X(),d=u(),f=ht(),p=yt(),m=()=>{d.invalidateQueries({queryKey:Fr})},h=()=>c(t.faceId),g=tr(t);return e(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[e(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[g===null?e(`button`,{type:`button`,onClick:h,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:l(`detectionIntelligence.unassignedFaces.noCropImageTheFace`,`No crop image — the face's crop media is missing (a pre-fix orphan). Safe to delete.`),children:[a(M,{className:`h-7 w-7 text-warning/70`}),a(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:l(`detectionIntelligence.unassignedFaces.noCrop`,`No crop`)})]}):a(`img`,{src:g,alt:l(`detectionIntelligence.unassignedFaces.faceFrom`,`Face from {{cameraName}}`,{cameraName:n}),onClick:h,loading:`lazy`,decoding:`async`,className:`h-full w-full cursor-zoom-in object-cover`}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(t.faceId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?l(`detectionIntelligence.unassignedFaces.deselect`,`Deselect`):l(`detectionIntelligence.unassignedFaces.select`,`Select`),children:i?a(fe,{className:`h-4 w-4 text-primary`}):a(O,{className:`h-4 w-4`})})]}),e(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[a(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:n,children:n}),a(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:Yn(t.timestamp,r)}),a(`p`,{className:`min-h-[0.875rem] truncate text-[10px] font-medium leading-tight ${t.identityName?`text-primary`:`invisible`}`,title:t.identityName,children:t.identityName??`\xA0`})]}),e(`div`,{className:`mt-1 flex min-h-[2rem] items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[t.assigned?a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),f.mutate({faceId:t.faceId},{onSettled:m})},disabled:f.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":l(`detectionIntelligence.unassignedFaces.detachFace`,`Detach face`),title:l(`detectionIntelligence.unassignedFaces.detach`,`Detach`),children:f.isPending?a(W,{className:`h-4 w-4 animate-spin`}):a(me,{className:`h-4 w-4`})}):a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s(t.faceId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":l(`detectionIntelligence.unassignedFaces.assignFaceToPerson`,`Assign face to person`),title:l(`detectionIntelligence.unassignedFaces.assignToPerson`,`Assign to person`),children:a(_,{className:`h-4 w-4`})}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),p.mutate({faceId:t.faceId},{onSettled:m})},disabled:p.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":l(`detectionIntelligence.unassignedFaces.deleteFace`,`Delete face`),title:l(`detectionIntelligence.unassignedFaces.deleteFace`,`Delete face`),children:p.isPending?a(W,{className:`h-4 w-4 animate-spin`}):a(x,{className:`h-4 w-4`})})]})]})}var zr=[{labelKey:`common.all`,value:`all`},{labelKey:`detectionIntelligence.unassignedFaces.filterUnassigned`,value:`unassigned`},{labelKey:`detectionIntelligence.unassignedFaces.filterRecognized`,value:`recognized`}];function Br(){let{t}=X(),r=u(),[i,o]=s(`all`),[c,l]=s(zn),[f,p]=s(new Set),[m,h]=s(new Set),[g,v]=s(null),[y,b]=s(!1),[S,C]=s(null),{data:w,isLoading:T}=Ne({limit:Ir,filter:i,includeCrops:!1},{refetchInterval:3e4}),{data:E=[]}=We(),{data:D}=et({isCamera:!0,projection:`slim`}),O=De(),k=ht(),A=xt(),N=yt(),P=Date.now(),F=w??[],I=n(()=>{let e=new Map;for(let t of D??[])e.set(t.id,t.name);return e},[D]),R=e=>I.get(e)??t(`detectionIntelligence.cameraFallback`,{id:String(e)}),z=n(()=>Kn(F).map(e=>({id:e,name:R(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[F,I]),B=n(()=>Gn(Wn(F,c),f),[F,c,f]),V=nr(B,Lr,n(()=>JSON.stringify([i,c.fromMs,c.toMs,[...f].sort((e,t)=>e-t)]),[i,c.fromMs,c.toMs,f])),H=n(()=>new Map(F.map(e=>[e.faceId,e])),[F]),U=n(()=>er(B),[B]),G=S===null?null:H.get(S)??null,ee=()=>{r.invalidateQueries({queryKey:Fr})},te=()=>h(new Set);function ne(e){h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function K(e){h(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function re(){K($n(B))}let ie=[...m],q=O.isPending||A.isPending||N.isPending,ae=k.isPending||N.isPending;function oe(){ie.length!==0&&A.mutate({faceIds:ie},{onSettled:()=>{ee(),te()}})}function se(){ie.length!==0&&Promise.allSettled(ie.map(e=>N.mutateAsync({faceId:e}))).then(()=>{ee(),te()})}function ce(e){C(null),v([e])}function le(e){k.mutate({faceId:e},{onSettled:ee}),C(null)}function ue(e){N.mutate({faceId:e},{onSettled:ee}),C(null)}let de=B.length!==F.length;return e(`div`,{className:`relative space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[a(`div`,{className:`flex items-center gap-1`,children:zr.map(e=>a(`button`,{type:`button`,onClick:()=>o(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${i===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:t(e.labelKey)},e.value))}),a(ur,{onChange:l}),a(cr,{cameras:z,selected:f,onChange:p}),e(`button`,{type:`button`,onClick:()=>b(!0),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${y?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(j,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.similarGroups`)]}),!T&&U>0&&e(`button`,{type:`button`,onClick:re,className:`ml-auto flex items-center gap-1 rounded-md px-2.5 py-1 text-xs text-warning/90 transition-colors hover:bg-warning/10`,title:t(`detectionIntelligence.unassignedFaces.selectEveryVisibleFaceWhose`,`Select every visible face whose crop image is missing so you can delete the orphans in one pass`),children:[a(M,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.selectCropless`,{count:U})]}),!T&&a(`span`,{className:`text-[10px] text-foreground-subtle ${U>0?`ml-2`:`ml-auto`}`,children:de?t(`detectionIntelligence.unassignedFaces.ofFaces`,`{{value1}} of {{value2}} faces`,{value1:String(B.length),value2:String(F.length)}):t(`detectionIntelligence.unassignedFaces.faceCount`,{count:B.length})})]}),m.size>0&&e(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[a(`span`,{className:`text-xs font-medium text-foreground`,children:t(`common.selectedCount`,{count:m.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[e(J,{variant:`primary`,onClick:()=>v(ie),disabled:q,children:[a(_,{className:`h-3.5 w-3.5`}),` `,t(`common.assign`)]}),e(J,{variant:`secondary`,onClick:oe,disabled:q,children:[A.isPending?a(W,{className:`h-3.5 w-3.5 animate-spin`}):a(me,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.detach`,`Detach`)]}),e(J,{variant:`secondary`,onClick:se,disabled:q,children:[a(x,{className:`h-3.5 w-3.5`}),` `,t(`common.delete`)]}),a(J,{variant:`ghost`,onClick:te,disabled:q,children:a(L,{className:`h-3.5 w-3.5`})})]})]}),T?a(it,{status:`pending`,pendingMessage:`Loading faces…`,testId:`faces-grid`}):B.length===0?a(we,{icon:M,title:F.length>0?t(`detectionIntelligence.unassignedFaces.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.unassignedFaces.noFacesFoundForThis`,`No faces found for this filter`),description:F.length>0?t(`detectionIntelligence.unassignedFaces.widenTheDateRangeOr`,`Widen the date range or clear the camera filter.`):t(`detectionIntelligence.unassignedFaces.faceCropsAppearHereWhen`,`Face crops appear here when the detection pipeline captures them.`)}):e(d,{children:[a(it,{status:`ready`,testId:`faces-grid`,className:`grid-cols-[repeat(auto-fill,minmax(6.5rem,6.5rem))] justify-start`,children:V.pageItems.map(e=>a(Rr,{face:e,cameraName:R(e.deviceId),nowMs:P,selected:m.has(e.faceId),onToggleSelect:ne,onAssign:e=>v([e]),onOpenDetail:C},e.faceId))}),a(ar,{currentPage:V.page,totalItems:V.totalItems,pageSize:V.pageSize,onPageChange:V.setPage,itemNoun:`faces`})]}),a(yr,{face:G,cameraName:G?R(G.deviceId):``,onClose:()=>C(null),onAssign:ce,onUnassign:le,onDelete:ue,actionsPending:ae}),a(sr,{faceIds:g,identities:E,onDone:()=>{v(null),te()}}),a(Pr,{open:y,onClose:()=>b(!1),byId:H,cameraName:R,nowMs:P,identities:E,selectMany:K})]})}function Vr(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}}l();var Hr=[[`faceGallery`]],Ur=2e3;function Wr(){let e=u(),n=t(e);n.current=e;let r=t(void 0);r.current||=Vr({delayMs:Ur,invalidate:()=>{n.current.invalidateQueries({queryKey:Hr})}}),o(()=>()=>r.current?.cancel(),[]),Ye(q.PipelineAnalyticsFaceGalleryChanged,()=>{r.current?.trigger()})}function Gr(){let{t}=X();return Wr(),e(`div`,{className:`space-y-3`,children:[a(jt,{headingId:`library-people`,title:t(`detectionIntelligence.people`,`People`),icon:_e,testId:`library-section-people`,children:e(`div`,{className:`${m} space-y-3`,children:[a(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`detectionIntelligence.enrolledIdentitiesUsedForFace`,`Enrolled identities used for face recognition. Open a person to rename them or remove training samples.`)}),a(Rn,{})]})}),a(jt,{headingId:`library-recent-faces`,title:t(`detectionIntelligence.recentDetectedFaces`,`Recent detected faces`),icon:se,testId:`library-section-recent-faces`,children:e(`div`,{className:`${m} space-y-3`,children:[a(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`detectionIntelligence.faceCropsCapturedByThe`,`Face crops captured by the detection pipeline. Assign them to a person to build recognition training data.`)}),a(Br,{})]})})]})}function Kr(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 qr=720*60*60*1e3;function Jr(e){let t=[];for(let n of e)t.push(...n);return t}function Yr(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function Xr(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 Zr(e,t){return`${String(e)}:${t}`}function Qr(e,t){let n=new Map,r=new Set;for(let i of e){let e=Zr(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 $r(e,t){return{since:e.fromMs??t-qr,until:e.toMs??t}}var ei=[`native`,`raster`,`standin`];function ti(e){return ei.some(t=>t===e)}function ni(e){return e===`standin`?{label:Y.t(`helpers.mediaProvenance.standin.label`),title:Y.t(`helpers.mediaProvenance.standin.title`),tone:`warning`}:{label:Y.t(`helpers.mediaProvenance.raster.label`),title:Y.t(`helpers.mediaProvenance.raster.title`),tone:`info`}}function ri(e){return e===`standin`?ni(`standin`):e===`raster`?ni(`raster`):null}var ii={"no-key-frame":`helpers.mediaProvenance.miss.noKeyFrame`,"no-best-seen-bbox":`helpers.mediaProvenance.miss.noBestSeenBbox`,"derive-returned-null":`helpers.mediaProvenance.miss.deriveReturnedNull`,"derive-threw":`helpers.mediaProvenance.miss.deriveThrew`,"derive-not-wired":`helpers.mediaProvenance.miss.deriveNotWired`,"no-media-store":`helpers.mediaProvenance.miss.noMediaStore`,"no-thumbnail":`helpers.mediaProvenance.miss.noThumbnail`,"standin-tile":`helpers.mediaProvenance.miss.standinTile`,"raster-tile":`helpers.mediaProvenance.miss.rasterTile`,"native-tile":`helpers.mediaProvenance.miss.nativeTile`};function ai(e){if(e===void 0)return null;let t=e.trim();if(t.length===0)return null;let n=t.split(/\s+/),r=n[0]??t,i=[];for(let e of n.slice(1)){let t=e.indexOf(`=`);t===-1?i.push({key:e,value:null}):i.push({key:e.slice(0,t),value:e.slice(t+1)})}let a=ii[r];return{sentence:a===void 0?r:Y.t(a),detail:i,raw:t}}function oi(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 si({row:t,cameraName:n,nowMs:r,onOpenDetail:i,selected:o=!1,onToggleSelect:s,score:c,provenance:l,footer:u}){let{t:d}=X(),p=Ht(t.mediaId===void 0?Ut(`track`,t.trackId):Gt(t.mediaId)),m=Math.round(t.importance*100),h=c===void 0?void 0:Math.round(c*100),_=oi(t.windowMs),v=()=>i(t),y=ri(l);return e(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${o?`border-primary ring-1 ring-primary`:`border-border`}`,children:[e(`div`,{className:`aspect-video relative overflow-hidden bg-surface-hover`,children:[p.src?a(`img`,{src:p.src,alt:d(`detectionIntelligence.eventCard.eventFrom`,`Event from {{cameraName}}`,{cameraName:n}),onClick:v,className:`h-full w-full cursor-zoom-in object-cover`}):a(`button`,{type:`button`,onClick:v,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-surface-hover text-foreground-subtle`,title:p.failed?d(`detectionIntelligence.eventCard.keyEventMediaUnavailable`,`Key-event media unavailable`):d(`detectionIntelligence.eventCard.noKeyEventMedia`,`No key-event media`),children:a(M,{className:`h-6 w-6 opacity-60`})}),s&&a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s(Zr(t.deviceId,t.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":o?d(`detectionIntelligence.eventCard.deselect`,`Deselect`):d(`detectionIntelligence.eventCard.select`,`Select`),children:o?a(fe,{className:`h-4 w-4 text-primary`}):a(O,{className:`h-4 w-4`})}),h!==void 0&&e(`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(h),`%`]}),m>0&&a(`span`,{className:`absolute right-1 top-1 z-10 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-semibold text-white`,children:String(m)}),y!==null&&a(`span`,{className:`absolute bottom-1 right-1 z-10 rounded px-1.5 py-0.5 text-[10px] font-semibold text-white ${y.tone===`warning`?`bg-warning/90`:`bg-black/70`}`,title:y.title,children:y.label}),(t.markForTrain===!0||t.retrainStatus===`trained`||t.debug===!0||t.favourited===!0)&&e(`span`,{className:`absolute bottom-1 left-1 z-10 flex gap-1`,children:[t.markForTrain===!0&&a(`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:a(g,{className:`h-3 w-3`})}),t.retrainStatus===`trained`&&t.markForTrain!==!0&&a(`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:a(T,{className:`h-3 w-3`})}),t.debug===!0&&a(`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:a(f,{className:`h-3 w-3`})}),t.favourited===!0&&a(`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:a(S,{className:`h-3 w-3`})})]})]}),e(`button`,{type:`button`,onClick:v,className:`min-w-0 px-2 py-1.5 text-left space-y-0.5`,children:[e(`p`,{className:`text-[11px] font-medium text-foreground truncate`,title:t.className,children:[t.className,Kr(t)?e(`span`,{className:`text-foreground-subtle`,children:[` · `,Kr(t)]}):null]}),a(`p`,{className:`text-[10px] text-foreground-subtle truncate`,title:n,children:n}),e(`div`,{className:`flex items-center justify-between gap-2`,children:[a(`span`,{className:`text-[10px] text-foreground-subtle truncate`,children:Yn(t.timestamp,r)}),_&&a(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:_})]})]}),u!==void 0&&a(`div`,{className:`px-2 pb-1.5`,children:u})]})}l();var ci=1400,li=`Admin-gated URL — opens only inside an authenticated session`;function ui({label:t,value:n,title:r}){let{t:c}=X(),[l,u]=s(!1),d=He();return o(()=>{if(!l)return;let e=setTimeout(()=>u(!1),ci);return()=>clearTimeout(e)},[l]),e(`button`,{type:`button`,onClick:i(()=>{(async()=>{try{await navigator.clipboard.writeText(n),u(!0)}catch{await d({title:c(`detectionIntelligence.copyUrlChips.copyTheMediaUrl`,`Copy the media URL`),message:c(`detectionIntelligence.copyUrlChips.clipboardAccessWasRefusedSelect`,`Clipboard access was refused. Select the URL below and copy it manually.`),label:c(`detectionIntelligence.copyUrlChips.url`,`{{label}} URL`,{label:t}),defaultValue:n,readOnly:!0,cancelLabel:c(`common.close`,`Close`)})}})()},[n,t,d,c]),title:r,"aria-label":c(`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 ${l?`border-success/40 bg-success/10 text-success`:`border-border text-foreground-subtle hover:border-primary hover:text-foreground`}`,children:[a(l?T:A,{className:`h-2.5 w-2.5 shrink-0`}),a(`span`,{className:`truncate`,children:l?c(`detectionIntelligence.copyUrlChips.copied`,`Copied`):t})]})}function di({localUrl:t,publicUrl:n}){let{t:r}=X();return e(`div`,{className:`flex flex-wrap gap-1`,children:[a(ui,{label:r(`detectionIntelligence.copyUrlChips.local`,`Local`),value:t,title:r(`detectionIntelligence.copyUrlChips.copyLanUrl`,`Copy LAN URL — {{AUTH_HINT}}`,{AUTH_HINT:li})}),n&&a(ui,{label:r(`detectionIntelligence.copyUrlChips.public`,`Public`),value:n,title:r(`detectionIntelligence.copyUrlChips.copyPublicUrl`,`Copy public URL — {{AUTH_HINT}}`,{AUTH_HINT:li})})]})}var fi={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 pi(e){return e in fi}function mi(e){return pi(e)?fi[e]:e}function hi(e,t){return`${e}${t}`}l();var gi=3e4;function _i(e){let[t,n]=s(null),r=i(e=>{n(t=>t??e)},[]);return o(()=>{e||n(null)},[e]),{publicOrigin:t,probes:e?a(vi,{onOrigin:r}):null}}function vi({onOrigin:e}){let{data:t}=Ie({capName:`network-access`});return a(d,{children:(t??[]).map(t=>a(yi,{addonId:t.addonId,onOrigin:e},t.addonId))})}function yi({addonId:e,onOrigin:t}){let{data:n}=Ae({addonId:e},{refetchInterval:gi,retry:!1});return o(()=>{let e=n?ae.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 bi=typeof Nt==`function`,xi=`Track flags arrive with the next server update`;function Si(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var Ci=bi?Nt:Si;function wi(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}}l();function Ti({label:t,hint:n,checked:r,disabled:i,title:o,icon:s,onToggle:c}){return e(`button`,{type:`button`,role:`switch`,"aria-checked":r,"aria-label":t,disabled:i,title:o,onClick:c,className:`flex w-full items-center gap-2 rounded-md border px-2 py-1.5 text-left transition-colors disabled:opacity-50 ${r?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[a(`span`,{className:r?`text-primary`:`text-foreground-subtle`,children:s}),e(`span`,{className:`min-w-0 flex-1`,children:[a(`span`,{className:`block text-[11px] font-medium text-foreground`,children:t}),a(`span`,{className:`block text-[10px] text-foreground-subtle`,children:n})]}),a(`span`,{"aria-hidden":`true`,className:`h-4 w-7 shrink-0 rounded-full p-0.5 transition-colors ${r?`bg-primary`:`bg-border`}`,children:a(`span`,{className:`block h-3 w-3 rounded-full bg-white transition-transform ${r?`translate-x-3`:``}`})})]})}function Ei({deviceId:t,trackId:n,markForTrain:r,debug:i,favourited:o,onChange:c}){let{t:l}=X(),u=Ci(),d=Oe(),[p,m]=s(null),h=p?.markForTrain??r===!0,_=p?.debug??i===!0,v=p?.favourited??o===!0,y=!bi||u.isPending,b=bi?void 0:xi,x=e=>{y||(async()=>{try{let r=wi(await u.mutateAsync({deviceId:t,trackId:n,flags:e}));if(!r)return;m(r),c?.(r)}catch(e){let t=e instanceof Error?e.message:``;await d({title:l(`detectionIntelligence.trackFlagToggles.couldNotUpdateThisTrack`,`Could not update this track`),message:t===``?l(`detectionIntelligence.trackFlagToggles.couldNotUpdateThisTrack2`,`Could not update this track. Check the server logs.`):t,variant:`danger`})}})()};return e(`div`,{className:`grid gap-1.5 sm:grid-cols-2`,children:[a(Ti,{label:l(`detectionIntelligence.trackFlagToggles.markForTraining`,`Mark for training`),hint:l(`detectionIntelligence.trackFlagToggles.keepsThisTrackAndIts`,`Keeps this track and its media past retention`),checked:h,disabled:y,...b===void 0?{}:{title:b},icon:a(g,{className:`h-4 w-4`}),onToggle:()=>x({markForTrain:!h})}),a(Ti,{label:l(`detectionIntelligence.trackFlagToggles.debug`,`Debug`),hint:l(`detectionIntelligence.trackFlagToggles.flagThisTrackForDiagnostic`,`Flag this track for diagnostic attention`),checked:_,disabled:y,...b===void 0?{}:{title:b},icon:a(f,{className:`h-4 w-4`}),onToggle:()=>x({debug:!_})}),a(Ti,{label:l(`detectionIntelligence.trackFlagToggles.favourited`,`Favourited`),hint:l(`detectionIntelligence.trackFlagToggles.keepsThisTrackAndIts`,`Keeps this track and its media past retention`),checked:v,disabled:y,...b===void 0?{}:{title:b},icon:a(S,{className:`h-4 w-4`}),onToggle:()=>x({favourited:!v})})]})}function Di(e){let t=e.deviceKey===void 0?e.nodeId:`${e.nodeId} · ${e.deviceKey}`;return e.modelId===void 0?t:`${t} (${e.modelId})`}function Oi(e){let t=e?.openedPlacement,n=e?.closedPlacement;if(t!==void 0&&n!==void 0){let e=Di(t),r=Di(n);return e===r?[{kind:`detected`,value:e}]:[{kind:`opened`,value:e},{kind:`closed`,value:r}]}return t===void 0?n===void 0?[]:[{kind:`closed`,value:Di(n)}]:[{kind:`opened`,value:Di(t)}]}var ki=100,Ai={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},ji=e=>e<0?0:e>1?1:e,Mi=e=>Math.round(e*100)/100;function Ni(e,t,n){if(e.length===0||t===null)return Ai;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return Ai;let a=oe(e.map(e=>({x:e.x/r,y:e.y/i,w:e.bbox.w/r,h:e.bbox.h/i})),n?.maxPoints===void 0?void 0:{maxPoints:n.maxPoints}).nodes.map(e=>({x:Mi(e.x*ki),y:Mi(e.y*ki)})),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:Mi(ji(e.x/r)*ki),y:Mi(ji(e.y/i)*ki),mediaId:e.mediaId})),u=null,d=-1;for(let t of e){let e=ji(t.bbox.w/r)*ji(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:Mi(ji(u.bbox.x/r)*ki),y:Mi(ji(u.bbox.y/i)*ki),w:Mi(ji(u.bbox.w/r)*ki),h:Mi(ji(u.bbox.h/i)*ki)}:null}}var Pi=typeof wt==`function`,Fi=`Track deletion arrives with the next server update`;function Ii(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var Li=Pi?wt:Ii;l();var Ri=15e3,zi=k();function Bi({url:e,label:t}){let{src:n,failed:r}=Ht(e);return n===null?a(`div`,{className:`flex h-full w-full items-center justify-center bg-surface-hover`,children:r?a(M,{className:`h-4 w-4 text-foreground-subtle opacity-60`}):a(W,{className:`h-4 w-4 animate-spin text-foreground-subtle opacity-70`})}):a(`img`,{src:n,alt:t,className:`h-full w-full object-cover`})}var Vi=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),Hi=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`,`sceneFrame`,`lastSceneFrame`]);function Ui(e){let[t,n]=s(null);return o(()=>{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 Wi({overlay:t,onPickSnapshot:n}){let{t:r}=X();return!t.polyline&&!t.peakBox&&t.snapshots.length===0?null:e(`svg`,{viewBox:`0 0 100 100`,preserveAspectRatio:`none`,className:`pointer-events-none absolute inset-0 h-full w-full`,children:[t.peakBox&&a(`rect`,{x:t.peakBox.x,y:t.peakBox.y,width:t.peakBox.w,height:t.peakBox.h,fill:`none`,stroke:`var(--color-warning)`,strokeWidth:2,vectorEffect:`non-scaling-stroke`,rx:1}),t.polyline&&a(`polyline`,{points:t.polyline,fill:`none`,stroke:`var(--color-info)`,strokeWidth:2,strokeLinejoin:`round`,strokeLinecap:`round`,strokeOpacity:.85,vectorEffect:`non-scaling-stroke`}),t.points.map((e,t)=>a(`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)}`)),t.snapshots.map((e,t)=>a(`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:n?`pointer-events-auto cursor-pointer`:void 0,onClick:n?t=>{t.stopPropagation(),n(e.mediaId)}:void 0,children:a(`title`,{children:r(`detectionIntelligence.eventDetailPanel.snapshotCheckpointClickToView`,`Snapshot checkpoint — click to view this frame`)})},`snap-${String(e.mediaId)}-${String(t)}`)),t.start&&a(`circle`,{cx:t.start.x,cy:t.start.y,r:2.4,fill:`var(--color-success)`,stroke:`var(--color-background)`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`}),t.end&&a(`circle`,{cx:t.end.x,cy:t.end.y,r:2.4,fill:`var(--color-danger)`,stroke:`var(--color-background)`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`})]})}function Z({label:t,value:n,mono:r,wrap:i}){return e(`div`,{className:`flex items-baseline justify-between gap-3 border-b border-border/60 py-1.5 last:border-0`,children:[a(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:t}),a(`span`,{className:`min-w-0 ${i?`break-words`:`truncate`} text-right text-xs font-medium text-foreground ${r?`font-mono text-[11px]`:``}`,title:n,children:n})]})}function Gi({row:t,cameraName:r,deleteAvailable:c,onClose:l,onDeleted:u,onFlagsChanged:f}){let{t:p}=X(),m=G(),h=Oe(),g=Be(),_=Li(),v=t!==null,y=t?.deviceId??0,S=t?.trackId??``,C=t?.timestamp??0,w=t?.windowMs??0,{data:T}=nt({deviceId:y,trackId:S},{enabled:v}),{data:E}=at({trackId:S,deviceId:y},{enabled:v}),D=T?.bestEventId===void 0?void 0:Number(T.bestEventId),{data:O}=dt({ownerType:`object`,eventId:D??0,deviceId:y},{enabled:v&&D!==void 0&&Number.isFinite(D)}),{data:k}=Ue({deviceId:y},{enabled:v}),A=(k??[]).find(e=>e.addonId!==void 0)?.addonId,{data:j}=Ve({deviceId:y,since:C-Ri,until:C+w+Ri,provider:A??``},{enabled:v&&A!==void 0}),[N,P]=s(null),[F,I]=s(!1),{publicOrigin:L,probes:R}=_i(v);o(()=>{P(null)},[y,S]);let z=n(()=>{let e=E??[],t=O??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[E,O]),B=N??z,V=Ht(B?B.url:void 0),H=n(()=>{let e=new Set,t=[];for(let n of[...O??[],...E??[]])e.has(n.mediaId)||(e.add(n.mediaId),t.push(n));return t},[O,E]),U=n(()=>H.find(e=>Vi.has(e.kind))??null,[H]),ee=Ui(Ht(U?U.url:void 0).src),te=n(()=>Ni(T?.positions??[],ee,{snapshots:(T?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaId:e.mediaId}))}),[T?.positions,T?.snapshots,ee]),ne=i(e=>{let t=H.find(t=>t.mediaId===e);t&&P(t)},[H]);if(t===null)return null;let K=V.src,re=B?.kind,ie=re!==void 0&&Hi.has(re)&&ee!==null&&(T?.positions.length??0)>=2,q=j&&j.length>0?j[0]:null,ae=()=>{q&&(I(!0),(async()=>{try{let e=await m.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:q.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)}})())},oe=()=>{!c||_.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]}),u()}catch{await h({title:p(`detectionIntelligence.eventDetailPanel.deleteFailed`,`Delete failed`),message:p(`detectionIntelligence.eventDetailPanel.failedToDeleteThisTrack`,`Failed to delete this track. Check the server logs.`),variant:`danger`})}})()},se=Math.round(t.importance*100),ce=T?.importanceReason?`${String(se)}% · ${T.importanceReason}`:`${String(se)}%`,le=T?.zonesVisited&&T.zonesVisited.length>0?T.zonesVisited.join(`, `):`—`,ue=T?.audioLabels&&T.audioLabels.length>0?T.audioLabels:t.audioLabels&&t.audioLabels.length>0?t.audioLabels:void 0,de=ue===void 0?`—`:ue.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `),fe=T?T.totalDistance.toFixed(2):`—`,pe=ai(T?.previewMissReason),me=Zn(T?T.firstSeen:C),he=T?Zn(T.lastSeen):`—`,ge=Oi(T),_e={detected:p(`detectionIntelligence.eventDetailPanel.detectedOn`,`Detected on`),opened:p(`detectionIntelligence.eventDetailPanel.openedOn`,`Opened on`),closed:p(`detectionIntelligence.eventDetailPanel.closedOn`,`Closed on`)};return a(rt,{open:!0,onOpenChange:e=>!e&&l(),children:e(pt,{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:[a(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:e(`div`,{className:`min-w-0`,children:[e(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:[t.className,Kr(t)?e(`span`,{className:`text-foreground-subtle`,children:[` · `,Kr(t)]}):null]}),a(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:r})]})}),e(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[K?a(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:a(mr,{src:K,alt:p(`detectionIntelligence.eventDetailPanel.keyFrameFrom`,`Key frame from {{cameraName}}`,{cameraName:r}),fit:`natural`,className:`w-full`,overlay:ie?a(Wi,{overlay:te,onPickSnapshot:ne}):void 0})}):a(`div`,{className:`flex aspect-video w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-surface-hover text-foreground-subtle`,children:V.failed?e(d,{children:[a(M,{className:`h-8 w-8 opacity-60`}),a(`span`,{className:`text-[11px]`,children:p(`detectionIntelligence.eventDetailPanel.keyFrameMediaUnavailable`,`Key-frame media unavailable`)})]}):a(W,{className:`h-6 w-6 animate-spin opacity-70`})}),H.length>0&&a(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:H.map(t=>{let n=mi(t.kind),r=hi(zi,t.url),i=L?hi(L,t.url):null;return e(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[a(`button`,{type:`button`,onClick:()=>P(t),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${n} · ${Zn(t.timestamp)}`,children:a(Bi,{url:t.url,label:n})}),e(`figcaption`,{className:`min-w-0 px-0.5`,children:[a(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:n,children:n}),a(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:Zn(t.timestamp),children:Xn(t.timestamp)})]}),a(di,{localUrl:r,publicUrl:i})]},t.mediaId)})}),R,q&&e(J,{variant:`secondary`,onClick:ae,disabled:F,children:[F?a(W,{className:`h-3.5 w-3.5 animate-spin`}):a(b,{className:`h-3.5 w-3.5`}),` `,p(`detectionIntelligence.eventDetailPanel.viewClip`,`View clip`)]}),a(Ei,{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}),pe!==null&&e(`div`,{className:`rounded-lg border border-warning/40 bg-warning/8 px-3 py-2`,children:[a(`p`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:p(`detectionIntelligence.eventDetailPanel.bestShot`,`Best shot`)}),a(`p`,{className:`mt-0.5 text-xs text-foreground`,children:pe.sentence}),a(`code`,{className:`mt-1 block break-all font-mono text-[10px] text-foreground-subtle`,children:pe.raw})]}),e(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[a(Z,{label:p(`detectionIntelligence.eventDetailPanel.camera`,`Camera`),value:r}),ge.map(e=>a(Z,{label:_e[e.kind],value:e.value,mono:!0,wrap:!0},e.kind)),a(Z,{label:p(`detectionIntelligence.eventDetailPanel.class`,`Class`),value:t.className}),a(Z,{label:p(`detectionIntelligence.eventDetailPanel.label`,`Label`),value:t.label??`—`}),a(Z,{label:p(`detectionIntelligence.eventDetailPanel.subLabel`,`Sub-label`),value:t.subLabel??`—`}),a(Z,{label:p(`detectionIntelligence.eventDetailPanel.importance`,`Importance`),value:ce}),a(Z,{label:p(`detectionIntelligence.eventDetailPanel.zonesVisited`,`Zones visited`),value:le}),a(Z,{label:p(`detectionIntelligence.eventDetailPanel.audioHeard`,`Audio heard`),value:de}),a(Z,{label:p(`detectionIntelligence.eventDetailPanel.totalDistance`,`Total distance`),value:fe}),a(Z,{label:p(`detectionIntelligence.eventDetailPanel.firstSeen`,`First seen`),value:me}),a(Z,{label:p(`detectionIntelligence.eventDetailPanel.lastSeen`,`Last seen`),value:he}),a(Z,{label:p(`detectionIntelligence.eventDetailPanel.track`,`Track`),value:t.trackId,mono:!0})]})]}),a(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:a(`span`,{title:c?void 0:Fi,children:e(J,{variant:`secondary`,onClick:oe,disabled:!c||_.isPending,children:[_.isPending?a(W,{className:`h-3.5 w-3.5 animate-spin`}):a(x,{className:`h-3.5 w-3.5`}),` `,p(`detectionIntelligence.eventDetailPanel.deleteTrack`,`Delete track`)]})})})]})})}var Ki={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`},qi={setRelation:`debug.gt.setRelation`,setPurity:`debug.gt.setPurity`,list:`debug.gt.list`},Ji=w(`/addon/pipeline-analytics/tape-export`),Yi=10*6e4;function Xi(e){return`${Ji}?tapeId=${encodeURIComponent(e)}`}var Zi=`The server answered in a shape this build does not understand.`;function Qi(e){return e instanceof Error?e.message:Y.t(`helpers.eventsDebugTapes.actionFailed`)}function $i(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 ea(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 ta(e,t){let n=e[t];return typeof n==`boolean`?n:null}function na(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 ra(e){return e===`off`||e===`recording`||e===`refused`||e===`failing`||e===`unknown`}function ia(e){if(!$i(e))return null;let t=Q(e,`deviceId`),n=e.state,r=Q(e,`gapsSinceArmed`),i=ea(e,`segmentsHeld`),a=ea(e,`bytesLastHour`),o=ea(e,`bytesHeld`);if(t===null||!ra(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 aa(e){return $i(e)?na(e.cameras,ia):null}function oa(e){if(!$i(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=ta(e,`reviewed`),f=ta(e,`released`),p=na(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 sa(e){return $i(e)?na(e.tapes,oa):null}function ca(e){if(!$i(e))return null;let t=$(e,`trackId`),n=Q(e,`firstT`),r=Q(e,`lastT`),i=Q(e,`boundFrames`),a=$(e,`cls`),o=ta(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 la(e){if(!$i(e))return null;let t=$(e,`tapeId`),n=Q(e,`deviceId`),r=Q(e,`fromMs`),i=Q(e,`toMs`),a=ta(e,`reviewed`),o=na(e.lanes,ca);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 ua(e){if(!$i(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 da(e){if(!$i(e))return null;let t=e.status;if(t===`released`){let n=Q(e,`unpinned`),r=ta(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 fa(e){if(!$i(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 pa(e){switch(e.status){case`released`:case`deleted`:return null;case`already-released`:return Y.t(`helpers.eventsDebugTapes.alreadyReleased`);case`not-found`:return Y.t(`helpers.eventsDebugTapes.notFound`);case`pins-owed`:return Y.t(`helpers.eventsDebugTapes.pinsOwed`);case`unavailable`:return Y.t(`helpers.eventsDebugTapes.unavailable`,{reason:e.reason})}}function ma(e){if(!$i(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 ha(e){if(!$i(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 ga(e){if(!$i(e))return null;let t=na(e.relations,ma),n=na(e.purities,ha),r=ta(e,`truncated`);return t===null||n===null||r===null?null:{relations:t,purities:n,truncated:r}}function _a(e){if(!e.truncated)return null;let t=e.relations.length+e.purities.length;return Y.t(`helpers.eventsDebugTapes.truncatedMarks`,{count:t})}function va(e){return e.filter(e=>e.segmentsHeld===null||e.segmentsHeld>0).map(e=>({deviceId:e.deviceId,segmentsUnknown:e.segmentsHeld===null}))}function ya(e){return e.slice(1).map((t,n)=>({trackId:e[n]??t,otherTrackId:t}))}function ba(e){return e.flatMap((t,n)=>e.slice(n+1).map(e=>({trackId:t,otherTrackId:e})))}function xa(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 Sa(e){switch(e.state){case`off`:return Y.t(`helpers.eventsDebugTapes.statusOff`);case`recording`:return Y.t(`helpers.eventsDebugTapes.statusRecording`);case`refused`:return Y.t(`helpers.eventsDebugTapes.statusRefused`,{reason:e.reason??Y.t(`helpers.eventsDebugTapes.unknownReason`)});case`failing`:return Y.t(`helpers.eventsDebugTapes.statusFailing`,{reason:e.reason??Y.t(`helpers.eventsDebugTapes.unknownReason`)});case`unknown`:return Y.t(`helpers.eventsDebugTapes.statusUnknown`,{reason:e.reason??Y.t(`helpers.eventsDebugTapes.unknownReason`)})}}var Ca={"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 wa(e,t){let n=Ca[e]??`Refused (${e}).`;return t.length>0?`${n} ${t}`:n}function Ta(e){if(e.length===0)return null;let t=new Date(e).getTime();return Number.isFinite(t)?t:null}function Ea(e){return e<1024*1024?Y.t(`helpers.eventsDebugTapes.sizeKb`,{value:(e/1024).toFixed(0)}):Y.t(`helpers.eventsDebugTapes.sizeMb`,{value:(e/1024/1024).toFixed(1)})}function Da(e){return e===null?`unknown`:Ea(e)}function Oa(e){return e===null?`unknown`:String(e)}function ka(e,t){let n=t.trim();return e===404?Y.t(`helpers.eventsDebugTapes.exportUnknown`):e===503?n.length>0?n:Y.t(`helpers.eventsDebugTapes.tapesUnavailable`):e===500?n.length>0?n:Y.t(`helpers.eventsDebugTapes.exportUnreadable`):Y.t(`helpers.eventsDebugTapes.downloadFailed`,{status:e})}l();function Aa({cameras:t,call:n,onPromoted:r}){let{t:i}=X(),[o,c]=s(``),[l,u]=s(``),[d,f]=s(``),[p,m]=s(``),[h,g]=s(``),[_,v]=s(`auto`),[y,b]=s(!1),[x,S]=s(null),C=async()=>{let e=Number.parseInt(o===``?t[0]?.value??``:o,10),i=Ta(l),a=Ta(d);if(!Number.isFinite(e)||i===null||a===null){S(`Pick a camera and both ends of the window.`);return}b(!0),S(null);try{let t=ua(await n(Ki.promote,{deviceId:e,fromMs:i,toMs:a,scenario:p,...h.trim().length>0?{note:h.trim()}:{},..._===`day`||_===`ir`?{lighting:_}:{}}));t===null?S(Zi):t.ok?(S(`Promoted ${t.tapeId}: ${String(t.frames)} frames, ${Ea(t.bytes)}, ${String(t.pinnedTracks)} tracks pinned`+(t.state===`incomplete`?` — incomplete (it has gaps) and cannot become a case.`:`.`)),r()):S(wa(t.reason,t.detail))}catch(e){S(Qi(e))}finally{b(!1)}};return e(`div`,{className:`flex flex-wrap items-end gap-2 rounded-md border border-border px-3 py-2`,children:[a(`div`,{className:`w-40`,children:a(bt,{value:o,options:[...t],onChange:e=>c(e.target.value),"aria-label":i(`eventsDebugTapesPromoteForm.camera`,`Camera`)})}),a(Fe,{type:`datetime-local`,"aria-label":i(`eventsDebugTapesPromoteForm.from`,`From`),value:l,onChange:e=>u(e.target.value),className:`w-48`}),a(Fe,{type:`datetime-local`,"aria-label":i(`eventsDebugTapesPromoteForm.to`,`To`),value:d,onChange:e=>f(e.target.value),className:`w-48`}),a(Fe,{"aria-label":i(`eventsDebugTapesPromoteForm.scenario`,`Scenario`),placeholder:`101-door-groups`,value:p,onChange:e=>m(e.target.value),className:`w-44`}),a(Fe,{"aria-label":i(`eventsDebugTapesPromoteForm.note`,`Note`),placeholder:i(`eventsDebugTapesPromoteForm.optionalNote`,`optional note`),value:h,onChange:e=>g(e.target.value),className:`w-52`}),a(`div`,{className:`w-28`,children:a(bt,{value:_,"aria-label":i(`eventsDebugTapesPromoteForm.lighting`,`Lighting`),options:[{value:`auto`,label:i(`eventsDebugTapesPromoteForm.lightingAuto`,`Lighting: auto`)},{value:`day`,label:i(`eventsDebugTapes.dayMode`)},{value:`ir`,label:`IR`}],onChange:e=>v(e.target.value)})}),e(J,{onClick:()=>void C(),disabled:y||t.length===0,children:[y?a(W,{className:`h-3.5 w-3.5 animate-spin`}):null,` `,i(`eventsDebugTapes.promoteWindow`)]}),a(`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&&a(`p`,{className:`w-full text-xs text-foreground`,children:x})]})}var ja=`pipeline-analytics`,Ma=`debug.listTracks`,Na=`debug.analyze`,Pa=w(`/addon/pipeline-analytics/debug-export`);function Fa(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Ia(e,t){let n=e[t];return typeof n==`string`?n:null}function La(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Ra(e,t){let n=e[t];return typeof n==`boolean`?n:null}function za(e){return e===`error`||e===`warn`||e===`info`}function Ba(e){if(!Fa(e))return null;let t=Ia(e,`code`),n=Ia(e,`detail`),r=e.severity;return t===null||n===null||!za(r)?null:{code:t,severity:r,detail:n}}function Va(e){if(!Fa(e))return null;let t=Ia(e,`trackId`),n=La(e,`deviceId`),r=Ia(e,`className`),i=La(e,`firstSeen`),a=La(e,`lastSeen`),o=La(e,`durationMs`),s=Ra(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=Ia(e,`label`),l=Ia(e,`subLabel`),u=Ia(e,`previewMissReason`),d=Ra(e,`markForTrain`),f=Ra(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:La(e,`importance`)??0,bestEventId:Ia(e,`bestEventId`)??``,...d===null?{}:{markForTrain:d},...f===null?{}:{favourited:f},debug:!0,...u===null||u.length===0?{}:{previewMissReason:u}}}function Ha(e){let t=Va(e);if(t===null||!Fa(e))return null;let n=La(e,`mediaCount`),r=La(e,`eventCount`),i=La(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=Ba(e);t!==null&&c.push(t)}let l=e.thumbnailProvenance;return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c,...ti(l)?{thumbnailProvenance:l}:{}}}function Ua(e){if(!Fa(e))return null;let t=Ra(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=Va(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function Wa(e){if(!Fa(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=Ha(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var Ga={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 Ka(e){return Ga[e]??e}var qa={error:0,warn:1,info:2};function Ja(e){return e.toSorted((e,t)=>qa[e.severity]-qa[t.severity]||e.code.localeCompare(t.code))}function Ya(e){return e.length===0?Pa:`${Pa}?deviceIds=${e.join(`,`)}`}function Xa(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 Za(e,t){return`${String(e)}:${t}`}function Qa(e,t){let n=[],r=new Set;for(let i of e){let e=Za(i.deviceId,i.trackId);!t.has(e)||r.has(e)||(r.add(e),n.push({deviceId:i.deviceId,trackId:i.trackId}))}return n}l();function $a({tapeId:t,call:n,onClose:r,onChanged:i}){let{t:o}=X(),l=c({queryKey:[`events-debug`,`tapes`,`tracks`,t],queryFn:async()=>la(await n(Ki.tracks,{tapeId:t}))}),u=l.data??null,d=c({queryKey:[`events-debug`,`tapes`,`marks`,t],enabled:u!==null,queryFn:async()=>u===null?null:ga(await n(qi.list,{deviceId:u.deviceId,since:u.fromMs-Yi,until:u.toMs+Yi,limit:5e3}))}),[f,p]=s([]),[m,h]=s(``),[g,_]=s(null),v=e=>p(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),y=async e=>{_(null);try{for(let[t,r]of e)await n(t,r);p([]),await d.refetch(),i()}catch(e){_(Qi(e))}};if(u===null)return l.isLoading?a(`p`,{className:`text-xs`,children:o(`eventsDebugTapesReview.loadingTheTape`,`Loading the tape…`)}):a(Ee,{message:Zi});let b=u.deviceId,x=(e,t)=>y(e.map(e=>[qi.setRelation,{deviceId:b,...e,relation:t}])),S=e=>{let t=Number.parseFloat(m),n=e===`mixed`&&Number.isFinite(t)?u.fromMs+t*1e3:void 0;return y(f.map(t=>[qi.setPurity,{deviceId:b,trackId:t,purity:e,...n===void 0?{}:{switchAtMs:Math.round(n)}}]))},C=d.data==null?null:_a(d.data);return e(`div`,{className:`space-y-2 rounded-md border border-primary/40 px-3 py-2`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[a(`span`,{className:`text-xs font-medium`,children:o(`eventsDebugTapes.reviewLanes`,{id:u.tapeId,count:u.lanes.length})}),a(J,{disabled:f.length<2,onClick:()=>void x(ya(f),`same-subject`),children:o(`eventsDebugTapesReview.sameSubject`,`Same subject`)}),a(J,{variant:`secondary`,disabled:f.length<2,onClick:()=>void x(ba(f),`different-subjects`),children:o(`eventsDebugTapesReview.differentSubjects`,`Different subjects`)}),a(Fe,{"aria-label":o(`eventsDebugTapesReview.changedAtSFromTape`,`Changed at (s from tape start)`),placeholder:o(`eventsDebugTapesReview.changedAtS`,`changed at s`),value:m,onChange:e=>h(e.target.value),className:`w-28`}),a(J,{variant:`secondary`,disabled:f.length!==1,onClick:()=>void S(`mixed`),children:o(`eventsDebugTapesReview.mixed`,`Mixed`)}),a(J,{variant:`secondary`,disabled:f.length===0,onClick:()=>void S(`not-a-subject`),children:o(`eventsDebugTapesReview.notASubject`,`Not a subject`)}),a(J,{variant:u.reviewed?`secondary`:`primary`,onClick:()=>void y([[Ki.review,{tapeId:u.tapeId,reviewed:!u.reviewed}]]).then(()=>l.refetch()),children:u.reviewed?o(`eventsDebugTapesReview.markNotReviewed`,`Mark not reviewed`):o(`eventsDebugTapesReview.markReviewed`,`Mark reviewed`)}),a(J,{variant:`ghost`,onClick:r,children:o(`common.close`,`Close`)})]}),g!==null&&a(Ee,{message:g}),C!==null&&a(Ee,{variant:`warning`,message:C}),a(`ul`,{className:`space-y-1`,children:u.lanes.toSorted((e,t)=>e.firstT-t.firstT).map(e=>a(eo,{lane:e,marks:d.data===null||d.data===void 0?[]:xa(e.trackId,d.data),selected:f.includes(e.trackId),onToggle:()=>v(e.trackId)},e.trackId))})]})}function eo({lane:t,marks:n,selected:r,onToggle:i}){let{t:o}=X(),{src:s}=Ht(t.stillStored?Ut(`track`,t.trackId):void 0);return e(`li`,{className:`flex items-center gap-2 text-xs`,children:[a(`input`,{type:`checkbox`,"aria-label":o(`eventsDebugTapesReview.select`,`select {{trackId}}`,{trackId:t.trackId}),checked:r,onChange:i}),s===null?a(`div`,{className:`h-10 w-10 rounded bg-surface-hover`}):a(`img`,{src:s,alt:t.trackId,className:`h-10 w-10 rounded object-cover`}),a(`span`,{className:`font-mono`,children:t.trackId}),a(`span`,{children:t.cls}),a(`span`,{className:`text-foreground-subtle`,children:o(`eventsDebugTapes.laneFrames`,{range:`${Xa(t.firstT)} → ${Xa(t.lastT)}`,count:t.boundFrames})}),!t.stillStored&&a(`span`,{className:`text-foreground-subtle`,children:o(`eventsDebugTapesReview.notStoredMarkedThroughThe`,`not stored — marked through the tape`)}),n.map(e=>a(Pe,{variant:`info`,children:e},e))]})}l();var to=`camstack_admin_token`;function no(){let e=G();return(t,n)=>e.trpcClient.addons.custom.mutate({addonId:ja,action:t,input:n})}async function ro(e,t){let n=localStorage.getItem(to),r={};n!==null&&(r.Authorization=`Bearer ${n}`);let i=await fetch(Xi(e),{headers:r});if(!i.ok){let e=await i.text().catch(()=>``);throw Error(ka(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 io(){let{t:e}=X(),[t,n]=s(!1);return a(ve,{expanded:t,onExpandedChange:n,header:a(`span`,{className:`text-sm font-medium text-foreground`,children:e(`eventsDebugTapes.trackingTapes`,`Tracking tapes`)}),children:a(ao,{})})}function ao(){let{t}=X(),r=no(),i=et({isCamera:!0,projection:`slim`}),o=n(()=>{let e=new Map;for(let t of i.data??[])e.set(t.id,t.name);return n=>e.get(n)??t(`cameraLoad.deviceLabel`,{deviceId:n})},[i.data,t]),l=c({queryKey:[`events-debug`,`tapes`,`status`],queryFn:async()=>aa(await r(Ki.status,{}))}),u=c({queryKey:[`events-debug`,`tapes`,`list`],queryFn:async()=>sa(await r(Ki.list,{}))}),[d,f]=s(null),[p,m]=s(null),h=async e=>{m(null);try{await ro(e.id,`${e.scenario}.tape-bundle.json.gz`)}catch(e){m(Qi(e))}},g=async e=>{let t=da(await r(Ki.release,{tapeId:e.id}));if(t===null)throw Error(Zi);let n=pa(t);if(n!==null)throw Error(n);await u.refetch()},_=async e=>{let t=fa(await r(Ki.remove,{tapeId:e.id}));if(t===null)throw Error(Zi);let n=pa(t);if(n!==null)throw Error(n);await u.refetch()};return e(`div`,{className:`space-y-3`,children:[a(`p`,{className:`text-xs text-foreground-subtle`,children:a(Lt,{i18nKey:`eventsDebugTapes.intro`,components:{b:a(`strong`,{}),code:a(`code`,{})}})}),p!==null&&a(Ee,{message:p}),l.isLoading&&a(`p`,{className:`text-xs text-foreground-subtle`,children:t(`eventsDebugTapes.loadingCameraStatus`,`Loading camera status…`)}),l.data===null&&a(Ee,{message:`The server answered in a shape this build does not understand.`}),e(`table`,{className:`w-full text-xs`,children:[a(`thead`,{children:e(`tr`,{className:`text-left text-foreground-subtle`,children:[a(`th`,{children:t(`eventsDebugTapes.camera`,`Camera`)}),a(`th`,{children:t(`eventsDebugTapes.state`,`State`)}),a(`th`,{children:t(`eventsDebugTapes.framesMin`,`Frames/min`)}),a(`th`,{children:t(`eventsDebugTapes.lastHour`,`Last hour`)}),a(`th`,{children:t(`eventsDebugTapes.held`,`Held`)}),a(`th`,{children:t(`eventsDebugTapes.gaps`,`Gaps`)})]})}),a(`tbody`,{children:(l.data??[]).map(n=>e(`tr`,{children:[a(`td`,{children:o(n.deviceId)}),a(`td`,{children:a(Pe,{variant:n.state===`recording`?`success`:n.state===`off`?`default`:n.state===`unknown`?`warning`:`danger`,children:Sa(n)})}),a(`td`,{children:n.framesPerMin===void 0?`—`:String(Math.round(n.framesPerMin))}),a(`td`,{title:n.shelfError,children:Da(n.bytesLastHour)}),a(`td`,{title:n.shelfError,children:t(`eventsDebugTapes.segsHeld`,{count:Oa(n.segmentsHeld),size:Da(n.bytesHeld)})}),a(`td`,{children:String(n.gapsSinceArmed)})]},n.deviceId))})]}),a(Aa,{cameras:va(l.data??[]).map(e=>({value:String(e.deviceId),label:e.segmentsUnknown?t(`eventsDebugTapes.segmentsUnknown`,`{{value1}} (segments unknown)`,{value1:o(e.deviceId)}):o(e.deviceId)})),call:r,onPromoted:()=>void u.refetch()}),u.isLoading&&a(`p`,{className:`text-xs text-foreground-subtle`,children:t(`eventsDebugTapes.loadingPromotedTapes`,`Loading promoted tapes…`)}),u.data===null&&a(Ee,{message:`The server answered in a shape this build does not understand.`}),e(`table`,{className:`w-full text-xs`,children:[a(`thead`,{children:e(`tr`,{className:`text-left text-foreground-subtle`,children:[a(`th`,{children:t(`eventsDebugTapes.scenario`,`Scenario`)}),a(`th`,{children:t(`eventsDebugTapes.camera`,`Camera`)}),a(`th`,{children:t(`eventsDebugTapes.window`,`Window`)}),a(`th`,{children:t(`eventsDebugTapes.state`,`State`)}),a(`th`,{children:t(`eventsDebugTapes.tracks`,`Tracks`)}),a(`th`,{})]})}),a(`tbody`,{children:(u.data??[]).map(n=>e(`tr`,{children:[a(`td`,{children:n.scenario}),a(`td`,{children:o(n.deviceId)}),e(`td`,{children:[new Date(n.fromMs).toLocaleString(),` · `,Xa(n.toMs-n.fromMs),` `,`· `,n.lighting]}),e(`td`,{children:[a(Pe,{variant:n.state===`complete`?`success`:`warning`,children:n.state}),` `,n.reviewed&&a(Pe,{variant:`info`,children:t(`eventsDebugTapes.reviewed`)}),` `,n.released&&a(Pe,{children:t(`eventsDebugTapes.released`)})]}),a(`td`,{children:t(`eventsDebugTapes.storedOf`,{stored:String(n.tracksStillStored),total:String(n.tracks.length)})}),e(`td`,{className:`space-x-1 text-right`,children:[a(J,{variant:`secondary`,"aria-label":t(`eventsDebugTapes.review`,`Review {{scenario}}`,{scenario:n.scenario}),onClick:()=>f(n.id),children:t(`eventsDebugTapes.review2`,`Review`)}),a(J,{variant:`ghost`,"aria-label":t(`eventsDebugTapes.download`,`Download {{scenario}}`,{scenario:n.scenario}),onClick:()=>void h(n),children:a(E,{className:`h-3.5 w-3.5`})}),a(st,{label:t(`eventsDebugTapes.release`,`Release`),icon:B,title:t(`eventsDebugTapes.release2`,`Release {{scenario}}?`,{scenario:n.scenario}),description:t(`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:t(`eventsDebugTapes.release`,`Release`),triggerVariant:`ghost`,confirmVariant:`danger`,disabled:n.released,action:()=>g(n)}),a(st,{label:t(`common.delete`,`Delete`),icon:x,title:t(`eventsDebugTapes.delete`,`Delete {{scenario}}?`,{scenario:n.scenario}),description:t(`eventsDebugTapes.deletingRemovesThePromotedBundle`,`Deleting removes the promoted bundle and its index row for good. Its tracks' pins are released first — this cannot be undone.`),confirmLabel:t(`common.delete`,`Delete`),triggerVariant:`ghost`,confirmVariant:`danger`,action:()=>_(n)})]})]},n.id))})]}),d!==null&&a($a,{tapeId:d,call:r,onClose:()=>f(null),onChanged:()=>void u.refetch()})]})}l();var oo=`all`,so=`The server answered in a shape this build does not understand.`,co={error:`danger`,warn:`warning`,info:`info`};function lo({findings:e}){let{t}=X();return e.length===0?a(Pe,{variant:`success`,children:t(`eventsDebug.noAnomalyFound`,`no anomaly found`)}):a(`div`,{className:`flex flex-wrap gap-1`,children:Ja(e).map(e=>a(Pe,{variant:co[e.severity],title:e.detail,children:Ka(e.code)},e.code))})}function uo({track:t,report:n,analyzing:r}){let{t:i}=X(),o=ai(n?.previewMissReason??t.previewMissReason);return e(`div`,{className:`space-y-1 border-t border-border pt-1.5`,children:[n===void 0?a(`span`,{className:`text-[10px] text-foreground-subtle`,children:r?i(`eventsDebug.analysing`,`analysing…`):i(`eventsDebug.notAnalysed`,`not analysed`)}):e(d,{children:[a(lo,{findings:n.findings}),a(`p`,{className:`text-[10px] text-foreground-subtle`,title:n.mediaKinds.length>0?n.mediaKinds.join(`, `):i(`eventsDebug.noMediaOfAnyKind`,`no media of any kind`),children:i(`eventsDebug.reportCounts`,{media:String(n.mediaCount),events:String(n.eventCount),positions:String(n.positionCount)})})]}),o!==null&&a(`p`,{className:`text-[10px] text-foreground-subtle`,title:o.raw,children:o.sentence})]})}function fo(){let{t}=X(),r=G(),[i,o]=s(oo),[l,u]=s(!1),[d,m]=s(null),[h,g]=s(new Set),[_,v]=s(null),[y,b]=s(null),[x,C]=s(null),[w,D]=s([]),O=Ci(),k=et({isCamera:!0,projection:`slim`}),A=n(()=>[{value:oo,label:t(`eventsDebug.allCameras`,`All cameras`)},...(k.data??[]).map(e=>({value:String(e.id),label:e.name}))],[k.data,t]),j=n(()=>{let e=new Map;for(let t of k.data??[])e.set(t.id,t.name);return e},[k.data]),M=e=>j.get(e)??t(`eventsDebug.cameraFallback`,{deviceId:e}),N=n(()=>i===oo?[]:[Number.parseInt(i,10)],[i]),P=c({queryKey:[`events-debug`,`list`,N],queryFn:async()=>Ua(await r.trpcClient.addons.custom.mutate({addonId:ja,action:Ma,input:N.length===0?{}:{deviceIds:N}}))}),I=n(()=>(P.data?.tracks??[]).map(e=>e.trackId),[P.data]),R=c({queryKey:[`events-debug`,`analyze`,I],enabled:I.length>0,queryFn:async()=>Wa(await r.trpcClient.addons.custom.mutate({addonId:ja,action:Na,input:{trackIds:I}}))}),z=n(()=>{let e=new Map;for(let t of R.data?.reports??[])e.set(t.trackId,t);return e},[R.data]),B=P.data?.tracks??[],V=P.data===null||R.data===null,H=()=>{P.refetch(),R.refetch()},U=e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},ee=()=>{g(new Set(B.map(e=>Za(e.deviceId,e.trackId))))},te=()=>g(new Set),ne=async(e,t)=>{let n=e===`analyzed`?{debug:!1}:{favourited:!0},r=0,i=[];for(let e of t)try{await O.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,flags:n}),r+=1}catch{i.push(e.trackId)}return{applied:r,refused:i}},K=e=>{if(!bi||y!==null)return;let t=Qa(B,h);t.length!==0&&(b(e),C(null),(async()=>{let n=await ne(e,t);b(null);let r=new Set(n.refused);g(new Set(t.filter(e=>r.has(e.trackId)).map(e=>Za(e.deviceId,e.trackId)))),e===`analyzed`&&D(t.filter(e=>!r.has(e.trackId))),n.refused.length>0&&C(`${String(n.refused.length)} of ${String(t.length)} were refused by the server and are still selected. Check the hub log.`),P.refetch()})())},re=()=>{let e=w;e.length===0||y!==null||(b(`analyzed`),C(null),(async()=>{for(let t of e)try{await O.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,flags:{debug:!0}})}catch{C(`Some tracks could not be re-marked. Refresh and try again.`)}b(null),D([]),P.refetch()})())},ie=async()=>{u(!0),m(null);try{await Kt(Ya(N),`camstack-debug.zip`)}catch(e){m(e instanceof Error?e.message:`Export failed.`)}finally{u(!1)}},q=y!==null;return e(`section`,{className:`space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[a(`div`,{className:`w-44`,children:a(bt,{value:i,options:A,onChange:e=>o(e.target.value)})}),e(J,{variant:`secondary`,onClick:H,disabled:P.isFetching,children:[P.isFetching?a(W,{className:`h-3.5 w-3.5 animate-spin`}):a(F,{className:`h-3.5 w-3.5`}),t(`common.refresh`,`Refresh`)]}),e(J,{onClick:()=>void ie(),disabled:l||B.length===0,children:[l?a(W,{className:`h-3.5 w-3.5 animate-spin`}):a(E,{className:`h-3.5 w-3.5`}),t(`eventsDebug.exportAll`,{count:String(B.length)})]}),B.length>0&&h.size<B.length&&a(J,{variant:`ghost`,onClick:ee,children:t(`eventsDebug.selectAll`,`Select all`)})]}),a(`p`,{className:`text-xs text-foreground-subtle`,children:a(Lt,{i18nKey:`eventsDebug.debugMarkNote`,components:{code:a(`code`,{}),strong:a(`strong`,{})}})}),a(io,{}),P.isError&&a(Ee,{message:t(`eventsDebug.couldNotLoadTheMarked`,`Could not load the marked tracks.`)}),V&&!P.isError&&a(Ee,{message:so}),d!==null&&a(Ee,{message:d}),x!==null&&a(Ee,{message:x}),P.data?.truncated===!0&&a(Ee,{message:t(`eventsDebug.aCameraFilledThePer`,`A camera filled the per-camera cap — some marked tracks are not listed. Un-mark a few, or filter to one camera.`)}),(R.data?.vanished.length??0)>0&&a(`p`,{className:`text-xs text-foreground-subtle`,children:t(`eventsDebug.vanished`,{count:String(R.data?.vanished.length)})}),h.size>0&&e(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[a(`span`,{className:`text-xs font-medium text-foreground`,children:t(`common.selectedCount`,{count:h.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[a(`span`,{title:bi?void 0:`Track flags arrive with the next server update`,children:e(J,{variant:`secondary`,onClick:()=>K(`keep`),disabled:!bi||q,children:[y===`keep`?a(W,{className:`h-3.5 w-3.5 animate-spin`}):a(S,{className:`h-3.5 w-3.5`}),` `,t(`eventsDebug.keep`,`Keep`)]})}),a(`span`,{title:bi?void 0:`Track flags arrive with the next server update`,children:e(J,{onClick:()=>K(`analyzed`),disabled:!bi||q,children:[y===`analyzed`?a(W,{className:`h-3.5 w-3.5 animate-spin`}):a(T,{className:`h-3.5 w-3.5`}),` `,t(`eventsDebug.analyzed`,`Analyzed`)]})}),a(J,{variant:`ghost`,onClick:te,disabled:q,children:a(L,{className:`h-3.5 w-3.5`})})]})]}),w.length>0&&e(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-border bg-surface px-3 py-2`,children:[a(`span`,{className:`text-xs text-foreground`,children:t(`eventsDebug.markedAnalyzed`,{count:String(w.length)})}),e(J,{variant:`ghost`,onClick:re,disabled:q,children:[a(p,{className:`h-3.5 w-3.5`}),` `,t(`eventsDebug.undo`)]}),a(J,{variant:`ghost`,onClick:()=>D([]),disabled:q,children:a(L,{className:`h-3.5 w-3.5`})})]}),P.isLoading?a(it,{status:`pending`,pendingMessage:`Loading…`,testId:`debug-tracks-grid`}):B.length===0?a(we,{icon:f,title:t(`eventsDebug.noTrackIsMarkedFor`,`No track is marked for debug`),description:t(`eventsDebug.markOneFromATrack`,`Mark one from a track's actions on the Feed to see it here.`)}):a(it,{status:`ready`,testId:`debug-tracks-grid`,children:B.map(e=>{let t=z.get(e.trackId);return a(si,{row:e,cameraName:M(e.deviceId),nowMs:e.lastSeen,selected:h.has(Za(e.deviceId,e.trackId)),onToggleSelect:U,onOpenDetail:v,...t?.thumbnailProvenance===void 0?{}:{provenance:t.thumbnailProvenance},footer:a(uo,{track:e,report:t,analyzing:R.isFetching})},Za(e.deviceId,e.trackId))})}),_&&a(Gi,{row:_,cameraName:M(_.deviceId),deleteAvailable:Pi,onClose:()=>v(null),onDeleted:()=>{v(null),P.refetch()},onFlagsChanged:e=>{e.debug||(v(null),P.refetch())}})]})}var po=200,mo=3e4,ho=[];function go(e){let t=G(),n=e.deviceIds.length>0,r=[...e.deviceIds].sort((e,t)=>e-t),{data:i,isLoading:a}=c({queryKey:[`events-feed`,r,e.since,e.until,e.minImportance??null,e.classFilter??null],enabled:n,staleTime:mo,refetchInterval:mo,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEventsBatch.query({deviceIds:r,since:e.since,until:e.until,limit:po,...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:Yr(Jr(i??ho),`importance`),isLoading:n&&a}}l();var _o=[`events-feed`],vo=2e3;function yo(e){let n=u(),r=e?.paused===!0,a=t(n);a.current=n;let c=t(r);c.current=r;let[l,d]=s(!1),f=i(()=>{a.current.invalidateQueries({queryKey:_o})},[]),p=t(void 0);p.current||=Vr({delayMs:vo,invalidate:()=>{c.current?d(!0):f()}}),o(()=>()=>p.current?.cancel(),[]),o(()=>{r||!l||(d(!1),f())},[r,l,f]);let m=i(()=>{d(!1),f()},[f]);return Ye(q.PipelineAnalyticsDetectionEvent,()=>{p.current?.trigger()}),Ye(q.PipelineAnalyticsTrackEnded,()=>{p.current?.trigger()}),{pending:l,refreshNow:m}}l();function bo({groups:t,selected:r,onChange:i,loading:o=!1}){let{t:c}=X(),l=$e(),[u,d]=s(!1),[f,p]=s(``),[m,h]=s(new Set),g=f.trim().toLowerCase(),_=e=>g.length===0||Ge(e,c).toLowerCase().includes(g),v=n(()=>t.map(e=>({macro:e.macro,subs:e.subs.filter(t=>_(t)||_(e.macro))})).filter(e=>_(e.macro)||e.subs.length>0),[t,g]),y=e=>h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),b=e=>{let t=new Set(r),n=r.has(e.macro.kind)&&e.subs.every(e=>r.has(e.kind)),a=[e.macro.kind,...e.subs.map(e=>e.kind)];if(n)for(let e of a)t.delete(e);else for(let e of a)t.add(e);i(t)},x=e=>{let t=new Set(r);t.has(e)?t.delete(e):t.add(e),i(t)},S=()=>i(new Set),C=r.size;return e(`div`,{className:`relative`,children:[e(`button`,{type:`button`,onClick:()=>d(e=>!e),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${C>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(D,{className:`h-3.5 w-3.5`}),C>0?c(`detectionIntelligence.eventKindFilter.kinds`,`Kinds ({{value1}})`,{value1:String(C)}):c(`detectionIntelligence.eventKindFilter.kinds2`,`Kinds`),a(K,{className:`h-3 w-3`})]}),u&&e(`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:[e(`div`,{className:`mb-2 flex items-center gap-1 rounded border border-border px-1.5`,children:[a(z,{className:`h-3.5 w-3.5 text-foreground-subtle`}),a(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:c(`detectionIntelligence.eventKindFilter.searchKinds`,`Search kinds…`),className:`w-full bg-transparent py-1 text-xs outline-none`}),C>0&&a(`button`,{type:`button`,onClick:S,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:c(`detectionIntelligence.eventKindFilter.clear`,`Clear`)})]}),v.length===0&&a(`div`,{className:`px-1 py-2 text-[11px] text-foreground-subtle`,children:o?c(`detectionIntelligence.eventKindFilter.loadingKinds`,`Loading kinds…`):g.length>0?c(`detectionIntelligence.eventKindFilter.noKindMatchesThatSearch`,`No kind matches that search.`):c(`detectionIntelligence.eventKindFilter.theseCamerasAdvertiseNoEvent`,`These cameras advertise no event kinds.`)}),v.map(t=>{let n=Je(t.macro.iconId),i=m.has(t.macro.kind)||g.length>0,o=r.has(t.macro.kind);return e(`div`,{className:`mb-0.5`,children:[e(`div`,{className:`flex items-center gap-1`,children:[t.subs.length>0?a(`button`,{type:`button`,onClick:()=>y(t.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":c(`detectionIntelligence.eventKindFilter.expand`,`Expand`),children:a(i?K:re,{className:`h-3 w-3`})}):a(`span`,{className:`w-3`}),e(`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:[a(`input`,{type:`checkbox`,checked:o,onChange:()=>b(t),className:`accent-primary`}),a(n,{className:`h-3.5 w-3.5`,style:{color:l(t.macro.kind)}}),a(`span`,{className:`font-medium`,children:Ge(t.macro,c)})]})]}),i&&t.subs.map(t=>{let n=Je(t.iconId);return e(`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:[a(`input`,{type:`checkbox`,checked:r.has(t.kind),onChange:()=>x(t.kind),className:`accent-primary`}),a(n,{className:`h-3.5 w-3.5`,style:{color:l(t.kind)}}),a(`span`,{children:Ge(t,c)})]},t.kind)})]},t.macro.kind)})]})]})}function xo(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 So(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var Co=new Set([`detection`,`package`]);function wo(e,t){return[...xo(e,t).values()].filter(e=>e.parentKind===null&&Co.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function To(e,t){let n=xo(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,So(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))}l();function Eo(){let[e,n]=s(!1),r=t(null),[a,c]=s(0),l=i(e=>{r.current!==e&&(r.current=e,c(e=>e+1))},[]);return o(()=>{let e=r.current;if(!e||typeof IntersectionObserver>`u`){n(!1);return}let t=new IntersectionObserver(e=>{let t=e[e.length-1];t&&n(!t.isIntersecting)},{rootMargin:`64px 0px 0px 0px`,threshold:0});return t.observe(e),()=>t.disconnect()},[a]),{ref:l,scrolledPast:e}}l();var Do=[`events-feed`],Oo=60,ko=[{value:`importance`,labelKey:`detectionIntelligence.eventsSection.sortImportance`,icon:ce},{value:`time`,labelKey:`detectionIntelligence.eventsSection.sortRecent`,icon:N}];function Ao(){let{t}=X(),r=u(),i=Oe(),c=Be(),[l,f]=s(zn),[p,m]=s(new Set),[h,g]=s(new Set),[_,v]=s(0),[y,b]=s(`time`),[S,C]=s(new Set),[w,T]=s(null),[E,D]=s(()=>Date.now());o(()=>{let e=setInterval(()=>D(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:O,until:k}=n(()=>$r({fromMs:l.fromMs,toMs:l.toMs},E),[l.fromMs,l.toMs,E]),A=Eo(),{pending:j,refreshNow:M}=yo({paused:w!==null||S.size>0||A.scrolledPast}),{data:N=[]}=et({isCamera:!0,projection:`slim`}),P=n(()=>N.map(e=>e.id),[N]),{data:F,isLoading:I}=gt({deviceIds:P},{enabled:P.length>0,staleTime:5*6e4}),R=n(()=>To(F??[],p),[F,p]),z=Li(),B=z.isPending,{rows:V,isLoading:H}=go({deviceIds:P,since:O,until:k,minImportance:_>0?_:void 0,classFilter:h.size===1?[...h][0]:void 0}),U=n(()=>{let e=new Map;for(let t of N??[])e.set(t.id,t.name);return e},[N]),G=e=>U.get(e)??t(`detectionIntelligence.cameraFallback`,{id:String(e)}),te=n(()=>Kn(V).map(e=>({id:e,name:G(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[V,U]),ne=n(()=>Yr(Xr(V,{cameras:p,classes:h,minImportance:_}),y),[V,p,h,_,y]),K=nr(ne,Oo,n(()=>JSON.stringify([[...p].sort((e,t)=>e-t),[...h].sort(),_,y,O,k]),[p,h,_,y,O,k])),re=()=>{r.invalidateQueries({queryKey:Do})},ie=()=>C(new Set);function q(e){C(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function ae(){if(S.size===0||!Pi)return;let e=Qr(V,S),n=[...e.values()].reduce((e,t)=>e+t.length,0);n!==0&&(async()=>{await c({title:t(`detectionIntelligence.eventsSection.deleteTitle`,{count:n}),message:t(`detectionIntelligence.eventsSection.deleteMessage`,{count:n}),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&oe(e)})()}function oe(e){let n=[...e];Promise.allSettled(n.map(([e,t])=>z.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{re();let r=[],a=new Set;if(e.forEach((e,t)=>{let i=n[t];if(!i)return;let[o,s]=i;if(e.status===`fulfilled`)for(let e of s)a.add(Zr(o,e));else r.push(o)}),C(e=>{let t=new Set(e);for(let e of a)t.delete(e);return t}),r.length>0){let e=r.map(e=>G(e)).join(`, `);i({title:t(`detectionIntelligence.eventsSection.someTracksWereNotDeleted`,`Some tracks were not deleted`),message:t(`detectionIntelligence.eventsSection.failedToDeleteTracksOn`,`Failed to delete tracks on: {{names}}. They remain selected — retry, or check the server logs.`,{names:e}),variant:`danger`})}})}let se=ne.length!==V.length;return e(`div`,{className:`relative space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[a(ur,{onChange:f}),a(cr,{cameras:te,selected:p,onChange:m}),a(bo,{groups:R,selected:h,onChange:g,loading:I}),e(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[a(`span`,{children:t(`detectionIntelligence.eventsSection.minScore`,`Min score`)}),a(`input`,{type:`range`,min:0,max:1,step:.05,value:_,onChange:e=>v(Number(e.target.value)),className:`h-1 w-24 cursor-pointer accent-primary`,"aria-label":t(`detectionIntelligence.eventsSection.minimumImportance`,`Minimum importance`)}),a(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(_*100)})]}),a(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:ko.map(n=>{let r=n.icon;return e(`button`,{type:`button`,onClick:()=>b(n.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${y===n.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(r,{className:`h-3.5 w-3.5`}),` `,t(n.labelKey)]},n.value)})}),!H&&a(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:se?t(`detectionIntelligence.eventsSection.ofEvents`,`{{value1}} of {{value2}} events`,{value1:String(ne.length),value2:String(V.length)}):t(`detectionIntelligence.eventsSection.eventCount`,{count:ne.length})})]}),S.size>0&&e(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[a(`span`,{className:`text-xs font-medium text-foreground`,children:t(`common.selectedCount`,{count:S.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[a(`span`,{title:Pi?void 0:`Track deletion arrives with the next server update`,children:e(J,{variant:`secondary`,onClick:ae,disabled:!Pi||B,children:[B?a(W,{className:`h-3.5 w-3.5 animate-spin`}):a(x,{className:`h-3.5 w-3.5`}),` `,t(`common.delete`,`Delete`)]})}),a(J,{variant:`ghost`,onClick:ie,disabled:B,children:a(L,{className:`h-3.5 w-3.5`})})]})]}),j&&a(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:a(`button`,{type:`button`,onClick:M,className:`rounded-full border border-primary/40 bg-surface px-3 py-1 text-[11px] font-medium text-primary shadow-sm hover:bg-primary/10`,children:t(`detectionIntelligence.eventsSection.newEventsRefresh`,`New events — refresh`)})}),H?a(it,{status:`pending`,pendingMessage:`Loading events…`,testId:`events-grid`}):ne.length===0?a(we,{icon:ee,title:se?t(`detectionIntelligence.eventsSection.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.eventsSection.noKeyEventsInThis`,`No key events in this window`),description:se?t(`detectionIntelligence.eventsSection.widenTheDateRangeClear`,`Widen the date range, clear cameras or kinds, or lower the min score.`):t(`detectionIntelligence.eventsSection.capturedTracksAppearHereWhen`,`Captured tracks appear here when the pipeline scores a key event.`)}):e(d,{children:[a(`div`,{ref:A.ref,"aria-hidden":!0,className:`h-0`}),a(it,{status:`ready`,testId:`events-grid`,children:K.pageItems.map(e=>a(si,{row:e,cameraName:G(e.deviceId),nowMs:E,selected:S.has(Zr(e.deviceId,e.trackId)),onToggleSelect:q,onOpenDetail:T},Zr(e.deviceId,e.trackId)))}),a(ar,{currentPage:K.page,totalItems:K.totalItems,pageSize:K.pageSize,onPageChange:K.setPage,itemNoun:`events`})]}),w&&a(Gi,{row:w,cameraName:G(w.deviceId),deleteAvailable:Pi,onClose:()=>T(null),onDeleted:()=>{re(),T(null)},onFlagsChanged:e=>{T(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug,favourited:e.favourited}:t)}})]})}var jo=`/addon/training`;function Mo(){let{t}=X(),n=It();return e(Mt,{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:[e(`div`,{className:`flex min-w-0 flex-1 items-start gap-2.5`,children:[a(g,{className:`mt-0.5 h-4 w-4 shrink-0 text-primary`,"aria-hidden":!0}),e(`div`,{className:`min-w-0 space-y-0.5`,children:[a(`p`,{className:`text-xs font-medium text-foreground`,children:t(`detectionIntelligence.retrainTabCallout.trainingFromThisFeed`,`Training from this feed`)}),a(`p`,{className:`${ie} leading-relaxed`,children:t(`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.`)})]})]}),a(J,{variant:`outline`,size:`sm`,className:`shrink-0 self-start sm:self-center`,onClick:()=>n(jo),children:t(`detectionIntelligence.retrainTabCallout.openTraining`,`Open Training`)})]})}l();var No=50,Po=350,Fo=[{value:`loose`,labelKey:`detectionIntelligence.semanticEventSearch.looseLabel`,titleKey:`detectionIntelligence.semanticEventSearch.looseTitle`},{value:`balanced`,labelKey:`detectionIntelligence.semanticEventSearch.balancedLabel`,titleKey:`detectionIntelligence.semanticEventSearch.balancedTitle`},{value:`strict`,labelKey:`detectionIntelligence.semanticEventSearch.strictLabel`,titleKey:`detectionIntelligence.semanticEventSearch.strictTitle`}];function Io(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 Lo({onActiveChange:t}){let{t:r}=X(),[i,c]=s(``),[l,u]=s(`loose`),[d,f]=s(null),[p,m]=s(null),[h,g]=s(null),_=mt(i,Po).trim(),v=_.length>0;o(()=>{t(v)},[v,t]);let[y,b]=s(()=>Date.now());o(()=>{let e=setInterval(()=>b(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:x=[]}=et({isCamera:!0,projection:`slim`}),S=n(()=>{let e=new Map;for(let t of x)e.set(t.id,t.name);return e},[x]),C=e=>S.get(e)??r(`detectionIntelligence.cameraFallback`,{id:String(e)}),w=n(()=>x.map(e=>e.id),[x]),{data:T}=gt({deviceIds:w},{enabled:w.length>0,staleTime:5*6e4}),E=n(()=>wo(T??[],new Set(p===null?[]:[p])),[T,p]);o(()=>{d!==null&&(E.some(e=>e.kind===d)||f(null))},[E,d]);let{data:D,isFetching:O,isError:k,error:A}=Tt({text:_,strictness:l,limit:No,classFilter:d??void 0,deviceId:p??void 0},{enabled:v}),j=n(()=>[...D??[]].sort((e,t)=>t.score-e.score).map(e=>({...Io(e),score:e.score})),[D]);function M(e){f(t=>t===e?null:e)}return e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(`div`,{className:`relative min-w-[16rem] flex-1`,children:[a(z,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),a(`input`,{type:`text`,value:i,onChange:e=>c(e.target.value),placeholder:r(`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":r(`detectionIntelligence.semanticEventSearch.semanticEventSearch`,`Semantic event search`)}),i&&a(`button`,{type:`button`,onClick:()=>c(``),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":r(`detectionIntelligence.semanticEventSearch.clearSearch`,`Clear search`),children:a(L,{className:`h-3.5 w-3.5`})})]}),O&&v&&a(W,{className:`h-4 w-4 shrink-0 animate-spin text-foreground-subtle`})]}),e(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[a(`div`,{className:`flex items-center gap-1`,children:E.map(e=>a(`button`,{type:`button`,onClick:()=>M(e.kind),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${d===e.kind?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:Ge(e)},e.kind))}),e(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[a(`span`,{children:r(`detectionIntelligence.semanticEventSearch.camera`,`Camera`)}),a(bt,{value:p===null?``:String(p),onChange:e=>m(e.target.value===``?null:Number(e.target.value)),className:`h-7 text-xs`,"aria-label":r(`detectionIntelligence.semanticEventSearch.filterByCamera`,`Filter by camera`),options:[{value:``,label:r(`detectionIntelligence.semanticEventSearch.all`,`All`)},...x.map(e=>({value:String(e.id),label:e.name}))]})]}),e(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[a(`span`,{children:r(`detectionIntelligence.semanticEventSearch.match`,`Match`)}),a(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Fo.map(e=>a(`button`,{type:`button`,onClick:()=>u(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${l===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:r(e.titleKey),children:r(e.labelKey)},e.value))})]}),v&&!O&&!k&&a(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:r(`common.matches`,{count:j.length})})]})]}),v&&e(`div`,{className:`space-y-3`,children:[k&&e(`p`,{className:`py-4 text-xs text-danger`,children:[r(`detectionIntelligence.semanticEventSearch.searchFailed`,`Search failed:`),` `,A instanceof Error?A.message:r(`detectionIntelligence.semanticEventSearch.unknownError`,`unknown error`),`. Check that the CLIP embedding step is enabled.`]}),!k&&O&&j.length===0&&a(it,{status:`pending`,pendingMessage:`Searching…`,testId:`semantic-events-grid`}),!k&&!O&&j.length===0&&a(it,{status:`empty`,emptyMessage:r(`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&&a(it,{status:`ready`,testId:`semantic-events-grid`,children:j.map(e=>a(si,{row:e,cameraName:C(e.deviceId),nowMs:y,score:e.score,onOpenDetail:g},e.id))})]}),h&&a(Gi,{row:h,cameraName:C(h.deviceId),deleteAvailable:Pi,onClose:()=>g(null),onDeleted:()=>g(null)})]})}l();function Ro(e,t){let n=Math.max(0,Math.round((e-t)/6e4));if(n<1)return Y.t(`helpers.relativeTime.justNow`);if(n<60)return`${String(n)}m`;let r=Math.floor(n/60);return`${String(r)}h ${String(n%60)}m`}function zo({row:t,cameraName:n,nowMs:r}){let{t:i}=X(),o=Ht(t.keyFrameMediaId===void 0?void 0:Gt(t.keyFrameMediaId));return e(`div`,{className:`flex flex-col overflow-hidden rounded-md border border-border bg-surface`,children:[e(`div`,{className:`relative aspect-video overflow-hidden bg-surface-hover`,children:[o.src?a(`img`,{src:o.src,alt:i(`detectionIntelligence.stationarySection.parkedOn`,`Parked {{className}} on {{cameraName}}`,{className:t.className,cameraName:n}),className:`h-full w-full object-cover`}):a(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:a(ue,{className:`h-6 w-6`})}),a(`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:t.label??t.className})]}),e(`div`,{className:`flex flex-col gap-0.5 p-1.5`,children:[a(`span`,{className:`truncate text-[11px] text-foreground`,children:n}),a(`span`,{className:`text-[10px] text-foreground-subtle`,children:i(`common.parkedSince`,{since:Ro(r,t.becameStationaryAt)})})]})]})}function Bo(){let{t}=X(),[r,i]=s(!1),o=Date.now(),{data:c=[]}=et({isCamera:!0,projection:`slim`}),l=n(()=>c.map(e=>e.id),[c]),u=n(()=>{let e=new Map;for(let t of c)e.set(t.id,t.name);return e},[c]),{rows:d,unreadableCount:f}=Vt(l);return d.length===0&&f===0?null:e(`div`,{className:`rounded-md border border-border bg-surface/40`,children:[e(`button`,{type:`button`,onClick:()=>i(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,children:[a(r?K:re,{className:`h-4 w-4 text-foreground-subtle`}),a(ue,{className:`h-4 w-4 text-foreground-subtle`}),a(`span`,{className:`text-sm font-semibold text-foreground`,children:t(`detectionIntelligence.stationarySection.stationary`,`Stationary`)}),a(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:d.length}),a(`span`,{className:`ml-2 text-[11px] text-foreground-subtle`,children:t(`detectionIntelligence.stationarySection.parkedObjectsKeptOutOf`,`Parked objects — kept out of the event feed`)}),f>0?a(`span`,{className:`ml-2 text-[11px] text-warning`,children:t(`detectionIntelligence.stationarySection.unreadable`,{count:f})}):null]}),r&&a(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:d.map(e=>a(zo,{row:e,cameraName:u.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:o},e.id))})]})}l();function Vo(){let[t,n]=s(!1);return e(`section`,{className:`space-y-3`,children:[a(Mo,{}),a(Lo,{onActiveChange:n}),!t&&a(Bo,{}),!t&&a(Ao,{})]})}function Ho(){let{t:e}=X(),[t]=Rt();return t.get(`section`)===`retrain`?a(Ft,{to:`/addon/training`,replace:!0}):a(Bt,{sectionsOnly:!0,paramName:`section`,defaultSection:`feed`,sectionsLabel:`Events sections`,sections:[{id:`feed`,label:e(`events.feed`,`Feed`),content:a(Vo,{})},{id:`debug`,label:e(`events.debug`,`Debug`),content:a(fo,{})}]})}function Uo(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}l();var Wo=[[`plateGallery`]];function Go({plateIds:t,vehicles:n,onDone:r}){let{t:i}=X(),o=u(),c=ot(),l=Et(),[d,f]=s(``),[p,m]=s(!1),[h,g]=s(null),_=t!==null&&t.length>0,v=t?.length??0;function y(){m(!1),f(``),g(null)}function b(){y(),r()}function x(e){!t||t.length===0||c.mutate({plateIds:[...t],vehicleId:e},{onSettled:()=>{o.invalidateQueries({queryKey:Wo}),b()}})}function S(){!t||!d.trim()||l.mutate({name:d.trim()},{onSuccess:e=>{e?.id&&x(e.id)},onError:()=>{o.invalidateQueries({queryKey:Wo}),b()}})}let C=c.isPending||l.isPending;return a(rt,{open:_,onOpenChange:e=>!e&&b(),children:e(pt,{children:[e(Ze,{children:[a(Dt,{children:v>1?i(`detectionIntelligence.assignPlateDialog.assignPlatesToVehicle`,`Assign {{value1}} plates to vehicle`,{value1:String(v)}):i(`detectionIntelligence.assignPlateDialog.assignPlateToVehicle`,`Assign plate to vehicle`)}),a(lt,{children:i(`detectionIntelligence.assignPlateDialog.selectAnExistingVehicleOr`,`Select an existing vehicle or create a new one.`)})]}),a(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:n.map(t=>e(`button`,{type:`button`,onClick:()=>g(t.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${h===t.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[a(`span`,{className:`font-medium`,children:t.name}),a(`span`,{className:`ml-2 text-foreground-subtle`,children:i(`detectionIntelligence.assignPlateDialog.plates`,{count:t.sampleCount})})]},t.id))}),p?a(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:a(Fe,{placeholder:i(`detectionIntelligence.assignPlateDialog.newVehicleName`,`New vehicle name…`),value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&S()},autoFocus:!0,className:`flex-1`})}):a(`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…`)}),e(ct,{children:[a(J,{variant:`secondary`,onClick:b,disabled:C,children:i(`common.cancel`,`Cancel`)}),p?e(J,{variant:`primary`,onClick:S,disabled:C||!d.trim(),children:[C&&a(W,{className:`h-3.5 w-3.5 animate-spin`}),i(`detectionIntelligence.assignPlateDialog.createAssign`,`Create & assign`)]}):e(J,{variant:`primary`,onClick:()=>h&&x(h),disabled:C||!h,children:[C&&a(W,{className:`h-3.5 w-3.5 animate-spin`}),v>1?i(`detectionIntelligence.assignCount`,{count:v}):i(`common.assign`)]})]})]})})}l();var Ko=[[`plateGallery`]];function qo(e){let[t,n]=s(null),[r,i]=s(null),[a,c]=s(!1);return o(()=>{if(n(null),i(null),c(!1),e===void 0)return;let t=!1,r=null;return(async()=>{try{let i=await Wt(Gt(e));if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||c(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),o(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>c(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function Jo(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 Yo({label:t,value:n,mono:r}){return e(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[a(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:t}),a(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${r?`font-mono`:``}`,title:n,children:n})]})}function Xo({box:e}){let{t}=X();return a(`div`,{className:`pointer-events-none absolute rounded-[3px] border-2 border-primary shadow-[0_0_0_9999px_rgba(0,0,0,0.28)]`,style:{left:`${String(e.x*100)}%`,top:`${String(e.y*100)}%`,width:`${String(e.width*100)}%`,height:`${String(e.height*100)}%`},children:a(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:t(`detectionIntelligence.plateDetailPanel.plate`,`Plate`)})})}function Zo({plate:t,cameraName:r,onClose:i,onAssign:c,onUnassign:l,onDelete:d,actionsPending:f}){let{t:p}=X(),m=u(),{data:h,isFetching:g}=At({plateId:t?.plateId??``},{enabled:t!==null}),v=Xe(),[b,S]=s(`frame`),[C,w]=s(!1),[E,D]=s(``),{frameSrc:O,naturalWidth:k,naturalHeight:A,failed:j}=qo(t?.keyFrameMediaId);o(()=>{w(!1),D(``),S(`frame`)},[t?.plateId]);let N=n(()=>{let e=Jo(h??[]);return e?e.url:Uo(t)},[h,t]),P=n(()=>!t?.plateBbox||k===null||A===null?null:fr(t.plateBbox,k,A),[t?.plateBbox,k,A]);if(t===null)return null;let F=t.keyFrameMediaId!==void 0&&!j,I=F&&b===`frame`,R=t.assigned?t.vehicleName??`Assigned`:t.recognizedVehicleId?`${t.vehicleName??`Recognized`} (suggested)`:`Unassigned`,z=`${String(Math.round(t.score*100))}%${t.corrected?` · corrected`:``}`;function B(){t&&(D(t.text),w(!0))}function V(){if(!t)return;let e=E.trim().toUpperCase();if(!e||e===t.text){w(!1);return}v.mutate({plateId:t.plateId,text:e},{onSettled:()=>{m.invalidateQueries({queryKey:Ko}),w(!1)}})}return a(rt,{open:!0,onOpenChange:e=>!e&&i(),children:e(pt,{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:[a(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:e(`div`,{className:`min-w-0`,children:[a(`div`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:t.text||p(`detectionIntelligence.plateDetailPanel.plateDetail`,`Plate detail`)}),a(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:r})]})}),e(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[F&&e(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[e(`button`,{type:`button`,onClick:()=>S(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${b===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(U,{className:`h-3.5 w-3.5`}),` `,p(`detectionIntelligence.detailPanel.fullFrame`)]}),e(`button`,{type:`button`,onClick:()=>S(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${b===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(ge,{className:`h-3.5 w-3.5`}),` `,p(`detectionIntelligence.detailPanel.crop`)]})]}),I&&O?a(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:a(mr,{src:O,alt:p(`detectionIntelligence.plateDetailPanel.fullFrameWithDetectedPlate`,`Full frame with detected plate`),fit:`natural`,className:`w-full`,overlay:P?a(Xo,{box:P}):void 0})}):N?e(`div`,{className:`relative aspect-[2/1] w-full overflow-hidden rounded-lg border border-border bg-background`,children:[a(mr,{src:N,alt:p(`detectionIntelligence.plateDetailPanel.detectedPlate`,`Detected plate`),className:`h-full w-full`}),g&&a(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:a(W,{className:`h-3.5 w-3.5 animate-spin`})})]}):e(`div`,{className:`flex aspect-[2/1] w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[a(M,{className:`h-8 w-8 text-warning/70`}),a(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:p(`detectionIntelligence.plateDetailPanel.noImage`,`No image`)}),a(`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.`)})]}),a(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-2`,children:e(`div`,{className:`flex items-center justify-between gap-3`,children:[a(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:p(`detectionIntelligence.plateDetailPanel.plateText`,`Plate text`)}),C?e(`div`,{className:`flex min-w-0 flex-1 items-center justify-end gap-1.5`,children:[a(Fe,{value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`&&V(),e.key===`Escape`&&w(!1)},className:`h-7 max-w-[10rem] text-right font-mono text-xs uppercase`,autoFocus:!0}),a(`button`,{type:`button`,onClick:V,disabled:v.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":p(`detectionIntelligence.plateDetailPanel.saveCorrectedText`,`Save corrected text`),children:v.isPending?a(W,{className:`h-3.5 w-3.5 animate-spin`}):a(T,{className:`h-3.5 w-3.5`})}),a(`button`,{type:`button`,onClick:()=>w(!1),className:`text-foreground-subtle hover:text-foreground`,"aria-label":p(`common.cancel`,`Cancel`),children:a(L,{className:`h-3.5 w-3.5`})})]}):e(`button`,{type:`button`,onClick:B,className:`group flex min-w-0 items-center gap-1.5`,title:p(`detectionIntelligence.plateDetailPanel.correctTheOcrReading`,`Correct the OCR reading`),children:[a(`span`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:t.text||`—`}),a(y,{className:`h-3 w-3 shrink-0 text-foreground-subtle group-hover:text-foreground`})]})]})}),e(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[a(Yo,{label:p(`detectionIntelligence.plateDetailPanel.camera`,`Camera`),value:r}),a(Yo,{label:p(`detectionIntelligence.plateDetailPanel.captured`,`Captured`),value:Zn(t.timestamp)}),a(Yo,{label:p(`detectionIntelligence.plateDetailPanel.confidence`,`Confidence`),value:z}),a(Yo,{label:p(`detectionIntelligence.plateDetailPanel.vehicle`,`Vehicle`),value:R}),a(Yo,{label:p(`detectionIntelligence.plateDetailPanel.track`,`Track`),value:t.trackId,mono:!0})]})]}),e(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[t.assigned?e(J,{variant:`secondary`,onClick:()=>l(t.plateId),disabled:f,children:[a(me,{className:`h-3.5 w-3.5`}),` `,p(`detectionIntelligence.detailPanel.detach`)]}):e(J,{variant:`primary`,onClick:()=>c(t.plateId),disabled:f,children:[a(_,{className:`h-3.5 w-3.5`}),` `,p(`common.assign`)]}),e(J,{variant:`secondary`,onClick:()=>d(t.plateId),disabled:f,children:[a(x,{className:`h-3.5 w-3.5`}),` `,p(`common.delete`)]})]})]})})}l();var Qo=[[`plateGallery`]],$o=500,es=120;function ts({plate:t,cameraName:n,nowMs:r,selected:i,onToggleSelect:o,onAssign:s,onOpenDetail:c}){let{t:l}=X(),d=u(),f=Ce(),p=Pt(),m=()=>{d.invalidateQueries({queryKey:Qo})},h=()=>c(t.plateId),g=Uo(t);return e(`div`,{className:`relative flex flex-col overflow-hidden rounded-md border bg-surface ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[e(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[g===null?e(`button`,{type:`button`,onClick:h,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:l(`detectionIntelligence.recentPlates.noCropImageThePlate`,`No crop image — the plate's crop media is missing. Safe to delete.`),children:[a(M,{className:`h-7 w-7 text-warning/70`}),a(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:l(`detectionIntelligence.recentPlates.noCrop`,`No crop`)})]}):a(`img`,{src:g,alt:l(`detectionIntelligence.recentPlates.plateFrom`,`Plate {{text}} from {{cameraName}}`,{text:t.text,cameraName:n}),onClick:h,className:`h-full w-full cursor-zoom-in object-cover`}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(t.plateId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?l(`detectionIntelligence.recentPlates.deselect`,`Deselect`):l(`detectionIntelligence.recentPlates.select`,`Select`),children:i?a(fe,{className:`h-4 w-4 text-primary`}):a(O,{className:`h-4 w-4`})}),t.corrected&&e(`span`,{className:`absolute right-0 top-0 z-10 flex items-center gap-0.5 rounded-bl-md bg-primary/80 px-1 py-0.5 text-[8px] font-semibold uppercase tracking-wide text-white`,title:l(`detectionIntelligence.recentPlates.manuallyCorrected`,`Manually corrected`),children:[a(pe,{className:`h-3 w-3`}),` `,l(`detectionIntelligence.recentPlates.fixed`)]})]}),e(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[a(`p`,{className:`truncate font-mono text-xs font-bold tracking-wide text-foreground`,title:t.text,children:t.text||`—`}),a(`p`,{className:`truncate text-[10px] text-foreground-subtle`,title:n,children:n}),a(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:Yn(t.timestamp,r)}),t.vehicleName&&a(`p`,{className:`truncate text-[10px] font-medium text-primary`,title:t.vehicleName,children:t.vehicleName})]}),e(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[t.assigned?a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),f.mutate({plateId:t.plateId},{onSettled:m})},disabled:f.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":l(`detectionIntelligence.recentPlates.detachPlate`,`Detach plate`),title:l(`detectionIntelligence.recentPlates.detach`,`Detach`),children:f.isPending?a(W,{className:`h-4 w-4 animate-spin`}):a(me,{className:`h-4 w-4`})}):a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s(t.plateId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":l(`detectionIntelligence.recentPlates.assignPlateToVehicle`,`Assign plate to vehicle`),title:l(`detectionIntelligence.recentPlates.assignToVehicle`,`Assign to vehicle`),children:a(_,{className:`h-4 w-4`})}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),p.mutate({plateId:t.plateId},{onSettled:m})},disabled:p.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":l(`detectionIntelligence.recentPlates.deletePlate`,`Delete plate`),title:l(`detectionIntelligence.recentPlates.deletePlate`,`Delete plate`),children:p.isPending?a(W,{className:`h-4 w-4 animate-spin`}):a(x,{className:`h-4 w-4`})})]})]})}var ns=[{labelKey:`common.all`,value:`all`},{labelKey:`detectionIntelligence.recentPlates.filterUnassigned`,value:`unassigned`},{labelKey:`detectionIntelligence.recentPlates.filterAssigned`,value:`assigned`}];function rs(e,t){return t===`unassigned`?e.filter(e=>!e.assigned):t===`assigned`?e.filter(e=>e.assigned):e}function is(){let{t}=X(),r=u(),[i,o]=s(`all`),[c,l]=s(zn),[f,p]=s(new Set),[m,h]=s(new Set),[g,v]=s(null),[y,b]=s(null),{data:S,isLoading:C}=Le({limit:$o,includeCrops:!1},{refetchInterval:3e4}),{data:w=[]}=Ot(),{data:T}=et({isCamera:!0,projection:`slim`}),E=Ce(),D=Me(),O=Pt(),k=Date.now(),A=S??[],j=n(()=>{let e=new Map;for(let t of T??[])e.set(t.id,t.name);return e},[T]),N=e=>j.get(e)??t(`detectionIntelligence.cameraFallback`,{id:String(e)}),P=n(()=>Kn(A).map(e=>({id:e,name:N(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[A,j]),F=n(()=>Gn(Wn(rs(A,i),c),f),[A,i,c,f]),I=nr(F,es,n(()=>JSON.stringify([i,c.fromMs,c.toMs,[...f].sort((e,t)=>e-t)]),[i,c.fromMs,c.toMs,f])),R=n(()=>new Map(A.map(e=>[e.plateId,e])),[A]),z=y===null?null:R.get(y)??null,B=()=>{r.invalidateQueries({queryKey:Qo})},V=()=>h(new Set);function H(e){h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}let U=[...m],G=D.isPending||O.isPending,ee=E.isPending||O.isPending;function te(){U.length!==0&&D.mutate({plateIds:U},{onSettled:()=>{B(),V()}})}function ne(){U.length!==0&&Promise.allSettled(U.map(e=>O.mutateAsync({plateId:e}))).then(()=>{B(),V()})}function K(e){b(null),v([e])}function re(e){E.mutate({plateId:e},{onSettled:B}),b(null)}function ie(e){O.mutate({plateId:e},{onSettled:B}),b(null)}let q=F.length!==A.length;return e(`div`,{className:`relative space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[a(`div`,{className:`flex items-center gap-1`,children:ns.map(e=>a(`button`,{type:`button`,onClick:()=>o(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${i===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:t(e.labelKey)},e.value))}),a(ur,{onChange:l}),a(cr,{cameras:P,selected:f,onChange:p}),!C&&a(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:q?t(`detectionIntelligence.recentPlates.ofPlates`,`{{value1}} of {{value2}} plates`,{value1:String(F.length),value2:String(A.length)}):t(`detectionIntelligence.recentPlates.plateCount`,{count:F.length})})]}),m.size>0&&e(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[a(`span`,{className:`text-xs font-medium text-foreground`,children:t(`common.selectedCount`,{count:m.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[e(J,{variant:`primary`,onClick:()=>v(U),disabled:G,children:[a(_,{className:`h-3.5 w-3.5`}),` `,t(`common.assign`)]}),e(J,{variant:`secondary`,onClick:te,disabled:G,children:[D.isPending?a(W,{className:`h-3.5 w-3.5 animate-spin`}):a(me,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.recentPlates.detach`,`Detach`)]}),e(J,{variant:`secondary`,onClick:ne,disabled:G,children:[a(x,{className:`h-3.5 w-3.5`}),` `,t(`common.delete`)]}),a(J,{variant:`ghost`,onClick:V,disabled:G,children:a(L,{className:`h-3.5 w-3.5`})})]})]}),C?a(it,{status:`pending`,pendingMessage:`Loading plates…`,testId:`plates-grid`}):F.length===0?a(we,{icon:M,title:A.length>0?t(`detectionIntelligence.recentPlates.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.recentPlates.noPlatesRecognizedYet`,`No plates recognized yet`),description:A.length>0?t(`detectionIntelligence.recentPlates.widenTheDateRangeOr`,`Widen the date range or clear the camera filter.`):t(`detectionIntelligence.recentPlates.plateReadsAppearHereWhen`,`Plate reads appear here when the detection pipeline OCRs a vehicle.`)}):e(d,{children:[a(it,{status:`ready`,testId:`plates-grid`,children:I.pageItems.map(e=>a(ts,{plate:e,cameraName:N(e.deviceId),nowMs:k,selected:m.has(e.plateId),onToggleSelect:H,onAssign:e=>v([e]),onOpenDetail:b},e.plateId))}),a(ar,{currentPage:I.page,totalItems:I.totalItems,pageSize:I.pageSize,onPageChange:I.setPage,itemNoun:`plates`})]}),a(Zo,{plate:z,cameraName:z?N(z.deviceId):``,onClose:()=>b(null),onAssign:K,onUnassign:re,onDelete:ie,actionsPending:ee}),a(Go,{plateIds:g,vehicles:w,onDone:()=>{v(null),V()}})]})}l();var as=[[`plateGallery`]];function os({vehicleId:t}){let{t:n}=X(),r=u(),{data:i,isLoading:o}=xe({vehicleId:t}),s=ze();function c(e){s.mutate({vehicleId:t,sampleId:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:as})}})}return o?e(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[a(W,{className:`h-3.5 w-3.5 animate-spin`}),n(`detectionIntelligence.vehiclesList.loadingPlates`,`Loading plates…`)]}):!i||i.length===0?a(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:n(`detectionIntelligence.vehiclesList.noPlatesYet`,`No plates yet.`)}):a(`div`,{className:`mt-2 grid grid-cols-3 gap-2 sm:grid-cols-4 md:grid-cols-6`,children:i.map(t=>e(`div`,{className:`group relative overflow-hidden rounded-md border border-border bg-surface`,children:[e(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[t.base64?a(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:t.text,className:`h-full w-full object-cover`}):a(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:a(v,{className:`h-6 w-6`})}),a(`button`,{type:`button`,onClick:()=>c(t),disabled:s.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":n(`detectionIntelligence.vehiclesList.removePlateSample`,`Remove plate sample`),children:a(L,{className:`h-4 w-4 text-white`})})]}),a(`p`,{className:`truncate px-1.5 py-1 text-center font-mono text-[11px] font-semibold tracking-wide text-foreground`,title:t.text,children:t.text})]},t.id))})}function ss(t){return[{key:`vehicle`,header:Y.t(`detectionIntelligence.vehiclesList.vehicle`,`Vehicle`),sortValue:e=>e.name,render:t=>e(`span`,{className:`flex min-w-0 items-center gap-2`,children:[a(`span`,{className:`h-8 w-12 shrink-0 overflow-hidden rounded border border-border bg-surface-hover`,children:a(Jt,{mediaId:t.coverMediaId,base64:t.coverBase64,alt:t.name,className:`h-full w-full object-cover`,placeholder:a(`span`,{className:`flex h-full w-full items-center justify-center`,children:a(v,{className:`h-4 w-4 text-foreground-subtle`})})})}),a(`span`,{className:`truncate text-sm font-medium text-foreground`,children:t.name})]})},{key:`samples`,header:Y.t(`detectionIntelligence.vehiclesList.plates`,`Plates`),align:`center`,nowrap:!0,sortValue:e=>e.sampleCount,render:e=>a(Pe,{variant:`default`,className:`text-[10px]`,children:e.sampleCount})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:n=>e(`span`,{className:`flex items-center justify-end gap-1`,children:[a(be,{variant:`ghost`,size:`sm`,icon:y,"aria-label":Y.t(`detectionIntelligence.vehiclesList.edit`,`Edit {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onEdit(n)}}),a(be,{variant:`ghost`,size:`sm`,icon:x,"aria-label":Y.t(`detectionIntelligence.vehiclesList.delete`,`Delete {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onDelete(n)}})]})}]}function cs({mode:t,vehicle:n,onClose:r}){let{t:i}=X(),c=u(),[l,d]=s(t===`edit`?n?.name??``:``),f=Et(),p=Te();o(()=>{d(t===`edit`?n?.name??``:``)},[t,n?.id,n?.name]);let m=f.isPending||p.isPending,h=l.trim(),g=t===`edit`&&n!==null&&h===n.name,_=m||h.length===0||g;function y(){c.invalidateQueries({queryKey:as})}function b(){if(!_){if(t===`new`){f.mutate({name:h},{onSuccess:()=>{y(),r()}});return}if(n===null){r();return}p.mutate({id:n.id,name:h},{onSuccess:()=>{y(),r()}})}}return a(ut,{open:!0,onClose:r,title:t===`new`?`Add vehicle`:`Edit ${n?.name??`vehicle`}`,icon:v,width:t===`edit`?`xl`:`lg`,testId:`vehicles-vehicle-form`,footer:e(J,{variant:`primary`,size:`sm`,type:`button`,onClick:b,disabled:_,children:[m?a(W,{className:`h-3.5 w-3.5 animate-spin`}):null,t===`new`?i(`common.add`,`Add`):i(`common.save`,`Save`)]}),children:e(`div`,{className:`space-y-4`,children:[a(Re,{label:i(`detectionIntelligence.vehiclesList.name`,`Name`),required:!0,children:a(Fe,{value:l,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b()},placeholder:i(`detectionIntelligence.vehiclesList.vehicleName`,`Vehicle name…`),autoFocus:!0})}),t===`edit`&&n!==null&&e(`div`,{children:[a(`p`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:i(`detectionIntelligence.vehiclesList.plateSamples`,`Plate samples`)}),a(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:i(`detectionIntelligence.vehiclesList.removeAPlateCropTo`,`Remove a plate crop to drop it from recognition for this vehicle. Assign new plates from Recent recognized plates.`)}),a(os,{vehicleId:n.id})]})]})})}function ls(){let{t}=X(),r=u(),i=Be(),{data:s,isLoading:c}=Ot(),l=Qe(),{state:d,openNew:f,openEdit:p,close:m}=vt(),h=s??[],g=_t(h,{searchText:e=>[e.name]}),_=d.mode===`edit`?h.find(e=>e.id===d.id)??null:null;o(()=>{d.mode===`edit`&&!c&&_===null&&m()},[d.mode,c,_,m]);let y=n(()=>ss({onEdit:e=>p(e.id),onDelete:e=>{(async()=>{await i({title:t(`detectionIntelligence.vehiclesList.deleteVehicle`,`Delete vehicle`),message:t(`detectionIntelligence.vehiclesList.deleteAndAllItsPlate`,`Delete {{name}} and all its plate samples? This cannot be undone.`,{name:e.name}),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&l.mutate({id:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:as}),d.mode===`edit`&&d.id===e.id&&m()}})})()}}),[i,m,l,d,p,r,t]);if(c)return e(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[a(W,{className:`h-4 w-4 animate-spin`}),t(`detectionIntelligence.vehiclesList.loadingVehicles`,`Loading vehicles…`)]});let b=d.mode===`new`||d.mode===`edit`&&_!==null;return e(`div`,{className:`space-y-2`,children:[a(`div`,{className:`flex flex-wrap items-center gap-2`,children:e(J,{variant:`primary`,size:`sm`,type:`button`,onClick:f,children:[a(V,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.vehiclesList.addVehicle`,`Add vehicle`)]})}),(h.length>0||g.active)&&a(ft,{state:g.state,facets:g.facets,labels:{searchPlaceholder:`Search vehicles…`,searchLabel:`Search vehicles`,facetsLabel:`Filter`,clearLabel:`Clear`},onSearch:g.setSearch,onToggleFacet:g.toggleFacet,onClear:g.clear}),g.rows.length===0?a(we,{icon:v,title:g.active?t(`detectionIntelligence.vehiclesList.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.vehiclesList.noVehiclesEnrolledYet`,`No vehicles enrolled yet`),description:g.active?t(`detectionIntelligence.vehiclesList.clearTheSearchOrTry`,`Clear the search or try another name.`):t(`detectionIntelligence.vehiclesList.addAVehicleThenAssign`,`Add a vehicle, then assign plate crops from Recent recognized plates.`)}):a(Se,{columns:y,rows:g.rows,rowKey:e=>e.id,maxBodyHeight:kt,emptyMessage:t(`detectionIntelligence.vehiclesList.noVehiclesEnrolledYet2`,`No vehicles enrolled yet.`),onRowClick:e=>p(e.id)}),b&&a(cs,{mode:d.mode===`new`?`new`:`edit`,vehicle:_,onClose:m})]})}l();var us=[[`plateGallery`]],ds=2e3;function fs(){let e=u(),n=t(e);n.current=e;let r=t(void 0);r.current||=Vr({delayMs:ds,invalidate:()=>{n.current.invalidateQueries({queryKey:us})}}),o(()=>()=>r.current?.cancel(),[]),Ye(q.PipelineAnalyticsPlateGalleryChanged,()=>{r.current?.trigger()})}function ps(){let{t}=X();return fs(),e(`div`,{className:`space-y-3`,children:[a(jt,{headingId:`library-vehicles`,title:t(`plates.vehicles`,`Vehicles`),icon:v,testId:`library-section-vehicles`,children:e(`div`,{className:`${m} space-y-3`,children:[a(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`plates.enrolledVehicleIdentitiesUsedFor`,`Enrolled vehicle identities used for plate recognition. Open a vehicle to rename it or remove plate samples.`)}),a(ls,{})]})}),a(jt,{headingId:`library-recent-plates`,title:t(`plates.recentRecognizedPlates`,`Recent recognized plates`),icon:le,testId:`library-section-recent-plates`,children:e(`div`,{className:`${m} space-y-3`,children:[a(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`plates.licensePlatesReadByThe`,`License plates read by the detection pipeline. Assign them to a vehicle, correct the OCR text, or delete.`)}),a(is,{})]})})]})}function ms(e){return e.states.length===0?3:e.latched?0:e.verdict===`diverged`?1:e.verdict===`unknown`?2:4}function hs(e){let t=[e.divergedAt,e.restoredAt].filter(e=>typeof e==`number`);return t.length===0?null:Math.max(...t)}function gs(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=ms(e.monitor)-ms(t.monitor);if(n!==0)return n;let r=hs(e.monitor)??-1,i=hs(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})}l();var _s={alarm:`danger`,ok:`success`,unknown:`default`},vs={alarm:`Alarm`,ok:`OK`,unknown:`Unknown`};function ys(e,t){let n=hs(e);return n===null?`—`:Y.t(`scenes.transitionAgo`,{duration:te(Math.max(0,t-n))})}function bs(e){return I(e.monitor).tone}function xs(e){let t=Number(e);return Number.isFinite(t)&&t>0?t:null}function Ss(){let{t}=X(),i=et({isCamera:!0,projection:`slim`}),c=n(()=>(i.data??[]).map(e=>({deviceId:e.id,deviceName:e.name})).sort((e,t)=>e.deviceName.localeCompare(t.deviceName)),[i.data]),l=n(()=>c.map(e=>e.deviceId),[c]),u=qt(l),d=n(()=>gs(c,u.results),[c,u.results]),f=_t(d,{searchText:e=>[e.monitor.label,e.deviceName],facetValue:bs}),{state:p,openNew:m,openEdit:g,close:_}=vt(),[v,y]=s(null);o(()=>{if(p.mode===`new`){y(e=>e??l[0]??null);return}y(null)},[p.mode,l]);let b=p.mode===`edit`?xs(p.id):null,x=b===null?``:c.find(e=>e.deviceId===b)?.deviceName??`#${b}`,S=Date.now(),C=[{key:`label`,header:t(`scenes.scene`,`Scene`),sortValue:e=>e.monitor.label,render:e=>a(`span`,{className:`font-medium`,children:e.monitor.label})},{key:`camera`,header:t(`scenes.camera`,`Camera`),nowrap:!0,sortValue:e=>e.deviceName,render:e=>e.deviceName},{key:`state`,header:t(`scenes.state`,`State`),nowrap:!0,sortValue:e=>bs(e),render:e=>{let t=I(e.monitor);return a(Pe,{variant:_s[t.tone],children:t.text})}},{key:`status`,header:t(`scenes.whatItSays`,`What it says`),notSortableReason:`Status is a live sentence, not a comparable value`,render:e=>a(`span`,{className:`text-xs text-foreground-muted`,children:R(e.monitor,S)})},{key:`coverage`,header:t(`scenes.variants`,`Variants`),notSortableReason:`Coverage is a summary string`,render:e=>a(`span`,{className:`text-xs text-foreground-muted`,children:H(e.monitor)})},{key:`transition`,header:t(`scenes.lastChange`,`Last change`),align:`right`,nowrap:!0,sortValue:e=>hs(e.monitor)??0,render:e=>a(`span`,{className:`text-xs tabular-nums text-foreground-muted`,children:ys(e.monitor,S)})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:e=>a(J,{variant:`ghost`,onClick:()=>g(String(e.deviceId)),children:t(`scenes.open`,`Open`)})}];return e(`section`,{className:`space-y-3`,children:[e(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between sm:gap-4`,children:[a(`p`,{className:`text-xs text-foreground-subtle`,children:t(`scenes.aSceneWatchesOneRegion`,`A scene watches one region of one camera and tells you when it stops looking like the picture you captured — a wheelie bin, a gate, a parking space.`)}),e(J,{onClick:m,disabled:c.length===0,className:`shrink-0`,children:[a(V,{className:`mr-1 h-3.5 w-3.5`}),t(`scenes.newScene`,`New scene`)]})]}),u.unreachableCount>0?a(`p`,{className:`text-xs text-warning`,children:t(`scenes.unreachable`,{count:u.unreachableCount})}):null,(d.length>0||f.active)&&a(ft,{state:f.state,facets:f.facets,labels:{searchPlaceholder:`Search scenes…`,searchLabel:`Search scenes`,facetsLabel:`State`,clearLabel:`Clear`},facetLabel:e=>vs[e]??e,onSearch:f.setSearch,onToggleFacet:f.toggleFacet,onClear:f.clear}),a(Mt,{variant:`flat`,className:`p-0`,children:a(Se,{columns:C,rows:f.rows,rowKey:e=>`${e.deviceId}:${e.monitor.id}`,minWidthPx:880,bordered:!1,maxBodyHeight:kt,emptyMessage:u.isLoading?t(`scenes.loadingScenes`,`Loading scenes…`):f.active?t(`scenes.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`scenes.noScenesYetPressNew`,`No scenes yet. Press “New scene”, pick a camera, then draw a box around the thing you want watched.`)})}),p.mode===`new`?e(ut,{open:!0,onClose:_,title:t(`scenes.whichCamera`,`Which camera?`),icon:h,width:`sm`,testId:`scenes-camera-picker`,footer:a(J,{onClick:()=>{v!==null&&g(String(v))},disabled:v===null,children:t(`scenes.continue`,`Continue`)}),children:[a(`p`,{className:`mb-3 text-xs text-foreground-subtle`,children:t(`scenes.aSceneLivesOnOne`,`A scene lives on one camera. Pick the one that can see the thing.`)}),a(bt,{value:v===null?``:String(v),onChange:e=>y(Number(e.target.value)),"aria-label":t(`scenes.camera`,`Camera`),options:c.map(e=>({value:String(e.deviceId),label:e.deviceName}))})]}):null,b===null?null:e(ut,{open:!0,onClose:_,title:t(`scenes.scenes`,`Scenes — {{editingName}}`,{editingName:x}),icon:h,width:`lg`,testId:`scenes-editor`,children:[a(`p`,{className:`mb-3 text-xs text-foreground-subtle`,children:t(`scenes.drawABoxNameIt`,`Draw a box, name it, then capture what “normal” looks like. Daylight is enough — the night reference is optional, and “Settings” on each scene tunes how fussy and how often it checks.`)}),a(r,{fallback:a(`p`,{className:`text-xs text-foreground-muted`,children:t(`scenes.loadingTheEditor`,`Loading the editor…`)}),children:a(St,{deviceId:b})})]})]})}function Cs(){let{t:e}=X(),t=zt(`/library`,{t:e,isAdmin:!0})??{icon:he,title:e(`nav.library`,`Library`)};return a(Bt,{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:a(Gr,{})},{id:`vehicles`,label:e(`library.vehicles`,`Vehicles`),content:a(ps,{})},{id:`events`,label:e(`library.events`,`Events`),content:a(Ho,{}),ownedParams:[`section`]},{id:`scenes`,label:e(`library.scenes`,`Scenes`),content:a(Ss,{})}]})}export{Cs as LibraryPage};
@@ -0,0 +1,3 @@
1
+ import{C as e,K as t,S as n,V as r,Y as i,et as a,o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$i as c,Di as l,Fn as u,Gi as d,Hr as f,Ht as p,It as m,Lr as h,Mi as g,O as _,Pi as v,Pr as y,Ri as b,Rt as x,Ur as S,V as C,bn as w,cn as T,dt as E,ea as D,ei as O,en as k,fi as A,gr as j,k as M,kn as N,lr as P,pn as F,pt as I,rn as L,rr as R,ta as ee,tr as te,ur as z,ut as ne,xi as re,yi as B,z as V,zt as ie}from"./player-overlays-DfIXPXfC.js";import{Ur as ae,Vr as H,vn as oe}from"./client-fa7ANI4X.js";import{t as se}from"./boxes-DomeSuUE.js";import{n as ce,r as le,t as ue}from"./speaker-vU_58Q4N.js";import{t as U}from"./user-round-D6lnAuWE.js";import{$u as de,Ao as fe,Cn as W,Co as pe,Gn as G,Gr as K,Ia as me,Io as he,Jr as q,L as ge,La as _e,Oo as ve,Qr as ye,Qu as J,Ra as be,So as xe,To as Se,Ur as Ce,Va as we,Wn as Te,_o as Ee,_r as De,bt as Oe,do as ke,ed as Ae,fr as je,gr as Me,ho as Ne,jo as Pe,ko as Fe,mn as Ie,mo as Le,mr as Re,pn as ze,po as Be,pr as Ve,qu as He,vr as Ue,wo as We}from"./src-Cy_bal4g.js";import{t as Y}from"./i18n-l_m6iBJW.js";import{t as X}from"./useTranslation-BJr-n0es.js";import{fr as Ge,m as Ke,mr as qe,ur as Z}from"./index-Ctkts88E.js";import{t as Je}from"./AdminSectionedPage-CJhCo7eS.js";import{a as Ye,n as Xe,r as Ze}from"./linked-devices-model-CWqnVKj5.js";a();var Qe={camera:l,hub:ce,container:se,light:z,siren:L,switch:ie,sensor:ee,thermostat:p,climate:D,button:A,"event-emitter":ne,update:le,notifier:b,script:F,automation:I,lock:R,cover:v,valve:S,humidifier:f,"water-heater":y,fan:h,"media-player":ue,"alarm-panel":T,control:k,presence:U,weather:O,vacuum:g,"lawn-mower":x,image:j,smoke:c};function Q({type:e,className:t}){return n(Qe[e]??A,{"aria-hidden":`true`,className:t??`h-3.5 w-3.5 shrink-0 text-foreground-subtle`})}function $e({online:e,deviceName:t}){return n(`span`,{className:e?`inline-block h-1.5 w-1.5 shrink-0 rounded-full bg-success`:`inline-block h-1.5 w-1.5 shrink-0 rounded-full border border-foreground-subtle`,role:`img`,"aria-label":Y.t(`locations.deviceGlyphs.aria`,{name:t,state:e?Y.t(`common.online`):Y.t(`common.offline`)}),title:e?Y.t(`common.online`):Y.t(`common.offline`)})}function et({open:t,title:a,items:o,listState:s,lockedIds:c,lockedNote:l,suggestions:u=null,busy:d=!1,onConfirm:f,onClose:p}){let{t:m}=X(),[h,g]=i([]);r(()=>{t||g([])},[t]);let _=new Map(o.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 n(je,{open:t,onOpenChange:e=>e?void 0:p(),children:e(Re,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":a,children:[n(De,{children:n(Ue,{children:a})}),e(Ve,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:[t&&u!==null&&v.length>0&&e(`section`,{"aria-label":u.heading,className:`flex flex-col gap-1`,children:[n(`h3`,{className:`text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:u.heading}),n(`div`,{className:`flex flex-wrap gap-1`,children:v.map(e=>n(`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))})]}),t&&n(ge,{devices:o,listState:s,value:h,onChange:e=>g(e),noun:`device`,emptyLabel:m(`locations.addDialog.nonePicked`),showAll:!0,lockedIds:c,lockedNote:l,testId:`quick-add-picker`})]}),e(Me,{children:[n(K,{variant:`ghost`,onClick:p,children:m(`locations.addDialog.cancel`)}),n(K,{disabled:h.length===0||d,onClick:()=>f(h),children:m(`locations.addDialog.confirm`,{count:h.length})})]})]})})}a();function tt({room:e,cameras:r,fleet:i}){let{t:a}=X(),o=t(()=>new Map(i.map(e=>[e.id,e])),[i]);return e===null?n(`p`,{className:`text-xs text-foreground-subtle`,children:a(`locations.links.noRoom`)}):n(`div`,{className:`flex flex-col gap-3`,"data-testid":`camera-links-section`,children:r.length===0?n(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`camera-links-empty`,children:a(`locations.links.noCameras`,{room:e})}):r.map(e=>n(rt,{camera:e,byId:o},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:t,byId:r}){let{t:a}=X(),s=o(),c=Ge(),[l,u]=i(!1),[d,f]=i(null),p=_e({deviceId:t.id}),m=Ze({status:p.status,data:p.data,error:p.error===null||p.error===void 0?null:p.error}),h=be(),g=m.kind===`present`?m:null,v=me({deviceId:t.id,slotRef:g?.slot.slotRef??``},{enabled:l&&g!==null}),y=g===null?[]:Xe(g.slot,g.value),b=y.map(e=>e.deviceId),x=(v.data?.candidates??[]).map(nt),S=new Set(x.map(e=>e.id)),C=b.filter(e=>!S.has(e)).map(e=>{let t=r.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 e=>{if(g!==null){f(null);try{await h.mutateAsync({deviceId:t.id,slotRef:g.slot.slotRef,value:Ye(g.value,e)}),await p.refetch(),await s.invalidateQueries({queryKey:[[`deviceManager`]]}),u(!1)}catch(e){f(e instanceof Error?e.message:String(e))}}},D=[{key:`device`,header:a(`locations.columns.device`),notSortableReason:a(`locations.columns.noSort`),render:t=>{let i=r.get(t.deviceId),o=t.name??i?.name??`#${String(t.deviceId)}`;return e(`span`,{className:`flex items-center gap-1.5`,children:[i!==void 0&&n(Q,{type:i.type}),n(Z,{to:`/devices/${String(t.deviceId)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:o}),t.implied&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:a(`locations.links.implied`)})]})}},{key:`type`,header:a(`locations.columns.type`),notSortableReason:a(`locations.columns.noSort`),render:e=>n(`span`,{className:`text-xs text-foreground-muted`,children:r.get(e.deviceId)?.type??`—`})},{key:`status`,header:a(`locations.columns.status`),notSortableReason:a(`locations.columns.noSort`),render:t=>{let i=r.get(t.deviceId);return i===void 0?n(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):e(`span`,{className:`flex items-center gap-1.5`,children:[n($e,{online:i.online,deviceName:i.name}),n(`span`,{className:`text-xs text-foreground-muted`,children:i.online?a(`common.online`):a(`common.offline`)})]})}}];return e(`section`,{className:`min-w-0 ${_}`,"data-testid":`camera-links-${String(t.id)}`,children:[e(`header`,{className:`${M} flex min-h-9 items-center gap-1.5`,children:[n(Q,{type:t.type}),n(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:t.name}),e(K,{variant:`ghost`,size:`sm`,onClick:()=>c(Ke(t.id)),children:[n(P,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),a(`locations.links.edit`)]}),n(K,{variant:`outline`,size:`sm`,disabled:g===null,onClick:()=>u(!0),"aria-label":a(`locations.links.addNamed`,{camera:t.name}),children:a(`locations.room.add`)})]}),m.kind===`pending`&&n(`p`,{role:`status`,className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:a(`locations.links.loading`)}),m.kind===`unknown`&&n(`p`,{role:`alert`,className:`px-3 py-3 text-xs text-warning sm:px-4`,children:a(`locations.links.unreadable`,{reason:m.reason})}),m.kind===`absent`&&n(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:a(`locations.links.unsupported`)}),d!==null&&n(`p`,{role:`alert`,className:`px-3 pt-2 text-xs text-danger break-words sm:px-4`,children:d}),g!==null&&(y.length===0?n(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:a(`locations.links.none`)}):n(W,{columns:D,rows:y,rowKey:e=>String(e.deviceId),bordered:!1,minWidthPx:360})),n(et,{open:l,title:a(`locations.links.pickTitle`,{camera:t.name}),items:w,listState:v.status===`error`?`failed`:v.data===void 0?`pending`:`answered`,lockedIds:b,lockedNote:a(`locations.links.alreadyLinked`),suggestions:t.location===null?null:{heading:a(`locations.links.suggested`,{room:t.location}),ids:T},busy:h.isPending,onConfirm:e=>void E(e),onClose:()=>u(!1)})]})}a();function it({name:t,description:a,busy:o,onSave:s}){let{t:c}=X(),[l,u]=i(a??``);return r(()=>{u(a??``)},[a]),e(`div`,{className:`border-t border-border px-3 py-2 sm:px-4`,children:[n(G,{htmlFor:`location-description-${t}`,className:`block`,children:c(`locations.locationDescriptionField.whatIsThere`,`What is there`)}),n(`textarea`,{id:`location-description-${t}`,value:l,onChange:e=>u(e.target.value),onBlur:()=>{let e=l.trim();e!==(a??``)&&s(e.length===0?null:e)},disabled:o,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`}),n(`p`,{className:`mt-1 ${V}`,children:c(`locations.locationDescriptionField.givenToTheAiWith`,`Given to the AI with the pictures, so it knows what it is looking at. Describe the PLACE, not what happens in it — events change, the ground does not.`)})]})}function at(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0||n.description.length===0?null:n.description}var ot=` none`;function st({name:t,zones:r,zoneKey:i,busy:a,onChange:o}){let{t:s}=X();if(r.length===0)return null;let c=[{value:ot,label:s(`locations.locationZoneField.none`,`— none —`)},...r.map(e=>({value:e.zoneKey,label:e.label}))];return e(`div`,{className:`flex items-center gap-2 border-t border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:[n(G,{htmlFor:`location-zone-${t}`,children:s(`locations.locationZoneField.zone`,`Zone`)}),n(He,{id:`location-zone-${t}`,value:i??ot,disabled:a,onChange:e=>{let t=e.target.value;if(t===ot){o(null);return}let n=r.find(e=>e.zoneKey===t);n!==void 0&&o(n.label)},options:c})]})}function ct(e,t){return e.find(e=>e.locationKeys.includes(t))?.zoneKey??null}function lt({name:e,icon:t,busy:r,onPick:i}){return n(Ae,{value:t,onPick:i,fallbackGlyph:te,clearGlyph:d,labels:{trigger:`Change the icon of ${e}`,panel:`Icon for ${e}`,searchPlaceholder:`Search icons`,clear:`No icon`,noMatches:`No icon matches that`},disabled:r})}function ut(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0?null:ae(n.icon)??`map-pin`}function $(e){if(e==null)return null;let t=e.trim();return t.length===0?null:t.toLowerCase()}function dt(e,t){let n=$(t);return n===null?[]:e.filter(e=>$(e.location)===n)}function ft(e,t){let n=dt(e,t),r=new Set(n.map(e=>e.id));return n.filter(e=>e.parentDeviceId===null||!r.has(e.parentDeviceId))}function pt(e,t){let n=$(e.location);return n===null||new Set(t.map(e=>$(e))).has(n)?null:e.location?.trim()??null}function mt(e,t){let n=$(e.location);return n!==null&&t.has(n)}function ht(e,t){let n=new Set(t.map(e=>$(e))),r=new Set(e.filter(e=>mt(e,n)).map(e=>e.id));return e.filter(e=>!(mt(e,n)||e.parentDeviceId!==null&&r.has(e.parentDeviceId)))}function gt(e,t){return ht(e,t).filter(e=>e.parentDeviceId===null)}function _t(e,t){let n=new Map;for(let t of e){if(t.parentDeviceId===null)continue;let e=n.get(t.parentDeviceId);e?e.push(t):n.set(t.parentDeviceId,[t])}let r=[],i=new Set([t]),a=[t];for(;a.length>0;){let e=[];for(let t of a)for(let a of n.get(t)??[])i.has(a.id)||(i.add(a.id),r.push(a),e.push(a.id));a=e}return r}function vt(e,t){return _t(e,t).length}function yt(e,t){return e.filter(e=>!e.isCamera&&e.parentDeviceId===t)}function bt(e,t){return t.map(t=>({name:t,members:ft(e,t)}))}function xt(e){return`${e.kind}:${String(e.device.id)}`}function St(e,t,n){return e.flatMap(e=>{let r=yt(t,e.id),i=n.has(e.id),a={kind:`member`,device:e,accessories:r,open:i};return!i||r.length===0?[a]:[a,...r.map(t=>({kind:`accessory`,device:t,parent:e}))]})}a();function Ct({name:r,members:a,devices:o,busy:c,icon:l,description:d,onRename:f,onDelete:p,onRebuildLinks:h,onAddDevices:g,onPickIcon:v,onSaveDescription:y,zones:b,zoneKey:x,onChangeZone:S}){let{t:C}=X(),[T,D]=i(!1),[O,k]=i(r),A=ze(a,t(()=>({searchText:e=>[e.name,...yt(o,e.id).map(e=>e.name)],facetValue:e=>e.type}),[o])),[j,N]=i(()=>new Set),P=e=>N(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),F=t(()=>St(A.rows,o,j),[A.rows,o,j]),I=[{key:`name`,header:C(`locations.columns.device`),notSortableReason:C(`locations.columns.noSort`),render:e=>e.kind===`member`?n(wt,{row:e,onToggle:()=>P(e.device.id)}):n(Tt,{row:e})},{key:`type`,header:C(`locations.columns.type`),notSortableReason:C(`locations.columns.noSort`),render:e=>n(`span`,{className:`text-xs text-foreground-muted`,children:e.device.type})},{key:`status`,header:C(`locations.columns.status`),notSortableReason:C(`locations.columns.noSort`),render:t=>e(`span`,{className:`flex items-center gap-1.5`,children:[n($e,{online:t.device.online,deviceName:t.device.name}),n(`span`,{className:`text-xs text-foreground-muted`,children:t.device.online?C(`common.online`):C(`common.offline`)})]})}],L=()=>{k(r),D(!1)},R=async()=>{let e=O.trim();if(e.length===0||e===r){L();return}await f(e),D(!1)},ee=[{id:`rename`,label:C(`locations.locationCard.rename`,`Rename`),icon:u,disabled:c,onClick:()=>{k(r),D(!0)}},{id:`rebuild-links`,label:C(`locations.locationCard.rebuildLinkedDevices`,`Rebuild linked devices`),icon:w,separatorBefore:!0,disabled:c,onClick:()=>void h()},{id:`delete`,label:C(`common.delete`,`Delete`),icon:m,danger:!0,separatorBefore:!0,disabled:c,onClick:()=>void p()}];return e(`section`,{className:`min-w-0 ${_}`,children:[e(`header`,{className:`${M} flex min-h-9 items-center gap-1.5`,children:[n(lt,{name:r,icon:l,busy:c,onPick:v}),T?e(s,{children:[n(J,{value:O,onChange:e=>k(e.target.value),onKeyDown:e=>{e.key===`Enter`&&R(),e.key===`Escape`&&L()},"aria-label":C(`locations.locationCard.rename2`,`Rename {{name}}`,{name:r}),className:`min-w-0 flex-1`,autoFocus:!0}),n(K,{type:`button`,size:`sm`,onClick:()=>void R(),children:C(`common.save`,`Save`)}),n(de,{type:`button`,variant:`ghost`,icon:E,onClick:L,"aria-label":C(`locations.locationCard.cancelRename`,`Cancel rename`)})]}):e(s,{children:[n(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:r}),n(K,{type:`button`,variant:`outline`,size:`sm`,disabled:c,onClick:g,"aria-label":C(`locations.room.addTo`,{room:r}),children:C(`locations.room.add`)}),n(Oe,{items:ee,title:C(`locations.locationCard.actionsFor`,`Actions for {{name}}`,{name:r}),triggerClassName:`p-1`})]})]}),n(st,{name:r,zones:b,zoneKey:x,busy:c,onChange:S}),n(it,{name:r,description:d,busy:c,onSave:y}),a.length>0&&n(`div`,{className:`border-b border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:n(Ie,{state:A.state,facets:A.facets,labels:{searchPlaceholder:C(`locations.filter.searchPlaceholder`),searchLabel:C(`locations.room.searchLabel`,{room:r}),facetsLabel:C(`locations.filter.typesLabel`),clearLabel:C(`locations.filter.clear`)},onSearch:A.setSearch,onToggleFacet:A.toggleFacet,onClear:A.clear})}),a.length===0?n(`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.`)}):n(W,{columns:I,rows:F,rowKey:xt,bordered:!1,minWidthPx:360,emptyMessage:C(`locations.filter.noMatch`)})]})}function wt({row:t,onToggle:r}){let{t:i}=X(),{device:a,accessories:o,open:s}=t,c=s?re:B;return e(`span`,{className:`flex items-center gap-1.5`,children:[o.length>0?e(K,{type:`button`,variant:`ghost`,onClick:r,"aria-expanded":s,"aria-label":i(s?`locations.locationCard.collapseAccessories`:`locations.locationCard.expandAccessories`,{count:o.length,name:a.name}),className:`h-auto shrink-0 gap-0.5 p-0.5 text-foreground-subtle hover:text-foreground`,children:[n(c,{className:`h-3 w-3`}),n(`span`,{className:`text-[10px] tabular-nums`,children:o.length})]}):n(`span`,{"aria-hidden":`true`,className:`w-[1.35rem] shrink-0`}),n(Q,{type:a.type}),n(Z,{to:`/devices/${String(a.id)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:a.name})]})}function Tt({row:t}){let{device:r}=t;return e(`span`,{className:`flex items-center gap-1.5 pl-6`,children:[n(`span`,{"aria-hidden":`true`,className:`text-[10px] text-foreground-subtle`,children:`└`}),n(Q,{type:r.type,className:`h-3 w-3 shrink-0 text-foreground-subtle`}),n(Z,{to:`/devices/${String(r.id)}`,className:`min-w-0 truncate text-xs text-foreground-muted hover:underline`,children:r.name})]})}a();function Et({zones:e,busy:t,onRename:r,onDelete:a,onPickIcon:o}){let{t:s}=X(),[c,l]=i(null),[u,d]=i(``),f=async e=>{let t=u.trim();l(null),!(t.length===0||t===e)&&await r(e,t)};return n(W,{columns:[{key:`icon`,header:s(`locations.siteZonesPanel.icon`,`Icon`),width:`w-12`,notSortableReason:`An icon has no order`,render:e=>n(lt,{name:e.label,icon:e.icon,busy:t,onPick:t=>o(e.label,t)})},{key:`name`,header:s(`locations.siteZonesPanel.zone`,`Zone`),sortValue:e=>e.label.toLowerCase(),render:e=>c===e.label?n(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}):n(K,{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=>n(`span`,{className:`tabular-nums text-foreground-subtle`,children:e.locationKeys.length===0?s(`common.empty`):s(`common.rooms`,{count:e.locationKeys.length})})},{key:`actions`,header:s(`locations.siteZonesPanel.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order`,render:e=>n(K,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void a(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:n(m,{className:`h-3.5 w-3.5`})})}],rows:e,rowKey:e=>e.zoneKey,emptyMessage:s(`locations.siteZonesPanel.noZonesYetAZone`,`No zones yet. A zone groups rooms — “Night zone” for the bedrooms — and shows up before them in the app’s camera filter.`)})}a();function Dt({busy:t,onCreate:r}){let{t:a}=X(),[o,s]=i(!1),[c,l]=i(``),u=()=>{l(``),s(!1)},d=async()=>{let e=c.trim();e.length!==0&&(await r(e),u())};return o?e(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),d()},children:[n(J,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&u()},placeholder:a(`locations.newLocationButton.frontDoorHallKitchen`,`Front door, Hall, Kitchen…`),"aria-label":a(`locations.newLocationButton.newLocationName`,`New location name`),className:`min-w-[12rem] flex-1`,autoFocus:!0}),e(K,{size:`sm`,type:`submit`,disabled:c.trim().length===0||t,children:[n(N,{className:`h-3.5 w-3.5`}),a(`common.add`,`Add`)]}),n(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":a(`locations.newLocationButton.cancelNewLocation`,`Cancel new location`),children:n(E,{className:`h-3.5 w-3.5`})})]}):e(K,{size:`sm`,type:`button`,onClick:()=>s(!0),"data-testid":`new-location-button`,children:[n(N,{className:`h-3.5 w-3.5`}),a(`locations.newLocationButton.newLocation`,`New location`)]})}a();function Ot({busy:t,onCreate:r}){let{t:a}=X(),[o,s]=i(!1),[c,l]=i(``),u=()=>{l(``),s(!1)},d=async()=>{let e=c.trim();e.length!==0&&(await r(e),u())};return o?e(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),d()},children:[n(J,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&u()},placeholder:a(`locations.newZoneButton.zonaGiornoZonaNotte`,`Zona giorno, Night zone…`),"aria-label":a(`locations.newZoneButton.newZoneName`,`New zone name`),className:`min-w-[12rem] flex-1`,autoFocus:!0}),e(K,{size:`sm`,type:`submit`,disabled:c.trim().length===0||t,children:[n(N,{className:`h-3.5 w-3.5`}),a(`common.add`,`Add`)]}),n(K,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":a(`locations.newZoneButton.cancelNewZone`,`Cancel new zone`),children:n(E,{className:`h-3.5 w-3.5`})})]}):e(K,{size:`sm`,type:`button`,onClick:()=>s(!0),"data-testid":`new-zone-button`,children:[n(N,{className:`h-3.5 w-3.5`}),a(`locations.newZoneButton.newZone`,`New zone`)]})}a();function kt(e,t,n,r){let i=e.map(e=>({value:e.name,label:`${e.name} · ${String(e.count)}`}));return t===void 0?i:[...i,{value:n,label:`${r} · ${String(t)}`}]}function At({rooms:e,unassignedCount:r,value:i,unassignedValue:a,onChange:o}){let{t:s}=X(),c=t(()=>kt(e,r,a,s(`locations.roomPicker.unassigned`)),[e,r,a,s]);return n(`div`,{className:`max-w-sm`,"data-testid":`room-select`,children:n(q,{mode:`single`,singleDisplay:`field`,label:s(`locations.roomPicker.label`),placeholder:s(`locations.roomPicker.placeholder`),options:c,value:i,onChange:o,searchable:!0,testId:`room-select-control`,optionTestIdPrefix:`room-option`})})}a();var jt={searchText:e=>[e.name],facetValue:e=>e.type};function Mt({rows:r,fleet:a,locations:o,busy:s,emptyMessage:c,onAssign:l}){let{t:u}=X(),[d,f]=i([]),[p,m]=i(``),h=ze(r,jt),g=h.rows,_=t(()=>g.map(e=>e.id),[g]),v=t(()=>d.filter(e=>_.includes(e)),[d,_]),y=g.length>0&&v.length===g.length,b=t(()=>{let e=new Map;for(let t of r)e.set(t.id,vt(a,t.id));return e},[r,a]),x=v.reduce((e,t)=>e+(b.get(t)??0),0),S=e=>f(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),w=()=>f(y?[]:_),T=()=>{p.length===0||v.length===0||(l(v,p),f([]),m(``))},E=o.map(e=>({value:e,label:e})),D=[{key:`select`,width:`w-8`,headerRender:()=>n(Te,{checked:y,onChange:w,"aria-label":y?u(`locations.unassignedTable.clearSelection`,`Clear selection`):u(`locations.unassignedTable.selectAllUnassignedDevices`,`Select all unassigned devices`)}),render:e=>n(Te,{checked:v.includes(e.id),onChange:()=>S(e.id),"aria-label":u(`locations.unassignedTable.select`,`Select {{name}}`,{name:e.name})})},{key:`name`,header:u(`locations.unassignedTable.device`,`Device`),sortValue:e=>e.name.toLowerCase(),render:t=>{let r=pt(t,o);return e(`span`,{className:`flex items-center gap-1.5`,children:[n(Q,{type:t.type}),n(Z,{to:`/devices/${String(t.id)}`,className:`truncate text-xs text-foreground hover:underline`,children:t.name}),r!==null&&n(ye,{variant:`warning`,children:u(`locations.unassignedTable.unknownRoom`,{room:r})})]})}},{key:`type`,header:u(`locations.unassignedTable.type`,`Type`),sortValue:e=>e.type,render:e=>n(`span`,{className:`text-xs text-foreground-muted`,children:e.type})},{key:`status`,header:u(`locations.unassignedTable.status`,`Status`),sortValue:e=>+!!e.online,render:t=>e(`span`,{className:`flex items-center gap-1.5`,children:[n($e,{online:t.online,deviceName:t.name}),n(`span`,{className:`text-xs text-foreground-muted`,children:t.online?u(`common.online`):u(`common.offline`)})]})},{key:`followers`,header:u(`locations.unassignedTable.accessoriesInTowCount`,`Accessories in tow`),align:`right`,sortValue:e=>b.get(e.id)??0,render:e=>n(`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=>n(He,{"aria-label":u(`locations.unassignedTable.locationFor`,`Location for {{name}}`,{name:e.name}),value:``,disabled:s||o.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 e(`section`,{className:`space-y-2`,children:[e(`header`,{className:`flex flex-wrap items-baseline gap-2`,children:[n(`h2`,{className:C,children:u(`locations.unassignedTable.notInARoom`,`Not in a room`)}),n(`p`,{className:V,children:u(`locations.unassignedTable.topLevelDevicesOnlyAccessories`,`Top-level devices only — accessories move with their parent.`)})]}),r.length>0&&n(Ie,{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&&e(`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:[e(`span`,{className:`text-xs text-foreground`,children:[u(`locations.unassignedTable.selected`,{count:v.length}),x>0&&` · ${u(`locations.unassignedTable.accessoriesInTowCount`,{count:x})}`]}),n(He,{"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]}),n(K,{type:`button`,size:`sm`,onClick:T,disabled:s||p.length===0,children:u(`locations.unassignedTable.assign`,`Assign`)}),n(K,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>f([]),children:u(`locations.unassignedTable.clear`,`Clear`)})]}),n(W,{columns:D,rows:g,rowKey:e=>e.id,minWidthPx:720,emptyMessage:h.active?u(`locations.filter.noMatch`):c})]})}function Nt(e){return{id:e.id,parentDeviceId:e.parentDeviceId,location:e.location,type:e.type,stableId:e.stableId??``,...e.primaryChildEntityId===void 0?{}:{primaryChildEntityId:e.primaryChildEntityId},...e.role!==void 0&&e.role!==null?{role:e.role}:{},name:e.name}}function Pt(e,t){let n=t.map(Nt),r=[];for(let i of t)i.isCamera&&i.location===e&&r.push({deviceId:i.id,name:i.name,ids:oe({selfId:i.id,selfLocation:i.location,candidates:n})});return{entries:r}}var Ft=`device-manager:linked-devices`;function It(e){return{deviceId:e.deviceId,slotRef:Ft,value:{slot:`linked-devices`,deviceIds:[...e.ids]}}}a();var Lt=`__unassigned__`;function Rt(){let{t:r}=X(),a=o(),s=Ce(),{data:c,isLoading:l}=Ne(),{data:u}=Le(),{data:d}=Be(),{data:f}=Ee(),{data:p,isLoading:m}=ke({projection:`slim`}),h=()=>{a.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listLocationIcons`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listLocationDescriptions`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listSiteZones`]]})},g=we({onSuccess:h}),_=xe({onSuccess:h}),v=ve({onSuccess:h}),y=We({onSuccess:h}),b=fe({onSuccess:h}),x=Fe({onSuccess:h}),S=he({onSuccess:h}),C=pe({onSuccess:h}),w=Se({onSuccess:h}),T=Pe({onSuccess:h}),E=be(),D=t(()=>(p??[]).map(e=>({id:e.id,name:e.name,location:e.location??null,type:String(e.type),isCamera:e.isCamera,parentDeviceId:e.parentDeviceId,online:e.online,role:e.role??null,stableId:e.stableId,primaryChildEntityId:e.primaryChildEntityId??null})),[p]),O=c??[],k=t(()=>bt(D,O),[D,O]),[A,j]=qe(),M=A.get(`tab`),N=M===`zones`||M===`camera-links`?M:`locations`,P=A.get(`room`),F=t(()=>gt(D,O),[D,O]),I=P===Lt,L=I?null:P!==null&&k.some(e=>e.name===P)?P:k[0]?.name??null,R=L===null?null:k.find(e=>e.name===L)??null,ee=I?Lt:L??`__unassigned__`,z=L??k[0]?.name??null,ne=t(()=>k.map(e=>({name:e.name,count:e.members.length})),[k]),re=e=>{j(t=>{let n=new URLSearchParams(t);return n.set(`room`,e),n},{replace:!0})},B=l||m,V=v.isPending||_.isPending||g.isPending||b.isPending,ie=async e=>{await g.mutateAsync({name:e})},ae=async(e,t)=>{let n=t.trim();n.length===0||n===e||await y.mutateAsync({from:e,to:n})},oe=async e=>{let t=Pt(e,D);if(t.entries.length===0){await s({title:r(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:r(`locations.noCameraIsAssignedTo`,`No camera is assigned to “{{room}}”.`,{room:e}),confirmLabel:`OK`});return}let n=t.entries.map(e=>r(`locations.rebuildEntry`,{name:e.name,count:e.ids.length})).join(`
2
+ `);if(!await s({title:r(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:r(`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:e,lines:n}),confirmLabel:r(`locations.rebuild`,`Rebuild`),variant:`danger`}))return;let i=[];for(let e of t.entries)try{await E.mutateAsync(It(e))}catch(t){i.push(`• ${e.name}: ${t instanceof Error?t.message:String(t)}`)}h(),i.length>0&&await s({title:r(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:r(`locations.notRebuilt`,`Not rebuilt: {{value1}}`,{value1:i.join(`
3
+ `)}),confirmLabel:`OK`})},se=async(e,t)=>{let n=t>0?` ${String(t)} device(s) will become unassigned.`:``;await s({title:r(`locations.deleteLocation`,`Delete location`),message:r(`locations.deleteTheLocation`,`Delete the location “{{name}}”?{{extra}}`,{name:e,extra:n}),confirmLabel:r(`common.delete`,`Delete`),variant:`danger`})&&await _.mutateAsync({name:e,cascade:!0})},ce=async e=>{await s({title:r(`locations.deleteZone`,`Delete zone`),message:r(`locations.deleteTheZoneTheRooms`,`Delete the zone “{{name}}”? The rooms in it are kept.`,{name:e}),confirmLabel:r(`common.delete`,`Delete`),variant:`danger`})&&await C.mutateAsync({name:e})},le=async(e,t)=>{await b.mutateAsync({location:e,icon:t})},ue=async(e,t)=>{await x.mutateAsync({location:e,description:t})},U=f??[],de=async(e,t)=>{await T.mutateAsync({location:e,zone:t})},W=(e,t)=>{for(let n of e)v.mutate({deviceId:n,location:t})},[G,K]=i(null),me=t(()=>D.filter(e=>e.parentDeviceId===null).map(e=>({id:e.id,name:e.name,type:e.type,location:e.location})),[D]),q=n(At,{rooms:ne,...N===`locations`?{unassignedCount:F.length}:{},value:N===`locations`?ee:z??``,unassignedValue:Lt,onChange:re}),ge=e(`div`,{className:`flex flex-col gap-3`,"data-testid":`locations-section`,children:[B&&n(`p`,{className:`text-xs text-foreground-subtle`,children:r(`locations.loadingLocationsAndDevices`,`Loading locations and devices…`)}),q,I||R===null?n(Mt,{rows:F,fleet:D,locations:O,busy:V,emptyMessage:B?r(`common.loading`,`Loading…`):r(`locations.everyTopLevelDeviceHas`,`Every top-level device has a room.`),onAssign:W}):n(Ct,{name:R.name,members:R.members,devices:D,busy:V,icon:ut(u,H(R.name)),onPickIcon:e=>le(R.name,e),description:at(d,H(R.name)),onSaveDescription:e=>ue(R.name,e),zones:U,zoneKey:ct(U,H(R.name)),onChangeZone:e=>de(R.name,e),onRename:e=>ae(R.name,e),onDelete:()=>se(R.name,dt(D,R.name).length),onRebuildLinks:()=>oe(R.name),onAddDevices:()=>K(R.name)},R.name),O.length===0&&!B&&n(`p`,{className:`text-xs text-foreground-subtle`,children:r(`locations.noLocationsYetAddFrontDoor`,`No locations yet. Add Front door, Hall, Kitchen…`)}),n(et,{open:G!==null,title:r(`locations.room.addDialogTitle`,{room:G??``}),items:me,listState:m?`pending`:`answered`,lockedIds:G===null?[]:(k.find(e=>e.name===G)?.members??[]).map(e=>e.id),lockedNote:r(`locations.room.alreadyHere`),suggestions:{heading:r(`locations.room.suggestedUnassigned`),ids:F.map(e=>e.id)},busy:v.isPending,onConfirm:e=>{G!==null&&W(e,G),K(null)},onClose:()=>K(null)})]}),_e=e(`div`,{className:`flex flex-col gap-3`,"data-testid":`camera-links-tab`,children:[q,n(tt,{room:z,cameras:z===null?[]:dt(D,z).filter(e=>e.isCamera),fleet:D})]});return n(Je,{icon:te,title:r(`locations.locations`,`Locations`),subtitle:r(`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`?n(Ot,{busy:S.isPending,onCreate:e=>S.mutateAsync({name:e})}):n(Dt,{busy:g.isPending,onCreate:ie}),sections:[{id:`locations`,label:r(`locations.locations`,`Locations`),content:ge},{id:`camera-links`,label:r(`locations.cameraLinks`,`Camera links`),content:_e},{id:`zones`,label:r(`locations.zones`,`Zones`),content:n(Et,{zones:U,busy:V,onRename:(e,t)=>w.mutateAsync({from:e,to:t}),onDelete:ce,onPickIcon:(e,t)=>S.mutateAsync({name:e,icon:t})})}]})}export{Rt as LocationsPage};
@@ -0,0 +1 @@
1
+ import{C as e,K as t,S as n,Y as r,et as i}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Di as a,Si as o,or as s,pn as c,ta as l}from"./player-overlays-DfIXPXfC.js";import{n as u,t as d}from"./timer-reset-BfVqeFHK.js";import{t as f}from"./layers-BC3a28BZ.js";import{Si as p,pd as m,pu as h,tn as g,uu as _,xi as v}from"./src-Cy_bal4g.js";import{t as y}from"./useTranslation-BJr-n0es.js";import{a as b,i as x,x as S}from"./index-Ctkts88E.js";import{t as C}from"./AdminSectionedPage-CJhCo7eS.js";import{t as w}from"./AdminPage-UX2_-EVb.js";import{n as T,t as E}from"./IntegrationHub-DdxMGRIt.js";import{n as D,t as O}from"./addon-display-names-BkwMrExv.js";i();var k=5e3,A=`log-destination`,j={"winston-logging":`Rotated log files on this node’s disk.`,"console-logging":`stdout / stderr of the node process.`,"loki-logging":`Pushes to a Grafana Loki instance. Off until enabled with a URL.`,"hub-forwarder":`Agent-only — forwards this node’s entries to the hub.`};function M(){let{t:e}=y(),r=p({capName:`log-destination`},{refetchInterval:k}),i=v(void 0,{refetchInterval:k}),a=t(()=>O(i.data??[]),[i.data]),o=t(()=>{let e=new Map;for(let t of i.data??[]){let n=t.description,r=t.id;typeof r==`string`&&typeof n==`string`&&n.length>0&&e.set(r,n)}return e},[i.data]),s=t(()=>(r.data??[]).map(e=>({addonId:e.addonId,displayName:a.get(e.addonId)??e.addonId,isActive:e.isActive,caption:o.get(e.addonId)??j[e.addonId]??``})),[r.data,a,o]),l=[{id:A,label:e(`system.logging.logDestinations`,`Log destinations`),entries:s.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:u,...D(e.isActive),render:()=>n(T,{addonId:e.addonId,displayName:e.displayName,capName:A,isActive:e.isActive,badges:e.caption.length>0?n(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.caption}):null})}))}];return n(E,{embedded:!0,icon:c,title:e(`system.logging.destinations`,`Destinations`),subtitle:e(`system.logging.everyRegisteredLogDestinationEntries`,`Every registered log destination. Entries are fanned to all enabled destinations at once — enabling one does not disable another.`),groups:l,isLoading:r.isLoading,emptyTitle:e(`system.logging.noLogDestinationsRegistered`,`No log destinations registered`),emptyDescription:e(`system.logging.thisShouldNotHappenThe`,`This should not happen — the console and rotated-file destinations are builtins. If the list is empty, the node is still booting.`)})}i();var N=[12e4,3e5,6e5,18e5],P={"request-census":`Counts every tRPC call by TRANSPORT PLANE — http, ws, mesh — and by procedure, caller, address and user-agent. Subscriptions are counted apart from calls, so a long-lived stream cannot pass for a storm. Arm it, then restart: the deadline is persisted, so the window is still running when clients reconnect.`};function F(){let{t}=y(),i=_({},{refetchInterval:5e3}),a=h(),[o,c]=r(null),u=(e,t)=>{c(e),a.mutate({patch:{diagnostics:[{id:e,armMs:t}]}},{onSettled:()=>{c(null),i.refetch()}})},d=i.data?.activeWindows??[],f=i.data?.channels??[],p=i.data?.activeChannels??[],m=(e,t,n)=>{c(e),a.mutate({patch:{channels:[{channel:e,armMs:t,deviceIds:n}]}},{onSettled:()=>{c(null),i.refetch()}})};return e(w,{embedded:!0,icon:l,title:t(`logging.diagnostics.title`,`Diagnostics`),subtitle:t(`logging.diagnostics.subtitle`,`Diagnostics are armed for a window, never switched on. Each carries a deadline and expires by itself — one left running is an incident of its own.`),children:[i.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[n(s,{className:`h-3.5 w-3.5 animate-spin`}),t(`common.loading`,`Loading…`)]}):n(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:d.map(e=>n(L,{window:e,busy:o===e.id,onArm:t=>u(e.id,t)},e.id))}),n(`h3`,{className:`mt-6 text-sm font-medium text-foreground`,children:t(`logging.diagnostics.channels`,`Component channels`)}),n(`p`,{className:`mb-2 max-w-3xl text-[11px] text-foreground-subtle`,children:t(`logging.diagnostics.channelsSubtitle`,`Declared by the addons that own them — this list is not maintained by hand. Arming a channel opens a window with a deadline; it closes by itself.`)}),f.length===0?n(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`logging.diagnostics.noChannels`,`No addon on this cluster declares a log channel, or none could be reached right now.`)}):n(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:f.map(e=>n(I,{channel:e,state:p.find(t=>t.channel===e.name),busy:o===e.name,onArm:(t,n)=>m(e.name,t,n)},e.name))})]})}function I({channel:t,state:i,busy:o,onArm:s}){let{t:c}=y(),[l,u]=r(``),f=i?.armed===!0,p=()=>{let e=l.split(/[\s,+]+/).filter(e=>/^\d+$/.test(e)).map(e=>Number(e));return e.length>0?e:null};return e(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[e(`div`,{className:`min-w-0`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[n(`span`,{className:`text-sm font-medium text-foreground`,children:t.name}),f?e(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[n(d,{className:`h-3 w-3`}),c(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:R(i?.remainingMs??0)})]}):n(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:c(`logging.diagnostics.disarmed`,`disarmed`)}),f&&i?.deviceIds!==null&&i?.deviceIds!==void 0&&e(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[n(a,{className:`h-3 w-3`}),i.deviceIds.join(`, `)]}),!t.perDevice&&n(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:c(`logging.diagnostics.notPerCamera`,`not filterable per camera`)})]}),n(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:t.description})]}),e(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[t.perDevice&&n(`input`,{type:`text`,inputMode:`numeric`,value:l,disabled:o,onChange:e=>u(e.target.value),placeholder:c(`logging.diagnostics.camerasPlaceholder`,`all cameras`),className:`w-28 rounded border border-border bg-surface px-2 py-1 text-[11px] text-foreground`}),N.map(e=>n(`button`,{type:`button`,disabled:o,onClick:()=>s(e,p()),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:R(e)},e)),n(`button`,{type:`button`,disabled:o||!f,onClick:()=>s(0,null),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:c(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function L({window:t,busy:r,onArm:i}){let{t:a}=y();return e(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[e(`div`,{className:`min-w-0`,children:[e(`div`,{className:`flex items-center gap-2`,children:[n(`span`,{className:`text-sm font-medium text-foreground`,children:t.id}),t.armed?e(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[n(d,{className:`h-3 w-3`}),a(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:R(t.remainingMs)})]}):n(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:a(`logging.diagnostics.disarmed`,`disarmed`)}),t.armed&&!t.persisted&&n(`span`,{className:`text-[10px] text-warning`,children:a(`logging.diagnostics.notPersisted`,`not persisted — will not survive a restart`)})]}),n(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:P[t.id]??``})]}),e(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[N.map(e=>n(`button`,{type:`button`,disabled:r,onClick:()=>i(e),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:R(e)},e)),n(`button`,{type:`button`,disabled:r||!t.armed,onClick:()=>i(0),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:a(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function R(e){let t=Math.max(0,Math.round(e/1e3)),n=Math.floor(t/60),r=t%60;return n===0?`${r}s`:r===0?`${n}m`:`${n}m ${r}s`}i();var z=[`debug`,`info`,`warn`,`error`],B=``,V=``;function H(){let{t:i}=y(),[a,o]=r(B),[c,l]=r(V),{nodes:u}=m(),d=t(()=>u.map(e=>({id:e.id,label:e.name||e.id})),[u]),p=_({...a===B?{}:{scopeNodeId:a},...c===V?{}:{scopeComponent:c}},{refetchInterval:15e3}),g=h(),v=p.data,b=g.isPending||p.isFetching,x=v?.channels??[],S=(e,t)=>{g.mutate({...e.nodeId===null?{}:{scopeNodeId:e.nodeId},...e.component===null?{}:{scopeComponent:e.component},patch:{level:t}},{onSuccess:()=>void p.refetch()})};return n(w,{embedded:!0,icon:f,title:i(`logging.levels.title`,`Levels`),subtitle:i(`logging.levels.subtitle`,`Cluster → node, most specific wins. The floor gates what reaches the log destinations; the in-memory viewer keeps every line either way.`),actions:e(`div`,{className:`flex flex-wrap items-center gap-3`,children:[e(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(`logging.levels.scope`,`Scope`),e(`select`,{className:`rounded border border-border bg-surface px-2 py-1 text-xs text-foreground disabled:opacity-50`,value:a,disabled:c!==V,onChange:e=>o(e.target.value),children:[n(`option`,{value:B,children:i(`logging.levels.cluster`,`Cluster`)}),d.map(e=>n(`option`,{value:e.id,children:e.label},e.id))]})]}),e(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(`logging.levels.component`,`Component`),e(`select`,{className:`rounded border border-border bg-surface px-2 py-1 text-xs text-foreground`,value:c,onChange:e=>l(e.target.value),children:[n(`option`,{value:V,children:i(`logging.levels.noComponent`,`None`)}),x.map(e=>n(`option`,{value:e.name,children:e.name},e.name))]})]})]}),children:p.isLoading||v===void 0?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[n(s,{className:`h-3.5 w-3.5 animate-spin`}),i(`common.loading`,`Loading…`)]}):e(`div`,{className:`space-y-3`,children:[n(W,{level:v.effective.level,source:v.effective.levelSource,persisted:v.persisted}),n(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:v.explicit.layers.map(e=>n(G,{layer:e,inForce:e.scope===v.effective.levelSource,busy:b,onSet:t=>S(e,t),onClear:()=>S(e,null)},`${e.scope}:${e.nodeId??e.component??`cluster`}`))}),c!==V&&n(`p`,{className:`text-[11px] text-foreground-subtle`,children:x.find(e=>e.name===c)?.description??``}),n(`p`,{className:`text-[11px] text-foreground-subtle`,children:i(`logging.levels.componentNote`,`A component is a log channel an addon declared. Its level is cluster-wide and beats both the node and the cluster layer.`)}),n(U,{days:v.opsLogRetentionDays,busy:b,onSet:e=>g.mutate({patch:{opsLogRetentionDays:e}},{onSuccess:()=>void p.refetch()})})]})})}function U({days:t,busy:r,onSet:i}){let{t:a}=y();return e(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-1`,children:[e(`label`,{className:`flex items-center justify-between gap-3`,children:[n(`span`,{className:`text-xs font-medium`,children:a(`logging.levels.opsLogRetention`,`Retention audit trail`)}),e(`span`,{className:`flex items-center gap-1.5`,children:[n(`input`,{type:`number`,min:0,max:3650,step:1,defaultValue:t,disabled:r,onBlur:e=>{let n=Number.parseInt(e.target.value,10);Number.isFinite(n)&&n!==t&&i(n)},className:`w-20 rounded border border-border bg-surface px-2 py-1 text-xs`}),n(`span`,{className:`text-[11px] text-foreground-subtle`,children:a(`common.days`,`days`)})]})]}),n(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`logging.levels.opsLogRetentionNote`,`How long the record of what retention deleted is kept. Cluster-wide, and deliberately longer than any camera window — it is the history of the sweep, not of the camera, and it is what makes a storage leak explainable after the fact. 0 keeps it forever.`)})]})}function W({level:t,source:r,persisted:i}){let{t:a}=y();return e(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[e(`div`,{className:`flex items-center gap-2`,children:[n(`span`,{className:`text-xs text-foreground-subtle`,children:a(`logging.levels.effective`,`In force here`)}),n(`span`,{className:`rounded bg-primary/10 px-2 py-0.5 text-xs font-semibold text-primary`,children:t}),n(`span`,{className:`text-[11px] text-foreground-subtle`,children:r==="default"?a(`logging.levels.fromDefault`,`nothing is set anywhere — this is the default`):a(`logging.levels.fromLayer`,`decided by the {{source}} layer`,{source:r})})]}),!i&&n(`p`,{className:`mt-1 text-[11px] text-warning`,children:a(`logging.levels.notPersisted`,`The settings store could not be read or written — what you see is live, but it would not survive a restart.`)})]})}function G({layer:t,inForce:r,busy:i,onSet:a,onClear:s}){let{t:c}=y();return e(`div`,{className:`flex flex-col gap-2 p-3 sm:flex-row sm:items-center sm:justify-between`,children:[e(`div`,{className:`min-w-0`,children:[e(`div`,{className:`flex items-center gap-2`,children:[n(`span`,{className:`text-sm font-medium text-foreground`,children:t.scope===`cluster`?c(`logging.levels.cluster`,`Cluster`):t.scope===`component`?t.component??``:t.nodeId??``}),r&&e(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[n(o,{className:`h-3 w-3`}),c(`logging.levels.inForce`,`in force`)]})]}),n(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:t.level===null?c(`logging.levels.inherits`,`inherits — nothing set at this layer`):c(`logging.levels.setHere`,`set here: {{level}}`,{level:t.level})})]}),e(`div`,{className:`flex shrink-0 items-center gap-1`,children:[z.map(e=>n(`button`,{type:`button`,disabled:i,onClick:()=>a(e),className:`rounded px-2 py-1 text-[11px] font-medium transition-colors disabled:opacity-50 ${t.level===e?`bg-primary text-primary-foreground`:`border border-border text-foreground-subtle hover:text-foreground`}`,children:e},e)),n(`button`,{type:`button`,disabled:i||t.level===null,onClick:s,className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-40`,children:c(`logging.levels.clear`,`Clear`)})]})]})}function K(){return n(w,{embedded:!0,children:n(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:n(g,{limit:500,maxHeight:`max-h-[calc(100vh-310px)]`,showScope:!0,showFilters:!0})})})}function q(){let{t:e}=y(),t=S(`/system/logs`,{t:e,isAdmin:!0})??{icon:c,title:e(`system.logs`,`Logs`)};return n(C,{icon:t.icon,title:t.title,defaultSection:`viewer`,sectionsLabel:`${t.title} sections`,sections:[{id:`viewer`,label:e(`admin.system.logs.viewer`,`Viewer`),content:n(K,{})},{id:b.logging.tab,label:e(`admin.system.logs.destinations`,`Destinations`),content:n(M,{}),ownedParams:x},{id:`levels`,label:e(`admin.system.logs.levels`,`Levels`),content:n(H,{})},{id:`diagnostics`,label:e(`admin.system.logs.diagnostics`,`Diagnostics`),content:n(F,{})}]})}export{q as LogsPage};
@@ -0,0 +1 @@
1
+ import{C as e,J as t,P as n,R as r,S as i,V as a,Y as o,et as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{sa as c}from"./player-overlays-DfIXPXfC.js";import{a as l,c as u,i as d,n as f,o as p,r as m,s as h,t as g}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_konva__loadShare__.js-BjdR__nc.js";s();var _={rect:`#ef4444`,polygon:`#3b82f6`,grid:`#6366f1`,line:`#f59e0b`},v=`33`,y=`66`,b=`#6366f1`,x=3,S=2,C=12,w=16,T=9;function E(e,t,n){return{x:e.x*t,y:e.y*n}}function D(e,t,n){return{x:e.x/t,y:e.y/n}}function O(e,t,n){return e.flatMap(e=>[e.x*t,e.y*n])}function k(e){return!Number.isFinite(e)||e<0?0:e>1?1:e}function A(e){return e.color??_[e.shape.kind]}function j(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 M(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 N(e){return e.kind===`polygon`||e.kind===`line`}function P({items:n,selectedId:s,onSelect:f,onShapeChange:p,onDrawComplete:m,drawingKind:v,supportedShapes:y,transparent:j=!1,backdrop:P,polygonVertices:F,grid:I}){let B=c(),V=t(null),[H,ee]=o({w:800,h:450}),[U,W]=o([]),[G,K]=o(null),[te,ne]=o(null),[q,J]=o(null),Y=v!==null&&y.includes(v);a(()=>{if(!q)return;let e=n.find(e=>e.id===q.itemId);if(!e||!N(e.shape)){J(null);return}M(e.shape.points,q.points)&&J(null)},[n,q]),a(()=>{let e=V.current;if(!e)return;let t=new ResizeObserver(e=>{let t=e[0];if(!t)return;let{width:n,height:r}=t.contentRect;ee(j?{w:n,h:r}:{w:n,h:n*9/16})});return t.observe(e),()=>t.disconnect()},[j]),a(()=>{!Y&&G!==null&&K(null)},[Y,G]);let X=r(e=>{m(e),W([])},[m]),re=r(e=>{if(!Y||v===null){f(null);return}let t=e.target.getStage();if(!t)return;let n=t.getPointerPosition();if(!n)return;let r=D(n,H.w,H.h);if(v===`rect`){let e=k(r.x),t=k(r.y);X({kind:`rect`,x:e,y:t,width:Math.min(.2,1-e),height:Math.min(.2,1-t)});return}if(v===`grid`){let e=I?.width??w,t=I?.height??T;X({kind:`grid`,gridWidth:e,gridHeight:t,cells:Array.from({length:e*t},()=>!1)});return}if(v===`line`){if(U.length===0){W([r]);return}X({kind:`line`,points:[...U,r]});return}if(v===`polygon`){if(U.length===0){W([r]);return}if(U.length>=x){let e=E(U[0],H.w,H.h);if(Math.hypot(n.x-e.x,n.y-e.y)<C){X({kind:`polygon`,points:U});return}}W(e=>[...e,r])}},[Y,v,U,H,I,X,f]),ie=r(e=>{!Y||v!==`polygon`||U.length<x||(e.cancelBubble=!0,X({kind:`polygon`,points:U}))},[Y,v,U,X]),Z=t(null),Q=t(null);a(()=>()=>{Z.current!==null&&cancelAnimationFrame(Z.current)},[]);let ae=r(e=>{if(!Y)return;let t=e.target.getStage();t&&(Q.current=t.getPointerPosition()??null,Z.current===null&&(Z.current=requestAnimationFrame(()=>{Z.current=null,K(Q.current)})))},[Y]),oe=t(!1),se=t(!0),ce=t(new Set),le=r((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,p(e,{...t,cells:a})},[p]),$=[];if(!j){for(let e=1;e<w;e++){let t=H.w/w*e;$.push(i(u,{points:[t,0,t,H.h],stroke:`#ffffff`,strokeWidth:.5,opacity:.08},`gv-${e}`))}for(let e=1;e<T;e++){let t=H.h/T*e;$.push(i(u,{points:[0,t,H.w,t],stroke:`#ffffff`,strokeWidth:.5,opacity:.08},`gh-${e}`))}}return e(`div`,{ref:V,className:j?`absolute inset-0`:`relative w-full bg-zinc-900 rounded-lg overflow-hidden`,style:{cursor:Y?`crosshair`:`default`},children:[P&&!j?i(`div`,{className:`absolute inset-0 pointer-events-none [&>*]:w-full [&>*]:h-full [&>img]:object-cover [&>video]:object-cover`,style:{width:H.w,height:H.h},children:P}):null,e(l,{width:H.w,height:H.h,onClick:re,onDblClick:ie,onMouseMove:ae,children:[e(g,{listening:!1,children:[i(u,{points:[0,0,H.w,0,H.w,H.h,0,H.h,0,0],stroke:`transparent`,strokeWidth:0}),$]}),i(g,{children:n.map(e=>{let t=e.id===s,n=e.enabled===!1,r=A(e),a=t&&!Y&&!n;if(e.shape.kind===`rect`)return i(L,{item:e,shape:e.shape,color:r,selected:t,dimmed:n,editable:a,isDrawing:Y,size:H,onSelect:f,onShapeChange:p},e.id);if(e.shape.kind===`grid`)return i(R,{item:e,shape:e.shape,color:r,dimmed:n,editable:a,size:H,onSelect:f,paintingRef:oe,paintValueRef:se,paintedRef:ce,paintCell:le},e.id);let o=e.shape.kind===`line`,c=o?S:Math.max(x,F?.min??x),l=o?S:F?.max,u=q&&q.itemId===e.id?q.points:e.shape.points;return i(z,{item:e,shape:e.shape,color:r,selected:t,dimmed:n,editable:a,isLine:o,isDrawing:Y,size:H,effectivePoints:u,minVertices:c,maxVertices:l,isDragging:te===e.id,onSelect:f,onShapeChange:p,setDragOverride:J,setDraggingItemId:ne},e.id)})}),i(g,{listening:!1,children:Y&&U.length>0&&e(d,{children:[v===`polygon`&&U.length>=2&&i(u,{points:O(U,H.w,H.h),stroke:b,strokeWidth:1.5,dash:[6,3],opacity:.8}),v===`line`&&U.length===1&&G&&i(u,{points:[U[0].x*H.w,U[0].y*H.h,G.x,G.y],stroke:_.line,strokeWidth:1.5,dash:[6,3],opacity:.7}),v===`polygon`&&G&&U.length>=1&&i(u,{points:[U[U.length-1].x*H.w,U[U.length-1].y*H.h,G.x,G.y],stroke:b,strokeWidth:1,dash:[4,4],opacity:.5}),U.map((e,t)=>{let n=E(e,H.w,H.h),r=t===0&&v===`polygon`&&U.length>=x;return i(h,{x:n.x,y:n.y,radius:r?7:4,fill:r?b:`#ffffff`,stroke:b,strokeWidth:1.5,opacity:.9},t)})]})})]}),Y?i(`div`,{className:`px-3 py-1.5 bg-zinc-800/80 text-[11px] text-zinc-400 border-t border-zinc-700`,children:v===`line`?B(`uiLibrary.maskShapeCanvas.hintLine`,`Click to set the start point, click again to complete the line`):v===`rect`?B(`uiLibrary.maskShapeCanvas.hintRect`,`Click to drop a rectangle, then drag the corner to resize`):v===`grid`?B(`uiLibrary.maskShapeCanvas.hintGrid`,`Click to add the grid, then paint cells`):U.length<x?B(`uiLibrary.maskShapeCanvas.hintPoints`,`Click to add points (min 3). Double-click or click the first point to close.`):B(`uiLibrary.maskShapeCanvas.hintMore`,`Continue adding points. Double-click or click the first point to close.`)}):null]})}var F=.02;function I(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 L({item:t,shape:n,color:r,selected:s,dimmed:c,editable:l,isDrawing:u,size:m,onSelect:g,onShapeChange:_}){let[b,x]=o(null),S={x:n.x,y:n.y,width:n.width,height:n.height};a(()=>{b&&I(S,b)&&x(null)},[n.x,n.y,n.width,n.height,b]);let C=b??S,w=C.x*m.w,T=C.y*m.h,E=C.width*m.w,D=C.height*m.h,O=c?.35:s?1:.85,A=e=>{x(e),_(t.id,{kind:`rect`,x:e.x,y:e.y,width:e.width,height:e.height})};return i(d,{onClick:e=>{e.cancelBubble=!0,u||g(t.id)},children:e(d,{draggable:l,dragBoundFunc:l?e=>({x:Math.max(-w,Math.min(m.w-(w+E),e.x)),y:Math.max(-T,Math.min(m.h-(T+D),e.y))}):void 0,onDragEnd:l?e=>{let t=e.target,n=t.x()/m.w,r=t.y()/m.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=u?`crosshair`:`default`)},children:[i(p,{x:w,y:T,width:E,height:D,fill:r+(s?y:v),stroke:r,strokeWidth:s?2.5:1.5,opacity:O}),t.label?i(f,{x:w,y:T-16,text:t.label,fontSize:12,fill:r,stroke:`#000000`,strokeWidth:3,fillAfterStrokeEnabled:!0,fontStyle:`bold`,listening:!1}):null,l?i(h,{x:w+E,y:T+D,radius:6,fill:r,stroke:`#ffffff`,strokeWidth:1.5,draggable:!0,dragBoundFunc:e=>({x:Math.min(m.w,Math.max(w,e.x)),y:Math.min(m.h,Math.max(T,e.y))}),onDragStart:e=>{e.cancelBubble=!0},onDragMove:e=>{let t=e.target,n=k(t.x()/m.w-C.x),r=k(t.y()/m.h-C.y);x({...C,width:Math.max(F,Math.min(n,1-C.x)),height:Math.max(F,Math.min(r,1-C.y))})},onDragEnd:e=>{let t=e.target,n=k(t.x()/m.w-C.x),r=k(t.y()/m.h-C.y);A({...C,width:Math.max(F,Math.min(n,1-C.x)),height:Math.max(F,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 R({item:e,shape:t,color:n,dimmed:r,editable:a,size:o,onSelect:s,paintingRef:c,paintValueRef:l,paintedRef:u,paintCell:f}){let{gridWidth:m,gridHeight:h,cells:g}=t,_=o.w/m,v=o.h/h,b=m*h,x=r?.3:1,S=n=>{if(!a){s(e.id);return}let r=g[n]!==!0;c.current=!0,l.current=r,u.current=new Set([n]),f(e.id,t,n,r)},C=n=>{!c.current||!a||u.current.has(n)||(u.current.add(n),f(e.id,t,n,l.current))},w=()=>{c.current&&(c.current=!1,u.current=new Set)};return i(d,{opacity:x,onMouseUp:w,onMouseLeave:w,children:Array.from({length:b},(e,t)=>{let r=t%m,a=Math.floor(t/m),o=g[t]===!0;return i(p,{x:r*_,y:a*v,width:_,height:v,fill:o?n+y:`#ffffff10`,stroke:o?n:`#ffffff40`,strokeWidth:.5,onMouseDown:e=>{e.cancelBubble=!0,S(t)},onMouseEnter:()=>C(t)},t)})})}function z({item:t,shape:n,color:r,selected:a,dimmed:o,editable:s,isLine:c,isDrawing:l,size:p,effectivePoints:g,minVertices:_,maxVertices:b,isDragging:x,onSelect:S,onShapeChange:C,setDragOverride:w,setDraggingItemId:T}){let k=O(g,p.w,p.h),A=o?.35:a?1:c?.8:.85,M=e=>c?{kind:`line`,points:[...e]}:{kind:`polygon`,points:[...e]},N=g.map(e=>e.x*p.w),P=g.map(e=>e.y*p.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(p.w-I,e.x)),y:Math.max(-L,Math.min(p.h-R,e.y))}),B=e=>{let r=e.target,i=r.x()/p.w,a=r.y()/p.h;if(r.position({x:0,y:0}),T(null),i===0&&a===0)return;let o=n.points.map(e=>({x:e.x+i,y:e.y+a}));w({itemId:t.id,points:o}),C(t.id,M(o))},V=!c&&g.length>_,H=!c&&(b===void 0||g.length<b);return e(d,{onClick:e=>{e.cancelBubble=!0,l||S(t.id)},children:[e(d,{draggable:s,dragBoundFunc:s?z:void 0,onDragStart:s?()=>T(t.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=l?`crosshair`:`default`)},children:[c?i(m,{points:k,stroke:r,strokeWidth:a?3:2,fill:r,pointerLength:10,pointerWidth:8,opacity:A}):i(u,{points:k,closed:!0,fill:r+(a?y:v),stroke:r,strokeWidth:a?2.5:1.5,opacity:A}),t.label&&g.length>0?(()=>{let e=E({x:g.reduce((e,t)=>e+t.x,0)/g.length,y:g.reduce((e,t)=>e+t.y,0)/g.length},p.w,p.h),n=Math.max(40,t.label.length*11*.62);return i(f,{x:e.x-n/2,y:e.y-7,width:n,align:`center`,text:t.label,fontSize:12,fill:r,stroke:`#000000`,strokeWidth:3,fillAfterStrokeEnabled:!0,fontStyle:`bold`,listening:!1})})():null]}),s&&!x&&g.map((e,a)=>{let o=E(e,p.w,p.h);return i(h,{x:o.x,y:o.y,radius:5,fill:r,stroke:`#ffffff`,strokeWidth:1.5,draggable:!0,onDragMove:e=>{let r=D({x:e.target.x(),y:e.target.y()},p.w,p.h);w(e=>{let i=e&&e.itemId===t.id?e.points:n.points;return{itemId:t.id,points:i.map((e,t)=>t===a?r:e)}})},onDragEnd:e=>{let r=D({x:e.target.x(),y:e.target.y()},p.w,p.h),i=n.points.map((e,t)=>t===a?r:e);w({itemId:t.id,points:i}),C(t.id,M(i))},onContextMenu:e=>{e.evt.preventDefault(),e.cancelBubble=!0,V&&C(t.id,M(n.points.filter((e,t)=>t!==a)))}},`pt-${a}`)}),s&&!x&&H&&g.length>=2&&g.map((e,a)=>{let o=g[(a+1)%g.length],s=E({x:(e.x+o.x)/2,y:(e.y+o.y)/2},p.w,p.h);return i(h,{x:s.x,y:s.y,radius:4,fill:`#ffffff`,stroke:r,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=l?`crosshair`:`default`)},onClick:e=>{e.cancelBubble=!0,C(t.id,M(j(n.points,a)))}},`mid-${a}`)})]})}var B=n(P);export{B as MaskShapeCanvas};
@@ -0,0 +1 @@
1
+ import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,et as s,x as ee}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Er as te,K as c,U as l,X as u,ia as ne,n as re,ot as d,sa as f,z as p}from"./player-overlays-DfIXPXfC.js";import{MaskShapeCanvas as m}from"./MaskShapeCanvas-Cmq6IidK.js";s();var ie=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:s}){let w=f(),D=c(d().trpcClient,s),[O,k]=o(null),[A,j]=o(!1),[M,N]=o(null),[P,F]=o(null),[I,L]=o(v),[R,z]=o(!1),[B,V]=o(!1),H=t(!1);a(()=>{if(!D)return;let e=!1;return H.current=!1,k(null),j(!1),N(null),F(null),L(v),V(!1),(async()=>{try{let t=await D.motionZones?.getOptions({});if(e)return;if(!t)throw Error(`device proxy not ready`);if(k(t),H.current)return;let n=await D.motionZones?.getStatus({});if(e)return;if(!n)throw Error(`device proxy not ready`);H.current=!0;let r=n.regions.find(e=>e.shape.kind===`grid`),i=x(r?r.shape.cells:[],t.grid.width,t.grid.height);F(i),N(T(i,t.grid.width,t.grid.height,v))}catch(t){if(e)return;l(t)?j(!0):console.error(`Motion Zones load failed`,t)}})(),()=>{e=!0}},[D]);let U=O?O.grid.width:0,W=O?O.grid.height:0,G=C(U,I),K=C(W,I),q=n(()=>M&&O?E(M,U,W,I):null,[M,O,U,W,I]),J=n(()=>q!==null&&P!==null&&!S(q,P),[q,P]),ae=n(()=>q?q.reduce((e,t)=>t?e+1:e,0):0,[q]),oe=U*W,Y=G*K,X=r(e=>{Y>0&&N(Array.from({length:Y},()=>e))},[Y]),se=r(()=>{N(e=>e&&e.map(e=>!e))},[]),Z=r(()=>{P&&O&&N(T(P,U,W,I))},[P,O,U,W,I]),ce=r(e=>{e===I||!O||N(t=>{if(!t)return L(e),t;let n=T(E(t,U,W,I),U,W,e);return L(e),n})},[I,O,U,W]),Q=n(()=>O&&M?[{id:g,shape:{kind:`grid`,gridWidth:G,gridHeight:K,cells:[...M]}}]:[],[O,M,G,K]),$=r((e,t)=>{t.kind===`grid`&&N(t.cells)},[]),le=r(async()=>{if(!(!D||!M||!O)){z(!0);try{let e=E(M,O.grid.width,O.grid.height,I),t={kind:`grid`,gridWidth:O.grid.width,gridHeight:O.grid.height,cells:e};await D.motionZones?.setZone({patch:{regions:[{id:g,enabled:!0,shape:t}]}});let n=await D.motionZones?.getStatus({});if(n){let e=n.regions.find(e=>e.shape.kind===`grid`),t=x(e?e.shape.cells:[],O.grid.width,O.grid.height);F(t),N(T(t,O.grid.width,O.grid.height,I))}}catch(e){console.error(`Motion Zones save failed`,e)}finally{z(!1)}}},[D,M,O,I]);re(n(()=>B&&!A&&O&&M?{id:h,order:ie,node:i(m,{transparent:!0,items:Q,supportedShapes:[`grid`],grid:{width:G,height:K},selectedId:g,onSelect:()=>{},onShapeChange:$,onDrawComplete:()=>{},drawingKind:null})}:null,[B,A,O,M,Q,$,G,K]));let ue=!A&&O!==null&&M!==null;return D?i(u,{title:w(`uiLibrary.motionZones.title`,`Motion Zones`),icon:i(te,{className:`h-3.5 w-3.5 text-foreground-subtle`}),children:i(`div`,{className:`flex flex-col gap-3`,children:A?i(`p`,{className:`${p} leading-relaxed`,children:w(`uiLibrary.motionZones.unsupported`,`This camera doesn't expose an on-board motion zones grid.`)}):ue?e(ee,{children:[i(`p`,{className:`${p} leading-relaxed`,children:i(ne,{uiKey:`uiLibrary.motionZones.intro`,fallback:`Toggle <0>Edit grid</0> to paint the region directly on the live frame, then <1>Save</1> to push the mask to the camera. Pick a bigger <2>Cell size</2> for quicker, broad-stroke painting — it's resampled to the camera's native {{width}}×{{height}} grid on save (×1 is the finest).`,components:[i(`strong`,{className:`text-foreground`},`e`),i(`strong`,{className:`text-foreground`},`s`),i(`strong`,{className:`text-foreground`},`c`)],values:{width:O.grid.width,height:O.grid.height}})}),e(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[i(`button`,{type:`button`,onClick:()=>V(e=>!e),disabled:R,"aria-pressed":B,className:B?b:y,children:B?w(`uiLibrary.motionZones.doneEditing`,`Done editing`):w(`uiLibrary.motionZones.editGrid`,`Edit grid`)}),i(`button`,{type:`button`,onClick:()=>X(!0),disabled:R,className:y,children:w(`uiLibrary.motionZones.allOn`,`All on`)}),i(`button`,{type:`button`,onClick:()=>X(!1),disabled:R,className:y,children:w(`uiLibrary.motionZones.allOff`,`All off`)}),i(`button`,{type:`button`,onClick:se,disabled:R,className:y,children:w(`uiLibrary.motionZones.invert`,`Invert`)}),e(`div`,{className:`flex items-center gap-1 ml-1`,role:`group`,"aria-label":w(`uiLibrary.motionZones.cellSize`,`Cell size`),children:[i(`span`,{className:`${p} mr-0.5`,children:w(`uiLibrary.motionZones.cellSize`,`Cell size`)}),_.map(t=>e(`button`,{type:`button`,onClick:()=>ce(t),disabled:R,"aria-pressed":I===t,title:t===1?w(`uiLibrary.motionZones.cameraGrid`,`Camera grid {{width}}×{{height}} (finest)`,{width:U,height:W}):w(`uiLibrary.motionZones.paintingGrid`,`{{width}}×{{height}} painting grid · cells ×{{factor}} bigger`,{width:C(U,t),height:C(W,t),factor:t}),className:I===t?b:y,children:[`×`,t]},t))]}),e(`span`,{className:`${p} ml-1 tabular-nums`,children:[w(`uiLibrary.motionZones.cells`,`{{active}} / {{total}} cells · {{width}}×{{height}}`,{active:ae,total:oe,width:O.grid.width,height:O.grid.height}),I===1?``:w(`uiLibrary.motionZones.paintSuffix`,` · paint {{width}}×{{height}}`,{width:G,height:K})]}),i(`span`,{className:`flex-1`}),i(`button`,{type:`button`,onClick:Z,disabled:R||!J,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:w(`uiLibrary.motionZones.revert`,`Revert`)}),i(`button`,{type:`button`,onClick:()=>void le(),disabled:R||!J,className:b,children:R?w(`uiLibrary.motionZones.saving`,`Saving…`):w(`uiLibrary.motionZones.save`,`Save`)})]})]}):i(`p`,{className:`${p} leading-relaxed`,children:w(`uiLibrary.motionZones.loading`,`Loading the camera's grid…`)})})}):null}export{D as MotionZonesSettings};