@camstack/addon-admin-ui 1.2.503 → 1.2.505

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 (138) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/assets/{AddonAssetIcon-DRZmNGlG.js → AddonAssetIcon-CvrR3ZEp.js} +1 -1
  3. package/dist/assets/Addons-CtYXCXR3.js +5 -0
  4. package/dist/assets/{AdminPage-Bn1s1Zyw.js → AdminPage-CRBjpZ4t.js} +1 -1
  5. package/dist/assets/{AdminSectionedPage-OHmEcMxM.js → AdminSectionedPage-O_gaWBic.js} +1 -1
  6. package/dist/assets/{AiProfiles-CrsCHAWJ.js → AiProfiles-DVFetD_E.js} +1 -1
  7. package/dist/assets/{BrokerEditorDialog-0I2FqCxl.js → BrokerEditorDialog--vuPcV-I.js} +1 -1
  8. package/dist/assets/Build-B7n9F9d7.js +40 -0
  9. package/dist/assets/{Calendars-CdAizSco.js → Calendars-D82HISef.js} +1 -1
  10. package/dist/assets/Cluster-D-6ztV8U.js +1 -0
  11. package/dist/assets/{CompositionBlockEditor-CP3_SX84.js → CompositionBlockEditor-BdgsCxJZ.js} +1 -1
  12. package/dist/assets/{CompositionEditorPage-DfjSU7uD.js → CompositionEditorPage-B91Y66Yn.js} +1 -1
  13. package/dist/assets/{Data-D2dSu7s6.js → Data-q4PMBaIS.js} +2 -2
  14. package/dist/assets/DeviceDetail-pPQkOmhX.js +2 -0
  15. package/dist/assets/{DeviceDoActionFields-CHeeEoE0.js → DeviceDoActionFields-D-6QkJSs.js} +1 -1
  16. package/dist/assets/{Devices-gen3hRHJ.js → Devices-DJs8xwIW.js} +1 -1
  17. package/dist/assets/{EmbedPlayerPage-rhZJ1QKl.js → EmbedPlayerPage-CohChj9F.js} +1 -1
  18. package/dist/assets/HelperWizard-D34R-al-.js +2 -0
  19. package/dist/assets/{History-D84HQRm3.js → History-Bt4HOJAj.js} +1 -1
  20. package/dist/assets/{Identity-CxluBwKM.js → Identity-Chnmwk7d.js} +1 -1
  21. package/dist/assets/IntegrationDetail-BWf4S4PI.js +1 -0
  22. package/dist/assets/{IntegrationHub-DXhDIgkG.js → IntegrationHub-CruhQ18c.js} +1 -1
  23. package/dist/assets/Integrations-Orv4u7hu.js +1 -0
  24. package/dist/assets/Integrations-swzrdB7i.js +1 -0
  25. package/dist/assets/Library-CUQkRmgv.js +1 -0
  26. package/dist/assets/{Locations-LcX-LYMF.js → Locations-BZ9_OyBS.js} +2 -2
  27. package/dist/assets/{Logs-BEZRwDcR.js → Logs-Czk-XHEo.js} +1 -1
  28. package/dist/assets/{MaskShapeCanvas-Cn8yntgZ.js → MaskShapeCanvas-DnJ8OyvO.js} +1 -1
  29. package/dist/assets/{MotionZonesSettings-ar2Pege0.js → MotionZonesSettings-BZ-C5Bpc.js} +1 -1
  30. package/dist/assets/MyAccess-Bk_kcdO9.js +2 -0
  31. package/dist/assets/Network-DbdD1jRj.js +1 -0
  32. package/dist/assets/{NodeAddonsSettingsPanel-DEdzDp8P.js → NodeAddonsSettingsPanel-Bxo7RX_t.js} +1 -1
  33. package/dist/assets/Notifications-jDLOdxxr.js +1 -0
  34. package/dist/assets/Pipeline-CdRFK7Ht.js +1 -0
  35. package/dist/assets/{PrivacyMaskSettings-w3Z1Pmp0.js → PrivacyMaskSettings-CwqJt7F1.js} +1 -1
  36. package/dist/assets/Recordings-ByMTLru0.js +1 -0
  37. package/dist/assets/{ScanNetworkModal-DYNrpcKO.js → ScanNetworkModal-C_wbwoQJ.js} +1 -1
  38. package/dist/assets/{SceneMonitorEditor-BbGTvgFe.js → SceneMonitorEditor-_eTUV0Nt.js} +1 -1
  39. package/dist/assets/SessionsList-NSwapFYQ.js +2 -0
  40. package/dist/assets/{Showroom-Cb8HIezy.js → Showroom-BPdeCFff.js} +1 -1
  41. package/dist/assets/{System-CmmWc699.js → System-6U5y0D0r.js} +1 -1
  42. package/dist/assets/{Terminal-B-DbiagD.js → Terminal-CtSs7HaV.js} +1 -1
  43. package/dist/assets/{Viewer-h_DWBxgH.js → Viewer-Cy6OOx-f.js} +1 -1
  44. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-ChYA9pOs.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BrKy-SMz.js} +1 -1
  45. package/dist/assets/{addon-icons-context-aYGMdVc6.js → addon-icons-context-9dO49JJv.js} +1 -1
  46. package/dist/assets/{archive-B8nHeizN.js → archive-8x-tu1s7.js} +1 -1
  47. package/dist/assets/{assignment-candidates-C73e9ykO.js → assignment-candidates-rjmoo-gF.js} +1 -1
  48. package/dist/assets/{authed-media-OiQVKexs.js → authed-media-DG3fVpcG.js} +1 -1
  49. package/dist/assets/{bell-off-B8qGTZJe.js → bell-off-DMfxbtq4.js} +1 -1
  50. package/dist/assets/{board-model-CCAK2YmC.js → board-model-WWlJx1cg.js} +1 -1
  51. package/dist/assets/{boxes-DTEgIla8.js → boxes-BWAGJm1O.js} +1 -1
  52. package/dist/assets/circle-slash-C5LGZ7Jt.js +1 -0
  53. package/dist/assets/client-DXl30Qia.js +674 -0
  54. package/dist/assets/{cloud-upload-CrsNLt4y.js → cloud-upload-CKs-pNsZ.js} +1 -1
  55. package/dist/assets/crop-CKoE-7yI.js +1 -0
  56. package/dist/assets/{device-integration-icon-BStZ5ytk.js → device-integration-icon-CNzVUpNN.js} +1 -1
  57. package/dist/assets/device-picker-model-B2lLKlrB.js +1 -0
  58. package/dist/assets/{dist-DhM3TUvu.js → dist-D1lJ0amf.js} +1 -1
  59. package/dist/assets/dist-pI3sPmA5.js +674 -0
  60. package/dist/assets/{eraser-B6GapSNa.js → eraser-Dboyt7DT.js} +1 -1
  61. package/dist/assets/{format-XZs_xh1r.js → format-CqUoeB6x.js} +1 -1
  62. package/dist/assets/framework-packages-B7oma9J4.js +1 -0
  63. package/dist/assets/{hard-drive-download-CKtXN4eq.js → hard-drive-download-9FzNEeA3.js} +1 -1
  64. package/dist/assets/{hostInit-Dugn9T0N.js → hostInit-DUNsyymc.js} +1 -1
  65. package/dist/assets/i18n-DDYls5dY.js +1 -0
  66. package/dist/assets/{icons-IUDDHPfU.js → icons-wUSx9AFv.js} +1 -1
  67. package/dist/assets/index-BQucBhdz.js +4 -0
  68. package/dist/assets/index-DUl9HFmr.css +2 -0
  69. package/dist/assets/{key-B1puhv1a.js → key-DsZMsE3B.js} +1 -1
  70. package/dist/assets/{key-round-DmUg5DWL.js → key-round-DP5HddQT.js} +1 -1
  71. package/dist/assets/{layers--KlhvTig.js → layers-Ce8hM9RV.js} +1 -1
  72. package/dist/assets/{linked-devices-model-CNnR_mjb.js → linked-devices-model-CwQqHHq3.js} +1 -1
  73. package/dist/assets/{list-ordered-pBVZh-hF.js → list-ordered-Bok3LKqI.js} +1 -1
  74. package/dist/assets/{location-owned-usage-Cwiz3bVN.js → location-owned-usage-caMWTIh0.js} +1 -1
  75. package/dist/assets/{log-in-DtNu6ihw.js → log-in-Dy7V-B3B.js} +1 -1
  76. package/dist/assets/{memory-stick-s804jcfZ.js → memory-stick-B1MtzV7u.js} +1 -1
  77. package/dist/assets/{message-square-plus-Cl5QQyI7.js → message-square-plus-B8tlaZRC.js} +1 -1
  78. package/dist/assets/{mf-entry-bootstrap-0-e18bf152.js → mf-entry-bootstrap-0-508d81ce.js} +2 -2
  79. package/dist/assets/{mic-off-Bl1AxZQ6.js → mic-off-BoPPgEuI.js} +1 -1
  80. package/dist/assets/{monitor-off-Du7HEr2h.js → monitor-off-NYPljllc.js} +1 -1
  81. package/dist/assets/{monitor-smartphone-DJqsZ1_F.js → monitor-smartphone-BjvCzSKA.js} +1 -1
  82. package/dist/assets/mount-B2lLKlrB.js +1 -0
  83. package/dist/assets/{player-overlays-B4lehTI4.js → player-overlays-DkX009EX.js} +1 -1
  84. package/dist/assets/{recycle-Clfv9-vM.js → recycle-DGYdB0Wq.js} +1 -1
  85. package/dist/assets/remoteEntry-B_HQRuMC.js +1 -0
  86. package/dist/assets/{scan-eye-k8IsYrRV.js → scan-eye-Ch-0lhIO.js} +1 -1
  87. package/dist/assets/{scissors-DSR_hX9P.js → scissors-B6VydNaF.js} +1 -1
  88. package/dist/assets/{search-x-CJK6g57h.js → search-x-BdKhxUyE.js} +1 -1
  89. package/dist/assets/{send-BXMUOnLc.js → send-bQSpRVGI.js} +1 -1
  90. package/dist/assets/{settings-2-D_d4vkzK.js → settings-2-D6b4Y6jH.js} +1 -1
  91. package/dist/assets/{sigma-C5zYB6Cq.js → sigma-HnZfIS_X.js} +1 -1
  92. package/dist/assets/{speaker-BCuags2o.js → speaker-zhX4f3kb.js} +1 -1
  93. package/dist/assets/src-B6o0JOTn.js +67 -0
  94. package/dist/assets/{step-inspector-model-DP-n2a-m.js → step-inspector-model-B9toNvbs.js} +1 -1
  95. package/dist/assets/{table-2-DecfWh5K.js → table-2-CkdRK3-h.js} +1 -1
  96. package/dist/assets/{timer-reset-CdW4OGWJ.js → timer-reset-GRtPzP8x.js} +1 -1
  97. package/dist/assets/{unlink-Chgtl9c5.js → unlink--JN-bzY3.js} +1 -1
  98. package/dist/assets/{usb-DSG8UHuC.js → usb-DVsgUDG3.js} +1 -1
  99. package/dist/assets/{use-scenes-feed-Px1hbQDA.js → use-scenes-feed-Cqw88fnG.js} +1 -1
  100. package/dist/assets/{use-stationary-objects-WqiRmYIc.js → use-stationary-objects-4q9AsEzW.js} +1 -1
  101. package/dist/assets/useEventInvalidation-B2lLKlrB.js +1 -0
  102. package/dist/assets/{useNodeUrlSelection-DW98VTZs.js → useNodeUrlSelection-DmVrPFLh.js} +1 -1
  103. package/dist/assets/user-round-DkmA2RnU.js +1 -0
  104. package/dist/assets/{user-x-Ddy9Al8t.js → user-x-CpK7WtDd.js} +1 -1
  105. package/dist/assets/{variable-BGeMjiqk.js → variable-CTjWqiYN.js} +1 -1
  106. package/dist/assets/{video-B-2RwuDj.js → video-DP_1jY7p.js} +1 -1
  107. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CoUIkQxD.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BKjBUyzU.js} +2 -2
  108. package/dist/index.html +10 -10
  109. package/dist/server/addon.js +75 -9
  110. package/package.json +1 -1
  111. package/dist/assets/Addons-RW0QdiVT.js +0 -5
  112. package/dist/assets/Build-vzgL6An-.js +0 -40
  113. package/dist/assets/Cluster-Bg0lO7ax.js +0 -1
  114. package/dist/assets/DeviceDetail-Dd1ulCyf.js +0 -2
  115. package/dist/assets/HelperWizard-QNL7ojgt.js +0 -2
  116. package/dist/assets/IntegrationDetail-2QlbVLE7.js +0 -1
  117. package/dist/assets/Integrations-Cs-b-69p.js +0 -1
  118. package/dist/assets/Integrations-DT3z5Q5Q.js +0 -1
  119. package/dist/assets/Library-BYQs9rzN.js +0 -1
  120. package/dist/assets/MyAccess-ChxQGXAk.js +0 -2
  121. package/dist/assets/Network-C7jEJlX5.js +0 -1
  122. package/dist/assets/Notifications-Dk-cpsUG.js +0 -1
  123. package/dist/assets/Pipeline-DanfCspn.js +0 -1
  124. package/dist/assets/Recordings-DPC7wBK7.js +0 -1
  125. package/dist/assets/SessionsList-_-3LQsWm.js +0 -2
  126. package/dist/assets/circle-slash--9TzZJnc.js +0 -1
  127. package/dist/assets/client-C6c46gRD.js +0 -674
  128. package/dist/assets/crop-Cf_bbG5R.js +0 -1
  129. package/dist/assets/device-picker-model-DuRGlFHX.js +0 -1
  130. package/dist/assets/dist-Dwc9xFn1.js +0 -674
  131. package/dist/assets/i18n-uD14huY2.js +0 -1
  132. package/dist/assets/index-WAVCQxxk.css +0 -2
  133. package/dist/assets/index-pzq9LOji.js +0 -4
  134. package/dist/assets/mount-DuRGlFHX.js +0 -1
  135. package/dist/assets/remoteEntry-C4v7BKsX.js +0 -1
  136. package/dist/assets/src-DlnTixq9.js +0 -67
  137. package/dist/assets/useEventInvalidation-DuRGlFHX.js +0 -1
  138. package/dist/assets/user-round-CsUnuDee.js +0 -1
