@camstack/addon-admin-ui 1.2.691 → 1.2.693

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 (123) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/assets/{AccessSection-D8SFhAIG.js → AccessSection-BTyH6Uq_.js} +1 -1
  3. package/dist/assets/Addons-VJhgqhzH.js +5 -0
  4. package/dist/assets/{AdminPage-Dr8PsIuX.js → AdminPage-DHZrZAII.js} +1 -1
  5. package/dist/assets/{AdminSectionedPage-C3NbPIMK.js → AdminSectionedPage-3Jh0qbF0.js} +1 -1
  6. package/dist/assets/AiProfiles-Dle37tWQ.js +3 -0
  7. package/dist/assets/Archive-SdeDPpcj.js +1 -0
  8. package/dist/assets/{BootstrapSettingsForm-EahE9xrT.js → BootstrapSettingsForm-DhCX-aLg.js} +1 -1
  9. package/dist/assets/Build-DY6Kzxeg.js +40 -0
  10. package/dist/assets/{Calendars-DqxqjWNj.js → Calendars-C8ofmzzq.js} +1 -1
  11. package/dist/assets/Cluster-JhBKuQrD.js +1 -0
  12. package/dist/assets/CompositionBlockEditor-Br6RqkCB.js +2 -0
  13. package/dist/assets/CompositionEditorPage-15ZoqacB.js +1 -0
  14. package/dist/assets/Data-B5ocdjeC.js +2 -0
  15. package/dist/assets/DeviceDetail-CFZv3c_f.js +1 -0
  16. package/dist/assets/{Devices-PRxhQLdr.js → Devices-WxmPKN4U.js} +1 -1
  17. package/dist/assets/{EmbedDevicePage-cBOLQorO.js → EmbedDevicePage-8R3q6IQn.js} +1 -1
  18. package/dist/assets/{EmbedPlayerPage-DSZTQL2b.js → EmbedPlayerPage-GnCekJoU.js} +1 -1
  19. package/dist/assets/History-BtkXJRVt.js +1 -0
  20. package/dist/assets/Identity-BCgp4vmD.js +1 -0
  21. package/dist/assets/InstancesTable-C81CknSI.js +1 -0
  22. package/dist/assets/IntegrationDetail-D-YgdyLl.js +1 -0
  23. package/dist/assets/Integrations-DNAuezUf.js +1 -0
  24. package/dist/assets/{Integrations-DziYFJDe.js → Integrations-DvJiMePt.js} +2 -2
  25. package/dist/assets/Library-DhRQQIcQ.js +1 -0
  26. package/dist/assets/Locations-CzTWySjI.js +3 -0
  27. package/dist/assets/{Logs-D76tMs8T.js → Logs-Qs13Mwb4.js} +1 -1
  28. package/dist/assets/{MaskShapeCanvas-DhkgwuqU.js → MaskShapeCanvas-Dj-FghGr.js} +1 -1
  29. package/dist/assets/{MotionZonesSettings-ePEXl_eY.js → MotionZonesSettings-DbgeWC2L.js} +1 -1
  30. package/dist/assets/MyAccess-WIF20bV3.js +2 -0
  31. package/dist/assets/Network-C3KG_FSW.js +1 -0
  32. package/dist/assets/{NewExportModal-DcAnxwF1.js → NewExportModal-Dy3oNUAO.js} +1 -1
  33. package/dist/assets/NodeAddonsSettingsPanel-DdbuZ3Yi.js +1 -0
  34. package/dist/assets/Notifications-Bqde3sni.js +1 -0
  35. package/dist/assets/{PanelContent-BD4VlG0k.js → PanelContent-BMrwHYf4.js} +2 -2
  36. package/dist/assets/Pipeline-BYpUtJpZ.js +1 -0
  37. package/dist/assets/{PrivacyMaskSettings-BKbsxTCz.js → PrivacyMaskSettings-BWDEhn0S.js} +1 -1
  38. package/dist/assets/{SceneMonitorEditor-BsG_DspV.js → SceneMonitorEditor-df7cZ311.js} +1 -1
  39. package/dist/assets/SessionsList-Bjhwy-7x.js +2 -0
  40. package/dist/assets/{Showroom-syizHLdc.js → Showroom-DCb25_tl.js} +1 -1
  41. package/dist/assets/{StorageLocationsTable-DX9GAr79.js → StorageLocationsTable-D29oGl9n.js} +1 -1
  42. package/dist/assets/System-Bz2RLf9j.js +1 -0
  43. package/dist/assets/TemplateEditorDialog-C0r2EnJJ.js +1 -0
  44. package/dist/assets/{Terminal-DNCcPfaX.js → Terminal-8cb4qrcL.js} +5 -5
  45. package/dist/assets/{TrainingProviders-Kir4QyJ0.js → TrainingProviders-DiSjJ4vy.js} +1 -1
  46. package/dist/assets/{Viewer-CxhObjjY.js → Viewer-JA89uHB4.js} +1 -1
  47. package/dist/assets/{__vite-browser-external-B6QEsNSJ.js → __vite-browser-external-DIbVKiho.js} +1 -1
  48. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DrIBdeiK.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CaJo1z-X.js} +1 -1
  49. package/dist/assets/{action-draft-BaaZLiaa.js → action-draft-80EQEtaM.js} +1 -1
  50. package/dist/assets/{ai-page.helpers-ByoISKAg.js → ai-page.helpers-DDnyI4U7.js} +1 -1
  51. package/dist/assets/{assignment-candidates-CfAyipS2.js → assignment-candidates-5H8d1AOa.js} +1 -1
  52. package/dist/assets/{authed-media-DHr41d8D.js → authed-media-Cu0gpTLP.js} +1 -1
  53. package/dist/assets/{board-model-COHOZu1s.js → board-model-D56hE08L.js} +1 -1
  54. package/dist/assets/camera-block-model-CCoPnK76.js +1 -0
  55. package/dist/assets/client-B3h-2G71.js +1120 -0
  56. package/dist/assets/{command-vocab-CopJIH2j.js → command-vocab-5-fsG014.js} +1 -1
  57. package/dist/assets/{device-detail-Bg2Ezyca.js → device-detail-iMuwFcWs.js} +1 -1
  58. package/dist/assets/{device-integration-icon-C0zbgR36.js → device-integration-icon-qHQjeL9y.js} +1 -1
  59. package/dist/assets/device-picker-model-DY4G4-U0.js +1 -0
  60. package/dist/assets/dist-Bt80qYnQ.js +1120 -0
  61. package/dist/assets/dist-C5ZYqtm3.js +1 -0
  62. package/dist/assets/{format-DVtQDLvq.js → format-BkMEj2-U.js} +1 -1
  63. package/dist/assets/{hostInit-BTfD9BWB.js → hostInit-DNeMlxxp.js} +1 -1
  64. package/dist/assets/i18n-BwW8nRaE.js +1 -0
  65. package/dist/assets/icons-CyWLWtXs.js +1 -0
  66. package/dist/assets/index-Bz3Pl5tG.css +2 -0
  67. package/dist/assets/index-D_vdUQKv.js +6 -0
  68. package/dist/assets/{linked-devices-model-CmiXN3Md.js → linked-devices-model-CI7wpAm-.js} +1 -1
  69. package/dist/assets/{mf-entry-bootstrap-0-8b23b2f2.js → mf-entry-bootstrap-0-c51fcd96.js} +2 -2
  70. package/dist/assets/mount-DY4G4-U0.js +1 -0
  71. package/dist/assets/{notification-rule-status-C6gd_uCT.js → notification-rule-status-CObTJD-i.js} +1 -1
  72. package/dist/assets/player-overlays-ugkkFXtV.js +1 -0
  73. package/dist/assets/remoteEntry-CjuAs5ha.js +1 -0
  74. package/dist/assets/src-DeDx2fDl.js +279 -0
  75. package/dist/assets/{sso-popup-CH6-S_OR.js → sso-popup-BRNSJ3u5.js} +1 -1
  76. package/dist/assets/{step-inspector-model-BG1lVQcU.js → step-inspector-model-BkoSviyf.js} +1 -1
  77. package/dist/assets/{terminal-Dgb4lrgM.js → terminal-DZ5OZpgC.js} +1 -1
  78. package/dist/assets/{use-scenes-feed-CWLyPlSj.js → use-scenes-feed-bbgFxJ_U.js} +1 -1
  79. package/dist/assets/{useAdminDeviceRemoval-CK2_Fytr.js → useAdminDeviceRemoval-Ia1zPolI.js} +1 -1
  80. package/dist/assets/useEventInvalidation-DY4G4-U0.js +1 -0
  81. package/dist/assets/{useNodeUrlSelection-piTRveNK.js → useNodeUrlSelection-BQ2MYP7C.js} +1 -1
  82. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-ePjBjURL.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BWXQZsum.js} +2 -2
  83. package/dist/index.html +11 -11
  84. package/dist/server/addon.js +1326 -174
  85. package/package.json +2 -2
  86. package/dist/assets/Addons-4zb8WqsP.js +0 -5
  87. package/dist/assets/AiProfiles-09uEdzUc.js +0 -3
  88. package/dist/assets/Archive-DDg3Te3v.js +0 -1
  89. package/dist/assets/Build-Dysn_dsI.js +0 -40
  90. package/dist/assets/CameraGrids-BaVLUgNc.js +0 -1
  91. package/dist/assets/Cluster-DCb9pTRO.js +0 -1
  92. package/dist/assets/CompositionBlockEditor-Bo7NCArN.js +0 -2
  93. package/dist/assets/CompositionEditorPage-D9gqtKg_.js +0 -1
  94. package/dist/assets/Data-CCfGw4D3.js +0 -2
  95. package/dist/assets/DeviceDetail-DGaYflb1.js +0 -1
  96. package/dist/assets/History-BzHUR50W.js +0 -1
  97. package/dist/assets/Identity-BH_Psx-M.js +0 -1
  98. package/dist/assets/InstancesTable-BkkLy_BU.js +0 -1
  99. package/dist/assets/IntegrationDetail-Dh1zEIkB.js +0 -1
  100. package/dist/assets/Integrations-I8w-NmB5.js +0 -1
  101. package/dist/assets/Library-CrU752kO.js +0 -1
  102. package/dist/assets/Locations-Cz9dHdgC.js +0 -3
  103. package/dist/assets/MyAccess-DrN6K8e1.js +0 -2
  104. package/dist/assets/Network-CcBl6Bv3.js +0 -1
  105. package/dist/assets/NodeAddonsSettingsPanel-BUnGcCpc.js +0 -1
  106. package/dist/assets/Notifications-DC_4_Px5.js +0 -1
  107. package/dist/assets/Pipeline-C9c451F4.js +0 -1
  108. package/dist/assets/SessionsList-CXVcORvl.js +0 -2
  109. package/dist/assets/System-D_y9BjT7.js +0 -1
  110. package/dist/assets/TemplateEditorDialog-Dg33OIxl.js +0 -1
  111. package/dist/assets/client-dUCYJcne.js +0 -1120
  112. package/dist/assets/device-picker-model-QTALOVj9.js +0 -1
  113. package/dist/assets/dist-BqygMNK3.js +0 -1
  114. package/dist/assets/dist-DcdbWcG-.js +0 -1120
  115. package/dist/assets/i18n-CtEN5OSf.js +0 -1
  116. package/dist/assets/icons-J91dUPcu.js +0 -1
  117. package/dist/assets/index-BuwKkAl-.js +0 -6
  118. package/dist/assets/index-pEaRJHY2.css +0 -2
  119. package/dist/assets/mount-QTALOVj9.js +0 -1
  120. package/dist/assets/player-overlays-CMIUmcCR.js +0 -1
  121. package/dist/assets/remoteEntry-CYYrFOe1.js +0 -1
  122. package/dist/assets/src-CZCLpkMn.js +0 -279
  123. package/dist/assets/useEventInvalidation-QTALOVj9.js +0 -1
@@ -0,0 +1 @@
1
+ import{C as e,J as t,K as n,Q as r,R as i,S as a,V as o,Y as s,et as c,o as l,x as u}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 d,Hn as f,Qa as p,Tt as m,Wi as h,Wt as g,Xr as _,Yn as v,Zt as y,c as b,ct as x,da as S,f as C,fa as w,ft as T,hi as E,ir as D,l as O,mn as k,qn as A,qt as j,sa as M,tn as N,u as P,ur as F,wi as I,yn as L,yt as R,zr as z}from"./player-overlays-ugkkFXtV.js";import{cl as B}from"./client-B3h-2G71.js";import{s as V}from"./terminal-DZ5OZpgC.js";import{a as H,i as ee,n as U,o as W,r as G,t as K}from"./user-x-DkWcmF99.js";import{t as te}from"./crop-B-t0rzRY.js";import{t as ne}from"./square-check-big-DAcFGNUN.js";import{Bc as re,Cd as ie,Dr as q,Fc as ae,Gi as oe,Gp as se,Hc as ce,Hi as J,Ic as le,Id as ue,Ir as de,Ji as fe,Js as pe,Ki as me,Lc as he,Ld as ge,Mc as _e,Nc as ve,Oa as ye,Pc as be,Pd as xe,Rc as Se,Rr as Ce,Sd as we,Tr as Te,Uc as Ee,Vc as De,Wi as Oe,Wp as ke,_d as Ae,_p as je,bd as Me,ca as Ne,cp as Y,fd as Pe,gd as Fe,gp as Ie,hd as Le,jc as Re,md as ze,nt as Be,pd as Ve,pi as He,qi as Ue,ra as We,rt as Ge,t as Ke,tt as qe,ut as Je,vd as Ye,wd as Xe,xd as Ze,yd as Qe,zc as $e,zr as et}from"./src-DeDx2fDl.js";import{t as X}from"./i18n-BwW8nRaE.js";import{t as Z}from"./useTranslation-BJr-n0es.js";import{Ai as tt,D as nt,Oi as rt,Si as it,gi as at,ji as ot,ki as st}from"./index-D_vdUQKv.js";import{t as ct}from"./AdminSectionedPage-3Jh0qbF0.js";import{a as lt,c as ut,d as dt,f as ft,i as pt,l as mt,m as ht,n as gt,o as _t,p as vt,r as yt,s as bt,t as xt}from"./NewExportModal-Dy3oNUAO.js";import{a as St,n as Ct,r as wt}from"./authed-media-Cu0gpTLP.js";import{t as Tt}from"./format-size-DIxKXxtj.js";import{t as Et}from"./use-scenes-feed-bbgFxJ_U.js";c();function Dt(e){let t=[];return e.timelapse?t.push(`timelapse ${String(e.timelapse.everyMs/1e3)}s`):(t.push(`${String(e.speed??1)}×`),e.includeAudio&&t.push(`+ audio`)),t.join(` `)}function Ot(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}function kt(e,t){let n=Math.max(0,Math.round((t-e)/1e3)),r=Math.floor(n/3600),i=Math.floor(n%3600/60),a=n%60,o=r>0?`${String(r)}:${String(i).padStart(2,`0`)}:${String(a).padStart(2,`0`)}`:`${String(i)}:${String(a).padStart(2,`0`)}`;return`${Ot(e)} · ${o}`}function At(e,t){let n=e-t;if(n<=0)return X.t(`helpers.exportFormat.expired`);let r=Math.floor(n/6e4);if(r<60)return X.t(`helpers.exportFormat.inMinutes`,{n:String(r)});let i=Math.floor(r/60);return i<24?X.t(`helpers.exportFormat.inHours`,{n:String(i)}):X.t(`helpers.exportFormat.inDays`,{n:String(Math.floor(i/24))})}function jt(e,t,n,r){return e.map(e=>{if(e.state===`expired`||e.state===`deleted`)return e;let i=r.get(e.id);if(i)return{...e,state:`failed`,error:i.error,progressPct:null};let a=n.get(e.id);if(a)return{...e,state:`ready`,fileBytes:a.fileBytes,progressPct:100};let o=t.get(e.id);return o&&(e.state===`queued`||e.state===`rendering`)?{...e,state:`rendering`,progressPct:o.progressPct}:e})}var Mt=[[`recordingExport`]],Nt={queued:{cls:`bg-surface-hover text-foreground-subtle`,labelKey:`recordings.exportsSection.queued`},rendering:{cls:`bg-primary/10 text-primary`,labelKey:`recordings.exportsSection.rendering`,spin:!0},ready:{cls:`bg-success/10 text-success`,labelKey:`recordings.exportsSection.ready`},failed:{cls:`bg-danger/10 text-danger`,labelKey:`recordings.exportsSection.failed`},expired:{cls:`bg-surface-hover text-foreground-subtle`,labelKey:`recordings.exportsSection.expired`},deleted:{cls:`bg-surface-hover text-foreground-subtle`,labelKey:`recordings.exportsSection.deleted`}};function Pt(){let{data:e,isLoading:t}=ge({},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`queued`||e.state===`rendering`)?3e3:!1}),{map:r}=ke(B.RecordingExportProgress,e=>e.exportId),{map:i}=ke(B.RecordingExportCompleted,e=>e.exportId),{map:a}=ke(B.RecordingExportFailed,e=>e.exportId);return{rows:n(()=>jt(e??[],r,i,a),[e,r,i,a]),isLoading:t}}function Ft(e){let[t,n]=s(()=>Date.now());return o(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}function It(){let{t}=Z(),r=l(),[o,c]=s(!1),u=()=>{r.invalidateQueries({queryKey:[[`recordingExport`,`listExports`]]})},d=x(),f=R().trpcClient,p=Ft(6e4),{rows:m,isLoading:g}=Pt(),[_,v]=it(),y=ot(_.get(rt)),b=n(()=>tt(m,y),[m,y]),S=n(()=>st(m,y),[m,y]),C=e=>{v(t=>{let n=new URLSearchParams(t);return e===``?n.delete(rt):n.set(rt,e),n},{replace:!0})},{data:w}=pe({isCamera:!0,projection:`slim`}),D=n(()=>{let e=new Map;for(let t of w??[])e.set(t.id,t.name);return e},[w]),O=i(()=>{r.invalidateQueries({queryKey:Mt})},[r]),k=xe({onSuccess:O}),A=ue({onSuccess:O}),[j,M]=s(null),P=i(async e=>{M(e.id);try{let{url:t}=await f.recordingExport.getDownloadUrl.query({exportId:e.id}),n=await Ct(t),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.options.title??e.id}.mp4`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r),O()}finally{M(null)}},[f,O]),F=i(async e=>{await d({title:t(`recordings.exportsSection.cancelThisExport`,`Cancel this export?`),message:t(`recordings.exportsSection.stopsTheRenderThePartial`,`Stops the render. The partial file is discarded.`),confirmLabel:t(`recordings.exportsSection.cancelExport`,`Cancel export`),variant:`danger`})&&k.mutate({exportId:e.id})},[d,k,t]),L=i(async e=>{await d({title:t(`recordings.exportsSection.deleteThisExport`,`Delete this export?`),message:t(`recordings.exportsSection.permanentlyRemovesTheRenderedFile`,`Permanently removes the rendered file and its history row.`),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&A.mutate({exportId:e.id})},[d,A,t]),B=n(()=>[{key:`camera`,header:t(`recordings.exportsSection.camera`,`Camera`),render:e=>a(`span`,{className:`text-foreground`,children:D.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`created`,header:t(`recordings.exportsSection.created`,`Created`),nowrap:!0,sortValue:e=>e.createdAt,render:n=>e(`span`,{className:`text-foreground-subtle tabular-nums`,children:[new Date(n.createdAt).toLocaleString(),a(`span`,{className:`ml-1`,children:t(`recordings.exportsSection.by`,`by {{who}}`,{who:n.createdBy})})]})},{key:`title`,header:t(`recordings.exportsSection.title`,`Title`),render:e=>a(`span`,{className:`text-foreground`,children:e.options.title??`—`})},{key:`range`,header:t(`recordings.exportsSection.range`,`Range`),nowrap:!0,render:e=>a(`span`,{className:`tabular-nums`,children:kt(e.fromMs,e.toMs)})},{key:`variant`,header:t(`recordings.exportsSection.variant`,`Variant`),render:e=>a(`span`,{className:`text-foreground-subtle`,children:Dt(e.options)})},{key:`state`,header:t(`recordings.exportsSection.state`,`State`),render:n=>{let r=Nt[n.state];return e(`div`,{className:`flex flex-col gap-0.5`,children:[e(`span`,{className:`inline-flex w-fit items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${r.cls}`,children:[r.spin&&a(z,{className:`h-2.5 w-2.5 animate-spin`}),t(r.labelKey),n.state===`rendering`&&n.progressPct!==null&&e(`span`,{className:`tabular-nums`,children:[n.progressPct,`%`]})]}),n.error!==null&&a(`span`,{className:`text-[10px] text-danger`,children:n.error})]})}},{key:`expiry`,header:t(`recordings.exportsSection.expires`,`Expires`),nowrap:!0,render:e=>e.state===`deleted`?a(`span`,{className:`text-foreground-subtle`,children:`—`}):a(`span`,{className:`text-foreground-subtle tabular-nums`,children:At(e.expiresAt,p)})},{key:`downloaded`,header:t(`recordings.exportsSection.downloaded`,`Downloaded`),nowrap:!0,render:e=>a(`span`,{className:`text-foreground-subtle tabular-nums`,children:e.downloadedAt===null?`—`:new Date(e.downloadedAt).toLocaleString()})},{key:`size`,header:t(`recordings.exportsSection.size`,`Size`),align:`right`,nowrap:!0,render:e=>a(`span`,{className:`tabular-nums`,children:e.fileBytes===null?`—`:Tt(e.fileBytes)})},{key:`actions`,header:``,align:`right`,render:n=>{let r=n.state===`ready`,i=n.state===`queued`||n.state===`rendering`,o=n.state!==`deleted`;return e(`div`,{className:`flex items-center justify-end gap-1`,children:[r&&e(Y,{variant:`unstyled`,onClick:()=>{P(n)},disabled:j===n.id,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-primary/10 hover:text-foreground disabled:opacity-50`,title:t(`recordings.exportsSection.downloadMp4`,`Download MP4`),children:[j===n.id?a(z,{className:`h-3 w-3 animate-spin`}):a(I,{className:`h-3 w-3`}),t(`recordings.exportsSection.download`,`Download`)]}),i&&e(Y,{variant:`unstyled`,onClick:()=>{F(n)},disabled:k.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-warning/10 hover:text-warning disabled:opacity-50`,title:t(`recordings.exportsSection.cancelRender`,`Cancel render`),children:[a(h,{className:`h-3 w-3`}),t(`common.cancel`,`Cancel`)]}),o&&a(Y,{variant:`unstyled`,onClick:()=>{L(n)},disabled:A.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:t(`recordings.exportsSection.deleteExport`,`Delete export`),children:a(N,{className:`h-3 w-3`})})]})}}],[D,p,j,k.isPending,A.isPending,P,F,L,t]);return g&&b.length===0?e(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[a(z,{className:`h-4 w-4 animate-spin`}),t(`recordings.exportsSection.loadingExports`,`Loading exports…`)]}):e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[S.length>1||y!==null?e(T,{wrapperClassName:`mr-auto inline-block w-auto`,"aria-label":t(`recordings.exportsSection.camera`,`Camera`),value:y===null?``:String(y),onChange:e=>C(e.target.value),children:[a(`option`,{value:``,children:t(`recordings.exportsSection.allCameras`,`All cameras`)}),S.map(e=>a(`option`,{value:String(e),children:D.get(e)??`#${String(e)}`},e))]}):null,e(Y,{variant:`unstyled`,onClick:()=>c(!0),className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground`,children:[a(E,{className:`h-3.5 w-3.5`}),t(`recordings.exportsSection.newExport`,`New export`)]})]}),b.length===0&&m.length>0?a(Ne,{icon:E,title:t(`recordings.exportsSection.noExportsForCamera`,`No exports for this camera`),description:t(`recordings.exportsSection.noExportsForCameraHint`,`Pick All cameras to see every export, or create one with New export.`)}):b.length===0?a(Ne,{icon:E,title:t(`recordings.exportsSection.noExportsYet`,`No exports yet`),description:t(`recordings.exportsSection.createOneHereNewExport`,`Create one here (New export) or from a camera's timeline in the viewer. Rendered clips show up here to download or manage.`)}):a(Ce,{columns:B,rows:b,rowKey:e=>e.id,minWidthPx:720}),o&&a(xt,{onClose:()=>c(!1),onCreated:u,...y===null?{}:{initialDeviceId:y}})]})}function Lt({mediaId:e,base64:t,alt:n,className:r,placeholder:i}){let{src:o,failed:s}=St(e===void 0?void 0:wt(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 Rt=`pipeline-analytics`,zt=`photo.analyze`,Bt=`photo.enroll`,Vt=`photo.discard`,Ht=18*1024*1024;function Ut(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Q(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function $(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Wt(e,t){let n=e[t];return typeof n==`boolean`?n:null}function Gt(e){if(!Ut(e))return null;let t=$(e,`x`),n=$(e,`y`),r=$(e,`width`),i=$(e,`height`);return t===null||n===null||r===null||i===null?null:{x:t,y:n,width:r,height:i}}function Kt(e){if(!Ut(e))return null;let t=$(e,`detectionShortSidePx`),n=$(e,`score`);if(t===null||n===null)return null;let r=$(e,`magnitude`);return{detectionShortSidePx:t,score:n,...r===null?{}:{magnitude:r}}}function qt(e){if(!Ut(e))return null;let t=$(e,`faceIndex`),n=$(e,`score`),r=Wt(e,`enrollable`),i=Gt(e.bbox),a=Kt(e.quality);if(t===null||n===null||r===null||i===null||a===null)return null;let o=Q(e,`refusedReason`),s=Q(e,`alignedCropBase64`),c=Q(e,`modelId`);return{faceIndex:t,bbox:i,score:n,enrollable:r,quality:a,...o===null?{}:{refusedReason:o},...s===null?{}:{alignedCropBase64:s},...c===null?{}:{modelId:c}}}function Jt(e){if(!Ut(e))return null;let t=Q(e,`sessionId`),n=Q(e,`ranOnNodeId`),r=e.faces;if(t===null||n===null||!Array.isArray(r))return null;let i=[];for(let e of r){let t=qt(e);t!==null&&i.push(t)}return{sessionId:t,ranOnNodeId:n,faces:i}}function Yt(e){if(!Ut(e))return null;let t=Q(e,`sampleId`),n=Q(e,`identityId`),r=Q(e,`modelId`);return t===null||n===null||r===null?null:{sampleId:t,identityId:n,modelId:r}}function Xt(e,t,n){let r={...e};return n===null||n===``?delete r[t]:r[t]=n,r}function Zt(e,t){return e.filter(e=>e.enrollable&&t[e.faceIndex]!==void 0).length}function Qt(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 $t(e){switch(e){case`no-embedding`:return X.t(`helpers.photoEnroll.refusal.noEmbedding`);case`no-model-id`:return X.t(`helpers.photoEnroll.refusal.noModelId`);case`no-aligned-crop`:return X.t(`helpers.photoEnroll.refusal.noAlignedCrop`);case`magnitude`:return X.t(`helpers.photoEnroll.refusal.magnitude`);default:return X.t(`helpers.photoEnroll.refusal.default`)}}function en(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 tn(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 nn(e,t,n){return e.map(e=>e.photoIndex===t?{...e,...n}:e)}function rn(e,t){return`${e}:${t}`}function an(e,t,n,r){let i=Xt(e[t]??{},n,r),a={...e};return Object.keys(i).length===0?delete a[t]:a[t]=i,a}function on(e,t){let n=0;for(let r of e)r.analysis!==void 0&&(n+=Zt(r.analysis.faces,t[r.photoIndex]??{}));return n}var sn=`__new__`;function cn(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[rn(i.photoIndex,t.faceIndex)]??``).trim();if(a===``)return{kind:`error`,message:X.t(`helpers.photoEnrollBatch.newPersonNoName`,{filename:i.filename,face:t.faceIndex+1})};r.includes(a)||r.push(a)}}return{kind:`ok`,names:r}}function ln(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[rn(e,a)]??``).trim()];s!==void 0&&(o[a]=s)}r[e]=o}return r}function un(e,t){let n=[];for(let r of e){if(r.analysis===void 0)continue;let e=Qt(r.analysis.sessionId,r.analysis.faces,t[r.photoIndex]??{});for(let t of e)n.push({photoIndex:r.photoIndex,request:t})}return n}function dn(e){return/expired/i.test(e)}function fn(e){return e instanceof Error?e.message:String(e)}async function pn(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??X.t(`helpers.photoEnrollBatch.photoFallback`,{n:e+1});return X.t(`helpers.photoEnrollBatch.faceLabel`,{filename:n,face:t+1})};for(let l of un(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=fn(t);if(!dn(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 (${fn(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)}: ${fn(e)}`)}}}return{enrolled:o,stampedModelId:s,failures:a,refreshedAnalyses:i}}c();var mn=[[`faceGallery`]],hn=``;function gn(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 _n(e){return e instanceof Error?e.message:String(e)}function vn({face:t,identities:r,value:i,onChange:o,disabled:s}){let{t:c}=Z(),l=n(()=>[{value:hn,label:c(`detectionIntelligence.photoEnrollDialog.ignoreThisFace`,`Ignore this face`)},...r.map(e=>({value:e.id,label:e.name})),{value:sn,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(U,{className:`h-8 w-8`})})}),a(`div`,{className:`min-h-[4.75rem]`,children:t.enrollable?e(u,{children:[a(T,{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(ye,{variant:`warning`,className:`text-[10px]`,children:c(`detectionIntelligence.photoEnrollDialog.notUsable`,`Not usable`)}),a(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:$t(t.refusedReason)})]})})]})}function yn({photo:t,identities:n,draft:r,newNames:i,disabled:o,onAssign:s,onNameChange:c,onRetry:l}){let{t:u}=Z(),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(Y,{variant:`secondary`,size:`sm`,disabled:o,onClick:l,children:[a(A,{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(y,{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(vn,{face:e,identities:n,value:f[e.faceIndex]??hn,disabled:o,onChange:t=>s(e.faceIndex,t)},e.faceIndex))}),d.filter(e=>f[e.faceIndex]===sn).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(Ie,{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[rn(t.photoIndex,n.faceIndex)]??``,onChange:e=>c(n.faceIndex,e.target.value)})]},n.faceIndex))]})}function bn({open:r,onOpenChange:o}){let{t:c}=Z(),u=R(),d=l(),f=t(null),{data:p}=le(),m=_e(),[h,g]=s([]),[_,v]=s(!1),[b,x]=s(null),[S,C]=s({}),[w,T]=s({}),[E,D]=s(null),O=n(()=>(p??[]).map(e=>({id:e.id,name:e.name})),[p]),k=h.some(e=>e.status===`queued`||e.status===`analyzing`),A=k||_,j=i(e=>{for(let t of e){let e=t.analysis?.sessionId;e!==void 0&&u.trpcClient.addons.custom.mutate({addonId:Rt,action:Vt,input:{sessionId:e}}).catch(()=>void 0)}},[u]),M=i(()=>{g([]),C({}),T({}),x(null),D(null),f.current&&(f.current.value=``)},[]),N=i(()=>{j(h),M(),o(!1)},[j,o,h,M]),P=i(async e=>{let t=Jt(await u.trpcClient.addons.custom.mutate({addonId:Rt,action:zt,input:{photoBase64:e.photoBase64,filename:e.filename}}));if(t===null)throw Error(`the server replied with something this page could not read`);return t},[u]),F=i(async e=>{g(t=>nn(t,e.photoIndex,{status:`analyzing`,error:void 0}));try{let t=await P(e);g(n=>nn(n,e.photoIndex,{status:`analyzed`,analysis:t}))}catch(t){g(n=>nn(n,e.photoIndex,{status:`failed`,error:_n(t)}))}},[P]),I=i(async e=>{if(e.length===0)return;j(h),M();let t=en(e,{maxCount:12,maxBytes:Ht}),n=[];t.oversize.length>0&&n.push(`Over the ${Math.round(Ht/(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&&x(n.join(` `));let r;try{r=await Promise.all(t.accepted.map(async(e,t)=>({photoIndex:t,filename:e.name,photoBase64:await gn(e),status:`queued`})))}catch(e){x(_n(e));return}g(r),await tn(r,2,e=>F(e))},[j,h,M,F]),L=on(h,S),B=i(async()=>{v(!0),x(null),D(null);try{let e=cn(h,S,w);if(e.kind===`error`){x(e.message);return}let t={};for(let n of e.names)t[n]=(await m.mutateAsync({name:n})).id;let n=await pn(h,ln(S,w,t),{enroll:async e=>{let t=Yt(await u.trpcClient.addons.custom.mutate({addonId:Rt,action:Bt,input:e}));if(t===null)throw Error(`unreadable reply`);return t},reanalyze:e=>P(e)});Object.keys(n.refreshedAnalyses).length>0&&g(e=>e.map(e=>{let t=n.refreshedAnalyses[e.photoIndex];return t===void 0?e:{...e,status:`analyzed`,analysis:t}})),d.invalidateQueries({queryKey:mn}),n.failures.length>0&&x(n.failures.join(` · `)),D(n.enrolled===0?`Nothing was enrolled.`:`Enrolled ${n.enrolled} sample${n.enrolled===1?``:`s`}${n.stampedModelId===null?``:` with ${n.stampedModelId}`}.`)}catch(e){x(_n(e))}finally{v(!1)}},[P,m,S,w,h,d,u]),V=h.filter(e=>e.status===`analyzed`).length;return a(J,{open:r,onOpenChange:e=>e?o(!0):N(),children:e(Oe,{className:`max-w-3xl`,children:[e(Ue,{children:[a(fe,{children:c(`detectionIntelligence.photoEnrollDialog.enrolFromPhotos`,`Enrol from photos`)}),a(oe,{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(at,{i18nKey:`detectionIntelligence.photoEnrollDialog.reliableRecognition`,components:{strong:a(`strong`,{})}})}),e(`div`,{className:`flex items-center gap-2`,children:[a(He,{ref:f,accept:`image/jpeg,image/png,image/webp`,multiple:!0,className:`hidden`,onChange:e=>void I(Array.from(e.target.files??[]))}),e(Y,{variant:`secondary`,size:`sm`,disabled:A,onClick:()=>f.current?.click(),children:[k?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(H,{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:V,count:h.length})})]}),a(`div`,{className:`min-h-11`,"aria-live":`polite`,children:b===null?E===null?null:a(`div`,{className:`rounded-md border border-success/40 bg-success/10 px-3 py-2 text-xs text-success`,children:E}):e(`div`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[a(y,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),a(`span`,{children:b})]})}),h.length>0&&a(`div`,{className:`max-h-[50vh] space-y-4 overflow-y-auto pr-1`,children:h.map(e=>a(yn,{photo:e,identities:O,draft:S,newNames:w,disabled:A,onAssign:(t,n)=>C(r=>an(r,e.photoIndex,t,n===hn?null:n)),onNameChange:(t,n)=>T(r=>({...r,[rn(e.photoIndex,t)]:n})),onRetry:()=>void F(e)},e.photoIndex))}),e(me,{children:[a(Y,{variant:`secondary`,onClick:N,disabled:_,children:c(`common.close`,`Close`)}),e(Y,{variant:`primary`,onClick:()=>void B(),disabled:A||L===0,children:[_?a(z,{className:`h-3.5 w-3.5 animate-spin`}):null,c(`detectionIntelligence.photoEnrollDialog.enrolFaces`,{count:L})]})]})]})})}c();var xn=[[`faceGallery`]];function Sn({identityId:t}){let{t:n}=Z(),r=l(),{data:i,isLoading:o}=he({identityId:t}),s=$e();function c(e){s.mutate({identityId:t,sampleId:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:xn})}})}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(U,{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(H,{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(m,{className:`h-4 w-4 text-white`})})]},t.id))})}function Cn(t){return[{key:`person`,header:X.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(Lt,{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(U,{className:`h-4 w-4 text-foreground-subtle`})})})}),a(`span`,{className:`truncate text-sm font-medium text-foreground`,children:t.name})]})},{key:`samples`,header:X.t(`detectionIntelligence.peopleList.samples`,`Samples`),align:`center`,nowrap:!0,sortValue:e=>e.sampleCount,render:e=>a(ye,{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(je,{variant:`ghost`,size:`sm`,icon:F,"aria-label":X.t(`detectionIntelligence.peopleList.edit`,`Edit {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onEdit(n)}}),a(je,{variant:`ghost`,size:`sm`,icon:N,"aria-label":X.t(`detectionIntelligence.peopleList.delete`,`Delete {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onDelete(n)}})]})}]}function wn({mode:t,identity:n,onClose:r}){let{t:i}=Z(),c=l(),[u,d]=s(t===`edit`?n?.name??``:``),f=_e(),p=re();o(()=>{d(t===`edit`?n?.name??``:``)},[t,n?.id,n?.name]);let m=f.isPending||p.isPending,h=u.trim(),g=t===`edit`&&n!==null&&h===n.name,_=m||h.length===0||g;function v(){c.invalidateQueries({queryKey:xn})}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(Ge,{open:!0,onClose:r,title:t===`new`?`Add person`:`Edit ${n?.name??`person`}`,icon:U,width:t===`edit`?`xl`:`lg`,testId:`people-person-form`,footer:e(Y,{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(Je,{label:i(`detectionIntelligence.peopleList.name`,`Name`),required:!0,children:a(Ie,{value:u,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(Sn,{identityId:n.id})]})]})})}function Tn(){let{t}=Z(),r=l(),i=x(),{data:c,isLoading:u}=le(),d=be(),{state:f,openNew:p,openEdit:m,close:h}=Be(),[g,_]=s(!1),v=c??[],y=Te(v,{searchText:e=>[e.name]}),b=f.mode===`edit`?v.find(e=>e.id===f.id)??null:null;o(()=>{f.mode===`edit`&&!u&&b===null&&h()},[f.mode,u,b,h]);let S=n(()=>Cn({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:xn}),f.mode===`edit`&&f.id===e.id&&h()}})})()}}),[i,h,d,f,m,r,t]);if(u)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`&&b!==null;return e(`div`,{className:`space-y-2`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(Y,{variant:`primary`,size:`sm`,type:`button`,onClick:p,children:[a(D,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.peopleList.addPerson`,`Add person`)]}),e(Y,{variant:`secondary`,size:`sm`,type:`button`,onClick:()=>_(!0),children:[a(H,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.peopleList.enrolFromAPhoto`,`Enrol from a photo`)]})]}),(v.length>0||y.active)&&a(q,{state:y.state,facets:y.facets,labels:{searchPlaceholder:`Search people…`,searchLabel:`Search people`,facetsLabel:`Filter`,clearLabel:`Clear`},onSearch:y.setSearch,onToggleFacet:y.toggleFacet,onClear:y.clear}),y.rows.length===0?a(Ne,{icon:U,title:y.active?t(`detectionIntelligence.peopleList.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.peopleList.noPeopleEnrolledYet`,`No people enrolled yet`),description:y.active?t(`detectionIntelligence.peopleList.clearTheSearchOrTry`,`Clear the search or try another name.`):t(`detectionIntelligence.peopleList.addAPersonOrEnrol`,`Add a person, or enrol faces from a photo.`)}):a(Ce,{columns:S,rows:y.rows,rowKey:e=>e.id,maxBodyHeight:et,emptyMessage:t(`detectionIntelligence.peopleList.noPeopleEnrolledYet2`,`No people enrolled yet.`),onRowClick:e=>m(e.id)}),C&&a(wn,{mode:f.mode===`new`?`new`:`edit`,identity:b,onClose:h}),a(bn,{open:g,onOpenChange:_})]})}function En(e){let t=e.cropUrl!==void 0&&e.cropUrl.length>0,n=e.base64!==void 0&&e.base64.length>0;return!t&&!n}function Dn(e){return e.filter(En).map(e=>e.faceId)}function On(e){let t=0;for(let n of e)En(n)&&(t+=1);return t}function kn(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}c();var An=[[`faceGallery`]];function jn({faceIds:t,identities:n,onDone:r}){let{t:i}=Z(),o=l(),c=Re(),u=_e(),[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:An}),b()}})}function S(){!t||!d.trim()||u.mutate({name:d.trim()},{onSuccess:e=>{e?.id&&x(e.id)},onError:()=>{o.invalidateQueries({queryKey:An}),b()}})}let C=c.isPending||u.isPending;return a(J,{open:_,onOpenChange:e=>!e&&b(),children:e(Oe,{children:[e(Ue,{children:[a(fe,{children:v>1?i(`detectionIntelligence.assignDialog.assignFacesToPerson`,`Assign {{value1}} faces to person`,{value1:String(v)}):i(`detectionIntelligence.assignDialog.assignFaceToPerson`,`Assign face to person`)}),a(oe,{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(Y,{variant:`unstyled`,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(Ie,{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(Y,{variant:`unstyled`,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(me,{className:`min-h-[2.75rem]`,children:[a(Y,{variant:`secondary`,onClick:b,disabled:C,children:i(`common.cancel`,`Cancel`)}),p?e(Y,{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(Y,{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`)]})]})]})})}function Mn(e){return e<0?0:e>1?1:e}function Nn(e,t,n){if(!Number.isFinite(t)||!Number.isFinite(n)||t<=0||n<=0)return null;let r=Mn(e.x/t),i=Mn(e.y/n),a=Mn((e.x+e.w)/t),o=Mn((e.y+e.h)/n);return{x:r,y:i,width:Math.max(0,a-r),height:Math.max(0,o-i)}}c();function Pn(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 Ct(wt(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 Fn(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 In({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 Ln({box:e}){let{t}=Z();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 Rn({face:t,cameraName:r,onClose:i,onAssign:o,onUnassign:c,onDelete:l,actionsPending:u}){let{t:d}=Z(),{data:p,isFetching:m}=ae({faceId:t?.faceId??``},{enabled:t!==null}),[h,v]=s(`frame`),{frameSrc:y,naturalWidth:b,naturalHeight:x,failed:S}=Pn(t?.keyFrameMediaId),C=n(()=>{let e=Fn(p??[]);return e?e.url:kn(t)},[p,t]),w=n(()=>!t?.faceBbox||b===null||x===null?null:Nn(t.faceBbox,b,x),[t?.faceBbox,b,x]);if(t===null)return null;let T=t.keyFrameMediaId!==void 0&&!S,E=T&&h===`frame`,D=t.assigned?t.identityName??`Assigned`:t.recognizedIdentityId?`${t.identityName??`Recognized`} (suggested)`:`Unassigned`;return a(J,{open:!0,onOpenChange:e=>!e&&i(),children:e(Oe,{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(Y,{variant:`unstyled`,type:`button`,onClick:()=>v(`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(f,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.fullFrame`)]}),e(Y,{variant:`unstyled`,type:`button`,onClick:()=>v(`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(te,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.crop`)]})]}),E&&y?a(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:a(pt,{src:y,alt:d(`detectionIntelligence.faceDetailPanel.fullFrameWithDetectedFace`,`Full frame with detected face`),fit:`natural`,className:`w-full`,overlay:w?a(Ln,{box:w}):void 0})}):C?e(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[a(pt,{src:C,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(_,{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(In,{label:d(`detectionIntelligence.faceDetailPanel.camera`,`Camera`),value:r}),a(In,{label:d(`detectionIntelligence.faceDetailPanel.captured`,`Captured`),value:ft(t.timestamp)}),a(In,{label:d(`detectionIntelligence.faceDetailPanel.track`,`Track`),value:t.trackId}),a(In,{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(Y,{variant:`secondary`,onClick:()=>c(t.faceId),disabled:u,children:[a(K,{className:`h-3.5 w-3.5`}),` `,d(`detectionIntelligence.detailPanel.detach`)]}):e(Y,{variant:`primary`,onClick:()=>o(t.faceId),disabled:u,children:[a(g,{className:`h-3.5 w-3.5`}),` `,d(`common.assign`)]}),e(Y,{variant:`secondary`,onClick:()=>l(t.faceId),disabled:u,children:[a(N,{className:`h-3.5 w-3.5`}),` `,d(`common.delete`)]})]})]})})}function zn(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function Bn(e,t){return e.faceIds.filter(e=>!t.has(e))}function Vn(e,t){return e.faceIds.filter(e=>t(e))}c();var Hn=[[`faceGallery`]],Un=20,Wn=.3,Gn=.9,Kn=.05,qn=.5,Jn=2,Yn=10,Xn=2;function Zn({cluster:t,face:n,active:r,onSelect:i}){let{t:o}=Z(),s=kn(n);return e(Y,{variant:`unstyled`,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(_,{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 Qn({face:t,cameraName:n,nowMs:r,excluded:i,onToggleExclude:o,onDelete:s,deletePending:c}){let{t:l}=Z(),u=kn(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(_,{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(pt,{src:u,alt:l(`detectionIntelligence.similarGroupsModal.faceFrom`,`Face from {{cameraName}}`,{cameraName:n}),className:`h-full w-full`}),a(Y,{variant:`unstyled`,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?j:m,{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:dt(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(Y,{variant:`unstyled`,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(N,{className:`h-4 w-4`})})})]})}function $n({open:t,onClose:r,byId:i,cameraName:c,nowMs:d,identities:f,selectMany:m}){let{t:h}=Z(),_=l(),y=x(),b=ve(),[S,C]=s(qn),[w,T]=s(Xn),[E,D]=s(null),[O,k]=s({}),[A,j]=s(null),{data:M,isFetching:N,refetch:P}=De({threshold:S,minClusterSize:w,limit:Un},{enabled:t}),F=M??[];o(()=>{k({})},[S,w]),o(()=>{if(F.length===0){D(null);return}F.some(e=>e.representativeFaceId===E)||D(F[0]?.representativeFaceId??null)},[F]);let I=n(()=>F.find(e=>e.representativeFaceId===E)??null,[F,E]),R=I?O[I.representativeFaceId]??new Set:new Set,B=n(()=>I?Vn(I,e=>i.has(e)):[],[I,i]),V=I?I.faceIds.length-B.length:0,H=I?Bn({...I,faceIds:B},R):[];function ee(e){if(!I)return;let t=I.representativeFaceId;k(n=>({...n,[t]:zn(n[t]??new Set,e)}))}function U(){_.invalidateQueries({queryKey:Hn})}async function W(e){await y({title:h(`detectionIntelligence.similarGroupsModal.deleteFace`,`Delete face`),message:h(`detectionIntelligence.similarGroupsModal.permanentlyDeletesThisFaceCrop`,`Permanently deletes this face crop. This cannot be undone.`),confirmLabel:h(`common.delete`,`Delete`),variant:`danger`})&&b.mutate({faceId:e},{onSettled:U})}function G(){j(null),r()}function K(){H.length!==0&&(m(H),G())}return e(J,{open:t,onOpenChange:e=>!e&&G(),children:[e(Oe,{placement:`sheet-on-mobile`,width:`lg`,"aria-label":h(`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(L,{className:`h-4 w-4 text-primary`}),` `,h(`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:[h(`detectionIntelligence.similarGroupsModal.threshold`,`Threshold`),a(p,{min:Wn,max:Gn,step:Kn,value:S,onChange:e=>C(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:S.toFixed(2)})]}),e(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[h(`detectionIntelligence.similarGroupsModal.minSize`,`Min size`),a(Ie,{type:`number`,min:Jn,max:Yn,step:1,value:w,onChange:e=>T(Math.min(Yn,Math.max(Jn,Number(e.target.value)||Jn))),className:`w-12 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`})]}),e(Y,{variant:`secondary`,onClick:()=>{k({}),P()},disabled:N,children:[N?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(v,{className:`h-3.5 w-3.5`}),h(`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:N&&F.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`}),` `,h(`detectionIntelligence.similarGroupsModal.finding`)]}):F.length===0?a(`div`,{className:`flex flex-1 items-center justify-center py-8 text-xs text-foreground-subtle`,children:h(`detectionIntelligence.similarGroupsModal.noLookAlikeGroupsAt`,`No look-alike groups at this threshold.`)}):e(u,{children:[a(`div`,{className:`flex gap-2 overflow-x-auto pb-1 md:hidden`,children:F.map(e=>a(Zn,{cluster:e,face:i.get(e.representativeFaceId),active:e.representativeFaceId===E,onSelect:()=>D(e.representativeFaceId)},e.representativeFaceId))}),a(`div`,{className:`hidden shrink-0 flex-col gap-2 overflow-y-auto md:flex md:w-56`,children:F.map(e=>a(Zn,{cluster:e,face:i.get(e.representativeFaceId),active:e.representativeFaceId===E,onSelect:()=>D(e.representativeFaceId)},e.representativeFaceId))}),a(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:I&&e(u,{children:[V>0&&a(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:h(`detectionIntelligence.similarGroupsModal.hiddenCount`,{count:V})}),a(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(13rem,13rem))] justify-start gap-2`,children:B.map(e=>{let t=i.get(e);return t?a(Qn,{face:t,cameraName:c(t.deviceId),nowMs:d,excluded:R.has(e),onToggleExclude:()=>ee(e),onDelete:()=>void W(e),deletePending:b.isPending&&b.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(Y,{variant:`secondary`,onClick:K,disabled:H.length===0,children:h(`detectionIntelligence.similarGroupsModal.selectInGallery`,`Select in gallery`)}),e(Y,{variant:`primary`,onClick:()=>j(H),disabled:H.length===0,children:[a(g,{className:`h-3.5 w-3.5`}),` `,h(`detectionIntelligence.similarGroupsModal.adopt`,{count:H.length})]})]})]}),a(jn,{faceIds:A,identities:f,onDone:()=>j(null)})]})}c();var er=[[`faceGallery`]],tr=500,nr=120;function rr({face:t,cameraName:n,nowMs:r,selected:i,onToggleSelect:o,onAssign:s,onOpenDetail:c}){let{t:u}=Z(),d=l(),f=ce(),p=ve(),m=()=>{d.invalidateQueries({queryKey:er})},h=()=>c(t.faceId),v=kn(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:[v===null?e(`button`,{type:`button`,onClick:h,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:u(`detectionIntelligence.unassignedFaces.noCropImageTheFace`,`No crop image — the face's crop media is missing (a pre-fix orphan). Safe to delete.`),children:[a(_,{className:`h-7 w-7 text-warning/70`}),a(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:u(`detectionIntelligence.unassignedFaces.noCrop`,`No crop`)})]}):a(`img`,{src:v,alt:u(`detectionIntelligence.unassignedFaces.faceFrom`,`Face from {{cameraName}}`,{cameraName:n}),onClick:h,loading:`lazy`,decoding:`async`,className:`h-full w-full cursor-zoom-in object-cover`}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(t.faceId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?u(`detectionIntelligence.unassignedFaces.deselect`,`Deselect`):u(`detectionIntelligence.unassignedFaces.select`,`Select`),children:i?a(ne,{className:`h-4 w-4 text-primary`}):a(k,{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:dt(t.timestamp,r)}),a(`p`,{className:`min-h-[0.875rem] truncate text-[10px] font-medium leading-tight ${t.identityName?`text-primary`:`invisible`}`,title:t.identityName,children:t.identityName??`\xA0`})]}),e(`div`,{className:`mt-1 flex min-h-[2rem] items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[t.assigned?a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),f.mutate({faceId:t.faceId},{onSettled:m})},disabled:f.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":u(`detectionIntelligence.unassignedFaces.detachFace`,`Detach face`),title:u(`detectionIntelligence.unassignedFaces.detach`,`Detach`),children:f.isPending?a(z,{className:`h-4 w-4 animate-spin`}):a(K,{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":u(`detectionIntelligence.unassignedFaces.assignFaceToPerson`,`Assign face to person`),title:u(`detectionIntelligence.unassignedFaces.assignToPerson`,`Assign to person`),children:a(g,{className:`h-4 w-4`})}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),p.mutate({faceId:t.faceId},{onSettled:m})},disabled:p.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":u(`detectionIntelligence.unassignedFaces.deleteFace`,`Delete face`),title:u(`detectionIntelligence.unassignedFaces.deleteFace`,`Delete face`),children:p.isPending?a(z,{className:`h-4 w-4 animate-spin`}):a(N,{className:`h-4 w-4`})})]})]})}var ir=[{labelKey:`common.all`,value:`all`},{labelKey:`detectionIntelligence.unassignedFaces.filterUnassigned`,value:`unassigned`},{labelKey:`detectionIntelligence.unassignedFaces.filterRecognized`,value:`recognized`}];function ar(){let{t}=Z(),r=l(),[i,o]=s(`all`),[c,d]=s(_t),[f,p]=s(new Set),[h,v]=s(new Set),[y,b]=s(null),[x,S]=s(!1),[C,w]=s(null),{data:T,isLoading:E}=Se({limit:tr,filter:i,includeCrops:!1},{refetchInterval:3e4}),{data:D=[]}=le(),{data:O}=pe({isCamera:!0,projection:`slim`}),k=Re(),A=ce(),j=Ee(),M=ve(),P=Date.now(),F=T??[],I=n(()=>{let e=new Map;for(let t of O??[])e.set(t.id,t.name);return e},[O]),R=e=>I.get(e)??t(`detectionIntelligence.cameraFallback`,{id:String(e)}),B=n(()=>bt(F).map(e=>({id:e,name:R(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[F,I]),V=n(()=>ut(mt(F,c),f),[F,c,f]),H=gt(V,nr,n(()=>JSON.stringify([i,c.fromMs,c.toMs,[...f].sort((e,t)=>e-t)]),[i,c.fromMs,c.toMs,f])),ee=n(()=>new Map(F.map(e=>[e.faceId,e])),[F]),U=n(()=>On(V),[V]),W=C===null?null:ee.get(C)??null,G=()=>{r.invalidateQueries({queryKey:er})},te=()=>v(new Set);function ne(e){v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function re(e){v(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function ie(){re(Dn(V))}let q=[...h],ae=k.isPending||j.isPending||M.isPending,oe=A.isPending||M.isPending;function se(){q.length!==0&&j.mutate({faceIds:q},{onSettled:()=>{G(),te()}})}function J(){q.length!==0&&Promise.allSettled(q.map(e=>M.mutateAsync({faceId:e}))).then(()=>{G(),te()})}function ue(e){w(null),b([e])}function de(e){A.mutate({faceId:e},{onSettled:G}),w(null)}function fe(e){M.mutate({faceId:e},{onSettled:G}),w(null)}let me=V.length!==F.length;return e(`div`,{className:`relative space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[a(`div`,{className:`flex items-center gap-1`,children:ir.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(lt,{onChange:d}),a(vt,{cameras:B,selected:f,onChange:p}),e(`button`,{type:`button`,onClick:()=>S(!0),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${x?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(L,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.similarGroups`)]}),!E&&U>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(_,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.selectCropless`,{count:U})]}),!E&&a(`span`,{className:`text-[10px] text-foreground-subtle ${U>0?`ml-2`:`ml-auto`}`,children:me?t(`detectionIntelligence.unassignedFaces.ofFaces`,`{{value1}} of {{value2}} faces`,{value1:String(V.length),value2:String(F.length)}):t(`detectionIntelligence.unassignedFaces.faceCount`,{count:V.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(Y,{variant:`primary`,onClick:()=>b(q),disabled:ae,children:[a(g,{className:`h-3.5 w-3.5`}),` `,t(`common.assign`)]}),e(Y,{variant:`secondary`,onClick:se,disabled:ae,children:[j.isPending?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(K,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.unassignedFaces.detach`,`Detach`)]}),e(Y,{variant:`secondary`,onClick:J,disabled:ae,children:[a(N,{className:`h-3.5 w-3.5`}),` `,t(`common.delete`)]}),a(Y,{variant:`ghost`,onClick:te,disabled:ae,children:a(m,{className:`h-3.5 w-3.5`})})]})]}),E?a(qe,{status:`pending`,pendingMessage:`Loading faces…`,testId:`faces-grid`}):V.length===0?a(Ne,{icon:_,title:F.length>0?t(`detectionIntelligence.unassignedFaces.nothingMatchesTheFilter`,`Nothing matches the filter`):t(`detectionIntelligence.unassignedFaces.noFacesFoundForThis`,`No faces found for this filter`),description:F.length>0?t(`detectionIntelligence.unassignedFaces.widenTheDateRangeOr`,`Widen the date range or clear the camera filter.`):t(`detectionIntelligence.unassignedFaces.faceCropsAppearHereWhen`,`Face crops appear here when the detection pipeline captures them.`)}):e(u,{children:[a(qe,{status:`ready`,testId:`faces-grid`,className:`grid-cols-[repeat(auto-fill,minmax(6.5rem,6.5rem))] justify-start`,children:H.pageItems.map(e=>a(rr,{face:e,cameraName:R(e.deviceId),nowMs:P,selected:h.has(e.faceId),onToggleSelect:ne,onAssign:e=>b([e]),onOpenDetail:w},e.faceId))}),a(yt,{currentPage:H.page,totalItems:H.totalItems,pageSize:H.pageSize,onPageChange:H.setPage,itemNoun:`faces`})]}),a(Rn,{face:W,cameraName:W?R(W.deviceId):``,onClose:()=>w(null),onAssign:ue,onUnassign:de,onDelete:fe,actionsPending:oe}),a(jn,{faceIds:y,identities:D,onDone:()=>{b(null),te()}}),a($n,{open:x,onClose:()=>S(!1),byId:ee,cameraName:R,nowMs:P,identities:D,selectMany:re})]})}c();var or=[[`faceGallery`]],sr=2e3;function cr(){let e=l(),n=t(e);n.current=e;let r=t(void 0);r.current||=ht({delayMs:sr,invalidate:()=>{n.current.invalidateQueries({queryKey:or})}}),o(()=>()=>r.current?.cancel(),[]),se(B.PipelineAnalyticsFaceGalleryChanged,()=>{r.current?.trigger()})}function lr(){let{t}=Z();return cr(),e(`div`,{className:`space-y-3`,children:[a(de,{headingId:`library-people`,title:t(`detectionIntelligence.people`,`People`),icon:U,testId:`library-section-people`,children:e(`div`,{className:`${d} 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(Tn,{})]})}),a(de,{headingId:`library-recent-faces`,title:t(`detectionIntelligence.recentDetectedFaces`,`Recent detected faces`),icon:ee,testId:`library-section-recent-faces`,children:e(`div`,{className:`${d} 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(ar,{})]})})]})}function ur(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}c();var dr=[[`plateGallery`]];function fr({plateIds:t,vehicles:n,onDone:r}){let{t:i}=Z(),o=l(),c=Pe(),u=ze(),[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:dr}),b()}})}function S(){!t||!d.trim()||u.mutate({name:d.trim()},{onSuccess:e=>{e?.id&&x(e.id)},onError:()=>{o.invalidateQueries({queryKey:dr}),b()}})}let C=c.isPending||u.isPending;return a(J,{open:_,onOpenChange:e=>!e&&b(),children:e(Oe,{children:[e(Ue,{children:[a(fe,{children:v>1?i(`detectionIntelligence.assignPlateDialog.assignPlatesToVehicle`,`Assign {{value1}} plates to vehicle`,{value1:String(v)}):i(`detectionIntelligence.assignPlateDialog.assignPlateToVehicle`,`Assign plate to vehicle`)}),a(oe,{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(Y,{variant:`unstyled`,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(Ie,{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(Y,{variant:`unstyled`,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(me,{children:[a(Y,{variant:`secondary`,onClick:b,disabled:C,children:i(`common.cancel`,`Cancel`)}),p?e(Y,{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(Y,{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`)]})]})]})})}c();var pr=[[`plateGallery`]];function mr(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 Ct(wt(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 hr(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 gr({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 _r({box:e}){let{t}=Z();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 vr({plate:t,cameraName:r,onClose:i,onAssign:c,onUnassign:u,onDelete:d,actionsPending:p}){let{t:h}=Z(),v=l(),{data:y,isFetching:b}=Ae({plateId:t?.plateId??``},{enabled:t!==null}),x=Ve(),[S,C]=s(`frame`),[w,T]=s(!1),[E,D]=s(``),{frameSrc:O,naturalWidth:k,naturalHeight:A,failed:j}=mr(t?.keyFrameMediaId);o(()=>{T(!1),D(``),C(`frame`)},[t?.plateId]);let P=n(()=>{let e=hr(y??[]);return e?e.url:ur(t)},[y,t]),I=n(()=>!t?.plateBbox||k===null||A===null?null:Nn(t.plateBbox,k,A),[t?.plateBbox,k,A]);if(t===null)return null;let L=t.keyFrameMediaId!==void 0&&!j,R=L&&S===`frame`,B=t.assigned?t.vehicleName??`Assigned`:t.recognizedVehicleId?`${t.vehicleName??`Recognized`} (suggested)`:`Unassigned`,V=`${String(Math.round(t.score*100))}%${t.corrected?` · corrected`:``}`;function H(){t&&(D(t.text),T(!0))}function ee(){if(!t)return;let e=E.trim().toUpperCase();if(!e||e===t.text){T(!1);return}x.mutate({plateId:t.plateId,text:e},{onSettled:()=>{v.invalidateQueries({queryKey:pr}),T(!1)}})}return a(J,{open:!0,onOpenChange:e=>!e&&i(),children:e(Oe,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":h(`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||h(`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:[L&&e(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[e(Y,{variant:`unstyled`,type:`button`,onClick:()=>C(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${S===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(f,{className:`h-3.5 w-3.5`}),` `,h(`detectionIntelligence.detailPanel.fullFrame`)]}),e(Y,{variant:`unstyled`,type:`button`,onClick:()=>C(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${S===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[a(te,{className:`h-3.5 w-3.5`}),` `,h(`detectionIntelligence.detailPanel.crop`)]})]}),R&&O?a(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:a(pt,{src:O,alt:h(`detectionIntelligence.plateDetailPanel.fullFrameWithDetectedPlate`,`Full frame with detected plate`),fit:`natural`,className:`w-full`,overlay:I?a(_r,{box:I}):void 0})}):P?e(`div`,{className:`relative aspect-[2/1] w-full overflow-hidden rounded-lg border border-border bg-background`,children:[a(pt,{src:P,alt:h(`detectionIntelligence.plateDetailPanel.detectedPlate`,`Detected plate`),className:`h-full w-full`}),b&&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(_,{className:`h-8 w-8 text-warning/70`}),a(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:h(`detectionIntelligence.plateDetailPanel.noImage`,`No image`)}),a(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:h(`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:h(`detectionIntelligence.plateDetailPanel.plateText`,`Plate text`)}),w?e(`div`,{className:`flex min-w-0 flex-1 items-center justify-end gap-1.5`,children:[a(Ie,{value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`&&ee(),e.key===`Escape`&&T(!1)},className:`h-7 max-w-[10rem] text-right font-mono text-xs uppercase`,autoFocus:!0}),a(Y,{variant:`unstyled`,type:`button`,onClick:ee,disabled:x.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":h(`detectionIntelligence.plateDetailPanel.saveCorrectedText`,`Save corrected text`),children:x.isPending?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(M,{className:`h-3.5 w-3.5`})}),a(Y,{variant:`unstyled`,type:`button`,onClick:()=>T(!1),className:`text-foreground-subtle hover:text-foreground`,"aria-label":h(`common.cancel`,`Cancel`),children:a(m,{className:`h-3.5 w-3.5`})})]}):e(Y,{variant:`unstyled`,type:`button`,onClick:H,className:`group flex min-w-0 items-center gap-1.5`,title:h(`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(F,{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(gr,{label:h(`detectionIntelligence.plateDetailPanel.camera`,`Camera`),value:r}),a(gr,{label:h(`detectionIntelligence.plateDetailPanel.captured`,`Captured`),value:ft(t.timestamp)}),a(gr,{label:h(`detectionIntelligence.plateDetailPanel.confidence`,`Confidence`),value:V}),a(gr,{label:h(`detectionIntelligence.plateDetailPanel.vehicle`,`Vehicle`),value:B}),a(gr,{label:h(`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(Y,{variant:`secondary`,onClick:()=>u(t.plateId),disabled:p,children:[a(K,{className:`h-3.5 w-3.5`}),` `,h(`detectionIntelligence.detailPanel.detach`)]}):e(Y,{variant:`primary`,onClick:()=>c(t.plateId),disabled:p,children:[a(g,{className:`h-3.5 w-3.5`}),` `,h(`common.assign`)]}),e(Y,{variant:`secondary`,onClick:()=>d(t.plateId),disabled:p,children:[a(N,{className:`h-3.5 w-3.5`}),` `,h(`common.delete`)]})]})]})})}c();var yr=[[`plateGallery`]],br=500,xr=120;function Sr({plate:t,cameraName:n,nowMs:r,selected:i,onToggleSelect:o,onAssign:s,onOpenDetail:c}){let{t:u}=Z(),d=l(),f=ie(),p=Le(),m=()=>{d.invalidateQueries({queryKey:yr})},h=()=>c(t.plateId),v=ur(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:[v===null?e(`button`,{type:`button`,onClick:h,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:u(`detectionIntelligence.recentPlates.noCropImageThePlate`,`No crop image — the plate's crop media is missing. Safe to delete.`),children:[a(_,{className:`h-7 w-7 text-warning/70`}),a(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:u(`detectionIntelligence.recentPlates.noCrop`,`No crop`)})]}):a(`img`,{src:v,alt:u(`detectionIntelligence.recentPlates.plateFrom`,`Plate {{text}} from {{cameraName}}`,{text:t.text,cameraName:n}),onClick:h,className:`h-full w-full cursor-zoom-in object-cover`}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(t.plateId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?u(`detectionIntelligence.recentPlates.deselect`,`Deselect`):u(`detectionIntelligence.recentPlates.select`,`Select`),children:i?a(ne,{className:`h-4 w-4 text-primary`}):a(k,{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:u(`detectionIntelligence.recentPlates.manuallyCorrected`,`Manually corrected`),children:[a(W,{className:`h-3 w-3`}),` `,u(`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:dt(t.timestamp,r)}),t.vehicleName&&a(`p`,{className:`truncate text-[10px] font-medium text-primary`,title:t.vehicleName,children:t.vehicleName})]}),e(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[t.assigned?a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),f.mutate({plateId:t.plateId},{onSettled:m})},disabled:f.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":u(`detectionIntelligence.recentPlates.detachPlate`,`Detach plate`),title:u(`detectionIntelligence.recentPlates.detach`,`Detach`),children:f.isPending?a(z,{className:`h-4 w-4 animate-spin`}):a(K,{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":u(`detectionIntelligence.recentPlates.assignPlateToVehicle`,`Assign plate to vehicle`),title:u(`detectionIntelligence.recentPlates.assignToVehicle`,`Assign to vehicle`),children:a(g,{className:`h-4 w-4`})}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),p.mutate({plateId:t.plateId},{onSettled:m})},disabled:p.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":u(`detectionIntelligence.recentPlates.deletePlate`,`Delete plate`),title:u(`detectionIntelligence.recentPlates.deletePlate`,`Delete plate`),children:p.isPending?a(z,{className:`h-4 w-4 animate-spin`}):a(N,{className:`h-4 w-4`})})]})]})}var Cr=[{labelKey:`common.all`,value:`all`},{labelKey:`detectionIntelligence.recentPlates.filterUnassigned`,value:`unassigned`},{labelKey:`detectionIntelligence.recentPlates.filterAssigned`,value:`assigned`}];function wr(e,t){return t===`unassigned`?e.filter(e=>!e.assigned):t===`assigned`?e.filter(e=>e.assigned):e}function Tr(){let{t}=Z(),r=l(),[i,o]=s(`all`),[c,d]=s(_t),[f,p]=s(new Set),[h,v]=s(new Set),[y,b]=s(null),[x,S]=s(null),{data:C,isLoading:w}=Ye({limit:br,includeCrops:!1},{refetchInterval:3e4}),{data:T=[]}=Me(),{data:E}=pe({isCamera:!0,projection:`slim`}),D=ie(),O=Xe(),k=Le(),A=Date.now(),j=C??[],M=n(()=>{let e=new Map;for(let t of E??[])e.set(t.id,t.name);return e},[E]),P=e=>M.get(e)??t(`detectionIntelligence.cameraFallback`,{id:String(e)}),F=n(()=>bt(j).map(e=>({id:e,name:P(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[j,M]),I=n(()=>ut(mt(wr(j,i),c),f),[j,i,c,f]),L=gt(I,xr,n(()=>JSON.stringify([i,c.fromMs,c.toMs,[...f].sort((e,t)=>e-t)]),[i,c.fromMs,c.toMs,f])),R=n(()=>new Map(j.map(e=>[e.plateId,e])),[j]),B=x===null?null:R.get(x)??null,V=()=>{r.invalidateQueries({queryKey:yr})},H=()=>v(new Set);function ee(e){v(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,G=D.isPending||k.isPending;function te(){U.length!==0&&O.mutate({plateIds:U},{onSettled:()=>{V(),H()}})}function ne(){U.length!==0&&Promise.allSettled(U.map(e=>k.mutateAsync({plateId:e}))).then(()=>{V(),H()})}function re(e){S(null),b([e])}function q(e){D.mutate({plateId:e},{onSettled:V}),S(null)}function ae(e){k.mutate({plateId:e},{onSettled:V}),S(null)}let oe=I.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:Cr.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(lt,{onChange:d}),a(vt,{cameras:F,selected:f,onChange:p}),!w&&a(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:oe?t(`detectionIntelligence.recentPlates.ofPlates`,`{{value1}} of {{value2}} plates`,{value1:String(I.length),value2:String(j.length)}):t(`detectionIntelligence.recentPlates.plateCount`,{count:I.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(Y,{variant:`primary`,onClick:()=>b(U),disabled:W,children:[a(g,{className:`h-3.5 w-3.5`}),` `,t(`common.assign`)]}),e(Y,{variant:`secondary`,onClick:te,disabled:W,children:[O.isPending?a(z,{className:`h-3.5 w-3.5 animate-spin`}):a(K,{className:`h-3.5 w-3.5`}),` `,t(`detectionIntelligence.recentPlates.detach`,`Detach`)]}),e(Y,{variant:`secondary`,onClick:ne,disabled:W,children:[a(N,{className:`h-3.5 w-3.5`}),` `,t(`common.delete`)]}),a(Y,{variant:`ghost`,onClick:H,disabled:W,children:a(m,{className:`h-3.5 w-3.5`})})]})]}),w?a(qe,{status:`pending`,pendingMessage:`Loading plates…`,testId:`plates-grid`}):I.length===0?a(Ne,{icon:_,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(u,{children:[a(qe,{status:`ready`,testId:`plates-grid`,children:L.pageItems.map(e=>a(Sr,{plate:e,cameraName:P(e.deviceId),nowMs:A,selected:h.has(e.plateId),onToggleSelect:ee,onAssign:e=>b([e]),onOpenDetail:S},e.plateId))}),a(yt,{currentPage:L.page,totalItems:L.totalItems,pageSize:L.pageSize,onPageChange:L.setPage,itemNoun:`plates`})]}),a(vr,{plate:B,cameraName:B?P(B.deviceId):``,onClose:()=>S(null),onAssign:re,onUnassign:q,onDelete:ae,actionsPending:G}),a(fr,{plateIds:y,vehicles:T,onDone:()=>{b(null),H()}})]})}c();var Er=[[`plateGallery`]];function Dr({vehicleId:t}){let{t:n}=Z(),r=l(),{data:i,isLoading:o}=Qe({vehicleId:t}),s=Ze();function c(e){s.mutate({vehicleId:t,sampleId:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:Er})}})}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(S,{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(m,{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 Or(t){return[{key:`vehicle`,header:X.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(Lt,{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(S,{className:`h-4 w-4 text-foreground-subtle`})})})}),a(`span`,{className:`truncate text-sm font-medium text-foreground`,children:t.name})]})},{key:`samples`,header:X.t(`detectionIntelligence.vehiclesList.plates`,`Plates`),align:`center`,nowrap:!0,sortValue:e=>e.sampleCount,render:e=>a(ye,{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(je,{variant:`ghost`,size:`sm`,icon:F,"aria-label":X.t(`detectionIntelligence.vehiclesList.edit`,`Edit {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onEdit(n)}}),a(je,{variant:`ghost`,size:`sm`,icon:N,"aria-label":X.t(`detectionIntelligence.vehiclesList.delete`,`Delete {{name}}`,{name:n.name}),onClick:e=>{e.stopPropagation(),t.onDelete(n)}})]})}]}function kr({mode:t,vehicle:n,onClose:r}){let{t:i}=Z(),c=l(),[u,d]=s(t===`edit`?n?.name??``:``),f=ze(),p=we();o(()=>{d(t===`edit`?n?.name??``:``)},[t,n?.id,n?.name]);let m=f.isPending||p.isPending,h=u.trim(),g=t===`edit`&&n!==null&&h===n.name,_=m||h.length===0||g;function v(){c.invalidateQueries({queryKey:Er})}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(Ge,{open:!0,onClose:r,title:t===`new`?`Add vehicle`:`Edit ${n?.name??`vehicle`}`,icon:S,width:t===`edit`?`xl`:`lg`,testId:`vehicles-vehicle-form`,footer:e(Y,{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(Je,{label:i(`detectionIntelligence.vehiclesList.name`,`Name`),required:!0,children:a(Ie,{value:u,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(Dr,{vehicleId:n.id})]})]})})}function Ar(){let{t}=Z(),r=l(),i=x(),{data:s,isLoading:c}=Me(),u=Fe(),{state:d,openNew:f,openEdit:p,close:m}=Be(),h=s??[],g=Te(h,{searchText:e=>[e.name]}),_=d.mode===`edit`?h.find(e=>e.id===d.id)??null:null;o(()=>{d.mode===`edit`&&!c&&_===null&&m()},[d.mode,c,_,m]);let v=n(()=>Or({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`})&&u.mutate({id:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:Er}),d.mode===`edit`&&d.id===e.id&&m()}})})()}}),[i,m,u,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 y=d.mode===`new`||d.mode===`edit`&&_!==null;return e(`div`,{className:`space-y-2`,children:[a(`div`,{className:`flex flex-wrap items-center gap-2`,children:e(Y,{variant:`primary`,size:`sm`,type:`button`,onClick:f,children:[a(D,{className:`h-3.5 w-3.5`}),t(`detectionIntelligence.vehiclesList.addVehicle`,`Add vehicle`)]})}),(h.length>0||g.active)&&a(q,{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(Ne,{icon:S,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(Ce,{columns:v,rows:g.rows,rowKey:e=>e.id,maxBodyHeight:et,emptyMessage:t(`detectionIntelligence.vehiclesList.noVehiclesEnrolledYet2`,`No vehicles enrolled yet.`),onRowClick:e=>p(e.id)}),y&&a(kr,{mode:d.mode===`new`?`new`:`edit`,vehicle:_,onClose:m})]})}c();var jr=[[`plateGallery`]],Mr=2e3;function Nr(){let e=l(),n=t(e);n.current=e;let r=t(void 0);r.current||=ht({delayMs:Mr,invalidate:()=>{n.current.invalidateQueries({queryKey:jr})}}),o(()=>()=>r.current?.cancel(),[]),se(B.PipelineAnalyticsPlateGalleryChanged,()=>{r.current?.trigger()})}function Pr(){let{t}=Z();return Nr(),e(`div`,{className:`space-y-3`,children:[a(de,{headingId:`library-vehicles`,title:t(`plates.vehicles`,`Vehicles`),icon:S,testId:`library-section-vehicles`,children:e(`div`,{className:`${d} 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(Ar,{})]})}),a(de,{headingId:`library-recent-plates`,title:t(`plates.recentRecognizedPlates`,`Recent recognized plates`),icon:G,testId:`library-section-recent-plates`,children:e(`div`,{className:`${d} 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(Tr,{})]})})]})}function Fr(e){return e.states.length===0?3:e.latched?0:e.verdict===`diverged`?1:e.verdict===`unknown`?2:4}function Ir(e){let t=[e.divergedAt,e.restoredAt].filter(e=>typeof e==`number`);return t.length===0?null:Math.max(...t)}function Lr(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=Fr(e.monitor)-Fr(t.monitor);if(n!==0)return n;let r=Ir(e.monitor)??-1,i=Ir(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})}c();var Rr={alarm:`danger`,ok:`success`,unknown:`default`},zr={alarm:`Alarm`,ok:`OK`,unknown:`Unknown`};function Br(e,t){let n=Ir(e);return n===null?`—`:X.t(`scenes.transitionAgo`,{duration:P(Math.max(0,t-n))})}function Vr(e){return b(e.monitor).tone}function Hr(e){let t=Number(e);return Number.isFinite(t)&&t>0?t:null}function Ur(){let{t}=Z(),i=pe({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=Et(l),d=n(()=>Lr(c,u.results),[c,u.results]),f=Te(d,{searchText:e=>[e.monitor.label,e.deviceName],facetValue:Vr}),{state:p,openNew:m,openEdit:h,close:g}=Be(),[_,v]=s(null);o(()=>{if(p.mode===`new`){v(e=>e??l[0]??null);return}v(null)},[p.mode,l]);let y=p.mode===`edit`?Hr(p.id):null,x=y===null?``:c.find(e=>e.deviceId===y)?.deviceName??`#${y}`,S=Date.now(),E=[{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=>Vr(e),render:e=>{let t=b(e.monitor);return a(ye,{variant:Rr[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:C(e.monitor,S)})},{key:`coverage`,header:t(`scenes.variants`,`Variants`),notSortableReason:`Coverage is a summary string`,render:e=>a(`span`,{className:`text-xs text-foreground-muted`,children:O(e.monitor)})},{key:`transition`,header:t(`scenes.lastChange`,`Last change`),align:`right`,nowrap:!0,sortValue:e=>Ir(e.monitor)??0,render:e=>a(`span`,{className:`text-xs tabular-nums text-foreground-muted`,children:Br(e.monitor,S)})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:e=>a(Y,{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(Y,{onClick:m,disabled:c.length===0,className:`shrink-0`,children:[a(D,{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(q,{state:f.state,facets:f.facets,labels:{searchPlaceholder:`Search scenes…`,searchLabel:`Search scenes`,facetsLabel:`State`,clearLabel:`Clear`},facetLabel:e=>zr[e]??e,onSearch:f.setSearch,onToggleFacet:f.toggleFacet,onClear:f.clear}),a(We,{variant:`flat`,className:`p-0`,children:a(Ce,{columns:E,rows:f.rows,rowKey:e=>`${e.deviceId}:${e.monitor.id}`,minWidthPx:880,bordered:!1,maxBodyHeight:et,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(Ge,{open:!0,onClose:g,title:t(`scenes.whichCamera`,`Which camera?`),icon:w,width:`sm`,testId:`scenes-camera-picker`,footer:a(Y,{onClick:()=>{_!==null&&h(String(_))},disabled:_===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(T,{value:_===null?``:String(_),onChange:e=>v(Number(e.target.value)),"aria-label":t(`scenes.camera`,`Camera`),options:c.map(e=>({value:String(e.deviceId),label:e.deviceName}))})]}):null,y===null?null:e(Ge,{open:!0,onClose:g,title:t(`scenes.scenes`,`Scenes — {{editingName}}`,{editingName:x}),icon:w,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(Ke,{deviceId:y})})]})]})}function Wr(){let{t:e}=Z(),t=nt(`/library`,{t:e,isAdmin:!0})??{icon:V,title:e(`nav.library`,`Library`)};return a(ct,{icon:t.icon,title:t.title,subtitle:e(`library.subtitleWithExports`,`People, vehicles, scenes and exports — what detection has recognised, and the clips you rendered.`),defaultSection:`people`,sectionsLabel:`${t.title} sections`,sections:[{id:`people`,label:e(`library.people`,`People`),content:a(lr,{})},{id:`vehicles`,label:e(`library.vehicles`,`Vehicles`),content:a(Pr,{})},{id:`scenes`,label:e(`library.scenes`,`Scenes`),content:a(Ur,{})},{id:`exports`,label:e(`library.exports`,`Exports`),content:a(It,{}),ownedParams:[rt]}]})}export{Wr as LibraryPage};
@@ -0,0 +1,3 @@
1
+ import{C as e,K as t,S as n,V as r,Y as i,et as a,o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Fa as c,Hr as l,Nr as u,O as d,Tt as f,V as p,Yn as m,Za as h,aa as g,ct as _,ft as v,ir as y,k as b,tn as x,ur as S,z as C}from"./player-overlays-ugkkFXtV.js";import{Bn as w,Rs as T,pc as E}from"./client-B3h-2G71.js";import{t as D}from"./chevron-down-CBb-F8DT.js";import{$s as O,An as k,Cs as A,Dr as ee,Fa as j,Hi as M,Ip as N,Ji as P,Js as te,Ki as ne,La as F,M as I,Oa as L,Pa as R,Qs as re,Rr as z,Tr as B,Ui as V,Va as ie,Wi as H,_p as ae,ba as oe,bs as se,cc as ce,cp as U,ec as le,gc as ue,gp as W,hc as de,hi as fe,lc as pe,mc as me,mi as he,nc as ge,pc as _e,qi as ve,sc as ye,ua as G,uc as be,vp as xe,vs as Se,xc as Ce,ys as we}from"./src-DeDx2fDl.js";import{t as K}from"./i18n-BwW8nRaE.js";import{t as q}from"./useTranslation-BJr-n0es.js";import{Si as Te,_i as J,bi as Ee,v as Y}from"./index-D_vdUQKv.js";import{t as De}from"./AdminSectionedPage-3Jh0qbF0.js";import{c as X,n as Oe,r as ke}from"./linked-devices-model-CI7wpAm-.js";a();function Z(e){return{id:e.id,name:e.name,type:e.type,stableId:e.stableId??``,parentDeviceId:e.parentDeviceId,location:e.location,...e.role!==void 0&&e.role!==null?{role:e.role}:{},...e.primaryChildEntityId!==void 0&&e.primaryChildEntityId!==null?{primaryChildEntityId:e.primaryChildEntityId}:{},...e.primaryChildPreference!==void 0&&e.primaryChildPreference!==null?{primaryChildPreference:e.primaryChildPreference}:{}}}function Q(e){if(e==null)return null;let t=e.trim();return t.length===0?null:t.toLowerCase()}function Ae(e,t){let n=Q(t);return n===null?[]:e.filter(e=>Q(e.location)===n)}function je(e,t){let n=Ae(e,t),r=new Set(n.map(e=>e.id));return n.filter(e=>e.parentDeviceId===null||!r.has(e.parentDeviceId))}function Me(e,t){let n=Q(e.location);return n===null||new Set(t.map(e=>Q(e))).has(n)?null:e.location?.trim()??null}function Ne(e,t){let n=Q(e.location);return n!==null&&t.has(n)}function Pe(e,t){let n=new Set(t.map(e=>Q(e))),r=new Set(e.filter(e=>Ne(e,n)).map(e=>e.id));return e.filter(e=>!(Ne(e,n)||e.parentDeviceId!==null&&r.has(e.parentDeviceId)))}function Fe(e,t){return Pe(e,t).filter(e=>e.parentDeviceId===null)}function Ie(e,t){let n=new Map;for(let t of e){if(t.parentDeviceId===null)continue;let e=n.get(t.parentDeviceId);e?e.push(t):n.set(t.parentDeviceId,[t])}let r=[],i=new Set([t]),a=[t];for(;a.length>0;){let e=[];for(let t of a)for(let a of n.get(t)??[])i.has(a.id)||(i.add(a.id),r.push(a),e.push(a.id));a=e}return r}function Le(e,t){return Ie(e,t).length}function Re(e,t){return e.filter(e=>!e.isCamera&&e.parentDeviceId===t)}function ze(e,t){return t.map(t=>({name:t,members:je(e,t)}))}function $({type:e,role:t,className:r}){return n(N(e,t),{"aria-hidden":`true`,className:r??`h-3.5 w-3.5 shrink-0 text-foreground-subtle`})}function Be({device:t}){let r=j(Z(t),`compact`);if(t.online)return n(`span`,{"aria-hidden":`true`,className:`inline-block h-1.5 w-1.5 shrink-0 rounded-full bg-success`,"data-status":`online`});let i=K.t(`common.offline`);return e(`span`,{className:`flex items-center gap-1.5`,children:[n(`span`,{className:`inline-block h-1.5 w-1.5 shrink-0 rounded-full border border-foreground-subtle`,"data-status":`offline`,role:`img`,"aria-label":K.t(`locations.deviceGlyphs.aria`,{name:r,state:i}),title:i}),n(`span`,{className:`text-xs text-foreground-muted`,children:i})]})}function Ve({open:t,title:a,items:o,listState:s,lockedIds:c,lockedNote:l,suggestions:u=null,busy:d=!1,onConfirm:f,onClose:p}){let{t:m}=q(),[h,g]=i([]);r(()=>{t||g([])},[t]);let _=new Map(o.map(e=>[e.id,e.name])),v=(u?.ids??[]).filter(e=>_.has(e)&&!c.includes(e)),y=e=>g(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]);return n(M,{open:t,onOpenChange:e=>e?void 0:p(),children:e(H,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":a,children:[n(ve,{children:n(P,{children:a})}),e(V,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:[t&&u!==null&&v.length>0&&e(`section`,{"aria-label":u.heading,className:`flex flex-col gap-1`,children:[n(`h3`,{className:`text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:u.heading}),n(`div`,{className:`flex flex-wrap gap-1`,children:v.map(e=>n(`button`,{type:`button`,"aria-pressed":h.includes(e),className:`inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${h.includes(e)?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:bg-surface-hover`}`,onClick:()=>y(e),children:_.get(e)},e))})]}),t&&n(I,{devices:o,listState:s,value:h,onChange:e=>g(e),noun:`device`,emptyLabel:m(`locations.addDialog.nonePicked`),showAll:!0,lockedIds:c,lockedNote:l,testId:`quick-add-picker`})]}),e(ne,{children:[n(U,{variant:`ghost`,onClick:p,children:m(`locations.addDialog.cancel`)}),n(U,{disabled:h.length===0||d,onClick:()=>f(h),children:m(`locations.addDialog.confirm`,{count:h.length})})]})]})})}a();function He({room:e,cameras:r,fleet:i}){let{t:a}=q(),o=t(()=>new Map(i.map(e=>[e.id,e])),[i]);return e===null?n(`p`,{className:`text-xs text-foreground-subtle`,children:a(`locations.links.noRoom`)}):n(`div`,{className:`flex flex-col gap-3`,"data-testid":`camera-links-section`,children:r.length===0?n(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`camera-links-empty`,children:a(`locations.links.noCameras`,{room:e})}):r.map(e=>n(We,{camera:e,byId:o},e.id))})}function Ue(e){return{id:e.deviceId,name:e.name,type:e.type,location:e.location}}function We({camera:t,byId:r}){let{t:a}=q(),s=j(Z(t),`full`),c=o(),u=Ee(),[f,p]=i(!1),[m,h]=i(null),g=we({deviceId:t.id}),_=ke({status:g.status,data:g.data,error:g.error===null||g.error===void 0?null:g.error}),v=se(),y=_.kind===`present`?_:null,x=Se({deviceId:t.id,slotRef:y?.slot.slotRef??``},{enabled:f&&y!==null}),S=y===null?[]:Oe(y.slot,y.value),C=S.map(e=>e.deviceId),w=(x.data?.candidates??[]).map(Ue),T=new Set(w.map(e=>e.id)),E=C.filter(e=>!T.has(e)).map(e=>{let t=r.get(e);return{id:e,name:t?.name??`#${String(e)}`,...t===void 0?{}:{type:t.type,location:t.location}}}),D=[...w,...E],O=(x.data?.candidates??[]).filter(e=>e.suggested).map(e=>e.deviceId),k=async e=>{if(y!==null){h(null);try{await v.mutateAsync({deviceId:t.id,slotRef:y.slot.slotRef,value:X(y.value,e)}),await g.refetch(),await c.invalidateQueries({queryKey:[[`deviceManager`]]}),p(!1)}catch(e){h(e instanceof Error?e.message:String(e))}}},A=[{key:`device`,header:a(`locations.columns.device`),notSortableReason:a(`locations.columns.noSort`),render:t=>{let i=r.get(t.deviceId),o=t.name??i?.name??`#${String(t.deviceId)}`;return e(`span`,{className:`flex items-center gap-1.5`,children:[i!==void 0&&n($,{type:i.type,role:i.role}),n(J,{to:`/devices/${String(t.deviceId)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:i===void 0?o:n(G,{device:Z(i),form:`compact`})}),t.implied&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:a(`locations.links.implied`)})]})}},{key:`type`,header:a(`locations.columns.type`),notSortableReason:a(`locations.columns.noSort`),render:e=>n(`span`,{className:`text-xs text-foreground-muted`,children:r.get(e.deviceId)?.type??`—`})},{key:`status`,header:a(`locations.columns.status`),notSortableReason:a(`locations.columns.noSort`),render:e=>{let t=r.get(e.deviceId);return t===void 0?n(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):n(Be,{device:t})}}];return e(`section`,{className:`min-w-0 ${d}`,"data-testid":`camera-links-${String(t.id)}`,children:[e(`header`,{className:`${b} flex min-h-9 items-center gap-1.5`,children:[n($,{type:t.type,role:t.role}),n(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:n(G,{device:Z(t),form:`full`})}),e(U,{variant:`ghost`,size:`sm`,onClick:()=>u(Y(t.id)),children:[n(l,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),a(`locations.links.edit`)]}),n(U,{variant:`outline`,size:`sm`,disabled:y===null,onClick:()=>p(!0),"aria-label":a(`locations.links.addNamed`,{camera:s}),children:a(`locations.room.add`)})]}),_.kind===`pending`&&n(`p`,{role:`status`,className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:a(`locations.links.loading`)}),_.kind===`unknown`&&n(`p`,{role:`alert`,className:`px-3 py-3 text-xs text-warning sm:px-4`,children:a(`locations.links.unreadable`,{reason:_.reason})}),_.kind===`absent`&&n(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:a(`locations.links.unsupported`)}),m!==null&&n(`p`,{role:`alert`,className:`px-3 pt-2 text-xs text-danger break-words sm:px-4`,children:m}),y!==null&&(S.length===0?n(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:a(`locations.links.none`)}):n(z,{columns:A,rows:S,rowKey:e=>String(e.deviceId),bordered:!1,minWidthPx:360})),n(Ve,{open:f,title:a(`locations.links.pickTitle`,{camera:s}),items:D,listState:x.status===`error`?`failed`:x.data===void 0?`pending`:`answered`,lockedIds:C,lockedNote:a(`locations.links.alreadyLinked`),suggestions:t.location===null?null:{heading:a(`locations.links.suggested`,{room:t.location}),ids:O},busy:v.isPending,onConfirm:e=>void k(e),onClose:()=>p(!1)})]})}a();function Ge({name:t,description:a,busy:o,onSave:s}){let{t:c}=q(),[l,u]=i(a??``);return r(()=>{u(a??``)},[a]),e(`div`,{className:`border-t border-border px-3 py-2 sm:px-4`,children:[n(fe,{htmlFor:`location-description-${t}`,className:`block`,children:c(`locations.locationDescriptionField.whatIsThere`,`What is there`)}),n(he,{id:`location-description-${t}`,value:l,onChange:e=>u(e.target.value),onBlur:()=>{let e=l.trim();e!==(a??``)&&s(e.length===0?null:e)},disabled:o,rows:2,maxLength:400,placeholder:c(`locations.locationDescriptionField.surfacesBoundariesWhatIsNormally`,`Surfaces, boundaries, what is normally parked or stored here.`),className:`mt-1 w-full resize-y rounded-md border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-inset focus:ring-primary disabled:cursor-not-allowed disabled:opacity-50`}),n(`p`,{className:`mt-1 ${C}`,children:c(`locations.locationDescriptionField.givenToTheAiWith`,`Given to the AI with the pictures, so it knows what it is looking at. Describe the PLACE, not what happens in it — events change, the ground does not.`)})]})}function Ke(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0||n.description.length===0?null:n.description}var qe=` none`;function Je({name:t,zones:r,zoneKey:i,busy:a,onChange:o}){let{t:s}=q();if(r.length===0)return null;let c=[{value:qe,label:s(`locations.locationZoneField.none`,`— none —`)},...r.map(e=>({value:e.zoneKey,label:e.label}))];return e(`div`,{className:`flex items-center gap-2 border-t border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:[n(fe,{htmlFor:`location-zone-${t}`,children:s(`locations.locationZoneField.zone`,`Zone`)}),n(v,{id:`location-zone-${t}`,value:i??qe,disabled:a,onChange:e=>{let t=e.target.value;if(t===qe){o(null);return}let n=r.find(e=>e.zoneKey===t);n!==void 0&&o(n.label)},options:c})]})}function Ye(e,t){return e.find(e=>e.locationKeys.includes(t))?.zoneKey??null}function Xe({name:e,icon:t,busy:r,onPick:i}){return n(xe,{value:t,onPick:i,fallbackGlyph:u,clearGlyph:c,labels:{trigger:`Change the icon of ${e}`,panel:`Icon for ${e}`,searchPlaceholder:`Search icons`,clear:`No icon`,noMatches:`No icon matches that`},disabled:r})}function Ze(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0?null:E(n.icon)??`map-pin`}function Qe(e){return`${e.kind}:${String(e.device.id)}`}function $e(e,t,n){return e.flatMap(e=>{let r=Re(t,e.id),i=n.has(e.id),a={kind:`member`,device:e,accessories:r,open:i};return!i||r.length===0?[a]:[a,...r.map(t=>({kind:`accessory`,device:t,parent:e}))]})}a();function et({name:r,members:a,devices:o,busy:c,icon:l,description:u,onRename:p,onDelete:h,onRebuildLinks:g,onAddDevices:_,onPickIcon:v,onSaveDescription:y,zones:C,zoneKey:w,onChangeZone:T}){let{t:E}=q(),[D,O]=i(!1),[A,j]=i(r),M=B(a,t(()=>({searchText:e=>[e.name,...Re(o,e.id).map(e=>e.name)],facetValue:e=>e.type}),[o])),[N,P]=i(()=>new Set),te=e=>P(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),ne=t(()=>$e(M.rows,o,N),[M.rows,o,N]),F=[{key:`name`,header:E(`locations.columns.device`),notSortableReason:E(`locations.columns.noSort`),render:e=>e.kind===`member`?n(tt,{row:e,onToggle:()=>te(e.device.id)}):n(nt,{row:e})},{key:`type`,header:E(`locations.columns.type`),notSortableReason:E(`locations.columns.noSort`),render:e=>n(`span`,{className:`text-xs text-foreground-muted`,children:e.device.type})},{key:`status`,header:E(`locations.columns.status`),notSortableReason:E(`locations.columns.noSort`),render:e=>n(Be,{device:e.device})}],I=()=>{j(r),O(!1)},L=async()=>{let e=A.trim();if(e.length===0||e===r){I();return}await p(e),O(!1)},R=[{id:`rename`,label:E(`locations.locationCard.rename`,`Rename`),icon:S,disabled:c,onClick:()=>{j(r),O(!0)}},{id:`rebuild-links`,label:E(`locations.locationCard.rebuildLinkedDevices`,`Rebuild linked devices`),icon:m,separatorBefore:!0,disabled:c,onClick:()=>void g()},{id:`delete`,label:E(`common.delete`,`Delete`),icon:x,danger:!0,separatorBefore:!0,disabled:c,onClick:()=>void h()}];return e(`section`,{className:`min-w-0 ${d}`,children:[e(`header`,{className:`${b} flex min-h-9 items-center gap-1.5`,children:[n(Xe,{name:r,icon:l,busy:c,onPick:v}),D?e(s,{children:[n(W,{value:A,onChange:e=>j(e.target.value),onKeyDown:e=>{e.key===`Enter`&&L(),e.key===`Escape`&&I()},"aria-label":E(`locations.locationCard.rename2`,`Rename {{name}}`,{name:r}),className:`min-w-0 flex-1`,autoFocus:!0}),n(U,{type:`button`,size:`sm`,onClick:()=>void L(),children:E(`common.save`,`Save`)}),n(ae,{type:`button`,variant:`ghost`,icon:f,onClick:I,"aria-label":E(`locations.locationCard.cancelRename`,`Cancel rename`)})]}):e(s,{children:[n(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:r}),n(U,{type:`button`,variant:`outline`,size:`sm`,disabled:c,onClick:_,"aria-label":E(`locations.room.addTo`,{room:r}),children:E(`locations.room.add`)}),n(k,{items:R,title:E(`locations.locationCard.actionsFor`,`Actions for {{name}}`,{name:r}),triggerClassName:`p-1`})]})]}),n(Je,{name:r,zones:C,zoneKey:w,busy:c,onChange:T}),n(Ge,{name:r,description:u,busy:c,onSave:y}),a.length>0&&n(`div`,{className:`border-b border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:n(ee,{state:M.state,facets:M.facets,labels:{searchPlaceholder:E(`locations.filter.searchPlaceholder`),searchLabel:E(`locations.room.searchLabel`,{room:r}),facetsLabel:E(`locations.filter.typesLabel`),clearLabel:E(`locations.filter.clear`)},onSearch:M.setSearch,onToggleFacet:M.toggleFacet,onClear:M.clear})}),a.length===0?n(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:E(`locations.locationCard.nothingHereYetAssignA`,`Nothing here yet — assign a device from the table below.`)}):n(z,{columns:F,rows:ne,rowKey:Qe,bordered:!1,minWidthPx:360,emptyMessage:E(`locations.filter.noMatch`)})]})}function tt({row:t,onToggle:r}){let{t:i}=q(),{device:a,accessories:o,open:s}=t,c=j(Z(a),`compact`),l=s?D:g;return e(`span`,{className:`flex items-center gap-1.5`,children:[o.length>0?e(U,{type:`button`,variant:`ghost`,onClick:r,"aria-expanded":s,"aria-label":i(s?`locations.locationCard.collapseAccessories`:`locations.locationCard.expandAccessories`,{count:o.length,name:c}),className:`h-auto shrink-0 gap-0.5 p-0.5 text-foreground-subtle hover:text-foreground`,children:[n(l,{className:`h-3 w-3`}),n(`span`,{className:`text-[10px] tabular-nums`,children:o.length})]}):n(`span`,{"aria-hidden":`true`,className:`w-[1.35rem] shrink-0`}),n($,{type:a.type,role:a.role}),n(J,{to:`/devices/${String(a.id)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:n(G,{device:Z(a),form:`compact`})})]})}function nt({row:t}){let{device:r,parent:i}=t;return e(`span`,{className:`flex items-center gap-1.5 pl-6`,children:[n(`span`,{"aria-hidden":`true`,className:`text-[10px] text-foreground-subtle`,children:`└`}),n($,{type:r.type,role:r.role,className:`h-3 w-3 shrink-0 text-foreground-subtle`}),n(J,{to:`/devices/${String(r.id)}`,className:`min-w-0 truncate text-xs text-foreground-muted hover:underline`,children:n(G,{device:Z(r),form:`nested`,parent:Z(i)})})]})}a();function rt({zones:e,busy:t,onRename:r,onDelete:a,onPickIcon:o}){let{t:s}=q(),[c,l]=i(null),[u,d]=i(``),f=async e=>{let t=u.trim();l(null),!(t.length===0||t===e)&&await r(e,t)};return n(z,{columns:[{key:`icon`,header:s(`locations.siteZonesPanel.icon`,`Icon`),width:`w-12`,notSortableReason:`An icon has no order`,render:e=>n(Xe,{name:e.label,icon:e.icon,busy:t,onPick:t=>o(e.label,t)})},{key:`name`,header:s(`locations.siteZonesPanel.zone`,`Zone`),sortValue:e=>e.label.toLowerCase(),render:e=>c===e.label?n(W,{value:u,onChange:e=>d(e.target.value),onKeyDown:t=>{t.key===`Enter`&&f(e.label),t.key===`Escape`&&l(null)},onBlur:()=>void f(e.label),"aria-label":s(`locations.siteZonesPanel.rename`,`Rename {{label}}`,{label:e.label}),autoFocus:!0}):n(U,{type:`button`,variant:`ghost`,size:`sm`,className:`px-0`,onClick:()=>{d(e.label),l(e.label)},disabled:t,title:s(`locations.siteZonesPanel.renameTheZone`,`Rename the zone`),children:e.label})},{key:`rooms`,header:s(`locations.siteZonesPanel.rooms`,`Rooms`),align:`right`,sortValue:e=>e.locationKeys.length,render:e=>n(`span`,{className:`tabular-nums text-foreground-subtle`,children:e.locationKeys.length===0?s(`common.empty`):s(`common.rooms`,{count:e.locationKeys.length})})},{key:`actions`,header:s(`locations.siteZonesPanel.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order`,render:e=>n(U,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void a(e.label),disabled:t,"aria-label":s(`locations.siteZonesPanel.delete`,`Delete {{label}}`,{label:e.label}),title:s(`locations.siteZonesPanel.deleteTheZoneTheRooms`,`Delete the zone — the rooms in it are kept`),children:n(x,{className:`h-3.5 w-3.5`})})}],rows:e,rowKey:e=>e.zoneKey,emptyMessage:s(`locations.siteZonesPanel.noZonesYetAZone`,`No zones yet. A zone groups rooms — “Night zone” for the bedrooms — and shows up before them in the app’s camera filter.`)})}a();function it({busy:t,onCreate:r}){let{t:a}=q(),[o,s]=i(!1),[c,l]=i(``),u=()=>{l(``),s(!1)},d=async()=>{let e=c.trim();e.length!==0&&(await r(e),u())};return o?e(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),d()},children:[n(W,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&u()},placeholder:a(`locations.newLocationButton.frontDoorHallKitchen`,`Front door, Hall, Kitchen…`),"aria-label":a(`locations.newLocationButton.newLocationName`,`New location name`),className:`min-w-[12rem] flex-1`,autoFocus:!0}),e(U,{size:`sm`,type:`submit`,disabled:c.trim().length===0||t,children:[n(y,{className:`h-3.5 w-3.5`}),a(`common.add`,`Add`)]}),n(U,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":a(`locations.newLocationButton.cancelNewLocation`,`Cancel new location`),children:n(f,{className:`h-3.5 w-3.5`})})]}):e(U,{size:`sm`,type:`button`,onClick:()=>s(!0),"data-testid":`new-location-button`,children:[n(y,{className:`h-3.5 w-3.5`}),a(`locations.newLocationButton.newLocation`,`New location`)]})}a();function at({busy:t,onCreate:r}){let{t:a}=q(),[o,s]=i(!1),[c,l]=i(``),u=()=>{l(``),s(!1)},d=async()=>{let e=c.trim();e.length!==0&&(await r(e),u())};return o?e(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),d()},children:[n(W,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&u()},placeholder:a(`locations.newZoneButton.zonaGiornoZonaNotte`,`Zona giorno, Night zone…`),"aria-label":a(`locations.newZoneButton.newZoneName`,`New zone name`),className:`min-w-[12rem] flex-1`,autoFocus:!0}),e(U,{size:`sm`,type:`submit`,disabled:c.trim().length===0||t,children:[n(y,{className:`h-3.5 w-3.5`}),a(`common.add`,`Add`)]}),n(U,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":a(`locations.newZoneButton.cancelNewZone`,`Cancel new zone`),children:n(f,{className:`h-3.5 w-3.5`})})]}):e(U,{size:`sm`,type:`button`,onClick:()=>s(!0),"data-testid":`new-zone-button`,children:[n(y,{className:`h-3.5 w-3.5`}),a(`locations.newZoneButton.newZone`,`New zone`)]})}a();function ot(e,t,n,r){let i=e.map(e=>({value:e.name,label:`${e.name} · ${String(e.count)}`}));return t===void 0?i:[...i,{value:n,label:`${r} · ${String(t)}`}]}function st({rooms:e,unassignedCount:r,value:i,unassignedValue:a,onChange:o}){let{t:s}=q(),c=t(()=>ot(e,r,a,s(`locations.roomPicker.unassigned`)),[e,r,a,s]);return n(`div`,{className:`max-w-sm`,"data-testid":`room-select`,children:n(oe,{mode:`single`,singleDisplay:`field`,label:s(`locations.roomPicker.label`),placeholder:s(`locations.roomPicker.placeholder`),options:c,value:i,onChange:o,searchable:!0,testId:`room-select-control`,optionTestIdPrefix:`room-option`})})}a();var ct={searchText:e=>[e.name],facetValue:e=>e.type};function lt({rows:r,fleet:a,locations:o,busy:s,emptyMessage:c,onAssign:l}){let{t:u}=q(),d=ie(),f=F(),m=e=>d===null?e.name:R(Z(e),`compact`,d,f),[g,_]=i([]),[y,b]=i(``),x=B(r,ct),S=x.rows,w=t(()=>S.map(e=>e.id),[S]),T=t(()=>g.filter(e=>w.includes(e)),[g,w]),E=S.length>0&&T.length===S.length,D=t(()=>{let e=new Map;for(let t of r)e.set(t.id,Le(a,t.id));return e},[r,a]),O=T.reduce((e,t)=>e+(D.get(t)??0),0),k=e=>_(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),A=()=>_(E?[]:w),j=()=>{y.length===0||T.length===0||(l(T,y),_([]),b(``))},M=o.map(e=>({value:e,label:e})),N=[{key:`select`,width:`w-8`,headerRender:()=>n(h,{checked:E,onChange:A,"aria-label":E?u(`locations.unassignedTable.clearSelection`,`Clear selection`):u(`locations.unassignedTable.selectAllUnassignedDevices`,`Select all unassigned devices`)}),render:e=>n(h,{checked:T.includes(e.id),onChange:()=>k(e.id),"aria-label":u(`locations.unassignedTable.select`,`Select {{name}}`,{name:m(e)})})},{key:`name`,header:u(`locations.unassignedTable.device`,`Device`),sortValue:e=>e.name.toLowerCase(),render:t=>{let r=Me(t,o);return e(`span`,{className:`flex items-center gap-1.5`,children:[n($,{type:t.type,role:t.role}),n(J,{to:`/devices/${String(t.id)}`,className:`truncate text-xs text-foreground hover:underline`,children:n(G,{device:Z(t),form:`compact`})}),r!==null&&n(L,{variant:`warning`,children:u(`locations.unassignedTable.unknownRoom`,{room:r})})]})}},{key:`type`,header:u(`locations.unassignedTable.type`,`Type`),sortValue:e=>e.type,render:e=>n(`span`,{className:`text-xs text-foreground-muted`,children:e.type})},{key:`status`,header:u(`locations.unassignedTable.status`,`Status`),sortValue:e=>+!!e.online,render:e=>n(Be,{device:e})},{key:`followers`,header:u(`locations.unassignedTable.accessoriesInTowCount`,`Accessories in tow`),align:`right`,sortValue:e=>D.get(e.id)??0,render:e=>n(`span`,{className:`tabular-nums text-xs text-foreground-muted`,children:D.get(e.id)??0})},{key:`assign`,header:u(`locations.unassignedTable.assignTo`,`Assign to`),align:`right`,notSortableReason:`This column is a control, not a value.`,render:e=>n(v,{"aria-label":u(`locations.unassignedTable.locationFor`,`Location for {{name}}`,{name:m(e)}),value:``,disabled:s||o.length===0,onChange:t=>{let n=t.target.value;n.length!==0&&l([e.id],n)},className:`max-w-[11rem]`,options:[{value:``,label:`—`},...M]})}];return e(`section`,{className:`space-y-2`,children:[e(`header`,{className:`flex flex-wrap items-baseline gap-2`,children:[n(`h2`,{className:p,children:u(`locations.unassignedTable.notInARoom`,`Not in a room`)}),n(`p`,{className:C,children:u(`locations.unassignedTable.topLevelDevicesOnlyAccessories`,`Top-level devices only — accessories move with their parent.`)})]}),r.length>0&&n(ee,{state:x.state,facets:x.facets,labels:{searchPlaceholder:u(`locations.filter.searchPlaceholder`),searchLabel:u(`locations.unassigned.searchLabel`),facetsLabel:u(`locations.filter.typesLabel`),clearLabel:u(`locations.filter.clear`)},onSearch:x.setSearch,onToggleFacet:x.toggleFacet,onClear:x.clear}),T.length>0&&e(`div`,{role:`group`,"aria-label":u(`locations.unassignedTable.bulkAssignment`,`Bulk assignment`),className:`flex flex-wrap items-center gap-2 rounded border border-primary/40 bg-primary/5 px-2 py-1.5`,children:[e(`span`,{className:`text-xs text-foreground`,children:[u(`locations.unassignedTable.selected`,{count:T.length}),O>0&&` · ${u(`locations.unassignedTable.accessoriesInTowCount`,{count:O})}`]}),n(v,{"aria-label":u(`locations.unassignedTable.assignSelectedDevicesTo`,`Assign selected devices to`),value:y,onChange:e=>b(e.target.value),className:`w-auto min-w-[10rem]`,options:[{value:``,label:u(`locations.unassignedTable.assignTo2`,`Assign to…`)},...M]}),n(U,{type:`button`,size:`sm`,onClick:j,disabled:s||y.length===0,children:u(`locations.unassignedTable.assign`,`Assign`)}),n(U,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>_([]),children:u(`locations.unassignedTable.clear`,`Clear`)})]}),n(z,{columns:N,rows:S,rowKey:e=>e.id,minWidthPx:720,emptyMessage:x.active?u(`locations.filter.noMatch`):c})]})}function ut(e){return{id:e.id,parentDeviceId:e.parentDeviceId,location:e.location,type:e.type,stableId:e.stableId??``,...e.primaryChildEntityId===void 0?{}:{primaryChildEntityId:e.primaryChildEntityId},...e.primaryChildPreference===void 0?{}:{primaryChildPreference:e.primaryChildPreference},...e.role!==void 0&&e.role!==null?{role:e.role}:{},name:e.name}}function dt(e,t){let n=t.map(ut),r=[];for(let i of t)i.isCamera&&i.location===e&&r.push({deviceId:i.id,name:i.name,ids:w({selfId:i.id,selfLocation:i.location,candidates:n})});return{entries:r}}var ft=`device-manager:linked-devices`;function pt(e){return{deviceId:e.deviceId,slotRef:ft,value:{slot:`linked-devices`,deviceIds:[...e.ids]}}}a();var mt=`__unassigned__`;function ht(){let{t:r}=q(),a=o(),s=_(),{data:c,isLoading:l}=le(),{data:d}=O(),{data:f}=re(),{data:p}=ge(),{data:m,isLoading:h}=te({projection:`slim`}),g=()=>{a.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listLocationIcons`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listLocationDescriptions`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listSiteZones`]]})},v=A({onSuccess:g}),y=ye({onSuccess:g}),b=_e({onSuccess:g}),x=pe({onSuccess:g}),S=de({onSuccess:g}),C=me({onSuccess:g}),w=Ce({onSuccess:g}),E=ce({onSuccess:g}),D=be({onSuccess:g}),k=ue({onSuccess:g}),ee=se(),j=t(()=>(m??[]).map(e=>({id:e.id,name:e.name,location:e.location??null,type:String(e.type),isCamera:e.isCamera,parentDeviceId:e.parentDeviceId,online:e.online,role:e.role??null,stableId:e.stableId,primaryChildEntityId:e.primaryChildEntityId??null,primaryChildPreference:e.primaryChildPreference??null})),[m]),M=c??[],N=t(()=>ze(j,M),[j,M]),[P,ne]=Te(),F=P.get(`tab`),I=F===`zones`||F===`camera-links`?F:`locations`,L=P.get(`room`),R=t(()=>Fe(j,M),[j,M]),z=L===mt,B=z?null:L!==null&&N.some(e=>e.name===L)?L:N[0]?.name??null,V=B===null?null:N.find(e=>e.name===B)??null,ie=z?mt:B??`__unassigned__`,H=B??N[0]?.name??null,ae=t(()=>N.map(e=>({name:e.name,count:e.members.length})),[N]),oe=e=>{ne(t=>{let n=new URLSearchParams(t);return n.set(`room`,e),n},{replace:!0})},U=l||h,W=b.isPending||y.isPending||v.isPending||S.isPending,fe=async e=>{await v.mutateAsync({name:e})},he=async(e,t)=>{let n=t.trim();n.length===0||n===e||await x.mutateAsync({from:e,to:n})},ve=async e=>{let t=dt(e,j);if(t.entries.length===0){await s({title:r(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:r(`locations.noCameraIsAssignedTo`,`No camera is assigned to “{{room}}”.`,{room:e}),confirmLabel:`OK`});return}let n=t.entries.map(e=>r(`locations.rebuildEntry`,{name:e.name,count:e.ids.length})).join(`
2
+ `);if(!await s({title:r(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:r(`locations.replaceTheLinkedDeviceList`,`Replace the linked-device list of every camera in “{{room}}” with what the room contains? {{lines}} Anything linked by hand that is not in this room is lost.`,{room:e,lines:n}),confirmLabel:r(`locations.rebuild`,`Rebuild`),variant:`danger`}))return;let i=[];for(let e of t.entries)try{await ee.mutateAsync(pt(e))}catch(t){i.push(`• ${e.name}: ${t instanceof Error?t.message:String(t)}`)}g(),i.length>0&&await s({title:r(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:r(`locations.notRebuilt`,`Not rebuilt: {{value1}}`,{value1:i.join(`
3
+ `)}),confirmLabel:`OK`})},G=async(e,t)=>{let n=t>0?` ${String(t)} device(s) will become unassigned.`:``;await s({title:r(`locations.deleteLocation`,`Delete location`),message:r(`locations.deleteTheLocation`,`Delete the location “{{name}}”?{{extra}}`,{name:e,extra:n}),confirmLabel:r(`common.delete`,`Delete`),variant:`danger`})&&await y.mutateAsync({name:e,cascade:!0})},xe=async e=>{await s({title:r(`locations.deleteZone`,`Delete zone`),message:r(`locations.deleteTheZoneTheRooms`,`Delete the zone “{{name}}”? The rooms in it are kept.`,{name:e}),confirmLabel:r(`common.delete`,`Delete`),variant:`danger`})&&await E.mutateAsync({name:e})},Se=async(e,t)=>{await S.mutateAsync({location:e,icon:t})},we=async(e,t)=>{await C.mutateAsync({location:e,description:t})},K=p??[],J=async(e,t)=>{await k.mutateAsync({location:e,zone:t})},Ee=(e,t)=>{for(let n of e)b.mutate({deviceId:n,location:t})},[Y,X]=i(null),Oe=t(()=>j.filter(e=>e.parentDeviceId===null).map(e=>({id:e.id,name:e.name,type:e.type,location:e.location})),[j]),ke=n(st,{rooms:ae,...I===`locations`?{unassignedCount:R.length}:{},value:I===`locations`?ie:H??``,unassignedValue:mt,onChange:oe}),Z=e(`div`,{className:`flex flex-col gap-3`,"data-testid":`locations-section`,children:[U&&n(`p`,{className:`text-xs text-foreground-subtle`,children:r(`locations.loadingLocationsAndDevices`,`Loading locations and devices…`)}),ke,z||V===null?n(lt,{rows:R,fleet:j,locations:M,busy:W,emptyMessage:U?r(`common.loading`,`Loading…`):r(`locations.everyTopLevelDeviceHas`,`Every top-level device has a room.`),onAssign:Ee}):n(et,{name:V.name,members:V.members,devices:j,busy:W,icon:Ze(d,T(V.name)),onPickIcon:e=>Se(V.name,e),description:Ke(f,T(V.name)),onSaveDescription:e=>we(V.name,e),zones:K,zoneKey:Ye(K,T(V.name)),onChangeZone:e=>J(V.name,e),onRename:e=>he(V.name,e),onDelete:()=>G(V.name,Ae(j,V.name).length),onRebuildLinks:()=>ve(V.name),onAddDevices:()=>X(V.name)},V.name),M.length===0&&!U&&n(`p`,{className:`text-xs text-foreground-subtle`,children:r(`locations.noLocationsYetAddFrontDoor`,`No locations yet. Add Front door, Hall, Kitchen…`)}),n(Ve,{open:Y!==null,title:r(`locations.room.addDialogTitle`,{room:Y??``}),items:Oe,listState:h?`pending`:`answered`,lockedIds:Y===null?[]:(N.find(e=>e.name===Y)?.members??[]).map(e=>e.id),lockedNote:r(`locations.room.alreadyHere`),suggestions:{heading:r(`locations.room.suggestedUnassigned`),ids:R.map(e=>e.id)},busy:b.isPending,onConfirm:e=>{Y!==null&&Ee(e,Y),X(null)},onClose:()=>X(null)})]}),Q=e(`div`,{className:`flex flex-col gap-3`,"data-testid":`camera-links-tab`,children:[ke,n(He,{room:H,cameras:H===null?[]:Ae(j,H).filter(e=>e.isCamera),fleet:j})]});return n(De,{icon:u,title:r(`locations.locations`,`Locations`),subtitle:r(`locations.roomsAndAreasOfThe`,`Rooms and areas of the site. Assign any device here — storage disks are under Data → Storage.`),defaultSection:`locations`,sectionsLabel:`Locations sections`,actions:I===`zones`?n(at,{busy:w.isPending,onCreate:e=>w.mutateAsync({name:e})}):n(it,{busy:v.isPending,onCreate:fe}),sections:[{id:`locations`,label:r(`locations.locations`,`Locations`),content:Z},{id:`camera-links`,label:r(`locations.cameraLinks`,`Camera links`),content:Q},{id:`zones`,label:r(`locations.zones`,`Zones`),content:n(rt,{zones:K,busy:W,onRename:(e,t)=>D.mutateAsync({from:e,to:t}),onDelete:xe,onPickIcon:(e,t)=>w.mutateAsync({name:e,icon:t})})}]})}export{ht as LocationsPage};
@@ -1 +1 @@
1
- import{C as e,K as t,R as n,S as r,V as i,Y as a,et as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Ga as s,Ka as c,Lr as l,Vn as u,ca as d,ft as f,hi as p,mn as m,ra as h}from"./player-overlays-CMIUmcCR.js";import{hc as g,zs as _}from"./client-dUCYJcne.js";import{t as v}from"./layers-BH9u1mrE.js";import{t as y}from"./timer-reset-5221y6Jb.js";import{Cf as b,Ef as x,Ir as S,Sa as C,Vp as w,Xi as T,Zi as E,bf as D,cp as O,gp as k,mr as A}from"./src-CZCLpkMn.js";import{t as j}from"./useTranslation-BJr-n0es.js";import{a as M,i as N,w as P,yi as F}from"./index-BuwKkAl-.js";import{t as I}from"./AdminSectionedPage-C3NbPIMK.js";import{t as L}from"./InstancesTable-BkkLy_BU.js";import{t as R}from"./AdminPage-Dr8PsIuX.js";o();var z=[12e4,3e5,6e5,18e5],B={"request-census":`Counts every tRPC call by TRANSPORT PLANE — http, ws, mesh — and by procedure, caller, address and user-agent. Subscriptions are counted apart from calls, so a long-lived stream cannot pass for a storm. Arm it, then restart: the deadline is persisted, so the window is still running when clients reconnect.`};function V(){let{t}=j(),n=b({},{refetchInterval:5e3}),i=x(),[o,c]=a(null),u=(e,t)=>{c(e),i.mutate({patch:{diagnostics:[{id:e,armMs:t}]}},{onSettled:()=>{c(null),n.refetch()}})},d=n.data?.activeWindows??[],f=(n.data?.channels??[]).filter(e=>e.kind!==`debug`),p=n.data?.activeChannels??[],m=(e,t,r)=>{c(e),i.mutate({patch:{channels:[{channel:e,armMs:t,deviceIds:r}]}},{onSettled:()=>{c(null),n.refetch()}})};return e(R,{embedded:!0,icon:s,title:t(`logging.diagnostics.title`,`Diagnostics`),subtitle:t(`logging.diagnostics.subtitle`,`Diagnostics are armed for a window, never switched on. Each carries a deadline and expires by itself — one left running is an incident of its own.`),children:[n.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(l,{className:`h-3.5 w-3.5 animate-spin`}),t(`common.loading`,`Loading…`)]}):r(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:d.map(e=>r(U,{window:e,busy:o===e.id,onArm:t=>u(e.id,t)},e.id))}),r(`h3`,{className:`mt-6 text-sm font-medium text-foreground`,children:t(`logging.diagnostics.channels`,`Component channels`)}),r(`p`,{className:`mb-2 max-w-3xl text-[11px] text-foreground-subtle`,children:t(`logging.diagnostics.channelsSubtitle`,`Declared by the addons that own them — this list is not maintained by hand. Arming a channel opens a window with a deadline; it closes by itself.`)}),f.length===0?r(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`logging.diagnostics.noChannels`,`No addon on this cluster declares a log channel, or none could be reached right now.`)}):r(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:f.map(e=>r(H,{channel:e,state:p.find(t=>t.channel===e.name),busy:o===e.name,onArm:(t,n)=>m(e.name,t,n)},e.name))})]})}function H({channel:t,state:n,busy:i,onArm:o}){let{t:s}=j(),[c,l]=a(``),u=n?.armed===!0,f=()=>{let e=c.split(/[\s,+]+/).filter(e=>/^\d+$/.test(e)).map(e=>Number(e));return e.length>0?e:null};return e(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[e(`div`,{className:`min-w-0`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(`span`,{className:`text-sm font-medium text-foreground`,children:t.name}),u?e(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[r(y,{className:`h-3 w-3`}),s(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:W(n?.remainingMs??0)})]}):r(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:s(`logging.diagnostics.disarmed`,`disarmed`)}),u&&n?.deviceIds!==null&&n?.deviceIds!==void 0&&e(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[r(d,{className:`h-3 w-3`}),n.deviceIds.join(`, `)]}),!t.perDevice&&r(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:s(`logging.diagnostics.notPerCamera`,`not filterable per camera`)})]}),r(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:t.description})]}),e(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[t.perDevice&&r(k,{type:`text`,inputMode:`numeric`,value:c,disabled:i,onChange:e=>l(e.target.value),placeholder:s(`logging.diagnostics.camerasPlaceholder`,`all cameras`),className:`w-28 rounded border border-border bg-surface px-2 py-1 text-[11px] text-foreground`}),z.map(e=>r(O,{variant:`unstyled`,type:`button`,disabled:i,onClick:()=>o(e,f()),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:W(e)},e)),r(O,{variant:`unstyled`,type:`button`,disabled:i||!u,onClick:()=>o(0,null),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:s(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function U({window:t,busy:n,onArm:i}){let{t:a}=j();return e(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[e(`div`,{className:`min-w-0`,children:[e(`div`,{className:`flex items-center gap-2`,children:[r(`span`,{className:`text-sm font-medium text-foreground`,children:t.id}),t.armed?e(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[r(y,{className:`h-3 w-3`}),a(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:W(t.remainingMs)})]}):r(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:a(`logging.diagnostics.disarmed`,`disarmed`)}),t.armed&&!t.persisted&&r(`span`,{className:`text-[10px] text-warning`,children:a(`logging.diagnostics.notPersisted`,`not persisted — will not survive a restart`)})]}),r(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:B[t.id]??``})]}),e(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[z.map(e=>r(O,{variant:`unstyled`,type:`button`,disabled:n,onClick:()=>i(e),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:W(e)},e)),r(O,{variant:`unstyled`,type:`button`,disabled:n||!t.armed,onClick:()=>i(0),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:a(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function W(e){let t=Math.max(0,Math.round(e/1e3)),n=Math.floor(t/60),r=t%60;return n===0?`${r}s`:r===0?`${n}m`:`${n}m ${r}s`}function G(){let{t:e}=j();return r(L,{functionCap:`log-destination`,icon:u,title:e(`system.logging.destinations`,`Destinations`),subtitle:e(`system.logging.everyRegisteredLogDestinationEntries`,`Every registered log destination. Entries are fanned to all enabled destinations at once — enabling one does not disable another.`),emptyTitle:e(`system.logging.noLogDestinationsRegistered`,`No log destinations registered`),emptyDescription:e(`system.logging.thisShouldNotHappenThe`,`This should not happen — the console and rotated-file destinations are builtins. If the list is empty, the node is still booting.`),defaultKindLabel:e(`system.logging.kindDestination`,`Log destination`),addLabel:e(`system.logging.addDestination`,`Add destination`),install:{capability:`log-destination`,label:e(`system.logging.installDestination`,`Install a destination`)}})}o();var K=[`debug`,`info`,`warn`,`error`],q=``,J=``;function Y(){let{t:n}=j(),[i,o]=a(q),[s,c]=a(J),{nodes:u}=w(),d=t(()=>u.map(e=>({id:e.id,label:e.name||e.id})),[u]),p=b({...i===q?{}:{scopeNodeId:i},...s===J?{}:{scopeComponent:s}},{refetchInterval:15e3}),m=x(),h=p.data,g=m.isPending||p.isFetching,_=(h?.channels??[]).filter(e=>e.kind!==`debug`),y=(e,t)=>{m.mutate({...e.nodeId===null?{}:{scopeNodeId:e.nodeId},...e.component===null?{}:{scopeComponent:e.component},patch:{level:t}},{onSuccess:()=>void p.refetch()})};return r(R,{embedded:!0,icon:v,title:n(`logging.levels.title`,`Levels`),subtitle:n(`logging.levels.subtitle`,`Cluster → node, most specific wins. The floor gates what reaches the log destinations; the in-memory viewer keeps every line either way.`),actions:e(`div`,{className:`flex flex-wrap items-center gap-3`,children:[e(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[n(`logging.levels.scope`,`Scope`),e(f,{wrapperClassName:`inline-block w-auto`,value:i,disabled:s!==J,onChange:e=>o(e.target.value),children:[r(`option`,{value:q,children:n(`logging.levels.cluster`,`Cluster`)}),d.map(e=>r(`option`,{value:e.id,children:e.label},e.id))]})]}),e(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[n(`logging.levels.component`,`Component`),e(f,{wrapperClassName:`inline-block w-auto`,value:s,onChange:e=>c(e.target.value),children:[r(`option`,{value:J,children:n(`logging.levels.noComponent`,`None`)}),_.map(e=>r(`option`,{value:e.name,children:e.name},e.name))]})]})]}),children:p.isLoading||h===void 0?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(l,{className:`h-3.5 w-3.5 animate-spin`}),n(`common.loading`,`Loading…`)]}):e(`div`,{className:`space-y-3`,children:[r(Z,{level:h.effective.level,source:h.effective.levelSource,persisted:h.persisted}),r(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:h.explicit.layers.map(e=>r(Q,{layer:e,inForce:e.scope===h.effective.levelSource,busy:g,onSet:t=>y(e,t),onClear:()=>y(e,null)},`${e.scope}:${e.nodeId??e.component??`cluster`}`))}),s!==J&&r(`p`,{className:`text-[11px] text-foreground-subtle`,children:_.find(e=>e.name===s)?.description??``}),r(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`logging.levels.componentNote`,`A component is a log channel an addon declared. Its level is cluster-wide and beats both the node and the cluster layer.`)}),r(X,{days:h.opsLogRetentionDays,busy:g,onSet:e=>m.mutate({patch:{opsLogRetentionDays:e}},{onSuccess:()=>void p.refetch()})})]})})}function X({days:t,busy:n,onSet:i}){let{t:a}=j();return e(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-1`,children:[e(`label`,{className:`flex items-center justify-between gap-3`,children:[r(`span`,{className:`text-xs font-medium`,children:a(`logging.levels.opsLogRetention`,`Retention audit trail`)}),e(`span`,{className:`flex items-center gap-1.5`,children:[r(k,{type:`number`,min:0,max:3650,step:1,defaultValue:t,disabled:n,onBlur:e=>{let n=Number.parseInt(e.target.value,10);Number.isFinite(n)&&n!==t&&i(n)},className:`w-20 rounded border border-border bg-surface px-2 py-1 text-xs`}),r(`span`,{className:`text-[11px] text-foreground-subtle`,children:a(`common.days`,`days`)})]})]}),r(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`logging.levels.opsLogRetentionNote`,`How long the record of what retention deleted is kept. Cluster-wide, and deliberately longer than any camera window — it is the history of the sweep, not of the camera, and it is what makes a storage leak explainable after the fact. 0 keeps it forever.`)})]})}function Z({level:t,source:n,persisted:i}){let{t:a}=j();return e(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[e(`div`,{className:`flex items-center gap-2`,children:[r(`span`,{className:`text-xs text-foreground-subtle`,children:a(`logging.levels.effective`,`In force here`)}),r(`span`,{className:`rounded bg-primary/10 px-2 py-0.5 text-xs font-semibold text-primary`,children:t}),r(`span`,{className:`text-[11px] text-foreground-subtle`,children:n==="default"?a(`logging.levels.fromDefault`,`nothing is set anywhere — this is the default`):a(`logging.levels.fromLayer`,`decided by the {{source}} layer`,{source:n})})]}),!i&&r(`p`,{className:`mt-1 text-[11px] text-warning`,children:a(`logging.levels.notPersisted`,`The settings store could not be read or written — what you see is live, but it would not survive a restart.`)})]})}function Q({layer:t,inForce:n,busy:i,onSet:a,onClear:o}){let{t:s}=j();return e(`div`,{className:`flex flex-col gap-2 p-3 sm:flex-row sm:items-center sm:justify-between`,children:[e(`div`,{className:`min-w-0`,children:[e(`div`,{className:`flex items-center gap-2`,children:[r(`span`,{className:`text-sm font-medium text-foreground`,children:t.scope===`cluster`?s(`logging.levels.cluster`,`Cluster`):t.scope===`component`?t.component??``:t.nodeId??``}),n&&e(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[r(h,{className:`h-3 w-3`}),s(`logging.levels.inForce`,`in force`)]})]}),r(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:t.level===null?s(`logging.levels.inherits`,`inherits — nothing set at this layer`):s(`logging.levels.setHere`,`set here: {{level}}`,{level:t.level})})]}),e(`div`,{className:`flex shrink-0 items-center gap-1`,children:[K.map(e=>r(O,{variant:`unstyled`,type:`button`,disabled:i,onClick:()=>a(e),className:`rounded px-2 py-1 text-[11px] font-medium transition-colors disabled:opacity-50 ${t.level===e?`bg-primary text-primary-foreground`:`border border-border text-foreground-subtle hover:text-foreground`}`,children:e},e)),r(O,{variant:`unstyled`,type:`button`,disabled:i||t.level===null,onClick:o,className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-40`,children:s(`logging.levels.clear`,`Clear`)})]})]})}function $(e){let t=Math.max(0,Math.round(e/1e3)),n=Math.floor(t/60),r=t%60;return n===0?`${r}s`:`${n}m ${String(r).padStart(2,`0`)}s`}function ee(e,t){return{windowMs:Math.max(0,e.untilMs-t),capMs:Math.max(0,e.capAtMs-t)}}function te(e,t){let n=new Set(e.map(e=>e.channel));return t.filter(e=>n.has(e))}o();var ne=[_.Camera],re=8,ie=1e3,ae=15e3;function oe(){let{t:o}=j(),s=b({},{refetchInterval:15e3}),u=D(),[d,f]=a([]),[h,_]=a([]),[v,x]=a([]),[w,k]=a(()=>Date.now()),[M,N]=a([]),P=t(()=>(s.data?.channels??[]).filter(e=>e.kind===`debug`),[s.data]),F=n((e,t,n)=>{u.mutate({action:e,channels:t,deviceIds:n},{onSuccess:e=>{f(e.watches),N(e.lapsed)}})},[]);i(()=>{let e=setInterval(()=>k(Date.now()),ie);return()=>clearInterval(e)},[]),i(()=>{F(`list`,[],[]);let e=setInterval(()=>F(`list`,[],[]),ae);return()=>clearInterval(e)},[F]);let I=te(d,h).join(`|`);i(()=>{if(I===``)return;let e=setInterval(()=>F(`rearm`,I.split(`|`),[]),g);return()=>clearInterval(e)},[I,F]);let L=h.length>0&&v.length>0&&!u.isPending,z=[...new Set(d.flatMap(e=>e.deviceIds))],B=(e,t)=>_(n=>t?[...n,e]:n.filter(t=>t!==e));return e(R,{embedded:!0,icon:p,title:o(`logging.watch.title`,`Watch`),subtitle:o(`logging.watch.subtitle`,`Switch a debug channel on for chosen devices and read it live. A watch lasts 10 minutes, is renewed while this page stays open, and ends by itself after 60 minutes at most.`),children:[r(S,{headingId:`log-watch-setup`,title:o(`logging.watch.setup`,`Channels and devices`),children:s.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(l,{className:`h-3.5 w-3.5 animate-spin`}),o(`common.loading`,`Loading…`)]}):P.length===0?r(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`logging.watch.noChannels`,`No addon on this cluster offers a debug channel, or none could be reached right now.`)}):e(`div`,{className:`space-y-3 p-3`,children:[r(`div`,{className:`space-y-2`,children:P.map(t=>e(`label`,{className:`flex items-start gap-2`,children:[r(c,{checked:h.includes(t.name),onChange:e=>B(t.name,e.target.checked)}),e(`span`,{className:`min-w-0`,children:[r(`span`,{className:`text-sm font-medium text-foreground`,children:t.name}),r(`span`,{className:`block text-[11px] text-foreground-subtle`,children:t.description})]})]},t.name))}),e(`div`,{className:`flex flex-col gap-1`,children:[r(`span`,{className:`text-xs font-medium text-foreground`,children:o(`logging.watch.devices`,`Devices`)}),r(C,{multiple:!0,pick:`device`,noun:`camera`,fixedTypes:ne,maxItems:re,recentKey:`log-watch-devices`,testId:`log-watch-devices`,value:E(v),onChange:e=>x(T(e))})]}),e(`div`,{className:`flex flex-wrap gap-2`,children:[r(O,{type:`button`,disabled:!L,onClick:()=>F(`start`,h,v),children:o(`logging.watch.start`,`Start watching`)}),e(O,{type:`button`,variant:`secondary`,disabled:d.length===0||u.isPending,onClick:()=>F(`stop`,d.map(e=>e.channel),[]),children:[r(m,{className:`mr-1 h-3.5 w-3.5`}),o(`logging.watch.stop`,`Stop`)]})]}),u.isError&&r(`p`,{className:`text-[11px] text-destructive`,children:u.error.message}),M.length>0&&r(`p`,{className:`text-[11px] text-warning`,children:o(`logging.watch.lapsed`,`Already ended, not renewed: {{names}}. Start again to continue.`,{names:M.join(`, `)})})]})}),d.length>0&&e(S,{headingId:`log-watch-live`,title:o(`logging.watch.live`,`Live`),children:[r(`div`,{className:`divide-y divide-border`,children:d.map(t=>{let n=ee(t,w);return e(`div`,{className:`flex flex-wrap items-center gap-2 p-3`,children:[r(`span`,{className:`text-sm font-medium text-foreground`,children:t.channel}),e(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[r(y,{className:`h-3 w-3`}),o(`logging.watch.endsIn`,`ends in {{left}}`,{left:$(n.windowMs)})]}),r(`span`,{className:`text-[11px] text-foreground-subtle`,children:o(`logging.watch.capIn`,`hard stop in {{left}}`,{left:$(n.capMs)})}),e(`span`,{className:`text-[11px] text-foreground-subtle`,children:[`#`,t.deviceIds.join(`, #`)]})]},t.channel)})}),z.map(e=>r(`div`,{className:`border-t border-border`,children:r(A,{deviceId:e,limit:200,maxHeight:`max-h-80`,showScope:!0,showFilters:!1})},e))]})]})}function se(){let[e]=F(),t=e.get(`deviceId`),n=t===null?void 0:Number(t);return r(R,{embedded:!0,children:r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:r(A,{deviceId:n!==void 0&&Number.isFinite(n)?n:void 0,limit:500,maxHeight:`max-h-[calc(100vh-310px)]`,showFilters:!0,showOriginFilter:!0,columns:{available:[`integration`,`device`],defaultVisible:[`integration`,`device`]}})})})}function ce(){let{t:e}=j(),t=P(`/system/logs`,{t:e,isAdmin:!0})??{icon:u,title:e(`system.logs`,`Logs`)};return r(I,{icon:t.icon,title:t.title,defaultSection:`viewer`,sectionsLabel:`${t.title} sections`,sections:[{id:`viewer`,label:e(`admin.system.logs.viewer`,`Viewer`),content:r(se,{})},{id:M.logging.tab,label:e(`admin.system.logs.destinations`,`Destinations`),content:r(G,{}),ownedParams:N},{id:`levels`,label:e(`admin.system.logs.levels`,`Levels`),content:r(Y,{})},{id:`watch`,label:e(`admin.system.logs.watch`,`Watch`),content:r(oe,{})},{id:`diagnostics`,label:e(`admin.system.logs.diagnostics`,`Diagnostics`),content:r(V,{})}]})}export{ce as LogsPage};
1
+ import{C as e,K as t,R as n,S as r,V as i,Y as a,et as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Vn as s,Xa as c,Za as l,_i as u,fa as d,ft as f,mn as p,sa as m,zr as h}from"./player-overlays-ugkkFXtV.js";import{Tc as g,Ys as _}from"./client-B3h-2G71.js";import{t as v}from"./layers-BH9u1mrE.js";import{t as y}from"./timer-reset-5221y6Jb.js";import{Ca as b,Df as x,Ir as S,Vp as C,Xi as w,Zi as T,cp as E,gp as D,mr as O,wf as k,xf as A}from"./src-DeDx2fDl.js";import{t as j}from"./useTranslation-BJr-n0es.js";import{D as M,Si as N,a as P,i as F}from"./index-D_vdUQKv.js";import{t as I}from"./AdminSectionedPage-3Jh0qbF0.js";import{t as L}from"./InstancesTable-C81CknSI.js";import{t as R}from"./AdminPage-DHZrZAII.js";o();var z=[12e4,3e5,6e5,18e5],B={"request-census":`Counts every tRPC call by TRANSPORT PLANE — http, ws, mesh — and by procedure, caller, address and user-agent. Subscriptions are counted apart from calls, so a long-lived stream cannot pass for a storm. Arm it, then restart: the deadline is persisted, so the window is still running when clients reconnect.`};function V(){let{t}=j(),n=k({},{refetchInterval:5e3}),i=x(),[o,s]=a(null),l=(e,t)=>{s(e),i.mutate({patch:{diagnostics:[{id:e,armMs:t}]}},{onSettled:()=>{s(null),n.refetch()}})},u=n.data?.activeWindows??[],d=(n.data?.channels??[]).filter(e=>e.kind!==`debug`),f=n.data?.activeChannels??[],p=(e,t,r)=>{s(e),i.mutate({patch:{channels:[{channel:e,armMs:t,deviceIds:r}]}},{onSettled:()=>{s(null),n.refetch()}})};return e(R,{embedded:!0,icon:c,title:t(`logging.diagnostics.title`,`Diagnostics`),subtitle:t(`logging.diagnostics.subtitle`,`Diagnostics are armed for a window, never switched on. Each carries a deadline and expires by itself — one left running is an incident of its own.`),children:[n.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(h,{className:`h-3.5 w-3.5 animate-spin`}),t(`common.loading`,`Loading…`)]}):r(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:u.map(e=>r(U,{window:e,busy:o===e.id,onArm:t=>l(e.id,t)},e.id))}),r(`h3`,{className:`mt-6 text-sm font-medium text-foreground`,children:t(`logging.diagnostics.channels`,`Component channels`)}),r(`p`,{className:`mb-2 max-w-3xl text-[11px] text-foreground-subtle`,children:t(`logging.diagnostics.channelsSubtitle`,`Declared by the addons that own them — this list is not maintained by hand. Arming a channel opens a window with a deadline; it closes by itself.`)}),d.length===0?r(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`logging.diagnostics.noChannels`,`No addon on this cluster declares a log channel, or none could be reached right now.`)}):r(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:d.map(e=>r(H,{channel:e,state:f.find(t=>t.channel===e.name),busy:o===e.name,onArm:(t,n)=>p(e.name,t,n)},e.name))})]})}function H({channel:t,state:n,busy:i,onArm:o}){let{t:s}=j(),[c,l]=a(``),u=n?.armed===!0,f=()=>{let e=c.split(/[\s,+]+/).filter(e=>/^\d+$/.test(e)).map(e=>Number(e));return e.length>0?e:null};return e(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[e(`div`,{className:`min-w-0`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(`span`,{className:`text-sm font-medium text-foreground`,children:t.name}),u?e(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[r(y,{className:`h-3 w-3`}),s(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:W(n?.remainingMs??0)})]}):r(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:s(`logging.diagnostics.disarmed`,`disarmed`)}),u&&n?.deviceIds!==null&&n?.deviceIds!==void 0&&e(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[r(d,{className:`h-3 w-3`}),n.deviceIds.join(`, `)]}),!t.perDevice&&r(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:s(`logging.diagnostics.notPerCamera`,`not filterable per camera`)})]}),r(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:t.description})]}),e(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[t.perDevice&&r(D,{type:`text`,inputMode:`numeric`,value:c,disabled:i,onChange:e=>l(e.target.value),placeholder:s(`logging.diagnostics.camerasPlaceholder`,`all cameras`),className:`w-28 rounded border border-border bg-surface px-2 py-1 text-[11px] text-foreground`}),z.map(e=>r(E,{variant:`unstyled`,type:`button`,disabled:i,onClick:()=>o(e,f()),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:W(e)},e)),r(E,{variant:`unstyled`,type:`button`,disabled:i||!u,onClick:()=>o(0,null),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:s(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function U({window:t,busy:n,onArm:i}){let{t:a}=j();return e(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[e(`div`,{className:`min-w-0`,children:[e(`div`,{className:`flex items-center gap-2`,children:[r(`span`,{className:`text-sm font-medium text-foreground`,children:t.id}),t.armed?e(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[r(y,{className:`h-3 w-3`}),a(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:W(t.remainingMs)})]}):r(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:a(`logging.diagnostics.disarmed`,`disarmed`)}),t.armed&&!t.persisted&&r(`span`,{className:`text-[10px] text-warning`,children:a(`logging.diagnostics.notPersisted`,`not persisted — will not survive a restart`)})]}),r(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:B[t.id]??``})]}),e(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[z.map(e=>r(E,{variant:`unstyled`,type:`button`,disabled:n,onClick:()=>i(e),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:W(e)},e)),r(E,{variant:`unstyled`,type:`button`,disabled:n||!t.armed,onClick:()=>i(0),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:a(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function W(e){let t=Math.max(0,Math.round(e/1e3)),n=Math.floor(t/60),r=t%60;return n===0?`${r}s`:r===0?`${n}m`:`${n}m ${r}s`}function G(){let{t:e}=j();return r(L,{functionCap:`log-destination`,icon:s,title:e(`system.logging.destinations`,`Destinations`),subtitle:e(`system.logging.everyRegisteredLogDestinationEntries`,`Every registered log destination. Entries are fanned to all enabled destinations at once — enabling one does not disable another.`),emptyTitle:e(`system.logging.noLogDestinationsRegistered`,`No log destinations registered`),emptyDescription:e(`system.logging.thisShouldNotHappenThe`,`This should not happen — the console and rotated-file destinations are builtins. If the list is empty, the node is still booting.`),defaultKindLabel:e(`system.logging.kindDestination`,`Log destination`),addLabel:e(`system.logging.addDestination`,`Add destination`),install:{capability:`log-destination`,label:e(`system.logging.installDestination`,`Install a destination`)}})}o();var K=[`debug`,`info`,`warn`,`error`],q=``,J=``;function Y(){let{t:n}=j(),[i,o]=a(q),[s,c]=a(J),{nodes:l}=C(),u=t(()=>l.map(e=>({id:e.id,label:e.name||e.id})),[l]),d=k({...i===q?{}:{scopeNodeId:i},...s===J?{}:{scopeComponent:s}},{refetchInterval:15e3}),p=x(),m=d.data,g=p.isPending||d.isFetching,_=(m?.channels??[]).filter(e=>e.kind!==`debug`),y=(e,t)=>{p.mutate({...e.nodeId===null?{}:{scopeNodeId:e.nodeId},...e.component===null?{}:{scopeComponent:e.component},patch:{level:t}},{onSuccess:()=>void d.refetch()})};return r(R,{embedded:!0,icon:v,title:n(`logging.levels.title`,`Levels`),subtitle:n(`logging.levels.subtitle`,`Cluster → node, most specific wins. The floor gates what reaches the log destinations; the in-memory viewer keeps every line either way.`),actions:e(`div`,{className:`flex flex-wrap items-center gap-3`,children:[e(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[n(`logging.levels.scope`,`Scope`),e(f,{wrapperClassName:`inline-block w-auto`,value:i,disabled:s!==J,onChange:e=>o(e.target.value),children:[r(`option`,{value:q,children:n(`logging.levels.cluster`,`Cluster`)}),u.map(e=>r(`option`,{value:e.id,children:e.label},e.id))]})]}),e(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[n(`logging.levels.component`,`Component`),e(f,{wrapperClassName:`inline-block w-auto`,value:s,onChange:e=>c(e.target.value),children:[r(`option`,{value:J,children:n(`logging.levels.noComponent`,`None`)}),_.map(e=>r(`option`,{value:e.name,children:e.name},e.name))]})]})]}),children:d.isLoading||m===void 0?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(h,{className:`h-3.5 w-3.5 animate-spin`}),n(`common.loading`,`Loading…`)]}):e(`div`,{className:`space-y-3`,children:[r(Z,{level:m.effective.level,source:m.effective.levelSource,persisted:m.persisted}),r(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:m.explicit.layers.map(e=>r(Q,{layer:e,inForce:e.scope===m.effective.levelSource,busy:g,onSet:t=>y(e,t),onClear:()=>y(e,null)},`${e.scope}:${e.nodeId??e.component??`cluster`}`))}),s!==J&&r(`p`,{className:`text-[11px] text-foreground-subtle`,children:_.find(e=>e.name===s)?.description??``}),r(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`logging.levels.componentNote`,`A component is a log channel an addon declared. Its level is cluster-wide and beats both the node and the cluster layer.`)}),r(X,{days:m.opsLogRetentionDays,busy:g,onSet:e=>p.mutate({patch:{opsLogRetentionDays:e}},{onSuccess:()=>void d.refetch()})})]})})}function X({days:t,busy:n,onSet:i}){let{t:a}=j();return e(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-1`,children:[e(`label`,{className:`flex items-center justify-between gap-3`,children:[r(`span`,{className:`text-xs font-medium`,children:a(`logging.levels.opsLogRetention`,`Retention audit trail`)}),e(`span`,{className:`flex items-center gap-1.5`,children:[r(D,{type:`number`,min:0,max:3650,step:1,defaultValue:t,disabled:n,onBlur:e=>{let n=Number.parseInt(e.target.value,10);Number.isFinite(n)&&n!==t&&i(n)},className:`w-20 rounded border border-border bg-surface px-2 py-1 text-xs`}),r(`span`,{className:`text-[11px] text-foreground-subtle`,children:a(`common.days`,`days`)})]})]}),r(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`logging.levels.opsLogRetentionNote`,`How long the record of what retention deleted is kept. Cluster-wide, and deliberately longer than any camera window — it is the history of the sweep, not of the camera, and it is what makes a storage leak explainable after the fact. 0 keeps it forever.`)})]})}function Z({level:t,source:n,persisted:i}){let{t:a}=j();return e(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[e(`div`,{className:`flex items-center gap-2`,children:[r(`span`,{className:`text-xs text-foreground-subtle`,children:a(`logging.levels.effective`,`In force here`)}),r(`span`,{className:`rounded bg-primary/10 px-2 py-0.5 text-xs font-semibold text-primary`,children:t}),r(`span`,{className:`text-[11px] text-foreground-subtle`,children:n==="default"?a(`logging.levels.fromDefault`,`nothing is set anywhere — this is the default`):a(`logging.levels.fromLayer`,`decided by the {{source}} layer`,{source:n})})]}),!i&&r(`p`,{className:`mt-1 text-[11px] text-warning`,children:a(`logging.levels.notPersisted`,`The settings store could not be read or written — what you see is live, but it would not survive a restart.`)})]})}function Q({layer:t,inForce:n,busy:i,onSet:a,onClear:o}){let{t:s}=j();return e(`div`,{className:`flex flex-col gap-2 p-3 sm:flex-row sm:items-center sm:justify-between`,children:[e(`div`,{className:`min-w-0`,children:[e(`div`,{className:`flex items-center gap-2`,children:[r(`span`,{className:`text-sm font-medium text-foreground`,children:t.scope===`cluster`?s(`logging.levels.cluster`,`Cluster`):t.scope===`component`?t.component??``:t.nodeId??``}),n&&e(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[r(m,{className:`h-3 w-3`}),s(`logging.levels.inForce`,`in force`)]})]}),r(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:t.level===null?s(`logging.levels.inherits`,`inherits — nothing set at this layer`):s(`logging.levels.setHere`,`set here: {{level}}`,{level:t.level})})]}),e(`div`,{className:`flex shrink-0 items-center gap-1`,children:[K.map(e=>r(E,{variant:`unstyled`,type:`button`,disabled:i,onClick:()=>a(e),className:`rounded px-2 py-1 text-[11px] font-medium transition-colors disabled:opacity-50 ${t.level===e?`bg-primary text-primary-foreground`:`border border-border text-foreground-subtle hover:text-foreground`}`,children:e},e)),r(E,{variant:`unstyled`,type:`button`,disabled:i||t.level===null,onClick:o,className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-40`,children:s(`logging.levels.clear`,`Clear`)})]})]})}function $(e){let t=Math.max(0,Math.round(e/1e3)),n=Math.floor(t/60),r=t%60;return n===0?`${r}s`:`${n}m ${String(r).padStart(2,`0`)}s`}function ee(e,t){return{windowMs:Math.max(0,e.untilMs-t),capMs:Math.max(0,e.capAtMs-t)}}function te(e,t){let n=new Set(e.map(e=>e.channel));return t.filter(e=>n.has(e))}o();var ne=[_.Camera],re=8,ie=1e3,ae=15e3;function oe(){let{t:o}=j(),s=k({},{refetchInterval:15e3}),c=A(),[d,f]=a([]),[m,_]=a([]),[v,x]=a([]),[C,D]=a(()=>Date.now()),[M,N]=a([]),P=t(()=>(s.data?.channels??[]).filter(e=>e.kind===`debug`),[s.data]),F=n((e,t,n)=>{c.mutate({action:e,channels:t,deviceIds:n},{onSuccess:e=>{f(e.watches),N(e.lapsed)}})},[]);i(()=>{let e=setInterval(()=>D(Date.now()),ie);return()=>clearInterval(e)},[]),i(()=>{F(`list`,[],[]);let e=setInterval(()=>F(`list`,[],[]),ae);return()=>clearInterval(e)},[F]);let I=te(d,m).join(`|`);i(()=>{if(I===``)return;let e=setInterval(()=>F(`rearm`,I.split(`|`),[]),g);return()=>clearInterval(e)},[I,F]);let L=m.length>0&&v.length>0&&!c.isPending,z=[...new Set(d.flatMap(e=>e.deviceIds))],B=(e,t)=>_(n=>t?[...n,e]:n.filter(t=>t!==e));return e(R,{embedded:!0,icon:u,title:o(`logging.watch.title`,`Watch`),subtitle:o(`logging.watch.subtitle`,`Switch a debug channel on for chosen devices and read it live. A watch lasts 10 minutes, is renewed while this page stays open, and ends by itself after 60 minutes at most.`),children:[r(S,{headingId:`log-watch-setup`,title:o(`logging.watch.setup`,`Channels and devices`),children:s.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(h,{className:`h-3.5 w-3.5 animate-spin`}),o(`common.loading`,`Loading…`)]}):P.length===0?r(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`logging.watch.noChannels`,`No addon on this cluster offers a debug channel, or none could be reached right now.`)}):e(`div`,{className:`space-y-3 p-3`,children:[r(`div`,{className:`space-y-2`,children:P.map(t=>e(`label`,{className:`flex items-start gap-2`,children:[r(l,{checked:m.includes(t.name),onChange:e=>B(t.name,e.target.checked)}),e(`span`,{className:`min-w-0`,children:[r(`span`,{className:`text-sm font-medium text-foreground`,children:t.name}),r(`span`,{className:`block text-[11px] text-foreground-subtle`,children:t.description})]})]},t.name))}),e(`div`,{className:`flex flex-col gap-1`,children:[r(`span`,{className:`text-xs font-medium text-foreground`,children:o(`logging.watch.devices`,`Devices`)}),r(b,{multiple:!0,pick:`device`,noun:`camera`,fixedTypes:ne,maxItems:re,recentKey:`log-watch-devices`,testId:`log-watch-devices`,value:T(v),onChange:e=>x(w(e))})]}),e(`div`,{className:`flex flex-wrap gap-2`,children:[r(E,{type:`button`,disabled:!L,onClick:()=>F(`start`,m,v),children:o(`logging.watch.start`,`Start watching`)}),e(E,{type:`button`,variant:`secondary`,disabled:d.length===0||c.isPending,onClick:()=>F(`stop`,d.map(e=>e.channel),[]),children:[r(p,{className:`mr-1 h-3.5 w-3.5`}),o(`logging.watch.stop`,`Stop`)]})]}),c.isError&&r(`p`,{className:`text-[11px] text-destructive`,children:c.error.message}),M.length>0&&r(`p`,{className:`text-[11px] text-warning`,children:o(`logging.watch.lapsed`,`Already ended, not renewed: {{names}}. Start again to continue.`,{names:M.join(`, `)})})]})}),d.length>0&&e(S,{headingId:`log-watch-live`,title:o(`logging.watch.live`,`Live`),children:[r(`div`,{className:`divide-y divide-border`,children:d.map(t=>{let n=ee(t,C);return e(`div`,{className:`flex flex-wrap items-center gap-2 p-3`,children:[r(`span`,{className:`text-sm font-medium text-foreground`,children:t.channel}),e(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[r(y,{className:`h-3 w-3`}),o(`logging.watch.endsIn`,`ends in {{left}}`,{left:$(n.windowMs)})]}),r(`span`,{className:`text-[11px] text-foreground-subtle`,children:o(`logging.watch.capIn`,`hard stop in {{left}}`,{left:$(n.capMs)})}),e(`span`,{className:`text-[11px] text-foreground-subtle`,children:[`#`,t.deviceIds.join(`, #`)]})]},t.channel)})}),z.map(e=>r(`div`,{className:`border-t border-border`,children:r(O,{deviceId:e,limit:200,maxHeight:`max-h-80`,showScope:!0,showFilters:!1})},e))]})]})}function se(){let[e]=N(),t=e.get(`deviceId`),n=t===null?void 0:Number(t);return r(R,{embedded:!0,children:r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:r(O,{deviceId:n!==void 0&&Number.isFinite(n)?n:void 0,limit:500,maxHeight:`max-h-[calc(100vh-310px)]`,showFilters:!0,showOriginFilter:!0,columns:{available:[`integration`,`device`],defaultVisible:[`integration`,`device`]}})})})}function ce(){let{t:e}=j(),t=M(`/system/logs`,{t:e,isAdmin:!0})??{icon:s,title:e(`system.logs`,`Logs`)};return r(I,{icon:t.icon,title:t.title,defaultSection:`viewer`,sectionsLabel:`${t.title} sections`,sections:[{id:`viewer`,label:e(`admin.system.logs.viewer`,`Viewer`),content:r(se,{})},{id:P.logging.tab,label:e(`admin.system.logs.destinations`,`Destinations`),content:r(G,{}),ownedParams:F},{id:`levels`,label:e(`admin.system.logs.levels`,`Levels`),content:r(Y,{})},{id:`watch`,label:e(`admin.system.logs.watch`,`Watch`),content:r(oe,{})},{id:`diagnostics`,label:e(`admin.system.logs.diagnostics`,`Diagnostics`),content:r(V,{})}]})}export{ce as LogsPage};
@@ -1 +1 @@
1
- import{C as e,J as t,P as n,R as r,S as i,V as a,Y as o,et as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{eo as c}from"./player-overlays-CMIUmcCR.js";import{a as l,c as u,i as d,n as f,o as p,r as m,s as h,t as g}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_konva__loadShare__.js-BjdR__nc.js";s();var _={rect:`#ef4444`,polygon:`#3b82f6`,grid:`#6366f1`,line:`#f59e0b`},v=`33`,y=`66`,b=`#6366f1`,x=3,S=2,C=12,w=16,T=9;function E(e,t,n){return{x:e.x*t,y:e.y*n}}function D(e,t,n){return{x:e.x/t,y:e.y/n}}function O(e,t,n){return e.flatMap(e=>[e.x*t,e.y*n])}function k(e){return!Number.isFinite(e)||e<0?0:e>1?1:e}function A(e){return e.color??_[e.shape.kind]}function j(e,t){let n=e[t],r=e[(t+1)%e.length];if(!n||!r)return[...e];let i={x:(n.x+r.x)/2,y:(n.y+r.y)/2};return[...e.slice(0,t+1),i,...e.slice(t+1)]}function M(e,t){return e.length===t.length?e.every((e,n)=>{let r=t[n];return Math.abs(e.x-r.x)<1e-6&&Math.abs(e.y-r.y)<1e-6}):!1}function N(e){return e.kind===`polygon`||e.kind===`line`}function P({items:n,selectedId:s,onSelect:f,onShapeChange:p,onDrawComplete:m,drawingKind:v,supportedShapes:y,transparent:j=!1,backdrop:P,polygonVertices:F,grid:I}){let B=c(),V=t(null),[H,ee]=o({w:800,h:450}),[U,W]=o([]),[G,K]=o(null),[te,ne]=o(null),[q,J]=o(null),Y=v!==null&&y.includes(v);a(()=>{if(!q)return;let e=n.find(e=>e.id===q.itemId);if(!e||!N(e.shape)){J(null);return}M(e.shape.points,q.points)&&J(null)},[n,q]),a(()=>{let e=V.current;if(!e)return;let t=new ResizeObserver(e=>{let t=e[0];if(!t)return;let{width:n,height:r}=t.contentRect;ee(j?{w:n,h:r}:{w:n,h:n*9/16})});return t.observe(e),()=>t.disconnect()},[j]),a(()=>{!Y&&G!==null&&K(null)},[Y,G]);let X=r(e=>{m(e),W([])},[m]),re=r(e=>{if(!Y||v===null){f(null);return}let t=e.target.getStage();if(!t)return;let n=t.getPointerPosition();if(!n)return;let r=D(n,H.w,H.h);if(v===`rect`){let e=k(r.x),t=k(r.y);X({kind:`rect`,x:e,y:t,width:Math.min(.2,1-e),height:Math.min(.2,1-t)});return}if(v===`grid`){let e=I?.width??w,t=I?.height??T;X({kind:`grid`,gridWidth:e,gridHeight:t,cells:Array.from({length:e*t},()=>!1)});return}if(v===`line`){if(U.length===0){W([r]);return}X({kind:`line`,points:[...U,r]});return}if(v===`polygon`){if(U.length===0){W([r]);return}if(U.length>=x){let e=E(U[0],H.w,H.h);if(Math.hypot(n.x-e.x,n.y-e.y)<C){X({kind:`polygon`,points:U});return}}W(e=>[...e,r])}},[Y,v,U,H,I,X,f]),ie=r(e=>{!Y||v!==`polygon`||U.length<x||(e.cancelBubble=!0,X({kind:`polygon`,points:U}))},[Y,v,U,X]),Z=t(null),Q=t(null);a(()=>()=>{Z.current!==null&&cancelAnimationFrame(Z.current)},[]);let ae=r(e=>{if(!Y)return;let t=e.target.getStage();t&&(Q.current=t.getPointerPosition()??null,Z.current===null&&(Z.current=requestAnimationFrame(()=>{Z.current=null,K(Q.current)})))},[Y]),oe=t(!1),se=t(!0),ce=t(new Set),le=r((e,t,n,r)=>{let i=t.gridWidth*t.gridHeight;if(n<0||n>=i||t.cells[n]===r)return;let a=[...t.cells];for(;a.length<i;)a.push(!1);a.length=i,a[n]=r,p(e,{...t,cells:a})},[p]),$=[];if(!j){for(let e=1;e<w;e++){let t=H.w/w*e;$.push(i(u,{points:[t,0,t,H.h],stroke:`#ffffff`,strokeWidth:.5,opacity:.08},`gv-${e}`))}for(let e=1;e<T;e++){let t=H.h/T*e;$.push(i(u,{points:[0,t,H.w,t],stroke:`#ffffff`,strokeWidth:.5,opacity:.08},`gh-${e}`))}}return e(`div`,{ref:V,className:j?`absolute inset-0`:`relative w-full bg-zinc-900 rounded-lg overflow-hidden`,style:{cursor:Y?`crosshair`:`default`},children:[P&&!j?i(`div`,{className:`absolute inset-0 pointer-events-none [&>*]:w-full [&>*]:h-full [&>img]:object-cover [&>video]:object-cover`,style:{width:H.w,height:H.h},children:P}):null,e(l,{width:H.w,height:H.h,onClick:re,onDblClick:ie,onMouseMove:ae,children:[e(g,{listening:!1,children:[i(u,{points:[0,0,H.w,0,H.w,H.h,0,H.h,0,0],stroke:`transparent`,strokeWidth:0}),$]}),i(g,{children:n.map(e=>{let t=e.id===s,n=e.enabled===!1,r=A(e),a=t&&!Y&&!n;if(e.shape.kind===`rect`)return i(L,{item:e,shape:e.shape,color:r,selected:t,dimmed:n,editable:a,isDrawing:Y,size:H,onSelect:f,onShapeChange:p},e.id);if(e.shape.kind===`grid`)return i(R,{item:e,shape:e.shape,color:r,dimmed:n,editable:a,size:H,onSelect:f,paintingRef:oe,paintValueRef:se,paintedRef:ce,paintCell:le},e.id);let o=e.shape.kind===`line`,c=o?S:Math.max(x,F?.min??x),l=o?S:F?.max,u=q&&q.itemId===e.id?q.points:e.shape.points;return i(z,{item:e,shape:e.shape,color:r,selected:t,dimmed:n,editable:a,isLine:o,isDrawing:Y,size:H,effectivePoints:u,minVertices:c,maxVertices:l,isDragging:te===e.id,onSelect:f,onShapeChange:p,setDragOverride:J,setDraggingItemId:ne},e.id)})}),i(g,{listening:!1,children:Y&&U.length>0&&e(d,{children:[v===`polygon`&&U.length>=2&&i(u,{points:O(U,H.w,H.h),stroke:b,strokeWidth:1.5,dash:[6,3],opacity:.8}),v===`line`&&U.length===1&&G&&i(u,{points:[U[0].x*H.w,U[0].y*H.h,G.x,G.y],stroke:_.line,strokeWidth:1.5,dash:[6,3],opacity:.7}),v===`polygon`&&G&&U.length>=1&&i(u,{points:[U[U.length-1].x*H.w,U[U.length-1].y*H.h,G.x,G.y],stroke:b,strokeWidth:1,dash:[4,4],opacity:.5}),U.map((e,t)=>{let n=E(e,H.w,H.h),r=t===0&&v===`polygon`&&U.length>=x;return i(h,{x:n.x,y:n.y,radius:r?7:4,fill:r?b:`#ffffff`,stroke:b,strokeWidth:1.5,opacity:.9},t)})]})})]}),Y?i(`div`,{className:`px-3 py-1.5 bg-zinc-800/80 text-[11px] text-zinc-400 border-t border-zinc-700`,children:v===`line`?B(`uiLibrary.maskShapeCanvas.hintLine`,`Click to set the start point, click again to complete the line`):v===`rect`?B(`uiLibrary.maskShapeCanvas.hintRect`,`Click to drop a rectangle, then drag the corner to resize`):v===`grid`?B(`uiLibrary.maskShapeCanvas.hintGrid`,`Click to add the grid, then paint cells`):U.length<x?B(`uiLibrary.maskShapeCanvas.hintPoints`,`Click to add points (min 3). Double-click or click the first point to close.`):B(`uiLibrary.maskShapeCanvas.hintMore`,`Continue adding points. Double-click or click the first point to close.`)}):null]})}var F=.02;function I(e,t){return Math.abs(e.x-t.x)<1e-6&&Math.abs(e.y-t.y)<1e-6&&Math.abs(e.width-t.width)<1e-6&&Math.abs(e.height-t.height)<1e-6}function L({item:t,shape:n,color:r,selected:s,dimmed:c,editable:l,isDrawing:u,size:m,onSelect:g,onShapeChange:_}){let[b,x]=o(null),S={x:n.x,y:n.y,width:n.width,height:n.height};a(()=>{b&&I(S,b)&&x(null)},[n.x,n.y,n.width,n.height,b]);let C=b??S,w=C.x*m.w,T=C.y*m.h,E=C.width*m.w,D=C.height*m.h,O=c?.35:s?1:.85,A=e=>{x(e),_(t.id,{kind:`rect`,x:e.x,y:e.y,width:e.width,height:e.height})};return i(d,{onClick:e=>{e.cancelBubble=!0,u||g(t.id)},children:e(d,{draggable:l,dragBoundFunc:l?e=>({x:Math.max(-w,Math.min(m.w-(w+E),e.x)),y:Math.max(-T,Math.min(m.h-(T+D),e.y))}):void 0,onDragEnd:l?e=>{let t=e.target,n=t.x()/m.w,r=t.y()/m.h;if(t.position({x:0,y:0}),n===0&&r===0)return;let i=Math.min(Math.max(0,C.x+n),Math.max(0,1-C.width)),a=Math.min(Math.max(0,C.y+r),Math.max(0,1-C.height));A({...C,x:i,y:a})}:void 0,onMouseEnter:e=>{if(!l)return;let t=e.target.getStage();t&&(t.container().style.cursor=`move`)},onMouseLeave:e=>{if(!l)return;let t=e.target.getStage();t&&(t.container().style.cursor=u?`crosshair`:`default`)},children:[i(p,{x:w,y:T,width:E,height:D,fill:r+(s?y:v),stroke:r,strokeWidth:s?2.5:1.5,opacity:O}),t.label?i(f,{x:w,y:T-16,text:t.label,fontSize:12,fill:r,stroke:`#000000`,strokeWidth:3,fillAfterStrokeEnabled:!0,fontStyle:`bold`,listening:!1}):null,l?i(h,{x:w+E,y:T+D,radius:6,fill:r,stroke:`#ffffff`,strokeWidth:1.5,draggable:!0,dragBoundFunc:e=>({x:Math.min(m.w,Math.max(w,e.x)),y:Math.min(m.h,Math.max(T,e.y))}),onDragStart:e=>{e.cancelBubble=!0},onDragMove:e=>{let t=e.target,n=k(t.x()/m.w-C.x),r=k(t.y()/m.h-C.y);x({...C,width:Math.max(F,Math.min(n,1-C.x)),height:Math.max(F,Math.min(r,1-C.y))})},onDragEnd:e=>{let t=e.target,n=k(t.x()/m.w-C.x),r=k(t.y()/m.h-C.y);A({...C,width:Math.max(F,Math.min(n,1-C.x)),height:Math.max(F,Math.min(r,1-C.y))})},onMouseEnter:e=>{let t=e.target.getStage();t&&(t.container().style.cursor=`nwse-resize`)},onMouseLeave:e=>{let t=e.target.getStage();t&&(t.container().style.cursor=`default`)}}):null]})})}function R({item:e,shape:t,color:n,dimmed:r,editable:a,size:o,onSelect:s,paintingRef:c,paintValueRef:l,paintedRef:u,paintCell:f}){let{gridWidth:m,gridHeight:h,cells:g}=t,_=o.w/m,v=o.h/h,b=m*h,x=r?.3:1,S=n=>{if(!a){s(e.id);return}let r=g[n]!==!0;c.current=!0,l.current=r,u.current=new Set([n]),f(e.id,t,n,r)},C=n=>{!c.current||!a||u.current.has(n)||(u.current.add(n),f(e.id,t,n,l.current))},w=()=>{c.current&&(c.current=!1,u.current=new Set)};return i(d,{opacity:x,onMouseUp:w,onMouseLeave:w,children:Array.from({length:b},(e,t)=>{let r=t%m,a=Math.floor(t/m),o=g[t]===!0;return i(p,{x:r*_,y:a*v,width:_,height:v,fill:o?n+y:`#ffffff10`,stroke:o?n:`#ffffff40`,strokeWidth:.5,onMouseDown:e=>{e.cancelBubble=!0,S(t)},onMouseEnter:()=>C(t)},t)})})}function z({item:t,shape:n,color:r,selected:a,dimmed:o,editable:s,isLine:c,isDrawing:l,size:p,effectivePoints:g,minVertices:_,maxVertices:b,isDragging:x,onSelect:S,onShapeChange:C,setDragOverride:w,setDraggingItemId:T}){let k=O(g,p.w,p.h),A=o?.35:a?1:c?.8:.85,M=e=>c?{kind:`line`,points:[...e]}:{kind:`polygon`,points:[...e]},N=g.map(e=>e.x*p.w),P=g.map(e=>e.y*p.h),F=N.length>0?Math.min(...N):0,I=N.length>0?Math.max(...N):0,L=P.length>0?Math.min(...P):0,R=P.length>0?Math.max(...P):0,z=e=>({x:Math.max(-F,Math.min(p.w-I,e.x)),y:Math.max(-L,Math.min(p.h-R,e.y))}),B=e=>{let r=e.target,i=r.x()/p.w,a=r.y()/p.h;if(r.position({x:0,y:0}),T(null),i===0&&a===0)return;let o=n.points.map(e=>({x:e.x+i,y:e.y+a}));w({itemId:t.id,points:o}),C(t.id,M(o))},V=!c&&g.length>_,H=!c&&(b===void 0||g.length<b);return e(d,{onClick:e=>{e.cancelBubble=!0,l||S(t.id)},children:[e(d,{draggable:s,dragBoundFunc:s?z:void 0,onDragStart:s?()=>T(t.id):void 0,onDragEnd:s?B:void 0,onMouseEnter:e=>{if(!s)return;let t=e.target.getStage();t&&(t.container().style.cursor=`move`)},onMouseLeave:e=>{if(!s)return;let t=e.target.getStage();t&&(t.container().style.cursor=l?`crosshair`:`default`)},children:[c?i(m,{points:k,stroke:r,strokeWidth:a?3:2,fill:r,pointerLength:10,pointerWidth:8,opacity:A}):i(u,{points:k,closed:!0,fill:r+(a?y:v),stroke:r,strokeWidth:a?2.5:1.5,opacity:A}),t.label&&g.length>0?(()=>{let e=E({x:g.reduce((e,t)=>e+t.x,0)/g.length,y:g.reduce((e,t)=>e+t.y,0)/g.length},p.w,p.h),n=Math.max(40,t.label.length*11*.62);return i(f,{x:e.x-n/2,y:e.y-7,width:n,align:`center`,text:t.label,fontSize:12,fill:r,stroke:`#000000`,strokeWidth:3,fillAfterStrokeEnabled:!0,fontStyle:`bold`,listening:!1})})():null]}),s&&!x&&g.map((e,a)=>{let o=E(e,p.w,p.h);return i(h,{x:o.x,y:o.y,radius:5,fill:r,stroke:`#ffffff`,strokeWidth:1.5,draggable:!0,onDragMove:e=>{let r=D({x:e.target.x(),y:e.target.y()},p.w,p.h);w(e=>{let i=e&&e.itemId===t.id?e.points:n.points;return{itemId:t.id,points:i.map((e,t)=>t===a?r:e)}})},onDragEnd:e=>{let r=D({x:e.target.x(),y:e.target.y()},p.w,p.h),i=n.points.map((e,t)=>t===a?r:e);w({itemId:t.id,points:i}),C(t.id,M(i))},onContextMenu:e=>{e.evt.preventDefault(),e.cancelBubble=!0,V&&C(t.id,M(n.points.filter((e,t)=>t!==a)))}},`pt-${a}`)}),s&&!x&&H&&g.length>=2&&g.map((e,a)=>{let o=g[(a+1)%g.length],s=E({x:(e.x+o.x)/2,y:(e.y+o.y)/2},p.w,p.h);return i(h,{x:s.x,y:s.y,radius:4,fill:`#ffffff`,stroke:r,strokeWidth:1.5,opacity:.6,onMouseEnter:e=>{let t=e.target;t.to({radius:6,opacity:1,duration:.1});let n=t.getStage();n&&(n.container().style.cursor=`copy`)},onMouseLeave:e=>{let t=e.target;t.to({radius:4,opacity:.6,duration:.1});let n=t.getStage();n&&(n.container().style.cursor=l?`crosshair`:`default`)},onClick:e=>{e.cancelBubble=!0,C(t.id,M(j(n.points,a)))}},`mid-${a}`)})]})}var B=n(P);export{B as MaskShapeCanvas};
1
+ import{C as e,J as t,P as n,R as r,S as i,V as a,Y as o,et as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{ao as c}from"./player-overlays-ugkkFXtV.js";import{a as l,c as u,i as d,n as f,o as p,r as m,s as h,t as g}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_konva__loadShare__.js-BjdR__nc.js";s();var _={rect:`#ef4444`,polygon:`#3b82f6`,grid:`#6366f1`,line:`#f59e0b`},v=`33`,y=`66`,b=`#6366f1`,x=3,S=2,C=12,w=16,T=9;function E(e,t,n){return{x:e.x*t,y:e.y*n}}function D(e,t,n){return{x:e.x/t,y:e.y/n}}function O(e,t,n){return e.flatMap(e=>[e.x*t,e.y*n])}function k(e){return!Number.isFinite(e)||e<0?0:e>1?1:e}function A(e){return e.color??_[e.shape.kind]}function j(e,t){let n=e[t],r=e[(t+1)%e.length];if(!n||!r)return[...e];let i={x:(n.x+r.x)/2,y:(n.y+r.y)/2};return[...e.slice(0,t+1),i,...e.slice(t+1)]}function M(e,t){return e.length===t.length?e.every((e,n)=>{let r=t[n];return Math.abs(e.x-r.x)<1e-6&&Math.abs(e.y-r.y)<1e-6}):!1}function N(e){return e.kind===`polygon`||e.kind===`line`}function P({items:n,selectedId:s,onSelect:f,onShapeChange:p,onDrawComplete:m,drawingKind:v,supportedShapes:y,transparent:j=!1,backdrop:P,polygonVertices:F,grid:I}){let B=c(),V=t(null),[H,ee]=o({w:800,h:450}),[U,W]=o([]),[G,K]=o(null),[te,ne]=o(null),[q,J]=o(null),Y=v!==null&&y.includes(v);a(()=>{if(!q)return;let e=n.find(e=>e.id===q.itemId);if(!e||!N(e.shape)){J(null);return}M(e.shape.points,q.points)&&J(null)},[n,q]),a(()=>{let e=V.current;if(!e)return;let t=new ResizeObserver(e=>{let t=e[0];if(!t)return;let{width:n,height:r}=t.contentRect;ee(j?{w:n,h:r}:{w:n,h:n*9/16})});return t.observe(e),()=>t.disconnect()},[j]),a(()=>{!Y&&G!==null&&K(null)},[Y,G]);let X=r(e=>{m(e),W([])},[m]),re=r(e=>{if(!Y||v===null){f(null);return}let t=e.target.getStage();if(!t)return;let n=t.getPointerPosition();if(!n)return;let r=D(n,H.w,H.h);if(v===`rect`){let e=k(r.x),t=k(r.y);X({kind:`rect`,x:e,y:t,width:Math.min(.2,1-e),height:Math.min(.2,1-t)});return}if(v===`grid`){let e=I?.width??w,t=I?.height??T;X({kind:`grid`,gridWidth:e,gridHeight:t,cells:Array.from({length:e*t},()=>!1)});return}if(v===`line`){if(U.length===0){W([r]);return}X({kind:`line`,points:[...U,r]});return}if(v===`polygon`){if(U.length===0){W([r]);return}if(U.length>=x){let e=E(U[0],H.w,H.h);if(Math.hypot(n.x-e.x,n.y-e.y)<C){X({kind:`polygon`,points:U});return}}W(e=>[...e,r])}},[Y,v,U,H,I,X,f]),ie=r(e=>{!Y||v!==`polygon`||U.length<x||(e.cancelBubble=!0,X({kind:`polygon`,points:U}))},[Y,v,U,X]),Z=t(null),Q=t(null);a(()=>()=>{Z.current!==null&&cancelAnimationFrame(Z.current)},[]);let ae=r(e=>{if(!Y)return;let t=e.target.getStage();t&&(Q.current=t.getPointerPosition()??null,Z.current===null&&(Z.current=requestAnimationFrame(()=>{Z.current=null,K(Q.current)})))},[Y]),oe=t(!1),se=t(!0),ce=t(new Set),le=r((e,t,n,r)=>{let i=t.gridWidth*t.gridHeight;if(n<0||n>=i||t.cells[n]===r)return;let a=[...t.cells];for(;a.length<i;)a.push(!1);a.length=i,a[n]=r,p(e,{...t,cells:a})},[p]),$=[];if(!j){for(let e=1;e<w;e++){let t=H.w/w*e;$.push(i(u,{points:[t,0,t,H.h],stroke:`#ffffff`,strokeWidth:.5,opacity:.08},`gv-${e}`))}for(let e=1;e<T;e++){let t=H.h/T*e;$.push(i(u,{points:[0,t,H.w,t],stroke:`#ffffff`,strokeWidth:.5,opacity:.08},`gh-${e}`))}}return e(`div`,{ref:V,className:j?`absolute inset-0`:`relative w-full bg-zinc-900 rounded-lg overflow-hidden`,style:{cursor:Y?`crosshair`:`default`},children:[P&&!j?i(`div`,{className:`absolute inset-0 pointer-events-none [&>*]:w-full [&>*]:h-full [&>img]:object-cover [&>video]:object-cover`,style:{width:H.w,height:H.h},children:P}):null,e(l,{width:H.w,height:H.h,onClick:re,onDblClick:ie,onMouseMove:ae,children:[e(g,{listening:!1,children:[i(u,{points:[0,0,H.w,0,H.w,H.h,0,H.h,0,0],stroke:`transparent`,strokeWidth:0}),$]}),i(g,{children:n.map(e=>{let t=e.id===s,n=e.enabled===!1,r=A(e),a=t&&!Y&&!n;if(e.shape.kind===`rect`)return i(L,{item:e,shape:e.shape,color:r,selected:t,dimmed:n,editable:a,isDrawing:Y,size:H,onSelect:f,onShapeChange:p},e.id);if(e.shape.kind===`grid`)return i(R,{item:e,shape:e.shape,color:r,dimmed:n,editable:a,size:H,onSelect:f,paintingRef:oe,paintValueRef:se,paintedRef:ce,paintCell:le},e.id);let o=e.shape.kind===`line`,c=o?S:Math.max(x,F?.min??x),l=o?S:F?.max,u=q&&q.itemId===e.id?q.points:e.shape.points;return i(z,{item:e,shape:e.shape,color:r,selected:t,dimmed:n,editable:a,isLine:o,isDrawing:Y,size:H,effectivePoints:u,minVertices:c,maxVertices:l,isDragging:te===e.id,onSelect:f,onShapeChange:p,setDragOverride:J,setDraggingItemId:ne},e.id)})}),i(g,{listening:!1,children:Y&&U.length>0&&e(d,{children:[v===`polygon`&&U.length>=2&&i(u,{points:O(U,H.w,H.h),stroke:b,strokeWidth:1.5,dash:[6,3],opacity:.8}),v===`line`&&U.length===1&&G&&i(u,{points:[U[0].x*H.w,U[0].y*H.h,G.x,G.y],stroke:_.line,strokeWidth:1.5,dash:[6,3],opacity:.7}),v===`polygon`&&G&&U.length>=1&&i(u,{points:[U[U.length-1].x*H.w,U[U.length-1].y*H.h,G.x,G.y],stroke:b,strokeWidth:1,dash:[4,4],opacity:.5}),U.map((e,t)=>{let n=E(e,H.w,H.h),r=t===0&&v===`polygon`&&U.length>=x;return i(h,{x:n.x,y:n.y,radius:r?7:4,fill:r?b:`#ffffff`,stroke:b,strokeWidth:1.5,opacity:.9},t)})]})})]}),Y?i(`div`,{className:`px-3 py-1.5 bg-zinc-800/80 text-[11px] text-zinc-400 border-t border-zinc-700`,children:v===`line`?B(`uiLibrary.maskShapeCanvas.hintLine`,`Click to set the start point, click again to complete the line`):v===`rect`?B(`uiLibrary.maskShapeCanvas.hintRect`,`Click to drop a rectangle, then drag the corner to resize`):v===`grid`?B(`uiLibrary.maskShapeCanvas.hintGrid`,`Click to add the grid, then paint cells`):U.length<x?B(`uiLibrary.maskShapeCanvas.hintPoints`,`Click to add points (min 3). Double-click or click the first point to close.`):B(`uiLibrary.maskShapeCanvas.hintMore`,`Continue adding points. Double-click or click the first point to close.`)}):null]})}var F=.02;function I(e,t){return Math.abs(e.x-t.x)<1e-6&&Math.abs(e.y-t.y)<1e-6&&Math.abs(e.width-t.width)<1e-6&&Math.abs(e.height-t.height)<1e-6}function L({item:t,shape:n,color:r,selected:s,dimmed:c,editable:l,isDrawing:u,size:m,onSelect:g,onShapeChange:_}){let[b,x]=o(null),S={x:n.x,y:n.y,width:n.width,height:n.height};a(()=>{b&&I(S,b)&&x(null)},[n.x,n.y,n.width,n.height,b]);let C=b??S,w=C.x*m.w,T=C.y*m.h,E=C.width*m.w,D=C.height*m.h,O=c?.35:s?1:.85,A=e=>{x(e),_(t.id,{kind:`rect`,x:e.x,y:e.y,width:e.width,height:e.height})};return i(d,{onClick:e=>{e.cancelBubble=!0,u||g(t.id)},children:e(d,{draggable:l,dragBoundFunc:l?e=>({x:Math.max(-w,Math.min(m.w-(w+E),e.x)),y:Math.max(-T,Math.min(m.h-(T+D),e.y))}):void 0,onDragEnd:l?e=>{let t=e.target,n=t.x()/m.w,r=t.y()/m.h;if(t.position({x:0,y:0}),n===0&&r===0)return;let i=Math.min(Math.max(0,C.x+n),Math.max(0,1-C.width)),a=Math.min(Math.max(0,C.y+r),Math.max(0,1-C.height));A({...C,x:i,y:a})}:void 0,onMouseEnter:e=>{if(!l)return;let t=e.target.getStage();t&&(t.container().style.cursor=`move`)},onMouseLeave:e=>{if(!l)return;let t=e.target.getStage();t&&(t.container().style.cursor=u?`crosshair`:`default`)},children:[i(p,{x:w,y:T,width:E,height:D,fill:r+(s?y:v),stroke:r,strokeWidth:s?2.5:1.5,opacity:O}),t.label?i(f,{x:w,y:T-16,text:t.label,fontSize:12,fill:r,stroke:`#000000`,strokeWidth:3,fillAfterStrokeEnabled:!0,fontStyle:`bold`,listening:!1}):null,l?i(h,{x:w+E,y:T+D,radius:6,fill:r,stroke:`#ffffff`,strokeWidth:1.5,draggable:!0,dragBoundFunc:e=>({x:Math.min(m.w,Math.max(w,e.x)),y:Math.min(m.h,Math.max(T,e.y))}),onDragStart:e=>{e.cancelBubble=!0},onDragMove:e=>{let t=e.target,n=k(t.x()/m.w-C.x),r=k(t.y()/m.h-C.y);x({...C,width:Math.max(F,Math.min(n,1-C.x)),height:Math.max(F,Math.min(r,1-C.y))})},onDragEnd:e=>{let t=e.target,n=k(t.x()/m.w-C.x),r=k(t.y()/m.h-C.y);A({...C,width:Math.max(F,Math.min(n,1-C.x)),height:Math.max(F,Math.min(r,1-C.y))})},onMouseEnter:e=>{let t=e.target.getStage();t&&(t.container().style.cursor=`nwse-resize`)},onMouseLeave:e=>{let t=e.target.getStage();t&&(t.container().style.cursor=`default`)}}):null]})})}function R({item:e,shape:t,color:n,dimmed:r,editable:a,size:o,onSelect:s,paintingRef:c,paintValueRef:l,paintedRef:u,paintCell:f}){let{gridWidth:m,gridHeight:h,cells:g}=t,_=o.w/m,v=o.h/h,b=m*h,x=r?.3:1,S=n=>{if(!a){s(e.id);return}let r=g[n]!==!0;c.current=!0,l.current=r,u.current=new Set([n]),f(e.id,t,n,r)},C=n=>{!c.current||!a||u.current.has(n)||(u.current.add(n),f(e.id,t,n,l.current))},w=()=>{c.current&&(c.current=!1,u.current=new Set)};return i(d,{opacity:x,onMouseUp:w,onMouseLeave:w,children:Array.from({length:b},(e,t)=>{let r=t%m,a=Math.floor(t/m),o=g[t]===!0;return i(p,{x:r*_,y:a*v,width:_,height:v,fill:o?n+y:`#ffffff10`,stroke:o?n:`#ffffff40`,strokeWidth:.5,onMouseDown:e=>{e.cancelBubble=!0,S(t)},onMouseEnter:()=>C(t)},t)})})}function z({item:t,shape:n,color:r,selected:a,dimmed:o,editable:s,isLine:c,isDrawing:l,size:p,effectivePoints:g,minVertices:_,maxVertices:b,isDragging:x,onSelect:S,onShapeChange:C,setDragOverride:w,setDraggingItemId:T}){let k=O(g,p.w,p.h),A=o?.35:a?1:c?.8:.85,M=e=>c?{kind:`line`,points:[...e]}:{kind:`polygon`,points:[...e]},N=g.map(e=>e.x*p.w),P=g.map(e=>e.y*p.h),F=N.length>0?Math.min(...N):0,I=N.length>0?Math.max(...N):0,L=P.length>0?Math.min(...P):0,R=P.length>0?Math.max(...P):0,z=e=>({x:Math.max(-F,Math.min(p.w-I,e.x)),y:Math.max(-L,Math.min(p.h-R,e.y))}),B=e=>{let r=e.target,i=r.x()/p.w,a=r.y()/p.h;if(r.position({x:0,y:0}),T(null),i===0&&a===0)return;let o=n.points.map(e=>({x:e.x+i,y:e.y+a}));w({itemId:t.id,points:o}),C(t.id,M(o))},V=!c&&g.length>_,H=!c&&(b===void 0||g.length<b);return e(d,{onClick:e=>{e.cancelBubble=!0,l||S(t.id)},children:[e(d,{draggable:s,dragBoundFunc:s?z:void 0,onDragStart:s?()=>T(t.id):void 0,onDragEnd:s?B:void 0,onMouseEnter:e=>{if(!s)return;let t=e.target.getStage();t&&(t.container().style.cursor=`move`)},onMouseLeave:e=>{if(!s)return;let t=e.target.getStage();t&&(t.container().style.cursor=l?`crosshair`:`default`)},children:[c?i(m,{points:k,stroke:r,strokeWidth:a?3:2,fill:r,pointerLength:10,pointerWidth:8,opacity:A}):i(u,{points:k,closed:!0,fill:r+(a?y:v),stroke:r,strokeWidth:a?2.5:1.5,opacity:A}),t.label&&g.length>0?(()=>{let e=E({x:g.reduce((e,t)=>e+t.x,0)/g.length,y:g.reduce((e,t)=>e+t.y,0)/g.length},p.w,p.h),n=Math.max(40,t.label.length*11*.62);return i(f,{x:e.x-n/2,y:e.y-7,width:n,align:`center`,text:t.label,fontSize:12,fill:r,stroke:`#000000`,strokeWidth:3,fillAfterStrokeEnabled:!0,fontStyle:`bold`,listening:!1})})():null]}),s&&!x&&g.map((e,a)=>{let o=E(e,p.w,p.h);return i(h,{x:o.x,y:o.y,radius:5,fill:r,stroke:`#ffffff`,strokeWidth:1.5,draggable:!0,onDragMove:e=>{let r=D({x:e.target.x(),y:e.target.y()},p.w,p.h);w(e=>{let i=e&&e.itemId===t.id?e.points:n.points;return{itemId:t.id,points:i.map((e,t)=>t===a?r:e)}})},onDragEnd:e=>{let r=D({x:e.target.x(),y:e.target.y()},p.w,p.h),i=n.points.map((e,t)=>t===a?r:e);w({itemId:t.id,points:i}),C(t.id,M(i))},onContextMenu:e=>{e.evt.preventDefault(),e.cancelBubble=!0,V&&C(t.id,M(n.points.filter((e,t)=>t!==a)))}},`pt-${a}`)}),s&&!x&&H&&g.length>=2&&g.map((e,a)=>{let o=g[(a+1)%g.length],s=E({x:(e.x+o.x)/2,y:(e.y+o.y)/2},p.w,p.h);return i(h,{x:s.x,y:s.y,radius:4,fill:`#ffffff`,stroke:r,strokeWidth:1.5,opacity:.6,onMouseEnter:e=>{let t=e.target;t.to({radius:6,opacity:1,duration:.1});let n=t.getStage();n&&(n.container().style.cursor=`copy`)},onMouseLeave:e=>{let t=e.target;t.to({radius:4,opacity:.6,duration:.1});let n=t.getStage();n&&(n.container().style.cursor=l?`crosshair`:`default`)},onClick:e=>{e.cancelBubble=!0,C(t.id,M(j(n.points,a)))}},`mid-${a}`)})]})}var B=n(P);export{B as MaskShapeCanvas};
@@ -1 +1 @@
1
- import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,et as s,x as ee}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{K as te,U as c,X as l,Za as u,eo as ne,ii as re,n as d,yt as f,z as p}from"./player-overlays-CMIUmcCR.js";import{MaskShapeCanvas as m}from"./MaskShapeCanvas-DhkgwuqU.js";s();var ie=110,h=`motion-zones`,g=0,_=[1,2,3],v=1,y=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,b=`rounded-md border border-primary/50 bg-primary/15 px-2.5 py-1 text-[11px] font-medium text-primary hover:bg-primary/25 disabled:opacity-40 transition-colors`;function x(e,t,n){let r=t*n,i=Array.from({length:r});for(let t=0;t<r;t+=1)i[t]=e[t]===!0;return i}function S(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return!1;return!0}function C(e,t){return Math.ceil(e/t)}function w(e,t,n){return Math.min(n-1,Math.floor((e+.5)/t*n))}function T(e,t,n,r){let i=C(t,r),a=C(n,r),o=Array.from({length:i*a},()=>!1);for(let r=0;r<n;r+=1){let s=w(r,n,a);for(let n=0;n<t;n+=1)e[r*t+n]===!0&&(o[s*i+w(n,t,i)]=!0)}return o}function E(e,t,n,r){let i=C(t,r),a=C(n,r),o=Array.from({length:t*n},()=>!1);for(let r=0;r<n;r+=1){let s=w(r,n,a);for(let n=0;n<t;n+=1)o[r*t+n]=e[s*i+w(n,t,i)]===!0}return o}function D({deviceId:s}){let w=ne(),D=te(f().trpcClient,s),[O,k]=o(null),[A,j]=o(!1),[M,N]=o(null),[P,F]=o(null),[I,L]=o(v),[R,z]=o(!1),[B,V]=o(!1),H=t(!1);a(()=>{if(!D)return;let e=!1;return H.current=!1,k(null),j(!1),N(null),F(null),L(v),V(!1),(async()=>{try{let t=await D.motionZones?.getOptions({});if(e)return;if(!t)throw Error(`device proxy not ready`);if(k(t),H.current)return;let n=await D.motionZones?.getStatus({});if(e)return;if(!n)throw Error(`device proxy not ready`);H.current=!0;let r=n.regions.find(e=>e.shape.kind===`grid`),i=x(r?r.shape.cells:[],t.grid.width,t.grid.height);F(i),N(T(i,t.grid.width,t.grid.height,v))}catch(t){if(e)return;c(t)?j(!0):console.error(`Motion Zones load failed`,t)}})(),()=>{e=!0}},[D]);let U=O?O.grid.width:0,W=O?O.grid.height:0,G=C(U,I),K=C(W,I),q=n(()=>M&&O?E(M,U,W,I):null,[M,O,U,W,I]),J=n(()=>q!==null&&P!==null&&!S(q,P),[q,P]),ae=n(()=>q?q.reduce((e,t)=>t?e+1:e,0):0,[q]),oe=U*W,Y=G*K,X=r(e=>{Y>0&&N(Array.from({length:Y},()=>e))},[Y]),se=r(()=>{N(e=>e&&e.map(e=>!e))},[]),Z=r(()=>{P&&O&&N(T(P,U,W,I))},[P,O,U,W,I]),ce=r(e=>{e===I||!O||N(t=>{if(!t)return L(e),t;let n=T(E(t,U,W,I),U,W,e);return L(e),n})},[I,O,U,W]),Q=n(()=>O&&M?[{id:g,shape:{kind:`grid`,gridWidth:G,gridHeight:K,cells:[...M]}}]:[],[O,M,G,K]),$=r((e,t)=>{t.kind===`grid`&&N(t.cells)},[]),le=r(async()=>{if(!(!D||!M||!O)){z(!0);try{let e=E(M,O.grid.width,O.grid.height,I),t={kind:`grid`,gridWidth:O.grid.width,gridHeight:O.grid.height,cells:e};await D.motionZones?.setZone({patch:{regions:[{id:g,enabled:!0,shape:t}]}});let n=await D.motionZones?.getStatus({});if(n){let e=n.regions.find(e=>e.shape.kind===`grid`),t=x(e?e.shape.cells:[],O.grid.width,O.grid.height);F(t),N(T(t,O.grid.width,O.grid.height,I))}}catch(e){console.error(`Motion Zones save failed`,e)}finally{z(!1)}}},[D,M,O,I]);d(n(()=>B&&!A&&O&&M?{id:h,order:ie,node:i(m,{transparent:!0,items:Q,supportedShapes:[`grid`],grid:{width:G,height:K},selectedId:g,onSelect:()=>{},onShapeChange:$,onDrawComplete:()=>{},drawingKind:null})}:null,[B,A,O,M,Q,$,G,K]));let ue=!A&&O!==null&&M!==null;return D?i(l,{title:w(`uiLibrary.motionZones.title`,`Motion Zones`),icon:i(re,{className:`h-3.5 w-3.5 text-foreground-subtle`}),children:i(`div`,{className:`flex flex-col gap-3`,children:A?i(`p`,{className:`${p} leading-relaxed`,children:w(`uiLibrary.motionZones.unsupported`,`This camera doesn't expose an on-board motion zones grid.`)}):ue?e(ee,{children:[i(`p`,{className:`${p} leading-relaxed`,children:i(u,{uiKey:`uiLibrary.motionZones.intro`,fallback:`Toggle <0>Edit grid</0> to paint the region directly on the live frame, then <1>Save</1> to push the mask to the camera. Pick a bigger <2>Cell size</2> for quicker, broad-stroke painting — it's resampled to the camera's native {{width}}×{{height}} grid on save (×1 is the finest).`,components:[i(`strong`,{className:`text-foreground`},`e`),i(`strong`,{className:`text-foreground`},`s`),i(`strong`,{className:`text-foreground`},`c`)],values:{width:O.grid.width,height:O.grid.height}})}),e(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[i(`button`,{type:`button`,onClick:()=>V(e=>!e),disabled:R,"aria-pressed":B,className:B?b:y,children:B?w(`uiLibrary.motionZones.doneEditing`,`Done editing`):w(`uiLibrary.motionZones.editGrid`,`Edit grid`)}),i(`button`,{type:`button`,onClick:()=>X(!0),disabled:R,className:y,children:w(`uiLibrary.motionZones.allOn`,`All on`)}),i(`button`,{type:`button`,onClick:()=>X(!1),disabled:R,className:y,children:w(`uiLibrary.motionZones.allOff`,`All off`)}),i(`button`,{type:`button`,onClick:se,disabled:R,className:y,children:w(`uiLibrary.motionZones.invert`,`Invert`)}),e(`div`,{className:`flex items-center gap-1 ml-1`,role:`group`,"aria-label":w(`uiLibrary.motionZones.cellSize`,`Cell size`),children:[i(`span`,{className:`${p} mr-0.5`,children:w(`uiLibrary.motionZones.cellSize`,`Cell size`)}),_.map(t=>e(`button`,{type:`button`,onClick:()=>ce(t),disabled:R,"aria-pressed":I===t,title:t===1?w(`uiLibrary.motionZones.cameraGrid`,`Camera grid {{width}}×{{height}} (finest)`,{width:U,height:W}):w(`uiLibrary.motionZones.paintingGrid`,`{{width}}×{{height}} painting grid · cells ×{{factor}} bigger`,{width:C(U,t),height:C(W,t),factor:t}),className:I===t?b:y,children:[`×`,t]},t))]}),e(`span`,{className:`${p} ml-1 tabular-nums`,children:[w(`uiLibrary.motionZones.cells`,`{{active}} / {{total}} cells · {{width}}×{{height}}`,{active:ae,total:oe,width:O.grid.width,height:O.grid.height}),I===1?``:w(`uiLibrary.motionZones.paintSuffix`,` · paint {{width}}×{{height}}`,{width:G,height:K})]}),i(`span`,{className:`flex-1`}),i(`button`,{type:`button`,onClick:Z,disabled:R||!J,className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,children:w(`uiLibrary.motionZones.revert`,`Revert`)}),i(`button`,{type:`button`,onClick:()=>void le(),disabled:R||!J,className:b,children:R?w(`uiLibrary.motionZones.saving`,`Saving…`):w(`uiLibrary.motionZones.save`,`Save`)})]})]}):i(`p`,{className:`${p} leading-relaxed`,children:w(`uiLibrary.motionZones.loading`,`Loading the camera's grid…`)})})}):null}export{D as MotionZonesSettings};
1
+ import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,et as s,x as ee}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{K as te,U as c,X as l,ao as u,n as ne,no as re,oi as d,yt as f,z as p}from"./player-overlays-ugkkFXtV.js";import{MaskShapeCanvas as m}from"./MaskShapeCanvas-Dj-FghGr.js";s();var ie=110,h=`motion-zones`,g=0,_=[1,2,3],v=1,y=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,b=`rounded-md border border-primary/50 bg-primary/15 px-2.5 py-1 text-[11px] font-medium text-primary hover:bg-primary/25 disabled:opacity-40 transition-colors`;function x(e,t,n){let r=t*n,i=Array.from({length:r});for(let t=0;t<r;t+=1)i[t]=e[t]===!0;return i}function S(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return!1;return!0}function C(e,t){return Math.ceil(e/t)}function w(e,t,n){return Math.min(n-1,Math.floor((e+.5)/t*n))}function T(e,t,n,r){let i=C(t,r),a=C(n,r),o=Array.from({length:i*a},()=>!1);for(let r=0;r<n;r+=1){let s=w(r,n,a);for(let n=0;n<t;n+=1)e[r*t+n]===!0&&(o[s*i+w(n,t,i)]=!0)}return o}function E(e,t,n,r){let i=C(t,r),a=C(n,r),o=Array.from({length:t*n},()=>!1);for(let r=0;r<n;r+=1){let s=w(r,n,a);for(let n=0;n<t;n+=1)o[r*t+n]=e[s*i+w(n,t,i)]===!0}return o}function D({deviceId:s}){let w=u(),D=te(f().trpcClient,s),[O,k]=o(null),[A,j]=o(!1),[M,N]=o(null),[P,F]=o(null),[I,L]=o(v),[R,z]=o(!1),[B,V]=o(!1),H=t(!1);a(()=>{if(!D)return;let e=!1;return H.current=!1,k(null),j(!1),N(null),F(null),L(v),V(!1),(async()=>{try{let t=await D.motionZones?.getOptions({});if(e)return;if(!t)throw Error(`device proxy not ready`);if(k(t),H.current)return;let n=await D.motionZones?.getStatus({});if(e)return;if(!n)throw Error(`device proxy not ready`);H.current=!0;let r=n.regions.find(e=>e.shape.kind===`grid`),i=x(r?r.shape.cells:[],t.grid.width,t.grid.height);F(i),N(T(i,t.grid.width,t.grid.height,v))}catch(t){if(e)return;c(t)?j(!0):console.error(`Motion Zones load failed`,t)}})(),()=>{e=!0}},[D]);let U=O?O.grid.width:0,W=O?O.grid.height:0,G=C(U,I),K=C(W,I),q=n(()=>M&&O?E(M,U,W,I):null,[M,O,U,W,I]),J=n(()=>q!==null&&P!==null&&!S(q,P),[q,P]),ae=n(()=>q?q.reduce((e,t)=>t?e+1:e,0):0,[q]),oe=U*W,Y=G*K,X=r(e=>{Y>0&&N(Array.from({length:Y},()=>e))},[Y]),se=r(()=>{N(e=>e&&e.map(e=>!e))},[]),Z=r(()=>{P&&O&&N(T(P,U,W,I))},[P,O,U,W,I]),ce=r(e=>{e===I||!O||N(t=>{if(!t)return L(e),t;let n=T(E(t,U,W,I),U,W,e);return L(e),n})},[I,O,U,W]),Q=n(()=>O&&M?[{id:g,shape:{kind:`grid`,gridWidth:G,gridHeight:K,cells:[...M]}}]:[],[O,M,G,K]),$=r((e,t)=>{t.kind===`grid`&&N(t.cells)},[]),le=r(async()=>{if(!(!D||!M||!O)){z(!0);try{let e=E(M,O.grid.width,O.grid.height,I),t={kind:`grid`,gridWidth:O.grid.width,gridHeight:O.grid.height,cells:e};await D.motionZones?.setZone({patch:{regions:[{id:g,enabled:!0,shape:t}]}});let n=await D.motionZones?.getStatus({});if(n){let e=n.regions.find(e=>e.shape.kind===`grid`),t=x(e?e.shape.cells:[],O.grid.width,O.grid.height);F(t),N(T(t,O.grid.width,O.grid.height,I))}}catch(e){console.error(`Motion Zones save failed`,e)}finally{z(!1)}}},[D,M,O,I]);ne(n(()=>B&&!A&&O&&M?{id:h,order:ie,node:i(m,{transparent:!0,items:Q,supportedShapes:[`grid`],grid:{width:G,height:K},selectedId:g,onSelect:()=>{},onShapeChange:$,onDrawComplete:()=>{},drawingKind:null})}:null,[B,A,O,M,Q,$,G,K]));let ue=!A&&O!==null&&M!==null;return D?i(l,{title:w(`uiLibrary.motionZones.title`,`Motion Zones`),icon:i(d,{className:`h-3.5 w-3.5 text-foreground-subtle`}),children:i(`div`,{className:`flex flex-col gap-3`,children:A?i(`p`,{className:`${p} leading-relaxed`,children:w(`uiLibrary.motionZones.unsupported`,`This camera doesn't expose an on-board motion zones grid.`)}):ue?e(ee,{children:[i(`p`,{className:`${p} leading-relaxed`,children:i(re,{uiKey:`uiLibrary.motionZones.intro`,fallback:`Toggle <0>Edit grid</0> to paint the region directly on the live frame, then <1>Save</1> to push the mask to the camera. Pick a bigger <2>Cell size</2> for quicker, broad-stroke painting — it's resampled to the camera's native {{width}}×{{height}} grid on save (×1 is the finest).`,components:[i(`strong`,{className:`text-foreground`},`e`),i(`strong`,{className:`text-foreground`},`s`),i(`strong`,{className:`text-foreground`},`c`)],values:{width:O.grid.width,height:O.grid.height}})}),e(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[i(`button`,{type:`button`,onClick:()=>V(e=>!e),disabled:R,"aria-pressed":B,className:B?b:y,children:B?w(`uiLibrary.motionZones.doneEditing`,`Done editing`):w(`uiLibrary.motionZones.editGrid`,`Edit grid`)}),i(`button`,{type:`button`,onClick:()=>X(!0),disabled:R,className:y,children:w(`uiLibrary.motionZones.allOn`,`All on`)}),i(`button`,{type:`button`,onClick:()=>X(!1),disabled:R,className:y,children:w(`uiLibrary.motionZones.allOff`,`All off`)}),i(`button`,{type:`button`,onClick:se,disabled:R,className:y,children:w(`uiLibrary.motionZones.invert`,`Invert`)}),e(`div`,{className:`flex items-center gap-1 ml-1`,role:`group`,"aria-label":w(`uiLibrary.motionZones.cellSize`,`Cell size`),children:[i(`span`,{className:`${p} mr-0.5`,children:w(`uiLibrary.motionZones.cellSize`,`Cell size`)}),_.map(t=>e(`button`,{type:`button`,onClick:()=>ce(t),disabled:R,"aria-pressed":I===t,title:t===1?w(`uiLibrary.motionZones.cameraGrid`,`Camera grid {{width}}×{{height}} (finest)`,{width:U,height:W}):w(`uiLibrary.motionZones.paintingGrid`,`{{width}}×{{height}} painting grid · cells ×{{factor}} bigger`,{width:C(U,t),height:C(W,t),factor:t}),className:I===t?b:y,children:[`×`,t]},t))]}),e(`span`,{className:`${p} ml-1 tabular-nums`,children:[w(`uiLibrary.motionZones.cells`,`{{active}} / {{total}} cells · {{width}}×{{height}}`,{active:ae,total:oe,width:O.grid.width,height:O.grid.height}),I===1?``:w(`uiLibrary.motionZones.paintSuffix`,` · paint {{width}}×{{height}}`,{width:G,height:K})]}),i(`span`,{className:`flex-1`}),i(`button`,{type:`button`,onClick:Z,disabled:R||!J,className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,children:w(`uiLibrary.motionZones.revert`,`Revert`)}),i(`button`,{type:`button`,onClick:()=>void le(),disabled:R||!J,className:b,children:R?w(`uiLibrary.motionZones.saving`,`Saving…`):w(`uiLibrary.motionZones.save`,`Save`)})]})]}):i(`p`,{className:`${p} leading-relaxed`,children:w(`uiLibrary.motionZones.loading`,`Loading the camera's grid…`)})})}):null}export{D as MotionZonesSettings};
@@ -0,0 +1,2 @@
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{$i as f,Cn as p,Fa as m,Hr as h,Ir as g,Mi as _,Nn as v,Q as y,Zi as b,Zt as x,_i as S,ao as C,ct as w,ft as T,qr as E,tn as D,ur as O,yt as k,zr as A}from"./player-overlays-ugkkFXtV.js";import{Ti as j,wi as M}from"./client-B3h-2G71.js";import{a as N,l as ee}from"./terminal-DZ5OZpgC.js";import{t as te}from"./monitor-smartphone-DPI9EQus.js";import{t as ne}from"./unlink-D3-IGpS8.js";import{Bi as re,Kp as P,Or as ie,Sl as ae,cp as F,gp as I,mt as L,pa as oe,wl as se,zi as ce}from"./src-DeDx2fDl.js";import{t as le}from"./i18n-BwW8nRaE.js";import{t as R}from"./useTranslation-BJr-n0es.js";import"./mount-DY4G4-U0.js";import{c as ue,i as de,l as z,s as B}from"./sso-popup-BRNSJ3u5.js";import{H as V,Si as H,gi as U,n as W,vi as G}from"./index-D_vdUQKv.js";import{t as fe}from"./AdminSectionedPage-3Jh0qbF0.js";import{t as pe}from"./AdminPage-DHZrZAII.js";import{n as me,t as he}from"./AccessSection-BTyH6Uq_.js";import{_ as ge,a as _e,h as ve,r as ye,t as be,w as xe}from"./SessionsList-Bjhwy-7x.js";l();var Se=`${M}/connect`,K={public:0,mesh:1,lan:2,"lan-ipv6":3};function Ce(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 q(e){return j(e)}function we(e){return e.startsWith(`https://`)}function Te(e){let t=e.flatMap(e=>{let t=Ce(e),n=q(e.baseUrl);return t===null||n===null?[]:[{endpoint:e,tier:t,origin:n}]}).toSorted((e,t)=>K[e.tier]-K[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:we(r),plausible:e.plausible}]))}function Ee(e,t,n=null){for(let r of[t,n]){if(r===null)continue;let t=q(r),n=e.find(e=>e.origin===t);if(n!==void 0)return n}return e[0]??null}function De(e){let t=new URL(Se);return t.searchParams.set(`hub`,e),t.toString()}var Oe=176,J={scheme:`https`};function ke(){let{t:e}=R(),t=se(J),r=ae(J).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(p,{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(A,{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(x,{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(F,{size:`sm`,variant:`ghost`,onClick:()=>void t.refetch(),children:e(`connectPhone.retry`)})]})]}):a(Ae,{candidates:Te(t.data.endpoints),preferredOrigin:r})]})]})}function Ae({candidates:e,preferredOrigin:t}){let{t:r}=R(),[o,c]=s(null),l=Ee(e,o,t),u=i(()=>l?De(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(ce,{value:u,size:Oe,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(T,{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(Y,{text:r(`connectPhone.insecure`)}),!l.plausible&&a(Y,{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(ie,{value:u,srLabel:r(`connectPhone.linkLabel`)})]})]}),a(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`connectPhone.signInHint`)})]})]})}function Y({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(x,{className:`h-3.5 w-3.5 text-warning mt-0.5 shrink-0`}),a(`span`,{children:e})]})}l();function je(e){return new Date(e).toLocaleDateString()}function Me(){let{t:e}=R(),t=w(),i=P.useUtils(),c=P.auth.listLinkableProviders.useQuery(),l=P.auth.listOwnExternalIdentities.useQuery(),[u,d]=s(null),[p,m]=s(()=>z(window.location.search)),g=r(null),_=W(`Linking a sign-in account`),v=r(null);o(()=>()=>v.current?.(),[]);let[x,S]=s(null);o(()=>{if(p===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)},[p]);let C=P.auth.beginExternalLink.useMutation({onSuccess:({url:e})=>{let t=g.current;if(g.current=null,t===null||t.closed){window.location.assign(e);return}let n=e=>{S(null),m(z(`?${e}`)),i.auth.listOwnExternalIdentities.invalidate()};v.current?.(),v.current=B(t,{onReturn:e=>{e.target===`profile`&&n(e.query)},onDone:e=>{e.target===`profile`&&n(e.query)},onClosed:()=>{v.current?.(),v.current=null,i.auth.listOwnExternalIdentities.invalidate()}}),t.location.href=y(ue(e))},onError:e=>{g.current?.close(),g.current=null,S(null),d(e.message)}}),T=P.auth.unlinkOwnExternalIdentity.useMutation({onSuccess:()=>void i.auth.listOwnExternalIdentities.invalidate(),onError:e=>d(e.message)}),E=c.data??[],D=l.data??[],O=x!==null&&D.some(e=>e.provider===x);if(o(()=>{!O||x===null||(S(null),m({kind:`linked`,provider:x}))},[O,x]),E.length===0&&D.length===0)return null;let k=new Set(D.map(e=>e.provider)),j=e=>E.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),T.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:[_.dialog,n(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[a(h,{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.`)}),p?.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(b,{className:`h-3.5 w-3.5 text-emerald-500 shrink-0`}),e(`users.linkedSignIns.linkedNotice`,{provider:j(p.provider)})]}),(p?.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(f,{className:`h-3.5 w-3.5 shrink-0`}),u??(p?.kind===`error`?p.message:``)]}),D.length>0&&a(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:D.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:je(t.linkedAt)})})]}),n(F,{variant:`unstyled`,onClick:()=>void M(t,r),disabled:T.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(ne,{className:`h-3 w-3`}),e(`users.linkedSignInsSection.unlink`,`Unlink`)]})]},`${t.provider}|${t.subject}`)})}),a(`div`,{className:`flex flex-wrap gap-2`,children:E.filter(e=>!k.has(e.provider)).map(t=>n(F,{variant:`unstyled`,onClick:()=>{d(null),m(null),_.requestProof().then(e=>{e!==null&&(g.current=de(null),S(g.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(A,{className:`h-3 w-3 animate-spin`}):a(h,{className:`h-3 w-3`}),e(`users.linkedSignIns.link`,{provider:t.label})]},t.provider))})]})]})}l();function Ne({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 Pe(){let{t:e}=R(),t=k(),[r,i]=s(``),[o,c]=s(``),[l,d]=s(``),[p,m]=s(null),h=u({mutationFn:e=>t.changeOwnPassword(e),onSuccess:()=>{m({kind:`success`,msg:`Password updated.`}),i(``),c(``),d(``)},onError:e=>{m({kind:`error`,msg:e instanceof Error?e.message:`Update failed`})}}),_=o.length>0&&l.length>0&&o!==l,v=o.length>0&&o.length<8,y=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(ee,{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(X,{label:e(`systemPage.myAccess.currentPassword`,`Current password`),value:r,onChange:i,autoComplete:`current-password`}),a(X,{label:e(`systemPage.myAccess.newPassword`,`New password`),value:o,onChange:c,autoComplete:`new-password`,hint:e(`systemPage.myAccess.atLeast8Characters`,`At least 8 characters.`)}),a(X,{label:e(`systemPage.myAccess.confirmNewPassword`,`Confirm new password`),value:l,onChange:d,autoComplete:`new-password`}),(_||v)&&a(`div`,{className:`text-[11px] text-danger`,children:_?e(`systemPage.myAccess.passwordsDoNotMatch`,`Passwords do not match.`):e(`systemPage.myAccess.newPasswordMustBeAt`,`New password must be at least 8 characters.`)}),p&&n(`div`,{className:`text-[11px] flex items-center gap-1 ${p.kind===`success`?`text-success`:`text-danger`}`,children:[p.kind===`success`?a(b,{className:`h-3 w-3`}):a(f,{className:`h-3 w-3`}),p.msg]}),a(`div`,{className:`flex justify-end`,children:n(F,{onClick:()=>{m(null),h.mutate({currentPassword:r,newPassword:o})},disabled:!y||h.isPending,children:[h.isPending?a(A,{className:`h-3 w-3 animate-spin`}):a(g,{className:`h-3 w-3`}),e(`systemPage.myAccess.updatePassword`,`Update password`)]})})]})]})}function X({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(I,{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 Fe({username:e}){let{t}=R(),r=k(),l=c({queryKey:[`auth`,`getOwnTotpStatus`],queryFn:()=>r.getOwnTotpStatus()}),m=l.data,[h,g]=s(null),[v,y]=s(``),[x,S]=s(null),[C,w]=s(!1),T=u({mutationFn:()=>r.setupOwnTotp(),onSuccess:e=>{g({secret:e.secret,otpauthUrl:e.otpauthUrl}),y(``),S(null)},onError:e=>S(e instanceof Error?e.message:`Setup failed`)}),E=u({mutationFn:e=>r.confirmOwnTotp(e),onSuccess:()=>{g(null),y(``),S(null),l.refetch()},onError:e=>S(e instanceof Error?e.message:`Confirmation failed — code did not match`)}),D=W(`Turning off two-factor authentication`),O=u({mutationFn:async()=>{let e=await D.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`:h?`setup_in_progress`:m?.enabled?`enrolled`:`not_enrolled`,[l.isLoading,m?.enabled,h]);return n(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[D.dialog,n(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[a(p,{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(A,{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(F,{onClick:()=>{S(null),T.mutate()},disabled:T.isPending,children:[T.isPending?a(A,{className:`h-3 w-3 animate-spin`}):a(p,{className:`h-3 w-3`}),t(`systemPage.myAccess.enable2fa`,`Enable 2FA`)]})})]}),j===`setup_in_progress`&&h&&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(Ne,{value:h.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:h.secret}),n(F,{variant:`ghost`,onClick:()=>{h&&navigator.clipboard.writeText(h.secret).then(()=>w(!0))},children:[C?a(b,{className:`h-3 w-3 text-success`}):a(_,{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(I,{type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,placeholder:`123456`,value:v,onChange:e=>y(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`})]}),x&&n(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[a(f,{className:`h-3 w-3`}),x]}),n(`div`,{className:`flex justify-end gap-2`,children:[a(F,{variant:`outline`,onClick:()=>{g(null),S(null),y(``)},children:t(`common.cancel`,`Cancel`)}),n(F,{onClick:()=>{S(null),E.mutate({code:v})},disabled:E.isPending||v.length!==6,children:[E.isPending?a(A,{className:`h-3 w-3 animate-spin`}):a(b,{className:`h-3 w-3`}),t(`common.confirm`,`Confirm`)]})]})]}),j===`enrolled`&&m&&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(b,{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:m.confirmedAt?new Date(m.confirmedAt).toLocaleString():`—`})})]})]}),x&&n(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[a(f,{className:`h-3 w-3`}),x]}),a(`div`,{className:`flex justify-end`,children:n(F,{variant:`danger`,onClick:()=>{S(null),O.mutate()},disabled:O.isPending,children:[O.isPending?a(A,{className:`h-3 w-3 animate-spin`}):a(p,{className:`h-3 w-3`}),t(`systemPage.myAccess.disable2fa`,`Disable 2FA`)]})})]})]})]})}function Z(){return oe(`auth-webauthn/passkey-enrollment`)?a(re,{widgetId:`auth-webauthn/passkey-enrollment`,host:`dashboard`}):null}l();function Q(e){return e.message.length>0?e.message:le.t(`auth.authAuditSection.requestFailed`)}function Ie(){let{t:e}=R(),{logout:t}=V(),r=w(),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:ge(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(te,{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(be,{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(F,{variant:`unstyled`,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(A,{className:`h-3 w-3 animate-spin`}):a(N,{className:`h-3 w-3`}),e(`auth.mySessionsSection.signOutEverywhere`,`Sign out everywhere`)]})})]})]})}l();var Le=`You`;function Re(){let{t:e}=R(),t=w(),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=>ye(e,Le)),[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:m,isAvailable:_e,onRun:e=>void d(e),busyId:l.isPending?l.variables?.id??null:null,disabled:l.isPending};return a(he,{id:`my-devices`,title:e(`certificates.myDevicesSection.myDevices`,`My devices`),icon:p,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:me(o),onDismissNotice:()=>c(null),children:a(xe,{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`},ze=[`linked`,`linkError`],Be={view:{icon:S,cls:`bg-foreground-subtle/15 text-foreground-subtle`},create:{icon:O,cls:`bg-primary/15 text-primary`},delete:{icon:D,cls:`bg-danger/15 text-danger`}};function Ve(){let{t:e}=R(),{user:t,logout:r}=V(),[i]=H(),o=e(`system.myAccess`,`My access`);if(!t)return a(pe,{icon:v,title:o,children:a(`div`,{className:`text-xs text-foreground-subtle`,children:e(`systemPage.myAccess.notSignedIn`,`Not signed in.`)})});if(i.get(`tab`)===`preferences`)return a(G,{to:`/system/settings`,replace:!0});if(ze.some(e=>i.has(e))&&!i.has(`tab`)){let e=new URLSearchParams(i);return e.set(`tab`,$.signIn),a(G,{to:`?${e.toString()}`,replace:!0})}return a(fe,{icon:v,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(F,{variant:`outline`,onClick:r,children:[a(N,{className:`h-3 w-3`}),e(`systemPage.myAccess.signOut`,`Sign out`)]}),sections:[{id:$.profile,label:e(`systemPage.myAccess.sections.profile`,`Profile`),content:a(He,{user:t})},{id:$.signIn,label:e(`systemPage.myAccess.sections.signIn`,`Sign-in & security`),content:n(`div`,{className:`space-y-4`,children:[a(Pe,{}),a(Fe,{username:t.username}),a(Z,{}),a(Me,{})]})},{id:$.sessions,label:e(`systemPage.myAccess.sections.sessions`,`Sessions & devices`),content:n(`div`,{className:`space-y-4`,children:[a(Ie,{}),a(Re,{}),a(ke,{})]})},{id:$.tokens,label:e(`systemPage.myAccess.sections.tokens`,`Tokens`),content:a(ve,{ownOnly:!0})}]})}function He({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(E,{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(Ue,{scopes:i})]})}function Ue({scopes:e}){let{t}=R(),r=C();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`?L(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}=Be[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{Ve as MyAccessPage};