@@ -1 +0,0 @@
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{Cr as f,D as p,Di as m,Ei as h,En as g,Fn as _,Ht as v,Ii as y,It as b,Mi as x,Ni as S,Nr as C,Nt as w,Oi as T,Q as E,Ti as D,Vn as O,Vr as k,Xr as A,Xt as j,Z as M,bn as N,c as P,ct as F,di as I,dt as ee,en as L,f as R,fr as z,gt as B,l as V,ot as H,ri as U,rn as W,sa as te,st as ne,tn as G,u as re,ur as ie,vn as K,wn as q,z as ae,zt as oe}from"./player-overlays-B4lehTI4.js";import{ao as se,nt as ce,zr as le}from"./client-C6c46gRD.js";import{a as ue,c as de,i as fe,n as pe,o as me,r as he,s as ge,t as _e}from"./user-x-Ddy9Al8t.js";import{c as ve}from"./video-B-2RwuDj.js";import{t as ye}from"./crop-Cf_bbG5R.js";import{t as be}from"./user-round-CsUnuDee.js";import{Ac as xe,Bl as Se,Cn as Ce,Do as we,Er as Te,Fi as Ee,Fl as De,Gl as Oe,Hl as ke,Ic as Ae,Id as je,Il as Me,Kl as Ne,Lc as Pe,Ll as Fe,Mc as Ie,Oc as Le,Pc as Re,Pl as ze,Qn as Be,Rl as Ve,Sn as He,Tr as Ue,Ul as We,Vl as Ge,Wl as Ke,Yr as J,_d as qe,_r as Je,_s as Ye,bn as Xe,br as Ze,cs as Qe,dd as $e,dr as et,ds as tt,dt as nt,fc as rt,fn as it,fs as at,ft as ot,gd as st,gr as ct,gs as lt,hn as ut,hr as dt,hs as ft,jc as pt,ls as mt,mr as ht,ms as gt,mt as _t,ni as vt,od as yt,pn as bt,pr as xt,ps as St,ri as Ct,sd as wt,ss as Tt,t as Et,ti as Dt,tn as Ot,un as kt,us as At,vs as jt,xt as Mt,ys as Nt,zl as Pt}from"./src-DlnTixq9.js";import{t as Y}from"./i18n-uD14huY2.js";import{t as X}from"./useTranslation-BJr-n0es.js";import"./mount-DuRGlFHX.js";import{S as Ft,fr as It,gr as Lt,mr as Rt,ur as zt}from"./index-pzq9LOji.js";import{t as Bt}from"./AdminSectionedPage-OHmEcMxM.js";import{t as Vt}from"./use-stationary-objects-WqiRmYIc.js";import{a as Ht,i as Ut,n as Wt,r as Gt,t as Kt}from"./authed-media-OiQVKexs.js";import{t as qt}from"./use-scenes-feed-Px1hbQDA.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(be,{className:`h-8 w-8`})})}),a(`div`,{className:`min-h-[4.75rem]`,children:t.enrollable?e(d,{children:[a($e,{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(Ct,{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(z,{className:`h-3 w-3 animate-spin`}),` `,u(`detectionIntelligence.photoEnrollDialog.analysing`)]}):null,t.status===`analyzed`&&t.analysis!==void 0&&a(`span`,{className:`text-xs text-foreground-subtle`,children:u(`detectionIntelligence.photoEnrollDialog.facesAnalysedOn`,{count:d.length,node:t.analysis.ranOnNodeId})}),t.status===`failed`&&e(J,{variant:`secondary`,size:`sm`,disabled:o,onClick:l,children:[a(q,{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(oe,{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=ee(),d=u(),f=t(null),{data:p}=at(),m=Qe(),[h,g]=s([]),[_,v]=s(!1),[y,b]=s(null),[x,S]=s({}),[C,w]=s({}),[T,E]=s(null),D=n(()=>(p??[]).map(e=>({id:e.id,name:e.name})),[p]),O=h.some(e=>e.status===`queued`||e.status===`analyzing`),k=O||_,A=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]),j=i(()=>{g([]),S({}),w({}),b(null),E(null),f.current&&(f.current.value=``)},[]),M=i(()=>{A(h),j(),o(!1)},[A,o,h,j]),N=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]),P=i(async e=>{g(t=>gn(t,e.photoIndex,{status:`analyzing`,error:void 0}));try{let t=await N(e);g(n=>gn(n,e.photoIndex,{status:`analyzed`,analysis:t}))}catch(t){g(n=>gn(n,e.photoIndex,{status:`failed`,error:An(t)}))}},[N]),F=i(async e=>{if(e.length===0)return;A(h),j();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=>P(e))},[A,h,j,P]),I=yn(h,x),L=i(async()=>{v(!0),b(null),E(null);try{let e=xn(h,x,C);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,C,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=>N(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(` · `)),E(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)}},[N,m,x,C,h,d,l]),R=h.filter(e=>e.status===`analyzed`).length;return a(et,{open:r,onOpenChange:e=>e?o(!0):M(),children:e(xt,{className:`max-w-3xl`,children:[e(ct,{children:[a(Je,{children:c(`detectionIntelligence.photoEnrollDialog.enrolFromPhotos`,`Enrol from photos`)}),a(ht,{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(zt,{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 F(Array.from(e.target.files??[]))}),e(J,{variant:`secondary`,size:`sm`,disabled:k,onClick:()=>f.current?.click(),children:[O?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(me,{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:R,count:h.length})})]}),a(`div`,{className:`min-h-11`,"aria-live":`polite`,children:y===null?T===null?null:a(`div`,{className:`rounded-md border border-success/40 bg-success/10 px-3 py-2 text-xs text-success`,children:T}):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(oe,{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:D,draft:x,newNames:C,disabled:k,onAssign:(t,n)=>S(r=>vn(r,e.photoIndex,t,n===On?null:n)),onNameChange:(t,n)=>w(r=>({...r,[_n(e.photoIndex,t)]:n})),onRetry:()=>void P(e)},e.photoIndex))}),e(dt,{children:[a(J,{variant:`secondary`,onClick:M,disabled:_,children:c(`common.close`,`Close`)}),e(J,{variant:`primary`,onClick:()=>void L(),disabled:k||I===0,children:[_?a(z,{className:`h-3.5 w-3.5 animate-spin`}):null,c(`detectionIntelligence.photoEnrollDialog.enrolFaces`,{count:I})]})]})]})})}l();var Pn=[[`faceGallery`]];function Fn({identityId:t}){let{t:n}=X(),r=u(),{data:i,isLoading:o}=St({identityId:t}),s=ft();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(z,{className:`h-3.5 w-3.5 animate-spin`}),n(`detectionIntelligence.peopleList.loadingSamples`,`Loading samples…`)]}):!i||i.length===0?a(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:n(`detectionIntelligence.peopleList.noSamplesYet`,`No samples yet.`)}):a(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:i.map(t=>e(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[t.base64?a(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:n(`detectionIntelligence.peopleList.sample`,`Sample`),className:`h-full w-full object-cover`}):a(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:a(be,{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(me,{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(B,{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(be,{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(Ct,{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(qe,{variant:`ghost`,size:`sm`,icon:O,"aria-label":Y.t(`detectionIntelligence.peopleList.edit`,`Edit {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onEdit(n)}}),a(qe,{variant:`ghost`,size:`sm`,icon:v,"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=Qe(),p=lt();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(_t,{open:!0,onClose:r,title:t===`new`?`Add person`:`Edit ${n?.name??`person`}`,icon:be,width:t===`edit`?`xl`:`lg`,testId:`people-person-form`,footer:e(J,{variant:`primary`,size:`sm`,type:`button`,onClick:y,disabled:_,children:[m?a(z,{className:`h-3.5 w-3.5 animate-spin`}):null,t===`new`?i(`common.add`,`Add`):i(`common.save`,`Save`)]}),children:e(`div`,{className:`space-y-4`,children:[a(Mt,{label:i(`detectionIntelligence.peopleList.name`,`Name`),required:!0,children:a(st,{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=ne(),{data:c,isLoading:l}=at(),d=At(),{state:f,openNew:p,openEdit:m,close:h}=ot(),[g,v]=s(!1),y=c??[],b=it(y,{searchText:e=>[e.name]}),x=f.mode===`edit`?y.find(e=>e.id===f.id)??null:null;o(()=>{f.mode===`edit`&&!l&&x===null&&h()},[f.mode,l,x,h]);let S=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(z,{className:`h-4 w-4 animate-spin`}),t(`detectionIntelligence.peopleList.loadingPeople`,`Loading people…`)]});let C=f.mode===`new`||f.mode===`edit`&&x!==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(_,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.peopleList.addPerson`,`Add person`)]}),e(J,{variant:`secondary`,size:`sm`,type:`button`,onClick:()=>v(!0),children:[a(me,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.peopleList.enrolFromAPhoto`,`Enrol from a photo`)]})]}),(y.length>0||b.active)&&a(bt,{state:b.state,facets:b.facets,labels:{searchPlaceholder:`Search people…`,searchLabel:`Search people`,facetsLabel:`Filter`,clearLabel:`Clear`},onSearch:b.setSearch,onToggleFacet:b.toggleFacet,onClear:b.clear}),b.rows.length===0?a(Te,{icon:be,title:b.active?t(`detectionIntelligence.peopleList.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.peopleList.noPeopleEnrolledYet`,`No people enrolled yet`),description:b.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(He,{columns:S,rows:b.rows,rowKey:e=>e.id,maxBodyHeight:Ce,emptyMessage:t(`detectionIntelligence.peopleList.noPeopleEnrolledYet2`,`No people enrolled yet.`),onRowClick:e=>m(e.id)}),C&&a(Ln,{mode:f.mode===`new`?`new`:`edit`,identity:x,onClose:h}),a(Nn,{open:g,onOpenChange:v})]})}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(h,{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(D,{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=Tt(),l=Qe(),[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(et,{open:_,onOpenChange:e=>!e&&b(),children:e(xt,{children:[e(ct,{children:[a(Je,{children:v>1?i(`detectionIntelligence.assignDialog.assignFacesToPerson`,`Assign {{value1}} faces to person`,{value1:String(v)}):i(`detectionIntelligence.assignDialog.assignFaceToPerson`,`Assign face to person`)}),a(ht,{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(st,{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(dt,{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(z,{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(z,{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,h=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(S,{className:`h-3.5 w-3.5`}),a(`span`,{className:`max-w-[10rem] truncate`,children:h}),a(m,{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:p,isFetching:m}=tt({faceId:t?.faceId??``},{enabled:t!==null}),[h,g]=s(`frame`),{frameSrc:_,naturalWidth:y,naturalHeight:b,failed:x}=hr(t?.keyFrameMediaId),S=n(()=>{let e=gr(p??[]);return e?e.url:tr(t)},[p,t]),C=n(()=>!t?.faceBbox||y===null||b===null?null:fr(t.faceBbox,y,b),[t?.faceBbox,y,b]);if(t===null)return null;let T=t.keyFrameMediaId!==void 0&&!x,E=T&&h===`frame`,D=t.assigned?t.identityName??`Assigned`:t.recognizedIdentityId?`${t.identityName??`Recognized`} (suggested)`:`Unassigned`;return a(et,{open:!0,onOpenChange:e=>!e&&i(),children:e(xt,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":d(`detectionIntelligence.faceDetailPanel.faceDetail`,`Face detail`),className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[a(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:e(`div`,{className:`min-w-0`,children:[a(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:d(`detectionIntelligence.faceDetailPanel.faceDetail`,`Face detail`)}),a(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:r})]})}),e(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[T&&e(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[e(`button`,{type:`button`,onClick:()=>g(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${h===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(N,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.fullFrame`)]}),e(`button`,{type:`button`,onClick:()=>g(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${h===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(ye,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.crop`)]})]}),E&&_?a(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:a(mr,{src:_,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`}),m&&a(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:a(z,{className:`h-3.5 w-3.5 animate-spin`})})]}):e(`div`,{className:`flex aspect-square w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[a(f,{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:D})]})]}),e(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[t.assigned?e(J,{variant:`secondary`,onClick:()=>c(t.faceId),disabled:u,children:[a(_e,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.detach`)]}):e(J,{variant:`primary`,onClick:()=>o(t.faceId),disabled:u,children:[a(w,{className:`h-3.5 w-3.5`}),` `,d(`common.assign`)]}),e(J,{variant:`secondary`,onClick:()=>l(t.faceId),disabled:u,children:[a(v,{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(f,{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(f,{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?b:B,{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(z,{className:`h-4 w-4 animate-spin`}):a(v,{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(),_=ne(),v=mt(),[y,b]=s(Or),[x,S]=s(jr),[C,T]=s(null),[E,D]=s({}),[O,k]=s(null),{data:A,isFetching:j,refetch:M}=Ye({threshold:y,minClusterSize:x,limit:wr},{enabled:t}),N=A??[];o(()=>{D({})},[y,x]),o(()=>{if(N.length===0){T(null);return}N.some(e=>e.representativeFaceId===C)||T(N[0]?.representativeFaceId??null)},[N]);let P=n(()=>N.find(e=>e.representativeFaceId===C)??null,[N,C]),F=P?E[P.representativeFaceId]??new Set:new Set,I=n(()=>P?Sr(P,e=>i.has(e)):[],[P,i]),ee=P?P.faceIds.length-I.length:0,L=P?xr({...P,faceIds:I},F):[];function R(e){if(!P)return;let t=P.representativeFaceId;D(n=>({...n,[t]:br(n[t]??new Set,e)}))}function B(){h.invalidateQueries({queryKey:Cr})}async function V(e){await _({title:m(`detectionIntelligence.similarGroupsModal.deleteFace`,`Delete face`),message:m(`detectionIntelligence.similarGroupsModal.permanentlyDeletesThisFaceCrop`,`Permanently deletes this face crop. This cannot be undone.`),confirmLabel:m(`common.delete`,`Delete`),variant:`danger`})&&v.mutate({faceId:e},{onSettled:B})}function H(){k(null),r()}function U(){L.length!==0&&(p(L),H())}return e(et,{open:t,onOpenChange:e=>!e&&H(),children:[e(xt,{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(W,{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:()=>{D({}),M()},disabled:j,children:[j?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(g,{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:j&&N.length===0?e(`div`,{className:`flex flex-1 items-center justify-center gap-2 py-8 text-xs text-foreground-subtle`,children:[a(z,{className:`h-4 w-4 animate-spin`}),` `,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:()=>T(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:()=>T(e.representativeFaceId)},e.representativeFaceId))}),a(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:P&&e(d,{children:[ee>0&&a(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:m(`detectionIntelligence.similarGroupsModal.hiddenCount`,{count:ee})}),a(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(13rem,13rem))] justify-start gap-2`,children:I.map(e=>{let t=i.get(e);return t?a(Nr,{face:t,cameraName:c(t.deviceId),nowMs:l,excluded:F.has(e),onToggleExclude:()=>R(e),onDelete:()=>void V(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:U,disabled:L.length===0,children:m(`detectionIntelligence.similarGroupsModal.selectInGallery`,`Select in gallery`)}),e(J,{variant:`primary`,onClick:()=>k(L),disabled:L.length===0,children:[a(w,{className:`h-3.5 w-3.5`}),` `,m(`detectionIntelligence.similarGroupsModal.adopt`,{count:L.length})]})]})]}),a(sr,{faceIds:O,identities:f,onDone:()=>k(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(),p=jt(),m=mt(),h=()=>{d.invalidateQueries({queryKey:Fr})},g=()=>c(t.faceId),_=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:[_===null?e(`button`,{type:`button`,onClick:g,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(f,{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:_,alt:l(`detectionIntelligence.unassignedFaces.faceFrom`,`Face from {{cameraName}}`,{cameraName:n}),onClick:g,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(he,{className:`h-4 w-4 text-primary`}):a(G,{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(),p.mutate({faceId:t.faceId},{onSettled:h})},disabled:p.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:p.isPending?a(z,{className:`h-4 w-4 animate-spin`}):a(_e,{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(w,{className:`h-4 w-4`})}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),m.mutate({faceId:t.faceId},{onSettled:h})},disabled:m.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:m.isPending?a(z,{className:`h-4 w-4 animate-spin`}):a(v,{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),[p,m]=s(new Set),[h,g]=s(new Set),[_,y]=s(null),[b,x]=s(!1),[S,C]=s(null),{data:T,isLoading:E}=gt({limit:Ir,filter:i,includeCrops:!1},{refetchInterval:3e4}),{data:D=[]}=at(),{data:O}=we({isCamera:!0,projection:`slim`}),k=Tt(),A=jt(),j=Nt(),M=mt(),N=Date.now(),P=T??[],F=n(()=>{let e=new Map;for(let t of O??[])e.set(t.id,t.name);return e},[O]),I=e=>F.get(e)??t(`detectionIntelligence.cameraFallback`,{id:String(e)}),ee=n(()=>Kn(P).map(e=>({id:e,name:I(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[P,F]),L=n(()=>Gn(Wn(P,c),p),[P,c,p]),R=nr(L,Lr,n(()=>JSON.stringify([i,c.fromMs,c.toMs,[...p].sort((e,t)=>e-t)]),[i,c.fromMs,c.toMs,p])),V=n(()=>new Map(P.map(e=>[e.faceId,e])),[P]),H=n(()=>er(L),[L]),U=S===null?null:V.get(S)??null,te=()=>{r.invalidateQueries({queryKey:Fr})},ne=()=>g(new Set);function G(e){g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function re(e){g(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function ie(){re($n(L))}let K=[...h],q=k.isPending||j.isPending||M.isPending,ae=A.isPending||M.isPending;function oe(){K.length!==0&&j.mutate({faceIds:K},{onSettled:()=>{te(),ne()}})}function se(){K.length!==0&&Promise.allSettled(K.map(e=>M.mutateAsync({faceId:e}))).then(()=>{te(),ne()})}function ce(e){C(null),y([e])}function le(e){A.mutate({faceId:e},{onSettled:te}),C(null)}function ue(e){M.mutate({faceId:e},{onSettled:te}),C(null)}let de=L.length!==P.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:ee,selected:p,onChange:m}),e(`button`,{type:`button`,onClick:()=>x(!0),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${b?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(W,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.similarGroups`)]}),!E&&H>0&&e(`button`,{type:`button`,onClick:ie,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(f,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.selectCropless`,{count:H})]}),!E&&a(`span`,{className:`text-[10px] text-foreground-subtle ${H>0?`ml-2`:`ml-auto`}`,children:de?t(`detectionIntelligence.unassignedFaces.ofFaces`,`{{value1}} of {{value2}} faces`,{value1:String(L.length),value2:String(P.length)}):t(`detectionIntelligence.unassignedFaces.faceCount`,{count:L.length})})]}),h.size>0&&e(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[a(`span`,{className:`text-xs font-medium text-foreground`,children:t(`common.selectedCount`,{count:h.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[e(J,{variant:`primary`,onClick:()=>y(K),disabled:q,children:[a(w,{className:`h-3.5 w-3.5`}),` `,t(`common.assign`)]}),e(J,{variant:`secondary`,onClick:oe,disabled:q,children:[j.isPending?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(_e,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.detach`,`Detach`)]}),e(J,{variant:`secondary`,onClick:se,disabled:q,children:[a(v,{className:`h-3.5 w-3.5`}),` `,t(`common.delete`)]}),a(J,{variant:`ghost`,onClick:ne,disabled:q,children:a(B,{className:`h-3.5 w-3.5`})})]})]}),E?a(nt,{status:`pending`,pendingMessage:`Loading faces…`,testId:`faces-grid`}):L.length===0?a(Te,{icon:f,title:P.length>0?t(`detectionIntelligence.unassignedFaces.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.unassignedFaces.noFacesFoundForThis`,`No faces found for this filter`),description:P.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(nt,{status:`ready`,testId:`faces-grid`,className:`grid-cols-[repeat(auto-fill,minmax(6.5rem,6.5rem))] justify-start`,children:R.pageItems.map(e=>a(Rr,{face:e,cameraName:I(e.deviceId),nowMs:N,selected:h.has(e.faceId),onToggleSelect:G,onAssign:e=>y([e]),onOpenDetail:C},e.faceId))}),a(ar,{currentPage:R.page,totalItems:R.totalItems,pageSize:R.pageSize,onPageChange:R.setPage,itemNoun:`faces`})]}),a(yr,{face:U,cameraName:U?I(U.deviceId):``,onClose:()=>C(null),onAssign:ce,onUnassign:le,onDelete:ue,actionsPending:ae}),a(sr,{faceIds:_,identities:D,onDone:()=>{y(null),ne()}}),a(Pr,{open:b,onClose:()=>x(!1),byId:V,cameraName:I,nowMs:N,identities:D,selectMany:re})]})}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(),[]),je(se.PipelineAnalyticsFaceGalleryChanged,()=>{r.current?.trigger()})}function Gr(){let{t}=X();return Wr(),e(`div`,{className:`space-y-3`,children:[a(Xe,{headingId:`library-people`,title:t(`detectionIntelligence.people`,`People`),icon:be,testId:`library-section-people`,children:e(`div`,{className:`${p} 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(Xe,{headingId:`library-recent-faces`,title:t(`detectionIntelligence.recentDetectedFaces`,`Recent detected faces`),icon:ue,testId:`library-section-recent-faces`,children:e(`div`,{className:`${p} 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),g=oi(t.windowMs),_=()=>i(t),v=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:_,className:`h-full w-full cursor-zoom-in object-cover`}):a(`button`,{type:`button`,onClick:_,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-surface-hover text-foreground-subtle`,title:p.failed?d(`detectionIntelligence.eventCard.keyEventMediaUnavailable`,`Key-event media unavailable`):d(`detectionIntelligence.eventCard.noKeyEventMedia`,`No key-event media`),children:a(f,{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(he,{className:`h-4 w-4 text-primary`}):a(G,{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)}),v!==null&&a(`span`,{className:`absolute bottom-1 right-1 z-10 rounded px-1.5 py-0.5 text-[10px] font-semibold text-white ${v.tone===`warning`?`bg-warning/90`:`bg-black/70`}`,title:v.title,children:v.label}),(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(C,{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(y,{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(L,{className:`h-3 w-3`})})]})]}),e(`button`,{type:`button`,onClick:_,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)}),g&&a(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:g})]})]}),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=F();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:U,{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}=Ee({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}=rt({addonId:e},{refetchInterval:gi,retry:!1});return o(()=>{let e=n?le.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 Pe==`function`,xi=`Track flags arrive with the next server update`;function Si(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var Ci=bi?Pe: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=H(),[f,p]=s(null),m=f?.markForTrain??r===!0,h=f?.debug??i===!0,g=f?.favourited??o===!0,_=!bi||u.isPending,v=bi?void 0:xi,b=e=>{_||(async()=>{try{let r=wi(await u.mutateAsync({deviceId:t,trackId:n,flags:e}));if(!r)return;p(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:m,disabled:_,...v===void 0?{}:{title:v},icon:a(C,{className:`h-4 w-4`}),onToggle:()=>b({markForTrain:!m})}),a(Ti,{label:l(`detectionIntelligence.trackFlagToggles.debug`,`Debug`),hint:l(`detectionIntelligence.trackFlagToggles.flagThisTrackForDiagnostic`,`Flag this track for diagnostic attention`),checked:h,disabled:_,...v===void 0?{}:{title:v},icon:a(y,{className:`h-4 w-4`}),onToggle:()=>b({debug:!h})}),a(Ti,{label:l(`detectionIntelligence.trackFlagToggles.favourited`,`Favourited`),hint:l(`detectionIntelligence.trackFlagToggles.keepsThisTrackAndIts`,`Keeps this track and its media past retention`),checked:g,disabled:_,...v===void 0?{}:{title:v},icon:a(L,{className:`h-4 w-4`}),onToggle:()=>b({favourited:!g})})]})}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=ce(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 Le==`function`,Fi=`Track deletion arrives with the next server update`;function Ii(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var Li=Pi?Le:Ii;l();var Ri=15e3,zi=M();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(f,{className:`h-4 w-4 text-foreground-subtle opacity-60`}):a(z,{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:p}){let{t:m}=X(),h=ee(),g=H(),_=ne(),y=Li(),b=t!==null,x=t?.deviceId??0,S=t?.trackId??``,C=t?.timestamp??0,w=t?.windowMs??0,{data:T}=xe({deviceId:x,trackId:S},{enabled:b}),{data:E}=Re({trackId:S,deviceId:x},{enabled:b}),D=T?.bestEventId===void 0?void 0:Number(T.bestEventId),{data:O}=Ie({ownerType:`object`,eventId:D??0,deviceId:x},{enabled:b&&D!==void 0&&Number.isFinite(D)}),{data:A}=wt({deviceId:x},{enabled:b}),j=(A??[]).find(e=>e.addonId!==void 0)?.addonId,{data:M}=yt({deviceId:x,since:C-Ri,until:C+w+Ri,provider:j??``},{enabled:b&&j!==void 0}),[N,P]=s(null),[F,I]=s(!1),{publicOrigin:L,probes:R}=_i(b);o(()=>{P(null)},[x,S]);let B=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]),V=N??B,U=Ht(V?V.url:void 0),W=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]),te=n(()=>W.find(e=>Vi.has(e.kind))??null,[W]),G=Ui(Ht(te?te.url:void 0).src),re=n(()=>Ni(T?.positions??[],G,{snapshots:(T?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaId:e.mediaId}))}),[T?.positions,T?.snapshots,G]),ie=i(e=>{let t=W.find(t=>t.mediaId===e);t&&P(t)},[W]);if(t===null)return null;let K=U.src,q=V?.kind,ae=q!==void 0&&Hi.has(q)&&G!==null&&(T?.positions.length??0)>=2,oe=M&&M.length>0?M[0]:null,se=()=>{oe&&(I(!0),(async()=>{try{let e=await h.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:oe.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{g({title:m(`detectionIntelligence.eventDetailPanel.clipUnavailable`,`Clip unavailable`),message:m(`detectionIntelligence.eventDetailPanel.couldNotResolveClipPlayback`,`Could not resolve clip playback. Check the server logs.`),variant:`warning`})}finally{I(!1)}})())},ce=()=>{!c||y.isPending||(async()=>{if(await _({title:m(`detectionIntelligence.eventDetailPanel.deleteTrack`,`Delete track`),message:m(`detectionIntelligence.eventDetailPanel.deleteThisTrackAndEvery`,`Delete this track and every image and clip captured for it? This cannot be undone.`),confirmLabel:m(`common.delete`,`Delete`),variant:`danger`}))try{await y.mutateAsync({deviceId:t.deviceId,trackIds:[t.trackId]}),u()}catch{await g({title:m(`detectionIntelligence.eventDetailPanel.deleteFailed`,`Delete failed`),message:m(`detectionIntelligence.eventDetailPanel.failedToDeleteThisTrack`,`Failed to delete this track. Check the server logs.`),variant:`danger`})}})()},le=Math.round(t.importance*100),ue=T?.importanceReason?`${String(le)}% · ${T.importanceReason}`:`${String(le)}%`,de=T?.zonesVisited&&T.zonesVisited.length>0?T.zonesVisited.join(`, `):`—`,fe=T?.audioLabels&&T.audioLabels.length>0?T.audioLabels:t.audioLabels&&t.audioLabels.length>0?t.audioLabels:void 0,pe=fe===void 0?`—`:fe.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `),me=T?T.totalDistance.toFixed(2):`—`,he=ai(T?.previewMissReason),ge=Zn(T?T.firstSeen:C),_e=T?Zn(T.lastSeen):`—`,ve=Oi(T),ye={detected:m(`detectionIntelligence.eventDetailPanel.detectedOn`,`Detected on`),opened:m(`detectionIntelligence.eventDetailPanel.openedOn`,`Opened on`),closed:m(`detectionIntelligence.eventDetailPanel.closedOn`,`Closed on`)};return a(et,{open:!0,onOpenChange:e=>!e&&l(),children:e(xt,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":m(`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:m(`detectionIntelligence.eventDetailPanel.keyFrameFrom`,`Key frame from {{cameraName}}`,{cameraName:r}),fit:`natural`,className:`w-full`,overlay:ae?a(Wi,{overlay:re,onPickSnapshot:ie}):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:U.failed?e(d,{children:[a(f,{className:`h-8 w-8 opacity-60`}),a(`span`,{className:`text-[11px]`,children:m(`detectionIntelligence.eventDetailPanel.keyFrameMediaUnavailable`,`Key-frame media unavailable`)})]}):a(z,{className:`h-6 w-6 animate-spin opacity-70`})}),W.length>0&&a(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:W.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,oe&&e(J,{variant:`secondary`,onClick:se,disabled:F,children:[F?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(k,{className:`h-3.5 w-3.5`}),` `,m(`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:p}),he!==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:m(`detectionIntelligence.eventDetailPanel.bestShot`,`Best shot`)}),a(`p`,{className:`mt-0.5 text-xs text-foreground`,children:he.sentence}),a(`code`,{className:`mt-1 block break-all font-mono text-[10px] text-foreground-subtle`,children:he.raw})]}),e(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[a(Z,{label:m(`detectionIntelligence.eventDetailPanel.camera`,`Camera`),value:r}),ve.map(e=>a(Z,{label:ye[e.kind],value:e.value,mono:!0,wrap:!0},e.kind)),a(Z,{label:m(`detectionIntelligence.eventDetailPanel.class`,`Class`),value:t.className}),a(Z,{label:m(`detectionIntelligence.eventDetailPanel.label`,`Label`),value:t.label??`—`}),a(Z,{label:m(`detectionIntelligence.eventDetailPanel.subLabel`,`Sub-label`),value:t.subLabel??`—`}),a(Z,{label:m(`detectionIntelligence.eventDetailPanel.importance`,`Importance`),value:ue}),a(Z,{label:m(`detectionIntelligence.eventDetailPanel.zonesVisited`,`Zones visited`),value:de}),a(Z,{label:m(`detectionIntelligence.eventDetailPanel.audioHeard`,`Audio heard`),value:pe}),a(Z,{label:m(`detectionIntelligence.eventDetailPanel.totalDistance`,`Total distance`),value:me}),a(Z,{label:m(`detectionIntelligence.eventDetailPanel.firstSeen`,`First seen`),value:ge}),a(Z,{label:m(`detectionIntelligence.eventDetailPanel.lastSeen`,`Last seen`),value:_e}),a(Z,{label:m(`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:ce,disabled:!c||y.isPending,children:[y.isPending?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(v,{className:`h-3.5 w-3.5`}),` `,m(`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=E(`/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($e,{value:o,options:[...t],onChange:e=>c(e.target.value),"aria-label":i(`eventsDebugTapesPromoteForm.camera`,`Camera`)})}),a(st,{type:`datetime-local`,"aria-label":i(`eventsDebugTapesPromoteForm.from`,`From`),value:l,onChange:e=>u(e.target.value),className:`w-48`}),a(st,{type:`datetime-local`,"aria-label":i(`eventsDebugTapesPromoteForm.to`,`To`),value:d,onChange:e=>f(e.target.value),className:`w-48`}),a(st,{"aria-label":i(`eventsDebugTapesPromoteForm.scenario`,`Scenario`),placeholder:`101-door-groups`,value:p,onChange:e=>m(e.target.value),className:`w-44`}),a(st,{"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($e,{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(z,{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=E(`/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(Ue,{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(st,{"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(Ue,{message:g}),C!==null&&a(Ue,{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(Ct,{variant:`info`,children:e},e))]})}l();var to=`camstack_admin_token`;function no(){let e=ee();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(Be,{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=we({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(zt,{i18nKey:`eventsDebugTapes.intro`,components:{b:a(`strong`,{}),code:a(`code`,{})}})}),p!==null&&a(Ue,{message:p}),l.isLoading&&a(`p`,{className:`text-xs text-foreground-subtle`,children:t(`eventsDebugTapes.loadingCameraStatus`,`Loading camera status…`)}),l.data===null&&a(Ue,{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(Ct,{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(Ue,{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(Ct,{variant:n.state===`complete`?`success`:`warning`,children:n.state}),` `,n.reviewed&&a(Ct,{variant:`info`,children:t(`eventsDebugTapes.reviewed`)}),` `,n.released&&a(Ct,{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(A,{className:`h-3.5 w-3.5`})}),a(ut,{label:t(`eventsDebugTapes.release`,`Release`),icon:ie,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(ut,{label:t(`common.delete`,`Delete`),icon:v,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(Ct,{variant:`success`,children:t(`eventsDebug.noAnomalyFound`,`no anomaly found`)}):a(`div`,{className:`flex flex-wrap gap-1`,children:Ja(e).map(e=>a(Ct,{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=ee(),[i,o]=s(oo),[l,u]=s(!1),[d,f]=s(null),[p,m]=s(new Set),[h,_]=s(null),[v,x]=s(null),[S,C]=s(null),[w,E]=s([]),D=Ci(),O=we({isCamera:!0,projection:`slim`}),k=n(()=>[{value:oo,label:t(`eventsDebug.allCameras`,`All cameras`)},...(O.data??[]).map(e=>({value:String(e.id),label:e.name}))],[O.data,t]),j=n(()=>{let e=new Map;for(let t of O.data??[])e.set(t.id,t.name);return e},[O.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}}))}),F=n(()=>(P.data?.tracks??[]).map(e=>e.trackId),[P.data]),I=c({queryKey:[`events-debug`,`analyze`,F],enabled:F.length>0,queryFn:async()=>Wa(await r.trpcClient.addons.custom.mutate({addonId:ja,action:Na,input:{trackIds:F}}))}),R=n(()=>{let e=new Map;for(let t of I.data?.reports??[])e.set(t.trackId,t);return e},[I.data]),V=P.data?.tracks??[],H=P.data===null||I.data===null,U=()=>{P.refetch(),I.refetch()},W=e=>{m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},te=()=>{m(new Set(V.map(e=>Za(e.deviceId,e.trackId))))},ne=()=>m(new Set),G=async(e,t)=>{let n=e===`analyzed`?{debug:!1}:{favourited:!0},r=0,i=[];for(let e of t)try{await D.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,flags:n}),r+=1}catch{i.push(e.trackId)}return{applied:r,refused:i}},re=e=>{if(!bi||v!==null)return;let t=Qa(V,p);t.length!==0&&(x(e),C(null),(async()=>{let n=await G(e,t);x(null);let r=new Set(n.refused);m(new Set(t.filter(e=>r.has(e.trackId)).map(e=>Za(e.deviceId,e.trackId)))),e===`analyzed`&&E(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()})())},ie=()=>{let e=w;e.length===0||v!==null||(x(`analyzed`),C(null),(async()=>{for(let t of e)try{await D.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,flags:{debug:!0}})}catch{C(`Some tracks could not be re-marked. Refresh and try again.`)}x(null),E([]),P.refetch()})())},K=async()=>{u(!0),f(null);try{await Kt(Ya(N),`camstack-debug.zip`)}catch(e){f(e instanceof Error?e.message:`Export failed.`)}finally{u(!1)}},q=v!==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($e,{value:i,options:k,onChange:e=>o(e.target.value)})}),e(J,{variant:`secondary`,onClick:U,disabled:P.isFetching,children:[P.isFetching?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(g,{className:`h-3.5 w-3.5`}),t(`common.refresh`,`Refresh`)]}),e(J,{onClick:()=>void K(),disabled:l||V.length===0,children:[l?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(A,{className:`h-3.5 w-3.5`}),t(`eventsDebug.exportAll`,{count:String(V.length)})]}),V.length>0&&p.size<V.length&&a(J,{variant:`ghost`,onClick:te,children:t(`eventsDebug.selectAll`,`Select all`)})]}),a(`p`,{className:`text-xs text-foreground-subtle`,children:a(zt,{i18nKey:`eventsDebug.debugMarkNote`,components:{code:a(`code`,{}),strong:a(`strong`,{})}})}),a(io,{}),P.isError&&a(Ue,{message:t(`eventsDebug.couldNotLoadTheMarked`,`Could not load the marked tracks.`)}),H&&!P.isError&&a(Ue,{message:so}),d!==null&&a(Ue,{message:d}),S!==null&&a(Ue,{message:S}),P.data?.truncated===!0&&a(Ue,{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.`)}),(I.data?.vanished.length??0)>0&&a(`p`,{className:`text-xs text-foreground-subtle`,children:t(`eventsDebug.vanished`,{count:String(I.data?.vanished.length)})}),p.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:p.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:()=>re(`keep`),disabled:!bi||q,children:[v===`keep`?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(L,{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:()=>re(`analyzed`),disabled:!bi||q,children:[v===`analyzed`?a(z,{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:ne,disabled:q,children:a(B,{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:ie,disabled:q,children:[a(b,{className:`h-3.5 w-3.5`}),` `,t(`eventsDebug.undo`)]}),a(J,{variant:`ghost`,onClick:()=>E([]),disabled:q,children:a(B,{className:`h-3.5 w-3.5`})})]}),P.isLoading?a(nt,{status:`pending`,pendingMessage:`Loading…`,testId:`debug-tracks-grid`}):V.length===0?a(Te,{icon:y,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(nt,{status:`ready`,testId:`debug-tracks-grid`,children:V.map(e=>{let t=R.get(e.trackId);return a(si,{row:e,cameraName:M(e.deviceId),nowMs:e.lastSeen,selected:p.has(Za(e.deviceId,e.trackId)),onToggleSelect:W,onOpenDetail:_,...t?.thumbnailProvenance===void 0?{}:{provenance:t.thumbnailProvenance},footer:a(uo,{track:e,report:t,analyzing:I.isFetching})},Za(e.deviceId,e.trackId))})}),h&&a(Gi,{row:h,cameraName:M(h.deviceId),deleteAvailable:Pi,onClose:()=>_(null),onDeleted:()=>{_(null),P.refetch()},onFlagsChanged:e=>{e.debug||(_(null),P.refetch())}})]})}var po=200,mo=3e4,ho=[];function go(e){let t=ee(),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 je(se.PipelineAnalyticsDetectionEvent,()=>{p.current?.trigger()}),je(se.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=kt(),[u,d]=s(!1),[f,p]=s(``),[h,g]=s(new Set),_=f.trim().toLowerCase(),v=e=>_.length===0||Dt(e,c).toLowerCase().includes(_),y=n(()=>t.map(e=>({macro:e.macro,subs:e.subs.filter(t=>v(t)||v(e.macro))})).filter(e=>v(e.macro)||e.subs.length>0),[t,_]),b=e=>g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),x=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)},S=e=>{let t=new Set(r);t.has(e)?t.delete(e):t.add(e),i(t)},C=()=>i(new Set),w=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 ${w>0?`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`}),w>0?c(`detectionIntelligence.eventKindFilter.kinds`,`Kinds ({{value1}})`,{value1:String(w)}):c(`detectionIntelligence.eventKindFilter.kinds2`,`Kinds`),a(m,{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(K,{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`}),w>0&&a(`button`,{type:`button`,onClick:C,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:c(`detectionIntelligence.eventKindFilter.clear`,`Clear`)})]}),y.length===0&&a(`div`,{className:`px-1 py-2 text-[11px] text-foreground-subtle`,children:o?c(`detectionIntelligence.eventKindFilter.loadingKinds`,`Loading kinds…`):_.length>0?c(`detectionIntelligence.eventKindFilter.noKindMatchesThatSearch`,`No kind matches that search.`):c(`detectionIntelligence.eventKindFilter.theseCamerasAdvertiseNoEvent`,`These cameras advertise no event kinds.`)}),y.map(t=>{let n=vt(t.macro.iconId),i=h.has(t.macro.kind)||_.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:()=>b(t.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":c(`detectionIntelligence.eventKindFilter.expand`,`Expand`),children:a(i?m:D,{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:()=>x(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:Dt(t.macro,c)})]})]}),i&&t.subs.map(t=>{let n=vt(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:()=>S(t.kind),className:`accent-primary`}),a(n,{className:`h-3.5 w-3.5`,style:{color:l(t.kind)}}),a(`span`,{children:Dt(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:de},{value:`time`,labelKey:`detectionIntelligence.eventsSection.sortRecent`,icon:I}];function Ao(){let{t}=X(),r=u(),i=H(),c=ne(),[l,f]=s(zn),[p,m]=s(new Set),[h,g]=s(new Set),[_,y]=s(0),[b,x]=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=[]}=we({isCamera:!0,projection:`slim`}),P=n(()=>N.map(e=>e.id),[N]),{data:F,isLoading:I}=pt({deviceIds:P},{enabled:P.length>0,staleTime:5*6e4}),ee=n(()=>To(F??[],p),[F,p]),L=Li(),R=L.isPending,{rows:V,isLoading:U}=go({deviceIds:P,since:O,until:k,minImportance:_>0?_:void 0,classFilter:h.size===1?[...h][0]:void 0}),W=n(()=>{let e=new Map;for(let t of N??[])e.set(t.id,t.name);return e},[N]),G=e=>W.get(e)??t(`detectionIntelligence.cameraFallback`,{id:String(e)}),re=n(()=>Kn(V).map(e=>({id:e,name:G(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[V,W]),ie=n(()=>Yr(Xr(V,{cameras:p,classes:h,minImportance:_}),b),[V,p,h,_,b]),K=nr(ie,Oo,n(()=>JSON.stringify([[...p].sort((e,t)=>e-t),[...h].sort(),_,b,O,k]),[p,h,_,b,O,k])),q=()=>{r.invalidateQueries({queryKey:Do})},ae=()=>C(new Set);function oe(e){C(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function se(){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`})&&ce(e)})()}function ce(e){let n=[...e];Promise.allSettled(n.map(([e,t])=>L.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{q();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 le=ie.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:re,selected:p,onChange:m}),a(bo,{groups:ee,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=>y(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:()=>x(n.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${b===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)})}),!U&&a(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:le?t(`detectionIntelligence.eventsSection.ofEvents`,`{{value1}} of {{value2}} events`,{value1:String(ie.length),value2:String(V.length)}):t(`detectionIntelligence.eventsSection.eventCount`,{count:ie.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:se,disabled:!Pi||R,children:[R?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(v,{className:`h-3.5 w-3.5`}),` `,t(`common.delete`,`Delete`)]})}),a(J,{variant:`ghost`,onClick:ae,disabled:R,children:a(B,{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`)})}),U?a(nt,{status:`pending`,pendingMessage:`Loading events…`,testId:`events-grid`}):ie.length===0?a(Te,{icon:te,title:le?t(`detectionIntelligence.eventsSection.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.eventsSection.noKeyEventsInThis`,`No key events in this window`),description:le?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(nt,{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:oe,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:()=>{q(),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=Rt();return e(Ze,{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(C,{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:`${ae} 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),_=Ot(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=[]}=we({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}=pt({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}=Ae({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(K,{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(B,{className:`h-3.5 w-3.5`})})]}),O&&v&&a(z,{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:Dt(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($e,{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(nt,{status:`pending`,pendingMessage:`Searching…`,testId:`semantic-events-grid`}),!k&&!O&&j.length===0&&a(nt,{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(nt,{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(pe,{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=[]}=we({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?m:D,{className:`h-4 w-4 text-foreground-subtle`}),a(pe,{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]=Lt();return t.get(`section`)===`retrain`?a(It,{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=ze(),l=Me(),[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(et,{open:_,onOpenChange:e=>!e&&b(),children:e(xt,{children:[e(ct,{children:[a(Je,{children:v>1?i(`detectionIntelligence.assignPlateDialog.assignPlatesToVehicle`,`Assign {{value1}} plates to vehicle`,{value1:String(v)}):i(`detectionIntelligence.assignPlateDialog.assignPlateToVehicle`,`Assign plate to vehicle`)}),a(ht,{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(st,{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(dt,{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(z,{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(z,{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:p}){let{t:m}=X(),h=u(),{data:g,isFetching:_}=Pt({plateId:t?.plateId??``},{enabled:t!==null}),y=De(),[b,x]=s(`frame`),[S,C]=s(!1),[E,D]=s(``),{frameSrc:k,naturalWidth:A,naturalHeight:j,failed:M}=qo(t?.keyFrameMediaId);o(()=>{C(!1),D(``),x(`frame`)},[t?.plateId]);let P=n(()=>{let e=Jo(g??[]);return e?e.url:Uo(t)},[g,t]),F=n(()=>!t?.plateBbox||A===null||j===null?null:fr(t.plateBbox,A,j),[t?.plateBbox,A,j]);if(t===null)return null;let I=t.keyFrameMediaId!==void 0&&!M,ee=I&&b===`frame`,L=t.assigned?t.vehicleName??`Assigned`:t.recognizedVehicleId?`${t.vehicleName??`Recognized`} (suggested)`:`Unassigned`,R=`${String(Math.round(t.score*100))}%${t.corrected?` · corrected`:``}`;function V(){t&&(D(t.text),C(!0))}function H(){if(!t)return;let e=E.trim().toUpperCase();if(!e||e===t.text){C(!1);return}y.mutate({plateId:t.plateId,text:e},{onSettled:()=>{h.invalidateQueries({queryKey:Ko}),C(!1)}})}return a(et,{open:!0,onOpenChange:e=>!e&&i(),children:e(xt,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":m(`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||m(`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:[I&&e(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[e(`button`,{type:`button`,onClick:()=>x(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${b===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(N,{className:`h-3.5 w-3.5`}),` `,m(`detectionIntelligence.detailPanel.fullFrame`)]}),e(`button`,{type:`button`,onClick:()=>x(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${b===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(ye,{className:`h-3.5 w-3.5`}),` `,m(`detectionIntelligence.detailPanel.crop`)]})]}),ee&&k?a(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:a(mr,{src:k,alt:m(`detectionIntelligence.plateDetailPanel.fullFrameWithDetectedPlate`,`Full frame with detected plate`),fit:`natural`,className:`w-full`,overlay:F?a(Xo,{box:F}):void 0})}):P?e(`div`,{className:`relative aspect-[2/1] w-full overflow-hidden rounded-lg border border-border bg-background`,children:[a(mr,{src:P,alt:m(`detectionIntelligence.plateDetailPanel.detectedPlate`,`Detected plate`),className:`h-full w-full`}),_&&a(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:a(z,{className:`h-3.5 w-3.5 animate-spin`})})]}):e(`div`,{className:`flex aspect-[2/1] w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[a(f,{className:`h-8 w-8 text-warning/70`}),a(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:m(`detectionIntelligence.plateDetailPanel.noImage`,`No image`)}),a(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:m(`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:m(`detectionIntelligence.plateDetailPanel.plateText`,`Plate text`)}),S?e(`div`,{className:`flex min-w-0 flex-1 items-center justify-end gap-1.5`,children:[a(st,{value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`&&H(),e.key===`Escape`&&C(!1)},className:`h-7 max-w-[10rem] text-right font-mono text-xs uppercase`,autoFocus:!0}),a(`button`,{type:`button`,onClick:H,disabled:y.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":m(`detectionIntelligence.plateDetailPanel.saveCorrectedText`,`Save corrected text`),children:y.isPending?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(T,{className:`h-3.5 w-3.5`})}),a(`button`,{type:`button`,onClick:()=>C(!1),className:`text-foreground-subtle hover:text-foreground`,"aria-label":m(`common.cancel`,`Cancel`),children:a(B,{className:`h-3.5 w-3.5`})})]}):e(`button`,{type:`button`,onClick:V,className:`group flex min-w-0 items-center gap-1.5`,title:m(`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(O,{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:m(`detectionIntelligence.plateDetailPanel.camera`,`Camera`),value:r}),a(Yo,{label:m(`detectionIntelligence.plateDetailPanel.captured`,`Captured`),value:Zn(t.timestamp)}),a(Yo,{label:m(`detectionIntelligence.plateDetailPanel.confidence`,`Confidence`),value:R}),a(Yo,{label:m(`detectionIntelligence.plateDetailPanel.vehicle`,`Vehicle`),value:L}),a(Yo,{label:m(`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:p,children:[a(_e,{className:`h-3.5 w-3.5`}),` `,m(`detectionIntelligence.detailPanel.detach`)]}):e(J,{variant:`primary`,onClick:()=>c(t.plateId),disabled:p,children:[a(w,{className:`h-3.5 w-3.5`}),` `,m(`common.assign`)]}),e(J,{variant:`secondary`,onClick:()=>d(t.plateId),disabled:p,children:[a(v,{className:`h-3.5 w-3.5`}),` `,m(`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(),p=Oe(),m=Fe(),h=()=>{d.invalidateQueries({queryKey:Qo})},g=()=>c(t.plateId),_=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:[_===null?e(`button`,{type:`button`,onClick:g,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(f,{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:_,alt:l(`detectionIntelligence.recentPlates.plateFrom`,`Plate {{text}} from {{cameraName}}`,{text:t.text,cameraName:n}),onClick:g,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(he,{className:`h-4 w-4 text-primary`}):a(G,{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(ge,{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(),p.mutate({plateId:t.plateId},{onSettled:h})},disabled:p.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:p.isPending?a(z,{className:`h-4 w-4 animate-spin`}):a(_e,{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(w,{className:`h-4 w-4`})}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),m.mutate({plateId:t.plateId},{onSettled:h})},disabled:m.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:m.isPending?a(z,{className:`h-4 w-4 animate-spin`}):a(v,{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),[p,m]=s(new Set),[h,g]=s(new Set),[_,y]=s(null),[b,x]=s(null),{data:S,isLoading:C}=Se({limit:$o,includeCrops:!1},{refetchInterval:3e4}),{data:T=[]}=ke(),{data:E}=we({isCamera:!0,projection:`slim`}),D=Oe(),O=Ne(),k=Fe(),A=Date.now(),j=S??[],M=n(()=>{let e=new Map;for(let t of E??[])e.set(t.id,t.name);return e},[E]),N=e=>M.get(e)??t(`detectionIntelligence.cameraFallback`,{id:String(e)}),P=n(()=>Kn(j).map(e=>({id:e,name:N(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[j,M]),F=n(()=>Gn(Wn(rs(j,i),c),p),[j,i,c,p]),I=nr(F,es,n(()=>JSON.stringify([i,c.fromMs,c.toMs,[...p].sort((e,t)=>e-t)]),[i,c.fromMs,c.toMs,p])),ee=n(()=>new Map(j.map(e=>[e.plateId,e])),[j]),L=b===null?null:ee.get(b)??null,R=()=>{r.invalidateQueries({queryKey:Qo})},V=()=>g(new Set);function H(e){g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}let U=[...h],W=O.isPending||k.isPending,te=D.isPending||k.isPending;function ne(){U.length!==0&&O.mutate({plateIds:U},{onSettled:()=>{R(),V()}})}function G(){U.length!==0&&Promise.allSettled(U.map(e=>k.mutateAsync({plateId:e}))).then(()=>{R(),V()})}function re(e){x(null),y([e])}function ie(e){D.mutate({plateId:e},{onSettled:R}),x(null)}function K(e){k.mutate({plateId:e},{onSettled:R}),x(null)}let q=F.length!==j.length;return e(`div`,{className:`relative space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[a(`div`,{className:`flex items-center gap-1`,children: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:p,onChange:m}),!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(j.length)}):t(`detectionIntelligence.recentPlates.plateCount`,{count:F.length})})]}),h.size>0&&e(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[a(`span`,{className:`text-xs font-medium text-foreground`,children:t(`common.selectedCount`,{count:h.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[e(J,{variant:`primary`,onClick:()=>y(U),disabled:W,children:[a(w,{className:`h-3.5 w-3.5`}),` `,t(`common.assign`)]}),e(J,{variant:`secondary`,onClick:ne,disabled:W,children:[O.isPending?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(_e,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.recentPlates.detach`,`Detach`)]}),e(J,{variant:`secondary`,onClick:G,disabled:W,children:[a(v,{className:`h-3.5 w-3.5`}),` `,t(`common.delete`)]}),a(J,{variant:`ghost`,onClick:V,disabled:W,children:a(B,{className:`h-3.5 w-3.5`})})]})]}),C?a(nt,{status:`pending`,pendingMessage:`Loading plates…`,testId:`plates-grid`}):F.length===0?a(Te,{icon:f,title:j.length>0?t(`detectionIntelligence.recentPlates.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.recentPlates.noPlatesRecognizedYet`,`No plates recognized yet`),description:j.length>0?t(`detectionIntelligence.recentPlates.widenTheDateRangeOr`,`Widen the date range or clear the camera filter.`):t(`detectionIntelligence.recentPlates.plateReadsAppearHereWhen`,`Plate reads appear here when the detection pipeline OCRs a vehicle.`)}):e(d,{children:[a(nt,{status:`ready`,testId:`plates-grid`,children:I.pageItems.map(e=>a(ts,{plate:e,cameraName:N(e.deviceId),nowMs:A,selected:h.has(e.plateId),onToggleSelect:H,onAssign:e=>y([e]),onOpenDetail:x},e.plateId))}),a(ar,{currentPage:I.page,totalItems:I.totalItems,pageSize:I.pageSize,onPageChange:I.setPage,itemNoun:`plates`})]}),a(Zo,{plate:L,cameraName:L?N(L.deviceId):``,onClose:()=>x(null),onAssign:re,onUnassign:ie,onDelete:K,actionsPending:te}),a(Go,{plateIds:_,vehicles:T,onDone:()=>{y(null),V()}})]})}l();var as=[[`plateGallery`]];function os({vehicleId:t}){let{t:n}=X(),r=u(),{data:i,isLoading:o}=Ge({vehicleId:t}),s=We();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(z,{className:`h-3.5 w-3.5 animate-spin`}),n(`detectionIntelligence.vehiclesList.loadingPlates`,`Loading plates…`)]}):!i||i.length===0?a(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:n(`detectionIntelligence.vehiclesList.noPlatesYet`,`No plates yet.`)}):a(`div`,{className:`mt-2 grid grid-cols-3 gap-2 sm:grid-cols-4 md:grid-cols-6`,children:i.map(t=>e(`div`,{className:`group relative overflow-hidden rounded-md border border-border bg-surface`,children:[e(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[t.base64?a(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:t.text,className:`h-full w-full object-cover`}):a(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:a(x,{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(B,{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(x,{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(Ct,{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(qe,{variant:`ghost`,size:`sm`,icon:O,"aria-label":Y.t(`detectionIntelligence.vehiclesList.edit`,`Edit {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onEdit(n)}}),a(qe,{variant:`ghost`,size:`sm`,icon:v,"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=Me(),p=Ke();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:as})}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(_t,{open:!0,onClose:r,title:t===`new`?`Add vehicle`:`Edit ${n?.name??`vehicle`}`,icon:x,width:t===`edit`?`xl`:`lg`,testId:`vehicles-vehicle-form`,footer:e(J,{variant:`primary`,size:`sm`,type:`button`,onClick:y,disabled:_,children:[m?a(z,{className:`h-3.5 w-3.5 animate-spin`}):null,t===`new`?i(`common.add`,`Add`):i(`common.save`,`Save`)]}),children:e(`div`,{className:`space-y-4`,children:[a(Mt,{label:i(`detectionIntelligence.vehiclesList.name`,`Name`),required:!0,children:a(st,{value:l,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&y()},placeholder:i(`detectionIntelligence.vehiclesList.vehicleName`,`Vehicle name…`),autoFocus:!0})}),t===`edit`&&n!==null&&e(`div`,{children:[a(`p`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:i(`detectionIntelligence.vehiclesList.plateSamples`,`Plate samples`)}),a(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:i(`detectionIntelligence.vehiclesList.removeAPlateCropTo`,`Remove a plate crop to drop it from recognition for this vehicle. Assign new plates from Recent recognized plates.`)}),a(os,{vehicleId:n.id})]})]})})}function ls(){let{t}=X(),r=u(),i=ne(),{data:s,isLoading:c}=ke(),l=Ve(),{state:d,openNew:f,openEdit:p,close:m}=ot(),h=s??[],g=it(h,{searchText:e=>[e.name]}),v=d.mode===`edit`?h.find(e=>e.id===d.id)??null:null;o(()=>{d.mode===`edit`&&!c&&v===null&&m()},[d.mode,c,v,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(z,{className:`h-4 w-4 animate-spin`}),t(`detectionIntelligence.vehiclesList.loadingVehicles`,`Loading vehicles…`)]});let b=d.mode===`new`||d.mode===`edit`&&v!==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(_,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.vehiclesList.addVehicle`,`Add vehicle`)]})}),(h.length>0||g.active)&&a(bt,{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(Te,{icon:x,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(He,{columns:y,rows:g.rows,rowKey:e=>e.id,maxBodyHeight:Ce,emptyMessage:t(`detectionIntelligence.vehiclesList.noVehiclesEnrolledYet2`,`No vehicles enrolled yet.`),onRowClick:e=>p(e.id)}),b&&a(cs,{mode:d.mode===`new`?`new`:`edit`,vehicle:v,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(),[]),je(se.PipelineAnalyticsPlateGalleryChanged,()=>{r.current?.trigger()})}function ps(){let{t}=X();return fs(),e(`div`,{className:`space-y-3`,children:[a(Xe,{headingId:`library-vehicles`,title:t(`plates.vehicles`,`Vehicles`),icon:x,testId:`library-section-vehicles`,children:e(`div`,{className:`${p} 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(Xe,{headingId:`library-recent-plates`,title:t(`plates.recentRecognizedPlates`,`Recent recognized plates`),icon:fe,testId:`library-section-recent-plates`,children:e(`div`,{className:`${p} 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:re(Math.max(0,t-n))})}function bs(e){return P(e.monitor).tone}function xs(e){let t=Number(e);return Number.isFinite(t)&&t>0?t:null}function Ss(){let{t}=X(),i=we({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=it(d,{searchText:e=>[e.monitor.label,e.deviceName],facetValue:bs}),{state:p,openNew:m,openEdit:h,close:g}=ot(),[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}`,C=Date.now(),w=[{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=P(e.monitor);return a(Ct,{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,C)})},{key:`coverage`,header:t(`scenes.variants`,`Variants`),notSortableReason:`Coverage is a summary string`,render:e=>a(`span`,{className:`text-xs text-foreground-muted`,children:V(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,C)})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:e=>a(J,{variant:`ghost`,onClick:()=>h(String(e.deviceId)),children:t(`scenes.open`,`Open`)})}];return e(`section`,{className:`space-y-3`,children:[e(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between sm:gap-4`,children:[a(`p`,{className:`text-xs text-foreground-subtle`,children:t(`scenes.aSceneWatchesOneRegion`,`A scene watches one region of one camera and tells you when it stops looking like the picture you captured — a wheelie bin, a gate, a parking space.`)}),e(J,{onClick:m,disabled:c.length===0,className:`shrink-0`,children:[a(_,{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(bt,{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(Ze,{variant:`flat`,className:`p-0`,children:a(He,{columns:w,rows:f.rows,rowKey:e=>`${e.deviceId}:${e.monitor.id}`,minWidthPx:880,bordered:!1,maxBodyHeight:Ce,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(_t,{open:!0,onClose:g,title:t(`scenes.whichCamera`,`Which camera?`),icon:S,width:`sm`,testId:`scenes-camera-picker`,footer:a(J,{onClick:()=>{v!==null&&h(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($e,{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(_t,{open:!0,onClose:g,title:t(`scenes.scenes`,`Scenes — {{editingName}}`,{editingName:x}),icon:S,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(Et,{deviceId:b})})]})]})}function Cs(){let{t:e}=X(),t=Ft(`/library`,{t:e,isAdmin:!0})??{icon:ve,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};
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./browser-BHo8W_uH.js","./rolldown-runtime-Cyuzqnbw.js"])))=>i.map(i=>d[i]);
2
- import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{t}from"./vite-preload-helper-kNaey6uv.js";import{C as n,J as r,K as i,S as a,V as o,Y as s,a as c,et as l,t 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{Ht as f,Q as p,Vn as m,Wr as h,Zi as g,an as _,bi as v,br as y,dt as b,fr as x,hr as S,lr as C,pa as w,pn as T,ri as E,st as D,xi as O,zt as k}from"./player-overlays-B4lehTI4.js";import{Gr as A,Kr as j}from"./client-C6c46gRD.js";import{s as M}from"./video-B-2RwuDj.js";import{t as N}from"./key-round-DmUg5DWL.js";import{t as ee}from"./monitor-smartphone-DJqsZ1_F.js";import{t as te}from"./unlink-Chgtl9c5.js";import{Et as ne,Ks as re,Ld as P,Wr as F,Ws as I,Yr as L,dd as ie,lr as ae,mn as oe,ur as se}from"./src-DlnTixq9.js";import{t as ce}from"./i18n-uD14huY2.js";import{t as R}from"./useTranslation-BJr-n0es.js";import"./mount-DuRGlFHX.js";import{_ as le,b as z,er as B,fr as V,gr as H,ur as U,v as W,y as ue}from"./index-pzq9LOji.js";import{t as de}from"./AdminSectionedPage-OHmEcMxM.js";import{t as fe}from"./AdminPage-Bn1s1Zyw.js";import{O as pe,T as me,_ as G,a as he,h as ge,k as _e,r as ve,t as K,v as ye}from"./SessionsList-_-3LQsWm.js";l();var be=`${A}/connect`,q={public:0,mesh:1,lan:2,"lan-ipv6":3};function xe(e){switch(e.kind){case`public`:return e.interfaceKind===`vpn`?`mesh`:`public`;case`lan-ipv4`:return`lan`;case`lan-ipv6`:return`lan-ipv6`;case`custom`:return`public`;case`loopback`:case`app-link`:return null}}function J(e){return j(e)}function Se(e){return e.startsWith(`https://`)}function Ce(e){let t=e.flatMap(e=>{let t=xe(e),n=J(e.baseUrl);return t===null||n===null?[]:[{endpoint:e,tier:t,origin:n}]}).toSorted((e,t)=>q[e.tier]-q[t.tier]||Number(t.endpoint.plausible)-Number(e.endpoint.plausible)||e.endpoint.priority-t.endpoint.priority),n=new Set;return t.flatMap(({endpoint:e,tier:t,origin:r})=>n.has(r)?[]:(n.add(r),[{origin:r,label:e.label,tier:t,secure:Se(r),plausible:e.plausible}]))}function we(e,t,n=null){for(let r of[t,n]){if(r===null)continue;let t=J(r),n=e.find(e=>e.origin===t);if(n!==void 0)return n}return e[0]??null}function Te(e){let t=new URL(be);return t.searchParams.set(`hub`,e),t.toString()}var Ee=176,Y={scheme:`https`};function De(){let{t:e}=R(),t=re(Y),r=I(Y).data?.roles.publicEndpoint.resolved??null;return n(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[n(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[a(_,{className:`h-3.5 w-3.5 text-foreground-subtle`}),a(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`connectPhone.title`)})]}),n(`div`,{className:`p-4 space-y-3`,children:[a(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`connectPhone.description`)}),t.isPending?n(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[a(x,{className:`h-3.5 w-3.5 animate-spin`}),e(`connectPhone.loading`)]}):t.isError?n(`div`,{className:`flex items-start gap-2 text-[11px] text-danger`,children:[a(k,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),n(`div`,{className:`flex-1 min-w-0 space-y-1.5`,children:[a(`div`,{className:`break-words`,children:e(`connectPhone.error`,{message:t.error.message})}),a(L,{size:`sm`,variant:`ghost`,onClick:()=>void t.refetch(),children:e(`connectPhone.retry`)})]})]}):a(Oe,{candidates:Ce(t.data.endpoints),preferredOrigin:r})]})]})}function Oe({candidates:e,preferredOrigin:t}){let{t:r}=R(),[o,c]=s(null),l=we(e,o,t),u=i(()=>l?Te(l.origin):null,[l]);if(l===null||u===null)return a(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`connectPhone.empty`)});let d=e=>r(`connectPhone.tier.${e}`),f=e.map(e=>({value:e.origin,label:`${d(e.tier)} — ${e.origin}`}));return n(`div`,{className:`flex flex-col sm:flex-row gap-4`,children:[a(ae,{value:u,size:Ee,alt:r(`connectPhone.qrAlt`),className:`self-start`}),n(`div`,{className:`flex-1 min-w-0 space-y-3`,children:[n(`label`,{className:`block space-y-1`,children:[a(`span`,{className:`text-[11px] font-medium text-foreground`,children:r(`connectPhone.addressLabel`)}),a(ie,{value:l.origin,options:f,onChange:e=>c(e.target.value)}),n(`span`,{className:`block text-[10px] text-foreground-subtle`,children:[d(l.tier),` · `,l.label]})]}),!l.secure&&a(X,{text:r(`connectPhone.insecure`)}),!l.plausible&&a(X,{text:r(`connectPhone.implausible`)}),n(`div`,{className:`space-y-1`,children:[a(`span`,{className:`text-[11px] font-medium text-foreground`,children:r(`connectPhone.linkLabel`)}),n(`div`,{className:`flex items-center gap-1 rounded-md border border-border bg-background px-2 py-1`,children:[a(`code`,{className:`flex-1 min-w-0 font-mono text-[11px] text-foreground break-all select-all`,children:u}),a(oe,{value:u,srLabel:r(`connectPhone.linkLabel`)})]})]}),a(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`connectPhone.signInHint`)})]})]})}function X({text:e}){return n(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-2.5 py-1.5 text-[11px] text-foreground`,children:[a(k,{className:`h-3.5 w-3.5 text-warning mt-0.5 shrink-0`}),a(`span`,{children:e})]})}l();function ke(e){return new Date(e).toLocaleDateString()}function Ae(){let{t:e}=R(),t=D(),i=P.useUtils(),c=P.auth.listLinkableProviders.useQuery(),l=P.auth.listOwnExternalIdentities.useQuery(),[u,d]=s(null),[f,m]=s(()=>z(window.location.search)),h=r(null),g=G(`Linking a sign-in account`),_=r(null);o(()=>()=>_.current?.(),[]);let[y,b]=s(null);o(()=>{if(f===null)return;let e=new URL(window.location.href);e.searchParams.delete(`linked`),e.searchParams.delete(`linkError`),window.history.replaceState({},``,e.pathname+e.search+e.hash)},[f]);let C=P.auth.beginExternalLink.useMutation({onSuccess:({url:e})=>{let t=h.current;if(h.current=null,t===null||t.closed){window.location.assign(e);return}let n=e=>{b(null),m(z(`?${e}`)),i.auth.listOwnExternalIdentities.invalidate()};_.current?.(),_.current=W(t,{onReturn:e=>{e.target===`profile`&&n(e.query)},onDone:e=>{e.target===`profile`&&n(e.query)},onClosed:()=>{_.current?.(),_.current=null,i.auth.listOwnExternalIdentities.invalidate()}}),t.location.href=p(ue(e))},onError:e=>{h.current?.close(),h.current=null,b(null),d(e.message)}}),w=P.auth.unlinkOwnExternalIdentity.useMutation({onSuccess:()=>void i.auth.listOwnExternalIdentities.invalidate(),onError:e=>d(e.message)}),T=c.data??[],E=l.data??[],k=y!==null&&E.some(e=>e.provider===y);if(o(()=>{!k||y===null||(b(null),m({kind:`linked`,provider:y}))},[k,y]),T.length===0&&E.length===0)return null;let A=new Set(E.map(e=>e.provider)),j=e=>T.find(t=>t.provider===e)?.label??e,M=async(n,r)=>{await t({title:e(`users.linkedSignInsSection.unlinkSignInAccount`,`Unlink sign-in account`),message:e(`users.linkedSignInsSection.stopSigningInWithThis`,`Stop signing in with this {{label}} account?`,{label:r}),confirmLabel:e(`users.linkedSignInsSection.unlink`,`Unlink`),variant:`danger`})&&(d(null),w.mutate({provider:n.provider,subject:n.subject}))};return n(`div`,{"data-testid":`linked-sign-ins`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[g.dialog,n(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[a(S,{className:`h-3.5 w-3.5 text-foreground-subtle`}),a(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`users.linkedSignInsSection.linkedSignInAccounts`,`Linked sign-in accounts`)})]}),n(`div`,{className:`p-4 space-y-3`,children:[a(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`users.linkedSignInsSection.signInWithAnExternal`,`Sign in with an external account instead of your password. Only accounts you link here can sign you in; your two-factor authentication still applies.`)}),f?.kind===`linked`&&n(`div`,{className:`flex items-center gap-2 rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2 text-xs text-foreground`,children:[a(v,{className:`h-3.5 w-3.5 text-emerald-500 shrink-0`}),e(`users.linkedSignIns.linkedNotice`,{provider:j(f.provider)})]}),(f?.kind===`error`||u)&&n(`div`,{className:`flex items-center gap-2 rounded-md border border-danger/20 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[a(O,{className:`h-3.5 w-3.5 shrink-0`}),u??(f?.kind===`error`?f.message:``)]}),E.length>0&&a(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:E.map(t=>{let r=t.providerLabel??t.provider;return n(`li`,{className:`flex items-center gap-3 px-3 py-2 text-xs`,children:[n(`div`,{className:`flex-1 min-w-0`,children:[n(`div`,{className:`font-medium text-foreground truncate`,children:[r,!t.available&&a(`span`,{className:`ml-2 rounded bg-foreground-subtle/15 px-1.5 py-0.5 text-[10px] font-normal text-foreground-subtle`,children:e(`users.linkedSignInsSection.providerUnavailable`,`provider unavailable`)})]}),a(`div`,{className:`text-[11px] text-foreground-subtle truncate`,children:e(`users.linkedSignIns.linkedOn`,{label:t.label??t.subject,date:ke(t.linkedAt)})})]}),n(`button`,{onClick:()=>void M(t,r),disabled:w.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[a(te,{className:`h-3 w-3`}),e(`users.linkedSignInsSection.unlink`,`Unlink`)]})]},`${t.provider}|${t.subject}`)})}),a(`div`,{className:`flex flex-wrap gap-2`,children:T.filter(e=>!A.has(e.provider)).map(t=>n(`button`,{onClick:()=>{d(null),m(null),g.requestProof().then(e=>{e!==null&&(h.current=le(null),b(h.current===null?null:t.provider),C.mutate({provider:t.provider,reauthToken:e}))})},disabled:C.isPending,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1 text-[11px] font-medium text-foreground hover:bg-surface-hover disabled:opacity-50`,children:[C.isPending&&C.variables?.provider===t.provider?a(x,{className:`h-3 w-3 animate-spin`}):a(S,{className:`h-3 w-3`}),e(`users.linkedSignIns.link`,{provider:t.label})]},t.provider))})]})]})}l();function je({value:r,size:i=192}){let{t:c}=R(),[l,u]=s(null),[d,f]=s(null);if(o(()=>{let n=!1;return t(()=>import(`./browser-BHo8W_uH.js`).then(t=>e(t.default,1)).then(async e=>{if(n)return;let t=e.create;if(typeof t!=`function`){f(`qrcode.create() unavailable in installed version`);return}try{let e=t(r,{errorCorrectionLevel:`M`});n||u(e)}catch(e){n||f(e instanceof Error?e.message:`QR generation failed`)}}),__vite__mapDeps([0,1]),import.meta.url).catch(()=>{n||f(`qrcode library not installed`)}),()=>{n=!0}},[r]),d)return a(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle text-center p-4`,style:{width:i,height:i},children:c(`users.totpQrCode.qrRenderingUnavailableUseThe`,`QR rendering unavailable — use the secret below.`)});if(!l)return a(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle animate-pulse`,style:{width:i,height:i},children:c(`users.totpQrCode.generating`,`Generating…`)});let p=l.modules.size,m=i/p,h=[];for(let e=0;e<p;e++)for(let t=0;t<p;t++)l.modules.data[e*p+t]&&h.push(a(`rect`,{x:t*m,y:e*m,width:m,height:m,fill:`currentColor`},`${t}-${e}`));return n(`svg`,{width:i,height:i,viewBox:`0 0 ${i} ${i}`,className:`text-black`,children:[a(`rect`,{x:0,y:0,width:i,height:i,fill:`white`}),h]})}l();function Me(){let{t:e}=R(),t=b(),[r,i]=s(``),[o,c]=s(``),[l,d]=s(``),[f,p]=s(null),m=u({mutationFn:e=>t.changeOwnPassword(e),onSuccess:()=>{p({kind:`success`,msg:`Password updated.`}),i(``),c(``),d(``)},onError:e=>{p({kind:`error`,msg:e instanceof Error?e.message:`Update failed`})}}),h=o.length>0&&l.length>0&&o!==l,g=o.length>0&&o.length<8,_=r.length>=1&&o.length>=8&&o===l;return n(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[n(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[a(N,{className:`h-3.5 w-3.5 text-foreground-subtle`}),a(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`systemPage.myAccess.changePassword`,`Change password`)})]}),n(`div`,{className:`p-4 space-y-3`,children:[a(Z,{label:e(`systemPage.myAccess.currentPassword`,`Current password`),value:r,onChange:i,autoComplete:`current-password`}),a(Z,{label:e(`systemPage.myAccess.newPassword`,`New password`),value:o,onChange:c,autoComplete:`new-password`,hint:e(`systemPage.myAccess.atLeast8Characters`,`At least 8 characters.`)}),a(Z,{label:e(`systemPage.myAccess.confirmNewPassword`,`Confirm new password`),value:l,onChange:d,autoComplete:`new-password`}),(h||g)&&a(`div`,{className:`text-[11px] text-danger`,children:h?e(`systemPage.myAccess.passwordsDoNotMatch`,`Passwords do not match.`):e(`systemPage.myAccess.newPasswordMustBeAt`,`New password must be at least 8 characters.`)}),f&&n(`div`,{className:`text-[11px] flex items-center gap-1 ${f.kind===`success`?`text-success`:`text-danger`}`,children:[f.kind===`success`?a(v,{className:`h-3 w-3`}):a(O,{className:`h-3 w-3`}),f.msg]}),a(`div`,{className:`flex justify-end`,children:n(L,{onClick:()=>{p(null),m.mutate({currentPassword:r,newPassword:o})},disabled:!_||m.isPending,children:[m.isPending?a(x,{className:`h-3 w-3 animate-spin`}):a(C,{className:`h-3 w-3`}),e(`systemPage.myAccess.updatePassword`,`Update password`)]})})]})]})}function Z({label:e,value:t,onChange:r,autoComplete:i,hint:o}){return n(`div`,{className:`space-y-1`,children:[a(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e}),a(`input`,{type:`password`,value:t,onChange:e=>r(e.target.value),autoComplete:i,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),o&&a(`div`,{className:`text-[10px] text-foreground-subtle`,children:o})]})}function Ne({username:e}){let{t}=R(),r=b(),l=c({queryKey:[`auth`,`getOwnTotpStatus`],queryFn:()=>r.getOwnTotpStatus()}),f=l.data,[p,m]=s(null),[h,g]=s(``),[y,S]=s(null),[C,w]=s(!1),T=u({mutationFn:()=>r.setupOwnTotp(),onSuccess:e=>{m({secret:e.secret,otpauthUrl:e.otpauthUrl}),g(``),S(null)},onError:e=>S(e instanceof Error?e.message:`Setup failed`)}),D=u({mutationFn:e=>r.confirmOwnTotp(e),onSuccess:()=>{m(null),g(``),S(null),l.refetch()},onError:e=>S(e instanceof Error?e.message:`Confirmation failed — code did not match`)}),k=G(`Turning off two-factor authentication`),A=u({mutationFn:async()=>{let e=await k.requestProof();return e===null?null:r.disableOwnTotp({reauthToken:e})},onSuccess:()=>{S(null),l.refetch()},onError:e=>S(e instanceof Error?e.message:`Disable failed`)});o(()=>{if(!C)return;let e=setTimeout(()=>w(!1),1500);return()=>clearTimeout(e)},[C]);let j=i(()=>l.isLoading?`loading`:p?`setup_in_progress`:f?.enabled?`enrolled`:`not_enrolled`,[l.isLoading,f?.enabled,p]);return n(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[k.dialog,n(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[a(_,{className:`h-3.5 w-3.5 text-foreground-subtle`}),a(`div`,{className:`text-xs font-semibold text-foreground`,children:t(`systemPage.myAccess.twoFactorAuthentication`,`Two-factor authentication`)})]}),n(`div`,{className:`p-4 space-y-3`,children:[j===`loading`&&n(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[a(x,{className:`h-3.5 w-3.5 animate-spin`}),t(`systemPage.myAccess.checkingStatus`,`Checking status…`)]}),j===`not_enrolled`&&n(d,{children:[a(`div`,{className:`text-xs text-foreground-subtle`,children:t(`systemPage.myAccess.2faIsnTActiveOn`,`2FA isn't active on your account. Enable it to require a 6-digit code from your authenticator app at every login.`)}),a(`div`,{className:`flex justify-end`,children:n(L,{onClick:()=>{S(null),T.mutate()},disabled:T.isPending,children:[T.isPending?a(x,{className:`h-3 w-3 animate-spin`}):a(_,{className:`h-3 w-3`}),t(`systemPage.myAccess.enable2fa`,`Enable 2FA`)]})})]}),j===`setup_in_progress`&&p&&n(d,{children:[a(`div`,{className:`text-[11px] text-foreground-subtle`,children:a(U,{i18nKey:`systemPage.myAccess.scanQr`,values:{username:e},components:{mono:a(`span`,{className:`font-mono`})}})}),n(`div`,{className:`flex flex-col items-center gap-3`,children:[a(`div`,{className:`rounded-lg border border-border bg-white p-3`,children:a(je,{value:p.otpauthUrl,size:180})}),n(`div`,{className:`w-full`,children:[a(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle mb-1`,children:t(`systemPage.myAccess.secretManualEntry`,`Secret (manual entry)`)}),n(`div`,{className:`flex items-center gap-2 rounded border border-border bg-surface-hover/30 px-2 py-1.5`,children:[a(`code`,{className:`text-[11px] font-mono text-foreground break-all flex-1`,children:p.secret}),n(L,{variant:`ghost`,onClick:()=>{p&&navigator.clipboard.writeText(p.secret).then(()=>w(!0))},children:[C?a(v,{className:`h-3 w-3 text-success`}):a(E,{className:`h-3 w-3`}),C?t(`systemPage.myAccess.copied`,`Copied`):t(`common.copy`,`Copy`)]})]})]})]}),n(`div`,{className:`space-y-1`,children:[a(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`6-digit code`}),a(`input`,{type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,placeholder:`123456`,value:h,onChange:e=>g(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full rounded-md border border-border bg-surface px-3 py-2 text-center text-lg font-mono tracking-widest text-foreground focus:outline-none focus:ring-2 focus:ring-primary`})]}),y&&n(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[a(O,{className:`h-3 w-3`}),y]}),n(`div`,{className:`flex justify-end gap-2`,children:[a(L,{variant:`outline`,onClick:()=>{m(null),S(null),g(``)},children:t(`common.cancel`,`Cancel`)}),n(L,{onClick:()=>{S(null),D.mutate({code:h})},disabled:D.isPending||h.length!==6,children:[D.isPending?a(x,{className:`h-3 w-3 animate-spin`}):a(v,{className:`h-3 w-3`}),t(`common.confirm`,`Confirm`)]})]})]}),j===`enrolled`&&f&&n(d,{children:[n(`div`,{className:`rounded-md border border-success/30 bg-success/5 px-3 py-2.5 flex items-start gap-2.5`,children:[a(v,{className:`h-4 w-4 mt-0.5 text-success shrink-0`}),n(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[a(`div`,{className:`font-medium`,children:t(`systemPage.myAccess.2faIsActive`,`2FA is active`)}),a(`div`,{className:`text-foreground-subtle`,children:t(`common.enrolledOn`,{when:f.confirmedAt?new Date(f.confirmedAt).toLocaleString():`—`})})]})]}),y&&n(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[a(O,{className:`h-3 w-3`}),y]}),a(`div`,{className:`flex justify-end`,children:n(L,{variant:`danger`,onClick:()=>{S(null),A.mutate()},disabled:A.isPending,children:[A.isPending?a(x,{className:`h-3 w-3 animate-spin`}):a(_,{className:`h-3 w-3`}),t(`systemPage.myAccess.disable2fa`,`Disable 2FA`)]})})]})]})]})}function Pe(){return F(`auth-webauthn/passkey-enrollment`)?a(se,{widgetId:`auth-webauthn/passkey-enrollment`,host:`dashboard`}):null}l();function Q(e){return e.message.length>0?e.message:ce.t(`auth.authAuditSection.requestFailed`)}function Fe(){let{t:e}=R(),{logout:t}=B(),r=D(),i=P.useUtils(),o=P.auth.listOwnSessions.useQuery(),[c,l]=s(null),u=P.auth.revokeOwnSession.useMutation({onSuccess:()=>void i.auth.listOwnSessions.invalidate(),onError:e=>l(`Sign out failed: ${Q(e)}`)}),d=P.auth.logout.useMutation({onSuccess:()=>t(),onError:e=>l(`Sign out failed: ${Q(e)}`)}),f=async t=>{await r({title:e(`auth.mySessionsSection.signOutThisSession`,`Sign out this session`),message:e(`auth.mySessionsSection.willHaveToSignIn`,`{{label}} will have to sign in again.`,{label:ye(t.client).label}),confirmLabel:e(`auth.mySessionsSection.signOut`,`Sign out`),variant:`danger`})&&(l(null),u.mutate({id:t.id}))},p=async()=>{await r({title:e(`auth.mySessionsSection.signOutEverywhere`,`Sign out everywhere`),message:e(`auth.mySessionsSection.everySessionOfYourAccount`,`Every session of your account ends, this browser included: you will be signed out here too and every device has to sign in again.`),confirmLabel:e(`auth.mySessionsSection.signOutEverywhere`,`Sign out everywhere`),variant:`danger`})&&(l(null),d.mutate({everywhere:!0}))};return n(`div`,{"data-testid":`my-sessions`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[n(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[a(ee,{className:`h-3.5 w-3.5 text-foreground-subtle`}),a(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`auth.mySessionsSection.activeSessions`,`Active sessions`)})]}),n(`div`,{className:`p-4 space-y-3`,children:[a(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`auth.mySessionsSection.theBrowsersAndAppsSigned`,`The browsers and apps signed in to your account. Signing one out ends it at once.`)}),c!==null&&a(`div`,{className:`text-[11px] text-danger`,children:c}),a(K,{sessions:o.data??[],isLoading:o.isLoading,loadError:o.isError?o.error?.message??e(`auth.authAuditSection.requestFailed`):null,emptyText:`No active sessions.`,onRevoke:e=>void f(e),revokingId:u.isPending?u.variables?.id??null:null}),a(`div`,{className:`flex justify-end`,children:n(`button`,{onClick:()=>void p(),disabled:d.isPending,className:`inline-flex items-center gap-1.5 rounded border border-danger/40 px-2.5 py-1 text-[11px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,children:[d.isPending?a(x,{className:`h-3 w-3 animate-spin`}):a(M,{className:`h-3 w-3`}),e(`auth.mySessionsSection.signOutEverywhere`,`Sign out everywhere`)]})})]})]})}l();var Ie=`You`;function Le(){let{t:e}=R(),t=D(),n=P.useUtils(),r=P.auth.listOwnDeviceCredentials.useQuery(),[o,c]=s(null),l=P.auth.revokeOwnDeviceCredential.useMutation({onSuccess:e=>{e.revoked||c(`That device could not be revoked - it may already be gone.`),n.auth.listOwnDeviceCredentials.invalidate()},onError:e=>c(`Revoke failed: ${e.message}`)}),u=i(()=>(r.data??[]).map(e=>ve(e,Ie)),[r.data]),d=async n=>{await t({title:e(`certificates.myDevicesSection.revoke`,`Revoke "{{name}}"?`,{name:n.name}),message:e(`certificates.myDevicesSection.theDeviceStopsSigningIn`,`The device stops signing in at once and its open sessions end. To use it again you have to pair it anew. This cannot be undone.`),confirmLabel:e(`certificates.myDevicesSection.revoke2`,`Revoke`),variant:`danger`})&&(c(null),l.mutate({id:n.id}))},f={label:e(`certificates.myDevicesSection.revoke2`,`Revoke`),icon:g,isAvailable:he,onRun:e=>void d(e),busyId:l.isPending?l.variables?.id??null:null,disabled:l.isPending};return a(pe,{id:`my-devices`,title:e(`certificates.myDevicesSection.myDevices`,`My devices`),icon:_,description:e(`certificates.myDevicesSection.phonesThatStaySignedIn`,`Phones that stay signed in to your account with a certificate. If one is lost, revoke it here and it is signed out at once.`),notice:_e(o),onDismissNotice:()=>c(null),children:a(me,{rows:u,label:e(`certificates.devicesCard.label`),isLoading:r.isPending,loadError:r.error===null?null:r.error.message||`Request failed`,emptyText:`No devices are signed in with a certificate.`,hideOwner:!0,expiresNone:`—`,action:f})})}var $={profile:`profile`,signIn:`sign-in`,sessions:`sessions`,tokens:`tokens`},Re=[`linked`,`linkError`],ze={view:{icon:h,cls:`bg-foreground-subtle/15 text-foreground-subtle`},create:{icon:m,cls:`bg-primary/15 text-primary`},delete:{icon:f,cls:`bg-danger/15 text-danger`}};function Be(){let{t:e}=R(),{user:t,logout:r}=B(),[i]=H(),o=e(`system.myAccess`,`My access`);if(!t)return a(fe,{icon:T,title:o,children:a(`div`,{className:`text-xs text-foreground-subtle`,children:e(`systemPage.myAccess.notSignedIn`,`Not signed in.`)})});if(Re.some(e=>i.has(e))&&!i.has(`tab`)){let e=new URLSearchParams(i);return e.set(`tab`,$.signIn),a(V,{to:`?${e.toString()}`,replace:!0})}return a(de,{icon:T,title:o,subtitle:e(`systemPage.myAccess.subtitle`,`Your account, how you sign in, where you are signed in, and your tokens.`),sectionsLabel:e(`systemPage.myAccess.sectionsLabel`,`My access sections`),defaultSection:$.profile,actions:n(L,{variant:`outline`,onClick:r,children:[a(M,{className:`h-3 w-3`}),e(`systemPage.myAccess.signOut`,`Sign out`)]}),sections:[{id:$.profile,label:e(`systemPage.myAccess.sections.profile`,`Profile`),content:a(Ve,{user:t})},{id:$.signIn,label:e(`systemPage.myAccess.sections.signIn`,`Sign-in & security`),content:n(`div`,{className:`space-y-4`,children:[a(Me,{}),a(Ne,{username:t.username}),a(Pe,{}),a(Ae,{})]})},{id:$.sessions,label:e(`systemPage.myAccess.sections.sessions`,`Sessions & devices`),content:n(`div`,{className:`space-y-4`,children:[a(Fe,{}),a(Le,{}),a(De,{})]})},{id:$.tokens,label:e(`systemPage.myAccess.sections.tokens`,`Tokens`),content:a(ge,{ownOnly:!0})}]})}function Ve({user:e}){let{t}=R(),r=e.isAdmin,i=e.scopes??[];return n(`div`,{className:`space-y-4`,children:[n(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3 flex items-center gap-3`,children:[a(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-full bg-primary/10 text-primary font-semibold text-base`,children:e.username.slice(0,1).toUpperCase()}),n(`div`,{className:`flex-1 min-w-0`,children:[a(`div`,{className:`text-sm font-semibold text-foreground truncate`,children:e.username}),n(`div`,{className:`text-[11px] text-foreground-subtle`,children:[r?t(`systemPage.myAccess.administrator`,`Administrator`):t(`systemPage.myAccess.user`,`User`),` `,a(U,{i18nKey:`systemPage.myAccess.sessionId`,values:{id:e.id.slice(0,8)},components:{mono:a(`span`,{className:`font-mono`})}})]})]})]}),r&&n(`div`,{className:`rounded-lg border border-primary/30 bg-primary/5 px-4 py-3 text-xs text-foreground flex items-start gap-2.5`,children:[a(y,{className:`h-4 w-4 text-primary mt-0.5 shrink-0`}),n(`div`,{children:[a(`div`,{className:`font-semibold text-foreground`,children:t(`systemPage.myAccess.unrestrictedAccess`,`Unrestricted access`)}),a(`p`,{className:`text-foreground-subtle mt-0.5`,children:t(`systemPage.myAccess.adminSessionsBypassThePer`,`Admin sessions bypass the per-call scope check. Every protected endpoint is reachable regardless of the list below.`)})]})]}),i.length>0&&a(He,{scopes:i})]})}function He({scopes:e}){let{t}=R(),r=w();return n(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[n(`div`,{className:`px-4 py-2 border-b border-border`,children:[a(`div`,{className:`text-xs font-semibold text-foreground`,children:t(`systemPage.myAccess.grantedScopes`,`Granted scopes`)}),a(`div`,{className:`text-[10px] text-foreground-subtle`,children:t(`systemPage.myAccess.bakedIntoYourSessionToken`,`Baked into your session token at login; sign out + back in to refresh after changes.`)})]}),n(`div`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[a(`div`,{children:t(`systemPage.myAccess.type`,`Type`)}),a(`div`,{children:t(`systemPage.myAccess.target`,`Target`)}),a(`div`,{children:t(`systemPage.myAccess.access`,`Access`)})]}),a(`ul`,{className:`divide-y divide-border`,children:e.map((e,i)=>n(`li`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2.5 items-center text-xs`,children:[a(`span`,{className:`font-mono text-foreground-subtle`,children:e.type}),a(`span`,{className:`font-mono text-foreground`,children:e.type===`device`?ne(e.selector,r):e.target}),a(`div`,{className:`flex items-center gap-1`,children:[`view`,`create`,`delete`].map(r=>{let i=e.access.includes(r),{icon:o,cls:s}=ze[r];return n(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${i?s:`bg-transparent text-foreground-subtle/40 line-through`}`,title:i?t(`systemPage.myAccess.can`,`Can {{a}}`,{a:r}):t(`systemPage.myAccess.cannot`,`Cannot {{a}}`,{a:r}),children:[a(o,{className:`h-3 w-3`}),r]},r)})})]},i))})]})}export{Be as MyAccessPage};
@@ -1 +0,0 @@
1
- import{C as e,K as t,R as n,S as r,V as i,Y as a,et as o,o as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{D as l,En as u,Fn as d,Gn as f,Ht as p,In as m,Kr as h,L as g,Oi as _,Tn as v,Z as y,_n as b,bt as x,dt as S,fn as C,fr as w,gt as T,lr as ee,ri as E,rn as te,tn as D,xn as ne,zt as O}from"./player-overlays-B4lehTI4.js";import{Ur as re,Wr as ie,ar as k,zr as ae}from"./client-C6c46gRD.js";import{t as A}from"./boxes-DTEgIla8.js";import{l as j,s as oe}from"./video-B-2RwuDj.js";import{t as se}from"./log-in-DtNu6ihw.js";import{$s as ce,Do as le,Fi as M,Gs as ue,Js as de,Pi as N,Sn as fe,Tr as pe,Un as me,Us as he,Ws as ge,Xs as _e,Yr as P,Zs as ve,_n as ye,ac as be,bn as xe,br as Se,cc as Ce,dd as we,ec as Te,fc as Ee,gd as De,lc as Oe,mc as ke,oc as Ae,pc as je,qu as Me,ri as F,sc as Ne,yn as Pe}from"./src-DlnTixq9.js";import{t as I}from"./i18n-uD14huY2.js";import{t as L}from"./useTranslation-BJr-n0es.js";import"./mount-DuRGlFHX.js";import{S as Fe,a as R,dr as Ie,fr as Le,gr as Re,i as z}from"./index-pzq9LOji.js";import{t as ze}from"./AdminSectionedPage-OHmEcMxM.js";import{t as B}from"./AdminPage-Bn1s1Zyw.js";import{t as Be}from"./NodeAddonsSettingsPanel-DEdzDp8P.js";import{n as V,r as H,t as U}from"./IntegrationHub-DXhDIgkG.js";import{n as W,t as G}from"./addon-display-names-BkwMrExv.js";o();var K=5e3,q=`network-access`,Ve={connected:!1,endpoint:null};function He(){let{t:e}=L(),n=s(),i=M({capName:`network-access`},{refetchInterval:K}),o=N(void 0,{refetchInterval:K}),c=t(()=>G(o.data??[]),[o.data]),l=t(()=>(i.data??[]).map(e=>({addonId:e.addonId,displayName:c.get(e.addonId)??e.addonId,isActive:e.isActive})),[i.data,c]),[u,d]=a(null),[f,p]=a({}),m=(e,t)=>{let r=t?.addonId;n.invalidateQueries({queryKey:[[`networkAccess`,`getStatus`],{input:{addonId:r},type:`query`}]}),d(null),p(e=>{if(r===void 0||!(r in e))return e;let t={...e};return delete t[r],t})},h=(e,t)=>{d(null);let n=t?.addonId;if(n===void 0)return;let r=e instanceof Error?e.message:String(e);p(e=>({...e,[n]:r}))},g=je({onSuccess:m,onError:h}),_=ke({onSuccess:m,onError:h}),v=[{id:q,label:e(`system.remoteAccess.remoteAccess`,`Remote access`),install:{capability:q,label:e(`system.remoteAccess.addTunnel`,`Add tunnel`)},entries:l.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:j,...W(e.isActive),render:()=>r(V,{addonId:e.addonId,displayName:e.displayName,capName:q,isActive:e.isActive,badges:r(We,{addonId:e.addonId}),error:f[e.addonId]??null,primaryAction:r(Ge,{addonId:e.addonId,busyId:u,onStart:e=>{d(e),g.mutate({addonId:e})},onStop:e=>{d(e),_.mutate({addonId:e})}})})}))}];return r(U,{embedded:!0,icon:j,title:e(`system.remoteAccess.remoteAccess2`,`Remote Access`),subtitle:e(`system.remoteAccess.publicFacingTunnelsThatExpose`,`Public-facing tunnels that expose this hub to the internet (Cloudflare Tunnel, ngrok, …).`),groups:v,isLoading:i.isLoading,emptyTitle:e(`system.remoteAccess.noRemoteAccessProvidersInstalled`,`No remote-access providers installed`),emptyDescription:e(`system.remoteAccess.installATunnelAddonE`,`Install a tunnel addon (e.g. @camstack/addon-cloudflare) to expose this hub publicly.`)})}function Ue(e){let{data:t}=Ee({addonId:e},{refetchInterval:K,retry:!1}),n=t?ae.safeParse(t):null;return n?.success?n.data:Ve}function We({addonId:t}){let{t:n}=L(),i=Ue(t);return e(c,{children:[r(F,{variant:i.connected?`success`:`default`,className:H,children:i.connected?n(`system.remoteAccess.connected`,`Connected`):n(`system.remoteAccess.disconnected`,`Disconnected`)}),i.endpoint&&e(`a`,{href:i.endpoint.url,target:`_blank`,rel:`noopener noreferrer`,className:`flex min-w-0 items-center gap-1 break-all text-[11px] text-success hover:underline`,children:[r(h,{className:`h-3 w-3`}),i.endpoint.url]})]})}function Ge({addonId:t,busyId:n,onStart:i,onStop:a}){let{t:o}=L(),s=Ue(t),c=n===t;return s.connected?e(P,{size:`sm`,variant:`secondary`,disabled:c,onClick:()=>a(t),children:[c?r(w,{className:`h-3 w-3 animate-spin`}):r(D,{className:`h-3 w-3`}),o(`system.remoteAccess.stop`,`Stop`)]}):e(P,{size:`sm`,variant:`primary`,disabled:c,onClick:()=>i(t),children:[c?r(w,{className:`h-3 w-3 animate-spin`}):r(m,{className:`h-3 w-3`}),o(`system.remoteAccess.start`,`Start`)]})}o();var Ke=3e4,J=`turn-provider`;function qe(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function Je(){let{t:n}=L(),i=M({capName:`turn-provider`},{refetchInterval:Ke}),a=N(void 0,{refetchInterval:Ke}),o=Me(),s=o.data??[],c=t(()=>G(a.data??[]),[a.data]),u=t(()=>(i.data??[]).map(e=>({addonId:e.addonId,displayName:c.get(e.addonId)??e.addonId,isActive:e.isActive})),[i.data,c]),d=[{id:J,label:n(`system.turnServers.turnProviders`,`TURN providers`),install:{capability:J,label:n(`system.turnServers.addProvider`,`Add provider`)},entries:u.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:f,...W(e.isActive),render:()=>r(V,{addonId:e.addonId,displayName:e.displayName,capName:J,isActive:e.isActive,panels:[{id:`ice-servers`,title:n(`system.turnServers.discoveredIceServers`,`Discovered ICE servers`),icon:f,content:r(Ye,{addonId:e.addonId,enabled:e.isActive})}]})}))}];return r(U,{embedded:!0,icon:f,title:n(`system.turnServers.turnServers`,`TURN Servers`),subtitle:n(`system.turnServers.iceServersUsedForWebrtc`,`ICE servers used for WebRTC NAT traversal. Multiple providers can coexist — the WebRTC layer concatenates servers from all enabled providers per session.`),groups:d,isLoading:i.isLoading,emptyTitle:n(`system.turnServers.noTurnProvidersInstalled`,`No TURN providers installed`),emptyDescription:n(`system.turnServers.installATurnAddonE`,`Install a TURN addon (e.g. @camstack/addon-cloudflare) to enable WebRTC behind restrictive NATs.`),trailing:r(xe,{headingId:`turn-combined-ice`,title:n(`system.turnServers.combinedIceServerListAll`,`Combined ICE server list — all enabled providers`),icon:f,actions:r(P,{size:`sm`,variant:`secondary`,onClick:()=>o.refetch(),disabled:o.isFetching,children:n(`common.refresh`,`Refresh`)}),children:r(`div`,{className:l,children:s.length===0?r(`div`,{className:`text-xs text-foreground-subtle`,children:n(`system.turnServers.noServersFromEnabledProviders`,`No servers from enabled providers.`)}):r(`div`,{className:`flex flex-col gap-3`,children:s.map((t,n)=>{let i=Array.isArray(t.urls)?t.urls:[t.urls];return e(`div`,{className:`rounded border border-border bg-surface`,children:[(t.username||t.credential)&&e(`div`,{className:`px-3 py-1.5 border-b border-border text-[10px] font-mono text-foreground-subtle flex items-center gap-3`,children:[t.username&&e(`span`,{children:[r(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,r(`span`,{className:`text-foreground`,children:t.username})]}),t.credential&&e(`span`,{children:[r(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,r(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),r(`ul`,{className:`divide-y divide-border`,children:i.map(e=>r(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},n)})})})})})}function Ye({addonId:e,enabled:n}){let i=Me({addonId:e},{enabled:n,retry:!1}),a=t(()=>qe(i.data??[]),[i.data]),o=n?i.isLoading?`Loading…`:a.length===0?`This provider returned no servers.`:null:`Disabled — enable the provider to fetch its servers.`;return r(`div`,{className:`rounded-lg border border-border bg-surface p-2 sm:p-3`,children:o===null?r(`div`,{className:`flex flex-wrap gap-1`,children:a.map(e=>r(`span`,{className:`inline-block break-all rounded bg-foreground-subtle/10 px-1.5 py-0.5 font-mono text-[10px] text-foreground`,children:e},e))}):r(`div`,{className:`text-xs text-foreground-subtle`,children:o})})}o();var Xe={lan:f,wifi:x,docker:A,vpn:ee,loopback:b,other:b},Ze={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},Qe=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function $e(n){let{t:i}=L(),{interfaces:a,disabled:o,hideLoopback:s,ipv4Only:c,emptyMessage:l}=n,u=t(()=>a.filter(e=>!(s&&e.kind===`loopback`||c&&e.family!==`IPv4`)),[a,s,c]),d=t(()=>{let e=new Map;for(let t of u){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return Qe.filter(t=>e.has(t)).map(t=>({kind:t,items:e.get(t)}))},[u]),f=e=>n.mode===`single`?n.value===e:n.value.includes(e),p=e=>{if(o||e.kind===`loopback`)return;if(n.mode===`single`){n.onChange(n.value===e.address?null:e.address);return}let t=new Set(n.value);t.has(e.address)?t.delete(e.address):t.add(e.address),n.onChange([...t])};return u.length===0?r(`div`,{className:`text-xs text-foreground-subtle italic`,children:l??i(`shared.addressSelector.noAddressesAvailable`,`No addresses available.`)}):r(`div`,{className:`flex flex-col gap-3`,children:d.map(({kind:t,items:a})=>e(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[e(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[r(Xe[t]??b,{className:`h-3.5 w-3.5 text-foreground-subtle`}),r(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:Ze[t]??t}),e(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,a.length]})]}),r(`ul`,{className:`divide-y divide-border`,children:a.map(t=>{let a=f(t.address),s=t.kind===`loopback`,c=!t.plausible&&!s;return e(`li`,{className:`flex items-center gap-3 px-3 py-2 ${s?`opacity-60 cursor-not-allowed`:o?`opacity-60`:c?`cursor-pointer hover:bg-surface-hover/30 bg-amber-500/[0.04]`:`cursor-pointer hover:bg-surface-hover/30`}`,onClick:()=>p(t),children:[r(`span`,{className:`flex items-center justify-center h-4 w-4 rounded ${n.mode===`single`?`rounded-full`:`rounded`} border ${a?`border-primary bg-primary text-primary-foreground`:`border-border bg-surface`}`,children:a&&r(_,{className:`h-3 w-3`})}),e(`div`,{className:`flex-1 min-w-0 ${c?`text-foreground-subtle`:``}`,children:[e(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[r(`span`,{className:`font-mono text-xs font-semibold ${c?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),r(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-mono`,children:t.family}),t.preferred&&r(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:i(`shared.addressSelector.autoPreferred`,`Auto-preferred`)}),s&&r(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:i(`shared.addressSelector.alwaysIncluded`,`Always included`)}),c&&e(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:t.plausibleReason||void 0,children:[r(O,{className:`h-2.5 w-2.5`}),i(`shared.addressSelector.unlikelyUsable`,`Unlikely usable`)]})]}),e(`div`,{className:`text-xs text-foreground-subtle mt-0.5 font-mono break-all`,children:[t.address,t.cidr&&t.cidr!==t.address?` (${t.cidr})`:``]})]})]},`${t.name}-${t.family}-${t.address}`)})})]},t))})}var Y=[{role:`appConnections`,get title(){return I.t(`helpers.addressTableModel.appConnectionsTitle`)},single:!1,get help(){return I.t(`helpers.addressTableModel.appConnectionsHelp`)}},{role:`notificationTaps`,get title(){return I.t(`helpers.addressTableModel.notificationTapsTitle`)},single:!0,get help(){return I.t(`helpers.addressTableModel.notificationTapsHelp`)}},{role:`publicEndpoint`,get title(){return I.t(`helpers.addressTableModel.publicEndpointTitle`)},single:!0,get help(){return I.t(`helpers.addressTableModel.publicEndpointHelp`)}},{role:`internal`,get title(){return I.t(`helpers.addressTableModel.internalTitle`)},single:!0,get help(){return I.t(`helpers.addressTableModel.internalHelp`)}}],et=`A role with nothing ticked is automatic. Add a custom address when the hub is reached at an address it cannot see itself (NAT, reverse proxy, VPN, Docker bridge).`;function X(e,t){return e.inUse.includes(t)}function tt(e,t){if(!e.eligible.includes(t))return{kind:`none`};if(e.kind===`app-link`)return X(e,t)?{kind:`none`}:{kind:`set`,input:{role:t,baseUrl:null,enabled:!0}};if(e.flags.includes(t)||t===`appConnections`&&X(e,t))return{kind:`set`,input:{role:t,baseUrl:e.baseUrl,enabled:!1}};let n={role:t,baseUrl:e.baseUrl,enabled:!0};return t===`publicEndpoint`&&e.baseUrl.startsWith(`http:`)?{kind:`confirm-http`,input:n,reason:re}:{kind:`set`,input:n}}function nt(e){return Y.map(({role:t,title:n})=>{if(t===`appConnections`){let r=e.roles.appConnections;return{role:t,title:n,inUse:r.resolved.length===0?`nothing reachable`:r.resolved.join(`, `),automatic:r.source!==`flagged`}}let r=e.roles[t];return{role:t,title:n,inUse:r.resolved===null?`nothing reachable`:t===`notificationTaps`&&r.source===`auto`?`CamStack app link`:r.resolved,automatic:r.source!==`flagged`}})}o();var rt={"lan-ipv4":{labelKey:`system.addressesCard.kindIpv4`,className:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`},"lan-ipv6":{labelKey:`system.addressesCard.kindIpv6`,className:`bg-violet-500/15 text-violet-700 dark:text-violet-300`},public:{labelKey:`system.addressesCard.kindPublic`,className:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},"app-link":{labelKey:`system.addressesCard.kindAppLink`,className:`bg-amber-500/15 text-amber-700 dark:text-amber-300`},custom:{labelKey:`system.addressesCard.kindCustom`,className:`bg-sky-500/15 text-sky-700 dark:text-sky-300`},loopback:{labelKey:`system.addressesCard.kindLoopback`,className:`bg-foreground-subtle/15 text-foreground-subtle`}};function it({book:t,loading:n,saving:i,error:o,onSetRole:s,onAdd:c,onRemove:l}){let{t:u}=L(),[f,m]=a(``),[h,g]=a(``),[_,v]=a(null),[y,b]=a(null),x=()=>{let e=ie(f);if(!e.ok){v(e.reason);return}v(null),m(``),g(``),c(e.baseUrl,h.trim())},S=(e,t)=>{let n=tt(e,t.role);if(n.kind!==`none`){if(n.kind===`confirm-http`){b({input:n.input,reason:n.reason});return}b(null),s(n.input)}},C=[{key:`url`,header:u(`system.addressesCard.address`,`Address`),render:n=>e(`div`,{className:`min-w-0 py-0.5`,children:[r(`div`,{className:`font-mono text-[12px] break-all ${n.plausible?`text-foreground`:`text-foreground-subtle`}`,children:n.baseUrl}),e(`div`,{className:`mt-0.5 flex flex-wrap items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[r(`span`,{children:n.label}),n.kind===`app-link`&&e(`span`,{className:`font-mono`,children:[`hub=`,` `,t?.appLinkHub??u(`system.addressesCard.noneNoTunnelOrTailscale`,`none (no tunnel or Tailscale)`)]}),n.custom&&n.detected&&r(`span`,{children:u(`system.addressesCard.alsoAddedAsACustom`,`also added as a custom address`)}),n.kind!==`custom`&&n.interfaceKind!==`lan`&&n.interfaceKind!==`public`&&n.interfaceKind!==`other`&&r(`span`,{className:`uppercase tracking-wide`,children:n.interfaceKind}),!n.plausible&&n.interfaceKind!==`loopback`&&e(`span`,{className:`inline-flex items-center gap-1 text-amber-700 dark:text-amber-300`,title:n.plausibleReason||void 0,children:[r(O,{className:`h-2.5 w-2.5`}),u(`system.addressesCard.unlikelyUsable`,`Unlikely usable`)]})]})]})},{key:`kind`,header:u(`system.addressesCard.kind`,`Kind`),nowrap:!0,render:e=>{let t=rt[e.kind]??rt.loopback;return r(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.className}`,children:u(t.labelKey)})}},...Y.map(t=>({key:t.role,headerRender:()=>r(`span`,{title:t.help,children:t.title}),align:`center`,nowrap:!0,width:`w-24`,render:n=>{let a=n.eligible.includes(t.role),o=n.flags.includes(t.role),s=X(n,t.role);return e(`label`,{className:`inline-flex items-center justify-center gap-1 ${a?`cursor-pointer`:`cursor-not-allowed opacity-40`}`,title:a?s&&!o?u(`system.addressesCard.inUseAutomatically`,`{{title}}: in use automatically. {{help}}`,{title:t.title,help:t.help}):t.help:u(`system.addressesCard.thisAddressCannotBeUsed`,`This address cannot be used for this.`),children:[r(me,{checked:a&&s,disabled:!a||i,onChange:()=>S(n,t),"aria-label":`${t.title}: ${n.baseUrl}`}),s&&!o&&a&&r(`span`,{className:`text-[9px] text-foreground-subtle`,children:u(`common.auto`)})]})}})),{key:`actions`,header:``,align:`right`,nowrap:!0,render:e=>e.custom?r(P,{size:`sm`,variant:`ghost`,disabled:i,onClick:()=>l(e.baseUrl),"aria-label":u(`system.addressesCard.remove`,`Remove {{baseUrl}}`,{baseUrl:e.baseUrl}),title:u(`system.addressesCard.removeThisCustomAddressIts`,`Remove this custom address (its roles turn automatic)`),children:r(p,{className:`h-3 w-3`})}):null}],w=t===void 0?[]:nt(t);return e(Se,{children:[e(`div`,{className:`px-4 py-3 border-b border-border flex flex-col gap-2`,children:[e(`div`,{children:[r(`div`,{className:`text-sm font-semibold`,children:u(`system.addressesCard.addresses`,`Addresses`)}),r(`div`,{className:`text-xs text-foreground-subtle max-w-3xl`,children:u(`system.addressesCard.everyAddressThisHubIs`,`Every address this hub is reached at, detected or added by you. Tick what each one is used for.`)}),e(`details`,{className:`mt-1.5 text-xs max-w-3xl`,"data-testid":`address-roles-help`,children:[r(`summary`,{className:`cursor-pointer select-none text-foreground-subtle hover:text-foreground`,children:u(`system.addressesCard.whatAreRoles`,`What are roles?`)}),r(`dl`,{className:`mt-1.5 grid grid-cols-[auto_1fr] gap-x-3 gap-y-1`,children:Y.map(t=>e(`div`,{className:`contents`,children:[r(`dt`,{className:`font-medium`,children:t.title}),r(`dd`,{className:`text-foreground-subtle`,children:t.help})]},t.role))}),r(`p`,{className:`mt-1.5 text-foreground-subtle`,children:et})]})]}),w.length>0&&r(`div`,{className:`grid grid-cols-[auto_1fr_auto] gap-x-3 gap-y-1 items-baseline text-xs`,"data-testid":`address-roles-summary`,children:w.map(t=>e(`div`,{className:`contents`,children:[r(`span`,{className:`text-foreground-subtle`,children:t.title}),e(`span`,{className:`font-mono break-all`,"data-testid":`address-role-${t.role}`,children:[t.inUse,r(`span`,{className:`ml-1.5 font-sans text-foreground-subtle`,children:t.automatic?u(`system.addressesCard.automatic`,`(automatic)`):u(`system.addressesCard.setByYou`,`(set by you)`)})]}),t.automatic?r(`span`,{}):r(P,{size:`sm`,variant:`secondary`,disabled:i,onClick:()=>s({role:t.role,baseUrl:null,enabled:!1}),children:u(`system.addressesCard.useAutomatic`,`Use automatic`)})]},t.role))}),y!==null&&e(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-xs flex flex-wrap items-center gap-2`,children:[r(O,{className:`h-3.5 w-3.5 text-amber-600`}),r(`span`,{className:`flex-1 min-w-[220px]`,children:y.reason}),r(P,{size:`sm`,variant:`secondary`,onClick:()=>{s({...y.input,acceptInsecureHttp:!0}),b(null)},children:u(`system.addressesCard.useHttpAnyway`,`Use http anyway`)}),r(P,{size:`sm`,variant:`ghost`,onClick:()=>b(null),children:u(`common.cancel`,`Cancel`)})]}),o!==null&&r(`div`,{className:`text-[11px] text-red-600 dark:text-red-400`,role:`alert`,children:o})]}),r(fe,{columns:C,rows:t?.rows??[],rowKey:e=>`${e.kind}-${e.baseUrl}`,minWidthPx:760,bordered:!1,emptyMessage:n?u(`common.loading`,`Loading…`):u(`system.addressesCard.noAddressesAvailable`,`No addresses available.`),rowClassName:e=>e.plausible?void 0:`opacity-80`}),e(`div`,{className:`px-4 py-3 border-t border-border flex flex-wrap items-start gap-2`,children:[e(`div`,{className:`flex-1 min-w-[220px]`,children:[r(De,{value:f,onChange:e=>{m(e.target.value),v(null)},placeholder:`https://cams.example.com or https://192.0.2.20:4443`,"aria-label":u(`system.addressesCard.customAddress`,`Custom address`),disabled:i}),_!==null&&r(`div`,{className:`mt-1 text-[11px] text-red-600 dark:text-red-400`,children:_})]}),r(`div`,{className:`w-48`,children:r(De,{value:h,onChange:e=>g(e.target.value),placeholder:u(`system.addressesCard.labelOptional`,`Label (optional)`),"aria-label":u(`system.addressesCard.customAddressLabel`,`Custom address label`),maxLength:80,disabled:i})}),e(P,{size:`sm`,variant:`secondary`,disabled:i||f.trim()===``,onClick:x,children:[r(d,{className:`h-3 w-3`}),u(`system.addressesCard.addCustomAddress`,`Add custom address`)]})]})]})}o();function at(){let{t:n}=L(),o=s(),c=()=>{o.invalidateQueries({queryKey:[[`localNetwork`]]})},d=de(void 0,{refetchInterval:3e4}),f=ue(void 0),p=Te({onSuccess:c}),m=ve({onSuccess:e=>{w(e.addresses),c()}}),h=t(()=>d.data?.interfaces??[],[d.data]),g=ge({scheme:typeof window<`u`&&window.location.protocol===`https:`?`https`:`http`},{refetchInterval:3e4}),_=ce({onSuccess:c}),y=he({onSuccess:c}),b=_e({onSuccess:c}),x=_.error?.message??y.error?.message??b.error?.message??null,S=_.isPending||y.isPending||b.isPending,[C,w]=a([]),[T,ee]=a(!1);i(()=>{!T&&f.data&&(w(f.data.addresses),ee(!0))},[f.data,T]);let E=f.data?.addresses??[],D=t(()=>{if(C.length!==E.length)return!0;let e=[...C].toSorted(),t=[...E].toSorted();return e.some((e,n)=>e!==t[n])},[C,E]);return e(B,{embedded:!0,children:[e(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[r(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:n(`system.networkAddresses.pinWhichHostInterfacesExist`,`Pin which host interfaces exist, then tick what each address is used for. Add a custom address when this hub is reached at one it cannot detect.`)}),r(`div`,{className:`flex items-center gap-2 shrink-0`,children:e(P,{size:`sm`,variant:`secondary`,onClick:()=>{d.refetch(),f.refetch(),g.refetch()},disabled:d.isLoading,children:[r(u,{className:`h-3 w-3 ${d.isLoading?`animate-spin`:``}`}),n(`common.refresh`,`Refresh`)]})})]}),r(xe,{headingId:`network-allowed-addresses`,title:n(`system.networkAddresses.allowedAddresses`,`Allowed addresses`),actions:e(`div`,{className:`flex flex-wrap items-center gap-1`,children:[e(P,{size:`sm`,variant:`secondary`,onClick:()=>m.mutate(void 0),disabled:m.isPending||p.isPending,title:n(`system.networkAddresses.reRunTheAutoDetection`,`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`),children:[r(te,{className:`h-3 w-3`}),m.isPending?n(`system.networkAddresses.detecting`,`Detecting…`):n(`system.networkAddresses.bestMatch`,`Best match`)]}),e(P,{size:`sm`,variant:`secondary`,onClick:()=>{w([])},disabled:C.length===0||p.isPending,children:[r(v,{className:`h-3 w-3`}),n(`system.networkAddresses.clear`,`Clear`)]}),D&&r(P,{size:`sm`,variant:`secondary`,onClick:()=>{w(E)},disabled:p.isPending,children:n(`system.networkAddresses.discard`,`Discard`)}),e(P,{size:`sm`,variant:`primary`,onClick:()=>{p.mutate({addresses:[...C]})},disabled:!D||p.isPending,children:[r(ne,{className:`h-3 w-3`}),p.isPending?n(`system.networkAddresses.saving`,`Saving…`):n(`common.save`,`Save`)]})]}),children:e(`div`,{className:l,children:[r(`p`,{className:`mb-3 text-xs text-foreground-subtle`,children:C.length===0?n(`system.networkAddresses.autoEveryNonLoopbackNon`,`Auto — every non-loopback / non-link-local interface participates.`):n(`system.networkAddresses.pinned`,`{{value1}} pinned`,{value1:String(C.length)})}),r($e,{mode:`multiple`,interfaces:h,value:C,onChange:w,disabled:p.isPending,emptyMessage:d.isLoading?n(`system.networkAddresses.loadingInterfaces`,`Loading interfaces…`):n(`system.networkAddresses.noInterfacesDetected`,`No interfaces detected.`)})]})}),r(it,{book:g.data,loading:g.isLoading,saving:S,error:x,onSetRole:e=>_.mutate({...e}),onAdd:(e,t)=>y.mutate({baseUrl:e,label:t}),onRemove:e=>b.mutate({baseUrl:e})})]})}o();var ot={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},Z=5e3,Q=`mesh-network`,st=3e4,ct={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function lt(){let{t:e}=L(),n=M({capName:`mesh-network`},{refetchInterval:Z}),i=N(void 0,{refetchInterval:Z}),a=t(()=>G(i.data??[]),[i.data]),o=t(()=>(n.data??[]).map(e=>({addonId:e.addonId,displayName:a.get(e.addonId)??e.addonId,isActive:e.isActive})),[n.data,a]),s=[{id:Q,label:e(`system.meshNetworks.meshNetworks`,`Mesh networks`),install:{capability:Q,label:e(`system.meshNetworks.addMesh`,`Add mesh`)},entries:o.map(t=>({id:t.addonId,name:t.displayName,fallbackIcon:f,...W(t.isActive),render:()=>r(V,{addonId:t.addonId,displayName:t.displayName,capName:Q,isActive:t.isActive,badges:r(ut,{addonId:t.addonId}),primaryAction:r(dt,{addonId:t.addonId}),panels:[{id:`status`,title:e(`system.meshNetworks.status`,`Status`),icon:A,content:r(ft,{addonId:t.addonId})}]})}))}];return r(U,{embedded:!0,icon:A,title:e(`system.meshNetworks.meshNetworks2`,`Mesh Networks`),subtitle:e(`system.meshNetworks.privateVpnMeshesThatConnect`,`Private VPN meshes that connect CamStack to your other devices (Tailscale, Headscale, …). Each provider can also expose this hub publicly via its ingress (Tailscale Funnel).`),groups:s,isLoading:n.isLoading,emptyTitle:e(`system.meshNetworks.noMeshNetworkProvidersInstalled`,`No mesh-network providers installed`),emptyDescription:e(`system.meshNetworks.installAMeshAddonE`,`Install a mesh addon (e.g. @camstack/addon-tailscale) to join this hub into a private VPN mesh.`)})}function $(e){let{data:t,isLoading:n}=be({addonId:e},{refetchInterval:Z,retry:!1}),r=t?k.safeParse(t):null;return{status:r?.success?r.data:ct,isLoading:n}}function ut({addonId:t}){let{t:n}=L(),{status:i}=$(t);return e(c,{children:[r(F,{variant:i.joined?`success`:`default`,className:H,children:i.joined?n(`system.meshNetworks.joined`,`Joined`):n(`system.meshNetworks.notJoined`,`Not joined`)}),i.joined&&r(F,{className:`text-[10px]`,children:n(`common.peers`,{count:i.peerCount})})]})}function dt({addonId:t}){let{t:i}=L(),o=s(),[l,u]=a(!1),[d,f]=a(null),p=S(),{status:m}=$(t),h=n(()=>{o.invalidateQueries({queryKey:[[`meshNetwork`]]})},[o]),g=Oe(),_=Ae({onSuccess:h}),v=Ce({onSuccess:h}),y=n(async()=>{u(!0);let e={cancelled:!1};f(e);try{let n=await g.mutateAsync({addonId:t});if(e.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!e.cancelled&&(await yt(2e3),!e.cancelled);){let e=await p.trpcClient.meshNetwork.getStatus.query({addonId:t}).catch(()=>null),n=e?k.safeParse(e):null;if(n?.success&&n.data.joined){h();break}if(Date.now()-r>6e5)break}}finally{u(!1),f(null)}},[t,h,g,p]),b=n(()=>{d&&(d.cancelled=!0),u(!1),f(null)},[d]);return r(c,{children:m.joined?e(c,{children:[e(P,{size:`sm`,variant:`secondary`,disabled:_.isPending,onClick:()=>_.mutate({addonId:t}),children:[_.isPending?r(w,{className:`h-3 w-3 animate-spin`}):r(oe,{className:`h-3 w-3`}),i(`system.meshNetworks.disconnect`,`Disconnect`)]}),e(P,{size:`sm`,variant:`ghost`,disabled:v.isPending,onClick:()=>v.mutate({addonId:t}),children:[v.isPending?r(w,{className:`h-3 w-3 animate-spin`}):r(C,{className:`h-3 w-3`}),i(`system.meshNetworks.logOut`,`Log out`)]})]}):l?e(P,{size:`sm`,variant:`ghost`,onClick:b,children:[r(T,{className:`h-3 w-3 mr-1`}),` `,i(`common.cancel`)]}):e(c,{children:[e(P,{size:`sm`,variant:`primary`,onClick:()=>void y(),children:[r(se,{className:`h-3 w-3`}),i(`system.meshNetworks.connect`,`Connect`)]}),e(P,{size:`sm`,variant:`ghost`,disabled:v.isPending,onClick:()=>v.mutate({addonId:t}),children:[v.isPending?r(w,{className:`h-3 w-3 animate-spin`}):r(C,{className:`h-3 w-3`}),i(`system.meshNetworks.logOut`,`Log out`)]})]})})}function ft({addonId:t}){let{t:n}=L(),{status:i}=$(t),a=Ne({addonId:t},{refetchInterval:st,retry:!1});return e(`div`,{className:`rounded-lg border border-border bg-surface`,children:[e(`div`,{className:`space-y-4 p-2 sm:p-4`,children:[i.error&&r(pe,{message:i.error}),r(pt,{status:i}),i.endpoints.length>0&&e(`div`,{className:`space-y-1.5`,children:[r(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:n(`system.meshNetworks.endpoints`,`Endpoints`)}),i.endpoints.map(t=>e(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[e(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${ot[t.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[t.scope===`public`?r(j,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,t.label]}),e(`a`,{href:t.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-emerald-700 dark:text-emerald-300 hover:underline break-all flex items-center gap-1`,children:[r(h,{className:`h-3 w-3 shrink-0`}),t.url]})]},t.id))]})]}),r(`div`,{className:`border-t border-border`,children:r(ht,{peers:a.data?.peers??[],loading:a.isLoading})})]})}function pt({status:t}){let{t:n}=L();return r(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-1.5`,children:[{label:n(`system.meshNetworks.tenant`,`Tenant`),value:t.tenantName||`—`},{label:n(`system.meshNetworks.user`,`User`),value:t.userLogin??`—`},{label:n(`system.meshNetworks.controlPlane`,`Control plane`),value:t.controlPlaneUrl||`—`},{label:n(`system.meshNetworks.meshIp`,`Mesh IP`),value:t.meshIp||`—`,mono:!0},{label:n(`system.meshNetworks.magicdns`,`MagicDNS`),value:t.magicDnsHostname||`—`,mono:!0},{label:n(`system.meshNetworks.dnsSuffix`,`DNS suffix`),value:t.magicDnsSuffix||`—`,mono:!0},{label:n(`system.meshNetworks.peers`,`Peers`),value:String(t.peerCount)},{label:n(`system.meshNetworks.keyExpiry`,`Key expiry`),value:t.keyExpiry?mt(t.keyExpiry):`—`}].map(t=>e(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[r(`span`,{className:`text-foreground-subtle shrink-0`,children:t.label}),r(`span`,{className:`text-foreground truncate ${t.mono?`font-mono`:``}`,children:t.value})]},t.label))})}function mt(e){let t=e-Date.now();if(t<0)return I.t(`system.meshNetworks.expiredAgo`,{when:vt(e)});let n=Math.floor(t/864e5);if(n>60)return new Date(e).toLocaleDateString();if(n>1)return I.t(`system.meshNetworks.expiryDays`,{count:n});let r=Math.floor(t/36e5);return r>1?I.t(`system.meshNetworks.expiryHours`,{count:r}):I.t(`system.meshNetworks.expiryMin`,{count:Math.max(1,Math.floor(t/6e4))})}function ht({peers:i,loading:a}){let{t:o}=L(),s=t(()=>i.map(e=>({...e,_id:e.id})),[i]),c=n(e=>{e&&navigator.clipboard?.writeText(e)},[]),l=t(()=>[{key:`hostname`,header:o(`system.meshNetworks.hostname`,`Hostname`),render:t=>e(`div`,{className:`flex flex-col`,children:[e(`div`,{className:`flex items-center gap-1.5`,children:[r(`span`,{className:`font-medium text-foreground`,children:t.hostname||o(`system.meshNetworks.unknown`,`(unknown)`)}),t.isSelf&&r(F,{variant:`info`,children:o(`common.self`)}),t.exitNodeOption&&r(F,{variant:`warning`,children:`exit-node`})]}),t.userLogin&&r(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:t.userLogin})]})},{key:`magicDns`,header:o(`system.meshNetworks.magicdns`,`MagicDNS`),render:t=>t.magicDns?e(`div`,{className:`flex items-center gap-1`,children:[r(`span`,{className:`font-mono text-xs truncate`,children:t.magicDns}),r(`button`,{onClick:()=>c(t.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":o(`system.meshNetworks.copyMagicdns`,`Copy MagicDNS`),children:r(E,{className:`h-3 w-3 text-foreground-subtle`})})]}):r(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:t=>{let n=t.addresses[0]??``;return n?e(`div`,{className:`flex items-center gap-1`,children:[r(`span`,{className:`font-mono text-xs`,children:n}),r(`button`,{onClick:()=>c(n),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":o(`system.meshNetworks.copyIp`,`Copy IP`),children:r(E,{className:`h-3 w-3 text-foreground-subtle`})})]}):r(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:o(`system.meshNetworks.connection`,`Connection`),render:t=>e(`div`,{className:`flex items-center gap-1.5`,children:[r(F,{variant:gt(t.connection),children:t.connection}),t.relay&&r(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:t.relay})]})},{key:`routes`,header:o(`system.meshNetworks.routes`,`Routes`),render:e=>e.advertisedRoutes.length>0?r(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):r(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:o(`system.meshNetworks.txRx`,`TX / RX`),render:t=>e(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,_t(t.txBytes),` · ↓ `,_t(t.rxBytes)]})},{key:`lastSeen`,header:o(`system.meshNetworks.lastSeen`,`Last seen`),render:e=>r(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?vt(e.lastSeenMs):`—`})}],[c,o]);return a&&i.length===0?e(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[r(w,{className:`h-3 w-3 animate-spin inline mr-1`}),` `,o(`systemPage.meshNetworks.loadingPeers`)]}):i.length===0?r(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:o(`system.meshNetworks.noPeersVisibleYourTailnet`,`No peers visible — your tailnet may be empty or the host is not joined.`)}):r(`div`,{className:`p-4`,children:r(fe,{columns:l,rows:s,rowKey:e=>e._id,minWidthPx:820})})}function gt(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function _t(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)}MB`:`${(e/1024/1024/1024).toFixed(2)}GB`}function vt(e){let t=Date.now()-e;return t<6e4?I.t(`system.meshNetworks.justNow`):t<36e5?I.t(`system.meshNetworks.agoMin`,{count:Math.round(t/6e4)}):t<864e5?I.t(`system.meshNetworks.agoHour`,{count:Math.round(t/36e5)}):I.t(`system.meshNetworks.agoDay`,{count:Math.round(t/864e5)})}function yt(e){return new Promise(t=>setTimeout(t,e))}var bt=`/system/identity?tab=certificates`;function xt(){let{t}=L();return r(B,{embedded:!0,children:e(`div`,{className:g,children:[r(Be,{nodeId:`hub`,addonIds:[`local-network`],level:`global`,title:t(`system.localAccess.lanHttp`,`LAN HTTP`),description:t(`system.localAccess.nativeAppsOnThisWi`,`Native apps on this Wi-Fi use http:// and skip the private certificate. The tunnel and this admin UI stay on HTTPS.`)}),e(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`https-certificate-hint`,children:[t(`system.localAccess.certificateMoved`,`The HTTPS certificate and the local CA are managed under`),` `,r(Ie,{className:`underline`,to:bt,children:t(`system.localAccess.certificateMovedLink`,`Identity → Certificates`)}),`.`]})]})})}o();function St({value:n,onChange:i}){let{t:a}=L(),{data:o}=le({isCamera:!0,projection:`slim`}),s=t(()=>o===void 0?[{value:``,label:a(`system.networkDiagnostics.loadingCameras`,`Loading cameras…`)}]:o.length===0?[{value:``,label:a(`system.networkDiagnostics.noCameras`,`No cameras`)}]:[{value:``,label:a(`system.networkDiagnostics.pickACamera`,`Pick a camera`)},...o.toSorted((e,t)=>e.name.localeCompare(t.name)).map(e=>({value:String(e.id),label:`${e.name} (#${String(e.id)})`}))],[o,a]);return e(`label`,{className:`flex min-w-0 flex-col gap-1`,children:[r(`span`,{className:`text-[11px] text-foreground-subtle`,children:a(`system.networkDiagnostics.camera`,`Camera`)}),r(we,{value:n===null?``:String(n),disabled:o===void 0||o.length===0,onChange:e=>i(e.target.value===``?null:Number(e.target.value)),options:s})]})}function Ct(){let t=S(),[i,o]=a(null);return r(B,{embedded:!0,children:e(`div`,{className:g,"data-testid":`network-diagnostics`,children:[r(Pe,{loadServers:n(async()=>t.trpcClient.turnProvider.getTurnServers.query(),[t])}),r(ye,{trpc:t.trpcClient,serverUrl:y(),deviceId:i,cameraField:r(St,{value:i,onChange:o})})]})})}var wt=[`certificate`,`certificates`,`https`];function Tt(){let{t:e}=L(),[t]=Re();if(wt.includes(t.get(`tab`)??``))return r(Le,{to:bt,replace:!0});let n=Fe(`/system/network`,{t:e,isAdmin:!0})??{icon:j,title:e(`system.network`,`Network`)};return r(ze,{icon:n.icon,title:n.title,defaultSection:`addresses`,sectionsLabel:`${n.title} sections`,sections:[{id:`local-access`,label:e(`systemPage.network.localAccess`,`Local access`),content:r(xt,{})},{id:`addresses`,label:e(`systemPage.network.networkAddresses`,`Network Addresses`),content:r(at,{})},{id:R.remoteAccess.tab,label:e(`systemPage.network.remoteAccess`,`Remote Access`),content:r(He,{}),ownedParams:z},{id:R.mesh.tab,label:e(`systemPage.network.meshNetworks`,`Mesh Networks`),content:r(lt,{}),ownedParams:z},{id:R.turn.tab,label:e(`systemPage.network.turnServers`,`TURN Servers`),content:r(Je,{}),ownedParams:z},{id:`diagnostics`,label:e(`systemPage.network.diagnostics`,`Diagnostics`),content:r(Ct,{})}]})}export{Tt as NetworkPage};